[vlc-devel] [PATCH] demux: avformat: handle AV_PKT_DATA_NEW_EXTRADATA
"zhilizhao(赵志立)"
quinkblack at foxmail.com
Wed Dec 30 14:18:01 UTC 2020
Sample file:
https://drive.google.com/file/d/1c3Dawdo4910lupAq0RoteOckLk0r5j-J/view?usp=sharing
> On Dec 30, 2020, at 10:15 PM, Zhao Zhili <quinkblack at foxmail.com> 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( 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;
> + 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 );
> + }
> +
> if( p_stream->codecpar->codec_id == AV_CODEC_ID_SSA )
> {
> p_frame = BuildSsaFrame( &pkt, p_sys->i_ssa_order++ );
> --
> 2.25.1
>
More information about the vlc-devel
mailing list