version 0.1.3
[sipe-libnice.git] / gst / gstnicesink.c
blob9898e9465257f2d847ae21d46c1cf6d0bd9304ff
1 /*
2 * This file is part of the Nice GLib ICE library.
4 * (C) 2006, 2007 Collabora Ltd.
5 * Contact: Dafydd Harries
6 * (C) 2006, 2007 Nokia Corporation. All rights reserved.
7 * Contact: Kai Vehmanen
9 * The contents of this file are subject to the Mozilla Public License Version
10 * 1.1 (the "License"); you may not use this file except in compliance with
11 * the License. You may obtain a copy of the License at
12 * http://www.mozilla.org/MPL/
14 * Software distributed under the License is distributed on an "AS IS" basis,
15 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
16 * for the specific language governing rights and limitations under the
17 * License.
19 * The Original Code is the Nice GLib ICE library.
21 * The Initial Developers of the Original Code are Collabora Ltd and Nokia
22 * Corporation. All Rights Reserved.
24 * Contributors:
25 * Dafydd Harries, Collabora Ltd.
27 * Alternatively, the contents of this file may be used under the terms of the
28 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
29 * case the provisions of LGPL are applicable instead of those above. If you
30 * wish to allow use of your version of this file only under the terms of the
31 * LGPL and not to allow others to use your version of this file under the
32 * MPL, indicate your decision by deleting the provisions above and replace
33 * them with the notice and other provisions required by the LGPL. If you do
34 * not delete the provisions above, a recipient may use your version of this
35 * file under either the MPL or the LGPL.
37 #ifdef HAVE_CONFIG_H
38 # include "config.h"
39 #endif
41 #include "gstnicesink.h"
44 GST_DEBUG_CATEGORY_STATIC (nicesink_debug);
45 #define GST_CAT_DEFAULT nicesink_debug
47 static GstFlowReturn
48 gst_nice_sink_render (
49 GstBaseSink *basesink,
50 GstBuffer *buffer);
52 static void
53 gst_nice_sink_set_property (
54 GObject *object,
55 guint prop_id,
56 const GValue *value,
57 GParamSpec *pspec);
59 static void
60 gst_nice_sink_get_property (
61 GObject *object,
62 guint prop_id,
63 GValue *value,
64 GParamSpec *pspec);
66 static void
67 gst_nice_sink_dispose (GObject *object);
69 static GstStateChangeReturn
70 gst_nice_sink_change_state (
71 GstElement * element,
72 GstStateChange transition);
74 static GstStaticPadTemplate gst_nice_sink_sink_template =
75 GST_STATIC_PAD_TEMPLATE (
76 "sink",
77 GST_PAD_SINK,
78 GST_PAD_ALWAYS,
79 GST_STATIC_CAPS_ANY);
81 G_DEFINE_TYPE (GstNiceSink, gst_nice_sink, GST_TYPE_BASE_SINK);
83 enum
85 PROP_AGENT = 1,
86 PROP_STREAM,
87 PROP_COMPONENT
90 static void
91 gst_nice_sink_class_init (GstNiceSinkClass *klass)
93 GstBaseSinkClass *gstbasesink_class;
94 GstElementClass *gstelement_class;
95 GObjectClass *gobject_class;
97 GST_DEBUG_CATEGORY_INIT (nicesink_debug, "nicesink",
98 0, "libnice sink");
100 gstbasesink_class = (GstBaseSinkClass *) klass;
101 gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_nice_sink_render);
103 gobject_class = (GObjectClass *) klass;
104 gobject_class->set_property = gst_nice_sink_set_property;
105 gobject_class->get_property = gst_nice_sink_get_property;
106 gobject_class->dispose = gst_nice_sink_dispose;
108 gstelement_class = (GstElementClass *) klass;
109 gstelement_class->change_state = gst_nice_sink_change_state;
111 gst_element_class_add_pad_template (gstelement_class,
112 gst_static_pad_template_get (&gst_nice_sink_sink_template));
113 #if GST_CHECK_VERSION (1,0,0)
114 gst_element_class_set_metadata (gstelement_class,
115 #else
116 gst_element_class_set_details_simple (gstelement_class,
117 #endif
118 "ICE sink",
119 "Sink",
120 "Interactive UDP connectivity establishment",
121 "Dafydd Harries <dafydd.harries@collabora.co.uk>");
124 g_object_class_install_property (gobject_class, PROP_AGENT,
125 g_param_spec_object (
126 "agent",
127 "Agent",
128 "The NiceAgent this source is bound to",
129 NICE_TYPE_AGENT,
130 G_PARAM_READWRITE));
132 g_object_class_install_property (gobject_class, PROP_STREAM,
133 g_param_spec_uint (
134 "stream",
135 "Stream ID",
136 "The ID of the stream to read from",
138 G_MAXUINT,
140 G_PARAM_READWRITE));
142 g_object_class_install_property (gobject_class, PROP_COMPONENT,
143 g_param_spec_uint (
144 "component",
145 "Component ID",
146 "The ID of the component to read from",
148 G_MAXUINT,
150 G_PARAM_READWRITE));
153 static void
154 gst_nice_sink_init (GstNiceSink *sink)
158 static GstFlowReturn
159 gst_nice_sink_render (GstBaseSink *basesink, GstBuffer *buffer)
161 GstNiceSink *nicesink = GST_NICE_SINK (basesink);
163 #if GST_CHECK_VERSION (1,0,0)
164 GstMapInfo info;
166 gst_buffer_map (buffer, &info, GST_MAP_READ);
168 nice_agent_send (nicesink->agent, nicesink->stream_id,
169 nicesink->component_id, info.size, (gchar *) info.data);
171 gst_buffer_unmap (buffer, &info);
172 #else
173 nice_agent_send (nicesink->agent, nicesink->stream_id,
174 nicesink->component_id, GST_BUFFER_SIZE (buffer),
175 (gchar *) GST_BUFFER_DATA (buffer));
176 #endif
178 return GST_FLOW_OK;
182 static void
183 gst_nice_sink_dispose (GObject *object)
185 GstNiceSink *sink = GST_NICE_SINK (object);
187 if (sink->agent)
188 g_object_unref (sink->agent);
189 sink->agent = NULL;
191 G_OBJECT_CLASS (gst_nice_sink_parent_class)->dispose (object);
194 static void
195 gst_nice_sink_set_property (
196 GObject *object,
197 guint prop_id,
198 const GValue *value,
199 GParamSpec *pspec)
201 GstNiceSink *sink = GST_NICE_SINK (object);
203 switch (prop_id)
205 case PROP_AGENT:
206 if (sink->agent)
207 GST_ERROR_OBJECT (object,
208 "Changing the agent on a nice sink not allowed");
209 else
210 sink->agent = g_value_dup_object (value);
211 break;
213 case PROP_STREAM:
214 sink->stream_id = g_value_get_uint (value);
215 break;
217 case PROP_COMPONENT:
218 sink->component_id = g_value_get_uint (value);
219 break;
221 default:
222 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
223 break;
227 static void
228 gst_nice_sink_get_property (
229 GObject *object,
230 guint prop_id,
231 GValue *value,
232 GParamSpec *pspec)
234 GstNiceSink *sink = GST_NICE_SINK (object);
236 switch (prop_id)
238 case PROP_AGENT:
239 g_value_set_object (value, sink->agent);
240 break;
242 case PROP_STREAM:
243 g_value_set_uint (value, sink->stream_id);
244 break;
246 case PROP_COMPONENT:
247 g_value_set_uint (value, sink->component_id);
248 break;
250 default:
251 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
252 break;
256 static GstStateChangeReturn
257 gst_nice_sink_change_state (GstElement * element, GstStateChange transition)
259 GstNiceSink *sink;
260 GstStateChangeReturn ret;
262 sink = GST_NICE_SINK (element);
264 switch (transition) {
265 case GST_STATE_CHANGE_NULL_TO_READY:
266 if (sink->agent == NULL)
268 GST_ERROR_OBJECT (element,
269 "Trying to start Nice sink without an agent set");
270 return GST_STATE_CHANGE_FAILURE;
272 break;
273 default:
274 break;
277 ret = GST_ELEMENT_CLASS (gst_nice_sink_parent_class)->change_state (element,
278 transition);
280 return ret;