Commit 8b9df201 authored by Zohar Kelrich's avatar Zohar Kelrich Committed by Luca Barbato

mpegts: Fix for continuity counter

Make continuity counter respect discontinuity flag
and null packets. Unpack the adaptation_field_control field.
Signed-off-by: 's avatarZohar Kelrich <lumimies@gmail.com>
Signed-off-by: 's avatarLuca Barbato <lu_zero@gentoo.org>
parent be9c0061
...@@ -1248,7 +1248,8 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet) ...@@ -1248,7 +1248,8 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
{ {
AVFormatContext *s = ts->stream; AVFormatContext *s = ts->stream;
MpegTSFilter *tss; MpegTSFilter *tss;
int len, pid, cc, expected_cc, cc_ok, afc, is_start; int len, pid, cc, expected_cc, cc_ok, afc, is_start, is_discontinuity,
has_adaptation, has_payload;
const uint8_t *p, *p_end; const uint8_t *p, *p_end;
int64_t pos; int64_t pos;
...@@ -1264,20 +1265,29 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet) ...@@ -1264,20 +1265,29 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
if (!tss) if (!tss)
return 0; return 0;
afc = (packet[3] >> 4) & 3;
if (afc == 0) /* reserved value */
return 0;
has_adaptation = afc & 2;
has_payload = afc & 1;
is_discontinuity = has_adaptation
&& packet[4] != 0 /* with length > 0 */
&& (packet[5] & 0x80); /* and discontinuity indicated */
/* continuity check (currently not used) */ /* continuity check (currently not used) */
cc = (packet[3] & 0xf); cc = (packet[3] & 0xf);
expected_cc = (packet[3] & 0x10) ? (tss->last_cc + 1) & 0x0f : tss->last_cc; expected_cc = has_payload ? (tss->last_cc + 1) & 0x0f : tss->last_cc;
cc_ok = (tss->last_cc < 0) || (expected_cc == cc); cc_ok = pid == 0x1FFF // null packet PID
|| is_discontinuity
|| tss->last_cc < 0
|| expected_cc == cc;
tss->last_cc = cc; tss->last_cc = cc;
/* skip adaptation field */ if (!has_payload)
afc = (packet[3] >> 4) & 3;
p = packet + 4;
if (afc == 0) /* reserved value */
return 0; return 0;
if (afc == 2) /* adaptation field only */ p = packet + 4;
return 0; if (has_adaptation) {
if (afc == 3) {
/* skip adapation field */ /* skip adapation field */
p += p[0] + 1; p += p[0] + 1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment