summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBranko Subasic <branko@axis.com>2021-02-01 12:16:46 +0100
committerBranko Subasic <branko@axis.com>2021-02-01 20:27:39 +0100
commit6fc8b963a595c0081788c551107478aaafd299d7 (patch)
tree1968abf2f6081f3f0f538e1e04dd73b9cf4a2726
parent2894640cc5a796eb27e5605b3932523bd1ab5982 (diff)
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>
-rw-r--r--gst/rtsp-server/rtsp-stream.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/gst/rtsp-server/rtsp-stream.c b/gst/rtsp-server/rtsp-stream.c
index c94e6ee..c5656ca 100644
--- a/gst/rtsp-server/rtsp-stream.c
+++ b/gst/rtsp-server/rtsp-stream.c
@@ -2733,11 +2733,10 @@ static gpointer
send_func (GstRTSPStream * stream)
{
GstRTSPStreamPrivate *priv = stream->priv;
- gboolean cont = TRUE;
g_mutex_lock (&priv->send_lock);
- while (cont) {
+ while (priv->continue_sending) {
int i;
int idx = -1;
guint cookie;
@@ -2763,10 +2762,9 @@ send_func (GstRTSPStream * stream)
g_mutex_unlock (&priv->lock);
g_mutex_lock (&priv->send_lock);
- while (cookie == priv->send_cookie) {
+ while (cookie == priv->send_cookie && priv->continue_sending) {
g_cond_wait (&priv->send_cond, &priv->send_lock);
}
- cont = priv->continue_sending;
}
g_mutex_unlock (&priv->send_lock);