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 ESMTP id A8CF448D67 for ; Mon, 25 Mar 2024 20:06:37 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A350568D502; Mon, 25 Mar 2024 22:06:28 +0200 (EET) Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9F57368D4DA for ; Mon, 25 Mar 2024 22:06:22 +0200 (EET) Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6e703e0e5deso3342296b3a.3 for ; Mon, 25 Mar 2024 13:06:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711397180; x=1712001980; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=HtlrqQ/rQLrs+fWCt3zDZNuGArfDy8D5wO2IuRTN5ss=; b=PK4dEoXGXHhWiC+ewNtiqLwD/T77ErafQkJOqviAju41RGSq8T9DWXj1zFjED65NBz F10tqBitZrWV800qGJ/aS2Ka8d8heM3M8LjCJjbk2aBvA4/+HHKgFxgXtyRj9tWbxI0J RFV2fbYKMGw3ORIyrBVwDehuLd3q/TULABfVYVU63D24U07kypmzbDY89ouFeQydF92Q M41JoJ7DrNRaw2TIR0giJPEz9VcF1eWnQ6Beei2vobAbz8W/S4TbloZ2HzszcBZMypnl MSXrfshD6Vm8OZo5lZDHkqoU1gMMbAkUxUA5oIkaqmwL6avdHiE6tekL44zHDLXwyU/p TgAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711397180; x=1712001980; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HtlrqQ/rQLrs+fWCt3zDZNuGArfDy8D5wO2IuRTN5ss=; b=pptfFb183gMgi/1taoVRuku8Trx8R4GUOsfvAFCoweuaTWJu/9yS4jDPzgjFm/pxnz m3YllsbyppFL/HfN5VO21vlmyf59a0jMsSuuMsdI3hCEcG63kvGB5IirEHUADdnUIfhM OjyM1fqhgIT8ekXV9YS7EvlkrDAu1naJa1AE501NPgVY9pJiSV83lx01EFres4TRzxSn s588ByRHqoIP7MscgDJMEprCmca6KBhzBLrDBzQbrujH5nogQlKJwdFwToSPfXHnAlQX jT6Spwx/aVCGh9PSqYmQhw7OoqgK1jTRyriE2JeIu40c/QT5wMonhFbVHINc+zh8eDcT KHYg== X-Gm-Message-State: AOJu0Yz4xbU//BY7UFK4mFZm53TJ1STD0A9AxVZuTQ9jJjh6QUV0rDJo 8lbrQ7nNXUl75i3mt+V+ke0aoIgJzyh3N4z5o4durB1viWOkUIlbB0jWu9/K X-Google-Smtp-Source: AGHT+IHU08mogHDHuMZ5PecQm6OQ6YuNtQwtc/xzoYvMkNm8iK/67nSgZlDgwbG45sTJkz0rQPlKZg== X-Received: by 2002:a05:6a20:6013:b0:1a3:7327:2312 with SMTP id r19-20020a056a20601300b001a373272312mr6100198pza.55.1711397179871; Mon, 25 Mar 2024 13:06:19 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id kt1-20020a056a004ba100b006ea98271e43sm4431120pfb.144.2024.03.25.13.06.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 13:06:19 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 25 Mar 2024 17:05:58 -0300 Message-ID: <20240325200602.63020-2-jamrial@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240325200602.63020-1-jamrial@gmail.com> References: <20240325200602.63020-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/6 v2] avutil/frame: add helper for adding side data w/ AVBufferRef to array 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: Signed-off-by: James Almer --- libavutil/frame.c | 43 +++++++++++++++++++++++++++++++++++++++++++ libavutil/frame.h | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/libavutil/frame.c b/libavutil/frame.c index a780e62fd0..33c077998a 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -789,6 +789,49 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, return ret; } +AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd, + enum AVFrameSideDataType type, + AVBufferRef **pbuf, unsigned int flags) +{ + AVFrameSideData *sd_dst = NULL; + AVBufferRef *buf; + + if (!sd || !pbuf || !nb_sd || (*nb_sd && !*sd)) + return NULL; + + if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE) + remove_side_data(sd, nb_sd, type); + if (flags & AV_FRAME_SIDE_DATA_FLAG_DONT_APPEND) { + for (int i = 0; i < *nb_sd; i++) { + AVFrameSideData *entry = ((*sd)[i]); + if (entry->type == type) { + if (!(flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF)) + av_buffer_unref(pbuf); + return entry; + } + } + } + + if (flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF) + buf = av_buffer_ref(*pbuf); + else + buf = *pbuf; + if (!buf) + return NULL; + + sd_dst = add_side_data_from_buf(sd, nb_sd, type, buf); + if (!sd_dst) { + if (flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF) + av_buffer_unref(&buf); + return NULL; + } + + if (!(flags & AV_FRAME_SIDE_DATA_FLAG_NEW_REF)) + *pbuf = NULL; + + return sd_dst; +} + int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, const AVFrameSideData *src, unsigned int flags) { diff --git a/libavutil/frame.h b/libavutil/frame.h index 7cc55a455e..e03ce39af7 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1011,6 +1011,10 @@ void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd); * Don't add a new entry if another of the same type exists. */ #define AV_FRAME_SIDE_DATA_FLAG_DONT_APPEND (1 << 1) +/** + * Create a new reference instead of taking ownership of the passed in one. + */ +#define AV_FRAME_SIDE_DATA_FLAG_NEW_REF (1 << 2) /** * Add new side data entry to an array. @@ -1029,11 +1033,41 @@ void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd); * is attempted. * @note In case of AV_FRAME_SIDE_DATA_FLAG_DONT_APPEND being set, if an * entry of the same type already exists, it will be returned instead. + * @note AV_FRAME_SIDE_DATA_FLAG_NEW_REF has no effect in this function. */ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, size_t size, unsigned int flags); +/** + * Add a new side data entry to an array from an existing AVBufferRef. + * + * @param sd pointer to array of side data to which to add another entry, + * or to NULL in order to start a new array. + * @param nb_sd pointer to an integer containing the number of entries in + * the array. + * @param type type of the added side data + * @param buf Pointer to AVBufferRef to add to the array. On success, + * the function takes ownership of the AVBufferRef and *buf is + * set to NULL, unless AV_FRAME_SIDE_DATA_FLAG_NEW_REF is set + * in which case the ownership will remain with the caller. + * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0. + * + * @return newly added side data on success, NULL on error. + * @note In case of AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of + * matching AVFrameSideDataType will be removed before the addition + * is attempted. + * @note In case of AV_FRAME_SIDE_DATA_FLAG_DONT_APPEND being set, if an + * entry of the same type already exists, it will be returned instead + * and the array will be unchanged. + * @note In case of AV_FRAME_SIDE_DATA_FLAG_NEW_REF being set, the ownership + * of *buf will remain with the caller. + * + */ +AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd, + enum AVFrameSideDataType type, + AVBufferRef **buf, unsigned int flags); + /** * Add a new side data entry to an array based on existing side data, taking * a reference towards the contained AVBufferRef. @@ -1053,6 +1087,7 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, * @note In case of AV_FRAME_SIDE_DATA_FLAG_DONT_APPEND being set, if an * entry of the same type as the one from src already exists, this * function will be a no-op. + * @note AV_FRAME_SIDE_DATA_FLAG_NEW_REF has no effect in this function. */ int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, const AVFrameSideData *src, unsigned int flags); -- 2.44.0 _______________________________________________ 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".