From patchwork Tue Apr 20 10:07:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brad Hards X-Patchwork-Id: 27190 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:5014:0:0:0:0:0 with SMTP id e20csp1325954iob; Tue, 20 Apr 2021 03:08:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmbpE00JP32ZUTmfZ2nNwnooLkQl8QfL7rD4Lwk8tFpBIGRi3jY1Ya2qH1OqyzQ3ZR91/P X-Received: by 2002:aa7:d693:: with SMTP id d19mr15288660edr.8.1618913300916; Tue, 20 Apr 2021 03:08:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618913300; cv=none; d=google.com; s=arc-20160816; b=Wdc8yLjNz6dy/q5y6Jz7GWecxlkDsWgbk6aMBTHk3hU0uzYHX4doium2ej9PUoE5rC SrguyooEt1/RHC7xYhKm+d7oM6kW6VuRWfBDUGrhpv/x7XA9yVVpog6VLgdEzmBvomkD Jz349kVEpQCuikL0xg5d+FUGljAPYXQP4Jo4l0yQuD/dBBDJiJb0eumUJLbpYECthC0l wSunjWlcZSx2FummEwby49JKtFTH9nXyQ9jKmRP9peOkoky5sz89wA8PQtSrVJ+TT3aF Tr2QAnug4pq5uaCxg/k3tHW4yCKuhx1eHkHB1mIWVgvOQ7zjwkUsfr/2Kbub7cS3HBlU NXvw== 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:message-id:date:to:from :delivered-to; bh=PLmk/gP5zM9Ju0Ncs1G4RsE9+12Mf92XRGzAF5S8YPQ=; b=Lkt95TeTw1z1p9NehW+Lb2YfTw8m2v1DL8a8wgapocuLfHiphmZZXNXvSc1IwxW+p+ KkKngMaC6zJDJvIxDhW4IYZgJFp/ir4lEz7Hryta+K2gSVxeD0kq1HGk39ilzR+pIdRa MlGaULTsBBvrgHdp0db1KCk5h+AM2JxjroQj0SrIYLbABefZOILipnMP+IpGooGwiXtv Mm3+s7cq2C8ERQ/k4TQnRTnCniRMZxj0PJBbXlIxBjyzz48f9uG4s7VKIiAcaRa1oFeK nP3t7zlkAIa2UV3XY0lJeW61WZ4m101Md1xff+1W/wiCRIfrrJYWS13J8topIhrXT+ez 61AA== 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 e26si16133629edv.198.2021.04.20.03.08.19; Tue, 20 Apr 2021 03:08:20 -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 5E869688335; Tue, 20 Apr 2021 13:08:15 +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 ADFE868026B for ; Tue, 20 Apr 2021 13:08:08 +0300 (EEST) Received: from ppp115-205.static.internode.on.net ([150.101.115.205]:37096 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 1lYnIb-00084W-CB; Tue, 20 Apr 2021 20:08:05 +1000 From: Brad Hards To: ffmpeg-devel@ffmpeg.org Date: Tue, 20 Apr 2021 20:07:42 +1000 Message-Id: <20210420100742.14357-1-bradh@frogmouth.net> X-Mailer: git-send-email 2.27.0 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] libavutil: additional side_data accessor 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: r+/1k3gZPa5g The existing function allows access the first instance of a given type. Mostly that is OK, but some types can occur multiple times (e.g. libx264 can write version info, VANC and UMID related data as user data unregistered SEI. This adds API to access additional instances of a given SEI type. --- libavutil/frame.c | 19 +++++++++++++++++++ libavutil/frame.h | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/libavutil/frame.c b/libavutil/frame.c index 31a2117b82..662fcfd452 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -748,6 +748,25 @@ 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; +} + 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 a5ed91b20a..76dd14cbd5 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -943,12 +943,32 @@ AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame, AVBufferRef *buf); /** + * Find the first 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 + * * @return a pointer to the side data of a given type on success, NULL if there * is no side data with such type in this 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. */