From patchwork Wed Dec 8 01:06:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32129 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7044328iog; Tue, 7 Dec 2021 17:09:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJzAB5eUXOEnJSTyNJTO1v7dM3qXBzB/7NINRYxGjAcWu4Cn4nlbte3fnF/4mSvEIlVAgnEx X-Received: by 2002:aa7:c783:: with SMTP id n3mr14709809eds.121.1638925736938; Tue, 07 Dec 2021 17:08:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925736; cv=none; d=google.com; s=arc-20160816; b=Zp31uxpe6f0GvA3NzqLpsQ9iouftymxXtjykwZC5shH058394Z/wBcEag1uf2O4aaa Cv3EHpaD/XmdRGICWCnEJH93L+WngVd8YezKrLt1A6G5P71rPtSNV0WMtyeW3v+A5Gnz SaFQBQTTGXkTfm1WQ2Uue2i+R92yrUFVho13PpL/73joEvXJo1M3KZ9qrHHH7SF/gzDZ MNVwBXGiCgZHzoNP/iYDEF0X0QjoRSGOh5zcjEZV3Gaw3PxGbrABo/oZZ9kZilPu47R3 EsGqL6UF17y8i+6rBPJuk0LFzjiJ+cYX9cmJI6/hYmlK3rKIv64iNBBfGre+U7V6Al3W E7bw== 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=RLCOe7qTdaY6RBb92CBpa4TY23/uQm2nVXnrs5X3nms=; b=qGnCiOJYMa8pxewPyZPCW1MSf4Az4aV59KeQYn0vne/gHLG76ZbaAnlenJiF0ptth8 XtplVf0p1mhOcR38ynJo65RJN6FPpEERfrc4P2p9koGL4Pj5lrd5rt/39xxkos0nOaD9 300bgl1dwnWGfQXzawkGfZHWVEwTGMmsTsVQsw9JcVW/lkC8JJHVfBnPl6En48RaD9e2 oRG1nc/DvkY56ON62Af5VjlZpkbcJntAjrT4AngO8EVkXqiyrYaeEFbYTzrF4cJXUVKg 2hair5i6jcVhz/1vslUFyVpWu4WziCYcaNO7p8J0APNaR6BY6COZgz1LUpId4qCI6VkY m9tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=luMS4nPU; 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 qw2si2672811ejc.118.2021.12.07.17.08.56; Tue, 07 Dec 2021 17:08: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=luMS4nPU; 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 3F67268AE59; Wed, 8 Dec 2021 03:07:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vk1-f175.google.com (mail-vk1-f175.google.com [209.85.221.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C336B68ADF8 for ; Wed, 8 Dec 2021 03:07:32 +0200 (EET) Received: by mail-vk1-f175.google.com with SMTP id f7so554198vkf.10 for ; Tue, 07 Dec 2021 17:07:32 -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=uznTsAbrRwwqmmpx5clws+iPQAFvP8fYmLnZQO9pk4k=; b=luMS4nPUdfZEIi5Ue4KIvRBUcjQxPbfwk0TUMeiQh3XlFqMkdxNaRuQru3XJiRmOfJ L1Iljx9aWhOyH9fnz4hl2i070jG5ILe7ANaE/LRgTN+R4u6Dj9dKnltndIf8mNv8wLSG ZlInEgPQ69M66N83rr4NH38HH8qSJUgDXj862GsFPlK2CyjnHlPx4y5LjXoQoKuAqYE5 O/o/V7o/SxKC4/aiVv8VEA+v2FZnciTCW0mUHc2XArf0f4GDtaipSeb8RpP8OEYdtNlR qJpxN5V5sQ/J44Mc2pNBZPZZdAseyC/EdWD8bSxaTjy/Gh0YDodtG+OL2hNrC4IbxUXp DaUg== 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=uznTsAbrRwwqmmpx5clws+iPQAFvP8fYmLnZQO9pk4k=; b=quU0iwWcgTCefS2wMDYMQ3NlRQvbdCLx5ptpdPotyru32A1cVEEQ31WW2XyLT/kYah J9yNmaRPoRZ6kZ9IKXqoEESH+IfUqrz64g9X+nkZK4S7/Qwx77OHU5WFkxpqRSMlvvn3 4752Xr660RU18Y13HOrmyExpbCgQB6rVl/2AgxKfIUm3mDv2kxVi1rxP3plOad8gNjZ7 fhFXFz+9Y6GkobbdTAAAoUao0SO1ejJ03DV0d0hZf9Dvou0nPlP6mJzLm4ibxh8NY/UW MyLrkzzgQCaYtWO2VWZvAA0JFCqFxNOu/CBsm1ett1jZbTBWPE/0H/WhorkOsB57ct2e DsTA== X-Gm-Message-State: AOAM530ZrCs0schziT0hIDKotXrKRoGlHCFfE8t85wKlv261IvgZgzYd IPjkNdb/63ukIS2GFpnbaf0bFnKA8nk0ng2/ X-Received: by 2002:a1f:54c4:: with SMTP id i187mr56708384vkb.40.1638925649940; Tue, 07 Dec 2021 17:07:29 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:29 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:21 -0300 Message-Id: <20211208010649.381-6-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 005/279] avframe: 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: g0DTcHkAfoYp From: Anton Khirnov Signed-off-by: Vittorio Giovara Signed-off-by: James Almer --- libavutil/frame.c | 112 +++++++++++++++++++++++++++++++++++++--------- libavutil/frame.h | 12 ++++- 2 files changed, 103 insertions(+), 21 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index 0912ad9131..d07d6d7984 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -186,18 +186,27 @@ fail: static int get_audio_buffer(AVFrame *frame, int align) { - int channels; int planar = av_sample_fmt_is_planar(frame->format); - int planes; + int channels, planes; int ret, i; - if (!frame->channels) - frame->channels = av_get_channel_layout_nb_channels(frame->channel_layout); - - channels = frame->channels; - planes = planar ? channels : 1; - - CHECK_CHANNELS_CONSISTENCY(frame); +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (!frame->ch_layout.nb_channels) { + if (frame->channel_layout) { + av_channel_layout_from_mask(&frame->ch_layout, frame->channel_layout); + } else { + frame->ch_layout.nb_channels = frame->channels; + frame->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + } + } + frame->channels = frame->ch_layout.nb_channels; + frame->channel_layout = frame->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + frame->ch_layout.u.mask : 0; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + channels = frame->ch_layout.nb_channels; + planes = planar ? channels : 1; if (!frame->linesize[0]) { ret = av_samples_get_buffer_size(&frame->linesize[0], channels, frame->nb_samples, frame->format, @@ -245,10 +254,17 @@ int av_frame_get_buffer(AVFrame *frame, int align) if (frame->format < 0) return AVERROR(EINVAL); +FF_DISABLE_DEPRECATION_WARNINGS if (frame->width > 0 && frame->height > 0) return get_video_buffer(frame, align); - else if (frame->nb_samples > 0 && (frame->channel_layout || frame->channels > 0)) + else if (frame->nb_samples > 0 && + (av_channel_layout_check(&frame->ch_layout) +#if FF_API_OLD_CHANNEL_LAYOUT + || frame->channel_layout || frame->channels > 0 +#endif + )) return get_audio_buffer(frame, align); +FF_ENABLE_DEPRECATION_WARNINGS return AVERROR(EINVAL); } @@ -332,14 +348,33 @@ int av_frame_ref(AVFrame *dst, const AVFrame *src) dst->format = src->format; dst->width = src->width; dst->height = src->height; + dst->nb_samples = src->nb_samples; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS dst->channels = src->channels; dst->channel_layout = src->channel_layout; - dst->nb_samples = src->nb_samples; + if (!av_channel_layout_check(&src->ch_layout)) { + if (src->channel_layout) + av_channel_layout_from_mask(&dst->ch_layout, src->channel_layout); + else { + dst->ch_layout.nb_channels = src->channels; + dst->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + } + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif ret = frame_copy_props(dst, src, 0); if (ret < 0) goto fail; + // this check is needed only until FF_API_OLD_CHANNEL_LAYOUT is out + if (av_channel_layout_check(&src->ch_layout)) { + ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout); + if (ret < 0) + goto fail; + } + /* duplicate the frame data if it's not refcounted */ if (!src->buf[0]) { ret = av_frame_get_buffer(dst, 0); @@ -392,13 +427,12 @@ int av_frame_ref(AVFrame *dst, const AVFrame *src) /* duplicate extended data */ if (src->extended_data != src->data) { - int ch = src->channels; + int ch = dst->ch_layout.nb_channels; if (!ch) { ret = AVERROR(EINVAL); goto fail; } - CHECK_CHANNELS_CONSISTENCY(src); dst->extended_data = av_malloc_array(sizeof(*dst->extended_data), ch); if (!dst->extended_data) { @@ -456,6 +490,8 @@ void av_frame_unref(AVFrame *frame) if (frame->extended_data != frame->data) av_freep(&frame->extended_data); + av_channel_layout_uninit(&frame->ch_layout); + get_frame_defaults(frame); } @@ -502,9 +538,18 @@ int av_frame_make_writable(AVFrame *frame) tmp.format = frame->format; tmp.width = frame->width; tmp.height = frame->height; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS tmp.channels = frame->channels; tmp.channel_layout = frame->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif tmp.nb_samples = frame->nb_samples; + ret = av_channel_layout_copy(&tmp.ch_layout, &frame->ch_layout); + if (ret < 0) { + av_frame_unref(&tmp); + return ret; + } if (frame->hw_frames_ctx) ret = av_hwframe_get_buffer(frame->hw_frames_ctx, &tmp, 0); @@ -545,10 +590,16 @@ AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane) int planes, i; if (frame->nb_samples) { - int channels = frame->channels; + int channels = frame->ch_layout.nb_channels; + +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (!channels) + channels = av_get_channel_layout_nb_channels(frame->channel_layout); +FF_ENABLE_DEPRECATION_WARNINGS +#endif if (!channels) return NULL; - CHECK_CHANNELS_CONSISTENCY(frame); planes = av_sample_fmt_is_planar(frame->format) ? channels : 1; } else planes = 4; @@ -654,14 +705,28 @@ static int frame_copy_video(AVFrame *dst, const AVFrame *src) static int frame_copy_audio(AVFrame *dst, const AVFrame *src) { int planar = av_sample_fmt_is_planar(dst->format); - int channels = dst->channels; + int channels = dst->ch_layout.nb_channels; int planes = planar ? channels : 1; int i; - if (dst->nb_samples != src->nb_samples || - dst->channels != src->channels || - dst->channel_layout != src->channel_layout) +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (!channels) { + channels = av_get_channel_layout_nb_channels(dst->channel_layout); + planes = planar ? channels : 1; + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + +FF_DISABLE_DEPRECATION_WARNINGS + if (dst->nb_samples != src->nb_samples || + av_channel_layout_compare(&dst->ch_layout, &src->ch_layout) +#if FF_API_OLD_CHANNEL_LAYOUT + || dst->channel_layout != src->channel_layout +#endif + ) return AVERROR(EINVAL); +FF_ENABLE_DEPRECATION_WARNINGS CHECK_CHANNELS_CONSISTENCY(src); @@ -680,10 +745,17 @@ int av_frame_copy(AVFrame *dst, const AVFrame *src) if (dst->format != src->format || dst->format < 0) return AVERROR(EINVAL); +FF_DISABLE_DEPRECATION_WARNINGS if (dst->width > 0 && dst->height > 0) return frame_copy_video(dst, src); - else if (dst->nb_samples > 0 && dst->channels > 0) + else if (dst->nb_samples > 0 && + (av_channel_layout_check(&dst->ch_layout) +#if FF_API_OLD_CHANNEL_LAYOUT + || dst->channel_layout || dst->channels +#endif + )) return frame_copy_audio(dst, src); +FF_ENABLE_DEPRECATION_WARNINGS return AVERROR(EINVAL); } diff --git a/libavutil/frame.h b/libavutil/frame.h index 3f295f6b9e..7f6aa1c7c8 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -30,6 +30,7 @@ #include "avutil.h" #include "buffer.h" +#include "channel_layout.h" #include "dict.h" #include "rational.h" #include "samplefmt.h" @@ -486,10 +487,14 @@ typedef struct AVFrame { */ int sample_rate; +#if FF_API_OLD_CHANNEL_LAYOUT /** * Channel layout of the audio data. + * @deprecated use ch_layout instead */ + attribute_deprecated uint64_t channel_layout; +#endif /** * AVBuffer references backing the data for this frame. All the pointers in @@ -674,6 +679,11 @@ typedef struct AVFrame { * for the target frame's private_ref field. */ AVBufferRef *private_ref; + + /** + * Channel layout of the audio data. + */ + AVChannelLayout ch_layout; } AVFrame; @@ -753,7 +763,7 @@ void av_frame_move_ref(AVFrame *dst, AVFrame *src); * The following fields must be set on frame before calling this function: * - format (pixel format for video, sample format for audio) * - width and height for video - * - nb_samples and channel_layout for audio + * - nb_samples and ch_layout for audio * * This function will fill AVFrame.data and AVFrame.buf arrays and, if * necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf.