[FFmpeg-devel] [PATCH] mmfdec: fix seeking

Paul B Mahol onemda at gmail.com
Mon Dec 3 19:27:36 CET 2012


Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 libavformat/Makefile    |  2 +-
 libavformat/mmf.c       | 16 ++++++++--------
 tests/ref/seek/lavf-mmf | 51 ++++++++++++++++++++++++++++++++-----------------
 3 files changed, 43 insertions(+), 26 deletions(-)

diff --git a/libavformat/Makefile b/libavformat/Makefile
index daa406f..1b1f6c1 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -172,7 +172,7 @@ OBJS-$(CONFIG_MJPEG_MUXER)               += rawenc.o
 OBJS-$(CONFIG_MLP_DEMUXER)               += rawdec.o
 OBJS-$(CONFIG_MLP_MUXER)                 += rawenc.o
 OBJS-$(CONFIG_MM_DEMUXER)                += mm.o
-OBJS-$(CONFIG_MMF_DEMUXER)               += mmf.o pcm.o
+OBJS-$(CONFIG_MMF_DEMUXER)               += mmf.o
 OBJS-$(CONFIG_MMF_MUXER)                 += mmf.o
 OBJS-$(CONFIG_MOV_DEMUXER)               += mov.o isom.o mov_chan.o
 OBJS-$(CONFIG_MOV_MUXER)                 += movenc.o isom.o avc.o \
diff --git a/libavformat/mmf.c b/libavformat/mmf.c
index 38c6970..dee8546 100644
--- a/libavformat/mmf.c
+++ b/libavformat/mmf.c
@@ -28,7 +28,7 @@
 
 typedef struct {
     int64_t atrpos, atsqpos, awapos;
-    int64_t data_size;
+    int64_t data_end;
 } MMFContext;
 
 static const int mmf_rates[] = { 4000, 8000, 11025, 22050, 44100 };
@@ -241,7 +241,7 @@ static int mmf_read_header(AVFormatContext *s)
         av_log(s, AV_LOG_ERROR, "Unexpected SMAF chunk %08x\n", tag);
         return -1;
     }
-    mmf->data_size = size;
+    mmf->data_end = avio_tell(pb) + size;
 
     st = avformat_new_stream(s, NULL);
     if (!st)
@@ -266,19 +266,19 @@ static int mmf_read_packet(AVFormatContext *s,
                            AVPacket *pkt)
 {
     MMFContext *mmf = s->priv_data;
-    int ret, size;
+    int64_t left, size;
+    int ret;
 
-    if (url_feof(s->pb) || !mmf->data_size)
+    left = mmf->data_end - avio_tell(s->pb);
+    size = FFMIN(left, MAX_SIZE);
+    if (url_feof(s->pb) || size <= 0)
         return AVERROR_EOF;
 
-    size = FFMIN(MAX_SIZE, mmf->data_size);
-
     ret = av_get_packet(s->pb, pkt, size);
     if (ret < 0)
         return ret;
 
     pkt->stream_index = 0;
-    mmf->data_size -= ret;
 
     return ret;
 }
@@ -291,7 +291,7 @@ AVInputFormat ff_mmf_demuxer = {
     .read_probe     = mmf_probe,
     .read_header    = mmf_read_header,
     .read_packet    = mmf_read_packet,
-    .read_seek      = ff_pcm_read_seek,
+    .flags          = AVFMT_GENERIC_INDEX,
 };
 #endif
 #if CONFIG_MMF_MUXER
diff --git a/tests/ref/seek/lavf-mmf b/tests/ref/seek/lavf-mmf
index b7fd5f5..9324d0d 100644
--- a/tests/ref/seek/lavf-mmf
+++ b/tests/ref/seek/lavf-mmf
@@ -1,27 +1,44 @@
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     81 size:  4096
-ret:-1         st:-1 flags:0  ts:-1.000000
-ret:-1         st:-1 flags:1  ts: 1.894167
-ret:-1         st: 0 flags:0  ts: 0.788345
+ret: 0         st:-1 flags:0  ts:-1.000000
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     81 size:  4096
+ret: 0         st:-1 flags:1  ts: 1.894167
+ret: 0         st: 0 flags:1 dts: 0.928798 pts: 0.928798 pos:  20561 size:  2048
+ret: 0         st: 0 flags:0  ts: 0.788345
+ret: 0         st: 0 flags:1 dts: 0.928798 pts: 0.928798 pos:  20561 size:  2048
 ret:-1         st: 0 flags:1  ts:-0.317506
 ret:-1         st:-1 flags:0  ts: 2.576668
