1 /*****************************************************************************
2 * var.c: object variables for input thread
3 *****************************************************************************
4 * Copyright (C) 2004-2007 VLC authors and VideoLAN
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_memstream.h>
38 #include "input_internal.h"
40 /*****************************************************************************
42 *****************************************************************************/
43 static int StateCallback ( vlc_object_t
*p_this
, char const *psz_cmd
,
44 vlc_value_t oldval
, vlc_value_t newval
, void * );
45 static int RateCallback ( vlc_object_t
*p_this
, char const *psz_cmd
,
46 vlc_value_t oldval
, vlc_value_t newval
, void * );
47 static int PositionCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
48 vlc_value_t oldval
, vlc_value_t newval
, void * );
49 static int TimeCallback ( vlc_object_t
*p_this
, char const *psz_cmd
,
50 vlc_value_t oldval
, vlc_value_t newval
, void * );
51 static int TimeOffsetCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
52 vlc_value_t oldval
, vlc_value_t newval
, void * );
53 static int ProgramCallback ( vlc_object_t
*p_this
, char const *psz_cmd
,
54 vlc_value_t oldval
, vlc_value_t newval
, void * );
55 static int TitleCallback ( vlc_object_t
*p_this
, char const *psz_cmd
,
56 vlc_value_t oldval
, vlc_value_t newval
, void * );
57 static int SeekpointCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
58 vlc_value_t oldval
, vlc_value_t newval
, void * );
59 static int NavigationCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
60 vlc_value_t oldval
, vlc_value_t newval
, void * );
61 static int EsVideoCallback ( vlc_object_t
*p_this
, char const *psz_cmd
,
62 vlc_value_t oldval
, vlc_value_t newval
, void * );
63 static int EsAudioCallback ( vlc_object_t
*p_this
, char const *psz_cmd
,
64 vlc_value_t oldval
, vlc_value_t newval
, void * );
65 static int EsSpuCallback ( vlc_object_t
*p_this
, char const *psz_cmd
,
66 vlc_value_t oldval
, vlc_value_t newval
, void * );
67 static int EsDelayCallback ( vlc_object_t
*p_this
, char const *psz_cmd
,
68 vlc_value_t oldval
, vlc_value_t newval
, void * );
70 static int BookmarkCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
71 vlc_value_t oldval
, vlc_value_t newval
, void * );
73 static int RecordCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
74 vlc_value_t oldval
, vlc_value_t newval
,
76 static int FrameNextCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
77 vlc_value_t oldval
, vlc_value_t newval
,
79 static int SubFpsCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
80 vlc_value_t oldval
, vlc_value_t newval
,
82 static void input_LegacyVarTitle( input_thread_t
*p_input
, int i_title
);
83 static void input_LegacyVarNavigation( input_thread_t
*p_input
);
88 vlc_callback_t callback
;
89 } vlc_input_callback_t
;
91 static void InputAddCallbacks( input_thread_t
*, const vlc_input_callback_t
* );
93 #ifdef CALLBACK /* For windows */
94 # undef CALLBACK /* We don't care of this one here */
96 /* List all callbacks added by input */
97 #define CALLBACK(name,cb) { name, cb }
98 static const vlc_input_callback_t p_input_callbacks
[] =
100 CALLBACK( "state", StateCallback
),
101 CALLBACK( "rate", RateCallback
),
102 CALLBACK( "position", PositionCallback
),
103 CALLBACK( "time", TimeCallback
),
104 CALLBACK( "time-offset", TimeOffsetCallback
),
105 CALLBACK( "bookmark", BookmarkCallback
),
106 CALLBACK( "program", ProgramCallback
),
107 CALLBACK( "title", TitleCallback
),
108 CALLBACK( "chapter", SeekpointCallback
),
109 CALLBACK( "audio-delay", EsDelayCallback
),
110 CALLBACK( "spu-delay", EsDelayCallback
),
111 CALLBACK( "video-es", EsVideoCallback
),
112 CALLBACK( "audio-es", EsAudioCallback
),
113 CALLBACK( "spu-es", EsSpuCallback
),
114 CALLBACK( "record", RecordCallback
),
115 CALLBACK( "frame-next", FrameNextCallback
),
116 CALLBACK( "sub-fps", SubFpsCallback
),
118 CALLBACK( NULL
, NULL
)
122 static void Trigger( input_thread_t
*p_input
, int i_type
)
124 var_SetInteger( p_input
, "intf-event", i_type
);
126 static void VarListAdd( input_thread_t
*p_input
,
127 const char *psz_variable
,
128 int i_value
, const char *psz_text
)
134 var_Change( p_input
, psz_variable
, VLC_VAR_ADDCHOICE
, val
, psz_text
);
136 static void VarListDel( input_thread_t
*p_input
,
137 const char *psz_variable
,
145 var_Change( p_input
, psz_variable
, VLC_VAR_DELCHOICE
, val
);
149 var_Change( p_input
, psz_variable
, VLC_VAR_CLEARCHOICES
);
152 static void VarListSelect( input_thread_t
*p_input
,
153 const char *psz_variable
,
159 var_Change( p_input
, psz_variable
, VLC_VAR_SETVALUE
, val
);
161 static const char *GetEsVarName( enum es_format_category_e i_cat
)
176 static void UpdateBookmarksOption( input_thread_t
*p_input
)
178 input_thread_private_t
*priv
= input_priv(p_input
);
179 input_item_t
* item
= priv
->p_item
;
180 struct vlc_memstream vstr
;
182 vlc_memstream_open( &vstr
);
183 vlc_memstream_puts( &vstr
, "bookmarks=" );
185 vlc_mutex_lock( &item
->lock
);
186 var_Change( p_input
, "bookmark", VLC_VAR_CLEARCHOICES
);
188 for( int i
= 0; i
< priv
->i_bookmark
; i
++ )
190 seekpoint_t
const* sp
= priv
->pp_bookmark
[i
];
192 /* Add bookmark to choice-list */
193 var_Change( p_input
, "bookmark", VLC_VAR_ADDCHOICE
,
194 (vlc_value_t
){ .i_int
= i
}, sp
->psz_name
);
196 /* Append bookmark to option-buffer */
197 /* TODO: escape inappropriate values */
198 vlc_memstream_printf( &vstr
, "%s{name=%s,time=%.3f}",
199 i
> 0 ? "," : "", sp
->psz_name
, secf_from_vlc_tick(sp
->i_time_offset
) );
202 if( vlc_memstream_close( &vstr
) )
204 vlc_mutex_unlock( &item
->lock
);
208 /* XXX: The below is ugly and should be fixed elsewhere, but in order to
209 * not have more than one "bookmarks=" option associated with the item, we
210 * need to remove any existing ones before adding the new one. This logic
211 * should exist in input_item_AddOption with "OPTION_UNIQUE & <an overwrite
212 * flag>, but until then we handle it here. */
214 char** const orig_beg
= &item
->ppsz_options
[0];
215 char** const orig_end
= orig_beg
+ item
->i_options
;
216 char** end
= orig_end
;
218 for( char** option
= orig_beg
; option
!= end
; )
220 if( strncmp( *option
, "bookmarks=", 10 ) )
225 /* It might be tempting to optimize the below by overwriting
226 * *option with the value of the last element, however; we want to
227 * preserve the order of the other options (as behavior might
229 memmove( option
, option
+ 1, ( --end
- option
) * sizeof *end
);
233 if( end
!= orig_end
) /* we removed at least 1 option */
236 item
->i_options
= end
- orig_beg
+ 1;
237 vlc_mutex_unlock( &item
->lock
);
239 else /* nothing removed, add the usual way */
241 vlc_mutex_unlock( &item
->lock
);
242 input_item_AddOption( item
, vstr
.ptr
, VLC_INPUT_OPTION_UNIQUE
);
247 static inline bool EsFmtIsTeletext( const es_format_t
*p_fmt
)
249 return p_fmt
->i_cat
== SPU_ES
&& p_fmt
->i_codec
== VLC_CODEC_TELETEXT
;
252 void input_LegacyEvents( input_thread_t
*p_input
,
253 const struct vlc_input_event
*event
, void *user_data
)
258 switch( event
->type
)
260 case INPUT_EVENT_STATE
:
261 val
.i_int
= event
->state
;
262 var_Change( p_input
, "state", VLC_VAR_SETVALUE
, val
);
264 case INPUT_EVENT_DEAD
:
266 case INPUT_EVENT_RATE
:
267 val
.f_float
= event
->rate
;
268 var_Change( p_input
, "rate", VLC_VAR_SETVALUE
, val
);
270 case INPUT_EVENT_CAPABILITIES
:
271 var_SetBool( p_input
, "can-seek",
272 event
->capabilities
& VLC_INPUT_CAPABILITIES_SEEKABLE
);
273 var_SetBool( p_input
, "can-pause",
274 event
->capabilities
& VLC_INPUT_CAPABILITIES_PAUSEABLE
);
275 var_SetBool( p_input
, "can-rate",
276 event
->capabilities
& VLC_INPUT_CAPABILITIES_CHANGE_RATE
);
277 var_SetBool( p_input
, "can-rewind",
278 event
->capabilities
& VLC_INPUT_CAPABILITIES_REWINDABLE
);
279 var_SetBool( p_input
, "can-record",
280 event
->capabilities
& VLC_INPUT_CAPABILITIES_RECORDABLE
);
282 case INPUT_EVENT_POSITION
:
283 val
.f_float
= event
->position
.percentage
;
284 var_Change( p_input
, "position", VLC_VAR_SETVALUE
, val
);
285 val
.i_int
= event
->position
.ms
;
286 var_Change( p_input
, "time", VLC_VAR_SETVALUE
, val
);
288 case INPUT_EVENT_LENGTH
:
289 /* FIXME ugly + what about meta change event ? */
290 if( var_GetInteger( p_input
, "length" ) == event
->length
)
292 val
.i_int
= event
->length
;
293 var_Change( p_input
, "length", VLC_VAR_SETVALUE
, val
);
295 case INPUT_EVENT_TITLE
:
296 val
.i_int
= event
->title
.action
== VLC_INPUT_TITLE_NEW_LIST
? 0 : event
->title
.selected_idx
;
297 var_Change( p_input
, "title", VLC_VAR_SETVALUE
, val
);
298 input_LegacyVarNavigation( p_input
);
299 input_LegacyVarTitle( p_input
, val
.i_int
);
301 case INPUT_EVENT_CHAPTER
:
303 val
.i_int
= event
->chapter
.seekpoint
;
304 var_Change( p_input
, "chapter", VLC_VAR_SETVALUE
, val
);
307 char psz_title
[sizeof ("title ") + 3 * sizeof (int)];
308 sprintf( psz_title
, "title %2u", event
->chapter
.title
);
309 var_Change( p_input
, psz_title
, VLC_VAR_SETVALUE
, val
);
311 case INPUT_EVENT_PROGRAM
:
312 switch (event
->program
.action
)
314 case VLC_INPUT_PROGRAM_ADDED
:
315 VarListAdd( p_input
, "program", event
->program
.id
,
316 event
->program
.title
);
318 case VLC_INPUT_PROGRAM_DELETED
:
319 VarListDel( p_input
, "program", event
->program
.id
);
321 case VLC_INPUT_PROGRAM_UPDATED
:
322 VarListDel( p_input
, "program", event
->program
.id
);
323 VarListAdd( p_input
, "program", event
->program
.id
,
324 event
->program
.title
);
326 case VLC_INPUT_PROGRAM_SELECTED
:
327 VarListSelect( p_input
, "program", event
->program
.id
);
329 case VLC_INPUT_PROGRAM_SCRAMBLED
:
330 if( var_GetInteger( p_input
, "program" ) != event
->program
.id
)
332 var_SetBool( p_input
, "program-scrambled", event
->program
.scrambled
);
337 switch (event
->es
.action
)
339 case VLC_INPUT_ES_ADDED
:
341 const char *varname
= GetEsVarName( event
->es
.fmt
->i_cat
);
345 var_Change( p_input
, varname
, VLC_VAR_CHOICESCOUNT
, &count
);
348 /* First one, we need to add the "Disable" choice */
349 VarListAdd( p_input
, varname
, -1, _("Disable") );
351 VarListAdd( p_input
, varname
, event
->es
.fmt
->i_id
, event
->es
.title
);
354 if( EsFmtIsTeletext( event
->es
.fmt
) )
357 snprintf( psz_page
, sizeof(psz_page
), "%d%2.2x",
358 event
->es
.fmt
->subs
.teletext
.i_magazine
,
359 event
->es
.fmt
->subs
.teletext
.i_page
);
360 VarListAdd( p_input
, "teletext-es", event
->es
.fmt
->i_id
,
361 event
->es
.fmt
->subs
.teletext
.i_magazine
>= 0 ? psz_page
: "" );
365 case VLC_INPUT_ES_DELETED
:
367 const char *varname
= GetEsVarName( event
->es
.fmt
->i_cat
);
369 VarListDel( p_input
, varname
, event
->es
.fmt
->i_id
);
371 if( EsFmtIsTeletext( event
->es
.fmt
) )
372 VarListDel( p_input
, "teletext-es", event
->es
.fmt
->i_id
);
375 case VLC_INPUT_ES_SELECTED
:
376 case VLC_INPUT_ES_UNSELECTED
:
378 int i_id
= event
->es
.action
== VLC_INPUT_ES_SELECTED
379 ? event
->es
.fmt
->i_id
: -1;
380 const char *varname
= GetEsVarName( event
->es
.fmt
->i_cat
);
382 VarListSelect( p_input
, varname
, i_id
);
383 if( EsFmtIsTeletext( event
->es
.fmt
) )
384 VarListSelect( p_input
, "teletext-es", i_id
);
387 case VLC_INPUT_ES_UPDATED
:
391 case INPUT_EVENT_RECORD
:
392 val
.b_bool
= event
->record
;
393 var_Change( p_input
, "record", VLC_VAR_SETVALUE
, val
);
395 case INPUT_EVENT_ITEM_META
:
397 case INPUT_EVENT_ITEM_INFO
:
399 case INPUT_EVENT_ITEM_EPG
:
401 case INPUT_EVENT_STATISTICS
:
403 case INPUT_EVENT_SIGNAL
:
404 val
.f_float
= event
->signal
.quality
;
405 var_Change( p_input
, "signal-quality", VLC_VAR_SETVALUE
, val
);
406 val
.f_float
= event
->signal
.strength
;
407 var_Change( p_input
, "signal-strength", VLC_VAR_SETVALUE
, val
);
409 case INPUT_EVENT_AUDIO_DELAY
:
410 val
.i_int
= event
->audio_delay
;
411 var_Change( p_input
, "audio-delay", VLC_VAR_SETVALUE
, val
);
413 case INPUT_EVENT_SUBTITLE_DELAY
:
414 val
.i_int
= event
->subtitle_delay
;
415 var_Change( p_input
, "spu-delay", VLC_VAR_SETVALUE
, val
);
417 case INPUT_EVENT_BOOKMARK
:
418 UpdateBookmarksOption( p_input
);
420 case INPUT_EVENT_CACHE
:
421 val
.f_float
= event
->cache
;
422 var_Change( p_input
, "cache", VLC_VAR_SETVALUE
, val
);
424 case INPUT_EVENT_VOUT
:
426 case INPUT_EVENT_SUBITEMS
:
429 Trigger( p_input
, event
->type
);
432 /*****************************************************************************
433 * input_LegacyVarInit:
434 * Create all control object variables with their callbacks
435 *****************************************************************************/
436 void input_LegacyVarInit ( input_thread_t
*p_input
)
440 var_Create( p_input
, "can-seek", VLC_VAR_BOOL
);
441 var_SetBool( p_input
, "can-seek", true ); /* Fixed later*/
443 var_Create( p_input
, "can-pause", VLC_VAR_BOOL
);
444 var_SetBool( p_input
, "can-pause", true ); /* Fixed later*/
446 var_Create( p_input
, "can-rate", VLC_VAR_BOOL
);
447 var_SetBool( p_input
, "can-rate", false );
449 var_Create( p_input
, "can-rewind", VLC_VAR_BOOL
);
450 var_SetBool( p_input
, "can-rewind", false );
452 var_Create( p_input
, "can-record", VLC_VAR_BOOL
);
453 var_SetBool( p_input
, "can-record", false ); /* Fixed later*/
455 var_Create( p_input
, "record", VLC_VAR_BOOL
);
456 var_SetBool( p_input
, "record", false );
458 var_Create( p_input
, "teletext-es", VLC_VAR_INTEGER
);
459 var_SetInteger( p_input
, "teletext-es", -1 );
461 var_Create( p_input
, "cache", VLC_VAR_FLOAT
);
462 var_SetFloat( p_input
, "cache", 0.0 );
464 var_Create( p_input
, "signal-quality", VLC_VAR_FLOAT
);
465 var_SetFloat( p_input
, "signal-quality", -1 );
467 var_Create( p_input
, "signal-strength", VLC_VAR_FLOAT
);
468 var_SetFloat( p_input
, "signal-strength", -1 );
470 var_Create( p_input
, "program-scrambled", VLC_VAR_BOOL
);
471 var_SetBool( p_input
, "program-scrambled", false );
474 var_Create( p_input
, "state", VLC_VAR_INTEGER
);
475 val
.i_int
= input_priv(p_input
)->i_state
;
476 var_Change( p_input
, "state", VLC_VAR_SETVALUE
, val
);
478 var_Create( p_input
, "frame-next", VLC_VAR_VOID
);
481 var_Create( p_input
, "position", VLC_VAR_FLOAT
);
484 var_Create( p_input
, "time", VLC_VAR_INTEGER
);
485 var_Create( p_input
, "time-offset", VLC_VAR_INTEGER
); /* relative */
488 var_Create( p_input
, "bookmark", VLC_VAR_INTEGER
| VLC_VAR_ISCOMMAND
);
489 var_Change( p_input
, "bookmark", VLC_VAR_SETTEXT
, _("Bookmark") );
492 var_Get( p_input
, "program", &val
);
494 var_Change( p_input
, "program", VLC_VAR_DELCHOICE
, val
);
495 var_Change( p_input
, "program", VLC_VAR_SETTEXT
, _("Program") );
498 var_Change( p_input
, "programs", VLC_VAR_SETTEXT
, _("Programs") );
501 var_Create( p_input
, "title", VLC_VAR_INTEGER
);
502 var_Change( p_input
, "title", VLC_VAR_SETTEXT
, _("Title") );
505 var_Create( p_input
, "chapter", VLC_VAR_INTEGER
);
506 var_Change( p_input
, "chapter", VLC_VAR_SETTEXT
, _("Chapter") );
509 var_Create( p_input
, "audio-delay", VLC_VAR_INTEGER
);
510 var_SetInteger( p_input
, "audio-delay",
511 VLC_TICK_FROM_MS( var_GetInteger( p_input
, "audio-desync" ) ) );
512 var_Create( p_input
, "spu-delay", VLC_VAR_INTEGER
);
516 var_Create( p_input
, "video-es", VLC_VAR_INTEGER
);
517 var_Change( p_input
, "video-es", VLC_VAR_SETVALUE
, val
);
518 var_Change( p_input
, "video-es", VLC_VAR_SETTEXT
, _("Video Track") );
521 var_Create( p_input
, "audio-es", VLC_VAR_INTEGER
);
522 var_Change( p_input
, "audio-es", VLC_VAR_SETVALUE
, val
);
523 var_Change( p_input
, "audio-es", VLC_VAR_SETTEXT
, _("Audio Track") );
526 var_Create( p_input
, "spu-es", VLC_VAR_INTEGER
);
527 var_Change( p_input
, "spu-es", VLC_VAR_SETVALUE
, val
);
528 var_Change( p_input
, "spu-es", VLC_VAR_SETTEXT
, _("Subtitle Track") );
530 var_Create( p_input
, "spu-choice", VLC_VAR_INTEGER
);
531 var_SetInteger( p_input
, "spu-choice", -1 );
533 var_Create( p_input
, "length", VLC_VAR_INTEGER
);
535 var_Create( p_input
, "bit-rate", VLC_VAR_INTEGER
);
536 var_Create( p_input
, "sample-rate", VLC_VAR_INTEGER
);
538 /* Special "intf-event" variable. */
539 var_Create( p_input
, "intf-event", VLC_VAR_INTEGER
);
540 var_Create( p_input
, "sub-fps", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
543 * XXX we put callback only in non preparsing mode. We need to create the variable
544 * unless someone want to check all var_Get/var_Change return value ... */
545 if( !input_priv(p_input
)->b_preparsing
)
546 InputAddCallbacks( p_input
, p_input_callbacks
);
549 /*****************************************************************************
550 * input_LegacyVarNavigation:
551 * Create all remaining control object variables
552 *****************************************************************************/
553 static void input_LegacyVarNavigation( input_thread_t
*p_input
)
555 /* Create more command variables */
556 if( input_priv(p_input
)->i_title
> 1 )
558 if( var_Type( p_input
, "next-title" ) == 0 ) {
559 var_Create( p_input
, "next-title", VLC_VAR_VOID
);
560 var_Change( p_input
, "next-title", VLC_VAR_SETTEXT
,
562 var_AddCallback( p_input
, "next-title", TitleCallback
, NULL
);
565 if( var_Type( p_input
, "prev-title" ) == 0 ) {
566 var_Create( p_input
, "prev-title", VLC_VAR_VOID
);
567 var_Change( p_input
, "prev-title", VLC_VAR_SETTEXT
,
568 _("Previous title") );
569 var_AddCallback( p_input
, "prev-title", TitleCallback
, NULL
);
572 if( var_Type( p_input
, "menu-title" ) == 0 ) {
573 var_Create( p_input
, "menu-title", VLC_VAR_VOID
);
574 var_Change( p_input
, "menu-title", VLC_VAR_SETTEXT
,
576 var_AddCallback( p_input
, "menu-title", TitleCallback
, NULL
);
579 if( var_Type( p_input
, "menu-popup" ) == 0 ) {
580 var_Create( p_input
, "menu-popup", VLC_VAR_VOID
);
581 var_Change( p_input
, "menu-popup", VLC_VAR_SETTEXT
,
583 var_AddCallback( p_input
, "menu-popup", TitleCallback
, NULL
);
587 /* Create titles and chapters */
588 var_Change( p_input
, "title", VLC_VAR_CLEARCHOICES
);
590 for( int i
= 0; i
< input_priv(p_input
)->i_title
; i
++ )
592 vlc_value_t val2
, text2
;
593 char title
[sizeof("title ") + 3 * sizeof (int)];
595 /* Add Navigation entries */
596 sprintf( title
, "title %2u", i
);
597 var_Destroy( p_input
, title
);
598 var_Create( p_input
, title
, VLC_VAR_INTEGER
| VLC_VAR_ISCOMMAND
);
599 var_AddCallback( p_input
, title
,
600 NavigationCallback
, (void *)(intptr_t)i
);
602 char psz_length
[MSTRTIME_MAX_SIZE
+ sizeof(" []")];
603 if( input_priv(p_input
)->title
[i
]->i_length
> 0 )
605 strcpy( psz_length
, " [" );
606 secstotimestr( &psz_length
[2], SEC_FROM_VLC_TICK(input_priv(p_input
)->title
[i
]->i_length
) );
607 strcat( psz_length
, "]" );
610 psz_length
[0] = '\0';
613 if( input_priv(p_input
)->title
[i
]->psz_name
== NULL
||
614 *input_priv(p_input
)->title
[i
]->psz_name
== '\0' )
616 if( asprintf( &titlestr
, _("Title %i%s"),
617 i
+ input_priv(p_input
)->i_title_offset
, psz_length
) == -1 )
622 if( asprintf( &titlestr
, "%s%s",
623 input_priv(p_input
)->title
[i
]->psz_name
, psz_length
) == -1 )
627 /* Add title choice */
629 var_Change( p_input
, "title", VLC_VAR_ADDCHOICE
, val2
,
630 (const char *)titlestr
);
634 for( int j
= 0; j
< input_priv(p_input
)->title
[i
]->i_seekpoint
; j
++ )
638 if( input_priv(p_input
)->title
[i
]->seekpoint
[j
]->psz_name
== NULL
||
639 *input_priv(p_input
)->title
[i
]->seekpoint
[j
]->psz_name
== '\0' )
642 if( asprintf( &text2
.psz_string
, _("Chapter %i"),
643 j
+ input_priv(p_input
)->i_seekpoint_offset
) == -1 )
649 strdup( input_priv(p_input
)->title
[i
]->seekpoint
[j
]->psz_name
);
652 var_Change( p_input
, title
, VLC_VAR_ADDCHOICE
, val2
,
653 (const char *)text2
.psz_string
);
654 free( text2
.psz_string
);
660 /*****************************************************************************
661 * input_LegacyVarTitle:
662 * Create all variables for a title
663 *****************************************************************************/
664 static void input_LegacyVarTitle( input_thread_t
*p_input
, int i_title
)
666 const input_title_t
*t
= input_priv(p_input
)->title
[i_title
];
670 /* Create/Destroy command variables */
671 if( t
->i_seekpoint
<= 1 )
673 var_Destroy( p_input
, "next-chapter" );
674 var_Destroy( p_input
, "prev-chapter" );
676 else if( var_Type( p_input
, "next-chapter" ) == 0 )
678 var_Create( p_input
, "next-chapter", VLC_VAR_VOID
);
679 var_Change( p_input
, "next-chapter", VLC_VAR_SETTEXT
,
681 var_AddCallback( p_input
, "next-chapter", SeekpointCallback
, NULL
);
683 var_Create( p_input
, "prev-chapter", VLC_VAR_VOID
);
684 var_Change( p_input
, "prev-chapter", VLC_VAR_SETTEXT
,
685 _("Previous chapter") );
686 var_AddCallback( p_input
, "prev-chapter", SeekpointCallback
, NULL
);
689 /* Build chapter list */
690 var_Change( p_input
, "chapter", VLC_VAR_CLEARCHOICES
);
691 for( i
= 0; i
< t
->i_seekpoint
; i
++ )
696 if( t
->seekpoint
[i
]->psz_name
== NULL
||
697 *t
->seekpoint
[i
]->psz_name
== '\0' )
700 if( asprintf( &text
.psz_string
, _("Chapter %i"),
701 i
+ input_priv(p_input
)->i_seekpoint_offset
) == -1 )
706 text
.psz_string
= strdup( t
->seekpoint
[i
]->psz_name
);
709 var_Change( p_input
, "chapter", VLC_VAR_ADDCHOICE
, val
,
710 (const char *)text
.psz_string
);
711 free( text
.psz_string
);
715 /*****************************************************************************
716 * input_ConfigVarInit:
717 * Create all config object variables
718 *****************************************************************************/
719 void input_ConfigVarInit ( input_thread_t
*p_input
)
721 /* Create Object Variables for private use only */
723 if( !input_priv(p_input
)->b_preparsing
)
725 var_Create( p_input
, "video", VLC_VAR_BOOL
| VLC_VAR_DOINHERIT
);
726 var_Create( p_input
, "audio", VLC_VAR_BOOL
| VLC_VAR_DOINHERIT
);
727 var_Create( p_input
, "spu", VLC_VAR_BOOL
| VLC_VAR_DOINHERIT
);
729 var_Create( p_input
, "video-track", VLC_VAR_INTEGER
|VLC_VAR_DOINHERIT
);
730 var_Create( p_input
, "audio-track", VLC_VAR_INTEGER
|VLC_VAR_DOINHERIT
);
731 var_Create( p_input
, "sub-track", VLC_VAR_INTEGER
|VLC_VAR_DOINHERIT
);
733 var_Create( p_input
, "audio-language",
734 VLC_VAR_STRING
|VLC_VAR_DOINHERIT
);
735 var_Create( p_input
, "sub-language",
736 VLC_VAR_STRING
|VLC_VAR_DOINHERIT
);
737 var_Create( p_input
, "menu-language",
738 VLC_VAR_STRING
|VLC_VAR_DOINHERIT
);
740 var_Create( p_input
, "video-track-id",
741 VLC_VAR_INTEGER
|VLC_VAR_DOINHERIT
);
742 var_Create( p_input
, "audio-track-id",
743 VLC_VAR_INTEGER
|VLC_VAR_DOINHERIT
);
744 var_Create( p_input
, "sub-track-id",
745 VLC_VAR_INTEGER
|VLC_VAR_DOINHERIT
);
747 var_Create( p_input
, "sub-file", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
748 var_Create( p_input
, "sub-autodetect-file", VLC_VAR_BOOL
|
750 var_Create( p_input
, "sub-autodetect-path", VLC_VAR_STRING
|
752 var_Create( p_input
, "sub-autodetect-fuzzy", VLC_VAR_INTEGER
|
755 var_Create( p_input
, "sout", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
756 var_Create( p_input
, "sout-all", VLC_VAR_BOOL
| VLC_VAR_DOINHERIT
);
757 var_Create( p_input
, "sout-audio", VLC_VAR_BOOL
| VLC_VAR_DOINHERIT
);
758 var_Create( p_input
, "sout-video", VLC_VAR_BOOL
| VLC_VAR_DOINHERIT
);
759 var_Create( p_input
, "sout-spu", VLC_VAR_BOOL
| VLC_VAR_DOINHERIT
);
760 var_Create( p_input
, "sout-keep", VLC_VAR_BOOL
| VLC_VAR_DOINHERIT
);
762 var_Create( p_input
, "input-repeat",
763 VLC_VAR_INTEGER
|VLC_VAR_DOINHERIT
);
764 var_Create( p_input
, "start-time", VLC_VAR_FLOAT
|VLC_VAR_DOINHERIT
);
765 var_Create( p_input
, "stop-time", VLC_VAR_FLOAT
|VLC_VAR_DOINHERIT
);
766 var_Create( p_input
, "run-time", VLC_VAR_FLOAT
|VLC_VAR_DOINHERIT
);
767 var_Create( p_input
, "input-fast-seek", VLC_VAR_BOOL
|VLC_VAR_DOINHERIT
);
769 var_Create( p_input
, "input-slave",
770 VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
772 var_Create( p_input
, "audio-desync",
773 VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
774 var_Create( p_input
, "cr-average",
775 VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
776 var_Create( p_input
, "clock-synchro",
777 VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
779 var_Create( p_input
, "bookmarks", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
780 var_Create( p_input
, "programs", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
781 var_Create( p_input
, "program", VLC_VAR_INTEGER
| VLC_VAR_DOINHERIT
);
782 var_Create( p_input
, "rate", VLC_VAR_FLOAT
| VLC_VAR_DOINHERIT
);
786 var_Create( p_input
, "input-record-native", VLC_VAR_BOOL
| VLC_VAR_DOINHERIT
);
789 var_Create( p_input
, "access", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
790 var_Create( p_input
, "demux", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
791 var_Create( p_input
, "demux-filter", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
792 var_Create( p_input
, "stream-filter", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
795 var_Create( p_input
, "meta-title", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
796 var_Create( p_input
, "meta-author", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
797 var_Create( p_input
, "meta-artist", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
798 var_Create( p_input
, "meta-genre", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
799 var_Create( p_input
, "meta-copyright", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
800 var_Create( p_input
, "meta-description", VLC_VAR_STRING
|VLC_VAR_DOINHERIT
);
801 var_Create( p_input
, "meta-date", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
802 var_Create( p_input
, "meta-url", VLC_VAR_STRING
| VLC_VAR_DOINHERIT
);
804 /* Inherited by demux/subtitle.c */
805 var_Create( p_input
, "sub-original-fps", VLC_VAR_FLOAT
);
808 /*****************************************************************************
809 * Callbacks managements:
810 *****************************************************************************/
811 static void InputAddCallbacks( input_thread_t
*p_input
,
812 const vlc_input_callback_t
*p_callbacks
)
815 for( i
= 0; p_callbacks
[i
].psz_name
!= NULL
; i
++ )
816 var_AddCallback( p_input
,
817 p_callbacks
[i
].psz_name
,
818 p_callbacks
[i
].callback
, NULL
);
821 /*****************************************************************************
823 *****************************************************************************/
824 static int StateCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
825 vlc_value_t oldval
, vlc_value_t newval
,
828 input_thread_t
*p_input
= (input_thread_t
*)p_this
;
829 VLC_UNUSED(psz_cmd
); VLC_UNUSED(oldval
); VLC_UNUSED(p_data
);
831 if( newval
.i_int
== PLAYING_S
|| newval
.i_int
== PAUSE_S
)
833 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_STATE
, &newval
);
840 static int RateCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
841 vlc_value_t oldval
, vlc_value_t newval
, void *p_data
)
843 input_thread_t
*p_input
= (input_thread_t
*)p_this
;
844 VLC_UNUSED(oldval
); VLC_UNUSED(p_data
); VLC_UNUSED(psz_cmd
);
846 newval
.i_int
= INPUT_RATE_DEFAULT
/ newval
.f_float
;
847 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_RATE
, &newval
);
852 static int PositionCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
853 vlc_value_t oldval
, vlc_value_t newval
,
856 input_thread_t
*p_input
= (input_thread_t
*)p_this
;
858 VLC_UNUSED(psz_cmd
); VLC_UNUSED(oldval
); VLC_UNUSED(p_data
);
860 /* Update "length" for better intf behaviour */
861 const vlc_tick_t i_length
= var_GetInteger( p_input
, "length" );
862 if( i_length
> 0 && newval
.f_float
>= 0.f
&& newval
.f_float
<= 1.f
)
866 val
.i_int
= i_length
* newval
.f_float
;
867 var_Change( p_input
, "time", VLC_VAR_SETVALUE
, val
);
870 input_SetPosition( p_input
, newval
.f_float
,
871 var_GetBool( p_input
, "input-fast-seek" ) );
875 static int TimeCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
876 vlc_value_t oldval
, vlc_value_t newval
, void *p_data
)
878 input_thread_t
*p_input
= (input_thread_t
*)p_this
;
879 VLC_UNUSED(psz_cmd
); VLC_UNUSED(oldval
); VLC_UNUSED(p_data
);
881 /* Update "position" for better intf behaviour */
882 const vlc_tick_t i_length
= var_GetInteger( p_input
, "length" );
883 if( i_length
> 0 && newval
.i_int
>= 0 && newval
.i_int
<= i_length
)
887 val
.f_float
= (double)newval
.i_int
/(double)i_length
;
888 var_Change( p_input
, "position", VLC_VAR_SETVALUE
, val
);
890 * Notify the intf that a new event has been occurred.
891 * XXX this is a bit hackish but it's the only way to do it now.
893 var_SetInteger( p_input
, "intf-event", INPUT_EVENT_POSITION
);
896 input_SetTime( p_input
, newval
.i_int
,
897 var_GetBool( p_input
, "input-fast-seek" ) );
901 static int TimeOffsetCallback( vlc_object_t
*obj
, char const *varname
,
902 vlc_value_t prev
, vlc_value_t cur
, void *data
)
904 VLC_UNUSED(varname
); VLC_UNUSED(prev
); VLC_UNUSED(data
);
906 vlc_tick_t i_time
= var_GetInteger( obj
, "time" ) + cur
.i_int
;
909 var_SetInteger( obj
, "time", i_time
);
913 static int ProgramCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
914 vlc_value_t oldval
, vlc_value_t newval
,
917 input_thread_t
*p_input
= (input_thread_t
*)p_this
;
918 VLC_UNUSED(psz_cmd
); VLC_UNUSED(oldval
); VLC_UNUSED(p_data
);
920 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_PROGRAM
, &newval
);
925 static int TitleCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
926 vlc_value_t oldval
, vlc_value_t newval
,
929 input_thread_t
*p_input
= (input_thread_t
*)p_this
;
932 VLC_UNUSED(oldval
); VLC_UNUSED(p_data
);
934 if( !strcmp( psz_cmd
, "next-title" ) )
936 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_TITLE_NEXT
, NULL
);
938 val
.i_int
= var_GetInteger( p_input
, "title" ) + 1;
939 var_Change( p_input
, "title", VLC_VAR_CHOICESCOUNT
, &count
);
940 if( (size_t)val
.i_int
< count
)
941 var_Change( p_input
, "title", VLC_VAR_SETVALUE
, val
);
943 else if( !strcmp( psz_cmd
, "prev-title" ) )
945 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_TITLE_PREV
, NULL
);
947 val
.i_int
= var_GetInteger( p_input
, "title" ) - 1;
949 var_Change( p_input
, "title", VLC_VAR_SETVALUE
, val
);
951 else if( !strcmp( psz_cmd
, "menu-title" ) )
953 input_ControlPushHelper( p_input
, INPUT_CONTROL_NAV_MENU
, NULL
);
955 else if( !strcmp( psz_cmd
, "menu-popup" ) )
957 input_ControlPushHelper( p_input
, INPUT_CONTROL_NAV_POPUP
, NULL
);
961 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_TITLE
, &newval
);
967 static int SeekpointCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
968 vlc_value_t oldval
, vlc_value_t newval
,
971 input_thread_t
*p_input
= (input_thread_t
*)p_this
;
974 VLC_UNUSED(oldval
); VLC_UNUSED(p_data
);
976 if( !strcmp( psz_cmd
, "next-chapter" ) )
978 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_SEEKPOINT_NEXT
, NULL
);
980 val
.i_int
= var_GetInteger( p_input
, "chapter" ) + 1;
981 var_Change( p_input
, "chapter", VLC_VAR_CHOICESCOUNT
, &count
);
982 if( (size_t)val
.i_int
< count
)
983 var_Change( p_input
, "chapter", VLC_VAR_SETVALUE
, val
);
985 else if( !strcmp( psz_cmd
, "prev-chapter" ) )
987 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_SEEKPOINT_PREV
, NULL
);
989 val
.i_int
= var_GetInteger( p_input
, "chapter" ) - 1;
991 var_Change( p_input
, "chapter", VLC_VAR_SETVALUE
, val
);
995 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_SEEKPOINT
, &newval
);
1001 static int NavigationCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
1002 vlc_value_t oldval
, vlc_value_t newval
,
1005 input_thread_t
*p_input
= (input_thread_t
*)p_this
;
1007 VLC_UNUSED(psz_cmd
); VLC_UNUSED(oldval
);
1009 /* Issue a title change */
1010 val
.i_int
= (intptr_t)p_data
;
1011 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_TITLE
, &val
);
1013 var_Change( p_input
, "title", VLC_VAR_SETVALUE
, val
);
1015 /* And a chapter change */
1016 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_SEEKPOINT
, &newval
);
1018 var_Change( p_input
, "chapter", VLC_VAR_SETVALUE
, newval
);
1023 static int EsVideoCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
1024 vlc_value_t oldval
, vlc_value_t newval
, void *p_data
)
1026 input_thread_t
*p_input
= (input_thread_t
*)p_this
;
1027 VLC_UNUSED( psz_cmd
); VLC_UNUSED( oldval
); VLC_UNUSED( p_data
);
1029 if( newval
.i_int
< 0 )
1030 newval
.i_int
= -VIDEO_ES
; /* disable video es */
1032 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_ES_BY_ID
, &newval
);
1037 static int EsAudioCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
1038 vlc_value_t oldval
, vlc_value_t newval
, void *p_data
)
1040 input_thread_t
*p_input
= (input_thread_t
*)p_this
;
1041 VLC_UNUSED( psz_cmd
); VLC_UNUSED( oldval
); VLC_UNUSED( p_data
);
1043 if( newval
.i_int
< 0 )
1044 newval
.i_int
= -AUDIO_ES
; /* disable audio es */
1046 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_ES_BY_ID
, &newval
);
1051 static int EsSpuCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
1052 vlc_value_t oldval
, vlc_value_t newval
, void *p_data
)
1054 input_thread_t
*p_input
= (input_thread_t
*)p_this
;
1055 VLC_UNUSED( psz_cmd
); VLC_UNUSED( oldval
); VLC_UNUSED( p_data
);
1057 if( newval
.i_int
< 0 )
1058 newval
.i_int
= -SPU_ES
; /* disable spu es */
1060 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_ES_BY_ID
, &newval
);
1065 static int EsDelayCallback ( vlc_object_t
*p_this
, char const *psz_cmd
,
1066 vlc_value_t oldval
, vlc_value_t newval
, void *p_data
)
1068 input_thread_t
*p_input
= (input_thread_t
*)p_this
;
1069 VLC_UNUSED(oldval
); VLC_UNUSED(p_data
);
1071 input_control_param_t param
= {
1074 .i_val
= newval
.i_int
,
1077 if( !strcmp( psz_cmd
, "audio-delay" ) )
1078 input_ControlPush( p_input
, INPUT_CONTROL_SET_AUDIO_DELAY
, ¶m
);
1079 else if( !strcmp( psz_cmd
, "spu-delay" ) )
1080 input_ControlPush( p_input
, INPUT_CONTROL_SET_SPU_DELAY
, ¶m
);
1084 static int BookmarkCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
1085 vlc_value_t oldval
, vlc_value_t newval
,
1088 input_thread_t
*p_input
= (input_thread_t
*)p_this
;
1089 VLC_UNUSED(psz_cmd
); VLC_UNUSED(oldval
); VLC_UNUSED(p_data
);
1091 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_BOOKMARK
, &newval
);
1096 static int RecordCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
1097 vlc_value_t oldval
, vlc_value_t newval
,
1100 input_thread_t
*p_input
= (input_thread_t
*)p_this
;
1101 VLC_UNUSED(psz_cmd
); VLC_UNUSED(oldval
); VLC_UNUSED(p_data
);
1103 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_RECORD_STATE
, &newval
);
1108 static int FrameNextCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
1109 vlc_value_t oldval
, vlc_value_t newval
,
1112 input_thread_t
*p_input
= (input_thread_t
*)p_this
;
1113 VLC_UNUSED(psz_cmd
); VLC_UNUSED(oldval
); VLC_UNUSED(p_data
);
1116 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_FRAME_NEXT
, NULL
);
1121 static int SubFpsCallback( vlc_object_t
*p_this
, char const *psz_cmd
,
1122 vlc_value_t oldval
, vlc_value_t newval
,
1125 input_thread_t
*p_input
= (input_thread_t
*)p_this
;
1126 VLC_UNUSED(psz_cmd
); VLC_UNUSED(oldval
); VLC_UNUSED(p_data
);
1129 input_ControlPushHelper( p_input
, INPUT_CONTROL_SET_SUBS_FPS
, &newval
);