2 VIDIX accelerated overlay in a WIN32 window
16 #include "video_out.h"
17 #include "video_out_internal.h"
20 #include "osdep/keycodes.h"
21 #include "input/input.h"
27 #include "vosub_vidix.h"
28 #include "vidix/vidix.h"
31 static const vo_info_t info
=
39 LIBVO_EXTERN(winvidix
)
41 #define UNUSED(x) ((void)(x)) /* Removes warning about unused arguments */
44 static char *vidix_name
;
46 /* Image parameters */
47 static uint32_t image_width
;
48 static uint32_t image_height
;
49 static uint32_t image_format
;
50 /* Window parameters */
51 static HWND hWnd
=NULL
,hWndFS
=NULL
;
52 static float window_aspect
;
54 static vidix_grkey_t gr_key
;
57 void set_video_eq(int cap
);
60 static LRESULT CALLBACK
WndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
67 mplayer_put_key(KEY_CLOSE_WIN
);
69 case WM_WINDOWPOSCHANGED
:
72 /*calculate new window rect*/
80 ClientToScreen(hWnd
,&point_window
);
81 GetClientRect(hWnd
,&rd
);
83 vo_dwidth
=rd
.right
- rd
.left
;
84 vo_dheight
=rd
.bottom
- rd
.top
;
85 vo_dx
=point_window
.x
;
86 vo_dy
=point_window
.y
;
87 // aspect(&vo_dwidth, &vo_dheight, A_NOZOOM);
89 /* keep aspect on resize, borrowed from vo_directx.c */
90 tmpheight
= ((float)vo_dwidth
/window_aspect
);
91 tmpheight
+= tmpheight
% 2;
92 if(tmpheight
> vo_dheight
)
94 vo_dwidth
= ((float)vo_dheight
*window_aspect
);
95 vo_dwidth
+= vo_dwidth
% 2;
97 else vo_dheight
= tmpheight
;
98 rd
.right
= rd
.left
+ vo_dwidth
;
99 rd
.bottom
= rd
.top
+ vo_dheight
;
101 if(rd
.left
< 0) rd
.left
= 0;
102 if(rd
.right
> vo_screenwidth
) rd
.right
= vo_screenwidth
;
103 if(rd
.top
< 0) rd
.top
= 0;
104 if(rd
.bottom
> vo_screenheight
) rd
.bottom
= vo_screenheight
;
106 AdjustWindowRect(&rd
, WS_OVERLAPPEDWINDOW
| WS_SIZEBOX
, 0);
107 SetWindowPos(hWnd
, HWND_TOPMOST
, vo_dx
+rd
.left
, vo_dy
+rd
.top
, rd
.right
-rd
.left
, rd
.bottom
-rd
.top
, SWP_NOOWNERZORDER
);
110 if(ShowCursor(FALSE
)>=0)while(ShowCursor(FALSE
)>=0){}
111 aspect(&vo_dwidth
, &vo_dheight
, A_ZOOM
);
112 vo_dx
= (vo_screenwidth
- vo_dwidth
)/2;
113 vo_dy
= (vo_screenheight
- vo_dheight
)/2;
116 /* FIXME: implement runtime resize/move if possible, this way is very ugly! */
118 if(vidix_init(image_width
, image_height
, vo_dx
, vo_dy
, vo_dwidth
, vo_dheight
, image_format
, vo_depthonscreen
, vo_screenwidth
, vo_screenheight
) != 0)
119 mp_msg(MSGT_VO
, MSGL_FATAL
, "Can't initialize VIDIX driver: %s\n", strerror(errno
));
122 mp_msg(MSGT_VO
, MSGL_V
, "[winvidix] window properties: pos: %dx%d, size: %dx%d\n",vo_dx
, vo_dy
, vo_dwidth
, vo_dheight
);
123 if(vidix_grkey_support()){
124 vidix_grkey_get(&gr_key
);
125 gr_key
.key_op
= KEYS_PUT
;
126 gr_key
.ckey
.op
= CKEY_TRUE
;
127 if(vo_fs
)gr_key
.ckey
.red
= gr_key
.ckey
.green
= gr_key
.ckey
.blue
= 0;
129 gr_key
.ckey
.red
= gr_key
.ckey
.blue
= 255;
130 gr_key
.ckey
.green
= 0;
132 vidix_grkey_set(&gr_key
);
140 case SC_MONITORPOWER
:
147 {mplayer_put_key(KEY_LEFT
);break;}
149 {mplayer_put_key(KEY_UP
);break;}
151 {mplayer_put_key(KEY_RIGHT
);break;}
153 {mplayer_put_key(KEY_DOWN
);break;}
155 {mplayer_put_key(KEY_TAB
);break;}
157 {mplayer_put_key(KEY_CTRL
);break;}
159 {mplayer_put_key(KEY_DELETE
);break;}
161 {mplayer_put_key(KEY_INSERT
);break;}
163 {mplayer_put_key(KEY_HOME
);break;}
165 {mplayer_put_key(KEY_END
);break;}
167 {mplayer_put_key(KEY_PAGE_UP
);break;}
169 {mplayer_put_key(KEY_PAGE_DOWN
);break;}
171 {mplayer_put_key(KEY_ESC
);break;}
175 mplayer_put_key(wParam
);
178 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
182 static int config(uint32_t width
, uint32_t height
, uint32_t d_width
,uint32_t d_height
, uint32_t flags
, char *title
, uint32_t format
){
183 title
= "MPlayer VIDIX WIN32 Overlay";
187 image_height
= height
;
189 image_format
= format
;
190 vo_screenwidth
= GetSystemMetrics(SM_CXSCREEN
);
191 vo_screenheight
= GetSystemMetrics(SM_CYSCREEN
);
192 vo_depthonscreen
= GetDeviceCaps(GetDC(GetDesktopWindow()),BITSPIXEL
);
195 aspect_save_orig(width
, height
);
196 aspect_save_prescale(d_width
, d_height
);
197 aspect_save_screenres(vo_screenwidth
, vo_screenheight
);
202 vo_dx
=( vo_screenwidth
- d_width
) / 2; vo_dy
=( vo_screenheight
- d_height
) / 2;
203 geometry(&vo_dx
, &vo_dy
, &d_width
, &d_height
, vo_screenwidth
, vo_screenheight
);
205 vo_fs
= flags
&VOFLAG_FULLSCREEN
;
208 aspect(&d_width
, &d_height
, A_NOZOOM
);
209 vo_dwidth
=d_width
; vo_dheight
=d_height
;
210 window_aspect
= (float)d_width
/ (float)d_height
;
213 if(!vo_config_count
){
214 HINSTANCE hInstance
= GetModuleHandle(NULL
);
219 rd
.right
= rd
.left
+ vo_dwidth
;
220 rd
.bottom
= rd
.top
+ vo_dheight
;
221 AdjustWindowRect(&rd
,WS_OVERLAPPEDWINDOW
| WS_SIZEBOX
,0);
222 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
223 wc
.lpfnWndProc
= WndProc
;
226 wc
.hInstance
= hInstance
;
227 wc
.hCursor
= LoadCursor(NULL
,IDC_ARROW
);
228 wc
.hIcon
=ExtractIcon(hInstance
,"mplayer.exe",0);
229 //LoadIcon(NULL,IDI_APPLICATION);
230 wc
.hbrBackground
= CreateSolidBrush(RGB(255,0,255));
231 wc
.lpszClassName
= "MPlayer - The Movie Player";
232 wc
.lpszMenuName
= NULL
;
234 hWnd
= CreateWindow("MPlayer - The Movie Player",
236 WS_OVERLAPPEDWINDOW
| WS_SIZEBOX
,
245 wc
.hbrBackground
= CreateSolidBrush(RGB(0,0,0));
246 wc
.lpszClassName
= "MPlayer - Fullscreen";
248 hWndFS
= CreateWindow("MPlayer - Fullscreen","MPlayer VIDIX Fullscreen",WS_POPUP
,0,0,vo_screenwidth
,vo_screenheight
,hWnd
,NULL
,hInstance
,NULL
);
255 ShowWindow(hWnd
,SW_SHOW
);
256 if(vo_fs
)ShowWindow(hWndFS
,SW_SHOW
);
261 static void check_events(void){
263 while (PeekMessage(&msg
, NULL
, 0, 0,PM_REMOVE
))
265 TranslateMessage(&msg
);
266 DispatchMessage(&msg
);
270 /* draw_osd, flip_page, draw_slice, draw_frame should be
271 overwritten with vidix functions (vosub_vidix.c) */
272 static void draw_osd(void){
273 mp_msg(MSGT_VO
, MSGL_FATAL
, "[winvidix] error: didn't use vidix draw_osd!\n");
277 static void flip_page(void){
278 mp_msg(MSGT_VO
, MSGL_FATAL
, "[winvidix] error: didn't use vidix flip_page!\n");
282 static int draw_slice(uint8_t *src
[], int stride
[],int w
, int h
, int x
, int y
){
289 mp_msg(MSGT_VO
, MSGL_FATAL
, "[winvidix] error: didn't use vidix draw_slice!\n");
293 static int draw_frame(uint8_t *src
[]){
295 mp_msg(MSGT_VO
, MSGL_FATAL
, "[winvidix] error: didn't use vidix draw_frame!\n");
299 static int query_format(uint32_t format
){
300 return vidix_query_fourcc(format
);
303 static void uninit(void){
304 DestroyWindow(hWndFS
);
306 if ( !vo_config_count
) return;
316 static int preinit(const char *arg
){
318 vidix_name
= strdup(arg
);
321 mp_msg(MSGT_VO
, MSGL_INFO
, "No vidix driver name provided, probing available ones (-v option for details)!\n");
325 if (vidix_preinit(vidix_name
, &video_out_winvidix
) != 0)
331 static int control(uint32_t request
, void *data
, ...){
333 case VOCTRL_FULLSCREEN
:
334 if(!vo_fs
){vo_fs
=1;ShowWindow(hWndFS
,SW_SHOW
);SetForegroundWindow(hWndFS
);}
335 else {vo_fs
=0; ShowWindow(hWndFS
,SW_HIDE
);}
337 case VOCTRL_QUERY_FORMAT
:
338 return query_format(*((uint32_t*)data
));
339 case VOCTRL_SET_EQUALIZER
:
345 value
= va_arg(ap
, int);
348 return vidix_control(request
, data
, (int *)value
);
350 case VOCTRL_GET_EQUALIZER
:
356 value
= va_arg(ap
, int*);
359 return vidix_control(request
, data
, value
);
362 return vidix_control(request
, data
);
363 // return VO_NOTIMPL;