#include "ac3.h"#include "bitstream.h"Go to the source code of this file.
Enumerations | |
| enum | AC3ParseError { AC3_PARSE_ERROR_SYNC = -1, AC3_PARSE_ERROR_BSID = -2, AC3_PARSE_ERROR_SAMPLE_RATE = -3, AC3_PARSE_ERROR_FRAME_SIZE = -4, AC3_PARSE_ERROR_FRAME_TYPE = -5, AC3_PARSE_ERROR_CRC = -6 } |
Functions | |
| int | ff_ac3_parse_header (GetBitContext *gbc, AC3HeaderInfo *hdr) |
| int | ff_ac3_parse_header_full (GetBitContext *gbc, AC3HeaderInfo *hdr) |
| enum AC3ParseError |
| AC3_PARSE_ERROR_SYNC | |
| AC3_PARSE_ERROR_BSID | |
| AC3_PARSE_ERROR_SAMPLE_RATE | |
| AC3_PARSE_ERROR_FRAME_SIZE | |
| AC3_PARSE_ERROR_FRAME_TYPE | |
| AC3_PARSE_ERROR_CRC |
Definition at line 29 of file ac3_parser.h.
00029 { 00030 AC3_PARSE_ERROR_SYNC = -1, 00031 AC3_PARSE_ERROR_BSID = -2, 00032 AC3_PARSE_ERROR_SAMPLE_RATE = -3, 00033 AC3_PARSE_ERROR_FRAME_SIZE = -4, 00034 AC3_PARSE_ERROR_FRAME_TYPE = -5, 00035 AC3_PARSE_ERROR_CRC = -6, 00036 } AC3ParseError;
| int ff_ac3_parse_header | ( | GetBitContext * | gbc, | |
| AC3HeaderInfo * | hdr | |||
| ) |
Parses AC-3 frame header. Parses the header up to the lfeon element, which is the first 52 or 54 bits depending on the audio coding mode.
| gbc[in] | BitContext containing the first 54 bits of the frame. | |
| hdr[out] | Pointer to struct where header info is written. |
Definition at line 37 of file ac3_parser.c.
References AC3_CHMODE_MONO, AC3_CHMODE_STEREO, AC3_HEADER_SIZE, AC3_PARSE_ERROR_BSID, AC3_PARSE_ERROR_FRAME_SIZE, AC3_PARSE_ERROR_FRAME_TYPE, AC3_PARSE_ERROR_SAMPLE_RATE, AC3_PARSE_ERROR_SYNC, eac3_blocks, EAC3_FRAME_TYPE_AC3_CONVERT, EAC3_FRAME_TYPE_RESERVED, ff_ac3_bitrate_tab, ff_ac3_channels_tab, ff_ac3_frame_size_tab, ff_ac3_sample_rate_tab, FFMAX, get_bits(), get_bits1(), show_bits_long(), and skip_bits().
Referenced by ac3_probe(), ac3_sync(), ff_ac3_parse_header_full(), and parse_frame_header().
00038 { 00039 int frame_size_code; 00040 00041 memset(hdr, 0, sizeof(*hdr)); 00042 00043 hdr->sync_word = get_bits(gbc, 16); 00044 if(hdr->sync_word != 0x0B77) 00045 return AC3_PARSE_ERROR_SYNC; 00046 00047 /* read ahead to bsid to distinguish between AC-3 and E-AC-3 */ 00048 hdr->bitstream_id = show_bits_long(gbc, 29) & 0x1F; 00049 if(hdr->bitstream_id > 16) 00050 return AC3_PARSE_ERROR_BSID; 00051 00052 hdr->num_blocks = 6; 00053 00054 /* set default mix levels */ 00055 hdr->center_mix_level = 1; // -4.5dB 00056 hdr->surround_mix_level = 1; // -6.0dB 00057 00058 if(hdr->bitstream_id <= 10) { 00059 /* Normal AC-3 */ 00060 hdr->crc1 = get_bits(gbc, 16); 00061 hdr->sr_code = get_bits(gbc, 2); 00062 if(hdr->sr_code == 3) 00063 return AC3_PARSE_ERROR_SAMPLE_RATE; 00064 00065 frame_size_code = get_bits(gbc, 6); 00066 if(frame_size_code > 37) 00067 return AC3_PARSE_ERROR_FRAME_SIZE; 00068 00069 skip_bits(gbc, 5); // skip bsid, already got it 00070 00071 skip_bits(gbc, 3); // skip bitstream mode 00072 hdr->channel_mode = get_bits(gbc, 3); 00073 00074 if(hdr->channel_mode == AC3_CHMODE_STEREO) { 00075 skip_bits(gbc, 2); // skip dsurmod 00076 } else { 00077 if((hdr->channel_mode & 1) && hdr->channel_mode != AC3_CHMODE_MONO) 00078 hdr->center_mix_level = get_bits(gbc, 2); 00079 if(hdr->channel_mode & 4) 00080 hdr->surround_mix_level = get_bits(gbc, 2); 00081 } 00082 hdr->lfe_on = get_bits1(gbc); 00083 00084 hdr->sr_shift = FFMAX(hdr->bitstream_id, 8) - 8; 00085 hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code] >> hdr->sr_shift; 00086 hdr->bit_rate = (ff_ac3_bitrate_tab[frame_size_code>>1] * 1000) >> hdr->sr_shift; 00087 hdr->channels = ff_ac3_channels_tab[hdr->channel_mode] + hdr->lfe_on; 00088 hdr->frame_size = ff_ac3_frame_size_tab[frame_size_code][hdr->sr_code] * 2; 00089 hdr->frame_type = EAC3_FRAME_TYPE_AC3_CONVERT; //EAC3_FRAME_TYPE_INDEPENDENT; 00090 hdr->substreamid = 0; 00091 } else { 00092 /* Enhanced AC-3 */ 00093 hdr->crc1 = 0; 00094 hdr->frame_type = get_bits(gbc, 2); 00095 if(hdr->frame_type == EAC3_FRAME_TYPE_RESERVED) 00096 return AC3_PARSE_ERROR_FRAME_TYPE; 00097 00098 hdr->substreamid = get_bits(gbc, 3); 00099 00100 hdr->frame_size = (get_bits(gbc, 11) + 1) << 1; 00101 if(hdr->frame_size < AC3_HEADER_SIZE) 00102 return AC3_PARSE_ERROR_FRAME_SIZE; 00103 00104 hdr->sr_code = get_bits(gbc, 2); 00105 if (hdr->sr_code == 3) { 00106 int sr_code2 = get_bits(gbc, 2); 00107 if(sr_code2 == 3) 00108 return AC3_PARSE_ERROR_SAMPLE_RATE; 00109 hdr->sample_rate = ff_ac3_sample_rate_tab[sr_code2] / 2; 00110 hdr->sr_shift = 1; 00111 } else { 00112 hdr->num_blocks = eac3_blocks[get_bits(gbc, 2)]; 00113 hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code]; 00114 hdr->sr_shift = 0; 00115 } 00116 00117 hdr->channel_mode = get_bits(gbc, 3); 00118 hdr->lfe_on = get_bits1(gbc); 00119 00120 hdr->bit_rate = (uint32_t)(8.0 * hdr->frame_size * hdr->sample_rate / 00121 (hdr->num_blocks * 256.0)); 00122 hdr->channels = ff_ac3_channels_tab[hdr->channel_mode] + hdr->lfe_on; 00123 } 00124 00125 return 0; 00126 }
| int ff_ac3_parse_header_full | ( | GetBitContext * | gbc, | |
| AC3HeaderInfo * | hdr | |||
| ) |
Parses AC-3 frame header and sets channel_map Parses the header up to the lfeon (channel_map in E-AC-3) element, which is the first 52, 54 or 104 bits depending on the audio coding mode.
| gbc[in] | BitContext containing the first 54 bits of the frame. | |
| hdr[out] | Pointer to struct where header info is written. |
Definition at line 128 of file ac3_parser.c.
References AC3_CHMAP_LFE, AC3HeaderInfo::bitstream_id, AC3HeaderInfo::channel_map, AC3HeaderInfo::channel_mode, EAC3_FRAME_TYPE_DEPENDENT, ff_ac3_parse_header(), ff_eac3_default_chmap, AC3HeaderInfo::frame_type, get_bits(), get_bits1(), AC3HeaderInfo::lfe_on, and skip_bits().
00128 { 00129 int ret, i; 00130 ret = ff_ac3_parse_header(gbc, hdr); 00131 if(!ret){ 00132 if(hdr->bitstream_id>10){ 00133 /* Enhanced AC-3 */ 00134 skip_bits(gbc, 5); // skip bitstream id 00135 00136 /* skip dialog normalization and compression gain */ 00137 for (i = 0; i < (hdr->channel_mode ? 1 : 2); i++) { 00138 skip_bits(gbc, 5); // skip dialog normalization 00139 if (get_bits1(gbc)) { 00140 skip_bits(gbc, 8); //skip Compression gain word 00141 } 00142 } 00143 /* dependent stream channel map */ 00144 if (hdr->frame_type == EAC3_FRAME_TYPE_DEPENDENT && get_bits1(gbc)) { 00145 hdr->channel_map = get_bits(gbc, 16); //custom channel map 00146 return 0; 00147 } 00148 } 00149 //default channel map based on acmod and lfeon 00150 hdr->channel_map = ff_eac3_default_chmap[hdr->channel_mode]; 00151 if(hdr->lfe_on) 00152 hdr->channel_map |= AC3_CHMAP_LFE; 00153 } 00154 return ret; 00155 }
1.5.1