📄 rc.c
字号:
ADD( "playlist", VOID, Playlist ) ADD( "sort", VOID, Playlist ) ADD( "play", VOID, Playlist ) ADD( "stop", VOID, Playlist ) ADD( "clear", VOID, Playlist ) ADD( "prev", VOID, Playlist ) ADD( "next", VOID, Playlist ) ADD( "goto", INTEGER, Playlist ) ADD( "status", INTEGER, Playlist ) /* OSD menu commands */ ADD( "menu", STRING, Menu ) /* DVD commands */ ADD( "pause", VOID, Input ) ADD( "seek", INTEGER, Input ) ADD( "title", STRING, Input ) ADD( "title_n", VOID, Input ) ADD( "title_p", VOID, Input ) ADD( "chapter", STRING, Input ) ADD( "chapter_n", VOID, Input ) ADD( "chapter_p", VOID, Input ) ADD( "fastforward", VOID, Input ) ADD( "rewind", VOID, Input ) ADD( "faster", VOID, Input ) ADD( "slower", VOID, Input ) ADD( "normal", VOID, Input ) ADD( "atrack", STRING, Input ) ADD( "vtrack", STRING, Input ) ADD( "strack", STRING, Input ) /* video commands */ ADD( "vratio", STRING, VideoConfig ) ADD( "vcrop", STRING, VideoConfig ) ADD( "vzoom", STRING, VideoConfig ) ADD( "snapshot", VOID, VideoConfig ) /* audio commands */ ADD( "volume", STRING, Volume ) ADD( "volup", STRING, VolumeMove ) ADD( "voldown", STRING, VolumeMove ) ADD( "adev", STRING, AudioConfig ) ADD( "achan", STRING, AudioConfig ) /* misc menu commands */ ADD( "stats", BOOL, Statistics )#undef ADD}/***************************************************************************** * Run: rc thread ***************************************************************************** * This part of the interface is in a separate thread so that we can call * exec() from within it without annoying the rest of the program. *****************************************************************************/static void Run( intf_thread_t *p_intf ){ input_thread_t * p_input; playlist_t * p_playlist; char p_buffer[ MAX_LINE_LENGTH + 1 ]; bool b_showpos = config_GetInt( p_intf, "rc-show-pos" ); bool b_longhelp = false; int i_size = 0; int i_oldpos = 0; int i_newpos; p_buffer[0] = 0; p_input = NULL; p_playlist = NULL; /* Register commands that will be cleaned up upon object destruction */ RegisterCallbacks( p_intf ); /* status callbacks */ /* Listen to audio volume updates */ var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );#ifdef WIN32 /* Get the file descriptor of the console input */ p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE); if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE ) { msg_Err( p_intf, "couldn't find user input handle" ); vlc_object_kill( p_intf ); }#endif while( !intf_ShouldDie( p_intf ) ) { char *psz_cmd, *psz_arg; bool b_complete; if( p_intf->p_sys->pi_socket_listen != NULL && p_intf->p_sys->i_socket == -1 ) { p_intf->p_sys->i_socket = net_Accept( p_intf, p_intf->p_sys->pi_socket_listen, INTF_IDLE_SLEEP ); if( p_intf->p_sys->i_socket == -1 ) continue; } b_complete = ReadCommand( p_intf, p_buffer, &i_size ); /* Manage the input part */ if( p_input == NULL ) { if( p_playlist ) { p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT, FIND_CHILD ); } else { p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE ); if( p_input ) { p_playlist = pl_Yield( p_input ); } } /* New input has been registered */ if( p_input ) { if( !p_input->b_dead || vlc_object_alive (p_input) ) { char *psz_uri = input_item_GetURI( input_GetItem( p_input ) ); msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri ); free( psz_uri ); msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_intf, "volume" )); } var_AddCallback( p_input, "state", StateChanged, p_intf ); var_AddCallback( p_input, "rate-faster", RateChanged, p_intf ); var_AddCallback( p_input, "rate-slower", RateChanged, p_intf ); var_AddCallback( p_input, "rate", RateChanged, p_intf ); var_AddCallback( p_input, "time-offset", TimeOffsetChanged, p_intf ); } } else if( p_input->b_dead ) { var_DelCallback( p_input, "state", StateChanged, p_intf ); var_DelCallback( p_input, "rate-faster", RateChanged, p_intf ); var_DelCallback( p_input, "rate-slower", RateChanged, p_intf ); var_DelCallback( p_input, "rate", RateChanged, p_intf ); var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf ); vlc_object_release( p_input ); p_input = NULL; if( p_playlist ) { vlc_object_lock( p_playlist ); p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED; msg_rc( STATUS_CHANGE "( stop state: 0 )" ); vlc_object_unlock( p_playlist ); } } if( (p_input != NULL) && !p_input->b_dead && vlc_object_alive (p_input) && (p_playlist != NULL) ) { vlc_object_lock( p_playlist ); if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) && (p_playlist->status.i_status == PLAYLIST_STOPPED) ) { p_intf->p_sys->i_last_state = PLAYLIST_STOPPED; msg_rc( STATUS_CHANGE "( stop state: 5 )" ); } else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) && (p_playlist->status.i_status == PLAYLIST_RUNNING) ) { p_intf->p_sys->i_last_state = p_playlist->status.i_status; msg_rc( STATUS_CHANGE "( play state: 3 )" ); } else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) && (p_playlist->status.i_status == PLAYLIST_PAUSED) ) { p_intf->p_sys->i_last_state = p_playlist->status.i_status; msg_rc( STATUS_CHANGE "( pause state: 4 )" ); } vlc_object_unlock( p_playlist ); } if( p_input && b_showpos ) { i_newpos = 100 * var_GetFloat( p_input, "position" ); if( i_oldpos != i_newpos ) { i_oldpos = i_newpos; msg_rc( "pos: %d%%", i_newpos ); } } /* Is there something to do? */ if( !b_complete ) continue; /* Skip heading spaces */ psz_cmd = p_buffer; while( *psz_cmd == ' ' ) { psz_cmd++; } /* Split psz_cmd at the first space and make sure that * psz_arg is valid */ psz_arg = strchr( psz_cmd, ' ' ); if( psz_arg ) { *psz_arg++ = 0; while( *psz_arg == ' ' ) { psz_arg++; } } else { psz_arg = (char*)""; } /* module specfic commands: @<module name> <command> <args...> */ if( *psz_cmd == '@' && *psz_arg ) { /* Parse miscellaneous commands */ char *psz_alias = psz_cmd + 1; char *psz_mycmd = strdup( psz_arg ); char *psz_myarg = strchr( psz_mycmd, ' ' ); char *psz_msg; if( !psz_myarg ) { msg_rc( "Not enough parameters." ); } else { *psz_myarg = '\0'; psz_myarg ++; var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg, &psz_msg ); if( psz_msg ) { msg_rc( psz_msg ); free( psz_msg ); } } free( psz_mycmd ); } /* If the user typed a registered local command, try it */ else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND ) { vlc_value_t val; int i_ret; val.psz_string = psz_arg; i_ret = var_Set( p_intf, psz_cmd, val ); msg_rc( "%s: returned %i (%s)", psz_cmd, i_ret, vlc_error( i_ret ) ); } /* Or maybe it's a global command */ else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND ) { vlc_value_t val; int i_ret; val.psz_string = psz_arg; /* FIXME: it's a global command, but we should pass the * local object as an argument, not p_intf->p_libvlc. */ i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val ); if( i_ret != 0 ) { msg_rc( "%s: returned %i (%s)", psz_cmd, i_ret, vlc_error( i_ret ) ); } } else if( !strcmp( psz_cmd, "logout" ) ) { /* Close connection */ if( p_intf->p_sys->i_socket != -1 ) { net_Close( p_intf->p_sys->i_socket ); } p_intf->p_sys->i_socket = -1; } else if( !strcmp( psz_cmd, "info" ) ) { if( p_input ) { int i, j; vlc_mutex_lock( &input_GetItem(p_input)->lock ); for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ ) { info_category_t *p_category = input_GetItem(p_input) ->pp_categories[i]; msg_rc( "+----[ %s ]", p_category->psz_name ); msg_rc( "| " ); for ( j = 0; j < p_category->i_infos; j++ ) { info_t *p_info = p_category->pp_infos[j]; msg_rc( "| %s: %s", p_info->psz_name, p_info->psz_value ); } msg_rc( "| " ); } msg_rc( "+----[ end of stream info ]" ); vlc_mutex_unlock( &input_GetItem(p_input)->lock ); } else { msg_rc( "no input" ); } } else if( !strcmp( psz_cmd, "is_playing" ) ) { if( ! p_input ) { msg_rc( "0" ); } else { msg_rc( "1" ); } } else if( !strcmp( psz_cmd, "get_time" ) ) { if( ! p_input ) { msg_rc("0"); } else { vlc_value_t time; var_Get( p_input, "time", &time ); msg_rc( "%i", time.i_time / 1000000); } } else if( !strcmp( psz_cmd, "get_length" ) ) { if( ! p_input ) { msg_rc("0"); } else { vlc_value_t time; var_Get( p_input, "length", &time ); msg_rc( "%i", time.i_time / 1000000); } } else if( !strcmp( psz_cmd, "get_title" ) ) { if( ! p_input ) { msg_rc(""); } else { msg_rc( "%s", input_GetItem(p_input)->psz_name ); } } else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 ) || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) ) { if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) ) b_longhelp = true; else b_longhelp = false; Help( p_intf, b_longhelp ); } else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) ) { var_SetInteger( p_intf->p_libvlc, "key-pressed", config_GetInt( p_intf, psz_arg ) ); } else switch( psz_cmd[0] ) { case 'f': case 'F':
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -