From patchwork Sun Jan 19 14:20:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zane van Iperen X-Patchwork-Id: 17421 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 5268144AF9C for ; Sun, 19 Jan 2020 16:20:17 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2F1E268AE68; Sun, 19 Jan 2020 16:20:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail2.protonmail.ch (mail2.protonmail.ch [185.70.40.22]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1CD0268AE56 for ; Sun, 19 Jan 2020 16:20:10 +0200 (EET) Date: Sun, 19 Jan 2020 14:20:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zanevaniperen.com; s=protonmail; t=1579443609; bh=GoUVwqDPBOYHBiUOq2+tA7huDsijwD8o4QR8hs7RYK4=; h=Date:To:From:Cc:Reply-To:Subject:Feedback-ID:From; b=uN3svE+iB61szGz2/M7HmirFAjSoDh0bJ0JWVZCm34Vf0GtbZlI0o7hU6yJIhLcQN eMxyx6iUqHCkes2n03doPZ5ZRTB+Oo4rZVOF0weBsUhdBBJnypJCvwPloBjf1KOwNw L7wvai2b51gnLg9hHIuCQoBW7zu3z5+DfYb6hXlQ= To: ffmpeg-devel@ffmpeg.org From: Zane van Iperen Message-ID: <20200119141945.16889-1-zane@zanevaniperen.com> Feedback-ID: xylLYHwBzJW7F28tHN-oL9EBm6h5yqtCqG6YwPpJ2oMwBYJT6-HxTnFTF6p18axLiSywX61iUfj4CElBGg8-GA==:Ext:ProtonMail MIME-Version: 1.0 X-Spam-Status: No, score=0.3 required=7.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_RHS_DOB shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.protonmail.ch Subject: [FFmpeg-devel] [PATCH v2 3/4] avcodec/adpcm_argo: formatting fixes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Zane van Iperen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Zane van Iperen --- Changelog | 1 + libavcodec/adpcm_argo.c | 53 +++++++++++++++++++---------------------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/Changelog b/Changelog index bc1593bfd1..65ef01c77d 100644 --- a/Changelog +++ b/Changelog @@ -33,6 +33,7 @@ version : - Argonaut Games ADPCM decoder - Argonaut Games ASF demuxer + version 4.2: - tpad filter - AV1 decoding support through libdav1d diff --git a/libavcodec/adpcm_argo.c b/libavcodec/adpcm_argo.c index d5b32e62ba..e6ebaac911 100644 --- a/libavcodec/adpcm_argo.c +++ b/libavcodec/adpcm_argo.c @@ -62,8 +62,7 @@ typedef int16_t *(*ADPCMDecoder) ( * Decoder 1: (prev0 + (s << (c + 2))) */ static int16_t *adpcm_decoder_1(uint8_t c, int16_t *dst, const uint8_t *src, - const int16_t *prev_, - int nsamples, int stride) + const int16_t *prev_, int nsamples, int stride) { int16_t prev; int8_t s; @@ -74,12 +73,12 @@ static int16_t *adpcm_decoder_1(uint8_t c, int16_t *dst, const uint8_t *src, prev = prev_[stride]; c += 2; - for (int i = 0; i < nsamples / 2; ++i, ++src) { - s = (int8_t) ((*src & 0xF0u) << 0u); + for (int i = 0; i < nsamples / 2; i++, src++) { + s = (int8_t)((*src & 0xF0u) << 0u); *dst = prev = ((prev << 6) + (s << c)) >> 6; dst += stride; - s = (int8_t) ((*src & 0x0Fu) << 4u); + s = (int8_t)((*src & 0x0Fu) << 4u); *dst = prev = ((prev << 6) + (s << c)) >> 6; dst += stride; } @@ -90,9 +89,8 @@ static int16_t *adpcm_decoder_1(uint8_t c, int16_t *dst, const uint8_t *src, /* * Decoder 2: (2 * prev0) - (1 * prev1) + (s << (c + 2)) */ -static int16_t *adpcm_decoder_2(uint8_t c, int16_t * dst, const uint8_t * src, - const int16_t * prev_, - int nsamples, int stride) +static int16_t *adpcm_decoder_2(uint8_t c, int16_t *dst, const uint8_t *src, + const int16_t *prev_, int nsamples, int stride) { int16_t cprev[2]; int8_t s; @@ -105,17 +103,17 @@ static int16_t *adpcm_decoder_2(uint8_t c, int16_t * dst, const uint8_t * src, cprev[1] = prev_[0]; c += 2; - for (int i = 0; i < nsamples / 2; ++i, ++src) { + for (int i = 0; i < nsamples / 2; i++, src++) { /* NB: (x << 7) == 2*(x << 6) */ - s = (int8_t) ((*src & 0xF0u) << 0u); + s = (int8_t)((*src & 0xF0u) << 0u); *dst = ((cprev[0] << 7) - (cprev[1] << 6) + (s << c)) >> 6; cprev[1] = cprev[0]; cprev[0] = *dst; dst += stride; - s = (int8_t) ((*src & 0x0Fu) << 4u); + s = (int8_t)((*src & 0x0Fu) << 4u); *dst = ((cprev[0] << 7) - (cprev[1] << 6) + (s << c)) >> 6; cprev[1] = cprev[0]; cprev[0] = *dst; @@ -154,16 +152,15 @@ static ADPCMDecoder adpcm_decoders[2] = { adpcm_decoder_1, adpcm_decoder_2 }; * @param nchannels The number of channels. Must be 1 or 2. */ static int16_t *adpcm_decode_block(int16_t *dst, const uint8_t *src, - const int16_t *prev, - int nsamples, int nchannels) + const int16_t *prev, int nsamples, int nchannels) { - unsigned char c; + uint8_t c; av_assert0(nsamples > 2 && (nsamples & 0x1) == 0); av_assert0(nchannels == 1 || nchannels == 2); /* NB: nsamples/2 because samples are 4 bits, not 8. */ - for (int i = 0; i < nchannels; ++i, src += nsamples / 2) { + for (int i = 0; i < nchannels; i++, src += nsamples / 2) { /* Get the control byte and run the samples through the decoder. */ c = *src++; adpcm_decoders[!!(c & 0x04)] (c >> 4, dst + i, src, prev + i, nsamples, nchannels - 1); @@ -173,8 +170,8 @@ static int16_t *adpcm_decode_block(int16_t *dst, const uint8_t *src, } -#define MAX_CHANNELS (2) -#define PREVIOUS_SAMPLE_COUNT (2) +#define MAX_CHANNELS 2 +#define PREVIOUS_SAMPLE_COUNT 2 typedef struct ADPCMArgoDecoderContext { int16_t prev[MAX_CHANNELS * PREVIOUS_SAMPLE_COUNT]; @@ -186,26 +183,26 @@ static av_cold int adpcm_decode_init(AVCodecContext *avctx) if (avctx->channels > MAX_CHANNELS) { av_log(avctx, AV_LOG_ERROR, "Invalid channel count %d\n", avctx->channels); - return AVERROR(EINVAL); + return AVERROR_INVALIDDATA; } if (avctx->bits_per_coded_sample != 4) { av_log(avctx, AV_LOG_ERROR, "Invalid number of bits %d\n", avctx->bits_per_coded_sample); - return AVERROR(EINVAL); + return AVERROR_INVALIDDATA; } avctx->sample_fmt = AV_SAMPLE_FMT_S16; - for (int i = 0; i < MAX_CHANNELS * PREVIOUS_SAMPLE_COUNT; ++i) + for (int i = 0; i < MAX_CHANNELS * PREVIOUS_SAMPLE_COUNT; i++) ctx->prev[i] = 0; return 0; } -static int adpcm_decode_frame(AVCodecContext * avctx, void *data, - int *got_frame_ptr, AVPacket * avpkt) +static int adpcm_decode_frame(AVCodecContext *avctx, void *data, + int *got_frame_ptr, AVPacket *avpkt) { - int r; + int ret; AVFrame *frame = data; ADPCMArgoDecoderContext *argo = avctx->priv_data; int16_t *dst; @@ -214,7 +211,7 @@ static int adpcm_decode_frame(AVCodecContext * avctx, void *data, av_log(avctx, AV_LOG_WARNING, "unexpected mono packet size, expected 17, got %d\n", avpkt->size); - } else if(avctx->channels == 2 && avpkt->size != 34) { + } else if (avctx->channels == 2 && avpkt->size != 34) { av_log(avctx, AV_LOG_WARNING, "unexpected stereo packet size, expected 34, got %d\n", avpkt->size); @@ -224,14 +221,14 @@ static int adpcm_decode_frame(AVCodecContext * avctx, void *data, (8 / avctx->bits_per_coded_sample); /* get output buffer */ - if ((r = ff_get_buffer(avctx, frame, 0)) < 0) - return r; + if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) + return ret; - dst = adpcm_decode_block((int16_t *) frame->data[0], avpkt->data, argo->prev, frame->nb_samples, avctx->channels); + dst = adpcm_decode_block((int16_t*)frame->data[0], avpkt->data, argo->prev, frame->nb_samples, avctx->channels); /* Save the previous samples for the next frame. */ r = avctx->channels * PREVIOUS_SAMPLE_COUNT; - for (int i = 0; i < r; ++i) + for (int i = 0; i < r; i++) argo->prev[i] = *(dst - (r - i)); *got_frame_ptr = 1;