Embedded Linux Multimedia - Odp
Embedded Linux Multimedia - Odp
systems
Multimedia
in embedded
Linux systems
Free Electrons
1
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Rights to copy
© Copyright 2004-2009, Free Electrons
feedback@free-electrons.com
4
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Quick Glossary (1)
Alpha channel:
A additional value in image pixels, describing
their opacity (1: opaque, 0: transparent)
Blitting: from BitBLT "Bit Block Transfer"
Copying image data (e.g. copying a surface on
another), applying image combination
operations.
Keying:
When compositing 2 image frames together,
removing parts of one according to a key (like
its color or brightness), to reveal the
corresponding part in the other.
5
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Quick Glossary (2)
6
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Multimedia in embedded Linux
systems
Multimedia libraries
SDL
7
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
SDL
QEMU: a CPU and system emulator Pig: a demo arcade game. 7000 lines.
9
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
SDL supported operating systems
10
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
SDL capabilities (1)
Video
Video mode setting at any depth (8-bpp or greater).
Automatic detection of the closest available mode.
Optional conversion if the video mode is not supported
by the hardware.
Writing directly to a linear graphics framebuffer.
Creating surfaces with colorkey or alpha blending
attributes.
Hardware accelerated blit and fill operations are used if
supported by the hardware (using MMX acceleration in
x86).
OpenGL support.
Facility to load BMP images.
11
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
SDL capabilities (2)
Events
Application visibility changes
Keyboard input
Mouse input
User-requested quit
Each event can be enabled or disabled with
SDL_EventState().
Events passed through a user-specified filter
function before being posted to the internal event
queue.
Thread-safe event queue.
12
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
SDL capabilities (3)
Audio
Audio playback of 8-bit and 16-bit audio, mono or
stereo.
Optional conversion if the format is not
supported by the hardware.
Audio run independently in a separate thread,
filled via a user callback mechanism.
CD-ROM audio
Complete CD audio control API
13
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
SDL capabilities (4)
15
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
SDL in embedded systems
16
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Additional SDL libraries
SDL_image: http://libsdl.org/projects/SDL_image/
Image loading library supporting JPEG, PNG, GIF,
BMP...
SDL_ttf: http://libsdl.org/projects/SDL_ttf/
TrueType font support library
SDL_mixer: http://libsdl.org/projects/SDL_mixer/
Sample multi-channel audio mixer library. Supports
Ogg, MP3, MIDI.
SDL_gfx: http://freshmeat.net/projects/sdl_gfx/
SDL graphics drawing primitives and other support
functions.
SAgl: http://freshmeat.net/projects/sagl/
Small Anti-aliased graphics library. 17
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Other free SDL libraries
18
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Free SDL applications (1)
19
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Free SDL applications (2)
Compiling
Easy to do with sdl-config:
gcc `sdl-config --cflags --libs` \ hello.c
-o hello
More examples
Plenty of code examples available on
http://www.libsdl.org/demos.php (check the
licenses).
22
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Useful reading about SDL
23
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Multimedia in embedded Linux
systems
Multimedia libraries
DirectFB
24
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
DirectFB
http://www.directfb.org/
License: LGPL
User space library developed for the special
requirements of embedded devices. Small, powerful,
flexible and easy to use.
Hardware accelerated graphics support. Software
fallbacks for operation not supported by the
underlying hardware.
Input device handling and abstraction.
Also supports SDL (when /dev/fb0 is not available).
Windowing system with support for translucent
windows.
Multiple layer support.
25
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
DirectFB screenshot
26
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
DirectFB in embedded systems
27
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
DirectFB graphical capabilities
User
DirectFB app. 1 DirectFB app. 2 DirectFB app. 3 space
Hardware
29
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
DirectFB implementation
30
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Input device support
Standard keyboards.
Serial and PS/2 mice.
Joysticks.
Devices using the Linux input layer (many!).
Infrared remote controls (using lirc).
Some touchscreens.
31
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
DirectFB image loading
32
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
DirectFB video playback
33
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
DirectFB font rendering
34
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
DirectFB API (1)
Retrieving information Get Capabi l i t i es Retrieve information about the video provider's capabilities.
Get Sur f aceDescr i pt i on Get a surface description that best matches the video
contained in the file.
Playback Pl ayTo Play the video rendering it into the specified rectangle of the
destination surface.
Color Adjustment Get Col or Adj ust ment Gets the current video color settings.
35
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
DirectFB API (2)
36
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
DirectFB API (3)
37
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
DirectFB API (4)
38
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
DirectFB Hello World
DirectFBInit(&argc, &argv);
DirectFBCreate(&dfb);
dfb->SetCooperativeLevel(dfb, DFSCL_FULLSCREEN);
memset(&dsc, 0, sizeof(DFBSurfaceDescription));
dsc.flags = DSDESC_CAPS;
dsc.caps = DSCAPS_PRIMARY;
dfb->CreateSurface(dfb, &dsc, &primary);
sleep(5);
primary->Release(primary);
dfb->Release(dfb);
39
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Compiling a DirectFB program
40
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Fusion
42
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Useful reading about DirectFB
DirectFB overview
http://www.directfb.org/docs/DirectFB_overview
_V0.2.pdf
43
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Multimedia in embedded Linux
systems
Kernel subsystems
Video4linux
44
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
V4L: video4linux subsystem
API: Documentation/video4linux/API.html
in the kernel sources (even in Linux 2.6).
Device files
/dev/video (minor 0-63): Video Capture
Interface
Of course, can read video input from several of
these devices:
/dev/video0, /dev/video1...
/dev/radio (minor 64-127): AM/FM Radio
Devices
/dev/vtx (minor 192-223): Teletext Interface
Chips
/dev/vbi (minor 224-239): Raw VBI Data 46
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
v4l2 new API
Also on Documentation/video4linux/API.html
Linux 2.4 no longer supported by V4L2.
Linux 2.6 ships the latest V4L2 versions
Development CVS snapshots available on
http://dl.bytesex.org/cvs-snapshots/.
Offers backward compatibility with V4L:
true for V4L applications, not for V4L drivers.
47
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
V4L2 API specification
48
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
A few V4L2 features
49
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Communicating with ioctl (1)
50
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Communicating with ioctl (2)
VIDIOC_QUERYCAP VIDIOC_ENUMSTD
Querying drivers capabilities Query supported video standards
VIDIOC_ENUMINPUT (PAL, NTSC...)
Querying the number, VIDIOC_QUERYCTRL
types and names of Query available controls
video connectors. VIDIOC_S_FMT
VIDIOC_G_FREQUENCY Setting the image format
Getting the tuner (including colorspace
frequency info)
VIDIOC_S_FREQUENCY VIDIOC_REQBUFS
Setting the tuner Asking the driver to
frequency allocate a buffer for
memory mapped I/O
52
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Concurrent access to /dev/video0
53
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
I/O modes
54
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
video4linux user tools
V4L
Lots of tools still seem to support only V4L.
Fortunately, the V4L2 high-level driver comes with a
backward compatibility layer which translates V4L ioctl
commands to V4L2 ones
Listed on http://www.exploits.org/v4l
V4L2
MPlayer (plugin)
DirectFB
Supports V4L2 devices as video providers for the display
More listed on
http://www.thedirks.org/v4l2/peopleprojects.htm
55
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
xawtv toolset (1)
56
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
xawtv toolset (2)
Kernel subsystems
Digital Video Broadcasting
59
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Digital Video Broadcasting
60
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
LinuxTV project
http://linuxtv.org/
LinuxTV is a vendor independent, non profit Linux
project that works on a standardized Linux DVB API
since 2000.
Version 3 of the Linux DVB API is included in Linux
2.6.
Very popular on PC systems, mostly in Europe and in
Australia.
Used by lots of Free Software projects and
commercial Set Top Boxes on different hardware
platforms.
61
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Multimedia in embedded Linux
systems
62
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
RealVideo
From RealNetworks
Free Software decoders
http://realnetworks.com/
available (mplayer)
Proprietary format
Supported by some
Originally used for low mobile phones.
bitrate streaming
Mainly used for
Supports streaming streaming, used by a
through the Real-time significant number of
Transport Protocol (RTP) on-line media.
http://en.wikipedia.org/wiki/Rea Only proprietary
lVideo
encoders. RealNetworks
encoder free of charge
only for personal use.
63
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
WMV
From DivXNetworks
http://divxnetworks.com/
DivX 3.11: hacked version DivX 4: MPEG 4 layer 2
of the Microsoft MPEG 4 compliant
layer 2 codec, which made
Free Software players
the codec popular.
available.
Able to shrink a 5-6 GB
Supported by most
DVD video to a file fitting
hardware video players too.
in a CDROM (700 MB) with
minimum quality loss. Still burdened by MPEG 4
patents. In some countries,
DivX 4 and later: clean
license needed to
room implementation from
implement or use a
DivXNetworks, to avoid
software or hardware
issues with Microsoft
player.
copyright. 66
See
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
XviD
From XviD.org
http://xvid.org/
Free Software codec, Many hardware players.
MPEG 4 based, competing Many Free Software
with DivX. players.
Started from DivXNetworks Still burdened by MPEG 4
OpenDivX, after access patents. In some
to its sources got closed. countries, license needed
License: GNU GPL. to implement or use a
software or hardware
player.
See
http://en.wikipedia.org/wik
i/XviD
67
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
Ogg Theora
Multimedia distributions
69
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
GeexBox
http://geexbox.org/
MPlayer based full featured home multimedia system:
Multimedia (DVD, DivX, CD, Ogg, MP3) and photo gallery.
Available through a live CD: boot your computer
with it, eject the CD, and load whatever media
you want to read.
Size: 6 MB.
Great for learning about a embedded
Linux media player!
Graphics: DirectFB.
Supported platforms: i386 and ppc.
Actively maintained.
70
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
MythTV
http://mythtv.org/
Set of Free Software applications to turn a PC into
a digital video recorder / digital multimedia
home entertainment system. Based on the QT library.
Requires TV tuner cards supported
by the video4linux(2) kernel drivers.
Lots of great features: commercial skipping,
access to free TV listings, DVD burning, web
browser, RSS news reader, IP telephony...
Can be tried through the KnoppMyth live CD:
http://en.wikipedia.org/wiki/Mythtv.
See http://en.wikipedia.org/wiki/Mythtv for details.
71
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http
FreeVo
http://freevo.sourceforge.net/
Another PC based digital multimedia
home entertainment system / personal
video recorder.
Supposed to be easy to install
for new users.
Based on the SDL library.
72
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http