var.c 26.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
/*****************************************************************************
 * var.c: object variables for input thread
 *****************************************************************************
 * Copyright (C) 2004 VideoLAN
 * $Id: input.c 7955 2004-06-07 22:21:33Z fenrir $
 *
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (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
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include <stdlib.h>
#include <vlc/vlc.h>
#include <vlc/input.h>

#include "input_internal.h"

/*****************************************************************************
 * Exported prototypes
 *****************************************************************************/
void input_ControlVarInit ( input_thread_t * );
void input_ControlVarClean( input_thread_t * );
void input_ControlVarNavigation( input_thread_t * );
void input_ControlVarTitle( input_thread_t *p_input, int i_title );

void input_ConfigVarInit ( input_thread_t *p_input );


/*****************************************************************************
 * 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 * );
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 * );
65 66 67
static int EsDelayCallback ( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void * );

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void * );

/*****************************************************************************
 * 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 );
    val.i_int = p_input->i_state;
    var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
    var_AddCallback( p_input, "state", StateCallback, NULL );

    /* Rate */
    var_Create( p_input, "rate", VLC_VAR_INTEGER );
    val.i_int = p_input->i_rate;
    var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
    var_AddCallback( p_input, "rate", RateCallback, NULL );

    var_Create( p_input, "rate-slower", VLC_VAR_VOID );
    var_AddCallback( p_input, "rate-slower", RateCallback, NULL );

    var_Create( p_input, "rate-faster", VLC_VAR_VOID );
    var_AddCallback( p_input, "rate-faster", RateCallback, NULL );


    /* Position */
    var_Create( p_input, "position",  VLC_VAR_FLOAT );
    var_Create( p_input, "position-offset",  VLC_VAR_FLOAT );
    val.f_float = 0.0;
    var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
    var_AddCallback( p_input, "position", PositionCallback, NULL );
    var_AddCallback( p_input, "position-offset", PositionCallback, NULL );

    /* Time */
    var_Create( p_input, "time",  VLC_VAR_TIME );
    var_Create( p_input, "time-offset",  VLC_VAR_TIME );    /* relative */
    val.i_time = 0;
    var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
    var_AddCallback( p_input, "time", TimeCallback, NULL );
    var_AddCallback( p_input, "time-offset", TimeCallback, NULL );


    /* 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 );
    var_AddCallback( p_input, "bookmark", BookmarkCallback, 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 );
    var_AddCallback( p_input, "program", ProgramCallback, NULL );

133 134 135 136 137
    /* Programs */
    var_Create( p_input, "programs", VLC_VAR_LIST | VLC_VAR_DOINHERIT );
    text.psz_string = _("Programs");
    var_Change( p_input, "programs", VLC_VAR_SETTEXT, &text, NULL );

138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
    /* 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 );
    var_AddCallback( p_input, "title", TitleCallback, 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 );
    var_AddCallback( p_input, "chapter", SeekpointCallback, NULL );

    /* Navigation The callback is added after */
    var_Create( p_input, "navigation", VLC_VAR_VARIABLE | VLC_VAR_HASCHOICE );
    text.psz_string = _("Navigation");
    var_Change( p_input, "navigation", VLC_VAR_SETTEXT, &text, NULL );

155 156 157 158 159 160 161 162 163 164 165
    /* Delay */
    var_Create( p_input, "audio-delay", VLC_VAR_TIME );
    val.i_time = 0;
    var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
    var_AddCallback( p_input, "audio-delay", EsDelayCallback, NULL );
    var_Create( p_input, "spu-delay", VLC_VAR_TIME );
    val.i_time = 0;
    var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
    var_AddCallback( p_input, "spu-delay", EsDelayCallback, NULL );


166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
    /* 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 );
    var_AddCallback( p_input, "video-es", ESCallback, 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 );
    var_AddCallback( p_input, "audio-es", ESCallback, NULL );

    /* Spu ES */
    var_Create( p_input, "spu-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE );
    text.psz_string = _("Subtitles Track");
    var_Change( p_input, "spu-es", VLC_VAR_SETTEXT, &text, NULL );
    var_AddCallback( p_input, "spu-es", ESCallback, NULL );


    /* Special read only objects variables for intf */
    var_Create( p_input, "bookmarks", VLC_VAR_STRING | VLC_VAR_DOINHERIT );

    var_Create( p_input, "length",  VLC_VAR_TIME );
    val.i_time = 0;
    var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );



   /* Special "intf-change" variable, it allows intf to set up a callback
     * to be notified of some changes.
     * TODO list all changes warn by this callbacks */
    var_Create( p_input, "intf-change", VLC_VAR_BOOL );
    var_SetBool( p_input, "intf-change", VLC_TRUE );
}

