diff mbox series

[FFmpeg-devel,v2,3/4] avcodec/adpcm_argo: formatting fixes

Message ID 20200119141945.16889-1-zane@zanevaniperen.com
State Accepted
Headers show
Series Argonaut Games ASF and ADPCM decoding support
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork fail Failed to apply patch

Commit Message

Zane van Iperen Jan. 19, 2020, 2:20 p.m. UTC
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
---
 Changelog               |  1 +
 libavcodec/adpcm_argo.c | 53 +++++++++++++++++++----------------------
 2 files changed, 26 insertions(+), 28 deletions(-)
diff mbox series

Patch

diff --git a/Changelog b/Changelog
index bc1593bfd1..65ef01c77d 100644
--- a/Changelog
+++ b/Changelog
@@ -33,6 +33,7 @@  version <next>:
 - 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;