Peios Learn
Documentation

Peios

Peios Peios Kernel Universal Directory Project

Developer Tools

Trail Acta Provium clackatoo CAF GCSL Pekit

Applications

Framewright

Standards and Conventions

Standards and Conventions Peios Specifications
Peios Kernel

Media driver interfaces

Single-page view · as markdown

Media driver-specific documentation

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

Video4Linux (V4L) drivers #

  • The bttv driver
  • The cx2341x driver
  • The cx88 driver
  • The Samsung S5P/EXYNOS4 FIMC driver
  • The pvrusb2 driver
  • PXA-Camera Host Driver
  • The Radiotrack radio driver
  • The Rockchip Image Signal Processor Driver (rkisp1)
  • The saa7134 driver
  • Cropping and Scaling algorithm, used in the sh_mobile_ceu_camera driver
  • Tuner drivers
  • The Virtual Media Controller Driver (vimc)
  • The Zoran driver
  • MIPI CCS camera sensor driver
  • Intel IPU6 Driver

Digital TV drivers #

  • Idea behind the dvb-usb-framework
  • Frontend drivers
  • vidtv: Virtual Digital TV driver
  • Contributors

The bttv driver

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

bttv and sound mini howto #

There are a lot of different bt848/849/878/879 based boards available. Making video work often is not a big deal, because this is handled completely by the bt8xx chip, which is common on all boards. But sound is handled in slightly different ways on each board.

To handle the grabber boards correctly, there is a array tvcards[] in bttv-cards.c, which holds the information required for each board. Sound will work only, if the correct entry is used (for video it often makes no difference). The bttv driver prints a line to the kernel log, telling which card type is used. Like this one:

bttv0: model: BT848(Hauppauge old) [autodetected]

You should verify this is correct. If it isn't, you have to pass the correct board type as insmod argument, insmod bttv card=2 for example. The file Documentation/admin-guide/media/bttv-cardlist.rst has a list of valid arguments for card.

If your card isn't listed there, you might check the source code for new entries which are not listed yet. If there isn't one for your card, you can check if one of the existing entries does work for you (just trial and error...).

Some boards have an extra processor for sound to do stereo decoding and other nice features. The msp34xx chips are used by Hauppauge for example. If your board has one, you might have to load a helper module like msp3400 to make sound work. If there isn't one for the chip used on your board: Bad luck. Start writing a new one. Well, you might want to check the video4linux mailing list archive first...

Of course you need a correctly installed soundcard unless you have the speakers connected directly to the grabber board. Hint: check the mixer settings too. ALSA for example has everything muted by default.

How sound works in detail #

Still doesn't work? Looks like some driver hacking is required. Below is a do-it-yourself description for you.

The bt8xx chips have 32 general purpose pins, and registers to control these pins. One register is the output enable register (BT848_GPIO_OUT_EN), it says which pins are actively driven by the bt848 chip. Another one is the data register (BT848_GPIO_DATA), where you can get/set the status if these pins. They can be used for input and output.

Most grabber board vendors use these pins to control an external chip which does the sound routing. But every board is a little different. These pins are also used by some companies to drive remote control receiver chips. Some boards use the i2c bus instead of the gpio pins to connect the mux chip.

As mentioned above, there is a array which holds the required information for each known board. You basically have to create a new line for your board. The important fields are these two:

struct tvcard
{
      [ ... ]
      u32 gpiomask;
      u32 audiomux[6]; /* Tuner, Radio, external, internal, mute, stereo */
};

gpiomask specifies which pins are used to control the audio mux chip. The corresponding bits in the output enable register (BT848_GPIO_OUT_EN) will be set as these pins must be driven by the bt848 chip.

The audiomux[] array holds the data values for the different inputs (i.e. which pins must be high/low for tuner/mute/...). This will be written to the data register (BT848_GPIO_DATA) to switch the audio mux.

What you have to do is figure out the correct values for gpiomask and the audiomux array. If you have Windows and the drivers four your card installed, you might to check out if you can read these registers values used by the windows driver. A tool to do this is available from http://btwincap.sourceforge.net/download.html.

You might also dig around in the *.ini files of the Windows applications. You can have a look at the board to see which of the gpio pins are connected at all and then start trial-and-error ...

Starting with release 0.7.41 bttv has a number of insmod options to make the gpio debugging easier:

bttv_gpio=0/1

enable/disable gpio debug messages

gpiomask=n

set the gpiomask value

audiomux=i,j,...

set the values of the audiomux array

audioall=a

set the values of the audiomux array (one value for all array elements, useful to check out which effect the particular value has).

The messages printed with bttv_gpio=1 look like this:

bttv0: gpio: en=00000027, out=00000024 in=00ffffd8 [audio: off]

en  =   output _en_able register (BT848_GPIO_OUT_EN)
out =   _out_put bits of the data register (BT848_GPIO_DATA),
        i.e. BT848_GPIO_DATA & BT848_GPIO_OUT_EN
in  =   _in_put bits of the data register,
        i.e. BT848_GPIO_DATA & ~BT848_GPIO_OUT_EN

Contributors

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

Note

This documentation is outdated. There are several other DVB contributors that aren't listed below.

Thanks go to the following people for patches and contributions:

  • Michael Hunold <m.hunold@gmx.de>

    • for the initial saa7146 driver and its recent overhaul
  • Christian Theiss

    • for his work on the initial Linux DVB driver
  • Marcus Metzler <mocm@metzlerbros.de> and Ralph Metzler <rjkm@metzlerbros.de>

    • for their continuing work on the DVB driver
  • Michael Holzt <kju@debian.org>

    • for his contributions to the dvb-net driver
  • Diego Picciani <d.picciani@novacomp.it>

    • for CyberLogin for Linux which allows logging onto EON (in case you are wondering where CyberLogin is, EON changed its login procedure and CyberLogin is no longer used.)
  • Martin Schaller <martin@smurf.franken.de>

    • for patching the cable card decoder driver
  • Klaus Schmidinger <Klaus.Schmidinger@cadsoft.de>

    • for various fixes regarding tuning, OSD and CI stuff and his work on VDR
  • Steve Brown <sbrown@cortland.com>

    • for his AFC kernel thread
  • Christoph Martin <martin@uni-mainz.de>

    • for his LIRC infrared handler
  • Andreas Oberritter <obi@linuxtv.org>, Dennis Noermann <dennis.noermann@noernet.de>, Felix Domke <tmbinc@elitedvb.net>, Florian Schirmer <jolt@tuxbox.org>, Ronny Strutz <3des@elitedvb.de>, Wolfram Joost <dbox2@frokaschwei.de> and all the other dbox2 people

    • for many bugfixes in the generic DVB Core, frontend drivers and their work on the dbox2 port of the DVB driver
  • Oliver Endriss <o.endriss@gmx.de>

    • for many bugfixes
  • Andrew de Quincey <adq_dvb@lidskialf.net>

    • for the tda1004x frontend driver, and various bugfixes
  • Peter Schildmann <peter.schildmann@web.de>

    • for the driver for the Technisat SkyStar2 PCI DVB card
  • Vadim Catana <skystar@moldova.cc>, Roberto Ragusa <r.ragusa@libero.it> and Augusto Cardoso <augusto@carhil.net>

    • for all the work for the FlexCopII chipset by B2C2,Inc.
  • Davor Emard <emard@softhome.net>

    • for his work on the budget drivers, the demux code, the module unloading problems, ...
  • Hans-Frieder Vogt <hfvogt@arcor.de>

    • for his work on calculating and checking the crc's for the TechnoTrend/Hauppauge DEC driver firmware
  • Michael Dreher <michael@5dot1.de> and Andreas 'randy' Weinberger

    • for the support of the Fujitsu-Siemens Activy budget DVB-S
  • Kenneth Aafløy <ke-aa@frisurf.no>

    • for adding support for Typhoon DVB-S budget card
  • Ernst Peinlich <e.peinlich@inode.at>

    • for tuning/DiSEqC support for the DEC 3000-s
  • Peter Beutner <p.beutner@gmx.net>

    • for the IR code for the ttusb-dec driver
  • Wilson Michaels <wilsonmichaels@earthlink.net>

    • for the lgdt330x frontend driver, and various bugfixes
  • Michael Krufky <mkrufky@linuxtv.org>

    • for maintaining v4l/dvb inter-tree dependencies
  • Taylor Jacob <rtjacob@earthlink.net>

    • for the nxt2002 frontend driver
  • Jean-Francois Thibert <jeanfrancois@sagetv.com>

    • for the nxt2004 frontend driver
  • Kirk Lapray <kirk.lapray@gmail.com>

    • for the or51211 and or51132 frontend drivers, and for merging the nxt2002 and nxt2004 modules into a single nxt200x frontend driver.

(If you think you should be in this list, but you are not, drop a line to the DVB mailing list)

The cx2341x driver

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

Memory at cx2341x chips #

This section describes the cx2341x memory map and documents some of the register space.

Note

the memory long words are little-endian ('intel format').

Warning

This information was figured out from searching through the memory and registers, this information may not be correct and is certainly not complete, and was not derived from anything more than searching through the memory space with commands like:

ivtvctl -O min=0x02000000,max=0x020000ff

So take this as is, I'm always searching for more stuff, it's a large register space :-).

Memory Map #

The cx2341x exposes its entire 64M memory space to the PCI host via the PCI BAR0 (Base Address Register 0). The addresses here are offsets relative to the address held in BAR0.

0x00000000-0x00ffffff Encoder memory space
0x00000000-0x0003ffff Encode.rom
???-???         MPEG buffer(s)
???-???         Raw video capture buffer(s)
???-???         Raw audio capture buffer(s)
???-???         Display buffers (6 or 9)

0x01000000-0x01ffffff Decoder memory space
0x01000000-0x0103ffff Decode.rom
???-???         MPEG buffers(s)
0x0114b000-0x0115afff Audio.rom (deprecated?)

0x02000000-0x0200ffff Register Space

Registers #

The registers occupy the 64k space starting at the 0x02000000 offset from BAR0. All of these registers are 32 bits wide.

DMA Registers 0x000-0xff:

0x00 - Control:
        0=reset/cancel, 1=read, 2=write, 4=stop
0x04 - DMA status:
        1=read busy, 2=write busy, 4=read error, 8=write error, 16=link list error
0x08 - pci DMA pointer for read link list
0x0c - pci DMA pointer for write link list
0x10 - read/write DMA enable:
        1=read enable, 2=write enable
0x14 - always 0xffffffff, if set any lower instability occurs, 0x00 crashes
0x18 - ??
0x1c - always 0x20 or 32, smaller values slow down DMA transactions
0x20 - always value of 0x780a010a
0x24-0x3c - usually just random values???
0x40 - Interrupt status
0x44 - Write a bit here and shows up in Interrupt status 0x40
0x48 - Interrupt Mask
0x4C - always value of 0xfffdffff,
        if changed to 0xffffffff DMA write interrupts break.
0x50 - always 0xffffffff
0x54 - always 0xffffffff (0x4c, 0x50, 0x54 seem like interrupt masks, are
        3 processors on chip, Java ones, VPU, SPU, APU, maybe these are the
        interrupt masks???).
0x60-0x7C - random values
0x80 - first write linked list reg, for Encoder Memory addr
0x84 - first write linked list reg, for pci memory addr
0x88 - first write linked list reg, for length of buffer in memory addr
        (|0x80000000 or this for last link)
0x8c-0xdc - rest of write linked list reg, 8 sets of 3 total, DMA goes here
        from linked list addr in reg 0x0c, firmware must push through or
        something.
0xe0 - first (and only) read linked list reg, for pci memory addr
0xe4 - first (and only) read linked list reg, for Decoder memory addr
0xe8 - first (and only) read linked list reg, for length of buffer
0xec-0xff - Nothing seems to be in these registers, 0xec-f4 are 0x00000000.

Memory locations for Encoder Buffers 0x700-0x7ff:

These registers show offsets of memory locations pertaining to each buffer area used for encoding, have to shift them by <<1 first.

  • 0x07F8: Encoder SDRAM refresh

  • 0x07FC: Encoder SDRAM pre-charge

Memory locations for Decoder Buffers 0x800-0x8ff:

These registers show offsets of memory locations pertaining to each buffer area used for decoding, have to shift them by <<1 first.

  • 0x08F8: Decoder SDRAM refresh

  • 0x08FC: Decoder SDRAM pre-charge

Other memory locations:

  • 0x2800: Video Display Module control

  • 0x2D00: AO (audio output?) control

  • 0x2D24: Bytes Flushed

  • 0x7000: LSB I2C write clock bit (inverted)

  • 0x7004: LSB I2C write data bit (inverted)

  • 0x7008: LSB I2C read clock bit

  • 0x700c: LSB I2C read data bit

  • 0x9008: GPIO get input state

  • 0x900c: GPIO set output state

  • 0x9020: GPIO direction (Bit7 (GPIO 0..7) - 0:input, 1:output)

  • 0x9050: SPU control

  • 0x9054: Reset HW blocks

  • 0x9058: VPU control

  • 0xA018: Bit6: interrupt pending?

  • 0xA064: APU command

Interrupt Status Register #

The definition of the bits in the interrupt status register 0x0040, and the interrupt mask 0x0048. If a bit is cleared in the mask, then we want our ISR to execute.

  • bit 31 Encoder Start Capture

  • bit 30 Encoder EOS

  • bit 29 Encoder VBI capture

  • bit 28 Encoder Video Input Module reset event

  • bit 27 Encoder DMA complete

  • bit 24 Decoder audio mode change detection event (through event notification)

  • bit 22 Decoder data request

  • bit 20 Decoder DMA complete

  • bit 19 Decoder VBI re-insertion

  • bit 18 Decoder DMA err (linked-list bad)

Missing documentation #

  • Encoder API post(?)

  • Decoder API post(?)

  • Decoder VTRACE event

The cx2341x firmware upload #

This document describes how to upload the cx2341x firmware to the card.

How to find #

See the web pages of the various projects that uses this chip for information on how to obtain the firmware.

The firmware stored in a Windows driver can be detected as follows:

  • Each firmware image is 256k bytes.

  • The 1st 32-bit word of the Encoder image is 0x0000da7

  • The 1st 32-bit word of the Decoder image is 0x00003a7

  • The 2nd 32-bit word of both images is 0xaa55bb66

How to load #

  • Issue the FWapi command to stop the encoder if it is running. Wait for the command to complete.

  • Issue the FWapi command to stop the decoder if it is running. Wait for the command to complete.

  • Issue the I2C command to the digitizer to stop emitting VSYNC events.

  • Issue the FWapi command to halt the encoder's firmware.

  • Sleep for 10ms.

  • Issue the FWapi command to halt the decoder's firmware.

  • Sleep for 10ms.

  • Write 0x00000000 to register 0x2800 to stop the Video Display Module.

  • Write 0x00000005 to register 0x2D00 to stop the AO (audio output?).

  • Write 0x00000000 to register 0xA064 to ping? the APU.

  • Write 0xFFFFFFFE to register 0x9058 to stop the VPU.

  • Write 0xFFFFFFFF to register 0x9054 to reset the HW blocks.

  • Write 0x00000001 to register 0x9050 to stop the SPU.

  • Sleep for 10ms.

  • Write 0x0000001A to register 0x07FC to init the Encoder SDRAM's pre-charge.

  • Write 0x80000640 to register 0x07F8 to init the Encoder SDRAM's refresh to 1us.

  • Write 0x0000001A to register 0x08FC to init the Decoder SDRAM's pre-charge.

  • Write 0x80000640 to register 0x08F8 to init the Decoder SDRAM's refresh to 1us.

  • Sleep for 512ms. (600ms is recommended)

  • Transfer the encoder's firmware image to offset 0 in Encoder memory space.

  • Transfer the decoder's firmware image to offset 0 in Decoder memory space.

  • Use a read-modify-write operation to Clear bit 0 of register 0x9050 to re-enable the SPU.

  • Sleep for 1 second.

  • Use a read-modify-write operation to Clear bits 3 and 0 of register 0x9058 to re-enable the VPU.

  • Sleep for 1 second.

  • Issue status API commands to both firmware images to verify.

How to call the firmware API #

The preferred calling convention is known as the firmware mailbox. The mailboxes are basically a fixed length array that serves as the call-stack.

Firmware mailboxes can be located by searching the encoder and decoder memory for a 16 byte signature. That signature will be located on a 256-byte boundary.

Signature:

0x78, 0x56, 0x34, 0x12, 0x12, 0x78, 0x56, 0x34,
0x34, 0x12, 0x78, 0x56, 0x56, 0x34, 0x12, 0x78

The firmware implements 20 mailboxes of 20 32-bit words. The first 10 are reserved for API calls. The second 10 are used by the firmware for event notification.

Index

Name

0

Flags

1

Command

2

Return value

3

Timeout

4-19

Parameter/Result

The flags are defined in the following table. The direction is from the perspective of the firmware.

Bit

Direction

Purpose

2

O

Firmware has processed the command.

1

I

Driver has finished setting the parameters.

0

I

Driver is using this mailbox.

The command is a 32-bit enumerator. The API specifics may be found in this chapter.

The return value is a 32-bit enumerator. Only two values are currently defined:

  • 0=success

  • -1=command undefined.

There are 16 parameters/results 32-bit fields. The driver populates these fields with values for all the parameters required by the call. The driver overwrites these fields with result values returned by the call.

The timeout value protects the card from a hung driver thread. If the driver doesn't handle the completed call within the timeout specified, the firmware will reset that mailbox.

To make an API call, the driver iterates over each mailbox looking for the first one available (bit 0 has been cleared). The driver sets that bit, fills in the command enumerator, the timeout value and any required parameters. The driver then sets the parameter ready bit (bit 1). The firmware scans the mailboxes for pending commands, processes them, sets the result code, populates the result value array with that call's return values and sets the call complete bit (bit 2). Once bit 2 is set, the driver should retrieve the results and clear all the flags. If the driver does not perform this task within the time set in the timeout register, the firmware will reset that mailbox.

Event notifications are sent from the firmware to the host. The host tells the firmware which events it is interested in via an API call. That call tells the firmware which notification mailbox to use. The firmware signals the host via an interrupt. Only the 16 Results fields are used, the Flags, Command, Return value and Timeout words are not used.

OSD firmware API description #

Note

this API is part of the decoder firmware, so it's cx23415 only.

CX2341X_OSD_GET_FRAMEBUFFER #

Enum: 65/0x41

Description #

Return base and length of contiguous OSD memory.

Result[0] #

OSD base address

Result[1] #

OSD length

CX2341X_OSD_GET_PIXEL_FORMAT #

Enum: 66/0x42

Description #

Query OSD format

Result[0] #

0=8bit index 1=16bit RGB 5:6:5 2=16bit ARGB 1:5:5:5 3=16bit ARGB 1:4:4:4 4=32bit ARGB 8:8:8:8

CX2341X_OSD_SET_PIXEL_FORMAT #

Enum: 67/0x43

Description #

Assign pixel format

Param[0] #

  • 0=8bit index

  • 1=16bit RGB 5:6:5

  • 2=16bit ARGB 1:5:5:5

  • 3=16bit ARGB 1:4:4:4

  • 4=32bit ARGB 8:8:8:8

CX2341X_OSD_GET_STATE #

Enum: 68/0x44

Description #

Query OSD state

Result[0] #

  • Bit 0 0=off, 1=on

  • Bits 1:2 alpha control

  • Bits 3:5 pixel format

CX2341X_OSD_SET_STATE #

Enum: 69/0x45

Description #

OSD switch

Param[0] #

0=off, 1=on

CX2341X_OSD_GET_OSD_COORDS #

Enum: 70/0x46

Description #

Retrieve coordinates of OSD area blended with video

Result[0] #

OSD buffer address

Result[1] #

Stride in pixels

Result[2] #

Lines in OSD buffer

Result[3] #

Horizontal offset in buffer

Result[4] #

Vertical offset in buffer

CX2341X_OSD_SET_OSD_COORDS #

Enum: 71/0x47

Description #

Assign the coordinates of the OSD area to blend with video

Param[0] #

buffer address

Param[1] #

buffer stride in pixels

Param[2] #

lines in buffer

Param[3] #

horizontal offset

Param[4] #

vertical offset

CX2341X_OSD_GET_SCREEN_COORDS #

Enum: 72/0x48

Description #

Retrieve OSD screen area coordinates

Result[0] #

top left horizontal offset

Result[1] #

top left vertical offset

Result[2] #

bottom right horizontal offset

Result[3] #

bottom right vertical offset

CX2341X_OSD_SET_SCREEN_COORDS #

Enum: 73/0x49

Description #

Assign the coordinates of the screen area to blend with video

Param[0] #

top left horizontal offset

Param[1] #

top left vertical offset

Param[2] #

bottom left horizontal offset

Param[3] #

bottom left vertical offset

CX2341X_OSD_GET_GLOBAL_ALPHA #

Enum: 74/0x4A

Description #

Retrieve OSD global alpha

Result[0] #

global alpha: 0=off, 1=on

Result[1] #

bits 0:7 global alpha

CX2341X_OSD_SET_GLOBAL_ALPHA #

Enum: 75/0x4B

Description #

Update global alpha

Param[0] #

global alpha: 0=off, 1=on

Param[1] #

global alpha (8 bits)

Param[2] #

local alpha: 0=on, 1=off

CX2341X_OSD_SET_BLEND_COORDS #

Enum: 78/0x4C

Description #

Move start of blending area within display buffer

Param[0] #

horizontal offset in buffer

Param[1] #

vertical offset in buffer

CX2341X_OSD_GET_FLICKER_STATE #

Enum: 79/0x4F

Description #

Retrieve flicker reduction module state

Result[0] #

flicker state: 0=off, 1=on

CX2341X_OSD_SET_FLICKER_STATE #

Enum: 80/0x50

Description #

Set flicker reduction module state

Param[0] #

State: 0=off, 1=on

CX2341X_OSD_BLT_COPY #

Enum: 82/0x52

Description #

BLT copy

Param[0] #

'0000'  zero
'0001' ~destination AND ~source
'0010' ~destination AND  source
'0011' ~destination
'0100'  destination AND ~source
'0101'                  ~source
'0110'  destination XOR  source
'0111' ~destination OR  ~source
'1000' ~destination AND ~source
'1001'  destination XNOR source
'1010'                   source
'1011' ~destination OR   source
'1100'  destination
'1101'  destination OR  ~source
'1110'  destination OR   source
'1111'  one

Param[1] #

Resulting alpha blending

  • '01' source_alpha

  • '10' destination_alpha

  • '11' source_alpha*destination_alpha+1 (zero if both source and destination alpha are zero)

Param[2] #

'00' output_pixel = source_pixel

'01' if source_alpha=0:
         output_pixel = destination_pixel
     if 256 > source_alpha > 1:
         output_pixel = ((source_alpha + 1)*source_pixel +
                         (255 - source_alpha)*destination_pixel)/256

'10' if destination_alpha=0:
         output_pixel = source_pixel
      if 255 > destination_alpha > 0:
         output_pixel = ((255 - destination_alpha)*source_pixel +
                         (destination_alpha + 1)*destination_pixel)/256

'11' if source_alpha=0:
         source_temp = 0
     if source_alpha=255:
         source_temp = source_pixel*256
     if 255 > source_alpha > 0:
         source_temp = source_pixel*(source_alpha + 1)
     if destination_alpha=0:
         destination_temp = 0
     if destination_alpha=255:
         destination_temp = destination_pixel*256
     if 255 > destination_alpha > 0:
         destination_temp = destination_pixel*(destination_alpha + 1)
     output_pixel = (source_temp + destination_temp)/256

Param[3] #

width

Param[4] #

height

Param[5] #

destination pixel mask

Param[6] #

destination rectangle start address

Param[7] #

destination stride in dwords

Param[8] #

source stride in dwords

Param[9] #

source rectangle start address

CX2341X_OSD_BLT_FILL #

Enum: 83/0x53

Description #

BLT fill color

Param[0] #

Same as Param[0] on API 0x52

Param[1] #

Same as Param[1] on API 0x52

Param[2] #

Same as Param[2] on API 0x52

Param[3] #

width

Param[4] #

height

Param[5] #

destination pixel mask

Param[6] #

destination rectangle start address

Param[7] #

destination stride in dwords

Param[8] #

color fill value

CX2341X_OSD_BLT_TEXT #

Enum: 84/0x54

Description #

BLT for 8 bit alpha text source

Param[0] #

Same as Param[0] on API 0x52

Param[1] #

Same as Param[1] on API 0x52

Param[2] #

Same as Param[2] on API 0x52

Param[3] #

width

Param[4] #

height

Param[5] #

destination pixel mask

Param[6] #

destination rectangle start address

Param[7] #

destination stride in dwords

Param[8] #

source stride in dwords

Param[9] #

source rectangle start address

Param[10] #

color fill value

CX2341X_OSD_SET_FRAMEBUFFER_WINDOW #

Enum: 86/0x56

Description #

Positions the main output window on the screen. The coordinates must be such that the entire window fits on the screen.

Param[0] #

window width

Param[1] #

window height

Param[2] #

top left window corner horizontal offset

Param[3] #

top left window corner vertical offset

CX2341X_OSD_SET_CHROMA_KEY #

Enum: 96/0x60

Description #

Chroma key switch and color

Param[0] #

state: 0=off, 1=on

Param[1] #

color

CX2341X_OSD_GET_ALPHA_CONTENT_INDEX #

Enum: 97/0x61

Description #

Retrieve alpha content index

Result[0] #

alpha content index, Range 0:15

CX2341X_OSD_SET_ALPHA_CONTENT_INDEX #

Enum: 98/0x62

Description #

Assign alpha content index

Param[0] #

alpha content index, range 0:15

Encoder firmware API description #

CX2341X_ENC_PING_FW #

Enum: 128/0x80

Description #

Does nothing. Can be used to check if the firmware is responding.

CX2341X_ENC_START_CAPTURE #

Enum: 129/0x81

Description #

Commences the capture of video, audio and/or VBI data. All encoding parameters must be initialized prior to this API call. Captures frames continuously or until a predefined number of frames have been captured.

Param[0] #

Capture stream type:

  • 0=MPEG

  • 1=Raw

  • 2=Raw passthrough

  • 3=VBI

Param[1] #

Bitmask:

  • Bit 0 when set, captures YUV

  • Bit 1 when set, captures PCM audio

  • Bit 2 when set, captures VBI (same as param[0]=3)

  • Bit 3 when set, the capture destination is the decoder (same as param[0]=2)

  • Bit 4 when set, the capture destination is the host

Note

this parameter is only meaningful for RAW capture type.

CX2341X_ENC_STOP_CAPTURE #

Enum: 130/0x82

Description #

Ends a capture in progress

Param[0] #

  • 0=stop at end of GOP (generates IRQ)

  • 1=stop immediate (no IRQ)

