rtsp-stream: avoid deadlock in send_func
authorBranko Subasic <branko@axis.com>
Mon, 1 Feb 2021 11:16:46 +0000 (12:16 +0100)
committerBranko Subasic <branko@axis.com>
Mon, 1 Feb 2021 19:27:39 +0000 (20:27 +0100)
commit6fc8b963a595c0081788c551107478aaafd299d7
tree1968abf2f6081f3f0f538e1e04dd73b9cf4a2726
parent2894640cc5a796eb27e5605b3932523bd1ab5982
rtsp-stream: avoid deadlock in send_func

Currently the send_func() runs in a thread of its own which is started
the first time we enter handle_new_sample(). It runs in an outer loop
until priv->continue_sending is FALSE, which happens when a TEARDOWN
request is received. We use a local variable, cont, which is initialized
to TRUE, meaning that we will always enter the outer loop, and at the
end of the outer loop we assign it the value of priv->continue_sending.

Within the outer loop there is an inner loop, where we wait to be
signaled when there is more data to send. The inner loop is exited when
priv->send_cookie has changed value, which it does when more data is
available or when a TEARDOWN has been received.

But if we get a TEARDOWN before send_func() is entered we will get stuck
in the inner loop because no one will increase priv->session_cookie
anymore.

By not entering the outer loop in send_func() if priv->continue_sending
is FALSE we make sure that we do not get stuck in send_func()'s inner
loop should we receive a TEARDOWN before the send thread has started.

Change-Id: I7338a0ea60ea435bb685f875965f5165839afa20
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/187>
gst/rtsp-server/rtsp-stream.c