summaryrefslogtreecommitdiffstats
path: root/libavcodec/atrac3.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/atrac3.c')
-rw-r--r--libavcodec/atrac3.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c
index a46b0b1..1e54784 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
*/
@@ -37,6 +37,7 @@
#include <stdio.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.
*
@@ -202,7 +203,7 @@ static av_cold int atrac3_decode_close(AVCodecContext *avctx)
return 0;
}
-/*
+/**
* Mantissa decoding
*
* @param selector which table the output values are coded with
@@ -264,7 +265,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
@@ -321,7 +322,7 @@ static int decode_spectrum(GetBitContext *gb, float *output)
return num_subbands;
}
-/*
+/**
* Restore the quantized tonal components
*
* @param components tonal components
@@ -405,7 +406,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
@@ -440,7 +441,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
@@ -497,7 +498,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
@@ -583,7 +584,7 @@ static void reverse_matrixing(float *su1, float *su2, int *prev_code,
}
break;
default:
- assert(0);
+ av_assert1(0);
}
}
}
@@ -624,7 +625,7 @@ static void channel_weighting(float *su1, float *su2, int *p3)
}
}
-/*
+/**
* Decode a Sound Unit
*
* @param snd the channel unit to be used
@@ -739,7 +740,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 * 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],
@@ -837,7 +838,7 @@ static int atrac3_decode_frame(AVCodecContext *avctx, void *data,
return avctx->block_align;
}
-static void atrac3_init_static_data(AVCodec *codec)
+static void atrac3_init_static_data(void)
{
int i;
@@ -856,14 +857,15 @@ static 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;
@@ -874,6 +876,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 */
@@ -916,6 +922,11 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
+ if (q->coding_mode == JOINT_STEREO && avctx->channels < 2) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid coding mode\n");
+ return AVERROR_INVALIDDATA;
+ }
+
/* Check the extradata */
if (version != 4) {
@@ -998,7 +1009,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,
OpenPOWER on IntegriCloud