• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavformat/ac3dec.c

Go to the documentation of this file.
00001 /*
00002  * RAW AC-3 and E-AC-3 demuxer
00003  * Copyright (c) 2007 Justin Ruggles <justin.ruggles@gmail.com>
00004  *
00005  * This file is part of Libav.
00006  *
00007  * Libav is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * Libav is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with Libav; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "libavutil/crc.h"
00023 #include "libavcodec/ac3_parser.h"
00024 #include "avformat.h"
00025 #include "rawdec.h"
00026 
00027 static int ac3_eac3_probe(AVProbeData *p, enum CodecID expected_codec_id)
00028 {
00029     int max_frames, first_frames = 0, frames;
00030     uint8_t *buf, *buf2, *end;
00031     AC3HeaderInfo hdr;
00032     GetBitContext gbc;
00033     enum CodecID codec_id = CODEC_ID_AC3;
00034 
00035     max_frames = 0;
00036     buf = p->buf;
00037     end = buf + p->buf_size;
00038 
00039     for(; buf < end; buf++) {
00040         buf2 = buf;
00041 
00042         for(frames = 0; buf2 < end; frames++) {
00043             init_get_bits(&gbc, buf2, 54);
00044             if(avpriv_ac3_parse_header(&gbc, &hdr) < 0)
00045                 break;
00046             if(buf2 + hdr.frame_size > end ||
00047                av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2))
00048                 break;
00049             if (hdr.bitstream_id > 10)
00050                 codec_id = CODEC_ID_EAC3;
00051             buf2 += hdr.frame_size;
00052         }
00053         max_frames = FFMAX(max_frames, frames);
00054         if(buf == p->buf)
00055             first_frames = frames;
00056     }
00057     if(codec_id != expected_codec_id) return 0;
00058     // keep this in sync with mp3 probe, both need to avoid
00059     // issues with MPEG-files!
00060     if   (first_frames>=4) return AVPROBE_SCORE_MAX/2+1;
00061     else if(max_frames>500)return AVPROBE_SCORE_MAX/2;
00062     else if(max_frames>=4) return AVPROBE_SCORE_MAX/4;
00063     else if(max_frames>=1) return 1;
00064     else                   return 0;
00065 }
00066 
00067 #if CONFIG_AC3_DEMUXER
00068 static int ac3_probe(AVProbeData *p)
00069 {
00070     return ac3_eac3_probe(p, CODEC_ID_AC3);
00071 }
00072 
00073 AVInputFormat ff_ac3_demuxer = {
00074     .name           = "ac3",
00075     .long_name      = NULL_IF_CONFIG_SMALL("raw AC-3"),
00076     .read_probe     = ac3_probe,
00077     .read_header    = ff_raw_audio_read_header,
00078     .read_packet    = ff_raw_read_partial_packet,
00079     .flags= AVFMT_GENERIC_INDEX,
00080     .extensions = "ac3",
00081     .value = CODEC_ID_AC3,
00082 };
00083 #endif
00084 
00085 #if CONFIG_EAC3_DEMUXER
00086 static int eac3_probe(AVProbeData *p)
00087 {
00088     return ac3_eac3_probe(p, CODEC_ID_EAC3);
00089 }
00090 
00091 AVInputFormat ff_eac3_demuxer = {
00092     .name           = "eac3",
00093     .long_name      = NULL_IF_CONFIG_SMALL("raw E-AC-3"),
00094     .read_probe     = eac3_probe,
00095     .read_header    = ff_raw_audio_read_header,
00096     .read_packet    = ff_raw_read_partial_packet,
00097     .flags= AVFMT_GENERIC_INDEX,
00098     .extensions = "eac3",
00099     .value = CODEC_ID_EAC3,
00100 };
00101 #endif
Generated on Sun Apr 22 2012 21:53:59 for Libav by doxygen 1.7.1