summaryrefslogtreecommitdiff
path: root/libavformat/mpegts.c
diff options
context:
space:
mode:
authorZohar Kelrich <lumimies@gmail.com>2011-07-24 11:13:50 +0300
committerLuca Barbato <lu_zero@gentoo.org>2011-08-02 02:43:22 +0200
commit8b9df201dfb2fa557b5dfc4e04c927d3f13a0dd9 (patch)
treec706d8f27cf16b3883ff2ac673edb89afe4c56a3 /libavformat/mpegts.c
parentbe9c00615b5c2cb858b9905854726ebe578c007b (diff)
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>
Diffstat (limited to 'libavformat/mpegts.c')
-rw-r--r--libavformat/mpegts.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 410507db6d..13b31177a5 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -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;
}