I am writing a video player on Linux and I would like to separate it into 2 process :
A. decoder process B. GUI
In this way, I could use different programming languages and when a problem happens, it's easier to know where is the problem.
The problem is, could process A render decoded pictures onto B's surface directly? I don't want to use some IPC to send B these decoded data because that might be very inefficient.
You can use the XEmbed specification, which allows you to embed one X11 window inside another, and they might be from different processes. This is what other media player frontends typically do.
Both GTK and Qt support XEmbed.
IPC (especially a Unix pipe) is much more efficient then you think and it is probably the right mechanism to use.
However, since you asked how to do it without IPC (and I parse this to mean without context switches and copies), you can simply create a shared memory segment between the two processes:
fd = shm_open("/my_shmem", O_RDWR| O_CREAT, S_IWUSR);
if(fd == -1) abort();
ftruncate(fd, SHMEM_SIZE);
p = mmap(NULL, SHMEM_SIZE, PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0);
if(p == MAP_FAILED) abort()
Now p has the address to a shared memory segment shared by the two (or more) processes.
Warning! the numeric value of p (virtual address of memory) might be different between the processes, so if you want to put a linked list in the shared memory for example, you'd have to use offsets.
Cheers, gby
Look at how mplayer and smplayer are implemented. mplayer decodes and shows the video, and smplayer is the (optional) GUI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With