629f098d4855cfb511551f2793673e194d32b984
[platform/upstream/gst-plugins-good.git] / gst / rtpmanager / gstrtpbin.c
1 /* GStreamer
2  * Copyright (C) <2007> Wim Taymans <wim@fluendo.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 /**
21  * SECTION:element-rtpbin
22  * @short_description: handle media from one RTP bin
23  * @see_also: rtpjitterbuffer, rtpclient, rtpsession
24  *
25  * <refsect2>
26  * <para>
27  * </para>
28  * <title>Example pipelines</title>
29  * <para>
30  * <programlisting>
31  * gst-launch -v filesrc location=sine.ogg ! oggdemux ! vorbisdec ! audioconvert ! alsasink
32  * </programlisting>
33  * </para>
34  * </refsect2>
35  *
36  * Last reviewed on 2007-04-02 (0.10.6)
37  */
38
39 #ifdef HAVE_CONFIG_H
40 #include "config.h"
41 #endif
42 #include <string.h>
43
44 #include "gstrtpbin.h"
45
46 /* elementfactory information */
47 static const GstElementDetails rtpbin_details = GST_ELEMENT_DETAILS ("RTP Bin",
48     "Filter/Editor/Video",
49     "Implement an RTP bin",
50     "Wim Taymans <wim@fluendo.com>");
51
52 /* sink pads */
53 static GstStaticPadTemplate rtpbin_recv_rtp_sink_template =
54 GST_STATIC_PAD_TEMPLATE ("recv_rtp_sink_%d",
55     GST_PAD_SINK,
56     GST_PAD_REQUEST,
57     GST_STATIC_CAPS ("application/x-rtp")
58     );
59
60 static GstStaticPadTemplate rtpbin_recv_rtcp_sink_template =
61 GST_STATIC_PAD_TEMPLATE ("recv_rtcp_sink_%d",
62     GST_PAD_SINK,
63     GST_PAD_REQUEST,
64     GST_STATIC_CAPS ("application/x-rtcp")
65     );
66
67 static GstStaticPadTemplate rtpbin_send_rtp_sink_template =
68 GST_STATIC_PAD_TEMPLATE ("send_rtp_sink_%d",
69     GST_PAD_SINK,
70     GST_PAD_REQUEST,
71     GST_STATIC_CAPS ("application/x-rtp")
72     );
73
74 /* src pads */
75 static GstStaticPadTemplate rtpbin_recv_rtp_src_template =
76 GST_STATIC_PAD_TEMPLATE ("recv_rtp_src_%d_%d_%d",
77     GST_PAD_SRC,
78     GST_PAD_SOMETIMES,
79     GST_STATIC_CAPS ("application/x-rtp")
80     );
81
82 static GstStaticPadTemplate rtpbin_send_rtcp_src_template =
83 GST_STATIC_PAD_TEMPLATE ("send_rtcp_src_%d",
84     GST_PAD_SRC,
85     GST_PAD_REQUEST,
86     GST_STATIC_CAPS ("application/x-rtcp")
87     );
88
89 static GstStaticPadTemplate rtpbin_send_rtp_src_template =
90 GST_STATIC_PAD_TEMPLATE ("send_rtp_src_%d",
91     GST_PAD_SRC,
92     GST_PAD_SOMETIMES,
93     GST_STATIC_CAPS ("application/x-rtp")
94     );
95
96 #define GST_RTP_BIN_GET_PRIVATE(obj)  \
97    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTP_BIN, GstRTPBinPrivate))
98
99 struct _GstRTPBinPrivate
100 {
101 };
102
103 /* signals and args */
104 enum
105 {
106   /* FILL ME */
107   LAST_SIGNAL
108 };
109
110 enum
111 {
112   PROP_0
113 };
114
115 /* GObject vmethods */
116 static void gst_rtp_bin_finalize (GObject * object);
117 static void gst_rtp_bin_set_property (GObject * object, guint prop_id,
118     const GValue * value, GParamSpec * pspec);
119 static void gst_rtp_bin_get_property (GObject * object, guint prop_id,
120     GValue * value, GParamSpec * pspec);
121
122 /* GstElement vmethods */
123 static GstStateChangeReturn gst_rtp_bin_change_state (GstElement * element,
124     GstStateChange transition);
125 static GstPad *gst_rtp_bin_request_new_pad (GstElement * element,
126     GstPadTemplate * templ, const gchar * name);
127 static void gst_rtp_bin_release_pad (GstElement * element, GstPad * pad);
128
129 /*static guint gst_rtp_bin_signals[LAST_SIGNAL] = { 0 }; */
130
131 GST_BOILERPLATE (GstRTPBin, gst_rtp_bin, GstBin, GST_TYPE_BIN);
132
133 static void
134 gst_rtp_bin_base_init (gpointer klass)
135 {
136   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
137
138   /* sink pads */
139   gst_element_class_add_pad_template (element_class,
140       gst_static_pad_template_get (&rtpbin_recv_rtp_sink_template));
141   gst_element_class_add_pad_template (element_class,
142       gst_static_pad_template_get (&rtpbin_recv_rtcp_sink_template));
143   gst_element_class_add_pad_template (element_class,
144       gst_static_pad_template_get (&rtpbin_send_rtp_sink_template));
145
146   /* src pads */
147   gst_element_class_add_pad_template (element_class,
148       gst_static_pad_template_get (&rtpbin_recv_rtp_src_template));
149   gst_element_class_add_pad_template (element_class,
150       gst_static_pad_template_get (&rtpbin_send_rtcp_src_template));
151   gst_element_class_add_pad_template (element_class,
152       gst_static_pad_template_get (&rtpbin_send_rtp_src_template));
153
154   gst_element_class_set_details (element_class, &rtpbin_details);
155 }
156
157 static void
158 gst_rtp_bin_class_init (GstRTPBinClass * klass)
159 {
160   GObjectClass *gobject_class;
161   GstElementClass *gstelement_class;
162
163   gobject_class = (GObjectClass *) klass;
164   gstelement_class = (GstElementClass *) klass;
165
166   g_type_class_add_private (klass, sizeof (GstRTPBinPrivate));
167
168   gobject_class->finalize = gst_rtp_bin_finalize;
169   gobject_class->set_property = gst_rtp_bin_set_property;
170   gobject_class->get_property = gst_rtp_bin_get_property;
171
172   gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_rtp_bin_change_state);
173   gstelement_class->request_new_pad =
174       GST_DEBUG_FUNCPTR (gst_rtp_bin_request_new_pad);
175   gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_rtp_bin_release_pad);
176 }
177
178 static void
179 gst_rtp_bin_init (GstRTPBin * rtpbin, GstRTPBinClass * klass)
180 {
181   rtpbin->priv = GST_RTP_BIN_GET_PRIVATE (rtpbin);
182 }
183
184 static void
185 gst_rtp_bin_finalize (GObject * object)
186 {
187   GstRTPBin *rtpbin;
188
189   rtpbin = GST_RTP_BIN (object);
190
191   G_OBJECT_CLASS (parent_class)->finalize (object);
192 }
193
194 static void
195 gst_rtp_bin_set_property (GObject * object, guint prop_id,
196     const GValue * value, GParamSpec * pspec)
197 {
198   GstRTPBin *rtpbin;
199
200   rtpbin = GST_RTP_BIN (object);
201
202   switch (prop_id) {
203     default:
204       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
205       break;
206   }
207 }
208
209 static void
210 gst_rtp_bin_get_property (GObject * object, guint prop_id,
211     GValue * value, GParamSpec * pspec)
212 {
213   GstRTPBin *rtpbin;
214
215   rtpbin = GST_RTP_BIN (object);
216
217   switch (prop_id) {
218     default:
219       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
220       break;
221   }
222 }
223
224 static GstStateChangeReturn
225 gst_rtp_bin_change_state (GstElement * element, GstStateChange transition)
226 {
227   GstStateChangeReturn res;
228   GstRTPBin *rtpbin;
229
230   rtpbin = GST_RTP_BIN (element);
231
232   switch (transition) {
233     case GST_STATE_CHANGE_NULL_TO_READY:
234       break;
235     case GST_STATE_CHANGE_READY_TO_PAUSED:
236       break;
237     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
238       break;
239     default:
240       break;
241   }
242
243   res = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
244
245   switch (transition) {
246     case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
247       break;
248     case GST_STATE_CHANGE_PAUSED_TO_READY:
249       break;
250     case GST_STATE_CHANGE_READY_TO_NULL:
251       break;
252     default:
253       break;
254   }
255   return res;
256 }
257
258 /* 
259  */
260 static GstPad *
261 gst_rtp_bin_request_new_pad (GstElement * element,
262     GstPadTemplate * templ, const gchar * name)
263 {
264   GstRTPBin *rtpbin;
265   GstElementClass *klass;
266
267   g_return_val_if_fail (templ != NULL, NULL);
268   g_return_val_if_fail (GST_IS_RTP_BIN (element), NULL);
269
270   rtpbin = GST_RTP_BIN (element);
271   klass = GST_ELEMENT_GET_CLASS (element);
272
273   return NULL;
274 }
275
276 static void
277 gst_rtp_bin_release_pad (GstElement * element, GstPad * pad)
278 {
279 }