summaryrefslogtreecommitdiff
path: root/libavcodec/atrac3.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2012-10-18 22:45:48 -0400
committerJustin Ruggles <justin.ruggles@gmail.com>2012-10-22 10:10:07 -0400
commitcdd0e0de816d3667b5bd069ac05d1faf40153782 (patch)
treece8eeef53d6e85eca2d8782f2ff10ba59ddac474 /libavcodec/atrac3.c
parent64ebbb8f89d15dddf7c3318b6ef33c9288b2be15 (diff)
atrac3: use AVCodecContext.block_align instead of keeping a private copy
Diffstat (limited to 'libavcodec/atrac3.c')
-rw-r--r--libavcodec/atrac3.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c
index 0645ab1ac5..76f2b22070 100644
--- a/libavcodec/atrac3.c
+++ b/libavcodec/atrac3.c
@@ -95,8 +95,6 @@ typedef struct ATRAC3Context {
int samples_per_channel;
int samples_per_frame;
- int bits_per_frame;
- int bytes_per_frame;
ChannelUnit *units;
//@}
//@{
@@ -723,7 +721,7 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf,
if (q->coding_mode == JOINT_STEREO) {
/* channel coupling mode */
/* decode Sound Unit 1 */
- init_get_bits(&q->gb,databuf,q->bits_per_frame);
+ init_get_bits(&q->gb, databuf, avctx->block_align * 8);
ret = decode_channel_sound_unit(q, &q->gb, q->units, out_samples[0], 0,
JOINT_STEREO);
@@ -733,26 +731,26 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf,
/* Framedata of the su2 in the joint-stereo mode is encoded in
* reverse byte order so we need to swap it first. */
if (databuf == q->decoded_bytes_buffer) {
- uint8_t *ptr2 = q->decoded_bytes_buffer + q->bytes_per_frame - 1;
+ uint8_t *ptr2 = q->decoded_bytes_buffer + avctx->block_align - 1;
ptr1 = q->decoded_bytes_buffer;
- for (i = 0; i < q->bytes_per_frame / 2; i++, ptr1++, ptr2--)
+ for (i = 0; i < avctx->block_align / 2; i++, ptr1++, ptr2--)
FFSWAP(uint8_t, *ptr1, *ptr2);
} else {
- const uint8_t *ptr2 = databuf + q->bytes_per_frame - 1;
- for (i = 0; i < q->bytes_per_frame; i++)
+ const uint8_t *ptr2 = databuf + avctx->block_align - 1;
+ for (i = 0; i < avctx->block_align; i++)
q->decoded_bytes_buffer[i] = *ptr2--;
}
/* Skip the sync codes (0xF8). */
ptr1 = q->decoded_bytes_buffer;
for (i = 4; *ptr1 == 0xF8; i++, ptr1++) {
- if (i >= q->bytes_per_frame)
+ if (i >= avctx->block_align)
return AVERROR_INVALIDDATA;
}
/* set the bitstream reader at the start of the second Sound Unit*/
- init_get_bits(&q->gb, ptr1, q->bits_per_frame);
+ init_get_bits(&q->gb, ptr1, avctx->block_align * 8);
/* Fill the Weighting coeffs delay buffer */
memmove(q->weighting_delay, &q->weighting_delay[2], 4 * sizeof(int));
@@ -783,8 +781,8 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf,
for (i = 0; i < avctx->channels; i++) {
/* Set the bitstream reader at the start of a channel sound unit. */
init_get_bits(&q->gb,
- databuf + i * q->bytes_per_frame / avctx->channels,
- q->bits_per_frame / avctx->channels);
+ databuf + i * avctx->block_align / avctx->channels,
+ avctx->block_align * 8 / avctx->channels);
ret = decode_channel_sound_unit(q, &q->gb, &q->units[i],
out_samples[i], i, q->coding_mode);
@@ -861,8 +859,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;
- q->bits_per_frame = avctx->block_align * 8;
- q->bytes_per_frame = avctx->block_align;
if (avctx->channels <= 0 || avctx->channels > 2) {
av_log(avctx, AV_LOG_ERROR, "Channel configuration error!\n");
@@ -889,11 +885,11 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
q->coding_mode = q->coding_mode ? JOINT_STEREO : STEREO;
q->scrambled_stream = 0;
- if (q->bytes_per_frame != 96 * avctx->channels * q->frame_factor &&
- q->bytes_per_frame != 152 * avctx->channels * q->frame_factor &&
- q->bytes_per_frame != 192 * avctx->channels * q->frame_factor) {
+ 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) {
av_log(avctx, AV_LOG_ERROR, "Unknown frame/channel/frame_factor "
- "configuration %d/%d/%d\n", q->bytes_per_frame,
+ "configuration %d/%d/%d\n", avctx->block_align,
avctx->channels, q->frame_factor);
return AVERROR_INVALIDDATA;
}