2004-04-26 14:17:26 +02:00
/*
vo_quartz . c
2008-11-24 14:28:56 +01:00
2004-10-19 17:04:45 +02:00
by Nicolas Plourde < nicolasplourde @ gmail . com >
2008-11-24 14:28:56 +01:00
2004-04-26 14:17:26 +02:00
Copyright ( c ) Nicolas Plourde - April 2004
2004-05-04 04:57:10 +02:00
YUV support Copyright ( C ) 2004 Romain Dolbeau < romain @ dolbeau . org >
2008-11-24 14:28:56 +01:00
2004-04-26 14:17:26 +02:00
MPlayer Mac OSX Quartz video out module .
2008-11-24 14:28:56 +01:00
2004-10-20 18:38:33 +02:00
todo : - screen overlay output
2004-10-30 21:56:41 +02:00
- fit osd in black bar when available
2005-06-09 14:39:52 +02:00
- fix RGB32
2004-04-26 14:17:26 +02:00
- ( add sugestion here )
2004-04-05 23:20:19 +02:00
*/
//SYS
# include <stdio.h>
//OSX
# include <Carbon/Carbon.h>
2004-05-04 04:57:10 +02:00
# include <QuickTime/QuickTime.h>
2004-04-05 23:20:19 +02:00
//MPLAYER
# include "config.h"
2004-05-04 04:57:10 +02:00
# include "fastmemcpy.h"
2004-04-05 23:20:19 +02:00
# include "video_out.h"
# include "video_out_internal.h"
# include "aspect.h"
2004-05-04 04:57:10 +02:00
# include "mp_msg.h"
# include "m_option.h"
2007-03-29 19:16:11 +02:00
# include "mp_fifo.h"
2007-06-29 23:57:31 +02:00
# include "mpbswap.h"
2004-04-05 23:20:19 +02:00
2004-10-28 03:15:53 +02:00
# include "input/input.h"
# include "input/mouse.h"
2004-04-05 23:20:19 +02:00
# include "vo_quartz.h"
2008-11-24 14:28:56 +01:00
static const vo_info_t info =
2004-04-26 14:17:26 +02:00
{
" Mac OSX (Quartz) " ,
" quartz " ,
2004-05-04 04:57:10 +02:00
" Nicolas Plourde <nicolasplourde@hotmail.com>, Romain Dolbeau <romain@dolbeau.org> " ,
2004-04-26 14:17:26 +02:00
" "
2004-04-05 23:20:19 +02:00
} ;
2007-12-02 15:39:15 +01:00
const LIBVO_EXTERN ( quartz )
2004-04-26 14:17:26 +02:00
2004-05-04 04:57:10 +02:00
static uint32_t image_depth ;
static uint32_t image_format ;
static uint32_t image_size ;
static uint32_t image_buffer_size ;
2004-05-07 03:44:08 +02:00
static char * image_data ;
2004-05-04 04:57:10 +02:00
2004-05-07 03:44:08 +02:00
static ImageSequence seqId ;
2004-05-04 04:57:10 +02:00
static CodecType image_qtcodec ;
2004-05-18 22:49:44 +02:00
static PlanarPixmapInfoYUV420 * P = NULL ;
2004-05-05 03:04:44 +02:00
static struct
{
ImageDescriptionHandle desc ;
Handle extension_colr ;
Handle extension_fiel ;
Handle extension_clap ;
Handle extension_pasp ;
2004-05-04 04:57:10 +02:00
} yuv_qt_stuff ;
2004-05-07 03:44:08 +02:00
static MatrixRecord matrix ;
2004-05-04 04:57:10 +02:00
static int EnterMoviesDone = 0 ;
2004-05-18 22:49:44 +02:00
static int get_image_done = 0 ;
2004-04-05 23:20:19 +02:00
2004-05-18 22:49:44 +02:00
static int vo_quartz_fs ; // we are in fullscreen
2004-10-28 23:48:41 +02:00
extern float monitor_aspect ;
2004-10-29 00:03:26 +02:00
extern float movie_aspect ;
static float old_movie_aspect ;
2004-04-05 23:20:19 +02:00
2004-07-15 19:36:01 +02:00
static int winLevel = 1 ;
int levelList [ ] =
{
kCGDesktopWindowLevelKey ,
kCGNormalWindowLevelKey ,
kCGScreenSaverWindowLevelKey
} ;
2004-05-18 22:49:44 +02:00
static int int_pause = 0 ;
static float winAlpha = 1 ;
2005-07-02 21:44:48 +02:00
static int mouseHide = FALSE ;
2004-04-05 23:20:19 +02:00
2008-11-24 11:01:03 +01:00
static int device_id = 0 ;
2004-04-05 23:20:19 +02:00
2004-10-28 16:52:47 +02:00
static short fs_res_x = 0 ;
static short fs_res_y = 0 ;
2004-05-18 22:49:44 +02:00
static WindowRef theWindow = NULL ;
2004-07-15 19:36:01 +02:00
static WindowGroupRef winGroup = NULL ;
2004-08-24 22:42:27 +02:00
static CGRect bounds ;
2008-11-24 11:01:03 +01:00
static CGDirectDisplayID displayId = 0 ;
static CFDictionaryRef originalMode = NULL ;
2004-08-24 22:42:27 +02:00
2008-11-24 11:01:03 +01:00
static CGDataProviderRef dataProviderRef = NULL ;
static CGImageRef image = NULL ;
2004-04-26 14:17:26 +02:00
2004-05-18 22:49:44 +02:00
static Rect imgRect ; // size of the original image (unscaled)
static Rect dstRect ; // size of the displayed image (after scaling)
static Rect winRect ; // size of the window containg the displayed image (include padding)
static Rect oldWinRect ; // size of the window containg the displayed image (include padding) when NOT in FS mode
2008-11-24 11:01:03 +01:00
static CGRect displayRect ; // size of the display device
2004-11-01 17:17:49 +01:00
static Rect oldWinBounds ;
2004-04-26 14:17:26 +02:00
2004-10-29 00:03:26 +02:00
static MenuRef windMenu ;
static MenuRef movMenu ;
static MenuRef aspectMenu ;
2008-11-24 11:01:03 +01:00
static int lastScreensaverUpdate = 0 ;
static int lastMouseHide = 0 ;
2004-10-19 17:04:45 +02:00
enum
{
kQuitCmd = 1 ,
kHalfScreenCmd = 2 ,
kNormalScreenCmd = 3 ,
kDoubleScreenCmd = 4 ,
2004-10-29 00:03:26 +02:00
kFullScreenCmd = 5 ,
kKeepAspectCmd = 6 ,
kAspectOrgCmd = 7 ,
kAspectFullCmd = 8 ,
2004-10-29 03:24:14 +02:00
kAspectWideCmd = 9 ,
kPanScanCmd = 10
2004-10-19 17:04:45 +02:00
} ;
2004-10-28 03:15:53 +02:00
# include "osdep/keycodes.h"
2004-04-26 14:17:26 +02:00
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 ) ) ;
2004-04-05 23:20:19 +02:00
//PROTOTYPE/////////////////////////////////////////////////////////////////
2005-06-09 14:39:52 +02:00
static OSStatus KeyEventHandler ( EventHandlerCallRef nextHandler , EventRef event , void * userData ) ;
static OSStatus MouseEventHandler ( EventHandlerCallRef nextHandler , EventRef event , void * userData ) ;
static OSStatus WindowEventHandler ( EventHandlerCallRef nextHandler , EventRef event , void * userData ) ;
2004-04-26 14:17:26 +02:00
void window_resized ( ) ;
void window_ontop ( ) ;
void window_fullscreen ( ) ;
2004-11-01 17:17:49 +01:00
void window_panscan ( ) ;
2004-04-26 14:17:26 +02:00
2004-07-22 22:02:26 +02:00
static inline int convert_key ( UInt32 key , UInt32 charcode )
{
switch ( key )
{
case QZ_IBOOK_ENTER :
case QZ_RETURN : return KEY_ENTER ;
case QZ_ESCAPE : return KEY_ESC ;
case QZ_BACKSPACE : return KEY_BACKSPACE ;
case QZ_LALT : return KEY_BACKSPACE ;
case QZ_LCTRL : return KEY_BACKSPACE ;
case QZ_LSHIFT : return KEY_BACKSPACE ;
case QZ_F1 : return KEY_F + 1 ;
case QZ_F2 : return KEY_F + 2 ;
case QZ_F3 : return KEY_F + 3 ;
case QZ_F4 : return KEY_F + 4 ;
case QZ_F5 : return KEY_F + 5 ;
case QZ_F6 : return KEY_F + 6 ;
case QZ_F7 : return KEY_F + 7 ;
case QZ_F8 : return KEY_F + 8 ;
case QZ_F9 : return KEY_F + 9 ;
case QZ_F10 : return KEY_F + 10 ;
case QZ_F11 : return KEY_F + 11 ;
case QZ_F12 : return KEY_F + 12 ;
case QZ_INSERT : return KEY_INSERT ;
case QZ_DELETE : return KEY_DELETE ;
case QZ_HOME : return KEY_HOME ;
case QZ_END : return KEY_END ;
case QZ_KP_PLUS : return ' + ' ;
case QZ_KP_MINUS : return ' - ' ;
case QZ_TAB : return KEY_TAB ;
case QZ_PAGEUP : return KEY_PAGE_UP ;
2008-11-24 14:28:56 +01:00
case QZ_PAGEDOWN : return KEY_PAGE_DOWN ;
2004-07-22 22:02:26 +02:00
case QZ_UP : return KEY_UP ;
case QZ_DOWN : return KEY_DOWN ;
case QZ_LEFT : return KEY_LEFT ;
case QZ_RIGHT : return KEY_RIGHT ;
case QZ_KP_MULTIPLY : return ' * ' ;
case QZ_KP_DIVIDE : return ' / ' ;
2007-11-06 14:17:37 +01:00
case QZ_KP_ENTER : return KEY_KPENTER ;
2004-07-22 22:02:26 +02:00
case QZ_KP_PERIOD : return KEY_KPDEC ;
case QZ_KP0 : return KEY_KP0 ;
case QZ_KP1 : return KEY_KP1 ;
case QZ_KP2 : return KEY_KP2 ;
case QZ_KP3 : return KEY_KP3 ;
case QZ_KP4 : return KEY_KP4 ;
case QZ_KP5 : return KEY_KP5 ;
case QZ_KP6 : return KEY_KP6 ;
case QZ_KP7 : return KEY_KP7 ;
case QZ_KP8 : return KEY_KP8 ;
case QZ_KP9 : return KEY_KP9 ;
default : return charcode ;
}
}
2004-04-26 14:17:26 +02:00
static void draw_alpha ( int x0 , int y0 , int w , int h , unsigned char * src , unsigned char * srca , int stride )
{
2004-05-05 03:04:44 +02:00
switch ( image_format )
{
case IMGFMT_RGB32 :
vo_draw_alpha_rgb32 ( w , h , src , srca , stride , image_data + 4 * ( y0 * imgRect . right + x0 ) , 4 * imgRect . right ) ;
break ;
case IMGFMT_YV12 :
case IMGFMT_IYUV :
case IMGFMT_I420 :
2007-06-29 23:57:31 +02:00
vo_draw_alpha_yv12 ( w , h , src , srca , stride , ( ( char * ) P ) + be2me_32 ( P - > componentInfoY . offset ) + x0 + y0 * imgRect . right , imgRect . right ) ;
2004-05-05 03:04:44 +02:00
break ;
case IMGFMT_UYVY :
2004-05-31 17:16:41 +02:00
vo_draw_alpha_uyvy ( w , h , src , srca , stride , ( ( char * ) P ) + ( x0 + y0 * imgRect . right ) * 2 , imgRect . right * 2 ) ;
2004-05-05 03:04:44 +02:00
break ;
case IMGFMT_YUY2 :
2004-05-18 22:49:44 +02:00
vo_draw_alpha_yuy2 ( w , h , src , srca , stride , ( ( char * ) P ) + ( x0 + y0 * imgRect . right ) * 2 , imgRect . right * 2 ) ;
2004-05-05 03:04:44 +02:00
break ;
2004-05-18 22:49:44 +02:00
}
2004-04-26 14:17:26 +02:00
}
2004-04-05 23:20:19 +02:00
2005-06-09 14:39:52 +02:00
//default keyboard event handler
static OSStatus KeyEventHandler ( EventHandlerCallRef nextHandler , EventRef event , void * userData )
2004-04-05 23:20:19 +02:00
{
2004-06-23 14:48:42 +02:00
OSStatus result = noErr ;
2004-05-12 22:47:14 +02:00
UInt32 class = GetEventClass ( event ) ;
2008-11-24 14:28:56 +01:00
UInt32 kind = GetEventKind ( event ) ;
2004-06-23 14:48:42 +02:00
result = CallNextEventHandler ( nextHandler , event ) ;
2008-11-24 14:28:56 +01:00
2004-10-21 01:33:31 +02:00
if ( class = = kEventClassKeyboard )
2004-05-12 22:47:14 +02:00
{
char macCharCodes ;
UInt32 macKeyCode ;
UInt32 macKeyModifiers ;
2008-11-24 14:28:56 +01:00
2004-05-12 22:47:14 +02:00
GetEventParameter ( event , kEventParamKeyMacCharCodes , typeChar , NULL , sizeof ( macCharCodes ) , NULL , & macCharCodes ) ;
GetEventParameter ( event , kEventParamKeyCode , typeUInt32 , NULL , sizeof ( macKeyCode ) , NULL , & macKeyCode ) ;
GetEventParameter ( event , kEventParamKeyModifiers , typeUInt32 , NULL , sizeof ( macKeyModifiers ) , NULL , & macKeyModifiers ) ;
2008-11-24 14:28:56 +01:00
2004-10-19 17:04:45 +02:00
if ( macKeyModifiers ! = 256 )
2004-04-26 14:17:26 +02:00
{
2004-10-19 17:04:45 +02:00
if ( kind = = kEventRawKeyRepeat | | kind = = kEventRawKeyDown )
{
int key = convert_key ( macKeyCode , macCharCodes ) ;
if ( key ! = - 1 )
mplayer_put_key ( key ) ;
}
}
else if ( macKeyModifiers = = 256 )
{
switch ( macCharCodes )
{
case ' [ ' : SetWindowAlpha ( theWindow , winAlpha - = 0.05 ) ; break ;
2008-11-24 14:28:56 +01:00
case ' ] ' : SetWindowAlpha ( theWindow , winAlpha + = 0.05 ) ; break ;
}
2004-05-12 22:47:14 +02:00
}
2004-07-22 22:02:26 +02:00
else
result = eventNotHandledErr ;
2004-05-12 22:47:14 +02:00
}
2008-11-24 14:28:56 +01:00
2005-06-09 14:39:52 +02:00
return result ;
}
//default mouse event handler
static OSStatus MouseEventHandler ( EventHandlerCallRef nextHandler , EventRef event , void * userData )
{
OSStatus result = noErr ;
UInt32 class = GetEventClass ( event ) ;
2008-11-24 14:28:56 +01:00
UInt32 kind = GetEventKind ( event ) ;
2005-06-09 14:39:52 +02:00
result = CallNextEventHandler ( nextHandler , event ) ;
2008-11-24 14:28:56 +01:00
2005-06-09 14:39:52 +02:00
if ( class = = kEventClassMouse )
2004-05-12 22:47:14 +02:00
{
WindowPtr tmpWin ;
Point mousePos ;
2005-06-09 14:39:52 +02:00
Point winMousePos ;
2004-04-05 23:20:19 +02:00
2004-05-12 22:47:14 +02:00
GetEventParameter ( event , kEventParamMouseLocation , typeQDPoint , 0 , sizeof ( Point ) , 0 , & mousePos ) ;
2005-06-09 14:39:52 +02:00
GetEventParameter ( event , kEventParamWindowMouseLocation , typeQDPoint , 0 , sizeof ( Point ) , 0 , & winMousePos ) ;
2004-04-05 23:20:19 +02:00
2004-05-12 22:47:14 +02:00
switch ( kind )
2004-04-26 14:17:26 +02:00
{
2005-07-01 19:21:13 +02:00
case kEventMouseMoved :
{
if ( vo_quartz_fs )
{
2008-11-24 11:01:03 +01:00
CGDisplayShowCursor ( displayId ) ;
2005-07-01 19:21:13 +02:00
mouseHide = FALSE ;
}
}
break ;
2008-11-24 14:28:56 +01:00
2005-06-09 14:39:52 +02:00
case kEventMouseWheelMoved :
{
int wheel ;
short part ;
2008-11-24 14:28:56 +01:00
2005-06-09 14:39:52 +02:00
GetEventParameter ( event , kEventParamMouseWheelDelta , typeSInt32 , 0 , sizeof ( int ) , 0 , & wheel ) ;
part = FindWindow ( mousePos , & tmpWin ) ;
2008-11-24 14:28:56 +01:00
2005-06-09 14:39:52 +02:00
if ( part = = inContent )
{
if ( wheel > 0 )
mplayer_put_key ( MOUSE_BTN3 ) ;
else
mplayer_put_key ( MOUSE_BTN4 ) ;
}
}
break ;
2008-11-24 14:28:56 +01:00
2004-05-12 22:47:14 +02:00
case kEventMouseDown :
2007-11-07 02:44:41 +01:00
case kEventMouseUp :
2004-05-12 22:47:14 +02:00
{
EventMouseButton button ;
2004-10-21 13:36:20 +02:00
short part ;
2005-06-09 14:39:52 +02:00
Rect bounds ;
2008-11-24 14:28:56 +01:00
2005-06-09 14:39:52 +02:00
GetWindowPortBounds ( theWindow , & bounds ) ;
2004-05-12 22:47:14 +02:00
GetEventParameter ( event , kEventParamMouseButton , typeMouseButton , 0 , sizeof ( EventMouseButton ) , 0 , & button ) ;
2008-11-24 14:28:56 +01:00
2004-10-21 13:36:20 +02:00
part = FindWindow ( mousePos , & tmpWin ) ;
2007-11-07 02:44:41 +01:00
if ( kind = = kEventMouseUp )
{
if ( part ! = inContent )
break ;
switch ( button )
2008-11-24 14:28:56 +01:00
{
2007-11-07 02:44:41 +01:00
case kEventMouseButtonPrimary :
mplayer_put_key ( MOUSE_BTN0 ) ;
break ;
case kEventMouseButtonSecondary :
2007-12-18 15:48:30 +01:00
mplayer_put_key ( MOUSE_BTN2 ) ;
2007-11-07 02:44:41 +01:00
break ;
case kEventMouseButtonTertiary :
2007-12-18 15:48:30 +01:00
mplayer_put_key ( MOUSE_BTN1 ) ;
2007-11-07 02:44:41 +01:00
break ;
2008-11-24 14:28:56 +01:00
2007-11-07 02:44:41 +01:00
default : result = eventNotHandledErr ; break ;
}
break ;
}
2005-06-09 14:39:52 +02:00
if ( ( winMousePos . h > ( bounds . right - 15 ) ) & & ( winMousePos . v > ( bounds . bottom ) ) )
{
2005-06-14 14:48:39 +02:00
if ( ! vo_quartz_fs )
{
2008-11-24 11:01:03 +01:00
Rect newSize ;
ResizeWindow ( theWindow , mousePos , NULL , & newSize ) ;
2005-06-14 14:48:39 +02:00
}
2005-06-09 14:39:52 +02:00
}
else if ( part = = inMenuBar )
2004-04-26 14:17:26 +02:00
{
MenuSelect ( mousePos ) ;
2004-05-12 22:47:14 +02:00
HiliteMenu ( 0 ) ;
2004-04-26 14:17:26 +02:00
}
2004-05-12 22:47:14 +02:00
else if ( part = = inContent )
{
switch ( button )
2008-11-24 14:28:56 +01:00
{
2007-11-06 16:57:36 +01:00
case kEventMouseButtonPrimary :
2007-11-07 02:44:41 +01:00
mplayer_put_key ( MOUSE_BTN0 | MP_KEY_DOWN ) ;
2007-11-06 16:57:36 +01:00
break ;
case kEventMouseButtonSecondary :
2007-12-18 15:48:30 +01:00
mplayer_put_key ( MOUSE_BTN2 | MP_KEY_DOWN ) ;
2007-11-06 16:57:36 +01:00
break ;
case kEventMouseButtonTertiary :
2007-12-18 15:48:30 +01:00
mplayer_put_key ( MOUSE_BTN1 | MP_KEY_DOWN ) ;
2007-11-06 16:57:36 +01:00
break ;
2008-11-24 14:28:56 +01:00
2004-06-23 14:48:42 +02:00
default : result = eventNotHandledErr ; break ;
2004-05-12 22:47:14 +02:00
}
}
2008-11-24 14:28:56 +01:00
}
2004-05-12 22:47:14 +02:00
break ;
2008-11-24 14:28:56 +01:00
2005-06-09 14:39:52 +02:00
case kEventMouseDragged :
break ;
2008-11-24 14:28:56 +01:00
2004-06-23 14:48:42 +02:00
default : result = eventNotHandledErr ; break ;
2004-05-12 22:47:14 +02:00
}
}
2005-06-09 14:39:52 +02:00
2004-06-23 14:48:42 +02:00
return result ;
2004-04-05 23:20:19 +02:00
}
2005-06-09 14:39:52 +02:00
//default window event handler
static OSStatus WindowEventHandler ( EventHandlerCallRef nextHandler , EventRef event , void * userData )
2004-10-20 18:38:33 +02:00
{
OSStatus result = noErr ;
2004-10-21 14:43:08 +02:00
uint32_t d_width ;
uint32_t d_height ;
2004-10-20 18:38:33 +02:00
UInt32 class = GetEventClass ( event ) ;
2008-11-24 14:28:56 +01:00
UInt32 kind = GetEventKind ( event ) ;
2004-10-20 18:38:33 +02:00
result = CallNextEventHandler ( nextHandler , event ) ;
2008-11-24 14:28:56 +01:00
2004-10-21 01:33:31 +02:00
aspect ( & d_width , & d_height , A_NOZOOM ) ;
2004-10-20 18:38:33 +02:00
if ( class = = kEventClassCommand )
{
HICommand theHICommand ;
GetEventParameter ( event , kEventParamDirectObject , typeHICommand , NULL , sizeof ( HICommand ) , NULL , & theHICommand ) ;
2008-11-24 14:28:56 +01:00
2004-10-20 18:38:33 +02:00
switch ( theHICommand . commandID )
{
case kHICommandQuit :
2005-11-02 22:50:55 +01:00
mplayer_put_key ( KEY_CLOSE_WIN ) ;
2004-10-20 18:38:33 +02:00
break ;
2008-11-24 14:28:56 +01:00
2004-10-20 18:38:33 +02:00
case kHalfScreenCmd :
2004-10-22 02:28:03 +02:00
if ( vo_quartz_fs )
{
vo_fs = ( ! ( vo_fs ) ) ; window_fullscreen ( ) ;
}
2008-11-24 14:28:56 +01:00
2005-06-09 14:39:52 +02:00
SizeWindow ( theWindow , ( d_width / 2 ) , ( ( d_width / movie_aspect ) / 2 ) , 1 ) ;
2004-10-20 18:38:33 +02:00
window_resized ( ) ;
break ;
case kNormalScreenCmd :
2004-10-22 02:28:03 +02:00
if ( vo_quartz_fs )
{
vo_fs = ( ! ( vo_fs ) ) ; window_fullscreen ( ) ;
}
2008-11-24 14:28:56 +01:00
2005-06-09 14:39:52 +02:00
SizeWindow ( theWindow , d_width , ( d_width / movie_aspect ) , 1 ) ;
2004-10-20 18:38:33 +02:00
window_resized ( ) ;
break ;
case kDoubleScreenCmd :
2004-10-22 02:28:03 +02:00
if ( vo_quartz_fs )
{
vo_fs = ( ! ( vo_fs ) ) ; window_fullscreen ( ) ;
}
2008-11-24 14:28:56 +01:00
2005-06-09 14:39:52 +02:00
SizeWindow ( theWindow , ( d_width * 2 ) , ( ( d_width / movie_aspect ) * 2 ) , 1 ) ;
2004-10-20 18:38:33 +02:00
window_resized ( ) ;
break ;
case kFullScreenCmd :
vo_fs = ( ! ( vo_fs ) ) ; window_fullscreen ( ) ;
break ;
2004-10-29 00:03:26 +02:00
case kKeepAspectCmd :
vo_keepaspect = ( ! ( vo_keepaspect ) ) ;
CheckMenuItem ( aspectMenu , 1 , vo_keepaspect ) ;
2005-07-03 16:28:51 +02:00
window_resized ( ) ;
2004-10-29 00:03:26 +02:00
break ;
2008-11-24 14:28:56 +01:00
2004-10-29 00:03:26 +02:00
case kAspectOrgCmd :
movie_aspect = old_movie_aspect ;
2005-07-03 14:24:48 +02:00
if ( ! vo_quartz_fs )
{
SizeWindow ( theWindow , dstRect . right , ( dstRect . right / movie_aspect ) , 1 ) ;
}
2004-10-29 00:03:26 +02:00
window_resized ( ) ;
break ;
2008-11-24 14:28:56 +01:00
2004-10-29 00:03:26 +02:00
case kAspectFullCmd :
movie_aspect = 4.0f / 3.0f ;
2005-07-02 21:44:48 +02:00
if ( ! vo_quartz_fs )
{
SizeWindow ( theWindow , dstRect . right , ( dstRect . right / movie_aspect ) , 1 ) ;
}
2004-10-29 00:03:26 +02:00
window_resized ( ) ;
break ;
2008-11-24 14:28:56 +01:00
2004-10-29 00:03:26 +02:00
case kAspectWideCmd :
movie_aspect = 16.0f / 9.0f ;
2005-07-02 21:44:48 +02:00
if ( ! vo_quartz_fs )
{
SizeWindow ( theWindow , dstRect . right , ( dstRect . right / movie_aspect ) , 1 ) ;
}
2004-10-29 00:03:26 +02:00
window_resized ( ) ;
break ;
2008-11-24 14:28:56 +01:00
2004-10-29 03:24:14 +02:00
case kPanScanCmd :
2004-11-01 17:17:49 +01:00
vo_panscan = ( ! ( vo_panscan ) ) ;
CheckMenuItem ( aspectMenu , 2 , vo_panscan ) ;
2005-07-03 14:24:48 +02:00
window_panscan ( ) ;
window_resized ( ) ;
2004-10-29 03:24:14 +02:00
break ;
2008-11-24 14:28:56 +01:00
2004-10-20 18:38:33 +02:00
default :
result = eventNotHandledErr ;
break ;
}
}
else if ( class = = kEventClassWindow )
{
WindowRef window ;
2008-11-24 11:01:03 +01:00
Rect rectWindow = { 0 , 0 , 0 , 0 } ;
2008-11-24 14:28:56 +01:00
2004-10-20 18:38:33 +02:00
GetEventParameter ( event , kEventParamDirectObject , typeWindowRef , NULL , sizeof ( WindowRef ) , NULL , & window ) ;
2008-11-24 14:28:56 +01:00
2004-10-20 18:38:33 +02:00
if ( window )
{
2008-11-24 11:01:03 +01:00
GetWindowBounds ( window , kWindowGlobalPortRgn , & rectWindow ) ;
2008-11-24 14:28:56 +01:00
}
2004-10-20 18:38:33 +02:00
switch ( kind )
{
case kEventWindowClosed :
theWindow = NULL ;
2005-11-02 22:50:55 +01:00
mplayer_put_key ( KEY_CLOSE_WIN ) ;
2004-10-20 18:38:33 +02:00
break ;
2008-11-24 14:28:56 +01:00
2004-10-20 18:38:33 +02:00
//resize window
2005-06-09 14:39:52 +02:00
case kEventWindowZoomed :
2004-10-20 18:38:33 +02:00
case kEventWindowBoundsChanged :
window_resized ( ) ;
flip_page ( ) ;
2005-07-02 15:28:25 +02:00
window_resized ( ) ;
2004-10-20 18:38:33 +02:00
break ;
2008-11-24 14:28:56 +01:00
2004-10-20 18:38:33 +02:00
default :
result = eventNotHandledErr ;
break ;
}
}
2008-11-24 14:28:56 +01:00
2004-10-20 18:38:33 +02:00
return result ;
}
2008-11-24 14:28:56 +01:00
static void quartz_CreateWindow ( uint32_t d_width , uint32_t d_height , WindowAttributes windowAttrs )
2004-05-18 22:49:44 +02:00
{
CFStringRef titleKey ;
2008-11-24 14:28:56 +01:00
CFStringRef windowTitle ;
OSStatus result ;
2004-10-29 00:03:26 +02:00
MenuItemIndex index ;
CFStringRef movMenuTitle ;
CFStringRef aspMenuTitle ;
2008-11-24 14:28:56 +01:00
2007-11-06 13:12:48 +01:00
const EventTypeSpec win_events [ ] = {
{ kEventClassWindow , kEventWindowClosed } ,
{ kEventClassWindow , kEventWindowBoundsChanged } ,
{ kEventClassCommand , kEventCommandProcess }
} ;
const EventTypeSpec key_events [ ] = {
{ kEventClassKeyboard , kEventRawKeyDown } ,
{ kEventClassKeyboard , kEventRawKeyRepeat }
} ;
const EventTypeSpec mouse_events [ ] = {
{ kEventClassMouse , kEventMouseMoved } ,
{ kEventClassMouse , kEventMouseWheelMoved } ,
{ kEventClassMouse , kEventMouseDown } ,
{ kEventClassMouse , kEventMouseUp } ,
{ kEventClassMouse , kEventMouseDragged }
} ;
2004-05-18 22:49:44 +02:00
SetRect ( & winRect , 0 , 0 , d_width , d_height ) ;
SetRect ( & oldWinRect , 0 , 0 , d_width , d_height ) ;
SetRect ( & dstRect , 0 , 0 , d_width , d_height ) ;
2008-11-24 14:28:56 +01:00
2004-12-01 22:19:04 +01:00
//Clear Menu Bar
ClearMenuBar ( ) ;
2008-11-24 14:28:56 +01:00
2004-10-29 00:03:26 +02:00
//Create Window Menu
2004-10-19 17:04:45 +02:00
CreateStandardWindowMenu ( 0 , & windMenu ) ;
InsertMenu ( windMenu , 0 ) ;
2008-11-24 14:28:56 +01:00
2004-10-29 00:03:26 +02:00
//Create Movie Menu
2004-10-19 17:04:45 +02:00
CreateNewMenu ( 1004 , 0 , & movMenu ) ;
2004-10-29 00:03:26 +02:00
movMenuTitle = CFSTR ( " Movie " ) ;
2004-10-19 17:04:45 +02:00
SetMenuTitleWithCFString ( movMenu , movMenuTitle ) ;
2008-11-24 14:28:56 +01:00
2004-10-19 17:04:45 +02:00
AppendMenuItemTextWithCFString ( movMenu , CFSTR ( " Half Size " ) , 0 , kHalfScreenCmd , & index ) ;
SetMenuItemCommandKey ( movMenu , index , 0 , ' 0 ' ) ;
2008-11-24 14:28:56 +01:00
2004-10-19 17:04:45 +02:00
AppendMenuItemTextWithCFString ( movMenu , CFSTR ( " Normal Size " ) , 0 , kNormalScreenCmd , & index ) ;
SetMenuItemCommandKey ( movMenu , index , 0 , ' 1 ' ) ;
2008-11-24 14:28:56 +01:00
2004-10-19 17:04:45 +02:00
AppendMenuItemTextWithCFString ( movMenu , CFSTR ( " Double Size " ) , 0 , kDoubleScreenCmd , & index ) ;
SetMenuItemCommandKey ( movMenu , index , 0 , ' 2 ' ) ;
2008-11-24 14:28:56 +01:00
2004-10-19 17:04:45 +02:00
AppendMenuItemTextWithCFString ( movMenu , CFSTR ( " Full Size " ) , 0 , kFullScreenCmd , & index ) ;
SetMenuItemCommandKey ( movMenu , index , 0 , ' F ' ) ;
2008-11-24 14:28:56 +01:00
2007-11-06 13:12:48 +01:00
AppendMenuItemTextWithCFString ( movMenu , NULL , kMenuItemAttrSeparator , 0 , & index ) ;
2004-10-29 00:03:26 +02:00
2007-11-06 13:12:48 +01:00
AppendMenuItemTextWithCFString ( movMenu , CFSTR ( " Aspect Ratio " ) , 0 , 0 , & index ) ;
2008-11-24 14:28:56 +01:00
2004-10-29 00:03:26 +02:00
////Create Aspect Ratio Sub Menu
CreateNewMenu ( 0 , 0 , & aspectMenu ) ;
aspMenuTitle = CFSTR ( " Aspect Ratio " ) ;
SetMenuTitleWithCFString ( aspectMenu , aspMenuTitle ) ;
SetMenuItemHierarchicalMenu ( movMenu , 6 , aspectMenu ) ;
2008-11-24 14:28:56 +01:00
2004-10-29 00:03:26 +02:00
AppendMenuItemTextWithCFString ( aspectMenu , CFSTR ( " Keep " ) , 0 , kKeepAspectCmd , & index ) ;
CheckMenuItem ( aspectMenu , 1 , vo_keepaspect ) ;
2004-10-29 03:24:14 +02:00
AppendMenuItemTextWithCFString ( aspectMenu , CFSTR ( " Pan-Scan " ) , 0 , kPanScanCmd , & index ) ;
2004-11-01 17:17:49 +01:00
CheckMenuItem ( aspectMenu , 2 , vo_panscan ) ;
2007-11-06 13:12:48 +01:00
AppendMenuItemTextWithCFString ( aspectMenu , NULL , kMenuItemAttrSeparator , 0 , & index ) ;
2004-10-29 00:03:26 +02:00
AppendMenuItemTextWithCFString ( aspectMenu , CFSTR ( " Original " ) , 0 , kAspectOrgCmd , & index ) ;
AppendMenuItemTextWithCFString ( aspectMenu , CFSTR ( " 4:3 " ) , 0 , kAspectFullCmd , & index ) ;
AppendMenuItemTextWithCFString ( aspectMenu , CFSTR ( " 16:9 " ) , 0 , kAspectWideCmd , & index ) ;
2008-11-24 14:28:56 +01:00
2004-10-19 17:04:45 +02:00
InsertMenu ( movMenu , GetMenuID ( windMenu ) ) ; //insert before Window menu
2008-11-24 14:28:56 +01:00
2004-10-19 17:04:45 +02:00
DrawMenuBar ( ) ;
2008-11-24 14:28:56 +01:00
2004-10-19 17:04:45 +02:00
//create window
2004-05-18 22:49:44 +02:00
CreateNewWindow ( kDocumentWindowClass , windowAttrs , & winRect , & theWindow ) ;
2008-11-24 14:28:56 +01:00
2004-07-15 19:36:01 +02:00
CreateWindowGroup ( 0 , & winGroup ) ;
SetWindowGroup ( theWindow , winGroup ) ;
2004-05-18 22:49:44 +02:00
//Set window title
2004-07-09 18:54:57 +02:00
titleKey = CFSTR ( " MPlayer - The Movie Player " ) ;
2004-05-18 22:49:44 +02:00
windowTitle = CFCopyLocalizedString ( titleKey , NULL ) ;
result = SetWindowTitleWithCFString ( theWindow , windowTitle ) ;
CFRelease ( titleKey ) ;
CFRelease ( windowTitle ) ;
2008-11-24 14:28:56 +01:00
2004-05-18 22:49:44 +02:00
//Install event handler
2005-06-09 14:39:52 +02:00
InstallApplicationEventHandler ( NewEventHandlerUPP ( KeyEventHandler ) , GetEventTypeCount ( key_events ) , key_events , NULL , NULL ) ;
InstallApplicationEventHandler ( NewEventHandlerUPP ( MouseEventHandler ) , GetEventTypeCount ( mouse_events ) , mouse_events , NULL , NULL ) ;
InstallWindowEventHandler ( theWindow , NewEventHandlerUPP ( WindowEventHandler ) , GetEventTypeCount ( win_events ) , win_events , theWindow , NULL ) ;
2004-05-18 22:49:44 +02:00
}
2005-08-05 03:24:37 +02:00
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 )
2004-04-05 23:20:19 +02:00
{
2004-04-26 14:17:26 +02:00
WindowAttributes windowAttrs ;
2004-05-04 04:57:10 +02:00
OSErr qterr ;
2005-06-09 14:39:52 +02:00
CGRect tmpBounds ;
2008-11-24 11:01:03 +01:00
CGDisplayCount displayCount ;
CGDirectDisplayID * displays ;
2004-10-21 13:36:20 +02:00
//Get Main device info///////////////////////////////////////////////////
2008-11-24 11:01:03 +01:00
//Display IDs might not be consecutive, get the list of all devices up to # device_id
displayCount = device_id + 1 ;
displays = malloc ( sizeof ( CGDirectDisplayID ) * displayCount ) ;
if ( kCGErrorSuccess ! = CGGetActiveDisplayList ( displayCount , displays , & displayCount ) | | displayCount < device_id + 1 ) {
2004-06-02 02:58:05 +02:00
mp_msg ( MSGT_VO , MSGL_FATAL , " Quartz error: Device ID %d do not exist, falling back to main device. \n " , device_id ) ;
2008-11-24 11:01:03 +01:00
displayId = kCGDirectMainDisplay ;
2005-02-14 22:28:21 +01:00
device_id = 0 ;
2004-06-02 02:58:05 +02:00
}
2008-11-24 11:01:03 +01:00
else
{
displayId = displays [ device_id ] ;
2004-06-02 02:58:05 +02:00
}
2008-11-24 11:01:03 +01:00
free ( displays ) ;
2008-11-24 14:28:56 +01:00
2008-11-24 11:01:03 +01:00
displayRect = CGDisplayBounds ( displayId ) ;
2008-11-24 14:28:56 +01:00
2008-11-24 11:01:03 +01:00
monitor_aspect = ( float ) displayRect . size . width / ( float ) displayRect . size . height ;
2004-10-28 23:48:41 +02:00
2004-04-26 14:17:26 +02:00
//misc mplayer setup/////////////////////////////////////////////////////
2004-05-18 22:49:44 +02:00
SetRect ( & imgRect , 0 , 0 , width , height ) ;
2008-11-24 14:28:56 +01:00
switch ( image_format )
2004-05-04 04:57:10 +02:00
{
case IMGFMT_RGB32 :
2004-05-07 03:44:08 +02:00
image_depth = 32 ;
2004-05-04 04:57:10 +02:00
break ;
case IMGFMT_YV12 :
case IMGFMT_IYUV :
case IMGFMT_I420 :
case IMGFMT_UYVY :
case IMGFMT_YUY2 :
image_depth = 16 ;
break ;
}
2004-05-18 22:49:44 +02:00
image_size = ( ( imgRect . right * imgRect . bottom * image_depth ) + 7 ) / 8 ;
2004-04-26 14:17:26 +02:00
vo_fs = flags & VOFLAG_FULLSCREEN ;
2008-11-24 14:28:56 +01:00
2004-04-26 14:17:26 +02:00
//get movie aspect
2004-10-29 03:24:14 +02:00
panscan_init ( ) ;
2004-04-26 14:17:26 +02:00
aspect_save_orig ( width , height ) ;
aspect_save_prescale ( d_width , d_height ) ;
2008-11-24 11:01:03 +01:00
aspect_save_screenres ( displayRect . size . width , displayRect . size . height ) ;
2008-11-24 14:28:56 +01:00
2004-04-26 14:17:26 +02:00
aspect ( & d_width , & d_height , A_NOZOOM ) ;
2008-11-24 14:28:56 +01:00
2004-10-29 01:06:35 +02:00
movie_aspect = ( float ) d_width / ( float ) d_height ;
old_movie_aspect = movie_aspect ;
2008-11-24 14:28:56 +01:00
2004-08-24 22:42:27 +02:00
if ( image_data )
free ( image_data ) ;
2008-11-24 14:28:56 +01:00
2004-08-24 22:42:27 +02:00
image_data = malloc ( image_size ) ;
2004-04-26 14:17:26 +02:00
//Create player window//////////////////////////////////////////////////
windowAttrs = kWindowStandardDocumentAttributes
| kWindowStandardHandlerAttribute
| kWindowLiveResizeAttribute ;
2008-11-24 14:28:56 +01:00
2005-06-09 14:39:52 +02:00
windowAttrs & = ( ~ kWindowResizableAttribute ) ;
2008-11-24 14:28:56 +01:00
if ( theWindow = = NULL )
2004-05-18 22:49:44 +02:00
{
2008-11-24 11:01:03 +01:00
CGContextRef context ;
2005-06-09 14:39:52 +02:00
quartz_CreateWindow ( d_width , d_height , windowAttrs ) ;
2008-11-24 14:28:56 +01:00
2004-05-18 22:49:44 +02:00
if ( theWindow = = NULL )
{
mp_msg ( MSGT_VO , MSGL_FATAL , " Quartz error: Couldn't create window !!!!! \n " ) ;
return - 1 ;
}
2005-06-09 14:39:52 +02:00
tmpBounds = CGRectMake ( 0 , 0 , winRect . right , winRect . bottom ) ;
2008-11-24 11:01:03 +01:00
QDBeginCGContext ( GetWindowPort ( theWindow ) , & context ) ;
2005-06-09 14:39:52 +02:00
CGContextFillRect ( context , tmpBounds ) ;
2008-11-24 11:01:03 +01:00
QDEndCGContext ( GetWindowPort ( theWindow ) , & context ) ;
2004-05-18 22:49:44 +02:00
}
2008-11-24 14:28:56 +01:00
else
2004-05-18 22:49:44 +02:00
{
HideWindow ( theWindow ) ;
ChangeWindowAttributes ( theWindow , ~ windowAttrs , windowAttrs ) ;
SetRect ( & winRect , 0 , 0 , d_width , d_height ) ;
SetRect ( & oldWinRect , 0 , 0 , d_width , d_height ) ;
SizeWindow ( theWindow , d_width , d_height , 1 ) ;
2008-11-24 14:28:56 +01:00
}
switch ( image_format )
2004-05-07 03:44:08 +02:00
{
2004-08-24 22:42:27 +02:00
case IMGFMT_RGB32 :
{
2008-11-24 11:01:03 +01:00
CGContextRef context ;
2008-11-24 14:28:56 +01:00
2008-11-24 11:01:03 +01:00
QDBeginCGContext ( GetWindowPort ( theWindow ) , & context ) ;
2008-11-24 14:28:56 +01:00
2004-08-24 22:42:27 +02:00
dataProviderRef = CGDataProviderCreateWithData ( 0 , image_data , imgRect . right * imgRect . bottom * 4 , 0 ) ;
2008-11-24 14:28:56 +01:00
2004-08-24 22:42:27 +02:00
image = CGImageCreate ( imgRect . right ,
imgRect . bottom ,
8 ,
image_depth ,
( ( imgRect . right * 32 ) + 7 ) / 8 ,
CGColorSpaceCreateDeviceRGB ( ) ,
kCGImageAlphaNoneSkipFirst ,
dataProviderRef , 0 , 1 , kCGRenderingIntentDefault ) ;
2008-11-24 11:01:03 +01:00
QDEndCGContext ( GetWindowPort ( theWindow ) , & context ) ;
2004-08-24 22:42:27 +02:00
break ;
}
2008-11-24 14:28:56 +01:00
2004-05-07 03:44:08 +02:00
case IMGFMT_YV12 :
case IMGFMT_IYUV :
case IMGFMT_I420 :
case IMGFMT_UYVY :
case IMGFMT_YUY2 :
{
2008-11-24 14:28:56 +01:00
get_image_done = 0 ;
2004-06-23 14:16:34 +02:00
if ( ! EnterMoviesDone )
{
qterr = EnterMovies ( ) ;
EnterMoviesDone = 1 ;
}
else
qterr = 0 ;
2008-11-24 14:28:56 +01:00
2004-06-23 14:16:34 +02:00
if ( qterr )
{
mp_msg ( MSGT_VO , MSGL_FATAL , " Quartz error: EnterMovies (%d) \n " , qterr ) ;
return - 1 ;
}
2008-11-24 14:28:56 +01:00
2004-06-23 14:16:34 +02:00
SetIdentityMatrix ( & matrix ) ;
2008-11-24 14:28:56 +01:00
2004-06-23 14:16:34 +02:00
if ( ( d_width ! = width ) | | ( d_height ! = height ) )
{
ScaleMatrix ( & matrix , FixDiv ( Long2Fix ( d_width ) , Long2Fix ( width ) ) , FixDiv ( Long2Fix ( d_height ) , Long2Fix ( height ) ) , 0 , 0 ) ;
2008-11-24 14:28:56 +01:00
}
2004-06-23 14:16:34 +02:00
2004-05-07 03:44:08 +02:00
yuv_qt_stuff . desc = ( ImageDescriptionHandle ) NewHandleClear ( sizeof ( ImageDescription ) ) ;
2008-11-24 14:28:56 +01:00
2004-05-07 03:44:08 +02:00
yuv_qt_stuff . extension_colr = NewHandleClear ( sizeof ( NCLCColorInfoImageDescriptionExtension ) ) ;
( ( NCLCColorInfoImageDescriptionExtension * ) ( * yuv_qt_stuff . extension_colr ) ) - > colorParamType = kVideoColorInfoImageDescriptionExtensionType ;
( ( NCLCColorInfoImageDescriptionExtension * ) ( * yuv_qt_stuff . extension_colr ) ) - > primaries = 2 ;
( ( NCLCColorInfoImageDescriptionExtension * ) ( * yuv_qt_stuff . extension_colr ) ) - > transferFunction = 2 ;
( ( NCLCColorInfoImageDescriptionExtension * ) ( * yuv_qt_stuff . extension_colr ) ) - > matrix = 2 ;
2008-11-24 14:28:56 +01:00
2004-05-07 03:44:08 +02:00
yuv_qt_stuff . extension_fiel = NewHandleClear ( sizeof ( FieldInfoImageDescriptionExtension ) ) ;
( ( FieldInfoImageDescriptionExtension * ) ( * yuv_qt_stuff . extension_fiel ) ) - > fieldCount = 1 ;
( ( FieldInfoImageDescriptionExtension * ) ( * yuv_qt_stuff . extension_fiel ) ) - > fieldOrderings = 0 ;
2008-11-24 14:28:56 +01:00
2004-05-07 03:44:08 +02:00
yuv_qt_stuff . extension_clap = NewHandleClear ( sizeof ( CleanApertureImageDescriptionExtension ) ) ;
2004-05-18 22:49:44 +02:00
( ( CleanApertureImageDescriptionExtension * ) ( * yuv_qt_stuff . extension_clap ) ) - > cleanApertureWidthN = imgRect . right ;
2004-05-07 03:44:08 +02:00
( ( CleanApertureImageDescriptionExtension * ) ( * yuv_qt_stuff . extension_clap ) ) - > cleanApertureWidthD = 1 ;
2004-05-18 22:49:44 +02:00
( ( CleanApertureImageDescriptionExtension * ) ( * yuv_qt_stuff . extension_clap ) ) - > cleanApertureHeightN = imgRect . bottom ;
2004-05-07 03:44:08 +02:00
( ( CleanApertureImageDescriptionExtension * ) ( * yuv_qt_stuff . extension_clap ) ) - > cleanApertureHeightD = 1 ;
( ( CleanApertureImageDescriptionExtension * ) ( * yuv_qt_stuff . extension_clap ) ) - > horizOffN = 0 ;
( ( CleanApertureImageDescriptionExtension * ) ( * yuv_qt_stuff . extension_clap ) ) - > horizOffD = 1 ;
( ( CleanApertureImageDescriptionExtension * ) ( * yuv_qt_stuff . extension_clap ) ) - > vertOffN = 0 ;
( ( CleanApertureImageDescriptionExtension * ) ( * yuv_qt_stuff . extension_clap ) ) - > vertOffD = 1 ;
2008-11-24 14:28:56 +01:00
2004-05-07 03:44:08 +02:00
yuv_qt_stuff . extension_pasp = NewHandleClear ( sizeof ( PixelAspectRatioImageDescriptionExtension ) ) ;
( ( PixelAspectRatioImageDescriptionExtension * ) ( * yuv_qt_stuff . extension_pasp ) ) - > hSpacing = 1 ;
( ( PixelAspectRatioImageDescriptionExtension * ) ( * yuv_qt_stuff . extension_pasp ) ) - > vSpacing = 1 ;
( * yuv_qt_stuff . desc ) - > idSize = sizeof ( ImageDescription ) ;
( * yuv_qt_stuff . desc ) - > cType = image_qtcodec ;
( * yuv_qt_stuff . desc ) - > version = 2 ;
( * yuv_qt_stuff . desc ) - > revisionLevel = 0 ;
( * yuv_qt_stuff . desc ) - > vendor = ' mpla ' ;
2004-05-18 22:49:44 +02:00
( * yuv_qt_stuff . desc ) - > width = imgRect . right ;
( * yuv_qt_stuff . desc ) - > height = imgRect . bottom ;
2004-05-07 03:44:08 +02:00
( * yuv_qt_stuff . desc ) - > hRes = Long2Fix ( 72 ) ;
( * yuv_qt_stuff . desc ) - > vRes = Long2Fix ( 72 ) ;
( * yuv_qt_stuff . desc ) - > temporalQuality = 0 ;
( * yuv_qt_stuff . desc ) - > spatialQuality = codecLosslessQuality ;
( * yuv_qt_stuff . desc ) - > frameCount = 1 ;
( * yuv_qt_stuff . desc ) - > dataSize = 0 ;
( * yuv_qt_stuff . desc ) - > depth = 24 ;
( * yuv_qt_stuff . desc ) - > clutID = - 1 ;
2008-11-24 14:28:56 +01:00
2004-05-07 03:44:08 +02:00
qterr = AddImageDescriptionExtension ( yuv_qt_stuff . desc , yuv_qt_stuff . extension_colr , kColorInfoImageDescriptionExtension ) ;
2004-05-05 03:04:44 +02:00
if ( qterr )
{
2004-05-18 22:49:44 +02:00
mp_msg ( MSGT_VO , MSGL_ERR , " Quartz error: AddImageDescriptionExtension [colr] (%d) \n " , qterr ) ;
2004-05-05 03:04:44 +02:00
}
2008-11-24 14:28:56 +01:00
2004-05-07 03:44:08 +02:00
qterr = AddImageDescriptionExtension ( yuv_qt_stuff . desc , yuv_qt_stuff . extension_fiel , kFieldInfoImageDescriptionExtension ) ;
if ( qterr )
2004-05-05 03:04:44 +02:00
{
2004-05-18 22:49:44 +02:00
mp_msg ( MSGT_VO , MSGL_ERR , " Quartz error: AddImageDescriptionExtension [fiel] (%d) \n " , qterr ) ;
2004-05-05 03:04:44 +02:00
}
2008-11-24 14:28:56 +01:00
2004-05-07 03:44:08 +02:00
qterr = AddImageDescriptionExtension ( yuv_qt_stuff . desc , yuv_qt_stuff . extension_clap , kCleanApertureImageDescriptionExtension ) ;
if ( qterr )
{
2004-05-18 22:49:44 +02:00
mp_msg ( MSGT_VO , MSGL_ERR , " Quartz error: AddImageDescriptionExtension [clap] (%d) \n " , qterr ) ;
2004-05-07 03:44:08 +02:00
}
2008-11-24 14:28:56 +01:00
2004-05-07 03:44:08 +02:00
qterr = AddImageDescriptionExtension ( yuv_qt_stuff . desc , yuv_qt_stuff . extension_pasp , kCleanApertureImageDescriptionExtension ) ;
if ( qterr )
{
2004-05-18 22:49:44 +02:00
mp_msg ( MSGT_VO , MSGL_ERR , " Quartz error: AddImageDescriptionExtension [pasp] (%d) \n " , qterr ) ;
}
if ( P ! = NULL ) { // second or subsequent movie
free ( P ) ;
2004-05-07 03:44:08 +02:00
}
P = calloc ( sizeof ( PlanarPixmapInfoYUV420 ) + image_size , 1 ) ;
switch ( image_format )
{
case IMGFMT_YV12 :
case IMGFMT_IYUV :
case IMGFMT_I420 :
2007-06-29 23:57:31 +02:00
P - > componentInfoY . offset = be2me_32 ( sizeof ( PlanarPixmapInfoYUV420 ) ) ;
P - > componentInfoCb . offset = be2me_32 ( be2me_32 ( P - > componentInfoY . offset ) + image_size / 2 ) ;
P - > componentInfoCr . offset = be2me_32 ( be2me_32 ( P - > componentInfoCb . offset ) + image_size / 4 ) ;
P - > componentInfoY . rowBytes = be2me_32 ( imgRect . right ) ;
P - > componentInfoCb . rowBytes = be2me_32 ( imgRect . right / 2 ) ;
P - > componentInfoCr . rowBytes = be2me_32 ( imgRect . right / 2 ) ;
2004-05-07 03:44:08 +02:00
image_buffer_size = image_size + sizeof ( PlanarPixmapInfoYUV420 ) ;
break ;
case IMGFMT_UYVY :
case IMGFMT_YUY2 :
image_buffer_size = image_size ;
break ;
}
2004-05-04 04:57:10 +02:00
2004-05-07 03:44:08 +02:00
qterr = DecompressSequenceBeginS ( & seqId ,
2004-05-04 04:57:10 +02:00
yuv_qt_stuff . desc ,
2004-05-07 03:44:08 +02:00
( char * ) P ,
2004-05-04 04:57:10 +02:00
image_buffer_size ,
2004-06-23 14:16:34 +02:00
GetWindowPort ( theWindow ) ,
2004-05-07 03:44:08 +02:00
NULL ,
NULL ,
2008-11-24 14:28:56 +01:00
( ( d_width ! = width ) | | ( d_height ! = height ) ) ?
2004-05-07 03:44:08 +02:00
& matrix : NULL ,
2004-05-04 04:57:10 +02:00
srcCopy ,
2004-05-07 03:44:08 +02:00
NULL ,
0 ,
2004-05-04 04:57:10 +02:00
codecLosslessQuality ,
bestSpeedCodec ) ;
2004-05-07 03:44:08 +02:00
if ( qterr )
{
mp_msg ( MSGT_VO , MSGL_FATAL , " Quartz error: DecompressSequenceBeginS (%d) \n " , qterr ) ;
2004-05-18 22:49:44 +02:00
return - 1 ;
2004-05-07 03:44:08 +02:00
}
2004-05-05 03:04:44 +02:00
}
2004-05-07 03:44:08 +02:00
break ;
2004-05-04 04:57:10 +02:00
}
2008-11-24 14:28:56 +01:00
2005-07-02 15:28:25 +02:00
//Show window
RepositionWindow ( theWindow , NULL , kWindowCenterOnMainScreen ) ;
ShowWindow ( theWindow ) ;
2008-11-24 14:28:56 +01:00
2004-04-26 14:17:26 +02:00
if ( vo_fs )
window_fullscreen ( ) ;
2008-11-24 14:28:56 +01:00
2004-04-26 14:17:26 +02:00
if ( vo_ontop )
window_ontop ( ) ;
2008-11-24 14:28:56 +01:00
2004-07-29 16:59:48 +02:00
if ( vo_rootwin )
2004-07-23 15:02:40 +02:00
{
vo_fs = TRUE ;
winLevel = 0 ;
SetWindowGroupLevel ( winGroup , CGWindowLevelForKey ( levelList [ winLevel ] ) ) ;
window_fullscreen ( ) ;
}
2008-11-24 14:28:56 +01:00
2005-07-02 15:28:25 +02:00
window_resized ( ) ;
2008-11-24 14:28:56 +01:00
2004-04-26 14:17:26 +02:00
return 0 ;
2004-04-05 23:20:19 +02:00
}
2004-04-26 14:17:26 +02:00
static void check_events ( void )
2004-04-05 23:20:19 +02:00
{
2004-04-26 14:17:26 +02:00
EventRef theEvent ;
EventTargetRef theTarget ;
OSStatus theErr ;
2008-11-24 14:28:56 +01:00
2004-04-26 14:17:26 +02:00
//Get event
theTarget = GetEventDispatcherTarget ( ) ;
theErr = ReceiveNextEvent ( 0 , 0 , kEventDurationNoWait , true , & theEvent ) ;
if ( theErr = = noErr & & theEvent ! = NULL )
{
SendEventToEventTarget ( theEvent , theTarget ) ;
ReleaseEvent ( theEvent ) ;
}
}
2004-04-05 23:20:19 +02:00
2004-04-26 14:17:26 +02:00
static void draw_osd ( void )
{
2004-05-18 22:49:44 +02:00
vo_draw_text ( imgRect . right , imgRect . bottom , draw_alpha ) ;
2004-04-26 14:17:26 +02:00
}
2004-04-05 23:20:19 +02:00
2004-04-26 14:17:26 +02:00
static void flip_page ( void )
{
2006-12-01 16:04:46 +01:00
int curTime ;
2004-10-20 18:38:33 +02:00
if ( theWindow = = NULL )
return ;
2008-11-24 14:28:56 +01:00
switch ( image_format )
2004-04-26 14:17:26 +02:00
{
2004-08-24 22:42:27 +02:00
case IMGFMT_RGB32 :
{
2008-11-24 11:01:03 +01:00
CGContextRef context ;
QDBeginCGContext ( GetWindowPort ( theWindow ) , & context ) ;
2004-08-24 22:42:27 +02:00
CGContextDrawImage ( context , bounds , image ) ;
2008-11-24 11:01:03 +01:00
QDEndCGContext ( GetWindowPort ( theWindow ) , & context ) ;
2004-08-24 22:42:27 +02:00
}
break ;
2008-11-24 14:28:56 +01:00
2004-05-07 04:34:22 +02:00
case IMGFMT_YV12 :
case IMGFMT_IYUV :
case IMGFMT_I420 :
case IMGFMT_UYVY :
case IMGFMT_YUY2 :
if ( EnterMoviesDone )
{
OSErr qterr ;
CodecFlags flags = 0 ;
qterr = DecompressSequenceFrameWhen ( seqId ,
( char * ) P ,
image_buffer_size ,
0 , //codecFlagUseImageBuffer,
& flags ,
NULL ,
NULL ) ;
if ( qterr )
{
2004-05-18 22:49:44 +02:00
mp_msg ( MSGT_VO , MSGL_ERR , " Quartz error: DecompressSequenceFrameWhen in flip_page (%d) flags:0x%08x \n " , qterr , flags ) ;
2004-05-07 04:34:22 +02:00
}
}
break ;
}
2008-11-24 14:28:56 +01:00
2005-06-14 14:48:39 +02:00
if ( ! vo_quartz_fs )
{
2008-11-24 11:01:03 +01:00
CGContextRef context ;
2008-11-24 14:28:56 +01:00
2008-11-24 11:01:03 +01:00
QDBeginCGContext ( GetWindowPort ( theWindow ) , & context ) ;
2005-06-14 14:48:39 +02:00
//render resize box
CGContextBeginPath ( context ) ;
CGContextSetAllowsAntialiasing ( context , false ) ;
//CGContextSaveGState(context);
2008-11-24 14:28:56 +01:00
2005-06-14 14:48:39 +02:00
//line white
CGContextSetRGBStrokeColor ( context , 0.2 , 0.2 , 0.2 , 0.5 ) ;
2008-11-24 14:28:56 +01:00
CGContextMoveToPoint ( context , winRect . right - 1 , 1 ) ; CGContextAddLineToPoint ( context , winRect . right - 1 , 1 ) ;
2005-06-14 14:48:39 +02:00
CGContextMoveToPoint ( context , winRect . right - 1 , 5 ) ; CGContextAddLineToPoint ( context , winRect . right - 5 , 1 ) ;
CGContextMoveToPoint ( context , winRect . right - 1 , 9 ) ; CGContextAddLineToPoint ( context , winRect . right - 9 , 1 ) ;
CGContextStrokePath ( context ) ;
//line gray
CGContextSetRGBStrokeColor ( context , 0.4 , 0.4 , 0.4 , 0.5 ) ;
2008-11-24 14:28:56 +01:00
CGContextMoveToPoint ( context , winRect . right - 1 , 2 ) ; CGContextAddLineToPoint ( context , winRect . right - 2 , 1 ) ;
2005-06-14 14:48:39 +02:00
CGContextMoveToPoint ( context , winRect . right - 1 , 6 ) ; CGContextAddLineToPoint ( context , winRect . right - 6 , 1 ) ;
CGContextMoveToPoint ( context , winRect . right - 1 , 10 ) ; CGContextAddLineToPoint ( context , winRect . right - 10 , 1 ) ;
CGContextStrokePath ( context ) ;
2008-11-24 14:28:56 +01:00
2005-06-14 14:48:39 +02:00
//line black
CGContextSetRGBStrokeColor ( context , 0.6 , 0.6 , 0.6 , 0.5 ) ;
2008-11-24 14:28:56 +01:00
CGContextMoveToPoint ( context , winRect . right - 1 , 3 ) ; CGContextAddLineToPoint ( context , winRect . right - 3 , 1 ) ;
2005-06-14 14:48:39 +02:00
CGContextMoveToPoint ( context , winRect . right - 1 , 7 ) ; CGContextAddLineToPoint ( context , winRect . right - 7 , 1 ) ;
CGContextMoveToPoint ( context , winRect . right - 1 , 11 ) ; CGContextAddLineToPoint ( context , winRect . right - 11 , 1 ) ;
CGContextStrokePath ( context ) ;
2008-11-24 14:28:56 +01:00
2005-06-14 14:48:39 +02:00
//CGContextRestoreGState( context );
CGContextFlush ( context ) ;
2008-11-24 11:01:03 +01:00
QDEndCGContext ( GetWindowPort ( theWindow ) , & context ) ;
2005-06-14 14:48:39 +02:00
}
2005-07-01 19:21:13 +02:00
2008-11-24 11:01:03 +01:00
curTime = TickCount ( ) / 60 ;
//auto hide mouse cursor (and future on-screen control?)
2005-07-01 19:21:13 +02:00
if ( vo_quartz_fs & & ! mouseHide )
{
2008-11-24 11:01:03 +01:00
if ( ( ( curTime - lastMouseHide ) > = 5 ) | | ( lastMouseHide = = 0 ) )
2005-07-01 19:21:13 +02:00
{
2008-11-24 11:01:03 +01:00
CGDisplayHideCursor ( displayId ) ;
2005-07-01 19:21:13 +02:00
mouseHide = TRUE ;
2008-11-24 11:01:03 +01:00
lastMouseHide = curTime ;
2005-07-01 19:21:13 +02:00
}
}
2006-02-07 02:36:32 +01:00
//update activity every 30 seconds to prevent
//screensaver from starting up.
2008-11-24 11:01:03 +01:00
if ( ( ( curTime - lastScreensaverUpdate ) > = 30 ) | | ( lastScreensaverUpdate = = 0 ) )
2006-02-07 02:36:32 +01:00
{
UpdateSystemActivity ( UsrActivity ) ;
2008-11-24 11:01:03 +01:00
lastScreensaverUpdate = curTime ;
2006-02-07 02:36:32 +01:00
}
2004-04-05 23:20:19 +02:00
}
2005-08-05 03:24:37 +02:00
static int draw_slice ( uint8_t * src [ ] , int stride [ ] , int w , int h , int x , int y )
2004-04-05 23:20:19 +02:00
{
2004-05-07 04:34:22 +02:00
switch ( image_format )
{
2008-11-24 14:28:56 +01:00
case IMGFMT_YV12 :
case IMGFMT_I420 :
memcpy_pic ( ( ( char * ) P ) + be2me_32 ( P - > componentInfoY . offset ) + x + imgRect . right * y , src [ 0 ] , w , h , imgRect . right , stride [ 0 ] ) ;
x = x / 2 ; y = y / 2 ; w = w / 2 ; h = h / 2 ;
memcpy_pic ( ( ( char * ) P ) + be2me_32 ( P - > componentInfoCb . offset ) + x + imgRect . right / 2 * y , src [ 1 ] , w , h , imgRect . right / 2 , stride [ 1 ] ) ;
memcpy_pic ( ( ( char * ) P ) + be2me_32 ( P - > componentInfoCr . offset ) + x + imgRect . right / 2 * y , src [ 2 ] , w , h , imgRect . right / 2 , stride [ 2 ] ) ;
return 0 ;
case IMGFMT_IYUV :
memcpy_pic ( ( ( char * ) P ) + be2me_32 ( P - > componentInfoY . offset ) + x + imgRect . right * y , src [ 0 ] , w , h , imgRect . right , stride [ 0 ] ) ;
x = x / 2 ; y = y / 2 ; w = w / 2 ; h = h / 2 ;
memcpy_pic ( ( ( char * ) P ) + be2me_32 ( P - > componentInfoCr . offset ) + x + imgRect . right / 2 * y , src [ 1 ] , w , h , imgRect . right / 2 , stride [ 1 ] ) ;
memcpy_pic ( ( ( char * ) P ) + be2me_32 ( P - > componentInfoCb . offset ) + x + imgRect . right / 2 * y , src [ 2 ] , w , h , imgRect . right / 2 , stride [ 2 ] ) ;
return 0 ;
2004-05-07 04:34:22 +02:00
}
2004-04-26 14:17:26 +02:00
return - 1 ;
}
2004-04-05 23:20:19 +02:00
2005-08-05 03:24:37 +02:00
static int draw_frame ( uint8_t * src [ ] )
2004-04-26 14:17:26 +02:00
{
2004-05-07 04:34:22 +02:00
switch ( image_format )
{
2004-08-24 22:42:27 +02:00
case IMGFMT_RGB32 :
2007-06-05 16:27:54 +02:00
fast_memcpy ( image_data , src [ 0 ] , image_size ) ;
2004-08-24 22:42:27 +02:00
return 0 ;
2008-11-24 14:28:56 +01:00
2004-05-07 04:34:22 +02:00
case IMGFMT_UYVY :
case IMGFMT_YUY2 :
2004-05-18 22:49:44 +02:00
memcpy_pic ( ( ( char * ) P ) , src [ 0 ] , imgRect . right * 2 , imgRect . bottom , imgRect . right * 2 , imgRect . right * 2 ) ;
2004-05-07 04:34:22 +02:00
return 0 ;
}
return - 1 ;
2004-04-05 23:20:19 +02:00
}
2005-08-05 03:24:37 +02:00
static int query_format ( uint32_t format )
2004-04-05 23:20:19 +02:00
{
2004-04-26 14:17:26 +02:00
image_format = format ;
2004-05-07 03:44:08 +02:00
image_qtcodec = 0 ;
2004-08-24 22:42:27 +02:00
if ( format = = IMGFMT_RGB32 )
{
return VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN ;
}
2008-11-24 14:28:56 +01:00
2004-05-05 03:04:44 +02:00
if ( ( format = = IMGFMT_YV12 ) | | ( format = = IMGFMT_IYUV ) | | ( format = = IMGFMT_I420 ) )
{
image_qtcodec = kMpegYUV420CodecType ; //kYUV420CodecType ?;
2004-05-18 22:49:44 +02:00
return VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_ACCEPT_STRIDE ;
2004-05-04 04:57:10 +02:00
}
2004-05-05 03:04:44 +02:00
if ( format = = IMGFMT_YUY2 )
{
image_qtcodec = kComponentVideoUnsigned ;
2004-05-18 22:49:44 +02:00
return VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN ;
2004-05-04 04:57:10 +02:00
}
2008-11-24 14:28:56 +01:00
2004-05-05 03:04:44 +02:00
if ( format = = IMGFMT_UYVY )
{
image_qtcodec = k422YpCbCr8CodecType ;
2004-05-18 22:49:44 +02:00
return VFCAP_CSP_SUPPORTED | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN ;
2004-05-05 03:04:44 +02:00
}
2004-05-04 04:57:10 +02:00
2004-04-26 14:17:26 +02:00
return 0 ;
2004-04-05 23:20:19 +02:00
}
2004-04-26 14:17:26 +02:00
static void uninit ( void )
2004-04-05 23:20:19 +02:00
{
2004-05-07 03:44:08 +02:00
OSErr qterr ;
2008-11-24 14:28:56 +01:00
2004-08-24 22:42:27 +02:00
switch ( image_format )
2004-05-05 03:04:44 +02:00
{
2004-08-24 22:42:27 +02:00
case IMGFMT_YV12 :
case IMGFMT_IYUV :
case IMGFMT_I420 :
case IMGFMT_UYVY :
case IMGFMT_YUY2 :
2004-05-05 03:04:44 +02:00
{
2004-08-24 22:42:27 +02:00
if ( EnterMoviesDone )
{
qterr = CDSequenceEnd ( seqId ) ;
if ( qterr )
{
mp_msg ( MSGT_VO , MSGL_ERR , " Quartz error: CDSequenceEnd (%d) \n " , qterr ) ;
}
}
break ;
2004-05-05 03:04:44 +02:00
}
2004-08-24 22:42:27 +02:00
default :
break ;
2004-05-04 04:57:10 +02:00
}
2004-05-07 03:44:08 +02:00
2004-04-26 14:17:26 +02:00
ShowMenuBar ( ) ;
2004-04-05 23:20:19 +02:00
}
2005-08-05 03:24:37 +02:00
static int preinit ( const char * arg )
2004-04-05 23:20:19 +02:00
{
2004-06-02 02:58:05 +02:00
int parse_err = 0 ;
2008-11-24 14:28:56 +01:00
if ( arg )
2004-06-02 02:58:05 +02:00
{
2004-06-23 14:16:34 +02:00
char * parse_pos = ( char * ) & arg [ 0 ] ;
2008-11-24 14:28:56 +01:00
while ( parse_pos [ 0 ] & & ! parse_err )
2004-06-02 02:58:05 +02:00
{
if ( strncmp ( parse_pos , " device_id= " , 10 ) = = 0 )
{
parse_pos = & parse_pos [ 10 ] ;
device_id = strtol ( parse_pos , & parse_pos , 0 ) ;
}
2004-10-28 16:52:47 +02:00
if ( strncmp ( parse_pos , " fs_res= " , 7 ) = = 0 )
{
parse_pos = & parse_pos [ 7 ] ;
fs_res_x = strtol ( parse_pos , & parse_pos , 0 ) ;
parse_pos = & parse_pos [ 1 ] ;
fs_res_y = strtol ( parse_pos , & parse_pos , 0 ) ;
}
2004-06-02 02:58:05 +02:00
if ( parse_pos [ 0 ] = = ' : ' ) parse_pos = & parse_pos [ 1 ] ;
else if ( parse_pos [ 0 ] ) parse_err = 1 ;
}
}
2008-11-24 14:28:56 +01:00
2008-08-07 14:20:50 +02:00
# if !defined (CONFIG_MACOSX_FINDER) || !defined (CONFIG_SDL)
2008-11-24 14:28:56 +01:00
//this chunk of code is heavily based off SDL_macosx.m from SDL
2008-11-24 11:01:03 +01:00
//the CPSEnableForegroundOperation that was here before is private and shouldn't be used
//replaced by a call to the 10.3+ TransformProcessType
2007-11-06 13:12:48 +01:00
{
2004-07-09 18:54:57 +02:00
ProcessSerialNumber myProc , frProc ;
Boolean sameProc ;
2008-11-24 14:28:56 +01:00
2004-07-09 18:54:57 +02:00
if ( GetFrontProcess ( & frProc ) = = noErr )
{
if ( GetCurrentProcess ( & myProc ) = = noErr )
{
if ( SameProcess ( & frProc , & myProc , & sameProc ) = = noErr & & ! sameProc )
{
2008-11-24 11:01:03 +01:00
TransformProcessType ( & myProc , kProcessTransformToForegroundApplication ) ;
2004-07-09 18:54:57 +02:00
}
SetFrontProcess ( & myProc ) ;
}
}
2007-11-06 13:12:48 +01:00
}
2004-11-10 17:43:40 +01:00
# endif
2004-07-09 18:54:57 +02:00
2004-04-26 14:17:26 +02:00
return 0 ;
2004-04-05 23:20:19 +02:00
}
2004-05-05 03:04:44 +02:00
static uint32_t draw_yuv_image ( mp_image_t * mpi )
{
// ATM we're only called for planar IMGFMT
// drawing is done directly in P
// and displaying is in flip_page.
2008-11-24 14:28:56 +01:00
return get_image_done ? VO_TRUE : VO_FALSE ;
2004-05-04 04:57:10 +02:00
}
2004-05-05 03:04:44 +02:00
static uint32_t get_yuv_image ( mp_image_t * mpi )
{
if ( mpi - > type ! = MP_IMGTYPE_EXPORT ) return VO_FALSE ;
2008-11-24 14:28:56 +01:00
2004-05-05 03:04:44 +02:00
if ( mpi - > imgfmt ! = image_format ) return VO_FALSE ;
2008-11-24 14:28:56 +01:00
2004-05-05 03:04:44 +02:00
if ( mpi - > flags & MP_IMGFLAG_PLANAR )
{
if ( mpi - > num_planes ! = 3 )
{
mp_msg ( MSGT_VO , MSGL_ERR , " Quartz error: only 3 planes allowed in get_yuv_image for planar (%d) \n " , mpi - > num_planes ) ;
return VO_FALSE ;
}
2004-05-04 04:57:10 +02:00
2007-06-29 23:57:31 +02:00
mpi - > planes [ 0 ] = ( ( char * ) P ) + be2me_32 ( P - > componentInfoY . offset ) ;
2004-05-18 22:49:44 +02:00
mpi - > stride [ 0 ] = imgRect . right ;
mpi - > width = imgRect . right ;
2004-05-04 04:57:10 +02:00
2004-05-05 03:04:44 +02:00
if ( mpi - > flags & MP_IMGFLAG_SWAPPED )
{
// I420
2007-06-29 23:57:31 +02:00
mpi - > planes [ 1 ] = ( ( char * ) P ) + be2me_32 ( P - > componentInfoCb . offset ) ;
mpi - > planes [ 2 ] = ( ( char * ) P ) + be2me_32 ( P - > componentInfoCr . offset ) ;
2004-05-18 22:49:44 +02:00
mpi - > stride [ 1 ] = imgRect . right / 2 ;
mpi - > stride [ 2 ] = imgRect . right / 2 ;
2008-11-24 14:28:56 +01:00
}
else
2004-05-05 03:04:44 +02:00
{
// YV12
2007-06-29 23:57:31 +02:00
mpi - > planes [ 1 ] = ( ( char * ) P ) + be2me_32 ( P - > componentInfoCr . offset ) ;
mpi - > planes [ 2 ] = ( ( char * ) P ) + be2me_32 ( P - > componentInfoCb . offset ) ;
2004-05-18 22:49:44 +02:00
mpi - > stride [ 1 ] = imgRect . right / 2 ;
mpi - > stride [ 2 ] = imgRect . right / 2 ;
2004-05-05 03:04:44 +02:00
}
2008-11-24 14:28:56 +01:00
2004-05-05 03:04:44 +02:00
mpi - > flags | = MP_IMGFLAG_DIRECT ;
2004-05-18 22:49:44 +02:00
get_image_done = 1 ;
2004-05-05 03:04:44 +02:00
return VO_TRUE ;
}
2008-11-24 14:28:56 +01:00
else
{
2004-05-07 04:34:22 +02:00
// doesn't work yet
2004-05-05 03:04:44 +02:00
if ( mpi - > num_planes ! = 1 )
{
mp_msg ( MSGT_VO , MSGL_ERR , " Quartz error: only 1 plane allowed in get_yuv_image for packed (%d) \n " , mpi - > num_planes ) ;
return VO_FALSE ;
}
mpi - > planes [ 0 ] = ( char * ) P ;
2004-05-18 22:49:44 +02:00
mpi - > stride [ 0 ] = imgRect . right * 2 ;
mpi - > width = imgRect . right ;
2004-05-05 03:04:44 +02:00
mpi - > flags | = MP_IMGFLAG_DIRECT ;
2004-05-18 22:49:44 +02:00
get_image_done = 1 ;
2004-05-05 03:04:44 +02:00
return VO_TRUE ;
}
return VO_FALSE ;
2004-05-04 04:57:10 +02:00
}
2005-08-05 03:24:37 +02:00
static int control ( uint32_t request , void * data , . . . )
2004-04-05 23:20:19 +02:00
{
2004-05-05 03:04:44 +02:00
switch ( request )
{
2008-05-16 10:33:27 +02:00
case VOCTRL_PAUSE : return int_pause = 1 ;
case VOCTRL_RESUME : return int_pause = 0 ;
2004-05-12 22:47:14 +02:00
case VOCTRL_FULLSCREEN : vo_fs = ( ! ( vo_fs ) ) ; window_fullscreen ( ) ; return VO_TRUE ;
case VOCTRL_ONTOP : vo_ontop = ( ! ( vo_ontop ) ) ; window_ontop ( ) ; return VO_TRUE ;
2004-05-05 03:04:44 +02:00
case VOCTRL_QUERY_FORMAT : return query_format ( * ( ( uint32_t * ) data ) ) ;
2004-10-29 03:24:14 +02:00
case VOCTRL_GET_PANSCAN : return VO_TRUE ;
2004-11-01 17:17:49 +01:00
case VOCTRL_SET_PANSCAN : window_panscan ( ) ; return VO_TRUE ;
2008-11-24 14:28:56 +01:00
2004-05-05 03:04:44 +02:00
case VOCTRL_GET_IMAGE :
switch ( image_format )
{
case IMGFMT_YV12 :
case IMGFMT_IYUV :
case IMGFMT_I420 :
2004-05-18 22:49:44 +02:00
case IMGFMT_UYVY :
case IMGFMT_YUY2 :
2004-05-05 03:04:44 +02:00
return get_yuv_image ( data ) ;
break ;
2004-05-18 22:49:44 +02:00
default :
break ;
2004-05-05 03:04:44 +02:00
}
case VOCTRL_DRAW_IMAGE :
switch ( image_format )
{
case IMGFMT_YV12 :
case IMGFMT_IYUV :
case IMGFMT_I420 :
2004-05-18 22:49:44 +02:00
case IMGFMT_UYVY :
case IMGFMT_YUY2 :
2004-05-05 03:04:44 +02:00
return draw_yuv_image ( data ) ;
break ;
2004-05-18 22:49:44 +02:00
default :
break ;
2004-05-05 03:04:44 +02:00
}
}
return VO_NOTIMPL ;
2004-04-05 23:20:19 +02:00
}
2004-04-26 14:17:26 +02:00
void window_resized ( )
2004-04-05 23:20:19 +02:00
{
2004-04-26 14:17:26 +02:00
float aspectX ;
float aspectY ;
2008-11-24 14:28:56 +01:00
2004-11-02 19:16:41 +01:00
int padding = 0 ;
2008-11-24 14:28:56 +01:00
2004-04-26 14:17:26 +02:00
uint32_t d_width ;
uint32_t d_height ;
2008-11-24 14:28:56 +01:00
2004-10-27 23:20:11 +02:00
CGRect tmpBounds ;
2004-10-22 02:28:03 +02:00
2008-11-24 11:01:03 +01:00
CGContextRef context ;
GetWindowPortBounds ( theWindow , & winRect ) ;
2004-04-26 14:17:26 +02:00
2004-10-29 00:03:26 +02:00
if ( vo_keepaspect )
{
2004-04-26 14:17:26 +02:00
aspect ( & d_width , & d_height , A_NOZOOM ) ;
2004-10-29 00:03:26 +02:00
d_height = ( ( float ) d_width / movie_aspect ) ;
2008-11-24 14:28:56 +01:00
2004-04-26 14:17:26 +02:00
aspectX = ( float ) ( ( float ) winRect . right / ( float ) d_width ) ;
2005-06-09 14:39:52 +02:00
aspectY = ( float ) ( ( float ) ( winRect . bottom ) / ( float ) d_height ) ;
2008-11-24 14:28:56 +01:00
2005-06-09 14:39:52 +02:00
if ( ( d_height * aspectX ) > ( winRect . bottom ) )
2004-04-26 14:17:26 +02:00
{
padding = ( winRect . right - d_width * aspectY ) / 2 ;
SetRect ( & dstRect , padding , 0 , d_width * aspectY + padding , d_height * aspectY ) ;
}
else
{
2005-06-09 14:39:52 +02:00
padding = ( ( winRect . bottom ) - d_height * aspectX ) / 2 ;
2004-04-26 14:17:26 +02:00
SetRect ( & dstRect , 0 , padding , ( d_width * aspectX ) , d_height * aspectX + padding ) ;
}
2004-10-29 00:03:26 +02:00
}
else
{
2005-06-09 14:39:52 +02:00
SetRect ( & dstRect , 0 , 0 , winRect . right , winRect . bottom ) ;
2004-10-29 00:03:26 +02:00
}
2008-11-24 14:28:56 +01:00
2004-08-24 22:42:27 +02:00
switch ( image_format )
2004-05-07 03:44:08 +02:00
{
2004-08-24 22:42:27 +02:00
case IMGFMT_RGB32 :
2004-05-07 03:44:08 +02:00
{
2005-06-09 14:39:52 +02:00
bounds = CGRectMake ( dstRect . left , dstRect . top , dstRect . right - dstRect . left , dstRect . bottom - dstRect . top ) ;
2004-08-24 22:42:27 +02:00
break ;
2004-05-05 03:04:44 +02:00
}
2004-08-24 22:42:27 +02:00
case IMGFMT_YV12 :
case IMGFMT_IYUV :
case IMGFMT_I420 :
case IMGFMT_UYVY :
case IMGFMT_YUY2 :
{
long scale_X = FixDiv ( Long2Fix ( dstRect . right - dstRect . left ) , Long2Fix ( imgRect . right ) ) ;
long scale_Y = FixDiv ( Long2Fix ( dstRect . bottom - dstRect . top ) , Long2Fix ( imgRect . bottom ) ) ;
2008-11-24 14:28:56 +01:00
2004-08-24 22:42:27 +02:00
SetIdentityMatrix ( & matrix ) ;
if ( ( ( dstRect . right - dstRect . left ) ! = imgRect . right ) | | ( ( dstRect . bottom - dstRect . right ) ! = imgRect . bottom ) )
{
ScaleMatrix ( & matrix , scale_X , scale_Y , 0 , 0 ) ;
2008-11-24 14:28:56 +01:00
2004-08-24 22:42:27 +02:00
if ( padding > 0 )
{
TranslateMatrix ( & matrix , Long2Fix ( dstRect . left ) , Long2Fix ( dstRect . top ) ) ;
}
}
2008-11-24 14:28:56 +01:00
2004-08-24 22:42:27 +02:00
SetDSequenceMatrix ( seqId , & matrix ) ;
break ;
}
default :
break ;
}
2008-11-24 14:28:56 +01:00
2005-06-09 14:39:52 +02:00
//Clear Background
tmpBounds = CGRectMake ( 0 , 0 , winRect . right , winRect . bottom ) ;
2008-11-24 11:01:03 +01:00
QDBeginCGContext ( GetWindowPort ( theWindow ) , & context ) ;
2005-06-09 14:39:52 +02:00
CGContextFillRect ( context , tmpBounds ) ;
2008-11-24 11:01:03 +01:00
QDEndCGContext ( GetWindowPort ( theWindow ) , & context ) ;
2004-04-05 23:20:19 +02:00
}
2004-04-26 14:17:26 +02:00
void window_ontop ( )
2004-05-12 22:47:14 +02:00
{
2004-10-28 16:52:47 +02:00
if ( ! vo_quartz_fs )
{
2004-07-15 19:36:01 +02:00
//Cycle between level
winLevel + + ;
if ( winLevel > 2 )
2005-05-20 18:40:35 +02:00
winLevel = 1 ;
2004-10-28 16:52:47 +02:00
}
2004-07-15 19:36:01 +02:00
SetWindowGroupLevel ( winGroup , CGWindowLevelForKey ( levelList [ winLevel ] ) ) ;
2004-04-05 23:20:19 +02:00
}
2004-04-26 14:17:26 +02:00
void window_fullscreen ( )
2004-04-05 23:20:19 +02:00
{
2004-04-26 14:17:26 +02:00
//go fullscreen
2004-05-07 03:44:08 +02:00
if ( vo_fs )
2004-04-26 14:17:26 +02:00
{
2004-07-15 19:36:01 +02:00
if ( winLevel ! = 0 )
{
2008-11-24 11:01:03 +01:00
if ( displayId = = kCGDirectMainDisplay )
2004-11-01 18:19:25 +01:00
{
2005-07-01 19:21:13 +02:00
SetSystemUIMode ( kUIModeAllHidden , kUIOptionAutoShowMenuBar ) ;
2008-11-24 11:01:03 +01:00
CGDisplayHideCursor ( displayId ) ;
2005-07-02 21:44:48 +02:00
mouseHide = TRUE ;
2004-11-01 18:19:25 +01:00
}
2008-11-24 14:28:56 +01:00
2004-10-28 16:52:47 +02:00
if ( fs_res_x ! = 0 | | fs_res_y ! = 0 )
{
2008-11-24 11:01:03 +01:00
CFDictionaryRef mode ;
size_t desiredBitDepth = 32 ;
boolean_t exactMatch ;
2008-11-24 14:28:56 +01:00
2008-11-24 11:01:03 +01:00
originalMode = CGDisplayCurrentMode ( displayId ) ;
2008-11-24 14:28:56 +01:00
2008-11-24 11:01:03 +01:00
mode = CGDisplayBestModeForParameters ( displayId , desiredBitDepth , fs_res_x , fs_res_y , & exactMatch ) ;
if ( mode ! = NULL )
{
if ( ! exactMatch )
{
//Warn if the mode doesn't match exactly
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 ) ) ;
}
CGDisplayCapture ( displayId ) ;
CGDisplaySwitchToMode ( displayId , mode ) ;
}
else
{
mp_msg ( MSGT_VO , MSGL_ERR , " Quartz error: can't switch to fullscreen \n " ) ;
}
//Get Main device info///////////////////////////////////////////////////
displayRect = CGDisplayBounds ( displayId ) ;
2004-10-28 16:52:47 +02:00
}
2004-07-15 19:36:01 +02:00
}
2004-04-26 14:17:26 +02:00
//save old window size
2008-11-24 14:28:56 +01:00
if ( ! vo_quartz_fs )
2004-10-30 21:56:41 +02:00
{
2004-05-18 22:49:44 +02:00
GetWindowPortBounds ( theWindow , & oldWinRect ) ;
2004-10-30 21:56:41 +02:00
GetWindowBounds ( theWindow , kWindowContentRgn , & oldWinBounds ) ;
}
2008-11-24 14:28:56 +01:00
2004-04-26 14:17:26 +02:00
//go fullscreen
2004-11-01 17:17:49 +01:00
panscan_calc ( ) ;
2005-06-09 14:39:52 +02:00
ChangeWindowAttributes ( theWindow , kWindowNoShadowAttribute , 0 ) ;
2008-11-24 11:01:03 +01:00
MoveWindow ( theWindow , displayRect . origin . x - ( vo_panscan_x > > 1 ) , displayRect . origin . y - ( vo_panscan_y > > 1 ) , 1 ) ;
SizeWindow ( theWindow , displayRect . size . width + vo_panscan_x , displayRect . size . height + vo_panscan_y , 1 ) ;
2004-05-18 22:49:44 +02:00
vo_quartz_fs = 1 ;
2004-04-26 14:17:26 +02:00
}
else //go back to windowed mode
{
2005-07-02 21:44:48 +02:00
vo_quartz_fs = 0 ;
2008-11-24 11:01:03 +01:00
if ( originalMode ! = NULL )
2004-10-28 16:52:47 +02:00
{
2008-11-24 11:01:03 +01:00
CGDisplaySwitchToMode ( displayId , originalMode ) ;
CGDisplayRelease ( displayId ) ;
2008-11-24 14:28:56 +01:00
2004-10-28 16:52:47 +02:00
//Get Main device info///////////////////////////////////////////////////
2008-11-24 11:01:03 +01:00
displayRect = CGDisplayBounds ( displayId ) ;
2008-11-24 14:28:56 +01:00
2008-11-24 11:01:03 +01:00
originalMode = NULL ;
2004-10-28 16:52:47 +02:00
}
2007-11-06 13:12:48 +01:00
SetSystemUIMode ( kUIModeNormal , 0 ) ;
2004-04-26 14:17:26 +02:00
//show mouse cursor
2008-11-24 11:01:03 +01:00
CGDisplayShowCursor ( displayId ) ;
2005-07-02 21:44:48 +02:00
mouseHide = FALSE ;
2008-11-24 14:28:56 +01:00
2004-04-26 14:17:26 +02:00
//revert window to previous setting
2005-06-09 14:39:52 +02:00
ChangeWindowAttributes ( theWindow , 0 , kWindowNoShadowAttribute ) ;
2004-05-18 22:49:44 +02:00
SizeWindow ( theWindow , oldWinRect . right , oldWinRect . bottom , 1 ) ;
2004-10-30 21:56:41 +02:00
MoveWindow ( theWindow , oldWinBounds . left , oldWinBounds . top , 1 ) ;
2004-04-26 14:17:26 +02:00
}
2005-06-09 14:39:52 +02:00
window_resized ( ) ;
2004-04-05 23:20:19 +02:00
}
2004-11-01 17:17:49 +01:00
void window_panscan ( )
{
panscan_calc ( ) ;
2008-11-24 14:28:56 +01:00
2004-11-01 17:17:49 +01:00
if ( vo_panscan > 0 )
CheckMenuItem ( aspectMenu , 2 , 1 ) ;
else
CheckMenuItem ( aspectMenu , 2 , 0 ) ;
2008-11-24 14:28:56 +01:00
2004-11-01 17:17:49 +01:00
if ( vo_quartz_fs )
{
2008-11-24 11:01:03 +01:00
MoveWindow ( theWindow , displayRect . origin . x - ( vo_panscan_x > > 1 ) , displayRect . origin . y - ( vo_panscan_y > > 1 ) , 1 ) ;
SizeWindow ( theWindow , displayRect . size . width + vo_panscan_x , displayRect . size . height + vo_panscan_y , 1 ) ;
2004-11-01 17:17:49 +01:00
}
}