OSDN Git Service

mpegts: relax restrictions on matching the packet start in read_header
authorAnton Khirnov <anton@khirnov.net>
Wed, 4 Feb 2015 11:37:01 +0000 (12:37 +0100)
committerAnton Khirnov <anton@khirnov.net>
Tue, 10 Feb 2015 20:43:44 +0000 (21:43 +0100)
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.

libavformat/mpegts.c

index ce13a08..2f1d9d9 100644 (file)
@@ -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);