Param[1] #

Stream type to stop, see param[0] of API 0x81

Param[2] #

Subtype, see param[1] of API 0x81

CX2341X_ENC_SET_AUDIO_ID #

Enum: 137/0x89

Description #

Assigns the transport stream ID of the encoded audio stream

Param[0] #

Audio Stream ID

CX2341X_ENC_SET_VIDEO_ID #

Enum: 139/0x8B

Description #

Set video transport stream ID

Param[0] #

Video stream ID

CX2341X_ENC_SET_PCR_ID #

Enum: 141/0x8D

Description #

Assigns the transport stream ID for PCR packets

Param[0] #

PCR Stream ID

CX2341X_ENC_SET_FRAME_RATE #

Enum: 143/0x8F

Description #

Set video frames per second. Change occurs at start of new GOP.

Param[0] #

  • 0=30fps

  • 1=25fps

CX2341X_ENC_SET_FRAME_SIZE #

Enum: 145/0x91

Description #

Select video stream encoding resolution.

Param[0] #

Height in lines. Default 480

Param[1] #

Width in pixels. Default 720

CX2341X_ENC_SET_BIT_RATE #

Enum: 149/0x95

Description #

Assign average video stream bitrate.

Param[0] #

0=variable bitrate, 1=constant bitrate

Param[1] #

bitrate in bits per second

Param[2] #

peak bitrate in bits per second, divided by 400

Param[3] #

Mux bitrate in bits per second, divided by 400. May be 0 (default).

Param[4] #

Rate Control VBR Padding

Param[5] #

VBV Buffer used by encoder

Note

  1. Param[3] and Param[4] seem to be always 0

  2. Param[5] doesn't seem to be used.

CX2341X_ENC_SET_GOP_PROPERTIES #

Enum: 151/0x97

Description #

Setup the GOP structure

Param[0] #

GOP size (maximum is 34)

Param[1] #

Number of B frames between the I and P frame, plus 1. For example: IBBPBBPBBPBB --> GOP size: 12, number of B frames: 2+1 = 3

Note

GOP size must be a multiple of (B-frames + 1).

CX2341X_ENC_SET_ASPECT_RATIO #

Enum: 153/0x99

Description #

Sets the encoding aspect ratio. Changes in the aspect ratio take effect at the start of the next GOP.

Param[0] #

  • '0000' forbidden

  • '0001' 1:1 square

  • '0010' 4:3

  • '0011' 16:9

  • '0100' 2.21:1

  • '0101' to '1111' reserved

CX2341X_ENC_SET_DNR_FILTER_MODE #

Enum: 155/0x9B

Description #

Assign Dynamic Noise Reduction operating mode

Param[0] #

Bit0: Spatial filter, set=auto, clear=manual Bit1: Temporal filter, set=auto, clear=manual

Param[1] #

Median filter:

  • 0=Disabled

  • 1=Horizontal

  • 2=Vertical

  • 3=Horiz/Vert

  • 4=Diagonal

CX2341X_ENC_SET_DNR_FILTER_PROPS #

Enum: 157/0x9D

Description #

These Dynamic Noise Reduction filter values are only meaningful when the respective filter is set to "manual" (See API 0x9B)

Param[0] #

Spatial filter: default 0, range 0:15

Param[1] #

Temporal filter: default 0, range 0:31

CX2341X_ENC_SET_CORING_LEVELS #

Enum: 159/0x9F

Description #

Assign Dynamic Noise Reduction median filter properties.

Param[0] #

Threshold above which the luminance median filter is enabled. Default: 0, range 0:255

Param[1] #

Threshold below which the luminance median filter is enabled. Default: 255, range 0:255

Param[2] #

Threshold above which the chrominance median filter is enabled. Default: 0, range 0:255

Param[3] #

Threshold below which the chrominance median filter is enabled. Default: 255, range 0:255

CX2341X_ENC_SET_SPATIAL_FILTER_TYPE #

Enum: 161/0xA1

Description #

Assign spatial prefilter parameters

Param[0] #

Luminance filter

  • 0=Off

  • 1=1D Horizontal

  • 2=1D Vertical

  • 3=2D H/V Separable (default)

  • 4=2D Symmetric non-separable

Param[1] #

Chrominance filter

  • 0=Off

  • 1=1D Horizontal (default)

CX2341X_ENC_SET_VBI_LINE #

Enum: 183/0xB7

Description #

Selects VBI line number.

Param[0] #

  • Bits 0:4 line number

  • Bit 31 0=top_field, 1=bottom_field

  • Bits 0:31 all set specifies "all lines"

Param[1] #

VBI line information features: 0=disabled, 1=enabled

Param[2] #

Slicing: 0=None, 1=Closed Caption Almost certainly not implemented. Set to 0.

Param[3] #

Luminance samples in this line. Almost certainly not implemented. Set to 0.

Param[4] #

Chrominance samples in this line Almost certainly not implemented. Set to 0.

CX2341X_ENC_SET_STREAM_TYPE #

Enum: 185/0xB9

Description #

Assign stream type

Note

Transport stream is not working in recent firmwares. And in older firmwares the timestamps in the TS seem to be unreliable.

Param[0] #

  • 0=Program stream

  • 1=Transport stream

  • 2=MPEG1 stream

  • 3=PES A/V stream

  • 5=PES Video stream

  • 7=PES Audio stream

  • 10=DVD stream

  • 11=VCD stream

  • 12=SVCD stream

  • 13=DVD_S1 stream

  • 14=DVD_S2 stream

CX2341X_ENC_SET_OUTPUT_PORT #

Enum: 187/0xBB

Description #

Assign stream output port. Normally 0 when the data is copied through the PCI bus (DMA), and 1 when the data is streamed to another chip (pvrusb and cx88-blackbird).

Param[0] #

  • 0=Memory (default)

  • 1=Streaming

  • 2=Serial

Param[1] #

Unknown, but leaving this to 0 seems to work best. Indications are that this might have to do with USB support, although passing anything but 0 only breaks things.

CX2341X_ENC_SET_AUDIO_PROPERTIES #

Enum: 189/0xBD

Description #

Set audio stream properties, may be called while encoding is in progress.

Note

All bitfields are consistent with ISO11172 documentation except bits 2:3 which ISO docs define as:

  • '11' Layer I

  • '10' Layer II

  • '01' Layer III

  • '00' Undefined

This discrepancy may indicate a possible error in the documentation. Testing indicated that only Layer II is actually working, and that the minimum bitrate should be 192 kbps.

Param[0] #

Bitmask:

 0:1  '00' 44.1Khz
      '01' 48Khz
      '10' 32Khz
      '11' reserved

 2:3  '01'=Layer I
      '10'=Layer II

 4:7  Bitrate:
           Index | Layer I     | Layer II
           ------+-------------+------------
          '0000' | free format | free format
          '0001' |  32 kbit/s  |  32 kbit/s
          '0010' |  64 kbit/s  |  48 kbit/s
          '0011' |  96 kbit/s  |  56 kbit/s
          '0100' | 128 kbit/s  |  64 kbit/s
          '0101' | 160 kbit/s  |  80 kbit/s
          '0110' | 192 kbit/s  |  96 kbit/s
          '0111' | 224 kbit/s  | 112 kbit/s
          '1000' | 256 kbit/s  | 128 kbit/s
          '1001' | 288 kbit/s  | 160 kbit/s
          '1010' | 320 kbit/s  | 192 kbit/s
          '1011' | 352 kbit/s  | 224 kbit/s
          '1100' | 384 kbit/s  | 256 kbit/s
          '1101' | 416 kbit/s  | 320 kbit/s
          '1110' | 448 kbit/s  | 384 kbit/s

      .. note::

              For Layer II, not all combinations of total bitrate
              and mode are allowed. See ISO11172-3 3-Annex B,
              Table 3-B.2

 8:9  '00'=Stereo
      '01'=JointStereo
      '10'=Dual
      '11'=Mono

      .. note::

              The cx23415 cannot decode Joint Stereo properly.

10:11 Mode Extension used in joint_stereo mode.
      In Layer I and II they indicate which subbands are in
      intensity_stereo. All other subbands are coded in stereo.
          '00' subbands 4-31 in intensity_stereo, bound==4
          '01' subbands 8-31 in intensity_stereo, bound==8
          '10' subbands 12-31 in intensity_stereo, bound==12
          '11' subbands 16-31 in intensity_stereo, bound==16

12:13 Emphasis:
          '00' None
          '01' 50/15uS
          '10' reserved
          '11' CCITT J.17

14    CRC:
          '0' off
          '1' on

15    Copyright:
          '0' off
          '1' on

16    Generation:
          '0' copy
          '1' original

CX2341X_ENC_HALT_FW #

Enum: 195/0xC3

Description #

The firmware is halted and no further API calls are serviced until the firmware is uploaded again.

CX2341X_ENC_GET_VERSION #

Enum: 196/0xC4

Description #

Returns the version of the encoder firmware.

Result[0] #

Version bitmask: - Bits 0:15 build - Bits 16:23 minor - Bits 24:31 major

CX2341X_ENC_SET_GOP_CLOSURE #

Enum: 197/0xC5

Description #

Assigns the GOP open/close property.

Param[0] #

  • 0=Open

  • 1=Closed

CX2341X_ENC_GET_SEQ_END #

Enum: 198/0xC6

Description #

Obtains the sequence end code of the encoder's buffer. When a capture is started a number of interrupts are still generated, the last of which will have Result[0] set to 1 and Result[1] will contain the size of the buffer.

Result[0] #

State of the transfer (1 if last buffer)

Result[1] #

If Result[0] is 1, this contains the size of the last buffer, undefined otherwise.

CX2341X_ENC_SET_PGM_INDEX_INFO #

Enum: 199/0xC7

Description #

Sets the Program Index Information. The information is stored as follows:

struct info {
        u32 length;             // Length of this frame
        u32 offset_low;         // Offset in the file of the
        u32 offset_high;        // start of this frame
        u32 mask1;              // Bits 0-2 are the type mask:
                                // 1=I, 2=P, 4=B
                                // 0=End of Program Index, other fields
                                //   are invalid.
        u32 pts;                // The PTS of the frame
        u32 mask2;              // Bit 0 is bit 32 of the pts.
};
u32 table_ptr;
struct info index[400];

The table_ptr is the encoder memory address in the table were new entries will be written.

Note

This is a ringbuffer, so the table_ptr will wraparound.

Param[0] #

Picture Mask: - 0=No index capture - 1=I frames - 3=I,P frames - 7=I,P,B frames

(Seems to be ignored, it always indexes I, P and B frames)

Param[1] #

Elements requested (up to 400)

Result[0] #

Offset in the encoder memory of the start of the table.

Result[1] #

Number of allocated elements up to a maximum of Param[1]

CX2341X_ENC_SET_VBI_CONFIG #

Enum: 200/0xC8

Description #

Configure VBI settings

Param[0] #

Bitmap:

0    Mode '0' Sliced, '1' Raw
1:3  Insertion:
         '000' insert in extension & user data
         '001' insert in private packets
         '010' separate stream and user data
         '111' separate stream and private data
8:15 Stream ID (normally 0xBD)

Param[1] #

Frames per interrupt (max 8). Only valid in raw mode.

Param[2] #

Total raw VBI frames. Only valid in raw mode.

Param[3] #

Start codes

Param[4] #

Stop codes

Param[5] #

Lines per frame

Param[6] #

Byte per line

Result[0] #

Observed frames per interrupt in raw mode only. Rage 1 to Param[1]

Result[1] #

Observed number of frames in raw mode. Range 1 to Param[2]

Result[2] #

Memory offset to start or raw VBI data

CX2341X_ENC_SET_DMA_BLOCK_SIZE #

Enum: 201/0xC9

Description #

Set DMA transfer block size

Param[0] #

DMA transfer block size in bytes or frames. When unit is bytes, supported block sizes are 2^7, 2^8 and 2^9 bytes.

Param[1] #

Unit: 0=bytes, 1=frames

CX2341X_ENC_GET_PREV_DMA_INFO_MB_10 #

Enum: 202/0xCA

Description #

Returns information on the previous DMA transfer in conjunction with bit 27 of the interrupt mask. Uses mailbox 10.

Result[0] #

Type of stream

Result[1] #

Address Offset

Result[2] #

Maximum size of transfer

CX2341X_ENC_GET_PREV_DMA_INFO_MB_9 #

Enum: 203/0xCB

Description #

Returns information on the previous DMA transfer in conjunction with bit 27 or 18 of the interrupt mask. Uses mailbox 9.

Result[0] #

Status bits: - 0 read completed - 1 write completed - 2 DMA read error - 3 DMA write error - 4 Scatter-Gather array error

Result[1] #

DMA type

Result[2] #

Presentation Time Stamp bits 0..31

Result[3] #

Presentation Time Stamp bit 32

CX2341X_ENC_SCHED_DMA_TO_HOST #

Enum: 204/0xCC

Description #

Setup DMA to host operation

Param[0] #

Memory address of link list

Param[1] #

Length of link list (wtf: what units ???)

Param[2] #

DMA type (0=MPEG)

CX2341X_ENC_INITIALIZE_INPUT #

Enum: 205/0xCD

Description #

Initializes the video input

CX2341X_ENC_SET_FRAME_DROP_RATE #

Enum: 208/0xD0

Description #

For each frame captured, skip specified number of frames.

Param[0] #

Number of frames to skip

CX2341X_ENC_PAUSE_ENCODER #

Enum: 210/0xD2

Description #

During a pause condition, all frames are dropped instead of being encoded.

Param[0] #

  • 0=Pause encoding

  • 1=Continue encoding

CX2341X_ENC_REFRESH_INPUT #

Enum: 211/0xD3

Description #

Refreshes the video input

CX2341X_ENC_SET_COPYRIGHT #

Enum: 212/0xD4

Description #

Sets stream copyright property

Param[0] #

  • 0=Stream is not copyrighted

  • 1=Stream is copyrighted

CX2341X_ENC_SET_EVENT_NOTIFICATION #

Enum: 213/0xD5

Description #

Setup firmware to notify the host about a particular event. Host must unmask the interrupt bit.

Param[0] #

Event (0=refresh encoder input)

Param[1] #

Notification 0=disabled 1=enabled

Param[2] #

Interrupt bit

Param[3] #

Mailbox slot, -1 if no mailbox required.

CX2341X_ENC_SET_NUM_VSYNC_LINES #

Enum: 214/0xD6

Description #

Depending on the analog video decoder used, this assigns the number of lines for field 1 and 2.

Param[0] #

Field 1 number of lines: - 0x00EF for SAA7114 - 0x00F0 for SAA7115 - 0x0105 for Micronas

Param[1] #

Field 2 number of lines: - 0x00EF for SAA7114 - 0x00F0 for SAA7115 - 0x0106 for Micronas

CX2341X_ENC_SET_PLACEHOLDER #

Enum: 215/0xD7

Description #

Provides a mechanism of inserting custom user data in the MPEG stream.

Param[0] #

  • 0=extension & user data

  • 1=private packet with stream ID 0xBD

Param[1] #

Rate at which to insert data, in units of frames (for private packet) or GOPs (for ext. & user data)

Param[2] #

Number of data DWORDs (below) to insert

Param[3] #

Custom data 0

Param[4] #

Custom data 1

Param[5] #

Custom data 2

Param[6] #

Custom data 3

Param[7] #

Custom data 4

Param[8] #

Custom data 5

Param[9] #

Custom data 6

Param[10] #

Custom data 7

Param[11] #

Custom data 8

CX2341X_ENC_MUTE_VIDEO #

Enum: 217/0xD9

Description #

Video muting

Param[0] #

Bit usage:

 0      '0'=video not muted
        '1'=video muted, creates frames with the YUV color defined below
 1:7    Unused
 8:15   V chrominance information
16:23   U chrominance information
24:31   Y luminance information

CX2341X_ENC_MUTE_AUDIO #

Enum: 218/0xDA

Description #

Audio muting

Param[0] #

  • 0=audio not muted

  • 1=audio muted (produces silent mpeg audio stream)

CX2341X_ENC_SET_VERT_CROP_LINE #

Enum: 219/0xDB

Description #

Something to do with 'Vertical Crop Line'

Param[0] #

If saa7114 and raw VBI capture and 60 Hz, then set to 10001. Else 0.

CX2341X_ENC_MISC #

Enum: 220/0xDC

Description #

Miscellaneous actions. Not known for 100% what it does. It's really a sort of ioctl call. The first parameter is a command number, the second the value.

Param[0] #

Command number:

 1=set initial SCR value when starting encoding (works).
 2=set quality mode (apparently some test setting).
 3=setup advanced VIM protection handling.
   Always 1 for the cx23416 and 0 for cx23415.
 4=generate DVD compatible PTS timestamps
 5=USB flush mode
 6=something to do with the quantization matrix
 7=set navigation pack insertion for DVD: adds 0xbf (private stream 2)
   packets to the MPEG. The size of these packets is 2048 bytes (including
   the header of 6 bytes: 0x000001bf + length). The payload is zeroed and
   it is up to the application to fill them in. These packets are apparently
   inserted every four frames.
 8=enable scene change detection (seems to be a failure)
 9=set history parameters of the video input module
10=set input field order of VIM
11=set quantization matrix
12=reset audio interface after channel change or input switch (has no argument).
   Needed for the cx2584x, not needed for the mspx4xx, but it doesn't seem to
   do any harm calling it regardless.
13=set audio volume delay
14=set audio delay

Param[1] #

Command value.

Decoder firmware API description #

Note

this API is part of the decoder firmware, so it's cx23415 only.

CX2341X_DEC_PING_FW #

Enum: 0/0x00

Description #

This API call does nothing. It may be used to check if the firmware is responding.

CX2341X_DEC_START_PLAYBACK #

Enum: 1/0x01

Description #

Begin or resume playback.

Param[0] #

0 based frame number in GOP to begin playback from.

Param[1] #

Specifies the number of muted audio frames to play before normal audio resumes. (This is not implemented in the firmware, leave at 0)

CX2341X_DEC_STOP_PLAYBACK #

Enum: 2/0x02

Description #

Ends playback and clears all decoder buffers. If PTS is not zero, playback stops at specified PTS.

Param[0] #

Display 0=last frame, 1=black

Note

this takes effect immediately, so if you want to wait for a PTS, then use '0', otherwise the screen goes to black at once. You can call this later (even if there is no playback) with a 1 value to set the screen to black.

Param[1] #

PTS low

Param[2] #

PTS high

CX2341X_DEC_SET_PLAYBACK_SPEED #

Enum: 3/0x03

Description #

Playback stream at speed other than normal. There are two modes of operation:

  • Smooth: host transfers entire stream and firmware drops unused frames.

  • Coarse: host drops frames based on indexing as required to achieve desired speed.

Param[0] #

Bitmap:
    0:7  0 normal
         1 fast only "1.5 times"
         n nX fast, 1/nX slow
    30   Framedrop:
             '0' during 1.5 times play, every other B frame is dropped
             '1' during 1.5 times play, stream is unchanged (bitrate
                 must not exceed 8mbps)
    31   Speed:
             '0' slow
             '1' fast

Note

n is limited to 2. Anything higher does not result in faster playback. Instead the host should start dropping frames.

Param[1] #

Direction: 0=forward, 1=reverse

Note

to make reverse playback work you have to write full GOPs in reverse order.

Param[2] #

Picture mask:
    1=I frames
    3=I, P frames
    7=I, P, B frames

Param[3] #

B frames per GOP (for reverse play only)

Note

for reverse playback the Picture Mask should be set to I or I, P. Adding B frames to the mask will result in corrupt video. This field has to be set to the correct value in order to keep the timing correct.

Param[4] #

Mute audio: 0=disable, 1=enable

Param[5] #

Display 0=frame, 1=field

Param[6] #

Specifies the number of muted audio frames to play before normal audio resumes. (Not implemented in the firmware, leave at 0)

CX2341X_DEC_STEP_VIDEO #

Enum: 5/0x05

Description #

Each call to this API steps the playback to the next unit defined below in the current playback direction.

Param[0] #

0=frame, 1=top field, 2=bottom field

CX2341X_DEC_SET_DMA_BLOCK_SIZE #

Enum: 8/0x08

Description #

Set DMA transfer block size. Counterpart to API 0xC9

Param[0] #

DMA transfer block size in bytes. A different size may be specified when issuing the DMA transfer command.

CX2341X_DEC_GET_XFER_INFO #

Enum: 9/0x09

Description #

This API call may be used to detect an end of stream condition.

Result[0] #

Stream type

Result[1] #

Address offset

Result[2] #

Maximum bytes to transfer

Result[3] #

Buffer fullness

CX2341X_DEC_GET_DMA_STATUS #

Enum: 10/0x0A

Description #

Status of the last DMA transfer

Result[0] #

Bit 1 set means transfer complete Bit 2 set means DMA error Bit 3 set means linked list error

Result[1] #

DMA type: 0=MPEG, 1=OSD, 2=YUV

CX2341X_DEC_SCHED_DMA_FROM_HOST #

Enum: 11/0x0B

Description #

Setup DMA from host operation. Counterpart to API 0xCC

Param[0] #

Memory address of link list

Param[1] #

Total # of bytes to transfer

Param[2] #

DMA type (0=MPEG, 1=OSD, 2=YUV)

CX2341X_DEC_PAUSE_PLAYBACK #

Enum: 13/0x0D

Description #

Freeze playback immediately. In this mode, when internal buffers are full, no more data will be accepted and data request IRQs will be masked.

Param[0] #

Display: 0=last frame, 1=black

CX2341X_DEC_HALT_FW #

Enum: 14/0x0E

Description #

The firmware is halted and no further API calls are serviced until the firmware is uploaded again.

CX2341X_DEC_SET_STANDARD #

Enum: 16/0x10

Description #

Selects display standard

Param[0] #

0=NTSC, 1=PAL

CX2341X_DEC_GET_VERSION #

Enum: 17/0x11

Description #

Returns decoder firmware version information

Result[0] #

  • Version bitmask:

    • Bits 0:15 build

    • Bits 16:23 minor

    • Bits 24:31 major

CX2341X_DEC_SET_STREAM_INPUT #

Enum: 20/0x14

Description #

Select decoder stream input port

Param[0] #

0=memory (default), 1=streaming

CX2341X_DEC_GET_TIMING_INFO #

Enum: 21/0x15

Description #

Returns timing information from start of playback

Result[0] #

Frame count by decode order

Result[1] #

Video PTS bits 0:31 by display order

Result[2] #

Video PTS bit 32 by display order

Result[3] #

SCR bits 0:31 by display order

Result[4] #

SCR bit 32 by display order

CX2341X_DEC_SET_AUDIO_MODE #

Enum: 22/0x16

Description #

Select audio mode

Param[0] #

  • Dual mono mode action

    0=Stereo, 1=Left, 2=Right, 3=Mono, 4=Swap, -1=Unchanged

Param[1] #

  • Stereo mode action:

    0=Stereo, 1=Left, 2=Right, 3=Mono, 4=Swap, -1=Unchanged

CX2341X_DEC_SET_EVENT_NOTIFICATION #

Enum: 23/0x17

Description #

Setup firmware to notify the host about a particular event. Counterpart to API 0xD5

Param[0] #

  • Event:

    • 0=Audio mode change between mono, (joint) stereo and dual channel.

    • 3=Decoder started

    • 4=Unknown: goes off 10-15 times per second while decoding.

    • 5=Some sync event: goes off once per frame.

Param[1] #

Notification 0=disabled, 1=enabled

Param[2] #

Interrupt bit

Param[3] #

Mailbox slot, -1 if no mailbox required.

CX2341X_DEC_SET_DISPLAY_BUFFERS #

Enum: 24/0x18

Description #

Number of display buffers. To decode all frames in reverse playback you must use nine buffers.

Param[0] #

0=six buffers, 1=nine buffers

CX2341X_DEC_EXTRACT_VBI #

Enum: 25/0x19

Description #

Extracts VBI data

Param[0] #

0=extract from extension & user data, 1=extract from private packets

Result[0] #

VBI table location

Result[1] #

VBI table size

CX2341X_DEC_SET_DECODER_SOURCE #

Enum: 26/0x1A

Description #

Selects decoder source. Ensure that the parameters passed to this API match the encoder settings.

Param[0] #

Mode: 0=MPEG from host, 1=YUV from encoder, 2=YUV from host

Param[1] #

YUV picture width

Param[2] #

YUV picture height

Param[3] #

Bitmap: see Param[0] of API 0xBD

CX2341X_DEC_SET_PREBUFFERING #

Enum: 30/0x1E

Description #

Decoder prebuffering, when enabled up to 128KB are buffered for streams <8mpbs or 640KB for streams >8mbps

Param[0] #

0=off, 1=on

PVR350 Video decoder registers 0x02002800 -> 0x02002B00 #

Author: Ian Armstrong <ian@iarmst.demon.co.uk>

Version: v0.4

Date: 12 March 2007

This list has been worked out through trial and error. There will be mistakes and omissions. Some registers have no obvious effect so it's hard to say what they do, while others interact with each other, or require a certain load sequence. Horizontal filter setup is one example, with six registers working in unison and requiring a certain load sequence to correctly configure. The indexed colour palette is much easier to set at just two registers, but again it requires a certain load sequence.

Some registers are fussy about what they are set to. Load in a bad value & the decoder will fail. A firmware reload will often recover, but sometimes a reset is required. For registers containing size information, setting them to 0 is generally a bad idea. For other control registers i.e. 2878, you'll only find out what values are bad when it hangs.

--------------------------------------------------------------------------------
2800
bit 0
        Decoder enable
        0 = disable
        1 = enable
--------------------------------------------------------------------------------
2804
bits 0:31
        Decoder horizontal Y alias register 1
---------------
2808
bits 0:31
        Decoder horizontal Y alias register 2
---------------
280C
bits 0:31
        Decoder horizontal Y alias register 3
---------------
2810
bits 0:31
        Decoder horizontal Y alias register 4
---------------
2814
bits 0:31
        Decoder horizontal Y alias register 5
---------------
2818
bits 0:31
        Decoder horizontal Y alias trigger

These six registers control the horizontal aliasing filter for the Y plane.
The first five registers must all be loaded before accessing the trigger
(2818), as this register actually clocks the data through for the first
five.

To correctly program set the filter, this whole procedure must be done 16
times. The actual register contents are copied from a lookup-table in the
firmware which contains 4 different filter settings.

--------------------------------------------------------------------------------
281C
bits 0:31
        Decoder horizontal UV alias register 1
---------------
2820
bits 0:31
        Decoder horizontal UV alias register 2
---------------
2824
bits 0:31
        Decoder horizontal UV alias register 3
---------------
2828
bits 0:31
        Decoder horizontal UV alias register 4
---------------
282C
bits 0:31
        Decoder horizontal UV alias register 5
