diff options
author | Anton Khirnov <anton@khirnov.net> | 2015-02-04 14:37:01 +0300 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2015-02-10 23:43:44 +0300 |
commit | 1509c018bd5b054a2354e20021ccbac9c934d213 (patch) | |
tree | 3fd78def01951d1a4bb81cb5d062beacc2378cb2 | |
parent | 6a5b8ca4329039fad44ad50b6496948f4bfacb4c (diff) |
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.
-rw-r--r-- | libavformat/mpegts.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index ce13a0832e..2f1d9d91ef 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); |