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 *****************************************************************************/
32 #include <vlc_common.h>
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_( \
71 #define FOLLOW_MOUSE_TEXT N_( "Follow the mouse" )
72 #define FOLLOW_MOUSE_LONGTEXT N_( \
73 "Follow the mouse when capturing a subscreen." )
76 static int Open ( vlc_object_t * );
77 static void Close( vlc_object_t * );
86 set_description( N_("Screen Input") );
87 set_shortname( N_("Screen" ));
88 set_category( CAT_INPUT );
89 set_subcategory( SUBCAT_INPUT_ACCESS );
91 add_integer( "screen-caching", DEFAULT_PTS_DELAY / 1000, NULL,
92 CACHING_TEXT, CACHING_LONGTEXT, true );
93 add_float( "screen-fps", SCREEN_FPS, 0, FPS_TEXT, FPS_LONGTEXT, true );
95 #ifdef SCREEN_SUBSCREEN
96 add_integer( "screen-top", 0, NULL, TOP_TEXT, TOP_LONGTEXT, true );
97 add_integer( "screen-left", 0, NULL, LEFT_TEXT, LEFT_LONGTEXT, true );
98 add_integer( "screen-width", 0, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, true );
99 add_integer( "screen-height", 0, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT, true );
100 add_bool( "screen-follow-mouse", false, NULL, FOLLOW_MOUSE_TEXT,
101 FOLLOW_MOUSE_LONGTEXT, true );
105 add_integer( "screen-fragment-size", 0, NULL, FRAGS_TEXT,
106 FRAGS_LONGTEXT, true );
109 set_capability( "access_demux", 0 );
110 add_shortcut( "screen" );
111 set_callbacks( Open, Close );
114 /*****************************************************************************
116 *****************************************************************************/
117 static int Control( demux_t *, int, va_list );
118 static int Demux ( demux_t * );
120 /*****************************************************************************
122 *****************************************************************************/
123 static int Open( vlc_object_t *p_this )
125 demux_t *p_demux = (demux_t*)p_this;
129 /* Fill p_demux field */
130 p_demux->pf_demux = Demux;
131 p_demux->pf_control = Control;
132 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
133 memset( p_sys, 0, sizeof( demux_sys_t ) );
135 /* Update default_pts to a suitable value for screen access */
136 var_Create( p_demux, "screen-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
138 var_Create( p_demux, "screen-fps", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT );
139 var_Get( p_demux, "screen-fps", &val );
140 p_sys->f_fps = val.f_float;
141 p_sys->i_incr = 1000000 / val.f_float;
142 p_sys->i_next_date = 0;
144 #ifdef SCREEN_SUBSCREEN
145 p_sys->i_top = var_CreateGetInteger( p_demux, "screen-top" );
146 p_sys->i_left = var_CreateGetInteger( p_demux, "screen-left" );
147 p_sys->i_width = var_CreateGetInteger( p_demux, "screen-width" );
148 p_sys->i_height = var_CreateGetInteger( p_demux, "screen-height" );
149 if( p_sys->i_width > 0 && p_sys->i_height > 0 )
150 msg_Dbg( p_demux, "capturing subscreen top: %d, left: %d, "
151 "width: %d, height: %d",
158 if( screen_InitCapture( p_demux ) != VLC_SUCCESS )
164 msg_Dbg( p_demux, "screen width: %i, height: %i, depth: %i",
165 p_sys->fmt.video.i_width, p_sys->fmt.video.i_height,
166 p_sys->fmt.video.i_bits_per_pixel );
168 #ifdef SCREEN_SUBSCREEN
169 if( p_sys->i_width > 0 && p_sys->i_height > 0 )
171 if( p_sys->i_left + p_sys->i_width > p_sys->fmt.video.i_width ||
172 p_sys->i_top + p_sys->i_height > p_sys->fmt.video.i_height )
174 msg_Err( p_demux, "subscreen region overflows the screen" );
180 p_sys->i_screen_width = p_sys->fmt.video.i_width;
181 p_sys->i_screen_height = p_sys->fmt.video.i_height;
182 p_sys->fmt.video.i_width = p_sys->i_width;
183 p_sys->fmt.video.i_height = p_sys->i_height;
184 p_sys->b_follow_mouse = var_CreateGetInteger( p_demux,
185 "screen-follow-mouse" );
186 if( p_sys->b_follow_mouse )
187 msg_Dbg( p_demux, "mouse following enabled" );
192 p_sys->es = es_out_Add( p_demux->out, &p_sys->fmt );
197 /*****************************************************************************
199 *****************************************************************************/
200 static void Close( vlc_object_t *p_this )
202 demux_t *p_demux = (demux_t*)p_this;
203 demux_sys_t *p_sys = p_demux->p_sys;
205 screen_CloseCapture( p_demux );
209 /*****************************************************************************
211 *****************************************************************************/
212 static int Demux( demux_t *p_demux )
214 demux_sys_t *p_sys = p_demux->p_sys;
217 if( !p_sys->i_next_date ) p_sys->i_next_date = mdate();
219 /* Frame skipping if necessary */
220 while( mdate() >= p_sys->i_next_date + p_sys->i_incr )
221 p_sys->i_next_date += p_sys->i_incr;
223 mwait( p_sys->i_next_date );
224 p_block = screen_Capture( p_demux );
227 p_sys->i_next_date += p_sys->i_incr;
231 p_block->i_dts = p_block->i_pts = p_sys->i_next_date;
233 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
234 es_out_Send( p_demux->out, p_sys->es, p_block );
236 p_sys->i_next_date += p_sys->i_incr;
241 /*****************************************************************************
243 *****************************************************************************/
244 static int Control( demux_t *p_demux, int i_query, va_list args )
251 /* Special for access_demux */
252 case DEMUX_CAN_PAUSE:
254 case DEMUX_CAN_CONTROL_PACE:
256 pb = (bool*)va_arg( args, bool * );
260 case DEMUX_GET_PTS_DELAY:
261 pi64 = (int64_t*)va_arg( args, int64_t * );
262 *pi64 = (int64_t)var_GetInteger( p_demux, "screen-caching" ) *1000;
265 /* TODO implement others */