Commit dc0610fa authored by Philippe Khalaf's avatar Philippe Khalaf
Browse files

gst-libs/gst/rtp gst-libs/gst/rtp/gstbasertpdepayload.c...

gst-libs/gst/rtp gst-libs/gst/rtp/gstbasertpdepayload.c gst-libs/gst/rtp/gstbasertpdepayload.h gst-libs/gst/rtp/gstrt...

Original commit message from CVS:
* gst-libs/gst/rtp
* gst-libs/gst/rtp/gstbasertpdepayload.c
* gst-libs/gst/rtp/gstbasertpdepayload.h
* gst-libs/gst/rtp/gstrtpbuffer.c
* gst-libs/gst/rtp/gstrtpbuffer.h
* gst-libs/gst/rtp/Makefile.am
* gst-libs/gst/rtp/README

Support libs for RTP. Basicaly this add a GstRTPBuffer (extended GstBuffer) and
a Depayloader Base class that shall be used by payload specific depayloaders.
parent d143d256
......@@ -918,6 +918,7 @@ gst-libs/gst/gconf/Makefile
gst-libs/gst/interfaces/Makefile
gst-libs/gst/net/Makefile
gst-libs/gst/riff/Makefile
gst-libs/gst/rtp/Makefile
gst-libs/gst/tag/Makefile
gst-libs/gst/video/Makefile
gst-libs/ext/Makefile
......
......@@ -11,6 +11,7 @@ SUBDIRS = \
interfaces \
net \
riff \
rtp \
tag \
video
......@@ -21,6 +22,7 @@ DIST_SUBDIRS = \
interfaces \
net \
riff \
rtp \
tag \
video
......
libgstrtpincludedir = $(includedir)/gstreamer-@GST_MAJORMINOR@/gst/rtp
libgstrtpinclude_HEADERS = gstrtpbuffer.h gstbasertpdepayload.h
lib_LTLIBRARIES = libgstrtp-@GST_MAJORMINOR@.la
libgstrtp_@GST_MAJORMINOR@_la_SOURCES = gstrtpbuffer.c gstbasertpdepayload.c
libgstrtp_@GST_MAJORMINOR@_la_CFLAGS = $(GST_CFLAGS) -I$(top_srcdir)/gst/tags
libgstrtp_@GST_MAJORMINOR@_la_LIBADD = $(GST_LIBS)
The RTP libraries
---------------------
GstRTPBuffer:
A GstBuffer subclass that can has extra RTP information such as timestamps and
marks. It is used for communications between the RTPSession element and the
RTP payloaders/depayloaders.
/* GStreamer
* Copyright (C) <2005> Philippe Khalaf <burger@speedy.org>
*
* 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.
*/
#include "gstbasertpdepayload.h"
GST_DEBUG_CATEGORY (basertpdepayload_debug);
#define GST_CAT_DEFAULT (basertpdepayload_debug)
/* Filter signals and args */
enum
{
/* FILL ME */
LAST_SIGNAL
};
enum
{
ARG_0,
ARG_PROCESS_ONLY,
ARG_QUEUEDELAY,
};
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("application/x-rtp-noheader")
);
/*static GstStaticPadTemplate src_factory =
GST_STATIC_PAD_TEMPLATE (
"src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
// GST_STATIC_CAPS ("video/x-h263")
GST_STATIC_CAPS("ANY")
);*/
static GstElementClass *parent_class = NULL;
static void gst_base_rtp_depayload_base_init (GstBaseRTPDepayloadClass * klass);
static void gst_base_rtp_depayload_class_init (GstBaseRTPDepayloadClass *
klass);
static void gst_base_rtp_depayload_init (GstBaseRTPDepayload * filter,
gpointer g_class);
GType
gst_base_rtp_depayload_get_type (void)
{
static GType plugin_type = 0;
if (!plugin_type) {
static const GTypeInfo plugin_info = {
sizeof (GstBaseRTPDepayloadClass),
(GBaseInitFunc) gst_base_rtp_depayload_base_init,
NULL,
(GClassInitFunc) gst_base_rtp_depayload_class_init,
NULL,
NULL,
sizeof (GstBaseRTPDepayload),
0,
(GInstanceInitFunc) gst_base_rtp_depayload_init,
};
plugin_type = g_type_register_static (GST_TYPE_ELEMENT,
"GstBaseRTPDepayload", &plugin_info, 0);
}
return plugin_type;
}
//static GstElementStateReturn gst_base_rtp_depayload_change_state (GstElement * element);
static void gst_base_rtp_depayload_finalize (GObject * object);
static void gst_base_rtp_depayload_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_base_rtp_depayload_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
static gboolean gst_base_rtp_depayload_setcaps (GstPad * pad, GstCaps * caps);
static GstFlowReturn gst_base_rtp_depayload_chain (GstPad * pad,
GstBuffer * in);
static GstFlowReturn gst_base_rtp_depayload_add_to_queue (GstBaseRTPDepayload *
filter, GstRTPBuffer * in);
static GstBuffer *gst_base_rtp_depayload_set_gst_timestamp (GstRTPBuffer * in);
static void
gst_base_rtp_depayload_base_init (GstBaseRTPDepayloadClass * klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&sink_factory));
}
static void
gst_base_rtp_depayload_class_init (GstBaseRTPDepayloadClass * klass)
{
GObjectClass *gobject_class;
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->set_property = gst_base_rtp_depayload_set_property;
gobject_class->get_property = gst_base_rtp_depayload_get_property;
g_object_class_install_property (gobject_class, ARG_QUEUEDELAY,
g_param_spec_uint ("queue_delay", "Queue Delay",
"Amount of ms to queue/buffer", 0, G_MAXUINT, 0, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, ARG_PROCESS_ONLY,
g_param_spec_boolean ("process_only", "Process Only",
"Directly send packets to processing", FALSE, G_PARAM_READWRITE));
gobject_class->finalize = gst_base_rtp_depayload_finalize;
klass->add_to_queue = gst_base_rtp_depayload_add_to_queue;
klass->setgsttimestamp = gst_base_rtp_depayload_set_gst_timestamp;
GST_DEBUG_CATEGORY_INIT (basertpdepayload_debug, "basertpdepayload", 0,
"Base class for RTP Depayloaders");
}
static void
gst_base_rtp_depayload_init (GstBaseRTPDepayload * filter, gpointer g_class)
{
GstPadTemplate *pad_template;
GST_DEBUG ("gst_base_rtp_depayload_init");
pad_template =
gst_element_class_get_pad_template (GST_ELEMENT_CLASS (g_class), "sink");
g_return_if_fail (pad_template != NULL);
filter->sinkpad = gst_pad_new_from_template (pad_template, "sink");
gst_pad_set_setcaps_function (filter->sinkpad,
gst_base_rtp_depayload_setcaps);
gst_pad_set_chain_function (filter->sinkpad, gst_base_rtp_depayload_chain);
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
pad_template =
gst_element_class_get_pad_template (GST_ELEMENT_CLASS (g_class), "src");
g_return_if_fail (pad_template != NULL);
filter->srcpad = gst_pad_new_from_template (pad_template, "src");
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
// create out queue
filter->queue = g_queue_new ();
filter->queue_delay = RTP_QUEUEDELAY;
// this one needs to be overwritten by child
filter->clock_rate = 0;
}
static void
gst_base_rtp_depayload_finalize (GObject * object)
{
// free our queue
g_queue_free (GST_BASE_RTP_DEPAYLOAD (object)->queue);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static gboolean
gst_base_rtp_depayload_setcaps (GstPad * pad, GstCaps * caps)
{
GstBaseRTPDepayload *filter;
// GstStructure *structure;
// int ret;
filter = GST_BASE_RTP_DEPAYLOAD (gst_pad_get_parent (pad));
g_return_val_if_fail (filter != NULL, FALSE);
g_return_val_if_fail (GST_IS_BASE_RTP_DEPAYLOAD (filter), FALSE);
/*
structure = gst_caps_get_structure( caps, 0 );
ret = gst_structure_get_int( structure, "clock_rate", &filter->clock_rate );
if (!ret) {
return FALSE;
}
*/
GstBaseRTPDepayloadClass *bclass = GST_BASE_RTP_DEPAYLOAD_GET_CLASS (filter);
if (bclass->set_caps)
return bclass->set_caps (filter, caps);
else
return TRUE;
}
static GstFlowReturn
gst_base_rtp_depayload_chain (GstPad * pad, GstBuffer * in)
{
GstBaseRTPDepayload *filter;
GstFlowReturn ret = GST_FLOW_OK;
g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
g_return_val_if_fail (GST_BUFFER (in) != NULL, GST_FLOW_ERROR);
filter = GST_BASE_RTP_DEPAYLOAD (GST_OBJECT_PARENT (pad));
g_return_val_if_fail (GST_IS_BASE_RTP_DEPAYLOAD (filter), GST_FLOW_ERROR);
g_return_val_if_fail (filter->clock_rate > 0, GST_FLOW_ERROR);
// must supply RTPBuffers here
g_return_val_if_fail (GST_IS_RTPBUFFER (in), GST_FLOW_ERROR);
GstBaseRTPDepayloadClass *bclass = GST_BASE_RTP_DEPAYLOAD_GET_CLASS (filter);
if (filter->process_only) {
bclass->process (filter, GST_RTPBUFFER (in));
} else {
if (bclass->add_to_queue)
ret = bclass->add_to_queue (filter, GST_RTPBUFFER (in));
}
return ret;
}
static GstFlowReturn
gst_base_rtp_depayload_add_to_queue (GstBaseRTPDepayload * filter,
GstRTPBuffer * in)
{
GQueue *queue = filter->queue;
// our first packet, just push it
if (g_queue_is_empty (queue)) {
g_queue_push_tail (queue, in);
} else
// not our first packet
{
// let us make sure it is not very late
if (in->seqnum < GST_RTPBUFFER (g_queue_peek_head (queue))->seqnum) {
// we need to drop this one
GST_DEBUG ("Packet arrived to late, dropping");
return GST_FLOW_OK;
}
// look for right place to insert it
int i = 0;
while (in->seqnum < GST_RTPBUFFER (g_queue_peek_nth (queue, i))->seqnum)
i++;
// now insert it at that place
g_queue_push_nth (queue, in, i);
GST_DEBUG ("Packet added to queue %d at pos %d timestamp %d sn %d",
g_queue_get_length (queue), i, in->timestamp, in->seqnum);
// if our queue is getting to big (more than RTP_QUEUEDELAY ms of data)
// release heading buffers
GST_DEBUG ("clockrate %d, queu_delay %d", filter->clock_rate,
filter->queue_delay);
gfloat q_size_secs = (gfloat) filter->queue_delay / 1000;
guint maxtsunits = (gfloat) filter->clock_rate * q_size_secs;
GST_DEBUG ("maxtsunit is %d", maxtsunits);
GST_DEBUG ("ts %d %d %d %d", in->timestamp, in->seqnum,
GST_RTPBUFFER (g_queue_peek_tail (queue))->timestamp,
GST_RTPBUFFER (g_queue_peek_tail (queue))->seqnum);
while (GST_RTPBUFFER (g_queue_peek_tail (queue))->timestamp -
in->timestamp > maxtsunits) {
GST_DEBUG ("Poping packet from queue");
GstBaseRTPDepayloadClass *bclass =
GST_BASE_RTP_DEPAYLOAD_GET_CLASS (filter);
if (bclass->process)
bclass->process (filter, GST_RTPBUFFER (g_queue_pop_tail (queue)));
}
}
return GST_FLOW_OK;
}
static GstBuffer *
gst_base_rtp_depayload_set_gst_timestamp (GstRTPBuffer * in)
{
return NULL;
}
static void
gst_base_rtp_depayload_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstBaseRTPDepayload *filter;
g_return_if_fail (GST_IS_BASE_RTP_DEPAYLOAD (object));
filter = GST_BASE_RTP_DEPAYLOAD (object);
switch (prop_id) {
case ARG_QUEUEDELAY:
filter->queue_delay = g_value_get_uint (value);
break;
case ARG_PROCESS_ONLY:
filter->process_only = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_base_rtp_depayload_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstBaseRTPDepayload *filter;
g_return_if_fail (GST_IS_BASE_RTP_DEPAYLOAD (object));
filter = GST_BASE_RTP_DEPAYLOAD (object);
switch (prop_id) {
case ARG_QUEUEDELAY:
g_value_set_uint (value, filter->queue_delay);
break;
case ARG_PROCESS_ONLY:
g_value_set_boolean (value, filter->process_only);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/* GStreamer
* Copyright (C) <2005> Philippe Khalaf <burger@speedy.org>
*
* 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.
*/
#ifndef __GST_BASE_RTP_DEPAYLOAD_H__
#define __GST_BASE_RTP_DEPAYLOAD_H__
#include <gst/gst.h>
#include <gst/rtp/gstrtpbuffer.h>
G_BEGIN_DECLS
/* #define's don't like whitespacey bits */
#define GST_TYPE_BASE_RTP_DEPAYLOAD (gst_base_rtp_depayload_get_type())
#define GST_BASE_RTP_DEPAYLOAD(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_RTP_DEPAYLOAD,GstBaseRTPDepayload))
#define GST_BASE_RTP_DEPAYLOAD_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_RTP_DEPAYLOAD,GstBaseRTPDepayload))
#define GST_BASE_RTP_DEPAYLOAD_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_BASE_RTP_DEPAYLOAD,GstBaseRTPDepayloadClass))
#define GST_IS_BASE_RTP_DEPAYLOAD(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_RTP_DEPAYLOAD))
#define GST_IS_BASE_RTP_DEPAYLOAD_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_RTP_DEPAYLOAD))
// in milliseconds
#define RTP_QUEUEDELAY 100;
typedef struct _GstBaseRTPDepayload GstBaseRTPDepayload;
typedef struct _GstBaseRTPDepayloadClass GstBaseRTPDepayloadClass;
struct _GstBaseRTPDepayload
{
GstElement parent;
GstPad *sinkpad, *srcpad;
// this attribute must be set by the child
guint clock_rate;
// this value can be modified by the child if needed
guint queue_delay;
gboolean process_only;
// we will queue up to RTP_QUEUEDELAY ms of packets,
// reordering them if necessary
// dropping any packets that are more than
// RTP_QUEUEDELAY ms late
GQueue *queue;
};
struct _GstBaseRTPDepayloadClass
{
GstElementClass parent_class;
// virtuals
gboolean (*set_caps) (GstBaseRTPDepayload *filter, GstCaps *caps);
// non-pure function, default implementation in base class
// this does buffering, reordering and dropping
GstFlowReturn (*add_to_queue) (GstBaseRTPDepayload *filter, GstRTPBuffer *in);
// pure virtual function, child must use this to process incoming
// rtp packets
GstFlowReturn (*process) (GstBaseRTPDepayload *base, GstRTPBuffer *in);
// non-pure function used to convert from RTP timestamp to GST timestamp
// this function is used by the child class before gst_pad_pushing
GstBuffer* (*setgsttimestamp) (GstRTPBuffer *in);
};
GType gst_base_rtp_depayload_get_type (void);
G_END_DECLS
#endif /* __GST_BASE_RTP_DEPAYLOAD_H__ */
/* GStreamer
* Copyright (C) <2005> Philippe Khalaf <burger@speedy.org>
*
* 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.
*/
#include "gstrtpbuffer.h"
static void gst_rtpbuffer_init (GTypeInstance * instance, gpointer g_class);
static void gst_rtpbuffer_class_init (gpointer g_class, gpointer class_data);
static void gst_rtpbuffer_finalize (GstRTPBuffer * nbuf);
static GstRTPBuffer *gst_rtpbuffer_copy (GstRTPBuffer * nbuf);
static GstBufferClass *parent_class;
GType
gst_rtpbuffer_get_type (void)
{
static GType _gst_rtpbuffer_type = 0;
if (G_UNLIKELY (_gst_rtpbuffer_type == 0)) {
static const GTypeInfo rtpbuffer_info = {
sizeof (GstRTPBufferClass),
NULL,
NULL,
gst_rtpbuffer_class_init,
NULL,
NULL,
sizeof (GstRTPBuffer),
0,
gst_rtpbuffer_init,
NULL
};
_gst_rtpbuffer_type = g_type_register_static (GST_TYPE_BUFFER,
"GstRTPBuffer", &rtpbuffer_info, 0);
}
return _gst_rtpbuffer_type;
}
static void
gst_rtpbuffer_class_init (gpointer g_class, gpointer class_data)
{
GstMiniObjectClass *mo_class = GST_MINI_OBJECT_CLASS (g_class);
parent_class = g_type_class_ref (GST_TYPE_BUFFER);
mo_class->copy = (GstMiniObjectCopyFunction) gst_rtpbuffer_copy;
mo_class->finalize = (GstMiniObjectFinalizeFunction) gst_rtpbuffer_finalize;
}
static void
gst_rtpbuffer_init (GTypeInstance * instance, gpointer g_class)
{
}
static void
gst_rtpbuffer_finalize (GstRTPBuffer * nbuf)
{
GST_MINI_OBJECT_CLASS (parent_class)->finalize (GST_MINI_OBJECT (nbuf));
}
static GstRTPBuffer *
gst_rtpbuffer_copy (GstRTPBuffer * nbuf)
{
GstRTPBuffer *copy;
copy =
(GstRTPBuffer *) GST_MINI_OBJECT_CLASS (parent_class)->
copy (GST_MINI_OBJECT (nbuf));
copy->pt = nbuf->pt;
copy->seqnum = nbuf->seqnum;
copy->timestamp = nbuf->timestamp;
copy->timestampinc = nbuf->timestampinc;
copy->mark = nbuf->mark;
return copy;
}
GstRTPBuffer *
gst_rtpbuffer_new (void)
{
GstRTPBuffer *buf;
buf = (GstRTPBuffer *) gst_mini_object_new (GST_TYPE_RTPBUFFER);
return buf;
}
/* GStreamer
* Copyright (C) <2005> Philippe Khalaf <burger@speedy.org>
*
* 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.
*/
#ifndef __GST_RTPBUFFER_H__
#define __GST_RTPBUFFER_H__
#include <gst/gst.h>
G_BEGIN_DECLS
typedef struct _GstRTPBuffer GstRTPBuffer;
typedef struct _GstRTPBufferClass GstRTPBufferClass;
#define GST_TYPE_RTPBUFFER (gst_rtpbuffer_get_type())
#define GST_IS_RTPBUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_RTPBUFFER))
#define GST_IS_RTPBUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_RTPBUFFER))
#define GST_RTPBUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTPBUFFER, GstRTPBufferClass))
#define GST_RTPBUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_RTPBUFFER, GstRTPBuffer))
#define GST_RTPBUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_RTPBUFFER, GstRTPBufferClass))
/* buffer for use rtp packets
*
* It contains the payload type, timestamp, timestamp increment
* and mark of the rtp packet
*/
struct _GstRTPBuffer {