From patchwork Wed Dec 8 01:06:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32124 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7043856iog; Tue, 7 Dec 2021 17:08:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZkWdQcWReTyausZcGZB7EJDsqGtLR5d9hZdyUXGKJKPH8a85REmxDBTsQZ45yMZJBDz/9 X-Received: by 2002:a17:906:a0d7:: with SMTP id bh23mr3636914ejb.82.1638925719544; Tue, 07 Dec 2021 17:08:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925719; cv=none; d=google.com; s=arc-20160816; b=vGWGG+hNiQizc/wH5oT6W0+roVsK9Wlt6MU6mWKWSdVgYV7tg7WU0zuZtnerGdPRrj uP9T+WIKz4NIRiTHOrlxlG/F4EUv4p4zS9yFEJe/Bknmd8KJ4GPIsj3Ir9jorm+DTBPV Xw8XOr7bXobq7/ZZnu8deXDJMb8y+Ey8XOkWxXM3/9cV+S2U0TRuD7r78fkoOepYWrc/ zqRQ3LRsnSwIbcuiVbxaZs4cOmDANT63FNxCXh1VMCWfsFY+ECp0pIrPzauM38nCvkSe 40Ba2uUyHmmcL8uxJjSJHAeT5/9EVaDmyU9fMI2Iy6tOPVOLnaZKOI5eNKFhRIRhtORM k+IQ== 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=yQ/PPYv4RgSj12J4aWOA0jegNUvOajLvxpF5Z8wFJCQ=; b=zfSMjDkbnfVDKBh9uJsSrq+AyK2dkNGGb/l93lGGqyl6m9RV3seyTJKqCyGAoHH7z9 MLzAPY3XrzCsgHD2vm+Af/cyP+EQd3L1Zu0bskxpaCWjFVNI49Nod+EJoPojek0SmJrQ iA1yyk3LPhdxt7sv8OfNMyQcAqpfDM4XKEhLnT/fyjq+tD3jYRAFd80HolRcvtW/Mii6 8j67DrZlvfiI3UVcpncyhBUeFqRAmHz2V1JaS4Z/H2H25NO8EdpQGUlWInWy/oR/i3Sx FK3vuKrXdnCcsY6vjPLxWAybTBCRobTrm3q2Ey0XIDEcO7Q/Rwu5VsDRx/cQ0wtHqYdE mKkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=RAV7WhAu; 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 e6si1897742ejb.739.2021.12.07.17.08.38; Tue, 07 Dec 2021 17:08:39 -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=RAV7WhAu; 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 1BC3068A980; Wed, 8 Dec 2021 03:07:38 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f41.google.com (mail-ua1-f41.google.com [209.85.222.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0C8FC68AD93 for ; Wed, 8 Dec 2021 03:07:33 +0200 (EET) Received: by mail-ua1-f41.google.com with SMTP id 30so1830558uag.13 for ; Tue, 07 Dec 2021 17:07:33 -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=IGCiUibKaN7Kf1mSX/Z7JiSSXQ58O+YdvQvTYfFXiSw=; b=RAV7WhAuYpKmI64/W1ZRFGQBno9blYvHjbQiDpL+Ocn/aAuLYElA6XDK3nUjcaU+j4 BW2aW0Snqj+fWNOL52VmbhzDJ+A4WuhVxeOtktLH+YVHbTfDzhJPLWC5u2/KMvp00mfB vZ5PhYP+9q0LJXxByqBsmIYaZCvFEoMckmerw8dLfzkZMiTNKmvk7/z6Ww0bYBQpdD5y XWrJSetmdbVIfzBVOnww3EBBRulCUj5iT3JLFIVMFHqa45px9FulliidpBrYnFlbYXxF AxNXLh44YfIOo9bmDMhads0hNus73QH3INIAxQ1QpVZEbh8wEeOi5S7FcC0GrLljU66U HWsQ== 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=IGCiUibKaN7Kf1mSX/Z7JiSSXQ58O+YdvQvTYfFXiSw=; b=eidvPra49C7Cm28URLy0pIjhhN4x4D9u+u+Ov4e2oY3Rk8Vo4dTRK5g0rTc6i4WMAI QMW9iUfKxl8X15B2G8vbFHGzLiE2qhaEPZZF4DKwA/BkbDua9G9AojuNLfao2Wew4luA aGachvZxV51+W2669v7BIZqRY93d96nMSy9QAseEYHWP6t9YlN1yYkka6r7JXP8t3Zr8 1pB2/05256TPcl22s0APZVWk+eDnMrrf5jSuy+Yqw3lzQrngw0L2ow8hCm6FQo26HNFJ f6aqY3kHfpAu+jqn2PTc3H8GRxIj27hCEPG4A2ZOXDay/mzdQkvr5Gt+tHJDcbhR5KEJ Upmg== X-Gm-Message-State: AOAM530mxf2ksJTiRf3uBVgKUyrz4hPXx/EjcCAOssSP1u2WvhGG7AZV TbWYUW6cjjpBd29Ng05l9Wse0FQJZqmmci9z X-Received: by 2002:ab0:36c4:: with SMTP id v4mr4080631uau.8.1638925652206; Tue, 07 Dec 2021 17:07:32 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:31 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:22 -0300 Message-Id: <20211208010649.381-7-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 006/279] avcodecpar: switch to the 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: vz7fVGTWiRqx From: Vittorio Giovara Signed-off-by: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavcodec/codec_par.c | 37 +++++++++++++++++++++++++++++++++---- libavcodec/codec_par.h | 12 ++++++++++++ libavcodec/utils.c | 12 ++++++++++-- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/libavcodec/codec_par.c b/libavcodec/codec_par.c index 1a5168a04b..9d43af1db4 100644 --- a/libavcodec/codec_par.c +++ b/libavcodec/codec_par.c @@ -31,6 +31,7 @@ static void codec_parameters_reset(AVCodecParameters *par) { av_freep(&par->extradata); + av_channel_layout_uninit(&par->ch_layout); memset(par, 0, sizeof(*par)); @@ -71,6 +72,8 @@ void avcodec_parameters_free(AVCodecParameters **ppar) int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src) { + int ret; + codec_parameters_reset(dst); memcpy(dst, src, sizeof(*dst)); @@ -84,6 +87,10 @@ int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src dst->extradata_size = src->extradata_size; } + ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout); + if (ret < 0) + return ret; + return 0; } @@ -118,8 +125,19 @@ int avcodec_parameters_from_context(AVCodecParameters *par, break; case AVMEDIA_TYPE_AUDIO: par->format = codec->sample_fmt; - par->channel_layout = codec->channel_layout; - par->channels = codec->channels; + if (codec->channel_layout) + av_channel_layout_from_mask(&par->ch_layout, codec->channel_layout); + else { + par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + par->ch_layout.nb_channels = codec->channels; + } +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + par->channel_layout = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + par->ch_layout.u.mask : 0; + par->channels = par->ch_layout.nb_channels; +FF_ENABLE_DEPRECATION_WARNINGS +#endif par->sample_rate = codec->sample_rate; par->block_align = codec->block_align; par->frame_size = codec->frame_size; @@ -173,8 +191,19 @@ int avcodec_parameters_to_context(AVCodecContext *codec, break; case AVMEDIA_TYPE_AUDIO: codec->sample_fmt = par->format; - codec->channel_layout = par->channel_layout; - codec->channels = par->channels; + if (par->ch_layout.nb_channels) { + codec->channel_layout = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + par->ch_layout.u.mask : 0; + codec->channels = par->ch_layout.nb_channels; + } +#if FF_API_OLD_CHANNEL_LAYOUT + else { +FF_DISABLE_DEPRECATION_WARNINGS + codec->channel_layout = par->channel_layout; + codec->channels = par->channels; +FF_ENABLE_DEPRECATION_WARNINGS + } +#endif codec->sample_rate = par->sample_rate; codec->block_align = par->block_align; codec->frame_size = par->frame_size; diff --git a/libavcodec/codec_par.h b/libavcodec/codec_par.h index 10cf79dff1..4cacfbf3b3 100644 --- a/libavcodec/codec_par.h +++ b/libavcodec/codec_par.h @@ -24,6 +24,7 @@ #include #include "libavutil/avutil.h" +#include "libavutil/channel_layout.h" #include "libavutil/rational.h" #include "libavutil/pixfmt.h" @@ -149,6 +150,7 @@ typedef struct AVCodecParameters { enum AVColorSpace color_space; enum AVChromaLocation chroma_location; +#if FF_API_OLD_CHANNEL_LAYOUT /** * Video only. Number of delayed frames. */ @@ -158,12 +160,17 @@ typedef struct AVCodecParameters { * Audio only. The channel layout bitmask. May be 0 if the channel layout is * unknown or unspecified, otherwise the number of bits set must be equal to * the channels field. + * @deprecated use ch_layout */ + attribute_deprecated uint64_t channel_layout; /** * Audio only. The number of audio channels. + * @deprecated use ch_layout.nb_channels */ + attribute_deprecated int channels; +#endif /** * Audio only. The number of audio samples per second. */ @@ -198,6 +205,11 @@ typedef struct AVCodecParameters { * Audio only. Number of samples to skip after a discontinuity. */ int seek_preroll; + + /** + * Audio only. The channel layout and number of channels. + */ + AVChannelLayout ch_layout; } AVCodecParameters; /** diff --git a/libavcodec/utils.c b/libavcodec/utils.c index a91a54b0dc..dc5156210f 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -826,8 +826,16 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes) int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes) { - int duration = get_audio_frame_duration(par->codec_id, par->sample_rate, - par->channels, par->block_align, + int channels = par->ch_layout.nb_channels; + int duration; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (!channels) + channels = par->channels; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + duration = get_audio_frame_duration(par->codec_id, par->sample_rate, + channels, par->block_align, par->codec_tag, par->bits_per_coded_sample, par->bit_rate, par->extradata, par->frame_size, frame_bytes);