summaryrefslogtreecommitdiff
path: root/libavformat/mpegts.c
diff options
context:
space:
mode:
authorZohar Kelrich <lumimies@gmail.com>2011-07-24 11:13:50 +0300
committerLuca Barbato <lu_zero@gentoo.org>2011-08-02 02:52:27 +0200
commitcdb9884a636987061d549ac23a248aabc4a91140 (patch)
tree2d70033c2dfad91e5b306b9d95efa73a89b68a16 /libavformat/mpegts.c
parentce9e31655e5b8f8db3bb4f13f436fc836062a514 (diff)
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@gmail.com> Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Diffstat (limited to 'libavformat/mpegts.c')
-rw-r--r--libavformat/mpegts.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index d4688aebfd..a5a8ce2a67 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;
}