rtp: Use gst_adapter_take_buffer_fast() where possible in RTP payloaders

This commit is contained in:
Olivier Crête 2013-07-16 15:37:49 -04:00
parent 54bba4f60c
commit 54c5a7f690
6 changed files with 22 additions and 25 deletions

View file

@ -208,7 +208,7 @@ gst_rtp_gst_pay_flush (GstRtpGSTPay * rtpgstpay, GstClockTime timestamp)
/* 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);
paybuf = gst_adapter_take_buffer_fast (rtpgstpay->adapter, payload_len);
/* create a new group to hold the rtp header and the payload */
gst_buffer_append (outbuf, paybuf);

View file

@ -127,10 +127,9 @@ gst_rtp_mp2t_pay_flush (GstRTPMP2TPay * rtpmp2tpay)
while (avail > 0 && (ret == GST_FLOW_OK)) {
guint towrite;
guint8 *payload;
guint payload_len;
guint packet_len;
GstRTPBuffer rtp = { NULL };
GstBuffer *paybuf;
/* this will be the total length of the packet */
packet_len = gst_rtp_buffer_calc_packet_len (avail, 0, 0);
@ -147,16 +146,11 @@ gst_rtp_mp2t_pay_flush (GstRTPMP2TPay * rtpmp2tpay)
break;
/* create buffer to hold the payload */
outbuf = gst_rtp_buffer_new_allocate (payload_len, 0, 0);
outbuf = gst_rtp_buffer_new_allocate (0, 0, 0);
/* get payload */
gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp);
payload = gst_rtp_buffer_get_payload (&rtp);
/* copy stuff from adapter to payload */
gst_adapter_copy (rtpmp2tpay->adapter, payload, 0, payload_len);
gst_rtp_buffer_unmap (&rtp);
gst_adapter_flush (rtpmp2tpay->adapter, payload_len);
paybuf = gst_adapter_take_buffer_fast (rtpmp2tpay->adapter, payload_len);
outbuf = gst_buffer_append (outbuf, paybuf);
avail -= payload_len;
GST_BUFFER_TIMESTAMP (outbuf) = rtpmp2tpay->first_ts;

View file

@ -469,6 +469,7 @@ gst_rtp_mp4g_pay_flush (GstRtpMP4GPay * rtpmp4gpay)
guint payload_len;
guint packet_len;
GstRTPBuffer rtp = { NULL };
GstBuffer *paybuf;
/* this will be the total lenght of the packet */
packet_len = gst_rtp_buffer_calc_packet_len (avail, 0, 0);
@ -485,7 +486,7 @@ gst_rtp_mp4g_pay_flush (GstRtpMP4GPay * rtpmp4gpay)
packet_len, payload_len);
/* create buffer to hold the payload, also make room for the 4 header bytes. */
outbuf = gst_rtp_buffer_new_allocate (payload_len + 4, 0, 0);
outbuf = gst_rtp_buffer_new_allocate (4, 0, 0);
gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp);
@ -526,15 +527,14 @@ gst_rtp_mp4g_pay_flush (GstRtpMP4GPay * rtpmp4gpay)
payload[2] = (total & 0x1fe0) >> 5;
payload[3] = (total & 0x1f) << 3; /* we use 13 bits for the size, 3 bits index */
/* copy stuff from adapter to payload */
gst_adapter_copy (rtpmp4gpay->adapter, &payload[4], 0, payload_len);
gst_adapter_flush (rtpmp4gpay->adapter, payload_len);
/* marker only if the packet is complete */
gst_rtp_buffer_set_marker (&rtp, avail <= payload_len);
gst_rtp_buffer_unmap (&rtp);
paybuf = gst_adapter_take_buffer_fast (rtpmp4gpay->adapter, payload_len);
outbuf = gst_buffer_append (outbuf, paybuf);
GST_BUFFER_TIMESTAMP (outbuf) = rtpmp4gpay->first_timestamp;
GST_BUFFER_DURATION (outbuf) = rtpmp4gpay->first_duration;

