Documentation/driver-api/media/drivers/vidtv.rst GitHub 원문 ↗

Linux 6.18.37 · Driver API

vidtv: Virtual Digital TV driver

Virtual DVB frontend, MPEG-TS 생성 pipeline, v4l-utils 시험 절차와 개선 과제를 설명하는 vidtv 전문 번역입니다.

Source pathDocumentation/driver-api/media/drivers/vidtv.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

vidtv.rst:1-513

Vidtv는 실제 RF hardware 없이 DVB frontend의 tuning, lock 변화, PSI/SI 생성, PES·MPEG-TS multiplexing과 demux 전달을 함께 시험하는 reference driver입니다. 단일 SMPTE 302M audio channel을 만들기 때문에 frontend API부터 userspace playback까지 하나의 재현 가능한 경로를 제공합니다.

검토할 때는 virtual tuner·demod·bridge control path와 `encoder → PES → TS mux → bridge → demux` data path를 나눠 보는 것이 좋습니다. `dvb-fe-tool`은 frontend capability, `dvbv5-scan`은 tuning·PSI 발견, `dvbv5-zap`은 PID 전달·recording·DVR playback을 각각 검증합니다.

문서 구성
원문 줄내용핵심
1-37배경과 상위 구성Virtual tuner·demod·bridge·S302M stream
38-74Build와 실행Kconfig, module, 기본 frequency
75-123Module parameterLock probability, timing, PID, mux rate
124-190내부 MPEG 계층TS·PSI·PES·encoder·S302M
191-229Channel과 muxPAT·PMT·SDT·EIT 구성과 mux loop
230-345v4l-utils·dvb-fe-toolFrontend capability와 `vidtv_demod_ops`
346-387dvb-scanScan file, tune, PSI service 발견
388-433dvbv5-zapMPEG-TS 기록과 DVR 재생
434-487개선 과제debugfs, video, white noise
488-513Kernel-doc sourceHeader·source function과 struct

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 ================================
4 vidtv: Virtual Digital TV driver
5 ================================
6
7 Author: Daniel W. S. Almeida <dwlsalmeida@gmail.com>, June 2020.
8
9 Background
10 ----------
11
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.
15
16 Currently, it consists of:
17
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.
21
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.
25
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
29 behaves.
30
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.
37
38 Building vidtv
39 --------------
40 vidtv is a test driver and thus is **not** enabled by default when
41 compiling the kernel.
42
43 In order to enable compilation of vidtv:
44
45 - Enable **DVB_TEST_DRIVERS**, then
46 - Enable **DVB_VIDTV**
47
48 When compiled as a module, expect the following .ko files:
49
50 - dvb_vidtv_tuner.ko
51
52 - dvb_vidtv_demod.ko
53
54 - dvb_vidtv_bridge.ko
55
56 Running vidtv
57 -------------
58 When compiled as a module, run::
59
60 modprobe vidtv
61
62 That's it! The bridge driver will initialize the tuner and demod drivers as
63 part of its own initialization.
64
65 By default, it will accept the following frequencies:
66
67 - 474 MHz for DVB-T/T2/C;
68 - 11,362 GHz for DVB-S/S2.
69
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.
72
73 You can optionally define some command-line arguments to vidtv.
74
75 Command-line arguments to vidtv
76 -------------------------------
77 Below is a list of all arguments that can be supplied to vidtv:
78
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
83 good.
84
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.
89
90 mock_power_up_delay_msec
91 Simulate a power up delay. Default: 0.
92
93 mock_tune_delay_msec
94 Simulate a tune delay. Default 0.
95
96 vidtv_valid_dvb_t_freqs
97 Valid DVB-T frequencies to simulate, in Hz.
98
99 vidtv_valid_dvb_c_freqs
100 Valid DVB-C frequencies to simulate, in Hz.
101
102 vidtv_valid_dvb_s_freqs
103 Valid DVB-S/S2 frequencies to simulate at Ku-Band, in kHz.
104
105 max_frequency_shift_hz,
106 Maximum shift in HZ allowed when tuning in a channel.
107
108 si_period_msec
109 How often to send SI packets. Default: 40ms.
110
111 pcr_period_msec
112 How often to send PCR packets. Default: 40ms.
113
114 mux_rate_kbytes_sec
115 Attempt to maintain this bit rate by inserting TS null packets, if
116 necessary. Default: 4096.
117
118 pcr_pid,
119 PCR PID for all channels. Default: 0x200.
120
121 mux_buf_sz_pkts,
122 Size for the mux buffer in multiples of 188 bytes.
123
124 vidtv internal structure
125 ------------------------
126 The kernel modules are split in the following way:
127
128 vidtv_tuner.[ch]
129 Implements a fake tuner DVB driver.
130
131 vidtv_demod.[ch]
132 Implements a fake demodulator DVB driver.
133
134 vidtv_bridge.[ch]
135 Implements a bridge driver.
136
137 The MPEG related code is split in the following way:
138
139 vidtv_ts.[ch]
140 Code to work with MPEG TS packets, such as TS headers, adaptation
141 fields, PCR packets and NULL packets.
142
143 vidtv_psi.[ch]
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.
148
149 Because the generator is implemented in a separate file, it can be
150 reused elsewhere in the media subsystem.
151
152 Currently vidtv supports working with 5 PSI tables: PAT, PMT,
153 SDT, NIT and EIT.
154
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
158 systems*.
159
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>`_.
164
165 A good way to visualize the structure of streams is by using
166 `DVBInspector <https://sourceforge.net/projects/dvbinspector/>`_.
167
168 vidtv_pes.[ch]
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
171 into userspace.
172
173 vidtv_encoder.h
174 An interface for vidtv encoders. New encoders can be added to this
175 driver by implementing the calls in this file.
176
177 vidtv_s302m.[ch]
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*.
182
183
184 The resulting MPEG Elementary Stream is conveyed in a private
185 stream with a S302M registration descriptor attached.
186
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.
190
191 vidtv_channel.[ch]
192 Implements a 'channel' abstraction.
193
194 When vidtv boots, it will create some hardcoded channels:
195
196 #. Their services will be concatenated to populate the SDT.
197
198 #. Their programs will be concatenated to populate the PAT
199
200 #. Their events will be concatenated to populate the EIT
201
202 #. For each program in the PAT, a PMT section will be created
203
204 #. The PMT section for a channel will be assigned its streams.
205
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
209 to the bridge.
210
211 vidtv_mux.[ch]
212 Implements a MPEG TS mux, loosely based on the ffmpeg
213 implementation in "libavcodec/mpegtsenc.c"
214
215 The muxer runs a loop which is responsible for:
216
217 #. Keeping track of the amount of time elapsed since the last
218 iteration.
219
220 #. Polling encoders in order to fetch 'elapsed_time' worth of data.
221
222 #. Inserting PSI and/or PCR packets, if needed.
223
224 #. Padding the resulting stream with NULL packets if
225 necessary in order to maintain the chosen bit rate.
226
227 #. Delivering the resulting TS packets to the bridge
228 driver so it can pass them to the demux.
229
230 Testing vidtv with v4l-utils
231 ----------------------------
232
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>`_.
236
237 From its webpage::
238
239 The v4l-utils are a series of packages for handling media devices.
240
241 It is hosted at http://git.linuxtv.org/v4l-utils.git, and packaged
242 on most distributions.
243
244 It provides a series of libraries and utilities to be used to
245 control several aspect of the media boards.
246
247
248 Start by installing v4l-utils and then modprobing vidtv::
249
250 modprobe dvb_vidtv_bridge
251
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.
254
255 Using dvb-fe-tool
256 ~~~~~~~~~~~~~~~~~
257
258 The first step to check whether the demod loaded successfully is to run::
259
260 $ dvb-fe-tool
261 Device Dummy demod for DVB-T/T2/C/S/S2 (/dev/dvb/adapter0/frontend0) capabilities:
262 CAN_FEC_1_2
263 CAN_FEC_2_3
264 CAN_FEC_3_4
265 CAN_FEC_4_5
266 CAN_FEC_5_6
267 CAN_FEC_6_7
268 CAN_FEC_7_8
269 CAN_FEC_8_9
270 CAN_FEC_AUTO
271 CAN_GUARD_INTERVAL_AUTO
272 CAN_HIERARCHY_AUTO
273 CAN_INVERSION_AUTO
274 CAN_QAM_16
275 CAN_QAM_32
276 CAN_QAM_64
277 CAN_QAM_128
278 CAN_QAM_256
279 CAN_QAM_AUTO
280 CAN_QPSK
281 CAN_TRANSMISSION_MODE_AUTO
282 DVB API Version 5.11, Current v5 delivery system: DVBC/ANNEX_A
283 Supported delivery systems:
284 DVBT
285 DVBT2
286 [DVBC/ANNEX_A]
287 DVBS
288 DVBS2
289 Frequency range for the current standard:
290 From: 51.0 MHz
291 To: 2.15 GHz
292 Step: 62.5 kHz
293 Tolerance: 29.5 MHz
294 Symbol rate ranges for the current standard:
295 From: 1.00 MBauds
296 To: 45.0 MBauds
297
298 This should return what is currently set up at the demod struct, i.e.::
299
300 static const struct dvb_frontend_ops vidtv_demod_ops = {
301 .delsys = {
302 SYS_DVBT,
303 SYS_DVBT2,
304 SYS_DVBC_ANNEX_A,
305 SYS_DVBS,
306 SYS_DVBS2,
307 },
308
309 .info = {
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,
317
318 .caps = FE_CAN_FEC_1_2 |
319 FE_CAN_FEC_2_3 |
320 FE_CAN_FEC_3_4 |
321 FE_CAN_FEC_4_5 |
322 FE_CAN_FEC_5_6 |
323 FE_CAN_FEC_6_7 |
324 FE_CAN_FEC_7_8 |
325 FE_CAN_FEC_8_9 |
326 FE_CAN_QAM_16 |
327 FE_CAN_QAM_64 |
328 FE_CAN_QAM_32 |
329 FE_CAN_QAM_128 |
330 FE_CAN_QAM_256 |
331 FE_CAN_QAM_AUTO |
332 FE_CAN_QPSK |
333 FE_CAN_FEC_AUTO |
334 FE_CAN_INVERSION_AUTO |
335 FE_CAN_TRANSMISSION_MODE_AUTO |
336 FE_CAN_GUARD_INTERVAL_AUTO |
337 FE_CAN_HIERARCHY_AUTO,
338 }
339
340 ....
341
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>`_.
345
346 Using dvb-scan
347 ~~~~~~~~~~~~~~
348
349 In order to tune into a channel and read the PSI tables, we can use dvb-scan.
350
351 For this, one should provide a configuration file known as a 'scan file',
352 here's an example::
353
354 [Channel]
355 FREQUENCY = 474000000
356 MODULATION = QAM/AUTO
357 SYMBOL_RATE = 6940000
358 INNER_FEC = AUTO
359 DELIVERY_SYSTEM = DVBC/ANNEX_A
360
361 .. note::
362 The parameters depend on the video standard you're testing.
363
364 .. note::
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'.
369
370 You can browse scan tables online here: `dvb-scan-tables
371 <https://git.linuxtv.org/dtv-scan-tables.git>`_.
372
373 Assuming this channel is named 'channel.conf', you can then run::
374
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
384
385 For more information on dvb-scan, check its documentation online here:
386 `dvb-scan Documentation <https://www.linuxtv.org/wiki/index.php/Dvbscan>`_.
387
388 Using dvb-zap
389 ~~~~~~~~~~~~~
390
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]_::
394
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
399 pass all PID's to TS
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
407
408 .. [1] In this example, it records 10 seconds with all program ID's stored
409 at the music.ts file.
410
411
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``.
414
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::
417
418 $ mplayer music.ts
419
420 or, alternatively, running this command on one terminal::
421
422 $ dvbv5-zap -c dvb_channel.conf "beethoven" -P -r &
423
424 And, on a second terminal, playing the contents from DVR interface with::
425
426 $ mplayer /dev/dvb/adapter0/dvr0
427
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>`_.
432
433
434 What can still be improved in vidtv
435 -----------------------------------
436
437 Add *debugfs* integration
438 ~~~~~~~~~~~~~~~~~~~~~~~~~
439
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.
444
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.
448
449 The Siano driver is one example of a driver using
450 debugfs to convey driver-specific statistics to userspace and it can be
451 used as a reference.
452
453 This should be further enabled and disabled via a Kconfig
454 option for convenience.
455
456 Add a way to test video
457 ~~~~~~~~~~~~~~~~~~~~~~~
458
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.
464
465 This might optionally use the Video4Linux2 Test Pattern Generator, v4l2-tpg,
466 which resides at::
467
468 drivers/media/common/v4l2-tpg/
469
470
471 Add white noise simulation
472 ~~~~~~~~~~~~~~~~~~~~~~~~~~
473
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.
478
479 A nice addition is to simulate some noise when the signal quality is bad by:
480
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.
483
484 - Updating the error statistics accordingly (e.g. BER, etc).
485
486 - Simulating some noise in the encoded data.
487
488 Functions and structs used within vidtv
489 ---------------------------------------
490
491 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_bridge.h
492
493 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_channel.h
494
495 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_demod.h
496
497 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_encoder.h
498
499 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_mux.h
500
501 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_pes.h
502
503 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_psi.h
504
505 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_s302m.h
506
507 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_ts.h
508
509 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_tuner.h
510
511 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_common.c
512
513 .. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_tuner.c
514

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

배경과 구성 요소

1-37

이 `GPL-2.0` 문서는 Daniel W. S. Almeida가 2020년 6월 작성했습니다. `vidtv`는 driver 작성자가 template으로 참고할 수 있게 만든 virtual DVB driver이며, 기존 media DVB API도 검증하므로 userspace application 작성자에게도 도움이 됩니다.

현재 구성에는 fake tuner, fake demodulator, fake bridge와 유효한 MPEG Transport Stream encoder가 포함됩니다. Fake tuner는 선택한 frequency가 delivery system별 유효 주파수 표에서 너무 멀면 나쁜 signal quality를 보고합니다.

Fake demodulator는 tuner가 돌려주는 signal quality를 계속 polling합니다. CNR level에 따라 signal lock을 잃거나 다시 획득하는 실제 장치의 동작을 모사합니다. Fake bridge는 tuner와 demod module을 `modprobe`하고 demux logic을 구현하며, 초기화 parameter로 simulation 동작을 결정합니다.

MPEG Transport Stream encoder가 만든 유효 stream은 bridge로 전달됩니다. 현재 hardcoded content는 audio-only channel 하나와 MPEG Elementary Stream 하나이며, 그 ES에는 SMPTE 302M으로 encoding한 sine wave가 들어 있습니다. SMPTE 302M을 선택한 이유는 PCM audio를 MPEG Transport Stream에 넣는 가장 간단한 방법이기 때문입니다.

vidtv 상위 구성
구성 요소역할모사하는 동작
Fake tuner주파수 유효성에 따른 signal quality 보고Delivery system별 유효 frequency와의 거리
Fake demodulatorSignal quality polling과 lock status 결정CNR에 따른 lock 상실·재획득
Fake bridgeTuner·demod load, demux logic, parameter 적용DVB bridge 초기화와 data 전달
MPEG-TS encoderHardcoded audio stream 생성SMPTE 302M sine-wave를 담은 단일 ES

.. SPDX-License-Identifier: GPL-2.0

================================
vidtv: Virtual Digital TV driver
================================

Author: Daniel W. S. Almeida <dwlsalmeida@gmail.com>, June 2020.

Background
----------

Vidtv is a virtual DVB driver that aims to serve as a reference for driver
writers by serving as a template. It also validates the existing media DVB
APIs, thus helping userspace application writers.

Currently, it consists of:

- A fake tuner driver, which will report a bad signal quality if the chosen
  frequency is too far away from a table of valid frequencies for a
  particular delivery system.

- A fake demod driver, which will constantly poll the fake signal quality
  returned by the tuner, simulating a device that can lose/reacquire a lock
  on the signal depending on the CNR levels.

- A fake bridge driver, which is the module responsible for modprobing the
  fake tuner and demod modules and implementing the demux logic. This module
  takes parameters at initialization that will dictate how the simulation
  behaves.

- Code responsible for encoding a valid MPEG Transport Stream, which is then
  passed to the bridge driver. This fake stream contains some hardcoded content.
  For now, we have a single, audio-only channel containing a single MPEG
  Elementary Stream, which in turn contains a SMPTE 302m encoded sine-wave.
  Note that this particular encoder was chosen because it is the easiest
  way to encode PCM audio data in a MPEG Transport Stream.

Build와 실행

38-74

`vidtv`는 test driver이므로 kernel compile 시 기본으로 enable되지 않습니다. 먼저 `DVB_TEST_DRIVERS`를 enable하고 이어서 `DVB_VIDTV`를 enable해야 합니다.

Module로 build하면 `dvb_vidtv_tuner.ko`, `dvb_vidtv_demod.ko`, `dvb_vidtv_bridge.ko`가 생성됩니다. `modprobe vidtv`를 실행하면 bridge driver가 자신의 초기화 과정에서 tuner와 demod driver를 초기화합니다.

기본적으로 DVB-T/T2/C에는 474 MHz를, DVB-S/S2에는 원문 표기 `11,362 GHz`를 허용합니다. Satellite system에서는 10.7 GHz부터 12.75 GHz까지의 Ku-Band frequency를 갖는 universal extended LNBf를 모사합니다. 필요하면 command-line argument로 동작을 바꿀 수 있습니다.

vidtv build와 시작
Enable `DVB_TEST_DRIVERS`Enable `DVB_VIDTV`Kernel/module build
`dvb_vidtv_tuner.ko``dvb_vidtv_demod.ko``dvb_vidtv_bridge.ko`
`modprobe vidtv`Bridge initializationTuner + demod initialization
DVB-T/T2/C474 MHz
DVB-S/S2Ku-Band 10.7-12.75 GHzUniversal extended LNBf simulation

Kconfig 선택부터 bridge가 하위 virtual frontend를 준비하는 순서입니다.

Building vidtv
--------------
vidtv is a test driver and thus is **not** enabled by default when
compiling the kernel.

In order to enable compilation of vidtv:

- Enable **DVB_TEST_DRIVERS**, then
- Enable **DVB_VIDTV**

When compiled as a module, expect the following .ko files:

- dvb_vidtv_tuner.ko

- dvb_vidtv_demod.ko

- dvb_vidtv_bridge.ko

Running vidtv
-------------
When compiled as a module, run::

        modprobe vidtv

That's it! The bridge driver will initialize the tuner and demod drivers as
part of its own initialization.

By default, it will accept the following frequencies:

        - 474 MHz for DVB-T/T2/C;
        - 11,362 GHz for DVB-S/S2.

For satellite systems, the driver simulates an universal extended
LNBf, with frequencies at Ku-Band, ranging from 10.7 GHz to 12.75 GHz.

You can optionally define some command-line arguments to vidtv.

vidtv command-line argument

75-123

`drop_tslock_prob_on_low_snr`는 signal quality가 나쁠 때 TS lock을 잃을 확률입니다. Fake demodulator가 좋지 않은 signal에서 때때로 status `0`을 반환하는 데 사용합니다. `recover_tslock_prob_on_good_snr`는 signal이 좋아졌을 때 TS lock을 회복할 확률이며, demodulator가 때때로 status `0x1f`를 반환하게 합니다.

`mock_power_up_delay_msec`는 power-up delay를, `mock_tune_delay_msec`는 tune delay를 모사하며 둘의 기본값은 `0`입니다. `vidtv_valid_dvb_t_freqs`와 `vidtv_valid_dvb_c_freqs`는 각각 모사할 유효 DVB-T·DVB-C frequency를 Hz로 지정하고, `vidtv_valid_dvb_s_freqs`는 Ku-Band DVB-S/S2 frequency를 kHz로 지정합니다.

`max_frequency_shift_hz`는 channel tuning 시 허용할 최대 shift를 Hz로 지정합니다. `si_period_msec`는 SI packet 전송 주기, `pcr_period_msec`는 PCR packet 전송 주기이며 둘 다 기본값은 40 ms입니다.

`mux_rate_kbytes_sec`는 필요할 때 TS NULL packet을 삽입해 유지하려는 bit rate이며 기본값은 4096입니다. `pcr_pid`는 모든 channel의 PCR PID로 기본값은 `0x200`입니다. `mux_buf_sz_pkts`는 188-byte packet의 배수로 mux buffer 크기를 지정합니다.

vidtv module parameter
Parameter단위·기본값효과
`drop_tslock_prob_on_low_snr`ProbabilityLow SNR에서 status `0`, TS lock 상실 모사
`recover_tslock_prob_on_good_snr`ProbabilitySignal 개선 시 status `0x1f`, lock 회복 모사
`mock_power_up_delay_msec`ms, 기본 `0`Power-up delay
`mock_tune_delay_msec`ms, 기본 `0`Tune delay
`vidtv_valid_dvb_t_freqs`Hz유효 DVB-T frequency 목록
`vidtv_valid_dvb_c_freqs`Hz유효 DVB-C frequency 목록
`vidtv_valid_dvb_s_freqs`kHzKu-Band 유효 DVB-S/S2 frequency 목록
`max_frequency_shift_hz`HzChannel tuning 허용 최대 shift
`si_period_msec`ms, 기본 `40`SI packet 전송 주기
`pcr_period_msec`ms, 기본 `40`PCR packet 전송 주기
`mux_rate_kbytes_sec`기본 `4096`NULL packet으로 유지할 mux bit rate
`pcr_pid`기본 `0x200`모든 channel의 PCR PID
`mux_buf_sz_pkts`188-byte packet 배수Mux buffer 크기

Command-line arguments to vidtv
-------------------------------
Below is a list of all arguments that can be supplied to vidtv:

drop_tslock_prob_on_low_snr
        Probability of losing the TS lock if the signal quality is bad.
        This probability be used by the fake demodulator driver to
        eventually return a status of 0 when the signal quality is not
        good.

recover_tslock_prob_on_good_snr:
        Probability recovering the TS lock when the signal improves. This
        probability be used by the fake demodulator driver to eventually
        return a status of 0x1f when/if the signal quality improves.

mock_power_up_delay_msec
        Simulate a power up delay.  Default: 0.

mock_tune_delay_msec
        Simulate a tune delay.  Default 0.

vidtv_valid_dvb_t_freqs
        Valid DVB-T frequencies to simulate, in Hz.

vidtv_valid_dvb_c_freqs
        Valid DVB-C frequencies to simulate, in Hz.

vidtv_valid_dvb_s_freqs
        Valid DVB-S/S2 frequencies to simulate at Ku-Band, in kHz.

max_frequency_shift_hz,
        Maximum shift in HZ allowed when tuning in a channel.

si_period_msec
        How often to send SI packets.  Default: 40ms.

pcr_period_msec
        How often to send PCR packets.  Default: 40ms.

mux_rate_kbytes_sec
        Attempt to maintain this bit rate by inserting TS null packets, if
        necessary.  Default: 4096.

pcr_pid,
        PCR PID for all channels.  Default: 0x200.

mux_buf_sz_pkts,
        Size for the mux buffer in multiples of 188 bytes.

내부 module과 MPEG 계층

124-190

Kernel module 쪽에서 `vidtv_tuner.[ch]`는 fake tuner DVB driver, `vidtv_demod.[ch]`는 fake demodulator DVB driver, `vidtv_bridge.[ch]`는 bridge driver를 구현합니다.

MPEG 관련 code 중 `vidtv_ts.[ch]`는 TS header, adaptation field, PCR packet, NULL packet 같은 MPEG-TS packet을 다룹니다. `vidtv_psi.[ch]`는 userspace가 Transport Stream 정보를 읽고 dummy channel에 tune할 수 있게 PSI를 생성합니다. 별도 파일이므로 media subsystem의 다른 위치에서도 재사용할 수 있습니다.

현재 지원하는 PSI table은 PAT, PMT, SDT, NIT, EIT 다섯 가지입니다. PAT와 PMT 사양은 `ISO 13818-1: Systems`에, SDT·NIT·EIT 사양은 `ETSI EN 300 468: Specification for Service Information (SI) in DVB systems`에 있습니다.

엄격히 필요하지는 않지만 실제 TS file은 PSI table debugging에 유용합니다. Vidtv는 `TS1Globo.ts`의 PSI 구조를 재현하려 하며 원문은 `https://tsduck.io/streams/brazil-isdb-tb/TS1globo.ts`를 가리킵니다. Stream 구조 시각화에는 `DVBInspector`를 사용할 수 있습니다.

