[vlc-commits] [Git][videolan/vlc][master] 8 commits: scaletempo: handle a NULL block from the resampler

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Fri Nov 6 16:23:22 UTC 2026



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
88129438 by Pierre Bogdanovscky at 2026-11-06T17:05:29+01:00
scaletempo: handle a NULL block from the resampler

Work item : #30206

- - - - -
026f2a84 by Pierre Bogdanovscky at 2026-11-06T17:05:29+01:00
soxr: fix error paths

On soxr_process failure, the released output block was returned.
When SoXR_Resample() failed, Resample() released the input block a
second time, and lost the flushed output; the flushed output was
also lost when gathering failed.

Work item : #30206

- - - - -
2ebea65d by Pierre Bogdanovscky at 2026-11-06T17:05:29+01:00
soxr: never return empty blocks

SoXR can keep all the input frames to fill its filter: return NULL then.

Work item : #30206

- - - - -
189a2e70 by Pierre Bogdanovscky at 2026-11-06T17:05:29+01:00
speex: never return empty blocks

The resampler can keep all the input frames: return NULL then.

Work item : #30206

- - - - -
8321a85b by Pierre Bogdanovscky at 2026-11-06T17:05:29+01:00
spatialaudio: don't output empty blocks

Work item : #30206

- - - - -
d0d3b0d5 by Pierre Bogdanovscky at 2026-11-06T17:05:29+01:00
src: don't output empty blocks

Work item : #30206

- - - - -
48491514 by Pierre Bogdanovscky at 2026-11-06T17:05:29+01:00
ugly: don't output empty blocks

Work item : #30206

- - - - -
f97acd05 by Pierre Bogdanovscky at 2026-11-06T17:05:29+01:00
aout: assert blocks sent to play are not empty

Work item : #30206

- - - - -


7 changed files:

- modules/audio_filter/channel_mixer/spatialaudio.cpp
- modules/audio_filter/resampler/soxr.c
- modules/audio_filter/resampler/speex.c
- modules/audio_filter/resampler/src.c
- modules/audio_filter/resampler/ugly.c
- modules/audio_filter/scaletempo.c
- src/audio_output/dec.c


Changes:

=====================================
modules/audio_filter/channel_mixer/spatialaudio.cpp
=====================================
@@ -184,6 +184,15 @@ static block_t *Mix( filter_t *p_filter, block_t *p_buf )
     const size_t i_outputBlockSize = sizeof(float) * p_sys->i_outputNb * AMB_BLOCK_TIME_LEN;
     const size_t i_nbBlocks = p_sys->inputSamples.size() * sizeof(float) / i_inputBlockSize;
 
+    if (i_nbBlocks == 0)
+    {
+        /* The next output starts with the frames queued from this block */
+        if (p_sys->i_inputPTS == 0)
+            p_sys->i_inputPTS = p_buf->i_pts;
+        block_Release(p_buf);
+        return NULL;
+    }
+
     block_t *p_out_buf = block_Alloc(i_outputBlockSize * i_nbBlocks);
     if (unlikely(p_out_buf == NULL))
     {


=====================================
modules/audio_filter/resampler/soxr.c
=====================================
@@ -273,8 +273,7 @@ SoXR_Resample( filter_t *p_filter, soxr_t soxr, block_t *p_in, size_t i_olen )
     if( error )
     {
         msg_Err( p_filter, "soxr_process failed: %s", soxr_strerror( error ) );
-        block_Release( p_out );
-        goto error;
+        goto drop;
     }
     if( unlikely( i_idone < i_ilen ) )
         msg_Err( p_filter, "lost %zd of %zd input frames",
@@ -297,11 +296,23 @@ SoXR_Resample( filter_t *p_filter, soxr_t soxr, block_t *p_in, size_t i_olen )
         p_sys->last_soxr = NULL;
     }
 
-error:
+    /* SoXR can keep all the input frames to fill its filter: never return an
+     * empty block */
+    if( i_odone == 0 )
+        goto drop;
+
     if( p_in && p_out != p_in )
         block_Release( p_in );
 
     return p_out;
+
+drop:
+    if( p_out != p_in )
+        block_Release( p_out );
+error:
+    if( p_in )
+        block_Release( p_in );
+    return NULL;
 }
 
 static size_t
@@ -361,11 +372,9 @@ Resample( filter_t *p_filter, block_t *p_in )
     {
         assert( !p_out );
         p_out = SoXR_Resample( p_filter, soxr, p_in, i_olen );
-        if( !p_out )
-            goto error;
     }
 
-    if( p_flushed_out )
+    if( p_flushed_out && p_out )
     {
         /* Prepend the flushed output data to p_out */
         const unsigned i_nb_samples = p_flushed_out->i_nb_samples
@@ -374,14 +383,19 @@ Resample( filter_t *p_filter, block_t *p_in )
         block_ChainAppend( &p_flushed_out, p_out );
         p_out = block_ChainGather( p_flushed_out );
         if( !p_out )
-            goto error;
+        {
+            block_ChainRelease( p_flushed_out );
+            return NULL;
+        }
         p_out->i_nb_samples = i_nb_samples;
     }
+    else if( p_flushed_out )
+        p_out = p_flushed_out;
+
+    if( !p_out )
+        return NULL;
     p_out->i_pts = i_pts;
     return p_out;
-error:
-    block_Release( p_in );
-    return NULL;
 }
 
 static block_t *


