multimedia in embedded linux guide
DESCRIPTION
Presenting linux multimedia capabilitiesTRANSCRIPT
-
1FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
MultimediainembeddedLinuxsystems
MultimediainembeddedLinuxsystems
FreeElectrons
-
2FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
Rightstocopy
AttributionShareAlike3.0Youarefree
tocopy,distribute,display,andperformtheworktomakederivativeworkstomakecommercialuseofthework
UnderthefollowingconditionsAttribution.Youmustgivetheoriginalauthorcredit.ShareAlike.Ifyoualter,transform,orbuilduponthiswork,youmaydistributetheresultingworkonlyunderalicenseidenticaltothisone.
Foranyreuseordistribution,youmustmakecleartoothersthelicensetermsofthiswork.Anyoftheseconditionscanbewaivedifyougetpermissionfromthecopyrightholder.
Yourfairuseandotherrightsareinnowayaffectedbytheabove.Licensetext:http://creativecommons.org/licenses/bysa/3.0/legalcode
Copyright20042009,[email protected]
Documentsources,updatesandtranslations:http://freeelectrons.com/docs/multimedia
Corrections,suggestions,contributionsandtranslationsarewelcome!
Latestupdate:Sep15,2009
-
3FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
Scopeofthistraining
MultimediainembeddedLinuxsystemsThistrainingtargetsthedevelopmentofmultimediacapableembeddedLinuxsystems.ThoughitcanbeusefultoplayingorcreatingmultimediacontentonGNU/Linuxdesktops,itisnotmeanttocovereverythingaboutthistopic.
AudioinembeddedLinuxsystemsisalreadycoveredinadedicatedtraining:http://freeelectrons.com/training/audio
Linux2.6ThistrainingonlytargetsnewsystemsbasedontheLinux2.6kernel.Thisway,youleveragethemostadvancedtechnologyanddon'tlearnaboutsomethinggettingobsolete.
-
4FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
Contents
Introduction
Glossary
Multimedialibraries
SDL
DirectFB
Kernelsubsystems
Video4LinuxAPI
DVBAPI
FreeSoftwareVideo
Videocodecsandfileformats
Multimediadistributions
-
5FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
QuickGlossary(1)
Alphachannel:Aadditionalvalueinimagepixels,describingtheiropacity(1:opaque,0:transparent)
Blitting:fromBitBLT"BitBlockTransfer"Copyingimagedata(e.g.copyingasurfaceonanother),applyingimagecombinationoperations.
Keying:Whencompositing2imageframestogether,removingpartsofoneaccordingtoakey(likeitscolororbrightness),torevealthecorrespondingpartintheother.
-
6FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
QuickGlossary(2)
VBI:VerticalBlankingIntervalIntervalduringwhichthetransmissionofavideosignalissuspendedtolettheelectrongungobacktothefirstscreenline.Usedtotransmitextradata,suchasteletext.
Seehttp://wikipedia.orgfordetails!
-
7FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
MultimediainembeddedLinuxsystems
MultimedialibrariesSDL
-
8FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
SDL
SimpleDirectMediaLayerhttp://libsdl.org/License:LGPL
Crossplatformmultimedialibrary
Originallycreatedforwritinggames,bySamLantinga,forLokiEntertainmentSoftware,specializinginportinggamestoGNU/Linux.
Provideslowlevelaccesstoaudio,keyboard,mouse,joystick,3DhardwareviaOpenGL,and2Dvideoframebuffer.
NativeCAPIBindingsavailableformostprogrammingandscriptinglanguages
-
9FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
SDLscreenshots
Pig:ademoarcadegame.7000lines.QEMU:aCPUandsystememulator
-
10FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
SDLsupportedoperatingsystems
Officiallysupports:Linux,Windows,WindowsCE,BeOS,MacOS,MacOSX,FreeBSD,NetBSD,OpenBSD,BSD/OS,Solaris,IRIX,andQNX.
Codewithnoofficialsupport:AmigaOS,Dreamcast,Atari,AIX,OSF/Tru64,RISCOS,SymbianOSandOS/2.
Makesitveryeasytocreateplatformindependentapplications!
-
11FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
SDLcapabilities(1)
Video
Videomodesettingatanydepth(8bpporgreater).Automaticdetectionoftheclosestavailablemode.Optionalconversionifthevideomodeisnotsupportedbythehardware.
Writingdirectlytoalineargraphicsframebuffer.
Creatingsurfaceswithcolorkeyoralphablendingattributes.
Hardwareacceleratedblitandfilloperationsareusedifsupportedbythehardware(usingMMXaccelerationinx86).
OpenGLsupport.
FacilitytoloadBMPimages.
-
12FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
SDLcapabilities(2)
Events
Applicationvisibilitychanges
Keyboardinput
Mouseinput
Userrequestedquit
EacheventcanbeenabledordisabledwithSDL_EventState().
Eventspassedthroughauserspecifiedfilterfunctionbeforebeingpostedtotheinternaleventqueue.
Threadsafeeventqueue.
-
13FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
SDLcapabilities(3)
Audio
Audioplaybackof8bitand16bitaudio,monoorstereo.Optionalconversioniftheformatisnotsupportedbythehardware.
Audiorunindependentlyinaseparatethread,filledviaausercallbackmechanism.
CDROMaudio
CompleteCDaudiocontrolAPI
-
14FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
SDLcapabilities(4)
Threads
SimplethreadcreationAPI.
Simplebinarysemaphoresforsynchronization.
Timers
Measureelapsedmilliseconds.
Waitfornmilliseconds.
Setasingleperiodictimerwith10msresolution.
Endianindependence
Detecttheendianismofthecurrentsystem.
Routinesforfastswappingofdatavalues.
Readandwritedataofaspecifiedendianism.
-
15FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
SDLimplementationonGNU/Linux
Videodisplay.Eitheruses
X11:takingadvantageofXFree86DGAextensionsandnewMTRRaccelerationforfullscreendisplay.
OrDirectFB(seethenextsection)
UsestheOSSAPIforsound.FineforLinuxsystemswithALSA,thankstoOSSemulation.
Threadsareimplementedusingeithertheclone()systemcallandSysVIPC,orglibc2.1pthreads.
-
16FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
SDLinembeddedsystems
ShouldworkonanyplatformsupportingLinux.
EvenrunsonlightweightdeviceswithoutX11.Aframebufferdriverissufficient(usingtheDirectFBAPI).
Usefultodevelopyourapplicationonthehostinparallelwithtargetsystemdevelopment.
Facilitiestosupportthetargetendianism.
-
17FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
AdditionalSDLlibraries
SDL_image:http://libsdl.org/projects/SDL_image/ImageloadinglibrarysupportingJPEG,PNG,GIF,BMP...
SDL_ttf:http://libsdl.org/projects/SDL_ttf/TrueTypefontsupportlibrary
SDL_mixer:http://libsdl.org/projects/SDL_mixer/Samplemultichannelaudiomixerlibrary.SupportsOgg,MP3,MIDI.
SDL_gfx:http://freshmeat.net/projects/sdl_gfx/SDLgraphicsdrawingprimitivesandothersupportfunctions.
SAgl:http://freshmeat.net/projects/sagl/SmallAntialiasedgraphicslibrary.
-
18FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
OtherfreeSDLlibraries
Listedonhttp://libsdl.org/libraries.php
Lotsoflibrariestoeasethedevelopmentofgames,inparticulargameengines!
Manygraphics,GUIandOpenGLlibraries.
GlyphKeeperTrueTypefontrenderinglibrary.
FastEventsAfastthreadbasedreplacementforSDLeventroutines.
KyraAsimpleandpowerfulSpriteenginewritteninC++.
-
19FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
FreeSDLapplications(1)
Alistisavailableonhttp://libsdl.org/applications.php
Veryactivedevelopment.
Lotsofgames,ofcourse!
Asignificantnumberofsystememulators.Example:QEMU(http://qemu.org).
Somemultimediavisualizationplugins(e.g.forxmms).
OpenPictureSpace2http://membres.lycos.fr/mavati/openpicturespace2/Showspicturesinadirectorythroughthumbnails.
-
20FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
FreeSDLapplications(2)
MPEGMenuSystemVersion2http://mms.sunsite.dk/
Menusystemforeasymovie,audioandimageplayback.ElectronicTVprogramguide.
SupportsMP3,OGG,DivX,XviD,VCD,SVCD,DVD,JPEG,PNG,andGIF
Controlledusingaremotecontrolorkeyboard
-
21FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
GettingstartedwithSDLHelloWorld
#include "SDL.h"
int main( int argc, char* argv[] ){
/* initialize SDL */SDL_Init(SDL_INIT_VIDEO);
/* set the title bar */SDL_WM_SetCaption("SDL Test", "SDL Test");
/* create window */SDL_Surface* screen = SDL_SetVideoMode(640, 480, 0, 0);
/* load bitmap to temp surface */SDL_Surface* temp = SDL_LoadBMP("hello.bmp");
/* convert bitmap to display format */SDL_Surface* bg = SDL_DisplayFormat(temp);
/* free the temp surface */SDL_FreeSurface(temp);
SDL_Event event;int gameover = 0;
/* message pump */while (!gameover){
/* look for an event */if (SDL_PollEvent(&event)) {
/* an event was found */switch (event.type) {
/* close button clicked */case SDL_QUIT:
gameover = 1;break;
/* handle the keyboard */case SDL_KEYDOWN:
switch (event.key.keysym.sym) {case SDLK_ESCAPE:case SDLK_q:
gameover = 1;break;
}break;
}}
/* draw the background */SDL_BlitSurface(bg, NULL, screen, NULL);
/* update the screen */SDL_UpdateRect(screen, 0, 0, 0, 0);
}
/* free the background surface */SDL_FreeSurface(bg);
/* cleanup SDL */SDL_Quit();
return 0;}
ThankstoTony(http://tonyandpaige.com)fortheexample!
-
22FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
GettingstartedwithSDL(2)
Compiling
Easytodowithsdlconfig:gcc`sdlconfigcflagslibs`\hello.cohello
Moreexamples
Plentyofcodeexamplesavailableonhttp://www.libsdl.org/demos.php(checkthelicenses).
-
23FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
UsefulreadingaboutSDL
2niceintroductionstothedifferentpartsoftheAPIthroughsimpleexamples.
SDLIntroduction,bySamLantingahttp://www.libsdl.org/intro.php
SDLLibraryDocumentationhttp://www.libsdl.org/cgi/docwiki.cgi/
3niceSDLtutorialswithsimpleexampleshttp://andrew.textux.com/Articles.html
-
24FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
MultimediainembeddedLinuxsystems
MultimedialibrariesDirectFB
-
25FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
DirectFB
http://www.directfb.org/License:LGPL
Userspacelibrarydevelopedforthespecialrequirementsofembeddeddevices.Small,powerful,flexibleandeasytouse.
Hardwareacceleratedgraphicssupport.Softwarefallbacksforoperationnotsupportedbytheunderlyinghardware.
Inputdevicehandlingandabstraction.
AlsosupportsSDL(when/dev/fb0isnotavailable).
Windowingsystemwithsupportfortranslucentwindows.
Multiplelayersupport.
-
26FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
DirectFBscreenshot
DemoofthenewTextureTriangles()methodusingexistingwindowsastextures(updatedinrealtime)
-
27FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
DirectFBinembeddedsystems
Extravalueinembeddedsystems
NoneedtorunaXserverusingdiskspaceandCPU.
Lightweight:veryfewgraphicslibrariesneeded.
Yourinterfacescanbeverysimple.Theydon'thavetohavethelookandfeelofdesktopapplications.
Portability:youcandevelopyourapplicationonthePChostwhilethetargetisstillunderdevelopment.
-
28FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
DirectFBgraphicalcapabilities
Rectanglefilling/drawing.
Trianglefilling/drawing.
Linedrawing.
Flatshadedtriangles.
Simpleblitting.
Stretchedblitting.
Texturedtriangles(perspectivecorrect).
Blendingwithanalphachannel(perpixelalpha).
Blendingwithanalphafactor(alphamodulation).
Ninesourceanddestinationblendfunctions.
Porter/Duffimagecompositionrulessupport.
Premultipliedalphasupported.
Colorizedblitting(colormodulation).
Sourcecolorkeying.
Destinationcolorkeying.
-
29FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
DirectFBoperation
Framebuffer Timingandmoderegisters
Accelerator
Framebufferdriver
DirectFBlibrary
DirectFBapp.2DirectFBapp.1 DirectFBapp.3
Chipsetdriver
Userspace
Kernelspace
Hardware
DisabledwhenDirectFBisused
mmap mappingI/Oregisters
-
30FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
DirectFBimplementation
Writingtotheframebuffer:directlywritestothememorymappedgraphicsdevicevideoRAM.
Accessinghardwareaccelerationcontrols:directlywritestothememorymappedgraphicsdeviceI/Oports.
-
31FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
Inputdevicesupport
Standardkeyboards.
SerialandPS/2mice.
Joysticks.
DevicesusingtheLinuxinputlayer(many!).
Infraredremotecontrols(usinglirc).
Sometouchscreens.
-
32FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
DirectFBimageloading
Thelibraryincludesimageproviders,whichallowtoloadimagesdirectlyintoDirectFBsurfaces:
JPEG(usinglibjpeg).
PNG(usinglibpng2).
GIF(builtin).
Variousotherimageformats(usingimlib2).
-
33FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
DirectFBvideoplayback
Includesdifferentvideoproviders,forrenderinginDirectFBsurfaces:
V4L(Video4Linux)andV4L2(/dev/video).
mpeg1/2(usinglibmpeg3).
AVI(usingavifile).
MOV(usingOpenQuicktime).
Flash(usinglibflash).
-
34FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
DirectFBfontrendering
Supportsantialiasedtext,andsupportsfontloadingthrough2providers:
DirectFBbitmapfont.
TrueType(usingFreeType2).
-
35FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
DirectFBAPI(1)
NativeAPIavailableinC.
13interfacesorproviders:structureswithfunctionpointers.Example:
Methods of IDirectFBVideoProvider
Retrieving information GetCapabilities Retrieve information about the video provider's capabilities.
GetSurfaceDescription Get a surface description that best matches the videocontained in the file.
Playback PlayTo Play the video rendering it into the specified rectangle of thedestination surface.
Stop Stop rendering into the destination surface.
Media Control SeekTo Seeks to a position within the stream.
GetPos Gets current position within the stream.
GetLength Gets the length of the stream.
Color Adjustment GetColorAdjustment Gets the current video color settings.
SetColorAdjustment Adjusts the video colors.
-
36FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
DirectFBAPI(2)
Morethan120types:datastructures.Example:DFBTriangleint x1; Xcoordinateoffirstedgeint y1; Ycoordinateoffirstedgeint x2; Xcoordinateofsecondedgeint y2; Ycoordinateofsecondedgeint x3; Xcoordinateofthirdedgeint y3; Ycoordinateofthirdedge
DFBScreenEncoderTVStandardsDSETV_UNKNOWN UnknownstandardDSETV_PAL PALDSETV_NTSC NTSCDSETV_SECAM SECAM
-
37FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
DirectFBAPI(3)
9definitions:macrostosimplifycode.Examples:
DFB_COLOR_EQUAL(x,y)Macrotocomparetwocolors.
DFB_DISPLAYLAYER_IDS_MAXMaximumnumberoflayerids.
DFB_DISPLAYLAYER_IDS_ADD(ids,id)Addstheidtothebitmaskoflayerids.
FullAPIdocumentationavailableonhttp://directfb.org/docs/DirectFB_Reference/
-
38FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
DirectFBAPI(4)
Onlyafewglobalfunctions
DirectFBInit(argc,argv)
DirectFBCreate(IDirectFB**dfb);
Then,throughtheIDirectFBinterface,itispossibletoworkonsurfaces,inputdevices,displaylayers,screens,mediafiles,etc.
Forexample,thedfb>CreateSurface()methodwillreturnaIDirectFBSurfaceinterfacepointer
TheIdirectFBSurfacethencontainsmethodstomanipulatethesurface:flipping,blitting,drawing,etc.
-
39FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
DirectFBHelloWorld
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);
dfb>CreateImageProvider(dfb,"test.png",&provider);provider>RenderTo(provider,primary,NULL);provider>Release(provider);
sleep(5);
primary>Release(primary);dfb>Release(dfb);
-
40FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
CompilingaDirectFBprogram
That'sveryeasytodothankstopkgconfig:
gcc`pkgconfigcflagsdirectfb`otesttest.c`pkgconfiglibsdirectfb`
pkgconfigisusedtoqueryneededClibraryheadersandsharedobjects.
-
41FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
Fusion
MakesitpossibleformultipleDirectFBapplicationstorunsimultaneously.
LayerusedbyDirectFBapplicationstocommunicate.
Previouslyimplementedcompletelyinuserspaceusingsemaphoresandmessagequeues..
NowcriticalpartsofFusionareimplementedinkernelspace(FusionKernelDevice),whichprovidesbetterperformanceandstability.SupportsbothLinux2.4and2.6.
LinuxkernelpatchavailableintheCoredownloadspage(linuxfusionmodule).
-
42FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
AfewDirectFBapplications
ByzantineOS,GeexBoxHomeentertainment
DBFSeeImageviewerandvideoplayer
DFBTermTerminalapplication
XDirectFBRootlessXServerusingDirectFBwindows.UsefultorunanyXwindowsapp.
ApplicationswithDirectFBbackends
gdkdirectfbDirectFBGDKforGTK
MPlayerDirectFBbackendsince2001.
SDLAlsohasaDirectFBbackend!
Moreonhttp://directfb.org!
-
43FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
UsefulreadingaboutDirectFB
DirectFBoverviewhttp://www.directfb.org/docs/DirectFB_overview_V0.2.pdfAniceandsyntheticarticle!
-
44FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
MultimediainembeddedLinuxsystems
KernelsubsystemsVideo4linux
-
45FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
V4L:video4linuxsubsystem
Providessupportforaudio/videocaptureandoverlaydevicesandFMradio
V4L:Originalvideocapture/overlayAPIoftheLinuxkernel.Appearedinthe2.1.xdevelopmentcycleoftheLinuxkernel.
V4L2:Secondgenerationofthevideo4linuxAPIfixinganumberofdesignbugs.Integratedintothestandardkernelin2.5.x.Notsupportedyetbyalldrivers.
Mainwebpages:
VideoforLinuxresources:http://www.exploits.org/v4l
video4linuxHQ:http://linux.bytesex.org/v4l2/
-
46FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
v4loriginalAPI
API:Documentation/video4linux/API.htmlinthekernelsources(eveninLinux2.6).
Devicefiles
/dev/video(minor063):VideoCaptureInterfaceOfcourse,canreadvideoinputfromseveralofthesedevices:/dev/video0,/dev/video1...
/dev/radio(minor64127):AM/FMRadioDevices
/dev/vtx(minor192223):TeletextInterfaceChips
/dev/vbi(minor224239):RawVBIData(Intercast/teletext)
-
47FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
v4l2newAPI
AlsoonDocumentation/video4linux/API.html
Linux2.4nolongersupportedbyV4L2.
Linux2.6shipsthelatestV4L2versionsDevelopmentCVSsnapshotsavailableonhttp://dl.bytesex.org/cvssnapshots/.
OffersbackwardcompatibilitywithV4L:trueforV4Lapplications,notforV4Ldrivers.
-
48FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
V4L2APIspecification
NewAPIspecification:http://v4l2spec.bytesex.org/spec/ByMichaelH.SchimekandBillDirks
Averyexhaustivedocument(Oct2007:280pages!)
Specifiesalldetailsabouttheinterfaceadrivershouldimplement.Lotsofcodeexamples.
Providesdetailsaboutapplicationprogrammingtoo.
Alotoftechnicalbackgroundprovidedtoo!
Readthislikeareferencebook!
-
49FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
AfewV4L2features
Devices:Usesthesamedevicefiles,butit'suptothesystemadministratortoassignminornumbers.
Multipleopens:maysupportconcurrentaccessto/dev/files,forexampletocontrolbrightnessorcolor(panelapplication)whileanotherapplicationisplayingthevideo.
Standardcontrols:theAPIdefineshardwareindependentdevicecontrols(brightness,colorsaturation,etc),andawaytoenumerateavailablecontrols.Applicationscanbedriverindependent.
-
50FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
Communicatingwithioctl(1)
Afewdetailsabouttheioctl()systemcallareneededtounderstandhowavideo4linuxclientapplicationcaninteractwithavideo4linuxdriver.
Prototype:
#includeintioctl(intfd,intrequest,void*argp);
fd:filedescriptor(theopenedfile)
request:anioctlnumber,supportedbythedriver
argp:argumentstringorpointertoavalueorstructurereturnedbythedriver.
-
51FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
Communicatingwithioctl(2)
ioctlisusedtointeractwiththedriverhandlingtheopeneddevicefile,withouthavingtoreadorwritedata.
ToaccessaparticularsettingofthedriverExample:gettingtheserialnumberoftheunderlyinghardware.
TosetaparticulardriversettingExample:settingthespeedandflowcontrolofaserialport.
TohavethedriverperformaspecialoperationExample:formattingafloppydisk.
-
52FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
AfewV4L2ioctlnumberexamples
VIDIOC_QUERYCAPQueryingdriverscapabilities
VIDIOC_ENUMINPUTQueryingthenumber,typesandnamesofvideoconnectors.
VIDIOC_G_FREQUENCYGettingthetunerfrequency
VIDIOC_S_FREQUENCYSettingthetunerfrequency
VIDIOC_ENUMSTDQuerysupportedvideostandards(PAL,NTSC...)
VIDIOC_QUERYCTRLQueryavailablecontrols
VIDIOC_S_FMTSettingtheimageformat(includingcolorspaceinfo)
VIDIOC_REQBUFSAskingthedrivertoallocateabufferformemorymappedI/O
-
53FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
Concurrentaccessto/dev/video0
/dev/video0Driver
Hardware
App1(fd1) App2(fd2)
ioctl() ioctl()
read()write()
IdentifyingApp1andApp2bydifferentfiledescriptors,thedrivercansendthemdifferentdata.
-
54FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
I/Omodes
SeveralI/Omodescanbeproposedbythedriver
read()andwrite()Standardwayofaccessingdata.Basicbutcanstillbeefficient(canuseDMAinternally).Butcan'tcarrymetainformationlikeframecountersortimestamps.
StreamingI/O(memorymapping)Sharingpointerstomemorymappedbuffers(mmap),allocatedbythedriver.Nodatacopying.Bufferscan'tbeswappedouttodisk.
StreamingI/O(userpointers)Sharingpointerstoapplicationallocatedmemorybuffers.Bufferscanresideinsharedorvirtualmemory(canbeswappedout).
-
55FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
video4linuxusertools
V4L
LotsoftoolsstillseemtosupportonlyV4L.Fortunately,theV4L2highleveldrivercomeswithabackwardcompatibilitylayerwhichtranslatesV4LioctlcommandstoV4L2ones
Listedonhttp://www.exploits.org/v4l
V4L2
MPlayer(plugin)
DirectFBSupportsV4L2devicesasvideoprovidersforthedisplay
Morelistedonhttp://www.thedirks.org/v4l2/peopleprojects.htm
-
56FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
xawtvtoolset(1)
X11applications
xawtvWatchingTV
motvMotifbasedTVGUI
mttTextorMotifteletextbrowser
piaSimplemovieplayer
Commandline/consoletools
fbtvFramebufferTVapplication
streamerRecordingmovies
v4lctlSettingV4L2parameters
AsetofV4L2compatibletoolsforwatchingTV,recordingvideo,browsingteletext...http://linux.bytesex.org/xawtv/
-
57FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
xawtvtoolset(2)
Console/commandlinetools
scantvChannelscanner
radioSimple,cursesbasedradioapplication.
webcamCapturesimagesanduploadsthemtoaWebServer
alevtdhttpserverforvideotextpages
Fontshttp://linux.bytesex.org/xawtv/tvfonts.html
ledfixedBigfontusedbyxawtvforonscreendisplay.
etsteletextTeletextfont.Blockgraphiccharacters.
etscaptionFontforclosedcaptions(audiosubtitlesandscenedescription).
-
58FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
Writingtoscreens
Videoisbestwhenyoucanwatchit!
Needtochooseanexistingapplicationdisplayingvideo
Orcreateyourownusingagivenmultimediacapablelibrary:DirectFB,SDL...
2waysofaccessingthegraphics:Xserverorframebufferbased(mainlyDirectFBorQtopiaCore)
Anyway,youmostprobablywon'thavetoaccessthedisplaybyyourself,butthroughthelowlevellibrary.
Supportingvideocodecsinacustomapplication.Besttorelyongstreamer:http://gstreamer.freedesktop.org/
-
59FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
MultimediainembeddedLinuxsystems
KernelsubsystemsDigitalVideoBroadcasting
-
60FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
DigitalVideoBroadcasting
DVB:DigitalVideoBroadcasting
DVBProject:http://www.dvb.org/
Since1993,industryledconsortiumofbroadcasters,manufacturers,networkoperators,softwaredevelopers,regulatorybodiesandothersinterestedinstandardsforthedeliveryofanydigitaltelevisionanddataservices.
CommittedtoopenstandardsStandardspecificationssupposedtobeavailablefreeofcharge(registrationrequired)fromETSI(EuropeanTelecommunicationStandardsInstitute)athttp://www.etsi.org/.
BasedonMPEG2transportstreams.
-
61FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
LinuxTVproject
http://linuxtv.org/
LinuxTVisavendorindependent,nonprofitLinuxprojectthatworksonastandardizedLinuxDVBAPIsince2000.
Version3oftheLinuxDVBAPIisincludedinLinux2.6.
VerypopularonPCsystems,mostlyinEuropeandinAustralia.
UsedbylotsofFreeSoftwareprojectsandcommercialSetTopBoxesondifferenthardwareplatforms.
-
62FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
MultimediainembeddedLinuxsystems
FreeSoftwareVideoVideocodecsandfileformats
-
63FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
RealVideo
FromRealNetworkshttp://realnetworks.com/
Proprietaryformat
Originallyusedforlowbitratestreaming
SupportsstreamingthroughtheRealtimeTransportProtocol(RTP)
http://en.wikipedia.org/wiki/RealVideo
FreeSoftwaredecodersavailable(mplayer)
Supportedbysomemobilephones.
Mainlyusedforstreaming,usedbyasignificantnumberofonlinemedia.
Onlyproprietaryencoders.RealNetworksencoderfreeofchargeonlyforpersonaluse.
-
64FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
WMV
WindowsMediaVideo
Proprietaryvideocodec:Microsoft'snonstandardMPEG4implementation.
OftencomeswithWMAforAudio.
PackedintoAVIorAdvancedStreamingFormat(ASF)container.
SupportsDRMencryption.
Nowmanyhardwareplayersavailable.
Notmanyfilesownedbyusers(preferDivXorXviD).
However,moreandmoreonlinestreamsavailableinthisformat.Customersarelikelytoexpectsupportforthisformatinahardwareplayer.
LackofFreeSoftwareplayers(exceptlibavcodec)andencoders.
Reliesonpatentedalgorithms.
Licensesmayapplytoencoding,decodingorevensongs,thoughMSisstillverytolerantsofar(toachievedomination).
-
65FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
QuickTime
FromAppleComputerhttp://apple.com/quicktime/
Multimediatechnologysupportingseveraldigitalvideoformats,sound,text,animation,music,andvirtualrealitypanoramicimages.
Openfileformat1998:ApprovedbyISOasthebasisfortheMPEG4standard
MPEG4compatibilitysince2002.
VideooftenencodedwiththeSorensonproprietarycodec.
FewusershaveQuickTimevideosandwillaskforQuickTimesupport.
NoFreeSoftwareencodersSorensonpatentlicensewouldbeneededanywayinsomecountries.
Just1FreeSoftwaredecoder(FFmpeg'slibavcodec).
Moreonhttp://en.wikipedia.org/wiki/Quicktime
-
66FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
DivX
FromDivXNetworkshttp://divxnetworks.com/
DivX3.11:hackedversionoftheMicrosoftMPEG4layer2codec,whichmadethecodecpopular.
Abletoshrinka56GBDVDvideotoafilefittinginaCDROM(700MB)withminimumqualityloss.
DivX4andlater:cleanroomimplementationfromDivXNetworks,toavoidissueswithMicrosoftcopyright.
DivX4:MPEG4layer2compliant
FreeSoftwareplayersavailable.
Supportedbymosthardwarevideoplayerstoo.
StillburdenedbyMPEG4patents.Insomecountries,licenseneededtoimplementoruseasoftwareorhardwareplayer.
Seehttp://en.wikipedia.org/wiki/DivX
-
67FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
XviD
FromXviD.orghttp://xvid.org/
FreeSoftwarecodec,MPEG4based,competingwithDivX.
StartedfromDivXNetworksOpenDivX,afteraccesstoitssourcesgotclosed.
License:GNUGPL.
Manyhardwareplayers.
ManyFreeSoftwareplayers.
StillburdenedbyMPEG4patents.Insomecountries,licenseneededtoimplementoruseasoftwareorhardwareplayer.
Seehttp://en.wikipedia.org/wiki/XviD
-
68FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
OggTheora
FromXiph.orghttp://theora.org/
Ogg:containerformultimediastreams.
Theora:videocodeccompetingwithMPEG4,RealVideoandWMV.
DerivedfromOn2TechnologiesVP3codec.On2irrevocablygrantedtoanyonearoyaltyfreelicensetouseallitsVP3patents.
VorbisorFlac:soundlayer
TheoralibraryavailableunderaBSDstylelicense.
Theoraalreadysupportedbyvarioussoftwareplayers.
Theoralibrarystillinbetastage,butgettingclosetoastablerelease.Anyway,thebitstreamformatisfrozenandwillbesupportedbyallfutureversions.
Veryrarehardwareplayers
-
69FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
MultimediainembeddedLinuxsystems
Multimediadistributions
-
70FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
GeexBox
http://geexbox.org/
MPlayerbasedfullfeaturedhomemultimediasystem:Multimedia(DVD,DivX,CD,Ogg,MP3)andphotogallery.
AvailablethroughaliveCD:bootyourcomputerwithit,ejecttheCD,andloadwhatevermediayouwanttoread.
Size:6MB.GreatforlearningaboutaembeddedLinuxmediaplayer!
Graphics:DirectFB.
Supportedplatforms:i386andppc.Activelymaintained.
-
71FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
MythTV
http://mythtv.org/
SetofFreeSoftwareapplicationstoturnaPCintoadigitalvideorecorder/digitalmultimediahomeentertainmentsystem.BasedontheQTlibrary.
RequiresTVtunercardssupportedbythevideo4linux(2)kerneldrivers.
Lotsofgreatfeatures:commercialskipping,accesstofreeTVlistings,DVDburning,webbrowser,RSSnewsreader,IPtelephony...
CanbetriedthroughtheKnoppMythliveCD:http://en.wikipedia.org/wiki/Mythtv.
Seehttp://en.wikipedia.org/wiki/Mythtvfordetails.
-
72FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
FreeVo
http://freevo.sourceforge.net/
AnotherPCbaseddigitalmultimediahomeentertainmentsystem/personalvideorecorder.
Supposedtobeeasytoinstallfornewusers.
BasedontheSDLlibrary.
-
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
Relateddocuments
Allourtechnicalpresentationsonhttp://freeelectrons.com/docs
LinuxkernelDevicedriversArchitecturespecificsEmbeddedLinuxsystemdevelopment
-
FreeElectrons.Kernel,driversandembeddedLinuxdevelopment,consulting,trainingandsupport.http//freeelectrons.com
Howtohelp
Youcanhelpustoimproveandmaintainthisdocument...
Bysendingcorrections,suggestions,contributionsandtranslations
Byaskingyourorganizationtoorderdevelopment,consultingandtrainingservicesperformedbytheauthorsofthesedocuments(seehttp://freeelectrons.com/).
Bysharingthisdocumentwithyourfriends,colleaguesandwiththelocalFreeSoftwarecommunity.
Byaddinglinksonyourwebsitetoouronlinematerials,toincreasetheirvisibilityinsearchengineresults.
-
CustomDevelopment
SystemintegrationEmbeddedLinuxdemosandprototypesSystemoptimizationApplicationandinterfacedevelopment
FreeElectronsOurservices
EmbeddedLinuxTraining
Allmaterialsreleasedwithafreelicense!
UnixandGNU/LinuxbasicsLinuxkernelanddriversdevelopmentRealtimeLinux,uClinuxDevelopmentandprofilingtoolsLightweighttoolsforembeddedsystemsRootfilesystemcreationAudioandmultimediaSystemoptimization
Consultingandtechnicalsupport
HelpindecisionmakingSystemarchitectureSystemdesignandperformancereviewDevelopmenttoolandapplicationsupportInvestigatingissuesandfixingtoolbugs
Linuxkernel
LinuxdevicedriversBoardsupportcodeMainstreamingkernelcodeKerneldebugging