1 /* GStreamer DTMF source
5 * Copyright (C) <2007> Collabora.
6 * Contact: Youness Alaoui <youness.alaoui@collabora.co.uk>
7 * Copyright (C) <2007> Nokia Corporation.
8 * Contact: Zeeshan Ali <zeeshan.ali@nokia.com>
9 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
10 * 2000,2005 Wim Taymans <wim@fluendo.com>
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with this library; if not, write to the
24 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 * Boston, MA 02111-1307, USA.
29 * SECTION:element-dtmfsrc
30 * @short_description: Generates DTMF packets
35 * The DTMFSrc element generates DTMF (ITU-T Q.23 Specification) tone packets on request
36 * from application. The application communicates the beginning and end of a
37 * DTMF event using custom upstream gstreamer events. To report a DTMF event, an
38 * application must send an event of type GST_EVENT_CUSTOM_UPSTREAM, having a
39 * structure of name "dtmf-event" with fields set according to the following
46 * <colspec colname='Name' />
47 * <colspec colname='Type' />
48 * <colspec colname='Possible values' />
49 * <colspec colname='Purpose' />
54 * <entry>GType</entry>
55 * <entry>Possible values</entry>
56 * <entry>Purpose</entry>
63 * <entry>G_TYPE_INT</entry>
65 * <entry>The application uses this field to specify which of the two methods
66 * specified in RFC 2833 to use. The value should be 0 for tones and 1 for
67 * named events. This element is only capable of generating tones.
71 * <entry>number</entry>
72 * <entry>G_TYPE_INT</entry>
74 * <entry>The event number.</entry>
77 * <entry>volume</entry>
78 * <entry>G_TYPE_INT</entry>
80 * <entry>This field describes the power level of the tone, expressed in dBm0
81 * after dropping the sign. Power levels range from 0 to -63 dBm0. The range of
82 * valid DTMF is from 0 to -36 dBm0. Can be omitted if start is set to FALSE.
86 * <entry>start</entry>
87 * <entry>G_TYPE_BOOLEAN</entry>
88 * <entry>True or False</entry>
89 * <entry>Whether the event is starting or ending.</entry>
92 * <entry>method</entry>
93 * <entry>G_TYPE_INT</entry>
95 * <entry>The method used for sending event, this element will react if this field
104 * <para>For example, the following code informs the pipeline (and in turn, the
105 * DTMFSrc element inside the pipeline) about the start of a DTMF named
106 * event '1' of volume -25 dBm0:
111 * structure = gst_structure_new ("dtmf-event",
112 * "type", G_TYPE_INT, 0,
113 * "number", G_TYPE_INT, 1,
114 * "volume", G_TYPE_INT, 25,
115 * "start", G_TYPE_BOOLEAN, TRUE, NULL);
117 * event = gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM, structure);
118 * gst_element_send_event (pipeline, event);
136 # define M_PI 3.14159265358979323846 /* pi */
140 #include "gstdtmfsrc.h"
142 #define GST_TONE_DTMF_TYPE_EVENT 0
143 #define DEFAULT_PACKET_INTERVAL 50 /* ms */
144 #define MIN_PACKET_INTERVAL 10 /* ms */
145 #define MAX_PACKET_INTERVAL 50 /* ms */
146 #define SAMPLE_RATE 8000
147 #define SAMPLE_SIZE 16
152 #define MAX_VOLUME 36
153 #define MIN_INTER_DIGIT_INTERVAL 100
154 #define MIN_PULSE_DURATION 250
155 #define MIN_DUTY_CYCLE (MIN_INTER_DIGIT_INTERVAL + MIN_PULSE_DURATION)
158 typedef struct st_dtmf_key {
162 float high_frequency;
165 static const DTMF_KEY DTMF_KEYS[] = {
166 {"DTMF_KEY_EVENT_0", 0, 941, 1336},
167 {"DTMF_KEY_EVENT_1", 1, 697, 1209},
168 {"DTMF_KEY_EVENT_2", 2, 697, 1336},
169 {"DTMF_KEY_EVENT_3", 3, 697, 1477},
170 {"DTMF_KEY_EVENT_4", 4, 770, 1209},
171 {"DTMF_KEY_EVENT_5", 5, 770, 1336},
172 {"DTMF_KEY_EVENT_6", 6, 770, 1477},
173 {"DTMF_KEY_EVENT_7", 7, 852, 1209},
174 {"DTMF_KEY_EVENT_8", 8, 852, 1336},
175 {"DTMF_KEY_EVENT_9", 9, 852, 1477},
176 {"DTMF_KEY_EVENT_S", 10, 941, 1209},
177 {"DTMF_KEY_EVENT_P", 11, 941, 1477},
178 {"DTMF_KEY_EVENT_A", 12, 697, 1633},
179 {"DTMF_KEY_EVENT_B", 13, 770, 1633},
180 {"DTMF_KEY_EVENT_C", 14, 852, 1633},
181 {"DTMF_KEY_EVENT_D", 15, 941, 1633},
184 #define MAX_DTMF_EVENTS 16
187 DTMF_KEY_EVENT_1 = 1,
188 DTMF_KEY_EVENT_2 = 2,
189 DTMF_KEY_EVENT_3 = 3,
190 DTMF_KEY_EVENT_4 = 4,
191 DTMF_KEY_EVENT_5 = 5,
192 DTMF_KEY_EVENT_6 = 6,
193 DTMF_KEY_EVENT_7 = 7,
194 DTMF_KEY_EVENT_8 = 8,
195 DTMF_KEY_EVENT_9 = 9,
196 DTMF_KEY_EVENT_0 = 0,
197 DTMF_KEY_EVENT_STAR = 10,
198 DTMF_KEY_EVENT_POUND = 11,
199 DTMF_KEY_EVENT_A = 12,
200 DTMF_KEY_EVENT_B = 13,
201 DTMF_KEY_EVENT_C = 14,
202 DTMF_KEY_EVENT_D = 15,
205 /* elementfactory information */
206 static const GstElementDetails gst_dtmf_src_details =
207 GST_ELEMENT_DETAILS ("DTMF tone generator",
209 "Generates DTMF tones",
210 "Youness Alaoui <youness.alaoui@collabora.co.uk>");
212 GST_DEBUG_CATEGORY_STATIC (gst_dtmf_src_debug);
213 #define GST_CAT_DEFAULT gst_dtmf_src_debug
221 static GstStaticPadTemplate gst_dtmf_src_template =
222 GST_STATIC_PAD_TEMPLATE ("src",
225 GST_STATIC_CAPS ("audio/x-raw-int, "
228 "endianness = (int) 1234, "
229 "signed = (bool) true, "
230 "rate = (int) 8000, "
231 "channels = (int) 1")
234 GST_BOILERPLATE (GstDTMFSrc, gst_dtmf_src, GstBaseSrc, GST_TYPE_BASE_SRC);
236 static void gst_dtmf_src_finalize (GObject * object);
238 static void gst_dtmf_src_set_property (GObject * object, guint prop_id,
239 const GValue * value, GParamSpec * pspec);
240 static void gst_dtmf_src_get_property (GObject * object, guint prop_id,
241 GValue * value, GParamSpec * pspec);
242 static gboolean gst_dtmf_src_handle_event (GstBaseSrc *src, GstEvent * event);
243 static GstStateChangeReturn gst_dtmf_src_change_state (GstElement * element,
244 GstStateChange transition);
245 static void gst_dtmf_src_generate_tone(GstDTMFSrcEvent *event, DTMF_KEY key,
246 float duration, GstBuffer * buffer);
247 static GstFlowReturn gst_dtmf_src_create (GstBaseSrc * basesrc,
248 guint64 offset, guint length, GstBuffer ** buffer);
249 static void gst_dtmf_src_add_start_event (GstDTMFSrc *dtmfsrc,
250 gint event_number, gint event_volume);
251 static void gst_dtmf_src_add_stop_event (GstDTMFSrc *dtmfsrc);
253 static void gst_dtmf_src_get_times (GstBaseSrc * basesrc,
254 GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
256 static gboolean gst_dtmf_src_unlock (GstBaseSrc *src);
260 gst_dtmf_src_base_init (gpointer g_class)
262 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
264 GST_DEBUG_CATEGORY_INIT (gst_dtmf_src_debug,
265 "dtmfsrc", 0, "dtmfsrc element");
267 gst_element_class_add_pad_template (element_class,
268 gst_static_pad_template_get (&gst_dtmf_src_template));
270 gst_element_class_set_details (element_class, &gst_dtmf_src_details);
274 gst_dtmf_src_class_init (GstDTMFSrcClass * klass)
276 GObjectClass *gobject_class;
277 GstBaseSrcClass *gstbasesrc_class;
278 GstElementClass *gstelement_class;
280 gobject_class = G_OBJECT_CLASS (klass);
281 gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
282 gstelement_class = GST_ELEMENT_CLASS (klass);
285 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_dtmf_src_finalize);
286 gobject_class->set_property =
287 GST_DEBUG_FUNCPTR (gst_dtmf_src_set_property);
288 gobject_class->get_property =
289 GST_DEBUG_FUNCPTR (gst_dtmf_src_get_property);
291 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_INTERVAL,
292 g_param_spec_int ("interval", "Interval between tone packets",
293 "Interval in ms between two tone packets", MIN_PACKET_INTERVAL,
294 MAX_PACKET_INTERVAL, DEFAULT_PACKET_INTERVAL, G_PARAM_READWRITE));
296 gstelement_class->change_state =
297 GST_DEBUG_FUNCPTR (gst_dtmf_src_change_state);
298 gstbasesrc_class->unlock =
299 GST_DEBUG_FUNCPTR (gst_dtmf_src_unlock);
301 gstbasesrc_class->event =
302 GST_DEBUG_FUNCPTR (gst_dtmf_src_handle_event);
303 gstbasesrc_class->get_times =
304 GST_DEBUG_FUNCPTR (gst_dtmf_src_get_times);
305 gstbasesrc_class->create =
306 GST_DEBUG_FUNCPTR (gst_dtmf_src_create);
312 gst_dtmf_src_init (GstDTMFSrc * dtmfsrc, GstDTMFSrcClass *g_class)
314 /* we operate in time */
315 gst_base_src_set_format (GST_BASE_SRC (dtmfsrc), GST_FORMAT_TIME);
316 gst_base_src_set_live (GST_BASE_SRC (dtmfsrc), TRUE);
318 dtmfsrc->interval = DEFAULT_PACKET_INTERVAL;
320 dtmfsrc->event_queue = g_async_queue_new ();
321 dtmfsrc->last_event = NULL;
323 dtmfsrc->clock_id = NULL;
325 GST_DEBUG_OBJECT (dtmfsrc, "init done");
329 gst_dtmf_src_finalize (GObject * object)
333 dtmfsrc = GST_DTMF_SRC (object);
335 if (dtmfsrc->event_queue) {
336 g_async_queue_unref (dtmfsrc->event_queue);
337 dtmfsrc->event_queue = NULL;
340 G_OBJECT_CLASS (parent_class)->finalize (object);
344 gst_dtmf_src_handle_dtmf_event (GstDTMFSrc *dtmfsrc,
345 const GstStructure * event_structure)
351 if (!gst_structure_get_int (event_structure, "type", &event_type) ||
352 !gst_structure_get_boolean (event_structure, "start", &start) ||
353 (start == TRUE && event_type != GST_TONE_DTMF_TYPE_EVENT))
356 if (gst_structure_get_int (event_structure, "method", &method)) {
366 if (!gst_structure_get_int (event_structure, "number", &event_number) ||
367 !gst_structure_get_int (event_structure, "volume", &event_volume))
370 GST_DEBUG_OBJECT (dtmfsrc, "Received start event %d with volume %d",
371 event_number, event_volume);
372 gst_dtmf_src_add_start_event (dtmfsrc, event_number, event_volume);
376 GST_DEBUG_OBJECT (dtmfsrc, "Received stop event");
377 gst_dtmf_src_add_stop_event (dtmfsrc);
386 gst_dtmf_src_handle_custom_upstream (GstDTMFSrc *dtmfsrc,
389 gboolean result = FALSE;
390 const GstStructure *structure;
392 GstStateChangeReturn ret;
394 ret = gst_element_get_state (GST_ELEMENT (dtmfsrc), &state, NULL, 0);
395 if (ret != GST_STATE_CHANGE_SUCCESS || state != GST_STATE_PLAYING) {
396 GST_DEBUG_OBJECT (dtmfsrc, "Received event while not in PLAYING state");
400 GST_DEBUG_OBJECT (dtmfsrc, "Received event is of our interest");
401 structure = gst_event_get_structure (event);
402 if (structure && gst_structure_has_name (structure, "dtmf-event"))
403 result = gst_dtmf_src_handle_dtmf_event (dtmfsrc, structure);
410 gst_dtmf_src_handle_event (GstBaseSrc * src, GstEvent * event)
413 gboolean result = FALSE;
415 dtmfsrc = GST_DTMF_SRC (src);
417 GST_DEBUG_OBJECT (dtmfsrc, "Received an event on the src pad");
418 if (GST_EVENT_TYPE (event) == GST_EVENT_CUSTOM_UPSTREAM) {
419 result = gst_dtmf_src_handle_custom_upstream (dtmfsrc, event);
426 gst_dtmf_src_set_property (GObject * object, guint prop_id,
427 const GValue * value, GParamSpec * pspec)
431 dtmfsrc = GST_DTMF_SRC (object);
435 dtmfsrc->interval = g_value_get_int (value);
438 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
444 gst_dtmf_src_get_property (GObject * object, guint prop_id, GValue * value,
449 dtmfsrc = GST_DTMF_SRC (object);
453 g_value_set_uint (value, dtmfsrc->interval);
456 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
462 gst_dtmf_src_set_stream_lock (GstDTMFSrc *dtmfsrc, gboolean lock)
464 GstPad *srcpad = GST_BASE_SRC_PAD (dtmfsrc);
466 GstStructure *structure;
468 structure = gst_structure_new ("stream-lock",
469 "lock", G_TYPE_BOOLEAN, lock, NULL);
471 event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_OOB, structure);
472 if (!gst_pad_push_event (srcpad, event)) {
473 GST_WARNING_OBJECT (dtmfsrc, "stream-lock event not handled");
478 gst_dtmf_prepare_timestamps (GstDTMFSrc *dtmfsrc)
481 GstClockTime base_time;
483 base_time = GST_ELEMENT_CAST (dtmfsrc)->base_time;
485 clock = gst_element_get_clock (GST_ELEMENT (dtmfsrc));
487 dtmfsrc->timestamp = gst_clock_get_time (clock) - base_time;
488 gst_object_unref (clock);
490 gchar *dtmf_name = gst_element_get_name (dtmfsrc);
491 GST_ERROR_OBJECT (dtmfsrc, "No clock set for element %s", dtmf_name);
492 dtmfsrc->timestamp = GST_CLOCK_TIME_NONE;
498 gst_dtmf_src_add_start_event (GstDTMFSrc *dtmfsrc, gint event_number,
502 GstDTMFSrcEvent * event = g_malloc (sizeof(GstDTMFSrcEvent));
503 event->event_type = DTMF_EVENT_TYPE_START;
505 event->event_number = CLAMP (event_number, MIN_EVENT, MAX_EVENT);
506 event->volume = CLAMP (event_volume, MIN_VOLUME, MAX_VOLUME);
508 g_async_queue_push (dtmfsrc->event_queue, event);
512 gst_dtmf_src_add_stop_event (GstDTMFSrc *dtmfsrc)
515 GstDTMFSrcEvent * event = g_malloc (sizeof(GstDTMFSrcEvent));
516 event->event_type = DTMF_EVENT_TYPE_STOP;
518 event->event_number = 0;
521 g_async_queue_push (dtmfsrc->event_queue, event);
525 gst_dtmf_src_generate_silence(GstBuffer * buffer, float duration)
529 /* Create a buffer with data set to 0 */
530 buf_size = ((duration/1000)*SAMPLE_RATE*SAMPLE_SIZE*CHANNELS)/8;
531 GST_BUFFER_SIZE (buffer) = buf_size;
532 GST_BUFFER_MALLOCDATA (buffer) = g_malloc0(buf_size);
533 GST_BUFFER_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer);
538 gst_dtmf_src_generate_tone(GstDTMFSrcEvent *event, DTMF_KEY key, float duration,
544 double amplitude, f1, f2;
545 double volume_factor;
547 /* Create a buffer for the tone */
548 tone_size = ((duration/1000)*SAMPLE_RATE*SAMPLE_SIZE*CHANNELS)/8;
549 GST_BUFFER_SIZE (buffer) = tone_size;
550 GST_BUFFER_MALLOCDATA (buffer) = g_malloc(tone_size);
551 GST_BUFFER_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer);
553 p = (gint16 *) GST_BUFFER_MALLOCDATA (buffer);
555 volume_factor = pow (10, (-event->volume) / 20);
558 * For each sample point we calculate 'x' as the
559 * the amplitude value.
561 for (i = 0; i < (tone_size / (SAMPLE_SIZE/8)); i++) {
563 * We add the fundamental frequencies together.
565 f1 = sin(2 * M_PI * key.low_frequency * (event->sample / SAMPLE_RATE));
566 f2 = sin(2 * M_PI * key.high_frequency * (event->sample / SAMPLE_RATE));
568 amplitude = (f1 + f2) / 2;
570 /* Adjust the volume */
571 amplitude *= volume_factor;
573 /* Make the [-1:1] interval into a [-32767:32767] interval */
576 /* Store it in the data buffer */
577 *(p++) = (gint16) amplitude;
584 gst_dtmf_src_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
585 GstClockTime * start, GstClockTime * end)
587 /* for live sources, sync on the timestamp of the buffer */
588 if (gst_base_src_is_live (basesrc)) {
589 GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
591 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
592 /* get duration to calculate end time */
593 GstClockTime duration = GST_BUFFER_DURATION (buffer);
596 if (GST_CLOCK_TIME_IS_VALID (duration)) {
597 *end = *start + duration;
608 gst_dtmf_src_create_next_tone_packet (GstDTMFSrc *dtmfsrc,
609 GstDTMFSrcEvent *event)
611 GstBuffer *buf = NULL;
612 gboolean send_silence = FALSE;
613 GstPad *srcpad = GST_BASE_SRC_PAD (dtmfsrc);
615 GST_DEBUG_OBJECT (dtmfsrc, "Creating buffer for tone %s",
616 DTMF_KEYS[event->event_number].event_name);
618 /* create buffer to hold the tone */
619 buf = gst_buffer_new ();
621 if (event->packet_count * dtmfsrc->interval < MIN_INTER_DIGIT_INTERVAL) {
626 GST_DEBUG_OBJECT (dtmfsrc, "Generating silence");
627 gst_dtmf_src_generate_silence (buf, dtmfsrc->interval);
629 GST_DEBUG_OBJECT (dtmfsrc, "Generating tone");
630 gst_dtmf_src_generate_tone(event, DTMF_KEYS[event->event_number],
631 dtmfsrc->interval, buf);
633 event->packet_count++;
636 /* timestamp and duration of GstBuffer */
637 GST_BUFFER_DURATION (buf) = dtmfsrc->interval * GST_MSECOND;
638 GST_BUFFER_TIMESTAMP (buf) = dtmfsrc->timestamp;
639 dtmfsrc->timestamp += GST_BUFFER_DURATION (buf);
641 /* Set caps on the buffer before pushing it */
642 gst_buffer_set_caps (buf, GST_PAD_CAPS (srcpad));
648 gst_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
649 guint length, GstBuffer ** buffer)
651 GstBuffer *buf = NULL;
653 GstDTMFSrcEvent *event;
654 GstDTMFSrc * dtmfsrc;
656 dtmfsrc = GST_DTMF_SRC (basesrc);
658 g_async_queue_ref (dtmfsrc->event_queue);
661 if (dtmfsrc->last_event == NULL) {
662 GST_DEBUG_OBJECT (dtmfsrc, "popping");
663 event = g_async_queue_pop (dtmfsrc->event_queue);
665 GST_DEBUG_OBJECT (dtmfsrc, "popped %d", event->event_type);
667 if (event->event_type == DTMF_EVENT_TYPE_STOP) {
668 GST_WARNING_OBJECT (dtmfsrc,
669 "Received a DTMF stop event when already stopped");
670 } else if (event->event_type == DTMF_EVENT_TYPE_START) {
671 gst_dtmf_prepare_timestamps (dtmfsrc);
673 /* Don't forget to get exclusive access to the stream */
674 gst_dtmf_src_set_stream_lock (dtmfsrc, TRUE);
676 event->packet_count = 0;
677 dtmfsrc->last_event = event;
678 } else if (event->event_type == DTMF_EVENT_TYPE_PAUSE_TASK) {
680 * We're pushing it back because it has to stay in there until
681 * the task is really paused (and the queue will then be flushed)
683 GST_DEBUG_OBJECT (dtmfsrc, "pushing pause_task...");
684 g_async_queue_push (dtmfsrc->event_queue, event);
685 g_async_queue_unref (dtmfsrc->event_queue);
687 } else if (dtmfsrc->last_event->packet_count * dtmfsrc->interval >=
689 event = g_async_queue_try_pop (dtmfsrc->event_queue);
692 if (event->event_type == DTMF_EVENT_TYPE_START) {
693 GST_WARNING_OBJECT (dtmfsrc,
694 "Received two consecutive DTMF start events");
695 } else if (event->event_type == DTMF_EVENT_TYPE_STOP) {
696 gst_dtmf_src_set_stream_lock (dtmfsrc, FALSE);
697 g_free (dtmfsrc->last_event);
698 dtmfsrc->last_event = NULL;
700 } else if (event->event_type == DTMF_EVENT_TYPE_PAUSE_TASK) {
702 * We're pushing it back because it has to stay in there until
703 * the task is really paused (and the queue will then be flushed)
705 GST_DEBUG_OBJECT (dtmfsrc, "pushing pause_task...");
706 g_async_queue_push (dtmfsrc->event_queue, event);
707 g_async_queue_unref (dtmfsrc->event_queue);
711 g_async_queue_unref (dtmfsrc->event_queue);
713 GST_DEBUG_OBJECT (dtmfsrc, "end event check");
715 if (dtmfsrc->last_event) {
716 buf = gst_dtmf_src_create_next_tone_packet (dtmfsrc, dtmfsrc->last_event);
718 GST_DEBUG_OBJECT (dtmfsrc, "Created buffer of size %d", GST_BUFFER_SIZE (buf));
723 ret = GST_FLOW_WRONG_STATE;
726 GST_DEBUG_OBJECT (dtmfsrc, "returning");
732 gst_dtmf_src_unlock (GstBaseSrc *src) {
733 GstDTMFSrc *dtmfsrc = GST_DTMF_SRC (src);
734 GstDTMFSrcEvent *event = NULL;
736 GST_DEBUG_OBJECT (dtmfsrc, "Pushing the PAUSE_TASK even on PAUSED_TO_READY change");
737 event = g_malloc (sizeof(GstDTMFSrcEvent));
738 event->event_type = DTMF_EVENT_TYPE_PAUSE_TASK;
739 g_async_queue_push (dtmfsrc->event_queue, event);
744 static GstStateChangeReturn
745 gst_dtmf_src_change_state (GstElement * element, GstStateChange transition)
748 GstStateChangeReturn result;
749 gboolean no_preroll = FALSE;
750 GstDTMFSrcEvent *event = NULL;
752 dtmfsrc = GST_DTMF_SRC (element);
754 switch (transition) {
755 case GST_STATE_CHANGE_READY_TO_PAUSED:
756 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
757 /* Flushing the event queue */
758 event = g_async_queue_try_pop (dtmfsrc->event_queue);
760 while (event != NULL) {
762 event = g_async_queue_try_pop (dtmfsrc->event_queue);
770 GST_ELEMENT_CLASS (parent_class)->change_state (element,
771 transition)) == GST_STATE_CHANGE_FAILURE)
774 switch (transition) {
775 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
776 GST_DEBUG_OBJECT (dtmfsrc, "PLAYING TO PAUSED");
778 if (dtmfsrc->last_event) {
779 GST_DEBUG_OBJECT (dtmfsrc, "Stopping current event");
780 /* Don't forget to release the stream lock */
781 gst_dtmf_src_set_stream_lock (dtmfsrc, FALSE);
782 g_free (dtmfsrc->last_event);
783 dtmfsrc->last_event = NULL;
786 GST_DEBUG_OBJECT (dtmfsrc, "Flushing event queue");
787 /* Flushing the event queue */
788 event = g_async_queue_try_pop (dtmfsrc->event_queue);
790 while (event != NULL) {
792 event = g_async_queue_try_pop (dtmfsrc->event_queue);
795 /* Indicate that we don't do PRE_ROLL */
802 if (no_preroll && result == GST_STATE_CHANGE_SUCCESS)
803 result = GST_STATE_CHANGE_NO_PREROLL;
810 GST_ERROR_OBJECT (dtmfsrc, "parent failed state change");
816 gst_dtmf_src_plugin_init (GstPlugin * plugin)
818 return gst_element_register (plugin, "dtmfsrc",
819 GST_RANK_NONE, GST_TYPE_DTMF_SRC);