[vlc-devel] [PATCH] demux: avformat: handle AV_PKT_DATA_NEW_EXTRADATA

"zhilizhao(赵志立)" quinkblack at foxmail.com
Mon Jan 4 09:25:49 UTC 2021



> On Jan 4, 2021, at 4:29 PM, Steve Lhomme <robux4 at ycbcr.xyz> wrote:
> 
> This seems supported in ffmpeg since 2011 so should not be an issue depending on the ffmpeg version we support in 4.0.
> 
> For seeking we may have to keep the extradata with their timestamp somewhere and use the proper value when seeking back (there's no way to know in advance for seeks in the future). In Matroska in Cues there's a way to tell such changes but it's not exposed by libavformat.
> 
> Comments below.
> 
> On 2020-12-30 15:15, Zhao Zhili wrote:
>> This is a best-effort solution. Seek may not work as expected.
>> ---
>>  modules/demux/avformat/demux.c | 27 ++++++++++++++++++++++++++-
>>  1 file changed, 26 insertions(+), 1 deletion(-)
>> diff --git a/modules/demux/avformat/demux.c b/modules/demux/avformat/demux.c
>> index 4a765b7352..44cd778964 100644
>> --- a/modules/demux/avformat/demux.c
>> +++ b/modules/demux/avformat/demux.c
>> @@ -55,6 +55,7 @@ struct avformat_track_s
>>  {
>>      es_out_id_t *p_es;
>>      vlc_tick_t i_pcr;
>> +    es_format_t es_format;
>>  };
>>    /*****************************************************************************
>> @@ -711,6 +712,7 @@ int avformat_OpenDemux( vlc_object_t *p_this )
>>                es_fmt.i_id = i;
>>              p_track->p_es = es_out_Add( p_demux->out, &es_fmt );
>> +            es_format_Copy( &p_track->es_format, &es_fmt );
> 
> If the ES was not added (p_track->p_es) you probably don't want to keep the format anyway.

Will check on p_track->p_es.

> 
>>              if( p_track->p_es && (s->disposition & AV_DISPOSITION_DEFAULT) )
>>                  es_out_Control( p_demux->out, ES_OUT_SET_ES_DEFAULT, p_track->p_es );
>>  @@ -766,7 +768,12 @@ void avformat_CloseDemux( vlc_object_t *p_this )
>>      demux_t     *p_demux = (demux_t*)p_this;
>>      demux_sys_t *p_sys = p_demux->p_sys;
>>  -    free( p_sys->tracks );
>> +    if( p_sys->tracks != NULL )
>> +    {
>> +        for( unsigned i = 0; i < p_sys->i_tracks; i++ )
>> +            es_format_Clean( &p_sys->tracks[i].es_format );
>> +        free( p_sys->tracks );
>> +    }
>>        if( p_sys->ic )
>>      {
>> @@ -821,6 +828,24 @@ static int Demux( demux_t *p_demux )
>>          av_packet_unref( &pkt );
>>          return 1;
>>      }
>> +
>> +    // handle extra data change, this can happen for FLV
>> +    int side_data_size;
>> +    uint8_t *side_data = av_packet_get_side_data( &pkt, AV_PKT_DATA_NEW_EXTRADATA, &side_data_size );
>> +    if( side_data != NULL && side_data_size > 0 ) {
>> +        msg_Warn( p_demux, "New extra data found, seek may not work as expected" );
>> +        void *p_extra = realloc( p_track->es_format.p_extra, side_data_size );
>> +        if( p_extra == NULL )
>> +        {
>> +            av_packet_unref( &pkt );
>> +            return 0;
>> +        }
>> +        p_track->es_format.p_extra = p_extra;
> 
> Missing free of the previous version.

There is memory leaks here since es_format will be cleaned during CloseDemux().
Free extra data at here and the following error case will make the code a litter cumbersome.
Is there something I’m missing?

> 
>> +        memcpy( p_track->es_format.p_extra, side_data, side_data_size );
>> +        p_track->es_format.i_extra = side_data_size;
>> +        es_out_Control( p_demux->out, ES_OUT_SET_ES_FMT, p_track->p_es, &p_track->es_format );
> 
> This may fail. The same error handling as above should be done.

Will update the patch.

> 
>> +    }
>> +
>>      if( p_stream->codecpar->codec_id == AV_CODEC_ID_SSA )
>>      {
>>          p_frame = BuildSsaFrame( &pkt, p_sys->i_ssa_order++ );
>> -- 
>> 2.25.1
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> https://mailman.videolan.org/listinfo/vlc-devel
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel



More information about the vlc-devel mailing list