gst/rtp/gstrtpmp2tpay.*: Fill the MTU with as many packets as possible. Fixes #491323.

Original commit message from CVS:
Patch by: Jordi Jaen Pallares <jordijp at gmail dot com>
* gst/rtp/gstrtpmp2tpay.c: (gst_rtp_mp2t_pay_class_init),
(gst_rtp_mp2t_pay_init), (gst_rtp_mp2t_pay_finalize),
(gst_rtp_mp2t_pay_flush), (gst_rtp_mp2t_pay_handle_buffer):
* gst/rtp/gstrtpmp2tpay.h:
Fill the MTU with as many packets as possible. Fixes #491323.
This commit is contained in:
Jordi Jaen Pallares 2007-11-15 18:19:19 +00:00 committed by Wim Taymans
parent 2a5f7c6acd
commit ccf7a43e6f
3 changed files with 92 additions and 19 deletions

View file

@ -1,3 +1,13 @@
2007-11-15 Wim Taymans <wim.taymans@gmail.com>
Patch by: Jordi Jaen Pallares <jordijp at gmail dot com>
* gst/rtp/gstrtpmp2tpay.c: (gst_rtp_mp2t_pay_class_init),
(gst_rtp_mp2t_pay_init), (gst_rtp_mp2t_pay_finalize),
(gst_rtp_mp2t_pay_flush), (gst_rtp_mp2t_pay_handle_buffer):
* gst/rtp/gstrtpmp2tpay.h:
Fill the MTU with as many packets as possible. Fixes #491323.
2007-11-15 Wim Taymans <wim.taymans@gmail.com> 2007-11-15 Wim Taymans <wim.taymans@gmail.com>
Patch by: Tommi Myöhänen <ext-tommi dot myohanen at nokia dot com> Patch by: Tommi Myöhänen <ext-tommi dot myohanen at nokia dot com>

View file

