mirror of https://git.ffmpeg.org/ffmpeg.git
mpegts: Fix for continuity counter
Make continuity counter respect discontinuity flag and null packets. Unpack the adaptation_field_control field. Signed-off-by: Zohar Kelrich <lumimies@gmail.com> Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
This commit is contained in:
parent
be9c00615b
commit
8b9df201df
|
@ -1248,7 +1248,8 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
|
|||
{
|
||||
AVFormatContext *s = ts->stream;
|
||||
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;
|
||||
int64_t pos;
|
||||
|
||||
|
@ -1264,20 +1265,29 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
|
|||
if (!tss)
|
||||
return 0;
|
||||
|
||||
/* continuity check (currently not used) */
|
||||
cc = (packet[3] & 0xf);
|
||||
expected_cc = (packet[3] & 0x10) ? (tss->last_cc + 1) & 0x0f : tss->last_cc;
|
||||
cc_ok = (tss->last_cc < 0) || (expected_cc == cc);
|
||||
tss->last_cc = cc;
|
||||
|
||||
/* skip adaptation field */
|
||||
afc = (packet[3] >> 4) & 3;
|
||||
p = packet + 4;
|
||||
if (afc == 0) /* reserved value */
|
||||
return 0;
|
||||
if (afc == 2) /* adaptation field only */
|
||||
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) */
|
||||
cc = (packet[3] & 0xf);
|
||||
expected_cc = has_payload ? (tss->last_cc + 1) & 0x0f : tss->last_cc;
|
||||
cc_ok = pid == 0x1FFF // null packet PID
|
||||
|| is_discontinuity
|
||||
|| tss->last_cc < 0
|
||||
|| expected_cc == cc;
|
||||
|
||||
tss->last_cc = cc;
|
||||
|
||||
if (!has_payload)
|
||||
return 0;
|
||||
if (afc == 3) {
|
||||
p = packet + 4;
|
||||
if (has_adaptation) {
|
||||
/* skip adapation field */
|
||||
p += p[0] + 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue