]> git.sesse.net Git - vlc/blob - src/audio_output/input.c
sout: remove unused sout_input_t.p_sout
[vlc] / src / audio_output / input.c
1 /*****************************************************************************
2  * input.c : internal management of input streams for the audio output
3  *****************************************************************************
4  * Copyright (C) 2002-2007 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
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 Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc_common.h>
33
34 #include <stdio.h>
35 #include <string.h>
36 #include <assert.h>
37
38 #include <vlc_input.h>
39 #include <vlc_vout.h>                  /* for vout_Request */
40 #include <vlc_modules.h>
41 #include <vlc_aout.h>
42 #include <vlc_filter.h>
43 #include <libvlc.h>
44
45 #include "aout_internal.h"
46
47 static void inputDrop( aout_input_t *, block_t * );
48 static void inputResamplingStop( aout_input_t *p_input );
49
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 * );
54
55 static vout_thread_t *RequestVout( void *,
56                                    vout_thread_t *, video_format_t *, bool );
57
58 /*****************************************************************************
59  * aout_InputNew : allocate a new input and rework the filter pipeline
60  *****************************************************************************/
61 aout_input_t *aout_InputNew (audio_output_t * p_aout,
62                              const audio_sample_format_t *restrict infmt,
63                              const audio_sample_format_t *restrict outfmt,
64                              const aout_request_vout_t *p_request_vout)
65 {
66     aout_input_t *p_input = malloc (sizeof (*p_input));
67     if (unlikely(p_input == NULL))
68         return NULL;
69
70     aout_FormatPrint( p_aout, "input", infmt );
71     p_input->samplerate = infmt->i_rate;
72
73     p_input->i_nb_resamplers = p_input->i_nb_filters = 0;
74
75     /* */
76     if( p_request_vout )
77     {
78         p_input->request_vout = *p_request_vout;
79     }
80     else
81     {
82         p_input->request_vout.pf_request_vout = RequestVout;
83         p_input->request_vout.p_private = p_aout;
84     }
85
86     /* Prepare format structure */
87     audio_sample_format_t chain_input_format = *infmt;
88     audio_sample_format_t chain_output_format = *outfmt;
89
90     chain_output_format.i_rate = infmt->i_rate;
91     aout_FormatPrepare( &chain_output_format );
92
93     /* Now add user filters */
94     var_AddCallback( p_aout, "visual", VisualizationCallback, p_input );
95     var_AddCallback( p_aout, "equalizer", EqualizerCallback, p_input );
96
97     char *psz_filters = var_GetString( p_aout, "audio-filter" );
98     char *psz_visual = var_GetString( p_aout, "audio-visual");
99     char *psz_scaletempo = var_InheritBool( p_aout, "audio-time-stretch" ) ? strdup( "scaletempo" ) : NULL;
100
101     p_input->b_recycle_vout = psz_visual && *psz_visual;
102
103     /* parse user filter lists */
104     char *const ppsz_array[] = { psz_scaletempo, psz_filters, psz_visual };
105     p_input->p_playback_rate_filter = NULL;
106
107     for (unsigned i_visual = 0;
108          i_visual < 3 && AOUT_FMT_LINEAR(&chain_output_format);
109          i_visual++)
110     {
111         char *psz_next = NULL;
112         char *psz_parser = ppsz_array[i_visual];
113
114         if( psz_parser == NULL || !*psz_parser )
115             continue;
116
117         while( psz_parser && *psz_parser )
118         {
119             filter_t * p_filter = NULL;
120
121             if( p_input->i_nb_filters >= AOUT_MAX_FILTERS )
122             {
123                 msg_Dbg( p_aout, "max filters reached (%d)", AOUT_MAX_FILTERS );
124                 break;
125             }
126
127             while( *psz_parser == ' ' && *psz_parser == ':' )
128             {
129                 psz_parser++;
130             }
131             if( ( psz_next = strchr( psz_parser , ':'  ) ) )
132             {
133                 *psz_next++ = '\0';
134             }
135             if( *psz_parser =='\0' )
136             {
137                 break;
138             }
139
140             /* Create a VLC object */
141             p_filter = vlc_custom_create( p_aout, sizeof(*p_filter),
142                                           "audio filter" );
143             if( p_filter == NULL )
144             {
145                 msg_Err( p_aout, "cannot add user filter %s (skipped)",
146                          psz_parser );
147                 psz_parser = psz_next;
148                 continue;
149             }
150             p_filter->p_owner = (filter_owner_sys_t *)p_input;
151
152             /* request format */
153             memcpy( &p_filter->fmt_in.audio, &chain_output_format,
154                     sizeof(audio_sample_format_t) );
155             p_filter->fmt_in.i_codec = chain_output_format.i_format;
156             memcpy( &p_filter->fmt_out.audio, &chain_output_format,
157                     sizeof(audio_sample_format_t) );
158             p_filter->fmt_out.i_codec = chain_output_format.i_format;
159
160             /* try to find the requested filter */
161             if( i_visual == 2 ) /* this can only be a visualization module */
162             {
163                 p_filter->p_module = module_need( p_filter, "visualization2",
164                                                   psz_parser, true );
165             }
166             else /* this can be a audio filter module as well as a visualization module */
167             {
168                 p_filter->p_module = module_need( p_filter, "audio filter",
169                                               psz_parser, true );
170
171                 if ( p_filter->p_module == NULL )
172                 {
173                     /* if the filter requested a special format, retry */
174                     if ( !( AOUT_FMTS_IDENTICAL( &p_filter->fmt_in.audio,
175                                                  &chain_input_format )
176                             && AOUT_FMTS_IDENTICAL( &p_filter->fmt_out.audio,
177                                                     &chain_output_format ) ) )
178                     {
179                         aout_FormatPrepare( &p_filter->fmt_in.audio );
180                         aout_FormatPrepare( &p_filter->fmt_out.audio );
181                         p_filter->p_module = module_need( p_filter,
182                                                           "audio filter",
183                                                           psz_parser, true );
184                     }
185                     /* try visual filters */
186                     else
187                     {
188                         memcpy( &p_filter->fmt_in.audio, &chain_output_format,
189                                 sizeof(audio_sample_format_t) );
190                         memcpy( &p_filter->fmt_out.audio, &chain_output_format,
191                                 sizeof(audio_sample_format_t) );
192                         p_filter->p_module = module_need( p_filter,
193                                                           "visualization2",
194                                                           psz_parser, true );
195                     }
196                 }
197             }
198
199             /* failure */
200             if ( p_filter->p_module == NULL )
201             {
202                 msg_Err( p_aout, "cannot add user filter %s (skipped)",
203                          psz_parser );
204
205                 vlc_object_release( p_filter );
206
207                 psz_parser = psz_next;
208                 continue;
209             }
210
211             /* complete the filter chain if necessary */
212             if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_filters,
213                                              &p_input->i_nb_filters,
214                                              &chain_input_format,
215                                              &p_filter->fmt_in.audio ) < 0 )
216             {
217                 msg_Err( p_aout, "cannot add user filter %s (skipped)",
218                          psz_parser );
219
220                 module_unneed( p_filter, p_filter->p_module );
221                 vlc_object_release( p_filter );
222
223                 psz_parser = psz_next;
224                 continue;
225             }
226
227             /* success */
228             p_input->pp_filters[p_input->i_nb_filters++] = p_filter;
229             memcpy( &chain_input_format, &p_filter->fmt_out.audio,
230                     sizeof( audio_sample_format_t ) );
231
232             if( i_visual == 0 ) /* scaletempo */
233                 p_input->p_playback_rate_filter = p_filter;
234
235             /* next filter if any */
236             psz_parser = psz_next;
237         }
238     }
239     free( psz_visual );
240     free( psz_filters );
241     free( psz_scaletempo );
242
243     /* complete the filter chain if necessary */
244     if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_filters,
245                                      &p_input->i_nb_filters,
246                                      &chain_input_format,
247                                      &chain_output_format ) < 0 )
248     {
249         msg_Err (p_aout, "cannot setup filtering pipeline");
250         goto error;
251     }
252
253     /* Create resamplers. */
254     if (AOUT_FMT_LINEAR(outfmt))
255     {
256         chain_output_format.i_rate = (__MAX(p_input->samplerate,
257                                             outfmt->i_rate)
258                                  * (100 + AOUT_MAX_RESAMPLING)) / 100;
259         if ( chain_output_format.i_rate == outfmt->i_rate )
260         {
261             /* Just in case... */
262             chain_output_format.i_rate++;
263         }
264         if (aout_FiltersCreatePipeline (p_aout, p_input->pp_resamplers,
265                                         &p_input->i_nb_resamplers,
266                                         &chain_output_format, outfmt) < 0)
267         {
268             msg_Err (p_aout, "cannot setup a resampling pipeline");
269             goto error;
270         }
271
272         /* Setup the initial rate of the resampler */
273         p_input->pp_resamplers[0]->fmt_in.audio.i_rate = p_input->samplerate;
274     }
275     p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
276
277     if( ! p_input->p_playback_rate_filter && p_input->i_nb_resamplers > 0 )
278     {
279         p_input->p_playback_rate_filter = p_input->pp_resamplers[0];
280     }
281
282     /* Success */
283     p_input->i_last_input_rate = INPUT_RATE_DEFAULT;
284     p_input->i_buffer_lost = 0;
285     return p_input;
286
287 error:
288     aout_FiltersDestroyPipeline( p_input->pp_filters, p_input->i_nb_filters );
289     aout_FiltersDestroyPipeline( p_input->pp_resamplers,
290                                  p_input->i_nb_resamplers );
291     free (p_input);
292     return NULL;
293 }
294
295 /*****************************************************************************
296  * aout_InputDelete : delete an input
297  *****************************************************************************
298  * This function must be entered with the mixer lock.
299  *****************************************************************************/
300 int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input )
301 {
302     var_DelCallback (p_aout, "equalizer", EqualizerCallback, p_input);
303     var_DelCallback (p_aout, "visual", VisualizationCallback, p_input);
304
305     /* XXX We need to update b_recycle_vout before calling aout_FiltersDestroyPipeline.
306      * FIXME They can be a race condition if audio-visual is updated between
307      * aout_InputDelete and aout_InputNew.
308      */
309     char *psz_visual = var_GetString( p_aout, "audio-visual");
310     p_input->b_recycle_vout = psz_visual && *psz_visual;
311     free( psz_visual );
312
313     aout_FiltersDestroyPipeline( p_input->pp_filters, p_input->i_nb_filters );
314     p_input->i_nb_filters = 0;
315     aout_FiltersDestroyPipeline( p_input->pp_resamplers,
316                                  p_input->i_nb_resamplers );
317     p_input->i_nb_resamplers = 0;
318
319     return 0;
320 }
321
322 /*****************************************************************************
323  * aout_InputPlay : play a buffer
324  *****************************************************************************
325  * This function must be entered with the input lock.
326  *****************************************************************************/
327 block_t *aout_InputPlay(audio_output_t *p_aout, aout_input_t *p_input,
328                         block_t *p_buffer, int i_input_rate, date_t *date )
329 {
330     mtime_t start_date;
331
332     aout_assert_locked( p_aout );
333
334     if( i_input_rate != INPUT_RATE_DEFAULT && p_input->p_playback_rate_filter == NULL )
335     {
336         inputDrop( p_input, p_buffer );
337         return NULL;
338     }
339
340     /* Handle input rate change, but keep drift correction */
341     if( i_input_rate != p_input->i_last_input_rate )
342     {
343         unsigned int * const pi_rate = &p_input->p_playback_rate_filter->fmt_in.audio.i_rate;
344 #define F(r,ir) ( INPUT_RATE_DEFAULT * (r) / (ir) )
345         const int i_delta = *pi_rate - F(p_input->samplerate,p_input->i_last_input_rate);
346         *pi_rate = F(p_input->samplerate + i_delta, i_input_rate);
347 #undef F
348         p_input->i_last_input_rate = i_input_rate;
349     }
350
351     mtime_t now = mdate();
352
353     /* We don't care if someone changes the start date behind our back after
354      * this. We'll deal with that when pushing the buffer, and compensate
355      * with the next incoming buffer. */
356     start_date = date_Get (date);
357
358     if ( start_date != VLC_TS_INVALID && start_date < now )
359     {
360         /* The decoder is _very_ late. This can only happen if the user
361          * pauses the stream (or if the decoder is buggy, which cannot
362          * happen :). */
363         msg_Warn( p_aout, "computed PTS is out of range (%"PRId64"), "
364                   "clearing out", now - start_date );
365         aout_OutputFlush( p_aout, false );
366         if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE )
367             msg_Warn( p_aout, "timing screwed, stopping resampling" );
368         inputResamplingStop( p_input );
369         p_buffer->i_flags |= BLOCK_FLAG_DISCONTINUITY;
370         start_date = VLC_TS_INVALID;
371     }
372
373     if ( p_buffer->i_pts < now + AOUT_MIN_PREPARE_TIME )
374     {
375         /* The decoder gives us f*cked up PTS. It's its business, but we
376          * can't present it anyway, so drop the buffer. */
377         msg_Warn( p_aout, "PTS is out of range (%"PRId64"), dropping buffer",
378                   now - p_buffer->i_pts );
379         inputDrop( p_input, p_buffer );
380         inputResamplingStop( p_input );
381         return NULL;
382     }
383
384     /* If the audio drift is too big then it's not worth trying to resample
385      * the audio. */
386     if( start_date == VLC_TS_INVALID )
387     {
388         start_date = p_buffer->i_pts;
389         date_Set (date, start_date);
390     }
391
392     mtime_t drift = start_date - p_buffer->i_pts;
393
394     if( drift < -i_input_rate * 3 * AOUT_MAX_PTS_ADVANCE / INPUT_RATE_DEFAULT )
395     {
396         msg_Warn( p_aout, "buffer way too early (%"PRId64"), clearing queue",
397                   drift );
398         aout_OutputFlush( p_aout, false );
399         if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE )
400             msg_Warn( p_aout, "timing screwed, stopping resampling" );
401         inputResamplingStop( p_input );
402         p_buffer->i_flags |= BLOCK_FLAG_DISCONTINUITY;
403         start_date = p_buffer->i_pts;
404         date_Set (date, start_date);
405         drift = 0;
406     }
407     else
408     if( drift > +i_input_rate * 3 * AOUT_MAX_PTS_DELAY / INPUT_RATE_DEFAULT )
409     {
410         msg_Warn( p_aout, "buffer way too late (%"PRId64"), dropping buffer",
411                   drift );
412         inputDrop( p_input, p_buffer );
413         return NULL;
414     }
415
416     /* Run pre-filters. */
417     aout_FiltersPlay( p_input->pp_filters, p_input->i_nb_filters, &p_buffer );
418     if( !p_buffer )
419         return NULL;
420
421     /* Run the resampler if needed.
422      * We first need to calculate the output rate of this resampler. */
423     if ( ( p_input->i_resampling_type == AOUT_RESAMPLING_NONE ) &&
424          ( drift < -AOUT_MAX_PTS_ADVANCE || drift > +AOUT_MAX_PTS_DELAY ) &&
425          p_input->i_nb_resamplers > 0 )
426     {
427         /* Can happen in several circumstances :
428          * 1. A problem at the input (clock drift)
429          * 2. A small pause triggered by the user
430          * 3. Some delay in the output stage, causing a loss of lip
431          *    synchronization
432          * Solution : resample the buffer to avoid a scratch.
433          */
434         p_input->i_resamp_start_date = now;
435         p_input->i_resamp_start_drift = (int)-drift;
436         p_input->i_resampling_type = (drift < 0) ? AOUT_RESAMPLING_DOWN
437                                                  : AOUT_RESAMPLING_UP;
438         msg_Warn( p_aout, (drift < 0)
439                   ? "buffer too early (%"PRId64"), down-sampling"
440                   : "buffer too late  (%"PRId64"), up-sampling", drift );
441     }
442
443     if ( p_input->i_resampling_type != AOUT_RESAMPLING_NONE )
444     {
445         /* Resampling has been triggered previously (because of dates
446          * mismatch). We want the resampling to happen progressively so
447          * it isn't too audible to the listener. */
448
449         if( p_input->i_resampling_type == AOUT_RESAMPLING_UP )
450             p_input->pp_resamplers[0]->fmt_in.audio.i_rate += 2; /* Hz */
451         else
452             p_input->pp_resamplers[0]->fmt_in.audio.i_rate -= 2; /* Hz */
453
454         /* Check if everything is back to normal, in which case we can stop the
455          * resampling */
456         unsigned int i_nominal_rate =
457           (p_input->pp_resamplers[0] == p_input->p_playback_rate_filter)
458           ? INPUT_RATE_DEFAULT * p_input->samplerate / i_input_rate
459           : p_input->samplerate;
460         if( p_input->pp_resamplers[0]->fmt_in.audio.i_rate == i_nominal_rate )
461         {
462             p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
463             msg_Warn( p_aout, "resampling stopped after %"PRIi64" usec "
464                       "(drift: %"PRIi64")",
465                       now - p_input->i_resamp_start_date,
466                       p_buffer->i_pts - start_date);
467         }
468         else if( abs( (int)(p_buffer->i_pts - start_date) ) <
469                  abs( p_input->i_resamp_start_drift ) / 2 )
470         {
471             /* if we reduced the drift from half, then it is time to switch
472              * back the resampling direction. */
473             if( p_input->i_resampling_type == AOUT_RESAMPLING_UP )
474                 p_input->i_resampling_type = AOUT_RESAMPLING_DOWN;
475             else
476                 p_input->i_resampling_type = AOUT_RESAMPLING_UP;
477             p_input->i_resamp_start_drift = 0;
478         }
479         else if( p_input->i_resamp_start_drift &&
480                  ( abs( (int)(p_buffer->i_pts - start_date) ) >
481                    abs( p_input->i_resamp_start_drift ) * 3 / 2 ) )
482         {
483             /* If the drift is increasing and not decreasing, than something
484              * is bad. We'd better stop the resampling right now. */
485             msg_Warn( p_aout, "timing screwed, stopping resampling" );
486             inputResamplingStop( p_input );
487             p_buffer->i_flags |= BLOCK_FLAG_DISCONTINUITY;
488         }
489     }
490
491     /* Actually run the resampler now. */
492     if ( p_input->i_nb_resamplers > 0 )
493     {
494         aout_FiltersPlay( p_input->pp_resamplers, p_input->i_nb_resamplers,
495                           &p_buffer );
496     }
497
498     if( !p_buffer )
499         return NULL;
500     if( p_buffer->i_nb_samples <= 0 )
501     {
502         block_Release( p_buffer );
503         return NULL;
504     }
505
506     p_buffer->i_pts = start_date;
507     return p_buffer;
508 }
509
510 /*****************************************************************************
511  * static functions
512  *****************************************************************************/
513
514 static void inputDrop( aout_input_t *p_input, block_t *p_buffer )
515 {
516     block_Release( p_buffer );
517
518     p_input->i_buffer_lost++;
519 }
520
521 static void inputResamplingStop( aout_input_t *p_input )
522 {
523     p_input->i_resampling_type = AOUT_RESAMPLING_NONE;
524     if( p_input->i_nb_resamplers != 0 )
525     {
526         p_input->pp_resamplers[0]->fmt_in.audio.i_rate =
527             ( p_input->pp_resamplers[0] == p_input->p_playback_rate_filter )
528             ? INPUT_RATE_DEFAULT * p_input->samplerate / p_input->i_last_input_rate
529             : p_input->samplerate;
530     }
531 }
532
533 static vout_thread_t *RequestVout( void *p_private,
534                                    vout_thread_t *p_vout, video_format_t *p_fmt, bool b_recycle )
535 {
536     audio_output_t *p_aout = p_private;
537     VLC_UNUSED(b_recycle);
538     vout_configuration_t cfg = {
539         .vout       = p_vout,
540         .input      = NULL,
541         .change_fmt = true,
542         .fmt        = p_fmt,
543         .dpb_size   = 1,
544     };
545     return vout_Request( p_aout, &cfg );
546 }
547
548 vout_thread_t *aout_filter_RequestVout( filter_t *p_filter,
549                                         vout_thread_t *p_vout, video_format_t *p_fmt )
550 {
551     aout_input_t *p_input = (aout_input_t *)p_filter->p_owner;
552     aout_request_vout_t *p_request = &p_input->request_vout;
553
554     /* XXX: this only works from audio input */
555     /* If you want to use visualization filters from another place, you will
556      * need to add a new pf_aout_request_vout callback or store a pointer
557      * to aout_request_vout_t inside filter_t (i.e. a level of indirection). */
558
559     return p_request->pf_request_vout( p_request->p_private,
560                                        p_vout, p_fmt, p_input->b_recycle_vout );
561 }
562
563 static inline bool ChangeFiltersString (vlc_object_t *aout, const char *var,
564                                         const char *filter, bool add)
565 {
566     return aout_ChangeFilterString (aout, aout, var, filter, add);
567 }
568
569 static int VisualizationCallback (vlc_object_t *obj, char const *var,
570                                   vlc_value_t oldval, vlc_value_t newval,
571                                   void *data)
572 {
573     const char *mode = newval.psz_string;
574     //aout_input_t *input = data;
575     (void) data;
576
577     if (!*mode)
578     {
579         ChangeFiltersString (obj, "audio-visual", "goom", false);
580         ChangeFiltersString (obj, "audio-visual", "visual", false);
581         ChangeFiltersString (obj, "audio-visual", "projectm", false);
582         ChangeFiltersString (obj, "audio-visual", "vsxu", false);
583     }
584     else if (!strcmp ("goom", mode))
585     {
586         ChangeFiltersString (obj, "audio-visual", "visual", false );
587         ChangeFiltersString (obj, "audio-visual", "goom", true );
588         ChangeFiltersString (obj, "audio-visual", "projectm", false );
589         ChangeFiltersString (obj, "audio-visual", "vsxu", false);
590     }
591     else if (!strcmp ("projectm", mode))
592     {
593         ChangeFiltersString (obj, "audio-visual", "visual", false);
594         ChangeFiltersString (obj, "audio-visual", "goom", false);
595         ChangeFiltersString (obj, "audio-visual", "projectm", true);
596         ChangeFiltersString (obj, "audio-visual", "vsxu", false);
597     }
598     else if (!strcmp ("vsxu", mode))
599     {
600         ChangeFiltersString (obj, "audio-visual", "visual", false);
601         ChangeFiltersString (obj, "audio-visual", "goom", false);
602         ChangeFiltersString (obj, "audio-visual", "projectm", false);
603         ChangeFiltersString (obj, "audio-visual", "vsxu", true);
604     }
605     else
606     {
607         var_Create (obj, "effect-list", VLC_VAR_STRING);
608         var_SetString (obj, "effect-list", mode);
609
610         ChangeFiltersString (obj, "audio-visual", "goom", false);
611         ChangeFiltersString (obj, "audio-visual", "visual", true);
612         ChangeFiltersString (obj, "audio-visual", "projectm", false);
613     }
614
615     /* That sucks FIXME: use "input" instead of cast */
616     aout_InputRequestRestart ((audio_output_t *)obj);
617
618     (void) var; (void) oldval;
619     return VLC_SUCCESS;
620 }
621
622 static int EqualizerCallback (vlc_object_t *obj, char const *cmd,
623                               vlc_value_t oldval, vlc_value_t newval,
624                               void *data)
625 {
626     char *mode = newval.psz_string;
627     //aout_input_t *input = data;
628     bool ret;
629
630     (void) data;
631     (void) cmd; (void) oldval;
632     if (!*mode)
633         ret = ChangeFiltersString (obj, "audio-filter", "equalizer", false);
634     else
635     {
636         var_Create (obj, "equalizer-preset", VLC_VAR_STRING);
637         var_SetString (obj, "equalizer-preset", mode);
638         ret = ChangeFiltersString (obj, "audio-filter", "equalizer", true);
639     }
640
641     /* That sucks */
642     if (ret)
643         aout_InputRequestRestart ((audio_output_t *)obj);
644     return VLC_SUCCESS;
645 }