avcodec/nvenc: only push cuda context on encoder close if encoder exists

Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
This commit is contained in:
Timo Rothenpieler 2017-08-30 21:12:23 +02:00
parent e51e07c34e
commit bab4cb3fb5
1 changed files with 13 additions and 12 deletions

View File

@ -1262,17 +1262,17 @@ av_cold int ff_nvenc_encode_close(AVCodecContext *avctx)
CUcontext dummy; CUcontext dummy;
int i; int i;
/* 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); cu_res = dl_fn->cuda_dl->cuCtxPushCurrent(ctx->cu_context);
if (cu_res != CUDA_SUCCESS) { if (cu_res != CUDA_SUCCESS) {
av_log(avctx, AV_LOG_ERROR, "cuCtxPushCurrent failed\n"); av_log(avctx, AV_LOG_ERROR, "cuCtxPushCurrent failed\n");
return AVERROR_EXTERNAL; 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 };
p_nvenc->nvEncEncodePicture(ctx->nvencoder, &params); p_nvenc->nvEncEncodePicture(ctx->nvencoder, &params);
} }
@ -1304,15 +1304,16 @@ av_cold int ff_nvenc_encode_close(AVCodecContext *avctx)
av_freep(&ctx->surfaces); av_freep(&ctx->surfaces);
ctx->nb_surfaces = 0; ctx->nb_surfaces = 0;
if (ctx->nvencoder) if (ctx->nvencoder) {
p_nvenc->nvEncDestroyEncoder(ctx->nvencoder); p_nvenc->nvEncDestroyEncoder(ctx->nvencoder);
ctx->nvencoder = NULL;
cu_res = dl_fn->cuda_dl->cuCtxPopCurrent(&dummy); cu_res = dl_fn->cuda_dl->cuCtxPopCurrent(&dummy);
if (cu_res != CUDA_SUCCESS) { if (cu_res != CUDA_SUCCESS) {
av_log(avctx, AV_LOG_ERROR, "cuCtxPopCurrent failed\n"); av_log(avctx, AV_LOG_ERROR, "cuCtxPopCurrent failed\n");
return AVERROR_EXTERNAL; return AVERROR_EXTERNAL;
} }
}
ctx->nvencoder = NULL;
if (ctx->cu_context_internal) if (ctx->cu_context_internal)
dl_fn->cuda_dl->cuCtxDestroy(ctx->cu_context_internal); dl_fn->cuda_dl->cuCtxDestroy(ctx->cu_context_internal);