From patchwork Tue Jan 11 20:45:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33255 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp4049588iog; Tue, 11 Jan 2022 12:50:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJyfGTWxgh27InKJiOUPQYTyBzP+l5VLZNGflKNpdiEAIVmH+tq87JqHp+JTNzpm64lIvAu3 X-Received: by 2002:a17:907:961d:: with SMTP id gb29mr4926617ejc.123.1641934258303; Tue, 11 Jan 2022 12:50:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641934258; cv=none; d=google.com; s=arc-20160816; b=SUOJ6bhkYUEhEwpliePm9+BpnYIAiUSRWt34XVyzHKmotNK0cScESQ5DEhFJ7DTUUo hQqIwnBvO0dzl2g6SEWIhDGaNrBYDSLDSzbXjS+CgPFhySrHCnzl22kxho4duhT5kKdM YbNyWCqX5zsA7mVkIgDKe79hzoedN9HS254VZfBr9bN6T1gQm5FK+k33d6aiP0RfZSWV X+4T/WL0RE2EaXTx0CQq4CKvae0DZlQ8wW35nxQgKxzzQ9l7I134u+ATF2Nb6vOQHerS 34LE8p+p1p2coSxHlaPcWCYlL8Qu4OGOs7CWEX0NVQXrrfCtM302+1agFeslOAMS4RR7 XI4A== 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:delivered-to; bh=FkCkV5Tr4wetqW/BRi4177Ql7OIJcLFMn8nST3v05cw=; b=qEBf0vXjeIu33fiV9NgReAa4hZuk19lHBNUqAUw/iQ1Cp8wqtyMa+A64Joded8t68B YmHZXfnsphO+84k93ZMiCr8hIk9/X+FEoJDevMlFf89pTwOvMsFK/xnwHVMX0QZ6qD5w jjk0ka4cX7C7Mp1ba4nVueVmjwdBknarlVjnGq4vpE6sLkHzXaJyLShHVHVRYPjf+DPq JBMbogZMVnKukL7M8llICRZ8ML0YaJ6sGI/M1yT6nFcST1gekxxyT/vdQ+nzwAi7VaH5 TRo27WeZQ+yUTicrdxRhwXEkI5QvcSSFgZGlOhgN9tzvXhe7/zZvFDwr25sxWS1V24T7 rd9w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ji2si2595711ejc.546.2022.01.11.12.50.58; Tue, 11 Jan 2022 12:50:58 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A05DA68AEDD; Tue, 11 Jan 2022 22:47:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 99D0968AE0F for ; Tue, 11 Jan 2022 22:47:37 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 261A724017C for ; Tue, 11 Jan 2022 21:47:37 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id z0furuBg5U2E for ; Tue, 11 Jan 2022 21:47:36 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 4F9D524068F for ; Tue, 11 Jan 2022 21:47:26 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id E33853A00D9; Tue, 11 Jan 2022 21:47:24 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 21:45:37 +0100 Message-Id: <20220111204610.14262-2-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220111204610.14262-1-anton@khirnov.net> References: <20220111204610.14262-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/35] lavu/fifo: make the contents of AVFifoBuffer private on next major bump 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: A1jGhahPTEdH There should be no good reason for the callers to access any of its contents. Define a new type for the internal struct that currently matches AVFifoBuffer. This will allow adding new private fields without waiting for the major bump and will be useful in the following commits. Unfortunately AVFifoBuffer fields cannot be marked as deprecated because it would trigger a warning wherever fifo.h is #included, due to inlined av_fifo_peek2(). --- doc/APIchanges | 4 ++++ libavutil/fifo.c | 23 +++++++++++++++++++---- libavutil/fifo.h | 14 ++++++++++++-- libavutil/tests/fifo.c | 2 +- libavutil/version.h | 1 + 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 8df0364e4c..21fa02ae9d 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -14,6 +14,10 @@ libavutil: 2021-04-27 API changes, most recent first: +2022-01-xx - xxxxxxxxxx - lavu fifo.h + Access to all AVFifoBuffer members is deprecated. The struct will + become an incomplete type in a future major libavutil version. + 2022-01-04 - 78dc21b123e - lavu 57.16.100 - frame.h Add AV_FRAME_DATA_DOVI_METADATA. diff --git a/libavutil/fifo.c b/libavutil/fifo.c index f2f046b1f3..aaade01333 100644 --- a/libavutil/fifo.c +++ b/libavutil/fifo.c @@ -28,9 +28,24 @@ #define FIFO_SIZE_MAX FFMIN3((uint64_t)INT_MAX, (uint64_t)UINT32_MAX, (uint64_t)SIZE_MAX) +#if FF_API_FIFO_PUBLIC +# define CTX_STRUCT_NAME FifoBuffer +#else +# define CTX_STRUCT_NAME AVFifoBuffer +#endif + +typedef struct CTX_STRUCT_NAME { + // These fields must match then contents of AVFifoBuffer in fifo.h + // until FF_API_FIFO_PUBLIC is removed + uint8_t *buffer; + uint8_t *rptr, *wptr, *end; + uint32_t rndx, wndx; + ///////////////////////////////////////// +} FifoBuffer; + AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size) { - AVFifoBuffer *f; + FifoBuffer *f; void *buffer; if (nmemb > FIFO_SIZE_MAX / size) @@ -39,15 +54,15 @@ AVFifoBuffer *av_fifo_alloc_array(size_t nmemb, size_t size) buffer = av_realloc_array(NULL, nmemb, size); if (!buffer) return NULL; - f = av_mallocz(sizeof(AVFifoBuffer)); + f = av_mallocz(sizeof(*f)); if (!f) { av_free(buffer); return NULL; } f->buffer = buffer; f->end = f->buffer + nmemb * size; - av_fifo_reset(f); - return f; + av_fifo_reset((AVFifoBuffer*)f); + return (AVFifoBuffer*)f; } AVFifoBuffer *av_fifo_alloc(unsigned int size) diff --git a/libavutil/fifo.h b/libavutil/fifo.h index f4fd291e59..ca4e7fe060 100644 --- a/libavutil/fifo.h +++ b/libavutil/fifo.h @@ -28,11 +28,21 @@ #include "avutil.h" #include "attributes.h" -typedef struct AVFifoBuffer { +#if FF_API_FIFO_PUBLIC +/** + * The contents of the struct are private and should not be accessed by the + * callers in any way. + */ +#endif +typedef struct AVFifoBuffer +#if FF_API_FIFO_PUBLIC +{ uint8_t *buffer; uint8_t *rptr, *wptr, *end; uint32_t rndx, wndx; -} AVFifoBuffer; +} +#endif +AVFifoBuffer; /** * Initialize an AVFifoBuffer. diff --git a/libavutil/tests/fifo.c b/libavutil/tests/fifo.c index a17d913233..e5aa88d252 100644 --- a/libavutil/tests/fifo.c +++ b/libavutil/tests/fifo.c @@ -18,7 +18,7 @@ #include #include -#include "libavutil/fifo.h" +#include "libavutil/fifo.c" int main(void) { diff --git a/libavutil/version.h b/libavutil/version.h index 953aac9d94..7c031f547e 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -110,6 +110,7 @@ #define FF_API_COLORSPACE_NAME (LIBAVUTIL_VERSION_MAJOR < 58) #define FF_API_AV_MALLOCZ_ARRAY (LIBAVUTIL_VERSION_MAJOR < 58) #define FF_API_FIFO_PEEK2 (LIBAVUTIL_VERSION_MAJOR < 58) +#define FF_API_FIFO_PUBLIC (LIBAVUTIL_VERSION_MAJOR < 58) /** * @}