From patchwork Tue Feb 27 22:12:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 46597 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:aea4:b0:19e:cdac:8cce with SMTP id do36csp11348pzb; Tue, 27 Feb 2024 14:12:57 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXnCZIvF2zYOHcG0bLRuqVm2q56MHFxpS+4hIVORiZTv9xy6x7uWtqJg0TcP4DExHodBhAnBc8jL7+v/x1zzICXa/msGCjy6hX1MA== X-Google-Smtp-Source: AGHT+IHQsb1qEo8MtI0yuspiXFuVS8dVem85eRQ2dTRYyjdkacp5W9utKJISyiCyESfi5+BZx8Js X-Received: by 2002:a17:906:f44:b0:a3e:a712:ba9d with SMTP id h4-20020a1709060f4400b00a3ea712ba9dmr8201723ejj.4.1709071977596; Tue, 27 Feb 2024 14:12:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709071977; cv=none; d=google.com; s=arc-20160816; b=X/2H9Y/nJh8yo0/VHK6FwYVHfkswFN2M2ks8RW2LYxP6P8BN1cgc0/JUrbcY38+pWv jCbaV5b+Qukm89Hi6J3ZMqrnUAg4dMOIXJjif1thTUVkJG0gcVrToG8YdbPAzRWVGsfX lcrZ4GCSfEs6rZ1y0ml7mCrd+dxymEWTOALFAL+4n1pM8Ko1vEsfhmDhvX1ibTGhR/tq l0wNa6QqAOtY7EVtpMh2eW0xUBfEkuawp64AYGJsAUwfOJfi7bbiOJcV2HZ1jLP/bYkW Lj1ZzxJhUgYi6H9wdEVsbHn+3axme5XZlsfsFEmcGMR7/DYwv2lKDaCJIhkQ+X+WDEbu 7p2w== 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=thwHTlTgx6Xn6JS1+8bxcGXeBj1I0bDvkatVGy/xdF0=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=KeKAuF19FzkLjE+VwwUHafxs8VwShl9WaQVlLSKw1sq5xzbAVb17Ke21GW8vaa/eV8 JDSEa/Ei2rpOdWfNK660K+cTiaqnDxHOTeuV3moejgJvEbAwf6HQaY5ucQ5Djvvzzges Hnb3XAfqocgQU8NuRc3MHJ+EU1+8YUYuV9f7GTR/TLpGHxQxkbX17m6xYlHMa5CIzn3s KypAVdHfH2xbH0AHW6ymZBr7/N6xIwSDcLF6mtYNGcOxFM8wydnP7sWvJD0BeMDwWX4z b3EOW53SqcSjTyoJapba5Zs+DeLZBSz1P7Kb+fxULFFZv3aAXK4b8hKZIHfW1qlqo4fI xGuw==; 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=Q737WFR3; 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 q3-20020a170906388300b00a4320e0ec34si1110128ejd.878.2024.02.27.14.12.57; Tue, 27 Feb 2024 14:12:57 -0800 (PST) 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=Q737WFR3; 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 4B27168CB61; Wed, 28 Feb 2024 00:12:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 086F168C119 for ; Wed, 28 Feb 2024 00:12:37 +0200 (EET) Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2d27184197cso60225601fa.1 for ; Tue, 27 Feb 2024 14:12:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709071956; x=1709676756; 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=z0oik7AgsGKAGFTerOO8crnlz4XqejOv/RaXy9CdOa8=; b=Q737WFR3Ffcp0qT2i8SN0LVde4DZvqCf1P05lVXpFy6doRFTW7oSJrpdihP+Vdpy2C s49b3Fe18XRZqfro8wdR163HizdpmmKH+29mG2MV3XSXCK2CG3jA+bVs69bhJMTfBHJ4 esCq9ANUJHA0f4deCm3GaYQ8TDtKIw67LalwmUKGDCVUM+ubaxY3RlcEANkc0Gwggvhw Ishj2amd9YHypF79C/436Rkdd0zetobDm32BpHSxXjSEmRPWwBtzf38qN+HYfM08y+M/ AHW6QRQ65i/A7/K1EbFV65gtczVKnNdOU988ryBmPZgsAa3SO4yOoq6CMcbNBPzDbcEB ZXLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709071956; x=1709676756; 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=z0oik7AgsGKAGFTerOO8crnlz4XqejOv/RaXy9CdOa8=; b=v+tVoPFC/A5l3cmvnZ5/LJB2wg+DyLmQg7V2JwO6jjLGFHeMaBa2SI9NjlCKx2fP4J BY6mfYVhaWmRY6dPTDscQggmTOHkB8FXfvWCRPj7l0kTZUpcewc2ihy+Jje9cKqb3r66 nwlb++ONn1zr8xqY6hPN4gK6SZBbaW5esdARVq2tkFo5j0kMu1RDubxR3mEg0/dd4aZv vGUbwg6q7qwUc/hJrYvGD5g0NKYIiBZBGSGS666gtnxhTbw5lhdZov0dMlayNTqymsmv fF4l1qTfewYiTyKfLyOILCKmiSCQoclNyu6dGapoKaqnTddjWEmFokvhUyx5lLm/PavI isBw== X-Gm-Message-State: AOJu0YydCrkZLunZEQGlm2c+maTXYdOlXoKkvqYmOQ5gx4FiQcUhKgNB 3Qrm83Q1QWjnQ0u5YFUxeF10T2bsMnIgiivn2h2/aQJEfho8oYf54Exy5R24 X-Received: by 2002:a2e:9cd1:0:b0:2d2:a7af:f017 with SMTP id g17-20020a2e9cd1000000b002d2a7aff017mr1184963ljj.49.1709071955901; Tue, 27 Feb 2024 14:12:35 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id j9-20020a2e8009000000b002d09bc941e8sm1373564ljg.139.2024.02.27.14.12.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:12:35 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Feb 2024 00:12:04 +0200 Message-ID: <20240227221226.1377758-2-jeebjp@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240227221226.1377758-1-jeebjp@gmail.com> References: <20240227221226.1377758-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 01/13] avutil/frame: split side data list wiping out to non-AVFrame function 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: tdCqk6tFj23N This will make it possible to to reuse logic in further commits. --- libavutil/frame.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index a3f07ca089..d94710687b 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -75,14 +75,19 @@ static void free_side_data(AVFrameSideData **ptr_sd) av_freep(ptr_sd); } -static void wipe_side_data(AVFrame *frame) +static void wipe_side_data(AVFrameSideData ***sd, int *nb_side_data) { - for (int i = 0; i < frame->nb_side_data; i++) { - free_side_data(&frame->side_data[i]); + for (int i = 0; i < *nb_side_data; i++) { + free_side_data(&((*sd)[i])); } - frame->nb_side_data = 0; + *nb_side_data = 0; + + av_freep(sd); +} - av_freep(&frame->side_data); +static void frame_side_data_wipe(AVFrame *frame) +{ + wipe_side_data(&frame->side_data, &frame->nb_side_data); } AVFrame *av_frame_alloc(void) @@ -337,7 +342,7 @@ FF_ENABLE_DEPRECATION_WARNINGS sd_dst = av_frame_new_side_data(dst, sd_src->type, sd_src->size); if (!sd_dst) { - wipe_side_data(dst); + frame_side_data_wipe(dst); return AVERROR(ENOMEM); } memcpy(sd_dst->data, sd_src->data, sd_src->size); @@ -346,7 +351,7 @@ FF_ENABLE_DEPRECATION_WARNINGS sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref); if (!sd_dst) { av_buffer_unref(&ref); - wipe_side_data(dst); + frame_side_data_wipe(dst); return AVERROR(ENOMEM); } } @@ -525,7 +530,7 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif - wipe_side_data(dst); + frame_side_data_wipe(dst); av_dict_free(&dst->metadata); ret = frame_copy_props(dst, src, 0); if (ret < 0) @@ -624,7 +629,7 @@ void av_frame_unref(AVFrame *frame) if (!frame) return; - wipe_side_data(frame); + frame_side_data_wipe(frame); for (int i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++) av_buffer_unref(&frame->buf[i]); From patchwork Tue Feb 27 22:12:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 46598 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:aea4:b0:19e:cdac:8cce with SMTP id do36csp11402pzb; Tue, 27 Feb 2024 14:13:06 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVHgV90mZqMrNA+KVq377NFPF0icTnBlOLdFNzzOKcPB0+7cP8GPZOv0awqv4g5/hKOSMkkn7qyW0V2Z3myHOB1dN6Y5kyySZigew== X-Google-Smtp-Source: AGHT+IEpM9P7OgcSPomOv8bbqahiBADT+SKjNREEIdv29jF6wmP+yQqCZX19xpvbDQPGaKUlkjyg X-Received: by 2002:a50:9549:0:b0:565:4b6e:7f71 with SMTP id v9-20020a509549000000b005654b6e7f71mr8582539eda.3.1709071986241; Tue, 27 Feb 2024 14:13:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709071986; cv=none; d=google.com; s=arc-20160816; b=xtybQoZ6x2l0eZZp//dNNekyUov8GAhXskKUrp20geqCu1q4Wue6zoHnVedp8I308G 660aBO3PEEuWUPTGPSWKqwaGsVk7kPLN3RRSJJhF01wXX1beMfjqBGd676buW1My583B cAjcji0fRgVy1Is8Sq8vz3IE+w/aXFrCBe5LlU8EXqKsE8G8UsHrjOH9HufKLX9AcUwP ktU4lQO/V/VO6bBobRuzC5qvH0AXl4Et49UJWUqW8Hf34+4qq+rEqSuSn8Tt/vZEpY/9 W2dVfBwPC2UJsZqbFRBMkz2CaRXJ9W4f7/G4Un4Me5fnq41HrMSpbFVGX4xclHtpLrFa UOJw== 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=pf9tthx6KLltYLDATo5y/nXiR11h4gFqp7/Z4S2ujYs=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=dP+5vYmPMoGIMzZcGTM8o4p0ImojGRESOKVT5WY0Qe6xkNyWgUj6MU3UUBGZzF3EC4 vSbcyCvTZggSGd8lxvnS4Tpqa/pV4pnu45NuWNK+03+Tk4TEFyri7QQE8X0Zf293J7xw GomLLMbi5GlrWUsbOYQqyNP11CmkBX8ynUKL4GJMt2T3RT9o1GYxtdIiVPKbXpq5vIRm ljI/pcovRFly+EeeXv4WxeMUWtQO0lzbGwlgKnc1dYTmquyeUThV55oOd6fqulmXj293 VYg5TN4G4wFuySKlOqGD4IVw46OOaj4kMjiF8zmdsZOTYj93T371iP4vQ+0JN30iHLrt dGPA==; 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=jyIq4z+p; 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 d10-20020a056402000a00b00565ae90009fsi1025625edu.584.2024.02.27.14.13.05; Tue, 27 Feb 2024 14:13:06 -0800 (PST) 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=jyIq4z+p; 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 3209968CBD4; Wed, 28 Feb 2024 00:12:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5D7F868C119 for ; Wed, 28 Feb 2024 00:12:37 +0200 (EET) Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2d29aad15a5so15275931fa.3 for ; Tue, 27 Feb 2024 14:12:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709071956; x=1709676756; 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=AydlSf4letThiHNJqbGM7A50qax+b4WC1ievPaI0SmI=; b=jyIq4z+pWugK5LjAarRynRVcJfDC02xq5dLZRL41b5fWcCb5wticSil9oircZPojgT eVnimoL5ffU15+Es8VJl10SuNyaujLZ5fe1XIlzoaqQ9h5+xWt0mOLQ8j2dSGNHqcQiO VtEBOZz3Ye4LceAbKglgTX3dMbRmkYSPiaxw4cG1mwS7PmYRtB6zZrAXAhF6QIdDb+5c CbaLmTZ5GRAX5mEVpbADILtgptxhov9elSTxooQrjjrN7ZGXYc5deSxEafKGvf8oCEOJ WHj95VcGn8QuPTeUSVb618/cITXk07gIPO7BsV3/J4O+ScE9I3j2n7ab118xd0kkkuZE BFgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709071956; x=1709676756; 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=AydlSf4letThiHNJqbGM7A50qax+b4WC1ievPaI0SmI=; b=PpnQu7yb5ggHjarCn27uzxuXn3rdfeGhsQs0aapA1CRF4Iv+X+TP8SXm1QcvlM/ZqT Cy85/5rp0CBioIPo/n4TV9WPCgQIAZxutWy5x1Qf0YtaGuSM6f65n++U9/5dTl68Xa5U ynBqnq46kTVkouuWVYgD/zgKlvhrGt2Wx+lcitamKg8Nnz0HNbTIp7sR0iWlpq0Q5qT3 KE5AV7tWcy6cVhhnuOn4hjJAhFKa4f7+J+++n4xd6G4aYM0hczVtAYWEMydPKSdmr7B4 Y6Ks1GotOkL/FTss1Dlp96AHJwBQs6gdBzJ8qRVQUrD2yQ94OmFNoctUsJjHuaMCIU7S ioFw== X-Gm-Message-State: AOJu0YzPCs0eR8sj9lfsx6Blc+4xCBo+ZCUNDI0RV7lwxYWe2VqGGT+G YFgdtDxxrERzJW1N6AmUqk7oZWrzn9kT171Jwe1HaCfzwSX4sm5QXAkoQwrf X-Received: by 2002:a2e:b0e6:0:b0:2d2:6d19:75ff with SMTP id h6-20020a2eb0e6000000b002d26d1975ffmr6123866ljl.50.1709071956417; Tue, 27 Feb 2024 14:12:36 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id j9-20020a2e8009000000b002d09bc941e8sm1373564ljg.139.2024.02.27.14.12.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:12:36 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Feb 2024 00:12:05 +0200 Message-ID: <20240227221226.1377758-3-jeebjp@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240227221226.1377758-1-jeebjp@gmail.com> References: <20240227221226.1377758-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 02/13] avutil/frame: add helper for freeing arrays of 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: vJ5aO9GyQWw8 --- libavutil/frame.c | 5 +++++ libavutil/frame.h | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/libavutil/frame.c b/libavutil/frame.c index d94710687b..615dcb1b83 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -90,6 +90,11 @@ static void frame_side_data_wipe(AVFrame *frame) wipe_side_data(&frame->side_data, &frame->nb_side_data); } +void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd) +{ + wipe_side_data(sd, nb_sd); +} + AVFrame *av_frame_alloc(void) { AVFrame *frame = av_malloc(sizeof(*frame)); diff --git a/libavutil/frame.h b/libavutil/frame.h index c0c1b23db7..921f2212cf 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1049,6 +1049,17 @@ int av_frame_apply_cropping(AVFrame *frame, int flags); */ const char *av_frame_side_data_name(enum AVFrameSideDataType type); +/** + * Free all side data entries and their contents, then zeroes out the + * struct values. + * + * @param sd pointer to array of side data to free. Will be set to NULL + * upon return. + * @param nb_sd pointer to an integer containing the number of entries in + * the array. Will be set to 0 upon return. + */ +void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd); + /** * @} */ From patchwork Tue Feb 27 22:12:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 46599 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:aea4:b0:19e:cdac:8cce with SMTP id do36csp11450pzb; Tue, 27 Feb 2024 14:13:14 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXmdOq6HEql7ORNuktWGTPLx/2zhXFtH+VO1zsvgk+XJeMaqAXE70oMPogi+amzJFZsl/bjBy8XFRZwGs1M03aWlb06Z7ibyUn8qw== X-Google-Smtp-Source: AGHT+IFSluAaA2Sv9DMoN7/+LqFruiX6y7shBb4RW0i+GzfRDHWN8d1PhdPkO+vpkZjLQDEO8swh X-Received: by 2002:a05:6402:1287:b0:565:bc3d:f355 with SMTP id w7-20020a056402128700b00565bc3df355mr6266613edv.5.1709071994193; Tue, 27 Feb 2024 14:13:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709071994; cv=none; d=google.com; s=arc-20160816; b=StvpPchEbXzxlvrA/A+a3hsC2raC/6ke99HqWMHffDnhyV0BzCvHvNuIGQiuK4SfKP JIeZsRyNEyvjuVjDO4bx27hjUsZ6C3PG8CtQoCp4HNt8HwJRFJoB5cH3V2Bu90tJejuU v082Cs2Afyu5or4cHQci0aq0QS25uRfC7KvWrva3BlWdufmTyV5Q2jdVkmr38WIBd/oD 2JP0CPpDda+AVGZR4ZKzSa6PsfEV/6OQA1Zc6D/zmzMVeOXM4K82U/XtqnJ9UJeGmerY u6iUJzTD3opYO/XXFDpKCI7kKi0HQn3RSpupvTQQ4szsxY2vHAtOOn9yRTIOIktBnqzj iU3g== 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=8VpIKx8I/6X4qJO2UIVpuBU1NM7+phSZ6MuAVnHhHFM=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=vJ93K64GbTQPPzgU73uVXosWTgcsrk/Uhd23L34+z3JHb5yb05/EIpLnpjYT4j3smv 8+MwvqQA4WpH/B1iXIvYVkGdDR1XWtfYN8FAVxMv4sChKSLMrXSY1+y4jh4D22aMyzmX 6kgoMfxw5a7o5zSNMzu4m7OUPKQrpjqyM37sxwI/PzwQpixd3hyO2N1HD0GSfDyFlmrq tAOfQo2xvpL+mdi7wNTrYvuXhij5ByUCSDlJUjZJCNPsZhMYT6krw3l5HpFxVT7SflnO xb8zx8otJN105Y5IoKO6/eAGywaGVqI5fuG3e0P1QB4Hy6Lp0WA07bTUqFMHw7pps8es /Z6w==; 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=Lnp99Lwu; 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 17-20020a508e11000000b0056668392525si18619edw.406.2024.02.27.14.13.13; Tue, 27 Feb 2024 14:13:14 -0800 (PST) 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=Lnp99Lwu; 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 1C54D68C0CC; Wed, 28 Feb 2024 00:12:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C373068C119 for ; Wed, 28 Feb 2024 00:12:37 +0200 (EET) Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2d269b2ff48so58657001fa.3 for ; Tue, 27 Feb 2024 14:12:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709071957; x=1709676757; 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=o4HmPy+3N5aTYfhtK5ObOOjk40D1vqdjnDK3IUfS5dQ=; b=Lnp99LwuINpck1tZC3H8XJJqVKrSdUPwwFwgcf0XFMHPt4H3OtebX4wqkSRhsh+Ixg ZERkcmBgIjgN9ZZLJ+WLK05d5iAV5ndlsd+UPPkOMLCG8yuZ47ohBme7E6vCOe3tE0lo RxZgOeLGudhPqj1LyFnlVhZ2NXpr0DRm8uhG0TAGT5KmSl7CkwQCJTCDsPRVm4d8Ee+r mxQ7xBo/OwxIwh2Ud0+76/OlMg36ehskLYBjuqdT7cyPE6Qr/5mxrajilNzB7x7vMsC5 14gfM5dPmftBp1M30ZhRNhKIeTEp0rSp1MRxQnjk9Q9BGaF35Lj06ONmnd+AkT27uN8n wsYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709071957; x=1709676757; 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=o4HmPy+3N5aTYfhtK5ObOOjk40D1vqdjnDK3IUfS5dQ=; b=sMTfZ0Hcxf3wpVno9x/K/2UJpIv9ihxFZozBwYKw1LG5j9/wXDv1ucfbEDD2Qg/aaB 31RngI3urebZF29Ez7k3OWba6MItEpq963Xu+R8OzMfJJlACDqrkKliDWeCzZxqRzjVW K0UIRYg/EUBq2wQ3Bzwd1PXAnRBMv3+fmBt2l7lHgKkH+YcI7cbhcBbhlvFSFVRRG5M8 9qMq6eTsjvzbZbKs5+hF040RA84XWLkyNGwXA5idGM89jvxHE5tHVkuCDnWDsi/eRPV/ rdd3HJ6jfrGpVPl8rHb8MHTaqzcYf6G3G6y0MOaKU7rynQ18Obg534W0tyln+MkvBR05 upqA== X-Gm-Message-State: AOJu0Yx7hzqs/noN/Bt60WGSPjIR7auESMIj5QYYo82785JB/Sqki3uw CRi4EUEYCMrHq/AdT6UlQyTf/8JrHzTgT0e5bfJk3LwFvUzZLFUbbW+7BNPw X-Received: by 2002:a2e:994c:0:b0:2d2:3017:c144 with SMTP id r12-20020a2e994c000000b002d23017c144mr6964202ljj.39.1709071956829; Tue, 27 Feb 2024 14:12:36 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id j9-20020a2e8009000000b002d09bc941e8sm1373564ljg.139.2024.02.27.14.12.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:12:36 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Feb 2024 00:12:06 +0200 Message-ID: <20240227221226.1377758-4-jeebjp@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240227221226.1377758-1-jeebjp@gmail.com> References: <20240227221226.1377758-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 03/13] avutil/frame: split side_data_from_buf to base and AVFrame func 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: B3yrMmxPlfLo --- libavutil/frame.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index 615dcb1b83..5d30887ec9 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -787,23 +787,23 @@ FF_ENABLE_DEPRECATION_WARNINGS return NULL; } -AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame, - enum AVFrameSideDataType type, - AVBufferRef *buf) +static AVFrameSideData *add_side_data_to_set_from_buf(AVFrameSideData ***sd, + int *nb_sd, + enum AVFrameSideDataType type, + AVBufferRef *buf) { AVFrameSideData *ret, **tmp; if (!buf) return NULL; - if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1) + if (*nb_sd > INT_MAX / sizeof(*sd) - 1) return NULL; - tmp = av_realloc(frame->side_data, - (frame->nb_side_data + 1) * sizeof(*frame->side_data)); + tmp = av_realloc(*sd, (*nb_sd + 1) * sizeof(*sd)); if (!tmp) return NULL; - frame->side_data = tmp; + *sd = tmp; ret = av_mallocz(sizeof(*ret)); if (!ret) @@ -814,11 +814,20 @@ AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame, ret->size = buf->size; ret->type = type; - frame->side_data[frame->nb_side_data++] = ret; + (*sd)[(*nb_sd)++] = ret; return ret; } +AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame, + enum AVFrameSideDataType type, + AVBufferRef *buf) +{ + return + add_side_data_to_set_from_buf(&frame->side_data, &frame->nb_side_data, + type, buf); +} + AVFrameSideData *av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, size_t size) From patchwork Tue Feb 27 22:12:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 46600 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:aea4:b0:19e:cdac:8cce with SMTP id do36csp11515pzb; Tue, 27 Feb 2024 14:13:22 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUGCwr2RZJCJcEfaFuKB5lnFrm/CTRN6oss+aI1Cx7rcTgCpbZUyVvZ74cTsqT6DLFauHQx5Vhn/CcamDhFFVotHXJ0V7SN6o4Z8A== X-Google-Smtp-Source: AGHT+IFrihhT8zKrSsNOluxFLe4mrKO4J498Wz8rWNKkamsaRrSHZ5+7/ezhNgtOoW9lj/sS59no X-Received: by 2002:a17:907:7797:b0:a3f:79e2:49f3 with SMTP id ky23-20020a170907779700b00a3f79e249f3mr7016734ejc.7.1709072002708; Tue, 27 Feb 2024 14:13:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709072002; cv=none; d=google.com; s=arc-20160816; b=DV7oJxPEcEKxgeY8aCvTzM3+PObqr53e882CooBICnpyfPlAbufwYGqTFKHRLULlxr 4a7vkYzMHYTPGfsqJlTHlZvX7O3TaRJMRcIHwddvsOcmAZUiitAzh08blK6tJTx0UgXQ FACowJSMygOAP5lGoFpwU+sr7OBYq8z9cr+CjgwKMwxsqAYZSmh5u8IuT4o2zeC0zCY1 9mt9FQ5eiKlIZky008294fMhcYeoc/GlfIPrF/AlL9m25kNrHWL7omgvlYkdDRQMdiEo qRcSYNMJuT1KPNizegoCN2W/WD9ds2R6oUWu8VPvsKAa45CvK/eMhkCBzbfSZskjfS/k vz5w== 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=/bGklkXrUyTjVl2w+BuThn8qXDeHnynN8rfNCzwBA90=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=dGfkT/+36FXSQ6NsUD67N2Zva5vLNkvrJANPpsJRrmtLcJ8CDPUhoJyDkIkZflkSiM qjAlmCbo/7qemKkk20rvX7OwxUNnFDB+ZiSB+Igd/8PTifJ+gOmzMiTlMHP6JQJKvEKc 7MQpNZHq9+IE40G3gxdHv/JZpkcKNr3p24uDXWuMZryQbW6dMBfcq3S7/14rY8fZsxOW W6JFsrRpLrRC4y2G64tDHAbI7jHnzaBTZRxt9wCaIZh2LwvNUlopBjvQKGnVYFMNxveb m8J3/IVWLvxHNOl0jjr9d8cvticcEhJ7ofucEXZS2chkzKv2Q6oGzCWl7S8BmwGat4KY F3iw==; 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=DTfaOnB5; 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 q16-20020a1709066b1000b00a432149ff40si1067610ejr.108.2024.02.27.14.13.22; Tue, 27 Feb 2024 14:13:22 -0800 (PST) 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=DTfaOnB5; 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 2934168CCFE; Wed, 28 Feb 2024 00:12:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5E8E568C7DF for ; Wed, 28 Feb 2024 00:12:38 +0200 (EET) Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2d180d6bd32so68830091fa.1 for ; Tue, 27 Feb 2024 14:12:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709071957; x=1709676757; 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=Dn+4UEHGNEyBz7sjUlV1HmM4IFv1exSCYMnSbYygO34=; b=DTfaOnB5GRcHPgOG5YmS5Tynmrd9JS6l2WjaSjNCZDImhZ/wd2gAQ16i6lA+QRJNJJ RVieXnq2EZwPqot1IPK8KpVByyUYlH5fbjRjNPxqrjTX6+vOiCs1QtdpPJXQct2eUw8N 4fIraZUHLwB0DebegQ3TLkiXCMZnVIAeWhDdDYre2lBJ0ckekvjiwiXqkZMBJ40FZvol 1QtHxJWg251tSPl5KAHrf4pIBibmX5vvcUwSoLnUmPNQglnbedY4iB+aTB8X9LAjAq3d apqng6BkxPQZ7m0qZYHny4tal8UcRickM+RFI/0TUzK/42n6eO/lat6WsYHQVnW60ll4 U/Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709071957; x=1709676757; 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=Dn+4UEHGNEyBz7sjUlV1HmM4IFv1exSCYMnSbYygO34=; b=uAMNx8acBxlSLW81PNBof2gyO12dWi/em0X24DPV3a0XC36MHAJY3iKYIAXT3VDXTs s7oY3a/oCASfVBP7MNc0pkg9DDyoUSJT8IuCp/DWcB4dQXWvAfxBKTbRsYnzJKJ/P0Hg 25JiTRS7HLhs2/omD0yNJszHUgyUArjVJdOibiatGMcFjp+ozkR0RJaBLI1SlKoPa7h0 Juj9bxBiq/QcouueNAR6GeP4fW/2IImUGH6SURm5QOvlz1b2BJz22Fj+Lg1v7hbhlWLO e40twt6VELYGScWbgZ2A5ggTdVEEJuIfLRxrDBykYgseHytcWPAbhUCvwHwTx9UgJg7w Tl/Q== X-Gm-Message-State: AOJu0YxqN/sxjz8OfLTvdO9bkXqBHOALfkfqxK+0AFfw+aKKdMeMwAiJ xN3w04/A4qPnvLv9Sax+sGl8/BRtgggCotf30KEKzOzs/aMFCQfgko26gmk5 X-Received: by 2002:a2e:a724:0:b0:2d2:b915:e073 with SMTP id s36-20020a2ea724000000b002d2b915e073mr308823lje.27.1709071957250; Tue, 27 Feb 2024 14:12:37 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id j9-20020a2e8009000000b002d09bc941e8sm1373564ljg.139.2024.02.27.14.12.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:12:36 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Feb 2024 00:12:07 +0200 Message-ID: <20240227221226.1377758-5-jeebjp@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240227221226.1377758-1-jeebjp@gmail.com> References: <20240227221226.1377758-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 04/13] avutil/frame: split side data removal out to non-AVFrame function 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: jcGkZnANZuj0 This will make it possible to reuse logic in further commits. --- libavutil/frame.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index 5d30887ec9..788999bdeb 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -95,6 +95,21 @@ void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd) wipe_side_data(sd, nb_sd); } +static void remove_side_data(AVFrameSideData ***sd, int *nb_side_data, + const enum AVFrameSideDataType type) +{ + for (int i = *nb_side_data - 1; i >= 0; i--) { + AVFrameSideData *entry = ((*sd)[i]); + if (entry->type != type) + continue; + + free_side_data(&entry); + + ((*sd)[i]) = ((*sd)[*nb_side_data - 1]); + (*nb_side_data)--; + } +} + AVFrame *av_frame_alloc(void) { AVFrame *frame = av_malloc(sizeof(*frame)); @@ -937,14 +952,7 @@ FF_ENABLE_DEPRECATION_WARNINGS void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type) { - for (int i = frame->nb_side_data - 1; i >= 0; i--) { - AVFrameSideData *sd = frame->side_data[i]; - if (sd->type == type) { - free_side_data(&frame->side_data[i]); - frame->side_data[i] = frame->side_data[frame->nb_side_data - 1]; - frame->nb_side_data--; - } - } + remove_side_data(&frame->side_data, &frame->nb_side_data, type); } const char *av_frame_side_data_name(enum AVFrameSideDataType type) From patchwork Tue Feb 27 22:12:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 46601 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:aea4:b0:19e:cdac:8cce with SMTP id do36csp11576pzb; Tue, 27 Feb 2024 14:13:31 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV9Z0tlx2V6iK+F9LXBoaCW2fjGF3/xVXzPqhfgcPzr1ftp3ETgBnZSWiMBrPfgmXooUAN9IjW3afvg984jd8naVDH9D7LYNpWA/Q== X-Google-Smtp-Source: AGHT+IGFcSw54fit3DwFOsVg/G4BoEl8ArflFOmJcHRWkHQfz3ituY65QPAGYaQCR8SI/mKDHUhT X-Received: by 2002:a17:906:a05a:b0:a3e:69ff:141f with SMTP id bg26-20020a170906a05a00b00a3e69ff141fmr588664ejb.33.1709072011563; Tue, 27 Feb 2024 14:13:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709072011; cv=none; d=google.com; s=arc-20160816; b=bHvFEQOb4FpxAr9AZEpfvpMPHSMs1hJSEXHeIfNMRbv7QZOT6NqTSHGJw/ALbaL+G+ ySMehdBMnMHqnj4G5P+Yy0Ygsiz8nq2D1x4FZJpYyhZYiRW0qX75R6WMybTAeM+wHtxn URxoE0vZLcSLwGabnWbkgYY2W16TsIqGo5AmmUKrlwTcYTX0Io/vLqz1lhsXJiVIEXJt oenso/U5T95L2wPBo+Ve5F47R0DRBboXBZjjQnUXyrdK4tTMY2dHRElP91qTdKdu+nYH NIENzSnxpg+P9C0wVt924Y5sC28OrWEkwbT/AO8TpCBfPGhyYnEEgCtkgF2rXKeCfeAH /6ag== 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=KtjYYRcD7BNsofjq+6VIt1QgQBCMUvmIx0vsz6gAST8=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=uPOmQmVXzVPgsCiVdWdWp15kzQDFQMBnIslg3e+lGQ9C38yUWJeVn6HQhvX3E3FOJ9 eQbk364iwCApNeY4n/vxV4+IamsborGM881Y4ICtxlQQsm0UyrxqfffvC3zLz9zN2h9e bhot8tQldwY9kxhIRBH9aGhzhegKzD3/tmzjpM60tc7tJlIzlYzMnUNof9zuQ7eb7yo6 dZZHLcMpgCqTtJqZ/CZkrkDO0ym+2BpT/xXYFXKUWNbZDaLO4np/CiV1O5NFZ1nAZp92 iqCryyfMyYMiaj9tkthaH8A+H8N0wqZgJ6Vv7GbpkIefKsT6NfwTPvIE+w4V4UW+qHFV dogg==; 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="emMyu/bG"; 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 cf13-20020a170906b2cd00b00a3d01994ccasi1076564ejb.268.2024.02.27.14.13.31; Tue, 27 Feb 2024 14:13:31 -0800 (PST) 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="emMyu/bG"; 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 1F7C668CD66; Wed, 28 Feb 2024 00:12:52 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BB57768C8A3 for ; Wed, 28 Feb 2024 00:12:38 +0200 (EET) Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2d2991e8c12so2546951fa.0 for ; Tue, 27 Feb 2024 14:12:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709071958; x=1709676758; 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=kLLYRtWVJDOXVKfBSwXv52sKZJrznINFeVr+gr/G+a4=; b=emMyu/bGlKjzxOD7MBgeYnflNvoqbBmN7A1TvSYspLEIcicmpp/VMFmnwELtBaMHDp dNgXo5iKNaVd/6PnUeKJaJNPTOsNZfrAwNtgsbwwbEVftuOTDQwGdxPsnH/pc5xuZfE+ 7kiln45JSrnZme8ItMGiAoyneUTFO5SXfjiFjMv1riqOSj3kPLp8C8qt7cjCf9CjAjSB MtYZFax+Lyc0TlT2I5HboPm0LODxOOGc73MD5NDTAxL+NaRe3lgE4gs10w0613ELgxSR y4PZSGVRnxId3Act0JmtXus8gwUSXuErZr/4N3UkvNVTExAJ+2osGeX/WcXU9lpKC9mB /WRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709071958; x=1709676758; 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=kLLYRtWVJDOXVKfBSwXv52sKZJrznINFeVr+gr/G+a4=; b=URbLCL/Esas5xNHyOWy/vcknpFoy/r294oFbxiGmOzaxKsXWRYRkZ8a1os/kvIYLdP 6VdfKEnbKVJuIJ1fQXwdGcIHfB8eYKDNiohyREaGgnjG5xfKQ1pqMshBEg+V7T6dh6rh 4udDVKyuDPYxpXhPZsm0GAHfZU0N2eeeiPpxS9e/X8rMbBisehDRbacI+nb4TI0C0CZL D8dKqtmqWFcXXkt4H7hFcZIjMRmKrl79Us/Zg5mHcKJyipjM08k9kz/ipv6jtqKFgtUE rilqlKV9Nz1ULMJ55teM9XByQBg5Kb2zdJYONuruaUwnJ8FCAmKcStpF5fu/b+ThlVju CWRA== X-Gm-Message-State: AOJu0YyV+owLCVxTDlkZlX8VwFI67K90opICQqneQW6LSk1Pa0WX72Yc oGXRW+anV7vG49oFs9okPmfmNLWk86FD1XYzWRKzfO80xSl8wxoJ9ERPewG3 X-Received: by 2002:a2e:91d5:0:b0:2d2:3c72:f67d with SMTP id u21-20020a2e91d5000000b002d23c72f67dmr244935ljg.1.1709071957721; Tue, 27 Feb 2024 14:12:37 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id j9-20020a2e8009000000b002d09bc941e8sm1373564ljg.139.2024.02.27.14.12.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:12:37 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Feb 2024 00:12:08 +0200 Message-ID: <20240227221226.1377758-6-jeebjp@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240227221226.1377758-1-jeebjp@gmail.com> References: <20240227221226.1377758-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 05/13] avutil/frame: add helper for adding side data 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: Velt6pJ4Xqqb Additionally, add an API test to check that the no-duplicates addition works after duplicates have been inserted. --- libavutil/Makefile | 1 + libavutil/frame.c | 17 ++++++ libavutil/frame.h | 21 +++++++ libavutil/tests/side_data_set.c | 103 ++++++++++++++++++++++++++++++++ tests/fate/libavutil.mak | 4 ++ tests/ref/fate/side_data_set | 14 +++++ 6 files changed, 160 insertions(+) create mode 100644 libavutil/tests/side_data_set.c create mode 100644 tests/ref/fate/side_data_set diff --git a/libavutil/Makefile b/libavutil/Makefile index e7709b97d0..4415c913a1 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -271,6 +271,7 @@ TESTPROGS = adler32 \ ripemd \ sha \ sha512 \ + side_data_set \ softfloat \ tree \ twofish \ diff --git a/libavutil/frame.c b/libavutil/frame.c index 788999bdeb..d9741240e7 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -855,6 +855,23 @@ AVFrameSideData *av_frame_new_side_data(AVFrame *frame, return ret; } +AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, + enum AVFrameSideDataType type, + size_t size, unsigned int flags) +{ + AVBufferRef *buf = av_buffer_alloc(size); + AVFrameSideData *ret = NULL; + + if (flags & AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES) + remove_side_data(sd, nb_sd, type); + + ret = add_side_data_to_set_from_buf(sd, nb_sd, type, buf); + if (!ret) + av_buffer_unref(&buf); + + return ret; +} + AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type) { diff --git a/libavutil/frame.h b/libavutil/frame.h index 921f2212cf..726ca19a03 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1060,6 +1060,27 @@ const char *av_frame_side_data_name(enum AVFrameSideDataType type); */ void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd); +#define AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES (1 << 0) + +/** + * Add a new side data entry to a set. + * + * @param sd pointer to array of side data to which to add another entry. + * @param nb_sd pointer to an integer containing the number of entries in + * the array. + * @param type type of the added side data + * @param size size of the side data + * @param flags Some combination of AV_FRAME_SIDE_DATA_SET_FLAG_* flags, or 0. + * + * @return newly added side data on success, NULL on error. In case of + * AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES being set, entries + * of matching AVFrameSideDataType will be removed before the + * addition is attempted. + */ +AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, + enum AVFrameSideDataType type, + size_t size, unsigned int flags); + /** * @} */ diff --git a/libavutil/tests/side_data_set.c b/libavutil/tests/side_data_set.c new file mode 100644 index 0000000000..7ef99db3d2 --- /dev/null +++ b/libavutil/tests/side_data_set.c @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2023 Jan Ekström + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include "libavutil/frame.c" +#include "libavutil/mastering_display_metadata.h" + +static void print_clls(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)); + + if (entry->type != AV_FRAME_DATA_CONTENT_LIGHT_LEVEL) { + putchar('\n'); + continue; + } + + printf(": MaxCLL: %u\n", + ((AVContentLightMetadata *)entry->data)->MaxCLL); + } +} + +typedef struct FrameSideDataSet { + AVFrameSideData **sd; + int nb_sd; +} FrameSideDataSet; + +int main(void) +{ + FrameSideDataSet set = { 0 }; + + av_assert0( + av_frame_side_data_new(&set.sd, &set.nb_sd, + AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT, + 0, 0)); + + // 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); + + av_assert0(sd); + + ((AVContentLightMetadata *)sd->data)->MaxCLL = value; + } + + av_assert0( + av_frame_side_data_new( + &set.sd, &set.nb_sd, AV_FRAME_DATA_SPHERICAL, 0, 0)); + + // 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); + + av_assert0(sd); + + ((AVContentLightMetadata *)sd->data)->MaxCLL = value + 3; + } + + puts("Initial addition results with duplicates:"); + print_clls((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_SET_FLAG_NO_DUPLICATES); + + av_assert0(sd); + + ((AVContentLightMetadata *)sd->data)->MaxCLL = 1337; + } + + puts("\nFinal state after a single 'no-duplicates' addition:"); + print_clls((const AVFrameSideData **)set.sd, set.nb_sd); + + av_frame_side_data_free(&set.sd, &set.nb_sd); + + return 0; +} diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak index 80153f4395..6864ea9c03 100644 --- a/tests/fate/libavutil.mak +++ b/tests/fate/libavutil.mak @@ -148,6 +148,10 @@ FATE_LIBAVUTIL += fate-sha512 fate-sha512: libavutil/tests/sha512$(EXESUF) fate-sha512: CMD = run libavutil/tests/sha512$(EXESUF) +FATE_LIBAVUTIL += fate-side_data_set +fate-side_data_set: libavutil/tests/side_data_set$(EXESUF) +fate-side_data_set: CMD = run libavutil/tests/side_data_set$(EXESUF) + FATE_LIBAVUTIL += fate-tree fate-tree: libavutil/tests/tree$(EXESUF) fate-tree: CMD = run libavutil/tests/tree$(EXESUF) diff --git a/tests/ref/fate/side_data_set b/tests/ref/fate/side_data_set new file mode 100644 index 0000000000..7d8c684d8f --- /dev/null +++ b/tests/ref/fate/side_data_set @@ -0,0 +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 + +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 From patchwork Tue Feb 27 22:12:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 46602 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:aea4:b0:19e:cdac:8cce with SMTP id do36csp11640pzb; Tue, 27 Feb 2024 14:13:40 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWv3zoN+1u1GLIuMjJQn639MbvAN5A/yQAoa+SxoHBhjPIxBSwMNWouNiZFzqV2wtrIyT5Kqpp7Ovzv05DWomFXfBv8ast/R62qrQ== X-Google-Smtp-Source: AGHT+IFBr+xGU+yZX9smOvOjaE/Tmq/HezFq2FPvJ5LGgcN3MUJGFMdkdnsMxCMrb4Y+kn3EQsEM X-Received: by 2002:a05:6402:2045:b0:564:2518:adfd with SMTP id bc5-20020a056402204500b005642518adfdmr8523026edb.10.1709072020517; Tue, 27 Feb 2024 14:13:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709072020; cv=none; d=google.com; s=arc-20160816; b=SPEsYfdL+vHFofpZlZchUIvWZx0wVivkLvBDEs2wEb2inav5b4jkMCNnaA/j7ru8kT Jed6XKJHLOfxPy+9XhvfOBlhvFM4ZMGzpYEKYjbTcTM+yuKdjyGRgNiibi3Cwza7iphx EJrDgLadLB0akrYEKNG4YaYDihnTfP23tFNsyFdIXHV3CAUzjWiq8w+kCWZu1qGk5D9B H0kHiy9/RzAAqDrZOzlx1LRFNUEdDmUvzeB6QR302mWX6jwphAOLsIXVFQuIYJ+wYY2L i3WY5J4b8CwP+vIERppw9EUIithjvfc1LybBOlJPiZBVnYc0yZm6BiAxzbgJbxRJcKHm oIBg== 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=XWwpM+IBo2jW1LsDqaAk/T5qaaekTwvi4xYBEd5WgjY=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=cxltrrB24GMISXuO2d/Og++eeZ2hL6h9HGSKOp0st88NgNES9Nb3ahsyR9R9ylLxJf 4DeIhMrdpci/AAGTSM64vE4v0wt1ClFAUC73R1wIwGh4CRUktsIrxIBFENebjo8czHcr acthl0y7LfffUnvzpIWMN76X2pK1rqvsGGA58KACI1kjyR87pIpTvXX5H244kSKT+rm0 Fyh81a2UhKjJC8D81wHSK7qDUPJN2hLKT8qBNp4Smmjr0+J2+MkhjjOO8v21RzSzStwR pm07Rdp1qlYDO017TlQjfaOxoCwaGFKuNam/++bDAAFrdRf52zLLRlbwLgid10m4i918 bRBQ==; 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=QELIuUaJ; 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 a2-20020aa7cf02000000b00565d73c1abfsi1054078edy.377.2024.02.27.14.13.40; Tue, 27 Feb 2024 14:13:40 -0800 (PST) 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=QELIuUaJ; 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 5B74768CD82; Wed, 28 Feb 2024 00:12:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 17A4968C90C for ; Wed, 28 Feb 2024 00:12:39 +0200 (EET) Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2d2ab9c5e83so8163131fa.2 for ; Tue, 27 Feb 2024 14:12:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709071958; x=1709676758; 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=vhn7IWOA6TqBRotDdGGMhAh/TknQqUqcU+LVsSZg4xU=; b=QELIuUaJI4nDKH3Q17zfRkw+aVb5lQXdaS77LdRv+Kl3lR3EP8tY1srgHt8lSqqxou KAUFzgTkKE7PVu+nQq3wWS63W/P56p/z7XdPBkqm9WdImBGLY6h95htyQY/OwqM2apm6 pLH6MlwMxzBTWjZzw64JtX0naCy0C2usXZWBQUrKyd/n3uacmB3RVEupshjw/OtX+Btl gBlXY4qq2Mm6yEdx9M2xsoxwI7zCAYM2KyVYOhHXpWIGbKcFzGvBzXsI6ZuC1urNfnz6 Cjcu/hde9sN0shic74WivUwvcFc/kdLPfJeamAx+znFD7khHfkwZLUxR/3brHsIRgATg I+AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709071958; x=1709676758; 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=vhn7IWOA6TqBRotDdGGMhAh/TknQqUqcU+LVsSZg4xU=; b=izXBy3w3H8A2IU5BEo/SmNz3E29NvR2aeHqMYp3jWZYi4VipMKl7x52AonoVmeaU2h ayNsFSlj1ueVpg8ISsOBlggcaDa+fK7ubEjq2/+XGCfqM3GmG9S7C5lWYCMP7u/SdR+N eoLet6uFvsm5mg1FexehvkPQrUnB4XZgZBmqjdye4qvkqaPdx0ZLNzljJbSTPyUyy7Ml VgjJcw4hMIYUSOY6FVfE41HPPdz5rmLw/q4E/+bfexLhKJwc3qONsgnHBkLn94XaHiVs 2kAzo8Y5n2hWKvTE7u+MnZUO6+bmCUF1sg+9ArnzrDyt8etsLqc9qTnJzyv6Nt9lbP3M oVjg== X-Gm-Message-State: AOJu0YxxsFGKAMxIddhWp4E4hrtVJASsFcuz7qf6B4DvRJtnl5Bag+9q 3iAG8Dla67z4WRm5IXw1C+Uh6k4lLxP8rZapvxOHwMVcpGh6cWwXdAc0eQ6Z X-Received: by 2002:a2e:be8e:0:b0:2d2:864c:8220 with SMTP id a14-20020a2ebe8e000000b002d2864c8220mr6910212ljr.5.1709071958153; Tue, 27 Feb 2024 14:12:38 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id j9-20020a2e8009000000b002d09bc941e8sm1373564ljg.139.2024.02.27.14.12.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:12:37 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Feb 2024 00:12:09 +0200 Message-ID: <20240227221226.1377758-7-jeebjp@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240227221226.1377758-1-jeebjp@gmail.com> References: <20240227221226.1377758-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 06/13] avutil/frame: add helper for adding existing side data to set 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: 8K/Lg7794vBT --- libavutil/frame.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ libavutil/frame.h | 19 ++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/libavutil/frame.c b/libavutil/frame.c index d9741240e7..99c9ce4119 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -110,6 +110,23 @@ static void remove_side_data(AVFrameSideData ***sd, int *nb_side_data, } } +static void remove_side_data_by_entry(AVFrameSideData ***sd, int *nb_sd, + const AVFrameSideData *target) +{ + for (int i = *nb_sd - 1; i >= 0; i--) { + AVFrameSideData *entry = ((*sd)[i]); + if (entry != target) + continue; + + free_side_data(&entry); + + ((*sd)[i]) = ((*sd)[*nb_sd - 1]); + (*nb_sd)--; + + return; + } +} + AVFrame *av_frame_alloc(void) { AVFrame *frame = av_malloc(sizeof(*frame)); @@ -872,6 +889,38 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, return ret; } +int av_frame_side_data_from_sd(AVFrameSideData ***sd, int *nb_sd, + const AVFrameSideData *src, + unsigned int flags) +{ + if (!sd || !src || !nb_sd || (*nb_sd && !*sd)) + return AVERROR(EINVAL); + + { + AVBufferRef *buf = av_buffer_ref(src->buf); + AVFrameSideData *sd_dst = NULL; + + if (flags & AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES) + remove_side_data(sd, nb_sd, src->type); + + sd_dst = add_side_data_to_set_from_buf(sd, nb_sd, src->type, buf); + if (!sd_dst) { + av_buffer_unref(&buf); + return AVERROR(ENOMEM); + } + + { + int ret = av_dict_copy(&sd_dst->metadata, src->metadata, 0); + if (ret < 0) { + remove_side_data_by_entry(sd, nb_sd, sd_dst); + return ret; + } + } + + return 0; + } +} + AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type) { diff --git a/libavutil/frame.h b/libavutil/frame.h index 726ca19a03..47d0096bc4 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1081,6 +1081,25 @@ 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 a set based on existing side data, taking + * a reference towards the contained AVBufferRef. + * + * @param sd pointer to array of side data to which to add another entry. + * @param nb_sd pointer to an integer containing the number of entries in + * the array. + * @param src side data which should be added to the set + * @param flags Some combination of AV_FRAME_SIDE_DATA_SET_FLAG_* flags, or 0. + * + * @return negative error code on failure, >=0 on success. In case of + * AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES being set, entries + * of matching AVFrameSideDataType will be removed before the + * addition is attempted. + */ +int av_frame_side_data_from_sd(AVFrameSideData ***sd, int *nb_sd, + const AVFrameSideData *src, + unsigned int flags); + /** * @} */ From patchwork Tue Feb 27 22:12:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 46604 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:aea4:b0:19e:cdac:8cce with SMTP id do36csp11679pzb; Tue, 27 Feb 2024 14:13:48 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXKahU84i5M9xE5fHwP7W8sdxnpkNIBXlPgYkenlsuZ9XeO18436ATf4A1JetHpJ23DvKNCZ2cdazHrsWu0YVxLIlT29ZO17aICmw== X-Google-Smtp-Source: AGHT+IF1x21ib+bHXRGkmMFv9YMGTxl7jRqKatm9hYkibH64rJabrVBRGImTmgr8dNYMrkE2WA2q X-Received: by 2002:a05:6402:5153:b0:566:66cc:633c with SMTP id n19-20020a056402515300b0056666cc633cmr75396edd.7.1709072028620; Tue, 27 Feb 2024 14:13:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709072028; cv=none; d=google.com; s=arc-20160816; b=zmSbJSYbpDcE0AW3Z6d+AwX/w3P0lxo0hPQkCCe1Rd5lr4X3Oyz/e+gEui+eSmVzEl /MnzwLCb9mtDh8rIPIAJ7NqvIRclfY5yDt7vaww4UsbQPwFWUKD8vJ+KS7eaXZP/x1+5 mwvzAeDNcUFEkvRRMjQnOvGNmTfjoRsyqz/p40Vw/W5JlNMnRi4xB9L8TEbBr9Ea/rzo VLXebNd4yo7YGz9c7V8H3lZ/+3mIqwW5mo0DvEsbMvYGYfoykkQ1I5ElihHkzUYJFKD5 3L/jJ4riE02/AWfj8yFFVuQTUEMEpVXMYDPy2T81oVEzwE5y63bVAlJhlu8arjNVxNSq oX1Q== 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=2oTz61mIx81tjJzLwhlghg5vmSmj7ulq+EF0GSDbFJ4=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=H8gfgCxLB1v4oGiS047PKZeb0pZwooWsBh9eFWNNIJgpuU9ZSKHnYuzoEQsHbowCH9 /xl1DfUAZq5HOsOiL/Bc+9mAUI3ZRPEEOol51oRhHtjzOr23RkkGm3hbtJ/0H2Vxx/kR 24rcaxwISwqkwFJvApT1gmNYqd63DSidbdU0FppUlG9it/Q2uyEFxjGfq6btbOZ+RMYg 6iR2nc5troVdarwNws/eHyVXCdjgPwmpdIB1nDIgREcq6OSt5ZkRnq9eK7d2VxPc6iZy WP7HfA3ysI0WxpfF9WUk16B2zoomR0+pg7esjyXsoOtxI/SEVZykxy0kE4agLn05WyJL bU6g==; 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=Js3kb5W1; 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 t28-20020a50d71c000000b005645ee8e9f5si1095466edi.639.2024.02.27.14.13.48; Tue, 27 Feb 2024 14:13:48 -0800 (PST) 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=Js3kb5W1; 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 8DC7A68C8F1; Wed, 28 Feb 2024 00:12:54 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B14A168CA1A for ; Wed, 28 Feb 2024 00:12:39 +0200 (EET) Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2d27fef509eso45488401fa.3 for ; Tue, 27 Feb 2024 14:12:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709071958; x=1709676758; 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=SRViwMZmL6BF+MLzeVFgqw1Z53adVywNqfTCQRn1wcE=; b=Js3kb5W1OJvxQNaVWm0DkdsPi5xEe8xyrg6b/ArGV3cSxpy/Wbr5TX4XZkxrDzbhBn 6FwsLiOH5N0bcWkkVs0KV1pYhiEQTVK/wF2cczPggl+kR0KIAziZR28t7oqS02I8ecqj M/nkunKNxq2G51KzsaCPrK7BOIB8mh//nxjZK1y+mXWOMG0e1AfAXIVYl3dSKgfpAACN SnK6spUnqf76Xsy52FqaZAK8VeCHYagTRkmg0Dh/kV/RoCFBoijRDVNGecPpufb27ChV m2a8KklKaBBtwd85ZUrxGPPM0ZhaXRth8JhINRsZjPAA2QtU5htFnv3SA9fZlkJ8ecUQ wcsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709071958; x=1709676758; 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=SRViwMZmL6BF+MLzeVFgqw1Z53adVywNqfTCQRn1wcE=; b=XOk++m33tfKH4ssDtW/IS9SlxyFq6ufqQIdQga5eu3JOC5N/uNrT8k7A7kKTsef+gx 4ScCVhwcuawfah6BcrUHh8NDQtjpqlF5lYTnT7X14DJUNjf64pYDAHzk/iTiHtzadEdB rLnLPnzXcWtZCNORO9z9Yv2X0aRRoXhCxXY9qRDm7++B37hHhbi2b3lBZnGwD+XjRgMH B1SfM+Ji3Dt8CoPqBL8+pxpAMbw+ftKTuXL3U2dV3N59VwV6BgEaEaXSzy7b0vYJGxVG f814I9PIw68Jz/1isQR3Kan7HOm81ZquXDgYcwTSAc68N2cpgG8CYMDxcNwqm6T0h3Zw mblA== X-Gm-Message-State: AOJu0YzmOF5E6JpVt5hpiijOI8uOGeqvUHKgcXi51rkv986iHyO4GkTC 14u/RDTm+HVwLT5+V/0NjUUy7Ee7kfXRWw7einWKRRc/owE6e/Zuyl+fU6Od X-Received: by 2002:a05:651c:1201:b0:2d2:66bf:2c1d with SMTP id i1-20020a05651c120100b002d266bf2c1dmr6432770lja.2.1709071958600; Tue, 27 Feb 2024 14:12:38 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id j9-20020a2e8009000000b002d09bc941e8sm1373564ljg.139.2024.02.27.14.12.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:12:38 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Feb 2024 00:12:10 +0200 Message-ID: <20240227221226.1377758-8-jeebjp@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240227221226.1377758-1-jeebjp@gmail.com> References: <20240227221226.1377758-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 07/13] avutil/frame: add helper for getting side data from 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: Qe4QPkbEqCn8 --- libavutil/frame.c | 20 +++++++++++++++----- libavutil/frame.h | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/libavutil/frame.c b/libavutil/frame.c index 99c9ce4119..e7679bf34d 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -921,16 +921,26 @@ int av_frame_side_data_from_sd(AVFrameSideData ***sd, int *nb_sd, } } -AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, - enum AVFrameSideDataType type) +const AVFrameSideData *av_frame_side_data_get(const AVFrameSideData **sd, + const int nb_sd, + enum AVFrameSideDataType type) { - for (int i = 0; i < frame->nb_side_data; i++) { - if (frame->side_data[i]->type == type) - return frame->side_data[i]; + for (int i = 0; i < nb_sd; i++) { + if (sd[i]->type == type) + return sd[i]; } return NULL; } +AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, + enum AVFrameSideDataType type) +{ + return (AVFrameSideData *)av_frame_side_data_get( + (const AVFrameSideData **)frame->side_data, frame->nb_side_data, + type + ); +} + static int frame_copy_video(AVFrame *dst, const AVFrame *src) { int planes; diff --git a/libavutil/frame.h b/libavutil/frame.h index 47d0096bc4..751f7a67d6 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -1100,6 +1100,20 @@ int av_frame_side_data_from_sd(AVFrameSideData ***sd, int *nb_sd, const AVFrameSideData *src, unsigned int flags); +/** + * Get a side data entry of a specific type from a set. + * + * @param sd array of side data. + * @param nb_sd integer containing the number of entries in the array. + * @param type type of side data to be queried + * + * @return a pointer to the side data of a given type on success, NULL if there + * is no side data with such type in this set. + */ +const AVFrameSideData *av_frame_side_data_get(const AVFrameSideData **sd, + const int nb_sd, + enum AVFrameSideDataType type); + /** * @} */ From patchwork Tue Feb 27 22:12:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 46606 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:aea4:b0:19e:cdac:8cce with SMTP id do36csp11780pzb; Tue, 27 Feb 2024 14:14:05 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWylQjfJxbhAA4YkHfvhuu9jYHK6A/zrzx0y/vIFz+2luPwhWM6skX8cC73bcATceAjQj14QUgAt4VcZqfurcneO2ej8oTKSfGg3g== X-Google-Smtp-Source: AGHT+IGZfZoodqxQwhWSiV9yaY9WI5ejEULb3z6KGDU39OuBCSSC38aKz1nz64L2eQvVmwcWdxW2 X-Received: by 2002:aa7:c0d6:0:b0:565:e4b7:e784 with SMTP id j22-20020aa7c0d6000000b00565e4b7e784mr4632365edp.40.1709072045099; Tue, 27 Feb 2024 14:14:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709072045; cv=none; d=google.com; s=arc-20160816; b=rPzEI5cg3lt0T7CM7TiOtxsD5op5jc9dSD4q5gEA/FDEt+fzwpg36bWWOzlOEwf1HZ tlcU6HT22sD7CdS5s3wXi4+PHRWiehGGJlM1fCvo/NEvEePUpJK3fiOnSZDddc+pjBlQ qRzmzivS55XJT+HCp/Clvj7jS2DGmPGUGPmCbm9BkPwebBX/jxjpwEyHYV3kxX9vQzR1 FT4aVNOfyAjMVwRvIZcqjmG0qzugHABYBuLLyNbiNIbCKDawrPj6Ga4rF1F96QwnXuSf sESWdQGnqO2YDZXI2niezbwPpNfFYMH5RqROsIZjktAtte4UFvU4U1AXwfXD5XRbHkUF 88VQ== 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=m2I5Ebzs52+rIiI8KihHi1ipRpSl6ZPTRx4p5XmRpps=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=HmtczshEydBKt+eWkwkiczIi6KdF9IeB70P5ZmdmN81PfsyWSkqRCuxnvAvjkRA9JF kFaoISJgrbDk+tM+QXR+kgD0bj2F+ptRd2ZxZ1po/AKcXHR40Q1CWQxssbvx7O2DWrcn 6hNKz1IBOh8QWlMzwEBRxCysQsXNqa7s1DgJfHFnwTaymHOX3gRQ5WvP/ZCIr6hgYPYS /BeoVWyWnA0z/WxkOrrnBYq4/wvAZ1yngfkbpTX1g3UbS6qCL2uXimk+3zdMbRz3kKj9 WHvG3o5piOi+SIfO3OBQMo+BjoPWCM1BoHg7ey69ffxWImOXUglrmq2hW+3sPKazLExl VdAg==; 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="kp/1hG1L"; 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 c14-20020a50d64e000000b005664fddf5dbsi441210edj.278.2024.02.27.14.14.04; Tue, 27 Feb 2024 14:14:05 -0800 (PST) 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="kp/1hG1L"; 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 8F8DB68CDF3; Wed, 28 Feb 2024 00:12:56 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DCE2868CAC9 for ; Wed, 28 Feb 2024 00:12:40 +0200 (EET) Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2d180d6bd32so68830441fa.1 for ; Tue, 27 Feb 2024 14:12:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709071959; x=1709676759; 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=X2Bi+4AI8dKxyKwmzmkmjL5rg1BswwJgZ+zRdZmnPq0=; b=kp/1hG1LjMMqhmygFeHn4q1U0U46Vx+ZrwSK6RJ0hjz4C5u8YPUqclAczRXRK6spqt eQWdkkxW2SvFqfMDOCJ06oQ4drKJ9/Dr9rDTu1YjXLzcuZOizFrZeqkDMJvUkBR4ISpM luuPi6SzXPny0tULItga4Zb8epwIAXOe8/sLUw33E9O7INhpk1Clvr4bD/KgMaOVTAO3 39WEtlyZpgb+YtExfHnZdSiIQ3YABVmvbP3MSw2yWgirYilkHwsB4NsRiQ+Uf506q2is 3h3SoUVjSK0b8eYxb1XhkblaARlDp/sA9pta90kKa77+rbqxpXHN5hEDl8v5P7RfN8AE 5rag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709071959; x=1709676759; 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=X2Bi+4AI8dKxyKwmzmkmjL5rg1BswwJgZ+zRdZmnPq0=; b=LdHK5sHRJf+lDlRElmheH5ZRk2JlOGb0Ri7ESJyCe7G3RndQlwG5ZjEkQfgQSK5P6Y F9A4Vbojd+IC3MP8exPeb2IfEuCWD6iPQHLFMP3lK+iVMiRP77NrZ2Zw8I7gF684p20m 2/n+5d6S3ykhNODe/yLKyIy56NHkuJWrDhu3wg2EaI7AorsO+5u89oOxDdBK7yFSQh/B k3S1pRKS8WPGVeTBkmTJ27IA5tBqXxwIc/RmDmhq3nCHlydJ7pyXYGmiMShqgl+V9I8O TFhgYybVjJ3wRGpvh3GU6e1XsNiP9eTOCgJVGFhVYPkJC68otsiZyB4WpsLYJXNmyuSn IVYg== X-Gm-Message-State: AOJu0Yxx3QwLCCuLZxYRYCqfJrq4UA+HG30kgdVVYxLZ31nQoYVK/JfR +dbOJ5eD3z9t2pNxATCrbXYdIMBEmDKTL6Lf45GdCRUl2CHa8FL2GFFRM4ki X-Received: by 2002:a2e:b0f1:0:b0:2d2:b245:2f9 with SMTP id h17-20020a2eb0f1000000b002d2b24502f9mr671830ljl.36.1709071959141; Tue, 27 Feb 2024 14:12:39 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id j9-20020a2e8009000000b002d09bc941e8sm1373564ljg.139.2024.02.27.14.12.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:12:38 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Feb 2024 00:12:11 +0200 Message-ID: <20240227221226.1377758-9-jeebjp@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240227221226.1377758-1-jeebjp@gmail.com> References: <20240227221226.1377758-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 08/13] avcodec: add frame side data array to 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: 2e5EBLp8xxJv This allows configuring an encoder by using AVFrameSideData. --- libavcodec/avcodec.h | 8 ++++++++ libavcodec/options.c | 2 ++ 2 files changed, 10 insertions(+) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 43859251cc..411f4caad3 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2120,6 +2120,14 @@ typedef struct AVCodecContext { * an error. */ int64_t frame_num; + + /** + * Set containing static side data, such as HDR10 CLL / MDCV structures. + * - encoding: set by user + * - decoding: unused + */ + AVFrameSideData **frame_side_data; + int nb_frame_side_data; } AVCodecContext; /** diff --git a/libavcodec/options.c b/libavcodec/options.c index 928e430ce9..7e39b49b7e 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -181,6 +181,8 @@ void avcodec_free_context(AVCodecContext **pavctx) av_freep(&avctx->inter_matrix); av_freep(&avctx->rc_override); av_channel_layout_uninit(&avctx->ch_layout); + av_frame_side_data_free( + &avctx->frame_side_data, &avctx->nb_frame_side_data); av_freep(pavctx); } From patchwork Tue Feb 27 22:12:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 46605 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:aea4:b0:19e:cdac:8cce with SMTP id do36csp11734pzb; Tue, 27 Feb 2024 14:13:57 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCX+Ms96kXC0zvTumQ7eYD95PqInFgftA+jgyxFYxB1jQ1E0Tn+RF8h3svCBiU+ZA8PiBn+AOIQCAy2u+z/YoArAijEm0yLhuDIoZA== X-Google-Smtp-Source: AGHT+IHxgjMNS/psO6QTGJI8Gh8cVPsmfxxwbcR8AW3t5sHBEzhFfhqZ+/wi4wkOpoYGLGfVMap/ X-Received: by 2002:aa7:d7c3:0:b0:565:a5aa:22e7 with SMTP id e3-20020aa7d7c3000000b00565a5aa22e7mr580839eds.2.1709072036888; Tue, 27 Feb 2024 14:13:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709072036; cv=none; d=google.com; s=arc-20160816; b=Cr3k6xK0if7jXN5xzrXqqamsXHuzXqevkylIbgjd/sjqeNQnjhF4u+qxNvyv3FG68P HZDRDaOKEaJG4nbMj4ZJd0TfgO9ex890WBx9Bq6e0SEQElUYWDZFElzGfa4KrCOuf0VE RAWErHkSpSBkC60TqFIs+l9A2ZG3N6vXEj4v0OcMkbr+hAtrrABk28oLV6NIGbJwXfOo SBS/lcRQhYROtGc45oH6NN6w2ZCqDZMa8x0PZQGImTUITsl9aIFHz4JW749eS3G++r/7 PgmHT+wMt4+jcfR5BrYKeSVJ7lQsjPNlsIeRzIhKBPTu2RXSjv3e1WQiO0KnwC+/xbi6 G7lg== 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=m7HXuQvimPwLk3S57EVZdwPs0pq+6KJ7jpphTP8wXRM=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=HRZrO+kLU3EkO23bTjogpDsbI7fT980EajIOQYWau1Yj6bfADwgDdW8hSxjx1LZyZj yxb5Uzm+BGNkSppc5jSyqO65a4Ir4eoX/Tk4GumQf56G6C935EPW/+LaAGKUW19Tck/V sky64vpS/VkIMvS2FHPzK8TBSGqyRU1Sb0ddLAdvtOKuXiw6muZqtXWX/87dlNu5Xsnj y+7/bsHrG+MtnxezP2fKUXFa5O9zMWdx2e0Lmjm0W71YptaDc4rbV2K8SWS9prob0WER s9l4WGGn/RQim3b65CJu3vuhqSXCuYbeb0I4Qa1XhZgstgbPa1jM0+1YxYUFK05o0mYJ 6q+Q==; 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=JNpc7Oy1; 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 w1-20020a056402128100b005643bf20cf2si1073452edv.272.2024.02.27.14.13.56; Tue, 27 Feb 2024 14:13:56 -0800 (PST) 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=JNpc7Oy1; 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 9E45768CDBE; Wed, 28 Feb 2024 00:12:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DD14B68CACC for ; Wed, 28 Feb 2024 00:12:40 +0200 (EET) Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2d2991e8c12so2547161fa.0 for ; Tue, 27 Feb 2024 14:12:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709071959; x=1709676759; 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=jjIz9BARMumrQkOyfM5DQUenPk8Hig/J3i61SB+xDmo=; b=JNpc7Oy1DuoFetAz5rKWrmRNGXd2q7FSg0A6ftDROxWJVN0uqjLlX33d37vZq3kkp5 6yjVwIBAG2f3I5FEodKGOQdjl3izCZ8lSCKouTNQ9vfjydY0ar1Ke8iY8HlSxiZLCnGT mfOiNfAz4CJvB1YLCf1aqpxmdGsOSFyRE3okxEdYw/yPQmNWhbEFi+qpjf2uYQxbf39Y bIUSyF0+/WUVZ/x+Pimtl2r3ZI1yM7x8cQiHtKNKC9a+fc7EXvQFj7mtlZvdfR2jUpPW p7qvFjstAIsR7bFmrMMwRfInLyBF4IUuiC539hbOp4BzBXixS3yMIPvXhFcBN+VKZ5TF DOPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709071959; x=1709676759; 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=jjIz9BARMumrQkOyfM5DQUenPk8Hig/J3i61SB+xDmo=; b=Inb/H0OglV+l5Dx5rFGgGWpsUBwlvhnGWpVzSeR5KsCJPy73QxbgVcFPrB3fvJ9QpU GgbE+/Ir+pQddY9koOLYe9psIszbE340tpmBcGo2tYg+LwcNRcDEzjAXXXPF/gAtk/i1 BnXIkYAwMofDWlcdEldR05EdVxANWC1+/MCtTK0GFrEPZ9xTqv9eVPIMwihnvtGkHWUd FfhGcSy94gMPPb9T4GrQ2UDKZWL8kRWXIBEeDTBUTRZlo+uBMYS+lJm0B/nP9124Iv7L J2+ASV9e1L3DuxbMjJD+RxGTxENF3KshSk+cb5lvJh5UD0K7/1+htOKjYzybcJE172j3 k8NQ== X-Gm-Message-State: AOJu0YzS7cAmgIB2e8c3GIzQxJPDqIQ9NINcErr2GX3IjDUSe0dh8ux1 zbgYVS24JdZf1R8a1Ae+GY8tCbt6cGGiLfywgnEoDvElR/7IeuLIwz2uFOqc X-Received: by 2002:a2e:3315:0:b0:2d2:a9a4:c3f8 with SMTP id d21-20020a2e3315000000b002d2a9a4c3f8mr201286ljc.15.1709071959562; Tue, 27 Feb 2024 14:12:39 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id j9-20020a2e8009000000b002d09bc941e8sm1373564ljg.139.2024.02.27.14.12.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:12:39 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Feb 2024 00:12:12 +0200 Message-ID: <20240227221226.1377758-10-jeebjp@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240227221226.1377758-1-jeebjp@gmail.com> References: <20240227221226.1377758-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 09/13] avcodec: add helper for configuring AVCodecContext's frame side data X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: lXRNtlr09KpQ This allows API clients that wish to configure multiple entries at a time to do so without writing the looping code themselves. --- libavcodec/avcodec.c | 30 ++++++++++++++++++++++++++++++ libavcodec/avcodec.h | 20 ++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index a13b781996..d3ec41b280 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -720,3 +720,33 @@ int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr return ff_decode_receive_frame(avctx, frame); return ff_encode_receive_frame(avctx, frame); } + +int avcodec_configure_side_data(AVCodecContext *avctx, + const AVFrameSideData **sd, const int nb_sd, + unsigned int flags) +{ + if (!avctx) + return AVERROR(EINVAL); + + if (!sd) { + av_frame_side_data_free( + &avctx->frame_side_data, &avctx->nb_frame_side_data); + return 0; + } + + if (nb_sd > 0 && nb_sd == avctx->nb_frame_side_data && + sd == (const AVFrameSideData **)avctx->frame_side_data) + return AVERROR(EINVAL); + + for (int i = 0; i < nb_sd; i++) { + int ret = av_frame_side_data_from_sd( + &avctx->frame_side_data, &avctx->nb_frame_side_data, sd[i], flags); + if (ret < 0) { + av_frame_side_data_free( + &avctx->frame_side_data, &avctx->nb_frame_side_data); + return ret; + } + } + + return 0; +} diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 411f4caad3..3b5ca9c0ef 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -3162,6 +3162,26 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size); */ int avcodec_is_open(AVCodecContext *s); +/** + * Add multiple side data entries to an AVCodecContext set in one go, for + * example from an AVFrame. + * + * In case the function fails to add a side data entry, it will clear the + * whole side data set. + * + * @param avctx context to which the side data should be added + * @param sd array of side data to use as input. + * if null, clears out the side data for this context. + * @param nb_sd integer containing the number of entries in the array. + * @param flags Some combination of AV_FRAME_SIDE_DATA_SET_FLAG_* flags, or 0. + * + * @return negative error code on failure, >=0 on success. + * + * @see av_frame_side_data_set_new_entry regarding the flags. + */ +int avcodec_configure_side_data(AVCodecContext *avctx, + const AVFrameSideData **sd, const int nb_sd, + unsigned int flags); /** * @} */ From patchwork Tue Feb 27 22:12:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 46607 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:aea4:b0:19e:cdac:8cce with SMTP id do36csp11833pzb; Tue, 27 Feb 2024 14:14:13 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVea09FFcpuz1ghbncPfM/A1vhLXcKKy4goKxGWuYCpwH0GiMBKWpbaBhuHamy2x3wa62j39I3tgmRkxXbv5xa49D+1tVRo4TXVpg== X-Google-Smtp-Source: AGHT+IGJ7njqDP0TTA9WEIS8HdinCL0XEYMtUKx89GuNT6XexZF5BEC93oRoIO+6qdBulGb/L7Tf X-Received: by 2002:a05:6512:3a82:b0:512:fd90:b4e1 with SMTP id q2-20020a0565123a8200b00512fd90b4e1mr4839974lfu.5.1709072052981; Tue, 27 Feb 2024 14:14:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709072052; cv=none; d=google.com; s=arc-20160816; b=EUtiEn1di6Z14nXdtxNXYH4s5PSt91t8Fy8gtKfQ0QMwCttiURI5k+6PylCGiM0KUJ A6TdfiINkomx9N66I+X6bx3tqH960SdAC/csqoWcUpnRJa6TXUaxjl7aga95XCewtSw6 IHIKPsU8HJGLRhf08hWJqUJSgrXA9G58wXQkZt/BC2+Ic5TvjTNhfe6Ejol6GmjnJNXm Ki7HDcZ+9S9r40WMq62H8AMpBWs2qEQo+WDNTt0zFiRE+JwMMMG9XXyX/EeyvNDrJjgp tZfQ/hcszVgW83k5z2zQ15wJ61XJBXO1xQ/Mxfs5k2WHNefa6oYyntG/MbEJtQmLWCBg XZOg== 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=8+IbzwMNQRRajJfdDfuynHZKKdn6D9YsrgKmPuANVN4=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=udGGGYPgFY+sYMe4+THl5T0kYU3NUcor/TG9+MJH2HWxZfAM8R9fqEQq/iMVLy8XQl S3rYgg64XgD5XSCqghoDEVc8hLo591rWjvjwwvZcc8QpHNXNsL05LZlwAKrGWJmbboLq KBr1URpBoq69o0C4SjpBMO2tuwKmghibSZOn6GbAKHPVJco+aqPUZlzbGHVULbzvvno4 VfeeatcZsgFaRrEJBj/I2DHZ0ltPiA6uQC/dXfgm1/HeNwC0ENFdfeLvrJ1VgvrUCkYc fh7cMn0I3CK4sV4yVni4sLQx1QazGWeEqTbkq4xpdKnat1KqlMEqz2CbbwN8oc0I9PS4 njhA==; 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=iGBxg8fS; 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 qw6-20020a1709066a0600b00a3e41c54c12si1027892ejc.12.2024.02.27.14.14.12; Tue, 27 Feb 2024 14:14:12 -0800 (PST) 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=iGBxg8fS; 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 A160B68CE0C; Wed, 28 Feb 2024 00:12:57 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E7FD068CACE for ; Wed, 28 Feb 2024 00:12:40 +0200 (EET) Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2d28051376eso46738091fa.0 for ; Tue, 27 Feb 2024 14:12:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709071960; x=1709676760; 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=uX+oR2akcxZ8UMxUtS21Up7aAnWZwudiiFc59F+0fOU=; b=iGBxg8fSEjq2oqMuMNqv98RJFWP9z/khr0xgc/N+Z0ijUiYe9jYPFnVHjl9i+Wvqfm DgYUuCuUwtZDxcJC/99XpRLgmXZAMWbfBm+SN6QOaulv3G0tNSgV7IVo+jR+kWkwOrbr xtoi2TQed8PqnakIxK0tmWqEHieWwBriaUja/MUqyo0YcvPvQyeByJlOUXuqH2wU56mL HDHGQpuQvldl8p272tSsQiVySJqtZDSQ61gMO/ALeuSACMq9Of87hQE30d/OZsRNIoVp 8b3rT8iJTYZZWRhH4LdGwy2UpGxXt4WLva6WsO7ifbKTkH2i8F5wBL0sMd8cg1W0BNSU u7Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709071960; x=1709676760; 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=uX+oR2akcxZ8UMxUtS21Up7aAnWZwudiiFc59F+0fOU=; b=fKoyBhBC6M+wwNGfJcRU37vuaArknc/3mIS0luBZgJbDyYluvd7+Td2H1WzBSGE9A8 MANy5h7Ie4nGmqUIfexnJBM2lLmRIYS2wWiQzEZAV4s96pjhdeTOe42KyZJ402hAF+Hl UEmz57qgXSjJh2AllYwUDgmmt/8xOJxdSmxFqCdsYPXVZmhOf6gtrUqYdeqpqzuUCupq i7NpheWgxkWItpY1bY1pRPaGzWig/BnNhYdgTCEg6DOaJ81YUxAxsC4GeKE+KPCiJeBM W2Ulu4KDMshOuLCKeZsm4Jb5zozPu25SJ4QvW+6gIoOwiRgbByUX7MbNrHz5oc6PLRDz EtHQ== X-Gm-Message-State: AOJu0YwA+99EcNC6h+wn1EpvkB7okhhs6vURh0znyOTd8KsB+Za8xe0K jgP1hTtfraDt6fJoR6nXJeVgWew1ii+diF95bPxWP8h+hNlUy9Vu48FXWHox X-Received: by 2002:a05:651c:38d:b0:2d2:3018:4cdf with SMTP id e13-20020a05651c038d00b002d230184cdfmr5642530ljp.23.1709071959991; Tue, 27 Feb 2024 14:12:39 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id j9-20020a2e8009000000b002d09bc941e8sm1373564ljg.139.2024.02.27.14.12.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:12:39 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Feb 2024 00:12:13 +0200 Message-ID: <20240227221226.1377758-11-jeebjp@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240227221226.1377758-1-jeebjp@gmail.com> References: <20240227221226.1377758-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 10/13] ffmpeg: pass first video AVFrame's side data to encoder 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: cLop8AltgGm0 This enables further configuration of output based on the results of input decoding and filtering in a similar manner as the color information. --- fftools/ffmpeg_enc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index bdba50df03..e39ba05b3b 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -245,6 +245,16 @@ int enc_open(void *opaque, const AVFrame *frame) enc_ctx->colorspace = frame->colorspace; enc_ctx->chroma_sample_location = frame->chroma_location; + ret = avcodec_configure_side_data( + enc_ctx, + (const AVFrameSideData **)frame->side_data, frame->nb_side_data, + AV_FRAME_SIDE_DATA_SET_FLAG_NO_DUPLICATES); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "failed to configure video encoder: %s!\n", + av_err2str(ret)); + return ret; + } + if (enc_ctx->flags & (AV_CODEC_FLAG_INTERLACED_DCT | AV_CODEC_FLAG_INTERLACED_ME) || (frame->flags & AV_FRAME_FLAG_INTERLACED) #if FFMPEG_OPT_TOP From patchwork Tue Feb 27 22:12:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 46608 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:aea4:b0:19e:cdac:8cce with SMTP id do36csp11887pzb; Tue, 27 Feb 2024 14:14:21 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXox28boLQdh2xIz5nDc3eJiPP7iIUQGeQxe7Zeef0oCcJmxYF0O/bGoGE00wJnEm2kw8wbzl7xWT0mKRZFdJhqwFYHzTkAIdRI9Q== X-Google-Smtp-Source: AGHT+IFG5qMH9g7jFXBHS1vKAQ/IH9fsGdR7jjL+9Q+brsc9HyarpvQp1RWfz7UVateFiDCCl6i2 X-Received: by 2002:a17:906:7190:b0:a43:e40a:50cd with SMTP id h16-20020a170906719000b00a43e40a50cdmr563998ejk.59.1709072061234; Tue, 27 Feb 2024 14:14:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709072061; cv=none; d=google.com; s=arc-20160816; b=UIwrTYu3xVdixx21NhJL3oedwg8kaw778Twjc52bVO8UenMZPZnnrxhrWgQQKBbaa3 LPoG8hNFATHMKSMX3LYuw59taOR8Qj3QS5vhlhysTjVdy0dAENiVb17yAGByTxjf4wNS QIJjM7UY+SLHKJ/t4J8Upd+Fsoio6xBTMTDl+EUj+XrmUMOfSxgOma3tnPZ2TMpnkxfn IHpBmpkQpO9N4bVZWOhpsGRq6Lxxn8zqce71w26bt0C8kTKl+xSXpBVgrM8qH0bZSYPC xTI3CiSGcVH9ZynmQbfm0ylYDdE7RieMQcOkseshg5dOy3ZOUkv47DTFMVT9M3GwV6W1 THPQ== 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=Dxd8mfC9tPV2FnVSuURZylp8vZVHUV3XUDUnB7afFbA=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=u62IC1VZNBhkNr4RWO/XqCGBNZ9FL1IdVK6oy5FIX1Tsf+cMNWXDI15VXtkiaQm6qb pFY5Ac2OxH0N+wdp3XO2GQKWl0zpUyD9HqWhtpDx2+IRqfkBuk/feT3Gw922rAeFk0fY qyZzib2vOPiDyGfWFlwg5hmVUaQdyIcddE95rdU7uieJ1zAUbd5S+EICPHIffX2apmH4 zOq/IB+Ny4F06mQWJv5VFRBtvPdamM70vWql+oN5e8FiPv//DLJ8FyX091Ml5E6fvcOa IrJ1ZocajMs3TcrkuhNghZwkUsTbljcnO4t+duwB+A/tD8DCXrQxkdMCSQNv7JZoLjG5 +hiw==; 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=bPRxf45R; 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 gb22-20020a170907961600b00a3e37770e69si1084253ejc.926.2024.02.27.14.14.20; Tue, 27 Feb 2024 14:14:21 -0800 (PST) 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=bPRxf45R; 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 940F868CE01; Wed, 28 Feb 2024 00:12:58 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 47E9568CACE for ; Wed, 28 Feb 2024 00:12:41 +0200 (EET) Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2d2509c66daso69581411fa.3 for ; Tue, 27 Feb 2024 14:12:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709071960; x=1709676760; 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=drbOwRCQ31m0kS9AxKB3vSe4C2XFCt5h2j1dvbFQHtU=; b=bPRxf45RRpx65kWXZMeJ6hKUVJ+AM/5B/pqScZixAeKRRudQBjwiBKdR7Ul3q6UFP4 7cCQWrPAT5542uaNZS8jA+NGEQxZsjn4GWgonTm4YzpGfb0Mmo2FoqAWFgd60wyb+gRt KtuGXx6TZwQ4Nntc3ee/sTQAABdE4wNjh5zSjQsssXrSNQQrbgmWVJPtiW7SoZodEv7f 468birKJaLNPGEH5XgBoWvRuClQTb42ner9hK/4VDuANL5RuJISZ0jiKqZRt+zqgG2Dd zkNZmZO+mo95iJVOvEClf8rZE40bLEpMoNqgkhEZF/fOtN+emZ8HUdQlSLTjm58dMtlr bHOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709071960; x=1709676760; 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=drbOwRCQ31m0kS9AxKB3vSe4C2XFCt5h2j1dvbFQHtU=; b=EYvA2ot4BXRV/bMwx9vtCjF5lo25x0DLMdMybKWv6kf6ss+VMmvZxgleYNjJL86T65 R6A6xUvOgH7fk/Mt4+Q165TEh7j9e+kVGjpUxGvPZAShKF8Zkc0Z1KFKQVVXrVhYLMSR gmGepLnS8eliozIWXzlT6OQBJa/LvQIQdQwUNbIua3VJWoR2RCh1KwABRfE+llWGHrYB iUiymEbgav6eiUBJsYdX2xfkhJKePSi92ZAtbo9rdWBMjw4OjjBibg/0jaa8CCxzsEki IcOCzkGaIAMPCsBYOzhLiCapiuFOFg6sVRS6aI8/xMx/mz/O7PeLhemugYM8iLy4rS6b 3I3Q== X-Gm-Message-State: AOJu0Yya3XpYK1XwvhysL0BchfAqTGSg+hOWnEW0oIdb6njkrAkoMdvj FdpqmzkeYYDiB1aZsqbQaubhiRp+zwH09063qlzYK2rCBY+81f0vVMIou6qA X-Received: by 2002:a2e:3507:0:b0:2d2:3018:6eda with SMTP id z7-20020a2e3507000000b002d230186edamr6985568ljz.39.1709071960409; Tue, 27 Feb 2024 14:12:40 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id j9-20020a2e8009000000b002d09bc941e8sm1373564ljg.139.2024.02.27.14.12.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:12:40 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Feb 2024 00:12:14 +0200 Message-ID: <20240227221226.1377758-12-jeebjp@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240227221226.1377758-1-jeebjp@gmail.com> References: <20240227221226.1377758-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 11/13] avcodec/libsvtav1: add support for writing out CLL and MDCV 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: MQ5BA1UffQD/ These two were added in 28e23d7f348c78d49a726c7469f9d4e38edec341 and 3558c1f2e97455e0b89edef31b9a72ab7fa30550 for version 0.9.0 of SVT-AV1, which is also our minimum requirement right now. In other words, no additional version limiting conditions seem to be required. Additionally, add a FATE test which verifies that pass-through of the MDCV/CLL side data is working during encoding. --- libavcodec/libsvtav1.c | 68 ++++++++++++++++++++++++++++++++++ tests/fate/enc_external.mak | 5 +++ tests/ref/fate/libsvtav1-hdr10 | 14 +++++++ 3 files changed, 87 insertions(+) create mode 100644 tests/ref/fate/libsvtav1-hdr10 diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c index 3b41f5a39e..76f000fd64 100644 --- a/libavcodec/libsvtav1.c +++ b/libavcodec/libsvtav1.c @@ -27,6 +27,8 @@ #include "libavutil/common.h" #include "libavutil/frame.h" #include "libavutil/imgutils.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/mastering_display_metadata.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "libavutil/avassert.h" @@ -146,6 +148,70 @@ static int alloc_buffer(EbSvtAv1EncConfiguration *config, SvtContext *svt_enc) } +static void handle_mdcv(struct EbSvtAv1MasteringDisplayInfo *dst, + const AVMasteringDisplayMetadata *mdcv) +{ + if (mdcv->has_primaries) { + const struct EbSvtAv1ChromaPoints *const points[] = { + &dst->r, + &dst->g, + &dst->b, + }; + + for (int i = 0; i < 3; i++) { + const struct EbSvtAv1ChromaPoints *dst = points[i]; + const AVRational *src = mdcv->display_primaries[i]; + + AV_WB16(&dst->x, + av_rescale_q(1, src[0], (AVRational){ 1, (1 << 16) })); + AV_WB16(&dst->y, + av_rescale_q(1, src[1], (AVRational){ 1, (1 << 16) })); + } + + AV_WB16(&dst->white_point.x, + av_rescale_q(1, mdcv->white_point[0], + (AVRational){ 1, (1 << 16) })); + AV_WB16(&dst->white_point.y, + av_rescale_q(1, mdcv->white_point[1], + (AVRational){ 1, (1 << 16) })); + } + + if (mdcv->has_luminance) { + AV_WB32(&dst->max_luma, + av_rescale_q(1, mdcv->max_luminance, + (AVRational){ 1, (1 << 8) })); + AV_WB32(&dst->min_luma, + av_rescale_q(1, mdcv->min_luminance, + (AVRational){ 1, (1 << 14) })); + } +} + +static void handle_side_data(AVCodecContext *avctx, + EbSvtAv1EncConfiguration *param) +{ + const AVFrameSideData *cll_sd = + av_frame_side_data_get( + (const AVFrameSideData **)avctx->frame_side_data, + avctx->nb_frame_side_data, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); + const AVFrameSideData *mdcv_sd = + av_frame_side_data_get( + (const AVFrameSideData **)avctx->frame_side_data, + avctx->nb_frame_side_data, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); + + if (cll_sd) { + const AVContentLightMetadata *cll = + (AVContentLightMetadata *)cll_sd->data; + + AV_WB16(¶m->content_light_level.max_cll, cll->MaxCLL); + AV_WB16(¶m->content_light_level.max_fall, cll->MaxFALL); + } + + if (mdcv_sd) { + handle_mdcv(¶m->mastering_display, + (AVMasteringDisplayMetadata *)mdcv_sd->data); + } +} + static int config_enc_params(EbSvtAv1EncConfiguration *param, AVCodecContext *avctx) { @@ -280,6 +346,8 @@ FF_ENABLE_DEPRECATION_WARNINGS /* 2 = IDR, closed GOP, 1 = CRA, open GOP */ param->intra_refresh_type = avctx->flags & AV_CODEC_FLAG_CLOSED_GOP ? 2 : 1; + handle_side_data(avctx, param); + #if SVT_AV1_CHECK_VERSION(0, 9, 1) while ((en = av_dict_get(svt_enc->svtav1_opts, "", en, AV_DICT_IGNORE_SUFFIX))) { EbErrorType ret = svt_av1_enc_parse_parameter(param, en->key, en->value); diff --git a/tests/fate/enc_external.mak b/tests/fate/enc_external.mak index 7eabebcc51..d787941c16 100644 --- a/tests/fate/enc_external.mak +++ b/tests/fate/enc_external.mak @@ -2,5 +2,10 @@ FATE_ENC_EXTERNAL-$(call ENCDEC, LIBX264 H264, MOV, H264_DEMUXER) += fate-libx26 fate-libx264-simple: CMD = enc_external $(TARGET_SAMPLES)/h264-conformance/BA1_Sony_D.jsv \ mp4 "-c:v libx264" "-show_entries frame=width,height,pix_fmt,pts,pkt_dts -of flat" +# test for SVT-AV1 MDCV and CLL passthrough during encoding +FATE_ENC_EXTERNAL-$(call ENCDEC, LIBSVTAV1 HEVC, MOV, HEVC_DEMUXER LIBDAV1D_DECODER) += fate-libsvtav1-hdr10 +fate-libsvtav1-hdr10: CMD = enc_external $(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc \ + mp4 "-c:v libsvtav1" "-show_frames -show_entries frame=side_data_list -of flat" + FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_ENC_EXTERNAL-yes) fate-enc-external: $(FATE_ENC_EXTERNAL-yes) diff --git a/tests/ref/fate/libsvtav1-hdr10 b/tests/ref/fate/libsvtav1-hdr10 new file mode 100644 index 0000000000..6f0d34903b --- /dev/null +++ b/tests/ref/fate/libsvtav1-hdr10 @@ -0,0 +1,14 @@ +frames.frame.0.side_data_list.side_data.0.side_data_type="Mastering display metadata" +frames.frame.0.side_data_list.side_data.0.red_x="17367/65536" +frames.frame.0.side_data_list.side_data.0.red_y="45220/65536" +frames.frame.0.side_data_list.side_data.0.green_x="9830/65536" +frames.frame.0.side_data_list.side_data.0.green_y="3932/65536" +frames.frame.0.side_data_list.side_data.0.blue_x="44564/65536" +frames.frame.0.side_data_list.side_data.0.blue_y="20972/65536" +frames.frame.0.side_data_list.side_data.0.white_point_x="20493/65536" +frames.frame.0.side_data_list.side_data.0.white_point_y="21561/65536" +frames.frame.0.side_data_list.side_data.0.min_luminance="82/16384" +frames.frame.0.side_data_list.side_data.0.max_luminance="256000/256" +frames.frame.0.side_data_list.side_data.1.side_data_type="Content light level metadata" +frames.frame.0.side_data_list.side_data.1.max_content=1000 +frames.frame.0.side_data_list.side_data.1.max_average=200 From patchwork Tue Feb 27 22:12:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 46609 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:aea4:b0:19e:cdac:8cce with SMTP id do36csp11958pzb; Tue, 27 Feb 2024 14:14:30 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXdT07EblJ4bv9SDUdqe3b0Mzi8quR8E818E8jo+rxyD1SuJ6/n8zXTDSKq86LSwN0JiNM2DMCBk1PW8RrOIKLjJXJHp8yCDCWKyA== X-Google-Smtp-Source: AGHT+IEvYkgZyUxpqodUCVJBd82xShstlCNB+YDq4JcL6hxc3Q9wJm/3uI9ioVBdU4tey0YFXeLn X-Received: by 2002:a2e:a70d:0:b0:2d2:4637:63f with SMTP id s13-20020a2ea70d000000b002d24637063fmr5246983lje.45.1709072069762; Tue, 27 Feb 2024 14:14:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709072069; cv=none; d=google.com; s=arc-20160816; b=SlD/NDFwTN0LjmEN4fUBk6XDA9VMjo/GCHBSi7MCmbExI4dskzzOS1PQl73Q6u09HY 2wUMDO8gbZmwEFRMMF3dPPtw3pioV0VMtUDYm5CfGj2xPmJAFOnhEQxLXPa9FWxd2eXe 85gXYIMW4/uljdQ7gJWh/BrAl0VZO3OU5aXeb7IqnT+8kL0i/i6boMBa4lQ9BaWbvrAH c1hx5qH6EtJwOWCvI1Dl/wkoAQfRvNuDI35IQdczb283njXUlELXA64llFlu6c8FFJFU ZaUJZjX1YU/RNsh8Lp28yHKzuLvJTvWHEDkrte6y7oG33ctnn7vL9qNxxsFfrbzaC6Ao N2IQ== 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=9tELwVkobSr2LUc+xnswUpogU5OArI4unIiIIBzhVoc=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=F/ODmMuXfMBM7Z3MFk9naQhvfentwYFJYXmm3kDLXse0YnQPnKSFA1nTeLehZ7vwEn pMyZvovgc51NeMx321bsb8KypBsFLL1cS3Yx/LfI4g+hYutlmkYPz8rRsJBWAWPZU/8v bxFXn1WuXLcNndbWuSLw4L6g+pVYSymiJHJ0b3mjnUmaN1f9e/vyip693z2a8J29YaCQ W2FBhCP4Cjo44Uffs2TZvIhgjrIc5RAdszI+d8r0YMlACnBZ0YvGMsbbhXujVWTSwG8M PAfEmwXdrWQXOB4AR3FPMEC28CAPdGIYLnwpKY9cmOd+3fQz5B2y2mFEbKAM+JdC/MEH rZBw==; 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=fGdHbuPD; 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 g20-20020aa7c594000000b005657233dee1si1080742edq.193.2024.02.27.14.14.29; Tue, 27 Feb 2024 14:14:29 -0800 (PST) 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=fGdHbuPD; 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 AC0F668C8A3; Wed, 28 Feb 2024 00:12:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B003768CACE for ; Wed, 28 Feb 2024 00:12:41 +0200 (EET) Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2d204e102a9so58060411fa.0 for ; Tue, 27 Feb 2024 14:12:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709071961; x=1709676761; 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=HmT+CICr/ckyqKR5iBlwGDZbWhYwkOoCsmCBGHVpwJw=; b=fGdHbuPDtu0xI18ktdG7akLNuGPgz9Z3FTiTX7+8a8ve9Uu5DBNcgxvjz/K9sb4F1h Dma1mOpGWHO9LB6N3LWa4OSHDEzNMGE6hu6Yw29QunEffutBIziH40xs2eRvsyEIVDUb zqczVOu0ajV2QryihKA6UqT+Y7cFE9MKNSRF0B97tWVIeCAtXcFRstwM9EwiKZILBF+U Kthl85bzdwTy6lZ47yfEV8aNxvX0GABxf171lEgcDYKBzq3b9vL4H0NFGsFJlqnZvco1 L+RJq4TtVdDS6vZZAaeR3QeZtk+9T+GjqWl77yYvR5AwGwyKzwCB/EyV0Zbws+0UdzFZ E5qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709071961; x=1709676761; 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=HmT+CICr/ckyqKR5iBlwGDZbWhYwkOoCsmCBGHVpwJw=; b=AbjUzFzD2nwqmIOch6aYwDtPT0YnlIwIvLRySQpxfVcwIkwvCdraD7oSZ/kXDjvtKt lO5MFk5X1Yz7QrAEW0TDmURw9ylLzI3BMR/fVLYb8ZIyqJ+vnAjNF5ygdhDz1ZGue+wP ZHbltsarw1QO38tpr+v8rAR19OyixjESjWZOM2MOy/YE9CtXblU1s8zzmYJEu7S6bH9w VH4u0qRgeyH1iqF2TVbErv88c/xoMEvt+lIpi4BDeWyK/yGzFMLcvDVH5WJXHAK229Oi H/v51zwI26P2vycaqVvsVU1EargSH7EDTKEyBsitIH6KGET4h9q68vtpOuL4fYwEzlAl l5vw== X-Gm-Message-State: AOJu0Yw6I3G1xunDZkB9Ndp4XSX9NQWm5u4vz77ckVrk2t4gTIIREeEx fCAULGiPMH43C1AWkzq1Oh7Zb2Eb6b3CrEKvh0HHhTlzHljQeL8xo0fk/P/J X-Received: by 2002:a2e:4941:0:b0:2d2:a473:eb7f with SMTP id b1-20020a2e4941000000b002d2a473eb7fmr1578299ljd.27.1709071960831; Tue, 27 Feb 2024 14:12:40 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id j9-20020a2e8009000000b002d09bc941e8sm1373564ljg.139.2024.02.27.14.12.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:12:40 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Feb 2024 00:12:15 +0200 Message-ID: <20240227221226.1377758-13-jeebjp@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240227221226.1377758-1-jeebjp@gmail.com> References: <20240227221226.1377758-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 12/13] avcodec/libx264: add support for writing out CLL and MDCV 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: 14z+5DCw0vCI Both of these two structures were first available with X264_BUILD 163, so make relevant functionality conditional on the version being at least such. Keep handle_side_data available in all cases as this way X264_init does not require additional version based conditions within it. Finally, add a FATE test which verifies that pass-through of the MDCV/CLL side data is working during encoding. --- configure | 2 + libavcodec/libx264.c | 79 ++++++++++++++++++++++++++++++++++++ tests/fate/enc_external.mak | 5 +++ tests/ref/fate/libx264-hdr10 | 15 +++++++ 4 files changed, 101 insertions(+) create mode 100644 tests/ref/fate/libx264-hdr10 diff --git a/configure b/configure index bb5e630bad..f48cf46ffe 100755 --- a/configure +++ b/configure @@ -2527,6 +2527,7 @@ CONFIG_EXTRA=" jpegtables lgplv3 libx262 + libx264_hdr10 llauddsp llviddsp llvidencdsp @@ -6927,6 +6928,7 @@ enabled libx264 && require_pkg_config libx264 x264 "stdint.h x264.h" x require_cpp_condition libx264 x264.h "X264_BUILD >= 122" && { [ "$toolchain" != "msvc" ] || require_cpp_condition libx264 x264.h "X264_BUILD >= 158"; } && + check_cpp_condition libx264_hdr10 x264.h "X264_BUILD >= 163" && check_cpp_condition libx262 x264.h "X264_MPEG2" enabled libx265 && require_pkg_config libx265 x265 x265.h x265_api_get && require_cpp_condition libx265 x265.h "X265_BUILD >= 89" diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 10d646bd76..effdcfdb37 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -25,6 +25,7 @@ #include "libavutil/eval.h" #include "libavutil/internal.h" #include "libavutil/opt.h" +#include "libavutil/mastering_display_metadata.h" #include "libavutil/mem.h" #include "libavutil/pixdesc.h" #include "libavutil/stereo3d.h" @@ -871,6 +872,82 @@ static int convert_pix_fmt(enum AVPixelFormat pix_fmt) return AVERROR(EINVAL);\ } +#if CONFIG_LIBX264_HDR10 +static void handle_mdcv(x264_param_t *params, + const AVMasteringDisplayMetadata *mdcv) +{ + if (!mdcv->has_primaries && !mdcv->has_luminance) + return; + + params->mastering_display.b_mastering_display = 1; + + if (mdcv->has_primaries) { + int *const points[][2] = { + { + ¶ms->mastering_display.i_red_x, + ¶ms->mastering_display.i_red_y + }, + { + ¶ms->mastering_display.i_green_x, + ¶ms->mastering_display.i_green_y + }, + { + ¶ms->mastering_display.i_blue_x, + ¶ms->mastering_display.i_blue_y + }, + }; + + for (int i = 0; i < 3; i++) { + const AVRational *src = mdcv->display_primaries[i]; + int *dst[2] = { points[i][0], points[i][1] }; + + *dst[0] = av_rescale_q(1, src[0], (AVRational){ 1, 50000 }); + *dst[1] = av_rescale_q(1, src[1], (AVRational){ 1, 50000 }); + } + + params->mastering_display.i_white_x = + av_rescale_q(1, mdcv->white_point[0], (AVRational){ 1, 50000 }); + params->mastering_display.i_white_y = + av_rescale_q(1, mdcv->white_point[1], (AVRational){ 1, 50000 }); + } + + if (mdcv->has_luminance) { + params->mastering_display.i_display_max = + av_rescale_q(1, mdcv->max_luminance, (AVRational){ 1, 10000 }); + params->mastering_display.i_display_min = + av_rescale_q(1, mdcv->min_luminance, (AVRational){ 1, 10000 }); + } +} +#endif // CONFIG_LIBX264_HDR10 + +static void handle_side_data(AVCodecContext *avctx, x264_param_t *params) +{ +#if CONFIG_LIBX264_HDR10 + const AVFrameSideData *cll_sd = + av_frame_side_data_get( + (const AVFrameSideData **)avctx->frame_side_data, + avctx->nb_frame_side_data, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); + const AVFrameSideData *mdcv_sd = + av_frame_side_data_get( + (const AVFrameSideData **)avctx->frame_side_data, + avctx->nb_frame_side_data, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); + + if (cll_sd) { + const AVContentLightMetadata *cll = + (AVContentLightMetadata *)cll_sd->data; + + params->content_light_level.i_max_cll = cll->MaxCLL; + params->content_light_level.i_max_fall = cll->MaxFALL; + + params->content_light_level.b_cll = 1; + } + + if (mdcv_sd) { + handle_mdcv(params, (AVMasteringDisplayMetadata *)mdcv_sd->data); + } +#endif // CONFIG_LIBX264_HDR10 +} + static av_cold int X264_init(AVCodecContext *avctx) { X264Context *x4 = avctx->priv_data; @@ -1171,6 +1248,8 @@ FF_ENABLE_DEPRECATION_WARNINGS if (avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED) x4->params.vui.i_chroma_loc = avctx->chroma_sample_location - 1; + handle_side_data(avctx, &x4->params); + if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) x4->params.b_repeat_headers = 0; diff --git a/tests/fate/enc_external.mak b/tests/fate/enc_external.mak index d787941c16..4095a4b51a 100644 --- a/tests/fate/enc_external.mak +++ b/tests/fate/enc_external.mak @@ -7,5 +7,10 @@ FATE_ENC_EXTERNAL-$(call ENCDEC, LIBSVTAV1 HEVC, MOV, HEVC_DEMUXER LIBDAV1D_DECO fate-libsvtav1-hdr10: CMD = enc_external $(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc \ mp4 "-c:v libsvtav1" "-show_frames -show_entries frame=side_data_list -of flat" +# test for x264 MDCV and CLL passthrough during encoding +FATE_ENC_EXTERNAL-$(call ENCDEC, LIBX264 HEVC, MOV, LIBX264_HDR10 HEVC_DEMUXER H264_DECODER) += fate-libx264-hdr10 +fate-libx264-hdr10: CMD = enc_external $(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc \ + mp4 "-c:v libx264" "-show_frames -show_entries frame=side_data_list -of flat" + FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_ENC_EXTERNAL-yes) fate-enc-external: $(FATE_ENC_EXTERNAL-yes) diff --git a/tests/ref/fate/libx264-hdr10 b/tests/ref/fate/libx264-hdr10 new file mode 100644 index 0000000000..99c11677f0 --- /dev/null +++ b/tests/ref/fate/libx264-hdr10 @@ -0,0 +1,15 @@ +frames.frame.0.side_data_list.side_data.0.side_data_type="H.26[45] User Data Unregistered SEI message" +frames.frame.0.side_data_list.side_data.1.side_data_type="Mastering display metadata" +frames.frame.0.side_data_list.side_data.1.red_x="13250/50000" +frames.frame.0.side_data_list.side_data.1.red_y="34500/50000" +frames.frame.0.side_data_list.side_data.1.green_x="7500/50000" +frames.frame.0.side_data_list.side_data.1.green_y="3000/50000" +frames.frame.0.side_data_list.side_data.1.blue_x="34000/50000" +frames.frame.0.side_data_list.side_data.1.blue_y="16000/50000" +frames.frame.0.side_data_list.side_data.1.white_point_x="15635/50000" +frames.frame.0.side_data_list.side_data.1.white_point_y="16450/50000" +frames.frame.0.side_data_list.side_data.1.min_luminance="50/10000" +frames.frame.0.side_data_list.side_data.1.max_luminance="10000000/10000" +frames.frame.0.side_data_list.side_data.2.side_data_type="Content light level metadata" +frames.frame.0.side_data_list.side_data.2.max_content=1000 +frames.frame.0.side_data_list.side_data.2.max_average=200 From patchwork Tue Feb 27 22:12:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 46603 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:aea4:b0:19e:cdac:8cce with SMTP id do36csp12036pzb; Tue, 27 Feb 2024 14:14:38 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXY6DGn7RGpZN32UTRa1KvWXgRjPldAvjRu13BXCb4+sGMzWAjx3wmDgd22JRe+9AMHHlzZz2kPoxzjZqqkZz6vB5Am9u9E/hu6HA== X-Google-Smtp-Source: AGHT+IG6rbR5UMmAEpnKHamP6On+SPSRSRqysbbTR5/yY/DiDv3M9S0D9zB9QPAs7vgf3W0lijWb X-Received: by 2002:a17:906:d0d7:b0:a3f:c3f0:69bf with SMTP id bq23-20020a170906d0d700b00a3fc3f069bfmr605684ejb.13.1709072078066; Tue, 27 Feb 2024 14:14:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709072078; cv=none; d=google.com; s=arc-20160816; b=C81yktrWuoCxQS2B8jNK5z5lrWLV+I2m7wYJmXrH0/3i80okgOzCh/+HltL00Eb0qc txEop9Xlz2b5+LzQV3E/S3SwbWMSQH5Jny6OP3krk4OuVHyQzGr0bKTu4kM7vsDYWrDP 9EvBnf8xiWwYxBrOHgPvSHpgYzydhOvBqJbeSxjZtD1gP6uG8vtGsCJIFJadNxEErNjx PTppGI+SUpYz+BrOWSVG+69ESyAX2uqHK/mf5+s/PlGNI0AfdrTP2yJt8qNRrKDhXAPl rDep5XbfIztRjd2g1a2jqXQhReWAKtq9o3KgSY2cirPqeKCGQUg3TmysCW1HFJzxhcNe ++7w== 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=km3JY6Q/tUtv5K3607MSWUZhtQ+bt5uS5amf0hpemOo=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=S7AtEaAZL35NmN5DamkC1x+KCK5U9snW1drXFXiuTh3jBvqjByrcO/xVfd28HDWKXe Odl5z//MT8Xv30G+3mKdsvrbmlbzaYK/FCBKidyjJtwCKOZO6AwOiFIPFOlw8MgzuNZC RDe5PH4rPa0K/ScPl6JlnO03IoNdjvX0JviG7Yn4Wb0vALPxRjbsWroH6ne5Hn2yc/uR Oget8vlq0WGqglGrpHmM8DKKd3f6+8rlZdxrf18vjn533qV4Ai6zIbl2DzPecPilNY3D 3a8Yu7/7x5iBac1elgDPDiAgLH4esHvaF7GdrevHGlvEpz+ZL2CGm32gHp3XUrv6vfgM zgTQ==; 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=ikdsKKMW; 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 k5-20020a1709065fc500b00a3ebdea18e1si1075142ejv.240.2024.02.27.14.14.37; Tue, 27 Feb 2024 14:14:38 -0800 (PST) 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=ikdsKKMW; 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 C612868CE27; Wed, 28 Feb 2024 00:13:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1542968CBD4 for ; Wed, 28 Feb 2024 00:12:42 +0200 (EET) Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2d2991e8c12so2547381fa.0 for ; Tue, 27 Feb 2024 14:12:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709071961; x=1709676761; 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=GAaCujyyN0wQ8JnNYVZhuaBUYpI9td6t5xHtgfPzbGg=; b=ikdsKKMW0Twd/q2c3zWVcUY4JIqobSjGorJG0+jDIiI2wAfog1jIVfhEQqxEfrJzvV /X3kX3KVWT14zNdNLG6LQddT673CrDAzgxe6puj9oqFwTqY/WW4YKTWerT3xtpMI8jNo o8MrK+mdzcJFec+d/CEskestZAm7YE3MwRUPSvDRFL9HJu+8uefMbq1yBPESvCzFQsNj qAOigEhKvzkdIadPfk3mxrnOVDq/5C9DVtk7G1X+scgRLNoUJuEZXPxWvPdQb1GpyuOB tzM3yJWtmTArZzzzDF5X0xcOuSfkc7vsjEeOGsYfD/lXpePCLpUaK7C1CE1jpkHby7HJ oBgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709071961; x=1709676761; 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=GAaCujyyN0wQ8JnNYVZhuaBUYpI9td6t5xHtgfPzbGg=; b=X0s8NzyUOp3O4WsWjJ/2dhX45xkbh8waIQivEuWOdMhLta27UbSHcQHK9ETAdZh9a6 +4ITfVubJazrhLvu2plsKUkYOBatzYL+fbmYYwlGV4+56LtELZ39PFnyBI6AHSJvooEB 4hvFB0YVuQQX+CwRSig4VCNyQMllfIzCQdkSm57EGnfY7oMfG6CXjN5Xzes1gFVAddvx P5Tf6nn7S+10QcWJi/4r5VeSqYa8fxs0jRVHGSw6xSRD3Y0Cb85eU+7vvnscLgXTtMvR F0WYTrASCYr07QzxKxiOBjO4KU3ekZpNZNeyRS/SSoDWxXuVBROowtu8NRNG/7G4xo+9 dZwA== X-Gm-Message-State: AOJu0Yx5vhDmPyCjJO+NFTRm3cA6CqG+Iw+/3Z+fB8Qh4vzw/YkvzzJA zd9lyxHoK+mFA2P7qozE7yZya/Dk2aNWUVIi3/HW+viZFsMl2NRXrRWxNK2r X-Received: by 2002:a05:651c:2121:b0:2d2:28a3:eb38 with SMTP id a33-20020a05651c212100b002d228a3eb38mr280749ljq.8.1709071961246; Tue, 27 Feb 2024 14:12:41 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id j9-20020a2e8009000000b002d09bc941e8sm1373564ljg.139.2024.02.27.14.12.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:12:40 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Feb 2024 00:12:16 +0200 Message-ID: <20240227221226.1377758-14-jeebjp@gmail.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240227221226.1377758-1-jeebjp@gmail.com> References: <20240227221226.1377758-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 13/13] avcodec/libx265: add support for writing out CLL and MDCV 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: D5tzwvWdxrGa The newer of these two are the separate integers for content light level, introduced in 3952bf3e98c76c31594529a3fe34e056d3e3e2ea , with X265_BUILD 75. As we already require X265_BUILD of at least 89, no further conditions are required. --- libavcodec/libx265.c | 88 ++++++++++++++++++++++++++++++++++++ tests/fate/enc_external.mak | 5 ++ tests/ref/fate/libx265-hdr10 | 16 +++++++ 3 files changed, 109 insertions(+) create mode 100644 tests/ref/fate/libx265-hdr10 diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 447e6da25f..8d366f51ab 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -28,9 +28,11 @@ #include #include "libavutil/avassert.h" +#include "libavutil/bprint.h" #include "libavutil/buffer.h" #include "libavutil/internal.h" #include "libavutil/common.h" +#include "libavutil/mastering_display_metadata.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "avcodec.h" @@ -179,6 +181,85 @@ static av_cold int libx265_param_parse_int(AVCodecContext *avctx, return 0; } +static int handle_mdcv(const AVClass **avcl, const x265_api *api, + x265_param *params, + const AVMasteringDisplayMetadata *mdcv) +{ + int ret = AVERROR_BUG; + AVBPrint buf; + av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); + + // G(%hu,%hu)B(%hu,%hu)R(%hu,%hu)WP(%hu,%hu)L(%u,%u) + av_bprintf( + &buf, + "G(%"PRId64",%"PRId64")B(%"PRId64",%"PRId64")R(%"PRId64",%"PRId64")" + "WP(%"PRId64",%"PRId64")L(%"PRId64",%"PRId64")", + av_rescale_q(1, mdcv->display_primaries[1][0], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[1][1], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[2][0], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[2][1], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[0][0], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[0][1], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->white_point[0], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->white_point[1], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->max_luminance, (AVRational){ 1, 10000 }), + av_rescale_q(1, mdcv->min_luminance, (AVRational){ 1, 10000 })); + + if (!av_bprint_is_complete(&buf)) { + av_log(avcl, AV_LOG_ERROR, + "MDCV string too long for its available space!\n"); + ret = AVERROR(ENOMEM); + goto end; + } + + if (api->param_parse(params, "master-display", buf.str) == + X265_PARAM_BAD_VALUE) { + av_log(avcl, AV_LOG_ERROR, + "Invalid value \"%s\" for param \"master-display\".\n", + buf.str); + ret = AVERROR(EINVAL); + goto end; + } + + ret = 0; + +end: + av_bprint_finalize(&buf, NULL); + + return ret; +} + +static int handle_side_data(AVCodecContext *avctx, const x265_api *api, + x265_param *params) +{ + const AVFrameSideData *cll_sd = + av_frame_side_data_get( + (const AVFrameSideData **)avctx->frame_side_data, + avctx->nb_frame_side_data, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); + const AVFrameSideData *mdcv_sd = + av_frame_side_data_get( + (const AVFrameSideData **)avctx->frame_side_data, + avctx->nb_frame_side_data, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); + + if (cll_sd) { + const AVContentLightMetadata *cll = + (AVContentLightMetadata *)cll_sd->data; + + params->maxCLL = cll->MaxCLL; + params->maxFALL = cll->MaxFALL; + } + + if (mdcv_sd) { + int ret = handle_mdcv( + &avctx->av_class, api, params, + (AVMasteringDisplayMetadata *)mdcv_sd->data); + if (ret < 0) + return ret; + } + + return 0; +} + static av_cold int libx265_encode_init(AVCodecContext *avctx) { libx265Context *ctx = avctx->priv_data; @@ -339,6 +420,13 @@ FF_ENABLE_DEPRECATION_WARNINGS return AVERROR_BUG; } + ret = handle_side_data(avctx, ctx->api, ctx->params); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "Failed handling side data! (%s)\n", + av_err2str(ret)); + return ret; + } + if (ctx->crf >= 0) { char crf[6]; diff --git a/tests/fate/enc_external.mak b/tests/fate/enc_external.mak index 4095a4b51a..30021efbcd 100644 --- a/tests/fate/enc_external.mak +++ b/tests/fate/enc_external.mak @@ -12,5 +12,10 @@ FATE_ENC_EXTERNAL-$(call ENCDEC, LIBX264 HEVC, MOV, LIBX264_HDR10 HEVC_DEMUXER H fate-libx264-hdr10: CMD = enc_external $(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc \ mp4 "-c:v libx264" "-show_frames -show_entries frame=side_data_list -of flat" +# test for x265 MDCV and CLL passthrough during encoding +FATE_ENC_EXTERNAL-$(call ENCDEC, LIBX265 HEVC, MOV, HEVC_DEMUXER) += fate-libx265-hdr10 +fate-libx265-hdr10: CMD = enc_external $(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc \ + mp4 "-c:v libx265" "-show_frames -show_entries frame=side_data_list -of flat" + FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_ENC_EXTERNAL-yes) fate-enc-external: $(FATE_ENC_EXTERNAL-yes) diff --git a/tests/ref/fate/libx265-hdr10 b/tests/ref/fate/libx265-hdr10 new file mode 100644 index 0000000000..571c837cac --- /dev/null +++ b/tests/ref/fate/libx265-hdr10 @@ -0,0 +1,16 @@ +frames.frame.0.side_data_list.side_data.0.side_data_type="H.26[45] User Data Unregistered SEI message" +frames.frame.0.side_data_list.side_data.1.side_data_type="H.26[45] User Data Unregistered SEI message" +frames.frame.0.side_data_list.side_data.2.side_data_type="Mastering display metadata" +frames.frame.0.side_data_list.side_data.2.red_x="13250/50000" +frames.frame.0.side_data_list.side_data.2.red_y="34500/50000" +frames.frame.0.side_data_list.side_data.2.green_x="7500/50000" +frames.frame.0.side_data_list.side_data.2.green_y="3000/50000" +frames.frame.0.side_data_list.side_data.2.blue_x="34000/50000" +frames.frame.0.side_data_list.side_data.2.blue_y="16000/50000" +frames.frame.0.side_data_list.side_data.2.white_point_x="15635/50000" +frames.frame.0.side_data_list.side_data.2.white_point_y="16450/50000" +frames.frame.0.side_data_list.side_data.2.min_luminance="50/10000" +frames.frame.0.side_data_list.side_data.2.max_luminance="10000000/10000" +frames.frame.0.side_data_list.side_data.3.side_data_type="Content light level metadata" +frames.frame.0.side_data_list.side_data.3.max_content=1000 +frames.frame.0.side_data_list.side_data.3.max_average=200