#include "parser.h"#include "ac3_parser.h"#include "aac_ac3_parser.h"#include "bitstream.h"Go to the source code of this file.
Defines | |
| #define | AC3_HEADER_SIZE 7 |
Functions | |
| int | ff_ac3_parse_header (GetBitContext *gbc, AC3HeaderInfo *hdr) |
| int | ff_ac3_parse_header_full (GetBitContext *gbc, AC3HeaderInfo *hdr) |
| static int | ac3_sync (uint64_t state, AACAC3ParseContext *hdr_info, int *need_next_header, int *new_frame_start) |
| static av_cold int | ac3_parse_init (AVCodecParserContext *s1) |
Variables | |
| static const uint8_t | eac3_blocks [4] |
| AVCodecParser | ac3_parser |
| #define AC3_HEADER_SIZE 7 |
Definition at line 29 of file ac3_parser.c.
Referenced by ac3_parse_init(), ac3_sync(), and ff_ac3_parse_header().
| static av_cold int ac3_parse_init | ( | AVCodecParserContext * | s1 | ) | [static] |
Definition at line 181 of file ac3_parser.c.
References AC3_HEADER_SIZE, ac3_sync(), AACAC3ParseContext::header_size, s1, and AACAC3ParseContext::sync.
00182 { 00183 AACAC3ParseContext *s = s1->priv_data; 00184 s->header_size = AC3_HEADER_SIZE; 00185 s->sync = ac3_sync; 00186 return 0; 00187 }
| static int ac3_sync | ( | uint64_t | state, | |
| AACAC3ParseContext * | hdr_info, | |||
| int * | need_next_header, | |||
| int * | new_frame_start | |||
| ) | [static] |
Definition at line 157 of file ac3_parser.c.
References AC3_FRAME_SIZE, AC3_HEADER_SIZE, be2me_64, AC3HeaderInfo::bit_rate, AACAC3ParseContext::bit_rate, AC3HeaderInfo::channels, AACAC3ParseContext::channels, EAC3_FRAME_TYPE_AC3_CONVERT, EAC3_FRAME_TYPE_DEPENDENT, ff_ac3_parse_header(), AC3HeaderInfo::frame_size, AC3HeaderInfo::frame_type, init_get_bits(), AC3HeaderInfo::sample_rate, AACAC3ParseContext::sample_rate, and AACAC3ParseContext::samples.
Referenced by ac3_parse_init().
00159 { 00160 int err; 00161 uint64_t tmp = be2me_64(state); 00162 AC3HeaderInfo hdr; 00163 GetBitContext gbc; 00164 00165 init_get_bits(&gbc, ((uint8_t *)&tmp)+8-AC3_HEADER_SIZE, 54); 00166 err = ff_ac3_parse_header(&gbc, &hdr); 00167 00168 if(err < 0) 00169 return 0; 00170 00171 hdr_info->sample_rate = hdr.sample_rate; 00172 hdr_info->bit_rate = hdr.bit_rate; 00173 hdr_info->channels = hdr.channels; 00174 hdr_info->samples = AC3_FRAME_SIZE; 00175 00176 *need_next_header = (hdr.frame_type != EAC3_FRAME_TYPE_AC3_CONVERT); 00177 *new_frame_start = (hdr.frame_type != EAC3_FRAME_TYPE_DEPENDENT); 00178 return hdr.frame_size; 00179 }
| 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 }
Initial value:
{
{ CODEC_ID_AC3 },
sizeof(AACAC3ParseContext),
ac3_parse_init,
ff_aac_ac3_parse,
ff_parse_close,
}
Definition at line 190 of file ac3_parser.c.
const uint8_t eac3_blocks[4] [static] |
Initial value:
{
1, 2, 3, 6
}
Definition at line 32 of file ac3_parser.c.
Referenced by ff_ac3_parse_header().
1.5.1