---------------
2830
bits 0:31
        Decoder horizontal UV alias trigger

These six registers control the horizontal aliasing for the UV plane.
Operation is the same as the Y filter, with 2830 being the trigger
register.

--------------------------------------------------------------------------------
2834
bits 0:15
        Decoder Y source width in pixels

bits 16:31
        Decoder Y destination width in pixels
---------------
2838
bits 0:15
        Decoder UV source width in pixels

bits 16:31
        Decoder UV destination width in pixels

NOTE: For both registers, the resulting image must be fully visible on
screen. If the image exceeds the right edge both the source and destination
size must be adjusted to reflect the visible portion. For the source width,
you must take into account the scaling when calculating the new value.
--------------------------------------------------------------------------------

283C
bits 0:31
        Decoder Y horizontal scaling
                Normally = Reg 2854 >> 2
---------------
2840
bits 0:31
        Decoder ?? unknown - horizontal scaling
        Usually 0x00080514
---------------
2844
bits 0:31
        Decoder UV horizontal scaling
        Normally = Reg 2854 >> 2
---------------
2848
bits 0:31
        Decoder ?? unknown - horizontal scaling
        Usually 0x00100514
---------------
284C
bits 0:31
        Decoder ?? unknown - Y plane
        Usually 0x00200020
---------------
2850
bits 0:31
        Decoder ?? unknown - UV plane
        Usually 0x00200020
---------------
2854
bits 0:31
        Decoder 'master' value for horizontal scaling
---------------
2858
bits 0:31
        Decoder ?? unknown
        Usually 0
---------------
285C
bits 0:31
        Decoder ?? unknown
        Normally = Reg 2854 >> 1
---------------
2860
bits 0:31
        Decoder ?? unknown
        Usually 0
---------------
2864
bits 0:31
        Decoder ?? unknown
        Normally = Reg 2854 >> 1
---------------
2868
bits 0:31
        Decoder ?? unknown
        Usually 0

Most of these registers either control horizontal scaling, or appear linked
to it in some way. Register 2854 contains the 'master' value & the other
registers can be calculated from that one. You must also remember to
correctly set the divider in Reg 2874.

To enlarge:
        Reg 2854 = (source_width * 0x00200000) / destination_width
        Reg 2874 = No divide

To reduce from full size down to half size:
        Reg 2854 = (source_width/2 * 0x00200000) / destination width
        Reg 2874 = Divide by 2

To reduce from half size down to quarter size:
        Reg 2854 = (source_width/4 * 0x00200000) / destination width
        Reg 2874 = Divide by 4

The result is always rounded up.

--------------------------------------------------------------------------------
286C
bits 0:15
        Decoder horizontal Y buffer offset

bits 15:31
        Decoder horizontal UV buffer offset

Offset into the video image buffer. If the offset is gradually incremented,
the on screen image will move left & wrap around higher up on the right.

--------------------------------------------------------------------------------
2870
bits 0:15
        Decoder horizontal Y output offset

bits 16:31
        Decoder horizontal UV output offset

Offsets the actual video output. Controls output alignment of the Y & UV
planes. The higher the value, the greater the shift to the left. Use
reg 2890 to move the image right.

--------------------------------------------------------------------------------
2874
bits 0:1
        Decoder horizontal Y output size divider
        00 = No divide
        01 = Divide by 2
        10 = Divide by 3

bits 4:5
        Decoder horizontal UV output size divider
        00 = No divide
        01 = Divide by 2
        10 = Divide by 3

bit 8
        Decoder ?? unknown
        0 = Normal
        1 = Affects video output levels

bit 16
        Decoder ?? unknown
        0 = Normal
        1 = Disable horizontal filter

--------------------------------------------------------------------------------
2878
bit 0
        ?? unknown

bit 1
        osd on/off
        0 = osd off
        1 = osd on

bit 2
        Decoder + osd video timing
        0 = NTSC
        1 = PAL

bits 3:4
        ?? unknown

bit 5
        Decoder + osd
        Swaps upper & lower fields

--------------------------------------------------------------------------------
287C
bits 0:10
        Decoder & osd ?? unknown
        Moves entire screen horizontally. Starts at 0x005 with the screen
        shifted heavily to the right. Incrementing in steps of 0x004 will
        gradually shift the screen to the left.

bits 11:31
        ?? unknown

Normally contents are 0x00101111 (NTSC) or 0x1010111d (PAL)

--------------------------------------------------------------------------------
2880  --------    ?? unknown
2884  --------    ?? unknown
--------------------------------------------------------------------------------
2888
bit 0
        Decoder + osd ?? unknown
        0 = Normal
        1 = Misaligned fields (Correctable through 289C & 28A4)

bit 4
        ?? unknown

bit 8
        ?? unknown

Warning: Bad values will require a firmware reload to recover.
                Known to be bad are 0x000,0x011,0x100,0x111
--------------------------------------------------------------------------------
288C
bits 0:15
        osd ?? unknown
        Appears to affect the osd position stability. The higher the value the
        more unstable it becomes. Decoder output remains stable.

bits 16:31
        osd ?? unknown
        Same as bits 0:15

--------------------------------------------------------------------------------
2890
bits 0:11
        Decoder output horizontal offset.

Horizontal offset moves the video image right. A small left shift is
possible, but it's better to use reg 2870 for that due to its greater
range.

NOTE: Video corruption will occur if video window is shifted off the right
edge. To avoid this read the notes for 2834 & 2838.
--------------------------------------------------------------------------------
2894
bits 0:23
        Decoder output video surround colour.

Contains the colour (in yuv) used to fill the screen when the video is
running in a window.
--------------------------------------------------------------------------------
2898
bits 0:23
        Decoder video window colour
        Contains the colour (in yuv) used to fill the video window when the
        video is turned off.

bit 24
        Decoder video output
        0 = Video on
        1 = Video off

bit 28
        Decoder plane order
        0 = Y,UV
        1 = UV,Y

bit 29
        Decoder second plane byte order
        0 = Normal (UV)
        1 = Swapped (VU)

In normal usage, the first plane is Y & the second plane is UV. Though the
order of the planes can be swapped, only the byte order of the second plane
can be swapped. This isn't much use for the Y plane, but can be useful for
the UV plane.

--------------------------------------------------------------------------------
289C
bits 0:15
        Decoder vertical field offset 1

bits 16:31
        Decoder vertical field offset 2

Controls field output vertical alignment. The higher the number, the lower
the image on screen. Known starting values are 0x011E0017 (NTSC) &
0x01500017 (PAL)
--------------------------------------------------------------------------------
28A0
bits 0:15
        Decoder & osd width in pixels

bits 16:31
        Decoder & osd height in pixels

All output from the decoder & osd are disabled beyond this area. Decoder
output will simply go black outside of this region. If the osd tries to
exceed this area it will become corrupt.
--------------------------------------------------------------------------------
28A4
bits 0:11
        osd left shift.

Has a range of 0x770->0x7FF. With the exception of 0, any value outside of
this range corrupts the osd.
--------------------------------------------------------------------------------
28A8
bits 0:15
        osd vertical field offset 1

bits 16:31
        osd vertical field offset 2

Controls field output vertical alignment. The higher the number, the lower
the image on screen. Known starting values are 0x011E0017 (NTSC) &
0x01500017 (PAL)
--------------------------------------------------------------------------------
28AC  --------    ?? unknown
|
V
28BC  --------    ?? unknown
--------------------------------------------------------------------------------
28C0
bit 0
        Current output field
        0 = first field
        1 = second field

bits 16:31
        Current scanline
        The scanline counts from the top line of the first field
        through to the last line of the second field.
--------------------------------------------------------------------------------
28C4  --------    ?? unknown
|
V
28F8  --------    ?? unknown
--------------------------------------------------------------------------------
28FC
bit 0
        ?? unknown
        0 = Normal
        1 = Breaks decoder & osd output
--------------------------------------------------------------------------------
2900
bits 0:31
        Decoder vertical Y alias register 1
---------------
2904
bits 0:31
        Decoder vertical Y alias register 2
---------------
2908
bits 0:31
        Decoder vertical Y alias trigger

These three registers control the vertical aliasing filter for the Y plane.
Operation is similar to the horizontal Y filter (2804). The only real
difference is that there are only two registers to set before accessing
the trigger register (2908). As for the horizontal filter, the values are
taken from a lookup table in the firmware, and the procedure must be
repeated 16 times to fully program the filter.
--------------------------------------------------------------------------------
290C
bits 0:31
        Decoder vertical UV alias register 1
---------------
2910
bits 0:31
        Decoder vertical UV alias register 2
---------------
2914
bits 0:31
        Decoder vertical UV alias trigger

These three registers control the vertical aliasing filter for the UV
plane. Operation is the same as the Y filter, with 2914 being the trigger.
--------------------------------------------------------------------------------
2918
bits 0:15
        Decoder Y source height in pixels

bits 16:31
        Decoder Y destination height in pixels
---------------
291C
bits 0:15
        Decoder UV source height in pixels divided by 2

bits 16:31
        Decoder UV destination height in pixels

NOTE: For both registers, the resulting image must be fully visible on
screen. If the image exceeds the bottom edge both the source and
destination size must be adjusted to reflect the visible portion. For the
source height, you must take into account the scaling when calculating the
new value.
--------------------------------------------------------------------------------
2920
bits 0:31
        Decoder Y vertical scaling
        Normally = Reg 2930 >> 2
---------------
2924
bits 0:31
        Decoder Y vertical scaling
        Normally = Reg 2920 + 0x514
---------------
2928
bits 0:31
        Decoder UV vertical scaling
        When enlarging = Reg 2930 >> 2
        When reducing = Reg 2930 >> 3
---------------
292C
bits 0:31
        Decoder UV vertical scaling
        Normally = Reg 2928 + 0x514
---------------
2930
bits 0:31
        Decoder 'master' value for vertical scaling
---------------
2934
bits 0:31
        Decoder ?? unknown - Y vertical scaling
---------------
2938
bits 0:31
        Decoder Y vertical scaling
        Normally = Reg 2930
---------------
293C
bits 0:31
        Decoder ?? unknown - Y vertical scaling
---------------
2940
bits 0:31
        Decoder UV vertical scaling
        When enlarging = Reg 2930 >> 1
        When reducing = Reg 2930
---------------
2944
bits 0:31
        Decoder ?? unknown - UV vertical scaling
---------------
2948
bits 0:31
        Decoder UV vertical scaling
        Normally = Reg 2940
---------------
294C
bits 0:31
        Decoder ?? unknown - UV vertical scaling

Most of these registers either control vertical scaling, or appear linked
to it in some way. Register 2930 contains the 'master' value & all other
registers can be calculated from that one. You must also remember to
correctly set the divider in Reg 296C

To enlarge:
        Reg 2930 = (source_height * 0x00200000) / destination_height
        Reg 296C = No divide

To reduce from full size down to half size:
        Reg 2930 = (source_height/2 * 0x00200000) / destination height
        Reg 296C = Divide by 2

To reduce from half down to quarter.
        Reg 2930 = (source_height/4 * 0x00200000) / destination height
        Reg 296C = Divide by 4

--------------------------------------------------------------------------------
2950
bits 0:15
        Decoder Y line index into display buffer, first field

bits 16:31
        Decoder Y vertical line skip, first field
--------------------------------------------------------------------------------
2954
bits 0:15
        Decoder Y line index into display buffer, second field

bits 16:31
        Decoder Y vertical line skip, second field
--------------------------------------------------------------------------------
2958
bits 0:15
        Decoder UV line index into display buffer, first field

bits 16:31
        Decoder UV vertical line skip, first field
--------------------------------------------------------------------------------
295C
bits 0:15
        Decoder UV line index into display buffer, second field

bits 16:31
        Decoder UV vertical line skip, second field
--------------------------------------------------------------------------------
2960
bits 0:15
        Decoder destination height minus 1

bits 16:31
        Decoder destination height divided by 2
--------------------------------------------------------------------------------
2964
bits 0:15
        Decoder Y vertical offset, second field

bits 16:31
        Decoder Y vertical offset, first field

These two registers shift the Y plane up. The higher the number, the
greater the shift.
--------------------------------------------------------------------------------
2968
bits 0:15
        Decoder UV vertical offset, second field

bits 16:31
        Decoder UV vertical offset, first field

These two registers shift the UV plane up. The higher the number, the
greater the shift.
--------------------------------------------------------------------------------
296C
bits 0:1
        Decoder vertical Y output size divider
        00 = No divide
        01 = Divide by 2
        10 = Divide by 4

bits 8:9
        Decoder vertical UV output size divider
        00 = No divide
        01 = Divide by 2
        10 = Divide by 4
--------------------------------------------------------------------------------
2970
bit 0
        Decoder ?? unknown
        0 = Normal
        1 = Affect video output levels

bit 16
        Decoder ?? unknown
        0 = Normal
        1 = Disable vertical filter

--------------------------------------------------------------------------------
2974  --------   ?? unknown
|
V
29EF  --------   ?? unknown
--------------------------------------------------------------------------------
2A00
bits 0:2
        osd colour mode
        000 = 8 bit indexed
        001 = 16 bit (565)
        010 = 15 bit (555)
        011 = 12 bit (444)
        100 = 32 bit (8888)

bits 4:5
        osd display bpp
        01 = 8 bit
        10 = 16 bit
        11 = 32 bit

bit 8
        osd global alpha
        0 = Off
        1 = On

bit 9
        osd local alpha
        0 = Off
        1 = On

bit 10
        osd colour key
        0 = Off
        1 = On

bit 11
        osd ?? unknown
        Must be 1

bit 13
        osd colour space
        0 = ARGB
        1 = AYVU

bits 16:31
        osd ?? unknown
        Must be 0x001B (some kind of buffer pointer ?)

When the bits-per-pixel is set to 8, the colour mode is ignored and
assumed to be 8 bit indexed. For 16 & 32 bits-per-pixel the colour depth
is honoured, and when using a colour depth that requires fewer bytes than
allocated the extra bytes are used as padding. So for a 32 bpp with 8 bit
index colour, there are 3 padding bytes per pixel. It's also possible to
select 16bpp with a 32 bit colour mode. This results in the pixel width
being doubled, but the color key will not work as expected in this mode.

Colour key is as it suggests. You designate a colour which will become
completely transparent. When using 565, 555 or 444 colour modes, the
colour key is always 16 bits wide. The colour to key on is set in Reg 2A18.

Local alpha works differently depending on the colour mode. For 32bpp & 8
bit indexed, local alpha is a per-pixel 256 step transparency, with 0 being
transparent and 255 being solid. For the 16bpp modes 555 & 444, the unused
bit(s) act as a simple transparency switch, with 0 being solid & 1 being
fully transparent. There is no local alpha support for 16bit 565.

Global alpha is a 256 step transparency that applies to the entire osd,
with 0 being transparent & 255 being solid.

It's possible to combine colour key, local alpha & global alpha.
--------------------------------------------------------------------------------
2A04
bits 0:15
        osd x coord for left edge

bits 16:31
        osd y coord for top edge
---------------
2A08
bits 0:15
        osd x coord for right edge

bits 16:31
        osd y coord for bottom edge

For both registers, (0,0) = top left corner of the display area. These
registers do not control the osd size, only where it's positioned & how
much is visible. The visible osd area cannot exceed the right edge of the
display, otherwise the osd will become corrupt. See reg 2A10 for
setting osd width.
--------------------------------------------------------------------------------
2A0C
bits 0:31
        osd buffer index

An index into the osd buffer. Slowly incrementing this moves the osd left,
wrapping around onto the right edge
--------------------------------------------------------------------------------
2A10
bits 0:11
        osd buffer 32 bit word width

Contains the width of the osd measured in 32 bit words. This means that all
colour modes are restricted to a byte width which is divisible by 4.
--------------------------------------------------------------------------------
2A14
bits 0:15
        osd height in pixels

bits 16:32
        osd line index into buffer
        osd will start displaying from this line.
--------------------------------------------------------------------------------
2A18
bits 0:31
        osd colour key

Contains the colour value which will be transparent.
--------------------------------------------------------------------------------
2A1C
bits 0:7
        osd global alpha

Contains the global alpha value (equiv ivtvfbctl --alpha XX)
--------------------------------------------------------------------------------
2A20  --------    ?? unknown
|
V
2A2C  --------    ?? unknown
--------------------------------------------------------------------------------
2A30
bits 0:7
        osd colour to change in indexed palette
---------------
2A34
bits 0:31
        osd colour for indexed palette

To set the new palette, first load the index of the colour to change into
2A30, then load the new colour into 2A34. The full palette is 256 colours,
so the index range is 0x00-0xFF
--------------------------------------------------------------------------------
2A38  --------    ?? unknown
2A3C  --------    ?? unknown
--------------------------------------------------------------------------------
2A40
bits 0:31
        osd ?? unknown

Affects overall brightness, wrapping around to black
--------------------------------------------------------------------------------
2A44
bits 0:31
        osd ?? unknown

Green tint
--------------------------------------------------------------------------------
2A48
bits 0:31
        osd ?? unknown

Red tint
--------------------------------------------------------------------------------
2A4C
bits 0:31
        osd ?? unknown

Affects overall brightness, wrapping around to black
--------------------------------------------------------------------------------
2A50
bits 0:31
        osd ?? unknown

Colour shift
--------------------------------------------------------------------------------
2A54
bits 0:31
        osd ?? unknown

Colour shift
--------------------------------------------------------------------------------
2A58  --------    ?? unknown
|
V
2AFC  --------    ?? unknown
--------------------------------------------------------------------------------
2B00
bit 0
        osd filter control
        0 = filter off
        1 = filter on

bits 1:4
        osd ?? unknown

--------------------------------------------------------------------------------

The cx231xx DMA engine #

This page describes the structures and procedures used by the cx2341x DMA engine.

Introduction #

The cx2341x PCI interface is busmaster capable. This means it has a DMA engine to efficiently transfer large volumes of data between the card and main memory without requiring help from a CPU. Like most hardware, it must operate on contiguous physical memory. This is difficult to come by in large quantities on virtual memory machines.

Therefore, it also supports a technique called "scatter-gather". The card can transfer multiple buffers in one operation. Instead of allocating one large contiguous buffer, the driver can allocate several smaller buffers.

In practice, I've seen the average transfer to be roughly 80K, but transfers above 128K were not uncommon, particularly at startup. The 128K figure is important, because that is the largest block that the kernel can normally allocate. Even still, 128K blocks are hard to come by, so the driver writer is urged to choose a smaller block size and learn the scatter-gather technique.

Mailbox #10 is reserved for DMA transfer information.

Note: the hardware expects little-endian data ('intel format').

Flow #

This section describes, in general, the order of events when handling DMA transfers. Detailed information follows this section.

  • The card raises the Encoder interrupt.

  • The driver reads the transfer type, offset and size from Mailbox #10.

  • The driver constructs the scatter-gather array from enough free dma buffers to cover the size.

  • The driver schedules the DMA transfer via the ScheduleDMAtoHost API call.

  • The card raises the DMA Complete interrupt.

  • The driver checks the DMA status register for any errors.

  • The driver post-processes the newly transferred buffers.

NOTE! It is possible that the Encoder and DMA Complete interrupts get raised simultaneously. (End of the last, start of the next, etc.)

Mailbox #10 #

The Flags, Command, Return Value and Timeout fields are ignored.

  • Name: Mailbox #10

  • Results[0]: Type: 0: MPEG.

  • Results[1]: Offset: The position relative to the card's memory space.

  • Results[2]: Size: The exact number of bytes to transfer.

My speculation is that since the StartCapture API has a capture type of "RAW" available, that the type field will have other values that correspond to YUV and PCM data.

Scatter-Gather Array #

The scatter-gather array is a contiguously allocated block of memory that tells the card the source and destination of each data-block to transfer. Card "addresses" are derived from the offset supplied by Mailbox #10. Host addresses are the physical memory location of the target DMA buffer.

Each S-G array element is a struct of three 32-bit words. The first word is the source address, the second is the destination address. Both take up the entire 32 bits. The lowest 18 bits of the third word is the transfer byte count. The high-bit of the third word is the "last" flag. The last-flag tells the card to raise the DMA_DONE interrupt. From hard personal experience, if you forget to set this bit, the card will still "work" but the stream will most likely get corrupted.

The transfer count must be a multiple of 256. Therefore, the driver will need to track how much data in the target buffer is valid and deal with it accordingly.

Array Element:

  • 32-bit Source Address

  • 32-bit Destination Address

  • 14-bit reserved (high bit is the last flag)

  • 18-bit byte count

DMA Transfer Status #

Register 0x0004 holds the DMA Transfer Status:

  • bit 0: read completed

  • bit 1: write completed

  • bit 2: DMA read error

  • bit 3: DMA write error

  • bit 4: Scatter-Gather array error

The cx88 driver

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

Author: Gerd Hoffmann

Documentation missing at the cx88 datasheet #

MO_OUTPUT_FORMAT (0x310164)

Previous default from DScaler: 0x1c1f0008
Digit 8: 31-28
28: PREVREMOD = 1

Digit 7: 27-24 (0xc = 12 = b1100 )
27: COMBALT = 1
26: PAL_INV_PHASE
  (DScaler apparently set this to 1, resulted in sucky picture)

Digits 6,5: 23-16
25-16: COMB_RANGE = 0x1f [default] (9 bits -> max 512)

Digit 4: 15-12
15: DISIFX = 0
14: INVCBF = 0
13: DISADAPT = 0
12: NARROWADAPT = 0

Digit 3: 11-8
11: FORCE2H
10: FORCEREMD
9: NCHROMAEN
8: NREMODEN

Digit 2: 7-4
7-6: YCORE
5-4: CCORE

Digit 1: 3-0
3: RANGE = 1
2: HACTEXT
1: HSFMT

0x47 is the sync byte for MPEG-2 transport stream packets. Datasheet incorrectly states to use 47 decimal. 188 is the length. All DVB compliant frontends output packets with this start code.

Hauppauge WinTV cx88 IR information #

The controls for the mux are GPIO [0,1] for source, and GPIO 2 for muting.

GPIO0

GPIO1

0

0

TV Audio

1

0

FM radio

0

1

Line-In

1

1

Mono tuner bypass or CD passthru (tuner specific)

GPIO 16(I believe) is tied to the IR port (if present).

From the data sheet:

  • Register 24'h20004 PCI Interrupt Status
  • bit [18] IR_SMP_INT Set when 32 input samples have been collected over

  • gpio[16] pin into GP_SAMPLE register.

What's missing from the data sheet:

  • Setup 4KHz sampling rate (roughly 2x oversampled; good enough for our RC5 compat remote)

  • set register 0x35C050 to 0xa80a80

  • enable sampling

  • set register 0x35C054 to 0x5

  • enable the IRQ bit 18 in the interrupt mask register (and provide for a handler)

GP_SAMPLE register is at 0x35C058

Bits are then right shifted into the GP_SAMPLE register at the specified rate; you get an interrupt when a full DWORD is received. You need to recover the actual RC5 bits out of the (oversampled) IR sensor bits. (Hint: look for the 0/1and 1/0 crossings of the RC5 bi-phase data) An actual raw RC5 code will span 2-3 DWORDS, depending on the actual alignment.

I'm pretty sure when no IR signal is present the receiver is always in a marking state(1); but stray light, etc can cause intermittent noise values as well. Remember, this is a free running sample of the IR receiver state over time, so don't assume any sample starts at any particular place.

Additional info #

This data sheet (google search) seems to have a lovely description of the RC5 basics: http://www.atmel.com/dyn/resources/prod_documents/doc2817.pdf

This document has more data: http://www.nenya.be/beor/electronics/rc5.htm

This document has a how to decode a bi-phase data stream: http://www.ee.washington.edu/circuit_archive/text/ir_decode.txt

This document has still more info: http://www.xs4all.nl/~sbp/knowledge/ir/rc5.htm

Idea behind the dvb-usb-framework

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

Note

  1. This documentation is outdated. Please check at the DVB wiki at https://linuxtv.org/wiki for more updated info.

  2. deprecated: Newer DVB USB drivers should use the dvb-usb-v2 framework.

In March 2005 I got the new Twinhan USB2.0 DVB-T device. They provided specs and a firmware.

Quite keen I wanted to put the driver (with some quirks of course) into dibusb. After reading some specs and doing some USB snooping, it realized, that the dibusb-driver would be a complete mess afterwards. So I decided to do it in a different way: With the help of a dvb-usb-framework.

The framework provides generic functions (mostly kernel API calls), such as:

  • Transport Stream URB handling in conjunction with dvb-demux-feed-control (bulk and isoc are supported)

  • registering the device for the DVB-API

  • registering an I2C-adapter if applicable

  • remote-control/input-device handling

  • firmware requesting and loading (currently just for the Cypress USB controllers)

  • other functions/methods which can be shared by several drivers (such as functions for bulk-control-commands)

  • TODO: a I2C-chunker. It creates device-specific chunks of register-accesses depending on length of a register and the number of values that can be multi-written and multi-read.

The source code of the particular DVB USB devices does just the communication with the device via the bus. The connection between the DVB-API-functionality is done via callbacks, assigned in a static device-description (struct dvb_usb_device) each device-driver has to have.

For an example have a look in drivers/media/usb/dvb-usb/vp7045*.

Objective is to migrate all the usb-devices (dibusb, cinergyT2, maybe the ttusb; flexcop-usb already benefits from the generic flexcop-device) to use the dvb-usb-lib.

TODO: dynamic enabling and disabling of the pid-filter in regard to number of feeds requested.

Supported devices #

See the LinuxTV DVB Wiki at https://linuxtv.org for a complete list of cards/drivers/firmwares: https://linuxtv.org/wiki/index.php/DVB_USB

  1. History & News:

2005-06-30

  • added support for WideView WT-220U (Thanks to Steve Chang)

2005-05-30

  • added basic isochronous support to the dvb-usb-framework

    • added support for Conexant Hybrid reference design and Nebula

      DigiTV USB

2005-04-17

  • all dibusb devices ported to make use of the dvb-usb-framework

2005-04-02

  • re-enabled and improved remote control code.

2005-03-31

  • ported the Yakumo/Hama/Typhoon DVB-T USB2.0 device to dvb-usb.

2005-03-30

  • first commit of the dvb-usb-module based on the dibusb-source. First device is a new driver for the TwinhanDTV Alpha / MagicBox II USB2.0-only DVB-T device.

  • (change from dvb-dibusb to dvb-usb)

2005-03-28

  • added support for the AVerMedia AverTV DVB-T USB2.0 device (Thanks to Glen Harris and Jiun-Kuei Jung, AVerMedia)

2005-03-14

  • added support for the Typhoon/Yakumo/HAMA DVB-T mobile USB2.0

