23

I'm running a Ubuntu 12.04 LTS as a home NAS server, without X. Recently I got into tuning it to serve as a video playing media device too. It might've been easier at this point to install X, but I decided to try mplayer with framebuffer playback. It worked, and everything was fine and good.

However, for curiosity and maybe for practical consequences too, I can't stop thinking about framebuffers. There seems to be only one framebuffer device, /dev/fb0. (Btw. I'm using vesafs driver) If I run multiple programs that use framebuffers, chaos ensues. For example, running mplayer from fbterm just crashes it. Curiously, fbi image viewer manages to view images somehow. Obviously the programs can't share the device, there's no windowing system after all.

So, is the number of (vesa) fb devices limited to hardware display devices? Or could there be more in principle, like there are multiple ttys? Would adding some more help running simultaneously software that uses them? How could I add more?

Also the logic how the framebuffers are connected to ttys isn't quite clear to me... for example, mplayer shows it's video frame on every tty, but fbi doesn't. Furthermore, Ubuntu default console (fbcon?) shows behind the video overlay, which srikes me odd. What is this all about?

1 Answer 1

27

Since nobody's answered yet, and after tedious hours of googling and testing, I got some grasp of the subject, I'm going to answer it...

Since framebuffer device interface is a quite general one, there could be more fb devices in principle. However, as the VESA driver I used provides a direct connection between a certain hardware device and the framebuffer device file, it doesn't make sense to have more of them than one has real devices.

There's a driver for virtual framebuffer devices, vfb. (Note: different from xvfb which is a virtual framebuffer for X) I haven't tested this myself, but one could have as many fb devices as one wants using the virtual device. I also think that nothing in principle prevents one from piping a virtual device to hardware framebuffer device, allowing to build a framebuffer multiplexer

About the connection between framebuffers and tty's: there is none. The framebuffer is simply drawn to the screen, disregarding anything.

What got me originally confused is the behavior of fbi image viewer. It turns out that it cleverly checks whether the tty it's running in is open or not, and draws to the framebuffer or not according to that. (That's why it refuses to run over SSH, unlike mplayer – it doesn't accept a pseudo terminal.) But the multiplexer-like functionality has got NOTHING to do with the framebuffer itself.

If there's multiple processes writing to framebuffer, they do not block each other. It turns out that my earlier problems (crashes and such) using multiple fb programs simultaneously were not even about the framebuffer at all. Take fbterm terminal and run mplayer from it: no problem. The fbterm and fbcon terminals and the fbi image viewer draw to buffer only when something is updated, so the mplayer dominates the screen virtually 100% of the time. But if you try to run two mplayers, you are going to get a view that flickers showing frames of the one and the other, as they try to draw to the buffer having a race condition.

Some useful links:

http://moi.vonos.net/linux/framebuffer-drivers/

https://www.kernel.org/doc/Documentation/fb/framebuffer.txt

1
  • If you have a small LCD 2nd display as secondary (think 320x240 pixels, 3 inches) using fb1 makes sense for that. I have a little Adafruit adafruit.com/product/1601 one that uses (only) fb1. Their software is open source, but their OS image tries to run Linux with a GUI in 320x240 and fails miserably. As a 2nd device it might be OK, I haven't used it in a couple years. See man mknod.
    – Alan Corey
    Feb 22, 2019 at 15:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .