[vlc-devel] [RFC PATCH 3/6] aout: don't wait from flush

Thomas Guillem thomas at gllm.fr
Thu Mar 16 16:43:22 CET 2017


---
 include/vlc_aout.h                      |  8 ++++----
 modules/audio_output/adummy.c           |  4 ++--
 modules/audio_output/alsa.c             | 10 ++++------
 modules/audio_output/amem.c             | 17 +++++++++++++----
 modules/audio_output/audiotrack.c       | 25 +++++--------------------
 modules/audio_output/audiounit_ios.m    |  2 +-
 modules/audio_output/coreaudio_common.c | 24 +++---------------------
 modules/audio_output/file.c             |  5 ++---
 modules/audio_output/mmdevice.c         |  4 ++--
 modules/audio_output/mmdevice.h         | 11 +----------
 modules/audio_output/pulse.c            | 11 +++--------
 modules/audio_output/sndio.c            |  5 ++---
 src/audio_output/aout_internal.h        |  4 ++--
 src/audio_output/dec.c                  | 15 ++++-----------
 src/audio_output/output.c               |  8 +++-----
 src/input/decoder.c                     |  8 ++++----
 16 files changed, 55 insertions(+), 106 deletions(-)

diff --git a/include/vlc_aout.h b/include/vlc_aout.h
index bbe7b4cbbe..7fc04ff146 100644
--- a/include/vlc_aout.h
+++ b/include/vlc_aout.h
@@ -141,10 +141,10 @@ struct audio_output
       * \param date timestamp when the pause or resume was requested
       * \note A stream must have been started when called.
       */
-    void (*flush)( audio_output_t *, bool wait);
-    /**< Flushes or drains the playback buffers (mandatory, cannot be NULL).
-      * \param wait true to wait for playback of pending buffers (drain),
-      *             false to discard pending buffers (flush)
+    void (*flush)(audio_output_t *);
+    /**< Flushes the playback buffers (mandatory, cannot be NULL).
+      * \note A stream must have been started when called.
+      */
       * \note A stream must have been started when called.
       */
     int (*volume_set)(audio_output_t *, float volume);
diff --git a/modules/audio_output/adummy.c b/modules/audio_output/adummy.c
index 0c330008cb..84d734b643 100644
--- a/modules/audio_output/adummy.c
+++ b/modules/audio_output/adummy.c
@@ -48,9 +48,9 @@ static void Play(audio_output_t *aout, block_t *block)
     (void) aout;
 }
 
-static void Flush(audio_output_t *aout, bool wait)
+static void Flush(audio_output_t *aout)
 {
-    (void) aout; (void) wait;
+    (void) aout;
 }
 
 static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
diff --git a/modules/audio_output/alsa.c b/modules/audio_output/alsa.c
index 580ebb06b1..ad2ec8a2a8 100644
--- a/modules/audio_output/alsa.c
+++ b/modules/audio_output/alsa.c
@@ -278,7 +278,7 @@ static int TimeGet (audio_output_t *aout, mtime_t *);
 static void Play (audio_output_t *, block_t *);
 static void Pause (audio_output_t *, bool, mtime_t);
 static void PauseDummy (audio_output_t *, bool, mtime_t);
-static void Flush (audio_output_t *, bool);
+static void Flush (audio_output_t *);
 
 /** Initializes an ALSA playback stream */
 static int Start (audio_output_t *aout, audio_sample_format_t *restrict fmt)
@@ -692,17 +692,15 @@ static void PauseDummy (audio_output_t *aout, bool pause, mtime_t date)
 /**
  * Flushes/drains the audio playback buffer.
  */
-static void Flush (audio_output_t *aout, bool wait)
+static void Flush (audio_output_t *aout)
 {
     snd_pcm_t *pcm = aout->sys->pcm;
 
-    if (wait)
-        snd_pcm_drain (pcm);
-    else
-        snd_pcm_drop (pcm);
+    snd_pcm_drop (pcm);
     snd_pcm_prepare (pcm);
 }
 
