From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTP id 835DB42F22
	for <ffmpegdev@gitmailbox.com>; Thu, 13 Jan 2022 02:42:53 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 47D8768B8F3;
	Thu, 13 Jan 2022 04:06:01 +0200 (EET)
Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com
 [209.85.219.53])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9903668B8D4
 for <ffmpeg-devel@ffmpeg.org>; Thu, 13 Jan 2022 04:05:58 +0200 (EET)
Received: by mail-qv1-f53.google.com with SMTP id q4so5110846qvh.9
 for <ffmpeg-devel@ffmpeg.org>; Wed, 12 Jan 2022 18:05:58 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
 h=from:to:subject:date:message-id:in-reply-to:references:mime-version
 :content-transfer-encoding;
 bh=0gKd//vzdEQ5IC8jNAqiJhEz5/WHYbDwn6RwiHmOUhA=;
 b=nk7mXSEX1i7Ny3IN9NGyHvjSMZrCtWA2U1HPB4NswhyIpqoXvHWOIYQxKgtNS5d1/V
 5i6PIvB1tkMijUmZBJI4EqjMJkfEqgWPuU2qH0zxbfNHRBiaRj6WOhW1R3gqZYc+wYjd
 Ldu0ge8ANp9FsvXLd64v97EwBJMnaj9NO3asfrZ1Nq9CADjOIBMeL2jkIoxDi5SjBbHS
 ZQKNUQCucPGpgxwo24ozkKVDXPrjRqRudKzKpbZyb71guAkbFETbskDnAvH5lLwo40AL
 sA+3oLjUEGQ5MOKKcArdOcTeTSIXGfG2zyAJCRqcuLGb/oDAi0uPRdBP5d7FHsLXJTIT
 tioA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
 :references:mime-version:content-transfer-encoding;
 bh=0gKd//vzdEQ5IC8jNAqiJhEz5/WHYbDwn6RwiHmOUhA=;
 b=QCWBGj/0eOuayQf4lw3aIsskN9F/xg+PQgubZ5afEIkceGfWuqYEojyodXn0yekacB
 UsBAOFWGSyhp6Nspo69O1/0q26FouWuWSWwQ0hnswg+EHyhthKZAblsZU5Yy95Y4vd8f
 M67Cow0/BReK5aJ6gmJDZ/PALzozbhUlSgJ5kRVcbOhmFuioiKUP3h1jQHJJZ8At1qNd
 T4Br73YYsdyB3jRWAy9XRtZo3pZhqC5szhHM8JP7mq+AlaWfcNh31ZvZsCYcl9ptL85j
 zPG27gWxppmmxdnSxByarZ7rQTUuqc9m4jIXJdIAESBQ/VlH9PTJSLKJwwRJeH0Y0hi0
 lXAw==
X-Gm-Message-State: AOAM531AZkYAW9RRbAhpk2MmxTQhgOfc4I3xvMUVforp0jPho+29imsy
 krZHy+fPXML9wUhFvZH9SqvoWBxs5X0=
X-Google-Smtp-Source: ABdhPJwk3qBZ+obO3gSK9OcrI3XjiV+7XyusTpsHqdd6G9N7xxhYD+25VSUIkrGUjnfFOypnShLsjw==
X-Received: by 2002:ad4:574f:: with SMTP id q15mr2363893qvx.94.1642039557143; 
 Wed, 12 Jan 2022 18:05:57 -0800 (PST)
Received: from localhost.localdomain ([186.136.131.95])
 by smtp.gmail.com with ESMTPSA id k9sm1264556qko.29.2022.01.12.18.05.56
 for <ffmpeg-devel@ffmpeg.org>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 12 Jan 2022 18:05:56 -0800 (PST)
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Date: Wed, 12 Jan 2022 23:05:10 -0300
Message-Id: <20220113020518.730-22-jamrial@gmail.com>
X-Mailer: git-send-email 2.34.1
In-Reply-To: <20220113015101.4-1-jamrial@gmail.com>
References: <20220113015101.4-1-jamrial@gmail.com>
MIME-Version: 1.0
Subject: [FFmpeg-devel] [PATCH 231/281] libspeexdec: convert to new channel
 layout API
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/20220113020518.730-22-jamrial@gmail.com/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

From: Anton Khirnov <anton@khirnov.net>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libspeexdec.c | 19 ++++++++++---------
 libavcodec/libspeexenc.c | 17 +++++++++--------
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/libavcodec/libspeexdec.c b/libavcodec/libspeexdec.c
index 6f032907fc..8029786b1f 100644
--- a/libavcodec/libspeexdec.c
+++ b/libavcodec/libspeexdec.c
@@ -42,7 +42,7 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
     LibSpeexContext *s = avctx->priv_data;
     const SpeexMode *mode;
     SpeexHeader *header = NULL;
