From patchwork Fri Apr 30 11:34:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brad Hards X-Patchwork-Id: 27538 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a11:4023:0:0:0:0 with SMTP id ky35csp333290pxb; Fri, 30 Apr 2021 04:35:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeeOYxvuSovqWMyPfLZwIUkzCNwBcfAg+wnO2ysrNz5K1bPlS6H+sRfER4G6WRSfvRbIlI X-Received: by 2002:a17:906:dc8:: with SMTP id p8mr3820604eji.75.1619782531290; Fri, 30 Apr 2021 04:35:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619782531; cv=none; d=google.com; s=arc-20160816; b=PY7rs8piLgXKsdgpf7n5c+/2AB2qLiSOPK6dwWq01FNFM4++gBaAgI2xf4wyK2hiqp 5m5CQrXFhumcLuiLKkf3xC2rJzxhgFSMXC++V7d28yaM2PWkeIkGbkuhcDdZgXirC7um wLwuUkUMt2imBpO06NZZJ+p9EAOZY+BPRYj08a5sMmf0Ui8+W7poF4RDV3A5VtV/7Ge0 w2MoGc3gSdeXKUdNDQ6Rc/evh5E5VRjN/Aa69T0F+HTDlGEqW8LhYt4ts0bmUzzyO/DB 8kwRUX93Oavt6SkzOAY+rWX//RAdi1gx17bcr3NafMmcg5OvFyedYdB4fkstu3B7PtOY EnTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=PjUh3Wvg2mNKt6AfhXUeebvC4gXKSmmVD/gO25y11H4=; b=ONMte4QCrRiFhYiS3dy7FFH/1C93jkm7kgndn9cmupbSj+cG09srzGff9AVsHXbX4f UTstqQ1MWb23D47tEoUpOzAaDsGJF7e0maby9v4wdtADc9fZDV+WNfcfUznhiGJ5inJt yhKOGKUhNZMYea0Vxxjs4GV26JJovdOyT3gXSlgY/NHE7HWq3aIUFHFS8Lt2zf0brTbh 0AfJ3U56lhvjUVq7nUfuX43SQPiMRJH/aLVguW1BiEjP8EqUDgX2BcFfeRsevxEktkTW RYjnrb02R7aDCZb2dMfDi6GHpmryCbl5ImXjKmxDjz4H2PcF+J6Sjzcqit/0dnDtmByS 7jzA== 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 p22si2892223ejg.624.2021.04.30.04.35.30; Fri, 30 Apr 2021 04:35:31 -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; 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 77A07689D84; Fri, 30 Apr 2021 14:34:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from cp1.nerdvana.net.au (cp1-new.nerdvana.net.au [113.212.99.70]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AC30C6883B3 for ; Fri, 30 Apr 2021 14:34:46 +0300 (EEST) Received: from ppp115-205.static.internode.on.net ([150.101.115.205]:41184 helo=audax.fritz.box) by cp1.nerdvana.net.au with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lcRPu-0000qy-Kj; Fri, 30 Apr 2021 21:34:42 +1000 From: Brad Hards To: ffmpeg-devel@ffmpeg.org Date: Fri, 30 Apr 2021 21:34:28 +1000 Message-Id: <20210430113432.308139-2-bradh@frogmouth.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210430113432.308139-1-bradh@frogmouth.net> References: <20210430113432.308139-1-bradh@frogmouth.net> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cp1.nerdvana.net.au X-AntiAbuse: Original Domain - ffmpeg.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - frogmouth.net X-Get-Message-Sender-Via: cp1.nerdvana.net.au: authenticated_id: bradh@frogmouth.net X-Authenticated-Sender: cp1.nerdvana.net.au: bradh@frogmouth.net X-Source: X-Source-Args: X-Source-Dir: Subject: [FFmpeg-devel] [PATCH 1/5] libavutil: add convenience accessors for frame side data 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 Cc: Brad Hards Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 0B40eHdZmal0 Signed-off-by: Brad Hards --- libavutil/frame.c | 31 +++++++++++++++++++++++++++++++ libavutil/frame.h | 23 +++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/libavutil/frame.c b/libavutil/frame.c index 2ec59b44b1..9f9953c2b4 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -625,6 +625,37 @@ AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, return NULL; } +AVFrameSideData *av_frame_get_side_data_n(const AVFrame *frame, + enum AVFrameSideDataType type, + const int side_data_instance) +{ + int i; + int n = 0; + + for (i = 0; i < frame->nb_side_data; i++) { + if (frame->side_data[i]->type == type) { + if (n == side_data_instance) { + return frame->side_data[i]; + } else { + n++; + } + } + } + return NULL; +} + +int av_frame_num_side_data(const AVFrame *frame, enum AVFrameSideDataType type) +{ + int i; + int num = 0; + for (i = 0; i < frame->nb_side_data; i++) { + if (frame->side_data[i]->type == type) { + num += 1; + } + } + return num; +} + static int frame_copy_video(AVFrame *dst, const AVFrame *src) { const uint8_t *src_data[4]; diff --git a/libavutil/frame.h b/libavutil/frame.h index ff2540a20f..8e94e3f679 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -839,11 +839,34 @@ AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame, AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type); +/** + * Find a specified instance of side data of a given type. + * + * @param frame a frame to find the side data in + * @param type type of the side data to find + * @param side_data_instance instance of the side data to return (0 base). + * + * @return a pointer to the n'th instance of side data of a given type on + * success, NULL if there are less than side_data_instance instances of the + * given type. + */ +AVFrameSideData *av_frame_get_side_data_n(const AVFrame *frame, + enum AVFrameSideDataType type, + const int side_data_instance); + /** * Remove and free all side data instances of the given type. */ void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type); +/** + * Get the number of instances of side data of a given type. + * + * @param frame a frame to find the side data in + * @param type type of the side data to find + * @return count of instances, which can be 0 + */ +int av_frame_num_side_data(const AVFrame *frame, enum AVFrameSideDataType type); /** * Flags for frame cropping.