Commit f44100de authored by Thomas Guillem's avatar Thomas Guillem

h264_nal: fix h264_get_spspps

Don't end the NAL unit when we reach 0x000000. Refactor since we don't need to
parse separately the start and the end of the NAL unit anymore.
parent 119d06b0
...@@ -322,59 +322,52 @@ int h264_get_spspps( uint8_t *p_buf, size_t i_buf, ...@@ -322,59 +322,52 @@ int h264_get_spspps( uint8_t *p_buf, size_t i_buf,
{ {
unsigned int i_move = 1; unsigned int i_move = 1;
if( i_nal_type == NAL_UNKNOWN ) /* cf B.1.1: a NAL unit starts and ends with 0x000001 or 0x00000001 */
if( i_buf > 3 && !memcmp( p_buf, annexb_startcode, 3 ) )
{ {
if( i_buf > 4 && !memcmp( p_buf, annexb_startcode, 3 ) ) if( i_nal_type != NAL_UNKNOWN )
{
i_nal_type = p_buf[3] & 0x1F;
i_move = 4;
/* The start prefix is always 0x00000001 (annexb_startcode + a
* leading zero byte) for SPS, PPS or the first NAL */
if( !b_has_zero_byte && ( b_first_nal || i_nal_type == NAL_SPS
|| i_nal_type == NAL_PPS ) )
return -1;
b_first_nal = false;
/* Pointer to the beginning of the SPS/PPS starting with the
* leading zero byte */
if( i_nal_type == NAL_SPS && !p_sps )
p_sps = p_buf - 1;
if( i_nal_type == NAL_PPS && !p_pps )
p_pps = p_buf - 1;
/* cf. 7.4.1.2.3 */
if( i_nal_type > 18 || ( i_nal_type >= 10 && i_nal_type <= 12 ) )
return -1;
/* SPS/PPS are before the slices */
if ( i_nal_type >= NAL_SLICE && i_nal_type <= NAL_SLICE_IDR )
break;
} else if( b_first_nal && p_buf[0] != 0 )
{
/* leading_zero_8bits only before the first NAL */
return -1;
}
}
else
{
/* cf B.3-3: a NAL unit ends with 0x000000, 0x000001 or with the
* end of the bytestream */
if( i_buf > 3 && p_buf[0] == 0 && p_buf[1] == 0
&& ( p_buf[2] == 0 || p_buf[2] == 1 ) )
{ {
/* update SPS/PPS size */ /* update SPS/PPS size */
if( i_nal_type == NAL_SPS ) if( i_nal_type == NAL_SPS )
i_sps_size = p_buf - p_sps; i_sps_size = p_buf - p_sps - (b_has_zero_byte ? 1 : 0);
if( i_nal_type == NAL_PPS ) if( i_nal_type == NAL_PPS )
i_pps_size = p_buf - p_pps; i_pps_size = p_buf - p_pps - (b_has_zero_byte ? 1 : 0);
if( i_sps_size && i_pps_size ) if( i_sps_size && i_pps_size )
break; break;
i_nal_type = NAL_UNKNOWN;
i_move = 0;
} }
if (i_buf < 4)
return -1;
i_nal_type = p_buf[3] & 0x1F;
/* The start prefix is always 0x00000001 (annexb_startcode + a
* leading zero byte) for SPS, PPS or the first NAL */
if( !b_has_zero_byte && ( b_first_nal || i_nal_type == NAL_SPS
|| i_nal_type == NAL_PPS ) )
return -1;
b_first_nal = false;
/* Pointer to the beginning of the SPS/PPS starting with the
* leading zero byte */
if( i_nal_type == NAL_SPS && !p_sps )
p_sps = p_buf - 1;
if( i_nal_type == NAL_PPS && !p_pps )
p_pps = p_buf - 1;
/* cf. 7.4.1.2.3 */
if( i_nal_type > 18 || ( i_nal_type >= 10 && i_nal_type <= 12 ) )
return -1;
/* SPS/PPS are before the slices */
if ( i_nal_type >= NAL_SLICE && i_nal_type <= NAL_SLICE_IDR )
break;
i_move = 4;
}
else if( b_first_nal && p_buf[0] != 0 )
{
/* leading_zero_8bits only before the first NAL */
return -1;
} }
b_has_zero_byte = *p_buf == 0; b_has_zero_byte = *p_buf == 0;
i_buf -= i_move; i_buf -= i_move;
......
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