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 <gst/app/gstappsrc.h>
24 #include <gst/app/gstappsink.h>
26 #include "rtsp-stream-transport.h"
34 GST_DEBUG_CATEGORY_STATIC (rtsp_stream_transport_debug);
35 #define GST_CAT_DEFAULT rtsp_stream_transport_debug
37 static void gst_rtsp_stream_transport_finalize (GObject * obj);
39 G_DEFINE_TYPE (GstRTSPStreamTransport, gst_rtsp_stream_transport,
43 gst_rtsp_stream_transport_class_init (GstRTSPStreamTransportClass * klass)
45 GObjectClass *gobject_class;
47 gobject_class = G_OBJECT_CLASS (klass);
49 gobject_class->finalize = gst_rtsp_stream_transport_finalize;
51 GST_DEBUG_CATEGORY_INIT (rtsp_stream_transport_debug, "rtspmediatransport",
52 0, "GstRTSPStreamTransport");
56 gst_rtsp_stream_transport_init (GstRTSPStreamTransport * trans)
61 gst_rtsp_stream_transport_finalize (GObject * obj)
63 GstRTSPStreamTransport *trans;
65 trans = GST_RTSP_STREAM_TRANSPORT (obj);
67 /* remove callbacks now */
68 gst_rtsp_stream_transport_set_callbacks (trans, NULL, NULL, NULL, NULL);
69 gst_rtsp_stream_transport_set_keepalive (trans, NULL, NULL, NULL);
72 gst_rtsp_transport_free (trans->transport);
76 g_object_set_qdata (trans->rtpsource, ssrc_stream_map_key, NULL);
79 G_OBJECT_CLASS (gst_rtsp_stream_transport_parent_class)->finalize (obj);
83 * gst_rtsp_stream_transport_new:
84 * @stream: a #GstRTSPStream
85 * @tr: (transfer full): a GstRTSPTransport
87 * Create a new #GstRTSPStreamTransport that can be used to manage
88 * @stream with transport @tr.
90 * Returns: a new #GstRTSPStreamTransport
92 GstRTSPStreamTransport *
93 gst_rtsp_stream_transport_new (GstRTSPStream * stream, GstRTSPTransport * tr)
95 GstRTSPStreamTransport *trans;
97 g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
98 g_return_val_if_fail (tr != NULL, NULL);
100 trans = g_object_new (GST_TYPE_RTSP_STREAM_TRANSPORT, NULL);
101 trans->stream = stream;
102 trans->transport = tr;
108 * gst_rtsp_stream_transport_set_callbacks:
109 * @trans: a #GstRTSPStreamTransport
110 * @send_rtp: (scope notified): a callback called when RTP should be sent
111 * @send_rtcp: (scope notified): a callback called when RTCP should be sent
112 * @user_data: user data passed to callbacks
113 * @notify: called with the user_data when no longer needed.
115 * Install callbacks that will be called when data for a stream should be sent
116 * to a client. This is usually used when sending RTP/RTCP over TCP.
119 gst_rtsp_stream_transport_set_callbacks (GstRTSPStreamTransport * trans,
120 GstRTSPSendFunc send_rtp, GstRTSPSendFunc send_rtcp,
121 gpointer user_data, GDestroyNotify notify)
123 trans->send_rtp = send_rtp;
124 trans->send_rtcp = send_rtcp;
126 trans->notify (trans->user_data);
127 trans->user_data = user_data;
128 trans->notify = notify;
132 * gst_rtsp_stream_transport_set_keepalive:
133 * @trans: a #GstRTSPStreamTransport
134 * @keep_alive: a callback called when the receiver is active
135 * @user_data: user data passed to callback
136 * @notify: called with the user_data when no longer needed.
138 * Install callbacks that will be called when RTCP packets are received from the
139 * receiver of @trans.
142 gst_rtsp_stream_transport_set_keepalive (GstRTSPStreamTransport * trans,
143 GstRTSPKeepAliveFunc keep_alive, gpointer user_data, GDestroyNotify notify)
145 trans->keep_alive = keep_alive;
146 if (trans->ka_notify)
147 trans->ka_notify (trans->ka_user_data);
148 trans->ka_user_data = user_data;
149 trans->ka_notify = notify;
154 * gst_rtsp_stream_transport_set_transport:
155 * @trans: a #GstRTSPStreamTransport
156 * @tr: (transfer full): a client #GstRTSPTransport
158 * Set @ct as the client transport. This function takes ownership of
162 gst_rtsp_stream_transport_set_transport (GstRTSPStreamTransport * trans,
163 GstRTSPTransport * tr)
165 g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
166 g_return_if_fail (tr != NULL);
168 /* keep track of the transports in the stream. */
169 if (trans->transport)
170 gst_rtsp_transport_free (trans->transport);
171 trans->transport = tr;
175 * gst_rtsp_stream_transport_send_rtp:
176 * @trans: a #GstRTSPStreamTransport
177 * @buffer: a #GstBuffer
179 * Send @buffer to the installed RTP callback for @trans.
181 * Returns: %TRUE on success
184 gst_rtsp_stream_transport_send_rtp (GstRTSPStreamTransport * trans,
187 gboolean res = FALSE;
191 trans->send_rtp (buffer, trans->transport->interleaved.min,
198 * gst_rtsp_stream_transport_send_rtcp:
199 * @trans: a #GstRTSPStreamTransport
200 * @buffer: a #GstBuffer
202 * Send @buffer to the installed RTCP callback for @trans.
204 * Returns: %TRUE on success
207 gst_rtsp_stream_transport_send_rtcp (GstRTSPStreamTransport * trans,
210 gboolean res = FALSE;
212 if (trans->send_rtcp)
214 trans->send_rtcp (buffer, trans->transport->interleaved.max,