`vidtv_pes.[ch]`는 encoder data를 MPEG-TS packet으로 바꾸는 PES logic을 구현하고, 이 packet은 TS multiplexer를 거쳐 userspace로 전달됩니다. `vidtv_encoder.h`는 encoder interface이며 해당 call을 구현해 새 encoder를 추가할 수 있습니다.

`vidtv_s302m.[ch]`는 생성한 MPEG Transport Stream에 PCM audio를 넣는 S302M encoder입니다. 관련 사양은 `SMPTE 302M-2007: Television - Mapping of AES3 Data into MPEG-2 Transport Stream`입니다. 결과 MPEG Elementary Stream은 S302M registration descriptor를 붙인 private stream으로 운반됩니다.

이 audio signal은 userspace로 넘어가 media software에서 decode·play할 수 있습니다. 대응하는 ffmpeg decoder는 `libavcodec/s302m.c`에 있으며 experimental 상태입니다.

vidtv 내부 파일 계층
파일계층역할
`vidtv_tuner.[ch]`DVB frontendFake tuner driver
`vidtv_demod.[ch]`DVB frontendFake demodulator driver
`vidtv_bridge.[ch]`Bridge/demuxModule 연결과 demux 전달
`vidtv_ts.[ch]`MPEG-TSTS header, adaptation, PCR, NULL packet
`vidtv_psi.[ch]`PSI/SIPAT·PMT·SDT·NIT·EIT 생성
`vidtv_pes.[ch]`PESEncoder data를 MPEG-TS packet으로 변환
`vidtv_encoder.h`Encoder API새 encoder 구현 interface
`vidtv_s302m.[ch]`Audio encoderPCM을 SMPTE 302M private stream으로 encoding
`libavcodec/s302m.c`Userspace decoderExperimental ffmpeg S302M decoder