/*****************************************************************************
 * input_ControlVarClean:
 *****************************************************************************/
void input_ControlVarClean( input_thread_t *p_input )
{
    var_Destroy( p_input, "state" );
    var_Destroy( p_input, "rate" );
    var_Destroy( p_input, "rate-slower" );
    var_Destroy( p_input, "rate-faster" );
    var_Destroy( p_input, "position" );
    var_Destroy( p_input, "position-offset" );
    var_Destroy( p_input, "time" );
    var_Destroy( p_input, "time-offset" );

215 216 217
    var_Destroy( p_input, "audio-delay" );
    var_Destroy( p_input, "spu-delay" );

218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
    var_Destroy( p_input, "bookmark" );

    var_Destroy( p_input, "program" );
    if( p_input->i_title > 1 )
    {
        /* TODO Destroy sub navigation var ? */

        var_Destroy( p_input, "next-title" );
        var_Destroy( p_input, "prev-title" );
    }
    if( p_input->i_title > 0 )
    {
        /* FIXME title > 0 doesn't mean current title has more than 1 seekpoint */
        var_Destroy( p_input, "next-chapter" );
        var_Destroy( p_input, "prev-chapter" );
    }
    var_Destroy( p_input, "title" );
    var_Destroy( p_input, "chapter" );
    var_Destroy( p_input, "navigation" );

    var_Destroy( p_input, "video-es" );
    var_Destroy( p_input, "audio-es" );
    var_Destroy( p_input, "spu-es" );

    var_Destroy( p_input, "bookmarks" );
    var_Destroy( p_input, "length" );

    var_Destroy( p_input, "intf-change" );
 }

/*****************************************************************************
 * input_ControlVarNavigation:
 *  Create all remaining control object variables
 *****************************************************************************/
void input_ControlVarNavigation( input_thread_t *p_input )
{
    vlc_value_t val, text;
    int  i;

    /* Create more command variables */
    if( p_input->i_title > 1 )
    {
        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 );

        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 );
    }

    /* Create title and navigation */
    val.psz_string = malloc( sizeof("title ") + 5 );
    for( i = 0; i < p_input->i_title; i++ )
    {
        vlc_value_t val2, text, text2;
        int j;

        /* Add Navigation entries */
        sprintf( val.psz_string,  "title %2i", i );
        var_Destroy( p_input, val.psz_string );
281 282
        var_Create( p_input, val.psz_string,
                    VLC_VAR_INTEGER|VLC_VAR_HASCHOICE|VLC_VAR_ISCOMMAND );
Gildas Bazin's avatar
Gildas Bazin committed
283 284
        var_AddCallback( p_input, val.psz_string,
                         NavigationCallback, (void *)i );
285 286 287 288

        if( p_input->title[i]->psz_name == NULL ||
            *p_input->title[i]->psz_name == '\0' )
        {
289 290
            asprintf( &text.psz_string, _("Title %i"),
                      i + p_input->i_title_offset );
291 292 293 294 295 296
        }
        else
        {
            text.psz_string = strdup( p_input->title[i]->psz_name );
        }
        var_Change( p_input, "navigation", VLC_VAR_ADDCHOICE, &val, &text );
Gildas Bazin's avatar
Gildas Bazin committed
297 298 299 300 301

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

302 303 304 305 306 307 308 309 310 311
        free( text.psz_string );

        for( j = 0; j < p_input->title[i]->i_seekpoint; j++ )
        {
            val2.i_int = j;

            if( p_input->title[i]->seekpoint[j]->psz_name == NULL ||
                *p_input->title[i]->seekpoint[j]->psz_name == '\0' )
            {
                /* Default value */
312 313
                asprintf( &text2.psz_string, _("Chapter %i"),
                          j + p_input->i_seekpoint_offset );
314 315 316
            }
            else
            {
Gildas Bazin's avatar
Gildas Bazin committed
317 318
                text2.psz_string =
                    strdup( p_input->title[i]->seekpoint[j]->psz_name );
319 320
            }

Gildas Bazin's avatar
Gildas Bazin committed
321 322
            var_Change( p_input, val.psz_string, VLC_VAR_ADDCHOICE,
                        &val2, &text2 );
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
            if( text2.psz_string ) free( text2.psz_string );
        }

    }
    free( val.psz_string );
}

