diff mbox series

[FFmpeg-devel,235/281] mace: convert to new channel layout API

Message ID 20220113020518.730-26-jamrial@gmail.com
State Accepted
Commit c5ccc0bd9421e6aed3e341f49a57284132b80a86
Headers show
Series New channel layout API | expand

Commit Message

James Almer Jan. 13, 2022, 2:05 a.m. UTC
From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/mace.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/mace.c b/libavcodec/mace.c
index 506a0ddece..9ed4747ba9 100644
--- a/libavcodec/mace.c
+++ b/libavcodec/mace.c
@@ -226,7 +226,7 @@  static void chomp6(ChannelData *chd, int16_t *output, uint8_t val, int tab_idx)
 
 static av_cold int mace_decode_init(AVCodecContext * avctx)
 {
-    if (avctx->channels > 2 || avctx->channels < 1)
+    if (avctx->ch_layout.nb_channels > 2 || avctx->ch_layout.nb_channels < 1)
         return AVERROR(EINVAL);
     avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
 
@@ -239,31 +239,32 @@  static int mace_decode_frame(AVCodecContext *avctx, void *data,
     AVFrame *frame     = data;
     const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
+    int channels = avctx->ch_layout.nb_channels;
     int16_t **samples;
     MACEContext *ctx = avctx->priv_data;
     int i, j, k, l, ret;
     int is_mace3 = (avctx->codec_id == AV_CODEC_ID_MACE3);
 
-    if (buf_size % (avctx->channels << is_mace3)) {
+    if (buf_size % (channels << is_mace3)) {
         av_log(avctx, AV_LOG_ERROR, "buffer size %d is odd\n", buf_size);
-        buf_size -= buf_size % (avctx->channels << is_mace3);
+        buf_size -= buf_size % (channels << is_mace3);
         if (!buf_size)
             return AVERROR_INVALIDDATA;
     }
 
     /* get output buffer */
-    frame->nb_samples = 3 * (buf_size << (1 - is_mace3)) / avctx->channels;
+    frame->nb_samples = 3 * (buf_size << (1 - is_mace3)) / channels;
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
         return ret;
     samples = (int16_t **)frame->extended_data;
 
-    for(i = 0; i < avctx->channels; i++) {
+    for(i = 0; i < channels; i++) {
         int16_t *output = samples[i];
 
-        for (j=0; j < buf_size / (avctx->channels << is_mace3); j++)
+        for (j=0; j < buf_size / (channels << is_mace3); j++)
             for (k=0; k < (1 << is_mace3); k++) {
                 uint8_t pkt = buf[(i << is_mace3) +
-                                  (j*avctx->channels << is_mace3) + k];
+                                  (j * channels << is_mace3) + k];
 
                 uint8_t val[2][3] = {{pkt >> 5, (pkt >> 3) & 3, pkt & 7 },
                                      {pkt & 7 , (pkt >> 3) & 3, pkt >> 5}};