vidtv internal structure
------------------------
The kernel modules are split in the following way:

vidtv_tuner.[ch]
        Implements a fake tuner DVB driver.

vidtv_demod.[ch]
        Implements a fake demodulator DVB driver.

vidtv_bridge.[ch]
        Implements a bridge driver.

The MPEG related code is split in the following way:

vidtv_ts.[ch]
        Code to work with MPEG TS packets, such as TS headers, adaptation
        fields, PCR packets and NULL packets.

vidtv_psi.[ch]
        This is the PSI generator.  PSI packets contain general information
        about a MPEG Transport Stream.  A PSI generator is needed so
        userspace apps can retrieve information about the Transport Stream
        and eventually tune into a (dummy) channel.

        Because the generator is implemented in a separate file, it can be
        reused elsewhere in the media subsystem.

        Currently vidtv supports working with 5 PSI tables: PAT, PMT,
        SDT, NIT and EIT.

        The specification for PAT and PMT can be found in *ISO 13818-1:
        Systems*, while the specification for the SDT, NIT, EIT can be found in *ETSI
        EN 300 468: Specification for Service Information (SI) in DVB
        systems*.

        It isn't strictly necessary, but using a real TS file helps when
        debugging PSI tables. Vidtv currently tries to replicate the PSI
        structure found in this file: `TS1Globo.ts
        <https://tsduck.io/streams/brazil-isdb-tb/TS1globo.ts>`_.

        A good way to visualize the structure of streams is by using
        `DVBInspector <https://sourceforge.net/projects/dvbinspector/>`_.

