Commit 9d9577f0 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Convert audio output core to audio filter2

audio filter plugins are now useless.
This breaks visual (needs to be ported to filter_t) and will likely
expose bugs in under-used audio filter2 infrastructure.

TODO: use filter chain instead of custom filter handling in core.
parent 1957186e
......@@ -192,7 +192,7 @@ typedef struct aout_output_t
bool b_starving;
/* post-filters */
aout_filter_t * pp_filters[AOUT_MAX_FILTERS];
filter_t * pp_filters[AOUT_MAX_FILTERS];
int i_nb_filters;
aout_fifo_t fifo;
......@@ -330,7 +330,7 @@ VLC_EXPORT( void, aout_EnableFilter, (vlc_object_t *, const char *, bool ));
aout_EnableFilter( VLC_OBJECT(o), n, b )
/* */
VLC_EXPORT( vout_thread_t *, aout_filter_RequestVout, ( aout_filter_t *, vout_thread_t *p_vout, video_format_t *p_fmt ) );
VLC_EXPORT( vout_thread_t *, aout_filter_RequestVout, ( filter_t *, vout_thread_t *p_vout, video_format_t *p_fmt ) );
# ifdef __cplusplus
}
......
......@@ -38,12 +38,14 @@ typedef struct
void *p_private;
} aout_request_vout_t;
struct aout_filter_owner_sys_t
struct filter_owner_sys_t
{
aout_instance_t *p_aout;
aout_input_t *p_input;
};
block_t *aout_FilterBufferNew( filter_t *, int );
/** an input stream for the audio output */
struct aout_input_t
{
......@@ -55,13 +57,13 @@ struct aout_input_t
aout_alloc_t input_alloc;
/* pre-filters */
aout_filter_t * pp_filters[AOUT_MAX_FILTERS];
filter_t * pp_filters[AOUT_MAX_FILTERS];
int i_nb_filters;
aout_filter_t * p_playback_rate_filter;
filter_t * p_playback_rate_filter;
/* resamplers */
aout_filter_t * pp_resamplers[AOUT_MAX_FILTERS];
filter_t * pp_resamplers[AOUT_MAX_FILTERS];
int i_nb_resamplers;
int i_resampling_type;
mtime_t i_resamp_start_date;
......@@ -108,10 +110,10 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
aout_buffer_t * p_buffer, int i_input_rate );
/* From filters.c : */
int aout_FiltersCreatePipeline ( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int * pi_nb_filters, const audio_sample_format_t * p_input_format, const audio_sample_format_t * p_output_format );
void aout_FiltersDestroyPipeline ( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters );
void aout_FiltersPlay ( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_buffer_t ** pp_input_buffer );
void aout_FiltersHintBuffers( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_alloc_t * p_first_alloc );
int aout_FiltersCreatePipeline ( aout_instance_t * p_aout, filter_t ** pp_filters, int * pi_nb_filters, const audio_sample_format_t * p_input_format, const audio_sample_format_t * p_output_format );
void aout_FiltersDestroyPipeline ( aout_instance_t * p_aout, filter_t ** pp_filters, int i_nb_filters );
void aout_FiltersPlay ( filter_t ** pp_filters, unsigned i_nb_filters, aout_buffer_t ** pp_input_buffer );
void aout_FiltersHintBuffers( aout_instance_t * p_aout, filter_t ** pp_filters, int i_nb_filters, aout_alloc_t * p_first_alloc );
/* From mixer.c : */
int aout_MixerNew( aout_instance_t * p_aout );
......
......@@ -34,18 +34,25 @@
#include <vlc_dialog.h>
#include <vlc_aout.h>
#include <vlc_filter.h>
#include "aout_internal.h"
#include <libvlc.h>
block_t *aout_FilterBufferNew( filter_t *p_filter, int size )
{
(void) p_filter;
return block_Alloc( size );
}
/*****************************************************************************
* FindFilter: find an audio filter for a specific transformation
*****************************************************************************/
static aout_filter_t * FindFilter( aout_instance_t * p_aout,
static filter_t * FindFilter( aout_instance_t * p_aout,
const audio_sample_format_t * p_input_format,
const audio_sample_format_t * p_output_format )
{
static const char typename[] = "audio output";
aout_filter_t * p_filter;
static const char typename[] = "audio filter";
filter_t * p_filter;
p_filter = vlc_custom_create( p_aout, sizeof(*p_filter),
VLC_OBJECT_GENERIC, typename );
......@@ -53,10 +60,15 @@ static aout_filter_t * FindFilter( aout_instance_t * p_aout,
if ( p_filter == NULL ) return NULL;
vlc_object_attach( p_filter, p_aout );
memcpy( &p_filter->fmt_in.audio, p_input_format, sizeof(audio_sample_format_t) );
memcpy( &p_filter->fmt_in.audio, p_input_format,
sizeof(audio_sample_format_t) );
p_filter->fmt_in.i_codec = p_input_format->i_format;
memcpy( &p_filter->fmt_out.audio, p_output_format,
sizeof(audio_sample_format_t) );
p_filter->p_module = module_need( p_filter, "audio filter", NULL, false );
p_filter->fmt_out.i_codec = p_output_format->i_format;
p_filter->pf_audio_buffer_new = aout_FilterBufferNew;
p_filter->p_module = module_need( p_filter, "audio filter2", NULL, false );
if ( p_filter->p_module == NULL )
{
vlc_object_detach( p_filter );
......@@ -64,6 +76,7 @@ static aout_filter_t * FindFilter( aout_instance_t * p_aout,
return NULL;
}
assert( p_filter->pf_audio_filter );
return p_filter;
}
......@@ -118,7 +131,7 @@ static int SplitConversion( const audio_sample_format_t * p_input_format,
return 2;
}
static void ReleaseFilter( aout_filter_t * p_filter )
static void ReleaseFilter( filter_t * p_filter )
{
module_unneed( p_filter, p_filter->p_module );
vlc_object_detach( p_filter );
......@@ -132,12 +145,12 @@ static void ReleaseFilter( aout_filter_t * p_filter )
* pi_nb_filters must be initialized before calling this function
*****************************************************************************/
int aout_FiltersCreatePipeline( aout_instance_t * p_aout,
aout_filter_t ** pp_filters_start,
filter_t ** pp_filters_start,
int * pi_nb_filters,
const audio_sample_format_t * p_input_format,
const audio_sample_format_t * p_output_format )
{
aout_filter_t** pp_filters = pp_filters_start + *pi_nb_filters;
filter_t** pp_filters = pp_filters_start + *pi_nb_filters;
audio_sample_format_t temp_format;
int i_nb_conversions;
......@@ -263,7 +276,7 @@ int aout_FiltersCreatePipeline( aout_instance_t * p_aout,
* aout_FiltersDestroyPipeline: deallocate a filters pipeline
*****************************************************************************/
void aout_FiltersDestroyPipeline( aout_instance_t * p_aout,
aout_filter_t ** pp_filters,
filter_t ** pp_filters,
int i_nb_filters )
{
int i;
......@@ -271,7 +284,7 @@ void aout_FiltersDestroyPipeline( aout_instance_t * p_aout,
for ( i = 0; i < i_nb_filters; i++ )
{
aout_filter_t *p_filter = pp_filters[i];
filter_t *p_filter = pp_filters[i];
module_unneed( p_filter, p_filter->p_module );
free( p_filter->p_owner );
......@@ -285,7 +298,7 @@ void aout_FiltersDestroyPipeline( aout_instance_t * p_aout,
* buffer allocations
*****************************************************************************/
void aout_FiltersHintBuffers( aout_instance_t * p_aout,
aout_filter_t ** pp_filters,
filter_t ** pp_filters,
int i_nb_filters, aout_alloc_t * p_first_alloc )
{
int i;
......@@ -294,7 +307,7 @@ void aout_FiltersHintBuffers( aout_instance_t * p_aout,
for ( i = i_nb_filters - 1; i >= 0; i-- )
{
aout_filter_t * p_filter = pp_filters[i];
filter_t * p_filter = pp_filters[i];
int i_output_size = p_filter->fmt_out.audio.i_bytes_per_frame
* p_filter->fmt_out.audio.i_rate * AOUT_MAX_INPUT_RATE
......@@ -303,71 +316,30 @@ void aout_FiltersHintBuffers( aout_instance_t * p_aout,
* p_filter->fmt_in.audio.i_rate * AOUT_MAX_INPUT_RATE
/ p_filter->fmt_in.audio.i_frame_length;
p_first_alloc->i_bytes_per_sec = __MAX( p_first_alloc->i_bytes_per_sec,
i_output_size );
if ( p_filter->b_in_place )
{
p_first_alloc->i_bytes_per_sec = __MAX(
p_first_alloc->i_bytes_per_sec,
i_input_size );
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->b_alloc = true;
if( i_output_size > p_first_alloc->i_bytes_per_sec )
p_first_alloc->i_bytes_per_sec = i_output_size;
if( i_input_size > p_first_alloc->i_bytes_per_sec )
p_first_alloc->i_bytes_per_sec = i_input_size;
}
}
}
/*****************************************************************************
* aout_FiltersPlay: play a buffer
*****************************************************************************/
void aout_FiltersPlay( aout_instance_t * p_aout,
aout_filter_t ** pp_filters,
int i_nb_filters, aout_buffer_t ** pp_input_buffer )
void aout_FiltersPlay( filter_t ** pp_filters,
unsigned i_nb_filters, block_t ** pp_block )
{
int i;
block_t *p_block = *pp_block;
for( i = 0; i < i_nb_filters; i++ )
{
aout_filter_t * p_filter = pp_filters[i];
aout_buffer_t * p_output_buffer;
/* Resamplers can produce slightly more samples than (i_in_nb *
* p_filter->output.i_rate / p_filter->input.i_rate) so we need
* slightly bigger buffers. */
p_output_buffer = aout_BufferAlloc( &p_filter->output_alloc,
((mtime_t)(*pp_input_buffer)->i_nb_samples + 2)
* 1000000 / p_filter->fmt_in.audio.i_rate,
*pp_input_buffer );
if( p_output_buffer == NULL )
return;
p_output_buffer->i_pts = (*pp_input_buffer)->i_pts;
p_output_buffer->i_length = (*pp_input_buffer)->i_length;
/* Please note that p_output_buffer->i_nb_samples & i_buffer
* shall be set by the filter plug-in. */
if( (*pp_input_buffer)->i_nb_samples > 0 )
{
p_filter->pf_do_work( p_aout, p_filter, *pp_input_buffer,
p_output_buffer );
}
else
/* TODO: use filter chain */
for( unsigned i = 0; i < i_nb_filters; i++ )
{
p_output_buffer->i_buffer = 0;
p_output_buffer->i_nb_samples = 0;
}
filter_t * p_filter = pp_filters[i];
if( !p_filter->b_in_place )
{
aout_BufferFree( *pp_input_buffer );
*pp_input_buffer = p_output_buffer;
}
/* Please note that p_block->i_nb_samples & i_buffer
* shall be set by the filter plug-in. */
p_block = p_filter->pf_audio_filter( p_filter, p_block );
}
*pp_block = p_block;
}
......@@ -42,6 +42,7 @@
#include <vlc_vout.h> /* for vout_Request */
#include <vlc_aout.h>
#include <vlc_filter.h>
#include <libvlc.h>
#include "aout_internal.h"
......@@ -248,7 +249,7 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
while( psz_parser && *psz_parser )
{
aout_filter_t * p_filter = NULL;
filter_t * p_filter = NULL;
if( p_input->i_nb_filters >= AOUT_MAX_FILTERS )
{
......@@ -290,19 +291,21 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
/* request format */
memcpy( &p_filter->fmt_in.audio, &chain_output_format,
sizeof(audio_sample_format_t) );
p_filter->fmt_in.i_codec = chain_output_format.i_format;
memcpy( &p_filter->fmt_out.audio, &chain_output_format,
sizeof(audio_sample_format_t) );
p_filter->fmt_out.i_codec = chain_output_format.i_format;
p_filter->pf_audio_buffer_new = aout_FilterBufferNew;
/* try to find the requested filter */
if( i_visual == 2 ) /* this can only be a visualization module */
{
p_filter->p_module = module_need( p_filter, "visualization",
p_filter->p_module = module_need( p_filter, "visualization2",
psz_parser, true );
}
else /* this can be a audio filter module as well as a visualization module */
{
p_filter->p_module = module_need( p_filter, "audio filter",
p_filter->p_module = module_need( p_filter, "audio filter2",
psz_parser, true );
if ( p_filter->p_module == NULL )
......@@ -316,7 +319,7 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
aout_FormatPrepare( &p_filter->fmt_in.audio );
aout_FormatPrepare( &p_filter->fmt_out.audio );
p_filter->p_module = module_need( p_filter,
"audio filter",
"audio filter2",
psz_parser, true );
}
/* try visual filters */
......@@ -327,7 +330,7 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
memcpy( &p_filter->fmt_out.audio, &chain_output_format,
sizeof(audio_sample_format_t) );
p_filter->p_module = module_need( p_filter,
"visualization",
"visualization2",
psz_parser, true );
}
}
......@@ -639,8 +642,7 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
#ifndef AOUT_PROCESS_BEFORE_CHEKS
/* Run pre-filters. */
aout_FiltersPlay( p_aout, p_input->pp_filters, p_input->i_nb_filters,
&p_buffer );
aout_FiltersPlay( p_input->pp_filters, p_input->i_nb_filters, &p_buffer );
#endif
/* Run the resampler if needed.
......@@ -729,8 +731,7 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
/* Actually run the resampler now. */
if ( p_input->i_nb_resamplers > 0 )
{
aout_FiltersPlay( p_aout, p_input->pp_resamplers,
p_input->i_nb_resamplers,
aout_FiltersPlay( p_input->pp_resamplers, p_input->i_nb_resamplers,
&p_buffer );
}
......@@ -807,7 +808,7 @@ static vout_thread_t *RequestVout( void *p_private,
return vout_Request( p_aout, p_vout, p_fmt );
}
vout_thread_t *aout_filter_RequestVout( aout_filter_t *p_filter,
vout_thread_t *aout_filter_RequestVout( filter_t *p_filter,
vout_thread_t *p_vout, video_format_t *p_fmt )
{
aout_input_t *p_input = p_filter->p_owner->p_input;
......
......@@ -246,8 +246,7 @@ void aout_OutputDelete( aout_instance_t * p_aout )
*****************************************************************************/
void aout_OutputPlay( aout_instance_t * p_aout, aout_buffer_t * p_buffer )
{
aout_FiltersPlay( p_aout, p_aout->output.pp_filters,
p_aout->output.i_nb_filters,
aout_FiltersPlay( p_aout->output.pp_filters, p_aout->output.i_nb_filters,
&p_buffer );
if( p_buffer->i_buffer == 0 )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment