fixed incorrect PTS/DTS logic in MPEG video case (caused rare PTS glitches if start codes were between two PES packets)

Originally committed as revision 2620 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Fabrice Bellard 2003-12-16 11:21:25 +00:00
parent b84f2a3533
commit 6ec87caa70
2 changed files with 11 additions and 21 deletions

View File

@ -5,7 +5,7 @@
extern "C" { extern "C" {
#endif #endif
#define LIBAVFORMAT_BUILD 4610 #define LIBAVFORMAT_BUILD 4611
#define LIBAVFORMAT_VERSION_INT FFMPEG_VERSION_INT #define LIBAVFORMAT_VERSION_INT FFMPEG_VERSION_INT
#define LIBAVFORMAT_VERSION FFMPEG_VERSION #define LIBAVFORMAT_VERSION FFMPEG_VERSION
@ -225,9 +225,7 @@ typedef struct AVStream {
/* av_read_frame() support */ /* av_read_frame() support */
int need_parsing; int need_parsing;
struct AVCodecParserContext *parser; struct AVCodecParserContext *parser;
int got_frame;
int64_t cur_frame_pts;
int64_t cur_frame_dts;
int64_t cur_dts; int64_t cur_dts;
int last_IP_duration; int last_IP_duration;
/* av_seek_frame() support */ /* av_seek_frame() support */

View File

@ -672,18 +672,11 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
s->cur_st = NULL; s->cur_st = NULL;
return 0; return 0;
} else if (s->cur_len > 0) { } else if (s->cur_len > 0) {
/* we use the MPEG semantics: the pts and dts in a len = av_parser_parse(st->parser, &st->codec, &pkt->data, &pkt->size,
packet are given from the first frame beginning in s->cur_ptr, s->cur_len,
it */ s->cur_pkt.pts, s->cur_pkt.dts);
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.pts = AV_NOPTS_VALUE;
s->cur_pkt.dts = 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);
/* increment read pointer */ /* increment read pointer */
s->cur_ptr += len; s->cur_ptr += len;
s->cur_len -= len; s->cur_len -= len;
@ -693,11 +686,10 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
got_packet: got_packet:
pkt->duration = 0; pkt->duration = 0;
pkt->stream_index = st->index; pkt->stream_index = st->index;
pkt->pts = st->cur_frame_pts; pkt->pts = st->parser->pts;
pkt->dts = st->cur_frame_dts; pkt->dts = st->parser->dts;
pkt->destruct = av_destruct_packet_nofree; pkt->destruct = av_destruct_packet_nofree;
compute_pkt_fields(s, st, st->parser, pkt); compute_pkt_fields(s, st, st->parser, pkt);
st->got_frame = 0;
return 0; return 0;
} }
} else { } else {
@ -717,7 +709,8 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
if (st->parser) { if (st->parser) {
av_parser_parse(st->parser, &st->codec, av_parser_parse(st->parser, &st->codec,
&pkt->data, &pkt->size, &pkt->data, &pkt->size,
NULL, 0); NULL, 0,
AV_NOPTS_VALUE, AV_NOPTS_VALUE);
if (pkt->size) if (pkt->size)
goto got_packet; goto got_packet;
} }
@ -736,7 +729,7 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
&s->last_pkt_stream_dts, &s->last_pkt_stream_dts,
s->cur_pkt.dts); s->cur_pkt.dts);
#if 0 #if 0
if (s->cur_pkt.stream_index == 1) { if (s->cur_pkt.stream_index == 0) {
if (s->cur_pkt.pts != AV_NOPTS_VALUE) if (s->cur_pkt.pts != AV_NOPTS_VALUE)
printf("PACKET pts=%0.3f\n", printf("PACKET pts=%0.3f\n",
(double)s->cur_pkt.pts / AV_TIME_BASE); (double)s->cur_pkt.pts / AV_TIME_BASE);
@ -844,7 +837,6 @@ static void av_read_frame_flush(AVFormatContext *s)
av_parser_close(st->parser); av_parser_close(st->parser);
st->parser = NULL; st->parser = NULL;
} }
st->got_frame = 0;
st->cur_dts = 0; /* we set the current DTS to an unspecified origin */ st->cur_dts = 0; /* we set the current DTS to an unspecified origin */
} }
} }