# HG changeset patch # User nplourde # Date 1228049711 0 # Node ID 3b8e66828e100f466b87491bc450cba7600803cc # Parent 94cf4a9270cbeb942cf5796d15df0c79f30291e4 use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz 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 diff -r 94cf4a9270cb -r 3b8e66828e10 libvo/vo_macosx.m --- a/libvo/vo_macosx.m Sun Nov 30 09:17:21 2008 +0000 +++ b/libvo/vo_macosx.m Sun Nov 30 12:55:11 2008 +0000 @@ -9,7 +9,7 @@ #import "vo_macosx.h" #include #include -#include +#include #include //special workaround for Apple bug #6267445 //(OSServices Power API disabled in OSServices.h for 64bit systems) @@ -39,8 +39,7 @@ OSType pixelFormat; //shared memory -int shm_id; -struct shmid_ds shm_desc; +int shm_fd; BOOL shared_buffer = false; //Screen @@ -165,21 +164,36 @@ 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 @@ 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);