views:

121

answers:

4

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.

+1  A: 

Look at how mplayer and smplayer are implemented. mplayer decodes and shows the video, and smplayer is the (optional) GUI.

Thomas Padron-McCarthy
A: 

This is probably overkill, but since you don't want IPC, how about using a Client-Server framework? The GUI could be implemented such that it is reading from the decoder process. Or, even make the decoder process "push" data, as it is produced to the GUI. Depending on your choice, one could be the Client and the other, Server

Amit
+6  A: 

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.

gnud
Thanks a lot! That's what I want.
ablmf
+3  A: 

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

gby