[FFmpeg-cvslog] avcodec/nvenc: push cuda context before encoding a frame
Timo Rothenpieler
git at videolan.org
Tue Feb 14 13:03:52 EET 2017
ffmpeg | branch: master | Timo Rothenpieler <timo at rothenpieler.org> | Mon Feb 13 22:59:46 2017 +0100| [be74ba648cf4063c9805ebe95ee83fd7299f7fd5] | committer: Timo Rothenpieler
avcodec/nvenc: push cuda context before encoding a frame
Thanks to Miroslav Slugeň for figuring out what was going on here.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=be74ba648cf4063c9805ebe95ee83fd7299f7fd5
---
libavcodec/nvenc.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 51e794e..ba2647b 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1649,6 +1649,8 @@ int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *frame, int *got_packet)
{
NVENCSTATUS nv_status;
+ CUresult cu_res;
+ CUcontext dummy;
NvencSurface *tmpoutsurf, *inSurf;
int res;
@@ -1666,7 +1668,20 @@ int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
return AVERROR_BUG;
}
+ 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;
+ }
+
res = nvenc_upload_frame(avctx, frame, inSurf);
+
+ 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;
+ }
+
if (res) {
inSurf->lockCount = 0;
return res;
@@ -1702,7 +1717,20 @@ int ff_nvenc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
pic_params.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;
+ }
+
nv_status = p_nvenc->nvEncEncodePicture(ctx->nvencoder, &pic_params);
+
+ 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;
+ }
+
if (nv_status != NV_ENC_SUCCESS &&
nv_status != NV_ENC_ERR_NEED_MORE_INPUT)
return nvenc_print_error(avctx, nv_status, "EncodePicture failed!");
More information about the ffmpeg-cvslog
mailing list