Mercurial > mplayer.hg
annotate libvo/vo_winvidix.c @ 15918:8f6c98310f38
initial translation, synced with 1.12
author | gabrov |
---|---|
date | Mon, 04 Jul 2005 18:29:48 +0000 |
parents | 0651bf280391 |
children | fd51fd1ff231 |
rev | line source |
---|---|
10979 | 1 /* |
2 VIDIX accelerated overlay in a WIN32 window | |
3 | |
4 (C) Sascha Sommer | |
5 | |
6 | |
7 */ | |
8 | |
9 #include <stdio.h> | |
10 #include <stdlib.h> | |
11 #include <string.h> | |
12 #include <math.h> | |
13 #include <errno.h> | |
14 | |
15 #include "config.h" | |
16 #include "video_out.h" | |
17 #include "video_out_internal.h" | |
18 | |
19 #include <windows.h> | |
13787
e047e70a9767
Handle "xxx.h" vs "../xxx.h" include paths in a consistent way.
diego
parents:
12861
diff
changeset
|
20 #include "osdep/keycodes.h" |
e047e70a9767
Handle "xxx.h" vs "../xxx.h" include paths in a consistent way.
diego
parents:
12861
diff
changeset
|
21 #include "input/input.h" |
10979 | 22 |
23 #include "aspect.h" | |
24 #include "mp_msg.h" | |
25 | |
26 #include "vosub_vidix.h" | |
13787
e047e70a9767
Handle "xxx.h" vs "../xxx.h" include paths in a consistent way.
diego
parents:
12861
diff
changeset
|
27 #include "vidix/vidixlib.h" |
10979 | 28 |
29 extern void mplayer_put_key(int code); | |
30 | |
31 static vo_info_t info = | |
32 { | |
33 "WIN32 (VIDIX)", | |
34 "winvidix", | |
35 "Sascha Sommer", | |
36 "" | |
37 }; | |
38 | |
39 LIBVO_EXTERN(winvidix) | |
40 | |
41 #define UNUSED(x) ((void)(x)) /* Removes warning about unused arguments */ | |
42 | |
43 /* VIDIX related */ | |
44 static char *vidix_name; | |
45 | |
46 /* Image parameters */ | |
47 static uint32_t image_width; | |
48 static uint32_t image_height; | |
49 static uint32_t image_format; | |
50 static HWND hWnd; | |
51 /* Window parameters */ | |
52 static HWND hWnd=NULL,hWndFS=NULL; | |
15822
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
53 static float window_aspect; |
10979 | 54 |
55 static vidix_grkey_t gr_key; | |
56 | |
57 | |
58 extern void set_video_eq( int cap ); | |
59 extern int vo_config_count; | |
60 | |
61 | |
62 static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) | |
63 { | |
64 switch (message){ | |
65 case WM_DESTROY: | |
15822
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
66 PostQuitMessage(0); |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
67 return 0; |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
68 case WM_CLOSE: |
10979 | 69 mp_input_queue_cmd(mp_input_parse_cmd("quit")); |
70 break; | |
71 case WM_WINDOWPOSCHANGED: | |
72 { | |
15822
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
73 int tmpheight=0; |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
74 /*calculate new window rect*/ |
10979 | 75 if(!vo_fs){ |
76 RECT rd; | |
77 POINT point_window; | |
78 if(!hWnd)hWnd=hwnd; | |
79 ShowCursor(TRUE); | |
80 point_window.x = 0; | |
81 point_window.y = 0; | |
82 ClientToScreen(hWnd,&point_window); | |
83 GetClientRect(hWnd,&rd); | |
84 | |
85 vo_dwidth=rd.right - rd.left; | |
86 vo_dheight=rd.bottom - rd.top; | |
87 vo_dx =point_window.x; | |
88 vo_dy =point_window.y; | |
89 // aspect(&vo_dwidth, &vo_dheight, A_NOZOOM); | |
15822
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
90 |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
91 /* keep aspect on resize, borrowed from vo_directx.c */ |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
92 tmpheight = ((float)vo_dwidth/window_aspect); |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
93 tmpheight += tmpheight % 2; |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
94 if(tmpheight > vo_dheight) |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
95 { |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
96 vo_dwidth = ((float)vo_dheight*window_aspect); |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
97 vo_dwidth += vo_dwidth % 2; |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
98 } |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
99 else vo_dheight = tmpheight; |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
100 rd.right = rd.left + vo_dwidth; |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
101 rd.bottom = rd.top + vo_dheight; |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
102 |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
103 if(rd.left < 0) rd.left = 0; |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
104 if(rd.right > vo_screenwidth) rd.right = vo_screenwidth; |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
105 if(rd.top < 0) rd.top = 0; |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
106 if(rd.bottom > vo_screenheight) rd.bottom = vo_screenheight; |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
107 |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
108 AdjustWindowRect(&rd, WS_OVERLAPPEDWINDOW | WS_SIZEBOX, 0); |
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
109 SetWindowPos(hWnd, HWND_TOPMOST, vo_dx+rd.left, vo_dy+rd.top, rd.right-rd.left, rd.bottom-rd.top, SWP_NOOWNERZORDER); |
10979 | 110 } |
111 else { | |
112 if(ShowCursor(FALSE)>=0)while(ShowCursor(FALSE)>=0){} | |
113 aspect(&vo_dwidth, &vo_dheight, A_ZOOM); | |
114 vo_dx = (vo_screenwidth - vo_dwidth)/2; | |
115 vo_dy = (vo_screenheight - vo_dheight)/2; | |
116 } | |
117 /*update vidix*/ | |
118 /* FIXME: implement runtime resize/move if possible, this way is very ugly! */ | |
119 vidix_stop(); | |
120 if(vidix_init(image_width, image_height, vo_dx, vo_dy, vo_dwidth, vo_dheight, image_format, vo_depthonscreen, vo_screenwidth, vo_screenheight) != 0) | |
121 mp_msg(MSGT_VO, MSGL_FATAL, "Can't initialize VIDIX driver: %s\n", strerror(errno)); | |
122 /*set colorkey*/ | |
123 vidix_start(); | |
124 mp_msg(MSGT_VO, MSGL_V, "[winvidix] window properties: pos: %dx%d, size: %dx%d\n",vo_dx, vo_dy, vo_dwidth, vo_dheight); | |
125 if(vidix_grkey_support()){ | |
126 vidix_grkey_get(&gr_key); | |
127 gr_key.key_op = KEYS_PUT; | |
128 gr_key.ckey.op = CKEY_TRUE; | |
129 if(vo_fs)gr_key.ckey.red = gr_key.ckey.green = gr_key.ckey.blue = 0; | |
130 else { | |
131 gr_key.ckey.red = gr_key.ckey.blue = 255; | |
132 gr_key.ckey.green = 0; | |
133 } | |
134 vidix_grkey_set(&gr_key); | |
135 } | |
136 | |
137 } | |
138 break; | |
139 case WM_SYSCOMMAND: | |
140 switch (wParam){ | |
141 case SC_SCREENSAVE: | |
142 case SC_MONITORPOWER: | |
143 return 0; | |
144 } | |
145 break; | |
146 case WM_KEYDOWN: | |
147 switch (wParam){ | |
148 case VK_LEFT: | |
149 {mplayer_put_key(KEY_LEFT);break;} | |
150 case VK_UP: | |
151 {mplayer_put_key(KEY_UP);break;} | |
152 case VK_RIGHT: | |
153 {mplayer_put_key(KEY_RIGHT);break;} | |
154 case VK_DOWN: | |
155 {mplayer_put_key(KEY_DOWN);break;} | |
156 case VK_TAB: | |
157 {mplayer_put_key(KEY_TAB);break;} | |
158 case VK_CONTROL: | |
159 {mplayer_put_key(KEY_CTRL);break;} | |
160 case VK_DELETE: | |
161 {mplayer_put_key(KEY_DELETE);break;} | |
162 case VK_INSERT: | |
163 {mplayer_put_key(KEY_INSERT);break;} | |
164 case VK_HOME: | |
165 {mplayer_put_key(KEY_HOME);break;} | |
166 case VK_END: | |
167 {mplayer_put_key(KEY_END);break;} | |
168 case VK_PRIOR: | |
169 {mplayer_put_key(KEY_PAGE_UP);break;} | |
170 case VK_NEXT: | |
171 {mplayer_put_key(KEY_PAGE_DOWN);break;} | |
172 case VK_ESCAPE: | |
173 {mplayer_put_key(KEY_ESC);break;} | |
174 } | |
175 break; | |
176 case WM_CHAR: | |
177 mplayer_put_key(wParam); | |
178 break; | |
179 } | |
180 return DefWindowProc(hwnd, message, wParam, lParam); | |
181 } | |
182 | |
183 | |
184 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width,uint32_t d_height, uint32_t flags, char *title, uint32_t format){ | |
185 title = "MPlayer VIDIX WIN32 Overlay"; | |
186 | |
187 panscan_init(); | |
188 | |
189 image_height = height; | |
190 image_width = width; | |
191 image_format = format; | |
192 vo_screenwidth = GetSystemMetrics(SM_CXSCREEN); | |
193 vo_screenheight = GetSystemMetrics(SM_CYSCREEN); | |
194 vo_depthonscreen = GetDeviceCaps(GetDC(GetDesktopWindow()),BITSPIXEL); | |
195 | |
196 | |
197 aspect_save_orig(width, height); | |
198 aspect_save_prescale(d_width, d_height); | |
199 aspect_save_screenres(vo_screenwidth, vo_screenheight); | |
200 | |
201 vo_dx = 0; | |
202 vo_dy = 0; | |
203 | |
204 vo_dx=( vo_screenwidth - d_width ) / 2; vo_dy=( vo_screenheight - d_height ) / 2; | |
205 geometry(&vo_dx, &vo_dy, &d_width, &d_height, vo_screenwidth, vo_screenheight); | |
206 | |
15212
05aa13cdf92f
replace VO and VF numeric flags with #defined identifiers
henry
parents:
13787
diff
changeset
|
207 vo_fs = flags&VOFLAG_FULLSCREEN; |
10979 | 208 |
209 | |
210 aspect(&d_width, &d_height, A_NOZOOM); | |
211 vo_dwidth=d_width; vo_dheight=d_height; | |
15822
0651bf280391
keep aspect when resizing, quit MPlayer when closing the window patch by Erik Lunchpail <erik_27can at yahoo.com>
faust3
parents:
15621
diff
changeset
|
212 window_aspect = (float)d_width / (float)d_height; |
10979 | 213 |
214 | |
215 if(!vo_config_count){ | |
216 HINSTANCE hInstance = GetModuleHandle(NULL); | |
217 WNDCLASS wc; | |
218 RECT rd; | |
219 rd.left = vo_dx; | |
220 rd.top = vo_dy; | |
221 rd.right = rd.left + vo_dwidth; | |
222 rd.bottom = rd.top + vo_dheight; | |
223 AdjustWindowRect(&rd,WS_OVERLAPPEDWINDOW| WS_SIZEBOX,0); | |
224 wc.style = CS_HREDRAW | CS_VREDRAW; | |
225 wc.lpfnWndProc = WndProc; | |
226 wc.cbClsExtra = 0; | |
227 wc.cbWndExtra = 0; | |
228 wc.hInstance = hInstance; | |
229 wc.hCursor = LoadCursor(NULL,IDC_ARROW); | |
230 wc.hIcon =ExtractIcon(hInstance,"mplayer.exe",0); | |
231 //LoadIcon(NULL,IDI_APPLICATION); | |
232 wc.hbrBackground = CreateSolidBrush(RGB(255,0,255)); | |
12858 | 233 wc.lpszClassName = "MPlayer - The Movie Player"; |
10979 | 234 wc.lpszMenuName = NULL; |
235 RegisterClass(&wc); | |
12861 | 236 hWnd = CreateWindow("MPlayer - The Movie Player", |
10979 | 237 title, |
238 WS_OVERLAPPEDWINDOW| WS_SIZEBOX, | |
239 rd.left, | |
240 rd.top, | |
241 rd.right - rd.left, | |
242 rd.bottom - rd.top, | |
243 NULL, | |
244 NULL, | |
245 hInstance, | |
246 NULL); | |
247 wc.hbrBackground = CreateSolidBrush(RGB(0,0,0)); | |
248 wc.lpszClassName = "MPlayer - Fullscreen"; | |
249 RegisterClass(&wc); | |
250 hWndFS = CreateWindow("MPlayer - Fullscreen","MPlayer VIDIX Fullscreen",WS_POPUP,0,0,vo_screenwidth,vo_screenheight,hWnd,NULL,hInstance,NULL); | |
251 | |
252 | |
253 | |
254 | |
255 | |
256 } | |
257 ShowWindow(hWnd,SW_SHOW); | |
258 if(vo_fs)ShowWindow(hWndFS,SW_SHOW); | |
259 | |
260 return(0); | |
261 } | |
262 | |
263 static void check_events(void){ | |
264 MSG msg; | |
265 while (PeekMessage(&msg, NULL, 0, 0,PM_REMOVE)) | |
266 { | |
267 TranslateMessage(&msg); | |
268 DispatchMessage(&msg); | |
269 } | |
270 } | |
271 | |
272 /* draw_osd, flip_page, draw_slice, draw_frame should be | |
273 overwritten with vidix functions (vosub_vidix.c) */ | |
274 static void draw_osd(void){ | |
275 mp_msg(MSGT_VO, MSGL_FATAL, "[winvidix] error: didn't use vidix draw_osd!\n"); | |
276 return; | |
277 } | |
278 | |
279 static void flip_page(void){ | |
280 mp_msg(MSGT_VO, MSGL_FATAL, "[winvidix] error: didn't use vidix flip_page!\n"); | |
281 return; | |
282 } | |
283 | |
284 static uint32_t draw_slice(uint8_t *src[], int stride[],int w, int h, int x, int y){ | |
285 UNUSED(src); | |
286 UNUSED(stride); | |
287 UNUSED(w); | |
288 UNUSED(h); | |
289 UNUSED(x); | |
290 UNUSED(y); | |
291 mp_msg(MSGT_VO, MSGL_FATAL, "[winvidix] error: didn't use vidix draw_slice!\n"); | |
292 return(-1); | |
293 } | |
294 | |
295 static uint32_t draw_frame(uint8_t *src[]){ | |
296 UNUSED(src); | |
297 mp_msg(MSGT_VO, MSGL_FATAL, "[winvidix] error: didn't use vidix draw_frame!\n"); | |
298 return(-1); | |
299 } | |
300 | |
301 static uint32_t query_format(uint32_t format){ | |
302 return(vidix_query_fourcc(format)); | |
303 } | |
304 | |
305 static void uninit(void){ | |
306 DestroyWindow(hWndFS); | |
307 DestroyWindow(hWnd); | |
308 if ( !vo_config_count ) return; | |
309 vidix_term(); | |
310 | |
311 if (vidix_name){ | |
312 free(vidix_name); | |
313 vidix_name = NULL; | |
314 } | |
315 // | |
316 } | |
317 | |
318 static uint32_t preinit(const char *arg){ | |
319 if (arg) | |
320 vidix_name = strdup(arg); | |
321 else | |
322 { | |
11462 | 323 mp_msg(MSGT_VO, MSGL_INFO, "No vidix driver name provided, probing available ones (-v option for details)!\n"); |
10979 | 324 vidix_name = NULL; |
325 } | |
326 | |
327 if (vidix_preinit(vidix_name, &video_out_winvidix) != 0) | |
328 return(1); | |
329 | |
330 return(0); | |
331 } | |
332 | |
333 static uint32_t control(uint32_t request, void *data, ...){ | |
334 switch (request) { | |
335 case VOCTRL_FULLSCREEN: | |
15621
54e8a5b5d9c4
regain window focus in fullscreen, patch by Erik Lunchpail <enik_27can at yahoo.com>
faust3
parents:
15212
diff
changeset
|
336 if(!vo_fs){vo_fs=1;ShowWindow(hWndFS,SW_SHOW);SetForegroundWindow(hWndFS);} |
10979 | 337 else {vo_fs=0; ShowWindow(hWndFS,SW_HIDE);} |
338 break; | |
339 case VOCTRL_QUERY_FORMAT: | |
340 return query_format(*((uint32_t*)data)); | |
341 case VOCTRL_SET_EQUALIZER: | |
342 { | |
343 va_list ap; | |
344 int value; | |
345 | |
346 va_start(ap, data); | |
347 value = va_arg(ap, int); | |
348 va_end(ap); | |
349 | |
350 return vidix_control(request, data, (int *)value); | |
351 } | |
352 case VOCTRL_GET_EQUALIZER: | |
353 { | |
354 va_list ap; | |
355 int *value; | |
356 | |
357 va_start(ap, data); | |
358 value = va_arg(ap, int*); | |
359 va_end(ap); | |
360 | |
361 return vidix_control(request, data, value); | |
362 } | |
363 } | |
364 return vidix_control(request, data); | |
365 // return VO_NOTIMPL; | |
366 } |