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>
This commit is contained in:
Zohar Kelrich 2011-07-24 11:13:50 +03:00 committed by Luca Barbato
parent ce9e31655e
commit cdb9884a63
1 changed files with 20 additions and 19 deletions

View File

@ -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;
}