stream: release some locks in error cases
[platform/upstream/gstreamer.git] / gst / rtsp-server / rtsp-stream.c
index a6b9494..fb20090 100644 (file)
@@ -173,12 +173,10 @@ gst_rtsp_stream_class_init (GstRTSPStreamClass * klass)
           "The control string for this stream", DEFAULT_CONTROL,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
-#ifdef GST_TYPE_RTSP_PROFILE
   g_object_class_install_property (gobject_class, PROP_PROFILES,
       g_param_spec_flags ("profiles", "Profiles",
           "Allowed transfer profiles", GST_TYPE_RTSP_PROFILE,
           DEFAULT_PROFILES, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-#endif
 
   g_object_class_install_property (gobject_class, PROP_PROTOCOLS,
       g_param_spec_flags ("protocols", "Protocols",
@@ -599,16 +597,19 @@ gst_rtsp_stream_is_transport_supported (GstRTSPStream * stream,
 unsupported_transmode:
   {
     GST_DEBUG ("unsupported transport mode %d", transport->trans);
+    g_mutex_unlock (&priv->lock);
     return FALSE;
   }
 unsupported_profile:
   {
     GST_DEBUG ("unsupported profile %d", transport->profile);
+    g_mutex_unlock (&priv->lock);
     return FALSE;
   }
 unsupported_ltrans:
   {
     GST_DEBUG ("unsupported lower transport %d", transport->lower_transport);
+    g_mutex_unlock (&priv->lock);
     return FALSE;
   }
 }
@@ -1856,6 +1857,7 @@ gst_rtsp_stream_leave_bin (GstRTSPStream * stream, GstBin * bin,
 
 was_not_joined:
   {
+    g_mutex_unlock (&priv->lock);
     return TRUE;
   }
 }
@@ -1880,33 +1882,61 @@ gst_rtsp_stream_get_rtpinfo (GstRTSPStream * stream,
 {
   GstRTSPStreamPrivate *priv;
   GstStructure *stats;
+  GObjectClass *payobjclass;
 
   g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE);
 
   priv = stream->priv;
 
+  payobjclass = G_OBJECT_GET_CLASS (priv->payloader);
+
   g_mutex_lock (&priv->lock);
 
-  g_object_get (priv->payloader, "stats", &stats, NULL);
+  if (g_object_class_find_property (payobjclass, "stats")) {
+    g_object_get (priv->payloader, "stats", &stats, NULL);
+    if (stats == NULL)
+      goto no_stats;
 
-  if (seq)
-    gst_structure_get_uint (stats, "seqnum", seq);
+    if (seq)
+      gst_structure_get_uint (stats, "seqnum", seq);
 
-  if (rtptime)
-    gst_structure_get_uint (stats, "timestamp", rtptime);
+    if (rtptime)
+      gst_structure_get_uint (stats, "timestamp", rtptime);
 
-  if (running_time)
-    gst_structure_get_clock_time (stats, "running-time", running_time);
+    if (running_time)
+      gst_structure_get_clock_time (stats, "running-time", running_time);
 
-  if (clock_rate) {
-    gst_structure_get_uint (stats, "clock-rate", clock_rate);
-    if (*clock_rate == 0 && running_time)
+    if (clock_rate) {
+      gst_structure_get_uint (stats, "clock-rate", clock_rate);
+      if (*clock_rate == 0 && running_time)
+        *running_time = GST_CLOCK_TIME_NONE;
+    }
+    gst_structure_free (stats);
+  } else {
+    if (!g_object_class_find_property (payobjclass, "seqnum") ||
+        !g_object_class_find_property (payobjclass, "timestamp"))
+      goto no_stats;
+
+    if (seq)
+      g_object_get (priv->payloader, "seqnum", seq, NULL);
+
+    if (rtptime)
+      g_object_get (priv->payloader, "timestamp", rtptime, NULL);
+
+    if (running_time)
       *running_time = GST_CLOCK_TIME_NONE;
   }
-
   g_mutex_unlock (&priv->lock);
 
   return TRUE;
+
+  /* ERRORS */
+no_stats:
+  {
+    GST_WARNING ("Could not get payloader stats");
+    g_mutex_unlock (&priv->lock);
+    return FALSE;
+  }
 }
 
 /**
@@ -2045,14 +2075,14 @@ update_transport (GstRTSPStream * stream, GstRTSPStreamTransport * trans,
       }
 
       if (add) {
-        GST_INFO ("adding %s:%d-%d", dest, min, max);
-        g_signal_emit_by_name (priv->udpsink[0], "add", dest, min, NULL);
-        g_signal_emit_by_name (priv->udpsink[1], "add", dest, max, NULL);
         if (ttl > 0) {
           GST_INFO ("setting ttl-mc %d", ttl);
           g_object_set (G_OBJECT (priv->udpsink[0]), "ttl-mc", ttl, NULL);
           g_object_set (G_OBJECT (priv->udpsink[1]), "ttl-mc", ttl, NULL);
         }
+        GST_INFO ("adding %s:%d-%d", dest, min, max);
+        g_signal_emit_by_name (priv->udpsink[0], "add", dest, min, NULL);
+        g_signal_emit_by_name (priv->udpsink[1], "add", dest, max, NULL);
         priv->transports = g_list_prepend (priv->transports, trans);
       } else {
         GST_INFO ("removing %s:%d-%d", dest, min, max);
@@ -2160,15 +2190,15 @@ gst_rtsp_stream_remove_transport (GstRTSPStream * stream,
  *
  * @stream must be joined to a bin.
  *
- * Returns: the RTP socket or %NULL if no socket could be allocated for @family.
- *     Unref after usage
+ * Returns: (transfer full): the RTP socket or %NULL if no socket could be
+ *     allocated for @family. Unref after usage
  */
 GSocket *
 gst_rtsp_stream_get_rtp_socket (GstRTSPStream * stream, GSocketFamily family)
 {
   GstRTSPStreamPrivate *priv = GST_RTSP_STREAM_GET_PRIVATE (stream);
   GSocket *socket;
-  gchar *name;
+  const gchar *name;
 
   g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
   g_return_val_if_fail (family == G_SOCKET_FAMILY_IPV4 ||
@@ -2194,15 +2224,15 @@ gst_rtsp_stream_get_rtp_socket (GstRTSPStream * stream, GSocketFamily family)
  *
  * @stream must be joined to a bin.
  *
- * Returns: the RTCP socket or %NULL if no socket could be allocated for
- *     @family. Unref after usage
+ * Returns: (transfer full): the RTCP socket or %NULL if no socket could be
+ *     allocated for @family. Unref after usage
  */
 GSocket *
 gst_rtsp_stream_get_rtcp_socket (GstRTSPStream * stream, GSocketFamily family)
 {
   GstRTSPStreamPrivate *priv = GST_RTSP_STREAM_GET_PRIVATE (stream);
   GSocket *socket;
-  gchar *name;
+  const gchar *name;
 
   g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
   g_return_val_if_fail (family == G_SOCKET_FAMILY_IPV4 ||