[MPlayer-cvslog] CVS: main/libvo vo_macosx.m,1.31,1.32

Nicolas Plourde CVS syncmail at mplayerhq.hu
Sun Sep 4 14:58:18 CEST 2005


CVS change done by Nicolas Plourde CVS

Update of /cvsroot/mplayer/main/libvo
In directory mail:/var2/tmp/cvs-serv15319/libvo

Modified Files:
	vo_macosx.m 
Log Message:
mplayer osx shared video buffer

Index: vo_macosx.m
===================================================================
RCS file: /cvsroot/mplayer/main/libvo/vo_macosx.m,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- vo_macosx.m	5 Aug 2005 01:24:36 -0000	1.31
+++ vo_macosx.m	4 Sep 2005 12:58:16 -0000	1.32
@@ -7,6 +7,9 @@
 */
 
 #import "vo_macosx.h"
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
 
 //MPLAYER
 #include "config.h"
@@ -23,10 +26,16 @@
 #include "osdep/keycodes.h"
 
 //Cocoa
+NSProxy *mplayerosxProxy;
 MPlayerOpenGLView *mpGLView;
 NSAutoreleasePool *autoreleasepool;
 OSType pixelFormat;
 
+//shared memory
+int shm_id;
+struct shmid_ds shm_desc;
+BOOL shared_buffer = false;
+
 //Screen
 int screen_id;
 BOOL screen_force;
@@ -87,7 +96,7 @@
 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)
 {
 	int i;
-
+	
 	//init screen
 	screen_array = [NSScreen screens];
 	if(screen_id < [screen_array count])
@@ -101,9 +110,7 @@
 		screen_id = 0;
 	}
 	screen_frame = [screen_handle frame];
-	
-	monitor_aspect = (float)screen_frame.size.width/(float)screen_frame.size.height;
-	
+
 	//misc mplayer setup
 	image_width = width;
 	image_height = height;
@@ -113,29 +120,55 @@
 		case IMGFMT_RGB32:
 			image_depth = 32;
 			break;
-        case IMGFMT_YUY2:
+		case IMGFMT_YUY2:
 			image_depth = 16;
 			break;
 	}
 	image_bytes = (image_depth + 7) / 8;
 	image_data = (unsigned char*)malloc(image_width*image_height*image_bytes);
-	
-	//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
-	[mpGLView config];
-	[mpGLView reshape];
-	
+		
+	if(!shared_buffer)
+	{		
+		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
+		[mpGLView config];
+		[mpGLView reshape];
+	}
+	else
+	{
+		movie_aspect = (float)d_width/(float)d_height;
+				
+		shm_id = shmget(9849, image_width*image_height*image_bytes, IPC_CREAT | 0666);
+		if (shm_id == -1)
+		{
+			perror("vo_mplayer shmget: ");
+			return 1;
+		}
+		
+		image_data = shmat(shm_id, NULL, 0);
+		if (!image_data)
+		{	
+			perror("vo_mplayer shmat: ");
+			return 1;
+		}
+		
+		//connnect to mplayerosx
+		mplayerosxProxy=[NSConnection rootProxyForConnectionWithRegisteredName:@"mplayerosx" host:nil];
+		[mplayerosxProxy startWithWidth: image_width withHeight: image_height withBytes: image_bytes withAspect:movie_aspect];
+	}
 	return 0;
 }
 
@@ -151,7 +184,10 @@
 
 static void flip_page(void)
 {
-	[mpGLView render];
+	if(shared_buffer)
+		[mplayerosxProxy render];
+	else
+		[mpGLView render];
 }
 
 static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
@@ -174,7 +210,10 @@
 			memcpy_pic(image_data, src[0], image_width * 2, image_height, image_width * 2, image_width * 2);
 			break;
 	}
-	[mpGLView setCurrentTexture];
+	
+	if(!shared_buffer)
+		[mpGLView setCurrentTexture];
+	
 	return 0;
 }
 
@@ -198,9 +237,20 @@
 
 static void uninit(void)
 {
+	if(shared_buffer)
+	{
+		[mplayerosxProxy stop];
+
+		if (shmdt(image_data) == -1)
+			mp_msg(MSGT_VO, MSGL_FATAL, "uninit: shmdt failed\n");
+	
+		if (shmctl(shm_id, IPC_RMID, &shm_desc) == -1)
+			mp_msg(MSGT_VO, MSGL_FATAL, "uninit: shmctl failed\n");
+	}
+
 	SetSystemUIMode( kUIModeNormal, 0);
 	ShowCursor();
-
+	
 	[autoreleasepool release];
 }
 
@@ -239,6 +289,11 @@
 				screen_id = strtol(parse_pos, &parse_pos, 0);
 				screen_force = YES;
             }
+			if (strncmp (parse_pos, "shared_buffer", 13) == 0)
+			{
+				parse_pos = &parse_pos[13];
+				shared_buffer = YES;
+            }
             if (parse_pos[0] == ':') parse_pos = &parse_pos[1];
             else if (parse_pos[0]) parse_err = 1;
         }
@@ -248,14 +303,17 @@
 	autoreleasepool = [[NSAutoreleasePool alloc] init];
 	NSApp = [NSApplication sharedApplication];
 	
-	if(!mpGLView)
+	if(!shared_buffer)
 	{
-		mpGLView = [[MPlayerOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) pixelFormat:[MPlayerOpenGLView defaultPixelFormat]];
-		[mpGLView autorelease];
-	}
+		if(!mpGLView)
+		{
+			mpGLView = [[MPlayerOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) pixelFormat:[MPlayerOpenGLView defaultPixelFormat]];
+			[mpGLView autorelease];
+		}
 	
-	[mpGLView display];
-	[mpGLView preinit];
+		[mpGLView display];
+		[mpGLView preinit];
+	}
 	
     return 0;
 }




More information about the MPlayer-cvslog mailing list