]> git.sesse.net Git - vlc/blob - modules/access/screen/screen.c
Use gettext_noop() consistently
[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 <vlc_plugin.h>
34 #include "screen.h"
35
36 /*****************************************************************************
37  * Module descriptor
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." )
46
47 #ifdef WIN32
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)." )
52 #endif
53
54 static int  Open ( vlc_object_t * );
55 static void Close( vlc_object_t * );
56
57 #ifdef WIN32
58 #   define SCREEN_FPS 1
59 #else
60 #   define SCREEN_FPS 5
61 #endif
62
63 vlc_module_begin();
64     set_description( N_("Screen Input") );
65     set_shortname( N_("Screen" ));
66     set_category( CAT_INPUT );
67     set_subcategory( SUBCAT_INPUT_ACCESS );
68
69     add_integer( "screen-caching", DEFAULT_PTS_DELAY / 1000, NULL,
70         CACHING_TEXT, CACHING_LONGTEXT, true );
71     add_float( "screen-fps", SCREEN_FPS, 0, FPS_TEXT, FPS_LONGTEXT, true );
72
73 #ifdef WIN32
74     add_integer( "screen-fragment-size", 0, NULL, FRAGS_TEXT,
75         FRAGS_LONGTEXT, true );
76 #endif
77
78     set_capability( "access_demux", 0 );
79     add_shortcut( "screen" );
80     set_callbacks( Open, Close );
81 vlc_module_end();
82
83 /*****************************************************************************
84  * Local prototypes
85  *****************************************************************************/
86 static int Control( demux_t *, int, va_list );
87 static int Demux  ( demux_t * );
88
89 /*****************************************************************************
90  * DemuxOpen:
91  *****************************************************************************/
92 static int Open( vlc_object_t *p_this )
93 {
94     demux_t     *p_demux = (demux_t*)p_this;
95     demux_sys_t *p_sys;
96     vlc_value_t val;
97
98     /* Fill p_demux field */
99     p_demux->pf_demux = Demux;
100     p_demux->pf_control = Control;
101     p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
102     memset( p_sys, 0, sizeof( demux_sys_t ) );
103
104     /* Update default_pts to a suitable value for screen access */
105     var_Create( p_demux, "screen-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
106
107     var_Create( p_demux, "screen-fps", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT );
108     var_Get( p_demux, "screen-fps", &val );
109     p_sys->f_fps = val.f_float;
110     p_sys->i_incr = 1000000 / val.f_float;
111     p_sys->i_next_date = 0;
112
113     if( screen_InitCapture( p_demux ) != VLC_SUCCESS )
114     {
115         free( p_sys );
116         return VLC_EGENERIC;
117     }
118
119     msg_Dbg( p_demux, "screen width: %i, height: %i, depth: %i",
120              p_sys->fmt.video.i_width, p_sys->fmt.video.i_height,
121              p_sys->fmt.video.i_bits_per_pixel );
122
123     p_sys->es = es_out_Add( p_demux->out, &p_sys->fmt );
124
125     return VLC_SUCCESS;
126 }
127
128 /*****************************************************************************
129  * Close:
130  *****************************************************************************/
131 static void Close( vlc_object_t *p_this )
132 {
133     demux_t     *p_demux = (demux_t*)p_this;
134     demux_sys_t *p_sys = p_demux->p_sys;
135
136     screen_CloseCapture( p_demux );
137     free( p_sys );
138 }
139
140 /*****************************************************************************
141  * Demux:
142  *****************************************************************************/
143 static int Demux( demux_t *p_demux )
144 {
145     demux_sys_t *p_sys = p_demux->p_sys;
146     block_t *p_block;
147
148     if( !p_sys->i_next_date ) p_sys->i_next_date = mdate();
149
150     /* Frame skipping if necessary */
151     while( mdate() >= p_sys->i_next_date + p_sys->i_incr )
152         p_sys->i_next_date += p_sys->i_incr;
153
154     mwait( p_sys->i_next_date );
155     p_block = screen_Capture( p_demux );
156     if( !p_block )
157     {
158         p_sys->i_next_date += p_sys->i_incr;
159         return 1;
160     }
161
162     p_block->i_dts = p_block->i_pts = p_sys->i_next_date;
163
164     es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
165     es_out_Send( p_demux->out, p_sys->es, p_block );
166
167     p_sys->i_next_date += p_sys->i_incr;
168
169     return 1;
170 }
171
172 /*****************************************************************************
173  * Control:
174  *****************************************************************************/
175 static int Control( demux_t *p_demux, int i_query, va_list args )
176 {
177     bool *pb;
178     int64_t *pi64;
179
180     switch( i_query )
181     {
182         /* Special for access_demux */
183         case DEMUX_CAN_PAUSE:
184         case DEMUX_CAN_SEEK:
185         case DEMUX_CAN_CONTROL_PACE:
186             /* TODO */
187             pb = (bool*)va_arg( args, bool * );
188             *pb = false;
189             return VLC_SUCCESS;
190
191         case DEMUX_GET_PTS_DELAY:
192             pi64 = (int64_t*)va_arg( args, int64_t * );
193             *pi64 = (int64_t)var_GetInteger( p_demux, "screen-caching" ) *1000;
194             return VLC_SUCCESS;
195
196         /* TODO implement others */
197         default:
198             return VLC_EGENERIC;
199     }
200 }