1 /*****************************************************************************
2 * input.c : internal management of input streams for the audio output
3 *****************************************************************************
4 * Copyright (C) 2002-2004 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* calloc(), malloc(), free() */
31 #include <vlc/input.h> /* for input_thread_t and i_pts_delay */
37 #include "audio_output.h"
38 #include "aout_internal.h"
40 static int VisualizationCallback( vlc_object_t *, char const *,
41 vlc_value_t, vlc_value_t, void * );
42 static int EqualizerCallback( vlc_object_t *, char const *,
43 vlc_value_t, vlc_value_t, void * );
44 static aout_filter_t * allocateUserChannelMixer( aout_instance_t *,
45 audio_sample_format_t *,
46 audio_sample_format_t * );
48 /*****************************************************************************
49 * aout_InputNew : allocate a new input and rework the filter pipeline
50 *****************************************************************************/
51 int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input )
53 audio_sample_format_t user_filter_format;
54 audio_sample_format_t intermediate_format;/* input of resampler */
55 vlc_value_t val, text;
56 char * psz_filters, *psz_visual;
57 aout_filter_t * p_user_channel_mixer;
59 aout_FormatPrint( p_aout, "input", &p_input->input );
62 aout_FifoInit( p_aout, &p_input->fifo, p_aout->mixer.mixer.i_rate );
63 p_input->p_first_byte_to_mix = NULL;
65 /* Prepare format structure */
66 memcpy( &intermediate_format, &p_aout->mixer.mixer,
67 sizeof(audio_sample_format_t) );
68 intermediate_format.i_rate = p_input->input.i_rate;
70 /* Try to use the channel mixer chosen by the user */
71 memcpy ( &user_filter_format, &intermediate_format,
72 sizeof(audio_sample_format_t) );
73 user_filter_format.i_physical_channels = p_input->input.i_physical_channels;
74 user_filter_format.i_original_channels = p_input->input.i_original_channels;
75 user_filter_format.i_bytes_per_frame = user_filter_format.i_bytes_per_frame
76 * aout_FormatNbChannels( &user_filter_format )
77 / aout_FormatNbChannels( &intermediate_format );
78 p_user_channel_mixer = allocateUserChannelMixer( p_aout, &user_filter_format,
79 &intermediate_format );
80 /* If it failed, let the main pipeline do channel mixing */
81 if ( ! p_user_channel_mixer )
83 memcpy ( &user_filter_format, &intermediate_format,
84 sizeof(audio_sample_format_t) );
88 if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_filters,
89 &p_input->i_nb_filters,
94 msg_Err( p_aout, "couldn't set an input pipeline" );
96 aout_FifoDestroy( p_aout, &p_input->fifo );
101 /* Now add user filters */
102 if( var_Type( p_aout, "visual" ) == 0 )
105 var_Create( p_aout, "visual", VLC_VAR_STRING | VLC_VAR_HASCHOICE );
106 text.psz_string = _("Visualizations");
107 var_Change( p_aout, "visual", VLC_VAR_SETTEXT, &text, NULL );
108 val.psz_string = ""; text.psz_string = _("Disable");
109 var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
110 val.psz_string = "random"; text.psz_string = _("Random");
111 var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
112 val.psz_string = "scope"; text.psz_string = _("Scope");
113 var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
114 val.psz_string = "spectrum"; text.psz_string = _("Spectrum");
115 var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
117 /* Look for goom plugin */
118 p_module = config_FindModule( VLC_OBJECT(p_aout), "goom" );
121 val.psz_string = "goom"; text.psz_string = "Goom";
122 var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
125 /* Look for galaktos plugin */
126 p_module = config_FindModule( VLC_OBJECT(p_aout), "galaktos" );
129 val.psz_string = "galaktos"; text.psz_string = "GaLaktos";
130 var_Change( p_aout, "visual", VLC_VAR_ADDCHOICE, &val, &text );
133 if( var_Get( p_aout, "effect-list", &val ) == VLC_SUCCESS )
135 var_Set( p_aout, "visual", val );
136 if( val.psz_string ) free( val.psz_string );
138 var_AddCallback( p_aout, "visual", VisualizationCallback, NULL );
141 if( var_Type( p_aout, "equalizer" ) == 0 )
143 module_config_t *p_config;
146 p_config = config_FindConfig( VLC_OBJECT(p_aout), "equalizer-preset" );
147 if( p_config && p_config->i_list )
149 var_Create( p_aout, "equalizer",
150 VLC_VAR_STRING | VLC_VAR_HASCHOICE );
151 text.psz_string = _("Equalizer");
152 var_Change( p_aout, "equalizer", VLC_VAR_SETTEXT, &text, NULL );
154 val.psz_string = ""; text.psz_string = _("Disable");
155 var_Change( p_aout, "equalizer", VLC_VAR_ADDCHOICE, &val, &text );
157 for( i = 0; i < p_config->i_list; i++ )
159 val.psz_string = p_config->ppsz_list[i];
160 text.psz_string = p_config->ppsz_list_text[i];
161 var_Change( p_aout, "equalizer", VLC_VAR_ADDCHOICE,
165 var_AddCallback( p_aout, "equalizer", EqualizerCallback, NULL );
169 if( var_Type( p_aout, "audio-filter" ) == 0 )
171 var_Create( p_aout, "audio-filter",
172 VLC_VAR_STRING | VLC_VAR_DOINHERIT );
173 text.psz_string = _("Audio filters");
174 var_Change( p_aout, "audio-filter", VLC_VAR_SETTEXT, &text, NULL );
176 if( var_Type( p_aout, "audio-visual" ) == 0 )
178 var_Create( p_aout, "audio-visual",
179 VLC_VAR_STRING | VLC_VAR_DOINHERIT );
180 text.psz_string = _("Audio visualizations");
181 var_Change( p_aout, "audio-visual", VLC_VAR_SETTEXT, &text, NULL );
184 var_Get( p_aout, "audio-filter", &val );
185 psz_filters = val.psz_string;
186 var_Get( p_aout, "audio-visual", &val );
187 psz_visual = val.psz_string;
189 if( psz_filters && *psz_filters && psz_visual && *psz_visual )
191 psz_filters = (char *)realloc( psz_filters, strlen( psz_filters ) +
192 strlen( psz_visual ) + 1);
193 sprintf( psz_filters, "%s,%s", psz_filters, psz_visual );
195 else if( psz_visual && *psz_visual )
197 if( psz_filters ) free( psz_filters );
198 psz_filters = strdup( psz_visual );
201 if( psz_filters && *psz_filters )
203 char *psz_parser = psz_filters;
205 while( psz_parser && *psz_parser )
207 aout_filter_t * p_filter;
209 if( p_input->i_nb_filters >= AOUT_MAX_FILTERS )
211 msg_Dbg( p_aout, "max filter reached (%d)", AOUT_MAX_FILTERS );
215 while( *psz_parser == ' ' && *psz_parser == ',' )
219 if( ( psz_next = strchr( psz_parser , ',' ) ) )
223 if( *psz_parser =='\0' )
228 msg_Dbg( p_aout, "user filter \"%s\"", psz_parser );
230 /* Create a VLC object */
231 p_filter = vlc_object_create( p_aout, sizeof(aout_filter_t) );
232 if( p_filter == NULL )
234 msg_Err( p_aout, "cannot add user filter %s (skipped)",
236 psz_parser = psz_next;
240 vlc_object_attach( p_filter , p_aout );
241 memcpy( &p_filter->input, &user_filter_format,
242 sizeof(audio_sample_format_t) );
243 memcpy( &p_filter->output, &user_filter_format,
244 sizeof(audio_sample_format_t) );
247 module_Need( p_filter,"audio filter", psz_parser, VLC_FALSE );
249 if( p_filter->p_module== NULL )
252 module_Need( p_filter,"visualization", psz_parser,
254 if( p_filter->p_module == NULL )
256 msg_Err( p_aout, "cannot add user filter %s (skipped)",
259 vlc_object_detach( p_filter );
260 vlc_object_destroy( p_filter );
261 psz_parser = psz_next;
265 p_filter->b_continuity = VLC_FALSE;
267 p_input->pp_filters[p_input->i_nb_filters++] = p_filter;
269 /* next filter if any */
270 psz_parser = psz_next;
273 if( psz_filters ) free( psz_filters );
274 if( psz_visual ) free( psz_visual );
276 /* Attach the user channel mixer */
277 if ( p_user_channel_mixer )
279 p_input->pp_filters[p_input->i_nb_filters++] = p_user_channel_mixer;
282 /* Prepare hints for the buffer allocator. */
283 p_input->input_alloc.i_alloc_type = AOUT_ALLOC_HEAP;
284 p_input->input_alloc.i_bytes_per_sec = -1;
286 if ( AOUT_FMT_NON_LINEAR( &p_aout->mixer.mixer ) )
288 p_input->i_nb_resamplers = 0;
292 /* Create resamplers. */
293 intermediate_format.i_rate = (__MAX(p_input->input.i_rate,
294 p_aout->mixer.mixer.i_rate)
295 * (100 + AOUT_MAX_RESAMPLING)) / 100;
296 if ( intermediate_format.i_rate == p_aout->mixer.mixer.i_rate )
298 /* Just in case... */
299 intermediate_format.i_rate++;
301 if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_resamplers,
302 &p_input->i_nb_resamplers,
303 &intermediate_format,
304 &p_aout->mixer.mixer ) < 0 )
306 msg_Err( p_aout, "couldn't set a resampler pipeline" );
308 aout_FiltersDestroyPipeline( p_aout, p_input->pp_filters,
309 p_input->i_nb_filters );
310 aout_FifoDestroy( p_aout, &p_input->fifo );
311 var_Destroy( p_aout, "visual" );
312 p_input->b_error = 1;
317 aout_FiltersHintBuffers( p_aout, p_input->pp_resamplers,
318 p_input->i_nb_resamplers,
319 &p_input->input_alloc );
321 /* Setup the initial rate of the resampler */
322 p_input->pp_resamplers[0]->input.i_rate = p_input->input.i_rate;
324 p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
326 p_input->input_alloc.i_alloc_type = AOUT_ALLOC_HEAP;
327 aout_FiltersHintBuffers( p_aout, p_input->pp_filters,
328 p_input->i_nb_filters,
329 &p_input->input_alloc );
331 /* i_bytes_per_sec is still == -1 if no filters */
332 p_input->input_alloc.i_bytes_per_sec = __MAX(
333 p_input->input_alloc.i_bytes_per_sec,
334 (int)(p_input->input.i_bytes_per_frame
335 * p_input->input.i_rate
336 / p_input->input.i_frame_length) );
337 /* Allocate in the heap, it is more convenient for the decoder. */
338 p_input->input_alloc.i_alloc_type = AOUT_ALLOC_HEAP;
340 p_input->b_error = VLC_FALSE;
341 p_input->b_restart = VLC_FALSE;
346 /*****************************************************************************
347 * aout_InputDelete : delete an input
348 *****************************************************************************
349 * This function must be entered with the mixer lock.
350 *****************************************************************************/
351 int aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input )
353 if ( p_input->b_error ) return 0;
355 aout_FiltersDestroyPipeline( p_aout, p_input->pp_filters,
356 p_input->i_nb_filters );
357 aout_FiltersDestroyPipeline( p_aout, p_input->pp_resamplers,
358 p_input->i_nb_resamplers );
359 aout_FifoDestroy( p_aout, &p_input->fifo );
364 /*****************************************************************************
365 * aout_InputPlay : play a buffer
366 *****************************************************************************
367 * This function must be entered with the input lock.
368 *****************************************************************************/
369 int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
370 aout_buffer_t * p_buffer )
374 if( p_input->b_restart )
376 aout_fifo_t fifo, dummy_fifo;
377 byte_t *p_first_byte_to_mix;
379 vlc_mutex_lock( &p_aout->mixer_lock );
381 /* A little trick to avoid loosing our input fifo */
382 aout_FifoInit( p_aout, &dummy_fifo, p_aout->mixer.mixer.i_rate );
383 p_first_byte_to_mix = p_input->p_first_byte_to_mix;
384 fifo = p_input->fifo;
385 p_input->fifo = dummy_fifo;
386 aout_InputDelete( p_aout, p_input );
387 aout_InputNew( p_aout, p_input );
388 p_input->p_first_byte_to_mix = p_first_byte_to_mix;
389 p_input->fifo = fifo;
391 vlc_mutex_unlock( &p_aout->mixer_lock );
394 /* We don't care if someone changes the start date behind our back after
395 * this. We'll deal with that when pushing the buffer, and compensate
396 * with the next incoming buffer. */
397 vlc_mutex_lock( &p_aout->input_fifos_lock );
398 start_date = aout_FifoNextStart( p_aout, &p_input->fifo );
399 vlc_mutex_unlock( &p_aout->input_fifos_lock );
401 if ( start_date != 0 && start_date < mdate() )
403 /* The decoder is _very_ late. This can only happen if the user
404 * pauses the stream (or if the decoder is buggy, which cannot
406 msg_Warn( p_aout, "computed PTS is out of range ("I64Fd"), "
407 "clearing out", mdate() - start_date );
408 vlc_mutex_lock( &p_aout->input_fifos_lock );
409 aout_FifoSet( p_aout, &p_input->fifo, 0 );
410 p_input->p_first_byte_to_mix = NULL;
411 vlc_mutex_unlock( &p_aout->input_fifos_lock );
412 if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE )
413 msg_Warn( p_aout, "timing screwed, stopping resampling" );
414 p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
415 if ( p_input->i_nb_resamplers != 0 )
417 p_input->pp_resamplers[0]->input.i_rate = p_input->input.i_rate;
418 p_input->pp_resamplers[0]->b_continuity = VLC_FALSE;
423 if ( p_buffer->start_date < mdate() + AOUT_MIN_PREPARE_TIME )
425 /* The decoder gives us f*cked up PTS. It's its business, but we
426 * can't present it anyway, so drop the buffer. */
427 msg_Warn( p_aout, "PTS is out of range ("I64Fd"), dropping buffer",
428 mdate() - p_buffer->start_date );
429 aout_BufferFree( p_buffer );
430 p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
431 if ( p_input->i_nb_resamplers != 0 )
433 p_input->pp_resamplers[0]->input.i_rate = p_input->input.i_rate;
434 p_input->pp_resamplers[0]->b_continuity = VLC_FALSE;
439 /* If the audio drift is too big then it's not worth trying to resample
441 if ( start_date != 0 &&
442 ( start_date < p_buffer->start_date - 3 * AOUT_PTS_TOLERANCE ) )
444 msg_Warn( p_aout, "audio drift is too big ("I64Fd"), clearing out",
445 start_date - p_buffer->start_date );
446 vlc_mutex_lock( &p_aout->input_fifos_lock );
447 aout_FifoSet( p_aout, &p_input->fifo, 0 );
448 p_input->p_first_byte_to_mix = NULL;
449 vlc_mutex_unlock( &p_aout->input_fifos_lock );
450 if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE )
451 msg_Warn( p_aout, "timing screwed, stopping resampling" );
452 p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
453 if ( p_input->i_nb_resamplers != 0 )
455 p_input->pp_resamplers[0]->input.i_rate = p_input->input.i_rate;
456 p_input->pp_resamplers[0]->b_continuity = VLC_FALSE;
460 else if ( start_date != 0 &&
461 ( start_date > p_buffer->start_date + 3 * AOUT_PTS_TOLERANCE ) )
463 msg_Warn( p_aout, "audio drift is too big ("I64Fd"), dropping buffer",
464 start_date - p_buffer->start_date );
465 aout_BufferFree( p_buffer );
469 if ( start_date == 0 ) start_date = p_buffer->start_date;
471 /* Run pre-filters. */
473 aout_FiltersPlay( p_aout, p_input->pp_filters, p_input->i_nb_filters,
476 /* Run the resampler if needed.
477 * We first need to calculate the output rate of this resampler. */
478 if ( ( p_input->i_resampling_type == AOUT_RESAMPLING_NONE ) &&
479 ( start_date < p_buffer->start_date - AOUT_PTS_TOLERANCE
480 || start_date > p_buffer->start_date + AOUT_PTS_TOLERANCE ) &&
481 p_input->i_nb_resamplers > 0 )
483 /* Can happen in several circumstances :
484 * 1. A problem at the input (clock drift)
485 * 2. A small pause triggered by the user
486 * 3. Some delay in the output stage, causing a loss of lip
488 * Solution : resample the buffer to avoid a scratch.
490 mtime_t drift = p_buffer->start_date - start_date;
492 p_input->i_resamp_start_date = mdate();
493 p_input->i_resamp_start_drift = (int)drift;
496 p_input->i_resampling_type = AOUT_RESAMPLING_DOWN;
498 p_input->i_resampling_type = AOUT_RESAMPLING_UP;
500 msg_Warn( p_aout, "buffer is "I64Fd" %s, triggering %ssampling",
501 drift > 0 ? drift : -drift,
502 drift > 0 ? "in advance" : "late",
503 drift > 0 ? "down" : "up");
506 if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE )
508 /* Resampling has been triggered previously (because of dates
509 * mismatch). We want the resampling to happen progressively so
510 * it isn't too audible to the listener. */
512 if( p_input->i_resampling_type == AOUT_RESAMPLING_UP )
514 p_input->pp_resamplers[0]->input.i_rate += 2; /* Hz */
518 p_input->pp_resamplers[0]->input.i_rate -= 2; /* Hz */
521 /* Check if everything is back to normal, in which case we can stop the
523 if( p_input->pp_resamplers[0]->input.i_rate ==
524 p_input->input.i_rate )
526 p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
527 msg_Warn( p_aout, "resampling stopped after "I64Fi" usec "
529 mdate() - p_input->i_resamp_start_date,
530 p_buffer->start_date - start_date);
532 else if( abs( (int)(p_buffer->start_date - start_date) ) <
533 abs( p_input->i_resamp_start_drift ) / 2 )
535 /* if we reduced the drift from half, then it is time to switch
536 * back the resampling direction. */
537 if( p_input->i_resampling_type == AOUT_RESAMPLING_UP )
538 p_input->i_resampling_type = AOUT_RESAMPLING_DOWN;
540 p_input->i_resampling_type = AOUT_RESAMPLING_UP;
541 p_input->i_resamp_start_drift = 0;
543 else if( p_input->i_resamp_start_drift &&
544 ( abs( (int)(p_buffer->start_date - start_date) ) >
545 abs( p_input->i_resamp_start_drift ) * 3 / 2 ) )
547 /* If the drift is increasing and not decreasing, than something
548 * is bad. We'd better stop the resampling right now. */
549 msg_Warn( p_aout, "timing screwed, stopping resampling" );
550 p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
551 p_input->pp_resamplers[0]->input.i_rate = p_input->input.i_rate;
555 /* Adding the start date will be managed by aout_FifoPush(). */
556 p_buffer->end_date = start_date +
557 (p_buffer->end_date - p_buffer->start_date);
558 p_buffer->start_date = start_date;
560 /* Actually run the resampler now. */
561 if ( p_input->i_nb_resamplers > 0 )
563 aout_FiltersPlay( p_aout, p_input->pp_resamplers,
564 p_input->i_nb_resamplers,
568 vlc_mutex_lock( &p_aout->input_fifos_lock );
569 aout_FifoPush( p_aout, &p_input->fifo, p_buffer );
570 vlc_mutex_unlock( &p_aout->input_fifos_lock );
575 static int ChangeFiltersString( aout_instance_t * p_aout,
576 char *psz_name, vlc_bool_t b_add )
581 var_Get( p_aout, "audio-filter", &val );
583 if( !val.psz_string ) val.psz_string = strdup("");
585 psz_parser = strstr( val.psz_string, psz_name );
591 psz_parser = val.psz_string;
592 asprintf( &val.psz_string, (*val.psz_string) ? "%s,%s" : "%s%s",
593 val.psz_string, psz_name );
605 memmove( psz_parser, psz_parser + strlen(psz_name) +
606 (*(psz_parser + strlen(psz_name)) == ',' ? 1 : 0 ),
607 strlen(psz_parser + strlen(psz_name)) + 1 );
611 free( val.psz_string );
616 var_Set( p_aout, "audio-filter", val );
617 free( val.psz_string );
621 static int VisualizationCallback( vlc_object_t *p_this, char const *psz_cmd,
622 vlc_value_t oldval, vlc_value_t newval, void *p_data )
624 aout_instance_t *p_aout = (aout_instance_t *)p_this;
625 char *psz_mode = newval.psz_string;
629 if( !psz_mode || !*psz_mode )
631 ChangeFiltersString( p_aout, "goom", VLC_FALSE );
632 ChangeFiltersString( p_aout, "visual", VLC_FALSE );
633 ChangeFiltersString( p_aout, "galaktos", VLC_FALSE );
637 if( !strcmp( "goom", psz_mode ) )
639 ChangeFiltersString( p_aout, "visual", VLC_FALSE );
640 ChangeFiltersString( p_aout, "goom", VLC_TRUE );
641 ChangeFiltersString( p_aout, "galaktos", VLC_FALSE );
643 else if( !strcmp( "galaktos", psz_mode ) )
645 ChangeFiltersString( p_aout, "visual", VLC_FALSE );
646 ChangeFiltersString( p_aout, "goom", VLC_FALSE );
647 ChangeFiltersString( p_aout, "galaktos", VLC_TRUE );
651 val.psz_string = psz_mode;
652 var_Create( p_aout, "effect-list", VLC_VAR_STRING );
653 var_Set( p_aout, "effect-list", val );
655 ChangeFiltersString( p_aout, "goom", VLC_FALSE );
656 ChangeFiltersString( p_aout, "visual", VLC_TRUE );
657 ChangeFiltersString( p_aout, "galaktos", VLC_FALSE );
662 for( i = 0; i < p_aout->i_nb_inputs; i++ )
664 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
670 static int EqualizerCallback( vlc_object_t *p_this, char const *psz_cmd,
671 vlc_value_t oldval, vlc_value_t newval, void *p_data )
673 aout_instance_t *p_aout = (aout_instance_t *)p_this;
674 char *psz_mode = newval.psz_string;
679 if( !psz_mode || !*psz_mode )
681 i_ret = ChangeFiltersString( p_aout, "equalizer", VLC_FALSE );
685 val.psz_string = psz_mode;
686 var_Create( p_aout, "equalizer-preset", VLC_VAR_STRING );
687 var_Set( p_aout, "equalizer-preset", val );
688 i_ret = ChangeFiltersString( p_aout, "equalizer", VLC_TRUE );
695 for( i = 0; i < p_aout->i_nb_inputs; i++ )
697 p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
704 static aout_filter_t * allocateUserChannelMixer( aout_instance_t * p_aout,
705 audio_sample_format_t * p_input_format,
706 audio_sample_format_t * p_output_format )
708 aout_filter_t * p_channel_mixer;
710 /* Retreive user preferred channel mixer */
711 char * psz_name = config_GetPsz( p_aout, "audio-channel-mixer" );
713 /* Not specified => let the main pipeline do the mixing */
714 if ( ! psz_name ) return NULL;
716 /* Debug information */
717 aout_FormatsPrint( p_aout, "channel mixer", p_input_format,
720 /* Create a VLC object */
721 p_channel_mixer = vlc_object_create( p_aout, sizeof(aout_filter_t) );
722 if( p_channel_mixer == NULL )
724 msg_Err( p_aout, "cannot add user channel mixer %s", psz_name );
727 vlc_object_attach( p_channel_mixer , p_aout );
729 /* Attach the suitable module */
730 memcpy( &p_channel_mixer->input, p_input_format,
731 sizeof(audio_sample_format_t) );
732 memcpy( &p_channel_mixer->output, p_output_format,
733 sizeof(audio_sample_format_t) );
734 p_channel_mixer->p_module =
735 module_Need( p_channel_mixer,"audio filter", psz_name, VLC_TRUE );
736 if( p_channel_mixer->p_module== NULL )
738 msg_Err( p_aout, "cannot add user channel mixer %s", psz_name );
739 vlc_object_detach( p_channel_mixer );
740 vlc_object_destroy( p_channel_mixer );
743 p_channel_mixer->b_continuity = VLC_FALSE;
746 return p_channel_mixer;