mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-17 03:35:21 +00:00
rtpsbcpay: Fix timestamping
We were just picking the timestamp of the last buffer pushed into our adapter before we had enough data to push out. This fixes things to figure out how large each frame is and what duration it covers, so we can set both the timestamp and duration correctly. Also adds some DISCONT handling.
This commit is contained in:
parent
25526ed7f3
commit
10a16a6321
2 changed files with 24 additions and 6 deletions
|
@ -157,6 +157,8 @@ gst_rtp_sbc_pay_set_caps (GstRTPBasePayload * payload, GstCaps * caps)
|
|||
bitpool, channel_mode);
|
||||
|
||||
sbcpay->frame_length = frame_len;
|
||||
sbcpay->frame_duration = ((blocks * subbands) * GST_SECOND) / rate;
|
||||
sbcpay->last_timestamp = GST_CLOCK_TIME_NONE;
|
||||
|
||||
gst_rtp_base_payload_set_options (payload, "audio", TRUE, "SBC", rate);
|
||||
|
||||
|
@ -214,9 +216,12 @@ gst_rtp_sbc_pay_flush_buffers (GstRtpSBCPay * sbcpay)
|
|||
g_quark_from_static_string (GST_META_TAG_AUDIO_STR));
|
||||
outbuf = gst_buffer_append (outbuf, paybuf);
|
||||
|
||||
/* FIXME: what about duration? */
|
||||
GST_BUFFER_PTS (outbuf) = sbcpay->timestamp;
|
||||
GST_DEBUG_OBJECT (sbcpay, "Pushing %d bytes", payload_length);
|
||||
GST_BUFFER_PTS (outbuf) = sbcpay->last_timestamp;
|
||||
GST_BUFFER_DURATION (outbuf) = frame_count * sbcpay->frame_duration;
|
||||
GST_DEBUG_OBJECT (sbcpay, "Pushing %d bytes: %" GST_TIME_FORMAT,
|
||||
payload_length, GST_TIME_ARGS (GST_BUFFER_PTS (outbuf)));
|
||||
|
||||
sbcpay->last_timestamp += frame_count * sbcpay->frame_duration;
|
||||
|
||||
return gst_rtp_base_payload_push (GST_RTP_BASE_PAYLOAD (sbcpay), outbuf);
|
||||
}
|
||||
|
@ -230,7 +235,19 @@ gst_rtp_sbc_pay_handle_buffer (GstRTPBasePayload * payload, GstBuffer * buffer)
|
|||
/* FIXME check for negotiation */
|
||||
|
||||
sbcpay = GST_RTP_SBC_PAY (payload);
|
||||
sbcpay->timestamp = GST_BUFFER_PTS (buffer);
|
||||
|
||||
if (GST_BUFFER_IS_DISCONT (buffer)) {
|
||||
/* Try to flush whatever's left */
|
||||
gst_rtp_sbc_pay_flush_buffers (sbcpay);
|
||||
/* Drop the rest */
|
||||
gst_adapter_flush (sbcpay->adapter,
|
||||
gst_adapter_available (sbcpay->adapter));
|
||||
/* Reset timestamps */
|
||||
sbcpay->last_timestamp = GST_CLOCK_TIME_NONE;
|
||||
}
|
||||
|
||||
if (sbcpay->last_timestamp == GST_CLOCK_TIME_NONE)
|
||||
sbcpay->last_timestamp = GST_BUFFER_PTS (buffer);
|
||||
|
||||
gst_adapter_push (sbcpay->adapter, buffer);
|
||||
|
||||
|
@ -347,7 +364,7 @@ gst_rtp_sbc_pay_init (GstRtpSBCPay * self)
|
|||
{
|
||||
self->adapter = gst_adapter_new ();
|
||||
self->frame_length = 0;
|
||||
self->timestamp = 0;
|
||||
self->last_timestamp = GST_CLOCK_TIME_NONE;
|
||||
|
||||
self->min_frames = DEFAULT_MIN_FRAMES;
|
||||
}
|
||||
|
|
|
@ -46,9 +46,10 @@ struct _GstRtpSBCPay {
|
|||
GstRTPBasePayload base;
|
||||
|
||||
GstAdapter *adapter;
|
||||
GstClockTime timestamp;
|
||||
GstClockTime last_timestamp;
|
||||
|
||||
guint frame_length;
|
||||
GstClockTime frame_duration;
|
||||
|
||||
guint min_frames;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue