var.c 30.9 KB
Newer Older
Laurent Aimar's avatar
Laurent Aimar committed
1 2 3
/*****************************************************************************
 * var.c: object variables for input thread
 *****************************************************************************
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
4
 * Copyright (C) 2004-2007 VLC authors and VideoLAN
5
 * $Id$
Laurent Aimar's avatar
Laurent Aimar committed
6 7 8
 *
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
9 10 11
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
Laurent Aimar's avatar
Laurent Aimar committed
12 13 14 15
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
16 17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
Laurent Aimar's avatar
Laurent Aimar committed
18
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
19 20 21
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
Laurent Aimar's avatar
Laurent Aimar committed
22 23 24 25 26
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
27 28 29 30
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

31
#include <vlc_common.h>
32 33
#include <assert.h>
#include <math.h>
34 35
#include <stdio.h>
#include <stdlib.h>
Laurent Aimar's avatar
Laurent Aimar committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49

#include "input_internal.h"

/*****************************************************************************
 * Callbacks
 *****************************************************************************/
static int StateCallback   ( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void * );
static int RateCallback    ( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void * );
static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void * );
static int TimeCallback    ( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void * );
50 51
static int TimeOffsetCallback( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void * );
Laurent Aimar's avatar
Laurent Aimar committed
52 53 54 55 56 57 58 59 60 61
static int ProgramCallback ( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void * );
static int TitleCallback   ( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void * );
static int SeekpointCallback( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void * );
static int NavigationCallback( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void * );
static int ESCallback      ( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void * );
62 63 64
static int EsDelayCallback ( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void * );

Laurent Aimar's avatar
Laurent Aimar committed
65 66 67
static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void * );

68 69 70
static int RecordCallback( vlc_object_t *p_this, char const *psz_cmd,
                           vlc_value_t oldval, vlc_value_t newval,
                           void *p_data );
71 72 73
static int FrameNextCallback( vlc_object_t *p_this, char const *psz_cmd,
                              vlc_value_t oldval, vlc_value_t newval,
                              void *p_data );
74

75 76 77 78 79
typedef struct
{
    const char *psz_name;
    vlc_callback_t callback;
} vlc_input_callback_t;
80

81 82 83
static void InputAddCallbacks( input_thread_t *, const vlc_input_callback_t * );
static void InputDelCallbacks( input_thread_t *, const vlc_input_callback_t * );

84 85 86
#ifdef CALLBACK /* For windows */
# undef CALLBACK /* We don't care of this one here */
#endif
87 88 89 90 91 92 93 94
/* List all callbacks added by input */
#define CALLBACK(name,cb) { name, cb }
static const vlc_input_callback_t p_input_callbacks[] =
{
    CALLBACK( "state", StateCallback ),
    CALLBACK( "rate", RateCallback ),
    CALLBACK( "position", PositionCallback ),
    CALLBACK( "time", TimeCallback ),
95
    CALLBACK( "time-offset", TimeOffsetCallback ),
96 97 98 99 100 101 102 103 104
    CALLBACK( "bookmark", BookmarkCallback ),
    CALLBACK( "program", ProgramCallback ),
    CALLBACK( "title", TitleCallback ),
    CALLBACK( "chapter", SeekpointCallback ),
    CALLBACK( "audio-delay", EsDelayCallback ),
    CALLBACK( "spu-delay", EsDelayCallback ),
    CALLBACK( "video-es", ESCallback ),
    CALLBACK( "audio-es", ESCallback ),
    CALLBACK( "spu-es", ESCallback ),
105
    CALLBACK( "record", RecordCallback ),
106
    CALLBACK( "frame-next", FrameNextCallback ),
107 108 109

    CALLBACK( NULL, NULL )
};
110
static const vlc_input_callback_t p_input_title_navigation_callbacks[] =
111 112 113
{
    CALLBACK( "next-title", TitleCallback ),
    CALLBACK( "prev-title", TitleCallback ),
114
    CALLBACK( "menu-popup", TitleCallback ),
115
    CALLBACK( "menu-title", TitleCallback ),
116 117 118

    CALLBACK( NULL, NULL )
};
119
static const vlc_input_callback_t p_input_seekpoint_navigation_callbacks[] =
120 121 122
{
    CALLBACK( "next-chapter", SeekpointCallback ),
    CALLBACK( "prev-chapter", SeekpointCallback ),
123 124

    CALLBACK( NULL, NULL )
125 126 127
};
#undef CALLBACK

Laurent Aimar's avatar
Laurent Aimar committed
128 129 130 131 132 133 134 135 136 137
/*****************************************************************************
 * input_ControlVarInit:
 *  Create all control object variables with their callbacks
 *****************************************************************************/
