# include "config.h"
#endif
-#include <assert.h>
-
#include <vlc_common.h>
#include <stdio.h>
#include <string.h>
-#include <math.h>
#include <assert.h>
#include <vlc_input.h>
#include <vlc_vout.h> /* for vout_Request */
#include <vlc_modules.h>
-
#include <vlc_aout.h>
#include <vlc_filter.h>
#include <libvlc.h>
#include "aout_internal.h"
-static void inputFailure( audio_output_t *, aout_input_t *, const char * );
static void inputDrop( aout_input_t *, aout_buffer_t * );
static void inputResamplingStop( aout_input_t *p_input );
vlc_value_t, vlc_value_t, void * );
static int EqualizerCallback( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
-static int ReplayGainCallback( vlc_object_t *, char const *,
- vlc_value_t, vlc_value_t, void * );
-static void ReplayGainSelect( audio_output_t *, aout_input_t * );
static vout_thread_t *RequestVout( void *,
vout_thread_t *, video_format_t *, bool );
/*****************************************************************************
* aout_InputNew : allocate a new input and rework the filter pipeline
*****************************************************************************/
-int aout_InputNew( audio_output_t * p_aout,
- const audio_sample_format_t *restrict infmt,
- const audio_sample_format_t *restrict outfmt,
- aout_input_t * p_input,
- const aout_request_vout_t *p_request_vout )
+aout_input_t *aout_InputNew (audio_output_t * p_aout,
+ const audio_sample_format_t *restrict infmt,
+ const audio_sample_format_t *restrict outfmt,
+ const aout_request_vout_t *p_request_vout)
{
- audio_sample_format_t chain_input_format;
- audio_sample_format_t chain_output_format;
- vlc_value_t val, text;
- char *psz_filters, *psz_visual, *psz_scaletempo;
- int i_visual;
+ aout_input_t *p_input = malloc (sizeof (*p_input));
+ if (unlikely(p_input == NULL))
+ return NULL;
aout_FormatPrint( p_aout, "input", infmt );
p_input->samplerate = infmt->i_rate;
}
/* Prepare format structure */
- chain_input_format = *infmt;
- chain_output_format = *outfmt;
+ audio_sample_format_t chain_input_format = *infmt;
+ audio_sample_format_t chain_output_format = *outfmt;
+
chain_output_format.i_rate = infmt->i_rate;
aout_FormatPrepare( &chain_output_format );
/* Now add user filters */
- if( var_Type( p_aout, "visual" ) == 0 )
- {
- var_Create( p_aout, "visual", VLC_VAR_STRING | VLC_VAR_HASCHOICE );
- text.psz_string = _("Visualizations");
- var_Change( p_aout, "visual", VLC_VAR_SETTEXT, &text, NULL );
- val.psz_string = (char*)""; text.psz_string = _("Disable");
- var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
- val.psz_string = (char*)"spectrometer"; text.psz_string = _("Spectrometer");
- var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
- val.psz_string = (char*)"scope"; text.psz_string = _("Scope");
- var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
- val.psz_string = (char*)"spectrum"; text.psz_string = _("Spectrum");
- var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
- val.psz_string = (char*)"vuMeter"; text.psz_string = _("Vu meter");
- var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
-
- /* Look for goom plugin */
- if( module_exists( "goom" ) )
- {
- val.psz_string = (char*)"goom"; text.psz_string = (char*)"Goom";
- var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
- }
-
- /* Look for libprojectM plugin */
- if( module_exists( "projectm" ) )
- {
- val.psz_string = (char*)"projectm"; text.psz_string = (char*)"projectM";
- var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
- }
-
- if( var_Get( p_aout, "effect-list", &val ) == VLC_SUCCESS )
- {
- var_SetString( p_aout, "visual", val.psz_string );
- free( val.psz_string );
- }
- var_AddCallback( p_aout, "visual", VisualizationCallback, p_input );
- }
-
- if( var_Type( p_aout, "equalizer" ) == 0 )
- {
- module_config_t *p_config;
- int i;
-
- p_config = config_FindConfig( VLC_OBJECT(p_aout), "equalizer-preset" );
- if( p_config && p_config->i_list )
- {
- var_Create( p_aout, "equalizer",
- VLC_VAR_STRING | VLC_VAR_HASCHOICE );
- text.psz_string = _("Equalizer");
- var_Change( p_aout, "equalizer", VLC_VAR_SETTEXT, &text, NULL );
-
- val.psz_string = (char*)""; text.psz_string = _("Disable");
- var_Change( p_aout, "equalizer", VLC_VAR_ADDCHOICE, &val, &text );
-
- for( i = 0; i < p_config->i_list; i++ )
- {
- val.psz_string = (char *)p_config->ppsz_list[i];
- text.psz_string = (char *)p_config->ppsz_list_text[i];
- var_Change( p_aout, "equalizer", VLC_VAR_ADDCHOICE,
- &val, &text );
- }
-
- var_AddCallback( p_aout, "equalizer", EqualizerCallback, p_input );
- }
- }
-
- if( var_Type( p_aout, "audio-filter" ) == 0 )
- {
- var_Create( p_aout, "audio-filter",
- VLC_VAR_STRING | VLC_VAR_DOINHERIT );
- text.psz_string = _("Audio filters");
- var_Change( p_aout, "audio-filter", VLC_VAR_SETTEXT, &text, NULL );
- }
- if( var_Type( p_aout, "audio-visual" ) == 0 )
- {
- var_Create( p_aout, "audio-visual",
- VLC_VAR_STRING | VLC_VAR_DOINHERIT );
- text.psz_string = _("Audio visualizations");
- var_Change( p_aout, "audio-visual", VLC_VAR_SETTEXT, &text, NULL );
- }
-
- if( var_Type( p_aout, "audio-replay-gain-mode" ) == 0 )
- {
- module_config_t *p_config;
- int i;
-
- p_config = config_FindConfig( VLC_OBJECT(p_aout), "audio-replay-gain-mode" );
- if( p_config && p_config->i_list )
- {
- var_Create( p_aout, "audio-replay-gain-mode",
- VLC_VAR_STRING | VLC_VAR_DOINHERIT );
-
- text.psz_string = _("Replay gain");
- var_Change( p_aout, "audio-replay-gain-mode", VLC_VAR_SETTEXT, &text, NULL );
-
- for( i = 0; i < p_config->i_list; i++ )
- {
- val.psz_string = (char *)p_config->ppsz_list[i];
- text.psz_string = (char *)p_config->ppsz_list_text[i];
- var_Change( p_aout, "audio-replay-gain-mode", VLC_VAR_ADDCHOICE,
- &val, &text );
- }
-
- var_AddCallback( p_aout, "audio-replay-gain-mode", ReplayGainCallback, p_input );
- }
- }
- if( var_Type( p_aout, "audio-replay-gain-preamp" ) == 0 )
- {
- var_Create( p_aout, "audio-replay-gain-preamp",
- VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
- }
- if( var_Type( p_aout, "audio-replay-gain-default" ) == 0 )
- {
- var_Create( p_aout, "audio-replay-gain-default",
- VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
- }
- if( var_Type( p_aout, "audio-replay-gain-peak-protection" ) == 0 )
- {
- var_Create( p_aout, "audio-replay-gain-peak-protection",
- VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
- }
+ var_AddCallback( p_aout, "visual", VisualizationCallback, p_input );
+ var_AddCallback( p_aout, "equalizer", EqualizerCallback, p_input );
- psz_filters = var_GetString( p_aout, "audio-filter" );
- psz_visual = var_GetString( p_aout, "audio-visual");
- psz_scaletempo = var_InheritBool( p_aout, "audio-time-stretch" ) ? strdup( "scaletempo" ) : NULL;
+ char *psz_filters = var_GetString( p_aout, "audio-filter" );
+ char *psz_visual = var_GetString( p_aout, "audio-visual");
+ char *psz_scaletempo = var_InheritBool( p_aout, "audio-time-stretch" ) ? strdup( "scaletempo" ) : NULL;
p_input->b_recycle_vout = psz_visual && *psz_visual;
char *const ppsz_array[] = { psz_scaletempo, psz_filters, psz_visual };
p_input->p_playback_rate_filter = NULL;
- for( i_visual = 0; i_visual < 3 && AOUT_FMT_LINEAR(&chain_output_format); i_visual++ )
+ for (unsigned i_visual = 0;
+ i_visual < 3 && AOUT_FMT_LINEAR(&chain_output_format);
+ i_visual++)
{
char *psz_next = NULL;
char *psz_parser = ppsz_array[i_visual];
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 */
&chain_input_format,
&chain_output_format ) < 0 )
{
- inputFailure( p_aout, p_input, "couldn't set an input pipeline" );
- return -1;
+ msg_Err (p_aout, "cannot setup filtering pipeline");
+ goto error;
}
/* Create resamplers. */
&p_input->i_nb_resamplers,
&chain_output_format, outfmt) < 0)
{
- inputFailure( p_aout, p_input, "couldn't set a resampler pipeline");
- return -1;
+ msg_Err (p_aout, "cannot setup a resampling pipeline");
+ goto error;
}
/* Setup the initial rate of the resampler */
p_input->p_playback_rate_filter = p_input->pp_resamplers[0];
}
- ReplayGainSelect( p_aout, p_input );
-
/* Success */
- p_input->b_error = false;
p_input->i_last_input_rate = INPUT_RATE_DEFAULT;
+ p_input->i_buffer_lost = 0;
+ return p_input;
- return 0;
+error:
+ aout_FiltersDestroyPipeline( p_input->pp_filters, p_input->i_nb_filters );
+ aout_FiltersDestroyPipeline( p_input->pp_resamplers,
+ p_input->i_nb_resamplers );
+ free (p_input);
+ return NULL;
}
/*****************************************************************************
*****************************************************************************/
int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input )
{
- aout_assert_locked( p_aout );
- if ( p_input->b_error )
- return 0;
+ var_DelCallback (p_aout, "equalizer", EqualizerCallback, p_input);
+ var_DelCallback (p_aout, "visual", VisualizationCallback, p_input);
/* XXX We need to update b_recycle_vout before calling aout_FiltersDestroyPipeline.
* FIXME They can be a race condition if audio-visual is updated between
* static functions
*****************************************************************************/
-static void inputFailure( audio_output_t * p_aout, aout_input_t * p_input,
- const char * psz_error_message )
-{
- /* error message */
- msg_Err( p_aout, "%s", psz_error_message );
-
- /* clean up */
- aout_FiltersDestroyPipeline( p_input->pp_filters, p_input->i_nb_filters );
- aout_FiltersDestroyPipeline( p_input->pp_resamplers,
- p_input->i_nb_resamplers );
- var_Destroy( p_aout, "visual" );
- var_Destroy( p_aout, "equalizer" );
- var_Destroy( p_aout, "audio-filter" );
- var_Destroy( p_aout, "audio-visual" );
-
- var_Destroy( p_aout, "audio-replay-gain-mode" );
- var_Destroy( p_aout, "audio-replay-gain-default" );
- var_Destroy( p_aout, "audio-replay-gain-preamp" );
- var_Destroy( p_aout, "audio-replay-gain-peak-protection" );
-
- /* error flag */
- p_input->b_error = 1;
-}
-
static void inputDrop( aout_input_t *p_input, aout_buffer_t *p_buffer )
{
aout_BufferFree( p_buffer );
void *data)
{
const char *mode = newval.psz_string;
- aout_input_t *input = data;
+ //aout_input_t *input = data;
+ (void) data;
if (!*mode)
{
void *data)
{
char *mode = newval.psz_string;
- aout_input_t *input = data;
+ //aout_input_t *input = data;
bool ret;
+ (void) data;
(void) cmd; (void) oldval;
if (!*mode)
ret = ChangeFiltersString (obj, "audio-filter", "equalizer", false);
aout_InputRequestRestart ((audio_output_t *)obj);
return VLC_SUCCESS;
}
-
-static int ReplayGainCallback (vlc_object_t *p_this, char const *psz_cmd,
- vlc_value_t oldval, vlc_value_t val, void *data)
-{
- audio_output_t *aout = (audio_output_t *)p_this;
- aout_input_t *input = data;
-
- aout_lock (aout);
- ReplayGainSelect (aout, input);
- aout_unlock (aout);
-
- VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(val);
- return VLC_SUCCESS;
-}
-
-static void ReplayGainSelect( audio_output_t *p_aout, aout_input_t *p_input )
-{
- char *psz_replay_gain = var_GetNonEmptyString( p_aout,
- "audio-replay-gain-mode" );
- int i_mode;
- int i_use;
- float f_gain;
-
- p_input->multiplier = 1.0;
-
- if( !psz_replay_gain )
- return;
-
- /* Find select mode */
- if( !strcmp( psz_replay_gain, "track" ) )
- i_mode = AUDIO_REPLAY_GAIN_TRACK;
- else if( !strcmp( psz_replay_gain, "album" ) )
- i_mode = AUDIO_REPLAY_GAIN_ALBUM;
- else
- i_mode = AUDIO_REPLAY_GAIN_MAX;
-
- /* If the select mode is not available, prefer the other one */
- i_use = i_mode;
- if( i_use != AUDIO_REPLAY_GAIN_MAX && !p_input->replay_gain.pb_gain[i_use] )
- {
- for( i_use = 0; i_use < AUDIO_REPLAY_GAIN_MAX; i_use++ )
- {
- if( p_input->replay_gain.pb_gain[i_use] )
- break;
- }
- }
-
- /* */
- if( i_use != AUDIO_REPLAY_GAIN_MAX )
- f_gain = p_input->replay_gain.pf_gain[i_use] + var_GetFloat( p_aout, "audio-replay-gain-preamp" );
- else if( i_mode != AUDIO_REPLAY_GAIN_MAX )
- f_gain = var_GetFloat( p_aout, "audio-replay-gain-default" );
- else
- f_gain = 0.0;
- p_input->multiplier = pow( 10.0, f_gain / 20.0 );
-
- /* */
- if( p_input->replay_gain.pb_peak[i_use] &&
- var_GetBool( p_aout, "audio-replay-gain-peak-protection" ) &&
- p_input->replay_gain.pf_peak[i_use] * p_input->multiplier > 1.0 )
- {
- p_input->multiplier = 1.0f / p_input->replay_gain.pf_peak[i_use];
- }
-
- free( psz_replay_gain );
-}