]> git.sesse.net Git - vlc/blobdiff - src/audio_output/common.c
Debug audio output lock ordering
[vlc] / src / audio_output / common.c
index dbdead4d07c5ecc5fc2439f8075f8b37017c394d..0c9cda76bc3128136a2c858450ae66c5bf2f82fb 100644 (file)
@@ -77,7 +77,6 @@ static void aout_Destructor( vlc_object_t * p_this );
 aout_instance_t * __aout_New( vlc_object_t * p_parent )
 {
     aout_instance_t * p_aout;
-    vlc_value_t val;
 
     /* Allocate descriptor. */
     p_aout = vlc_object_create( p_parent, VLC_OBJECT_AOUT );
@@ -97,8 +96,7 @@ aout_instance_t * __aout_New( vlc_object_t * p_parent )
     p_aout->output.b_starving = 1;
 
     var_Create( p_aout, "intf-change", VLC_VAR_BOOL );
-    val.b_bool = true;
-    var_Set( p_aout, "intf-change", val );
+    var_SetBool( p_aout, "intf-change", true );
 
     vlc_object_set_destructor( p_aout, aout_Destructor );
 
@@ -116,6 +114,54 @@ static void aout_Destructor( vlc_object_t * p_this )
     vlc_mutex_destroy( &p_aout->output_fifo_lock );
 }
 
+/* Lock ordering rules:
+ *
+ *            Mixer Input IFIFO OFIFO (< Inner lock)
+ * Mixer       No!   N/A   Yes   Yes
+ * Input       N/A   No!   Yes   N/A
+ * In FIFOs    No!   No!   No!   No!
+ * Out FIFOs   No!   N/A   Yes   No!
+ * (^ Outer lock)
+ */
+#ifdef AOUT_DEBUG
+/* Lock debugging */
+static __thread unsigned aout_locks = 0;
+
+void aout_lock (unsigned i)
+{
+    unsigned allowed;
+    switch (i)
+    {
+        case MIXER_LOCK:
+            allowed = 0;
+            break;
+        case INPUT_LOCK:
+            allowed = 0;
+            break;
+        case OUTPUT_FIFO_LOCK:
+            allowed = MIXER_LOCK;
+            break;
+        case INPUT_FIFO_LOCK:
+            allowed = MIXER_LOCK|INPUT_LOCK|OUTPUT_FIFO_LOCK;
+            break;
+    }
+
+    if (aout_locks & ~allowed)
+    {
+        fprintf (stderr, "Illegal audio lock transition (%x -> %x)\n",
+                 aout_locks, aout_locks|i);
+        vlc_backtrace ();
+        //abort ();
+    }
+    aout_locks |= i;
+}
+
+void aout_unlock (unsigned i)
+{
+    assert (aout_locks & i);
+    aout_locks &= ~i;
+}
+#endif
 
 /*
  * Formats management (internal and external)
@@ -371,13 +417,14 @@ void aout_FifoPush( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
     /* Enforce the continuity of the stream. */
     if ( date_Get( &p_fifo->end_date ) )
     {
-        p_buffer->start_date = date_Get( &p_fifo->end_date );
-        p_buffer->end_date = date_Increment( &p_fifo->end_date,
+        p_buffer->i_pts = date_Get( &p_fifo->end_date );
+        p_buffer->i_length = date_Increment( &p_fifo->end_date,
                                              p_buffer->i_nb_samples );
+        p_buffer->i_length -= p_buffer->i_pts;
     }
     else
     {
-        date_Set( &p_fifo->end_date, p_buffer->end_date );
+        date_Set( &p_fifo->end_date, p_buffer->i_pts + p_buffer->i_length );
     }
 }
 
@@ -418,8 +465,7 @@ void aout_FifoMoveDates( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
     p_buffer = p_fifo->p_first;
     while ( p_buffer != NULL )
     {
-        p_buffer->start_date += difference;
-        p_buffer->end_date += difference;
+        p_buffer->i_pts += difference;
         p_buffer = p_buffer->p_next;
     }
 }
@@ -442,7 +488,7 @@ mtime_t aout_FifoFirstDate( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
 {
     (void)p_aout;
     AOUT_ASSERT_FIFO_LOCKED;
-    return p_fifo->p_first ?  p_fifo->p_first->start_date : 0;
+    return p_fifo->p_first ?  p_fifo->p_first->i_pts : 0;
 }
 
 /*****************************************************************************
@@ -701,38 +747,16 @@ bool aout_CheckChannelExtraction( int *pi_selection,
  * aout_BufferAlloc:
  *****************************************************************************/
 
-void aout_BufferAlloc(aout_alloc_t *allocation, mtime_t microseconds,
-        aout_buffer_t *old_buffer, aout_buffer_t **new_buffer)
+aout_buffer_t *aout_BufferAlloc(aout_alloc_t *allocation, mtime_t microseconds,
+        aout_buffer_t *old_buffer)
 {
     if ( !allocation->b_alloc )
     {
-        *new_buffer = old_buffer;
-        return;
+        return old_buffer;
     }
 
-    aout_buffer_t *buffer;
-    int i_alloc_size;
-
-    i_alloc_size = (int)( (uint64_t)allocation->i_bytes_per_sec
+    size_t i_alloc_size = (int)( (uint64_t)allocation->i_bytes_per_sec
                                         * (microseconds) / 1000000 + 1 );
 
-    buffer = malloc( i_alloc_size + sizeof(aout_buffer_t) );
-    if ( !buffer )
-    {
-        *new_buffer = NULL;
-        return;
-    }
-
-    buffer->b_alloc = true;
-    buffer->i_size = i_alloc_size;
-    buffer->p_buffer = (uint8_t *)buffer + sizeof(aout_buffer_t);
-    buffer->b_discontinuity = false;
-
-    if ( old_buffer )
-    {
-        buffer->start_date = old_buffer->start_date;
-        buffer->end_date = old_buffer->end_date;
-    }
-
-    *new_buffer = buffer;
+    return block_Alloc( i_alloc_size );
 }