1 /*****************************************************************************
2 * input.c : internal management of input streams for the audio output
3 *****************************************************************************
4 * Copyright (C) 2002-2007 the VideoLAN team
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
31 #include <stdlib.h> /* calloc(), malloc(), free() */
34 #include <vlc_input.h> /* for input_thread_t and i_pts_delay */
41 #include "aout_internal.h"
43 /** FIXME: Ugly but needed to access the counters */
44 #include "input/input_internal.h"
46 static void inputFailure( aout_instance_t *, aout_input_t *, const char * );
47 static void inputDrop( aout_instance_t *, aout_input_t *, aout_buffer_t * );
48 static void inputResamplingStop( aout_input_t *p_input );
50 static int VisualizationCallback( vlc_object_t *, char const *,
51 vlc_value_t, vlc_value_t, void * );
52 static int EqualizerCallback( vlc_object_t *, char const *,
53 vlc_value_t, vlc_value_t, void * );
55 /*****************************************************************************
56 * aout_InputNew : allocate a new input and rework the filter pipeline
57 *****************************************************************************/
58 int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input )
60 audio_sample_format_t chain_input_format;
61 audio_sample_format_t chain_output_format;
62 vlc_value_t val, text;
63 char * psz_filters, *psz_visual;
66 aout_FormatPrint( p_aout, "input", &p_input->input );
68 p_input->i_nb_resamplers = p_input->i_nb_filters = 0;
71 aout_FifoInit( p_aout, &p_input->fifo, p_aout->mixer.mixer.i_rate );
72 p_input->p_first_byte_to_mix = NULL;
74 /* Prepare format structure */
75 memcpy( &chain_input_format, &p_input->input,
76 sizeof(audio_sample_format_t) );
77 memcpy( &chain_output_format, &p_aout->mixer.mixer,
78 sizeof(audio_sample_format_t) );
79 chain_output_format.i_rate = p_input->input.i_rate;
80 aout_FormatPrepare( &chain_output_format );
82 /* Now add user filters */
83 if( var_Type( p_aout, "visual" ) == 0 )
86 var_Create( p_aout, "visual", VLC_VAR_STRING | VLC_VAR_HASCHOICE );
87 text.psz_string = _("Visualizations");
88 var_Change( p_aout, "visual", VLC_VAR_SETTEXT, &text, NULL );
89 val.psz_string = ""; text.psz_string = _("Disable");
90 var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
91 val.psz_string = "spectrometer"; text.psz_string = _("Spectrometer");
92 var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
93 val.psz_string = "scope"; text.psz_string = _("Scope");
94 var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
95 val.psz_string = "spectrum"; text.psz_string = _("Spectrum");
96 var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
98 /* Look for goom plugin */
99 p_module = config_FindModule( VLC_OBJECT(p_aout), "goom" );
102 val.psz_string = "goom"; text.psz_string = "Goom";
103 var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
106 /* Look for galaktos plugin */
107 p_module = config_FindModule( VLC_OBJECT(p_aout), "galaktos" );
110 val.psz_string = "galaktos"; text.psz_string = "GaLaktos";
111 var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
114 if( var_Get( p_aout, "effect-list", &val ) == VLC_SUCCESS )
116 var_Set( p_aout, "visual", val );
117 if( val.psz_string ) free( val.psz_string );
119 var_AddCallback( p_aout, "visual", VisualizationCallback, NULL );
122 if( var_Type( p_aout, "equalizer" ) == 0 )
124 module_config_t *p_config;
127 p_config = config_FindConfig( VLC_OBJECT(p_aout), "equalizer-preset" );
128 if( p_config && p_config->i_list )
130 var_Create( p_aout, "equalizer",
131 VLC_VAR_STRING | VLC_VAR_HASCHOICE );
132 text.psz_string = _("Equalizer");
133 var_Change( p_aout, "equalizer", VLC_VAR_SETTEXT, &text, NULL );
135 val.psz_string = ""; text.psz_string = _("Disable");
136 var_Change( p_aout, "equalizer", VLC_VAR_ADDCHOICE, &val, &text );
138 for( i = 0; i < p_config->i_list; i++ )
140 val.psz_string = (char *)p_config->ppsz_list[i];
141 text.psz_string = (char *)p_config->ppsz_list_text[i];
142 var_Change( p_aout, "equalizer", VLC_VAR_ADDCHOICE,
146 var_AddCallback( p_aout, "equalizer", EqualizerCallback, NULL );
150 if( var_Type( p_aout, "audio-filter" ) == 0 )
152 var_Create( p_aout, "audio-filter",
153 VLC_VAR_STRING | VLC_VAR_DOINHERIT );
154 text.psz_string = _("Audio filters");
155 var_Change( p_aout, "audio-filter", VLC_VAR_SETTEXT, &text, NULL );
157 if( var_Type( p_aout, "audio-visual" ) == 0 )
159 var_Create( p_aout, "audio-visual",
160 VLC_VAR_STRING | VLC_VAR_DOINHERIT );
161 text.psz_string = _("Audio visualizations");
162 var_Change( p_aout, "audio-visual", VLC_VAR_SETTEXT, &text, NULL );
165 var_Get( p_aout, "audio-filter", &val );
166 psz_filters = val.psz_string;
167 var_Get( p_aout, "audio-visual", &val );
168 psz_visual = val.psz_string;
170 /* parse user filter lists */
171 for( i_visual = 0; i_visual < 2; i_visual++ )
173 char *psz_next = NULL;
174 char *psz_parser = i_visual ? psz_visual : psz_filters;
176 if( psz_parser == NULL || !*psz_parser )
179 while( psz_parser && *psz_parser )
181 aout_filter_t * p_filter = NULL;
183 if( p_input->i_nb_filters >= AOUT_MAX_FILTERS )
185 msg_Dbg( p_aout, "max filters reached (%d)", AOUT_MAX_FILTERS );
189 while( *psz_parser == ' ' && *psz_parser == ':' )
193 if( ( psz_next = strchr( psz_parser , ':' ) ) )
197 if( *psz_parser =='\0' )
202 /* Create a VLC object */
203 p_filter = vlc_object_create( p_aout, sizeof(aout_filter_t) );
204 if( p_filter == NULL )
206 msg_Err( p_aout, "cannot add user filter %s (skipped)",
208 psz_parser = psz_next;
212 vlc_object_attach( p_filter , p_aout );
214 /* try to find the requested filter */
215 if( i_visual == 1 ) /* this can only be a visualization module */
218 memcpy( &p_filter->input, &chain_output_format,
219 sizeof(audio_sample_format_t) );
220 memcpy( &p_filter->output, &chain_output_format,
221 sizeof(audio_sample_format_t) );
223 p_filter->p_module = module_Need( p_filter, "visualization",
224 psz_parser, VLC_TRUE );
226 else /* this can be a audio filter module as well as a visualization module */
229 memcpy( &p_filter->input, &chain_input_format,
230 sizeof(audio_sample_format_t) );
231 memcpy( &p_filter->output, &chain_output_format,
232 sizeof(audio_sample_format_t) );
234 p_filter->p_module = module_Need( p_filter, "audio filter",
235 psz_parser, VLC_TRUE );
237 if ( p_filter->p_module == NULL )
239 /* if the filter requested a special format, retry */
240 if ( !( AOUT_FMTS_IDENTICAL( &p_filter->input,
241 &chain_input_format )
242 && AOUT_FMTS_IDENTICAL( &p_filter->output,
243 &chain_output_format ) ) )
245 aout_FormatPrepare( &p_filter->input );
246 aout_FormatPrepare( &p_filter->output );
247 p_filter->p_module = module_Need( p_filter,
249 psz_parser, VLC_TRUE );
251 /* try visual filters */
254 memcpy( &p_filter->input, &chain_output_format,
255 sizeof(audio_sample_format_t) );
256 memcpy( &p_filter->output, &chain_output_format,
257 sizeof(audio_sample_format_t) );
258 p_filter->p_module = module_Need( p_filter,
260 psz_parser, VLC_TRUE );
266 if ( p_filter->p_module == NULL )
268 msg_Err( p_aout, "cannot add user filter %s (skipped)",
271 vlc_object_detach( p_filter );
272 vlc_object_destroy( p_filter );
274 psz_parser = psz_next;
278 /* complete the filter chain if necessary */
279 if ( !AOUT_FMTS_IDENTICAL( &chain_input_format, &p_filter->input ) )
281 if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_filters,
282 &p_input->i_nb_filters,
284 &p_filter->input ) < 0 )
286 msg_Err( p_aout, "cannot add user filter %s (skipped)",
289 module_Unneed( p_filter, p_filter->p_module );
290 vlc_object_detach( p_filter );
291 vlc_object_destroy( p_filter );
293 psz_parser = psz_next;
299 p_filter->b_continuity = VLC_FALSE;
300 p_input->pp_filters[p_input->i_nb_filters++] = p_filter;
301 memcpy( &chain_input_format, &p_filter->output,
302 sizeof( audio_sample_format_t ) );
304 /* next filter if any */
305 psz_parser = psz_next;
308 if( psz_filters ) free( psz_filters );
309 if( psz_visual ) free( psz_visual );
311 /* complete the filter chain if necessary */
312 if ( !AOUT_FMTS_IDENTICAL( &chain_input_format, &chain_output_format ) )
314 if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_filters,
315 &p_input->i_nb_filters,
317 &chain_output_format ) < 0 )
319 inputFailure( p_aout, p_input, "couldn't set an input pipeline" );
324 /* Prepare hints for the buffer allocator. */
325 p_input->input_alloc.i_alloc_type = AOUT_ALLOC_HEAP;
326 p_input->input_alloc.i_bytes_per_sec = -1;
328 /* Create resamplers. */
329 if ( !AOUT_FMT_NON_LINEAR( &p_aout->mixer.mixer ) )
331 chain_output_format.i_rate = (__MAX(p_input->input.i_rate,
332 p_aout->mixer.mixer.i_rate)
333 * (100 + AOUT_MAX_RESAMPLING)) / 100;
334 if ( chain_output_format.i_rate == p_aout->mixer.mixer.i_rate )
336 /* Just in case... */
337 chain_output_format.i_rate++;
339 if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_resamplers,
340 &p_input->i_nb_resamplers,
341 &chain_output_format,
342 &p_aout->mixer.mixer ) < 0 )
344 inputFailure( p_aout, p_input, "couldn't set a resampler pipeline");
348 aout_FiltersHintBuffers( p_aout, p_input->pp_resamplers,
349 p_input->i_nb_resamplers,
350 &p_input->input_alloc );
351 p_input->input_alloc.i_alloc_type = AOUT_ALLOC_HEAP;
353 /* Setup the initial rate of the resampler */
354 p_input->pp_resamplers[0]->input.i_rate = p_input->input.i_rate;
356 p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
358 aout_FiltersHintBuffers( p_aout, p_input->pp_filters,
359 p_input->i_nb_filters,
360 &p_input->input_alloc );
361 p_input->input_alloc.i_alloc_type = AOUT_ALLOC_HEAP;
363 /* i_bytes_per_sec is still == -1 if no filters */
364 p_input->input_alloc.i_bytes_per_sec = __MAX(
365 p_input->input_alloc.i_bytes_per_sec,
366 (int)(p_input->input.i_bytes_per_frame
367 * p_input->input.i_rate
368 / p_input->input.i_frame_length) );
370 p_input->b_error = VLC_FALSE;
371 p_input->b_restart = VLC_FALSE;
372 p_input->i_last_input_rate = INPUT_RATE_DEFAULT;
377 /*****************************************************************************
378 * aout_InputDelete : delete an input
379 *****************************************************************************
380 * This function must be entered with the mixer lock.
381 *****************************************************************************/
382 int aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input )
384 if ( p_input->b_error ) return 0;
386 aout_FiltersDestroyPipeline( p_aout, p_input->pp_filters,
387 p_input->i_nb_filters );
388 p_input->i_nb_filters = 0;
389 aout_FiltersDestroyPipeline( p_aout, p_input->pp_resamplers,
390 p_input->i_nb_resamplers );
391 p_input->i_nb_resamplers = 0;
392 aout_FifoDestroy( p_aout, &p_input->fifo );
397 /*****************************************************************************
398 * aout_InputPlay : play a buffer
399 *****************************************************************************
400 * This function must be entered with the input lock.
401 *****************************************************************************/
402 /* XXX Do not activate it !! */
403 //#define AOUT_PROCESS_BEFORE_CHEKS
404 int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
405 aout_buffer_t * p_buffer, int i_input_rate )
409 if( p_input->b_restart )
411 aout_fifo_t fifo, dummy_fifo;
412 byte_t *p_first_byte_to_mix;
414 vlc_mutex_lock( &p_aout->mixer_lock );
416 /* A little trick to avoid loosing our input fifo */
417 aout_FifoInit( p_aout, &dummy_fifo, p_aout->mixer.mixer.i_rate );
418 p_first_byte_to_mix = p_input->p_first_byte_to_mix;
419 fifo = p_input->fifo;
420 p_input->fifo = dummy_fifo;
421 aout_InputDelete( p_aout, p_input );
422 aout_InputNew( p_aout, p_input );
423 p_input->p_first_byte_to_mix = p_first_byte_to_mix;
424 p_input->fifo = fifo;
426 vlc_mutex_unlock( &p_aout->mixer_lock );
429 #ifdef AOUT_PROCESS_BEFORE_CHEKS
430 /* Run pre-filters. */
431 aout_FiltersPlay( p_aout, p_input->pp_filters, p_input->i_nb_filters,
434 /* Actually run the resampler now. */
435 if ( p_input->i_nb_resamplers > 0 )
437 const mtime_t i_date = p_buffer->start_date;
438 aout_FiltersPlay( p_aout, p_input->pp_resamplers,
439 p_input->i_nb_resamplers,
443 if( p_buffer->i_nb_samples <= 0 )
445 aout_BufferFree( p_buffer );
450 /* Handle input rate change by modifying resampler input rate */
451 if( i_input_rate != p_input->i_last_input_rate )
453 unsigned int * const pi_rate = &p_input->pp_resamplers[0]->input.i_rate;
454 #define F(r,ir) ( INPUT_RATE_DEFAULT * (r) / (ir) )
455 const int i_delta = *pi_rate - F(p_input->input.i_rate,p_input->i_last_input_rate);
456 *pi_rate = F(p_input->input.i_rate + i_delta, i_input_rate);
458 p_input->i_last_input_rate = i_input_rate;
461 /* We don't care if someone changes the start date behind our back after
462 * this. We'll deal with that when pushing the buffer, and compensate
463 * with the next incoming buffer. */
464 vlc_mutex_lock( &p_aout->input_fifos_lock );
465 start_date = aout_FifoNextStart( p_aout, &p_input->fifo );
466 vlc_mutex_unlock( &p_aout->input_fifos_lock );
468 if ( start_date != 0 && start_date < mdate() )
470 /* The decoder is _very_ late. This can only happen if the user
471 * pauses the stream (or if the decoder is buggy, which cannot
473 msg_Warn( p_aout, "computed PTS is out of range ("I64Fd"), "
474 "clearing out", mdate() - start_date );
475 vlc_mutex_lock( &p_aout->input_fifos_lock );
476 aout_FifoSet( p_aout, &p_input->fifo, 0 );
477 p_input->p_first_byte_to_mix = NULL;
478 vlc_mutex_unlock( &p_aout->input_fifos_lock );
479 if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE )
480 msg_Warn( p_aout, "timing screwed, stopping resampling" );
481 inputResamplingStop( p_input );
485 if ( p_buffer->start_date < mdate() + AOUT_MIN_PREPARE_TIME )
487 /* The decoder gives us f*cked up PTS. It's its business, but we
488 * can't present it anyway, so drop the buffer. */
489 msg_Warn( p_aout, "PTS is out of range ("I64Fd"), dropping buffer",
490 mdate() - p_buffer->start_date );
492 inputDrop( p_aout, p_input, p_buffer );
493 inputResamplingStop( p_input );
497 /* If the audio drift is too big then it's not worth trying to resample
499 if ( start_date != 0 &&
500 ( start_date < p_buffer->start_date - 3 * AOUT_PTS_TOLERANCE ) )
502 msg_Warn( p_aout, "audio drift is too big ("I64Fd"), clearing out",
503 start_date - p_buffer->start_date );
504 vlc_mutex_lock( &p_aout->input_fifos_lock );
505 aout_FifoSet( p_aout, &p_input->fifo, 0 );
506 p_input->p_first_byte_to_mix = NULL;
507 vlc_mutex_unlock( &p_aout->input_fifos_lock );
508 if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE )
509 msg_Warn( p_aout, "timing screwed, stopping resampling" );
510 inputResamplingStop( p_input );
513 else if ( start_date != 0 &&
514 ( start_date > p_buffer->start_date + 3 * AOUT_PTS_TOLERANCE ) )
516 msg_Warn( p_aout, "audio drift is too big ("I64Fd"), dropping buffer",
517 start_date - p_buffer->start_date );
518 inputDrop( p_aout, p_input, p_buffer );
522 if ( start_date == 0 ) start_date = p_buffer->start_date;
524 #ifndef AOUT_PROCESS_BEFORE_CHEKS
525 /* Run pre-filters. */
526 aout_FiltersPlay( p_aout, p_input->pp_filters, p_input->i_nb_filters,
530 /* Run the resampler if needed.
531 * We first need to calculate the output rate of this resampler. */
532 if ( ( p_input->i_resampling_type == AOUT_RESAMPLING_NONE ) &&
533 ( start_date < p_buffer->start_date - AOUT_PTS_TOLERANCE
534 || start_date > p_buffer->start_date + AOUT_PTS_TOLERANCE ) &&
535 p_input->i_nb_resamplers > 0 )
537 /* Can happen in several circumstances :
538 * 1. A problem at the input (clock drift)
539 * 2. A small pause triggered by the user
540 * 3. Some delay in the output stage, causing a loss of lip
542 * Solution : resample the buffer to avoid a scratch.
544 mtime_t drift = p_buffer->start_date - start_date;
546 p_input->i_resamp_start_date = mdate();
547 p_input->i_resamp_start_drift = (int)drift;
550 p_input->i_resampling_type = AOUT_RESAMPLING_DOWN;
552 p_input->i_resampling_type = AOUT_RESAMPLING_UP;
554 msg_Warn( p_aout, "buffer is "I64Fd" %s, triggering %ssampling",
555 drift > 0 ? drift : -drift,
556 drift > 0 ? "in advance" : "late",
557 drift > 0 ? "down" : "up");
560 if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE )
562 /* Resampling has been triggered previously (because of dates
563 * mismatch). We want the resampling to happen progressively so
564 * it isn't too audible to the listener. */
566 if( p_input->i_resampling_type == AOUT_RESAMPLING_UP )
568 p_input->pp_resamplers[0]->input.i_rate += 2; /* Hz */
572 p_input->pp_resamplers[0]->input.i_rate -= 2; /* Hz */
575 /* Check if everything is back to normal, in which case we can stop the
577 if( p_input->pp_resamplers[0]->input.i_rate == 1000 * p_input->input.i_rate / i_input_rate )
579 p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
580 msg_Warn( p_aout, "resampling stopped after "I64Fi" usec "
582 mdate() - p_input->i_resamp_start_date,
583 p_buffer->start_date - start_date);
585 else if( abs( (int)(p_buffer->start_date - start_date) ) <
586 abs( p_input->i_resamp_start_drift ) / 2 )
588 /* if we reduced the drift from half, then it is time to switch
589 * back the resampling direction. */
590 if( p_input->i_resampling_type == AOUT_RESAMPLING_UP )
591 p_input->i_resampling_type = AOUT_RESAMPLING_DOWN;
593 p_input->i_resampling_type = AOUT_RESAMPLING_UP;
594 p_input->i_resamp_start_drift = 0;
596 else if( p_input->i_resamp_start_drift &&
597 ( abs( (int)(p_buffer->start_date - start_date) ) >
598 abs( p_input->i_resamp_start_drift ) * 3 / 2 ) )
600 /* If the drift is increasing and not decreasing, than something
601 * is bad. We'd better stop the resampling right now. */
602 msg_Warn( p_aout, "timing screwed, stopping resampling" );
603 inputResamplingStop( p_input );
607 #ifndef AOUT_PROCESS_BEFORE_CHEKS
608 /* Actually run the resampler now. */
609 if ( p_input->i_nb_resamplers > 0 )
611 aout_FiltersPlay( p_aout, p_input->pp_resamplers,
612 p_input->i_nb_resamplers,
616 if( p_buffer->i_nb_samples <= 0 )
618 aout_BufferFree( p_buffer );
623 /* Adding the start date will be managed by aout_FifoPush(). */
624 p_buffer->end_date = start_date +
625 (p_buffer->end_date - p_buffer->start_date);
626 p_buffer->start_date = start_date;
628 vlc_mutex_lock( &p_aout->input_fifos_lock );
629 aout_FifoPush( p_aout, &p_input->fifo, p_buffer );
630 vlc_mutex_unlock( &p_aout->input_fifos_lock );
634 /*****************************************************************************
636 *****************************************************************************/
638 static void inputFailure( aout_instance_t * p_aout, aout_input_t * p_input,
639 const char * psz_error_message )
642 msg_Err( p_aout, "%s", psz_error_message );
645 aout_FiltersDestroyPipeline( p_aout, p_input->pp_filters,
646 p_input->i_nb_filters );
647 aout_FiltersDestroyPipeline( p_aout, p_input->pp_resamplers,
648 p_input->i_nb_resamplers );
649 aout_FifoDestroy( p_aout, &p_input->fifo );
650 var_Destroy( p_aout, "visual" );
651 var_Destroy( p_aout, "equalizer" );
652 var_Destroy( p_aout, "audio-filter" );
653 var_Destroy( p_aout, "audio-visual" );
656 p_input->b_error = 1;
659 static void inputDrop( aout_instance_t *p_aout, aout_input_t *p_input, aout_buffer_t *p_buffer )
661 aout_BufferFree( p_buffer );
663 if( !p_input->p_input_thread )
666 vlc_mutex_lock( &p_input->p_input_thread->p->counters.counters_lock);
667 stats_UpdateInteger( p_aout, p_input->p_input_thread->p->counters.p_lost_abuffers, 1, NULL );
668 vlc_mutex_unlock( &p_input->p_input_thread->p->counters.counters_lock);
671 static void inputResamplingStop( aout_input_t *p_input )
673 p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
674 if( p_input->i_nb_resamplers != 0 )
676 p_input->pp_resamplers[0]->input.i_rate = INPUT_RATE_DEFAULT *
677 p_input->input.i_rate / p_input->i_last_input_rate;
678 p_input->pp_resamplers[0]->b_continuity = VLC_FALSE;
682 static int ChangeFiltersString( aout_instance_t * p_aout, const char* psz_variable,
683 const char *psz_name, vlc_bool_t b_add )
688 var_Get( p_aout, psz_variable, &val );
690 if( !val.psz_string ) val.psz_string = strdup("");
692 psz_parser = strstr( val.psz_string, psz_name );
698 psz_parser = val.psz_string;
699 asprintf( &val.psz_string, (*val.psz_string) ? "%s:%s" : "%s%s",
700 val.psz_string, psz_name );
712 memmove( psz_parser, psz_parser + strlen(psz_name) +
713 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
714 strlen(psz_parser + strlen(psz_name)) + 1 );
718 free( val.psz_string );
723 var_Set( p_aout, psz_variable, val );
724 free( val.psz_string );
728 static int VisualizationCallback( vlc_object_t *p_this, char const *psz_cmd,
729 vlc_value_t oldval, vlc_value_t newval, void *p_data )
731 aout_instance_t *p_aout = (aout_instance_t *)p_this;
732 char *psz_mode = newval.psz_string;
735 (void)psz_cmd; (void)oldval; (void)p_data;
737 if( !psz_mode || !*psz_mode )
739 ChangeFiltersString( p_aout, "audio-visual", "goom", VLC_FALSE );
740 ChangeFiltersString( p_aout, "audio-visual", "visual", VLC_FALSE );
741 ChangeFiltersString( p_aout, "audio-visual", "galaktos", VLC_FALSE );
745 if( !strcmp( "goom", psz_mode ) )
747 ChangeFiltersString( p_aout, "audio-visual", "visual", VLC_FALSE );
748 ChangeFiltersString( p_aout, "audio-visual", "goom", VLC_TRUE );
749 ChangeFiltersString( p_aout, "audio-visual", "galaktos", VLC_FALSE);
751 else if( !strcmp( "galaktos", psz_mode ) )
753 ChangeFiltersString( p_aout, "audio-visual", "visual", VLC_FALSE );
754 ChangeFiltersString( p_aout, "audio-visual", "goom", VLC_FALSE );
755 ChangeFiltersString( p_aout, "audio-visual", "galaktos", VLC_TRUE );
759 val.psz_string = psz_mode;
760 var_Create( p_aout, "effect-list", VLC_VAR_STRING );
761 var_Set( p_aout, "effect-list", val );
763 ChangeFiltersString( p_aout, "audio-visual", "goom", VLC_FALSE );
764 ChangeFiltersString( p_aout, "audio-visual", "visual", VLC_TRUE );
765 ChangeFiltersString( p_aout, "audio-visual", "galaktos", VLC_FALSE);
770 for( i = 0; i < p_aout->i_nb_inputs; i++ )
772 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
778 static int EqualizerCallback( vlc_object_t *p_this, char const *psz_cmd,
779 vlc_value_t oldval, vlc_value_t newval, void *p_data )
781 aout_instance_t *p_aout = (aout_instance_t *)p_this;
782 char *psz_mode = newval.psz_string;
786 (void)psz_cmd; (void)oldval; (void)p_data;
788 if( !psz_mode || !*psz_mode )
790 i_ret = ChangeFiltersString( p_aout, "audio-filter", "equalizer",
795 val.psz_string = psz_mode;
796 var_Create( p_aout, "equalizer-preset", VLC_VAR_STRING );
797 var_Set( p_aout, "equalizer-preset", val );
798 i_ret = ChangeFiltersString( p_aout, "audio-filter", "equalizer",
806 for( i = 0; i < p_aout->i_nb_inputs; i++ )
808 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;