[FFmpeg-cvslog] mpegts: Move scan test to handle_packets
Zohar Kelrich
git at videolan.org
Tue Aug 2 22:24:35 CEST 2011
ffmpeg | branch: master | Zohar Kelrich <lumimies at gmail.com> | Sun Jul 24 11:13:50 2011 +0300| [cdb9884a636987061d549ac23a248aabc4a91140] | committer: Luca Barbato
mpegts: Move scan test to handle_packets
This fixes an issue where packets which start being read
while reading the header stick around after a seek.
Signed-off-by: Zohar Kelrich <lumimies at gmail.com>
Signed-off-by: Luca Barbato <lu_zero at gentoo.org>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cdb9884a636987061d549ac23a248aabc4a91140
---
libavformat/mpegts.c | 39 ++++++++++++++++++++-------------------
1 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index d4688ae..a5a8ce2 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -1399,7 +1399,22 @@ static int handle_packets(MpegTSContext *ts, int nb_packets)
{
AVFormatContext *s = ts->stream;
uint8_t packet[TS_PACKET_SIZE];
- int packet_num, ret;
+ int packet_num, ret = 0;
+
+ if (avio_tell(s->pb) != ts->last_pos) {
+ int i;
+ av_dlog("Skipping after seek\n");
+ /* seek detected, flush pes buffer */
+ for (i = 0; i < NB_PID_MAX; i++) {
+ if (ts->pids[i] && ts->pids[i]->type == MPEGTS_PES) {
+ PESContext *pes = ts->pids[i]->u.pes_filter.opaque;
+ av_freep(&pes->buffer);
+ ts->pids[i]->last_cc = -1;
+ pes->data_index = 0;
+ pes->state = MPEGTS_SKIP; /* skip until pes header */
+ }
+ }
+ }
ts->stop_parse = 0;
packet_num = 0;
@@ -1411,12 +1426,13 @@ static int handle_packets(MpegTSContext *ts, int nb_packets)
break;
ret = read_packet(s, packet, ts->raw_packet_size);
if (ret != 0)
- return ret;
+ break;
ret = handle_packet(ts, packet);
if (ret != 0)
- return ret;
+ break;
}
- return 0;
+ ts->last_pos = avio_tell(s->pb);
+ return ret;
}
static int mpegts_probe(AVProbeData *p)
@@ -1630,19 +1646,6 @@ static int mpegts_read_packet(AVFormatContext *s,
MpegTSContext *ts = s->priv_data;
int ret, i;
- if (avio_tell(s->pb) != ts->last_pos) {
- /* seek detected, flush pes buffer */
- for (i = 0; i < NB_PID_MAX; i++) {
- if (ts->pids[i] && ts->pids[i]->type == MPEGTS_PES) {
- PESContext *pes = ts->pids[i]->u.pes_filter.opaque;
- av_freep(&pes->buffer);
- ts->pids[i]->last_cc = -1;
- pes->data_index = 0;
- pes->state = MPEGTS_SKIP; /* skip until pes header */
- }
- }
- }
-
ts->pkt = pkt;
ret = handle_packets(ts, 0);
if (ret < 0) {
@@ -1660,8 +1663,6 @@ static int mpegts_read_packet(AVFormatContext *s,
}
}
- ts->last_pos = avio_tell(s->pb);
-
return ret;
}
More information about the ffmpeg-cvslog
mailing list