]> git.sesse.net Git - vlc/blobdiff - src/audio_output/common.c
aout_BufferAlloc() : remove stack allocation
[vlc] / src / audio_output / common.c
index fde38b3ab78a159d08996192c18102ea87767fa8..dbdead4d07c5ecc5fc2439f8075f8b37017c394d 100644 (file)
@@ -43,6 +43,9 @@
 static inline void aout_assert_fifo_locked( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
 {
 #ifndef NDEBUG
+    if( !p_aout )
+        return;
+
     if( p_fifo == &p_aout->output.fifo )
         vlc_assert_locked( &p_aout->output_fifo_lock );
     else
@@ -50,7 +53,7 @@ static inline void aout_assert_fifo_locked( aout_instance_t * p_aout, aout_fifo_
         int i;
         for( i = 0; i < p_aout->i_nb_inputs; i++ )
         {
-            if( p_fifo == &p_aout->pp_inputs[i]->fifo)
+            if( p_fifo == &p_aout->pp_inputs[i]->mixer.fifo)
             {
                 vlc_assert_locked( &p_aout->input_fifos_lock );
                 break;
@@ -88,8 +91,8 @@ aout_instance_t * __aout_New( vlc_object_t * p_parent )
     vlc_mutex_init( &p_aout->mixer_lock );
     vlc_mutex_init( &p_aout->output_fifo_lock );
     p_aout->i_nb_inputs = 0;
-    p_aout->mixer.f_multiplier = 1.0;
-    p_aout->mixer.b_error = 1;
+    p_aout->mixer_multiplier = 1.0;
+    p_aout->p_mixer = NULL;
     p_aout->output.b_error = 1;
     p_aout->output.b_starving = 1;
 
@@ -197,6 +200,8 @@ const char * aout_FormatPrintChannels( const audio_sample_format_t * p_format )
 {
     switch ( p_format->i_physical_channels & AOUT_CHAN_PHYSMASK )
     {
+    case AOUT_CHAN_LEFT:
+    case AOUT_CHAN_RIGHT:
     case AOUT_CHAN_CENTER:
         if ( (p_format->i_original_channels & AOUT_CHAN_CENTER)
               || (p_format->i_original_channels
@@ -348,7 +353,7 @@ void aout_FifoInit( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
 
     p_fifo->p_first = NULL;
     p_fifo->pp_last = &p_fifo->p_first;
-    aout_DateInit( &p_fifo->end_date, i_rate );
+    date_Init( &p_fifo->end_date, i_rate, 1 );
 }
 
 /*****************************************************************************
@@ -364,15 +369,15 @@ void aout_FifoPush( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
     p_fifo->pp_last = &p_buffer->p_next;
     *p_fifo->pp_last = NULL;
     /* Enforce the continuity of the stream. */
-    if ( aout_DateGet( &p_fifo->end_date ) )
+    if ( date_Get( &p_fifo->end_date ) )
     {
-        p_buffer->start_date = aout_DateGet( &p_fifo->end_date );
-        p_buffer->end_date = aout_DateIncrement( &p_fifo->end_date,
-                                                 p_buffer->i_nb_samples );
+        p_buffer->start_date = date_Get( &p_fifo->end_date );
+        p_buffer->end_date = date_Increment( &p_fifo->end_date,
+                                             p_buffer->i_nb_samples );
     }
     else
     {
-        aout_DateSet( &p_fifo->end_date, p_buffer->end_date );
+        date_Set( &p_fifo->end_date, p_buffer->end_date );
     }
 }
 
@@ -387,7 +392,7 @@ void aout_FifoSet( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
     (void)p_aout;
     AOUT_ASSERT_FIFO_LOCKED;
 
-    aout_DateSet( &p_fifo->end_date, date );
+    date_Set( &p_fifo->end_date, date );
     p_buffer = p_fifo->p_first;
     while ( p_buffer != NULL )
     {
@@ -409,7 +414,7 @@ void aout_FifoMoveDates( aout_instance_t * p_aout, aout_fifo_t * p_fifo,
     (void)p_aout;
     AOUT_ASSERT_FIFO_LOCKED;
 
-    aout_DateMove( &p_fifo->end_date, difference );
+    date_Move( &p_fifo->end_date, difference );
     p_buffer = p_fifo->p_first;
     while ( p_buffer != NULL )
     {
@@ -426,7 +431,7 @@ mtime_t aout_FifoNextStart( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
 {
     (void)p_aout;
     AOUT_ASSERT_FIFO_LOCKED;
-    return aout_DateGet( &p_fifo->end_date );
+    return date_Get( &p_fifo->end_date );
 }
 
 /*****************************************************************************
@@ -481,65 +486,6 @@ void aout_FifoDestroy( aout_instance_t * p_aout, aout_fifo_t * p_fifo )
     p_fifo->pp_last = &p_fifo->p_first;
 }
 
-
-/*
- * Date management (internal and external)
- */
-
-/*****************************************************************************
- * aout_DateInit : set the divider of an audio_date_t
- *****************************************************************************/
-void aout_DateInit( audio_date_t * p_date, uint32_t i_divider )
-{
-    p_date->date = 0;
-    p_date->i_divider = i_divider;
-    p_date->i_remainder = 0;
-}
-
-/*****************************************************************************
- * aout_DateSet : set the date of an audio_date_t
- *****************************************************************************/
-void aout_DateSet( audio_date_t * p_date, mtime_t new_date )
-{
-    p_date->date = new_date;
-    p_date->i_remainder = 0;
-}
-
-/*****************************************************************************
- * aout_DateMove : move forwards or backwards the date of an audio_date_t
- *****************************************************************************/
-void aout_DateMove( audio_date_t * p_date, mtime_t difference )
-{
-    p_date->date += difference;
-}
-
-/*****************************************************************************
- * aout_DateGet : get the date of an audio_date_t
- *****************************************************************************/
-mtime_t aout_DateGet( const audio_date_t * p_date )
-{
-    return p_date->date;
-}
-
-/*****************************************************************************
- * aout_DateIncrement : increment the date and return the result, taking
- * into account rounding errors
- *****************************************************************************/
-mtime_t aout_DateIncrement( audio_date_t * p_date, uint32_t i_nb_samples )
-{
-    mtime_t i_dividend = INT64_C(1000000) * i_nb_samples;
-    assert( p_date->i_divider > 0 ); /* uninitialized audio_data_t ? */
-    p_date->date += i_dividend / p_date->i_divider;
-    p_date->i_remainder += (int)(i_dividend % p_date->i_divider);
-    if ( p_date->i_remainder >= p_date->i_divider )
-    {
-        /* This is Bresenham algorithm. */
-        p_date->date++;
-        p_date->i_remainder -= p_date->i_divider;
-    }
-    return p_date->date;
-}
-
 /*****************************************************************************
  * aout_CheckChannelReorder : Check if we need to do some channel re-ordering
  *****************************************************************************/
@@ -750,3 +696,43 @@ bool aout_CheckChannelExtraction( int *pi_selection,
     }
     return i_out == i_channels;
 }
+
+/*****************************************************************************
+ * aout_BufferAlloc:
+ *****************************************************************************/
+
+void aout_BufferAlloc(aout_alloc_t *allocation, mtime_t microseconds,
+        aout_buffer_t *old_buffer, aout_buffer_t **new_buffer)
+{
+    if ( !allocation->b_alloc )
+    {
+        *new_buffer = old_buffer;
+        return;
+    }
+
+    aout_buffer_t *buffer;
+    int i_alloc_size;
+
+    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;
+}