+/* TODO implement Drain with snd_pcm_drain (pcm); */
 
 /**
  * Releases the audio output.
diff --git a/modules/audio_output/amem.c b/modules/audio_output/amem.c
index 1821e46e07..99da35cc7e 100644
--- a/modules/audio_output/amem.c
+++ b/modules/audio_output/amem.c
@@ -98,14 +98,23 @@ static void Pause (audio_output_t *aout, bool paused, mtime_t date)
         cb (sys->opaque, date);
 }
 
-static void Flush (audio_output_t *aout, bool wait)
+static void Flush (audio_output_t *aout)
 {
     aout_sys_t *sys = aout->sys;
-    void (*cb) (void *) = wait ? sys->drain : sys->flush;
 
-    if (cb != NULL)
-        cb (sys->opaque);
+    if (sys->flush != NULL)
+        sys->flush (sys->opaque);
+}
+
+/* TODO Implement threaded drain
+static void Drain (audio_output_t *aout)
+{
+    aout_sys_t *sys = aout->sys;
+
+    if (sys->drain != NULL)
+        sys->drain (sys->opaque);
 }
+*/
 
 static int VolumeSet (audio_output_t *aout, float vol)
 {
diff --git a/modules/audio_output/audiotrack.c b/modules/audio_output/audiotrack.c
index 1a6b4f387b..c72620fd3f 100644
--- a/modules/audio_output/audiotrack.c
+++ b/modules/audio_output/audiotrack.c
@@ -1812,7 +1812,7 @@ bailout:
 }
 
 static void
-Flush( audio_output_t *p_aout, bool b_wait )
+Flush( audio_output_t *p_aout )
 {
     aout_sys_t *p_sys = p_aout->sys;
     JNIEnv *env;
@@ -1833,25 +1833,10 @@ Flush( audio_output_t *p_aout, bool b_wait )
      * that has not been played back will be discarded.  No-op if not stopped
      * or paused, or if the track's creation mode is not MODE_STREAM.
      */
-    if( b_wait )
-    {
-        /* Wait for the thread to process the circular buffer */
-        while( !p_sys->b_error
-            && p_sys->circular.i_read != p_sys->circular.i_write )
-            vlc_cond_wait( &p_sys->aout_cond, &p_sys->lock );
-        if( p_sys->b_error )
-            goto bailout;
-
-        JNI_AT_CALL_VOID( stop );
-        if( CHECK_AT_EXCEPTION( "stop" ) )
-            goto bailout;
-    } else
-    {
-        JNI_AT_CALL_VOID( pause );
-        if( CHECK_AT_EXCEPTION( "pause" ) )
-            goto bailout;
-        JNI_AT_CALL_VOID( flush );
-    }
+    JNI_AT_CALL_VOID( pause );
+    if( CHECK_AT_EXCEPTION( "pause" ) )
+        goto bailout;
+    JNI_AT_CALL_VOID( flush );
     p_sys->circular.i_read = p_sys->circular.i_write = 0;
 
     /* HACK: Before Android 4.4, the head position is not reset to zero and is
diff --git a/modules/audio_output/audiounit_ios.m b/modules/audio_output/audiounit_ios.m
index 0c7642fc3c..b23af07cdd 100644
--- a/modules/audio_output/audiounit_ios.m
+++ b/modules/audio_output/audiounit_ios.m
@@ -328,7 +328,7 @@ MuteSet(audio_output_t *p_aout, bool mute)
     {
         Pause(p_aout, mute, 0);
         if (mute)
-            ca_Flush(p_aout, false);
+            ca_Flush(p_aout);
     }
 
     return VLC_SUCCESS;
diff --git a/modules/audio_output/coreaudio_common.c b/modules/audio_output/coreaudio_common.c
index 406c30d743..520c64fbb1 100644
--- a/modules/audio_output/coreaudio_common.c
+++ b/modules/audio_output/coreaudio_common.c
@@ -92,30 +92,12 @@ ca_TimeGet(audio_output_t *p_aout, mtime_t *delay)
 }
 
 void
-ca_Flush(audio_output_t *p_aout, bool wait)
+ca_Flush(audio_output_t *p_aout)
 {
     struct aout_sys_common *p_sys = (struct aout_sys_common *) p_aout->sys;
 
-    if (wait)
-    {
-        int32_t i_bytes;
-
-        while (TPCircularBufferTail(&p_sys->circular_buffer, &i_bytes) != NULL)
-        {
-            /* Calculate the duration of the circular buffer, in order to wait
-             * for the render thread to play it all */
-            const mtime_t i_frame_us =
-                FramesToUs(p_sys, BytesToFrames(p_sys, i_bytes)) + 10000;
-
-            /* Don't sleep less than 10ms */
-            msleep(__MAX(i_frame_us, 10000));
-        }
-    }
-    else
-    {
-        /* flush circular buffer if data is left */
-        TPCircularBufferClear(&p_sys->circular_buffer);
-    }
+    /* flush circular buffer if data is left */
+    TPCircularBufferClear(&p_sys->circular_buffer);
 }
 
 void
