[FFmpeg-cvslog] avcodec/nvenc: only push cuda context on encoder close if encoder exists
Timo Rothenpieler
git at videolan.org
Fri Sep 1 12:15:04 EEST 2017
ffmpeg | branch: release/3.3 | Timo Rothenpieler <timo at rothenpieler.org> | Wed Aug 30 21:12:23 2017 +0200| [bab4cb3fb55e32d2f01bfb8c06f8e9fbd2d3f65d] | committer: Timo Rothenpieler
avcodec/nvenc: only push cuda context on encoder close if encoder exists
Signed-off-by: Timo Rothenpieler <timo at rothenpieler.org>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bab4cb3fb55e32d2f01bfb8c06f8e9fbd2d3f65d
---
libavcodec/nvenc.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index b7957867d7..e4f6f0f927 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1262,17 +1262,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);
}
@@ -1304,15 +1304,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);
More information about the ffmpeg-cvslog
mailing list