# 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_modules.h>
#include <vlc_aout.h>
#include <vlc_filter.h>
-#include <vlc_atomic.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 float ReplayGainSelect(vlc_object_t *, const char *,
- const audio_replay_gain_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, "visual", VisualizationCallback, p_input );
+ var_AddCallback( p_aout, "equalizer", EqualizerCallback, p_input );
- 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 );
- }
- }
-
- char *gain = var_InheritString (p_aout, "audio-replay-gain-mode");
- vlc_atomic_setf (&p_input->multiplier,
- ReplayGainSelect (VLC_OBJECT(p_aout), gain,
- &p_input->replay_gain));
- free (gain);
-
- 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 );
- }
-
- 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];
&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 */
}
/* 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 );
aout_InputRequestRestart ((audio_output_t *)obj);
return VLC_SUCCESS;
}
-
-float aout_InputGetMultiplier (const aout_input_t *input)
-{
- return vlc_atomic_getf (&input->multiplier);
-}
-
-static int ReplayGainCallback (vlc_object_t *obj, char const *var,
- vlc_value_t oldval, vlc_value_t val, void *data)
-{
- aout_input_t *input = data;
- float multiplier = ReplayGainSelect (obj, val.psz_string,
- &input->replay_gain);
-
- vlc_atomic_setf (&input->multiplier, multiplier);
-
- VLC_UNUSED(var); VLC_UNUSED(oldval);
- return VLC_SUCCESS;
-}
-
-static float ReplayGainSelect (vlc_object_t *obj, const char *str,
- const audio_replay_gain_t *replay_gain)
-{
- float gain = 0.;
- unsigned mode = AUDIO_REPLAY_GAIN_MAX;
-
- if (likely(str != NULL))
- { /* Find selectrf mode */
- if (!strcmp (str, "track"))
- mode = AUDIO_REPLAY_GAIN_TRACK;
- else
- if (!strcmp (str, "album"))
- mode = AUDIO_REPLAY_GAIN_ALBUM;
-
- /* If the selectrf mode is not available, prefer the other one */
- if (mode != AUDIO_REPLAY_GAIN_MAX && !replay_gain->pb_gain[mode])
- {
- if (replay_gain->pb_gain[!mode])
- mode = !mode;
- }
- }
-
- /* */
- if (mode == AUDIO_REPLAY_GAIN_MAX)
- return 1.;
-
- if (replay_gain->pb_gain[mode])
- gain = replay_gain->pf_gain[mode]
- + var_InheritFloat (obj, "audio-replay-gain-preamp");
- else
- gain = var_InheritFloat (obj, "audio-replay-gain-default");
-
- float multiplier = pow (10., gain / 20.);
-
- if (replay_gain->pb_peak[mode]
- && var_InheritBool (obj, "audio-replay-gain-peak-protection")
- && replay_gain->pf_peak[mode] * multiplier > 1.0)
- multiplier = 1.0f / replay_gain->pf_peak[mode];
-
- return multiplier;
-}