-    int spx_mode;
+    int spx_mode, channels;
 
     if (avctx->extradata && avctx->extradata_size >= 80) {
         header = speex_packet_to_header(avctx->extradata,
@@ -68,7 +68,7 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
         spx_mode           = 0;
     } else if (header) {
         avctx->sample_rate = header->rate;
-        avctx->channels    = header->nb_channels;
+        channels           = header->nb_channels;
         spx_mode           = header->mode;
         speex_header_free(header);
     } else {
@@ -94,14 +94,15 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
     if (!avctx->sample_rate)
         avctx->sample_rate = 8000 << spx_mode;
 
-    if (avctx->channels < 1 || avctx->channels > 2) {
+    if (channels < 1 || channels > 2) {
         /* libspeex can handle mono or stereo if initialized as stereo */
         av_log(avctx, AV_LOG_ERROR, "Invalid channel count: %d.\n"
-                                    "Decoding as stereo.\n", avctx->channels);
-        avctx->channels = 2;
+                                    "Decoding as stereo.\n", channels);
+        channels = 2;
     }
-    avctx->channel_layout = avctx->channels == 2 ? AV_CH_LAYOUT_STEREO :
-                                                   AV_CH_LAYOUT_MONO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    avctx->ch_layout = channels == 2 ? (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO :
+                                       (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
     speex_bits_init(&s->bits);
     s->dec_state = speex_decoder_init(mode);
@@ -110,7 +111,7 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
         return -1;
     }
 
-    if (avctx->channels == 2) {
+    if (channels == 2) {
         SpeexCallback callback;
         callback.callback_id = SPEEX_INBAND_STEREO;
         callback.func = speex_std_stereo_request_handler;
@@ -163,7 +164,7 @@ static int libspeex_decode_frame(AVCodecContext *avctx, void *data,
         av_log(avctx, AV_LOG_ERROR, "Error decoding Speex frame.\n");
         return AVERROR_INVALIDDATA;
     }
-    if (avctx->channels == 2)
+    if (avctx->ch_layout.nb_channels == 2)
         speex_decode_stereo_int(output, s->frame_size, &s->stereo);
 
     *got_frame_ptr = 1;
diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c
index d095b41bee..058dafad39 100644
--- a/libavcodec/libspeexenc.c
+++ b/libavcodec/libspeexenc.c
@@ -28,8 +28,8 @@
  * order to control various encoding parameters.
  *
  * Channels
- *     Speex only supports mono or stereo, so avctx->channels must be set to
- *     1 or 2.
+ *     Speex only supports mono or stereo, so avctx->ch_layout.nb_channels must
+ *     be set to 1 or 2.
  *
  * Sample Rate / Encoding Mode
  *     Speex has 3 modes, each of which uses a specific sample rate.
@@ -114,7 +114,7 @@ static av_cold void print_enc_params(AVCodecContext *avctx,
 {
     const char *mode_str = "unknown";
 
-    av_log(avctx, AV_LOG_DEBUG, "channels: %d\n", avctx->channels);
+    av_log(avctx, AV_LOG_DEBUG, "channels: %d\n", avctx->ch_layout.nb_channels);
     switch (s->header.mode) {
     case SPEEX_MODEID_NB:  mode_str = "narrowband";     break;
     case SPEEX_MODEID_WB:  mode_str = "wideband";       break;
@@ -146,15 +146,16 @@ static av_cold void print_enc_params(AVCodecContext *avctx,
 static av_cold int encode_init(AVCodecContext *avctx)
 {
     LibSpeexEncContext *s = avctx->priv_data;
+    int channels = avctx->ch_layout.nb_channels;
     const SpeexMode *mode;
     uint8_t *header_data;
     int header_size;
     int32_t complexity;
 
     /* channels */
-    if (avctx->channels < 1 || avctx->channels > 2) {
+    if (channels < 1 || channels > 2) {
         av_log(avctx, AV_LOG_ERROR, "Invalid channels (%d). Only stereo and "
-               "mono are supported\n", avctx->channels);
+               "mono are supported\n", channels);
         return AVERROR(EINVAL);
     }
 
@@ -175,7 +176,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
         av_log(avctx, AV_LOG_ERROR, "Error initializing libspeex\n");
         return -1;
     }
-    speex_init_header(&s->header, avctx->sample_rate, avctx->channels, mode);
+    speex_init_header(&s->header, avctx->sample_rate, channels, mode);
 
     /* rate control method and parameters */
     if (avctx->flags & AV_CODEC_FLAG_QSCALE) {
@@ -210,7 +211,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
         }
         /* stereo side information adds about 800 bps to the base bitrate */
         /* TODO: this should be calculated exactly */
-        avctx->bit_rate = s->header.bitrate + (avctx->channels == 2 ? 800 : 0);
+        avctx->bit_rate = s->header.bitrate + (channels == 2 ? 800 : 0);
     }
 
     /* VAD is activated with VBR or can be turned on by itself */
@@ -275,7 +276,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
 
     if (samples) {
         /* encode Speex frame */
-        if (avctx->channels == 2)
+        if (avctx->ch_layout.nb_channels == 2)
             speex_encode_stereo_int(samples, s->header.frame_size, &s->bits);
         speex_encode_int(s->enc_state, samples, &s->bits);
         s->pkt_frame_count++;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".