@@ -22,14 +22,14 @@ namespace rtc_adapter {
2222// in up to 2 times max video bitrate if the bandwidth estimate allows it.
2323static const int TRANSMISSION_MAXBITRATE_MULTIPLIER = 2 ;
2424
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 )
2626{
27- if (buffer_size < 4 ) {
27+ if (buffer_size < 3 ) {
2828 return -1 ;
2929 }
3030 is_aud_or_sei = false ;
3131 uint8_t * head = buffer;
32- uint8_t * end = buffer + buffer_size - 4 ;
32+ uint8_t * end = buffer + buffer_size - 3 ;
3333 while (head < end) {
3434 if (head[0 ]) {
3535 head++;
@@ -40,17 +40,27 @@ static int getNextNaluPosition(uint8_t* buffer, int buffer_size, bool& is_aud_or
4040 continue ;
4141 }
4242 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+ }
4350 head += 3 ;
4451 continue ;
4552 }
4653 if (head[3 ] != 0x01 ) {
4754 head++;
4855 continue ;
4956 }
57+ if (head + 1 == end) {
58+ break ;
59+ }
5060 if (((head[4 ] & 0x1F ) == 9 ) || ((head[4 ] & 0x1F ) == 6 )) {
5161 is_aud_or_sei = true ;
5262 }
53-
63+ sc_len = 4 ;
5464 return static_cast <int >(head - buffer);
5565 }
5666 return -1 ;
@@ -70,15 +80,16 @@ static int dropAUDandSEI(uint8_t* framePayload, int frameLength)
7080
7181 int sc_positions_length = 0 ;
7282 int sc_position = 0 ;
83+ int sc_len = 4 ;
7384 while (sc_positions_length < MAX_NALS_PER_FRAME) {
7485 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 );
7687 if (nalu_position < 0 ) {
7788 break ;
7889 }
7990 sc_position += nalu_position;
8091 nal_offset.push_back (sc_position); // include start code.
81- sc_position += 4 ;
92+ sc_position += sc_len ;
8293 sc_positions_length++;
8394 if (is_aud_or_sei) {
8495 has_aud_or_sei = true ;
0 commit comments