From patchwork Thu Jan 13 01:49:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33299 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp13223iog; Wed, 12 Jan 2022 17:54:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4hOJGLtraysZHRZkNfhjjowmCTqhltNPumgWFw/4+31PoJeue4dqoNYbojdXi1qRJdBPg X-Received: by 2002:a17:906:cc84:: with SMTP id oq4mr1982464ejb.736.1642038841837; Wed, 12 Jan 2022 17:54:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642038841; cv=none; d=google.com; s=arc-20160816; b=a5PXOjvkZkmm3Y1EmJKcqx1ZGwnPb+R/DIdXdhOS40Cqrl/iOdhgi7oYnnla6RaY6l tvQ4bL8YcbeiLvpmqrz+DHoPd4cgu6g5MIz13JN4BTPhgoO/d7Z8SbAow2HVAuv+sxAS OGgbcv+T+SYuXVdlLeBuukmD6PScX1I/950qmWYZr2316OY01C9a876Axyca98Sqd739 KwATnb1fPqDlMdtFJb9/D9n3Pj4lKwrJnlXdpoiKG5o77qi4Dn4DqAFs24j9FqU8IjgE kQv5WnWJ9JiEUoqI7qkh7mzDfSh4KGUenzdecrpJivl6xv6pfsue0JT0nmXfqtsPi9Ip CRig== 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=78fI5cwr4JARHxNQEzl+T0TXwyV2YhLgitfO2obJXDI=; b=VUIUOT/rCaEYxp1Z0kv7IFRUguyGroUxDQAMQ7T8bzBnbQ2igTnjjGdEigwHAnTgCv nZCKHKSyMHsW5lzne8ooerNge+uYR9is9aq8aPxChkODPiox8oCj+OtEW8XVoa+rZw1j jDpt5UGsvRWn+gNL+QfYoUdHiAX8HgQCp8+B3rdi4wtFxzFSZAaf0oPV/FHiu5S/EsWu YtesqlldbfoQgwY/DYjfRf/cY0b57T/sWg4T9hq4bdNnS+Q4KdivQjEJoODhxiDLFvtk 8YBgzg6R10CtXB2Up4G54xG1aXvDA6DqOytkDoYJ9oS2uAA3fbTpWJo4oRwQVCK4x/1o YXlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=RihRodnu; 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 j4si742525edr.142.2022.01.12.17.53.58; Wed, 12 Jan 2022 17:54:01 -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=RihRodnu; 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 DF79968AF36; Thu, 13 Jan 2022 03:52:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EC0EE68AF26 for ; Thu, 13 Jan 2022 03:52:06 +0200 (EET) Received: by mail-qt1-f177.google.com with SMTP id q14so5298476qtx.10 for ; Wed, 12 Jan 2022 17:52:06 -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=1D+2yorsQk47XQkOy4AF+TlYZGKwcNN+oDBMcqLL25Q=; b=RihRodnuHnU8Us6++7blpYI1Nuvk4+Ju/GtyDw4kJczkV1tFC7XGsDkV/dtnRbwIDv K2bVZbYLXce21LuKxLBnH5Q83NzboS6Z/iQWKBrEdaw3tIRVMq8O68+lV9Ir0g85kxXZ BSGmDIUA8kAAaiO4DnmkElLfMlE4iYNBXdQdCek4WVpzo3ll6T7fMcfJFhT6QHUZUQXP ZdYsWowgOgFjQJFHGrOp85sF5U3mrFK0uGBKW0txVtfeFkfBhsE4YFv0NKucU/eZUs7x oBZFGMcgdWroDF3QvzdXE3Zrh96mfPm3mIr7erJQSvzBq6KtKBzRv4+MJ1t2BUlTkzQn vVjw== 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=1D+2yorsQk47XQkOy4AF+TlYZGKwcNN+oDBMcqLL25Q=; b=EueFhHKLISbMBRuxfE3UpmtPvpBKJqL6t15707VKEELw/lYQpxHuUi8rtkKdwLdu3q RyyHWbM40mwc5ZlpomPgMMIMOfFkrmdjfUeFlYUZiCZW1tfP6YGl+WDwJkV+o5HsjhZJ IlnxbUaKANk8j+1V31V24YuJpU7LHOtPNdmbV8UPqbYeuTTKZaF7YLQnNut64rP3FGMq jed+MzWyClXs4aTaBQom3jQdsaSrf7eVBvtq5sux7dpPBs1aYgByn+e8yjPQUKFDz0py RuikKZf79zfeyaV5C81m75/kS3WMTi2/PpYFzoKg9rs60zn4Dujai4R9fsvfFyaPuiXE yRHw== X-Gm-Message-State: AOAM531p3mkFdhj6FrYScozFqt0dZdEPMzNldhBfUHuIKMgbbvNem6QO ++Irp3w8HWe+L2SINZz9Zf/3bA81IBs= X-Received: by 2002:ac8:5d94:: with SMTP id d20mr2065738qtx.214.1642038725216; Wed, 12 Jan 2022 17:52:05 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id i21sm1204710qti.31.2022.01.12.17.52.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 17:52:04 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 22:49:28 -0300 Message-Id: <20220113015101.4-7-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 006/281] 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: mdpnwYDFJKYa 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..7660791a12 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" @@ -154,16 +155,22 @@ typedef struct AVCodecParameters { */ int video_delay; +#if FF_API_OLD_CHANNEL_LAYOUT /** * 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 b19befef21..0505ea6ba2 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -815,8 +815,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);