Hamad Kadmany | d853d13 | 2012-05-30 13:13:46 +0300 | [diff] [blame] | 1 | Introduction |
| 2 | ============ |
| 3 | MPQ DVB Adapter implements Digital Video Broadcasting devices according |
| 4 | to LinuxTV (linuxtv.org) defined API and infrastructure. |
| 5 | |
| 6 | The implemented devices are dvb/demux devices, dvb/dvr devices and |
| 7 | dvb/video devices. |
| 8 | |
| 9 | These devices are used in Qualcomm's MPQ chipsets that support |
| 10 | broadcast applications. |
| 11 | |
| 12 | dvb/demux is responsible to receive a digital stream broadcasted over |
| 13 | the air from a hardware unit (TSPP - Transport stream packet processor, |
| 14 | or TSIF - Transport Stream Interface) and separates the stream into its |
| 15 | various sub-streams such as video, audio and auxiliary data. |
| 16 | The separation operation is named demuxing. |
| 17 | |
| 18 | dvb/dvr is used in conjunction with dvb/demux to re-play a digital |
| 19 | stream from memory or to record stream to memory. |
| 20 | |
| 21 | dvb/video is used to handle the video decoding, it receives compressed |
| 22 | video from dvb/demux through a stream-buffer interface and interacts |
| 23 | with the existing HW video driver to perform the decoding. |
| 24 | |
| 25 | For more information on the TSIF interface, please refer to TSIF |
| 26 | documentation under "Documentation/arm/msm/tsif.txt". |
| 27 | For more information on the TSPP interface, please refer to TSPP |
| 28 | documentation under "Documentation/arm/msm/tspp.txt". |
| 29 | For more information on DVB-API definition, please refer dvb |
| 30 | documentation under "Documentation/dvb/readme.txt". |
| 31 | |
| 32 | Hardware description |
| 33 | ==================== |
| 34 | dvb/demux, dvb/dvr and dvb/video do not interact with a hardware directly; |
| 35 | The implementation of these drivers is done using the kernel API of TSPP, |
| 36 | TSIF and video drivers. |
| 37 | |
| 38 | Software description |
| 39 | ==================== |
| 40 | |
| 41 | Terminology |
| 42 | ----------- |
| 43 | Stream: A stream is a TS packet source |
| 44 | - For example, MPEG2 Transport Stream from TSIF0 |
| 45 | Filter: 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. |
| 51 | Service: 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 | |
| 56 | Requirments |
| 57 | ----------- |
| 58 | 1. Demuxing from different sources: |
| 59 | - Live transport stream inputs (TSIF) |
| 60 | - Memory inputs |
| 61 | 2. Support different packet formats: |
| 62 | - 188-bytes transport packets |
| 63 | - 192-bytes transport packets |
| 64 | 3. PID filtering |
| 65 | 4. 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. |
| 81 | 5. Support decryption of scrambled transport packets. |
| 82 | 6. Support recording of scrambled streams. |
| 83 | 8. Section filtering. |
| 84 | |
| 85 | Control path |
| 86 | ------------ |
| 87 | 1. Client opens a demux device. Open request is done on the same demux |
| 88 | device for each filter. |
| 89 | 2. Client may configure the demux's internal ring-buffer size used to |
| 90 | hold the data for user-space (or default is used). |
| 91 | 3. 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. |
| 97 | 4. Client can then read data received from the selected filter. |
| 98 | |
| 99 | Data path |
| 100 | --------- |
| 101 | For each filter that is opened, demux manages a circular buffer that |
| 102 | holds the captured filter data; Client read commands extract data from |
| 103 | the relevant ring buffer. Data loss can occur if a client cannot keep up |
| 104 | with stream bandwidth. |
| 105 | |
| 106 | For PES data tunneled to decoder, demux manages a stream-buffer used to |
| 107 | transfer the PES data to the decoder. The stream-buffer is built from |
| 108 | two ring-buffers: One holding the PES payload (elementary stream) and |
| 109 | the other holding PES parameters extracted from the PES header. The |
| 110 | ring-buffer with PES parameters points to the location of respective PES |
| 111 | payload in the PES payload ring-buffer. |
| 112 | |
| 113 | To allow concurrency of multiple stream processing, multiple demux/dvr |
| 114 | devices exist. Each demux devices handles a single stream input. The |
| 115 | number of demux devices is configurable depending on the required number |
| 116 | of concurrent stream processing. |
| 117 | |
| 118 | The client configures each demux device with the stream to process, |
| 119 | by default, all devices are configured to process stream from memory. |
| 120 | The default setting can be changed by issuing ioctl that configures |
| 121 | the demux source to either TSIF0 or TSIF1. For specific TSIF input, |
| 122 | only one demux device may process it at a time. |
| 123 | |
| 124 | Background Processing |
| 125 | --------------------- |
Hamad Kadmany | 79de9e3 | 2012-11-27 17:51:01 +0200 | [diff] [blame] | 126 | Demux allocates a kernel thread for each live-input to process |
| 127 | the TS packets notified from the HW for specific input. There |
| 128 | are two such inputs (TSIF0 and TSIF1), both can be processed in |
| 129 | parallel by two seperate threads. |
Hamad Kadmany | d853d13 | 2012-05-30 13:13:46 +0300 | [diff] [blame] | 130 | |
| 131 | The processing is the action of demuxing of the new data; it may sleep |
| 132 | as it locks against the demux data-structure that may be accessed by |
| 133 | user-space in the meanwhile. |
| 134 | |
Hamad Kadmany | d853d13 | 2012-05-30 13:13:46 +0300 | [diff] [blame] | 135 | Dependencies |
| 136 | ------------ |
| 137 | The demux driver depends on the following kernel drivers and subsystems: |
| 138 | 1. TSIF driver: Used to receive TS packets from TSIF interface for |
| 139 | targets supporting TSIF only. |
| 140 | 2. TSPP driver: Used to receive TS packets and/or PES from TSPP |
| 141 | interface for targets supporting TSPP. |
| 142 | 3. TZ-COM: Used to communicate with TrustZone to handle scrambled |
| 143 | streams. |
| 144 | 4. 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. |
| 147 | 5. dvb-core: Existing Linux infrastructure used for implementation of |
| 148 | dvb devices. |
| 149 | |
| 150 | Design |
| 151 | ====== |
| 152 | |
| 153 | Goals |
| 154 | ----- |
| 155 | The demux driver is designed to: |
| 156 | 1. Fulfil the requirements listed above. |
| 157 | 2. 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 | |
| 161 | Design Blocks |
| 162 | ------------- |
| 163 | Demux implementation hooks to the existing Linux dvb-core |
| 164 | infrastructure 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 | |
| 185 | The new developed code is QCOM MPQ Adapter and the MPQ Demux driver |
| 186 | with the various MPQ-DMX Plugins. |
| 187 | |
| 188 | QCOM MPQ Adapter registers a new DVB adapter to Linux dvb-core. |
| 189 | The MPQ DVB adapter is built as a separate kernel module. Using it |
| 190 | demux and video devices can register themselves to the adapter. |
| 191 | |
| 192 | MPQ-DMX plugins exist to hook to dvb-core demux implementation |
| 193 | depending on the HW capabilities. Only one of these plugins might be |
| 194 | compiled and run at a time on the target. |
| 195 | As the name of each plugin implies, one plugin implements demux |
| 196 | functionality for targets supporting TSIF only, and the others |
| 197 | implement pluging for targets supporting TSPP in different versions. |
| 198 | |
| 199 | The plugin implementation is not hooked to specific chipset as |
| 200 | different chipsets might have the same HW capability. |
| 201 | |
| 202 | The MPQ-DMX Plugin Common Services provides common services that are |
| 203 | used by all plugins, such as registrations of demux devices to |
| 204 | the dvb-core. |
| 205 | |
| 206 | The demux plugin is built as a separate kernel module. Each plugin |
| 207 | hooks to the DVB-Demux by providing set of pointers to functions |
| 208 | required for DVB-Demux and dvb-core operation. The actual |
| 209 | implementation of these function differs between the plugins depending |
| 210 | on the HW capabilities. The plugins may be viewed as "classes" |
| 211 | inheriting from DVB-Demux "class". |
| 212 | |
| 213 | Interface to TSPP/TSIF Drivers |
| 214 | ------------------------------ |
| 215 | Each 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 |
| 217 | depending on the HW capabilities. |
| 218 | |
| 219 | The demux uses the kernel API of TSIF and TSPP drivers and registers |
| 220 | callback triggered when new data is received. The callback schedules |
| 221 | work to a single-threaded workqueue to process the data. The actual |
| 222 | processing of the data depends on the HW capabilities. |
| 223 | |
| 224 | Interface to TZ-COM Driver |
| 225 | -------------------------- |
| 226 | For cases HW does not support descrambling, the descrambling is |
| 227 | performed by communicating with TZ using TZ-COM kernel API. |
| 228 | |
| 229 | ION driver is used to allocate input and output buffers provided to TZ. |
| 230 | |
| 231 | Interface to Decoders |
| 232 | --------------------- |
| 233 | The interface to the decoders is done through a stream-buffer interface. |
| 234 | The design aims not to have direct calls between dvb/demux and |
| 235 | dvb/video for de-coupling and generality. dvb/demux and dvb/video |
| 236 | interact only with stream-buffer API. |
| 237 | |
| 238 | Stream buffer is built of two ring-buffers, one holding the PES payload |
| 239 | (the video elementary stream) and the other holding parameters from PES |
| 240 | headers required by decoders. |
| 241 | |
| 242 | The separation to two ring-buffers allows locking the payload buffer |
| 243 | as secured buffer that only the decoder's HW may access while allowing |
| 244 | the software to access the PES headers which are not required to be |
| 245 | secured. Locking of the payload buffer is done when the data should be |
| 246 | secured (scrambled video stream for example). |
| 247 | |
| 248 | The stream-buffer API make use of dvb-ring buffer implementation that |
| 249 | is part of dvb-core. |
| 250 | |
| 251 | SMP/multi-core |
| 252 | ============== |
| 253 | Driver is fully SMP aware. |
| 254 | |
| 255 | Interface |
| 256 | ========= |
| 257 | |
| 258 | User-space API |
| 259 | -------------- |
| 260 | dvb/demux and dvb/dvr each expose a char device interface to user-space |
| 261 | as defined by linuxtv.org. Extension to this interface is done to add |
| 262 | new features required by MPQ use-cases. The extensions preserve backward |
| 263 | compatibility of the API defined by linuxtv.org |
| 264 | |
| 265 | The devices appear in file-system under: |
| 266 | /dev/dvb/adapter0/demuxN |
| 267 | /dev/dvb/adapter0/dvrN |
| 268 | |
| 269 | Where "N" ranges between 0 to total number of demux devices defined. |
| 270 | The default configuration is 4 devices. |
| 271 | |
| 272 | Extensions to this API (through new ioctl) exist to provide the |
| 273 | following functionality: |
| 274 | |
| 275 | 1. 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 | |
| 285 | 2. 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 | |
| 296 | 3. 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 | |
| 307 | 4. 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 | |
| 314 | 5. 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 | |
| 324 | debugfs |
| 325 | ------- |
| 326 | debugfs is used for debug purposes. |
| 327 | |
| 328 | Directory in debugfs is created for each demux device. |
| 329 | |
| 330 | Each directory includes several performance counters of the specific demux: |
| 331 | Total demuxing time, total CRC time, HW notification rate, HW notification |
| 332 | buffer size. |
| 333 | |
| 334 | |
| 335 | Exported Kernel API |
| 336 | ------------------- |
| 337 | MPQ adapter exports the following kernel API: |
| 338 | 1. 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. |
| 341 | 2. 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. |
| 344 | 3. 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 | |
| 354 | Driver parameters |
| 355 | ================= |
| 356 | There are three kernel modules required for DVB API operation: |
| 357 | 1. 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 | |
| 363 | 2. 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 | |
| 368 | 3. 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 | |
| 373 | Config options |
| 374 | ============== |
| 375 | New kernel configurations is available (through make menuconfig) to |
| 376 | enable MPQ based adapter functionality. The following configurations |
| 377 | exist: |
| 378 | 1. Control whether to enable QCOM MPQ DVB adapter (tri-state). |
| 379 | It depends on having dvb-core enabled. |
| 380 | 2. 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 | |
| 389 | Dependencies |
| 390 | ============ |
| 391 | 1. The implementation depends on having dvb-core enabled. |
| 392 | 2. 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. |
| 395 | 3. There's no communication to other processors. |
| 396 | |
| 397 | User space utilities |
| 398 | ==================== |
| 399 | N/A |
| 400 | |
| 401 | Other |
| 402 | ===== |
| 403 | N/A |
| 404 | |
| 405 | Known issues |
| 406 | ============ |
| 407 | N/A |