From patchwork Thu Mar 28 16:52:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 47590 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp1467926pzb; Thu, 28 Mar 2024 09:53:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWb9USDn5YMLvIOrZj29Ylfso7RLigY3O8q7bWMAmo7HSiyq0S+6wORqMSmeja5IAIKD/HyqunftdBztYdkovJdMNe8xMfGLqABxw== X-Google-Smtp-Source: AGHT+IGTj0wpuSJTbYeQ7pOnJzgaqtFj7tdjvSjaZUL3vPvrd7+QTfqg58162++RnuPkRC9m90xj X-Received: by 2002:a17:907:7684:b0:a47:4e09:e685 with SMTP id jv4-20020a170907768400b00a474e09e685mr1995249ejc.32.1711644818371; Thu, 28 Mar 2024 09:53:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711644818; cv=none; d=google.com; s=arc-20160816; b=QBtz2PKrvVeXuYuqIowWVwXaZtbGyjouBy4yvh4QaWCFpNGTsqD4ET18yzErIWuHdW YEmnHLy5NwZ02YajF4MjVj9a6/jcMlqCbYcIEVioOv00+VJVIsKZcH3bBEjPBJBS1ZNw R6Bxpwcvr5Sur1gexnNQTNxQcDVCgWZb5R4TWtSBBRYRsmLLNYix5Z5sYE1w3zlgcPuD m9wtKKGfnxwaz292lUVWgDukJynmzFbOuoraJoohQ4bLjJ9UP+DmNSA4LwZCyJlygbWU 0m8ppT+ahkM2prY7eoJgybbJyOANHddnWYD0DdJ0IIiFuNkf0y76J/VZNxrgcFBEXvO9 T+5Q== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=ab1g3JOYXeo8lRsWIKDAyK4++bq2mgctjHCk95iN9mA=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=ubBjEjRyA4IyTSJ5AMaZC6DCbO+k4jwldBL1x+sdmAwsv/ZbCxmQdLfidxTVKzmIGx zCPB23AsUWgd+H/GQhVbgNjP24UH5mBewz9RD19FAd5g4f9dlHTMQHKY2jsXdyazvKcZ 5maveeL1cukh/POmeN0FaKjppcE1YoEkjQfa2TVOBS2RD+VzXwj5LldxoR5MHkeZ+rM7 wQ6XjzUBShpm356UEuNmyp1uAOvwrFiOHhYrorBAhA4khl5q/TKpprfPk5QxQVXQVenx 98thhc3kmHTHYxuw8eXGAlOzl3UFbFCsCuKiDTR4uyVpS8A27XiIVPAr1oLMMfMUTMar 9cmw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=CvdEeMax; 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 gq6-20020a170906e24600b00a4746db1c28si911001ejb.29.2024.03.28.09.53.37; Thu, 28 Mar 2024 09:53:38 -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=20230601 header.b=CvdEeMax; 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 34A9968D0F4; Thu, 28 Mar 2024 18:53:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4846F68D01B for ; Thu, 28 Mar 2024 18:53:28 +0200 (EET) Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6e6082eab17so1094534b3a.1 for ; Thu, 28 Mar 2024 09:53:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711644805; x=1712249605; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=5E05i/7T+/66LbTbwEqpqLwG2G09axfHnrAz+rZ83Jc=; b=CvdEeMax1/wtJKzoHnJ9dfENeL7bCmaVty+IrXIi41pskQDS4LOICTWJgv0L3af3zz DpBaT8gVSQ/K8r40lEhWpXQNH/cHbQhUd08fotwZlNcERY6PSKWfk3YAydUp9fBmU0rV oe8XCwAiWkLlgMeFRbujkm9iSD3L3Q58ybZAZlgOGSePdSsxUrGZaKxoAf58QyTWkSeY rCkQ+gSqPkUrl2p7/mB55LcazmfNQW7a6oRPxj7vceOSpdLy/J7/uUC/2C/hTk8sh8oG D7uMVQnuBNTX55T+XnHtiSou5t4QB2lkMqXPwWuQIZh5lN62Y6F46NAphGBS7NPWi5oe n3Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711644805; x=1712249605; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5E05i/7T+/66LbTbwEqpqLwG2G09axfHnrAz+rZ83Jc=; b=kpEBJ89KIb/nXSRNTy3JoV8fs2249kOAQH3IalK2la6D94ISYFApePIlO5pYh3yY3g 64hlsLmya2DQg2sVm0u9Gy0JHKYzPPQeq0cs22zzM0yhB7dQOFCKboRDwI6NtKNctmaH O7FHfznl79nBOKuaN1etO8dLqeS0BKlkQ4Qnyy0Qi/zjd5VvcSJjcwZV1Xs5GvQyhwJp HRJFq2zfVuCcb887nAkW7iBQ/Q3318S+eZic6ixn5H+o5z2ybPi9XP88Lmiw797Zrye4 2ZUWTMhFEh/sKq/le8mz0/pt2DoubJHTi/4q8R7UfCCOwLrNf3NZLDI5c2XZAeuTZEql cBgQ== X-Gm-Message-State: AOJu0Yw8ZL49vHf18LHi4KL0C/TXilHd/GeL8i1m5BWV+0TuFI4fevzL nlgXEAbTV5z98fOp68qw4S5xPdl0COJbuwcbYoUuu7SBHXmqp9hjm/hqE1Ip X-Received: by 2002:a05:6a20:3b0f:b0:1a3:ac79:5771 with SMTP id c15-20020a056a203b0f00b001a3ac795771mr3098260pzh.14.1711644804869; Thu, 28 Mar 2024 09:53:24 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id w4-20020a1709029a8400b001d8f111804asm1822860plp.113.2024.03.28.09.53.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 09:53:24 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 Mar 2024 13:52:44 -0300 Message-ID: <20240328165250.64259-1-jamrial@gmail.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/7 v5] 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: fVFcGue+lVNg Signed-off-by: James Almer --- libavutil/frame.c | 19 +++++++++++++++++++ libavutil/frame.h | 24 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/libavutil/frame.c b/libavutil/frame.c index ef1613c344..87cc8450c8 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -812,6 +812,25 @@ 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) +{ + const AVSideDataDescriptor *desc = av_frame_side_data_desc(type); + AVFrameSideData *sd_dst = NULL; + AVBufferRef *buf = *pbuf; + + if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE) + remove_side_data(sd, nb_sd, type); + + sd_dst = add_side_data_from_buf(sd, nb_sd, type, buf); + if (!sd_dst) + return NULL; + + *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 3b6d746a16..8d16924432 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1062,6 +1062,30 @@ 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. + * + */ +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.