1 /*****************************************************************************
2 * screen.c: Screen capture module.
3 *****************************************************************************
4 * Copyright (C) 2004 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
30 #include <vlc/input.h>
34 /*****************************************************************************
36 *****************************************************************************/
37 #define CACHING_TEXT N_("Caching value in ms")
38 #define CACHING_LONGTEXT N_( \
39 "Allows you to modify the default caching value for screen capture " \
40 "streams. This value should be set in millisecond units." )
41 #define FPS_TEXT N_("Frame rate")
42 #define FPS_LONGTEXT N_( \
43 "Allows you to set the desired frame rate for the capture." )
46 #define FRAGS_TEXT N_("Capture fragement size")
47 #define FRAGS_LONGTEXT N_( \
48 "Allows you optimize the capture by fragmenting the screen in chunks " \
49 "of predefined height (16 might be a good value, and 0 means disabled)." )
52 static int Open ( vlc_object_t * );
53 static void Close( vlc_object_t * );
62 set_description( _("Screen Input") );
64 add_integer( "screen-caching", DEFAULT_PTS_DELAY / 1000, NULL,
65 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
66 add_float( "screen-fps", SCREEN_FPS, 0, FPS_TEXT, FPS_LONGTEXT, VLC_TRUE );
69 add_integer( "screen-fragment-size", 0, NULL, FRAGS_TEXT,
70 FRAGS_LONGTEXT, VLC_TRUE );
73 set_capability( "access_demux", 0 );
74 add_shortcut( "screen" );
75 set_callbacks( Open, Close );
78 /*****************************************************************************
80 *****************************************************************************/
81 static int Control( demux_t *, int, va_list );
82 static int Demux ( demux_t * );
84 /*****************************************************************************
86 *****************************************************************************/
87 static int Open( vlc_object_t *p_this )
89 demux_t *p_demux = (demux_t*)p_this;
93 /* Fill p_demux field */
94 p_demux->pf_demux = Demux;
95 p_demux->pf_control = Control;
96 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
97 memset( p_sys, 0, sizeof( demux_sys_t ) );
99 /* Update default_pts to a suitable value for screen access */
100 var_Create( p_demux, "screen-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
102 var_Create( p_demux, "screen-fps", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT );
103 var_Get( p_demux, "screen-fps", &val );
104 p_sys->f_fps = val.f_float;
105 p_sys->i_incr = 1000000 / val.f_float;
106 p_sys->i_next_date = 0;
108 if( screen_InitCapture( p_demux ) != VLC_SUCCESS )
114 msg_Dbg( p_demux, "screen width: %i, height: %i, depth: %i",
115 p_sys->fmt.video.i_width, p_sys->fmt.video.i_height,
116 p_sys->fmt.video.i_bits_per_pixel );
118 p_sys->es = es_out_Add( p_demux->out, &p_sys->fmt );
123 /*****************************************************************************
125 *****************************************************************************/
126 static void Close( vlc_object_t *p_this )
128 demux_t *p_demux = (demux_t*)p_this;
129 demux_sys_t *p_sys = p_demux->p_sys;
131 screen_CloseCapture( p_demux );
135 /*****************************************************************************
137 *****************************************************************************/
138 static int Demux( demux_t *p_demux )
140 demux_sys_t *p_sys = p_demux->p_sys;
143 if( !p_sys->i_next_date ) p_sys->i_next_date = mdate();
145 /* Frame skipping if necessary */
146 while( mdate() >= p_sys->i_next_date + p_sys->i_incr )
147 p_sys->i_next_date += p_sys->i_incr;
149 mwait( p_sys->i_next_date );
150 p_block = screen_Capture( p_demux );
153 p_sys->i_next_date += p_sys->i_incr;
157 p_block->i_dts = p_block->i_pts = p_sys->i_next_date;
159 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
160 es_out_Send( p_demux->out, p_sys->es, p_block );
162 p_sys->i_next_date += p_sys->i_incr;
167 /*****************************************************************************
169 *****************************************************************************/
170 static int Control( demux_t *p_demux, int i_query, va_list args )
177 /* Special for access_demux */
178 case DEMUX_CAN_PAUSE:
179 case DEMUX_CAN_CONTROL_PACE:
181 pb = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
185 case DEMUX_GET_PTS_DELAY:
186 pi64 = (int64_t*)va_arg( args, int64_t * );
187 *pi64 = (int64_t)var_GetInteger( p_demux, "screen-caching" ) *1000;
190 /* TODO implement others */