From patchwork Sat Nov 11 15:21:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Rothenpieler X-Patchwork-Id: 5980 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp219240jah; Sat, 11 Nov 2017 07:22:38 -0800 (PST) X-Google-Smtp-Source: AGs4zMa8QOEAZWOQn6CKTID++4Yr38qSdnLPa8y0xocAdcutC6eHBA487AefKkcZCvSIpFHugNom X-Received: by 10.223.160.132 with SMTP id m4mr2979288wrm.45.1510413758097; Sat, 11 Nov 2017 07:22:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510413758; cv=none; d=google.com; s=arc-20160816; b=PLtg/QfdGJZGKCnxFdXoR5XQnUsB9w4aIlTmemhNByp2Jkox8XkLHiouszA7mT2UIb Y+2YiaV72GCC7yOyk1vSCwGuo36zjkOM+ZzugimgwS0QjGeH4GnKYFfZ8IISnwq1juqB K/e6/hLLHOZf1ByoB0Ss0QwZTnCzgONAjNrcMog968CNT/qOeu8aqBxS0nYtWFERV8cF qi5ySoSaavOASX1++C52ICJDkYVf5nUPyKPzhR7U4yr6ttYhO/NIMuH7t76Z4CzYTk+z Il45mzuWIlXAg6eP/3TJkClFu85r+PbQrW7p72OZr3QlphpvvcwMG00gl7KnNDTh4l7K 9d1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=SIG2iUmh9YDw1d4CvW3AX/ya3tzLOz/5i3OLSCb2qM8=; b=FqmognJYWcwZceFWgF2uAVE41c6r4uOlWhrwXuZAsvKIqOfhCFVtLQKZAZ9laAmZMD Rla10xQiMcKdn+s9X7FFYDKO6JUlg2dgQkgFNHG6FK7PEr3dUa2swDXdRm5yHNnbzkiE YuY5DYOoAeKIPp1XWDOkDdWRHBi7IBT/UeH8zVxKJSJut5piWyv8kX6OsiyYVo8O5eDD rtNeu2N2uh6M4WV5vXeWEJZht6Od62NcpZkK7OY5l5YkwqhTrLRB0pb9gfPILamtZ0Mp tVICknH5Ar9cayw2knoAQayU3HdrEGOe8b79uLYVCBxceme3dkov1QRFr+3AInHHyfAV m+3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rothenpieler.org header.s=mail header.b=qYuN9va6; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f15si3271044wmg.4.2017.11.11.07.22.37; Sat, 11 Nov 2017 07:22: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=@rothenpieler.org header.s=mail header.b=qYuN9va6; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4635F689AC7; Sat, 11 Nov 2017 17:21:54 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from btbn.de (btbn.de [5.9.118.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DEB4268973B for ; Sat, 11 Nov 2017 17:21:46 +0200 (EET) Received: from localhost.localdomain (unknown [IPv6:2a02:8109:43f:959c:ba97:5aff:fe10:ec69]) by btbn.de (Postfix) with ESMTPSA id 8EBDF4C071; Sat, 11 Nov 2017 16:22:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rothenpieler.org; s=mail; t=1510413720; bh=hs7ikzs06S9kGonnRjA/r2qrknhkWSQClvTuGSXv65Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qYuN9va6BbWNoYCbosYRqWGhoY7hhuQt84yZ1ie/Bye6rMY7FDsYUj48hf9LsgeSW UDKXwUkDo+8R4twudGiMODpl9RloxzyXZMXbT+MeBRG+7bd7g6Z+Fo/1vTNan4rre1 qnMfQi/bBcuaDZRzt1Vvs/mwks9xgEoFFglYgEzA= From: Timo Rothenpieler To: ffmpeg-devel@ffmpeg.org Date: Sat, 11 Nov 2017 16:21:39 +0100 Message-Id: <20171111152139.14394-4-timo@rothenpieler.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171111152139.14394-1-timo@rothenpieler.org> References: <20171111152139.14394-1-timo@rothenpieler.org> Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/nvdec: check hardware capabilities 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 Cc: Timo Rothenpieler MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavcodec/nvdec.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c index d3620f0d1f..d706540db0 100644 --- a/libavcodec/nvdec.c +++ b/libavcodec/nvdec.c @@ -74,6 +74,56 @@ static int map_chroma_format(enum AVPixelFormat pix_fmt) return -1; } +static int nvdec_test_capabilities(NVDECDecoder *decoder, + CUVIDDECODECREATEINFO *params, void *logctx) +{ + CUresult err; + CUVIDDECODECAPS caps = { 0 }; + + caps.eCodecType = params->CodecType; + caps.eChromaFormat = params->ChromaFormat; + caps.nBitDepthMinus8 = params->bitDepthMinus8; + + err = decoder->cvdl->cuvidGetDecoderCaps(&caps); + if (err != CUDA_SUCCESS) { + av_log(logctx, AV_LOG_ERROR, "Failed querying decoder capabilities\n"); + return AVERROR_UNKNOWN; + } + + av_log(logctx, AV_LOG_VERBOSE, "NVDEC capabilities:\n"); + av_log(logctx, AV_LOG_VERBOSE, "format supported: %s, max_mb_count: %d\n", + caps.bIsSupported ? "yes" : "no", caps.nMaxMBCount); + av_log(logctx, AV_LOG_VERBOSE, "min_width: %d, max_width: %d\n", + caps.nMinWidth, caps.nMaxWidth); + av_log(logctx, AV_LOG_VERBOSE, "min_height: %d, max_height: %d\n", + caps.nMinHeight, caps.nMaxHeight); + + if (!caps.bIsSupported) { + av_log(logctx, AV_LOG_ERROR, "Hardware is lacking required capabilities\n"); + return AVERROR(EINVAL); + } + + if (params->ulWidth > caps.nMaxWidth || params->ulWidth < caps.nMinWidth) { + av_log(logctx, AV_LOG_ERROR, "Video width %d not within range from %d to %d\n", + (int)params->ulWidth, caps.nMinWidth, caps.nMaxWidth); + return AVERROR(EINVAL); + } + + if (params->ulHeight > caps.nMaxHeight || params->ulHeight < caps.nMinHeight) { + av_log(logctx, AV_LOG_ERROR, "Video height %d not within range from %d to %d\n", + (int)params->ulHeight, caps.nMinHeight, caps.nMaxHeight); + return AVERROR(EINVAL); + } + + if ((params->ulWidth * params->ulHeight) / 256 > caps.nMaxMBCount) { + av_log(logctx, AV_LOG_ERROR, "Video macroblock count %d exceeds maximum of %d\n", + (int)(params->ulWidth * params->ulHeight) / 256, caps.nMaxMBCount); + return AVERROR(EINVAL); + } + + return 0; +} + static void nvdec_decoder_free(void *opaque, uint8_t *data) { NVDECDecoder *decoder = (NVDECDecoder*)data; @@ -132,6 +182,12 @@ static int nvdec_decoder_create(AVBufferRef **out, AVBufferRef *hw_device_ref, goto fail; } + ret = nvdec_test_capabilities(decoder, params, logctx); + if (ret < 0) { + decoder->cudl->cuCtxPopCurrent(&dummy); + goto fail; + } + err = decoder->cvdl->cuvidCreateDecoder(&decoder->decoder, params); decoder->cudl->cuCtxPopCurrent(&dummy);