Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
audiobasesrc: Fix divide by zero assertion
GstAudioRingBufferSpec can be cleared from other thread, then
rate value will be zero

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1179>
  • Loading branch information
seungha-yang authored and GStreamer Marge Bot committed May 27, 2021
1 parent 9a502c1 commit 5ad59ce
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions gst-libs/gst/audio/gstaudiobasesrc.c
Expand Up @@ -305,21 +305,26 @@ gst_audio_base_src_get_time (GstClock * clock, GstAudioBaseSrc * src)
guint64 raw, samples;
guint delay;
GstClockTime result;
GstAudioRingBuffer *ringbuffer;
gint rate;

ringbuffer = src->ringbuffer;
if (!ringbuffer)
return GST_CLOCK_TIME_NONE;

if (G_UNLIKELY (src->ringbuffer == NULL
|| src->ringbuffer->spec.info.rate == 0))
rate = ringbuffer->spec.info.rate;
if (rate == 0)
return GST_CLOCK_TIME_NONE;

raw = samples = gst_audio_ring_buffer_samples_done (src->ringbuffer);
raw = samples = gst_audio_ring_buffer_samples_done (ringbuffer);

/* the number of samples not yet processed, this is still queued in the
* device (not yet read for capture). */
delay = gst_audio_ring_buffer_delay (src->ringbuffer);
delay = gst_audio_ring_buffer_delay (ringbuffer);

samples += delay;

result = gst_util_uint64_scale_int (samples, GST_SECOND,
src->ringbuffer->spec.info.rate);
result = gst_util_uint64_scale_int (samples, GST_SECOND, rate);

GST_DEBUG_OBJECT (src,
"processed samples: raw %" G_GUINT64_FORMAT ", delay %u, real %"
Expand Down

0 comments on commit 5ad59ce

Please sign in to comment.