[FFmpeg-devel] [PATCH 3/3] lavf/matroskadec: add read_flush function

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Wed Feb 19 02:44:00 EET 2020


rcombs:
> ---
>  libavformat/matroskadec.c | 23 +++++++++++++++++------
>  1 file changed, 17 insertions(+), 6 deletions(-)
> 
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index 4d7fdab99f..68e424992a 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -3703,6 +3703,21 @@ static int matroska_read_packet(AVFormatContext *s, AVPacket *pkt)
>      return 0;
>  }
>  
> +static void matroska_read_flush(AVFormatContext *s)
> +{
> +    MatroskaDemuxContext *matroska = s->priv_data;
> +    int i;
> +
> +    matroska_reset_status(matroska, 0, -1);
> +    matroska->resync_pos = -1;
> +    matroska_clear_queue(matroska);
> +    matroska->skip_to_keyframe = 0;
> +    matroska->done = 0;
> +
> +    for (i = 0; i < s->nb_streams; i++)

AVFormatContext.nb_streams is actually unsigned, so maybe i should be,
too? (It is nevertheless not dangerous, as it is checked that
nb_streams is in the range of int. (And strangely AVStream.index is
int, too.))

> +        s->streams[i]->skip_to_keyframe = 0;
> +}
> +
>  static int matroska_read_seek(AVFormatContext *s, int stream_index,
>                                int64_t timestamp, int flags)
>  {
> @@ -3758,12 +3773,7 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index,
>  err:
>      // slightly hackish but allows proper fallback to
>      // the generic seeking code.
> -    matroska_reset_status(matroska, 0, -1);
> -    matroska->resync_pos = -1;
> -    matroska_clear_queue(matroska);
> -    st->skip_to_keyframe =
> -    matroska->skip_to_keyframe = 0;
> -    matroska->done = 0;

I just noticed that the resetting of the RealAudio stuff (see the loop
above) doesn't happen when falling back to the generic seeking code.
You should add code for it in matroska_read_flush().

> +    matroska_read_flush(s);
>      return -1;
>  }
>  
> @@ -4200,6 +4210,7 @@ AVInputFormat ff_matroska_demuxer = {
>      .read_packet    = matroska_read_packet,
>      .read_close     = matroska_read_close,
>      .read_seek      = matroska_read_seek,
> +    .read_flush     = matroska_read_flush,
>      .mime_type      = "audio/webm,audio/x-matroska,video/webm,video/x-matroska"
>  };
>  
> 



More information about the ffmpeg-devel mailing list