vidtv_pes.[ch]
        Implements the PES logic to convert encoder data into MPEG TS
        packets. These can then be fed into a TS multiplexer and eventually
        into userspace.

vidtv_encoder.h
        An interface for vidtv encoders. New encoders can be added to this
        driver by implementing the calls in this file.

vidtv_s302m.[ch]
        Implements a S302M encoder to make it possible to insert PCM audio
        data in the generated MPEG Transport Stream. The relevant
        specification is available online as *SMPTE 302M-2007: Television -
        Mapping of AES3 Data into MPEG-2 Transport Stream*.


        The resulting MPEG Elementary Stream is conveyed in a private
        stream with a S302M registration descriptor attached.

        This shall enable passing an audio signal into userspace so it can
        be decoded and played by media software. The corresponding decoder
        in ffmpeg is located in 'libavcodec/s302m.c' and is experimental.

Channel 구성과 TS mux loop

191-229

`vidtv_channel.[ch]`는 channel abstraction을 구현합니다. Vidtv가 boot하면 hardcoded channel을 만들고, service를 이어 붙여 SDT를, program을 이어 붙여 PAT를, event를 이어 붙여 EIT를 채웁니다.

PAT의 각 program마다 PMT section을 만들고, channel의 PMT section에 stream을 할당합니다. 각 stream의 encoder를 loop에서 polling해 TS packet을 생성합니다. Muxer는 packet을 서로 interleave할 수 있고, 최종 packet을 bridge로 전달합니다.

