X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fatrac3.c;h=0474268f465b1cc88959ece3b7a7e35996d4f3b4;hb=09031b4639667273354d6bcd1705d9f24fc9bdd4;hp=76e251ba1cc40c03f1da4f270584225245de3a60;hpb=327747de15be919f8060e12a2e82afa37500629f;p=ffmpeg diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index 76e251ba1cc..0474268f465 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -42,6 +42,7 @@ #include "fft.h" #include "fmtconvert.h" #include "get_bits.h" +#include "internal.h" #include "atrac.h" #include "atrac3data.h" @@ -85,12 +86,10 @@ typedef struct ChannelUnit { } ChannelUnit; typedef struct ATRAC3Context { - AVFrame frame; GetBitContext gb; //@{ /** stream data */ int coding_mode; - int sample_rate; ChannelUnit *units; //@} @@ -311,13 +310,13 @@ static int decode_spectrum(GetBitContext *gb, float *output) output[first] = mantissas[j] * scale_factor; } else { /* this subband was not coded, so zero the entire subband */ - memset(output + first, 0, subband_size * sizeof(float)); + memset(output + first, 0, subband_size * sizeof(*output)); } } /* clear the subbands that were not coded */ first = subband_tab[i]; - memset(output + first, 0, (SAMPLES_PER_FRAME - first) * sizeof(float)); + memset(output + first, 0, (SAMPLES_PER_FRAME - first) * sizeof(*output)); return num_subbands; } @@ -494,7 +493,7 @@ static void gain_compensate_and_overlap(float *input, float *prev, } /* Delay for the overlapping part. */ - memcpy(prev, &input[256], 256 * sizeof(float)); + memcpy(prev, &input[256], 256 * sizeof(*prev)); } /* @@ -517,7 +516,7 @@ static int add_tonal_components(float *spectrum, int num_components, 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; @@ -684,7 +683,7 @@ static int decode_channel_sound_unit(ATRAC3Context *q, GetBitContext *gb, if (band <= num_bands) imlt(q, &snd->spectrum[band * 256], snd->imdct_buf, band & 1); else - memset(snd->imdct_buf, 0, 512 * sizeof(float)); + memset(snd->imdct_buf, 0, 512 * sizeof(*snd->imdct_buf)); /* gain compensation and overlapping */ gain_compensate_and_overlap(snd->imdct_buf, @@ -742,7 +741,8 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf, 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)); + memmove(q->weighting_delay, &q->weighting_delay[2], + 4 * sizeof(*q->weighting_delay)); q->weighting_delay[4] = get_bits1(&q->gb); q->weighting_delay[5] = get_bits(&q->gb, 3); @@ -797,6 +797,7 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf, 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; @@ -810,8 +811,8 @@ static int atrac3_decode_frame(AVCodecContext *avctx, void *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) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } @@ -824,14 +825,13 @@ static int atrac3_decode_frame(AVCodecContext *avctx, void *data, 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; } @@ -868,9 +868,6 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) 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); @@ -915,6 +912,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) } else { av_log(NULL, AV_LOG_ERROR, "Unknown extradata size %d.\n", avctx->extradata_size); + return AVERROR(EINVAL); } /* Check the extradata */ @@ -950,8 +948,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) 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); @@ -982,15 +979,12 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) avpriv_float_dsp_init(&q->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); ff_fmt_convert_init(&q->fmt_conv, avctx); - q->units = av_mallocz(sizeof(ChannelUnit) * avctx->channels); + q->units = av_mallocz(sizeof(*q->units) * avctx->channels); if (!q->units) { atrac3_decode_close(avctx); return AVERROR(ENOMEM); } - avcodec_get_frame_defaults(&q->frame); - avctx->coded_frame = &q->frame; - return 0; }