]> git.sesse.net Git - vlc/blob - src/input/var.c
Changed input_DestroyThread to take care of detaching, cleaning and destroying input.
[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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <vlc/vlc.h>
28 #include <stdio.h>
29 #include <stdlib.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     /* XXX we put callback only in non preparsing mode. We need to create the variable
79      * unless someone want to check all var_Get/var_Change return value ... */
80 #define ADD_CALLBACK( name, callback ) do { if( !p_input->b_preparsing ) { var_AddCallback( p_input, name, callback, NULL ); } } while(0)
81     /* State */
82     var_Create( p_input, "state", VLC_VAR_INTEGER );
83     val.i_int = p_input->i_state;
84     var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
85     ADD_CALLBACK( "state", StateCallback );
86
87     /* Rate */
88     var_Create( p_input, "rate", VLC_VAR_INTEGER );
89     val.i_int = p_input->p->i_rate;
90     var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
91     ADD_CALLBACK( "rate", RateCallback );
92
93     var_Create( p_input, "rate-slower", VLC_VAR_VOID );
94     ADD_CALLBACK( "rate-slower", RateCallback );
95
96     var_Create( p_input, "rate-faster", VLC_VAR_VOID );
97     ADD_CALLBACK( "rate-faster", RateCallback );
98
99     /* Position */
100     var_Create( p_input, "position",  VLC_VAR_FLOAT );
101     var_Create( p_input, "position-offset",  VLC_VAR_FLOAT );
102     val.f_float = 0.0;
103     var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
104     ADD_CALLBACK( "position", PositionCallback );
105     ADD_CALLBACK( "position-offset", PositionCallback );
106
107     /* Time */
108     var_Create( p_input, "time",  VLC_VAR_TIME );
109     var_Create( p_input, "time-offset",  VLC_VAR_TIME );    /* relative */
110     val.i_time = 0;
111     var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
112     ADD_CALLBACK( "time", TimeCallback );
113     ADD_CALLBACK( "time-offset", TimeCallback );
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     ADD_CALLBACK( "bookmark", BookmarkCallback );
121
122     /* Program */
123     var_Create( p_input, "program", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE |
124                 VLC_VAR_DOINHERIT );
125     var_Get( p_input, "program", &val );
126     if( val.i_int <= 0 )
127         var_Change( p_input, "program", VLC_VAR_DELCHOICE, &val, NULL );
128     text.psz_string = _("Program");
129     var_Change( p_input, "program", VLC_VAR_SETTEXT, &text, NULL );
130     ADD_CALLBACK( "program", ProgramCallback );
131
132     /* Programs */
133     var_Create( p_input, "programs", VLC_VAR_LIST | VLC_VAR_DOINHERIT );
134     text.psz_string = _("Programs");
135     var_Change( p_input, "programs", VLC_VAR_SETTEXT, &text, NULL );
136
137     /* Title */
138     var_Create( p_input, "title", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
139     text.psz_string = _("Title");
140     var_Change( p_input, "title", VLC_VAR_SETTEXT, &text, NULL );
141     ADD_CALLBACK( "title", TitleCallback );
142
143     /* Chapter */
144     var_Create( p_input, "chapter", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
145     text.psz_string = _("Chapter");
146     var_Change( p_input, "chapter", VLC_VAR_SETTEXT, &text, NULL );
147     ADD_CALLBACK( "chapter", SeekpointCallback );
148
149     /* Navigation The callback is added after */
150     var_Create( p_input, "navigation", VLC_VAR_VARIABLE | VLC_VAR_HASCHOICE );
151     text.psz_string = _("Navigation");
152     var_Change( p_input, "navigation", VLC_VAR_SETTEXT, &text, NULL );
153
154     /* Delay */
155     var_Create( p_input, "audio-delay", VLC_VAR_TIME );
156     val.i_time = 0;
157     var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
158     ADD_CALLBACK( "audio-delay", EsDelayCallback );
159     var_Create( p_input, "spu-delay", VLC_VAR_TIME );
160     val.i_time = 0;
161     var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
162     ADD_CALLBACK( "spu-delay", EsDelayCallback );
163
164     /* Video ES */
165     var_Create( p_input, "video-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
166     text.psz_string = _("Video Track");
167     var_Change( p_input, "video-es", VLC_VAR_SETTEXT, &text, NULL );
168     ADD_CALLBACK( "video-es", ESCallback );
169
170     /* Audio ES */
171     var_Create( p_input, "audio-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
172     text.psz_string = _("Audio Track");
173     var_Change( p_input, "audio-es", VLC_VAR_SETTEXT, &text, NULL );
174     ADD_CALLBACK( "audio-es", ESCallback );
175
176     /* Spu ES */
177     var_Create( p_input, "spu-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
178     text.psz_string = _("Subtitles Track");
179     var_Change( p_input, "spu-es", VLC_VAR_SETTEXT, &text, NULL );
180     ADD_CALLBACK( "spu-es", ESCallback );
181
182     /* Special read only objects variables for intf */
183     var_Create( p_input, "bookmarks", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
184
185     var_Create( p_input, "length",  VLC_VAR_TIME );
186     val.i_time = 0;
187     var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
188
189     if( !p_input->b_preparsing )
190     {
191         /* Special "intf-change" variable, it allows intf to set up a callback
192          * to be notified of some changes.
193          * TODO list all changes warn by this callbacks */
194         var_Create( p_input, "intf-change", VLC_VAR_BOOL );
195         var_SetBool( p_input, "intf-change", VLC_TRUE );
196
197        /* item-change variable */
198         var_Create( p_input, "item-change", VLC_VAR_INTEGER );
199     }
200 #undef ADD_CALLBACK
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->p->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->p->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->p->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->p->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->p->title[i]->psz_name == NULL ||
289             *p_input->p->title[i]->psz_name == '\0' )
290         {
291             asprintf( &text.psz_string, _("Title %i"),
292                       i + p_input->p->i_title_offset );
293         }
294         else
295         {
296             text.psz_string = strdup( p_input->p->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->p->title[i]->i_seekpoint; j++ )
307         {
308             val2.i_int = j;
309
310             if( p_input->p->title[i]->seekpoint[j]->psz_name == NULL ||
311                 *p_input->p->title[i]->seekpoint[j]->psz_name == '\0' )
312             {
313                 /* Default value */
314                 asprintf( &text2.psz_string, _("Chapter %i"),
315                           j + p_input->p->i_seekpoint_offset );
316             }
317             else
318             {
319                 text2.psz_string =
320                     strdup( p_input->p->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->p->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->p->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  * input_ConfigVarInit:
389  *  Create all config object variables
390  *****************************************************************************/
391 void input_ConfigVarInit ( input_thread_t *p_input )
392 {
393     vlc_value_t val;
394
395     /* Create Object Variables for private use only */
396
397     if( !p_input->b_preparsing )
398     {
399         var_Create( p_input, "video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
400         var_Create( p_input, "audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
401         var_Create( p_input, "spu", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
402
403         var_Create( p_input, "audio-track", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
404         var_Create( p_input, "sub-track", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
405
406         var_Create( p_input, "audio-language",
407                     VLC_VAR_STRING|VLC_VAR_DOINHERIT );
408         var_Create( p_input, "sub-language",
409                     VLC_VAR_STRING|VLC_VAR_DOINHERIT );
410
411         var_Create( p_input, "audio-track-id",
412                     VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
413         var_Create( p_input, "sub-track-id",
414                     VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
415
416         var_Create( p_input, "sub-file", VLC_VAR_FILE | VLC_VAR_DOINHERIT );
417         var_Create( p_input, "sub-autodetect-file", VLC_VAR_BOOL |
418                     VLC_VAR_DOINHERIT );
419         var_Create( p_input, "sub-autodetect-path", VLC_VAR_STRING |
420                     VLC_VAR_DOINHERIT );
421         var_Create( p_input, "sub-autodetect-fuzzy", VLC_VAR_INTEGER |
422                     VLC_VAR_DOINHERIT );
423
424         var_Create( p_input, "sout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
425         var_Create( p_input, "sout-all",   VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
426         var_Create( p_input, "sout-audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
427         var_Create( p_input, "sout-video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
428         var_Create( p_input, "sout-spu", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
429         var_Create( p_input, "sout-keep",  VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
430
431         var_Create( p_input, "input-repeat",
432                     VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
433         var_Create( p_input, "start-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
434         var_Create( p_input, "stop-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
435
436         var_Create( p_input, "input-slave",
437                     VLC_VAR_STRING | VLC_VAR_DOINHERIT );
438
439         var_Create( p_input, "minimize-threads",
440                     VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
441
442         var_Create( p_input, "audio-desync",
443                     VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
444         var_Create( p_input, "cr-average",
445                     VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
446         var_Create( p_input, "clock-synchro",
447                     VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
448     }
449
450     var_Create( p_input, "demuxed-id3", VLC_VAR_BOOL ); /* FIXME beurk */
451     val.b_bool = VLC_FALSE;
452     var_Change( p_input, "demuxed-id3", VLC_VAR_SETVALUE, &val, NULL );
453
454     var_Create( p_input, "seekable", VLC_VAR_BOOL );
455     val.b_bool = VLC_TRUE; /* Fixed later*/
456     var_Change( p_input, "seekable", VLC_VAR_SETVALUE, &val, NULL );
457
458     /* */
459     var_Create( p_input, "access-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
460     var_Create( p_input, "access", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
461     var_Create( p_input, "demux", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
462
463     /* Meta */
464     var_Create( p_input, "meta-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
465     var_Create( p_input, "meta-author", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
466     var_Create( p_input, "meta-artist", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
467     var_Create( p_input, "meta-genre", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
468     var_Create( p_input, "meta-copyright", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
469     var_Create( p_input, "meta-description", VLC_VAR_STRING|VLC_VAR_DOINHERIT);
470     var_Create( p_input, "meta-date", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
471     var_Create( p_input, "meta-url", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
472 }
473
474 /*****************************************************************************
475  * All Callbacks:
476  *****************************************************************************/
477 static int StateCallback( vlc_object_t *p_this, char const *psz_cmd,
478                           vlc_value_t oldval, vlc_value_t newval,
479                           void *p_data )
480 {
481     input_thread_t *p_input = (input_thread_t*)p_this;
482
483
484     if( newval.i_int == PLAYING_S || newval.i_int == PAUSE_S )
485     {
486         input_ControlPush( p_input, INPUT_CONTROL_SET_STATE, &newval );
487         return VLC_SUCCESS;
488     }
489
490     return VLC_EGENERIC;
491 }
492
493 static int RateCallback( vlc_object_t *p_this, char const *psz_cmd,
494                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
495 {
496     input_thread_t *p_input = (input_thread_t*)p_this;
497
498     /* Problem with this way: the "rate" variable is update after the input thread do the change */
499     if( !strcmp( psz_cmd, "rate-slower" ) )
500     {
501         input_ControlPush( p_input, INPUT_CONTROL_SET_RATE_SLOWER, NULL );
502     }
503     else if( !strcmp( psz_cmd, "rate-faster" ) )
504     {
505         input_ControlPush( p_input, INPUT_CONTROL_SET_RATE_FASTER, NULL );
506     }
507     else
508     {
509         input_ControlPush( p_input, INPUT_CONTROL_SET_RATE, &newval );
510     }
511
512     return VLC_SUCCESS;
513 }
514
515 static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
516                              vlc_value_t oldval, vlc_value_t newval,
517                              void *p_data )
518 {
519     input_thread_t *p_input = (input_thread_t*)p_this;
520     vlc_value_t val, length;
521
522     if( !strcmp( psz_cmd, "position-offset" ) )
523     {
524         input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION_OFFSET, &newval );
525
526         val.f_float = var_GetFloat( p_input, "position" ) + newval.f_float;
527         if( val.f_float < 0.0 ) val.f_float = 0.0;
528         if( val.f_float > 1.0 ) val.f_float = 1.0;
529         var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
530     }
531     else
532     {
533         val.f_float = newval.f_float;
534         input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &newval );
535     }
536
537     /* Update "position" for better intf behavour */
538     var_Get( p_input, "length", &length );
539     if( length.i_time > 0 && val.f_float >= 0.0 && val.f_float <= 1.0 )
540     {
541         val.i_time = length.i_time * val.f_float;
542         var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
543     }
544
545     return VLC_SUCCESS;
546 }
547
548 static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
549                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
550 {
551     input_thread_t *p_input = (input_thread_t*)p_this;
552     vlc_value_t val, length;
553
554     if( !strcmp( psz_cmd, "time-offset" ) )
555     {
556         input_ControlPush( p_input, INPUT_CONTROL_SET_TIME_OFFSET, &newval );
557         val.i_time = var_GetTime( p_input, "time" ) + newval.i_time;
558         if( val.i_time < 0 ) val.i_time = 0;
559         /* TODO maybe test against i_length ? */
560         var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
561     }
562     else
563     {
564         val.i_time = newval.i_time;
565         input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval );
566     }
567
568     /* Update "position" for better intf behavour */
569     var_Get( p_input, "length", &length );
570     if( length.i_time > 0 && val.i_time >= 0 && val.i_time <= length.i_time )
571     {
572         val.f_float = (double)val.i_time/(double)length.i_time;
573         var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
574     }
575
576     return VLC_SUCCESS;
577 }
578
579 static int ProgramCallback( vlc_object_t *p_this, char const *psz_cmd,
580                             vlc_value_t oldval, vlc_value_t newval,
581                             void *p_data )
582 {
583     input_thread_t *p_input = (input_thread_t*)p_this;
584
585     input_ControlPush( p_input, INPUT_CONTROL_SET_PROGRAM, &newval );
586
587     return VLC_SUCCESS;
588 }
589
590 static int TitleCallback( vlc_object_t *p_this, char const *psz_cmd,
591                           vlc_value_t oldval, vlc_value_t newval,
592                           void *p_data )
593 {
594     input_thread_t *p_input = (input_thread_t*)p_this;
595     vlc_value_t val, count;
596
597     if( !strcmp( psz_cmd, "next-title" ) )
598     {
599         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE_NEXT, NULL );
600
601         val.i_int = var_GetInteger( p_input, "title" ) + 1;
602         var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &count, NULL );
603         if( val.i_int < count.i_int )
604             var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
605     }
606     else if( !strcmp( psz_cmd, "prev-title" ) )
607     {
608         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE_PREV, NULL );
609
610         val.i_int = var_GetInteger( p_input, "title" ) - 1;
611         if( val.i_int >= 0 )
612             var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
613     }
614     else
615     {
616         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &newval );
617     }
618
619     return VLC_SUCCESS;
620 }
621
622 static int SeekpointCallback( vlc_object_t *p_this, char const *psz_cmd,
623                               vlc_value_t oldval, vlc_value_t newval,
624                               void *p_data )
625 {
626     input_thread_t *p_input = (input_thread_t*)p_this;
627     vlc_value_t val, count;
628
629     if( !strcmp( psz_cmd, "next-chapter" ) )
630     {
631         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT_NEXT, NULL );
632
633         val.i_int = var_GetInteger( p_input, "chapter" ) + 1;
634         var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &count, NULL );
635         if( val.i_int < count.i_int )
636             var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
637     }
638     else if( !strcmp( psz_cmd, "prev-chapter" ) )
639     {
640         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT_PREV, NULL );
641
642         val.i_int = var_GetInteger( p_input, "chapter" ) - 1;
643         if( val.i_int >= 0 )
644             var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
645     }
646     else
647     {
648         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &newval );
649     }
650
651     return VLC_SUCCESS;
652 }
653
654 static int NavigationCallback( vlc_object_t *p_this, char const *psz_cmd,
655                                vlc_value_t oldval, vlc_value_t newval,
656                                void *p_data )
657 {
658     input_thread_t *p_input = (input_thread_t*)p_this;
659     vlc_value_t     val;
660
661     /* Issue a title change */
662     val.i_int = (int)p_data;
663     input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
664
665     var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
666
667     /* And a chapter change */
668     input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &newval );
669
670     var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &newval, NULL );
671
672     return VLC_SUCCESS;
673 }
674
675 static int ESCallback( vlc_object_t *p_this, char const *psz_cmd,
676                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
677 {
678     input_thread_t *p_input = (input_thread_t*)p_this;
679
680     if( newval.i_int < 0 )
681     {
682         vlc_value_t v;
683         /* Hack */
684         if( !strcmp( psz_cmd, "audio-es" ) )
685             v.i_int = -AUDIO_ES;
686         else if( !strcmp( psz_cmd, "video-es" ) )
687             v.i_int = -VIDEO_ES;
688         else if( !strcmp( psz_cmd, "spu-es" ) )
689             v.i_int = -SPU_ES;
690         else
691             v.i_int = 0;
692         if( v.i_int != 0 )
693             input_ControlPush( p_input, INPUT_CONTROL_SET_ES, &v );
694     }
695     else
696     {
697         input_ControlPush( p_input, INPUT_CONTROL_SET_ES, &newval );
698     }
699
700     return VLC_SUCCESS;
701 }
702
703 static int EsDelayCallback ( vlc_object_t *p_this, char const *psz_cmd,
704                              vlc_value_t oldval, vlc_value_t newval, void *p )
705 {
706     input_thread_t *p_input = (input_thread_t*)p_this;
707
708
709     if( !strcmp( psz_cmd, "audio-delay" ) )
710     {
711         /*Change i_pts_delay to make sure es are decoded in time*/
712         if (newval.i_int < 0 || oldval.i_int < 0 )
713         {
714             p_input->i_pts_delay -= newval.i_int - oldval.i_int;
715         }
716         input_ControlPush( p_input, INPUT_CONTROL_SET_AUDIO_DELAY, &newval );
717     }
718     else if( !strcmp( psz_cmd, "spu-delay" ) )
719         input_ControlPush( p_input, INPUT_CONTROL_SET_SPU_DELAY, &newval );
720     return VLC_SUCCESS;
721 }
722
723 static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
724                              vlc_value_t oldval, vlc_value_t newval,
725                              void *p_data )
726 {
727     input_thread_t *p_input = (input_thread_t*)p_this;
728
729     input_ControlPush( p_input, INPUT_CONTROL_SET_BOOKMARK, &newval );
730
731     return VLC_SUCCESS;
732 }