summaryrefslogtreecommitdiffstats
path: root/libvo
diff options
context:
space:
mode:
authornplourde <nplourde@b3059339-0415-0410-9bf9-f77b7e298cf2>2008-11-30 12:55:11 +0000
committernplourde <nplourde@b3059339-0415-0410-9bf9-f77b7e298cf2>2008-11-30 12:55:11 +0000
commit7baeb6bcfc295035192dbf73889acf0f31a5873c (patch)
tree0fecbf0c38facbab023b98aa7d3a6eca2a4d8f83 /libvo
parent54c23a5806d5928e6f6278b79fbdb6c89c6cb608 (diff)
downloadmpv-7baeb6bcfc295035192dbf73889acf0f31a5873c.tar.bz2
mpv-7baeb6bcfc295035192dbf73889acf0f31a5873c.tar.xz
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
Original thread: date: Sun, Oct 12, 2008 at 10:32 PM subject: [MPlayer-dev-eng] [PATCH] vo_macosx: use mmap instead of shmat for MPlayerOSX git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@28050 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libvo')
-rw-r--r--libvo/vo_macosx.m49
1 files changed, 32 insertions, 17 deletions
diff --git a/libvo/vo_macosx.m b/libvo/vo_macosx.m
index b756550ae3..2d051e8a8f 100644
--- a/libvo/vo_macosx.m
+++ b/libvo/vo_macosx.m
@@ -9,7 +9,7 @@
#import "vo_macosx.h"
#include <sys/types.h>
#include <sys/ipc.h>
-#include <sys/shm.h>
+#include <sys/mman.h>
#include <CoreServices/CoreServices.h>
//special workaround for Apple bug #6267445
//(OSServices Power API disabled in OSServices.h for 64bit systems)
@@ -39,8 +39,7 @@ NSAutoreleasePool *autoreleasepool;
OSType pixelFormat;
//shared memory
-int shm_id;
-struct shmid_ds shm_desc;
+int shm_fd;
BOOL shared_buffer = false;
//Screen
@@ -165,21 +164,36 @@ static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_
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)
+
+ // create shared memory
+ shm_fd = shm_open("mplayerosx", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
+ if (shm_fd == -1)
{
- perror("vo_mplayer shmget: ");
+ mp_msg(MSGT_VO, MSGL_FATAL,
+ "vo_macosx: failed to open shared memory. Error: %s\n", strerror(errno));
return 1;
}
- image_data = shmat(shm_id, NULL, 0);
- if (!image_data)
- {
- perror("vo_mplayer shmat: ");
+
+ if (ftruncate(shm_fd, image_width*image_height*image_bytes) == -1)
+ {
+ 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");
return 1;
}
+ image_data = mmap(NULL, image_width*image_height*image_bytes,
+ PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
+
+ if (image_data == MAP_FAILED)
+ {
+ mp_msg(MSGT_VO, MSGL_FATAL,
+ "vo_macosx: failed to map shared memory. Error: %s\n", strerror(errno));
+ shm_unlink("mplayerosx");
+ return 1;
+ }
+
//connnect to mplayerosx
mplayerosxProxy=[NSConnection rootProxyForConnectionWithRegisteredName:@"mplayerosx" host:nil];
if ([mplayerosxProxy conformsToProtocol:@protocol(MPlayerOSXVOProto)]) {
@@ -269,12 +283,13 @@ static void uninit(void)
mplayerosxProto = nil;
[mplayerosxProxy release];
mplayerosxProxy = nil;
-
- 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");
+
+ 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)
+ mp_msg(MSGT_VO, MSGL_FATAL, "uninit: shm_unlink failed. Error: %s\n", strerror(errno));
+
}
SetSystemUIMode( kUIModeNormal, 0);