2005-02-11

  • added support for the KWorld/ADSTech Instant DVB-T USB2.0. Thanks a lot to Joachim von Caron

2005-02-02 - added support for the Hauppauge Win-TV Nova-T USB2

2005-01-31 - distorted streaming is gone for USB1.1 devices

2005-01-13

  • moved the mirrored pid_filter_table back to dvb-dibusb first almost working version for HanfTek UMT-010 found out, that Yakumo/HAMA/Typhoon are predecessors of the HanfTek UMT-010

2005-01-10

  • refactoring completed, now everything is very delightful

  • tuner quirks for some weird devices (Artec T1 AN2235 device has sometimes a Panasonic Tuner assembled). Tunerprobing implemented. Thanks a lot to Gunnar Wittich.

2004-12-29

  • after several days of struggling around bug of no returning URBs fixed.

2004-12-26

  • refactored the dibusb-driver, split into separate files

  • i2c-probing enabled

2004-12-06

  • possibility for demod i2c-address probing

  • new usb IDs (Compro, Artec)

2004-11-23

  • merged changes from DiB3000MC_ver2.1

  • revised the debugging

  • possibility to deliver the complete TS for USB2.0

2004-11-21

  • first working version of the dib3000mc/p frontend driver.

2004-11-12

  • added additional remote control keys. Thanks to Uwe Hanke.

2004-11-07

  • added remote control support. Thanks to David Matthews.

2004-11-05

  • added support for a new devices (Grandtec/Avermedia/Artec)

  • merged my changes (for dib3000mb/dibusb) to the FE_REFACTORING, because it became HEAD

  • moved transfer control (pid filter, fifo control) from usb driver to frontend, it seems better settled there (added xfer_ops-struct)

  • created a common files for frontends (mc/p/mb)

2004-09-28

  • added support for a new device (Unknown, vendor ID is Hyper-Paltek)

2004-09-20

  • added support for a new device (Compro DVB-U2000), thanks to Amaury Demol for reporting

  • changed usb TS transfer method (several urbs, stopping transfer before setting a new pid)

2004-09-13

  • added support for a new device (Artec T1 USB TVBOX), thanks to Christian Motschke for reporting

2004-09-05

  • released the dibusb device and dib3000mb-frontend driver (old news for vp7041.c)

2004-07-15

  • found out, by accident, that the device has a TUA6010XS for PLL

2004-07-12

  • figured out, that the driver should also work with the CTS Portable (Chinese Television System)

2004-07-08

  • firmware-extraction-2.422-problem solved, driver is now working properly with firmware extracted from 2.422

  • #if for 2.6.4 (dvb), compile issue

  • changed firmware handling, see vp7041.txt sec 1.1

2004-07-02

  • some tuner modifications, v0.1, cleanups, first public

2004-06-28

  • now using the dvb_dmx_swfilter_packets, everything runs fine now

2004-06-27

  • able to watch and switching channels (pre-alpha)

  • no section filtering yet

2004-06-06

  • first TS received, but kernel oops :/

2004-05-14

  • firmware loader is working

2004-05-11

  • start writing the driver

How to use? #

Firmware #

Most of the USB drivers need to download a firmware to the device before start working.

Have a look at the Wikipage for the DVB-USB-drivers to find out, which firmware you need for your device:

https://linuxtv.org/wiki/index.php/DVB_USB

Compiling #

Since the driver is in the linux kernel, activating the driver in your favorite config-environment should sufficient. I recommend to compile the driver as module. Hotplug does the rest.

If you use dvb-kernel enter the build-2.6 directory run 'make' and 'insmod.sh load' afterwards.

Loading the drivers #

Hotplug is able to load the driver, when it is needed (because you plugged in the device).

If you want to enable debug output, you have to load the driver manually and from within the dvb-kernel cvs repository.

first have a look, which debug level are available:

# modinfo dvb-usb
# modinfo dvb-usb-vp7045

etc.
modprobe dvb-usb debug=<level>
modprobe dvb-usb-vp7045 debug=<level>
etc.

should do the trick.

When the driver is loaded successfully, the firmware file was in the right place and the device is connected, the "Power"-LED should be turned on.

At this point you should be able to start a dvb-capable application. I'm use (t|s)zap, mplayer and dvbscan to test the basics. VDR-xine provides the long-term test scenario.

Known problems and bugs #

  • Don't remove the USB device while running an DVB application, your system will go crazy or die most likely.

Adding support for devices #

TODO

USB1.1 Bandwidth limitation #

A lot of the currently supported devices are USB1.1 and thus they have a maximum bandwidth of about 5-6 MBit/s when connected to a USB2.0 hub. This is not enough for receiving the complete transport stream of a DVB-T channel (which is about 16 MBit/s). Normally this is not a problem, if you only want to watch TV (this does not apply for HDTV), but watching a channel while recording another channel on the same frequency simply does not work very well. This applies to all USB1.1 DVB-T devices, not just the dvb-usb-devices)

The bug, where the TS is distorted by a heavy usage of the device is gone definitely. All dvb-usb-devices I was using (Twinhan, Kworld, DiBcom) are working like charm now with VDR. Sometimes I even was able to record a channel and watch another one.

Comments #

Patches, comments and suggestions are very very welcome.

3. Acknowledgements #

Amaury Demol (Amaury.Demol@parrot.com) and Francois Kanounnikoff from DiBcom for providing specs, code and help, on which the dvb-dibusb, dib3000mb and dib3000mc are based.

David Matthews for identifying a new device type (Artec T1 with AN2235) and for extending dibusb with remote control event handling. Thank you.

Alex Woods for frequently answering question about usb and dvb stuff, a big thank you.

Bernd Wagner for helping with huge bug reports and discussions.

Gunnar Wittich and Joachim von Caron for their trust for providing root-shells on their machines to implement support for new devices.

Allan Third and Michael Hutchinson for their help to write the Nebula digitv-driver.

Glen Harris for bringing up, that there is a new dibusb-device and Jiun-Kuei Jung from AVerMedia who kindly provided a special firmware to get the device up and running in Linux.

Jennifer Chen, Jeff and Jack from Twinhan for kindly supporting by writing the vp7045-driver.

Steve Chang from WideView for providing information for new devices and firmware files.

Michael Paxton for submitting remote control keymaps.

Some guys on the linux-dvb mailing list for encouraging me.

Peter Schildmann >peter.schildmann-nospam-at-web.de< for his user-level firmware loader, which saves a lot of time (when writing the vp7041 driver)

Ulf Hermenau for helping me out with traditional chinese.

André Smoktun and Christian Frömmel for supporting me with hardware and listening to my problems very patiently.

The Samsung S5P/EXYNOS4 FIMC driver

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

Copyright © 2012 - 2013 Samsung Electronics Co., Ltd.

Files partitioning #

  • media device driver

    drivers/media/platform/samsung/exynos4-is/media-dev.[ch]

  • camera capture video device driver

    drivers/media/platform/samsung/exynos4-is/fimc-capture.c

  • MIPI-CSI2 receiver subdev

    drivers/media/platform/samsung/exynos4-is/mipi-csis.[ch]

  • video post-processor (mem-to-mem)

    drivers/media/platform/samsung/exynos4-is/fimc-core.c

  • common files

    drivers/media/platform/samsung/exynos4-is/fimc-core.h drivers/media/platform/samsung/exynos4-is/fimc-reg.h drivers/media/platform/samsung/exynos4-is/regs-fimc.h

Frontend drivers

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

Frontend attach headers #

struct a8293_platform_data #

Platform data for the a8293 driver

Definition

struct a8293_platform_data {
    struct dvb_frontend *dvb_frontend;
    int volt_slew_nanos_per_mv;
};

Members

  • dvb_frontend: DVB frontend.
  • volt_slew_nanos_per_mv: Slew rate when increasing LNB voltage, in nanoseconds per millivolt.

struct af9013_platform_data #

Platform data for the af9013 driver

Definition

struct af9013_platform_data {
        u32 clk;
    #define AF9013_TUNER_MXL5003D      3;
    #define AF9013_TUNER_MXL5005D     13;
    #define AF9013_TUNER_MXL5005R     30;
    #define AF9013_TUNER_ENV77H11D5  129;
    #define AF9013_TUNER_MT2060      130;
    #define AF9013_TUNER_MC44S803    133;
    #define AF9013_TUNER_QT1010      134;
    #define AF9013_TUNER_UNKNOWN     140;
    #define AF9013_TUNER_MT2060_2    147;
    #define AF9013_TUNER_TDA18271    156;
    #define AF9013_TUNER_QT1010A     162;
    #define AF9013_TUNER_MXL5007T    177;
    #define AF9013_TUNER_TDA18218    179;
        u8 tuner;
        u32 if_frequency;
    #define AF9013_TS_MODE_USB       0;
    #define AF9013_TS_MODE_PARALLEL  1;
    #define AF9013_TS_MODE_SERIAL    2;
        u8 ts_mode;
        u8 ts_output_pin;
        bool spec_inv;
        u8 api_version[4];
    #define AF9013_GPIO_ON (1 << 0);
    #define AF9013_GPIO_EN (1 << 1);
    #define AF9013_GPIO_O  (1 << 2);
    #define AF9013_GPIO_I  (1 << 3);
    #define AF9013_GPIO_LO (AF9013_GPIO_ON|AF9013_GPIO_EN);
    #define AF9013_GPIO_HI (AF9013_GPIO_ON|AF9013_GPIO_EN|AF9013_GPIO_O);
    #define AF9013_GPIO_TUNER_ON  (AF9013_GPIO_ON|AF9013_GPIO_EN);
    #define AF9013_GPIO_TUNER_OFF (AF9013_GPIO_ON|AF9013_GPIO_EN|AF9013_GPIO_O);
        u8 gpio[4];
        struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *);
        struct i2c_adapter* (*get_i2c_adapter)(struct i2c_client *);
        int (*pid_filter_ctrl)(struct dvb_frontend *, int);
        int (*pid_filter)(struct dvb_frontend *, u8, u16, int);
};

Members

  • clk: Clock frequency.
  • tuner: Used tuner model.
  • if_frequency: IF frequency.
  • ts_mode: TS mode.
  • ts_output_pin: TS output pin.
  • spec_inv: Input spectrum inverted.
  • api_version: Firmware API version.
  • gpio: GPIOs.
  • get_dvb_frontend: Get DVB frontend callback.
  • get_i2c_adapter: Get I2C adapter.
  • pid_filter_ctrl: Control PID filter.
  • pid_filter: Set PID to PID filter.

struct ascot2e_config #

the configuration of Ascot2E tuner driver

Definition

struct ascot2e_config {
    u8 i2c_address;
    u8 xtal_freq_mhz;
    void *set_tuner_priv;
    int (*set_tuner_callback)(void *, int);
};

Members

  • i2c_address: I2C address of the tuner
  • xtal_freq_mhz: Oscillator frequency, MHz
  • set_tuner_priv: Callback function private context
  • set_tuner_callback: Callback function that notifies the parent driver which tuner is active now

ascot2e_attach() #

struct dvb_frontend * ascot2e_attach(struct dvb_frontend *fe, const struct ascot2e_config *config, struct i2c_adapter *i2c)

Attach an ascot2e tuner

Parameters

  • struct dvb_frontend *fe: frontend to be attached
  • const struct ascot2e_config *config: pointer to struct ascot2e_config with tuner configuration.
  • struct i2c_adapter *i2c: i2c adapter to use.

Return

FE pointer on success, NULL on failure.

struct cxd2820r_platform_data #

Platform data for the cxd2820r driver

Definition

struct cxd2820r_platform_data {
    u8 ts_mode;
    bool ts_clk_inv;
    bool if_agc_polarity;
    bool spec_inv;
    int **gpio_chip_base;
    struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *);
};

Members

  • ts_mode: TS mode.
  • ts_clk_inv: TS clock inverted.
  • if_agc_polarity: IF AGC polarity.
  • spec_inv: Input spectrum inverted.
  • gpio_chip_base: GPIO.
  • get_dvb_frontend: Get DVB frontend.

struct cxd2820r_config #

configuration for cxd2020r demod

Definition

struct cxd2820r_config {
    u8 i2c_address;
    u8 ts_mode;
    bool ts_clock_inv;
    bool if_agc_polarity;
    bool spec_inv;
};

Members

  • i2c_address: Demodulator I2C address. Driver determines DVB-C slave I2C address automatically from master address. Default: none, must set. Values: 0x6c, 0x6d.
  • ts_mode: TS output mode. Default: none, must set. Values: FIXME?
  • ts_clock_inv: TS clock inverted. Default: 0. Values: 0, 1.
  • if_agc_polarity: Default: 0. Values: 0, 1
  • spec_inv: Spectrum inversion. Default: 0. Values: 0, 1.

cxd2820r_attach() #

struct dvb_frontend * cxd2820r_attach(const struct cxd2820r_config *config, struct i2c_adapter *i2c, int *gpio_chip_base)

Attach a cxd2820r demod

Parameters

  • const struct cxd2820r_config *config: pointer to struct cxd2820r_config with demod configuration.
  • struct i2c_adapter *i2c: i2c adapter to use.
  • int *gpio_chip_base: if zero, disables GPIO setting. Otherwise, if CONFIG_GPIOLIB is set dynamically allocate gpio base; if is not set, use its value to setup the GPIO pins.

Return

FE pointer on success, NULL on failure.

struct drxk_config #

Configure the initial parameters for DRX-K

Definition

struct drxk_config {
    u8 adr;
    bool single_master;
    bool no_i2c_bridge;
    bool parallel_ts;
    bool dynamic_clk;
    bool enable_merr_cfg;
    bool antenna_dvbt;
    u16 antenna_gpio;
    u8 mpeg_out_clk_strength;
    int chunk_size;
    const char      *microcode_name;
    int qam_demod_parameter_count;
};

Members

  • adr: I2C address of the DRX-K
  • single_master: Device is on the single master mode
  • no_i2c_bridge: Don't switch the I2C bridge to talk with tuner
  • parallel_ts: True means that the device uses parallel TS, Serial otherwise.
  • dynamic_clk: True means that the clock will be dynamically adjusted. Static clock otherwise.
  • enable_merr_cfg: Enable SIO_PDR_PERR_CFG/SIO_PDR_MVAL_CFG.
  • antenna_dvbt: GPIO bit for changing antenna to DVB-C. A value of 1 means that 1=DVBC, 0 = DVBT. Zero means the opposite.
  • antenna_gpio: GPIO bit used to control the antenna
  • mpeg_out_clk_strength: DRXK Mpeg output clock drive strength.
  • chunk_size: maximum size for I2C messages
  • microcode_name: Name of the firmware file with the microcode
  • qam_demod_parameter_count: The number of parameters used for the command to set the demodulator parameters. All firmwares are using the 2-parameter command. An exception is the drxk_a3.mc firmware, which uses the 4-parameter command. A value of 0 (default) or lower indicates that the correct number of parameters will be automatically detected.

Description

On the *_gpio vars, bit 0 is UIO-1, bit 1 is UIO-2 and bit 2 is UIO-3.

drxk_attach() #

struct dvb_frontend * drxk_attach(const struct drxk_config *config, struct i2c_adapter *i2c)

Attach a drxk demod

Parameters

  • const struct drxk_config *config: pointer to struct drxk_config with demod configuration.
  • struct i2c_adapter *i2c: i2c adapter to use.

Return

FE pointer on success, NULL on failure.

dvb_pll_attach() #

struct dvb_frontend * dvb_pll_attach(struct dvb_frontend *fe, int pll_addr, struct i2c_adapter *i2c, unsigned int pll_desc_id)

Attach a dvb-pll to the supplied frontend structure.

Parameters

  • struct dvb_frontend *fe: Frontend to attach to.
  • int pll_addr: i2c address of the PLL (if used).
  • struct i2c_adapter *i2c: i2c adapter to use (set to NULL if not used).
  • unsigned int pll_desc_id: dvb_pll_desc to use.

Return

Frontend pointer on success, NULL on failure

struct helene_config #

the configuration of 'Helene' tuner driver

Definition

struct helene_config {
    u8 i2c_address;
    u8 xtal_freq_mhz;
    void *set_tuner_priv;
    int (*set_tuner_callback)(void *, int);
    enum helene_xtal xtal;
    struct dvb_frontend *fe;
};

Members

  • i2c_address: I2C address of the tuner
  • xtal_freq_mhz: Oscillator frequency, MHz
  • set_tuner_priv: Callback function private context
  • set_tuner_callback: Callback function that notifies the parent driver which tuner is active now
  • xtal: Cristal frequency as described by enum helene_xtal
  • fe: Frontend for which connects this tuner

helene_attach() #

struct dvb_frontend * helene_attach(struct dvb_frontend *fe, const struct helene_config *config, struct i2c_adapter *i2c)

Attach a helene tuner (terrestrial and cable standards)

Parameters

  • struct dvb_frontend *fe: frontend to be attached
  • const struct helene_config *config: pointer to struct helene_config with tuner configuration.
  • struct i2c_adapter *i2c: i2c adapter to use.

Return

FE pointer on success, NULL on failure.

helene_attach_s() #

struct dvb_frontend * helene_attach_s(struct dvb_frontend *fe, const struct helene_config *config, struct i2c_adapter *i2c)

Attach a helene tuner (satellite standards)

Parameters

  • struct dvb_frontend *fe: frontend to be attached
  • const struct helene_config *config: pointer to struct helene_config with tuner configuration.
  • struct i2c_adapter *i2c: i2c adapter to use.

Return

FE pointer on success, NULL on failure.

struct horus3a_config #

the configuration of Horus3A tuner driver

Definition

struct horus3a_config {
    u8 i2c_address;
    u8 xtal_freq_mhz;
    void *set_tuner_priv;
    int (*set_tuner_callback)(void *, int);
};

Members

  • i2c_address: I2C address of the tuner
  • xtal_freq_mhz: Oscillator frequency, MHz
  • set_tuner_priv: Callback function private context
  • set_tuner_callback: Callback function that notifies the parent driver which tuner is active now

horus3a_attach() #

struct dvb_frontend * horus3a_attach(struct dvb_frontend *fe, const struct horus3a_config *config, struct i2c_adapter *i2c)

Attach a horus3a tuner

Parameters

  • struct dvb_frontend *fe: frontend to be attached
  • const struct horus3a_config *config: pointer to struct helene_config with tuner configuration.
  • struct i2c_adapter *i2c: i2c adapter to use.

Return

FE pointer on success, NULL on failure.

struct ix2505v_config #

ix2505 attachment configuration

Definition

struct ix2505v_config {
    u8 tuner_address;
    u8 tuner_gain;
    u8 tuner_chargepump;
    int min_delay_ms;
    u8 tuner_write_only;
};

Members

  • tuner_address: tuner address
  • tuner_gain: Baseband AMP gain control 0/1=0dB(default) 2=-2bB 3=-4dB
  • tuner_chargepump: Charge pump output +/- 0=120 1=260 2=555 3=1200(default)
  • min_delay_ms: delay after tune
  • tuner_write_only: disables reads

ix2505v_attach() #

struct dvb_frontend * ix2505v_attach(struct dvb_frontend *fe, const struct ix2505v_config *config, struct i2c_adapter *i2c)

Attach a ix2505v tuner to the supplied frontend structure.

Parameters

  • struct dvb_frontend *fe: Frontend to attach to.
  • const struct ix2505v_config *config: pointer to struct ix2505v_config
  • struct i2c_adapter *i2c: pointer to struct i2c_adapter.

Return

FE pointer on success, NULL on failure.

enum m88ds3103_ts_mode #

TS connection mode

Constants

  • M88DS3103_TS_SERIAL: TS output pin D0, normal
  • M88DS3103_TS_SERIAL_D7: TS output pin D7
  • M88DS3103_TS_PARALLEL: TS Parallel mode
  • M88DS3103_TS_CI: TS CI Mode

enum m88ds3103_clock_out #

Constants

  • M88DS3103_CLOCK_OUT_DISABLED: Clock output is disabled
  • M88DS3103_CLOCK_OUT_ENABLED: Clock output is enabled with crystal clock.
  • M88DS3103_CLOCK_OUT_ENABLED_DIV2: Clock output is enabled with half crystal clock.

struct m88ds3103_platform_data #

Platform data for the m88ds3103 driver

Definition

struct m88ds3103_platform_data {
    u32 clk;
    u16 i2c_wr_max;
    enum m88ds3103_ts_mode ts_mode;
    u32 ts_clk;
    enum m88ds3103_clock_out clk_out;
    u8 ts_clk_pol:1;
    u8 spec_inv:1;
    u8 agc;
    u8 agc_inv:1;
    u8 envelope_mode:1;
    u8 lnb_hv_pol:1;
    u8 lnb_en_pol:1;
    struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *);
    struct i2c_adapter* (*get_i2c_adapter)(struct i2c_client *);
};

Members

  • clk: Clock frequency.
  • i2c_wr_max: Max bytes I2C adapter can write at once.
  • ts_mode: TS mode.
  • ts_clk: TS clock (KHz).
  • clk_out: Clock output.
  • ts_clk_pol: TS clk polarity. 1-active at falling edge; 0-active at rising edge.
  • spec_inv: Input spectrum inversion.
  • agc: AGC configuration.
  • agc_inv: AGC polarity.
  • envelope_mode: DiSEqC envelope mode.
  • lnb_hv_pol: LNB H/V pin polarity. 0: pin high set to VOLTAGE_18, pin low to set VOLTAGE_13. 1: pin high set to VOLTAGE_13, pin low to set VOLTAGE_18.
  • lnb_en_pol: LNB enable pin polarity. 0: pin high to disable, pin low to enable. 1: pin high to enable, pin low to disable.
  • get_dvb_frontend: Get DVB frontend.
  • get_i2c_adapter: Get I2C adapter.

struct m88ds3103_config #

m88ds3102 configuration

Definition

struct m88ds3103_config {
    u8 i2c_addr;
    u32 clock;
    u16 i2c_wr_max;
    u8 ts_mode;
    u32 ts_clk;
    u8 ts_clk_pol:1;
    u8 spec_inv:1;
    u8 agc_inv:1;
    u8 clock_out;
    u8 envelope_mode:1;
    u8 agc;
    u8 lnb_hv_pol:1;
    u8 lnb_en_pol:1;
};

Members

  • i2c_addr: I2C address. Default: none, must set. Example: 0x68, ...
  • clock: Device's clock. Default: none, must set. Example: 27000000
  • i2c_wr_max: Max bytes I2C provider is asked to write at once. Default: none, must set. Example: 33, 65, ...
  • ts_mode: TS output mode, as defined by enum m88ds3103_ts_mode. Default: M88DS3103_TS_SERIAL.
  • ts_clk: TS clk in KHz. Default: 0.
  • ts_clk_pol: TS clk polarity.Default: 0. 1-active at falling edge; 0-active at rising edge.
  • spec_inv: Spectrum inversion. Default: 0.
  • agc_inv: AGC polarity. Default: 0.
  • clock_out: Clock output, as defined by enum m88ds3103_clock_out. Default: M88DS3103_CLOCK_OUT_DISABLED.
  • envelope_mode: DiSEqC envelope mode. Default: 0.
  • agc: AGC configuration. Default: none, must set.
  • lnb_hv_pol: LNB H/V pin polarity. Default: 0. Values: 1: pin high set to VOLTAGE_13, pin low to set VOLTAGE_18; 0: pin high set to VOLTAGE_18, pin low to set VOLTAGE_13.
  • lnb_en_pol: LNB enable pin polarity. Default: 0. Values: 1: pin high to enable, pin low to disable; 0: pin high to disable, pin low to enable.

m88ds3103_attach() #

struct dvb_frontend * m88ds3103_attach(const struct m88ds3103_config *config, struct i2c_adapter *i2c, struct i2c_adapter **tuner_i2c)

Attach a m88ds3103 demod

Parameters

  • const struct m88ds3103_config *config: pointer to struct m88ds3103_config with demod configuration.
  • struct i2c_adapter *i2c: i2c adapter to use.
  • struct i2c_adapter **tuner_i2c: on success, returns the I2C adapter associated with m88ds3103 tuner.

Return

FE pointer on success, NULL on failure.

Note

Do not add new m88ds3103_attach() users! Use I2C bindings instead.

struct mb86a20s_config #

Define the per-device attributes of the frontend

Definition

struct mb86a20s_config {
    u32 fclk;
    u8 demod_address;
    bool is_serial;
};

Members

  • fclk: Clock frequency. If zero, assumes the default (32.57142 Mhz)
  • demod_address: the demodulator's i2c address
  • is_serial: if true, TS is serial. Otherwise, TS is parallel

mb86a20s_attach() #

struct dvb_frontend * mb86a20s_attach(const struct mb86a20s_config *config, struct i2c_adapter *i2c)

Attach a mb86a20s demod

Parameters

  • const struct mb86a20s_config *config: pointer to struct mb86a20s_config with demod configuration.
  • struct i2c_adapter *i2c: i2c adapter to use.

Return

FE pointer on success, NULL on failure.

struct mn88472_config #

Platform data for the mn88472 driver

Definition

struct mn88472_config {
        unsigned int xtal;
    #define MN88472_TS_MODE_SERIAL      0;
    #define MN88472_TS_MODE_PARALLEL    1;
        int ts_mode;
    #define MN88472_TS_CLK_FIXED        0;
    #define MN88472_TS_CLK_VARIABLE     1;
        int ts_clock;
        u16 i2c_wr_max;
        struct dvb_frontend **fe;
        struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *);
};

Members

  • xtal: Clock frequency.
  • ts_mode: TS mode.
  • ts_clock: TS clock config.
  • i2c_wr_max: Max number of bytes driver writes to I2C at once.
  • fe: pointer to a frontend pointer
  • get_dvb_frontend: Get DVB frontend callback.

struct rtl2830_platform_data #

Platform data for the rtl2830 driver

Definition

struct rtl2830_platform_data {
    u32 clk;
    bool spec_inv;
    u8 vtop;
    u8 krf;
    u8 agc_targ_val;
    struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *);
    struct i2c_adapter* (*get_i2c_adapter)(struct i2c_client *);
    int (*pid_filter)(struct dvb_frontend *, u8, u16, int);
    int (*pid_filter_ctrl)(struct dvb_frontend *, int);
};

Members

  • clk: Clock frequency (4000000, 16000000, 25000000, 28800000).
  • spec_inv: Spectrum inversion.
  • vtop: AGC take-over point.
  • krf: AGC ratio.
  • agc_targ_val: AGC.
  • get_dvb_frontend: Get DVB frontend.
  • get_i2c_adapter: Get I2C adapter.
  • pid_filter: Set PID to PID filter.
  • pid_filter_ctrl: Control PID filter.

struct rtl2832_platform_data #

Platform data for the rtl2832 driver

Definition

