struct aout_buffer_t
{
uint8_t * p_buffer;
- int i_alloc_type;
+ bool b_alloc;
/* i_size is the real size of the buffer (used for debug ONLY), i_nb_bytes
* is the number of significative bytes in it. */
size_t i_size, i_nb_bytes;
void (*pf_release)( aout_buffer_t * );
};
-#define aout_BufferFree( p_buffer ) do { \
- if( p_buffer != NULL && (p_buffer)->i_alloc_type == AOUT_ALLOC_HEAP ) \
- { \
- free( p_buffer ); \
- } \
- p_buffer = NULL; } while(0)
+static inline void aout_BufferFree( aout_buffer_t *buffer )
+{
+ if( buffer && buffer->b_alloc )
+ free( buffer );
+}
/* Size of a frame for S/PDIF output. */
#define AOUT_SPDIF_SIZE 6144
/** allocation of memory in the audio output */
typedef struct aout_alloc_t
{
- int i_alloc_type;
+ bool b_alloc;
int i_bytes_per_sec;
} aout_alloc_t;
-#define AOUT_ALLOC_NONE 0
-#define AOUT_ALLOC_STACK 1
-#define AOUT_ALLOC_HEAP 2
-
/** audio output buffer FIFO */
struct aout_fifo_t
{
p_mixer->mix = DoWork;
/* This is a bit kludgy - do not ask for a new buffer, since the one
* provided by the first input will be good enough. */
- p_mixer->allocation.i_alloc_type = AOUT_ALLOC_NONE;
+ p_mixer->allocation.b_alloc = false;
return 0;
}
#ifndef __LIBVLC_AOUT_INTERNAL_H
# define __LIBVLC_AOUT_INTERNAL_H 1
-#include <assert.h>
-
-#if defined( __APPLE__ ) || defined( SYS_BSD )
-#undef HAVE_ALLOCA
-#endif
-
-#ifdef HAVE_ALLOCA
-# define ALLOCA_TEST( p_alloc, p_new_buffer ) \
- if ( (p_alloc)->i_alloc_type == AOUT_ALLOC_STACK ) \
- { \
- (p_new_buffer) = alloca( i_alloc_size + sizeof(aout_buffer_t) );\
- i_alloc_type = AOUT_ALLOC_STACK; \
- } \
- else
-#else
-# define ALLOCA_TEST( p_alloc, p_new_buffer )
-#endif
-
-#define aout_BufferAlloc( p_alloc, i_nb_usec, p_previous_buffer, \
- p_new_buffer ) \
- if ( (p_alloc)->i_alloc_type == AOUT_ALLOC_NONE ) \
- { \
- (p_new_buffer) = p_previous_buffer; \
- } \
- else \
- { \
- int i_alloc_size, i_alloc_type; \
- i_alloc_size = (int)( (uint64_t)(p_alloc)->i_bytes_per_sec \
- * (i_nb_usec) / 1000000 + 1 ); \
- ALLOCA_TEST( p_alloc, p_new_buffer ) \
- { \
- (p_new_buffer) = malloc( i_alloc_size + sizeof(aout_buffer_t) );\
- i_alloc_type = AOUT_ALLOC_HEAP; \
- } \
- if ( p_new_buffer != NULL ) \
- { \
- (p_new_buffer)->i_alloc_type = i_alloc_type; \
- (p_new_buffer)->i_size = i_alloc_size; \
- (p_new_buffer)->p_buffer = (uint8_t *)(p_new_buffer) \
- + sizeof(aout_buffer_t); \
- (p_new_buffer)->b_discontinuity = false; \
- if ( (p_previous_buffer) != NULL ) \
- { \
- (p_new_buffer)->start_date = \
- ((aout_buffer_t *)p_previous_buffer)->start_date;\
- (p_new_buffer)->end_date = \
- ((aout_buffer_t *)p_previous_buffer)->end_date; \
- } \
- } \
- /* we'll keep that for a while --Meuuh */ \
- /* else printf("%s:%d\n", __FILE__, __LINE__); */ \
- }
+void aout_BufferAlloc(aout_alloc_t *allocation, mtime_t microseconds,
+ aout_buffer_t *old_buffer, aout_buffer_t **new_buffer);
struct aout_filter_owner_sys_t
{
}
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;
+}
duration = (1000000 * (mtime_t)i_nb_samples) / p_input->input.i_rate;
/* This necessarily allocates in the heap. */
- aout_BufferAlloc( &p_input->input_alloc, duration, NULL, p_buffer );
+ aout_BufferAlloc( &p_input->input_alloc, duration, NULL, &p_buffer );
if( p_buffer != NULL )
p_buffer->i_nb_bytes = i_nb_samples * p_input->input.i_bytes_per_frame
/ p_input->input.i_frame_length;
mtime_t duration = (1000000 * (mtime_t)p_buffer->i_nb_samples)
/ p_input->input.i_rate;
- aout_BufferAlloc( &p_input->input_alloc, duration, NULL, p_new_buffer );
+ aout_BufferAlloc( &p_input->input_alloc, duration, NULL, &p_new_buffer );
vlc_memcpy( p_new_buffer->p_buffer, p_buffer->p_buffer,
p_buffer->i_nb_bytes );
p_new_buffer->i_nb_samples = p_buffer->i_nb_samples;
p_first_alloc->i_bytes_per_sec = __MAX(
p_first_alloc->i_bytes_per_sec,
i_input_size );
- p_filter->output_alloc.i_alloc_type = AOUT_ALLOC_NONE;
+ p_filter->output_alloc.b_alloc = false;
}
else
{
/* We're gonna need a buffer allocation. */
memcpy( &p_filter->output_alloc, p_first_alloc,
sizeof(aout_alloc_t) );
- p_first_alloc->i_alloc_type = AOUT_ALLOC_STACK;
+ p_first_alloc->b_alloc = true;
p_first_alloc->i_bytes_per_sec = i_input_size;
}
}
aout_BufferAlloc( &p_filter->output_alloc,
((mtime_t)(*pp_input_buffer)->i_nb_samples + 2)
* 1000000 / p_filter->input.i_rate,
- *pp_input_buffer, p_output_buffer );
+ *pp_input_buffer, &p_output_buffer );
if( p_output_buffer == NULL )
return;
*pp_input_buffer = p_output_buffer;
}
}
-
- assert( (*pp_input_buffer) == NULL || (*pp_input_buffer)->i_alloc_type != AOUT_ALLOC_STACK );
}
/*****************************************************************************
}
/* Prepare hints for the buffer allocator. */
- p_input->input_alloc.i_alloc_type = AOUT_ALLOC_HEAP;
+ p_input->input_alloc.b_alloc = true;
p_input->input_alloc.i_bytes_per_sec = -1;
/* Create resamplers. */
aout_FiltersHintBuffers( p_aout, p_input->pp_resamplers,
p_input->i_nb_resamplers,
&p_input->input_alloc );
- p_input->input_alloc.i_alloc_type = AOUT_ALLOC_HEAP;
+ p_input->input_alloc.b_alloc = true;
/* Setup the initial rate of the resampler */
p_input->pp_resamplers[0]->input.i_rate = p_input->input.i_rate;
aout_FiltersHintBuffers( p_aout, p_input->pp_filters,
p_input->i_nb_filters,
&p_input->input_alloc );
- p_input->input_alloc.i_alloc_type = AOUT_ALLOC_HEAP;
+ p_input->input_alloc.b_alloc = true;
/* i_bytes_per_sec is still == -1 if no filters */
p_input->input_alloc.i_bytes_per_sec = __MAX(
/* This is a bit kludgy, but is actually only used
* for the S/PDIF dummy mixer : */
p_aout->pp_inputs[i_first_input]->mixer.fifo.p_first,
- p_output_buffer );
+ &p_output_buffer );
if ( p_output_buffer == NULL )
{
aout_unlock_input_fifos( p_aout );
return -1;
}
/* This is again a bit kludgy - for the S/PDIF mixer. */
- if ( p_aout->p_mixer->allocation.i_alloc_type != AOUT_ALLOC_NONE )
+ if ( p_aout->p_mixer->allocation.b_alloc )
{
p_output_buffer->i_nb_samples = p_aout->output.i_nb_samples;
p_output_buffer->i_nb_bytes = p_aout->output.i_nb_samples
}
/* Prepare hints for the buffer allocator. */
- p_aout->mixer_allocation.i_alloc_type = AOUT_ALLOC_HEAP;
+ p_aout->mixer_allocation.b_alloc = true;
p_aout->mixer_allocation.i_bytes_per_sec
= p_aout->mixer_format.i_bytes_per_frame
* p_aout->mixer_format.i_rate