diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2003-12-09 00:17:43 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2003-12-09 00:17:43 +0000 |
commit | a0b8f70c2958ccf96b57f3d07af90545800f5b35 (patch) | |
tree | 563d34fff07656f4da944578cd0626d84ea65db6 | |
parent | f8830383a9d63289f9f9b4b7c7a4577636a1764e (diff) | |
download | ffmpeg-a0b8f70c2958ccf96b57f3d07af90545800f5b35.tar.gz |
better get_packet_size and probe
Originally committed as revision 2578 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavformat/mpegts.c | 65 |
1 files changed, 48 insertions, 17 deletions
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 311653c880..2da011a57e 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -218,24 +218,45 @@ 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){ + int stat[packet_size]; + int i; + int x=0; + int best_score=0; + + memset(stat, 0, packet_size*sizeof(int)); + + for(x=i=0; i<size; i++){ + if(buf[i] == 0x47){ + stat[x]++; + if(stat[x] > best_score){ + best_score= stat[x]; + if(index) *index= x; + } + } + + x++; + if(x == packet_size) x= 0; + } + + return best_score; +} + /* autodetect fec presence. Must have at least 1024 bytes */ static int get_packet_size(const uint8_t *buf, int size) { - int i; + int score, fec_score; if (size < (TS_FEC_PACKET_SIZE * 5 + 1)) return -1; - for(i=0;i<5;i++) { - if (buf[i * TS_PACKET_SIZE] != 0x47) - goto try_fec; - } - return TS_PACKET_SIZE; - try_fec: - for(i=0;i<5;i++) { - if (buf[i * TS_FEC_PACKET_SIZE] != 0x47) - return -1; - } - return TS_FEC_PACKET_SIZE; + + score = analyze(buf, size, TS_PACKET_SIZE, NULL); + fec_score= analyze(buf, size, TS_FEC_PACKET_SIZE, NULL); +// av_log(NULL, AV_LOG_DEBUG, "score: %d, fec_score: %d \n", score, fec_score); + + if (score > fec_score) return TS_PACKET_SIZE; + else if(score < fec_score) return TS_FEC_PACKET_SIZE; + else return -1; } typedef struct SectionHeader { @@ -988,11 +1009,21 @@ static int handle_packets(MpegTSContext *ts, int nb_packets) static int mpegts_probe(AVProbeData *p) { #if 1 - int size; - size = get_packet_size(p->buf, p->buf_size); - if (size < 0) - return 0; - return AVPROBE_SCORE_MAX - 1; + const int size= p->buf_size; + int score, fec_score; +#define CHECK_COUNT 10 + + if (size < (TS_FEC_PACKET_SIZE * CHECK_COUNT)) + return -1; + + score = analyze(p->buf, TS_PACKET_SIZE *CHECK_COUNT, TS_PACKET_SIZE, NULL); + fec_score= analyze(p->buf, TS_FEC_PACKET_SIZE*CHECK_COUNT, TS_FEC_PACKET_SIZE, NULL); +// av_log(NULL, AV_LOG_DEBUG, "score: %d, fec_score: %d \n", score, fec_score); + +// we need a clear definition for the returned score otherwise things will become messy sooner or later + if (score > fec_score && score > 6) return AVPROBE_SCORE_MAX + score - CHECK_COUNT; + else if( fec_score > 6) return AVPROBE_SCORE_MAX + fec_score - CHECK_COUNT; + else return -1; #else /* only use the extension for safer guess */ if (match_ext(p->filename, "ts")) |