diff --git a/modules/audio_output/file.c b/modules/audio_output/file.c
index e651dff825..d48b180d69 100644
--- a/modules/audio_output/file.c
+++ b/modules/audio_output/file.c
@@ -75,7 +75,7 @@ static const int pi_channels_maps[CHANNELS_MAX+1] =
  *****************************************************************************/
 static int     Open        ( vlc_object_t * );
 static void    Play        ( audio_output_t *, block_t * );
-static void    Flush       ( audio_output_t *, bool );
+static void    Flush       ( audio_output_t * );
 
 /*****************************************************************************
  * Module descriptor
@@ -330,11 +330,10 @@ static void Play( audio_output_t * p_aout, block_t *p_buffer )
     block_Release( p_buffer );
 }
 
-static void Flush( audio_output_t *aout, bool wait )
+static void Flush( audio_output_t *aout )
 {
     if( fflush( aout->sys->p_file ) )
         msg_Err( aout, "flush error: %s", vlc_strerror_c(errno) );
-    (void) wait;
 }
 
 static int Open(vlc_object_t *obj)
diff --git a/modules/audio_output/mmdevice.c b/modules/audio_output/mmdevice.c
index 1e16a4ca1a..26519e474b 100644
--- a/modules/audio_output/mmdevice.c
+++ b/modules/audio_output/mmdevice.c
@@ -162,13 +162,13 @@ static void Pause(audio_output_t *aout, bool paused, mtime_t date)
     (void) date;
 }
 
-static void Flush(audio_output_t *aout, bool wait)
+static void Flush(audio_output_t *aout)
 {
     aout_sys_t *sys = aout->sys;
     HRESULT hr;
 
     EnterMTA();
-    hr = aout_stream_Flush(sys->stream, wait);
+    hr = aout_stream_Flush(sys->stream);
     LeaveMTA();
 
     vlc_FromHR(aout, hr);
diff --git a/modules/audio_output/mmdevice.h b/modules/audio_output/mmdevice.h
index 51f5e427df..9e4e1dc50b 100644
--- a/modules/audio_output/mmdevice.h
+++ b/modules/audio_output/mmdevice.h
@@ -74,16 +74,7 @@ static inline HRESULT aout_stream_Pause(aout_stream_t *s, bool paused)
 
 static inline HRESULT aout_stream_Flush(aout_stream_t *s, bool wait)
 {
-    if (wait)
-    {   /* Loosy drain emulation */
-        mtime_t delay;
-
-        if (SUCCEEDED(aout_stream_TimeGet(s, &delay)))
-            Sleep((delay / (CLOCK_FREQ / 1000)) + 1);
-        return S_OK;
-    }
-    else
-        return (s->flush)(s);
+    return (s->flush)(s);
 }
 
 static inline
