From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 0DBCA4DDC7 for ; Tue, 4 Mar 2025 11:55:40 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DECBD68ED6D; Tue, 4 Mar 2025 13:55:35 +0200 (EET) Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 03ECE68ECCA for ; Tue, 4 Mar 2025 13:55:28 +0200 (EET) Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-43bcc02ca41so5302515e9.0 for ; Tue, 04 Mar 2025 03:55:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741089328; x=1741694128; darn=ffmpeg.org; h=content-transfer-encoding:content-language:to:subject:from :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=vSbj3EuSHS4rK/zNoR21hfoC1yQCYMw4ayC1MApHeKo=; b=kXj0BLH2M0IIx9MtuSQewBN+MoGrt3PPIgHRLNSwWBp0LiJC9iIm6dmm9peS2BqDP4 swxQmUDH7P7RW8y0IuHIjU6voUe0bc95NsmbKYeSDzC5OJOAroETG/N4GpVZEqgfZx4J RuNNvxDwWKoYcIAyJsqiL0Wj9WiU/yyiH95LEPQdo99DmMdqfgC1Z7uCQ1Eaqj0Bo6wx /KON/+D1x5kTjryWTVtQdVpTChNi/wvPAHDeRQVa3bpSRCsU5GcAvFoRKbOeh1YG9YK+ o1vd6T4HxprT18JSTcEdzxa/QdqgPrRPeC+O+cXuSxrnNs07c+ZSV+mFXncDvNeQJMUE YbYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741089328; x=1741694128; h=content-transfer-encoding:content-language:to:subject:from :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=vSbj3EuSHS4rK/zNoR21hfoC1yQCYMw4ayC1MApHeKo=; b=UaHjkHAqR45IR5uHrHmc8LvxUxI+6tDcSfwhyTfnCAkIUb3oQkW5W2lmN1F9iwWh3x uY2W+M5ZqMlBlL7GM7qDV5NDGzT0xSfB7NetCcBkg2uwUjJLO1renM62IyspgMyXv+Bg IypOyMvOePhLLaKr5ZgQ9R+Gbj5IZ7Mq5lQuhRptfNEy9BChejnFDDCd6bEdqQ4DHWQD kzvwXemdqC6V6T5VS9/LwfGg3dtpspvd+b+3it7TMyM36EhHFWBNBc8MEY5WbnmgWJhZ GD/5JpE+kZfck3o63Fu0weY73W821RP3ixZ3J/QUeKYSyxu3v8jN7nxalf3dxndTX1pR U3lg== X-Gm-Message-State: AOJu0YzfUr+CgVzbg43zrS/bd/aoCPJPf3zerIBiUZvRhhPkEN024BjK leb9ady+zC0dNISo0FkJgsOTqrwTZko7hSsYt636UN31Yw/e87gchq7ruA== X-Gm-Gg: ASbGnctxdX2MXpuFYsh50fbQ181ShljSV9yzm6tkxIsYfkE+s75vU7lCSfbTNx/k+QS r/GgGvLxRDoQna+tPMl5HkkSzHcbZyY+5LmZ3eMmD3CamZLWK86/zyTW3RGUlUdctQdpVhD3/vk mymLW6VK37HZJdEWCw9rM7dBY4C8mqKzzYOfjUHM89+jGvgMKXi4G916JRJZhwVcg+l+/PNdnQ6 ZFinJt1nc/uLwB/47EXpIhL79tg5K7X8F/2fE8SPfWchvia56gISb1AULsDeeShKIiYQZakE9aB gS9JybfnVR2PZQgWac668hPr62BkZnzB55BOHVePbF3v3p+jKhhQVyW04TpH/AH6/u7YVVnaWrm /yX4gV5zcbJ41/PdgfJH8FX1R X-Google-Smtp-Source: AGHT+IHQDfk+90sGJS7MRTo1F2JA20N/ttcQSq2M+FPKIy/t8GTl0IcHjhVyr2fJbdLvTNizikPOjg== X-Received: by 2002:a05:600c:154e:b0:439:6a7b:7697 with SMTP id 5b1f17b1804b1-43ba670fb9bmr144701665e9.14.1741089328039; Tue, 04 Mar 2025 03:55:28 -0800 (PST) Received: from ?IPV6:2001:9e8:1dab:f200:e498:a19b:30c6:a662? ([2001:9e8:1dab:f200:e498:a19b:30c6:a662]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43bcbcc53d3sm13526555e9.0.2025.03.04.03.55.27 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Mar 2025 03:55:27 -0800 (PST) Message-ID: <15e94abf-61dc-49ab-a209-bf6d1b3701ae@gmail.com> Date: Tue, 4 Mar 2025 12:55:26 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Leandro Santiago To: ffmpeg-devel@ffmpeg.org Content-Language: en-US Subject: [FFmpeg-devel] [PATCH] avutil/frame: add new functions to get 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: The functions are: av_frame_side_data_get_nth_c() av_frame_side_data_get_nth() av_frame_get_nth_side_data() They mimic the counterparts without the `_nth` suffix/infix, with an extra argument, which specifies the relative position of the entry of a given type. Signed-off-by: Leandro Santiago --- libavutil/frame.c | 10 ++++++++++ libavutil/frame.h | 43 ++++++++++++++++++++++++++++++++++++++++--- libavutil/side_data.c | 14 +++++++++++--- 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index 71bde48f8b..dd0fd06378 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -699,6 +699,16 @@ AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, ); } +AVFrameSideData *av_frame_get_nth_side_data(const AVFrame *frame, + enum AVFrameSideDataType type, + int n) +{ + return (AVFrameSideData *)av_frame_side_data_get_nth( + frame->side_data, frame->nb_side_data, + type, n + ); +} + static int frame_copy_video(AVFrame *dst, const AVFrame *src) { int planes; diff --git a/libavutil/frame.h b/libavutil/frame.h index 49260ae2dd..56375280bb 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1017,12 +1017,22 @@ AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame, AVBufferRef *buf); /** - * @return a pointer to the side data of a given type on success, NULL if there + * @return a pointer to the first 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); +/** + * @return a pointer to the side data of a given type on success, + * after skipping the first matches. Otherwise return NULL if there + * is no side data with such type in this frame or if all the matches were skipped. + * @param n the relative position of the side data entry + */ +AVFrameSideData *av_frame_get_nth_side_data(const AVFrame *frame, + enum AVFrameSideDataType type, + int n); + /** * Remove and free all side data instances of the given type. */ @@ -1170,7 +1180,7 @@ int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, const AVFrameSideData *src, unsigned int flags); /** - * Get a side data entry of a specific type from an array. + * Get the first side data entry of a specific type from an array. * * @param sd array of side data. * @param nb_sd integer containing the number of entries in the array. @@ -1184,7 +1194,24 @@ const AVFrameSideData *av_frame_side_data_get_c(const AVFrameSideData * const *s enum AVFrameSideDataType type); /** - * Wrapper around av_frame_side_data_get_c() to workaround the limitation + * Get a side data entry of a specific type from an array. + * + * @param sd array of side data. + * @param nb_sd integer containing the number of entries in the array. + * @param type type of side data to be queried + * @param n relative position of the side data entry. + * + * @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 set or all the entries were skipped. + */ +const AVFrameSideData *av_frame_side_data_get_nth_c(const AVFrameSideData * const *sd, + const int nb_sd, + enum AVFrameSideDataType type, + int n +); + +/** + * Wrappers around av_frame_side_data_get{_nth}_c() and to workaround the limitation * that for any type T the conversion from T * const * to const T * const * * is not performed automatically in C. * @see av_frame_side_data_get_c() @@ -1198,6 +1225,16 @@ const AVFrameSideData *av_frame_side_data_get(AVFrameSideData * const *sd, nb_sd, type); } +static inline +const AVFrameSideData *av_frame_side_data_get_nth(AVFrameSideData * const *sd, + const int nb_sd, + enum AVFrameSideDataType type, + int n) +{ + return av_frame_side_data_get_nth_c((const AVFrameSideData * const *)sd, + nb_sd, type, n); +} + /** * Remove and free all side data instances of the given type from an array. */ diff --git a/libavutil/side_data.c b/libavutil/side_data.c index 17965f2d3c..bfe408e611 100644 --- a/libavutil/side_data.c +++ b/libavutil/side_data.c @@ -301,13 +301,21 @@ int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, return 0; } -const AVFrameSideData *av_frame_side_data_get_c(const AVFrameSideData * const *sd, +const AVFrameSideData *av_frame_side_data_get_nth_c(const AVFrameSideData * const *sd, const int nb_sd, - enum AVFrameSideDataType type) + enum AVFrameSideDataType type, + int n) { for (int i = 0; i < nb_sd; i++) { - if (sd[i]->type == type) + if (sd[i]->type == type && --n < 0) return sd[i]; } return NULL; } + +const AVFrameSideData *av_frame_side_data_get_c(const AVFrameSideData * const *sd, + const int nb_sd, + enum AVFrameSideDataType type) +{ + return av_frame_side_data_get_nth_c(sd, nb_sd, type, 0); +} -- 2.48.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".