GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
- "dtmf",
- "DTMF plugins",
- plugin_init, "0.1" , "LGPL", "DTMF", "");
+ "dtmf", "DTMF plugins", plugin_init, "0.1", "LGPL", "DTMF", "");
#include "gstdtmfsrc.h"
#define GST_TONE_DTMF_TYPE_EVENT 1
-#define DEFAULT_PACKET_INTERVAL 50 /* ms */
-#define MIN_PACKET_INTERVAL 10 /* ms */
-#define MAX_PACKET_INTERVAL 50 /* ms */
+#define DEFAULT_PACKET_INTERVAL 50 /* ms */
+#define MIN_PACKET_INTERVAL 10 /* ms */
+#define MAX_PACKET_INTERVAL 50 /* ms */
#define DEFAULT_SAMPLE_RATE 8000
#define SAMPLE_SIZE 16
#define CHANNELS 1
#define MIN_DUTY_CYCLE (MIN_INTER_DIGIT_INTERVAL + MIN_PULSE_DURATION)
-typedef struct st_dtmf_key {
- char *event_name;
- int event_encoding;
- float low_frequency;
- float high_frequency;
+typedef struct st_dtmf_key
+{
+ char *event_name;
+ int event_encoding;
+ float low_frequency;
+ float high_frequency;
} DTMF_KEY;
static const DTMF_KEY DTMF_KEYS[] = {
- {"DTMF_KEY_EVENT_0", 0, 941, 1336},
- {"DTMF_KEY_EVENT_1", 1, 697, 1209},
- {"DTMF_KEY_EVENT_2", 2, 697, 1336},
- {"DTMF_KEY_EVENT_3", 3, 697, 1477},
- {"DTMF_KEY_EVENT_4", 4, 770, 1209},
- {"DTMF_KEY_EVENT_5", 5, 770, 1336},
- {"DTMF_KEY_EVENT_6", 6, 770, 1477},
- {"DTMF_KEY_EVENT_7", 7, 852, 1209},
- {"DTMF_KEY_EVENT_8", 8, 852, 1336},
- {"DTMF_KEY_EVENT_9", 9, 852, 1477},
- {"DTMF_KEY_EVENT_S", 10, 941, 1209},
- {"DTMF_KEY_EVENT_P", 11, 941, 1477},
- {"DTMF_KEY_EVENT_A", 12, 697, 1633},
- {"DTMF_KEY_EVENT_B", 13, 770, 1633},
- {"DTMF_KEY_EVENT_C", 14, 852, 1633},
- {"DTMF_KEY_EVENT_D", 15, 941, 1633},
+ {"DTMF_KEY_EVENT_0", 0, 941, 1336},
+ {"DTMF_KEY_EVENT_1", 1, 697, 1209},
+ {"DTMF_KEY_EVENT_2", 2, 697, 1336},
+ {"DTMF_KEY_EVENT_3", 3, 697, 1477},
+ {"DTMF_KEY_EVENT_4", 4, 770, 1209},
+ {"DTMF_KEY_EVENT_5", 5, 770, 1336},
+ {"DTMF_KEY_EVENT_6", 6, 770, 1477},
+ {"DTMF_KEY_EVENT_7", 7, 852, 1209},
+ {"DTMF_KEY_EVENT_8", 8, 852, 1336},
+ {"DTMF_KEY_EVENT_9", 9, 852, 1477},
+ {"DTMF_KEY_EVENT_S", 10, 941, 1209},
+ {"DTMF_KEY_EVENT_P", 11, 941, 1477},
+ {"DTMF_KEY_EVENT_A", 12, 697, 1633},
+ {"DTMF_KEY_EVENT_B", 13, 770, 1633},
+ {"DTMF_KEY_EVENT_C", 14, 852, 1633},
+ {"DTMF_KEY_EVENT_D", 15, 941, 1633},
};
#define MAX_DTMF_EVENTS 16
-enum {
-DTMF_KEY_EVENT_1 = 1,
-DTMF_KEY_EVENT_2 = 2,
-DTMF_KEY_EVENT_3 = 3,
-DTMF_KEY_EVENT_4 = 4,
-DTMF_KEY_EVENT_5 = 5,
-DTMF_KEY_EVENT_6 = 6,
-DTMF_KEY_EVENT_7 = 7,
-DTMF_KEY_EVENT_8 = 8,
-DTMF_KEY_EVENT_9 = 9,
-DTMF_KEY_EVENT_0 = 0,
-DTMF_KEY_EVENT_STAR = 10,
-DTMF_KEY_EVENT_POUND = 11,
-DTMF_KEY_EVENT_A = 12,
-DTMF_KEY_EVENT_B = 13,
-DTMF_KEY_EVENT_C = 14,
-DTMF_KEY_EVENT_D = 15,
+enum
+{
+ DTMF_KEY_EVENT_1 = 1,
+ DTMF_KEY_EVENT_2 = 2,
+ DTMF_KEY_EVENT_3 = 3,
+ DTMF_KEY_EVENT_4 = 4,
+ DTMF_KEY_EVENT_5 = 5,
+ DTMF_KEY_EVENT_6 = 6,
+ DTMF_KEY_EVENT_7 = 7,
+ DTMF_KEY_EVENT_8 = 8,
+ DTMF_KEY_EVENT_9 = 9,
+ DTMF_KEY_EVENT_0 = 0,
+ DTMF_KEY_EVENT_STAR = 10,
+ DTMF_KEY_EVENT_POUND = 11,
+ DTMF_KEY_EVENT_A = 12,
+ DTMF_KEY_EVENT_B = 13,
+ DTMF_KEY_EVENT_C = 14,
+ DTMF_KEY_EVENT_D = 15,
};
/* elementfactory information */
"width = (int) 16, "
"depth = (int) 16, "
"endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", "
- "signed = (bool) true, "
- "rate = (int) 8000, "
- "channels = (int) 1")
+ "signed = (bool) true, " "rate = (int) 8000, " "channels = (int) 1")
);
GST_BOILERPLATE (GstDTMFSrc, gst_dtmf_src, GstBaseSrc, GST_TYPE_BASE_SRC);
const GValue * value, GParamSpec * pspec);
static void gst_dtmf_src_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
-static gboolean gst_dtmf_src_handle_event (GstBaseSrc *src, GstEvent * event);
+static gboolean gst_dtmf_src_handle_event (GstBaseSrc * src, GstEvent * event);
static GstStateChangeReturn gst_dtmf_src_change_state (GstElement * element,
GstStateChange transition);
static GstFlowReturn gst_dtmf_src_create (GstBaseSrc * basesrc,
guint64 offset, guint length, GstBuffer ** buffer);
-static void gst_dtmf_src_add_start_event (GstDTMFSrc *dtmfsrc,
+static void gst_dtmf_src_add_start_event (GstDTMFSrc * dtmfsrc,
gint event_number, gint event_volume);
-static void gst_dtmf_src_add_stop_event (GstDTMFSrc *dtmfsrc);
+static void gst_dtmf_src_add_stop_event (GstDTMFSrc * dtmfsrc);
-static gboolean gst_dtmf_src_unlock (GstBaseSrc *src);
+static gboolean gst_dtmf_src_unlock (GstBaseSrc * src);
-static gboolean gst_dtmf_src_unlock_stop (GstBaseSrc *src);
+static gboolean gst_dtmf_src_unlock_stop (GstBaseSrc * src);
static gboolean gst_dtmf_src_negotiate (GstBaseSrc * basesrc);
static void
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
- GST_DEBUG_CATEGORY_INIT (gst_dtmf_src_debug,
- "dtmfsrc", 0, "dtmfsrc element");
+ GST_DEBUG_CATEGORY_INIT (gst_dtmf_src_debug, "dtmfsrc", 0, "dtmfsrc element");
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_dtmf_src_template));
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_dtmf_src_finalize);
- gobject_class->set_property =
- GST_DEBUG_FUNCPTR (gst_dtmf_src_set_property);
- gobject_class->get_property =
- GST_DEBUG_FUNCPTR (gst_dtmf_src_get_property);
+ gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_dtmf_src_set_property);
+ gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_dtmf_src_get_property);
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_INTERVAL,
g_param_spec_uint ("interval", "Interval between tone packets",
gstelement_class->change_state =
GST_DEBUG_FUNCPTR (gst_dtmf_src_change_state);
- gstbasesrc_class->unlock =
- GST_DEBUG_FUNCPTR (gst_dtmf_src_unlock);
- gstbasesrc_class->unlock_stop =
- GST_DEBUG_FUNCPTR (gst_dtmf_src_unlock_stop);
-
- gstbasesrc_class->event =
- GST_DEBUG_FUNCPTR (gst_dtmf_src_handle_event);
- gstbasesrc_class->create =
- GST_DEBUG_FUNCPTR (gst_dtmf_src_create);
- gstbasesrc_class->negotiate =
- GST_DEBUG_FUNCPTR (gst_dtmf_src_negotiate);
+ gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_dtmf_src_unlock);
+ gstbasesrc_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_dtmf_src_unlock_stop);
+
+ gstbasesrc_class->event = GST_DEBUG_FUNCPTR (gst_dtmf_src_handle_event);
+ gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_dtmf_src_create);
+ gstbasesrc_class->negotiate = GST_DEBUG_FUNCPTR (gst_dtmf_src_negotiate);
}
static void
-gst_dtmf_src_init (GstDTMFSrc * dtmfsrc, GstDTMFSrcClass *g_class)
+gst_dtmf_src_init (GstDTMFSrc * dtmfsrc, GstDTMFSrcClass * g_class)
{
/* we operate in time */
gst_base_src_set_format (GST_BASE_SRC (dtmfsrc), GST_FORMAT_TIME);
}
static gboolean
-gst_dtmf_src_handle_dtmf_event (GstDTMFSrc *dtmfsrc,
- const GstStructure * event_structure)
+gst_dtmf_src_handle_dtmf_event (GstDTMFSrc * dtmfsrc,
+ const GstStructure * event_structure)
{
gint event_type;
gboolean start;
gint event_volume;
if (!gst_structure_get_int (event_structure, "number", &event_number) ||
- !gst_structure_get_int (event_structure, "volume", &event_volume))
+ !gst_structure_get_int (event_structure, "volume", &event_volume))
goto failure;
GST_DEBUG_OBJECT (dtmfsrc, "Received start event %d with volume %d",
- event_number, event_volume);
+ event_number, event_volume);
gst_dtmf_src_add_start_event (dtmfsrc, event_number, event_volume);
}
}
static gboolean
-gst_dtmf_src_handle_custom_upstream (GstDTMFSrc *dtmfsrc,
- GstEvent * event)
+gst_dtmf_src_handle_custom_upstream (GstDTMFSrc * dtmfsrc, GstEvent * event)
{
gboolean result = FALSE;
const GstStructure *structure;
}
static void
-gst_dtmf_src_set_stream_lock (GstDTMFSrc *dtmfsrc, gboolean lock)
+gst_dtmf_src_set_stream_lock (GstDTMFSrc * dtmfsrc, gboolean lock)
{
- GstPad *srcpad = GST_BASE_SRC_PAD (dtmfsrc);
- GstEvent *event;
- GstStructure *structure;
+ GstPad *srcpad = GST_BASE_SRC_PAD (dtmfsrc);
+ GstEvent *event;
+ GstStructure *structure;
- structure = gst_structure_new ("stream-lock",
- "lock", G_TYPE_BOOLEAN, lock, NULL);
+ structure = gst_structure_new ("stream-lock",
+ "lock", G_TYPE_BOOLEAN, lock, NULL);
- event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_OOB, structure);
- if (!gst_pad_push_event (srcpad, event)) {
- GST_WARNING_OBJECT (dtmfsrc, "stream-lock event not handled");
- }
+ event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_OOB, structure);
+ if (!gst_pad_push_event (srcpad, event)) {
+ GST_WARNING_OBJECT (dtmfsrc, "stream-lock event not handled");
+ }
}
static void
-gst_dtmf_prepare_timestamps (GstDTMFSrc *dtmfsrc)
+gst_dtmf_prepare_timestamps (GstDTMFSrc * dtmfsrc)
{
GstClock *clock;
GstClockTime base_time;
}
static void
-gst_dtmf_src_add_start_event (GstDTMFSrc *dtmfsrc, gint event_number,
+gst_dtmf_src_add_start_event (GstDTMFSrc * dtmfsrc, gint event_number,
gint event_volume)
{
- GstDTMFSrcEvent * event = g_malloc (sizeof(GstDTMFSrcEvent));
+ GstDTMFSrcEvent *event = g_malloc (sizeof (GstDTMFSrcEvent));
event->event_type = DTMF_EVENT_TYPE_START;
event->sample = 0;
event->event_number = CLAMP (event_number, MIN_EVENT, MAX_EVENT);
}
static void
-gst_dtmf_src_add_stop_event (GstDTMFSrc *dtmfsrc)
+gst_dtmf_src_add_stop_event (GstDTMFSrc * dtmfsrc)
{
- GstDTMFSrcEvent * event = g_malloc (sizeof(GstDTMFSrcEvent));
+ GstDTMFSrcEvent *event = g_malloc (sizeof (GstDTMFSrcEvent));
event->event_type = DTMF_EVENT_TYPE_STOP;
event->sample = 0;
event->event_number = 0;
}
static void
-gst_dtmf_src_generate_silence(GstBuffer * buffer, float duration,
+gst_dtmf_src_generate_silence (GstBuffer * buffer, float duration,
gint sample_rate)
{
gint buf_size;
/* Create a buffer with data set to 0 */
- buf_size = ((duration/1000)*sample_rate*SAMPLE_SIZE*CHANNELS)/8;
+ buf_size = ((duration / 1000) * sample_rate * SAMPLE_SIZE * CHANNELS) / 8;
GST_BUFFER_SIZE (buffer) = buf_size;
- GST_BUFFER_MALLOCDATA (buffer) = g_malloc0(buf_size);
+ GST_BUFFER_MALLOCDATA (buffer) = g_malloc0 (buf_size);
GST_BUFFER_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer);
}
static void
-gst_dtmf_src_generate_tone(GstDTMFSrcEvent *event, DTMF_KEY key, float duration,
- GstBuffer * buffer, gint sample_rate)
+gst_dtmf_src_generate_tone (GstDTMFSrcEvent * event, DTMF_KEY key,
+ float duration, GstBuffer * buffer, gint sample_rate)
{
gint16 *p;
gint tone_size;
double volume_factor;
/* Create a buffer for the tone */
- tone_size = ((duration/1000)*sample_rate*SAMPLE_SIZE*CHANNELS)/8;
+ tone_size = ((duration / 1000) * sample_rate * SAMPLE_SIZE * CHANNELS) / 8;
GST_BUFFER_SIZE (buffer) = tone_size;
- GST_BUFFER_MALLOCDATA (buffer) = g_malloc(tone_size);
+ GST_BUFFER_MALLOCDATA (buffer) = g_malloc (tone_size);
GST_BUFFER_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer);
p = (gint16 *) GST_BUFFER_MALLOCDATA (buffer);
* For each sample point we calculate 'x' as the
* the amplitude value.
*/
- for (i = 0; i < (tone_size / (SAMPLE_SIZE/8)); i++) {
+ for (i = 0; i < (tone_size / (SAMPLE_SIZE / 8)); i++) {
/*
* We add the fundamental frequencies together.
*/
- f1 = sin(2 * M_PI * key.low_frequency * (event->sample / sample_rate));
- f2 = sin(2 * M_PI * key.high_frequency * (event->sample / sample_rate));
+ f1 = sin (2 * M_PI * key.low_frequency * (event->sample / sample_rate));
+ f2 = sin (2 * M_PI * key.high_frequency * (event->sample / sample_rate));
amplitude = (f1 + f2) / 2;
static GstBuffer *
-gst_dtmf_src_create_next_tone_packet (GstDTMFSrc *dtmfsrc,
- GstDTMFSrcEvent *event)
+gst_dtmf_src_create_next_tone_packet (GstDTMFSrc * dtmfsrc,
+ GstDTMFSrcEvent * event)
{
GstBuffer *buf = NULL;
gboolean send_silence = FALSE;
}
if (send_silence) {
- GST_DEBUG_OBJECT (dtmfsrc, "Generating silence");
+ GST_DEBUG_OBJECT (dtmfsrc, "Generating silence");
gst_dtmf_src_generate_silence (buf, dtmfsrc->interval,
dtmfsrc->sample_rate);
} else {
- GST_DEBUG_OBJECT (dtmfsrc, "Generating tone");
- gst_dtmf_src_generate_tone(event, DTMF_KEYS[event->event_number],
+ GST_DEBUG_OBJECT (dtmfsrc, "Generating tone");
+ gst_dtmf_src_generate_tone (event, DTMF_KEYS[event->event_number],
dtmfsrc->interval, buf, dtmfsrc->sample_rate);
}
event->packet_count++;
{
GstBuffer *buf = NULL;
GstDTMFSrcEvent *event;
- GstDTMFSrc * dtmfsrc;
+ GstDTMFSrc *dtmfsrc;
GstClock *clock;
GstClockID *clockid;
GstClockReturn clockret;
}
if (event)
g_free (event);
- } else if (dtmfsrc->last_event->packet_count * dtmfsrc->interval >=
+ } else if (dtmfsrc->last_event->packet_count * dtmfsrc->interval >=
MIN_DUTY_CYCLE) {
event = g_async_queue_try_pop (dtmfsrc->event_queue);
GST_OBJECT_LOCK (dtmfsrc);
if (dtmfsrc->paused)
clockret = GST_CLOCK_UNSCHEDULED;
- } else {
+ } else {
clockret = GST_CLOCK_UNSCHEDULED;
}
gst_clock_id_unref (clockid);
buf = gst_dtmf_src_create_next_tone_packet (dtmfsrc, dtmfsrc->last_event);
- GST_DEBUG_OBJECT (dtmfsrc, "Created buffer of size %d", GST_BUFFER_SIZE (buf));
+ GST_DEBUG_OBJECT (dtmfsrc, "Created buffer of size %d",
+ GST_BUFFER_SIZE (buf));
*buffer = buf;
GST_DEBUG_OBJECT (dtmfsrc, "returning a buffer");
return GST_FLOW_OK;
- paused_locked:
+paused_locked:
GST_OBJECT_UNLOCK (dtmfsrc);
- paused:
+paused:
if (dtmfsrc->last_event) {
GST_DEBUG_OBJECT (dtmfsrc, "Stopping current event");
}
static gboolean
-gst_dtmf_src_unlock (GstBaseSrc *src) {
+gst_dtmf_src_unlock (GstBaseSrc * src)
+{
GstDTMFSrc *dtmfsrc = GST_DTMF_SRC (src);
GstDTMFSrcEvent *event = NULL;
GST_OBJECT_UNLOCK (dtmfsrc);
GST_DEBUG_OBJECT (dtmfsrc, "Pushing the PAUSE_TASK event on unlock request");
- event = g_malloc (sizeof(GstDTMFSrcEvent));
+ event = g_malloc (sizeof (GstDTMFSrcEvent));
event->event_type = DTMF_EVENT_TYPE_PAUSE_TASK;
g_async_queue_push (dtmfsrc->event_queue, event);
static gboolean
-gst_dtmf_src_unlock_stop (GstBaseSrc *src) {
+gst_dtmf_src_unlock_stop (GstBaseSrc * src)
+{
GstDTMFSrc *dtmfsrc = GST_DTMF_SRC (src);
GST_DEBUG_OBJECT (dtmfsrc, "Unlock stopped");
"width", G_TYPE_INT, 16,
"depth", G_TYPE_INT, 16,
"endianness", G_TYPE_INT, G_BYTE_ORDER,
- "signed", G_TYPE_BOOLEAN, TRUE,
- "channels", G_TYPE_INT, 1,
- NULL);
+ "signed", G_TYPE_BOOLEAN, TRUE, "channels", G_TYPE_INT, 1, NULL);
peercaps = gst_pad_peer_get_caps (GST_BASE_SRC_PAD (basesrc));
if (peercaps == NULL) {
/* no peer caps, just add the other properties */
gst_caps_set_simple (srccaps,
- "rate", G_TYPE_INT, dtmfsrc->sample_rate,
- NULL);
+ "rate", G_TYPE_INT, dtmfsrc->sample_rate, NULL);
} else {
GstStructure *s;
gint sample_rate;
/* get first structure */
s = gst_caps_get_structure (srccaps, 0);
- if (gst_structure_get_int (s, "rate", &sample_rate))
- {
+ if (gst_structure_get_int (s, "rate", &sample_rate)) {
dtmfsrc->sample_rate = sample_rate;
- GST_LOG_OBJECT (dtmfsrc, "using rate from caps %d",
- dtmfsrc->sample_rate);
+ GST_LOG_OBJECT (dtmfsrc, "using rate from caps %d", dtmfsrc->sample_rate);
} else {
- GST_LOG_OBJECT (dtmfsrc, "using existing rate %d",
- dtmfsrc->sample_rate);
+ GST_LOG_OBJECT (dtmfsrc, "using existing rate %d", dtmfsrc->sample_rate);
}
- gst_structure_set (s, "rate", G_TYPE_INT, dtmfsrc->sample_rate,
- NULL);
+ gst_structure_set (s, "rate", G_TYPE_INT, dtmfsrc->sample_rate, NULL);
}
ret = gst_pad_set_caps (GST_BASE_SRC_PAD (basesrc), srccaps);
return gst_element_register (plugin, "dtmfsrc",
GST_RANK_NONE, GST_TYPE_DTMF_SRC);
}
-
#include <gst/base/gstbasesrc.h>
G_BEGIN_DECLS
-
#define GST_TYPE_DTMF_SRC (gst_dtmf_src_get_type())
#define GST_DTMF_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DTMF_SRC,GstDTMFSrc))
#define GST_DTMF_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DTMF_SRC,GstDTMFSrcClass))
#define GST_IS_DTMF_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DTMF_SRC))
#define GST_IS_DTMF_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DTMF_SRC))
#define GST_DTMF_SRC_CAST(obj) ((GstDTMFSrc *)(obj))
-
typedef struct _GstDTMFSrc GstDTMFSrc;
typedef struct _GstDTMFSrcClass GstDTMFSrcClass;
* The opaque #GstDTMFSrc data structure.
*/
-enum _GstDTMFEventType {
+enum _GstDTMFEventType
+{
DTMF_EVENT_TYPE_START,
DTMF_EVENT_TYPE_STOP,
DTMF_EVENT_TYPE_PAUSE_TASK
typedef enum _GstDTMFEventType GstDTMFEventType;
-struct _GstDTMFSrcEvent {
- GstDTMFEventType event_type;
- double sample;
- guint16 event_number;
- guint16 volume;
- guint32 packet_count;
+struct _GstDTMFSrcEvent
+{
+ GstDTMFEventType event_type;
+ double sample;
+ guint16 event_number;
+ guint16 volume;
+ guint32 packet_count;
};
typedef struct _GstDTMFSrcEvent GstDTMFSrcEvent;
-struct _GstDTMFSrc {
- GstBaseSrc parent;
- GAsyncQueue* event_queue;
- GstDTMFSrcEvent* last_event;
+struct _GstDTMFSrc
+{
+ GstBaseSrc parent;
+ GAsyncQueue *event_queue;
+ GstDTMFSrcEvent *last_event;
- guint16 interval;
- GstClockTime timestamp;
+ guint16 interval;
+ GstClockTime timestamp;
- gboolean paused;
- GstClockID clockid;
+ gboolean paused;
+ GstClockID clockid;
- gint sample_rate;
+ gint sample_rate;
};
-struct _GstDTMFSrcClass {
+struct _GstDTMFSrcClass
+{
GstBaseSrcClass parent_class;
};
gboolean gst_dtmf_src_plugin_init (GstPlugin * plugin);
G_END_DECLS
-
#endif /* __GST_DTMF_SRC_H__ */
#define __GST_RTP_DTMF_COMMON_H__
-typedef struct {
- unsigned event:8; /* Current DTMF event */
+typedef struct
+{
+ unsigned event:8; /* Current DTMF event */
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
- unsigned volume:6; /* power level of the tone, in dBm0 */
- unsigned r:1; /* Reserved-bit */
- unsigned e:1; /* End-bit */
+ unsigned volume:6; /* power level of the tone, in dBm0 */
+ unsigned r:1; /* Reserved-bit */
+ unsigned e:1; /* End-bit */
#elif G_BYTE_ORDER == G_BIG_ENDIAN
- unsigned e:1; /* End-bit */
- unsigned r:1; /* Reserved-bit */
- unsigned volume:6; /* power level of the tone, in dBm0 */
+ unsigned e:1; /* End-bit */
+ unsigned r:1; /* Reserved-bit */
+ unsigned volume:6; /* power level of the tone, in dBm0 */
#else
#error "G_BYTE_ORDER should be big or little endian."
#endif
- unsigned duration:16; /* Duration of digit, in timestamp units */
+ unsigned duration:16; /* Duration of digit, in timestamp units */
} GstRTPDTMFPayload;
#endif /* __GST_RTP_DTMF_COMMON_H__ */
#endif
-#define DEFAULT_PACKET_INTERVAL 50 /* ms */
-#define MIN_PACKET_INTERVAL 10 /* ms */
-#define MAX_PACKET_INTERVAL 50 /* ms */
+#define DEFAULT_PACKET_INTERVAL 50 /* ms */
+#define MIN_PACKET_INTERVAL 10 /* ms */
+#define MAX_PACKET_INTERVAL 50 /* ms */
#define SAMPLE_RATE 8000
#define SAMPLE_SIZE 16
#define CHANNELS 1
#define DEFAULT_MAX_DURATION 0
-typedef struct st_dtmf_key {
- char *event_name;
- int event_encoding;
- float low_frequency;
- float high_frequency;
+typedef struct st_dtmf_key
+{
+ char *event_name;
+ int event_encoding;
+ float low_frequency;
+ float high_frequency;
} DTMF_KEY;
static const DTMF_KEY DTMF_KEYS[] = {
- {"DTMF_KEY_EVENT_0", 0, 941, 1336},
- {"DTMF_KEY_EVENT_1", 1, 697, 1209},
- {"DTMF_KEY_EVENT_2", 2, 697, 1336},
- {"DTMF_KEY_EVENT_3", 3, 697, 1477},
- {"DTMF_KEY_EVENT_4", 4, 770, 1209},
- {"DTMF_KEY_EVENT_5", 5, 770, 1336},
- {"DTMF_KEY_EVENT_6", 6, 770, 1477},
- {"DTMF_KEY_EVENT_7", 7, 852, 1209},
- {"DTMF_KEY_EVENT_8", 8, 852, 1336},
- {"DTMF_KEY_EVENT_9", 9, 852, 1477},
- {"DTMF_KEY_EVENT_S", 10, 941, 1209},
- {"DTMF_KEY_EVENT_P", 11, 941, 1477},
- {"DTMF_KEY_EVENT_A", 12, 697, 1633},
- {"DTMF_KEY_EVENT_B", 13, 770, 1633},
- {"DTMF_KEY_EVENT_C", 14, 852, 1633},
- {"DTMF_KEY_EVENT_D", 15, 941, 1633},
+ {"DTMF_KEY_EVENT_0", 0, 941, 1336},
+ {"DTMF_KEY_EVENT_1", 1, 697, 1209},
+ {"DTMF_KEY_EVENT_2", 2, 697, 1336},
+ {"DTMF_KEY_EVENT_3", 3, 697, 1477},
+ {"DTMF_KEY_EVENT_4", 4, 770, 1209},
+ {"DTMF_KEY_EVENT_5", 5, 770, 1336},
+ {"DTMF_KEY_EVENT_6", 6, 770, 1477},
+ {"DTMF_KEY_EVENT_7", 7, 852, 1209},
+ {"DTMF_KEY_EVENT_8", 8, 852, 1336},
+ {"DTMF_KEY_EVENT_9", 9, 852, 1477},
+ {"DTMF_KEY_EVENT_S", 10, 941, 1209},
+ {"DTMF_KEY_EVENT_P", 11, 941, 1477},
+ {"DTMF_KEY_EVENT_A", 12, 697, 1633},
+ {"DTMF_KEY_EVENT_B", 13, 770, 1633},
+ {"DTMF_KEY_EVENT_C", 14, 852, 1633},
+ {"DTMF_KEY_EVENT_D", 15, 941, 1633},
};
#define MAX_DTMF_EVENTS 16
-enum {
-DTMF_KEY_EVENT_1 = 1,
-DTMF_KEY_EVENT_2 = 2,
-DTMF_KEY_EVENT_3 = 3,
-DTMF_KEY_EVENT_4 = 4,
-DTMF_KEY_EVENT_5 = 5,
-DTMF_KEY_EVENT_6 = 6,
-DTMF_KEY_EVENT_7 = 7,
-DTMF_KEY_EVENT_8 = 8,
-DTMF_KEY_EVENT_9 = 9,
-DTMF_KEY_EVENT_0 = 0,
-DTMF_KEY_EVENT_STAR = 10,
-DTMF_KEY_EVENT_POUND = 11,
-DTMF_KEY_EVENT_A = 12,
-DTMF_KEY_EVENT_B = 13,
-DTMF_KEY_EVENT_C = 14,
-DTMF_KEY_EVENT_D = 15,
+enum
+{
+ DTMF_KEY_EVENT_1 = 1,
+ DTMF_KEY_EVENT_2 = 2,
+ DTMF_KEY_EVENT_3 = 3,
+ DTMF_KEY_EVENT_4 = 4,
+ DTMF_KEY_EVENT_5 = 5,
+ DTMF_KEY_EVENT_6 = 6,
+ DTMF_KEY_EVENT_7 = 7,
+ DTMF_KEY_EVENT_8 = 8,
+ DTMF_KEY_EVENT_9 = 9,
+ DTMF_KEY_EVENT_0 = 0,
+ DTMF_KEY_EVENT_STAR = 10,
+ DTMF_KEY_EVENT_POUND = 11,
+ DTMF_KEY_EVENT_A = 12,
+ DTMF_KEY_EVENT_B = 13,
+ DTMF_KEY_EVENT_C = 14,
+ DTMF_KEY_EVENT_D = 15,
};
/* elementfactory information */
"depth = (int) 16, "
"endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", "
"signed = (boolean) true, "
- "rate = (int) [0, MAX], "
- "channels = (int) 1")
+ "rate = (int) [0, MAX], " "channels = (int) 1")
);
static GstStaticPadTemplate gst_rtp_dtmf_depay_sink_template =
GST_DEBUG_CATEGORY_INIT (gst_rtp_dtmf_depay_debug,
- "rtpdtmfdepay", 0, "rtpdtmfdepay element");
+ "rtpdtmfdepay", 0, "rtpdtmfdepay element");
gst_element_class_set_details (element_class, &gst_rtp_dtmfdepay_details);
}
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_depay_get_property);
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_UNIT_TIME,
- g_param_spec_uint ("unit-time", "Duration unittime",
- "The smallest unit (ms) the duration must be a multiple of (0 disables it)", MIN_UNIT_TIME,
- MAX_UNIT_TIME, DEFAULT_UNIT_TIME, G_PARAM_READWRITE));
+ g_param_spec_uint ("unit-time", "Duration unittime",
+ "The smallest unit (ms) the duration must be a multiple of (0 disables it)",
+ MIN_UNIT_TIME, MAX_UNIT_TIME, DEFAULT_UNIT_TIME, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_MAX_DURATION,
- g_param_spec_uint ("max-duration", "Maximum duration",
- "The maxumimum duration (ms) of the outgoing soundpacket. "
- "(0 = no limit)", 0, G_MAXUINT, DEFAULT_MAX_DURATION,
- G_PARAM_READWRITE));
+ g_param_spec_uint ("max-duration", "Maximum duration",
+ "The maxumimum duration (ms) of the outgoing soundpacket. "
+ "(0 = no limit)", 0, G_MAXUINT, DEFAULT_MAX_DURATION,
+ G_PARAM_READWRITE));
gstbasertpdepayload_class->process =
- GST_DEBUG_FUNCPTR (gst_rtp_dtmf_depay_process);
+ GST_DEBUG_FUNCPTR (gst_rtp_dtmf_depay_process);
gstbasertpdepayload_class->set_caps =
- GST_DEBUG_FUNCPTR (gst_rtp_dtmf_depay_setcaps);
+ GST_DEBUG_FUNCPTR (gst_rtp_dtmf_depay_setcaps);
}
gst_rtp_dtmf_depay_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
- GstRtpDTMFDepay * rtpdtmfdepay;
+ GstRtpDTMFDepay *rtpdtmfdepay;
rtpdtmfdepay = GST_RTP_DTMF_DEPAY (object);
gst_rtp_dtmf_depay_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
- GstRtpDTMFDepay * rtpdtmfdepay;
+ GstRtpDTMFDepay *rtpdtmfdepay;
rtpdtmfdepay = GST_RTP_DTMF_DEPAY (object);
{
GstCaps *srccaps;
GstStructure *structure = gst_caps_get_structure (caps, 0);
- gint clock_rate = 8000; /* default */
+ gint clock_rate = 8000; /* default */
gst_structure_get_int (structure, "clock-rate", &clock_rate);
filter->clock_rate = clock_rate;
"depth", G_TYPE_INT, 16,
"endianness", G_TYPE_INT, G_BYTE_ORDER,
"signed", G_TYPE_BOOLEAN, TRUE,
- "channels", G_TYPE_INT, 1,
- "rate", G_TYPE_INT, clock_rate, NULL);
+ "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, clock_rate, NULL);
gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (filter), srccaps);
gst_caps_unref (srccaps);
}
static void
-gst_dtmf_src_generate_tone(GstRtpDTMFDepay *rtpdtmfdepay,
+gst_dtmf_src_generate_tone (GstRtpDTMFDepay * rtpdtmfdepay,
GstRTPDTMFPayload payload, GstBuffer * buffer)
{
gint16 *p;
double amplitude, f1, f2;
double volume_factor;
DTMF_KEY key = DTMF_KEYS[payload.event];
- guint32 clock_rate = 8000 /* default */;
- GstBaseRTPDepayload * depayload = GST_BASE_RTP_DEPAYLOAD (rtpdtmfdepay);
+ guint32 clock_rate = 8000 /* default */ ;
+ GstBaseRTPDepayload *depayload = GST_BASE_RTP_DEPAYLOAD (rtpdtmfdepay);
gint volume;
clock_rate = depayload->clock_rate;
/* Create a buffer for the tone */
- tone_size = (payload.duration*SAMPLE_SIZE*CHANNELS)/8;
+ tone_size = (payload.duration * SAMPLE_SIZE * CHANNELS) / 8;
GST_BUFFER_SIZE (buffer) = tone_size;
- GST_BUFFER_MALLOCDATA (buffer) = g_malloc(tone_size);
+ GST_BUFFER_MALLOCDATA (buffer) = g_malloc (tone_size);
GST_BUFFER_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer);
GST_BUFFER_DURATION (buffer) = payload.duration * GST_SECOND / clock_rate;
volume = payload.volume;
* For each sample point we calculate 'x' as the
* the amplitude value.
*/
- for (i = 0; i < (tone_size / (SAMPLE_SIZE/8)); i++) {
+ for (i = 0; i < (tone_size / (SAMPLE_SIZE / 8)); i++) {
/*
* We add the fundamental frequencies together.
*/
- f1 = sin(2 * M_PI * key.low_frequency * (rtpdtmfdepay->sample / clock_rate));
- f2 = sin(2 * M_PI * key.high_frequency * (rtpdtmfdepay->sample / clock_rate));
+ f1 = sin (2 * M_PI * key.low_frequency * (rtpdtmfdepay->sample /
+ clock_rate));
+ f2 = sin (2 * M_PI * key.high_frequency * (rtpdtmfdepay->sample /
+ clock_rate));
amplitude = (f1 + f2) / 2;
payload_len = gst_rtp_buffer_get_payload_len (buf);
payload = gst_rtp_buffer_get_payload (buf);
- if (payload_len != sizeof(GstRTPDTMFPayload) )
+ if (payload_len != sizeof (GstRTPDTMFPayload))
goto bad_packet;
memcpy (&dtmf_payload, payload, sizeof (GstRTPDTMFPayload));
dtmf_payload.duration = g_ntohs (dtmf_payload.duration);
/* clip to whole units of unit_time */
- if (rtpdtmfdepay->unit_time)
- {
+ if (rtpdtmfdepay->unit_time) {
guint unit_time_clock =
(rtpdtmfdepay->unit_time * depayload->clock_rate) / 1000;
- if (dtmf_payload.duration % unit_time_clock)
- {
+ if (dtmf_payload.duration % unit_time_clock) {
/* Make sure we don't overflow the duration */
if (dtmf_payload.duration < G_MAXUINT16 - unit_time_clock)
dtmf_payload.duration += unit_time_clock -
}
/* clip to max duration */
- if (rtpdtmfdepay->max_duration)
- {
+ if (rtpdtmfdepay->max_duration) {
guint max_duration_clock =
(rtpdtmfdepay->max_duration * depayload->clock_rate) / 1000;
"marker=%d - timestamp=%u - event=%d - duration=%d",
marker, timestamp, dtmf_payload.event, dtmf_payload.duration);
- GST_DEBUG_OBJECT (depayload, "Previous information : timestamp=%u - duration=%d",
+ GST_DEBUG_OBJECT (depayload,
+ "Previous information : timestamp=%u - duration=%d",
rtpdtmfdepay->previous_ts, rtpdtmfdepay->previous_duration);
/* First packet */
structure = gst_structure_new ("dtmf-event",
"number", G_TYPE_INT, dtmf_payload.event,
"volume", G_TYPE_INT, dtmf_payload.volume,
- "type", G_TYPE_INT, 1,
- "method", G_TYPE_INT, 1,
- NULL);
+ "type", G_TYPE_INT, 1, "method", G_TYPE_INT, 1, NULL);
if (structure) {
- dtmf_message = gst_message_new_element (GST_OBJECT (depayload), structure);
+ dtmf_message =
+ gst_message_new_element (GST_OBJECT (depayload), structure);
if (dtmf_message) {
if (!gst_element_post_message (GST_ELEMENT (depayload), dtmf_message)) {
- GST_ERROR_OBJECT (depayload, "Unable to send dtmf-event message to bus");
+ GST_ERROR_OBJECT (depayload,
+ "Unable to send dtmf-event message to bus");
}
} else {
GST_ERROR_OBJECT (depayload, "Unable to create dtmf-event message");
/* If late or duplicate packet (like the redundant end packet). Ignore */
if (dtmf_payload.duration > 0) {
outbuf = gst_buffer_new ();
- gst_dtmf_src_generate_tone(rtpdtmfdepay, dtmf_payload, outbuf);
+ gst_dtmf_src_generate_tone (rtpdtmfdepay, dtmf_payload, outbuf);
GST_BUFFER_TIMESTAMP (outbuf) = rtpdtmfdepay->first_gst_ts +
GST_SECOND / depayload->clock_rate;
GST_BUFFER_OFFSET (outbuf) =
(rtpdtmfdepay->previous_duration - dtmf_payload.duration) *
- GST_SECOND / depayload->clock_rate;
+ GST_SECOND / depayload->clock_rate;
GST_BUFFER_OFFSET_END (outbuf) = rtpdtmfdepay->previous_duration *
- GST_SECOND / depayload->clock_rate;
+ GST_SECOND / depayload->clock_rate;
GST_DEBUG_OBJECT (depayload, "timestamp : %llu - time %" GST_TIME_FORMAT,
GST_BUFFER_TIMESTAMP (buf), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
return gst_element_register (plugin, "rtpdtmfdepay",
GST_RANK_MARGINAL, GST_TYPE_RTP_DTMF_DEPAY);
}
-
#include "gstrtpdtmfcommon.h"
G_BEGIN_DECLS
-
#define GST_TYPE_RTP_DTMF_DEPAY \
(gst_rtp_dtmf_depay_get_type())
#define GST_RTP_DTMF_DEPAY(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_DTMF_DEPAY))
#define GST_IS_RTP_DTMF_DEPAY_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_DTMF_DEPAY))
-
-
typedef struct _GstRtpDTMFDepay GstRtpDTMFDepay;
typedef struct _GstRtpDTMFDepayClass GstRtpDTMFDepayClass;
struct _GstRtpDTMFDepay
{
- GstBaseRTPDepayload depayload;
- double sample;
- guint32 previous_ts;
- guint16 previous_duration;
- GstClockTime first_gst_ts;
+ GstBaseRTPDepayload depayload;
+ double sample;
+ guint32 previous_ts;
+ guint16 previous_duration;
+ GstClockTime first_gst_ts;
guint unit_time;
guint max_duration;
};
gboolean gst_rtp_dtmf_depay_plugin_init (GstPlugin * plugin);
G_END_DECLS
-
#endif /* __GST_RTP_DTMF_DEPAY_H__ */
#include "gstrtpdtmfsrc.h"
#define GST_RTP_DTMF_TYPE_EVENT 1
-#define DEFAULT_PACKET_INTERVAL 50 /* ms */
-#define MIN_PACKET_INTERVAL 10 /* ms */
-#define MAX_PACKET_INTERVAL 50 /* ms */
+#define DEFAULT_PACKET_INTERVAL 50 /* ms */
+#define MIN_PACKET_INTERVAL 10 /* ms */
+#define MAX_PACKET_INTERVAL 50 /* ms */
#define DEFAULT_SSRC -1
#define DEFAULT_PT 96
#define DEFAULT_TIMESTAMP_OFFSET -1
#define MIN_VOLUME 0
#define MAX_VOLUME 36
-#define MIN_INTER_DIGIT_INTERVAL 50 /* ms */
-#define MIN_PULSE_DURATION 70 /* ms */
+#define MIN_INTER_DIGIT_INTERVAL 50 /* ms */
+#define MIN_PULSE_DURATION 70 /* ms */
#define DEFAULT_PACKET_REDUNDANCY 1
#define MIN_PACKET_REDUNDANCY 1
"ssrc = (int) [ 0, MAX ], "
"encoding-name = (string) \"TELEPHONE-EVENT\"")
/* "events = (string) \"0-15\" */
-
);
const GValue * value, GParamSpec * pspec);
static void gst_rtp_dtmf_src_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
-static gboolean gst_rtp_dtmf_src_handle_event (GstBaseSrc *basesrc,
+static gboolean gst_rtp_dtmf_src_handle_event (GstBaseSrc * basesrc,
GstEvent * event);
static GstStateChangeReturn gst_rtp_dtmf_src_change_state (GstElement * element,
GstStateChange transition);
-static void gst_rtp_dtmf_src_add_start_event (GstRTPDTMFSrc *dtmfsrc,
+static void gst_rtp_dtmf_src_add_start_event (GstRTPDTMFSrc * dtmfsrc,
gint event_number, gint event_volume);
-static void gst_rtp_dtmf_src_add_stop_event (GstRTPDTMFSrc *dtmfsrc);
+static void gst_rtp_dtmf_src_add_stop_event (GstRTPDTMFSrc * dtmfsrc);
-static gboolean gst_rtp_dtmf_src_unlock (GstBaseSrc *src);
-static gboolean gst_rtp_dtmf_src_unlock_stop (GstBaseSrc *src);
+static gboolean gst_rtp_dtmf_src_unlock (GstBaseSrc * src);
+static gboolean gst_rtp_dtmf_src_unlock_stop (GstBaseSrc * src);
static GstFlowReturn gst_rtp_dtmf_src_create (GstBaseSrc * basesrc,
guint64 offset, guint length, GstBuffer ** buffer);
static gboolean gst_rtp_dtmf_src_negotiate (GstBaseSrc * basesrc);
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
GST_DEBUG_CATEGORY_INIT (gst_rtp_dtmf_src_debug,
- "rtpdtmfsrc", 0, "rtpdtmfsrc element");
+ "rtpdtmfsrc", 0, "rtpdtmfsrc element");
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_rtp_dtmf_src_template));
gstelement_class->change_state =
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_change_state);
- gstbasesrc_class->unlock =
- GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_unlock);
+ gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_unlock);
gstbasesrc_class->unlock_stop =
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_unlock_stop);
- gstbasesrc_class->event =
- GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_handle_event);
- gstbasesrc_class->create =
- GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_create);
- gstbasesrc_class->negotiate =
- GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_negotiate);
+ gstbasesrc_class->event = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_handle_event);
+ gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_create);
+ gstbasesrc_class->negotiate = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_negotiate);
}
static void
}
static gboolean
-gst_rtp_dtmf_src_handle_dtmf_event (GstRTPDTMFSrc *dtmfsrc,
- const GstStructure * event_structure)
+gst_rtp_dtmf_src_handle_dtmf_event (GstRTPDTMFSrc * dtmfsrc,
+ const GstStructure * event_structure)
{
gint event_type;
gboolean start;
gint method;
if (!gst_structure_get_int (event_structure, "type", &event_type) ||
- !gst_structure_get_boolean (event_structure, "start", &start) ||
- event_type != GST_RTP_DTMF_TYPE_EVENT)
+ !gst_structure_get_boolean (event_structure, "start", &start) ||
+ event_type != GST_RTP_DTMF_TYPE_EVENT)
goto failure;
if (gst_structure_get_int (event_structure, "method", &method)) {
gint event_volume;
if (!gst_structure_get_int (event_structure, "number", &event_number) ||
- !gst_structure_get_int (event_structure, "volume", &event_volume))
+ !gst_structure_get_int (event_structure, "volume", &event_volume))
goto failure;
GST_DEBUG_OBJECT (dtmfsrc, "Received start event %d with volume %d",
- event_number, event_volume);
+ event_number, event_volume);
gst_rtp_dtmf_src_add_start_event (dtmfsrc, event_number, event_volume);
}
}
static gboolean
-gst_rtp_dtmf_src_handle_custom_upstream (GstRTPDTMFSrc *dtmfsrc,
+gst_rtp_dtmf_src_handle_custom_upstream (GstRTPDTMFSrc * dtmfsrc,
GstEvent * event)
{
gboolean result = FALSE;
}
static gboolean
-gst_rtp_dtmf_src_handle_event (GstBaseSrc *basesrc, GstEvent * event)
+gst_rtp_dtmf_src_handle_event (GstBaseSrc * basesrc, GstEvent * event)
{
GstRTPDTMFSrc *dtmfsrc;
gboolean result = FALSE;
}
static void
-gst_rtp_dtmf_src_set_stream_lock (GstRTPDTMFSrc *dtmfsrc, gboolean lock)
+gst_rtp_dtmf_src_set_stream_lock (GstRTPDTMFSrc * dtmfsrc, gboolean lock)
{
- GstEvent *event;
- GstStructure *structure;
+ GstEvent *event;
+ GstStructure *structure;
- structure = gst_structure_new ("stream-lock",
- "lock", G_TYPE_BOOLEAN, lock, NULL);
+ structure = gst_structure_new ("stream-lock",
+ "lock", G_TYPE_BOOLEAN, lock, NULL);
- event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_OOB, structure);
- if (!gst_pad_push_event (GST_BASE_SRC_PAD (dtmfsrc), event)) {
- GST_WARNING_OBJECT (dtmfsrc, "stream-lock event not handled");
- }
+ event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_OOB, structure);
+ if (!gst_pad_push_event (GST_BASE_SRC_PAD (dtmfsrc), event)) {
+ GST_WARNING_OBJECT (dtmfsrc, "stream-lock event not handled");
+ }
}
static void
-gst_rtp_dtmf_prepare_timestamps (GstRTPDTMFSrc *dtmfsrc)
+gst_rtp_dtmf_prepare_timestamps (GstRTPDTMFSrc * dtmfsrc)
{
GstClock *clock;
GstClockTime base_time;
}
dtmfsrc->rtp_timestamp = dtmfsrc->ts_base +
- gst_util_uint64_scale_int (
- gst_segment_to_running_time (&GST_BASE_SRC (dtmfsrc)->segment,
- GST_FORMAT_TIME, dtmfsrc->timestamp),
- dtmfsrc->clock_rate, GST_SECOND);
+ gst_util_uint64_scale_int (gst_segment_to_running_time (&GST_BASE_SRC
+ (dtmfsrc)->segment, GST_FORMAT_TIME, dtmfsrc->timestamp),
+ dtmfsrc->clock_rate, GST_SECOND);
}
static void
-gst_rtp_dtmf_src_add_start_event (GstRTPDTMFSrc *dtmfsrc, gint event_number,
+gst_rtp_dtmf_src_add_start_event (GstRTPDTMFSrc * dtmfsrc, gint event_number,
gint event_volume)
{
- GstRTPDTMFSrcEvent * event = g_malloc (sizeof(GstRTPDTMFSrcEvent));
+ GstRTPDTMFSrcEvent *event = g_malloc (sizeof (GstRTPDTMFSrcEvent));
event->event_type = RTP_DTMF_EVENT_TYPE_START;
event->payload = g_new0 (GstRTPDTMFPayload, 1);
}
static void
-gst_rtp_dtmf_src_add_stop_event (GstRTPDTMFSrc *dtmfsrc)
+gst_rtp_dtmf_src_add_stop_event (GstRTPDTMFSrc * dtmfsrc)
{
- GstRTPDTMFSrcEvent * event = g_malloc (sizeof(GstRTPDTMFSrcEvent));
+ GstRTPDTMFSrcEvent *event = g_malloc (sizeof (GstRTPDTMFSrcEvent));
event->event_type = RTP_DTMF_EVENT_TYPE_STOP;
g_async_queue_push (dtmfsrc->event_queue, event);
static void
-gst_rtp_dtmf_prepare_rtp_headers (GstRTPDTMFSrc *dtmfsrc, GstBuffer *buf)
+gst_rtp_dtmf_prepare_rtp_headers (GstRTPDTMFSrc * dtmfsrc, GstBuffer * buf)
{
gst_rtp_buffer_set_ssrc (buf, dtmfsrc->current_ssrc);
gst_rtp_buffer_set_payload_type (buf, dtmfsrc->pt);
}
static void
-gst_rtp_dtmf_prepare_buffer_data (GstRTPDTMFSrc *dtmfsrc, GstBuffer *buf)
+gst_rtp_dtmf_prepare_buffer_data (GstRTPDTMFSrc * dtmfsrc, GstBuffer * buf)
{
GstRTPDTMFPayload *payload;
* if its the end of the event
*/
if (payload->e &&
- payload->duration < MIN_PULSE_DURATION * dtmfsrc->clock_rate / 1000 )
+ payload->duration < MIN_PULSE_DURATION * dtmfsrc->clock_rate / 1000)
payload->duration = MIN_PULSE_DURATION * dtmfsrc->clock_rate / 1000;
payload->duration = g_htons (payload->duration);
}
static GstBuffer *
-gst_rtp_dtmf_src_create_next_rtp_packet (GstRTPDTMFSrc *dtmfsrc)
+gst_rtp_dtmf_src_create_next_rtp_packet (GstRTPDTMFSrc * dtmfsrc)
{
GstBuffer *buf = NULL;
guint length, GstBuffer ** buffer)
{
GstRTPDTMFSrcEvent *event;
- GstRTPDTMFSrc * dtmfsrc;
+ GstRTPDTMFSrc *dtmfsrc;
GstClock *clock;
GstClockID *clockid;
GstClockReturn clockret;
g_free (event);
} else if (!dtmfsrc->first_packet && !dtmfsrc->last_packet &&
- (dtmfsrc->timestamp - dtmfsrc->start_timestamp)/GST_MSECOND >=
+ (dtmfsrc->timestamp - dtmfsrc->start_timestamp) / GST_MSECOND >=
MIN_PULSE_DURATION) {
GST_DEBUG_OBJECT (dtmfsrc, "try popping");
event = g_async_queue_try_pop (dtmfsrc->event_queue);
GST_OBJECT_LOCK (dtmfsrc);
if (dtmfsrc->paused)
clockret = GST_CLOCK_UNSCHEDULED;
- } else {
+ } else {
clockret = GST_CLOCK_UNSCHEDULED;
}
gst_clock_id_unref (clockid);
goto paused;
}
- send_last:
+send_last:
if (dtmfsrc->dirty)
if (!gst_rtp_dtmf_src_negotiate (basesrc))
return GST_FLOW_OK;
- paused_locked:
+paused_locked:
GST_OBJECT_UNLOCK (dtmfsrc);
- paused:
+paused:
if (dtmfsrc->payload) {
dtmfsrc->first_packet = FALSE;
} else {
if (gst_structure_has_field (s, "payload")) {
/* can only fixate if there is a field */
- gst_structure_fixate_field_nearest_int (s, "payload",
- dtmfsrc->pt);
+ gst_structure_fixate_field_nearest_int (s, "payload", dtmfsrc->pt);
gst_structure_get_int (s, "payload", &pt);
GST_LOG_OBJECT (dtmfsrc, "using peer pt %d", pt);
} else {
}
}
- if (gst_structure_get_int (s, "clock-rate", &clock_rate))
- {
+ if (gst_structure_get_int (s, "clock-rate", &clock_rate)) {
dtmfsrc->clock_rate = clock_rate;
GST_LOG_OBJECT (dtmfsrc, "using clock-rate from caps %d",
dtmfsrc->clock_rate);
GST_LOG_OBJECT (dtmfsrc, "using existing clock-rate %d",
dtmfsrc->clock_rate);
}
- gst_structure_set (s, "clock-rate", G_TYPE_INT, dtmfsrc->clock_rate,
- NULL);
+ gst_structure_set (s, "clock-rate", G_TYPE_INT, dtmfsrc->clock_rate, NULL);
if (gst_structure_has_field_typed (s, "ssrc", G_TYPE_UINT)) {
static void
-gst_rtp_dtmf_src_ready_to_paused (GstRTPDTMFSrc *dtmfsrc)
+gst_rtp_dtmf_src_ready_to_paused (GstRTPDTMFSrc * dtmfsrc)
{
if (dtmfsrc->ssrc == -1)
dtmfsrc->current_ssrc = g_random_int ();
GstRTPDTMFSrc *dtmfsrc;
GstStateChangeReturn result;
gboolean no_preroll = FALSE;
- GstRTPDTMFSrcEvent *event= NULL;
+ GstRTPDTMFSrcEvent *event = NULL;
dtmfsrc = GST_RTP_DTMF_SRC (element);
break;
case GST_STATE_CHANGE_PAUSED_TO_READY:
- /* Flushing the event queue */
+ /* Flushing the event queue */
while ((event = g_async_queue_try_pop (dtmfsrc->event_queue)) != NULL)
g_free (event);
static gboolean
-gst_rtp_dtmf_src_unlock (GstBaseSrc *src) {
+gst_rtp_dtmf_src_unlock (GstBaseSrc * src)
+{
GstRTPDTMFSrc *dtmfsrc = GST_RTP_DTMF_SRC (src);
GstRTPDTMFSrcEvent *event = NULL;
GST_OBJECT_UNLOCK (dtmfsrc);
GST_DEBUG_OBJECT (dtmfsrc, "Pushing the PAUSE_TASK event on unlock request");
- event = g_malloc (sizeof(GstRTPDTMFSrcEvent));
+ event = g_malloc (sizeof (GstRTPDTMFSrcEvent));
event->event_type = RTP_DTMF_EVENT_TYPE_PAUSE_TASK;
g_async_queue_push (dtmfsrc->event_queue, event);
static gboolean
-gst_rtp_dtmf_src_unlock_stop (GstBaseSrc *src) {
+gst_rtp_dtmf_src_unlock_stop (GstBaseSrc * src)
+{
GstRTPDTMFSrc *dtmfsrc = GST_RTP_DTMF_SRC (src);
GST_DEBUG_OBJECT (dtmfsrc, "Unlock stopped");
#include "gstrtpdtmfcommon.h"
G_BEGIN_DECLS
-
#define GST_TYPE_RTP_DTMF_SRC (gst_rtp_dtmf_src_get_type())
#define GST_RTP_DTMF_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RTP_DTMF_SRC,GstRTPDTMFSrc))
#define GST_RTP_DTMF_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RTP_DTMF_SRC,GstRTPDTMFSrcClass))
#define GST_IS_RTP_DTMF_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_DTMF_SRC))
#define GST_IS_RTP_DTMF_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_DTMF_SRC))
#define GST_RTP_DTMF_SRC_CAST(obj) ((GstRTPDTMFSrc *)(obj))
-
-
typedef struct _GstRTPDTMFSrc GstRTPDTMFSrc;
typedef struct _GstRTPDTMFSrcClass GstRTPDTMFSrcClass;
-enum _GstRTPDTMFEventType {
+enum _GstRTPDTMFEventType
+{
RTP_DTMF_EVENT_TYPE_START,
RTP_DTMF_EVENT_TYPE_STOP,
RTP_DTMF_EVENT_TYPE_PAUSE_TASK
typedef enum _GstRTPDTMFEventType GstRTPDTMFEventType;
-struct _GstRTPDTMFSrcEvent {
- GstRTPDTMFEventType event_type;
- GstRTPDTMFPayload* payload;
+struct _GstRTPDTMFSrcEvent
+{
+ GstRTPDTMFEventType event_type;
+ GstRTPDTMFPayload *payload;
};
typedef struct _GstRTPDTMFSrcEvent GstRTPDTMFSrcEvent;
*
* The opaque #GstRTPDTMFSrc data structure.
*/
-struct _GstRTPDTMFSrc {
- GstBaseSrc basesrc;
-
- GAsyncQueue* event_queue;
- GstClockID clockid;
- gboolean paused;
- GstRTPDTMFPayload* payload;
-
- GstClockTime timestamp;
- GstClockTime start_timestamp;
- gboolean first_packet;
- gboolean last_packet;
- guint32 ts_base;
- guint16 seqnum_base;
- gint16 seqnum_offset;
- guint16 seqnum;
- gint32 ts_offset;
- guint32 rtp_timestamp;
- guint pt;
- guint ssrc;
- guint current_ssrc;
- guint16 interval;
- guint16 packet_redundancy;
- guint32 clock_rate;
-
- gboolean dirty;
- guint16 redundancy_count;
+struct _GstRTPDTMFSrc
+{
+ GstBaseSrc basesrc;
+
+ GAsyncQueue *event_queue;
+ GstClockID clockid;
+ gboolean paused;
+ GstRTPDTMFPayload *payload;
+
+ GstClockTime timestamp;
+ GstClockTime start_timestamp;
+ gboolean first_packet;
+ gboolean last_packet;
+ guint32 ts_base;
+ guint16 seqnum_base;
+ gint16 seqnum_offset;
+ guint16 seqnum;
+ gint32 ts_offset;
+ guint32 rtp_timestamp;
+ guint pt;
+ guint ssrc;
+ guint current_ssrc;
+ guint16 interval;
+ guint16 packet_redundancy;
+ guint32 clock_rate;
+
+ gboolean dirty;
+ guint16 redundancy_count;
};
-struct _GstRTPDTMFSrcClass {
+struct _GstRTPDTMFSrcClass
+{
GstBaseSrcClass parent_class;
};
G_END_DECLS
-
#endif /* __GST_RTP_DTMF_SRC_H__ */