vo_quartz.c

来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 1,431 行 · 第 1/3 页

C
1,431
字号
				theWindow = NULL;				mplayer_put_key(KEY_CLOSE_WIN);				break;							//resize window			case kEventWindowZoomed:			case kEventWindowBoundsChanged:				window_resized();				flip_page();				window_resized();				break;						default:				result = eventNotHandledErr;				break;		}	}	    return result;}static void quartz_CreateWindow(uint32_t d_width, uint32_t d_height, WindowAttributes windowAttrs) {	CFStringRef		titleKey;	CFStringRef		windowTitle; 	OSStatus	       	result;		MenuItemIndex index;	CFStringRef movMenuTitle;	CFStringRef aspMenuTitle; 	SetRect(&winRect, 0, 0, d_width, d_height);	SetRect(&oldWinRect, 0, 0, d_width, d_height);	SetRect(&dstRect, 0, 0, d_width, d_height);		//Clear Menu Bar	ClearMenuBar();		//Create Window Menu	CreateStandardWindowMenu(0, &windMenu);	InsertMenu(windMenu, 0);		//Create Movie Menu	CreateNewMenu (1004, 0, &movMenu);	movMenuTitle = CFSTR("Movie");	SetMenuTitleWithCFString(movMenu, movMenuTitle);		AppendMenuItemTextWithCFString(movMenu, CFSTR("Half Size"), 0, kHalfScreenCmd, &index);	SetMenuItemCommandKey(movMenu, index, 0, '0');		AppendMenuItemTextWithCFString(movMenu, CFSTR("Normal Size"), 0, kNormalScreenCmd, &index);	SetMenuItemCommandKey(movMenu, index, 0, '1');		AppendMenuItemTextWithCFString(movMenu, CFSTR("Double Size"), 0, kDoubleScreenCmd, &index);	SetMenuItemCommandKey(movMenu, index, 0, '2');		AppendMenuItemTextWithCFString(movMenu, CFSTR("Full Size"), 0, kFullScreenCmd, &index);	SetMenuItemCommandKey(movMenu, index, 0, 'F');		AppendMenuItemTextWithCFString(movMenu, NULL, kMenuItemAttrSeparator, NULL, &index);	AppendMenuItemTextWithCFString(movMenu, CFSTR("Aspect Ratio"), 0, NULL, &index);		////Create Aspect Ratio Sub Menu	CreateNewMenu (0, 0, &aspectMenu);	aspMenuTitle = CFSTR("Aspect Ratio");	SetMenuTitleWithCFString(aspectMenu, aspMenuTitle);	SetMenuItemHierarchicalMenu(movMenu, 6, aspectMenu);		AppendMenuItemTextWithCFString(aspectMenu, CFSTR("Keep"), 0, kKeepAspectCmd, &index);	CheckMenuItem (aspectMenu, 1, vo_keepaspect);	AppendMenuItemTextWithCFString(aspectMenu, CFSTR("Pan-Scan"), 0, kPanScanCmd, &index);	CheckMenuItem (aspectMenu, 2, vo_panscan);	AppendMenuItemTextWithCFString(aspectMenu, NULL, kMenuItemAttrSeparator, NULL, &index);	AppendMenuItemTextWithCFString(aspectMenu, CFSTR("Original"), 0, kAspectOrgCmd, &index);	AppendMenuItemTextWithCFString(aspectMenu, CFSTR("4:3"), 0, kAspectFullCmd, &index);	AppendMenuItemTextWithCFString(aspectMenu, CFSTR("16:9"), 0, kAspectWideCmd, &index);			InsertMenu(movMenu, GetMenuID(windMenu)); //insert before Window menu		DrawMenuBar();  	//create window	CreateNewWindow(kDocumentWindowClass, windowAttrs, &winRect, &theWindow);		CreateWindowGroup(0, &winGroup);	SetWindowGroup(theWindow, winGroup);	//Set window title	titleKey	= CFSTR("MPlayer - The Movie Player");	windowTitle = CFCopyLocalizedString(titleKey, NULL);	result		= SetWindowTitleWithCFString(theWindow, windowTitle);	CFRelease(titleKey);	CFRelease(windowTitle);  	//Install event handler    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 }	};		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);}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){	WindowAttributes	windowAttrs;	OSErr				qterr;	int i;	CGRect tmpBounds;	//Get Main device info///////////////////////////////////////////////////	deviceHdl = GetMainDevice();		for(i=0; i<device_id; i++)	{		deviceHdl = GetNextDevice(deviceHdl);				if(deviceHdl == NULL)		{			mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: Device ID %d do not exist, falling back to main device.\n", device_id);			deviceHdl = GetMainDevice();			device_id = 0;			break;		}	}		deviceRect = (*deviceHdl)->gdRect;	device_width = deviceRect.right-deviceRect.left;	device_height = deviceRect.bottom-deviceRect.top;		monitor_aspect = (float)device_width/(float)device_height;	//misc mplayer setup/////////////////////////////////////////////////////	SetRect(&imgRect, 0, 0, width, height);	switch (image_format) 	{		case IMGFMT_RGB32:			image_depth = 32;			break;		case IMGFMT_YV12:		case IMGFMT_IYUV:        case IMGFMT_I420:        case IMGFMT_UYVY:        case IMGFMT_YUY2:			image_depth = 16;			break;	}	image_size = ((imgRect.right*imgRect.bottom*image_depth)+7)/8;	vo_fs = flags & VOFLAG_FULLSCREEN;		//get movie aspect	panscan_init();	aspect_save_orig(width,height);	aspect_save_prescale(d_width,d_height);	aspect_save_screenres(device_width, device_height);		aspect(&d_width,&d_height,A_NOZOOM);		movie_aspect = (float)d_width/(float)d_height;	old_movie_aspect = movie_aspect;		if(image_data)		free(image_data);		image_data = malloc(image_size);	//Create player window//////////////////////////////////////////////////	windowAttrs =   kWindowStandardDocumentAttributes					| kWindowStandardHandlerAttribute					| kWindowLiveResizeAttribute;						windowAttrs &= (~kWindowResizableAttribute);					 	if (theWindow == NULL)	{		quartz_CreateWindow(d_width, d_height, windowAttrs);				if (theWindow == NULL)		{			mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: Couldn't create window !!!!!\n");			return -1;		}		tmpBounds = CGRectMake( 0, 0, winRect.right, winRect.bottom);		CreateCGContextForPort(GetWindowPort(theWindow),&context);		CGContextFillRect(context, tmpBounds);	}	else 	{		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); 	}		switch (image_format) 	{		case IMGFMT_RGB32:		{			CreateCGContextForPort (GetWindowPort (theWindow), &context);						dataProviderRef = CGDataProviderCreateWithData (0, image_data, imgRect.right * imgRect.bottom * 4, 0);						image = CGImageCreate   (imgRect.right,									 imgRect.bottom,									 8,									 image_depth,									 ((imgRect.right*32)+7)/8,									 CGColorSpaceCreateDeviceRGB(),									 kCGImageAlphaNoneSkipFirst,									 dataProviderRef, 0, 1, kCGRenderingIntentDefault);			break;		}					case IMGFMT_YV12:		case IMGFMT_IYUV:		case IMGFMT_I420:		case IMGFMT_UYVY:		case IMGFMT_YUY2:		{		 	get_image_done = 0;			if (!EnterMoviesDone)			{				qterr = EnterMovies();				EnterMoviesDone = 1;			}			else				qterr = 0;				if (qterr)			{				mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: EnterMovies (%d)\n", qterr);				return -1;			}					SetIdentityMatrix(&matrix);				if ((d_width != width) || (d_height != height))			{				ScaleMatrix(&matrix, FixDiv(Long2Fix(d_width),Long2Fix(width)), FixDiv(Long2Fix(d_height),Long2Fix(height)), 0, 0);			}					yuv_qt_stuff.desc = (ImageDescriptionHandle)NewHandleClear( sizeof(ImageDescription) );					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;					yuv_qt_stuff.extension_fiel = NewHandleClear(sizeof(FieldInfoImageDescriptionExtension));			((FieldInfoImageDescriptionExtension*)(*yuv_qt_stuff.extension_fiel))->fieldCount = 1;			((FieldInfoImageDescriptionExtension*)(*yuv_qt_stuff.extension_fiel))->fieldOrderings = 0;					yuv_qt_stuff.extension_clap = NewHandleClear(sizeof(CleanApertureImageDescriptionExtension));			((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->cleanApertureWidthN = imgRect.right;			((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->cleanApertureWidthD = 1;			((CleanApertureImageDescriptionExtension*)(*yuv_qt_stuff.extension_clap))->cleanApertureHeightN = imgRect.bottom;			((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;        			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';			(*yuv_qt_stuff.desc)->width = imgRect.right;			(*yuv_qt_stuff.desc)->height = imgRect.bottom;			(*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;	  			qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_colr, kColorInfoImageDescriptionExtension);			if (qterr)			{				mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [colr] (%d)\n", qterr);			}						qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_fiel, kFieldInfoImageDescriptionExtension);			if (qterr)			{				mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [fiel] (%d)\n", qterr);			}					qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_clap, kCleanApertureImageDescriptionExtension);			if (qterr)			{				mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [clap] (%d)\n", qterr);			}					qterr = AddImageDescriptionExtension(yuv_qt_stuff.desc, yuv_qt_stuff.extension_pasp, kCleanApertureImageDescriptionExtension);			if (qterr)			{				mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: AddImageDescriptionExtension [pasp] (%d)\n", qterr);			}			if (P != NULL) { // second or subsequent movie				free(P);			}			P = calloc(sizeof(PlanarPixmapInfoYUV420) + image_size, 1);			switch (image_format)			{				case IMGFMT_YV12:				case IMGFMT_IYUV:				case IMGFMT_I420:					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);					image_buffer_size = image_size + sizeof(PlanarPixmapInfoYUV420);					break;				case IMGFMT_UYVY:				case IMGFMT_YUY2:					image_buffer_size = image_size;					break;			}			qterr = DecompressSequenceBeginS(&seqId,					   yuv_qt_stuff.desc,					   (char *)P,					   image_buffer_size,					   GetWindowPort(theWindow),					   NULL,					   NULL,					   ((d_width != width) || (d_height != height)) ? 					   &matrix : NULL,					   srcCopy,					   NULL,					   0,					   codecLosslessQuality,					   bestSpeedCodec);			if (qterr)			{				mp_msg(MSGT_VO, MSGL_FATAL, "Quartz error: DecompressSequenceBeginS (%d)\n", qterr);				return -1;			}		}		break;	}		//Show window	RepositionWindow(theWindow, NULL, kWindowCenterOnMainScreen);	ShowWindow (theWindow);		if(vo_fs)		window_fullscreen();			if(vo_ontop)		window_ontop();			if(vo_rootwin)	{		vo_fs = TRUE;		winLevel = 0;		SetWindowGroupLevel(winGroup, CGWindowLevelForKey(levelList[winLevel]));		window_fullscreen();	}		window_resized();		return 0;}static void check_events(void){	EventRef theEvent;	EventTargetRef theTarget;	OSStatus	theErr;		//Get event	theTarget = GetEventDispatcherTarget();    theErr = ReceiveNextEvent(0, 0, kEventDurationNoWait,true, &theEvent);    if(theErr == noErr && theEvent != NULL)	{		SendEventToEventTarget (theEvent, theTarget);		ReleaseEvent(theEvent);	}}static void draw_osd(void){	vo_draw_text(imgRect.right,imgRect.bottom,draw_alpha);}static void flip_page(void){	int curTime;	static int lastTime;	if(theWindow == NULL)		return;			switch (image_format) 	{		case IMGFMT_RGB32:		{			CGContextDrawImage (context, bounds, image);		}		break;					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)				{					mp_msg(MSGT_VO, MSGL_ERR, "Quartz error: DecompressSequenceFrameWhen in flip_page (%d) flags:0x%08x\n", qterr, flags);				}			}		break;	}		if(!vo_quartz_fs)	{		//render resize box		CGContextBeginPath(context);		CGContextSetAllowsAntialiasing(context, false);		//CGContextSaveGState(context);			//line white		CGContextSetRGBStrokeColor (context, 0.2, 0.2, 0.2, 0.5);		CGContextMoveToPoint( context, winRect.right-1, 1); CGContextAddLineToPoint( context, winRect.right-1, 1);			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);		CGContextMoveToPoint( context, winRect.right-1, 2); CGContextAddLineToPoint( context, winRect.right-2, 1);	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?