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_( \
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_integer( "screen-height", 0, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT, true );
101 add_bool( "screen-follow-mouse", false, NULL, FOLLOW_MOUSE_TEXT,
102 FOLLOW_MOUSE_LONGTEXT, true );
106 add_integer( "screen-fragment-size", 0, NULL, FRAGS_TEXT,
107 FRAGS_LONGTEXT, true );
110 set_capability( "access_demux", 0 );
111 add_shortcut( "screen" );
112 set_callbacks( Open, Close );
115 /*****************************************************************************
117 *****************************************************************************/
118 static int Control( demux_t *, int, va_list );
119 static int Demux ( demux_t * );
121 /*****************************************************************************
123 *****************************************************************************/
124 static int Open( vlc_object_t *p_this )
126 demux_t *p_demux = (demux_t*)p_this;
130 /* Fill p_demux field */
131 p_demux->pf_demux = Demux;
132 p_demux->pf_control = Control;
133 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
134 memset( p_sys, 0, sizeof( demux_sys_t ) );
136 /* Update default_pts to a suitable value for screen access */
137 var_Create( p_demux, "screen-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
139 var_Create( p_demux, "screen-fps", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT );
140 var_Get( p_demux, "screen-fps", &val );
141 p_sys->f_fps = val.f_float;
142 p_sys->i_incr = 1000000 / val.f_float;
143 p_sys->i_next_date = 0;
145 #ifdef SCREEN_SUBSCREEN
146 p_sys->i_top = var_CreateGetInteger( p_demux, "screen-top" );
147 p_sys->i_left = var_CreateGetInteger( p_demux, "screen-left" );
148 p_sys->i_width = var_CreateGetInteger( p_demux, "screen-width" );
149 p_sys->i_height = var_CreateGetInteger( p_demux, "screen-height" );
150 if( p_sys->i_width > 0 && p_sys->i_height > 0 )
151 msg_Dbg( p_demux, "capturing subscreen top: %d, left: %d, "
152 "width: %d, height: %d",
159 if( screen_InitCapture( p_demux ) != VLC_SUCCESS )
165 msg_Dbg( p_demux, "screen width: %i, height: %i, depth: %i",
166 p_sys->fmt.video.i_width, p_sys->fmt.video.i_height,
167 p_sys->fmt.video.i_bits_per_pixel );
169 #ifdef SCREEN_SUBSCREEN
170 if( p_sys->i_width > 0 && p_sys->i_height > 0 )
172 if( p_sys->i_left + p_sys->i_width > p_sys->fmt.video.i_width ||
173 p_sys->i_top + p_sys->i_height > p_sys->fmt.video.i_height )
175 msg_Err( p_demux, "subscreen region overflows the screen" );
181 p_sys->i_screen_width = p_sys->fmt.video.i_width;
182 p_sys->i_screen_height = p_sys->fmt.video.i_height;
183 p_sys->fmt.video.i_width = p_sys->i_width;
184 p_sys->fmt.video.i_height = p_sys->i_height;
185 p_sys->b_follow_mouse = var_CreateGetInteger( p_demux,
186 "screen-follow-mouse" );
187 if( p_sys->b_follow_mouse )
188 msg_Dbg( p_demux, "mouse following enabled" );
193 p_sys->es = es_out_Add( p_demux->out, &p_sys->fmt );
198 /*****************************************************************************
200 *****************************************************************************/
201 static void Close( vlc_object_t *p_this )
203 demux_t *p_demux = (demux_t*)p_this;
204 demux_sys_t *p_sys = p_demux->p_sys;
206 screen_CloseCapture( p_demux );
210 /*****************************************************************************
212 *****************************************************************************/
213 static int Demux( demux_t *p_demux )
215 demux_sys_t *p_sys = p_demux->p_sys;
218 if( !p_sys->i_next_date ) p_sys->i_next_date = mdate();
220 /* Frame skipping if necessary */
221 while( mdate() >= p_sys->i_next_date + p_sys->i_incr )
222 p_sys->i_next_date += p_sys->i_incr;
224 mwait( p_sys->i_next_date );
225 p_block = screen_Capture( p_demux );
228 p_sys->i_next_date += p_sys->i_incr;
232 p_block->i_dts = p_block->i_pts = p_sys->i_next_date;
234 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
235 es_out_Send( p_demux->out, p_sys->es, p_block );
237 p_sys->i_next_date += p_sys->i_incr;
242 /*****************************************************************************
244 *****************************************************************************/
245 static int Control( demux_t *p_demux, int i_query, va_list args )
252 /* Special for access_demux */
253 case DEMUX_CAN_PAUSE:
255 case DEMUX_CAN_CONTROL_PACE:
257 pb = (bool*)va_arg( args, bool * );
261 case DEMUX_GET_PTS_DELAY:
262 pi64 = (int64_t*)va_arg( args, int64_t * );
263 *pi64 = (int64_t)var_GetInteger( p_demux, "screen-caching" ) *1000;
266 /* TODO implement others */