From patchwork Mon Jun 12 22:40:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 3935 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.22.4 with SMTP id 4csp77828vsw; Mon, 12 Jun 2017 15:42:02 -0700 (PDT) X-Received: by 10.28.66.196 with SMTP id k65mr635009wmi.55.1497307321952; Mon, 12 Jun 2017 15:42:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497307321; cv=none; d=google.com; s=arc-20160816; b=tKYAYR1BvQQ9MTdTpKOBRu6xDfbsx5TbMZ6K7tFQ8vyMCOtDqUg7T0785ejo598o2/ gGC79/ubr5DiFmyQRBVwVh0PWnpxFasaC3LLE3/QCtQ+pKIrbkVSZBWh4A4v6EArqA2V AlF80mCBFdYEfMIqBLe5rPdCExQLs/zzB65yaQ7jOFpwXgIiezeBCwfS4GbiyY6gKXiI NXDoqu7wiI9izS92u+O0/HzUcTbEb/wJ2iSfAIuXRb3I1kIKBlUTTgtDKG6Q4CLfjAgs MBUAiJEIjH1XER6IdDwSawunYGuWxfjbq+sUTZoFexIS9Q1dqhq+6iyUrbH7gnmFoxzR H7vw== 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: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=5MBsRMKTXcr/4NXOedFYEdS9qxtsYqqp4uhNCCFX4C8=; b=he/C6MUmf+5ughc/D4e0vLUZ2djPy96SXDRT8g0pBTrGfAY/e1iKiszl21kZWC4nVB Cs3OaesvkqKwdAWKUeqy86HwbdjPAnG/wTmEGMZeQoUF7MkSgVhfb2KTmO+DfyU548g9 xC119vr3s0M0rFM7FuEwr4x9gfDXCIO967gJlC26j0BtL5R2ZR1HfBP2KR7XE1wqFKUu 8ZQaaD6Eba31OGjOiWTWyi3vdiUvpoxiI7IbuJWcxgziuhzZ2cbsExj7Nkviv98Ltz5i de1xKtCwxsVL1SqN73z+fizPC4BXFmzJjmrrScrwGGf/IMa7c9mEUrBcYPcNpIuUQ4QV 9NNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com; 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 39si10583037wrk.320.2017.06.12.15.42.01; Mon, 12 Jun 2017 15:42:01 -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=@jkqxz-net.20150623.gappssmtp.com; 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 17EE668A041; Tue, 13 Jun 2017 01:41:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f177.google.com (mail-wr0-f177.google.com [209.85.128.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EE42F680A4D for ; Tue, 13 Jun 2017 01:41:01 +0300 (EEST) Received: by mail-wr0-f177.google.com with SMTP id g76so113426397wrd.1 for ; Mon, 12 Jun 2017 15:41:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=bHH0t/G/Fn2sRc/XKc4pU5S3J44RpR9VlitTMySex3o=; b=grVZe6avPfursi9lZ/qv6hxiBpJhb2g7lBOvG+6OK5LQw2NNxgGJxeyiYcLmvj25zI 74negbuXk1XoVg6TqhMQD+Au37VG/msVrStD9y9tP/axMOdaA+5gE/hVaibsLGf07Jzr oi4whu7BLd6qFFeTmClru/l2ol0kGoAbFaRa5JyEiVWMCdLROlSmAUmQT03Er/+973up 1JOOCU4yykVVj/eG1IIC72FtcUKAoUsKwdnxSa9ehz8SGpLeTXqq7zVOSfj9QmG7GZ7r sEECJ/NUyHOPGUAMT5gPx68lmwCiAJvPZomO2EngsB8cKTRNJO4lqO3m/O+ebKPttjcJ R62A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=bHH0t/G/Fn2sRc/XKc4pU5S3J44RpR9VlitTMySex3o=; b=m/5+6cv+vu9JzZl0j3mhGv19RcLrOSjlMhL/jOX9cAK54VdK0rnmXbj2iZ09/+cQuK kuzgcPs4Yfa3MjU9zm/Ft3hMnF+JbJ+oC3SgylUXI2+4x4JQQLRgRvDIx6a1xOBX6vYz /P3ohHa2ZDjCgqdCSPhHvZjphHUJLeinjCpbdCuF3GI8Bcfc7/cdavHTkBAXgOjww3+4 FJXYjKTziYuEN+IecmOb6SowutStq/I8bnn062DISv4PBxPyMIVmjGxEmXAY9M59RjNa +Kxp2kZqSblg3papf2x1X2B3Y0xnySZVY/9LT381GXcDoNppE318vDhcJslkVlgwVQaN 0hkQ== X-Gm-Message-State: AKS2vOx465zzi2cLEIop7dfRGDmlDCqEk5LBGCny7+ojNfD6tfC34UH1 DVDCJ+SgxcookRnHcWY= X-Received: by 10.28.153.143 with SMTP id b137mr657688wme.15.1497307263337; Mon, 12 Jun 2017 15:41:03 -0700 (PDT) Received: from rywe.jkqxz.net (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id m191sm13098233wmg.30.2017.06.12.15.41.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jun 2017 15:41:02 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Jun 2017 23:40:22 +0100 Message-Id: <20170612224041.6750-6-sw@jkqxz.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170612224041.6750-1-sw@jkqxz.net> References: <20170612224041.6750-1-sw@jkqxz.net> Subject: [FFmpeg-devel] [PATCH 05/24] ffmpeg: Generic device setup 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Not yet enabled for any hwaccels. (cherry picked from commit d2e6dd32a445b5744a51d090c0822dbd7e434592) (cherry picked from commit 9203aac22874c7259e155b7d00f1f33bb1355129) --- Makefile | 2 +- ffmpeg.c | 18 +++ ffmpeg.h | 17 +++ ffmpeg_hw.c | 387 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ffmpeg_opt.c | 39 ++++-- 5 files changed, 455 insertions(+), 8 deletions(-) create mode 100644 ffmpeg_hw.c diff --git a/Makefile b/Makefile index a2df8b9d8d..913a890a78 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF)) $(foreach prog,$(AVBASENAMES),$(eval OBJS-$(prog) += cmdutils.o)) $(foreach prog,$(AVBASENAMES),$(eval OBJS-$(prog)-$(CONFIG_OPENCL) += cmdutils_opencl.o)) -OBJS-ffmpeg += ffmpeg_opt.o ffmpeg_filter.o +OBJS-ffmpeg += ffmpeg_opt.o ffmpeg_filter.o ffmpeg_hw.o OBJS-ffmpeg-$(CONFIG_VIDEOTOOLBOX) += ffmpeg_videotoolbox.o OBJS-ffmpeg-$(CONFIG_LIBMFX) += ffmpeg_qsv.o OBJS-ffmpeg-$(CONFIG_VAAPI) += ffmpeg_vaapi.o diff --git a/ffmpeg.c b/ffmpeg.c index cd19594f8b..6170bd453c 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -2884,6 +2884,15 @@ static int init_input_stream(int ist_index, char *error, int error_len) if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0)) av_dict_set(&ist->decoder_opts, "threads", "auto", 0); + + ret = hw_device_setup_for_decode(ist); + if (ret < 0) { + snprintf(error, error_len, "Device setup failed for " + "decoder on input stream #%d:%d : %s", + ist->file_index, ist->st->index, av_err2str(ret)); + return ret; + } + if ((ret = avcodec_open2(ist->dec_ctx, codec, &ist->decoder_opts)) < 0) { if (ret == AVERROR_EXPERIMENTAL) abort_codec_experimental(codec, 0); @@ -3441,6 +3450,14 @@ static int init_output_stream(OutputStream *ost, char *error, int error_len) ost->enc_ctx->hw_frames_ctx = av_buffer_ref(av_buffersink_get_hw_frames_ctx(ost->filter->filter)); if (!ost->enc_ctx->hw_frames_ctx) return AVERROR(ENOMEM); + } else { + ret = hw_device_setup_for_encode(ost); + if (ret < 0) { + snprintf(error, error_len, "Device setup failed for " + "encoder on output stream #%d:%d : %s", + ost->file_index, ost->index, av_err2str(ret)); + return ret; + } } if ((ret = avcodec_open2(ost->enc_ctx, codec, &ost->encoder_opts)) < 0) { @@ -4643,6 +4660,7 @@ static int transcode(void) } av_buffer_unref(&hw_device_ctx); + hw_device_free_all(); /* finished ! */ ret = 0; diff --git a/ffmpeg.h b/ffmpeg.h index a806445e0d..5c115cf9a3 100644 --- a/ffmpeg.h +++ b/ffmpeg.h @@ -42,6 +42,7 @@ #include "libavutil/dict.h" #include "libavutil/eval.h" #include "libavutil/fifo.h" +#include "libavutil/hwcontext.h" #include "libavutil/pixfmt.h" #include "libavutil/rational.h" #include "libavutil/threadmessage.h" @@ -74,8 +75,15 @@ typedef struct HWAccel { int (*init)(AVCodecContext *s); enum HWAccelID id; enum AVPixelFormat pix_fmt; + enum AVHWDeviceType device_type; } HWAccel; +typedef struct HWDevice { + char *name; + enum AVHWDeviceType type; + AVBufferRef *device_ref; +} HWDevice; + /* select an input stream for an output stream */ typedef struct StreamMap { int disabled; /* 1 is this mapping is disabled by a negative map */ @@ -661,4 +669,13 @@ int vaapi_decode_init(AVCodecContext *avctx); int vaapi_device_init(const char *device); int cuvid_init(AVCodecContext *s); +HWDevice *hw_device_get_by_name(const char *name); +int hw_device_init_from_string(const char *arg, HWDevice **dev); +void hw_device_free_all(void); + +int hw_device_setup_for_decode(InputStream *ist); +int hw_device_setup_for_encode(OutputStream *ost); + +int hwaccel_decode_init(AVCodecContext *avctx); + #endif /* FFMPEG_H */ diff --git a/ffmpeg_hw.c b/ffmpeg_hw.c new file mode 100644 index 0000000000..3acf8b4532 --- /dev/null +++ b/ffmpeg_hw.c @@ -0,0 +1,387 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "ffmpeg.h" + +static int nb_hw_devices; +static HWDevice **hw_devices; + +static HWDevice *hw_device_get_by_type(enum AVHWDeviceType type) +{ + HWDevice *found = NULL; + int i; + for (i = 0; i < nb_hw_devices; i++) { + if (hw_devices[i]->type == type) { + if (found) + return NULL; + found = hw_devices[i]; + } + } + return found; +} + +HWDevice *hw_device_get_by_name(const char *name) +{ + int i; + for (i = 0; i < nb_hw_devices; i++) { + if (!strcmp(hw_devices[i]->name, name)) + return hw_devices[i]; + } + return NULL; +} + +static HWDevice *hw_device_add(void) +{ + int err; + err = av_reallocp_array(&hw_devices, nb_hw_devices + 1, + sizeof(*hw_devices)); + if (err) { + nb_hw_devices = 0; + return NULL; + } + hw_devices[nb_hw_devices] = av_mallocz(sizeof(HWDevice)); + if (!hw_devices[nb_hw_devices]) + return NULL; + return hw_devices[nb_hw_devices++]; +} + +int hw_device_init_from_string(const char *arg, HWDevice **dev_out) +{ + // "type=name:device,key=value,key2=value2" + // "type:device,key=value,key2=value2" + // -> av_hwdevice_ctx_create() + // "type=name@name" + // "type@name" + // -> av_hwdevice_ctx_create_derived() + + AVDictionary *options = NULL; + char *type_name = NULL, *name = NULL, *device = NULL; + enum AVHWDeviceType type; + HWDevice *dev, *src; + AVBufferRef *device_ref; + int err; + const char *errmsg, *p, *q; + size_t k; + + k = strcspn(arg, ":=@"); + p = arg + k; + + type_name = av_strndup(arg, k); + if (!type_name) { + err = AVERROR(ENOMEM); + goto fail; + } + type = av_hwdevice_find_type_by_name(type_name); + if (type == AV_HWDEVICE_TYPE_NONE) { + errmsg = "unknown device type"; + goto invalid; + } + + if (*p == '=') { + k = strcspn(p + 1, ":@"); + + name = av_strndup(p + 1, k); + if (!name) { + err = AVERROR(ENOMEM); + goto fail; + } + if (hw_device_get_by_name(name)) { + errmsg = "named device already exists"; + goto invalid; + } + + p += 1 + k; + } else { + // Give the device an automatic name of the form "type%d". + // We arbitrarily limit at 1000 anonymous devices of the same + // type - there is probably something else very wrong if you + // get to this limit. + size_t index_pos; + int index, index_limit = 1000; + index_pos = strlen(type_name); + name = av_malloc(index_pos + 4); + if (!name) { + err = AVERROR(ENOMEM); + goto fail; + } + for (index = 0; index < index_limit; index++) { + snprintf(name, index_pos + 4, "%s%d", type_name, index); + if (!hw_device_get_by_name(name)) + break; + } + if (index >= index_limit) { + errmsg = "too many devices"; + goto invalid; + } + } + + if (!*p) { + // New device with no parameters. + err = av_hwdevice_ctx_create(&device_ref, type, + NULL, NULL, 0); + if (err < 0) + goto fail; + + } else if (*p == ':') { + // New device with some parameters. + ++p; + q = strchr(p, ','); + if (q) { + device = av_strndup(p, q - p); + if (!device) { + err = AVERROR(ENOMEM); + goto fail; + } + err = av_dict_parse_string(&options, q + 1, "=", ",", 0); + if (err < 0) { + errmsg = "failed to parse options"; + goto invalid; + } + } + + err = av_hwdevice_ctx_create(&device_ref, type, + device ? device : p, options, 0); + if (err < 0) + goto fail; + + } else if (*p == '@') { + // Derive from existing device. + + src = hw_device_get_by_name(p + 1); + if (!src) { + errmsg = "invalid source device name"; + goto invalid; + } + + err = av_hwdevice_ctx_create_derived(&device_ref, type, + src->device_ref, 0); + if (err < 0) + goto fail; + } else { + errmsg = "parse error"; + goto invalid; + } + + dev = hw_device_add(); + if (!dev) { + err = AVERROR(ENOMEM); + goto fail; + } + + dev->name = name; + dev->type = type; + dev->device_ref = device_ref; + + if (dev_out) + *dev_out = dev; + + name = NULL; + err = 0; +done: + av_freep(&type_name); + av_freep(&name); + av_freep(&device); + av_dict_free(&options); + return err; +invalid: + av_log(NULL, AV_LOG_ERROR, + "Invalid device specification \"%s\": %s\n", arg, errmsg); + err = AVERROR(EINVAL); + goto done; +fail: + av_log(NULL, AV_LOG_ERROR, + "Device creation failed: %d.\n", err); + goto done; +} + +void hw_device_free_all(void) +{ + int i; + for (i = 0; i < nb_hw_devices; i++) { + av_freep(&hw_devices[i]->name); + av_buffer_unref(&hw_devices[i]->device_ref); + av_freep(&hw_devices[i]); + } + av_freep(&hw_devices); + nb_hw_devices = 0; +} + +static enum AVHWDeviceType hw_device_match_type_by_hwaccel(enum HWAccelID hwaccel_id) +{ + int i; + if (hwaccel_id == HWACCEL_NONE) + return AV_HWDEVICE_TYPE_NONE; + for (i = 0; hwaccels[i].name; i++) { + if (hwaccels[i].id == hwaccel_id) + return hwaccels[i].device_type; + } + return AV_HWDEVICE_TYPE_NONE; +} + +static enum AVHWDeviceType hw_device_match_type_in_name(const char *codec_name) +{ + const char *type_name; + enum AVHWDeviceType type; + for (type = av_hwdevice_iterate_types(AV_HWDEVICE_TYPE_NONE); + type != AV_HWDEVICE_TYPE_NONE; + type = av_hwdevice_iterate_types(type)) { + type_name = av_hwdevice_get_type_name(type); + if (strstr(codec_name, type_name)) + return type; + } + return AV_HWDEVICE_TYPE_NONE; +} + +int hw_device_setup_for_decode(InputStream *ist) +{ + enum AVHWDeviceType type; + HWDevice *dev; + const char *type_name; + int err; + + if (ist->hwaccel_device) { + dev = hw_device_get_by_name(ist->hwaccel_device); + if (!dev) { + char *tmp; + size_t len; + type = hw_device_match_type_by_hwaccel(ist->hwaccel_id); + if (type == AV_HWDEVICE_TYPE_NONE) { + // No match - this isn't necessarily invalid, though, + // because an explicit device might not be needed or + // the hwaccel setup could be handled elsewhere. + return 0; + } + type_name = av_hwdevice_get_type_name(type); + len = strlen(type_name) + 1 + + strlen(ist->hwaccel_device) + 1; + tmp = av_malloc(len); + if (!tmp) + return AVERROR(ENOMEM); + snprintf(tmp, len, "%s:%s", type_name, ist->hwaccel_device); + err = hw_device_init_from_string(tmp, &dev); + av_free(tmp); + if (err < 0) + return err; + } + } else { + if (ist->hwaccel_id != HWACCEL_NONE) + type = hw_device_match_type_by_hwaccel(ist->hwaccel_id); + else + type = hw_device_match_type_in_name(ist->dec->name); + if (type != AV_HWDEVICE_TYPE_NONE) { + dev = hw_device_get_by_type(type); + if (!dev) { + hw_device_init_from_string(av_hwdevice_get_type_name(type), + &dev); + } + } else { + // No device required. + return 0; + } + } + + if (!dev) { + av_log(ist->dec_ctx, AV_LOG_WARNING, "No device available " + "for decoder (device type %s for codec %s).\n", + av_hwdevice_get_type_name(type), ist->dec->name); + return 0; + } + + ist->dec_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref); + if (!ist->dec_ctx->hw_device_ctx) + return AVERROR(ENOMEM); + + return 0; +} + +int hw_device_setup_for_encode(OutputStream *ost) +{ + enum AVHWDeviceType type; + HWDevice *dev; + + type = hw_device_match_type_in_name(ost->enc->name); + if (type != AV_HWDEVICE_TYPE_NONE) { + dev = hw_device_get_by_type(type); + if (!dev) { + av_log(ost->enc_ctx, AV_LOG_WARNING, "No device available " + "for encoder (device type %s for codec %s).\n", + av_hwdevice_get_type_name(type), ost->enc->name); + return 0; + } + ost->enc_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref); + if (!ost->enc_ctx->hw_device_ctx) + return AVERROR(ENOMEM); + return 0; + } else { + // No device required. + return 0; + } +} + +static int hwaccel_retrieve_data(AVCodecContext *avctx, AVFrame *input) +{ + InputStream *ist = avctx->opaque; + AVFrame *output = NULL; + enum AVPixelFormat output_format = ist->hwaccel_output_format; + int err; + + if (input->format == output_format) { + // Nothing to do. + return 0; + } + + output = av_frame_alloc(); + if (!output) + return AVERROR(ENOMEM); + + output->format = output_format; + + err = av_hwframe_transfer_data(output, input, 0); + if (err < 0) { + av_log(avctx, AV_LOG_ERROR, "Failed to transfer data to " + "output frame: %d.\n", err); + goto fail; + } + + err = av_frame_copy_props(output, input); + if (err < 0) { + av_frame_unref(output); + goto fail; + } + + av_frame_unref(input); + av_frame_move_ref(input, output); + av_frame_free(&output); + + return 0; + +fail: + av_frame_free(&output); + return err; +} + +int hwaccel_decode_init(AVCodecContext *avctx) +{ + InputStream *ist = avctx->opaque; + + ist->hwaccel_retrieve_data = &hwaccel_retrieve_data; + + return 0; +} diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c index c997ea8faf..6755e09e47 100644 --- a/ffmpeg_opt.c +++ b/ffmpeg_opt.c @@ -67,25 +67,32 @@ const HWAccel hwaccels[] = { #if HAVE_VDPAU_X11 - { "vdpau", vdpau_init, HWACCEL_VDPAU, AV_PIX_FMT_VDPAU }, + { "vdpau", vdpau_init, HWACCEL_VDPAU, AV_PIX_FMT_VDPAU, + AV_HWDEVICE_TYPE_NONE }, #endif #if HAVE_DXVA2_LIB - { "dxva2", dxva2_init, HWACCEL_DXVA2, AV_PIX_FMT_DXVA2_VLD }, + { "dxva2", dxva2_init, HWACCEL_DXVA2, AV_PIX_FMT_DXVA2_VLD, + AV_HWDEVICE_TYPE_NONE }, #endif #if CONFIG_VDA - { "vda", videotoolbox_init, HWACCEL_VDA, AV_PIX_FMT_VDA }, + { "vda", videotoolbox_init, HWACCEL_VDA, AV_PIX_FMT_VDA, + AV_HWDEVICE_TYPE_NONE }, #endif #if CONFIG_VIDEOTOOLBOX - { "videotoolbox", videotoolbox_init, HWACCEL_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX }, + { "videotoolbox", videotoolbox_init, HWACCEL_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX, + AV_HWDEVICE_TYPE_NONE }, #endif #if CONFIG_LIBMFX - { "qsv", qsv_init, HWACCEL_QSV, AV_PIX_FMT_QSV }, + { "qsv", qsv_init, HWACCEL_QSV, AV_PIX_FMT_QSV, + AV_HWDEVICE_TYPE_NONE }, #endif #if CONFIG_VAAPI - { "vaapi", vaapi_decode_init, HWACCEL_VAAPI, AV_PIX_FMT_VAAPI }, + { "vaapi", vaapi_decode_init, HWACCEL_VAAPI, AV_PIX_FMT_VAAPI, + AV_HWDEVICE_TYPE_NONE }, #endif #if CONFIG_CUVID - { "cuvid", cuvid_init, HWACCEL_CUVID, AV_PIX_FMT_CUDA }, + { "cuvid", cuvid_init, HWACCEL_CUVID, AV_PIX_FMT_CUDA, + AV_HWDEVICE_TYPE_NONE }, #endif { 0 }, }; @@ -463,6 +470,21 @@ static int opt_vaapi_device(void *optctx, const char *opt, const char *arg) } #endif +static int opt_init_hw_device(void *optctx, const char *opt, const char *arg) +{ + if (!strcmp(arg, "list")) { + enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE; + printf("Supported hardware device types:\n"); + while ((type = av_hwdevice_iterate_types(type)) != + AV_HWDEVICE_TYPE_NONE) + printf("%s\n", av_hwdevice_get_type_name(type)); + printf("\n"); + exit_program(0); + } else { + return hw_device_init_from_string(arg, NULL); + } +} + /** * Parse a metadata specifier passed as 'arg' parameter. * @param arg metadata string to parse @@ -3674,5 +3696,8 @@ const OptionDef options[] = { "set QSV hardware device (DirectX adapter index, DRM path or X11 display name)", "device"}, #endif + { "init_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_init_hw_device }, + "initialise hardware device", "args" }, + { NULL, }, };