summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2021-11-12 18:26:58 +0530
committerTim-Philipp Müller <tim@centricular.com>2021-11-20 17:29:24 +0000
commitde7fcdeaa5717b031e1e15d1a9dd7ab02b271b8a (patch)
tree41a984d390f1917f0a588ebff884083cdffa052f
parentb42a19ac10f2bdd4a0117d38f8c65b0bc5bb40d2 (diff)
downloadgstreamer-plugins-base-de7fcdeaa5717b031e1e15d1a9dd7ab02b271b8a.tar.gz
audio-resampler: Fix segfault when we can't output any frames
Sometimes the resampler has enough space to store all the incoming samples without outputting anything. When this happens, gst_audio_resampler_get_out_frames() returns 0. In that case, the resampler should consume samples and just return. Otherwise, we get a segfault when gst_audio_resampler_resample() tries to resample into a NULL 'out' pointer. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1286>
-rw-r--r--gst-libs/gst/audio/audio-resampler.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/gst-libs/gst/audio/audio-resampler.c b/gst-libs/gst/audio/audio-resampler.c
index 69c14c776..5e65da5b6 100644
--- a/gst-libs/gst/audio/audio-resampler.c
+++ b/gst-libs/gst/audio/audio-resampler.c
@@ -1662,12 +1662,16 @@ gst_audio_resampler_get_out_frames (GstAudioResampler * resampler,
GST_LOG ("need %d = %d + %d + %d, avail %d = %d + %d", (gint) need,
resampler->n_taps, resampler->samp_index, resampler->skip,
(gint) avail, (gint) resampler->samples_avail, (gint) in_frames);
- if (avail < need)
+ if (avail < need) {
+ GST_LOG ("avail %d < need %d", (int) avail, (int) need);
return 0;
+ }
out = (avail - need) * resampler->out_rate;
- if (out < resampler->samp_phase)
+ if (out < resampler->samp_phase) {
+ GST_LOG ("out %d < samp_phase %d", (int) out, (int) resampler->samp_phase);
return 0;
+ }
out = ((out - resampler->samp_phase) / resampler->in_rate) + 1;
GST_LOG ("out %d = ((%d * %d - %d) / %d) + 1", (gint) out,
@@ -1775,7 +1779,10 @@ gst_audio_resampler_resample (GstAudioResampler * resampler,
resampler->samples_avail = samples_avail += in_frames;
need = resampler->n_taps + resampler->samp_index;
- if (G_UNLIKELY (samples_avail < need)) {
+ if (G_UNLIKELY (samples_avail < need || out_frames == 0)) {
+ GST_LOG ("not enough samples to start: need %" G_GSIZE_FORMAT ", avail %"
+ G_GSIZE_FORMAT ", out %" G_GSIZE_FORMAT, samples_avail, need,
+ out_frames);
/* not enough samples to start */
return;
}