From patchwork Sat May 21 14:07:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 35875 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:9992:b0:82:461d:f3b with SMTP id ve18csp1081724pzb; Sat, 21 May 2022 07:08:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqXat/j8mPXyu+v5/cl4Jkh3ATt8ZDkoPkmTpuOyR8PIQVis+PTYYrHK8AZ9DQbARMVvFP X-Received: by 2002:a17:906:264d:b0:6fe:a134:59ae with SMTP id i13-20020a170906264d00b006fea13459aemr9455969ejc.56.1653142088408; Sat, 21 May 2022 07:08:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653142088; cv=none; d=google.com; s=arc-20160816; b=w6qa0qX3D8gF4YOj8/KU/PJgafEoadddCru0z8X7YkoKkZC0IFDdUjEwsFyWNmYtgs 1ZaDBDTKNs9qdi2soLW8QxizAdDLb9DyxUopVUEApfNifQIpRTWF/gj3G4ns/fr933Bf qHh7gdAckwmUvvrkQ50Ej/t+jr1LNlL3iY8bG+ewp8Gpux6advvUBsEpkrM+0lTN9bVv krjij/dhFb/fPqDSLbr+Le0o9Fqn5rkYJ49SNaqZAKi1PgBw0CPeV2sN3SUN4QBYGO2V W0vAhG5e2JI7RA3/GtPgo++bqe8W0zgCAz4tE/pabg/mEQuWiiCk1SCJGuDIxVkJdwWs RR9A== 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=RFhjK2+r0cUTs0FVefIxmnI7iEJ33O16n0URN8Er3hID99r/Yfv+83tpfMuFNl5BM9 avUbTDCVtGm9J6FEc/5D760r17kr3MLoRCrvCux6XAJwLw9sJ9GQ6/frOcn28H7kDkEe VwMq8twiBnJMByBxkqifQresTD+ecmUOzTYt6zKhUgyrhC//8HZHkbnfV9HpEJO/uScn 15HMsUtL+EG9AispeJUvqBo1AUmP+aG/jVyzKfOzi9U1Xl1XI6chMvoYvuMmvhBR+6Wz 5YzhfrP1GEgfaPYp/BY+m7ERMXGXziwj3pcraEExuGJOFNdvYUKUJ4t5QvEbh4iV466o QFpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=DSJjhDoC; 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 t12-20020a1709067c0c00b006fea05c0ccasi1482767ejo.680.2022.05.21.07.08.07; Sat, 21 May 2022 07:08:08 -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=DSJjhDoC; 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 803EB68B49D; Sat, 21 May 2022 17:07:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C74B968A2F6 for ; Sat, 21 May 2022 17:07:46 +0300 (EEST) Received: by mail-pg1-f169.google.com with SMTP id r71so10020299pgr.0 for ; Sat, 21 May 2022 07:07:46 -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=DSJjhDoCgSCH9tNBPt5pusr5jJqhw5HmmZ4R2KjXDcfNVjyYfiHD0E+xMydA27w7Al R9HoiGX8kuaiufELXVcJwMQV0uCQVJkHzIOV6+BQWwEn+qS0kPNmxUuTXaK5DQrFZNJk bWhyX9xry2C5m1Ywhp4YKYdy+f9YMqxN15FX2mvZfIjm+90raU0B1qgW4pjwJFC7HMDU C+mbsXC0lNU9Rz29+23Od2mGXP0Ix4FJnPgjWCKqGVR2xZNbz368OZQa9N8ts4VESmZ8 syRKYyzyVfYeyuZMaVZgefTV8ZACFfSDHznryeRetLZfeBtypcLuBaxLxnS3kuNrjZg1 N4zg== 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=glbcjF9CFRqzSAEMNzPG14PCgznpCkOakrWMbitIaJa+Lb3fNGm/5gvdnyFMtJBElx h6xhV2zeuz0u8tNQSIA1fcBo6BvQDm83EWah1SsSYcuH0zggsnUr8vOpgYHBRBHOW4AM Snbujdk+qbXAKJnvvu4G0C/OXxDsBMp8reuBmyyaL/95VR8jlXvQcMi8hXc2EMjw3vOU 6Nb3IgG0yRoieqDtz2yTLUh0NRegN+ouzBT/orDdhhgBtsAL+2h5KEe07ueVNWA9g39p lpZXvExz55UYMFfrTM9/Ta92L7YPkTFU1BqjwAE+nD6ChmlVZW/EWN2sklv9jwTv6noj BJnQ== X-Gm-Message-State: AOAM5314rDnTEdmk5cF1Sh4dIegs98lpjrNa67/aCewpHR2T5ULK4lgb 9SPmCnH2rFRK8LW3rITKGzSenxcfYuwJTQ== X-Received: by 2002:a62:be14:0:b0:505:a43b:cf6e with SMTP id l20-20020a62be14000000b00505a43bcf6emr14945217pff.33.1653142065067; Sat, 21 May 2022 07:07:45 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id 21-20020a170902c11500b0016173113c50sm1643120pli.92.2022.05.21.07.07.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 May 2022 07:07:44 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: In-Reply-To: References: Date: Sat, 21 May 2022 14:07:39 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2 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: 2LZsRedkStCb 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 Sat May 21 14:07: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: 35876 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:9992:b0:82:461d:f3b with SMTP id ve18csp1081809pzb; Sat, 21 May 2022 07:08:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDShxpkOYW8xF0xlbrUyWI+3rO8t1oFKNvF0nMSdLRv48I2FpJhf4akAduRjYDQs1O4vNk X-Received: by 2002:a17:907:6d06:b0:6fa:8499:66ce with SMTP id sa6-20020a1709076d0600b006fa849966cemr13172062ejc.718.1653142096764; Sat, 21 May 2022 07:08:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653142096; cv=none; d=google.com; s=arc-20160816; b=KZ8IPPPop/+b2UxIOgsihaFRr0R04d1I5bbF166Aaz79ff4x1hXYT3X6q/a+z52KaR 0SNguPnhZZ3ENd7Uh5d8gnFOgo2Fbt9w9AiyOv6ziECLF59j7H7wxlYp2MUD8yp1E4jW lUBWw8iAli4X2QpiiX2rUz+qxFgVtP+nfsr3U0IDmokygh7MQfIIyPauMKcwl3kYDG3m 9PDNiarSzd9dTD1z6HpvC8CeMGD9PL35fA4YIOveDuljnxu346K8qmSorGeKyEjd+7Mz jpJumdCKHLqtrJB/7NtbzynvSjBPD8utZblvUE++X/qLl5ar9qht04rjucux2yG7gO/q iNvw== 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=uqY240/thdRswmNC5lRyiPwAarze5IRq59soV5HyfNc=; b=eEvfC/7PDiuorHwfDYyJOqTETNr4VdzFQLPrImC2IhP37gAyL+hGK+6oIJm0vc8WyG wgkfZTY2xEhOOe7Q3o6jSu9YyX+mYdgbB3JtnyxeCxfB9aGYkOw03QXjG4aly5S9OI0e KwcbEYNqObWgCbinM0KHAIyb2GPRXR7lsymW3MXl8oMKKt2u3sw1Xix3kQRGdYOzBZ7X k5yFVqAD3jQ7C21ijFR3vzvuxIuih/SLBjEwukegKnriDiKf5qEFOnKT2dFHnsyjR1Rh 4l1q05bFbEfyo0Wx6NqNsif+C6jVgSX2stwsA3L236+iLha66DASmkOYZRvOKG/EuCQw FhgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=YoXsSbEZ; 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 y5-20020a056402440500b00427ad71530fsi14429090eda.528.2022.05.21.07.08.16; Sat, 21 May 2022 07:08:16 -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=YoXsSbEZ; 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 99DD168B475; Sat, 21 May 2022 17:07:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0E1AD68A2F6 for ; Sat, 21 May 2022 17:07:48 +0300 (EEST) Received: by mail-pj1-f54.google.com with SMTP id l14so10255475pjk.2 for ; Sat, 21 May 2022 07:07: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=u2gEFs/dHnEVna8RkQ8KbNasCai+Mdvz7MO5iZtNvzc=; b=YoXsSbEZv+q51mIMzE99HZgR/xP634caG8ErGrhDKiIS0tSOBB8YRHJR4WRhG6T21/ D+/ObABc+IPt1rKWFQ1a2ZboYlT8+LfLhoFP9aSYyxcJMPGzs0phILJzJ5FiyGQ2BrDD CULstTQzkJo8XYnrV4+MCuO+hvLOTwtQfIkVutXzKBBjgXgLZkUsnqlLN/PvZ7bJL8+9 BfLolS9z/UhpAVI7zr8iMS4qraAprtKWpJaHR508sLZceq8fOpULTfa0jZ3AQnG6OrxM 6RW4et0CCSfsVl2ajvWdCYaOSxWRxlxblcDA1p3A8Ipv6VSmCiqRSqQz+LK+qMflbRz4 5Kig== 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=u2gEFs/dHnEVna8RkQ8KbNasCai+Mdvz7MO5iZtNvzc=; b=ZZNDDn3ITmdsJwdNvB1cRvzCg5b13YOS6ozh9t8LDk9lig/AfCVB0dCif4ZZ+l+NXP luLqxEoxTSXmervC9d/Hu5q8FmaiSJLlWMVifyZW24D16Dl+Otf26djBL7ep8BmgYC1O /BrrYdvY2Yf+e/z1CzZ+9UMozMPegWz7/j+yfT6rx5DBUQlGvGfsJXiGGjDbAUF7Ecp4 dl2UqNNfDn0ltRF3ICUvw7w0gvxj949yKhXqvTcMTs7OgMQmPDAFpg6LOiUWf7+JOxNg u8b5vnbzM8UhcWxkjUXKQxqF8l/kPuVY2gyXdbvwdTTzTaKYgYg69b5+Y5X561gEizHA ge6A== X-Gm-Message-State: AOAM532hI+nprGofrepJ3nqEBYMZKPVYlNxAOSvUkjKEwus4p1lPTpJF /s77UR0SVGiKEKDtOwP1tvMc5WbYgYhxpw== X-Received: by 2002:a17:90b:1e4f:b0:1e0:b91:39ef with SMTP id pi15-20020a17090b1e4f00b001e00b9139efmr5177971pjb.51.1653142066264; Sat, 21 May 2022 07:07:46 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id z124-20020a623382000000b005183cf12184sm3583638pfz.133.2022.05.21.07.07.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 May 2022 07:07:45 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: In-Reply-To: References: Date: Sat, 21 May 2022 14:07:40 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2 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: uEu8sSTludv2 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 66c0e38955..423b891ec5 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -309,7 +309,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) { } @@ -322,7 +322,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; @@ -1649,8 +1649,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 Sat May 21 14:07: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: 35877 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:9992:b0:82:461d:f3b with SMTP id ve18csp1081903pzb; Sat, 21 May 2022 07:08:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzw+koqxgHckApdIWKh3gvfwnHKBLgtsUb9wU33eeE3b4ipjG0ffOFC0wvGkZv6MVah2BJc X-Received: by 2002:a17:907:3f1f:b0:6fe:b40a:21f0 with SMTP id hq31-20020a1709073f1f00b006feb40a21f0mr5873967ejc.744.1653142106770; Sat, 21 May 2022 07:08:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653142106; cv=none; d=google.com; s=arc-20160816; b=Wdq6E1uwfDgaLv9JfFaB2c+mNUTSESeJiRz+FBJ9NGECd5m2JqehiZ0NWlVW+d+tKu kvoKuP+wXtiy94/i/sfgG2/ASqGRkRs4OMtdWzsmCS+nxR/yxgoos45uOOSRTuxE/hEe r6Xb20etkto+r6v9/x+BTOmnJ1nnq88virS555TqQwpbsrBL0e82vZYxT9XKdiYIbVJO mEml5VKlB6k7obwNYkEVJkz1QmROTNemhtYMYEZzIl8bHZs+Bj9xH4deRVJ3e1EDDNbT Q33MPSA3JNp45eW1MiRZmNuHET44bRyMmstfofXmw2pnZETVNuWvsBt1WkY0RPuLl8Vx ehFQ== 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=VBzOpO0tQoG7hQ11RleuEr0oLQW3Ek9Ws4RKAnRT0I8=; b=nBQRaH+nkO0MxOolLkGBk8syxCwaAZmGZeqAdc3+nWNslckjYE+ipes+XcudclQinM nr1hGxI32E22SUeFswbomdNeYByC3cNnpFa+O00kwqFzSZnpjoJB8NisQh5drmA80TAJ qASyitjOmAnImn4A2mQtkIa9ii7HngYG87IED8su8CXA1q05GQ26Y2arT7HYABB553QJ n1fdO428wAYL9e7DinNlbWJzCsUXRdGlXrNV7ezF0QKvt72AVIK9Rc7ctuVYAoRNNvDs tedajb3pkDStBCK93t0nhHyCFgJd5frG3/6MGYWYvNGJ/fjuzvJOHbL6+c7+3VuWhMqA zmZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=TbHsblv5; 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 z10-20020a05640240ca00b00427c9262a1dsi6535861edb.28.2022.05.21.07.08.26; Sat, 21 May 2022 07:08:26 -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=TbHsblv5; 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 8F15768B4D2; Sat, 21 May 2022 17:07:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E642668B48A for ; Sat, 21 May 2022 17:07:48 +0300 (EEST) Received: by mail-pf1-f180.google.com with SMTP id p8so9929196pfh.8 for ; Sat, 21 May 2022 07:07: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=xUN2IOaq9cmR6iPAK3CamDiar2FEwtfoV5/bdFBOIts=; b=TbHsblv5sHLbYff0hnWDTVYbrjKaSrm6p72u5/ZrQ1MFPCQIhwye03JHWvDliJZCVN E+DtY/hNvtau6o1c5ESTVoN1dzAx+kF/Pe7t5YnL3tYqbry8wV2nBlmXbWOY8mkL56nl wi7EX+gc8bzRXl0QUWLQJHtLrgU3AHQhEqHI0EKv77Bge627tB74Ms1DkBBSI+fEMpZ0 N9Sa71zncB2i5TrJW3pDQO1SKUAZADuePdj6kyzJRqHkeiM8lIaSZ2oTUoziC69Aqx82 gzIPj9Koo5TkNTQHv3XTqGtdvAPTQEnBidSare8vPFL26jEuwU0a/OAmvAJrJ3fuiEK/ I/NA== 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=xUN2IOaq9cmR6iPAK3CamDiar2FEwtfoV5/bdFBOIts=; b=qgGAa/YvauxmHidjoTdxv2+5Hxj5RotOZVjqm9jSF6MfX31yGuGDhuHSvVrAYWEIfl uATK9UVtQVhzyF9CbjCHv+B4uiqv98Mg59/Dv3TYOHj6EeKT1be5cY4cT++p6S3cwY7G Rh5W77TV5oBy4e546go3P02qkrCaHCCjvhPiMagUoGwuk5Gw68wb7L0zjahIEMVbbTq+ b6N2192sfC88F3qfOBUqYx+QGu0La/2TIxIEWQUOKVuomR/OGBIwx59KH8K4xWsiZGlN p2ZY2jS4EeezYLnv31FEDJv0s7nY7rv67BrWS22PpgKMy8FQFY0Ytl24nAeW9s4MABNn 2ebw== X-Gm-Message-State: AOAM531L1VJR/dFHC7hHPGtiGx6mbVF0Yk5wyEW+p5icSSkMAKSZuN7V GNiIlyVD0F4izyrCvsa9rM4pK6Tdho57Mw== X-Received: by 2002:a63:fb50:0:b0:3db:a519:1f84 with SMTP id w16-20020a63fb50000000b003dba5191f84mr12855429pgj.61.1653142067298; Sat, 21 May 2022 07:07:47 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id w12-20020a17090a380c00b001df1f7c5941sm3767638pjb.16.2022.05.21.07.07.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 May 2022 07:07:46 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: In-Reply-To: References: Date: Sat, 21 May 2022 14:07:41 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2 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: NoPUlYAO+nvi From: softworkz Signed-off-by: softworkz --- doc/APIchanges | 6 ++++++ libavutil/version.h | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 1a9f0a303e..92b6d70ac0 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -14,6 +14,12 @@ libavutil: 2021-04-27 API changes, most recent first: +2022-05-21 - xxxxxxxxxx - lavu 57.25.100 - hwcontext.h + Add av_hwdevice_ctx_get_or_create_derived(). + +2022-04-30 - xxxxxxxxxx - lavu 57.25.100 - buffer.h + Add av_ref_from_buffer(). + 2022-03-16 - xxxxxxxxxx - all libraries - version_major.h Add lib/version_major.h as new installed headers, which only contain the major version number (and corresponding API deprecation diff --git a/libavutil/version.h b/libavutil/version.h index 6735c20090..dd7d20a9fa 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,8 +79,8 @@ */ #define LIBAVUTIL_VERSION_MAJOR 57 -#define LIBAVUTIL_VERSION_MINOR 24 -#define LIBAVUTIL_VERSION_MICRO 101 +#define LIBAVUTIL_VERSION_MINOR 25 +#define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ LIBAVUTIL_VERSION_MINOR, \ From patchwork Sat May 21 14:07: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: 35878 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:9992:b0:82:461d:f3b with SMTP id ve18csp1081975pzb; Sat, 21 May 2022 07:08:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMV3s8qyI4xQR7XXcVCo9E+/kHxJUCjCgmR5OB4LEfaI3Dn8iQVORb38zCY9HJ7qKAuQ7w X-Received: by 2002:aa7:c849:0:b0:427:d464:e66f with SMTP id g9-20020aa7c849000000b00427d464e66fmr15810613edt.411.1653142116227; Sat, 21 May 2022 07:08:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653142116; cv=none; d=google.com; s=arc-20160816; b=RyGg8MSvPBDT16yqfIqNJI5PlJObqTmW2tcS2av/4S9OOu7Rtkk5T0v77uws6PtPR6 PPYPDCr3FspjAVyyujdveRXg3NtbblEOyq8RBHrvOqQvsNwujjJ1ET96Gtq0vbTi2cTe FBnDa32EfCnmx6owEWc0R1pQcQOfqijXdOHGZFMJjVkHO3ppXEUwKcah6RqcxSMntBTu DktOogCDvxyUEvI15V6PNTIxaLdHaYkt9LUM97DdW9vpeyok3a34sK0402m0DaNKsFpm oBEul4Wq4OSXEh/4pzpJ3LoYhIXrwUa0PQOxBDzIQcCnrgXDAG7Ld91BIc6SVt/YrFxh /vYg== 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=OvoApCJcdiCk/TZqGfG6MmcalV+D59akfbuhVDd4tUWxm5MlPJFOjDMSsHx0C23inv YAiI+gSFr/YN6eUX5F+n10CiyYa+FM2i1PXCfprV7skv3ELP8wM+JgW7P5yJOQy7bmRf x66B7CJ0gvvk3zY2CpkEs8CUCSaF3tN+gNKyJB7bhZD9eEglsXTbovjRwnzerC9mOMCH LQ0NGUhTQxXVWTQ6V+gXJkQvPW40vcatoeVr0YvulvKFUum5Xp3qJvF8glVHLARh+HWu TojSv6IRwCZoNDgN/wwm3FIdDB0rFkaSjIOSMOwc6SPjpzt7A8qVrVGy/c3TApYSynvP TBJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=XoqrRDRQ; 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 d22-20020a056402079600b00418f11819a9si9448148edy.120.2022.05.21.07.08.35; Sat, 21 May 2022 07:08:36 -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=XoqrRDRQ; 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 7B77F68B4B4; Sat, 21 May 2022 17:07:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1343C68A2F6 for ; Sat, 21 May 2022 17:07:50 +0300 (EEST) Received: by mail-pg1-f172.google.com with SMTP id 31so9972718pgp.8 for ; Sat, 21 May 2022 07:07: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=LiwY9esjylXEwphM8sKD7BmHNam7jJI8KTt+HXBYNik=; b=XoqrRDRQ5f35P5qN102J1qVrhYJieNGKCz/oF2Ktsg+aznMTNjrrhkbjpgNV7fbB+r 1KVB1qbTKgS8Z33kYrm0e0d4eDi5sIN7dvr8z+8jwkqAcaMQtuHxBfpvT44TiNSa/kU3 pfKgzmaGrFQ7BJMRPVauEBH1Z+GJs/0/4dbDIl4dUkwJkSQTxvo9YiZbFkFUbtqXwst4 FncXp6ZWdZA/LoJCY8Q6JarxP3Ls2vUrHiRbKonEXXIG25uo2gZA6i4jNfzJoeCLotfR CRfpVBQQLz3L8E54OfJqBp4vKYKYYxrmlEzQ4Vki0BAmcU7Z1pJnnWywe7/sO5TuK6DB mX4g== 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=TpkBSi+LpqR4/+bKLOrD+DagekAhEodrIbsVPPJ6YWbf4T6fsU+0sWZvaqf/RtUc5S IwOJP0w5znKZQqaNOPqeNAafCQflnSw+2YoCE4DF+nA/60ggbhHoGRHMTJ3v9OMNYc4M DnkE2iaRsluch20fRVGFGUgK56MhvdONzLX+np/HZ7PtJRxJE2xz578BALXi5g6aD2v4 mK5eoyg6658iqlAVh8mh2VWXH5QO03+2XyrwkULfP1SnXJrwGb1JKjJm2H6qCpa/9czX 3HB98R4qeNVwq+Q9ZZcYeLqZNZx1ZS7x5i3qkUy5aOvQPMkrY1bZH7qOqEOQIELdzHaW cF9w== X-Gm-Message-State: AOAM5319ELrvgZGpCazbtQnDahUbi8N/+EMx97CLfaa5DiYp0ZJCDVPg kr0xQaH9d3qmsh5DrJcVcINi1p/mbgXT5w== X-Received: by 2002:a63:854a:0:b0:3f9:ee3e:5769 with SMTP id u71-20020a63854a000000b003f9ee3e5769mr2712438pgd.450.1653142068280; Sat, 21 May 2022 07:07:48 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id g11-20020a170902e38b00b0015e8d4eb1ebsm1650619ple.53.2022.05.21.07.07.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 May 2022 07:07:47 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: In-Reply-To: References: Date: Sat, 21 May 2022 14:07:42 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2 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: 9lu/5kOcFcab 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);