rtsp-stream-transport: Fix accidental API/ABI breakage with message_sent callbacks
authorSebastian Dröge <sebastian@centricular.com>
Fri, 1 May 2020 07:42:17 +0000 (10:42 +0300)
committerSebastian Dröge <sebastian@centricular.com>
Fri, 1 May 2020 07:45:45 +0000 (10:45 +0300)
The old API is preserved now and new API was added that provides the
additional parameter to the callback.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/issues/104

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/-/merge_requests/116>

gst/rtsp-server/rtsp-stream-transport.c
gst/rtsp-server/rtsp-stream-transport.h
gst/rtsp-server/rtsp-stream.c

index ac0e257..d293a95 100644 (file)
@@ -77,6 +77,10 @@ struct _GstRTSPStreamTransportPrivate
   gpointer ms_user_data;
   GDestroyNotify ms_notify;
 
+  GstRTSPMessageSentFuncFull message_sent_full;
+  gpointer msf_user_data;
+  GDestroyNotify msf_notify;
+
   GstRTSPTransport *transport;
   GstRTSPUrl *url;
 
@@ -373,6 +377,34 @@ gst_rtsp_stream_transport_set_message_sent (GstRTSPStreamTransport * trans,
   priv->ms_notify = notify;
 }
 
+/**
+ * gst_rtsp_stream_transport_set_message_sent_full:
+ * @trans: a #GstRTSPStreamTransport
+ * @message_sent: (scope notified): a callback called when a message has been sent
+ * @user_data: (closure): user data passed to callback
+ * @notify: (allow-none): called with the user_data when no longer needed
+ *
+ * Install a callback that will be called when a message has been sent on @trans.
+ *
+ * Since: 1.18
+ */
+void
+gst_rtsp_stream_transport_set_message_sent_full (GstRTSPStreamTransport * trans,
+    GstRTSPMessageSentFuncFull message_sent, gpointer user_data,
+    GDestroyNotify notify)
+{
+  GstRTSPStreamTransportPrivate *priv;
+
+  g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
+
+  priv = trans->priv;
+
+  priv->message_sent_full = message_sent;
+  if (priv->msf_notify)
+    priv->msf_notify (priv->msf_user_data);
+  priv->msf_user_data = user_data;
+  priv->msf_notify = notify;
+}
 
 /**
  * gst_rtsp_stream_transport_set_transport:
@@ -750,7 +782,7 @@ gst_rtsp_stream_transport_keep_alive (GstRTSPStreamTransport * trans)
  * gst_rtsp_stream_transport_message_sent:
  * @trans: a #GstRTSPStreamTransport
  *
- * Signal the installed message_sent callback for @trans.
+ * Signal the installed message_sent / message_sent_full callback for @trans.
  *
  * Since: 1.16
  */
@@ -761,8 +793,10 @@ gst_rtsp_stream_transport_message_sent (GstRTSPStreamTransport * trans)
 
   priv = trans->priv;
 
+  if (priv->message_sent_full)
+    priv->message_sent_full (trans, priv->msf_user_data);
   if (priv->message_sent)
-    priv->message_sent (trans, priv->ms_user_data);
+    priv->message_sent (priv->ms_user_data);
 }
 
 /**
index f878858..d8516c0 100644 (file)
@@ -89,7 +89,18 @@ typedef void     (*GstRTSPKeepAliveFunc) (gpointer user_data);
  * Function registered with gst_rtsp_stream_transport_set_message_sent()
  * and called when a message has been sent on the transport.
  */
-typedef void     (*GstRTSPMessageSentFunc) (GstRTSPStreamTransport *trans, gpointer user_data);
+typedef void     (*GstRTSPMessageSentFunc) (gpointer user_data);
+
+/**
+ * GstRTSPMessageSentFuncFull:
+ * @user_data: user data
+ *
+ * Function registered with gst_rtsp_stream_transport_set_message_sent_full()
+ * and called when a message has been sent on the transport.
+ *
+ * Since: 1.18
+ */
+typedef void     (*GstRTSPMessageSentFuncFull) (GstRTSPStreamTransport *trans, gpointer user_data);
 
 /**
  * GstRTSPStreamTransport:
@@ -163,11 +174,16 @@ void                     gst_rtsp_stream_transport_set_keepalive (GstRTSPStreamT
 
 GST_RTSP_SERVER_API
 void                     gst_rtsp_stream_transport_set_message_sent (GstRTSPStreamTransport *trans,
-                                                                  GstRTSPMessageSentFunc message_sent,
-                                                                  gpointer user_data,
-                                                                  GDestroyNotify  notify);
+                                                                     GstRTSPMessageSentFunc message_sent,
+                                                                     gpointer user_data,
+                                                                     GDestroyNotify  notify);
 
 GST_RTSP_SERVER_API
+void                     gst_rtsp_stream_transport_set_message_sent_full (GstRTSPStreamTransport *trans,
+                                                                          GstRTSPMessageSentFuncFull message_sent,
+                                                                          gpointer user_data,
+                                                                          GDestroyNotify  notify);
+GST_RTSP_SERVER_API
 void                     gst_rtsp_stream_transport_keep_alive    (GstRTSPStreamTransport *trans);
 
 GST_RTSP_SERVER_API
index aabb3b0..4114980 100644 (file)
@@ -4685,8 +4685,8 @@ gst_rtsp_stream_add_transport (GstRTSPStream * stream,
   g_mutex_lock (&priv->lock);
   res = update_transport (stream, trans, TRUE);
   if (res)
-    gst_rtsp_stream_transport_set_message_sent (trans, on_message_sent, stream,
-        NULL);
+    gst_rtsp_stream_transport_set_message_sent_full (trans, on_message_sent,
+        stream, NULL);
   g_mutex_unlock (&priv->lock);
 
   return res;