From patchwork Sat Mar 6 19:42:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26218 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 60A6A44B9AF for ; Sat, 6 Mar 2021 21:43:16 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2FD3B68A31D; Sat, 6 Mar 2021 21:43:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DABDE687F30 for ; Sat, 6 Mar 2021 21:43:09 +0200 (EET) Received: by mail-qv1-f47.google.com with SMTP id bh3so2728137qvb.5 for ; Sat, 06 Mar 2021 11:43:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=/rE+akdYJDOEd+/r4eiPj8ftVQL6PfntIBxudoCi4NY=; b=EUTLFfHbJ6RdRZn6H62mt0XknBwXRTmAUAGo0kISR/nqpe6Wf264bZJDE2PvBGtPJv xNsM5WPrf8myhQe0keP4Uc2Ot6/sp6u7t/OaD+EXjeelfk9+zuQVKY9UiDsCb7eKMaOz 1PWYEYG2yjWs8B9wXTao5gaBM+KvvBJ8k8R5vUASsklsl/OP/eVnJ2dFVeBPGqexsJSz PafbkPOk9BgiQVi5wr6Z4KXjy+N6APklAyLC+Y7qbpSryeNVHgLQw1Ypyvl+wFFQYdvI DjfZpNIFIoRriskw0vXKTD/VpexM4eB0QJPHkt+KesTHkSBgTSQguoOl17LIg2r33HIq qkoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=/rE+akdYJDOEd+/r4eiPj8ftVQL6PfntIBxudoCi4NY=; b=arBqvoJDMApx4zImKNYB69+p371dLFRxMLvDbCW+nfBMvia83jF3F+qUQlueKU8aRn YoSFqtp30Je3FtXFwEmchHa0ybxnh2Q6GAe4jQfc8/RKMXMOxPran6W1ern9r5Bxsf0v 3S2rMRYDeu2PbXhT56/sfIOhTdOvvSUHTtGF6UlCzZuz+bjZE3mNHAR0Y4a+Hmk7b1b0 2I4cveSh69CaWcbK/5EfqluLzm1ryL63h8hzoD0EZv2lviVtgT9LXVGXfaqE+Zxu6y5m tEBH5d7WlsdWsjg2DNvFkUNBWwUXqsgFJSp9RtatVbmfEfbmGK3tIk2EdyLPKHOSBgLg X5XQ== X-Gm-Message-State: AOAM5331vK0Iq4ZrmcCZta0L50FqrryUCkpsnIOd5PD3xWYtLp4Z5SjF vHpoCpJ6OaFMVAyti00suZbdzuYPdWE24A== X-Google-Smtp-Source: ABdhPJzJg6dvfG+Hz+lYtyJaNx2DUnLCbUr/nTvomuxmBpOc0jMVf2fW4M1e8lgmx4qe3uUyBgA8rg== X-Received: by 2002:a0c:d78e:: with SMTP id z14mr14966058qvi.8.1615059788046; Sat, 06 Mar 2021 11:43:08 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id s19sm4376601qks.130.2021.03.06.11.43.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Mar 2021 11:43:07 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sat, 6 Mar 2021 16:42:35 -0300 Message-Id: <20210306194243.14931-1-jamrial@gmail.com> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/9 v3] avutil/buffer: change public function and struct size parameter types to size_t X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" Signed-off-by: James Almer --- Changes since v2 is the addition of the buffer_size_t typedef to reduce the amount of ifdeffery required to adapt our code. doc/APIchanges | 4 ++++ libavutil/buffer.c | 14 +++++++------- libavutil/buffer.h | 32 ++++++++++++++++++++++++++++++++ libavutil/buffer_internal.h | 8 ++++---- libavutil/internal.h | 7 +++++++ libavutil/version.h | 5 ++++- 6 files changed, 58 insertions(+), 12 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 4027d599e7..7abc320db2 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,10 @@ libavutil: 2017-10-21 API changes, most recent first: +2021-03-xx - xxxxxxxxxx - lavu 56.68.100 - buffer.h + Change AVBufferRef related function and struct size parameter and fields + type to size_t at next major bump. + 2021-03-04 - xxxxxxxxxx - lavc 58.128.101 - avcodec.h Enable err_recognition to be set for encoders. diff --git a/libavutil/buffer.c b/libavutil/buffer.c index 3204f11b68..858633e8c7 100644 --- a/libavutil/buffer.c +++ b/libavutil/buffer.c @@ -26,7 +26,7 @@ #include "mem.h" #include "thread.h" -AVBufferRef *av_buffer_create(uint8_t *data, int size, +AVBufferRef *av_buffer_create(uint8_t *data, buffer_size_t size, void (*free)(void *opaque, uint8_t *data), void *opaque, int flags) { @@ -64,7 +64,7 @@ void av_buffer_default_free(void *opaque, uint8_t *data) av_free(data); } -AVBufferRef *av_buffer_alloc(int size) +AVBufferRef *av_buffer_alloc(buffer_size_t size) { AVBufferRef *ret = NULL; uint8_t *data = NULL; @@ -80,7 +80,7 @@ AVBufferRef *av_buffer_alloc(int size) return ret; } -AVBufferRef *av_buffer_allocz(int size) +AVBufferRef *av_buffer_allocz(buffer_size_t size) { AVBufferRef *ret = av_buffer_alloc(size); if (!ret) @@ -166,7 +166,7 @@ int av_buffer_make_writable(AVBufferRef **pbuf) return 0; } -int av_buffer_realloc(AVBufferRef **pbuf, int size) +int av_buffer_realloc(AVBufferRef **pbuf, buffer_size_t size) { AVBufferRef *buf = *pbuf; uint8_t *tmp; @@ -242,8 +242,8 @@ int av_buffer_replace(AVBufferRef **pdst, AVBufferRef *src) return 0; } -AVBufferPool *av_buffer_pool_init2(int size, void *opaque, - AVBufferRef* (*alloc)(void *opaque, int size), +AVBufferPool *av_buffer_pool_init2(buffer_size_t size, void *opaque, + AVBufferRef* (*alloc)(void *opaque, buffer_size_t size), void (*pool_free)(void *opaque)) { AVBufferPool *pool = av_mallocz(sizeof(*pool)); @@ -263,7 +263,7 @@ AVBufferPool *av_buffer_pool_init2(int size, void *opaque, return pool; } -AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size)) +AVBufferPool *av_buffer_pool_init(buffer_size_t size, AVBufferRef* (*alloc)(buffer_size_t size)) { AVBufferPool *pool = av_mallocz(sizeof(*pool)); if (!pool) diff --git a/libavutil/buffer.h b/libavutil/buffer.h index fd4e381efa..241a80ed67 100644 --- a/libavutil/buffer.h +++ b/libavutil/buffer.h @@ -25,8 +25,11 @@ #ifndef AVUTIL_BUFFER_H #define AVUTIL_BUFFER_H +#include #include +#include "version.h" + /** * @defgroup lavu_buffer AVBuffer * @ingroup lavu_data @@ -90,7 +93,11 @@ typedef struct AVBufferRef { /** * Size of data in bytes. */ +#if FF_API_BUFFER_SIZE_T int size; +#else + size_t size; +#endif } AVBufferRef; /** @@ -98,13 +105,21 @@ typedef struct AVBufferRef { * * @return an AVBufferRef of given size or NULL when out of memory */ +#if FF_API_BUFFER_SIZE_T AVBufferRef *av_buffer_alloc(int size); +#else +AVBufferRef *av_buffer_alloc(size_t size); +#endif /** * Same as av_buffer_alloc(), except the returned buffer will be initialized * to zero. */ +#if FF_API_BUFFER_SIZE_T AVBufferRef *av_buffer_allocz(int size); +#else +AVBufferRef *av_buffer_allocz(size_t size); +#endif /** * Always treat the buffer as read-only, even when it has only one @@ -127,7 +142,11 @@ AVBufferRef *av_buffer_allocz(int size); * * @return an AVBufferRef referring to data on success, NULL on failure. */ +#if FF_API_BUFFER_SIZE_T AVBufferRef *av_buffer_create(uint8_t *data, int size, +#else +AVBufferRef *av_buffer_create(uint8_t *data, size_t size, +#endif void (*free)(void *opaque, uint8_t *data), void *opaque, int flags); @@ -195,7 +214,11 @@ int av_buffer_make_writable(AVBufferRef **buf); * reference to it (i.e. the one passed to this function). In all other cases * a new buffer is allocated and the data is copied. */ +#if FF_API_BUFFER_SIZE_T int av_buffer_realloc(AVBufferRef **buf, int size); +#else +int av_buffer_realloc(AVBufferRef **buf, size_t size); +#endif /** * Ensure dst refers to the same data as src. @@ -262,7 +285,11 @@ typedef struct AVBufferPool AVBufferPool; * (av_buffer_alloc()). * @return newly created buffer pool on success, NULL on error. */ +#if FF_API_BUFFER_SIZE_T AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size)); +#else +AVBufferPool *av_buffer_pool_init(size_t size, AVBufferRef* (*alloc)(size_t size)); +#endif /** * Allocate and initialize a buffer pool with a more complex allocator. @@ -279,8 +306,13 @@ AVBufferPool *av_buffer_pool_init(int size, AVBufferRef* (*alloc)(int size)); * data. May be NULL. * @return newly created buffer pool on success, NULL on error. */ +#if FF_API_BUFFER_SIZE_T AVBufferPool *av_buffer_pool_init2(int size, void *opaque, AVBufferRef* (*alloc)(void *opaque, int size), +#else +AVBufferPool *av_buffer_pool_init2(size_t size, void *opaque, + AVBufferRef* (*alloc)(void *opaque, size_t size), +#endif void (*pool_free)(void *opaque)); /** diff --git a/libavutil/buffer_internal.h b/libavutil/buffer_internal.h index 70d2615a06..0b549e3a53 100644 --- a/libavutil/buffer_internal.h +++ b/libavutil/buffer_internal.h @@ -32,7 +32,7 @@ struct AVBuffer { uint8_t *data; /**< data described by this buffer */ - int size; /**< size of data in bytes */ + buffer_size_t size; /**< size of data in bytes */ /** * number of existing AVBufferRef instances referring to this buffer @@ -89,10 +89,10 @@ struct AVBufferPool { */ atomic_uint refcount; - int size; + buffer_size_t size; void *opaque; - AVBufferRef* (*alloc)(int size); - AVBufferRef* (*alloc2)(void *opaque, int size); + AVBufferRef* (*alloc)(buffer_size_t size); + AVBufferRef* (*alloc2)(void *opaque, buffer_size_t size); void (*pool_free)(void *opaque); }; diff --git a/libavutil/internal.h b/libavutil/internal.h index 93ea57c324..572daefec3 100644 --- a/libavutil/internal.h +++ b/libavutil/internal.h @@ -299,4 +299,11 @@ int avpriv_dict_set_timestamp(AVDictionary **dict, const char *key, int64_t time #define FF_PSEUDOPAL 0 #endif +// Temporary typedef to simplify porting all AVBufferRef users to size_t +#if FF_API_BUFFER_SIZE_T +typedef int buffer_size_t; +#else +typedef size_t buffer_size_t; +#endif + #endif /* AVUTIL_INTERNAL_H */ diff --git a/libavutil/version.h b/libavutil/version.h index 356c54d633..9a290d57e7 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 56 -#define LIBAVUTIL_VERSION_MINOR 67 +#define LIBAVUTIL_VERSION_MINOR 68 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ @@ -132,6 +132,9 @@ #ifndef FF_API_CHILD_CLASS_NEXT #define FF_API_CHILD_CLASS_NEXT (LIBAVUTIL_VERSION_MAJOR < 57) #endif +#ifndef FF_API_BUFFER_SIZE_T +#define FF_API_BUFFER_SIZE_T (LIBAVUTIL_VERSION_MAJOR < 57) +#endif #ifndef FF_API_D2STR #define FF_API_D2STR (LIBAVUTIL_VERSION_MAJOR < 58) #endif