16
16
17
17
namespace rtc {
18
18
19
- const binary naluStartCode = {byte{0 }, byte{0 }, byte{0 }, byte{1 }};
19
+ const binary naluLongStartCode = {byte{0 }, byte{0 }, byte{0 }, byte{1 }};
20
+ const binary naluShortStartCode = {byte{0 }, byte{0 }, byte{1 }};
20
21
21
22
const uint8_t naluTypeAP = 48 ;
22
23
const uint8_t naluTypeFU = 49 ;
23
24
25
+ H265RtpDepacketizer::H265RtpDepacketizer (Separator separator) : separator(separator) {
26
+ switch (separator) {
27
+ case Separator::StartSequence: [[fallthrough]];
28
+ case Separator::LongStartSequence: [[fallthrough]];
29
+ case Separator::ShortStartSequence:
30
+ break ;
31
+ case Separator::Length: [[fallthrough]];
32
+ default :
33
+ throw std::invalid_argument (" Invalid separator" );
34
+ }
35
+ }
36
+
37
+ void H265RtpDepacketizer::addSeparator (binary& accessUnit)
38
+ {
39
+ switch (separator) {
40
+ case Separator::StartSequence: [[fallthrough]];
41
+ case Separator::LongStartSequence:
42
+ accessUnit.insert (accessUnit.end (),
43
+ naluLongStartCode.begin (),
44
+ naluLongStartCode.end ());
45
+ break ;
46
+ case Separator::ShortStartSequence:
47
+ accessUnit.insert (accessUnit.end (),
48
+ naluShortStartCode.begin (),
49
+ naluShortStartCode.end ());
50
+ break ;
51
+ case Separator::Length: [[fallthrough]];
52
+ default :
53
+ throw std::invalid_argument (" Invalid separator" );
54
+ }
55
+ }
56
+
24
57
message_vector H265RtpDepacketizer::buildFrames (message_vector::iterator begin,
25
58
message_vector::iterator end, uint32_t timestamp) {
26
59
message_vector out = {};
@@ -52,8 +85,7 @@ message_vector H265RtpDepacketizer::buildFrames(message_vector::iterator begin,
52
85
std::to_integer<uint8_t >(pkt->at (rtpHeaderSize + sizeof (H265NalUnitHeader)))};
53
86
54
87
if (nFrags++ == 0 ) {
55
- accessUnit.insert (accessUnit.end (), naluStartCode.begin (), naluStartCode.end ());
56
-
88
+ addSeparator (accessUnit);
57
89
nalUnitHeader.setUnitType (nalUnitFragmentHeader.unitType ());
58
90
accessUnit.emplace_back (byte (nalUnitHeader._first ));
59
91
accessUnit.emplace_back (byte (nalUnitHeader._second ));
@@ -76,8 +108,7 @@ message_vector H265RtpDepacketizer::buildFrames(message_vector::iterator begin,
76
108
throw std::runtime_error (" H265 AP declared size is larger than buffer" );
77
109
}
78
110
79
- accessUnit.insert (accessUnit.end (), naluStartCode.begin (), naluStartCode.end ());
80
-
111
+ addSeparator (accessUnit);
81
112
accessUnit.insert (accessUnit.end (), pkt->begin () + currOffset,
82
113
pkt->begin () + currOffset + naluSize);
83
114
@@ -86,7 +117,7 @@ message_vector H265RtpDepacketizer::buildFrames(message_vector::iterator begin,
86
117
} else if (nalUnitHeader.unitType () < naluTypeAP) {
87
118
// "NAL units with NAL unit type values in the range of 0 to 47, inclusive, may be
88
119
// passed to the decoder."
89
- accessUnit. insert (accessUnit. end (), naluStartCode. begin (), naluStartCode. end () );
120
+ addSeparator (accessUnit);
90
121
accessUnit.insert (accessUnit.end (), pkt->begin () + rtpHeaderSize, pkt->end ());
91
122
} else {
92
123
// "NAL-unit-like structures with NAL unit type values in the range of 48 to 63,
0 commit comments