2010-12-12 04:10:01 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <2010> Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-04 00:07:18 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-12-12 04:10:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
2012-11-01 10:55:03 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2021-02-12 12:16:28 +00:00
|
|
|
#include "gstrtpelements.h"
|
2010-12-12 04:10:01 +00:00
|
|
|
#include "gstrtpgstdepay.h"
|
2015-08-04 17:59:17 +00:00
|
|
|
#include "gstrtputils.h"
|
2010-12-12 04:10:01 +00:00
|
|
|
|
2018-07-26 13:43:28 +00:00
|
|
|
#include <gst/video/video.h>
|
|
|
|
|
2010-12-12 04:10:01 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (rtpgstdepay_debug);
|
|
|
|
#define GST_CAT_DEFAULT (rtpgstdepay_debug)
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_rtp_gst_depay_src_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_rtp_gst_depay_sink_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("application/x-rtp, "
|
|
|
|
"media = (string) \"application\", "
|
|
|
|
"clock-rate = (int) 90000, " "encoding-name = (string) \"X-GST\"")
|
|
|
|
);
|
|
|
|
|
2011-04-25 11:16:58 +00:00
|
|
|
#define gst_rtp_gst_depay_parent_class parent_class
|
2011-11-11 11:25:01 +00:00
|
|
|
G_DEFINE_TYPE (GstRtpGSTDepay, gst_rtp_gst_depay, GST_TYPE_RTP_BASE_DEPAYLOAD);
|
2021-02-12 12:16:28 +00:00
|
|
|
GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (rtpgstdepay, "rtpgstdepay",
|
|
|
|
GST_RANK_MARGINAL, GST_TYPE_RTP_GST_DEPAY, rtp_element_init (plugin));
|
2010-12-12 04:10:01 +00:00
|
|
|
|
|
|
|
static void gst_rtp_gst_depay_finalize (GObject * object);
|
|
|
|
|
2013-08-21 08:28:50 +00:00
|
|
|
static gboolean gst_rtp_gst_depay_handle_event (GstRTPBaseDepayload * depay,
|
|
|
|
GstEvent * event);
|
2010-12-12 14:10:47 +00:00
|
|
|
static GstStateChangeReturn gst_rtp_gst_depay_change_state (GstElement *
|
|
|
|
element, GstStateChange transition);
|
|
|
|
|
2013-08-21 08:28:50 +00:00
|
|
|
static void gst_rtp_gst_depay_reset (GstRtpGSTDepay * rtpgstdepay, gboolean
|
|
|
|
full);
|
2011-11-11 11:25:01 +00:00
|
|
|
static gboolean gst_rtp_gst_depay_setcaps (GstRTPBaseDepayload * depayload,
|
2010-12-12 04:10:01 +00:00
|
|
|
GstCaps * caps);
|
2011-11-11 11:25:01 +00:00
|
|
|
static GstBuffer *gst_rtp_gst_depay_process (GstRTPBaseDepayload * depayload,
|
2015-07-12 13:27:15 +00:00
|
|
|
GstRTPBuffer * rtp);
|
2010-12-12 04:10:01 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_gst_depay_class_init (GstRtpGSTDepayClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2010-12-12 14:10:47 +00:00
|
|
|
GstElementClass *gstelement_class;
|
2011-11-11 11:25:01 +00:00
|
|
|
GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
|
2010-12-12 04:10:01 +00:00
|
|
|
|
2011-04-25 11:16:58 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (rtpgstdepay_debug, "rtpgstdepay", 0,
|
|
|
|
"Gstreamer RTP Depayloader");
|
|
|
|
|
2010-12-12 04:10:01 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
2010-12-12 14:10:47 +00:00
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2011-11-11 11:25:01 +00:00
|
|
|
gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
|
2010-12-12 04:10:01 +00:00
|
|
|
|
|
|
|
gobject_class->finalize = gst_rtp_gst_depay_finalize;
|
|
|
|
|
2010-12-12 14:10:47 +00:00
|
|
|
gstelement_class->change_state = gst_rtp_gst_depay_change_state;
|
|
|
|
|
2016-03-04 01:30:12 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&gst_rtp_gst_depay_src_template);
|
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&gst_rtp_gst_depay_sink_template);
|
2011-04-25 11:16:58 +00:00
|
|
|
|
2012-04-09 23:51:41 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2011-04-25 11:16:58 +00:00
|
|
|
"GStreamer depayloader", "Codec/Depayloader/Network",
|
|
|
|
"Extracts GStreamer buffers from RTP packets",
|
|
|
|
"Wim Taymans <wim.taymans@gmail.com>");
|
|
|
|
|
2013-08-21 08:28:50 +00:00
|
|
|
gstrtpbasedepayload_class->handle_event = gst_rtp_gst_depay_handle_event;
|
2011-11-11 11:25:01 +00:00
|
|
|
gstrtpbasedepayload_class->set_caps = gst_rtp_gst_depay_setcaps;
|
2015-07-12 13:27:15 +00:00
|
|
|
gstrtpbasedepayload_class->process_rtp_packet = gst_rtp_gst_depay_process;
|
2010-12-12 04:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-04-25 11:16:58 +00:00
|
|
|
gst_rtp_gst_depay_init (GstRtpGSTDepay * rtpgstdepay)
|
2010-12-12 04:10:01 +00:00
|
|
|
{
|
2023-08-11 10:24:49 +00:00
|
|
|
gst_rtp_base_depayload_set_aggregate_hdrext_enabled (GST_RTP_BASE_DEPAYLOAD
|
|
|
|
(rtpgstdepay), TRUE);
|
|
|
|
|
2010-12-12 04:10:01 +00:00
|
|
|
rtpgstdepay->adapter = gst_adapter_new ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_gst_depay_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstRtpGSTDepay *rtpgstdepay;
|
|
|
|
|
|
|
|
rtpgstdepay = GST_RTP_GST_DEPAY (object);
|
|
|
|
|
2013-08-21 08:28:50 +00:00
|
|
|
gst_rtp_gst_depay_reset (rtpgstdepay, TRUE);
|
2010-12-12 04:10:01 +00:00
|
|
|
g_object_unref (rtpgstdepay->adapter);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2010-12-12 14:10:47 +00:00
|
|
|
static void
|
2013-08-21 08:28:50 +00:00
|
|
|
gst_rtp_gst_depay_reset (GstRtpGSTDepay * rtpgstdepay, gboolean full)
|
2010-12-12 14:10:47 +00:00
|
|
|
{
|
|
|
|
gst_adapter_clear (rtpgstdepay->adapter);
|
2013-08-21 08:28:50 +00:00
|
|
|
if (full) {
|
|
|
|
rtpgstdepay->current_CV = 0;
|
2019-06-12 11:57:24 +00:00
|
|
|
gst_caps_replace (&rtpgstdepay->current_caps, NULL);
|
2013-08-21 10:10:00 +00:00
|
|
|
g_free (rtpgstdepay->stream_id);
|
|
|
|
rtpgstdepay->stream_id = NULL;
|
|
|
|
if (rtpgstdepay->tags)
|
|
|
|
gst_tag_list_unref (rtpgstdepay->tags);
|
|
|
|
rtpgstdepay->tags = NULL;
|
2013-08-21 08:28:50 +00:00
|
|
|
}
|
2010-12-12 14:10:47 +00:00
|
|
|
}
|
|
|
|
|
2010-12-12 04:10:01 +00:00
|
|
|
static gboolean
|
2011-11-11 11:25:01 +00:00
|
|
|
gst_rtp_gst_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
|
2010-12-12 04:10:01 +00:00
|
|
|
{
|
|
|
|
GstRtpGSTDepay *rtpgstdepay;
|
|
|
|
GstStructure *structure;
|
|
|
|
gint clock_rate;
|
|
|
|
gboolean res;
|
|
|
|
const gchar *capsenc;
|
|
|
|
|
|
|
|
rtpgstdepay = GST_RTP_GST_DEPAY (depayload);
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
|
|
|
if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
|
|
|
|
clock_rate = 90000;
|
|
|
|
depayload->clock_rate = clock_rate;
|
|
|
|
|
|
|
|
capsenc = gst_structure_get_string (structure, "caps");
|
|
|
|
if (capsenc) {
|
2012-11-01 10:55:03 +00:00
|
|
|
GstCaps *outcaps;
|
2010-12-12 04:10:01 +00:00
|
|
|
gsize out_len;
|
2012-11-01 10:55:03 +00:00
|
|
|
gchar *capsstr;
|
|
|
|
const gchar *capsver;
|
|
|
|
guint CV;
|
2010-12-12 04:10:01 +00:00
|
|
|
|
2012-11-01 10:55:03 +00:00
|
|
|
/* decode caps */
|
2010-12-12 04:10:01 +00:00
|
|
|
capsstr = (gchar *) g_base64_decode (capsenc, &out_len);
|
|
|
|
outcaps = gst_caps_from_string (capsstr);
|
|
|
|
g_free (capsstr);
|
|
|
|
|
2012-11-01 10:55:03 +00:00
|
|
|
/* parse version */
|
|
|
|
capsver = gst_structure_get_string (structure, "capsversion");
|
|
|
|
if (capsver) {
|
|
|
|
CV = atoi (capsver);
|
|
|
|
} else {
|
|
|
|
/* no version, assume 0 */
|
|
|
|
CV = 0;
|
|
|
|
}
|
|
|
|
/* store in cache */
|
|
|
|
rtpgstdepay->current_CV = CV;
|
2019-06-12 11:57:24 +00:00
|
|
|
gst_caps_replace (&rtpgstdepay->current_caps, outcaps);
|
2012-11-01 10:55:03 +00:00
|
|
|
|
|
|
|
res = gst_pad_set_caps (depayload->srcpad, outcaps);
|
|
|
|
gst_caps_unref (outcaps);
|
2010-12-12 04:10:01 +00:00
|
|
|
} else {
|
2012-11-01 10:55:03 +00:00
|
|
|
GST_WARNING_OBJECT (depayload, "no caps given");
|
|
|
|
rtpgstdepay->current_CV = -1;
|
2019-06-12 11:57:24 +00:00
|
|
|
gst_caps_replace (&rtpgstdepay->current_caps, NULL);
|
2012-11-01 10:55:03 +00:00
|
|
|
res = TRUE;
|
2010-12-12 04:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-11-01 17:44:11 +00:00
|
|
|
static gboolean
|
|
|
|
read_length (GstRtpGSTDepay * rtpgstdepay, guint8 * data, guint size,
|
|
|
|
guint * length, guint * skip)
|
|
|
|
{
|
|
|
|
guint b, len, offset;
|
|
|
|
|
|
|
|
/* start reading the length, we need this to skip to the data later */
|
|
|
|
len = offset = 0;
|
|
|
|
do {
|
|
|
|
if (offset >= size)
|
|
|
|
return FALSE;
|
|
|
|
b = data[offset++];
|
|
|
|
len = (len << 7) | (b & 0x7f);
|
|
|
|
} while (b & 0x80);
|
|
|
|
|
|
|
|
/* check remaining buffer size */
|
|
|
|
if (size - offset < len)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*length = len;
|
|
|
|
*skip = offset;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
|
|
|
read_caps (GstRtpGSTDepay * rtpgstdepay, GstBuffer * buf, guint * skip)
|
|
|
|
{
|
|
|
|
guint offset, length;
|
|
|
|
GstCaps *caps;
|
|
|
|
GstMapInfo map;
|
|
|
|
|
|
|
|
gst_buffer_map (buf, &map, GST_MAP_READ);
|
|
|
|
|
2012-12-18 14:51:46 +00:00
|
|
|
GST_DEBUG_OBJECT (rtpgstdepay, "buffer size %" G_GSIZE_FORMAT, map.size);
|
2012-11-01 17:44:11 +00:00
|
|
|
|
|
|
|
if (!read_length (rtpgstdepay, map.data, map.size, &length, &offset))
|
|
|
|
goto too_small;
|
|
|
|
|
2014-11-20 11:40:28 +00:00
|
|
|
if (length == 0 || map.data[offset + length - 1] != '\0')
|
|
|
|
goto invalid_buffer;
|
|
|
|
|
2012-11-01 17:44:11 +00:00
|
|
|
GST_DEBUG_OBJECT (rtpgstdepay, "parsing caps %s", &map.data[offset]);
|
|
|
|
|
|
|
|
/* parse and store in cache */
|
|
|
|
caps = gst_caps_from_string ((gchar *) & map.data[offset]);
|
|
|
|
gst_buffer_unmap (buf, &map);
|
|
|
|
|
|
|
|
*skip = length + offset;
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
|
|
|
|
too_small:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_WARNING (rtpgstdepay, STREAM, DECODE,
|
|
|
|
("Buffer too small."), (NULL));
|
|
|
|
gst_buffer_unmap (buf, &map);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-11-20 11:40:28 +00:00
|
|
|
invalid_buffer:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_WARNING (rtpgstdepay, STREAM, DECODE,
|
|
|
|
("caps string not 0-terminated."), (NULL));
|
|
|
|
gst_buffer_unmap (buf, &map);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-01 17:44:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstEvent *
|
|
|
|
read_event (GstRtpGSTDepay * rtpgstdepay, guint type,
|
|
|
|
GstBuffer * buf, guint * skip)
|
|
|
|
{
|
|
|
|
guint offset, length;
|
|
|
|
GstStructure *s;
|
|
|
|
GstEvent *event;
|
|
|
|
GstEventType etype;
|
|
|
|
gchar *end;
|
|
|
|
GstMapInfo map;
|
|
|
|
|
|
|
|
gst_buffer_map (buf, &map, GST_MAP_READ);
|
|
|
|
|
2012-12-18 14:51:46 +00:00
|
|
|
GST_DEBUG_OBJECT (rtpgstdepay, "buffer size %" G_GSIZE_FORMAT, map.size);
|
2012-11-01 17:44:11 +00:00
|
|
|
|
|
|
|
if (!read_length (rtpgstdepay, map.data, map.size, &length, &offset))
|
|
|
|
goto too_small;
|
|
|
|
|
2014-11-20 12:14:14 +00:00
|
|
|
if (length == 0)
|
|
|
|
goto invalid_buffer;
|
|
|
|
/* backward compat, old payloader did not put 0-byte at the end */
|
2015-11-16 01:16:29 +00:00
|
|
|
if (map.data[offset + length - 1] != '\0'
|
|
|
|
&& map.data[offset + length - 1] != ';')
|
2014-11-20 11:40:28 +00:00
|
|
|
goto invalid_buffer;
|
|
|
|
|
2012-11-01 17:44:11 +00:00
|
|
|
GST_DEBUG_OBJECT (rtpgstdepay, "parsing event %s", &map.data[offset]);
|
|
|
|
|
|
|
|
/* parse */
|
|
|
|
s = gst_structure_from_string ((gchar *) & map.data[offset], &end);
|
|
|
|
gst_buffer_unmap (buf, &map);
|
|
|
|
|
2013-04-12 15:08:58 +00:00
|
|
|
if (s == NULL)
|
|
|
|
goto parse_failed;
|
|
|
|
|
2012-11-01 17:44:11 +00:00
|
|
|
switch (type) {
|
|
|
|
case 1:
|
|
|
|
etype = GST_EVENT_TAG;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
etype = GST_EVENT_CUSTOM_DOWNSTREAM;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
etype = GST_EVENT_CUSTOM_BOTH;
|
|
|
|
break;
|
2013-07-25 21:56:38 +00:00
|
|
|
case 4:
|
|
|
|
etype = GST_EVENT_STREAM_START;
|
|
|
|
break;
|
2012-11-01 17:44:11 +00:00
|
|
|
default:
|
|
|
|
goto unknown_event;
|
|
|
|
}
|
|
|
|
event = gst_event_new_custom (etype, s);
|
|
|
|
|
|
|
|
*skip = length + offset;
|
|
|
|
|
|
|
|
return event;
|
|
|
|
|
|
|
|
too_small:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_WARNING (rtpgstdepay, STREAM, DECODE,
|
|
|
|
("Buffer too small."), (NULL));
|
|
|
|
gst_buffer_unmap (buf, &map);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-11-20 11:40:28 +00:00
|
|
|
invalid_buffer:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_WARNING (rtpgstdepay, STREAM, DECODE,
|
|
|
|
("event string not 0-terminated."), (NULL));
|
|
|
|
gst_buffer_unmap (buf, &map);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-04-12 15:08:58 +00:00
|
|
|
parse_failed:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (rtpgstdepay, "could not parse event");
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-01 17:44:11 +00:00
|
|
|
unknown_event:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (rtpgstdepay, "unknown event type");
|
2012-11-01 18:42:24 +00:00
|
|
|
gst_structure_free (s);
|
2012-11-01 17:44:11 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-21 10:10:00 +00:00
|
|
|
static void
|
|
|
|
store_event (GstRtpGSTDepay * rtpgstdepay, GstEvent * event)
|
|
|
|
{
|
|
|
|
gboolean do_push = FALSE;
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_TAG:
|
|
|
|
{
|
|
|
|
GstTagList *old, *tags;
|
|
|
|
|
|
|
|
gst_event_parse_tag (event, &tags);
|
|
|
|
|
|
|
|
old = rtpgstdepay->tags;
|
|
|
|
if (!old || !gst_tag_list_is_equal (old, tags)) {
|
|
|
|
do_push = TRUE;
|
|
|
|
if (old)
|
|
|
|
gst_tag_list_unref (old);
|
|
|
|
rtpgstdepay->tags = gst_tag_list_ref (tags);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_EVENT_CUSTOM_DOWNSTREAM:
|
|
|
|
case GST_EVENT_CUSTOM_BOTH:
|
|
|
|
/* always push custom events */
|
|
|
|
do_push = TRUE;
|
|
|
|
break;
|
|
|
|
case GST_EVENT_STREAM_START:
|
|
|
|
{
|
|
|
|
gchar *old;
|
|
|
|
const gchar *stream_id = NULL;
|
|
|
|
|
|
|
|
gst_event_parse_stream_start (event, &stream_id);
|
|
|
|
|
|
|
|
old = rtpgstdepay->stream_id;
|
|
|
|
if (!old || g_strcmp0 (old, stream_id)) {
|
|
|
|
do_push = TRUE;
|
|
|
|
g_free (old);
|
|
|
|
rtpgstdepay->stream_id = g_strdup (stream_id);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
/* unknown event, don't push */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (do_push)
|
|
|
|
gst_pad_push_event (GST_RTP_BASE_DEPAYLOAD (rtpgstdepay)->srcpad, event);
|
|
|
|
else
|
|
|
|
gst_event_unref (event);
|
|
|
|
}
|
|
|
|
|
2010-12-12 04:10:01 +00:00
|
|
|
static GstBuffer *
|
2015-07-12 13:27:15 +00:00
|
|
|
gst_rtp_gst_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
|
2010-12-12 04:10:01 +00:00
|
|
|
{
|
|
|
|
GstRtpGSTDepay *rtpgstdepay;
|
|
|
|
GstBuffer *subbuf, *outbuf = NULL;
|
|
|
|
gint payload_len;
|
|
|
|
guint8 *payload;
|
2012-11-01 17:44:11 +00:00
|
|
|
guint CV, frag_offset, avail, offset;
|
2010-12-12 04:10:01 +00:00
|
|
|
|
|
|
|
rtpgstdepay = GST_RTP_GST_DEPAY (depayload);
|
|
|
|
|
2015-07-12 13:27:15 +00:00
|
|
|
payload_len = gst_rtp_buffer_get_payload_len (rtp);
|
2010-12-12 04:10:01 +00:00
|
|
|
|
|
|
|
if (payload_len <= 8)
|
|
|
|
goto empty_packet;
|
|
|
|
|
2015-07-12 13:27:15 +00:00
|
|
|
if (GST_BUFFER_IS_DISCONT (rtp->buffer)) {
|
2010-12-12 04:10:01 +00:00
|
|
|
GST_WARNING_OBJECT (rtpgstdepay, "DISCONT, clear adapter");
|
|
|
|
gst_adapter_clear (rtpgstdepay->adapter);
|
2023-08-11 10:24:49 +00:00
|
|
|
gst_rtp_base_depayload_flush (depayload, TRUE);
|
2010-12-12 04:10:01 +00:00
|
|
|
}
|
|
|
|
|
2015-07-12 13:27:15 +00:00
|
|
|
payload = gst_rtp_buffer_get_payload (rtp);
|
2010-12-12 04:10:01 +00:00
|
|
|
|
|
|
|
/* strip off header
|
|
|
|
*
|
|
|
|
* 0 1 2 3
|
|
|
|
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2012-11-01 17:44:11 +00:00
|
|
|
* |C| CV |D|0|0|0| ETYPE | MBZ |
|
2010-12-12 04:10:01 +00:00
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | Frag_offset |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
*/
|
2012-11-01 11:58:57 +00:00
|
|
|
frag_offset =
|
|
|
|
(payload[4] << 24) | (payload[5] << 16) | (payload[6] << 8) | payload[7];
|
|
|
|
|
|
|
|
avail = gst_adapter_available (rtpgstdepay->adapter);
|
|
|
|
if (avail != frag_offset)
|
|
|
|
goto wrong_frag;
|
2010-12-12 04:10:01 +00:00
|
|
|
|
|
|
|
/* subbuffer skipping the 8 header bytes */
|
2015-07-12 13:27:15 +00:00
|
|
|
subbuf = gst_rtp_buffer_get_payload_subbuffer (rtp, 8, -1);
|
2010-12-12 04:10:01 +00:00
|
|
|
gst_adapter_push (rtpgstdepay->adapter, subbuf);
|
|
|
|
|
2012-11-01 17:44:11 +00:00
|
|
|
offset = 0;
|
2015-07-12 13:27:15 +00:00
|
|
|
if (gst_rtp_buffer_get_marker (rtp)) {
|
2010-12-12 04:10:01 +00:00
|
|
|
guint avail;
|
|
|
|
GstCaps *outcaps;
|
|
|
|
|
|
|
|
/* take the buffer */
|
|
|
|
avail = gst_adapter_available (rtpgstdepay->adapter);
|
|
|
|
outbuf = gst_adapter_take_buffer (rtpgstdepay->adapter, avail);
|
|
|
|
|
|
|
|
CV = (payload[0] >> 4) & 0x7;
|
|
|
|
|
|
|
|
if (payload[0] & 0x80) {
|
2012-11-01 17:44:11 +00:00
|
|
|
guint size;
|
2010-12-12 04:10:01 +00:00
|
|
|
|
|
|
|
/* C bit, we have inline caps */
|
2012-11-01 17:44:11 +00:00
|
|
|
outcaps = read_caps (rtpgstdepay, outbuf, &size);
|
|
|
|
if (outcaps == NULL)
|
|
|
|
goto no_caps;
|
2010-12-12 04:10:01 +00:00
|
|
|
|
2012-11-01 17:44:11 +00:00
|
|
|
GST_DEBUG_OBJECT (rtpgstdepay,
|
|
|
|
"inline caps %u, length %u, %" GST_PTR_FORMAT, CV, size, outcaps);
|
2012-11-01 10:55:03 +00:00
|
|
|
|
2019-06-12 11:57:24 +00:00
|
|
|
if (!rtpgstdepay->current_caps
|
|
|
|
|| !gst_caps_is_strictly_equal (rtpgstdepay->current_caps, outcaps))
|
2018-12-04 17:50:51 +00:00
|
|
|
gst_pad_set_caps (depayload->srcpad, outcaps);
|
2019-06-12 11:57:24 +00:00
|
|
|
gst_caps_replace (&rtpgstdepay->current_caps, outcaps);
|
|
|
|
gst_caps_unref (outcaps);
|
|
|
|
rtpgstdepay->current_CV = CV;
|
2010-12-12 04:10:01 +00:00
|
|
|
|
|
|
|
/* skip caps */
|
2012-11-01 17:44:11 +00:00
|
|
|
offset += size;
|
|
|
|
avail -= size;
|
2010-12-12 04:10:01 +00:00
|
|
|
}
|
2012-11-01 17:44:11 +00:00
|
|
|
if (payload[1]) {
|
|
|
|
guint size;
|
|
|
|
GstEvent *event;
|
2010-12-12 04:10:01 +00:00
|
|
|
|
2012-11-01 17:44:11 +00:00
|
|
|
/* we have an event */
|
|
|
|
event = read_event (rtpgstdepay, payload[1], outbuf, &size);
|
|
|
|
if (event == NULL)
|
|
|
|
goto no_event;
|
2010-12-12 04:10:01 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (rtpgstdepay,
|
2012-11-01 17:44:11 +00:00
|
|
|
"inline event, length %u, %" GST_PTR_FORMAT, size, event);
|
|
|
|
|
2013-08-21 10:10:00 +00:00
|
|
|
store_event (rtpgstdepay, event);
|
2010-12-12 04:10:01 +00:00
|
|
|
|
2012-11-01 17:44:11 +00:00
|
|
|
/* no buffer after event */
|
|
|
|
avail = 0;
|
2010-12-12 04:10:01 +00:00
|
|
|
}
|
|
|
|
|
2012-11-01 17:44:11 +00:00
|
|
|
if (avail) {
|
|
|
|
if (offset != 0) {
|
|
|
|
GstBuffer *temp;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (rtpgstdepay, "sub buffer: offset %u, size %u", offset,
|
|
|
|
avail);
|
|
|
|
|
|
|
|
temp =
|
|
|
|
gst_buffer_copy_region (outbuf, GST_BUFFER_COPY_ALL, offset, avail);
|
|
|
|
|
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
outbuf = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* see what caps we need */
|
|
|
|
if (CV != rtpgstdepay->current_CV) {
|
2019-06-12 11:57:24 +00:00
|
|
|
/* we need to switch caps but didn't receive the new caps yet */
|
|
|
|
gst_caps_replace (&rtpgstdepay->current_caps, NULL);
|
|
|
|
goto missing_caps;
|
2012-11-01 17:44:11 +00:00
|
|
|
}
|
|
|
|
|
2010-12-12 04:10:01 +00:00
|
|
|
if (payload[0] & 0x8)
|
|
|
|
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DELTA_UNIT);
|
2012-11-01 17:44:11 +00:00
|
|
|
} else {
|
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
outbuf = NULL;
|
2010-12-12 04:10:01 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-01 17:44:11 +00:00
|
|
|
|
2015-08-04 17:59:17 +00:00
|
|
|
if (outbuf) {
|
|
|
|
gst_rtp_drop_meta (GST_ELEMENT_CAST (rtpgstdepay), outbuf, 0);
|
|
|
|
}
|
|
|
|
|
2010-12-12 04:10:01 +00:00
|
|
|
return outbuf;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
empty_packet:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_WARNING (rtpgstdepay, STREAM, DECODE,
|
|
|
|
("Empty Payload."), (NULL));
|
2023-08-11 10:24:49 +00:00
|
|
|
gst_rtp_base_depayload_dropped (depayload);
|
2010-12-12 04:10:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-01 11:58:57 +00:00
|
|
|
wrong_frag:
|
|
|
|
{
|
|
|
|
gst_adapter_clear (rtpgstdepay->adapter);
|
|
|
|
GST_LOG_OBJECT (rtpgstdepay, "wrong fragment, skipping");
|
2023-08-11 10:24:49 +00:00
|
|
|
gst_rtp_base_depayload_dropped (depayload);
|
2012-11-01 11:58:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-11-01 17:44:11 +00:00
|
|
|
no_caps:
|
2010-12-12 04:10:01 +00:00
|
|
|
{
|
2012-11-01 17:44:11 +00:00
|
|
|
GST_WARNING_OBJECT (rtpgstdepay, "failed to parse caps");
|
|
|
|
gst_buffer_unref (outbuf);
|
2023-08-11 10:24:49 +00:00
|
|
|
gst_rtp_base_depayload_dropped (depayload);
|
2012-11-01 17:44:11 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
no_event:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (rtpgstdepay, "failed to parse event");
|
|
|
|
gst_buffer_unref (outbuf);
|
2023-08-11 10:24:49 +00:00
|
|
|
gst_rtp_base_depayload_dropped (depayload);
|
2010-12-12 04:10:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
missing_caps:
|
|
|
|
{
|
2018-02-24 19:05:05 +00:00
|
|
|
GST_INFO_OBJECT (rtpgstdepay, "No caps received yet %u", CV);
|
2012-11-01 17:44:11 +00:00
|
|
|
gst_buffer_unref (outbuf);
|
2018-07-26 13:43:28 +00:00
|
|
|
|
|
|
|
gst_pad_push_event (GST_RTP_BASE_DEPAYLOAD_SINKPAD (rtpgstdepay),
|
|
|
|
gst_video_event_new_upstream_force_key_unit (GST_CLOCK_TIME_NONE,
|
|
|
|
TRUE, 0));
|
|
|
|
|
2023-08-11 10:24:49 +00:00
|
|
|
gst_rtp_base_depayload_dropped (depayload);
|
|
|
|
|
2010-12-12 04:10:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-21 08:28:50 +00:00
|
|
|
static gboolean
|
|
|
|
gst_rtp_gst_depay_handle_event (GstRTPBaseDepayload * depay, GstEvent * event)
|
|
|
|
{
|
|
|
|
GstRtpGSTDepay *rtpgstdepay;
|
|
|
|
|
|
|
|
rtpgstdepay = GST_RTP_GST_DEPAY (depay);
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
gst_rtp_gst_depay_reset (rtpgstdepay, FALSE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
GST_RTP_BASE_DEPAYLOAD_CLASS (parent_class)->handle_event (depay, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-12 14:10:47 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_rtp_gst_depay_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstRtpGSTDepay *rtpgstdepay;
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
|
|
|
rtpgstdepay = GST_RTP_GST_DEPAY (element);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2013-08-21 08:28:50 +00:00
|
|
|
gst_rtp_gst_depay_reset (rtpgstdepay, TRUE);
|
2010-12-12 14:10:47 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2013-08-21 08:28:50 +00:00
|
|
|
gst_rtp_gst_depay_reset (rtpgstdepay, TRUE);
|
2010-12-12 14:10:47 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|