1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

better get_packet_size and probe

Originally committed as revision 2578 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Michael Niedermayer 2003-12-09 00:17:43 +00:00
parent f8830383a9
commit a0b8f70c29

View File

@ -218,24 +218,45 @@ void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter)
ts->pids[pid] = NULL; 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 */ /* autodetect fec presence. Must have at least 1024 bytes */
static int get_packet_size(const uint8_t *buf, int size) 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)) if (size < (TS_FEC_PACKET_SIZE * 5 + 1))
return -1; return -1;
for(i=0;i<5;i++) {
if (buf[i * TS_PACKET_SIZE] != 0x47) score = analyze(buf, size, TS_PACKET_SIZE, NULL);
goto try_fec; 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);
return TS_PACKET_SIZE;
try_fec: if (score > fec_score) return TS_PACKET_SIZE;
for(i=0;i<5;i++) { else if(score < fec_score) return TS_FEC_PACKET_SIZE;
if (buf[i * TS_FEC_PACKET_SIZE] != 0x47) else return -1;
return -1;
}
return TS_FEC_PACKET_SIZE;
} }
typedef struct SectionHeader { typedef struct SectionHeader {
@ -988,11 +1009,21 @@ static int handle_packets(MpegTSContext *ts, int nb_packets)
static int mpegts_probe(AVProbeData *p) static int mpegts_probe(AVProbeData *p)
{ {
#if 1 #if 1
int size; const int size= p->buf_size;
size = get_packet_size(p->buf, p->buf_size); int score, fec_score;
if (size < 0) #define CHECK_COUNT 10
return 0;
return AVPROBE_SCORE_MAX - 1; 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 #else
/* only use the extension for safer guess */ /* only use the extension for safer guess */
if (match_ext(p->filename, "ts")) if (match_ext(p->filename, "ts"))