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