gstpay: use bufferlist to avoid memcpy

This commit is contained in:
Wim Taymans 2013-04-09 16:52:21 +02:00
parent 3d7d757521
commit 91a3afc4dc

View file

@ -141,9 +141,14 @@ gst_rtp_gst_pay_flush (GstRtpGSTPay * rtpgstpay, GstClockTime timestamp)
GstFlowReturn ret; GstFlowReturn ret;
guint avail; guint avail;
guint frag_offset; guint frag_offset;
GstBufferList *list;
frag_offset = 0; frag_offset = 0;
avail = gst_adapter_available (rtpgstpay->adapter); avail = gst_adapter_available (rtpgstpay->adapter);
if (avail == 0)
return GST_FLOW_OK;
list = gst_buffer_list_new ();
while (avail) { while (avail) {
guint towrite; guint towrite;
@ -152,6 +157,7 @@ gst_rtp_gst_pay_flush (GstRtpGSTPay * rtpgstpay, GstClockTime timestamp)
guint packet_len; guint packet_len;
GstBuffer *outbuf; GstBuffer *outbuf;
GstRTPBuffer rtp = { NULL }; GstRTPBuffer rtp = { NULL };
GstBuffer *paybuf;
/* this will be the total lenght of the packet */ /* this will be the total lenght of the packet */
@ -163,8 +169,8 @@ gst_rtp_gst_pay_flush (GstRtpGSTPay * rtpgstpay, GstClockTime timestamp)
/* this is the payload length */ /* this is the payload length */
payload_len = gst_rtp_buffer_calc_payload_len (towrite, 0, 0); payload_len = gst_rtp_buffer_calc_payload_len (towrite, 0, 0);
/* create buffer to hold the payload */ /* create buffer to hold the header */
outbuf = gst_rtp_buffer_new_allocate (payload_len, 0, 0); outbuf = gst_rtp_buffer_new_allocate (8, 0, 0);
gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp); gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp);
payload = gst_rtp_buffer_get_payload (&rtp); payload = gst_rtp_buffer_get_payload (&rtp);
@ -192,11 +198,6 @@ gst_rtp_gst_pay_flush (GstRtpGSTPay * rtpgstpay, GstClockTime timestamp)
payload += 8; payload += 8;
payload_len -= 8; payload_len -= 8;
GST_DEBUG_OBJECT (rtpgstpay, "copy %u bytes from adapter", payload_len);
gst_adapter_copy (rtpgstpay->adapter, payload, 0, payload_len);
gst_adapter_flush (rtpgstpay->adapter, payload_len);
frag_offset += payload_len; frag_offset += payload_len;
avail -= payload_len; avail -= payload_len;
@ -205,28 +206,26 @@ gst_rtp_gst_pay_flush (GstRtpGSTPay * rtpgstpay, GstClockTime timestamp)
gst_rtp_buffer_unmap (&rtp); gst_rtp_buffer_unmap (&rtp);
/* create a new buf to hold the payload */
GST_DEBUG_OBJECT (rtpgstpay, "take %u bytes from adapter", payload_len);
paybuf = gst_adapter_take_buffer (rtpgstpay->adapter, payload_len);
/* create a new group to hold the rtp header and the payload */
gst_buffer_append (outbuf, paybuf);
GST_BUFFER_TIMESTAMP (outbuf) = timestamp; GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
ret = gst_rtp_base_payload_push (GST_RTP_BASE_PAYLOAD (rtpgstpay), outbuf); /* and add to list */
if (ret != GST_FLOW_OK) gst_buffer_list_insert (list, -1, outbuf);
goto push_failed;
} }
/* push the whole buffer list at once */
ret = gst_rtp_base_payload_push_list (GST_RTP_BASE_PAYLOAD (rtpgstpay), list);
rtpgstpay->flags &= 0x70; rtpgstpay->flags &= 0x70;
rtpgstpay->etype = 0; rtpgstpay->etype = 0;
return GST_FLOW_OK;
/* ERRORS */
push_failed:
{
GST_DEBUG_OBJECT (rtpgstpay, "push failed %d (%s)", ret,
gst_flow_get_name (ret));
gst_adapter_clear (rtpgstpay->adapter);
rtpgstpay->flags &= 0x70;
rtpgstpay->etype = 0;
return ret; return ret;
} }
}
static GstBuffer * static GstBuffer *
make_data_buffer (GstRtpGSTPay * rtpgstpay, gchar * data, guint size) make_data_buffer (GstRtpGSTPay * rtpgstpay, gchar * data, guint size)