diff mbox series

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

Message ID 20200219002150.27705-3-rcombs@rcombs.me
State New
Headers show
Series [FFmpeg-devel,1/3] lavf: add read_flush function to AVInputFormat vtable
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

rcombs Feb. 19, 2020, 12:21 a.m. UTC
---
 libavformat/matroskadec.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

Comments

Andreas Rheinhardt Feb. 19, 2020, 12:44 a.m. UTC | #1
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"
>  };
>  
>
diff mbox series

Patch

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++)
+        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;
+    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"
 };