#include <stddef.h>
#include <stdio.h>
+#include "libavutil/attributes.h"
#include "libavutil/float_dsp.h"
#include "avcodec.h"
#include "bytestream.h"
} ChannelUnit;
typedef struct ATRAC3Context {
- AVFrame frame;
GetBitContext gb;
//@{
/** stream data */
off = (intptr_t)input & 3;
buf = (const uint32_t *)(input - off);
- c = av_be2ne32((0x537F6103 >> (off * 8)) | (0x537F6103 << (32 - (off * 8))));
+ if (off)
+ c = av_be2ne32((0x537F6103U >> (off * 8)) | (0x537F6103U << (32 - (off * 8))));
+ else
+ c = av_be2ne32(0x537F6103U);
bytes += 3 + off;
for (i = 0; i < bytes / 4; i++)
output[i] = c ^ buf[i];
if (off)
- av_log_ask_for_sample(NULL, "Offset of %d not handled.\n", off);
+ avpriv_request_sample(NULL, "Offset of %d", off);
return off;
}
output = &spectrum[components[i].pos];
for (j = 0; j < components[i].num_coefs; j++)
- output[i] += input[i];
+ output[j] += input[j];
}
return last_pos;
snd->num_components = decode_tonal_components(gb, snd->components,
snd->bands_coded);
- if (snd->num_components == -1)
- return -1;
+ if (snd->num_components < 0)
+ return snd->num_components;
num_subbands = decode_spectrum(gb, snd->spectrum);
/* set the bitstream reader at the start of the second Sound Unit*/
- init_get_bits(&q->gb, ptr1, avctx->block_align * 8);
+ init_get_bits(&q->gb, ptr1, (avctx->block_align - i) * 8);
/* Fill the Weighting coeffs delay buffer */
memmove(q->weighting_delay, &q->weighting_delay[2],
static int atrac3_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame_ptr, AVPacket *avpkt)
{
+ AVFrame *frame = data;
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
ATRAC3Context *q = avctx->priv_data;
}
/* get output buffer */
- q->frame.nb_samples = SAMPLES_PER_FRAME;
- if ((ret = ff_get_buffer(avctx, &q->frame)) < 0) {
+ 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");
return ret;
}
databuf = buf;
}
- ret = decode_frame(avctx, databuf, (float **)q->frame.extended_data);
+ ret = decode_frame(avctx, databuf, (float **)frame->extended_data);
if (ret) {
av_log(NULL, AV_LOG_ERROR, "Frame decoding error!\n");
return ret;
}
- *got_frame_ptr = 1;
- *(AVFrame *)data = q->frame;
+ *got_frame_ptr = 1;
return avctx->block_align;
}
-static void atrac3_init_static_data(AVCodec *codec)
+static av_cold void atrac3_init_static_data(AVCodec *codec)
{
int i;
if (q->coding_mode == STEREO)
av_log(avctx, AV_LOG_DEBUG, "Normal stereo detected.\n");
- else if (q->coding_mode == JOINT_STEREO)
+ else if (q->coding_mode == JOINT_STEREO) {
+ if (avctx->channels != 2)
+ return AVERROR_INVALIDDATA;
av_log(avctx, AV_LOG_DEBUG, "Joint stereo detected.\n");
- else {
+ } else {
av_log(avctx, AV_LOG_ERROR, "Unknown channel coding mode %x!\n",
q->coding_mode);
return AVERROR_INVALIDDATA;
return AVERROR(ENOMEM);
}
- avcodec_get_frame_defaults(&q->frame);
- avctx->coded_frame = &q->frame;
-
return 0;
}