Mercurial > mplayer.hg
annotate libvo/vo_quartz.c @ 12886:9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
author | nplourde |
---|---|
date | Thu, 22 Jul 2004 20:02:26 +0000 |
parents | b177cc8afdc0 |
children | 3a58fa9639d4 |
rev | line source |
---|---|
12296 | 1 /* |
2 vo_quartz.c | |
3 | |
4 by Nicolas Plourde <nicolasplourde@hotmail.com> | |
5 | |
6 Copyright (c) Nicolas Plourde - April 2004 | |
12414 | 7 |
8 YUV support Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org> | |
12296 | 9 |
10 MPlayer Mac OSX Quartz video out module. | |
11 | |
12785
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
12 todo: -RGB32 color space support |
12460 | 13 -screen overlay output |
12623 | 14 -while mouse button down event mplayer is locked, fix that |
12886
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
15 -Enable live resize |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
16 -fix menu |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
17 -quit properly when using close button |
12296 | 18 -(add sugestion here) |
12120 | 19 */ |
20 | |
21 //SYS | |
22 #include <stdio.h> | |
23 | |
24 //OSX | |
25 #include <Carbon/Carbon.h> | |
12414 | 26 #include <QuickTime/QuickTime.h> |
12120 | 27 |
28 //MPLAYER | |
29 #include "config.h" | |
12414 | 30 #include "fastmemcpy.h" |
12120 | 31 #include "video_out.h" |
32 #include "video_out_internal.h" | |
33 #include "aspect.h" | |
12414 | 34 #include "mp_msg.h" |
35 #include "m_option.h" | |
12120 | 36 |
37 #include "../input/input.h" | |
38 #include "../input/mouse.h" | |
39 | |
40 #include "vo_quartz.h" | |
41 | |
12296 | 42 static vo_info_t info = |
43 { | |
44 "Mac OSX (Quartz)", | |
45 "quartz", | |
12414 | 46 "Nicolas Plourde <nicolasplourde@hotmail.com>, Romain Dolbeau <romain@dolbeau.org>", |
12296 | 47 "" |
12120 | 48 }; |
49 | |
12296 | 50 LIBVO_EXTERN(quartz) |
12120 | 51 |
12414 | 52 static uint32_t image_depth; |
53 static uint32_t image_format; | |
54 static uint32_t image_size; | |
55 static uint32_t image_buffer_size; | |
12432 | 56 static char *image_data; |
12414 | 57 |
12432 | 58 static ImageSequence seqId; |
12414 | 59 static CodecType image_qtcodec; |
12487 | 60 static PlanarPixmapInfoYUV420 *P = NULL; |
12424 | 61 static struct |
62 { | |
63 ImageDescriptionHandle desc; | |
64 Handle extension_colr; | |
65 Handle extension_fiel; | |
66 Handle extension_clap; | |
67 Handle extension_pasp; | |
12414 | 68 } yuv_qt_stuff; |
12432 | 69 static MatrixRecord matrix; |
12414 | 70 static int EnterMoviesDone = 0; |
12487 | 71 static int get_image_done = 0; |
12120 | 72 |
12296 | 73 extern int vo_ontop; |
12487 | 74 extern int vo_fs; // user want fullscreen |
75 static int vo_quartz_fs; // we are in fullscreen | |
12120 | 76 |
12826
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
77 static int winLevel = 1; |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
78 int levelList[] = |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
79 { |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
80 kCGDesktopWindowLevelKey, |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
81 kCGNormalWindowLevelKey, |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
82 kCGScreenSaverWindowLevelKey |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
83 }; |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
84 |
12487 | 85 static int int_pause = 0; |
86 static float winAlpha = 1; | |
12296 | 87 |
12487 | 88 static int device_width; |
89 static int device_height; | |
12519
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
90 static int device_id; |
12120 | 91 |
12487 | 92 static WindowRef theWindow = NULL; |
12826
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
93 static WindowGroupRef winGroup = NULL; |
12296 | 94 |
12487 | 95 static Rect imgRect; // size of the original image (unscaled) |
96 static Rect dstRect; // size of the displayed image (after scaling) | |
97 static Rect winRect; // size of the window containg the displayed image (include padding) | |
98 static Rect oldWinRect; // size of the window containg the displayed image (include padding) when NOT in FS mode | |
12519
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
99 static Rect deviceRect; // size of the display device |
12296 | 100 |
12120 | 101 #include "../osdep/keycodes.h" |
12296 | 102 extern void mplayer_put_key(int code); |
103 | |
104 extern void vo_draw_text(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)); | |
12120 | 105 |
106 //PROTOTYPE///////////////////////////////////////////////////////////////// | |
12296 | 107 void window_resized(); |
108 void window_ontop(); | |
109 void window_fullscreen(); | |
12120 | 110 |
12886
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
111 static inline int convert_key(UInt32 key, UInt32 charcode) |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
112 { |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
113 switch(key) |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
114 { |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
115 case QZ_IBOOK_ENTER: |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
116 case QZ_RETURN: return KEY_ENTER; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
117 case QZ_ESCAPE: return KEY_ESC; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
118 case QZ_BACKSPACE: return KEY_BACKSPACE; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
119 case QZ_LALT: return KEY_BACKSPACE; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
120 case QZ_LCTRL: return KEY_BACKSPACE; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
121 case QZ_LSHIFT: return KEY_BACKSPACE; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
122 case QZ_F1: return KEY_F+1; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
123 case QZ_F2: return KEY_F+2; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
124 case QZ_F3: return KEY_F+3; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
125 case QZ_F4: return KEY_F+4; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
126 case QZ_F5: return KEY_F+5; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
127 case QZ_F6: return KEY_F+6; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
128 case QZ_F7: return KEY_F+7; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
129 case QZ_F8: return KEY_F+8; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
130 case QZ_F9: return KEY_F+9; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
131 case QZ_F10: return KEY_F+10; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
132 case QZ_F11: return KEY_F+11; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
133 case QZ_F12: return KEY_F+12; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
134 case QZ_INSERT: return KEY_INSERT; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
135 case QZ_DELETE: return KEY_DELETE; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
136 case QZ_HOME: return KEY_HOME; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
137 case QZ_END: return KEY_END; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
138 case QZ_KP_PLUS: return '+'; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
139 case QZ_KP_MINUS: return '-'; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
140 case QZ_TAB: return KEY_TAB; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
141 case QZ_PAGEUP: return KEY_PAGE_UP; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
142 case QZ_PAGEDOWN: return KEY_PAGE_DOWN; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
143 case QZ_UP: return KEY_UP; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
144 case QZ_DOWN: return KEY_DOWN; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
145 case QZ_LEFT: return KEY_LEFT; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
146 case QZ_RIGHT: return KEY_RIGHT; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
147 case QZ_KP_MULTIPLY: return '*'; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
148 case QZ_KP_DIVIDE: return '/'; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
149 case QZ_KP_ENTER: return KEY_BACKSPACE; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
150 case QZ_KP_PERIOD: return KEY_KPDEC; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
151 case QZ_KP0: return KEY_KP0; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
152 case QZ_KP1: return KEY_KP1; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
153 case QZ_KP2: return KEY_KP2; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
154 case QZ_KP3: return KEY_KP3; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
155 case QZ_KP4: return KEY_KP4; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
156 case QZ_KP5: return KEY_KP5; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
157 case QZ_KP6: return KEY_KP6; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
158 case QZ_KP7: return KEY_KP7; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
159 case QZ_KP8: return KEY_KP8; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
160 case QZ_KP9: return KEY_KP9; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
161 case QZ_LEFTBRACKET: SetWindowAlpha(theWindow, winAlpha-=0.05); return -1; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
162 case QZ_RIGHTBRACKET: SetWindowAlpha(theWindow, winAlpha+=0.05); return -1; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
163 default: return charcode; |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
164 } |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
165 } |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
166 |
12460 | 167 static OSStatus MainEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData); |
12296 | 168 |
169 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride) | |
170 { | |
12424 | 171 switch (image_format) |
172 { | |
173 case IMGFMT_RGB32: | |
174 vo_draw_alpha_rgb32(w,h,src,srca,stride,image_data+4*(y0*imgRect.right+x0),4*imgRect.right); | |
175 break; | |
176 case IMGFMT_YV12: | |
177 case IMGFMT_IYUV: | |
178 case IMGFMT_I420: | |
12487 | 179 vo_draw_alpha_yv12(w,h,src,srca,stride, ((char*)P) + P->componentInfoY.offset + x0 + y0 * imgRect.right, imgRect.right); |
12424 | 180 break; |
181 case IMGFMT_UYVY: | |
12517 | 182 vo_draw_alpha_uyvy(w,h,src,srca,stride,((char*)P) + (x0 + y0 * imgRect.right) * 2,imgRect.right*2); |
12424 | 183 break; |
184 case IMGFMT_YUY2: | |
12487 | 185 vo_draw_alpha_yuy2(w,h,src,srca,stride,((char*)P) + (x0 + y0 * imgRect.right) * 2,imgRect.right*2); |
12424 | 186 break; |
12487 | 187 } |
12296 | 188 } |
12120 | 189 |
190 //default window event handler | |
12460 | 191 static OSStatus MainEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *userData) |
12120 | 192 { |
12624 | 193 OSStatus result = noErr; |
12460 | 194 UInt32 class = GetEventClass (event); |
195 UInt32 kind = GetEventKind (event); | |
12624 | 196 |
197 result = CallNextEventHandler(nextHandler, event); | |
198 | |
12460 | 199 if(class == kEventClassWindow) |
200 { | |
201 WindowRef window; | |
202 Rect rectPort = {0,0,0,0}; | |
203 | |
204 GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window); | |
205 | |
206 if(window) | |
207 { | |
12519
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
208 GetPortBounds(GetWindowPort(window), &rectPort); |
12460 | 209 } |
12296 | 210 |
12460 | 211 switch (kind) |
212 { | |
213 //close window | |
214 case kEventWindowClosed: | |
215 mplayer_put_key(KEY_ESC); | |
216 break; | |
217 | |
218 //resize window | |
219 case kEventWindowBoundsChanged: | |
220 window_resized(); | |
221 flip_page(); | |
222 break; | |
223 | |
12624 | 224 default:result = eventNotHandledErr;break; |
12460 | 225 } |
226 } | |
227 else if(class == kEventClassKeyboard) | |
228 { | |
229 char macCharCodes; | |
230 UInt32 macKeyCode; | |
231 UInt32 macKeyModifiers; | |
232 | |
233 GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(macCharCodes), NULL, &macCharCodes); | |
234 GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(macKeyCode), NULL, &macKeyCode); | |
235 GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(macKeyModifiers), NULL, &macKeyModifiers); | |
12296 | 236 |
12886
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
237 if (kind == kEventRawKeyRepeat || kind == kEventRawKeyDown) |
12296 | 238 { |
12886
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
239 int key = convert_key(macKeyCode, macCharCodes); |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
240 if(key != -1) |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
241 mplayer_put_key(key); |
12460 | 242 } |
12886
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
243 else |
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
244 result = eventNotHandledErr; |
12460 | 245 } |
246 else if(class == kEventClassMouse) | |
247 { | |
248 WindowPtr tmpWin; | |
249 Point mousePos; | |
250 | |
251 GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, 0, sizeof(Point), 0, &mousePos); | |
252 | |
253 switch (kind) | |
254 { | |
255 case kEventMouseDown: | |
12296 | 256 { |
12460 | 257 EventMouseButton button; |
258 GetEventParameter(event, kEventParamMouseButton, typeMouseButton, 0, sizeof(EventMouseButton), 0, &button); | |
259 | |
12296 | 260 short part = FindWindow(mousePos,&tmpWin); |
261 | |
262 if(part == inMenuBar) | |
263 { | |
264 MenuSelect(mousePos); | |
12460 | 265 HiliteMenu(0); |
12296 | 266 } |
12460 | 267 else if(part == inContent) |
268 { | |
269 switch(button) | |
270 { | |
271 case 1: mplayer_put_key(MOUSE_BTN0);break; | |
272 case 2: mplayer_put_key(MOUSE_BTN2);break; | |
273 case 3: mplayer_put_key(MOUSE_BTN1);break; | |
274 | |
12624 | 275 default:result = eventNotHandledErr;break; |
12460 | 276 } |
277 } | |
278 } | |
279 break; | |
280 | |
281 case kEventMouseWheelMoved: | |
282 { | |
283 int wheel; | |
284 GetEventParameter(event, kEventParamMouseWheelDelta, typeSInt32, 0, sizeof(int), 0, &wheel); | |
285 | |
286 short part = FindWindow(mousePos,&tmpWin); | |
287 | |
288 if(part == inContent) | |
289 { | |
290 if(wheel > 0) | |
291 mplayer_put_key(MOUSE_BTN3); | |
292 else | |
293 mplayer_put_key(MOUSE_BTN4); | |
294 } | |
295 } | |
296 break; | |
297 | |
12624 | 298 default:result = eventNotHandledErr;break; |
12460 | 299 } |
300 } | |
301 | |
12624 | 302 return result; |
12296 | 303 } |
12120 | 304 |
12487 | 305 static void quartz_CreateWindow(uint32_t d_width, uint32_t d_height, WindowAttributes windowAttrs) |
306 { | |
307 CFStringRef titleKey; | |
308 CFStringRef windowTitle; | |
309 OSStatus result; | |
310 | |
311 SetRect(&winRect, 0, 0, d_width, d_height); | |
312 SetRect(&oldWinRect, 0, 0, d_width, d_height); | |
313 SetRect(&dstRect, 0, 0, d_width, d_height); | |
314 | |
315 CreateNewWindow(kDocumentWindowClass, windowAttrs, &winRect, &theWindow); | |
12826
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
316 |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
317 CreateWindowGroup(0, &winGroup); |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
318 SetWindowGroup(theWindow, winGroup); |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
319 |
12487 | 320 //Set window title |
12785
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
321 titleKey = CFSTR("MPlayer - The Movie Player"); |
12487 | 322 windowTitle = CFCopyLocalizedString(titleKey, NULL); |
323 result = SetWindowTitleWithCFString(theWindow, windowTitle); | |
324 CFRelease(titleKey); | |
325 CFRelease(windowTitle); | |
326 | |
327 //Install event handler | |
328 const EventTypeSpec winEvents[] = { { kEventClassKeyboard, kEventRawKeyDown }, | |
12886
9b95958f4eb0
listen for key repeats, patch by Dan Christiansen
nplourde
parents:
12830
diff
changeset
|
329 { kEventClassKeyboard, kEventRawKeyRepeat }, |
12487 | 330 { kEventClassMouse, kEventMouseDown }, |
331 { kEventClassMouse, kEventMouseWheelMoved }, | |
332 { kEventClassWindow, kEventWindowClosed }, | |
333 { kEventClassWindow, kEventWindowBoundsChanged } }; | |
334 | |
12519
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
335 InstallApplicationEventHandler (NewEventHandlerUPP (MainEventHandler), GetEventTypeCount(winEvents), winEvents, NULL, NULL); |
12487 | 336 } |
337 | |
12296 | 338 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) |
339 { | |
340 WindowAttributes windowAttrs; | |
341 GDHandle deviceHdl; | |
12414 | 342 OSErr qterr; |
12296 | 343 |
344 //Get Main device info/////////////////////////////////////////////////// | |
12519
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
345 int i; |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
346 |
12296 | 347 deviceHdl = GetMainDevice(); |
348 | |
12519
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
349 for(i=0; i<device_id; i++) |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
350 { |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
351 deviceHdl = GetNextDevice(deviceHdl); |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
352 |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
353 if(deviceHdl == NULL) |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
354 { |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
355 mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: Device ID %d do not exist, falling back to main device.\n", device_id); |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
356 deviceHdl = GetMainDevice(); |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
357 break; |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
358 } |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
359 } |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
360 |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
361 deviceRect = (*deviceHdl)->gdRect; |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
362 device_width = deviceRect.right-deviceRect.left; |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
363 device_height = deviceRect.bottom-deviceRect.top; |
12296 | 364 |
365 //misc mplayer setup///////////////////////////////////////////////////// | |
12487 | 366 SetRect(&imgRect, 0, 0, width, height); |
12414 | 367 switch (image_format) |
368 { | |
369 case IMGFMT_RGB32: | |
12432 | 370 image_depth = 32; |
12414 | 371 break; |
372 case IMGFMT_YV12: | |
373 case IMGFMT_IYUV: | |
374 case IMGFMT_I420: | |
375 case IMGFMT_UYVY: | |
376 case IMGFMT_YUY2: | |
377 image_depth = 16; | |
378 break; | |
379 } | |
12487 | 380 image_size = ((imgRect.right*imgRect.bottom*image_depth)+7)/8; |
12296 | 381 |
382 vo_fs = flags & VOFLAG_FULLSCREEN; | |
383 | |
384 //get movie aspect | |
385 aspect_save_orig(width,height); | |
386 aspect_save_prescale(d_width,d_height); | |
387 aspect_save_screenres(device_width, device_height); | |
388 | |
389 aspect(&d_width,&d_height,A_NOZOOM); | |
390 | |
391 //Create player window////////////////////////////////////////////////// | |
392 windowAttrs = kWindowStandardDocumentAttributes | |
393 | kWindowStandardHandlerAttribute | |
394 | kWindowLiveResizeAttribute; | |
12425 | 395 |
12432 | 396 windowAttrs &= (~kWindowResizableAttribute); |
12296 | 397 |
12487 | 398 if (theWindow == NULL) |
399 { | |
400 quartz_CreateWindow(d_width, d_height, windowAttrs); | |
401 | |
402 if (theWindow == NULL) | |
403 { | |
404 mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: Couldn't create window !!!!!\n"); | |
405 return -1; | |
406 } | |
407 } | |
408 else | |
409 { | |
410 HideWindow(theWindow); | |
411 ChangeWindowAttributes(theWindow, ~windowAttrs, windowAttrs); | |
412 SetRect(&winRect, 0, 0, d_width, d_height); | |
413 SetRect(&oldWinRect, 0, 0, d_width, d_height); | |
414 SizeWindow (theWindow, d_width, d_height, 1); | |
415 } | |
12519
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
416 |
12623 | 417 SetPort(GetWindowPort(theWindow)); |
12433 | 418 |
12432 | 419 switch (image_format) |
420 { | |
421 case IMGFMT_YV12: | |
422 case IMGFMT_IYUV: | |
423 case IMGFMT_I420: | |
424 case IMGFMT_UYVY: | |
425 case IMGFMT_YUY2: | |
12424 | 426 { |
12623 | 427 get_image_done = 0; |
428 | |
429 if (!EnterMoviesDone) | |
430 { | |
431 qterr = EnterMovies(); | |
432 EnterMoviesDone = 1; | |
433 } | |
434 else | |
435 qterr = 0; | |
436 | |
437 if (qterr) | |
438 { | |
439 mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: EnterMovies (%d)\n", qterr); | |
440 return -1; | |
441 } | |
442 | |
443 | |
444 SetIdentityMatrix(&matrix); | |
445 | |
446 if ((d_width != width) || (d_height != height)) | |
447 { | |
448 ScaleMatrix(&matrix, FixDiv(Long2Fix(d_width),Long2Fix(width)), FixDiv(Long2Fix(d_height),Long2Fix(height)), 0, 0); | |
449 } | |
450 | |
12432 | 451 yuv_qt_stuff.desc = (ImageDescriptionHandle)NewHandleClear( sizeof(ImageDescription) ); |
12424 | 452 |
12432 | 453 yuv_qt_stuff.extension_colr = NewHandleClear(sizeof(NCLCColorInfoImageDescriptionExtension)); |
454 ((NCLCColorInfoImageDescriptionExtension*)(*yuv_qt_stuff.extension_colr))->colorParamType = kVideoColorInfoImageDescriptionExtensionType; | |
455 ((NCLCColorInfoImageDescriptionExtension*)(*yuv_qt_stuff.extension_colr))->primaries = 2; | |
456 ((NCLCColorInfoImageDescriptionExtension*)(*yuv_qt_stuff.extension_colr))->transferFunction = 2; | |
457 ((NCLCColorInfoImageDescriptionExtension*)(*yuv_qt_stuff.extension_colr))->matrix = 2; | |
458 | |
459 yuv_qt_stuff.extension_fiel = NewHandleClear(sizeof(FieldInfoImageDescriptionExtension)); | |
460 ((FieldInfoImageDescriptionExtension*)(*yuv_qt_stuff.extension_fiel))->fieldCount = 1; | |
461 ((FieldInfoImageDescriptionExtension*)(*yuv_qt_stuff.extension_fiel))->fieldOrderings = 0; | |
12424 | 462 |
12432 | 463 yuv_qt_stuff.extension_clap = NewHandleClear(sizeof(CleanApertureImageDescriptionExtension)); |
12487 | 464 ((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->cleanApertureWidthN = imgRect.right; |
12432 | 465 ((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->cleanApertureWidthD = 1; |
12487 | 466 ((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->cleanApertureHeightN = imgRect.bottom; |
12432 | 467 ((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->cleanApertureHeightD = 1; |
468 ((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->horizOffN = 0; | |
469 ((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->horizOffD = 1; | |
470 ((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->vertOffN = 0; | |
471 ((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->vertOffD = 1; | |
472 | |
473 yuv_qt_stuff.extension_pasp = NewHandleClear(sizeof(PixelAspectRatioImageDescriptionExtension)); | |
474 ((PixelAspectRatioImageDescriptionExtension*)(*yuv_qt_stuff.extension_pasp))->hSpacing = 1; | |
475 ((PixelAspectRatioImageDescriptionExtension*)(*yuv_qt_stuff.extension_pasp))->vSpacing = 1; | |
476 | |
477 (*yuv_qt_stuff.desc)->idSize = sizeof(ImageDescription); | |
478 (*yuv_qt_stuff.desc)->cType = image_qtcodec; | |
479 (*yuv_qt_stuff.desc)->version = 2; | |
480 (*yuv_qt_stuff.desc)->revisionLevel = 0; | |
481 (*yuv_qt_stuff.desc)->vendor = 'mpla'; | |
12487 | 482 (*yuv_qt_stuff.desc)->width = imgRect.right; |
483 (*yuv_qt_stuff.desc)->height = imgRect.bottom; | |
12432 | 484 (*yuv_qt_stuff.desc)->hRes = Long2Fix(72); |
485 (*yuv_qt_stuff.desc)->vRes = Long2Fix(72); | |
486 (*yuv_qt_stuff.desc)->temporalQuality = 0; | |
487 (*yuv_qt_stuff.desc)->spatialQuality = codecLosslessQuality; | |
488 (*yuv_qt_stuff.desc)->frameCount = 1; | |
489 (*yuv_qt_stuff.desc)->dataSize = 0; | |
490 (*yuv_qt_stuff.desc)->depth = 24; | |
491 (*yuv_qt_stuff.desc)->clutID = -1; | |
12424 | 492 |
12432 | 493 qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_colr, kColorInfoImageDescriptionExtension); |
494 if (qterr) | |
495 { | |
12487 | 496 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [colr] (%d)\n", qterr); |
12432 | 497 } |
498 | |
499 qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_fiel, kFieldInfoImageDescriptionExtension); | |
500 if (qterr) | |
501 { | |
12487 | 502 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [fiel] (%d)\n", qterr); |
12432 | 503 } |
504 | |
505 qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_clap, kCleanApertureImageDescriptionExtension); | |
506 if (qterr) | |
507 { | |
12487 | 508 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [clap] (%d)\n", qterr); |
12432 | 509 } |
510 | |
511 qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_pasp, kCleanApertureImageDescriptionExtension); | |
512 if (qterr) | |
513 { | |
12487 | 514 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [pasp] (%d)\n", qterr); |
12432 | 515 } |
12487 | 516 if (P != NULL) { // second or subsequent movie |
517 free(P); | |
518 } | |
12432 | 519 P = calloc(sizeof(PlanarPixmapInfoYUV420) + image_size, 1); |
520 switch (image_format) | |
521 { | |
522 case IMGFMT_YV12: | |
523 case IMGFMT_IYUV: | |
524 case IMGFMT_I420: | |
525 P->componentInfoY.offset = sizeof(PlanarPixmapInfoYUV420); | |
526 P->componentInfoCb.offset = P->componentInfoY.offset + image_size / 2; | |
527 P->componentInfoCr.offset = P->componentInfoCb.offset + image_size / 4; | |
12487 | 528 P->componentInfoY.rowBytes = imgRect.right; |
529 P->componentInfoCb.rowBytes = imgRect.right / 2; | |
530 P->componentInfoCr.rowBytes = imgRect.right / 2; | |
12432 | 531 image_buffer_size = image_size + sizeof(PlanarPixmapInfoYUV420); |
532 break; | |
533 case IMGFMT_UYVY: | |
534 case IMGFMT_YUY2: | |
535 image_buffer_size = image_size; | |
536 break; | |
537 } | |
12414 | 538 |
12432 | 539 qterr = DecompressSequenceBeginS(&seqId, |
12414 | 540 yuv_qt_stuff.desc, |
12432 | 541 (char *)P, |
12414 | 542 image_buffer_size, |
12623 | 543 GetWindowPort(theWindow), |
12432 | 544 NULL, |
545 NULL, | |
12414 | 546 ((d_width != width) || (d_height != height)) ? |
12432 | 547 &matrix : NULL, |
12414 | 548 srcCopy, |
12432 | 549 NULL, |
550 0, | |
12414 | 551 codecLosslessQuality, |
552 bestSpeedCodec); | |
12432 | 553 |
554 if (qterr) | |
555 { | |
556 mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: DecompressSequenceBeginS (%d)\n", qterr); | |
12487 | 557 return -1; |
12432 | 558 } |
12424 | 559 } |
12432 | 560 break; |
12414 | 561 } |
562 | |
12424 | 563 //Show window |
564 RepositionWindow(theWindow, NULL, kWindowCascadeOnMainScreen); | |
12296 | 565 ShowWindow (theWindow); |
566 | |
567 if(vo_fs) | |
568 window_fullscreen(); | |
569 | |
570 if(vo_ontop) | |
571 window_ontop(); | |
572 | |
573 return 0; | |
12120 | 574 } |
575 | |
12296 | 576 static void check_events(void) |
12120 | 577 { |
12296 | 578 EventRef theEvent; |
579 EventTargetRef theTarget; | |
580 OSStatus theErr; | |
581 | |
582 //Get event | |
583 theTarget = GetEventDispatcherTarget(); | |
584 theErr = ReceiveNextEvent(0, 0, kEventDurationNoWait,true, &theEvent); | |
585 if(theErr == noErr && theEvent != NULL) | |
586 { | |
587 SendEventToEventTarget (theEvent, theTarget); | |
588 ReleaseEvent(theEvent); | |
589 } | |
12120 | 590 |
12296 | 591 //update activity every 30 seconds to prevent |
592 //screensaver from starting up. | |
593 DateTimeRec d; | |
594 unsigned long curTime; | |
595 static unsigned long lastTime = 0; | |
596 | |
597 GetTime(&d); | |
598 DateToSeconds( &d, &curTime); | |
599 | |
600 if( ( (curTime - lastTime) >= 30) || (lastTime == 0)) | |
601 { | |
602 UpdateSystemActivity(UsrActivity); | |
603 lastTime = curTime; | |
604 } | |
605 } | |
12120 | 606 |
12296 | 607 static void draw_osd(void) |
608 { | |
12487 | 609 vo_draw_text(imgRect.right,imgRect.bottom,draw_alpha); |
12296 | 610 } |
12120 | 611 |
12296 | 612 static void flip_page(void) |
613 { | |
12432 | 614 switch (image_format) |
615 { | |
12433 | 616 case IMGFMT_YV12: |
617 case IMGFMT_IYUV: | |
618 case IMGFMT_I420: | |
619 case IMGFMT_UYVY: | |
620 case IMGFMT_YUY2: | |
621 if (EnterMoviesDone) | |
622 { | |
623 OSErr qterr; | |
624 CodecFlags flags = 0; | |
625 qterr = DecompressSequenceFrameWhen(seqId, | |
626 (char *)P, | |
627 image_buffer_size, | |
628 0, //codecFlagUseImageBuffer, | |
629 &flags, | |
630 NULL, | |
631 NULL); | |
632 if (qterr) | |
633 { | |
12487 | 634 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: DecompressSequenceFrameWhen in flip_page (%d) flags:0x%08x\n", qterr, flags); |
12433 | 635 } |
636 } | |
637 break; | |
638 } | |
12296 | 639 } |
640 | |
641 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) | |
642 { | |
12433 | 643 switch (image_format) |
644 { | |
12487 | 645 case IMGFMT_YV12: |
646 case IMGFMT_I420: | |
647 memcpy_pic(((char*)P) + P->componentInfoY.offset + x + imgRect.right * y, src[0], w, h, imgRect.right, stride[0]); | |
648 x=x/2;y=y/2;w=w/2;h=h/2; | |
649 | |
650 memcpy_pic(((char*)P) + P->componentInfoCb.offset + x + imgRect.right / 2 * y, src[1], w, h, imgRect.right / 2, stride[1]); | |
651 memcpy_pic(((char*)P) + P->componentInfoCr.offset + x + imgRect.right / 2 * y, src[2], w, h, imgRect.right / 2, stride[2]); | |
652 return 0; | |
653 | |
654 case IMGFMT_IYUV: | |
655 memcpy_pic(((char*)P) + P->componentInfoY.offset + x + imgRect.right * y, src[0], w, h, imgRect.right, stride[0]); | |
656 x=x/2;y=y/2;w=w/2;h=h/2; | |
657 | |
658 memcpy_pic(((char*)P) + P->componentInfoCr.offset + x + imgRect.right / 2 * y, src[1], w, h, imgRect.right / 2, stride[1]); | |
659 memcpy_pic(((char*)P) + P->componentInfoCb.offset + x + imgRect.right / 2 * y, src[2], w, h, imgRect.right / 2, stride[2]); | |
660 return 0; | |
12433 | 661 } |
12296 | 662 return -1; |
663 } | |
664 | |
665 static uint32_t draw_frame(uint8_t *src[]) | |
666 { | |
12433 | 667 switch (image_format) |
668 { | |
669 case IMGFMT_UYVY: | |
670 case IMGFMT_YUY2: | |
12487 | 671 memcpy_pic(((char*)P), src[0], imgRect.right * 2, imgRect.bottom, imgRect.right * 2, imgRect.right * 2); |
12433 | 672 return 0; |
673 } | |
674 return -1; | |
12296 | 675 } |
12120 | 676 |
12296 | 677 static uint32_t query_format(uint32_t format) |
678 { | |
679 image_format = format; | |
12432 | 680 image_qtcodec = 0; |
681 | |
12424 | 682 if ((format == IMGFMT_YV12) || (format == IMGFMT_IYUV) || (format == IMGFMT_I420)) |
683 { | |
684 image_qtcodec = kMpegYUV420CodecType; //kYUV420CodecType ?; | |
12487 | 685 return VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_ACCEPT_STRIDE; |
12414 | 686 } |
687 | |
12424 | 688 if (format == IMGFMT_YUY2) |
689 { | |
690 image_qtcodec = kComponentVideoUnsigned; | |
12487 | 691 return VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN; |
12414 | 692 } |
693 | |
12424 | 694 if (format == IMGFMT_UYVY) |
695 { | |
696 image_qtcodec = k422YpCbCr8CodecType; | |
12487 | 697 return VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN; |
12424 | 698 } |
12414 | 699 |
12296 | 700 return 0; |
701 } | |
12120 | 702 |
12296 | 703 static void uninit(void) |
704 { | |
12432 | 705 OSErr qterr; |
12424 | 706 |
12432 | 707 if (EnterMoviesDone) |
708 { | |
709 qterr = CDSequenceEnd(seqId); | |
710 if (qterr) | |
711 { | |
12487 | 712 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: CDSequenceEnd (%d)\n", qterr); |
12424 | 713 } |
12414 | 714 } |
12432 | 715 |
12296 | 716 ShowMenuBar(); |
717 } | |
12120 | 718 |
12296 | 719 static uint32_t preinit(const char *arg) |
720 { | |
12519
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
721 int parse_err = 0; |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
722 |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
723 if(arg) |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
724 { |
12623 | 725 char *parse_pos = (char *)&arg[0]; |
12519
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
726 while (parse_pos[0] && !parse_err) |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
727 { |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
728 if (strncmp (parse_pos, "device_id=", 10) == 0) |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
729 { |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
730 parse_pos = &parse_pos[10]; |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
731 device_id = strtol(parse_pos, &parse_pos, 0); |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
732 } |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
733 if (parse_pos[0] == ':') parse_pos = &parse_pos[1]; |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
734 else if (parse_pos[0]) parse_err = 1; |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
735 } |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
736 } |
12785
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
737 |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
738 //this chunk of code is heavily based off SDL_macosx.m from SDL |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
739 //it uses an Apple private function to request foreground operation |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
740 |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
741 void CPSEnableForegroundOperation(ProcessSerialNumber* psn); |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
742 ProcessSerialNumber myProc, frProc; |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
743 Boolean sameProc; |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
744 |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
745 if (GetFrontProcess(&frProc) == noErr) |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
746 { |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
747 if (GetCurrentProcess(&myProc) == noErr) |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
748 { |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
749 if (SameProcess(&frProc, &myProc, &sameProc) == noErr && !sameProc) |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
750 { |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
751 CPSEnableForegroundOperation(&myProc); |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
752 } |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
753 SetFrontProcess(&myProc); |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
754 } |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
755 } |
33f58bfc8a1b
make mplayer capable of being in the foreground by Dan Christiansen
nplourde
parents:
12624
diff
changeset
|
756 |
12296 | 757 return 0; |
12120 | 758 } |
759 | |
12424 | 760 static uint32_t draw_yuv_image(mp_image_t *mpi) |
761 { | |
762 // ATM we're only called for planar IMGFMT | |
763 // drawing is done directly in P | |
764 // and displaying is in flip_page. | |
12487 | 765 return get_image_done ? VO_TRUE : VO_FALSE; |
12414 | 766 } |
767 | |
12424 | 768 static uint32_t get_yuv_image(mp_image_t *mpi) |
769 { | |
770 if(mpi->type!=MP_IMGTYPE_EXPORT) return VO_FALSE; | |
12414 | 771 |
12424 | 772 if(mpi->imgfmt!=image_format) return VO_FALSE; |
12414 | 773 |
12424 | 774 if(mpi->flags&MP_IMGFLAG_PLANAR) |
775 { | |
776 if (mpi->num_planes != 3) | |
777 { | |
778 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: only 3 planes allowed in get_yuv_image for planar (%d) \n", mpi->num_planes); | |
779 return VO_FALSE; | |
780 } | |
12414 | 781 |
12424 | 782 mpi->planes[0]=((char*)P) + P->componentInfoY.offset; |
12487 | 783 mpi->stride[0]=imgRect.right; |
784 mpi->width=imgRect.right; | |
12414 | 785 |
12424 | 786 if(mpi->flags&MP_IMGFLAG_SWAPPED) |
787 { | |
788 // I420 | |
789 mpi->planes[1]=((char*)P) + P->componentInfoCb.offset; | |
790 mpi->planes[2]=((char*)P) + P->componentInfoCr.offset; | |
12487 | 791 mpi->stride[1]=imgRect.right/2; |
792 mpi->stride[2]=imgRect.right/2; | |
12424 | 793 } |
794 else | |
795 { | |
796 // YV12 | |
797 mpi->planes[1]=((char*)P) + P->componentInfoCr.offset; | |
798 mpi->planes[2]=((char*)P) + P->componentInfoCb.offset; | |
12487 | 799 mpi->stride[1]=imgRect.right/2; |
800 mpi->stride[2]=imgRect.right/2; | |
12424 | 801 } |
802 | |
803 mpi->flags|=MP_IMGFLAG_DIRECT; | |
12487 | 804 get_image_done = 1; |
12424 | 805 return VO_TRUE; |
806 } | |
807 else | |
12433 | 808 { |
809 // doesn't work yet | |
12424 | 810 if (mpi->num_planes != 1) |
811 { | |
812 mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: only 1 plane allowed in get_yuv_image for packed (%d) \n", mpi->num_planes); | |
813 return VO_FALSE; | |
814 } | |
12414 | 815 |
12424 | 816 mpi->planes[0] = (char*)P; |
12487 | 817 mpi->stride[0] = imgRect.right * 2; |
818 mpi->width=imgRect.right; | |
12424 | 819 mpi->flags|=MP_IMGFLAG_DIRECT; |
12487 | 820 get_image_done = 1; |
12424 | 821 return VO_TRUE; |
822 } | |
823 return VO_FALSE; | |
12414 | 824 } |
825 | |
12296 | 826 static uint32_t control(uint32_t request, void *data, ...) |
12120 | 827 { |
12424 | 828 switch (request) |
829 { | |
830 case VOCTRL_PAUSE: return (int_pause=1); | |
831 case VOCTRL_RESUME: return (int_pause=0); | |
12460 | 832 case VOCTRL_FULLSCREEN: vo_fs = (!(vo_fs)); window_fullscreen(); return VO_TRUE; |
833 case VOCTRL_ONTOP: vo_ontop = (!(vo_ontop)); window_ontop(); return VO_TRUE; | |
12424 | 834 case VOCTRL_QUERY_FORMAT: return query_format(*((uint32_t*)data)); |
835 case VOCTRL_GET_IMAGE: | |
836 switch (image_format) | |
837 { | |
838 case IMGFMT_YV12: | |
839 case IMGFMT_IYUV: | |
840 case IMGFMT_I420: | |
12487 | 841 case IMGFMT_UYVY: |
842 case IMGFMT_YUY2: | |
12424 | 843 return get_yuv_image(data); |
844 break; | |
12487 | 845 default: |
846 break; | |
12424 | 847 } |
848 case VOCTRL_DRAW_IMAGE: | |
849 switch (image_format) | |
850 { | |
851 case IMGFMT_YV12: | |
852 case IMGFMT_IYUV: | |
853 case IMGFMT_I420: | |
12487 | 854 case IMGFMT_UYVY: |
855 case IMGFMT_YUY2: | |
12424 | 856 return draw_yuv_image(data); |
857 break; | |
12487 | 858 default: |
859 break; | |
12424 | 860 } |
861 } | |
862 return VO_NOTIMPL; | |
12120 | 863 } |
864 | |
12296 | 865 void window_resized() |
12120 | 866 { |
12296 | 867 float aspectX; |
868 float aspectY; | |
869 | |
870 int padding; | |
871 | |
872 uint32_t d_width; | |
873 uint32_t d_height; | |
874 | |
12623 | 875 GetPortBounds( GetWindowPort(theWindow), &winRect ); |
12120 | 876 |
12296 | 877 aspect( &d_width, &d_height, A_NOZOOM); |
878 | |
879 aspectX = (float)((float)winRect.right/(float)d_width); | |
880 aspectY = (float)((float)winRect.bottom/(float)d_height); | |
881 | |
882 if((d_height*aspectX)>winRect.bottom) | |
883 { | |
884 padding = (winRect.right - d_width*aspectY)/2; | |
885 SetRect(&dstRect, padding, 0, d_width*aspectY+padding, d_height*aspectY); | |
886 } | |
887 else | |
888 { | |
889 padding = (winRect.bottom - d_height*aspectX)/2; | |
890 SetRect(&dstRect, 0, padding, (d_width*aspectX), d_height*aspectX+padding); | |
891 } | |
12120 | 892 |
12519
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
893 //Clear Background |
12623 | 894 SetGWorld( GetWindowPort(theWindow), NULL ); |
12519
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
895 RGBColor blackC = { 0x0000, 0x0000, 0x0000 }; |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
896 RGBForeColor( &blackC ); |
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
897 PaintRect( &winRect ); |
12414 | 898 |
12487 | 899 long scale_X = FixDiv(Long2Fix(dstRect.right - dstRect.left),Long2Fix(imgRect.right)); |
900 long scale_Y = FixDiv(Long2Fix(dstRect.bottom - dstRect.top),Long2Fix(imgRect.bottom)); | |
12414 | 901 |
12432 | 902 SetIdentityMatrix(&matrix); |
12487 | 903 if (((dstRect.right - dstRect.left) != imgRect.right) || ((dstRect.bottom - dstRect.right) != imgRect.bottom)) |
12432 | 904 { |
905 ScaleMatrix(&matrix, scale_X, scale_Y, 0, 0); | |
12414 | 906 |
12432 | 907 if (padding > 0) |
908 { | |
909 TranslateMatrix(&matrix, Long2Fix(dstRect.left), Long2Fix(dstRect.top)); | |
910 } | |
911 } | |
12424 | 912 |
12432 | 913 SetDSequenceMatrix(seqId, &matrix); |
12120 | 914 } |
915 | |
12296 | 916 void window_ontop() |
12460 | 917 { |
12826
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
918 //Cycle between level |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
919 winLevel++; |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
920 if(winLevel>2) |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
921 winLevel = 0; |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
922 |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
923 //hide menu bar and mouse cursor if in fullscreen and quiting wallpaper mode |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
924 if(vo_fs) |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
925 { |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
926 if(winLevel != 0) |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
927 { |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
928 HideMenuBar(); |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
929 HideCursor(); |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
930 } |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
931 else |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
932 { |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
933 ShowMenuBar(); |
12830 | 934 ShowCursor(); |
12826
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
935 } |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
936 } |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
937 |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
938 SetWindowGroupLevel(winGroup, CGWindowLevelForKey(levelList[winLevel])); |
12120 | 939 } |
940 | |
12296 | 941 void window_fullscreen() |
12120 | 942 { |
12296 | 943 //go fullscreen |
12432 | 944 if(vo_fs) |
12296 | 945 { |
12826
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
946 if(winLevel != 0) |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
947 { |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
948 HideMenuBar(); |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
949 HideCursor(); |
fb55f94f3001
Add Window Level Key, Can switch mode with T key
nplourde
parents:
12785
diff
changeset
|
950 } |
12120 | 951 |
12296 | 952 //save old window size |
12487 | 953 if (!vo_quartz_fs) |
954 GetWindowPortBounds(theWindow, &oldWinRect); | |
12296 | 955 |
956 //go fullscreen | |
12432 | 957 //ChangeWindowAttributes(theWindow, 0, kWindowResizableAttribute); |
12425 | 958 |
12519
12a87d539f6d
choose fullscreen device with suboption device_id=#
nplourde
parents:
12517
diff
changeset
|
959 MoveWindow (theWindow, deviceRect.left, deviceRect.top, 1); |
12296 | 960 SizeWindow(theWindow, device_width, device_height,1); |
12487 | 961 |
962 vo_quartz_fs = 1; | |
12296 | 963 } |
964 else //go back to windowed mode | |
965 { | |
966 ShowMenuBar(); | |
12120 | 967 |
12296 | 968 //show mouse cursor |
969 ShowCursor(); | |
970 | |
971 //revert window to previous setting | |
12432 | 972 //ChangeWindowAttributes(theWindow, kWindowResizableAttribute, 0); |
12425 | 973 |
12487 | 974 SizeWindow(theWindow, oldWinRect.right, oldWinRect.bottom,1); |
12296 | 975 RepositionWindow(theWindow, NULL, kWindowCascadeOnMainScreen); |
12487 | 976 |
977 vo_quartz_fs = 0; | |
12296 | 978 } |
979 | |
980 window_resized(); | |
12120 | 981 } |