2 * Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 * SECTION:rtsp-stream-transport
21 * @short_description: A media stream transport configuration
22 * @see_also: #GstRTSPStream, #GstRTSPSessionMedia
24 * The #GstRTSPStreamTransport configures the transport used by a
25 * #GstRTSPStream. It is usually manages by a #GstRTSPSessionMedia object.
27 * With gst_rtsp_stream_transport_set_callbacks(), callbacks can be configured
28 * to handle the RTP and RTCP packets from the stream, for example when they
29 * need to be sent over TCP.
31 * With gst_rtsp_stream_transport_set_active() the transports are added and
32 * removed from the stream.
34 * A #GstRTSPStream will call gst_rtsp_stream_transport_keep_alive() when RTCP
35 * is received from the client. It will also call
36 * gst_rtsp_stream_transport_set_timed_out() when a receiver has timed out.
38 * Last reviewed on 2013-07-16 (1.0.0)
44 #include "rtsp-stream-transport.h"
46 #define GST_RTSP_STREAM_TRANSPORT_GET_PRIVATE(obj) \
47 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTSP_STREAM_TRANSPORT, GstRTSPStreamTransportPrivate))
49 struct _GstRTSPStreamTransportPrivate
51 GstRTSPStream *stream;
53 GstRTSPSendFunc send_rtp;
54 GstRTSPSendFunc send_rtcp;
56 GDestroyNotify notify;
58 GstRTSPKeepAliveFunc keep_alive;
59 gpointer ka_user_data;
60 GDestroyNotify ka_notify;
64 GstRTSPTransport *transport;
75 GST_DEBUG_CATEGORY_STATIC (rtsp_stream_transport_debug);
76 #define GST_CAT_DEFAULT rtsp_stream_transport_debug
78 static void gst_rtsp_stream_transport_finalize (GObject * obj);
80 G_DEFINE_TYPE (GstRTSPStreamTransport, gst_rtsp_stream_transport,
84 gst_rtsp_stream_transport_class_init (GstRTSPStreamTransportClass * klass)
86 GObjectClass *gobject_class;
88 g_type_class_add_private (klass, sizeof (GstRTSPStreamTransportPrivate));
90 gobject_class = G_OBJECT_CLASS (klass);
92 gobject_class->finalize = gst_rtsp_stream_transport_finalize;
94 GST_DEBUG_CATEGORY_INIT (rtsp_stream_transport_debug, "rtspmediatransport",
95 0, "GstRTSPStreamTransport");
99 gst_rtsp_stream_transport_init (GstRTSPStreamTransport * trans)
101 GstRTSPStreamTransportPrivate *priv =
102 GST_RTSP_STREAM_TRANSPORT_GET_PRIVATE (trans);
108 gst_rtsp_stream_transport_finalize (GObject * obj)
110 GstRTSPStreamTransportPrivate *priv;
111 GstRTSPStreamTransport *trans;
113 trans = GST_RTSP_STREAM_TRANSPORT (obj);
116 /* remove callbacks now */
117 gst_rtsp_stream_transport_set_callbacks (trans, NULL, NULL, NULL, NULL);
118 gst_rtsp_stream_transport_set_keepalive (trans, NULL, NULL, NULL);
121 gst_rtsp_transport_free (priv->transport);
123 G_OBJECT_CLASS (gst_rtsp_stream_transport_parent_class)->finalize (obj);
127 * gst_rtsp_stream_transport_new:
128 * @stream: a #GstRTSPStream
129 * @tr: (transfer full): a GstRTSPTransport
131 * Create a new #GstRTSPStreamTransport that can be used to manage
132 * @stream with transport @tr.
134 * Returns: a new #GstRTSPStreamTransport
136 GstRTSPStreamTransport *
137 gst_rtsp_stream_transport_new (GstRTSPStream * stream, GstRTSPTransport * tr)
139 GstRTSPStreamTransportPrivate *priv;
140 GstRTSPStreamTransport *trans;
142 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
143 g_return_val_if_fail (tr != NULL, NULL);
145 trans = g_object_new (GST_TYPE_RTSP_STREAM_TRANSPORT, NULL);
147 priv->stream = stream;
148 priv->transport = tr;
154 * gst_rtsp_stream_transport_get_stream:
155 * @trans: a #GstRTSPStreamTransport
157 * Get the #GstRTSPStream used when constructing @trans.
159 * Returns: (transfer none): the stream used when constructing @trans.
162 gst_rtsp_stream_transport_get_stream (GstRTSPStreamTransport * trans)
164 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), NULL);
166 return trans->priv->stream;
170 * gst_rtsp_stream_transport_set_callbacks:
171 * @trans: a #GstRTSPStreamTransport
172 * @send_rtp: (scope notified): a callback called when RTP should be sent
173 * @send_rtcp: (scope notified): a callback called when RTCP should be sent
174 * @user_data: user data passed to callbacks
175 * @notify: called with the user_data when no longer needed.
177 * Install callbacks that will be called when data for a stream should be sent
178 * to a client. This is usually used when sending RTP/RTCP over TCP.
181 gst_rtsp_stream_transport_set_callbacks (GstRTSPStreamTransport * trans,
182 GstRTSPSendFunc send_rtp, GstRTSPSendFunc send_rtcp,
183 gpointer user_data, GDestroyNotify notify)
185 GstRTSPStreamTransportPrivate *priv;
187 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
191 priv->send_rtp = send_rtp;
192 priv->send_rtcp = send_rtcp;
194 priv->notify (priv->user_data);
195 priv->user_data = user_data;
196 priv->notify = notify;
200 * gst_rtsp_stream_transport_set_keepalive:
201 * @trans: a #GstRTSPStreamTransport
202 * @keep_alive: a callback called when the receiver is active
203 * @user_data: user data passed to callback
204 * @notify: called with the user_data when no longer needed.
206 * Install callbacks that will be called when RTCP packets are received from the
207 * receiver of @trans.
210 gst_rtsp_stream_transport_set_keepalive (GstRTSPStreamTransport * trans,
211 GstRTSPKeepAliveFunc keep_alive, gpointer user_data, GDestroyNotify notify)
213 GstRTSPStreamTransportPrivate *priv;
215 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
219 priv->keep_alive = keep_alive;
221 priv->ka_notify (priv->ka_user_data);
222 priv->ka_user_data = user_data;
223 priv->ka_notify = notify;
228 * gst_rtsp_stream_transport_set_transport:
229 * @trans: a #GstRTSPStreamTransport
230 * @tr: (transfer full): a client #GstRTSPTransport
232 * Set @tr as the client transport. This function takes ownership of the
236 gst_rtsp_stream_transport_set_transport (GstRTSPStreamTransport * trans,
237 GstRTSPTransport * tr)
239 GstRTSPStreamTransportPrivate *priv;
241 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
242 g_return_if_fail (tr != NULL);
246 /* keep track of the transports in the stream. */
248 gst_rtsp_transport_free (priv->transport);
249 priv->transport = tr;
253 * gst_rtsp_stream_transport_get_transport:
254 * @trans: a #GstRTSPStreamTransport
256 * Get the transport configured in @trans.
258 * Returns: (transfer none): the transport configured in @trans. It remains
259 * valid for as long as @trans is valid.
261 const GstRTSPTransport *
262 gst_rtsp_stream_transport_get_transport (GstRTSPStreamTransport * trans)
264 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), NULL);
266 return trans->priv->transport;
270 * gst_rtsp_stream_transport_set_active:
271 * @trans: a #GstRTSPStreamTransport
272 * @active: new state of @trans
274 * Activate or deactivate datatransfer configured in @trans.
276 * Returns: %TRUE when the state was changed.
279 gst_rtsp_stream_transport_set_active (GstRTSPStreamTransport * trans,
282 GstRTSPStreamTransportPrivate *priv;
285 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
289 if (priv->active == active)
293 res = gst_rtsp_stream_add_transport (priv->stream, trans);
295 res = gst_rtsp_stream_remove_transport (priv->stream, trans);
298 priv->active = active;
304 * gst_rtsp_stream_transport_set_timed_out:
305 * @trans: a #GstRTSPStreamTransport
306 * @timedout: timed out value
308 * Set the timed out state of @trans to @timedout
311 gst_rtsp_stream_transport_set_timed_out (GstRTSPStreamTransport * trans,
314 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
316 trans->priv->timed_out = timedout;
320 * gst_rtsp_stream_transport_is_timed_out:
321 * @trans: a #GstRTSPStreamTransport
323 * Check if @trans is timed out.
325 * Returns: %TRUE if @trans timed out.
328 gst_rtsp_stream_transport_is_timed_out (GstRTSPStreamTransport * trans)
330 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
332 return trans->priv->timed_out;
336 * gst_rtsp_stream_transport_send_rtp:
337 * @trans: a #GstRTSPStreamTransport
338 * @buffer: a #GstBuffer
340 * Send @buffer to the installed RTP callback for @trans.
342 * Returns: %TRUE on success
345 gst_rtsp_stream_transport_send_rtp (GstRTSPStreamTransport * trans,
348 GstRTSPStreamTransportPrivate *priv;
349 gboolean res = FALSE;
355 priv->send_rtp (buffer, priv->transport->interleaved.min,
362 * gst_rtsp_stream_transport_send_rtcp:
363 * @trans: a #GstRTSPStreamTransport
364 * @buffer: a #GstBuffer
366 * Send @buffer to the installed RTCP callback for @trans.
368 * Returns: %TRUE on success
371 gst_rtsp_stream_transport_send_rtcp (GstRTSPStreamTransport * trans,
374 GstRTSPStreamTransportPrivate *priv;
375 gboolean res = FALSE;
381 priv->send_rtcp (buffer, priv->transport->interleaved.max,
388 * gst_rtsp_stream_transport_keep_alive:
389 * @trans: a #GstRTSPStreamTransport
391 * Signal the installed keep_alive callback for @trans.
394 gst_rtsp_stream_transport_keep_alive (GstRTSPStreamTransport * trans)
396 GstRTSPStreamTransportPrivate *priv;
400 if (priv->keep_alive)
401 priv->keep_alive (priv->ka_user_data);