diff mbox series

[FFmpeg-devel] avformat/smacker: Support seeking to first frame

Message ID 20200724041021.23977-1-andreas.rheinhardt@gmail.com
State Accepted
Commit edea15657981ac85baa058f6cdb5588171349b83
Headers show
Series [FFmpeg-devel] avformat/smacker: Support seeking to first frame | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt July 24, 2020, 4:10 a.m. UTC
From: Timotej Lazar <timotej.lazar@araneo.si>

Add .read_seek function to the smacker demuxer for the special case of
seeking to ts=0. This is useful because smacker – like bink, with a
similar implementation – was mostly used to encode clips in video
games, where random seeks are rare but looping media are common.

Signed-off-by: Timotej Lazar <timotej.lazar@araneo.si>
---
 libavformat/smacker.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Comments

Andreas Rheinhardt July 27, 2020, 1:41 a.m. UTC | #1
Andreas Rheinhardt:
> From: Timotej Lazar <timotej.lazar@araneo.si>
> 
> Add .read_seek function to the smacker demuxer for the special case of
> seeking to ts=0. This is useful because smacker – like bink, with a
> similar implementation – was mostly used to encode clips in video
> games, where random seeks are rare but looping media are common.
> 
> Signed-off-by: Timotej Lazar <timotej.lazar@araneo.si>
> ---
>  libavformat/smacker.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/libavformat/smacker.c b/libavformat/smacker.c
> index 0ca5a87b8f..5507e7c169 100644
> --- a/libavformat/smacker.c
> +++ b/libavformat/smacker.c
> @@ -349,6 +349,31 @@ next_frame:
>      return ret;
>  }
>  
> +static int smacker_read_seek(AVFormatContext *s, int stream_index,
> +                             int64_t timestamp, int flags)
> +{
> +    SmackerContext *smk = s->priv_data;
> +    int64_t ret;
> +
> +    /* only rewinding to start is supported */
> +    if (timestamp != 0) {
> +        av_log(s, AV_LOG_ERROR,
> +               "Random seeks are not supported (can only seek to start).\n");
> +        return AVERROR(EINVAL);
> +    }
> +
> +    if ((ret = avio_seek(s->pb, s->internal->data_offset, SEEK_SET)) < 0)
> +        return ret;
> +
> +    smk->cur_frame = 0;
> +    smk->next_audio_index = 0;
> +    smk->new_palette = 0;
> +    memset(smk->pal, 0, sizeof(smk->pal));
> +    memset(smk->aud_pts, 0, sizeof(smk->aud_pts));
> +
> +    return 0;
> +}
> +
>  AVInputFormat ff_smacker_demuxer = {
>      .name           = "smk",
>      .long_name      = NULL_IF_CONFIG_SMALL("Smacker"),
> @@ -356,4 +381,5 @@ AVInputFormat ff_smacker_demuxer = {
>      .read_probe     = smacker_probe,
>      .read_header    = smacker_read_header,
>      .read_packet    = smacker_read_packet,
> +    .read_seek      = smacker_read_seek,
>  };
> 
Will apply this patchset tomorrow unless there are objections.

- Andreas
diff mbox series

Patch

diff --git a/libavformat/smacker.c b/libavformat/smacker.c
index 0ca5a87b8f..5507e7c169 100644
--- a/libavformat/smacker.c
+++ b/libavformat/smacker.c
@@ -349,6 +349,31 @@  next_frame:
     return ret;
 }
 
+static int smacker_read_seek(AVFormatContext *s, int stream_index,
+                             int64_t timestamp, int flags)
+{
+    SmackerContext *smk = s->priv_data;
+    int64_t ret;
+
+    /* only rewinding to start is supported */
+    if (timestamp != 0) {
+        av_log(s, AV_LOG_ERROR,
+               "Random seeks are not supported (can only seek to start).\n");
+        return AVERROR(EINVAL);
+    }
+
+    if ((ret = avio_seek(s->pb, s->internal->data_offset, SEEK_SET)) < 0)
+        return ret;
+
+    smk->cur_frame = 0;
+    smk->next_audio_index = 0;
+    smk->new_palette = 0;
+    memset(smk->pal, 0, sizeof(smk->pal));
+    memset(smk->aud_pts, 0, sizeof(smk->aud_pts));
+
+    return 0;
+}
+
 AVInputFormat ff_smacker_demuxer = {
     .name           = "smk",
     .long_name      = NULL_IF_CONFIG_SMALL("Smacker"),
@@ -356,4 +381,5 @@  AVInputFormat ff_smacker_demuxer = {
     .read_probe     = smacker_probe,
     .read_header    = smacker_read_header,
     .read_packet    = smacker_read_packet,
+    .read_seek      = smacker_read_seek,
 };