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. From patchwork Thu Mar 28 16:52:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 47591 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp1468018pzb; Thu, 28 Mar 2024 09:53:48 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUZ2Smn5aR1cWL+4S7llbZGqieOmEmSKglYug50NNDDL1HiJmRbwKf8ZuE72ugxb4dN5v4AxVbIb3juzn8/WWxqTDqCwOz5YrX1sg== X-Google-Smtp-Source: AGHT+IFVHOaBZi/H0mn8AexSfRz4zGs1C/n7VvrRVYhOZp8ZaDO2ypY6xJDqzzq5I9MEEdHg/s3l X-Received: by 2002:a50:ccde:0:b0:56c:2ad8:6fb2 with SMTP id b30-20020a50ccde000000b0056c2ad86fb2mr3055409edj.33.1711644828270; Thu, 28 Mar 2024 09:53:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711644828; cv=none; d=google.com; s=arc-20160816; b=ogoZCp1tYil+sarCy9+r6EjwPO3K9h53mqMfW0dIrCyemDpQyJAcSlGEgEj1gUDtTl 6cgBwqd0j3bUE3qXmMXnrcRsQRBlCRc8bOT75XcD3x+peX6eAmL4/K45TG/bOgw9Qdyk RIp8iGjqTVrhYePU9Nxdz3yP0wLhRPQwhLSCcBnPUmL6d6SlCquxzPqPT5o3InXXWcHH /hEXzkFG6KJPCneSfLaSriAiiS/ptUO4qO0Zwf4dZ5LMv8vwMlUlj1KAah3tMPgf0YsE MmIyp5uMaHwkOJWeOI5NrUF5V0ms2ASdLEBfIu3nl6CqvDHRMeXIJNpI5+SrjqiT3nfg G8zg== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=55eai4mchQ82LWKYFqBC+yJI8Wo2vcIlzf3+5Nyq6xQ=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=POGA3iUX0bpZ7YUFA7a5xA2NWXSUjDS2qU/nlTKIo2MYSh1kqfygJ9/empP577BeTK if+XIwk/90BjRWS/2CWu7FtmwW6RrKyyItnCBhmv3VyQvMgb7dxF3mLeY7ZLZ7f7BR/+ Gozzh7dtT0V+lSdZCRmA7C1m6qIOyzTUw2fn/XhCJwGN4TimJ1kGOc2ij+J4ViB0Z++4 JYLZSi/uEal9L8n+tWDf+YVjHCwvStwsrJJOvoTqc9zJBmQOeb/m2rjuPYn1Cpi0JBNo MHgrOBCgsnV8oKl+RO6ZWA7ymB0gg+y+QmR6P2wAaicWIuTbTcEjV++KgT8IQOWsk9gi VzYQ==; 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=H+udyPwk; 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 s16-20020a056402521000b0056c54031541si729585edd.220.2024.03.28.09.53.47; Thu, 28 Mar 2024 09:53:48 -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=H+udyPwk; 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 456E068D53D; Thu, 28 Mar 2024 18:53:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E90B568B4F8 for ; Thu, 28 Mar 2024 18:53:29 +0200 (EET) Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-5d8b70b39efso959025a12.0 for ; Thu, 28 Mar 2024 09:53:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711644807; x=1712249607; 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=PYGcK2X2+108ks0lYZ6SjlMCgksB/cstNas62md7b7Y=; b=H+udyPwk/sOVkXxPp8UXM+pWa2XYk45CLMnsWTW0jMinaP15z5ixMTkPnAeSFuU4SJ wZ+/bQHmbBWA4vtq2anuv7TJSma24OiMXF4eBp8EX38SfLcVt44HWSi4iWvmsmXVWwA7 x4jeYkffFNc1+njEMbe6uaDEc0Niib5G1+4u0E83JJSyVnuyyO5qnkU5L0KkLJvBtHZz DTtn4rur0k9yUQf/v2zHC4IBiWsY0l5VdXIY36n7DAMoZT+q5gG1L7gFshgoQ8YqOPRT xX7Bg/vlmgC9KVvl/oCUethvtFXC2i9TueM/6gUhZnl9WGDIFceCh4qj6XcVb2cQjspk YvhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711644807; x=1712249607; 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=PYGcK2X2+108ks0lYZ6SjlMCgksB/cstNas62md7b7Y=; b=qc2PJCUu9qj9d/UkKlW+thuoVS1+WrrPvzME4zvD9MlCMjBTNJcXz6t/9hnuh7WwLE MBf8LrHOjmjVtQzwfb8N1AMIEj7YNkqNs/FBMjNNGBKPkAl69QwblGj7rD5SQdmnW7tc 2kQHKNiYdk/cbOreIm9IDoBCMZg/OUUhddCOE9VNbso/MVUX+rRvxbPEBsnlDbr49ipk qnDrodvcwE/KHnO6z35N36Qew9irKQQDTGV/8iALn+j+kJ5cIwYCOZRRvcFJkhHmaP8/ WUAEFFwvFTMdWbgv3C/MofGiHVmKKcdJykNw3B5wE5boenIgisdQBxIlvbxfkM2Sjo7b LFrA== X-Gm-Message-State: AOJu0YyJ9PMGqImN4P18fzfmvF0AwhjXNYGept+ooWS0nSHw6S29E+SE +gq08wyRnAN2zV/egnrv028F2va37MD/lwzPs9ZvOrn2Ivcj+xrxRWHzzxa/ X-Received: by 2002:a05:6a20:6a2c:b0:1a5:6fbc:43ad with SMTP id p44-20020a056a206a2c00b001a56fbc43admr2189840pzk.57.1711644806838; Thu, 28 Mar 2024 09:53:26 -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.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 09:53:25 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 Mar 2024 13:52:45 -0300 Message-ID: <20240328165250.64259-2-jamrial@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240328165250.64259-1-jamrial@gmail.com> References: <20240328165250.64259-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/7 v5] avutil/frame: add a flag to allow overwritting existing entries 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: J1pQgqSCG6id Enable it only for side data types that don't allow more than one entry. Signed-off-by: James Almer --- libavutil/frame.c | 59 +++++++++++++++++++++++++++++-- libavutil/frame.h | 30 +++++++++++----- libavutil/tests/side_data_array.c | 52 +++++++++++++++------------ tests/ref/fate/side_data_array | 22 ++++++------ 4 files changed, 119 insertions(+), 44 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index 87cc8450c8..9c3569db0e 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -795,15 +795,36 @@ AVFrameSideData *av_frame_new_side_data(AVFrame *frame, return ret; } +static AVFrameSideData *replace_side_data_from_buf(AVFrameSideData *dst, + AVBufferRef *buf, int flags) +{ + if (!(flags & AV_FRAME_SIDE_DATA_FLAG_REPLACE)) + return NULL; + + av_dict_free(&dst->metadata); + dst->buf = buf; + dst->data = buf->data; + dst->size = buf->size; + return dst; +} + AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, size_t size, unsigned int flags) { + const AVSideDataDescriptor *desc = av_frame_side_data_desc(type); AVBufferRef *buf = av_buffer_alloc(size); AVFrameSideData *ret = NULL; if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE) remove_side_data(sd, nb_sd, type); + if ((!desc || !(desc->props & AV_SIDE_DATA_PROP_MULTI)) && + (ret = (AVFrameSideData *)av_frame_side_data_get(*sd, *nb_sd, type))) { + ret = replace_side_data_from_buf(ret, buf, flags); + if (!ret) + av_buffer_unref(&buf); + return ret; + } ret = add_side_data_from_buf(sd, nb_sd, type, buf); if (!ret) @@ -822,6 +843,13 @@ AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd, if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE) remove_side_data(sd, nb_sd, type); + if ((!desc || !(desc->props & AV_SIDE_DATA_PROP_MULTI)) && + (sd_dst = (AVFrameSideData *)av_frame_side_data_get(*sd, *nb_sd, type))) { + sd_dst = replace_side_data_from_buf(sd_dst, buf, flags); + if (sd_dst) + *pbuf = NULL; + return sd_dst; + } sd_dst = add_side_data_from_buf(sd, nb_sd, type, buf); if (!sd_dst) @@ -834,6 +862,7 @@ AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd, int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, const AVFrameSideData *src, unsigned int flags) { + const AVSideDataDescriptor *desc; AVBufferRef *buf = NULL; AVFrameSideData *sd_dst = NULL; int ret = AVERROR_BUG; @@ -841,13 +870,37 @@ int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, if (!sd || !src || !nb_sd || (*nb_sd && !*sd)) return AVERROR(EINVAL); + desc = av_frame_side_data_desc(src->type); + if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE) + remove_side_data(sd, nb_sd, src->type); + if ((!desc || !(desc->props & AV_SIDE_DATA_PROP_MULTI)) && + (sd_dst = (AVFrameSideData *)av_frame_side_data_get(*sd, *nb_sd, src->type))) { + AVDictionary *dict = NULL; + + if (!(flags & AV_FRAME_SIDE_DATA_FLAG_REPLACE)) + return AVERROR(EEXIST); + + ret = av_dict_copy(&dict, src->metadata, 0); + if (ret < 0) + return ret; + + ret = av_buffer_replace(&sd_dst->buf, src->buf); + if (ret < 0) { + av_dict_free(&dict); + return ret; + } + + av_dict_free(&sd_dst->metadata); + sd_dst->metadata = dict; + sd_dst->data = src->data; + sd_dst->size = src->size; + return 0; + } + buf = av_buffer_ref(src->buf); if (!buf) return AVERROR(ENOMEM); - if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE) - remove_side_data(sd, nb_sd, src->type); - sd_dst = add_side_data_from_buf(sd, nb_sd, src->type, buf); if (!sd_dst) { av_buffer_unref(&buf); diff --git a/libavutil/frame.h b/libavutil/frame.h index 8d16924432..4885600dce 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1040,7 +1040,15 @@ const AVSideDataDescriptor *av_frame_side_data_desc(enum AVFrameSideDataType typ */ void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd); +/** + * Remove existing entries before adding new ones. + */ #define AV_FRAME_SIDE_DATA_FLAG_UNIQUE (1 << 0) +/** + * Don't add a new entry if another of the same type exists. + * Applies only for side data types without the AV_SIDE_DATA_PROP_MULTI prop. + */ +#define AV_FRAME_SIDE_DATA_FLAG_REPLACE (1 << 1) /** * Add new side data entry to an array. @@ -1053,10 +1061,12 @@ void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd); * @param size size of the side data * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0. * - * @return newly added side data on success, NULL on error. In case of - * AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of matching - * AVFrameSideDataType will be removed before the addition is - * attempted. + * @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_REPLACE being set, if an + * entry of the same type already exists, it will be replaced instead. */ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, @@ -1080,6 +1090,8 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, * @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_REPLACE being set, if an + * entry of the same type already exists, it will be replaced instead. * */ AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd, @@ -1098,10 +1110,12 @@ AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd, * for the buffer. * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0. * - * @return negative error code on failure, >=0 on success. In case of - * AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of matching - * AVFrameSideDataType will be removed before the addition is - * attempted. + * @return negative error code on failure, >=0 on success. + * @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_REPLACE being set, if an + * entry of the same type already exists, it will be replaced instead. */ int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, const AVFrameSideData *src, unsigned int flags); diff --git a/libavutil/tests/side_data_array.c b/libavutil/tests/side_data_array.c index 793a62c009..633e9ee681 100644 --- a/libavutil/tests/side_data_array.c +++ b/libavutil/tests/side_data_array.c @@ -20,23 +20,22 @@ #include #include "libavutil/frame.c" -#include "libavutil/mastering_display_metadata.h" +#include "libavutil/internal.h" -static void print_clls(const AVFrameSideData **sd, const int nb_sd) +static void print_entries(const AVFrameSideData **sd, const int nb_sd) { for (int i = 0; i < nb_sd; i++) { const AVFrameSideData *entry = sd[i]; - printf("sd %d, %s", - i, av_frame_side_data_name(entry->type)); + printf("sd %d (size %"SIZE_SPECIFIER"), %s", + i, entry->size, av_frame_side_data_name(entry->type)); - if (entry->type != AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) { + if (entry->type != AV_FRAME_DATA_SEI_UNREGISTERED) { putchar('\n'); continue; } - printf(": MaxCLL: %u\n", - ((AVContentLightMetadata *)entry->data)->MaxCLL); + printf(": %d\n", *(int32_t *)entry->data); } } @@ -51,51 +50,60 @@ int main(void) av_assert0( av_frame_side_data_new(&set.sd, &set.nb_sd, - AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT, - 0, 0)); + AV_FRAME_DATA_CONTENT_LIGHT_LEVEL, + sizeof(int64_t), 0)); + av_assert0( + av_frame_side_data_new(&set.sd, &set.nb_sd, + AV_FRAME_DATA_CONTENT_LIGHT_LEVEL, + sizeof(int32_t), AV_FRAME_SIDE_DATA_FLAG_REPLACE)); // test entries in the middle for (int value = 1; value < 4; value++) { AVFrameSideData *sd = av_frame_side_data_new( - &set.sd, &set.nb_sd, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL, - sizeof(AVContentLightMetadata), 0); + &set.sd, &set.nb_sd, AV_FRAME_DATA_SEI_UNREGISTERED, + sizeof(int32_t), 0); av_assert0(sd); - ((AVContentLightMetadata *)sd->data)->MaxCLL = value; + *(int32_t *)sd->data = value; } av_assert0( av_frame_side_data_new( - &set.sd, &set.nb_sd, AV_FRAME_DATA_SPHERICAL, 0, 0)); + &set.sd, &set.nb_sd, AV_FRAME_DATA_SPHERICAL, + sizeof(int64_t), 0)); + + av_assert0( + av_frame_side_data_new( + &set.sd, &set.nb_sd, AV_FRAME_DATA_SPHERICAL, + sizeof(int32_t), AV_FRAME_SIDE_DATA_FLAG_REPLACE)); // test entries at the end for (int value = 1; value < 4; value++) { AVFrameSideData *sd = av_frame_side_data_new( - &set.sd, &set.nb_sd, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL, - sizeof(AVContentLightMetadata), 0); + &set.sd, &set.nb_sd, AV_FRAME_DATA_SEI_UNREGISTERED, + sizeof(int32_t), 0); av_assert0(sd); - ((AVContentLightMetadata *)sd->data)->MaxCLL = value + 3; + *(int32_t *)sd->data = value + 3; } puts("Initial addition results with duplicates:"); - print_clls((const AVFrameSideData **)set.sd, set.nb_sd); + print_entries((const AVFrameSideData **)set.sd, set.nb_sd); { AVFrameSideData *sd = av_frame_side_data_new( - &set.sd, &set.nb_sd, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL, - sizeof(AVContentLightMetadata), - AV_FRAME_SIDE_DATA_FLAG_UNIQUE); + &set.sd, &set.nb_sd, AV_FRAME_DATA_SEI_UNREGISTERED, + sizeof(int32_t), AV_FRAME_SIDE_DATA_FLAG_UNIQUE); av_assert0(sd); - ((AVContentLightMetadata *)sd->data)->MaxCLL = 1337; + *(int32_t *)sd->data = 1337; } puts("\nFinal state after a single 'no-duplicates' addition:"); - print_clls((const AVFrameSideData **)set.sd, set.nb_sd); + print_entries((const AVFrameSideData **)set.sd, set.nb_sd); av_frame_side_data_free(&set.sd, &set.nb_sd); diff --git a/tests/ref/fate/side_data_array b/tests/ref/fate/side_data_array index 7d8c684d8f..c1d77b0445 100644 --- a/tests/ref/fate/side_data_array +++ b/tests/ref/fate/side_data_array @@ -1,14 +1,14 @@ Initial addition results with duplicates: -sd 0, Ambient viewing environment -sd 1, Content light level metadata: MaxCLL: 1 -sd 2, Content light level metadata: MaxCLL: 2 -sd 3, Content light level metadata: MaxCLL: 3 -sd 4, Spherical Mapping -sd 5, Content light level metadata: MaxCLL: 4 -sd 6, Content light level metadata: MaxCLL: 5 -sd 7, Content light level metadata: MaxCLL: 6 +sd 0 (size 4), Content light level metadata +sd 1 (size 4), H.26[45] User Data Unregistered SEI message: 1 +sd 2 (size 4), H.26[45] User Data Unregistered SEI message: 2 +sd 3 (size 4), H.26[45] User Data Unregistered SEI message: 3 +sd 4 (size 4), Spherical Mapping +sd 5 (size 4), H.26[45] User Data Unregistered SEI message: 4 +sd 6 (size 4), H.26[45] User Data Unregistered SEI message: 5 +sd 7 (size 4), H.26[45] User Data Unregistered SEI message: 6 Final state after a single 'no-duplicates' addition: -sd 0, Ambient viewing environment -sd 1, Spherical Mapping -sd 2, Content light level metadata: MaxCLL: 1337 +sd 0 (size 4), Content light level metadata +sd 1 (size 4), Spherical Mapping +sd 2 (size 4), H.26[45] User Data Unregistered SEI message: 1337 From patchwork Thu Mar 28 16:52:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 47592 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp1468114pzb; Thu, 28 Mar 2024 09:53:57 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVf5vM7eQQLX3ptDNhIGGQO2YtPymDUv/tJaUNrZobsEIBxBOocEWSs6Vm9T7NMhkLBOhe7gRCUEMi/zkyOnjslr/WCnR27t2AriA== X-Google-Smtp-Source: AGHT+IHmn5WccqND27O/4TEKAZFRu8/PaZIw+tmCfNRUXjRAt3gHua8uF8Miw1Lf2GE8cdq40IPg X-Received: by 2002:a05:6402:34d6:b0:56c:5a49:731 with SMTP id w22-20020a05640234d600b0056c5a490731mr534091edc.1.1711644836867; Thu, 28 Mar 2024 09:53:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711644836; cv=none; d=google.com; s=arc-20160816; b=0yH7DBmt5ZbjY1FykjYauCsj5Or1qTiJ4hlUNCXEcoZckaJ9fIR01O06ugQoQ0P/WJ bZdPlaBrlMeZdEFMj3Q2R225SYjdGGyEerULS4ynv/Kb6dmZK+gBDz2s7aN5pvGFGfMw SrfL9T80NyjdesbGWuHtJ74u0utdsYZcFkpPlis3Qq/y2t78RDDthIFeQ8vpOzrJ00Rd 5qThCS8WDxu0aP09YjFDXvCnuGtwWMFvmJ7QfA0Oq3bEWTqRY626NoqYoeVc59JqSo92 NAV0c8aukKcjBBWgf3H8GVpgK1fNJQmhuOCe2UfZr0Rdho0Sn/m7u+QZee8+8VufPXsN 1giw== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=/P8AbIAt1TJ25MyNRkDHobmUneCK8UXk2D++SGt4nfc=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=r3cKI/jsax35jwus2l4KOkzdIeHk6K8CaGkoFfWChDffik3Swti3u3SgJ6OKB7ZkQy DSiiAIhgti132Wo3luD+NnG4IQFQJawdOgQhgNzLm2WdF2EuOxbY6wNn+7RESBiGzjzx te/UawdTfwhWRxjXZaVtW5S3cwEx2q4v9rTKi2z7vrmLh7qU/xrXDhZFBqVuyYdHoWqq 8rf2PcfkK/erwYEtIakV+tYi9xoAZx1qA/XbmG01T2rpID3OZiEiFS1jkWaVfekPtusF w32nNdrFRQt75wJxla+2OaCGPjtZkXK3SUk89SUqF7ZZRn/fCaOWYsJFYGaVWSkYS26z BvQw==; 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=CPIiURf7; 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 m6-20020a056402430600b0056bf6a7f91fsi985214edc.511.2024.03.28.09.53.56; Thu, 28 Mar 2024 09:53:56 -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=CPIiURf7; 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 3F0BA68D68B; Thu, 28 Mar 2024 18:53:38 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 717D668D591 for ; Thu, 28 Mar 2024 18:53:31 +0200 (EET) Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1def89f0cfdso17995175ad.0 for ; Thu, 28 Mar 2024 09:53:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711644809; x=1712249609; 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=2CXOi5Xmnl6ODPKl09G0iN+OyC37sEjQsh/qudo/ZqQ=; b=CPIiURf7W169TA66YXt31OmMMrBFgM50C4mX/oRBdteirXa4eR4egAFtCG+ktARZaL cV/QwSMvJXX7Juik2U3jzR5t+TZDkXoYI9S08B5zTBbIgbwhN43KeV2BbHcWmpIUkXye cRRbwX4oY608R5vJxuSmy2WUbp8vwQUeUdbySHIsRbjYVMMuHI9z24n8EtvcRgEAe5zL KIw3qZlzReXvWu9/h7TBZ6d/5AHYuYW21HyAEvjIJCg0uJSZ9O1/ry2o1Bqf35DtbIaF c3n9puDsGW7N9B+uqxAQlZ2ZixevI3LJWAnAmC8dHfYOGwB+fuUuVtBKwmSboorlY2uw IgSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711644809; x=1712249609; 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=2CXOi5Xmnl6ODPKl09G0iN+OyC37sEjQsh/qudo/ZqQ=; b=dTYAlbDg/nOpjsTR5cAU/5Oj0WFiHP+RZ5Th07Je2VHhRvk6m5ayxU8YsA6klxxKSn ykrsYEs1Px40Bz/BoY6eH/1acYXh0HQK/EWXJNF0eU+uqNXG0Ad4KSA15H37Hq9nU2py hMSo3NxtMRLXn4C7pMm+A1HJOy5tTP5CBfeXl9if7e7Qk7kSYxQevesskeIwGrzdJmfk vjGdmdO3mwUzQbSz+z97Y6MLAtIPeWgH1OvU4uoR4a/Vunrx8g4eQjjk3hp7SfizXLin 5m4xSdIecopgWzn30eH545VBovBzu4txHr+EGGKKiwFNqwwVIGW6bQpxRdgQ10/b2qg/ VkiQ== X-Gm-Message-State: AOJu0YwSQY9VNgoHDS7wGPrHwPtggMn23qvCzNsn/8jajdhqVsRvtzSS e5wGqWhleV/emA2jN7gnPdU4blgzHAPdvgufs0a1hYFL/KXs87/1Rwg5Rcad X-Received: by 2002:a17:902:e54d:b0:1e0:9d43:55cb with SMTP id n13-20020a170902e54d00b001e09d4355cbmr4032424plf.34.1711644808572; Thu, 28 Mar 2024 09:53:28 -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.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 09:53:27 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 Mar 2024 13:52:46 -0300 Message-ID: <20240328165250.64259-3-jamrial@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240328165250.64259-1-jamrial@gmail.com> References: <20240328165250.64259-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/7 v5] avutil/frame: use the same data information as the source entry when cloning 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 8aK+d62fJMh/ src->{data,size} does not need to match src->buf->{data,size}. Signed-off-by: James Almer --- libavutil/frame.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index 9c3569db0e..d37f1511e8 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -741,16 +741,14 @@ AVBufferRef *av_frame_get_plane_buffer(const AVFrame *frame, int plane) return NULL; } -static AVFrameSideData *add_side_data_from_buf(AVFrameSideData ***sd, - int *nb_sd, - enum AVFrameSideDataType type, - AVBufferRef *buf) +static AVFrameSideData *add_side_data_from_buf_ext(AVFrameSideData ***sd, + int *nb_sd, + enum AVFrameSideDataType type, + AVBufferRef *buf, uint8_t *data, + size_t size) { AVFrameSideData *ret, **tmp; - if (!buf) - return NULL; - // *nb_sd + 1 needs to fit into an int and a size_t. if ((unsigned)*nb_sd >= FFMIN(INT_MAX, SIZE_MAX)) return NULL; @@ -765,8 +763,8 @@ static AVFrameSideData *add_side_data_from_buf(AVFrameSideData ***sd, return NULL; ret->buf = buf; - ret->data = ret->buf->data; - ret->size = buf->size; + ret->data = data; + ret->size = size; ret->type = type; (*sd)[(*nb_sd)++] = ret; @@ -774,6 +772,17 @@ static AVFrameSideData *add_side_data_from_buf(AVFrameSideData ***sd, return ret; } +static AVFrameSideData *add_side_data_from_buf(AVFrameSideData ***sd, + int *nb_sd, + enum AVFrameSideDataType type, + AVBufferRef *buf) +{ + if (!buf) + return NULL; + + return add_side_data_from_buf_ext(sd, nb_sd, type, buf, buf->data, buf->size); +} + AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef *buf) @@ -901,7 +910,8 @@ int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, if (!buf) return AVERROR(ENOMEM); - sd_dst = add_side_data_from_buf(sd, nb_sd, src->type, buf); + sd_dst = add_side_data_from_buf_ext(sd, nb_sd, src->type, buf, + src->data, src->size); if (!sd_dst) { av_buffer_unref(&buf); return AVERROR(ENOMEM); From patchwork Thu Mar 28 16:52:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 47593 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp1468175pzb; Thu, 28 Mar 2024 09:54:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWJeV5Ma18S4MaTUXUIQuePYxHFypo/Kxj1jKsoM7tgTfDaQg0kYd2LXV5dtOeO39VArnpif3QGqnDmYT3sQJWK/7ByZAHKcOvb3Q== X-Google-Smtp-Source: AGHT+IGw5KSjJM18FnlN00UpdVTJJJ/tweG98ovkEB/K29OzlSqUeJYMW5aypJHgfp0uzfW3UHoZ X-Received: by 2002:a50:d71a:0:b0:565:59a:a103 with SMTP id t26-20020a50d71a000000b00565059aa103mr2545802edi.33.1711644845516; Thu, 28 Mar 2024 09:54:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711644845; cv=none; d=google.com; s=arc-20160816; b=dyWcPSQOkgx85FlsxDjjl/Uv3YKFOhTUEzB7KdQ/5+k5YlwShiRUmdo4qStDR9ncd4 RW1CD5+PTVLfllmJSjWC/eej8ZDYskWphUSLrlR+g5akT1b4xWcXZa6pwzZf3Fdr8Imj 9IpKJISQ16IV4e/KeAOzRoUFgv8BWumplOBj04WwwID3wBAICaoYugruTTmEE0N/aeMz 4UEZy0R0OcH+6ieDLyNOupMpnw5siKYgxeL8lWRUgMUzl861TXxU/NOwqLUxdU9kAcFx 5QgTL5rsTF3uC4S3L8m8E9eNawGeWHmdwOdt9x2W0ysUVLx2NnF9vDU749FxgK9KtEg1 5cog== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=Xo4tnWgsfBh0j2rKV53phLDNwrhmK1gFzcSsh8NS4sI=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=wauHNqy0UzL0KhC05OCihp53yy+k1pwVgTgIxnjt37EQ95BQYcBVLD7Czr7a2e8BWo 5vYWUFZBYKFg+zQDEtPzp42vmRU4RtGpHqk2uVQbXafzQEtY3Cai2oR/p58LrWQrcYGO gBxi2B8UpOh73LpSTNAOA6YeJiaghCNaEc1EDa6d6HiKF5jsQ42FyFrYzlLA3fHxf7Ti DzMeZwK/RKKLJGiPXQHet9zh8qYilTWEnbVAmhoavvJA/q9Cpdi3uKQsM26g0qQ4QyPb NccdPtHKBwjmI4R3QWXM8guMkPZGnfu31MckSUCrsbiwsoxUoPsW1osQQbo1IYxtXSIV Ro4Q==; 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=YTCA6hKg; 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 l13-20020a056402254d00b0056bd2b21d3esi968497edb.364.2024.03.28.09.54.05; Thu, 28 Mar 2024 09:54:05 -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=YTCA6hKg; 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 7054968D71B; Thu, 28 Mar 2024 18:53:41 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F3B8568D68B for ; Thu, 28 Mar 2024 18:53:32 +0200 (EET) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1e228c12468so1630585ad.1 for ; Thu, 28 Mar 2024 09:53:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711644810; x=1712249610; 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=OGrR2Rxl/49lu/c1oondfET2GKTVsAC8QFRN/MFqP08=; b=YTCA6hKg7jgi/R9XNeFEY+IQV/Us0SWBdeQ3tNwUp3loeIaSBzBj3fNHZHSJWP3OzA hlDxjZerWAfFc0q3kw/evJ8u3Ain8nxsU43HWGph379lH+gG8z8PgldkudzB1JHhY1l4 AWmVlCZRFbCCL+MGt//yj4HLtEAUxWLIpvo26qeb66jusjawasaQVJ87O3I15zPnBelP OxbRyez2Eyow2bG7eN9N9GvR7Tc/x0+46otA2alvES4JUYb8S8TLSpFLrpEt0T1KRiae MxJ1G0mJvQK3UXwuIzFcr/mp48trLbFD/6TZG3hb0b+okW7+xXfpeS6EVmKFYk1ksVfe BHlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711644810; x=1712249610; 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=OGrR2Rxl/49lu/c1oondfET2GKTVsAC8QFRN/MFqP08=; b=dmXgLjjQcuCETw3HyK8lvXYw/OX1UPORaC1VdP8KjxyJXEe9tYUbcgLnHV7vfpd/NO y4S+V0yma1GCiCk02PTsPG9cgHMqR9FkeY/RPa+NXRSgz4YOjRn24FCY/MhptRlwMUyR blR4WlnE6eCnhlF5wtJ0dIsbvTvL8v3wUx6fmsW4V893krwbewbpnBvF9w026baGe21w 9/mmYnRHBL/JASnW2z/+N3K/PPRYn7va7BmYj6GMwojiMR4MC0x30kGDIzIS7KFLGkU0 wlJT/rPzKECe7h3iH1Xe1ct/ckVpBw0ujXNPmexIHQMYYGXsKOUGD8oT51TQ9n3xD8sX oMnw== X-Gm-Message-State: AOJu0YzEumypZEmrwqRZkXEZjmAJQ4UoitK6MhhH0L+r7oCshwlfPmtp vT4xDw4409i3QY/6mrSvzJ0np3v9+arw2Gh4/pqcppxsFikZ8u1jwN/35fyi X-Received: by 2002:a17:902:e74b:b0:1dd:dcd3:662c with SMTP id p11-20020a170902e74b00b001dddcd3662cmr4526879plf.4.1711644810248; Thu, 28 Mar 2024 09:53:30 -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.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 09:53:29 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 Mar 2024 13:52:47 -0300 Message-ID: <20240328165250.64259-4-jamrial@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240328165250.64259-1-jamrial@gmail.com> References: <20240328165250.64259-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/7 v5] avutil/frame: add helper to remove side data of a given type from an 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: SHWZ5CBwcfQ8 Signed-off-by: James Almer --- libavutil/frame.c | 6 ++++++ libavutil/frame.h | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/libavutil/frame.c b/libavutil/frame.c index d37f1511e8..10b9f7fa94 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -937,6 +937,12 @@ const AVFrameSideData *av_frame_side_data_get_c(const AVFrameSideData * const *s return NULL; } +void av_frame_side_data_remove(AVFrameSideData ***sd, int *nb_sd, + enum AVFrameSideDataType type) +{ + remove_side_data(sd, nb_sd, type); +} + AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type) { diff --git a/libavutil/frame.h b/libavutil/frame.h index 4885600dce..68a2ad1555 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1149,6 +1149,11 @@ const AVFrameSideData *av_frame_side_data_get(AVFrameSideData * const *sd, nb_sd, type); } +/** + * Remove and free all side data instances of the given type from an array. + */ +void av_frame_side_data_remove(AVFrameSideData ***sd, int *nb_sd, + enum AVFrameSideDataType type); /** * @} */ From patchwork Thu Mar 28 16:52:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 47594 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp1468293pzb; Thu, 28 Mar 2024 09:54:15 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVp/3jmMHiJ0AnxkqTCJVg1IlzueoTtKlDEc0uuBFasMGrQliezpkWWPt9OjTgDrTg9N17Zi5qBVinZzN+Ec6ci0o5mixW+6Pikig== X-Google-Smtp-Source: AGHT+IGtH3Ld3PPywZ72xzX8Nws2x+G3sN+13DgByhL03IF9EMjiBieFLoHLFSTmnuurD0eVSNEj X-Received: by 2002:a50:9b02:0:b0:56b:b0f9:b7fa with SMTP id o2-20020a509b02000000b0056bb0f9b7famr2631268edi.2.1711644855023; Thu, 28 Mar 2024 09:54:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711644855; cv=none; d=google.com; s=arc-20160816; b=dLiRwQaNOUUrGILAY+YGB9TaVYwwxhRTdi7SJQsz9ynaSlaBbbrvAv14EuQkoWmzEv jlXx9cFV3H2GM7uvJ/GLn9gL+kCNPzOQW7eP+GNDWVCmJ+Svt0ht0hzGqByKUBFSRcKj 5PN12uwKSqSB7ZV7C63juSKWmCdJTPkzSWjYdSpRHw/yzA3RUSIE68Xb9AXHHVfRQ54A kJ9JKbsKEFYd4bgDDyYfEkZlq29O2GQ6lpWRsKd5vE8eFgiPK88jYu+P7n1NUkK9YbTQ +HENy/ZDU6PO9v5ZzUr3Ph5tyFAaDDYR/d2LTB5VKACyd22PUNCO7WfmQYHsiZLWRtHy 5qHg== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=YgUKp8LFxZ+0EaUu5fH2E29oNpSihlb4qCOADwHyR9Q=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=j6/2D+Q9KQFxrhUdF8h8ZBNi3xsW161qf01GUx9j8wUQ6zYLw4r0E9kggfZVd6Ll3M QxBnZn0Yf691PNsWxM/VLDpj+pGmHBPjt+HRyCoDvrK5SKlhW6SSMhDvZiEwVgZTRj0P wHgGORVRbxffHcw1C7GINQW6TweW7gy+3N+rM27h4ldEUriKb59wrAjx3Bz66/xRuzOD V362wavjI78EfOl5sn4x5fkgQMUIxP4AR7EYnWOJOJwRSJfllC4QMb5vS2fCPBAfNcXz G1vbn7yg+OZKiWoxvPhMgJMzyOiUczt1hP388PhTrzH4ez14ywcKZnSmrz+qv8Gp2rSj +2Sw==; 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=Ijv1yszX; 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 u19-20020a509513000000b0056bb0275c90si920789eda.368.2024.03.28.09.54.14; Thu, 28 Mar 2024 09:54:15 -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=Ijv1yszX; 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 96B4168D724; Thu, 28 Mar 2024 18:53:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 59B1868D707 for ; Thu, 28 Mar 2024 18:53:34 +0200 (EET) Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1e2232e30f4so4799915ad.2 for ; Thu, 28 Mar 2024 09:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711644812; x=1712249612; 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=cdmDbmhRfwrLuF1ItnfBTleLfF1gxKeLPb/7OhrUx1c=; b=Ijv1yszXfAqqHCn6ABW+enRCfNLJFARlnFhCPitiezDRO0o7sa8HoCFzHiJ3tC+3Of hKBJ2vTGkbfnhe+D48nm6UZ1OZnorFiD4esSR+WM2VYpXgtb8j4Jua889m3JjlffSCK+ 6qmJoYnG3h46quVVcr57r7aLNhFKKJHF1ekybVeykmi9QpZ8VPoCUV/jhH58CVmAq+hR MGr2A6xDGOmdgcHO5+e/HR1OLeUceJ/Dq/GdgEtZNpsb5UzHjNcensdk28IM+0KpucyO 4tfnP7Q/lmfxEAFwOHJMESZexEN1uPfc9kajRhZwzx8F/Fw6Fd9PfswlBUu36UpX03Uv lHLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711644812; x=1712249612; 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=cdmDbmhRfwrLuF1ItnfBTleLfF1gxKeLPb/7OhrUx1c=; b=s+G1pshTEDiP75Zm4os4fkBcrrtpEZn1sQiIgHttgLuc6kcJrElY0oVh/ToKKh/ggK 06rgRnJAZnHdsJUnU3OjTEcij3oUNfA1FKrLxCRDN0z2h/Gm6WqO6IU6tXB/qPSh7V2m IQxB2fycPrDUJWCV3g0Pd1V4bE6xuSTd/PSc2KB4woGmrgXj+SuEtebbePu56sAOcuGd te+1dnxAVQ790TSjtBPftpXnnT7UUxxY03G3w5XX51rTn0CZiKNWJqOW54Zj24hkvO4z 8mPF9shyGXdNRQrhP4v8P1L+8vKhd4DAHsLGxYYoTOUVmS3dHhbcsbmc0DLEOoEiFZhc 6I+g== X-Gm-Message-State: AOJu0Yzt+ImeWOlxPCAuEsoM2kzdyJeHSMpUJQuyNYeXvI5Glk8cxCO5 +v7GXXrf/67HFmpCAsZrm8zjc76hqpuVPEwtiDRuEzBN1wIeYSKUsYMo6vUu X-Received: by 2002:a17:902:ba94:b0:1e0:c567:bb42 with SMTP id k20-20020a170902ba9400b001e0c567bb42mr2847683pls.59.1711644811745; Thu, 28 Mar 2024 09:53:31 -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.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 09:53:31 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 Mar 2024 13:52:48 -0300 Message-ID: <20240328165250.64259-5-jamrial@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240328165250.64259-1-jamrial@gmail.com> References: <20240328165250.64259-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/7 v5] avutil/mastering_display_metadata: add a new allocator function that returns a size 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: cGj1iAX901gn av_mastering_display_metadata_alloc() is not useful in scenarios where you need to know the runtime size of AVMasteringDisplayMetadata. Signed-off-by: James Almer --- libavutil/mastering_display_metadata.c | 13 +++++++++++++ libavutil/mastering_display_metadata.h | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/libavutil/mastering_display_metadata.c b/libavutil/mastering_display_metadata.c index 6069347617..ea41f13f9d 100644 --- a/libavutil/mastering_display_metadata.c +++ b/libavutil/mastering_display_metadata.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include #include @@ -29,6 +30,18 @@ AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc(void) return av_mallocz(sizeof(AVMasteringDisplayMetadata)); } +AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc_size(size_t *size) +{ + AVMasteringDisplayMetadata *mastering = av_mallocz(sizeof(AVMasteringDisplayMetadata)); + if (!mastering) + return NULL; + + if (size) + *size = sizeof(*mastering); + + return mastering; +} + AVMasteringDisplayMetadata *av_mastering_display_metadata_create_side_data(AVFrame *frame) { AVFrameSideData *side_data = av_frame_new_side_data(frame, diff --git a/libavutil/mastering_display_metadata.h b/libavutil/mastering_display_metadata.h index c23b07c3cd..52fcef9e37 100644 --- a/libavutil/mastering_display_metadata.h +++ b/libavutil/mastering_display_metadata.h @@ -77,6 +77,15 @@ typedef struct AVMasteringDisplayMetadata { */ AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc(void); +/** + * Allocate an AVMasteringDisplayMetadata structure and set its fields to + * default values. The resulting struct can be freed using av_freep(). + * + * @return An AVMasteringDisplayMetadata filled with default values or NULL + * on failure. + */ +AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc_size(size_t *size); + /** * Allocate a complete AVMasteringDisplayMetadata and add it to the frame. * From patchwork Thu Mar 28 16:52:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 47595 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp1468355pzb; Thu, 28 Mar 2024 09:54:23 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXLcFOyJJ6T+i3TgclFFEVjjw6E0tEwtcKTnVgjSOXzLNUN3nRaLLshAIK6jjN5HQrPWAfU3EPBOByUEaeDJ5nQC1QfMGSeeg31Cw== X-Google-Smtp-Source: AGHT+IHy0HoOsH4UPn3zGCxPiyAkUWkwY4YL1v479MZKvNpDniFVgL9SDAcMUzq519sU//WZeM4x X-Received: by 2002:a17:906:2813:b0:a46:a3d1:679a with SMTP id r19-20020a170906281300b00a46a3d1679amr12827ejc.14.1711644863646; Thu, 28 Mar 2024 09:54:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711644863; cv=none; d=google.com; s=arc-20160816; b=cELLeYQuRmZ7TAcCFRbpQxWJIWQ3m4/F4Hb3M7V/9M1uo2OK4j3Ph+2Dqv31hdhmnm YIIBgHaq2apsbTHlp3KbWM2viZE/LOfw1Lc6cPyLvhJ7eS4PEAoam2RhUO6INwATho4K zIv1qU60FxMwkuARt4MooJHmt7ADRw54jCN7S2IaOp4VhcnK1CEABBcKQieqa1F8ppXT s9lkJwpV86XbagfwFTXN5E/DcLzisUzpX29ujr7uHND7ucl87B3DynmK0pMVPpP/XQXP Zlu5PhJWzuMXFgRh9f3kSGHBZ81ojfm/EVW3CPbSMSfHrdYGtQBM8o1sVsDp/QITymAK 1S+g== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=xU70jvCGAdv+XPTghGTbVnRBsadhR/Hktf1NeGgnYcM=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=b0MeYE9MR5uHKDAuNC1KANvyDyCDSndEbtfW86Bxbi+2y3dgRT1STTVOQ7U0tQegdE CBEqrJD2rTBcOTjoRSQb7Erjk+EzicANhKpsPBah0Iv1vvqX0zRD70abLrgQkvdyxzx1 QnJia4glpYLKMsJJpve68KCpdmnycU1T5YMfLjyCCqThl2GFR8nsRB5tqvWdw+6ME+ru UulYnOUiPoz8DTf5rkw1oQJNG+XbEbs7syBSo//T3GkXE+TEcVIC0HQ8yuYwbGNz+ap9 F4MyOMnj3e9ZOaYxFdBuRsebSUPk1DtKY2YePf+koDPjomsWncf8TE+DEtrTxe5Bn/jV FnRQ==; 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=HrOdRXgB; 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 x26-20020a1709060a5a00b00a4666ecd61bsi896655ejf.217.2024.03.28.09.54.23; Thu, 28 Mar 2024 09:54:23 -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=HrOdRXgB; 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 A15E568D732; Thu, 28 Mar 2024 18:53:44 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8E85A68D66C for ; Thu, 28 Mar 2024 18:53:35 +0200 (EET) Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1e0b889901bso11152935ad.1 for ; Thu, 28 Mar 2024 09:53:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711644813; x=1712249613; 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=x9qKa1umoZM/KVYEiT2Xn4Op+edIaLIoiVbekHhYHQA=; b=HrOdRXgBdRKh43OMe80snf1xMD9mzi/tp03fG1VQCHE2uuYa0o49cDKl0q32tLYOAY Ybnc8FT38YN3MgEXFwF3C3jM1PsmTpuStRXXwQtvDY5yTupgOd9ReWIc1VCacPlRaLn2 oLL9eaR9A8TFa2ZOSNXMHZcyygg/vyk8l/1afuQ+Xke4BcsuTBJnrXU0NL1A4MdK65MY CPSw4q3t0FHiASqAojCLOvh4DmSP6qKw77E0QcQm2hkSR/tfAIYn3zOAtMJpGlFi9wWz HW+g0iTDftgNQnvMM01v6s1gJPt+hxYntjTGygn4txp80C1x+2cItZ7CiEf55xdG0QKX qtlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711644813; x=1712249613; 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=x9qKa1umoZM/KVYEiT2Xn4Op+edIaLIoiVbekHhYHQA=; b=pEhSTiwJ3ZqStvdY3Z0P2YrmnGZhAVl/hht44rNK4h5S4ZjClQ8jENY95iYIMDBux/ BRznXP8vaL1aCDeqf5CmvZ8e2JmoUdqnS4PPaAyM9BSj9KcUqsWYTl3c06QEiJpQtyLc qkdxzl6eemWOwAfE1/yBQ5nRGPkmBXtOc7h1YC9H5JWMvZbwr36nz83rw10w1kLgU1hf 5whTW4Wp59SEjmPvkgiZdGe/Aa+hsac8rMvkVTde3NYsmIIxrFvo+OjjsOpVJq067MeE 5ZzNefUgg5elJ9aX0zHbvM4qC4uDsyCJf991DEioWg/qIH1pF9rqRsPYyIcXVEtkmJ7C WFJw== X-Gm-Message-State: AOJu0YyXi7JpD+ykc3hsQYnRFu3AdRm0nvbfPWGknRlYqWd9DEeVkWWC 7qT0JEYeZhAOETR/IdUGtpKzNcXxgHxKDAavMyWw2C1T4+9fPRjX2jnMoUQQ X-Received: by 2002:a17:902:654f:b0:1e0:cd88:cb16 with SMTP id d15-20020a170902654f00b001e0cd88cb16mr3047521pln.32.1711644813250; Thu, 28 Mar 2024 09:53:33 -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.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 09:53:32 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 Mar 2024 13:52:49 -0300 Message-ID: <20240328165250.64259-6-jamrial@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240328165250.64259-1-jamrial@gmail.com> References: <20240328165250.64259-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/7 v5] avcodec/decode: add AVFrameSideData helper wrappers that don't depend on frames 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: azC9t+c52yU/ They will be useful to fill arrays stored in other structs. Signed-off-by: James Almer --- libavcodec/decode.c | 106 ++++++++++++++++++++++++++++++++++++-------- libavcodec/decode.h | 24 ++++++++++ 2 files changed, 112 insertions(+), 18 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 34bcb7cc64..1f6c2a8dde 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1799,16 +1799,16 @@ int ff_decode_preinit(AVCodecContext *avctx) * @retval 0 side data of this type can be added to frame * @retval 1 side data of this type should not be added to frame */ -static int side_data_pref(const AVCodecContext *avctx, AVFrame *frame, - enum AVFrameSideDataType type) +static int side_data_pref(const AVCodecContext *avctx, AVFrameSideData ***sd, + int *nb_sd, enum AVFrameSideDataType type) { DecodeContext *dc = decode_ctx(avctx->internal); // Note: could be skipped for `type` without corresponding packet sd - if (av_frame_get_side_data(frame, type)) { + if (av_frame_side_data_get(*sd, *nb_sd, type)) { if (dc->side_data_pref_mask & (1ULL << type)) return 1; - av_frame_remove_side_data(frame, type); + av_frame_side_data_remove(sd, nb_sd, type); } return 0; @@ -1821,7 +1821,7 @@ int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame, { AVFrameSideData *sd; - if (side_data_pref(avctx, frame, type)) { + if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data, type)) { if (psd) *psd = NULL; return 0; @@ -1834,34 +1834,71 @@ int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame, return sd ? 0 : AVERROR(ENOMEM); } -int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, - AVFrame *frame, enum AVFrameSideDataType type, - AVBufferRef **buf, AVFrameSideData **psd) +int ff_frame_new_side_data_from_buf_ext(const AVCodecContext *avctx, + AVFrameSideData ***sd, int *nb_sd, + enum AVFrameSideDataType type, + AVBufferRef **buf) { - AVFrameSideData *sd = NULL; int ret = 0; - if (side_data_pref(avctx, frame, type)) + if (side_data_pref(avctx, sd, nb_sd, type)) goto finish; - sd = av_frame_new_side_data_from_buf(frame, type, *buf); - if (sd) - *buf = NULL; - else + if (!av_frame_side_data_add(sd, nb_sd, type, buf, 0)) ret = AVERROR(ENOMEM); finish: av_buffer_unref(buf); - if (psd) - *psd = sd; return ret; } +int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, + AVFrame *frame, enum AVFrameSideDataType type, + AVBufferRef **buf, AVFrameSideData **psd) +{ + return ff_frame_new_side_data_from_buf_ext(avctx, + &frame->side_data, &frame->nb_side_data, + type, buf); +} + +int ff_decode_mastering_display_new_ext(const AVCodecContext *avctx, + AVFrameSideData ***sd, int *nb_sd, + struct AVMasteringDisplayMetadata **mdm) +{ + AVBufferRef *buf; + size_t size; + + if (side_data_pref(avctx, sd, nb_sd, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA)) { + *mdm = NULL; + return 0; + } + + *mdm = av_mastering_display_metadata_alloc_size(&size); + if (!*mdm) + return AVERROR(ENOMEM); + + buf = av_buffer_create((uint8_t *)*mdm, size, NULL, NULL, 0); + if (!buf) { + av_freep(mdm); + return AVERROR(ENOMEM); + } + + if (!av_frame_side_data_add(sd, nb_sd, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA, + &buf, 0)) { + *mdm = NULL; + av_buffer_unref(&buf); + return AVERROR(ENOMEM); + } + + return 0; +} + int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame, AVMasteringDisplayMetadata **mdm) { - if (side_data_pref(avctx, frame, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA)) { + if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data, + AV_FRAME_DATA_MASTERING_DISPLAY_METADATA)) { *mdm = NULL; return 0; } @@ -1870,10 +1907,43 @@ int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame, return *mdm ? 0 : AVERROR(ENOMEM); } +int ff_decode_content_light_new_ext(const AVCodecContext *avctx, + AVFrameSideData ***sd, int *nb_sd, + AVContentLightMetadata **clm) +{ + AVBufferRef *buf; + size_t size; + + if (side_data_pref(avctx, sd, nb_sd, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL)) { + *clm = NULL; + return 0; + } + + *clm = av_content_light_metadata_alloc(&size); + if (!*clm) + return AVERROR(ENOMEM); + + buf = av_buffer_create((uint8_t *)*clm, size, NULL, NULL, 0); + if (!buf) { + av_freep(clm); + return AVERROR(ENOMEM); + } + + if (!av_frame_side_data_add(sd, nb_sd, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL, + &buf, 0)) { + *clm = NULL; + av_buffer_unref(&buf); + return AVERROR(ENOMEM); + } + + return 0; +} + int ff_decode_content_light_new(const AVCodecContext *avctx, AVFrame *frame, AVContentLightMetadata **clm) { - if (side_data_pref(avctx, frame, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL)) { + if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data, + AV_FRAME_DATA_CONTENT_LIGHT_LEVEL)) { *clm = NULL; return 0; } diff --git a/libavcodec/decode.h b/libavcodec/decode.h index 4ffbd9db8e..72a775ff9d 100644 --- a/libavcodec/decode.h +++ b/libavcodec/decode.h @@ -175,6 +175,15 @@ int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef **buf, AVFrameSideData **sd); +/** + * Same as `ff_frame_new_side_data_from_buf`, but taking a AVFrameSideData + * array directly instead of an AVFrame. + */ +int ff_frame_new_side_data_from_buf_ext(const AVCodecContext *avctx, + AVFrameSideData ***sd, int *nb_sd, + enum AVFrameSideDataType type, + AVBufferRef **buf); + struct AVMasteringDisplayMetadata; struct AVContentLightMetadata; @@ -187,6 +196,14 @@ struct AVContentLightMetadata; int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame, struct AVMasteringDisplayMetadata **mdm); +/** + * Same as `ff_decode_mastering_display_new`, but taking a AVFrameSideData + * array directly instead of an AVFrame. + */ +int ff_decode_mastering_display_new_ext(const AVCodecContext *avctx, + AVFrameSideData ***sd, int *nb_sd, + struct AVMasteringDisplayMetadata **mdm); + /** * Wrapper around av_content_light_metadata_create_side_data(), which * rejects side data overridden by the demuxer. Returns 0 on success, and a @@ -196,4 +213,11 @@ int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame, int ff_decode_content_light_new(const AVCodecContext *avctx, AVFrame *frame, struct AVContentLightMetadata **clm); +/** + * Same as `ff_decode_content_light_new`, but taking a AVFrameSideData + * array directly instead of an AVFrame. + */ +int ff_decode_content_light_new_ext(const AVCodecContext *avctx, + AVFrameSideData ***sd, int *nb_sd, + struct AVContentLightMetadata **clm); #endif /* AVCODEC_DECODE_H */ From patchwork Thu Mar 28 16:52:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 47596 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp1468431pzb; Thu, 28 Mar 2024 09:54:32 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWMLZPv0kx4rALH8Fb6EIWggxGesPV+awGZ3XdG7LERGSf4jlPo1N6NOtSeS0txevIia1c7GZvUuyUL2D6G1QoVn0pxkdkrimyWJg== X-Google-Smtp-Source: AGHT+IERBgrEKF+LXWljyvSNIwn6McQd3AYiIrKRWWGfNczsMxz8P0W2Fh9CQsoNVgqdCt8J66oH X-Received: by 2002:a50:9fa6:0:b0:56b:eb92:3d with SMTP id c35-20020a509fa6000000b0056beb92003dmr2254835edf.3.1711644872516; Thu, 28 Mar 2024 09:54:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711644872; cv=none; d=google.com; s=arc-20160816; b=wX1IzvPA+xzG5JuhdSF2pqMMqP9RrKCil5gyVNNPgtJZafr/5n6M1KrJwDuLiWdYlm fKqq8sJ+Z3zlDnXtRwrcQeTClt+M50UF/O38KpKKv5fUXfhX2U7EoO5kgHqCardkCdRE mugP+SeEbnJrcTOUJDP3+QQVcVxux2kq32egH2dUWiMvm0vVWby3OU2nkwLku03mTKOG XAAhrD/KTilLfLpHLDylfbV0KlsaMa+rC54OM2/CPVhKABXph49xLidlcqFV7VE83Ew0 9HO+JceOPEZ2Jr+3r4bxT2Tn6wSKQGLain+ZqLurvSZpG59aE0Rg7gc4aFINNbYpEsmP hh5g== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=O0RSpbbF7i0rydJbwDi4hUvI/2L8RWHMCgVVDr28nRY=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=DPGq3b2BxBNWwUAyPJ+2pS5EUo4O14z14I/X20/WVu/SsdBJbWFthG95zBKTgZt37w WIo7E4YXtNQrUmwbqKlUG3CSYwjfQ2SiaND10/hARnU3etk4Xp0LYlqfv+ZRfrGN4GhS LgWcgxL5jYVQ5j9xLU4eFY3z+5iVfAfjMAG9shkvKwQl4p0/431/VmiV5YsPg2R60tCz S4IeIeGd3nggjkWwbuWkojGSCNq3KI8gmWAGu385OAVwuadSHziyu0vnHSXG/4uAwk7b H3xOSNqPCTBJdXKvKrFkZVBRhWLtOUGmMZA3F6PaJln0GJ/+3lMoLOUf0lQZ0r1HwV86 bg3g==; 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=aW80F3mh; 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 u20-20020a50a414000000b0056c428ef9desi927700edb.142.2024.03.28.09.54.32; Thu, 28 Mar 2024 09:54:32 -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=aW80F3mh; 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 B9BEE68D076; Thu, 28 Mar 2024 18:53:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 21DAB68D71D for ; Thu, 28 Mar 2024 18:53:37 +0200 (EET) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1e2266655b1so2863965ad.2 for ; Thu, 28 Mar 2024 09:53:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711644815; x=1712249615; 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=eBzge9Da7tH+cAgH5LZTKPRamP4RxErN6wqhSUs0V0M=; b=aW80F3mhiGIRJSUXlLM88Azjvq8nKdV37FiSfgcDyjU99tEp05Y9x+gei2UvbgPto3 uIYdH0YLBVNWbkaMx78IxUoalopEGn0g54HbT+aG6O5hKtTl9DJUdb47K6ps9PgeQVLB xqNhnN4bHW2NaR2mo+G1tPTH7J3j4A9iQSrjWdUIBzAkd4G9mF/ho9u/u2jiKL/XLIZx +3wYYAbzK79kWE9nBcelQW0vS1fQ8MJwvqpK245R2ZJFO1VfmdiGePbjaNbrkVpOss9P Ppp6x3GTQlrJ5a9BtnzCbp6pOodTkP7x8p1pLyL5GH5gRu03LtHRtsBnQ3/PYLrTmMlf y80A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711644815; x=1712249615; 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=eBzge9Da7tH+cAgH5LZTKPRamP4RxErN6wqhSUs0V0M=; b=JxVRqG9db2cSiqvI7bGb/hjA5E4tyIkY+PqmZoqEfqFcQQvEl69yfn/l35U9NxcdiN b7Bby0dnrzoYHmdeQDe/YDFmweinGhdk0oiR/0SM8mIDCSI15AoZzqvsrkO2cq1WFZEk /PtP9a/EB1I7PqlFIFpr8epLWzYPo+DYocjZ6M5kVof98+PRrh+hbL2svKgV2u8IkucC r5wKAo1PSLge/sfqwGH7V8KWNaigbdE8qX/gPy723JMANW/+nRHMbW22CoAwFqTKy0Un 5R3UGTeVsNOn7hZAcjc4AuznkCUNAlWPf/dgmdYCLjMfF4L/H2iEX3ivGT8AYPfASDNI afrw== X-Gm-Message-State: AOJu0YzsdiAO2wo0xFXJ1eKZoN6ns3SA70ELkwgTtmyR1HC8/IRIJKFn WDK5SXYxVXyidm+x8tYqb9MUtIVXIM5hRmyGUnCSUYn4kEDfcCM4KjjkXBTN X-Received: by 2002:a17:902:e945:b0:1e0:afa0:cc9c with SMTP id b5-20020a170902e94500b001e0afa0cc9cmr7759pll.2.1711644814875; Thu, 28 Mar 2024 09:53:34 -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.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 09:53:34 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 Mar 2024 13:52:50 -0300 Message-ID: <20240328165250.64259-7-jamrial@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240328165250.64259-1-jamrial@gmail.com> References: <20240328165250.64259-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 7/7 v5] avcodec/hevcdec: export global side data in AVCodecContext 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: rxWF6Hjkh8Ui Signed-off-by: James Almer --- libavcodec/avcodec.h | 2 +- libavcodec/h2645_sei.c | 215 +++++++++++++++++++++---------------- libavcodec/h2645_sei.h | 2 + libavcodec/hevcdec.c | 4 + libavcodec/pthread_frame.c | 11 ++ 5 files changed, 141 insertions(+), 93 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 83dc487251..968009a192 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2071,7 +2071,7 @@ typedef struct AVCodecContext { * - encoding: may be set by user before calling avcodec_open2() for * encoder configuration. Afterwards owned and freed by the * encoder. - * - decoding: unused + * - decoding: may be set by libavcodec in avcodec_open2(). */ AVFrameSideData **decoded_side_data; int nb_decoded_side_data; diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c index afc103b69c..14a01c64d2 100644 --- a/libavcodec/h2645_sei.c +++ b/libavcodec/h2645_sei.c @@ -529,6 +529,120 @@ static int is_frame_packing_type_valid(SEIFpaType type, enum AVCodecID codec_id) type >= SEI_FPA_TYPE_SIDE_BY_SIDE; } +static int h2645_sei_to_side_data(AVCodecContext *avctx, H2645SEI *sei, + AVFrameSideData ***sd, int *nb_sd) +{ + int ret; + + for (unsigned i = 0; i < sei->unregistered.nb_buf_ref; i++) { + H2645SEIUnregistered *unreg = &sei->unregistered; + + if (unreg->buf_ref[i]) { + AVFrameSideData *entry = av_frame_side_data_add(sd, nb_sd, + AV_FRAME_DATA_SEI_UNREGISTERED, + &unreg->buf_ref[i], 0); + if (!entry) + av_buffer_unref(&unreg->buf_ref[i]); + } + } + sei->unregistered.nb_buf_ref = 0; + + if (sei->ambient_viewing_environment.present) { + H2645SEIAmbientViewingEnvironment *env = + &sei->ambient_viewing_environment; + AVBufferRef *buf; + size_t size; + + AVAmbientViewingEnvironment *dst_env = + av_ambient_viewing_environment_alloc(&size); + if (!dst_env) + return AVERROR(ENOMEM); + + buf = av_buffer_create((uint8_t *)dst_env, size, NULL, NULL, 0); + if (!buf) { + av_free(dst_env); + return AVERROR(ENOMEM); + } + + ret = ff_frame_new_side_data_from_buf_ext(avctx, sd, nb_sd, + AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT, &buf); + + if (ret < 0) + return ret; + + dst_env->ambient_illuminance = av_make_q(env->ambient_illuminance, 10000); + dst_env->ambient_light_x = av_make_q(env->ambient_light_x, 50000); + dst_env->ambient_light_y = av_make_q(env->ambient_light_y, 50000); + } + + if (sei->mastering_display.present) { + // HEVC uses a g,b,r ordering, which we convert to a more natural r,g,b + const int mapping[3] = {2, 0, 1}; + const int chroma_den = 50000; + const int luma_den = 10000; + int i; + AVMasteringDisplayMetadata *metadata; + + ret = ff_decode_mastering_display_new_ext(avctx, sd, nb_sd, &metadata); + if (ret < 0) + return ret; + + if (metadata) { + for (i = 0; i < 3; i++) { + const int j = mapping[i]; + metadata->display_primaries[i][0].num = sei->mastering_display.display_primaries[j][0]; + metadata->display_primaries[i][0].den = chroma_den; + metadata->display_primaries[i][1].num = sei->mastering_display.display_primaries[j][1]; + metadata->display_primaries[i][1].den = chroma_den; + } + metadata->white_point[0].num = sei->mastering_display.white_point[0]; + metadata->white_point[0].den = chroma_den; + metadata->white_point[1].num = sei->mastering_display.white_point[1]; + metadata->white_point[1].den = chroma_den; + + metadata->max_luminance.num = sei->mastering_display.max_luminance; + metadata->max_luminance.den = luma_den; + metadata->min_luminance.num = sei->mastering_display.min_luminance; + metadata->min_luminance.den = luma_den; + metadata->has_luminance = 1; + metadata->has_primaries = 1; + + av_log(avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n"); + av_log(avctx, AV_LOG_DEBUG, + "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n", + av_q2d(metadata->display_primaries[0][0]), + av_q2d(metadata->display_primaries[0][1]), + av_q2d(metadata->display_primaries[1][0]), + av_q2d(metadata->display_primaries[1][1]), + av_q2d(metadata->display_primaries[2][0]), + av_q2d(metadata->display_primaries[2][1]), + av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1])); + av_log(avctx, AV_LOG_DEBUG, + "min_luminance=%f, max_luminance=%f\n", + av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance)); + } + } + + if (sei->content_light.present) { + AVContentLightMetadata *metadata; + + ret = ff_decode_content_light_new_ext(avctx, sd, nb_sd, &metadata); + if (ret < 0) + return ret; + + if (metadata) { + metadata->MaxCLL = sei->content_light.max_content_light_level; + metadata->MaxFALL = sei->content_light.max_pic_average_light_level; + + av_log(avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n"); + av_log(avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n", + metadata->MaxCLL, metadata->MaxFALL); + } + } + + return 0; +} + int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, enum AVCodecID codec_id, AVCodecContext *avctx, const H2645VUI *vui, @@ -625,19 +739,9 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; } - for (unsigned i = 0; i < sei->unregistered.nb_buf_ref; i++) { - H2645SEIUnregistered *unreg = &sei->unregistered; - - if (unreg->buf_ref[i]) { - AVFrameSideData *sd = av_frame_new_side_data_from_buf(frame, - AV_FRAME_DATA_SEI_UNREGISTERED, - unreg->buf_ref[i]); - if (!sd) - av_buffer_unref(&unreg->buf_ref[i]); - unreg->buf_ref[i] = NULL; - } - } - sei->unregistered.nb_buf_ref = 0; + ret = h2645_sei_to_side_data(avctx, sei, &frame->side_data, &frame->nb_side_data); + if (ret < 0) + return ret; if (sei->afd.present) { AVFrameSideData *sd = av_frame_new_side_data(frame, AV_FRAME_DATA_AFD, @@ -728,88 +832,15 @@ FF_ENABLE_DEPRECATION_WARNINGS return ret; #endif - if (sei->ambient_viewing_environment.present) { - H2645SEIAmbientViewingEnvironment *env = - &sei->ambient_viewing_environment; - - AVAmbientViewingEnvironment *dst_env = - av_ambient_viewing_environment_create_side_data(frame); - if (!dst_env) - return AVERROR(ENOMEM); - - dst_env->ambient_illuminance = av_make_q(env->ambient_illuminance, 10000); - dst_env->ambient_light_x = av_make_q(env->ambient_light_x, 50000); - dst_env->ambient_light_y = av_make_q(env->ambient_light_y, 50000); - } - - if (sei->mastering_display.present) { - // HEVC uses a g,b,r ordering, which we convert to a more natural r,g,b - const int mapping[3] = {2, 0, 1}; - const int chroma_den = 50000; - const int luma_den = 10000; - int i; - AVMasteringDisplayMetadata *metadata; - - ret = ff_decode_mastering_display_new(avctx, frame, &metadata); - if (ret < 0) - return ret; - - if (metadata) { - for (i = 0; i < 3; i++) { - const int j = mapping[i]; - metadata->display_primaries[i][0].num = sei->mastering_display.display_primaries[j][0]; - metadata->display_primaries[i][0].den = chroma_den; - metadata->display_primaries[i][1].num = sei->mastering_display.display_primaries[j][1]; - metadata->display_primaries[i][1].den = chroma_den; - } - metadata->white_point[0].num = sei->mastering_display.white_point[0]; - metadata->white_point[0].den = chroma_den; - metadata->white_point[1].num = sei->mastering_display.white_point[1]; - metadata->white_point[1].den = chroma_den; - - metadata->max_luminance.num = sei->mastering_display.max_luminance; - metadata->max_luminance.den = luma_den; - metadata->min_luminance.num = sei->mastering_display.min_luminance; - metadata->min_luminance.den = luma_den; - metadata->has_luminance = 1; - metadata->has_primaries = 1; - - av_log(avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n"); - av_log(avctx, AV_LOG_DEBUG, - "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n", - av_q2d(metadata->display_primaries[0][0]), - av_q2d(metadata->display_primaries[0][1]), - av_q2d(metadata->display_primaries[1][0]), - av_q2d(metadata->display_primaries[1][1]), - av_q2d(metadata->display_primaries[2][0]), - av_q2d(metadata->display_primaries[2][1]), - av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1])); - av_log(avctx, AV_LOG_DEBUG, - "min_luminance=%f, max_luminance=%f\n", - av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance)); - } - } - - if (sei->content_light.present) { - AVContentLightMetadata *metadata; - - ret = ff_decode_content_light_new(avctx, frame, &metadata); - if (ret < 0) - return ret; - - if (metadata) { - metadata->MaxCLL = sei->content_light.max_content_light_level; - metadata->MaxFALL = sei->content_light.max_pic_average_light_level; - - av_log(avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n"); - av_log(avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n", - metadata->MaxCLL, metadata->MaxFALL); - } - } - return 0; } +int ff_h2645_sei_to_context(AVCodecContext *avctx, H2645SEI *sei) +{ + return h2645_sei_to_side_data(avctx, sei, &avctx->decoded_side_data, + &avctx->nb_decoded_side_data); +} + void ff_h2645_sei_reset(H2645SEI *s) { av_buffer_unref(&s->a53_caption.buf_ref); diff --git a/libavcodec/h2645_sei.h b/libavcodec/h2645_sei.h index b9a6c7587b..488dbcad7e 100644 --- a/libavcodec/h2645_sei.h +++ b/libavcodec/h2645_sei.h @@ -168,4 +168,6 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, unsigned bit_depth_luma, unsigned bit_depth_chroma, int seed); +int ff_h2645_sei_to_context(AVCodecContext *avctx, H2645SEI *sei); + #endif /* AVCODEC_H2645_SEI_H */ diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 575836e340..3d98d51249 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -3656,6 +3656,10 @@ static av_cold int hevc_decode_init(AVCodecContext *avctx) if (ret < 0) { return ret; } + + ret = ff_h2645_sei_to_context(avctx, &s->sei.common); + if (ret < 0) + return ret; } sd = ff_get_coded_side_data(avctx, AV_PKT_DATA_DOVI_CONF); diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index fd356bd190..a693e12670 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -334,6 +334,15 @@ FF_ENABLE_DEPRECATION_WARNINGS if (for_user) { if (codec->update_thread_context_for_user) err = codec->update_thread_context_for_user(dst, src); + + av_frame_side_data_free(&dst->decoded_side_data, &dst->nb_decoded_side_data); + for (int i = 0; i < src->nb_decoded_side_data; i++) { + int ret = av_frame_side_data_clone(&dst->decoded_side_data, + &dst->nb_decoded_side_data, + src->decoded_side_data[i], 0); + if (ret < 0) + return ret; + } } else { const PerThreadContext *p_src = src->internal->thread_ctx; PerThreadContext *p_dst = dst->internal->thread_ctx; @@ -767,6 +776,8 @@ static av_cold int init_thread(PerThreadContext *p, int *threads_to_free, if (!copy) return AVERROR(ENOMEM); copy->priv_data = NULL; + copy->decoded_side_data = NULL; + copy->nb_decoded_side_data = 0; /* From now on, this PerThreadContext will be cleaned up by * ff_frame_thread_free in case of errors. */