2005-07-14 10:29:30 +00:00
|
|
|
/* GStreamer
|
2011-05-23 20:12:50 +00:00
|
|
|
* Copyright (C) <2005> Philippe Khalaf <burger@speedy.org>
|
2006-02-02 00:04:37 +00:00
|
|
|
* Copyright (C) <2005> Nokia Corporation <kai.vehmanen@nokia.com>
|
2005-07-14 10:29:30 +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
|
2012-11-03 23:05:09 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2005-07-14 10:29:30 +00:00
|
|
|
*/
|
|
|
|
|
2007-04-21 15:10:25 +00:00
|
|
|
/**
|
2011-11-11 11:32:23 +00:00
|
|
|
* SECTION:gstrtpbasedepayload
|
2007-04-21 15:10:25 +00:00
|
|
|
* @short_description: Base class for RTP depayloader
|
|
|
|
*
|
|
|
|
* Provides a base class for RTP depayloaders
|
|
|
|
*/
|
|
|
|
|
2011-11-11 11:32:23 +00:00
|
|
|
#include "gstrtpbasedepayload.h"
|
2005-07-14 10:29:30 +00:00
|
|
|
|
2011-11-11 11:32:23 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (rtpbasedepayload_debug);
|
|
|
|
#define GST_CAT_DEFAULT (rtpbasedepayload_debug)
|
2005-07-14 10:29:30 +00:00
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
#define GST_RTP_BASE_DEPAYLOAD_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTP_BASE_DEPAYLOAD, GstRTPBaseDepayloadPrivate))
|
2007-03-29 16:23:53 +00:00
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
struct _GstRTPBaseDepayloadPrivate
|
2007-03-29 16:23:53 +00:00
|
|
|
{
|
2007-05-12 16:18:39 +00:00
|
|
|
GstClockTime npt_start;
|
|
|
|
GstClockTime npt_stop;
|
|
|
|
gdouble play_speed;
|
|
|
|
gdouble play_scale;
|
2015-03-27 20:22:36 +00:00
|
|
|
guint clock_base;
|
2007-06-05 16:19:30 +00:00
|
|
|
|
2007-09-04 16:18:48 +00:00
|
|
|
gboolean discont;
|
2011-11-10 16:18:00 +00:00
|
|
|
GstClockTime pts;
|
|
|
|
GstClockTime dts;
|
2007-09-19 16:09:57 +00:00
|
|
|
GstClockTime duration;
|
2008-05-23 14:14:28 +00:00
|
|
|
|
2014-04-12 05:10:36 +00:00
|
|
|
guint32 last_seqnum;
|
|
|
|
guint32 last_rtptime;
|
2008-05-23 14:14:28 +00:00
|
|
|
guint32 next_seqnum;
|
2008-10-13 09:16:59 +00:00
|
|
|
|
|
|
|
gboolean negotiated;
|
2013-04-10 19:45:37 +00:00
|
|
|
|
|
|
|
GstCaps *last_caps;
|
2015-03-27 20:22:36 +00:00
|
|
|
GstEvent *segment_event;
|
2007-03-29 16:23:53 +00:00
|
|
|
};
|
|
|
|
|
2005-07-14 10:29:30 +00:00
|
|
|
/* Filter signals and args */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2007-03-29 16:23:53 +00:00
|
|
|
PROP_0,
|
2014-04-12 05:10:36 +00:00
|
|
|
PROP_STATS,
|
2008-05-02 12:11:07 +00:00
|
|
|
PROP_LAST
|
2005-07-14 10:29:30 +00:00
|
|
|
};
|
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
static void gst_rtp_base_depayload_finalize (GObject * object);
|
|
|
|
static void gst_rtp_base_depayload_set_property (GObject * object,
|
2005-07-14 10:29:30 +00:00
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
2011-11-11 11:24:08 +00:00
|
|
|
static void gst_rtp_base_depayload_get_property (GObject * object,
|
2005-07-14 10:29:30 +00:00
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
static GstFlowReturn gst_rtp_base_depayload_chain (GstPad * pad,
|
2011-11-17 11:48:25 +00:00
|
|
|
GstObject * parent, GstBuffer * in);
|
2015-05-21 12:59:55 +00:00
|
|
|
static GstFlowReturn gst_rtp_base_depayload_chain_list (GstPad * pad,
|
|
|
|
GstObject * parent, GstBufferList * list);
|
2011-11-11 11:24:08 +00:00
|
|
|
static gboolean gst_rtp_base_depayload_handle_sink_event (GstPad * pad,
|
2011-11-17 11:48:25 +00:00
|
|
|
GstObject * parent, GstEvent * event);
|
2005-07-14 10:29:30 +00:00
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
static GstStateChangeReturn gst_rtp_base_depayload_change_state (GstElement *
|
2005-09-02 15:43:18 +00:00
|
|
|
element, GstStateChange transition);
|
2007-03-29 16:23:53 +00:00
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
static gboolean gst_rtp_base_depayload_packet_lost (GstRTPBaseDepayload *
|
2008-05-02 12:11:07 +00:00
|
|
|
filter, GstEvent * event);
|
2011-11-11 11:24:08 +00:00
|
|
|
static gboolean gst_rtp_base_depayload_handle_event (GstRTPBaseDepayload *
|
2010-12-21 14:02:18 +00:00
|
|
|
filter, GstEvent * event);
|
2005-07-14 10:29:30 +00:00
|
|
|
|
2011-04-18 16:29:35 +00:00
|
|
|
static GstElementClass *parent_class = NULL;
|
2011-11-11 11:24:08 +00:00
|
|
|
static void gst_rtp_base_depayload_class_init (GstRTPBaseDepayloadClass *
|
2011-04-18 16:29:35 +00:00
|
|
|
klass);
|
2011-11-11 11:32:23 +00:00
|
|
|
static void gst_rtp_base_depayload_init (GstRTPBaseDepayload * rtpbasepayload,
|
2011-11-11 11:24:08 +00:00
|
|
|
GstRTPBaseDepayloadClass * klass);
|
2015-03-27 20:22:36 +00:00
|
|
|
static GstEvent *create_segment_event (GstRTPBaseDepayload * filter,
|
|
|
|
guint rtptime, GstClockTime position);
|
2011-04-18 16:29:35 +00:00
|
|
|
|
|
|
|
GType
|
2011-11-11 11:24:08 +00:00
|
|
|
gst_rtp_base_depayload_get_type (void)
|
2005-07-14 10:29:30 +00:00
|
|
|
{
|
2011-11-11 11:24:08 +00:00
|
|
|
static GType rtp_base_depayload_type = 0;
|
2011-04-18 16:29:35 +00:00
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
if (g_once_init_enter ((gsize *) & rtp_base_depayload_type)) {
|
|
|
|
static const GTypeInfo rtp_base_depayload_info = {
|
|
|
|
sizeof (GstRTPBaseDepayloadClass),
|
2011-04-18 16:29:35 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2011-11-11 11:24:08 +00:00
|
|
|
(GClassInitFunc) gst_rtp_base_depayload_class_init,
|
2011-04-18 16:29:35 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2011-11-11 11:24:08 +00:00
|
|
|
sizeof (GstRTPBaseDepayload),
|
2011-04-18 16:29:35 +00:00
|
|
|
0,
|
2011-11-11 11:24:08 +00:00
|
|
|
(GInstanceInitFunc) gst_rtp_base_depayload_init,
|
2011-04-18 16:29:35 +00:00
|
|
|
};
|
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
g_once_init_leave ((gsize *) & rtp_base_depayload_type,
|
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstRTPBaseDepayload",
|
|
|
|
&rtp_base_depayload_info, G_TYPE_FLAG_ABSTRACT));
|
2011-04-18 16:29:35 +00:00
|
|
|
}
|
2011-11-11 11:24:08 +00:00
|
|
|
return rtp_base_depayload_type;
|
2005-07-14 10:29:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-11 11:24:08 +00:00
|
|
|
gst_rtp_base_depayload_class_init (GstRTPBaseDepayloadClass * klass)
|
2005-07-14 10:29:30 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2005-08-12 13:34:56 +00:00
|
|
|
GstElementClass *gstelement_class;
|
2005-07-14 10:29:30 +00:00
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
2005-08-12 13:34:56 +00:00
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2005-10-26 20:00:46 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2005-07-14 10:29:30 +00:00
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstRTPBaseDepayloadPrivate));
|
2007-03-29 16:23:53 +00:00
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
gobject_class->finalize = gst_rtp_base_depayload_finalize;
|
|
|
|
gobject_class->set_property = gst_rtp_base_depayload_set_property;
|
|
|
|
gobject_class->get_property = gst_rtp_base_depayload_get_property;
|
2005-07-14 10:29:30 +00:00
|
|
|
|
2014-04-12 05:10:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GstRTPBaseDepayload:stats:
|
|
|
|
*
|
|
|
|
* Various depayloader statistics retrieved atomically (and are therefore
|
|
|
|
* synchroized with each other). This property return a GstStructure named
|
|
|
|
* application/x-rtp-depayload-stats containing the following fields relating to
|
|
|
|
* the last processed buffer and current state of the stream being depayloaded:
|
|
|
|
*
|
|
|
|
* <variablelist>
|
|
|
|
* <varlistentry>
|
|
|
|
* <term>clock-rate</term>
|
|
|
|
* <listitem><para>#G_TYPE_UINT, clock-rate of the
|
|
|
|
* stream</para></listitem>
|
|
|
|
* </varlistentry>
|
|
|
|
* <varlistentry>
|
|
|
|
* <term>npt-start</term>
|
|
|
|
* <listitem><para>#G_TYPE_UINT64, time of playback start
|
|
|
|
* </para></listitem>
|
|
|
|
* </varlistentry>
|
|
|
|
* <varlistentry>
|
|
|
|
* <term>npt-stop</term>
|
|
|
|
* <listitem><para>#G_TYPE_UINT64, time of playback stop
|
|
|
|
* </para></listitem>
|
|
|
|
* </varlistentry>
|
|
|
|
* <varlistentry>
|
|
|
|
* <term>play-speed</term>
|
|
|
|
* <listitem><para>#G_TYPE_DOUBLE, the playback speed
|
|
|
|
* </para></listitem>
|
|
|
|
* </varlistentry>
|
|
|
|
* <varlistentry>
|
|
|
|
* <term>play-scale</term>
|
|
|
|
* <listitem><para>#G_TYPE_DOUBLE, the playback scale
|
|
|
|
* </para></listitem>
|
|
|
|
* </varlistentry>
|
|
|
|
* <varlistentry>
|
|
|
|
* <term>running-time-dts</term>
|
|
|
|
* <listitem><para>#G_TYPE_UINT64, the last running-time of the
|
|
|
|
* last DTS
|
|
|
|
* </para></listitem>
|
|
|
|
* </varlistentry>
|
|
|
|
* <varlistentry>
|
|
|
|
* <term>running-time-pts</term>
|
|
|
|
* <listitem><para>#G_TYPE_UINT64, the last running-time of the
|
|
|
|
* last PTS
|
|
|
|
* </para></listitem>
|
|
|
|
* </varlistentry>
|
|
|
|
* <varlistentry>
|
|
|
|
* <term>seqnum</term>
|
|
|
|
* <listitem><para>#G_TYPE_UINT, the last seen seqnum
|
|
|
|
* </para></listitem>
|
|
|
|
* </varlistentry>
|
|
|
|
* <varlistentry>
|
|
|
|
* <term>timestamp</term>
|
|
|
|
* <listitem><para>#G_TYPE_UINT, the last seen RTP timestamp
|
|
|
|
* </para></listitem>
|
|
|
|
* </varlistentry>
|
|
|
|
* </variablelist>
|
|
|
|
**/
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_STATS,
|
|
|
|
g_param_spec_boxed ("stats", "Statistics", "Various statistics",
|
|
|
|
GST_TYPE_STRUCTURE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
gstelement_class->change_state = gst_rtp_base_depayload_change_state;
|
2005-08-12 13:34:56 +00:00
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
klass->packet_lost = gst_rtp_base_depayload_packet_lost;
|
|
|
|
klass->handle_event = gst_rtp_base_depayload_handle_event;
|
2005-07-14 10:29:30 +00:00
|
|
|
|
2011-11-11 11:32:23 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (rtpbasedepayload_debug, "rtpbasedepayload", 0,
|
2005-07-14 10:29:30 +00:00
|
|
|
"Base class for RTP Depayloaders");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-11 11:24:08 +00:00
|
|
|
gst_rtp_base_depayload_init (GstRTPBaseDepayload * filter,
|
|
|
|
GstRTPBaseDepayloadClass * klass)
|
2005-07-14 10:29:30 +00:00
|
|
|
{
|
|
|
|
GstPadTemplate *pad_template;
|
2011-11-11 11:24:08 +00:00
|
|
|
GstRTPBaseDepayloadPrivate *priv;
|
2007-03-29 16:23:53 +00:00
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
priv = GST_RTP_BASE_DEPAYLOAD_GET_PRIVATE (filter);
|
2007-03-29 16:23:53 +00:00
|
|
|
filter->priv = priv;
|
2005-07-14 10:29:30 +00:00
|
|
|
|
2005-10-31 15:32:54 +00:00
|
|
|
GST_DEBUG_OBJECT (filter, "init");
|
2005-07-14 10:29:30 +00:00
|
|
|
|
|
|
|
pad_template =
|
2007-03-29 16:23:53 +00:00
|
|
|
gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "sink");
|
2005-07-14 10:29:30 +00:00
|
|
|
g_return_if_fail (pad_template != NULL);
|
|
|
|
filter->sinkpad = gst_pad_new_from_template (pad_template, "sink");
|
2011-11-11 11:24:08 +00:00
|
|
|
gst_pad_set_chain_function (filter->sinkpad, gst_rtp_base_depayload_chain);
|
2015-05-21 12:59:55 +00:00
|
|
|
gst_pad_set_chain_list_function (filter->sinkpad,
|
|
|
|
gst_rtp_base_depayload_chain_list);
|
2005-12-18 00:56:07 +00:00
|
|
|
gst_pad_set_event_function (filter->sinkpad,
|
2011-11-11 11:24:08 +00:00
|
|
|
gst_rtp_base_depayload_handle_sink_event);
|
2005-07-14 10:29:30 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
|
|
|
|
|
|
|
pad_template =
|
2007-03-29 16:23:53 +00:00
|
|
|
gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "src");
|
2005-07-14 10:29:30 +00:00
|
|
|
g_return_if_fail (pad_template != NULL);
|
|
|
|
filter->srcpad = gst_pad_new_from_template (pad_template, "src");
|
2006-09-27 11:06:54 +00:00
|
|
|
gst_pad_use_fixed_caps (filter->srcpad);
|
2005-07-14 10:29:30 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
|
|
|
|
2014-04-12 05:10:36 +00:00
|
|
|
priv->npt_start = 0;
|
|
|
|
priv->npt_stop = -1;
|
|
|
|
priv->play_speed = 1.0;
|
|
|
|
priv->play_scale = 1.0;
|
2015-03-27 20:22:36 +00:00
|
|
|
priv->clock_base = -1;
|
2014-04-12 05:10:36 +00:00
|
|
|
priv->dts = -1;
|
|
|
|
priv->pts = -1;
|
|
|
|
priv->duration = -1;
|
|
|
|
|
2007-09-16 19:31:06 +00:00
|
|
|
gst_segment_init (&filter->segment, GST_FORMAT_UNDEFINED);
|
2005-07-14 10:29:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-11 11:24:08 +00:00
|
|
|
gst_rtp_base_depayload_finalize (GObject * object)
|
2005-07-14 10:29:30 +00:00
|
|
|
{
|
2006-09-22 14:13:34 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2005-07-14 10:29:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-11 11:24:08 +00:00
|
|
|
gst_rtp_base_depayload_setcaps (GstRTPBaseDepayload * filter, GstCaps * caps)
|
2005-07-14 10:29:30 +00:00
|
|
|
{
|
2011-11-11 11:24:08 +00:00
|
|
|
GstRTPBaseDepayloadClass *bclass;
|
|
|
|
GstRTPBaseDepayloadPrivate *priv;
|
2006-03-07 12:49:03 +00:00
|
|
|
gboolean res;
|
2007-03-29 16:23:53 +00:00
|
|
|
GstStructure *caps_struct;
|
|
|
|
const GValue *value;
|
2005-07-14 10:29:30 +00:00
|
|
|
|
2007-03-29 16:23:53 +00:00
|
|
|
priv = filter->priv;
|
2005-07-14 10:29:30 +00:00
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
bclass = GST_RTP_BASE_DEPAYLOAD_GET_CLASS (filter);
|
2005-07-14 10:29:30 +00:00
|
|
|
|
2013-04-10 19:45:37 +00:00
|
|
|
GST_DEBUG_OBJECT (filter, "Set caps %" GST_PTR_FORMAT, caps);
|
|
|
|
|
|
|
|
if (priv->last_caps) {
|
|
|
|
if (gst_caps_is_equal (priv->last_caps, caps)) {
|
|
|
|
res = TRUE;
|
|
|
|
goto caps_not_changed;
|
|
|
|
} else {
|
|
|
|
gst_caps_unref (priv->last_caps);
|
|
|
|
priv->last_caps = NULL;
|
|
|
|
}
|
|
|
|
}
|
2007-03-29 16:23:53 +00:00
|
|
|
|
|
|
|
caps_struct = gst_caps_get_structure (caps, 0);
|
|
|
|
|
2007-05-12 16:18:39 +00:00
|
|
|
/* get other values for newsegment */
|
|
|
|
value = gst_structure_get_value (caps_struct, "npt-start");
|
|
|
|
if (value && G_VALUE_HOLDS_UINT64 (value))
|
|
|
|
priv->npt_start = g_value_get_uint64 (value);
|
|
|
|
else
|
|
|
|
priv->npt_start = 0;
|
2007-10-08 18:04:34 +00:00
|
|
|
GST_DEBUG_OBJECT (filter, "NPT start %" G_GUINT64_FORMAT, priv->npt_start);
|
2007-05-12 16:18:39 +00:00
|
|
|
|
|
|
|
value = gst_structure_get_value (caps_struct, "npt-stop");
|
|
|
|
if (value && G_VALUE_HOLDS_UINT64 (value))
|
|
|
|
priv->npt_stop = g_value_get_uint64 (value);
|
|
|
|
else
|
|
|
|
priv->npt_stop = -1;
|
|
|
|
|
2007-10-08 18:04:34 +00:00
|
|
|
GST_DEBUG_OBJECT (filter, "NPT stop %" G_GUINT64_FORMAT, priv->npt_stop);
|
2007-09-16 19:31:06 +00:00
|
|
|
|
2007-05-12 16:18:39 +00:00
|
|
|
value = gst_structure_get_value (caps_struct, "play-speed");
|
|
|
|
if (value && G_VALUE_HOLDS_DOUBLE (value))
|
|
|
|
priv->play_speed = g_value_get_double (value);
|
|
|
|
else
|
|
|
|
priv->play_speed = 1.0;
|
|
|
|
|
|
|
|
value = gst_structure_get_value (caps_struct, "play-scale");
|
|
|
|
if (value && G_VALUE_HOLDS_DOUBLE (value))
|
|
|
|
priv->play_scale = g_value_get_double (value);
|
|
|
|
else
|
|
|
|
priv->play_scale = 1.0;
|
|
|
|
|
2015-03-27 20:22:36 +00:00
|
|
|
value = gst_structure_get_value (caps_struct, "clock-base");
|
|
|
|
if (value && G_VALUE_HOLDS_UINT (value))
|
|
|
|
priv->clock_base = g_value_get_uint (value);
|
|
|
|
else
|
|
|
|
priv->clock_base = -1;
|
|
|
|
|
2010-09-06 17:17:10 +00:00
|
|
|
if (bclass->set_caps) {
|
2006-03-07 12:49:03 +00:00
|
|
|
res = bclass->set_caps (filter, caps);
|
2010-09-06 17:17:10 +00:00
|
|
|
if (!res) {
|
|
|
|
GST_WARNING_OBJECT (filter, "Subclass rejected caps %" GST_PTR_FORMAT,
|
|
|
|
caps);
|
|
|
|
}
|
|
|
|
} else {
|
2006-03-07 12:49:03 +00:00
|
|
|
res = TRUE;
|
2010-09-06 17:17:10 +00:00
|
|
|
}
|
2006-03-07 12:49:03 +00:00
|
|
|
|
2008-10-13 09:16:59 +00:00
|
|
|
priv->negotiated = res;
|
|
|
|
|
2013-04-10 19:45:37 +00:00
|
|
|
if (priv->negotiated)
|
|
|
|
priv->last_caps = gst_caps_ref (caps);
|
|
|
|
|
2006-03-07 12:49:03 +00:00
|
|
|
return res;
|
2013-04-10 19:45:37 +00:00
|
|
|
|
|
|
|
caps_not_changed:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (filter, "Caps did not change");
|
|
|
|
return res;
|
|
|
|
}
|
2005-07-14 10:29:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2015-05-21 12:59:55 +00:00
|
|
|
gst_rtp_base_depayload_handle_buffer (GstRTPBaseDepayload * filter,
|
|
|
|
GstRTPBaseDepayloadClass * bclass, GstBuffer * in)
|
2005-07-14 10:29:30 +00:00
|
|
|
{
|
2011-11-11 11:24:08 +00:00
|
|
|
GstRTPBaseDepayloadPrivate *priv;
|
2005-07-14 10:29:30 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2007-08-31 15:58:30 +00:00
|
|
|
GstBuffer *out_buf;
|
2011-11-10 16:18:00 +00:00
|
|
|
GstClockTime pts, dts;
|
2008-05-23 14:14:28 +00:00
|
|
|
guint16 seqnum;
|
2008-10-06 16:29:33 +00:00
|
|
|
guint32 rtptime;
|
2013-08-21 10:34:24 +00:00
|
|
|
gboolean discont, buf_discont;
|
2008-05-23 14:14:28 +00:00
|
|
|
gint gap;
|
2011-12-05 17:42:24 +00:00
|
|
|
GstRTPBuffer rtp = { NULL };
|
2005-07-14 10:29:30 +00:00
|
|
|
|
2008-10-13 09:16:59 +00:00
|
|
|
priv = filter->priv;
|
|
|
|
|
|
|
|
/* we must have a setcaps first */
|
|
|
|
if (G_UNLIKELY (!priv->negotiated))
|
|
|
|
goto not_negotiated;
|
2005-07-14 10:29:30 +00:00
|
|
|
|
2012-07-17 14:35:06 +00:00
|
|
|
if (G_UNLIKELY (!gst_rtp_buffer_map (in, GST_MAP_READ, &rtp)))
|
2008-05-14 20:28:02 +00:00
|
|
|
goto invalid_buffer;
|
|
|
|
|
2013-08-21 10:34:24 +00:00
|
|
|
buf_discont = GST_BUFFER_IS_DISCONT (in);
|
2007-09-04 16:18:48 +00:00
|
|
|
|
2011-11-10 16:18:00 +00:00
|
|
|
pts = GST_BUFFER_PTS (in);
|
|
|
|
dts = GST_BUFFER_DTS (in);
|
2007-09-16 19:31:06 +00:00
|
|
|
/* convert to running_time and save the timestamp, this is the timestamp
|
|
|
|
* we put on outgoing buffers. */
|
2011-11-10 16:18:00 +00:00
|
|
|
pts = gst_segment_to_running_time (&filter->segment, GST_FORMAT_TIME, pts);
|
|
|
|
dts = gst_segment_to_running_time (&filter->segment, GST_FORMAT_TIME, dts);
|
|
|
|
priv->pts = pts;
|
|
|
|
priv->dts = dts;
|
2007-09-19 16:09:57 +00:00
|
|
|
priv->duration = GST_BUFFER_DURATION (in);
|
2007-09-16 19:31:06 +00:00
|
|
|
|
2011-03-27 11:55:15 +00:00
|
|
|
seqnum = gst_rtp_buffer_get_seq (&rtp);
|
|
|
|
rtptime = gst_rtp_buffer_get_timestamp (&rtp);
|
|
|
|
gst_rtp_buffer_unmap (&rtp);
|
|
|
|
|
2014-04-12 05:10:36 +00:00
|
|
|
priv->last_seqnum = seqnum;
|
|
|
|
priv->last_rtptime = rtptime;
|
|
|
|
|
2013-08-21 10:34:24 +00:00
|
|
|
discont = buf_discont;
|
2008-05-23 14:14:28 +00:00
|
|
|
|
2011-11-10 16:18:00 +00:00
|
|
|
GST_LOG_OBJECT (filter, "discont %d, seqnum %u, rtptime %u, pts %"
|
2013-08-21 10:34:24 +00:00
|
|
|
GST_TIME_FORMAT ", dts %" GST_TIME_FORMAT, buf_discont, seqnum, rtptime,
|
2011-11-10 16:18:00 +00:00
|
|
|
GST_TIME_ARGS (pts), GST_TIME_ARGS (dts));
|
2008-05-23 14:14:28 +00:00
|
|
|
|
|
|
|
/* Check seqnum. This is a very simple check that makes sure that the seqnums
|
|
|
|
* are striclty increasing, dropping anything that is out of the ordinary. We
|
|
|
|
* can only do this when the next_seqnum is known. */
|
2008-10-13 09:16:59 +00:00
|
|
|
if (G_LIKELY (priv->next_seqnum != -1)) {
|
2008-05-23 14:14:28 +00:00
|
|
|
gap = gst_rtp_buffer_compare_seqnum (seqnum, priv->next_seqnum);
|
|
|
|
|
|
|
|
/* if we have no gap, all is fine */
|
|
|
|
if (G_UNLIKELY (gap != 0)) {
|
|
|
|
GST_LOG_OBJECT (filter, "got packet %u, expected %u, gap %d", seqnum,
|
|
|
|
priv->next_seqnum, gap);
|
|
|
|
if (gap < 0) {
|
|
|
|
/* seqnum > next_seqnum, we are missing some packets, this is always a
|
|
|
|
* DISCONT. */
|
|
|
|
GST_LOG_OBJECT (filter, "%d missing packets", gap);
|
|
|
|
discont = TRUE;
|
|
|
|
} else {
|
|
|
|
/* seqnum < next_seqnum, we have seen this packet before or the sender
|
|
|
|
* could be restarted. If the packet is not too old, we throw it away as
|
|
|
|
* a duplicate, otherwise we mark discont and continue. 100 misordered
|
|
|
|
* packets is a good threshold. See also RFC 4737. */
|
|
|
|
if (gap < 100)
|
|
|
|
goto dropping;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (filter,
|
|
|
|
"%d > 100, packet too old, sender likely restarted", gap);
|
|
|
|
discont = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
priv->next_seqnum = (seqnum + 1) & 0xffff;
|
|
|
|
|
2013-08-21 10:34:24 +00:00
|
|
|
if (G_UNLIKELY (discont)) {
|
2008-05-23 14:14:28 +00:00
|
|
|
priv->discont = TRUE;
|
2013-08-21 10:34:24 +00:00
|
|
|
if (!buf_discont) {
|
|
|
|
/* we detected a seqnum discont but the buffer was not flagged with a discont,
|
|
|
|
* set the discont flag so that the subclass can throw away old data. */
|
|
|
|
GST_LOG_OBJECT (filter, "mark DISCONT on input buffer");
|
|
|
|
in = gst_buffer_make_writable (in);
|
|
|
|
GST_BUFFER_FLAG_SET (in, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
}
|
2008-05-23 14:14:28 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 20:22:36 +00:00
|
|
|
/* prepare segment event if needed */
|
|
|
|
if (filter->need_newsegment) {
|
|
|
|
priv->segment_event = create_segment_event (filter, rtptime,
|
|
|
|
GST_BUFFER_PTS (in));
|
|
|
|
filter->need_newsegment = FALSE;
|
|
|
|
}
|
|
|
|
|
2008-05-23 14:14:28 +00:00
|
|
|
if (G_UNLIKELY (bclass->process == NULL))
|
|
|
|
goto no_process;
|
|
|
|
|
2007-08-31 15:58:30 +00:00
|
|
|
/* let's send it out to processing */
|
|
|
|
out_buf = bclass->process (filter, in);
|
|
|
|
if (out_buf) {
|
2011-11-11 11:24:08 +00:00
|
|
|
ret = gst_rtp_base_depayload_push (filter, out_buf);
|
2005-07-14 10:29:30 +00:00
|
|
|
}
|
2007-08-31 15:58:30 +00:00
|
|
|
|
2005-07-14 10:29:30 +00:00
|
|
|
return ret;
|
2008-05-14 20:28:02 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2008-10-13 09:16:59 +00:00
|
|
|
not_negotiated:
|
|
|
|
{
|
|
|
|
/* this is not fatal but should be filtered earlier */
|
2011-05-09 11:05:12 +00:00
|
|
|
GST_ELEMENT_ERROR (filter, CORE, NEGOTIATION,
|
|
|
|
("No RTP format was negotiated."),
|
|
|
|
("Input buffers need to have RTP caps set on them. This is usually "
|
|
|
|
"achieved by setting the 'caps' property of the upstream source "
|
|
|
|
"element (often udpsrc or appsrc), or by putting a capsfilter "
|
|
|
|
"element before the depayloader and setting the 'caps' property "
|
|
|
|
"on that. Also see http://cgit.freedesktop.org/gstreamer/"
|
|
|
|
"gst-plugins-good/tree/gst/rtp/README"));
|
2008-10-13 09:16:59 +00:00
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
}
|
2008-05-14 20:28:02 +00:00
|
|
|
invalid_buffer:
|
|
|
|
{
|
|
|
|
/* this is not fatal but should be filtered earlier */
|
|
|
|
GST_ELEMENT_WARNING (filter, STREAM, DECODE, (NULL),
|
|
|
|
("Received invalid RTP payload, dropping"));
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
2008-05-23 14:14:28 +00:00
|
|
|
dropping:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (filter, "%d <= 100, dropping old packet", gap);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
no_process:
|
|
|
|
{
|
|
|
|
/* this is not fatal but should be filtered earlier */
|
|
|
|
GST_ELEMENT_ERROR (filter, STREAM, NOT_IMPLEMENTED, (NULL),
|
|
|
|
("The subclass does not have a process method"));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2005-07-14 10:29:30 +00:00
|
|
|
}
|
|
|
|
|
2015-05-21 12:59:55 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_rtp_base_depayload_chain (GstPad * pad, GstObject * parent, GstBuffer * in)
|
|
|
|
{
|
|
|
|
GstRTPBaseDepayloadClass *bclass;
|
|
|
|
GstRTPBaseDepayload *basedepay;
|
|
|
|
GstFlowReturn flow_ret;
|
|
|
|
|
|
|
|
basedepay = GST_RTP_BASE_DEPAYLOAD_CAST (parent);
|
|
|
|
|
|
|
|
bclass = GST_RTP_BASE_DEPAYLOAD_GET_CLASS (basedepay);
|
|
|
|
|
|
|
|
flow_ret = gst_rtp_base_depayload_handle_buffer (basedepay, bclass, in);
|
|
|
|
|
|
|
|
gst_buffer_unref (in);
|
|
|
|
|
|
|
|
return flow_ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_rtp_base_depayload_chain_list (GstPad * pad, GstObject * parent,
|
|
|
|
GstBufferList * list)
|
|
|
|
{
|
|
|
|
GstRTPBaseDepayloadClass *bclass;
|
|
|
|
GstRTPBaseDepayload *basedepay;
|
|
|
|
GstFlowReturn flow_ret;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
guint i, len;
|
|
|
|
|
|
|
|
basedepay = GST_RTP_BASE_DEPAYLOAD_CAST (parent);
|
|
|
|
|
|
|
|
bclass = GST_RTP_BASE_DEPAYLOAD_GET_CLASS (basedepay);
|
|
|
|
|
|
|
|
flow_ret = GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* chain each buffer in list individually */
|
|
|
|
len = gst_buffer_list_length (list);
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
buffer = gst_buffer_list_get (list, i);
|
|
|
|
|
|
|
|
/* Should we fix up any missing timestamps for list buffers here
|
|
|
|
* (e.g. set to first or previous timestamp in list) or just assume
|
|
|
|
* the's a jitterbuffer that will have done that for us? */
|
|
|
|
flow_ret = gst_rtp_base_depayload_handle_buffer (basedepay, bclass, buffer);
|
|
|
|
if (flow_ret != GST_FLOW_OK)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
|
|
|
gst_buffer_list_unref (list);
|
|
|
|
|
|
|
|
return flow_ret;
|
|
|
|
}
|
|
|
|
|
2005-12-18 00:56:07 +00:00
|
|
|
static gboolean
|
2011-11-11 11:24:08 +00:00
|
|
|
gst_rtp_base_depayload_handle_event (GstRTPBaseDepayload * filter,
|
2010-12-21 14:02:18 +00:00
|
|
|
GstEvent * event)
|
2005-12-18 00:56:07 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
2009-08-31 18:31:56 +00:00
|
|
|
gboolean forward = TRUE;
|
2005-12-18 00:56:07 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2007-09-16 19:31:06 +00:00
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
gst_segment_init (&filter->segment, GST_FORMAT_UNDEFINED);
|
|
|
|
filter->need_newsegment = TRUE;
|
2008-05-23 14:14:28 +00:00
|
|
|
filter->priv->next_seqnum = -1;
|
2015-03-27 20:22:36 +00:00
|
|
|
gst_event_replace (&filter->priv->segment_event, NULL);
|
2007-09-16 19:31:06 +00:00
|
|
|
break;
|
2011-06-02 17:21:24 +00:00
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
gst_event_parse_caps (event, &caps);
|
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
res = gst_rtp_base_depayload_setcaps (filter, caps);
|
2011-06-02 17:21:24 +00:00
|
|
|
forward = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2011-05-16 11:48:11 +00:00
|
|
|
case GST_EVENT_SEGMENT:
|
2005-12-18 00:56:07 +00:00
|
|
|
{
|
2011-05-18 15:23:18 +00:00
|
|
|
gst_event_copy_segment (event, &filter->segment);
|
2007-09-16 19:31:06 +00:00
|
|
|
/* don't pass the event downstream, we generate our own segment including
|
|
|
|
* the NTP time and other things we receive in caps */
|
2009-08-31 18:31:56 +00:00
|
|
|
forward = FALSE;
|
2007-09-16 19:31:06 +00:00
|
|
|
break;
|
2006-07-27 10:52:52 +00:00
|
|
|
}
|
2008-05-02 12:11:07 +00:00
|
|
|
case GST_EVENT_CUSTOM_DOWNSTREAM:
|
|
|
|
{
|
2011-11-11 11:24:08 +00:00
|
|
|
GstRTPBaseDepayloadClass *bclass;
|
2008-05-02 12:11:07 +00:00
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
bclass = GST_RTP_BASE_DEPAYLOAD_GET_CLASS (filter);
|
2008-05-02 12:11:07 +00:00
|
|
|
|
|
|
|
if (gst_event_has_name (event, "GstRTPPacketLost")) {
|
|
|
|
/* we get this event from the jitterbuffer when it considers a packet as
|
|
|
|
* being lost. We send it to our packet_lost vmethod. The default
|
2012-09-05 10:00:50 +00:00
|
|
|
* implementation will make time progress by pushing out a GAP event.
|
2014-01-30 23:06:30 +00:00
|
|
|
* Subclasses can override and do one of the following:
|
2008-05-02 12:11:07 +00:00
|
|
|
* - Adjust timestamp/duration to something more accurate before
|
|
|
|
* calling the parent (default) packet_lost method.
|
|
|
|
* - do some more advanced error concealing on the already received
|
|
|
|
* (fragmented) packets.
|
|
|
|
* - ignore the packet lost.
|
|
|
|
*/
|
|
|
|
if (bclass->packet_lost)
|
|
|
|
res = bclass->packet_lost (filter, event);
|
2009-08-31 18:31:56 +00:00
|
|
|
forward = FALSE;
|
2008-05-02 12:11:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-12-18 00:56:07 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-08-31 18:31:56 +00:00
|
|
|
|
|
|
|
if (forward)
|
|
|
|
res = gst_pad_push_event (filter->srcpad, event);
|
|
|
|
else
|
|
|
|
gst_event_unref (event);
|
|
|
|
|
2005-12-18 00:56:07 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-12-21 14:02:18 +00:00
|
|
|
static gboolean
|
2011-11-17 11:48:25 +00:00
|
|
|
gst_rtp_base_depayload_handle_sink_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event)
|
2010-12-21 14:02:18 +00:00
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
2011-11-11 11:24:08 +00:00
|
|
|
GstRTPBaseDepayload *filter;
|
|
|
|
GstRTPBaseDepayloadClass *bclass;
|
2010-12-21 14:02:18 +00:00
|
|
|
|
2011-11-17 11:48:25 +00:00
|
|
|
filter = GST_RTP_BASE_DEPAYLOAD (parent);
|
2011-11-11 11:24:08 +00:00
|
|
|
bclass = GST_RTP_BASE_DEPAYLOAD_GET_CLASS (filter);
|
2010-12-21 14:02:18 +00:00
|
|
|
if (bclass->handle_event)
|
|
|
|
res = bclass->handle_event (filter, event);
|
2011-04-08 13:10:02 +00:00
|
|
|
else
|
|
|
|
gst_event_unref (event);
|
2010-12-21 14:02:18 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2008-11-11 16:40:50 +00:00
|
|
|
static GstEvent *
|
2015-03-27 20:22:36 +00:00
|
|
|
create_segment_event (GstRTPBaseDepayload * filter, guint rtptime,
|
|
|
|
GstClockTime position)
|
2008-11-11 16:40:50 +00:00
|
|
|
{
|
|
|
|
GstEvent *event;
|
2015-03-27 20:22:36 +00:00
|
|
|
GstClockTime start, stop, running_time;
|
2011-11-11 11:24:08 +00:00
|
|
|
GstRTPBaseDepayloadPrivate *priv;
|
2011-05-16 11:48:11 +00:00
|
|
|
GstSegment segment;
|
2008-11-11 16:40:50 +00:00
|
|
|
|
|
|
|
priv = filter->priv;
|
|
|
|
|
2015-05-05 11:14:12 +00:00
|
|
|
/* determining the start of the segment */
|
2015-03-27 20:22:36 +00:00
|
|
|
start = 0;
|
|
|
|
if (priv->clock_base != -1 && position != -1) {
|
|
|
|
GstClockTime exttime, gap;
|
|
|
|
|
|
|
|
exttime = priv->clock_base;
|
|
|
|
gst_rtp_buffer_ext_timestamp (&exttime, rtptime);
|
|
|
|
gap = gst_util_uint64_scale_int (exttime - priv->clock_base,
|
|
|
|
filter->clock_rate, GST_SECOND);
|
|
|
|
|
|
|
|
/* account for lost packets */
|
2015-05-05 11:14:12 +00:00
|
|
|
if (position > gap) {
|
|
|
|
GST_DEBUG_OBJECT (filter,
|
|
|
|
"Found gap of %" GST_TIME_FORMAT ", adjusting start: %"
|
|
|
|
GST_TIME_FORMAT " = %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (gap), GST_TIME_ARGS (position - gap),
|
|
|
|
GST_TIME_ARGS (position), GST_TIME_ARGS (gap));
|
2015-03-27 20:22:36 +00:00
|
|
|
start = position - gap;
|
2015-05-05 11:14:12 +00:00
|
|
|
}
|
2015-03-27 20:22:36 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 11:14:12 +00:00
|
|
|
/* determining the stop of the segment */
|
2015-03-27 20:22:36 +00:00
|
|
|
stop = -1;
|
2008-11-11 16:40:50 +00:00
|
|
|
if (priv->npt_stop != -1)
|
2015-03-27 20:22:36 +00:00
|
|
|
stop = start + (priv->npt_stop - priv->npt_start);
|
2008-11-11 16:40:50 +00:00
|
|
|
|
2015-03-25 22:40:25 +00:00
|
|
|
if (position == -1)
|
|
|
|
position = 0;
|
|
|
|
|
|
|
|
running_time = gst_segment_to_running_time (&filter->segment,
|
2015-03-27 20:22:36 +00:00
|
|
|
GST_FORMAT_TIME, start);
|
2015-03-25 22:40:25 +00:00
|
|
|
|
2011-05-16 11:48:11 +00:00
|
|
|
gst_segment_init (&segment, GST_FORMAT_TIME);
|
|
|
|
segment.rate = priv->play_speed;
|
|
|
|
segment.applied_rate = priv->play_scale;
|
2015-03-27 20:22:36 +00:00
|
|
|
segment.start = start;
|
2011-05-16 11:48:11 +00:00
|
|
|
segment.stop = stop;
|
|
|
|
segment.time = priv->npt_start;
|
|
|
|
segment.position = position;
|
2015-03-25 22:40:25 +00:00
|
|
|
segment.base = running_time;
|
2011-05-16 11:48:11 +00:00
|
|
|
|
2015-05-05 11:14:12 +00:00
|
|
|
GST_DEBUG_OBJECT (filter, "Creating segment event %" GST_SEGMENT_FORMAT,
|
|
|
|
&segment);
|
2011-05-16 11:48:11 +00:00
|
|
|
event = gst_event_new_segment (&segment);
|
2008-11-11 16:40:50 +00:00
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2010-12-15 11:58:47 +00:00
|
|
|
typedef struct
|
2005-08-10 20:52:37 +00:00
|
|
|
{
|
2011-11-11 11:24:08 +00:00
|
|
|
GstRTPBaseDepayload *depayload;
|
|
|
|
GstRTPBaseDepayloadClass *bclass;
|
2010-12-15 11:58:47 +00:00
|
|
|
} HeaderData;
|
2007-09-04 16:18:48 +00:00
|
|
|
|
2011-03-31 15:47:43 +00:00
|
|
|
static gboolean
|
|
|
|
set_headers (GstBuffer ** buffer, guint idx, HeaderData * data)
|
2010-12-15 11:58:47 +00:00
|
|
|
{
|
2011-11-11 11:24:08 +00:00
|
|
|
GstRTPBaseDepayload *depayload = data->depayload;
|
|
|
|
GstRTPBaseDepayloadPrivate *priv = depayload->priv;
|
2011-11-10 16:18:00 +00:00
|
|
|
GstClockTime pts, dts, duration;
|
2006-09-22 14:13:34 +00:00
|
|
|
|
2011-03-27 11:55:15 +00:00
|
|
|
*buffer = gst_buffer_make_writable (*buffer);
|
2010-04-30 17:37:33 +00:00
|
|
|
|
2011-11-10 16:18:00 +00:00
|
|
|
pts = GST_BUFFER_PTS (*buffer);
|
|
|
|
dts = GST_BUFFER_DTS (*buffer);
|
|
|
|
duration = GST_BUFFER_DURATION (*buffer);
|
|
|
|
|
|
|
|
/* apply last incomming timestamp and duration to outgoing buffer if
|
|
|
|
* not otherwise set. */
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (pts))
|
|
|
|
GST_BUFFER_PTS (*buffer) = priv->pts;
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (dts))
|
|
|
|
GST_BUFFER_DTS (*buffer) = priv->dts;
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (duration))
|
|
|
|
GST_BUFFER_DURATION (*buffer) = priv->duration;
|
2006-09-22 14:13:34 +00:00
|
|
|
|
2010-12-15 11:58:47 +00:00
|
|
|
if (G_UNLIKELY (depayload->priv->discont)) {
|
|
|
|
GST_LOG_OBJECT (depayload, "Marking DISCONT on output buffer");
|
|
|
|
GST_BUFFER_FLAG_SET (*buffer, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
depayload->priv->discont = FALSE;
|
|
|
|
}
|
2006-09-22 14:13:34 +00:00
|
|
|
|
2011-11-10 16:18:00 +00:00
|
|
|
/* make sure we only set the timestamp on the first packet */
|
|
|
|
priv->pts = GST_CLOCK_TIME_NONE;
|
|
|
|
priv->dts = GST_CLOCK_TIME_NONE;
|
|
|
|
priv->duration = GST_CLOCK_TIME_NONE;
|
|
|
|
|
2011-03-31 15:47:43 +00:00
|
|
|
return TRUE;
|
2010-12-15 11:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2011-11-11 11:24:08 +00:00
|
|
|
gst_rtp_base_depayload_prepare_push (GstRTPBaseDepayload * filter,
|
2011-11-10 16:18:00 +00:00
|
|
|
gboolean is_list, gpointer obj)
|
2010-12-15 11:58:47 +00:00
|
|
|
{
|
|
|
|
HeaderData data;
|
|
|
|
|
|
|
|
data.depayload = filter;
|
2011-11-11 11:24:08 +00:00
|
|
|
data.bclass = GST_RTP_BASE_DEPAYLOAD_GET_CLASS (filter);
|
2010-12-15 11:58:47 +00:00
|
|
|
|
|
|
|
if (is_list) {
|
2010-12-28 10:41:49 +00:00
|
|
|
GstBufferList **blist = obj;
|
|
|
|
gst_buffer_list_foreach (*blist, (GstBufferListFunc) set_headers, &data);
|
2010-12-15 11:58:47 +00:00
|
|
|
} else {
|
2010-12-28 10:41:49 +00:00
|
|
|
GstBuffer **buf = obj;
|
2011-03-31 15:47:43 +00:00
|
|
|
set_headers (buf, 0, &data);
|
2010-12-15 11:58:47 +00:00
|
|
|
}
|
2006-09-22 14:13:34 +00:00
|
|
|
|
2008-11-11 16:40:50 +00:00
|
|
|
/* if this is the first buffer send a NEWSEGMENT */
|
2015-03-27 20:22:36 +00:00
|
|
|
if (G_UNLIKELY (filter->priv->segment_event)) {
|
|
|
|
gst_pad_push_event (filter->srcpad, filter->priv->segment_event);
|
|
|
|
filter->priv->segment_event = NULL;
|
2008-11-11 16:40:50 +00:00
|
|
|
GST_DEBUG_OBJECT (filter, "Pushed newsegment event on this first buffer");
|
|
|
|
}
|
|
|
|
|
2010-12-15 11:58:47 +00:00
|
|
|
return GST_FLOW_OK;
|
2006-09-22 14:13:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-11-11 11:24:08 +00:00
|
|
|
* gst_rtp_base_depayload_push:
|
|
|
|
* @filter: a #GstRTPBaseDepayload
|
2006-09-22 14:13:34 +00:00
|
|
|
* @out_buf: a #GstBuffer
|
|
|
|
*
|
|
|
|
* Push @out_buf to the peer of @filter. This function takes ownership of
|
|
|
|
* @out_buf.
|
|
|
|
*
|
2011-11-10 16:18:00 +00:00
|
|
|
* This function will by default apply the last incomming timestamp on
|
|
|
|
* the outgoing buffer when it didn't have a timestamp already.
|
2006-09-22 14:13:34 +00:00
|
|
|
*
|
2007-03-29 16:23:53 +00:00
|
|
|
* Returns: a #GstFlowReturn.
|
2006-09-22 14:13:34 +00:00
|
|
|
*/
|
|
|
|
GstFlowReturn
|
2011-11-11 11:24:08 +00:00
|
|
|
gst_rtp_base_depayload_push (GstRTPBaseDepayload * filter, GstBuffer * out_buf)
|
2006-09-22 14:13:34 +00:00
|
|
|
{
|
2010-12-15 11:58:47 +00:00
|
|
|
GstFlowReturn res;
|
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
res = gst_rtp_base_depayload_prepare_push (filter, FALSE, &out_buf);
|
2010-12-15 11:58:47 +00:00
|
|
|
|
|
|
|
if (G_LIKELY (res == GST_FLOW_OK))
|
|
|
|
res = gst_pad_push (filter->srcpad, out_buf);
|
|
|
|
else
|
|
|
|
gst_buffer_unref (out_buf);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-11-11 11:24:08 +00:00
|
|
|
* gst_rtp_base_depayload_push_list:
|
|
|
|
* @filter: a #GstRTPBaseDepayload
|
2010-12-15 11:58:47 +00:00
|
|
|
* @out_list: a #GstBufferList
|
|
|
|
*
|
|
|
|
* Push @out_list to the peer of @filter. This function takes ownership of
|
|
|
|
* @out_list.
|
|
|
|
*
|
|
|
|
* Returns: a #GstFlowReturn.
|
|
|
|
*/
|
|
|
|
GstFlowReturn
|
2011-11-11 11:24:08 +00:00
|
|
|
gst_rtp_base_depayload_push_list (GstRTPBaseDepayload * filter,
|
2010-12-15 11:58:47 +00:00
|
|
|
GstBufferList * out_list)
|
|
|
|
{
|
|
|
|
GstFlowReturn res;
|
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
res = gst_rtp_base_depayload_prepare_push (filter, TRUE, &out_list);
|
2010-12-15 11:58:47 +00:00
|
|
|
|
|
|
|
if (G_LIKELY (res == GST_FLOW_OK))
|
|
|
|
res = gst_pad_push_list (filter->srcpad, out_list);
|
|
|
|
else
|
|
|
|
gst_buffer_list_unref (out_list);
|
|
|
|
|
|
|
|
return res;
|
2006-09-22 14:13:34 +00:00
|
|
|
}
|
|
|
|
|
2014-01-30 23:06:30 +00:00
|
|
|
/* convert the PacketLost event from a jitterbuffer to a GAP event.
|
2008-05-02 12:11:07 +00:00
|
|
|
* subclasses can override this. */
|
|
|
|
static gboolean
|
2011-11-11 11:24:08 +00:00
|
|
|
gst_rtp_base_depayload_packet_lost (GstRTPBaseDepayload * filter,
|
2008-05-02 12:11:07 +00:00
|
|
|
GstEvent * event)
|
|
|
|
{
|
2012-10-29 20:29:36 +00:00
|
|
|
GstClockTime timestamp, duration;
|
2008-05-02 12:11:07 +00:00
|
|
|
GstEvent *sevent;
|
|
|
|
const GstStructure *s;
|
|
|
|
|
|
|
|
s = gst_event_get_structure (event);
|
|
|
|
|
|
|
|
/* first start by parsing the timestamp and duration */
|
|
|
|
timestamp = -1;
|
|
|
|
duration = -1;
|
|
|
|
|
|
|
|
gst_structure_get_clock_time (s, "timestamp", ×tamp);
|
|
|
|
gst_structure_get_clock_time (s, "duration", &duration);
|
|
|
|
|
2012-09-05 10:00:50 +00:00
|
|
|
/* send GAP event */
|
|
|
|
sevent = gst_event_new_gap (timestamp, duration);
|
2008-05-02 12:11:07 +00:00
|
|
|
|
|
|
|
return gst_pad_push_event (filter->srcpad, sevent);
|
|
|
|
}
|
|
|
|
|
2005-09-02 15:43:18 +00:00
|
|
|
static GstStateChangeReturn
|
2011-11-11 11:24:08 +00:00
|
|
|
gst_rtp_base_depayload_change_state (GstElement * element,
|
2005-09-02 15:43:18 +00:00
|
|
|
GstStateChange transition)
|
2005-08-12 13:34:56 +00:00
|
|
|
{
|
2011-11-11 11:24:08 +00:00
|
|
|
GstRTPBaseDepayload *filter;
|
|
|
|
GstRTPBaseDepayloadPrivate *priv;
|
2006-10-06 13:34:46 +00:00
|
|
|
GstStateChangeReturn ret;
|
2005-08-12 13:34:56 +00:00
|
|
|
|
2011-11-11 11:24:08 +00:00
|
|
|
filter = GST_RTP_BASE_DEPAYLOAD (element);
|
2007-09-16 19:31:06 +00:00
|
|
|
priv = filter->priv;
|
2005-08-12 13:34:56 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2005-08-12 13:34:56 +00:00
|
|
|
break;
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2007-03-29 16:23:53 +00:00
|
|
|
filter->need_newsegment = TRUE;
|
2007-09-16 19:31:06 +00:00
|
|
|
priv->npt_start = 0;
|
|
|
|
priv->npt_stop = -1;
|
|
|
|
priv->play_speed = 1.0;
|
|
|
|
priv->play_scale = 1.0;
|
2015-03-27 20:22:36 +00:00
|
|
|
priv->clock_base = -1;
|
2008-10-13 09:16:59 +00:00
|
|
|
priv->next_seqnum = -1;
|
|
|
|
priv->negotiated = FALSE;
|
2010-08-18 10:34:07 +00:00
|
|
|
priv->discont = FALSE;
|
2015-03-27 20:22:36 +00:00
|
|
|
gst_event_replace (&filter->priv->segment_event, NULL);
|
2005-08-12 13:34:56 +00:00
|
|
|
break;
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
2005-08-12 13:34:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-10-06 13:34:46 +00:00
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
2005-08-12 13:34:56 +00:00
|
|
|
switch (transition) {
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
2005-08-12 13:34:56 +00:00
|
|
|
break;
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2013-04-10 19:45:37 +00:00
|
|
|
gst_caps_replace (&priv->last_caps, NULL);
|
2005-08-12 13:34:56 +00:00
|
|
|
break;
|
2005-09-02 15:43:18 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2005-08-12 13:34:56 +00:00
|
|
|
break;
|
2005-09-02 15:43:18 +00:00
|
|
|
default:
|
|
|
|
break;
|
2005-08-12 13:34:56 +00:00
|
|
|
}
|
2006-10-06 13:34:46 +00:00
|
|
|
return ret;
|
2005-08-12 13:34:56 +00:00
|
|
|
}
|
|
|
|
|
2014-04-12 05:10:36 +00:00
|
|
|
static GstStructure *
|
|
|
|
gst_rtp_base_depayload_create_stats (GstRTPBaseDepayload * depayload)
|
|
|
|
{
|
|
|
|
GstRTPBaseDepayloadPrivate *priv;
|
|
|
|
GstStructure *s;
|
|
|
|
|
|
|
|
priv = depayload->priv;
|
|
|
|
|
|
|
|
s = gst_structure_new ("application/x-rtp-depayload-stats",
|
|
|
|
"clock_rate", G_TYPE_UINT, depayload->clock_rate,
|
|
|
|
"npt-start", G_TYPE_UINT64, priv->npt_start,
|
|
|
|
"npt-stop", G_TYPE_UINT64, priv->npt_stop,
|
|
|
|
"play-speed", G_TYPE_DOUBLE, priv->play_speed,
|
|
|
|
"play-scale", G_TYPE_DOUBLE, priv->play_scale,
|
|
|
|
"running-time-dts", G_TYPE_UINT64, priv->dts,
|
|
|
|
"running-time-pts", G_TYPE_UINT64, priv->pts,
|
|
|
|
"seqnum", G_TYPE_UINT, (guint) priv->last_seqnum,
|
|
|
|
"timestamp", G_TYPE_UINT, (guint) priv->last_rtptime, NULL);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-14 10:29:30 +00:00
|
|
|
static void
|
2011-11-11 11:24:08 +00:00
|
|
|
gst_rtp_base_depayload_set_property (GObject * object, guint prop_id,
|
2005-07-14 10:29:30 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-11 11:24:08 +00:00
|
|
|
gst_rtp_base_depayload_get_property (GObject * object, guint prop_id,
|
2005-07-14 10:29:30 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2014-04-12 05:10:36 +00:00
|
|
|
GstRTPBaseDepayload *depayload;
|
|
|
|
|
|
|
|
depayload = GST_RTP_BASE_DEPAYLOAD (object);
|
|
|
|
|
2005-07-14 10:29:30 +00:00
|
|
|
switch (prop_id) {
|
2014-04-12 05:10:36 +00:00
|
|
|
case PROP_STATS:
|
|
|
|
g_value_take_boxed (value,
|
|
|
|
gst_rtp_base_depayload_create_stats (depayload));
|
|
|
|
break;
|
2005-07-14 10:29:30 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|