diff options
author | Seungha Yang <seungha.yang@navercorp.com> | 2019-03-26 20:24:22 +0900 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.com> | 2019-05-02 11:02:00 +0100 |
commit | 1410f521dbc395534f640c08a145dd1996a60879 (patch) | |
tree | ef733263b182a0c0c216b4d789ad773be12bfbad | |
parent | 6a7a92befd931904a8df0470354a86f1c6e063e3 (diff) | |
download | gstreamer-plugins-bad-1410f521dbc395534f640c08a145dd1996a60879.tar.gz |
nvenc: Ensure unmap resources before finalizing them
Mapped resource via NvEncMapInputResource() will result to unregister fail.
It can happen when paused to ready state change without EOS event.
-rw-r--r-- | sys/nvenc/gstnvbaseenc.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sys/nvenc/gstnvbaseenc.c b/sys/nvenc/gstnvbaseenc.c index 796741e55..5481b4656 100644 --- a/sys/nvenc/gstnvbaseenc.c +++ b/sys/nvenc/gstnvbaseenc.c @@ -193,6 +193,10 @@ struct gl_input_resource gsize cuda_num_bytes; NV_ENC_REGISTER_RESOURCE nv_resource; NV_ENC_MAP_INPUT_RESOURCE nv_mapped_resource; + + /* whether nv_mapped_resource was mapped via NvEncMapInputResource() + * and therefore should unmap via NvEncUnmapInputResource or not */ + gboolean mapped; }; #endif @@ -851,6 +855,8 @@ gst_nv_base_enc_bitstream_thread (gpointer user_data) nv_ret = NvEncUnmapInputResource (nvenc->encoder, in_gl_resource->nv_mapped_resource.mappedResource); + in_gl_resource->mapped = FALSE; + if (nv_ret != NV_ENC_SUCCESS) { GST_ERROR_OBJECT (nvenc, "Failed to unmap input resource %p, ret %d", in_gl_resource, nv_ret); @@ -985,6 +991,20 @@ gst_nv_base_enc_free_buffers (GstNvBaseEnc * nvenc) struct gl_input_resource *in_gl_resource = nvenc->input_bufs[i]; cuCtxPushCurrent (nvenc->cuda_ctx); + + if (in_gl_resource->mapped) { + GST_LOG_OBJECT (nvenc, "Unmap resource %p", in_gl_resource); + + nv_ret = + NvEncUnmapInputResource (nvenc->encoder, + in_gl_resource->nv_mapped_resource.mappedResource); + + if (nv_ret != NV_ENC_SUCCESS) { + GST_ERROR_OBJECT (nvenc, "Failed to unmap input resource %p, ret %d", + in_gl_resource, nv_ret); + } + } + nv_ret = NvEncUnregisterResource (nvenc->encoder, in_gl_resource->nv_resource.registeredResource); @@ -1737,6 +1757,8 @@ gst_nv_base_enc_handle_frame (GstVideoEncoder * enc, GstVideoCodecFrame * frame) goto error; } + in_gl_resource->mapped = TRUE; + out_buf = g_async_queue_try_pop (nvenc->bitstream_pool); if (out_buf == NULL) { GST_DEBUG_OBJECT (nvenc, "wait for output buf to become available again"); |