Originally committed as revision 12922 to svn://svn.ffmpeg.org/ffmpeg/trunk
| ... | ... |
@@ -33,51 +33,64 @@ static const uint8_t eac3_blocks[4] = {
|
| 33 | 33 |
1, 2, 3, 6 |
| 34 | 34 |
}; |
| 35 | 35 |
|
| 36 |
+/** |
|
| 37 |
+ * Table for center mix levels |
|
| 38 |
+ * reference: Section 5.4.2.4 cmixlev |
|
| 39 |
+ */ |
|
| 40 |
+static const uint8_t center_levels[4] = { 2, 3, 4, 3 };
|
|
| 41 |
+ |
|
| 42 |
+/** |
|
| 43 |
+ * Table for surround mix levels |
|
| 44 |
+ * reference: Section 5.4.2.5 surmixlev |
|
| 45 |
+ */ |
|
| 46 |
+static const uint8_t surround_levels[4] = { 2, 4, 0, 4 };
|
|
| 36 | 47 |
|
| 37 |
-int ff_ac3_parse_header(const uint8_t buf[7], AC3HeaderInfo *hdr) |
|
| 48 |
+ |
|
| 49 |
+int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr) |
|
| 38 | 50 |
{
|
| 39 |
- GetBitContext gbc; |
|
| 40 | 51 |
int frame_size_code; |
| 41 | 52 |
int num_blocks; |
| 42 | 53 |
|
| 43 | 54 |
memset(hdr, 0, sizeof(*hdr)); |
| 44 | 55 |
|
| 45 |
- init_get_bits(&gbc, buf, 54); |
|
| 46 |
- |
|
| 47 |
- hdr->sync_word = get_bits(&gbc, 16); |
|
| 56 |
+ hdr->sync_word = get_bits(gbc, 16); |
|
| 48 | 57 |
if(hdr->sync_word != 0x0B77) |
| 49 | 58 |
return AC3_PARSE_ERROR_SYNC; |
| 50 | 59 |
|
| 51 | 60 |
/* read ahead to bsid to distinguish between AC-3 and E-AC-3 */ |
| 52 |
- hdr->bitstream_id = show_bits_long(&gbc, 29) & 0x1F; |
|
| 61 |
+ hdr->bitstream_id = show_bits_long(gbc, 29) & 0x1F; |
|
| 53 | 62 |
if(hdr->bitstream_id > 16) |
| 54 | 63 |
return AC3_PARSE_ERROR_BSID; |
| 55 | 64 |
|
| 56 | 65 |
if(hdr->bitstream_id <= 10) {
|
| 57 | 66 |
/* Normal AC-3 */ |
| 58 |
- hdr->crc1 = get_bits(&gbc, 16); |
|
| 59 |
- hdr->sr_code = get_bits(&gbc, 2); |
|
| 67 |
+ hdr->crc1 = get_bits(gbc, 16); |
|
| 68 |
+ hdr->sr_code = get_bits(gbc, 2); |
|
| 60 | 69 |
if(hdr->sr_code == 3) |
| 61 | 70 |
return AC3_PARSE_ERROR_SAMPLE_RATE; |
| 62 | 71 |
|
| 63 |
- frame_size_code = get_bits(&gbc, 6); |
|
| 72 |
+ frame_size_code = get_bits(gbc, 6); |
|
| 64 | 73 |
if(frame_size_code > 37) |
| 65 | 74 |
return AC3_PARSE_ERROR_FRAME_SIZE; |
| 66 | 75 |
|
| 67 |
- skip_bits(&gbc, 5); // skip bsid, already got it |
|
| 76 |
+ skip_bits(gbc, 5); // skip bsid, already got it |
|
| 77 |
+ |
|
| 78 |
+ skip_bits(gbc, 3); // skip bitstream mode |
|
| 79 |
+ hdr->channel_mode = get_bits(gbc, 3); |
|
| 80 |
+ |
|
| 81 |
+ /* set default mix levels */ |
|
| 82 |
+ hdr->center_mix_level = 3; // -4.5dB |
|
| 83 |
+ hdr->surround_mix_level = 4; // -6.0dB |
|
| 68 | 84 |
|
| 69 |
- skip_bits(&gbc, 3); // skip bitstream mode |
|
| 70 |
- hdr->channel_mode = get_bits(&gbc, 3); |
|
| 71 |
- if((hdr->channel_mode & 1) && hdr->channel_mode != AC3_CHMODE_MONO) {
|
|
| 72 |
- skip_bits(&gbc, 2); // skip center mix level |
|
| 73 |
- } |
|
| 74 |
- if(hdr->channel_mode & 4) {
|
|
| 75 |
- skip_bits(&gbc, 2); // skip surround mix level |
|
| 76 |
- } |
|
| 77 | 85 |
if(hdr->channel_mode == AC3_CHMODE_STEREO) {
|
| 78 |
- skip_bits(&gbc, 2); // skip dolby surround mode |
|
| 86 |
+ skip_bits(gbc, 2); // skip dsurmod |
|
| 87 |
+ } else {
|
|
| 88 |
+ if((hdr->channel_mode & 1) && hdr->channel_mode != AC3_CHMODE_MONO) |
|
| 89 |
+ hdr->center_mix_level = center_levels[get_bits(gbc, 2)]; |
|
| 90 |
+ if(hdr->channel_mode & 4) |
|
| 91 |
+ hdr->surround_mix_level = surround_levels[get_bits(gbc, 2)]; |
|
| 79 | 92 |
} |
| 80 |
- hdr->lfe_on = get_bits1(&gbc); |
|
| 93 |
+ hdr->lfe_on = get_bits1(gbc); |
|
| 81 | 94 |
|
| 82 | 95 |
hdr->sr_shift = FFMAX(hdr->bitstream_id, 8) - 8; |
| 83 | 96 |
hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code] >> hdr->sr_shift; |
| ... | ... |
@@ -88,32 +101,32 @@ int ff_ac3_parse_header(const uint8_t buf[7], AC3HeaderInfo *hdr) |
| 88 | 88 |
} else {
|
| 89 | 89 |
/* Enhanced AC-3 */ |
| 90 | 90 |
hdr->crc1 = 0; |
| 91 |
- hdr->frame_type = get_bits(&gbc, 2); |
|
| 91 |
+ hdr->frame_type = get_bits(gbc, 2); |
|
| 92 | 92 |
if(hdr->frame_type == EAC3_FRAME_TYPE_RESERVED) |
| 93 | 93 |
return AC3_PARSE_ERROR_FRAME_TYPE; |
| 94 | 94 |
|
| 95 |
- skip_bits(&gbc, 3); // skip substream id |
|
| 95 |
+ skip_bits(gbc, 3); // skip substream id |
|
| 96 | 96 |
|
| 97 |
- hdr->frame_size = (get_bits(&gbc, 11) + 1) << 1; |
|
| 97 |
+ hdr->frame_size = (get_bits(gbc, 11) + 1) << 1; |
|
| 98 | 98 |
if(hdr->frame_size < AC3_HEADER_SIZE) |
| 99 | 99 |
return AC3_PARSE_ERROR_FRAME_SIZE; |
| 100 | 100 |
|
| 101 |
- hdr->sr_code = get_bits(&gbc, 2); |
|
| 101 |
+ hdr->sr_code = get_bits(gbc, 2); |
|
| 102 | 102 |
if (hdr->sr_code == 3) {
|
| 103 |
- int sr_code2 = get_bits(&gbc, 2); |
|
| 103 |
+ int sr_code2 = get_bits(gbc, 2); |
|
| 104 | 104 |
if(sr_code2 == 3) |
| 105 | 105 |
return AC3_PARSE_ERROR_SAMPLE_RATE; |
| 106 | 106 |
hdr->sample_rate = ff_ac3_sample_rate_tab[sr_code2] / 2; |
| 107 | 107 |
hdr->sr_shift = 1; |
| 108 | 108 |
num_blocks = 6; |
| 109 | 109 |
} else {
|
| 110 |
- num_blocks = eac3_blocks[get_bits(&gbc, 2)]; |
|
| 110 |
+ num_blocks = eac3_blocks[get_bits(gbc, 2)]; |
|
| 111 | 111 |
hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code]; |
| 112 | 112 |
hdr->sr_shift = 0; |
| 113 | 113 |
} |
| 114 | 114 |
|
| 115 |
- hdr->channel_mode = get_bits(&gbc, 3); |
|
| 116 |
- hdr->lfe_on = get_bits1(&gbc); |
|
| 115 |
+ hdr->channel_mode = get_bits(gbc, 3); |
|
| 116 |
+ hdr->lfe_on = get_bits1(gbc); |
|
| 117 | 117 |
|
| 118 | 118 |
hdr->bit_rate = (uint32_t)(8.0 * hdr->frame_size * hdr->sample_rate / |
| 119 | 119 |
(num_blocks * 256.0)); |
| ... | ... |
@@ -129,8 +142,10 @@ static int ac3_sync(uint64_t state, AACAC3ParseContext *hdr_info, |
| 129 | 129 |
int err; |
| 130 | 130 |
uint64_t tmp = be2me_64(state); |
| 131 | 131 |
AC3HeaderInfo hdr; |
| 132 |
+ GetBitContext gbc; |
|
| 132 | 133 |
|
| 133 |
- err = ff_ac3_parse_header(((uint8_t *)&tmp)+8-AC3_HEADER_SIZE, &hdr); |
|
| 134 |
+ init_get_bits(&gbc, ((uint8_t *)&tmp)+8-AC3_HEADER_SIZE, 54); |
|
| 135 |
+ err = ff_ac3_parse_header(&gbc, &hdr); |
|
| 134 | 136 |
|
| 135 | 137 |
if(err < 0) |
| 136 | 138 |
return 0; |
| ... | ... |
@@ -24,6 +24,7 @@ |
| 24 | 24 |
#define FFMPEG_AC3_PARSER_H |
| 25 | 25 |
|
| 26 | 26 |
#include "ac3.h" |
| 27 |
+#include "bitstream.h" |
|
| 27 | 28 |
|
| 28 | 29 |
typedef enum {
|
| 29 | 30 |
AC3_PARSE_ERROR_SYNC = -1, |
| ... | ... |
@@ -37,12 +38,12 @@ typedef enum {
|
| 37 | 37 |
* Parses AC-3 frame header. |
| 38 | 38 |
* Parses the header up to the lfeon element, which is the first 52 or 54 bits |
| 39 | 39 |
* depending on the audio coding mode. |
| 40 |
- * @param buf[in] Array containing the first 7 bytes of the frame. |
|
| 40 |
+ * @param gbc[in] BitContext containing the first 54 bits of the frame. |
|
| 41 | 41 |
* @param hdr[out] Pointer to struct where header info is written. |
| 42 | 42 |
* @return Returns 0 on success, -1 if there is a sync word mismatch, |
| 43 | 43 |
* -2 if the bsid (version) element is invalid, -3 if the fscod (sample rate) |
| 44 | 44 |
* element is invalid, or -4 if the frmsizecod (bit rate) element is invalid. |
| 45 | 45 |
*/ |
| 46 |
-int ff_ac3_parse_header(const uint8_t buf[7], AC3HeaderInfo *hdr); |
|
| 46 |
+int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr); |
|
| 47 | 47 |
|
| 48 | 48 |
#endif /* FFMPEG_AC3_PARSER_H */ |
| ... | ... |
@@ -89,18 +89,6 @@ static const float gain_levels[6] = {
|
| 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 | 92 |
* Table for default stereo downmixing coefficients |
| 105 | 93 |
* reference: Section 7.8.2 Downmixing Into Two Channels |
| 106 | 94 |
*/ |
| ... | ... |
@@ -315,7 +303,7 @@ static int ac3_parse_header(AC3DecodeContext *s) |
| 315 | 315 |
GetBitContext *gbc = &s->gbc; |
| 316 | 316 |
int err, i; |
| 317 | 317 |
|
| 318 |
- err = ff_ac3_parse_header(gbc->buffer, &hdr); |
|
| 318 |
+ err = ff_ac3_parse_header(gbc, &hdr); |
|
| 319 | 319 |
if(err) |
| 320 | 320 |
return err; |
| 321 | 321 |
|
| ... | ... |
@@ -333,6 +321,8 @@ static int ac3_parse_header(AC3DecodeContext *s) |
| 333 | 333 |
s->fbw_channels = s->channels - s->lfe_on; |
| 334 | 334 |
s->lfe_ch = s->fbw_channels + 1; |
| 335 | 335 |
s->frame_size = hdr.frame_size; |
| 336 |
+ s->center_mix_level = hdr.center_mix_level; |
|
| 337 |
+ s->surround_mix_level = hdr.surround_mix_level; |
|
| 336 | 338 |
|
| 337 | 339 |
/* set default output to all source channels */ |
| 338 | 340 |
s->out_channels = s->channels; |
| ... | ... |
@@ -340,25 +330,6 @@ static int ac3_parse_header(AC3DecodeContext *s) |
| 340 | 340 |
if(s->lfe_on) |
| 341 | 341 |
s->output_mode |= AC3_OUTPUT_LFEON; |
| 342 | 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 |
- |
|
| 362 | 343 |
/* read the rest of the bsi. read twice for dual mono mode. */ |
| 363 | 344 |
i = !(s->channel_mode); |
| 364 | 345 |
do {
|
| ... | ... |
@@ -23,6 +23,7 @@ |
| 23 | 23 |
#include "ac3_parser.h" |
| 24 | 24 |
#include "raw.h" |
| 25 | 25 |
#include "crc.h" |
| 26 |
+#include "bitstream.h" |
|
| 26 | 27 |
|
| 27 | 28 |
#ifdef CONFIG_MUXERS |
| 28 | 29 |
/* simple formats */ |
| ... | ... |
@@ -419,6 +420,7 @@ static int ac3_probe(AVProbeData *p) |
| 419 | 419 |
int max_frames, first_frames = 0, frames; |
| 420 | 420 |
uint8_t *buf, *buf2, *end; |
| 421 | 421 |
AC3HeaderInfo hdr; |
| 422 |
+ GetBitContext gbc; |
|
| 422 | 423 |
|
| 423 | 424 |
max_frames = 0; |
| 424 | 425 |
buf = p->buf; |
| ... | ... |
@@ -428,7 +430,8 @@ static int ac3_probe(AVProbeData *p) |
| 428 | 428 |
buf2 = buf; |
| 429 | 429 |
|
| 430 | 430 |
for(frames = 0; buf2 < end; frames++) {
|
| 431 |
- if(ff_ac3_parse_header(buf2, &hdr) < 0) |
|
| 431 |
+ init_get_bits(&gbc, buf2, 54); |
|
| 432 |
+ if(ff_ac3_parse_header(&gbc, &hdr) < 0) |
|
| 432 | 433 |
break; |
| 433 | 434 |
if(buf2 + hdr.frame_size > end || |
| 434 | 435 |
av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2)) |