X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcodec%2Fcrystalhd.c;h=e3e44b579f72553e9cee182dcec18fdbc74f9ad6;hb=2ef307b4e9e69c887ec2d554345015016ce55bbc;hp=ff60509d521041485685d71742e014cc7e390414;hpb=3d5114236a915140cc14597da76dc512aa3cff4f;p=vlc diff --git a/modules/codec/crystalhd.c b/modules/codec/crystalhd.c index ff60509d52..e3e44b579f 100644 --- a/modules/codec/crystalhd.c +++ b/modules/codec/crystalhd.c @@ -37,6 +37,7 @@ #include #include #include +#include "h264_nal.h" /* Workaround for some versions of libcrystalHD */ #if !defined(_WIN32) && !defined(__APPLE__) @@ -606,9 +607,7 @@ static int crystal_insert_sps_pps( decoder_t *p_dec, uint32_t i_buf_size) { decoder_sys_t *p_sys = p_dec->p_sys; - int i_profile; - uint32_t i_data_size = i_buf_size, i_nal_size; - unsigned int i_loop_end; + int ret; p_sys->i_sps_pps_size = 0; @@ -616,68 +615,14 @@ static int crystal_insert_sps_pps( decoder_t *p_dec, if( !p_sys->p_sps_pps_buf ) return VLC_ENOMEM; - /* */ - if( i_data_size < 7 ) - { - msg_Err( p_dec, "Input Metadata too small" ); - goto error; - } - - /* Read infos in first 6 bytes */ - i_profile = (p_buf[1] << 16) | (p_buf[2] << 8) | p_buf[3]; - p_sys->i_nal_size = (p_buf[4] & 0x03) + 1; - p_buf += 5; - i_data_size -= 5; - - for ( unsigned int j = 0; j < 2; j++ ) - { - /* First time is SPS, Second is PPS */ - if( i_data_size < 1 ) - { - msg_Err( p_dec, "PPS too small after processing SPS/PPS %u", - i_data_size ); - goto error; - } - i_loop_end = p_buf[0] & (j == 0 ? 0x1f : 0xff); - p_buf++; i_data_size--; - - for ( unsigned int i = 0; i < i_loop_end; i++) - { - if( i_data_size < 2 ) - { - msg_Err( p_dec, "SPS is too small %u", i_data_size ); - goto error; - } - - i_nal_size = (p_buf[0] << 8) | p_buf[1]; - p_buf += 2; - i_data_size -= 2; - - if( i_data_size < i_nal_size ) - { - msg_Err( p_dec, "SPS size does not match NAL specified size %u", - i_data_size ); - goto error; - } - - p_sys->p_sps_pps_buf[p_sys->i_sps_pps_size++] = 0; - p_sys->p_sps_pps_buf[p_sys->i_sps_pps_size++] = 0; - p_sys->p_sps_pps_buf[p_sys->i_sps_pps_size++] = 0; - p_sys->p_sps_pps_buf[p_sys->i_sps_pps_size++] = 1; + ret = convert_sps_pps( p_dec, p_buf, i_buf_size, p_sys->p_sps_pps_buf, + p_dec->fmt_in.i_extra * 2, &p_sys->i_sps_pps_size, + &p_sys->i_nal_size ); + if( !ret ) + return ret; - memcpy( p_sys->p_sps_pps_buf + p_sys->i_sps_pps_size, p_buf, i_nal_size ); - p_sys->i_sps_pps_size += i_nal_size; - - p_buf += i_nal_size; - i_data_size -= i_nal_size; - } - } - - return VLC_SUCCESS; - -error: free( p_sys->p_sps_pps_buf ); p_sys->p_sps_pps_buf = NULL; - return VLC_ENOMEM; + return ret; }