static int mp3_read_probe(AVProbeData *p) { int max_frames, first_frames = 0; int fsize, frames, sample_rate; uint32_t header; uint8_t *buf, *buf0, *buf2, *end; AVCodecContext avctx; buf0 = p->buf; end = p->buf + p->buf_size - sizeof(uint32_t); while(buf0 < end && !*buf0) buf0++; max_frames = 0; buf = buf0; for(; buf < end; buf= buf2+1) { buf2 = buf; for(frames = 0; buf2 < end; frames++) { header = AV_RB32(buf2); fsize = avpriv_mpa_decode_header(&avctx, header, &sample_rate, &sample_rate, &sample_rate, &sample_rate); if(fsize < 0) break; buf2 += fsize; } max_frames = FFMAX(max_frames, frames); if(buf == buf0) first_frames= frames; } // keep this in sync with ac3 probe, both need to avoid // issues with MPEG-files! if (first_frames >= 4) return AVPROBE_SCORE_EXTENSION + 1; if (max_frames) { int pes = 0, i; unsigned int code = -1; #define VIDEO_ID 0x000001e0 #define AUDIO_ID 0x000001c0 /* do a search for mpegps headers to be able to properly bias * towards mpegps if we detect this stream as both. */ for (i = 0; i<p->buf_size; i++) { code = (code << 8) + p->buf[i]; if ((code & 0xffffff00) == 0x100) { if ((code & 0x1f0) == VIDEO_ID) pes++; else if((code & 0x1e0) == AUDIO_ID) pes++; } } if (pes) max_frames = (max_frames + pes - 1) / pes; } if (max_frames > 500) return AVPROBE_SCORE_EXTENSION; else if (max_frames >= 4) return AVPROBE_SCORE_EXTENSION / 2; else if (max_frames >= 1) return 1; else return 0; //mpegps_mp3_unrecognized_format.mpg has max_frames=3 }
static int mp3_read_probe(AVProbeData *p) { int max_frames, first_frames = 0; int fsize, frames, sample_rate; uint32_t header; uint8_t *buf, *buf0, *buf2, *end; AVCodecContext avctx; buf0 = p->buf; end = p->buf + p->buf_size - sizeof(uint32_t); while(buf0 < end && !*buf0) buf0++; max_frames = 0; buf = buf0; for(; buf < end; buf= buf2+1) { buf2 = buf; for(frames = 0; buf2 < end; frames++) { header = AV_RB32(buf2); fsize = avpriv_mpa_decode_header(&avctx, header, &sample_rate, &sample_rate, &sample_rate, &sample_rate); if(fsize < 0) break; buf2 += fsize; } max_frames = FFMAX(max_frames, frames); if(buf == buf0) first_frames= frames; } // keep this in sync with ac3 probe, both need to avoid // issues with MPEG-files! if (first_frames>=4) return AVPROBE_SCORE_MAX/2+1; else if(max_frames>200)return AVPROBE_SCORE_MAX/2; else if(max_frames>=4) return AVPROBE_SCORE_MAX/4; else if(ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) && 2*ff_id3v2_tag_len(buf0) >= p->buf_size) return AVPROBE_SCORE_MAX/8; else if(max_frames>=1) return 1; else return 0; //mpegps_mp3_unrecognized_format.mpg has max_frames=3 }
static int mpegaudio_parse(AVCodecParserContext *s1, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { MpegAudioParseContext *s = s1->priv_data; ParseContext *pc = &s->pc; uint32_t state= pc->state; int i; int next= END_NOT_FOUND; for(i=0; i<buf_size; ){ if(s->frame_size){ int inc= FFMIN(buf_size - i, s->frame_size); i += inc; s->frame_size -= inc; if(!s->frame_size){ next= i; break; } }else{ while(i<buf_size){ int ret, sr, channels, bit_rate, frame_size; state= (state<<8) + buf[i++]; ret = avpriv_mpa_decode_header(avctx, state, &sr, &channels, &frame_size, &bit_rate); if (ret < 4) { if (i > 4) s->header_count = -2; } else { if((state&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header) s->header_count= -3; s->header= state; s->header_count++; s->frame_size = ret-4; if (s->header_count > 1 || avctx->sample_rate == 0) { avctx->sample_rate= sr; avctx->channels = channels; s1->duration = frame_size; avctx->bit_rate = bit_rate; } break; } } } } pc->state= state; if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { *poutbuf = NULL; *poutbuf_size = 0; return buf_size; } *poutbuf = buf; *poutbuf_size = buf_size; return next; }