changeset 334:7f089db11f9a libavformat

fixed incorrect PTS/DTS logic in MPEG video case (caused rare PTS glitches if start codes were between two PES packets)
author bellard
date Tue, 16 Dec 2003 11:21:25 +0000
parents e3beadc2ed83
children b0ac206f232d
files avformat.h utils.c
diffstat 2 files changed, 11 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/avformat.h	Mon Dec 15 14:45:37 2003 +0000
+++ b/avformat.h	Tue Dec 16 11:21:25 2003 +0000
@@ -5,7 +5,7 @@
 extern "C" {
 #endif
 
-#define LIBAVFORMAT_BUILD       4610
+#define LIBAVFORMAT_BUILD       4611
 
 #define LIBAVFORMAT_VERSION_INT FFMPEG_VERSION_INT
 #define LIBAVFORMAT_VERSION     FFMPEG_VERSION
@@ -225,9 +225,7 @@
     /* av_read_frame() support */
     int need_parsing;
     struct AVCodecParserContext *parser;
-    int got_frame;
-    int64_t cur_frame_pts;
-    int64_t cur_frame_dts;
+
     int64_t cur_dts;
     int last_IP_duration;
     /* av_seek_frame() support */
--- a/utils.c	Mon Dec 15 14:45:37 2003 +0000
+++ b/utils.c	Tue Dec 16 11:21:25 2003 +0000
@@ -672,18 +672,11 @@
                 s->cur_st = NULL;
                 return 0;
             } else if (s->cur_len > 0) {
-                /* we use the MPEG semantics: the pts and dts in a
-                   packet are given from the first frame beginning in
-                   it */
-                if (!st->got_frame) {
-                    st->cur_frame_pts = s->cur_pkt.pts;
-                    st->cur_frame_dts = s->cur_pkt.dts;
-                    s->cur_pkt.pts = AV_NOPTS_VALUE;
-                    s->cur_pkt.dts = AV_NOPTS_VALUE;
-                    st->got_frame = 1;
-                }
                 len = av_parser_parse(st->parser, &st->codec, &pkt->data, &pkt->size, 
-                                      s->cur_ptr, s->cur_len);
+                                      s->cur_ptr, s->cur_len,
+                                      s->cur_pkt.pts, s->cur_pkt.dts);
+                s->cur_pkt.pts = AV_NOPTS_VALUE;
+                s->cur_pkt.dts = AV_NOPTS_VALUE;
                 /* increment read pointer */
                 s->cur_ptr += len;
                 s->cur_len -= len;
@@ -693,11 +686,10 @@
                 got_packet:
                     pkt->duration = 0;
                     pkt->stream_index = st->index;
-                    pkt->pts = st->cur_frame_pts;
-                    pkt->dts = st->cur_frame_dts;
+                    pkt->pts = st->parser->pts;
+                    pkt->dts = st->parser->dts;
                     pkt->destruct = av_destruct_packet_nofree;
                     compute_pkt_fields(s, st, st->parser, pkt);
-                    st->got_frame = 0;
                     return 0;
                 }
             } else {
@@ -717,7 +709,8 @@
                     if (st->parser) {
                         av_parser_parse(st->parser, &st->codec, 
                                         &pkt->data, &pkt->size, 
-                                        NULL, 0);
+                                        NULL, 0, 
+                                        AV_NOPTS_VALUE, AV_NOPTS_VALUE);
                         if (pkt->size)
                             goto got_packet;
                     }
@@ -736,7 +729,7 @@
                                                &s->last_pkt_stream_dts,
                                                s->cur_pkt.dts);
 #if 0
-            if (s->cur_pkt.stream_index == 1) {
+            if (s->cur_pkt.stream_index == 0) {
                 if (s->cur_pkt.pts != AV_NOPTS_VALUE) 
                     printf("PACKET pts=%0.3f\n", 
                            (double)s->cur_pkt.pts / AV_TIME_BASE);
@@ -844,7 +837,6 @@
             av_parser_close(st->parser);
             st->parser = NULL;
         }
-        st->got_frame = 0;
         st->cur_dts = 0; /* we set the current DTS to an unspecified origin */
     }
 }