`vidtv_mux.[ch]`는 ffmpeg의 `libavcodec/mpegtsenc.c`를 느슨하게 참고한 MPEG-TS mux입니다. Loop는 마지막 iteration 이후 흐른 시간을 추적하고, encoder에서 그 `elapsed_time`만큼의 data를 가져옵니다.

필요하면 PSI 또는 PCR packet을 삽입하고, 선택한 bit rate를 유지해야 하면 결과 stream을 NULL packet으로 padding합니다. 완성한 TS packet은 bridge driver에 전달되고 bridge가 demux로 넘깁니다.

Hardcoded channel에서 TS packet까지
Channel servicesConcatenateSDT
Channel programsConcatenatePATProgram별 PMT 생성
Channel eventsConcatenateEIT
PMT에 stream 할당Encoder pollingTS packets
Mux interleaveBridgeDemux

Channel metadata와 stream encoder가 MPEG-TS로 결합되는 순서입니다.

MPEG-TS mux iteration
이전 iteration 이후 시간 계산`elapsed_time`
Encoder polling`elapsed_time`만큼 data 수집
필요 시 PSI 삽입필요 시 PCR 삽입
목표 bit rate 미달NULL packet padding
TS packet batchBridge driverDemux

`elapsed_time`을 기준으로 data와 timing packet을 만들고 목표 rate를 맞춥니다.

vidtv_channel.[ch]
        Implements a 'channel' abstraction.

        When vidtv boots, it will create some hardcoded channels:

        #. Their services will be concatenated to populate the SDT.

        #. Their programs will be concatenated to populate the PAT

        #. Their events will be concatenated to populate the EIT

        #. For each program in the PAT, a PMT section will be created

        #. The PMT section for a channel will be assigned its streams.

        #. Every stream will have its corresponding encoder polled in a
           loop to produce TS packets.
           These packets may be interleaved by the muxer and then delivered
           to the bridge.

vidtv_mux.[ch]
        Implements a MPEG TS mux, loosely based on the ffmpeg
        implementation in "libavcodec/mpegtsenc.c"

        The muxer runs a loop which is responsible for:

        #. Keeping track of the amount of time elapsed since the last
           iteration.

        #. Polling encoders in order to fetch 'elapsed_time' worth of data.

        #. Inserting PSI and/or PCR packets, if needed.

        #. Padding the resulting stream with NULL packets if
           necessary in order to maintain the chosen bit rate.

        #. Delivering the resulting TS packets to the bridge
           driver so it can pass them to the demux.

v4l-utils와 dvb-fe-tool로 frontend 확인

230-345

`v4l-utils` 도구는 vidtv 출력을 시험하고 검사하기에 적합합니다. 이 project는 대부분의 distribution에서 package로 제공되며 media device의 여러 측면을 제어하는 library와 utility를 포함합니다. 원문은 v4l-utils documentation과 `http://git.linuxtv.org/v4l-utils.git`를 안내합니다.

먼저 v4l-utils를 설치하고 `modprobe dvb_vidtv_bridge`를 실행합니다. Driver가 정상이라면 probe code가 실행되며 tuner와 demod driver를 함께 불러옵니다.

Demod가 성공적으로 load됐는지 확인하려면 `dvb-fe-tool`을 실행합니다. 예제 출력은 `/dev/dvb/adapter0/frontend0`의 `Dummy demod for DVB-T/T2/C/S/S2`가 FEC 1/2부터 8/9, automatic FEC·guard interval·hierarchy·inversion·transmission mode, QAM 16/32/64/128/256/AUTO와 QPSK capability를 제공함을 보여 줍니다.

