[FFmpeg-cvslog] mpegts: relax restrictions on matching the packet start in read_header

Anton Khirnov git at videolan.org
Wed Feb 11 02:05:17 CET 2015


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed Feb  4 12:37:01 2015 +0100| [1509c018bd5b054a2354e20021ccbac9c934d213] | committer: Anton Khirnov

mpegts: relax restrictions on matching the packet start in read_header

analyze() is currently called both when probing and from read_header().
It determines the packet start by looking for the sync byte, followed by
unset Transport Error Indicator and valid adaptation_field_control.

This makes sense to do when probing, but once we already know the format
is MPEG-TS, it is counterproductive to be so strict -- e.g. in some
files the TEI might be set and analyze() might get called with a smaller
buffer than the one used for probing, resulting in a failure.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1509c018bd5b054a2354e20021ccbac9c934d213
---

 libavformat/mpegts.c |   18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index ce13a08..2f1d9d9 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -425,7 +425,8 @@ static void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter)
     ts->pids[pid] = NULL;
 }
 
-static int analyze(const uint8_t *buf, int size, int packet_size, int *index)
+static int analyze(const uint8_t *buf, int size, int packet_size, int *index,
+                   int probe)
 {
     int stat[TS_MAX_PACKET_SIZE];
     int i;
@@ -435,7 +436,8 @@ static int analyze(const uint8_t *buf, int size, int packet_size, int *index)
     memset(stat, 0, packet_size * sizeof(int));
 
     for (x = i = 0; i < size - 3; i++) {
-        if (buf[i] == 0x47 && !(buf[i + 1] & 0x80) && (buf[i + 3] & 0x30)) {
+        if (buf[i] == 0x47 &&
+            (!probe || (!(buf[i + 1] & 0x80) && (buf[i + 3] & 0x30)))) {
             stat[x]++;
             if (stat[x] > best_score) {
                 best_score = stat[x];
@@ -460,9 +462,9 @@ static int get_packet_size(const uint8_t *buf, int size)
     if (size < (TS_FEC_PACKET_SIZE * 5 + 1))
         return AVERROR_INVALIDDATA;
 
-    score      = analyze(buf, size, TS_PACKET_SIZE, NULL);
-    dvhs_score = analyze(buf, size, TS_DVHS_PACKET_SIZE, NULL);
-    fec_score  = analyze(buf, size, TS_FEC_PACKET_SIZE, NULL);
+    score      = analyze(buf, size, TS_PACKET_SIZE,      NULL, 0);
+    dvhs_score = analyze(buf, size, TS_DVHS_PACKET_SIZE, NULL, 0);
+    fec_score  = analyze(buf, size, TS_FEC_PACKET_SIZE,  NULL, 0);
     av_dlog(NULL, "score: %d, dvhs_score: %d, fec_score: %d \n",
             score, dvhs_score, fec_score);
 
@@ -1986,11 +1988,11 @@ static int mpegts_probe(AVProbeData *p)
         return AVERROR_INVALIDDATA;
 
     score = analyze(p->buf, TS_PACKET_SIZE * check_count,
-                    TS_PACKET_SIZE, NULL) * CHECK_COUNT / check_count;
+                    TS_PACKET_SIZE, NULL, 1) * CHECK_COUNT / check_count;
     dvhs_score = analyze(p->buf, TS_DVHS_PACKET_SIZE * check_count,
-                         TS_DVHS_PACKET_SIZE, NULL) * CHECK_COUNT / check_count;
+                         TS_DVHS_PACKET_SIZE, NULL, 1) * CHECK_COUNT / check_count;
     fec_score = analyze(p->buf, TS_FEC_PACKET_SIZE * check_count,
-                        TS_FEC_PACKET_SIZE, NULL) * CHECK_COUNT / check_count;
+                        TS_FEC_PACKET_SIZE, NULL, 1) * CHECK_COUNT / check_count;
     av_dlog(NULL, "score: %d, dvhs_score: %d, fec_score: %d \n",
             score, dvhs_score, fec_score);
 



More information about the ffmpeg-cvslog mailing list