struct rtl2832_platform_data {
        u32 clk;
    #define RTL2832_TUNER_FC2580    0x21;
    #define RTL2832_TUNER_TUA9001   0x24;
    #define RTL2832_TUNER_FC0012    0x26;
    #define RTL2832_TUNER_E4000     0x27;
    #define RTL2832_TUNER_FC0013    0x29;
    #define RTL2832_TUNER_R820T     0x2a;
    #define RTL2832_TUNER_R828D     0x2b;
    #define RTL2832_TUNER_SI2157    0x2c;
        u8 tuner;
        struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *);
        struct i2c_adapter* (*get_i2c_adapter)(struct i2c_client *);
        int (*slave_ts_ctrl)(struct i2c_client *, bool);
        int (*pid_filter)(struct dvb_frontend *, u8, u16, int);
        int (*pid_filter_ctrl)(struct dvb_frontend *, int);
};

Members

  • clk: Clock frequency (4000000, 16000000, 25000000, 28800000).
  • tuner: Used tuner model.
  • get_dvb_frontend: Get DVB frontend.
  • get_i2c_adapter: Get I2C adapter.
  • slave_ts_ctrl: Control slave TS interface.
  • pid_filter: Set PID to PID filter.
  • pid_filter_ctrl: Control PID filter.

struct rtl2832_sdr_platform_data #

Platform data for the rtl2832_sdr driver

Definition

struct rtl2832_sdr_platform_data {
        u32 clk;
    #define RTL2832_SDR_TUNER_FC2580    0x21;
    #define RTL2832_SDR_TUNER_TUA9001   0x24;
    #define RTL2832_SDR_TUNER_FC0012    0x26;
    #define RTL2832_SDR_TUNER_E4000     0x27;
    #define RTL2832_SDR_TUNER_FC0013    0x29;
    #define RTL2832_SDR_TUNER_R820T     0x2a;
    #define RTL2832_SDR_TUNER_R828D     0x2b;
        u8 tuner;
        struct regmap *regmap;
        struct dvb_frontend *dvb_frontend;
        struct v4l2_subdev *v4l2_subdev;
        struct dvb_usb_device *dvb_usb_device;
};

Members

  • clk: Clock frequency (4000000, 16000000, 25000000, 28800000).
  • tuner: Used tuner model.
  • regmap: pointer to struct regmap.
  • dvb_frontend: rtl2832 DVB frontend.
  • v4l2_subdev: Tuner v4l2 controls.
  • dvb_usb_device: DVB USB interface for USB streaming.

stb6000_attach() #

struct dvb_frontend * stb6000_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c)

Attach a stb6000 tuner to the supplied frontend structure.

Parameters

  • struct dvb_frontend *fe: Frontend to attach to.
  • int addr: i2c address of the tuner.
  • struct i2c_adapter *i2c: i2c adapter to use.

Return

FE pointer on success, NULL on failure.

struct tda10071_platform_data #

Platform data for the tda10071 driver

Definition

struct tda10071_platform_data {
        u32 clk;
        u16 i2c_wr_max;
    #define TDA10071_TS_SERIAL        0;
    #define TDA10071_TS_PARALLEL      1;
        u8 ts_mode;
        bool spec_inv;
        u8 pll_multiplier;
        u8 tuner_i2c_addr;
        struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *);
};

Members

  • clk: Clock frequency.
  • i2c_wr_max: Max bytes I2C adapter can write at once.
  • ts_mode: TS mode.
  • spec_inv: Input spectrum inversion.
  • pll_multiplier: PLL multiplier.
  • tuner_i2c_addr: CX24118A tuner I2C address (0x14, 0x54, ...).
  • get_dvb_frontend: Get DVB frontend.

tda826x_attach() #

struct dvb_frontend* tda826x_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c, int has_loopthrough)

Attach a tda826x tuner to the supplied frontend structure.

Parameters

  • struct dvb_frontend *fe: Frontend to attach to.
  • int addr: i2c address of the tuner.
  • struct i2c_adapter *i2c: i2c adapter to use.
  • int has_loopthrough: Set to 1 if the card has a loopthrough RF connector.

Return

FE pointer on success, NULL on failure.

struct zd1301_demod_platform_data #

Platform data for the zd1301_demod driver

Definition

struct zd1301_demod_platform_data {
    void *reg_priv;
    int (*reg_read)(void *, u16, u8 *);
    int (*reg_write)(void *, u16, u8);
};

Members

  • reg_priv: First argument of reg_read and reg_write callbacks.
  • reg_read: Register read callback.
  • reg_write: Register write callback.

zd1301_demod_get_dvb_frontend() #

struct dvb_frontend * zd1301_demod_get_dvb_frontend(struct platform_device *pdev)

Get pointer to DVB frontend

Parameters

  • struct platform_device *pdev: Pointer to platform device

Return

Pointer to DVB frontend which given platform device owns.

zd1301_demod_get_i2c_adapter() #

struct i2c_adapter * zd1301_demod_get_i2c_adapter(struct platform_device *pdev)

Get pointer to I2C adapter

Parameters

  • struct platform_device *pdev: Pointer to platform device

Return

Pointer to I2C adapter which given platform device owns.

zl10036_attach() #

struct dvb_frontend * zl10036_attach(struct dvb_frontend *fe, const struct zl10036_config *config, struct i2c_adapter *i2c)

Attach a zl10036 tuner to the supplied frontend structure.

Parameters

  • struct dvb_frontend *fe: Frontend to attach to.
  • const struct zl10036_config *config: zl10036_config structure.
  • struct i2c_adapter *i2c: pointer to struct i2c_adapter.

Return

FE pointer on success, NULL on failure.

Intel IPU6 Driver

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

Author: Bingbu Cao <bingbu.cao@intel.com>

Overview #

Intel IPU6 is the sixth generation of Intel Image Processing Unit used in some Intel Chipsets such as Tiger Lake, Jasper Lake, Alder Lake, Raptor Lake and Meteor Lake. IPU6 consists of two major systems: Input System (ISYS) and Processing System (PSYS). IPU6 are visible on the PCI bus as a single device, it can be found by lspci:

0000:00:05.0 Multimedia controller: Intel Corporation Device xxxx (rev xx)

IPU6 has a 16 MB BAR in PCI configuration Space for MMIO registers which is visible for driver.

Buttress #

The IPU6 is connecting to the system fabric with Buttress which is enabling host driver to control the IPU6, it also allows IPU6 access the system memory to store and load frame pixel streams and any other metadata.

Buttress mainly manages several system functionalities: power management, interrupt handling, firmware authentication and global timer sync.

ISYS and PSYS Power flow #

IPU6 driver initialize the ISYS and PSYS power up or down request by setting the Buttress frequency control register for ISYS and PSYS (IPU6_BUTTRESS_REG_IS_FREQ_CTL and IPU6_BUTTRESS_REG_PS_FREQ_CTL) in function:

int ipu6_buttress_power(...)

Buttress forwards the request to Punit, after Punit execute the power up flow, Buttress indicates driver that ISYS or PSYS is powered up by updating the power status registers.

Note

ISYS power up needs take place prior to PSYS power up, ISYS power down needs take place after PSYS power down due to hardware limitation.

Interrupt #

IPU6 interrupt can be generated as MSI or INTA, interrupt will be triggered when ISYS, PSYS, Buttress event or error happen, driver can get the interrupt cause by reading the interrupt status register BUTTRESS_REG_ISR_STATUS, driver clears the irq status and then calls specific ISYS or PSYS irq handler.

irqreturn_t ipu6_buttress_isr(int irq, ...)

Security and firmware authentication #

To address the IPU6 firmware security concerns, the IPU6 firmware needs to undergo an authentication process before it is allowed to executed on the IPU6 internal processors. The IPU6 driver will work with Converged Security Engine (CSE) to complete authentication process. The CSE is responsible of authenticating the IPU6 firmware. The authenticated firmware binary is copied into an isolated memory region. Firmware authentication process is implemented by CSE following an IPC handshake with the IPU6 driver. There are some Buttress registers used by the CSE and the IPU6 driver to communicate with each other via IPC.

int ipu6_buttress_authenticate(...)

Global timer sync #

The IPU6 driver initiates a Hammock Harbor synchronization flow each time it starts camera operation. The IPU6 will synchronizes an internal counter in the Buttress with a copy of the SoC time, this counter maintains the up-to-date time until camera operation is stopped. The IPU6 driver can use this time counter to calibrate the timestamp based on the timestamp in response event from firmware.

int ipu6_buttress_start_tsc_sync(...)

DMA and MMU #

The IPU6 has its own scalar processor where the firmware run at and an internal 32-bit virtual address space. The IPU6 has MMU address translation hardware to allow that scalar processors to access the internal memory and external system memory through IPU6 virtual address. The address translation is based on two levels of page lookup tables stored in system memory which are maintained by the IPU6 driver. The IPU6 driver sets the level-1 page table base address to MMU register and allows MMU to perform page table lookups.

The IPU6 driver exports its own DMA operations. The IPU6 driver will update the page table entries for each DMA operation and invalidate the MMU TLB after each unmap and free.

Firmware file format #

The IPU6 firmware is in Code Partition Directory (CPD) file format. The CPD firmware contains a CPD header, several CPD entries and components. The CPD component includes 3 entries - manifest, metadata and module data. Manifest and metadata are defined by CSE and used by CSE for authentication. Module data is specific to IPU6 which holds the binary data of firmware called package directory. The IPU6 driver (ipu6-cpd.c in particular) parses and validates the CPD firmware file and gets the package directory binary data of the IPU6 firmware, copies it to specific DMA buffer and sets its base address to Buttress FW_SOURCE_BASE register. Finally the CSE will do authentication for this firmware binary.

Syscom interface #

The IPU6 driver communicates with firmware via the Syscom ABI. Syscom is an inter-processor communication mechanism between the IPU scalar processors and the CPU. There are a number of resources shared between firmware and software. A system memory region where the message queues reside, firmware can access the memory region via the IPU MMU. The Syscom queues are FIFO fixed depth queues with a configurable number of tokens (messages). There are also common IPU6 MMIO registers where the queue read and write indices reside. Software and firmware function as producer and consumer of tokens in the queues and update the write and read indices separately when sending or receiving each message.

The IPU6 driver must prepare and configure the number of input and output queues, configure the count of tokens per queue and the size of per token before initiating and starting the communication with firmware. Firmware and software must use same configurations. The IPU6 Buttress has a number of firmware boot parameter registers which can be used to store the address of configuration and initialise the Syscom state, then driver can request firmware to start and run via setting the scalar processor control status register.

Input System #

IPU6 input system consists of MIPI D-PHY and several CSI-2 receivers. It can capture image pixel data from camera sensors or other MIPI CSI-2 output devices.

D-PHYs and CSI-2 ports lane mapping #

The IPU6 integrates different D-PHY IPs on different SoCs, on Tiger Lake and Alder Lake, IPU6 integrates MCD10 D-PHY, IPU6SE on Jasper Lake integrates JSL D-PHY and IPU6EP on Meteor Lake integrates a Synopsys DWC D-PHY. There is an adaptional layer between D-PHY and CSI-2 receiver controller which includes port configuration, PHY wrapper or private test interfaces for D-PHY. There are 3 D-PHY drivers ipu6-isys-mcd-phy.c, ipu6-isys-jsl-phy.c and ipu6-isys-dwc-phy.c program the above 3 D-PHYs in IPU6.

Different IPU6 versions have different D-PHY lanes mappings, On Tiger Lake, there are 12 data lanes and 8 clock lanes, IPU6 support maximum 8 CSI-2 ports, see the PPI mmapping in ipu6-isys-mcd-phy.c for more information. On Jasper Lake and Alder Lake, D-PHY has 8 data lanes and 4 clock lanes, the IPU6 supports maximum 4 CSI-2 ports. For Meteor Lake, D-PHY has 12 data lanes and 6 clock lanes so IPU6 support maximum 6 CSI-2 ports.

Note

Each pair of CSI-2 two ports is a single unit that can share the data lanes. For example, for CSI-2 port 0 and 1, CSI-2 port 0 support maximum 4 data lanes, CSI-2 port 1 support maximum 2 data lanes, CSI-2 port 0 with 2 data lanes can work together with CSI-2 port 1 with 2 data lanes. If trying to use CSI-2 port 0 with 4 lanes, CSI-2 port 1 will not be available as the 4 data lanes are shared by CSI-2 port 0 and 1. The same applies to CSI ports 2/3, 4/5 and 7/8.

ISYS firmware ABIs #

The IPU6 firmware implements a series of ABIs for software access. In general, software firstly prepares the stream configuration struct ipu6_fw_isys_stream_cfg_data_abi and sends the configuration to firmware via sending STREAM_OPEN command. Stream configuration includes input pins and output pins, input pin struct ipu6_fw_isys_input_pin_info_abi defines the resolution and data type of input source, output pin struct ipu6_fw_isys_output_pin_info_abi defines the output resolution, stride and frame format, etc.

Once the driver gets the interrupt from firmware that indicates stream open successfully, the driver will send the STREAM_START and STREAM_CAPTURE command to request firmware to start capturing image frames. STREAM_CAPTURE command queues the buffers to firmware with struct ipu6_fw_isys_frame_buff_set, software then waits for the interrupt and response from firmware, PIN_DATA_READY means a buffer is ready on a specific output pin and then software can return the buffer to user.

Note

See Examples about how to do capture by IPU6 ISYS driver.

The pvrusb2 driver

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

Author: Mike Isely <isely@pobox.com>

Background #

This driver is intended for the "Hauppauge WinTV PVR USB 2.0", which is a USB 2.0 hosted TV Tuner. This driver is a work in progress. Its history started with the reverse-engineering effort by Björn Danielsson <pvrusb2@dax.nu> whose web page can be found here: http://pvrusb2.dax.nu/

From there Aurelien Alleaume <slts@free.fr> began an effort to create a video4linux compatible driver. I began with Aurelien's last known snapshot and evolved the driver to the state it is in here.

More information on this driver can be found at: https://www.isely.net/pvrusb2.html

This driver has a strong separation of layers. They are very roughly:

  1. Low level wire-protocol implementation with the device.

  2. I2C adaptor implementation and corresponding I2C client drivers implemented elsewhere in V4L.

  3. High level hardware driver implementation which coordinates all activities that ensure correct operation of the device.

  4. A "context" layer which manages instancing of driver, setup, tear-down, arbitration, and interaction with high level interfaces appropriately as devices are hotplugged in the system.

  5. High level interfaces which glue the driver to various published Linux APIs (V4L, sysfs, maybe DVB in the future).

The most important shearing layer is between the top 2 layers. A lot of work went into the driver to ensure that any kind of conceivable API can be laid on top of the core driver. (Yes, the driver internally leverages V4L to do its work but that really has nothing to do with the API published by the driver to the outside world.) The architecture allows for different APIs to simultaneously access the driver. I have a strong sense of fairness about APIs and also feel that it is a good design principle to keep implementation and interface isolated from each other. Thus while right now the V4L high level interface is the most complete, the sysfs high level interface will work equally well for similar functions, and there's no reason I see right now why it shouldn't be possible to produce a DVB high level interface that can sit right alongside V4L.

Building #

To build these modules essentially amounts to just running "Make", but you need the kernel source tree nearby and you will likely also want to set a few controlling environment variables first in order to link things up with that source tree. Please see the Makefile here for comments that explain how to do that.

Source file list / functional overview #

(Note: The term "module" used below generally refers to loosely defined functional units within the pvrusb2 driver and bears no relation to the Linux kernel's concept of a loadable module.)

  • pvrusb2-audio.[ch] - This is glue logic that resides between this

    driver and the msp3400.ko I2C client driver (which is found elsewhere in V4L).

  • pvrusb2-context.[ch] - This module implements the context for an

    instance of the driver. Everything else eventually ties back to or is otherwise instanced within the data structures implemented here. Hotplugging is ultimately coordinated here. All high level interfaces tie into the driver through this module. This module helps arbitrate each interface's access to the actual driver core, and is designed to allow concurrent access through multiple instances of multiple interfaces (thus you can for example change the tuner's frequency through sysfs while simultaneously streaming video through V4L out to an instance of mplayer).

  • pvrusb2-debug.h - This header defines a printk() wrapper and a mask

    of debugging bit definitions for the various kinds of debug messages that can be enabled within the driver.

  • pvrusb2-debugifc.[ch] - This module implements a crude command line

    oriented debug interface into the driver. Aside from being part of the process for implementing manual firmware extraction (see the pvrusb2 web site mentioned earlier), probably I'm the only one who has ever used this. It is mainly a debugging aid.

  • pvrusb2-eeprom.[ch] - This is glue logic that resides between this

    driver the tveeprom.ko module, which is itself implemented elsewhere in V4L.

  • pvrusb2-encoder.[ch] - This module implements all protocol needed to

    interact with the Conexant mpeg2 encoder chip within the pvrusb2 device. It is a crude echo of corresponding logic in ivtv, however the design goals (strict isolation) and physical layer (proxy through USB instead of PCI) are enough different that this implementation had to be completely different.

  • pvrusb2-hdw-internal.h - This header defines the core data structure

    in the driver used to track ALL internal state related to control of the hardware. Nobody outside of the core hardware-handling modules should have any business using this header. All external access to the driver should be through one of the high level interfaces (e.g. V4L, sysfs, etc), and in fact even those high level interfaces are restricted to the API defined in pvrusb2-hdw.h and NOT this header.

  • pvrusb2-hdw.h - This header defines the full internal API for

    controlling the hardware. High level interfaces (e.g. V4L, sysfs) will work through here.

  • pvrusb2-hdw.c - This module implements all the various bits of logic

    that handle overall control of a specific pvrusb2 device. (Policy, instantiation, and arbitration of pvrusb2 devices fall within the jurisdiction of pvrusb-context not here).

  • pvrusb2-i2c-chips-*.c - These modules implement the glue logic to

    tie together and configure various I2C modules as they attach to the I2C bus. There are two versions of this file. The "v4l2" version is intended to be used in-tree alongside V4L, where we implement just the logic that makes sense for a pure V4L environment. The "all" version is intended for use outside of V4L, where we might encounter other possibly "challenging" modules from ivtv or older kernel snapshots (or even the support modules in the standalone snapshot).

  • pvrusb2-i2c-cmd-v4l1.[ch] - This module implements generic V4L1

    compatible commands to the I2C modules. It is here where state changes inside the pvrusb2 driver are translated into V4L1 commands that are in turn send to the various I2C modules.

  • pvrusb2-i2c-cmd-v4l2.[ch] - This module implements generic V4L2

    compatible commands to the I2C modules. It is here where state changes inside the pvrusb2 driver are translated into V4L2 commands that are in turn send to the various I2C modules.

  • pvrusb2-i2c-core.[ch] - This module provides an implementation of a

    kernel-friendly I2C adaptor driver, through which other external I2C client drivers (e.g. msp3400, tuner, lirc) may connect and operate corresponding chips within the pvrusb2 device. It is through here that other V4L modules can reach into this driver to operate specific pieces (and those modules are in turn driven by glue logic which is coordinated by pvrusb2-hdw, doled out by pvrusb2-context, and then ultimately made available to users through one of the high level interfaces).

  • pvrusb2-io.[ch] - This module implements a very low level ring of

    transfer buffers, required in order to stream data from the device. This module is very low level. It only operates the buffers and makes no attempt to define any policy or mechanism for how such buffers might be used.

  • pvrusb2-ioread.[ch] - This module layers on top of pvrusb2-io.[ch]

    to provide a streaming API usable by a read() system call style of I/O. Right now this is the only layer on top of pvrusb2-io.[ch], however the underlying architecture here was intended to allow for other styles of I/O to be implemented with additional modules, like mmap()'ed buffers or something even more exotic.

  • pvrusb2-main.c - This is the top level of the driver. Module level

    and USB core entry points are here. This is our "main".

  • pvrusb2-sysfs.[ch] - This is the high level interface which ties the

    pvrusb2 driver into sysfs. Through this interface you can do everything with the driver except actually stream data.

  • pvrusb2-tuner.[ch] - This is glue logic that resides between this

    driver and the tuner.ko I2C client driver (which is found elsewhere in V4L).

  • pvrusb2-util.h - This header defines some common macros used

    throughout the driver. These macros are not really specific to the driver, but they had to go somewhere.

  • pvrusb2-v4l2.[ch] - This is the high level interface which ties the

    pvrusb2 driver into video4linux. It is through here that V4L applications can open and operate the driver in the usual V4L ways. Note that ALL V4L functionality is published only through here and nowhere else.

  • pvrusb2-video-*.[ch] - This is glue logic that resides between this

    driver and the saa711x.ko I2C client driver (which is found elsewhere in V4L). Note that saa711x.ko used to be known as saa7115.ko in ivtv. There are two versions of this; one is selected depending on the particular saa711[5x].ko that is found.

  • pvrusb2.h - This header contains compile time tunable parameters

    (and at the moment the driver has very little that needs to be tuned).

PXA-Camera Host Driver

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

Author: Robert Jarzmik <robert.jarzmik@free.fr>

Constraints #

  • a) Image size for YUV422P format All YUV422P images are enforced to have width x height % 16 = 0. This is due to DMA constraints, which transfers only planes of 8 byte multiples.

Global video workflow #

  • a) QCI stopped Initially, the QCI interface is stopped. When a buffer is queued, start_streaming is called and the QCI starts.

  • b) QCI started More buffers can be queued while the QCI is started without halting the capture. The new buffers are "appended" at the tail of the DMA chain, and smoothly captured one frame after the other.

    Once a buffer is filled in the QCI interface, it is marked as "DONE" and removed from the active buffers list. It can be then requeud or dequeued by userland application.

    Once the last buffer is filled in, the QCI interface stops.

  • c) Capture global finite state machine schema

+----+                             +---+  +----+
| DQ |                             | Q |  | DQ |
|    v                             |   v  |    v
+-----------+                     +------------------------+
|   STOP    |                     | Wait for capture start |
+-----------+         Q           +------------------------+
+-> | QCI: stop | ------------------> | QCI: run               | <------------+
|   | DMA: stop |                     | DMA: stop              |              |
|   +-----------+             +-----> +------------------------+              |
|                            /                            |                   |
|                           /             +---+  +----+   |                   |
|capture list empty        /              | Q |  | DQ |   | QCI Irq EOF       |
|                         /               |   v  |    v   v                   |
|   +--------------------+             +----------------------+               |
|   | DMA hotlink missed |             |    Capture running   |               |
|   +--------------------+             +----------------------+               |
|   | QCI: run           |     +-----> | QCI: run             | <-+           |
|   | DMA: stop          |    /        | DMA: run             |   |           |
|   +--------------------+   /         +----------------------+   | Other     |
|     ^                     /DMA still            |               | channels  |
|     | capture list       /  running             | DMA Irq End   | not       |
|     | not empty         /                       |               | finished  |
|     |                  /                        v               | yet       |
|   +----------------------+           +----------------------+   |           |
|   |  Videobuf released   |           |  Channel completed   |   |           |
|   +----------------------+           +----------------------+   |           |
+-- | QCI: run             |           | QCI: run             | --+           |
| DMA: run             |           | DMA: run             |               |
+----------------------+           +----------------------+               |
        ^                      /           |                           |
        |          no overrun /            | overrun                   |
        |                    /             v                           |
+--------------------+         /   +----------------------+               |
|  Frame completed   |        /    |     Frame overran    |               |
+--------------------+ <-----+     +----------------------+ restart frame |
| QCI: run           |             | QCI: stop            | --------------+
| DMA: run           |             | DMA: stop            |
+--------------------+             +----------------------+

Legend: - each box is a FSM state
        - each arrow is the condition to transition to another state
        - an arrow with a comment is a mandatory transition (no condition)
        - arrow "Q" means : a buffer was enqueued
        - arrow "DQ" means : a buffer was dequeued
        - "QCI: stop" means the QCI interface is not enabled
        - "DMA: stop" means all 3 DMA channels are stopped
        - "DMA: run" means at least 1 DMA channel is still running

DMA usage #

  • a) - DMA flow

    • first buffer queued for capture Once a first buffer is queued for capture, the QCI is started, but data transfer is not started. On "End Of Frame" interrupt, the irq handler starts the DMA chain.

    • capture of one videobuffer The DMA chain starts transferring data into videobuffer RAM pages. When all pages are transferred, the DMA irq is raised on "ENDINTR" status

    • finishing one videobuffer The DMA irq handler marks the videobuffer as "done", and removes it from the active running queue Meanwhile, the next videobuffer (if there is one), is transferred by DMA

    • finishing the last videobuffer On the DMA irq of the last videobuffer, the QCI is stopped.

  • b) DMA prepared buffer will have this structure

+------------+-----+---------------+-----------------+
| desc-sg[0] | ... | desc-sg[last] | finisher/linker |
+------------+-----+---------------+-----------------+

This structure is pointed by dma->sg_cpu. The descriptors are used as follows:

  • desc-sg[i]: i-th descriptor, transferring the i-th sg element to the video buffer scatter gather

  • finisher: has ddadr=DADDR_STOP, dcmd=ENDIRQEN

  • linker: has ddadr= desc-sg[0] of next video buffer, dcmd=0

For the next schema, let's assume d0=desc-sg[0] .. dN=desc-sg[N], "f" stands for finisher and "l" for linker. A typical running chain is :

    Videobuffer 1         Videobuffer 2
+---------+----+---+  +----+----+----+---+
| d0 | .. | dN | l |  | d0 | .. | dN | f |
+---------+----+-|-+  ^----+----+----+---+
                 |    |
                 +----+

After the chaining is finished, the chain looks like :

    Videobuffer 1         Videobuffer 2         Videobuffer 3
+---------+----+---+  +----+----+----+---+  +----+----+----+---+
| d0 | .. | dN | l |  | d0 | .. | dN | l |  | d0 | .. | dN | f |
+---------+----+-|-+  ^----+----+----+-|-+  ^----+----+----+---+
                 |    |                |    |
                 +----+                +----+
                                      new_link
  • c) DMA hot chaining timeslice issue

As DMA chaining is done while DMA _is_ running, the linking may be done while the DMA jumps from one Videobuffer to another. On the schema, that would be a problem if the following sequence is encountered :

  • DMA chain is Videobuffer1 + Videobuffer2

  • pxa_videobuf_queue() is called to queue Videobuffer3

  • DMA controller finishes Videobuffer2, and DMA stops

 =>
    Videobuffer 1         Videobuffer 2
+---------+----+---+  +----+----+----+---+
| d0 | .. | dN | l |  | d0 | .. | dN | f |
+---------+----+-|-+  ^----+----+----+-^-+
                 |    |                |
                 +----+                +-- DMA DDADR loads DDADR_STOP
  • pxa_dma_add_tail_buf() is called, the Videobuffer2 "finisher" is replaced by a "linker" to Videobuffer3 (creation of new_link)

  • pxa_videobuf_queue() finishes

  • the DMA irq handler is called, which terminates Videobuffer2

  • Videobuffer3 capture is not scheduled on DMA chain (as it stopped !!!)

    Videobuffer 1         Videobuffer 2         Videobuffer 3