void input_ControlVarInit ( input_thread_t *p_input )
{
    vlc_value_t val, text;

    /* State */
    var_Create( p_input, "state", VLC_VAR_INTEGER );
Laurent Aimar's avatar
Laurent Aimar committed
138
    val.i_int = p_input->p->i_state;
Laurent Aimar's avatar
Laurent Aimar committed
139 140 141
    var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );

    /* Rate */
142
    var_Create( p_input, "rate", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
Laurent Aimar's avatar
Laurent Aimar committed
143

144 145
    var_Create( p_input, "frame-next", VLC_VAR_VOID );

Laurent Aimar's avatar
Laurent Aimar committed
146 147 148 149
    /* Position */
    var_Create( p_input, "position",  VLC_VAR_FLOAT );

    /* Time */
150
    var_Create( p_input, "time", VLC_VAR_INTEGER );
151
    var_Create( p_input, "time-offset", VLC_VAR_INTEGER );    /* relative */
Laurent Aimar's avatar
Laurent Aimar committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167

    /* Bookmark */
    var_Create( p_input, "bookmark", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE |
                VLC_VAR_ISCOMMAND );
    val.psz_string = _("Bookmark");
    var_Change( p_input, "bookmark", VLC_VAR_SETTEXT, &val, NULL );

    /* Program */
    var_Create( p_input, "program", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE |
                VLC_VAR_DOINHERIT );
    var_Get( p_input, "program", &val );
    if( val.i_int <= 0 )
        var_Change( p_input, "program", VLC_VAR_DELCHOICE, &val, NULL );
    text.psz_string = _("Program");
    var_Change( p_input, "program", VLC_VAR_SETTEXT, &text, NULL );

168
    /* Programs */
169
    var_Create( p_input, "programs", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
170 171 172
    text.psz_string = _("Programs");
    var_Change( p_input, "programs", VLC_VAR_SETTEXT, &text, NULL );

Laurent Aimar's avatar
Laurent Aimar committed
173 174 175 176 177 178 179 180 181 182
    /* Title */
    var_Create( p_input, "title", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
    text.psz_string = _("Title");
    var_Change( p_input, "title", VLC_VAR_SETTEXT, &text, NULL );

    /* Chapter */
    var_Create( p_input, "chapter", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
    text.psz_string = _("Chapter");
    var_Change( p_input, "chapter", VLC_VAR_SETTEXT, &text, NULL );

183
    /* Delay */
184 185 186 187
    var_Create( p_input, "audio-delay", VLC_VAR_INTEGER );
    var_SetInteger( p_input, "audio-delay",
                    1000 * var_GetInteger( p_input, "audio-desync" ) );
    var_Create( p_input, "spu-delay", VLC_VAR_INTEGER );
188

Laurent Aimar's avatar
Laurent Aimar committed
189 190 191 192 193 194 195 196 197 198 199 200
    /* Video ES */
    var_Create( p_input, "video-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
    text.psz_string = _("Video Track");
    var_Change( p_input, "video-es", VLC_VAR_SETTEXT, &text, NULL );

    /* Audio ES */
    var_Create( p_input, "audio-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
    text.psz_string = _("Audio Track");
    var_Change( p_input, "audio-es", VLC_VAR_SETTEXT, &text, NULL );

    /* Spu ES */
    var_Create( p_input, "spu-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
201
    text.psz_string = _("Subtitle Track");
Laurent Aimar's avatar
Laurent Aimar committed
202 203
    var_Change( p_input, "spu-es", VLC_VAR_SETTEXT, &text, NULL );

204
    var_Create( p_input, "spu-choice", VLC_VAR_INTEGER );
205
    var_SetInteger( p_input, "spu-choice", -1 );
206

Laurent Aimar's avatar
Laurent Aimar committed
207 208 209
    /* Special read only objects variables for intf */
    var_Create( p_input, "bookmarks", VLC_VAR_STRING | VLC_VAR_DOINHERIT );

210
    var_Create( p_input, "length", VLC_VAR_INTEGER );
Laurent Aimar's avatar
Laurent Aimar committed
211

212 213 214
    var_Create( p_input, "bit-rate", VLC_VAR_INTEGER );
    var_Create( p_input, "sample-rate", VLC_VAR_INTEGER );

215 216
    /* Special "intf-event" variable. */
    var_Create( p_input, "intf-event", VLC_VAR_INTEGER );
217 218 219 220 221 222

    /* Add all callbacks
     * XXX we put callback only in non preparsing mode. We need to create the variable
     * unless someone want to check all var_Get/var_Change return value ... */
    if( !p_input->b_preparsing )
        InputAddCallbacks( p_input, p_input_callbacks );
Laurent Aimar's avatar
Laurent Aimar committed
223 224 225
}

/*****************************************************************************
226
 * input_ControlVarStop:
Laurent Aimar's avatar
Laurent Aimar committed
227
 *****************************************************************************/
228
void input_ControlVarStop( input_thread_t *p_input )
Laurent Aimar's avatar
Laurent Aimar committed
229
{
230 231
    if( !p_input->b_preparsing )
        InputDelCallbacks( p_input, p_input_callbacks );
Laurent Aimar's avatar
Laurent Aimar committed
232

233 234 235
    if( p_input->p->i_title > 1 )
        InputDelCallbacks( p_input, p_input_title_navigation_callbacks );

zorglub's avatar
zorglub committed
236
    if( p_input->p->i_title > 0 )
Laurent Aimar's avatar
Laurent Aimar committed
237
    {
238
        InputDelCallbacks( p_input, p_input_seekpoint_navigation_callbacks );
Laurent Aimar's avatar
Laurent Aimar committed
239

240
        for( int i = 0; i < p_input->p->i_title; i++ )
241
        {
242 243 244
            char name[sizeof("title ") + 3 * sizeof (int)];

            sprintf( name, "title %2u", i );
245 246 247 248
            var_DelCallback( p_input, name, NavigationCallback, (void *)(intptr_t)i );
        }
    }
}
Laurent Aimar's avatar
Laurent Aimar committed
249 250 251 252 253 254 255

/*****************************************************************************
 * input_ControlVarNavigation:
 *  Create all remaining control object variables
 *****************************************************************************/
void input_ControlVarNavigation( input_thread_t *p_input )
{
256
    vlc_value_t text;
Laurent Aimar's avatar
Laurent Aimar committed
257 258

    /* Create more command variables */
zorglub's avatar
zorglub committed
259
    if( p_input->p->i_title > 1 )
Laurent Aimar's avatar
Laurent Aimar committed
260
    {
261 262 263 264 265 266 267 268 269 270 271 272 273
        if( var_Type( p_input, "next-title" ) == 0 ) {
            var_Create( p_input, "next-title", VLC_VAR_VOID );
            text.psz_string = _("Next title");
            var_Change( p_input, "next-title", VLC_VAR_SETTEXT, &text, NULL );
            var_AddCallback( p_input, "next-title", TitleCallback, NULL );
        }

        if( var_Type( p_input, "prev-title" ) == 0 ) {
            var_Create( p_input, "prev-title", VLC_VAR_VOID );
            text.psz_string = _("Previous title");
            var_Change( p_input, "prev-title", VLC_VAR_SETTEXT, &text, NULL );
            var_AddCallback( p_input, "prev-title", TitleCallback, NULL );
        }
274

275 276 277 278 279 280 281
        if( var_Type( p_input, "menu-title" ) == 0 ) {
            var_Create( p_input, "menu-title", VLC_VAR_VOID );
            text.psz_string = _("Menu title");
            var_Change( p_input, "menu-title", VLC_VAR_SETTEXT, &text, NULL );
            var_AddCallback( p_input, "menu-title", TitleCallback, NULL );
        }

282 283 284 285 286 287
        if( var_Type( p_input, "menu-popup" ) == 0 ) {
            var_Create( p_input, "menu-popup", VLC_VAR_VOID );
            text.psz_string = _("Menu popup");
            var_Change( p_input, "menu-popup", VLC_VAR_SETTEXT, &text, NULL );
            var_AddCallback( p_input, "menu-popup", TitleCallback, NULL );
        }
Laurent Aimar's avatar
Laurent Aimar committed
288 289
    }

290
    /* Create titles and chapters */
291 292
    var_Change( p_input, "title", VLC_VAR_CLEARCHOICES, NULL, NULL );

293
    for( int i = 0; i < p_input->p->i_title; i++ )
Laurent Aimar's avatar
Laurent Aimar committed
294
    {
295
        vlc_value_t val2, text2;
296
        char title[sizeof("title ") + 3 * sizeof (int)];
Laurent Aimar's avatar
Laurent Aimar committed
297 298

        /* Add Navigation entries */
299 300 301
        sprintf( title, "title %2u", i );
        var_Destroy( p_input, title );
        var_Create( p_input, title,
302
                    VLC_VAR_INTEGER|VLC_VAR_HASCHOICE|VLC_VAR_ISCOMMAND );
303
        var_AddCallback( p_input, title,
304
                         NavigationCallback, (void *)(intptr_t)i );
Laurent Aimar's avatar
Laurent Aimar committed
305

306
        char psz_length[MSTRTIME_MAX_SIZE + sizeof(" []")];
307 308 309 310 311 312
        if( p_input->p->title[i]->i_length > 0 )
        {
            strcpy( psz_length, " [" );
            secstotimestr( &psz_length[2], p_input->p->title[i]->i_length / CLOCK_FREQ );
            strcat( psz_length, "]" );
        }
313 314
        else
            psz_length[0] = '\0';
315

zorglub's avatar
zorglub committed
316 317
        if( p_input->p->title[i]->psz_name == NULL ||
            *p_input->p->title[i]->psz_name == '\0' )
Laurent Aimar's avatar
Laurent Aimar committed
318
        {
319 320
            if( asprintf( &text.psz_string, _("Title %i%s"),
                          i + p_input->p->i_title_offset, psz_length ) == -1 )
321
                continue;
Laurent Aimar's avatar
Laurent Aimar committed
322 323 324
        }
        else
        {
325 326 327
            if( asprintf( &text.psz_string, "%s%s",
                          p_input->p->title[i]->psz_name, psz_length ) == -1 )
                continue;
Laurent Aimar's avatar
Laurent Aimar committed
328
        }
gbazin's avatar
gbazin committed
329 330 331 332 333

        /* Add title choice */
        val2.i_int = i;
        var_Change( p_input, "title", VLC_VAR_ADDCHOICE, &val2, &text );

Laurent Aimar's avatar
Laurent Aimar committed
334 335
        free( text.psz_string );

336
        for( int j = 0; j < p_input->p->title[i]->i_seekpoint; j++ )
Laurent Aimar's avatar
Laurent Aimar committed
337 338 339
        {
            val2.i_int = j;

zorglub's avatar
zorglub committed
340 341
            if( p_input->p->title[i]->seekpoint[j]->psz_name == NULL ||
                *p_input->p->title[i]->seekpoint[j]->psz_name == '\0' )
Laurent Aimar's avatar
Laurent Aimar committed
342 343
            {
                /* Default value */
344 345 346
                if( asprintf( &text2.psz_string, _("Chapter %i"),
                          j + p_input->p->i_seekpoint_offset ) == -1 )
                    continue;
Laurent Aimar's avatar
Laurent Aimar committed
347 348 349
            }
            else
            {
gbazin's avatar
gbazin committed
350
                text2.psz_string =
zorglub's avatar
zorglub committed
351
                    strdup( p_input->p->title[i]->seekpoint[j]->psz_name );
Laurent Aimar's avatar
Laurent Aimar committed
352 353
            }

354
            var_Change( p_input, title, VLC_VAR_ADDCHOICE, &val2, &text2 );
355
            free( text2.psz_string );
Laurent Aimar's avatar
Laurent Aimar committed
356 357 358 359 360 361 362 363 364 365 366
        }

    }
}

/*****************************************************************************
 * input_ControlVarTitle:
 *  Create all variables for a title
 *****************************************************************************/
void input_ControlVarTitle( input_thread_t *p_input, int i_title )
{
zorglub's avatar
zorglub committed
367
    input_title_t *t = p_input->p->title[i_title];
368
    vlc_value_t text;
Laurent Aimar's avatar
Laurent Aimar committed
369 370 371
    int  i;

    /* Create/Destroy command variables */
372 373 374 375 376
    if( t->i_seekpoint <= 1 )
    {
        var_Destroy( p_input, "next-chapter" );
        var_Destroy( p_input, "prev-chapter" );
    }
377
    else if( var_Type( p_input, "next-chapter" ) == 0 )
Laurent Aimar's avatar
Laurent Aimar committed
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
    {
        var_Create( p_input, "next-chapter", VLC_VAR_VOID );
        text.psz_string = _("Next chapter");
        var_Change( p_input, "next-chapter", VLC_VAR_SETTEXT, &text, NULL );
        var_AddCallback( p_input, "next-chapter", SeekpointCallback, NULL );

        var_Create( p_input, "prev-chapter", VLC_VAR_VOID );
        text.psz_string = _("Previous chapter");
        var_Change( p_input, "prev-chapter", VLC_VAR_SETTEXT, &text, NULL );
        var_AddCallback( p_input, "prev-chapter", SeekpointCallback, NULL );
    }

    /* Build chapter list */
    var_Change( p_input, "chapter", VLC_VAR_CLEARCHOICES, NULL, NULL );
    for( i = 0; i <  t->i_seekpoint; i++ )
    {
394
        vlc_value_t val;
gbazin's avatar
gbazin committed
395 396 397 398 399 400
        val.i_int = i;

        if( t->seekpoint[i]->psz_name == NULL ||
            *t->seekpoint[i]->psz_name == '\0' )
        {
            /* Default value */
401 402 403
            if( asprintf( &text.psz_string, _("Chapter %i"),
                      i + p_input->p->i_seekpoint_offset ) == -1 )
                continue;
gbazin's avatar
gbazin committed
404 405 406 407 408 409 410
        }
        else
        {
            text.psz_string = strdup( t->seekpoint[i]->psz_name );
        }

        var_Change( p_input, "chapter", VLC_VAR_ADDCHOICE, &val, &text );
411
        free( text.psz_string );
Laurent Aimar's avatar
Laurent Aimar committed
412 413 414 415 416 417 418 419 420 421 422
    }
}

/*****************************************************************************
 * input_ConfigVarInit:
 *  Create all config object variables
 *****************************************************************************/
void input_ConfigVarInit ( input_thread_t *p_input )
{
    /* Create Object Variables for private use only */

423 424 425 426 427 428 429 430 431 432 433 434 435
    if( !p_input->b_preparsing )
    {
        var_Create( p_input, "video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
        var_Create( p_input, "audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
        var_Create( p_input, "spu", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );

        var_Create( p_input, "audio-track", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
        var_Create( p_input, "sub-track", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );

        var_Create( p_input, "audio-language",
                    VLC_VAR_STRING|VLC_VAR_DOINHERIT );
        var_Create( p_input, "sub-language",
                    VLC_VAR_STRING|VLC_VAR_DOINHERIT );
436 437
        var_Create( p_input, "menu-language",
                    VLC_VAR_STRING|VLC_VAR_DOINHERIT );
438 439 440 441 442 443

        var_Create( p_input, "audio-track-id",
                    VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
        var_Create( p_input, "sub-track-id",
                    VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );

444
        var_Create( p_input, "sub-file", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
        var_Create( p_input, "sub-autodetect-file", VLC_VAR_BOOL |
                    VLC_VAR_DOINHERIT );
        var_Create( p_input, "sub-autodetect-path", VLC_VAR_STRING |
                    VLC_VAR_DOINHERIT );
        var_Create( p_input, "sub-autodetect-fuzzy", VLC_VAR_INTEGER |
                    VLC_VAR_DOINHERIT );

        var_Create( p_input, "sout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
        var_Create( p_input, "sout-all",   VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
        var_Create( p_input, "sout-audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
        var_Create( p_input, "sout-video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
        var_Create( p_input, "sout-spu", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
        var_Create( p_input, "sout-keep",  VLC_VAR_BOOL | VLC_VAR_DOINHERIT );

        var_Create( p_input, "input-repeat",
                    VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
461 462 463
        var_Create( p_input, "start-time", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT );
        var_Create( p_input, "stop-time", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT );
        var_Create( p_input, "run-time", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT );
464
        var_Create( p_input, "input-fast-seek", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
465 466 467 468 469 470 471 472 473 474 475

        var_Create( p_input, "input-slave",
                    VLC_VAR_STRING | VLC_VAR_DOINHERIT );

        var_Create( p_input, "audio-desync",
                    VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
        var_Create( p_input, "cr-average",
                    VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
        var_Create( p_input, "clock-synchro",
                    VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
    }
Laurent Aimar's avatar
Laurent Aimar committed
476

477 478
    var_Create( p_input, "can-seek", VLC_VAR_BOOL );
    var_SetBool( p_input, "can-seek", true ); /* Fixed later*/
479

480
    var_Create( p_input, "can-pause", VLC_VAR_BOOL );
481 482
    var_SetBool( p_input, "can-pause", true ); /* Fixed later*/

483 484 485
    var_Create( p_input, "can-rate", VLC_VAR_BOOL );
    var_SetBool( p_input, "can-rate", false );

486 487 488
    var_Create( p_input, "can-rewind", VLC_VAR_BOOL );
    var_SetBool( p_input, "can-rewind", false );

489 490 491 492 493 494
    var_Create( p_input, "can-record", VLC_VAR_BOOL );
    var_SetBool( p_input, "can-record", false ); /* Fixed later*/

    var_Create( p_input, "record", VLC_VAR_BOOL );
    var_SetBool( p_input, "record", false );

495 496
    var_Create( p_input, "teletext-es", VLC_VAR_INTEGER );
    var_SetInteger( p_input, "teletext-es", -1 );
497

498 499 500 501 502 503
    var_Create( p_input, "signal-quality", VLC_VAR_FLOAT );
    var_SetFloat( p_input, "signal-quality", -1 );

    var_Create( p_input, "signal-strength", VLC_VAR_FLOAT );
    var_SetFloat( p_input, "signal-strength", -1 );

504 505 506
    var_Create( p_input, "program-scrambled", VLC_VAR_BOOL );
    var_SetBool( p_input, "program-scrambled", false );

507 508 509
    var_Create( p_input, "cache", VLC_VAR_FLOAT );
    var_SetFloat( p_input, "cache", 0.0 );

510 511 512
    /* */
    var_Create( p_input, "input-record-native", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );

513
    /* */
514 515
    var_Create( p_input, "access", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
    var_Create( p_input, "demux", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
516
    var_Create( p_input, "demux-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
517
    var_Create( p_input, "stream-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
518

519 520 521 522 523 524 525 526 527
    /* Meta */
    var_Create( p_input, "meta-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
    var_Create( p_input, "meta-author", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
    var_Create( p_input, "meta-artist", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
    var_Create( p_input, "meta-genre", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
    var_Create( p_input, "meta-copyright", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
    var_Create( p_input, "meta-description", VLC_VAR_STRING|VLC_VAR_DOINHERIT);
    var_Create( p_input, "meta-date", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
    var_Create( p_input, "meta-url", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
Laurent Aimar's avatar
Laurent Aimar committed
528 529
}

530 531 532 533 534 535 536 537 538 539 540 541
/*****************************************************************************
 * Callbacks managements:
 *****************************************************************************/
static void InputAddCallbacks( input_thread_t *p_input,
                               const vlc_input_callback_t *p_callbacks )
{
    int i;
    for( i = 0; p_callbacks[i].psz_name != NULL; i++ )
        var_AddCallback( p_input,
                         p_callbacks[i].psz_name,
                         p_callbacks[i].callback, NULL );
}
542

543 544 545 546 547 548 549 550 551
static void InputDelCallbacks( input_thread_t *p_input,
                               const vlc_input_callback_t *p_callbacks )
{
    int i;
    for( i = 0; p_callbacks[i].psz_name != NULL; i++ )
        var_DelCallback( p_input,
                         p_callbacks[i].psz_name,
                         p_callbacks[i].callback, NULL );
}
552

Laurent Aimar's avatar
Laurent Aimar committed
553 554 555
/*****************************************************************************
 * All Callbacks:
 *****************************************************************************/
556 557 558
static int StateCallback( vlc_object_t *p_this, char const *psz_cmd,
                          vlc_value_t oldval, vlc_value_t newval,
                          void *p_data )
Laurent Aimar's avatar
Laurent Aimar committed
559 560
{
    input_thread_t *p_input = (input_thread_t*)p_this;
561
    VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
Laurent Aimar's avatar
Laurent Aimar committed
562 563 564 565 566 567 568 569 570

    if( newval.i_int == PLAYING_S || newval.i_int == PAUSE_S )
    {
        input_ControlPush( p_input, INPUT_CONTROL_SET_STATE, &newval );
        return VLC_SUCCESS;
    }

    return VLC_EGENERIC;
}
Jean-Paul Saman's avatar
Jean-Paul Saman committed
571

572 573
static int RateCallback( vlc_object_t *p_this, char const *psz_cmd,
                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
Laurent Aimar's avatar
Laurent Aimar committed
574 575
{
    input_thread_t *p_input = (input_thread_t*)p_this;
576 577 578 579 580 581 582 583
    VLC_UNUSED(oldval); VLC_UNUSED(p_data); VLC_UNUSED(psz_cmd);

    newval.i_int = INPUT_RATE_DEFAULT / newval.f_float;
    input_ControlPush( p_input, INPUT_CONTROL_SET_RATE, &newval );

    return VLC_SUCCESS;
}

Laurent Aimar's avatar
Laurent Aimar committed
584
static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
585 586
                             vlc_value_t oldval, vlc_value_t newval,
                             void *p_data )
Laurent Aimar's avatar
Laurent Aimar committed
587 588 589
{
    input_thread_t *p_input = (input_thread_t*)p_this;

590
    VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
Laurent Aimar's avatar
Laurent Aimar committed
591

592 593 594 595 596
    /* Update "length" for better intf behaviour */
    const int64_t i_length = var_GetInteger( p_input, "length" );
    if( i_length > 0 && newval.f_float >= 0.f && newval.f_float <= 1.f )
    {
        vlc_value_t val;
Laurent Aimar's avatar
Laurent Aimar committed
597

598 599
        val.i_int = i_length * newval.f_float;
        var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
600
    }
601 602

    input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &newval );
Laurent Aimar's avatar
Laurent Aimar committed
603 604 605
    return VLC_SUCCESS;
}

606 607
static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
Laurent Aimar's avatar
Laurent Aimar committed
608 609
{
    input_thread_t *p_input = (input_thread_t*)p_this;
610
    VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
Laurent Aimar's avatar
Laurent Aimar committed
611

Steve Lhomme's avatar
Steve Lhomme committed
612
    /* Update "position" for better intf behaviour */
613 614
    const int64_t i_length = var_GetInteger( p_input, "length" );
    if( i_length > 0 && newval.i_int >= 0 && newval.i_int <= i_length )
Laurent Aimar's avatar
Laurent Aimar committed
615
    {
616 617
        vlc_value_t val;

618
        val.f_float = (double)newval.i_int/(double)i_length;
619 620 621 622 623 624
        var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
        /*
         * Notify the intf that a new event has been occurred.
         * XXX this is a bit hackish but it's the only way to do it now.
         */
        var_SetInteger( p_input, "intf-event", INPUT_EVENT_POSITION );
Laurent Aimar's avatar
Laurent Aimar committed
625 626
    }

627 628 629
    input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval );
    return VLC_SUCCESS;
}
Laurent Aimar's avatar
Laurent Aimar committed
630

631 632 633 634 635
static int TimeOffsetCallback( vlc_object_t *obj, char const *varname,
                               vlc_value_t prev, vlc_value_t cur, void *data )
{
    VLC_UNUSED(varname); VLC_UNUSED(prev); VLC_UNUSED(data);

636
    int64_t i_time = var_GetInteger( obj, "time" ) + cur.i_int;
637 638
    if( i_time < 0 )
        i_time = 0;
639
    var_SetInteger( obj, "time", i_time );
Laurent Aimar's avatar
Laurent Aimar committed
640 641 642
    return VLC_SUCCESS;
}

643 644 645
static int ProgramCallback( vlc_object_t *p_this, char const *psz_cmd,
                            vlc_value_t oldval, vlc_value_t newval,
                            void *p_data )
Laurent Aimar's avatar
Laurent Aimar committed
646 647
{
    input_thread_t *p_input = (input_thread_t*)p_this;
648
    VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
Laurent Aimar's avatar
Laurent Aimar committed
649 650 651 652 653 654

    input_ControlPush( p_input, INPUT_CONTROL_SET_PROGRAM, &newval );

    return VLC_SUCCESS;
}

655 656 657
static int TitleCallback( vlc_object_t *p_this, char const *psz_cmd,
                          vlc_value_t oldval, vlc_value_t newval,
                          void *p_data )
Laurent Aimar's avatar
Laurent Aimar committed
658 659 660
{
    input_thread_t *p_input = (input_thread_t*)p_this;
    vlc_value_t val, count;
661
    VLC_UNUSED(oldval); VLC_UNUSED(p_data);
Laurent Aimar's avatar
Laurent Aimar committed
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679

    if( !strcmp( psz_cmd, "next-title" ) )
    {
        input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE_NEXT, NULL );

        val.i_int = var_GetInteger( p_input, "title" ) + 1;
        var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &count, NULL );
        if( val.i_int < count.i_int )
            var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
    }
    else if( !strcmp( psz_cmd, "prev-title" ) )
    {
        input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE_PREV, NULL );

        val.i_int = var_GetInteger( p_input, "title" ) - 1;
        if( val.i_int >= 0 )
            var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
    }
680 681 682 683
    else if( !strcmp( psz_cmd, "menu-title" ) )
    {
        input_ControlPush( p_input, INPUT_CONTROL_NAV_MENU, NULL );
    }
684 685 686 687
    else if( !strcmp( psz_cmd, "menu-popup" ) )
    {
        input_ControlPush( p_input, INPUT_CONTROL_NAV_POPUP, NULL );
    }
Laurent Aimar's avatar
Laurent Aimar committed
688 689 690 691 692 693 694 695 696
    else
    {
        input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &newval );
    }

    return VLC_SUCCESS;
}

static int SeekpointCallback( vlc_object_t *p_this, char const *psz_cmd,
697 698
                              vlc_value_t oldval, vlc_value_t newval,
                              void *p_data )
Laurent Aimar's avatar
Laurent Aimar committed
699 700 701
{
    input_thread_t *p_input = (input_thread_t*)p_this;
    vlc_value_t val, count;
702
    VLC_UNUSED(oldval); VLC_UNUSED(p_data);
Laurent Aimar's avatar
Laurent Aimar committed
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729

    if( !strcmp( psz_cmd, "next-chapter" ) )
    {
        input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT_NEXT, NULL );

        val.i_int = var_GetInteger( p_input, "chapter" ) + 1;
        var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &count, NULL );
        if( val.i_int < count.i_int )
            var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
    }
    else if( !strcmp( psz_cmd, "prev-chapter" ) )
    {
        input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT_PREV, NULL );

        val.i_int = var_GetInteger( p_input, "chapter" ) - 1;
        if( val.i_int >= 0 )
            var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
    }
    else
    {
        input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &newval );
    }

    return VLC_SUCCESS;
}

static int NavigationCallback( vlc_object_t *p_this, char const *psz_cmd,
730 731
                               vlc_value_t oldval, vlc_value_t newval,
                               void *p_data )
Laurent Aimar's avatar
Laurent Aimar committed
732 733 734
{
    input_thread_t *p_input = (input_thread_t*)p_this;
    vlc_value_t     val;
735
    VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
Laurent Aimar's avatar
Laurent Aimar committed
736 737

    /* Issue a title change */
738
    val.i_int = (intptr_t)p_data;
Laurent Aimar's avatar
Laurent Aimar committed
739 740 741 742 743 744 745 746 747 748 749 750
    input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );

    var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );

    /* And a chapter change */
    input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &newval );

    var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &newval, NULL );

    return VLC_SUCCESS;
}

751 752
static int ESCallback( vlc_object_t *p_this, char const *psz_cmd,
                       vlc_value_t oldval, vlc_value_t newval, void *p_data )
Laurent Aimar's avatar
Laurent Aimar committed
753 754
{
    input_thread_t *p_input = (input_thread_t*)p_this;
755
    VLC_UNUSED(oldval); VLC_UNUSED(p_data);
Laurent Aimar's avatar
Laurent Aimar committed
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779

    if( newval.i_int < 0 )
    {
        vlc_value_t v;
        /* Hack */
        if( !strcmp( psz_cmd, "audio-es" ) )
            v.i_int = -AUDIO_ES;
        else if( !strcmp( psz_cmd, "video-es" ) )
            v.i_int = -VIDEO_ES;
        else if( !strcmp( psz_cmd, "spu-es" ) )
            v.i_int = -SPU_ES;
        else
            v.i_int = 0;
        if( v.i_int != 0 )
            input_ControlPush( p_input, INPUT_CONTROL_SET_ES, &v );
    }
    else
    {
        input_ControlPush( p_input, INPUT_CONTROL_SET_ES, &newval );
    }

    return VLC_SUCCESS;
}

780
static int EsDelayCallback ( vlc_object_t *p_this, char const *psz_cmd,
781
                             vlc_value_t oldval, vlc_value_t newval, void *p_data )
782 783
{
    input_thread_t *p_input = (input_thread_t*)p_this;
784
    VLC_UNUSED(oldval); VLC_UNUSED(p_data);
785

786
    if( !strcmp( psz_cmd, "audio-delay" ) )
zorglub's avatar
zorglub committed
787
    {
788
        input_ControlPush( p_input, INPUT_CONTROL_SET_AUDIO_DELAY, &newval );
zorglub's avatar
zorglub committed
789
    }
790
    else if( !strcmp( psz_cmd, "spu-delay" ) )
791
    {
792
        input_ControlPush( p_input, INPUT_CONTROL_SET_SPU_DELAY, &newval );
793
    }
794 795 796
    return VLC_SUCCESS;
}

Laurent Aimar's avatar
Laurent Aimar committed
797
static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
798 799
                             vlc_value_t oldval, vlc_value_t newval,
                             void *p_data )
Laurent Aimar's avatar
Laurent Aimar committed
800 801
{
    input_thread_t *p_input = (input_thread_t*)p_this;
802
    VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
Laurent Aimar's avatar
Laurent Aimar committed
803 804 805 806 807

    input_ControlPush( p_input, INPUT_CONTROL_SET_BOOKMARK, &newval );

    return VLC_SUCCESS;
}
808 809 810 811 812 813 814 815 816 817 818 819

static int RecordCallback( vlc_object_t *p_this, char const *psz_cmd,
                           vlc_value_t oldval, vlc_value_t newval,
                           void *p_data )
{
    input_thread_t *p_input = (input_thread_t*)p_this;
    VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);

    input_ControlPush( p_input, INPUT_CONTROL_SET_RECORD_STATE, &newval );

    return VLC_SUCCESS;
}
820

821 822 823 824 825 826
static int FrameNextCallback( vlc_object_t *p_this, char const *psz_cmd,
                              vlc_value_t oldval, vlc_value_t newval,
                              void *p_data )
{
    input_thread_t *p_input = (input_thread_t*)p_this;
    VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
Laurent Aimar's avatar
Laurent Aimar committed
827
    VLC_UNUSED(newval);
828 829 830 831 832 833

    input_ControlPush( p_input, INPUT_CONTROL_SET_FRAME_NEXT, NULL );

    return VLC_SUCCESS;
}