=====================================
modules/audio_filter/resampler/speex.c
=====================================
@@ -173,6 +173,15 @@ static block_t *Resample (filter_t *filter, block_t *in)
         msg_Err (filter, "lost %"PRIu32" of %u input frames",
                  in->i_nb_samples - ilen, in->i_nb_samples);
 
+    /* The resampler can keep all the input frames: never return an empty
+     * block */
+    if (olen == 0)
+    {
+        block_Release (out);
+        out = NULL;
+        goto error;
+    }
+
     out->i_buffer = olen * framesize;
     out->i_nb_samples = olen;
     out->i_pts = in->i_pts;


=====================================
modules/audio_filter/resampler/src.c
=====================================
@@ -162,6 +162,15 @@ static block_t *Resample (filter_t *filter, block_t *in)
         msg_Err (filter, "lost %ld of %ld input frames",
                  src.input_frames - src.input_frames_used, src.input_frames);
 
+    /* The sinc converters can keep all the input frames for their filter
+     * delay: never return an empty block */
+    if (src.output_frames_gen == 0)
+    {
+        block_Release (out);
+        out = NULL;
+        goto error;
+    }
+
     out->i_buffer = src.output_frames_gen * framesize;
     out->i_nb_samples = src.output_frames_gen;
     out->i_pts = in->i_pts;


=====================================
modules/audio_filter/resampler/ugly.c
=====================================
@@ -99,6 +99,13 @@ static block_t *DoWork( filter_t * p_filter, block_t * p_in_buf )
     const unsigned framesize = (p_filter->fmt_in.audio.i_bitspersample / 8)
         * aout_FormatNbChannels( &p_filter->fmt_in.audio );
 
+    /* Downsampling a block shorter than in_rate / out_rate frames */
+    if( i_out_nb == 0 )
+    {
+        block_Release( p_in_buf );
+        return NULL;
+    }
+
     if( p_filter->fmt_out.audio.i_rate > p_filter->fmt_in.audio.i_rate )
     {
         p_out_buf = block_Alloc( i_out_nb * framesize );


=====================================
modules/audio_filter/scaletempo.c
=====================================
@@ -614,6 +614,9 @@ static block_t *DoPitchWork( filter_t * p_filter, block_t * p_in_buf )
 
     /* Change rate, thus changing pitch */
     p_in_buf = p->resampler->ops->filter_audio( p->resampler, p_in_buf );
+    /* The resampler may keep all the frames for now */
+    if( p_in_buf == NULL )
+        return NULL;
 
     /* Change tempo while preserving shifted pitch */
     return DoWork( p_filter, p_in_buf );


=====================================
src/audio_output/dec.c
=====================================
@@ -566,14 +566,23 @@ static void stream_StopResampling(vlc_aout_stream *stream)
     aout_FiltersAdjustResampling (stream->filters, 0);
 }
 
+static void stream_Play(audio_output_t *aout, block_t *block,
+                        vlc_tick_t date)
+{
+    /* Output modules don't handle empty blocks */
+    assert(block->i_buffer > 0);
+    aout->play(aout, block, date);
+}
+
 static void stream_Silence (vlc_aout_stream *stream, vlc_tick_t length, vlc_tick_t pts)
 {
+    assert(length > 0);
     audio_output_t *aout = aout_stream_aout(stream);
     const audio_sample_format_t *fmt = &stream->mixer_format;
     size_t frames = samples_from_vlc_tick(length, fmt->i_rate);
+    size_t size = frames * fmt->i_bytes_per_frame / fmt->i_frame_length;
 
-    block_t *block = block_Alloc (frames * fmt->i_bytes_per_frame
-                                  / fmt->i_frame_length);
+    block_t *block = block_Alloc (size);
     if (unlikely(block == NULL))
         return; /* uho! */
 
@@ -591,7 +600,7 @@ static void stream_Silence (vlc_aout_stream *stream, vlc_tick_t length, vlc_tick
                                  stream->sync.rate, NULL);
     vlc_clock_Unlock(stream->sync.clock);
     stream->timing.played_samples += block->i_nb_samples;
-    aout->play(aout, block, system_pts);
+    stream_Play(aout, block, system_pts);
 }
 
 static void stream_HandleDrift(vlc_aout_stream *stream, vlc_tick_t drift,
@@ -913,7 +922,7 @@ int vlc_aout_stream_Play(vlc_aout_stream *stream, block_t *block)
     /* Output */
     stream->sync.played = true;
     stream->timing.played_samples += block->i_nb_samples;
-    aout->play(aout, block, play_date);
+    stream_Play(aout, block, play_date);
 
     atomic_fetch_add_explicit(&stream->buffers_played, 1, memory_order_relaxed);
     return ret;
@@ -1057,7 +1066,7 @@ void vlc_aout_stream_Drain(vlc_aout_stream *stream)
         {
             assert (block->i_pts != VLC_TICK_INVALID);
             stream->timing.played_samples += block->i_nb_samples;
-            aout->play(aout, block, vlc_tick_now());
+            stream_Play(aout, block, vlc_tick_now());
         }
     }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/2faf503918df22f1da609bacf66c5f55f9a3db35...f97acd05bd12ff0a74518319344149117c800f8b

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/2faf503918df22f1da609bacf66c5f55f9a3db35...f97acd05bd12ff0a74518319344149117c800f8b
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list