comparison ac3dec.c @ 6661:a409fbf1f42b libavcodec

change ff_ac3_parse_header() to take a GetBitContext instead of const char*
author bwolowiec
date Tue, 22 Apr 2008 11:14:01 +0000
parents b0d44aec1ec0
children 5b3acf9fd50a
comparison
equal deleted inserted replaced
6660:582712867474 6661:a409fbf1f42b
87 LEVEL_MINUS_6DB, 87 LEVEL_MINUS_6DB,
88 LEVEL_MINUS_9DB 88 LEVEL_MINUS_9DB
89 }; 89 };
90 90
91 /** 91 /**
92 * Table for center mix levels
93 * reference: Section 5.4.2.4 cmixlev
94 */
95 static const uint8_t center_levels[4] = { 2, 3, 4, 3 };
96
97 /**
98 * Table for surround mix levels
99 * reference: Section 5.4.2.5 surmixlev
100 */
101 static const uint8_t surround_levels[4] = { 2, 4, 0, 4 };
102
103 /**
104 * Table for default stereo downmixing coefficients 92 * Table for default stereo downmixing coefficients
105 * reference: Section 7.8.2 Downmixing Into Two Channels 93 * reference: Section 7.8.2 Downmixing Into Two Channels
106 */ 94 */
107 static const uint8_t ac3_default_coeffs[8][5][2] = { 95 static const uint8_t ac3_default_coeffs[8][5][2] = {
108 { { 1, 0 }, { 0, 1 }, }, 96 { { 1, 0 }, { 0, 1 }, },
313 { 301 {
314 AC3HeaderInfo hdr; 302 AC3HeaderInfo hdr;
315 GetBitContext *gbc = &s->gbc; 303 GetBitContext *gbc = &s->gbc;
316 int err, i; 304 int err, i;
317 305
318 err = ff_ac3_parse_header(gbc->buffer, &hdr); 306 err = ff_ac3_parse_header(gbc, &hdr);
319 if(err) 307 if(err)
320 return err; 308 return err;
321 309
322 if(hdr.bitstream_id > 10) 310 if(hdr.bitstream_id > 10)
323 return AC3_PARSE_ERROR_BSID; 311 return AC3_PARSE_ERROR_BSID;
331 s->bit_rate = hdr.bit_rate; 319 s->bit_rate = hdr.bit_rate;
332 s->channels = hdr.channels; 320 s->channels = hdr.channels;
333 s->fbw_channels = s->channels - s->lfe_on; 321 s->fbw_channels = s->channels - s->lfe_on;
334 s->lfe_ch = s->fbw_channels + 1; 322 s->lfe_ch = s->fbw_channels + 1;
335 s->frame_size = hdr.frame_size; 323 s->frame_size = hdr.frame_size;
324 s->center_mix_level = hdr.center_mix_level;
325 s->surround_mix_level = hdr.surround_mix_level;
336 326
337 /* set default output to all source channels */ 327 /* set default output to all source channels */
338 s->out_channels = s->channels; 328 s->out_channels = s->channels;
339 s->output_mode = s->channel_mode; 329 s->output_mode = s->channel_mode;
340 if(s->lfe_on) 330 if(s->lfe_on)
341 s->output_mode |= AC3_OUTPUT_LFEON; 331 s->output_mode |= AC3_OUTPUT_LFEON;
342
343 /* set default mix levels */
344 s->center_mix_level = 3; // -4.5dB
345 s->surround_mix_level = 4; // -6.0dB
346
347 /* skip over portion of header which has already been read */
348 skip_bits(gbc, 16); // skip the sync_word
349 skip_bits(gbc, 16); // skip crc1
350 skip_bits(gbc, 8); // skip fscod and frmsizecod
351 skip_bits(gbc, 11); // skip bsid, bsmod, and acmod
352 if(s->channel_mode == AC3_CHMODE_STEREO) {
353 skip_bits(gbc, 2); // skip dsurmod
354 } else {
355 if((s->channel_mode & 1) && s->channel_mode != AC3_CHMODE_MONO)
356 s->center_mix_level = center_levels[get_bits(gbc, 2)];
357 if(s->channel_mode & 4)
358 s->surround_mix_level = surround_levels[get_bits(gbc, 2)];
359 }
360 skip_bits1(gbc); // skip lfeon
361 332
362 /* read the rest of the bsi. read twice for dual mono mode. */ 333 /* read the rest of the bsi. read twice for dual mono mode. */
363 i = !(s->channel_mode); 334 i = !(s->channel_mode);
364 do { 335 do {
365 skip_bits(gbc, 5); // skip dialog normalization 336 skip_bits(gbc, 5); // skip dialog normalization