mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-26 18:20:44 +00:00
gstpay: use bufferlist to avoid memcpy
This commit is contained in:
parent
3d7d757521
commit
91a3afc4dc
1 changed files with 21 additions and 22 deletions
|
@ -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,27 +206,25 @@ 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;
|
return ret;
|
||||||
|
|
||||||
/* 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstBuffer *
|
static GstBuffer *
|
||||||
|
|
Loading…
Reference in a new issue