[FFmpeg-cvslog] Merge commit '2e219b491bcc0845248345fdad31231b081e06d1'

Hendrik Leppkes git at videolan.org
Sun Jun 26 20:23:55 CEST 2016


ffmpeg | branch: release/3.1 | Hendrik Leppkes <h.leppkes at gmail.com> | Sun Jun 26 15:25:12 2016 +0200| [c5a0c16850fc8bcdd38f30824ee2acaeba45749c] | committer: Hendrik Leppkes

Merge commit '2e219b491bcc0845248345fdad31231b081e06d1'

* commit '2e219b491bcc0845248345fdad31231b081e06d1':
  hwcontext_cuda: implement device creation

Merged-by: Hendrik Leppkes <h.leppkes at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c5a0c16850fc8bcdd38f30824ee2acaeba45749c
---

 libavutil/hwcontext_cuda.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
index 2c5980d..fa24c5d 100644
--- a/libavutil/hwcontext_cuda.c
+++ b/libavutil/hwcontext_cuda.c
@@ -253,6 +253,49 @@ static int cuda_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst,
     return 0;
 }
 
+static void cuda_device_free(AVHWDeviceContext *ctx)
+{
+    AVCUDADeviceContext *hwctx = ctx->hwctx;
+    cuCtxDestroy(hwctx->cuda_ctx);
+}
+
+static int cuda_device_create(AVHWDeviceContext *ctx, const char *device,
+                              AVDictionary *opts, int flags)
+{
+    AVCUDADeviceContext *hwctx = ctx->hwctx;
+    CUdevice cu_device;
+    CUcontext dummy;
+    CUresult err;
+    int device_idx = 0;
+
+    if (device)
+        device_idx = strtol(device, NULL, 0);
+
+    err = cuInit(0);
+    if (err != CUDA_SUCCESS) {
+        av_log(ctx, AV_LOG_ERROR, "Could not initialize the CUDA driver API\n");
+        return AVERROR_UNKNOWN;
+    }
+
+    err = cuDeviceGet(&cu_device, device_idx);
+    if (err != CUDA_SUCCESS) {
+        av_log(ctx, AV_LOG_ERROR, "Could not get the device number %d\n", device_idx);
+        return AVERROR_UNKNOWN;
+    }
+
+    err = cuCtxCreate(&hwctx->cuda_ctx, 0, cu_device);
+    if (err != CUDA_SUCCESS) {
+        av_log(ctx, AV_LOG_ERROR, "Error creating a CUDA context\n");
+        return AVERROR_UNKNOWN;
+    }
+
+    cuCtxPopCurrent(&dummy);
+
+    ctx->free = cuda_device_free;
+
+    return 0;
+}
+
 const HWContextType ff_hwcontext_type_cuda = {
     .type                 = AV_HWDEVICE_TYPE_CUDA,
     .name                 = "CUDA",
@@ -260,6 +303,7 @@ const HWContextType ff_hwcontext_type_cuda = {
     .device_hwctx_size    = sizeof(AVCUDADeviceContext),
     .frames_priv_size     = sizeof(CUDAFramesContext),
 
+    .device_create        = cuda_device_create,
     .frames_init          = cuda_frames_init,
     .frames_get_buffer    = cuda_get_buffer,
     .transfer_get_formats = cuda_transfer_get_formats,


======================================================================




More information about the ffmpeg-cvslog mailing list