dtmf: port to 0.11

This commit is contained in:
Olivier Crête 2012-01-25 11:21:50 +01:00
parent 8c2d0ab637
commit bc44628831
5 changed files with 153 additions and 179 deletions

View file

@ -101,50 +101,42 @@ static gboolean gst_dtmf_detect_set_caps (GstBaseTransform * trans,
GstCaps * incaps, GstCaps * outcaps); GstCaps * incaps, GstCaps * outcaps);
static GstFlowReturn gst_dtmf_detect_transform_ip (GstBaseTransform * trans, static GstFlowReturn gst_dtmf_detect_transform_ip (GstBaseTransform * trans,
GstBuffer * buf); GstBuffer * buf);
static gboolean gst_dtmf_detect_event (GstBaseTransform * trans, static gboolean gst_dtmf_detect_sink_event (GstBaseTransform * trans,
GstEvent * event); GstEvent * event);
static void G_DEFINE_TYPE (GstDtmfDetect, gst_dtmf_detect, GST_TYPE_BASE_TRANSFORM);
_do_init (GType type)
{
GST_DEBUG_CATEGORY_INIT (dtmf_detect_debug, "dtmfdetect", 0, "dtmfdetect");
}
GST_BOILERPLATE_FULL (GstDtmfDetect, gst_dtmf_detect, GstBaseTransform,
GST_TYPE_BASE_TRANSFORM, _do_init);
static void
gst_dtmf_detect_base_init (gpointer klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&srctemplate));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&sinktemplate));
gst_element_class_set_details_simple (element_class, "DTMF detector element",
"Filter/Analyzer/Audio",
"This element detects DTMF tones",
"Olivier Crete <olivier.crete@collabora.co.uk>");
}
static void static void
gst_dtmf_detect_class_init (GstDtmfDetectClass * klass) gst_dtmf_detect_class_init (GstDtmfDetectClass * klass)
{ {
GstElementClass *gstelement_class;
GstBaseTransformClass *gstbasetransform_class; GstBaseTransformClass *gstbasetransform_class;
gstelement_class = GST_ELEMENT_CLASS (klass);
gstbasetransform_class = (GstBaseTransformClass *) klass; gstbasetransform_class = (GstBaseTransformClass *) klass;
GST_DEBUG_CATEGORY_INIT (dtmf_detect_debug, "dtmfdetect", 0, "dtmfdetect");
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&srctemplate));
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&sinktemplate));
gst_element_class_set_metadata (gstelement_class, "DTMF detector element",
"Filter/Analyzer/Audio",
"This element detects DTMF tones",
"Olivier Crete <olivier.crete@collabora.com>");
gstbasetransform_class->set_caps = gstbasetransform_class->set_caps =
GST_DEBUG_FUNCPTR (gst_dtmf_detect_set_caps); GST_DEBUG_FUNCPTR (gst_dtmf_detect_set_caps);
gstbasetransform_class->transform_ip = gstbasetransform_class->transform_ip =
GST_DEBUG_FUNCPTR (gst_dtmf_detect_transform_ip); GST_DEBUG_FUNCPTR (gst_dtmf_detect_transform_ip);
gstbasetransform_class->event = GST_DEBUG_FUNCPTR (gst_dtmf_detect_event); gstbasetransform_class->sink_event =
GST_DEBUG_FUNCPTR (gst_dtmf_detect_sink_event);
} }
static void static void
gst_dtmf_detect_init (GstDtmfDetect * dtmfdetect, GstDtmfDetectClass * klass) gst_dtmf_detect_init (GstDtmfDetect * dtmfdetect)
{ {
gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (dtmfdetect), TRUE); gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (dtmfdetect), TRUE);
gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM (dtmfdetect), TRUE); gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM (dtmfdetect), TRUE);
@ -169,14 +161,17 @@ gst_dtmf_detect_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
gint dtmf_count; gint dtmf_count;
gchar dtmfbuf[MAX_DTMF_DIGITS] = ""; gchar dtmfbuf[MAX_DTMF_DIGITS] = "";
gint i; gint i;
gpointer data;
gsize size;
if (GST_BUFFER_IS_DISCONT (buf)) if (GST_BUFFER_IS_DISCONT (buf))
zap_dtmf_detect_init (&self->dtmf_state); zap_dtmf_detect_init (&self->dtmf_state);
if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_GAP)) if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_GAP))
return GST_FLOW_OK; return GST_FLOW_OK;
zap_dtmf_detect (&self->dtmf_state, (gint16 *) GST_BUFFER_DATA (buf), data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
GST_BUFFER_SIZE (buf) / 2, FALSE);
zap_dtmf_detect (&self->dtmf_state, (gint16 *) data, size / 2, FALSE);
dtmf_count = zap_dtmf_get (&self->dtmf_state, dtmfbuf, MAX_DTMF_DIGITS); dtmf_count = zap_dtmf_get (&self->dtmf_state, dtmfbuf, MAX_DTMF_DIGITS);
@ -185,6 +180,8 @@ gst_dtmf_detect_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
else else
GST_LOG_OBJECT (self, "Got no DTMF events"); GST_LOG_OBJECT (self, "Got no DTMF events");
gst_buffer_unmap (buf, data, size);
for (i = 0; i < dtmf_count; i++) { for (i = 0; i < dtmf_count; i++) {
GstMessage *dtmf_message = NULL; GstMessage *dtmf_message = NULL;
GstStructure *structure; GstStructure *structure;
@ -258,7 +255,7 @@ gst_dtmf_detect_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
static gboolean static gboolean
gst_dtmf_detect_event (GstBaseTransform * trans, GstEvent * event) gst_dtmf_detect_sink_event (GstBaseTransform * trans, GstEvent * event)
{ {
GstDtmfDetect *self = GST_DTMF_DETECT (trans); GstDtmfDetect *self = GST_DTMF_DETECT (trans);
@ -270,8 +267,7 @@ gst_dtmf_detect_event (GstBaseTransform * trans, GstEvent * event)
break; break;
} }
return GST_CALL_PARENT_WITH_DEFAULT (GST_BASE_TRANSFORM_CLASS, event, return GST_BASE_TRANSFORM_GET_CLASS (trans)->sink_event (trans, event);
(trans, event), TRUE);
} }

View file

@ -211,7 +211,7 @@ GST_STATIC_PAD_TEMPLATE ("src",
"signed = (bool) true, rate = (int) [1, MAX], channels = (int) 1") "signed = (bool) true, rate = (int) [1, MAX], channels = (int) 1")
); );
GST_BOILERPLATE (GstDTMFSrc, gst_dtmf_src, GstBaseSrc, GST_TYPE_BASE_SRC); G_DEFINE_TYPE (GstDTMFSrc, gst_dtmf_src, GST_TYPE_BASE_SRC);
static void gst_dtmf_src_finalize (GObject * object); static void gst_dtmf_src_finalize (GObject * object);
@ -234,21 +234,6 @@ 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
gst_dtmf_src_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
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));
gst_element_class_set_details_simple (element_class, "DTMF tone generator",
"Source/Audio",
"Generates DTMF tones",
"Youness Alaoui <youness.alaoui@collabora.co.uk>");
}
static void static void
gst_dtmf_src_class_init (GstDTMFSrcClass * klass) gst_dtmf_src_class_init (GstDTMFSrcClass * klass)
@ -262,6 +247,17 @@ gst_dtmf_src_class_init (GstDTMFSrcClass * klass)
gstelement_class = GST_ELEMENT_CLASS (klass); gstelement_class = GST_ELEMENT_CLASS (klass);
GST_DEBUG_CATEGORY_INIT (gst_dtmf_src_debug, "dtmfsrc", 0, "dtmfsrc element");
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_dtmf_src_template));
gst_element_class_set_details_simple (gstelement_class, "DTMF tone generator",
"Source/Audio",
"Generates DTMF tones",
"Youness Alaoui <youness.alaoui@collabora.co.uk>");
gobject_class->finalize = gst_dtmf_src_finalize; gobject_class->finalize = gst_dtmf_src_finalize;
gobject_class->set_property = gst_dtmf_src_set_property; gobject_class->set_property = gst_dtmf_src_set_property;
gobject_class->get_property = gst_dtmf_src_get_property; gobject_class->get_property = gst_dtmf_src_get_property;
@ -291,7 +287,7 @@ event_free (GstDTMFSrcEvent * event)
} }
static void static void
gst_dtmf_src_init (GstDTMFSrc * dtmfsrc, GstDTMFSrcClass * g_class) gst_dtmf_src_init (GstDTMFSrc * dtmfsrc)
{ {
/* 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);
@ -319,7 +315,7 @@ gst_dtmf_src_finalize (GObject * object)
dtmfsrc->event_queue = NULL; dtmfsrc->event_queue = NULL;
} }
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (gst_dtmf_src_parent_class)->finalize (object);
} }
static gboolean static gboolean
@ -426,7 +422,8 @@ gst_dtmf_src_send_event (GstElement * element, GstEvent * event)
if (gst_dtmf_src_handle_event (GST_BASE_SRC (element), event)) if (gst_dtmf_src_handle_event (GST_BASE_SRC (element), event))
return TRUE; return TRUE;
return GST_ELEMENT_CLASS (parent_class)->send_event (element, event); return GST_ELEMENT_CLASS (gst_dtmf_src_parent_class)->send_event
(element, event);
} }
static void static void
@ -528,24 +525,22 @@ gst_dtmf_src_add_stop_event (GstDTMFSrc * dtmfsrc)
g_async_queue_push (dtmfsrc->event_queue, event); g_async_queue_push (dtmfsrc->event_queue, event);
} }
static void static GstBuffer *
gst_dtmf_src_generate_silence (GstBuffer * buffer, float duration, gst_dtmf_src_generate_silence (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_MALLOCDATA (buffer) = g_malloc0 (buf_size);
GST_BUFFER_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer);
return gst_buffer_new_wrapped (g_malloc0 (buf_size), buf_size);
} }
static void static GstBuffer *
gst_dtmf_src_generate_tone (GstDTMFSrcEvent * event, DTMF_KEY key, gst_dtmf_src_generate_tone (GstDTMFSrcEvent * event, DTMF_KEY key,
float duration, GstBuffer * buffer, gint sample_rate) float duration, gint sample_rate)
{ {
GstBuffer *buffer;
gint16 *p; gint16 *p;
gint tone_size; gint tone_size;
double i = 0; double i = 0;
@ -554,11 +549,10 @@ gst_dtmf_src_generate_tone (GstDTMFSrcEvent * event, DTMF_KEY key,
/* 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_MALLOCDATA (buffer) = g_malloc (tone_size);
GST_BUFFER_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer);
p = (gint16 *) GST_BUFFER_MALLOCDATA (buffer); buffer = gst_buffer_new_allocate (NULL, tone_size, 1);
p = (gint16 *) gst_buffer_map (buffer, NULL, NULL, GST_MAP_READWRITE);
volume_factor = pow (10, (-event->volume) / 20); volume_factor = pow (10, (-event->volume) / 20);
@ -586,6 +580,10 @@ gst_dtmf_src_generate_tone (GstDTMFSrcEvent * event, DTMF_KEY key,
(event->sample)++; (event->sample)++;
} }
gst_buffer_unmap (buffer, p, tone_size);
return buffer;
} }
@ -596,26 +594,22 @@ gst_dtmf_src_create_next_tone_packet (GstDTMFSrc * dtmfsrc,
{ {
GstBuffer *buf = NULL; GstBuffer *buf = NULL;
gboolean send_silence = FALSE; gboolean send_silence = FALSE;
GstPad *srcpad = GST_BASE_SRC_PAD (dtmfsrc);
GST_LOG_OBJECT (dtmfsrc, "Creating buffer for tone %s", GST_LOG_OBJECT (dtmfsrc, "Creating buffer for tone %s",
DTMF_KEYS[event->event_number].event_name); DTMF_KEYS[event->event_number].event_name);
/* create buffer to hold the tone */
buf = gst_buffer_new ();
if (event->packet_count * dtmfsrc->interval < MIN_INTER_DIGIT_INTERVAL) { if (event->packet_count * dtmfsrc->interval < MIN_INTER_DIGIT_INTERVAL) {
send_silence = TRUE; send_silence = TRUE;
} }
if (send_silence) { if (send_silence) {
GST_LOG_OBJECT (dtmfsrc, "Generating silence"); GST_LOG_OBJECT (dtmfsrc, "Generating silence");
gst_dtmf_src_generate_silence (buf, dtmfsrc->interval, buf = gst_dtmf_src_generate_silence (dtmfsrc->interval,
dtmfsrc->sample_rate); dtmfsrc->sample_rate);
} else { } else {
GST_LOG_OBJECT (dtmfsrc, "Generating tone"); GST_LOG_OBJECT (dtmfsrc, "Generating tone");
gst_dtmf_src_generate_tone (event, DTMF_KEYS[event->event_number], buf = gst_dtmf_src_generate_tone (event, DTMF_KEYS[event->event_number],
dtmfsrc->interval, buf, dtmfsrc->sample_rate); dtmfsrc->interval, dtmfsrc->sample_rate);
} }
event->packet_count++; event->packet_count++;
@ -631,9 +625,6 @@ gst_dtmf_src_create_next_tone_packet (GstDTMFSrc * dtmfsrc,
dtmfsrc->timestamp += GST_BUFFER_DURATION (buf); dtmfsrc->timestamp += GST_BUFFER_DURATION (buf);
/* Set caps on the buffer before pushing it */
gst_buffer_set_caps (buf, GST_PAD_CAPS (srcpad));
return buf; return buf;
} }
@ -787,7 +778,8 @@ 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_LOG_OBJECT (dtmfsrc, "Created buffer of size %d", GST_BUFFER_SIZE (buf)); GST_LOG_OBJECT (dtmfsrc, "Created buffer of size %d",
gst_buffer_get_size (buf));
*buffer = buf; *buffer = buf;
return GST_FLOW_OK; return GST_FLOW_OK;
@ -912,7 +904,7 @@ gst_dtmf_src_change_state (GstElement * element, GstStateChange transition)
} }
if ((result = if ((result =
GST_ELEMENT_CLASS (parent_class)->change_state (element, GST_ELEMENT_CLASS (gst_dtmf_src_parent_class)->change_state (element,
transition)) == GST_STATE_CHANGE_FAILURE) transition)) == GST_STATE_CHANGE_FAILURE)
goto failure; goto failure;