예제의 DVB API version은 5.11이고 현재 delivery system은 `DVBC/ANNEX_A`입니다. 지원 system은 `DVBT`, `DVBT2`, `DVBC/ANNEX_A`, `DVBS`, `DVBS2`입니다. 현재 standard의 frequency 범위는 51.0 MHz부터 2.15 GHz, step은 62.5 kHz, tolerance는 29.5 MHz입니다. Symbol rate 범위는 1.00 MBauds부터 45.0 MBauds입니다.

이 출력은 `static const struct dvb_frontend_ops vidtv_demod_ops`의 설정을 반영합니다. `.delsys` 배열은 다섯 delivery system을, `.info`는 name, `frequency_min_hz`, `frequency_max_hz`, `frequency_stepsize_hz`, `frequency_tolerance_hz`, `symbol_rate_min`, `symbol_rate_max`와 `FE_CAN_*` capability bit를 정의합니다.

자세한 사용법은 원문의 `dvb-fe-tool Documentation` 링크에서 확인할 수 있습니다.

Frontend 확인 절차
단계명령·대상기대 결과
1v4l-utils 설치DVB inspection utility 준비
2`modprobe dvb_vidtv_bridge`Bridge probe와 tuner·demod load
3`dvb-fe-tool``/dev/dvb/adapter0/frontend0` capability 출력
4`vidtv_demod_ops` 대조출력과 `.delsys`·`.info`·`.caps` 일치

Dummy demod capability
분류보고 값Driver field
Delivery systems`DVBT`, `DVBT2`, `DVBC/ANNEX_A`, `DVBS`, `DVBS2``.delsys`
Frequency51 MHz-2150 MHz`.frequency_min_hz`, `.frequency_max_hz`
Step62.5 kHz`.frequency_stepsize_hz = 62500`
Tolerance29.5 MHz`.frequency_tolerance_hz = 29500 * kHz`
Symbol rate1,000,000-45,000,000`.symbol_rate_min`, `.symbol_rate_max`
FEC1/2, 2/3, 3/4, 4/5, 5/6, 6/7, 7/8, 8/9, AUTO`FE_CAN_FEC_*`
ModulationQAM 16/32/64/128/256/AUTO, QPSK`FE_CAN_QAM_*`, `FE_CAN_QPSK`
Automatic modesInversion, transmission, guard interval, hierarchy`FE_CAN_*_AUTO`

Testing vidtv with v4l-utils
----------------------------

Using the tools in v4l-utils is a great way to test and inspect the output of
vidtv. It is hosted here: `v4l-utils Documentation
<https://linuxtv.org/wiki/index.php/V4l-utils>`_.

From its webpage::

        The v4l-utils are a series of packages for handling media devices.

        It is hosted at http://git.linuxtv.org/v4l-utils.git, and packaged
        on most distributions.

        It provides a series of libraries and utilities to be used to
        control several aspect of the media boards.


Start by installing v4l-utils and then modprobing vidtv::

        modprobe dvb_vidtv_bridge

If the driver is OK, it should load and its probing code will run. This will
pull in the tuner and demod drivers.

Using dvb-fe-tool
~~~~~~~~~~~~~~~~~

The first step to check whether the demod loaded successfully is to run::

        $ dvb-fe-tool
        Device Dummy demod for DVB-T/T2/C/S/S2 (/dev/dvb/adapter0/frontend0) capabilities:
            CAN_FEC_1_2
            CAN_FEC_2_3
            CAN_FEC_3_4
            CAN_FEC_4_5
            CAN_FEC_5_6
            CAN_FEC_6_7
            CAN_FEC_7_8
            CAN_FEC_8_9
            CAN_FEC_AUTO
            CAN_GUARD_INTERVAL_AUTO
            CAN_HIERARCHY_AUTO
            CAN_INVERSION_AUTO
            CAN_QAM_16
            CAN_QAM_32
            CAN_QAM_64
            CAN_QAM_128
            CAN_QAM_256
            CAN_QAM_AUTO
            CAN_QPSK
            CAN_TRANSMISSION_MODE_AUTO
        DVB API Version 5.11, Current v5 delivery system: DVBC/ANNEX_A
        Supported delivery systems:
            DVBT
            DVBT2
            [DVBC/ANNEX_A]
            DVBS
            DVBS2
        Frequency range for the current standard:
        From:            51.0 MHz
        To:              2.15 GHz
        Step:            62.5 kHz
        Tolerance:       29.5 MHz
        Symbol rate ranges for the current standard:
        From:            1.00 MBauds
        To:              45.0 MBauds

