summaryrefslogtreecommitdiff
path: root/libavcodec/atrac3.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/atrac3.c')
-rw-r--r--libavcodec/atrac3.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c
index 1cb7b2bc4d..c2da6e2411 100644
--- a/libavcodec/atrac3.c
+++ b/libavcodec/atrac3.c
@@ -3,20 +3,20 @@
* Copyright (c) 2006-2008 Maxim Poliakovski
* Copyright (c) 2006-2008 Benjamin Larsson
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -38,6 +38,7 @@
#include "libavutil/attributes.h"
#include "libavutil/float_dsp.h"
+#include "libavutil/libm.h"
#include "avcodec.h"
#include "bytestream.h"
#include "fft.h"
@@ -123,7 +124,7 @@ static float gain_tab1[16];
static float gain_tab2[31];
-/*
+/**
* Regular 512 points IMDCT without overlapping, with the exception of the
* swapping of odd bands caused by the reverse spectra of the QMF.
*
@@ -205,7 +206,7 @@ static av_cold int atrac3_decode_close(AVCodecContext *avctx)
return 0;
}
-/*
+/**
* Mantissa decoding
*
* @param selector which table the output values are coded with
@@ -267,7 +268,7 @@ static void read_quant_spectral_coeffs(GetBitContext *gb, int selector,
}
}
-/*
+/**
* Restore the quantized band spectrum coefficients
*
* @return subband count, fix for broken specification/files
@@ -324,7 +325,7 @@ static int decode_spectrum(GetBitContext *gb, float *output)
return num_subbands;
}
-/*
+/**
* Restore the quantized tonal components
*
* @param components tonal components
@@ -408,7 +409,7 @@ static int decode_tonal_components(GetBitContext *gb,
return component_count;
}
-/*
+/**
* Decode gain parameters for the coded bands
*
* @param block the gainblock for the current band
@@ -443,7 +444,7 @@ static int decode_gain_control(GetBitContext *gb, GainBlock *block,
return 0;
}
-/*
+/**
* Apply gain parameters and perform the MDCT overlapping part
*
* @param input input buffer
@@ -500,7 +501,7 @@ static void gain_compensate_and_overlap(float *input, float *prev,
memcpy(prev, &input[256], 256 * sizeof(*prev));
}
-/*
+/**
* Combine the tonal band spectrum and regular band spectrum
*
* @param spectrum output spectrum buffer
@@ -586,7 +587,7 @@ static void reverse_matrixing(float *su1, float *su2, int *prev_code,
}
break;
default:
- assert(0);
+ av_assert1(0);
}
}
}
@@ -627,7 +628,7 @@ static void channel_weighting(float *su1, float *su2, int *p3)
}
}
-/*
+/**
* Decode a Sound Unit
*
* @param snd the channel unit to be used
@@ -742,7 +743,7 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf,
/* set the bitstream reader at the start of the second Sound Unit*/
- init_get_bits(&q->gb, ptr1, (avctx->block_align - i) * 8);
+ init_get_bits8(&q->gb, ptr1, q->decoded_bytes_buffer + avctx->block_align - ptr1);
/* Fill the Weighting coeffs delay buffer */
memmove(q->weighting_delay, &q->weighting_delay[2],
@@ -816,10 +817,8 @@ static int atrac3_decode_frame(AVCodecContext *avctx, void *data,
/* get output buffer */
frame->nb_samples = SAMPLES_PER_FRAME;
- if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
return ret;
- }
/* Check if we need to descramble and what buffer to pass on. */
if (q->scrambled_stream) {
@@ -840,7 +839,7 @@ static int atrac3_decode_frame(AVCodecContext *avctx, void *data,
return avctx->block_align;
}
-static av_cold void atrac3_init_static_data(AVCodec *codec)
+static av_cold void atrac3_init_static_data(void)
{
int i;
@@ -859,14 +858,15 @@ static av_cold void atrac3_init_static_data(AVCodec *codec)
/* Generate gain tables */
for (i = 0; i < 16; i++)
- gain_tab1[i] = powf(2.0, (4 - i));
+ gain_tab1[i] = exp2f (4 - i);
for (i = -15; i < 16; i++)
- gain_tab2[i + 15] = powf(2.0, i * -0.125);
+ gain_tab2[i + 15] = exp2f (i * -0.125);
}
static av_cold int atrac3_decode_init(AVCodecContext *avctx)
{
+ static int static_init_done;
int i, ret;
int version, delay, samples_per_frame, frame_factor;
const uint8_t *edata_ptr = avctx->extradata;
@@ -877,6 +877,10 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
+ if (!static_init_done)
+ atrac3_init_static_data();
+ static_init_done = 1;
+
/* Take care of the codec-specific extradata. */
if (avctx->extradata_size == 14) {
/* Parse the extradata, WAV format */
@@ -905,7 +909,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
avctx->channels, frame_factor);
return AVERROR_INVALIDDATA;
}
- } else if (avctx->extradata_size == 10) {
+ } else if (avctx->extradata_size == 12 || avctx->extradata_size == 10) {
/* Parse the extradata, RM format. */
version = bytestream_get_be32(&edata_ptr);
samples_per_frame = bytestream_get_be16(&edata_ptr);
@@ -942,8 +946,10 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
if (q->coding_mode == STEREO)
av_log(avctx, AV_LOG_DEBUG, "Normal stereo detected.\n");
else if (q->coding_mode == JOINT_STEREO) {
- if (avctx->channels != 2)
+ if (avctx->channels != 2) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid coding mode\n");
return AVERROR_INVALIDDATA;
+ }
av_log(avctx, AV_LOG_DEBUG, "Joint stereo detected.\n");
} else {
av_log(avctx, AV_LOG_ERROR, "Unknown channel coding mode %x!\n",
@@ -1001,7 +1007,6 @@ 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,