Opened 16 years ago

Closed 15 years ago

#1295 closed defect (fixed)

shmem issues on mac; MPlayer OS X won't play anything while PostgreSQL is running

Reported by: camillo.lists@… Owned by: nicolas.plourde@…
Priority: normal Component: MPlayer OS X
Version: 1.0rc2 Severity: major
Keywords: Cc:
Blocked By: Blocking:
Reproduced by developer: no Analyzed by developer: no

Description

Summary

There is an issue with the vo_macosx module when set to play the video inside the window with the player controls (corresponding to the "MPlayer OS X" setting for video output in 1.0rc2, or "Integrated into player window" in MPlayer OS X Extended; in both cases, it's the default setting). Under certain circumstances, playback stops without feedback before the video appears; if you check the console, you see these messages:

vo_mplayer shmget: : Cannot allocate memory
FATAL: Cannot initialize video driver.

Analysis

The problem occurs when some other program is using too much shared memory; in particular, it always seems to occur if PostgreSQL is installed and running in the default configuration. The reason is that, by default, Mac OS X (up to Leopard included) limits the *total* amount of SysV-style shared memory to 4 MB.

$ sysctl kern.sysv
kern.sysv.shmall: 1024
kern.sysv.shmseg: 8
kern.sysv.shmmni: 32
kern.sysv.shmmin: 1
kern.sysv.shmmax: 4194304
(note that the shmall value is the number of 4K pages allowed)

And PostgreSQL, in its default configuration, uses up most of it:

$ ipcs -mb
IPC status from <running system> as of Thu Sep 25 14:14:38 CEST 2008
T ID KEY MODE OWNER GROUP SEGSZ
Shared Memory:
m 65536 0x0052e2c1 --rw------- postgres postgres 4038656

The remaining 152 KB are not enough for mplayer's video buffer.

Workaround

For the time being, a user can get things to work using this command:

sudo sysctl -w kern.sysv.shmall=2048

This doubles the limit to 2048 pages (8 MB), allowing MPlayer OS X to work even with PostgreSQL running. Note that for very high resolution videos even 4 MB might not be enough, in which case shmall needs to be increased further, and kern.sysv.shmmax (the maximum size of a single segment) will also need to be increased.

As a stopgap, MPlayer's error handling could at least be extended to give the user an explanation of the error and recommend a workaround in case shmget fails. But clearly, this is not an acceptable solution.

Solution

The methods Apple recommends for using shared memory on Mac OS X are mmap and POSIX-style shared memory objects. They can be combined by first creating a shmem object with shm_open and then mapping it using mmap, reproducing the functionality of shmget, but without the trouble with limits.

Change History (3)

comment:1 by compn, 16 years ago

you should talk to otvos atilla since those patches arent in mplayer svn.
http://onebithq.com/root/mplayer/videomixer

comment:2 by compn, 16 years ago

nevermind, ignore the above message.
reading too many bugreports i've lost my mind.

comment:3 by nicolas.plourde@…, 15 years ago

Resolution: fixed
Status: newclosed

use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@…>"

Note: See TracTickets for help on using tickets.