From patchwork Mon Apr 19 14:10:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 27059 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:5014:0:0:0:0:0 with SMTP id e20csp565437iob; Mon, 19 Apr 2021 07:23:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCxdK0hYBuM0kyjk1nSFlwvCUlnpfa0h4I7UGNbAgvOVJEb4mgjeIVMr3TAaCVvFVI7B1r X-Received: by 2002:a17:906:b7c4:: with SMTP id fy4mr22073175ejb.489.1618842192800; Mon, 19 Apr 2021 07:23:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618842192; cv=none; d=google.com; s=arc-20160816; b=F9oLHOHSLIzCK57t4HYUS92bYpyzjYljHXPAqfteE4kRW3FpDTtp6kvsDvR4HfDyFR OadUOoMFVzthfkuqQsRj2gmO8UtY8n3bLp/Z3E686qgoHVBfv6cNvPDjSAP9v54kIcq7 dy1fTAw4SG0AIjOgNowx4JTDyNRQI5BS4An4S/ael1nIUBRBRka9b4Zg+ksqc90+/sOD Bl0qmxDyyIzJeoqqbnaRYtkA+cRHiqXtl6aPHl516OP5ezBHfT7W3uyWKUQF73SxnONt HkcxHLWzMC63iCgZd6284Lc96WDDKVV1JKGEHOjGylnbOAsXsxUzpl0bUD37jMJNYoa4 KNyA== 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=SdzHSTikEqu6DD0pci7kwdOCYrVIwcT/FBwg2gkqsXA=; b=sqkwj/P9wcNVf/67b8EST1ZS2EfPrVxrde3eNHuHDhtZlY+M9G2h/GjgSZZUCYuKgg 1TEqoXSdqKFo1lcFM1q/wUZ0Rc1x7tB4PfHixtj5D/1MFnbXD8lSG5WFxKOCtSXgCShI zQqif5t01dJoXZvLJvLTihKGvIC/nlMYVRf3iQDvnmcXnrT+hTcO7nz9ZnQ4P58nlqGN 7eP/gB6/yhayX0kq9nMbN4qVtCoaX5bf3WwZtGhFRfIOTvrBmGHnNfPmuNXYHSFJio+m SuIzUs8xEGK3l8R6Z2wxI/lV91GLTfNek+ebthHtH6zK2CZMHn9/iLB2nPoqpJMigBrW YYPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=pt0i5XzL; 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 hb9si9847489ejb.304.2021.04.19.07.23.12; Mon, 19 Apr 2021 07:23:12 -0700 (PDT) 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=20161025 header.b=pt0i5XzL; 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 70668689E50; Mon, 19 Apr 2021 17:12:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 86B8A680906 for ; Mon, 19 Apr 2021 17:12:36 +0300 (EEST) Received: by mail-qv1-f41.google.com with SMTP id i3so11376770qvj.7 for ; Mon, 19 Apr 2021 07:12:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=J+d4Wxl1j85gpvMShTF4sQnTAfWWOulTNdoXbXzn4/M=; b=pt0i5XzLH57Bd8mRu1uxU/bc2SP+zZfI6HrV6hDpJ87xNowedUNv/jwF3X1/i0bxx2 T9S87Tx7QpUHsvxj5Geq9wqm8mukYj17xYqh7bE8V496tSfHT9S8slirumt0aaCFF5Tv Bf3OxtfIVp4Vy5s/qVM8M83U+b1aCLP/1Nl5UdM4OFJk6G6HPxdncZNXw+HBUzVnwMTH aXIn82oGDsjWyFgKHst8QAJihLJRMxj5fAmK3XfbM6G8OCcJqZScEJ4vvfMa6NPUfyR3 zrgmboqP9CvvqOuIwoAZakjgMzt6L5r53ogI/jO5MC3Q8PiqaHJN4N5jkNICY2s32odL yUMQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=J+d4Wxl1j85gpvMShTF4sQnTAfWWOulTNdoXbXzn4/M=; b=Alwhm/syWqSW3C4zTeEs8JTSa+DCXqjPRcYRtULmbiW6W9lW5nMjXfpjSDp5FlKipZ a125I32qA0iM9xkWScvuv8SbXJzFgikaQM2WsdNljH+GBdHR/2zh2Ukeb6FNRVqNUEeA /TdfYuBC1nfAupYwbOAWUqyHHCcLaGJapXqDtK9tCNx7+RBTGBfVcEngj0bXBgsbnBbM cAWGiGa68Lly2T1zftK+9ZnJ+b0cPlsX5OclFufXMOpfA2BIx/AJ0aHu/V6A/IjBTteP 7UeXbHSEISznuejrPi0a9nrVTZVCIhIB3UMs+RyuYb6bqWh0zlYONrXcbVx1P2dRrpK7 CrBg== X-Gm-Message-State: AOAM531Kw0npVIw+o2VCcVEDEoNqo9PJzFNHXkS0P0AO0golMQ/KlBMG pNT5RI0S4U+Q2LwUYeLgqx6zM/H6CLc= X-Received: by 2002:ad4:538a:: with SMTP id i10mr21721107qvv.9.1618841554828; Mon, 19 Apr 2021 07:12:34 -0700 (PDT) Received: from localhost.localdomain ([191.83.209.133]) by smtp.gmail.com with ESMTPSA id f7sm2049494qtv.53.2021.04.19.07.12.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Apr 2021 07:12:34 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 19 Apr 2021 11:10:11 -0300 Message-Id: <20210419141024.8174-75-jamrial@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210419141024.8174-1-jamrial@gmail.com> References: <20210419141024.8174-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 74/87] avcodec/codec, allcodecs: Constify the AVCodec 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: fXS0uHZe9oqZ From: Andreas Rheinhardt Signed-off-by: Andreas Rheinhardt --- doc/APIchanges | 5 +++++ libavcodec/allcodecs.c | 18 +++++++++--------- libavcodec/codec.h | 8 ++++---- tools/target_dec_fuzzer.c | 8 ++++---- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 2522978952..a823a4419c 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -17,6 +17,11 @@ API changes, most recent first: 2021-04-17 - xxxxxxxxxx - lavu 56.73.100 - frame.h detection_bbox.h Add AV_FRAME_DATA_DETECTION_BBOXES +2021-04-14 - xxxxxxxxxx - lavc yyyyyyyyy - codec.h + avcodec_find_encoder_by_name(), avcodec_find_encoder(), + avcodec_find_decoder_by_name() and avcodec_find_decoder() + now return a pointer to const AVCodec. + 2021-04-14 - xxxxxxxxxx - lavf yyyyyyyyy - avformat.h Constified AVFormatContext.*_codec. diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index cf6fe2055b..e60ac5ce78 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -872,7 +872,7 @@ static enum AVCodecID remap_deprecated_codec_id(enum AVCodecID id) } } -static AVCodec *find_codec(enum AVCodecID id, int (*x)(const AVCodec *)) +static const AVCodec *find_codec(enum AVCodecID id, int (*x)(const AVCodec *)) { const AVCodec *p, *experimental = NULL; void *i = 0; @@ -886,24 +886,24 @@ static AVCodec *find_codec(enum AVCodecID id, int (*x)(const AVCodec *)) if (p->capabilities & AV_CODEC_CAP_EXPERIMENTAL && !experimental) { experimental = p; } else - return (AVCodec*)p; + return p; } } - return (AVCodec*)experimental; + return experimental; } -AVCodec *avcodec_find_encoder(enum AVCodecID id) +const AVCodec *avcodec_find_encoder(enum AVCodecID id) { return find_codec(id, av_codec_is_encoder); } -AVCodec *avcodec_find_decoder(enum AVCodecID id) +const AVCodec *avcodec_find_decoder(enum AVCodecID id) { return find_codec(id, av_codec_is_decoder); } -static AVCodec *find_codec_by_name(const char *name, int (*x)(const AVCodec *)) +static const AVCodec *find_codec_by_name(const char *name, int (*x)(const AVCodec *)) { void *i = 0; const AVCodec *p; @@ -915,18 +915,18 @@ static AVCodec *find_codec_by_name(const char *name, int (*x)(const AVCodec *)) if (!x(p)) continue; if (strcmp(name, p->name) == 0) - return (AVCodec*)p; + return p; } return NULL; } -AVCodec *avcodec_find_encoder_by_name(const char *name) +const AVCodec *avcodec_find_encoder_by_name(const char *name) { return find_codec_by_name(name, av_codec_is_encoder); } -AVCodec *avcodec_find_decoder_by_name(const char *name) +const AVCodec *avcodec_find_decoder_by_name(const char *name) { return find_codec_by_name(name, av_codec_is_decoder); } diff --git a/libavcodec/codec.h b/libavcodec/codec.h index c95078491d..c8653e3b31 100644 --- a/libavcodec/codec.h +++ b/libavcodec/codec.h @@ -367,7 +367,7 @@ const AVCodec *av_codec_iterate(void **opaque); * @param id AVCodecID of the requested decoder * @return A decoder if one was found, NULL otherwise. */ -AVCodec *avcodec_find_decoder(enum AVCodecID id); +const AVCodec *avcodec_find_decoder(enum AVCodecID id); /** * Find a registered decoder with the specified name. @@ -375,7 +375,7 @@ AVCodec *avcodec_find_decoder(enum AVCodecID id); * @param name name of the requested decoder * @return A decoder if one was found, NULL otherwise. */ -AVCodec *avcodec_find_decoder_by_name(const char *name); +const AVCodec *avcodec_find_decoder_by_name(const char *name); /** * Find a registered encoder with a matching codec ID. @@ -383,7 +383,7 @@ AVCodec *avcodec_find_decoder_by_name(const char *name); * @param id AVCodecID of the requested encoder * @return An encoder if one was found, NULL otherwise. */ -AVCodec *avcodec_find_encoder(enum AVCodecID id); +const AVCodec *avcodec_find_encoder(enum AVCodecID id); /** * Find a registered encoder with the specified name. @@ -391,7 +391,7 @@ AVCodec *avcodec_find_encoder(enum AVCodecID id); * @param name name of the requested encoder * @return An encoder if one was found, NULL otherwise. */ -AVCodec *avcodec_find_encoder_by_name(const char *name); +const AVCodec *avcodec_find_encoder_by_name(const char *name); /** * @return a non-zero number if codec is an encoder, zero otherwise */ diff --git a/tools/target_dec_fuzzer.c b/tools/target_dec_fuzzer.c index 334c47a2c8..f52eba92b1 100644 --- a/tools/target_dec_fuzzer.c +++ b/tools/target_dec_fuzzer.c @@ -59,7 +59,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); -extern AVCodec * codec_list[]; +extern const AVCodec * codec_list[]; static void error(const char *err) { @@ -67,10 +67,10 @@ static void error(const char *err) exit(1); } -static AVCodec *c = NULL; -static AVCodec *AVCodecInitialize(enum AVCodecID codec_id) +static const AVCodec *c = NULL; +static const AVCodec *AVCodecInitialize(enum AVCodecID codec_id) { - AVCodec *res; + const AVCodec *res; res = avcodec_find_decoder(codec_id); if (!res)