2007-03-14 09:03:58 +00:00
|
|
|
/* RTP muxer element for GStreamer
|
|
|
|
*
|
|
|
|
* gstrtpmux.c:
|
|
|
|
*
|
|
|
|
* Copyright (C) <2007> Nokia Corporation.
|
|
|
|
* Contact: Zeeshan Ali <zeeshan.ali@nokia.com>
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000,2005 Wim Taymans <wim@fluendo.com>
|
2007-03-07 08:53:07 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:element-rtpmux
|
|
|
|
*
|
2009-02-10 19:11:15 +00:00
|
|
|
* The rtp muxer takes multiple RTP streams having the same clock-rate and
|
|
|
|
* muxes into a single stream with a single SSRC.
|
2007-03-07 08:53:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/rtp/gstrtpbuffer.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2009-04-20 21:42:40 +00:00
|
|
|
#include "gstrtpmux.h"
|
|
|
|
|
2007-03-07 08:53:07 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_rtp_mux_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_rtp_mux_debug
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
2007-03-28 11:22:19 +00:00
|
|
|
PROP_TIMESTAMP_OFFSET,
|
2007-03-07 08:53:07 +00:00
|
|
|
PROP_SEQNUM_OFFSET,
|
2007-03-29 13:36:22 +00:00
|
|
|
PROP_SEQNUM,
|
|
|
|
PROP_SSRC
|
2007-03-07 08:53:07 +00:00
|
|
|
};
|
|
|
|
|
2007-03-28 11:22:19 +00:00
|
|
|
#define DEFAULT_TIMESTAMP_OFFSET -1
|
2007-03-29 13:36:22 +00:00
|
|
|
#define DEFAULT_SEQNUM_OFFSET -1
|
|
|
|
#define DEFAULT_SSRC -1
|
2007-03-07 08:53:07 +00:00
|
|
|
|
2009-02-20 22:45:50 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2009-04-20 22:36:42 +00:00
|
|
|
gboolean have_clock_base;
|
2008-08-12 16:30:52 +00:00
|
|
|
guint clock_base;
|
2009-04-21 00:00:15 +00:00
|
|
|
|
|
|
|
GstCaps *out_caps;
|
2008-08-12 16:30:52 +00:00
|
|
|
} GstRTPMuxPadPrivate;
|
|
|
|
|
2007-03-07 08:53:07 +00:00
|
|
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("application/x-rtp")
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink_%d",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_REQUEST,
|
|
|
|
GST_STATIC_CAPS ("application/x-rtp")
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstPad *gst_rtp_mux_request_new_pad (GstElement * element,
|
|
|
|
GstPadTemplate * templ, const gchar * name);
|
2009-07-21 19:31:33 +00:00
|
|
|
static void gst_rtp_mux_release_pad (GstElement * element, GstPad * pad);
|
2009-02-20 22:45:50 +00:00
|
|
|
static GstFlowReturn gst_rtp_mux_chain (GstPad * pad, GstBuffer * buffer);
|
|
|
|
static gboolean gst_rtp_mux_setcaps (GstPad * pad, GstCaps * caps);
|
|
|
|
static GstCaps *gst_rtp_mux_getcaps (GstPad * pad);
|
2007-03-07 08:53:07 +00:00
|
|
|
|
|
|
|
static GstStateChangeReturn gst_rtp_mux_change_state (GstElement *
|
|
|
|
element, GstStateChange transition);
|
|
|
|
|
|
|
|
static void gst_rtp_mux_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_rtp_mux_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2009-12-09 13:42:21 +00:00
|
|
|
static void gst_rtp_mux_dispose (GObject * object);
|
2007-03-07 08:53:07 +00:00
|
|
|
|
2009-04-20 21:43:39 +00:00
|
|
|
GST_BOILERPLATE (GstRTPMux, gst_rtp_mux, GstElement, GST_TYPE_ELEMENT);
|
2007-03-07 08:53:07 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_mux_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&src_factory));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&sink_factory));
|
|
|
|
|
2010-03-18 16:30:26 +00:00
|
|
|
gst_element_class_set_details_simple (element_class, "RTP muxer",
|
|
|
|
"Codec/Muxer",
|
|
|
|
"multiplex N rtp streams into one", "Zeeshan Ali <first.last@nokia.com>");
|
2007-03-07 08:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_mux_class_init (GstRTPMuxClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
|
|
|
gobject_class->get_property = gst_rtp_mux_get_property;
|
|
|
|
gobject_class->set_property = gst_rtp_mux_set_property;
|
2009-12-09 13:42:21 +00:00
|
|
|
gobject_class->dispose = gst_rtp_mux_dispose;
|
2007-03-07 08:53:07 +00:00
|
|
|
|
2007-03-28 11:22:19 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass),
|
|
|
|
PROP_TIMESTAMP_OFFSET, g_param_spec_int ("timestamp-offset",
|
|
|
|
"Timestamp Offset",
|
|
|
|
"Offset to add to all outgoing timestamps (-1 = random)", -1,
|
|
|
|
G_MAXINT, DEFAULT_TIMESTAMP_OFFSET, G_PARAM_READWRITE));
|
2007-03-07 08:53:07 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SEQNUM_OFFSET,
|
|
|
|
g_param_spec_int ("seqnum-offset", "Sequence number Offset",
|
|
|
|
"Offset to add to all outgoing seqnum (-1 = random)", -1, G_MAXINT,
|
|
|
|
DEFAULT_SEQNUM_OFFSET, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SEQNUM,
|
|
|
|
g_param_spec_uint ("seqnum", "Sequence number",
|
|
|
|
"The RTP sequence number of the last processed packet",
|
|
|
|
0, G_MAXUINT, 0, G_PARAM_READABLE));
|
2007-03-29 13:36:22 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SSRC,
|
|
|
|
g_param_spec_uint ("ssrc", "SSRC",
|
|
|
|
"The SSRC of the packets (-1 == random)",
|
|
|
|
0, G_MAXUINT, DEFAULT_SSRC, G_PARAM_READWRITE));
|
2007-03-07 08:53:07 +00:00
|
|
|
|
2009-04-15 17:23:01 +00:00
|
|
|
gstelement_class->request_new_pad =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_rtp_mux_request_new_pad);
|
2009-07-21 19:31:33 +00:00
|
|
|
gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_rtp_mux_release_pad);
|
2009-04-15 17:23:01 +00:00
|
|
|
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_rtp_mux_change_state);
|
2007-03-21 12:31:49 +00:00
|
|
|
|
|
|
|
klass->chain_func = gst_rtp_mux_chain;
|
2007-03-07 08:53:07 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 13:42:21 +00:00
|
|
|
static void
|
|
|
|
gst_rtp_mux_dispose (GObject * object)
|
|
|
|
{
|
|
|
|
GList *item;
|
|
|
|
|
|
|
|
restart:
|
|
|
|
for (item = GST_ELEMENT_PADS (object); item; item = g_list_next (item)) {
|
|
|
|
GstPad *pad = GST_PAD (item->data);
|
|
|
|
if (GST_PAD_IS_SINK (pad)) {
|
|
|
|
gst_element_release_request_pad (GST_ELEMENT (object), pad);
|
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2009-02-20 22:45:50 +00:00
|
|
|
static gboolean
|
|
|
|
gst_rtp_mux_src_event (GstPad * pad, GstEvent * event)
|
2007-05-25 10:27:09 +00:00
|
|
|
{
|
2007-05-25 12:31:16 +00:00
|
|
|
GstElement *rtp_mux;
|
|
|
|
GstIterator *iter;
|
|
|
|
GstPad *sinkpad;
|
|
|
|
gboolean result = FALSE;
|
2007-05-28 12:28:08 +00:00
|
|
|
gboolean done = FALSE;
|
2008-08-12 16:23:32 +00:00
|
|
|
|
2007-05-25 12:31:16 +00:00
|
|
|
rtp_mux = gst_pad_get_parent_element (pad);
|
|
|
|
g_return_val_if_fail (rtp_mux != NULL, FALSE);
|
2007-05-25 10:27:09 +00:00
|
|
|
|
2007-05-25 12:31:16 +00:00
|
|
|
iter = gst_element_iterate_sink_pads (rtp_mux);
|
2007-05-25 10:27:09 +00:00
|
|
|
|
2007-05-28 12:28:08 +00:00
|
|
|
while (!done) {
|
2009-02-20 22:45:50 +00:00
|
|
|
switch (gst_iterator_next (iter, (gpointer) & sinkpad)) {
|
2007-05-28 12:28:08 +00:00
|
|
|
case GST_ITERATOR_OK:
|
|
|
|
gst_event_ref (event);
|
2007-05-28 15:25:05 +00:00
|
|
|
result |= gst_pad_push_event (sinkpad, event);
|
2007-05-28 12:28:08 +00:00
|
|
|
gst_object_unref (sinkpad);
|
|
|
|
break;
|
|
|
|
case GST_ITERATOR_RESYNC:
|
|
|
|
gst_iterator_resync (iter);
|
2008-12-01 22:54:58 +00:00
|
|
|
result = FALSE;
|
2007-05-28 12:28:08 +00:00
|
|
|
break;
|
|
|
|
case GST_ITERATOR_ERROR:
|
2007-05-28 12:37:49 +00:00
|
|
|
GST_WARNING_OBJECT (rtp_mux, "Error iterating sinkpads");
|
2007-05-28 12:28:08 +00:00
|
|
|
case GST_ITERATOR_DONE:
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2007-05-25 10:27:09 +00:00
|
|
|
}
|
2008-12-01 22:54:58 +00:00
|
|
|
gst_iterator_free (iter);
|
|
|
|
gst_object_unref (rtp_mux);
|
2007-05-25 10:27:09 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-03-07 08:53:07 +00:00
|
|
|
static void
|
2009-04-20 21:43:39 +00:00
|
|
|
gst_rtp_mux_init (GstRTPMux * object, GstRTPMuxClass * g_class)
|
2007-03-07 08:53:07 +00:00
|
|
|
{
|
2009-04-20 21:43:39 +00:00
|
|
|
GstElementClass *klass = GST_ELEMENT_GET_CLASS (object);
|
2007-03-07 08:53:07 +00:00
|
|
|
|
2009-04-20 21:43:39 +00:00
|
|
|
object->srcpad =
|
2007-03-07 08:53:07 +00:00
|
|
|
gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
|
|
|
|
"src"), "src");
|
2009-04-20 21:43:39 +00:00
|
|
|
gst_pad_set_event_function (object->srcpad,
|
2009-04-15 17:23:01 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_rtp_mux_src_event));
|
2009-04-20 21:43:39 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (object), object->srcpad);
|
2008-08-12 16:23:32 +00:00
|
|
|
|
2009-04-20 21:43:39 +00:00
|
|
|
object->ssrc = DEFAULT_SSRC;
|
|
|
|
object->ts_offset = DEFAULT_TIMESTAMP_OFFSET;
|
|
|
|
object->seqnum_offset = DEFAULT_SEQNUM_OFFSET;
|
2007-03-07 08:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstPad *
|
2009-09-28 17:36:44 +00:00
|
|
|
gst_rtp_mux_create_sinkpad (GstRTPMux * rtp_mux, GstPadTemplate * templ,
|
|
|
|
const gchar * req_name)
|
2007-03-07 08:53:07 +00:00
|
|
|
{
|
2007-03-22 12:41:32 +00:00
|
|
|
GstPad *newpad = NULL;
|
2009-02-20 22:45:50 +00:00
|
|
|
GstPadTemplate *class_templ;
|
2008-08-12 16:23:32 +00:00
|
|
|
|
2009-02-20 22:45:50 +00:00
|
|
|
class_templ =
|
|
|
|
gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (rtp_mux),
|
|
|
|
"sink_%d");
|
2007-03-07 08:53:07 +00:00
|
|
|
|
2007-03-21 12:31:49 +00:00
|
|
|
if (templ == class_templ) {
|
2009-09-28 17:36:44 +00:00
|
|
|
gchar *tmpname = NULL;
|
|
|
|
const gchar *name = NULL;
|
2007-03-07 08:53:07 +00:00
|
|
|
|
|
|
|
/* create new pad with the name */
|
2009-09-28 17:36:44 +00:00
|
|
|
if (req_name)
|
|
|
|
name = req_name;
|
|
|
|
else
|
|
|
|
name = tmpname = g_strdup_printf ("sink_%02d", rtp_mux->numpads);
|
2007-03-07 08:53:07 +00:00
|
|
|
newpad = gst_pad_new_from_template (templ, name);
|
2009-09-28 17:36:44 +00:00
|
|
|
g_free (tmpname);
|
2007-03-07 08:53:07 +00:00
|
|
|
|
|
|
|
rtp_mux->numpads++;
|
|
|
|
} else {
|
2007-03-14 10:20:58 +00:00
|
|
|
GST_WARNING_OBJECT (rtp_mux, "this is not our template!\n");
|
2007-03-07 08:53:07 +00:00
|
|
|
}
|
|
|
|
|
2007-03-22 15:42:51 +00:00
|
|
|
return newpad;
|
2007-03-22 12:41:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_mux_setup_sinkpad (GstRTPMux * rtp_mux, GstPad * sinkpad)
|
|
|
|
{
|
|
|
|
GstRTPMuxClass *klass;
|
2008-08-12 16:30:52 +00:00
|
|
|
GstRTPMuxPadPrivate *padpriv = g_slice_new0 (GstRTPMuxPadPrivate);
|
2007-03-22 12:41:32 +00:00
|
|
|
|
|
|
|
klass = GST_RTP_MUX_GET_CLASS (rtp_mux);
|
2008-08-12 16:23:32 +00:00
|
|
|
|
2007-03-07 08:53:07 +00:00
|
|
|
/* setup some pad functions */
|
2007-03-22 12:41:32 +00:00
|
|
|
gst_pad_set_setcaps_function (sinkpad, gst_rtp_mux_setcaps);
|
2009-02-18 20:20:58 +00:00
|
|
|
gst_pad_set_getcaps_function (sinkpad, gst_rtp_mux_getcaps);
|
2007-03-21 12:31:49 +00:00
|
|
|
if (klass->chain_func)
|
2007-03-22 12:41:32 +00:00
|
|
|
gst_pad_set_chain_function (sinkpad, klass->chain_func);
|
2007-03-21 12:31:49 +00:00
|
|
|
if (klass->sink_event_func)
|
2007-03-22 12:41:32 +00:00
|
|
|
gst_pad_set_event_function (sinkpad, klass->sink_event_func);
|
2007-03-07 08:53:07 +00:00
|
|
|
|
2007-08-20 18:50:32 +00:00
|
|
|
/* This could break with gstreamer 0.10.9 */
|
2007-07-06 20:24:59 +00:00
|
|
|
gst_pad_set_active (sinkpad, TRUE);
|
|
|
|
|
2008-08-12 16:30:52 +00:00
|
|
|
gst_pad_set_element_private (sinkpad, padpriv);
|
|
|
|
|
2007-03-07 08:53:07 +00:00
|
|
|
/* dd the pad to the element */
|
2007-03-22 12:41:32 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (rtp_mux), sinkpad);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstPad *
|
|
|
|
gst_rtp_mux_request_new_pad (GstElement * element,
|
|
|
|
GstPadTemplate * templ, const gchar * req_name)
|
|
|
|
{
|
|
|
|
GstRTPMux *rtp_mux;
|
|
|
|
GstPad *newpad;
|
|
|
|
|
|
|
|
g_return_val_if_fail (templ != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GST_IS_RTP_MUX (element), NULL);
|
|
|
|
|
|
|
|
rtp_mux = GST_RTP_MUX (element);
|
|
|
|
|
|
|
|
if (templ->direction != GST_PAD_SINK) {
|
|
|
|
GST_WARNING_OBJECT (rtp_mux, "request pad that is not a SINK pad");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-09-28 17:36:44 +00:00
|
|
|
newpad = gst_rtp_mux_create_sinkpad (rtp_mux, templ, req_name);
|
2007-03-22 12:41:32 +00:00
|
|
|
if (newpad)
|
|
|
|
gst_rtp_mux_setup_sinkpad (rtp_mux, newpad);
|
2007-03-22 15:42:51 +00:00
|
|
|
else
|
|
|
|
GST_WARNING_OBJECT (rtp_mux, "failed to create request pad");
|
2007-03-07 08:53:07 +00:00
|
|
|
|
|
|
|
return newpad;
|
|
|
|
}
|
|
|
|
|
2009-07-21 19:31:33 +00:00
|
|
|
static void
|
|
|
|
gst_rtp_mux_release_pad (GstElement * element, GstPad * pad)
|
|
|
|
{
|
|
|
|
GstRTPMuxPadPrivate *padpriv;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (element);
|
|
|
|
padpriv = gst_pad_get_element_private (pad);
|
|
|
|
gst_pad_set_element_private (pad, NULL);
|
|
|
|
GST_OBJECT_UNLOCK (element);
|
|
|
|
|
|
|
|
gst_element_remove_pad (element, pad);
|
|
|
|
|
|
|
|
if (padpriv) {
|
|
|
|
gst_caps_replace (&padpriv->out_caps, NULL);
|
|
|
|
g_slice_free (GstRTPMuxPadPrivate, padpriv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-28 11:22:19 +00:00
|
|
|
/* Put our own clock-base on the buffer */
|
|
|
|
static void
|
2008-08-12 16:46:07 +00:00
|
|
|
gst_rtp_mux_readjust_rtp_timestamp (GstRTPMux * rtp_mux, GstPad * pad,
|
|
|
|
GstBuffer * buffer)
|
2007-03-28 11:22:19 +00:00
|
|
|
{
|
|
|
|
guint32 ts;
|
2008-08-12 16:46:07 +00:00
|
|
|
guint32 sink_ts_base = 0;
|
2009-07-21 19:31:33 +00:00
|
|
|
GstRTPMuxPadPrivate *padpriv;
|
|
|
|
|
2008-08-12 16:46:07 +00:00
|
|
|
|
2009-07-21 19:31:33 +00:00
|
|
|
GST_OBJECT_LOCK (rtp_mux);
|
|
|
|
padpriv = gst_pad_get_element_private (pad);
|
|
|
|
if (padpriv && padpriv->have_clock_base)
|
2008-08-12 16:46:07 +00:00
|
|
|
sink_ts_base = padpriv->clock_base;
|
2009-07-21 19:31:33 +00:00
|
|
|
GST_OBJECT_UNLOCK (rtp_mux);
|
2007-03-28 11:22:19 +00:00
|
|
|
|
|
|
|
ts = gst_rtp_buffer_get_timestamp (buffer) - sink_ts_base + rtp_mux->ts_base;
|
2008-08-12 16:48:02 +00:00
|
|
|
GST_LOG_OBJECT (rtp_mux, "Re-adjusting RTP ts %u to %u",
|
|
|
|
gst_rtp_buffer_get_timestamp (buffer), ts);
|
2007-03-28 11:22:19 +00:00
|
|
|
gst_rtp_buffer_set_timestamp (buffer, ts);
|
|
|
|
}
|
|
|
|
|
2007-03-07 08:53:07 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_rtp_mux_chain (GstPad * pad, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstRTPMux *rtp_mux;
|
2007-03-16 13:14:44 +00:00
|
|
|
GstFlowReturn ret;
|
2009-07-21 19:31:33 +00:00
|
|
|
GstRTPMuxPadPrivate *padpriv;
|
2008-08-12 16:23:32 +00:00
|
|
|
|
2007-03-07 08:53:07 +00:00
|
|
|
rtp_mux = GST_RTP_MUX (gst_pad_get_parent (pad));
|
2007-07-12 19:53:36 +00:00
|
|
|
|
2009-02-18 22:05:13 +00:00
|
|
|
if (!gst_rtp_buffer_validate (buffer)) {
|
|
|
|
GST_ERROR_OBJECT (rtp_mux, "Invalid RTP buffer");
|
|
|
|
gst_object_unref (rtp_mux);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-02-20 22:45:50 +00:00
|
|
|
buffer = gst_buffer_make_writable (buffer);
|
2007-07-12 19:53:36 +00:00
|
|
|
|
2009-02-18 23:14:52 +00:00
|
|
|
GST_OBJECT_LOCK (rtp_mux);
|
2007-03-21 12:31:49 +00:00
|
|
|
rtp_mux->seqnum++;
|
|
|
|
gst_rtp_buffer_set_seq (buffer, rtp_mux->seqnum);
|
2009-07-21 19:31:33 +00:00
|
|
|
padpriv = gst_pad_get_element_private (pad);
|
|
|
|
if (padpriv)
|
|
|
|
gst_buffer_set_caps (buffer, padpriv->out_caps);
|
2009-02-18 23:14:52 +00:00
|
|
|
GST_OBJECT_UNLOCK (rtp_mux);
|
2007-03-29 13:36:22 +00:00
|
|
|
gst_rtp_buffer_set_ssrc (buffer, rtp_mux->current_ssrc);
|
2008-08-12 16:46:07 +00:00
|
|
|
gst_rtp_mux_readjust_rtp_timestamp (rtp_mux, pad, buffer);
|
2008-08-12 16:48:02 +00:00
|
|
|
GST_LOG_OBJECT (rtp_mux, "Pushing packet size %d, seq=%d, ts=%u",
|
2009-02-18 18:32:56 +00:00
|
|
|
GST_BUFFER_SIZE (buffer), rtp_mux->seqnum,
|
|
|
|
gst_rtp_buffer_get_timestamp (buffer));
|
2007-03-07 08:53:07 +00:00
|
|
|
|
2009-07-21 19:31:33 +00:00
|
|
|
if (!padpriv) {
|
|
|
|
ret = GST_FLOW_NOT_LINKED;
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
goto out;
|
|
|
|
}
|
2008-08-12 16:46:23 +00:00
|
|
|
|
2007-03-21 12:31:49 +00:00
|
|
|
ret = gst_pad_push (rtp_mux->srcpad, buffer);
|
2008-08-12 16:23:32 +00:00
|
|
|
|
2009-07-21 19:31:33 +00:00
|
|
|
out:
|
|
|
|
|
2007-03-16 13:14:44 +00:00
|
|
|
gst_object_unref (rtp_mux);
|
|
|
|
return ret;
|
2007-03-07 08:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-20 22:45:50 +00:00
|
|
|
gst_rtp_mux_setcaps (GstPad * pad, GstCaps * caps)
|
2007-03-07 08:53:07 +00:00
|
|
|
{
|
2007-03-23 16:31:39 +00:00
|
|
|
GstRTPMux *rtp_mux;
|
2007-03-28 11:22:19 +00:00
|
|
|
GstStructure *structure;
|
2009-04-28 20:10:21 +00:00
|
|
|
gboolean ret = FALSE;
|
2009-07-21 19:31:33 +00:00
|
|
|
GstRTPMuxPadPrivate *padpriv;
|
2007-03-07 08:53:07 +00:00
|
|
|
|
|
|
|
rtp_mux = GST_RTP_MUX (gst_pad_get_parent (pad));
|
2007-08-23 21:22:25 +00:00
|
|
|
|
2007-03-28 11:22:19 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
2007-08-23 21:22:25 +00:00
|
|
|
|
2009-04-28 20:10:21 +00:00
|
|
|
if (!structure)
|
2008-08-12 01:03:22 +00:00
|
|
|
goto out;
|
|
|
|
|
2009-07-21 19:31:33 +00:00
|
|
|
GST_OBJECT_LOCK (rtp_mux);
|
|
|
|
padpriv = gst_pad_get_element_private (pad);
|
|
|
|
if (padpriv &&
|
|
|
|
gst_structure_get_uint (structure, "clock-base", &padpriv->clock_base)) {
|
2009-04-20 22:36:42 +00:00
|
|
|
padpriv->have_clock_base = TRUE;
|
2008-08-12 16:41:59 +00:00
|
|
|
}
|
2009-07-21 19:31:33 +00:00
|
|
|
GST_OBJECT_UNLOCK (rtp_mux);
|
2008-08-12 16:41:59 +00:00
|
|
|
|
2009-04-28 20:10:21 +00:00
|
|
|
caps = gst_caps_copy (caps);
|
2008-08-12 01:03:22 +00:00
|
|
|
|
|
|
|
gst_caps_set_simple (caps,
|
|
|
|
"clock-base", G_TYPE_UINT, rtp_mux->ts_base,
|
2009-02-20 22:45:50 +00:00
|
|
|
"seqnum-base", G_TYPE_UINT, rtp_mux->seqnum_base, NULL);
|
2008-08-12 01:03:22 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (rtp_mux,
|
2008-08-12 01:05:34 +00:00
|
|
|
"setting caps %" GST_PTR_FORMAT " on src pad..", caps);
|
2008-08-12 01:03:22 +00:00
|
|
|
ret = gst_pad_set_caps (rtp_mux->srcpad, caps);
|
2009-04-21 00:00:15 +00:00
|
|
|
|
2009-11-18 15:38:33 +00:00
|
|
|
if (rtp_mux->ssrc == -1) {
|
|
|
|
if (gst_structure_has_field_typed (structure, "ssrc", G_TYPE_UINT)) {
|
|
|
|
rtp_mux->current_ssrc = g_value_get_uint
|
|
|
|
(gst_structure_get_value (structure, "ssrc"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-21 19:31:33 +00:00
|
|
|
if (ret) {
|
|
|
|
GST_OBJECT_LOCK (rtp_mux);
|
|
|
|
padpriv = gst_pad_get_element_private (pad);
|
|
|
|
if (padpriv)
|
|
|
|
gst_caps_replace (&padpriv->out_caps, caps);
|
|
|
|
GST_OBJECT_UNLOCK (rtp_mux);
|
|
|
|
}
|
2009-04-28 19:58:41 +00:00
|
|
|
gst_caps_unref (caps);
|
2007-03-07 08:53:07 +00:00
|
|
|
|
2009-02-20 22:45:50 +00:00
|
|
|
out:
|
2007-06-07 12:01:21 +00:00
|
|
|
gst_object_unref (rtp_mux);
|
|
|
|
|
2007-03-23 16:31:39 +00:00
|
|
|
return ret;
|
2007-03-07 08:53:07 +00:00
|
|
|
}
|
|
|
|
|
2009-02-18 20:20:58 +00:00
|
|
|
static void
|
2009-02-20 22:45:50 +00:00
|
|
|
clear_caps (GstCaps * caps, gboolean only_clock_rate)
|
2009-02-18 20:20:58 +00:00
|
|
|
{
|
|
|
|
gint i, j;
|
|
|
|
|
|
|
|
/* Lets only match on the clock-rate */
|
|
|
|
for (i = 0; i < gst_caps_get_size (caps); i++) {
|
|
|
|
GstStructure *s = gst_caps_get_structure (caps, i);
|
|
|
|
|
|
|
|
for (j = 0; j < gst_structure_n_fields (s); j++) {
|
|
|
|
const gchar *name = gst_structure_nth_field_name (s, j);
|
|
|
|
|
2009-02-19 01:18:46 +00:00
|
|
|
if (strcmp (name, "clock-rate") && (only_clock_rate ||
|
|
|
|
(strcmp (name, "ssrc")))) {
|
2009-02-18 20:20:58 +00:00
|
|
|
gst_structure_remove_field (s, name);
|
|
|
|
j--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-02-20 22:45:50 +00:00
|
|
|
same_clock_rate_fold (gpointer item, GValue * ret, gpointer user_data)
|
2009-02-18 20:20:58 +00:00
|
|
|
{
|
|
|
|
GstPad *mypad = user_data;
|
|
|
|
GstPad *pad = item;
|
|
|
|
GstCaps *peercaps;
|
|
|
|
GstCaps *othercaps;
|
|
|
|
const GstCaps *accumcaps;
|
|
|
|
GstCaps *intersect;
|
|
|
|
|
2009-04-28 20:03:19 +00:00
|
|
|
if (pad == mypad) {
|
|
|
|
gst_object_unref (pad);
|
2009-02-18 20:20:58 +00:00
|
|
|
return TRUE;
|
2009-04-28 20:03:19 +00:00
|
|
|
}
|
2009-02-18 20:20:58 +00:00
|
|
|
|
|
|
|
peercaps = gst_pad_peer_get_caps (pad);
|
2009-04-28 20:03:19 +00:00
|
|
|
if (!peercaps) {
|
|
|
|
gst_object_unref (pad);
|
2009-02-18 20:20:58 +00:00
|
|
|
return TRUE;
|
2009-04-28 20:03:19 +00:00
|
|
|
}
|
2009-02-18 20:20:58 +00:00
|
|
|
|
|
|
|
othercaps = gst_caps_intersect (peercaps,
|
|
|
|
gst_pad_get_pad_template_caps (pad));
|
|
|
|
gst_caps_unref (peercaps);
|
|
|
|
|
|
|
|
accumcaps = gst_value_get_caps (ret);
|
|
|
|
|
2009-02-19 01:18:46 +00:00
|
|
|
clear_caps (othercaps, TRUE);
|
2009-02-18 20:20:58 +00:00
|
|
|
|
|
|
|
intersect = gst_caps_intersect (accumcaps, othercaps);
|
|
|
|
|
|
|
|
g_value_take_boxed (ret, intersect);
|
|
|
|
|
|
|
|
gst_caps_unref (othercaps);
|
2009-04-28 20:03:19 +00:00
|
|
|
gst_object_unref (pad);
|
2009-02-18 20:20:58 +00:00
|
|
|
|
|
|
|
return !gst_caps_is_empty (intersect);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
2009-02-20 22:45:50 +00:00
|
|
|
gst_rtp_mux_getcaps (GstPad * pad)
|
2009-02-18 20:20:58 +00:00
|
|
|
{
|
|
|
|
GstRTPMux *mux = GST_RTP_MUX (gst_pad_get_parent (pad));
|
|
|
|
GstCaps *caps = NULL;
|
|
|
|
GstIterator *iter = NULL;
|
2009-02-20 22:45:50 +00:00
|
|
|
GValue v = { 0 };
|
2009-02-18 20:20:58 +00:00
|
|
|
GstIteratorResult res;
|
|
|
|
GstCaps *peercaps = gst_pad_peer_get_caps (mux->srcpad);
|
2009-02-20 22:45:50 +00:00
|
|
|
GstCaps *othercaps = NULL;
|
2009-02-18 20:20:58 +00:00
|
|
|
|
|
|
|
if (peercaps) {
|
|
|
|
othercaps = gst_caps_intersect (peercaps,
|
|
|
|
gst_pad_get_pad_template_caps (pad));
|
|
|
|
gst_caps_unref (peercaps);
|
2009-02-20 22:45:50 +00:00
|
|
|
} else {
|
2009-02-18 20:20:58 +00:00
|
|
|
othercaps = gst_caps_copy (gst_pad_get_pad_template_caps (mux->srcpad));
|
|
|
|
}
|
|
|
|
|
2009-02-19 01:18:46 +00:00
|
|
|
clear_caps (othercaps, FALSE);
|
2009-02-18 20:20:58 +00:00
|
|
|
|
|
|
|
g_value_init (&v, GST_TYPE_CAPS);
|
|
|
|
|
|
|
|
iter = gst_element_iterate_sink_pads (GST_ELEMENT (mux));
|
|
|
|
do {
|
|
|
|
gst_value_set_caps (&v, othercaps);
|
|
|
|
res = gst_iterator_fold (iter, same_clock_rate_fold, &v, pad);
|
|
|
|
} while (res == GST_ITERATOR_RESYNC);
|
|
|
|
gst_iterator_free (iter);
|
|
|
|
|
2009-02-20 22:45:50 +00:00
|
|
|
caps = (GstCaps *) gst_value_get_caps (&v);
|
2009-02-18 20:20:58 +00:00
|
|
|
|
|
|
|
if (res == GST_ITERATOR_ERROR) {
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
caps = gst_caps_new_empty ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (othercaps)
|
|
|
|
gst_caps_unref (othercaps);
|
|
|
|
gst_object_unref (mux);
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-07 08:53:07 +00:00
|
|
|
static void
|
|
|
|
gst_rtp_mux_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstRTPMux *rtp_mux;
|
|
|
|
|
|
|
|
rtp_mux = GST_RTP_MUX (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2007-03-28 11:22:19 +00:00
|
|
|
case PROP_TIMESTAMP_OFFSET:
|
2007-03-29 13:52:50 +00:00
|
|
|
g_value_set_int (value, rtp_mux->ts_offset);
|
2007-03-28 11:22:19 +00:00
|
|
|
break;
|
2007-03-07 08:53:07 +00:00
|
|
|
case PROP_SEQNUM_OFFSET:
|
|
|
|
g_value_set_int (value, rtp_mux->seqnum_offset);
|
|
|
|
break;
|
|
|
|
case PROP_SEQNUM:
|
2009-02-18 23:14:52 +00:00
|
|
|
GST_OBJECT_LOCK (rtp_mux);
|
2007-03-07 08:53:07 +00:00
|
|
|
g_value_set_uint (value, rtp_mux->seqnum);
|
2009-02-18 23:14:52 +00:00
|
|
|
GST_OBJECT_UNLOCK (rtp_mux);
|
2007-03-07 08:53:07 +00:00
|
|
|
break;
|
2007-03-29 13:36:22 +00:00
|
|
|
case PROP_SSRC:
|
|
|
|
g_value_set_uint (value, rtp_mux->ssrc);
|
|
|
|
break;
|
2007-03-07 08:53:07 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_mux_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstRTPMux *rtp_mux;
|
|
|
|
|
|
|
|
rtp_mux = GST_RTP_MUX (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2007-03-28 11:22:19 +00:00
|
|
|
case PROP_TIMESTAMP_OFFSET:
|
|
|
|
rtp_mux->ts_offset = g_value_get_int (value);
|
|
|
|
break;
|
2007-03-07 08:53:07 +00:00
|
|
|
case PROP_SEQNUM_OFFSET:
|
|
|
|
rtp_mux->seqnum_offset = g_value_get_int (value);
|
|
|
|
break;
|
2007-03-29 13:36:22 +00:00
|
|
|
case PROP_SSRC:
|
|
|
|
rtp_mux->ssrc = g_value_get_uint (value);
|
|
|
|
break;
|
2007-03-07 08:53:07 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-12 16:23:32 +00:00
|
|
|
static void
|
2007-03-29 13:52:23 +00:00
|
|
|
gst_rtp_mux_ready_to_paused (GstRTPMux * rtp_mux)
|
|
|
|
{
|
2009-02-18 23:14:52 +00:00
|
|
|
GST_OBJECT_LOCK (rtp_mux);
|
|
|
|
|
2007-03-29 13:52:23 +00:00
|
|
|
if (rtp_mux->ssrc == -1)
|
|
|
|
rtp_mux->current_ssrc = g_random_int ();
|
|
|
|
else
|
|
|
|
rtp_mux->current_ssrc = rtp_mux->ssrc;
|
|
|
|
|
|
|
|
if (rtp_mux->seqnum_offset == -1)
|
|
|
|
rtp_mux->seqnum_base = g_random_int_range (0, G_MAXUINT16);
|
|
|
|
else
|
|
|
|
rtp_mux->seqnum_base = rtp_mux->seqnum_offset;
|
2008-08-12 01:20:06 +00:00
|
|
|
rtp_mux->seqnum = rtp_mux->seqnum_base;
|
2008-08-12 16:23:32 +00:00
|
|
|
|
2007-03-29 13:52:23 +00:00
|
|
|
if (rtp_mux->ts_offset == -1)
|
|
|
|
rtp_mux->ts_base = g_random_int ();
|
|
|
|
else
|
|
|
|
rtp_mux->ts_base = rtp_mux->ts_offset;
|
2009-02-20 22:45:50 +00:00
|
|
|
GST_DEBUG_OBJECT (rtp_mux, "set clock-base to %u", rtp_mux->ts_base);
|
2009-02-18 23:14:52 +00:00
|
|
|
|
|
|
|
GST_OBJECT_UNLOCK (rtp_mux);
|
2007-03-29 13:52:23 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 08:53:07 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_rtp_mux_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstRTPMux *rtp_mux;
|
|
|
|
|
|
|
|
rtp_mux = GST_RTP_MUX (element);
|
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2007-03-29 13:52:23 +00:00
|
|
|
gst_rtp_mux_ready_to_paused (rtp_mux);
|
2007-03-07 08:53:07 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-03-29 13:52:23 +00:00
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
2007-03-07 08:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_rtp_mux_plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
2009-02-20 22:45:50 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_rtp_mux_debug, "rtpmux", 0, "rtp muxer");
|
2007-03-07 08:53:07 +00:00
|
|
|
|
|
|
|
return gst_element_register (plugin, "rtpmux", GST_RANK_NONE,
|
|
|
|
GST_TYPE_RTP_MUX);
|
|
|
|
}
|