]> git.sesse.net Git - vlc/blob - src/input/var.c
Fix subtitle delay < 0
[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     /* 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-channel", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
401     var_Create( p_input, "spu-channel", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
402
403     var_Create( p_input, "sub-file", VLC_VAR_FILE | VLC_VAR_DOINHERIT );
404     var_Create( p_input, "sub-autodetect-file", VLC_VAR_BOOL |
405                 VLC_VAR_DOINHERIT );
406     var_Create( p_input, "sub-autodetect-path", VLC_VAR_STRING |
407                 VLC_VAR_DOINHERIT );
408     var_Create( p_input, "sub-autodetect-fuzzy", VLC_VAR_INTEGER |
409                 VLC_VAR_DOINHERIT );
410
411     var_Create( p_input, "sout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
412     var_Create( p_input, "sout-all",   VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
413     var_Create( p_input, "sout-audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
414     var_Create( p_input, "sout-video", 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
432     var_Create( p_input, "seekable", VLC_VAR_BOOL );
433     val.b_bool = VLC_TRUE; /* Fixed later*/
434     var_Change( p_input, "seekable", VLC_VAR_SETVALUE, &val, NULL );
435
436     var_Create( p_input, "input-slave", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
437
438     /* Meta */
439     var_Create( p_input, "meta-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
440     var_Create( p_input, "meta-author", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
441     var_Create( p_input, "meta-artist", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
442     var_Create( p_input, "meta-genre", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
443     var_Create( p_input, "meta-copyright", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
444     var_Create( p_input, "meta-description", VLC_VAR_STRING|VLC_VAR_DOINHERIT);
445     var_Create( p_input, "meta-date", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
446     var_Create( p_input, "meta-url", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
447 }
448
449 /*****************************************************************************
450  * All Callbacks:
451  *****************************************************************************/
452 static int StateCallback( vlc_object_t *p_this, char const *psz_cmd,
453                           vlc_value_t oldval, vlc_value_t newval,
454                           void *p_data )
455 {
456     input_thread_t *p_input = (input_thread_t*)p_this;
457
458
459     if( newval.i_int == PLAYING_S || newval.i_int == PAUSE_S )
460     {
461         input_ControlPush( p_input, INPUT_CONTROL_SET_STATE, &newval );
462         return VLC_SUCCESS;
463     }
464
465     return VLC_EGENERIC;
466 }
467 static int RateCallback( vlc_object_t *p_this, char const *psz_cmd,
468                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
469 {
470     input_thread_t *p_input = (input_thread_t*)p_this;
471     vlc_value_t val;
472     int i_rate;
473
474     /* Problem with this way: the "rate" variable is update after the input thread do the change */
475     if( !strcmp( psz_cmd, "rate-slower" ) )
476     {
477         input_ControlPush( p_input, INPUT_CONTROL_SET_RATE_SLOWER, NULL );
478
479         /* Fix "rate" value */
480         i_rate = var_GetInteger( p_input, "rate" ) * 2;
481         if( i_rate < INPUT_RATE_MIN ) i_rate = INPUT_RATE_MIN;
482         val.i_int = i_rate;
483         var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
484     }
485     else if( !strcmp( psz_cmd, "rate-faster" ) )
486     {
487         input_ControlPush( p_input, INPUT_CONTROL_SET_RATE_FASTER, NULL );
488         i_rate = var_GetInteger( p_input, "rate" ) / 2;
489
490         if( i_rate > INPUT_RATE_MAX ) i_rate = INPUT_RATE_MAX;
491         val.i_int = i_rate;
492         var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
493     }
494     else
495     {
496         input_ControlPush( p_input, INPUT_CONTROL_SET_RATE, &newval );
497     }
498
499     return VLC_SUCCESS;
500 }
501
502 static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
503                              vlc_value_t oldval, vlc_value_t newval,
504                              void *p_data )
505 {
506     input_thread_t *p_input = (input_thread_t*)p_this;
507     vlc_value_t val, length;
508
509     if( !strcmp( psz_cmd, "position-offset" ) )
510     {
511         input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION_OFFSET, &newval );
512
513         val.f_float = var_GetFloat( p_input, "position" ) + newval.f_float;
514         if( val.f_float < 0.0 ) val.f_float = 0.0;
515         if( val.f_float > 1.0 ) val.f_float = 1.0;
516         var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
517     }
518     else
519     {
520         val.f_float = newval.f_float;
521         input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &newval );
522     }
523
524     /* Update "position" for better intf behavour */
525     var_Get( p_input, "length", &length );
526     if( length.i_time > 0 && val.f_float >= 0.0 && val.f_float <= 1.0 )
527     {
528         val.i_time = length.i_time * val.f_float;
529         var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
530     }
531
532     return VLC_SUCCESS;
533 }
534
535
536 static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
537                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
538 {
539     input_thread_t *p_input = (input_thread_t*)p_this;
540     vlc_value_t val, length;
541
542     if( !strcmp( psz_cmd, "time-offset" ) )
543     {
544         input_ControlPush( p_input, INPUT_CONTROL_SET_TIME_OFFSET, &newval );
545
546         val.i_time = var_GetTime( p_input, "time" ) + newval.i_time;
547         if( val.i_time < 0 ) val.i_time = 0;
548         /* TODO maybe test against i_length ? */
549         var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
550     }
551     else
552     {
553         val.i_time = newval.i_time;
554         input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval );
555     }
556
557     /* Update "position" for better intf behavour */
558     var_Get( p_input, "length", &length );
559     if( length.i_time > 0 && val.i_time >= 0 && val.i_time <= length.i_time )
560     {
561         val.f_float = (double)val.i_time/(double)length.i_time;
562         var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
563     }
564
565     return VLC_SUCCESS;
566 }
567
568 static int ProgramCallback( vlc_object_t *p_this, char const *psz_cmd,
569                             vlc_value_t oldval, vlc_value_t newval,
570                             void *p_data )
571 {
572     input_thread_t *p_input = (input_thread_t*)p_this;
573
574     input_ControlPush( p_input, INPUT_CONTROL_SET_PROGRAM, &newval );
575
576     return VLC_SUCCESS;
577 }
578
579 static int TitleCallback( 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     vlc_value_t val, count;
585
586     if( !strcmp( psz_cmd, "next-title" ) )
587     {
588         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE_NEXT, NULL );
589
590         val.i_int = var_GetInteger( p_input, "title" ) + 1;
591         var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &count, NULL );
592         if( val.i_int < count.i_int )
593             var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
594     }
595     else if( !strcmp( psz_cmd, "prev-title" ) )
596     {
597         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE_PREV, NULL );
598
599         val.i_int = var_GetInteger( p_input, "title" ) - 1;
600         if( val.i_int >= 0 )
601             var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
602     }
603     else
604     {
605         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &newval );
606     }
607
608     return VLC_SUCCESS;
609 }
610
611 static int SeekpointCallback( vlc_object_t *p_this, char const *psz_cmd,
612                               vlc_value_t oldval, vlc_value_t newval,
613                               void *p_data )
614 {
615     input_thread_t *p_input = (input_thread_t*)p_this;
616     vlc_value_t val, count;
617
618     if( !strcmp( psz_cmd, "next-chapter" ) )
619     {
620         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT_NEXT, NULL );
621
622         val.i_int = var_GetInteger( p_input, "chapter" ) + 1;
623         var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &count, NULL );
624         if( val.i_int < count.i_int )
625             var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
626     }
627     else if( !strcmp( psz_cmd, "prev-chapter" ) )
628     {
629         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT_PREV, NULL );
630
631         val.i_int = var_GetInteger( p_input, "chapter" ) - 1;
632         if( val.i_int >= 0 )
633             var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
634     }
635     else
636     {
637         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &newval );
638     }
639
640     return VLC_SUCCESS;
641 }
642
643 static int NavigationCallback( vlc_object_t *p_this, char const *psz_cmd,
644                                vlc_value_t oldval, vlc_value_t newval,
645                                void *p_data )
646 {
647     input_thread_t *p_input = (input_thread_t*)p_this;
648     vlc_value_t     val;
649
650     /* Issue a title change */
651     val.i_int = (int)p_data;
652     input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
653
654     var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
655
656     /* And a chapter change */
657     input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &newval );
658
659     var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &newval, NULL );
660
661     return VLC_SUCCESS;
662 }
663
664 static int ESCallback( vlc_object_t *p_this, char const *psz_cmd,
665                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
666 {
667     input_thread_t *p_input = (input_thread_t*)p_this;
668
669     if( newval.i_int < 0 )
670     {
671         vlc_value_t v;
672         /* Hack */
673         if( !strcmp( psz_cmd, "audio-es" ) )
674             v.i_int = -AUDIO_ES;
675         else if( !strcmp( psz_cmd, "video-es" ) )
676             v.i_int = -VIDEO_ES;
677         else if( !strcmp( psz_cmd, "spu-es" ) )
678             v.i_int = -SPU_ES;
679         else
680             v.i_int = 0;
681         if( v.i_int != 0 )
682             input_ControlPush( p_input, INPUT_CONTROL_SET_ES, &v );
683     }
684     else
685     {
686         input_ControlPush( p_input, INPUT_CONTROL_SET_ES, &newval );
687     }
688
689     return VLC_SUCCESS;
690 }
691
692 static int EsDelayCallback ( vlc_object_t *p_this, char const *psz_cmd,
693                              vlc_value_t oldval, vlc_value_t newval, void *p )
694 {
695     input_thread_t *p_input = (input_thread_t*)p_this;
696
697
698     if( !strcmp( psz_cmd, "audio-delay" ) )
699     {
700         /*Change i_pts_delay to make sure es are decoded in time*/
701         if (newval.i_int < 0 || oldval.i_int < 0 )
702         {
703             p_input->i_pts_delay -= newval.i_int - oldval.i_int;
704         }
705         input_ControlPush( p_input, INPUT_CONTROL_SET_AUDIO_DELAY, &newval );
706     }
707     else if( !strcmp( psz_cmd, "spu-delay" ) )
708         input_ControlPush( p_input, INPUT_CONTROL_SET_SPU_DELAY, &newval );
709     return VLC_SUCCESS;
710 }
711
712 static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
713                              vlc_value_t oldval, vlc_value_t newval,
714                              void *p_data )
715 {
716     input_thread_t *p_input = (input_thread_t*)p_this;
717
718     input_ControlPush( p_input, INPUT_CONTROL_SET_BOOKMARK, &newval );
719
720     return VLC_SUCCESS;
721 }