rtsp: refactor configuration of transport
[platform/upstream/gstreamer.git] / gst / rtsp-server / rtsp-stream-transport.c
1 /* GStreamer
2  * Copyright (C) 2008 Wim Taymans <wim.taymans at gmail.com>
3  *
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.
8  *
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.
13  *
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., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <string.h>
21 #include <stdlib.h>
22
23 #include <gst/app/gstappsrc.h>
24 #include <gst/app/gstappsink.h>
25
26 #include "rtsp-stream-transport.h"
27
28 enum
29 {
30   PROP_0,
31   PROP_LAST
32 };
33
34 GST_DEBUG_CATEGORY_STATIC (rtsp_stream_transport_debug);
35 #define GST_CAT_DEFAULT rtsp_stream_transport_debug
36
37 static void gst_rtsp_stream_transport_finalize (GObject * obj);
38
39 G_DEFINE_TYPE (GstRTSPStreamTransport, gst_rtsp_stream_transport,
40     G_TYPE_OBJECT);
41
42 static void
43 gst_rtsp_stream_transport_class_init (GstRTSPStreamTransportClass * klass)
44 {
45   GObjectClass *gobject_class;
46
47   gobject_class = G_OBJECT_CLASS (klass);
48
49   gobject_class->finalize = gst_rtsp_stream_transport_finalize;
50
51   GST_DEBUG_CATEGORY_INIT (rtsp_stream_transport_debug, "rtspmediatransport",
52       0, "GstRTSPStreamTransport");
53 }
54
55 static void
56 gst_rtsp_stream_transport_init (GstRTSPStreamTransport * trans)
57 {
58 }
59
60 static void
61 gst_rtsp_stream_transport_finalize (GObject * obj)
62 {
63   GstRTSPStreamTransport *trans;
64
65   trans = GST_RTSP_STREAM_TRANSPORT (obj);
66
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);
70
71   if (trans->transport)
72     gst_rtsp_transport_free (trans->transport);
73
74 #if 0
75   if (trans->rtpsource)
76     g_object_set_qdata (trans->rtpsource, ssrc_stream_map_key, NULL);
77 #endif
78
79   G_OBJECT_CLASS (gst_rtsp_stream_transport_parent_class)->finalize (obj);
80 }
81
82 /**
83  * gst_rtsp_stream_transport_new:
84  * @stream: a #GstRTSPStream
85  *
86  * Create a new #GstRTSPStreamTransport that can be used to manage
87  * @stream.
88  *
89  * Returns: a new #GstRTSPStreamTransport
90  */
91 GstRTSPStreamTransport *
92 gst_rtsp_stream_transport_new (GstRTSPStream * stream)
93 {
94   GstRTSPStreamTransport *trans;
95
96   g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
97
98   trans = g_object_new (GST_TYPE_RTSP_STREAM_TRANSPORT, NULL);
99   trans->stream = stream;
100
101   return trans;
102 }
103
104 /**
105  * gst_rtsp_stream_transport_set_callbacks:
106  * @trans: a #GstRTSPStreamTransport
107  * @send_rtp: (scope notified): a callback called when RTP should be sent
108  * @send_rtcp: (scope notified): a callback called when RTCP should be sent
109  * @user_data: user data passed to callbacks
110  * @notify: called with the user_data when no longer needed.
111  *
112  * Install callbacks that will be called when data for a stream should be sent
113  * to a client. This is usually used when sending RTP/RTCP over TCP.
114  */
115 void
116 gst_rtsp_stream_transport_set_callbacks (GstRTSPStreamTransport * trans,
117     GstRTSPSendFunc send_rtp, GstRTSPSendFunc send_rtcp,
118     gpointer user_data, GDestroyNotify notify)
119 {
120   trans->send_rtp = send_rtp;
121   trans->send_rtcp = send_rtcp;
122   if (trans->notify)
123     trans->notify (trans->user_data);
124   trans->user_data = user_data;
125   trans->notify = notify;
126 }
127
128 /**
129  * gst_rtsp_stream_transport_set_keepalive:
130  * @trans: a #GstRTSPStreamTransport
131  * @keep_alive: a callback called when the receiver is active
132  * @user_data: user data passed to callback
133  * @notify: called with the user_data when no longer needed.
134  *
135  * Install callbacks that will be called when RTCP packets are received from the
136  * receiver of @trans.
137  */
138 void
139 gst_rtsp_stream_transport_set_keepalive (GstRTSPStreamTransport * trans,
140     GstRTSPKeepAliveFunc keep_alive, gpointer user_data, GDestroyNotify notify)
141 {
142   trans->keep_alive = keep_alive;
143   if (trans->ka_notify)
144     trans->ka_notify (trans->ka_user_data);
145   trans->ka_user_data = user_data;
146   trans->ka_notify = notify;
147 }
148
149
150 /**
151  * gst_rtsp_stream_transport_set_transport:
152  * @trans: a #GstRTSPStreamTransport
153  * @ct: a client #GstRTSPTransport
154  *
155  * Set @ct as the client transport. This function takes ownership of
156  * the passed @ct.
157  */
158 void
159 gst_rtsp_stream_transport_set_transport (GstRTSPStreamTransport * trans,
160     GstRTSPTransport * ct)
161 {
162   g_return_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans));
163   g_return_if_fail (ct != NULL);
164
165   /* keep track of the transports in the stream. */
166   if (trans->transport)
167     gst_rtsp_transport_free (trans->transport);
168   trans->transport = ct;
169 }