Digital TV on Linux -...
Transcript of Digital TV on Linux -...
Oct 14, 2014
© 2014 SAMSUNG Electronics Co.
Not to be used for commercial purpose without getting permissionAll information herein are my own and may not represent the company's positions, strategies or opinionsOpen Source Group – Silicon Valley
Samsung Research Brazil
Digital TV on Linux
Mauro Carvalho ChehabLinux Kernel Expert
Samsung Open Source Group
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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.
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
Digital TV Terrestrial Standards
Source: http://en.wikipedia.org/wiki/File:Digital_broadcast_standards.svg
Updated in May, 2014Note: DVB-T2 is gradually replacing DVB-T
Source: http://en.wikipedia.org/wiki/File:Digital_broadcast_standards.svg
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
TV Digital standards
Copyright © 2006-2014 Mauro Carvalho Chehab – GPLv2 licensed
8 Mhz
Video Elem. Stream
Audio Elem. Stream
Modulation
Transport
Channel1.7 Mhz 5 Mhz 6 Mhz 7 Mhz 10 Mhz
VSB QAM
MPEG2 MPEG4
280i LD 480iSDTV 720pEDTV 1080iHDTV
MPEG2-BC MPEG2-AAC
DOLBYAC3
MPEG4-AAC
QPSK COFDM COFDM-BST TDS-OFDM
MPEG2 – Transport Stream
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
8 Mhz
TV Digital Linux Mapping
Video Elem. Stream
Audio Elem. Stream
Modulation
Transport
Channel1.7 Mhz 5 Mhz 6 Mhz 7 Mhz 10 Mhz
VSB QAM
MPEG2 MPEG4
280i LD 480iSDTV 720pEDTV 1080iHDTV
MPEG2-BC MPEG2-AAC
DOLBYAC3
MPEG4-AAC
Copyright © 2006-2014 Mauro Carvalho Chehab – GPLv2 licensed
Kernelspace
Userspace
QPSK COFDM COFDM-BST TDS-OFDM
MPEG2 – Transport Stream
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
Media device block diagram
TunerFM/TV
Audio decoder
Video decoder
Audio encoder
Button Key/IR input logic
EEPROM
Sensor
Bridge to CPU/Chipset bus
I2C
Bus
Sys
tem
Bus
Frontend
SEC
Transport Stream filter
Conditional Access Module
Video encoder
Radio / Analog TV
Digital TV
PS.: picture is not complete: other blocks may be present,Like audio/video A/D and D/A, HDMI decoder/encoder, etc.
Webcam
PCI,USB,PCIe,...Processing blocks
Smartcard
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
●Video4Linux API (version 2)
TunerFM/TV
Audio decoder
Video decoder
Audio encoder
Sensor
Video encoder
Radio / Analog TV
Webcam
● For webcams, video inputs/outputs and radio, video and analog TV
● Extensions for Software Digital Radio were added recently
● Audio output uses the standard ALSA API
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
●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)
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
Linux Kernel DTV APIs
● 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);
Frontend
SEC
Transport Stream filter
Conditional Access Module
Digital TV
DVB Frontend API
DVB CA API
DVB Demux API Smartcard
Frontend
SEC
Transport Stream filter
Conditional Access Module
Digital TV
DVB Frontend API
DVB CA API
DVB Demux API
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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
14
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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
15
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
DVB API history● DVBv1: the old Nokia API (1998-1999?)
– Developed/Implemented for a Nokia project developed by Convergence
● DVBv2: major re-factoring step (2000-2002?)
– Stabilized the API for DVB-T/C/S; ATSC
● DVBv3: namespace cleanups
– First version on Kernel – Jun/2003 – for Kernel v2.5.74
● DVBv4: An abandoned WIP project (2004-2005)
– 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
16
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
PHYSICALCHANNEL /
TRANSPONDER
MPEG-TS container example
MPEGTransport
Streamcontainer
Program 1(service ID 1000)
Video
Audio 1
Audio 2
Program 2(service ID 2000)
Video
Audio 1
Data
PID 100
PID 101
PID 102
PID 200
PID 231
PID 554
Virtual Channel 17.1: playing movie (HD)
Virtual Channel 17.2: playing news (SD)
Other PIDs
NOTE:The PID and Service ID
data are described on sometables inside the MPEG-TS:
PAT/PMT plus:SDT(DVB, ISDB) orTVCT/CVCT (ATSC)
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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).
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
DVBv3 APIstruct dvb_qpsk_parameters { /* DVB-S */
__u32 symbol_rate;fe_code_rate_t fec_inner;
};
struct dvb_qam_parameters { /* DVB-C */__u32 symbol_rate;fe_code_rate_t fec_inner;fe_modulation_t modulation;
};
struct dvb_vsb_parameters { /* ATSC */fe_modulation_t modulation;
};
struct dvb_ofdm_parameters { /* DVB-T */fe_bandwidth_t bandwidth;fe_code_rate_t code_rate_HP;fe_code_rate_t code_rate_LP;fe_modulation_t constellation;fe_transmit_mode_t transmission_mode;fe_guard_interval_t guard_interval;fe_hierarchy_t hierarchy_information;
};
struct dvb_frontend_parameters {__u32 frequency;fe_spectral_inversion_t inversion;
union { struct dvb_qpsk_parameters qpsk; struct dvb_qam_parameters qam; struct dvb_ofdm_parameters ofdm; struct dvb_vsb_parameters vsb;
} u;};
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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.
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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.
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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 S-Band, 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.
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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.
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
Example: tuning into a channeldvb = 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);
}
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
DVBv5 utils● DVBv5 utils:
– Uses libdvbv5 as basis for scan/zap and read/write channel files;
– It consists of 4 tools:
● Both DVBv5 utils and libdvbv5 are packaged together withv4l-utils:
– http://git.linuxtv.org/cgit.cgi/v4l-utils.git/
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
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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 DVB-C);
– 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
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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...
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
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
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
How to contribute● Main discussions and patches for TV on Linux:
– Userspace/kernelspace: [email protected]
● 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/
33
Thank you.
© 2014 SAMSUNG Electronics Co.Open Source Group – Silicon ValleySamsung Research Brazil
Questions?
WE ARE HIRING