]> git.sesse.net Git - vlc/blob - src/input/var.c
* src/input/es_out.c: New --no-spu and --no-sout-spu options to disable
[vlc] / src / input / var.c
1 /*****************************************************************************
2  * var.c: object variables for input thread
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
5  * $Id$
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  * Callbacks
45  *****************************************************************************/
46 static int StateCallback   ( vlc_object_t *p_this, char const *psz_cmd,
47                              vlc_value_t oldval, vlc_value_t newval, void * );
48 static int RateCallback    ( vlc_object_t *p_this, char const *psz_cmd,
49                              vlc_value_t oldval, vlc_value_t newval, void * );
50 static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
51                              vlc_value_t oldval, vlc_value_t newval, void * );
52 static int TimeCallback    ( vlc_object_t *p_this, char const *psz_cmd,
53                              vlc_value_t oldval, vlc_value_t newval, void * );
54 static int ProgramCallback ( vlc_object_t *p_this, char const *psz_cmd,
55                              vlc_value_t oldval, vlc_value_t newval, void * );
56 static int TitleCallback   ( vlc_object_t *p_this, char const *psz_cmd,
57                              vlc_value_t oldval, vlc_value_t newval, void * );
58 static int SeekpointCallback( vlc_object_t *p_this, char const *psz_cmd,
59                              vlc_value_t oldval, vlc_value_t newval, void * );
60 static int NavigationCallback( vlc_object_t *p_this, char const *psz_cmd,
61                              vlc_value_t oldval, vlc_value_t newval, void * );
62 static int ESCallback      ( vlc_object_t *p_this, char const *psz_cmd,
63                              vlc_value_t oldval, vlc_value_t newval, void * );
64 static int EsDelayCallback ( vlc_object_t *p_this, char const *psz_cmd,
65                              vlc_value_t oldval, vlc_value_t newval, void * );
66
67 static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
68                              vlc_value_t oldval, vlc_value_t newval, void * );
69
70 /*****************************************************************************
71  * input_ControlVarInit:
72  *  Create all control object variables with their callbacks
73  *****************************************************************************/
74 void input_ControlVarInit ( input_thread_t *p_input )
75 {
76     vlc_value_t val, text;
77
78     /* State */
79     var_Create( p_input, "state", VLC_VAR_INTEGER );
80     val.i_int = p_input->i_state;
81     var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
82     var_AddCallback( p_input, "state", StateCallback, NULL );
83
84     /* Rate */
85     var_Create( p_input, "rate", VLC_VAR_INTEGER );
86     val.i_int = p_input->i_rate;
87     var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
88     var_AddCallback( p_input, "rate", RateCallback, NULL );
89
90     var_Create( p_input, "rate-slower", VLC_VAR_VOID );
91     var_AddCallback( p_input, "rate-slower", RateCallback, NULL );
92
93     var_Create( p_input, "rate-faster", VLC_VAR_VOID );
94     var_AddCallback( p_input, "rate-faster", RateCallback, NULL );
95
96     /* Position */
97     var_Create( p_input, "position",  VLC_VAR_FLOAT );
98     var_Create( p_input, "position-offset",  VLC_VAR_FLOAT );
99     val.f_float = 0.0;
100     var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
101     var_AddCallback( p_input, "position", PositionCallback, NULL );
102     var_AddCallback( p_input, "position-offset", PositionCallback, NULL );
103
104     /* Time */
105     var_Create( p_input, "time",  VLC_VAR_TIME );
106     var_Create( p_input, "time-offset",  VLC_VAR_TIME );    /* relative */
107     val.i_time = 0;
108     var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
109     var_AddCallback( p_input, "time", TimeCallback, NULL );
110     var_AddCallback( p_input, "time-offset", TimeCallback, NULL );
111
112     /* Bookmark */
113     var_Create( p_input, "bookmark", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE |
114                 VLC_VAR_ISCOMMAND );
115     val.psz_string = _("Bookmark");
116     var_Change( p_input, "bookmark", VLC_VAR_SETTEXT, &val, NULL );
117     var_AddCallback( p_input, "bookmark", BookmarkCallback, NULL );
118
119     /* Program */
120     var_Create( p_input, "program", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE |
121                 VLC_VAR_DOINHERIT );
122     var_Get( p_input, "program", &val );
123     if( val.i_int <= 0 )
124         var_Change( p_input, "program", VLC_VAR_DELCHOICE, &val, NULL );
125     text.psz_string = _("Program");
126     var_Change( p_input, "program", VLC_VAR_SETTEXT, &text, NULL );
127     var_AddCallback( p_input, "program", ProgramCallback, NULL );
128
129     /* Programs */
130     var_Create( p_input, "programs", VLC_VAR_LIST | VLC_VAR_DOINHERIT );
131     text.psz_string = _("Programs");
132     var_Change( p_input, "programs", VLC_VAR_SETTEXT, &text, NULL );
133
134     /* Title */
135     var_Create( p_input, "title", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
136     text.psz_string = _("Title");
137     var_Change( p_input, "title", VLC_VAR_SETTEXT, &text, NULL );
138     var_AddCallback( p_input, "title", TitleCallback, NULL );
139
140     /* Chapter */
141     var_Create( p_input, "chapter", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
142     text.psz_string = _("Chapter");
143     var_Change( p_input, "chapter", VLC_VAR_SETTEXT, &text, NULL );
144     var_AddCallback( p_input, "chapter", SeekpointCallback, NULL );
145
146     /* Navigation The callback is added after */
147     var_Create( p_input, "navigation", VLC_VAR_VARIABLE | VLC_VAR_HASCHOICE );
148     text.psz_string = _("Navigation");
149     var_Change( p_input, "navigation", VLC_VAR_SETTEXT, &text, NULL );
150
151     /* Delay */
152     var_Create( p_input, "audio-delay", VLC_VAR_TIME );
153     val.i_time = 0;
154     var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
155     var_AddCallback( p_input, "audio-delay", EsDelayCallback, NULL );
156     var_Create( p_input, "spu-delay", VLC_VAR_TIME );
157     val.i_time = 0;
158     var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
159     var_AddCallback( p_input, "spu-delay", EsDelayCallback, NULL );
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     /* Special read only objects variables for intf */
180     var_Create( p_input, "bookmarks", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
181
182     var_Create( p_input, "length",  VLC_VAR_TIME );
183     val.i_time = 0;
184     var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
185
186     /* Special "intf-change" variable, it allows intf to set up a callback
187      * to be notified of some changes.
188      * TODO list all changes warn by this callbacks */
189     var_Create( p_input, "intf-change", VLC_VAR_BOOL );
190     var_SetBool( p_input, "intf-change", VLC_TRUE );
191
192    /* item-change variable */
193     var_Create( p_input, "item-change", VLC_VAR_INTEGER );
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             asprintf( &text.psz_string, _("Title %i"),
285                       i + p_input->i_title_offset );
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                 asprintf( &text2.psz_string, _("Chapter %i"),
308                           j + p_input->i_seekpoint_offset );
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         var_Destroy( p_input, "next-chapter" );
339         var_Destroy( p_input, "prev-chapter" );
340     }
341     else if( var_Get( p_input, "next-chapter", &val ) != VLC_SUCCESS )
342     {
343         vlc_value_t text;
344
345         var_Create( p_input, "next-chapter", VLC_VAR_VOID );
346         text.psz_string = _("Next chapter");
347         var_Change( p_input, "next-chapter", VLC_VAR_SETTEXT, &text, NULL );
348         var_AddCallback( p_input, "next-chapter", SeekpointCallback, NULL );
349
350         var_Create( p_input, "prev-chapter", VLC_VAR_VOID );
351         text.psz_string = _("Previous chapter");
352         var_Change( p_input, "prev-chapter", VLC_VAR_SETTEXT, &text, NULL );
353         var_AddCallback( p_input, "prev-chapter", SeekpointCallback, NULL );
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             asprintf( &text.psz_string, _("Chapter %i"),
368                       i + p_input->i_seekpoint_offset );
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  * input_ConfigVarInit:
382  *  Create all config object variables
383  *****************************************************************************/
384 void input_ConfigVarInit ( input_thread_t *p_input )
385 {
386     vlc_value_t val;
387
388     /* Create Object Variables for private use only */
389     var_Create( p_input, "video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
390     var_Create( p_input, "audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
391     var_Create( p_input, "spu", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
392
393     var_Create( p_input, "audio-track", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
394     var_Create( p_input, "sub-track", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
395
396     var_Create( p_input, "audio-language", VLC_VAR_STRING|VLC_VAR_DOINHERIT );
397     var_Create( p_input, "sub-language", VLC_VAR_STRING|VLC_VAR_DOINHERIT );
398
399     var_Create( p_input, "audio-track-id", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
400     var_Create( p_input, "sub-track-id", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
401
402     var_Create( p_input, "sub-file", VLC_VAR_FILE | VLC_VAR_DOINHERIT );
403     var_Create( p_input, "sub-autodetect-file", VLC_VAR_BOOL |
404                 VLC_VAR_DOINHERIT );
405     var_Create( p_input, "sub-autodetect-path", VLC_VAR_STRING |
406                 VLC_VAR_DOINHERIT );
407     var_Create( p_input, "sub-autodetect-fuzzy", VLC_VAR_INTEGER |
408                 VLC_VAR_DOINHERIT );
409
410     var_Create( p_input, "sout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
411     var_Create( p_input, "sout-all",   VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
412     var_Create( p_input, "sout-audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
413     var_Create( p_input, "sout-video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
414     var_Create( p_input, "sout-spu", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
415     var_Create( p_input, "sout-keep",  VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
416
417     var_Create( p_input, "input-repeat", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
418
419     var_Create( p_input, "start-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
420     var_Create( p_input, "stop-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
421
422     var_Create( p_input, "minimize-threads", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
423
424     var_Create( p_input, "demuxed-id3", VLC_VAR_BOOL ); /* FIXME beurk */
425     val.b_bool = VLC_FALSE;
426     var_Change( p_input, "demuxed-id3", VLC_VAR_SETVALUE, &val, NULL );
427
428     var_Create( p_input, "audio-desync", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
429
430     var_Create( p_input, "cr-average", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
431     var_Create( p_input, "clock-synchro", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
432
433     var_Create( p_input, "seekable", VLC_VAR_BOOL );
434     val.b_bool = VLC_TRUE; /* Fixed later*/
435     var_Change( p_input, "seekable", VLC_VAR_SETVALUE, &val, NULL );
436
437     var_Create( p_input, "input-slave", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
438
439     /* */
440     var_Create( p_input, "access-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
441     var_Create( p_input, "access", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
442     var_Create( p_input, "demux", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
443
444     /* Meta */
445     var_Create( p_input, "meta-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
446     var_Create( p_input, "meta-author", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
447     var_Create( p_input, "meta-artist", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
448     var_Create( p_input, "meta-genre", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
449     var_Create( p_input, "meta-copyright", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
450     var_Create( p_input, "meta-description", VLC_VAR_STRING|VLC_VAR_DOINHERIT);
451     var_Create( p_input, "meta-date", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
452     var_Create( p_input, "meta-url", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
453 }
454
455 /*****************************************************************************
456  * All Callbacks:
457  *****************************************************************************/
458 static int StateCallback( vlc_object_t *p_this, char const *psz_cmd,
459                           vlc_value_t oldval, vlc_value_t newval,
460                           void *p_data )
461 {
462     input_thread_t *p_input = (input_thread_t*)p_this;
463
464
465     if( newval.i_int == PLAYING_S || newval.i_int == PAUSE_S )
466     {
467         input_ControlPush( p_input, INPUT_CONTROL_SET_STATE, &newval );
468         return VLC_SUCCESS;
469     }
470
471     return VLC_EGENERIC;
472 }
473
474 static int RateCallback( vlc_object_t *p_this, char const *psz_cmd,
475                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
476 {
477     input_thread_t *p_input = (input_thread_t*)p_this;
478
479     /* Problem with this way: the "rate" variable is update after the input thread do the change */
480     if( !strcmp( psz_cmd, "rate-slower" ) )
481     {
482         input_ControlPush( p_input, INPUT_CONTROL_SET_RATE_SLOWER, NULL );
483     }
484     else if( !strcmp( psz_cmd, "rate-faster" ) )
485     {
486         input_ControlPush( p_input, INPUT_CONTROL_SET_RATE_FASTER, NULL );
487     }
488     else
489     {
490         input_ControlPush( p_input, INPUT_CONTROL_SET_RATE, &newval );
491     }
492
493     return VLC_SUCCESS;
494 }
495
496 static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
497                              vlc_value_t oldval, vlc_value_t newval,
498                              void *p_data )
499 {
500     input_thread_t *p_input = (input_thread_t*)p_this;
501     vlc_value_t val, length;
502
503     if( !strcmp( psz_cmd, "position-offset" ) )
504     {
505         input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION_OFFSET, &newval );
506
507         val.f_float = var_GetFloat( p_input, "position" ) + newval.f_float;
508         if( val.f_float < 0.0 ) val.f_float = 0.0;
509         if( val.f_float > 1.0 ) val.f_float = 1.0;
510         var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
511     }
512     else
513     {
514         val.f_float = newval.f_float;
515         input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &newval );
516     }
517
518     /* Update "position" for better intf behavour */
519     var_Get( p_input, "length", &length );
520     if( length.i_time > 0 && val.f_float >= 0.0 && val.f_float <= 1.0 )
521     {
522         val.i_time = length.i_time * val.f_float;
523         var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
524     }
525
526     return VLC_SUCCESS;
527 }
528
529 static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
530                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
531 {
532     input_thread_t *p_input = (input_thread_t*)p_this;
533     vlc_value_t val, length;
534
535     if( !strcmp( psz_cmd, "time-offset" ) )
536     {
537         input_ControlPush( p_input, INPUT_CONTROL_SET_TIME_OFFSET, &newval );
538         val.i_time = var_GetTime( p_input, "time" ) + newval.i_time;
539         if( val.i_time < 0 ) val.i_time = 0;
540         /* TODO maybe test against i_length ? */
541         var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
542     }
543     else
544     {
545         val.i_time = newval.i_time;
546         input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval );
547     }
548
549     /* Update "position" for better intf behavour */
550     var_Get( p_input, "length", &length );
551     if( length.i_time > 0 && val.i_time >= 0 && val.i_time <= length.i_time )
552     {
553         val.f_float = (double)val.i_time/(double)length.i_time;
554         var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
555     }
556
557     return VLC_SUCCESS;
558 }
559
560 static int ProgramCallback( vlc_object_t *p_this, char const *psz_cmd,
561                             vlc_value_t oldval, vlc_value_t newval,
562                             void *p_data )
563 {
564     input_thread_t *p_input = (input_thread_t*)p_this;
565
566     input_ControlPush( p_input, INPUT_CONTROL_SET_PROGRAM, &newval );
567
568     return VLC_SUCCESS;
569 }
570
571 static int TitleCallback( vlc_object_t *p_this, char const *psz_cmd,
572                           vlc_value_t oldval, vlc_value_t newval,
573                           void *p_data )
574 {
575     input_thread_t *p_input = (input_thread_t*)p_this;
576     vlc_value_t val, count;
577
578     if( !strcmp( psz_cmd, "next-title" ) )
579     {
580         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE_NEXT, NULL );
581
582         val.i_int = var_GetInteger( p_input, "title" ) + 1;
583         var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &count, NULL );
584         if( val.i_int < count.i_int )
585             var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
586     }
587     else if( !strcmp( psz_cmd, "prev-title" ) )
588     {
589         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE_PREV, NULL );
590
591         val.i_int = var_GetInteger( p_input, "title" ) - 1;
592         if( val.i_int >= 0 )
593             var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
594     }
595     else
596     {
597         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &newval );
598     }
599
600     return VLC_SUCCESS;
601 }
602
603 static int SeekpointCallback( vlc_object_t *p_this, char const *psz_cmd,
604                               vlc_value_t oldval, vlc_value_t newval,
605                               void *p_data )
606 {
607     input_thread_t *p_input = (input_thread_t*)p_this;
608     vlc_value_t val, count;
609
610     if( !strcmp( psz_cmd, "next-chapter" ) )
611     {
612         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT_NEXT, NULL );
613
614         val.i_int = var_GetInteger( p_input, "chapter" ) + 1;
615         var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &count, NULL );
616         if( val.i_int < count.i_int )
617             var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
618     }
619     else if( !strcmp( psz_cmd, "prev-chapter" ) )
620     {
621         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT_PREV, NULL );
622
623         val.i_int = var_GetInteger( p_input, "chapter" ) - 1;
624         if( val.i_int >= 0 )
625             var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
626     }
627     else
628     {
629         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &newval );
630     }
631
632     return VLC_SUCCESS;
633 }
634
635 static int NavigationCallback( vlc_object_t *p_this, char const *psz_cmd,
636                                vlc_value_t oldval, vlc_value_t newval,
637                                void *p_data )
638 {
639     input_thread_t *p_input = (input_thread_t*)p_this;
640     vlc_value_t     val;
641
642     /* Issue a title change */
643     val.i_int = (int)p_data;
644     input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
645
646     var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
647
648     /* And a chapter change */
649     input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &newval );
650
651     var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &newval, NULL );
652
653     return VLC_SUCCESS;
654 }
655
656 static int ESCallback( vlc_object_t *p_this, char const *psz_cmd,
657                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
658 {
659     input_thread_t *p_input = (input_thread_t*)p_this;
660
661     if( newval.i_int < 0 )
662     {
663         vlc_value_t v;
664         /* Hack */
665         if( !strcmp( psz_cmd, "audio-es" ) )
666             v.i_int = -AUDIO_ES;
667         else if( !strcmp( psz_cmd, "video-es" ) )
668             v.i_int = -VIDEO_ES;
669         else if( !strcmp( psz_cmd, "spu-es" ) )
670             v.i_int = -SPU_ES;
671         else
672             v.i_int = 0;
673         if( v.i_int != 0 )
674             input_ControlPush( p_input, INPUT_CONTROL_SET_ES, &v );
675     }
676     else
677     {
678         input_ControlPush( p_input, INPUT_CONTROL_SET_ES, &newval );
679     }
680
681     return VLC_SUCCESS;
682 }
683
684 static int EsDelayCallback ( vlc_object_t *p_this, char const *psz_cmd,
685                              vlc_value_t oldval, vlc_value_t newval, void *p )
686 {
687     input_thread_t *p_input = (input_thread_t*)p_this;
688
689
690     if( !strcmp( psz_cmd, "audio-delay" ) )
691     {
692         /*Change i_pts_delay to make sure es are decoded in time*/
693         if (newval.i_int < 0 || oldval.i_int < 0 )
694         {
695             p_input->i_pts_delay -= newval.i_int - oldval.i_int;
696         }
697         input_ControlPush( p_input, INPUT_CONTROL_SET_AUDIO_DELAY, &newval );
698     }
699     else if( !strcmp( psz_cmd, "spu-delay" ) )
700         input_ControlPush( p_input, INPUT_CONTROL_SET_SPU_DELAY, &newval );
701     return VLC_SUCCESS;
702 }
703
704 static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
705                              vlc_value_t oldval, vlc_value_t newval,
706                              void *p_data )
707 {
708     input_thread_t *p_input = (input_thread_t*)p_this;
709
710     input_ControlPush( p_input, INPUT_CONTROL_SET_BOOKMARK, &newval );
711
712     return VLC_SUCCESS;
713 }