From patchwork Sun Feb 18 23:53:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Langdale X-Patchwork-Id: 7644 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.33 with SMTP id c30csp910204jai; Sun, 18 Feb 2018 15:54:11 -0800 (PST) X-Google-Smtp-Source: AH8x224VcXmu72Rf6FfrMdn7jfTAX/KVuyMpim1foR4o+OjX2noF7MoOkrJZiYjYQzaTNLiR7+BC X-Received: by 10.223.156.207 with SMTP id h15mr10502979wre.281.1518998051919; Sun, 18 Feb 2018 15:54:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518998051; cv=none; d=google.com; s=arc-20160816; b=avMhuLOb5j8BFjdJSgJgpQZY9yTPQFWMUZAti1rb6FihoFFV4lnPxPsaY88WuZTTxy zeNM4FMMRojce+2UakX7kU4fPYpcaWaeB0/y+N+T7qss9aYI54j/+0U1Ms1Qbsa0/CdM MsefPvmbQdwVPYHddPcBg6xNww++2V2mAKEWxTOdtpOGLGgsK4x61BIoildHRDDVia4K lWFq5yY1yc97Qwd7ICVm60VHaMDEP72eZh7vfXeC+JHiGpXn8219/b359wgFHCgnbPog QvzqrcUsW0RZa/2VsBa/yUDqvCUu7ZLe79bV6y15M7eOePWE+RLHYeSeTP1+tJUtHqi+ 6o4Q== 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=caxe9w+kTlkEKPqb3XUq8Rt0w24x8tRwROQt4lx5dd8=; b=qw9DYc506UIo929aXSSTYGszr/+01B0aIRLhw1mxKahdWd45bagyH4ohYlKhA1p/p6 0RtAVy4IWosVRJffZZKi2/nN7w4fnT8c032MdiBRwi7sThYcftgRXAOb+CDQXa7t1tNe x7rmC3fo8Mrgcc4E88CRCWjwi8Dc6792Sbcntm/bUDO8zrntcuvBDsTSlUHkmg28l4qq 6nhOFSNzn55kiVHJ9OQ1VJZIrXY9RKN06VcvSbibm/nAq49y8QGUjYCgh9TZT4sHsPP7 +kwebUtfLKa7KMTuzDPJ9SG13nuBDHR+nSkXvKJMkKFhudy6RdqUIPMnTsVn7Hj7knYn gKEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@overt.org header.s=mail header.b=hdYn4nce; 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 d12si17177100wrf.340.2018.02.18.15.54.11; Sun, 18 Feb 2018 15:54:11 -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=hdYn4nce; 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 66F09689C9F; Mon, 19 Feb 2018 01:54:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io0-f226.google.com (mail-io0-f226.google.com [209.85.223.226]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A0EDF689217 for ; Mon, 19 Feb 2018 01:53:54 +0200 (EET) Received: by mail-io0-f226.google.com with SMTP id 30so4345937iog.2 for ; Sun, 18 Feb 2018 15:53:55 -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:in-reply-to:references; bh=cwQGi+rLytRA4x1WhiqhEZbcPa3TBpvs9JZnftxqRjM=; b=q0qKrs36Rn9qwxg3HV4Gyv7QMtQJVi33LFYhBvvTRlLebEkhs4+abkdNfMI2NWziqc bbsVHBgfO3d5Jbg23DfTggvyzVZRAlg4cQP+qmtNJ5YEWyl2GskCGSCvDBsq8XSglZ7k kltzn3MDipz/fiAKs3K77C/gUEfVWw/qG1HUBEPCP6G/qy0eqR9AAJxTV7+WR4msj7oI 92kRAua+MvA5B7zo1py+RRHFzKSxKOLR+gleaePgGaGYz5WXW35jRNkbCgC8Qgz8oQ4S z9LhsbvXC3Q8IwZKkhIzxQJfb+/FypHX1/t6W7Jwip37c+3vV2QnlkvN/Zf7FsnqPBfZ uxOQ== X-Gm-Message-State: APf1xPD3L1AQTT/2BH+eAcabJ8kUCUhMBpyFSAEIbzLBxLDbCianJu27 xVuJwnAhAToiONy/xTmRZn+xWAM4QVMOCSwbEudTlvO2SOck5w== X-Received: by 10.107.52.16 with SMTP id b16mr18468733ioa.103.1518998034001; Sun, 18 Feb 2018 15:53:54 -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 138sm5988230itx.0.2018.02.18.15.53.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Feb 2018 15:53:53 -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 6F070601B2; Sun, 18 Feb 2018 23:53:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=overt.org; s=mail; t=1518998033; bh=7FRj3ikn3JN6A/5FtDzIGIyBnnFSiMEdgMKdNbZuYtc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hdYn4ncet4EhWj88bHnPbaBe+AWWUki3TGsI00u8z1HL1hMNsdR5ZFS7E1Glpmwo5 KRlymyRfqRxTQ+7WiSih5fdUct43wYtriRr2IDq140zTay5mPS578GCQ4PP2rpx3+f ktboBWyv/ojwz8DRBMN4JiVL/Q2PvDcrcnj7YAMB/N5ADvJpCv6zs+UPY6fkE33YjV SsrQQSbQbd+x0t+X3KiRS+p/QiOyqZ9GDny47u3auCDSZCRpIlzMTNpl3s5alt/N4K YVRF2zaiZHtLFGlWVc6AbpUTBzaV7nt4F1SaApBlragkLpEUe9DZRtvjtSznS6pPFm ikPI0H/au95kw== From: Philip Langdale To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Feb 2018 15:53:33 -0800 Message-Id: <20180218235333.6965-4-philipl@overt.org> In-Reply-To: <20180218235333.6965-1-philipl@overt.org> References: <20180218235333.6965-1-philipl@overt.org> Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/nvdec: Implement mjpeg 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" --- Changelog | 2 +- configure | 2 ++ libavcodec/Makefile | 1 + libavcodec/hwaccels.h | 1 + libavcodec/mjpegdec.c | 6 ++++ libavcodec/nvdec.c | 1 + libavcodec/nvdec_mjpeg.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ libavcodec/version.h | 2 +- 8 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 libavcodec/nvdec_mjpeg.c diff --git a/Changelog b/Changelog index 2acdbbea30..82603c1c58 100644 --- a/Changelog +++ b/Changelog @@ -13,7 +13,7 @@ version : - PCE support for extended channel layouts in the AAC encoder - native aptX and aptX HD encoder and decoder - Raw aptX and aptX HD muxer and demuxer -- NVIDIA NVDEC-accelerated H.264, HEVC, MPEG-1/2/4, VC1, VP8/9 hwaccel decoding +- NVIDIA NVDEC-accelerated H.264, HEVC, MJPEG, MPEG-1/2/4, VC1, VP8/9 hwaccel decoding - Intel QSV-accelerated overlay filter - mcompand audio filter - acontrast audio filter diff --git a/configure b/configure index 99c53d482a..76f2b154ae 100755 --- a/configure +++ b/configure @@ -2714,6 +2714,8 @@ hevc_vdpau_hwaccel_deps="vdpau VdpPictureInfoHEVC" hevc_vdpau_hwaccel_select="hevc_decoder" hevc_videotoolbox_hwaccel_deps="videotoolbox" hevc_videotoolbox_hwaccel_select="hevc_decoder" +mjpeg_nvdec_hwaccel_deps="nvdec" +mjpeg_nvdec_hwaccel_select="mjpeg_decoder" mpeg_xvmc_hwaccel_deps="xvmc" mpeg_xvmc_hwaccel_select="mpeg2video_decoder" mpeg1_nvdec_hwaccel_deps="nvdec" diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 3d4b738e0b..a66b4d7217 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -854,6 +854,7 @@ OBJS-$(CONFIG_HEVC_NVDEC_HWACCEL) += nvdec_hevc.o OBJS-$(CONFIG_HEVC_QSV_HWACCEL) += qsvdec_h2645.o OBJS-$(CONFIG_HEVC_VAAPI_HWACCEL) += vaapi_hevc.o OBJS-$(CONFIG_HEVC_VDPAU_HWACCEL) += vdpau_hevc.o +OBJS-$(CONFIG_MJPEG_NVDEC_HWACCEL) += nvdec_mjpeg.o OBJS-$(CONFIG_MPEG1_NVDEC_HWACCEL) += nvdec_mpeg12.o OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL) += vdpau_mpeg12.o OBJS-$(CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o diff --git a/libavcodec/hwaccels.h b/libavcodec/hwaccels.h index fcfe4e088e..7415eae371 100644 --- a/libavcodec/hwaccels.h +++ b/libavcodec/hwaccels.h @@ -37,6 +37,7 @@ extern const AVHWAccel ff_hevc_nvdec_hwaccel; extern const AVHWAccel ff_hevc_vaapi_hwaccel; extern const AVHWAccel ff_hevc_vdpau_hwaccel; extern const AVHWAccel ff_hevc_videotoolbox_hwaccel; +extern const AVHWAccel ff_mjpeg_nvdec_hwaccel; extern const AVHWAccel ff_mpeg1_nvdec_hwaccel; extern const AVHWAccel ff_mpeg1_vdpau_hwaccel; extern const AVHWAccel ff_mpeg1_videotoolbox_hwaccel; diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index b41d2ce467..7d64a926ad 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -650,6 +650,9 @@ unk_pixfmt: s->avctx->pix_fmt = s->hwaccel_pix_fmt; } else { enum AVPixelFormat pix_fmts[] = { +#if CONFIG_MJPEG_NVDEC_HWACCEL + AV_PIX_FMT_CUDA, +#endif s->avctx->pix_fmt, AV_PIX_FMT_NONE, }; @@ -2770,6 +2773,9 @@ AVCodec ff_mjpeg_decoder = { .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, .hw_configs = (const AVCodecHWConfigInternal*[]) { +#if CONFIG_MJPEG_NVDEC_HWACCEL + HWACCEL_NVDEC(mjpeg), +#endif NULL }, }; diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c index e9e6ea0f8b..ab3cb88b27 100644 --- a/libavcodec/nvdec.c +++ b/libavcodec/nvdec.c @@ -54,6 +54,7 @@ static int map_avcodec_id(enum AVCodecID id) switch (id) { case AV_CODEC_ID_H264: return cudaVideoCodec_H264; case AV_CODEC_ID_HEVC: return cudaVideoCodec_HEVC; + case AV_CODEC_ID_MJPEG: return cudaVideoCodec_JPEG; case AV_CODEC_ID_MPEG1VIDEO: return cudaVideoCodec_MPEG1; case AV_CODEC_ID_MPEG2VIDEO: return cudaVideoCodec_MPEG2; case AV_CODEC_ID_MPEG4: return cudaVideoCodec_MPEG4; diff --git a/libavcodec/nvdec_mjpeg.c b/libavcodec/nvdec_mjpeg.c new file mode 100644 index 0000000000..7e404246ce --- /dev/null +++ b/libavcodec/nvdec_mjpeg.c @@ -0,0 +1,86 @@ +/* + * MJPEG 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 "internal.h" +#include "mjpegdec.h" +#include "nvdec.h" +#include "decode.h" + +static int nvdec_mjpeg_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) +{ + MJpegDecodeContext *s = avctx->priv_data; + + NVDECContext *ctx = avctx->internal->hwaccel_priv_data; + CUVIDPICPARAMS *pp = &ctx->pic_params; + FrameDecodeData *fdd; + NVDECFrame *cf; + AVFrame *cur_frame = s->picture; + + 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, + + .intra_pic_flag = 1, + .ref_pic_flag = 0, + }; + + return ff_nvdec_simple_decode_slice(avctx, buffer, size); +} + +static int nvdec_mjpeg_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) +{ + return 0; +} + +static int nvdec_mjpeg_frame_params(AVCodecContext *avctx, + AVBufferRef *hw_frames_ctx) +{ + // Only need storage for the current frame + return ff_nvdec_frame_params(avctx, hw_frames_ctx, 1); +} + +#if CONFIG_MJPEG_NVDEC_HWACCEL +AVHWAccel ff_mjpeg_nvdec_hwaccel = { + .name = "mjpeg_nvdec", + .type = AVMEDIA_TYPE_VIDEO, + .id = AV_CODEC_ID_MJPEG, + .pix_fmt = AV_PIX_FMT_CUDA, + .start_frame = nvdec_mjpeg_start_frame, + .end_frame = ff_nvdec_simple_end_frame, + .decode_slice = nvdec_mjpeg_decode_slice, + .frame_params = nvdec_mjpeg_frame_params, + .init = ff_nvdec_decode_init, + .uninit = ff_nvdec_decode_uninit, + .priv_data_size = sizeof(NVDECContext), +}; +#endif diff --git a/libavcodec/version.h b/libavcodec/version.h index d13dd41fa3..0ba6e6a164 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #define LIBAVCODEC_VERSION_MAJOR 58 #define LIBAVCODEC_VERSION_MINOR 11 -#define LIBAVCODEC_VERSION_MICRO 101 +#define LIBAVCODEC_VERSION_MICRO 102 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \