X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fadpcm.c;h=c6bc4d09d710d68729c957e8ed7dc7ab6920af0c;hb=999d31d354f1f0616a09691913659ac0abdcc899;hp=b6a20e2c322012840c12d98c91081d787b6796b0;hpb=4ebd74cec75cb384c0297e9bffcab3ed06be6371;p=ffmpeg diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index b6a20e2c322..c6bc4d09d71 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -1,6 +1,18 @@ /* * Copyright (c) 2001-2003 The ffmpeg Project * + * first version by Francois Revol (revol@free.fr) + * fringe ADPCM codecs (e.g., DK3, DK4, Westwood) + * by Mike Melanson (melanson@pcisys.net) + * CD-ROM XA ADPCM codec by BERO + * EA ADPCM decoder by Robin Kay (komadori@myrealbox.com) + * EA ADPCM R1/R2/R3 decoder by Peter Ross (pross@xvid.org) + * EA IMA EACS decoder by Peter Ross (pross@xvid.org) + * EA IMA SEAD decoder by Peter Ross (pross@xvid.org) + * EA ADPCM XAS decoder by Peter Ross (pross@xvid.org) + * MAXIS EA ADPCM decoder by Robert Marston (rmarston@gmail.com) + * THP ADPCM decoder by Marco Gerards (mgerards@xs4all.nl) + * * This file is part of Libav. * * Libav is free software; you can redistribute it and/or @@ -23,22 +35,11 @@ #include "bytestream.h" #include "adpcm.h" #include "adpcm_data.h" +#include "internal.h" /** * @file * ADPCM decoders - * First version by Francois Revol (revol@free.fr) - * Fringe ADPCM codecs (e.g., DK3, DK4, Westwood) - * by Mike Melanson (melanson@pcisys.net) - * CD-ROM XA ADPCM codec by BERO - * EA ADPCM decoder by Robin Kay (komadori@myrealbox.com) - * EA ADPCM R1/R2/R3 decoder by Peter Ross (pross@xvid.org) - * EA IMA EACS decoder by Peter Ross (pross@xvid.org) - * EA IMA SEAD decoder by Peter Ross (pross@xvid.org) - * EA ADPCM XAS decoder by Peter Ross (pross@xvid.org) - * MAXIS EA ADPCM decoder by Robert Marston (rmarston@gmail.com) - * THP ADPCM decoder by Marco Gerards (mgerards@xs4all.nl) - * * Features and limitations: * * Reference documents: @@ -84,7 +85,6 @@ static const int swf_index_tables[4][16] = { /* end of tables */ typedef struct ADPCMDecodeContext { - AVFrame frame; ADPCMChannelStatus status[6]; int vqa_version; /**< VQA version. Used for ADPCM_IMA_WS */ } ADPCMDecodeContext; @@ -155,9 +155,6 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) avctx->sample_fmt = AV_SAMPLE_FMT_S16; } - avcodec_get_frame_defaults(&c->frame); - avctx->coded_frame = &c->frame; - return 0; } @@ -590,6 +587,7 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, static int adpcm_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; ADPCMDecodeContext *c = avctx->priv_data; @@ -610,20 +608,20 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } /* get output buffer */ - c->frame.nb_samples = nb_samples; - if ((ret = avctx->get_buffer(avctx, &c->frame)) < 0) { + frame->nb_samples = nb_samples; + if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } - samples = (short *)c->frame.data[0]; - samples_p = (int16_t **)c->frame.extended_data; + samples = (short *)frame->data[0]; + samples_p = (int16_t **)frame->extended_data; /* use coded_samples when applicable */ /* it is always <= nb_samples, so the output buffer will be large enough */ if (coded_samples) { if (coded_samples != nb_samples) av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n"); - c->frame.nb_samples = nb_samples = coded_samples; + frame->nb_samples = nb_samples = coded_samples; } st = avctx->channels == 2 ? 1 : 0; @@ -709,7 +707,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } for (i = 0; i < avctx->channels; i++) { - samples = (int16_t *)c->frame.data[i]; + samples = (int16_t *)frame->data[i]; cs = &c->status[i]; for (n = nb_samples >> 1; n > 0; n--) { int v = bytestream2_get_byteu(&gb); @@ -772,7 +770,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, return AVERROR_INVALIDDATA; } } - for (n = nb_samples >> (1 - st); n > 0; n--) { + for (n = (nb_samples >> (1 - st)) - 1; n > 0; n--) { int v = bytestream2_get_byteu(&gb); *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4 , 3); *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3); @@ -1096,7 +1094,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } } - c->frame.nb_samples = count * 28; + frame->nb_samples = count * 28; bytestream2_seek(&gb, 0, SEEK_END); break; } @@ -1277,8 +1275,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, return -1; } - *got_frame_ptr = 1; - *(AVFrame *)data = c->frame; + *got_frame_ptr = 1; return bytestream2_tell(&gb); } @@ -1295,13 +1292,13 @@ static const enum AVSampleFormat sample_fmts_both[] = { AV_SAMPLE_FMT_S16, #define ADPCM_DECODER(id_, sample_fmts_, name_, long_name_) \ AVCodec ff_ ## name_ ## _decoder = { \ .name = #name_, \ + .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ .type = AVMEDIA_TYPE_AUDIO, \ .id = id_, \ .priv_data_size = sizeof(ADPCMDecodeContext), \ .init = adpcm_decode_init, \ .decode = adpcm_decode_frame, \ .capabilities = CODEC_CAP_DR1, \ - .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ .sample_fmts = sample_fmts_, \ }