avformat/mpegts: Improve the position determination for avpriv_mpegts_parse_packet()
Fixes: assertion failure
Fixes: Ticket 8005
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit e5bb48ae59
)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
@@ -2586,13 +2586,12 @@ static int parse_pcr(int64_t *ppcr_high, int *ppcr_low,
|
|||||||
const uint8_t *packet);
|
const uint8_t *packet);
|
||||||
|
|
||||||
/* handle one TS packet */
|
/* handle one TS packet */
|
||||||
static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
|
static int handle_packet(MpegTSContext *ts, const uint8_t *packet, int64_t pos)
|
||||||
{
|
{
|
||||||
MpegTSFilter *tss;
|
MpegTSFilter *tss;
|
||||||
int len, pid, cc, expected_cc, cc_ok, afc, is_start, is_discontinuity,
|
int len, pid, cc, expected_cc, cc_ok, afc, is_start, is_discontinuity,
|
||||||
has_adaptation, has_payload;
|
has_adaptation, has_payload;
|
||||||
const uint8_t *p, *p_end;
|
const uint8_t *p, *p_end;
|
||||||
int64_t pos;
|
|
||||||
|
|
||||||
pid = AV_RB16(packet + 1) & 0x1fff;
|
pid = AV_RB16(packet + 1) & 0x1fff;
|
||||||
is_start = packet[1] & 0x40;
|
is_start = packet[1] & 0x40;
|
||||||
@@ -2659,7 +2658,6 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
|
|||||||
if (p >= p_end || !has_payload)
|
if (p >= p_end || !has_payload)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
pos = avio_tell(ts->stream->pb);
|
|
||||||
if (pos >= 0) {
|
if (pos >= 0) {
|
||||||
av_assert0(pos >= TS_PACKET_SIZE);
|
av_assert0(pos >= TS_PACKET_SIZE);
|
||||||
ts->pos47_full = pos - TS_PACKET_SIZE;
|
ts->pos47_full = pos - TS_PACKET_SIZE;
|
||||||
@@ -2870,7 +2868,7 @@ static int handle_packets(MpegTSContext *ts, int64_t nb_packets)
|
|||||||
ret = read_packet(s, packet, ts->raw_packet_size, &data);
|
ret = read_packet(s, packet, ts->raw_packet_size, &data);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
break;
|
break;
|
||||||
ret = handle_packet(ts, data);
|
ret = handle_packet(ts, data, avio_tell(s->pb));
|
||||||
finished_reading_packet(s, ts->raw_packet_size);
|
finished_reading_packet(s, ts->raw_packet_size);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
break;
|
break;
|
||||||
@@ -3263,7 +3261,7 @@ int avpriv_mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt,
|
|||||||
buf++;
|
buf++;
|
||||||
len--;
|
len--;
|
||||||
} else {
|
} else {
|
||||||
handle_packet(ts, buf);
|
handle_packet(ts, buf, len1 - len + TS_PACKET_SIZE);
|
||||||
buf += TS_PACKET_SIZE;
|
buf += TS_PACKET_SIZE;
|
||||||
len -= TS_PACKET_SIZE;
|
len -= TS_PACKET_SIZE;
|
||||||
if (ts->stop_parse == 1)
|
if (ts->stop_parse == 1)
|
||||||
|
Reference in New Issue
Block a user