]> git.sesse.net Git - vlc/blob - src/input/var.c
* all: compilation fix with vc7.1 compiler, and removed a bunch of warnings (there...
[vlc] / src / input / var.c
1 /*****************************************************************************
2  * var.c: object variables for input thread
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
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     /* Programs */
134     var_Create( p_input, "programs", VLC_VAR_LIST | VLC_VAR_DOINHERIT );
135     text.psz_string = _("Programs");
136     var_Change( p_input, "programs", VLC_VAR_SETTEXT, &text, NULL );
137
138     /* Title */
139     var_Create( p_input, "title", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
140     text.psz_string = _("Title");
141     var_Change( p_input, "title", VLC_VAR_SETTEXT, &text, NULL );
142     var_AddCallback( p_input, "title", TitleCallback, NULL );
143
144     /* Chapter */
145     var_Create( p_input, "chapter", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
146     text.psz_string = _("Chapter");
147     var_Change( p_input, "chapter", VLC_VAR_SETTEXT, &text, NULL );
148     var_AddCallback( p_input, "chapter", SeekpointCallback, NULL );
149
150     /* Navigation The callback is added after */
151     var_Create( p_input, "navigation", VLC_VAR_VARIABLE | VLC_VAR_HASCHOICE );
152     text.psz_string = _("Navigation");
153     var_Change( p_input, "navigation", VLC_VAR_SETTEXT, &text, NULL );
154
155     /* Delay */
156     var_Create( p_input, "audio-delay", VLC_VAR_TIME );
157     val.i_time = 0;
158     var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
159     var_AddCallback( p_input, "audio-delay", EsDelayCallback, NULL );
160     var_Create( p_input, "spu-delay", VLC_VAR_TIME );
161     val.i_time = 0;
162     var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
163     var_AddCallback( p_input, "spu-delay", EsDelayCallback, NULL );
164
165
166     /* Video ES */
167     var_Create( p_input, "video-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
168     text.psz_string = _("Video Track");
169     var_Change( p_input, "video-es", VLC_VAR_SETTEXT, &text, NULL );
170     var_AddCallback( p_input, "video-es", ESCallback, NULL );
171
172     /* Audio ES */
173     var_Create( p_input, "audio-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
174     text.psz_string = _("Audio Track");
175     var_Change( p_input, "audio-es", VLC_VAR_SETTEXT, &text, NULL );
176     var_AddCallback( p_input, "audio-es", ESCallback, NULL );
177
178     /* Spu ES */
179     var_Create( p_input, "spu-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
180     text.psz_string = _("Subtitles Track");
181     var_Change( p_input, "spu-es", VLC_VAR_SETTEXT, &text, NULL );
182     var_AddCallback( p_input, "spu-es", ESCallback, NULL );
183
184
185     /* Special read only objects variables for intf */
186     var_Create( p_input, "bookmarks", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
187
188     var_Create( p_input, "length",  VLC_VAR_TIME );
189     val.i_time = 0;
190     var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
191
192
193    /* Special "intf-change" variable, it allows intf to set up a callback
194      * to be notified of some changes.
195      * TODO list all changes warn by this callbacks */
196     var_Create( p_input, "intf-change", VLC_VAR_BOOL );
197     var_SetBool( p_input, "intf-change", VLC_TRUE );
198
199    /* item-change variable */
200     var_Create( p_input, "item-change", VLC_VAR_INTEGER );
201 }
202
203 /*****************************************************************************
204  * input_ControlVarClean:
205  *****************************************************************************/
206 void input_ControlVarClean( input_thread_t *p_input )
207 {
208     var_Destroy( p_input, "state" );
209     var_Destroy( p_input, "rate" );
210     var_Destroy( p_input, "rate-slower" );
211     var_Destroy( p_input, "rate-faster" );
212     var_Destroy( p_input, "position" );
213     var_Destroy( p_input, "position-offset" );
214     var_Destroy( p_input, "time" );
215     var_Destroy( p_input, "time-offset" );
216
217     var_Destroy( p_input, "audio-delay" );
218     var_Destroy( p_input, "spu-delay" );
219
220     var_Destroy( p_input, "bookmark" );
221
222     var_Destroy( p_input, "program" );
223     if( p_input->i_title > 1 )
224     {
225         /* TODO Destroy sub navigation var ? */
226
227         var_Destroy( p_input, "next-title" );
228         var_Destroy( p_input, "prev-title" );
229     }
230     if( p_input->i_title > 0 )
231     {
232         /* FIXME title > 0 doesn't mean current title has more than 1 seekpoint */
233         var_Destroy( p_input, "next-chapter" );
234         var_Destroy( p_input, "prev-chapter" );
235     }
236     var_Destroy( p_input, "title" );
237     var_Destroy( p_input, "chapter" );
238     var_Destroy( p_input, "navigation" );
239
240     var_Destroy( p_input, "video-es" );
241     var_Destroy( p_input, "audio-es" );
242     var_Destroy( p_input, "spu-es" );
243
244     var_Destroy( p_input, "bookmarks" );
245     var_Destroy( p_input, "length" );
246
247     var_Destroy( p_input, "intf-change" );
248  }
249
250 /*****************************************************************************
251  * input_ControlVarNavigation:
252  *  Create all remaining control object variables
253  *****************************************************************************/
254 void input_ControlVarNavigation( input_thread_t *p_input )
255 {
256     vlc_value_t val, text;
257     int  i;
258
259     /* Create more command variables */
260     if( p_input->i_title > 1 )
261     {
262         var_Create( p_input, "next-title", VLC_VAR_VOID );
263         text.psz_string = _("Next title");
264         var_Change( p_input, "next-title", VLC_VAR_SETTEXT, &text, NULL );
265         var_AddCallback( p_input, "next-title", TitleCallback, NULL );
266
267         var_Create( p_input, "prev-title", VLC_VAR_VOID );
268         text.psz_string = _("Previous title");
269         var_Change( p_input, "prev-title", VLC_VAR_SETTEXT, &text, NULL );
270         var_AddCallback( p_input, "prev-title", TitleCallback, NULL );
271     }
272
273     /* Create title and navigation */
274     val.psz_string = malloc( sizeof("title ") + 5 );
275     for( i = 0; i < p_input->i_title; i++ )
276     {
277         vlc_value_t val2, text, text2;
278         int j;
279
280         /* Add Navigation entries */
281         sprintf( val.psz_string,  "title %2i", i );
282         var_Destroy( p_input, val.psz_string );
283         var_Create( p_input, val.psz_string,
284                     VLC_VAR_INTEGER|VLC_VAR_HASCHOICE|VLC_VAR_ISCOMMAND );
285         var_AddCallback( p_input, val.psz_string,
286                          NavigationCallback, (void *)i );
287
288         if( p_input->title[i]->psz_name == NULL ||
289             *p_input->title[i]->psz_name == '\0' )
290         {
291             asprintf( &text.psz_string, _("Title %i"),
292                       i + p_input->i_title_offset );
293         }
294         else
295         {
296             text.psz_string = strdup( p_input->title[i]->psz_name );
297         }
298         var_Change( p_input, "navigation", VLC_VAR_ADDCHOICE, &val, &text );
299
300         /* Add title choice */
301         val2.i_int = i;
302         var_Change( p_input, "title", VLC_VAR_ADDCHOICE, &val2, &text );
303
304         free( text.psz_string );
305
306         for( j = 0; j < p_input->title[i]->i_seekpoint; j++ )
307         {
308             val2.i_int = j;
309
310             if( p_input->title[i]->seekpoint[j]->psz_name == NULL ||
311                 *p_input->title[i]->seekpoint[j]->psz_name == '\0' )
312             {
313                 /* Default value */
314                 asprintf( &text2.psz_string, _("Chapter %i"),
315                           j + p_input->i_seekpoint_offset );
316             }
317             else
318             {
319                 text2.psz_string =
320                     strdup( p_input->title[i]->seekpoint[j]->psz_name );
321             }
322
323             var_Change( p_input, val.psz_string, VLC_VAR_ADDCHOICE,
324                         &val2, &text2 );
325             if( text2.psz_string ) free( text2.psz_string );
326         }
327
328     }
329     free( val.psz_string );
330 }
331
332 /*****************************************************************************
333  * input_ControlVarTitle:
334  *  Create all variables for a title
335  *****************************************************************************/
336 void input_ControlVarTitle( input_thread_t *p_input, int i_title )
337 {
338     input_title_t *t = p_input->title[i_title];
339     vlc_value_t val;
340     int  i;
341
342     /* Create/Destroy command variables */
343     if( t->i_seekpoint <= 1 )
344     {
345         var_Destroy( p_input, "next-chapter" );
346         var_Destroy( p_input, "prev-chapter" );
347     }
348     else if( var_Get( p_input, "next-chapter", &val ) != VLC_SUCCESS )
349     {
350         vlc_value_t text;
351
352         var_Create( p_input, "next-chapter", VLC_VAR_VOID );
353         text.psz_string = _("Next chapter");
354         var_Change( p_input, "next-chapter", VLC_VAR_SETTEXT, &text, NULL );
355         var_AddCallback( p_input, "next-chapter", SeekpointCallback, NULL );
356
357         var_Create( p_input, "prev-chapter", VLC_VAR_VOID );
358         text.psz_string = _("Previous chapter");
359         var_Change( p_input, "prev-chapter", VLC_VAR_SETTEXT, &text, NULL );
360         var_AddCallback( p_input, "prev-chapter", SeekpointCallback, NULL );
361     }
362
363     /* Build chapter list */
364     var_Change( p_input, "chapter", VLC_VAR_CLEARCHOICES, NULL, NULL );
365     for( i = 0; i <  t->i_seekpoint; i++ )
366     {
367         vlc_value_t text;
368         val.i_int = i;
369
370         if( t->seekpoint[i]->psz_name == NULL ||
371             *t->seekpoint[i]->psz_name == '\0' )
372         {
373             /* Default value */
374             asprintf( &text.psz_string, _("Chapter %i"),
375                       i + p_input->i_seekpoint_offset );
376         }
377         else
378         {
379             text.psz_string = strdup( t->seekpoint[i]->psz_name );
380         }
381
382         var_Change( p_input, "chapter", VLC_VAR_ADDCHOICE, &val, &text );
383         if( text.psz_string ) free( text.psz_string );
384     }
385 }
386
387
388 /*****************************************************************************
389  * input_ConfigVarInit:
390  *  Create all config object variables
391  *****************************************************************************/
392 void input_ConfigVarInit ( input_thread_t *p_input )
393 {
394     vlc_value_t val;
395
396     /* Create Object Variables for private use only */
397     var_Create( p_input, "video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
398     var_Create( p_input, "audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
399
400     var_Create( p_input, "audio-track", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
401     var_Create( p_input, "sub-track", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
402
403     var_Create( p_input, "audio-language", VLC_VAR_STRING|VLC_VAR_DOINHERIT );
404     var_Create( p_input, "sub-language", VLC_VAR_STRING|VLC_VAR_DOINHERIT );
405
406     var_Create( p_input, "sub-file", VLC_VAR_FILE | VLC_VAR_DOINHERIT );
407     var_Create( p_input, "sub-autodetect-file", VLC_VAR_BOOL |
408                 VLC_VAR_DOINHERIT );
409     var_Create( p_input, "sub-autodetect-path", VLC_VAR_STRING |
410                 VLC_VAR_DOINHERIT );
411     var_Create( p_input, "sub-autodetect-fuzzy", VLC_VAR_INTEGER |
412                 VLC_VAR_DOINHERIT );
413
414     var_Create( p_input, "sout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
415     var_Create( p_input, "sout-all",   VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
416     var_Create( p_input, "sout-audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
417     var_Create( p_input, "sout-video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
418     var_Create( p_input, "sout-keep",  VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
419
420     var_Create( p_input, "input-repeat", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
421
422     var_Create( p_input, "start-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
423     var_Create( p_input, "stop-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
424
425     var_Create( p_input, "minimize-threads", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
426
427     var_Create( p_input, "demuxed-id3", VLC_VAR_BOOL ); /* FIXME beurk */
428     val.b_bool = VLC_FALSE;
429     var_Change( p_input, "demuxed-id3", VLC_VAR_SETVALUE, &val, NULL );
430
431     var_Create( p_input, "audio-desync", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
432
433     var_Create( p_input, "cr-average", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
434     var_Create( p_input, "clock-synchro", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
435
436     var_Create( p_input, "seekable", VLC_VAR_BOOL );
437     val.b_bool = VLC_TRUE; /* Fixed later*/
438     var_Change( p_input, "seekable", VLC_VAR_SETVALUE, &val, NULL );
439
440     var_Create( p_input, "input-slave", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
441
442     /* */
443     var_Create( p_input, "access-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
444
445     /* Meta */
446     var_Create( p_input, "meta-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
447     var_Create( p_input, "meta-author", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
448     var_Create( p_input, "meta-artist", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
449     var_Create( p_input, "meta-genre", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
450     var_Create( p_input, "meta-copyright", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
451     var_Create( p_input, "meta-description", VLC_VAR_STRING|VLC_VAR_DOINHERIT);
452     var_Create( p_input, "meta-date", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
453     var_Create( p_input, "meta-url", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
454 }
455
456 /*****************************************************************************
457  * All Callbacks:
458  *****************************************************************************/
459 static int StateCallback( vlc_object_t *p_this, char const *psz_cmd,
460                           vlc_value_t oldval, vlc_value_t newval,
461                           void *p_data )
462 {
463     input_thread_t *p_input = (input_thread_t*)p_this;
464
465
466     if( newval.i_int == PLAYING_S || newval.i_int == PAUSE_S )
467     {
468         input_ControlPush( p_input, INPUT_CONTROL_SET_STATE, &newval );
469         return VLC_SUCCESS;
470     }
471
472     return VLC_EGENERIC;
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
530 static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
531                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
532 {
533     input_thread_t *p_input = (input_thread_t*)p_this;
534     vlc_value_t val, length;
535
536     if( !strcmp( psz_cmd, "time-offset" ) )
537     {
538         input_ControlPush( p_input, INPUT_CONTROL_SET_TIME_OFFSET, &newval );
539
540         val.i_time = var_GetTime( p_input, "time" ) + newval.i_time;
541         if( val.i_time < 0 ) val.i_time = 0;
542         /* TODO maybe test against i_length ? */
543         var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
544     }
545     else
546     {
547         val.i_time = newval.i_time;
548         input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval );
549     }
550
551     /* Update "position" for better intf behavour */
552     var_Get( p_input, "length", &length );
553     if( length.i_time > 0 && val.i_time >= 0 && val.i_time <= length.i_time )
554     {
555         val.f_float = (double)val.i_time/(double)length.i_time;
556         var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
557     }
558
559     return VLC_SUCCESS;
560 }
561
562 static int ProgramCallback( vlc_object_t *p_this, char const *psz_cmd,
563                             vlc_value_t oldval, vlc_value_t newval,
564                             void *p_data )
565 {
566     input_thread_t *p_input = (input_thread_t*)p_this;
567
568     input_ControlPush( p_input, INPUT_CONTROL_SET_PROGRAM, &newval );
569
570     return VLC_SUCCESS;
571 }
572
573 static int TitleCallback( vlc_object_t *p_this, char const *psz_cmd,
574                           vlc_value_t oldval, vlc_value_t newval,
575                           void *p_data )
576 {
577     input_thread_t *p_input = (input_thread_t*)p_this;
578     vlc_value_t val, count;
579
580     if( !strcmp( psz_cmd, "next-title" ) )
581     {
582         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE_NEXT, NULL );
583
584         val.i_int = var_GetInteger( p_input, "title" ) + 1;
585         var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &count, NULL );
586         if( val.i_int < count.i_int )
587             var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
588     }
589     else if( !strcmp( psz_cmd, "prev-title" ) )
590     {
591         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE_PREV, NULL );
592
593         val.i_int = var_GetInteger( p_input, "title" ) - 1;
594         if( val.i_int >= 0 )
595             var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
596     }
597     else
598     {
599         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &newval );
600     }
601
602     return VLC_SUCCESS;
603 }
604
605 static int SeekpointCallback( vlc_object_t *p_this, char const *psz_cmd,
606                               vlc_value_t oldval, vlc_value_t newval,
607                               void *p_data )
608 {
609     input_thread_t *p_input = (input_thread_t*)p_this;
610     vlc_value_t val, count;
611
612     if( !strcmp( psz_cmd, "next-chapter" ) )
613     {
614         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT_NEXT, NULL );
615
616         val.i_int = var_GetInteger( p_input, "chapter" ) + 1;
617         var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &count, NULL );
618         if( val.i_int < count.i_int )
619             var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
620     }
621     else if( !strcmp( psz_cmd, "prev-chapter" ) )
622     {
623         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT_PREV, NULL );
624
625         val.i_int = var_GetInteger( p_input, "chapter" ) - 1;
626         if( val.i_int >= 0 )
627             var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
628     }
629     else
630     {
631         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &newval );
632     }
633
634     return VLC_SUCCESS;
635 }
636
637 static int NavigationCallback( vlc_object_t *p_this, char const *psz_cmd,
638                                vlc_value_t oldval, vlc_value_t newval,
639                                void *p_data )
640 {
641     input_thread_t *p_input = (input_thread_t*)p_this;
642     vlc_value_t     val;
643
644     /* Issue a title change */
645     val.i_int = (int)p_data;
646     input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
647
648     var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
649
650     /* And a chapter change */
651     input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &newval );
652
653     var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &newval, NULL );
654
655     return VLC_SUCCESS;
656 }
657
658 static int ESCallback( vlc_object_t *p_this, char const *psz_cmd,
659                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
660 {
661     input_thread_t *p_input = (input_thread_t*)p_this;
662
663     if( newval.i_int < 0 )
664     {
665         vlc_value_t v;
666         /* Hack */
667         if( !strcmp( psz_cmd, "audio-es" ) )
668             v.i_int = -AUDIO_ES;
669         else if( !strcmp( psz_cmd, "video-es" ) )
670             v.i_int = -VIDEO_ES;
671         else if( !strcmp( psz_cmd, "spu-es" ) )
672             v.i_int = -SPU_ES;
673         else
674             v.i_int = 0;
675         if( v.i_int != 0 )
676             input_ControlPush( p_input, INPUT_CONTROL_SET_ES, &v );
677     }
678     else
679     {
680         input_ControlPush( p_input, INPUT_CONTROL_SET_ES, &newval );
681     }
682
683     return VLC_SUCCESS;
684 }
685
686 static int EsDelayCallback ( vlc_object_t *p_this, char const *psz_cmd,
687                              vlc_value_t oldval, vlc_value_t newval, void *p )
688 {
689     input_thread_t *p_input = (input_thread_t*)p_this;
690
691
692     if( !strcmp( psz_cmd, "audio-delay" ) )
693     {
694         /*Change i_pts_delay to make sure es are decoded in time*/
695         if (newval.i_int < 0 || oldval.i_int < 0 )
696         {
697             p_input->i_pts_delay -= newval.i_int - oldval.i_int;
698         }
699         input_ControlPush( p_input, INPUT_CONTROL_SET_AUDIO_DELAY, &newval );
700     }
701     else if( !strcmp( psz_cmd, "spu-delay" ) )
702         input_ControlPush( p_input, INPUT_CONTROL_SET_SPU_DELAY, &newval );
703     return VLC_SUCCESS;
704 }
705
706 static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
707                              vlc_value_t oldval, vlc_value_t newval,
708                              void *p_data )
709 {
710     input_thread_t *p_input = (input_thread_t*)p_this;
711
712     input_ControlPush( p_input, INPUT_CONTROL_SET_BOOKMARK, &newval );
713
714     return VLC_SUCCESS;
715 }