From 80cf4355292d1975018d7d449520530293b985f4 Mon Sep 17 00:00:00 2001 From: gpoirier Date: Tue, 30 Dec 2008 21:39:42 +0000 Subject: Add an option to vo_macosx to set a custom buffer_name. This allows to have multiple instances of MPlayerOSX running without stepping on each other's toes. Patch by Adrian Stutz % adrian A sttz P ch % Original thread: date: Tue, Dec 9, 2008 at 2:46 PM subject: [MPlayer-dev-eng] [PATCH] vo_macosx: option to set shared buffer name to allow multiple instances git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@28215 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libvo/vo_macosx.m | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'libvo/vo_macosx.m') diff --git a/libvo/vo_macosx.m b/libvo/vo_macosx.m index 34043de579..e9043fc8b4 100644 --- a/libvo/vo_macosx.m +++ b/libvo/vo_macosx.m @@ -45,6 +45,8 @@ OSType pixelFormat; //shared memory int shm_fd; BOOL shared_buffer = false; +#define DEFAULT_BUFFER_NAME "mplayerosx" +static char *buffer_name; //Screen int screen_id; @@ -164,10 +166,13 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_ } else { + mp_msg(MSGT_VO, MSGL_INFO, "VO: [macosx] 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("mplayerosx", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); + shm_fd = shm_open(buffer_name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (shm_fd == -1) { mp_msg(MSGT_VO, MSGL_FATAL, @@ -180,7 +185,7 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_ { mp_msg(MSGT_VO, MSGL_FATAL, "vo_macosx: failed to size shared memory, possibly already in use. Error: %s\n", strerror(errno)); - shm_unlink("mplayerosx"); + shm_unlink(buffer_name); return 1; } @@ -191,12 +196,12 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_ { mp_msg(MSGT_VO, MSGL_FATAL, "vo_macosx: failed to map shared memory. Error: %s\n", strerror(errno)); - shm_unlink("mplayerosx"); + shm_unlink(buffer_name); return 1; } //connnect to mplayerosx - mplayerosxProxy=[NSConnection rootProxyForConnectionWithRegisteredName:@"mplayerosx" host:nil]; + mplayerosxProxy=[NSConnection rootProxyForConnectionWithRegisteredName:[NSString stringWithCString:buffer_name] host:nil]; if ([mplayerosxProxy conformsToProtocol:@protocol(MPlayerOSXVOProto)]) { [mplayerosxProxy setProtocolForProxy:@protocol(MPlayerOSXVOProto)]; mplayerosxProto = (id )mplayerosxProxy; @@ -288,7 +293,7 @@ static void uninit(void) if (munmap(image_data, image_width*image_height*image_bytes) == -1) mp_msg(MSGT_VO, MSGL_FATAL, "uninit: munmap failed. Error: %s\n", strerror(errno)); - if (shm_unlink("mplayerosx") == -1) + if (shm_unlink(buffer_name) == -1) mp_msg(MSGT_VO, MSGL_FATAL, "uninit: shm_unlink failed. Error: %s\n", strerror(errno)); } @@ -314,11 +319,15 @@ static void uninit(void) image_datas[1] = NULL; image_data = NULL; } + + if (buffer_name) free(buffer_name); + buffer_name = NULL; } static opt_t subopts[] = { {"device_id", OPT_ARG_INT, &screen_id, (opt_test_f)int_non_neg}, {"shared_buffer", OPT_ARG_BOOL, &shared_buffer, NULL}, +{"buffer_name", OPT_ARG_MSTRZ,&buffer_name, NULL}, {NULL} }; @@ -328,16 +337,21 @@ static int preinit(const char *arg) // set defaults screen_id = 0; shared_buffer = false; + buffer_name = DEFAULT_BUFFER_NAME; if (subopt_parse(arg, subopts) != 0) { mp_msg(MSGT_VO, MSGL_FATAL, "\n-vo macosx command line help:\n" - "Example: mplayer -vo macosx:device_id=1:shared_buffer\n" + "Example: mplayer -vo macosx:device_id=1:shared_buffer:buffer_name=mybuff\n" "\nOptions:\n" " device_id=<0-...>\n" " Set screen device id for fullscreen.\n" " shared_buffer\n" " Write output to a shared memory buffer instead of displaying it.\n" + " buffer_name=\n" + " Name of the shared buffer created with shm_open() as well as\n" + " the name of the NSConnection MPlayer will try to open.\n" + " Setting buffer_name implicitly enables shared_buffer.\n" "\n" ); return -1; } @@ -347,6 +361,9 @@ static int preinit(const char *arg) NSApp = [NSApplication sharedApplication]; isLeopardOrLater = floor(NSAppKitVersionNumber) > 824; + if (strcmp(buffer_name, DEFAULT_BUFFER_NAME)) + shared_buffer = true; + if(!shared_buffer) { #if !defined (CONFIG_MACOSX_FINDER) || !defined (CONFIG_SDL) -- cgit v1.2.3 From fd99631e06fe3f6090d3782fb451226580c9703c Mon Sep 17 00:00:00 2001 From: gpoirier Date: Sat, 3 Jan 2009 22:33:04 +0000 Subject: Fix deinit problem due to r28215 original thread: date: Fri, Jan 2, 2009 at 10:00 PM subject: [PATCH] Fix deinit problem due to r28215 (was Re: [MPlayer-cvslog] r28215 - in trunk: DOCS/man/en/mplayer.1 libvo/vo_macosx.m) git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@28239 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libvo/vo_macosx.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libvo/vo_macosx.m') diff --git a/libvo/vo_macosx.m b/libvo/vo_macosx.m index e9043fc8b4..b049cf080c 100644 --- a/libvo/vo_macosx.m +++ b/libvo/vo_macosx.m @@ -337,7 +337,7 @@ static int preinit(const char *arg) // set defaults screen_id = 0; shared_buffer = false; - buffer_name = DEFAULT_BUFFER_NAME; + buffer_name = NULL; if (subopt_parse(arg, subopts) != 0) { mp_msg(MSGT_VO, MSGL_FATAL, @@ -361,7 +361,9 @@ static int preinit(const char *arg) NSApp = [NSApplication sharedApplication]; isLeopardOrLater = floor(NSAppKitVersionNumber) > 824; - if (strcmp(buffer_name, DEFAULT_BUFFER_NAME)) + if (!buffer_name) + buffer_name = strdup(DEFAULT_BUFFER_NAME); + else shared_buffer = true; if(!shared_buffer) -- cgit v1.2.3