From patchwork Thu Jan 13 02:05:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33500 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp42180iog; Wed, 12 Jan 2022 18:42:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJxcrgeF0UYJuuTDoDgIpnOykK6sazBdfREhLXgbStfpmKjx0MvuQaWAGlcfhDaC/1XPcUYq X-Received: by 2002:a17:906:c14e:: with SMTP id dp14mr2049882ejc.138.1642041776432; Wed, 12 Jan 2022 18:42:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642041776; cv=none; d=google.com; s=arc-20160816; b=zGbBperasS28t7YLT/io/+LzmfEp3q1/SAvBOzw3TNMF62ywdYRV/iEyuKkpp+3ljm u5TrF7DZdpGuJSAcRP/oZTvm6q8GQvIfIwO2Xbg6SDFfgr5m9fJg8VwPMArLHGN1brW0 x+PhdT7PYwX4ZrI4m9wXEOqZqwRhw0KDMeZT9Vc7/bEKKU9fvOzSK0I8vtOCLwFVMaKE bSsk1j0T2wSU41QUuWGKTliQVeridITC2QrZ9CoN6V4Vifk3bdlWR0CWG0AfK/LHsyLa DEb/KnE0X472Y0dHSJolq/YTJvCH5hayod8qgYfgE626OFTtRf6BWnLI6CQJkH3m75H3 YR0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=EsoYGD2I25FpHc6oNWRDxHNmmRr61LQ+D2wUgOUFuPo=; b=WndoZ8z1P8UKdSBwrDCW/KGU0qu9RgLU4+Cmi5DtHV1imK+RhVr29kybqUwfR8PFhB xenLUuxwiP3JEXUx36faXLqRZw6UktQ+w2jgN+B3ZL7iahU2yB8CN9g4tMlHR9W2jV61 qdG8axbHu/p4HBsp5BPHdw70npq6oclhtdMR4AC20CJI52+HoLTwVJInxlXQ1bnZ6Ps7 avnQoNIIGr69SC1dvq095T40UxzpmY6lgEDkCfogRh2yVDNMqAVOX7WUa2LDJgE0wugj uRB7j/NsG1704dHfN53a6gnyPbhz/Lz+889trUIUgaNzrgry2GQkmngGqax0oZM4Nkie lgYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=nk7mXSEX; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w19si849110edq.469.2022.01.12.18.42.56; Wed, 12 Jan 2022 18:42:56 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=nk7mXSEX; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 70A4868B8F4; Thu, 13 Jan 2022 04:06:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 ; Thu, 13 Jan 2022 04:05:58 +0200 (EET) Received: by mail-qv1-f53.google.com with SMTP id q4so5110846qvh.9 for ; 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-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 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 18:05:56 -0800 (PST) From: James Almer 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: /LD0keAPnmEZ From: Anton Khirnov Signed-off-by: James Almer --- 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++;