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: <https://gitlab.freedesktop.org/gstreamer/gstreamer-vaapi/-/merge_requests/404>
This commit is contained in:
He Junyan 2020-12-08 13:34:35 +08:00 committed by Víctor Manuel Jáquez Leal
parent 5997093ba1
commit 5bee089331

View file

@ -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)