+---------+----+---+  +----+----+----+---+  +----+----+----+---+
| d0 | .. | dN | l |  | d0 | .. | dN | l |  | d0 | .. | dN | f |
+---------+----+-|-+  ^----+----+----+-|-+  ^----+----+----+---+
                 |    |                |    |
                 +----+                +----+
                                      new_link
                                     DMA DDADR still is DDADR_STOP
  • pxa_camera_check_link_miss() is called This checks if the DMA is finished and a buffer is still on the pcdev->capture list. If that's the case, the capture will be restarted, and Videobuffer3 is scheduled on DMA chain.

  • the DMA irq handler finishes

Note

If DMA stops just after pxa_camera_check_link_miss() reads DDADR() value, we have the guarantee that the DMA irq handler will be called back when the DMA will finish the buffer, and pxa_camera_check_link_miss() will be called again, to reschedule Videobuffer3.

The Radiotrack radio driver

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

Author: Stephen M. Benoit <benoits@servicepro.com>

Date: Dec 14, 1996

ACKNOWLEDGMENTS #

This document was made based on 'C' code for Linux from Gideon le Grange (legrang@active.co.za or legrang@cs.sun.ac.za) in 1994, and elaborations from Frans Brinkman (brinkman@esd.nl) in 1996. The results reported here are from experiments that the author performed on his own setup, so your mileage may vary... I make no guarantees, claims or warranties to the suitability or validity of this information. No other documentation on the AIMS Lab (http://www.aimslab.com/) RadioTrack card was made available to the author. This document is offered in the hopes that it might help users who want to use the RadioTrack card in an environment other than MS Windows.

WHY THIS DOCUMENT? #

I have a RadioTrack card from back when I ran an MS-Windows platform. After converting to Linux, I found Gideon le Grange's command-line software for running the card, and found that it was good! Frans Brinkman made a comfortable X-windows interface, and added a scanning feature. For hack value, I wanted to see if the tuner could be tuned beyond the usual FM radio broadcast band, so I could pick up the audio carriers from North American broadcast TV channels, situated just below and above the 87.0-109.0 MHz range. I did not get much success, but I learned about programming ioports under Linux and gained some insights about the hardware design used for the card.

So, without further delay, here are the details.

PHYSICAL DESCRIPTION #

The RadioTrack card is an ISA 8-bit FM radio card. The radio frequency (RF) input is simply an antenna lead, and the output is a power audio signal available through a miniature phone plug. Its RF frequencies of operation are more or less limited from 87.0 to 109.0 MHz (the commercial FM broadcast band). Although the registers can be programmed to request frequencies beyond these limits, experiments did not give promising results. The variable frequency oscillator (VFO) that demodulates the intermediate frequency (IF) signal probably has a small range of useful frequencies, and wraps around or gets clipped beyond the limits mentioned above.

CONTROLLING THE CARD WITH IOPORT #

The RadioTrack (base) ioport is configurable for 0x30c or 0x20c. Only one ioport seems to be involved. The ioport decoding circuitry must be pretty simple, as individual ioport bits are directly matched to specific functions (or blocks) of the radio card. This way, many functions can be changed in parallel with one write to the ioport. The only feedback available through the ioports appears to be the "Stereo Detect" bit.

The bits of the ioport are arranged as follows:

MSb                                                         LSb
+------+------+------+--------+--------+-------+---------+--------+
| VolA | VolB | ???? | Stereo | Radio  | TuneA | TuneB   | Tune   |
|  (+) |  (-) |      | Detect | Audio  | (bit) | (latch) | Update |
|      |      |      | Enable | Enable |       |         | Enable |
+------+------+------+--------+--------+-------+---------+--------+

VolA

VolB

Description

0

0

audio mute

0

1

volume + (some delay required)

1

0

volume - (some delay required)

1

1

stay at present volume

Stereo Detect Enable

Description

0

No Detect

1

Detect

Results available by reading ioport >60 msec after last port write.

0xff ==> no stereo detected, 0xfd ==> stereo detected.

Radio to Audio (path) Enable

Description

0

Disable path (silence)

1

Enable path (audio produced)

TuneA

TuneB

Description

0

0

"zero" bit phase 1

0

1

"zero" bit phase 2

1

0

"one" bit phase 1

1

1

"one" bit phase 2

24-bit code, where bits = (freq*40) + 10486188. The Most Significant 11 bits must be 1010 xxxx 0x0 to be valid. The bits are shifted in LSb first.

Tune Update Enable

Description

0

Tuner held constant

1

Tuner updating in progress

PROGRAMMING EXAMPLES #

Default:        BASE <-- 0xc8  (current volume, no stereo detect,
                                radio enable, tuner adjust disable)

Card Off:       BASE <-- 0x00  (audio mute, no stereo detect,
                                radio disable, tuner adjust disable)

Card On:        BASE <-- 0x00  (see "Card Off", clears any unfinished business)
                BASE <-- 0xc8  (see "Default")

Volume Down:    BASE <-- 0x48  (volume down, no stereo detect,
                                radio enable, tuner adjust disable)
                wait 10 msec
                BASE <-- 0xc8  (see "Default")

Volume Up:      BASE <-- 0x88  (volume up, no stereo detect,
                                radio enable, tuner adjust disable)
                wait 10 msec
                BASE <-- 0xc8  (see "Default")

Check Stereo:   BASE <-- 0xd8  (current volume, stereo detect,
                                radio enable, tuner adjust disable)
                wait 100 msec
                x <-- BASE     (read ioport)
                BASE <-- 0xc8  (see "Default")

                x=0xff ==> "not stereo", x=0xfd ==> "stereo detected"

Set Frequency:  code = (freq*40) + 10486188
                foreach of the 24 bits in code,
                (from Least to Most Significant):
                to write a "zero" bit,
                BASE <-- 0x01  (audio mute, no stereo detect, radio
                                disable, "zero" bit phase 1, tuner adjust)
                BASE <-- 0x03  (audio mute, no stereo detect, radio
                                disable, "zero" bit phase 2, tuner adjust)
                to write a "one" bit,
                BASE <-- 0x05  (audio mute, no stereo detect, radio
                                disable, "one" bit phase 1, tuner adjust)
                BASE <-- 0x07  (audio mute, no stereo detect, radio
                                disable, "one" bit phase 2, tuner adjust)

The Rockchip Image Signal Processor Driver (rkisp1)

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

Versions and their differences #

The rkisp1 block underwent some changes between SoC implementations. The vendor designates them as:

  • V10: used at least in rk3288 and rk3399

  • V11: declared in the original vendor code, but not used

  • V12: used at least in rk3326 and px30

  • V13: used at least in rk1808

  • V20: used in rk3568 and beyond

Right now the kernel supports rkisp1 implementations based on V10 and V12 variants. V11 does not seem to be actually used and V13 will need some more additions but isn't researched yet, especially as it seems to be limited to the rk1808 which hasn't reached much market spread.

V20 on the other hand will probably be used in future SoCs and has seen really big changes in the vendor kernel, so will need quite a bit of research.

Changes from V10 to V12 #

  • V12 supports a new CSI-host implementation but can still also use the same implementation from V10

  • The module for lens shading correction got changed from 12bit to 13bit width

  • The AWB and AEC modules got replaced to support finer grained data collection

Changes from V12 to V13 #

The list for V13 is incomplete and needs further investigation.

  • V13 does not support the old CSI-host implementation anymore

The saa7134 driver

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

Author Gerd Hoffmann

Card Variations: #

Cards can use either of these two crystals (xtal):

  • 32.11 MHz -> .audio_clock=0x187de7

  • 24.576MHz -> .audio_clock=0x200000 (xtal * .audio_clock = 51539600)

Some details about 30/34/35:

  • saa7130 - low-price chip, doesn't have mute, that is why all those cards should have .mute field defined in their tuner structure.

  • saa7134 - usual chip

  • saa7133/35 - saa7135 is probably a marketing decision, since all those chips identifies itself as 33 on pci.

LifeView GPIOs #

This section was authored by: Peter Missel <peter.missel@onlinehome.de>

  • LifeView FlyTV Platinum FM (LR214WF)

    • GP27 MDT2005 PB4 pin 10

    • GP26 MDT2005 PB3 pin 9

    • GP25 MDT2005 PB2 pin 8

    • GP23 MDT2005 PB1 pin 7

    • GP22 MDT2005 PB0 pin 6

    • GP21 MDT2005 PB5 pin 11

    • GP20 MDT2005 PB6 pin 12

    • GP19 MDT2005 PB7 pin 13

    • nc MDT2005 PA3 pin 2

    • Remote MDT2005 PA2 pin 1

    • GP18 MDT2005 PA1 pin 18

    • nc MDT2005 PA0 pin 17 strap low

    • GP17 Strap "GP7"=High

    • GP16 Strap "GP6"=High

      • 0=Radio 1=TV

      • Drives SA630D ENCH1 and HEF4052 A1 pinsto do FM radio through SIF input

    • GP15 nc

    • GP14 nc

    • GP13 nc

    • GP12 Strap "GP5" = High

    • GP11 Strap "GP4" = High

    • GP10 Strap "GP3" = High

    • GP09 Strap "GP2" = Low

    • GP08 Strap "GP1" = Low

    • GP07.00 nc

Credits #

andrew.stevens@philips.com + werner.leeb@philips.com for providing saa7134 hardware specs and sample board.

Cropping and Scaling algorithm, used in the sh_mobile_ceu_camera driver

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>

Terminology #

sensor scales: horizontal and vertical scales, configured by the sensor driver host scales: -"- host driver combined scales: sensor_scale * host_scale

Generic scaling / cropping scheme #

-1--
|
-2-- -\
|      --\
|         --\
+-5-- .      -- -3-- -\
|      `...            -\
|          `... -4-- .   - -7..
|                     `.
|                       `. .6--
|
|                        . .6'-
|                      .´
|           ... -4'- .´
|       ...´             - -7'.
+-5'- .´               -/
|            -- -3'- -/
|         --/
|      --/
-2'- -/
|
|
-1'-

In the above chart minuses and slashes represent "real" data amounts, points and accents represent "useful" data, basically, CEU scaled and cropped output, mapped back onto the client's source plane.

Such a configuration can be produced by user requests:

S_CROP(left / top = (5) - (1), width / height = (5') - (5)) S_FMT(width / height = (6') - (6))

Here:

(1) to (1') - whole max width or height (1) to (2) - sensor cropped left or top (2) to (2') - sensor cropped width or height (3) to (3') - sensor scale (3) to (4) - CEU cropped left or top (4) to (4') - CEU cropped width or height (5) to (5') - reverse sensor scale applied to CEU cropped width or height (2) to (5) - reverse sensor scale applied to CEU cropped left or top (6) to (6') - CEU scale - user window

S_FMT #

Do not touch input rectangle - it is already optimal.

  1. Calculate current sensor scales:

    scale_s = ((2') - (2)) / ((3') - (3))

2. Calculate "effective" input crop (sensor subwindow) - CEU crop scaled back at current sensor scales onto input window - this is user S_CROP:

width_u = (5') - (5) = ((4') - (4)) * scale_s

3. Calculate new combined scales from "effective" input window to requested user window:

