1 /*****************************************************************************
2 * screen.c: Screen capture module.
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
33 #include <vlc_plugin.h>
36 /*****************************************************************************
38 *****************************************************************************/
39 #define CACHING_TEXT N_("Caching value in ms")
40 #define CACHING_LONGTEXT N_( \
41 "Caching value for screen capture. "\
42 "This value should be set in milliseconds." )
43 #define FPS_TEXT N_("Frame rate")
44 #define FPS_LONGTEXT N_( \
45 "Desired frame rate for the capture." )
48 #define FRAGS_TEXT N_("Capture fragment size")
49 #define FRAGS_LONGTEXT N_( \
50 "Optimize the capture by fragmenting the screen in chunks " \
51 "of predefined height (16 might be a good value, and 0 means disabled)." )
54 #ifdef SCREEN_SUBSCREEN
55 #define TOP_TEXT N_( "Subscreen top left corner" )
56 #define TOP_LONGTEXT N_( \
57 "Top coordinate of the subscreen top left corner." )
59 #define LEFT_TEXT N_( "Subscreen top left corner" )
60 #define LEFT_LONGTEXT N_( \
61 "Left coordinate of the subscreen top left corner." )
63 #define WIDTH_TEXT N_( "Subscreen width" )
64 #define WIDTH_LONGTEXT N_( \
67 #define HEIGHT_TEXT N_( "Subscreen height" )
68 #define HEIGHT_LONGTEXT N_( \
72 static int Open ( vlc_object_t * );
73 static void Close( vlc_object_t * );
82 set_description( N_("Screen Input") );
83 set_shortname( N_("Screen" ));
84 set_category( CAT_INPUT );
85 set_subcategory( SUBCAT_INPUT_ACCESS );
87 add_integer( "screen-caching", DEFAULT_PTS_DELAY / 1000, NULL,
88 CACHING_TEXT, CACHING_LONGTEXT, true );
89 add_float( "screen-fps", SCREEN_FPS, 0, FPS_TEXT, FPS_LONGTEXT, true );
91 #ifdef SCREEN_SUBSCREEN
92 add_integer( "screen-top", 0, NULL, TOP_TEXT, TOP_LONGTEXT, true );
93 add_integer( "screen-left", 0, NULL, LEFT_TEXT, LEFT_LONGTEXT, true );
94 add_integer( "screen-width", 0, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, true );
95 add_integer( "screen-height", 0, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT, true );
99 add_integer( "screen-fragment-size", 0, NULL, FRAGS_TEXT,
100 FRAGS_LONGTEXT, true );
103 set_capability( "access_demux", 0 );
104 add_shortcut( "screen" );
105 set_callbacks( Open, Close );
108 /*****************************************************************************
110 *****************************************************************************/
111 static int Control( demux_t *, int, va_list );
112 static int Demux ( demux_t * );
114 /*****************************************************************************
116 *****************************************************************************/
117 static int Open( vlc_object_t *p_this )
119 demux_t *p_demux = (demux_t*)p_this;
123 /* Fill p_demux field */
124 p_demux->pf_demux = Demux;
125 p_demux->pf_control = Control;
126 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
127 memset( p_sys, 0, sizeof( demux_sys_t ) );
129 /* Update default_pts to a suitable value for screen access */
130 var_Create( p_demux, "screen-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
132 var_Create( p_demux, "screen-fps", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT );
133 var_Get( p_demux, "screen-fps", &val );
134 p_sys->f_fps = val.f_float;
135 p_sys->i_incr = 1000000 / val.f_float;
136 p_sys->i_next_date = 0;
138 #ifdef SCREEN_SUBSCREEN
139 p_sys->i_top = var_CreateGetInteger( p_demux, "screen-top" );
140 p_sys->i_left = var_CreateGetInteger( p_demux, "screen-left" );
141 p_sys->i_width = var_CreateGetInteger( p_demux, "screen-width" );
142 p_sys->i_height = var_CreateGetInteger( p_demux, "screen-height" );
143 if( p_sys->i_width > 0 && p_sys->i_height > 0 )
144 msg_Dbg( p_demux, "capturing subscreen top: %d, left: %d, "
145 "width: %d, height: %d",
152 if( screen_InitCapture( p_demux ) != VLC_SUCCESS )
158 msg_Dbg( p_demux, "screen width: %i, height: %i, depth: %i",
159 p_sys->fmt.video.i_width, p_sys->fmt.video.i_height,
160 p_sys->fmt.video.i_bits_per_pixel );
162 #ifdef SCREEN_SUBSCREEN
163 if( p_sys->i_width > 0 && p_sys->i_height > 0 )
165 if( p_sys->i_left + p_sys->i_width > p_sys->fmt.video.i_width ||
166 p_sys->i_top + p_sys->i_height > p_sys->fmt.video.i_height )
168 msg_Err( p_demux, "subscreen region overflows the screen" );
174 p_sys->fmt.video.i_width = p_sys->i_width;
175 p_sys->fmt.video.i_height = p_sys->i_height;
180 p_sys->es = es_out_Add( p_demux->out, &p_sys->fmt );
185 /*****************************************************************************
187 *****************************************************************************/
188 static void Close( vlc_object_t *p_this )
190 demux_t *p_demux = (demux_t*)p_this;
191 demux_sys_t *p_sys = p_demux->p_sys;
193 screen_CloseCapture( p_demux );
197 /*****************************************************************************
199 *****************************************************************************/
200 static int Demux( demux_t *p_demux )
202 demux_sys_t *p_sys = p_demux->p_sys;
205 if( !p_sys->i_next_date ) p_sys->i_next_date = mdate();
207 /* Frame skipping if necessary */
208 while( mdate() >= p_sys->i_next_date + p_sys->i_incr )
209 p_sys->i_next_date += p_sys->i_incr;
211 mwait( p_sys->i_next_date );
212 p_block = screen_Capture( p_demux );
215 p_sys->i_next_date += p_sys->i_incr;
219 p_block->i_dts = p_block->i_pts = p_sys->i_next_date;
221 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
222 es_out_Send( p_demux->out, p_sys->es, p_block );
224 p_sys->i_next_date += p_sys->i_incr;
229 /*****************************************************************************
231 *****************************************************************************/
232 static int Control( demux_t *p_demux, int i_query, va_list args )
239 /* Special for access_demux */
240 case DEMUX_CAN_PAUSE:
242 case DEMUX_CAN_CONTROL_PACE:
244 pb = (bool*)va_arg( args, bool * );
248 case DEMUX_GET_PTS_DELAY:
249 pi64 = (int64_t*)va_arg( args, int64_t * );
250 *pi64 = (int64_t)var_GetInteger( p_demux, "screen-caching" ) *1000;
253 /* TODO implement others */