From patchwork Tue May 8 13:31:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Rothenpieler X-Patchwork-Id: 8869 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp4022258jad; Tue, 8 May 2018 06:32:34 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrPJpSVUAFV5WiCxfnC4vxYHRvtPEVYeJtBEAdRdZN9zsIzLOdLAyNyhPJKMIAbibLBWy+l X-Received: by 2002:adf:9893:: with SMTP id w19-v6mr35075109wrb.34.1525786354049; Tue, 08 May 2018 06:32:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525786354; cv=none; d=google.com; s=arc-20160816; b=q3bIakNZRZyK4JfzbCaeGbW64hQb89zq15efRT/vO7I0MxutPRBf8mloz05Ygdl+zH PwWIpICTbzxxAZ9blGPW2GvUd4aycf1t+gaDz0OK20dG3rr5+toi8zckgOoomrauLlQk W4BgvQLmOl84YhaN047zIBbbWjJfLfGBuLql/PFQUMtqXppnLS/s2br2YLqTHt6GbK0y kAY2ymvZi5j7nVwkARAcdqbXWC+jVSwbtYBCbsbpoCBQjmwcv96noP+jniVePc/JDYqH n917Z3k9lrFYfKmd2ODznEBCGhcn5Y85kbLIGKFl5eAvcjBQ+sS4/i4Vs4HIiTlAJU6G K0+A== 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=QXjH5DXmROhSQvUBEyM6CszN0ZWaBv6QSGh4K57lyLQ=; b=sGlWChA1YnSK5gpvNMtkhR1iJEbH3Dl06DxJ2Pb4gX+th+fZjpkqLBzrCP0Fe0VP3B tcrG0ThXZjRHgU0iNtEazfQYa+5xpwhajKaPfDtVMAJSTh9VOB4GCqzkA9bwv5vlJEI5 vYoVAeUHcXQnt996QuHx8D9qKE6GGEbYT6JeJeyalFG6EfoxcsUrb4WXT6epatuhxoJE V5UtKPD54UE76gM/K0Bf8F9mlJJcwmAU2PV5SCPXmBMMAwc/d5gbldjlWnJa1qkVhXBD C7P26osQ0K75dn87+XZheHHGcyf1rkOpqF2zHgsO4X5QoXQGIFxqu3+U03suuzBbt0vw AySg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rothenpieler.org header.s=mail header.b=porUcxJG; 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 b2-v6si17392526wrc.306.2018.05.08.06.32.33; Tue, 08 May 2018 06:32:34 -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=@rothenpieler.org header.s=mail header.b=porUcxJG; 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 4771768A6E2; Tue, 8 May 2018 16:31:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from btbn.de (btbn.de [5.9.118.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 35A5B68A6CE for ; Tue, 8 May 2018 16:31:10 +0300 (EEST) Received: from localhost.localdomain (200116b864513a00ba975afffe10ec69.dip.versatel-1u1.de [IPv6:2001:16b8:6451:3a00:ba97:5aff:fe10:ec69]) by btbn.de (Postfix) with ESMTPSA id A34E473289; Tue, 8 May 2018 15:31:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rothenpieler.org; s=mail; t=1525786303; bh=6j9H84ZpVB3HuFuCdgoyhtIQ/4yXxGr+yrXdORbJ6sc=; h=From:To:Cc:Subject:Date; b=porUcxJGqPdgkk8Or5pnhKwyzjfPcc6ccd/ROGOBkZaSrI3vgzpnVYsILRBKqPHXx +RdKtyrvJcyV9ldwKHl8gQ3T34nWQ7tu1XzXAzgFwD6u8S0p4qJGnbAzZogW4zlvZh QMh+UvxhJk2HPdXdM3a+I1JgQYvK+lbac6PlyFQ4= From: Timo Rothenpieler To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 May 2018 15:31:27 +0200 Message-Id: <20180508133132.28940-1-timo@rothenpieler.org> X-Mailer: git-send-email 2.17.0 Subject: [FFmpeg-devel] [PATCH 1/6] avutil/hwcontext_cuda: add AVCUDAFramesContext and AVCUDAFramesContext.flags 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: Timo Rothenpieler MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Frames can be mapped from nvdec/cuvid, not needing any actual memory allocation, but all other features of the hw_frames_ctx. Hence the dummy-mode, which does not allocate any (notable amounts of) memory but otherwise behaves the exact same. --- doc/APIchanges | 3 +++ libavutil/hwcontext_cuda.c | 12 +++++++++++- libavutil/hwcontext_cuda.h | 22 +++++++++++++++++++++- libavutil/version.h | 2 +- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index ede5b186ae..f8ae6b0433 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2017-10-21 API changes, most recent first: +2018-05-xx - xxxxxxxxxx - lavu 56.19.100 - hwcontext_cuda.h + Add AVCUDAFramesContext and AVCUDAFramesContext.flags. + 2018-04-xx - xxxxxxxxxx - lavu 56.18.100 - pixdesc.h Add AV_PIX_FMT_FLAG_ALPHA to AV_PIX_FMT_PAL8. diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c index 37827a770c..b0b4bf24ae 100644 --- a/libavutil/hwcontext_cuda.c +++ b/libavutil/hwcontext_cuda.c @@ -161,6 +161,7 @@ static int cuda_frames_init(AVHWFramesContext *ctx) static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame *frame) { + AVCUDAFramesContext *frctx = ctx->hwctx; int aligned_width; int width_in_bytes = ctx->width; @@ -171,7 +172,11 @@ static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame *frame) } aligned_width = FFALIGN(width_in_bytes, CUDA_FRAME_ALIGNMENT); - frame->buf[0] = av_buffer_pool_get(ctx->pool); + if (frctx->flags & AV_CUDA_HWFRAMES_DUMMY_MODE) + frame->buf[0] = av_buffer_create(NULL, 0, NULL, NULL, 0); + else + frame->buf[0] = av_buffer_pool_get(ctx->pool); + if (!frame->buf[0]) return AVERROR(ENOMEM); @@ -210,6 +215,10 @@ static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame *frame) frame->width = ctx->width; frame->height = ctx->height; + // they're pointing to invalid memory, dangerous to leave set + if (frctx->flags & AV_CUDA_HWFRAMES_DUMMY_MODE) + frame->data[0] = frame->data[1] = frame->data[2] = NULL; + return 0; } @@ -402,6 +411,7 @@ const HWContextType ff_hwcontext_type_cuda = { .name = "CUDA", .device_hwctx_size = sizeof(AVCUDADeviceContext), + .frames_hwctx_size = sizeof(AVCUDAFramesContext), .frames_priv_size = sizeof(CUDAFramesContext), .device_create = cuda_device_create, diff --git a/libavutil/hwcontext_cuda.h b/libavutil/hwcontext_cuda.h index 12dae8449e..19accbd9be 100644 --- a/libavutil/hwcontext_cuda.h +++ b/libavutil/hwcontext_cuda.h @@ -45,7 +45,27 @@ typedef struct AVCUDADeviceContext { } AVCUDADeviceContext; /** - * AVHWFramesContext.hwctx is currently not used + * This struct is allocated as AVHWFramesContext.hwctx */ +typedef struct AVCUDAFramesContext { + /** + * Special implementation-specific flags. + * + * May be set by the user before calling av_hwframe_ctx_init(). + */ + int flags; +} AVCUDAFramesContext; + +/** + * No actual allocation will happen, but otherwise behaves like normal. + * + * This is to be used if a AVHWFramesContext is required, but the actual + * allocation is happening outside of it. + * + * The resulting AVFrames will be identical to normal frames, except for + * their data[] pointers being NULL and the AVBufferRef in buf[0] being + * set but containing no notable allocation of memory. + */ +#define AV_CUDA_HWFRAMES_DUMMY_MODE (1 << 0) #endif /* AVUTIL_HWCONTEXT_CUDA_H */ diff --git a/libavutil/version.h b/libavutil/version.h index 5185454d9b..84409b1d69 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 56 -#define LIBAVUTIL_VERSION_MINOR 18 +#define LIBAVUTIL_VERSION_MINOR 19 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \