Use SetErrorMode so Windows will not show all kinds of error dialogs
[mplayer/glamo.git] / libvo / video_out.c
blobc99f312e162760b372975bf8ca92f5b7607f41d8
1 /*
2 * libvo common functions, variables used by many/all drivers.
4 * This file is part of MPlayer.
6 * MPlayer is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * MPlayer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
25 #include <unistd.h>
26 //#include <sys/mman.h>
28 #include "config.h"
29 #include "video_out.h"
30 #include "aspect.h"
31 #include "geometry.h"
33 #include "mp_msg.h"
34 #include "help_mp.h"
36 #include "osdep/shmem.h"
38 //int vo_flags=0;
40 int xinerama_screen = -1;
41 int xinerama_x;
42 int xinerama_y;
44 // currect resolution/bpp on screen: (should be autodetected by vo_init())
45 int vo_depthonscreen=0;
46 int vo_screenwidth=0;
47 int vo_screenheight=0;
49 int vo_config_count=0;
51 // requested resolution/bpp: (-x -y -bpp options)
52 int vo_dx=0;
53 int vo_dy=0;
54 int vo_dwidth=0;
55 int vo_dheight=0;
56 int vo_dbpp=0;
58 int vo_nomouse_input = 0;
59 int vo_grabpointer = 1;
60 int vo_doublebuffering = 1;
61 int vo_vsync = 0;
62 int vo_fs = 0;
63 int vo_fsmode = 0;
64 float vo_panscan = 0.0f;
65 int vo_ontop = 0;
66 int vo_adapter_num=0;
67 int vo_refresh_rate=0;
68 int vo_keepaspect=1;
69 int vo_rootwin=0;
70 int vo_border=1;
71 int WinID = -1;
73 int vo_pts=0; // for hw decoding
74 float vo_fps=0;
76 char *vo_subdevice = NULL;
77 int vo_directrendering=0;
79 int vo_colorkey = 0x0000ff00; // default colorkey is green
80 // (0xff000000 means that colorkey has been disabled)
83 // Externally visible list of all vo drivers
85 extern vo_functions_t video_out_mga;
86 extern vo_functions_t video_out_xmga;
87 extern vo_functions_t video_out_x11;
88 extern vo_functions_t video_out_xover;
89 extern vo_functions_t video_out_xvmc;
90 extern vo_functions_t video_out_xv;
91 extern vo_functions_t video_out_gl;
92 extern vo_functions_t video_out_gl2;
93 extern vo_functions_t video_out_dga;
94 extern vo_functions_t video_out_sdl;
95 extern vo_functions_t video_out_3dfx;
96 extern vo_functions_t video_out_tdfxfb;
97 extern vo_functions_t video_out_s3fb;
98 extern vo_functions_t video_out_wii;
99 extern vo_functions_t video_out_null;
100 extern vo_functions_t video_out_zr;
101 extern vo_functions_t video_out_zr2;
102 extern vo_functions_t video_out_bl;
103 extern vo_functions_t video_out_fbdev;
104 extern vo_functions_t video_out_fbdev2;
105 extern vo_functions_t video_out_svga;
106 extern vo_functions_t video_out_png;
107 extern vo_functions_t video_out_ggi;
108 extern vo_functions_t video_out_aa;
109 extern vo_functions_t video_out_caca;
110 extern vo_functions_t video_out_mpegpes;
111 extern vo_functions_t video_out_yuv4mpeg;
112 extern vo_functions_t video_out_direct3d;
113 extern vo_functions_t video_out_directx;
114 extern vo_functions_t video_out_dxr2;
115 extern vo_functions_t video_out_dxr3;
116 extern vo_functions_t video_out_ivtv;
117 extern vo_functions_t video_out_v4l2;
118 extern vo_functions_t video_out_jpeg;
119 extern vo_functions_t video_out_gif89a;
120 extern vo_functions_t video_out_vesa;
121 extern vo_functions_t video_out_directfb;
122 extern vo_functions_t video_out_dfbmga;
123 extern vo_functions_t video_out_xvidix;
124 extern vo_functions_t video_out_winvidix;
125 extern vo_functions_t video_out_cvidix;
126 extern vo_functions_t video_out_tdfx_vid;
127 extern vo_functions_t video_out_xvr100;
128 extern vo_functions_t video_out_tga;
129 extern vo_functions_t video_out_macosx;
130 extern vo_functions_t video_out_quartz;
131 extern vo_functions_t video_out_pnm;
132 extern vo_functions_t video_out_md5sum;
134 const vo_functions_t* const video_out_drivers[] =
136 #ifdef CONFIG_XVR100
137 &video_out_xvr100,
138 #endif
139 #ifdef CONFIG_TDFX_VID
140 &video_out_tdfx_vid,
141 #endif
142 #ifdef CONFIG_DIRECTX
143 &video_out_directx,
144 #endif
145 #ifdef CONFIG_DIRECT3D
146 &video_out_direct3d,
147 #endif
148 #ifdef CONFIG_COREVIDEO
149 &video_out_macosx,
150 #endif
151 #ifdef CONFIG_QUARTZ
152 &video_out_quartz,
153 #endif
154 #ifdef CONFIG_XMGA
155 &video_out_xmga,
156 #endif
157 #ifdef CONFIG_MGA
158 &video_out_mga,
159 #endif
160 #ifdef CONFIG_TDFXFB
161 &video_out_tdfxfb,
162 #endif
163 #ifdef CONFIG_S3FB
164 &video_out_s3fb,
165 #endif
166 #ifdef CONFIG_WII
167 &video_out_wii,
168 #endif
169 #ifdef CONFIG_3DFX
170 &video_out_3dfx,
171 #endif
172 #ifdef CONFIG_XV
173 &video_out_xv,
174 #endif
175 #ifdef CONFIG_X11
176 &video_out_x11,
177 &video_out_xover,
178 #endif
179 #ifdef CONFIG_GL
180 &video_out_gl,
181 &video_out_gl2,
182 #endif
183 #ifdef CONFIG_DGA
184 &video_out_dga,
185 #endif
186 #ifdef CONFIG_SDL
187 &video_out_sdl,
188 #endif
189 #ifdef CONFIG_GGI
190 &video_out_ggi,
191 #endif
192 #ifdef CONFIG_FBDEV
193 &video_out_fbdev,
194 &video_out_fbdev2,
195 #endif
196 #ifdef CONFIG_SVGALIB
197 &video_out_svga,
198 #endif
199 #ifdef CONFIG_AA
200 &video_out_aa,
201 #endif
202 #ifdef CONFIG_CACA
203 &video_out_caca,
204 #endif
205 #ifdef CONFIG_DXR2
206 &video_out_dxr2,
207 #endif
208 #ifdef CONFIG_DXR3
209 &video_out_dxr3,
210 #endif
211 #ifdef CONFIG_IVTV
212 &video_out_ivtv,
213 #endif
214 #ifdef CONFIG_V4L2_DECODER
215 &video_out_v4l2,
216 #endif
217 #ifdef CONFIG_ZR
218 &video_out_zr,
219 &video_out_zr2,
220 #endif
221 #ifdef CONFIG_BL
222 &video_out_bl,
223 #endif
224 #ifdef CONFIG_VESA
225 &video_out_vesa,
226 #endif
227 #ifdef CONFIG_DIRECTFB
228 &video_out_directfb,
229 #endif
230 #ifdef CONFIG_DFBMGA
231 &video_out_dfbmga,
232 #endif
233 #ifdef CONFIG_VIDIX
234 #ifdef CONFIG_X11
235 &video_out_xvidix,
236 #endif
237 #if defined(__MINGW32__) || defined(__CYGWIN__)
238 &video_out_winvidix,
239 #endif
240 &video_out_cvidix,
241 #endif
242 &video_out_null,
243 // should not be auto-selected
244 #if CONFIG_XVMC
245 &video_out_xvmc,
246 #endif
247 &video_out_mpegpes,
248 #ifdef CONFIG_YUV4MPEG
249 &video_out_yuv4mpeg,
250 #endif
251 #ifdef CONFIG_PNG
252 &video_out_png,
253 #endif
254 #ifdef CONFIG_JPEG
255 &video_out_jpeg,
256 #endif
257 #ifdef CONFIG_GIF
258 &video_out_gif89a,
259 #endif
260 #ifdef CONFIG_TGA
261 &video_out_tga,
262 #endif
263 #ifdef CONFIG_PNM
264 &video_out_pnm,
265 #endif
266 #ifdef CONFIG_MD5SUM
267 &video_out_md5sum,
268 #endif
269 NULL
272 void list_video_out(void){
273 int i=0;
274 mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableVideoOutputDrivers);
275 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_OUTPUTS\n");
276 while (video_out_drivers[i]) {
277 const vo_info_t *info = video_out_drivers[i++]->info;
278 mp_msg(MSGT_GLOBAL, MSGL_INFO,"\t%s\t%s\n", info->short_name, info->name);
280 mp_msg(MSGT_GLOBAL, MSGL_INFO,"\n");
283 const vo_functions_t* init_best_video_out(char** vo_list){
284 int i;
285 // first try the preferred drivers, with their optional subdevice param:
286 if(vo_list && vo_list[0])
287 while(vo_list[0][0]){
288 char* vo=strdup(vo_list[0]);
289 vo_subdevice=strchr(vo,':');
290 if (!strcmp(vo, "pgm"))
291 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_VO_PGM_HasBeenReplaced);
292 if (!strcmp(vo, "md5"))
293 mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_VO_MD5_HasBeenReplaced);
294 if(vo_subdevice){
295 vo_subdevice[0]=0;
296 ++vo_subdevice;
298 for(i=0;video_out_drivers[i];i++){
299 const vo_functions_t* video_driver=video_out_drivers[i];
300 const vo_info_t *info = video_driver->info;
301 if(!strcmp(info->short_name,vo)){
302 // name matches, try it
303 if(!video_driver->preinit(vo_subdevice))
305 free(vo);
306 return video_driver; // success!
310 // continue...
311 free(vo);
312 ++vo_list;
313 if(!(vo_list[0])) return NULL; // do NOT fallback to others
315 // now try the rest...
316 vo_subdevice=NULL;
317 for(i=0;video_out_drivers[i];i++){
318 const vo_functions_t* video_driver=video_out_drivers[i];
319 if(!video_driver->preinit(vo_subdevice))
320 return video_driver; // success!
322 return NULL;
325 int config_video_out(const vo_functions_t *vo, uint32_t width, uint32_t height,
326 uint32_t d_width, uint32_t d_height, uint32_t flags,
327 char *title, uint32_t format) {
328 panscan_init();
329 aspect_save_orig(width,height);
330 aspect_save_prescale(d_width,d_height);
332 if (vo->control(VOCTRL_UPDATE_SCREENINFO, NULL) == VO_TRUE) {
333 aspect(&d_width,&d_height,A_NOZOOM);
334 vo_dx = (int)(vo_screenwidth - d_width) / 2;
335 vo_dy = (int)(vo_screenheight - d_height) / 2;
336 geometry(&vo_dx, &vo_dy, &d_width, &d_height,
337 vo_screenwidth, vo_screenheight);
338 vo_dx += xinerama_x;
339 vo_dy += xinerama_y;
340 vo_dwidth = d_width;
341 vo_dheight = d_height;
344 return vo->config(width, height, d_width, d_height, flags, title, format);
348 * \brief lookup an integer in a table, table must have 0 as the last key
349 * \param key key to search for
350 * \result translation corresponding to key or "to" value of last mapping
351 * if not found.
353 int lookup_keymap_table(const struct keymap *map, int key) {
354 while (map->from && map->from != key) map++;
355 return map->to;
358 #if defined(CONFIG_FBDEV) || defined(CONFIG_VESA)
359 /* Borrowed from vo_fbdev.c
360 Monitor ranges related functions*/
362 char *monitor_hfreq_str = NULL;
363 char *monitor_vfreq_str = NULL;
364 char *monitor_dotclock_str = NULL;
366 float range_max(range_t *r)
368 float max = 0;
370 for (/* NOTHING */; (r->min != -1 && r->max != -1); r++)
371 if (max < r->max) max = r->max;
372 return max;
376 int in_range(range_t *r, float f)
378 for (/* NOTHING */; (r->min != -1 && r->max != -1); r++)
379 if (f >= r->min && f <= r->max)
380 return 1;
381 return 0;
384 range_t *str2range(char *s)
386 float tmp_min, tmp_max;
387 char *endptr = s; // to start the loop
388 range_t *r = NULL;
389 int i;
391 if (!s)
392 return NULL;
393 for (i = 0; *endptr; i++) {
394 if (*s == ',')
395 goto out_err;
396 if (!(r = (range_t *) realloc(r, sizeof(*r) * (i + 2)))) {
397 mp_msg(MSGT_GLOBAL, MSGL_WARN,"can't realloc 'r'\n");
398 return NULL;
400 tmp_min = strtod(s, &endptr);
401 if (*endptr == 'k' || *endptr == 'K') {
402 tmp_min *= 1000.0;
403 endptr++;
404 } else if (*endptr == 'm' || *endptr == 'M') {
405 tmp_min *= 1000000.0;
406 endptr++;
408 if (*endptr == '-') {
409 tmp_max = strtod(endptr + 1, &endptr);
410 if (*endptr == 'k' || *endptr == 'K') {
411 tmp_max *= 1000.0;
412 endptr++;
413 } else if (*endptr == 'm' || *endptr == 'M') {
414 tmp_max *= 1000000.0;
415 endptr++;
417 if (*endptr != ',' && *endptr)
418 goto out_err;
419 } else if (*endptr == ',' || !*endptr) {
420 tmp_max = tmp_min;
421 } else
422 goto out_err;
423 r[i].min = tmp_min;
424 r[i].max = tmp_max;
425 if (r[i].min < 0 || r[i].max < 0)
426 goto out_err;
427 s = endptr + 1;
429 r[i].min = r[i].max = -1;
430 return r;
431 out_err:
432 if (r)
433 free(r);
434 return NULL;
437 /* Borrowed from vo_fbdev.c END */
438 #endif