diff mbox series

[FFmpeg-devel,255/281] sbc: convert to new channel layout API

Message ID 20220113020713.801-16-jamrial@gmail.com
State Accepted
Commit b7483d02c246b1f5155eb156c98785830560a7b4
Headers show
Series New channel layout API | expand

Commit Message

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

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/sbc_parser.c |  8 ++++++--
 libavcodec/sbcdec.c     |  9 ++++++++-
 libavcodec/sbcenc.c     | 15 ++++++++++-----
 3 files changed, 24 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/sbc_parser.c b/libavcodec/sbc_parser.c
index 8bf726b39e..2d427cc7cb 100644
--- a/libavcodec/sbc_parser.c
+++ b/libavcodec/sbc_parser.c
@@ -41,7 +41,9 @@  static int sbc_parse_header(AVCodecParserContext *s, AVCodecContext *avctx,
         return -1;
 
     if (data[0] == MSBC_SYNCWORD && data[1] == 0 && data[2] == 0) {
-        avctx->channels = 1;
+        av_channel_layout_uninit(&avctx->ch_layout);
+        avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+        avctx->ch_layout.nb_channels = 1;
         avctx->sample_rate = 16000;
         avctx->frame_size = 120;
         s->duration = avctx->frame_size;
@@ -64,7 +66,9 @@  static int sbc_parse_header(AVCodecParserContext *s, AVCodecContext *avctx,
              + ((((mode == SBC_MODE_DUAL_CHANNEL) + 1) * blocks * bitpool
                  + (joint * subbands)) + 7) / 8;
 
-    avctx->channels = channels;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    avctx->ch_layout.nb_channels = channels;
     avctx->sample_rate = sample_rates[sr];
     avctx->frame_size = subbands * blocks;
     s->duration = avctx->frame_size;
diff --git a/libavcodec/sbcdec.c b/libavcodec/sbcdec.c
index e14d8c8958..1c053ad9a7 100644
--- a/libavcodec/sbcdec.c
+++ b/libavcodec/sbcdec.c
@@ -351,7 +351,9 @@  static int sbc_decode_frame(AVCodecContext *avctx,
     if (frame_length <= 0)
         return frame_length;
 
-    avctx->channels = sbc->frame.channels;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+    avctx->ch_layout.nb_channels = sbc->frame.channels;
 
     frame->nb_samples = sbc->frame.blocks * sbc->frame.subbands;
     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
@@ -374,8 +376,13 @@  const AVCodec ff_sbc_decoder = {
     .decode                = sbc_decode_frame,
     .capabilities          = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
     .caps_internal         = FF_CODEC_CAP_INIT_THREADSAFE,
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts       = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
                                                   AV_CH_LAYOUT_STEREO, 0},
+#endif
+    .ch_layouts            = (const AVChannelLayout[]) { AV_CHANNEL_LAYOUT_MONO,
+                                                         AV_CHANNEL_LAYOUT_STEREO,
+                                                         { 0 } },
     .sample_fmts           = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
                                                              AV_SAMPLE_FMT_NONE },
     .supported_samplerates = (const int[]) { 16000, 32000, 44100, 48000, 0 },
diff --git a/libavcodec/sbcenc.c b/libavcodec/sbcenc.c
index 45156277b7..cff93e8917 100644
--- a/libavcodec/sbcenc.c
+++ b/libavcodec/sbcenc.c
@@ -202,7 +202,7 @@  static int sbc_encode_init(AVCodecContext *avctx)
         sbc->msbc = 1;
 
     if (sbc->msbc) {
-        if (avctx->channels != 1) {
+        if (avctx->ch_layout.nb_channels != 1) {
             av_log(avctx, AV_LOG_ERROR, "mSBC require mono channel.\n");
             return AVERROR(EINVAL);
         }
@@ -227,7 +227,7 @@  static int sbc_encode_init(AVCodecContext *avctx)
             return AVERROR(EINVAL);
         }
 
-        if (avctx->channels == 1) {
+        if (avctx->ch_layout.nb_channels == 1) {
             frame->mode = SBC_MODE_MONO;
             if (sbc->max_delay <= 3000 || avctx->bit_rate > 270000)
                 frame->subbands = 4;
@@ -251,7 +251,7 @@  static int sbc_encode_init(AVCodecContext *avctx)
 
         d = frame->blocks * ((frame->mode == SBC_MODE_DUAL_CHANNEL) + 1);
         frame->bitpool = (((avctx->bit_rate * frame->subbands * frame->blocks) / avctx->sample_rate)
-                          - 4 * frame->subbands * avctx->channels
+                          - 4 * frame->subbands * avctx->ch_layout.nb_channels
                           - (frame->mode == SBC_MODE_JOINT_STEREO)*frame->subbands - 32 + d/2) / d;
         if (avctx->global_quality > 0)
             frame->bitpool = avctx->global_quality / FF_QP2LAMBDA;
@@ -263,8 +263,8 @@  static int sbc_encode_init(AVCodecContext *avctx)
         if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
             frame->frequency = i;
 
-    frame->channels = avctx->channels;
-    frame->codesize = frame->subbands * frame->blocks * avctx->channels * 2;
+    frame->channels = avctx->ch_layout.nb_channels;
+    frame->codesize = frame->subbands * frame->blocks * avctx->ch_layout.nb_channels * 2;
     frame->crc_ctx = av_crc_get_table(AV_CRC_8_EBU);
 
     memset(&sbc->dsp.X, 0, sizeof(sbc->dsp.X));
@@ -353,8 +353,13 @@  const AVCodec ff_sbc_encoder = {
     .init                  = sbc_encode_init,
     .encode2               = sbc_encode_frame,
     .caps_internal         = FF_CODEC_CAP_INIT_THREADSAFE,
+#if FF_API_OLD_CHANNEL_LAYOUT
     .channel_layouts       = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
                                                   AV_CH_LAYOUT_STEREO, 0},
+#endif
+    .ch_layouts            = (const AVChannelLayout[]) { AV_CHANNEL_LAYOUT_MONO,
+                                                         AV_CHANNEL_LAYOUT_STEREO,
+                                                         { 0 } },
     .sample_fmts           = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16,
                                                              AV_SAMPLE_FMT_NONE },
     .supported_samplerates = (const int[]) { 16000, 32000, 44100, 48000, 0 },