Compat: relicense vasprintf, strlcpy and localtime_r to LGPL
[vlc.git] / src / input / var.c
blobf1fbc3cb58b9bff2ac36d99c94d86a1c3bfb02a4
1 /*****************************************************************************
2 * var.c: object variables for input thread
3 *****************************************************************************
4 * Copyright (C) 2004-2007 the VideoLAN team
5 * $Id$
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc_common.h>
32 #include <assert.h>
33 #include <math.h>
34 #include <stdio.h>
35 #include <stdlib.h>
37 #include "input_internal.h"
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 * );
63 static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
64 vlc_value_t oldval, vlc_value_t newval, void * );
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 );
73 typedef struct
75 const char *psz_name;
76 vlc_callback_t callback;
77 } vlc_input_callback_t;
79 static void InputAddCallbacks( input_thread_t *, const vlc_input_callback_t * );
80 static void InputDelCallbacks( input_thread_t *, const vlc_input_callback_t * );
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[] =
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 ),
107 CALLBACK( NULL, NULL )
109 static const vlc_input_callback_t p_input_navigation_callbacks[] =
111 CALLBACK( "next-title", TitleCallback ),
112 CALLBACK( "prev-title", TitleCallback ),
114 CALLBACK( NULL, NULL )
116 static const vlc_input_callback_t p_input_title_callbacks[] =
118 CALLBACK( "next-chapter", SeekpointCallback ),
119 CALLBACK( "prev-chapter", SeekpointCallback ),
121 CALLBACK( NULL, NULL )
123 #undef CALLBACK
125 /*****************************************************************************
126 * input_ControlVarInit:
127 * Create all control object variables with their callbacks
128 *****************************************************************************/
129 void input_ControlVarInit ( input_thread_t *p_input )
131 vlc_value_t val, text;
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 );
138 /* Rate */
139 var_Create( p_input, "rate", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
141 var_Create( p_input, "frame-next", VLC_VAR_VOID );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
208 /* Spu ES */
209 var_Create( p_input, "spu-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
210 text.psz_string = _("Subtitles Track");
211 var_Change( p_input, "spu-es", VLC_VAR_SETTEXT, &text, NULL );
213 /* Special read only objects variables for intf */
214 var_Create( p_input, "bookmarks", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
216 var_Create( p_input, "length", VLC_VAR_TIME );
217 val.i_time = 0;
218 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
220 var_Create( p_input, "bit-rate", VLC_VAR_INTEGER );
221 var_Create( p_input, "sample-rate", VLC_VAR_INTEGER );
223 if( !p_input->b_preparsing )
225 /* Special "intf-event" variable. */
226 var_Create( p_input, "intf-event", VLC_VAR_INTEGER );
229 /* Add all callbacks
230 * XXX we put callback only in non preparsing mode. We need to create the variable
231 * unless someone want to check all var_Get/var_Change return value ... */
232 if( !p_input->b_preparsing )
233 InputAddCallbacks( p_input, p_input_callbacks );
236 /*****************************************************************************
237 * input_ControlVarStop:
238 *****************************************************************************/
239 void input_ControlVarStop( input_thread_t *p_input )
241 if( !p_input->b_preparsing )
242 InputDelCallbacks( p_input, p_input_callbacks );
244 if( p_input->p->i_title > 0 )
246 char name[sizeof("title ") + 5 ];
247 int i;
249 InputDelCallbacks( p_input, p_input_navigation_callbacks );
250 InputDelCallbacks( p_input, p_input_title_callbacks );
252 for( i = 0; i < p_input->p->i_title; i++ )
254 snprintf( name, sizeof(name), "title %2i", i );
255 var_DelCallback( p_input, name, NavigationCallback, (void *)(intptr_t)i );
260 /*****************************************************************************
261 * input_ControlVarNavigation:
262 * Create all remaining control object variables
263 *****************************************************************************/
264 void input_ControlVarNavigation( input_thread_t *p_input )
266 vlc_value_t val, text;
267 int i;
269 /* Create more command variables */
270 if( p_input->p->i_title > 1 )
272 var_Create( p_input, "next-title", VLC_VAR_VOID );
273 text.psz_string = _("Next title");
274 var_Change( p_input, "next-title", VLC_VAR_SETTEXT, &text, NULL );
275 var_AddCallback( p_input, "next-title", TitleCallback, NULL );
277 var_Create( p_input, "prev-title", VLC_VAR_VOID );
278 text.psz_string = _("Previous title");
279 var_Change( p_input, "prev-title", VLC_VAR_SETTEXT, &text, NULL );
280 var_AddCallback( p_input, "prev-title", TitleCallback, NULL );
283 /* Create title and navigation */
284 val.psz_string = malloc( sizeof("title ") + 5 );
285 if( !val.psz_string )
286 return;
288 for( i = 0; i < p_input->p->i_title; i++ )
290 vlc_value_t val2, text2;
291 int j;
293 /* Add Navigation entries */
294 sprintf( val.psz_string, "title %2i", i );
295 var_Destroy( p_input, val.psz_string );
296 var_Create( p_input, val.psz_string,
297 VLC_VAR_INTEGER|VLC_VAR_HASCHOICE|VLC_VAR_ISCOMMAND );
298 var_AddCallback( p_input, val.psz_string,
299 NavigationCallback, (void *)(intptr_t)i );
301 char psz_length[MSTRTIME_MAX_SIZE + sizeof(" []")] = "";
302 if( p_input->p->title[i]->i_length > 0 )
304 strcpy( psz_length, " [" );
305 secstotimestr( &psz_length[2], p_input->p->title[i]->i_length / CLOCK_FREQ );
306 strcat( psz_length, "]" );
309 if( p_input->p->title[i]->psz_name == NULL ||
310 *p_input->p->title[i]->psz_name == '\0' )
312 if( asprintf( &text.psz_string, _("Title %i%s"),
313 i + p_input->p->i_title_offset, psz_length ) == -1 )
314 continue;
316 else
318 if( asprintf( &text.psz_string, "%s%s",
319 p_input->p->title[i]->psz_name, psz_length ) == -1 )
320 continue;
322 var_Change( p_input, "navigation", VLC_VAR_ADDCHOICE, &val, &text );
324 /* Add title choice */
325 val2.i_int = i;
326 var_Change( p_input, "title", VLC_VAR_ADDCHOICE, &val2, &text );
328 free( text.psz_string );
330 for( j = 0; j < p_input->p->title[i]->i_seekpoint; j++ )
332 val2.i_int = j;
334 if( p_input->p->title[i]->seekpoint[j]->psz_name == NULL ||
335 *p_input->p->title[i]->seekpoint[j]->psz_name == '\0' )
337 /* Default value */
338 if( asprintf( &text2.psz_string, _("Chapter %i"),
339 j + p_input->p->i_seekpoint_offset ) == -1 )
340 continue;
342 else
344 text2.psz_string =
345 strdup( p_input->p->title[i]->seekpoint[j]->psz_name );
348 var_Change( p_input, val.psz_string, VLC_VAR_ADDCHOICE,
349 &val2, &text2 );
350 free( text2.psz_string );
354 free( val.psz_string );
357 /*****************************************************************************
358 * input_ControlVarTitle:
359 * Create all variables for a title
360 *****************************************************************************/
361 void input_ControlVarTitle( input_thread_t *p_input, int i_title )
363 input_title_t *t = p_input->p->title[i_title];
364 vlc_value_t text;
365 int i;
367 /* Create/Destroy command variables */
368 if( t->i_seekpoint <= 1 )
370 var_Destroy( p_input, "next-chapter" );
371 var_Destroy( p_input, "prev-chapter" );
373 else if( var_Type( p_input, "next-chapter" ) == 0 )
375 var_Create( p_input, "next-chapter", VLC_VAR_VOID );
376 text.psz_string = _("Next chapter");
377 var_Change( p_input, "next-chapter", VLC_VAR_SETTEXT, &text, NULL );
378 var_AddCallback( p_input, "next-chapter", SeekpointCallback, NULL );
380 var_Create( p_input, "prev-chapter", VLC_VAR_VOID );
381 text.psz_string = _("Previous chapter");
382 var_Change( p_input, "prev-chapter", VLC_VAR_SETTEXT, &text, NULL );
383 var_AddCallback( p_input, "prev-chapter", SeekpointCallback, NULL );
386 /* Build chapter list */
387 var_Change( p_input, "chapter", VLC_VAR_CLEARCHOICES, NULL, NULL );
388 for( i = 0; i < t->i_seekpoint; i++ )
390 vlc_value_t val;
391 val.i_int = i;
393 if( t->seekpoint[i]->psz_name == NULL ||
394 *t->seekpoint[i]->psz_name == '\0' )
396 /* Default value */
397 if( asprintf( &text.psz_string, _("Chapter %i"),
398 i + p_input->p->i_seekpoint_offset ) == -1 )
399 continue;
401 else
403 text.psz_string = strdup( t->seekpoint[i]->psz_name );
406 var_Change( p_input, "chapter", VLC_VAR_ADDCHOICE, &val, &text );
407 free( text.psz_string );
411 /*****************************************************************************
412 * input_ConfigVarInit:
413 * Create all config object variables
414 *****************************************************************************/
415 void input_ConfigVarInit ( input_thread_t *p_input )
417 /* Create Object Variables for private use only */
419 if( !p_input->b_preparsing )
421 var_Create( p_input, "video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
422 var_Create( p_input, "audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
423 var_Create( p_input, "spu", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
425 var_Create( p_input, "audio-track", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
426 var_Create( p_input, "sub-track", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
428 var_Create( p_input, "audio-language",
429 VLC_VAR_STRING|VLC_VAR_DOINHERIT );
430 var_Create( p_input, "sub-language",
431 VLC_VAR_STRING|VLC_VAR_DOINHERIT );
433 var_Create( p_input, "audio-track-id",
434 VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
435 var_Create( p_input, "sub-track-id",
436 VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
438 var_Create( p_input, "sub-file", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
439 var_Create( p_input, "sub-autodetect-file", VLC_VAR_BOOL |
440 VLC_VAR_DOINHERIT );
441 var_Create( p_input, "sub-autodetect-path", VLC_VAR_STRING |
442 VLC_VAR_DOINHERIT );
443 var_Create( p_input, "sub-autodetect-fuzzy", VLC_VAR_INTEGER |
444 VLC_VAR_DOINHERIT );
446 var_Create( p_input, "sout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
447 var_Create( p_input, "sout-all", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
448 var_Create( p_input, "sout-audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
449 var_Create( p_input, "sout-video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
450 var_Create( p_input, "sout-spu", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
451 var_Create( p_input, "sout-keep", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
453 var_Create( p_input, "input-repeat",
454 VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
455 var_Create( p_input, "start-time", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT );
456 var_Create( p_input, "stop-time", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT );
457 var_Create( p_input, "run-time", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT );
458 var_Create( p_input, "input-fast-seek", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
460 var_Create( p_input, "input-slave",
461 VLC_VAR_STRING | VLC_VAR_DOINHERIT );
463 var_Create( p_input, "audio-desync",
464 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
465 var_Create( p_input, "cr-average",
466 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
467 var_Create( p_input, "clock-synchro",
468 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
471 var_Create( p_input, "can-seek", VLC_VAR_BOOL );
472 var_SetBool( p_input, "can-seek", true ); /* Fixed later*/
474 var_Create( p_input, "can-pause", VLC_VAR_BOOL );
475 var_SetBool( p_input, "can-pause", true ); /* Fixed later*/
477 var_Create( p_input, "can-rate", VLC_VAR_BOOL );
478 var_SetBool( p_input, "can-rate", false );
480 var_Create( p_input, "can-rewind", VLC_VAR_BOOL );
481 var_SetBool( p_input, "can-rewind", false );
483 var_Create( p_input, "can-record", VLC_VAR_BOOL );
484 var_SetBool( p_input, "can-record", false ); /* Fixed later*/
486 var_Create( p_input, "record", VLC_VAR_BOOL );
487 var_SetBool( p_input, "record", false );
489 var_Create( p_input, "teletext-es", VLC_VAR_INTEGER );
490 var_SetInteger( p_input, "teletext-es", -1 );
492 var_Create( p_input, "signal-quality", VLC_VAR_FLOAT );
493 var_SetFloat( p_input, "signal-quality", -1 );
495 var_Create( p_input, "signal-strength", VLC_VAR_FLOAT );
496 var_SetFloat( p_input, "signal-strength", -1 );
498 var_Create( p_input, "program-scrambled", VLC_VAR_BOOL );
499 var_SetBool( p_input, "program-scrambled", false );
501 var_Create( p_input, "cache", VLC_VAR_FLOAT );
502 var_SetFloat( p_input, "cache", 0.0 );
504 /* */
505 var_Create( p_input, "input-record-native", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
507 /* */
508 var_Create( p_input, "access", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
509 var_Create( p_input, "demux", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
510 var_Create( p_input, "stream-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
512 /* Meta */
513 var_Create( p_input, "meta-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
514 var_Create( p_input, "meta-author", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
515 var_Create( p_input, "meta-artist", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
516 var_Create( p_input, "meta-genre", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
517 var_Create( p_input, "meta-copyright", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
518 var_Create( p_input, "meta-description", VLC_VAR_STRING|VLC_VAR_DOINHERIT);
519 var_Create( p_input, "meta-date", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
520 var_Create( p_input, "meta-url", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
523 /*****************************************************************************
524 * Callbacks managements:
525 *****************************************************************************/
526 static void InputAddCallbacks( input_thread_t *p_input,
527 const vlc_input_callback_t *p_callbacks )
529 int i;
530 for( i = 0; p_callbacks[i].psz_name != NULL; i++ )
531 var_AddCallback( p_input,
532 p_callbacks[i].psz_name,
533 p_callbacks[i].callback, NULL );
536 static void InputDelCallbacks( input_thread_t *p_input,
537 const vlc_input_callback_t *p_callbacks )
539 int i;
540 for( i = 0; p_callbacks[i].psz_name != NULL; i++ )
541 var_DelCallback( p_input,
542 p_callbacks[i].psz_name,
543 p_callbacks[i].callback, NULL );
546 /*****************************************************************************
547 * All Callbacks:
548 *****************************************************************************/
549 static int StateCallback( vlc_object_t *p_this, char const *psz_cmd,
550 vlc_value_t oldval, vlc_value_t newval,
551 void *p_data )
553 input_thread_t *p_input = (input_thread_t*)p_this;
554 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
556 if( newval.i_int == PLAYING_S || newval.i_int == PAUSE_S )
558 input_ControlPush( p_input, INPUT_CONTROL_SET_STATE, &newval );
559 return VLC_SUCCESS;
562 return VLC_EGENERIC;
565 static int RateCallback( vlc_object_t *p_this, char const *psz_cmd,
566 vlc_value_t oldval, vlc_value_t newval, void *p_data )
568 input_thread_t *p_input = (input_thread_t*)p_this;
569 VLC_UNUSED(oldval); VLC_UNUSED(p_data); VLC_UNUSED(psz_cmd);
571 newval.i_int = INPUT_RATE_DEFAULT / newval.f_float;
572 input_ControlPush( p_input, INPUT_CONTROL_SET_RATE, &newval );
574 return VLC_SUCCESS;
577 static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
578 vlc_value_t oldval, vlc_value_t newval,
579 void *p_data )
581 input_thread_t *p_input = (input_thread_t*)p_this;
582 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
584 if( !strcmp( psz_cmd, "position-offset" ) )
586 float f_position = var_GetFloat( p_input, "position" ) + newval.f_float;
587 if( f_position < 0.0 )
588 f_position = 0.0;
589 else if( f_position > 1.0 )
590 f_position = 1.0;
591 var_SetFloat( p_this, "position", f_position );
593 else
595 /* Update "length" for better intf behavour */
596 const mtime_t i_length = var_GetTime( p_input, "length" );
597 if( i_length > 0 && newval.f_float >= 0.0 && newval.f_float <= 1.0 )
599 vlc_value_t val;
601 val.i_time = i_length * newval.f_float;
602 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
605 /* */
606 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &newval );
608 return VLC_SUCCESS;
611 static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
612 vlc_value_t oldval, vlc_value_t newval, void *p_data )
614 input_thread_t *p_input = (input_thread_t*)p_this;
615 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
617 if( !strcmp( psz_cmd, "time-offset" ) )
619 mtime_t i_time = var_GetTime( p_input, "time" ) + newval.i_time;
620 if( i_time < 0 )
621 i_time = 0;
622 var_SetTime( p_this, "time", i_time );
624 else
626 /* Update "position" for better intf behavour */
627 const mtime_t i_length = var_GetTime( p_input, "length" );
628 if( i_length > 0 && newval.i_time >= 0 && newval.i_time <= i_length )
630 vlc_value_t val;
632 val.f_float = (double)newval.i_time/(double)i_length;
633 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
635 * Notify the intf that a new event has been occurred.
636 * XXX this is a bit hackish but it's the only way to do it now.
638 var_SetInteger( p_input, "intf-event", INPUT_EVENT_POSITION );
641 /* */
642 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval );
644 return VLC_SUCCESS;
647 static int ProgramCallback( vlc_object_t *p_this, char const *psz_cmd,
648 vlc_value_t oldval, vlc_value_t newval,
649 void *p_data )
651 input_thread_t *p_input = (input_thread_t*)p_this;
652 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
654 input_ControlPush( p_input, INPUT_CONTROL_SET_PROGRAM, &newval );
656 return VLC_SUCCESS;
659 static int TitleCallback( vlc_object_t *p_this, char const *psz_cmd,
660 vlc_value_t oldval, vlc_value_t newval,
661 void *p_data )
663 input_thread_t *p_input = (input_thread_t*)p_this;
664 vlc_value_t val, count;
665 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
667 if( !strcmp( psz_cmd, "next-title" ) )
669 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE_NEXT, NULL );
671 val.i_int = var_GetInteger( p_input, "title" ) + 1;
672 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &count, NULL );
673 if( val.i_int < count.i_int )
674 var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
676 else if( !strcmp( psz_cmd, "prev-title" ) )
678 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE_PREV, NULL );
680 val.i_int = var_GetInteger( p_input, "title" ) - 1;
681 if( val.i_int >= 0 )
682 var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
684 else
686 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &newval );
689 return VLC_SUCCESS;
692 static int SeekpointCallback( vlc_object_t *p_this, char const *psz_cmd,
693 vlc_value_t oldval, vlc_value_t newval,
694 void *p_data )
696 input_thread_t *p_input = (input_thread_t*)p_this;
697 vlc_value_t val, count;
698 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
700 if( !strcmp( psz_cmd, "next-chapter" ) )
702 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT_NEXT, NULL );
704 val.i_int = var_GetInteger( p_input, "chapter" ) + 1;
705 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &count, NULL );
706 if( val.i_int < count.i_int )
707 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
709 else if( !strcmp( psz_cmd, "prev-chapter" ) )
711 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT_PREV, NULL );
713 val.i_int = var_GetInteger( p_input, "chapter" ) - 1;
714 if( val.i_int >= 0 )
715 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
717 else
719 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &newval );
722 return VLC_SUCCESS;
725 static int NavigationCallback( vlc_object_t *p_this, char const *psz_cmd,
726 vlc_value_t oldval, vlc_value_t newval,
727 void *p_data )
729 input_thread_t *p_input = (input_thread_t*)p_this;
730 vlc_value_t val;
731 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
733 /* Issue a title change */
734 val.i_int = (intptr_t)p_data;
735 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
737 var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
739 /* And a chapter change */
740 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &newval );
742 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &newval, NULL );
744 return VLC_SUCCESS;
747 static int ESCallback( vlc_object_t *p_this, char const *psz_cmd,
748 vlc_value_t oldval, vlc_value_t newval, void *p_data )
750 input_thread_t *p_input = (input_thread_t*)p_this;
751 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
753 if( newval.i_int < 0 )
755 vlc_value_t v;
756 /* Hack */
757 if( !strcmp( psz_cmd, "audio-es" ) )
758 v.i_int = -AUDIO_ES;
759 else if( !strcmp( psz_cmd, "video-es" ) )
760 v.i_int = -VIDEO_ES;
761 else if( !strcmp( psz_cmd, "spu-es" ) )
762 v.i_int = -SPU_ES;
763 else
764 v.i_int = 0;
765 if( v.i_int != 0 )
766 input_ControlPush( p_input, INPUT_CONTROL_SET_ES, &v );
768 else
770 input_ControlPush( p_input, INPUT_CONTROL_SET_ES, &newval );
773 return VLC_SUCCESS;
776 static int EsDelayCallback ( vlc_object_t *p_this, char const *psz_cmd,
777 vlc_value_t oldval, vlc_value_t newval, void *p_data )
779 input_thread_t *p_input = (input_thread_t*)p_this;
780 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
782 if( !strcmp( psz_cmd, "audio-delay" ) )
784 input_ControlPush( p_input, INPUT_CONTROL_SET_AUDIO_DELAY, &newval );
786 else if( !strcmp( psz_cmd, "spu-delay" ) )
788 input_ControlPush( p_input, INPUT_CONTROL_SET_SPU_DELAY, &newval );
790 return VLC_SUCCESS;
793 static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
794 vlc_value_t oldval, vlc_value_t newval,
795 void *p_data )
797 input_thread_t *p_input = (input_thread_t*)p_this;
798 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
800 input_ControlPush( p_input, INPUT_CONTROL_SET_BOOKMARK, &newval );
802 return VLC_SUCCESS;
805 static int RecordCallback( vlc_object_t *p_this, char const *psz_cmd,
806 vlc_value_t oldval, vlc_value_t newval,
807 void *p_data )
809 input_thread_t *p_input = (input_thread_t*)p_this;
810 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
812 input_ControlPush( p_input, INPUT_CONTROL_SET_RECORD_STATE, &newval );
814 return VLC_SUCCESS;
817 static int FrameNextCallback( vlc_object_t *p_this, char const *psz_cmd,
818 vlc_value_t oldval, vlc_value_t newval,
819 void *p_data )
821 input_thread_t *p_input = (input_thread_t*)p_this;
822 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
823 VLC_UNUSED(newval);
825 input_ControlPush( p_input, INPUT_CONTROL_SET_FRAME_NEXT, NULL );
827 return VLC_SUCCESS;