[farsight2/master] Don't re-lock too early after emitting src-pad-added

Olivier Crête olivier.crete at collabora.co.uk
Tue Dec 16 15:28:38 PST 2008


---
 gst/fsrtpconference/fs-rtp-session.c   |   31 ++++++++++++------------
 gst/fsrtpconference/fs-rtp-stream.c    |   11 ++++++--
 gst/fsrtpconference/fs-rtp-stream.h    |    2 +-
 gst/fsrtpconference/fs-rtp-substream.c |   40 +++++++++++++++++--------------
 gst/fsrtpconference/fs-rtp-substream.h |    4 +-
 5 files changed, 49 insertions(+), 39 deletions(-)

diff --git a/gst/fsrtpconference/fs-rtp-session.c b/gst/fsrtpconference/fs-rtp-session.c
index 8bea13c..198b4f4 100644
--- a/gst/fsrtpconference/fs-rtp-session.c
+++ b/gst/fsrtpconference/fs-rtp-session.c
@@ -1856,7 +1856,7 @@ fs_rtp_session_verify_recv_codecs_locked (FsRtpSession *session)
   for (item = g_list_first (session->priv->free_substreams);
        item;
        item = g_list_next (item))
-    fs_rtp_sub_stream_verify_codec_locked (item->data);
+    fs_rtp_sub_stream_verify_codec (item->data);
 
   for (item = g_list_first (session->priv->streams);
        item;
@@ -1867,7 +1867,7 @@ fs_rtp_session_verify_recv_codecs_locked (FsRtpSession *session)
     for (item2 = g_list_first (stream->substreams);
          item2;
          item2 = g_list_next (item2))
-      fs_rtp_sub_stream_verify_codec_locked (item2->data);
+      fs_rtp_sub_stream_verify_codec (item2->data);
 
   }
 }
@@ -2314,15 +2314,17 @@ fs_rtp_session_new_recv_pad (FsRtpSession *session, GstPad *new_pad,
 
   if (stream)
   {
-    if (!fs_rtp_stream_add_substream_locked (stream, substream, &error))
+    if (!fs_rtp_stream_add_substream_unlock (stream, substream, &error))
       fs_session_emit_error (FS_SESSION (session), error->code,
           "Could not add the output ghostpad to the new substream",
           error->message);
 
     g_clear_error (&error);
   }
-
-  FS_RTP_SESSION_UNLOCK (session);
+  else
+  {
+    FS_RTP_SESSION_UNLOCK (session);
+  }
 
   if (stream)
     g_object_unref (stream);
@@ -3502,9 +3504,9 @@ fs_rtp_session_associate_free_substreams (FsRtpSession *session,
         g_signal_handlers_disconnect_by_func (substream, "no-rtcp-timedout",
             session) > 0);
 
-    if (fs_rtp_stream_add_substream_locked (stream, substream, &error))
+    if (fs_rtp_stream_add_substream_unlock (stream, substream, &error))
     {
-      fs_rtp_sub_stream_verify_codec_locked (substream);
+      fs_rtp_sub_stream_verify_codec (substream);
       GST_DEBUG ("Associated SSRC %x in session %u", ssrc, session->id);
     }
     else
@@ -3516,6 +3518,7 @@ fs_rtp_session_associate_free_substreams (FsRtpSession *session,
           error->message);
     }
     g_clear_error (&error);
+    FS_RTP_SESSION_LOCK (session);
   }
   FS_RTP_SESSION_UNLOCK (session);
 
@@ -3587,14 +3590,16 @@ _substream_no_rtcp_timedout_cb (FsRtpSubStream *substream,
         " for %d milliseconds, but we have more than one stream so we can"
         " not associate it.", substream->ssrc, substream->pt,
         substream->no_rtcp_timeout);
-    goto done;
+    FS_RTP_SESSION_UNLOCK (session);
+    return;
   }
 
   if (!g_list_find (session->priv->free_substreams, substream))
   {
     GST_WARNING ("Could not find substream %p in the list of free substreams",
         substream);
-    goto done;
+    FS_RTP_SESSION_UNLOCK (session);
+    return;
   }
 
   session->priv->free_substreams =
