Re-indent to Gst style

This commit is contained in:
Olivier Crête 2009-02-20 17:37:43 -05:00 committed by Edward Hervey
parent d89e80f1c9
commit 22b1337ed7
8 changed files with 324 additions and 350 deletions

View file

@ -26,6 +26,4 @@ plugin_init (GstPlugin * plugin)
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR, GST_VERSION_MINOR,
"dtmf", "dtmf", "DTMF plugins", plugin_init, "0.1", "LGPL", "DTMF", "");
"DTMF plugins",
plugin_init, "0.1" , "LGPL", "DTMF", "");

View file

@ -142,9 +142,9 @@
#include "gstdtmfsrc.h" #include "gstdtmfsrc.h"
#define GST_TONE_DTMF_TYPE_EVENT 1 #define GST_TONE_DTMF_TYPE_EVENT 1
#define DEFAULT_PACKET_INTERVAL 50 /* ms */ #define DEFAULT_PACKET_INTERVAL 50 /* ms */
#define MIN_PACKET_INTERVAL 10 /* ms */ #define MIN_PACKET_INTERVAL 10 /* ms */
#define MAX_PACKET_INTERVAL 50 /* ms */ #define MAX_PACKET_INTERVAL 50 /* ms */
#define DEFAULT_SAMPLE_RATE 8000 #define DEFAULT_SAMPLE_RATE 8000
#define SAMPLE_SIZE 16 #define SAMPLE_SIZE 16
#define CHANNELS 1 #define CHANNELS 1
@ -157,51 +157,53 @@
#define MIN_DUTY_CYCLE (MIN_INTER_DIGIT_INTERVAL + MIN_PULSE_DURATION) #define MIN_DUTY_CYCLE (MIN_INTER_DIGIT_INTERVAL + MIN_PULSE_DURATION)
typedef struct st_dtmf_key { typedef struct st_dtmf_key
char *event_name; {
int event_encoding; char *event_name;
float low_frequency; int event_encoding;
float high_frequency; float low_frequency;
float high_frequency;
} DTMF_KEY; } DTMF_KEY;
static const DTMF_KEY DTMF_KEYS[] = { static const DTMF_KEY DTMF_KEYS[] = {
{"DTMF_KEY_EVENT_0", 0, 941, 1336}, {"DTMF_KEY_EVENT_0", 0, 941, 1336},
{"DTMF_KEY_EVENT_1", 1, 697, 1209}, {"DTMF_KEY_EVENT_1", 1, 697, 1209},
{"DTMF_KEY_EVENT_2", 2, 697, 1336}, {"DTMF_KEY_EVENT_2", 2, 697, 1336},
{"DTMF_KEY_EVENT_3", 3, 697, 1477}, {"DTMF_KEY_EVENT_3", 3, 697, 1477},
{"DTMF_KEY_EVENT_4", 4, 770, 1209}, {"DTMF_KEY_EVENT_4", 4, 770, 1209},
{"DTMF_KEY_EVENT_5", 5, 770, 1336}, {"DTMF_KEY_EVENT_5", 5, 770, 1336},
{"DTMF_KEY_EVENT_6", 6, 770, 1477}, {"DTMF_KEY_EVENT_6", 6, 770, 1477},
{"DTMF_KEY_EVENT_7", 7, 852, 1209}, {"DTMF_KEY_EVENT_7", 7, 852, 1209},
{"DTMF_KEY_EVENT_8", 8, 852, 1336}, {"DTMF_KEY_EVENT_8", 8, 852, 1336},
{"DTMF_KEY_EVENT_9", 9, 852, 1477}, {"DTMF_KEY_EVENT_9", 9, 852, 1477},
{"DTMF_KEY_EVENT_S", 10, 941, 1209}, {"DTMF_KEY_EVENT_S", 10, 941, 1209},
{"DTMF_KEY_EVENT_P", 11, 941, 1477}, {"DTMF_KEY_EVENT_P", 11, 941, 1477},
{"DTMF_KEY_EVENT_A", 12, 697, 1633}, {"DTMF_KEY_EVENT_A", 12, 697, 1633},
{"DTMF_KEY_EVENT_B", 13, 770, 1633}, {"DTMF_KEY_EVENT_B", 13, 770, 1633},
{"DTMF_KEY_EVENT_C", 14, 852, 1633}, {"DTMF_KEY_EVENT_C", 14, 852, 1633},
{"DTMF_KEY_EVENT_D", 15, 941, 1633}, {"DTMF_KEY_EVENT_D", 15, 941, 1633},
}; };
#define MAX_DTMF_EVENTS 16 #define MAX_DTMF_EVENTS 16
enum { enum
DTMF_KEY_EVENT_1 = 1, {
DTMF_KEY_EVENT_2 = 2, DTMF_KEY_EVENT_1 = 1,
DTMF_KEY_EVENT_3 = 3, DTMF_KEY_EVENT_2 = 2,
DTMF_KEY_EVENT_4 = 4, DTMF_KEY_EVENT_3 = 3,
DTMF_KEY_EVENT_5 = 5, DTMF_KEY_EVENT_4 = 4,
DTMF_KEY_EVENT_6 = 6, DTMF_KEY_EVENT_5 = 5,
DTMF_KEY_EVENT_7 = 7, DTMF_KEY_EVENT_6 = 6,
DTMF_KEY_EVENT_8 = 8, DTMF_KEY_EVENT_7 = 7,
DTMF_KEY_EVENT_9 = 9, DTMF_KEY_EVENT_8 = 8,
DTMF_KEY_EVENT_0 = 0, DTMF_KEY_EVENT_9 = 9,
DTMF_KEY_EVENT_STAR = 10, DTMF_KEY_EVENT_0 = 0,
DTMF_KEY_EVENT_POUND = 11, DTMF_KEY_EVENT_STAR = 10,
DTMF_KEY_EVENT_A = 12, DTMF_KEY_EVENT_POUND = 11,
DTMF_KEY_EVENT_B = 13, DTMF_KEY_EVENT_A = 12,
DTMF_KEY_EVENT_C = 14, DTMF_KEY_EVENT_B = 13,
DTMF_KEY_EVENT_D = 15, DTMF_KEY_EVENT_C = 14,
DTMF_KEY_EVENT_D = 15,
}; };
/* elementfactory information */ /* elementfactory information */
@ -228,9 +230,7 @@ GST_STATIC_PAD_TEMPLATE ("src",
"width = (int) 16, " "width = (int) 16, "
"depth = (int) 16, " "depth = (int) 16, "
"endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", " "endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", "
"signed = (bool) true, " "signed = (bool) true, " "rate = (int) 8000, " "channels = (int) 1")
"rate = (int) 8000, "
"channels = (int) 1")
); );
GST_BOILERPLATE (GstDTMFSrc, gst_dtmf_src, GstBaseSrc, GST_TYPE_BASE_SRC); GST_BOILERPLATE (GstDTMFSrc, gst_dtmf_src, GstBaseSrc, GST_TYPE_BASE_SRC);
@ -241,18 +241,18 @@ static void gst_dtmf_src_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec); const GValue * value, GParamSpec * pspec);
static void gst_dtmf_src_get_property (GObject * object, guint prop_id, static void gst_dtmf_src_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec); 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, static GstStateChangeReturn gst_dtmf_src_change_state (GstElement * element,
GstStateChange transition); GstStateChange transition);
static GstFlowReturn gst_dtmf_src_create (GstBaseSrc * basesrc, static GstFlowReturn gst_dtmf_src_create (GstBaseSrc * basesrc,
guint64 offset, guint length, GstBuffer ** buffer); 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); 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 gboolean gst_dtmf_src_negotiate (GstBaseSrc * basesrc);
static void static void
@ -260,8 +260,7 @@ gst_dtmf_src_base_init (gpointer g_class)
{ {
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
GST_DEBUG_CATEGORY_INIT (gst_dtmf_src_debug, GST_DEBUG_CATEGORY_INIT (gst_dtmf_src_debug, "dtmfsrc", 0, "dtmfsrc element");
"dtmfsrc", 0, "dtmfsrc element");
gst_element_class_add_pad_template (element_class, gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_dtmf_src_template)); gst_static_pad_template_get (&gst_dtmf_src_template));
@ -282,10 +281,8 @@ gst_dtmf_src_class_init (GstDTMFSrcClass * klass)
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_dtmf_src_finalize); gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_dtmf_src_finalize);
gobject_class->set_property = gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_dtmf_src_set_property);
GST_DEBUG_FUNCPTR (gst_dtmf_src_set_property); gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_dtmf_src_get_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_object_class_install_property (G_OBJECT_CLASS (klass), PROP_INTERVAL,
g_param_spec_uint ("interval", "Interval between tone packets", g_param_spec_uint ("interval", "Interval between tone packets",
@ -294,22 +291,17 @@ gst_dtmf_src_class_init (GstDTMFSrcClass * klass)
gstelement_class->change_state = gstelement_class->change_state =
GST_DEBUG_FUNCPTR (gst_dtmf_src_change_state); GST_DEBUG_FUNCPTR (gst_dtmf_src_change_state);
gstbasesrc_class->unlock = gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_dtmf_src_unlock);
GST_DEBUG_FUNCPTR (gst_dtmf_src_unlock); gstbasesrc_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_dtmf_src_unlock_stop);
gstbasesrc_class->unlock_stop =
GST_DEBUG_FUNCPTR (gst_dtmf_src_unlock_stop);
gstbasesrc_class->event = gstbasesrc_class->event = GST_DEBUG_FUNCPTR (gst_dtmf_src_handle_event);
GST_DEBUG_FUNCPTR (gst_dtmf_src_handle_event); gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_dtmf_src_create);
gstbasesrc_class->create = gstbasesrc_class->negotiate = GST_DEBUG_FUNCPTR (gst_dtmf_src_negotiate);
GST_DEBUG_FUNCPTR (gst_dtmf_src_create);
gstbasesrc_class->negotiate =
GST_DEBUG_FUNCPTR (gst_dtmf_src_negotiate);
} }
static void static void
gst_dtmf_src_init (GstDTMFSrc * dtmfsrc, GstDTMFSrcClass *g_class) gst_dtmf_src_init (GstDTMFSrc * dtmfsrc, GstDTMFSrcClass * g_class)
{ {
/* we operate in time */ /* we operate in time */
gst_base_src_set_format (GST_BASE_SRC (dtmfsrc), GST_FORMAT_TIME); gst_base_src_set_format (GST_BASE_SRC (dtmfsrc), GST_FORMAT_TIME);
@ -341,8 +333,8 @@ gst_dtmf_src_finalize (GObject * object)
} }
static gboolean static gboolean
gst_dtmf_src_handle_dtmf_event (GstDTMFSrc *dtmfsrc, gst_dtmf_src_handle_dtmf_event (GstDTMFSrc * dtmfsrc,
const GstStructure * event_structure) const GstStructure * event_structure)
{ {
gint event_type; gint event_type;
gboolean start; gboolean start;
@ -364,11 +356,11 @@ gst_dtmf_src_handle_dtmf_event (GstDTMFSrc *dtmfsrc,
gint event_volume; gint event_volume;
if (!gst_structure_get_int (event_structure, "number", &event_number) || 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; goto failure;
GST_DEBUG_OBJECT (dtmfsrc, "Received start event %d with volume %d", 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); gst_dtmf_src_add_start_event (dtmfsrc, event_number, event_volume);
} }
@ -383,8 +375,7 @@ failure:
} }
static gboolean static gboolean
gst_dtmf_src_handle_custom_upstream (GstDTMFSrc *dtmfsrc, gst_dtmf_src_handle_custom_upstream (GstDTMFSrc * dtmfsrc, GstEvent * event)
GstEvent * event)
{ {
gboolean result = FALSE; gboolean result = FALSE;
const GstStructure *structure; const GstStructure *structure;
@ -459,23 +450,23 @@ gst_dtmf_src_get_property (GObject * object, guint prop_id, GValue * value,
} }
static void 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); GstPad *srcpad = GST_BASE_SRC_PAD (dtmfsrc);
GstEvent *event; GstEvent *event;
GstStructure *structure; GstStructure *structure;
structure = gst_structure_new ("stream-lock", structure = gst_structure_new ("stream-lock",
"lock", G_TYPE_BOOLEAN, lock, NULL); "lock", G_TYPE_BOOLEAN, lock, NULL);
event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_OOB, structure); event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_OOB, structure);
if (!gst_pad_push_event (srcpad, event)) { if (!gst_pad_push_event (srcpad, event)) {
GST_WARNING_OBJECT (dtmfsrc, "stream-lock event not handled"); GST_WARNING_OBJECT (dtmfsrc, "stream-lock event not handled");
} }
} }
static void static void
gst_dtmf_prepare_timestamps (GstDTMFSrc *dtmfsrc) gst_dtmf_prepare_timestamps (GstDTMFSrc * dtmfsrc)
{ {
GstClock *clock; GstClock *clock;
GstClockTime base_time; GstClockTime base_time;
@ -499,11 +490,11 @@ gst_dtmf_prepare_timestamps (GstDTMFSrc *dtmfsrc)
} }
static void 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) gint event_volume)
{ {
GstDTMFSrcEvent * event = g_malloc (sizeof(GstDTMFSrcEvent)); GstDTMFSrcEvent *event = g_malloc (sizeof (GstDTMFSrcEvent));
event->event_type = DTMF_EVENT_TYPE_START; event->event_type = DTMF_EVENT_TYPE_START;
event->sample = 0; event->sample = 0;
event->event_number = CLAMP (event_number, MIN_EVENT, MAX_EVENT); event->event_number = CLAMP (event_number, MIN_EVENT, MAX_EVENT);
@ -513,10 +504,10 @@ gst_dtmf_src_add_start_event (GstDTMFSrc *dtmfsrc, gint event_number,
} }
static void 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->event_type = DTMF_EVENT_TYPE_STOP;
event->sample = 0; event->sample = 0;
event->event_number = 0; event->event_number = 0;
@ -526,22 +517,22 @@ gst_dtmf_src_add_stop_event (GstDTMFSrc *dtmfsrc)
} }
static void static void
gst_dtmf_src_generate_silence(GstBuffer * buffer, float duration, gst_dtmf_src_generate_silence (GstBuffer * buffer, float duration,
gint sample_rate) gint sample_rate)
{ {
gint buf_size; gint buf_size;
/* Create a buffer with data set to 0 */ /* 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_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); GST_BUFFER_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer);
} }
static void static void
gst_dtmf_src_generate_tone(GstDTMFSrcEvent *event, DTMF_KEY key, float duration, gst_dtmf_src_generate_tone (GstDTMFSrcEvent * event, DTMF_KEY key,
GstBuffer * buffer, gint sample_rate) float duration, GstBuffer * buffer, gint sample_rate)
{ {
gint16 *p; gint16 *p;
gint tone_size; gint tone_size;
@ -550,9 +541,9 @@ gst_dtmf_src_generate_tone(GstDTMFSrcEvent *event, DTMF_KEY key, float duration,
double volume_factor; double volume_factor;
/* Create a buffer for the tone */ /* 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_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_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer);
p = (gint16 *) GST_BUFFER_MALLOCDATA (buffer); p = (gint16 *) GST_BUFFER_MALLOCDATA (buffer);
@ -563,12 +554,12 @@ gst_dtmf_src_generate_tone(GstDTMFSrcEvent *event, DTMF_KEY key, float duration,
* For each sample point we calculate 'x' as the * For each sample point we calculate 'x' as the
* the amplitude value. * 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. * We add the fundamental frequencies together.
*/ */
f1 = sin(2 * M_PI * key.low_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)); f2 = sin (2 * M_PI * key.high_frequency * (event->sample / sample_rate));
amplitude = (f1 + f2) / 2; amplitude = (f1 + f2) / 2;
@ -588,8 +579,8 @@ gst_dtmf_src_generate_tone(GstDTMFSrcEvent *event, DTMF_KEY key, float duration,
static GstBuffer * static GstBuffer *
gst_dtmf_src_create_next_tone_packet (GstDTMFSrc *dtmfsrc, gst_dtmf_src_create_next_tone_packet (GstDTMFSrc * dtmfsrc,
GstDTMFSrcEvent *event) GstDTMFSrcEvent * event)
{ {
GstBuffer *buf = NULL; GstBuffer *buf = NULL;
gboolean send_silence = FALSE; gboolean send_silence = FALSE;
@ -606,12 +597,12 @@ gst_dtmf_src_create_next_tone_packet (GstDTMFSrc *dtmfsrc,
} }
if (send_silence) { if (send_silence) {
GST_DEBUG_OBJECT (dtmfsrc, "Generating silence"); GST_DEBUG_OBJECT (dtmfsrc, "Generating silence");
gst_dtmf_src_generate_silence (buf, dtmfsrc->interval, gst_dtmf_src_generate_silence (buf, dtmfsrc->interval,
dtmfsrc->sample_rate); dtmfsrc->sample_rate);
} else { } else {
GST_DEBUG_OBJECT (dtmfsrc, "Generating tone"); GST_DEBUG_OBJECT (dtmfsrc, "Generating tone");
gst_dtmf_src_generate_tone(event, DTMF_KEYS[event->event_number], gst_dtmf_src_generate_tone (event, DTMF_KEYS[event->event_number],
dtmfsrc->interval, buf, dtmfsrc->sample_rate); dtmfsrc->interval, buf, dtmfsrc->sample_rate);
} }
event->packet_count++; event->packet_count++;
@ -634,7 +625,7 @@ gst_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
{ {
GstBuffer *buf = NULL; GstBuffer *buf = NULL;
GstDTMFSrcEvent *event; GstDTMFSrcEvent *event;
GstDTMFSrc * dtmfsrc; GstDTMFSrc *dtmfsrc;
GstClock *clock; GstClock *clock;
GstClockID *clockid; GstClockID *clockid;
GstClockReturn clockret; GstClockReturn clockret;
@ -680,7 +671,7 @@ gst_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
} }
if (event) if (event)
g_free (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) { MIN_DUTY_CYCLE) {
event = g_async_queue_try_pop (dtmfsrc->event_queue); event = g_async_queue_try_pop (dtmfsrc->event_queue);
@ -740,7 +731,7 @@ gst_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
GST_OBJECT_LOCK (dtmfsrc); GST_OBJECT_LOCK (dtmfsrc);
if (dtmfsrc->paused) if (dtmfsrc->paused)
clockret = GST_CLOCK_UNSCHEDULED; clockret = GST_CLOCK_UNSCHEDULED;
} else { } else {
clockret = GST_CLOCK_UNSCHEDULED; clockret = GST_CLOCK_UNSCHEDULED;
} }
gst_clock_id_unref (clockid); gst_clock_id_unref (clockid);
@ -753,16 +744,17 @@ gst_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
buf = gst_dtmf_src_create_next_tone_packet (dtmfsrc, dtmfsrc->last_event); 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; *buffer = buf;
GST_DEBUG_OBJECT (dtmfsrc, "returning a buffer"); GST_DEBUG_OBJECT (dtmfsrc, "returning a buffer");
return GST_FLOW_OK; return GST_FLOW_OK;
paused_locked: paused_locked:
GST_OBJECT_UNLOCK (dtmfsrc); GST_OBJECT_UNLOCK (dtmfsrc);
paused: paused:
if (dtmfsrc->last_event) { if (dtmfsrc->last_event) {
GST_DEBUG_OBJECT (dtmfsrc, "Stopping current event"); GST_DEBUG_OBJECT (dtmfsrc, "Stopping current event");
@ -777,7 +769,8 @@ gst_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
} }
static gboolean static gboolean
gst_dtmf_src_unlock (GstBaseSrc *src) { gst_dtmf_src_unlock (GstBaseSrc * src)
{
GstDTMFSrc *dtmfsrc = GST_DTMF_SRC (src); GstDTMFSrc *dtmfsrc = GST_DTMF_SRC (src);
GstDTMFSrcEvent *event = NULL; GstDTMFSrcEvent *event = NULL;
@ -791,7 +784,7 @@ gst_dtmf_src_unlock (GstBaseSrc *src) {
GST_OBJECT_UNLOCK (dtmfsrc); GST_OBJECT_UNLOCK (dtmfsrc);
GST_DEBUG_OBJECT (dtmfsrc, "Pushing the PAUSE_TASK event on unlock request"); 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; event->event_type = DTMF_EVENT_TYPE_PAUSE_TASK;
g_async_queue_push (dtmfsrc->event_queue, event); g_async_queue_push (dtmfsrc->event_queue, event);
@ -800,7 +793,8 @@ gst_dtmf_src_unlock (GstBaseSrc *src) {
static gboolean static gboolean
gst_dtmf_src_unlock_stop (GstBaseSrc *src) { gst_dtmf_src_unlock_stop (GstBaseSrc * src)
{
GstDTMFSrc *dtmfsrc = GST_DTMF_SRC (src); GstDTMFSrc *dtmfsrc = GST_DTMF_SRC (src);
GST_DEBUG_OBJECT (dtmfsrc, "Unlock stopped"); GST_DEBUG_OBJECT (dtmfsrc, "Unlock stopped");
@ -824,17 +818,14 @@ gst_dtmf_src_negotiate (GstBaseSrc * basesrc)
"width", G_TYPE_INT, 16, "width", G_TYPE_INT, 16,
"depth", G_TYPE_INT, 16, "depth", G_TYPE_INT, 16,
"endianness", G_TYPE_INT, G_BYTE_ORDER, "endianness", G_TYPE_INT, G_BYTE_ORDER,
"signed", G_TYPE_BOOLEAN, TRUE, "signed", G_TYPE_BOOLEAN, TRUE, "channels", G_TYPE_INT, 1, NULL);
"channels", G_TYPE_INT, 1,
NULL);
peercaps = gst_pad_peer_get_caps (GST_BASE_SRC_PAD (basesrc)); peercaps = gst_pad_peer_get_caps (GST_BASE_SRC_PAD (basesrc));
if (peercaps == NULL) { if (peercaps == NULL) {
/* no peer caps, just add the other properties */ /* no peer caps, just add the other properties */
gst_caps_set_simple (srccaps, gst_caps_set_simple (srccaps,
"rate", G_TYPE_INT, dtmfsrc->sample_rate, "rate", G_TYPE_INT, dtmfsrc->sample_rate, NULL);
NULL);
} else { } else {
GstStructure *s; GstStructure *s;
gint sample_rate; gint sample_rate;
@ -864,17 +855,13 @@ gst_dtmf_src_negotiate (GstBaseSrc * basesrc)
/* get first structure */ /* get first structure */
s = gst_caps_get_structure (srccaps, 0); 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; dtmfsrc->sample_rate = sample_rate;
GST_LOG_OBJECT (dtmfsrc, "using rate from caps %d", GST_LOG_OBJECT (dtmfsrc, "using rate from caps %d", dtmfsrc->sample_rate);
dtmfsrc->sample_rate);
} else { } else {
GST_LOG_OBJECT (dtmfsrc, "using existing rate %d", GST_LOG_OBJECT (dtmfsrc, "using existing rate %d", dtmfsrc->sample_rate);
dtmfsrc->sample_rate);
} }
gst_structure_set (s, "rate", G_TYPE_INT, dtmfsrc->sample_rate, gst_structure_set (s, "rate", G_TYPE_INT, dtmfsrc->sample_rate, NULL);
NULL);
} }
ret = gst_pad_set_caps (GST_BASE_SRC_PAD (basesrc), srccaps); ret = gst_pad_set_caps (GST_BASE_SRC_PAD (basesrc), srccaps);
@ -952,4 +939,3 @@ gst_dtmf_src_plugin_init (GstPlugin * plugin)
return gst_element_register (plugin, "dtmfsrc", return gst_element_register (plugin, "dtmfsrc",
GST_RANK_NONE, GST_TYPE_DTMF_SRC); GST_RANK_NONE, GST_TYPE_DTMF_SRC);
} }

View file

@ -32,7 +32,6 @@
#include <gst/base/gstbasesrc.h> #include <gst/base/gstbasesrc.h>
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_TYPE_DTMF_SRC (gst_dtmf_src_get_type()) #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(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_DTMF_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DTMF_SRC,GstDTMFSrcClass))
@ -40,7 +39,6 @@ G_BEGIN_DECLS
#define GST_IS_DTMF_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DTMF_SRC)) #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_IS_DTMF_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DTMF_SRC))
#define GST_DTMF_SRC_CAST(obj) ((GstDTMFSrc *)(obj)) #define GST_DTMF_SRC_CAST(obj) ((GstDTMFSrc *)(obj))
typedef struct _GstDTMFSrc GstDTMFSrc; typedef struct _GstDTMFSrc GstDTMFSrc;
typedef struct _GstDTMFSrcClass GstDTMFSrcClass; typedef struct _GstDTMFSrcClass GstDTMFSrcClass;
@ -51,7 +49,8 @@ typedef struct _GstDTMFSrcClass GstDTMFSrcClass;
* The opaque #GstDTMFSrc data structure. * The opaque #GstDTMFSrc data structure.
*/ */
enum _GstDTMFEventType { enum _GstDTMFEventType
{
DTMF_EVENT_TYPE_START, DTMF_EVENT_TYPE_START,
DTMF_EVENT_TYPE_STOP, DTMF_EVENT_TYPE_STOP,
DTMF_EVENT_TYPE_PAUSE_TASK DTMF_EVENT_TYPE_PAUSE_TASK
@ -59,32 +58,35 @@ enum _GstDTMFEventType {
typedef enum _GstDTMFEventType GstDTMFEventType; typedef enum _GstDTMFEventType GstDTMFEventType;
struct _GstDTMFSrcEvent { struct _GstDTMFSrcEvent
GstDTMFEventType event_type; {
double sample; GstDTMFEventType event_type;
guint16 event_number; double sample;
guint16 volume; guint16 event_number;
guint32 packet_count; guint16 volume;
guint32 packet_count;
}; };
typedef struct _GstDTMFSrcEvent GstDTMFSrcEvent; typedef struct _GstDTMFSrcEvent GstDTMFSrcEvent;
struct _GstDTMFSrc { struct _GstDTMFSrc
GstBaseSrc parent; {
GAsyncQueue* event_queue; GstBaseSrc parent;
GstDTMFSrcEvent* last_event; GAsyncQueue *event_queue;
GstDTMFSrcEvent *last_event;
guint16 interval; guint16 interval;
GstClockTime timestamp; GstClockTime timestamp;
gboolean paused; gboolean paused;
GstClockID clockid; GstClockID clockid;
gint sample_rate; gint sample_rate;
}; };
struct _GstDTMFSrcClass { struct _GstDTMFSrcClass
{
GstBaseSrcClass parent_class; GstBaseSrcClass parent_class;
}; };
@ -93,5 +95,4 @@ GType gst_dtmf_src_get_type (void);
gboolean gst_dtmf_src_plugin_init (GstPlugin * plugin); gboolean gst_dtmf_src_plugin_init (GstPlugin * plugin);
G_END_DECLS G_END_DECLS
#endif /* __GST_DTMF_SRC_H__ */ #endif /* __GST_DTMF_SRC_H__ */

View file

@ -3,20 +3,21 @@
#define __GST_RTP_DTMF_COMMON_H__ #define __GST_RTP_DTMF_COMMON_H__
typedef struct { typedef struct
unsigned event:8; /* Current DTMF event */ {
unsigned event:8; /* Current DTMF event */
#if G_BYTE_ORDER == G_LITTLE_ENDIAN #if G_BYTE_ORDER == G_LITTLE_ENDIAN
unsigned volume:6; /* power level of the tone, in dBm0 */ unsigned volume:6; /* power level of the tone, in dBm0 */
unsigned r:1; /* Reserved-bit */ unsigned r:1; /* Reserved-bit */
unsigned e:1; /* End-bit */ unsigned e:1; /* End-bit */
#elif G_BYTE_ORDER == G_BIG_ENDIAN #elif G_BYTE_ORDER == G_BIG_ENDIAN
unsigned e:1; /* End-bit */ unsigned e:1; /* End-bit */
unsigned r:1; /* Reserved-bit */ unsigned r:1; /* Reserved-bit */
unsigned volume:6; /* power level of the tone, in dBm0 */ unsigned volume:6; /* power level of the tone, in dBm0 */
#else #else
#error "G_BYTE_ORDER should be big or little endian." #error "G_BYTE_ORDER should be big or little endian."
#endif #endif
unsigned duration:16; /* Duration of digit, in timestamp units */ unsigned duration:16; /* Duration of digit, in timestamp units */
} GstRTPDTMFPayload; } GstRTPDTMFPayload;
#endif /* __GST_RTP_DTMF_COMMON_H__ */ #endif /* __GST_RTP_DTMF_COMMON_H__ */

View file

@ -35,9 +35,9 @@
#endif #endif
#define DEFAULT_PACKET_INTERVAL 50 /* ms */ #define DEFAULT_PACKET_INTERVAL 50 /* ms */
#define MIN_PACKET_INTERVAL 10 /* ms */ #define MIN_PACKET_INTERVAL 10 /* ms */
#define MAX_PACKET_INTERVAL 50 /* ms */ #define MAX_PACKET_INTERVAL 50 /* ms */
#define SAMPLE_RATE 8000 #define SAMPLE_RATE 8000
#define SAMPLE_SIZE 16 #define SAMPLE_SIZE 16
#define CHANNELS 1 #define CHANNELS 1
@ -55,51 +55,53 @@
#define DEFAULT_MAX_DURATION 0 #define DEFAULT_MAX_DURATION 0
typedef struct st_dtmf_key { typedef struct st_dtmf_key
char *event_name; {
int event_encoding; char *event_name;
float low_frequency; int event_encoding;
float high_frequency; float low_frequency;
float high_frequency;
} DTMF_KEY; } DTMF_KEY;
static const DTMF_KEY DTMF_KEYS[] = { static const DTMF_KEY DTMF_KEYS[] = {
{"DTMF_KEY_EVENT_0", 0, 941, 1336}, {"DTMF_KEY_EVENT_0", 0, 941, 1336},
{"DTMF_KEY_EVENT_1", 1, 697, 1209}, {"DTMF_KEY_EVENT_1", 1, 697, 1209},
{"DTMF_KEY_EVENT_2", 2, 697, 1336}, {"DTMF_KEY_EVENT_2", 2, 697, 1336},
{"DTMF_KEY_EVENT_3", 3, 697, 1477}, {"DTMF_KEY_EVENT_3", 3, 697, 1477},
{"DTMF_KEY_EVENT_4", 4, 770, 1209}, {"DTMF_KEY_EVENT_4", 4, 770, 1209},
{"DTMF_KEY_EVENT_5", 5, 770, 1336}, {"DTMF_KEY_EVENT_5", 5, 770, 1336},
{"DTMF_KEY_EVENT_6", 6, 770, 1477}, {"DTMF_KEY_EVENT_6", 6, 770, 1477},
{"DTMF_KEY_EVENT_7", 7, 852, 1209}, {"DTMF_KEY_EVENT_7", 7, 852, 1209},
{"DTMF_KEY_EVENT_8", 8, 852, 1336}, {"DTMF_KEY_EVENT_8", 8, 852, 1336},
{"DTMF_KEY_EVENT_9", 9, 852, 1477}, {"DTMF_KEY_EVENT_9", 9, 852, 1477},
{"DTMF_KEY_EVENT_S", 10, 941, 1209}, {"DTMF_KEY_EVENT_S", 10, 941, 1209},
{"DTMF_KEY_EVENT_P", 11, 941, 1477}, {"DTMF_KEY_EVENT_P", 11, 941, 1477},
{"DTMF_KEY_EVENT_A", 12, 697, 1633}, {"DTMF_KEY_EVENT_A", 12, 697, 1633},
{"DTMF_KEY_EVENT_B", 13, 770, 1633}, {"DTMF_KEY_EVENT_B", 13, 770, 1633},
{"DTMF_KEY_EVENT_C", 14, 852, 1633}, {"DTMF_KEY_EVENT_C", 14, 852, 1633},
{"DTMF_KEY_EVENT_D", 15, 941, 1633}, {"DTMF_KEY_EVENT_D", 15, 941, 1633},
}; };
#define MAX_DTMF_EVENTS 16 #define MAX_DTMF_EVENTS 16
enum { enum
DTMF_KEY_EVENT_1 = 1, {
DTMF_KEY_EVENT_2 = 2, DTMF_KEY_EVENT_1 = 1,
DTMF_KEY_EVENT_3 = 3, DTMF_KEY_EVENT_2 = 2,
DTMF_KEY_EVENT_4 = 4, DTMF_KEY_EVENT_3 = 3,
DTMF_KEY_EVENT_5 = 5, DTMF_KEY_EVENT_4 = 4,
DTMF_KEY_EVENT_6 = 6, DTMF_KEY_EVENT_5 = 5,
DTMF_KEY_EVENT_7 = 7, DTMF_KEY_EVENT_6 = 6,
DTMF_KEY_EVENT_8 = 8, DTMF_KEY_EVENT_7 = 7,
DTMF_KEY_EVENT_9 = 9, DTMF_KEY_EVENT_8 = 8,
DTMF_KEY_EVENT_0 = 0, DTMF_KEY_EVENT_9 = 9,
DTMF_KEY_EVENT_STAR = 10, DTMF_KEY_EVENT_0 = 0,
DTMF_KEY_EVENT_POUND = 11, DTMF_KEY_EVENT_STAR = 10,
DTMF_KEY_EVENT_A = 12, DTMF_KEY_EVENT_POUND = 11,
DTMF_KEY_EVENT_B = 13, DTMF_KEY_EVENT_A = 12,
DTMF_KEY_EVENT_C = 14, DTMF_KEY_EVENT_B = 13,
DTMF_KEY_EVENT_D = 15, DTMF_KEY_EVENT_C = 14,
DTMF_KEY_EVENT_D = 15,
}; };
/* elementfactory information */ /* elementfactory information */
@ -141,8 +143,7 @@ GST_STATIC_PAD_TEMPLATE ("src",
"depth = (int) 16, " "depth = (int) 16, "
"endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", " "endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", "
"signed = (boolean) true, " "signed = (boolean) true, "
"rate = (int) [0, MAX], " "rate = (int) [0, MAX], " "channels = (int) 1")
"channels = (int) 1")
); );
static GstStaticPadTemplate gst_rtp_dtmf_depay_sink_template = static GstStaticPadTemplate gst_rtp_dtmf_depay_sink_template =
@ -180,7 +181,7 @@ gst_rtp_dtmf_depay_base_init (gpointer klass)
GST_DEBUG_CATEGORY_INIT (gst_rtp_dtmf_depay_debug, 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_element_class_set_details (element_class, &gst_rtp_dtmfdepay_details);
} }
@ -203,20 +204,20 @@ gst_rtp_dtmf_depay_class_init (GstRtpDTMFDepayClass * klass)
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_depay_get_property); GST_DEBUG_FUNCPTR (gst_rtp_dtmf_depay_get_property);
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_UNIT_TIME, g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_UNIT_TIME,
g_param_spec_uint ("unit-time", "Duration unittime", 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, "The smallest unit (ms) the duration must be a multiple of (0 disables it)",
MAX_UNIT_TIME, DEFAULT_UNIT_TIME, G_PARAM_READWRITE)); 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_object_class_install_property (G_OBJECT_CLASS (klass), PROP_MAX_DURATION,
g_param_spec_uint ("max-duration", "Maximum duration", g_param_spec_uint ("max-duration", "Maximum duration",
"The maxumimum duration (ms) of the outgoing soundpacket. " "The maxumimum duration (ms) of the outgoing soundpacket. "
"(0 = no limit)", 0, G_MAXUINT, DEFAULT_MAX_DURATION, "(0 = no limit)", 0, G_MAXUINT, DEFAULT_MAX_DURATION,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
gstbasertpdepayload_class->process = gstbasertpdepayload_class->process =
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_depay_process); GST_DEBUG_FUNCPTR (gst_rtp_dtmf_depay_process);
gstbasertpdepayload_class->set_caps = gstbasertpdepayload_class->set_caps =
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_depay_setcaps); GST_DEBUG_FUNCPTR (gst_rtp_dtmf_depay_setcaps);
} }
@ -231,7 +232,7 @@ static void
gst_rtp_dtmf_depay_set_property (GObject * object, guint prop_id, gst_rtp_dtmf_depay_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec) const GValue * value, GParamSpec * pspec)
{ {
GstRtpDTMFDepay * rtpdtmfdepay; GstRtpDTMFDepay *rtpdtmfdepay;
rtpdtmfdepay = GST_RTP_DTMF_DEPAY (object); rtpdtmfdepay = GST_RTP_DTMF_DEPAY (object);
@ -252,7 +253,7 @@ static void
gst_rtp_dtmf_depay_get_property (GObject * object, guint prop_id, gst_rtp_dtmf_depay_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec) GValue * value, GParamSpec * pspec)
{ {
GstRtpDTMFDepay * rtpdtmfdepay; GstRtpDTMFDepay *rtpdtmfdepay;
rtpdtmfdepay = GST_RTP_DTMF_DEPAY (object); rtpdtmfdepay = GST_RTP_DTMF_DEPAY (object);
@ -274,7 +275,7 @@ gst_rtp_dtmf_depay_setcaps (GstBaseRTPDepayload * filter, GstCaps * caps)
{ {
GstCaps *srccaps; GstCaps *srccaps;
GstStructure *structure = gst_caps_get_structure (caps, 0); 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); gst_structure_get_int (structure, "clock-rate", &clock_rate);
filter->clock_rate = clock_rate; filter->clock_rate = clock_rate;
@ -284,8 +285,7 @@ gst_rtp_dtmf_depay_setcaps (GstBaseRTPDepayload * filter, GstCaps * caps)
"depth", G_TYPE_INT, 16, "depth", G_TYPE_INT, 16,
"endianness", G_TYPE_INT, G_BYTE_ORDER, "endianness", G_TYPE_INT, G_BYTE_ORDER,
"signed", G_TYPE_BOOLEAN, TRUE, "signed", G_TYPE_BOOLEAN, TRUE,
"channels", G_TYPE_INT, 1, "channels", G_TYPE_INT, 1, "rate", G_TYPE_INT, clock_rate, NULL);
"rate", G_TYPE_INT, clock_rate, NULL);
gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (filter), srccaps); gst_pad_set_caps (GST_BASE_RTP_DEPAYLOAD_SRCPAD (filter), srccaps);
gst_caps_unref (srccaps); gst_caps_unref (srccaps);
@ -293,7 +293,7 @@ gst_rtp_dtmf_depay_setcaps (GstBaseRTPDepayload * filter, GstCaps * caps)
} }
static void static void
gst_dtmf_src_generate_tone(GstRtpDTMFDepay *rtpdtmfdepay, gst_dtmf_src_generate_tone (GstRtpDTMFDepay * rtpdtmfdepay,
GstRTPDTMFPayload payload, GstBuffer * buffer) GstRTPDTMFPayload payload, GstBuffer * buffer)
{ {
gint16 *p; gint16 *p;
@ -302,16 +302,16 @@ gst_dtmf_src_generate_tone(GstRtpDTMFDepay *rtpdtmfdepay,
double amplitude, f1, f2; double amplitude, f1, f2;
double volume_factor; double volume_factor;
DTMF_KEY key = DTMF_KEYS[payload.event]; DTMF_KEY key = DTMF_KEYS[payload.event];
guint32 clock_rate = 8000 /* default */; guint32 clock_rate = 8000 /* default */ ;
GstBaseRTPDepayload * depayload = GST_BASE_RTP_DEPAYLOAD (rtpdtmfdepay); GstBaseRTPDepayload *depayload = GST_BASE_RTP_DEPAYLOAD (rtpdtmfdepay);
gint volume; gint volume;
clock_rate = depayload->clock_rate; clock_rate = depayload->clock_rate;
/* Create a buffer for the tone */ /* 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_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_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer);
GST_BUFFER_DURATION (buffer) = payload.duration * GST_SECOND / clock_rate; GST_BUFFER_DURATION (buffer) = payload.duration * GST_SECOND / clock_rate;
volume = payload.volume; volume = payload.volume;
@ -324,12 +324,14 @@ gst_dtmf_src_generate_tone(GstRtpDTMFDepay *rtpdtmfdepay,
* For each sample point we calculate 'x' as the * For each sample point we calculate 'x' as the
* the amplitude value. * 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. * We add the fundamental frequencies together.
*/ */
f1 = sin(2 * M_PI * key.low_frequency * (rtpdtmfdepay->sample / clock_rate)); f1 = sin (2 * M_PI * key.low_frequency * (rtpdtmfdepay->sample /
f2 = sin(2 * M_PI * key.high_frequency * (rtpdtmfdepay->sample / clock_rate)); clock_rate));
f2 = sin (2 * M_PI * key.high_frequency * (rtpdtmfdepay->sample /
clock_rate));
amplitude = (f1 + f2) / 2; amplitude = (f1 + f2) / 2;
@ -369,7 +371,7 @@ gst_rtp_dtmf_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
payload_len = gst_rtp_buffer_get_payload_len (buf); payload_len = gst_rtp_buffer_get_payload_len (buf);
payload = gst_rtp_buffer_get_payload (buf); payload = gst_rtp_buffer_get_payload (buf);
if (payload_len != sizeof(GstRTPDTMFPayload) ) if (payload_len != sizeof (GstRTPDTMFPayload))
goto bad_packet; goto bad_packet;
memcpy (&dtmf_payload, payload, sizeof (GstRTPDTMFPayload)); memcpy (&dtmf_payload, payload, sizeof (GstRTPDTMFPayload));
@ -385,12 +387,10 @@ gst_rtp_dtmf_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
dtmf_payload.duration = g_ntohs (dtmf_payload.duration); dtmf_payload.duration = g_ntohs (dtmf_payload.duration);
/* clip to whole units of unit_time */ /* clip to whole units of unit_time */
if (rtpdtmfdepay->unit_time) if (rtpdtmfdepay->unit_time) {
{
guint unit_time_clock = guint unit_time_clock =
(rtpdtmfdepay->unit_time * depayload->clock_rate) / 1000; (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 */ /* Make sure we don't overflow the duration */
if (dtmf_payload.duration < G_MAXUINT16 - unit_time_clock) if (dtmf_payload.duration < G_MAXUINT16 - unit_time_clock)
dtmf_payload.duration += unit_time_clock - dtmf_payload.duration += unit_time_clock -
@ -401,8 +401,7 @@ gst_rtp_dtmf_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
} }
/* clip to max duration */ /* clip to max duration */
if (rtpdtmfdepay->max_duration) if (rtpdtmfdepay->max_duration) {
{
guint max_duration_clock = guint max_duration_clock =
(rtpdtmfdepay->max_duration * depayload->clock_rate) / 1000; (rtpdtmfdepay->max_duration * depayload->clock_rate) / 1000;
@ -415,7 +414,8 @@ gst_rtp_dtmf_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
"marker=%d - timestamp=%u - event=%d - duration=%d", "marker=%d - timestamp=%u - event=%d - duration=%d",
marker, timestamp, dtmf_payload.event, dtmf_payload.duration); 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); rtpdtmfdepay->previous_ts, rtpdtmfdepay->previous_duration);
/* First packet */ /* First packet */
@ -428,14 +428,14 @@ gst_rtp_dtmf_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
structure = gst_structure_new ("dtmf-event", structure = gst_structure_new ("dtmf-event",
"number", G_TYPE_INT, dtmf_payload.event, "number", G_TYPE_INT, dtmf_payload.event,
"volume", G_TYPE_INT, dtmf_payload.volume, "volume", G_TYPE_INT, dtmf_payload.volume,
"type", G_TYPE_INT, 1, "type", G_TYPE_INT, 1, "method", G_TYPE_INT, 1, NULL);
"method", G_TYPE_INT, 1,
NULL);
if (structure) { 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 (dtmf_message) {
if (!gst_element_post_message (GST_ELEMENT (depayload), 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 { } else {
GST_ERROR_OBJECT (depayload, "Unable to create dtmf-event message"); GST_ERROR_OBJECT (depayload, "Unable to create dtmf-event message");
@ -460,7 +460,7 @@ gst_rtp_dtmf_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
/* If late or duplicate packet (like the redundant end packet). Ignore */ /* If late or duplicate packet (like the redundant end packet). Ignore */
if (dtmf_payload.duration > 0) { if (dtmf_payload.duration > 0) {
outbuf = gst_buffer_new (); 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_BUFFER_TIMESTAMP (outbuf) = rtpdtmfdepay->first_gst_ts +
@ -468,9 +468,9 @@ gst_rtp_dtmf_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
GST_SECOND / depayload->clock_rate; GST_SECOND / depayload->clock_rate;
GST_BUFFER_OFFSET (outbuf) = GST_BUFFER_OFFSET (outbuf) =
(rtpdtmfdepay->previous_duration - dtmf_payload.duration) * (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_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_DEBUG_OBJECT (depayload, "timestamp : %llu - time %" GST_TIME_FORMAT,
GST_BUFFER_TIMESTAMP (buf), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf))); GST_BUFFER_TIMESTAMP (buf), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
@ -492,4 +492,3 @@ gst_rtp_dtmf_depay_plugin_init (GstPlugin * plugin)
return gst_element_register (plugin, "rtpdtmfdepay", return gst_element_register (plugin, "rtpdtmfdepay",
GST_RANK_MARGINAL, GST_TYPE_RTP_DTMF_DEPAY); GST_RANK_MARGINAL, GST_TYPE_RTP_DTMF_DEPAY);
} }

View file

@ -30,7 +30,6 @@
#include "gstrtpdtmfcommon.h" #include "gstrtpdtmfcommon.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_TYPE_RTP_DTMF_DEPAY \ #define GST_TYPE_RTP_DTMF_DEPAY \
(gst_rtp_dtmf_depay_get_type()) (gst_rtp_dtmf_depay_get_type())
#define GST_RTP_DTMF_DEPAY(obj) \ #define GST_RTP_DTMF_DEPAY(obj) \
@ -41,18 +40,16 @@ G_BEGIN_DECLS
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_DTMF_DEPAY)) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_DTMF_DEPAY))
#define GST_IS_RTP_DTMF_DEPAY_CLASS(klass) \ #define GST_IS_RTP_DTMF_DEPAY_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_DTMF_DEPAY)) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_DTMF_DEPAY))
typedef struct _GstRtpDTMFDepay GstRtpDTMFDepay; typedef struct _GstRtpDTMFDepay GstRtpDTMFDepay;
typedef struct _GstRtpDTMFDepayClass GstRtpDTMFDepayClass; typedef struct _GstRtpDTMFDepayClass GstRtpDTMFDepayClass;
struct _GstRtpDTMFDepay struct _GstRtpDTMFDepay
{ {
GstBaseRTPDepayload depayload; GstBaseRTPDepayload depayload;
double sample; double sample;
guint32 previous_ts; guint32 previous_ts;
guint16 previous_duration; guint16 previous_duration;
GstClockTime first_gst_ts; GstClockTime first_gst_ts;
guint unit_time; guint unit_time;
guint max_duration; guint max_duration;
}; };
@ -65,5 +62,4 @@ struct _GstRtpDTMFDepayClass
gboolean gst_rtp_dtmf_depay_plugin_init (GstPlugin * plugin); gboolean gst_rtp_dtmf_depay_plugin_init (GstPlugin * plugin);
G_END_DECLS G_END_DECLS
#endif /* __GST_RTP_DTMF_DEPAY_H__ */ #endif /* __GST_RTP_DTMF_DEPAY_H__ */

View file

@ -134,9 +134,9 @@
#include "gstrtpdtmfsrc.h" #include "gstrtpdtmfsrc.h"
#define GST_RTP_DTMF_TYPE_EVENT 1 #define GST_RTP_DTMF_TYPE_EVENT 1
#define DEFAULT_PACKET_INTERVAL 50 /* ms */ #define DEFAULT_PACKET_INTERVAL 50 /* ms */
#define MIN_PACKET_INTERVAL 10 /* ms */ #define MIN_PACKET_INTERVAL 10 /* ms */
#define MAX_PACKET_INTERVAL 50 /* ms */ #define MAX_PACKET_INTERVAL 50 /* ms */
#define DEFAULT_SSRC -1 #define DEFAULT_SSRC -1
#define DEFAULT_PT 96 #define DEFAULT_PT 96
#define DEFAULT_TIMESTAMP_OFFSET -1 #define DEFAULT_TIMESTAMP_OFFSET -1
@ -149,8 +149,8 @@
#define MIN_VOLUME 0 #define MIN_VOLUME 0
#define MAX_VOLUME 36 #define MAX_VOLUME 36
#define MIN_INTER_DIGIT_INTERVAL 50 /* ms */ #define MIN_INTER_DIGIT_INTERVAL 50 /* ms */
#define MIN_PULSE_DURATION 70 /* ms */ #define MIN_PULSE_DURATION 70 /* ms */
#define DEFAULT_PACKET_REDUNDANCY 1 #define DEFAULT_PACKET_REDUNDANCY 1
#define MIN_PACKET_REDUNDANCY 1 #define MIN_PACKET_REDUNDANCY 1
@ -198,7 +198,6 @@ GST_STATIC_PAD_TEMPLATE ("src",
"ssrc = (int) [ 0, MAX ], " "ssrc = (int) [ 0, MAX ], "
"encoding-name = (string) \"TELEPHONE-EVENT\"") "encoding-name = (string) \"TELEPHONE-EVENT\"")
/* "events = (string) \"0-15\" */ /* "events = (string) \"0-15\" */
); );
@ -215,16 +214,16 @@ static void gst_rtp_dtmf_src_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec); const GValue * value, GParamSpec * pspec);
static void gst_rtp_dtmf_src_get_property (GObject * object, guint prop_id, static void gst_rtp_dtmf_src_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec); 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); GstEvent * event);
static GstStateChangeReturn gst_rtp_dtmf_src_change_state (GstElement * element, static GstStateChangeReturn gst_rtp_dtmf_src_change_state (GstElement * element,
GstStateChange transition); 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); 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 (GstBaseSrc * src);
static gboolean gst_rtp_dtmf_src_unlock_stop (GstBaseSrc *src); static gboolean gst_rtp_dtmf_src_unlock_stop (GstBaseSrc * src);
static GstFlowReturn gst_rtp_dtmf_src_create (GstBaseSrc * basesrc, static GstFlowReturn gst_rtp_dtmf_src_create (GstBaseSrc * basesrc,
guint64 offset, guint length, GstBuffer ** buffer); guint64 offset, guint length, GstBuffer ** buffer);
static gboolean gst_rtp_dtmf_src_negotiate (GstBaseSrc * basesrc); static gboolean gst_rtp_dtmf_src_negotiate (GstBaseSrc * basesrc);
@ -236,7 +235,7 @@ gst_rtp_dtmf_src_base_init (gpointer g_class)
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
GST_DEBUG_CATEGORY_INIT (gst_rtp_dtmf_src_debug, 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_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_rtp_dtmf_src_template)); gst_static_pad_template_get (&gst_rtp_dtmf_src_template));
@ -305,17 +304,13 @@ gst_rtp_dtmf_src_class_init (GstRTPDTMFSrcClass * klass)
gstelement_class->change_state = gstelement_class->change_state =
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_change_state); GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_change_state);
gstbasesrc_class->unlock = gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_unlock);
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_unlock);
gstbasesrc_class->unlock_stop = gstbasesrc_class->unlock_stop =
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_unlock_stop); GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_unlock_stop);
gstbasesrc_class->event = gstbasesrc_class->event = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_handle_event);
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_handle_event); gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_create);
gstbasesrc_class->create = gstbasesrc_class->negotiate = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_negotiate);
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_create);
gstbasesrc_class->negotiate =
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_negotiate);
} }
static void static void
@ -355,16 +350,16 @@ gst_rtp_dtmf_src_finalize (GObject * object)
} }
static gboolean static gboolean
gst_rtp_dtmf_src_handle_dtmf_event (GstRTPDTMFSrc *dtmfsrc, gst_rtp_dtmf_src_handle_dtmf_event (GstRTPDTMFSrc * dtmfsrc,
const GstStructure * event_structure) const GstStructure * event_structure)
{ {
gint event_type; gint event_type;
gboolean start; gboolean start;
gint method; gint method;
if (!gst_structure_get_int (event_structure, "type", &event_type) || if (!gst_structure_get_int (event_structure, "type", &event_type) ||
!gst_structure_get_boolean (event_structure, "start", &start) || !gst_structure_get_boolean (event_structure, "start", &start) ||
event_type != GST_RTP_DTMF_TYPE_EVENT) event_type != GST_RTP_DTMF_TYPE_EVENT)
goto failure; goto failure;
if (gst_structure_get_int (event_structure, "method", &method)) { if (gst_structure_get_int (event_structure, "method", &method)) {
@ -378,11 +373,11 @@ gst_rtp_dtmf_src_handle_dtmf_event (GstRTPDTMFSrc *dtmfsrc,
gint event_volume; gint event_volume;
if (!gst_structure_get_int (event_structure, "number", &event_number) || 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; goto failure;
GST_DEBUG_OBJECT (dtmfsrc, "Received start event %d with volume %d", 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); gst_rtp_dtmf_src_add_start_event (dtmfsrc, event_number, event_volume);
} }
@ -397,7 +392,7 @@ failure:
} }
static gboolean static gboolean
gst_rtp_dtmf_src_handle_custom_upstream (GstRTPDTMFSrc *dtmfsrc, gst_rtp_dtmf_src_handle_custom_upstream (GstRTPDTMFSrc * dtmfsrc,
GstEvent * event) GstEvent * event)
{ {
gboolean result = FALSE; gboolean result = FALSE;
@ -426,7 +421,7 @@ ret:
} }
static gboolean static gboolean
gst_rtp_dtmf_src_handle_event (GstBaseSrc *basesrc, GstEvent * event) gst_rtp_dtmf_src_handle_event (GstBaseSrc * basesrc, GstEvent * event)
{ {
GstRTPDTMFSrc *dtmfsrc; GstRTPDTMFSrc *dtmfsrc;
gboolean result = FALSE; gboolean result = FALSE;
@ -522,23 +517,23 @@ gst_rtp_dtmf_src_get_property (GObject * object, guint prop_id, GValue * value,
} }
static void 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; GstEvent *event;
GstStructure *structure; GstStructure *structure;
structure = gst_structure_new ("stream-lock", structure = gst_structure_new ("stream-lock",
"lock", G_TYPE_BOOLEAN, lock, NULL); "lock", G_TYPE_BOOLEAN, lock, NULL);
event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_OOB, structure); event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_OOB, structure);
if (!gst_pad_push_event (GST_BASE_SRC_PAD (dtmfsrc), event)) { if (!gst_pad_push_event (GST_BASE_SRC_PAD (dtmfsrc), event)) {
GST_WARNING_OBJECT (dtmfsrc, "stream-lock event not handled"); GST_WARNING_OBJECT (dtmfsrc, "stream-lock event not handled");
} }
} }
static void static void
gst_rtp_dtmf_prepare_timestamps (GstRTPDTMFSrc *dtmfsrc) gst_rtp_dtmf_prepare_timestamps (GstRTPDTMFSrc * dtmfsrc)
{ {
GstClock *clock; GstClock *clock;
GstClockTime base_time; GstClockTime base_time;
@ -563,19 +558,18 @@ gst_rtp_dtmf_prepare_timestamps (GstRTPDTMFSrc *dtmfsrc)
} }
dtmfsrc->rtp_timestamp = dtmfsrc->ts_base + dtmfsrc->rtp_timestamp = dtmfsrc->ts_base +
gst_util_uint64_scale_int ( gst_util_uint64_scale_int (gst_segment_to_running_time (&GST_BASE_SRC
gst_segment_to_running_time (&GST_BASE_SRC (dtmfsrc)->segment, (dtmfsrc)->segment, GST_FORMAT_TIME, dtmfsrc->timestamp),
GST_FORMAT_TIME, dtmfsrc->timestamp), dtmfsrc->clock_rate, GST_SECOND);
dtmfsrc->clock_rate, GST_SECOND);
} }
static void 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) gint event_volume)
{ {
GstRTPDTMFSrcEvent * event = g_malloc (sizeof(GstRTPDTMFSrcEvent)); GstRTPDTMFSrcEvent *event = g_malloc (sizeof (GstRTPDTMFSrcEvent));
event->event_type = RTP_DTMF_EVENT_TYPE_START; event->event_type = RTP_DTMF_EVENT_TYPE_START;
event->payload = g_new0 (GstRTPDTMFPayload, 1); event->payload = g_new0 (GstRTPDTMFPayload, 1);
@ -587,10 +581,10 @@ gst_rtp_dtmf_src_add_start_event (GstRTPDTMFSrc *dtmfsrc, gint event_number,
} }
static void 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; event->event_type = RTP_DTMF_EVENT_TYPE_STOP;
g_async_queue_push (dtmfsrc->event_queue, event); g_async_queue_push (dtmfsrc->event_queue, event);
@ -598,7 +592,7 @@ gst_rtp_dtmf_src_add_stop_event (GstRTPDTMFSrc *dtmfsrc)
static void 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_ssrc (buf, dtmfsrc->current_ssrc);
gst_rtp_buffer_set_payload_type (buf, dtmfsrc->pt); gst_rtp_buffer_set_payload_type (buf, dtmfsrc->pt);
@ -617,7 +611,7 @@ gst_rtp_dtmf_prepare_rtp_headers (GstRTPDTMFSrc *dtmfsrc, GstBuffer *buf)
} }
static void static void
gst_rtp_dtmf_prepare_buffer_data (GstRTPDTMFSrc *dtmfsrc, GstBuffer *buf) gst_rtp_dtmf_prepare_buffer_data (GstRTPDTMFSrc * dtmfsrc, GstBuffer * buf)
{ {
GstRTPDTMFPayload *payload; GstRTPDTMFPayload *payload;
@ -641,7 +635,7 @@ gst_rtp_dtmf_prepare_buffer_data (GstRTPDTMFSrc *dtmfsrc, GstBuffer *buf)
* if its the end of the event * if its the end of the event
*/ */
if (payload->e && 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 = MIN_PULSE_DURATION * dtmfsrc->clock_rate / 1000;
payload->duration = g_htons (payload->duration); payload->duration = g_htons (payload->duration);
@ -656,7 +650,7 @@ gst_rtp_dtmf_prepare_buffer_data (GstRTPDTMFSrc *dtmfsrc, GstBuffer *buf)
} }
static GstBuffer * 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; GstBuffer *buf = NULL;
@ -676,7 +670,7 @@ gst_rtp_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
guint length, GstBuffer ** buffer) guint length, GstBuffer ** buffer)
{ {
GstRTPDTMFSrcEvent *event; GstRTPDTMFSrcEvent *event;
GstRTPDTMFSrc * dtmfsrc; GstRTPDTMFSrc *dtmfsrc;
GstClock *clock; GstClock *clock;
GstClockID *clockid; GstClockID *clockid;
GstClockReturn clockret; GstClockReturn clockret;
@ -726,7 +720,7 @@ gst_rtp_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
g_free (event); g_free (event);
} else if (!dtmfsrc->first_packet && !dtmfsrc->last_packet && } 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) { MIN_PULSE_DURATION) {
GST_DEBUG_OBJECT (dtmfsrc, "try popping"); GST_DEBUG_OBJECT (dtmfsrc, "try popping");
event = g_async_queue_try_pop (dtmfsrc->event_queue); event = g_async_queue_try_pop (dtmfsrc->event_queue);
@ -790,7 +784,7 @@ gst_rtp_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
GST_OBJECT_LOCK (dtmfsrc); GST_OBJECT_LOCK (dtmfsrc);
if (dtmfsrc->paused) if (dtmfsrc->paused)
clockret = GST_CLOCK_UNSCHEDULED; clockret = GST_CLOCK_UNSCHEDULED;
} else { } else {
clockret = GST_CLOCK_UNSCHEDULED; clockret = GST_CLOCK_UNSCHEDULED;
} }
gst_clock_id_unref (clockid); gst_clock_id_unref (clockid);
@ -801,7 +795,7 @@ gst_rtp_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
goto paused; goto paused;
} }
send_last: send_last:
if (dtmfsrc->dirty) if (dtmfsrc->dirty)
if (!gst_rtp_dtmf_src_negotiate (basesrc)) if (!gst_rtp_dtmf_src_negotiate (basesrc))
@ -830,11 +824,11 @@ gst_rtp_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
return GST_FLOW_OK; return GST_FLOW_OK;
paused_locked: paused_locked:
GST_OBJECT_UNLOCK (dtmfsrc); GST_OBJECT_UNLOCK (dtmfsrc);
paused: paused:
if (dtmfsrc->payload) { if (dtmfsrc->payload) {
dtmfsrc->first_packet = FALSE; dtmfsrc->first_packet = FALSE;
@ -910,8 +904,7 @@ gst_rtp_dtmf_src_negotiate (GstBaseSrc * basesrc)
} else { } else {
if (gst_structure_has_field (s, "payload")) { if (gst_structure_has_field (s, "payload")) {
/* can only fixate if there is a field */ /* can only fixate if there is a field */
gst_structure_fixate_field_nearest_int (s, "payload", gst_structure_fixate_field_nearest_int (s, "payload", dtmfsrc->pt);
dtmfsrc->pt);
gst_structure_get_int (s, "payload", &pt); gst_structure_get_int (s, "payload", &pt);
GST_LOG_OBJECT (dtmfsrc, "using peer pt %d", pt); GST_LOG_OBJECT (dtmfsrc, "using peer pt %d", pt);
} else { } else {
@ -922,8 +915,7 @@ gst_rtp_dtmf_src_negotiate (GstBaseSrc * basesrc)
} }
} }
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; dtmfsrc->clock_rate = clock_rate;
GST_LOG_OBJECT (dtmfsrc, "using clock-rate from caps %d", GST_LOG_OBJECT (dtmfsrc, "using clock-rate from caps %d",
dtmfsrc->clock_rate); dtmfsrc->clock_rate);
@ -931,8 +923,7 @@ gst_rtp_dtmf_src_negotiate (GstBaseSrc * basesrc)
GST_LOG_OBJECT (dtmfsrc, "using existing clock-rate %d", GST_LOG_OBJECT (dtmfsrc, "using existing clock-rate %d",
dtmfsrc->clock_rate); dtmfsrc->clock_rate);
} }
gst_structure_set (s, "clock-rate", G_TYPE_INT, dtmfsrc->clock_rate, gst_structure_set (s, "clock-rate", G_TYPE_INT, dtmfsrc->clock_rate, NULL);
NULL);
if (gst_structure_has_field_typed (s, "ssrc", G_TYPE_UINT)) { if (gst_structure_has_field_typed (s, "ssrc", G_TYPE_UINT)) {
@ -982,7 +973,7 @@ gst_rtp_dtmf_src_negotiate (GstBaseSrc * basesrc)
static void static void
gst_rtp_dtmf_src_ready_to_paused (GstRTPDTMFSrc *dtmfsrc) gst_rtp_dtmf_src_ready_to_paused (GstRTPDTMFSrc * dtmfsrc)
{ {
if (dtmfsrc->ssrc == -1) if (dtmfsrc->ssrc == -1)
dtmfsrc->current_ssrc = g_random_int (); dtmfsrc->current_ssrc = g_random_int ();
@ -1008,7 +999,7 @@ gst_rtp_dtmf_src_change_state (GstElement * element, GstStateChange transition)
GstRTPDTMFSrc *dtmfsrc; GstRTPDTMFSrc *dtmfsrc;
GstStateChangeReturn result; GstStateChangeReturn result;
gboolean no_preroll = FALSE; gboolean no_preroll = FALSE;
GstRTPDTMFSrcEvent *event= NULL; GstRTPDTMFSrcEvent *event = NULL;
dtmfsrc = GST_RTP_DTMF_SRC (element); dtmfsrc = GST_RTP_DTMF_SRC (element);
@ -1037,7 +1028,7 @@ gst_rtp_dtmf_src_change_state (GstElement * element, GstStateChange transition)
break; break;
case GST_STATE_CHANGE_PAUSED_TO_READY: 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) while ((event = g_async_queue_try_pop (dtmfsrc->event_queue)) != NULL)
g_free (event); g_free (event);
@ -1063,7 +1054,8 @@ failure:
static gboolean static gboolean
gst_rtp_dtmf_src_unlock (GstBaseSrc *src) { gst_rtp_dtmf_src_unlock (GstBaseSrc * src)
{
GstRTPDTMFSrc *dtmfsrc = GST_RTP_DTMF_SRC (src); GstRTPDTMFSrc *dtmfsrc = GST_RTP_DTMF_SRC (src);
GstRTPDTMFSrcEvent *event = NULL; GstRTPDTMFSrcEvent *event = NULL;
@ -1077,7 +1069,7 @@ gst_rtp_dtmf_src_unlock (GstBaseSrc *src) {
GST_OBJECT_UNLOCK (dtmfsrc); GST_OBJECT_UNLOCK (dtmfsrc);
GST_DEBUG_OBJECT (dtmfsrc, "Pushing the PAUSE_TASK event on unlock request"); 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; event->event_type = RTP_DTMF_EVENT_TYPE_PAUSE_TASK;
g_async_queue_push (dtmfsrc->event_queue, event); g_async_queue_push (dtmfsrc->event_queue, event);
@ -1086,7 +1078,8 @@ gst_rtp_dtmf_src_unlock (GstBaseSrc *src) {
static gboolean 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); GstRTPDTMFSrc *dtmfsrc = GST_RTP_DTMF_SRC (src);
GST_DEBUG_OBJECT (dtmfsrc, "Unlock stopped"); GST_DEBUG_OBJECT (dtmfsrc, "Unlock stopped");

View file

@ -32,7 +32,6 @@
#include "gstrtpdtmfcommon.h" #include "gstrtpdtmfcommon.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_TYPE_RTP_DTMF_SRC (gst_rtp_dtmf_src_get_type()) #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(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_RTP_DTMF_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RTP_DTMF_SRC,GstRTPDTMFSrcClass))
@ -40,14 +39,13 @@ G_BEGIN_DECLS
#define GST_IS_RTP_DTMF_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_DTMF_SRC)) #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_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)) #define GST_RTP_DTMF_SRC_CAST(obj) ((GstRTPDTMFSrc *)(obj))
typedef struct _GstRTPDTMFSrc GstRTPDTMFSrc; typedef struct _GstRTPDTMFSrc GstRTPDTMFSrc;
typedef struct _GstRTPDTMFSrcClass GstRTPDTMFSrcClass; typedef struct _GstRTPDTMFSrcClass GstRTPDTMFSrcClass;
enum _GstRTPDTMFEventType { enum _GstRTPDTMFEventType
{
RTP_DTMF_EVENT_TYPE_START, RTP_DTMF_EVENT_TYPE_START,
RTP_DTMF_EVENT_TYPE_STOP, RTP_DTMF_EVENT_TYPE_STOP,
RTP_DTMF_EVENT_TYPE_PAUSE_TASK RTP_DTMF_EVENT_TYPE_PAUSE_TASK
@ -55,9 +53,10 @@ enum _GstRTPDTMFEventType {
typedef enum _GstRTPDTMFEventType GstRTPDTMFEventType; typedef enum _GstRTPDTMFEventType GstRTPDTMFEventType;
struct _GstRTPDTMFSrcEvent { struct _GstRTPDTMFSrcEvent
GstRTPDTMFEventType event_type; {
GstRTPDTMFPayload* payload; GstRTPDTMFEventType event_type;
GstRTPDTMFPayload *payload;
}; };
typedef struct _GstRTPDTMFSrcEvent GstRTPDTMFSrcEvent; typedef struct _GstRTPDTMFSrcEvent GstRTPDTMFSrcEvent;
@ -68,36 +67,38 @@ typedef struct _GstRTPDTMFSrcEvent GstRTPDTMFSrcEvent;
* *
* The opaque #GstRTPDTMFSrc data structure. * The opaque #GstRTPDTMFSrc data structure.
*/ */
struct _GstRTPDTMFSrc { struct _GstRTPDTMFSrc
GstBaseSrc basesrc; {
GstBaseSrc basesrc;
GAsyncQueue* event_queue; GAsyncQueue *event_queue;
GstClockID clockid; GstClockID clockid;
gboolean paused; gboolean paused;
GstRTPDTMFPayload* payload; GstRTPDTMFPayload *payload;
GstClockTime timestamp; GstClockTime timestamp;
GstClockTime start_timestamp; GstClockTime start_timestamp;
gboolean first_packet; gboolean first_packet;
gboolean last_packet; gboolean last_packet;
guint32 ts_base; guint32 ts_base;
guint16 seqnum_base; guint16 seqnum_base;
gint16 seqnum_offset; gint16 seqnum_offset;
guint16 seqnum; guint16 seqnum;
gint32 ts_offset; gint32 ts_offset;
guint32 rtp_timestamp; guint32 rtp_timestamp;
guint pt; guint pt;
guint ssrc; guint ssrc;
guint current_ssrc; guint current_ssrc;
guint16 interval; guint16 interval;
guint16 packet_redundancy; guint16 packet_redundancy;
guint32 clock_rate; guint32 clock_rate;
gboolean dirty; gboolean dirty;
guint16 redundancy_count; guint16 redundancy_count;
}; };
struct _GstRTPDTMFSrcClass { struct _GstRTPDTMFSrcClass
{
GstBaseSrcClass parent_class; GstBaseSrcClass parent_class;
}; };
@ -107,5 +108,4 @@ gboolean gst_rtp_dtmf_src_plugin_init (GstPlugin * plugin);
G_END_DECLS G_END_DECLS
#endif /* __GST_RTP_DTMF_SRC_H__ */ #endif /* __GST_RTP_DTMF_SRC_H__ */