Comment out the correct #endif directive.
[mplayer/greg.git] / libvo / video_out.c
blob98feb468d716408564cc667143b282f4670ee8e1
2 /* this file contains libvo's common functions, variables used by
3 many/all drivers. */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
9 #include <unistd.h>
10 //#include <sys/mman.h>
12 #include "config.h"
13 #include "video_out.h"
14 #include "aspect.h"
15 #include "geometry.h"
17 #include "mp_msg.h"
18 #include "help_mp.h"
20 #include "osdep/shmem.h"
22 //int vo_flags=0;
24 int xinerama_screen = -1;
25 int xinerama_x;
26 int xinerama_y;
28 // currect resolution/bpp on screen: (should be autodetected by vo_init())
29 int vo_depthonscreen=0;
30 int vo_screenwidth=0;
31 int vo_screenheight=0;
33 int vo_config_count=0;
35 // requested resolution/bpp: (-x -y -bpp options)
36 int vo_dx=0;
37 int vo_dy=0;
38 int vo_dwidth=0;
39 int vo_dheight=0;
40 int vo_dbpp=0;
42 int vo_nomouse_input = 0;
43 int vo_grabpointer = 1;
44 int vo_doublebuffering = 1;
45 int vo_vsync = 0;
46 int vo_fs = 0;
47 int vo_fsmode = 0;
48 float vo_panscan = 0.0f;
49 int vo_ontop = 0;
50 int vo_adapter_num=0;
51 int vo_refresh_rate=0;
52 int vo_keepaspect=1;
53 int vo_rootwin=0;
54 int vo_border=1;
55 int WinID = -1;
57 int vo_pts=0; // for hw decoding
58 float vo_fps=0;
60 char *vo_subdevice = NULL;
61 int vo_directrendering=0;
63 int vo_colorkey = 0x0000ff00; // default colorkey is green
64 // (0xff000000 means that colorkey has been disabled)
67 // Externally visible list of all vo drivers
69 extern vo_functions_t video_out_mga;
70 extern vo_functions_t video_out_xmga;
71 extern vo_functions_t video_out_x11;
72 extern vo_functions_t video_out_xover;
73 extern vo_functions_t video_out_xvmc;
74 extern vo_functions_t video_out_xv;
75 extern vo_functions_t video_out_gl;
76 extern vo_functions_t video_out_gl2;
77 extern vo_functions_t video_out_dga;
78 extern vo_functions_t video_out_sdl;
79 extern vo_functions_t video_out_3dfx;
80 extern vo_functions_t video_out_tdfxfb;
81 extern vo_functions_t video_out_s3fb;
82 extern vo_functions_t video_out_null;
83 extern vo_functions_t video_out_zr;
84 extern vo_functions_t video_out_zr2;
85 extern vo_functions_t video_out_bl;
86 extern vo_functions_t video_out_fbdev;
87 extern vo_functions_t video_out_fbdev2;
88 extern vo_functions_t video_out_svga;
89 extern vo_functions_t video_out_png;
90 extern vo_functions_t video_out_ggi;
91 extern vo_functions_t video_out_aa;
92 extern vo_functions_t video_out_caca;
93 extern vo_functions_t video_out_mpegpes;
94 extern vo_functions_t video_out_yuv4mpeg;
95 #ifdef HAVE_DIRECTX
96 extern vo_functions_t video_out_directx;
97 #endif
98 #ifdef HAVE_DXR2
99 extern vo_functions_t video_out_dxr2;
100 #endif
101 extern vo_functions_t video_out_dxr3;
102 #ifdef HAVE_IVTV
103 extern vo_functions_t video_out_ivtv;
104 #endif
105 #ifdef HAVE_V4L2_DECODER
106 extern vo_functions_t video_out_v4l2;
107 #endif
108 #ifdef HAVE_JPEG
109 extern vo_functions_t video_out_jpeg;
110 #endif
111 #ifdef HAVE_GIF
112 extern vo_functions_t video_out_gif89a;
113 #endif
114 #ifdef HAVE_VESA
115 extern vo_functions_t video_out_vesa;
116 #endif
117 #ifdef HAVE_DIRECTFB
118 extern vo_functions_t video_out_directfb;
119 #ifdef HAVE_DFBMGA
120 extern vo_functions_t video_out_dfbmga;
121 #endif
122 #endif
123 #ifdef CONFIG_VIDIX
124 extern vo_functions_t video_out_xvidix;
125 extern vo_functions_t video_out_winvidix;
126 extern vo_functions_t video_out_cvidix;
127 #endif
128 #ifdef HAVE_TDFX_VID
129 extern vo_functions_t video_out_tdfx_vid;
130 #endif
131 #ifdef HAVE_XVR100
132 extern vo_functions_t video_out_xvr100;
133 #endif
134 #ifdef HAVE_TGA
135 extern vo_functions_t video_out_tga;
136 #endif
137 #ifdef MACOSX
138 #ifdef MACOSX_COREVIDEO
139 extern vo_functions_t video_out_macosx;
140 #endif
141 extern vo_functions_t video_out_quartz;
142 #endif
143 #ifdef HAVE_PNM
144 extern vo_functions_t video_out_pnm;
145 #endif
146 #ifdef HAVE_MD5SUM
147 extern vo_functions_t video_out_md5sum;
148 #endif
150 const vo_functions_t* const video_out_drivers[] =
152 #ifdef HAVE_XVR100
153 &video_out_xvr100,
154 #endif
155 #ifdef HAVE_TDFX_VID
156 &video_out_tdfx_vid,
157 #endif
158 #ifdef HAVE_DIRECTX
159 &video_out_directx,
160 #endif
161 #ifdef MACOSX
162 #ifdef MACOSX_COREVIDEO
163 &video_out_macosx,
164 #endif
165 &video_out_quartz,
166 #endif
167 #ifdef HAVE_XMGA
168 &video_out_xmga,
169 #endif
170 #ifdef HAVE_MGA
171 &video_out_mga,
172 #endif
173 #ifdef HAVE_TDFXFB
174 &video_out_tdfxfb,
175 #endif
176 #ifdef HAVE_S3FB
177 &video_out_s3fb,
178 #endif
179 #ifdef HAVE_3DFX
180 &video_out_3dfx,
181 #endif
182 #ifdef HAVE_XV
183 &video_out_xv,
184 #endif
185 #ifdef HAVE_X11
186 &video_out_x11,
187 &video_out_xover,
188 #endif
189 #ifdef HAVE_GL
190 &video_out_gl,
191 &video_out_gl2,
192 #endif
193 #ifdef HAVE_DGA
194 &video_out_dga,
195 #endif
196 #ifdef HAVE_SDL
197 &video_out_sdl,
198 #endif
199 #ifdef HAVE_GGI
200 &video_out_ggi,
201 #endif
202 #ifdef HAVE_FBDEV
203 &video_out_fbdev,
204 &video_out_fbdev2,
205 #endif
206 #ifdef HAVE_SVGALIB
207 &video_out_svga,
208 #endif
209 #ifdef HAVE_AA
210 &video_out_aa,
211 #endif
212 #ifdef HAVE_CACA
213 &video_out_caca,
214 #endif
215 #ifdef HAVE_DXR2
216 &video_out_dxr2,
217 #endif
218 #ifdef HAVE_DXR3
219 &video_out_dxr3,
220 #endif
221 #ifdef HAVE_IVTV
222 &video_out_ivtv,
223 #endif
224 #ifdef HAVE_V4L2_DECODER
225 &video_out_v4l2,
226 #endif
227 #ifdef HAVE_ZR
228 &video_out_zr,
229 &video_out_zr2,
230 #endif
231 #ifdef HAVE_BL
232 &video_out_bl,
233 #endif
234 #ifdef HAVE_VESA
235 &video_out_vesa,
236 #endif
237 #ifdef HAVE_DIRECTFB
238 &video_out_directfb,
239 #ifdef HAVE_DFBMGA
240 &video_out_dfbmga,
241 #endif
242 #endif
243 #ifdef CONFIG_VIDIX
244 #ifdef HAVE_X11
245 &video_out_xvidix,
246 #endif
247 #ifdef WIN32
248 &video_out_winvidix,
249 #endif
250 &video_out_cvidix,
251 #endif
252 &video_out_null,
253 // should not be auto-selected
254 #ifdef HAVE_XVMC
255 &video_out_xvmc,
256 #endif
257 &video_out_mpegpes,
258 &video_out_yuv4mpeg,
259 #ifdef HAVE_PNG
260 &video_out_png,
261 #endif
262 #ifdef HAVE_JPEG
263 &video_out_jpeg,
264 #endif
265 #ifdef HAVE_GIF
266 &video_out_gif89a,
267 #endif
268 #ifdef HAVE_TGA
269 &video_out_tga,
270 #endif
271 #ifdef HAVE_PNM
272 &video_out_pnm,
273 #endif
274 #ifdef HAVE_MD5SUM
275 &video_out_md5sum,
276 #endif
277 NULL
280 void list_video_out(void){
281 int i=0;
282 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoOutputDrivers);
283 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_OUTPUTS\n");
284 while (video_out_drivers[i]) {
285 const vo_info_t *info = video_out_drivers[i++]->info;
286 mp_msg(MSGT_GLOBAL, MSGL_INFO,"\t%s\t%s\n", info->short_name, info->name);
288 mp_msg(MSGT_GLOBAL, MSGL_INFO,"\n");
291 const vo_functions_t* init_best_video_out(char** vo_list){
292 int i;
293 // first try the preferred drivers, with their optional subdevice param:
294 if(vo_list && vo_list[0])
295 while(vo_list[0][0]){
296 char* vo=strdup(vo_list[0]);
297 vo_subdevice=strchr(vo,':');
298 if (!strcmp(vo, "pgm"))
299 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_VO_PGM_HasBeenReplaced);
300 if (!strcmp(vo, "md5"))
301 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_VO_MD5_HasBeenReplaced);
302 if(vo_subdevice){
303 vo_subdevice[0]=0;
304 ++vo_subdevice;
306 for(i=0;video_out_drivers[i];i++){
307 const vo_functions_t* video_driver=video_out_drivers[i];
308 const vo_info_t *info = video_driver->info;
309 if(!strcmp(info->short_name,vo)){
310 // name matches, try it
311 if(!video_driver->preinit(vo_subdevice))
313 free(vo);
314 return video_driver; // success!
318 // continue...
319 free(vo);
320 ++vo_list;
321 if(!(vo_list[0])) return NULL; // do NOT fallback to others
323 // now try the rest...
324 vo_subdevice=NULL;
325 for(i=0;video_out_drivers[i];i++){
326 const vo_functions_t* video_driver=video_out_drivers[i];
327 if(!video_driver->preinit(vo_subdevice))
328 return video_driver; // success!
330 return NULL;
333 int config_video_out(const vo_functions_t *vo, uint32_t width, uint32_t height,
334 uint32_t d_width, uint32_t d_height, uint32_t flags,
335 char *title, uint32_t format) {
336 panscan_init();
337 aspect_save_orig(width,height);
338 aspect_save_prescale(d_width,d_height);
340 if (vo->control(VOCTRL_UPDATE_SCREENINFO, NULL) == VO_TRUE) {
341 aspect(&d_width,&d_height,A_NOZOOM);
342 vo_dx = (int)(vo_screenwidth - d_width) / 2;
343 vo_dy = (int)(vo_screenheight - d_height) / 2;
344 geometry(&vo_dx, &vo_dy, &d_width, &d_height,
345 vo_screenwidth, vo_screenheight);
346 vo_dx += xinerama_x;
347 vo_dy += xinerama_y;
348 vo_dwidth = d_width;
349 vo_dheight = d_height;
352 return vo->config(width, height, d_width, d_height, flags, title, format);
355 #if defined(HAVE_FBDEV)||defined(HAVE_VESA)
356 /* Borrowed from vo_fbdev.c
357 Monitor ranges related functions*/
359 char *monitor_hfreq_str = NULL;
360 char *monitor_vfreq_str = NULL;
361 char *monitor_dotclock_str = NULL;
363 float range_max(range_t *r)
365 float max = 0;
367 for (/* NOTHING */; (r->min != -1 && r->max != -1); r++)
368 if (max < r->max) max = r->max;
369 return max;
373 int in_range(range_t *r, float f)
375 for (/* NOTHING */; (r->min != -1 && r->max != -1); r++)
376 if (f >= r->min && f <= r->max)
377 return 1;
378 return 0;
381 range_t *str2range(char *s)
383 float tmp_min, tmp_max;
384 char *endptr = s; // to start the loop
385 range_t *r = NULL;
386 int i;
388 if (!s)
389 return NULL;
390 for (i = 0; *endptr; i++) {
391 if (*s == ',')
392 goto out_err;
393 if (!(r = (range_t *) realloc(r, sizeof(*r) * (i + 2)))) {
394 mp_msg(MSGT_GLOBAL, MSGL_WARN,"can't realloc 'r'\n");
395 return NULL;
397 tmp_min = strtod(s, &endptr);
398 if (*endptr == 'k' || *endptr == 'K') {
399 tmp_min *= 1000.0;
400 endptr++;
401 } else if (*endptr == 'm' || *endptr == 'M') {
402 tmp_min *= 1000000.0;
403 endptr++;
405 if (*endptr == '-') {
406 tmp_max = strtod(endptr + 1, &endptr);
407 if (*endptr == 'k' || *endptr == 'K') {
408 tmp_max *= 1000.0;
409 endptr++;
410 } else if (*endptr == 'm' || *endptr == 'M') {
411 tmp_max *= 1000000.0;
412 endptr++;
414 if (*endptr != ',' && *endptr)
415 goto out_err;
416 } else if (*endptr == ',' || !*endptr) {
417 tmp_max = tmp_min;
418 } else
419 goto out_err;
420 r[i].min = tmp_min;
421 r[i].max = tmp_max;
422 if (r[i].min < 0 || r[i].max < 0)
423 goto out_err;
424 s = endptr + 1;
426 r[i].min = r[i].max = -1;
427 return r;
428 out_err:
429 if (r)
430 free(r);
431 return NULL;
434 /* Borrowed from vo_fbdev.c END */
435 #endif