From patchwork Thu Jul 21 23:39:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 36885 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp86064pzb; Thu, 21 Jul 2022 16:40:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uKjs+DTJ2lIsdIYITlVv0CmkBO2421k4JsSpRMfh7FTbFCABWTETHnBbIHOwz7jRtPi7zk X-Received: by 2002:a17:907:a413:b0:72f:1959:f35f with SMTP id sg19-20020a170907a41300b0072f1959f35fmr862936ejc.112.1658446832052; Thu, 21 Jul 2022 16:40:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658446832; cv=none; d=google.com; s=arc-20160816; b=ZVcseYtX6qZvg8KyVr1Ru4VYBiHdjCOyUYFR8F9V9FrpN6ukigR6E7NceaqwqhMeSw 96UlLCfdxM+fQLpOM8oZxsAj6k7vnsI4grxefORT9dfC4LBdHtN19xGWQwDmhclvSSbZ A3MUiAguFWYDW0CW6h6YhiciAnHAyQ/VRG/xoKjTvtHYKrs5H/G91vjIqcGWSFxRXuS9 UciMmBOJYK4rsyizQ7Q+5X1nymh+SP112ezBBpjMmUXMK85/c5g5fr5D/U0dMWoZkITr 76UFQdTkE3POYQUqtxo0M9DhW4hkhjSnKnw3TqobFiRX8WxecEOfT+PnFXvc1beK3d9C ZdYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=wL1XOJRPMcK5O5M+w2JZyutSXUB8ihZN8Mz8KUIcvTM=; b=hcOgOMkpGDHwPAMEBgCdq5GH74Ut6skER1GHYGNUTztndPJanX1MX/W9wltVB5zNaA F9SYtfhzX4vhXG8QUMt4Cz9cwqg1r+8bW4R7lsoi+lRTrxtKhBftrrEIPyRPg5rMLaql R0rKv/PZwLyghMw8+ZI+va8ul1LgHJIerh8T4z0VjJsJB7xEhWYcfK2ORuB/gZoFfwgb 98ow6rUKI9Pa/xFLBTy+kNCDK/+SdiF6aSeYE167gg5FafYMzeuHz9o46UO4BjHqAB9N 1WBB2/uYwR1T5a/B49rEBv2gHoWM+6fe7IRXJpuGZaHwiZDk7bSSr3Kixdi25T45P1mP neSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=QTOI7m8S; 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 sb5-20020a1709076d8500b0072b919c8216si4677086ejc.609.2022.07.21.16.40.09; Thu, 21 Jul 2022 16:40:32 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=QTOI7m8S; 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 801D168B6AF; Fri, 22 Jul 2022 02:39:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6B3B668B369 for ; Fri, 22 Jul 2022 02:39:47 +0300 (EEST) Received: by mail-pl1-f169.google.com with SMTP id g17so3233365plh.2 for ; Thu, 21 Jul 2022 16:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=YG2Ueo0jW0GycGgy19XZ+62ItpaRuc1ZGAlGOPvDpaI=; b=QTOI7m8SajGapwXWDunglbvIm76GLuZz2EPo/872zKBOC5PjR8pqZI4XAfJg2LNBmN sjJDMQk6A8jWK/IKVTnE7Lycj33XXHmByv7mhucAyaml+NDNml0IoVcKjX349EAtbndN rhL9/UF3U5TxBvOpNQMHMucjzNZWGz+v9YN8fBRiIa6WIjbiBf8oKyL1Uoyj9kzPPbTi +iqDnf91T3q5HXcJ/oL6vV8ub3Ho82X9Y04duWgfzNovf7dl/r8UneF+hJ1XeHcD3eTT gMdbxVdbIYxTjm4z8IO3LWLX5WQe4BIUEh1m7sQwk5/32uE2eT6BPgVVnbBC/jjHTGt2 gB6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=YG2Ueo0jW0GycGgy19XZ+62ItpaRuc1ZGAlGOPvDpaI=; b=bubF/MUNltLlyBUE5+JUpnJWl+X1j6Y0SGkffki5y1reED9nYjrjPONXq0Id2nTUNW TXV7PXrZER3y25UbXAFvLAd8l15xA/XieTFH+e9lJ4KOpu3kJHhDJ9rFe+QqqTLUXhD9 PQevU8kaPsP97sUTxpCZLvnMk3V4pRHZHwccRjtPp+SulstE42Qc0M2AUEKZdVX8k2jI oj4KHbD7m5X0PgmFJA6r2qmJ/3KXWJKPW5kWTM7WwTObDHGedx7mZkbHSziJxi9AYpjV 4lUzmzclz7AX+lvg0abYT88m+CY8oQNlCHCbFFkIXj/x9myUcsIxxJ4jzu+U+jBm9UHt 2Ynw== X-Gm-Message-State: AJIora8sR4meVzuIQvJqm5+hkShVm9GRYgWRrASxQIi4Cn8cazev8FLq uzh4x96U75dSWuh84FyTij4UU8xZzmg= X-Received: by 2002:a17:902:f68c:b0:16c:4eb6:913c with SMTP id l12-20020a170902f68c00b0016c4eb6913cmr871358plg.2.1658446785685; Thu, 21 Jul 2022 16:39:45 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id t18-20020a170902d15200b0016c304612a0sm2210654plt.292.2022.07.21.16.39.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jul 2022 16:39:45 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: In-Reply-To: References: Date: Thu, 21 Jul 2022 23:39:40 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v3 1/4] avutil/buffer: add av_ref_from_buffer() 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 Cc: Mark Thompson , softworkz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: M+f5x44HPQMC From: softworkz This allows to create AVBufferRef from AVBuffer directly. Signed-off-by: softworkz --- libavutil/buffer.c | 16 ++++++++++++++++ libavutil/buffer.h | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/libavutil/buffer.c b/libavutil/buffer.c index 54590be566..f9df0ad6ea 100644 --- a/libavutil/buffer.c +++ b/libavutil/buffer.c @@ -100,6 +100,22 @@ AVBufferRef *av_buffer_allocz(size_t size) return ret; } +AVBufferRef *av_ref_from_buffer(AVBuffer *buf) +{ + AVBufferRef *ref = av_mallocz(sizeof(*ref)); + + if (!ref) + return NULL; + + ref->buffer = buf; + ref->data = buf->data; + ref->size = buf->size; + + atomic_fetch_add_explicit(&buf->refcount, 1, memory_order_relaxed); + + return ref; +} + AVBufferRef *av_buffer_ref(const AVBufferRef *buf) { AVBufferRef *ret = av_mallocz(sizeof(*ret)); diff --git a/libavutil/buffer.h b/libavutil/buffer.h index e1ef5b7f07..491734b9ca 100644 --- a/libavutil/buffer.h +++ b/libavutil/buffer.h @@ -139,6 +139,14 @@ AVBufferRef *av_buffer_create(uint8_t *data, size_t size, */ void av_buffer_default_free(void *opaque, uint8_t *data); +/** + * Create a new reference to an AVBuffer. + * + * @return a new AVBufferRef referring to the same AVBuffer as buf or NULL on + * failure. + */ +AVBufferRef *av_ref_from_buffer(AVBuffer *buf); + /** * Create a new reference to an AVBuffer. * From patchwork Thu Jul 21 23:39:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 36883 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp85977pzb; Thu, 21 Jul 2022 16:40:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vzdy96q7O17qOnqmwFMoVAwiPrfo7M3/sANatqeBXLA7mM/Uk38UbaG7Oy3Dz7aY25Nlil X-Received: by 2002:a17:906:7007:b0:6ff:8028:42e with SMTP id n7-20020a170906700700b006ff8028042emr856100ejj.278.1658446820442; Thu, 21 Jul 2022 16:40:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658446820; cv=none; d=google.com; s=arc-20160816; b=0o2+wbchNUVPwDsnwRAW7tX82kSEnW4tzeLVJF4BVx/Nd/gDeoPswssFJQAZ6RcqUC RWZqFoX8XmC2OD3umDtegqX2QIJ/iF3dfpeTU46neoslpFgX92J7+VhHj4py8rGbxIgG Dlr4HZBDk7YUj/p/wTgydATZivBICeZUhhyZl470ftQLxuLpwWZILYAO+dnbQOuMM8XI SiXNBMsHi2UzsNz8bVkwNSuFWh4SpxG9+67Wvj6+A1q5wg3N6rkA52d9xObx6IVH7ENR Zc43/+hH2jUlOmLmjOoUJzS8dxswJAUJovUwQsjwaukdO1SyPFugCfYrFrTkjc5QVOdC Gqyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=qk2i2UZWVVI+ZcpauPtL6402xcjPvp8gi48iBSnX0oI=; b=njH26fFkGJGahAoxpNS4HaL4mSPwmqT/+9ovZ+osAWhHZjKKAQ0PGvaq5brh3ESqZz ZL1uE5dIBdYxUypnVau+h1iCaM1SQ7KvmH8W+wblnbO3Rj1bEvjWSW+xkivAo5gVOaTh GRqTlAlGVS+71TA1KxJE5KwvueYNtmDXXbz6T78544d7MxX4JJsKvkouFw2j1pmhlelk WqdRoBmslUrds1spALEcRzIQhunyQvo/XnBi2LUOEM6NU4Y1REP2fDHpus514RxIFt30 AK4jrLAwI2LrWyxWzP4dibaiAXBTJRn+795L69O6wh6X4ROUKQRwp/ADyGAZNBqmbNv4 28Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=jNcgptLk; 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 go17-20020a1709070d9100b0072b67b81430si5038467ejc.577.2022.07.21.16.40.20; Thu, 21 Jul 2022 16:40:20 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=jNcgptLk; 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 7299168B6D1; Fri, 22 Jul 2022 02:39:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C69CC68B698 for ; Fri, 22 Jul 2022 02:39:48 +0300 (EEST) Received: by mail-pf1-f176.google.com with SMTP id b9so3098478pfp.10 for ; Thu, 21 Jul 2022 16:39:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=AtTfYjXGYnq76b2SNQL+rN6fLRAND3u7sorv+vy6980=; b=jNcgptLkoReiMZaY4mU/zPmTeHKTyrt4WbbCDPKRpPpP+tmxilcWOgLz1l379+VS+A ZMvu2kisz5tPA2cig8IZR4moD5FzOfFi5noNaUKLzsScnA5KEJ1o9sAKNACaT0qib2SL Cgz6wgTjKTgnWKETOuDI7ja486s3Ldp9SOKLMl0DWSKE2Ft3ihXAfPMNBQVb2opzlhFs Li1LJCc3ZD0JlGFkRBpVZ8GqUlhwjp1GpKTELOrE8GF2gb6dieRO9rKBaOvOJtC/YxJm 1Cnqh7H818UxVejUOzf7whoY3DzTMADPvyLu+E1A4Zecw0q9I+cbYs2fSQYWssBCuWg6 CGhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=AtTfYjXGYnq76b2SNQL+rN6fLRAND3u7sorv+vy6980=; b=V2HU4kchG71X1wLZqVrdxH1q8lwVFbzAf6hpHs0Vd47CA72mOSNhINq3oIYzBG4v5R uETpyvLiXMex3LwJUeg1+YYfzLWBaw1i2138aw6zhLtlzqFbXy68ftEX1gwGpUZ5hLee kzsRVR3X6tTvEWDuHJsrQja3dEOVrv6iwXHc68e7TevJwLFiQwNA7i2pmM8jZDbVVSDa S6D4NougnnOhbFIFJ04jZO3U8qX3PeDtZEQWo5EFkUSY5qO1G9l7pdvjNTTvffJA3ncK vR/MKeMcfyz3Vf9MVcWYSRJBH1DwccvpVw8dCeGxoSp+fqlogsHWJBXmcefI914gdtVt asIg== X-Gm-Message-State: AJIora8HL9hL31sFZPWvrUj8fLhGT5E/lL8IvWYJp4DqM2JgmpgHecD3 AP96E+sY7xhXhUl1GH0Hz+3ZU5a/xyM= X-Received: by 2002:a65:6e9a:0:b0:41a:63d7:d053 with SMTP id bm26-20020a656e9a000000b0041a63d7d053mr718869pgb.212.1658446786802; Thu, 21 Jul 2022 16:39:46 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id e25-20020a633719000000b0041a716cec9esm2016249pga.62.2022.07.21.16.39.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jul 2022 16:39:46 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <5cd017dfa7689046b04fee62eb5fddecd2a912e2.1658446783.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Thu, 21 Jul 2022 23:39:41 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v3 2/4] avutils/hwcontext: add derive-device function which searches for existing devices in both directions 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 Cc: Mark Thompson , softworkz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: eSsSYo7kAzPH From: softworkz The test /libavutil/tests/hwdevice checks that when deriving a device from a source device and then deriving back to the type of the source device, the result is matching the original source device, i.e. the derivation mechanism doesn't create a new device in this case. Previously, this test was usually passed, but only due to two different kind of flaws: 1. The test covers only a single level of derivation (and back) It derives device Y from device X and then Y back to the type of X and checks whether the result matches X. What it doesn't check for, are longer chains of derivation like: CUDA1 > OpenCL2 > CUDA3 and then back to OpenCL4 In that case, the second derivation returns the first device (CUDA3 == CUDA1), but when deriving OpenCL4, hwcontext.c was creating a new OpenCL4 context instead of returning OpenCL2, because there was no link from CUDA1 to OpenCL2 (only backwards from OpenCL2 to CUDA1) If the test would check for two levels of derivation, it would have failed. This patch fixes those (yet untested) cases by introducing forward references (derived_device) in addition to the existing back references (source_device). 2. hwcontext_qsv didn't properly set the source_device In case of QSV, hwcontext_qsv creates a source context internally (vaapi, dxva2 or d3d11va) without calling av_hwdevice_ctx_create_derived and without setting source_device. This way, the hwcontext test ran successful, but what practically happened, was that - for example - deriving vaapi from qsv didn't return the original underlying vaapi device and a new one was created instead: Exactly what the test is intended to detect and prevent. It just couldn't do so, because the original device was hidden (= not set as the source_device of the QSV device). This patch properly makes these setting and fixes all derivation scenarios. (at a later stage, /libavutil/tests/hwdevice should be extended to check longer derivation chains as well) Signed-off-by: softworkz --- libavutil/hwcontext.c | 167 +++++++++++++++++++++++++++++++-- libavutil/hwcontext.h | 20 ++++ libavutil/hwcontext_internal.h | 11 +++ libavutil/hwcontext_qsv.c | 11 ++- 4 files changed, 199 insertions(+), 10 deletions(-) diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c index ab9ad3703e..43e39cb2d3 100644 --- a/libavutil/hwcontext.c +++ b/libavutil/hwcontext.c @@ -22,12 +22,17 @@ #include "buffer.h" #include "common.h" #include "hwcontext.h" + +#include + +#include "buffer_internal.h" #include "hwcontext_internal.h" #include "imgutils.h" #include "log.h" #include "mem.h" #include "pixdesc.h" #include "pixfmt.h" +#include "thread.h" static const HWContextType * const hw_table[] = { #if CONFIG_CUDA @@ -80,6 +85,84 @@ static const char *const hw_type_names[] = { [AV_HWDEVICE_TYPE_VULKAN] = "vulkan", }; +#define DEVICE_REGISTRY_SIZE 1024 + +static AVMutex mutex; +static int is_mutex_initialized = 0; +static int max_device_reg_id = 1; +static AVBuffer *hw_device_registry[DEVICE_REGISTRY_SIZE]; + +static int register_hw_device(const AVBufferRef *ref) +{ + AVHWDeviceContext *ctx = (AVHWDeviceContext*)ref->data; + const int reg_id = max_device_reg_id; + + if (ctx == NULL) + return AVERROR(EINVAL); + + if (!is_mutex_initialized) { + int ret; + ret = ff_mutex_init(&mutex, NULL); + if (ret) { + av_log(ctx, AV_LOG_ERROR, "hwcontext: mutex initialization failed! Error code: %d\n", ret); + return AVERROR(EINVAL); + } + + is_mutex_initialized = 1; + } + + ff_mutex_lock(&mutex); + + for (int i = 0; i < max_device_reg_id; ++i) { + if (hw_device_registry[i] != NULL && hw_device_registry[i] == ref->buffer) { + ff_mutex_unlock(&mutex); + return i; + } + } + + if (max_device_reg_id >= DEVICE_REGISTRY_SIZE) { + ff_mutex_unlock(&mutex); + av_log(ctx, AV_LOG_ERROR, "Device registry limit (%d) reached. Please check for excessive device creation.", DEVICE_REGISTRY_SIZE); + return AVERROR(ENOMEM); + } + + hw_device_registry[reg_id] = ref->buffer; + max_device_reg_id++; + + ff_mutex_unlock(&mutex); + + return reg_id; +} + +static void unregister_hw_device(const AVHWDeviceContext *ctx) +{ + if (ctx == NULL || !is_mutex_initialized) + return; + + ff_mutex_lock(&mutex); + + hw_device_registry[ctx->internal->registered_device_id] = NULL; + + ff_mutex_unlock(&mutex); +} + +static AVBufferRef *get_registered_hw_device(int registered_id) +{ + if (registered_id <= 0 || registered_id >= max_device_reg_id) + return NULL; + + ff_mutex_lock(&mutex); + + if (hw_device_registry[registered_id] != NULL && hw_device_registry[registered_id]->data != NULL) { + AVBufferRef *ref = av_ref_from_buffer(hw_device_registry[registered_id]); + return ref; + } + + ff_mutex_unlock(&mutex); + + return NULL; +} + enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name) { int type; @@ -124,6 +207,8 @@ static void hwdevice_ctx_free(void *opaque, uint8_t *data) { AVHWDeviceContext *ctx = (AVHWDeviceContext*)data; + unregister_hw_device(ctx); + /* uninit might still want access the hw context and the user * free() callback might destroy it, so uninit has to be called first */ if (ctx->internal->hw_type->device_uninit) @@ -612,7 +697,7 @@ int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags) { AVBufferRef *device_ref = NULL; - AVHWDeviceContext *device_ctx; + AVHWDeviceContext *device_ctx = NULL; int ret = 0; device_ref = av_hwdevice_ctx_alloc(type); @@ -632,22 +717,58 @@ int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type, if (ret < 0) goto fail; + ret = register_hw_device(device_ref); + if (ret < 0) + goto fail; + ret = av_hwdevice_ctx_init(device_ref); if (ret < 0) goto fail; + device_ctx->internal->registered_device_id = ret; + *pdevice_ref = device_ref; return 0; fail: + unregister_hw_device(device_ctx); av_buffer_unref(&device_ref); *pdevice_ref = NULL; return ret; } -int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ref_ptr, - enum AVHWDeviceType type, - AVBufferRef *src_ref, - AVDictionary *options, int flags) +static AVBufferRef* find_derived_hwdevice_ctx(AVBufferRef *src_ref, enum AVHWDeviceType type) +{ + AVBufferRef *derived_ref; + AVHWDeviceContext *src_ctx; + int i; + + src_ctx = (AVHWDeviceContext*)src_ref->data; + if (src_ctx->type == type) + return src_ref; + + for (i = 0; i < AV_HWDEVICE_TYPE_NB; i++) + if (src_ctx->internal->derived_device_ids[i]) { + AVBufferRef *tmp_ref = get_registered_hw_device(src_ctx->internal->derived_device_ids[i]); + + if (tmp_ref) { + derived_ref = find_derived_hwdevice_ctx(tmp_ref, type); + + if (tmp_ref != derived_ref) + av_buffer_unref(&tmp_ref); + + if (derived_ref) + return derived_ref; + } + } + + return NULL; +} + +static int hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr, + enum AVHWDeviceType type, + AVBufferRef *src_ref, + AVDictionary *options, int flags, + int get_existing) { AVBufferRef *dst_ref = NULL, *tmp_ref; AVHWDeviceContext *dst_ctx, *tmp_ctx; @@ -667,6 +788,18 @@ int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ref_ptr, tmp_ref = tmp_ctx->internal->source_device; } + if (get_existing) { + tmp_ref = find_derived_hwdevice_ctx(src_ref, type); + if (tmp_ref) { + dst_ref = av_buffer_ref(tmp_ref); + if (!dst_ref) { + ret = AVERROR(ENOMEM); + goto fail; + } + goto done; + } + } + dst_ref = av_hwdevice_ctx_alloc(type); if (!dst_ref) { ret = AVERROR(ENOMEM); @@ -688,6 +821,9 @@ int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ref_ptr, ret = AVERROR(ENOMEM); goto fail; } + if (!tmp_ctx->internal->derived_device_ids[type]) + tmp_ctx->internal->derived_device_ids[type] = dst_ctx->internal->registered_device_id; + ret = av_hwdevice_ctx_init(dst_ref); if (ret < 0) goto fail; @@ -712,12 +848,29 @@ fail: return ret; } +int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ref_ptr, + enum AVHWDeviceType type, + AVBufferRef *src_ref, + AVDictionary *options, int flags) +{ + return hwdevice_ctx_create_derived(dst_ref_ptr, type, src_ref, + options, flags, 0); +} + +int av_hwdevice_ctx_get_or_create_derived(AVBufferRef **dst_ref_ptr, + enum AVHWDeviceType type, + AVBufferRef *src_ref, int flags) +{ + return hwdevice_ctx_create_derived(dst_ref_ptr, type, src_ref, + NULL, flags, 1); +} + int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr, enum AVHWDeviceType type, AVBufferRef *src_ref, int flags) { - return av_hwdevice_ctx_create_derived_opts(dst_ref_ptr, type, src_ref, - NULL, flags); + return hwdevice_ctx_create_derived(dst_ref_ptr, type, src_ref, + NULL, flags, 0); } static void ff_hwframe_unmap(void *opaque, uint8_t *data) diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h index c18b7e1e8b..3785811f98 100644 --- a/libavutil/hwcontext.h +++ b/libavutil/hwcontext.h @@ -37,6 +37,7 @@ enum AVHWDeviceType { AV_HWDEVICE_TYPE_OPENCL, AV_HWDEVICE_TYPE_MEDIACODEC, AV_HWDEVICE_TYPE_VULKAN, + AV_HWDEVICE_TYPE_NB, ///< number of hw device types }; typedef struct AVHWDeviceInternal AVHWDeviceInternal; @@ -328,6 +329,25 @@ int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ctx, enum AVHWDeviceType type, AVBufferRef *src_ctx, int flags); +/** + * Create a new device of the specified type from an existing device. + * + * This function performs the same action as av_hwdevice_ctx_create_derived, + * however, if a derived device of the specified type already exists, + * it returns the existing instance. + * + * @param dst_ctx On success, a reference to the newly-created + * AVHWDeviceContext. + * @param type The type of the new device to create. + * @param src_ctx A reference to an existing AVHWDeviceContext which will be + * used to create the new device. + * @param flags Currently unused; should be set to zero. + * @return Zero on success, a negative AVERROR code on failure. + */ +int av_hwdevice_ctx_get_or_create_derived(AVBufferRef **dst_ctx, + enum AVHWDeviceType type, + AVBufferRef *src_ctx, int flags); + /** * Create a new device of the specified type from an existing device. * diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h index e6266494ac..adb649cde4 100644 --- a/libavutil/hwcontext_internal.h +++ b/libavutil/hwcontext_internal.h @@ -109,6 +109,17 @@ struct AVHWDeviceInternal { * context it was derived from. */ AVBufferRef *source_device; + + /** + * An array of device registration ids from device contexts which + * were derived from this device. + */ + int derived_device_ids[AV_HWDEVICE_TYPE_NB]; + + /** + * ID under wich the hw context is registered internally. + */ + int registered_device_id; }; struct AVHWFramesInternal { diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index 56dffa1f25..09f6b1289f 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -307,7 +307,7 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx) av_buffer_unref(&s->child_frames_ref); } -static void qsv_pool_release_dummy(void *opaque, uint8_t *data) +static void qsv_release_dummy(void *opaque, uint8_t *data) { } @@ -320,7 +320,7 @@ static AVBufferRef *qsv_pool_alloc(void *opaque, size_t size) if (s->nb_surfaces_used < hwctx->nb_surfaces) { s->nb_surfaces_used++; return av_buffer_create((uint8_t*)(s->surfaces_internal + s->nb_surfaces_used - 1), - sizeof(*hwctx->surfaces), qsv_pool_release_dummy, NULL, 0); + sizeof(*hwctx->surfaces), qsv_release_dummy, NULL, 0); } return NULL; @@ -1658,8 +1658,13 @@ static int qsv_device_create(AVHWDeviceContext *ctx, const char *device, child_device = (AVHWDeviceContext*)priv->child_device_ctx->data; impl = choose_implementation(device, child_device_type); + ret = qsv_device_derive_from_child(ctx, impl, child_device, 0); + if (ret >= 0) { + ctx->internal->source_device = av_buffer_ref(priv->child_device_ctx); + child_device->internal->derived_device_ids[ctx->type] = ctx->internal->registered_device_id; + } - return qsv_device_derive_from_child(ctx, impl, child_device, 0); + return ret; } const HWContextType ff_hwcontext_type_qsv = { From patchwork Thu Jul 21 23:39:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 36884 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp86062pzb; Thu, 21 Jul 2022 16:40:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vqc/Cp0+orUrXlOmB9qxF39Or+kBWEMM5dWmSuP6sJPuOLRQNwW2qxIlHh5nz9a16CNao/ X-Received: by 2002:aa7:c685:0:b0:43b:aadc:af1b with SMTP id n5-20020aa7c685000000b0043baadcaf1bmr820784edq.256.1658446831129; Thu, 21 Jul 2022 16:40:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658446831; cv=none; d=google.com; s=arc-20160816; b=ghffgdVdEqzYPIflFlZctRtoy3LIfbrxwPJBD0LFvLs3e9IILMZmBGCgVn7hpEHlyG NmLAaY1GCEQSsD7M9zM0tvxYMP84pbvoXVGARRnynV4LiwReMiU7hU71qVAmVu0oDyci vC8LVGVLED4e0cdeB9fWm/jMxvoLZVCJ1FtxlFyseJRLZaRrGHbN0bWLhL1tLN4eSuL5 RzOwS5QMQUkyltcia78C+6/3VjulA29EFdJlysaWVQysN0MPPvGh3xQmIZb2C/nDLJI1 3ngBsz1qRhJdoEZfcueNnNtRnAM4ubHgyEViOZmECR3jfMfscSSMCt2KESAU7ZLgo5sI 3Zgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=OgXsScj6HAMTG8uMbfM+YRSH39NDH3EfLVMZU9D8dOY=; b=cFWm11wt5EchxWv4vlQrD+D6cNwzajGwwtC56/je70s3aM+EsNkuO/FopJwwaybK/M fx1L6JD8X0hQbkgJN24dO4XlWccLw3d+gvsar+mvvty806Y9nidDrXPwajOp00NqZdcN mMtwSXNG15UHBlYQpzGGdYiL2zBHJCZb9VPEPNXUclgd4bJaMIX3NMy6Cyn7tlrvvNkS JPMuJ02EKX0cdKaqzw9D5Fhkyjwk6uhbqwH3F6jW6K5mLnj2oytY6jbVtIkSvCmRDgvh XIgZTNHHs0lyHFylnH9O4y0wh1mE0HmF/RvzZ34T/jT6YbzZvF8vrzNoQnnmGT9RKkY4 IVVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=idFfIASp; 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 u26-20020aa7d89a000000b0043bbd40a8fesi978989edq.164.2022.07.21.16.40.30; Thu, 21 Jul 2022 16:40:31 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=idFfIASp; 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 84C5A68B369; Fri, 22 Jul 2022 02:39:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D692668B697 for ; Fri, 22 Jul 2022 02:39:49 +0300 (EEST) Received: by mail-pg1-f174.google.com with SMTP id 23so3009455pgc.8 for ; Thu, 21 Jul 2022 16:39:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=aIbN5Pn4e6gjan9z8hdagf1pY75fAMt2EqkcrWfqdYw=; b=idFfIASpw+3PJZx42RMWmaa2SEDpFOvBZQOtAuKT1cLqGkp8w2qLaUXxiVdUrGzplv GEzHyCo+yPmy93SaR6giEZON3Ak3FXKF6Pg1FzisNs9UlR4aiwU0CF9ZBBTOSq+DUJZ3 Tuw0B0GOLUwR34FmJdBXdTyLVbsXKiVUpZKs5PYlGdM22VwxMknm53UzuV7U2iKwKfsH JFZihFngn/oDYf5lcUwAWpBKeL+r4oqE71aH4WeBownmdbK7AG2DGPJ747goYkADGKQG afXxJpGoG0n8tRoBOmepNhElCjweuJsZuf8NsoLQvyxH6PZKUVd9CUUO9QaimbsaFNU9 zo4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=aIbN5Pn4e6gjan9z8hdagf1pY75fAMt2EqkcrWfqdYw=; b=noicdSQk47P4QQYb3b1GIWBriykwjnxYxnumT8gT6X8NQsOo+Y4ZU6zvBnurDAg82x w9Mavjhn+g+u8flQlZtinuWhKxcLYi9hLyQtxUPHnNTFIa1KzJ8pZaee/GpAtz72v1/B bJmAQPtQC1y7QGkNz3wlVlZGb8c1goARir6P29Crzz6/hvP5ERrxiiLuXCvlcI3loEA2 TMJlP41TlzYWCucR+/8Af8W97x9AKjFAuYKEpsmqHfYUBFw+7ALjFyG1/SUO1U/ryPWe pZzXEss59ZjO3jBlp6I+dGajIuQLolvkkwlkgGhTRn2a6JIllBAIbHOOK+lPMRIXacEb pgLw== X-Gm-Message-State: AJIora/COBZFDWCAG1LRPWXUSwUSOXAWFZxhYDCqxsiEJBSl918ucWC5 na4NHQ4vk9LnQy/Pf+J6UspQsJw2a68= X-Received: by 2002:a63:87c6:0:b0:419:fdbb:9959 with SMTP id i189-20020a6387c6000000b00419fdbb9959mr679316pge.556.1658446787801; Thu, 21 Jul 2022 16:39:47 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id q4-20020a6557c4000000b0041aa01c8bb0sm188196pgr.10.2022.07.21.16.39.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jul 2022 16:39:47 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <03528fce43980a6b3c782c1360c01d62f5ad7f15.1658446783.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Thu, 21 Jul 2022 23:39:42 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v3 3/4] lavu: bump minor version and add doc/APIchanges entry for av_hwdevice_ctx_get_or_create_derived() 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 Cc: Mark Thompson , softworkz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: XgFCMwPJaAZa From: softworkz Signed-off-by: softworkz --- doc/APIchanges | 6 ++++++ libavutil/version.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index b3563cd528..ba21f60953 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -14,6 +14,12 @@ libavutil: 2021-04-27 API changes, most recent first: +2022-07-01 - xxxxxxxxxx - lavu 57.31.100 - hwcontext.h + Add av_hwdevice_ctx_get_or_create_derived(). + +2022-07-01 - xxxxxxxxxx - lavu 57.31.100 - buffer.h + Add av_ref_from_buffer(). + 2022-07-xx - xxxxxxxxxx - lavu 57.30.100 - frame.h Add AVFrame.duration, deprecate AVFrame.pkt_duration. diff --git a/libavutil/version.h b/libavutil/version.h index ee4c531b80..e9eefcdb2c 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 57 -#define LIBAVUTIL_VERSION_MINOR 30 +#define LIBAVUTIL_VERSION_MINOR 31 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ From patchwork Thu Jul 21 23:39:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 36886 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp86127pzb; Thu, 21 Jul 2022 16:40:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vfMd+5kng9iNz4II3f5NEW9RfbBWOGF8Uwd87huVrjy1D6MjIt1mhgh3WH8HEBNFF+oZ/V X-Received: by 2002:aa7:ccd6:0:b0:43b:c2de:da04 with SMTP id y22-20020aa7ccd6000000b0043bc2deda04mr749062edt.393.1658446840093; Thu, 21 Jul 2022 16:40:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658446840; cv=none; d=google.com; s=arc-20160816; b=ildEnfukHxFRT/S37AzvIDxt+5rteiOVqyiPWgehJG9fcijMwQtHYebhko8+o/jjE9 FzOLUk4JJAfpO/ZuE6kDdWxb5+6v9mKqlbUmhb4jDNUDjL2frQ0hj2Zs6QziaZwJPJp8 A+Vf68uOO/foKF96l/p04YI8DV0xafzbeqqm8GsT/xQYqjZnjMJ5jrOgQt9Tngp29s98 SFojLNXg/FMIVj7YQPcV3yaWO/oH39tJAocfavO+BNeUUTtE78nsP2WZYrF+WpobKTs3 8jFRkSbruFXKLNF388MtJwYIep0JPvh+yMlx/YRHp5ZGQ+K54ngEjFDNBKPQP53u6Ftn rqpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:fcc:date:references :in-reply-to:message-id:from:dkim-signature:delivered-to; bh=mLyBavhuHet1rLscrX3VjFBii58JU/kiNsn4oR7YLSA=; b=J9NPS5I9pYqH+AZdGRSuwyKiUwnp1AsvTMBil7z7vgGNMzl2K7u2c8dAhQY/iz380J 9yqhD8I2E/REehbdpnNlbxwitNlHs6a5RlgYpISaY+vG9dnaTGy0zIcPL5zSIQS+4I/f 0R3p5mRgAU8g+zREacGoaYIe8enII3pUe/utkDkvAAWEMMPvODWC/tYdyiW4GvFFwqIH 4vc4sUWavwhFScS9gANyrOolDaNwx06fqR1+ohdNI9mi2edgRDAbqczNwp5ZIU3UCyoV qCP1IsUDU0HioejITq8eAYA4iUSAfc2UlOr8stNhiC2crBQehs6GJuDLB98ytUpw/Hz2 +wzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Kow1SEBN; 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 u29-20020a50d51d000000b0043a1efc97adsi3584123edi.220.2022.07.21.16.40.39; Thu, 21 Jul 2022 16:40:40 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Kow1SEBN; 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 8177B68B6EA; Fri, 22 Jul 2022 02:39:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E0B9A68B6CB for ; Fri, 22 Jul 2022 02:39:50 +0300 (EEST) Received: by mail-pj1-f53.google.com with SMTP id p6-20020a17090a680600b001f2267a1c84so5029487pjj.5 for ; Thu, 21 Jul 2022 16:39:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:in-reply-to:references:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=LiwY9esjylXEwphM8sKD7BmHNam7jJI8KTt+HXBYNik=; b=Kow1SEBNB4mMS+H8LGS6ZP24cubcPEP8GsLAR8SojbkPapkmJ9YICHsEgztdEX3ch6 T6mXCNihDFycLFkrU1lPlfjrT638L7Oj5E/eAQvhJ+pi/K68b7Fgc3YZ6IWWOk8Pwld8 4wu5sqqEVPZnutjBffx3Xia2lPzOjNdqIwYkQSwVUClGQEykA4jh0EcPUXS8rWPvWXqv q018SfCOjmj1r/bQtJJ31y5gdME2jO/ILCVvAcA29nzaTnmB5c4JBaj818eEcynSstcs K6I7pvqH1Ytb2O/wwxDOJkeNFdhg7vLrADijc95hUUJk4Z9m1XVXlh/f1KJR01OvtSdI z3iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:in-reply-to:references:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=LiwY9esjylXEwphM8sKD7BmHNam7jJI8KTt+HXBYNik=; b=nJ6wWQ+78rSYzx//c3L56NEVjf8xGhTsSSGzH95R9G/xe264lrD6HCZISGWUEkaRIn Rcj60kOzZnbKLNyC7QW/srw/i98CShvaIox7iwgH9sivApv/WXTOrPIxajvKeXYb1HtI zcuA/zfjGufWaoaXEhFFQJbDyGRKp3UuInWwXePSGFsItpIoz+QCrqD/rVHX+IGxL9I8 /lP4fu9xtxzqhBwpUxsqj4fENsvE1mmiEDDc3XMJVAAyXZC0gw2s0wlbqDebmzfr/TMN Ubx6kn5kmIl6ZuTLW5zJPLvuAxmM2jwvtMvFKvUXFY2L92UJ1TTq3eq1zzWbj/o3l49/ ZuqA== X-Gm-Message-State: AJIora+NKVFxufYxwfXh93pmDJuoV61yo5UKpnDyy1sLIeSMHWI6Qeg6 U4sAG0hhZPMyMhw9tZ5ZlHKbkVCjc0g= X-Received: by 2002:a17:90a:e4ca:b0:1f2:32e3:e13e with SMTP id e10-20020a17090ae4ca00b001f232e3e13emr887485pju.103.1658446788755; Thu, 21 Jul 2022 16:39:48 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id v4-20020a17090a960400b001f004ba93b1sm1977524pjo.27.2022.07.21.16.39.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jul 2022 16:39:48 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <7ee28b7c25ac6aeb0567b036c24d7d3bea3b733a.1658446783.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Thu, 21 Jul 2022 23:39:43 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v3 4/4] avfilter/hwmap, hwupload: use new av_hwdevice_ctx_get_or_create_derived method 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 Cc: Mark Thompson , softworkz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: qCwf29NtXisB From: softworkz Signed-off-by: softworkz --- libavfilter/vf_hwmap.c | 4 ++-- libavfilter/vf_hwupload.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libavfilter/vf_hwmap.c b/libavfilter/vf_hwmap.c index 2e03dfc1fe..b79cf6732c 100644 --- a/libavfilter/vf_hwmap.c +++ b/libavfilter/vf_hwmap.c @@ -82,8 +82,8 @@ static int hwmap_config_output(AVFilterLink *outlink) goto fail; } - err = av_hwdevice_ctx_create_derived(&device, type, - hwfc->device_ref, 0); + err = av_hwdevice_ctx_get_or_create_derived(&device, type, + hwfc->device_ref, 0); if (err < 0) { av_log(avctx, AV_LOG_ERROR, "Failed to created derived " "device context: %d.\n", err); diff --git a/libavfilter/vf_hwupload.c b/libavfilter/vf_hwupload.c index dbc41734cc..41ee0e43c4 100644 --- a/libavfilter/vf_hwupload.c +++ b/libavfilter/vf_hwupload.c @@ -51,7 +51,7 @@ static int hwupload_query_formats(AVFilterContext *avctx) /* We already have a specified device. */ } else if (avctx->hw_device_ctx) { if (ctx->device_type) { - err = av_hwdevice_ctx_create_derived( + err = av_hwdevice_ctx_get_or_create_derived( &ctx->hwdevice_ref, av_hwdevice_find_type_by_name(ctx->device_type), avctx->hw_device_ctx, 0);