summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBranko Subasic <branko@axis.com>2021-02-01 12:16:46 +0100
committerTim-Philipp Müller <tim@centricular.com>2021-02-03 00:28:35 +0000
commit9b9784abbbffd33ed8e9f9eb3d74fdfde749e3bc (patch)
treebdf5b3c11e2d243e4dc29692346883aa900a2e87
parent175cb932899257072314e563cb94e028a5e43aba (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/188>
-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 009e2aa..e211a28 100644
--- a/gst/rtsp-server/rtsp-stream.c
+++ b/gst/rtsp-server/rtsp-stream.c
@@ -2702,11 +2702,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;
@@ -2732,10 +2731,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);