[FFmpeg-devel] [PATCH 6/7] lavf: move generic index generation code to a later point

Michael Niedermayer michaelni at gmx.at
Tue Jul 24 18:15:38 CEST 2012


Note the parser internal variables are not available at the later position
and thus are replaced by the more correct usage of pkt->pos.

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavformat/utils.c    |   14 ++++++--------
 tests/ref/seek/mp2_mp2 |   14 +++++---------
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 8a21e94..b43885e 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1229,14 +1229,6 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index)
 
         compute_pkt_fields(s, st, st->parser, &out_pkt);
 
-        if ((s->iformat->flags & AVFMT_GENERIC_INDEX) &&
-            out_pkt.flags & AV_PKT_FLAG_KEY) {
-            int64_t pos= (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? out_pkt.pos : st->parser->frame_offset;
-            ff_reduce_index(s, st->index);
-            av_add_index_entry(st, pos, out_pkt.dts,
-                               0, 0, AVINDEX_KEYFRAME);
-        }
-
         if (out_pkt.data == pkt->data && out_pkt.size == pkt->size) {
             out_pkt.destruct = pkt->destruct;
             pkt->destruct = NULL;
@@ -1464,10 +1456,16 @@ return_packet:
         st->skip_samples = 0;
     }
 
+    if ((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & AV_PKT_FLAG_KEY) {
+        ff_reduce_index(s, st->index);
+        av_add_index_entry(st, pkt->pos, pkt->dts, 0, 0, AVINDEX_KEYFRAME);
+    }
+
     if (is_relative(pkt->dts))
         pkt->dts -= RELATIVE_TS_BASE;
     if (is_relative(pkt->pts))
         pkt->pts -= RELATIVE_TS_BASE;
+
     return ret;
 }
 
diff --git a/tests/ref/seek/mp2_mp2 b/tests/ref/seek/mp2_mp2
index 6166cb3..8de3676 100644
--- a/tests/ref/seek/mp2_mp2
+++ b/tests/ref/seek/mp2_mp2
@@ -1,20 +1,18 @@
 ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   417
 ret: 0         st:-1 flags:0  ts:-1.000000
-ret: 0         st: 0 flags:1 dts: 0.026122 pts: 0.026122 pos:    417 size:   418
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   417
 ret: 0         st:-1 flags:1  ts: 1.894167
 ret: 0         st: 0 flags:1 dts: 1.880816 pts: 1.880816 pos:  30093 size:   418
 ret: 0         st: 0 flags:0  ts: 0.788334
 ret: 0         st: 0 flags:1 dts: 0.809796 pts: 0.809796 pos:  12956 size:   418
-ret: 0         st: 0 flags:1  ts:-0.317499
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   417
+ret:-1         st: 0 flags:1  ts:-0.317499
 ret: 0         st:-1 flags:0  ts: 2.576668
 ret: 0         st: 0 flags:1 dts: 2.586122 pts: 2.586122 pos:  41377 size:   418
 ret: 0         st:-1 flags:1  ts: 1.470835
 ret: 0         st: 0 flags:1 dts: 1.462857 pts: 1.462857 pos:  23405 size:   418
 ret: 0         st: 0 flags:0  ts: 0.365002
 ret: 0         st: 0 flags:1 dts: 0.365714 pts: 0.365714 pos:   5851 size:   418
-ret: 0         st: 0 flags:1  ts:-0.740831
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   417
+ret:-1         st: 0 flags:1  ts:-0.740831
 ret: 0         st:-1 flags:0  ts: 2.153336
 ret: 0         st: 0 flags:1 dts: 2.168163 pts: 2.168163 pos:  34690 size:   418
 ret: 0         st:-1 flags:1  ts: 1.047503
@@ -41,13 +39,11 @@ ret: 0         st: 0 flags:1  ts: 1.989173
 ret: 0         st: 0 flags:1 dts: 1.985306 pts: 1.985306 pos:  31764 size:   418
 ret: 0         st:-1 flags:0  ts: 0.883340
 ret: 0         st: 0 flags:1 dts: 0.888163 pts: 0.888163 pos:  14210 size:   418
-ret: 0         st:-1 flags:1  ts:-0.222493
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   417
+ret:-1         st:-1 flags:1  ts:-0.222493
 ret: 0         st: 0 flags:0  ts: 2.671674
 ret: 0         st: 0 flags:1 dts: 2.690612 pts: 2.690612 pos:  43049 size:   418
 ret: 0         st: 0 flags:1  ts: 1.565841
 ret: 0         st: 0 flags:1 dts: 1.541224 pts: 1.541224 pos:  24659 size:   418
 ret: 0         st:-1 flags:0  ts: 0.460008
 ret: 0         st: 0 flags:1 dts: 0.470204 pts: 0.470204 pos:   7523 size:   418
-ret: 0         st:-1 flags:1  ts:-0.645825
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:      0 size:   417
+ret:-1         st:-1 flags:1  ts:-0.645825
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list