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);
104 g_object_set_qdata (priv->rtpsource, ssrc_stream_map_key, NULL);
107 G_OBJECT_CLASS (gst_rtsp_stream_transport_parent_class)->finalize (obj);
111 * gst_rtsp_stream_transport_new:
112 * @stream: a #GstRTSPStream
113 * @tr: (transfer full): a GstRTSPTransport
115 * Create a new #GstRTSPStreamTransport that can be used to manage
116 * @stream with transport @tr.
118 * Returns: a new #GstRTSPStreamTransport
120 GstRTSPStreamTransport *
121 gst_rtsp_stream_transport_new (GstRTSPStream * stream, GstRTSPTransport * tr)
123 GstRTSPStreamTransportPrivate *priv;
124 GstRTSPStreamTransport *trans;
126 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
127 g_return_val_if_fail (tr != NULL, NULL);
129 trans = g_object_new (GST_TYPE_RTSP_STREAM_TRANSPORT, NULL);
131 priv->stream = stream;
132 priv->transport = tr;
138 * gst_rtsp_stream_transport_get_stream:
139 * @trans: a #GstRTSPStreamTransport
141 * Get the #GstRTSPStream used when constructing @trans.
143 * Returns: (transfer none): the stream used when constructing @trans.
146 gst_rtsp_stream_transport_get_stream (GstRTSPStreamTransport * trans)
148 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), NULL);
150 return trans->priv->stream;
154 * gst_rtsp_stream_transport_set_callbacks:
155 * @trans: a #GstRTSPStreamTransport
156 * @send_rtp: (scope notified): a callback called when RTP should be sent
157 * @send_rtcp: (scope notified): a callback called when RTCP should be sent
158 * @user_data: user data passed to callbacks
159 * @notify: called with the user_data when no longer needed.
161 * Install callbacks that will be called when data for a stream should be sent
162 * to a client. This is usually used when sending RTP/RTCP over TCP.
165 gst_rtsp_stream_transport_set_callbacks (GstRTSPStreamTransport * trans,
166 GstRTSPSendFunc send_rtp, GstRTSPSendFunc send_rtcp,
167 gpointer user_data, GDestroyNotify notify)
169 GstRTSPStreamTransportPrivate *priv;
171 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
175 priv->send_rtp = send_rtp;
176 priv->send_rtcp = send_rtcp;
178 priv->notify (priv->user_data);
179 priv->user_data = user_data;
180 priv->notify = notify;
184 * gst_rtsp_stream_transport_set_keepalive:
185 * @trans: a #GstRTSPStreamTransport
186 * @keep_alive: a callback called when the receiver is active
187 * @user_data: user data passed to callback
188 * @notify: called with the user_data when no longer needed.
190 * Install callbacks that will be called when RTCP packets are received from the
191 * receiver of @trans.
194 gst_rtsp_stream_transport_set_keepalive (GstRTSPStreamTransport * trans,
195 GstRTSPKeepAliveFunc keep_alive, gpointer user_data, GDestroyNotify notify)
197 GstRTSPStreamTransportPrivate *priv;
199 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
203 priv->keep_alive = keep_alive;
205 priv->ka_notify (priv->ka_user_data);
206 priv->ka_user_data = user_data;
207 priv->ka_notify = notify;
212 * gst_rtsp_stream_transport_set_transport:
213 * @trans: a #GstRTSPStreamTransport
214 * @tr: (transfer full): a client #GstRTSPTransport
216 * Set @tr as the client transport. This function takes ownership of the
220 gst_rtsp_stream_transport_set_transport (GstRTSPStreamTransport * trans,
221 GstRTSPTransport * tr)
223 GstRTSPStreamTransportPrivate *priv;
225 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
226 g_return_if_fail (tr != NULL);
230 /* keep track of the transports in the stream. */
232 gst_rtsp_transport_free (priv->transport);
233 priv->transport = tr;
237 * gst_rtsp_stream_transport_get_transport:
238 * @trans: a #GstRTSPStreamTransport
240 * Get the transport configured in @trans.
242 * Returns: (transfer none): the transport configured in @trans. It remains
243 * valid for as long as @trans is valid.
245 const GstRTSPTransport *
246 gst_rtsp_stream_transport_get_transport (GstRTSPStreamTransport * trans)
248 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), NULL);
250 return trans->priv->transport;
254 * gst_rtsp_stream_transport_set_active:
255 * @trans: a #GstRTSPStreamTransport
256 * @active: new state of @trans
258 * Activate or deactivate datatransfer configured in @trans.
260 * Returns: %TRUE when the state was changed.
263 gst_rtsp_stream_transport_set_active (GstRTSPStreamTransport * trans,
266 GstRTSPStreamTransportPrivate *priv;
269 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
273 if (priv->active == active)
277 res = gst_rtsp_stream_add_transport (priv->stream, trans);
279 res = gst_rtsp_stream_remove_transport (priv->stream, trans);
282 priv->active = active;
288 * gst_rtsp_stream_transport_set_timed_out:
289 * @trans: a #GstRTSPStreamTransport
290 * @timedout: timed out value
292 * Set the timed out state of @trans to @timedout
295 gst_rtsp_stream_transport_set_timed_out (GstRTSPStreamTransport * trans,
298 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
300 trans->priv->timed_out = timedout;
304 * gst_rtsp_stream_transport_is_timed_out:
305 * @trans: a #GstRTSPStreamTransport
307 * Check if @trans is timed out.
309 * Returns: %TRUE if @trans timed out.
312 gst_rtsp_stream_transport_is_timed_out (GstRTSPStreamTransport * trans)
314 g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), FALSE);
316 return trans->priv->timed_out;
320 * gst_rtsp_stream_transport_send_rtp:
321 * @trans: a #GstRTSPStreamTransport
322 * @buffer: a #GstBuffer
324 * Send @buffer to the installed RTP callback for @trans.
326 * Returns: %TRUE on success
329 gst_rtsp_stream_transport_send_rtp (GstRTSPStreamTransport * trans,
332 GstRTSPStreamTransportPrivate *priv;
333 gboolean res = FALSE;
339 priv->send_rtp (buffer, priv->transport->interleaved.min,
346 * gst_rtsp_stream_transport_send_rtcp:
347 * @trans: a #GstRTSPStreamTransport
348 * @buffer: a #GstBuffer
350 * Send @buffer to the installed RTCP callback for @trans.
352 * Returns: %TRUE on success
355 gst_rtsp_stream_transport_send_rtcp (GstRTSPStreamTransport * trans,
358 GstRTSPStreamTransportPrivate *priv;
359 gboolean res = FALSE;
365 priv->send_rtcp (buffer, priv->transport->interleaved.max,
372 * gst_rtsp_stream_transport_keep_alive:
373 * @trans: a #GstRTSPStreamTransport
375 * Signal the installed keep_alive callback for @trans.
378 gst_rtsp_stream_transport_keep_alive (GstRTSPStreamTransport * trans)
380 GstRTSPStreamTransportPrivate *priv;
384 if (priv->keep_alive)
385 priv->keep_alive (priv->ka_user_data);