@@ -22,14 +22,14 @@ namespace rtc_adapter {
22
22
// in up to 2 times max video bitrate if the bandwidth estimate allows it.
23
23
static const int TRANSMISSION_MAXBITRATE_MULTIPLIER = 2 ;
24
24
25
- static int getNextNaluPosition (uint8_t * buffer, int buffer_size, bool & is_aud_or_sei)
25
+ static int getNextNaluPosition (uint8_t * buffer, int buffer_size, bool & is_aud_or_sei, int & sc_len )
26
26
{
27
- if (buffer_size < 4 ) {
27
+ if (buffer_size < 3 ) {
28
28
return -1 ;
29
29
}
30
30
is_aud_or_sei = false ;
31
31
uint8_t * head = buffer;
32
- uint8_t * end = buffer + buffer_size - 4 ;
32
+ uint8_t * end = buffer + buffer_size - 3 ;
33
33
while (head < end) {
34
34
if (head[0 ]) {
35
35
head++;
@@ -40,17 +40,27 @@ static int getNextNaluPosition(uint8_t* buffer, int buffer_size, bool& is_aud_or
40
40
continue ;
41
41
}
42
42
if (head[2 ]) {
43
+ if (head[2 ] == 0x01 ) {
44
+ if (((head[3 ] & 0x1F ) == 9 ) || ((head[3 ] & 0x1F ) == 6 )) {
45
+ is_aud_or_sei = true ;
46
+ }
47
+ sc_len = 3 ;
48
+ return static_cast <int >(head - buffer);
49
+ }
43
50
head += 3 ;
44
51
continue ;
45
52
}
46
53
if (head[3 ] != 0x01 ) {
47
54
head++;
48
55
continue ;
49
56
}
57
+ if (head + 1 == end) {
58
+ break ;
59
+ }
50
60
if (((head[4 ] & 0x1F ) == 9 ) || ((head[4 ] & 0x1F ) == 6 )) {
51
61
is_aud_or_sei = true ;
52
62
}
53
-
63
+ sc_len = 4 ;
54
64
return static_cast <int >(head - buffer);
55
65
}
56
66
return -1 ;
@@ -70,15 +80,16 @@ static int dropAUDandSEI(uint8_t* framePayload, int frameLength)
70
80
71
81
int sc_positions_length = 0 ;
72
82
int sc_position = 0 ;
83
+ int sc_len = 4 ;
73
84
while (sc_positions_length < MAX_NALS_PER_FRAME) {
74
85
int nalu_position = getNextNaluPosition (origin_pkt_data + sc_position,
75
- origin_pkt_length - sc_position, is_aud_or_sei);
86
+ origin_pkt_length - sc_position, is_aud_or_sei, sc_len );
76
87
if (nalu_position < 0 ) {
77
88
break ;
78
89
}
79
90
sc_position += nalu_position;
80
91
nal_offset.push_back (sc_position); // include start code.
81
- sc_position += 4 ;
92
+ sc_position += sc_len ;
82
93
sc_positions_length++;
83
94
if (is_aud_or_sei) {
84
95
has_aud_or_sei = true ;
0 commit comments