View file

@ -275,7 +275,8 @@ gst_rtp_mp4v_pay_flush (GstRtpMP4VPay * rtpmp4vpay)
outbuf = gst_rtp_buffer_new_allocate (0, 0, 0);
/* Take buffer with the payload from the adapter */
outbuf_data = gst_adapter_take_buffer (rtpmp4vpay->adapter, payload_len);
outbuf_data = gst_adapter_take_buffer_fast (rtpmp4vpay->adapter,
payload_len);
avail -= payload_len;

View file

@ -189,6 +189,7 @@ gst_rtp_mpa_pay_flush (GstRtpMPAPay * rtpmpapay)
guint payload_len;
guint packet_len;
GstRTPBuffer rtp = { NULL };
GstBuffer *paybuf;
/* this will be the total length of the packet */
packet_len = gst_rtp_buffer_calc_packet_len (4 + avail, 0, 0);
@ -200,7 +201,7 @@ gst_rtp_mpa_pay_flush (GstRtpMPAPay * rtpmpapay)
payload_len = gst_rtp_buffer_calc_payload_len (towrite, 0, 0);
/* create buffer to hold the payload */
outbuf = gst_rtp_buffer_new_allocate (payload_len, 0, 0);
outbuf = gst_rtp_buffer_new_allocate (4, 0, 0);
gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp);
@ -221,9 +222,6 @@ gst_rtp_mpa_pay_flush (GstRtpMPAPay * rtpmpapay)
payload[2] = frag_offset >> 8;
payload[3] = frag_offset & 0xff;
gst_adapter_copy (rtpmpapay->adapter, &payload[4], 0, payload_len);
gst_adapter_flush (rtpmpapay->adapter, payload_len);
avail -= payload_len;
frag_offset += payload_len;
@ -232,6 +230,9 @@ gst_rtp_mpa_pay_flush (GstRtpMPAPay * rtpmpapay)
gst_rtp_buffer_unmap (&rtp);
paybuf = gst_adapter_take_buffer_fast (rtpmpapay->adapter, payload_len);
outbuf = gst_buffer_append (outbuf, paybuf);
GST_BUFFER_TIMESTAMP (outbuf) = rtpmpapay->first_ts;
GST_BUFFER_DURATION (outbuf) = rtpmpapay->duration;

View file

@ -178,6 +178,7 @@ gst_rtp_mpv_pay_flush (GstRTPMPVPay * rtpmpvpay)
guint packet_len;
guint payload_len;
GstRTPBuffer rtp = { NULL };
GstBuffer *paybuf;
packet_len = gst_rtp_buffer_calc_packet_len (avail, 4, 0);
@ -185,7 +186,7 @@ gst_rtp_mpv_pay_flush (GstRTPMPVPay * rtpmpvpay)
payload_len = gst_rtp_buffer_calc_payload_len (towrite, 4, 0);
outbuf = gst_rtp_buffer_new_allocate (payload_len, 4, 0);
outbuf = gst_rtp_buffer_new_allocate (4, 0, 0);
gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp);
@ -205,14 +206,14 @@ gst_rtp_mpv_pay_flush (GstRTPMPVPay * rtpmpvpay)
*/
memset (payload, 0x0, 4);
gst_adapter_copy (rtpmpvpay->adapter, payload + 4, 0, payload_len);
gst_adapter_flush (rtpmpvpay->adapter, payload_len);
avail -= payload_len;
gst_rtp_buffer_set_marker (&rtp, avail == 0);
gst_rtp_buffer_unmap (&rtp);
paybuf = gst_adapter_take_buffer_fast (rtpmpvpay->adapter, payload_len);
outbuf = gst_buffer_append (outbuf, paybuf);
GST_BUFFER_TIMESTAMP (outbuf) = rtpmpvpay->first_ts;
ret = gst_rtp_base_payload_push (GST_RTP_BASE_PAYLOAD (rtpmpvpay), outbuf);