1 .. SPDX-License-Identifier: GPL-2.0
3 ================================
4 vidtv: Virtual Digital TV driver
5 ================================
7 Author: Daniel W. S. Almeida <dwlsalmeida@gmail.com>, June 2020.
12 Vidtv is a virtual DVB driver that aims to serve as a reference for driver
13 writers by serving as a template. It also validates the existing media DVB
14 APIs, thus helping userspace application writers.
16 Currently, it consists of:
18 - A fake tuner driver, which will report a bad signal quality if the chosen
19 frequency is too far away from a table of valid frequencies for a
20 particular delivery system.
22 - A fake demod driver, which will constantly poll the fake signal quality
23 returned by the tuner, simulating a device that can lose/reacquire a lock
24 on the signal depending on the CNR levels.
26 - A fake bridge driver, which is the module responsible for modprobing the
27 fake tuner and demod modules and implementing the demux logic. This module
28 takes parameters at initialization that will dictate how the simulation
31 - Code responsible for encoding a valid MPEG Transport Stream, which is then
32 passed to the bridge driver. This fake stream contains some hardcoded content.
33 For now, we have a single, audio-only channel containing a single MPEG
34 Elementary Stream, which in turn contains a SMPTE 302m encoded sine-wave.
35 Note that this particular encoder was chosen because it is the easiest
36 way to encode PCM audio data in a MPEG Transport Stream.
40 vidtv is a test driver and thus is **not** enabled by default when
43 In order to enable compilation of vidtv:
45 - Enable **DVB_TEST_DRIVERS**, then
46 - Enable **DVB_VIDTV**
48 When compiled as a module, expect the following .ko files:
58 When compiled as a module, run::
62 That's it! The bridge driver will initialize the tuner and demod drivers as
63 part of its own initialization.
65 By default, it will accept the following frequencies:
67 - 474 MHz for DVB-T/T2/C;
68 - 11,362 GHz for DVB-S/S2.
70 For satellite systems, the driver simulates an universal extended
71 LNBf, with frequencies at Ku-Band, ranging from 10.7 GHz to 12.75 GHz.
73 You can optionally define some command-line arguments to vidtv.
75 Command-line arguments to vidtv
76 -------------------------------
77 Below is a list of all arguments that can be supplied to vidtv:
79 drop_tslock_prob_on_low_snr
80 Probability of losing the TS lock if the signal quality is bad.
81 This probability be used by the fake demodulator driver to
82 eventually return a status of 0 when the signal quality is not
85 recover_tslock_prob_on_good_snr:
86 Probability recovering the TS lock when the signal improves. This
87 probability be used by the fake demodulator driver to eventually
88 return a status of 0x1f when/if the signal quality improves.
90 mock_power_up_delay_msec
91 Simulate a power up delay. Default: 0.
94 Simulate a tune delay. Default 0.
96 vidtv_valid_dvb_t_freqs
97 Valid DVB-T frequencies to simulate, in Hz.
99 vidtv_valid_dvb_c_freqs
100 Valid DVB-C frequencies to simulate, in Hz.
102 vidtv_valid_dvb_s_freqs
103 Valid DVB-S/S2 frequencies to simulate at Ku-Band, in kHz.
105 max_frequency_shift_hz,
106 Maximum shift in HZ allowed when tuning in a channel.
109 How often to send SI packets. Default: 40ms.
112 How often to send PCR packets. Default: 40ms.
115 Attempt to maintain this bit rate by inserting TS null packets, if
116 necessary. Default: 4096.
119 PCR PID for all channels. Default: 0x200.
122 Size for the mux buffer in multiples of 188 bytes.
124 vidtv internal structure
125 ------------------------
126 The kernel modules are split in the following way:
129 Implements a fake tuner DVB driver.
132 Implements a fake demodulator DVB driver.
135 Implements a bridge driver.
137 The MPEG related code is split in the following way:
140 Code to work with MPEG TS packets, such as TS headers, adaptation
141 fields, PCR packets and NULL packets.
144 This is the PSI generator. PSI packets contain general information
145 about a MPEG Transport Stream. A PSI generator is needed so
146 userspace apps can retrieve information about the Transport Stream
147 and eventually tune into a (dummy) channel.
149 Because the generator is implemented in a separate file, it can be
150 reused elsewhere in the media subsystem.
152 Currently vidtv supports working with 5 PSI tables: PAT, PMT,
155 The specification for PAT and PMT can be found in *ISO 13818-1:
156 Systems*, while the specification for the SDT, NIT, EIT can be found in *ETSI
157 EN 300 468: Specification for Service Information (SI) in DVB
160 It isn't strictly necessary, but using a real TS file helps when
161 debugging PSI tables. Vidtv currently tries to replicate the PSI
162 structure found in this file: `TS1Globo.ts
163 <https://tsduck.io/streams/brazil-isdb-tb/TS1globo.ts>`_.
165 A good way to visualize the structure of streams is by using
166 `DVBInspector <https://sourceforge.net/projects/dvbinspector/>`_.
169 Implements the PES logic to convert encoder data into MPEG TS
170 packets. These can then be fed into a TS multiplexer and eventually
174 An interface for vidtv encoders. New encoders can be added to this
175 driver by implementing the calls in this file.
178 Implements a S302M encoder to make it possible to insert PCM audio
179 data in the generated MPEG Transport Stream. The relevant
180 specification is available online as *SMPTE 302M-2007: Television -
181 Mapping of AES3 Data into MPEG-2 Transport Stream*.
184 The resulting MPEG Elementary Stream is conveyed in a private
185 stream with a S302M registration descriptor attached.
187 This shall enable passing an audio signal into userspace so it can
188 be decoded and played by media software. The corresponding decoder
189 in ffmpeg is located in 'libavcodec/s302m.c' and is experimental.
192 Implements a 'channel' abstraction.
194 When vidtv boots, it will create some hardcoded channels:
196 #. Their services will be concatenated to populate the SDT.
198 #. Their programs will be concatenated to populate the PAT
200 #. Their events will be concatenated to populate the EIT
202 #. For each program in the PAT, a PMT section will be created
204 #. The PMT section for a channel will be assigned its streams.
206 #. Every stream will have its corresponding encoder polled in a
207 loop to produce TS packets.
208 These packets may be interleaved by the muxer and then delivered
212 Implements a MPEG TS mux, loosely based on the ffmpeg
213 implementation in "libavcodec/mpegtsenc.c"
215 The muxer runs a loop which is responsible for:
217 #. Keeping track of the amount of time elapsed since the last
220 #. Polling encoders in order to fetch 'elapsed_time' worth of data.
222 #. Inserting PSI and/or PCR packets, if needed.
224 #. Padding the resulting stream with NULL packets if
225 necessary in order to maintain the chosen bit rate.
227 #. Delivering the resulting TS packets to the bridge
228 driver so it can pass them to the demux.
230 Testing vidtv with v4l-utils
231 ----------------------------
233 Using the tools in v4l-utils is a great way to test and inspect the output of
234 vidtv. It is hosted here: `v4l-utils Documentation
235 <https://linuxtv.org/wiki/index.php/V4l-utils>`_.
239 The v4l-utils are a series of packages for handling media devices.
241 It is hosted at http://git.linuxtv.org/v4l-utils.git, and packaged
242 on most distributions.
244 It provides a series of libraries and utilities to be used to
245 control several aspect of the media boards.
248 Start by installing v4l-utils and then modprobing vidtv::
250 modprobe dvb_vidtv_bridge
252 If the driver is OK, it should load and its probing code will run. This will
253 pull in the tuner and demod drivers.
258 The first step to check whether the demod loaded successfully is to run::
261 Device Dummy demod for DVB-T/T2/C/S/S2 (/dev/dvb/adapter0/frontend0) capabilities:
271 CAN_GUARD_INTERVAL_AUTO
281 CAN_TRANSMISSION_MODE_AUTO
282 DVB API Version 5.11, Current v5 delivery system: DVBC/ANNEX_A
283 Supported delivery systems:
289 Frequency range for the current standard:
294 Symbol rate ranges for the current standard:
298 This should return what is currently set up at the demod struct, i.e.::
300 static const struct dvb_frontend_ops vidtv_demod_ops = {
310 .name = "Dummy demod for DVB-T/T2/C/S/S2",
311 .frequency_min_hz = 51 * MHz,
312 .frequency_max_hz = 2150 * MHz,
313 .frequency_stepsize_hz = 62500,
314 .frequency_tolerance_hz = 29500 * kHz,
315 .symbol_rate_min = 1000000,
316 .symbol_rate_max = 45000000,
318 .caps = FE_CAN_FEC_1_2 |
334 FE_CAN_INVERSION_AUTO |
335 FE_CAN_TRANSMISSION_MODE_AUTO |
336 FE_CAN_GUARD_INTERVAL_AUTO |
337 FE_CAN_HIERARCHY_AUTO,
342 For more information on dvb-fe-tools check its online documentation here:
343 `dvb-fe-tool Documentation
344 <https://www.linuxtv.org/wiki/index.php/Dvb-fe-tool>`_.
349 In order to tune into a channel and read the PSI tables, we can use dvb-scan.
351 For this, one should provide a configuration file known as a 'scan file',
355 FREQUENCY = 474000000
356 MODULATION = QAM/AUTO
357 SYMBOL_RATE = 6940000
359 DELIVERY_SYSTEM = DVBC/ANNEX_A
362 The parameters depend on the video standard you're testing.
365 Vidtv is a fake driver and does not validate much of the information
366 in the scan file. Just specifying 'FREQUENCY' and 'DELIVERY_SYSTEM'
367 should be enough for DVB-T/DVB-T2. For DVB-S/DVB-C however, you
368 should also provide 'SYMBOL_RATE'.
370 You can browse scan tables online here: `dvb-scan-tables
371 <https://git.linuxtv.org/dtv-scan-tables.git>`_.
373 Assuming this channel is named 'channel.conf', you can then run::
375 $ dvbv5-scan channel.conf
376 dvbv5-scan ~/vidtv.conf
377 ERROR command BANDWIDTH_HZ (5) not found during retrieve
378 Cannot calc frequency shift. Either bandwidth/symbol-rate is unavailable (yet).
379 Scanning frequency #1 330000000
380 (0x00) Signal= -68.00dBm
381 Scanning frequency #2 474000000
382 Lock (0x1f) Signal= -34.45dBm C/N= 33.74dB UCB= 0
383 Service Beethoven, provider LinuxTV.org: digital television
385 For more information on dvb-scan, check its documentation online here:
386 `dvb-scan Documentation <https://www.linuxtv.org/wiki/index.php/Dvbscan>`_.
391 dvbv5-zap is a command line tool that can be used to record MPEG-TS to disk. The
392 typical use is to tune into a channel and put it into record mode. The example
393 below - which is taken from the documentation - illustrates that\ [1]_::
395 $ dvbv5-zap -c dvb_channel.conf "beethoven" -o music.ts -P -t 10
396 using demux 'dvb0.demux0'
397 reading channels from file 'dvb_channel.conf'
398 tuning to 474000000 Hz
400 dvb_set_pesfilter 8192
401 dvb_dev_set_bufsize: buffer set to 6160384
402 Lock (0x1f) Quality= Good Signal= -34.66dBm C/N= 33.41dB UCB= 0 postBER= 0 preBER= 1.05x10^-3 PER= 0
403 Lock (0x1f) Quality= Good Signal= -34.57dBm C/N= 33.46dB UCB= 0 postBER= 0 preBER= 1.05x10^-3 PER= 0
404 Record to file 'music.ts' started
405 received 24587768 bytes (2401 Kbytes/sec)
406 Lock (0x1f) Quality= Good Signal= -34.42dBm C/N= 33.89dB UCB= 0 postBER= 0 preBER= 2.44x10^-3 PER= 0
408 .. [1] In this example, it records 10 seconds with all program ID's stored
409 at the music.ts file.
412 The channel can be watched by playing the contents of the stream with some
413 player that recognizes the MPEG-TS format, such as ``mplayer`` or ``vlc``.
415 By playing the contents of the stream one can visually inspect the workings of
416 vidtv, e.g., to play a recorded TS file with::
420 or, alternatively, running this command on one terminal::
422 $ dvbv5-zap -c dvb_channel.conf "beethoven" -P -r &
424 And, on a second terminal, playing the contents from DVR interface with::
426 $ mplayer /dev/dvb/adapter0/dvr0
428 For more information on dvb-zap check its online documentation here:
429 `dvb-zap Documentation
430 <https://www.linuxtv.org/wiki/index.php/Dvbv5-zap>`_.
431 See also: `zap <https://www.linuxtv.org/wiki/index.php/Zap>`_.
434 What can still be improved in vidtv
435 -----------------------------------
437 Add *debugfs* integration
438 ~~~~~~~~~~~~~~~~~~~~~~~~~
440 Although frontend drivers provide DVBv5 statistics via the .read_status
441 call, a nice addition would be to make additional statistics available to
442 userspace via debugfs, which is a simple-to-use, RAM-based filesystem
443 specifically designed for debug purposes.
445 The logic for this would be implemented on a separate file so as not to
446 pollute the frontend driver. These statistics are driver-specific and can
447 be useful during tests.
449 The Siano driver is one example of a driver using
450 debugfs to convey driver-specific statistics to userspace and it can be
453 This should be further enabled and disabled via a Kconfig
454 option for convenience.
456 Add a way to test video
457 ~~~~~~~~~~~~~~~~~~~~~~~
459 Currently, vidtv can only encode PCM audio. It would be great to implement
460 a barebones version of MPEG-2 video encoding so we can also test video. The
461 first place to look into is *ISO 13818-2: Information technology — Generic
462 coding of moving pictures and associated audio information — Part 2: Video*,
463 which covers the encoding of compressed video in MPEG Transport Streams.
465 This might optionally use the Video4Linux2 Test Pattern Generator, v4l2-tpg,
468 drivers/media/common/v4l2-tpg/
471 Add white noise simulation
472 ~~~~~~~~~~~~~~~~~~~~~~~~~~
474 The vidtv tuner already has code to identify whether the chosen frequency
475 is too far away from a table of valid frequencies. For now, this means that
476 the demodulator can eventually lose the lock on the signal, since the tuner will
477 report a bad signal quality.
479 A nice addition is to simulate some noise when the signal quality is bad by:
481 - Randomly dropping some TS packets. This will trigger a continuity error if the
482 continuity counter is updated but the packet is not passed on to the demux.
484 - Updating the error statistics accordingly (e.g. BER, etc).
486 - Simulating some noise in the encoded data.
488 Functions and structs used within vidtv
489 ---------------------------------------
491 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_bridge.h
493 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_channel.h
495 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_demod.h
497 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_encoder.h
499 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_mux.h
501 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_pes.h
503 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_psi.h
505 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_s302m.h
507 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_ts.h
509 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_tuner.h
511 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_common.c
513 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_tuner.c