From 86b0a0d6d0a277f5e55e06ea6bb2bf9397fb4e9a Mon Sep 17 00:00:00 2001 From: "Reynaldo H. Verdejo Pinochet" Date: Thu, 19 Dec 2013 17:41:31 -0300 Subject: [PATCH] gstaudiobasesink: Refactor alignment computation for clarity --- gst-libs/gst/audio/gstaudiobasesink.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/gst-libs/gst/audio/gstaudiobasesink.c b/gst-libs/gst/audio/gstaudiobasesink.c index 288896bb51..44eede3877 100644 --- a/gst-libs/gst/audio/gstaudiobasesink.c +++ b/gst-libs/gst/audio/gstaudiobasesink.c @@ -1533,22 +1533,18 @@ gst_audio_base_sink_get_alignment (GstAudioBaseSink * sink, gboolean discont = FALSE; gint rate; - /* now try to align the sample to the previous one, first see how big the - * difference is. */ - if (sample_offset >= sink->next_sample) - sample_diff = sample_offset - sink->next_sample; - else - sample_diff = sink->next_sample - sample_offset; + /* now try to align the sample to the previous one. */ - rate = GST_AUDIO_INFO_RATE (&ringbuf->spec.info); + /* calc align with previous sample and determine how big the + * difference is. */ + align = sink->next_sample - sample_offset; + sample_diff = ABS (align); /* calculate the max allowed drift in units of samples. */ + rate = GST_AUDIO_INFO_RATE (&ringbuf->spec.info); max_sample_diff = gst_util_uint64_scale_int (sink->priv->alignment_threshold, rate, GST_SECOND); - /* calc align with previous sample */ - align = sink->next_sample - sample_offset; - /* don't align if it means writing behind the read-segment */ if (sample_diff > headroom && align < 0) allow_align = FALSE;