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;
76 GST_DEBUG_CATEGORY_STATIC (rtsp_stream_transport_debug);
77 #define GST_CAT_DEFAULT rtsp_stream_transport_debug
79 static void gst_rtsp_stream_transport_finalize (GObject * obj);
81 G_DEFINE_TYPE (GstRTSPStreamTransport, gst_rtsp_stream_transport,
85 gst_rtsp_stream_transport_class_init (GstRTSPStreamTransportClass * klass)
87 GObjectClass *gobject_class;
89 g_type_class_add_private (klass, sizeof (GstRTSPStreamTransportPrivate));
91 gobject_class = G_OBJECT_CLASS (klass);
93 gobject_class->finalize = gst_rtsp_stream_transport_finalize;
95 GST_DEBUG_CATEGORY_INIT (rtsp_stream_transport_debug, "rtspmediatransport",
96 0, "GstRTSPStreamTransport");
100 gst_rtsp_stream_transport_init (GstRTSPStreamTransport * trans)
102 GstRTSPStreamTransportPrivate *priv =
103 GST_RTSP_STREAM_TRANSPORT_GET_PRIVATE (trans);
109 gst_rtsp_stream_transport_finalize (GObject * obj)
111 GstRTSPStreamTransportPrivate *priv;
112 GstRTSPStreamTransport *trans;
114 trans = GST_RTSP_STREAM_TRANSPORT (obj);
117 /* remove callbacks now */
118 gst_rtsp_stream_transport_set_callbacks (trans, NULL, NULL, NULL, NULL);
119 gst_rtsp_stream_transport_set_keepalive (trans, NULL, NULL, NULL);
122 gst_rtsp_transport_free (priv->transport);
125 gst_rtsp_url_free (priv->url);
127 G_OBJECT_CLASS (gst_rtsp_stream_transport_parent_class)->finalize (obj);
131 * gst_rtsp_stream_transport_new:
132 * @stream: a #GstRTSPStream
133 * @tr: (transfer full): a GstRTSPTransport
135 * Create a new #GstRTSPStreamTransport that can be used to manage
136 * @stream with transport @tr.
138 * Returns: a new #GstRTSPStreamTransport
140 GstRTSPStreamTransport *
141 gst_rtsp_stream_transport_new (GstRTSPStream * stream, GstRTSPTransport * tr)
143 GstRTSPStreamTransportPrivate *priv;
144 GstRTSPStreamTransport *trans;
146 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
147 g_return_val_if_fail (tr != NULL, NULL);
149 trans = g_object_new (GST_TYPE_RTSP_STREAM_TRANSPORT, NULL);
151 priv->stream = stream;
152 priv->transport = tr;
158 * gst_rtsp_stream_transport_get_stream:
159 * @trans: a #GstRTSPStreamTransport
161 * Get the #GstRTSPStream used when constructing @trans.
163 * Returns: (transfer none): the stream used when constructing @trans.
166 gst_rtsp_stream_transport_get_stream (GstRTSPStreamTransport * trans)
168 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), NULL);
170 return trans->priv->stream;
174 * gst_rtsp_stream_transport_set_callbacks:
175 * @trans: a #GstRTSPStreamTransport
176 * @send_rtp: (scope notified): a callback called when RTP should be sent
177 * @send_rtcp: (scope notified): a callback called when RTCP should be sent
178 * @user_data: user data passed to callbacks
179 * @notify: called with the user_data when no longer needed.
181 * Install callbacks that will be called when data for a stream should be sent
182 * to a client. This is usually used when sending RTP/RTCP over TCP.
185 gst_rtsp_stream_transport_set_callbacks (GstRTSPStreamTransport * trans,
186 GstRTSPSendFunc send_rtp, GstRTSPSendFunc send_rtcp,
187 gpointer user_data, GDestroyNotify notify)
189 GstRTSPStreamTransportPrivate *priv;
191 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
195 priv->send_rtp = send_rtp;
196 priv->send_rtcp = send_rtcp;
198 priv->notify (priv->user_data);
199 priv->user_data = user_data;
200 priv->notify = notify;
204 * gst_rtsp_stream_transport_set_keepalive:
205 * @trans: a #GstRTSPStreamTransport
206 * @keep_alive: a callback called when the receiver is active
207 * @user_data: user data passed to callback
208 * @notify: called with the user_data when no longer needed.
210 * Install callbacks that will be called when RTCP packets are received from the
211 * receiver of @trans.
214 gst_rtsp_stream_transport_set_keepalive (GstRTSPStreamTransport * trans,
215 GstRTSPKeepAliveFunc keep_alive, gpointer user_data, GDestroyNotify notify)
217 GstRTSPStreamTransportPrivate *priv;
219 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
223 priv->keep_alive = keep_alive;
225 priv->ka_notify (priv->ka_user_data);
226 priv->ka_user_data = user_data;
227 priv->ka_notify = notify;
232 * gst_rtsp_stream_transport_set_transport:
233 * @trans: a #GstRTSPStreamTransport
234 * @tr: (transfer full): a client #GstRTSPTransport
236 * Set @tr as the client transport. This function takes ownership of the
240 gst_rtsp_stream_transport_set_transport (GstRTSPStreamTransport * trans,
241 GstRTSPTransport * tr)
243 GstRTSPStreamTransportPrivate *priv;
245 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
246 g_return_if_fail (tr != NULL);
250 /* keep track of the transports in the stream. */
252 gst_rtsp_transport_free (priv->transport);
253 priv->transport = tr;
257 * gst_rtsp_stream_transport_get_transport:
258 * @trans: a #GstRTSPStreamTransport
260 * Get the transport configured in @trans.
262 * Returns: (transfer none): the transport configured in @trans. It remains
263 * valid for as long as @trans is valid.
265 const GstRTSPTransport *
266 gst_rtsp_stream_transport_get_transport (GstRTSPStreamTransport * trans)
268 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), NULL);
270 return trans->priv->transport;
274 * gst_rtsp_stream_transport_set_url:
275 * @trans: a #GstRTSPStreamTransport
276 * @url: (transfer none): a client #GstRTSPUrl
278 * Set @url as the client url.
281 gst_rtsp_stream_transport_set_url (GstRTSPStreamTransport * trans,
282 const GstRTSPUrl * url)
284 GstRTSPStreamTransportPrivate *priv;
286 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
290 /* keep track of the transports in the stream. */
292 gst_rtsp_url_free (priv->url);
293 priv->url = (url ? gst_rtsp_url_copy (url) : NULL);
297 * gst_rtsp_stream_transport_get_url:
298 * @trans: a #GstRTSPStreamTransport
300 * Get the url configured in @trans.
302 * Returns: (transfer none): the url configured in @trans. It remains
303 * valid for as long as @trans is valid.
306 gst_rtsp_stream_transport_get_url (GstRTSPStreamTransport * trans)
308 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), NULL);
310 return trans->priv->url;
314 * gst_rtsp_stream_transport_get_rtpinfo:
315 * @trans: a #GstRTSPStreamTransport
316 * @start_time: a star time
318 * Get the RTPInfo string for @trans and @start_time.
320 * Returns: the RTPInfo string for @trans and @start_time. g_free() after
324 gst_rtsp_stream_transport_get_rtpinfo (GstRTSPStreamTransport * trans,
325 GstClockTime start_time)
327 GstRTSPStreamTransportPrivate *priv;
332 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), NULL);
336 if (!gst_rtsp_stream_get_rtpinfo (priv->stream, &rtptime, &seq, NULL))
339 rtpinfo = g_string_new ("");
341 url_str = gst_rtsp_url_get_request_uri (trans->priv->url);
342 g_string_append_printf (rtpinfo, "url=%s;seq=%u;rtptime=%u",
343 url_str, seq, rtptime);
346 return g_string_free (rtpinfo, FALSE);
350 * gst_rtsp_stream_transport_set_active:
351 * @trans: a #GstRTSPStreamTransport
352 * @active: new state of @trans
354 * Activate or deactivate datatransfer configured in @trans.
356 * Returns: %TRUE when the state was changed.
359 gst_rtsp_stream_transport_set_active (GstRTSPStreamTransport * trans,
362 GstRTSPStreamTransportPrivate *priv;
365 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
369 if (priv->active == active)
373 res = gst_rtsp_stream_add_transport (priv->stream, trans);
375 res = gst_rtsp_stream_remove_transport (priv->stream, trans);
378 priv->active = active;
384 * gst_rtsp_stream_transport_set_timed_out:
385 * @trans: a #GstRTSPStreamTransport
386 * @timedout: timed out value
388 * Set the timed out state of @trans to @timedout
391 gst_rtsp_stream_transport_set_timed_out (GstRTSPStreamTransport * trans,
394 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
396 trans->priv->timed_out = timedout;
400 * gst_rtsp_stream_transport_is_timed_out:
401 * @trans: a #GstRTSPStreamTransport
403 * Check if @trans is timed out.
405 * Returns: %TRUE if @trans timed out.
408 gst_rtsp_stream_transport_is_timed_out (GstRTSPStreamTransport * trans)
410 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
412 return trans->priv->timed_out;
416 * gst_rtsp_stream_transport_send_rtp:
417 * @trans: a #GstRTSPStreamTransport
418 * @buffer: a #GstBuffer
420 * Send @buffer to the installed RTP callback for @trans.
422 * Returns: %TRUE on success
425 gst_rtsp_stream_transport_send_rtp (GstRTSPStreamTransport * trans,
428 GstRTSPStreamTransportPrivate *priv;
429 gboolean res = FALSE;
435 priv->send_rtp (buffer, priv->transport->interleaved.min,
442 * gst_rtsp_stream_transport_send_rtcp:
443 * @trans: a #GstRTSPStreamTransport
444 * @buffer: a #GstBuffer
446 * Send @buffer to the installed RTCP callback for @trans.
448 * Returns: %TRUE on success
451 gst_rtsp_stream_transport_send_rtcp (GstRTSPStreamTransport * trans,
454 GstRTSPStreamTransportPrivate *priv;
455 gboolean res = FALSE;
461 priv->send_rtcp (buffer, priv->transport->interleaved.max,
468 * gst_rtsp_stream_transport_keep_alive:
469 * @trans: a #GstRTSPStreamTransport
471 * Signal the installed keep_alive callback for @trans.
474 gst_rtsp_stream_transport_keep_alive (GstRTSPStreamTransport * trans)
476 GstRTSPStreamTransportPrivate *priv;
480 if (priv->keep_alive)
481 priv->keep_alive (priv->ka_user_data);