From patchwork Wed Aug 21 09:04:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 14636 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 A3948447EBB for ; Wed, 21 Aug 2019 12:14:18 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8679C68AB2F; Wed, 21 Aug 2019 12:14:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8438B68023F for ; Wed, 21 Aug 2019 12:14:11 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id k2so1312122wrq.2 for ; Wed, 21 Aug 2019 02:14:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=35c7x1uHmDthOLMw1zknlbv/4IGgRmLgxpEmoFkvp2Q=; b=VuPJlfYj4Sjvyypbyy2iO/lp05TZGETm2g5dWTB1Sfy6Q3g/o2SDIHk2tUdFeXq6Bf RJvGlbMVjsWwclGAaq327M1/5QwUSIHbxKbXxwPiOJ+n+MS2wVCztWtRndBtKHGelpco 3LYu59Sd+y34i2vnbg79IFviRlPOloFS2w7ELh5Rzpl4FyERgSBGHkSw9gzM+QgWeaPN 8xa2WJjN4fkouSg89j22UrKBB+1EArxNStRVHZ0isagAbOK6ZEJdEYWDDnRNHBAVXVmk /vrTwhmku6380FelibDP1vTODFcqLsatUSnhLxxQIbaLCkQGuQCoWeWOqssMg0MOxvRz VGxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=35c7x1uHmDthOLMw1zknlbv/4IGgRmLgxpEmoFkvp2Q=; b=Ti0FGUc4Lst0aPB7IlKx029pLqEg7y6u7W8nvoG6KPNK040oaHgsaL+Mhxr35F08P8 DE3XAa1FHagVLlCQqDP6U3YDJ6yYItDf+1ljQjksl/PK3QyfqplEvyKkfqbM8K8VDzeO KUqPPnu8xsXqeh85Jo2u7l8US94kUAMSLzskVR6xM/Tm/fCu9iLlb48r2cAHQryS3uZQ 0bswyu2sKAspGhByHA8gjq5ToT+CqSTx1JtNmhVb5wEAAZIpL9w78AvG+562c5IHcP/l 6/eV1Af+XQB0JzdiUfQabJQZCkao5CdRZtztoMuh5KRiDTiTgUWB2UDkp1wArQlEcF+1 Fimw== X-Gm-Message-State: APjAAAVzeG0/btJB+r3d4aGDLnQ7CUH2H3u/uCpCFoMV7eofvz5M1jZc s61fObxBasOFfjdtA1F6BPFxGtrahrSs2hBi X-Google-Smtp-Source: APXvYqyJYqHU3Ir4592+Xx3q3paifBkEIbe9Ox00IKyy1DHA2gIc/dpjp/evt1Ai8ruPg1wHMcb9zA== X-Received: by 2002:adf:e708:: with SMTP id c8mr40099590wrm.25.1566378850873; Wed, 21 Aug 2019 02:14:10 -0700 (PDT) Received: from localhost.localdomain (ipbcc0f857.dynamic.kabel-deutschland.de. [188.192.248.87]) by smtp.gmail.com with ESMTPSA id o14sm37173171wrg.64.2019.08.21.02.14.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2019 02:14:10 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 21 Aug 2019 11:04:36 +0200 Message-Id: <20190821090438.10260-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190821090438.10260-1-andreas.rheinhardt@gmail.com> References: <20190821090438.10260-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] lavformat: Prepare to make avio_enum_protocols const correct 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Using avio_enum_protocols works as follows: One initializes a pointer to void and gives avio_enum_protocols the address of said pointer as argument; the pointer will be updated to point to a member of the url_protocols array. Now the address of the pointer can be reused for another call to avio_enum_protocols. Said array consists of constant pointers (to constant URLProtocols), but the user now has a pointer to non-const to it; of course it was always intended that the user is not allowed to modify what the pointer points to and this has been enforced by hiding the real type of the underlying object. But it is better to use a const void ** as parameter to enforce this. This way avio_enum_protocols can be implemented without resorting to casting a const away or ignoring constness as is done currently. Given that this amounts to an ABI and API break, this can only be done at the next major version bump; as usual, the break is currently hidden behind an appropriate #if. It was also necessary to change the type of a pointer used in avio_enum_protocols. This makes the line that is not const correct move as long as the old function signature is used. With the new signature, avio_enum_protocols will be const correct. This change will eventually force changes in their callers, e.g. to show_protocols in fftools/cmdutils. (This function contains all currently existing calls to avio_enum_protocols in FFmpeg's codebase. It hasn't been touched in this commit.) Signed-off-by: Andreas Rheinhardt --- libavformat/avio.h | 4 ++++ libavformat/protocols.c | 6 +++++- libavformat/version.h | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libavformat/avio.h b/libavformat/avio.h index 9141642e75..e067ea8985 100644 --- a/libavformat/avio.h +++ b/libavformat/avio.h @@ -805,7 +805,11 @@ int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer); * * @return A static string containing the name of current protocol or NULL */ +#if FF_API_NONCONST_ENUM_PROTOCOLS const char *avio_enum_protocols(void **opaque, int output); +#else +const char *avio_enum_protocols(const void **opaque, int output); +#endif /** * Pause and resume playing - only meaningful if using a network streaming diff --git a/libavformat/protocols.c b/libavformat/protocols.c index ad95659795..c722f9a897 100644 --- a/libavformat/protocols.c +++ b/libavformat/protocols.c @@ -91,9 +91,13 @@ const AVClass *ff_urlcontext_child_class_next(const AVClass *prev) } +#if FF_API_NONCONST_ENUM_PROTOCOLS const char *avio_enum_protocols(void **opaque, int output) +#else +const char *avio_enum_protocols(const void **opaque, int output) +#endif { - const URLProtocol **p = *opaque; + const URLProtocol * const *p = *opaque; p = p ? p + 1 : url_protocols; *opaque = p; diff --git a/libavformat/version.h b/libavformat/version.h index 9814db8633..b0b9264382 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -106,6 +106,9 @@ #ifndef FF_API_AVIOFORMAT #define FF_API_AVIOFORMAT (LIBAVFORMAT_VERSION_MAJOR < 59) #endif +#ifndef FF_API_NONCONST_ENUM_PROTOCOLS +#define FF_API_NONCONST_ENUM_PROTOCOLS (LIBAVFORMAT_VERSION_MAJOR < 59) +#endif #ifndef FF_API_R_FRAME_RATE