Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On Linux, could a process render another process's GUI?

Tags:

linux

video

x11

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.

like image 856
ablmf Avatar asked Oct 25 '09 08:10

ablmf


3 Answers

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.

like image 171
gnud Avatar answered Nov 18 '22 01:11

gnud


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

like image 45
gby Avatar answered Nov 18 '22 02:11

gby


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

like image 1
Thomas Padron-McCarthy Avatar answered Nov 18 '22 01:11

Thomas Padron-McCarthy