From: Alexandra Hájková <[email protected]>
---
libavcodec/ac3_parser.c | 51 ++++++------
libavcodec/ac3_parser.h | 6 +-
libavcodec/ac3dec.c | 212 ++++++++++++++++++++++++------------------------
libavcodec/ac3dec.h | 5 +-
libavcodec/eac3dec.c | 183 ++++++++++++++++++++---------------------
libavformat/ac3dec.c | 6 +-
6 files changed, 230 insertions(+), 233 deletions(-)
diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index 9704848..a7db17e 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -21,10 +21,11 @@
*/
#include "libavutil/channel_layout.h"
+
+#include "bitstream.h"
#include "parser.h"
#include "ac3_parser.h"
#include "aac_ac3_parser.h"
-#include "get_bits.h"
#define AC3_HEADER_SIZE 7
@@ -47,18 +48,18 @@ static const uint8_t center_levels[4] = { 4, 5, 6, 5 };
static const uint8_t surround_levels[4] = { 4, 6, 7, 6 };
-int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
+int avpriv_ac3_parse_header(BitstreamContext *bc, AC3HeaderInfo *hdr)
{
int frame_size_code;
memset(hdr, 0, sizeof(*hdr));
- hdr->sync_word = get_bits(gbc, 16);
+ hdr->sync_word = bitstream_read(bc, 16);
if(hdr->sync_word != 0x0B77)
return AAC_AC3_PARSE_ERROR_SYNC;
/* read ahead to bsid to distinguish between AC-3 and E-AC-3 */
- hdr->bitstream_id = show_bits_long(gbc, 29) & 0x1F;
+ hdr->bitstream_id = bitstream_peek(bc, 29) & 0x1F;
if(hdr->bitstream_id > 16)
return AAC_AC3_PARSE_ERROR_BSID;
@@ -73,29 +74,29 @@ int avpriv_ac3_parse_header(GetBitContext *gbc,
AC3HeaderInfo *hdr)
if(hdr->bitstream_id <= 10) {
/* Normal AC-3 */
- hdr->crc1 = get_bits(gbc, 16);
- hdr->sr_code = get_bits(gbc, 2);
+ hdr->crc1 = bitstream_read(bc, 16);
+ hdr->sr_code = bitstream_read(bc, 2);
if(hdr->sr_code == 3)
return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
- frame_size_code = get_bits(gbc, 6);
+ frame_size_code = bitstream_read(bc, 6);
if(frame_size_code > 37)
return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
- skip_bits(gbc, 5); // skip bsid, already got it
+ bitstream_skip(bc, 5); // skip bsid, already got it
- hdr->bitstream_mode = get_bits(gbc, 3);
- hdr->channel_mode = get_bits(gbc, 3);
+ hdr->bitstream_mode = bitstream_read(bc, 3);
+ hdr->channel_mode = bitstream_read(bc, 3);
if(hdr->channel_mode == AC3_CHMODE_STEREO) {
- hdr->dolby_surround_mode = get_bits(gbc, 2);
+ hdr->dolby_surround_mode = bitstream_read(bc, 2);
} else {
if((hdr->channel_mode & 1) && hdr->channel_mode != AC3_CHMODE_MONO)
- hdr-> center_mix_level = center_levels[get_bits(gbc, 2)];
+ hdr->center_mix_level = center_levels[bitstream_read(bc, 2)];
if(hdr->channel_mode & 4)
- hdr->surround_mix_level = surround_levels[get_bits(gbc, 2)];
+ hdr->surround_mix_level = surround_levels[bitstream_read(bc,
2)];
}
- hdr->lfe_on = get_bits1(gbc);
+ hdr->lfe_on = bitstream_read_bit(bc);
hdr->sr_shift = FFMAX(hdr->bitstream_id, 8) - 8;
hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code] >>
hdr->sr_shift;
@@ -107,31 +108,31 @@ int avpriv_ac3_parse_header(GetBitContext *gbc,
AC3HeaderInfo *hdr)
} else {
/* Enhanced AC-3 */
hdr->crc1 = 0;
- hdr->frame_type = get_bits(gbc, 2);
+ hdr->frame_type = bitstream_read(bc, 2);
if(hdr->frame_type == EAC3_FRAME_TYPE_RESERVED)
return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
- hdr->substreamid = get_bits(gbc, 3);
+ hdr->substreamid = bitstream_read(bc, 3);
- hdr->frame_size = (get_bits(gbc, 11) + 1) << 1;
+ hdr->frame_size = (bitstream_read(bc, 11) + 1) << 1;
if(hdr->frame_size < AC3_HEADER_SIZE)
return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
- hdr->sr_code = get_bits(gbc, 2);
+ hdr->sr_code = bitstream_read(bc, 2);
if (hdr->sr_code == 3) {
- int sr_code2 = get_bits(gbc, 2);
+ int sr_code2 = bitstream_read(bc, 2);
if(sr_code2 == 3)
return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
hdr->sample_rate = ff_ac3_sample_rate_tab[sr_code2] / 2;
hdr->sr_shift = 1;
} else {
- hdr->num_blocks = eac3_blocks[get_bits(gbc, 2)];
+ hdr->num_blocks = eac3_blocks[bitstream_read(bc, 2)];
hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code];
hdr->sr_shift = 0;
}
- hdr->channel_mode = get_bits(gbc, 3);
- hdr->lfe_on = get_bits1(gbc);
+ hdr->channel_mode = bitstream_read(bc, 3);
+ hdr->lfe_on = bitstream_read_bit(bc);
hdr->bit_rate = (uint32_t)(8.0 * hdr->frame_size * hdr->sample_rate /
(hdr->num_blocks * 256.0));
@@ -153,10 +154,10 @@ static int ac3_sync(uint64_t state, AACAC3ParseContext
*hdr_info,
uint8_t u8[8 + AV_INPUT_BUFFER_PADDING_SIZE];
} tmp = { av_be2ne64(state) };
AC3HeaderInfo hdr;
- GetBitContext gbc;
+ BitstreamContext bc;
- init_get_bits(&gbc, tmp.u8+8-AC3_HEADER_SIZE, 54);
- err = avpriv_ac3_parse_header(&gbc, &hdr);
+ bitstream_init(&bc, tmp.u8 + 8 - AC3_HEADER_SIZE, 54);
+ err = avpriv_ac3_parse_header(&bc, &hdr);
if(err < 0)
return 0;
diff --git a/libavcodec/ac3_parser.h b/libavcodec/ac3_parser.h
index 9322550..660ddd7 100644
--- a/libavcodec/ac3_parser.h
+++ b/libavcodec/ac3_parser.h
@@ -24,18 +24,18 @@
#define AVCODEC_AC3_PARSER_H
#include "ac3.h"
-#include "get_bits.h"
+#include "bitstream.h"
/**
* Parse AC-3 frame header.
* Parse the header up to the lfeon element, which is the first 52 or 54 bits
* depending on the audio coding mode.
- * @param[in] gbc BitContext containing the first 54 bits of the frame.
+ * @param[in] bc BitContext containing the first 54 bits of the frame.
* @param[out] hdr Pointer to struct where header info is written.
* @return Returns 0 on success, -1 if there is a sync word mismatch,
* -2 if the bsid (version) element is invalid, -3 if the fscod (sample rate)
* element is invalid, or -4 if the frmsizecod (bit rate) element is invalid.
*/
-int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr);
+int avpriv_ac3_parse_header(BitstreamContext *bc, AC3HeaderInfo *hdr);
#endif /* AVCODEC_AC3_PARSER_H */
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index 9b08638..dcd12e1 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -208,54 +208,54 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
/**
* Parse the 'sync info' and 'bit stream info' from the AC-3 bitstream.
- * GetBitContext within AC3DecodeContext must point to
+ * BitstreamContext within AC3DecodeContext must point to
* the start of the synchronized AC-3 bitstream.
*/
static int ac3_parse_header(AC3DecodeContext *s)
{
- GetBitContext *gbc = &s->gbc;
+ BitstreamContext *bc = &s->bc;
int i;
/* read the rest of the bsi. read twice for dual mono mode. */
i = !s->channel_mode;
do {
- skip_bits(gbc, 5); // skip dialog normalization
- if (get_bits1(gbc))
- skip_bits(gbc, 8); //skip compression
- if (get_bits1(gbc))
- skip_bits(gbc, 8); //skip language code
- if (get_bits1(gbc))
- skip_bits(gbc, 7); //skip audio production information
+ bitstream_skip(bc, 5); // skip dialog normalization
+ if (bitstream_read_bit(bc))
+ bitstream_skip(bc, 8); // skip compression
+ if (bitstream_read_bit(bc))
+ bitstream_skip(bc, 8); // skip language code
+ if (bitstream_read_bit(bc))
+ bitstream_skip(bc, 7); // skip audio production information
} while (i--);
- skip_bits(gbc, 2); //skip copyright bit and original bitstream bit
+ bitstream_skip(bc, 2); // skip copyright bit and original bitstream bit
/* skip the timecodes or parse the Alternate Bit Stream Syntax */
if (s->bitstream_id != 6) {
- if (get_bits1(gbc))
- skip_bits(gbc, 14); //skip timecode1
- if (get_bits1(gbc))
- skip_bits(gbc, 14); //skip timecode2
+ if (bitstream_read_bit(bc))
+ bitstream_skip(bc, 14); // skip timecode1
+ if (bitstream_read_bit(bc))
+ bitstream_skip(bc, 14); // skip timecode2
} else {
- if (get_bits1(gbc)) {
- s->preferred_downmix = get_bits(gbc, 2);
- s->center_mix_level_ltrt = get_bits(gbc, 3);
- s->surround_mix_level_ltrt = av_clip(get_bits(gbc, 3), 3, 7);
- s->center_mix_level = get_bits(gbc, 3);
- s->surround_mix_level = av_clip(get_bits(gbc, 3), 3, 7);
+ if (bitstream_read_bit(bc)) {
+ s->preferred_downmix = bitstream_read(bc, 2);
+ s->center_mix_level_ltrt = bitstream_read(bc, 3);
+ s->surround_mix_level_ltrt = av_clip(bitstream_read(bc, 3), 3, 7);
+ s->center_mix_level = bitstream_read(bc, 3);
+ s->surround_mix_level = av_clip(bitstream_read(bc, 3), 3, 7);
}
- if (get_bits1(gbc)) {
- s->dolby_surround_ex_mode = get_bits(gbc, 2);
- s->dolby_headphone_mode = get_bits(gbc, 2);
- skip_bits(gbc, 10); // skip adconvtyp (1), xbsi2 (8), encinfo (1)
+ if (bitstream_read_bit(bc)) {
+ s->dolby_surround_ex_mode = bitstream_read(bc, 2);
+ s->dolby_headphone_mode = bitstream_read(bc, 2);
+ bitstream_skip(bc, 10); // skip adconvtyp (1), xbsi2 (8), encinfo
(1)
}
}
/* skip additional bitstream info */
- if (get_bits1(gbc)) {
- i = get_bits(gbc, 6);
+ if (bitstream_read_bit(bc)) {
+ i = bitstream_read(bc, 6);
do {
- skip_bits(gbc, 8);
+ bitstream_skip(bc, 8);
} while (i--);
}
@@ -270,7 +270,7 @@ static int parse_frame_header(AC3DecodeContext *s)
AC3HeaderInfo hdr;
int err;
- err = avpriv_ac3_parse_header(&s->gbc, &hdr);
+ err = avpriv_ac3_parse_header(&s->bc, &hdr);
if (err)
return err;
@@ -379,7 +379,7 @@ static void set_downmix_coeffs(AC3DecodeContext *s)
* Decode the grouped exponents according to exponent strategy.
* reference: Section 7.1.3 Exponent Decoding
*/
-static int decode_exponents(GetBitContext *gbc, int exp_strategy, int ngrps,
+static int decode_exponents(BitstreamContext *bc, int exp_strategy, int ngrps,
uint8_t absexp, int8_t *dexps)
{
int i, j, grp, group_size;
@@ -389,7 +389,7 @@ static int decode_exponents(GetBitContext *gbc, int
exp_strategy, int ngrps,
/* unpack groups */
group_size = exp_strategy + (exp_strategy == EXP_D45);
for (grp = 0, i = 0; grp < ngrps; grp++) {
- expacc = get_bits(gbc, 7);
+ expacc = bitstream_read(bc, 7);
dexp[i++] = ungroup_3_in_7_bits_tab[expacc][0];
dexp[i++] = ungroup_3_in_7_bits_tab[expacc][1];
dexp[i++] = ungroup_3_in_7_bits_tab[expacc][2];
@@ -465,7 +465,7 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext
*s, int ch_index, ma
int8_t *exps = s->dexps[ch_index];
int32_t *coeffs = s->fixed_coeffs[ch_index];
int dither = (ch_index == CPL_CH) || s->dither_flag[ch_index];
- GetBitContext *gbc = &s->gbc;
+ BitstreamContext *bc = &s->bc;
int freq;
for (freq = start_freq; freq < end_freq; freq++) {
@@ -484,7 +484,7 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext
*s, int ch_index, ma
m->b1--;
mantissa = m->b1_mant[m->b1];
} else {
- int bits = get_bits(gbc, 5);
+ int bits = bitstream_read(bc, 5);
mantissa = b1_mantissas[bits][0];
m->b1_mant[1] = b1_mantissas[bits][1];
m->b1_mant[0] = b1_mantissas[bits][2];
@@ -496,7 +496,7 @@ static void ac3_decode_transform_coeffs_ch(AC3DecodeContext
*s, int ch_index, ma
m->b2--;
mantissa = m->b2_mant[m->b2];
} else {
- int bits = get_bits(gbc, 7);
+ int bits = bitstream_read(bc, 7);
mantissa = b2_mantissas[bits][0];
m->b2_mant[1] = b2_mantissas[bits][1];
m->b2_mant[0] = b2_mantissas[bits][2];
@@ -504,25 +504,25 @@ static void
ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, ma
}
break;
case 3:
- mantissa = b3_mantissas[get_bits(gbc, 3)];
+ mantissa = b3_mantissas[bitstream_read(bc, 3)];
break;
case 4:
if (m->b4) {
m->b4 = 0;
mantissa = m->b4_mant;
} else {
- int bits = get_bits(gbc, 7);
+ int bits = bitstream_read(bc, 7);
mantissa = b4_mantissas[bits][0];
m->b4_mant = b4_mantissas[bits][1];
m->b4 = 1;
}
break;
case 5:
- mantissa = b5_mantissas[get_bits(gbc, 4)];
+ mantissa = b5_mantissas[bitstream_read(bc, 4)];
break;
default: /* 6 to 15 */
/* Shift mantissa and sign-extend it. */
- mantissa = get_sbits(gbc, quantization_tab[bap]);
+ mantissa = bitstream_read_signed(bc, quantization_tab[bap]);
mantissa <<= 24 - quantization_tab[bap];
break;
}
@@ -687,7 +687,7 @@ static void ac3_upmix_delay(AC3DecodeContext *s)
* subband in the range, 1 means it is combined with the previous band, and 0
* means that it starts a new band.
*
- * @param[in] gbc bit reader context
+ * @param[in] bc bit reader context
* @param[in] blk block number
* @param[in] eac3 flag to indicate E-AC-3
* @param[in] ecpl flag to indicate enhanced coupling
@@ -697,7 +697,7 @@ static void ac3_upmix_delay(AC3DecodeContext *s)
* @param[out] num_bands number of bands (optionally NULL)
* @param[out] band_sizes array containing the number of bins in each band
(optionally NULL)
*/
-static void decode_band_structure(GetBitContext *gbc, int blk, int eac3,
+static void decode_band_structure(BitstreamContext *bc, int blk, int eac3,
int ecpl, int start_subband, int end_subband,
const uint8_t *default_band_struct,
int *num_bands, uint8_t *band_sizes)
@@ -710,9 +710,9 @@ static void decode_band_structure(GetBitContext *gbc, int
blk, int eac3,
n_subbands = end_subband - start_subband;
/* decode band structure from bitstream or use default */
- if (!eac3 || get_bits1(gbc)) {
+ if (!eac3 || bitstream_read_bit(bc)) {
for (subbnd = 0; subbnd < n_subbands - 1; subbnd++) {
- coded_band_struct[subbnd] = get_bits1(gbc);
+ coded_band_struct[subbnd] = bitstream_read_bit(bc);
}
band_struct = coded_band_struct;
} else if (!blk) {
@@ -757,14 +757,14 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
int different_transforms;
int downmix_output;
int cpl_in_use;
- GetBitContext *gbc = &s->gbc;
+ BitstreamContext *bc = &s->bc;
uint8_t bit_alloc_stages[AC3_MAX_CHANNELS] = { 0 };
/* block switch flags */
different_transforms = 0;
if (s->block_switch_syntax) {
for (ch = 1; ch <= fbw_channels; ch++) {
- s->block_switch[ch] = get_bits1(gbc);
+ s->block_switch[ch] = bitstream_read_bit(bc);
if (ch > 1 && s->block_switch[ch] != s->block_switch[1])
different_transforms = 1;
}
@@ -773,17 +773,17 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
/* dithering flags */
if (s->dither_flag_syntax) {
for (ch = 1; ch <= fbw_channels; ch++) {
- s->dither_flag[ch] = get_bits1(gbc);
+ s->dither_flag[ch] = bitstream_read_bit(bc);
}
}
/* dynamic range */
i = !s->channel_mode;
do {
- if (get_bits1(gbc)) {
+ if (bitstream_read_bit(bc)) {
/* Allow asymmetric application of DRC when drc_scale > 1.
Amplification of quiet sounds is enhanced */
- float range = dynamic_range_tab[get_bits(gbc, 8)];
+ float range = dynamic_range_tab[bitstream_read(bc, 8)];
if (range > 1.0 || s->drc_scale <= 1.0)
s->dynamic_range[i] = powf(range, s->drc_scale);
else
@@ -794,8 +794,8 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
} while (i--);
/* spectral extension strategy */
- if (s->eac3 && (!blk || get_bits1(gbc))) {
- s->spx_in_use = get_bits1(gbc);
+ if (s->eac3 && (!blk || bitstream_read_bit(bc))) {
+ s->spx_in_use = bitstream_read_bit(bc);
if (s->spx_in_use) {
int dst_start_freq, dst_end_freq, src_start_freq,
start_subband, end_subband;
@@ -805,16 +805,16 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
s->channel_uses_spx[1] = 1;
} else {
for (ch = 1; ch <= fbw_channels; ch++)
- s->channel_uses_spx[ch] = get_bits1(gbc);
+ s->channel_uses_spx[ch] = bitstream_read_bit(bc);
}
/* get the frequency bins of the spx copy region and the spx start
and end subbands */
- dst_start_freq = get_bits(gbc, 2);
- start_subband = get_bits(gbc, 3) + 2;
+ dst_start_freq = bitstream_read(bc, 2);
+ start_subband = bitstream_read(bc, 3) + 2;
if (start_subband > 7)
start_subband += start_subband - 7;
- end_subband = get_bits(gbc, 3) + 5;
+ end_subband = bitstream_read(bc, 3) + 5;
if (end_subband > 7)
end_subband += end_subband - 7;
dst_start_freq = dst_start_freq * 12 + 25;
@@ -837,7 +837,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
s->spx_src_start_freq = src_start_freq;
s->spx_dst_end_freq = dst_end_freq;
- decode_band_structure(gbc, blk, s->eac3, 0,
+ decode_band_structure(bc, blk, s->eac3, 0,
start_subband, end_subband,
ff_eac3_default_spx_band_struct,
&s->num_spx_bands,
@@ -854,13 +854,13 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
if (s->spx_in_use) {
for (ch = 1; ch <= fbw_channels; ch++) {
if (s->channel_uses_spx[ch]) {
- if (s->first_spx_coords[ch] || get_bits1(gbc)) {
+ if (s->first_spx_coords[ch] || bitstream_read_bit(bc)) {
float spx_blend;
int bin, master_spx_coord;
s->first_spx_coords[ch] = 0;
- spx_blend = get_bits(gbc, 5) * (1.0f/32);
- master_spx_coord = get_bits(gbc, 2) * 3;
+ spx_blend = bitstream_read(bc, 5) * (1.0f / 32);
+ master_spx_coord = bitstream_read(bc, 2) * 3;
bin = s->spx_src_start_freq;
for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
@@ -878,8 +878,8 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
bin += bandsize;
/* decode spx coordinates */
- spx_coord_exp = get_bits(gbc, 4);
- spx_coord_mant = get_bits(gbc, 2);
+ spx_coord_exp = bitstream_read(bc, 4);
+ spx_coord_mant = bitstream_read(bc, 2);
if (spx_coord_exp == 15) spx_coord_mant <<= 1;
else spx_coord_mant += 4;
spx_coord_mant <<= (25 - spx_coord_exp -
master_spx_coord);
@@ -897,10 +897,10 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
}
/* coupling strategy */
- if (s->eac3 ? s->cpl_strategy_exists[blk] : get_bits1(gbc)) {
+ if (s->eac3 ? s->cpl_strategy_exists[blk] : bitstream_read_bit(bc)) {
memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS);
if (!s->eac3)
- s->cpl_in_use[blk] = get_bits1(gbc);
+ s->cpl_in_use[blk] = bitstream_read_bit(bc);
if (s->cpl_in_use[blk]) {
/* coupling in use */
int cpl_start_subband, cpl_end_subband;
@@ -911,7 +911,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
}
/* check for enhanced coupling */
- if (s->eac3 && get_bits1(gbc)) {
+ if (s->eac3 && bitstream_read_bit(bc)) {
/* TODO: parse enhanced coupling strategy info */
avpriv_request_sample(s->avctx, "Enhanced coupling");
return AVERROR_PATCHWELCOME;
@@ -923,17 +923,17 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
s->channel_in_cpl[2] = 1;
} else {
for (ch = 1; ch <= fbw_channels; ch++)
- s->channel_in_cpl[ch] = get_bits1(gbc);
+ s->channel_in_cpl[ch] = bitstream_read_bit(bc);
}
/* phase flags in use */
if (channel_mode == AC3_CHMODE_STEREO)
- s->phase_flags_in_use = get_bits1(gbc);
+ s->phase_flags_in_use = bitstream_read_bit(bc);
/* coupling frequency range */
- cpl_start_subband = get_bits(gbc, 4);
+ cpl_start_subband = bitstream_read(bc, 4);
cpl_end_subband = s->spx_in_use ? (s->spx_src_start_freq - 37) /
12 :
- get_bits(gbc, 4) + 3;
+ bitstream_read(bc, 4) + 3;
if (cpl_start_subband >= cpl_end_subband) {
av_log(s->avctx, AV_LOG_ERROR, "invalid coupling range (%d >=
%d)\n",
cpl_start_subband, cpl_end_subband);
@@ -942,7 +942,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk)
s->start_freq[CPL_CH] = cpl_start_subband * 12 + 37;
s->end_freq[CPL_CH] = cpl_end_subband * 12 + 37;
- decode_band_structure(gbc, blk, s->eac3, 0, cpl_start_subband,
+ decode_band_structure(bc, blk, s->eac3, 0, cpl_start_subband,
cpl_end_subband,
ff_eac3_default_cpl_band_struct,
&s->num_cpl_bands, s->cpl_band_sizes);
@@ -972,14 +972,14 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
for (ch = 1; ch <= fbw_channels; ch++) {
if (s->channel_in_cpl[ch]) {
- if ((s->eac3 && s->first_cpl_coords[ch]) || get_bits1(gbc)) {
+ if ((s->eac3 && s->first_cpl_coords[ch]) ||
bitstream_read_bit(bc)) {
int master_cpl_coord, cpl_coord_exp, cpl_coord_mant;
s->first_cpl_coords[ch] = 0;
cpl_coords_exist = 1;
- master_cpl_coord = 3 * get_bits(gbc, 2);
+ master_cpl_coord = 3 * bitstream_read(bc, 2);
for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
- cpl_coord_exp = get_bits(gbc, 4);
- cpl_coord_mant = get_bits(gbc, 4);
+ cpl_coord_exp = bitstream_read(bc, 4);
+ cpl_coord_mant = bitstream_read(bc, 4);
if (cpl_coord_exp == 15)
s->cpl_coords[ch][bnd] = cpl_coord_mant << 22;
else
@@ -999,14 +999,14 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
/* phase flags */
if (channel_mode == AC3_CHMODE_STEREO && cpl_coords_exist) {
for (bnd = 0; bnd < s->num_cpl_bands; bnd++) {
- s->phase_flags[bnd] = s->phase_flags_in_use? get_bits1(gbc) :
0;
+ s->phase_flags[bnd] = s->phase_flags_in_use ?
bitstream_read_bit(bc) : 0;
}
}
}
/* stereo rematrixing strategy and band structure */
if (channel_mode == AC3_CHMODE_STEREO) {
- if ((s->eac3 && !blk) || get_bits1(gbc)) {
+ if ((s->eac3 && !blk) || bitstream_read_bit(bc)) {
s->num_rematrixing_bands = 4;
if (cpl_in_use && s->start_freq[CPL_CH] <= 61) {
s->num_rematrixing_bands -= 1 + (s->start_freq[CPL_CH] == 37);
@@ -1014,7 +1014,7 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
s->num_rematrixing_bands--;
}
for (bnd = 0; bnd < s->num_rematrixing_bands; bnd++)
- s->rematrixing_flags[bnd] = get_bits1(gbc);
+ s->rematrixing_flags[bnd] = bitstream_read_bit(bc);
} else if (!blk) {
av_log(s->avctx, AV_LOG_WARNING, "Warning: "
"new rematrixing strategy not present in block 0\n");
@@ -1025,7 +1025,7 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
/* exponent strategies for each channel */
for (ch = !cpl_in_use; ch <= s->channels; ch++) {
if (!s->eac3)
- s->exp_strategy[blk][ch] = get_bits(gbc, 2 - (ch == s->lfe_ch));
+ s->exp_strategy[blk][ch] = bitstream_read(bc, 2 - (ch ==
s->lfe_ch));
if (s->exp_strategy[blk][ch] != EXP_REUSE)
bit_alloc_stages[ch] = 3;
}
@@ -1041,7 +1041,7 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
else if (s->channel_uses_spx[ch])
s->end_freq[ch] = s->spx_src_start_freq;
else {
- int bandwidth_code = get_bits(gbc, 6);
+ int bandwidth_code = bitstream_read(bc, 6);
if (bandwidth_code > 60) {
av_log(s->avctx, AV_LOG_ERROR, "bandwidth code = %d >
60\n", bandwidth_code);
return AVERROR_INVALIDDATA;
@@ -1062,26 +1062,26 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
/* decode exponents for each channel */
for (ch = !cpl_in_use; ch <= s->channels; ch++) {
if (s->exp_strategy[blk][ch] != EXP_REUSE) {
- s->dexps[ch][0] = get_bits(gbc, 4) << !ch;
- if (decode_exponents(gbc, s->exp_strategy[blk][ch],
+ s->dexps[ch][0] = bitstream_read(bc, 4) << !ch;
+ if (decode_exponents(bc, s->exp_strategy[blk][ch],
s->num_exp_groups[ch], s->dexps[ch][0],
&s->dexps[ch][s->start_freq[ch]+!!ch])) {
av_log(s->avctx, AV_LOG_ERROR, "exponent out-of-range\n");
return AVERROR_INVALIDDATA;
}
if (ch != CPL_CH && ch != s->lfe_ch)
- skip_bits(gbc, 2); /* skip gainrng */
+ bitstream_skip(bc, 2); /* skip gainrng */
}
}
/* bit allocation information */
if (s->bit_allocation_syntax) {
- if (get_bits1(gbc)) {
- s->bit_alloc_params.slow_decay =
ff_ac3_slow_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift;
- s->bit_alloc_params.fast_decay =
ff_ac3_fast_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift;
- s->bit_alloc_params.slow_gain =
ff_ac3_slow_gain_tab[get_bits(gbc, 2)];
- s->bit_alloc_params.db_per_bit =
ff_ac3_db_per_bit_tab[get_bits(gbc, 2)];
- s->bit_alloc_params.floor = ff_ac3_floor_tab[get_bits(gbc, 3)];
+ if (bitstream_read_bit(bc)) {
+ s->bit_alloc_params.slow_decay =
ff_ac3_slow_decay_tab[bitstream_read(bc, 2)] >> s->bit_alloc_params.sr_shift;
+ s->bit_alloc_params.fast_decay =
ff_ac3_fast_decay_tab[bitstream_read(bc, 2)] >> s->bit_alloc_params.sr_shift;
+ s->bit_alloc_params.slow_gain =
ff_ac3_slow_gain_tab[bitstream_read(bc, 2)];
+ s->bit_alloc_params.db_per_bit =
ff_ac3_db_per_bit_tab[bitstream_read(bc, 2)];
+ s->bit_alloc_params.floor =
ff_ac3_floor_tab[bitstream_read(bc, 3)];
for (ch = !cpl_in_use; ch <= s->channels; ch++)
bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2);
} else if (!blk) {
@@ -1093,14 +1093,14 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
/* signal-to-noise ratio offsets and fast gains (signal-to-mask ratios) */
if (!s->eac3 || !blk) {
- if (s->snr_offset_strategy && get_bits1(gbc)) {
+ if (s->snr_offset_strategy && bitstream_read_bit(bc)) {
int snr = 0;
int csnr;
- csnr = (get_bits(gbc, 6) - 15) << 4;
+ csnr = (bitstream_read(bc, 6) - 15) << 4;
for (i = ch = !cpl_in_use; ch <= s->channels; ch++) {
/* snr offset */
if (ch == i || s->snr_offset_strategy == 2)
- snr = (csnr + get_bits(gbc, 4)) << 2;
+ snr = (csnr + bitstream_read(bc, 4)) << 2;
/* run at least last bit allocation stage if snr offset
changes */
if (blk && s->snr_offset[ch] != snr) {
bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 1);
@@ -1110,7 +1110,7 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
/* fast gain (normal AC-3 only) */
if (!s->eac3) {
int prev = s->fast_gain[ch];
- s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)];
+ s->fast_gain[ch] = ff_ac3_fast_gain_tab[bitstream_read(bc,
3)];
/* run last 2 bit allocation stages if fast gain changes */
if (blk && prev != s->fast_gain[ch])
bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2);
@@ -1123,10 +1123,10 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
}
/* fast gain (E-AC-3 only) */
- if (s->fast_gain_syntax && get_bits1(gbc)) {
+ if (s->fast_gain_syntax && bitstream_read_bit(bc)) {
for (ch = !cpl_in_use; ch <= s->channels; ch++) {
int prev = s->fast_gain[ch];
- s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)];
+ s->fast_gain[ch] = ff_ac3_fast_gain_tab[bitstream_read(bc, 3)];
/* run last 2 bit allocation stages if fast gain changes */
if (blk && prev != s->fast_gain[ch])
bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2);
@@ -1137,15 +1137,15 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
}
/* E-AC-3 to AC-3 converter SNR offset */
- if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && get_bits1(gbc)) {
- skip_bits(gbc, 10); // skip converter snr offset
+ if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT &&
bitstream_read_bit(bc)) {
+ bitstream_skip(bc, 10); // skip converter snr offset
}
/* coupling leak information */
if (cpl_in_use) {
- if (s->first_cpl_leak || get_bits1(gbc)) {
- int fl = get_bits(gbc, 3);
- int sl = get_bits(gbc, 3);
+ if (s->first_cpl_leak || bitstream_read_bit(bc)) {
+ int fl = bitstream_read(bc, 3);
+ int sl = bitstream_read(bc, 3);
/* run last 2 bit allocation stages for coupling channel if
coupling leak changes */
if (blk && (fl != s->bit_alloc_params.cpl_fast_leak ||
@@ -1163,10 +1163,10 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
}
/* delta bit allocation information */
- if (s->dba_syntax && get_bits1(gbc)) {
+ if (s->dba_syntax && bitstream_read_bit(bc)) {
/* delta bit allocation exists (strategy) */
for (ch = !cpl_in_use; ch <= fbw_channels; ch++) {
- s->dba_mode[ch] = get_bits(gbc, 2);
+ s->dba_mode[ch] = bitstream_read(bc, 2);
if (s->dba_mode[ch] == DBA_RESERVED) {
av_log(s->avctx, AV_LOG_ERROR, "delta bit allocation strategy
reserved\n");
return AVERROR_INVALIDDATA;
@@ -1176,11 +1176,11 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
/* channel delta offset, len and bit allocation */
for (ch = !cpl_in_use; ch <= fbw_channels; ch++) {
if (s->dba_mode[ch] == DBA_NEW) {
- s->dba_nsegs[ch] = get_bits(gbc, 3) + 1;
+ s->dba_nsegs[ch] = bitstream_read(bc, 3) + 1;
for (seg = 0; seg < s->dba_nsegs[ch]; seg++) {
- s->dba_offsets[ch][seg] = get_bits(gbc, 5);
- s->dba_lengths[ch][seg] = get_bits(gbc, 4);
- s->dba_values[ch][seg] = get_bits(gbc, 3);
+ s->dba_offsets[ch][seg] = bitstream_read(bc, 5);
+ s->dba_lengths[ch][seg] = bitstream_read(bc, 4);
+ s->dba_values[ch][seg] = bitstream_read(bc, 3);
}
/* run last 2 bit allocation stages if new dba values */
bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2);
@@ -1226,10 +1226,10 @@ static int decode_audio_block(AC3DecodeContext *s, int
blk)
}
/* unused dummy data */
- if (s->skip_syntax && get_bits1(gbc)) {
- int skipl = get_bits(gbc, 9);
+ if (s->skip_syntax && bitstream_read_bit(bc)) {
+ int skipl = bitstream_read(bc, 9);
while (skipl--)
- skip_bits(gbc, 8);
+ bitstream_skip(bc, 8);
}
/* unpack the transform coefficients
@@ -1323,8 +1323,8 @@ static int ac3_decode_frame(AVCodecContext * avctx, void
*data,
} else
memcpy(s->input_buffer, buf, FFMIN(buf_size, AC3_FRAME_BUFFER_SIZE));
buf = s->input_buffer;
- /* initialize the GetBitContext with the start of valid AC-3 Frame */
- init_get_bits(&s->gbc, buf, buf_size * 8);
+ /* initialize the BitstreamContext with the start of a valid AC-3 Frame */
+ bitstream_init(&s->bc, buf, buf_size * 8);
/* parse the syncinfo */
err = parse_frame_header(s);
diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h
index 4c5359c..1c4db87 100644
--- a/libavcodec/ac3dec.h
+++ b/libavcodec/ac3dec.h
@@ -52,10 +52,11 @@
#include "libavutil/float_dsp.h"
#include "libavutil/lfg.h"
+
#include "ac3.h"
#include "ac3dsp.h"
+#include "bitstream.h"
#include "bswapdsp.h"
-#include "get_bits.h"
#include "fft.h"
#include "fmtconvert.h"
@@ -69,7 +70,7 @@
typedef struct AC3DecodeContext {
AVClass *class; ///< class for AVOptions
AVCodecContext *avctx; ///< parent context
- GetBitContext gbc; ///< bitstream reader
+ BitstreamContext bc; ///< bitstream reader
///@name Bit stream information
///@{
diff --git a/libavcodec/eac3dec.c b/libavcodec/eac3dec.c
index fe52d27..d23eee6 100644
--- a/libavcodec/eac3dec.c
+++ b/libavcodec/eac3dec.c
@@ -199,10 +199,10 @@ void
ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
{
int bin, blk, gs;
int end_bap, gaq_mode;
- GetBitContext *gbc = &s->gbc;
+ BitstreamContext *bc = &s->bc;
int gaq_gain[AC3_MAX_COEFS];
- gaq_mode = get_bits(gbc, 2);
+ gaq_mode = bitstream_read(bc, 2);
end_bap = (gaq_mode < 2) ? 12 : 17;
/* if GAQ gain is used, decode gain codes for bins with hebap between
@@ -212,7 +212,7 @@ void
ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
/* read 1-bit GAQ gain codes */
for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
- gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1);
+ gaq_gain[gs++] = bitstream_read_bit(bc) << (gaq_mode - 1);
}
} else if (gaq_mode == EAC3_GAQ_124) {
/* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
@@ -220,7 +220,7 @@ void
ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
if (gc++ == 2) {
- int group_code = get_bits(gbc, 5);
+ int group_code = bitstream_read(bc, 5);
if (group_code > 26) {
av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code
out-of-range\n");
group_code = 26;
@@ -245,7 +245,7 @@ void
ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
}
} else if (hebap < 8) {
/* Vector Quantization */
- int v = get_bits(gbc, bits);
+ int v = bitstream_read(bc, bits);
for (blk = 0; blk < 6; blk++) {
s->pre_mantissa[ch][bin][blk] =
ff_eac3_mantissa_vq[hebap][v][blk] << 8;
}
@@ -260,12 +260,12 @@ void
ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
gbits = bits - log_gain;
for (blk = 0; blk < 6; blk++) {
- int mant = get_sbits(gbc, gbits);
+ int mant = bitstream_read_signed(bc, gbits);
if (log_gain && mant == -(1 << (gbits-1))) {
/* large mantissa */
int b;
int mbits = bits - (2 - log_gain);
- mant = get_sbits(gbc, mbits);
+ mant = bitstream_read_signed(bc, mbits);
mant <<= (23 - (mbits - 1));
/* remap mantissa value to correct for asymmetric
quantization */
if (mant >= 0)
@@ -294,7 +294,7 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
int parse_transient_proc_info;
int num_cpl_blocks;
- GetBitContext *gbc = &s->gbc;
+ BitstreamContext *bc = &s->bc;
/* An E-AC-3 stream can have multiple independent streams which the
application can select from. each independent stream can also contain
@@ -330,108 +330,105 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
avpriv_request_sample(s->avctx, "Reduced sampling rate");
return AVERROR_PATCHWELCOME;
}
- skip_bits(gbc, 5); // skip bitstream id
+ bitstream_skip(bc, 5); // skip bitstream id
/* volume control params */
for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
- skip_bits(gbc, 5); // skip dialog normalization
- if (get_bits1(gbc)) {
- skip_bits(gbc, 8); // skip compression gain word
- }
+ bitstream_skip(bc, 5); // skip dialog normalization
+ if (bitstream_read_bit(bc))
+ bitstream_skip(bc, 8); // skip compression gain word
}
/* dependent stream channel map */
if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) {
- if (get_bits1(gbc)) {
- skip_bits(gbc, 16); // skip custom channel map
- }
+ if (bitstream_read_bit(bc))
+ bitstream_skip(bc, 16); // skip custom channel map
}
/* mixing metadata */
- if (get_bits1(gbc)) {
+ if (bitstream_read_bit(bc)) {
/* center and surround mix levels */
if (s->channel_mode > AC3_CHMODE_STEREO) {
- s->preferred_downmix = get_bits(gbc, 2);
+ s->preferred_downmix = bitstream_read(bc, 2);
if (s->channel_mode & 1) {
/* if three front channels exist */
- s->center_mix_level_ltrt = get_bits(gbc, 3);
- s->center_mix_level = get_bits(gbc, 3);
+ s->center_mix_level_ltrt = bitstream_read(bc, 3);
+ s->center_mix_level = bitstream_read(bc, 3);
}
if (s->channel_mode & 4) {
/* if a surround channel exists */
- s->surround_mix_level_ltrt = av_clip(get_bits(gbc, 3), 3, 7);
- s->surround_mix_level = av_clip(get_bits(gbc, 3), 3, 7);
+ s->surround_mix_level_ltrt = av_clip(bitstream_read(bc, 3), 3,
7);
+ s->surround_mix_level = av_clip(bitstream_read(bc, 3), 3,
7);
}
}
/* lfe mix level */
- if (s->lfe_on && (s->lfe_mix_level_exists = get_bits1(gbc))) {
- s->lfe_mix_level = get_bits(gbc, 5);
- }
+ if (s->lfe_on && (s->lfe_mix_level_exists = bitstream_read_bit(bc)))
+ s->lfe_mix_level = bitstream_read(bc, 5);
/* info for mixing with other streams and substreams */
if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT) {
for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
// TODO: apply program scale factor
- if (get_bits1(gbc)) {
- skip_bits(gbc, 6); // skip program scale factor
- }
- }
- if (get_bits1(gbc)) {
- skip_bits(gbc, 6); // skip external program scale factor
+ if (bitstream_read_bit(bc))
+ bitstream_skip(bc, 6); // skip program scale factor
}
+ if (bitstream_read_bit(bc))
+ bitstream_skip(bc, 6); // skip external program scale factor
/* skip mixing parameter data */
- switch(get_bits(gbc, 2)) {
- case 1: skip_bits(gbc, 5); break;
- case 2: skip_bits(gbc, 12); break;
- case 3: {
- int mix_data_size = (get_bits(gbc, 5) + 2) << 3;
- skip_bits_long(gbc, mix_data_size);
- break;
- }
+ switch (bitstream_read(bc, 2)) {
+ case 1:
+ bitstream_skip(bc, 5);
+ break;
+ case 2:
+ bitstream_skip(bc, 12);
+ break;
+ case 3:
+ {
+ int mix_data_size = (bitstream_read(bc, 5) + 2) << 3;
+ bitstream_skip(bc, mix_data_size);
+ break;
+ }
}
/* skip pan information for mono or dual mono source */
if (s->channel_mode < AC3_CHMODE_STEREO) {
for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
- if (get_bits1(gbc)) {
+ if (bitstream_read_bit(bc)) {
/* note: this is not in the ATSC A/52B specification
reference: ETSI TS 102 366 V1.1.1
section: E.1.3.1.25 */
- skip_bits(gbc, 8); // skip pan mean direction index
- skip_bits(gbc, 6); // skip reserved paninfo bits
+ bitstream_skip(bc, 8); // skip pan mean direction
index
+ bitstream_skip(bc, 6); // skip reserved paninfo bits
}
}
}
/* skip mixing configuration information */
- if (get_bits1(gbc)) {
+ if (bitstream_read_bit(bc)) {
for (blk = 0; blk < s->num_blocks; blk++) {
- if (s->num_blocks == 1 || get_bits1(gbc)) {
- skip_bits(gbc, 5);
- }
+ if (s->num_blocks == 1 || bitstream_read_bit(bc))
+ bitstream_skip(bc, 5);
}
}
}
}
/* informational metadata */
- if (get_bits1(gbc)) {
- s->bitstream_mode = get_bits(gbc, 3);
- skip_bits(gbc, 2); // skip copyright bit and original bitstream bit
+ if (bitstream_read_bit(bc)) {
+ s->bitstream_mode = bitstream_read(bc, 3);
+ bitstream_skip(bc, 2); // skip copyright bit and original bitstream bit
if (s->channel_mode == AC3_CHMODE_STEREO) {
- s->dolby_surround_mode = get_bits(gbc, 2);
- s->dolby_headphone_mode = get_bits(gbc, 2);
+ s->dolby_surround_mode = bitstream_read(bc, 2);
+ s->dolby_headphone_mode = bitstream_read(bc, 2);
}
if (s->channel_mode >= AC3_CHMODE_2F2R) {
- s->dolby_surround_ex_mode = get_bits(gbc, 2);
+ s->dolby_surround_ex_mode = bitstream_read(bc, 2);
}
for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
- if (get_bits1(gbc)) {
- skip_bits(gbc, 8); // skip mix level, room type, and A/D
converter type
- }
- }
- if (s->bit_alloc_params.sr_code != EAC3_SR_CODE_REDUCED) {
- skip_bits1(gbc); // skip source sample rate code
+ if (bitstream_read_bit(bc))
+ bitstream_skip(bc, 8); // skip mix level, room type, and A/D
converter type
}
+ if (s->bit_alloc_params.sr_code != EAC3_SR_CODE_REDUCED)
+ bitstream_skip(bc, 1); // skip source sample rate code
}
/* converter synchronization flag
@@ -439,28 +436,27 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
once every 6 blocks to indicate the start of a frame set.
reference: RFC 4598, Section 2.1.3 Frame Sets */
if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && s->num_blocks != 6) {
- skip_bits1(gbc); // skip converter synchronization flag
+ bitstream_skip(bc, 1); // skip converter synchronization flag
}
/* original frame size code if this stream was converted from AC-3 */
if (s->frame_type == EAC3_FRAME_TYPE_AC3_CONVERT &&
- (s->num_blocks == 6 || get_bits1(gbc))) {
- skip_bits(gbc, 6); // skip frame size code
- }
+ (s->num_blocks == 6 || bitstream_read_bit(bc)))
+ bitstream_skip(bc, 6); // skip frame size code
/* additional bitstream info */
- if (get_bits1(gbc)) {
- int addbsil = get_bits(gbc, 6);
+ if (bitstream_read_bit(bc)) {
+ int addbsil = bitstream_read(bc, 6);
for (i = 0; i < addbsil + 1; i++) {
- skip_bits(gbc, 8); // skip additional bit stream info
+ bitstream_skip(bc, 8); // skip additional bit stream info
}
}
/* audio frame syntax flags, strategy data, and per-frame data */
if (s->num_blocks == 6) {
- ac3_exponent_strategy = get_bits1(gbc);
- parse_aht_info = get_bits1(gbc);
+ ac3_exponent_strategy = bitstream_read_bit(bc);
+ parse_aht_info = bitstream_read_bit(bc);
} else {
/* less than 6 blocks, so use AC-3-style exponent strategy syntax, and
do not use AHT */
@@ -468,21 +464,21 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
parse_aht_info = 0;
}
- s->snr_offset_strategy = get_bits(gbc, 2);
- parse_transient_proc_info = get_bits1(gbc);
+ s->snr_offset_strategy = bitstream_read(bc, 2);
+ parse_transient_proc_info = bitstream_read_bit(bc);
- s->block_switch_syntax = get_bits1(gbc);
+ s->block_switch_syntax = bitstream_read_bit(bc);
if (!s->block_switch_syntax)
memset(s->block_switch, 0, sizeof(s->block_switch));
- s->dither_flag_syntax = get_bits1(gbc);
+ s->dither_flag_syntax = bitstream_read_bit(bc);
if (!s->dither_flag_syntax) {
for (ch = 1; ch <= s->fbw_channels; ch++)
s->dither_flag[ch] = 1;
}
s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
- s->bit_allocation_syntax = get_bits1(gbc);
+ s->bit_allocation_syntax = bitstream_read_bit(bc);
if (!s->bit_allocation_syntax) {
/* set default bit allocation parameters */
s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2];
@@ -492,18 +488,18 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
s->bit_alloc_params.floor = ff_ac3_floor_tab [7];
}
- s->fast_gain_syntax = get_bits1(gbc);
- s->dba_syntax = get_bits1(gbc);
- s->skip_syntax = get_bits1(gbc);
- parse_spx_atten_data = get_bits1(gbc);
+ s->fast_gain_syntax = bitstream_read_bit(bc);
+ s->dba_syntax = bitstream_read_bit(bc);
+ s->skip_syntax = bitstream_read_bit(bc);
+ parse_spx_atten_data = bitstream_read_bit(bc);
/* coupling strategy occurrence and coupling use per block */
num_cpl_blocks = 0;
if (s->channel_mode > 1) {
for (blk = 0; blk < s->num_blocks; blk++) {
- s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc));
+ s->cpl_strategy_exists[blk] = (!blk || bitstream_read_bit(bc));
if (s->cpl_strategy_exists[blk]) {
- s->cpl_in_use[blk] = get_bits1(gbc);
+ s->cpl_in_use[blk] = bitstream_read_bit(bc);
} else {
s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
}
@@ -518,13 +514,13 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
/* AC-3-style exponent strategy syntax */
for (blk = 0; blk < s->num_blocks; blk++) {
for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
- s->exp_strategy[blk][ch] = get_bits(gbc, 2);
+ s->exp_strategy[blk][ch] = bitstream_read(bc, 2);
}
}
} else {
/* LUT-based exponent strategy syntax */
for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <=
s->fbw_channels; ch++) {
- int frmchexpstr = get_bits(gbc, 5);
+ int frmchexpstr = bitstream_read(bc, 5);
for (blk = 0; blk < 6; blk++) {
s->exp_strategy[blk][ch] =
ff_eac3_frm_expstr[frmchexpstr][blk];
}
@@ -533,14 +529,13 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
/* LFE exponent strategy */
if (s->lfe_on) {
for (blk = 0; blk < s->num_blocks; blk++) {
- s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc);
+ s->exp_strategy[blk][s->lfe_ch] = bitstream_read_bit(bc);
}
}
/* original exponent strategies if this stream was converted from AC-3 */
if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT &&
- (s->num_blocks == 6 || get_bits1(gbc))) {
- skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel
exponent strategy
- }
+ (s->num_blocks == 6 || bitstream_read_bit(bc)))
+ bitstream_skip(bc, 5 * s->fbw_channels); // skip converter channel
exponent strategy
/* determine which channels use AHT */
if (parse_aht_info) {
@@ -558,7 +553,7 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
break;
}
}
- s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
+ s->channel_uses_aht[ch] = use_aht && bitstream_read_bit(bc);
}
} else {
memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
@@ -566,8 +561,8 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
/* per-frame SNR offset */
if (!s->snr_offset_strategy) {
- int csnroffst = (get_bits(gbc, 6) - 15) << 4;
- int snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
+ int csnroffst = (bitstream_read(bc, 6) - 15) << 4;
+ int snroffst = (csnroffst + bitstream_read(bc, 4)) << 2;
for (ch = 0; ch <= s->channels; ch++)
s->snr_offset[ch] = snroffst;
}
@@ -575,30 +570,30 @@ int ff_eac3_parse_header(AC3DecodeContext *s)
/* transient pre-noise processing data */
if (parse_transient_proc_info) {
for (ch = 1; ch <= s->fbw_channels; ch++) {
- if (get_bits1(gbc)) { // channel in transient processing
- skip_bits(gbc, 10); // skip transient processing location
- skip_bits(gbc, 8); // skip transient processing length
+ if (bitstream_read_bit(bc)) { // channel in transient processing
+ bitstream_skip(bc, 10); // skip transient processing location
+ bitstream_skip(bc, 8); // skip transient processing length
}
}
}
/* spectral extension attenuation data */
for (ch = 1; ch <= s->fbw_channels; ch++) {
- if (parse_spx_atten_data && get_bits1(gbc)) {
- s->spx_atten_code[ch] = get_bits(gbc, 5);
+ if (parse_spx_atten_data && bitstream_read_bit(bc)) {
+ s->spx_atten_code[ch] = bitstream_read(bc, 5);
} else {
s->spx_atten_code[ch] = -1;
}
}
/* block start information */
- if (s->num_blocks > 1 && get_bits1(gbc)) {
+ if (s->num_blocks > 1 && bitstream_read_bit(bc)) {
/* reference: Section E2.3.2.27
nblkstrtbits = (numblks - 1) * (4 + ceiling(log2(words_per_frame)))
The spec does not say what this data is or what it's used for.
It is likely the offset of each block within the frame. */
int block_start_bits = (s->num_blocks-1) * (4 +
av_log2(s->frame_size-2));
- skip_bits_long(gbc, block_start_bits);
+ bitstream_skip(bc, block_start_bits);
avpriv_request_sample(s->avctx, "Block start info");
}
diff --git a/libavformat/ac3dec.c b/libavformat/ac3dec.c
index 4ceffa5..0089db1 100644
--- a/libavformat/ac3dec.c
+++ b/libavformat/ac3dec.c
@@ -29,7 +29,7 @@ static int ac3_eac3_probe(AVProbeData *p, enum AVCodecID
expected_codec_id)
int max_frames, first_frames = 0, frames;
uint8_t *buf, *buf2, *end;
AC3HeaderInfo hdr;
- GetBitContext gbc;
+ BitstreamContext bc;
enum AVCodecID codec_id = AV_CODEC_ID_AC3;
max_frames = 0;
@@ -40,8 +40,8 @@ static int ac3_eac3_probe(AVProbeData *p, enum AVCodecID
expected_codec_id)
buf2 = buf;
for(frames = 0; buf2 < end; frames++) {
- init_get_bits(&gbc, buf2, 54);
- if(avpriv_ac3_parse_header(&gbc, &hdr) < 0)
+ bitstream_init(&bc, buf2, 54);
+ if (avpriv_ac3_parse_header(&bc, &hdr) < 0)
break;
if(buf2 + hdr.frame_size > end ||
av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2,
hdr.frame_size - 2))
--
2.7.3
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel