2007-02-14 13:13:52 +00:00
|
|
|
/* GStreamer RTP DTMF source
|
|
|
|
*
|
|
|
|
* gstrtpdtmfsrc.c:
|
|
|
|
*
|
2007-02-14 13:55:01 +00:00
|
|
|
* Copyright (C) <2007> Nokia Corporation.
|
|
|
|
* Contact: Zeeshan Ali <zeeshan.ali@nokia.com>
|
2007-02-15 13:48:53 +00:00
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000,2005 Wim Taymans <wim@fluendo.com>
|
2007-02-14 13:55:01 +00:00
|
|
|
*
|
2007-02-14 13:13:52 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-02-16 12:06:06 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-rtpdtmfsrc
|
|
|
|
* @short_description: Generates RTP DTMF packets
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
*
|
|
|
|
* <para>
|
|
|
|
* The RTPDTMFSrc element generates RTP DTMF (RFC 2833) event packets on request
|
|
|
|
* from application. The application communicates the beginning and end of a
|
|
|
|
* DTMF event using custom upstream gstreamer events. To report a DTMF event, an
|
|
|
|
* application must send an event of type GST_EVENT_CUSTOM_UPSTREAM, having a
|
|
|
|
* structure of name "dtmf-event" with fields set according to the following
|
|
|
|
* table:
|
|
|
|
* </para>
|
|
|
|
*
|
|
|
|
* <para>
|
|
|
|
* <informaltable>
|
|
|
|
* <tgroup cols='4'>
|
|
|
|
* <colspec colname='Name' />
|
|
|
|
* <colspec colname='Type' />
|
|
|
|
* <colspec colname='Possible values' />
|
|
|
|
* <colspec colname='Purpose' />
|
2007-08-22 17:55:33 +00:00
|
|
|
*
|
2007-02-16 12:06:06 +00:00
|
|
|
* <thead>
|
|
|
|
* <row>
|
|
|
|
* <entry>Name</entry>
|
|
|
|
* <entry>GType</entry>
|
|
|
|
* <entry>Possible values</entry>
|
|
|
|
* <entry>Purpose</entry>
|
|
|
|
* </row>
|
|
|
|
* </thead>
|
2007-08-22 17:55:33 +00:00
|
|
|
*
|
2007-02-16 12:06:06 +00:00
|
|
|
* <tbody>
|
|
|
|
* <row>
|
|
|
|
* <entry>type</entry>
|
|
|
|
* <entry>G_TYPE_INT</entry>
|
|
|
|
* <entry>0-1</entry>
|
|
|
|
* <entry>The application uses this field to specify which of the two methods
|
|
|
|
* specified in RFC 2833 to use. The value should be 0 for tones and 1 for
|
|
|
|
* named events. This element is only capable of generating named events.
|
|
|
|
* </entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>number</entry>
|
|
|
|
* <entry>G_TYPE_INT</entry>
|
|
|
|
* <entry>0-16</entry>
|
|
|
|
* <entry>The event number.</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>volume</entry>
|
|
|
|
* <entry>G_TYPE_INT</entry>
|
|
|
|
* <entry>0-36</entry>
|
|
|
|
* <entry>This field describes the power level of the tone, expressed in dBm0
|
|
|
|
* after dropping the sign. Power levels range from 0 to -63 dBm0. The range of
|
|
|
|
* valid DTMF is from 0 to -36 dBm0. Can be omitted if start is set to FALSE.
|
|
|
|
* </entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>start</entry>
|
|
|
|
* <entry>G_TYPE_BOOLEAN</entry>
|
|
|
|
* <entry>True or False</entry>
|
2007-05-04 19:52:51 +00:00
|
|
|
* <entry>Whether the event is starting or ending.</entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>method</entry>
|
|
|
|
* <entry>G_TYPE_INT</entry>
|
|
|
|
* <entry>1</entry>
|
2007-08-27 19:56:10 +00:00
|
|
|
* <entry>The method used for sending event, this element will react if this
|
|
|
|
* field is absent or 1.
|
2007-05-04 19:52:51 +00:00
|
|
|
* </entry>
|
2007-02-16 12:06:06 +00:00
|
|
|
* </row>
|
|
|
|
* </tbody>
|
|
|
|
* </tgroup>
|
|
|
|
* </informaltable>
|
|
|
|
* </para>
|
2007-08-22 17:55:33 +00:00
|
|
|
*
|
2007-02-16 12:06:06 +00:00
|
|
|
* <para>For example, the following code informs the pipeline (and in turn, the
|
|
|
|
* RTPDTMFSrc element inside the pipeline) about the start of an RTP DTMF named
|
|
|
|
* event '1' of volume -25 dBm0:
|
|
|
|
* </para>
|
2007-08-22 17:55:33 +00:00
|
|
|
*
|
2007-02-16 12:06:06 +00:00
|
|
|
* <para>
|
|
|
|
* <programlisting>
|
|
|
|
* structure = gst_structure_new ("dtmf-event",
|
2007-03-08 22:35:59 +00:00
|
|
|
* "type", G_TYPE_INT, 1,
|
2007-02-16 12:06:06 +00:00
|
|
|
* "number", G_TYPE_INT, 1,
|
|
|
|
* "volume", G_TYPE_INT, 25,
|
|
|
|
* "start", G_TYPE_BOOLEAN, TRUE, NULL);
|
2007-08-22 17:55:33 +00:00
|
|
|
*
|
2007-02-16 12:06:06 +00:00
|
|
|
* event = gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM, structure);
|
|
|
|
* gst_element_send_event (pipeline, event);
|
|
|
|
* </programlisting>
|
|
|
|
* </para>
|
|
|
|
*
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
2007-02-14 13:13:52 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
#include <glib.h>
|
|
|
|
|
2007-02-14 13:13:52 +00:00
|
|
|
#include "gstrtpdtmfsrc.h"
|
|
|
|
|
2007-02-15 10:10:30 +00:00
|
|
|
#define GST_RTP_DTMF_TYPE_EVENT 1
|
2007-04-24 19:31:55 +00:00
|
|
|
#define DEFAULT_PACKET_INTERVAL 50 /* ms */
|
|
|
|
#define MIN_PACKET_INTERVAL 10 /* ms */
|
|
|
|
#define MAX_PACKET_INTERVAL 50 /* ms */
|
2007-02-15 10:10:30 +00:00
|
|
|
#define DEFAULT_SSRC -1
|
|
|
|
#define DEFAULT_PT 96
|
|
|
|
#define DEFAULT_TIMESTAMP_OFFSET -1
|
|
|
|
#define DEFAULT_SEQNUM_OFFSET -1
|
|
|
|
#define DEFAULT_CLOCK_RATE 8000
|
|
|
|
#define MIN_EVENT 0
|
|
|
|
#define MAX_EVENT 16
|
|
|
|
#define MIN_EVENT_STRING "0"
|
|
|
|
#define MAX_EVENT_STRING "16"
|
|
|
|
#define MIN_VOLUME 0
|
|
|
|
#define MAX_VOLUME 36
|
2007-07-12 19:55:28 +00:00
|
|
|
#define MIN_EVENT_DURATION 50
|
2007-02-14 13:13:52 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
#define MIN_INTER_DIGIT_INTERVAL 50
|
|
|
|
#define MIN_PULSE_DURATION 70
|
|
|
|
#define MIN_DUTY_CYCLE (MIN_INTER_DIGIT_INTERVAL + MIN_PULSE_DURATION)
|
|
|
|
|
2007-04-24 19:31:55 +00:00
|
|
|
#define DEFAULT_PACKET_REDUNDANCY 1
|
|
|
|
#define MIN_PACKET_REDUNDANCY 1
|
|
|
|
#define MAX_PACKET_REDUNDANCY 5
|
|
|
|
|
2007-02-14 13:13:52 +00:00
|
|
|
/* elementfactory information */
|
|
|
|
static const GstElementDetails gst_rtp_dtmf_src_details =
|
|
|
|
GST_ELEMENT_DETAILS ("RTP DTMF packet generator",
|
|
|
|
"Source/Network",
|
|
|
|
"Generates RTP DTMF packets",
|
|
|
|
"Zeeshan Ali <zeeshan.ali@nokia.com>");
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_rtp_dtmf_src_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_rtp_dtmf_src_debug
|
|
|
|
|
|
|
|
/* signals and args */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_SSRC,
|
2007-02-15 10:10:30 +00:00
|
|
|
PROP_TIMESTAMP_OFFSET,
|
|
|
|
PROP_SEQNUM_OFFSET,
|
2007-02-14 13:13:52 +00:00
|
|
|
PROP_PT,
|
|
|
|
PROP_CLOCK_RATE,
|
2007-02-15 10:10:30 +00:00
|
|
|
PROP_TIMESTAMP,
|
2007-04-24 19:31:55 +00:00
|
|
|
PROP_SEQNUM,
|
|
|
|
PROP_INTERVAL,
|
|
|
|
PROP_REDUNDANCY
|
2007-02-14 13:13:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_rtp_dtmf_src_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("application/x-rtp, "
|
|
|
|
"media = (string) \"audio\", "
|
|
|
|
"payload = (int) [ 96, 127 ], "
|
2007-08-22 17:55:33 +00:00
|
|
|
"clock-rate = (int) [ 0, MAX ], "
|
|
|
|
"ssrc = (int) [ 0, MAX ], "
|
2007-02-15 10:10:30 +00:00
|
|
|
"events = (int) [ " MIN_EVENT_STRING ", " MAX_EVENT_STRING " ], "
|
2007-02-14 13:13:52 +00:00
|
|
|
"encoding-name = (string) \"telephone-event\"")
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
|
|
|
|
static void gst_rtp_dtmf_src_base_init (gpointer g_class);
|
|
|
|
static void gst_rtp_dtmf_src_class_init (GstRTPDTMFSrcClass * klass);
|
|
|
|
static void gst_rtp_dtmf_src_init (GstRTPDTMFSrc * dtmfsrc, gpointer g_class);
|
|
|
|
static void gst_rtp_dtmf_src_finalize (GObject * object);
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_rtp_dtmf_src_get_type (void)
|
|
|
|
{
|
|
|
|
static GType base_src_type = 0;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (base_src_type == 0)) {
|
|
|
|
static const GTypeInfo base_src_info = {
|
|
|
|
sizeof (GstRTPDTMFSrcClass),
|
|
|
|
(GBaseInitFunc) gst_rtp_dtmf_src_base_init,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_rtp_dtmf_src_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstRTPDTMFSrc),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_rtp_dtmf_src_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
base_src_type = g_type_register_static (GST_TYPE_ELEMENT,
|
|
|
|
"GstRTPDTMFSrc", &base_src_info, 0);
|
|
|
|
}
|
|
|
|
return base_src_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gst_rtp_dtmf_src_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_rtp_dtmf_src_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static gboolean gst_rtp_dtmf_src_handle_event (GstPad * pad, GstEvent * event);
|
|
|
|
static GstStateChangeReturn gst_rtp_dtmf_src_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
|
|
|
static void gst_rtp_dtmf_src_push_next_rtp_packet (GstRTPDTMFSrc *dtmfsrc);
|
2007-08-22 17:55:33 +00:00
|
|
|
static void gst_rtp_dtmf_src_start (GstRTPDTMFSrc *dtmfsrc);
|
2007-02-14 13:13:52 +00:00
|
|
|
static void gst_rtp_dtmf_src_stop (GstRTPDTMFSrc *dtmfsrc);
|
2007-08-22 17:55:33 +00:00
|
|
|
static void gst_rtp_dtmf_src_add_start_event (GstRTPDTMFSrc *dtmfsrc,
|
|
|
|
gint event_number, gint event_volume);
|
|
|
|
static void gst_rtp_dtmf_src_add_stop_event (GstRTPDTMFSrc *dtmfsrc);
|
2007-02-14 13:13:52 +00:00
|
|
|
static void gst_rtp_dtmf_src_set_caps (GstRTPDTMFSrc *dtmfsrc);
|
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-02-14 13:13:52 +00:00
|
|
|
static void
|
|
|
|
gst_rtp_dtmf_src_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-02-14 13:13:52 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_rtp_dtmf_src_debug,
|
2007-08-20 18:48:52 +00:00
|
|
|
"rtpdtmfsrc", 0, "rtpdtmfsrc element");
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-02-14 13:13:52 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&gst_rtp_dtmf_src_template));
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-02-14 13:13:52 +00:00
|
|
|
gst_element_class_set_details (element_class, &gst_rtp_dtmf_src_details);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_dtmf_src_class_init (GstRTPDTMFSrcClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
gstelement_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
|
|
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_finalize);
|
2007-08-22 17:55:33 +00:00
|
|
|
gobject_class->set_property =
|
2007-02-14 13:13:52 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_set_property);
|
|
|
|
gobject_class->get_property =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_get_property);
|
|
|
|
|
2007-02-15 10:10:30 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_TIMESTAMP,
|
|
|
|
g_param_spec_uint ("timestamp", "Timestamp",
|
|
|
|
"The RTP timestamp of the last processed packet",
|
|
|
|
0, G_MAXUINT, 0, G_PARAM_READABLE));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SEQNUM,
|
|
|
|
g_param_spec_uint ("seqnum", "Sequence number",
|
|
|
|
"The RTP sequence number of the last processed packet",
|
|
|
|
0, G_MAXUINT, 0, G_PARAM_READABLE));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass),
|
|
|
|
PROP_TIMESTAMP_OFFSET, g_param_spec_int ("timestamp-offset",
|
|
|
|
"Timestamp Offset",
|
|
|
|
"Offset to add to all outgoing timestamps (-1 = random)", -1,
|
|
|
|
G_MAXINT, DEFAULT_TIMESTAMP_OFFSET, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SEQNUM_OFFSET,
|
|
|
|
g_param_spec_int ("seqnum-offset", "Sequence number Offset",
|
|
|
|
"Offset to add to all outgoing seqnum (-1 = random)", -1, G_MAXINT,
|
|
|
|
DEFAULT_SEQNUM_OFFSET, G_PARAM_READWRITE));
|
2007-02-14 13:13:52 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_CLOCK_RATE,
|
|
|
|
g_param_spec_uint ("clock-rate", "clockrate",
|
|
|
|
"The clock-rate at which to generate the dtmf packets",
|
|
|
|
0, G_MAXUINT, DEFAULT_CLOCK_RATE, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SSRC,
|
|
|
|
g_param_spec_uint ("ssrc", "SSRC",
|
|
|
|
"The SSRC of the packets (-1 == random)",
|
|
|
|
0, G_MAXUINT, DEFAULT_SSRC, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PT,
|
|
|
|
g_param_spec_uint ("pt", "payload type",
|
|
|
|
"The payload type of the packets",
|
|
|
|
0, 0x80, DEFAULT_PT, G_PARAM_READWRITE));
|
2007-04-24 19:31:55 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_INTERVAL,
|
|
|
|
g_param_spec_int ("interval", "Interval between rtp packets",
|
|
|
|
"Interval in ms between two rtp packets", MIN_PACKET_INTERVAL,
|
|
|
|
MAX_PACKET_INTERVAL, DEFAULT_PACKET_INTERVAL, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_REDUNDANCY,
|
|
|
|
g_param_spec_int ("packet-redundancy", "Packet Redundancy",
|
|
|
|
"Number of packets to send to indicate start and stop dtmf events",
|
|
|
|
MIN_PACKET_REDUNDANCY, MAX_PACKET_REDUNDANCY,
|
|
|
|
DEFAULT_PACKET_REDUNDANCY, G_PARAM_READWRITE));
|
2007-02-14 13:13:52 +00:00
|
|
|
|
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_change_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_dtmf_src_init (GstRTPDTMFSrc * dtmfsrc, gpointer g_class)
|
|
|
|
{
|
|
|
|
dtmfsrc->srcpad =
|
|
|
|
gst_pad_new_from_static_template (&gst_rtp_dtmf_src_template, "src");
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "adding src pad");
|
|
|
|
gst_element_add_pad (GST_ELEMENT (dtmfsrc), dtmfsrc->srcpad);
|
|
|
|
|
|
|
|
gst_pad_set_event_function (dtmfsrc->srcpad, gst_rtp_dtmf_src_handle_event);
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-02-14 13:13:52 +00:00
|
|
|
dtmfsrc->ssrc = DEFAULT_SSRC;
|
2007-02-15 10:10:30 +00:00
|
|
|
dtmfsrc->seqnum_offset = DEFAULT_SEQNUM_OFFSET;
|
|
|
|
dtmfsrc->ts_offset = DEFAULT_TIMESTAMP_OFFSET;
|
2007-02-14 13:13:52 +00:00
|
|
|
dtmfsrc->pt = DEFAULT_PT;
|
|
|
|
dtmfsrc->clock_rate = DEFAULT_CLOCK_RATE;
|
2007-04-24 19:31:55 +00:00
|
|
|
dtmfsrc->interval = DEFAULT_PACKET_INTERVAL;
|
|
|
|
dtmfsrc->packet_redundancy = DEFAULT_PACKET_REDUNDANCY;
|
2007-09-04 22:57:53 +00:00
|
|
|
dtmfsrc->task_paused = TRUE;
|
2007-08-22 17:55:33 +00:00
|
|
|
|
|
|
|
dtmfsrc->event_queue = g_async_queue_new ();
|
|
|
|
dtmfsrc->last_event = NULL;
|
2007-08-28 22:15:34 +00:00
|
|
|
dtmfsrc->clock_id = NULL;
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-02-14 13:13:52 +00:00
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "init done");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_dtmf_src_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstRTPDTMFSrc *dtmfsrc;
|
|
|
|
|
2007-08-28 22:15:34 +00:00
|
|
|
dtmfsrc = GST_RTP_DTMF_SRC (object);
|
2007-08-22 17:55:33 +00:00
|
|
|
|
|
|
|
if (dtmfsrc->event_queue) {
|
|
|
|
g_async_queue_unref (dtmfsrc->event_queue);
|
|
|
|
dtmfsrc->event_queue = NULL;
|
|
|
|
}
|
|
|
|
|
2007-02-14 13:13:52 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2007-04-02 12:46:35 +00:00
|
|
|
static gboolean
|
|
|
|
gst_rtp_dtmf_src_handle_dtmf_event (GstRTPDTMFSrc *dtmfsrc,
|
|
|
|
const GstStructure * event_structure)
|
|
|
|
{
|
|
|
|
gint event_type;
|
|
|
|
gboolean start;
|
2007-05-04 19:52:51 +00:00
|
|
|
gint method;
|
2007-04-02 12:46:35 +00:00
|
|
|
|
|
|
|
if (!gst_structure_get_int (event_structure, "type", &event_type) ||
|
|
|
|
!gst_structure_get_boolean (event_structure, "start", &start) ||
|
|
|
|
event_type != GST_RTP_DTMF_TYPE_EVENT)
|
|
|
|
goto failure;
|
|
|
|
|
2007-05-04 19:52:51 +00:00
|
|
|
if (gst_structure_get_int (event_structure, "method", &method)) {
|
|
|
|
if (method != 1) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-02 12:46:35 +00:00
|
|
|
if (start) {
|
|
|
|
gint event_number;
|
|
|
|
gint event_volume;
|
|
|
|
|
|
|
|
if (!gst_structure_get_int (event_structure, "number", &event_number) ||
|
|
|
|
!gst_structure_get_int (event_structure, "volume", &event_volume))
|
|
|
|
goto failure;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "Received start event %d with volume %d",
|
|
|
|
event_number, event_volume);
|
2007-08-22 17:55:33 +00:00
|
|
|
gst_rtp_dtmf_src_add_start_event (dtmfsrc, event_number, event_volume);
|
2007-04-02 12:46:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "Received stop event");
|
2007-08-22 17:55:33 +00:00
|
|
|
gst_rtp_dtmf_src_add_stop_event (dtmfsrc);
|
2007-04-02 12:46:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
failure:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2007-04-24 20:02:52 +00:00
|
|
|
gst_rtp_dtmf_src_handle_custom_upstream (GstRTPDTMFSrc *dtmfsrc,
|
|
|
|
GstEvent * event)
|
2007-04-02 12:46:35 +00:00
|
|
|
{
|
|
|
|
gboolean result = FALSE;
|
2007-08-22 17:55:33 +00:00
|
|
|
gchar *struct_str;
|
2007-04-02 12:46:35 +00:00
|
|
|
const GstStructure *structure;
|
|
|
|
|
2007-08-28 17:15:46 +00:00
|
|
|
GstState state;
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
2007-08-28 22:15:34 +00:00
|
|
|
ret = gst_element_get_state (GST_ELEMENT (dtmfsrc), &state, NULL, 0);
|
2007-08-28 17:15:46 +00:00
|
|
|
if (ret != GST_STATE_CHANGE_SUCCESS || state != GST_STATE_PLAYING) {
|
2007-04-02 12:46:35 +00:00
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "Received event while not in PLAYING state");
|
|
|
|
goto ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "Received event is of our interest");
|
|
|
|
structure = gst_event_get_structure (event);
|
2007-08-22 17:55:33 +00:00
|
|
|
struct_str = gst_structure_to_string (structure);
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "Event has structure %s", struct_str);
|
|
|
|
g_free (struct_str);
|
2007-04-02 12:46:35 +00:00
|
|
|
if (structure && gst_structure_has_name (structure, "dtmf-event"))
|
|
|
|
result = gst_rtp_dtmf_src_handle_dtmf_event (dtmfsrc, structure);
|
|
|
|
|
|
|
|
ret:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-02-14 13:13:52 +00:00
|
|
|
static gboolean
|
|
|
|
gst_rtp_dtmf_src_handle_event (GstPad * pad, GstEvent * event)
|
|
|
|
{
|
|
|
|
GstRTPDTMFSrc *dtmfsrc;
|
|
|
|
gboolean result = FALSE;
|
2007-08-28 17:15:46 +00:00
|
|
|
GstElement *parent = gst_pad_get_parent_element (pad);
|
2007-08-28 22:15:34 +00:00
|
|
|
dtmfsrc = GST_RTP_DTMF_SRC (parent);
|
2007-02-14 13:13:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "Received an event on the src pad");
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_CUSTOM_UPSTREAM:
|
|
|
|
{
|
2007-04-02 12:46:35 +00:00
|
|
|
result = gst_rtp_dtmf_src_handle_custom_upstream (dtmfsrc, event);
|
2007-02-15 10:10:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-02-15 12:26:55 +00:00
|
|
|
/* Ideally this element should not be flushed but let's handle the event
|
|
|
|
* just in case it is */
|
|
|
|
case GST_EVENT_FLUSH_START:
|
|
|
|
gst_rtp_dtmf_src_stop (dtmfsrc);
|
|
|
|
result = TRUE;
|
2007-02-15 10:10:30 +00:00
|
|
|
break;
|
2007-04-12 20:04:35 +00:00
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
gst_segment_init (&dtmfsrc->segment, GST_FORMAT_UNDEFINED);
|
|
|
|
break;
|
2007-02-14 13:13:52 +00:00
|
|
|
default:
|
2007-02-15 10:10:30 +00:00
|
|
|
result = gst_pad_event_default (pad, event);
|
2007-02-14 13:13:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-02-15 10:10:30 +00:00
|
|
|
|
2007-08-28 17:15:46 +00:00
|
|
|
gst_object_unref (parent);
|
2007-02-14 13:13:52 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_dtmf_src_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstRTPDTMFSrc *dtmfsrc;
|
|
|
|
|
|
|
|
dtmfsrc = GST_RTP_DTMF_SRC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2007-02-15 10:10:30 +00:00
|
|
|
case PROP_TIMESTAMP_OFFSET:
|
|
|
|
dtmfsrc->ts_offset = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_SEQNUM_OFFSET:
|
|
|
|
dtmfsrc->seqnum_offset = g_value_get_int (value);
|
|
|
|
break;
|
2007-02-14 13:13:52 +00:00
|
|
|
case PROP_CLOCK_RATE:
|
|
|
|
dtmfsrc->clock_rate = g_value_get_uint (value);
|
|
|
|
gst_rtp_dtmf_src_set_caps (dtmfsrc);
|
|
|
|
break;
|
|
|
|
case PROP_SSRC:
|
|
|
|
dtmfsrc->ssrc = g_value_get_uint (value);
|
|
|
|
break;
|
|
|
|
case PROP_PT:
|
|
|
|
dtmfsrc->pt = g_value_get_uint (value);
|
|
|
|
gst_rtp_dtmf_src_set_caps (dtmfsrc);
|
|
|
|
break;
|
2007-04-24 20:02:52 +00:00
|
|
|
case PROP_INTERVAL:
|
2007-04-24 19:31:55 +00:00
|
|
|
dtmfsrc->interval = g_value_get_int (value);
|
|
|
|
break;
|
2007-04-24 20:02:52 +00:00
|
|
|
case PROP_REDUNDANCY:
|
2007-04-24 19:31:55 +00:00
|
|
|
dtmfsrc->packet_redundancy = g_value_get_int (value);
|
|
|
|
break;
|
2007-02-14 13:13:52 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_dtmf_src_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstRTPDTMFSrc *dtmfsrc;
|
|
|
|
|
|
|
|
dtmfsrc = GST_RTP_DTMF_SRC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2007-02-15 10:10:30 +00:00
|
|
|
case PROP_TIMESTAMP_OFFSET:
|
|
|
|
g_value_set_int (value, dtmfsrc->ts_offset);
|
|
|
|
break;
|
|
|
|
case PROP_SEQNUM_OFFSET:
|
|
|
|
g_value_set_int (value, dtmfsrc->seqnum_offset);
|
|
|
|
break;
|
2007-02-14 13:13:52 +00:00
|
|
|
case PROP_CLOCK_RATE:
|
|
|
|
g_value_set_uint (value, dtmfsrc->clock_rate);
|
|
|
|
break;
|
|
|
|
case PROP_SSRC:
|
|
|
|
g_value_set_uint (value, dtmfsrc->ssrc);
|
|
|
|
break;
|
|
|
|
case PROP_PT:
|
|
|
|
g_value_set_uint (value, dtmfsrc->pt);
|
|
|
|
break;
|
2007-02-15 10:10:30 +00:00
|
|
|
case PROP_TIMESTAMP:
|
|
|
|
g_value_set_uint (value, dtmfsrc->rtp_timestamp);
|
|
|
|
break;
|
|
|
|
case PROP_SEQNUM:
|
|
|
|
g_value_set_uint (value, dtmfsrc->seqnum);
|
|
|
|
break;
|
2007-04-24 19:31:55 +00:00
|
|
|
case PROP_INTERVAL:
|
|
|
|
g_value_set_uint (value, dtmfsrc->interval);
|
|
|
|
break;
|
|
|
|
case PROP_REDUNDANCY:
|
|
|
|
g_value_set_uint (value, dtmfsrc->packet_redundancy);
|
|
|
|
break;
|
2007-02-14 13:13:52 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-14 17:17:56 +00:00
|
|
|
static void
|
|
|
|
gst_rtp_dtmf_src_set_stream_lock (GstRTPDTMFSrc *dtmfsrc, gboolean lock)
|
|
|
|
{
|
|
|
|
GstEvent *event;
|
|
|
|
GstStructure *structure;
|
|
|
|
|
|
|
|
structure = gst_structure_new ("stream-lock",
|
|
|
|
"lock", G_TYPE_BOOLEAN, lock, NULL);
|
|
|
|
|
|
|
|
event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_OOB, structure);
|
2007-08-28 17:15:46 +00:00
|
|
|
if (!gst_pad_push_event (dtmfsrc->srcpad, event)) {
|
|
|
|
GST_WARNING_OBJECT (dtmfsrc, "stream-lock event not handled");
|
|
|
|
}
|
|
|
|
|
2007-03-14 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
2007-02-14 13:13:52 +00:00
|
|
|
static void
|
2007-04-02 12:46:35 +00:00
|
|
|
gst_rtp_dtmf_prepare_timestamps (GstRTPDTMFSrc *dtmfsrc)
|
2007-02-14 13:13:52 +00:00
|
|
|
{
|
2007-02-15 10:10:30 +00:00
|
|
|
GstClock *clock;
|
|
|
|
|
2007-08-28 22:15:34 +00:00
|
|
|
clock = gst_element_get_clock (GST_ELEMENT (dtmfsrc));
|
2007-08-28 17:15:46 +00:00
|
|
|
if (clock != NULL) {
|
|
|
|
dtmfsrc->timestamp = gst_clock_get_time (clock)
|
2007-08-27 19:56:10 +00:00
|
|
|
+ (MIN_INTER_DIGIT_INTERVAL * GST_MSECOND);
|
2007-08-28 17:15:46 +00:00
|
|
|
gst_object_unref (clock);
|
|
|
|
} else {
|
|
|
|
gchar *dtmf_name = gst_element_get_name (dtmfsrc);
|
|
|
|
GST_ERROR_OBJECT (dtmfsrc, "No clock set for element %s", dtmf_name);
|
2007-02-15 10:10:30 +00:00
|
|
|
dtmfsrc->timestamp = GST_CLOCK_TIME_NONE;
|
2007-08-28 17:15:46 +00:00
|
|
|
g_free (dtmf_name);
|
2007-02-15 10:10:30 +00:00
|
|
|
}
|
|
|
|
|
2007-03-30 15:43:03 +00:00
|
|
|
dtmfsrc->rtp_timestamp = dtmfsrc->ts_base +
|
2007-03-30 00:17:00 +00:00
|
|
|
gst_util_uint64_scale_int (
|
2007-04-12 20:04:35 +00:00
|
|
|
gst_segment_to_running_time (&dtmfsrc->segment, GST_FORMAT_TIME,
|
2007-07-12 16:23:28 +00:00
|
|
|
dtmfsrc->timestamp),
|
2007-04-12 20:04:35 +00:00
|
|
|
dtmfsrc->clock_rate, GST_SECOND);
|
2007-04-02 12:46:35 +00:00
|
|
|
}
|
2007-02-15 10:10:30 +00:00
|
|
|
|
2007-04-02 12:46:35 +00:00
|
|
|
static void
|
2007-08-22 17:55:33 +00:00
|
|
|
gst_rtp_dtmf_src_start (GstRTPDTMFSrc *dtmfsrc)
|
2007-04-02 12:46:35 +00:00
|
|
|
{
|
2007-03-26 10:57:12 +00:00
|
|
|
gst_rtp_dtmf_src_set_caps (dtmfsrc);
|
|
|
|
|
2007-09-04 22:57:53 +00:00
|
|
|
dtmfsrc->task_paused = FALSE;
|
2007-02-14 13:13:52 +00:00
|
|
|
if (!gst_pad_start_task (dtmfsrc->srcpad,
|
|
|
|
(GstTaskFunction) gst_rtp_dtmf_src_push_next_rtp_packet, dtmfsrc)) {
|
|
|
|
GST_ERROR_OBJECT (dtmfsrc, "Failed to start task on src pad");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_dtmf_src_stop (GstRTPDTMFSrc *dtmfsrc)
|
|
|
|
{
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-08-28 22:15:34 +00:00
|
|
|
GstRTPDTMFSrcEvent *event = NULL;
|
|
|
|
|
2007-09-04 22:57:53 +00:00
|
|
|
dtmfsrc->task_paused = TRUE;
|
2007-09-04 20:55:09 +00:00
|
|
|
GST_OBJECT_LOCK (dtmfsrc);
|
2007-08-28 22:15:34 +00:00
|
|
|
if (dtmfsrc->clock_id != NULL) {
|
|
|
|
gst_clock_id_unschedule(dtmfsrc->clock_id);
|
|
|
|
}
|
2007-09-04 20:55:09 +00:00
|
|
|
GST_OBJECT_UNLOCK (dtmfsrc);
|
2007-08-28 22:15:34 +00:00
|
|
|
|
2007-08-31 23:44:13 +00:00
|
|
|
event = g_malloc (sizeof(GstRTPDTMFSrcEvent));
|
|
|
|
event->event_type = RTP_DTMF_EVENT_TYPE_PAUSE_TASK;
|
2007-09-04 20:55:09 +00:00
|
|
|
g_async_queue_push (dtmfsrc->event_queue, event);
|
2007-08-31 23:44:13 +00:00
|
|
|
|
|
|
|
event = NULL;
|
|
|
|
|
2007-08-28 22:15:34 +00:00
|
|
|
if (!gst_pad_pause_task (dtmfsrc->srcpad)) {
|
|
|
|
GST_ERROR_OBJECT (dtmfsrc, "Failed to pause task on src pad");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-08-31 23:44:13 +00:00
|
|
|
|
2007-08-28 22:15:34 +00:00
|
|
|
if (dtmfsrc->last_event) {
|
|
|
|
/* Don't forget to release the stream lock */
|
|
|
|
gst_rtp_dtmf_src_set_stream_lock (dtmfsrc, FALSE);
|
|
|
|
g_free (dtmfsrc->last_event);
|
|
|
|
dtmfsrc->last_event = NULL;
|
|
|
|
}
|
2007-08-22 17:55:33 +00:00
|
|
|
|
|
|
|
/* Flushing the event queue */
|
2007-08-28 22:15:34 +00:00
|
|
|
event = g_async_queue_try_pop (dtmfsrc->event_queue);
|
2007-08-22 17:55:33 +00:00
|
|
|
|
|
|
|
while (event != NULL) {
|
|
|
|
g_free (event);
|
|
|
|
event = g_async_queue_try_pop (dtmfsrc->event_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_dtmf_src_add_start_event (GstRTPDTMFSrc *dtmfsrc, gint event_number,
|
|
|
|
gint event_volume)
|
|
|
|
{
|
|
|
|
|
|
|
|
GstRTPDTMFSrcEvent * event = g_malloc (sizeof(GstRTPDTMFSrcEvent));
|
|
|
|
event->event_type = RTP_DTMF_EVENT_TYPE_START;
|
|
|
|
|
|
|
|
event->payload = g_new0 (GstRTPDTMFPayload, 1);
|
|
|
|
event->payload->event = CLAMP (event_number, MIN_EVENT, MAX_EVENT);
|
|
|
|
event->payload->volume = CLAMP (event_volume, MIN_VOLUME, MAX_VOLUME);
|
|
|
|
|
|
|
|
g_async_queue_push (dtmfsrc->event_queue, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_dtmf_src_add_stop_event (GstRTPDTMFSrc *dtmfsrc)
|
|
|
|
{
|
2007-02-14 13:13:52 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
GstRTPDTMFSrcEvent * event = g_malloc (sizeof(GstRTPDTMFSrcEvent));
|
|
|
|
event->event_type = RTP_DTMF_EVENT_TYPE_STOP;
|
|
|
|
event->payload = g_new0 (GstRTPDTMFPayload, 1);
|
|
|
|
event->payload->event = 0;
|
|
|
|
event->payload->volume = 0;
|
2007-02-14 13:13:52 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
g_async_queue_push (dtmfsrc->event_queue, event);
|
2007-02-14 13:13:52 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-02-14 13:13:52 +00:00
|
|
|
static void
|
2007-04-02 12:46:35 +00:00
|
|
|
gst_rtp_dtmf_src_wait_for_buffer_ts (GstRTPDTMFSrc *dtmfsrc, GstBuffer * buf)
|
2007-02-14 13:13:52 +00:00
|
|
|
{
|
2007-04-02 12:46:35 +00:00
|
|
|
GstClock *clock;
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-08-28 22:15:34 +00:00
|
|
|
clock = gst_element_get_clock (GST_ELEMENT (dtmfsrc));
|
2007-04-02 12:46:35 +00:00
|
|
|
if (clock != NULL) {
|
|
|
|
GstClockReturn clock_ret;
|
2007-09-04 20:55:09 +00:00
|
|
|
GstClockID clock_id;
|
2007-02-14 13:13:52 +00:00
|
|
|
|
2007-09-04 20:55:09 +00:00
|
|
|
clock_id = gst_clock_new_single_shot_id (clock, GST_BUFFER_TIMESTAMP (buf));
|
2007-08-28 17:15:46 +00:00
|
|
|
gst_object_unref (clock);
|
2007-08-28 22:15:34 +00:00
|
|
|
|
2007-09-04 20:55:09 +00:00
|
|
|
GST_OBJECT_LOCK (dtmfsrc);
|
|
|
|
dtmfsrc->clock_id = clock_id;
|
|
|
|
GST_OBJECT_UNLOCK (dtmfsrc);
|
|
|
|
|
2007-09-04 22:57:53 +00:00
|
|
|
if (dtmfsrc->task_paused) {
|
|
|
|
clock_ret = GST_CLOCK_UNSCHEDULED;
|
|
|
|
} else {
|
|
|
|
clock_ret = gst_clock_id_wait (dtmfsrc->clock_id, NULL);
|
|
|
|
}
|
2007-09-04 20:55:09 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (dtmfsrc);
|
|
|
|
dtmfsrc->clock_id = NULL;
|
|
|
|
gst_clock_id_unref (clock_id);
|
|
|
|
GST_OBJECT_UNLOCK (dtmfsrc);
|
|
|
|
|
2007-08-28 22:15:34 +00:00
|
|
|
if (clock_ret == GST_CLOCK_UNSCHEDULED) {
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "Clock wait unscheduled");
|
|
|
|
} else {
|
|
|
|
if (clock_ret != GST_CLOCK_OK && clock_ret != GST_CLOCK_EARLY) {
|
|
|
|
gchar *clock_name = NULL;
|
|
|
|
|
|
|
|
clock = gst_element_get_clock (GST_ELEMENT (dtmfsrc));
|
|
|
|
clock_name = gst_element_get_name (clock);
|
|
|
|
gst_object_unref (clock);
|
|
|
|
|
|
|
|
GST_ERROR_OBJECT (dtmfsrc, "Failed to wait on clock %s", clock_name);
|
|
|
|
g_free (clock_name);
|
|
|
|
}
|
|
|
|
}
|
2007-04-02 12:46:35 +00:00
|
|
|
}
|
2007-02-14 13:13:52 +00:00
|
|
|
|
2007-04-02 12:46:35 +00:00
|
|
|
else {
|
2007-08-28 17:15:46 +00:00
|
|
|
gchar *dtmf_name = gst_element_get_name (dtmfsrc);
|
|
|
|
GST_ERROR_OBJECT (dtmfsrc, "No clock set for element %s", dtmf_name);
|
|
|
|
g_free (dtmf_name);
|
2007-04-02 12:46:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-08-27 19:56:10 +00:00
|
|
|
gst_rtp_dtmf_prepare_rtp_headers (GstRTPDTMFSrc *dtmfsrc,
|
|
|
|
GstRTPDTMFSrcEvent *event, GstBuffer *buf)
|
2007-04-02 12:46:35 +00:00
|
|
|
{
|
2007-02-14 13:13:52 +00:00
|
|
|
gst_rtp_buffer_set_ssrc (buf, dtmfsrc->current_ssrc);
|
|
|
|
gst_rtp_buffer_set_payload_type (buf, dtmfsrc->pt);
|
|
|
|
if (dtmfsrc->first_packet) {
|
|
|
|
gst_rtp_buffer_set_marker (buf, TRUE);
|
|
|
|
dtmfsrc->first_packet = FALSE;
|
2007-07-12 19:57:15 +00:00
|
|
|
} else if (dtmfsrc->last_packet) {
|
2007-08-22 17:55:33 +00:00
|
|
|
event->payload->e = 1;
|
2007-07-12 19:57:15 +00:00
|
|
|
dtmfsrc->last_packet = FALSE;
|
2007-02-14 13:13:52 +00:00
|
|
|
}
|
2007-07-12 19:57:15 +00:00
|
|
|
|
2007-02-15 10:10:30 +00:00
|
|
|
dtmfsrc->seqnum++;
|
|
|
|
gst_rtp_buffer_set_seq (buf, dtmfsrc->seqnum);
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-03-29 10:39:46 +00:00
|
|
|
/* timestamp of RTP header */
|
|
|
|
gst_rtp_buffer_set_timestamp (buf, dtmfsrc->rtp_timestamp);
|
2007-04-02 12:46:35 +00:00
|
|
|
}
|
2007-03-30 00:17:00 +00:00
|
|
|
|
2007-04-02 12:46:35 +00:00
|
|
|
static void
|
2007-08-27 19:56:10 +00:00
|
|
|
gst_rtp_dtmf_prepare_buffer_data (GstRTPDTMFSrc *dtmfsrc,
|
|
|
|
GstRTPDTMFSrcEvent *event,GstBuffer *buf)
|
2007-04-02 12:46:35 +00:00
|
|
|
{
|
|
|
|
GstRTPDTMFPayload *payload;
|
2007-08-22 17:55:33 +00:00
|
|
|
|
|
|
|
gst_rtp_dtmf_prepare_rtp_headers (dtmfsrc,event, buf);
|
2007-03-29 10:39:46 +00:00
|
|
|
|
2007-07-12 19:55:28 +00:00
|
|
|
/* duration of DTMF payload */
|
2007-08-22 17:55:33 +00:00
|
|
|
event->payload->duration +=
|
2007-07-12 19:55:28 +00:00
|
|
|
dtmfsrc->interval * dtmfsrc->clock_rate / 1000;
|
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
/* timestamp and duration of GstBuffer */
|
2007-04-24 19:31:55 +00:00
|
|
|
GST_BUFFER_DURATION (buf) = dtmfsrc->interval * GST_MSECOND;
|
2007-02-15 10:10:30 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (buf) = dtmfsrc->timestamp;
|
2007-03-29 11:42:57 +00:00
|
|
|
dtmfsrc->timestamp += GST_BUFFER_DURATION (buf);
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-02-14 13:13:52 +00:00
|
|
|
payload = (GstRTPDTMFPayload *) gst_rtp_buffer_get_payload (buf);
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-02-14 13:13:52 +00:00
|
|
|
/* copy payload and convert to network-byte order */
|
2007-08-22 17:55:33 +00:00
|
|
|
g_memmove (payload, event->payload, sizeof (GstRTPDTMFPayload));
|
2007-07-12 19:55:28 +00:00
|
|
|
/* Force the packet duration to a certain minumum
|
|
|
|
* if its the end of the event
|
|
|
|
*/
|
|
|
|
if (payload->e &&
|
|
|
|
payload->duration < MIN_EVENT_DURATION * dtmfsrc->clock_rate / 1000)
|
|
|
|
payload->duration = MIN_EVENT_DURATION * dtmfsrc->clock_rate / 1000;
|
2007-07-11 15:51:57 +00:00
|
|
|
|
2007-07-12 19:55:28 +00:00
|
|
|
payload->duration = g_htons (payload->duration);
|
2007-04-02 12:46:35 +00:00
|
|
|
}
|
2007-02-14 13:13:52 +00:00
|
|
|
|
2007-04-02 12:46:35 +00:00
|
|
|
static GstBuffer *
|
2007-08-27 19:56:10 +00:00
|
|
|
gst_rtp_dtmf_src_create_next_rtp_packet (GstRTPDTMFSrc *dtmfsrc,
|
|
|
|
GstRTPDTMFSrcEvent *event)
|
2007-04-02 12:46:35 +00:00
|
|
|
{
|
|
|
|
GstBuffer *buf = NULL;
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-04-02 12:46:35 +00:00
|
|
|
/* create buffer to hold the payload */
|
|
|
|
buf = gst_rtp_buffer_new_allocate (sizeof (GstRTPDTMFPayload), 0, 0);
|
2007-02-14 13:13:52 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
gst_rtp_dtmf_prepare_buffer_data (dtmfsrc, event, buf);
|
2007-02-14 13:13:52 +00:00
|
|
|
|
2007-04-02 12:46:35 +00:00
|
|
|
/* FIXME: Should we sync to clock ourselves or leave it to sink */
|
|
|
|
gst_rtp_dtmf_src_wait_for_buffer_ts (dtmfsrc, buf);
|
2007-02-14 13:13:52 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
event->sent_packets++;
|
|
|
|
|
2007-03-23 16:29:22 +00:00
|
|
|
/* Set caps on the buffer before pushing it */
|
|
|
|
gst_buffer_set_caps (buf, GST_PAD_CAPS (dtmfsrc->srcpad));
|
2007-04-02 12:46:35 +00:00
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_dtmf_src_push_next_rtp_packet (GstRTPDTMFSrc *dtmfsrc)
|
|
|
|
{
|
|
|
|
GstBuffer *buf = NULL;
|
|
|
|
GstFlowReturn ret;
|
2007-04-24 19:31:55 +00:00
|
|
|
gint redundancy_count = 1;
|
2007-08-22 17:55:33 +00:00
|
|
|
GstRTPDTMFSrcEvent *event;
|
2007-04-24 19:31:55 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
g_async_queue_ref (dtmfsrc->event_queue);
|
2007-04-24 19:31:55 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
if (dtmfsrc->last_event == NULL) {
|
|
|
|
event = g_async_queue_pop (dtmfsrc->event_queue);
|
2007-04-24 19:31:55 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
if (event->event_type == RTP_DTMF_EVENT_TYPE_STOP) {
|
2007-08-27 19:56:10 +00:00
|
|
|
GST_WARNING_OBJECT (dtmfsrc,
|
|
|
|
"Received a DTMF stop event when already stopped");
|
2007-08-22 17:55:33 +00:00
|
|
|
} else if (event->event_type == RTP_DTMF_EVENT_TYPE_START) {
|
2007-04-02 12:46:35 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
dtmfsrc->first_packet = TRUE;
|
|
|
|
dtmfsrc->last_packet = FALSE;
|
|
|
|
gst_rtp_dtmf_prepare_timestamps (dtmfsrc);
|
2007-04-02 12:46:35 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
/* Don't forget to get exclusive access to the stream */
|
|
|
|
gst_rtp_dtmf_src_set_stream_lock (dtmfsrc, TRUE);
|
2007-04-24 19:31:55 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
event->sent_packets = 0;
|
|
|
|
|
|
|
|
dtmfsrc->last_event = event;
|
2007-08-31 23:44:13 +00:00
|
|
|
} else if (event->event_type == RTP_DTMF_EVENT_TYPE_PAUSE_TASK) {
|
2007-09-04 20:55:09 +00:00
|
|
|
/*
|
|
|
|
* We're pushing it back because it has to stay in there until
|
|
|
|
* the task is really paused (and the queue will then be flushed
|
|
|
|
*/
|
|
|
|
g_async_queue_push (dtmfsrc->event_queue, event);
|
2007-08-31 23:44:13 +00:00
|
|
|
g_async_queue_unref (dtmfsrc->event_queue);
|
|
|
|
return;
|
2007-08-22 17:55:33 +00:00
|
|
|
}
|
2007-08-27 19:56:10 +00:00
|
|
|
} else if (dtmfsrc->last_event->sent_packets * dtmfsrc->interval >=
|
|
|
|
MIN_PULSE_DURATION){
|
2007-08-22 17:55:33 +00:00
|
|
|
event = g_async_queue_try_pop (dtmfsrc->event_queue);
|
|
|
|
|
|
|
|
if (event != NULL) {
|
|
|
|
if (event->event_type == RTP_DTMF_EVENT_TYPE_START) {
|
2007-08-27 19:56:10 +00:00
|
|
|
GST_WARNING_OBJECT (dtmfsrc,
|
|
|
|
"Received two consecutive DTMF start events");
|
2007-08-22 17:55:33 +00:00
|
|
|
} else if (event->event_type == RTP_DTMF_EVENT_TYPE_STOP) {
|
2007-08-27 19:56:10 +00:00
|
|
|
dtmfsrc->first_packet = FALSE;
|
|
|
|
dtmfsrc->last_packet = TRUE;
|
2007-08-22 17:55:33 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-24 19:31:55 +00:00
|
|
|
}
|
2007-08-22 17:55:33 +00:00
|
|
|
g_async_queue_unref (dtmfsrc->event_queue);
|
2007-04-24 19:31:55 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
if (dtmfsrc->last_event) {
|
2007-07-12 19:57:15 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
if (dtmfsrc->first_packet == TRUE || dtmfsrc->last_packet == TRUE) {
|
|
|
|
redundancy_count = dtmfsrc->packet_redundancy;
|
2007-07-12 19:57:15 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
if(dtmfsrc->first_packet == TRUE) {
|
2007-08-27 19:56:10 +00:00
|
|
|
GST_DEBUG_OBJECT (dtmfsrc,
|
|
|
|
"redundancy count set to %d due to dtmf start",
|
|
|
|
redundancy_count);
|
2007-08-22 17:55:33 +00:00
|
|
|
} else if(dtmfsrc->last_packet == TRUE) {
|
2007-08-27 19:56:10 +00:00
|
|
|
GST_DEBUG_OBJECT (dtmfsrc,
|
|
|
|
"redundancy count set to %d due to dtmf stop",
|
|
|
|
redundancy_count);
|
2007-08-22 17:55:33 +00:00
|
|
|
}
|
2007-07-12 19:57:15 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
/* create buffer to hold the payload */
|
2007-08-27 19:56:10 +00:00
|
|
|
buf = gst_rtp_dtmf_src_create_next_rtp_packet (dtmfsrc,
|
|
|
|
dtmfsrc->last_event);
|
2007-08-22 17:55:33 +00:00
|
|
|
|
|
|
|
while ( redundancy_count-- ) {
|
|
|
|
gst_buffer_ref(buf);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc,
|
2007-08-27 19:56:10 +00:00
|
|
|
"pushing buffer on src pad of size %d with redundancy count %d",
|
|
|
|
GST_BUFFER_SIZE (buf), redundancy_count);
|
2007-08-22 17:55:33 +00:00
|
|
|
ret = gst_pad_push (dtmfsrc->srcpad, buf);
|
|
|
|
if (ret != GST_FLOW_OK)
|
2007-08-27 19:56:10 +00:00
|
|
|
GST_ERROR_OBJECT (dtmfsrc,
|
|
|
|
"Failed to push buffer on src pad");
|
2007-08-22 17:55:33 +00:00
|
|
|
|
|
|
|
/* Make sure only the first packet sent has the marker set */
|
|
|
|
gst_rtp_buffer_set_marker (buf, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_buffer_unref(buf);
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc,
|
2007-08-28 22:15:34 +00:00
|
|
|
"pushed DTMF event '%d' on src pad", dtmfsrc->last_event->payload->event);
|
2007-07-12 19:57:15 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
if (dtmfsrc->last_event->payload->e) {
|
|
|
|
/* Don't forget to release the stream lock */
|
|
|
|
gst_rtp_dtmf_src_set_stream_lock (dtmfsrc, FALSE);
|
|
|
|
|
|
|
|
g_free (dtmfsrc->last_event->payload);
|
2007-08-28 22:15:34 +00:00
|
|
|
dtmfsrc->last_event->payload = NULL;
|
2007-08-22 17:55:33 +00:00
|
|
|
|
|
|
|
g_free (dtmfsrc->last_event);
|
|
|
|
dtmfsrc->last_event = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2007-02-14 13:13:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_dtmf_src_set_caps (GstRTPDTMFSrc *dtmfsrc)
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
caps = gst_caps_new_simple ("application/x-rtp",
|
|
|
|
"media", G_TYPE_STRING, "audio",
|
|
|
|
"payload", G_TYPE_INT, dtmfsrc->pt,
|
|
|
|
"clock-rate", G_TYPE_INT, dtmfsrc->clock_rate,
|
|
|
|
"encoding-name", G_TYPE_STRING, "telephone-event",
|
2007-02-15 10:10:30 +00:00
|
|
|
"ssrc", G_TYPE_UINT, dtmfsrc->current_ssrc,
|
|
|
|
"clock-base", G_TYPE_UINT, dtmfsrc->ts_base,
|
|
|
|
"seqnum-base", G_TYPE_UINT, dtmfsrc->seqnum_base, NULL);
|
2007-02-14 13:13:52 +00:00
|
|
|
|
2007-03-29 10:39:04 +00:00
|
|
|
if (!gst_pad_set_caps (dtmfsrc->srcpad, caps))
|
2007-03-07 11:41:09 +00:00
|
|
|
GST_ERROR_OBJECT (dtmfsrc,
|
|
|
|
"Failed to set caps %" GST_PTR_FORMAT " on src pad", caps);
|
2007-03-29 10:39:04 +00:00
|
|
|
else
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc,
|
|
|
|
"caps %" GST_PTR_FORMAT " set on src pad", caps);
|
2007-02-14 13:13:52 +00:00
|
|
|
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
|
2007-04-02 12:46:35 +00:00
|
|
|
static void
|
|
|
|
gst_rtp_dtmf_src_ready_to_paused (GstRTPDTMFSrc *dtmfsrc)
|
|
|
|
{
|
2007-04-12 20:04:35 +00:00
|
|
|
gst_segment_init (&dtmfsrc->segment, GST_FORMAT_UNDEFINED);
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-04-02 12:46:35 +00:00
|
|
|
if (dtmfsrc->ssrc == -1)
|
|
|
|
dtmfsrc->current_ssrc = g_random_int ();
|
|
|
|
else
|
|
|
|
dtmfsrc->current_ssrc = dtmfsrc->ssrc;
|
|
|
|
|
|
|
|
if (dtmfsrc->seqnum_offset == -1)
|
|
|
|
dtmfsrc->seqnum_base = g_random_int_range (0, G_MAXUINT16);
|
|
|
|
else
|
|
|
|
dtmfsrc->seqnum_base = dtmfsrc->seqnum_offset;
|
|
|
|
dtmfsrc->seqnum = dtmfsrc->seqnum_base;
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-04-02 12:46:35 +00:00
|
|
|
if (dtmfsrc->ts_offset == -1)
|
|
|
|
dtmfsrc->ts_base = g_random_int ();
|
|
|
|
else
|
|
|
|
dtmfsrc->ts_base = dtmfsrc->ts_offset;
|
|
|
|
}
|
|
|
|
|
2007-02-14 13:13:52 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_rtp_dtmf_src_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstRTPDTMFSrc *dtmfsrc;
|
|
|
|
GstStateChangeReturn result;
|
2007-03-30 00:17:00 +00:00
|
|
|
gboolean no_preroll = FALSE;
|
2007-02-14 13:13:52 +00:00
|
|
|
|
|
|
|
dtmfsrc = GST_RTP_DTMF_SRC (element);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2007-04-02 12:46:35 +00:00
|
|
|
gst_rtp_dtmf_src_ready_to_paused (dtmfsrc);
|
2007-02-14 13:13:52 +00:00
|
|
|
/* Indicate that we don't do PRE_ROLL */
|
|
|
|
no_preroll = TRUE;
|
|
|
|
break;
|
2007-08-22 17:55:33 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
|
|
|
gst_rtp_dtmf_src_start (dtmfsrc);
|
|
|
|
break;
|
2007-02-14 13:13:52 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((result =
|
|
|
|
GST_ELEMENT_CLASS (parent_class)->change_state (element,
|
|
|
|
transition)) == GST_STATE_CHANGE_FAILURE)
|
|
|
|
goto failure;
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
|
|
|
/* Indicate that we don't do PRE_ROLL */
|
|
|
|
no_preroll = TRUE;
|
2007-08-22 17:55:33 +00:00
|
|
|
gst_rtp_dtmf_src_stop (dtmfsrc);
|
2007-02-14 13:13:52 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (no_preroll && result == GST_STATE_CHANGE_SUCCESS)
|
|
|
|
result = GST_STATE_CHANGE_NO_PREROLL;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
failure:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (dtmfsrc, "parent failed state change");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-20 18:48:52 +00:00
|
|
|
gboolean
|
2007-02-14 13:13:52 +00:00
|
|
|
gst_rtp_dtmf_src_plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
|
|
|
return gst_element_register (plugin, "rtpdtmfsrc",
|
|
|
|
GST_RANK_NONE, GST_TYPE_RTP_DTMF_SRC);
|
|
|
|
}
|