Mercurial > libavformat.hg
comparison raw.c @ 3864:b31edc09d556 libavformat
simplify ac3_probe() and eac3_probe(). patch by Aurelien Jacobs.
author | jbr |
---|---|
date | Mon, 01 Sep 2008 15:31:14 +0000 |
parents | 9c384a47085f |
children | f55b5e474321 |
comparison
equal
deleted
inserted
replaced
3863:9c384a47085f | 3864:b31edc09d556 |
---|---|
486 return 0; | 486 return 0; |
487 } | 487 } |
488 #endif | 488 #endif |
489 | 489 |
490 #if (ENABLE_AC3_DEMUXER || ENABLE_EAC3_DEMUXER) | 490 #if (ENABLE_AC3_DEMUXER || ENABLE_EAC3_DEMUXER) |
491 static int ac3_eac3_probe(AVProbeData *p, int *codec_id) | 491 static int ac3_eac3_probe(AVProbeData *p, enum CodecID expected_codec_id) |
492 { | 492 { |
493 int max_frames, first_frames = 0, frames; | 493 int max_frames, first_frames = 0, frames; |
494 uint8_t *buf, *buf2, *end; | 494 uint8_t *buf, *buf2, *end; |
495 AC3HeaderInfo hdr; | 495 AC3HeaderInfo hdr; |
496 GetBitContext gbc; | 496 GetBitContext gbc; |
497 enum CodecID codec_id = CODEC_ID_AC3; | |
497 | 498 |
498 max_frames = 0; | 499 max_frames = 0; |
499 buf = p->buf; | 500 buf = p->buf; |
500 end = buf + p->buf_size; | 501 end = buf + p->buf_size; |
501 | 502 |
502 *codec_id = CODEC_ID_AC3; | |
503 for(; buf < end; buf++) { | 503 for(; buf < end; buf++) { |
504 buf2 = buf; | 504 buf2 = buf; |
505 | 505 |
506 for(frames = 0; buf2 < end; frames++) { | 506 for(frames = 0; buf2 < end; frames++) { |
507 init_get_bits(&gbc, buf2, 54); | 507 init_get_bits(&gbc, buf2, 54); |
509 break; | 509 break; |
510 if(buf2 + hdr.frame_size > end || | 510 if(buf2 + hdr.frame_size > end || |
511 av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2)) | 511 av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2)) |
512 break; | 512 break; |
513 if (hdr.bitstream_id > 10) | 513 if (hdr.bitstream_id > 10) |
514 *codec_id = CODEC_ID_EAC3; | 514 codec_id = CODEC_ID_EAC3; |
515 buf2 += hdr.frame_size; | 515 buf2 += hdr.frame_size; |
516 } | 516 } |
517 max_frames = FFMAX(max_frames, frames); | 517 max_frames = FFMAX(max_frames, frames); |
518 if(buf == p->buf) | 518 if(buf == p->buf) |
519 first_frames = frames; | 519 first_frames = frames; |
520 } | 520 } |
521 if(codec_id != expected_codec_id) return 0; | |
521 if (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4; | 522 if (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4; |
522 else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2; | 523 else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2; |
523 else if(max_frames>=1) return 1; | 524 else if(max_frames>=1) return 1; |
524 else return 0; | 525 else return 0; |
525 } | 526 } |
526 #endif | 527 #endif |
527 | 528 |
528 #ifdef CONFIG_AC3_DEMUXER | 529 #ifdef CONFIG_AC3_DEMUXER |
529 static int ac3_probe(AVProbeData *p) | 530 static int ac3_probe(AVProbeData *p) |
530 { | 531 { |
531 int codec_id = CODEC_ID_NONE; | 532 return ac3_eac3_probe(p, CODEC_ID_AC3); |
532 int score = ac3_eac3_probe(p, &codec_id); | |
533 if(codec_id == CODEC_ID_AC3) | |
534 return score; | |
535 return 0; | |
536 } | 533 } |
537 #endif | 534 #endif |
538 | 535 |
539 #ifdef CONFIG_EAC3_DEMUXER | 536 #ifdef CONFIG_EAC3_DEMUXER |
540 static int eac3_probe(AVProbeData *p) | 537 static int eac3_probe(AVProbeData *p) |
541 { | 538 { |
542 int codec_id = CODEC_ID_NONE; | 539 return ac3_eac3_probe(p, CODEC_ID_EAC3); |
543 int score = ac3_eac3_probe(p, &codec_id); | |
544 if(codec_id == CODEC_ID_EAC3) | |
545 return score; | |
546 return 0; | |
547 } | 540 } |
548 #endif | 541 #endif |
549 | 542 |
550 #ifdef CONFIG_FLAC_DEMUXER | 543 #ifdef CONFIG_FLAC_DEMUXER |
551 static int flac_probe(AVProbeData *p) | 544 static int flac_probe(AVProbeData *p) |