/*****************************************************************************
 * input_ControlVarTitle:
 *  Create all variables for a title
 *****************************************************************************/
void input_ControlVarTitle( input_thread_t *p_input, int i_title )
{
    input_title_t *t = p_input->title[i_title];
    vlc_value_t val;
    int  i;

    /* Create/Destroy command variables */
341 342 343 344 345 346
    if( t->i_seekpoint <= 1 )
    {
        var_Destroy( p_input, "next-chapter" );
        var_Destroy( p_input, "prev-chapter" );
    }
    else if( var_Get( p_input, "next-chapter", &val ) != VLC_SUCCESS )
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
    {
        vlc_value_t text;

        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++ )
    {
Gildas Bazin's avatar
Gildas Bazin committed
365 366 367 368 369 370 371
        vlc_value_t text;
        val.i_int = i;

        if( t->seekpoint[i]->psz_name == NULL ||
            *t->seekpoint[i]->psz_name == '\0' )
        {
            /* Default value */
372 373
            asprintf( &text.psz_string, _("Chapter %i"),
                      i + p_input->i_seekpoint_offset );
Gildas Bazin's avatar
Gildas Bazin committed
374 375 376 377 378 379 380 381
        }
        else
        {
            text.psz_string = strdup( t->seekpoint[i]->psz_name );
        }

        var_Change( p_input, "chapter", VLC_VAR_ADDCHOICE, &val, &text );
        if( text.psz_string ) free( text.psz_string );
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
    }
}


/*****************************************************************************
 * input_ConfigVarInit:
 *  Create all config object variables
 *****************************************************************************/
