13
13
14
14
#include " common.hpp"
15
15
16
+ #include < vector>
16
17
#include < cassert>
17
18
18
19
namespace rtc {
@@ -61,15 +62,31 @@ enum NalUnitStartSequenceMatch {
61
62
62
63
static const size_t H264_NAL_HEADER_SIZE = 1 ;
63
64
static const size_t H265_NAL_HEADER_SIZE = 2 ;
64
- // / Nal unit
65
+
66
+ struct NalUnitFragmentA ;
67
+
68
+ // / NAL unit
65
69
struct RTC_CPP_EXPORT NalUnit : binary {
70
+ static std::vector<binary> GenerateFragments (const std::vector<NalUnit> &nalus,
71
+ size_t maxFragmentSize);
72
+
73
+ enum class Separator {
74
+ Length = RTC_NAL_SEPARATOR_LENGTH, // first 4 bytes are NAL unit length
75
+ LongStartSequence = RTC_NAL_SEPARATOR_LONG_START_SEQUENCE, // 0x00, 0x00, 0x00, 0x01
76
+ ShortStartSequence = RTC_NAL_SEPARATOR_SHORT_START_SEQUENCE, // 0x00, 0x00, 0x01
77
+ StartSequence = RTC_NAL_SEPARATOR_START_SEQUENCE, // LongStartSequence or ShortStartSequence
78
+ };
79
+
80
+ static NalUnitStartSequenceMatch StartSequenceMatchSucc (NalUnitStartSequenceMatch match,
81
+ std::byte _byte, Separator separator);
82
+
66
83
enum class Type { H264, H265 };
67
84
68
85
NalUnit (const NalUnit &unit) = default ;
69
86
NalUnit (size_t size, bool includingHeader = true , Type type = Type::H264)
70
- : binary(size + (includingHeader
71
- ? 0
72
- : (type == Type::H264 ? H264_NAL_HEADER_SIZE : H265_NAL_HEADER_SIZE))) {}
87
+ : binary(size + (includingHeader ? 0
88
+ : (type == Type::H264 ? H264_NAL_HEADER_SIZE
89
+ : H265_NAL_HEADER_SIZE))) {}
73
90
NalUnit (binary &&data) : binary(std::move(data)) {}
74
91
NalUnit (Type type = Type::H264)
75
92
: binary(type == Type::H264 ? H264_NAL_HEADER_SIZE : H265_NAL_HEADER_SIZE) {}
@@ -94,56 +111,7 @@ struct RTC_CPP_EXPORT NalUnit : binary {
94
111
insert (end (), payload.begin (), payload.end ());
95
112
}
96
113
97
- // / NAL unit separator
98
- enum class Separator {
99
- Length = RTC_NAL_SEPARATOR_LENGTH, // first 4 bytes are NAL unit length
100
- LongStartSequence = RTC_NAL_SEPARATOR_LONG_START_SEQUENCE, // 0x00, 0x00, 0x00, 0x01
101
- ShortStartSequence = RTC_NAL_SEPARATOR_SHORT_START_SEQUENCE, // 0x00, 0x00, 0x01
102
- StartSequence = RTC_NAL_SEPARATOR_START_SEQUENCE, // LongStartSequence or ShortStartSequence
103
- };
104
-
105
- static NalUnitStartSequenceMatch StartSequenceMatchSucc (NalUnitStartSequenceMatch match,
106
- std::byte _byte, Separator separator) {
107
- assert (separator != Separator::Length);
108
- auto byte = (uint8_t )_byte;
109
- auto detectShort =
110
- separator == Separator::ShortStartSequence || separator == Separator::StartSequence;
111
- auto detectLong =
112
- separator == Separator::LongStartSequence || separator == Separator::StartSequence;
113
- switch (match) {
114
- case NUSM_noMatch:
115
- if (byte == 0x00 ) {
116
- return NUSM_firstZero;
117
- }
118
- break ;
119
- case NUSM_firstZero:
120
- if (byte == 0x00 ) {
121
- return NUSM_secondZero;
122
- }
123
- break ;
124
- case NUSM_secondZero:
125
- if (byte == 0x00 && detectLong) {
126
- return NUSM_thirdZero;
127
- } else if (byte == 0x00 && detectShort) {
128
- return NUSM_secondZero;
129
- } else if (byte == 0x01 && detectShort) {
130
- return NUSM_shortMatch;
131
- }
132
- break ;
133
- case NUSM_thirdZero:
134
- if (byte == 0x00 && detectLong) {
135
- return NUSM_thirdZero;
136
- } else if (byte == 0x01 && detectLong) {
137
- return NUSM_longMatch;
138
- }
139
- break ;
140
- case NUSM_shortMatch:
141
- return NUSM_shortMatch;
142
- case NUSM_longMatch:
143
- return NUSM_longMatch;
144
- }
145
- return NUSM_noMatch;
146
- }
114
+ std::vector<NalUnitFragmentA> generateFragments (size_t maxFragmentSize) const ;
147
115
148
116
protected:
149
117
const NalUnitHeader *header () const {
@@ -159,8 +127,9 @@ struct RTC_CPP_EXPORT NalUnit : binary {
159
127
160
128
// / Nal unit fragment A
161
129
struct RTC_CPP_EXPORT NalUnitFragmentA : NalUnit {
162
- static std::vector<shared_ptr<NalUnitFragmentA>> fragmentsFrom (shared_ptr<NalUnit> nalu,
163
- uint16_t maxFragmentSize);
130
+ // For backward compatibility, do not use
131
+ [[deprecated]] static std::vector<shared_ptr<NalUnitFragmentA>>
132
+ fragmentsFrom (shared_ptr<NalUnit> nalu, uint16_t maxFragmentSize);
164
133
165
134
enum class FragmentType { Start, Middle, End };
166
135
@@ -212,7 +181,8 @@ struct RTC_CPP_EXPORT NalUnitFragmentA : NalUnit {
212
181
}
213
182
};
214
183
215
- class RTC_CPP_EXPORT NalUnits : public std::vector<shared_ptr<NalUnit>> {
184
+ // For backward compatibility, do not use
185
+ class [[deprecated]] RTC_CPP_EXPORT NalUnits : public std::vector<shared_ptr<NalUnit>> {
216
186
public:
217
187
static const uint16_t defaultMaximumFragmentSize =
218
188
uint16_t (RTC_DEFAULT_MTU - 12 - 8 - 40 ); // SRTP/UDP/IPv6
0 commit comments