rtph263pay: Stop using an adapter and directly use the buffer

We always pushed one buffer into the adapter, then handled exactly that one
buffer and flushed it from the adapter. Now also don't memcpy() the actual
payload but just attach the input buffer's data to the output buffer.

This code still needs some serious refactoring/rewriting.
This commit is contained in:
Sebastian Dröge 2015-07-02 09:17:59 +02:00
parent 51cd22c912
commit 8b0d11a0ee
2 changed files with 23 additions and 29 deletions

View file

@ -440,8 +440,6 @@ gst_rtp_h263_pay_class_init (GstRtpH263PayClass * klass)
static void static void
gst_rtp_h263_pay_init (GstRtpH263Pay * rtph263pay) gst_rtp_h263_pay_init (GstRtpH263Pay * rtph263pay)
{ {
rtph263pay->adapter = gst_adapter_new ();
rtph263pay->prop_payload_mode = DEFAULT_MODE_A; rtph263pay->prop_payload_mode = DEFAULT_MODE_A;
} }
@ -452,8 +450,7 @@ gst_rtp_h263_pay_finalize (GObject * object)
rtph263pay = GST_RTP_H263_PAY (object); rtph263pay = GST_RTP_H263_PAY (object);
g_object_unref (rtph263pay->adapter); gst_buffer_replace (&rtph263pay->current_buffer, NULL);
rtph263pay->adapter = NULL;
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
@ -1268,14 +1265,12 @@ gst_rtp_h263_pay_push (GstRtpH263Pay * rtph263pay,
* Splat the payload header values * Splat the payload header values
*/ */
guint8 *header; guint8 *header;
guint8 *payload;
GstFlowReturn ret; GstFlowReturn ret;
GstRTPBuffer rtp = { NULL }; GstRTPBuffer rtp = { NULL };
gst_rtp_buffer_map (package->outbuf, GST_MAP_WRITE, &rtp); gst_rtp_buffer_map (package->outbuf, GST_MAP_WRITE, &rtp);
header = gst_rtp_buffer_get_payload (&rtp); header = gst_rtp_buffer_get_payload (&rtp);
payload = header + package->mode;
switch (package->mode) { switch (package->mode) {
case GST_RTP_H263_PAYLOAD_HEADER_MODE_A: case GST_RTP_H263_PAYLOAD_HEADER_MODE_A:
@ -1293,13 +1288,6 @@ gst_rtp_h263_pay_push (GstRtpH263Pay * rtph263pay,
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
/*
* Copy the payload data in the buffer
*/
GST_DEBUG ("Copying memory");
memcpy (payload, (guint8 *) package->payload_start, package->payload_len);
/* /*
* timestamp the buffer * timestamp the buffer
*/ */
@ -1311,6 +1299,14 @@ gst_rtp_h263_pay_push (GstRtpH263Pay * rtph263pay,
gst_rtp_buffer_unmap (&rtp); gst_rtp_buffer_unmap (&rtp);
/*
* Copy the payload data in the buffer
*/
GST_DEBUG ("Copying memory");
gst_buffer_copy_into (package->outbuf, rtph263pay->current_buffer,
GST_BUFFER_COPY_MEMORY, package->payload_start - rtph263pay->map.data,
package->payload_len);
ret = ret =
gst_rtp_base_payload_push (GST_RTP_BASE_PAYLOAD (rtph263pay), gst_rtp_base_payload_push (GST_RTP_BASE_PAYLOAD (rtph263pay),
package->outbuf); package->outbuf);
@ -1343,8 +1339,7 @@ gst_rtp_h263_pay_A_fragment_push (GstRtpH263Pay * rtph263pay,
pack->gobn = context->gobs[first]->gobn; pack->gobn = context->gobs[first]->gobn;
pack->mode = GST_RTP_H263_PAYLOAD_HEADER_MODE_A; pack->mode = GST_RTP_H263_PAYLOAD_HEADER_MODE_A;
pack->outbuf = pack->outbuf = gst_rtp_buffer_new_allocate (pack->mode, 0, 0);
gst_rtp_buffer_new_allocate (pack->payload_len + pack->mode, 0, 0);
GST_DEBUG ("Sending len:%d data to push function", pack->payload_len); GST_DEBUG ("Sending len:%d data to push function", pack->payload_len);
@ -1400,8 +1395,7 @@ gst_rtp_h263_pay_B_fragment_push (GstRtpH263Pay * rtph263pay,
} }
pack->payload_len = pack->payload_end - pack->payload_start + 1; pack->payload_len = pack->payload_end - pack->payload_start + 1;
pack->outbuf = pack->outbuf = gst_rtp_buffer_new_allocate (pack->mode, 0, 0);
gst_rtp_buffer_new_allocate (pack->payload_len + pack->mode, 0, 0);
return gst_rtp_h263_pay_push (rtph263pay, context, pack); return gst_rtp_h263_pay_push (rtph263pay, context, pack);
} }
@ -1441,7 +1435,6 @@ gst_rtp_h263_pay_mode_B_fragment (GstRtpH263Pay * rtph263pay,
&boundry.end, &gob->end) != 0) { &boundry.end, &gob->end) != 0) {
GST_ERROR GST_ERROR
("The rest of the bits should be 0, exiting, because something bad happend"); ("The rest of the bits should be 0, exiting, because something bad happend");
gst_adapter_flush (rtph263pay->adapter, rtph263pay->available_data);
goto decode_error; goto decode_error;
} }
//The first GOB of a frame "has no" actual header - PICTURE header is his header //The first GOB of a frame "has no" actual header - PICTURE header is his header
@ -1613,8 +1606,7 @@ gst_rtp_h263_send_entire_frame (GstRtpH263Pay * rtph263pay,
GST_DEBUG ("Available data: %d", rtph263pay->available_data); GST_DEBUG ("Available data: %d", rtph263pay->available_data);
pack->outbuf = pack->outbuf =
gst_rtp_buffer_new_allocate (pack->payload_len + gst_rtp_buffer_new_allocate (GST_RTP_H263_PAYLOAD_HEADER_MODE_A, 0, 0);
GST_RTP_H263_PAYLOAD_HEADER_MODE_A, 0, 0);
return gst_rtp_h263_pay_push (rtph263pay, context, pack); return gst_rtp_h263_pay_push (rtph263pay, context, pack);
} }
@ -1639,16 +1631,15 @@ gst_rtp_h263_pay_flush (GstRtpH263Pay * rtph263pay)
GST_RTP_H263_PAYLOAD_HEADER_MODE_C); GST_RTP_H263_PAYLOAD_HEADER_MODE_C);
GST_DEBUG ("MTU: %d", context->mtu); GST_DEBUG ("MTU: %d", context->mtu);
rtph263pay->available_data = gst_adapter_available (rtph263pay->adapter); rtph263pay->available_data = gst_buffer_get_size (rtph263pay->current_buffer);
if (rtph263pay->available_data == 0) { if (rtph263pay->available_data == 0) {
ret = GST_FLOW_OK; ret = GST_FLOW_OK;
goto end; goto end;
} }
/* Get a pointer to all the data for the frame */ /* Get a pointer to all the data for the frame */
rtph263pay->data = gst_buffer_map (rtph263pay->current_buffer, &rtph263pay->map, GST_MAP_READ);
(guint8 *) gst_adapter_map (rtph263pay->adapter, rtph263pay->data = (guint8 *) rtph263pay->map.data;
rtph263pay->available_data);
/* Picture header */ /* Picture header */
context->piclayer = (GstRtpH263PayPic *) rtph263pay->data; context->piclayer = (GstRtpH263PayPic *) rtph263pay->data;
@ -1804,8 +1795,8 @@ gst_rtp_h263_pay_flush (GstRtpH263Pay * rtph263pay)
end: end:
gst_rtp_h263_pay_context_destroy (context, gst_rtp_h263_pay_context_destroy (context,
context->piclayer->ptype_srcformat); context->piclayer->ptype_srcformat);
gst_adapter_unmap (rtph263pay->adapter); gst_buffer_unmap (rtph263pay->current_buffer, &rtph263pay->map);
gst_adapter_flush (rtph263pay->adapter, rtph263pay->available_data); gst_buffer_replace (&rtph263pay->current_buffer, NULL);
return ret; return ret;
} }
@ -1822,8 +1813,10 @@ gst_rtp_h263_pay_handle_buffer (GstRTPBasePayload * payload, GstBuffer * buffer)
rtph263pay->first_ts = GST_BUFFER_PTS (buffer); rtph263pay->first_ts = GST_BUFFER_PTS (buffer);
gst_buffer_replace (&rtph263pay->current_buffer, buffer);
gst_buffer_unref (buffer);
/* we always encode and flush a full picture */ /* we always encode and flush a full picture */
gst_adapter_push (rtph263pay->adapter, buffer);
ret = gst_rtp_h263_pay_flush (rtph263pay); ret = gst_rtp_h263_pay_flush (rtph263pay);
GST_DEBUG ("-------------------- END FRAME ---------------"); GST_DEBUG ("-------------------- END FRAME ---------------");

View file

@ -24,7 +24,6 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/rtp/gstrtpbasepayload.h> #include <gst/rtp/gstrtpbasepayload.h>
#include <gst/base/gstadapter.h>
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_TYPE_RTP_H263_PAY \ #define GST_TYPE_RTP_H263_PAY \
@ -63,7 +62,9 @@ struct _GstRtpH263Pay
{ {
GstRTPBasePayload payload; GstRTPBasePayload payload;
GstAdapter *adapter; GstBuffer *current_buffer;
GstMapInfo map;
GstClockTime first_ts; GstClockTime first_ts;
gboolean prop_payload_mode; gboolean prop_payload_mode;
guint8 *data; guint8 *data;