blob: 1196da03e11f84c49e193418137d4ad69670796a [file] [log] [blame]
Hamad Kadmanyd853d132012-05-30 13:13:46 +03001Introduction
2============
3MPQ DVB Adapter implements Digital Video Broadcasting devices according
4to LinuxTV (linuxtv.org) defined API and infrastructure.
5
6The implemented devices are dvb/demux devices, dvb/dvr devices and
7dvb/video devices.
8
9These devices are used in Qualcomm's MPQ chipsets that support
10broadcast applications.
11
12dvb/demux is responsible to receive a digital stream broadcasted over
13the air from a hardware unit (TSPP - Transport stream packet processor,
14or TSIF - Transport Stream Interface) and separates the stream into its
15various sub-streams such as video, audio and auxiliary data.
16The separation operation is named demuxing.
17
18dvb/dvr is used in conjunction with dvb/demux to re-play a digital
19stream from memory or to record stream to memory.
20
21dvb/video is used to handle the video decoding, it receives compressed
22video from dvb/demux through a stream-buffer interface and interacts
23with the existing HW video driver to perform the decoding.
24
25For more information on the TSIF interface, please refer to TSIF
26documentation under "Documentation/arm/msm/tsif.txt".
27For more information on the TSPP interface, please refer to TSPP
28documentation under "Documentation/arm/msm/tspp.txt".
29For more information on DVB-API definition, please refer dvb
30documentation under "Documentation/dvb/readme.txt".
31
32Hardware description
33====================
34dvb/demux, dvb/dvr and dvb/video do not interact with a hardware directly;
35The implementation of these drivers is done using the kernel API of TSPP,
36TSIF and video drivers.
37
38Software description
39====================
40
41Terminology
42-----------
43Stream: A stream is a TS packet source
44 - For example, MPEG2 Transport Stream from TSIF0
45Filter: Enables TS packet filtering and routing according to PID (packet ID)
46 - The decision regarding which PIDs in the stream will be routed
47 is done via filters, each demux open request corresponds to a filter.
48 - Filters can pass TS packets as-is (for recording), assemble them into
49 "other" PES packets (for PES packets read by client), assemble and send
50 them to decoder (for decoder PES), or assemble them into sections.
51Service: A service is a set of PIDs as defined in the service PMT.
52 Each service may be carried in a different transport stream or part of the
53 same transport stream. Processing a service means either preparing the
54 data for display and/or for recording.
55
56Requirments
57-----------
581. Demuxing from different sources:
59 - Live transport stream inputs (TSIF)
60 - Memory inputs
612. Support different packet formats:
62 - 188-bytes transport packets
63 - 192-bytes transport packets
643. PID filtering
654. Output of the following data:
66 - Decoder PES: PES (video and/or audio) that can be directed to HW decoders
67 in tunneling mode (without interaction of user-space).
68 - Other PES: a non-decoder PES, such as subtitle, teletext. The consumer
69 of this data is user-space that reads the data through standard read
70 calls.
71 - Sections: Sections are used by user-space to acquire different kinds of
72 information such as channels list, program user guide, etc.
73 - Transport Stream Packets: Transport stream packets of specific PIDs as
74 they were received in the input stream. User-space can use those to
75 record specific services and/or to perform time-shift buffer.
76 - PCR/STC: Pairs of PCR/STC can be used by user-space to perform
77 clock-recovery.
78 - Frame-indexing: For recorded stream, demux provides indexing of the
79 I-frames within the stream that can be used for trick-modes operations
80 while playing a recorded file.
815. Support decryption of scrambled transport packets.
826. Support recording of scrambled streams.
838. Section filtering.
84
85Control path
86------------
871. Client opens a demux device. Open request is done on the same demux
88 device for each filter.
892. Client may configure the demux's internal ring-buffer size used to
90 hold the data for user-space (or default is used).
913. Client configures the opened filter either to capture sections,
92 TS packets (for recording) or PES (decoder or non-decoder PES).
93 - The demux configures the underlying HW accordingly through
94 TSPP or TSIF kernel APIs
95 - demux receives notification of new data from the underlying HW and
96 performs demuxing operation based on the configuration.
974. Client can then read data received from the selected filter.
98
99Data path
100---------
101For each filter that is opened, demux manages a circular buffer that
102holds the captured filter data; Client read commands extract data from
103the relevant ring buffer. Data loss can occur if a client cannot keep up
104with stream bandwidth.
105
106For PES data tunneled to decoder, demux manages a stream-buffer used to
107transfer the PES data to the decoder. The stream-buffer is built from
108two ring-buffers: One holding the PES payload (elementary stream) and
109the other holding PES parameters extracted from the PES header. The
110ring-buffer with PES parameters points to the location of respective PES
111payload in the PES payload ring-buffer.
112
113To allow concurrency of multiple stream processing, multiple demux/dvr
114devices exist. Each demux devices handles a single stream input. The
115number of demux devices is configurable depending on the required number
116of concurrent stream processing.
117
118The client configures each demux device with the stream to process,
119by default, all devices are configured to process stream from memory.
120The default setting can be changed by issuing ioctl that configures
121the demux source to either TSIF0 or TSIF1. For specific TSIF input,
122only one demux device may process it at a time.
123
124Background Processing
125---------------------
Hamad Kadmany79de9e32012-11-27 17:51:01 +0200126Demux allocates a kernel thread for each live-input to process
127the TS packets notified from the HW for specific input. There
128are two such inputs (TSIF0 and TSIF1), both can be processed in
129parallel by two seperate threads.
Hamad Kadmanyd853d132012-05-30 13:13:46 +0300130
131The processing is the action of demuxing of the new data; it may sleep
132as it locks against the demux data-structure that may be accessed by
133user-space in the meanwhile.
134
Hamad Kadmanyd853d132012-05-30 13:13:46 +0300135Dependencies
136------------
137The demux driver depends on the following kernel drivers and subsystems:
1381. TSIF driver: Used to receive TS packets from TSIF interface for
139 targets supporting TSIF only.
1402. TSPP driver: Used to receive TS packets and/or PES from TSPP
141 interface for targets supporting TSPP.
1423. TZ-COM: Used to communicate with TrustZone to handle scrambled
143 streams.
1444. ION: Used to allocate memory for buffers holding decoder-data in
145 case the data is tunneled between demux and decoders.
146 Also used to allocate memory for TSPP/TSIF output pipes.
1475. dvb-core: Existing Linux infrastructure used for implementation of
148 dvb devices.
149
150Design
151======
152
153Goals
154-----
155The demux driver is designed to:
1561. Fulfil the requirements listed above.
1572. Be able to work on different chipsets having different HW
158 capabilities. For example, some chipsets are equipped with TSIF only,
159 others are equipped with TSPP of different versions.
160
161Design Blocks
162-------------
163Demux implementation hooks to the existing Linux dvb-core
164infrastructure as follows:
165
166 +----------+ +------------------------------------------+
167 | | | MPQ Demux Driver |
168 | | | +----------+ +----------+ +----------+ |
169 | | | | MPQ DMX | | MPQ DMX | | MPQ DMX | |
170 | QCOM MPQ | | | TSIF | | TSPPv1 | | TSPPv2 | |
171 | Adapter | | | Plugin | | Plugin | | Plugin | |
172 | | | +----------+ +----------+ +----------+ |
173 | | | +--------------------------------------+ |
174 | | | | MPQ Demux Common Services | |
175 | | | +--------------------------------------+ |
176 +----------+ +------------------------------------------+
177 +--------------------------------------------------------+
178 | Linux DVB Core |
179 | +----------+ +----------+ +----------+ |
180 | | DVB | | DVB DMX | | DVB | |
181 | | Demux | | Device | | Device | |
182 | +----------+ +----------+ +----------+ |
183 +--------------------------------------------------------+
184
185The new developed code is QCOM MPQ Adapter and the MPQ Demux driver
186with the various MPQ-DMX Plugins.
187
188QCOM MPQ Adapter registers a new DVB adapter to Linux dvb-core.
189The MPQ DVB adapter is built as a separate kernel module. Using it
190demux and video devices can register themselves to the adapter.
191
192MPQ-DMX plugins exist to hook to dvb-core demux implementation
193depending on the HW capabilities. Only one of these plugins might be
194compiled and run at a time on the target.
195As the name of each plugin implies, one plugin implements demux
196functionality for targets supporting TSIF only, and the others
197implement pluging for targets supporting TSPP in different versions.
198
199The plugin implementation is not hooked to specific chipset as
200different chipsets might have the same HW capability.
201
202The MPQ-DMX Plugin Common Services provides common services that are
203used by all plugins, such as registrations of demux devices to
204the dvb-core.
205
206The demux plugin is built as a separate kernel module. Each plugin
207hooks to the DVB-Demux by providing set of pointers to functions
208required for DVB-Demux and dvb-core operation. The actual
209implementation of these function differs between the plugins depending
210on the HW capabilities. The plugins may be viewed as "classes"
211inheriting from DVB-Demux "class".
212
213Interface to TSPP/TSIF Drivers
214------------------------------
215Each demux plugin interacts with the kernel API of the relevant driver
216(either TSIF or TSPP) to receive TS packets or other kinds of data
217depending on the HW capabilities.
218
219The demux uses the kernel API of TSIF and TSPP drivers and registers
220callback triggered when new data is received. The callback schedules
221work to a single-threaded workqueue to process the data. The actual
222processing of the data depends on the HW capabilities.
223
224Interface to TZ-COM Driver
225--------------------------
226For cases HW does not support descrambling, the descrambling is
227performed by communicating with TZ using TZ-COM kernel API.
228
229ION driver is used to allocate input and output buffers provided to TZ.
230
231Interface to Decoders
232---------------------
233The interface to the decoders is done through a stream-buffer interface.
234The design aims not to have direct calls between dvb/demux and
235dvb/video for de-coupling and generality. dvb/demux and dvb/video
236interact only with stream-buffer API.
237
238Stream buffer is built of two ring-buffers, one holding the PES payload
239(the video elementary stream) and the other holding parameters from PES
240headers required by decoders.
241
242The separation to two ring-buffers allows locking the payload buffer
243as secured buffer that only the decoder's HW may access while allowing
244the software to access the PES headers which are not required to be
245secured. Locking of the payload buffer is done when the data should be
246secured (scrambled video stream for example).
247
248The stream-buffer API make use of dvb-ring buffer implementation that
249is part of dvb-core.
250
251SMP/multi-core
252==============
253Driver is fully SMP aware.
254
255Interface
256=========
257
258User-space API
259--------------
260dvb/demux and dvb/dvr each expose a char device interface to user-space
261as defined by linuxtv.org. Extension to this interface is done to add
262new features required by MPQ use-cases. The extensions preserve backward
263compatibility of the API defined by linuxtv.org
264
265The devices appear in file-system under:
266/dev/dvb/adapter0/demuxN
267/dev/dvb/adapter0/dvrN
268
269Where "N" ranges between 0 to total number of demux devices defined.
270The default configuration is 4 devices.
271
272Extensions to this API (through new ioctl) exist to provide the
273following functionality:
274
2751. DMX_SET_TS_PACKET_FORMAT: Set the transport stream TS packet format.
276 Configures whether the stream fed to demux from memory is with TS packet
277 of 188 bytes long, 192 bytes long, etc.
278 Default is 188 bytes long to preserve backward compatibility.
279
280 Returns the following values:
281 0 in case of success.
282 -EINVAL if the parameter is invalid.
283 -EBUSY if demux is already running.
284
2852. DMX_SET_DECODER_BUFFER_SIZE: Set the decoder's buffer size.
286 For data tunneled to decoder, client can configure the size of the buffer
287 holding the PES payload.
288 Default is set to the fixed size value that exists in current dvb-core to
289 preserve backward compatibility.
290
291 Returns the following values:
292 0 in case of success.
293 -EINVAL if the parameter is invalid.
294 -EBUSY if demux is already running.
295
2963. DMX_SET_TS_OUT_FORMAT: Set the TS packet recording format.
297 Indicates whether the TS packet used for recording should be in 188 or 192
298 bytes long format. In case of 192-packets output, 4 bytes zero timestamp
299 is attached to the original 188 packet.
300 Default is set for 188 to preserve backward compatibility.
301
302 Returns the following values:
303 0 in case of success.
304 -EINVAL if the parameter is invalid.
305 -EBUSY if demux is already running.
306
3074. Added support for mmap for direct access to input/output buffers.
308 User can either use the original read/write syscalls or use mmap
309 on the specific file-handle. Several ioctls were exposed so that
310 user can find-out the status of the buffers (DMX_GET_BUFFER_STATUS),
311 to notify demux when data is consumed (DMX_RELEASE_DATA) or notify
312 dvr when data is fed (DMX_FEED_DATA).
313
3145. DMX_SET_PLAYBACK_MODE: Set playback mode in memory input.
315 In memory input, contrary to live input, playback can be in pull mode,
316 where if one of output buffers is full, demux stalls waiting for free space,
317 this would cause DVR input buffer fullness to accumulate.
318
319 Returns the following values:
320 0 in case of success.
321 -EINVAL if the parameter is invalid.
322 -EBUSY if demux is already running.
323
324debugfs
325-------
326debugfs is used for debug purposes.
327
328Directory in debugfs is created for each demux device.
329
330Each directory includes several performance counters of the specific demux:
331Total demuxing time, total CRC time, HW notification rate, HW notification
332buffer size.
333
334
335Exported Kernel API
336-------------------
337MPQ adapter exports the following kernel API:
3381. Getter API for the registered MPQ adapter handle.
339 This is used by demux plugin as well as dvb/video implementation to
340 register their devices to that adapter.
3412. Stream buffer API: Used to tunnel the data between dvb/demux and
342 decoders. The API is used by dvb/demux and by decoders to write/read
343 tunneled data.
3443. Stream buffer interface registration: Used to register stream-buffer
345 interfaces. When demux driver is asked to tunnel data to a decoder,
346 the demux allocates a stream-buffer to be shared between demux and
347 the decoder. For the decoder to retrieve the info of the
348 stream-buffer it should connect to, stream-buffer registration API
349 exist.
350 The demux registers the new allocated stream buffer handle to MPQ
351 Adapter, and the decoder may query the registered interface through
352 MPQ Adapter.
353
354Driver parameters
355=================
356There are three kernel modules required for DVB API operation:
3571. dvb-core.ko: This is an existing Linux module for dvb functionality.
358 The parameters for this module are the one defined by linuxtv.org.
359 An additional parameter was added to specify whether to collect
360 performance debug information exposed through debugfs.
361 Parameter name: dvb_demux_performancecheck
362
3632. mpq-adapter.ko: MPQ DVB adapter module. Has a parameter to
364 specify the adapter number, the number (X) is the same as the one
365 that appears in /dev/dvb/adapterX. Default is 0.
366 Parameter name: adapter_nr
367
3683. mpq-dmx-hw-plugin.ko: Module for demux HW plugin. Receives as a
369 parameter the number of required demux devices. Default is set to the
370 number specified in kernel configuration.
371 Parameter name: mpq_demux_device_num
372
373Config options
374==============
375New kernel configurations is available (through make menuconfig) to
376enable MPQ based adapter functionality. The following configurations
377exist:
3781. Control whether to enable QCOM MPQ DVB adapter (tri-state).
379 It depends on having dvb-core enabled.
3802. If MPQ adapter is enabled:
381 2.1. Control whether to enable MPQ dvb/demux (tri-state)
382 2.2. Control whether to enable MPQ dvb/video (tri-state)
383 2.3. If dvb/demux is enabled:
384 2.3.1. Configure the number of demux devices. Default is 4.
385 2.3.2. Select the desired demux plugin. Each plugin would appear
386 in the list of options depending whether the respective
387 driver (TSIF/TSPP) is enabled or not.
388
389Dependencies
390============
3911. The implementation depends on having dvb-core enabled.
3922. Each demux plugin depends on whether the relevant driver it uses
393 is enabled. TSIF plugin depends on TSIF driver and TSPP plugins
394 depend on TSPP driver.
3953. There's no communication to other processors.
396
397User space utilities
398====================
399N/A
400
401Other
402=====
403N/A
404
405Known issues
406============
407N/A