-ret:-1         st:-1 flags:1  ts: 1.470835
-ret:-1         st: 0 flags:0  ts: 0.365011
+ret: 0         st:-1 flags:1  ts: 1.470835
+ret: 0         st: 0 flags:1 dts: 0.928798 pts: 0.928798 pos:  20561 size:  2048
+ret: 0         st: 0 flags:0  ts: 0.365011
+ret: 0         st: 0 flags:1 dts: 0.371519 pts: 0.371519 pos:   8273 size:  4096
 ret:-1         st: 0 flags:1  ts:-0.740839
 ret:-1         st:-1 flags:0  ts: 2.153336
-ret:-1         st:-1 flags:1  ts: 1.047503
-ret:-1         st: 0 flags:0  ts:-0.058322
-ret:-1         st: 0 flags:1  ts: 2.835828
+ret: 0         st:-1 flags:1  ts: 1.047503
+ret: 0         st: 0 flags:1 dts: 0.928798 pts: 0.928798 pos:  20561 size:  2048
+ret: 0         st: 0 flags:0  ts:-0.058322
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     81 size:  4096
+ret: 0         st: 0 flags:1  ts: 2.835828
+ret: 0         st: 0 flags:1 dts: 0.928798 pts: 0.928798 pos:  20561 size:  2048
 ret:-1         st:-1 flags:0  ts: 1.730004
-ret:-1         st:-1 flags:1  ts: 0.624171
-ret:-1         st: 0 flags:0  ts:-0.481655
-ret:-1         st: 0 flags:1  ts: 2.412494
+ret: 0         st:-1 flags:1  ts: 0.624171
+ret: 0         st: 0 flags:1 dts: 0.557279 pts: 0.557279 pos:  12369 size:  4096
+ret: 0         st: 0 flags:0  ts:-0.481655
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     81 size:  4096
+ret: 0         st: 0 flags:1  ts: 2.412494
+ret: 0         st: 0 flags:1 dts: 0.928798 pts: 0.928798 pos:  20561 size:  2048
 ret:-1         st:-1 flags:0  ts: 1.306672
-ret:-1         st:-1 flags:1  ts: 0.200839
-ret:-1         st: 0 flags:0  ts:-0.904989
-ret:-1         st: 0 flags:1  ts: 1.989184
-ret:-1         st:-1 flags:0  ts: 0.883340
+ret: 0         st:-1 flags:1  ts: 0.200839
+ret: 0         st: 0 flags:1 dts: 0.185760 pts: 0.185760 pos:   4177 size:  4096
+ret: 0         st: 0 flags:0  ts:-0.904989
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     81 size:  4096
+ret: 0         st: 0 flags:1  ts: 1.989184
+ret: 0         st: 0 flags:1 dts: 0.928798 pts: 0.928798 pos:  20561 size:  2048
+ret: 0         st:-1 flags:0  ts: 0.883340
+ret: 0         st: 0 flags:1 dts: 0.928798 pts: 0.928798 pos:  20561 size:  2048
 ret:-1         st:-1 flags:1  ts:-0.222493
 ret:-1         st: 0 flags:0  ts: 2.671678
-ret:-1         st: 0 flags:1  ts: 1.565850
-ret:-1         st:-1 flags:0  ts: 0.460008
+ret: 0         st: 0 flags:1  ts: 1.565850
+ret: 0         st: 0 flags:1 dts: 0.928798 pts: 0.928798 pos:  20561 size:  2048
+ret: 0         st:-1 flags:0  ts: 0.460008
+ret: 0         st: 0 flags:1 dts: 0.557279 pts: 0.557279 pos:  12369 size:  4096
 ret:-1         st:-1 flags:1  ts:-0.645825
-- 
1.7.11.4



More information about the ffmpeg-devel mailing list