Commit 40d06b6a authored by Wim Taymans's avatar Wim Taymans
Browse files

gst/rtp/gstrtpL16pay.*: Fill up to MTU using adapter.

Original commit message from CVS:
* gst/rtp/gstrtpL16pay.c: (gst_rtp_L16_pay_setcaps),
(gst_rtp_L16_pay_flush), (gst_rtp_L16_pay_handle_buffer):
* gst/rtp/gstrtpL16pay.h:
Fill up to MTU using adapter.
Timestamp rtp packets.
parent d7666d03
2007-01-25 Wim Taymans <wim@fluendo.com>
* gst/rtp/gstrtpL16pay.c: (gst_rtp_L16_pay_setcaps),
(gst_rtp_L16_pay_flush), (gst_rtp_L16_pay_handle_buffer):
* gst/rtp/gstrtpL16pay.h:
Fill up to MTU using adapter.
Timestamp rtp packets.
2007-01-25 Edward Hervey <edward@fluendo.com>
* gst/multipart/multipartmux.c: (gst_multipart_mux_collected):
......
......@@ -179,6 +179,9 @@ gst_rtp_L16_pay_setcaps (GstBaseRTPPayload * basepayload, GstCaps * caps)
gst_basertppayload_set_outcaps (basepayload,
"channels", G_TYPE_INT, channels, "rate", G_TYPE_INT, rate, NULL);
rtpL16pay->rate = rate;
rtpL16pay->channels = channels;
return TRUE;
/* ERRORS */
......@@ -194,42 +197,79 @@ no_channels:
}
}
static GstFlowReturn
gst_rtp_L16_pay_flush (GstRtpL16Pay * rtpL16pay, guint len)
{
GstBuffer *outbuf;
guint8 *payload;
GstFlowReturn ret;
guint samples;
GstClockTime duration;
/* now alloc output buffer */
outbuf = gst_rtp_buffer_new_allocate (len, 0, 0);
/* get payload, this is now writable */
payload = gst_rtp_buffer_get_payload (outbuf);
/* copy and flush data out of adapter into the RTP payload */
gst_adapter_copy (rtpL16pay->adapter, payload, 0, len);
gst_adapter_flush (rtpL16pay->adapter, len);
samples = len / (2 * rtpL16pay->channels);
duration = gst_util_uint64_scale_int (samples, GST_SECOND, rtpL16pay->rate);
GST_BUFFER_TIMESTAMP (outbuf) = rtpL16pay->first_ts;
GST_BUFFER_DURATION (outbuf) = duration;
/* increase count (in ts) of data pushed to basertppayload */
if (GST_CLOCK_TIME_IS_VALID (rtpL16pay->first_ts))
rtpL16pay->first_ts += duration;
ret = gst_basertppayload_push (GST_BASE_RTP_PAYLOAD (rtpL16pay), outbuf);
return ret;
}
static GstFlowReturn
gst_rtp_L16_pay_handle_buffer (GstBaseRTPPayload * basepayload,
GstBuffer * buffer)
{
GstRtpL16Pay *rtpL16pay;
GstFlowReturn ret;
guint size, payload_len;
GstBuffer *outbuf;
guint8 *payload, *data;
GstClockTime timestamp;
guint packet_len, mtu;
GstFlowReturn ret = GST_FLOW_OK;
guint payload_len;
GstClockTime timestamp, duration;
guint mtu, avail;
rtpL16pay = GST_RTP_L16_PAY (basepayload);
mtu = GST_BASE_RTP_PAYLOAD_MTU (rtpL16pay);
size = GST_BUFFER_SIZE (buffer);
data = GST_BUFFER_DATA (buffer);
timestamp = GST_BUFFER_TIMESTAMP (buffer);
duration = GST_BUFFER_DURATION (buffer);
GST_DEBUG_OBJECT (basepayload, "got %d bytes", size);
if (GST_BUFFER_IS_DISCONT (buffer))
gst_adapter_clear (rtpL16pay->adapter);
payload_len = size;
avail = gst_adapter_available (rtpL16pay->adapter);
if (avail == 0) {
rtpL16pay->first_ts = timestamp;
}
/* get packet len to check against MTU */
packet_len = gst_rtp_buffer_calc_packet_len (payload_len, 0, 0);
/* push buffer in adapter */
gst_adapter_push (rtpL16pay->adapter, buffer);
/* now alloc output buffer */
outbuf = gst_rtp_buffer_new_allocate (payload_len, 0, 0);
/* get payload len for MTU */
payload_len = gst_rtp_buffer_calc_payload_len (mtu, 0, 0);
/* get payload, this is now writable */
payload = gst_rtp_buffer_get_payload (outbuf);
gst_buffer_unref (buffer);
ret = gst_basertppayload_push (basepayload, outbuf);
/* flush complete MTU while we have enough data in the adapter */
while (avail >= payload_len) {
/* flush payload_len bytes */
ret = gst_rtp_L16_pay_flush (rtpL16pay, payload_len);
if (ret != GST_FLOW_OK)
break;
avail = gst_adapter_available (rtpL16pay->adapter);
}
return ret;
}
......
......@@ -44,7 +44,8 @@ struct _GstRtpL16Pay
{
GstBaseRTPPayload payload;
GstAdapter *adapter;
GstAdapter *adapter;
GstClockTime first_ts;
gint rate;
gint channels;
......
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