2 \author Nicolas Plourde <nicolasplourde@gmail.com>
4 Copyright (c) Nicolas Plourde - April 2004
6 YUV support Copyright (C) 2004 Romain Dolbeau <romain@dolbeau.org>
8 \brief MPlayer Mac OSX Quartz video out module.
10 \todo: -screen overlay output
11 -fit osd in black bar when available
20 #include <Carbon/Carbon.h>
21 #include <QuickTime/QuickTime.h>
25 #include "fastmemcpy.h"
26 #include "video_out.h"
27 #include "video_out_internal.h"
35 #include "input/input.h"
36 #include "input/mouse.h"
38 #include "vo_quartz.h"
40 static const vo_info_t info
=
44 "Nicolas Plourde <nicolasplourde@hotmail.com>, Romain Dolbeau <romain@dolbeau.org>",
48 const LIBVO_EXTERN(quartz
)
50 static uint32_t image_depth
;
51 static uint32_t image_format
;
52 static uint32_t image_size
;
53 static uint32_t image_buffer_size
;
54 static char *image_data
;
56 static ImageSequence seqId
;
57 static CodecType image_qtcodec
;
58 static PlanarPixmapInfoYUV420
*P
= NULL
;
61 ImageDescriptionHandle desc
;
62 Handle extension_colr
;
63 Handle extension_fiel
;
64 Handle extension_clap
;
65 Handle extension_pasp
;
67 static MatrixRecord matrix
;
68 static int EnterMoviesDone
= 0;
69 static int get_image_done
= 0;
71 static int vo_quartz_fs
; // we are in fullscreen
72 extern float monitor_aspect
;
73 extern float movie_aspect
;
74 static float old_movie_aspect
;
76 static int winLevel
= 1;
79 kCGDesktopWindowLevelKey
,
80 kCGNormalWindowLevelKey
,
81 kCGScreenSaverWindowLevelKey
84 static int int_pause
= 0;
85 static float winAlpha
= 1;
86 static int mouseHide
= FALSE
;
88 static int device_id
= 0;
90 static short fs_res_x
= 0;
91 static short fs_res_y
= 0;
93 static WindowRef theWindow
= NULL
;
94 static WindowGroupRef winGroup
= NULL
;
96 static CGDirectDisplayID displayId
= 0;
97 static CFDictionaryRef originalMode
= NULL
;
99 static CGDataProviderRef dataProviderRef
= NULL
;
100 static CGImageRef image
= NULL
;
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
106 static CGRect displayRect
; // size of the display device
107 static Rect oldWinBounds
;
109 static MenuRef windMenu
;
110 static MenuRef movMenu
;
111 static MenuRef aspectMenu
;
113 static int lastScreensaverUpdate
= 0;
114 static int lastMouseHide
= 0;
120 kNormalScreenCmd
= 3,
121 kDoubleScreenCmd
= 4,
130 #include "osdep/keycodes.h"
132 //PROTOTYPE/////////////////////////////////////////////////////////////////
133 static OSStatus
KeyEventHandler(EventHandlerCallRef nextHandler
, EventRef event
, void *userData
);
134 static OSStatus
MouseEventHandler(EventHandlerCallRef nextHandler
, EventRef event
, void *userData
);
135 static OSStatus
WindowEventHandler(EventHandlerCallRef nextHandler
, EventRef event
, void *userData
);
136 void window_resized();
138 void window_fullscreen();
139 void window_panscan();
141 static inline int convert_key(UInt32 key
, UInt32 charcode
)
146 case QZ_RETURN
: return KEY_ENTER
;
147 case QZ_ESCAPE
: return KEY_ESC
;
148 case QZ_BACKSPACE
: return KEY_BACKSPACE
;
149 case QZ_LALT
: return KEY_BACKSPACE
;
150 case QZ_LCTRL
: return KEY_BACKSPACE
;
151 case QZ_LSHIFT
: return KEY_BACKSPACE
;
152 case QZ_F1
: return KEY_F
+ 1;
153 case QZ_F2
: return KEY_F
+ 2;
154 case QZ_F3
: return KEY_F
+ 3;
155 case QZ_F4
: return KEY_F
+ 4;
156 case QZ_F5
: return KEY_F
+ 5;
157 case QZ_F6
: return KEY_F
+ 6;
158 case QZ_F7
: return KEY_F
+ 7;
159 case QZ_F8
: return KEY_F
+ 8;
160 case QZ_F9
: return KEY_F
+ 9;
161 case QZ_F10
: return KEY_F
+ 10;
162 case QZ_F11
: return KEY_F
+ 11;
163 case QZ_F12
: return KEY_F
+ 12;
164 case QZ_INSERT
: return KEY_INSERT
;
165 case QZ_DELETE
: return KEY_DELETE
;
166 case QZ_HOME
: return KEY_HOME
;
167 case QZ_END
: return KEY_END
;
168 case QZ_KP_PLUS
: return '+';
169 case QZ_KP_MINUS
: return '-';
170 case QZ_TAB
: return KEY_TAB
;
171 case QZ_PAGEUP
: return KEY_PAGE_UP
;
172 case QZ_PAGEDOWN
: return KEY_PAGE_DOWN
;
173 case QZ_UP
: return KEY_UP
;
174 case QZ_DOWN
: return KEY_DOWN
;
175 case QZ_LEFT
: return KEY_LEFT
;
176 case QZ_RIGHT
: return KEY_RIGHT
;
177 case QZ_KP_MULTIPLY
: return '*';
178 case QZ_KP_DIVIDE
: return '/';
179 case QZ_KP_ENTER
: return KEY_KPENTER
;
180 case QZ_KP_PERIOD
: return KEY_KPDEC
;
181 case QZ_KP0
: return KEY_KP0
;
182 case QZ_KP1
: return KEY_KP1
;
183 case QZ_KP2
: return KEY_KP2
;
184 case QZ_KP3
: return KEY_KP3
;
185 case QZ_KP4
: return KEY_KP4
;
186 case QZ_KP5
: return KEY_KP5
;
187 case QZ_KP6
: return KEY_KP6
;
188 case QZ_KP7
: return KEY_KP7
;
189 case QZ_KP8
: return KEY_KP8
;
190 case QZ_KP9
: return KEY_KP9
;
191 default: return charcode
;
195 static void draw_alpha(int x0
, int y0
, int w
, int h
, unsigned char *src
, unsigned char *srca
, int stride
)
197 switch (image_format
)
200 vo_draw_alpha_rgb32(w
, h
, src
, srca
, stride
, image_data
+ 4 * (y0
* imgRect
.right
+ x0
), 4 * imgRect
.right
);
205 vo_draw_alpha_yv12(w
, h
, src
, srca
, stride
, ((char *)P
) + be2me_32(P
->componentInfoY
.offset
) + x0
+ y0
* imgRect
.right
, imgRect
.right
);
208 vo_draw_alpha_uyvy(w
, h
, src
, srca
, stride
, ((char *)P
) + (x0
+ y0
* imgRect
.right
) * 2, imgRect
.right
* 2);
211 vo_draw_alpha_yuy2(w
, h
, src
, srca
, stride
, ((char *)P
) + (x0
+ y0
* imgRect
.right
) * 2, imgRect
.right
* 2);
216 //default keyboard event handler
217 static OSStatus
KeyEventHandler(EventHandlerCallRef nextHandler
, EventRef event
, void *userData
)
219 OSStatus result
= noErr
;
220 UInt32
class = GetEventClass(event
);
221 UInt32 kind
= GetEventKind(event
);
223 result
= CallNextEventHandler(nextHandler
, event
);
225 if (class == kEventClassKeyboard
)
229 UInt32 macKeyModifiers
;
231 GetEventParameter(event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, sizeof(macCharCodes
), NULL
, &macCharCodes
);
232 GetEventParameter(event
, kEventParamKeyCode
, typeUInt32
, NULL
, sizeof(macKeyCode
), NULL
, &macKeyCode
);
233 GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, sizeof(macKeyModifiers
), NULL
, &macKeyModifiers
);
235 if (macKeyModifiers
!= 256)
237 if (kind
== kEventRawKeyRepeat
|| kind
== kEventRawKeyDown
)
239 int key
= convert_key(macKeyCode
, macCharCodes
);
242 mplayer_put_key(key
);
245 else if (macKeyModifiers
== 256)
247 switch (macCharCodes
)
249 case '[': SetWindowAlpha(theWindow
, winAlpha
-= 0.05); break;
250 case ']': SetWindowAlpha(theWindow
, winAlpha
+= 0.05); break;
254 result
= eventNotHandledErr
;
260 //default mouse event handler
261 static OSStatus
MouseEventHandler(EventHandlerCallRef nextHandler
, EventRef event
, void *userData
)
263 OSStatus result
= noErr
;
264 UInt32
class = GetEventClass(event
);
265 UInt32 kind
= GetEventKind(event
);
267 result
= CallNextEventHandler(nextHandler
, event
);
269 if (class == kEventClassMouse
)
275 GetEventParameter(event
, kEventParamMouseLocation
, typeQDPoint
, 0, sizeof(Point
), 0, &mousePos
);
276 GetEventParameter(event
, kEventParamWindowMouseLocation
, typeQDPoint
, 0, sizeof(Point
), 0, &winMousePos
);
280 case kEventMouseMoved
:
284 CGDisplayShowCursor(displayId
);
290 case kEventMouseWheelMoved
:
295 GetEventParameter(event
, kEventParamMouseWheelDelta
, typeSInt32
, 0, sizeof(int), 0, &wheel
);
297 part
= FindWindow(mousePos
, &tmpWin
);
299 if (part
== inContent
)
302 mplayer_put_key(MOUSE_BTN3
);
304 mplayer_put_key(MOUSE_BTN4
);
309 case kEventMouseDown
:
312 EventMouseButton button
;
316 GetWindowPortBounds(theWindow
, &bounds
);
317 GetEventParameter(event
, kEventParamMouseButton
, typeMouseButton
, 0, sizeof(EventMouseButton
), 0, &button
);
319 part
= FindWindow(mousePos
, &tmpWin
);
320 if (kind
== kEventMouseUp
)
322 if (part
!= inContent
)
326 case kEventMouseButtonPrimary
:
327 mplayer_put_key(MOUSE_BTN0
);
329 case kEventMouseButtonSecondary
:
330 mplayer_put_key(MOUSE_BTN2
);
332 case kEventMouseButtonTertiary
:
333 mplayer_put_key(MOUSE_BTN1
);
337 result
= eventNotHandledErr
;
342 if ((winMousePos
.h
> (bounds
.right
- 15)) && (winMousePos
.v
> (bounds
.bottom
)))
348 ResizeWindow(theWindow
, mousePos
, NULL
, &newSize
);
351 else if (part
== inMenuBar
)
353 MenuSelect(mousePos
);
356 else if (part
== inContent
)
360 case kEventMouseButtonPrimary
:
361 mplayer_put_key(MOUSE_BTN0
| MP_KEY_DOWN
);
363 case kEventMouseButtonSecondary
:
364 mplayer_put_key(MOUSE_BTN2
| MP_KEY_DOWN
);
366 case kEventMouseButtonTertiary
:
367 mplayer_put_key(MOUSE_BTN1
| MP_KEY_DOWN
);
371 result
= eventNotHandledErr
;
378 case kEventMouseDragged
:
382 result
= eventNotHandledErr
;
390 //default window event handler
391 static OSStatus
WindowEventHandler(EventHandlerCallRef nextHandler
, EventRef event
, void *userData
)
393 OSStatus result
= noErr
;
396 UInt32
class = GetEventClass(event
);
397 UInt32 kind
= GetEventKind(event
);
399 result
= CallNextEventHandler(nextHandler
, event
);
401 aspect(&d_width
, &d_height
, A_NOZOOM
);
403 if (class == kEventClassCommand
)
405 HICommand theHICommand
;
407 GetEventParameter(event
, kEventParamDirectObject
, typeHICommand
, NULL
, sizeof(HICommand
), NULL
, &theHICommand
);
409 switch (theHICommand
.commandID
)
412 mplayer_put_key(KEY_CLOSE_WIN
);
422 SizeWindow(theWindow
, (d_width
/ 2), ((d_width
/ movie_aspect
) / 2), 1);
426 case kNormalScreenCmd
:
433 SizeWindow(theWindow
, d_width
, (d_width
/ movie_aspect
), 1);
437 case kDoubleScreenCmd
:
444 SizeWindow(theWindow
, (d_width
* 2), ((d_width
/ movie_aspect
) * 2), 1);
454 vo_keepaspect
= (!(vo_keepaspect
));
455 CheckMenuItem(aspectMenu
, 1, vo_keepaspect
);
460 movie_aspect
= old_movie_aspect
;
463 SizeWindow(theWindow
, dstRect
.right
, (dstRect
.right
/ movie_aspect
), 1);
469 movie_aspect
= 4.0f
/ 3.0f
;
472 SizeWindow(theWindow
, dstRect
.right
, (dstRect
.right
/ movie_aspect
), 1);
478 movie_aspect
= 16.0f
/ 9.0f
;
481 SizeWindow(theWindow
, dstRect
.right
, (dstRect
.right
/ movie_aspect
), 1);
487 vo_panscan
= (!(vo_panscan
));
488 CheckMenuItem(aspectMenu
, 2, vo_panscan
);
494 result
= eventNotHandledErr
;
498 else if (class == kEventClassWindow
)
501 Rect rectWindow
= { 0, 0, 0, 0 };
503 GetEventParameter(event
, kEventParamDirectObject
, typeWindowRef
, NULL
, sizeof(WindowRef
), NULL
, &window
);
507 GetWindowBounds(window
, kWindowGlobalPortRgn
, &rectWindow
);
512 case kEventWindowClosed
:
514 mplayer_put_key(KEY_CLOSE_WIN
);
518 case kEventWindowZoomed
:
519 case kEventWindowBoundsChanged
:
526 result
= eventNotHandledErr
;
534 static void quartz_CreateWindow(uint32_t d_width
, uint32_t d_height
, WindowAttributes windowAttrs
)
536 CFStringRef titleKey
;
537 CFStringRef windowTitle
;
541 CFStringRef movMenuTitle
;
542 CFStringRef aspMenuTitle
;
544 const EventTypeSpec win_events
[] = {
545 {kEventClassWindow
, kEventWindowClosed
},
546 {kEventClassWindow
, kEventWindowBoundsChanged
},
547 {kEventClassCommand
, kEventCommandProcess
}
550 const EventTypeSpec key_events
[] = {
551 {kEventClassKeyboard
, kEventRawKeyDown
},
552 {kEventClassKeyboard
, kEventRawKeyRepeat
}
555 const EventTypeSpec mouse_events
[] = {
556 {kEventClassMouse
, kEventMouseMoved
},
557 {kEventClassMouse
, kEventMouseWheelMoved
},
558 {kEventClassMouse
, kEventMouseDown
},
559 {kEventClassMouse
, kEventMouseUp
},
560 {kEventClassMouse
, kEventMouseDragged
}
563 SetRect(&winRect
, 0, 0, d_width
, d_height
);
564 SetRect(&oldWinRect
, 0, 0, d_width
, d_height
);
565 SetRect(&dstRect
, 0, 0, d_width
, d_height
);
570 // Create Window Menu
571 CreateStandardWindowMenu(0, &windMenu
);
572 InsertMenu(windMenu
, 0);
575 CreateNewMenu(1004, 0, &movMenu
);
576 movMenuTitle
= CFSTR("Movie");
577 SetMenuTitleWithCFString(movMenu
, movMenuTitle
);
579 AppendMenuItemTextWithCFString(movMenu
, CFSTR("Half Size"), 0, kHalfScreenCmd
, &index
);
580 SetMenuItemCommandKey(movMenu
, index
, 0, '0');
582 AppendMenuItemTextWithCFString(movMenu
, CFSTR("Normal Size"), 0, kNormalScreenCmd
, &index
);
583 SetMenuItemCommandKey(movMenu
, index
, 0, '1');
585 AppendMenuItemTextWithCFString(movMenu
, CFSTR("Double Size"), 0, kDoubleScreenCmd
, &index
);
586 SetMenuItemCommandKey(movMenu
, index
, 0, '2');
588 AppendMenuItemTextWithCFString(movMenu
, CFSTR("Full Size"), 0, kFullScreenCmd
, &index
);
589 SetMenuItemCommandKey(movMenu
, index
, 0, 'F');
591 AppendMenuItemTextWithCFString(movMenu
, NULL
, kMenuItemAttrSeparator
, 0, &index
);
593 AppendMenuItemTextWithCFString(movMenu
, CFSTR("Aspect Ratio"), 0, 0, &index
);
595 //// Create Aspect Ratio Sub Menu
596 CreateNewMenu(0, 0, &aspectMenu
);
597 aspMenuTitle
= CFSTR("Aspect Ratio");
598 SetMenuTitleWithCFString(aspectMenu
, aspMenuTitle
);
599 SetMenuItemHierarchicalMenu(movMenu
, 6, aspectMenu
);
601 AppendMenuItemTextWithCFString(aspectMenu
, CFSTR("Keep"), 0, kKeepAspectCmd
, &index
);
602 CheckMenuItem(aspectMenu
, 1, vo_keepaspect
);
603 AppendMenuItemTextWithCFString(aspectMenu
, CFSTR("Pan-Scan"), 0, kPanScanCmd
, &index
);
604 CheckMenuItem(aspectMenu
, 2, vo_panscan
);
605 AppendMenuItemTextWithCFString(aspectMenu
, NULL
, kMenuItemAttrSeparator
, 0, &index
);
606 AppendMenuItemTextWithCFString(aspectMenu
, CFSTR("Original"), 0, kAspectOrgCmd
, &index
);
607 AppendMenuItemTextWithCFString(aspectMenu
, CFSTR("4:3"), 0, kAspectFullCmd
, &index
);
608 AppendMenuItemTextWithCFString(aspectMenu
, CFSTR("16:9"), 0, kAspectWideCmd
, &index
);
610 InsertMenu(movMenu
, GetMenuID(windMenu
)); //insert before Window menu
615 CreateNewWindow(kDocumentWindowClass
, windowAttrs
, &winRect
, &theWindow
);
617 CreateWindowGroup(0, &winGroup
);
618 SetWindowGroup(theWindow
, winGroup
);
621 titleKey
= CFSTR("MPlayer - The Movie Player");
622 windowTitle
= CFCopyLocalizedString(titleKey
, NULL
);
623 result
= SetWindowTitleWithCFString(theWindow
, windowTitle
);
625 CFRelease(windowTitle
);
627 // Install event handler
628 InstallApplicationEventHandler(NewEventHandlerUPP(KeyEventHandler
), GetEventTypeCount(key_events
), key_events
, NULL
, NULL
);
629 InstallApplicationEventHandler(NewEventHandlerUPP(MouseEventHandler
), GetEventTypeCount(mouse_events
), mouse_events
, NULL
, NULL
);
630 InstallWindowEventHandler(theWindow
, NewEventHandlerUPP(WindowEventHandler
), GetEventTypeCount(win_events
), win_events
, theWindow
, NULL
);
633 static int config(uint32_t width
, uint32_t height
, uint32_t d_width
, uint32_t d_height
, uint32_t flags
, char *title
, uint32_t format
)
635 WindowAttributes windowAttrs
;
638 CGDisplayCount displayCount
;
639 CGDirectDisplayID
*displays
;
641 // Get Main device info///////////////////////////////////////////////////
643 // Display IDs might not be consecutive, get the list of all devices up to # device_id
644 displayCount
= device_id
+ 1;
645 displays
= malloc(sizeof(CGDirectDisplayID
) * displayCount
);
646 if (kCGErrorSuccess
!= CGGetActiveDisplayList(displayCount
, displays
, &displayCount
) || displayCount
< device_id
+ 1) {
647 mp_msg(MSGT_VO
, MSGL_FATAL
, "Quartz error: Device ID %d do not exist, falling back to main device.\n", device_id
);
648 displayId
= kCGDirectMainDisplay
;
653 displayId
= displays
[device_id
];
657 displayRect
= CGDisplayBounds(displayId
);
659 monitor_aspect
= (float)displayRect
.size
.width
/ (float)displayRect
.size
.height
;
661 // misc mplayer setup/////////////////////////////////////////////////////
662 SetRect(&imgRect
, 0, 0, width
, height
);
663 switch (image_format
)
676 image_size
= ((imgRect
.right
* imgRect
.bottom
* image_depth
) + 7) / 8;
678 vo_fs
= flags
& VOFLAG_FULLSCREEN
;
682 aspect_save_orig(width
, height
);
683 aspect_save_prescale(d_width
, d_height
);
684 aspect_save_screenres(displayRect
.size
.width
, displayRect
.size
.height
);
686 aspect(&d_width
, &d_height
, A_NOZOOM
);
688 movie_aspect
= (float)d_width
/ (float)d_height
;
689 old_movie_aspect
= movie_aspect
;
694 image_data
= malloc(image_size
);
696 // Create player window//////////////////////////////////////////////////
697 windowAttrs
= kWindowStandardDocumentAttributes
698 | kWindowStandardHandlerAttribute
699 | kWindowLiveResizeAttribute
;
701 windowAttrs
&= (~kWindowResizableAttribute
);
703 if (theWindow
== NULL
)
705 CGContextRef context
;
707 quartz_CreateWindow(d_width
, d_height
, windowAttrs
);
709 if (theWindow
== NULL
)
711 mp_msg(MSGT_VO
, MSGL_FATAL
, "Quartz error: Couldn't create window !!!!!\n");
714 tmpBounds
= CGRectMake(0, 0, winRect
.right
, winRect
.bottom
);
715 QDBeginCGContext(GetWindowPort(theWindow
), &context
);
716 CGContextFillRect(context
, tmpBounds
);
717 QDEndCGContext(GetWindowPort(theWindow
), &context
);
721 HideWindow(theWindow
);
722 ChangeWindowAttributes(theWindow
, ~windowAttrs
, windowAttrs
);
723 SetRect(&winRect
, 0, 0, d_width
, d_height
);
724 SetRect(&oldWinRect
, 0, 0, d_width
, d_height
);
725 SizeWindow(theWindow
, d_width
, d_height
, 1);
728 switch (image_format
)
732 CGContextRef context
;
734 QDBeginCGContext(GetWindowPort(theWindow
), &context
);
736 dataProviderRef
= CGDataProviderCreateWithData(0, image_data
, imgRect
.right
* imgRect
.bottom
* 4, 0);
738 image
= CGImageCreate(imgRect
.right
,
742 ((imgRect
.right
* 32) + 7) / 8,
743 CGColorSpaceCreateDeviceRGB(),
744 kCGImageAlphaNoneSkipFirst
,
745 dataProviderRef
, 0, 1, kCGRenderingIntentDefault
);
747 QDEndCGContext(GetWindowPort(theWindow
), &context
);
759 if (!EnterMoviesDone
)
761 qterr
= EnterMovies();
769 mp_msg(MSGT_VO
, MSGL_FATAL
, "Quartz error: EnterMovies (%d)\n", qterr
);
774 SetIdentityMatrix(&matrix
);
776 if ((d_width
!= width
) || (d_height
!= height
))
778 ScaleMatrix(&matrix
, FixDiv(Long2Fix(d_width
), Long2Fix(width
)), FixDiv(Long2Fix(d_height
), Long2Fix(height
)), 0, 0);
781 yuv_qt_stuff
.desc
= (ImageDescriptionHandle
) NewHandleClear(sizeof(ImageDescription
));
783 yuv_qt_stuff
.extension_colr
= NewHandleClear(sizeof(NCLCColorInfoImageDescriptionExtension
));
784 ((NCLCColorInfoImageDescriptionExtension
*) (*yuv_qt_stuff
.extension_colr
))->colorParamType
= kVideoColorInfoImageDescriptionExtensionType
;
785 ((NCLCColorInfoImageDescriptionExtension
*) (*yuv_qt_stuff
.extension_colr
))->primaries
= 2;
786 ((NCLCColorInfoImageDescriptionExtension
*) (*yuv_qt_stuff
.extension_colr
))->transferFunction
= 2;
787 ((NCLCColorInfoImageDescriptionExtension
*) (*yuv_qt_stuff
.extension_colr
))->matrix
= 2;
789 yuv_qt_stuff
.extension_fiel
= NewHandleClear(sizeof(FieldInfoImageDescriptionExtension
));
790 ((FieldInfoImageDescriptionExtension
*) (*yuv_qt_stuff
.extension_fiel
))->fieldCount
= 1;
791 ((FieldInfoImageDescriptionExtension
*) (*yuv_qt_stuff
.extension_fiel
))->fieldOrderings
= 0;
793 yuv_qt_stuff
.extension_clap
= NewHandleClear(sizeof(CleanApertureImageDescriptionExtension
));
794 ((CleanApertureImageDescriptionExtension
*) (*yuv_qt_stuff
.extension_clap
))->cleanApertureWidthN
= imgRect
.right
;
795 ((CleanApertureImageDescriptionExtension
*) (*yuv_qt_stuff
.extension_clap
))->cleanApertureWidthD
= 1;
796 ((CleanApertureImageDescriptionExtension
*) (*yuv_qt_stuff
.extension_clap
))->cleanApertureHeightN
= imgRect
.bottom
;
797 ((CleanApertureImageDescriptionExtension
*) (*yuv_qt_stuff
.extension_clap
))->cleanApertureHeightD
= 1;
798 ((CleanApertureImageDescriptionExtension
*) (*yuv_qt_stuff
.extension_clap
))->horizOffN
= 0;
799 ((CleanApertureImageDescriptionExtension
*) (*yuv_qt_stuff
.extension_clap
))->horizOffD
= 1;
800 ((CleanApertureImageDescriptionExtension
*) (*yuv_qt_stuff
.extension_clap
))->vertOffN
= 0;
801 ((CleanApertureImageDescriptionExtension
*) (*yuv_qt_stuff
.extension_clap
))->vertOffD
= 1;
803 yuv_qt_stuff
.extension_pasp
= NewHandleClear(sizeof(PixelAspectRatioImageDescriptionExtension
));
804 ((PixelAspectRatioImageDescriptionExtension
*) (*yuv_qt_stuff
.extension_pasp
))->hSpacing
= 1;
805 ((PixelAspectRatioImageDescriptionExtension
*) (*yuv_qt_stuff
.extension_pasp
))->vSpacing
= 1;
807 (*yuv_qt_stuff
.desc
)->idSize
= sizeof(ImageDescription
);
808 (*yuv_qt_stuff
.desc
)->cType
= image_qtcodec
;
809 (*yuv_qt_stuff
.desc
)->version
= 2;
810 (*yuv_qt_stuff
.desc
)->revisionLevel
= 0;
811 (*yuv_qt_stuff
.desc
)->vendor
= 'mpla';
812 (*yuv_qt_stuff
.desc
)->width
= imgRect
.right
;
813 (*yuv_qt_stuff
.desc
)->height
= imgRect
.bottom
;
814 (*yuv_qt_stuff
.desc
)->hRes
= Long2Fix(72);
815 (*yuv_qt_stuff
.desc
)->vRes
= Long2Fix(72);
816 (*yuv_qt_stuff
.desc
)->temporalQuality
= 0;
817 (*yuv_qt_stuff
.desc
)->spatialQuality
= codecLosslessQuality
;
818 (*yuv_qt_stuff
.desc
)->frameCount
= 1;
819 (*yuv_qt_stuff
.desc
)->dataSize
= 0;
820 (*yuv_qt_stuff
.desc
)->depth
= 24;
821 (*yuv_qt_stuff
.desc
)->clutID
= -1;
823 qterr
= AddImageDescriptionExtension(yuv_qt_stuff
.desc
, yuv_qt_stuff
.extension_colr
, kColorInfoImageDescriptionExtension
);
826 mp_msg(MSGT_VO
, MSGL_ERR
, "Quartz error: AddImageDescriptionExtension [colr] (%d)\n", qterr
);
829 qterr
= AddImageDescriptionExtension(yuv_qt_stuff
.desc
, yuv_qt_stuff
.extension_fiel
, kFieldInfoImageDescriptionExtension
);
832 mp_msg(MSGT_VO
, MSGL_ERR
, "Quartz error: AddImageDescriptionExtension [fiel] (%d)\n", qterr
);
835 qterr
= AddImageDescriptionExtension(yuv_qt_stuff
.desc
, yuv_qt_stuff
.extension_clap
, kCleanApertureImageDescriptionExtension
);
838 mp_msg(MSGT_VO
, MSGL_ERR
, "Quartz error: AddImageDescriptionExtension [clap] (%d)\n", qterr
);
841 qterr
= AddImageDescriptionExtension(yuv_qt_stuff
.desc
, yuv_qt_stuff
.extension_pasp
, kCleanApertureImageDescriptionExtension
);
844 mp_msg(MSGT_VO
, MSGL_ERR
, "Quartz error: AddImageDescriptionExtension [pasp] (%d)\n", qterr
);
846 if (P
!= NULL
) { // second or subsequent movie
849 P
= calloc(sizeof(PlanarPixmapInfoYUV420
) + image_size
, 1);
850 switch (image_format
)
855 P
->componentInfoY
.offset
= be2me_32(sizeof(PlanarPixmapInfoYUV420
));
856 P
->componentInfoCb
.offset
= be2me_32(be2me_32(P
->componentInfoY
.offset
) + image_size
/ 2);
857 P
->componentInfoCr
.offset
= be2me_32(be2me_32(P
->componentInfoCb
.offset
) + image_size
/ 4);
858 P
->componentInfoY
.rowBytes
= be2me_32(imgRect
.right
);
859 P
->componentInfoCb
.rowBytes
= be2me_32(imgRect
.right
/ 2);
860 P
->componentInfoCr
.rowBytes
= be2me_32(imgRect
.right
/ 2);
861 image_buffer_size
= image_size
+ sizeof(PlanarPixmapInfoYUV420
);
865 image_buffer_size
= image_size
;
869 qterr
= DecompressSequenceBeginS(&seqId
,
873 GetWindowPort(theWindow
),
876 ((d_width
!= width
) || (d_height
!= height
)) ?
881 codecLosslessQuality
,
886 mp_msg(MSGT_VO
, MSGL_FATAL
, "Quartz error: DecompressSequenceBeginS (%d)\n", qterr
);
894 RepositionWindow(theWindow
, NULL
, kWindowCenterOnMainScreen
);
895 ShowWindow(theWindow
);
907 SetWindowGroupLevel(winGroup
, CGWindowLevelForKey(levelList
[winLevel
]));
916 static void check_events(void)
919 EventTargetRef theTarget
;
923 theTarget
= GetEventDispatcherTarget();
924 theErr
= ReceiveNextEvent(0, 0, kEventDurationNoWait
, true, &theEvent
);
925 if (theErr
== noErr
&& theEvent
!= NULL
)
927 SendEventToEventTarget(theEvent
, theTarget
);
928 ReleaseEvent(theEvent
);
932 static void draw_osd(void)
934 vo_draw_text(imgRect
.right
, imgRect
.bottom
, draw_alpha
);
937 static void flip_page(void)
941 if (theWindow
== NULL
)
944 switch (image_format
)
948 CGContextRef context
;
950 QDBeginCGContext(GetWindowPort(theWindow
), &context
);
951 CGContextDrawImage(context
, bounds
, image
);
952 QDEndCGContext(GetWindowPort(theWindow
), &context
);
964 CodecFlags flags
= 0;
966 qterr
= DecompressSequenceFrameWhen(seqId
,
969 0, //codecFlagUseImageBuffer,
975 mp_msg(MSGT_VO
, MSGL_ERR
, "Quartz error: DecompressSequenceFrameWhen in flip_page (%d) flags:0x%08x\n", qterr
, flags
);
983 CGContextRef context
;
985 QDBeginCGContext(GetWindowPort(theWindow
), &context
);
987 CGContextBeginPath(context
);
988 CGContextSetAllowsAntialiasing(context
, false);
989 //CGContextSaveGState(context);
992 CGContextSetRGBStrokeColor(context
, 0.2, 0.2, 0.2, 0.5);
993 CGContextMoveToPoint(context
, winRect
.right
- 1, 1); CGContextAddLineToPoint(context
, winRect
.right
- 1, 1);
994 CGContextMoveToPoint(context
, winRect
.right
- 1, 5); CGContextAddLineToPoint(context
, winRect
.right
- 5, 1);
995 CGContextMoveToPoint(context
, winRect
.right
- 1, 9); CGContextAddLineToPoint(context
, winRect
.right
- 9, 1);
996 CGContextStrokePath(context
);
999 CGContextSetRGBStrokeColor(context
, 0.4, 0.4, 0.4, 0.5);
1000 CGContextMoveToPoint(context
, winRect
.right
- 1, 2); CGContextAddLineToPoint(context
, winRect
.right
- 2, 1);
1001 CGContextMoveToPoint(context
, winRect
.right
- 1, 6); CGContextAddLineToPoint(context
, winRect
.right
- 6, 1);
1002 CGContextMoveToPoint(context
, winRect
.right
- 1, 10); CGContextAddLineToPoint(context
, winRect
.right
- 10, 1);
1003 CGContextStrokePath(context
);
1006 CGContextSetRGBStrokeColor(context
, 0.6, 0.6, 0.6, 0.5);
1007 CGContextMoveToPoint(context
, winRect
.right
- 1, 3); CGContextAddLineToPoint(context
, winRect
.right
- 3, 1);
1008 CGContextMoveToPoint(context
, winRect
.right
- 1, 7); CGContextAddLineToPoint(context
, winRect
.right
- 7, 1);
1009 CGContextMoveToPoint(context
, winRect
.right
- 1, 11); CGContextAddLineToPoint(context
, winRect
.right
- 11, 1);
1010 CGContextStrokePath(context
);
1012 // CGContextRestoreGState( context );
1013 CGContextFlush(context
);
1014 QDEndCGContext(GetWindowPort(theWindow
), &context
);
1017 curTime
= TickCount() / 60;
1019 // auto hide mouse cursor (and future on-screen control?)
1020 if (vo_quartz_fs
&& !mouseHide
)
1022 if (((curTime
- lastMouseHide
) >= 5) || (lastMouseHide
== 0))
1024 CGDisplayHideCursor(displayId
);
1026 lastMouseHide
= curTime
;
1029 // update activity every 30 seconds to prevent
1030 // screensaver from starting up.
1031 if (((curTime
- lastScreensaverUpdate
) >= 30) || (lastScreensaverUpdate
== 0))
1033 UpdateSystemActivity(UsrActivity
);
1034 lastScreensaverUpdate
= curTime
;
1038 static int draw_slice(uint8_t * src
[], int stride
[], int w
, int h
, int x
, int y
)
1040 switch (image_format
)
1044 memcpy_pic(((char *)P
) + be2me_32(P
->componentInfoY
.offset
) + x
+ imgRect
.right
* y
, src
[0], w
, h
, imgRect
.right
, stride
[0]);
1045 x
=x
/2;y
=y
/2;w
=w
/2;h
=h
/2;
1047 memcpy_pic(((char *)P
) + be2me_32(P
->componentInfoCb
.offset
) + x
+ imgRect
.right
/ 2 * y
, src
[1], w
, h
, imgRect
.right
/ 2, stride
[1]);
1048 memcpy_pic(((char *)P
) + be2me_32(P
->componentInfoCr
.offset
) + x
+ imgRect
.right
/ 2 * y
, src
[2], w
, h
, imgRect
.right
/ 2, stride
[2]);
1052 memcpy_pic(((char *)P
) + be2me_32(P
->componentInfoY
.offset
) + x
+ imgRect
.right
* y
, src
[0], w
, h
, imgRect
.right
, stride
[0]);
1053 x
=x
/2;y
=y
/2;w
=w
/2;h
=h
/2;
1055 memcpy_pic(((char *)P
) + be2me_32(P
->componentInfoCr
.offset
) + x
+ imgRect
.right
/ 2 * y
, src
[1], w
, h
, imgRect
.right
/ 2, stride
[1]);
1056 memcpy_pic(((char *)P
) + be2me_32(P
->componentInfoCb
.offset
) + x
+ imgRect
.right
/ 2 * y
, src
[2], w
, h
, imgRect
.right
/ 2, stride
[2]);
1062 static int draw_frame(uint8_t * src
[])
1064 switch (image_format
)
1067 fast_memcpy(image_data
, src
[0], image_size
);
1072 memcpy_pic(((char *)P
), src
[0], imgRect
.right
* 2, imgRect
.bottom
, imgRect
.right
* 2, imgRect
.right
* 2);
1078 static int query_format(uint32_t format
)
1080 image_format
= format
;
1083 if (format
== IMGFMT_RGB32
)
1085 return VFCAP_CSP_SUPPORTED
| VFCAP_OSD
| VFCAP_HWSCALE_UP
| VFCAP_HWSCALE_DOWN
;
1088 if ((format
== IMGFMT_YV12
) || (format
== IMGFMT_IYUV
) || (format
== IMGFMT_I420
))
1090 image_qtcodec
= kMpegYUV420CodecType
; //kYUV420CodecType ?;
1091 return VFCAP_CSP_SUPPORTED
| VFCAP_OSD
| VFCAP_HWSCALE_UP
| VFCAP_HWSCALE_DOWN
| VFCAP_ACCEPT_STRIDE
;
1094 if (format
== IMGFMT_YUY2
)
1096 image_qtcodec
= kComponentVideoUnsigned
;
1097 return VFCAP_CSP_SUPPORTED
| VFCAP_OSD
| VFCAP_HWSCALE_UP
| VFCAP_HWSCALE_DOWN
;
1100 if (format
== IMGFMT_UYVY
)
1102 image_qtcodec
= k422YpCbCr8CodecType
;
1103 return VFCAP_CSP_SUPPORTED
| VFCAP_OSD
| VFCAP_HWSCALE_UP
| VFCAP_HWSCALE_DOWN
;
1109 static void uninit(void)
1113 switch (image_format
)
1121 if (EnterMoviesDone
)
1123 qterr
= CDSequenceEnd(seqId
);
1126 mp_msg(MSGT_VO
, MSGL_ERR
, "Quartz error: CDSequenceEnd (%d)\n", qterr
);
1138 static int preinit(const char *arg
)
1144 char *parse_pos
= (char *)&arg
[0];
1146 while (parse_pos
[0] && !parse_err
)
1148 if (strncmp(parse_pos
, "device_id=", 10) == 0)
1150 parse_pos
= &parse_pos
[10];
1151 device_id
= strtol(parse_pos
, &parse_pos
, 0);
1153 if (strncmp(parse_pos
, "fs_res=", 7) == 0)
1155 parse_pos
= &parse_pos
[7];
1156 fs_res_x
= strtol(parse_pos
, &parse_pos
, 0);
1157 parse_pos
= &parse_pos
[1];
1158 fs_res_y
= strtol(parse_pos
, &parse_pos
, 0);
1160 if (parse_pos
[0] == ':')
1161 parse_pos
= &parse_pos
[1];
1162 else if (parse_pos
[0])
1167 #if !defined (CONFIG_MACOSX_FINDER) || !defined (CONFIG_SDL)
1168 // this chunk of code is heavily based off SDL_macosx.m from SDL
1169 // the CPSEnableForegroundOperation that was here before is private and shouldn't be used
1170 // replaced by a call to the 10.3+ TransformProcessType
1172 ProcessSerialNumber myProc
, frProc
;
1175 if (GetFrontProcess(&frProc
) == noErr
)
1177 if (GetCurrentProcess(&myProc
) == noErr
)
1179 if (SameProcess(&frProc
, &myProc
, &sameProc
) == noErr
&& !sameProc
)
1181 TransformProcessType(&myProc
, kProcessTransformToForegroundApplication
);
1183 SetFrontProcess(&myProc
);
1192 static uint32_t draw_yuv_image(mp_image_t
* mpi
)
1194 // ATM we're only called for planar IMGFMT
1195 // drawing is done directly in P
1196 // and displaying is in flip_page.
1197 return get_image_done
? VO_TRUE
: VO_FALSE
;
1200 static uint32_t get_yuv_image(mp_image_t
* mpi
)
1202 if (mpi
->type
!= MP_IMGTYPE_EXPORT
) return VO_FALSE
;
1204 if (mpi
->imgfmt
!= image_format
) return VO_FALSE
;
1206 if (mpi
->flags
& MP_IMGFLAG_PLANAR
)
1208 if (mpi
->num_planes
!= 3)
1210 mp_msg(MSGT_VO
, MSGL_ERR
, "Quartz error: only 3 planes allowed in get_yuv_image for planar (%d) \n", mpi
->num_planes
);
1214 mpi
->planes
[0] = ((char *)P
) + be2me_32(P
->componentInfoY
.offset
);
1215 mpi
->stride
[0] = imgRect
.right
;
1216 mpi
->width
= imgRect
.right
;
1218 if (mpi
->flags
& MP_IMGFLAG_SWAPPED
)
1221 mpi
->planes
[1] = ((char *)P
) + be2me_32(P
->componentInfoCb
.offset
);
1222 mpi
->planes
[2] = ((char *)P
) + be2me_32(P
->componentInfoCr
.offset
);
1223 mpi
->stride
[1] = imgRect
.right
/ 2;
1224 mpi
->stride
[2] = imgRect
.right
/ 2;
1229 mpi
->planes
[1] = ((char *)P
) + be2me_32(P
->componentInfoCr
.offset
);
1230 mpi
->planes
[2] = ((char *)P
) + be2me_32(P
->componentInfoCb
.offset
);
1231 mpi
->stride
[1] = imgRect
.right
/ 2;
1232 mpi
->stride
[2] = imgRect
.right
/ 2;
1235 mpi
->flags
|= MP_IMGFLAG_DIRECT
;
1242 if (mpi
->num_planes
!= 1)
1244 mp_msg(MSGT_VO
, MSGL_ERR
, "Quartz error: only 1 plane allowed in get_yuv_image for packed (%d) \n", mpi
->num_planes
);
1248 mpi
->planes
[0] = (char *)P
;
1249 mpi
->stride
[0] = imgRect
.right
* 2;
1250 mpi
->width
= imgRect
.right
;
1251 mpi
->flags
|= MP_IMGFLAG_DIRECT
;
1258 static int control(uint32_t request
, void *data
, ...)
1262 case VOCTRL_PAUSE
: return int_pause
= 1;
1263 case VOCTRL_RESUME
: return int_pause
= 0;
1264 case VOCTRL_FULLSCREEN
: vo_fs
= (!(vo_fs
)); window_fullscreen(); return VO_TRUE
;
1265 case VOCTRL_ONTOP
: vo_ontop
= (!(vo_ontop
)); window_ontop(); return VO_TRUE
;
1266 case VOCTRL_QUERY_FORMAT
: return query_format(*((uint32_t *) data
));
1267 case VOCTRL_GET_PANSCAN
: return VO_TRUE
;
1268 case VOCTRL_SET_PANSCAN
: window_panscan(); return VO_TRUE
;
1270 case VOCTRL_GET_IMAGE
:
1271 switch (image_format
)
1278 return get_yuv_image(data
);
1283 case VOCTRL_DRAW_IMAGE
:
1284 switch (image_format
)
1291 return draw_yuv_image(data
);
1300 void window_resized()
1312 CGContextRef context
;
1314 GetWindowPortBounds(theWindow
, &winRect
);
1318 aspect(&d_width
, &d_height
, A_NOZOOM
);
1319 d_height
= ((float)d_width
/ movie_aspect
);
1321 aspectX
= (float)((float)winRect
.right
/ (float)d_width
);
1322 aspectY
= (float)((float)(winRect
.bottom
) / (float)d_height
);
1324 if ((d_height
* aspectX
) > (winRect
.bottom
))
1326 padding
= (winRect
.right
- d_width
* aspectY
) / 2;
1327 SetRect(&dstRect
, padding
, 0, d_width
* aspectY
+ padding
, d_height
* aspectY
);
1331 padding
= ((winRect
.bottom
) - d_height
* aspectX
) / 2;
1332 SetRect(&dstRect
, 0, padding
, (d_width
* aspectX
), d_height
* aspectX
+ padding
);
1337 SetRect(&dstRect
, 0, 0, winRect
.right
, winRect
.bottom
);
1340 switch (image_format
)
1344 bounds
= CGRectMake(dstRect
.left
, dstRect
.top
, dstRect
.right
- dstRect
.left
, dstRect
.bottom
- dstRect
.top
);
1353 long scale_X
= FixDiv(Long2Fix(dstRect
.right
- dstRect
.left
), Long2Fix(imgRect
.right
));
1354 long scale_Y
= FixDiv(Long2Fix(dstRect
.bottom
- dstRect
.top
), Long2Fix(imgRect
.bottom
));
1356 SetIdentityMatrix(&matrix
);
1357 if (((dstRect
.right
- dstRect
.left
) != imgRect
.right
) || ((dstRect
.bottom
- dstRect
.right
) != imgRect
.bottom
))
1359 ScaleMatrix(&matrix
, scale_X
, scale_Y
, 0, 0);
1363 TranslateMatrix(&matrix
, Long2Fix(dstRect
.left
), Long2Fix(dstRect
.top
));
1367 SetDSequenceMatrix(seqId
, &matrix
);
1375 tmpBounds
= CGRectMake(0, 0, winRect
.right
, winRect
.bottom
);
1376 QDBeginCGContext(GetWindowPort(theWindow
), &context
);
1377 CGContextFillRect(context
, tmpBounds
);
1378 QDEndCGContext(GetWindowPort(theWindow
), &context
);
1385 // Cycle between level
1390 SetWindowGroupLevel(winGroup
, CGWindowLevelForKey(levelList
[winLevel
]));
1393 void window_fullscreen()
1400 if (displayId
== kCGDirectMainDisplay
)
1402 SetSystemUIMode(kUIModeAllHidden
, kUIOptionAutoShowMenuBar
);
1403 CGDisplayHideCursor(displayId
);
1407 if (fs_res_x
!= 0 || fs_res_y
!= 0)
1409 CFDictionaryRef mode
;
1410 size_t desiredBitDepth
= 32;
1411 boolean_t exactMatch
;
1413 originalMode
= CGDisplayCurrentMode(displayId
);
1415 mode
= CGDisplayBestModeForParameters(displayId
, desiredBitDepth
, fs_res_x
, fs_res_y
, &exactMatch
);
1421 // Warn if the mode doesn't match exactly
1422 mp_msg(MSGT_VO
, MSGL_WARN
, "Quartz warning: did not get exact mode match (got %dx%d) \n", (int)CFDictionaryGetValue(mode
, kCGDisplayWidth
), (int)CFDictionaryGetValue(mode
, kCGDisplayHeight
));
1425 CGDisplayCapture(displayId
);
1426 CGDisplaySwitchToMode(displayId
, mode
);
1430 mp_msg(MSGT_VO
, MSGL_ERR
, "Quartz error: can't switch to fullscreen \n");
1433 // Get Main device info///////////////////////////////////////////////////
1434 displayRect
= CGDisplayBounds(displayId
);
1437 // save old window size
1440 GetWindowPortBounds(theWindow
, &oldWinRect
);
1441 GetWindowBounds(theWindow
, kWindowContentRgn
, &oldWinBounds
);
1445 ChangeWindowAttributes(theWindow
, kWindowNoShadowAttribute
, 0);
1446 MoveWindow(theWindow
, displayRect
.origin
.x
- (vo_panscan_x
>> 1), displayRect
.origin
.y
- (vo_panscan_y
>> 1), 1);
1447 SizeWindow(theWindow
, displayRect
.size
.width
+ vo_panscan_x
, displayRect
.size
.height
+ vo_panscan_y
, 1);
1451 else //go back to windowed mode
1454 if (originalMode
!= NULL
)
1456 CGDisplaySwitchToMode(displayId
, originalMode
);
1457 CGDisplayRelease(displayId
);
1459 // Get Main device info///////////////////////////////////////////////////
1460 displayRect
= CGDisplayBounds(displayId
);
1462 originalMode
= NULL
;
1464 SetSystemUIMode(kUIModeNormal
, 0);
1466 // show mouse cursor
1467 CGDisplayShowCursor(displayId
);
1470 // revert window to previous setting
1471 ChangeWindowAttributes(theWindow
, 0, kWindowNoShadowAttribute
);
1472 SizeWindow(theWindow
, oldWinRect
.right
, oldWinRect
.bottom
, 1);
1473 MoveWindow(theWindow
, oldWinBounds
.left
, oldWinBounds
.top
, 1);
1478 void window_panscan()
1483 CheckMenuItem(aspectMenu
, 2, 1);
1485 CheckMenuItem(aspectMenu
, 2, 0);
1489 MoveWindow(theWindow
, displayRect
.origin
.x
- (vo_panscan_x
>> 1), displayRect
.origin
.y
- (vo_panscan_y
>> 1), 1);
1490 SizeWindow(theWindow
, displayRect
.size
.width
+ vo_panscan_x
, displayRect
.size
.height
+ vo_panscan_y
, 1);