From patchwork Wed Nov 28 00:16:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 11187 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 2588A44E7BA for ; Wed, 28 Nov 2018 02:24:30 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8EAB268A664; Wed, 28 Nov 2018 02:24:30 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 873BD68A641 for ; Wed, 28 Nov 2018 02:24:24 +0200 (EET) Received: by mail-wr1-f48.google.com with SMTP id j2so24554267wrw.1 for ; Tue, 27 Nov 2018 16:24:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=zO0cbaHtFgAC3zD7v0nIWI6x9Y1GmIg4j/begEUaWbA=; b=C2/rU8ud1PehsrqNcA1j/E/HTRDGIzYu/P+yEWhVDoQUVLJZ2YJj3R81bibDrfG6hb Ljin6lLgqqUrO5ZXYvSBJgNobdPcq47TNgLNirfHhbgPPdfvlpw+mpUWzI/lbXcdVFpB Y4snmOuvydCkFUSjFOUrkVcjhvwAr2LWqQcspmJNlgacHPNYRwWiCMoHTvsZ+BkQmuev u9vz+uKvxrGYmOVUtIVhhtrJUXTdQrp/oIU3W48O8FZ33JWtRgiEjJp31qNLgm0sfVng MW5VWZORmo57uLR1ImluotpLTvyWKi7RGiq4xtTMGK/1VbSZsD9i3Z5IHfKUkoQYy0VT ZliA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=zO0cbaHtFgAC3zD7v0nIWI6x9Y1GmIg4j/begEUaWbA=; b=o1J6RZXKy/pRX4VvWEGybXYfqV6c58Y38qLVIulFMh5AT/mH3O+WkXas0KTOuFs43z BabIKpWvlNDvlspLVdIHgm4jFzaIjoMaTUyP2WjjRP0hAvX64K4yf70v+mSbZd+kqWZm g+f2RS1sWURMmH0vkAQ6rAgLHMVjYgsrJZnlyKf3s/4q4G/yRwOx18hZggKT2nAzxZHJ vXe6Sm48a9j5wDYpxVNXDmGFRTKEGe01jJftcRGD595EysCYXlaFZR3+GQclmQIHdqDc 2ucEp1HkAxi3UmFg+DIUg2Jj/W3lQQPSxQ7p3l48xisRFuTHG0cVraU7hF5DwVRtnazm w8TA== X-Gm-Message-State: AA+aEWZPal64X2qViuMsv6tIfy0bsMj0zTMCm2CwrxGR1ElKJqDXjA+9 fXqjtfp4GQavi0O3v/IWEaTdn75191I= X-Google-Smtp-Source: AFSGD/WsA4kRK5XKtxU78O3HUv3jldIsAoqLpFADuhsehJzGN1iRmHdradVe/4cc6icblvoNc/6l+w== X-Received: by 2002:adf:9205:: with SMTP id 5mr18778428wrj.189.1543364191994; Tue, 27 Nov 2018 16:16:31 -0800 (PST) Received: from [192.168.0.4] (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id q189sm836850wme.5.2018.11.27.16.16.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 16:16:31 -0800 (PST) To: ffmpeg-devel@ffmpeg.org References: <1d0ee491-9296-086b-bd4e-01c6846ac504@jkqxz.net> <148B1B7A67D1C24B9EF0BE42EA4977068507210B@SHSMSX103.ccr.corp.intel.com> From: Mark Thompson Message-ID: <3962a3fb-af87-6b26-16f9-f8c85baa11ca@jkqxz.net> Date: Wed, 28 Nov 2018 00:16:30 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <148B1B7A67D1C24B9EF0BE42EA4977068507210B@SHSMSX103.ccr.corp.intel.com> Content-Language: en-US Subject: [FFmpeg-devel] [PATCH] hwcontext_opencl: Use correct function to enumerate devices 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" Also assert that all required functions are present. --- On 26/11/2018 08:57, Song, Ruiling wrote: >> -----Original Message----- >> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf Of >> Mark Thompson >> Sent: Monday, November 26, 2018 6:08 AM >> To: FFmpeg development discussions and patches >> Subject: [FFmpeg-devel] [PATCH] hwcontext_opencl: Use correct function to >> enumerate devices >> >> --- >> libavutil/hwcontext_opencl.c | 6 +++--- >> 1 file changed, 3 insertions(+), 3 deletions(-) >> >> diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c >> index e6cef74269..6a26354c87 100644 >> --- a/libavutil/hwcontext_opencl.c >> +++ b/libavutil/hwcontext_opencl.c >> @@ -542,9 +542,9 @@ static int >> opencl_device_create_internal(AVHWDeviceContext *hwdev, >> continue; >> } >> >> - err = opencl_enumerate_devices(hwdev, platforms[p], platform_name, >> - &nb_devices, &devices, >> - selector->context); >> + err = selector->enumerate_devices(hwdev, platforms[p], platform_name, >> + &nb_devices, &devices, >> + selector->context); > I think it is better to check enumerate_devices against null pointer before calling it, although it should works well currently. The two enumerate functions should always be set when entering the function, since they are always required. (Unlike the filter, where "do nothing" is a reasonable case.) How about an assert at the start of the function to check that, like this? - Mark libavutil/hwcontext_opencl.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c index be71c8323e..d3df6221c4 100644 --- a/libavutil/hwcontext_opencl.c +++ b/libavutil/hwcontext_opencl.c @@ -500,6 +500,9 @@ static int opencl_device_create_internal(AVHWDeviceContext *hwdev, *device_name_src = NULL; int err, found, p, d; + av_assert0(selector->enumerate_platforms && + selector->enumerate_devices); + err = selector->enumerate_platforms(hwdev, &nb_platforms, &platforms, selector->context); if (err) @@ -531,9 +534,9 @@ static int opencl_device_create_internal(AVHWDeviceContext *hwdev, continue; } - err = opencl_enumerate_devices(hwdev, platforms[p], platform_name, - &nb_devices, &devices, - selector->context); + err = selector->enumerate_devices(hwdev, platforms[p], platform_name, + &nb_devices, &devices, + selector->context); if (err < 0) continue;