rtsp-client: make sure sessmedia will not get freed while used
[platform/upstream/gstreamer.git] / subprojects / gst-rtsp-server / gst / rtsp-server / rtsp-session.c
index b1b0799..2f51120 100644 (file)
@@ -343,20 +343,9 @@ gst_rtsp_session_release_media (GstRTSPSession * sess,
   return more;
 }
 
-/**
- * gst_rtsp_session_get_media:
- * @sess: a #GstRTSPSession
- * @path: the path for the media
- * @matched: (out): the amount of matched characters
- *
- * Get the session media for @path. @matched will contain the number of matched
- * characters of @path.
- *
- * Returns: (transfer none) (nullable): the configuration for @path in @sess.
- */
-GstRTSPSessionMedia *
-gst_rtsp_session_get_media (GstRTSPSession * sess, const gchar * path,
-    gint * matched)
+static GstRTSPSessionMedia *
+_gst_rtsp_session_get_media (GstRTSPSession * sess, const gchar * path,
+    gint * matched, gboolean dup)
 {
   GstRTSPSessionPrivate *priv;
   GstRTSPSessionMedia *result;
@@ -384,6 +373,9 @@ gst_rtsp_session_get_media (GstRTSPSession * sess, const gchar * path,
       }
     }
   }
+
+  if (result && dup)
+    result = g_object_ref (result);
   g_mutex_unlock (&priv->lock);
 
   *matched = best;
@@ -392,6 +384,45 @@ gst_rtsp_session_get_media (GstRTSPSession * sess, const gchar * path,
 }
 
 /**
+ * gst_rtsp_session_get_media:
+ * @sess: a #GstRTSPSession
+ * @path: the path for the media
+ * @matched: (out): the amount of matched characters
+ *
+ * Gets the session media for @path. @matched will contain the number of matched
+ * characters of @path.
+ *
+ * Returns: (transfer none) (nullable): the configuration for @path in @sess.
+ */
+GstRTSPSessionMedia *
+gst_rtsp_session_get_media (GstRTSPSession * sess, const gchar * path,
+    gint * matched)
+{
+  return _gst_rtsp_session_get_media (sess, path, matched, FALSE);
+}
+
+/**
+ * gst_rtsp_session_dup_media:
+ * @sess: a #GstRTSPSession
+ * @path: the path for the media
+ * @matched: (out): the amount of matched characters
+ *
+ * Gets the session media for @path, increasing its reference count. @matched
+ * will contain the number of matched characters of @path.
+ *
+ * Returns: (transfer full) (nullable): the configuration for @path in @sess,
+ * should be unreferenced when no longer needed.
+ *
+ * Since: 1.20
+ */
+GstRTSPSessionMedia *
+gst_rtsp_session_dup_media (GstRTSPSession * sess, const gchar * path,
+    gint * matched)
+{
+  return _gst_rtsp_session_get_media (sess, path, matched, TRUE);
+}
+
+/**
  * gst_rtsp_session_filter:
  * @sess: a #GstRTSPSession
  * @func: (scope call) (allow-none): a callback