From 5bee089331cfe6e579f75f482b2501737cfbecdc Mon Sep 17 00:00:00 2001 From: He Junyan Date: Tue, 8 Dec 2020 13:34:35 +0800 Subject: plugins: encode: unlock the stream lock before _flush() The current encoder will hang when EOS comes. When we call the gst_vaapi_encoder_encode_and_queue(), we should release the stream lock, just like what we do in gst_vaapiencode_handle_frame(). The deadlock happens when: The input thread holding the stream lock is using gst_vaapi_encoder_create_coded_buffer() to acquire a coded buffer, while the output thread which holding the coded buffer resource is acquiring the stream lock in _push_frame() to push the data to down stream element. Part-of: --- gst/vaapi/gstvaapiencode.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gst/vaapi/gstvaapiencode.c b/gst/vaapi/gstvaapiencode.c index a970f827..b17a81e5 100644 --- a/gst/vaapi/gstvaapiencode.c +++ b/gst/vaapi/gstvaapiencode.c @@ -565,7 +565,10 @@ gst_vaapiencode_drain (GstVaapiEncode * encode) if (!encode->encoder) return TRUE; + GST_VIDEO_ENCODER_STREAM_UNLOCK (encode); status = gst_vaapi_encoder_flush (encode->encoder); + GST_VIDEO_ENCODER_STREAM_LOCK (encode); + if (status != GST_VAAPI_ENCODER_STATUS_SUCCESS) return FALSE; gst_vaapiencode_purge (encode); @@ -722,10 +725,12 @@ gst_vaapiencode_finish (GstVideoEncoder * venc) if (!encode->encoder) return GST_FLOW_NOT_NEGOTIATED; + GST_VIDEO_ENCODER_STREAM_UNLOCK (encode); + status = gst_vaapi_encoder_flush (encode->encoder); - GST_VIDEO_ENCODER_STREAM_UNLOCK (encode); gst_pad_stop_task (GST_VAAPI_PLUGIN_BASE_SRC_PAD (encode)); + GST_VIDEO_ENCODER_STREAM_LOCK (encode); while (status == GST_VAAPI_ENCODER_STATUS_SUCCESS && ret == GST_FLOW_OK) -- cgit v1.2.3