Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

input.c

00001 /*****************************************************************************
00002  * input_dummy.c: dummy input plugin, to manage "vlc:***" special options
00003  *****************************************************************************
00004  * Copyright (C) 2001, 2002 the VideoLAN team
00005  * $Id: input.c 12108 2005-08-10 16:18:18Z hartman $
00006  *
00007  * Authors: Samuel Hocevar <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>
00028 #include <string.h>
00029 
00030 #include <vlc/vlc.h>
00031 #include <vlc/intf.h>
00032 #include <vlc/input.h>
00033 
00034 /*****************************************************************************
00035  * Access functions.
00036  *****************************************************************************/
00037 static int AccessRead( access_t *p_access, uint8_t *p, int i_size )
00038 {
00039     memset( p, 0, i_size );
00040     return i_size;
00041 }
00042 static int AccessControl( access_t *p_access, int i_query, va_list args )
00043 {
00044     vlc_bool_t   *pb_bool;
00045     int          *pi_int;
00046     int64_t      *pi_64;
00047 
00048     switch( i_query )
00049     {
00050         /* */
00051         case ACCESS_CAN_SEEK:
00052         case ACCESS_CAN_FASTSEEK:
00053         case ACCESS_CAN_PAUSE:
00054         case ACCESS_CAN_CONTROL_PACE:
00055             pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
00056             *pb_bool = VLC_FALSE;
00057             break;
00058 
00059         /* */
00060         case ACCESS_GET_MTU:
00061             pi_int = (int*)va_arg( args, int * );
00062             *pi_int = 0;
00063             break;
00064 
00065         case ACCESS_GET_PTS_DELAY:
00066             pi_64 = (int64_t*)va_arg( args, int64_t * );
00067             *pi_64 = DEFAULT_PTS_DELAY * 1000;
00068             break;
00069 
00070         /* */
00071         case ACCESS_SET_PAUSE_STATE:
00072         case ACCESS_GET_TITLE_INFO:
00073         case ACCESS_GET_META:
00074         case ACCESS_SET_TITLE:
00075         case ACCESS_SET_SEEKPOINT:
00076             return VLC_EGENERIC;
00077 
00078         default:
00079             msg_Err( p_access, "unimplemented query in control" );
00080             return VLC_EGENERIC;
00081     }
00082     return VLC_SUCCESS;
00083 }
00084 
00085 int E_(OpenAccess)( vlc_object_t *p_this )
00086 {
00087     access_t *p_access = (access_t*)p_this;
00088 
00089     /* Init p_access */
00090     p_access->pf_read = AccessRead;
00091     p_access->pf_block = NULL;
00092     p_access->pf_seek = NULL;
00093     p_access->pf_control = AccessControl;
00094     p_access->info.i_update = 0;
00095     p_access->info.i_size = 0;
00096     p_access->info.i_pos = 0;
00097     p_access->info.b_eof = VLC_FALSE;
00098     p_access->info.i_title = 0;
00099     p_access->info.i_seekpoint = 0;
00100     p_access->p_sys = NULL;
00101 
00102     /* Force dummy demux plug-in */
00103     p_access->psz_demux = strdup( "vlc" );
00104 
00105     return VLC_SUCCESS;
00106 }
00107 
00108 
00109 /*****************************************************************************
00110  * Demux
00111  *****************************************************************************/
00112 struct demux_sys_t
00113 {
00114     /* The real command */
00115     int i_command;
00116 
00117     /* Used for the pause command */
00118     mtime_t expiration;
00119     
00120     /* The command to run */
00121     char* psz_command;
00122 };
00123 enum
00124 {
00125     COMMAND_NOP  = 0,
00126     COMMAND_QUIT = 1,
00127     COMMAND_PAUSE= 3,
00128 };
00129 
00130 static int Demux( demux_t * );
00131 static int DemuxControl( demux_t *, int, va_list );
00132 
00133 
00134 /*****************************************************************************
00135  * OpenDemux: initialize the target, ie. parse the command
00136  *****************************************************************************/
00137 int E_(OpenDemux) ( vlc_object_t *p_this )
00138 {
00139     demux_t *p_demux = (demux_t*)p_this;
00140     char * psz_name = p_demux->psz_path;
00141 
00142     int i_len = strlen( psz_name );
00143     demux_sys_t *p_sys;
00144     int   i_arg;
00145 
00146     p_demux->pf_demux   = Demux;
00147     p_demux->pf_control = DemuxControl;
00148     p_demux->p_sys      = p_sys = malloc( sizeof( demux_sys_t ) );
00149 
00150     /* Check for a "vlc:nop" command */
00151     if( i_len == 3 && !strncasecmp( psz_name, "nop", 3 ) )
00152     {
00153         msg_Info( p_demux, "command `nop'" );
00154         p_sys->i_command = COMMAND_NOP;
00155         return VLC_SUCCESS;
00156     }
00157 
00158     /* Check for a "vlc:quit" command */
00159     if( i_len == 4 && !strncasecmp( psz_name, "quit", 4 ) )
00160     {
00161         msg_Info( p_demux, "command `quit'" );
00162         p_sys->i_command = COMMAND_QUIT;
00163         return VLC_SUCCESS;
00164     }
00165 
00166     /* Check for a "vlc:pause:***" command */
00167     if( i_len > 6 && !strncasecmp( psz_name, "pause:", 6 ) )
00168     {
00169         i_arg = atoi( psz_name + 6 );
00170         msg_Info( p_demux, "command `pause %i'", i_arg );
00171         p_sys->i_command = COMMAND_PAUSE;
00172         p_sys->expiration = mdate() + (mtime_t)i_arg * (mtime_t)1000000;
00173         return VLC_SUCCESS;
00174     }
00175     
00176     msg_Err( p_demux, "unknown command `%s'", psz_name );
00177 
00178     free( p_sys );
00179     return VLC_EGENERIC;
00180 }
00181 
00182 /*****************************************************************************
00183  * CloseDemux: initialize the target, ie. parse the command
00184  *****************************************************************************/
00185 void E_(CloseDemux) ( vlc_object_t *p_this )
00186 {
00187     demux_t *p_demux = (demux_t*)p_this;
00188 
00189     free( p_demux->p_sys );
00190 }
00191 
00192 /*****************************************************************************
00193  * Demux: do what the command says
00194  *****************************************************************************/
00195 static int Demux( demux_t *p_demux )
00196 {
00197     demux_sys_t *p_sys = p_demux->p_sys;
00198     playlist_t *p_playlist;
00199     vlc_bool_t b_eof = VLC_FALSE;
00200 
00201     p_playlist = vlc_object_find( p_demux, VLC_OBJECT_PLAYLIST, FIND_PARENT );
00202 
00203     if( p_playlist == NULL )
00204     {
00205         msg_Err( p_demux, "we are not attached to a playlist" );
00206         return -1;
00207     }
00208 
00209     switch( p_sys->i_command )
00210     {
00211         case COMMAND_QUIT:
00212             b_eof = p_demux->p_vlc->b_die = VLC_TRUE;
00213             break;
00214 
00215         case COMMAND_PAUSE:
00216             if( mdate() >= p_sys->expiration )
00217                 b_eof = VLC_TRUE;
00218             else
00219                 msleep( 10000 );
00220             break;
00221         
00222         case COMMAND_NOP:
00223         default:
00224             b_eof = VLC_TRUE;
00225             break;       
00226     }
00227 
00228     vlc_object_release( p_playlist );
00229     return b_eof ? 0 : 1;
00230 }
00231 
00232 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
00233 {
00234     return demux2_vaControlHelper( p_demux->s,
00235                                    0, 0, 0, 1,
00236                                    i_query, args );
00237 }

Generated on Tue Dec 20 10:14:48 2005 for vlc-0.8.4a by  doxygen 1.4.2