From 7e76f270819e5c5a11372bc0e6368b542586506c Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 18 Oct 2012 22:51:41 -0400 Subject: atrac3: remove unused ATRAC3Context field, bit_rate --- libavcodec/atrac3.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'libavcodec/atrac3.c') diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index 3a6d4e8..474fa76 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -90,7 +90,6 @@ typedef struct ATRAC3Context { //@{ /** stream data */ int coding_mode; - int bit_rate; int sample_rate; ChannelUnit *units; @@ -856,7 +855,6 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) /* Take data from the AVCodecContext (RM container). */ q->sample_rate = avctx->sample_rate; - q->bit_rate = avctx->bit_rate; if (avctx->channels <= 0 || avctx->channels > 2) { av_log(avctx, AV_LOG_ERROR, "Channel configuration error!\n"); -- cgit v1.1 From c51311b907e0397866748d6af14b160d96c4673b Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 18 Oct 2012 22:53:13 -0400 Subject: atrac3: move the 'frame_factor' field from ATRAC3Context to where it is used --- libavcodec/atrac3.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'libavcodec/atrac3.c') diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index 474fa76..21403d2 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -109,7 +109,6 @@ typedef struct ATRAC3Context { //@{ /** extradata */ int scrambled_stream; - int frame_factor; //@} FFTContext mdct_ctx; @@ -847,7 +846,7 @@ static int atrac3_decode_frame(AVCodecContext *avctx, void *data, static av_cold int atrac3_decode_init(AVCodecContext *avctx) { int i, ret; - int version, delay, samples_per_frame; + int version, delay, samples_per_frame, frame_factor; const uint8_t *edata_ptr = avctx->extradata; ATRAC3Context *q = avctx->priv_data; static VLC_TYPE atrac3_vlc_table[4096][2]; @@ -870,7 +869,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) q->coding_mode = bytestream_get_le16(&edata_ptr); av_log(avctx, AV_LOG_DEBUG,"[8-9] %d\n", bytestream_get_le16(&edata_ptr)); //Dupe of coding mode - q->frame_factor = bytestream_get_le16(&edata_ptr); // Unknown always 1 + frame_factor = bytestream_get_le16(&edata_ptr); // Unknown always 1 av_log(avctx, AV_LOG_DEBUG,"[12-13] %d\n", bytestream_get_le16(&edata_ptr)); // Unknown always 0 @@ -881,12 +880,12 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) q->coding_mode = q->coding_mode ? JOINT_STEREO : STEREO; q->scrambled_stream = 0; - if (avctx->block_align != 96 * avctx->channels * q->frame_factor && - avctx->block_align != 152 * avctx->channels * q->frame_factor && - avctx->block_align != 192 * avctx->channels * q->frame_factor) { + if (avctx->block_align != 96 * avctx->channels * frame_factor && + avctx->block_align != 152 * avctx->channels * frame_factor && + avctx->block_align != 192 * avctx->channels * frame_factor) { av_log(avctx, AV_LOG_ERROR, "Unknown frame/channel/frame_factor " "configuration %d/%d/%d\n", avctx->block_align, - avctx->channels, q->frame_factor); + avctx->channels, frame_factor); return AVERROR_INVALIDDATA; } } else if (avctx->extradata_size == 10) { -- cgit v1.1 From 78edce3f1973cf8d611e0408b8d3681038828cfc Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 18 Oct 2012 22:56:10 -0400 Subject: atrac3: separate window initialization from IMDCT initialization --- libavcodec/atrac3.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'libavcodec/atrac3.c') diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index 21403d2..69b42fd 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -174,7 +174,7 @@ static int decode_bytes(const uint8_t *input, uint8_t *out, int bytes) return off; } -static av_cold int init_atrac3_transforms(ATRAC3Context *q) +static av_cold void init_atrac3_window(void) { float enc_window[256]; int i; @@ -184,17 +184,12 @@ static av_cold int init_atrac3_transforms(ATRAC3Context *q) for (i = 0; i < 256; i++) enc_window[i] = (sin(((i + 0.5) / 256.0 - 0.5) * M_PI) + 1.0) * 0.5; - if (!mdct_window[0]) { - for (i = 0; i < 256; i++) { - mdct_window[i] = enc_window[i] / - (enc_window[ i] * enc_window[ i] + - enc_window[255 - i] * enc_window[255 - i]); - mdct_window[511 - i] = mdct_window[i]; - } + for (i = 0; i < 256; i++) { + mdct_window[i] = enc_window[i] / + (enc_window[ i] * enc_window[ i] + + enc_window[255 - i] * enc_window[255 - i]); + mdct_window[511 - i] = mdct_window[i]; } - - /* initialize the MDCT transform */ - return ff_mdct_init(&q->mdct_ctx, 9, 1, 1.0 / 32768); } static av_cold int atrac3_decode_close(AVCodecContext *avctx) @@ -956,12 +951,14 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; - if ((ret = init_atrac3_transforms(q))) { + /* initialize the MDCT transform */ + if ((ret = ff_mdct_init(&q->mdct_ctx, 9, 1, 1.0 / 32768)) < 0) { av_log(avctx, AV_LOG_ERROR, "Error initializing MDCT\n"); av_freep(&q->decoded_bytes_buffer); return ret; } + init_atrac3_window(); ff_atrac_generate_tables(); /* Generate gain tables */ -- cgit v1.1 From 5d1007f74dd496d54b932242004382f44e3b22b4 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 18 Oct 2012 23:04:03 -0400 Subject: atrac3: initialize static tables in AVCodec.init_static_data() --- libavcodec/atrac3.c | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) (limited to 'libavcodec/atrac3.c') diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index 69b42fd..9e0f273 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -117,6 +117,7 @@ typedef struct ATRAC3Context { } ATRAC3Context; static DECLARE_ALIGNED(32, float, mdct_window)[MDCT_SIZE]; +static VLC_TYPE atrac3_vlc_table[4096][2]; static VLC spectral_coeff_tab[7]; static float gain_tab1[16]; static float gain_tab2[31]; @@ -838,14 +839,37 @@ static int atrac3_decode_frame(AVCodecContext *avctx, void *data, return avctx->block_align; } +static void atrac3_init_static_data(AVCodec *codec) +{ + int i; + + init_atrac3_window(); + ff_atrac_generate_tables(); + + /* Initialize the VLC tables. */ + for (i = 0; i < 7; i++) { + spectral_coeff_tab[i].table = &atrac3_vlc_table[atrac3_vlc_offs[i]]; + spectral_coeff_tab[i].table_allocated = atrac3_vlc_offs[i + 1] - + atrac3_vlc_offs[i ]; + init_vlc(&spectral_coeff_tab[i], 9, huff_tab_sizes[i], + huff_bits[i], 1, 1, + huff_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); + } + + /* Generate gain tables */ + for (i = 0; i < 16; i++) + gain_tab1[i] = powf(2.0, (4 - i)); + + for (i = -15; i < 16; i++) + gain_tab2[i + 15] = powf(2.0, i * -0.125); +} + static av_cold int atrac3_decode_init(AVCodecContext *avctx) { int i, ret; int version, delay, samples_per_frame, frame_factor; const uint8_t *edata_ptr = avctx->extradata; ATRAC3Context *q = avctx->priv_data; - static VLC_TYPE atrac3_vlc_table[4096][2]; - static int vlcs_initialized = 0; /* Take data from the AVCodecContext (RM container). */ q->sample_rate = avctx->sample_rate; @@ -935,20 +959,6 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) if (q->decoded_bytes_buffer == NULL) return AVERROR(ENOMEM); - - /* Initialize the VLC tables. */ - if (!vlcs_initialized) { - for (i = 0; i < 7; i++) { - spectral_coeff_tab[i].table = &atrac3_vlc_table[atrac3_vlc_offs[i]]; - spectral_coeff_tab[i].table_allocated = atrac3_vlc_offs[i + 1] - - atrac3_vlc_offs[i ]; - init_vlc(&spectral_coeff_tab[i], 9, huff_tab_sizes[i], - huff_bits[i], 1, 1, - huff_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); - } - vlcs_initialized = 1; - } - avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; /* initialize the MDCT transform */ @@ -958,16 +968,6 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) return ret; } - init_atrac3_window(); - ff_atrac_generate_tables(); - - /* Generate gain tables */ - for (i = 0; i < 16; i++) - gain_tab1[i] = powf(2.0, (4 - i)); - - for (i = -15; i < 16; i++) - gain_tab2[i + 15] = powf(2.0, i * -0.125); - /* init the joint-stereo decoding data */ q->weighting_delay[0] = 0; q->weighting_delay[1] = 7; @@ -1003,6 +1003,7 @@ AVCodec ff_atrac3_decoder = { .id = AV_CODEC_ID_ATRAC3, .priv_data_size = sizeof(ATRAC3Context), .init = atrac3_decode_init, + .init_static_data = atrac3_init_static_data, .close = atrac3_decode_close, .decode = atrac3_decode_frame, .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_DR1, -- cgit v1.1