From patchwork Mon Jun 12 22:40:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 3944 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.22.4 with SMTP id 4csp78219vsw; Mon, 12 Jun 2017 15:43:32 -0700 (PDT) X-Received: by 10.223.138.204 with SMTP id z12mr680553wrz.50.1497307412593; Mon, 12 Jun 2017 15:43:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497307412; cv=none; d=google.com; s=arc-20160816; b=KHIM1+qb5dTXTeXoTx9ipsjq1CoVI14xD35Yor05NyZ9HcZpbrquWmXQhvFOT0logd Z3VQGE06njPRO4uBJwnzcSCps/IW5S8ob46ns9UAcjhBVZap258S8scOrp8vaI61/3BA c0a8ra2y8XkmmgsA58kduwAqcE3vXxXXcScQQuCRGsFKTFB1qchrXNkArg/GLMveVSua CtD0yR2RCQfT1QOWpJBjS0mIFNjzUUhJNIbx29xC3hcYhgZjO7Xo4aEREJnZM3eSXAON vdGEhAlUt0XQOp55ufkTLA6a2HCAu9+lAo/rCYR5PEY9Zxm8bFibZacT2bbcVUNlhoI/ M1gw== 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=Opq8SPJdPvaRO6jx/h1aU+5s8f9klhH/Rb69/os5H/4=; b=HYk94iIMxVu29xTBp3g3FmDEsKpcUEVAVI6SEHav1uADU/OL6h9G+Jq3Sy3b3rCzbM cuVnZw3/w3SUuRu0i7gRAfF3BAy1Q2bZnBEwJAAo9YdsSYELPaOojbr/PGToDZDNPVZk waLppCTIUxM14eWsg4AlYBoTIFKnhRLue/C78u9sWuPGIrN3mDENOio6QL6Y4c+LsfRp m2NWbrq5aavs+331hrabB0d/qVkJy5ncrWiXHhJxh1ZuwOSyHZvofAO9+XJ1kqhqULGK a2zSXjue33Rj8W7xJ84UNoJeNzxYa6K0JW/91g0MUQlCfuhhYMwTY9Ga7ELS3xiC1ynO BaQQ== 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 c67si8894004wmh.136.2017.06.12.15.43.32; Mon, 12 Jun 2017 15:43:32 -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 4ECEA68A099; Tue, 13 Jun 2017 01:41:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f172.google.com (mail-wr0-f172.google.com [209.85.128.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6443B68A042 for ; Tue, 13 Jun 2017 01:41:11 +0300 (EEST) Received: by mail-wr0-f172.google.com with SMTP id v111so116327064wrc.3 for ; Mon, 12 Jun 2017 15:41:13 -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=k7EOaIvL1Pta6D+gc4jM6d02e8jxw3mrsrmWB7zI1bU=; b=jj24KChixGc7bs1tAglGFlb+7BjRFwkb0RYdFJ+PHZyFZ+T7PoW0YS9LRVUFljxfBR iGHsOWbu8u0tmlcGbug5K14BmEy6yc4fuVszNHB9Vvui+h0oSV8kQ+0xqMI1+XI98GWw gted42hPnlygOoc+zeUOhavJdKh4J6oHPlzCoiN6vePUDgtSFST6gxsdBZ05ri/DtNaV /n+PTc/uvz7OCSXtMdyxip/fr4c2SeMBy67YWWdQlW7ZncIowSmYErxW/Yh7wsx4HXC7 Rw3g7Kj3CGiC/sP2TV194+2E4QJ3BOtdqaRMTvotn4yKbCmjntDbk8Stwn++XK5mhA/5 pG+Q== 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=k7EOaIvL1Pta6D+gc4jM6d02e8jxw3mrsrmWB7zI1bU=; b=EdhZjs+cfmi2kEDab/8D1dFHd6uoQQqpmGxIVLGTAvlBI3tqJueuVK9F427ZCb9s6R wyJzaQNfn5dbCYo1u+sE1i1ZZ7EM0/BhBxxvVF7VtVR4hl2LIQxXEV0OJ9AoigiMcip5 lPclcaeUUHnwiZFMqCu6PeHTGS17FmKkh/UAWCvfElw0q+iwB1Nmo4+EFt9BvvtP+fPu j84jzXkhNxvMusNDb7GBtikhXo/cUgXScHn4KdM/JkF9jpZJouINBah/UDhaM3K+QgpL BV8Tyw5alcWqD8JKNfKuOyR2To5HOxoSN0slYd9bkJ+NSK+L8+83emGF6AhrVe3Sbqyi Xrrw== X-Gm-Message-State: AKS2vOxFp3jd/Vl0p9w8LzFRvnSKH1y16Mryd2rplK3XxJxNZWhtvKe3 e8Ywy5jK7Sg5NaFDCrk= X-Received: by 10.223.163.11 with SMTP id c11mr615176wrb.185.1497307272527; Mon, 12 Jun 2017 15:41:12 -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.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jun 2017 15:41:11 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Jun 2017 23:40:33 +0100 Message-Id: <20170612224041.6750-17-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 16/24] ffmpeg: Support setting the hardware device to use when filtering 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" This only supports one device globally, but more can be used by passing them with input streams in hw_frames_ctx or by deriving new devices inside a filter graph with hwmap. (cherry picked from commit e669db76108de8d7a36c2274c99da82cc94d1dd1) --- doc/ffmpeg.texi | 11 +++++++++++ ffmpeg.h | 1 + ffmpeg_filter.c | 10 ++++++++-- ffmpeg_opt.c | 17 +++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index db7f05a3e0..4616a4239e 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -765,6 +765,17 @@ deriving it from the existing device with the name @var{source}. @item -init_hw_device list List all hardware device types supported in this build of ffmpeg. +@item -filter_hw_device @var{name} +Pass the hardware device called @var{name} to all filters in any filter graph. +This can be used to set the device to upload to with the @code{hwupload} filter, +or the device to map to with the @code{hwmap} filter. Other filters may also +make use of this parameter when they require a hardware device. Note that this +is typically only required when the input is not already in hardware frames - +when it is, filters will derive the device they require from the context of the +frames they receive as input. + +This is a global setting, so all filters will receive the same device. + @item -hwaccel[:@var{stream_specifier}] @var{hwaccel} (@emph{input,per-stream}) Use hardware acceleration to decode the matching stream(s). The allowed values of @var{hwaccel} are: diff --git a/ffmpeg.h b/ffmpeg.h index fbb9172d74..c3854bcb4a 100644 --- a/ffmpeg.h +++ b/ffmpeg.h @@ -628,6 +628,7 @@ extern AVBufferRef *hw_device_ctx; #if CONFIG_QSV extern char *qsv_device; #endif +extern HWDevice *filter_hw_device; void term_init(void); diff --git a/ffmpeg_filter.c b/ffmpeg_filter.c index 817f48f473..aacc185059 100644 --- a/ffmpeg_filter.c +++ b/ffmpeg_filter.c @@ -1046,9 +1046,15 @@ int configure_filtergraph(FilterGraph *fg) if ((ret = avfilter_graph_parse2(fg->graph, graph_desc, &inputs, &outputs)) < 0) goto fail; - if (hw_device_ctx) { + if (filter_hw_device || hw_device_ctx) { + AVBufferRef *device = filter_hw_device ? filter_hw_device->device_ref + : hw_device_ctx; for (i = 0; i < fg->graph->nb_filters; i++) { - fg->graph->filters[i]->hw_device_ctx = av_buffer_ref(hw_device_ctx); + fg->graph->filters[i]->hw_device_ctx = av_buffer_ref(device); + if (!fg->graph->filters[i]->hw_device_ctx) { + ret = AVERROR(ENOMEM); + goto fail; + } } } diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c index 1facc82f44..90c31c0f58 100644 --- a/ffmpeg_opt.c +++ b/ffmpeg_opt.c @@ -98,6 +98,7 @@ const HWAccel hwaccels[] = { }; int hwaccel_lax_profile_check = 0; AVBufferRef *hw_device_ctx; +HWDevice *filter_hw_device; char *vstats_filename; char *sdp_filename; @@ -497,6 +498,20 @@ static int opt_init_hw_device(void *optctx, const char *opt, const char *arg) } } +static int opt_filter_hw_device(void *optctx, const char *opt, const char *arg) +{ + if (filter_hw_device) { + av_log(NULL, AV_LOG_ERROR, "Only one filter device can be used.\n"); + return AVERROR(EINVAL); + } + filter_hw_device = hw_device_get_by_name(arg); + if (!filter_hw_device) { + av_log(NULL, AV_LOG_ERROR, "Invalid filter device %s.\n", arg); + return AVERROR(EINVAL); + } + return 0; +} + /** * Parse a metadata specifier passed as 'arg' parameter. * @param arg metadata string to parse @@ -3710,6 +3725,8 @@ const OptionDef options[] = { { "init_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_init_hw_device }, "initialise hardware device", "args" }, + { "filter_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_hw_device }, + "set hardware device used when filtering", "device" }, { NULL, }, };