From patchwork Sun Nov 26 22:04:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Langdale X-Patchwork-Id: 6370 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp936417jah; Sun, 26 Nov 2017 14:12:23 -0800 (PST) X-Google-Smtp-Source: AGs4zMb9AsM4OXvVrsV0uGHHO/kKDDTeId6lPaSKdCfi3UvCrntyxLO9KK8Mwx3fqws9GQWXUt66 X-Received: by 10.28.6.6 with SMTP id 6mr10769100wmg.114.1511734343834; Sun, 26 Nov 2017 14:12:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511734343; cv=none; d=google.com; s=arc-20160816; b=qGEm9BzMu9fmKcnUs6l72r0rCK30G/mepq/5Rzx2+9pefbAbGqs+z9RPv8v9yXajhY 27tQ44pNn0BsM9O7khF3ZvHS2PfkU9+Zd0XSgtjtm/G8EGBSmTVD5o5R3NTi0ZHunjyj Nhc8+G7a6WcVJqOXhaGt2OOjD55vaVYsRmqCUjh87sgsTL0seEWF3ISgzllN6avpFr6f S/ID7qvzCLnhlzlj/iQ7KEDMyE0csLSYxccVVmJle8Z2rqbc+f162wJoedy4NMFb7YpM n9zqEVhUF49smccmuCmmn4doCsWdU8XpE8NS58WpLEATtRXvNwQ/I8/FEXwV+/B/u3co WtUA== 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:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=YyIHLJiWusyu/9H1sPGa0U0Xcl9pthlBt9S2DWQJf60=; b=WOQDT7Ex6EDD0+Tet8O+JuMleKiBQkzTFN1wR9REWSUbk5rwC7JLOARhP0E0dzCiYY 9jA5gcPgE5APoUWwG5c/sIDBAf+TpRthTfmDmV+AXQUOacAkvCpPr6uGafPdOl8fR9ZB I1zxjE0EyxGYmZw2gcAniJ7a2pIcmT9ChcVN5ybJzYVWeZZSi5+okjgK3g3qeADctnOQ XEGBfpTn+d/ZWOYK51KqUbyDNsDTQ2XVnunQossSiuQW9/iy1rpD8TnCZgbbWdVsnxSC xfkKZfcgZvUn/xI4xJNvKPw40Qe5dSB+mjI5fbPfuIUPfK7m/+xOc16r2JpHeNDLeQqy vkJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@overt.org header.s=mail header.b=LxjiqvOn; 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 p1si20299579wra.437.2017.11.26.14.12.23; Sun, 26 Nov 2017 14:12:23 -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=@overt.org header.s=mail header.b=LxjiqvOn; 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 53EB368A18A; Mon, 27 Nov 2017 00:12:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io0-f225.google.com (mail-io0-f225.google.com [209.85.223.225]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A2B8A689FC6 for ; Mon, 27 Nov 2017 00:12:14 +0200 (EET) Received: by mail-io0-f225.google.com with SMTP id z74so34318250iof.12 for ; Sun, 26 Nov 2017 14:12:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id; bh=vHt5LiDWsOkvn3hQ7HDKZFQYjJZMxjPpBIm2LzezqCY=; b=Ul/WpgBp1SQ2DQACOvc3ciLgmVb0R5F7kEoJI+5rq27ncM9FJyy+n0Tf7YoSd3ogsy Vw7qfeqMpI2AC6QHgx272E/v7n/IOzXbtATQLoIAvEg79ZHJnwQqhsqZtja6zpFB3NPZ Xm3D4VWNrOu95UyUEE2lhBrxHH6nDPcjxrT3Twa3qyY4BuMmiQDo1Db0SKwDLArA91k7 eHsuBFjiEIh8ZmTQJH/3qwVlrCKU1BqXhOuz29eDLPiEA5Sc0zY2u6H/hpB7pneyfZHx dljmOzrWy7WKZLzUEJJOwyabxJkqRwE2vyToYJXs0MUHOGhaNdvEJZFOVvY0mzDVhYZa XKbw== X-Gm-Message-State: AJaThX5JBYNlkC96vvfgNVY+7hlqOOVt2FFzr2scTemHVgdXU/vzjsfH 5zyPlO0wW9mqPzpvxqPsHSh+vmz9UMW9P3qyiO1C21Yir1MTGg== X-Received: by 10.107.182.6 with SMTP id g6mr30888808iof.101.1511733872039; Sun, 26 Nov 2017 14:04:32 -0800 (PST) Received: from mail.overt.org (155.208.178.107.bc.googleusercontent.com. [107.178.208.155]) by smtp-relay.gmail.com with ESMTPS id 189sm4483430itu.7.2017.11.26.14.04.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Nov 2017 14:04:32 -0800 (PST) X-Relaying-Domain: gapps.overt.org Received: from authenticated-user (mail.overt.org [107.178.208.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.overt.org (Postfix) with ESMTPSA id 5DC057852A; Sun, 26 Nov 2017 22:04:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=overt.org; s=mail; t=1511733871; bh=wfVAuXQ3uYAj3PJ64t5RV4Zfm4fFsCDyXg9lnV8kfTE=; h=From:To:Cc:Subject:Date:From; b=LxjiqvOn/gb7UGMDGTOxgC1ovqr3EeDAPoLAMOax8YFSQNVBKzzMLJbTVHRpIUsH/ uzZEu98hPAgOpKXxuwQWyCX5dZs0FRxcn1iQrkx+JJhjOD+LJgOOmSsZEqvyU4eAAp Ly2IONND4K8lENk6v2PTNM2AqYCKFbtieJndNAqNQHpTl5Gh38P1ffb0uwtixpxQqu AlsRoMC1scFwF+kG1KFDnUVtbCJ7sjFqYYjbJu6YnfdWWQyzCLeFsX1RsIvnyQzpgX pQ2BtchkFS6yecgfWWAIxN7/gMLMf5NJH+TyKYWQ43qzd0FbndVwzOuOD8kK/EpZWt /B5Ztp2z+8/qw== From: Philip Langdale To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Nov 2017 14:04:08 -0800 Message-Id: <20171126220408.30979-1-philipl@overt.org> Subject: [FFmpeg-devel] [PATCH] avcodec: Implement vp8 nvdec hwaccel 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: Philip Langdale MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Philip Langdale --- Changelog | 2 +- configure | 2 ++ libavcodec/Makefile | 1 + libavcodec/hwaccels.h | 1 + libavcodec/nvdec.c | 1 + libavcodec/nvdec_vp8.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++ libavcodec/version.h | 3 +- libavcodec/vp8.c | 6 ++++ 8 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 libavcodec/nvdec_vp8.c diff --git a/Changelog b/Changelog index e3092e211f..4db1d57721 100644 --- a/Changelog +++ b/Changelog @@ -13,7 +13,7 @@ version : - PCE support for extended channel layouts in the AAC encoder - native aptX encoder and decoder - Raw aptX muxer and demuxer -- NVIDIA NVDEC-accelerated H.264, HEVC, MPEG-1/2/4, VC1 and VP9 hwaccel decoding +- NVIDIA NVDEC-accelerated H.264, HEVC, MPEG-1/2/4, VC1, VP8 and VP9 hwaccel decoding - Intel QSV-accelerated overlay filter - mcompand audio filter - acontrast audio filter diff --git a/configure b/configure index bc00b71489..e5fa61e83d 100755 --- a/configure +++ b/configure @@ -2748,6 +2748,8 @@ vc1_vaapi_hwaccel_deps="vaapi" vc1_vaapi_hwaccel_select="vc1_decoder" vc1_vdpau_hwaccel_deps="vdpau" vc1_vdpau_hwaccel_select="vc1_decoder" +vp8_nvdec_hwaccel_deps="nvdec" +vp8_nvdec_hwaccel_select="vp8_decoder" vp8_vaapi_hwaccel_deps="vaapi VAPictureParameterBufferVP8" vp8_vaapi_hwaccel_select="vp8_decoder" vp9_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_VP9" diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 640edfb590..ca7960cdf4 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -872,6 +872,7 @@ OBJS-$(CONFIG_VC1_NVDEC_HWACCEL) += nvdec_vc1.o OBJS-$(CONFIG_VC1_QSV_HWACCEL) += qsvdec_other.o OBJS-$(CONFIG_VC1_VAAPI_HWACCEL) += vaapi_vc1.o OBJS-$(CONFIG_VC1_VDPAU_HWACCEL) += vdpau_vc1.o +OBJS-$(CONFIG_VP8_NVDEC_HWACCEL) += nvdec_vp8.o OBJS-$(CONFIG_VP8_VAAPI_HWACCEL) += vaapi_vp8.o OBJS-$(CONFIG_VP9_D3D11VA_HWACCEL) += dxva2_vp9.o OBJS-$(CONFIG_VP9_DXVA2_HWACCEL) += dxva2_vp9.o diff --git a/libavcodec/hwaccels.h b/libavcodec/hwaccels.h index cefd2b15be..420e2feeea 100644 --- a/libavcodec/hwaccels.h +++ b/libavcodec/hwaccels.h @@ -60,6 +60,7 @@ extern const AVHWAccel ff_vc1_dxva2_hwaccel; extern const AVHWAccel ff_vc1_nvdec_hwaccel; extern const AVHWAccel ff_vc1_vaapi_hwaccel; extern const AVHWAccel ff_vc1_vdpau_hwaccel; +extern const AVHWAccel ff_vp8_nvdec_hwaccel; extern const AVHWAccel ff_vp8_vaapi_hwaccel; extern const AVHWAccel ff_vp9_d3d11va_hwaccel; extern const AVHWAccel ff_vp9_d3d11va2_hwaccel; diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c index da4451a739..c7a02ff40f 100644 --- a/libavcodec/nvdec.c +++ b/libavcodec/nvdec.c @@ -58,6 +58,7 @@ static int map_avcodec_id(enum AVCodecID id) case AV_CODEC_ID_MPEG2VIDEO: return cudaVideoCodec_MPEG2; case AV_CODEC_ID_MPEG4: return cudaVideoCodec_MPEG4; case AV_CODEC_ID_VC1: return cudaVideoCodec_VC1; + case AV_CODEC_ID_VP8: return cudaVideoCodec_VP8; case AV_CODEC_ID_VP9: return cudaVideoCodec_VP9; case AV_CODEC_ID_WMV3: return cudaVideoCodec_VC1; } diff --git a/libavcodec/nvdec_vp8.c b/libavcodec/nvdec_vp8.c new file mode 100644 index 0000000000..6fc0ac7ded --- /dev/null +++ b/libavcodec/nvdec_vp8.c @@ -0,0 +1,97 @@ +/* + * VP8 HW decode acceleration through NVDEC + * + * Copyright (c) 2017 Philip Langdale + * + * 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 "avcodec.h" +#include "nvdec.h" +#include "decode.h" +#include "internal.h" +#include "vp8.h" + +static unsigned char safe_get_ref_idx(VP8Frame *frame) +{ + return frame ? ff_nvdec_get_ref_idx(frame->tf.f) : 255; +} + +static int nvdec_vp8_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) +{ + VP8Context *h = avctx->priv_data; + + NVDECContext *ctx = avctx->internal->hwaccel_priv_data; + CUVIDPICPARAMS *pp = &ctx->pic_params; + FrameDecodeData *fdd; + NVDECFrame *cf; + AVFrame *cur_frame = h->framep[VP56_FRAME_CURRENT]->tf.f; + + int ret; + + ret = ff_nvdec_start_frame(avctx, cur_frame); + if (ret < 0) + return ret; + + fdd = (FrameDecodeData*)cur_frame->private_ref->data; + cf = (NVDECFrame*)fdd->hwaccel_priv; + + *pp = (CUVIDPICPARAMS) { + .PicWidthInMbs = (cur_frame->width + 15) / 16, + .FrameHeightInMbs = (cur_frame->height + 15) / 16, + .CurrPicIdx = cf->idx, + + .CodecSpecific.vp8 = { + .width = cur_frame->width, + .height = cur_frame->height, + + .first_partition_size = h->header_partition_size, + + .LastRefIdx = safe_get_ref_idx(h->framep[VP56_FRAME_PREVIOUS]), + .GoldenRefIdx = safe_get_ref_idx(h->framep[VP56_FRAME_GOLDEN]), + .AltRefIdx = safe_get_ref_idx(h->framep[VP56_FRAME_GOLDEN2]), + + .frame_type = !h->keyframe, + .version = h->profile, + .show_frame = !h->invisible, + .update_mb_segmentation_data = h->segmentation.enabled ? h->segmentation.update_feature_data : 0, + } + }; + + return 0; +} + +static int nvdec_vp8_frame_params(AVCodecContext *avctx, + AVBufferRef *hw_frames_ctx) +{ + // VP8 uses a fixed size pool of 4 possible reference frames + return ff_nvdec_frame_params(avctx, hw_frames_ctx, 4); +} + +AVHWAccel ff_vp8_nvdec_hwaccel = { + .name = "vp8_nvdec", + .type = AVMEDIA_TYPE_VIDEO, + .id = AV_CODEC_ID_VP8, + .pix_fmt = AV_PIX_FMT_CUDA, + .start_frame = nvdec_vp8_start_frame, + .end_frame = ff_nvdec_simple_end_frame, + .decode_slice = ff_nvdec_simple_decode_slice, + .frame_params = nvdec_vp8_frame_params, + .init = ff_nvdec_decode_init, + .uninit = ff_nvdec_decode_uninit, + .priv_data_size = sizeof(NVDECContext), +}; diff --git a/libavcodec/version.h b/libavcodec/version.h index ba46721fb5..4dd39c9c06 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,8 @@ #define LIBAVCODEC_VERSION_MAJOR 58 #define LIBAVCODEC_VERSION_MINOR 6 -#define LIBAVCODEC_VERSION_MICRO 100 +#define LIBAVCODEC_VERSION_MICRO 101 +>>>>>>> avcodec: Implement vp8 nvdec hwaccel #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c index 2b1cd155e2..471c0bb89e 100644 --- a/libavcodec/vp8.c +++ b/libavcodec/vp8.c @@ -2601,6 +2601,9 @@ int vp78_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, enum AVPixelFormat pix_fmts[] = { #if CONFIG_VP8_VAAPI_HWACCEL AV_PIX_FMT_VAAPI, +#endif +#if CONFIG_VP8_NVDEC_HWACCEL + AV_PIX_FMT_CUDA, #endif AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE, @@ -2949,6 +2952,9 @@ AVCodec ff_vp8_decoder = { .hw_configs = (const AVCodecHWConfigInternal*[]) { #if CONFIG_VP8_VAAPI_HWACCEL HWACCEL_VAAPI(vp8), +#endif +#if CONFIG_VP8_NVDEC_HWACCEL + HWACCEL_NVDEC(vp8), #endif NULL },