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.
23 #include "rtsp-stream-transport.h"
25 #define GST_RTSP_STREAM_TRANSPORT_GET_PRIVATE(obj) \
26 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTSP_STREAM_TRANSPORT, GstRTSPStreamTransportPrivate))
28 struct _GstRTSPStreamTransportPrivate
30 GstRTSPStream *stream;
32 GstRTSPSendFunc send_rtp;
33 GstRTSPSendFunc send_rtcp;
35 GDestroyNotify notify;
37 GstRTSPKeepAliveFunc keep_alive;
38 gpointer ka_user_data;
39 GDestroyNotify ka_notify;
43 GstRTSPTransport *transport;
54 GST_DEBUG_CATEGORY_STATIC (rtsp_stream_transport_debug);
55 #define GST_CAT_DEFAULT rtsp_stream_transport_debug
57 static void gst_rtsp_stream_transport_finalize (GObject * obj);
59 G_DEFINE_TYPE (GstRTSPStreamTransport, gst_rtsp_stream_transport,
63 gst_rtsp_stream_transport_class_init (GstRTSPStreamTransportClass * klass)
65 GObjectClass *gobject_class;
67 g_type_class_add_private (klass, sizeof (GstRTSPStreamTransportPrivate));
69 gobject_class = G_OBJECT_CLASS (klass);
71 gobject_class->finalize = gst_rtsp_stream_transport_finalize;
73 GST_DEBUG_CATEGORY_INIT (rtsp_stream_transport_debug, "rtspmediatransport",
74 0, "GstRTSPStreamTransport");
78 gst_rtsp_stream_transport_init (GstRTSPStreamTransport * trans)
80 GstRTSPStreamTransportPrivate *priv =
81 GST_RTSP_STREAM_TRANSPORT_GET_PRIVATE (trans);
87 gst_rtsp_stream_transport_finalize (GObject * obj)
89 GstRTSPStreamTransportPrivate *priv;
90 GstRTSPStreamTransport *trans;
92 trans = GST_RTSP_STREAM_TRANSPORT (obj);
95 /* remove callbacks now */
96 gst_rtsp_stream_transport_set_callbacks (trans, NULL, NULL, NULL, NULL);
97 gst_rtsp_stream_transport_set_keepalive (trans, NULL, NULL, NULL);
100 gst_rtsp_transport_free (priv->transport);
102 G_OBJECT_CLASS (gst_rtsp_stream_transport_parent_class)->finalize (obj);
106 * gst_rtsp_stream_transport_new:
107 * @stream: a #GstRTSPStream
108 * @tr: (transfer full): a GstRTSPTransport
110 * Create a new #GstRTSPStreamTransport that can be used to manage
111 * @stream with transport @tr.
113 * Returns: a new #GstRTSPStreamTransport
115 GstRTSPStreamTransport *
116 gst_rtsp_stream_transport_new (GstRTSPStream * stream, GstRTSPTransport * tr)
118 GstRTSPStreamTransportPrivate *priv;
119 GstRTSPStreamTransport *trans;
121 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
122 g_return_val_if_fail (tr != NULL, NULL);
124 trans = g_object_new (GST_TYPE_RTSP_STREAM_TRANSPORT, NULL);
126 priv->stream = stream;
127 priv->transport = tr;
133 * gst_rtsp_stream_transport_get_stream:
134 * @trans: a #GstRTSPStreamTransport
136 * Get the #GstRTSPStream used when constructing @trans.
138 * Returns: (transfer none): the stream used when constructing @trans.
141 gst_rtsp_stream_transport_get_stream (GstRTSPStreamTransport * trans)
143 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), NULL);
145 return trans->priv->stream;
149 * gst_rtsp_stream_transport_set_callbacks:
150 * @trans: a #GstRTSPStreamTransport
151 * @send_rtp: (scope notified): a callback called when RTP should be sent
152 * @send_rtcp: (scope notified): a callback called when RTCP should be sent
153 * @user_data: user data passed to callbacks
154 * @notify: called with the user_data when no longer needed.
156 * Install callbacks that will be called when data for a stream should be sent
157 * to a client. This is usually used when sending RTP/RTCP over TCP.
160 gst_rtsp_stream_transport_set_callbacks (GstRTSPStreamTransport * trans,
161 GstRTSPSendFunc send_rtp, GstRTSPSendFunc send_rtcp,
162 gpointer user_data, GDestroyNotify notify)
164 GstRTSPStreamTransportPrivate *priv;
166 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
170 priv->send_rtp = send_rtp;
171 priv->send_rtcp = send_rtcp;
173 priv->notify (priv->user_data);
174 priv->user_data = user_data;
175 priv->notify = notify;
179 * gst_rtsp_stream_transport_set_keepalive:
180 * @trans: a #GstRTSPStreamTransport
181 * @keep_alive: a callback called when the receiver is active
182 * @user_data: user data passed to callback
183 * @notify: called with the user_data when no longer needed.
185 * Install callbacks that will be called when RTCP packets are received from the
186 * receiver of @trans.
189 gst_rtsp_stream_transport_set_keepalive (GstRTSPStreamTransport * trans,
190 GstRTSPKeepAliveFunc keep_alive, gpointer user_data, GDestroyNotify notify)
192 GstRTSPStreamTransportPrivate *priv;
194 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
198 priv->keep_alive = keep_alive;
200 priv->ka_notify (priv->ka_user_data);
201 priv->ka_user_data = user_data;
202 priv->ka_notify = notify;
207 * gst_rtsp_stream_transport_set_transport:
208 * @trans: a #GstRTSPStreamTransport
209 * @tr: (transfer full): a client #GstRTSPTransport
211 * Set @tr as the client transport. This function takes ownership of the
215 gst_rtsp_stream_transport_set_transport (GstRTSPStreamTransport * trans,
216 GstRTSPTransport * tr)
218 GstRTSPStreamTransportPrivate *priv;
220 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
221 g_return_if_fail (tr != NULL);
225 /* keep track of the transports in the stream. */
227 gst_rtsp_transport_free (priv->transport);
228 priv->transport = tr;
232 * gst_rtsp_stream_transport_get_transport:
233 * @trans: a #GstRTSPStreamTransport
235 * Get the transport configured in @trans.
237 * Returns: (transfer none): the transport configured in @trans. It remains
238 * valid for as long as @trans is valid.
240 const GstRTSPTransport *
241 gst_rtsp_stream_transport_get_transport (GstRTSPStreamTransport * trans)
243 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), NULL);
245 return trans->priv->transport;
249 * gst_rtsp_stream_transport_set_active:
250 * @trans: a #GstRTSPStreamTransport
251 * @active: new state of @trans
253 * Activate or deactivate datatransfer configured in @trans.
255 * Returns: %TRUE when the state was changed.
258 gst_rtsp_stream_transport_set_active (GstRTSPStreamTransport * trans,
261 GstRTSPStreamTransportPrivate *priv;
264 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
268 if (priv->active == active)
272 res = gst_rtsp_stream_add_transport (priv->stream, trans);
274 res = gst_rtsp_stream_remove_transport (priv->stream, trans);
277 priv->active = active;
283 * gst_rtsp_stream_transport_set_timed_out:
284 * @trans: a #GstRTSPStreamTransport
285 * @timedout: timed out value
287 * Set the timed out state of @trans to @timedout
290 gst_rtsp_stream_transport_set_timed_out (GstRTSPStreamTransport * trans,
293 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
295 trans->priv->timed_out = timedout;
299 * gst_rtsp_stream_transport_is_timed_out:
300 * @trans: a #GstRTSPStreamTransport
302 * Check if @trans is timed out.
304 * Returns: %TRUE if @trans timed out.
307 gst_rtsp_stream_transport_is_timed_out (GstRTSPStreamTransport * trans)
309 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
311 return trans->priv->timed_out;
315 * gst_rtsp_stream_transport_send_rtp:
316 * @trans: a #GstRTSPStreamTransport
317 * @buffer: a #GstBuffer
319 * Send @buffer to the installed RTP callback for @trans.
321 * Returns: %TRUE on success
324 gst_rtsp_stream_transport_send_rtp (GstRTSPStreamTransport * trans,
327 GstRTSPStreamTransportPrivate *priv;
328 gboolean res = FALSE;
334 priv->send_rtp (buffer, priv->transport->interleaved.min,
341 * gst_rtsp_stream_transport_send_rtcp:
342 * @trans: a #GstRTSPStreamTransport
343 * @buffer: a #GstBuffer
345 * Send @buffer to the installed RTCP callback for @trans.
347 * Returns: %TRUE on success
350 gst_rtsp_stream_transport_send_rtcp (GstRTSPStreamTransport * trans,
353 GstRTSPStreamTransportPrivate *priv;
354 gboolean res = FALSE;
360 priv->send_rtcp (buffer, priv->transport->interleaved.max,
367 * gst_rtsp_stream_transport_keep_alive:
368 * @trans: a #GstRTSPStreamTransport
370 * Signal the installed keep_alive callback for @trans.
373 gst_rtsp_stream_transport_keep_alive (GstRTSPStreamTransport * trans)
375 GstRTSPStreamTransportPrivate *priv;
379 if (priv->keep_alive)
380 priv->keep_alive (priv->ka_user_data);