diff mbox series

[FFmpeg-devel,v2] avcodec/cuviddec: fix CUDA_ERROR_INVALID_CONTEXT error found by cuda-memcheck tool

Message ID 20201120032343.1966-1-nowerzt@gmail.com
State Accepted
Commit 7ce7d33d1537bebe3e11b4046466d6c694f2e9c7
Headers show
Series [FFmpeg-devel,v2] avcodec/cuviddec: fix CUDA_ERROR_INVALID_CONTEXT error found by cuda-memcheck tool
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

leozhang Nov. 20, 2020, 3:23 a.m. UTC
Test command like below:
cuda-memcheck ./ffmpeg -hwaccel cuvid -c:v h264_cuvid -i input_file -c:v h264_nvenc -f null -

Signed-off-by: leozhang <nowerzt@gmail.com>
---
 libavcodec/cuviddec.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Timo Rothenpieler Nov. 21, 2020, 9:02 p.m. UTC | #1
applied
diff mbox series

Patch

diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index 5e698d4cd0..61d7f36c79 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -673,15 +673,22 @@  static int cuvid_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
 static av_cold int cuvid_decode_end(AVCodecContext *avctx)
 {
     CuvidContext *ctx = avctx->priv_data;
+    AVHWDeviceContext *device_ctx = (AVHWDeviceContext *)ctx->hwdevice->data;
+    AVCUDADeviceContext *device_hwctx = device_ctx->hwctx;
+    CUcontext dummy, cuda_ctx = device_hwctx->cuda_ctx;
 
     av_fifo_freep(&ctx->frame_queue);
 
+    ctx->cudl->cuCtxPushCurrent(cuda_ctx);
+
     if (ctx->cuparser)
         ctx->cvdl->cuvidDestroyVideoParser(ctx->cuparser);
 
     if (ctx->cudecoder)
         ctx->cvdl->cuvidDestroyDecoder(ctx->cudecoder);
 
+    ctx->cudl->cuCtxPopCurrent(&dummy);
+
     ctx->cudl = NULL;
 
     av_buffer_unref(&ctx->hwframe);