]> git.sesse.net Git - vlc/blobdiff - src/audio_output/common.c
aout_BufferAlloc() : remove stack allocation
[vlc] / src / audio_output / common.c
index b153f0c4de4ecfdb31bcced56ae354b8285d0f30..dbdead4d07c5ecc5fc2439f8075f8b37017c394d 100644 (file)
@@ -696,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;
+}