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
|
2017-01-23 19:36:11 +00:00
|
|
|
* @title: GstRTPBaseDepayload
|
2007-04-21 15:10:25 +00:00
|
|
|
* @short_description: Base class for RTP depayloader
|
|
|
|
*
|
|
|
|
* Provides a base class for RTP depayloaders
|
|
|
|
*/
|
2018-04-28 13:50:11 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2007-04-21 15:10:25 +00:00
|
|
|
|
2011-11-11 11:32:23 +00:00
|
|
|
#include "gstrtpbasedepayload.h"
|
2018-10-10 18:16:12 +00:00
|
|
|
#include "gstrtpmeta.h"
|
2020-07-10 05:30:57 +00:00
|
|
|
#include "gstrtphdrext.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
|
|
|
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;
|
2019-07-12 14:56:52 +00:00
|
|
|
gboolean onvif_mode;
|
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
|
|
|
|
2016-04-02 08:37:55 +00:00
|
|
|
guint32 last_ssrc;
|
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;
|
2019-06-13 08:36:05 +00:00
|
|
|
gint max_reorder;
|
2021-01-26 08:37:44 +00:00
|
|
|
gboolean auto_hdr_ext;
|
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;
|
2018-06-05 15:24:55 +00:00
|
|
|
guint32 segment_seqnum; /* Note: this is a GstEvent seqnum */
|
2018-10-10 18:16:12 +00:00
|
|
|
|
|
|
|
gboolean source_info;
|
|
|
|
GstBuffer *input_buffer;
|
2019-11-22 02:04:14 +00:00
|
|
|
|
|
|
|
GstFlowReturn process_flow_ret;
|
2020-07-10 05:30:57 +00:00
|
|
|
|
|
|
|
/* array of GstRTPHeaderExtension's * */
|
|
|
|
GPtrArray *header_exts;
|
2007-03-29 16:23:53 +00:00
|
|
|
};
|
|
|
|
|
2005-07-14 10:29:30 +00:00
|
|
|
/* Filter signals and args */
|
|
|
|
enum
|
|
|
|
{
|
2020-07-10 05:30:57 +00:00
|
|
|
SIGNAL_0,
|
|
|
|
SIGNAL_REQUEST_EXTENSION,
|
|
|
|
SIGNAL_ADD_EXTENSION,
|
|
|
|
SIGNAL_CLEAR_EXTENSIONS,
|
2005-07-14 10:29:30 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2020-07-10 05:30:57 +00:00
|
|
|
static guint gst_rtp_base_depayload_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2018-10-10 18:16:12 +00:00
|
|
|
#define DEFAULT_SOURCE_INFO FALSE
|
2019-06-13 08:36:05 +00:00
|
|
|
#define DEFAULT_MAX_REORDER 100
|
2021-01-26 08:37:44 +00:00
|
|
|
#define DEFAULT_AUTO_HEADER_EXTENSION TRUE
|
2018-10-10 18:16:12 +00:00
|
|
|
|
2005-07-14 10:29:30 +00:00
|
|
|
enum
|
|
|
|
{
|
2007-03-29 16:23:53 +00:00
|
|
|
PROP_0,
|
2014-04-12 05:10:36 +00:00
|
|
|
PROP_STATS,
|
2018-10-10 18:16:12 +00:00
|
|
|
PROP_SOURCE_INFO,
|
2019-06-13 08:36:05 +00:00
|
|
|
PROP_MAX_REORDER,
|
2021-01-26 08:37:44 +00:00
|
|
|
PROP_AUTO_HEADER_EXTENSION,
|
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;
|
2018-06-23 19:33:16 +00:00
|
|
|
static gint private_offset = 0;
|
|
|
|
|
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
|
|
|
|
2020-07-10 05:30:57 +00:00
|
|
|
static void gst_rtp_base_depayload_add_extension (GstRTPBaseDepayload *
|
|
|
|
rtpbasepayload, GstRTPHeaderExtension * ext);
|
|
|
|
static void gst_rtp_base_depayload_clear_extensions (GstRTPBaseDepayload *
|
|
|
|
rtpbasepayload);
|
|
|
|
|
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
|
|
|
};
|
2018-06-23 19:33:16 +00:00
|
|
|
GType _type;
|
|
|
|
|
|
|
|
_type = g_type_register_static (GST_TYPE_ELEMENT, "GstRTPBaseDepayload",
|
|
|
|
&rtp_base_depayload_info, G_TYPE_FLAG_ABSTRACT);
|
|
|
|
|
|
|
|
private_offset =
|
|
|
|
g_type_add_instance_private (_type,
|
|
|
|
sizeof (GstRTPBaseDepayloadPrivate));
|
2011-04-18 16:29:35 +00:00
|
|
|
|
2018-06-23 19:33:16 +00:00
|
|
|
g_once_init_leave ((gsize *) & rtp_base_depayload_type, _type);
|
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
|
|
|
}
|
|
|
|
|
2018-06-23 19:33:16 +00:00
|
|
|
static inline GstRTPBaseDepayloadPrivate *
|
|
|
|
gst_rtp_base_depayload_get_instance_private (GstRTPBaseDepayload * self)
|
|
|
|
{
|
|
|
|
return (G_STRUCT_MEMBER_P (self, private_offset));
|
|
|
|
}
|
|
|
|
|
2021-01-26 08:37:44 +00:00
|
|
|
static GstRTPHeaderExtension *
|
|
|
|
gst_rtp_base_depayload_request_extension_default (GstRTPBaseDepayload *
|
|
|
|
depayload, guint ext_id, const gchar * uri)
|
|
|
|
{
|
|
|
|
GstRTPHeaderExtension *ext = NULL;
|
|
|
|
|
|
|
|
if (!depayload->priv->auto_hdr_ext)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ext = gst_rtp_header_extension_create_from_uri (uri);
|
|
|
|
if (ext) {
|
|
|
|
GST_DEBUG_OBJECT (depayload,
|
|
|
|
"Automatically enabled extension %s for uri \'%s\'",
|
|
|
|
GST_ELEMENT_NAME (ext), uri);
|
|
|
|
|
|
|
|
gst_rtp_header_extension_set_id (ext, ext_id);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (depayload,
|
|
|
|
"Didn't find any extension implementing uri \'%s\'", uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
extension_accumulator (GSignalInvocationHint * ihint,
|
|
|
|
GValue * return_accu, const GValue * handler_return, gpointer data)
|
|
|
|
{
|
|
|
|
gpointer ext;
|
|
|
|
|
|
|
|
/* Call default handler if user callback didn't create the extension */
|
|
|
|
ext = g_value_get_object (handler_return);
|
|
|
|
if (!ext)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
g_value_set_object (return_accu, ext);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-06-23 19:33:16 +00:00
|
|
|
if (private_offset != 0)
|
|
|
|
g_type_class_adjust_private_offset (klass, &private_offset);
|
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:
|
|
|
|
*
|
2017-01-23 19:36:11 +00:00
|
|
|
* * `clock-rate`: #G_TYPE_UINT, clock-rate of the stream
|
|
|
|
* * `npt-start`: #G_TYPE_UINT64, time of playback start
|
|
|
|
* * `npt-stop`: #G_TYPE_UINT64, time of playback stop
|
|
|
|
* * `play-speed`: #G_TYPE_DOUBLE, the playback speed
|
|
|
|
* * `play-scale`: #G_TYPE_DOUBLE, the playback scale
|
|
|
|
* * `running-time-dts`: #G_TYPE_UINT64, the last running-time of the
|
2014-04-12 05:10:36 +00:00
|
|
|
* last DTS
|
2017-01-23 19:36:11 +00:00
|
|
|
* * `running-time-pts`: #G_TYPE_UINT64, the last running-time of the
|
2014-04-12 05:10:36 +00:00
|
|
|
* last PTS
|
2017-01-23 19:36:11 +00:00
|
|
|
* * `seqnum`: #G_TYPE_UINT, the last seen seqnum
|
|
|
|
* * `timestamp`: #G_TYPE_UINT, the last seen RTP timestamp
|
2014-04-12 05:10:36 +00:00
|
|
|
**/
|
|
|
|
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));
|
|
|
|
|
2018-10-10 18:16:12 +00:00
|
|
|
/**
|
|
|
|
* GstRTPBaseDepayload:source-info:
|
|
|
|
*
|
|
|
|
* Add RTP source information found in RTP header as meta to output buffer.
|
|
|
|
*
|
|
|
|
* Since: 1.16
|
|
|
|
**/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SOURCE_INFO,
|
|
|
|
g_param_spec_boolean ("source-info", "RTP source information",
|
|
|
|
"Add RTP source information as buffer meta",
|
|
|
|
DEFAULT_SOURCE_INFO, G_PARAM_READWRITE));
|
|
|
|
|
2019-06-13 08:36:05 +00:00
|
|
|
/**
|
|
|
|
* GstRTPBaseDepayload:max-reorder:
|
|
|
|
*
|
|
|
|
* Max seqnum reorder before the sender is assumed to have restarted.
|
|
|
|
*
|
|
|
|
* When max-reorder is set to 0 all reordered/duplicate packets are
|
|
|
|
* considered coming from a restarted sender.
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
**/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_MAX_REORDER,
|
|
|
|
g_param_spec_int ("max-reorder", "Max Reorder",
|
|
|
|
"Max seqnum reorder before assuming sender has restarted",
|
|
|
|
0, G_MAXINT, DEFAULT_MAX_REORDER, G_PARAM_READWRITE));
|
|
|
|
|
2021-01-26 08:37:44 +00:00
|
|
|
/**
|
|
|
|
* GstRTPBaseDepayload:auto-header-extension:
|
|
|
|
*
|
|
|
|
* If enabled, the depayloader will automatically try to enable all the
|
|
|
|
* RTP header extensions provided in the sink caps, saving the application
|
|
|
|
* the need to handle these extensions manually using the
|
|
|
|
* GstRTPBaseDepayload::request-extension: signal.
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass),
|
|
|
|
PROP_AUTO_HEADER_EXTENSION, g_param_spec_boolean ("auto-header-extension",
|
|
|
|
"Automatic RTP header extension",
|
|
|
|
"Whether RTP header extensions should be automatically enabled, if an implementation is available",
|
|
|
|
DEFAULT_AUTO_HEADER_EXTENSION,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2020-07-10 05:30:57 +00:00
|
|
|
/**
|
|
|
|
* GstRTPBaseDepayload::request-extension:
|
|
|
|
* @object: the #GstRTPBaseDepayload
|
|
|
|
* @ext_id: the extension id being requested
|
|
|
|
* @ext_uri: (nullable): the extension URI being requested
|
|
|
|
*
|
|
|
|
* The returned @ext must be configured with the correct @ext_id and with the
|
|
|
|
* necessary attributes as required by the extension implementation.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the #GstRTPHeaderExtension for @ext_id, or %NULL
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
|
|
|
gst_rtp_base_depayload_signals[SIGNAL_REQUEST_EXTENSION] =
|
|
|
|
g_signal_new_class_handler ("request-extension",
|
2021-01-26 08:37:44 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
|
|
|
|
G_CALLBACK (gst_rtp_base_depayload_request_extension_default),
|
|
|
|
extension_accumulator, NULL, NULL,
|
2020-07-10 05:30:57 +00:00
|
|
|
GST_TYPE_RTP_HEADER_EXTENSION, 2, G_TYPE_UINT, G_TYPE_STRING);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstRTPBaseDepayload::add-extension:
|
|
|
|
* @object: the #GstRTPBaseDepayload
|
|
|
|
* @ext: (transfer full): the #GstRTPHeaderExtension
|
|
|
|
*
|
|
|
|
* Add @ext as an extension for reading part of an RTP header extension from
|
|
|
|
* incoming RTP packets.
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
|
|
|
gst_rtp_base_depayload_signals[SIGNAL_ADD_EXTENSION] =
|
|
|
|
g_signal_new_class_handler ("add-extension", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
G_CALLBACK (gst_rtp_base_depayload_add_extension), NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 1, GST_TYPE_RTP_HEADER_EXTENSION);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstRTPBaseDepayload::clear-extensions:
|
|
|
|
* @object: the #GstRTPBaseDepayload
|
|
|
|
*
|
|
|
|
* Clear all RTP header extensions used by this depayloader.
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
2021-01-25 13:25:45 +00:00
|
|
|
gst_rtp_base_depayload_signals[SIGNAL_CLEAR_EXTENSIONS] =
|
2020-07-10 05:30:57 +00:00
|
|
|
g_signal_new_class_handler ("clear-extensions", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
G_CALLBACK (gst_rtp_base_depayload_clear_extensions), NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
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
|
|
|
|
2018-06-23 19:33:16 +00:00
|
|
|
priv = gst_rtp_base_depayload_get_instance_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;
|
2019-07-12 14:56:52 +00:00
|
|
|
priv->onvif_mode = FALSE;
|
2014-04-12 05:10:36 +00:00
|
|
|
priv->dts = -1;
|
|
|
|
priv->pts = -1;
|
|
|
|
priv->duration = -1;
|
2018-10-10 18:16:12 +00:00
|
|
|
priv->source_info = DEFAULT_SOURCE_INFO;
|
2019-06-13 08:36:05 +00:00
|
|
|
priv->max_reorder = DEFAULT_MAX_REORDER;
|
2021-01-26 08:37:44 +00:00
|
|
|
priv->auto_hdr_ext = DEFAULT_AUTO_HEADER_EXTENSION;
|
2014-04-12 05:10:36 +00:00
|
|
|
|
2007-09-16 19:31:06 +00:00
|
|
|
gst_segment_init (&filter->segment, GST_FORMAT_UNDEFINED);
|
2020-07-10 05:30:57 +00:00
|
|
|
|
|
|
|
priv->header_exts =
|
|
|
|
g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
|
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
|
|
|
{
|
2020-07-10 05:30:57 +00:00
|
|
|
GstRTPBaseDepayload *rtpbasedepayload = GST_RTP_BASE_DEPAYLOAD (object);
|
|
|
|
|
|
|
|
g_ptr_array_unref (rtpbasedepayload->priv->header_exts);
|
|
|
|
rtpbasedepayload->priv->header_exts = NULL;
|
|
|
|
|
2006-09-22 14:13:34 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2005-07-14 10:29:30 +00:00
|
|
|
}
|
|
|
|
|
2020-07-10 05:30:57 +00:00
|
|
|
static void
|
|
|
|
add_and_ref_item (GstRTPHeaderExtension * ext, GPtrArray * ret)
|
|
|
|
{
|
|
|
|
g_ptr_array_add (ret, gst_object_ref (ext));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_item_from (GstRTPHeaderExtension * ext, GPtrArray * ret)
|
|
|
|
{
|
|
|
|
g_ptr_array_remove_fast (ret, ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_item_to (GstRTPHeaderExtension * ext, GPtrArray * ret)
|
|
|
|
{
|
|
|
|
g_ptr_array_add (ret, ext);
|
|
|
|
}
|
|
|
|
|
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;
|
2020-07-10 05:30:57 +00:00
|
|
|
gboolean res = TRUE;
|
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);
|
|
|
|
|
2019-07-12 14:56:52 +00:00
|
|
|
value = gst_structure_get_value (caps_struct, "onvif-mode");
|
|
|
|
if (value && G_VALUE_HOLDS_BOOLEAN (value))
|
|
|
|
priv->onvif_mode = g_value_get_boolean (value);
|
|
|
|
else
|
|
|
|
priv->onvif_mode = FALSE;
|
|
|
|
GST_DEBUG_OBJECT (filter, "Onvif mode: %d", priv->onvif_mode);
|
|
|
|
|
|
|
|
if (priv->onvif_mode)
|
|
|
|
filter->need_newsegment = FALSE;
|
|
|
|
|
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;
|
|
|
|
|
2020-07-10 05:30:57 +00:00
|
|
|
{
|
|
|
|
/* ensure we have header extension implementations for the list in the
|
|
|
|
* caps */
|
|
|
|
guint i, j, n_fields = gst_structure_n_fields (caps_struct);
|
|
|
|
GPtrArray *header_exts = g_ptr_array_new_with_free_func (gst_object_unref);
|
|
|
|
GPtrArray *to_add = g_ptr_array_new ();
|
|
|
|
GPtrArray *to_remove = g_ptr_array_new ();
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (filter);
|
|
|
|
g_ptr_array_foreach (filter->priv->header_exts,
|
|
|
|
(GFunc) add_and_ref_item, header_exts);
|
|
|
|
GST_OBJECT_UNLOCK (filter);
|
|
|
|
|
|
|
|
for (i = 0; i < n_fields; i++) {
|
|
|
|
const gchar *field_name = gst_structure_nth_field_name (caps_struct, i);
|
|
|
|
if (g_str_has_prefix (field_name, "extmap-")) {
|
|
|
|
const GValue *val;
|
|
|
|
const gchar *uri = NULL;
|
|
|
|
gchar *nptr;
|
2021-04-11 22:43:06 +00:00
|
|
|
guint ext_id;
|
2020-07-10 05:30:57 +00:00
|
|
|
GstRTPHeaderExtension *ext = NULL;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
ext_id = g_ascii_strtoull (&field_name[strlen ("extmap-")], &nptr, 10);
|
|
|
|
if (errno != 0 || (ext_id == 0 && field_name == nptr)) {
|
|
|
|
GST_WARNING_OBJECT (filter, "could not parse id from %s", field_name);
|
|
|
|
res = FALSE;
|
|
|
|
goto ext_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = gst_structure_get_value (caps_struct, field_name);
|
|
|
|
if (G_VALUE_HOLDS_STRING (val)) {
|
|
|
|
uri = g_value_get_string (val);
|
|
|
|
} else if (GST_VALUE_HOLDS_ARRAY (val)) {
|
|
|
|
/* the uri is the second value in the array */
|
|
|
|
const GValue *str = gst_value_array_get_value (val, 1);
|
|
|
|
if (G_VALUE_HOLDS_STRING (str)) {
|
|
|
|
uri = g_value_get_string (str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!uri) {
|
|
|
|
GST_WARNING_OBJECT (filter, "could not get extmap uri for "
|
|
|
|
"field %s", field_name);
|
|
|
|
res = FALSE;
|
|
|
|
goto ext_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to find if this extension mapping already exists */
|
|
|
|
for (j = 0; j < header_exts->len; j++) {
|
|
|
|
ext = g_ptr_array_index (header_exts, j);
|
|
|
|
if (gst_rtp_header_extension_get_id (ext) == ext_id) {
|
|
|
|
if (g_strcmp0 (uri, gst_rtp_header_extension_get_uri (ext)) == 0) {
|
|
|
|
/* still matching, we're good, set attributes from caps in case
|
|
|
|
* the caps have changed */
|
|
|
|
if (!gst_rtp_header_extension_set_attributes_from_caps (ext,
|
|
|
|
caps)) {
|
|
|
|
GST_WARNING_OBJECT (filter,
|
|
|
|
"Failed to configure rtp header " "extension %"
|
|
|
|
GST_PTR_FORMAT " attributes from caps %" GST_PTR_FORMAT,
|
|
|
|
ext, caps);
|
|
|
|
res = FALSE;
|
|
|
|
goto ext_out;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else {
|
2021-04-11 22:43:06 +00:00
|
|
|
GST_DEBUG_OBJECT (filter, "extension id %u"
|
2020-07-10 05:30:57 +00:00
|
|
|
"was replaced with a different extension uri "
|
|
|
|
"original:\'%s' vs \'%s\'", ext_id,
|
|
|
|
gst_rtp_header_extension_get_uri (ext), uri);
|
|
|
|
g_ptr_array_add (to_remove, ext);
|
|
|
|
ext = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ext = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if no extension, attempt to request one */
|
|
|
|
if (!ext) {
|
2021-04-11 22:43:06 +00:00
|
|
|
GST_DEBUG_OBJECT (filter, "requesting extension for id %u"
|
|
|
|
" and uri %s", ext_id, uri);
|
2020-07-10 05:30:57 +00:00
|
|
|
g_signal_emit (filter,
|
|
|
|
gst_rtp_base_depayload_signals[SIGNAL_REQUEST_EXTENSION], 0,
|
|
|
|
ext_id, uri, &ext);
|
|
|
|
GST_DEBUG_OBJECT (filter, "request returned extension %p \'%s\' "
|
2021-04-11 22:43:06 +00:00
|
|
|
"for id %u and uri %s", ext,
|
2020-07-10 05:30:57 +00:00
|
|
|
ext ? GST_OBJECT_NAME (ext) : "", ext_id, uri);
|
|
|
|
|
2021-01-26 08:37:44 +00:00
|
|
|
/* We require the caller to set the appropriate extension if it's required */
|
2020-07-10 05:30:57 +00:00
|
|
|
if (ext && gst_rtp_header_extension_get_id (ext) != ext_id) {
|
|
|
|
g_warning ("\'request-extension\' signal provided an rtp header "
|
|
|
|
"extension for uri \'%s\' that does not match the requested "
|
2021-04-11 22:43:06 +00:00
|
|
|
"extension id %u", uri, ext_id);
|
2020-07-10 05:30:57 +00:00
|
|
|
gst_clear_object (&ext);
|
|
|
|
}
|
2021-01-26 09:39:34 +00:00
|
|
|
|
|
|
|
if (ext && !gst_rtp_header_extension_set_attributes_from_caps (ext,
|
|
|
|
caps)) {
|
|
|
|
GST_WARNING_OBJECT (filter,
|
|
|
|
"Failed to configure rtp header " "extension %"
|
|
|
|
GST_PTR_FORMAT " attributes from caps %" GST_PTR_FORMAT,
|
|
|
|
ext, caps);
|
|
|
|
res = FALSE;
|
|
|
|
g_clear_object (&ext);
|
|
|
|
goto ext_out;
|
|
|
|
}
|
2020-07-10 05:30:57 +00:00
|
|
|
|
|
|
|
if (ext)
|
|
|
|
g_ptr_array_add (to_add, ext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: we intentionally don't remove extensions that are not listed
|
|
|
|
* in caps */
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (filter);
|
|
|
|
g_ptr_array_foreach (to_remove, (GFunc) remove_item_from,
|
|
|
|
filter->priv->header_exts);
|
|
|
|
g_ptr_array_foreach (to_add, (GFunc) add_item_to,
|
|
|
|
filter->priv->header_exts);
|
|
|
|
GST_OBJECT_UNLOCK (filter);
|
|
|
|
|
|
|
|
ext_out:
|
|
|
|
g_ptr_array_unref (to_add);
|
|
|
|
g_ptr_array_unref (to_remove);
|
|
|
|
g_ptr_array_unref (header_exts);
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-12-11 10:25:00 +00:00
|
|
|
/* takes ownership of the input buffer */
|
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
|
|
|
{
|
2015-05-27 17:55:20 +00:00
|
|
|
GstBuffer *(*process_rtp_packet_func) (GstRTPBaseDepayload * base,
|
|
|
|
GstRTPBuffer * rtp_buffer);
|
|
|
|
GstBuffer *(*process_func) (GstRTPBaseDepayload * base, GstBuffer * in);
|
2011-11-11 11:24:08 +00:00
|
|
|
GstRTPBaseDepayloadPrivate *priv;
|
2007-08-31 15:58:30 +00:00
|
|
|
GstBuffer *out_buf;
|
2016-04-02 08:37:55 +00:00
|
|
|
guint32 ssrc;
|
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;
|
2019-11-22 02:04:14 +00:00
|
|
|
priv->process_flow_ret = GST_FLOW_OK;
|
2008-10-13 09:16:59 +00:00
|
|
|
|
2015-05-27 17:55:20 +00:00
|
|
|
process_func = bclass->process;
|
|
|
|
process_rtp_packet_func = bclass->process_rtp_packet;
|
|
|
|
|
2008-10-13 09:16:59 +00:00
|
|
|
/* 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
|
|
|
|
2015-08-05 19:32:54 +00:00
|
|
|
priv->pts = GST_BUFFER_PTS (in);
|
|
|
|
priv->dts = GST_BUFFER_DTS (in);
|
2007-09-19 16:09:57 +00:00
|
|
|
priv->duration = GST_BUFFER_DURATION (in);
|
2007-09-16 19:31:06 +00:00
|
|
|
|
2016-04-02 08:37:55 +00:00
|
|
|
ssrc = gst_rtp_buffer_get_ssrc (&rtp);
|
2011-03-27 11:55:15 +00:00
|
|
|
seqnum = gst_rtp_buffer_get_seq (&rtp);
|
|
|
|
rtptime = gst_rtp_buffer_get_timestamp (&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,
|
2015-08-05 19:32:54 +00:00
|
|
|
GST_TIME_ARGS (priv->pts), GST_TIME_ARGS (priv->dts));
|
2008-05-23 14:14:28 +00:00
|
|
|
|
|
|
|
/* Check seqnum. This is a very simple check that makes sure that the seqnums
|
2015-07-07 18:56:52 +00:00
|
|
|
* are strictly increasing, dropping anything that is out of the ordinary. We
|
2008-05-23 14:14:28 +00:00
|
|
|
* 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)) {
|
2016-04-02 08:37:55 +00:00
|
|
|
if (ssrc != priv->last_ssrc) {
|
|
|
|
GST_LOG_OBJECT (filter,
|
|
|
|
"New ssrc %u (current ssrc %u), sender restarted",
|
|
|
|
ssrc, priv->last_ssrc);
|
2016-04-12 13:34:00 +00:00
|
|
|
discont = TRUE;
|
2016-04-02 08:37:55 +00:00
|
|
|
} else {
|
|
|
|
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 {
|
2019-06-13 08:36:05 +00:00
|
|
|
/* seqnum < next_seqnum, we have seen this packet before, have a
|
|
|
|
* reordered packet 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 assuming the sender has restarted. See
|
|
|
|
* also RFC 4737. */
|
2020-05-14 13:49:54 +00:00
|
|
|
if (gap <= priv->max_reorder) {
|
|
|
|
GST_WARNING_OBJECT (filter, "got old packet %u, expected %u, "
|
|
|
|
"gap %d <= max_reorder (%d), dropping!",
|
|
|
|
seqnum, priv->next_seqnum, gap, priv->max_reorder);
|
2016-04-02 08:37:55 +00:00
|
|
|
goto dropping;
|
2020-05-14 13:49:54 +00:00
|
|
|
}
|
|
|
|
GST_WARNING_OBJECT (filter, "got old packet %u, expected %u, "
|
|
|
|
"marking discont", seqnum, priv->next_seqnum);
|
2016-04-02 08:37:55 +00:00
|
|
|
discont = TRUE;
|
|
|
|
}
|
2008-05-23 14:14:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
priv->next_seqnum = (seqnum + 1) & 0xffff;
|
2016-04-02 08:37:55 +00:00
|
|
|
priv->last_ssrc = ssrc;
|
2008-05-23 14:14:28 +00:00
|
|
|
|
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) {
|
2015-12-11 11:01:53 +00:00
|
|
|
gpointer old_inbuf = in;
|
|
|
|
|
2013-08-21 10:34:24 +00:00
|
|
|
/* 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);
|
2015-12-11 11:01:53 +00:00
|
|
|
/* depayloaders will check flag on rtpbuffer->buffer, so if the input
|
|
|
|
* buffer was not writable already we need to remap to make our
|
|
|
|
* newly-flagged buffer current on the rtpbuffer */
|
|
|
|
if (in != old_inbuf) {
|
|
|
|
gst_rtp_buffer_unmap (&rtp);
|
|
|
|
if (G_UNLIKELY (!gst_rtp_buffer_map (in, GST_MAP_READ, &rtp)))
|
|
|
|
goto invalid_buffer;
|
|
|
|
}
|
2013-08-21 10:34:24 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2018-10-10 18:16:12 +00:00
|
|
|
priv->input_buffer = in;
|
|
|
|
|
2015-05-27 17:55:20 +00:00
|
|
|
if (process_rtp_packet_func != NULL) {
|
|
|
|
out_buf = process_rtp_packet_func (filter, &rtp);
|
|
|
|
gst_rtp_buffer_unmap (&rtp);
|
|
|
|
} else if (process_func != NULL) {
|
|
|
|
gst_rtp_buffer_unmap (&rtp);
|
|
|
|
out_buf = process_func (filter, in);
|
|
|
|
} else {
|
2008-05-23 14:14:28 +00:00
|
|
|
goto no_process;
|
2015-05-27 17:55:20 +00:00
|
|
|
}
|
2008-05-23 14:14:28 +00:00
|
|
|
|
2007-08-31 15:58:30 +00:00
|
|
|
/* let's send it out to processing */
|
|
|
|
if (out_buf) {
|
2019-11-22 02:04:14 +00:00
|
|
|
if (priv->process_flow_ret == GST_FLOW_OK)
|
|
|
|
priv->process_flow_ret = gst_rtp_base_depayload_push (filter, out_buf);
|
|
|
|
else
|
|
|
|
gst_buffer_unref (out_buf);
|
2005-07-14 10:29:30 +00:00
|
|
|
}
|
2007-08-31 15:58:30 +00:00
|
|
|
|
2015-12-11 10:25:00 +00:00
|
|
|
gst_buffer_unref (in);
|
2018-10-10 18:16:12 +00:00
|
|
|
priv->input_buffer = NULL;
|
2015-12-11 10:25:00 +00:00
|
|
|
|
2019-11-22 02:04:14 +00:00
|
|
|
return priv->process_flow_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"));
|
2015-12-11 10:25:00 +00:00
|
|
|
gst_buffer_unref (in);
|
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"));
|
2015-12-11 10:25:00 +00:00
|
|
|
gst_buffer_unref (in);
|
2008-05-14 20:28:02 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
2008-05-23 14:14:28 +00:00
|
|
|
dropping:
|
|
|
|
{
|
2015-07-30 11:50:56 +00:00
|
|
|
gst_rtp_buffer_unmap (&rtp);
|
2015-12-11 10:25:00 +00:00
|
|
|
gst_buffer_unref (in);
|
2008-05-23 14:14:28 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
no_process:
|
|
|
|
{
|
2015-07-30 11:50:56 +00:00
|
|
|
gst_rtp_buffer_unmap (&rtp);
|
2008-05-23 14:14:28 +00:00
|
|
|
/* this is not fatal but should be filtered earlier */
|
|
|
|
GST_ELEMENT_ERROR (filter, STREAM, NOT_IMPLEMENTED, (NULL),
|
2015-05-27 17:55:20 +00:00
|
|
|
("The subclass does not have a process or process_rtp_packet method"));
|
2015-12-11 10:25:00 +00:00
|
|
|
gst_buffer_unref (in);
|
2008-05-23 14:14:28 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-12-11 10:25:00 +00:00
|
|
|
/* handle_buffer takes ownership of input buffer */
|
|
|
|
/* FIXME: add a way to steal buffers from list as we will unref it anyway */
|
|
|
|
gst_buffer_ref (buffer);
|
|
|
|
|
2015-05-21 12:59:55 +00:00
|
|
|
/* 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:
|
2015-08-15 13:33:14 +00:00
|
|
|
GST_OBJECT_LOCK (filter);
|
2007-09-16 19:31:06 +00:00
|
|
|
gst_segment_init (&filter->segment, GST_FORMAT_UNDEFINED);
|
2015-08-15 13:33:14 +00:00
|
|
|
GST_OBJECT_UNLOCK (filter);
|
|
|
|
|
2019-07-12 14:56:52 +00:00
|
|
|
filter->need_newsegment = !filter->priv->onvif_mode;
|
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
|
|
|
{
|
2016-05-02 06:48:09 +00:00
|
|
|
GstSegment segment;
|
|
|
|
|
2015-08-15 13:33:14 +00:00
|
|
|
GST_OBJECT_LOCK (filter);
|
2016-05-02 06:48:09 +00:00
|
|
|
gst_event_copy_segment (event, &segment);
|
|
|
|
|
|
|
|
if (segment.format != GST_FORMAT_TIME) {
|
|
|
|
GST_ERROR_OBJECT (filter, "Segment with non-TIME format not supported");
|
|
|
|
res = FALSE;
|
|
|
|
}
|
2018-06-05 15:24:55 +00:00
|
|
|
filter->priv->segment_seqnum = gst_event_get_seqnum (event);
|
2016-05-02 06:48:09 +00:00
|
|
|
filter->segment = segment;
|
2015-08-15 13:33:14 +00:00
|
|
|
GST_OBJECT_UNLOCK (filter);
|
|
|
|
|
2019-07-12 14:56:52 +00:00
|
|
|
/* In ONVIF mode, upstream is expected to send us the correct segment */
|
|
|
|
if (!filter->priv->onvif_mode) {
|
|
|
|
/* don't pass the event downstream, we generate our own segment including
|
|
|
|
* the NTP time and other things we receive in caps */
|
|
|
|
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-08-15 13:33:14 +00:00
|
|
|
/* We don't need the object lock around - the segment
|
|
|
|
* can't change here while we're holding the STREAM_LOCK
|
|
|
|
*/
|
|
|
|
|
2015-05-05 11:14:12 +00:00
|
|
|
/* determining the start of the segment */
|
2015-07-10 16:49:01 +00:00
|
|
|
start = filter->segment.start;
|
2015-03-27 20:22:36 +00:00
|
|
|
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-07-10 16:49:01 +00:00
|
|
|
stop = filter->segment.stop;
|
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)
|
2015-07-10 16:49:01 +00:00
|
|
|
position = start;
|
2015-03-25 22:40:25 +00:00
|
|
|
|
2016-11-01 19:09:04 +00:00
|
|
|
running_time = gst_segment_to_running_time (&filter->segment,
|
|
|
|
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);
|
2018-06-05 15:24:55 +00:00
|
|
|
if (filter->priv->segment_seqnum != GST_SEQNUM_INVALID)
|
|
|
|
gst_event_set_seqnum (event, filter->priv->segment_seqnum);
|
2008-11-11 16:40:50 +00:00
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2019-06-12 12:31:09 +00:00
|
|
|
static gboolean
|
|
|
|
foreach_metadata_drop (GstBuffer * buffer, GstMeta ** meta, gpointer user_data)
|
|
|
|
{
|
|
|
|
GType drop_api_type = (GType) user_data;
|
|
|
|
const GstMetaInfo *info = (*meta)->info;
|
|
|
|
|
|
|
|
if (info->api == drop_api_type)
|
|
|
|
*meta = NULL;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-10-10 18:16:12 +00:00
|
|
|
static void
|
|
|
|
add_rtp_source_meta (GstBuffer * outbuf, GstBuffer * rtpbuf)
|
|
|
|
{
|
|
|
|
GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
|
|
|
|
GstRTPSourceMeta *meta;
|
|
|
|
guint32 ssrc;
|
2019-06-12 12:31:09 +00:00
|
|
|
GType source_meta_api = gst_rtp_source_meta_api_get_type ();
|
2018-10-10 18:16:12 +00:00
|
|
|
|
|
|
|
if (!gst_rtp_buffer_map (rtpbuf, GST_MAP_READ, &rtp))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ssrc = gst_rtp_buffer_get_ssrc (&rtp);
|
2019-06-12 12:31:09 +00:00
|
|
|
|
|
|
|
/* remove any pre-existing source-meta */
|
|
|
|
gst_buffer_foreach_meta (outbuf, foreach_metadata_drop,
|
|
|
|
(gpointer) source_meta_api);
|
|
|
|
|
2018-10-10 18:16:12 +00:00
|
|
|
meta = gst_buffer_add_rtp_source_meta (outbuf, &ssrc, NULL, 0);
|
|
|
|
if (meta != NULL) {
|
|
|
|
gint i;
|
|
|
|
gint csrc_count = gst_rtp_buffer_get_csrc_count (&rtp);
|
|
|
|
for (i = 0; i < csrc_count; i++) {
|
|
|
|
guint32 csrc = gst_rtp_buffer_get_csrc (&rtp, i);
|
|
|
|
gst_rtp_source_meta_append_csrc (meta, &csrc, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_rtp_buffer_unmap (&rtp);
|
|
|
|
}
|
|
|
|
|
2020-07-10 05:30:57 +00:00
|
|
|
static void
|
|
|
|
gst_rtp_base_depayload_add_extension (GstRTPBaseDepayload * rtpbasepayload,
|
|
|
|
GstRTPHeaderExtension * ext)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_RTP_HEADER_EXTENSION (ext));
|
|
|
|
g_return_if_fail (gst_rtp_header_extension_get_id (ext) > 0);
|
|
|
|
|
|
|
|
/* XXX: check for duplicate ids? */
|
|
|
|
GST_OBJECT_LOCK (rtpbasepayload);
|
|
|
|
g_ptr_array_add (rtpbasepayload->priv->header_exts, gst_object_ref (ext));
|
|
|
|
GST_OBJECT_UNLOCK (rtpbasepayload);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_base_depayload_clear_extensions (GstRTPBaseDepayload * rtpbasepayload)
|
|
|
|
{
|
|
|
|
GST_OBJECT_LOCK (rtpbasepayload);
|
|
|
|
g_ptr_array_set_size (rtpbasepayload->priv->header_exts, 0);
|
|
|
|
GST_OBJECT_UNLOCK (rtpbasepayload);
|
|
|
|
}
|
|
|
|
|
2021-02-09 21:09:52 +00:00
|
|
|
static gboolean
|
2020-07-10 05:30:57 +00:00
|
|
|
read_rtp_header_extensions (GstRTPBaseDepayload * depayload,
|
|
|
|
GstBuffer * input, GstBuffer * output)
|
|
|
|
{
|
|
|
|
GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
|
|
|
|
guint16 bit_pattern;
|
|
|
|
guint8 *pdata;
|
|
|
|
guint wordlen;
|
2021-02-09 21:09:52 +00:00
|
|
|
gboolean needs_src_caps_update = FALSE;
|
2020-07-10 05:30:57 +00:00
|
|
|
|
|
|
|
if (!input) {
|
|
|
|
GST_DEBUG_OBJECT (depayload, "no input buffer");
|
2021-02-09 21:09:52 +00:00
|
|
|
return needs_src_caps_update;
|
2020-07-10 05:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_rtp_buffer_map (input, GST_MAP_READ, &rtp)) {
|
|
|
|
GST_WARNING_OBJECT (depayload, "Failed to map buffer");
|
2021-02-09 21:09:52 +00:00
|
|
|
return needs_src_caps_update;
|
2020-07-10 05:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_rtp_buffer_get_extension_data (&rtp, &bit_pattern, (gpointer) & pdata,
|
|
|
|
&wordlen)) {
|
|
|
|
GstRTPHeaderExtensionFlags ext_flags = 0;
|
|
|
|
gsize bytelen = wordlen * 4;
|
|
|
|
guint hdr_unit_bytes;
|
|
|
|
gsize offset = 0;
|
|
|
|
|
|
|
|
if (bit_pattern == 0xBEDE) {
|
|
|
|
/* one byte extensions */
|
|
|
|
hdr_unit_bytes = 1;
|
|
|
|
ext_flags |= GST_RTP_HEADER_EXTENSION_ONE_BYTE;
|
|
|
|
} else if (bit_pattern >> 4 == 0x100) {
|
|
|
|
/* two byte extensions */
|
|
|
|
hdr_unit_bytes = 2;
|
|
|
|
ext_flags |= GST_RTP_HEADER_EXTENSION_TWO_BYTE;
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (depayload, "unknown extension bit pattern 0x%02x%02x",
|
|
|
|
bit_pattern >> 8, bit_pattern & 0xff);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (TRUE) {
|
|
|
|
guint8 read_id, read_len;
|
|
|
|
GstRTPHeaderExtension *ext = NULL;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (offset + hdr_unit_bytes >= bytelen)
|
|
|
|
/* not enough remaning data */
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (ext_flags & GST_RTP_HEADER_EXTENSION_ONE_BYTE) {
|
|
|
|
read_id = GST_READ_UINT8 (pdata + offset) >> 4;
|
|
|
|
read_len = (GST_READ_UINT8 (pdata + offset) & 0x0F) + 1;
|
|
|
|
offset += 1;
|
|
|
|
|
|
|
|
if (read_id == 0)
|
|
|
|
/* padding */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (read_id == 15)
|
|
|
|
/* special id for possible future expansion */
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
read_id = GST_READ_UINT8 (pdata + offset);
|
|
|
|
offset += 1;
|
|
|
|
|
|
|
|
if (read_id == 0)
|
|
|
|
/* padding */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
read_len = GST_READ_UINT8 (pdata + offset);
|
|
|
|
offset += 1;
|
|
|
|
}
|
|
|
|
GST_TRACE_OBJECT (depayload, "found rtp header extension with id %u and "
|
|
|
|
"length %u", read_id, read_len);
|
|
|
|
|
|
|
|
/* Ignore extension headers where the size does not fit */
|
|
|
|
if (offset + read_len > bytelen) {
|
|
|
|
GST_WARNING_OBJECT (depayload, "Extension length extends past the "
|
|
|
|
"size of the extension data");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (depayload);
|
|
|
|
for (i = 0; i < depayload->priv->header_exts->len; i++) {
|
|
|
|
ext = g_ptr_array_index (depayload->priv->header_exts, i);
|
|
|
|
if (read_id == gst_rtp_header_extension_get_id (ext)) {
|
|
|
|
gst_object_ref (ext);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ext = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ext) {
|
|
|
|
if (!gst_rtp_header_extension_read (ext, ext_flags, &pdata[offset],
|
|
|
|
read_len, output)) {
|
|
|
|
GST_WARNING_OBJECT (depayload, "RTP header extension (%s) could "
|
|
|
|
"not read payloaded data", GST_OBJECT_NAME (ext));
|
|
|
|
gst_object_unref (ext);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2021-02-04 16:08:04 +00:00
|
|
|
if (gst_rtp_header_extension_wants_update_non_rtp_src_caps (ext)) {
|
2021-02-09 21:09:52 +00:00
|
|
|
needs_src_caps_update = TRUE;
|
2021-02-04 16:08:04 +00:00
|
|
|
}
|
|
|
|
|
2020-07-10 05:30:57 +00:00
|
|
|
gst_object_unref (ext);
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (depayload);
|
|
|
|
|
|
|
|
offset += read_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
gst_rtp_buffer_unmap (&rtp);
|
2021-02-09 21:09:52 +00:00
|
|
|
|
|
|
|
return needs_src_caps_update;
|
2020-07-10 05:30:57 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 15:47:43 +00:00
|
|
|
static gboolean
|
2021-02-09 21:09:52 +00:00
|
|
|
gst_rtp_base_depayload_set_headers (GstRTPBaseDepayload * depayload,
|
|
|
|
GstBuffer * buffer)
|
2010-12-15 11:58:47 +00:00
|
|
|
{
|
2011-11-11 11:24:08 +00:00
|
|
|
GstRTPBaseDepayloadPrivate *priv = depayload->priv;
|
2011-11-10 16:18:00 +00:00
|
|
|
GstClockTime pts, dts, duration;
|
2006-09-22 14:13:34 +00:00
|
|
|
|
2021-02-09 21:09:52 +00:00
|
|
|
pts = GST_BUFFER_PTS (buffer);
|
|
|
|
dts = GST_BUFFER_DTS (buffer);
|
|
|
|
duration = GST_BUFFER_DURATION (buffer);
|
2011-11-10 16:18:00 +00:00
|
|
|
|
2019-08-29 17:42:39 +00:00
|
|
|
/* apply last incoming timestamp and duration to outgoing buffer if
|
2011-11-10 16:18:00 +00:00
|
|
|
* not otherwise set. */
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (pts))
|
2021-02-09 21:09:52 +00:00
|
|
|
GST_BUFFER_PTS (buffer) = priv->pts;
|
2011-11-10 16:18:00 +00:00
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (dts))
|
2021-02-09 21:09:52 +00:00
|
|
|
GST_BUFFER_DTS (buffer) = priv->dts;
|
2011-11-10 16:18:00 +00:00
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (duration))
|
2021-02-09 21:09:52 +00:00
|
|
|
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");
|
2021-02-09 21:09:52 +00:00
|
|
|
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
|
2010-12-15 11:58:47 +00:00
|
|
|
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;
|
|
|
|
|
2020-07-10 05:30:57 +00:00
|
|
|
if (priv->input_buffer) {
|
|
|
|
if (priv->source_info)
|
2021-02-09 21:09:52 +00:00
|
|
|
add_rtp_source_meta (buffer, priv->input_buffer);
|
2020-07-10 05:30:57 +00:00
|
|
|
|
2021-02-09 21:09:52 +00:00
|
|
|
return read_rtp_header_extensions (depayload, priv->input_buffer, buffer);
|
2020-07-10 05:30:57 +00:00
|
|
|
}
|
2018-10-10 18:16:12 +00:00
|
|
|
|
2021-02-09 21:09:52 +00:00
|
|
|
return FALSE;
|
2010-12-15 11:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2021-02-09 21:09:52 +00:00
|
|
|
gst_rtp_base_depayload_finish_push (GstRTPBaseDepayload * filter,
|
2011-11-10 16:18:00 +00:00
|
|
|
gboolean is_list, gpointer obj)
|
2010-12-15 11:58:47 +00:00
|
|
|
{
|
2021-02-09 21:09:52 +00:00
|
|
|
/* if this is the first buffer send a NEWSEGMENT */
|
|
|
|
if (G_UNLIKELY (filter->priv->segment_event)) {
|
|
|
|
gst_pad_push_event (filter->srcpad, filter->priv->segment_event);
|
|
|
|
filter->priv->segment_event = NULL;
|
|
|
|
GST_DEBUG_OBJECT (filter, "Pushed newsegment event on this first buffer");
|
|
|
|
}
|
|
|
|
|
2010-12-15 11:58:47 +00:00
|
|
|
if (is_list) {
|
2021-02-09 21:09:52 +00:00
|
|
|
GstBufferList *blist = obj;
|
|
|
|
return gst_pad_push_list (filter->srcpad, blist);
|
2010-12-15 11:58:47 +00:00
|
|
|
} else {
|
2021-02-09 21:09:52 +00:00
|
|
|
GstBuffer *buf = obj;
|
|
|
|
return gst_pad_push (filter->srcpad, buf);
|
2010-12-15 11:58:47 +00:00
|
|
|
}
|
2021-02-09 21:09:52 +00:00
|
|
|
}
|
2006-09-22 14:13:34 +00:00
|
|
|
|
2021-02-09 21:09:52 +00:00
|
|
|
static gboolean
|
|
|
|
gst_rtp_base_depayload_set_src_caps_from_hdrext (GstRTPBaseDepayload * filter)
|
|
|
|
{
|
|
|
|
gboolean update_ok = TRUE;
|
|
|
|
GstCaps *src_caps = gst_pad_get_current_caps (filter->srcpad);
|
2021-02-04 16:08:04 +00:00
|
|
|
|
2021-02-09 21:09:52 +00:00
|
|
|
if (src_caps) {
|
|
|
|
GstCaps *new_caps;
|
|
|
|
gint i;
|
2021-02-04 16:08:04 +00:00
|
|
|
|
2021-02-09 21:09:52 +00:00
|
|
|
new_caps = gst_caps_copy (src_caps);
|
|
|
|
for (i = 0; i < filter->priv->header_exts->len; i++) {
|
|
|
|
GstRTPHeaderExtension *ext;
|
2021-02-04 16:08:04 +00:00
|
|
|
|
2021-02-09 21:09:52 +00:00
|
|
|
ext = g_ptr_array_index (filter->priv->header_exts, i);
|
|
|
|
update_ok =
|
|
|
|
gst_rtp_header_extension_update_non_rtp_src_caps (ext, new_caps);
|
2021-02-04 16:08:04 +00:00
|
|
|
|
2021-02-09 21:09:52 +00:00
|
|
|
if (!update_ok) {
|
|
|
|
GST_ELEMENT_ERROR (filter, STREAM, DECODE,
|
|
|
|
("RTP header extension (%s) could not update src caps",
|
|
|
|
GST_OBJECT_NAME (ext)), (NULL));
|
|
|
|
break;
|
2021-02-04 16:08:04 +00:00
|
|
|
}
|
2021-02-09 21:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (G_UNLIKELY (update_ok && !gst_caps_is_equal (src_caps, new_caps))) {
|
|
|
|
gst_pad_set_caps (filter->srcpad, new_caps);
|
|
|
|
}
|
2021-02-04 16:08:04 +00:00
|
|
|
|
2021-02-09 21:09:52 +00:00
|
|
|
gst_caps_unref (src_caps);
|
|
|
|
gst_caps_unref (new_caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
return update_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_rtp_base_depayload_do_push (GstRTPBaseDepayload * filter, gboolean is_list,
|
|
|
|
gpointer obj)
|
|
|
|
{
|
|
|
|
GstFlowReturn res;
|
|
|
|
|
|
|
|
if (is_list) {
|
|
|
|
GstBufferList *blist = obj;
|
|
|
|
guint i;
|
|
|
|
guint first_not_pushed_idx = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < gst_buffer_list_length (blist); ++i) {
|
|
|
|
GstBuffer *buf = gst_buffer_list_get_writable (blist, i);
|
|
|
|
|
|
|
|
if (G_UNLIKELY (gst_rtp_base_depayload_set_headers (filter, buf))) {
|
|
|
|
/* src caps have changed; push the buffers preceding the current one,
|
|
|
|
* then apply the new caps on the src pad */
|
|
|
|
guint j;
|
|
|
|
|
|
|
|
for (j = first_not_pushed_idx; j < i; ++j) {
|
|
|
|
res = gst_rtp_base_depayload_finish_push (filter, FALSE,
|
|
|
|
gst_buffer_ref (gst_buffer_list_get (blist, j)));
|
|
|
|
if (G_UNLIKELY (res != GST_FLOW_OK)) {
|
|
|
|
goto error_list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
first_not_pushed_idx = i;
|
|
|
|
|
|
|
|
if (!gst_rtp_base_depayload_set_src_caps_from_hdrext (filter)) {
|
|
|
|
res = GST_FLOW_ERROR;
|
|
|
|
goto error_list;
|
|
|
|
}
|
2021-02-04 16:08:04 +00:00
|
|
|
}
|
2021-02-09 21:09:52 +00:00
|
|
|
}
|
2021-02-04 16:08:04 +00:00
|
|
|
|
2021-02-09 21:09:52 +00:00
|
|
|
if (G_LIKELY (first_not_pushed_idx == 0)) {
|
|
|
|
res = gst_rtp_base_depayload_finish_push (filter, TRUE, blist);
|
|
|
|
blist = NULL;
|
|
|
|
} else {
|
|
|
|
for (i = first_not_pushed_idx; i < gst_buffer_list_length (blist); ++i) {
|
|
|
|
res = gst_rtp_base_depayload_finish_push (filter, FALSE,
|
|
|
|
gst_buffer_ref (gst_buffer_list_get (blist, i)));
|
|
|
|
if (G_UNLIKELY (res != GST_FLOW_OK)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-04 16:08:04 +00:00
|
|
|
|
2021-02-09 21:09:52 +00:00
|
|
|
error_list:
|
|
|
|
gst_clear_buffer_list (&blist);
|
|
|
|
} else {
|
|
|
|
GstBuffer *buf = obj;
|
|
|
|
if (G_UNLIKELY (gst_rtp_base_depayload_set_headers (filter, buf))) {
|
|
|
|
if (!gst_rtp_base_depayload_set_src_caps_from_hdrext (filter)) {
|
|
|
|
res = GST_FLOW_ERROR;
|
|
|
|
goto error_buffer;
|
2021-02-04 16:08:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-09 21:09:52 +00:00
|
|
|
res = gst_rtp_base_depayload_finish_push (filter, FALSE, buf);
|
|
|
|
buf = NULL;
|
2021-02-04 16:08:04 +00:00
|
|
|
|
2021-02-09 21:09:52 +00:00
|
|
|
error_buffer:
|
|
|
|
gst_clear_buffer (&buf);
|
2008-11-11 16:40:50 +00:00
|
|
|
}
|
|
|
|
|
2021-02-09 21:09:52 +00:00
|
|
|
return res;
|
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.
|
|
|
|
*
|
2019-08-29 17:42:39 +00:00
|
|
|
* This function will by default apply the last incoming timestamp on
|
2011-11-10 16:18:00 +00:00
|
|
|
* 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;
|
|
|
|
|
2021-02-09 21:09:52 +00:00
|
|
|
res = gst_rtp_base_depayload_do_push (filter, FALSE, out_buf);
|
2010-12-15 11:58:47 +00:00
|
|
|
|
2019-11-22 02:04:14 +00:00
|
|
|
if (res != GST_FLOW_OK)
|
|
|
|
filter->priv->process_flow_ret = res;
|
|
|
|
|
2010-12-15 11:58:47 +00:00
|
|
|
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;
|
|
|
|
|
2021-02-09 21:09:52 +00:00
|
|
|
res = gst_rtp_base_depayload_do_push (filter, TRUE, out_list);
|
2010-12-15 11:58:47 +00:00
|
|
|
|
2019-11-22 02:04:14 +00:00
|
|
|
if (res != GST_FLOW_OK)
|
|
|
|
filter->priv->process_flow_ret = res;
|
|
|
|
|
2010-12-15 11:58:47 +00:00
|
|
|
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;
|
rtpbasedepayload: condition the sending of gap events
The default implementation for packet loss handling previously
always sent a gap event.
While this is correct as long as we know the packet that was
lost was actually a media packet, with ULPFEC this becomes
a bit more complicated, as we do not know whether the packet
that was lost was a FEC packet, in which case it is better
to not actually send any gap events in the default implementation.
Some payloaders can be more clever about, for example VP8 can
use the picture-id, and the M and S bits to determine whether
the missing packet was inside an encoded frame or outside,
and thus whether if it was a media packet or a FEC packet,
which is why ulpfecdec still lets these lost events go through,
though stripping them of their seqnum, and appending a new
"might-have-been-fec" field to them.
This is all a bit terrible, but necessary to have ULPFEC
integrate properly with the rest of our RTP stack.
https://bugzilla.gnome.org/show_bug.cgi?id=794909
2018-04-06 18:02:13 +00:00
|
|
|
gboolean might_have_been_fec;
|
|
|
|
gboolean res = TRUE;
|
2008-05-02 12:11:07 +00:00
|
|
|
|
|
|
|
s = gst_event_get_structure (event);
|
|
|
|
|
|
|
|
/* first start by parsing the timestamp and duration */
|
|
|
|
timestamp = -1;
|
|
|
|
duration = -1;
|
|
|
|
|
2015-12-14 12:11:21 +00:00
|
|
|
if (!gst_structure_get_clock_time (s, "timestamp", ×tamp) ||
|
|
|
|
!gst_structure_get_clock_time (s, "duration", &duration)) {
|
|
|
|
GST_ERROR_OBJECT (filter,
|
|
|
|
"Packet loss event without timestamp or duration");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-05-02 12:11:07 +00:00
|
|
|
|
2016-08-30 11:48:00 +00:00
|
|
|
sevent = gst_pad_get_sticky_event (filter->srcpad, GST_EVENT_SEGMENT, 0);
|
|
|
|
if (G_UNLIKELY (!sevent)) {
|
|
|
|
/* Typically happens if lost event arrives before first buffer */
|
|
|
|
GST_DEBUG_OBJECT (filter,
|
|
|
|
"Ignore packet loss because segment event missing");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
gst_event_unref (sevent);
|
|
|
|
|
rtpbasedepayload: condition the sending of gap events
The default implementation for packet loss handling previously
always sent a gap event.
While this is correct as long as we know the packet that was
lost was actually a media packet, with ULPFEC this becomes
a bit more complicated, as we do not know whether the packet
that was lost was a FEC packet, in which case it is better
to not actually send any gap events in the default implementation.
Some payloaders can be more clever about, for example VP8 can
use the picture-id, and the M and S bits to determine whether
the missing packet was inside an encoded frame or outside,
and thus whether if it was a media packet or a FEC packet,
which is why ulpfecdec still lets these lost events go through,
though stripping them of their seqnum, and appending a new
"might-have-been-fec" field to them.
This is all a bit terrible, but necessary to have ULPFEC
integrate properly with the rest of our RTP stack.
https://bugzilla.gnome.org/show_bug.cgi?id=794909
2018-04-06 18:02:13 +00:00
|
|
|
if (!gst_structure_get_boolean (s, "might-have-been-fec",
|
|
|
|
&might_have_been_fec) || !might_have_been_fec) {
|
|
|
|
/* send GAP event */
|
|
|
|
sevent = gst_event_new_gap (timestamp, duration);
|
2020-07-01 16:18:36 +00:00
|
|
|
gst_event_set_gap_flags (sevent, GST_GAP_FLAG_MISSING_DATA);
|
rtpbasedepayload: condition the sending of gap events
The default implementation for packet loss handling previously
always sent a gap event.
While this is correct as long as we know the packet that was
lost was actually a media packet, with ULPFEC this becomes
a bit more complicated, as we do not know whether the packet
that was lost was a FEC packet, in which case it is better
to not actually send any gap events in the default implementation.
Some payloaders can be more clever about, for example VP8 can
use the picture-id, and the M and S bits to determine whether
the missing packet was inside an encoded frame or outside,
and thus whether if it was a media packet or a FEC packet,
which is why ulpfecdec still lets these lost events go through,
though stripping them of their seqnum, and appending a new
"might-have-been-fec" field to them.
This is all a bit terrible, but necessary to have ULPFEC
integrate properly with the rest of our RTP stack.
https://bugzilla.gnome.org/show_bug.cgi?id=794909
2018-04-06 18:02:13 +00:00
|
|
|
res = gst_pad_push_event (filter->srcpad, sevent);
|
|
|
|
}
|
2008-05-02 12:11:07 +00:00
|
|
|
|
rtpbasedepayload: condition the sending of gap events
The default implementation for packet loss handling previously
always sent a gap event.
While this is correct as long as we know the packet that was
lost was actually a media packet, with ULPFEC this becomes
a bit more complicated, as we do not know whether the packet
that was lost was a FEC packet, in which case it is better
to not actually send any gap events in the default implementation.
Some payloaders can be more clever about, for example VP8 can
use the picture-id, and the M and S bits to determine whether
the missing packet was inside an encoded frame or outside,
and thus whether if it was a media packet or a FEC packet,
which is why ulpfecdec still lets these lost events go through,
though stripping them of their seqnum, and appending a new
"might-have-been-fec" field to them.
This is all a bit terrible, but necessary to have ULPFEC
integrate properly with the rest of our RTP stack.
https://bugzilla.gnome.org/show_bug.cgi?id=794909
2018-04-06 18:02:13 +00:00
|
|
|
return res;
|
2008-05-02 12:11:07 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2019-07-12 14:56:52 +00:00
|
|
|
priv->onvif_mode = FALSE;
|
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;
|
2018-06-05 15:24:55 +00:00
|
|
|
priv->segment_seqnum = GST_SEQNUM_INVALID;
|
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);
|
2015-07-07 14:05:59 +00:00
|
|
|
gst_event_replace (&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_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;
|
2015-08-15 13:33:14 +00:00
|
|
|
GstClockTime pts = GST_CLOCK_TIME_NONE, dts = GST_CLOCK_TIME_NONE;
|
2014-04-12 05:10:36 +00:00
|
|
|
|
|
|
|
priv = depayload->priv;
|
|
|
|
|
2015-08-15 13:33:14 +00:00
|
|
|
GST_OBJECT_LOCK (depayload);
|
|
|
|
if (depayload->segment.format != GST_FORMAT_UNDEFINED) {
|
|
|
|
pts = gst_segment_to_running_time (&depayload->segment, GST_FORMAT_TIME,
|
|
|
|
priv->pts);
|
|
|
|
dts = gst_segment_to_running_time (&depayload->segment, GST_FORMAT_TIME,
|
|
|
|
priv->dts);
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (depayload);
|
2015-08-05 19:32:54 +00:00
|
|
|
|
2014-04-12 05:10:36 +00:00
|
|
|
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,
|
2015-08-05 19:32:54 +00:00
|
|
|
"running-time-dts", G_TYPE_UINT64, dts,
|
|
|
|
"running-time-pts", G_TYPE_UINT64, pts,
|
2014-04-12 05:10:36 +00:00
|
|
|
"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)
|
|
|
|
{
|
2018-10-10 18:16:12 +00:00
|
|
|
GstRTPBaseDepayload *depayload;
|
2019-06-13 08:36:05 +00:00
|
|
|
GstRTPBaseDepayloadPrivate *priv;
|
2018-10-10 18:16:12 +00:00
|
|
|
|
|
|
|
depayload = GST_RTP_BASE_DEPAYLOAD (object);
|
2019-06-13 08:36:05 +00:00
|
|
|
priv = depayload->priv;
|
2018-10-10 18:16:12 +00:00
|
|
|
|
2005-07-14 10:29:30 +00:00
|
|
|
switch (prop_id) {
|
2018-10-10 18:16:12 +00:00
|
|
|
case PROP_SOURCE_INFO:
|
|
|
|
gst_rtp_base_depayload_set_source_info_enabled (depayload,
|
|
|
|
g_value_get_boolean (value));
|
|
|
|
break;
|
2019-06-13 08:36:05 +00:00
|
|
|
case PROP_MAX_REORDER:
|
|
|
|
priv->max_reorder = g_value_get_int (value);
|
|
|
|
break;
|
2021-01-26 08:37:44 +00:00
|
|
|
case PROP_AUTO_HEADER_EXTENSION:
|
|
|
|
priv->auto_hdr_ext = g_value_get_boolean (value);
|
|
|
|
break;
|
2005-07-14 10:29:30 +00:00
|
|
|
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;
|
2019-06-13 08:36:05 +00:00
|
|
|
GstRTPBaseDepayloadPrivate *priv;
|
2014-04-12 05:10:36 +00:00
|
|
|
|
|
|
|
depayload = GST_RTP_BASE_DEPAYLOAD (object);
|
2019-06-13 08:36:05 +00:00
|
|
|
priv = depayload->priv;
|
2014-04-12 05:10:36 +00:00
|
|
|
|
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;
|
2018-10-10 18:16:12 +00:00
|
|
|
case PROP_SOURCE_INFO:
|
|
|
|
g_value_set_boolean (value,
|
|
|
|
gst_rtp_base_depayload_is_source_info_enabled (depayload));
|
|
|
|
break;
|
2019-06-13 08:36:05 +00:00
|
|
|
case PROP_MAX_REORDER:
|
|
|
|
g_value_set_int (value, priv->max_reorder);
|
|
|
|
break;
|
2021-01-26 08:37:44 +00:00
|
|
|
case PROP_AUTO_HEADER_EXTENSION:
|
|
|
|
g_value_set_boolean (value, priv->auto_hdr_ext);
|
|
|
|
break;
|
2005-07-14 10:29:30 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-10-10 18:16:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtp_base_depayload_set_source_info_enabled:
|
|
|
|
* @depayload: a #GstRTPBaseDepayload
|
|
|
|
* @enable: whether to add meta about RTP sources to buffer
|
|
|
|
*
|
|
|
|
* Enable or disable adding #GstRTPSourceMeta to depayloaded buffers.
|
|
|
|
*
|
|
|
|
* Since: 1.16
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gst_rtp_base_depayload_set_source_info_enabled (GstRTPBaseDepayload * depayload,
|
|
|
|
gboolean enable)
|
|
|
|
{
|
|
|
|
depayload->priv->source_info = enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_rtp_base_depayload_is_source_info_enabled:
|
|
|
|
* @depayload: a #GstRTPBaseDepayload
|
|
|
|
*
|
|
|
|
* Queries whether #GstRTPSourceMeta will be added to depayloaded buffers.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if source-info is enabled.
|
|
|
|
*
|
|
|
|
* Since: 1.16
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gst_rtp_base_depayload_is_source_info_enabled (GstRTPBaseDepayload * depayload)
|
|
|
|
{
|
|
|
|
return depayload->priv->source_info;
|
|
|
|
}
|