From patchwork Tue Dec 1 21:26:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 24229 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 61E104494A6 for ; Tue, 1 Dec 2020 23:33:39 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 35277689A59; Tue, 1 Dec 2020 23:33:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2999F68810A for ; Tue, 1 Dec 2020 23:33:33 +0200 (EET) Received: by mail-wr1-f67.google.com with SMTP id p8so5111758wrx.5 for ; Tue, 01 Dec 2020 13:33:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=to:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=FV/4sk28U7QrYKh9SOWCOgLRl8YdZv92d1JKvS1gBkk=; b=RvlhWg27cR6YvnmRJXHHCVtX2PA7r2quI/PT5M9vDdqT2S157koxFTowBVeAnRXD9J NDAV/SRRca0Sy08u55GNc4REZqTpr8XvD/IyXJozHR1refRgxAf58R3UUCdkJlTYootM o2nlRNM64wTvVRI80c+2qTBRpxOpGsnbe+B1q5XlkDio5F2hr8bY09+WK5hpggfXzOtv CyY7T7MRwXs6YFJerP1nbKvYI6z0InjU1RSWTtn95Ib9Snmhd4ue25Ww4nfzTMykltEl 6VaGF5RPx4o0kYy5Dq4YWIbelzxTV7V5Rvme9bnT0+rw1wghJ7/UZtk9luCmWUAOTsCz m9kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=FV/4sk28U7QrYKh9SOWCOgLRl8YdZv92d1JKvS1gBkk=; b=h+/r6GuL1mYruzUVzcZD17h2PGhmfpuxn3YLO7E8F4b5zL9meNR7ADkwRbmHXN3AcG s2K5nS+2DtdQw8cyBeWvvlGhqPHqNuo8vD4vV6AxaWHU9K3js8757Gi7KwNJTRbiaANn 7eaNW2OhM5ZjT3JGx3bAe3l+b/XWD/Fr5+/ErlliIq3ZSj3XMUMwxqAgpk6S4FE69dPe iMavldGcu/IHDTGnGWCYWIx3gOFkbb58whiQ7wDFocGLBKOr61xoOV3Z9mH1vvrWnTvj hoNtGn+izwaEB7H/BOo6j1CxOvOgm5NM2nGi3HVryPdhN45NNjehgqKjgTQLUhlMALWM oNKg== X-Gm-Message-State: AOAM533yvPrx5iLYsv3XMRff+8LTNc6m2XT+3osY+7BpuN2x17Yr9U8d xVXxQb1pH66aVzLdu2SzQGwB0AN9vk9wQg== X-Google-Smtp-Source: ABdhPJxEvVzeCOcIhwVs+QND0v2xggoe10WjjFyudVLb42AzoManWvYI26t/RsTjPOexRlpGkqXUpQ== X-Received: by 2002:adf:e48d:: with SMTP id i13mr6521702wrm.387.1606857967986; Tue, 01 Dec 2020 13:26:07 -0800 (PST) Received: from [192.168.0.3] (cpc91226-cmbg18-2-0-cust7.5-4.cable.virginm.net. [82.0.29.8]) by smtp.gmail.com with ESMTPSA id j8sm1334818wrx.11.2020.12.01.13.26.06 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Dec 2020 13:26:07 -0800 (PST) To: FFmpeg development discussions and patches From: Mark Thompson Message-ID: <484c6644-dfcd-1ad9-95fe-4bf2a06b30e7@jkqxz.net> Date: Tue, 1 Dec 2020 21:26:03 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 Content-Language: en-US Subject: [FFmpeg-devel] [PATCH] hwcontext: Return a sensible error when deriving an unsupported device type X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" This previously returned ENOMEM because the failure was detected during av_hwdevice_ctx_alloc(), which is not helpful. Check earlier in order to return the correct ENOSYS instead. --- Before: $ ./ffmpeg_g -init_hw_device vaapi=d0:/dev/dri/renderD128 -init_hw_device dxva2=d1@d0 ... Device creation failed: -12. Failed to set value 'dxva2=d1@d0' for option 'init_hw_device': Cannot allocate memory Error parsing global options: Cannot allocate memory After: $ ./ffmpeg_g -init_hw_device vaapi=d0:/dev/dri/renderD128 -init_hw_device dxva2=d1@d0 Device creation failed: -38. Failed to set value 'dxva2=d1@d0' for option 'init_hw_device': Function not implemented Error parsing global options: Function not implemented libavutil/hwcontext.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c index d13d0f7c9b..4a307369c4 100644 --- a/libavutil/hwcontext.c +++ b/libavutil/hwcontext.c @@ -139,19 +139,22 @@ static void hwdevice_ctx_free(void *opaque, uint8_t *data) av_freep(&ctx); } +static const HWContextType *hwcontext_find_type(enum AVHWDeviceType type) +{ + for (int i = 0; hw_table[i]; i++) { + if (hw_table[i]->type == type) + return hw_table[i]; + } + return NULL; +} + AVBufferRef *av_hwdevice_ctx_alloc(enum AVHWDeviceType type) { AVHWDeviceContext *ctx; AVBufferRef *buf; - const HWContextType *hw_type = NULL; - int i; + const HWContextType *hw_type; - for (i = 0; hw_table[i]; i++) { - if (hw_table[i]->type == type) { - hw_type = hw_table[i]; - break; - } - } + hw_type = hwcontext_find_type(type); if (!hw_type) return NULL; @@ -652,6 +655,11 @@ int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ref_ptr, AVHWDeviceContext *dst_ctx, *tmp_ctx; int ret = 0; + if (!hwcontext_find_type(type)) { + // The type we want to derive is not supported in this build. + return AVERROR(ENOSYS); + } + tmp_ref = src_ref; while (tmp_ref) { tmp_ctx = (AVHWDeviceContext*)tmp_ref->data;