summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog21
-rw-r--r--gst/rtp/Makefile.am4
-rw-r--r--gst/rtp/gstasteriskh263.c306
-rw-r--r--gst/rtp/gstasteriskh263.h64
-rw-r--r--gst/rtp/gstrtp.c8
-rw-r--r--gst/rtp/gstrtph263enc.c380
-rw-r--r--gst/rtp/gstrtph263enc.h60
-rw-r--r--gst/rtp/gstrtph263pay.c380
-rw-r--r--gst/rtp/gstrtph263pay.h60
9 files changed, 1283 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 0d60da63..aa75d21c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2005-10-24 Wim Taymans <wim@fluendo.com>
+
+ * gst/rtp/Makefile.am:
+ * gst/rtp/gstasteriskh263.c: (gst_asteriskh263_get_type),
+ (gst_asteriskh263_base_init), (gst_asteriskh263_class_init),
+ (gst_asteriskh263_init), (gst_asteriskh263_finalize),
+ (gst_asteriskh263_chain), (gst_asteriskh263_set_property),
+ (gst_asteriskh263_get_property), (gst_asteriskh263_change_state),
+ (gst_asteriskh263_plugin_init):
+ * gst/rtp/gstasteriskh263.h:
+ * gst/rtp/gstrtp.c: (plugin_init):
+ * gst/rtp/gstrtph263enc.c: (gst_rtph263enc_get_type),
+ (gst_rtph263enc_base_init), (gst_rtph263enc_class_init),
+ (gst_rtph263enc_init), (gst_rtph263enc_finalize),
+ (gst_rtph263enc_setcaps), (gst_rtph263enc_gobfiner),
+ (gst_rtph263enc_flush), (gst_rtph263enc_handle_buffer),
+ (gst_rtph263enc_plugin_init):
+ * gst/rtp/gstrtph263enc.h:
+ Added two new payloaders, an RFC 2190 payloader for h263 and
+ a payload convertor for an asterisk server.
+
2005-10-24 Tim-Philipp Müller <tim at centricular dot net>
* sys/oss/gstosssrc.c: (gst_oss_src_prepare):
diff --git a/gst/rtp/Makefile.am b/gst/rtp/Makefile.am
index 533842e7..e80c7f66 100644
--- a/gst/rtp/Makefile.am
+++ b/gst/rtp/Makefile.am
@@ -10,6 +10,8 @@ libgstrtp_la_SOURCES = gstrtp.c \
gstrtpamrenc.c \
gstrtph263pdec.c \
gstrtph263penc.c \
+ gstrtph263enc.c \
+ gstasteriskh263.c \
gstrtpmp4venc.c \
gstrtpmp4vdec.c
@@ -30,6 +32,8 @@ noinst_HEADERS = gstrtpL16enc.h \
gstrtpmpaenc.h \
gstrtph263pdec.h \
gstrtph263penc.h \
+ gstrtph263enc.c \
+ gstasteriskh263.c \
gstrtpmp4venc.h \
gstrtpmp4vdec.h \
gstrtpdec.h
diff --git a/gst/rtp/gstasteriskh263.c b/gst/rtp/gstasteriskh263.c
new file mode 100644
index 00000000..2c27e15e
--- /dev/null
+++ b/gst/rtp/gstasteriskh263.c
@@ -0,0 +1,306 @@
+/* GStreamer
+ * Copyright (C) <2005> Wim Taymans <wim@fluendo.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
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <string.h>
+#include <netinet/in.h>
+
+#include <gst/rtp/gstrtpbuffer.h>
+#include "gstasteriskh263.h"
+
+#define GST_ASTERISKH263_HEADER_LEN 6
+
+typedef struct _GstAsteriskH263Header
+{
+ guint32 timestamp; /* Timestamp */
+ guint16 length; /* Length */
+} GstAsteriskH263Header;
+
+#define GST_ASTERISKH263_HEADER_TIMESTAMP(buf) (((GstAsteriskH263Header *)(GST_BUFFER_DATA (buf)))->timestamp)
+#define GST_ASTERISKH263_HEADER_LENGTH(buf) (((GstAsteriskH263Header *)(GST_BUFFER_DATA (buf)))->length)
+
+/* elementfactory information */
+static GstElementDetails gst_rtp_h263pdec_details = {
+ "RTP packet parser",
+ "Codec/Parser/Network",
+ "Extracts H263 video from RTP and encodes in Asterisk H263 format",
+ "Neil Stratford <neils@vipadia.com>"
+};
+
+/* Asteriskh263 signals and args */
+enum
+{
+ /* FILL ME */
+ LAST_SIGNAL
+};
+
+enum
+{
+ ARG_0,
+ ARG_FREQUENCY
+};
+
+static GstStaticPadTemplate gst_asteriskh263_src_template =
+GST_STATIC_PAD_TEMPLATE ("src",
+ GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("application/x-asteriskh263")
+ );
+
+static GstStaticPadTemplate gst_asteriskh263_sink_template =
+GST_STATIC_PAD_TEMPLATE ("sink",
+ GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("application/x-rtp, "
+ "media = (string) \"video\", "
+ "payload = (int) [ 96, 255 ], "
+ "clock-rate = (int) 90000, " "encoding-name = (string) \"H263-1998\"")
+ );
+
+static void gst_asteriskh263_class_init (GstAsteriskh263Class * klass);
+static void gst_asteriskh263_base_init (GstAsteriskh263Class * klass);
+static void gst_asteriskh263_init (GstAsteriskh263 * asteriskh263);
+static void gst_asteriskh263_finalize (GObject * object);
+
+static GstFlowReturn gst_asteriskh263_chain (GstPad * pad, GstBuffer * buffer);
+
+static void gst_asteriskh263_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec);
+static void gst_asteriskh263_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec);
+
+static GstStateChangeReturn gst_asteriskh263_change_state (GstElement *
+ element, GstStateChange transition);
+
+static GstElementClass *parent_class = NULL;
+
+static GType
+gst_asteriskh263_get_type (void)
+{
+ static GType asteriskh263_type = 0;
+
+ if (!asteriskh263_type) {
+ static const GTypeInfo asteriskh263_info = {
+ sizeof (GstAsteriskh263Class),
+ (GBaseInitFunc) gst_asteriskh263_base_init,
+ NULL,
+ (GClassInitFunc) gst_asteriskh263_class_init,
+ NULL,
+ NULL,
+ sizeof (GstAsteriskh263),
+ 0,
+ (GInstanceInitFunc) gst_asteriskh263_init,
+ };
+
+ asteriskh263_type =
+ g_type_register_static (GST_TYPE_ELEMENT, "GstAsteriskh263",
+ &asteriskh263_info, 0);
+ }
+ return asteriskh263_type;
+}
+
+static void
+gst_asteriskh263_base_init (GstAsteriskh263Class * klass)
+{
+ GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
+
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&gst_asteriskh263_src_template));
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&gst_asteriskh263_sink_template));
+
+ gst_element_class_set_details (element_class, &gst_rtp_h263pdec_details);
+}
+
+static void
+gst_asteriskh263_class_init (GstAsteriskh263Class * klass)
+{
+ GObjectClass *gobject_class;
+ GstElementClass *gstelement_class;
+
+ gobject_class = (GObjectClass *) klass;
+ gstelement_class = (GstElementClass *) klass;
+
+ parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
+
+ gobject_class->finalize = gst_asteriskh263_finalize;
+
+ gobject_class->set_property = gst_asteriskh263_set_property;
+ gobject_class->get_property = gst_asteriskh263_get_property;
+
+ gstelement_class->change_state = gst_asteriskh263_change_state;
+}
+
+static void
+gst_asteriskh263_init (GstAsteriskh263 * asteriskh263)
+{
+ asteriskh263->srcpad =
+ gst_pad_new_from_template (gst_static_pad_template_get
+ (&gst_asteriskh263_src_template), "src");
+ gst_element_add_pad (GST_ELEMENT (asteriskh263), asteriskh263->srcpad);
+
+ asteriskh263->sinkpad =
+ gst_pad_new_from_template (gst_static_pad_template_get
+ (&gst_asteriskh263_sink_template), "sink");
+ gst_pad_set_chain_function (asteriskh263->sinkpad, gst_asteriskh263_chain);
+ gst_element_add_pad (GST_ELEMENT (asteriskh263), asteriskh263->sinkpad);
+
+ asteriskh263->adapter = gst_adapter_new ();
+}
+
+static void
+gst_asteriskh263_finalize (GObject * object)
+{
+ GstAsteriskh263 *asteriskh263;
+
+ asteriskh263 = GST_ASTERISK_H263 (object);
+
+ g_object_unref (asteriskh263->adapter);
+ asteriskh263->adapter = NULL;
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static GstFlowReturn
+gst_asteriskh263_chain (GstPad * pad, GstBuffer * buf)
+{
+ GstAsteriskh263 *asteriskh263;
+ GstBuffer *outbuf;
+ GstFlowReturn ret;
+
+ asteriskh263 = GST_ASTERISK_H263 (GST_OBJECT_PARENT (pad));
+
+ if (!gst_rtpbuffer_validate (buf))
+ goto bad_packet;
+
+ {
+ gint payload_len;
+ guint8 *payload;
+ gboolean M;
+ guint32 timestamp;
+ guint32 samples;
+ guint16 asterisk_len;
+
+ payload_len = gst_rtpbuffer_get_payload_len (buf);
+ payload = gst_rtpbuffer_get_payload (buf);
+
+ M = gst_rtpbuffer_get_marker (buf);
+ timestamp = gst_rtpbuffer_get_timestamp (buf);
+
+ outbuf = gst_buffer_new_and_alloc (payload_len +
+ GST_ASTERISKH263_HEADER_LEN);
+
+ /* build the asterisk header */
+ asterisk_len = payload_len;
+ if (M)
+ asterisk_len |= 0x8000;
+ if (!asteriskh263->lastts)
+ asteriskh263->lastts = timestamp;
+ samples = timestamp - asteriskh263->lastts;
+ asteriskh263->lastts = timestamp;
+
+ GST_ASTERISKH263_HEADER_TIMESTAMP (outbuf) = htonl (samples);
+ GST_ASTERISKH263_HEADER_LENGTH (outbuf) = htons (asterisk_len);
+
+ /* copy the data into place */
+ memcpy (GST_BUFFER_DATA (outbuf) + GST_ASTERISKH263_HEADER_LEN, payload,
+ payload_len);
+
+ GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
+ gst_buffer_set_caps (outbuf,
+ (GstCaps *) gst_pad_get_pad_template_caps (asteriskh263->srcpad));
+
+ ret = gst_pad_push (asteriskh263->srcpad, outbuf);
+
+ gst_buffer_unref (buf);
+ }
+
+ return ret;
+
+bad_packet:
+ {
+ GST_DEBUG ("Packet does not validate");
+ gst_buffer_unref (buf);
+ return GST_FLOW_ERROR;
+ }
+}
+
+static void
+gst_asteriskh263_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec)
+{
+ GstAsteriskh263 *asteriskh263;
+
+ asteriskh263 = GST_ASTERISK_H263 (object);
+
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gst_asteriskh263_get_property (GObject * object, guint prop_id, GValue * value,
+ GParamSpec * pspec)
+{
+ GstAsteriskh263 *asteriskh263;
+
+ asteriskh263 = GST_ASTERISK_H263 (object);
+
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static GstStateChangeReturn
+gst_asteriskh263_change_state (GstElement * element, GstStateChange transition)
+{
+ GstAsteriskh263 *asteriskh263;
+ GstStateChangeReturn ret;
+
+ asteriskh263 = GST_ASTERISK_H263 (element);
+
+ switch (transition) {
+ case GST_STATE_CHANGE_NULL_TO_READY:
+ break;
+ case GST_STATE_CHANGE_READY_TO_PAUSED:
+ gst_adapter_clear (asteriskh263->adapter);
+ break;
+ default:
+ break;
+ }
+
+ ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
+
+ switch (transition) {
+ case GST_STATE_CHANGE_READY_TO_NULL:
+ break;
+ default:
+ break;
+ }
+ return ret;
+}
+
+gboolean
+gst_asteriskh263_plugin_init (GstPlugin * plugin)
+{
+ return gst_element_register (plugin, "asteriskh263",
+ GST_RANK_NONE, GST_TYPE_ASTERISK_H263);
+}
diff --git a/gst/rtp/gstasteriskh263.h b/gst/rtp/gstasteriskh263.h
new file mode 100644
index 00000000..5ca18ec0
--- /dev/null
+++ b/gst/rtp/gstasteriskh263.h
@@ -0,0 +1,64 @@
+/* Gnome-Streamer
+ * Copyright (C) <2005> Wim Taymans <wim@fluendo.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
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GST_ASTERISK_H263_H__
+#define __GST_ASTERISK_H263_H__
+
+#include <gst/gst.h>
+#include <gst/base/gstadapter.h>
+
+G_BEGIN_DECLS
+
+#define GST_TYPE_ASTERISK_H263 \
+ (gst_asteriskh263_get_type())
+#define GST_ASTERISK_H263(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_ASTERISK_H263,GstAsteriskh263))
+#define GST_ASTERISK_H263_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ASTERISK_H263,GstAsteriskh263))
+#define GST_IS_ASTERISK_H263(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_ASTERISK_H263))
+#define GST_IS_ASTERISK_H263_CLASS(obj) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_ASTERISK_H263))
+
+typedef struct _GstAsteriskh263 GstAsteriskh263;
+typedef struct _GstAsteriskh263Class GstAsteriskh263Class;
+
+struct _GstAsteriskh263
+{
+ GstElement element;
+
+ GstPad *sinkpad;
+ GstPad *srcpad;
+
+ GstAdapter *adapter;
+
+ guint frequency;
+ guint32 lastts;
+};
+
+struct _GstAsteriskh263Class
+{
+ GstElementClass parent_class;
+};
+
+gboolean gst_asteriskh263_plugin_init (GstPlugin * plugin);
+
+G_END_DECLS
+
+#endif /* __GST_ASTERISK_H263_H__ */
diff --git a/gst/rtp/gstrtp.c b/gst/rtp/gstrtp.c
index 6c6523cc..f39c0178 100644
--- a/gst/rtp/gstrtp.c
+++ b/gst/rtp/gstrtp.c
@@ -30,6 +30,8 @@
#include "gstrtpmpadec.h"
#include "gstrtph263pdec.h"
#include "gstrtph263penc.h"
+#include "gstrtph263enc.h"
+#include "gstasteriskh263.h"
#include "gstrtpmp4venc.h"
#include "gstrtpmp4vdec.h"
@@ -63,6 +65,12 @@ plugin_init (GstPlugin * plugin)
if (!gst_rtph263pdec_plugin_init (plugin))
return FALSE;
+ if (!gst_rtph263enc_plugin_init (plugin))
+ return FALSE;
+
+ if (!gst_asteriskh263_plugin_init (plugin))
+ return FALSE;
+
if (!gst_rtpmp4venc_plugin_init (plugin))
return FALSE;
diff --git a/gst/rtp/gstrtph263enc.c b/gst/rtp/gstrtph263enc.c
new file mode 100644
index 00000000..c2caa06f
--- /dev/null
+++ b/gst/rtp/gstrtph263enc.c
@@ -0,0 +1,380 @@
+/* GStreamer
+ * Copyright (C) <2005> Wim Taymans <wim@fluendo.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
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <string.h>
+
+#include <gst/rtp/gstrtpbuffer.h>
+
+#include "gstrtph263enc.h"
+
+#define GST_RFC2190A_HEADER_LEN 4
+
+typedef struct _GstRFC2190AHeader
+{
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+ unsigned int ebit:3; /* End position */
+ unsigned int sbit:3; /* Start position */
+ unsigned int p:1; /* PB-frames mode */
+ unsigned int f:1; /* flag bit */
+
+ unsigned int r1:1; /* Reserved */
+ unsigned int a:1; /* Advanced Prediction */
+ unsigned int s:1; /* syntax based arithmetic coding */
+ unsigned int u:1; /* Unrestricted motion vector */
+ unsigned int i:1; /* Picture coding type */
+ unsigned int src:3; /* Source format */
+
+ unsigned int trb:3; /* Temporal ref for B frame */
+ unsigned int dbq:2; /* Differential Quantisation parameter */
+ unsigned int r2:3; /* Reserved */
+#elif G_BYTE_ORDER == G_BIG_ENDIAN
+ unsigned int f:1; /* flag bit */
+ unsigned int p:1; /* PB-frames mode */
+ unsigned int sbit:3; /* Start position */
+ unsigned int ebit:3; /* End position */
+
+ unsigned int src:3; /* Source format */
+ unsigned int i:1; /* Picture coding type */
+ unsigned int u:1; /* Unrestricted motion vector */
+ unsigned int s:1; /* syntax based arithmetic coding */
+ unsigned int a:1; /* Advanced Prediction */
+ unsigned int r1:1; /* Reserved */
+
+ unsigned int r2:3; /* Reserved */
+ unsigned int dbq:2; /* Differential Quantisation parameter */
+ unsigned int trb:3; /* Temporal ref for B frame */
+#else
+#error "G_BYTE_ORDER should be big or little endian."
+#endif
+ guint8 tr; /* Temporal ref for P frame */
+} GstRFC2190AHeader;
+
+
+#define GST_RFC2190A_HEADER_F(buf) (((GstRFC2190AHeader *)(buf))->f)
+#define GST_RFC2190A_HEADER_P(buf) (((GstRFC2190AHeader *)(buf))->p)
+#define GST_RFC2190A_HEADER_SBIT(buf) (((GstRFC2190AHeader *)(buf))->sbit)
+#define GST_RFC2190A_HEADER_EBIT(buf) (((GstRFC2190AHeader *)(buf))->ebit)
+#define GST_RFC2190A_HEADER_SRC(buf) (((GstRFC2190AHeader *)(buf))->src)
+#define GST_RFC2190A_HEADER_I(buf) (((GstRFC2190AHeader *)(buf))->i)
+#define GST_RFC2190A_HEADER_U(buf) (((GstRFC2190AHeader *)(buf))->u)
+#define GST_RFC2190A_HEADER_S(buf) (((GstRFC2190AHeader *)(buf))->s)
+#define GST_RFC2190A_HEADER_A(buf) (((GstRFC2190AHeader *)(buf))->a)
+#define GST_RFC2190A_HEADER_R1(buf) (((GstRFC2190AHeader *)(buf))->r1)
+#define GST_RFC2190A_HEADER_R2(buf) (((GstRFC2190AHeader *)(buf))->r2)
+#define GST_RFC2190A_HEADER_DBQ(buf) (((GstRFC2190AHeader *)(buf))->dbq)
+#define GST_RFC2190A_HEADER_TRB(buf) (((GstRFC2190AHeader *)(buf))->trb)
+#define GST_RFC2190A_HEADER_TR(buf) (((GstRFC2190AHeader *)(buf))->tr)
+
+
+typedef struct _GstH263PictureLayer
+{
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+ unsigned int psc1:16;
+
+ unsigned int tr1:2;
+ unsigned int psc2:6;
+
+ unsigned int ptype_263:1;
+ unsigned int ptype_start:1;
+ unsigned int tr2:6;
+
+ unsigned int ptype_umvmode:1;
+ unsigned int ptype_pictype:1;
+ unsigned int ptype_srcformat:3;
+ unsigned int ptype_freeze:1;
+ unsigned int ptype_camera:1;
+ unsigned int ptype_split:1;
+
+ unsigned int chaff:5;
+ unsigned int ptype_pbmode:1;
+ unsigned int ptype_apmode:1;
+ unsigned int ptype_sacmode:1;
+#elif G_BYTE_ORDER == G_BIG_ENDIAN
+ unsigned int psc1:16;
+
+ unsigned int psc2:6;
+ unsigned int tr1:2;
+
+ unsigned int tr2:6;
+ unsigned int ptype_start:1;
+ unsigned int ptype_263:1;
+
+ unsigned int ptype_split:1;
+ unsigned int ptype_camera:1;
+ unsigned int ptype_freeze:1;
+ unsigned int ptype_srcformat:3;
+ unsigned int ptype_pictype:1;
+ unsigned int ptype_umvmode:1;
+
+ unsigned int ptype_sacmode:1;
+ unsigned int ptype_apmode:1;
+ unsigned int ptype_pbmode:1;
+ unsigned int chaff:5;
+#else
+#error "G_BYTE_ORDER should be big or little endian."
+#endif
+} GstH263PictureLayer;
+
+#define GST_H263_PICTURELAYER_PLSRC(buf) (((GstH263PictureLayer *)(buf))->ptype_srcformat)
+#define GST_H263_PICTURELAYER_PLTYPE(buf) (((GstH263PictureLayer *)(buf))->ptype_pictype)
+#define GST_H263_PICTURELAYER_PLUMV(buf) (((GstH263PictureLayer *)(buf))->ptype_umvmode)
+#define GST_H263_PICTURELAYER_PLSAC(buf) (((GstH263PictureLayer *)(buf))->ptype_sacmode)
+#define GST_H263_PICTURELAYER_PLAP(buf) (((GstH263PictureLayer *)(buf))->ptype_apmode)
+
+
+
+/* elementfactory information */
+static GstElementDetails gst_rtp_h263enc_details = {
+ "RTP packet parser",
+ "Codec/Encoder/Network",
+ "Encodes H263 video in RTP packets (RFC 2190)",
+ "Neil Stratford <neils@vipadia.com>"
+};
+
+static GstStaticPadTemplate gst_rtph263enc_sink_template =
+GST_STATIC_PAD_TEMPLATE ("sink",
+ GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("video/x-h263")
+ );
+
+static GstStaticPadTemplate gst_rtph263enc_src_template =
+GST_STATIC_PAD_TEMPLATE ("src",
+ GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("application/x-rtp, "
+ "media = (string) \"video\", "
+ "payload = (int) [ 96, 255 ], "
+ "clock-rate = (int) 90000, " "encoding-name = (string) \"H263-1998\"")
+ );
+
+static void gst_rtph263enc_class_init (GstRtpH263EncClass * klass);
+static void gst_rtph263enc_base_init (GstRtpH263EncClass * klass);
+static void gst_rtph263enc_init (GstRtpH263Enc * rtph263enc);
+static void gst_rtph263enc_finalize (GObject * object);
+
+static gboolean gst_rtph263enc_setcaps (GstBaseRTPPayload * payload,
+ GstCaps * caps);
+static GstFlowReturn gst_rtph263enc_handle_buffer (GstBaseRTPPayload * payload,
+ GstBuffer * buffer);
+
+static GstBaseRTPPayloadClass *parent_class = NULL;
+
+static GType
+gst_rtph263enc_get_type (void)
+{
+ static GType rtph263enc_type = 0;
+
+ if (!rtph263enc_type) {
+ static const GTypeInfo rtph263enc_info = {
+ sizeof (GstRtpH263EncClass),
+ (GBaseInitFunc) gst_rtph263enc_base_init,
+ NULL,
+ (GClassInitFunc) gst_rtph263enc_class_init,
+ NULL,
+ NULL,
+ sizeof (GstRtpH263Enc),
+ 0,
+ (GInstanceInitFunc) gst_rtph263enc_init,
+ };
+
+ rtph263enc_type =
+ g_type_register_static (GST_TYPE_BASE_RTP_PAYLOAD, "GstRtpH263Enc",
+ &rtph263enc_info, 0);
+ }
+ return rtph263enc_type;
+}
+
+static void
+gst_rtph263enc_base_init (GstRtpH263EncClass * klass)
+{
+ GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
+
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&gst_rtph263enc_src_template));
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&gst_rtph263enc_sink_template));
+
+ gst_element_class_set_details (element_class, &gst_rtp_h263enc_details);
+}
+
+static void
+gst_rtph263enc_class_init (GstRtpH263EncClass * klass)
+{
+ GObjectClass *gobject_class;
+ GstElementClass *gstelement_class;
+ GstBaseRTPPayloadClass *gstbasertppayload_class;
+
+ gobject_class = (GObjectClass *) klass;
+ gstelement_class = (GstElementClass *) klass;
+ gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
+
+ parent_class = g_type_class_ref (GST_TYPE_BASE_RTP_PAYLOAD);
+
+ gobject_class->finalize = gst_rtph263enc_finalize;
+
+ gstbasertppayload_class->set_caps = gst_rtph263enc_setcaps;
+ gstbasertppayload_class->handle_buffer = gst_rtph263enc_handle_buffer;
+}
+
+static void
+gst_rtph263enc_init (GstRtpH263Enc * rtph263enc)
+{
+ rtph263enc->adapter = gst_adapter_new ();
+}
+
+static void
+gst_rtph263enc_finalize (GObject * object)
+{
+ GstRtpH263Enc *rtph263enc;
+
+ rtph263enc = GST_RTP_H263_ENC (object);
+
+ g_object_unref (rtph263enc->adapter);
+ rtph263enc->adapter = NULL;
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static gboolean
+gst_rtph263enc_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
+{
+ gst_basertppayload_set_options (payload, "video", TRUE, "H263-1998", 90000);
+ gst_basertppayload_set_outcaps (payload, NULL);
+
+ return TRUE;
+}
+
+static guint
+gst_rtph263enc_gobfiner (guint8 * data, guint len, guint curpos)
+{
+ guint16 test = 0xffff;
+ guint i;
+
+ /* If we are past the end, stop */
+ if (curpos >= len)
+ return 0;
+
+ /* start at curpos and loop looking for next gob start */
+ for (i = curpos; i < len; i++) {
+ test = (test << 8) | data[i];
+ if ((test == 0) && (i > curpos + 4)) {
+ return i - 3;
+ }
+ }
+ return len;
+}
+
+static GstFlowReturn
+gst_rtph263enc_flush (GstRtpH263Enc * rtph263enc)
+{
+ guint avail;
+ GstBuffer *outbuf;
+ GstFlowReturn ret = 0;
+ gboolean fragmented;
+ guint8 *data, *header;
+ GstH263PictureLayer *piclayer;
+ guint8 *payload;
+ guint payload_len, total_len;
+ guint curpos, nextgobpos;
+
+ avail = gst_adapter_available (rtph263enc->adapter);
+ if (avail == 0)
+ return GST_FLOW_OK;
+
+ fragmented = FALSE;
+
+ /* Get a pointer to all the data for the frame */
+ data = (guint8 *) gst_adapter_peek (rtph263enc->adapter, avail);
+
+ /* Start at the begining and loop looking for gobs */
+ curpos = 0;
+
+ /* Picture header */
+ piclayer = (GstH263PictureLayer *) data;
+
+ while ((nextgobpos = gst_rtph263enc_gobfiner (data, avail, curpos)) > 0) {
+
+ payload_len = nextgobpos - curpos;
+ total_len = payload_len + GST_RFC2190A_HEADER_LEN;
+
+ outbuf = gst_rtpbuffer_new_allocate (total_len, 0, 0);
+
+ header = gst_rtpbuffer_get_payload (outbuf);
+ payload = header + GST_RFC2190A_HEADER_LEN;
+
+ /* Build the headers */
+ GST_RFC2190A_HEADER_F (header) = 0;
+ GST_RFC2190A_HEADER_P (header) = 0;
+ GST_RFC2190A_HEADER_SBIT (header) = 0;
+ GST_RFC2190A_HEADER_EBIT (header) = 0;
+
+ GST_RFC2190A_HEADER_SRC (header) = GST_H263_PICTURELAYER_PLSRC (piclayer);
+ GST_RFC2190A_HEADER_I (header) = GST_H263_PICTURELAYER_PLTYPE (piclayer);
+ GST_RFC2190A_HEADER_U (header) = GST_H263_PICTURELAYER_PLUMV (piclayer);
+ GST_RFC2190A_HEADER_S (header) = GST_H263_PICTURELAYER_PLSAC (piclayer);
+ GST_RFC2190A_HEADER_A (header) = GST_H263_PICTURELAYER_PLAP (piclayer);
+ GST_RFC2190A_HEADER_R1 (header) = 0;
+ GST_RFC2190A_HEADER_R2 (header) = 0;
+ GST_RFC2190A_HEADER_DBQ (header) = 0;
+ GST_RFC2190A_HEADER_TRB (header) = 0;
+ GST_RFC2190A_HEADER_TR (header) = 0;
+
+ /* last fragment gets the marker bit set */
+ gst_rtpbuffer_set_marker (outbuf, nextgobpos < avail ? 0 : 1);
+
+ memcpy (payload, data + curpos, payload_len);
+
+ GST_BUFFER_TIMESTAMP (outbuf) = rtph263enc->first_ts;
+
+ ret = gst_basertppayload_push (GST_BASE_RTP_PAYLOAD (rtph263enc), outbuf);
+
+ curpos = nextgobpos;
+ }
+
+ /* Flush the whole packet */
+ gst_adapter_flush (rtph263enc->adapter, avail);
+
+ return ret;
+}
+
+static GstFlowReturn
+gst_rtph263enc_handle_buffer (GstBaseRTPPayload * payload, GstBuffer * buffer)
+{
+ GstRtpH263Enc *rtph263enc;
+ GstFlowReturn ret;
+ guint size;
+
+ rtph263enc = GST_RTP_H263_ENC (payload);
+
+ size = GST_BUFFER_SIZE (buffer);
+ rtph263enc->first_ts = GST_BUFFER_TIMESTAMP (buffer);
+
+ /* we always encode and flush a full picture */
+ gst_adapter_push (rtph263enc->adapter, buffer);
+ ret = gst_rtph263enc_flush (rtph263enc);
+
+ return ret;
+}
+
+gboolean
+gst_rtph263enc_plugin_init (GstPlugin * plugin)
+{
+ return gst_element_register (plugin, "rtph263enc",
+ GST_RANK_NONE, GST_TYPE_RTP_H263_ENC);
+}
diff --git a/gst/rtp/gstrtph263enc.h b/gst/rtp/gstrtph263enc.h
new file mode 100644
index 00000000..1f3fb1c1
--- /dev/null
+++ b/gst/rtp/gstrtph263enc.h
@@ -0,0 +1,60 @@
+/* Gnome-Streamer
+ * Copyright (C) <2005> Wim Taymans <wim@fluendo.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
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GST_RTP_H263_ENC_H__
+#define __GST_RTP_H263_ENC_H__
+
+#include <gst/gst.h>
+#include <gst/rtp/gstbasertppayload.h>
+#include <gst/base/gstadapter.h>
+
+G_BEGIN_DECLS
+
+#define GST_TYPE_RTP_H263_ENC \
+ (gst_rtph263enc_get_type())
+#define GST_RTP_H263_ENC(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RTP_H263_ENC,GstRtpH263Enc))
+#define GST_RTP_H263_ENC_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RTP_H263_ENC,GstRtpH263Enc))
+#define GST_IS_RTP_H263_ENC(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_H263_ENC))
+#define GST_IS_RTP_H263_ENC_CLASS(obj) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_H263_ENC))
+
+typedef struct _GstRtpH263Enc GstRtpH263Enc;
+typedef struct _GstRtpH263EncClass GstRtpH263EncClass;
+
+struct _GstRtpH263Enc
+{
+ GstBaseRTPPayload payload;
+
+ GstAdapter *adapter;
+ GstClockTime first_ts;
+};
+
+struct _GstRtpH263EncClass
+{
+ GstBaseRTPPayloadClass parent_class;
+};
+
+gboolean gst_rtph263enc_plugin_init (GstPlugin * plugin);
+
+G_END_DECLS
+
+#endif /* __GST_RTP_H263_ENC_H__ */
diff --git a/gst/rtp/gstrtph263pay.c b/gst/rtp/gstrtph263pay.c
new file mode 100644
index 00000000..c2caa06f
--- /dev/null
+++ b/gst/rtp/gstrtph263pay.c
@@ -0,0 +1,380 @@
+/* GStreamer
+ * Copyright (C) <2005> Wim Taymans <wim@fluendo.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
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <string.h>
+
+#include <gst/rtp/gstrtpbuffer.h>
+
+#include "gstrtph263enc.h"
+
+#define GST_RFC2190A_HEADER_LEN 4
+
+typedef struct _GstRFC2190AHeader
+{
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+ unsigned int ebit:3; /* End position */
+ unsigned int sbit:3; /* Start position */
+ unsigned int p:1; /* PB-frames mode */
+ unsigned int f:1; /* flag bit */
+
+ unsigned int r1:1; /* Reserved */
+ unsigned int a:1; /* Advanced Prediction */
+ unsigned int s:1; /* syntax based arithmetic coding */
+ unsigned int u:1; /* Unrestricted motion vector */
+ unsigned int i:1; /* Picture coding type */
+ unsigned int src:3; /* Source format */
+
+ unsigned int trb:3; /* Temporal ref for B frame */
+ unsigned int dbq:2; /* Differential Quantisation parameter */
+ unsigned int r2:3; /* Reserved */
+#elif G_BYTE_ORDER == G_BIG_ENDIAN
+ unsigned int f:1; /* flag bit */
+ unsigned int p:1; /* PB-frames mode */
+ unsigned int sbit:3; /* Start position */
+ unsigned int ebit:3; /* End position */
+
+ unsigned int src:3; /* Source format */
+ unsigned int i:1; /* Picture coding type */
+ unsigned int u:1; /* Unrestricted motion vector */
+ unsigned int s:1; /* syntax based arithmetic coding */
+ unsigned int a:1; /* Advanced Prediction */
+ unsigned int r1:1; /* Reserved */
+
+ unsigned int r2:3; /* Reserved */
+ unsigned int dbq:2; /* Differential Quantisation parameter */
+ unsigned int trb:3; /* Temporal ref for B frame */
+#else
+#error "G_BYTE_ORDER should be big or little endian."
+#endif
+ guint8 tr; /* Temporal ref for P frame */
+} GstRFC2190AHeader;
+
+
+#define GST_RFC2190A_HEADER_F(buf) (((GstRFC2190AHeader *)(buf))->f)
+#define GST_RFC2190A_HEADER_P(buf) (((GstRFC2190AHeader *)(buf))->p)
+#define GST_RFC2190A_HEADER_SBIT(buf) (((GstRFC2190AHeader *)(buf))->sbit)
+#define GST_RFC2190A_HEADER_EBIT(buf) (((GstRFC2190AHeader *)(buf))->ebit)
+#define GST_RFC2190A_HEADER_SRC(buf) (((GstRFC2190AHeader *)(buf))->src)
+#define GST_RFC2190A_HEADER_I(buf) (((GstRFC2190AHeader *)(buf))->i)
+#define GST_RFC2190A_HEADER_U(buf) (((GstRFC2190AHeader *)(buf))->u)
+#define GST_RFC2190A_HEADER_S(buf) (((GstRFC2190AHeader *)(buf))->s)
+#define GST_RFC2190A_HEADER_A(buf) (((GstRFC2190AHeader *)(buf))->a)
+#define GST_RFC2190A_HEADER_R1(buf) (((GstRFC2190AHeader *)(buf))->r1)
+#define GST_RFC2190A_HEADER_R2(buf) (((GstRFC2190AHeader *)(buf))->r2)
+#define GST_RFC2190A_HEADER_DBQ(buf) (((GstRFC2190AHeader *)(buf))->dbq)
+#define GST_RFC2190A_HEADER_TRB(buf) (((GstRFC2190AHeader *)(buf))->trb)
+#define GST_RFC2190A_HEADER_TR(buf) (((GstRFC2190AHeader *)(buf))->tr)
+
+
+typedef struct _GstH263PictureLayer
+{
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+ unsigned int psc1:16;
+
+ unsigned int tr1:2;
+ unsigned int psc2:6;
+
+ unsigned int ptype_263:1;
+ unsigned int ptype_start:1;
+ unsigned int tr2:6;
+
+ unsigned int ptype_umvmode:1;
+ unsigned int ptype_pictype:1;
+ unsigned int ptype_srcformat:3;
+ unsigned int ptype_freeze:1;
+ unsigned int ptype_camera:1;
+ unsigned int ptype_split:1;
+
+ unsigned int chaff:5;
+ unsigned int ptype_pbmode:1;
+ unsigned int ptype_apmode:1;
+ unsigned int ptype_sacmode:1;
+#elif G_BYTE_ORDER == G_BIG_ENDIAN
+ unsigned int psc1:16;
+
+ unsigned int psc2:6;
+ unsigned int tr1:2;
+
+ unsigned int tr2:6;
+ unsigned int ptype_start:1;
+ unsigned int ptype_263:1;
+
+ unsigned int ptype_split:1;
+ unsigned int ptype_camera:1;
+ unsigned int ptype_freeze:1;
+ unsigned int ptype_srcformat:3;
+ unsigned int ptype_pictype:1;
+ unsigned int ptype_umvmode:1;
+
+ unsigned int ptype_sacmode:1;
+ unsigned int ptype_apmode:1;
+ unsigned int ptype_pbmode:1;
+ unsigned int chaff:5;
+#else
+#error "G_BYTE_ORDER should be big or little endian."
+#endif
+} GstH263PictureLayer;
+
+#define GST_H263_PICTURELAYER_PLSRC(buf) (((GstH263PictureLayer *)(buf))->ptype_srcformat)
+#define GST_H263_PICTURELAYER_PLTYPE(buf) (((GstH263PictureLayer *)(buf))->ptype_pictype)
+#define GST_H263_PICTURELAYER_PLUMV(buf) (((GstH263PictureLayer *)(buf))->ptype_umvmode)
+#define GST_H263_PICTURELAYER_PLSAC(buf) (((GstH263PictureLayer *)(buf))->ptype_sacmode)
+#define GST_H263_PICTURELAYER_PLAP(buf) (((GstH263PictureLayer *)(buf))->ptype_apmode)
+
+
+
+/* elementfactory information */
+static GstElementDetails gst_rtp_h263enc_details = {
+ "RTP packet parser",
+ "Codec/Encoder/Network",
+ "Encodes H263 video in RTP packets (RFC 2190)",
+ "Neil Stratford <neils@vipadia.com>"
+};
+
+static GstStaticPadTemplate gst_rtph263enc_sink_template =
+GST_STATIC_PAD_TEMPLATE ("sink",
+ GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("video/x-h263")
+ );
+
+static GstStaticPadTemplate gst_rtph263enc_src_template =
+GST_STATIC_PAD_TEMPLATE ("src",
+ GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("application/x-rtp, "
+ "media = (string) \"video\", "
+ "payload = (int) [ 96, 255 ], "
+ "clock-rate = (int) 90000, " "encoding-name = (string) \"H263-1998\"")
+ );
+
+static void gst_rtph263enc_class_init (GstRtpH263EncClass * klass);
+static void gst_rtph263enc_base_init (GstRtpH263EncClass * klass);
+static void gst_rtph263enc_init (GstRtpH263Enc * rtph263enc);
+static void gst_rtph263enc_finalize (GObject * object);
+
+static gboolean gst_rtph263enc_setcaps (GstBaseRTPPayload * payload,
+ GstCaps * caps);
+static GstFlowReturn gst_rtph263enc_handle_buffer (GstBaseRTPPayload * payload,
+ GstBuffer * buffer);
+
+static GstBaseRTPPayloadClass *parent_class = NULL;
+
+static GType
+gst_rtph263enc_get_type (void)
+{
+ static GType rtph263enc_type = 0;
+
+ if (!rtph263enc_type) {
+ static const GTypeInfo rtph263enc_info = {
+ sizeof (GstRtpH263EncClass),
+ (GBaseInitFunc) gst_rtph263enc_base_init,
+ NULL,
+ (GClassInitFunc) gst_rtph263enc_class_init,
+ NULL,
+ NULL,
+ sizeof (GstRtpH263Enc),
+ 0,
+ (GInstanceInitFunc) gst_rtph263enc_init,
+ };
+
+ rtph263enc_type =
+ g_type_register_static (GST_TYPE_BASE_RTP_PAYLOAD, "GstRtpH263Enc",
+ &rtph263enc_info, 0);
+ }
+ return rtph263enc_type;
+}
+
+static void
+gst_rtph263enc_base_init (GstRtpH263EncClass * klass)
+{
+ GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
+
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&gst_rtph263enc_src_template));
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&gst_rtph263enc_sink_template));
+
+ gst_element_class_set_details (element_class, &gst_rtp_h263enc_details);
+}
+
+static void
+gst_rtph263enc_class_init (GstRtpH263EncClass * klass)
+{
+ GObjectClass *gobject_class;
+ GstElementClass *gstelement_class;
+ GstBaseRTPPayloadClass *gstbasertppayload_class;
+
+ gobject_class = (GObjectClass *) klass;
+ gstelement_class = (GstElementClass *) klass;
+ gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
+
+ parent_class = g_type_class_ref (GST_TYPE_BASE_RTP_PAYLOAD);
+
+ gobject_class->finalize = gst_rtph263enc_finalize;
+
+ gstbasertppayload_class->set_caps = gst_rtph263enc_setcaps;
+ gstbasertppayload_class->handle_buffer = gst_rtph263enc_handle_buffer;
+}
+
+static void
+gst_rtph263enc_init (GstRtpH263Enc * rtph263enc)
+{
+ rtph263enc->adapter = gst_adapter_new ();
+}
+
+static void
+gst_rtph263enc_finalize (GObject * object)
+{
+ GstRtpH263Enc *rtph263enc;
+
+ rtph263enc = GST_RTP_H263_ENC (object);
+
+ g_object_unref (rtph263enc->adapter);
+ rtph263enc->adapter = NULL;
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static gboolean
+gst_rtph263enc_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
+{
+ gst_basertppayload_set_options (payload, "video", TRUE, "H263-1998", 90000);
+ gst_basertppayload_set_outcaps (payload, NULL);
+
+ return TRUE;
+}
+
+static guint
+gst_rtph263enc_gobfiner (guint8 * data, guint len, guint curpos)
+{
+ guint16 test = 0xffff;
+ guint i;
+
+ /* If we are past the end, stop */
+ if (curpos >= len)
+ return 0;
+
+ /* start at curpos and loop looking for next gob start */
+ for (i = curpos; i < len; i++) {
+ test = (test << 8) | data[i];
+ if ((test == 0) && (i > curpos + 4)) {
+ return i - 3;
+ }
+ }
+ return len;
+}
+
+static GstFlowReturn
+gst_rtph263enc_flush (GstRtpH263Enc * rtph263enc)
+{
+ guint avail;
+ GstBuffer *outbuf;
+ GstFlowReturn ret = 0;
+ gboolean fragmented;
+ guint8 *data, *header;
+ GstH263PictureLayer *piclayer;
+ guint8 *payload;
+ guint payload_len, total_len;
+ guint curpos, nextgobpos;
+
+ avail = gst_adapter_available (rtph263enc->adapter);
+ if (avail == 0)
+ return GST_FLOW_OK;
+
+ fragmented = FALSE;
+
+ /* Get a pointer to all the data for the frame */
+ data = (guint8 *) gst_adapter_peek (rtph263enc->adapter, avail);
+
+ /* Start at the begining and loop looking for gobs */
+ curpos = 0;
+
+ /* Picture header */
+ piclayer = (GstH263PictureLayer *) data;
+
+ while ((nextgobpos = gst_rtph263enc_gobfiner (data, avail, curpos)) > 0) {
+
+ payload_len = nextgobpos - curpos;
+ total_len = payload_len + GST_RFC2190A_HEADER_LEN;
+
+ outbuf = gst_rtpbuffer_new_allocate (total_len, 0, 0);
+
+ header = gst_rtpbuffer_get_payload (outbuf);
+ payload = header + GST_RFC2190A_HEADER_LEN;
+
+ /* Build the headers */
+ GST_RFC2190A_HEADER_F (header) = 0;
+ GST_RFC2190A_HEADER_P (header) = 0;
+ GST_RFC2190A_HEADER_SBIT (header) = 0;
+ GST_RFC2190A_HEADER_EBIT (header) = 0;
+
+ GST_RFC2190A_HEADER_SRC (header) = GST_H263_PICTURELAYER_PLSRC (piclayer);
+ GST_RFC2190A_HEADER_I (header) = GST_H263_PICTURELAYER_PLTYPE (piclayer);
+ GST_RFC2190A_HEADER_U (header) = GST_H263_PICTURELAYER_PLUMV (piclayer);
+ GST_RFC2190A_HEADER_S (header) = GST_H263_PICTURELAYER_PLSAC (piclayer);
+ GST_RFC2190A_HEADER_A (header) = GST_H263_PICTURELAYER_PLAP (piclayer);
+ GST_RFC2190A_HEADER_R1 (header) = 0;
+ GST_RFC2190A_HEADER_R2 (header) = 0;
+ GST_RFC2190A_HEADER_DBQ (header) = 0;
+ GST_RFC2190A_HEADER_TRB (header) = 0;
+ GST_RFC2190A_HEADER_TR (header) = 0;
+
+ /* last fragment gets the marker bit set */
+ gst_rtpbuffer_set_marker (outbuf, nextgobpos < avail ? 0 : 1);
+
+ memcpy (payload, data + curpos, payload_len);
+
+ GST_BUFFER_TIMESTAMP (outbuf) = rtph263enc->first_ts;
+
+ ret = gst_basertppayload_push (GST_BASE_RTP_PAYLOAD (rtph263enc), outbuf);
+
+ curpos = nextgobpos;
+ }
+
+ /* Flush the whole packet */
+ gst_adapter_flush (rtph263enc->adapter, avail);
+
+ return ret;
+}
+
+static GstFlowReturn
+gst_rtph263enc_handle_buffer (GstBaseRTPPayload * payload, GstBuffer * buffer)
+{
+ GstRtpH263Enc *rtph263enc;
+ GstFlowReturn ret;
+ guint size;
+
+ rtph263enc = GST_RTP_H263_ENC (payload);
+
+ size = GST_BUFFER_SIZE (buffer);
+ rtph263enc->first_ts = GST_BUFFER_TIMESTAMP (buffer);
+
+ /* we always encode and flush a full picture */
+ gst_adapter_push (rtph263enc->adapter, buffer);
+ ret = gst_rtph263enc_flush (rtph263enc);
+
+ return ret;
+}
+
+gboolean
+gst_rtph263enc_plugin_init (GstPlugin * plugin)
+{
+ return gst_element_register (plugin, "rtph263enc",
+ GST_RANK_NONE, GST_TYPE_RTP_H263_ENC);
+}
diff --git a/gst/rtp/gstrtph263pay.h b/gst/rtp/gstrtph263pay.h
new file mode 100644
index 00000000..1f3fb1c1
--- /dev/null
+++ b/gst/rtp/gstrtph263pay.h
@@ -0,0 +1,60 @@
+/* Gnome-Streamer
+ * Copyright (C) <2005> Wim Taymans <wim@fluendo.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
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GST_RTP_H263_ENC_H__
+#define __GST_RTP_H263_ENC_H__
+
+#include <gst/gst.h>
+#include <gst/rtp/gstbasertppayload.h>
+#include <gst/base/gstadapter.h>
+
+G_BEGIN_DECLS
+
+#define GST_TYPE_RTP_H263_ENC \
+ (gst_rtph263enc_get_type())
+#define GST_RTP_H263_ENC(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RTP_H263_ENC,GstRtpH263Enc))
+#define GST_RTP_H263_ENC_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RTP_H263_ENC,GstRtpH263Enc))
+#define GST_IS_RTP_H263_ENC(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_H263_ENC))
+#define GST_IS_RTP_H263_ENC_CLASS(obj) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_H263_ENC))
+
+typedef struct _GstRtpH263Enc GstRtpH263Enc;
+typedef struct _GstRtpH263EncClass GstRtpH263EncClass;
+
+struct _GstRtpH263Enc
+{
+ GstBaseRTPPayload payload;
+
+ GstAdapter *adapter;
+ GstClockTime first_ts;
+};
+
+struct _GstRtpH263EncClass
+{
+ GstBaseRTPPayloadClass parent_class;
+};
+
+gboolean gst_rtph263enc_plugin_init (GstPlugin * plugin);
+
+G_END_DECLS
+
+#endif /* __GST_RTP_H263_ENC_H__ */