changeset 29564:4ae3d2d7946e

Use MPlayer's standard aspect handling functions in corevideo instead of reimplementing them incompletely.
author reimar
date Tue, 01 Sep 2009 09:36:04 +0000
parents 0ba024eac67c
children d39aa2e3a91f
files libvo/vo_corevideo.h libvo/vo_corevideo.m
diffstat 2 files changed, 30 insertions(+), 100 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/vo_corevideo.h	Tue Sep 01 08:30:15 2009 +0000
+++ b/libvo/vo_corevideo.h	Tue Sep 01 09:36:04 2009 +0000
@@ -55,7 +55,6 @@
     GLfloat upperLeft[2];
 
 	BOOL mouseHide;
-	float winSizeMult;
 
 	//menu command id
 	NSMenuItem *kQuitCmd;
@@ -72,6 +71,8 @@
 	//timestamps for disabling screensaver and mouse hiding
 	int lastMouseHide;
 	int lastScreensaverUpdate;
+@public
+	float winSizeMult;
 }
 
 - (BOOL) acceptsFirstResponder;
--- a/libvo/vo_corevideo.m	Tue Sep 01 08:30:15 2009 +0000
+++ b/libvo/vo_corevideo.m	Tue Sep 01 09:36:04 2009 +0000
@@ -84,9 +84,6 @@
 static int isFullscreen;
 static int isOntop;
 static int isRootwin;
-extern float monitor_aspect;
-extern float movie_aspect;
-static float old_movie_aspect;
 extern int enable_mouse_movements;
 
 static float winAlpha = 1;
@@ -117,10 +114,8 @@
 	}
 }
 
-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)
+static void update_screen_info(void)
 {
-
-	//init screen
 	screen_array = [NSScreen screens];
 	if(screen_id < (int)[screen_array count])
 	{
@@ -132,9 +127,20 @@
 		screen_handle = [screen_array objectAtIndex:0];
 		screen_id = -1;
 	}
-	screen_frame = [screen_handle frame];
+
+	screen_frame = ![mpGLView window] || screen_id >= 0 ? [screen_handle frame] : [[[mpGLView window] screen] frame];
 	vo_screenwidth = screen_frame.size.width;
 	vo_screenheight = screen_frame.size.height;
+	xinerama_x = xinerama_y = 0;
+	aspect_save_screenres(vo_screenwidth, vo_screenheight);
+}
+
+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)
+{
+	config_movie_aspect((float)d_width/d_height);
+
+	vo_dwidth  = d_width  *= mpGLView->winSizeMult;
+	vo_dheight = d_height *= mpGLView->winSizeMult;
 
 	//misc mplayer setup
 	image_width = width;
@@ -159,18 +165,6 @@
 			image_datas[1] = malloc(image_width*image_height*image_bytes);
 		image_page = 0;
 
-		monitor_aspect = (float)screen_frame.size.width/(float)screen_frame.size.height;
-
-		//set aspect
-		panscan_init();
-		aspect_save_orig(width,height);
-		aspect_save_prescale(d_width,d_height);
-		aspect_save_screenres(screen_frame.size.width, screen_frame.size.height);
-		aspect((int *)&d_width,(int *)&d_height,A_NOZOOM);
-
-		movie_aspect = (float)d_width/(float)d_height;
-		old_movie_aspect = movie_aspect;
-
 		vo_fs = flags & VOFLAG_FULLSCREEN;
 
 		//config OpenGL View
@@ -182,8 +176,6 @@
 		mp_msg(MSGT_VO, MSGL_INFO, "[vo_corevideo] writing output to a shared buffer "
 				"named \"%s\"\n",buffer_name);
 
-		movie_aspect = (float)d_width/(float)d_height;
-
 		// create shared memory
 		shm_fd = shm_open(buffer_name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
 		if (shm_fd == -1)
@@ -218,7 +210,7 @@
 		if ([mplayerosxProxy conformsToProtocol:@protocol(MPlayerOSXVOProto)]) {
 			[mplayerosxProxy setProtocolForProxy:@protocol(MPlayerOSXVOProto)];
 			mplayerosxProto = (id <MPlayerOSXVOProto>)mplayerosxProxy;
-			[mplayerosxProto startWithWidth: image_width withHeight: image_height withBytes: image_bytes withAspect:(int)(movie_aspect*100)];
+			[mplayerosxProto startWithWidth: image_width withHeight: image_height withBytes: image_bytes withAspect:d_width*100/d_height];
 		}
 		else {
 			[mplayerosxProxy release];
@@ -428,6 +420,7 @@
 		case VOCTRL_FULLSCREEN: vo_fs = (!(vo_fs)); if(!shared_buffer){ [mpGLView fullscreen: NO]; } else { [mplayerosxProto toggleFullscreen]; } return VO_TRUE;
 		case VOCTRL_GET_PANSCAN: return VO_TRUE;
 		case VOCTRL_SET_PANSCAN: [mpGLView panscan]; return VO_TRUE;
+		case VOCTRL_UPDATE_SCREENINFO: update_screen_info(); return VO_TRUE;
 	}
 	return VO_NOTIMPL;
 }
@@ -468,7 +461,7 @@
 	CVReturn error = kCVReturnSuccess;
 
 	//config window
-	aspect((int *)&d_width, (int *)&d_height,A_NOZOOM);
+	d_width = vo_dwidth; d_height = vo_dheight;
 	frame = NSMakeRect(0, 0, d_width, d_height);
 	[window setContentSize: frame.size];
 
@@ -596,8 +589,8 @@
 		}
 
 		winSizeMult = 0.5;
