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) ...@@ -156,16 +156,15 @@ gst_rtp_g729_pay_set_caps (GstRTPBasePayload * payload, GstCaps * caps)
} }
static GstFlowReturn static GstFlowReturn
gst_rtp_g729_pay_push (GstRTPG729Pay * rtpg729pay, gst_rtp_g729_pay_push (GstRTPG729Pay * rtpg729pay, GstBuffer * buf)
const guint8 * data, guint payload_len)
{ {
GstRTPBasePayload *basepayload; GstRTPBasePayload *basepayload;
GstClockTime duration; GstClockTime duration;
guint frames; guint frames;
GstBuffer *outbuf; GstBuffer *outbuf;
guint8 *payload;
GstFlowReturn ret; GstFlowReturn ret;
GstRTPBuffer rtp = { NULL }; GstRTPBuffer rtp = { NULL };
guint payload_len = gst_buffer_get_size (buf);
basepayload = GST_RTP_BASE_PAYLOAD (rtpg729pay); basepayload = GST_RTP_BASE_PAYLOAD (rtpg729pay);
...@@ -173,14 +172,10 @@ gst_rtp_g729_pay_push (GstRTPG729Pay * rtpg729pay, ...@@ -173,14 +172,10 @@ gst_rtp_g729_pay_push (GstRTPG729Pay * rtpg729pay,
payload_len, GST_TIME_ARGS (rtpg729pay->next_ts)); payload_len, GST_TIME_ARGS (rtpg729pay->next_ts));
/* create buffer to hold the payload */ /* 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); 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 */ /* set metadata */
frames = frames =
(payload_len / G729_FRAME_SIZE) + ((payload_len % G729_FRAME_SIZE) >> 1); (payload_len / G729_FRAME_SIZE) + ((payload_len % G729_FRAME_SIZE) >> 1);
...@@ -199,19 +194,11 @@ gst_rtp_g729_pay_push (GstRTPG729Pay * rtpg729pay, ...@@ -199,19 +194,11 @@ gst_rtp_g729_pay_push (GstRTPG729Pay * rtpg729pay,
} }
gst_rtp_buffer_unmap (&rtp); gst_rtp_buffer_unmap (&rtp);
ret = gst_rtp_base_payload_push (basepayload, outbuf); /* append payload */
outbuf = gst_buffer_append (outbuf, buf);
return ret;
}
static GstFlowReturn ret = gst_rtp_base_payload_push (basepayload, outbuf);
gst_rtp_g729_pay_push_and_free (GstRTPG729Pay * rtpg729pay,
guint8 * data, guint payload_len)
{
GstFlowReturn ret;
ret = gst_rtp_g729_pay_push (rtpg729pay, data, payload_len);
g_free (data);
return ret; return ret;
} }
...@@ -320,8 +307,8 @@ gst_rtp_g729_pay_handle_buffer (GstRTPBasePayload * payload, GstBuffer * buf) ...@@ -320,8 +307,8 @@ gst_rtp_g729_pay_handle_buffer (GstRTPBasePayload * payload, GstBuffer * buf)
if (GST_BUFFER_IS_DISCONT (buf)) { if (GST_BUFFER_IS_DISCONT (buf)) {
/* flush remainder */ /* flush remainder */
if (available > 0) { if (available > 0) {
gst_rtp_g729_pay_push_and_free (rtpg729pay, gst_rtp_g729_pay_push (rtpg729pay,
gst_adapter_take (adapter, available), available); gst_adapter_take_buffer_fast (adapter, available));
available = 0; available = 0;
} }
rtpg729pay->discont = TRUE; rtpg729pay->discont = TRUE;
...@@ -341,12 +328,7 @@ gst_rtp_g729_pay_handle_buffer (GstRTPBasePayload * payload, GstBuffer * buf) ...@@ -341,12 +328,7 @@ gst_rtp_g729_pay_handle_buffer (GstRTPBasePayload * payload, GstBuffer * buf)
rtpg729pay->next_ts = timestamp; rtpg729pay->next_ts = timestamp;
if (available == 0 && size >= min_payload_len && size <= max_payload_len) { if (available == 0 && size >= min_payload_len && size <= max_payload_len) {
GstMapInfo map; ret = gst_rtp_g729_pay_push (rtpg729pay, gst_buffer_ref (buf));
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);
return ret; return ret;
} }
...@@ -365,8 +347,8 @@ gst_rtp_g729_pay_handle_buffer (GstRTPBasePayload * payload, GstBuffer * buf) ...@@ -365,8 +347,8 @@ gst_rtp_g729_pay_handle_buffer (GstRTPBasePayload * payload, GstBuffer * buf)
(available / G729_FRAME_SIZE) * G729_FRAME_SIZE); (available / G729_FRAME_SIZE) * G729_FRAME_SIZE);
} }
ret = gst_rtp_g729_pay_push_and_free (rtpg729pay, ret = gst_rtp_g729_pay_push (rtpg729pay,
gst_adapter_take (adapter, payload_len), payload_len); gst_adapter_take_buffer_fast (adapter, payload_len));
available -= 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