Commit cb0232ba authored by Sebastian Dröge's avatar Sebastian Dröge 🍵
Browse files

rtpg729pay: Attach payload directly to output buffers instead of copying

parent 0a71dbc8
......@@ -156,16 +156,15 @@ gst_rtp_g729_pay_set_caps (GstRTPBasePayload * payload, GstCaps * caps)
}
static GstFlowReturn
gst_rtp_g729_pay_push (GstRTPG729Pay * rtpg729pay,
const guint8 * data, guint payload_len)
gst_rtp_g729_pay_push (GstRTPG729Pay * rtpg729pay, GstBuffer * buf)
{
GstRTPBasePayload *basepayload;
GstClockTime duration;
guint frames;
GstBuffer *outbuf;
guint8 *payload;
GstFlowReturn ret;
GstRTPBuffer rtp = { NULL };
guint payload_len = gst_buffer_get_size (buf);
basepayload = GST_RTP_BASE_PAYLOAD (rtpg729pay);
......@@ -173,14 +172,10 @@ gst_rtp_g729_pay_push (GstRTPG729Pay * rtpg729pay,
payload_len, GST_TIME_ARGS (rtpg729pay->next_ts));
/* 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);
gst_rtp_buffer_map (outbuf, GST_MAP_READWRITE, &rtp);
/* copy payload */
payload = gst_rtp_buffer_get_payload (&rtp);
memcpy (payload, data, payload_len);
/* set metadata */
frames =
(payload_len / G729_FRAME_SIZE) + ((payload_len % G729_FRAME_SIZE) >> 1);
......@@ -199,19 +194,11 @@ gst_rtp_g729_pay_push (GstRTPG729Pay * rtpg729pay,
}
gst_rtp_buffer_unmap (&rtp);
ret = gst_rtp_base_payload_push (basepayload, outbuf);
return ret;
}
/* append payload */
outbuf = gst_buffer_append (outbuf, buf);
static GstFlowReturn
gst_rtp_g729_pay_push_and_free (GstRTPG729Pay * rtpg729pay,
guint8 * data, guint payload_len)
{
GstFlowReturn ret;
ret = gst_rtp_base_payload_push (basepayload, outbuf);
ret = gst_rtp_g729_pay_push (rtpg729pay, data, payload_len);
g_free (data);
return ret;
}
......@@ -320,8 +307,8 @@ gst_rtp_g729_pay_handle_buffer (GstRTPBasePayload * payload, GstBuffer * buf)
if (GST_BUFFER_IS_DISCONT (buf)) {
/* flush remainder */
if (available > 0) {
gst_rtp_g729_pay_push_and_free (rtpg729pay,
gst_adapter_take (adapter, available), available);
gst_rtp_g729_pay_push (rtpg729pay,
gst_adapter_take_buffer_fast (adapter, available));
available = 0;
}
rtpg729pay->discont = TRUE;
......@@ -341,12 +328,7 @@ gst_rtp_g729_pay_handle_buffer (GstRTPBasePayload * payload, GstBuffer * buf)
rtpg729pay->next_ts = timestamp;
if (available == 0 && size >= min_payload_len && size <= max_payload_len) {
GstMapInfo map;
gst_buffer_map (buf, &map, GST_MAP_READ);
ret = gst_rtp_g729_pay_push (rtpg729pay, map.data, map.size);
gst_buffer_unmap (buf, &map);
gst_buffer_unref (buf);
ret = gst_rtp_g729_pay_push (rtpg729pay, gst_buffer_ref (buf));
return ret;
}
......@@ -365,8 +347,8 @@ gst_rtp_g729_pay_handle_buffer (GstRTPBasePayload * payload, GstBuffer * buf)
(available / G729_FRAME_SIZE) * G729_FRAME_SIZE);
}
ret = gst_rtp_g729_pay_push_and_free (rtpg729pay,
gst_adapter_take (adapter, payload_len), payload_len);
ret = gst_rtp_g729_pay_push (rtpg729pay,
gst_adapter_take_buffer_fast (adapter, payload_len));
available -= payload_len;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment