diff options
author | Timo Rothenpieler <timo@rothenpieler.org> | 2017-08-30 21:12:23 +0200 |
---|---|---|
committer | Timo Rothenpieler <timo@rothenpieler.org> | 2017-09-01 10:52:15 +0200 |
commit | 0e995eac2035ecd3c4c61cccdbc8cec478441779 (patch) | |
tree | fd7a4f3396f77127985d79f0b69d2a1e5477870b /libavcodec/nvenc.c | |
parent | a0b69e2b0a7ba994b722393a0273bb3464fd5efe (diff) | |
download | ffmpeg-0e995eac2035ecd3c4c61cccdbc8cec478441779.tar.gz |
avcodec/nvenc: only push cuda context on encoder close if encoder exists
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
Diffstat (limited to 'libavcodec/nvenc.c')
-rw-r--r-- | libavcodec/nvenc.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 422ac6c73e..1220ae4b8c 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -1330,17 +1330,17 @@ av_cold int ff_nvenc_encode_close(AVCodecContext *avctx) CUcontext dummy; int i; - cu_res = dl_fn->cuda_dl->cuCtxPushCurrent(ctx->cu_context); - if (cu_res != CUDA_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "cuCtxPushCurrent failed\n"); - return AVERROR_EXTERNAL; - } - /* the encoder has to be flushed before it can be closed */ if (ctx->nvencoder) { NV_ENC_PIC_PARAMS params = { .version = NV_ENC_PIC_PARAMS_VER, .encodePicFlags = NV_ENC_PIC_FLAG_EOS }; + cu_res = dl_fn->cuda_dl->cuCtxPushCurrent(ctx->cu_context); + if (cu_res != CUDA_SUCCESS) { + av_log(avctx, AV_LOG_ERROR, "cuCtxPushCurrent failed\n"); + return AVERROR_EXTERNAL; + } + p_nvenc->nvEncEncodePicture(ctx->nvencoder, ¶ms); } @@ -1373,15 +1373,16 @@ av_cold int ff_nvenc_encode_close(AVCodecContext *avctx) av_freep(&ctx->surfaces); ctx->nb_surfaces = 0; - if (ctx->nvencoder) + if (ctx->nvencoder) { p_nvenc->nvEncDestroyEncoder(ctx->nvencoder); - ctx->nvencoder = NULL; - cu_res = dl_fn->cuda_dl->cuCtxPopCurrent(&dummy); - if (cu_res != CUDA_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "cuCtxPopCurrent failed\n"); - return AVERROR_EXTERNAL; + cu_res = dl_fn->cuda_dl->cuCtxPopCurrent(&dummy); + if (cu_res != CUDA_SUCCESS) { + av_log(avctx, AV_LOG_ERROR, "cuCtxPopCurrent failed\n"); + return AVERROR_EXTERNAL; + } } + ctx->nvencoder = NULL; if (ctx->cu_context_internal) dl_fn->cuda_dl->cuCtxDestroy(ctx->cu_context_internal); |