X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Finput%2Fvar.c;h=258b5f4584433a78de0ad708f4f2ee0cc75efc90;hb=426d82731aa74530af562c3fa09ce7a2eeb45c6a;hp=c61f3579b7f803d4daed9c59b824b993cc4d6c0a;hpb=d6f0bd78c5aaae605b7894777d4d8eddb6fdaddb;p=vlc diff --git a/src/input/var.c b/src/input/var.c index c61f3579b7..258b5f4584 100644 --- a/src/input/var.c +++ b/src/input/var.c @@ -1,24 +1,24 @@ /***************************************************************************** * var.c: object variables for input thread ***************************************************************************** - * Copyright (C) 2004-2007 the VideoLAN team + * Copyright (C) 2004-2007 VLC authors and VideoLAN * $Id$ * * Authors: Laurent Aimar * - * 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 + * 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 * (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. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + * 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. *****************************************************************************/ /***************************************************************************** @@ -29,6 +29,8 @@ #endif #include +#include +#include #include #include @@ -68,9 +70,6 @@ static int FrameNextCallback( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data ); -static int IntfEvent( vlc_object_t *p_this, char const *psz_cmd, - vlc_value_t oldval, vlc_value_t newval, void *p_data ); - typedef struct { const char *psz_name; @@ -89,8 +88,6 @@ static const vlc_input_callback_t p_input_callbacks[] = { CALLBACK( "state", StateCallback ), CALLBACK( "rate", RateCallback ), - CALLBACK( "rate-slower", RateCallback ), - CALLBACK( "rate-faster", RateCallback ), CALLBACK( "position", PositionCallback ), CALLBACK( "position-offset", PositionCallback ), CALLBACK( "time", TimeCallback ), @@ -135,17 +132,11 @@ void input_ControlVarInit ( input_thread_t *p_input ) /* State */ var_Create( p_input, "state", VLC_VAR_INTEGER ); - val.i_int = p_input->i_state; + val.i_int = p_input->p->i_state; var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL ); /* Rate */ - var_Create( p_input, "rate", VLC_VAR_INTEGER ); - val.i_int = p_input->p->i_rate; - var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL ); - - var_Create( p_input, "rate-slower", VLC_VAR_VOID ); - - var_Create( p_input, "rate-faster", VLC_VAR_VOID ); + var_Create( p_input, "rate", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT ); var_Create( p_input, "frame-next", VLC_VAR_VOID ); @@ -177,7 +168,7 @@ void input_ControlVarInit ( input_thread_t *p_input ) var_Change( p_input, "program", VLC_VAR_SETTEXT, &text, NULL ); /* Programs */ - var_Create( p_input, "programs", VLC_VAR_LIST | VLC_VAR_DOINHERIT ); + var_Create( p_input, "programs", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); text.psz_string = _("Programs"); var_Change( p_input, "programs", VLC_VAR_SETTEXT, &text, NULL ); @@ -216,9 +207,13 @@ void input_ControlVarInit ( input_thread_t *p_input ) /* Spu ES */ var_Create( p_input, "spu-es", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE ); - text.psz_string = _("Subtitles Track"); + text.psz_string = _("Subtitle Track"); var_Change( p_input, "spu-es", VLC_VAR_SETTEXT, &text, NULL ); + var_Create( p_input, "spu-choice", VLC_VAR_INTEGER ); + val.i_int = -1; + var_Change( p_input, "spu-choice", VLC_VAR_SETVALUE, &val, NULL ); + /* Special read only objects variables for intf */ var_Create( p_input, "bookmarks", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); @@ -226,28 +221,13 @@ void input_ControlVarInit ( input_thread_t *p_input ) val.i_time = 0; var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL ); + var_Create( p_input, "bit-rate", VLC_VAR_INTEGER ); + var_Create( p_input, "sample-rate", VLC_VAR_INTEGER ); + if( !p_input->b_preparsing ) { /* Special "intf-event" variable. */ var_Create( p_input, "intf-event", VLC_VAR_INTEGER ); - - /* Callback for legacy variables */ - var_AddCallback( p_input, "intf-event", IntfEvent, NULL ); - - /* Legacy variable - * TODO remove them when unused */ - static const char *ppsz_event[] = { - "intf-change", - "rate-change", - "stats-change", - "intf-change-vout", - NULL - }; - for( int i = 0; ppsz_event[i] != NULL; i++ ) - { - var_Create( p_input, ppsz_event[i], VLC_VAR_BOOL ); - var_SetBool( p_input, ppsz_event[i], true ); - } } /* Add all callbacks @@ -262,7 +242,8 @@ void input_ControlVarInit ( input_thread_t *p_input ) *****************************************************************************/ void input_ControlVarStop( input_thread_t *p_input ) { - InputDelCallbacks( p_input, p_input_callbacks ); + if( !p_input->b_preparsing ) + InputDelCallbacks( p_input, p_input_callbacks ); if( p_input->p->i_title > 0 ) { @@ -308,6 +289,8 @@ void input_ControlVarNavigation( input_thread_t *p_input ) if( !val.psz_string ) return; + var_Change( p_input, "title", VLC_VAR_CLEARCHOICES, NULL, NULL ); + for( i = 0; i < p_input->p->i_title; i++ ) { vlc_value_t val2, text2; @@ -321,16 +304,26 @@ void input_ControlVarNavigation( input_thread_t *p_input ) var_AddCallback( p_input, val.psz_string, NavigationCallback, (void *)(intptr_t)i ); + char psz_length[MSTRTIME_MAX_SIZE + sizeof(" []")] = ""; + 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, "]" ); + } + if( p_input->p->title[i]->psz_name == NULL || *p_input->p->title[i]->psz_name == '\0' ) { - if( asprintf( &text.psz_string, _("Title %i"), - i + p_input->p->i_title_offset ) == -1 ) + if( asprintf( &text.psz_string, _("Title %i%s"), + i + p_input->p->i_title_offset, psz_length ) == -1 ) continue; } else { - text.psz_string = strdup( p_input->p->title[i]->psz_name ); + if( asprintf( &text.psz_string, "%s%s", + p_input->p->title[i]->psz_name, psz_length ) == -1 ) + continue; } var_Change( p_input, "navigation", VLC_VAR_ADDCHOICE, &val, &text ); @@ -374,7 +367,7 @@ void input_ControlVarNavigation( input_thread_t *p_input ) void input_ControlVarTitle( input_thread_t *p_input, int i_title ) { input_title_t *t = p_input->p->title[i_title]; - vlc_value_t val, text; + vlc_value_t text; int i; /* Create/Destroy command variables */ @@ -383,7 +376,7 @@ void input_ControlVarTitle( input_thread_t *p_input, int i_title ) var_Destroy( p_input, "next-chapter" ); var_Destroy( p_input, "prev-chapter" ); } - else if( var_Get( p_input, "next-chapter", &val ) != VLC_SUCCESS ) + else if( var_Type( p_input, "next-chapter" ) == 0 ) { var_Create( p_input, "next-chapter", VLC_VAR_VOID ); text.psz_string = _("Next chapter"); @@ -400,6 +393,7 @@ void input_ControlVarTitle( input_thread_t *p_input, int i_title ) var_Change( p_input, "chapter", VLC_VAR_CLEARCHOICES, NULL, NULL ); for( i = 0; i < t->i_seekpoint; i++ ) { + vlc_value_t val; val.i_int = i; if( t->seekpoint[i]->psz_name == NULL || @@ -441,13 +435,15 @@ void input_ConfigVarInit ( input_thread_t *p_input ) VLC_VAR_STRING|VLC_VAR_DOINHERIT ); var_Create( p_input, "sub-language", VLC_VAR_STRING|VLC_VAR_DOINHERIT ); + var_Create( p_input, "menu-language", + VLC_VAR_STRING|VLC_VAR_DOINHERIT ); 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 ); - var_Create( p_input, "sub-file", VLC_VAR_FILE | VLC_VAR_DOINHERIT ); + var_Create( p_input, "sub-file", VLC_VAR_STRING | 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 | @@ -464,9 +460,10 @@ void input_ConfigVarInit ( input_thread_t *p_input ) 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, "run-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT ); + 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 ); + var_Create( p_input, "input-fast-seek", VLC_VAR_BOOL|VLC_VAR_DOINHERIT ); var_Create( p_input, "input-slave", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); @@ -479,8 +476,8 @@ void input_ConfigVarInit ( input_thread_t *p_input ) VLC_VAR_INTEGER | VLC_VAR_DOINHERIT); } - var_Create( p_input, "seekable", VLC_VAR_BOOL ); - var_SetBool( p_input, "seekable", true ); /* Fixed later*/ + var_Create( p_input, "can-seek", VLC_VAR_BOOL ); + var_SetBool( p_input, "can-seek", true ); /* Fixed later*/ var_Create( p_input, "can-pause", VLC_VAR_BOOL ); var_SetBool( p_input, "can-pause", true ); /* Fixed later*/ @@ -506,10 +503,19 @@ void input_ConfigVarInit ( input_thread_t *p_input ) var_Create( p_input, "signal-strength", VLC_VAR_FLOAT ); var_SetFloat( p_input, "signal-strength", -1 ); + var_Create( p_input, "program-scrambled", VLC_VAR_BOOL ); + var_SetBool( p_input, "program-scrambled", false ); + + var_Create( p_input, "cache", VLC_VAR_FLOAT ); + var_SetFloat( p_input, "cache", 0.0 ); + + /* */ + var_Create( p_input, "input-record-native", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); + /* */ - var_Create( p_input, "access-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_Create( p_input, "access", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_Create( p_input, "demux", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); + var_Create( p_input, "stream-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); /* Meta */ var_Create( p_input, "meta-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); @@ -568,21 +574,11 @@ static int RateCallback( 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(oldval); VLC_UNUSED(p_data); + 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 ); - /* 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 ); - } - else if( !strcmp( psz_cmd, "rate-faster" ) ) - { - input_ControlPush( p_input, INPUT_CONTROL_SET_RATE_FASTER, NULL ); - } - else - { - input_ControlPush( p_input, INPUT_CONTROL_SET_RATE, &newval ); - } return VLC_SUCCESS; } @@ -591,32 +587,32 @@ static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd, void *p_data ) { input_thread_t *p_input = (input_thread_t*)p_this; - vlc_value_t val, length; VLC_UNUSED(oldval); VLC_UNUSED(p_data); 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 ); + float f_position = var_GetFloat( p_input, "position" ) + newval.f_float; + if( f_position < 0.f ) + f_position = 0.f; + else if( f_position > 1.f ) + f_position = 1.f; + var_SetFloat( p_this, "position", f_position ); } else { - val.f_float = newval.f_float; - input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &newval ); - } + /* Update "length" for better intf behavour */ + const mtime_t i_length = var_GetTime( p_input, "length" ); + if( i_length > 0 && newval.f_float >= 0.f && newval.f_float <= 1.f ) + { + vlc_value_t val; - /* 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 ); - } + val.i_time = i_length * newval.f_float; + var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL ); + } + /* */ + input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &newval ); + } return VLC_SUCCESS; } @@ -624,31 +620,35 @@ static int TimeCallback( 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_value_t val, length; VLC_UNUSED(oldval); VLC_UNUSED(p_data); 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 ); + mtime_t i_time = var_GetTime( p_input, "time" ) + newval.i_time; + if( i_time < 0 ) + i_time = 0; + var_SetTime( p_this, "time", i_time ); } else { - val.i_time = newval.i_time; - input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval ); - } + /* Update "position" for better intf behavour */ + const mtime_t i_length = var_GetTime( p_input, "length" ); + if( i_length > 0 && newval.i_time >= 0 && newval.i_time <= i_length ) + { + vlc_value_t val; + + val.f_float = (double)newval.i_time/(double)i_length; + 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 ); + } - /* 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 ); + /* */ + input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval ); } - return VLC_SUCCESS; } @@ -789,11 +789,6 @@ static int EsDelayCallback ( vlc_object_t *p_this, char const *psz_cmd, if( !strcmp( psz_cmd, "audio-delay" ) ) { - /* Change i_pts_delay to make sure es are decoded in time */ - if( newval.i_int < 0 || oldval.i_int < 0 ) - { - p_input->i_pts_delay -= newval.i_int - oldval.i_int; - } input_ControlPush( p_input, INPUT_CONTROL_SET_AUDIO_DELAY, &newval ); } else if( !strcmp( psz_cmd, "spu-delay" ) ) @@ -840,21 +835,3 @@ static int FrameNextCallback( vlc_object_t *p_this, char const *psz_cmd, return VLC_SUCCESS; } -static int IntfEvent( vlc_object_t *p_this, char const *psz_cmd, - vlc_value_t oldval, vlc_value_t newval, void *p_data ) -{ - VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data); - switch( newval.i_int ) - { - case INPUT_EVENT_RATE: - return var_SetBool( p_this, "rate-change", true ); - case INPUT_EVENT_STATISTICS: - return var_SetBool( p_this, "stats-change", true ); - case INPUT_EVENT_VOUT: - return var_SetBool( p_this, "intf-change-vout", true ); - - default: - return var_SetBool( p_this, "intf-change", true ); - } -} -