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