From c84a6b964f84ad7c25b187451ee911fc7bb40736 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sat, 16 Jul 2005 17:13:35 +0000 Subject: [PATCH] gst-libs/gst/audio/gstbaseaudiosink.c: Align samples even if we have roundoff errors in the timestamp conversion. Original commit message from CVS: * gst-libs/gst/audio/gstbaseaudiosink.c: (gst_base_audio_sink_render): Align samples even if we have roundoff errors in the timestamp conversion. --- ChangeLog | 7 +++++++ gst-libs/gst/audio/gstbaseaudiosink.c | 18 +++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6ff35d3aaf..5cc7124b48 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-07-16 Wim Taymans + + * gst-libs/gst/audio/gstbaseaudiosink.c: + (gst_base_audio_sink_render): + Align samples even if we have roundoff errors in the + timestamp conversion. + 2005-07-16 Wim Taymans * docs/libs/tmpl/gstringbuffer.sgml: diff --git a/gst-libs/gst/audio/gstbaseaudiosink.c b/gst-libs/gst/audio/gstbaseaudiosink.c index 8381c277a2..984a91d892 100644 --- a/gst-libs/gst/audio/gstbaseaudiosink.c +++ b/gst-libs/gst/audio/gstbaseaudiosink.c @@ -322,6 +322,7 @@ gst_base_audio_sink_render (GstBaseSink * bsink, GstBuffer * buf) guint64 render_offset, in_offset; GstClockTime time, render_time; GstBaseAudioSink *sink = GST_BASE_AUDIO_SINK (bsink); + gint64 diff; /* can't do anything when we don't have the device */ if (!gst_ring_buffer_is_acquired (sink->ringbuffer)) @@ -336,7 +337,7 @@ gst_base_audio_sink_render (GstBaseSink * bsink, GstBuffer * buf) /* samples should be rendered based on their timestamp. All samples * arriving before the discont_start are to be trown away */ /* FIXME, for now we drop the sample completely, we should - * in fact clip the sample */ + * in fact clip the sample. Same for the segment_stop, actually. */ if (time < bsink->discont_start) return GST_FLOW_OK; @@ -347,8 +348,19 @@ gst_base_audio_sink_render (GstBaseSink * bsink, GstBuffer * buf) /* and bring the time to the offset in the buffer */ render_offset = render_time * sink->ringbuffer->spec.rate / GST_SECOND; - GST_DEBUG ("render time %" GST_TIME_FORMAT ", render offset %llu", - GST_TIME_ARGS (render_time), render_offset); + /* roundoff errors in timestamp conversion */ + diff = ABS ((gint64) render_offset - (gint64) sink->ringbuffer->next_sample); + + GST_DEBUG ("render time %" GST_TIME_FORMAT ", render offset %llu, diff %lld", + GST_TIME_ARGS (render_time), render_offset, diff); + + /* FIXME, depends on samplerate... Also the purpose of the OFFSET fields + * are to detect gaps and dropouts, we might better use them if they are + * valid. */ + if (diff < 10) { + /* just align with previous sample then */ + render_offset = -1; + } gst_ring_buffer_commit (sink->ringbuffer, render_offset, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));