[vlc-commits] aout: use separate lock for the packet FIFO (fix #5131)

Rémi Denis-Courmont git at videolan.org
Thu Aug 4 18:38:21 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Aug  4 19:08:34 2011 +0300| [85aa03d0af48e9db48c8fab1a8c13d968ad0de2b] | committer: Rémi Denis-Courmont

aout: use separate lock for the packet FIFO (fix #5131)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=85aa03d0af48e9db48c8fab1a8c13d968ad0de2b
---

 include/vlc_aout.h        |   15 ++++++++-------
 src/audio_output/output.c |   16 +++++++++++++---
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/include/vlc_aout.h b/include/vlc_aout.h
index 5a978c9..1eb9a58 100644
--- a/include/vlc_aout.h
+++ b/include/vlc_aout.h
@@ -260,13 +260,14 @@ struct aout_fifo_t
 /* Legacy packet-oriented audio output helpers */
 typedef struct
 {
-   aout_fifo_t partial; /**< Audio blocks before packetization */
-   aout_fifo_t fifo; /**< Packetized audio blocks */
-   mtime_t pause_date; /**< Date when paused or VLC_TS_INVALID */
-   unsigned samples; /**< Samples per packet */
-   bool starving;
-   /* Indicates whether the audio output is currently starving, to avoid
-    * printing a 1,000 "output is starving" messages. */
+    vlc_mutex_t lock;
+    aout_fifo_t partial; /**< Audio blocks before packetization */
+    aout_fifo_t fifo; /**< Packetized audio blocks */
+    mtime_t pause_date; /**< Date when paused or VLC_TS_INVALID */
+    unsigned samples; /**< Samples per packet */
+    bool starving;
+    /* Indicates whether the audio output is currently starving, to avoid
+     * printing a 1,000 "output is starving" messages. */
 } aout_packet_t;
 
 VLC_API void aout_PacketInit(audio_output_t *, aout_packet_t *, unsigned);
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index 2a35615..2c64d6d 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -373,6 +373,7 @@ void aout_PacketInit (audio_output_t *aout, aout_packet_t *p, unsigned samples)
 {
     assert (p == aout_packet (aout));
 
+    vlc_mutex_init (&p->lock);
     aout_FifoInit (aout, &p->partial, aout->format.i_rate);
     aout_FifoInit (aout, &p->fifo, aout->format.i_rate);
     p->pause_date = VLC_TS_INVALID;
@@ -386,6 +387,7 @@ void aout_PacketDestroy (audio_output_t *aout)
 
     aout_FifoDestroy (&p->partial);
     aout_FifoDestroy (&p->fifo);
+    vlc_mutex_destroy (&p->lock);
 }
 
 static block_t *aout_OutputSlice (audio_output_t *);
@@ -394,9 +396,11 @@ void aout_PacketPlay (audio_output_t *aout, block_t *block)
 {
     aout_packet_t *p = aout_packet (aout);
 
+    vlc_mutex_lock (&p->lock);
     aout_FifoPush (&p->partial, block);
     while ((block = aout_OutputSlice (aout)) != NULL)
         aout_FifoPush (&p->fifo, block);
+    vlc_mutex_unlock (&p->lock);
 }
 
 void aout_PacketPause (audio_output_t *aout, bool pause, mtime_t date)
@@ -415,8 +419,10 @@ void aout_PacketPause (audio_output_t *aout, bool pause, mtime_t date)
         mtime_t duration = date - p->pause_date;
 
         p->pause_date = VLC_TS_INVALID;
+        vlc_mutex_lock (&p->lock);
         aout_FifoMoveDates (&p->partial, duration);
         aout_FifoMoveDates (&p->fifo, duration);
+        vlc_mutex_unlock (&p->lock);
     }
 }
 
@@ -424,8 +430,11 @@ void aout_PacketFlush (audio_output_t *aout, bool drain)
 {
     aout_packet_t *p = aout_packet (aout);
 
+    vlc_mutex_lock (&p->lock);
     aout_FifoReset (&p->partial);
     aout_FifoReset (&p->fifo);
+    vlc_mutex_unlock (&p->lock);
+
     (void) drain; /* TODO */
 }
 
@@ -442,7 +451,7 @@ static block_t *aout_OutputSlice (audio_output_t *p_aout)
     const unsigned samples = p->samples;
     assert( samples > 0 );
 
-    aout_assert_locked( p_aout );
+    vlc_assert_locked( &p->lock );
 
     /* Retrieve the date of the next buffer. */
     date_t exact_start_date = p->fifo.end_date;
@@ -597,7 +606,7 @@ aout_buffer_t * aout_OutputNextBuffer( audio_output_t * p_aout,
     aout_buffer_t * p_buffer;
     mtime_t now = mdate();
 
-    aout_lock( p_aout );
+    vlc_mutex_lock( &p->lock );
 
     /* Drop the audio sample if the audio output is really late.
      * In the case of b_can_sleek, we don't use a resampler so we need to be
@@ -653,8 +662,9 @@ aout_buffer_t * aout_OutputNextBuffer( audio_output_t * p_aout,
 
         aout_FifoMoveDates (&p->partial, delta);
         aout_FifoMoveDates (p_fifo, delta);
+#warning FIXME: feed back to input for resampling!!!
     }
 out:
-    aout_unlock( p_aout );
+    vlc_mutex_unlock( &p->lock );
     return p_buffer;
 }



More information about the vlc-commits mailing list