-		frame.size.width = (d_width*winSizeMult);
-		frame.size.height = ((d_width/movie_aspect)*winSizeMult);
+		frame.size.width = d_width*winSizeMult;
+		frame.size.height = d_height*winSizeMult;
 		[window setContentSize: frame.size];
 		[self reshape];
 	}
@@ -609,7 +602,7 @@
 
 		winSizeMult = 1;
 		frame.size.width = d_width;
-		frame.size.height = d_width/movie_aspect;
+		frame.size.height = d_height;
 		[window setContentSize: frame.size];
 		[self reshape];
 	}
@@ -621,7 +614,7 @@
 
 		winSizeMult = 2;
 		frame.size.width = d_width*winSizeMult;
-		frame.size.height = (d_width/movie_aspect)*winSizeMult;
+		frame.size.height = d_height*winSizeMult;
 		[window setContentSize: frame.size];
 		[self reshape];
 	}
@@ -654,55 +647,13 @@
 	}
 
 	if(sender == kAspectOrgCmd)
-	{
-		movie_aspect = old_movie_aspect;
-
-		if(isFullscreen)
-		{
-			[self reshape];
-		}
-		else
-		{
-			frame.size.width = d_width*winSizeMult;
-			frame.size.height = (d_width/movie_aspect)*winSizeMult;
-			[window setContentSize: frame.size];
-			[self reshape];
-		}
-	}
+		change_movie_aspect(-1);
 
 	if(sender == kAspectFullCmd)
-	{
-		movie_aspect = 4.0f/3.0f;
-
-		if(isFullscreen)
-		{
-			[self reshape];
-		}
-		else
-		{
-			frame.size.width = d_width*winSizeMult;
-			frame.size.height = (d_width/movie_aspect)*winSizeMult;
-			[window setContentSize: frame.size];
-			[self reshape];
-		}
-	}
+		change_movie_aspect(4.0f/3.0f);
 
 	if(sender == kAspectWideCmd)
-	{
-		movie_aspect = 16.0f/9.0f;
-
-		if(isFullscreen)
-		{
-			[self reshape];
-		}
-		else
-		{
-			frame.size.width = d_width*winSizeMult;
-			frame.size.height = (d_width/movie_aspect)*winSizeMult;
-			[window setContentSize: frame.size];
-			[self reshape];
-		}
-	}
+		change_movie_aspect(16.0f/9.0f);
 }
 
 /*
@@ -724,11 +675,10 @@
 {
 	uint32_t d_width;
 	uint32_t d_height;
-	float aspectX;
-	float aspectY;
-	int padding = 0;
 
 	NSRect frame = [self frame];
+	vo_dwidth  = frame.size.width;
+	vo_dheight = frame.size.height;
 
 	glViewport(0, 0, frame.size.width, frame.size.height);
 	glMatrixMode(GL_PROJECTION);
@@ -740,29 +690,14 @@
 	//set texture frame
 	if(vo_keepaspect)
 	{
-		aspect( (int *)&d_width, (int *)&d_height, A_NOZOOM);
-		d_height = ((float)d_width/movie_aspect);
-
-		aspectX = (float)((float)frame.size.width/(float)d_width);
-		aspectY = (float)((float)(frame.size.height)/(float)d_height);
+		aspect( (int *)&d_width, (int *)&d_height, A_WINZOOM);
 
-		if((d_height*aspectX)>(frame.size.height))
-		{
-			padding = (frame.size.width - d_width*aspectY)/2;
-			textureFrame = NSMakeRect(padding, 0, d_width*aspectY, d_height*aspectY);
-		}
-		else
-		{
-			padding = ((frame.size.height) - d_height*aspectX)/2;
-			textureFrame = NSMakeRect(0, padding, d_width*aspectX, d_height*aspectX);
-		}
+		textureFrame = NSMakeRect((vo_dwidth - d_width) / 2, (vo_dheight - d_height) / 2, d_width, d_height);
 	}
 	else
 	{
 		textureFrame = frame;
 	}
-	vo_dwidth = textureFrame.size.width;
-	vo_dheight = textureFrame.size.height;
 }
 
 /*
@@ -877,13 +812,7 @@
 		}
 
 		old_frame = [window frame];	//save main window size & position
-		if(screen_id >= 0)
-			screen_frame = [screen_handle frame];
-		else {
-			screen_frame = [[window screen] frame];
-			vo_screenwidth = screen_frame.size.width;
-			vo_screenheight = screen_frame.size.height;
-		}
+		update_screen_info();
 
 		[window setFrame:screen_frame display:YES animate:animate]; //zoom-in window with nice useless sfx
 		old_view_frame = [self bounds];