1 /* RTP DTMF muxer element for GStreamer
5 * Copyright (C) <2007> Nokia Corporation.
6 * Contact: Zeeshan Ali <zeeshan.ali@nokia.com>
7 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
8 * 2000,2005 Wim Taymans <wim@fluendo.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
27 * SECTION:element-rtpdtmfmux
28 * @short_description: mixes RTP DTMF streams into other RTP streams
31 * The RTPDTMFMuxer mixes/muxes RTP DTMF stream(s) into other RTP
32 * streams. It does exactly what it's parent (RTPMuxer) does, except
33 * that it allows upstream peer elements to request exclusive access
34 * to the stream, which is required by the RTP DTMF standards (see RFC
35 * 2833, section 3.2, para 1 for details). The peer upstream element
36 * requests the acquisition and release of a stream lock beginning
37 * using custom downstream gstreamer events. To request the acquisition
38 * of the lock, the peer element must send an event of type
39 * GST_EVENT_CUSTOM_DOWNSTREAM_OOB, having a
40 * structure of name "stream-lock" with only one boolean field:
41 * "lock". If this field is set to TRUE, the request is for the
42 * acquisition of the lock, otherwise it is for release of the lock.
44 * <para>For example, the following code in an upstream peer element
45 * requests the acquisition of the stream lock:
50 * GstStructure *structure;
53 * ... /\* srcpad initialization goes here \*\/
55 * structure = gst_structure_new ("stream-lock",
56 * "lock", G_TYPE_BOOLEAN, TRUE, NULL);
58 * event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_OOB, structure);
59 * gst_pad_push_event (dtmfsrc->srcpad, event);
70 #include <gstrtpdtmfmux.h>
73 GST_DEBUG_CATEGORY_STATIC (gst_rtp_dtmf_mux_debug);
74 #define GST_CAT_DEFAULT gst_rtp_dtmf_mux_debug
76 /* elementfactory information */
77 static const GstElementDetails gst_rtp_dtmf_mux_details =
78 GST_ELEMENT_DETAILS ("RTP muxer",
80 "mixes RTP DTMF streams into other RTP streams",
81 "Zeeshan Ali <first.last@nokia.com>");
83 static void gst_rtp_dtmf_mux_base_init (gpointer g_class);
84 static void gst_rtp_dtmf_mux_class_init (GstRTPDTMFMuxClass * klass);
85 static void gst_rtp_dtmf_mux_finalize (GObject * object);
87 static gboolean gst_rtp_dtmf_mux_sink_event (GstPad * pad,
89 static GstFlowReturn gst_rtp_dtmf_mux_chain (GstPad * pad,
92 static GstRTPMuxClass *parent_class = NULL;
95 gst_rtp_dtmf_mux_get_type (void)
97 static GType mux_type = 0;
100 static const GTypeInfo mux_info = {
101 sizeof (GstRTPDTMFMuxClass),
102 gst_rtp_dtmf_mux_base_init,
104 (GClassInitFunc) gst_rtp_dtmf_mux_class_init,
107 sizeof (GstRTPDTMFMux),
109 (GInstanceInitFunc) NULL,
113 g_type_register_static (GST_TYPE_RTP_MUX, "GstRTPDTMFMux",
120 gst_rtp_dtmf_mux_base_init (gpointer g_class)
122 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
124 gst_element_class_set_details (element_class, &gst_rtp_dtmf_mux_details);
128 gst_rtp_dtmf_mux_class_init (GstRTPDTMFMuxClass * klass)
130 GObjectClass *gobject_class;
131 GstElementClass *gstelement_class;
132 GstRTPMuxClass *gstrtpmux_class;
134 gobject_class = (GObjectClass *) klass;
135 gstelement_class = (GstElementClass *) klass;
136 gstrtpmux_class = (GstRTPMuxClass *) klass;
138 parent_class = g_type_class_peek_parent (klass);
140 gobject_class->finalize = gst_rtp_dtmf_mux_finalize;
141 gstrtpmux_class->chain_func = gst_rtp_dtmf_mux_chain;
142 gstrtpmux_class->sink_event_func = gst_rtp_dtmf_mux_sink_event;
146 gst_rtp_dtmf_mux_finalize (GObject * object)
150 mux = GST_RTP_DTMF_MUX (object);
152 G_OBJECT_CLASS (parent_class)->finalize (object);
156 gst_rtp_dtmf_mux_chain (GstPad * pad, GstBuffer * buffer)
161 mux = GST_RTP_DTMF_MUX (gst_pad_get_parent (pad));
163 GST_OBJECT_LOCK (mux);
164 if (mux->special_pad != NULL && mux->special_pad != pad) {
165 /* Drop the buffer */
166 gst_buffer_unref (buffer);
168 GST_OBJECT_UNLOCK (mux);
172 GST_OBJECT_UNLOCK (mux);
173 if (parent_class->chain_func)
174 ret = parent_class->chain_func (pad, buffer);
176 ret = GST_FLOW_ERROR;
179 gst_object_unref (mux);
184 gst_rtp_dtmf_mux_lock_stream (GstRTPDTMFMux *mux, GstPad * pad)
186 if (mux->special_pad != NULL)
187 GST_WARNING_OBJECT (mux,
188 "Stream lock already acquired by pad %s",
189 GST_ELEMENT_NAME (mux->special_pad));
192 GST_DEBUG_OBJECT (mux,
193 "Stream lock acquired by pad %s",
194 GST_ELEMENT_NAME (pad));
195 mux->special_pad = gst_object_ref (pad);
200 gst_rtp_dtmf_mux_unlock_stream (GstRTPDTMFMux *mux, GstPad * pad)
202 if (mux->special_pad == NULL)
203 GST_WARNING_OBJECT (mux,
204 "Stream lock not acquired, can't release it");
206 else if (pad != mux->special_pad)
207 GST_WARNING_OBJECT (mux,
208 "pad %s attempted to release Stream lock"
209 " which was acquired by pad %s", GST_ELEMENT_NAME (pad),
210 GST_ELEMENT_NAME (mux->special_pad));
212 GST_DEBUG_OBJECT (mux,
213 "Stream lock released by pad %s",
214 GST_ELEMENT_NAME (mux->special_pad));
215 gst_object_unref (mux->special_pad);
216 mux->special_pad = NULL;
221 gst_rtp_dtmf_mux_handle_stream_lock_event (GstRTPDTMFMux *mux, GstPad * pad,
222 const GstStructure * event_structure)
226 if (!gst_structure_get_boolean (event_structure, "lock", &lock))
229 GST_OBJECT_LOCK (mux);
231 gst_rtp_dtmf_mux_lock_stream (mux, pad);
233 gst_rtp_dtmf_mux_unlock_stream (mux, pad);
234 GST_OBJECT_UNLOCK (mux);
240 gst_rtp_dtmf_mux_handle_downstream_event (GstRTPDTMFMux *mux,
241 GstPad * pad, GstEvent * event)
243 const GstStructure *structure;
244 gboolean ret = FALSE;
246 structure = gst_event_get_structure (event);
247 /* FIXME: is this event generic enough to be given a generic name? */
248 if (structure && gst_structure_has_name (structure, "stream-lock"))
249 ret = gst_rtp_dtmf_mux_handle_stream_lock_event (mux, pad, structure);
255 gst_rtp_dtmf_mux_ignore_event (GstPad * pad, GstEvent * event)
259 if (parent_class->sink_event_func)
260 /* Give the parent a chance to handle the event first */
261 ret = parent_class->sink_event_func (pad, event);
264 ret = gst_pad_event_default (pad, event);
270 gst_rtp_dtmf_mux_sink_event (GstPad * pad, GstEvent * event)
274 gboolean ret = FALSE;
276 type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN;
278 mux = (GstRTPDTMFMux *) gst_pad_get_parent (pad);
281 case GST_EVENT_CUSTOM_DOWNSTREAM_OOB:
282 ret = gst_rtp_dtmf_mux_handle_downstream_event (mux, pad, event);
283 gst_event_unref (event);
286 ret = gst_rtp_dtmf_mux_ignore_event (pad, event);
290 gst_object_unref (mux);
295 gst_rtp_dtmf_mux_plugin_init (GstPlugin * plugin)
297 GST_DEBUG_CATEGORY_INIT (gst_rtp_dtmf_mux_debug, "rtpdtmfmux", 0,
300 return gst_element_register (plugin, "rtpdtmfmux", GST_RANK_NONE,
301 GST_TYPE_RTP_DTMF_MUX);