@@ -3608,8 +3613,8 @@ _substream_no_rtcp_timedout_cb (FsRtpSubStream *substream,
 
   first_stream = g_list_first (session->priv->streams)->data;
   g_object_ref (first_stream);
-  if (fs_rtp_stream_add_substream_locked (first_stream, substream, &error))
-    fs_rtp_sub_stream_verify_codec_locked (substream);
+  if (fs_rtp_stream_add_substream_unlock (first_stream, substream, &error))
+    fs_rtp_sub_stream_verify_codec (substream);
   else
     fs_session_emit_error (FS_SESSION (session),
         error ? error->code : FS_ERROR_INTERNAL,
@@ -3617,10 +3622,6 @@ _substream_no_rtcp_timedout_cb (FsRtpSubStream *substream,
         error ? error->message : "No error message");
   g_clear_error (&error);
   g_object_unref (first_stream);
-
- done:
-
-  FS_RTP_SESSION_UNLOCK (session);
 }
 
 /**
diff --git a/gst/fsrtpconference/fs-rtp-stream.c b/gst/fsrtpconference/fs-rtp-stream.c
index ca75a5d..56b2cb2 100644
--- a/gst/fsrtpconference/fs-rtp-stream.c
+++ b/gst/fsrtpconference/fs-rtp-stream.c
@@ -740,16 +740,19 @@ _substream_error (FsRtpSubStream *substream,
 }
 
 /**
- * fs_rtp_stream_add_substream_locked:
+ * fs_rtp_stream_add_substream_unlock:
  * @stream: a #FsRtpStream
  * @substream: the #FsRtpSubStream to associate with this stream
  *
  * This functions associates a substream with this stream
  *
+ * You must enter this function with the session lock held and it will release
+ * it.
+ *
  * Returns: TRUE on success, FALSE on failure
  */
 gboolean
-fs_rtp_stream_add_substream_locked (FsRtpStream *stream,
+fs_rtp_stream_add_substream_unlock (FsRtpStream *stream,
     FsRtpSubStream *substream,
     GError **error)
 {
@@ -771,7 +774,9 @@ fs_rtp_stream_add_substream_locked (FsRtpStream *stream,
 
   /* Only announce a pad if it has a codec attached to it */
   if (substream->codec)
-    ret = fs_rtp_sub_stream_add_output_ghostpad_locked (substream, error);
+    ret = fs_rtp_sub_stream_add_output_ghostpad_unlock (substream, error);
+  else
+    FS_RTP_SESSION_UNLOCK (stream->priv->session);
 
   return ret;
 }
diff --git a/gst/fsrtpconference/fs-rtp-stream.h b/gst/fsrtpconference/fs-rtp-stream.h
index 1b1dae1..0f169e5 100644
--- a/gst/fsrtpconference/fs-rtp-stream.h
+++ b/gst/fsrtpconference/fs-rtp-stream.h
@@ -100,7 +100,7 @@ FsRtpStream *fs_rtp_stream_new (FsRtpSession *session,
     gpointer user_data_for_cb,
     GError **error);
 
-gboolean fs_rtp_stream_add_substream_locked (FsRtpStream *stream,
+gboolean fs_rtp_stream_add_substream_unlock (FsRtpStream *stream,
     FsRtpSubStream *substream,
     GError **error);
 
diff --git a/gst/fsrtpconference/fs-rtp-substream.c b/gst/fsrtpconference/fs-rtp-substream.c
index 8ea66ce..f98a1b3 100644
--- a/gst/fsrtpconference/fs-rtp-substream.c
+++ b/gst/fsrtpconference/fs-rtp-substream.c
@@ -801,7 +801,8 @@ fs_rtp_sub_stream_set_codecbin_unlock (FsRtpSubStream *substream,
           "Could not set the codec bin for ssrc %u"
           " and payload type %d to the state NULL", substream->ssrc,
           substream->pt);
-      goto error_no_remove;
+      FS_RTP_SESSION_UNLOCK (substream->priv->session);
+      return FALSE;
     }
 
     gst_bin_remove (GST_BIN (substream->priv->conference),
@@ -820,7 +821,8 @@ fs_rtp_sub_stream_set_codecbin_unlock (FsRtpSubStream *substream,
   {
     g_set_error (error, FS_ERROR, FS_ERROR_CONSTRUCTION,
       "Could not add the codec bin to the conference");
-    goto error_no_remove;
+    FS_RTP_SESSION_UNLOCK (substream->priv->session);
+    return FALSE;
   }
 
   if (gst_element_set_state (codecbin, GST_STATE_PLAYING) ==
@@ -828,7 +830,7 @@ fs_rtp_sub_stream_set_codecbin_unlock (FsRtpSubStream *substream,
   {
     g_set_error (error, FS_ERROR, FS_ERROR_CONSTRUCTION,
       "Could not set the codec bin to the playing state");
-    goto error;
+    goto error_locked;
   }
 
   if (!gst_element_link_pads (codecbin, "src",
@@ -836,7 +838,7 @@ fs_rtp_sub_stream_set_codecbin_unlock (FsRtpSubStream *substream,
   {
     g_set_error (error, FS_ERROR, FS_ERROR_CONSTRUCTION,
       "Could not link the codec bin to the valve");
-    goto error;
+    goto error_locked;
   }
 
   if (!gst_element_link_pads (substream->priv->capsfilter, "src",
@@ -845,7 +847,7 @@ fs_rtp_sub_stream_set_codecbin_unlock (FsRtpSubStream *substream,
      g_set_error (error, FS_ERROR, FS_ERROR_CONSTRUCTION,
          "Could not link the receive capsfilter and the codecbin for pt %d",
          substream->pt);
-    goto error;
+    goto error_locked;
   }
 
   caps = fs_codec_to_gst_caps (codec);
@@ -859,7 +861,7 @@ fs_rtp_sub_stream_set_codecbin_unlock (FsRtpSubStream *substream,
   {
     g_set_error (error, FS_ERROR, FS_ERROR_INTERNAL, "Could not get sink pad"
         " from codecbin");
-    goto error;
+    goto error_locked;
   }
 
   /* This is a non-error error
@@ -876,7 +878,7 @@ fs_rtp_sub_stream_set_codecbin_unlock (FsRtpSubStream *substream,
 
     /* We call this to drop all buffers until something comes up */
     fs_rtp_sub_stream_add_probe_locked (substream);
-    goto error;
+    goto error_locked;
   }
 
   gst_object_unref (pad);
@@ -887,9 +889,8 @@ fs_rtp_sub_stream_set_codecbin_unlock (FsRtpSubStream *substream,
 
   if (substream->priv->stream && !substream->priv->output_ghostpad)
   {
-    if (!fs_rtp_sub_stream_add_output_ghostpad_locked (substream, error))
+    if (!fs_rtp_sub_stream_add_output_ghostpad_unlock (substream, error))
       goto error;
-    FS_RTP_SESSION_UNLOCK (substream->priv->session);
   }
   else
   {
@@ -900,6 +901,9 @@ fs_rtp_sub_stream_set_codecbin_unlock (FsRtpSubStream *substream,
 
   return TRUE;
 
+ error_locked:
+  FS_RTP_SESSION_UNLOCK (substream->priv->session);
+
  error:
 
   gst_element_set_locked_state (codecbin, TRUE);
@@ -907,10 +911,6 @@ fs_rtp_sub_stream_set_codecbin_unlock (FsRtpSubStream *substream,
   gst_object_ref (codecbin);
   gst_bin_remove (GST_BIN (substream->priv->conference), codecbin);
 
- error_no_remove:
-
-  FS_RTP_SESSION_UNLOCK (substream->priv->session);
-
   return ret;
 }
 
@@ -976,7 +976,7 @@ fs_rtp_sub_stream_stop (FsRtpSubStream *substream)
 
 
 /**
- * fs_rtp_sub_stream_add_output_ghostpad:
+ * fs_rtp_sub_stream_add_output_ghostpad_unlock:
  *
  * Creates and adds an output ghostpad for this substreams
  *
@@ -986,7 +986,7 @@ fs_rtp_sub_stream_stop (FsRtpSubStream *substream)
  */
 
 gboolean
-fs_rtp_sub_stream_add_output_ghostpad_locked (FsRtpSubStream *substream,
+fs_rtp_sub_stream_add_output_ghostpad_unlock (FsRtpSubStream *substream,
     GError **error)
 {
   GstPad *valve_srcpad;
@@ -1016,6 +1016,7 @@ fs_rtp_sub_stream_add_output_ghostpad_locked (FsRtpSubStream *substream,
     g_set_error (error, FS_ERROR, FS_ERROR_CONSTRUCTION,
         "Could not build ghostpad src_%u_%u_%d", substream->priv->session->id,
         substream->ssrc, substream->pt);
+    FS_RTP_SESSION_UNLOCK (substream->priv->session);
     return FALSE;
   }
 
@@ -1025,6 +1026,7 @@ fs_rtp_sub_stream_add_output_ghostpad_locked (FsRtpSubStream *substream,
         "Could not activate the src_%u_%u_%d", substream->priv->session->id,
         substream->ssrc, substream->pt);
     gst_object_unref (ghostpad);
+    FS_RTP_SESSION_UNLOCK (substream->priv->session);
     return FALSE;
   }
 
@@ -1035,6 +1037,7 @@ fs_rtp_sub_stream_add_output_ghostpad_locked (FsRtpSubStream *substream,
         "Could add build ghostpad src_%u_%u_%d to the conference",
         substream->priv->session->id, substream->ssrc, substream->pt);
     gst_object_unref (ghostpad);
+    FS_RTP_SESSION_UNLOCK (substream->priv->session);
     return FALSE;
   }
 
@@ -1048,10 +1051,11 @@ fs_rtp_sub_stream_add_output_ghostpad_locked (FsRtpSubStream *substream,
   g_signal_emit (substream, signals[SRC_PAD_ADDED], 0,
                  ghostpad, substream->codec);
   g_signal_emit (substream, signals[CODEC_CHANGED], 0);
-  FS_RTP_SESSION_LOCK (substream->priv->session);
 
+  FS_RTP_SESSION_LOCK (substream->priv->session);
   if (substream->priv->receiving)
     g_object_set (substream->priv->valve, "drop", FALSE, NULL);
+  FS_RTP_SESSION_UNLOCK (substream->priv->session);
 
   return TRUE;
 }
@@ -1139,7 +1143,7 @@ fs_rtp_sub_stream_add_probe_locked (FsRtpSubStream *substream)
 }
 
 /**
- * fs_rtp_sub_stream_verify_codec_locked:
+ * fs_rtp_sub_stream_verify_codec:
  * @substream: A #FsRtpSubStream
  *
  * This function will start the process that invalidates the codec
@@ -1149,7 +1153,7 @@ fs_rtp_sub_stream_add_probe_locked (FsRtpSubStream *substream)
  */
 
 void
-fs_rtp_sub_stream_verify_codec_locked (FsRtpSubStream *substream)
+fs_rtp_sub_stream_verify_codec (FsRtpSubStream *substream)
 {
   GST_LOG ("Starting codec verification process for substream with"
       " SSRC:%x pt:%d", substream->ssrc, substream->pt);
diff --git a/gst/fsrtpconference/fs-rtp-substream.h b/gst/fsrtpconference/fs-rtp-substream.h
index 391f0ea..5bb9a79 100644
--- a/gst/fsrtpconference/fs-rtp-substream.h
+++ b/gst/fsrtpconference/fs-rtp-substream.h
@@ -98,11 +98,11 @@ gboolean fs_rtp_sub_stream_set_codecbin_unlock (FsRtpSubStream *substream,
 
 void fs_rtp_sub_stream_stop (FsRtpSubStream *substream);
 
-gboolean fs_rtp_sub_stream_add_output_ghostpad_locked (
+gboolean fs_rtp_sub_stream_add_output_ghostpad_unlock (
     FsRtpSubStream *substream,
     GError **error);
 
-void fs_rtp_sub_stream_verify_codec_locked (FsRtpSubStream *substream);
+void fs_rtp_sub_stream_verify_codec (FsRtpSubStream *substream);
 
 
 G_END_DECLS
-- 
1.5.6.5




More information about the farsight-commits mailing list