@ -56,6 +56,8 @@ static gboolean gst_rtp_mp2t_pay_setcaps (GstBaseRTPPayload * payload,
GstCaps * caps); GstCaps * caps);
static GstFlowReturn gst_rtp_mp2t_pay_handle_buffer (GstBaseRTPPayload * static GstFlowReturn gst_rtp_mp2t_pay_handle_buffer (GstBaseRTPPayload *
payload, GstBuffer * buffer); payload, GstBuffer * buffer);
static GstFlowReturn gst_rtp_mp2t_pay_flush (GstRTPMP2TPay * rtpmp2tpay);
static void gst_rtp_mp2t_pay_finalize (GObject * object);
GST_BOILERPLATE (GstRTPMP2TPay, gst_rtp_mp2t_pay, GstBaseRTPPayload, GST_BOILERPLATE (GstRTPMP2TPay, gst_rtp_mp2t_pay, GstBaseRTPPayload,
GST_TYPE_BASE_RTP_PAYLOAD); GST_TYPE_BASE_RTP_PAYLOAD);
@ -83,6 +85,8 @@ gst_rtp_mp2t_pay_class_init (GstRTPMP2TPayClass * klass)
gstelement_class = (GstElementClass *) klass; gstelement_class = (GstElementClass *) klass;
gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass; gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
gobject_class->finalize = gst_rtp_mp2t_pay_finalize;
gstbasertppayload_class->set_caps = gst_rtp_mp2t_pay_setcaps; gstbasertppayload_class->set_caps = gst_rtp_mp2t_pay_setcaps;
gstbasertppayload_class->handle_buffer = gst_rtp_mp2t_pay_handle_buffer; gstbasertppayload_class->handle_buffer = gst_rtp_mp2t_pay_handle_buffer;
} }
@ -92,6 +96,21 @@ gst_rtp_mp2t_pay_init (GstRTPMP2TPay * rtpmp2tpay, GstRTPMP2TPayClass * klass)
{ {
GST_BASE_RTP_PAYLOAD (rtpmp2tpay)->clock_rate = 90000; GST_BASE_RTP_PAYLOAD (rtpmp2tpay)->clock_rate = 90000;
GST_BASE_RTP_PAYLOAD_PT (rtpmp2tpay) = GST_RTP_PAYLOAD_MP2T; GST_BASE_RTP_PAYLOAD_PT (rtpmp2tpay) = GST_RTP_PAYLOAD_MP2T;
rtpmp2tpay->adapter = gst_adapter_new ();
}
static void
gst_rtp_mp2t_pay_finalize (GObject * object)
{
GstRTPMP2TPay *rtpmp2tpay;
rtpmp2tpay = GST_RTP_MP2T_PAY (object);
g_object_unref (rtpmp2tpay->adapter);
rtpmp2tpay->adapter = NULL;
G_OBJECT_CLASS (parent_class)->finalize (object);
} }
static gboolean static gboolean
@ -110,14 +129,44 @@ gst_rtp_mp2t_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
return TRUE; return TRUE;
} }
static GstFlowReturn
gst_rtp_mp2t_pay_flush (GstRTPMP2TPay * rtpmp2tpay)
{
guint avail;
guint8 *payload;
GstFlowReturn ret;
GstBuffer *outbuf;
avail = gst_adapter_available (rtpmp2tpay->adapter);
outbuf = gst_rtp_buffer_new_allocate (avail, 0, 0);
/* get payload */
payload = gst_rtp_buffer_get_payload (outbuf);
/* copy stuff from adapter to payload */
gst_adapter_copy (rtpmp2tpay->adapter, payload, 0, avail);
GST_BUFFER_TIMESTAMP (outbuf) = rtpmp2tpay->first_ts;
GST_BUFFER_DURATION (outbuf) = rtpmp2tpay->duration;
GST_DEBUG_OBJECT (rtpmp2tpay, "pushing buffer of size %d",
GST_BUFFER_SIZE (outbuf));
ret = gst_basertppayload_push (GST_BASE_RTP_PAYLOAD (rtpmp2tpay), outbuf);
/* flush the adapter content */
gst_adapter_flush (rtpmp2tpay->adapter, avail);
return ret;
}
static GstFlowReturn static GstFlowReturn
gst_rtp_mp2t_pay_handle_buffer (GstBaseRTPPayload * basepayload, gst_rtp_mp2t_pay_handle_buffer (GstBaseRTPPayload * basepayload,
GstBuffer * buffer) GstBuffer * buffer)
{ {
GstRTPMP2TPay *rtpmp2tpay; GstRTPMP2TPay *rtpmp2tpay;
guint size, payload_len; guint size, avail, packet_len;
GstBuffer *outbuf; guint8 *data;
guint8 *payload, *data;
GstClockTime timestamp, duration; GstClockTime timestamp, duration;
GstFlowReturn ret; GstFlowReturn ret;
@ -128,29 +177,38 @@ gst_rtp_mp2t_pay_handle_buffer (GstBaseRTPPayload * basepayload,
timestamp = GST_BUFFER_TIMESTAMP (buffer); timestamp = GST_BUFFER_TIMESTAMP (buffer);
duration = GST_BUFFER_DURATION (buffer); duration = GST_BUFFER_DURATION (buffer);
/* FIXME, only one MP2T frame per RTP packet for now */ ret = GST_FLOW_OK;
payload_len = size; avail = gst_adapter_available (rtpmp2tpay->adapter);
outbuf = gst_rtp_buffer_new_allocate (payload_len, 0, 0); /* Initialize new RTP payload */
if (avail == 0) {
rtpmp2tpay->first_ts = timestamp;
rtpmp2tpay->duration = duration;
}
/* copy timestamp */ /* get packet length of previous data and this new data,
GST_BUFFER_TIMESTAMP (outbuf) = timestamp; * payload length includes a 4 byte header */
GST_BUFFER_DURATION (outbuf) = duration; packet_len = gst_rtp_buffer_calc_packet_len (4 + avail + size, 0, 0);
/* get payload */ /* if this buffer is going to overflow the packet, flush what we
payload = gst_rtp_buffer_get_payload (outbuf); * have. */
if (gst_basertppayload_is_filled (basepayload,
packet_len, rtpmp2tpay->duration + duration)) {
ret = gst_rtp_mp2t_pay_flush (rtpmp2tpay);
rtpmp2tpay->first_ts = timestamp;
rtpmp2tpay->duration = duration;
/* copy data in payload */ /* keep filling the payload */
memcpy (payload, data, size); } else {
if (GST_CLOCK_TIME_IS_VALID (duration))
rtpmp2tpay->duration += duration;
}
gst_buffer_unref (buffer); /* copy buffer to adapter */
gst_adapter_push (rtpmp2tpay->adapter, buffer);
GST_DEBUG_OBJECT (rtpmp2tpay, "pushing buffer of size %d",
GST_BUFFER_SIZE (outbuf));
ret = gst_basertppayload_push (basepayload, outbuf);
return ret; return ret;
} }
gboolean gboolean

View file

@ -23,6 +23,7 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/rtp/gstbasertppayload.h> #include <gst/rtp/gstbasertppayload.h>
#include <gst/base/gstadapter.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -43,6 +44,10 @@ typedef struct _GstRTPMP2TPayClass GstRTPMP2TPayClass;
struct _GstRTPMP2TPay struct _GstRTPMP2TPay
{ {
GstBaseRTPPayload payload; GstBaseRTPPayload payload;
GstAdapter *adapter;
GstClockTime first_ts;
GstClockTime duration;
}; };
struct _GstRTPMP2TPayClass struct _GstRTPMP2TPayClass