scale_comb = width_u / ((6') - (6))

4. Calculate sensor output window by applying combined scales to real input window:

width_s_out = ((7') - (7)) = ((2') - (2)) / scale_comb

  1. Apply iterative sensor S_FMT for sensor output window.

    subdev->video_ops->s_fmt(.width = width_s_out)

  2. Retrieve sensor output window (g_fmt)

  3. Calculate new sensor scales:

    scale_s_new = ((3')_new - (3)_new) / ((2') - (2))

8. Calculate new CEU crop - apply sensor scales to previously calculated "effective" crop:

width_ceu = (4')_new - (4)_new = width_u / scale_s_new left_ceu = (4)_new - (3)_new = ((5) - (2)) / scale_s_new

  1. Use CEU cropping to crop to the new window:

    ceu_crop(.width = width_ceu, .left = left_ceu)

  2. Use CEU scaling to scale to the requested user window:

    scale_ceu = width_ceu / width

S_CROP #

The V4L2 crop API says:

"...specification does not define an origin or units. However by convention drivers should horizontally count unscaled samples relative to 0H."

We choose to follow the advise and interpret cropping units as client input pixels.

Cropping is performed in the following 6 steps:

  1. Request exactly user rectangle from the sensor.

  2. If smaller - iterate until a larger one is obtained. Result: sensor cropped to 2 : 2', target crop 5 : 5', current output format 6' - 6.

  3. In the previous step the sensor has tried to preserve its output frame as good as possible, but it could have changed. Retrieve it again.

  4. Sensor scaled to 3 : 3'. Sensor's scale is (2' - 2) / (3' - 3). Calculate intermediate window: 4' - 4 = (5' - 5) * (3' - 3) / (2' - 2)

  5. Calculate and apply host scale = (6' - 6) / (4' - 4)

  6. Calculate and apply host crop: 6 - 7 = (5 - 2) * (6' - 6) / (5' - 5)

Tuner drivers

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

Simple tuner Programming #

There are some flavors of Tuner programming APIs. These differ mainly by the bandswitch byte.

  • L= LG_API (VHF_LO=0x01, VHF_HI=0x02, UHF=0x08, radio=0x04)

  • P= PHILIPS_API (VHF_LO=0xA0, VHF_HI=0x90, UHF=0x30, radio=0x04)

  • T= TEMIC_API (VHF_LO=0x02, VHF_HI=0x04, UHF=0x01)

  • A= ALPS_API (VHF_LO=0x14, VHF_HI=0x12, UHF=0x11)

  • M= PHILIPS_MK3 (VHF_LO=0x01, VHF_HI=0x02, UHF=0x04, radio=0x19)

Tuner Manufacturers #

  • Samsung Tuner identification: (e.g. TCPM9091PD27)
TCP [ABCJLMNQ] 90[89][125] [DP] [ACD] 27 [ABCD]
[ABCJLMNQ]:
  A= BG+DK
  B= BG
  C= I+DK
  J= NTSC-Japan
  L= Secam LL
  M= BG+I+DK
  N= NTSC
  Q= BG+I+DK+LL
[89]: ?
[125]:
  2: No FM
  5: With FM
[DP]:
  D= NTSC
  P= PAL
[ACD]:
  A= F-connector
  C= Phono connector
  D= Din Jack
[ABCD]:
  3-wire/I2C tuning, 2-band/3-band

These Tuners are PHILIPS_API compatible.

Philips Tuner identification: (e.g. FM1216MF)

F[IRMQ]12[1345]6{MF|ME|MP}
F[IRMQ]:
 FI12x6: Tuner Series
 FR12x6: Tuner + Radio IF
 FM12x6: Tuner + FM
 FQ12x6: special
 FMR12x6: special
 TD15xx: Digital Tuner ATSC
12[1345]6:
 1216: PAL BG
 1236: NTSC
 1246: PAL I
 1256: Pal DK
{MF|ME|MP}
 MF: BG LL w/ Secam (Multi France)
 ME: BG DK I LL   (Multi Europe)
 MP: BG DK I      (Multi PAL)
 MR: BG DK M (?)
 MG: BG DKI M (?)
MK2 series PHILIPS_API, most tuners are compatible to this one !
MK3 series introduced in 2002 w/ PHILIPS_MK3_API

Temic Tuner identification: (.e.g 4006FH5)

 4[01][0136][269]F[HYNR]5
  40x2: Tuner (5V/33V), TEMIC_API.
  40x6: Tuner 5V
  41xx: Tuner compact
  40x9: Tuner+FM compact
 [0136]
  xx0x: PAL BG
  xx1x: Pal DK, Secam LL
  xx3x: NTSC
  xx6x: PAL I
 F[HYNR]5
  FH5: Pal BG
  FY5: others
  FN5: multistandard
  FR5: w/ FM radio
 3X xxxx: order number with specific connector
Note: Only 40x2 series has TEMIC_API, all newer tuners have PHILIPS_API.

LG Innotek Tuner:

  • TPI8NSR11 : NTSC J/M (TPI8NSR01 w/FM) (P,210/497)

  • TPI8PSB11 : PAL B/G (TPI8PSB01 w/FM) (P,170/450)

  • TAPC-I701 : PAL I (TAPC-I001 w/FM) (P,170/450)

  • TPI8PSB12 : PAL D/K+B/G (TPI8PSB02 w/FM) (P,170/450)

  • TAPC-H701P: NTSC_JP (TAPC-H001P w/FM) (L,170/450)

  • TAPC-G701P: PAL B/G (TAPC-G001P w/FM) (L,170/450)

  • TAPC-W701P: PAL I (TAPC-W001P w/FM) (L,170/450)

  • TAPC-Q703P: PAL D/K (TAPC-Q001P w/FM) (L,170/450)

  • TAPC-Q704P: PAL D/K+I (L,170/450)

  • TAPC-G702P: PAL D/K+B/G (L,170/450)

  • TADC-H002F: NTSC (L,175/410?; 2-B, C-W+11, W+12-69)

  • TADC-M201D: PAL D/K+B/G+I (L,143/425) (sound control at I2C address 0xc8)

  • TADC-T003F: NTSC Taiwan (L,175/410?; 2-B, C-W+11, W+12-69)

  • Suffix:

    • P= Standard phono female socket

    • D= IEC female socket

    • F= F-connector

Other Tuners:

  • TCL2002MB-1 : PAL BG + DK =TUNER_LG_PAL_NEW_TAPC

  • TCL2002MB-1F: PAL BG + DK w/FM =PHILIPS_PAL

  • TCL2002MI-2 : PAL I = ??

ALPS Tuners:

  • Most are LG_API compatible

  • TSCH6 has ALPS_API (TSCH5 ?)

  • TSBE1 has extra API 05,02,08 Control_byte=0xCB Source:1

[1] conexant100029b-PCI-Decoder-ApplicationNote.pdf

vidtv: Virtual Digital TV driver

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

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.

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.

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.

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.

    A good way to visualize the structure of streams is by using 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.

  • vidtv_channel.[ch]

    Implements a 'channel' abstraction.

    When vidtv boots, it will create some hardcoded channels:

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

    2. Their programs will be concatenated to populate the PAT

    3. Their events will be concatenated to populate the EIT

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

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

    6. 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:

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

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

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

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

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

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.

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.

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.

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.

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 that1:

$ 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. See also: zap.

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.

Functions and structs used within vidtv #

struct vidtv_dvb #

Vidtv bridge state

Definition

struct vidtv_dvb {
        struct platform_device *pdev;
        struct dvb_frontend *fe[NUM_FE];
        struct dvb_adapter adapter;
        struct dvb_demux demux;
        struct dmxdev dmx_dev;
        struct dmx_frontend dmx_fe[NUM_FE];
        struct i2c_adapter i2c_adapter;
        struct i2c_client *i2c_client_demod[NUM_FE];
        struct i2c_client *i2c_client_tuner[NUM_FE];
        u32 nfeeds;
        struct mutex feed_lock;
        bool streaming;
        struct vidtv_mux *mux;
    #ifdef CONFIG_MEDIA_CONTROLLER_DVB;
        struct media_device mdev;
    #endif;
};

Members

  • pdev: The platform device. Obtained when the bridge is probed.
  • fe: The frontends. Obtained when probing the demodulator modules.
  • adapter: Represents a DTV adapter. See 'dvb_register_adapter'.
  • demux: The demux used by the dvb_dmx_swfilter_packets() call.
  • dmx_dev: Represents a demux device.
  • dmx_fe: The frontends associated with the demux.
  • i2c_adapter: The i2c_adapter associated with the bridge driver.
  • i2c_client_demod: The i2c_clients associated with the demodulator modules.
  • i2c_client_tuner: The i2c_clients associated with the tuner modules.
  • nfeeds: The number of feeds active.
  • feed_lock: Protects access to the start/stop stream logic/data.
  • streaming: Whether we are streaming now.
  • mux: The abstraction responsible for delivering MPEG TS packets to the bridge.
  • mdev: The media_device struct for media controller support.

struct vidtv_channel #

A 'channel' abstraction

Definition

struct vidtv_channel {
    char *name;
    u16 transport_stream_id;
    struct vidtv_psi_table_sdt_service *service;
    u16 program_num;
    struct vidtv_psi_table_pat_program *program;
    struct vidtv_psi_table_pmt_stream *streams;
    struct vidtv_encoder *encoders;
    struct vidtv_psi_table_eit_event *events;
    struct vidtv_channel *next;
};

Members

  • name: name of the channel
  • transport_stream_id: a number to identify the TS, chosen at will.
  • service: A single service. Will be concatenated into the SDT.
  • program_num: The link between PAT, PMT and SDT.
  • program: A single program with one or more streams associated with it. Will be concatenated into the PAT.
  • streams: A stream loop used to populate the PMT section for 'program'
  • encoders: A encoder loop. There must be one encoder for each stream.
  • events: Optional event information. This will feed into the EIT.
  • next: Optionally chain this channel.

Description

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 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 to produce TS packets These packets may be interleaved by the mux and then delivered to the bridge

vidtv_channel_si_init() #

int vidtv_channel_si_init(struct vidtv_mux *m)

Init the PSI tables from the channels in the mux

Parameters

  • struct vidtv_mux *m: The mux containing the channels.

vidtv_channels_init() #

int vidtv_channels_init(struct vidtv_mux *m)

Init hardcoded, fake 'channels'.

Parameters

  • struct vidtv_mux *m: The mux to store the channels into.

struct vidtv_demod_cnr_to_qual_s #

Map CNR values to a given combination of modulation and fec_inner

Definition

struct vidtv_demod_cnr_to_qual_s {
    u32 modulation;
    u32 fec;
    u32 cnr_ok;
    u32 cnr_good;
};

Members

  • modulation: see enum fe_modulation
  • fec: see enum fe_fec_rate
  • cnr_ok: S/N threshold to consider the signal as OK. Below that, there's a chance of losing sync.
  • cnr_good: S/N threshold to consider the signal strong.

Description

This struct matches values for 'good' and 'ok' CNRs given the combination of modulation and fec_inner in use. We might simulate some noise if the signal quality is not too good.

The values were taken from libdvbv5.

struct vidtv_demod_config #

Configuration used to init the demod

Definition

struct vidtv_demod_config {
    u8 drop_tslock_prob_on_low_snr;
    u8 recover_tslock_prob_on_good_snr;
};

Members

  • drop_tslock_prob_on_low_snr: probability of losing the lock due to low snr
  • recover_tslock_prob_on_good_snr: probability of recovering when the signal improves

Description

The configuration used to init the demodulator module, usually filled by a bridge driver. For vidtv, this is filled by vidtv_bridge before the demodulator module is probed.

struct vidtv_demod_state #

The demodulator state

Definition

struct vidtv_demod_state {
    struct dvb_frontend frontend;
    struct vidtv_demod_config config;
    enum fe_status status;
    u16 tuner_cnr;
};

Members

  • frontend: The frontend structure allocated by the demod.
  • config: The config used to init the demod.
  • status: the demod status.
  • tuner_cnr: current S/N ratio for the signal carrier

struct vidtv_encoder #

A generic encoder type.

Definition

struct vidtv_encoder {
    enum vidtv_encoder_id id;
    char *name;
    u8 *encoder_buf;
    u32 encoder_buf_sz;
    u32 encoder_buf_offset;
    u64 sample_count;
    struct vidtv_access_unit *access_units;
    void *src_buf;
    u32 src_buf_sz;
    u32 src_buf_offset;
    bool is_video_encoder;
    void *ctx;
    __be16 stream_id;
    __be16 es_pid;
    void *(*encode)(struct vidtv_encoder *e);
    u32 (*clear)(struct vidtv_encoder *e);
    struct vidtv_encoder *sync;
    u32 sampling_rate_hz;
    void (*last_sample_cb)(u32 sample_no);
    void (*destroy)(struct vidtv_encoder *e);
    struct vidtv_encoder *next;
};

Members

  • id: So we can cast to a concrete implementation when needed.
  • name: Usually the same as the stream name.
  • encoder_buf: The encoder internal buffer for the access units.
  • encoder_buf_sz: The encoder buffer size, in bytes
  • encoder_buf_offset: Our byte position in the encoder buffer.
  • sample_count: How many samples we have encoded in total.
  • access_units: encoder payload units, used for clock references
  • src_buf: The source of raw data to be encoded, encoder might set a default if null.
  • src_buf_sz: size of src_buf.
  • src_buf_offset: Our position in the source buffer.
  • is_video_encoder: Whether this a video encoder (as opposed to audio)
  • ctx: Encoder-specific state.
  • stream_id: Examples: Audio streams (0xc0-0xdf), Video streams (0xe0-0xef).
  • es_pid: The TS PID to use for the elementary stream in this encoder.
  • encode: Prepare enough AUs for the given amount of time.
  • clear: Clear the encoder output.
  • sync: Attempt to synchronize with this encoder.
  • sampling_rate_hz: The sampling rate (or fps, if video) used.
  • last_sample_cb: Called when the encoder runs out of data.This is so the source can read data in a piecemeal fashion instead of having to provide it all at once.
  • destroy: Destroy this encoder, freeing allocated resources.
  • next: Next in the chain

struct vidtv_mux_timing #

Timing related information

Definition

struct vidtv_mux_timing {
    u64 start_jiffies;
    u64 current_jiffies;
    u64 past_jiffies;
    u64 clk;
    u64 pcr_period_usecs;
    u64 si_period_usecs;
};

Members

  • start_jiffies: The value of 'jiffies' when we started the mux thread.
  • current_jiffies: The value of 'jiffies' for the current iteration.
  • past_jiffies: The value of 'jiffies' for the past iteration.
  • clk: A 27Mhz clock from which we will drive the PCR. Updated proportionally on every iteration.
  • pcr_period_usecs: How often we should send PCR packets.
  • si_period_usecs: How often we should send PSI packets.

Description

This is used to decide when PCR or PSI packets should be sent. This will also provide storage for the clock, which is used to compute the value for the PCR.

struct vidtv_mux_si #

Store the PSI context.

Definition

struct vidtv_mux_si {
    struct vidtv_psi_table_pat *pat;
    struct vidtv_psi_table_pmt **pmt_secs;
    struct vidtv_psi_table_sdt *sdt;
    struct vidtv_psi_table_nit *nit;
    struct vidtv_psi_table_eit *eit;
};

Members

  • pat: The PAT in use by the muxer.
  • pmt_secs: The PMT sections in use by the muxer. One for each program in the PAT.
  • sdt: The SDT in use by the muxer.
  • nit: The NIT in use by the muxer.
  • eit: the EIT in use by the muxer.

Description

This is used to store the PAT, PMT sections and SDT in use by the muxer.

The muxer acquire these by looking into the hardcoded channels in vidtv_channel and then periodically sends the TS packets for them>

struct vidtv_mux_pid_ctx #

Store the context for a given TS PID.

Definition

struct vidtv_mux_pid_ctx {
    u16 pid;
    u8 cc;
    struct hlist_node h;
};

Members

  • pid: The TS PID.
  • cc: The continuity counter for this PID. It is incremented on every TS pack and it will wrap around at 0xf0. If the decoder notices a sudden jump in this counter this will trigger a discontinuity state.
  • h: This is embedded in a hash table, mapping pid -> vidtv_mux_pid_ctx

struct vidtv_mux #

A muxer abstraction loosely based in libavcodec/mpegtsenc.c

Definition

struct vidtv_mux {
    struct dvb_frontend *fe;
    struct device *dev;
    struct vidtv_mux_timing timing;
    u32 mux_rate_kbytes_sec;
    unsigned long pid_ctx[1 << ((3) - 1)];
    void (*on_new_packets_available_cb)(void *priv, u8 *buf, u32 npackets);
    u8 *mux_buf;
    u32 mux_buf_sz;
    u32 mux_buf_offset;
    struct vidtv_channel  *channels;
    struct vidtv_mux_si si;
    u64 num_streamed_pcr;
    u64 num_streamed_si;
    struct work_struct mpeg_thread;
    bool streaming;
    u16 pcr_pid;
    u16 transport_stream_id;
    u16 network_id;
    char *network_name;
    void *priv;
};

Members

  • fe: The frontend structure allocated by the muxer.
  • dev: pointer to struct device.
  • timing: Keeps track of timing related information.
  • mux_rate_kbytes_sec: The bit rate for the TS, in kbytes.
  • pid_ctx: A hash table to keep track of per-PID metadata.
  • on_new_packets_available_cb: A callback to inform of new TS packets ready.
  • mux_buf: A pointer to a buffer for this muxer. TS packets are stored there and then passed on to the bridge driver.
  • mux_buf_sz: The size for 'mux_buf'.
  • mux_buf_offset: The current offset into 'mux_buf'.
  • channels: The channels associated with this muxer.
  • si: Keeps track of the PSI context.
  • num_streamed_pcr: Number of PCR packets streamed.
  • num_streamed_si: The number of PSI packets streamed.
  • mpeg_thread: Thread responsible for the muxer loop.
  • streaming: whether 'mpeg_thread' is running.
  • pcr_pid: The TS PID used for the PSI packets. All channels will share the same PCR.
  • transport_stream_id: The transport stream ID
  • network_id: The network ID
  • network_name: The network name
  • priv: Private data.

struct vidtv_mux_init_args #

Arguments used to inix the muxer.

Definition

struct vidtv_mux_init_args {
    u32 mux_rate_kbytes_sec;
    void (*on_new_packets_available_cb)(void *priv, u8 *buf, u32 npackets);
    u32 mux_buf_sz;
    u64 pcr_period_usecs;
    u64 si_period_usecs;
    u16 pcr_pid;
    u16 transport_stream_id;
    struct vidtv_channel *channels;
    u16 network_id;
    char *network_name;
    void *priv;
};

Members

  • mux_rate_kbytes_sec: The bit rate for the TS, in kbytes.
  • on_new_packets_available_cb: A callback to inform of new TS packets ready.
  • mux_buf_sz: The size for 'mux_buf'.
  • pcr_period_usecs: How often we should send PCR packets.
  • si_period_usecs: How often we should send PSI packets.
  • pcr_pid: The TS PID used for the PSI packets. All channels will share the same PCR.
  • transport_stream_id: The transport stream ID
  • channels: an optional list of channels to use
  • network_id: The network ID
  • network_name: The network name
  • priv: Private data.

struct pes_header_write_args #

Arguments to write a PES header.

Definition

struct pes_header_write_args {
    void *dest_buf;
    u32 dest_offset;
    u32 dest_buf_sz;
    u32 encoder_id;
    bool send_pts;
    u64 pts;
    bool send_dts;
    u64 dts;
    u16 stream_id;
    u32 n_pes_h_s_bytes;
    u32 access_unit_len;
};

Members

  • dest_buf: The buffer to write into.
  • dest_offset: where to start writing in the dest_buffer.
  • dest_buf_sz: The size of the dest_buffer
  • encoder_id: Encoder id (see vidtv_encoder.h)
  • send_pts: Should we send PTS?
  • pts: PTS value to send.
  • send_dts: Should we send DTS?
  • dts: DTS value to send.
  • stream_id: The stream id to use. Ex: Audio streams (0xc0-0xdf), Video streams (0xe0-0xef).
  • n_pes_h_s_bytes: Padding bytes. Might be used by an encoder if needed, gets discarded by the decoder.
  • access_unit_len: The size of one access unit (with any headers it might need)

struct pes_ts_header_write_args #

Arguments to write a TS header.

Definition

struct pes_ts_header_write_args {
    void *dest_buf;
    u32 dest_offset;
    u32 dest_buf_sz;
    u16 pid;
    u8 *continuity_counter;
    bool wrote_pes_header;
    u32 n_stuffing_bytes;
    u64 pcr;
};

Members

  • dest_buf: The buffer to write into.
  • dest_offset: where to start writing in the dest_buffer.
  • dest_buf_sz: The size of the dest_buffer
  • pid: The PID to use for the TS packets.
  • continuity_counter: Incremented on every new TS packet.
  • wrote_pes_header: Flag to indicate that the PES header was written
  • n_stuffing_bytes: Padding bytes. Might be used by an encoder if needed, gets discarded by the decoder.
  • pcr: counter driven by a 27Mhz clock.

struct pes_write_args #

Arguments for the packetizer.

Definition

struct pes_write_args {
    void *dest_buf;
    void *from;
    u32 access_unit_len;
    u32 dest_offset;
    u32 dest_buf_sz;
    u16 pid;
    u32 encoder_id;
    u8 *continuity_counter;
    u16 stream_id;
    bool send_pts;
    u64 pts;
    bool send_dts;
    u64 dts;
    u32 n_pes_h_s_bytes;
    u64 pcr;
};

Members

  • dest_buf: The buffer to write into.
  • from: A pointer to the encoder buffer containing one access unit.
  • access_unit_len: The size of one access unit (with any headers it might need)
  • dest_offset: where to start writing in the dest_buffer.
  • dest_buf_sz: The size of the dest_buffer
  • pid: The PID to use for the TS packets.
  • encoder_id: Encoder id (see vidtv_encoder.h)
  • continuity_counter: Incremented on every new TS packet.
  • stream_id: The stream id to use. Ex: Audio streams (0xc0-0xdf), Video streams (0xe0-0xef).
  • send_pts: Should we send PTS?
  • pts: PTS value to send.
  • send_dts: Should we send DTS?
  • dts: DTS value to send.
  • n_pes_h_s_bytes: Padding bytes. Might be used by an encoder if needed, gets discarded by the decoder.
  • pcr: counter driven by a 27Mhz clock.

vidtv_pes_write_into() #

u32 vidtv_pes_write_into(struct pes_write_args *args)

Write a PES packet as MPEG-TS packets into a buffer.

Parameters

  • struct pes_write_args *args: The args to use when writing

Description

This function translate the ES data for one access unit from an encoder into MPEG TS packets. It does so by first encapsulating it with a PES header and then splitting it into TS packets.

The data is then written into the buffer pointed to by 'args.buf'

Return

The number of bytes written into the buffer. This is usually NOT equal to the size of the access unit, since we need space for PES headers, TS headers and padding bytes, if any.

struct psi_write_args #

Arguments for the PSI packetizer.

Definition

struct psi_write_args {
    void *dest_buf;
    void *from;
    size_t len;
    u32 dest_offset;
    u16 pid;
    bool new_psi_section;
    u8 *continuity_counter;
    bool is_crc;
    u32 dest_buf_sz;
    u32 *crc;
};

Members

  • dest_buf: The buffer to write into.
  • from: PSI data to be copied.
  • len: How much to write.
  • dest_offset: where to start writing in the dest_buffer.
  • pid: TS packet ID.
  • new_psi_section: Set when starting a table section.
  • continuity_counter: Incremented on every new packet.
  • is_crc: Set when writing the CRC at the end.
  • dest_buf_sz: The size of the dest_buffer
  • crc: a pointer to store the crc for this chunk

struct desc_write_args #

Arguments in order to write a descriptor.

Definition

struct desc_write_args {
    void *dest_buf;
    u32 dest_offset;
    struct vidtv_psi_desc *desc;
    u16 pid;
    u8 *continuity_counter;
    u32 dest_buf_sz;
    u32 *crc;
};

Members

  • dest_buf: The buffer to write into.
  • dest_offset: where to start writing in the dest_buffer.
  • desc: A pointer to the descriptor
  • pid: TS packet ID.
  • continuity_counter: Incremented on every new packet.
  • dest_buf_sz: The size of the dest_buffer
  • crc: a pointer to store the crc for this chunk

struct crc32_write_args #

Arguments in order to write the CRC at the end of the PSI tables.

Definition

struct crc32_write_args {
    void *dest_buf;
    u32 dest_offset;
    __be32 crc;
    u16 pid;
    u8 *continuity_counter;
    u32 dest_buf_sz;
};

Members

  • dest_buf: The buffer to write into.
  • dest_offset: where to start writing in the dest_buffer.
  • crc: the CRC value to write
  • pid: TS packet ID.
  • continuity_counter: Incremented on every new packet.
  • dest_buf_sz: The size of the dest_buffer

struct header_write_args #

Arguments in order to write the common table header

Definition

struct header_write_args {
    void *dest_buf;
    u32 dest_offset;
    struct vidtv_psi_table_header *h;
    u16 pid;
    u8 *continuity_counter;
    u32 dest_buf_sz;
    u32 *crc;
};

Members

  • dest_buf: The buffer to write into.
  • dest_offset: where to start writing in the dest_buffer.
  • h: a pointer to the header.
  • pid: TS packet ID.
  • continuity_counter: Incremented on every new packet.
  • dest_buf_sz: The size of the dest_buffer
  • crc: a pointer to store the crc for this chunk

vidtv_psi_sdt_service_assign() #

void vidtv_psi_sdt_service_assign(struct vidtv_psi_table_sdt *sdt, struct vidtv_psi_table_sdt_service *service)

Assigns the service loop to the SDT.

Parameters

  • struct vidtv_psi_table_sdt *sdt: The SDT to assign to.
  • struct vidtv_psi_table_sdt_service *service: The service loop (one or more services)

Description

This will free the previous service loop in the table. This will assign ownership of the service loop to the table, i.e. the table will free this service loop when a call to its destroy function is made.

vidtv_psi_desc_assign() #

void vidtv_psi_desc_assign(struct vidtv_psi_desc **to, struct vidtv_psi_desc *desc)

Assigns a descriptor loop at some point

Parameters

  • struct vidtv_psi_desc **to: Where to assign this descriptor loop to
  • struct vidtv_psi_desc *desc: The descriptor loop that will be assigned.

Description

This will free the loop in 'to', if any.

vidtv_pmt_desc_assign() #

void vidtv_pmt_desc_assign(struct vidtv_psi_table_pmt *pmt, struct vidtv_psi_desc **to, struct vidtv_psi_desc *desc)

Assigns a descriptor loop at some point in a PMT section.

Parameters

  • struct vidtv_psi_table_pmt *pmt: The PMT section that will contain the descriptor loop
  • struct vidtv_psi_desc **to: Where in the PMT to assign this descriptor loop to
  • struct vidtv_psi_desc *desc: The descriptor loop that will be assigned.

Description

This will free the loop in 'to', if any. This will assign ownership of the loop to the table, i.e. the table will free this loop when a call to its destroy function is made.

vidtv_sdt_desc_assign() #

void vidtv_sdt_desc_assign(struct vidtv_psi_table_sdt *sdt, struct vidtv_psi_desc **to, struct vidtv_psi_desc *desc)

Assigns a descriptor loop at some point in a SDT.

Parameters

  • struct vidtv_psi_table_sdt *sdt: The SDT that will contain the descriptor loop
  • struct vidtv_psi_desc **to: Where in the PMT to assign this descriptor loop to
  • struct vidtv_psi_desc *desc: The descriptor loop that will be assigned.

Description

This will free the loop in 'to', if any. This will assign ownership of the loop to the table, i.e. the table will free this loop when a call to its destroy function is made.

vidtv_psi_pat_program_assign() #

void vidtv_psi_pat_program_assign(struct vidtv_psi_table_pat *pat, struct vidtv_psi_table_pat_program *p)

Assigns the program loop to the PAT.

Parameters

  • struct vidtv_psi_table_pat *pat: The PAT to assign to.
  • struct vidtv_psi_table_pat_program *p: The program loop (one or more programs)

Description

This will free the previous program loop in the table. This will assign ownership of the program loop to the table, i.e. the table will free this program loop when a call to its destroy function is made.

vidtv_psi_pmt_stream_assign() #

void vidtv_psi_pmt_stream_assign(struct vidtv_psi_table_pmt *pmt, struct vidtv_psi_table_pmt_stream *s)

Assigns the stream loop to the PAT.

Parameters

  • struct vidtv_psi_table_pmt *pmt: The PMT to assign to.
  • struct vidtv_psi_table_pmt_stream *s: The stream loop (one or more streams)

Description

This will free the previous stream loop in the table. This will assign ownership of the stream loop to the table, i.e. the table will free this stream loop when a call to its destroy function is made.

vidtv_psi_pmt_create_sec_for_each_pat_entry() #

struct vidtv_psi_table_pmt** vidtv_psi_pmt_create_sec_for_each_pat_entry(struct vidtv_psi_table_pat *pat, u16 pcr_pid)

Create a PMT section for each program found in the PAT

Parameters

  • struct vidtv_psi_table_pat *pat: The PAT to look for programs.
  • u16 pcr_pid: packet ID for the PCR to be used for the program described in this PMT section

vidtv_psi_pmt_get_pid() #

u16 vidtv_psi_pmt_get_pid(struct vidtv_psi_table_pmt *section, struct vidtv_psi_table_pat *pat)

Get the TS PID for a PMT section.

Parameters

  • struct vidtv_psi_table_pmt *section: The PMT section whose PID we want to retrieve.
  • struct vidtv_psi_table_pat *pat: The PAT table to look into.

Return

the TS PID for 'section'

vidtv_psi_pat_table_update_sec_len() #

void vidtv_psi_pat_table_update_sec_len(struct vidtv_psi_table_pat *pat)

Recompute and update the PAT section length.

Parameters

  • struct vidtv_psi_table_pat *pat: The PAT whose length is to be updated.

Description

This will traverse the table and accumulate the length of its components, which is then used to replace the 'section_length' field.

If section_length > MAX_SECTION_LEN, the operation fails.

vidtv_psi_pmt_table_update_sec_len() #

void vidtv_psi_pmt_table_update_sec_len(struct vidtv_psi_table_pmt *pmt)

Recompute and update the PMT section length.

Parameters

  • struct vidtv_psi_table_pmt *pmt: The PMT whose length is to be updated.

Description

This will traverse the table and accumulate the length of its components, which is then used to replace the 'section_length' field.

If section_length > MAX_SECTION_LEN, the operation fails.

vidtv_psi_sdt_table_update_sec_len() #

void vidtv_psi_sdt_table_update_sec_len(struct vidtv_psi_table_sdt *sdt)

Recompute and update the SDT section length.

Parameters

  • struct vidtv_psi_table_sdt *sdt: The SDT whose length is to be updated.

Description

This will traverse the table and accumulate the length of its components, which is then used to replace the 'section_length' field.

If section_length > MAX_SECTION_LEN, the operation fails.

struct vidtv_psi_pat_write_args #

Arguments for writing a PAT table

Definition

struct vidtv_psi_pat_write_args {
    char *buf;
    u32 offset;
    struct vidtv_psi_table_pat *pat;
    u32 buf_sz;
    u8 *continuity_counter;
};

Members

  • buf: The destination buffer.
  • offset: The offset into the destination buffer.
  • pat: A pointer to the PAT.
  • buf_sz: The size of the destination buffer.
  • continuity_counter: A pointer to the CC. Incremented on every new packet.

vidtv_psi_pat_write_into() #

u32 vidtv_psi_pat_write_into(struct vidtv_psi_pat_write_args *args)

Write PAT as MPEG-TS packets into a buffer.

Parameters

  • struct vidtv_psi_pat_write_args *args: An instance of struct vidtv_psi_pat_write_args

Description

This function writes the MPEG TS packets for a PAT table into a buffer. Calling code will usually generate the PAT via a call to its init function and thus is responsible for freeing it.

Return

The number of bytes written into the buffer. This is NOT equal to the size of the PAT, since more space is needed for TS headers during TS encapsulation.

struct vidtv_psi_sdt_write_args #

Arguments for writing a SDT table

Definition

struct vidtv_psi_sdt_write_args {
    char *buf;
    u32 offset;
    struct vidtv_psi_table_sdt *sdt;
    u32 buf_sz;
    u8 *continuity_counter;
};

Members

  • buf: The destination buffer.
  • offset: The offset into the destination buffer.
  • sdt: A pointer to the SDT.
  • buf_sz: The size of the destination buffer.
  • continuity_counter: A pointer to the CC. Incremented on every new packet.

vidtv_psi_sdt_write_into() #

u32 vidtv_psi_sdt_write_into(struct vidtv_psi_sdt_write_args *args)

Write SDT as MPEG-TS packets into a buffer.

Parameters

  • struct vidtv_psi_sdt_write_args *args: an instance of struct vidtv_psi_sdt_write_args

Description

This function writes the MPEG TS packets for a SDT table into a buffer. Calling code will usually generate the SDT via a call to its init function and thus is responsible for freeing it.

Return

The number of bytes written into the buffer. This is NOT equal to the size of the SDT, since more space is needed for TS headers during TS encapsulation.

struct vidtv_psi_pmt_write_args #

Arguments for writing a PMT section

Definition

struct vidtv_psi_pmt_write_args {
    char *buf;
    u32 offset;
    struct vidtv_psi_table_pmt *pmt;
    u16 pid;
    u32 buf_sz;
    u8 *continuity_counter;
    u16 pcr_pid;
};

Members

  • buf: The destination buffer.
  • offset: The offset into the destination buffer.
  • pmt: A pointer to the PMT.
  • pid: Program ID
  • buf_sz: The size of the destination buffer.
  • continuity_counter: A pointer to the CC. Incremented on every new packet.
  • pcr_pid: The TS PID used for the PSI packets. All channels will share the same PCR.

vidtv_psi_pmt_write_into() #

u32 vidtv_psi_pmt_write_into(struct vidtv_psi_pmt_write_args *args)

Write PMT as MPEG-TS packets into a buffer.

Parameters

  • struct vidtv_psi_pmt_write_args *args: an instance of struct vidtv_psi_pmt_write_args

Description

This function writes the MPEG TS packets for a PMT section into a buffer. Calling code will usually generate the PMT section via a call to its init function and thus is responsible for freeing it.

Return

The number of bytes written into the buffer. This is NOT equal to the size of the PMT section, since more space is needed for TS headers during TS encapsulation.

vidtv_psi_find_pmt_sec() #

struct vidtv_psi_table_pmt * vidtv_psi_find_pmt_sec(struct vidtv_psi_table_pmt **pmt_sections, u16 nsections, u16 program_num)

Finds the PMT section for 'program_num'

Parameters

  • struct vidtv_psi_table_pmt **pmt_sections: The sections to look into.
  • u16 nsections: The number of sections.
  • u16 program_num: The 'program_num' from PAT pointing to a PMT section.

Return

A pointer to the PMT, if found, or NULL.

struct vidtv_psi_table_transport #

A entry in the TS loop for the NIT and/or other tables. See ETSI 300 468 section 5.2.1

Definition

struct vidtv_psi_table_transport {
    __be16 transport_id;
    __be16 network_id;
    __be16 bitfield;
    struct vidtv_psi_desc *descriptor;
    struct vidtv_psi_table_transport *next;
};

Members

  • transport_id: The TS ID being described
  • network_id: The network_id that contains the TS ID
  • bitfield: Contains the descriptor loop length
  • descriptor: A descriptor loop
  • next: Pointer to the next entry

struct vidtv_psi_table_nit #

A Network Information Table (NIT). See ETSI 300 468 section 5.2.1

Definition

struct vidtv_psi_table_nit {
    struct vidtv_psi_table_header header;
    __be16 bitfield;
    struct vidtv_psi_desc *descriptor;
    __be16 bitfield2;
    struct vidtv_psi_table_transport *transport;
};

Members

  • header: A PSI table header
  • bitfield: Contains the network descriptor length
  • descriptor: A descriptor loop describing the network
  • bitfield2: Contains the transport stream loop length
  • transport: The transport stream loop

struct vidtv_psi_nit_write_args #

Arguments for writing a NIT section

Definition

struct vidtv_psi_nit_write_args {
    char *buf;
    u32 offset;
    struct vidtv_psi_table_nit *nit;
    u32 buf_sz;
    u8 *continuity_counter;
};

Members

  • buf: The destination buffer.
  • offset: The offset into the destination buffer.
  • nit: A pointer to the NIT
  • buf_sz: The size of the destination buffer.
  • continuity_counter: A pointer to the CC. Incremented on every new packet.

vidtv_psi_nit_write_into() #

u32 vidtv_psi_nit_write_into(struct vidtv_psi_nit_write_args *args)

Write NIT as MPEG-TS packets into a buffer.

Parameters

  • struct vidtv_psi_nit_write_args *args: an instance of struct vidtv_psi_nit_write_args

Description

This function writes the MPEG TS packets for a NIT table into a buffer. Calling code will usually generate the NIT via a call to its init function and thus is responsible for freeing it.

Return

The number of bytes written into the buffer. This is NOT equal to the size of the NIT, since more space is needed for TS headers during TS encapsulation.

struct vidtv_psi_eit_write_args #

Arguments for writing an EIT section

Definition

struct vidtv_psi_eit_write_args {
    char *buf;
    u32 offset;
    struct vidtv_psi_table_eit *eit;
    u32 buf_sz;
    u8 *continuity_counter;
};

Members

  • buf: The destination buffer.
  • offset: The offset into the destination buffer.
  • eit: A pointer to the EIT
  • buf_sz: The size of the destination buffer.
  • continuity_counter: A pointer to the CC. Incremented on every new packet.

vidtv_psi_eit_write_into() #

u32 vidtv_psi_eit_write_into(struct vidtv_psi_eit_write_args *args)

Write EIT as MPEG-TS packets into a buffer.

Parameters

  • struct vidtv_psi_eit_write_args *args: an instance of struct vidtv_psi_nit_write_args

Description

This function writes the MPEG TS packets for a EIT table into a buffer. Calling code will usually generate the EIT via a call to its init function and thus is responsible for freeing it.

Return

The number of bytes written into the buffer. This is NOT equal to the size of the EIT, since more space is needed for TS headers during TS encapsulation.

vidtv_psi_eit_table_update_sec_len() #

void vidtv_psi_eit_table_update_sec_len(struct vidtv_psi_table_eit *eit)

Recompute and update the EIT section length.

Parameters

  • struct vidtv_psi_table_eit *eit: The EIT whose length is to be updated.

Description

This will traverse the table and accumulate the length of its components, which is then used to replace the 'section_length' field.

If section_length > EIT_MAX_SECTION_LEN, the operation fails.

vidtv_psi_eit_event_assign() #

void vidtv_psi_eit_event_assign(struct vidtv_psi_table_eit *eit, struct vidtv_psi_table_eit_event *e)

Assigns the event loop to the EIT.

Parameters

  • struct vidtv_psi_table_eit *eit: The EIT to assign to.
  • struct vidtv_psi_table_eit_event *e: The event loop

Description

This will free the previous event loop in the table. This will assign ownership of the stream loop to the table, i.e. the table will free this stream loop when a call to its destroy function is made.

struct vidtv_s302m_ctx #

s302m encoder context.

Definition

struct vidtv_s302m_ctx {
    struct vidtv_encoder *enc;
    u32 frame_index;
    u32 au_count;
    int last_duration;
    unsigned int note_offset;
    enum musical_notes last_tone;
};

Members

  • enc: A pointer to the containing encoder structure.
  • frame_index: The current frame in a block
  • au_count: The total number of access units encoded up to now
  • last_duration: Duration of the tone currently being played
  • note_offset: Position at the music tone array
  • last_tone: Tone currently being played

struct vidtv_s302m_encoder_init_args #

Args for the s302m encoder.

Definition

struct vidtv_s302m_encoder_init_args {
    char *name;
    void *src_buf;
    u32 src_buf_sz;
    u16 es_pid;
    struct vidtv_encoder *sync;
    void (*last_sample_cb)(u32 sample_no);
    struct vidtv_encoder *head;
};

Members

  • name: A name to identify this particular instance
  • src_buf: The source buffer, encoder will default to a sine wave if this is NULL.
  • src_buf_sz: The size of the source buffer.
  • es_pid: The MPEG Elementary Stream PID to use.
  • sync: Attempt to synchronize audio with this video encoder, if not NULL.
  • last_sample_cb: A callback called when the encoder runs out of data.
  • head: Add to this chain

struct pcr_write_args #

Arguments for the pcr_write_into function.

Definition

struct pcr_write_args {
    void *dest_buf;
    u32 dest_offset;
    u16 pid;
    u32 buf_sz;
    u8 *continuity_counter;
    u64 pcr;
};

Members

  • dest_buf: The buffer to write into.
  • dest_offset: The byte offset into the buffer.
  • pid: The TS PID for the PCR packets.
  • buf_sz: The size of the buffer in bytes.
  • continuity_counter: The TS continuity_counter.
  • pcr: A sample from the system clock.

struct null_packet_write_args #

Arguments for the null_write_into function

Definition

struct null_packet_write_args {
    void *dest_buf;
    u32 dest_offset;
    u32 buf_sz;
    u8 *continuity_counter;
};

Members

  • dest_buf: The buffer to write into.
  • dest_offset: The byte offset into the buffer.
  • buf_sz: The size of the buffer in bytes.
  • continuity_counter: The TS continuity_counter.

vidtv_ts_null_write_into() #

u32 vidtv_ts_null_write_into(const struct null_packet_write_args *args)

Write a TS null packet into a buffer.

Parameters

  • const struct null_packet_write_args *args: the arguments to use when writing.

Description

This function will write a null packet into a buffer. This is usually used to pad TS streams.

Return

The number of bytes written into the buffer.

vidtv_ts_pcr_write_into() #

u32 vidtv_ts_pcr_write_into(const struct pcr_write_args *args)

Write a PCR packet into a buffer.

Parameters

  • const struct pcr_write_args *args: the arguments to use when writing.

Description

This function will write a PCR packet into a buffer. This is used to synchronize the clocks between encoders and decoders.

Return

The number of bytes written into the buffer.

struct vidtv_tuner_config #

Configuration used to init the tuner.

Definition

struct vidtv_tuner_config {
    struct dvb_frontend *fe;
    u32 mock_power_up_delay_msec;
    u32 mock_tune_delay_msec;
    u32 vidtv_valid_dvb_t_freqs[NUM_VALID_TUNER_FREQS];
    u32 vidtv_valid_dvb_c_freqs[NUM_VALID_TUNER_FREQS];
    u32 vidtv_valid_dvb_s_freqs[NUM_VALID_TUNER_FREQS];
    u8 max_frequency_shift_hz;
};

Members

  • fe: A pointer to the dvb_frontend structure allocated by vidtv_demod.
  • mock_power_up_delay_msec: Simulate a power-up delay.
  • mock_tune_delay_msec: Simulate a tune delay.
  • vidtv_valid_dvb_t_freqs: The valid DVB-T frequencies to simulate.
  • vidtv_valid_dvb_c_freqs: The valid DVB-C frequencies to simulate.
  • vidtv_valid_dvb_s_freqs: The valid DVB-S frequencies to simulate.
  • max_frequency_shift_hz: The maximum frequency shift in HZ allowed when tuning in a channel

Description

The configuration used to init the tuner module, usually filled by a bridge driver. For vidtv, this is filled by vidtv_bridge before the tuner module is probed.

vidtv_memcpy() #

u32 vidtv_memcpy(void *to, size_t to_offset, size_t to_size, const void *from, size_t len)

wrapper routine to be used by MPEG-TS generator, in order to avoid going past the output buffer.

Parameters

  • void *to: Starting element to where a MPEG-TS packet will be copied.
  • size_t to_offset: Starting position of the to buffer to be filled.
  • size_t to_size: Size of the to buffer.
  • const void *from: Starting element of the buffer to be copied.
  • size_t len: Number of elements to be copy from from buffer into to+ to_offset buffer.

Note

Real digital TV demod drivers should not have memcpy wrappers. We use it here because emulating MPEG-TS generation at kernelspace requires some extra care.

Return

Returns the number of bytes written

vidtv_memset() #

u32 vidtv_memset(void *to, size_t to_offset, size_t to_size, const int c, size_t len)

wrapper routine to be used by MPEG-TS generator, in order to avoid going past the output buffer.

Parameters

  • void *to: Starting element to set
  • size_t to_offset: Starting position of the to buffer to be filled.
  • size_t to_size: Size of the to buffer.
  • const int c: The value to set the memory to.
  • size_t len: Number of elements to be copy from from buffer into to+ to_offset buffer.

Note

Real digital TV demod drivers should not have memset wrappers. We use it here because emulating MPEG-TS generation at kernelspace requires some extra care.

Return

Returns the number of bytes written

struct vidtv_tuner_hardware_state #

Simulate the tuner hardware status

Definition

struct vidtv_tuner_hardware_state {
    bool asleep;
    u32 lock_status;
    u32 if_frequency;
    u32 tuned_frequency;
    u32 bandwidth;
};

Members

  • asleep: whether the tuner is asleep, i.e whether _sleep() or _suspend() was called.
  • lock_status: Whether the tuner has managed to lock on the requested frequency.
  • if_frequency: The tuner's intermediate frequency. Hardcoded for the purposes of simulation.
  • tuned_frequency: The actual tuned frequency.
  • bandwidth: The actual bandwidth.

Description

This structure is meant to simulate the status of the tuner hardware, as if we had a physical tuner hardware.

struct vidtv_tuner_dev #

The tuner struct

Definition

struct vidtv_tuner_dev {
    struct dvb_frontend *fe;
    struct vidtv_tuner_hardware_state hw_state;
    struct vidtv_tuner_config config;
};

Members

  • fe: A pointer to the dvb_frontend structure allocated by vidtv_demod
  • hw_state: A struct to simulate the tuner's hardware state as if we had a physical tuner hardware.
  • config: The configuration used to start the tuner module, usually filled by a bridge driver. For vidtv, this is filled by vidtv_bridge before the tuner module is probed.

The Virtual Media Controller Driver (vimc)

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

Source code documentation #

vimc-streamer #

struct vimc_stream #

struct that represents a stream in the pipeline

Definition

struct vimc_stream {
    struct media_pipeline pipe;
    struct vimc_ent_device *ved_pipeline[VIMC_STREAMER_PIPELINE_MAX_SIZE];
    unsigned int pipe_size;
    struct task_struct *kthread;
};

Members

  • pipe: the media pipeline object associated with this stream
  • ved_pipeline: array containing all the entities participating in the stream. The order is from a video device (usually a capture device) where stream_on was called, to the entity generating the first base image to be processed in the pipeline.
  • pipe_size: size of ved_pipeline
  • kthread: thread that generates the frames of the stream.

Description

When the user call stream_on in a video device, struct vimc_stream is used to keep track of all entities and subdevices that generates and process frames for the stream.

vimc_get_source_entity() #

struct media_entity * vimc_get_source_entity(struct media_entity *ent)

get the entity connected with the first sink pad

Parameters

  • struct media_entity *ent: reference media_entity

Description

Helper function that returns the media entity containing the source pad linked with the first sink pad from the given media entity pad list.

Return

The source pad or NULL, if it wasn't found.

vimc_streamer_pipeline_terminate() #

void vimc_streamer_pipeline_terminate(struct vimc_stream *stream)

Disable stream in all ved in stream

Parameters

  • struct vimc_stream *stream: the pointer to the stream structure with the pipeline to be disabled.

Description

Calls s_stream to disable the stream in each entity of the pipeline

vimc_streamer_pipeline_init() #

int vimc_streamer_pipeline_init(struct vimc_stream *stream, struct vimc_ent_device *ved)

Initializes the stream structure

Parameters

  • struct vimc_stream *stream: the pointer to the stream structure to be initialized
  • struct vimc_ent_device *ved: the pointer to the vimc entity initializing the stream

Description

Initializes the stream structure. Walks through the entity graph to construct the pipeline used later on the streamer thread. Calls vimc_streamer_s_stream() to enable stream in all entities of the pipeline.

Return

0 if success, error code otherwise.

vimc_streamer_thread() #

int vimc_streamer_thread(void *data)

Process frames through the pipeline

Parameters

  • void *data: vimc_stream struct of the current stream

Description

From the source to the sink, gets a frame from each subdevice and send to the next one of the pipeline at a fixed framerate.

Return

Always zero (created as int instead of void to comply with kthread API).

vimc_streamer_s_stream() #

int vimc_streamer_s_stream(struct vimc_stream *stream, struct vimc_ent_device *ved, int enable)

Start/stop the streaming on the media pipeline

Parameters

  • struct vimc_stream *stream: the pointer to the stream structure of the current stream
  • struct vimc_ent_device *ved: pointer to the vimc entity of the entity of the stream
  • int enable: flag to determine if stream should start/stop

Description

When starting, check if there is no stream->kthread allocated. This should indicate that a stream is already running. Then, it initializes the pipeline, creates and runs a kthread to consume buffers through the pipeline. When stopping, analogously check if there is a stream running, stop the thread and terminates the pipeline.

Return

0 if success, error code otherwise.

The Zoran driver

Peios Kernel / Hardware and drivers / Driver development / Media driver interfaces

unified zoran driver (zr360x7, zoran, buz, dc10(+), dc30(+), lml33)

website: http://mjpeg.sourceforge.net/driver-zoran/

Frequently Asked Questions #

What cards are supported #

Iomega Buz, Linux Media Labs LML33/LML33R10, Pinnacle/Miro DC10/DC10+/DC30/DC30+ and related boards (available under various names).

Iomega Buz #

  • Zoran zr36067 PCI controller

  • Zoran zr36060 MJPEG codec

  • Philips saa7111 TV decoder

  • Philips saa7185 TV encoder

Drivers to use: videodev, i2c-core, i2c-algo-bit, videocodec, saa7111, saa7185, zr36060, zr36067

Inputs/outputs: Composite and S-video

Norms: PAL, SECAM (720x576 @ 25 fps), NTSC (720x480 @ 29.97 fps)

Card number: 7

AverMedia 6 Eyes AVS6EYES #

  • Zoran zr36067 PCI controller

  • Zoran zr36060 MJPEG codec

  • Samsung ks0127 TV decoder

  • Conexant bt866 TV encoder

Drivers to use: videodev, i2c-core, i2c-algo-bit, videocodec, ks0127, bt866, zr36060, zr36067

  • Inputs/outputs:

    Six physical inputs. 1-6 are composite, 1-2, 3-4, 5-6 doubles as S-video, 1-3 triples as component. One composite output.

Norms: PAL, SECAM (720x576 @ 25 fps), NTSC (720x480 @ 29.97 fps)

Card number: 8

Note

Not autodetected, card=8 is necessary.

Linux Media Labs LML33 #

  • Zoran zr36067 PCI controller

  • Zoran zr36060 MJPEG codec

  • Brooktree bt819 TV decoder

  • Brooktree bt856 TV encoder

Drivers to use: videodev, i2c-core, i2c-algo-bit, videocodec, bt819, bt856, zr36060, zr36067

Inputs/outputs: Composite and S-video

Norms: PAL (720x576 @ 25 fps), NTSC (720x480 @ 29.97 fps)

Card number: 5

Linux Media Labs LML33R10 #

  • Zoran zr36067 PCI controller

  • Zoran zr36060 MJPEG codec

  • Philips saa7114 TV decoder

  • Analog Devices adv7170 TV encoder

Drivers to use: videodev, i2c-core, i2c-algo-bit, videocodec, saa7114, adv7170, zr36060, zr36067

Inputs/outputs: Composite and S-video

Norms: PAL (720x576 @ 25 fps), NTSC (720x480 @ 29.97 fps)

Card number: 6

Pinnacle/Miro DC10(new) #

  • Zoran zr36057 PCI controller

  • Zoran zr36060 MJPEG codec

  • Philips saa7110a TV decoder

  • Analog Devices adv7176 TV encoder

Drivers to use: videodev, i2c-core, i2c-algo-bit, videocodec, saa7110, adv7175, zr36060, zr36067

Inputs/outputs: Composite, S-video and Internal

Norms: PAL, SECAM (768x576 @ 25 fps), NTSC (640x480 @ 29.97 fps)

Card number: 1

Pinnacle/Miro DC10+ #

  • Zoran zr36067 PCI controller

  • Zoran zr36060 MJPEG codec

  • Philips saa7110a TV decoder

  • Analog Devices adv7176 TV encoder

Drivers to use: videodev, i2c-core, i2c-algo-bit, videocodec, saa7110, adv7175, zr36060, zr36067

Inputs/outputs: Composite, S-video and Internal

Norms: PAL, SECAM (768x576 @ 25 fps), NTSC (640x480 @ 29.97 fps)

Card number: 2

Pinnacle/Miro DC10(old) #

  • Zoran zr36057 PCI controller

  • Zoran zr36050 MJPEG codec

  • Zoran zr36016 Video Front End or Fuji md0211 Video Front End (clone?)

  • Micronas vpx3220a TV decoder

  • mse3000 TV encoder or Analog Devices adv7176 TV encoder

Drivers to use: videodev, i2c-core, i2c-algo-bit, videocodec, vpx3220, mse3000/adv7175, zr36050, zr36016, zr36067

Inputs/outputs: Composite, S-video and Internal

Norms: PAL, SECAM (768x576 @ 25 fps), NTSC (640x480 @ 29.97 fps)

Card number: 0

Pinnacle/Miro DC30 #

  • Zoran zr36057 PCI controller

  • Zoran zr36050 MJPEG codec

  • Zoran zr36016 Video Front End

  • Micronas vpx3225d/vpx3220a/vpx3216b TV decoder

  • Analog Devices adv7176 TV encoder

Drivers to use: videodev, i2c-core, i2c-algo-bit, videocodec, vpx3220/vpx3224, adv7175, zr36050, zr36016, zr36067

Inputs/outputs: Composite, S-video and Internal

Norms: PAL, SECAM (768x576 @ 25 fps), NTSC (640x480 @ 29.97 fps)

Card number: 3

Pinnacle/Miro DC30+ #

  • Zoran zr36067 PCI controller

  • Zoran zr36050 MJPEG codec

  • Zoran zr36016 Video Front End

  • Micronas vpx3225d/vpx3220a/vpx3216b TV decoder

  • Analog Devices adv7176 TV encoder

Drivers to use: videodev, i2c-core, i2c-algo-bit, videocodec, vpx3220/vpx3224, adv7175, zr36050, zr36015, zr36067

Inputs/outputs: Composite, S-video and Internal

Norms: PAL, SECAM (768x576 @ 25 fps), NTSC (640x480 @ 29.97 fps)

Card number: 4

Note

  1. No module for the mse3000 is available yet

  2. No module for the vpx3224 is available yet

1.1 What the TV decoder can do an what not #

The best know TV standards are NTSC/PAL/SECAM. but for decoding a frame that information is not enough. There are several formats of the TV standards. And not every TV decoder is able to handle every format. Also the every combination is supported by the driver. There are currently 11 different tv broadcast formats all aver the world.

The CCIR defines parameters needed for broadcasting the signal. The CCIR has defined different standards: A,B,D,E,F,G,D,H,I,K,K1,L,M,N,... The CCIR says not much about the colorsystem used !!! And talking about a colorsystem says not to much about how it is broadcast.

The CCIR standards A,E,F are not used any more.

When you speak about NTSC, you usually mean the standard: CCIR - M using the NTSC colorsystem which is used in the USA, Japan, Mexico, Canada and a few others.

When you talk about PAL, you usually mean: CCIR - B/G using the PAL colorsystem which is used in many Countries.

When you talk about SECAM, you mean: CCIR - L using the SECAM Colorsystem which is used in France, and a few others.

There the other version of SECAM, CCIR - D/K is used in Bulgaria, China, Slovakai, Hungary, Korea (Rep.), Poland, Rumania and a others.

The CCIR - H uses the PAL colorsystem (sometimes SECAM) and is used in Egypt, Libya, Sri Lanka, Syrain Arab. Rep.

The CCIR - I uses the PAL colorsystem, and is used in Great Britain, Hong Kong, Ireland, Nigeria, South Africa.

The CCIR - N uses the PAL colorsystem and PAL frame size but the NTSC framerate, and is used in Argentina, Uruguay, an a few others

We do not talk about how the audio is broadcast !

A rather good sites about the TV standards are: http://www.sony.jp/support/ http://info.electronicwerkstatt.de/bereiche/fernsehtechnik/frequenzen_und_normen/Fernsehnormen/ and http://www.cabl.com/restaurant/channel.html

Other weird things around: NTSC 4.43 is a modificated NTSC, which is mainly used in PAL VCR's that are able to play back NTSC. PAL 60 seems to be the same as NTSC 4.43 . The Datasheets also talk about NTSC 44, It seems as if it would be the same as NTSC 4.43. NTSC Combs seems to be a decoder mode where the decoder uses a comb filter to split coma and luma instead of a Delay line.

But I did not defiantly find out what NTSC Comb is.

Philips saa7111 TV decoder #

  • was introduced in 1997, is used in the BUZ and

  • can handle: PAL B/G/H/I, PAL N, PAL M, NTSC M, NTSC N, NTSC 4.43 and SECAM

Philips saa7110a TV decoder #

  • was introduced in 1995, is used in the Pinnacle/Miro DC10(new), DC10+ and

  • can handle: PAL B/G, NTSC M and SECAM

Philips saa7114 TV decoder #

  • was introduced in 2000, is used in the LML33R10 and

  • can handle: PAL B/G/D/H/I/N, PAL N, PAL M, NTSC M, NTSC 4.43 and SECAM

Brooktree bt819 TV decoder #

  • was introduced in 1996, and is used in the LML33 and

  • can handle: PAL B/D/G/H/I, NTSC M

Micronas vpx3220a TV decoder #

  • was introduced in 1996, is used in the DC30 and DC30+ and

  • can handle: PAL B/G/H/I, PAL N, PAL M, NTSC M, NTSC 44, PAL 60, SECAM,NTSC Comb

Samsung ks0127 TV decoder #

  • is used in the AVS6EYES card and

  • can handle: NTSC-M/N/44, PAL-M/N/B/G/H/I/D/K/L and SECAM

What the TV encoder can do an what not #

The TV encoder is doing the "same" as the decoder, but in the other direction. You feed them digital data and the generate a Composite or SVHS signal. For information about the colorsystems and TV norm take a look in the TV decoder section.

Philips saa7185 TV Encoder #

  • was introduced in 1996, is used in the BUZ

  • can generate: PAL B/G, NTSC M

Brooktree bt856 TV Encoder #

  • was introduced in 1994, is used in the LML33

  • can generate: PAL B/D/G/H/I/N, PAL M, NTSC M, PAL-N (Argentina)

Analog Devices adv7170 TV Encoder #

  • was introduced in 2000, is used in the LML300R10

  • can generate: PAL B/D/G/H/I/N, PAL M, NTSC M, PAL 60

Analog Devices adv7175 TV Encoder #

  • was introduced in 1996, is used in the DC10, DC10+, DC10 old, DC30, DC30+

  • can generate: PAL B/D/G/H/I/N, PAL M, NTSC M

ITT mse3000 TV encoder #

  • was introduced in 1991, is used in the DC10 old

  • can generate: PAL , NTSC , SECAM

Conexant bt866 TV encoder #

  • is used in AVS6EYES, and

  • can generate: NTSC/PAL, PAL-M, PAL-N

The adv717x, should be able to produce PAL N. But you find nothing PAL N specific in the registers. Seem that you have to reuse a other standard to generate PAL N, maybe it would work if you use the PAL M settings.

How do I get this damn thing to work #

Load zr36067.o. If it can't autodetect your card, use the card=X insmod option with X being the card number as given in the previous section. To have more than one card, use card=X1[,X2[,X3,[X4[..]]]]

To automate this, add the following to your /etc/modprobe.d/zoran.conf:

options zr36067 card=X1[,X2[,X3[,X4[..]]]] alias char-major-81-0 zr36067

One thing to keep in mind is that this doesn't load zr36067.o itself yet. It just automates loading. If you start using xawtv, the device won't load on some systems, since you're trying to load modules as a user, which is not allowed ("permission denied"). A quick workaround is to add 'Load "v4l"' to XF86Config-4 when you use X by default, or to run 'v4l-conf -c <device>' in one of your startup scripts (normally rc.local) if you don't use X. Both make sure that the modules are loaded on startup, under the root account.

What mainboard should I use (or why doesn't my card work) #

<insert lousy disclaimer here>. In short: good=SiS/Intel, bad=VIA.

Experience tells us that people with a Buz, on average, have more problems than users with a DC10+/LML33. Also, it tells us that people owning a VIA- based mainboard (ktXXX, MVP3) have more problems than users with a mainboard based on a different chipset. Here's some notes from Andrew Stevens:

Here's my experience of using LML33 and Buz on various motherboards:

    • VIA MVP3

      • Forget it. Pointless. Doesn't work.
    • Intel 430FX (Pentium 200)

      • LML33 perfect, Buz tolerable (3 or 4 frames dropped per movie)
    • Intel 440BX (early stepping)

      • LML33 tolerable. Buz starting to get annoying (6-10 frames/hour)
    • Intel 440BX (late stepping)

      • Buz tolerable, LML3 almost perfect (occasional single frame drops)
    • SiS735

      • LML33 perfect, Buz tolerable.
    • VIA KT133(*)

      • LML33 starting to get annoying, Buz poor enough that I have up.
  • Both 440BX boards were dual CPU versions.

Bernhard Praschinger later added:

    • AMD 751

      • Buz perfect-tolerable
    • AMD 760

      • Buz perfect-tolerable

In general, people on the user mailinglist won't give you much of a chance if you have a VIA-based motherboard. They may be cheap, but sometimes, you'd rather want to spend some more money on better boards. In general, VIA mainboard's IDE/PCI performance will also suck badly compared to others. You'll noticed the DC10+/DC30+ aren't mentioned anywhere in the overview. Basically, you can assume that if the Buz works, the LML33 will work too. If the LML33 works, the DC10+/DC30+ will work too. They're most tolerant to different mainboard chipsets from all of the supported cards.

If you experience timeouts during capture, buy a better mainboard or lower the quality/buffersize during capture (see 'Concerning buffer sizes, quality, output size etc.'). If it hangs, there's little we can do as of now. Check your IRQs and make sure the card has its own interrupts.

Programming interface #

This driver conforms to video4linux2. Support for V4L1 and for the custom zoran ioctls has been removed in kernel 2.6.38.

For programming example, please, look at lavrec.c and lavplay.c code in the MJPEG-tools (http://mjpeg.sf.net/).

Additional notes for software developers:

The driver returns maxwidth and maxheight parameters according to the current TV standard (norm). Therefore, the software which communicates with the driver and "asks" for these parameters should first set the correct norm. Well, it seems logically correct: TV standard is "more constant" for current country than geometry settings of a variety of TV capture cards which may work in ITU or square pixel format.

Applications #

Applications known to work with this driver:

TV viewing:

  • xawtv

  • kwintv

  • probably any TV application that supports video4linux or video4linux2.

MJPEG capture/playback:

  • mjpegtools/lavtools (or Linux Video Studio)

  • gstreamer

  • mplayer

General raw capture:

  • xawtv

  • gstreamer

  • probably any application that supports video4linux or video4linux2

Video editing:

  • Cinelerra

  • MainActor

  • mjpegtools (or Linux Video Studio)

Concerning buffer sizes, quality, output size etc. #

The zr36060 can do 1:2 JPEG compression. This is really the theoretical maximum that the chipset can reach. The driver can, however, limit compression to a maximum (size) of 1:4. The reason for this is that some cards (e.g. Buz) can't handle 1:2 compression without stopping capture after only a few minutes. With 1:4, it'll mostly work. If you have a Buz, use 'low_bitrate=1' to go into 1:4 max. compression mode.

100% JPEG quality is thus 1:2 compression in practice. So for a full PAL frame (size 720x576). The JPEG fields are stored in YUY2 format, so the size of the fields are 720x288x16/2 bits/field (2 fields/frame) = 207360 bytes/field x 2 = 414720 bytes/frame (add some more bytes for headers and DHT (huffman)/DQT (quantization) tables, and you'll get to something like 512kB per frame for 1:2 compression. For 1:4 compression, you'd have frames of half this size.

Some additional explanation by Martin Samuelsson, which also explains the importance of buffer sizes: -- > Hmm, I do not think it is really that way. With the current (downloaded > at 18:00 Monday) driver I get that output sizes for 10 sec: > -q 50 -b 128 : 24.283.332 Bytes > -q 50 -b 256 : 48.442.368 > -q 25 -b 128 : 24.655.992 > -q 25 -b 256 : 25.859.820

I woke up, and can't go to sleep again. I'll kill some time explaining why this doesn't look strange to me.

Let's do some math using a width of 704 pixels. I'm not sure whether the Buz actually use that number or not, but that's not too important right now.

704x288 pixels, one field, is 202752 pixels. Divided by 64 pixels per block; 3168 blocks per field. Each pixel consist of two bytes; 128 bytes per block; 1024 bits per block. 100% in the new driver mean 1:2 compression; the maximum output becomes 512 bits per block. Actually 510, but 512 is simpler to use for calculations.

Let's say that we specify d1q50. We thus want 256 bits per block; times 3168 becomes 811008 bits; 101376 bytes per field. We're talking raw bits and bytes here, so we don't need to do any fancy corrections for bits-per-pixel or such things. 101376 bytes per field.

d1 video contains two fields per frame. Those sum up to 202752 bytes per frame, and one of those frames goes into each buffer.

But wait a second! -b128 gives 128kB buffers! It's not possible to cram 202752 bytes of JPEG data into 128kB!

This is what the driver notice and automatically compensate for in your examples. Let's do some math using this information:

128kB is 131072 bytes. In this buffer, we want to store two fields, which leaves 65536 bytes for each field. Using 3168 blocks per field, we get 20.68686868... available bytes per block; 165 bits. We can't allow the request for 256 bits per block when there's only 165 bits available! The -q50 option is silently overridden, and the -b128 option takes precedence, leaving us with the equivalence of -q32.

This gives us a data rate of 165 bits per block, which, times 3168, sums up to 65340 bytes per field, out of the allowed 65536. The current driver has another level of rate limiting; it won't accept -q values that fill more than 6/8 of the specified buffers. (I'm not sure why. "Playing it safe" seem to be a safe bet. Personally, I think I would have lowered requested-bits-per-block by one, or something like that.) We can't use 165 bits per block, but have to lower it again, to 6/8 of the available buffer space: We end up with 124 bits per block, the equivalence of -q24. With 128kB buffers, you can't use greater than -q24 at -d1. (And PAL, and 704 pixels width...)

The third example is limited to -q24 through the same process. The second example, using very similar calculations, is limited to -q48. The only example that actually grab at the specified -q value is the last one, which is clearly visible, looking at the file size. --

Conclusion: the quality of the resulting movie depends on buffer size, quality, whether or not you use 'low_bitrate=1' as insmod option for the zr36060.c module to do 1:4 instead of 1:2 compression, etc.

If you experience timeouts, lowering the quality/buffersize or using 'low_bitrate=1 as insmod option for zr36060.o might actually help, as is proven by the Buz.

It hangs/crashes/fails/whatevers! Help! #

Make sure that the card has its own interrupts (see /proc/interrupts), check the output of dmesg at high verbosity (load zr36067.o with debug=2, load all other modules with debug=1). Check that your mainboard is favorable (see question 2) and if not, test the card in another computer. Also see the notes given in question 3 and try lowering quality/buffersize/capturesize if recording fails after a period of time.

If all this doesn't help, give a clear description of the problem including detailed hardware information (memory+brand, mainboard+chipset+brand, which MJPEG card, processor, other PCI cards that might be of interest), give the system PnP information (/proc/interrupts, /proc/dma, /proc/devices), and give the kernel version, driver version, glibc version, gcc version and any other information that might possibly be of interest. Also provide the dmesg output at high verbosity. See 'Contacting' on how to contact the developers.

Maintainers/Contacting #

Previous maintainers/developers of this driver are - Laurent Pinchart <laurent.pinchart@skynet.be> - Ronald Bultje rbultje@ronald.bitfreak.net - Serguei Miridonov <mirsev@cicese.mx> - Wolfgang Scherr <scherr@net4you.net> - Dave Perks <dperks@ibm.net> - Rainer Johanni <Rainer@Johanni.de>

Driver's License #

This driver is distributed under the terms of the General Public License.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

See http://www.gnu.org/ for more information.

Peios Learn — documentation for Peios software.

Built with Trail.