[vlc-devel] [PATCH v2 5/7] aout: the drain callback can now invalidate the stream

Thomas Guillem thomas at gllm.fr
Wed Mar 13 09:55:53 CET 2019


Only stop() and flush() can be called after.
---
 include/vlc_aout.h               |  5 +++++
 src/audio_output/aout_internal.h |  2 ++
 src/audio_output/dec.c           | 10 +++++-----
 src/audio_output/output.c        |  1 +
 4 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/include/vlc_aout.h b/include/vlc_aout.h
index a6b8069151..d25abd874b 100644
--- a/include/vlc_aout.h
+++ b/include/vlc_aout.h
@@ -222,6 +222,11 @@ struct audio_output
       */
     void (*drain)(audio_output_t *);
     /**< Drain the playback buffers (can be NULL).
+      *
+      * The implementation can invalidate the stream since this is generally
+      * the last call before a stop(). However, a flush() could also be called
+      * just after a drain(). In that case the stream must be ready for a new
+      * playback.
       *
       * If NULL, the caller will wait for the delay returned by time_get before
       * calling stop().
diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index a1bc4cfe65..ed72cff0f8 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -84,6 +84,8 @@ typedef struct
     atomic_uint buffers_lost;
     atomic_uint buffers_played;
     atomic_uchar restart;
+
+    bool drained;
 } aout_owner_t;
 
 typedef struct
diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c
index 73c473bc97..683f181f9f 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -127,6 +127,7 @@ void aout_DecDelete (audio_output_t *aout)
     }
     aout_volume_Delete (owner->volume);
     owner->volume = NULL;
+    owner->drained = false;
 }
 
 static int aout_CheckReady (audio_output_t *aout)
@@ -387,6 +388,7 @@ int aout_DecPlay(audio_output_t *aout, block_t *block)
 {
     aout_owner_t *owner = aout_owner (aout);
 
+    assert(!owner->drained);
     assert (block->i_pts != VLC_TICK_INVALID);
 
     block->i_length = vlc_tick_from_samples( block->i_nb_samples,
@@ -526,6 +528,7 @@ void aout_DecFlush(audio_output_t *aout)
     }
     owner->sync.discontinuity = true;
     owner->original_pts = VLC_TICK_INVALID;
+    owner->drained = false;
 }
 
 void aout_DecDrain(audio_output_t *aout)
@@ -534,6 +537,7 @@ void aout_DecDrain(audio_output_t *aout)
 
     if (!owner->mixer_format.i_format)
         return;
+    assert(!owner->drained);
 
     block_t *block = aout_FiltersDrain (owner->filters);
     if (block)
@@ -548,9 +552,5 @@ void aout_DecDrain(audio_output_t *aout)
             vlc_tick_sleep(delay);
     }
 
-    vlc_clock_Reset(owner->sync.clock);
-    aout_FiltersResetClock(owner->filters);
-
-    owner->sync.discontinuity = true;
-    owner->original_pts = VLC_TICK_INVALID;
+    owner->drained = true;
 }
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index f12121a704..cfc786f4a1 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -245,6 +245,7 @@ audio_output_t *aout_New (vlc_object_t *parent)
     vlc_viewpoint_init (&owner->vp.value);
     atomic_init (&owner->vp.update, false);
 
+    owner->drained = false;
     vlc_object_set_destructor (aout, aout_Destructor);
 
     /* Audio output module callbacks */
-- 
2.20.1



More information about the vlc-devel mailing list