⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rc.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************** * rc.c : remote control stdin/stdout module for vlc ***************************************************************************** * Copyright (C) 2004 - 2005 the VideoLAN team * $Id: rc.c 19808 2007-04-15 08:52:35Z courmisch $ * * Author: Peter Surda <shurdeek@panorama.sth.ac.at> *         Jean-Paul Saman <jpsaman #_at_# m2x _replaceWith#dot_ nl> * * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdlib.h>                                      /* malloc(), free() */#include <string.h>#include <errno.h>                                                 /* ENOMEM */#include <stdio.h>#include <ctype.h>#include <signal.h>#include <vlc/vlc.h>#include <vlc/intf.h>#include <vlc/aout.h>#include <vlc/vout.h>#include <vlc_video.h>#include <vlc_osd.h>#include <vlc_update.h>#ifdef HAVE_UNISTD_H#    include <unistd.h>#endif#ifdef HAVE_SYS_TIME_H#    include <sys/time.h>#endif#include <sys/types.h>#include "vlc_error.h"#include "network.h"#include "vlc_url.h"#include "charset.h"#if defined(AF_UNIX) && !defined(AF_LOCAL)#    define AF_LOCAL AF_UNIX#endif#if defined(AF_LOCAL) && ! defined(WIN32)#    include <sys/un.h>#endif#define MAX_LINE_LENGTH 256#define STATUS_CHANGE "status change: "/***************************************************************************** * Local prototypes *****************************************************************************/static int  Activate     ( vlc_object_t * );static void Deactivate   ( vlc_object_t * );static void Run          ( intf_thread_t * );static void Help         ( intf_thread_t *, vlc_bool_t );static void RegisterCallbacks( intf_thread_t * );static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );static playlist_item_t *parse_MRL( intf_thread_t *, char * );static int  Input        ( vlc_object_t *, char const *,                           vlc_value_t, vlc_value_t, void * );static int  Playlist     ( vlc_object_t *, char const *,                           vlc_value_t, vlc_value_t, void * );static int  Other        ( vlc_object_t *, char const *,                           vlc_value_t, vlc_value_t, void * );static int  Quit         ( vlc_object_t *, char const *,                           vlc_value_t, vlc_value_t, void * );static int  Intf         ( vlc_object_t *, char const *,                           vlc_value_t, vlc_value_t, void * );static int  Volume       ( vlc_object_t *, char const *,                           vlc_value_t, vlc_value_t, void * );static int  VolumeMove   ( vlc_object_t *, char const *,                           vlc_value_t, vlc_value_t, void * );static int  VideoConfig  ( vlc_object_t *, char const *,                           vlc_value_t, vlc_value_t, void * );static int  AudioConfig  ( vlc_object_t *, char const *,                           vlc_value_t, vlc_value_t, void * );static int  Menu         ( vlc_object_t *, char const *,                           vlc_value_t, vlc_value_t, void * );static void checkUpdates( intf_thread_t *p_intf, char *psz_arg );/* Status Callbacks */static int TimeOffsetChanged( vlc_object_t *, char const *,                              vlc_value_t, vlc_value_t , void * );static int VolumeChanged    ( vlc_object_t *, char const *,                              vlc_value_t, vlc_value_t, void * );static int StateChanged     ( vlc_object_t *, char const *,                              vlc_value_t, vlc_value_t, void * );static int RateChanged      ( vlc_object_t *, char const *,                              vlc_value_t, vlc_value_t, void * );struct intf_sys_t{    int *pi_socket_listen;    int i_socket;    char *psz_unix_path;    /* status changes */    vlc_mutex_t       status_lock;    playlist_status_t i_last_state;#ifdef WIN32    HANDLE hConsoleIn;    vlc_bool_t b_quiet;#endif};#ifdef HAVE_VARIADIC_MACROS#   define msg_rc( psz_format, args... ) \      __msg_rc( p_intf, psz_format, ## args )#endifvoid __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... ){    va_list args;    va_start( args, psz_fmt );    if( p_intf->p_sys->i_socket == -1 )    {        utf8_vfprintf( stdout, psz_fmt, args );        printf( "\r\n" );    }    else    {        net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );        net_Write( p_intf, p_intf->p_sys->i_socket, NULL, (uint8_t*)"\r\n", 2 );    }    va_end( args );}/***************************************************************************** * Module descriptor *****************************************************************************/#define POS_TEXT N_("Show stream position")#define POS_LONGTEXT N_("Show the current position in seconds within the " \                        "stream from time to time." )#define TTY_TEXT N_("Fake TTY")#define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")#define UNIX_TEXT N_("UNIX socket command input")#define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \                         "stdin." )#define HOST_TEXT N_("TCP command input")#define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \            "You can set the address and port the interface will bind to." )#ifdef WIN32#define QUIET_TEXT N_("Do not open a DOS command box interface")#define QUIET_LONGTEXT N_( \    "By default the rc interface plugin will start a DOS command box. " \    "Enabling the quiet mode will not bring this command box but can also " \    "be pretty annoying when you want to stop VLC and no video window is " \    "open." )#endifvlc_module_begin();    set_shortname( _("RC"));    set_category( CAT_INTERFACE );    set_subcategory( SUBCAT_INTERFACE_MAIN );    set_description( _("Remote control interface") );    add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );#ifdef WIN32    add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );#else#if defined (HAVE_ISATTY)    add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );#endif    add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );#endif    add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );    set_capability( "interface", 20 );    set_callbacks( Activate, Deactivate );vlc_module_end();/***************************************************************************** * Activate: initialize and create stuff *****************************************************************************/static int Activate( vlc_object_t *p_this ){    intf_thread_t *p_intf = (intf_thread_t*)p_this;    playlist_t *p_playlist;    char *psz_host, *psz_unix_path;    int  *pi_socket = NULL;#ifndef WIN32#if defined(HAVE_ISATTY)    /* Check that stdin is a TTY */    if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )    {        msg_Warn( p_intf, "fd 0 is not a TTY" );        return VLC_EGENERIC;    }#endif    psz_unix_path = config_GetPsz( p_intf, "rc-unix" );    if( psz_unix_path )    {        int i_socket;#ifndef AF_LOCAL        msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );        free( psz_unix_path );        return VLC_EGENERIC;#else        struct sockaddr_un addr;        int i_ret;        memset( &addr, 0, sizeof(struct sockaddr_un) );        msg_Dbg( p_intf, "trying UNIX socket" );        if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )        {            msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );            free( psz_unix_path );            return VLC_EGENERIC;        }        addr.sun_family = AF_LOCAL;        strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );        addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';        if( (i_ret = bind( i_socket, (struct sockaddr*)&addr,                           sizeof(struct sockaddr_un) ) ) < 0 )        {            msg_Warn( p_intf, "couldn't bind socket to address: %s",                      strerror(errno) );            free( psz_unix_path );            net_Close( i_socket );            return VLC_EGENERIC;        }        if( ( i_ret = listen( i_socket, 1 ) ) < 0 )        {            msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));            free( psz_unix_path );            net_Close( i_socket );            return VLC_EGENERIC;        }        /* FIXME: we need a core function to merge listening sockets sets */        pi_socket = calloc( 2, sizeof( int ) );        if( pi_socket == NULL )        {            free( psz_unix_path );            net_Close( i_socket );            return VLC_ENOMEM;        }        pi_socket[0] = i_socket;        pi_socket[1] = -1;#endif /* AF_LOCAL */    }#endif /* !WIN32 */    if( ( pi_socket == NULL ) &&        ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )    {        vlc_url_t url;        vlc_UrlParse( &url, psz_host, 0 );        msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );        pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);        if( pi_socket == NULL )        {            msg_Warn( p_intf, "can't listen to %s port %i",                      url.psz_host, url.i_port );            vlc_UrlClean( &url );            free( psz_host );            return VLC_EGENERIC;        }        vlc_UrlClean( &url );        free( psz_host );    }    p_intf->p_sys = malloc( sizeof( intf_sys_t ) );    if( !p_intf->p_sys )    {        msg_Err( p_intf, "no memory" );        return VLC_ENOMEM;    }    p_intf->p_sys->pi_socket_listen = pi_socket;    p_intf->p_sys->i_socket = -1;    p_intf->p_sys->psz_unix_path = psz_unix_path;    vlc_mutex_init( p_intf, &p_intf->p_sys->status_lock );    p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;    /* Non-buffered stdout */    setvbuf( stdout, (char *)NULL, _IOLBF, 0 );    p_intf->pf_run = Run;#ifdef WIN32    p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );    if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }#else    CONSOLE_INTRO_MSG;#endif    /* Force "no-view" mode */    p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,                                                 FIND_ANYWHERE );    if( p_playlist )    {        vlc_mutex_lock( &p_playlist->object_lock );        p_playlist->status.i_view = -1;        vlc_mutex_unlock( &p_playlist->object_lock );        vlc_object_release( p_playlist );    }    msg_rc( _("Remote control interface initialized. Type `help' for help.") );    return VLC_SUCCESS;}/***************************************************************************** * Deactivate: uninitialize and cleanup *****************************************************************************/static void Deactivate( vlc_object_t *p_this ){    intf_thread_t *p_intf = (intf_thread_t*)p_this;    net_ListenClose( p_intf->p_sys->pi_socket_listen );    if( p_intf->p_sys->i_socket != -1 )        net_Close( p_intf->p_sys->i_socket );    if( p_intf->p_sys->psz_unix_path != NULL )    {#if defined(AF_LOCAL) && !defined(WIN32)        unlink( p_intf->p_sys->psz_unix_path );#endif        free( p_intf->p_sys->psz_unix_path );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -