[FFmpeg-devel] [PATCH 3/3] avformat/dss: implement seeking

Michael Niedermayer michaelni at gmx.at
Tue Feb 24 15:22:39 CET 2015


This assumes CBR (which is true for all samples i have)

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavformat/dss.c |   39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/libavformat/dss.c b/libavformat/dss.c
index c595982..72c7e1a 100644
--- a/libavformat/dss.c
+++ b/libavformat/dss.c
@@ -340,6 +340,44 @@ static int dss_read_close(AVFormatContext *s)
     return 0;
 }
 
+static int dss_read_seek(AVFormatContext *s, int stream_index,
+                         int64_t timestamp, int flags)
+{
+    DSSDemuxContext *ctx = s->priv_data;
+    int64_t ret, seekto;
+    uint8_t header[6];
+    int offset;
+
+    if (ctx->audio_codec == DSS_ACODEC_DSS_SP)
+        seekto = timestamp / 264 * 41 / 506 * 512;
+    else
+        seekto = timestamp / 240 * ctx->packet_size / 506 * 512;
+
+    if (seekto < 0)
+        seekto = 0;
+
+    seekto += DSS_HEADER_SIZE;
+
+    ret = avio_seek(s->pb, seekto, SEEK_SET);
+    if (ret < 0)
+        return ret;
+
+    avio_read(s->pb, header, 6);
+    ctx->swap = !!(header[0] & 0x80);
+    offset = 2*header[1] + 2*ctx->swap;
+    if (offset < DSS_AUDIO_BLOCK_HEADER_SIZE)
+        return AVERROR_INVALIDDATA;
+    if (offset == DSS_AUDIO_BLOCK_HEADER_SIZE) {
+        ctx->counter = 0;
+        offset = avio_skip(s->pb, -DSS_AUDIO_BLOCK_HEADER_SIZE);
+    } else {
+        ctx->counter = DSS_BLOCK_SIZE - offset;
+        offset = avio_skip(s->pb, offset - DSS_AUDIO_BLOCK_HEADER_SIZE);
+    }
+    return 0;
+}
+
+
 AVInputFormat ff_dss_demuxer = {
     .name           = "dss",
     .long_name      = NULL_IF_CONFIG_SMALL("Digital Speech Standard (DSS)"),
@@ -348,5 +386,6 @@ AVInputFormat ff_dss_demuxer = {
     .read_header    = dss_read_header,
     .read_packet    = dss_read_packet,
     .read_close     = dss_read_close,
+    .read_seek      = dss_read_seek,
     .extensions     = "dss"
 };
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list