This should return what is currently set up at the demod struct, i.e.::

        static const struct dvb_frontend_ops vidtv_demod_ops = {
                .delsys = {
                        SYS_DVBT,
                        SYS_DVBT2,
                        SYS_DVBC_ANNEX_A,
                        SYS_DVBS,
                        SYS_DVBS2,
                },

                .info = {
                        .name                   = "Dummy demod for DVB-T/T2/C/S/S2",
                        .frequency_min_hz       = 51 * MHz,
                        .frequency_max_hz       = 2150 * MHz,
                        .frequency_stepsize_hz  = 62500,
                        .frequency_tolerance_hz = 29500 * kHz,
                        .symbol_rate_min        = 1000000,
                        .symbol_rate_max        = 45000000,

                        .caps = FE_CAN_FEC_1_2 |
                                FE_CAN_FEC_2_3 |
                                FE_CAN_FEC_3_4 |
                                FE_CAN_FEC_4_5 |
                                FE_CAN_FEC_5_6 |
                                FE_CAN_FEC_6_7 |
                                FE_CAN_FEC_7_8 |
                                FE_CAN_FEC_8_9 |
                                FE_CAN_QAM_16 |
                                FE_CAN_QAM_64 |
                                FE_CAN_QAM_32 |
                                FE_CAN_QAM_128 |
                                FE_CAN_QAM_256 |
                                FE_CAN_QAM_AUTO |
                                FE_CAN_QPSK |
                                FE_CAN_FEC_AUTO |
                                FE_CAN_INVERSION_AUTO |
                                FE_CAN_TRANSMISSION_MODE_AUTO |
                                FE_CAN_GUARD_INTERVAL_AUTO |
                                FE_CAN_HIERARCHY_AUTO,
                }

                ....

For more information on dvb-fe-tools check its online documentation here:
`dvb-fe-tool Documentation
<https://www.linuxtv.org/wiki/index.php/Dvb-fe-tool>`_.

dvb-scan으로 tune하고 PSI 읽기

346-387

Channel에 tune하고 PSI table을 읽으려면 `dvb-scan`을 사용할 수 있습니다. 이를 위해 scan file이라는 configuration file을 제공합니다. 예제 `[Channel]`은 `FREQUENCY = 474000000`, `MODULATION = QAM/AUTO`, `SYMBOL_RATE = 6940000`, `INNER_FEC = AUTO`, `DELIVERY_SYSTEM = DVBC/ANNEX_A`를 지정합니다.

Parameter는 시험하는 video standard에 따라 달라집니다. Vidtv는 fake driver라 scan file 정보를 많이 검증하지 않습니다. DVB-T/DVB-T2에는 `FREQUENCY`와 `DELIVERY_SYSTEM`만으로 충분하지만, DVB-S/DVB-C에는 `SYMBOL_RATE`도 제공해야 합니다. 원문은 online `dvb-scan-tables` repository를 안내합니다.

File 이름을 `channel.conf`로 정했다면 `dvbv5-scan channel.conf`를 실행합니다. 예제 출력은 bandwidth 또는 symbol-rate가 아직 없어 frequency shift를 계산하지 못했다는 message 뒤 330000000 Hz에서 약한 signal을 보고하고, 474000000 Hz에서 status `0x1f`로 lock한 뒤 `Beethoven` service와 provider `LinuxTV.org`를 찾습니다.

더 자세한 내용은 원문의 `dvb-scan Documentation` 링크에서 확인할 수 있습니다.

Scan file과 결과
항목예제 값해설
`FREQUENCY``474000000`DVB-T/T2/S/C 모두 필요한 tuning frequency
`MODULATION``QAM/AUTO`예제 modulation
`SYMBOL_RATE``6940000`특히 DVB-S/DVB-C에 필요
`INNER_FEC``AUTO`예제 inner FEC
`DELIVERY_SYSTEM``DVBC/ANNEX_A`시험할 delivery system
첫 scan`330000000`, Signal `-68.00dBm`Lock 없음
둘째 scan`474000000`, Lock `0x1f``Beethoven`, `LinuxTV.org` 발견

Using dvb-scan
~~~~~~~~~~~~~~

In order to tune into a channel and read the PSI tables, we can use dvb-scan.

For this, one should provide a configuration file known as a 'scan file',
here's an example::

        [Channel]
        FREQUENCY = 474000000
        MODULATION = QAM/AUTO
        SYMBOL_RATE = 6940000
        INNER_FEC = AUTO
        DELIVERY_SYSTEM = DVBC/ANNEX_A

.. note::
        The parameters depend on the video standard you're testing.

.. note::
        Vidtv is a fake driver and does not validate much of the information
        in the scan file. Just specifying 'FREQUENCY' and 'DELIVERY_SYSTEM'
        should be enough for DVB-T/DVB-T2. For DVB-S/DVB-C however, you
        should also provide 'SYMBOL_RATE'.

You can browse scan tables online here: `dvb-scan-tables
<https://git.linuxtv.org/dtv-scan-tables.git>`_.

Assuming this channel is named 'channel.conf', you can then run::

        $ dvbv5-scan channel.conf
        dvbv5-scan ~/vidtv.conf
        ERROR    command BANDWIDTH_HZ (5) not found during retrieve
        Cannot calc frequency shift. Either bandwidth/symbol-rate is unavailable (yet).
        Scanning frequency #1 330000000
            (0x00) Signal= -68.00dBm
        Scanning frequency #2 474000000
        Lock   (0x1f) Signal= -34.45dBm C/N= 33.74dB UCB= 0
        Service Beethoven, provider LinuxTV.org: digital television

For more information on dvb-scan, check its documentation online here:
`dvb-scan Documentation <https://www.linuxtv.org/wiki/index.php/Dvbscan>`_.

dvbv5-zap으로 MPEG-TS 기록과 재생

388-433

`dvbv5-zap`은 channel에 tune한 뒤 record mode로 MPEG-TS를 disk에 저장하는 command-line tool입니다. 예제 `dvbv5-zap -c dvb_channel.conf "beethoven" -o music.ts -P -t 10`은 모든 program ID를 포함해 10초 동안 `music.ts`에 기록합니다.

출력은 `dvb0.demux0` 사용, channel file 읽기, 474000000 Hz tuning, 모든 PID를 TS에 전달, PES filter 8192와 buffer size 6160384 설정을 보여 줍니다. Lock quality와 signal·C/N·UCB·BER·PER를 보고한 뒤 recording을 시작하며 예제에서는 24,587,768 byte를 약 2401 Kbytes/sec로 받습니다.

기록한 stream은 MPEG-TS를 인식하는 `mplayer`나 `vlc`로 재생해 vidtv 동작을 살펴볼 수 있습니다. `mplayer music.ts`로 file을 직접 재생할 수 있습니다.

또는 첫 terminal에서 `dvbv5-zap -c dvb_channel.conf "beethoven" -P -r &`를 실행하고, 둘째 terminal에서 `mplayer /dev/dvb/adapter0/dvr0`로 DVR interface의 내용을 재생할 수 있습니다. 원문은 `dvb-zap Documentation`, `Dvbv5-zap`, `Zap` 링크를 제공합니다.

Tune, record, play
`dvbv5-zap`Tune 474000000 HzLock `0x1f`
File mode `-o music.ts -t 10`모든 PID 기록`music.ts``mplayer` 또는 `vlc`
DVR mode `-P -r``/dev/dvb/adapter0/dvr0``mplayer`
관찰Signal·C/N·UCB·BER·PERMPEG-TS audio 재생

File recording 경로와 live DVR 재생 경로를 함께 정리했습니다.

Using dvb-zap
~~~~~~~~~~~~~

dvbv5-zap is a command line tool that can be used to record MPEG-TS to disk. The
typical use is to tune into a channel and put it into record mode. The example
below - which is taken from the documentation - illustrates that\ [1]_::

        $ dvbv5-zap -c dvb_channel.conf "beethoven" -o music.ts -P -t 10
        using demux 'dvb0.demux0'
        reading channels from file 'dvb_channel.conf'
        tuning to 474000000 Hz
        pass all PID's to TS
        dvb_set_pesfilter 8192
        dvb_dev_set_bufsize: buffer set to 6160384
        Lock   (0x1f) Quality= Good Signal= -34.66dBm C/N= 33.41dB UCB= 0 postBER= 0 preBER= 1.05x10^-3 PER= 0
        Lock   (0x1f) Quality= Good Signal= -34.57dBm C/N= 33.46dB UCB= 0 postBER= 0 preBER= 1.05x10^-3 PER= 0
        Record to file 'music.ts' started
        received 24587768 bytes (2401 Kbytes/sec)
        Lock   (0x1f) Quality= Good Signal= -34.42dBm C/N= 33.89dB UCB= 0 postBER= 0 preBER= 2.44x10^-3 PER= 0

.. [1] In this example, it records 10 seconds with all program ID's stored
       at the music.ts file.


The channel can be watched by playing the contents of the stream with some
player that  recognizes the MPEG-TS format, such as ``mplayer`` or ``vlc``.

By playing the contents of the stream one can visually inspect the workings of
vidtv, e.g., to play a recorded TS file with::

        $ mplayer music.ts

or, alternatively, running this command on one terminal::

        $ dvbv5-zap -c dvb_channel.conf "beethoven" -P -r &

And, on a second terminal, playing the contents from DVR interface with::

        $ mplayer /dev/dvb/adapter0/dvr0

For more information on dvb-zap check its online documentation here:
`dvb-zap Documentation
<https://www.linuxtv.org/wiki/index.php/Dvbv5-zap>`_.
See also: `zap <https://www.linuxtv.org/wiki/index.php/Zap>`_.

vidtv의 개선 과제

434-487

첫 번째 과제는 `debugfs` integration입니다. Frontend driver는 `.read_status` call을 통해 DVBv5 statistics를 제공하지만, debug purpose용 RAM-based filesystem인 debugfs로 추가 driver-specific statistics를 userspace에 제공하면 유용합니다.

이 logic은 frontend driver를 복잡하게 하지 않도록 별도 파일에 구현해야 합니다. Siano driver가 debugfs로 driver-specific statistics를 userspace에 전달하는 참고 사례이며, 편의를 위해 별도 Kconfig option으로 enable·disable할 수 있어야 합니다.

두 번째 과제는 video test입니다. 현재 vidtv는 PCM audio만 encoding합니다. MPEG Transport Stream에서 compressed video encoding을 다루는 `ISO 13818-2: Information technology - Generic coding of moving pictures and associated audio information - Part 2: Video`를 바탕으로 최소 MPEG-2 video encoder를 구현할 수 있습니다.

Video source에는 `drivers/media/common/v4l2-tpg/`의 Video4Linux2 Test Pattern Generator인 `v4l2-tpg`를 선택적으로 사용할 수 있습니다.

세 번째 과제는 white noise simulation입니다. 현재 tuner는 선택 frequency가 유효 frequency 표에서 너무 먼지 판별하고, 나쁜 signal quality를 보고해 demodulator가 결국 lock을 잃게 할 수 있습니다.

Signal quality가 나쁠 때 noise를 모사하려면 TS packet을 무작위로 drop할 수 있습니다. Continuity counter는 갱신됐지만 packet이 demux로 전달되지 않으면 continuity error가 발생합니다. 또한 BER 같은 error statistics를 갱신하고 encoded data 자체에 noise를 모사할 수 있습니다.

개선 과제
과제구현 방향참고·검증 효과
`debugfs` integration별도 파일의 driver-specific statistics, Kconfig 제어Siano driver 참고, `.read_status` 보완
Video testBarebones MPEG-2 encoder`ISO 13818-2`, `drivers/media/common/v4l2-tpg/`
White noiseTS packet drop, error statistics, encoded data noiseContinuity error와 BER 등 복원력 시험

What can still be improved in vidtv
-----------------------------------

Add *debugfs* integration
~~~~~~~~~~~~~~~~~~~~~~~~~

Although frontend drivers provide DVBv5 statistics via the .read_status
call, a nice addition would be to make additional statistics available to
userspace via debugfs, which is a simple-to-use, RAM-based filesystem
specifically designed for debug purposes.

The logic for this would be implemented on a separate file so as not to
pollute the frontend driver.  These statistics are driver-specific and can
be useful during tests.

The Siano driver is one example of a driver using
debugfs to convey driver-specific statistics to userspace and it can be
used as a reference.

This should be further enabled and disabled via a Kconfig
option for convenience.

Add a way to test video
~~~~~~~~~~~~~~~~~~~~~~~

Currently, vidtv can only encode PCM audio. It would be great to implement
a barebones version of MPEG-2 video encoding so we can also test video. The
first place to look into is *ISO 13818-2: Information technology — Generic
coding of moving pictures and associated audio information — Part 2: Video*,
which covers the encoding of compressed video in MPEG Transport Streams.

This might optionally use the Video4Linux2 Test Pattern Generator, v4l2-tpg,
which resides at::

        drivers/media/common/v4l2-tpg/


Add white noise simulation
~~~~~~~~~~~~~~~~~~~~~~~~~~

The vidtv tuner already has code to identify whether the chosen frequency
is too far away from a table of valid frequencies. For now, this means that
the demodulator can eventually lose the lock on the signal, since the tuner will
report a bad signal quality.

A nice addition is to simulate some noise when the signal quality is bad by:

- Randomly dropping some TS packets. This will trigger a continuity error if the
  continuity counter is updated but the packet is not passed on to the demux.

- Updating the error statistics accordingly (e.g. BER, etc).

- Simulating some noise in the encoded data.

vidtv에서 사용하는 function과 struct

488-513

마지막 절은 vidtv implementation의 function과 struct를 kernel-doc으로 포함합니다. Header는 bridge, channel, demod, encoder, mux, PES, PSI, S302M, TS, tuner interface를 문서화합니다.

Source file에서는 공통 helper를 담은 `vidtv_common.c`와 tuner implementation인 `vidtv_tuner.c`의 kernel-doc을 포함합니다. 모든 path는 `drivers/media/test-drivers/vidtv/` 아래에 있습니다.

Kernel-doc source
Source path주요 영역
`drivers/media/test-drivers/vidtv/vidtv_bridge.h`Bridge
`drivers/media/test-drivers/vidtv/vidtv_channel.h`Channel abstraction
`drivers/media/test-drivers/vidtv/vidtv_demod.h`Fake demodulator
`drivers/media/test-drivers/vidtv/vidtv_encoder.h`Encoder interface
`drivers/media/test-drivers/vidtv/vidtv_mux.h`MPEG-TS mux
`drivers/media/test-drivers/vidtv/vidtv_pes.h`PES
`drivers/media/test-drivers/vidtv/vidtv_psi.h`PSI/SI
`drivers/media/test-drivers/vidtv/vidtv_s302m.h`SMPTE 302M encoder
`drivers/media/test-drivers/vidtv/vidtv_ts.h`TS packet
`drivers/media/test-drivers/vidtv/vidtv_tuner.h`Fake tuner interface
`drivers/media/test-drivers/vidtv/vidtv_common.c`Common helper
`drivers/media/test-drivers/vidtv/vidtv_tuner.c`Fake tuner implementation

Functions and structs used within vidtv
---------------------------------------

.. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_bridge.h

.. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_channel.h

.. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_demod.h

.. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_encoder.h

.. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_mux.h

.. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_pes.h

.. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_psi.h

.. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_s302m.h

.. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_ts.h

.. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_tuner.h

.. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_common.c

.. kernel-doc:: drivers/media/test-drivers/vidtv/vidtv_tuner.c