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