View file

@ -199,47 +199,40 @@ GST_STATIC_PAD_TEMPLATE ("sink",
"encoding-name = (string) \"TELEPHONE-EVENT\"") "encoding-name = (string) \"TELEPHONE-EVENT\"")
); );
GST_BOILERPLATE (GstRtpDTMFDepay, gst_rtp_dtmf_depay, GstBaseRTPDepayload, G_DEFINE_TYPE (GstRtpDTMFDepay, gst_rtp_dtmf_depay,
GST_TYPE_BASE_RTP_DEPAYLOAD); GST_TYPE_RTP_BASE_DEPAYLOAD);
static void gst_rtp_dtmf_depay_set_property (GObject * object, guint prop_id, static void gst_rtp_dtmf_depay_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec); const GValue * value, GParamSpec * pspec);
static void gst_rtp_dtmf_depay_get_property (GObject * object, guint prop_id, static void gst_rtp_dtmf_depay_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec); GValue * value, GParamSpec * pspec);
static GstBuffer *gst_rtp_dtmf_depay_process (GstBaseRTPDepayload * depayload, static GstBuffer *gst_rtp_dtmf_depay_process (GstRTPBaseDepayload * depayload,
GstBuffer * buf); GstBuffer * buf);
gboolean gst_rtp_dtmf_depay_setcaps (GstBaseRTPDepayload * filter, gboolean gst_rtp_dtmf_depay_setcaps (GstRTPBaseDepayload * filter,
GstCaps * caps); GstCaps * caps);
static void
gst_rtp_dtmf_depay_base_init (gpointer klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_rtp_dtmf_depay_src_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_rtp_dtmf_depay_sink_template));
GST_DEBUG_CATEGORY_INIT (gst_rtp_dtmf_depay_debug,
"rtpdtmfdepay", 0, "rtpdtmfdepay element");
gst_element_class_set_details_simple (element_class,
"RTP DTMF packet depayloader", "Codec/Depayloader/Network",
"Generates DTMF Sound from telephone-event RTP packets",
"Youness Alaoui <youness.alaoui@collabora.co.uk>");
}
static void static void
gst_rtp_dtmf_depay_class_init (GstRtpDTMFDepayClass * klass) gst_rtp_dtmf_depay_class_init (GstRtpDTMFDepayClass * klass)
{ {
GObjectClass *gobject_class; GObjectClass *gobject_class;
GstBaseRTPDepayloadClass *gstbasertpdepayload_class; GstElementClass *gstelement_class;
GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
gobject_class = (GObjectClass *) klass; gobject_class = G_OBJECT_CLASS (klass);
gstbasertpdepayload_class = (GstBaseRTPDepayloadClass *) klass; gstelement_class = GST_ELEMENT_CLASS (klass);
gstrtpbasedepayload_class = GST_RTP_BASE_DEPAYLOAD_CLASS (klass);
parent_class = g_type_class_peek_parent (klass); gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_rtp_dtmf_depay_src_template));
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_rtp_dtmf_depay_sink_template));
GST_DEBUG_CATEGORY_INIT (gst_rtp_dtmf_depay_debug,
"rtpdtmfdepay", 0, "rtpdtmfdepay element");
gst_element_class_set_details_simple (gstelement_class,
"RTP DTMF packet depayloader", "Codec/Depayloader/Network",
"Generates DTMF Sound from telephone-event RTP packets",
"Youness Alaoui <youness.alaoui@collabora.co.uk>");
gobject_class->set_property = gobject_class->set_property =
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_depay_set_property); GST_DEBUG_FUNCPTR (gst_rtp_dtmf_depay_set_property);
@ -258,16 +251,15 @@ gst_rtp_dtmf_depay_class_init (GstRtpDTMFDepayClass * klass)
"(0 = no limit)", 0, G_MAXUINT, DEFAULT_MAX_DURATION, "(0 = no limit)", 0, G_MAXUINT, DEFAULT_MAX_DURATION,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gstbasertpdepayload_class->process = gstrtpbasedepayload_class->process =
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_depay_process); GST_DEBUG_FUNCPTR (gst_rtp_dtmf_depay_process);
gstbasertpdepayload_class->set_caps = gstrtpbasedepayload_class->set_caps =
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_depay_setcaps); GST_DEBUG_FUNCPTR (gst_rtp_dtmf_depay_setcaps);
} }
static void static void
gst_rtp_dtmf_depay_init (GstRtpDTMFDepay * rtpdtmfdepay, gst_rtp_dtmf_depay_init (GstRtpDTMFDepay * rtpdtmfdepay)
GstRtpDTMFDepayClass * klass)
{ {
rtpdtmfdepay->unit_time = DEFAULT_UNIT_TIME; rtpdtmfdepay->unit_time = DEFAULT_UNIT_TIME;
} }
@ -315,7 +307,7 @@ gst_rtp_dtmf_depay_get_property (GObject * object, guint prop_id,
} }
gboolean gboolean
gst_rtp_dtmf_depay_setcaps (GstBaseRTPDepayload * filter, GstCaps * caps) gst_rtp_dtmf_depay_setcaps (GstRTPBaseDepayload * filter, GstCaps * caps)
{ {
GstCaps *srccaps; GstCaps *srccaps;
GstStructure *structure = gst_caps_get_structure (caps, 0); GstStructure *structure = gst_caps_get_structure (caps, 0);
@ -330,16 +322,17 @@ gst_rtp_dtmf_depay_setcaps (GstBaseRTPDepayload * filter, GstCaps * caps)
"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, "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_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (filter), srccaps);
gst_caps_unref (srccaps); gst_caps_unref (srccaps);
return TRUE; return TRUE;
} }
static void static GstBuffer *
gst_dtmf_src_generate_tone (GstRtpDTMFDepay * rtpdtmfdepay, gst_dtmf_src_generate_tone (GstRtpDTMFDepay * rtpdtmfdepay,
GstRTPDTMFPayload payload, GstBuffer * buffer) GstRTPDTMFPayload payload)
{ {
GstBuffer *buf;
gint16 *p; gint16 *p;
gint tone_size; gint tone_size;
double i = 0; double i = 0;
@ -347,20 +340,18 @@ gst_dtmf_src_generate_tone (GstRtpDTMFDepay * rtpdtmfdepay,
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); GstRTPBaseDepayload *depayload = GST_RTP_BASE_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; buf = gst_buffer_new_allocate (NULL, tone_size, 1);
GST_BUFFER_MALLOCDATA (buffer) = g_malloc (tone_size); GST_BUFFER_DURATION (buf) = payload.duration * GST_SECOND / clock_rate;
GST_BUFFER_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer);
GST_BUFFER_DURATION (buffer) = payload.duration * GST_SECOND / clock_rate;
volume = payload.volume; volume = payload.volume;
p = (gint16 *) GST_BUFFER_MALLOCDATA (buffer); p = (gint16 *) gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
volume_factor = pow (10, (-volume) / 20); volume_factor = pow (10, (-volume) / 20);
@ -390,11 +381,15 @@ gst_dtmf_src_generate_tone (GstRtpDTMFDepay * rtpdtmfdepay,
(rtpdtmfdepay->sample)++; (rtpdtmfdepay->sample)++;
} }
gst_buffer_unmap (buf, p, tone_size);
return buf;
} }
static GstBuffer * static GstBuffer *
gst_rtp_dtmf_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf) gst_rtp_dtmf_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
{ {
GstRtpDTMFDepay *rtpdtmfdepay = NULL; GstRtpDTMFDepay *rtpdtmfdepay = NULL;
@ -406,14 +401,17 @@ gst_rtp_dtmf_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
gboolean marker; gboolean marker;
GstStructure *structure = NULL; GstStructure *structure = NULL;
GstMessage *dtmf_message = NULL; GstMessage *dtmf_message = NULL;
GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT;
rtpdtmfdepay = GST_RTP_DTMF_DEPAY (depayload); rtpdtmfdepay = GST_RTP_DTMF_DEPAY (depayload);
if (!gst_rtp_buffer_validate (buf)) if (!gst_rtp_buffer_validate (buf))
goto bad_packet; goto bad_packet;
payload_len = gst_rtp_buffer_get_payload_len (buf); gst_rtp_buffer_map (buf, GST_MAP_READ, &rtpbuffer);
payload = gst_rtp_buffer_get_payload (buf);
payload_len = gst_rtp_buffer_get_payload_len (&rtpbuffer);
payload = gst_rtp_buffer_get_payload (&rtpbuffer);
if (payload_len != sizeof (GstRTPDTMFPayload)) if (payload_len != sizeof (GstRTPDTMFPayload))
goto bad_packet; goto bad_packet;
@ -424,9 +422,9 @@ gst_rtp_dtmf_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
goto bad_packet; goto bad_packet;
marker = gst_rtp_buffer_get_marker (buf); marker = gst_rtp_buffer_get_marker (&rtpbuffer);
timestamp = gst_rtp_buffer_get_timestamp (buf); timestamp = gst_rtp_buffer_get_timestamp (&rtpbuffer);
dtmf_payload.duration = g_ntohs (dtmf_payload.duration); dtmf_payload.duration = g_ntohs (dtmf_payload.duration);
@ -467,7 +465,7 @@ gst_rtp_dtmf_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
rtpdtmfdepay->sample = 0; rtpdtmfdepay->sample = 0;
rtpdtmfdepay->previous_ts = timestamp; rtpdtmfdepay->previous_ts = timestamp;
rtpdtmfdepay->previous_duration = dtmf_payload.duration; rtpdtmfdepay->previous_duration = dtmf_payload.duration;
rtpdtmfdepay->first_gst_ts = GST_BUFFER_TIMESTAMP (buf); rtpdtmfdepay->first_gst_ts = GST_BUFFER_PTS (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,
@ -503,11 +501,10 @@ 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_dtmf_src_generate_tone (rtpdtmfdepay, dtmf_payload);
gst_dtmf_src_generate_tone (rtpdtmfdepay, dtmf_payload, outbuf);
GST_BUFFER_TIMESTAMP (outbuf) = rtpdtmfdepay->first_gst_ts + GST_BUFFER_PTS (outbuf) = rtpdtmfdepay->first_gst_ts +
(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 (outbuf) = GST_BUFFER_OFFSET (outbuf) =
@ -522,12 +519,17 @@ gst_rtp_dtmf_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
} }
return outbuf; gst_rtp_buffer_unmap (&rtpbuffer);
return outbuf;
bad_packet: bad_packet:
GST_ELEMENT_WARNING (rtpdtmfdepay, STREAM, DECODE, GST_ELEMENT_WARNING (rtpdtmfdepay, STREAM, DECODE,
("Packet did not validate"), (NULL)); ("Packet did not validate"), (NULL));
if (rtpbuffer.buffer != NULL)
gst_rtp_buffer_unmap (&rtpbuffer);
return NULL; return NULL;
} }

View file

@ -25,7 +25,7 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/base/gstadapter.h> #include <gst/base/gstadapter.h>
#include <gst/rtp/gstbasertpdepayload.h> #include <gst/rtp/gstrtpbasedepayload.h>
#include "gstdtmfcommon.h" #include "gstdtmfcommon.h"
@ -46,7 +46,7 @@ typedef struct _GstRtpDTMFDepayClass GstRtpDTMFDepayClass;
struct _GstRtpDTMFDepay struct _GstRtpDTMFDepay
{ {
/*< private >*/ /*< private >*/
GstBaseRTPDepayload depayload; GstRTPBaseDepayload depayload;
double sample; double sample;
guint32 previous_ts; guint32 previous_ts;
guint16 previous_duration; guint16 previous_duration;
@ -57,7 +57,7 @@ struct _GstRtpDTMFDepay
struct _GstRtpDTMFDepayClass struct _GstRtpDTMFDepayClass
{ {
GstBaseRTPDepayloadClass parent_class; GstRTPBaseDepayloadClass parent_class;
}; };
GType gst_rtp_dtmf_depay_get_type (void); GType gst_rtp_dtmf_depay_get_type (void);

View file

@ -176,8 +176,7 @@ GST_STATIC_PAD_TEMPLATE ("src",
); );
GST_BOILERPLATE (GstRTPDTMFSrc, gst_rtp_dtmf_src, GstBaseSrc, G_DEFINE_TYPE (GstRTPDTMFSrc, gst_rtp_dtmf_src, GST_TYPE_BASE_SRC);
GST_TYPE_BASE_SRC);
static void gst_rtp_dtmf_src_finalize (GObject * object); static void gst_rtp_dtmf_src_finalize (GObject * object);
@ -200,22 +199,6 @@ static GstFlowReturn gst_rtp_dtmf_src_create (GstBaseSrc * basesrc,
static gboolean gst_rtp_dtmf_src_negotiate (GstBaseSrc * basesrc); static gboolean gst_rtp_dtmf_src_negotiate (GstBaseSrc * basesrc);
static void
gst_rtp_dtmf_src_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
GST_DEBUG_CATEGORY_INIT (gst_rtp_dtmf_src_debug,
"rtpdtmfsrc", 0, "rtpdtmfsrc element");
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_rtp_dtmf_src_template));
gst_element_class_set_details_simple (element_class,
"RTP DTMF packet generator", "Source/Network",
"Generates RTP DTMF packets", "Zeeshan Ali <zeeshan.ali@nokia.com>");
}
static void static void
gst_rtp_dtmf_src_class_init (GstRTPDTMFSrcClass * klass) gst_rtp_dtmf_src_class_init (GstRTPDTMFSrcClass * klass)
{ {
@ -227,7 +210,15 @@ gst_rtp_dtmf_src_class_init (GstRTPDTMFSrcClass * klass)
gstbasesrc_class = GST_BASE_SRC_CLASS (klass); gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
gstelement_class = GST_ELEMENT_CLASS (klass); gstelement_class = GST_ELEMENT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass); GST_DEBUG_CATEGORY_INIT (gst_rtp_dtmf_src_debug,
"rtpdtmfsrc", 0, "rtpdtmfsrc element");
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_rtp_dtmf_src_template));
gst_element_class_set_metadata (gstelement_class,
"RTP DTMF packet generator", "Source/Network",
"Generates RTP DTMF packets", "Zeeshan Ali <zeeshan.ali@nokia.com>");
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_finalize); gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_finalize);
gobject_class->set_property = gobject_class->set_property =
@ -297,7 +288,7 @@ gst_rtp_dtmf_src_event_free (GstRTPDTMFSrcEvent * event)
} }
static void static void
gst_rtp_dtmf_src_init (GstRTPDTMFSrc * object, GstRTPDTMFSrcClass * g_class) gst_rtp_dtmf_src_init (GstRTPDTMFSrc * object)
{ {
gst_base_src_set_format (GST_BASE_SRC (object), GST_FORMAT_TIME); gst_base_src_set_format (GST_BASE_SRC (object), GST_FORMAT_TIME);
gst_base_src_set_live (GST_BASE_SRC (object), TRUE); gst_base_src_set_live (GST_BASE_SRC (object), TRUE);
@ -330,7 +321,7 @@ gst_rtp_dtmf_src_finalize (GObject * object)
} }
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (gst_rtp_dtmf_src_parent_class)->finalize (object);
} }
static gboolean static gboolean
@ -577,30 +568,37 @@ 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,
GstRTPBuffer * rtpbuf)
{ {
gst_rtp_buffer_set_ssrc (buf, dtmfsrc->current_ssrc); gst_rtp_buffer_set_ssrc (rtpbuf, dtmfsrc->current_ssrc);
gst_rtp_buffer_set_payload_type (buf, dtmfsrc->pt); gst_rtp_buffer_set_payload_type (rtpbuf, dtmfsrc->pt);
/* Only the very first packet gets a marker */ /* Only the very first packet gets a marker */
if (dtmfsrc->first_packet) { if (dtmfsrc->first_packet) {
gst_rtp_buffer_set_marker (buf, TRUE); gst_rtp_buffer_set_marker (rtpbuf, TRUE);
} else if (dtmfsrc->last_packet) { } else if (dtmfsrc->last_packet) {
dtmfsrc->payload->e = 1; dtmfsrc->payload->e = 1;
} }
dtmfsrc->seqnum++; dtmfsrc->seqnum++;
gst_rtp_buffer_set_seq (buf, dtmfsrc->seqnum); gst_rtp_buffer_set_seq (rtpbuf, dtmfsrc->seqnum);
/* timestamp of RTP header */ /* timestamp of RTP header */
gst_rtp_buffer_set_timestamp (buf, dtmfsrc->rtp_timestamp); gst_rtp_buffer_set_timestamp (rtpbuf, dtmfsrc->rtp_timestamp);
} }
static void static GstBuffer *
gst_rtp_dtmf_prepare_buffer_data (GstRTPDTMFSrc * dtmfsrc, GstBuffer * buf) gst_rtp_dtmf_src_create_next_rtp_packet (GstRTPDTMFSrc * dtmfsrc)
{ {
GstBuffer *buf;
GstRTPDTMFPayload *payload; GstRTPDTMFPayload *payload;
GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT;
gst_rtp_dtmf_prepare_rtp_headers (dtmfsrc, buf); buf = gst_rtp_buffer_new_allocate (sizeof (GstRTPDTMFPayload), 0, 0);
gst_rtp_buffer_map (buf, GST_MAP_READWRITE, &rtpbuffer);
gst_rtp_dtmf_prepare_rtp_headers (dtmfsrc, &rtpbuffer);
/* timestamp and duration of GstBuffer */ /* timestamp and duration of GstBuffer */
/* Redundant buffer have no duration ... */ /* Redundant buffer have no duration ... */
@ -608,10 +606,9 @@ gst_rtp_dtmf_prepare_buffer_data (GstRTPDTMFSrc * dtmfsrc, GstBuffer * buf)
GST_BUFFER_DURATION (buf) = 0; GST_BUFFER_DURATION (buf) = 0;
else else
GST_BUFFER_DURATION (buf) = dtmfsrc->ptime * GST_MSECOND; GST_BUFFER_DURATION (buf) = dtmfsrc->ptime * GST_MSECOND;
GST_BUFFER_TIMESTAMP (buf) = dtmfsrc->timestamp; GST_BUFFER_PTS (buf) = dtmfsrc->timestamp;
payload = (GstRTPDTMFPayload *) gst_rtp_buffer_get_payload (&rtpbuffer);
payload = (GstRTPDTMFPayload *) gst_rtp_buffer_get_payload (buf);
/* copy payload and convert to network-byte order */ /* copy payload and convert to network-byte order */
g_memmove (payload, dtmfsrc->payload, sizeof (GstRTPDTMFPayload)); g_memmove (payload, dtmfsrc->payload, sizeof (GstRTPDTMFPayload));
@ -642,20 +639,7 @@ gst_rtp_dtmf_prepare_buffer_data (GstRTPDTMFSrc * dtmfsrc, GstBuffer * buf)
if (GST_CLOCK_TIME_IS_VALID (dtmfsrc->timestamp)) if (GST_CLOCK_TIME_IS_VALID (dtmfsrc->timestamp))
dtmfsrc->timestamp += GST_BUFFER_DURATION (buf); dtmfsrc->timestamp += GST_BUFFER_DURATION (buf);
} gst_rtp_buffer_unmap (&rtpbuffer);
static GstBuffer *
gst_rtp_dtmf_src_create_next_rtp_packet (GstRTPDTMFSrc * dtmfsrc)
{
GstBuffer *buf = NULL;
/* create buffer to hold the payload */
buf = gst_rtp_buffer_new_allocate (sizeof (GstRTPDTMFPayload), 0, 0);
gst_rtp_dtmf_prepare_buffer_data (dtmfsrc, buf);
/* Set caps on the buffer before pushing it */
gst_buffer_set_caps (buf, GST_PAD_CAPS (GST_BASE_SRC_PAD (dtmfsrc)));
return buf; return buf;
} }
@ -884,7 +868,7 @@ gst_rtp_dtmf_src_negotiate (GstBaseSrc * basesrc)
"encoding-name", G_TYPE_STRING, "TELEPHONE-EVENT", NULL); "encoding-name", G_TYPE_STRING, "TELEPHONE-EVENT", NULL);
/* the peer caps can override some of the defaults */ /* the peer caps can override some of the defaults */
peercaps = gst_pad_peer_get_caps (GST_BASE_SRC_PAD (basesrc)); peercaps = gst_pad_peer_query_caps (GST_BASE_SRC_PAD (basesrc), NULL);
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,
@ -1068,8 +1052,8 @@ gst_rtp_dtmf_src_change_state (GstElement * element, GstStateChange transition)
} }
if ((result = if ((result =
GST_ELEMENT_CLASS (parent_class)->change_state (element, GST_ELEMENT_CLASS (gst_rtp_dtmf_src_parent_class)->change_state
transition)) == GST_STATE_CHANGE_FAILURE) (element, transition)) == GST_STATE_CHANGE_FAILURE)
goto failure; goto failure;
switch (transition) { switch (transition) {