diff --git a/modules/audio_output/pulse.c b/modules/audio_output/pulse.c
index 38a0d6624e..cc995efb57 100644
--- a/modules/audio_output/pulse.c
+++ b/modules/audio_output/pulse.c
@@ -549,21 +549,16 @@ static void Pause(audio_output_t *aout, bool paused, mtime_t date)
 }
 
 /**
- * Flush or drain the playback stream
+ * Flush the playback stream
  */
-static void Flush(audio_output_t *aout, bool wait)
+static void Flush(audio_output_t *aout)
 {
     aout_sys_t *sys = aout->sys;
     pa_stream *s = sys->stream;
     pa_operation *op;
 
     pa_threaded_mainloop_lock(sys->mainloop);
-
-    if (wait)
-        op = pa_stream_drain(s, NULL, NULL);
-        /* TODO: wait for drain completion*/
-    else
-        op = pa_stream_flush(s, NULL, NULL);
+    op = pa_stream_flush(s, NULL, NULL);
     if (op != NULL)
         pa_operation_unref(op);
     sys->first_pts = VLC_TS_INVALID;
diff --git a/modules/audio_output/sndio.c b/modules/audio_output/sndio.c
index fb5f4bd35b..7dce88c313 100644
--- a/modules/audio_output/sndio.c
+++ b/modules/audio_output/sndio.c
@@ -45,7 +45,7 @@ vlc_module_end ()
 
 static int TimeGet (audio_output_t *, mtime_t *);
 static void Play (audio_output_t *, block_t *);
-static void Flush (audio_output_t *, bool);
+static void Flush (audio_output_t *);
 static int VolumeSet (audio_output_t *, float);
 static int MuteSet (audio_output_t *, bool);
 static void VolumeChanged (void *, unsigned);
@@ -238,7 +238,7 @@ static void Play (audio_output_t *aout, block_t *block)
     block_Release (block);
 }
 
-static void Flush (audio_output_t *aout, bool wait)
+static void Flush (audio_output_t *aout)
 {
     aout_sys_t *sys = aout->sys;
 
@@ -246,7 +246,6 @@ static void Flush (audio_output_t *aout, bool wait)
     sys->started = 0;
     sys->delay = 0;
     sio_start (sys->hdl);
-    (void)wait;
 }
 
 static void VolumeChanged (void *arg, unsigned volume)
diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index 8516d4cd40..c6a0f7f728 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -118,7 +118,7 @@ int aout_OutputNew(audio_output_t *, audio_sample_format_t *);
 int aout_OutputTimeGet(audio_output_t *, mtime_t *);
 void aout_OutputPlay(audio_output_t *, block_t *);
 void aout_OutputPause( audio_output_t * p_aout, bool, mtime_t );
-void aout_OutputFlush( audio_output_t * p_aout, bool );
+void aout_OutputFlush( audio_output_t * p_aout );
 void aout_OutputDelete( audio_output_t * p_aout );
 void aout_OutputLock(audio_output_t *);
 void aout_OutputUnlock(audio_output_t *);
@@ -144,7 +144,7 @@ void aout_DecDelete(audio_output_t *);
 int aout_DecPlay(audio_output_t *, block_t *, int i_input_rate);
 void aout_DecGetResetStats(audio_output_t *, unsigned *, unsigned *);
 void aout_DecChangePause(audio_output_t *, bool b_paused, mtime_t i_date);
-void aout_DecFlush(audio_output_t *, bool wait);
+void aout_DecFlush(audio_output_t *);
 void aout_RequestRestart (audio_output_t *, unsigned);
 
 static inline void aout_InputRequestRestart(audio_output_t *aout)
diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c
index 157443635e..bf0027520e 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -261,7 +261,7 @@ static void aout_DecSynchronize (audio_output_t *aout, mtime_t dec_pts,
         else
             msg_Dbg (aout, "playback too late (%"PRId64"): "
                      "flushing buffers", drift);
-        aout_OutputFlush (aout, false);
+        aout_OutputFlush (aout);
 
         aout_StopResampling (aout);
         owner->sync.end = VLC_TS_INVALID;
@@ -426,7 +426,7 @@ void aout_DecChangePause (audio_output_t *aout, bool paused, mtime_t date)
     aout_OutputUnlock (aout);
 }
 
-void aout_DecFlush (audio_output_t *aout, bool wait)
+void aout_DecFlush (audio_output_t *aout)
 {
     aout_owner_t *owner = aout_owner (aout);
 
@@ -434,15 +434,8 @@ void aout_DecFlush (audio_output_t *aout, bool wait)
     owner->sync.end = VLC_TS_INVALID;
     if (owner->mixer_format.i_format)
     {
-        if (wait)
-        {
-            block_t *block = aout_FiltersDrain (owner->filters);
-            if (block)
-                aout_OutputPlay (aout, block);
-        }
-        else
-            aout_FiltersFlush (owner->filters);
-        aout_OutputFlush (aout, wait);
+        aout_FiltersFlush (owner->filters);
+        aout_OutputFlush (aout);
     }
     aout_OutputUnlock (aout);
 }
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index 8a70cdfddc..9dadcf8537 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -512,17 +512,15 @@ void aout_OutputPause( audio_output_t *aout, bool pause, mtime_t date )
 }
 
 /**
- * Flushes or drains the audio output buffers.
+ * Flushes he audio output buffers.
  * This enables the output to expedite seek and stop.
- * \param wait if true, wait for buffer playback (i.e. drain),
- *             if false, discard the buffers immediately (i.e. flush)
  * \note This can only be called after a successful aout_OutputNew().
  * \warning The caller must hold the audio output lock.
  */
-void aout_OutputFlush( audio_output_t *aout, bool wait )
+void aout_OutputFlush( audio_output_t *aout )
 {
     aout_OutputAssertLocked( aout );
-    aout->flush (aout, wait);
+    aout->flush( aout );
 }
 
 static int aout_OutputVolumeSet (audio_output_t *aout, float vol)
diff --git a/src/input/decoder.c b/src/input/decoder.c
index f868559c54..d1d14ae3cb 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -1080,7 +1080,7 @@ static int DecoderPlayAudio( decoder_t *p_dec, block_t *p_audio,
         msg_Dbg( p_dec, "end of audio preroll" );
 
         if( p_owner->p_aout )
-            aout_DecFlush( p_owner->p_aout, false );
+            aout_DecFlush( p_owner->p_aout );
     }
 
     /* */
@@ -1419,7 +1419,7 @@ static void DecoderProcessFlush( decoder_t *p_dec )
     if( p_dec->fmt_out.i_cat == AUDIO_ES )
     {
         if( p_owner->p_aout )
-            aout_DecFlush( p_owner->p_aout, false );
+            aout_DecFlush( p_owner->p_aout );
     }
     else if( p_dec->fmt_out.i_cat == VIDEO_ES )
     {
@@ -1538,7 +1538,7 @@ static void *DecoderThread( void *p_data )
         {   /* Draining: the decoder is drained and all decoded buffers are
              * queued to the output at this point. Now drain the output. */
             if( p_owner->p_aout != NULL )
-                aout_DecFlush( p_owner->p_aout, true );
+                aout_DecFlush( p_owner->p_aout );
         }
         vlc_restorecancel( canc );
 
@@ -1746,7 +1746,7 @@ static void DeleteDecoder( decoder_t * p_dec )
     if( p_owner->p_aout )
     {
         /* TODO: REVISIT gap-less audio */
-        aout_DecFlush( p_owner->p_aout, false );
+        aout_DecFlush( p_owner->p_aout );
         aout_DecDelete( p_owner->p_aout );
         input_resource_PutAout( p_owner->p_resource, p_owner->p_aout );
         if( p_owner->p_input != NULL )
-- 
2.11.0



More information about the vlc-devel mailing list