diff mbox series

[FFmpeg-devel] avformat/argo_asf: implement seeking

Message ID 20200921112132.21688-1-zane@zanevaniperen.com
State Accepted
Commit 003b5c800fef909fa84dd2fae43d66bd434d3f7e
Headers show
Series [FFmpeg-devel] avformat/argo_asf: implement seeking
Related show

Checks

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

Commit Message

Zane van Iperen Sept. 21, 2020, 11:21 a.m. UTC
Causes some error as the ADPCM predictors aren't known, but
the difference is negligible and not audible.

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
---
 libavformat/argo_asf.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

Comments

Zane van Iperen Sept. 22, 2020, 12:57 p.m. UTC | #1
On Mon, 21 Sep 2020 11:21:47 +0000
"Zane van Iperen" <zane@zanevaniperen.com> wrote:

> 
> Causes some error as the ADPCM predictors aren't known, but
> the difference is negligible and not audible.
> 

Ping. Will merge tomorrow if no objections.
diff mbox series

Patch

diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c
index 6f7d9e93c9..de941caeac 100644
--- a/libavformat/argo_asf.c
+++ b/libavformat/argo_asf.c
@@ -238,12 +238,34 @@  static int argo_asf_read_packet(AVFormatContext *s, AVPacket *pkt)
 
     pkt->stream_index   = st->index;
     pkt->duration       = asf->ckhdr.num_samples * (ret / st->codecpar->block_align);
+    pkt->pts            = asf->blocks_read * asf->ckhdr.num_samples;
     asf->blocks_read   += (ret / st->codecpar->block_align);
 
     pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
     return 0;
 }
 
+static int argo_asf_seek(AVFormatContext *s, int stream_index,
+                         int64_t pts, int flags)
+{
+    ArgoASFDemuxContext *asf = s->priv_data;
+    AVStream *st             = s->streams[stream_index];
+    int64_t offset;
+    uint32_t block = pts / asf->ckhdr.num_samples;
+
+    if (block >= asf->ckhdr.num_blocks)
+        return -1;
+
+    offset = asf->fhdr.chunk_offset + ASF_CHUNK_HEADER_SIZE +
+             (block * st->codecpar->block_align);
+
+    if ((offset = avio_seek(s->pb, offset, SEEK_SET)) < 0)
+        return offset;
+
+    asf->blocks_read = block;
+    return 0;
+}
+
 /*
  * Not actually sure what ASF stands for.
  * - Argonaut Sound File?
@@ -255,7 +277,8 @@  AVInputFormat ff_argo_asf_demuxer = {
     .priv_data_size = sizeof(ArgoASFDemuxContext),
     .read_probe     = argo_asf_probe,
     .read_header    = argo_asf_read_header,
-    .read_packet    = argo_asf_read_packet
+    .read_packet    = argo_asf_read_packet,
+    .read_seek      = argo_asf_seek,
 };
 #endif