void input_ConfigVarInit ( input_thread_t *p_input )
{
    vlc_value_t val;

    /* Create Object Variables for private use only */
    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, "audio-channel", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
    var_Create( p_input, "spu-channel", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );

    var_Create( p_input, "sub-file", VLC_VAR_FILE | VLC_VAR_DOINHERIT );
    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-keep",  VLC_VAR_BOOL | VLC_VAR_DOINHERIT );

    var_Create( p_input, "input-repeat", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );

    var_Create( p_input, "start-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
    var_Create( p_input, "stop-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );

    var_Create( p_input, "minimize-threads", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );

    var_Create( p_input, "demuxed-id3", VLC_VAR_BOOL ); /* FIXME beurk */
    val.b_bool = VLC_FALSE;
    var_Change( p_input, "demuxed-id3", VLC_VAR_SETVALUE, &val, NULL );

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

    var_Create( p_input, "cr-average", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
429 430 431 432 433

    var_Create( p_input, "seekable", VLC_VAR_BOOL );
    val.b_bool = VLC_TRUE; /* Fixed later*/
    var_Change( p_input, "seekable", VLC_VAR_SETVALUE, &val, NULL );

434
    var_Create( p_input, "input-slave", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
435 436 437 438 439 440 441 442 443 444

    /* 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 );
445 446 447 448 449
}

/*****************************************************************************
 * All Callbacks:
 *****************************************************************************/
450 451 452
static int StateCallback( vlc_object_t *p_this, char const *psz_cmd,
                          vlc_value_t oldval, vlc_value_t newval,
                          void *p_data )
453 454 455 456 457 458 459 460 461 462 463 464
{
    input_thread_t *p_input = (input_thread_t*)p_this;


    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;
}
465 466
static int RateCallback( vlc_object_t *p_this, char const *psz_cmd,
                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
{
    input_thread_t *p_input = (input_thread_t*)p_this;
    vlc_value_t val;
    int i_rate;

    /* Problem with this way: the "rate" variable is update after the input thread do the change */
    if( !strcmp( psz_cmd, "rate-slower" ) )
    {
        input_ControlPush( p_input, INPUT_CONTROL_SET_RATE_SLOWER, NULL );

        /* Fix "rate" value */
        i_rate = var_GetInteger( p_input, "rate" ) * 2;
        if( i_rate < INPUT_RATE_MIN ) i_rate = INPUT_RATE_MIN;
        val.i_int = i_rate;
        var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
    }
    else if( !strcmp( psz_cmd, "rate-faster" ) )
    {
        input_ControlPush( p_input, INPUT_CONTROL_SET_RATE_FASTER, NULL );
        i_rate = var_GetInteger( p_input, "rate" ) / 2;

        if( i_rate > INPUT_RATE_MAX ) i_rate = INPUT_RATE_MAX;
        val.i_int = i_rate;
        var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
    }
    else
    {
        input_ControlPush( p_input, INPUT_CONTROL_SET_RATE, &newval );
    }

    return VLC_SUCCESS;
}

static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
501 502
                             vlc_value_t oldval, vlc_value_t newval,
                             void *p_data )
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
{
    input_thread_t *p_input = (input_thread_t*)p_this;
    vlc_value_t val, length;

    if( !strcmp( psz_cmd, "position-offset" ) )
    {
        input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION_OFFSET, &newval );

        val.f_float = var_GetFloat( p_input, "position" ) + newval.f_float;
        if( val.f_float < 0.0 ) val.f_float = 0.0;
        if( val.f_float > 1.0 ) val.f_float = 1.0;
        var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
    }
    else
    {
        val.f_float = newval.f_float;
        input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &newval );
    }

    /* Update "position" for better intf behavour */
    var_Get( p_input, "length", &length );
    if( length.i_time > 0 && val.f_float >= 0.0 && val.f_float <= 1.0 )
    {
        val.i_time = length.i_time * val.f_float;
        var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
    }

    return VLC_SUCCESS;
}


534 535
static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
{
    input_thread_t *p_input = (input_thread_t*)p_this;
    vlc_value_t val, length;

    if( !strcmp( psz_cmd, "time-offset" ) )
    {
        input_ControlPush( p_input, INPUT_CONTROL_SET_TIME_OFFSET, &newval );

        val.i_time = var_GetTime( p_input, "time" ) + newval.i_time;
        if( val.i_time < 0 ) val.i_time = 0;
        /* TODO maybe test against i_length ? */
        var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
    }
    else
    {
        val.i_time = newval.i_time;
        input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval );
    }

    /* Update "position" for better intf behavour */
    var_Get( p_input, "length", &length );
    if( length.i_time > 0 && val.i_time >= 0 && val.i_time <= length.i_time )
    {
        val.f_float = (double)val.i_time/(double)length.i_time;
        var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
    }

    return VLC_SUCCESS;
}

566 567 568
static int ProgramCallback( vlc_object_t *p_this, char const *psz_cmd,
                            vlc_value_t oldval, vlc_value_t newval,
                            void *p_data )
569 570 571 572 573 574 575 576
{
    input_thread_t *p_input = (input_thread_t*)p_this;

    input_ControlPush( p_input, INPUT_CONTROL_SET_PROGRAM, &newval );

    return VLC_SUCCESS;
}

577 578 579
static int TitleCallback( vlc_object_t *p_this, char const *psz_cmd,
                          vlc_value_t oldval, vlc_value_t newval,
                          void *p_data )
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
{
    input_thread_t *p_input = (input_thread_t*)p_this;
    vlc_value_t val, count;

    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 );
    }
    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,
610 611
                              vlc_value_t oldval, vlc_value_t newval,
                              void *p_data )
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
{
    input_thread_t *p_input = (input_thread_t*)p_this;
    vlc_value_t val, count;

    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,
642 643
                               vlc_value_t oldval, vlc_value_t newval,
                               void *p_data )
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
{
    input_thread_t *p_input = (input_thread_t*)p_this;
    vlc_value_t     val;

    /* Issue a title change */
    val.i_int = (int)p_data;
    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;
}

662 663
static int ESCallback( vlc_object_t *p_this, char const *psz_cmd,
                       vlc_value_t oldval, vlc_value_t newval, void *p_data )
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
{
    input_thread_t *p_input = (input_thread_t*)p_this;

    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;
}

690 691 692 693 694 695 696 697 698 699 700 701
static int EsDelayCallback ( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void *p )
{
    input_thread_t *p_input = (input_thread_t*)p_this;

    if( !strcmp( psz_cmd, "audio-delay" ) )
        input_ControlPush( p_input, INPUT_CONTROL_SET_AUDIO_DELAY, &newval );
    else if( !strcmp( psz_cmd, "spu-delay" ) )
        input_ControlPush( p_input, INPUT_CONTROL_SET_SPU_DELAY, &newval );
    return VLC_SUCCESS;
}

702
static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
703 704
                             vlc_value_t oldval, vlc_value_t newval,
                             void *p_data )
705 706 707 708 709 710 711
{
    input_thread_t *p_input = (input_thread_t*)p_this;

    input_ControlPush( p_input, INPUT_CONTROL_SET_BOOKMARK, &newval );

    return VLC_SUCCESS;
}