#include <stddef.h>
#include <stdio.h>
+#include "libavutil/attributes.h"
#include "libavutil/float_dsp.h"
#include "avcodec.h"
#include "bytestream.h"
#include "fft.h"
#include "fmtconvert.h"
#include "get_bits.h"
+#include "internal.h"
#include "atrac.h"
#include "atrac3data.h"
} ChannelUnit;
typedef struct ATRAC3Context {
- AVFrame frame;
GetBitContext gb;
//@{
/** stream data */
int coding_mode;
- int sample_rate;
ChannelUnit *units;
//@}
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;
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 = avctx->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;
const uint8_t *edata_ptr = avctx->extradata;
ATRAC3Context *q = avctx->priv_data;
- /* Take data from the AVCodecContext (RM container). */
- q->sample_rate = avctx->sample_rate;
-
if (avctx->channels <= 0 || avctx->channels > 2) {
av_log(avctx, AV_LOG_ERROR, "Channel configuration error!\n");
return AVERROR(EINVAL);
} else {
av_log(NULL, AV_LOG_ERROR, "Unknown extradata size %d.\n",
avctx->extradata_size);
+ return AVERROR(EINVAL);
}
/* Check the extradata */
if (avctx->block_align >= UINT_MAX / 2)
return AVERROR(EINVAL);
- q->decoded_bytes_buffer = av_mallocz(avctx->block_align +
- (4 - avctx->block_align % 4) +
+ q->decoded_bytes_buffer = av_mallocz(FFALIGN(avctx->block_align, 4) +
FF_INPUT_BUFFER_PADDING_SIZE);
if (q->decoded_bytes_buffer == NULL)
return AVERROR(ENOMEM);
return AVERROR(ENOMEM);
}
- avcodec_get_frame_defaults(&q->frame);
- avctx->coded_frame = &q->frame;
-
return 0;
}