]> git.sesse.net Git - vlc/blob - src/input/var.c
* src/input/input.c:
[vlc] / src / input / var.c
1 /*****************************************************************************
2  * var.c: object variables for input thread
3  *****************************************************************************
4  * Copyright (C) 2004 VideoLAN
5  * $Id: input.c 7955 2004-06-07 22:21:33Z fenrir $
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *
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.
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 General Public License for more details.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>
28 #include <vlc/vlc.h>
29 #include <vlc/input.h>
30
31 #include "input_internal.h"
32
33 /*****************************************************************************
34  * Exported prototypes
35  *****************************************************************************/
36 void input_ControlVarInit ( input_thread_t * );
37 void input_ControlVarClean( input_thread_t * );
38 void input_ControlVarNavigation( input_thread_t * );
39 void input_ControlVarTitle( input_thread_t *p_input, int i_title );
40
41 void input_ConfigVarInit ( input_thread_t *p_input );
42
43
44 /*****************************************************************************
45  * Callbacks
46  *****************************************************************************/
47 static int StateCallback   ( vlc_object_t *p_this, char const *psz_cmd,
48                              vlc_value_t oldval, vlc_value_t newval, void * );
49 static int RateCallback    ( vlc_object_t *p_this, char const *psz_cmd,
50                              vlc_value_t oldval, vlc_value_t newval, void * );
51 static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
52                              vlc_value_t oldval, vlc_value_t newval, void * );
53 static int TimeCallback    ( vlc_object_t *p_this, char const *psz_cmd,
54                              vlc_value_t oldval, vlc_value_t newval, void * );
55 static int ProgramCallback ( vlc_object_t *p_this, char const *psz_cmd,
56                              vlc_value_t oldval, vlc_value_t newval, void * );
57 static int TitleCallback   ( vlc_object_t *p_this, char const *psz_cmd,
58                              vlc_value_t oldval, vlc_value_t newval, void * );
59 static int SeekpointCallback( vlc_object_t *p_this, char const *psz_cmd,
60                              vlc_value_t oldval, vlc_value_t newval, void * );
61 static int NavigationCallback( vlc_object_t *p_this, char const *psz_cmd,
62                              vlc_value_t oldval, vlc_value_t newval, void * );
63 static int ESCallback      ( vlc_object_t *p_this, char const *psz_cmd,
64                              vlc_value_t oldval, vlc_value_t newval, void * );
65 static int EsDelayCallback ( vlc_object_t *p_this, char const *psz_cmd,
66                              vlc_value_t oldval, vlc_value_t newval, void * );
67
68 static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
69                              vlc_value_t oldval, vlc_value_t newval, void * );
70
71 /*****************************************************************************
72  * input_ControlVarInit:
73  *  Create all control object variables with their callbacks
74  *****************************************************************************/
75 void input_ControlVarInit ( input_thread_t *p_input )
76 {
77     vlc_value_t val, text;
78
79     /* State */
80     var_Create( p_input, "state", VLC_VAR_INTEGER );
81     val.i_int = p_input->i_state;
82     var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
83     var_AddCallback( p_input, "state", StateCallback, NULL );
84
85     /* Rate */
86     var_Create( p_input, "rate", VLC_VAR_INTEGER );
87     val.i_int = p_input->i_rate;
88     var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
89     var_AddCallback( p_input, "rate", RateCallback, NULL );
90
91     var_Create( p_input, "rate-slower", VLC_VAR_VOID );
92     var_AddCallback( p_input, "rate-slower", RateCallback, NULL );
93
94     var_Create( p_input, "rate-faster", VLC_VAR_VOID );
95     var_AddCallback( p_input, "rate-faster", RateCallback, NULL );
96
97
98     /* Position */
99     var_Create( p_input, "position",  VLC_VAR_FLOAT );
100     var_Create( p_input, "position-offset",  VLC_VAR_FLOAT );
101     val.f_float = 0.0;
102     var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
103     var_AddCallback( p_input, "position", PositionCallback, NULL );
104     var_AddCallback( p_input, "position-offset", PositionCallback, NULL );
105
106     /* Time */
107     var_Create( p_input, "time",  VLC_VAR_TIME );
108     var_Create( p_input, "time-offset",  VLC_VAR_TIME );    /* relative */
109     val.i_time = 0;
110     var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
111     var_AddCallback( p_input, "time", TimeCallback, NULL );
112     var_AddCallback( p_input, "time-offset", TimeCallback, NULL );
113
114
115     /* Bookmark */
116     var_Create( p_input, "bookmark", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE |
117                 VLC_VAR_ISCOMMAND );
118     val.psz_string = _("Bookmark");
119     var_Change( p_input, "bookmark", VLC_VAR_SETTEXT, &val, NULL );
120     var_AddCallback( p_input, "bookmark", BookmarkCallback, NULL );
121
122
123     /* Program */
124     var_Create( p_input, "program", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE |
125                 VLC_VAR_DOINHERIT );
126     var_Get( p_input, "program", &val );
127     if( val.i_int <= 0 )
128         var_Change( p_input, "program", VLC_VAR_DELCHOICE, &val, NULL );
129     text.psz_string = _("Program");
130     var_Change( p_input, "program", VLC_VAR_SETTEXT, &text, NULL );
131     var_AddCallback( p_input, "program", ProgramCallback, NULL );
132
133     /* Title */
134     var_Create( p_input, "title", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
135     text.psz_string = _("Title");
136     var_Change( p_input, "title", VLC_VAR_SETTEXT, &text, NULL );
137     var_AddCallback( p_input, "title", TitleCallback, NULL );
138
139     /* Chapter */
140     var_Create( p_input, "chapter", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
141     text.psz_string = _("Chapter");
142     var_Change( p_input, "chapter", VLC_VAR_SETTEXT, &text, NULL );
143     var_AddCallback( p_input, "chapter", SeekpointCallback, NULL );
144
145     /* Navigation The callback is added after */
146     var_Create( p_input, "navigation", VLC_VAR_VARIABLE | VLC_VAR_HASCHOICE );
147     text.psz_string = _("Navigation");
148     var_Change( p_input, "navigation", VLC_VAR_SETTEXT, &text, NULL );
149
150     /* Delay */
151     var_Create( p_input, "audio-delay", VLC_VAR_TIME );
152     val.i_time = 0;
153     var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
154     var_AddCallback( p_input, "audio-delay", EsDelayCallback, NULL );
155     var_Create( p_input, "spu-delay", VLC_VAR_TIME );
156     val.i_time = 0;
157     var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
158     var_AddCallback( p_input, "spu-delay", EsDelayCallback, NULL );
159
160
161     /* Video ES */
162     var_Create( p_input, "video-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
163     text.psz_string = _("Video Track");
164     var_Change( p_input, "video-es", VLC_VAR_SETTEXT, &text, NULL );
165     var_AddCallback( p_input, "video-es", ESCallback, NULL );
166
167     /* Audio ES */
168     var_Create( p_input, "audio-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
169     text.psz_string = _("Audio Track");
170     var_Change( p_input, "audio-es", VLC_VAR_SETTEXT, &text, NULL );
171     var_AddCallback( p_input, "audio-es", ESCallback, NULL );
172
173     /* Spu ES */
174     var_Create( p_input, "spu-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
175     text.psz_string = _("Subtitles Track");
176     var_Change( p_input, "spu-es", VLC_VAR_SETTEXT, &text, NULL );
177     var_AddCallback( p_input, "spu-es", ESCallback, NULL );
178
179
180     /* Special read only objects variables for intf */
181     var_Create( p_input, "bookmarks", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
182
183     var_Create( p_input, "length",  VLC_VAR_TIME );
184     val.i_time = 0;
185     var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
186
187
188
189    /* Special "intf-change" variable, it allows intf to set up a callback
190      * to be notified of some changes.
191      * TODO list all changes warn by this callbacks */
192     var_Create( p_input, "intf-change", VLC_VAR_BOOL );
193     var_SetBool( p_input, "intf-change", VLC_TRUE );
194 }
195
196 /*****************************************************************************
197  * input_ControlVarClean:
198  *****************************************************************************/
199 void input_ControlVarClean( input_thread_t *p_input )
200 {
201     var_Destroy( p_input, "state" );
202     var_Destroy( p_input, "rate" );
203     var_Destroy( p_input, "rate-slower" );
204     var_Destroy( p_input, "rate-faster" );
205     var_Destroy( p_input, "position" );
206     var_Destroy( p_input, "position-offset" );
207     var_Destroy( p_input, "time" );
208     var_Destroy( p_input, "time-offset" );
209
210     var_Destroy( p_input, "audio-delay" );
211     var_Destroy( p_input, "spu-delay" );
212
213     var_Destroy( p_input, "bookmark" );
214
215     var_Destroy( p_input, "program" );
216     if( p_input->i_title > 1 )
217     {
218         /* TODO Destroy sub navigation var ? */
219
220         var_Destroy( p_input, "next-title" );
221         var_Destroy( p_input, "prev-title" );
222     }
223     if( p_input->i_title > 0 )
224     {
225         /* FIXME title > 0 doesn't mean current title has more than 1 seekpoint */
226         var_Destroy( p_input, "next-chapter" );
227         var_Destroy( p_input, "prev-chapter" );
228     }
229     var_Destroy( p_input, "title" );
230     var_Destroy( p_input, "chapter" );
231     var_Destroy( p_input, "navigation" );
232
233     var_Destroy( p_input, "video-es" );
234     var_Destroy( p_input, "audio-es" );
235     var_Destroy( p_input, "spu-es" );
236
237     var_Destroy( p_input, "bookmarks" );
238     var_Destroy( p_input, "length" );
239
240     var_Destroy( p_input, "intf-change" );
241  }
242
243 /*****************************************************************************
244  * input_ControlVarNavigation:
245  *  Create all remaining control object variables
246  *****************************************************************************/
247 void input_ControlVarNavigation( input_thread_t *p_input )
248 {
249     vlc_value_t val, text;
250     int  i;
251
252     /* Create more command variables */
253     if( p_input->i_title > 1 )
254     {
255         var_Create( p_input, "next-title", VLC_VAR_VOID );
256         text.psz_string = _("Next title");
257         var_Change( p_input, "next-title", VLC_VAR_SETTEXT, &text, NULL );
258         var_AddCallback( p_input, "next-title", TitleCallback, NULL );
259
260         var_Create( p_input, "prev-title", VLC_VAR_VOID );
261         text.psz_string = _("Previous title");
262         var_Change( p_input, "prev-title", VLC_VAR_SETTEXT, &text, NULL );
263         var_AddCallback( p_input, "prev-title", TitleCallback, NULL );
264     }
265
266     /* Create title and navigation */
267     val.psz_string = malloc( sizeof("title ") + 5 );
268     for( i = 0; i < p_input->i_title; i++ )
269     {
270         vlc_value_t val2, text, text2;
271         int j;
272
273         /* Add Navigation entries */
274         sprintf( val.psz_string,  "title %2i", i );
275         var_Destroy( p_input, val.psz_string );
276         var_Create( p_input, val.psz_string,
277                     VLC_VAR_INTEGER|VLC_VAR_HASCHOICE|VLC_VAR_ISCOMMAND );
278         var_AddCallback( p_input, val.psz_string,
279                          NavigationCallback, (void *)i );
280
281         if( p_input->title[i]->psz_name == NULL ||
282             *p_input->title[i]->psz_name == '\0' )
283         {
284             text.psz_string = malloc( strlen( _("Title %i") ) + 20 );
285             sprintf( text.psz_string, _("Title %i"), i );
286         }
287         else
288         {
289             text.psz_string = strdup( p_input->title[i]->psz_name );
290         }
291         var_Change( p_input, "navigation", VLC_VAR_ADDCHOICE, &val, &text );
292
293         /* Add title choice */
294         val2.i_int = i;
295         var_Change( p_input, "title", VLC_VAR_ADDCHOICE, &val2, &text );
296
297         free( text.psz_string );
298
299         for( j = 0; j < p_input->title[i]->i_seekpoint; j++ )
300         {
301             val2.i_int = j;
302
303             if( p_input->title[i]->seekpoint[j]->psz_name == NULL ||
304                 *p_input->title[i]->seekpoint[j]->psz_name == '\0' )
305             {
306                 /* Default value */
307                 text2.psz_string = malloc( strlen( _("Chapter %i") ) + 20 );
308                 sprintf( text2.psz_string, _("Chapter %i"), j );
309             }
310             else
311             {
312                 text2.psz_string =
313                     strdup( p_input->title[i]->seekpoint[j]->psz_name );
314             }
315
316             var_Change( p_input, val.psz_string, VLC_VAR_ADDCHOICE,
317                         &val2, &text2 );
318             if( text2.psz_string ) free( text2.psz_string );
319         }
320
321     }
322     free( val.psz_string );
323 }
324
325 /*****************************************************************************
326  * input_ControlVarTitle:
327  *  Create all variables for a title
328  *****************************************************************************/
329 void input_ControlVarTitle( input_thread_t *p_input, int i_title )
330 {
331     input_title_t *t = p_input->title[i_title];
332     vlc_value_t val;
333     int  i;
334
335     /* Create/Destroy command variables */
336     if( t->i_seekpoint > 1 )
337     {
338         vlc_value_t text;
339
340         var_Create( p_input, "next-chapter", VLC_VAR_VOID );
341         text.psz_string = _("Next chapter");
342         var_Change( p_input, "next-chapter", VLC_VAR_SETTEXT, &text, NULL );
343         var_AddCallback( p_input, "next-chapter", SeekpointCallback, NULL );
344
345         var_Create( p_input, "prev-chapter", VLC_VAR_VOID );
346         text.psz_string = _("Previous chapter");
347         var_Change( p_input, "prev-chapter", VLC_VAR_SETTEXT, &text, NULL );
348         var_AddCallback( p_input, "prev-chapter", SeekpointCallback, NULL );
349     }
350     else
351     {
352         var_Destroy( p_input, "next-chapter" );
353         var_Destroy( p_input, "prev-chapter" );
354     }
355
356     /* Build chapter list */
357     var_Change( p_input, "chapter", VLC_VAR_CLEARCHOICES, NULL, NULL );
358     for( i = 0; i <  t->i_seekpoint; i++ )
359     {
360         vlc_value_t text;
361         val.i_int = i;
362
363         if( t->seekpoint[i]->psz_name == NULL ||
364             *t->seekpoint[i]->psz_name == '\0' )
365         {
366             /* Default value */
367             text.psz_string = malloc( strlen( _("Chapter %i") ) + 20 );
368             sprintf( text.psz_string, _("Chapter %i"), i );
369         }
370         else
371         {
372             text.psz_string = strdup( t->seekpoint[i]->psz_name );
373         }
374
375         var_Change( p_input, "chapter", VLC_VAR_ADDCHOICE, &val, &text );
376         if( text.psz_string ) free( text.psz_string );
377     }
378 }
379
380
381 /*****************************************************************************
382  * input_ConfigVarInit:
383  *  Create all config object variables
384  *****************************************************************************/
385 void input_ConfigVarInit ( input_thread_t *p_input )
386 {
387     vlc_value_t val;
388
389     /* Create Object Variables for private use only */
390     var_Create( p_input, "video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
391     var_Create( p_input, "audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
392
393     var_Create( p_input, "audio-channel", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
394     var_Create( p_input, "spu-channel", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
395
396     var_Create( p_input, "sub-file", VLC_VAR_FILE | VLC_VAR_DOINHERIT );
397     var_Create( p_input, "sub-autodetect-file", VLC_VAR_BOOL |
398                 VLC_VAR_DOINHERIT );
399     var_Create( p_input, "sub-autodetect-path", VLC_VAR_STRING |
400                 VLC_VAR_DOINHERIT );
401     var_Create( p_input, "sub-autodetect-fuzzy", VLC_VAR_INTEGER |
402                 VLC_VAR_DOINHERIT );
403
404     var_Create( p_input, "sout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
405     var_Create( p_input, "sout-all",   VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
406     var_Create( p_input, "sout-audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
407     var_Create( p_input, "sout-video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
408     var_Create( p_input, "sout-keep",  VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
409
410     var_Create( p_input, "input-repeat", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
411
412     var_Create( p_input, "start-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
413     var_Create( p_input, "stop-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
414
415     var_Create( p_input, "minimize-threads", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
416
417     var_Create( p_input, "demuxed-id3", VLC_VAR_BOOL ); /* FIXME beurk */
418     val.b_bool = VLC_FALSE;
419     var_Change( p_input, "demuxed-id3", VLC_VAR_SETVALUE, &val, NULL );
420
421     var_Create( p_input, "audio-desync", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
422
423     var_Create( p_input, "cr-average", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
424
425     var_Create( p_input, "seekable", VLC_VAR_BOOL );
426     val.b_bool = VLC_TRUE; /* Fixed later*/
427     var_Change( p_input, "seekable", VLC_VAR_SETVALUE, &val, NULL );
428
429 }
430
431 /*****************************************************************************
432  * All Callbacks:
433  *****************************************************************************/
434 static int StateCallback( vlc_object_t *p_this, char const *psz_cmd,
435                           vlc_value_t oldval, vlc_value_t newval,
436                           void *p_data )
437 {
438     input_thread_t *p_input = (input_thread_t*)p_this;
439
440
441     if( newval.i_int == PLAYING_S || newval.i_int == PAUSE_S )
442     {
443         input_ControlPush( p_input, INPUT_CONTROL_SET_STATE, &newval );
444         return VLC_SUCCESS;
445     }
446
447     return VLC_EGENERIC;
448 }
449 static int RateCallback( vlc_object_t *p_this, char const *psz_cmd,
450                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
451 {
452     input_thread_t *p_input = (input_thread_t*)p_this;
453     vlc_value_t val;
454     int i_rate;
455
456     /* Problem with this way: the "rate" variable is update after the input thread do the change */
457     if( !strcmp( psz_cmd, "rate-slower" ) )
458     {
459         input_ControlPush( p_input, INPUT_CONTROL_SET_RATE_SLOWER, NULL );
460
461         /* Fix "rate" value */
462         i_rate = var_GetInteger( p_input, "rate" ) * 2;
463         if( i_rate < INPUT_RATE_MIN ) i_rate = INPUT_RATE_MIN;
464         val.i_int = i_rate;
465         var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
466     }
467     else if( !strcmp( psz_cmd, "rate-faster" ) )
468     {
469         input_ControlPush( p_input, INPUT_CONTROL_SET_RATE_FASTER, NULL );
470         i_rate = var_GetInteger( p_input, "rate" ) / 2;
471
472         if( i_rate > INPUT_RATE_MAX ) i_rate = INPUT_RATE_MAX;
473         val.i_int = i_rate;
474         var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
475     }
476     else
477     {
478         input_ControlPush( p_input, INPUT_CONTROL_SET_RATE, &newval );
479     }
480
481     return VLC_SUCCESS;
482 }
483
484 static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
485                              vlc_value_t oldval, vlc_value_t newval,
486                              void *p_data )
487 {
488     input_thread_t *p_input = (input_thread_t*)p_this;
489     vlc_value_t val, length;
490
491     if( !strcmp( psz_cmd, "position-offset" ) )
492     {
493         input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION_OFFSET, &newval );
494
495         val.f_float = var_GetFloat( p_input, "position" ) + newval.f_float;
496         if( val.f_float < 0.0 ) val.f_float = 0.0;
497         if( val.f_float > 1.0 ) val.f_float = 1.0;
498         var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
499     }
500     else
501     {
502         val.f_float = newval.f_float;
503         input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &newval );
504     }
505
506     /* Update "position" for better intf behavour */
507     var_Get( p_input, "length", &length );
508     if( length.i_time > 0 && val.f_float >= 0.0 && val.f_float <= 1.0 )
509     {
510         val.i_time = length.i_time * val.f_float;
511         var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
512     }
513
514     return VLC_SUCCESS;
515 }
516
517
518 static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
519                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
520 {
521     input_thread_t *p_input = (input_thread_t*)p_this;
522     vlc_value_t val, length;
523
524     if( !strcmp( psz_cmd, "time-offset" ) )
525     {
526         input_ControlPush( p_input, INPUT_CONTROL_SET_TIME_OFFSET, &newval );
527
528         val.i_time = var_GetTime( p_input, "time" ) + newval.i_time;
529         if( val.i_time < 0 ) val.i_time = 0;
530         /* TODO maybe test against i_length ? */
531         var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
532     }
533     else
534     {
535         val.i_time = newval.i_time;
536         input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval );
537     }
538
539     /* Update "position" for better intf behavour */
540     var_Get( p_input, "length", &length );
541     if( length.i_time > 0 && val.i_time >= 0 && val.i_time <= length.i_time )
542     {
543         val.f_float = (double)val.i_time/(double)length.i_time;
544         var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
545     }
546
547     return VLC_SUCCESS;
548 }
549
550 static int ProgramCallback( vlc_object_t *p_this, char const *psz_cmd,
551                             vlc_value_t oldval, vlc_value_t newval,
552                             void *p_data )
553 {
554     input_thread_t *p_input = (input_thread_t*)p_this;
555
556     input_ControlPush( p_input, INPUT_CONTROL_SET_PROGRAM, &newval );
557
558     return VLC_SUCCESS;
559 }
560
561 static int TitleCallback( vlc_object_t *p_this, char const *psz_cmd,
562                           vlc_value_t oldval, vlc_value_t newval,
563                           void *p_data )
564 {
565     input_thread_t *p_input = (input_thread_t*)p_this;
566     vlc_value_t val, count;
567
568     if( !strcmp( psz_cmd, "next-title" ) )
569     {
570         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE_NEXT, NULL );
571
572         val.i_int = var_GetInteger( p_input, "title" ) + 1;
573         var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &count, NULL );
574         if( val.i_int < count.i_int )
575             var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
576     }
577     else if( !strcmp( psz_cmd, "prev-title" ) )
578     {
579         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE_PREV, NULL );
580
581         val.i_int = var_GetInteger( p_input, "title" ) - 1;
582         if( val.i_int >= 0 )
583             var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
584     }
585     else
586     {
587         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &newval );
588     }
589
590     return VLC_SUCCESS;
591 }
592
593 static int SeekpointCallback( vlc_object_t *p_this, char const *psz_cmd,
594                               vlc_value_t oldval, vlc_value_t newval,
595                               void *p_data )
596 {
597     input_thread_t *p_input = (input_thread_t*)p_this;
598     vlc_value_t val, count;
599
600     if( !strcmp( psz_cmd, "next-chapter" ) )
601     {
602         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT_NEXT, NULL );
603
604         val.i_int = var_GetInteger( p_input, "chapter" ) + 1;
605         var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &count, NULL );
606         if( val.i_int < count.i_int )
607             var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
608     }
609     else if( !strcmp( psz_cmd, "prev-chapter" ) )
610     {
611         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT_PREV, NULL );
612
613         val.i_int = var_GetInteger( p_input, "chapter" ) - 1;
614         if( val.i_int >= 0 )
615             var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
616     }
617     else
618     {
619         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &newval );
620     }
621
622     return VLC_SUCCESS;
623 }
624
625 static int NavigationCallback( vlc_object_t *p_this, char const *psz_cmd,
626                                vlc_value_t oldval, vlc_value_t newval,
627                                void *p_data )
628 {
629     input_thread_t *p_input = (input_thread_t*)p_this;
630     vlc_value_t     val;
631
632     /* Issue a title change */
633     val.i_int = (int)p_data;
634     input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
635
636     var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
637
638     /* And a chapter change */
639     input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &newval );
640
641     var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &newval, NULL );
642
643     return VLC_SUCCESS;
644 }
645
646 static int ESCallback( vlc_object_t *p_this, char const *psz_cmd,
647                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
648 {
649     input_thread_t *p_input = (input_thread_t*)p_this;
650
651     if( newval.i_int < 0 )
652     {
653         vlc_value_t v;
654         /* Hack */
655         if( !strcmp( psz_cmd, "audio-es" ) )
656             v.i_int = -AUDIO_ES;
657         else if( !strcmp( psz_cmd, "video-es" ) )
658             v.i_int = -VIDEO_ES;
659         else if( !strcmp( psz_cmd, "spu-es" ) )
660             v.i_int = -SPU_ES;
661         else
662             v.i_int = 0;
663         if( v.i_int != 0 )
664             input_ControlPush( p_input, INPUT_CONTROL_SET_ES, &v );
665     }
666     else
667     {
668         input_ControlPush( p_input, INPUT_CONTROL_SET_ES, &newval );
669     }
670
671     return VLC_SUCCESS;
672 }
673
674 static int EsDelayCallback ( vlc_object_t *p_this, char const *psz_cmd,
675                              vlc_value_t oldval, vlc_value_t newval, void *p )
676 {
677     input_thread_t *p_input = (input_thread_t*)p_this;
678
679     if( !strcmp( psz_cmd, "audio-delay" ) )
680         input_ControlPush( p_input, INPUT_CONTROL_SET_AUDIO_DELAY, &newval );
681     else if( !strcmp( psz_cmd, "spu-delay" ) )
682         input_ControlPush( p_input, INPUT_CONTROL_SET_SPU_DELAY, &newval );
683     return VLC_SUCCESS;
684 }
685
686 static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
687                              vlc_value_t oldval, vlc_value_t newval,
688                              void *p_data )
689 {
690     input_thread_t *p_input = (input_thread_t*)p_this;
691
692     input_ControlPush( p_input, INPUT_CONTROL_SET_BOOKMARK, &newval );
693
694     return VLC_SUCCESS;
695 }