]> git.sesse.net Git - vlc/blob - modules/access/screen/screen.c
Replace vlc_bool_t by bool, VLC_TRUE by true and VLC_FALSE by false.
[vlc] / modules / access / screen / screen.c
1 /*****************************************************************************
2  * screen.c: Screen capture module.
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc/vlc.h>
33 #include "screen.h"
34
35 /*****************************************************************************
36  * Module descriptor
37  *****************************************************************************/
38 #define CACHING_TEXT N_("Caching value in ms")
39 #define CACHING_LONGTEXT N_( \
40     "Caching value for screen capture. "\
41     "This value should be set in milliseconds." )
42 #define FPS_TEXT N_("Frame rate")
43 #define FPS_LONGTEXT N_( \
44     "Desired frame rate for the capture." )
45
46 #ifdef WIN32
47 #define FRAGS_TEXT N_("Capture fragment size")
48 #define FRAGS_LONGTEXT N_( \
49     "Optimize the capture by fragmenting the screen in chunks " \
50     "of predefined height (16 might be a good value, and 0 means disabled)." )
51 #endif
52
53 static int  Open ( vlc_object_t * );
54 static void Close( vlc_object_t * );
55
56 #ifdef WIN32
57 #   define SCREEN_FPS 1
58 #else
59 #   define SCREEN_FPS 5
60 #endif
61
62 vlc_module_begin();
63     set_description( _("Screen Input") );
64     set_shortname( _("Screen" ));
65     set_category( CAT_INPUT );
66     set_subcategory( SUBCAT_INPUT_ACCESS );
67
68     add_integer( "screen-caching", DEFAULT_PTS_DELAY / 1000, NULL,
69         CACHING_TEXT, CACHING_LONGTEXT, true );
70     add_float( "screen-fps", SCREEN_FPS, 0, FPS_TEXT, FPS_LONGTEXT, true );
71
72 #ifdef WIN32
73     add_integer( "screen-fragment-size", 0, NULL, FRAGS_TEXT,
74         FRAGS_LONGTEXT, true );
75 #endif
76
77     set_capability( "access_demux", 0 );
78     add_shortcut( "screen" );
79     set_callbacks( Open, Close );
80 vlc_module_end();
81
82 /*****************************************************************************
83  * Local prototypes
84  *****************************************************************************/
85 static int Control( demux_t *, int, va_list );
86 static int Demux  ( demux_t * );
87
88 /*****************************************************************************
89  * DemuxOpen:
90  *****************************************************************************/
91 static int Open( vlc_object_t *p_this )
92 {
93     demux_t     *p_demux = (demux_t*)p_this;
94     demux_sys_t *p_sys;
95     vlc_value_t val;
96
97     /* Fill p_demux field */
98     p_demux->pf_demux = Demux;
99     p_demux->pf_control = Control;
100     p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
101     memset( p_sys, 0, sizeof( demux_sys_t ) );
102
103     /* Update default_pts to a suitable value for screen access */
104     var_Create( p_demux, "screen-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
105
106     var_Create( p_demux, "screen-fps", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT );
107     var_Get( p_demux, "screen-fps", &val );
108     p_sys->f_fps = val.f_float;
109     p_sys->i_incr = 1000000 / val.f_float;
110     p_sys->i_next_date = 0;
111
112     if( screen_InitCapture( p_demux ) != VLC_SUCCESS )
113     {
114         free( p_sys );
115         return VLC_EGENERIC;
116     }
117
118     msg_Dbg( p_demux, "screen width: %i, height: %i, depth: %i",
119              p_sys->fmt.video.i_width, p_sys->fmt.video.i_height,
120              p_sys->fmt.video.i_bits_per_pixel );
121
122     p_sys->es = es_out_Add( p_demux->out, &p_sys->fmt );
123
124     return VLC_SUCCESS;
125 }
126
127 /*****************************************************************************
128  * Close:
129  *****************************************************************************/
130 static void Close( vlc_object_t *p_this )
131 {
132     demux_t     *p_demux = (demux_t*)p_this;
133     demux_sys_t *p_sys = p_demux->p_sys;
134
135     screen_CloseCapture( p_demux );
136     free( p_sys );
137 }
138
139 /*****************************************************************************
140  * Demux:
141  *****************************************************************************/
142 static int Demux( demux_t *p_demux )
143 {
144     demux_sys_t *p_sys = p_demux->p_sys;
145     block_t *p_block;
146
147     if( !p_sys->i_next_date ) p_sys->i_next_date = mdate();
148
149     /* Frame skipping if necessary */
150     while( mdate() >= p_sys->i_next_date + p_sys->i_incr )
151         p_sys->i_next_date += p_sys->i_incr;
152
153     mwait( p_sys->i_next_date );
154     p_block = screen_Capture( p_demux );
155     if( !p_block )
156     {
157         p_sys->i_next_date += p_sys->i_incr;
158         return 1;
159     }
160
161     p_block->i_dts = p_block->i_pts = p_sys->i_next_date;
162
163     es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
164     es_out_Send( p_demux->out, p_sys->es, p_block );
165
166     p_sys->i_next_date += p_sys->i_incr;
167
168     return 1;
169 }
170
171 /*****************************************************************************
172  * Control:
173  *****************************************************************************/
174 static int Control( demux_t *p_demux, int i_query, va_list args )
175 {
176     bool *pb;
177     int64_t *pi64;
178
179     switch( i_query )
180     {
181         /* Special for access_demux */
182         case DEMUX_CAN_PAUSE:
183         case DEMUX_CAN_SEEK:
184         case DEMUX_CAN_CONTROL_PACE:
185             /* TODO */
186             pb = (bool*)va_arg( args, bool * );
187             *pb = false;
188             return VLC_SUCCESS;
189
190         case DEMUX_GET_PTS_DELAY:
191             pi64 = (int64_t*)va_arg( args, int64_t * );
192             *pi64 = (int64_t)var_GetInteger( p_demux, "screen-caching" ) *1000;
193             return VLC_SUCCESS;
194
195         /* TODO implement others */
196         default:
197             return VLC_EGENERIC;
198     }
199 }