From patchwork Wed Mar 22 06:47:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wm4 X-Patchwork-Id: 3060 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.50.79 with SMTP id y76csp173638vsy; Tue, 21 Mar 2017 23:47:45 -0700 (PDT) X-Received: by 10.223.146.164 with SMTP id 33mr11387914wrn.135.1490165264984; Tue, 21 Mar 2017 23:47:44 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z33si739282wrc.101.2017.03.21.23.47.44; Tue, 21 Mar 2017 23:47:44 -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=@googlemail.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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A3A13688340; Wed, 22 Mar 2017 08:47:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 84C286882BF for ; Wed, 22 Mar 2017 08:47:09 +0200 (EET) Received: by mail-wm0-f66.google.com with SMTP id x124so6961350wmf.3 for ; Tue, 21 Mar 2017 23:47:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KBljJ8HnGnJih+vR6mFn4Bpkr10Izgytdxwd0AJh5XE=; b=lLo09eWrLecRT2w36NBPu+RgUrao2pMvbhde8uDWy7QSynHjef5WCilN5w0b4g5RDr kUECE40yTCy3JDFl6vMePbrWYt+lRz8c5KirlWhObr2U39mFOpog+DagINFxbWVTxf7f /ZZyLk1DhOr65rhat7Cmyz6SyJXqMq0ul3bWDNs8hP4Rhp5HiIhed3M9e1LNT0jM7Cv1 ou3ogiUafBH/QfK29mcXO5dyhN8iq4N8t8G6Uw11raKGdPInbmVK9WWZpAmv42dp1rRq 9v8gSNxjlDJt81r0xieUPjen9H1YOmrU0nlEiPDjvG3GI9wGZOhncCgG8AeGDrjNYffo 8ZGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KBljJ8HnGnJih+vR6mFn4Bpkr10Izgytdxwd0AJh5XE=; b=NyAuhwiB9ORKaasUa0BAwZE0MJqeABmZxyQWgl5vdfUg3JUOIG22k94Gmqfj55lD9r +tXx4S+hjnsCpMJSg+eUAF48vPWGo7t2nUvgIiO2mwHf1uiyXYSPKrJNIVCSXxZki9ur 5xP8nhWcd5difXwEMjONmpUHwm+BVTEcX8ZT/pvaHJeDdAHOC1Qp1bia9nPRPM4NK0pg myMAdyX+SNmfMxDCbewZO4W0ChU+VWp7iU8+OCKf+GmaoO58+dy6MIInQdUtwdpD5NL4 lfYVCQBJ+Dk5L//2/Xlfn+kuB810SjaJrTNvaa/IQO1xywN5+YMdOapPTGvZI5kTD1+T z1wg== X-Gm-Message-State: AFeK/H1BW6YAN5QTTBPsQl+qKdKjnivz7zVK1bcuKO513xKtzYU2fvCXBuvDUXbO/AYfvg== X-Received: by 10.28.84.18 with SMTP id i18mr6356657wmb.12.1490165247612; Tue, 21 Mar 2017 23:47:27 -0700 (PDT) Received: from localhost.localdomain (p4FF0073D.dip0.t-ipconnect.de. [79.240.7.61]) by smtp.googlemail.com with ESMTPSA id m188sm914626wmm.7.2017.03.21.23.47.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Mar 2017 23:47:26 -0700 (PDT) From: wm4 To: ffmpeg-devel@ffmpeg.org Date: Wed, 22 Mar 2017 07:47:27 +0100 Message-Id: <20170322064727.21772-2-nfxjfg@googlemail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170322064727.21772-1-nfxjfg@googlemail.com> References: <20170322064727.21772-1-nfxjfg@googlemail.com> Subject: [FFmpeg-devel] [PATCH 2/2] lavc: vdpau: add support for new hw_frames_ctx and hw_device_ctx API 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: wm4 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This supports retrieving the device from a provided hw_frames_ctx, and automatically creating a hw_frames_ctx if hw_device_ctx is set. The old API is not deprecated yet. The user can still use av_vdpau_bind_context() (with or without setting hw_frames_ctx), or use the API before that by allocating and setting hwaccel_context manually. (Adds missing APIchanges entry to the Libav version.) --- Libav merge. --- doc/APIchanges | 5 +++ libavcodec/vdpau.c | 95 +++++++++++++++++++++++++++++++++------------ libavcodec/vdpau_internal.h | 2 + libavcodec/version.h | 2 +- 4 files changed, 78 insertions(+), 26 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index bd0ad30a04..95b04b0933 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,11 @@ libavutil: 2015-08-28 API changes, most recent first: +2017-03-xx - xxxxxxx - lavc 57.84.101 - avcodec.h + vdpau hardware accelerated decoding now supports the new hwaccel API, which + can create the decoder context and allocate hardware frame automatically. + See AVCodecContext.hw_device_ctx and AVCodecContext.hw_frames_ctx. + 2017-03-xx - xxxxxxx - lavc 57.84.100 - avcodec.h Add AVCodecContext.hwaccel_flags field. This will control some hwaccels at a later point. diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c index bbb9913f8b..a232603c60 100644 --- a/libavcodec/vdpau.c +++ b/libavcodec/vdpau.c @@ -138,34 +138,75 @@ int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile, vdctx->width = UINT32_MAX; vdctx->height = UINT32_MAX; - if (!hwctx) { - vdctx->device = VDP_INVALID_HANDLE; - av_log(avctx, AV_LOG_WARNING, "hwaccel_context has not been setup by the user application, cannot initialize\n"); - return 0; - } + if (av_vdpau_get_surface_parameters(avctx, &type, &width, &height)) + return AVERROR(ENOSYS); - if (hwctx->context.decoder != VDP_INVALID_HANDLE) { - vdctx->decoder = hwctx->context.decoder; - vdctx->render = hwctx->context.render; - vdctx->device = VDP_INVALID_HANDLE; - return 0; /* Decoder created by user */ - } - hwctx->reset = 0; + if (hwctx) { + hwctx->reset = 0; - vdctx->device = hwctx->device; - vdctx->get_proc_address = hwctx->get_proc_address; + if (hwctx->context.decoder != VDP_INVALID_HANDLE) { + vdctx->decoder = hwctx->context.decoder; + vdctx->render = hwctx->context.render; + vdctx->device = VDP_INVALID_HANDLE; + return 0; /* Decoder created by user */ + } - if (hwctx->flags & AV_HWACCEL_FLAG_IGNORE_LEVEL) - level = 0; - else if (level < 0) - return AVERROR(ENOTSUP); + vdctx->device = hwctx->device; + vdctx->get_proc_address = hwctx->get_proc_address; + + if (hwctx->flags & AV_HWACCEL_FLAG_IGNORE_LEVEL) + level = 0; + + if (!(hwctx->flags & AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH) && + type != VDP_CHROMA_TYPE_420) + return AVERROR(ENOSYS); + } else { + AVHWFramesContext *frames_ctx = NULL; + AVVDPAUDeviceContext *dev_ctx; + + // We assume the hw_frames_ctx always survives until ff_vdpau_common_uninit + // is called. This holds true as the user is not allowed to touch + // hw_device_ctx, or hw_frames_ctx after get_format (and ff_get_format + // itself also uninits before unreffing hw_frames_ctx). + if (avctx->hw_frames_ctx) { + frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data; + } else if (avctx->hw_device_ctx) { + int ret; + + avctx->hw_frames_ctx = av_hwframe_ctx_alloc(avctx->hw_device_ctx); + if (!avctx->hw_frames_ctx) + return AVERROR(ENOMEM); + + frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data; + frames_ctx->format = AV_PIX_FMT_VDPAU; + frames_ctx->sw_format = avctx->sw_pix_fmt; + frames_ctx->width = avctx->coded_width; + frames_ctx->height = avctx->coded_height; + + ret = av_hwframe_ctx_init(avctx->hw_frames_ctx); + if (ret < 0) { + av_buffer_unref(&avctx->hw_frames_ctx); + return ret; + } + } - if (av_vdpau_get_surface_parameters(avctx, &type, &width, &height)) - return AVERROR(ENOSYS); + if (!frames_ctx) { + av_log(avctx, AV_LOG_ERROR, "A hardware frames context is " + "required for VDPAU decoding.\n"); + return AVERROR(EINVAL); + } - if (!(hwctx->flags & AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH) && - type != VDP_CHROMA_TYPE_420) - return AVERROR(ENOSYS); + dev_ctx = frames_ctx->device_ctx->hwctx; + + vdctx->device = dev_ctx->device; + vdctx->get_proc_address = dev_ctx->get_proc_address; + + if (avctx->hwaccel_flags & AV_HWACCEL_FLAG_IGNORE_LEVEL) + level = 0; + } + + if (level < 0) + return AVERROR(ENOTSUP); status = vdctx->get_proc_address(vdctx->device, VDP_FUNC_ID_VIDEO_SURFACE_QUERY_CAPABILITIES, @@ -263,7 +304,7 @@ static int ff_vdpau_common_reinit(AVCodecContext *avctx) if (vdctx->device == VDP_INVALID_HANDLE) return 0; /* Decoder created by user */ if (avctx->coded_width == vdctx->width && - avctx->coded_height == vdctx->height && !hwctx->reset) + avctx->coded_height == vdctx->height && (!hwctx || !hwctx->reset)) return 0; avctx->hwaccel->uninit(avctx); @@ -295,15 +336,17 @@ int ff_vdpau_common_end_frame(AVCodecContext *avctx, AVFrame *frame, #if FF_API_BUFS_VDPAU FF_DISABLE_DEPRECATION_WARNINGS + if (hwctx) { av_assert0(sizeof(hwctx->info) <= sizeof(pic_ctx->info)); memcpy(&hwctx->info, &pic_ctx->info, sizeof(hwctx->info)); hwctx->bitstream_buffers = pic_ctx->bitstream_buffers; hwctx->bitstream_buffers_used = pic_ctx->bitstream_buffers_used; hwctx->bitstream_buffers_allocated = pic_ctx->bitstream_buffers_allocated; + } FF_ENABLE_DEPRECATION_WARNINGS #endif - if (!hwctx->render && hwctx->render2) { + if (hwctx && !hwctx->render && hwctx->render2) { status = hwctx->render2(avctx, frame, (void *)&pic_ctx->info, pic_ctx->bitstream_buffers_used, pic_ctx->bitstream_buffers); } else @@ -315,9 +358,11 @@ FF_ENABLE_DEPRECATION_WARNINGS #if FF_API_BUFS_VDPAU FF_DISABLE_DEPRECATION_WARNINGS + if (hwctx) { hwctx->bitstream_buffers = NULL; hwctx->bitstream_buffers_used = 0; hwctx->bitstream_buffers_allocated = 0; + } FF_ENABLE_DEPRECATION_WARNINGS #endif diff --git a/libavcodec/vdpau_internal.h b/libavcodec/vdpau_internal.h index 77800af33f..30d01af65d 100644 --- a/libavcodec/vdpau_internal.h +++ b/libavcodec/vdpau_internal.h @@ -28,6 +28,8 @@ #include #include "libavutil/frame.h" +#include "libavutil/hwcontext.h" +#include "libavutil/hwcontext_vdpau.h" #include "avcodec.h" #include "vdpau.h" diff --git a/libavcodec/version.h b/libavcodec/version.h index 97cccef000..bdefbcb14b 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #define LIBAVCODEC_VERSION_MAJOR 57 #define LIBAVCODEC_VERSION_MINOR 84 -#define LIBAVCODEC_VERSION_MICRO 100 +#define LIBAVCODEC_VERSION_MICRO 101 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \