From patchwork Thu Jan 13 01:49:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33297 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp13013iog; Wed, 12 Jan 2022 17:53:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJzykHnJ7dimdMSw+rgbpZQoW5pYE8RaL5RyE7770XeaS9LCw3sMlq70GgoHLp+x17L/UyIT X-Received: by 2002:a17:906:74d2:: with SMTP id z18mr1881252ejl.528.1642038816357; Wed, 12 Jan 2022 17:53:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642038816; cv=none; d=google.com; s=arc-20160816; b=OnqfT59XrmWEzTJxOeSB5h/2EgbkfHfD1qrMOTBIUDAZPqbVLY89RVxEmTjgy0Tp+e JhqPrAcKUzmysxbYwcw7vz2TPgVeQp8nHqa1I3pvZGo4fpDH3VEkFQ+1ukQ/AaMOEV9j yHeH44WcRFE7pNaAYSvTBEB2DkPDlFUuakpaDo5AFWQ6t0AWEM6FCjykCAffUR2s2Qcp eOcqbm6+WEUn72UhLTiNfDaBT35+rg6VRoGHeO5uVCrFot23as5RvCyJVbrGODNj8xAc IjhQaUJv24X8rrcaKbCNCinI2l32S2Xku4KutSwWeDWty8KSIA5/QgomS0djiFc/ot02 u/FA== 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=L1meX3CvssDlIyDDXONLXswLrTWmIXCGQl3ElWLK4Kk=; b=AzFkepvJFOqBaeBdgDQjUqS7NiYPofwDTJZ+euhjaw692mFVba5Dt48P6qJW9+SYDv pghHscFo+VsSOZL88qKrbmQYnrYtOsoK77Yj0G+ZKwNOhmsWnSuzII3AXY037n/AH4k/ o88tMi9oF/cZZKNPpHT398yO7KRmpt/Sf3CFDrny2c9nLxgrmcg0Z5mqvwE5Yi/mcYm/ DD8ZSyhkTzXOtEGTFoUerIpTN4juIP7dEQhb6UfUf7FMt6/gEL82J4wZNZ9gNsBRNhjx 9n+HFHIzya+xsGUoH8KwXnrLo0OzjnQRgaHyxPOSCPMG2YJv9ygofh5+5zReMA5Xk0fo WJNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=EXfaU7AT; 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 b4si869330edw.283.2022.01.12.17.53.36; Wed, 12 Jan 2022 17:53:36 -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=EXfaU7AT; 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 E8FC368AF54; Thu, 13 Jan 2022 03:52:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9821468ACAE for ; Thu, 13 Jan 2022 03:52:05 +0200 (EET) Received: by mail-qk1-f171.google.com with SMTP id c190so3901625qkg.9 for ; Wed, 12 Jan 2022 17:52:05 -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=G1ajNEdJ2HjeB+GqEtDbzt3KVUiAr7RVhwWKUyUL7nU=; b=EXfaU7AThcd76/IQLfAwQkwu+7Sh5Prd0FTXlwCwnwh5cXIMGZtFw4LihhBtoXGmPA 04qcBlmPfCBKY+/wmYooGD+j1GdMmESLsz2MrYbOhLV6iLtcCVQrvDJTZakHs880i4hb Cd8wyK/stqAXNbDzG9BdTCTifCOqzdydNTBovsnsZP543imEu5vnVx38Q/OryKDYajjt umUWjom/e5w0S1MB178LIRPOIEQVMfkXkQ/Lh64/hrl1oJiQVB+xIyjkqzlIaxixthMk orf1gG9bewkPi8JBQO981JT/Swjt8ltfIiFkDVRnBM4wgaItUhEjZTYqt1mcEIjQBA29 eDEA== 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=G1ajNEdJ2HjeB+GqEtDbzt3KVUiAr7RVhwWKUyUL7nU=; b=VizoOCYbN+61kHQUdiNKUjrWYXwxCflXSZNqXMAGfy3yJA1A2ShSDlWDvAOZ+9EUAf GIBo3p/hhuwlBTQx6g3cyq8+I5YftGjvZKf4XAQehSGtWJux7GIseWB3M1HOr0Yq+SoJ BRINWSp1kGFPL8JHGHpGeceNpldtq8FX77OVf0gSGT7jomwi3CsGk6W+v6+nCfn6fDNc +fzukClAGZK/UPMgswPzYuiuywwA7nTEQlY/eCEoKcSgrWKZXUKplVTCdqTYiTrVJAtb dZbDYMRupOHqBQrOH99vubcwsxj0nOxlp0IrD68HJ8bXAuHhtEJ8saFjKoBZFiPHsVq5 ZtIA== X-Gm-Message-State: AOAM533SgU2JonH+75ctVaoMu2z3IWybgHj1OoJNonjlPiT44XqVJqM5 WQN7PL/TajzPut6iG6uY6oZS8igvYW8= X-Received: by 2002:a05:620a:6:: with SMTP id j6mr1814974qki.294.1642038724009; Wed, 12 Jan 2022 17:52:04 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id i21sm1204710qti.31.2022.01.12.17.52.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 17:52:03 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 22:49:27 -0300 Message-Id: <20220113015101.4-6-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 005/281] 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: ehznomXx/oH0 From: Anton Khirnov Signed-off-by: Vittorio Giovara Signed-off-by: James Almer --- libavutil/frame.c | 116 +++++++++++++++++++++++++++++++++++++--------- libavutil/frame.h | 16 ++++++- 2 files changed, 109 insertions(+), 23 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index 8997c85e35..6bb72943d1 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -28,10 +28,12 @@ #include "samplefmt.h" #include "hwcontext.h" +#if FF_API_OLD_CHANNEL_LAYOUT #define CHECK_CHANNELS_CONSISTENCY(frame) \ av_assert2(!(frame)->channel_layout || \ (frame)->channels == \ av_get_channel_layout_nb_channels((frame)->channel_layout)) +#endif #if FF_API_COLORSPACE_NAME const char *av_get_colorspace_name(enum AVColorSpace val) @@ -186,18 +188,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 +256,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 +350,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 +429,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 +492,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 +540,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 +592,18 @@ 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 = frame->channels; + CHECK_CHANNELS_CONSISTENCY(frame); + } +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,16 +709,26 @@ 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) - return AVERROR(EINVAL); +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (!channels) { + if (dst->channels != src->channels || + dst->channel_layout != src->channel_layout) + return AVERROR(EINVAL); + channels = dst->channels; + planes = planar ? channels : 1; + CHECK_CHANNELS_CONSISTENCY(src); + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif - CHECK_CHANNELS_CONSISTENCY(src); + if (dst->nb_samples != src->nb_samples || + av_channel_layout_compare(&dst->ch_layout, &src->ch_layout)) + return AVERROR(EINVAL); for (i = 0; i < planes; i++) if (!dst->extended_data[i] || !src->extended_data[i]) @@ -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 18e239f870..7443f1a9b1 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" @@ -493,10 +494,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 @@ -620,12 +625,16 @@ typedef struct AVFrame { #define FF_DECODE_ERROR_CONCEALMENT_ACTIVE 4 #define FF_DECODE_ERROR_DECODE_SLICES 8 +#if FF_API_OLD_CHANNEL_LAYOUT /** * number of audio channels, only used for audio. * - encoding: unused * - decoding: Read by user. + * @deprecated use ch_layout instead */ + attribute_deprecated int channels; +#endif /** * size of the corresponding packet containing the compressed @@ -681,6 +690,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; @@ -760,7 +774,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.