00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdlib.h>
00028
00029 #include <vlc/vlc.h>
00030 #include <vlc/input.h>
00031
00032 #include "screen.h"
00033
00034
00035
00036
00037 #define CACHING_TEXT N_("Caching value in ms")
00038 #define CACHING_LONGTEXT N_( \
00039 "Allows you to modify the default caching value for screen capture " \
00040 "streams. This value should be set in millisecond units." )
00041 #define FPS_TEXT N_("Frame rate")
00042 #define FPS_LONGTEXT N_( \
00043 "Allows you to set the desired frame rate for the capture." )
00044
00045 #ifdef WIN32
00046 #define FRAGS_TEXT N_("Capture fragment size")
00047 #define FRAGS_LONGTEXT N_( \
00048 "Allows you optimize the capture by fragmenting the screen in chunks " \
00049 "of predefined height (16 might be a good value, and 0 means disabled)." )
00050 #endif
00051
00052 static int Open ( vlc_object_t * );
00053 static void Close( vlc_object_t * );
00054
00055 #ifdef WIN32
00056 # define SCREEN_FPS 1
00057 #else
00058 # define SCREEN_FPS 5
00059 #endif
00060
00061 vlc_module_begin();
00062 set_description( _("Screen Input") );
00063 set_shortname( N_("Screen" ));
00064 set_category( CAT_INPUT );
00065 set_subcategory( SUBCAT_INPUT_ACCESS );
00066
00067 add_integer( "screen-caching", DEFAULT_PTS_DELAY / 1000, NULL,
00068 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
00069 add_float( "screen-fps", SCREEN_FPS, 0, FPS_TEXT, FPS_LONGTEXT, VLC_TRUE );
00070
00071 #ifdef WIN32
00072 add_integer( "screen-fragment-size", 0, NULL, FRAGS_TEXT,
00073 FRAGS_LONGTEXT, VLC_TRUE );
00074 #endif
00075
00076 set_capability( "access_demux", 0 );
00077 add_shortcut( "screen" );
00078 set_callbacks( Open, Close );
00079 vlc_module_end();
00080
00081
00082
00083
00084 static int Control( demux_t *, int, va_list );
00085 static int Demux ( demux_t * );
00086
00087
00088
00089
00090 static int Open( vlc_object_t *p_this )
00091 {
00092 demux_t *p_demux = (demux_t*)p_this;
00093 demux_sys_t *p_sys;
00094 vlc_value_t val;
00095
00096
00097 p_demux->pf_demux = Demux;
00098 p_demux->pf_control = Control;
00099 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
00100 memset( p_sys, 0, sizeof( demux_sys_t ) );
00101
00102
00103 var_Create( p_demux, "screen-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
00104
00105 var_Create( p_demux, "screen-fps", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT );
00106 var_Get( p_demux, "screen-fps", &val );
00107 p_sys->f_fps = val.f_float;
00108 p_sys->i_incr = 1000000 / val.f_float;
00109 p_sys->i_next_date = 0;
00110
00111 if( screen_InitCapture( p_demux ) != VLC_SUCCESS )
00112 {
00113 free( p_sys );
00114 return VLC_EGENERIC;
00115 }
00116
00117 msg_Dbg( p_demux, "screen width: %i, height: %i, depth: %i",
00118 p_sys->fmt.video.i_width, p_sys->fmt.video.i_height,
00119 p_sys->fmt.video.i_bits_per_pixel );
00120
00121 p_sys->es = es_out_Add( p_demux->out, &p_sys->fmt );
00122
00123 return VLC_SUCCESS;
00124 }
00125
00126
00127
00128
00129 static void Close( vlc_object_t *p_this )
00130 {
00131 demux_t *p_demux = (demux_t*)p_this;
00132 demux_sys_t *p_sys = p_demux->p_sys;
00133
00134 screen_CloseCapture( p_demux );
00135 free( p_sys );
00136 }
00137
00138
00139
00140
00141 static int Demux( demux_t *p_demux )
00142 {
00143 demux_sys_t *p_sys = p_demux->p_sys;
00144 block_t *p_block;
00145
00146 if( !p_sys->i_next_date ) p_sys->i_next_date = mdate();
00147
00148
00149 while( mdate() >= p_sys->i_next_date + p_sys->i_incr )
00150 p_sys->i_next_date += p_sys->i_incr;
00151
00152 mwait( p_sys->i_next_date );
00153 p_block = screen_Capture( p_demux );
00154 if( !p_block )
00155 {
00156 p_sys->i_next_date += p_sys->i_incr;
00157 return 1;
00158 }
00159
00160 p_block->i_dts = p_block->i_pts = p_sys->i_next_date;
00161
00162 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
00163 es_out_Send( p_demux->out, p_sys->es, p_block );
00164
00165 p_sys->i_next_date += p_sys->i_incr;
00166
00167 return 1;
00168 }
00169
00170
00171
00172
00173 static int Control( demux_t *p_demux, int i_query, va_list args )
00174 {
00175 vlc_bool_t *pb;
00176 int64_t *pi64;
00177
00178 switch( i_query )
00179 {
00180
00181 case DEMUX_CAN_PAUSE:
00182 case DEMUX_CAN_CONTROL_PACE:
00183
00184 pb = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
00185 *pb = VLC_FALSE;
00186 return VLC_SUCCESS;
00187
00188 case DEMUX_GET_PTS_DELAY:
00189 pi64 = (int64_t*)va_arg( args, int64_t * );
00190 *pi64 = (int64_t)var_GetInteger( p_demux, "screen-caching" ) *1000;
00191 return VLC_SUCCESS;
00192
00193
00194 default:
00195 return VLC_EGENERIC;
00196 }
00197 }