|
|
|
@ -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; |
|
|
|
|
|
|
|
|
|
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) */ |
|
|
|
|
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); |
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
/* skip adaptation field */ |
|
|
|
|
afc = (packet[3] >> 4) & 3; |
|
|
|
|
p = packet + 4; |
|
|
|
|
if (afc == 0) /* reserved value */ |
|
|
|
|
if (!has_payload) |
|
|
|
|
return 0; |
|
|
|
|
if (afc == 2) /* adaptation field only */ |
|
|
|
|
return 0; |
|
|
|
|
if (afc == 3) { |
|
|
|
|
p = packet + 4; |
|
|
|
|
if (has_adaptation) { |
|
|
|
|
/* skip adapation field */ |
|
|
|
|
p += p[0] + 1; |
|
|
|
|
} |
|
|
|
|