comparison raw.c @ 1931:69c6eb14fdfc libavformat

improve ac3_probe by counting consecutive frames
author jbr
date Sun, 18 Mar 2007 19:32:22 +0000
parents 4b8313d5b23b
children f73b9a471583
comparison
equal deleted inserted replaced
1930:f67a8d12053d 1931:69c6eb14fdfc
18 * You should have received a copy of the GNU Lesser General Public 18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software 19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */ 21 */
22 #include "avformat.h" 22 #include "avformat.h"
23 #include "ac3.h"
23 24
24 #ifdef CONFIG_MUXERS 25 #ifdef CONFIG_MUXERS
25 /* simple formats */ 26 /* simple formats */
26 static int raw_write_header(struct AVFormatContext *s) 27 static int raw_write_header(struct AVFormatContext *s)
27 { 28 {
406 return 0; 407 return 0;
407 } 408 }
408 409
409 static int ac3_probe(AVProbeData *p) 410 static int ac3_probe(AVProbeData *p)
410 { 411 {
411 int score=0; 412 int max_frames, first_frames, frames;
412 413 uint8_t *buf, *buf2, *end;
413 if(p->buf_size < 6) 414 AC3HeaderInfo hdr;
415
416 if(p->buf_size < 7)
414 return 0; 417 return 0;
415 418
416 if((p->buf[0] == 0x0B) && (p->buf[1] == 0x77) && // sync word 419 max_frames = 0;
417 ((p->buf[4] >> 6) != 3) && // fscod 420 buf = p->buf;
418 ((p->buf[5] >> 3) <= 16)) { // bsid 421 end = buf + FFMIN(4096, p->buf_size - 7);
419 score = AVPROBE_SCORE_MAX / 2 + 10; 422
420 } 423 for(; buf < end; buf++) {
421 424 buf2 = buf;
422 return score; 425
426 for(frames = 0; buf2 < end; frames++) {
427 if(ff_ac3_parse_header(buf2, &hdr) < 0)
428 break;
429 buf2 += hdr.frame_size;
430 }
431 max_frames = FFMAX(max_frames, frames);
432 if(buf == p->buf)
433 first_frames = frames;
434 }
435 if (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
436 else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
437 else if(max_frames>=1) return 1;
438 else return 0;
423 } 439 }
424 440
425 AVInputFormat shorten_demuxer = { 441 AVInputFormat shorten_demuxer = {
426 "shn", 442 "shn",
427 "raw shorten", 443 "raw shorten",