mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-12 19:14:16 +00:00
rtpg729pay: Attach payload directly to output buffers instead of copying
This commit is contained in:
parent
0a71dbc80c
commit
cb0232ba4e
1 changed files with 11 additions and 29 deletions
|
@ -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,22 +194,14 @@ gst_rtp_g729_pay_push (GstRTPG729Pay * rtpg729pay,
|
|||
}
|
||||
gst_rtp_buffer_unmap (&rtp);
|
||||
|
||||
/* append payload */
|
||||
outbuf = gst_buffer_append (outbuf, buf);
|
||||
|
||||
ret = gst_rtp_base_payload_push (basepayload, outbuf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
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;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_rtp_g729_pay_recalc_rtp_time (GstRTPG729Pay * rtpg729pay, GstClockTime time)
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue