2007-08-20 18:48:00 +00:00
|
|
|
/* GStreamer RTP DTMF source
|
|
|
|
*
|
|
|
|
* gstrtpdtmfsrc.c:
|
|
|
|
*
|
|
|
|
* Copyright (C) <2007> Nokia Corporation.
|
|
|
|
* Contact: Zeeshan Ali <zeeshan.ali@nokia.com>
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000,2005 Wim Taymans <wim@fluendo.com>
|
|
|
|
*
|
|
|
|
* 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
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2007-08-20 18:48:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:element-rtpdtmfsrc
|
2009-02-20 23:16:02 +00:00
|
|
|
* @see_also: dtmfsrc, rtpdtmfdepay, rtpdtmfmux
|
2007-08-20 18:48:00 +00:00
|
|
|
*
|
|
|
|
* 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:
|
|
|
|
*
|
|
|
|
* <informaltable>
|
|
|
|
* <tgroup cols='4'>
|
|
|
|
* <colspec colname='Name' />
|
|
|
|
* <colspec colname='Type' />
|
|
|
|
* <colspec colname='Possible values' />
|
|
|
|
* <colspec colname='Purpose' />
|
|
|
|
* <thead>
|
|
|
|
* <row>
|
|
|
|
* <entry>Name</entry>
|
|
|
|
* <entry>GType</entry>
|
|
|
|
* <entry>Possible values</entry>
|
|
|
|
* <entry>Purpose</entry>
|
|
|
|
* </row>
|
|
|
|
* </thead>
|
|
|
|
* <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
|
2008-10-15 20:21:50 +00:00
|
|
|
* named events. Tones are specified by their frequencies and events are specied
|
|
|
|
* by their number. This element can only take events as input. Do not confuse
|
|
|
|
* with "method" which specified the output.
|
2007-08-20 18:48:00 +00:00
|
|
|
* </entry>
|
|
|
|
* </row>
|
|
|
|
* <row>
|
|
|
|
* <entry>number</entry>
|
|
|
|
* <entry>G_TYPE_INT</entry>
|
2011-07-12 23:09:02 +00:00
|
|
|
* <entry>0-15</entry>
|
2007-08-20 18:48:00 +00:00
|
|
|
* <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>
|
|
|
|
* <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-08-20 18:48:00 +00:00
|
|
|
* </entry>
|
|
|
|
* </row>
|
|
|
|
* </tbody>
|
|
|
|
* </tgroup>
|
|
|
|
* </informaltable>
|
2007-08-22 17:55:33 +00:00
|
|
|
*
|
2009-02-20 22:40:57 +00:00
|
|
|
* For example, the following code informs the pipeline (and in turn, the
|
2007-08-20 18:48:00 +00:00
|
|
|
* RTPDTMFSrc element inside the pipeline) about the start of an RTP DTMF named
|
|
|
|
* event '1' of volume -25 dBm0:
|
2007-08-22 17:55:33 +00:00
|
|
|
*
|
2007-08-20 18:48:00 +00:00
|
|
|
* <programlisting>
|
|
|
|
* structure = gst_structure_new ("dtmf-event",
|
|
|
|
* "type", G_TYPE_INT, 1,
|
|
|
|
* "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-08-20 18:48:00 +00:00
|
|
|
* event = gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM, structure);
|
|
|
|
* gst_element_send_event (pipeline, event);
|
|
|
|
* </programlisting>
|
|
|
|
*
|
2011-10-29 16:24:26 +00:00
|
|
|
* When a DTMF tone actually starts or stop, a "dtmf-event-processed"
|
|
|
|
* element #GstMessage with the same fields as the "dtmf-event"
|
|
|
|
* #GstEvent that was used to request the event. Also, if any event
|
|
|
|
* has not been processed when the element goes from the PAUSED to the
|
|
|
|
* READY state, then a "dtmf-event-dropped" message is posted on the
|
|
|
|
* #GstBus in the order that they were received.
|
|
|
|
*/
|
2007-08-20 18:48:00 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2011-04-12 20:42:17 +00:00
|
|
|
#include "config.h"
|
2007-08-20 18:48:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
#include <glib.h>
|
|
|
|
|
2007-08-20 18:48:00 +00:00
|
|
|
#include "gstrtpdtmfsrc.h"
|
|
|
|
|
|
|
|
#define GST_RTP_DTMF_TYPE_EVENT 1
|
2011-04-14 20:49:39 +00:00
|
|
|
#define DEFAULT_PTIME 40 /* ms */
|
2007-08-20 18:48:00 +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
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-08-20 18:48:00 +00:00
|
|
|
#define DEFAULT_PACKET_REDUNDANCY 1
|
|
|
|
#define MIN_PACKET_REDUNDANCY 1
|
|
|
|
#define MAX_PACKET_REDUNDANCY 5
|
|
|
|
|
|
|
|
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,
|
|
|
|
PROP_TIMESTAMP_OFFSET,
|
|
|
|
PROP_SEQNUM_OFFSET,
|
|
|
|
PROP_PT,
|
|
|
|
PROP_CLOCK_RATE,
|
|
|
|
PROP_TIMESTAMP,
|
|
|
|
PROP_SEQNUM,
|
|
|
|
PROP_REDUNDANCY
|
|
|
|
};
|
|
|
|
|
|
|
|
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 ], "
|
2008-03-19 19:32:51 +00:00
|
|
|
"encoding-name = (string) \"TELEPHONE-EVENT\"")
|
2008-06-13 23:30:06 +00:00
|
|
|
/* "events = (string) \"0-15\" */
|
2007-08-20 18:48:00 +00:00
|
|
|
);
|
|
|
|
|
2007-09-16 19:44:08 +00:00
|
|
|
|
2012-01-25 10:21:50 +00:00
|
|
|
G_DEFINE_TYPE (GstRTPDTMFSrc, gst_rtp_dtmf_src, GST_TYPE_BASE_SRC);
|
2007-09-16 19:44:08 +00:00
|
|
|
|
2007-08-20 18:48:00 +00:00
|
|
|
static void gst_rtp_dtmf_src_finalize (GObject * object);
|
|
|
|
|
|
|
|
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);
|
2009-02-20 22:37:43 +00:00
|
|
|
static gboolean gst_rtp_dtmf_src_handle_event (GstBaseSrc * basesrc,
|
2007-09-16 19:44:08 +00:00
|
|
|
GstEvent * event);
|
2007-08-20 18:48:00 +00:00
|
|
|
static GstStateChangeReturn gst_rtp_dtmf_src_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
2009-02-20 22:37:43 +00:00
|
|
|
static void gst_rtp_dtmf_src_add_start_event (GstRTPDTMFSrc * dtmfsrc,
|
2007-08-22 17:55:33 +00:00
|
|
|
gint event_number, gint event_volume);
|
2009-02-20 22:37:43 +00:00
|
|
|
static void gst_rtp_dtmf_src_add_stop_event (GstRTPDTMFSrc * dtmfsrc);
|
2007-08-20 18:48:00 +00:00
|
|
|
|
2009-02-20 22:37:43 +00:00
|
|
|
static gboolean gst_rtp_dtmf_src_unlock (GstBaseSrc * src);
|
|
|
|
static gboolean gst_rtp_dtmf_src_unlock_stop (GstBaseSrc * src);
|
2007-09-16 19:44:08 +00:00
|
|
|
static GstFlowReturn gst_rtp_dtmf_src_create (GstBaseSrc * basesrc,
|
|
|
|
guint64 offset, guint length, GstBuffer ** buffer);
|
2007-09-17 00:24:12 +00:00
|
|
|
static gboolean gst_rtp_dtmf_src_negotiate (GstBaseSrc * basesrc);
|
2015-09-01 19:39:22 +00:00
|
|
|
static gboolean gst_rtp_dtmf_src_query (GstBaseSrc * basesrc, GstQuery * query);
|
2007-09-16 19:44:08 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-08-20 18:48:00 +00:00
|
|
|
static void
|
|
|
|
gst_rtp_dtmf_src_class_init (GstRTPDTMFSrcClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2007-09-16 19:44:08 +00:00
|
|
|
GstBaseSrcClass *gstbasesrc_class;
|
2007-08-20 18:48:00 +00:00
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
2007-09-16 19:44:08 +00:00
|
|
|
gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
|
2007-08-20 18:48:00 +00:00
|
|
|
gstelement_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
|
2012-01-25 10:21:50 +00:00
|
|
|
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));
|
|
|
|
|
2012-10-17 16:34:26 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2012-01-25 10:21:50 +00:00
|
|
|
"RTP DTMF packet generator", "Source/Network",
|
|
|
|
"Generates RTP DTMF packets", "Zeeshan Ali <zeeshan.ali@nokia.com>");
|
2007-08-20 18:48:00 +00:00
|
|
|
|
|
|
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_finalize);
|
2007-08-22 17:55:33 +00:00
|
|
|
gobject_class->set_property =
|
2007-08-20 18:48:00 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_set_property);
|
|
|
|
gobject_class->get_property =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_get_property);
|
|
|
|
|
|
|
|
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",
|
2010-10-19 10:43:14 +00:00
|
|
|
0, G_MAXUINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2007-08-20 18:48:00 +00:00
|
|
|
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",
|
2010-10-19 10:43:14 +00:00
|
|
|
0, G_MAXUINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2007-08-20 18:48:00 +00:00
|
|
|
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,
|
2010-10-19 10:43:14 +00:00
|
|
|
G_MAXINT, DEFAULT_TIMESTAMP_OFFSET,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2007-08-20 18:48:00 +00:00
|
|
|
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,
|
2010-10-19 10:43:14 +00:00
|
|
|
DEFAULT_SEQNUM_OFFSET, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2007-08-20 18:48:00 +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",
|
2010-10-19 10:43:14 +00:00
|
|
|
0, G_MAXUINT, DEFAULT_CLOCK_RATE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2007-08-20 18:48:00 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SSRC,
|
|
|
|
g_param_spec_uint ("ssrc", "SSRC",
|
|
|
|
"The SSRC of the packets (-1 == random)",
|
2010-10-19 10:43:14 +00:00
|
|
|
0, G_MAXUINT, DEFAULT_SSRC,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2007-08-20 18:48:00 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PT,
|
|
|
|
g_param_spec_uint ("pt", "payload type",
|
|
|
|
"The payload type of the packets",
|
2010-10-19 10:43:14 +00:00
|
|
|
0, 0x80, DEFAULT_PT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2007-08-20 18:48:00 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_REDUNDANCY,
|
2007-09-17 00:15:52 +00:00
|
|
|
g_param_spec_uint ("packet-redundancy", "Packet Redundancy",
|
2007-08-20 18:48:00 +00:00
|
|
|
"Number of packets to send to indicate start and stop dtmf events",
|
|
|
|
MIN_PACKET_REDUNDANCY, MAX_PACKET_REDUNDANCY,
|
2010-10-19 10:43:14 +00:00
|
|
|
DEFAULT_PACKET_REDUNDANCY,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2007-08-20 18:48:00 +00:00
|
|
|
|
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_change_state);
|
2007-09-16 19:44:08 +00:00
|
|
|
|
2009-02-20 22:37:43 +00:00
|
|
|
gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_unlock);
|
2007-09-16 19:44:08 +00:00
|
|
|
gstbasesrc_class->unlock_stop =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_unlock_stop);
|
|
|
|
|
2009-02-20 22:37:43 +00:00
|
|
|
gstbasesrc_class->event = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_handle_event);
|
|
|
|
gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_create);
|
|
|
|
gstbasesrc_class->negotiate = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_negotiate);
|
2015-09-01 19:39:22 +00:00
|
|
|
gstbasesrc_class->query = GST_DEBUG_FUNCPTR (gst_rtp_dtmf_src_query);
|
2007-08-20 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
2009-08-11 20:23:20 +00:00
|
|
|
static void
|
|
|
|
gst_rtp_dtmf_src_event_free (GstRTPDTMFSrcEvent * event)
|
|
|
|
{
|
|
|
|
if (event) {
|
2009-08-11 20:39:42 +00:00
|
|
|
if (event->payload)
|
|
|
|
g_slice_free (GstRTPDTMFPayload, event->payload);
|
|
|
|
g_slice_free (GstRTPDTMFSrcEvent, event);
|
2009-08-11 20:23:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-20 18:48:00 +00:00
|
|
|
static void
|
2012-01-25 10:21:50 +00:00
|
|
|
gst_rtp_dtmf_src_init (GstRTPDTMFSrc * object)
|
2007-08-20 18:48:00 +00:00
|
|
|
{
|
2007-09-16 19:44:08 +00:00
|
|
|
gst_base_src_set_format (GST_BASE_SRC (object), GST_FORMAT_TIME);
|
|
|
|
gst_base_src_set_live (GST_BASE_SRC (object), TRUE);
|
|
|
|
|
|
|
|
object->ssrc = DEFAULT_SSRC;
|
|
|
|
object->seqnum_offset = DEFAULT_SEQNUM_OFFSET;
|
|
|
|
object->ts_offset = DEFAULT_TIMESTAMP_OFFSET;
|
|
|
|
object->pt = DEFAULT_PT;
|
|
|
|
object->clock_rate = DEFAULT_CLOCK_RATE;
|
2011-04-14 20:49:39 +00:00
|
|
|
object->ptime = DEFAULT_PTIME;
|
2007-09-16 19:44:08 +00:00
|
|
|
object->packet_redundancy = DEFAULT_PACKET_REDUNDANCY;
|
|
|
|
|
2009-08-11 20:23:20 +00:00
|
|
|
object->event_queue =
|
|
|
|
g_async_queue_new_full ((GDestroyNotify) gst_rtp_dtmf_src_event_free);
|
2007-09-17 00:36:54 +00:00
|
|
|
object->payload = NULL;
|
2007-09-16 19:44:08 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (object, "init done");
|
2007-08-20 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-08-20 18:48:00 +00:00
|
|
|
|
2012-01-25 10:21:50 +00:00
|
|
|
G_OBJECT_CLASS (gst_rtp_dtmf_src_parent_class)->finalize (object);
|
2007-08-20 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-20 22:37:43 +00:00
|
|
|
gst_rtp_dtmf_src_handle_dtmf_event (GstRTPDTMFSrc * dtmfsrc,
|
|
|
|
const GstStructure * event_structure)
|
2007-08-20 18:48:00 +00:00
|
|
|
{
|
|
|
|
gint event_type;
|
|
|
|
gboolean start;
|
|
|
|
gint method;
|
2011-04-14 21:08:57 +00:00
|
|
|
GstClockTime last_stop;
|
2011-11-04 21:54:04 +00:00
|
|
|
gint event_number;
|
|
|
|
gint event_volume;
|
|
|
|
gboolean correct_order;
|
2007-08-20 18:48:00 +00:00
|
|
|
|
|
|
|
if (!gst_structure_get_int (event_structure, "type", &event_type) ||
|
2009-02-20 22:37:43 +00:00
|
|
|
!gst_structure_get_boolean (event_structure, "start", &start) ||
|
|
|
|
event_type != GST_RTP_DTMF_TYPE_EVENT)
|
2007-08-20 18:48:00 +00:00
|
|
|
goto failure;
|
|
|
|
|
|
|
|
if (gst_structure_get_int (event_structure, "method", &method)) {
|
|
|
|
if (method != 1) {
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-04 21:54:04 +00:00
|
|
|
if (start)
|
|
|
|
if (!gst_structure_get_int (event_structure, "number", &event_number) ||
|
|
|
|
!gst_structure_get_int (event_structure, "volume", &event_volume))
|
|
|
|
goto failure;
|
|
|
|
|
2011-04-14 21:08:57 +00:00
|
|
|
GST_OBJECT_LOCK (dtmfsrc);
|
|
|
|
if (gst_structure_get_clock_time (event_structure, "last-stop", &last_stop))
|
|
|
|
dtmfsrc->last_stop = last_stop;
|
|
|
|
else
|
|
|
|
dtmfsrc->last_stop = GST_CLOCK_TIME_NONE;
|
2011-11-04 21:54:04 +00:00
|
|
|
correct_order = (start != dtmfsrc->last_event_was_start);
|
|
|
|
dtmfsrc->last_event_was_start = start;
|
2011-04-14 21:08:57 +00:00
|
|
|
GST_OBJECT_UNLOCK (dtmfsrc);
|
|
|
|
|
2011-11-04 21:54:04 +00:00
|
|
|
if (!correct_order)
|
|
|
|
goto failure;
|
2007-08-20 18:48:00 +00:00
|
|
|
|
2011-11-04 21:54:04 +00:00
|
|
|
if (start) {
|
2007-08-20 18:48:00 +00:00
|
|
|
if (!gst_structure_get_int (event_structure, "number", &event_number) ||
|
2009-02-20 22:37:43 +00:00
|
|
|
!gst_structure_get_int (event_structure, "volume", &event_volume))
|
2007-08-20 18:48:00 +00:00
|
|
|
goto failure;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "Received start event %d with volume %d",
|
2009-02-20 22:37:43 +00:00
|
|
|
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-08-20 18:48:00 +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-08-20 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
failure:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-20 22:37:43 +00:00
|
|
|
gst_rtp_dtmf_src_handle_custom_upstream (GstRTPDTMFSrc * dtmfsrc,
|
2007-08-20 18:48:00 +00:00
|
|
|
GstEvent * event)
|
|
|
|
{
|
|
|
|
gboolean result = FALSE;
|
2007-08-22 17:55:33 +00:00
|
|
|
gchar *struct_str;
|
2007-08-20 18:48:00 +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-08-20 18:48:00 +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-08-20 18:48:00 +00:00
|
|
|
if (structure && gst_structure_has_name (structure, "dtmf-event"))
|
|
|
|
result = gst_rtp_dtmf_src_handle_dtmf_event (dtmfsrc, structure);
|
|
|
|
|
|
|
|
ret:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-20 22:37:43 +00:00
|
|
|
gst_rtp_dtmf_src_handle_event (GstBaseSrc * basesrc, GstEvent * event)
|
2007-08-20 18:48:00 +00:00
|
|
|
{
|
|
|
|
GstRTPDTMFSrc *dtmfsrc;
|
|
|
|
gboolean result = FALSE;
|
|
|
|
|
2007-09-16 19:44:08 +00:00
|
|
|
dtmfsrc = GST_RTP_DTMF_SRC (basesrc);
|
2007-08-20 18:48:00 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "Received an event on the src pad");
|
2007-09-16 19:44:08 +00:00
|
|
|
if (GST_EVENT_TYPE (event) == GST_EVENT_CUSTOM_UPSTREAM) {
|
|
|
|
result = gst_rtp_dtmf_src_handle_custom_upstream (dtmfsrc, event);
|
2007-08-20 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
case PROP_CLOCK_RATE:
|
|
|
|
dtmfsrc->clock_rate = g_value_get_uint (value);
|
2007-09-17 00:24:12 +00:00
|
|
|
dtmfsrc->dirty = TRUE;
|
2007-08-20 18:48:00 +00:00
|
|
|
break;
|
|
|
|
case PROP_SSRC:
|
|
|
|
dtmfsrc->ssrc = g_value_get_uint (value);
|
|
|
|
break;
|
|
|
|
case PROP_PT:
|
|
|
|
dtmfsrc->pt = g_value_get_uint (value);
|
2007-09-17 00:24:12 +00:00
|
|
|
dtmfsrc->dirty = TRUE;
|
2007-08-20 18:48:00 +00:00
|
|
|
break;
|
|
|
|
case PROP_REDUNDANCY:
|
2007-09-17 00:15:52 +00:00
|
|
|
dtmfsrc->packet_redundancy = g_value_get_uint (value);
|
2007-08-20 18:48:00 +00:00
|
|
|
break;
|
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
case PROP_TIMESTAMP:
|
|
|
|
g_value_set_uint (value, dtmfsrc->rtp_timestamp);
|
|
|
|
break;
|
|
|
|
case PROP_SEQNUM:
|
|
|
|
g_value_set_uint (value, dtmfsrc->seqnum);
|
|
|
|
break;
|
|
|
|
case PROP_REDUNDANCY:
|
|
|
|
g_value_set_uint (value, dtmfsrc->packet_redundancy);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-12 01:30:28 +00:00
|
|
|
static gboolean
|
2009-02-20 22:37:43 +00:00
|
|
|
gst_rtp_dtmf_prepare_timestamps (GstRTPDTMFSrc * dtmfsrc)
|
2007-08-20 18:48:00 +00:00
|
|
|
{
|
2011-04-14 21:08:57 +00:00
|
|
|
GstClockTime last_stop;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (dtmfsrc);
|
|
|
|
last_stop = dtmfsrc->last_stop;
|
|
|
|
GST_OBJECT_UNLOCK (dtmfsrc);
|
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (last_stop)) {
|
|
|
|
dtmfsrc->start_timestamp = last_stop;
|
|
|
|
} else {
|
|
|
|
GstClock *clock = gst_element_get_clock (GST_ELEMENT (dtmfsrc));
|
|
|
|
|
|
|
|
if (clock == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-07-12 00:46:20 +00:00
|
|
|
dtmfsrc->start_timestamp = gst_clock_get_time (clock)
|
2011-04-14 21:08:57 +00:00
|
|
|
- gst_element_get_base_time (GST_ELEMENT (dtmfsrc));
|
|
|
|
gst_object_unref (clock);
|
|
|
|
}
|
2007-08-20 18:48:00 +00:00
|
|
|
|
2011-07-12 00:47:23 +00:00
|
|
|
/* If the last stop was in the past, then lets add the buffers together */
|
|
|
|
if (dtmfsrc->start_timestamp < dtmfsrc->timestamp)
|
|
|
|
dtmfsrc->start_timestamp = dtmfsrc->timestamp;
|
|
|
|
|
|
|
|
dtmfsrc->timestamp = dtmfsrc->start_timestamp;
|
|
|
|
|
2007-08-20 18:48:00 +00:00
|
|
|
dtmfsrc->rtp_timestamp = dtmfsrc->ts_base +
|
2009-02-20 22:37:43 +00:00
|
|
|
gst_util_uint64_scale_int (gst_segment_to_running_time (&GST_BASE_SRC
|
|
|
|
(dtmfsrc)->segment, GST_FORMAT_TIME, dtmfsrc->timestamp),
|
|
|
|
dtmfsrc->clock_rate, GST_SECOND);
|
2011-07-12 01:30:28 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2007-08-20 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
|
|
|
|
static void
|
2009-02-20 22:37:43 +00:00
|
|
|
gst_rtp_dtmf_src_add_start_event (GstRTPDTMFSrc * dtmfsrc, gint event_number,
|
2007-08-22 17:55:33 +00:00
|
|
|
gint event_volume)
|
|
|
|
{
|
|
|
|
|
2009-08-11 20:39:42 +00:00
|
|
|
GstRTPDTMFSrcEvent *event = g_slice_new0 (GstRTPDTMFSrcEvent);
|
2007-08-22 17:55:33 +00:00
|
|
|
event->event_type = RTP_DTMF_EVENT_TYPE_START;
|
|
|
|
|
2009-08-11 20:39:42 +00:00
|
|
|
event->payload = g_slice_new0 (GstRTPDTMFPayload);
|
2007-08-22 17:55:33 +00:00
|
|
|
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
|
2009-02-20 22:37:43 +00:00
|
|
|
gst_rtp_dtmf_src_add_stop_event (GstRTPDTMFSrc * dtmfsrc)
|
2007-08-22 17:55:33 +00:00
|
|
|
{
|
2007-08-20 18:48:00 +00:00
|
|
|
|
2009-08-11 20:39:42 +00:00
|
|
|
GstRTPDTMFSrcEvent *event = g_slice_new0 (GstRTPDTMFSrcEvent);
|
2007-08-22 17:55:33 +00:00
|
|
|
event->event_type = RTP_DTMF_EVENT_TYPE_STOP;
|
2007-08-20 18:48:00 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
g_async_queue_push (dtmfsrc->event_queue, event);
|
2007-08-20 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-08-20 18:48:00 +00:00
|
|
|
static void
|
2012-01-25 10:21:50 +00:00
|
|
|
gst_rtp_dtmf_prepare_rtp_headers (GstRTPDTMFSrc * dtmfsrc,
|
|
|
|
GstRTPBuffer * rtpbuf)
|
2007-08-20 18:48:00 +00:00
|
|
|
{
|
2012-01-25 10:21:50 +00:00
|
|
|
gst_rtp_buffer_set_ssrc (rtpbuf, dtmfsrc->current_ssrc);
|
|
|
|
gst_rtp_buffer_set_payload_type (rtpbuf, dtmfsrc->pt);
|
2007-09-17 00:36:54 +00:00
|
|
|
/* Only the very first packet gets a marker */
|
2007-08-20 18:48:00 +00:00
|
|
|
if (dtmfsrc->first_packet) {
|
2012-01-25 10:21:50 +00:00
|
|
|
gst_rtp_buffer_set_marker (rtpbuf, TRUE);
|
2007-08-20 18:48:00 +00:00
|
|
|
} else if (dtmfsrc->last_packet) {
|
2007-09-17 00:36:54 +00:00
|
|
|
dtmfsrc->payload->e = 1;
|
2007-08-20 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dtmfsrc->seqnum++;
|
2012-01-25 10:21:50 +00:00
|
|
|
gst_rtp_buffer_set_seq (rtpbuf, dtmfsrc->seqnum);
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-08-20 18:48:00 +00:00
|
|
|
/* timestamp of RTP header */
|
2012-01-25 10:21:50 +00:00
|
|
|
gst_rtp_buffer_set_timestamp (rtpbuf, dtmfsrc->rtp_timestamp);
|
2007-08-20 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
2012-01-25 10:21:50 +00:00
|
|
|
static GstBuffer *
|
|
|
|
gst_rtp_dtmf_src_create_next_rtp_packet (GstRTPDTMFSrc * dtmfsrc)
|
2007-08-20 18:48:00 +00:00
|
|
|
{
|
2012-01-25 10:21:50 +00:00
|
|
|
GstBuffer *buf;
|
2007-08-20 18:48:00 +00:00
|
|
|
GstRTPDTMFPayload *payload;
|
2012-01-25 10:21:50 +00:00
|
|
|
GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT;
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2012-01-25 10:21:50 +00:00
|
|
|
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);
|
2007-08-20 18:48:00 +00:00
|
|
|
|
2007-08-22 17:55:33 +00:00
|
|
|
/* timestamp and duration of GstBuffer */
|
2007-09-17 00:36:54 +00:00
|
|
|
/* Redundant buffer have no duration ... */
|
|
|
|
if (dtmfsrc->redundancy_count > 1)
|
|
|
|
GST_BUFFER_DURATION (buf) = 0;
|
|
|
|
else
|
2011-04-14 20:49:39 +00:00
|
|
|
GST_BUFFER_DURATION (buf) = dtmfsrc->ptime * GST_MSECOND;
|
2012-01-25 10:21:50 +00:00
|
|
|
GST_BUFFER_PTS (buf) = dtmfsrc->timestamp;
|
2007-09-17 00:36:54 +00:00
|
|
|
|
2012-01-25 10:21:50 +00:00
|
|
|
payload = (GstRTPDTMFPayload *) gst_rtp_buffer_get_payload (&rtpbuffer);
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-08-20 18:48:00 +00:00
|
|
|
/* copy payload and convert to network-byte order */
|
2013-11-21 15:30:34 +00:00
|
|
|
memmove (payload, dtmfsrc->payload, sizeof (GstRTPDTMFPayload));
|
2007-08-20 18:48:00 +00:00
|
|
|
|
|
|
|
payload->duration = g_htons (payload->duration);
|
2007-09-17 00:36:54 +00:00
|
|
|
|
2011-07-12 01:31:07 +00:00
|
|
|
if (dtmfsrc->redundancy_count <= 1 && dtmfsrc->last_packet) {
|
2011-07-12 00:46:20 +00:00
|
|
|
GstClockTime inter_digit_interval = MIN_INTER_DIGIT_INTERVAL;
|
|
|
|
|
|
|
|
if (inter_digit_interval % dtmfsrc->ptime != 0)
|
|
|
|
inter_digit_interval += dtmfsrc->ptime -
|
|
|
|
(MIN_INTER_DIGIT_INTERVAL % dtmfsrc->ptime);
|
|
|
|
|
|
|
|
GST_BUFFER_DURATION (buf) += inter_digit_interval * GST_MSECOND;
|
|
|
|
}
|
|
|
|
|
2011-07-13 01:48:37 +00:00
|
|
|
GST_LOG_OBJECT (dtmfsrc, "Creating new buffer with event %u duration "
|
|
|
|
" gst: %" GST_TIME_FORMAT " at %" GST_TIME_FORMAT "(rtp ts:%u dur:%u)",
|
|
|
|
dtmfsrc->payload->event, GST_TIME_ARGS (GST_BUFFER_DURATION (buf)),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), dtmfsrc->rtp_timestamp,
|
|
|
|
dtmfsrc->payload->duration);
|
|
|
|
|
|
|
|
/* duration of DTMF payloadfor the NEXT packet */
|
|
|
|
/* not updated for redundant packets */
|
|
|
|
if (dtmfsrc->redundancy_count <= 1)
|
|
|
|
dtmfsrc->payload->duration += dtmfsrc->ptime * dtmfsrc->clock_rate / 1000;
|
|
|
|
|
2011-07-12 00:46:20 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (dtmfsrc->timestamp))
|
|
|
|
dtmfsrc->timestamp += GST_BUFFER_DURATION (buf);
|
2011-07-13 01:48:37 +00:00
|
|
|
|
2012-01-25 10:21:50 +00:00
|
|
|
gst_rtp_buffer_unmap (&rtpbuffer);
|
2007-08-20 18:48:00 +00:00
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2013-01-26 01:39:33 +00:00
|
|
|
static GstMessage *
|
|
|
|
gst_dtmf_src_prepare_message (GstRTPDTMFSrc * dtmfsrc,
|
|
|
|
const gchar * message_name, GstRTPDTMFSrcEvent * event)
|
2011-10-29 16:24:26 +00:00
|
|
|
{
|
2013-01-26 01:39:33 +00:00
|
|
|
GstStructure *s;
|
2011-10-29 16:24:26 +00:00
|
|
|
|
|
|
|
switch (event->event_type) {
|
|
|
|
case RTP_DTMF_EVENT_TYPE_START:
|
|
|
|
s = gst_structure_new (message_name,
|
|
|
|
"type", G_TYPE_INT, 1,
|
|
|
|
"method", G_TYPE_INT, 1,
|
|
|
|
"start", G_TYPE_BOOLEAN, TRUE,
|
|
|
|
"number", G_TYPE_INT, event->payload->event,
|
|
|
|
"volume", G_TYPE_INT, event->payload->volume, NULL);
|
|
|
|
break;
|
|
|
|
case RTP_DTMF_EVENT_TYPE_STOP:
|
|
|
|
s = gst_structure_new (message_name,
|
|
|
|
"type", G_TYPE_INT, 1, "method", G_TYPE_INT, 1,
|
|
|
|
"start", G_TYPE_BOOLEAN, FALSE, NULL);
|
|
|
|
break;
|
|
|
|
case RTP_DTMF_EVENT_TYPE_PAUSE_TASK:
|
2013-01-26 01:39:33 +00:00
|
|
|
return NULL;
|
2013-01-26 22:58:29 +00:00
|
|
|
default:
|
|
|
|
return NULL;
|
2011-10-29 16:24:26 +00:00
|
|
|
}
|
|
|
|
|
2013-01-26 01:39:33 +00:00
|
|
|
return gst_message_new_element (GST_OBJECT (dtmfsrc), s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dtmf_src_post_message (GstRTPDTMFSrc * dtmfsrc, const gchar * message_name,
|
|
|
|
GstRTPDTMFSrcEvent * event)
|
|
|
|
{
|
|
|
|
GstMessage *m = gst_dtmf_src_prepare_message (dtmfsrc, message_name, event);
|
|
|
|
|
|
|
|
|
|
|
|
if (m)
|
|
|
|
gst_element_post_message (GST_ELEMENT (dtmfsrc), m);
|
2011-10-29 16:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-16 19:44:08 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_rtp_dtmf_src_create (GstBaseSrc * basesrc, guint64 offset,
|
|
|
|
guint length, GstBuffer ** buffer)
|
2007-08-20 18:48:00 +00:00
|
|
|
{
|
2007-08-22 17:55:33 +00:00
|
|
|
GstRTPDTMFSrcEvent *event;
|
2009-02-20 22:37:43 +00:00
|
|
|
GstRTPDTMFSrc *dtmfsrc;
|
2007-09-16 19:44:08 +00:00
|
|
|
GstClock *clock;
|
|
|
|
GstClockID *clockid;
|
|
|
|
GstClockReturn clockret;
|
2013-01-26 01:39:33 +00:00
|
|
|
GstMessage *message;
|
|
|
|
GQueue messages = G_QUEUE_INIT;
|
2007-09-16 19:44:08 +00:00
|
|
|
|
|
|
|
dtmfsrc = GST_RTP_DTMF_SRC (basesrc);
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
2007-09-17 00:36:54 +00:00
|
|
|
if (dtmfsrc->payload == NULL) {
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "popping");
|
2007-09-16 19:44:08 +00:00
|
|
|
event = g_async_queue_pop (dtmfsrc->event_queue);
|
|
|
|
|
2007-09-17 00:36:54 +00:00
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "popped %d", event->event_type);
|
|
|
|
|
2007-09-16 19:44:08 +00:00
|
|
|
switch (event->event_type) {
|
|
|
|
case RTP_DTMF_EVENT_TYPE_STOP:
|
|
|
|
GST_WARNING_OBJECT (dtmfsrc,
|
|
|
|
"Received a DTMF stop event when already stopped");
|
2011-10-29 16:24:26 +00:00
|
|
|
gst_dtmf_src_post_message (dtmfsrc, "dtmf-event-dropped", event);
|
2007-09-16 19:44:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RTP_DTMF_EVENT_TYPE_START:
|
|
|
|
dtmfsrc->first_packet = TRUE;
|
|
|
|
dtmfsrc->last_packet = FALSE;
|
2008-03-20 00:50:41 +00:00
|
|
|
/* Set the redundancy on the first packet */
|
2007-09-17 00:36:54 +00:00
|
|
|
dtmfsrc->redundancy_count = dtmfsrc->packet_redundancy;
|
2011-07-12 01:30:28 +00:00
|
|
|
if (!gst_rtp_dtmf_prepare_timestamps (dtmfsrc))
|
|
|
|
goto no_clock;
|
2007-09-16 19:44:08 +00:00
|
|
|
|
2013-01-26 01:39:33 +00:00
|
|
|
g_queue_push_tail (&messages,
|
|
|
|
gst_dtmf_src_prepare_message (dtmfsrc, "dtmf-event-processed",
|
|
|
|
event));
|
2007-09-17 00:36:54 +00:00
|
|
|
dtmfsrc->payload = event->payload;
|
2013-01-26 01:37:53 +00:00
|
|
|
dtmfsrc->payload->duration =
|
|
|
|
dtmfsrc->ptime * dtmfsrc->clock_rate / 1000;
|
2009-08-11 20:23:20 +00:00
|
|
|
event->payload = NULL;
|
2007-09-16 19:44:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RTP_DTMF_EVENT_TYPE_PAUSE_TASK:
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
GST_OBJECT_LOCK (dtmfsrc);
|
|
|
|
if (dtmfsrc->paused) {
|
|
|
|
g_async_queue_push (dtmfsrc->event_queue, event);
|
|
|
|
goto paused_locked;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (dtmfsrc);
|
|
|
|
break;
|
|
|
|
}
|
2007-09-17 00:36:54 +00:00
|
|
|
|
2009-08-11 20:23:20 +00:00
|
|
|
gst_rtp_dtmf_src_event_free (event);
|
2007-09-17 00:36:54 +00:00
|
|
|
} else if (!dtmfsrc->first_packet && !dtmfsrc->last_packet &&
|
2009-02-20 22:37:43 +00:00
|
|
|
(dtmfsrc->timestamp - dtmfsrc->start_timestamp) / GST_MSECOND >=
|
2007-09-16 19:44:08 +00:00
|
|
|
MIN_PULSE_DURATION) {
|
2007-09-17 00:36:54 +00:00
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "try popping");
|
2007-09-16 19:44:08 +00:00
|
|
|
event = g_async_queue_try_pop (dtmfsrc->event_queue);
|
|
|
|
|
2007-09-17 00:36:54 +00:00
|
|
|
|
2007-09-16 19:44:08 +00:00
|
|
|
if (event != NULL) {
|
2007-09-17 00:36:54 +00:00
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "try popped %d", event->event_type);
|
|
|
|
|
2007-09-16 19:44:08 +00:00
|
|
|
switch (event->event_type) {
|
|
|
|
case RTP_DTMF_EVENT_TYPE_START:
|
|
|
|
GST_WARNING_OBJECT (dtmfsrc,
|
|
|
|
"Received two consecutive DTMF start events");
|
2011-10-29 16:24:26 +00:00
|
|
|
gst_dtmf_src_post_message (dtmfsrc, "dtmf-event-dropped", event);
|
2007-09-16 19:44:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RTP_DTMF_EVENT_TYPE_STOP:
|
|
|
|
dtmfsrc->first_packet = FALSE;
|
|
|
|
dtmfsrc->last_packet = TRUE;
|
2008-03-20 00:50:41 +00:00
|
|
|
/* Set the redundancy on the last packet */
|
2007-09-17 00:36:54 +00:00
|
|
|
dtmfsrc->redundancy_count = dtmfsrc->packet_redundancy;
|
2013-01-26 01:39:33 +00:00
|
|
|
g_queue_push_tail (&messages,
|
|
|
|
gst_dtmf_src_prepare_message (dtmfsrc, "dtmf-event-processed",
|
|
|
|
event));
|
2007-09-16 19:44:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RTP_DTMF_EVENT_TYPE_PAUSE_TASK:
|
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
*/
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "pushing pause_task...");
|
|
|
|
GST_OBJECT_LOCK (dtmfsrc);
|
|
|
|
if (dtmfsrc->paused) {
|
|
|
|
g_async_queue_push (dtmfsrc->event_queue, event);
|
|
|
|
goto paused_locked;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (dtmfsrc);
|
|
|
|
break;
|
|
|
|
}
|
2009-08-11 20:23:20 +00:00
|
|
|
gst_rtp_dtmf_src_event_free (event);
|
2007-09-16 19:44:08 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-17 00:36:54 +00:00
|
|
|
} while (dtmfsrc->payload == NULL);
|
2007-08-20 18:48:00 +00:00
|
|
|
|
|
|
|
|
2007-09-16 19:44:08 +00:00
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "Processed events, now lets wait on the clock");
|
2007-08-20 18:48:00 +00:00
|
|
|
|
2007-09-16 19:44:08 +00:00
|
|
|
clock = gst_element_get_clock (GST_ELEMENT (basesrc));
|
2011-07-12 01:30:28 +00:00
|
|
|
if (!clock)
|
|
|
|
goto no_clock;
|
2007-09-17 00:36:54 +00:00
|
|
|
clockid = gst_clock_new_single_shot_id (clock, dtmfsrc->timestamp +
|
2007-09-16 19:44:08 +00:00
|
|
|
gst_element_get_base_time (GST_ELEMENT (dtmfsrc)));
|
|
|
|
gst_object_unref (clock);
|
2007-08-20 18:48:00 +00:00
|
|
|
|
2007-09-16 19:44:08 +00:00
|
|
|
GST_OBJECT_LOCK (dtmfsrc);
|
|
|
|
if (!dtmfsrc->paused) {
|
|
|
|
dtmfsrc->clockid = clockid;
|
|
|
|
GST_OBJECT_UNLOCK (dtmfsrc);
|
2007-08-20 18:48:00 +00:00
|
|
|
|
2007-09-16 19:44:08 +00:00
|
|
|
clockret = gst_clock_id_wait (clockid, NULL);
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-09-16 19:44:08 +00:00
|
|
|
GST_OBJECT_LOCK (dtmfsrc);
|
|
|
|
if (dtmfsrc->paused)
|
|
|
|
clockret = GST_CLOCK_UNSCHEDULED;
|
2009-02-20 22:37:43 +00:00
|
|
|
} else {
|
2007-09-16 19:44:08 +00:00
|
|
|
clockret = GST_CLOCK_UNSCHEDULED;
|
|
|
|
}
|
|
|
|
gst_clock_id_unref (clockid);
|
|
|
|
dtmfsrc->clockid = NULL;
|
|
|
|
GST_OBJECT_UNLOCK (dtmfsrc);
|
|
|
|
|
2013-01-26 01:39:33 +00:00
|
|
|
while ((message = g_queue_pop_head (&messages)) != NULL)
|
|
|
|
gst_element_post_message (GST_ELEMENT (dtmfsrc), message);
|
|
|
|
|
2007-09-16 19:44:08 +00:00
|
|
|
if (clockret == GST_CLOCK_UNSCHEDULED) {
|
|
|
|
goto paused;
|
2007-08-20 18:48:00 +00:00
|
|
|
}
|
2007-09-16 19:44:08 +00:00
|
|
|
|
2009-02-20 22:37:43 +00:00
|
|
|
send_last:
|
2007-08-20 18:48:00 +00:00
|
|
|
|
2007-09-17 00:36:54 +00:00
|
|
|
if (dtmfsrc->dirty)
|
|
|
|
if (!gst_rtp_dtmf_src_negotiate (basesrc))
|
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
2007-08-20 18:48:00 +00:00
|
|
|
|
2007-09-17 00:36:54 +00:00
|
|
|
/* create buffer to hold the payload */
|
|
|
|
*buffer = gst_rtp_dtmf_src_create_next_rtp_packet (dtmfsrc);
|
2007-08-20 18:48:00 +00:00
|
|
|
|
2007-09-17 00:36:54 +00:00
|
|
|
if (dtmfsrc->redundancy_count)
|
|
|
|
dtmfsrc->redundancy_count--;
|
2007-09-16 19:44:08 +00:00
|
|
|
|
2007-09-17 00:36:54 +00:00
|
|
|
/* Only the very first one has a marker */
|
|
|
|
dtmfsrc->first_packet = FALSE;
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-09-17 00:36:54 +00:00
|
|
|
/* This is the end of the event */
|
|
|
|
if (dtmfsrc->last_packet == TRUE && dtmfsrc->redundancy_count == 0) {
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2009-08-11 20:39:42 +00:00
|
|
|
g_slice_free (GstRTPDTMFPayload, dtmfsrc->payload);
|
2007-09-17 00:36:54 +00:00
|
|
|
dtmfsrc->payload = NULL;
|
2007-08-22 17:55:33 +00:00
|
|
|
|
2007-09-17 00:36:54 +00:00
|
|
|
dtmfsrc->last_packet = FALSE;
|
2007-08-22 17:55:33 +00:00
|
|
|
}
|
2007-09-16 19:44:08 +00:00
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
2009-02-20 22:37:43 +00:00
|
|
|
paused_locked:
|
2007-09-16 19:44:08 +00:00
|
|
|
|
|
|
|
GST_OBJECT_UNLOCK (dtmfsrc);
|
|
|
|
|
2009-02-20 22:37:43 +00:00
|
|
|
paused:
|
2007-09-16 19:44:08 +00:00
|
|
|
|
2007-09-17 00:36:54 +00:00
|
|
|
if (dtmfsrc->payload) {
|
2007-09-16 19:44:08 +00:00
|
|
|
dtmfsrc->first_packet = FALSE;
|
|
|
|
dtmfsrc->last_packet = TRUE;
|
2007-09-17 00:36:54 +00:00
|
|
|
/* Set the redundanc on the last packet */
|
|
|
|
dtmfsrc->redundancy_count = dtmfsrc->packet_redundancy;
|
2007-09-16 19:44:08 +00:00
|
|
|
goto send_last;
|
2007-09-17 00:36:54 +00:00
|
|
|
} else {
|
2012-02-08 15:37:13 +00:00
|
|
|
return GST_FLOW_FLUSHING;
|
2007-09-16 19:44:08 +00:00
|
|
|
}
|
2011-07-12 01:30:28 +00:00
|
|
|
|
|
|
|
no_clock:
|
|
|
|
GST_ELEMENT_ERROR (dtmfsrc, STREAM, MUX, ("No available clock"),
|
|
|
|
("No available clock"));
|
|
|
|
gst_pad_pause_task (GST_BASE_SRC_PAD (dtmfsrc));
|
|
|
|
return GST_FLOW_ERROR;
|
2007-08-20 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 19:44:08 +00:00
|
|
|
|
2007-09-17 00:24:12 +00:00
|
|
|
static gboolean
|
|
|
|
gst_rtp_dtmf_src_negotiate (GstBaseSrc * basesrc)
|
2007-08-20 18:48:00 +00:00
|
|
|
{
|
2007-09-17 00:24:12 +00:00
|
|
|
GstCaps *srccaps, *peercaps;
|
|
|
|
GstRTPDTMFSrc *dtmfsrc = GST_RTP_DTMF_SRC (basesrc);
|
|
|
|
gboolean ret;
|
2007-08-20 18:48:00 +00:00
|
|
|
|
2007-09-17 00:24:12 +00:00
|
|
|
/* fill in the defaults, there properties cannot be negotiated. */
|
|
|
|
srccaps = gst_caps_new_simple ("application/x-rtp",
|
2007-08-20 18:48:00 +00:00
|
|
|
"media", G_TYPE_STRING, "audio",
|
2008-03-19 19:32:51 +00:00
|
|
|
"encoding-name", G_TYPE_STRING, "TELEPHONE-EVENT", NULL);
|
2007-09-17 00:24:12 +00:00
|
|
|
|
|
|
|
/* the peer caps can override some of the defaults */
|
2012-01-25 10:21:50 +00:00
|
|
|
peercaps = gst_pad_peer_query_caps (GST_BASE_SRC_PAD (basesrc), NULL);
|
2007-09-17 00:24:12 +00:00
|
|
|
if (peercaps == NULL) {
|
|
|
|
/* no peer caps, just add the other properties */
|
|
|
|
gst_caps_set_simple (srccaps,
|
|
|
|
"payload", G_TYPE_INT, dtmfsrc->pt,
|
|
|
|
"ssrc", G_TYPE_UINT, dtmfsrc->current_ssrc,
|
2014-10-10 22:11:19 +00:00
|
|
|
"timestamp-offset", G_TYPE_UINT, dtmfsrc->ts_base,
|
2008-06-13 23:30:06 +00:00
|
|
|
"clock-rate", G_TYPE_INT, dtmfsrc->clock_rate,
|
2014-10-10 22:11:19 +00:00
|
|
|
"seqnum-offset", G_TYPE_UINT, dtmfsrc->seqnum_base, NULL);
|
2007-09-17 00:24:12 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "no peer caps: %" GST_PTR_FORMAT, srccaps);
|
|
|
|
} else {
|
|
|
|
GstCaps *temp;
|
|
|
|
GstStructure *s;
|
|
|
|
const GValue *value;
|
|
|
|
gint pt;
|
2008-06-13 23:30:06 +00:00
|
|
|
gint clock_rate;
|
2007-09-17 00:24:12 +00:00
|
|
|
|
|
|
|
/* peer provides caps we can use to fixate, intersect. This always returns a
|
|
|
|
* writable caps. */
|
|
|
|
temp = gst_caps_intersect (srccaps, peercaps);
|
|
|
|
gst_caps_unref (srccaps);
|
|
|
|
gst_caps_unref (peercaps);
|
|
|
|
|
|
|
|
if (!temp) {
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "Could not get intersection with peer caps");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_caps_is_empty (temp)) {
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "Intersection with peer caps is empty");
|
|
|
|
gst_caps_unref (temp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now fixate, start by taking the first caps */
|
2012-03-11 18:06:59 +00:00
|
|
|
temp = gst_caps_truncate (temp);
|
|
|
|
temp = gst_caps_make_writable (temp);
|
2007-09-17 00:24:12 +00:00
|
|
|
srccaps = temp;
|
|
|
|
|
|
|
|
/* get first structure */
|
|
|
|
s = gst_caps_get_structure (srccaps, 0);
|
|
|
|
|
2007-09-17 17:52:33 +00:00
|
|
|
if (gst_structure_get_int (s, "payload", &pt)) {
|
2007-09-17 00:24:12 +00:00
|
|
|
/* use peer pt */
|
|
|
|
dtmfsrc->pt = pt;
|
|
|
|
GST_LOG_OBJECT (dtmfsrc, "using peer pt %d", pt);
|
|
|
|
} else {
|
|
|
|
if (gst_structure_has_field (s, "payload")) {
|
|
|
|
/* can only fixate if there is a field */
|
2009-02-20 22:37:43 +00:00
|
|
|
gst_structure_fixate_field_nearest_int (s, "payload", dtmfsrc->pt);
|
2007-09-17 00:24:12 +00:00
|
|
|
gst_structure_get_int (s, "payload", &pt);
|
|
|
|
GST_LOG_OBJECT (dtmfsrc, "using peer pt %d", pt);
|
|
|
|
} else {
|
|
|
|
/* no pt field, use the internal pt */
|
|
|
|
pt = dtmfsrc->pt;
|
|
|
|
gst_structure_set (s, "payload", G_TYPE_INT, pt, NULL);
|
2009-02-18 18:30:44 +00:00
|
|
|
GST_LOG_OBJECT (dtmfsrc, "using internal pt %d", pt);
|
2007-09-17 00:24:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-20 22:37:43 +00:00
|
|
|
if (gst_structure_get_int (s, "clock-rate", &clock_rate)) {
|
2008-06-13 23:30:06 +00:00
|
|
|
dtmfsrc->clock_rate = clock_rate;
|
|
|
|
GST_LOG_OBJECT (dtmfsrc, "using clock-rate from caps %d",
|
|
|
|
dtmfsrc->clock_rate);
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (dtmfsrc, "using existing clock-rate %d",
|
|
|
|
dtmfsrc->clock_rate);
|
|
|
|
}
|
2009-02-20 22:37:43 +00:00
|
|
|
gst_structure_set (s, "clock-rate", G_TYPE_INT, dtmfsrc->clock_rate, NULL);
|
2008-06-13 23:30:06 +00:00
|
|
|
|
|
|
|
|
2007-09-17 00:24:12 +00:00
|
|
|
if (gst_structure_has_field_typed (s, "ssrc", G_TYPE_UINT)) {
|
|
|
|
value = gst_structure_get_value (s, "ssrc");
|
|
|
|
dtmfsrc->current_ssrc = g_value_get_uint (value);
|
|
|
|
GST_LOG_OBJECT (dtmfsrc, "using peer ssrc %08x", dtmfsrc->current_ssrc);
|
|
|
|
} else {
|
|
|
|
/* FIXME, fixate_nearest_uint would be even better */
|
|
|
|
gst_structure_set (s, "ssrc", G_TYPE_UINT, dtmfsrc->current_ssrc, NULL);
|
|
|
|
GST_LOG_OBJECT (dtmfsrc, "using internal ssrc %08x",
|
|
|
|
dtmfsrc->current_ssrc);
|
|
|
|
}
|
|
|
|
|
2014-10-10 22:11:19 +00:00
|
|
|
if (gst_structure_has_field_typed (s, "timestamp-offset", G_TYPE_UINT)) {
|
|
|
|
value = gst_structure_get_value (s, "timestamp-offset");
|
2007-09-17 00:24:12 +00:00
|
|
|
dtmfsrc->ts_base = g_value_get_uint (value);
|
2014-10-10 22:11:19 +00:00
|
|
|
GST_LOG_OBJECT (dtmfsrc, "using peer timestamp-offset %u",
|
|
|
|
dtmfsrc->ts_base);
|
2007-09-17 00:24:12 +00:00
|
|
|
} else {
|
|
|
|
/* FIXME, fixate_nearest_uint would be even better */
|
2014-10-10 22:11:19 +00:00
|
|
|
gst_structure_set (s, "timestamp-offset", G_TYPE_UINT, dtmfsrc->ts_base,
|
|
|
|
NULL);
|
|
|
|
GST_LOG_OBJECT (dtmfsrc, "using internal timestamp-offset %u",
|
2007-09-17 00:24:12 +00:00
|
|
|
dtmfsrc->ts_base);
|
|
|
|
}
|
2014-10-10 22:11:19 +00:00
|
|
|
if (gst_structure_has_field_typed (s, "seqnum-offset", G_TYPE_UINT)) {
|
|
|
|
value = gst_structure_get_value (s, "seqnum-offset");
|
2007-09-17 00:24:12 +00:00
|
|
|
dtmfsrc->seqnum_base = g_value_get_uint (value);
|
2014-10-10 22:11:19 +00:00
|
|
|
GST_LOG_OBJECT (dtmfsrc, "using peer seqnum-offset %u",
|
2007-09-17 00:24:12 +00:00
|
|
|
dtmfsrc->seqnum_base);
|
|
|
|
} else {
|
|
|
|
/* FIXME, fixate_nearest_uint would be even better */
|
2014-10-10 22:11:19 +00:00
|
|
|
gst_structure_set (s, "seqnum-offset", G_TYPE_UINT, dtmfsrc->seqnum_base,
|
2007-09-17 00:24:12 +00:00
|
|
|
NULL);
|
2014-10-10 22:11:19 +00:00
|
|
|
GST_LOG_OBJECT (dtmfsrc, "using internal seqnum-offset %u",
|
2007-09-17 00:24:12 +00:00
|
|
|
dtmfsrc->seqnum_base);
|
|
|
|
}
|
2011-04-14 20:49:39 +00:00
|
|
|
|
|
|
|
if (gst_structure_has_field_typed (s, "ptime", G_TYPE_UINT)) {
|
|
|
|
value = gst_structure_get_value (s, "ptime");
|
|
|
|
dtmfsrc->ptime = g_value_get_uint (value);
|
|
|
|
GST_LOG_OBJECT (dtmfsrc, "using peer ptime %u", dtmfsrc->ptime);
|
|
|
|
} else if (gst_structure_has_field_typed (s, "maxptime", G_TYPE_UINT)) {
|
|
|
|
value = gst_structure_get_value (s, "maxptime");
|
|
|
|
dtmfsrc->ptime = g_value_get_uint (value);
|
|
|
|
GST_LOG_OBJECT (dtmfsrc, "using peer maxptime as ptime %u",
|
|
|
|
dtmfsrc->ptime);
|
|
|
|
} else {
|
|
|
|
/* FIXME, fixate_nearest_uint would be even better */
|
|
|
|
gst_structure_set (s, "ptime", G_TYPE_UINT, dtmfsrc->ptime, NULL);
|
|
|
|
GST_LOG_OBJECT (dtmfsrc, "using internal ptime %u", dtmfsrc->ptime);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-17 00:24:12 +00:00
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "with peer caps: %" GST_PTR_FORMAT, srccaps);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = gst_pad_set_caps (GST_BASE_SRC_PAD (basesrc), srccaps);
|
|
|
|
gst_caps_unref (srccaps);
|
|
|
|
|
|
|
|
dtmfsrc->dirty = FALSE;
|
|
|
|
|
|
|
|
return ret;
|
2007-08-20 18:48:00 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-09-01 19:39:22 +00:00
|
|
|
static gboolean
|
|
|
|
gst_rtp_dtmf_src_query (GstBaseSrc * basesrc, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstRTPDTMFSrc *dtmfsrc = GST_RTP_DTMF_SRC (basesrc);
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_LATENCY:
|
|
|
|
{
|
|
|
|
GstClockTime latency;
|
|
|
|
|
|
|
|
latency = dtmfsrc->ptime * GST_MSECOND;
|
|
|
|
gst_query_set_latency (query, gst_base_src_is_live (basesrc), latency,
|
|
|
|
GST_CLOCK_TIME_NONE);
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "Reporting latency of %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (latency));
|
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = GST_BASE_SRC_CLASS (gst_rtp_dtmf_src_parent_class)->query (basesrc,
|
|
|
|
query);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2007-09-17 00:24:12 +00:00
|
|
|
|
2007-08-20 18:48:00 +00:00
|
|
|
static void
|
2009-02-20 22:37:43 +00:00
|
|
|
gst_rtp_dtmf_src_ready_to_paused (GstRTPDTMFSrc * dtmfsrc)
|
2007-08-20 18:48:00 +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-08-20 18:48:00 +00:00
|
|
|
if (dtmfsrc->ts_offset == -1)
|
|
|
|
dtmfsrc->ts_base = g_random_int ();
|
|
|
|
else
|
|
|
|
dtmfsrc->ts_base = dtmfsrc->ts_offset;
|
2007-09-16 19:44:08 +00:00
|
|
|
|
2011-07-12 00:47:23 +00:00
|
|
|
dtmfsrc->timestamp = 0;
|
2007-08-20 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_rtp_dtmf_src_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstRTPDTMFSrc *dtmfsrc;
|
|
|
|
GstStateChangeReturn result;
|
|
|
|
gboolean no_preroll = FALSE;
|
2009-02-20 22:37:43 +00:00
|
|
|
GstRTPDTMFSrcEvent *event = NULL;
|
2007-08-20 18:48:00 +00:00
|
|
|
|
|
|
|
dtmfsrc = GST_RTP_DTMF_SRC (element);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
|
|
gst_rtp_dtmf_src_ready_to_paused (dtmfsrc);
|
2007-09-16 19:44:08 +00:00
|
|
|
|
|
|
|
/* Flushing the event queue */
|
2011-10-29 16:24:26 +00:00
|
|
|
while ((event = g_async_queue_try_pop (dtmfsrc->event_queue)) != NULL) {
|
|
|
|
gst_dtmf_src_post_message (dtmfsrc, "dtmf-event-dropped", event);
|
2009-08-11 20:23:20 +00:00
|
|
|
gst_rtp_dtmf_src_event_free (event);
|
2011-10-29 16:24:26 +00:00
|
|
|
}
|
2011-11-04 21:54:04 +00:00
|
|
|
dtmfsrc->last_event_was_start = FALSE;
|
2007-09-16 19:44:08 +00:00
|
|
|
|
2007-08-20 18:48:00 +00:00
|
|
|
no_preroll = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((result =
|
2012-01-25 10:21:50 +00:00
|
|
|
GST_ELEMENT_CLASS (gst_rtp_dtmf_src_parent_class)->change_state
|
|
|
|
(element, transition)) == GST_STATE_CHANGE_FAILURE)
|
2007-08-20 18:48:00 +00:00
|
|
|
goto failure;
|
|
|
|
|
|
|
|
switch (transition) {
|
2007-09-17 04:26:49 +00:00
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
|
|
|
no_preroll = TRUE;
|
|
|
|
break;
|
2007-09-16 19:44:08 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
|
2009-02-20 22:37:43 +00:00
|
|
|
/* Flushing the event queue */
|
2011-10-29 16:24:26 +00:00
|
|
|
while ((event = g_async_queue_try_pop (dtmfsrc->event_queue)) != NULL) {
|
|
|
|
gst_dtmf_src_post_message (dtmfsrc, "dtmf-event-dropped", event);
|
2009-08-11 20:23:20 +00:00
|
|
|
gst_rtp_dtmf_src_event_free (event);
|
2011-10-29 16:24:26 +00:00
|
|
|
}
|
2011-11-04 21:54:04 +00:00
|
|
|
dtmfsrc->last_event_was_start = FALSE;
|
2007-09-16 19:44:08 +00:00
|
|
|
|
2007-08-20 18:48:00 +00:00
|
|
|
/* Indicate that we don't do PRE_ROLL */
|
|
|
|
break;
|
2007-09-16 19:44:08 +00:00
|
|
|
|
2007-08-20 18:48:00 +00:00
|
|
|
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-09-16 19:44:08 +00:00
|
|
|
|
|
|
|
static gboolean
|
2009-02-20 22:37:43 +00:00
|
|
|
gst_rtp_dtmf_src_unlock (GstBaseSrc * src)
|
|
|
|
{
|
2007-09-16 19:44:08 +00:00
|
|
|
GstRTPDTMFSrc *dtmfsrc = GST_RTP_DTMF_SRC (src);
|
|
|
|
GstRTPDTMFSrcEvent *event = NULL;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "Called unlock");
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (dtmfsrc);
|
|
|
|
dtmfsrc->paused = TRUE;
|
|
|
|
if (dtmfsrc->clockid) {
|
|
|
|
gst_clock_id_unschedule (dtmfsrc->clockid);
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (dtmfsrc);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "Pushing the PAUSE_TASK event on unlock request");
|
2009-08-11 20:39:42 +00:00
|
|
|
event = g_slice_new0 (GstRTPDTMFSrcEvent);
|
2007-09-16 19:44:08 +00:00
|
|
|
event->event_type = RTP_DTMF_EVENT_TYPE_PAUSE_TASK;
|
|
|
|
g_async_queue_push (dtmfsrc->event_queue, event);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-20 22:37:43 +00:00
|
|
|
gst_rtp_dtmf_src_unlock_stop (GstBaseSrc * src)
|
|
|
|
{
|
2007-09-16 19:44:08 +00:00
|
|
|
GstRTPDTMFSrc *dtmfsrc = GST_RTP_DTMF_SRC (src);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (dtmfsrc, "Unlock stopped");
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (dtmfsrc);
|
|
|
|
dtmfsrc->paused = FALSE;
|
|
|
|
GST_OBJECT_UNLOCK (dtmfsrc);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-08-20 18:48:52 +00:00
|
|
|
gboolean
|
2007-08-20 18:48:00 +00:00
|
|
|
gst_rtp_dtmf_src_plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
|
|
|
return gst_element_register (plugin, "rtpdtmfsrc",
|
|
|
|
GST_RANK_NONE, GST_TYPE_RTP_DTMF_SRC);
|
|
|
|
}
|