[FFmpeg-cvslog] mpegts: Fix for continuity counter
Zohar Kelrich
git at videolan.org
Tue Aug 2 22:24:35 CEST 2011
ffmpeg | branch: master | Zohar Kelrich <lumimies at gmail.com> | Sun Jul 24 11:13:50 2011 +0300| [8b9df201dfb2fa557b5dfc4e04c927d3f13a0dd9] | committer: 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: Zohar Kelrich <lumimies at gmail.com>
Signed-off-by: Luca Barbato <lu_zero at gentoo.org>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8b9df201dfb2fa557b5dfc4e04c927d3f13a0dd9
---
libavformat/mpegts.c | 30 ++++++++++++++++++++----------
1 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 410507d..13b3117 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;
}
More information about the ffmpeg-cvslog
mailing list