Digital TV on Linux Mauro Carvalho Chehab Linux Kernel Expert Samsung Open Source Group Oct 14, 2014 Open Source Group – Silicon Valley Samsung Research Brazil Not to be used for commercial purpose without getting permission All information herein are my own and may not represent the company's positions, strategies or opinions © 2014 SAMSUNG Electronics Co. Digital TV challenges ● Major standards: – – – – ATSC - Advanced Television System Committee ● Defined in United States DVB - Digital Video Broadcasting ● Defined in Europe ISDB – Integrated Services Digital Broadcasting Terrestrial ● Defined in Japan DTMB - Digital Terrestrial Multimedia Broadcast ● Defined in China Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. Digital TV challenges ● Digital TV variants: – – – Terrestrial (air) standards are used by air broadcasts: ATSC, DVB-T, DVB-T2, ISDB-T, DMB; Cable standards are used by cable operators: DVB-C, DVB-C2, ClearQAM (DVB-C Annex B), ISDB-C; Satellite standards are used by Satellite operators: DVB-S, DVB-S2, ISDB-S. Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. Digital TV Terrestrial Standards Source: http://en.wikipedia.org/wiki/File:Digital_broadcast_standards.svg Note: DVB-T2 is gradually replacing DVB-T Open Source Group – Silicon Valley Samsung Research Brazil Updated in May, 2014 © 2014 SAMSUNG Electronics Co. TV Digital standards Audio Elem. Stream Video Elem. Stream MPEG2-BC 280i LD Channel 480iSDTV DOLBY AC3 MPEG4AAC 720pEDTV 1080iHDTV MPEG4 MPEG2 MPEG2 – Transport Stream Transport Modulation MPEG2AAC VSB QAM QPSK COFDM COFDM-BST TDS-OFDM 1.7 Mhz 5 Mhz 6 Mhz 7 Mhz 8 Mhz 10 Mhz Copyright © 2006-2014 Mauro Carvalho Chehab – GPLv2 licensed Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. TV Digital Linux Mapping Userspace Audio Elem. Stream Video Elem. Stream MPEG2-BC 280i LD Channel 480iSDTV DOLBY AC3 MPEG4AAC 720pEDTV 1080iHDTV MPEG4 MPEG2 MPEG2 – Transport Stream Transport Modulation MPEG2AAC VSB QAM QPSK COFDM COFDM-BST TDS-OFDM 1.7 Mhz 5 Mhz 6 Mhz 7 Mhz 8 Mhz 10 Mhz Kernelspace Copyright © 2006-2014 Mauro Carvalho Chehab – GPLv2 licensed Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. Media device block diagram Tuner FM/TV Frontend SEC Audio decoder Conditional Access Module Audio encoder Digital TV Button Key/IR input logic System Bus Radio / Analog TV I2C Bus Video decoder Video encoder Smartcard Transport Stream filter EEPROM Sensor Webcam Processing blocks PCI, USB, PCIe, ... Bridge to CPU/Chipset bus PS.: picture is not complete: other blocks may be present, Like audio/video A/D and D/A, HDMI decoder/encoder, etc. Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. ● Video4Linux API (version 2) Tuner FM/TV Audio decoder Audio encoder Video decoder Video encoder For webcams, video inputs/outputs and radio, video and analog TV ● Extensions for Software Digital Radio were added recently ● Radio / Analog TV ● Sensor Audio output uses the standard ALSA API Webcam Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. ● Remote Controller / Input APIs Button Key/IR input logic Used for Remote Controllers and Webcam buttons ● It is an extension of the standard Linux Input API (evdev) ● Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. Linux Kernel DTV APIs DVB Frontend API Frontend SEC DVB CA API DVB Demux API Conditional Access Module Transport Stream filter Smartcard Digital TV ● Despite being called Linux DVB API, it covers all standards ● Each frontend, CA and Demux device on a DTV card is exported ● ● The frontend control is complex, as it is standard-dependent and Country dependent; Satellite Equipment Control (SEC) setup is also complex: – Controls LNBf and smart devices (DiSEqC); Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. Media Controller API ● ● ● To control complex devices with configurable pipelines Currently, used only on embedded devices and on UVC (USB Video Class) Subdev API: controls each logical element on complex devices Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. Media controller API ● ● Discovering a device internal topology – hardware devices are modeled as an oriented graph – building blocks called entities connected through pads. An entity is a media hardware or software building block – ● ● correspond to logical blocks: physical/logical hardware devices, DMA channels, physical connectors A pad is a connection endpoint – Represents interactions between entities – Data flows from the entity's output to one or more entity inputs A link is a point-to-point oriented connection between two pads – Data flows from source to sink pads Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. Sub-devices ● sub-devices are usually kernel-only objects – If a driver implements the media device API: Applications will be able to: – enumerate the sub-devices – discover the hardware topology In addition to make sub-devices discoverable: ● ● – ● drivers can also choose to make sub-devices directly configurable sub-devices will feature a character device node – on which ioctls can be called to affecting directly that subdevice – image formats can be negotiated on individual pads ● Currently, only available for V4L2 ● Adding support for DVB will require more work Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. Summary of Media Kernel APIs ● APIs described at: http://linuxtv.org/downloads/v4l-dvb-apis/ – Video4Linux API (version 2) – For webcams, video inputs/outputs and radio, video and analog TV Linux DVB API (version 5) – For digital TV inputs Remote Controller / Input evdev APIs – For Remote Controllers Media Controller and Subdev APIs ● ● ● To control complex devices with configurable pipelines The Advanced Linux Sound Architecture (ALSA) ● ● – ● For audio inputs, outputs, mixers (and sequencers) Standard input evdev API – For webcam/grabber buttons and remote controllers 14 Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. DVB API history ● DVBv1: the old Nokia API (1998-1999?) – ● DVBv2: major re-factoring step (2000-2002?) – ● First version on Kernel – Jun/2003 – for Kernel v2.5.74 DVBv4: An abandoned WIP project (2004-2005) – ● Stabilized the API for DVB-T/C/S; ATSC DVBv3: namespace cleanups – ● Developed/Implemented for a Nokia project developed by Convergence Meant to add all features for STB, but never finished. DVBv5: Current version – Committed in Kernel 2.6.28 (2008). – Added full multi-standard support. Frontend-only changes. – New standards generally support DVBv3 legacy calls, with drawbacks 15 Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. MPEG-TS container example Virtual Channel 17.1: playing movie (HD) Program 1 (service ID 1000) PHYSICAL CHANNEL / TRANSPONDER MPEG Transport Stream container PID 100 Audio 1 PID 101 Audio 2 PID 102 Virtual Channel 17.2: playing news (SD) Program 2 (service ID 2000) Other PIDs 16 Open Source Group – Silicon Valley Samsung Research Brazil Video Video PID 200 Audio 1 PID 231 Data PID 554 NOTE: The PID and Service ID data are described on some tables inside the MPEG-TS: PAT/PMT plus: SDT(DVB, ISDB) or TVCT/CVCT (ATSC) © 2014 SAMSUNG Electronics Co. Kernel system calls used on media ● The media API devices are accessed via Kernel system calls: – open() - opens a device node for read or read/write access; – close() - closes a device node, releasing resources; – ioctl() - sends/receives special commands to the device; – read() - reads some data from an input device; – write() - sends some data to an output device; – poll() - checks if something is a available for input, if output finished or if an I/O error (or event) occurred; – mmap() - creates a shared memory to be used by both the application and the device (currently, only V4L2). Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. DVBv3 API struct dvb_qpsk_parameters { __u32 fe_code_rate_t /* DVB-S */ symbol_rate; fec_inner; }; struct dvb_qam_parameters { __u32 fe_code_rate_t fe_modulation_t /* DVB-C */ symbol_rate; fec_inner; modulation; }; struct dvb_vsb_parameters { fe_modulation_t /* ATSC */ modulation; }; struct dvb_ofdm_parameters { fe_bandwidth_t fe_code_rate_t fe_code_rate_t fe_modulation_t fe_transmit_mode_t fe_guard_interval_t fe_hierarchy_t /* DVB-T */ bandwidth; code_rate_HP; code_rate_LP; constellation; transmission_mode; guard_interval; hierarchy_information; }; struct dvb_frontend_parameters { __u32 frequency; fe_spectral_inversion_t inversion; union { struct struct struct struct dvb_qpsk_parameters dvb_qam_parameters dvb_ofdm_parameters dvb_vsb_parameters qpsk; qam; ofdm; vsb; } u; }; Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. Digital TV frontend properties ● ● The Linux DVB frontend API sets/gets the frontend properties. At Linux DVB API version 5, it is based mainly on two ioctl() syscalls: – FE_GET_PROPERTY: This ioctl call returns one or more frontend properties. Only requires read-only access to the device to read the props from a cache. FE_SET_PROPERTY: This ioctl call sets one or more frontend properties. ● – – Read/write access is required to write the props at the kernel cache. Each property consists of a key and its associated value. – Several properties can be get/set at the same time. ● ● NOTE: other ioctls also defined at DVBv3 are still used, like: – FE_READ_STATUS – reads frontend lock status Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. DVBv5 properties example ● For example, to receive a DVB/C channel at 651 kHz, the following properties should be filled with: – FREQUENCY = 651000000 – MODULATION = QAM_256 – INVERSION = INVERSION_AUTO – SYMBOL_RATE = 5217000 – INNER_FEC = FEC_3_4 – (inner convolutional code FEC = 3/4) DVB_TUNE = <any value> ● This special property writes data from the previous properties stored at the cache into the hardware Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. Digital TV demux settings ● ● The DVB demux API provides ways to filter the MPEG TS and read its contents The most used ioctl syscals are the ones that set the filters: – DMX_SET_BUFFER_SIZE – Sets the size of the circular buffer used to store the filtered data – DMX_SET_FILTER - This ioctl call sets up a MPEG-TS packet filter according to the filter and mask parameters provided (up to the 16 bytes of the packet can be filtered). – DMX_SET_PES_FILTER - This ioctl call sets up a Program Elementary Stream (PES) filter according to the parameters provided. It filters just the packet identifier (PID) A PID equal to 0x2000 means to just send the entire MPEG-TS as-is to userspace. Generally, only used for testing purposes, especially on embedded or USB-based devices, as this eats a lot of CPU time and bus bandwidth. Once a filter is set, the data is read via the dvr device node, using poll() and read() syscalls. ● ● Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. Userspace library: libdvbv5 ● Written from scratch to fully support DVBv5; ● Provide a standard way to work with all DVB standards; ● ● Offers functions to discover the TV programs (“channels”) that are inside a transport stream; Offers functions to read/write files on both legacyformats used by DVBv3 applications and to read/write data compatible with DVBv5. ● Used by DVBv5 utils, tvdaemon, Kaffeine (at linuxtv.org); ● The API stabilized in April, 2014. – Released at v4l-utils version 1.4.0 (Sept, 8 2014) – Fully documented at v4l-utils version 1.6.0 (Oct, 5 2014) – Already packaged for Fedora and Debian (a Tizen package is also available at linuxtv.org – pending to be pushed upstream) – New projects should start using it. Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. The libdvbv5 library ● ● ● The Library uses internally (key, value) sets, just like the DVBv5 API – All DVBv5 sets are supported – Additional properties for Satellite Equipment Control(SEC) config – Additional properties for derived statistics; The logic to configure SEC should be in userspace, as only the application knows: – Satellite LNBf, with converts from C-Band/Ku-Band/... into SBand, used by the satellite TV devices; – Parameters to select the satellite dish/LNBf, to change the dish position and to select the LNBf frequency range/polarization. As the DVB evolved, there are different ways to do the same thing, e. g. via the latest DVBv5 API spec or to use some fallback code when running a DVBv5 API lower than version 5.10 or even DVBv3. Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. The libdvbv5 features summary ● ● ● ● ● ● It abstracts the DVB version, supporting all types of drivers from version 3.2 and up; It allows setting parameters related to the satellite system; It provides a way to receive the DVBv5 enhanced statistics if available; It provides decoders for several MPEG-TS descriptors needed to identify the Packet IDs inside a MPEG-TS program; Provides functions to read files containing channel/program properties; Provides extra statistics like signal quality, BER and PER measurements, etc. Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. Example: tuning into a channel dvb = dvb_fe_open(0, 0, 0, 0); /* Opens adapter 0, frontend 0 */ dvb_file = dvb_read_file_format(“channel”, SYS_UNDEFINED, FILE_DVBV5); entry = dvb_file->first_entry; /* Use the first channel */ for (i = 0; i < entry->n_props; i++) dvb_fe_store_parm(dvb, entry->props[i].cmd, entry->props[i].u.data); dvb_file_free(dvb_file); dvb_fe_set_parms(dvb); while (1) { char buf[256], p = buf; int len = sizeof(buf), show = 1; dvb_fe_get_stats(dvb); dvb_fe_snprintf_stat(dvb, DTV_STATUS, NULL, 0, &p, &len, &show); dvb_fe_snprintf_stat(dvb, DTV_QUALITY, "Qual", 0, &p, &len, &show); fprintf(fd, "\t%s\n", buf); } Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. DVBv5 utils ● DVBv5 utils: – Uses libdvbv5 as basis for scan/zap and read/write channel files; – It consists of 4 tools: dvbv5-scan Scans the channel transponders and gets the services available there dvbv5-zap Locks into a channel (zap), allowing other applications to get the stream at the dvr devices or to monitor the stream dvb-fe-tool Lists frontend properties, allows to manually set the DVB frontend delivery system and to monitor the frontend statistics dvb-format-convert Converts from/to several other formats used by DVBv3 apps ● Both DVBv5 utils and libdvbv5 are packaged together with v4l-utils: – http://git.linuxtv.org/cgit.cgi/v4l-utils.git/ Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. GUI apps using libdvbv5 ● ● Kaffeine has a recent experimental addition of libdvbv5 support: – It is a KDE media player with support for several types of input, including Digital TV (ATSC, DVB-S, DVB-S2 and DVBC); – The experimental patches also adds support for ISDB-T; – Should not be hard to add support for DVB-T2 and other modern standards; – Need more testing and bug fixes; – Located at: http://git.linuxtv.org/cgit.cgi/mchehab/kaffeine.git/ Tvdaemon: – It is a TV streaming server; – It is a fork/rewrite of tvheadend; – Located at: https://github.com/neolynx/tvdaemon Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. DVB-C Scan Example $ dvbv5-scan ~/dvbc-teste -I channel Scanning frequency #1 573000000 Lock (0x1f) Quality= Good Signal= 100.00% C/N= -13.80dB UCB= 0 postBER= 3.14x10^-3 PER= 0 Service SBT, provider (null): digital television Service Globo, provider Globo: digital television Service Record, provider (null): digital television Service Band, provider (null): digital television ... Service Trilhas Sonoras, provider (null): digital radio New transponder/channel found: #2: 579000000 ... New transponder/channel found: #39: 507000000 Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. Service zap example $ dvbv5-zap -c dvb_channel.conf "trilhas sonoras" -r using demux '/dev/dvb/adapter0/demux0' reading channels from file 'dvb_channel.conf' service has pid type 05: 204 tuning to 573000000 Hz audio pid 104 dvb_set_pesfilter 104 Lock (0x1f) Quality= Good Signal= 100.00% C/N= -13.80dB UCB= 70 postBER= 3.14x10^-3 PER= 0 DVR interface '/dev/dvb/adapter0/dvr0' can now be opened Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. DVB DVR device play $ mplayer -cache 800 /dev/dvb/adapter0/dvr0 MPlayer SVN-r37077-4.8.2 (C) 2000-2014 MPlayer Team TS file format detected. NO VIDEO! AUDIO MPA(pid=104) NO SUBS (yet)! PROGRAM N. 0 ================================================================== Opening audio decoder: [mpg123] MPEG 1.0/2.0/2.5 layers I, II, III AUDIO: 48000 Hz, 2 ch, s16le, 192.0 kbit/12.50% (ratio: 24000>192000) Selected audio codec: [mpg123] afm: mpg123 (MPEG 1.0/2.0/2.5 layers I, II, III) ================================================================== AO: [alsa] 48000Hz 2ch s16le (2 bytes per sample) Video: no video Starting playback... Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. DVB transponder traffic monitor $ dvbv5-zap -c dvb_channel.conf 573000000 -m ... Lock (0x1f) Quality= Good Signal= 100.00% C/N= -13.90dB UCB= 384 postBER= 96.8x10^-6 PER= 0 dvb_set_pesfilter to 0x2000 PID FREQ SPEED TOTAL 0000 9.88 p/s 14.5 Kbps 1 KB 0001 1.98 p/s 2.9 Kbps 376 B 0010 18.77 p/s 27.6 Kbps 3 KB 0011 48.42 p/s 71.1 Kbps 8 KB 0012 1455.53 p/s 2137.8 Kbps 270 KB 1fff 1033.60 p/s 1518.1 Kbps 192 KB TOT 25296.44 p/s 37154.2 Kbps 4700 KB ... Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. How to contribute ● Main discussions and patches for TV on Linux: – ● ● Userspace/kernelspace: linux-media@vger.kernel.org Upstream trees: – To test Kernel drivers: http://git.linuxtv.org/media_build.git – To develop Kernel drivers http://git.linuxtv.org/media_tree.git – v4l-utils, dvbv5 utils and libdvbv5: http://git.linuxtv.org/v4l-utils.git Documentation: – Media APIs http://linuxtv.org/downloads/v4l-dvb-apis – libdvbv5 docs: http://linuxtv.org/docs/libdvbv5/index.html ● Wiki pages: http://linuxtv.org/wiki/ ● IRC channel: irc.freenode.net – channels #v4l and #linuxtv – Can be assessed via http://webchat.freenode.net/ Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co. WE ARE HIRING Thank you. Questions? 33 Open Source Group – Silicon Valley Samsung Research Brazil © 2014 SAMSUNG Electronics Co.
© Copyright 2024