From patchwork Thu Jan 13 02:06:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33519 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp45030iog; Wed, 12 Jan 2022 18:48:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJwwVZ3YCjy8q1JfK3o2laUEPi2iBMKhrgAL8XQfdtWU5cXS6wyB6iXx4PLH5amfuiFfk+68 X-Received: by 2002:a17:907:e8d:: with SMTP id ho13mr1868299ejc.477.1642042098698; Wed, 12 Jan 2022 18:48:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642042098; cv=none; d=google.com; s=arc-20160816; b=UN4rmdADP3ZhaxZTuOD4DzfXg/CJ7PIiMFwCi16Wm4M7vIsMkacxDYEr2zwfrllIz6 uRoPLbl9imdh80b9+u9i+wrOoKN+IL4LQ0iyThM86OtWpG8Y2X9NWlTqvv//YAoiXInq voPE2wFfLHus0ONDV9ilxR4q6nST/S79H7PDsGFQ8FVr5eNiKwLboFhc5NCltAkAu7IB HqOi4OO+DC6VOIpPDSbtI1Ctnzg7gAyDZ3rDj8xw1S6uKxTIMb7tfOzSfSLm5xJBFykR K4KChEHE8U0d0eyTN4RWVSP9kX4rUX8RuwCIzDHdCun+edjRodLoGLYMN25w97wNbfz3 NBbg== 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=TuVOV5h5m6OpiDo3A3kHltlkibVbvVl8pPHt+qvk3Yo=; b=vXmKPOvq9/fZn5RDMwYBQoKz3ZRAxAg9NPz1RrwkdOLQqnmp6V2lv70SssLa/ZMMZA PhNaL/GIlK0dT0ltXIqU1TYI+eOz8m2s0csyYt5nDj05N4XWxsZ9IWmIv9O1ZIRsIPvB J6wXzNz7mj6TS8pmrBn4LJvy/JkFiqoCtoqdQUQuIN/mb1Go5Fk2jtMW6pffCX2ECWYA Qs4GtF47rMKhgjOE2KY4XeH4MyY24ORNYsdXZiC3G8unxXT3DIAYZ61Zq1G1L4sSEzwK ir99+5JJvUjZ4fgYVHItOzg+FlgBOBlQGCcwPtNgA7nNgb+uUanZzW+600OrjvEPMGz5 LOxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=jxnSTT4b; 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 cm23si801973edb.406.2022.01.12.18.48.18; Wed, 12 Jan 2022 18:48:18 -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=jxnSTT4b; 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 29A6B68B9E4; Thu, 13 Jan 2022 04:07:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7DE8D68B9CD for ; Thu, 13 Jan 2022 04:07:48 +0200 (EET) Received: by mail-qt1-f175.google.com with SMTP id q14so5335825qtx.10 for ; Wed, 12 Jan 2022 18:07:48 -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=w5BEfF/oM5LHuOiczGoMGJsILFh7d+65wDaTRgKKyJg=; b=jxnSTT4beRYGi0bJ6+sdWRtyzEdxX1vG0RK3VxRpI3Ds4IHJKCSx6phze+MITV8lC4 a+4DsguRAW8yFd5mK++g7jbfqZic2WmHGLSBg5NNQNbwZUYLPxhlQjDk2h9v1tHgbBjg MTXrtAV/UvKij9dQT44hHaTKn8js1m94Yv62YqIAtMEzMt9YFWUfSpM60ExGlBFpVvbh 9gxrS1+HFVL7PhdngAlyciwL4TMaBNEj4XO6MWyweYbSwlqbHmxJNsltk25wqKRiWUCF 01Aw3rgG/+dfp/VmvFNcIqOu+9RfyydYhVJ6cO1I07tIWlvAAjmFwQAEyaejJwI5zxTm obng== 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=w5BEfF/oM5LHuOiczGoMGJsILFh7d+65wDaTRgKKyJg=; b=1fjFDJSXig1gN56iiR15LnbsScSKnu/Ud4MTM7RdjFtm4ZZrHeFwTEPywoNbL1rRGV P6z77V1/kxC04rkd+df6HkfQh7H3CbtpRmdHlek3iBl+FXFu5XF3fsHtwDKd74kfQHIf oEbuODSBCY8gjiTYU6K7UhqahaZ2wGsgQONGyUUtWTFAwnidZVNY+IF1auT3YJIanWxR h2apykKfoouEiN+gMEl7DemFtzMfyV0OBHAVLipJvdr2ZmJxZcebr8HXIqrea4KY7h8J 2uqNKScJg+3AYYN0u0YvljEfT5p/E4Sbc/KCVkwXs/wQMz8iOBypukkiD6gY2mv5pU5H LSMg== X-Gm-Message-State: AOAM533PngALnrVDaD2px2R6croxcNRnqykq1frIy0P3IRlJa5nSXGS3 Z5THVry16gUhuj4v2GBloLlchw9MPcs= X-Received: by 2002:a05:622a:1b8e:: with SMTP id bp14mr2005652qtb.357.1642039667057; Wed, 12 Jan 2022 18:07:47 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id a16sm1085946qta.13.2022.01.12.18.07.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 18:07:46 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 23:06:59 -0300 Message-Id: <20220113020713.801-16-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 255/281] sbc: 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: kPOXGXuC4h8A From: Anton Khirnov Signed-off-by: James Almer --- libavcodec/sbc_parser.c | 8 ++++++-- libavcodec/sbcdec.c | 9 ++++++++- libavcodec/sbcenc.c | 15 ++++++++++----- 3 files changed, 24 insertions(+), 8 deletions(-) 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 },