Commit aa51f404 authored by Ilkka Ollakka's avatar Ilkka Ollakka

mp4: find nal limits on 0*001 startcode instead 0001

parent 0023f19d
...@@ -873,37 +873,44 @@ static bo_t *GetAvcCTag( mp4_stream_t *p_stream ) ...@@ -873,37 +873,44 @@ static bo_t *GetAvcCTag( mp4_stream_t *p_stream )
uint8_t *p_buffer = p_stream->fmt.p_extra; uint8_t *p_buffer = p_stream->fmt.p_extra;
int i_buffer = p_stream->fmt.i_extra; int i_buffer = p_stream->fmt.i_extra;
while( i_buffer > 4 && while( i_buffer > 3 )
p_buffer[0] == 0 && p_buffer[1] == 0 &&
p_buffer[2] == 0 && p_buffer[3] == 1 )
{ {
const int i_nal_type = p_buffer[4]&0x1f; /* seek startcode */
while( p_buffer[0] != 0 || p_buffer[1] != 0 ||
p_buffer[2] != 1 )
{
i_buffer--;
p_buffer++;
}
const int i_nal_type = p_buffer[3]&0x1f;
int i_offset = 1; int i_offset = 1;
int i_size = 0; int i_size = 0;
int i_startcode = 0; int i_startcode = 0;
//msg_Dbg( p_stream, "we found a startcode for NAL with TYPE:%d", i_nal_type );
for( i_offset = 1; i_offset+3 < i_buffer ; i_offset++) for( i_offset = 1; i_offset+2 < i_buffer ; i_offset++)
{ {
if( p_buffer[i_offset] == 0 && p_buffer[i_offset+1] == 0 && if( p_buffer[i_offset] == 0 && p_buffer[i_offset+1] == 0 &&
p_buffer[i_offset+2] == 0 && p_buffer[i_offset+3] == 1 ) p_buffer[i_offset+2] == 1 )
{ {
/* we found another startcode */ /* we found another startcode */
i_startcode = i_offset; i_startcode = i_offset;
while( p_buffer[i_startcode-1] == 0 && i_startcode > 0 )
i_startcode--;
break; break;
} }
} }
i_size = i_startcode ? i_startcode : i_buffer; i_size = i_startcode ? i_startcode : i_buffer;
if( i_nal_type == 7 ) if( i_nal_type == 7 )
{ {
p_sps = &p_buffer[4]; p_sps = &p_buffer[3];
i_sps_size = i_size - 4; i_sps_size = i_size - 3;
} }
if( i_nal_type == 8 ) if( i_nal_type == 8 )
{ {
p_pps = &p_buffer[4]; p_pps = &p_buffer[3];
i_pps_size = i_size - 4; i_pps_size = i_size - 3;
} }
i_buffer -= i_size; i_buffer -= i_size;
p_buffer += i_size; p_buffer += i_size;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment