]> git.sesse.net Git - vlc/blob - src/input/var.c
decoder: reorder to avoid forward declation, no functional changes
[vlc] / src / input / var.c
1 /*****************************************************************************
2  * var.c: object variables for input thread
3  *****************************************************************************
4  * Copyright (C) 2004-2007 VLC authors and VideoLAN
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 it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc_common.h>
32 #include <assert.h>
33 #include <math.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36
37 #include "input_internal.h"
38
39 /*****************************************************************************
40  * Callbacks
41  *****************************************************************************/
42 static int StateCallback   ( vlc_object_t *p_this, char const *psz_cmd,
43                              vlc_value_t oldval, vlc_value_t newval, void * );
44 static int RateCallback    ( vlc_object_t *p_this, char const *psz_cmd,
45                              vlc_value_t oldval, vlc_value_t newval, void * );
46 static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
47                              vlc_value_t oldval, vlc_value_t newval, void * );
48 static int TimeCallback    ( vlc_object_t *p_this, char const *psz_cmd,
49                              vlc_value_t oldval, vlc_value_t newval, void * );
50 static int ProgramCallback ( vlc_object_t *p_this, char const *psz_cmd,
51                              vlc_value_t oldval, vlc_value_t newval, void * );
52 static int TitleCallback   ( vlc_object_t *p_this, char const *psz_cmd,
53                              vlc_value_t oldval, vlc_value_t newval, void * );
54 static int SeekpointCallback( vlc_object_t *p_this, char const *psz_cmd,
55                              vlc_value_t oldval, vlc_value_t newval, void * );
56 static int NavigationCallback( vlc_object_t *p_this, char const *psz_cmd,
57                              vlc_value_t oldval, vlc_value_t newval, void * );
58 static int ESCallback      ( vlc_object_t *p_this, char const *psz_cmd,
59                              vlc_value_t oldval, vlc_value_t newval, void * );
60 static int EsDelayCallback ( vlc_object_t *p_this, char const *psz_cmd,
61                              vlc_value_t oldval, vlc_value_t newval, void * );
62
63 static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
64                              vlc_value_t oldval, vlc_value_t newval, void * );
65
66 static int RecordCallback( vlc_object_t *p_this, char const *psz_cmd,
67                            vlc_value_t oldval, vlc_value_t newval,
68                            void *p_data );
69 static int FrameNextCallback( vlc_object_t *p_this, char const *psz_cmd,
70                               vlc_value_t oldval, vlc_value_t newval,
71                               void *p_data );
72
73 typedef struct
74 {
75     const char *psz_name;
76     vlc_callback_t callback;
77 } vlc_input_callback_t;
78
79 static void InputAddCallbacks( input_thread_t *, const vlc_input_callback_t * );
80 static void InputDelCallbacks( input_thread_t *, const vlc_input_callback_t * );
81
82 #ifdef CALLBACK /* For windows */
83 # undef CALLBACK /* We don't care of this one here */
84 #endif
85 /* List all callbacks added by input */
86 #define CALLBACK(name,cb) { name, cb }
87 static const vlc_input_callback_t p_input_callbacks[] =
88 {
89     CALLBACK( "state", StateCallback ),
90     CALLBACK( "rate", RateCallback ),
91     CALLBACK( "position", PositionCallback ),
92     CALLBACK( "position-offset", PositionCallback ),
93     CALLBACK( "time", TimeCallback ),
94     CALLBACK( "time-offset", TimeCallback ),
95     CALLBACK( "bookmark", BookmarkCallback ),
96     CALLBACK( "program", ProgramCallback ),
97     CALLBACK( "title", TitleCallback ),
98     CALLBACK( "chapter", SeekpointCallback ),
99     CALLBACK( "audio-delay", EsDelayCallback ),
100     CALLBACK( "spu-delay", EsDelayCallback ),
101     CALLBACK( "video-es", ESCallback ),
102     CALLBACK( "audio-es", ESCallback ),
103     CALLBACK( "spu-es", ESCallback ),
104     CALLBACK( "record", RecordCallback ),
105     CALLBACK( "frame-next", FrameNextCallback ),
106
107     CALLBACK( NULL, NULL )
108 };
109 static const vlc_input_callback_t p_input_navigation_callbacks[] =
110 {
111     CALLBACK( "next-title", TitleCallback ),
112     CALLBACK( "prev-title", TitleCallback ),
113
114     CALLBACK( NULL, NULL )
115 };
116 static const vlc_input_callback_t p_input_title_callbacks[] =
117 {
118     CALLBACK( "next-chapter", SeekpointCallback ),
119     CALLBACK( "prev-chapter", SeekpointCallback ),
120
121     CALLBACK( NULL, NULL )
122 };
123 #undef CALLBACK
124
125 /*****************************************************************************
126  * input_ControlVarInit:
127  *  Create all control object variables with their callbacks
128  *****************************************************************************/
129 void input_ControlVarInit ( input_thread_t *p_input )
130 {
131     vlc_value_t val, text;
132
133     /* State */
134     var_Create( p_input, "state", VLC_VAR_INTEGER );
135     val.i_int = p_input->p->i_state;
136     var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
137
138     /* Rate */
139     var_Create( p_input, "rate", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
140
141     var_Create( p_input, "frame-next", VLC_VAR_VOID );
142
143     /* Position */
144     var_Create( p_input, "position",  VLC_VAR_FLOAT );
145     var_Create( p_input, "position-offset",  VLC_VAR_FLOAT );
146     val.f_float = 0.0;
147     var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
148
149     /* Time */
150     var_Create( p_input, "time",  VLC_VAR_TIME );
151     var_Create( p_input, "time-offset",  VLC_VAR_TIME );    /* relative */
152     val.i_time = 0;
153     var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
154
155     /* Bookmark */
156     var_Create( p_input, "bookmark", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE |
157                 VLC_VAR_ISCOMMAND );
158     val.psz_string = _("Bookmark");
159     var_Change( p_input, "bookmark", VLC_VAR_SETTEXT, &val, NULL );
160
161     /* Program */
162     var_Create( p_input, "program", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE |
163                 VLC_VAR_DOINHERIT );
164     var_Get( p_input, "program", &val );
165     if( val.i_int <= 0 )
166         var_Change( p_input, "program", VLC_VAR_DELCHOICE, &val, NULL );
167     text.psz_string = _("Program");
168     var_Change( p_input, "program", VLC_VAR_SETTEXT, &text, NULL );
169
170     /* Programs */
171     var_Create( p_input, "programs", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
172     text.psz_string = _("Programs");
173     var_Change( p_input, "programs", VLC_VAR_SETTEXT, &text, NULL );
174
175     /* Title */
176     var_Create( p_input, "title", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
177     text.psz_string = _("Title");
178     var_Change( p_input, "title", VLC_VAR_SETTEXT, &text, NULL );
179
180     /* Chapter */
181     var_Create( p_input, "chapter", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
182     text.psz_string = _("Chapter");
183     var_Change( p_input, "chapter", VLC_VAR_SETTEXT, &text, NULL );
184
185     /* Navigation The callback is added after */
186     var_Create( p_input, "navigation", VLC_VAR_VARIABLE | VLC_VAR_HASCHOICE );
187     text.psz_string = _("Navigation");
188     var_Change( p_input, "navigation", VLC_VAR_SETTEXT, &text, NULL );
189
190     /* Delay */
191     var_Create( p_input, "audio-delay", VLC_VAR_TIME );
192     val.i_time = INT64_C(1000) * var_GetInteger( p_input, "audio-desync" );
193     var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
194     var_Create( p_input, "spu-delay", VLC_VAR_TIME );
195     val.i_time = 0;
196     var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
197
198     /* Video ES */
199     var_Create( p_input, "video-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
200     text.psz_string = _("Video Track");
201     var_Change( p_input, "video-es", VLC_VAR_SETTEXT, &text, NULL );
202
203     /* Audio ES */
204     var_Create( p_input, "audio-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
205     text.psz_string = _("Audio Track");
206     var_Change( p_input, "audio-es", VLC_VAR_SETTEXT, &text, NULL );
207
208     /* Spu ES */
209     var_Create( p_input, "spu-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
210     text.psz_string = _("Subtitle Track");
211     var_Change( p_input, "spu-es", VLC_VAR_SETTEXT, &text, NULL );
212
213     var_Create( p_input, "spu-choice", VLC_VAR_INTEGER );
214     val.i_int = -1;
215     var_Change( p_input, "spu-choice", VLC_VAR_SETVALUE, &val, NULL );
216
217     /* Special read only objects variables for intf */
218     var_Create( p_input, "bookmarks", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
219
220     var_Create( p_input, "length",  VLC_VAR_TIME );
221     val.i_time = 0;
222     var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
223
224     var_Create( p_input, "bit-rate", VLC_VAR_INTEGER );
225     var_Create( p_input, "sample-rate", VLC_VAR_INTEGER );
226
227     if( !p_input->b_preparsing )
228     {
229         /* Special "intf-event" variable. */
230         var_Create( p_input, "intf-event", VLC_VAR_INTEGER );
231     }
232
233     /* Add all callbacks
234      * XXX we put callback only in non preparsing mode. We need to create the variable
235      * unless someone want to check all var_Get/var_Change return value ... */
236     if( !p_input->b_preparsing )
237         InputAddCallbacks( p_input, p_input_callbacks );
238 }
239
240 /*****************************************************************************
241  * input_ControlVarStop:
242  *****************************************************************************/
243 void input_ControlVarStop( input_thread_t *p_input )
244 {
245     if( !p_input->b_preparsing )
246         InputDelCallbacks( p_input, p_input_callbacks );
247
248     if( p_input->p->i_title > 0 )
249     {
250         char name[sizeof("title ") + 5 ];
251         int i;
252
253         InputDelCallbacks( p_input, p_input_navigation_callbacks );
254         InputDelCallbacks( p_input, p_input_title_callbacks );
255
256         for( i = 0; i < p_input->p->i_title; i++ )
257         {
258             snprintf( name, sizeof(name), "title %2i", i );
259             var_DelCallback( p_input, name, NavigationCallback, (void *)(intptr_t)i );
260         }
261     }
262 }
263
264 /*****************************************************************************
265  * input_ControlVarNavigation:
266  *  Create all remaining control object variables
267  *****************************************************************************/
268 void input_ControlVarNavigation( input_thread_t *p_input )
269 {
270     vlc_value_t val, text;
271     int  i;
272
273     /* Create more command variables */
274     if( p_input->p->i_title > 1 )
275     {
276         var_Create( p_input, "next-title", VLC_VAR_VOID );
277         text.psz_string = _("Next title");
278         var_Change( p_input, "next-title", VLC_VAR_SETTEXT, &text, NULL );
279         var_AddCallback( p_input, "next-title", TitleCallback, NULL );
280
281         var_Create( p_input, "prev-title", VLC_VAR_VOID );
282         text.psz_string = _("Previous title");
283         var_Change( p_input, "prev-title", VLC_VAR_SETTEXT, &text, NULL );
284         var_AddCallback( p_input, "prev-title", TitleCallback, NULL );
285     }
286
287     /* Create title and navigation */
288     val.psz_string = malloc( sizeof("title ") + 5 );
289     if( !val.psz_string )
290         return;
291
292     var_Change( p_input, "title", VLC_VAR_CLEARCHOICES, NULL, NULL );
293
294     for( i = 0; i < p_input->p->i_title; i++ )
295     {
296         vlc_value_t val2, text2;
297         int j;
298
299         /* Add Navigation entries */
300         sprintf( val.psz_string,  "title %2i", i );
301         var_Destroy( p_input, val.psz_string );
302         var_Create( p_input, val.psz_string,
303                     VLC_VAR_INTEGER|VLC_VAR_HASCHOICE|VLC_VAR_ISCOMMAND );
304         var_AddCallback( p_input, val.psz_string,
305                          NavigationCallback, (void *)(intptr_t)i );
306
307         char psz_length[MSTRTIME_MAX_SIZE + sizeof(" []")] = "";
308         if( p_input->p->title[i]->i_length > 0 )
309         {
310             strcpy( psz_length, " [" );
311             secstotimestr( &psz_length[2], p_input->p->title[i]->i_length / CLOCK_FREQ );
312             strcat( psz_length, "]" );
313         }
314
315         if( p_input->p->title[i]->psz_name == NULL ||
316             *p_input->p->title[i]->psz_name == '\0' )
317         {
318             if( asprintf( &text.psz_string, _("Title %i%s"),
319                           i + p_input->p->i_title_offset, psz_length ) == -1 )
320                 continue;
321         }
322         else
323         {
324             if( asprintf( &text.psz_string, "%s%s",
325                           p_input->p->title[i]->psz_name, psz_length ) == -1 )
326                 continue;
327         }
328         var_Change( p_input, "navigation", VLC_VAR_ADDCHOICE, &val, &text );
329
330         /* Add title choice */
331         val2.i_int = i;
332         var_Change( p_input, "title", VLC_VAR_ADDCHOICE, &val2, &text );
333
334         free( text.psz_string );
335
336         for( j = 0; j < p_input->p->title[i]->i_seekpoint; j++ )
337         {
338             val2.i_int = j;
339
340             if( p_input->p->title[i]->seekpoint[j]->psz_name == NULL ||
341                 *p_input->p->title[i]->seekpoint[j]->psz_name == '\0' )
342             {
343                 /* Default value */
344                 if( asprintf( &text2.psz_string, _("Chapter %i"),
345                           j + p_input->p->i_seekpoint_offset ) == -1 )
346                     continue;
347             }
348             else
349             {
350                 text2.psz_string =
351                     strdup( p_input->p->title[i]->seekpoint[j]->psz_name );
352             }
353
354             var_Change( p_input, val.psz_string, VLC_VAR_ADDCHOICE,
355                         &val2, &text2 );
356             free( text2.psz_string );
357         }
358
359     }
360     free( val.psz_string );
361 }
362
363 /*****************************************************************************
364  * input_ControlVarTitle:
365  *  Create all variables for a title
366  *****************************************************************************/
367 void input_ControlVarTitle( input_thread_t *p_input, int i_title )
368 {
369     input_title_t *t = p_input->p->title[i_title];
370     vlc_value_t text;
371     int  i;
372
373     /* Create/Destroy command variables */
374     if( t->i_seekpoint <= 1 )
375     {
376         var_Destroy( p_input, "next-chapter" );
377         var_Destroy( p_input, "prev-chapter" );
378     }
379     else if( var_Type( p_input, "next-chapter" ) == 0 )
380     {
381         var_Create( p_input, "next-chapter", VLC_VAR_VOID );
382         text.psz_string = _("Next chapter");
383         var_Change( p_input, "next-chapter", VLC_VAR_SETTEXT, &text, NULL );
384         var_AddCallback( p_input, "next-chapter", SeekpointCallback, NULL );
385
386         var_Create( p_input, "prev-chapter", VLC_VAR_VOID );
387         text.psz_string = _("Previous chapter");
388         var_Change( p_input, "prev-chapter", VLC_VAR_SETTEXT, &text, NULL );
389         var_AddCallback( p_input, "prev-chapter", SeekpointCallback, NULL );
390     }
391
392     /* Build chapter list */
393     var_Change( p_input, "chapter", VLC_VAR_CLEARCHOICES, NULL, NULL );
394     for( i = 0; i <  t->i_seekpoint; i++ )
395     {
396         vlc_value_t val;
397         val.i_int = i;
398
399         if( t->seekpoint[i]->psz_name == NULL ||
400             *t->seekpoint[i]->psz_name == '\0' )
401         {
402             /* Default value */
403             if( asprintf( &text.psz_string, _("Chapter %i"),
404                       i + p_input->p->i_seekpoint_offset ) == -1 )
405                 continue;
406         }
407         else
408         {
409             text.psz_string = strdup( t->seekpoint[i]->psz_name );
410         }
411
412         var_Change( p_input, "chapter", VLC_VAR_ADDCHOICE, &val, &text );
413         free( text.psz_string );
414     }
415 }
416
417 /*****************************************************************************
418  * input_ConfigVarInit:
419  *  Create all config object variables
420  *****************************************************************************/
421 void input_ConfigVarInit ( input_thread_t *p_input )
422 {
423     /* Create Object Variables for private use only */
424
425     if( !p_input->b_preparsing )
426     {
427         var_Create( p_input, "video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
428         var_Create( p_input, "audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
429         var_Create( p_input, "spu", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
430
431         var_Create( p_input, "audio-track", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
432         var_Create( p_input, "sub-track", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
433
434         var_Create( p_input, "audio-language",
435                     VLC_VAR_STRING|VLC_VAR_DOINHERIT );
436         var_Create( p_input, "sub-language",
437                     VLC_VAR_STRING|VLC_VAR_DOINHERIT );
438         var_Create( p_input, "menu-language",
439                     VLC_VAR_STRING|VLC_VAR_DOINHERIT );
440
441         var_Create( p_input, "audio-track-id",
442                     VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
443         var_Create( p_input, "sub-track-id",
444                     VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
445
446         var_Create( p_input, "sub-file", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
447         var_Create( p_input, "sub-autodetect-file", VLC_VAR_BOOL |
448                     VLC_VAR_DOINHERIT );
449         var_Create( p_input, "sub-autodetect-path", VLC_VAR_STRING |
450                     VLC_VAR_DOINHERIT );
451         var_Create( p_input, "sub-autodetect-fuzzy", VLC_VAR_INTEGER |
452                     VLC_VAR_DOINHERIT );
453
454         var_Create( p_input, "sout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
455         var_Create( p_input, "sout-all",   VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
456         var_Create( p_input, "sout-audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
457         var_Create( p_input, "sout-video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
458         var_Create( p_input, "sout-spu", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
459         var_Create( p_input, "sout-keep",  VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
460
461         var_Create( p_input, "input-repeat",
462                     VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
463         var_Create( p_input, "start-time", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT );
464         var_Create( p_input, "stop-time", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT );
465         var_Create( p_input, "run-time", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT );
466         var_Create( p_input, "input-fast-seek", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
467
468         var_Create( p_input, "input-slave",
469                     VLC_VAR_STRING | VLC_VAR_DOINHERIT );
470
471         var_Create( p_input, "audio-desync",
472                     VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
473         var_Create( p_input, "cr-average",
474                     VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
475         var_Create( p_input, "clock-synchro",
476                     VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
477     }
478
479     var_Create( p_input, "can-seek", VLC_VAR_BOOL );
480     var_SetBool( p_input, "can-seek", true ); /* Fixed later*/
481
482     var_Create( p_input, "can-pause", VLC_VAR_BOOL );
483     var_SetBool( p_input, "can-pause", true ); /* Fixed later*/
484
485     var_Create( p_input, "can-rate", VLC_VAR_BOOL );
486     var_SetBool( p_input, "can-rate", false );
487
488     var_Create( p_input, "can-rewind", VLC_VAR_BOOL );
489     var_SetBool( p_input, "can-rewind", false );
490
491     var_Create( p_input, "can-record", VLC_VAR_BOOL );
492     var_SetBool( p_input, "can-record", false ); /* Fixed later*/
493
494     var_Create( p_input, "record", VLC_VAR_BOOL );
495     var_SetBool( p_input, "record", false );
496
497     var_Create( p_input, "teletext-es", VLC_VAR_INTEGER );
498     var_SetInteger( p_input, "teletext-es", -1 );
499
500     var_Create( p_input, "signal-quality", VLC_VAR_FLOAT );
501     var_SetFloat( p_input, "signal-quality", -1 );
502
503     var_Create( p_input, "signal-strength", VLC_VAR_FLOAT );
504     var_SetFloat( p_input, "signal-strength", -1 );
505
506     var_Create( p_input, "program-scrambled", VLC_VAR_BOOL );
507     var_SetBool( p_input, "program-scrambled", false );
508
509     var_Create( p_input, "cache", VLC_VAR_FLOAT );
510     var_SetFloat( p_input, "cache", 0.0 );
511
512     /* */
513     var_Create( p_input, "input-record-native", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
514
515     /* */
516     var_Create( p_input, "access", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
517     var_Create( p_input, "demux", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
518     var_Create( p_input, "stream-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
519
520     /* Meta */
521     var_Create( p_input, "meta-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
522     var_Create( p_input, "meta-author", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
523     var_Create( p_input, "meta-artist", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
524     var_Create( p_input, "meta-genre", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
525     var_Create( p_input, "meta-copyright", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
526     var_Create( p_input, "meta-description", VLC_VAR_STRING|VLC_VAR_DOINHERIT);
527     var_Create( p_input, "meta-date", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
528     var_Create( p_input, "meta-url", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
529 }
530
531 /*****************************************************************************
532  * Callbacks managements:
533  *****************************************************************************/
534 static void InputAddCallbacks( input_thread_t *p_input,
535                                const vlc_input_callback_t *p_callbacks )
536 {
537     int i;
538     for( i = 0; p_callbacks[i].psz_name != NULL; i++ )
539         var_AddCallback( p_input,
540                          p_callbacks[i].psz_name,
541                          p_callbacks[i].callback, NULL );
542 }
543
544 static void InputDelCallbacks( input_thread_t *p_input,
545                                const vlc_input_callback_t *p_callbacks )
546 {
547     int i;
548     for( i = 0; p_callbacks[i].psz_name != NULL; i++ )
549         var_DelCallback( p_input,
550                          p_callbacks[i].psz_name,
551                          p_callbacks[i].callback, NULL );
552 }
553
554 /*****************************************************************************
555  * All Callbacks:
556  *****************************************************************************/
557 static int StateCallback( vlc_object_t *p_this, char const *psz_cmd,
558                           vlc_value_t oldval, vlc_value_t newval,
559                           void *p_data )
560 {
561     input_thread_t *p_input = (input_thread_t*)p_this;
562     VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
563
564     if( newval.i_int == PLAYING_S || newval.i_int == PAUSE_S )
565     {
566         input_ControlPush( p_input, INPUT_CONTROL_SET_STATE, &newval );
567         return VLC_SUCCESS;
568     }
569
570     return VLC_EGENERIC;
571 }
572
573 static int RateCallback( vlc_object_t *p_this, char const *psz_cmd,
574                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
575 {
576     input_thread_t *p_input = (input_thread_t*)p_this;
577     VLC_UNUSED(oldval); VLC_UNUSED(p_data); VLC_UNUSED(psz_cmd);
578
579     newval.i_int = INPUT_RATE_DEFAULT / newval.f_float;
580     input_ControlPush( p_input, INPUT_CONTROL_SET_RATE, &newval );
581
582     return VLC_SUCCESS;
583 }
584
585 static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
586                              vlc_value_t oldval, vlc_value_t newval,
587                              void *p_data )
588 {
589     input_thread_t *p_input = (input_thread_t*)p_this;
590     VLC_UNUSED(oldval); VLC_UNUSED(p_data);
591
592     if( !strcmp( psz_cmd, "position-offset" ) )
593     {
594         float f_position = var_GetFloat( p_input, "position" ) + newval.f_float;
595         if( f_position < 0.f )
596             f_position = 0.f;
597         else if( f_position > 1.f )
598             f_position = 1.f;
599         var_SetFloat( p_this, "position", f_position );
600     }
601     else
602     {
603         /* Update "length" for better intf behavour */
604         const mtime_t i_length = var_GetTime( p_input, "length" );
605         if( i_length > 0 && newval.f_float >= 0.f && newval.f_float <= 1.f )
606         {
607             vlc_value_t val;
608
609             val.i_time = i_length * newval.f_float;
610             var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
611         }
612
613         /* */
614         input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &newval );
615     }
616     return VLC_SUCCESS;
617 }
618
619 static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
620                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
621 {
622     input_thread_t *p_input = (input_thread_t*)p_this;
623     VLC_UNUSED(oldval); VLC_UNUSED(p_data);
624
625     if( !strcmp( psz_cmd, "time-offset" ) )
626     {
627         mtime_t i_time = var_GetTime( p_input, "time" ) + newval.i_time;
628         if( i_time < 0 )
629             i_time = 0;
630         var_SetTime( p_this, "time", i_time );
631     }
632     else
633     {
634         /* Update "position" for better intf behavour */
635         const mtime_t i_length = var_GetTime( p_input, "length" );
636         if( i_length > 0 && newval.i_time >= 0 && newval.i_time <= i_length )
637         {
638             vlc_value_t val;
639
640             val.f_float = (double)newval.i_time/(double)i_length;
641             var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
642             /*
643              * Notify the intf that a new event has been occurred.
644              * XXX this is a bit hackish but it's the only way to do it now.
645              */
646             var_SetInteger( p_input, "intf-event", INPUT_EVENT_POSITION );
647         }
648
649         /* */
650         input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval );
651     }
652     return VLC_SUCCESS;
653 }
654
655 static int ProgramCallback( vlc_object_t *p_this, char const *psz_cmd,
656                             vlc_value_t oldval, vlc_value_t newval,
657                             void *p_data )
658 {
659     input_thread_t *p_input = (input_thread_t*)p_this;
660     VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
661
662     input_ControlPush( p_input, INPUT_CONTROL_SET_PROGRAM, &newval );
663
664     return VLC_SUCCESS;
665 }
666
667 static int TitleCallback( vlc_object_t *p_this, char const *psz_cmd,
668                           vlc_value_t oldval, vlc_value_t newval,
669                           void *p_data )
670 {
671     input_thread_t *p_input = (input_thread_t*)p_this;
672     vlc_value_t val, count;
673     VLC_UNUSED(oldval); VLC_UNUSED(p_data);
674
675     if( !strcmp( psz_cmd, "next-title" ) )
676     {
677         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE_NEXT, NULL );
678
679         val.i_int = var_GetInteger( p_input, "title" ) + 1;
680         var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &count, NULL );
681         if( val.i_int < count.i_int )
682             var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
683     }
684     else if( !strcmp( psz_cmd, "prev-title" ) )
685     {
686         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE_PREV, NULL );
687
688         val.i_int = var_GetInteger( p_input, "title" ) - 1;
689         if( val.i_int >= 0 )
690             var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
691     }
692     else
693     {
694         input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &newval );
695     }
696
697     return VLC_SUCCESS;
698 }
699
700 static int SeekpointCallback( vlc_object_t *p_this, char const *psz_cmd,
701                               vlc_value_t oldval, vlc_value_t newval,
702                               void *p_data )
703 {
704     input_thread_t *p_input = (input_thread_t*)p_this;
705     vlc_value_t val, count;
706     VLC_UNUSED(oldval); VLC_UNUSED(p_data);
707
708     if( !strcmp( psz_cmd, "next-chapter" ) )
709     {
710         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT_NEXT, NULL );
711
712         val.i_int = var_GetInteger( p_input, "chapter" ) + 1;
713         var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &count, NULL );
714         if( val.i_int < count.i_int )
715             var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
716     }
717     else if( !strcmp( psz_cmd, "prev-chapter" ) )
718     {
719         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT_PREV, NULL );
720
721         val.i_int = var_GetInteger( p_input, "chapter" ) - 1;
722         if( val.i_int >= 0 )
723             var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
724     }
725     else
726     {
727         input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &newval );
728     }
729
730     return VLC_SUCCESS;
731 }
732
733 static int NavigationCallback( vlc_object_t *p_this, char const *psz_cmd,
734                                vlc_value_t oldval, vlc_value_t newval,
735                                void *p_data )
736 {
737     input_thread_t *p_input = (input_thread_t*)p_this;
738     vlc_value_t     val;
739     VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
740
741     /* Issue a title change */
742     val.i_int = (intptr_t)p_data;
743     input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
744
745     var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
746
747     /* And a chapter change */
748     input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &newval );
749
750     var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &newval, NULL );
751
752     return VLC_SUCCESS;
753 }
754
755 static int ESCallback( vlc_object_t *p_this, char const *psz_cmd,
756                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
757 {
758     input_thread_t *p_input = (input_thread_t*)p_this;
759     VLC_UNUSED(oldval); VLC_UNUSED(p_data);
760
761     if( newval.i_int < 0 )
762     {
763         vlc_value_t v;
764         /* Hack */
765         if( !strcmp( psz_cmd, "audio-es" ) )
766             v.i_int = -AUDIO_ES;
767         else if( !strcmp( psz_cmd, "video-es" ) )
768             v.i_int = -VIDEO_ES;
769         else if( !strcmp( psz_cmd, "spu-es" ) )
770             v.i_int = -SPU_ES;
771         else
772             v.i_int = 0;
773         if( v.i_int != 0 )
774             input_ControlPush( p_input, INPUT_CONTROL_SET_ES, &v );
775     }
776     else
777     {
778         input_ControlPush( p_input, INPUT_CONTROL_SET_ES, &newval );
779     }
780
781     return VLC_SUCCESS;
782 }
783
784 static int EsDelayCallback ( vlc_object_t *p_this, char const *psz_cmd,
785                              vlc_value_t oldval, vlc_value_t newval, void *p_data )
786 {
787     input_thread_t *p_input = (input_thread_t*)p_this;
788     VLC_UNUSED(oldval); VLC_UNUSED(p_data);
789
790     if( !strcmp( psz_cmd, "audio-delay" ) )
791     {
792         input_ControlPush( p_input, INPUT_CONTROL_SET_AUDIO_DELAY, &newval );
793     }
794     else if( !strcmp( psz_cmd, "spu-delay" ) )
795     {
796         input_ControlPush( p_input, INPUT_CONTROL_SET_SPU_DELAY, &newval );
797     }
798     return VLC_SUCCESS;
799 }
800
801 static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
802                              vlc_value_t oldval, vlc_value_t newval,
803                              void *p_data )
804 {
805     input_thread_t *p_input = (input_thread_t*)p_this;
806     VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
807
808     input_ControlPush( p_input, INPUT_CONTROL_SET_BOOKMARK, &newval );
809
810     return VLC_SUCCESS;
811 }
812
813 static int RecordCallback( vlc_object_t *p_this, char const *psz_cmd,
814                            vlc_value_t oldval, vlc_value_t newval,
815                            void *p_data )
816 {
817     input_thread_t *p_input = (input_thread_t*)p_this;
818     VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
819
820     input_ControlPush( p_input, INPUT_CONTROL_SET_RECORD_STATE, &newval );
821
822     return VLC_SUCCESS;
823 }
824
825 static int FrameNextCallback( vlc_object_t *p_this, char const *psz_cmd,
826                               vlc_value_t oldval, vlc_value_t newval,
827                               void *p_data )
828 {
829     input_thread_t *p_input = (input_thread_t*)p_this;
830     VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
831     VLC_UNUSED(newval);
832
833     input_ControlPush( p_input, INPUT_CONTROL_SET_FRAME_NEXT, NULL );
834
835     return VLC_SUCCESS;
836 }
837