4 Memory at cx2341x chips
5 -----------------------
7 This section describes the cx2341x memory map and documents some of the
10 .. note:: the memory long words are little-endian ('intel format').
14 This information was figured out from searching through the memory
15 and registers, this information may not be correct and is certainly
16 not complete, and was not derived from anything more than searching
17 through the memory space with commands like:
21 ivtvctl -O min=0x02000000,max=0x020000ff
23 So take this as is, I'm always searching for more stuff, it's a large
29 The cx2341x exposes its entire 64M memory space to the PCI host via the PCI BAR0
30 (Base Address Register 0). The addresses here are offsets relative to the
35 0x00000000-0x00ffffff Encoder memory space
36 0x00000000-0x0003ffff Encode.rom
37 ???-??? MPEG buffer(s)
38 ???-??? Raw video capture buffer(s)
39 ???-??? Raw audio capture buffer(s)
40 ???-??? Display buffers (6 or 9)
42 0x01000000-0x01ffffff Decoder memory space
43 0x01000000-0x0103ffff Decode.rom
44 ???-??? MPEG buffers(s)
45 0x0114b000-0x0115afff Audio.rom (deprecated?)
47 0x02000000-0x0200ffff Register Space
52 The registers occupy the 64k space starting at the 0x02000000 offset from BAR0.
53 All of these registers are 32 bits wide.
57 DMA Registers 0x000-0xff:
60 0=reset/cancel, 1=read, 2=write, 4=stop
62 1=read busy, 2=write busy, 4=read error, 8=write error, 16=link list error
63 0x08 - pci DMA pointer for read link list
64 0x0c - pci DMA pointer for write link list
65 0x10 - read/write DMA enable:
66 1=read enable, 2=write enable
67 0x14 - always 0xffffffff, if set any lower instability occurs, 0x00 crashes
69 0x1c - always 0x20 or 32, smaller values slow down DMA transactions
70 0x20 - always value of 0x780a010a
71 0x24-0x3c - usually just random values???
72 0x40 - Interrupt status
73 0x44 - Write a bit here and shows up in Interrupt status 0x40
75 0x4C - always value of 0xfffdffff,
76 if changed to 0xffffffff DMA write interrupts break.
77 0x50 - always 0xffffffff
78 0x54 - always 0xffffffff (0x4c, 0x50, 0x54 seem like interrupt masks, are
79 3 processors on chip, Java ones, VPU, SPU, APU, maybe these are the
81 0x60-0x7C - random values
82 0x80 - first write linked list reg, for Encoder Memory addr
83 0x84 - first write linked list reg, for pci memory addr
84 0x88 - first write linked list reg, for length of buffer in memory addr
85 (|0x80000000 or this for last link)
86 0x8c-0xdc - rest of write linked list reg, 8 sets of 3 total, DMA goes here
87 from linked list addr in reg 0x0c, firmware must push through or
89 0xe0 - first (and only) read linked list reg, for pci memory addr
90 0xe4 - first (and only) read linked list reg, for Decoder memory addr
91 0xe8 - first (and only) read linked list reg, for length of buffer
92 0xec-0xff - Nothing seems to be in these registers, 0xec-f4 are 0x00000000.
94 Memory locations for Encoder Buffers 0x700-0x7ff:
96 These registers show offsets of memory locations pertaining to each
97 buffer area used for encoding, have to shift them by <<1 first.
99 - 0x07F8: Encoder SDRAM refresh
100 - 0x07FC: Encoder SDRAM pre-charge
102 Memory locations for Decoder Buffers 0x800-0x8ff:
104 These registers show offsets of memory locations pertaining to each
105 buffer area used for decoding, have to shift them by <<1 first.
107 - 0x08F8: Decoder SDRAM refresh
108 - 0x08FC: Decoder SDRAM pre-charge
110 Other memory locations:
112 - 0x2800: Video Display Module control
113 - 0x2D00: AO (audio output?) control
114 - 0x2D24: Bytes Flushed
115 - 0x7000: LSB I2C write clock bit (inverted)
116 - 0x7004: LSB I2C write data bit (inverted)
117 - 0x7008: LSB I2C read clock bit
118 - 0x700c: LSB I2C read data bit
119 - 0x9008: GPIO get input state
120 - 0x900c: GPIO set output state
121 - 0x9020: GPIO direction (Bit7 (GPIO 0..7) - 0:input, 1:output)
122 - 0x9050: SPU control
123 - 0x9054: Reset HW blocks
124 - 0x9058: VPU control
125 - 0xA018: Bit6: interrupt pending?
126 - 0xA064: APU command
129 Interrupt Status Register
130 ~~~~~~~~~~~~~~~~~~~~~~~~~
132 The definition of the bits in the interrupt status register 0x0040, and the
133 interrupt mask 0x0048. If a bit is cleared in the mask, then we want our ISR to
136 - bit 31 Encoder Start Capture
138 - bit 29 Encoder VBI capture
139 - bit 28 Encoder Video Input Module reset event
140 - bit 27 Encoder DMA complete
141 - bit 24 Decoder audio mode change detection event (through event notification)
142 - bit 22 Decoder data request
143 - bit 20 Decoder DMA complete
144 - bit 19 Decoder VBI re-insertion
145 - bit 18 Decoder DMA err (linked-list bad)
147 Missing documentation
148 ---------------------
150 - Encoder API post(?)
151 - Decoder API post(?)
152 - Decoder VTRACE event
155 The cx2341x firmware upload
156 ---------------------------
158 This document describes how to upload the cx2341x firmware to the card.
163 See the web pages of the various projects that uses this chip for information
164 on how to obtain the firmware.
166 The firmware stored in a Windows driver can be detected as follows:
168 - Each firmware image is 256k bytes.
169 - The 1st 32-bit word of the Encoder image is 0x0000da7
170 - The 1st 32-bit word of the Decoder image is 0x00003a7
171 - The 2nd 32-bit word of both images is 0xaa55bb66
176 - Issue the FWapi command to stop the encoder if it is running. Wait for the
178 - Issue the FWapi command to stop the decoder if it is running. Wait for the
180 - Issue the I2C command to the digitizer to stop emitting VSYNC events.
181 - Issue the FWapi command to halt the encoder's firmware.
183 - Issue the FWapi command to halt the decoder's firmware.
185 - Write 0x00000000 to register 0x2800 to stop the Video Display Module.
186 - Write 0x00000005 to register 0x2D00 to stop the AO (audio output?).
187 - Write 0x00000000 to register 0xA064 to ping? the APU.
188 - Write 0xFFFFFFFE to register 0x9058 to stop the VPU.
189 - Write 0xFFFFFFFF to register 0x9054 to reset the HW blocks.
190 - Write 0x00000001 to register 0x9050 to stop the SPU.
192 - Write 0x0000001A to register 0x07FC to init the Encoder SDRAM's pre-charge.
193 - Write 0x80000640 to register 0x07F8 to init the Encoder SDRAM's refresh to 1us.
194 - Write 0x0000001A to register 0x08FC to init the Decoder SDRAM's pre-charge.
195 - Write 0x80000640 to register 0x08F8 to init the Decoder SDRAM's refresh to 1us.
196 - Sleep for 512ms. (600ms is recommended)
197 - Transfer the encoder's firmware image to offset 0 in Encoder memory space.
198 - Transfer the decoder's firmware image to offset 0 in Decoder memory space.
199 - Use a read-modify-write operation to Clear bit 0 of register 0x9050 to
201 - Sleep for 1 second.
202 - Use a read-modify-write operation to Clear bits 3 and 0 of register 0x9058
203 to re-enable the VPU.
204 - Sleep for 1 second.
205 - Issue status API commands to both firmware images to verify.
208 How to call the firmware API
209 ----------------------------
211 The preferred calling convention is known as the firmware mailbox. The
212 mailboxes are basically a fixed length array that serves as the call-stack.
214 Firmware mailboxes can be located by searching the encoder and decoder memory
215 for a 16 byte signature. That signature will be located on a 256-byte boundary.
221 0x78, 0x56, 0x34, 0x12, 0x12, 0x78, 0x56, 0x34,
222 0x34, 0x12, 0x78, 0x56, 0x56, 0x34, 0x12, 0x78
224 The firmware implements 20 mailboxes of 20 32-bit words. The first 10 are
225 reserved for API calls. The second 10 are used by the firmware for event
228 ====== =================
230 ====== =================
235 4-19 Parameter/Result
236 ====== =================
239 The flags are defined in the following table. The direction is from the
240 perspective of the firmware.
242 ==== ========== ============================================
243 Bit Direction Purpose
244 ==== ========== ============================================
245 2 O Firmware has processed the command.
246 1 I Driver has finished setting the parameters.
247 0 I Driver is using this mailbox.
248 ==== ========== ============================================
250 The command is a 32-bit enumerator. The API specifics may be found in this
253 The return value is a 32-bit enumerator. Only two values are currently defined:
256 - -1=command undefined.
258 There are 16 parameters/results 32-bit fields. The driver populates these fields
259 with values for all the parameters required by the call. The driver overwrites
260 these fields with result values returned by the call.
262 The timeout value protects the card from a hung driver thread. If the driver
263 doesn't handle the completed call within the timeout specified, the firmware
264 will reset that mailbox.
266 To make an API call, the driver iterates over each mailbox looking for the
267 first one available (bit 0 has been cleared). The driver sets that bit, fills
268 in the command enumerator, the timeout value and any required parameters. The
269 driver then sets the parameter ready bit (bit 1). The firmware scans the
270 mailboxes for pending commands, processes them, sets the result code, populates
271 the result value array with that call's return values and sets the call
272 complete bit (bit 2). Once bit 2 is set, the driver should retrieve the results
273 and clear all the flags. If the driver does not perform this task within the
274 time set in the timeout register, the firmware will reset that mailbox.
276 Event notifications are sent from the firmware to the host. The host tells the
277 firmware which events it is interested in via an API call. That call tells the
278 firmware which notification mailbox to use. The firmware signals the host via
279 an interrupt. Only the 16 Results fields are used, the Flags, Command, Return
280 value and Timeout words are not used.
283 OSD firmware API description
284 ----------------------------
286 .. note:: this API is part of the decoder firmware, so it's cx23415 only.
290 CX2341X_OSD_GET_FRAMEBUFFER
291 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
298 Return base and length of contiguous OSD memory.
312 CX2341X_OSD_GET_PIXEL_FORMAT
313 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
333 CX2341X_OSD_SET_PIXEL_FORMAT
334 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
348 - 2=16bit ARGB 1:5:5:5
349 - 3=16bit ARGB 1:4:4:4
350 - 4=32bit ARGB 8:8:8:8
354 CX2341X_OSD_GET_STATE
355 ~~~~~~~~~~~~~~~~~~~~~
368 - Bits 1:2 alpha control
369 - Bits 3:5 pixel format
373 CX2341X_OSD_SET_STATE
374 ~~~~~~~~~~~~~~~~~~~~~
390 CX2341X_OSD_GET_OSD_COORDS
391 ~~~~~~~~~~~~~~~~~~~~~~~~~~
398 Retrieve coordinates of OSD area blended with video
418 Horizontal offset in buffer
423 Vertical offset in buffer
427 CX2341X_OSD_SET_OSD_COORDS
428 ~~~~~~~~~~~~~~~~~~~~~~~~~~
435 Assign the coordinates of the OSD area to blend with video
445 buffer stride in pixels
464 CX2341X_OSD_GET_SCREEN_COORDS
465 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
472 Retrieve OSD screen area coordinates
477 top left horizontal offset
482 top left vertical offset
487 bottom right horizontal offset
492 bottom right vertical offset
496 CX2341X_OSD_SET_SCREEN_COORDS
497 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
504 Assign the coordinates of the screen area to blend with video
509 top left horizontal offset
514 top left vertical offset
519 bottom left horizontal offset
524 bottom left vertical offset
528 CX2341X_OSD_GET_GLOBAL_ALPHA
529 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
536 Retrieve OSD global alpha
541 global alpha: 0=off, 1=on
546 bits 0:7 global alpha
550 CX2341X_OSD_SET_GLOBAL_ALPHA
551 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
563 global alpha: 0=off, 1=on
568 global alpha (8 bits)
573 local alpha: 0=on, 1=off
577 CX2341X_OSD_SET_BLEND_COORDS
578 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
585 Move start of blending area within display buffer
590 horizontal offset in buffer
595 vertical offset in buffer
599 CX2341X_OSD_GET_FLICKER_STATE
600 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
607 Retrieve flicker reduction module state
612 flicker state: 0=off, 1=on
616 CX2341X_OSD_SET_FLICKER_STATE
617 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
624 Set flicker reduction module state
649 '0001' ~destination AND ~source
650 '0010' ~destination AND source
652 '0100' destination AND ~source
654 '0110' destination XOR source
655 '0111' ~destination OR ~source
656 '1000' ~destination AND ~source
657 '1001' destination XNOR source
659 '1011' ~destination OR source
661 '1101' destination OR ~source
662 '1110' destination OR source
669 Resulting alpha blending
672 - '10' destination_alpha
673 - '11' source_alpha*destination_alpha+1
674 (zero if both source and destination alpha are zero)
681 '00' output_pixel = source_pixel
683 '01' if source_alpha=0:
684 output_pixel = destination_pixel
685 if 256 > source_alpha > 1:
686 output_pixel = ((source_alpha + 1)*source_pixel +
687 (255 - source_alpha)*destination_pixel)/256
689 '10' if destination_alpha=0:
690 output_pixel = source_pixel
691 if 255 > destination_alpha > 0:
692 output_pixel = ((255 - destination_alpha)*source_pixel +
693 (destination_alpha + 1)*destination_pixel)/256
695 '11' if source_alpha=0:
698 source_temp = source_pixel*256
699 if 255 > source_alpha > 0:
700 source_temp = source_pixel*(source_alpha + 1)
701 if destination_alpha=0:
703 if destination_alpha=255:
704 destination_temp = destination_pixel*256
705 if 255 > destination_alpha > 0:
706 destination_temp = destination_pixel*(destination_alpha + 1)
707 output_pixel = (source_temp + destination_temp)/256
722 destination pixel mask
727 destination rectangle start address
732 destination stride in dwords
737 source stride in dwords
742 source rectangle start address
759 Same as Param[0] on API 0x52
764 Same as Param[1] on API 0x52
769 Same as Param[2] on API 0x52
784 destination pixel mask
789 destination rectangle start address
794 destination stride in dwords
811 BLT for 8 bit alpha text source
816 Same as Param[0] on API 0x52
821 Same as Param[1] on API 0x52
826 Same as Param[2] on API 0x52
841 destination pixel mask
846 destination rectangle start address
851 destination stride in dwords
856 source stride in dwords
861 source rectangle start address
870 CX2341X_OSD_SET_FRAMEBUFFER_WINDOW
871 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
878 Positions the main output window on the screen. The coordinates must be
879 such that the entire window fits on the screen.
894 top left window corner horizontal offset
899 top left window corner vertical offset
903 CX2341X_OSD_SET_CHROMA_KEY
904 ~~~~~~~~~~~~~~~~~~~~~~~~~~
911 Chroma key switch and color
925 CX2341X_OSD_GET_ALPHA_CONTENT_INDEX
926 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
933 Retrieve alpha content index
938 alpha content index, Range 0:15
942 CX2341X_OSD_SET_ALPHA_CONTENT_INDEX
943 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
950 Assign alpha content index
955 alpha content index, range 0:15
958 Encoder firmware API description
959 --------------------------------
969 Does nothing. Can be used to check if the firmware is responding.
973 CX2341X_ENC_START_CAPTURE
974 ~~~~~~~~~~~~~~~~~~~~~~~~~
981 Commences the capture of video, audio and/or VBI data. All encoding
982 parameters must be initialized prior to this API call. Captures frames
983 continuously or until a predefined number of frames have been captured.
1001 - Bit 0 when set, captures YUV
1002 - Bit 1 when set, captures PCM audio
1003 - Bit 2 when set, captures VBI (same as param[0]=3)
1004 - Bit 3 when set, the capture destination is the decoder
1005 (same as param[0]=2)
1006 - Bit 4 when set, the capture destination is the host
1008 .. note:: this parameter is only meaningful for RAW capture type.
1012 CX2341X_ENC_STOP_CAPTURE
1013 ~~~~~~~~~~~~~~~~~~~~~~~~
1020 Ends a capture in progress
1025 - 0=stop at end of GOP (generates IRQ)
1026 - 1=stop immediate (no IRQ)
1031 Stream type to stop, see param[0] of API 0x81
1036 Subtype, see param[1] of API 0x81
1040 CX2341X_ENC_SET_AUDIO_ID
1041 ~~~~~~~~~~~~~~~~~~~~~~~~
1048 Assigns the transport stream ID of the encoded audio stream
1057 CX2341X_ENC_SET_VIDEO_ID
1058 ~~~~~~~~~~~~~~~~~~~~~~~~
1065 Set video transport stream ID
1074 CX2341X_ENC_SET_PCR_ID
1075 ~~~~~~~~~~~~~~~~~~~~~~
1082 Assigns the transport stream ID for PCR packets
1091 CX2341X_ENC_SET_FRAME_RATE
1092 ~~~~~~~~~~~~~~~~~~~~~~~~~~
1099 Set video frames per second. Change occurs at start of new GOP.
1109 CX2341X_ENC_SET_FRAME_SIZE
1110 ~~~~~~~~~~~~~~~~~~~~~~~~~~
1117 Select video stream encoding resolution.
1122 Height in lines. Default 480
1127 Width in pixels. Default 720
1131 CX2341X_ENC_SET_BIT_RATE
1132 ~~~~~~~~~~~~~~~~~~~~~~~~
1139 Assign average video stream bitrate.
1144 0=variable bitrate, 1=constant bitrate
1149 bitrate in bits per second
1154 peak bitrate in bits per second, divided by 400
1159 Mux bitrate in bits per second, divided by 400. May be 0 (default).
1164 Rate Control VBR Padding
1169 VBV Buffer used by encoder
1173 #) Param\[3\] and Param\[4\] seem to be always 0
1174 #) Param\[5\] doesn't seem to be used.
1178 CX2341X_ENC_SET_GOP_PROPERTIES
1179 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1186 Setup the GOP structure
1191 GOP size (maximum is 34)
1196 Number of B frames between the I and P frame, plus 1.
1197 For example: IBBPBBPBBPBB --> GOP size: 12, number of B frames: 2+1 = 3
1201 GOP size must be a multiple of (B-frames + 1).
1205 CX2341X_ENC_SET_ASPECT_RATIO
1206 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1213 Sets the encoding aspect ratio. Changes in the aspect ratio take effect
1214 at the start of the next GOP.
1224 - '0101' to '1111' reserved
1228 CX2341X_ENC_SET_DNR_FILTER_MODE
1229 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1236 Assign Dynamic Noise Reduction operating mode
1241 Bit0: Spatial filter, set=auto, clear=manual
1242 Bit1: Temporal filter, set=auto, clear=manual
1257 CX2341X_ENC_SET_DNR_FILTER_PROPS
1258 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1265 These Dynamic Noise Reduction filter values are only meaningful when
1266 the respective filter is set to "manual" (See API 0x9B)
1271 Spatial filter: default 0, range 0:15
1276 Temporal filter: default 0, range 0:31
1280 CX2341X_ENC_SET_CORING_LEVELS
1281 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1288 Assign Dynamic Noise Reduction median filter properties.
1293 Threshold above which the luminance median filter is enabled.
1294 Default: 0, range 0:255
1299 Threshold below which the luminance median filter is enabled.
1300 Default: 255, range 0:255
1305 Threshold above which the chrominance median filter is enabled.
1306 Default: 0, range 0:255
1311 Threshold below which the chrominance median filter is enabled.
1312 Default: 255, range 0:255
1316 CX2341X_ENC_SET_SPATIAL_FILTER_TYPE
1317 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1324 Assign spatial prefilter parameters
1334 - 3=2D H/V Separable (default)
1335 - 4=2D Symmetric non-separable
1343 - 1=1D Horizontal (default)
1347 CX2341X_ENC_SET_VBI_LINE
1348 ~~~~~~~~~~~~~~~~~~~~~~~~
1355 Selects VBI line number.
1360 - Bits 0:4 line number
1361 - Bit 31 0=top_field, 1=bottom_field
1362 - Bits 0:31 all set specifies "all lines"
1367 VBI line information features: 0=disabled, 1=enabled
1372 Slicing: 0=None, 1=Closed Caption
1373 Almost certainly not implemented. Set to 0.
1378 Luminance samples in this line.
1379 Almost certainly not implemented. Set to 0.
1384 Chrominance samples in this line
1385 Almost certainly not implemented. Set to 0.
1389 CX2341X_ENC_SET_STREAM_TYPE
1390 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1401 Transport stream is not working in recent firmwares.
1402 And in older firmwares the timestamps in the TS seem to be
1409 - 1=Transport stream
1412 - 5=PES Video stream
1413 - 7=PES Audio stream
1422 CX2341X_ENC_SET_OUTPUT_PORT
1423 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1430 Assign stream output port. Normally 0 when the data is copied through
1431 the PCI bus (DMA), and 1 when the data is streamed to another chip
1432 (pvrusb and cx88-blackbird).
1437 - 0=Memory (default)
1444 Unknown, but leaving this to 0 seems to work best. Indications are that
1445 this might have to do with USB support, although passing anything but 0
1450 CX2341X_ENC_SET_AUDIO_PROPERTIES
1451 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1458 Set audio stream properties, may be called while encoding is in progress.
1462 All bitfields are consistent with ISO11172 documentation except
1463 bits 2:3 which ISO docs define as:
1470 This discrepancy may indicate a possible error in the documentation.
1471 Testing indicated that only Layer II is actually working, and that
1472 the minimum bitrate should be 192 kbps.
1479 .. code-block:: none
1490 Index | Layer I | Layer II
1491 ------+-------------+------------
1492 '0000' | free format | free format
1493 '0001' | 32 kbit/s | 32 kbit/s
1494 '0010' | 64 kbit/s | 48 kbit/s
1495 '0011' | 96 kbit/s | 56 kbit/s
1496 '0100' | 128 kbit/s | 64 kbit/s
1497 '0101' | 160 kbit/s | 80 kbit/s
1498 '0110' | 192 kbit/s | 96 kbit/s
1499 '0111' | 224 kbit/s | 112 kbit/s
1500 '1000' | 256 kbit/s | 128 kbit/s
1501 '1001' | 288 kbit/s | 160 kbit/s
1502 '1010' | 320 kbit/s | 192 kbit/s
1503 '1011' | 352 kbit/s | 224 kbit/s
1504 '1100' | 384 kbit/s | 256 kbit/s
1505 '1101' | 416 kbit/s | 320 kbit/s
1506 '1110' | 448 kbit/s | 384 kbit/s
1510 For Layer II, not all combinations of total bitrate
1511 and mode are allowed. See ISO11172-3 3-Annex B,
1521 The cx23415 cannot decode Joint Stereo properly.
1523 10:11 Mode Extension used in joint_stereo mode.
1524 In Layer I and II they indicate which subbands are in
1525 intensity_stereo. All other subbands are coded in stereo.
1526 '00' subbands 4-31 in intensity_stereo, bound==4
1527 '01' subbands 8-31 in intensity_stereo, bound==8
1528 '10' subbands 12-31 in intensity_stereo, bound==12
1529 '11' subbands 16-31 in intensity_stereo, bound==16
1559 The firmware is halted and no further API calls are serviced until the
1560 firmware is uploaded again.
1564 CX2341X_ENC_GET_VERSION
1565 ~~~~~~~~~~~~~~~~~~~~~~~
1572 Returns the version of the encoder firmware.
1584 CX2341X_ENC_SET_GOP_CLOSURE
1585 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
1592 Assigns the GOP open/close property.
1602 CX2341X_ENC_GET_SEQ_END
1603 ~~~~~~~~~~~~~~~~~~~~~~~
1610 Obtains the sequence end code of the encoder's buffer. When a capture
1611 is started a number of interrupts are still generated, the last of
1612 which will have Result[0] set to 1 and Result[1] will contain the size
1618 State of the transfer (1 if last buffer)
1623 If Result[0] is 1, this contains the size of the last buffer, undefined
1628 CX2341X_ENC_SET_PGM_INDEX_INFO
1629 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1636 Sets the Program Index Information.
1637 The information is stored as follows:
1642 u32 length; // Length of this frame
1643 u32 offset_low; // Offset in the file of the
1644 u32 offset_high; // start of this frame
1645 u32 mask1; // Bits 0-2 are the type mask:
1647 // 0=End of Program Index, other fields
1649 u32 pts; // The PTS of the frame
1650 u32 mask2; // Bit 0 is bit 32 of the pts.
1653 struct info index[400];
1655 The table_ptr is the encoder memory address in the table were
1656 *new* entries will be written.
1658 .. note:: This is a ringbuffer, so the table_ptr will wraparound.
1664 - 0=No index capture
1669 (Seems to be ignored, it always indexes I, P and B frames)
1674 Elements requested (up to 400)
1679 Offset in the encoder memory of the start of the table.
1684 Number of allocated elements up to a maximum of Param[1]
1688 CX2341X_ENC_SET_VBI_CONFIG
1689 ~~~~~~~~~~~~~~~~~~~~~~~~~~
1696 Configure VBI settings
1703 .. code-block:: none
1705 0 Mode '0' Sliced, '1' Raw
1707 '000' insert in extension & user data
1708 '001' insert in private packets
1709 '010' separate stream and user data
1710 '111' separate stream and private data
1711 8:15 Stream ID (normally 0xBD)
1716 Frames per interrupt (max 8). Only valid in raw mode.
1721 Total raw VBI frames. Only valid in raw mode.
1746 Observed frames per interrupt in raw mode only. Rage 1 to Param[1]
1751 Observed number of frames in raw mode. Range 1 to Param[2]
1756 Memory offset to start or raw VBI data
1760 CX2341X_ENC_SET_DMA_BLOCK_SIZE
1761 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1768 Set DMA transfer block size
1773 DMA transfer block size in bytes or frames. When unit is bytes,
1774 supported block sizes are 2^7, 2^8 and 2^9 bytes.
1779 Unit: 0=bytes, 1=frames
1783 CX2341X_ENC_GET_PREV_DMA_INFO_MB_10
1784 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1791 Returns information on the previous DMA transfer in conjunction with
1792 bit 27 of the interrupt mask. Uses mailbox 10.
1807 Maximum size of transfer
1811 CX2341X_ENC_GET_PREV_DMA_INFO_MB_9
1812 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1819 Returns information on the previous DMA transfer in conjunction with
1820 bit 27 or 18 of the interrupt mask. Uses mailbox 9.
1830 - 4 Scatter-Gather array error
1840 Presentation Time Stamp bits 0..31
1845 Presentation Time Stamp bit 32
1849 CX2341X_ENC_SCHED_DMA_TO_HOST
1850 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1857 Setup DMA to host operation
1862 Memory address of link list
1867 Length of link list (wtf: what units ???)
1876 CX2341X_ENC_INITIALIZE_INPUT
1877 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1884 Initializes the video input
1888 CX2341X_ENC_SET_FRAME_DROP_RATE
1889 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1896 For each frame captured, skip specified number of frames.
1901 Number of frames to skip
1905 CX2341X_ENC_PAUSE_ENCODER
1906 ~~~~~~~~~~~~~~~~~~~~~~~~~
1913 During a pause condition, all frames are dropped instead of being encoded.
1919 - 1=Continue encoding
1923 CX2341X_ENC_REFRESH_INPUT
1924 ~~~~~~~~~~~~~~~~~~~~~~~~~
1931 Refreshes the video input
1935 CX2341X_ENC_SET_COPYRIGHT
1936 ~~~~~~~~~~~~~~~~~~~~~~~~~
1943 Sets stream copyright property
1949 - 0=Stream is not copyrighted
1950 - 1=Stream is copyrighted
1954 CX2341X_ENC_SET_EVENT_NOTIFICATION
1955 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1962 Setup firmware to notify the host about a particular event. Host must
1963 unmask the interrupt bit.
1968 Event (0=refresh encoder input)
1973 Notification 0=disabled 1=enabled
1983 Mailbox slot, -1 if no mailbox required.
1987 CX2341X_ENC_SET_NUM_VSYNC_LINES
1988 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1995 Depending on the analog video decoder used, this assigns the number
1996 of lines for field 1 and 2.
2001 Field 1 number of lines:
2002 - 0x00EF for SAA7114
2003 - 0x00F0 for SAA7115
2004 - 0x0105 for Micronas
2009 Field 2 number of lines:
2010 - 0x00EF for SAA7114
2011 - 0x00F0 for SAA7115
2012 - 0x0106 for Micronas
2016 CX2341X_ENC_SET_PLACEHOLDER
2017 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
2024 Provides a mechanism of inserting custom user data in the MPEG stream.
2029 - 0=extension & user data
2030 - 1=private packet with stream ID 0xBD
2035 Rate at which to insert data, in units of frames (for private packet)
2036 or GOPs (for ext. & user data)
2041 Number of data DWORDs (below) to insert
2090 CX2341X_ENC_MUTE_VIDEO
2091 ~~~~~~~~~~~~~~~~~~~~~~
2105 .. code-block:: none
2107 0 '0'=video not muted
2108 '1'=video muted, creates frames with the YUV color defined below
2110 8:15 V chrominance information
2111 16:23 U chrominance information
2112 24:31 Y luminance information
2116 CX2341X_ENC_MUTE_AUDIO
2117 ~~~~~~~~~~~~~~~~~~~~~~
2130 - 1=audio muted (produces silent mpeg audio stream)
2134 CX2341X_ENC_SET_VERT_CROP_LINE
2135 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2142 Something to do with 'Vertical Crop Line'
2147 If saa7114 and raw VBI capture and 60 Hz, then set to 10001.
2160 Miscellaneous actions. Not known for 100% what it does. It's really a
2161 sort of ioctl call. The first parameter is a command number, the second
2169 .. code-block:: none
2171 1=set initial SCR value when starting encoding (works).
2172 2=set quality mode (apparently some test setting).
2173 3=setup advanced VIM protection handling.
2174 Always 1 for the cx23416 and 0 for cx23415.
2175 4=generate DVD compatible PTS timestamps
2177 6=something to do with the quantization matrix
2178 7=set navigation pack insertion for DVD: adds 0xbf (private stream 2)
2179 packets to the MPEG. The size of these packets is 2048 bytes (including
2180 the header of 6 bytes: 0x000001bf + length). The payload is zeroed and
2181 it is up to the application to fill them in. These packets are apparently
2182 inserted every four frames.
2183 8=enable scene change detection (seems to be a failure)
2184 9=set history parameters of the video input module
2185 10=set input field order of VIM
2186 11=set quantization matrix
2187 12=reset audio interface after channel change or input switch (has no argument).
2188 Needed for the cx2584x, not needed for the mspx4xx, but it doesn't seem to
2189 do any harm calling it regardless.
2190 13=set audio volume delay
2199 Decoder firmware API description
2200 --------------------------------
2202 .. note:: this API is part of the decoder firmware, so it's cx23415 only.
2214 This API call does nothing. It may be used to check if the firmware
2219 CX2341X_DEC_START_PLAYBACK
2220 ~~~~~~~~~~~~~~~~~~~~~~~~~~
2227 Begin or resume playback.
2232 0 based frame number in GOP to begin playback from.
2237 Specifies the number of muted audio frames to play before normal
2238 audio resumes. (This is not implemented in the firmware, leave at 0)
2242 CX2341X_DEC_STOP_PLAYBACK
2243 ~~~~~~~~~~~~~~~~~~~~~~~~~
2250 Ends playback and clears all decoder buffers. If PTS is not zero,
2251 playback stops at specified PTS.
2256 Display 0=last frame, 1=black
2260 this takes effect immediately, so if you want to wait for a PTS,
2261 then use '0', otherwise the screen goes to black at once.
2262 You can call this later (even if there is no playback) with a 1 value
2263 to set the screen to black.
2277 CX2341X_DEC_SET_PLAYBACK_SPEED
2278 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2285 Playback stream at speed other than normal. There are two modes of
2288 - Smooth: host transfers entire stream and firmware drops unused
2290 - Coarse: host drops frames based on indexing as required to achieve
2296 .. code-block:: none
2300 1 fast only "1.5 times"
2301 n nX fast, 1/nX slow
2303 '0' during 1.5 times play, every other B frame is dropped
2304 '1' during 1.5 times play, stream is unchanged (bitrate
2305 must not exceed 8mbps)
2312 n is limited to 2. Anything higher does not result in
2313 faster playback. Instead the host should start dropping frames.
2318 Direction: 0=forward, 1=reverse
2322 to make reverse playback work you have to write full GOPs in
2328 .. code-block:: none
2338 B frames per GOP (for reverse play only)
2342 for reverse playback the Picture Mask should be set to I or I, P.
2343 Adding B frames to the mask will result in corrupt video. This field
2344 has to be set to the correct value in order to keep the timing correct.
2349 Mute audio: 0=disable, 1=enable
2354 Display 0=frame, 1=field
2359 Specifies the number of muted audio frames to play before normal audio
2360 resumes. (Not implemented in the firmware, leave at 0)
2364 CX2341X_DEC_STEP_VIDEO
2365 ~~~~~~~~~~~~~~~~~~~~~~
2372 Each call to this API steps the playback to the next unit defined below
2373 in the current playback direction.
2378 0=frame, 1=top field, 2=bottom field
2382 CX2341X_DEC_SET_DMA_BLOCK_SIZE
2383 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2390 Set DMA transfer block size. Counterpart to API 0xC9
2395 DMA transfer block size in bytes. A different size may be specified
2396 when issuing the DMA transfer command.
2400 CX2341X_DEC_GET_XFER_INFO
2401 ~~~~~~~~~~~~~~~~~~~~~~~~~
2408 This API call may be used to detect an end of stream condition.
2423 Maximum bytes to transfer
2432 CX2341X_DEC_GET_DMA_STATUS
2433 ~~~~~~~~~~~~~~~~~~~~~~~~~~
2440 Status of the last DMA transfer
2445 Bit 1 set means transfer complete
2446 Bit 2 set means DMA error
2447 Bit 3 set means linked list error
2452 DMA type: 0=MPEG, 1=OSD, 2=YUV
2456 CX2341X_DEC_SCHED_DMA_FROM_HOST
2457 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2464 Setup DMA from host operation. Counterpart to API 0xCC
2469 Memory address of link list
2474 Total # of bytes to transfer
2479 DMA type (0=MPEG, 1=OSD, 2=YUV)
2483 CX2341X_DEC_PAUSE_PLAYBACK
2484 ~~~~~~~~~~~~~~~~~~~~~~~~~~
2491 Freeze playback immediately. In this mode, when internal buffers are
2492 full, no more data will be accepted and data request IRQs will be
2498 Display: 0=last frame, 1=black
2510 The firmware is halted and no further API calls are serviced until
2511 the firmware is uploaded again.
2515 CX2341X_DEC_SET_STANDARD
2516 ~~~~~~~~~~~~~~~~~~~~~~~~
2523 Selects display standard
2532 CX2341X_DEC_GET_VERSION
2533 ~~~~~~~~~~~~~~~~~~~~~~~
2540 Returns decoder firmware version information
2552 CX2341X_DEC_SET_STREAM_INPUT
2553 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2560 Select decoder stream input port
2565 0=memory (default), 1=streaming
2569 CX2341X_DEC_GET_TIMING_INFO
2570 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
2577 Returns timing information from start of playback
2582 Frame count by decode order
2587 Video PTS bits 0:31 by display order
2592 Video PTS bit 32 by display order
2597 SCR bits 0:31 by display order
2602 SCR bit 32 by display order
2606 CX2341X_DEC_SET_AUDIO_MODE
2607 ~~~~~~~~~~~~~~~~~~~~~~~~~~
2619 Dual mono mode action
2620 0=Stereo, 1=Left, 2=Right, 3=Mono, 4=Swap, -1=Unchanged
2626 0=Stereo, 1=Left, 2=Right, 3=Mono, 4=Swap, -1=Unchanged
2630 CX2341X_DEC_SET_EVENT_NOTIFICATION
2631 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2638 Setup firmware to notify the host about a particular event.
2639 Counterpart to API 0xD5
2645 - 0=Audio mode change between mono, (joint) stereo and dual channel.
2647 - 4=Unknown: goes off 10-15 times per second while decoding.
2648 - 5=Some sync event: goes off once per frame.
2653 Notification 0=disabled, 1=enabled
2663 Mailbox slot, -1 if no mailbox required.
2667 CX2341X_DEC_SET_DISPLAY_BUFFERS
2668 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2675 Number of display buffers. To decode all frames in reverse playback you
2676 must use nine buffers.
2681 0=six buffers, 1=nine buffers
2685 CX2341X_DEC_EXTRACT_VBI
2686 ~~~~~~~~~~~~~~~~~~~~~~~
2698 0=extract from extension & user data, 1=extract from private packets
2712 CX2341X_DEC_SET_DECODER_SOURCE
2713 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2720 Selects decoder source. Ensure that the parameters passed to this
2721 API match the encoder settings.
2726 Mode: 0=MPEG from host, 1=YUV from encoder, 2=YUV from host
2741 Bitmap: see Param[0] of API 0xBD
2745 CX2341X_DEC_SET_PREBUFFERING
2746 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2753 Decoder prebuffering, when enabled up to 128KB are buffered for
2754 streams <8mpbs or 640KB for streams >8mbps
2761 PVR350 Video decoder registers 0x02002800 -> 0x02002B00
2762 -------------------------------------------------------
2764 Author: Ian Armstrong <ian@iarmst.demon.co.uk>
2771 This list has been worked out through trial and error. There will be mistakes
2772 and omissions. Some registers have no obvious effect so it's hard to say what
2773 they do, while others interact with each other, or require a certain load
2774 sequence. Horizontal filter setup is one example, with six registers working
2775 in unison and requiring a certain load sequence to correctly configure. The
2776 indexed colour palette is much easier to set at just two registers, but again
2777 it requires a certain load sequence.
2779 Some registers are fussy about what they are set to. Load in a bad value & the
2780 decoder will fail. A firmware reload will often recover, but sometimes a reset
2781 is required. For registers containing size information, setting them to 0 is
2782 generally a bad idea. For other control registers i.e. 2878, you'll only find
2783 out what values are bad when it hangs.
2785 .. code-block:: none
2787 --------------------------------------------------------------------------------
2793 --------------------------------------------------------------------------------
2796 Decoder horizontal Y alias register 1
2800 Decoder horizontal Y alias register 2
2804 Decoder horizontal Y alias register 3
2808 Decoder horizontal Y alias register 4
2812 Decoder horizontal Y alias register 5
2816 Decoder horizontal Y alias trigger
2818 These six registers control the horizontal aliasing filter for the Y plane.
2819 The first five registers must all be loaded before accessing the trigger
2820 (2818), as this register actually clocks the data through for the first
2823 To correctly program set the filter, this whole procedure must be done 16
2824 times. The actual register contents are copied from a lookup-table in the
2825 firmware which contains 4 different filter settings.
2827 --------------------------------------------------------------------------------
2830 Decoder horizontal UV alias register 1
2834 Decoder horizontal UV alias register 2
2838 Decoder horizontal UV alias register 3
2842 Decoder horizontal UV alias register 4
2846 Decoder horizontal UV alias register 5
2850 Decoder horizontal UV alias trigger
2852 These six registers control the horizontal aliasing for the UV plane.
2853 Operation is the same as the Y filter, with 2830 being the trigger
2856 --------------------------------------------------------------------------------
2859 Decoder Y source width in pixels
2862 Decoder Y destination width in pixels
2866 Decoder UV source width in pixels
2869 Decoder UV destination width in pixels
2871 NOTE: For both registers, the resulting image must be fully visible on
2872 screen. If the image exceeds the right edge both the source and destination
2873 size must be adjusted to reflect the visible portion. For the source width,
2874 you must take into account the scaling when calculating the new value.
2875 --------------------------------------------------------------------------------
2879 Decoder Y horizontal scaling
2880 Normally = Reg 2854 >> 2
2884 Decoder ?? unknown - horizontal scaling
2889 Decoder UV horizontal scaling
2890 Normally = Reg 2854 >> 2
2894 Decoder ?? unknown - horizontal scaling
2899 Decoder ?? unknown - Y plane
2904 Decoder ?? unknown - UV plane
2909 Decoder 'master' value for horizontal scaling
2919 Normally = Reg 2854 >> 1
2929 Normally = Reg 2854 >> 1
2936 Most of these registers either control horizontal scaling, or appear linked
2937 to it in some way. Register 2854 contains the 'master' value & the other
2938 registers can be calculated from that one. You must also remember to
2939 correctly set the divider in Reg 2874.
2942 Reg 2854 = (source_width * 0x00200000) / destination_width
2943 Reg 2874 = No divide
2945 To reduce from full size down to half size:
2946 Reg 2854 = (source_width/2 * 0x00200000) / destination width
2947 Reg 2874 = Divide by 2
2949 To reduce from half size down to quarter size:
2950 Reg 2854 = (source_width/4 * 0x00200000) / destination width
2951 Reg 2874 = Divide by 4
2953 The result is always rounded up.
2955 --------------------------------------------------------------------------------
2958 Decoder horizontal Y buffer offset
2961 Decoder horizontal UV buffer offset
2963 Offset into the video image buffer. If the offset is gradually incremented,
2964 the on screen image will move left & wrap around higher up on the right.
2966 --------------------------------------------------------------------------------
2969 Decoder horizontal Y output offset
2972 Decoder horizontal UV output offset
2974 Offsets the actual video output. Controls output alignment of the Y & UV
2975 planes. The higher the value, the greater the shift to the left. Use
2976 reg 2890 to move the image right.
2978 --------------------------------------------------------------------------------
2981 Decoder horizontal Y output size divider
2987 Decoder horizontal UV output size divider
2995 1 = Affects video output levels
3000 1 = Disable horizontal filter
3002 --------------------------------------------------------------------------------
3013 Decoder + osd video timing
3022 Swaps upper & lower fields
3024 --------------------------------------------------------------------------------
3027 Decoder & osd ?? unknown
3028 Moves entire screen horizontally. Starts at 0x005 with the screen
3029 shifted heavily to the right. Incrementing in steps of 0x004 will
3030 gradually shift the screen to the left.
3035 Normally contents are 0x00101111 (NTSC) or 0x1010111d (PAL)
3037 --------------------------------------------------------------------------------
3038 2880 -------- ?? unknown
3039 2884 -------- ?? unknown
3040 --------------------------------------------------------------------------------
3043 Decoder + osd ?? unknown
3045 1 = Misaligned fields (Correctable through 289C & 28A4)
3053 Warning: Bad values will require a firmware reload to recover.
3054 Known to be bad are 0x000,0x011,0x100,0x111
3055 --------------------------------------------------------------------------------
3059 Appears to affect the osd position stability. The higher the value the
3060 more unstable it becomes. Decoder output remains stable.
3066 --------------------------------------------------------------------------------
3069 Decoder output horizontal offset.
3071 Horizontal offset moves the video image right. A small left shift is
3072 possible, but it's better to use reg 2870 for that due to its greater
3075 NOTE: Video corruption will occur if video window is shifted off the right
3076 edge. To avoid this read the notes for 2834 & 2838.
3077 --------------------------------------------------------------------------------
3080 Decoder output video surround colour.
3082 Contains the colour (in yuv) used to fill the screen when the video is
3083 running in a window.
3084 --------------------------------------------------------------------------------
3087 Decoder video window colour
3088 Contains the colour (in yuv) used to fill the video window when the
3089 video is turned off.
3092 Decoder video output
3102 Decoder second plane byte order
3106 In normal usage, the first plane is Y & the second plane is UV. Though the
3107 order of the planes can be swapped, only the byte order of the second plane
3108 can be swapped. This isn't much use for the Y plane, but can be useful for
3111 --------------------------------------------------------------------------------
3114 Decoder vertical field offset 1
3117 Decoder vertical field offset 2
3119 Controls field output vertical alignment. The higher the number, the lower
3120 the image on screen. Known starting values are 0x011E0017 (NTSC) &
3122 --------------------------------------------------------------------------------
3125 Decoder & osd width in pixels
3128 Decoder & osd height in pixels
3130 All output from the decoder & osd are disabled beyond this area. Decoder
3131 output will simply go black outside of this region. If the osd tries to
3132 exceed this area it will become corrupt.
3133 --------------------------------------------------------------------------------
3138 Has a range of 0x770->0x7FF. With the exception of 0, any value outside of
3139 this range corrupts the osd.
3140 --------------------------------------------------------------------------------
3143 osd vertical field offset 1
3146 osd vertical field offset 2
3148 Controls field output vertical alignment. The higher the number, the lower
3149 the image on screen. Known starting values are 0x011E0017 (NTSC) &
3151 --------------------------------------------------------------------------------
3152 28AC -------- ?? unknown
3155 28BC -------- ?? unknown
3156 --------------------------------------------------------------------------------
3159 Current output field
3165 The scanline counts from the top line of the first field
3166 through to the last line of the second field.
3167 --------------------------------------------------------------------------------
3168 28C4 -------- ?? unknown
3171 28F8 -------- ?? unknown
3172 --------------------------------------------------------------------------------
3177 1 = Breaks decoder & osd output
3178 --------------------------------------------------------------------------------
3181 Decoder vertical Y alias register 1
3185 Decoder vertical Y alias register 2
3189 Decoder vertical Y alias trigger
3191 These three registers control the vertical aliasing filter for the Y plane.
3192 Operation is similar to the horizontal Y filter (2804). The only real
3193 difference is that there are only two registers to set before accessing
3194 the trigger register (2908). As for the horizontal filter, the values are
3195 taken from a lookup table in the firmware, and the procedure must be
3196 repeated 16 times to fully program the filter.
3197 --------------------------------------------------------------------------------
3200 Decoder vertical UV alias register 1
3204 Decoder vertical UV alias register 2
3208 Decoder vertical UV alias trigger
3210 These three registers control the vertical aliasing filter for the UV
3211 plane. Operation is the same as the Y filter, with 2914 being the trigger.
3212 --------------------------------------------------------------------------------
3215 Decoder Y source height in pixels
3218 Decoder Y destination height in pixels
3222 Decoder UV source height in pixels divided by 2
3225 Decoder UV destination height in pixels
3227 NOTE: For both registers, the resulting image must be fully visible on
3228 screen. If the image exceeds the bottom edge both the source and
3229 destination size must be adjusted to reflect the visible portion. For the
3230 source height, you must take into account the scaling when calculating the
3232 --------------------------------------------------------------------------------
3235 Decoder Y vertical scaling
3236 Normally = Reg 2930 >> 2
3240 Decoder Y vertical scaling
3241 Normally = Reg 2920 + 0x514
3245 Decoder UV vertical scaling
3246 When enlarging = Reg 2930 >> 2
3247 When reducing = Reg 2930 >> 3
3251 Decoder UV vertical scaling
3252 Normally = Reg 2928 + 0x514
3256 Decoder 'master' value for vertical scaling
3260 Decoder ?? unknown - Y vertical scaling
3264 Decoder Y vertical scaling
3269 Decoder ?? unknown - Y vertical scaling
3273 Decoder UV vertical scaling
3274 When enlarging = Reg 2930 >> 1
3275 When reducing = Reg 2930
3279 Decoder ?? unknown - UV vertical scaling
3283 Decoder UV vertical scaling
3288 Decoder ?? unknown - UV vertical scaling
3290 Most of these registers either control vertical scaling, or appear linked
3291 to it in some way. Register 2930 contains the 'master' value & all other
3292 registers can be calculated from that one. You must also remember to
3293 correctly set the divider in Reg 296C
3296 Reg 2930 = (source_height * 0x00200000) / destination_height
3297 Reg 296C = No divide
3299 To reduce from full size down to half size:
3300 Reg 2930 = (source_height/2 * 0x00200000) / destination height
3301 Reg 296C = Divide by 2
3303 To reduce from half down to quarter.
3304 Reg 2930 = (source_height/4 * 0x00200000) / destination height
3305 Reg 296C = Divide by 4
3307 --------------------------------------------------------------------------------
3310 Decoder Y line index into display buffer, first field
3313 Decoder Y vertical line skip, first field
3314 --------------------------------------------------------------------------------
3317 Decoder Y line index into display buffer, second field
3320 Decoder Y vertical line skip, second field
3321 --------------------------------------------------------------------------------
3324 Decoder UV line index into display buffer, first field
3327 Decoder UV vertical line skip, first field
3328 --------------------------------------------------------------------------------
3331 Decoder UV line index into display buffer, second field
3334 Decoder UV vertical line skip, second field
3335 --------------------------------------------------------------------------------
3338 Decoder destination height minus 1
3341 Decoder destination height divided by 2
3342 --------------------------------------------------------------------------------
3345 Decoder Y vertical offset, second field
3348 Decoder Y vertical offset, first field
3350 These two registers shift the Y plane up. The higher the number, the
3352 --------------------------------------------------------------------------------
3355 Decoder UV vertical offset, second field
3358 Decoder UV vertical offset, first field
3360 These two registers shift the UV plane up. The higher the number, the
3362 --------------------------------------------------------------------------------
3365 Decoder vertical Y output size divider
3371 Decoder vertical UV output size divider
3375 --------------------------------------------------------------------------------
3380 1 = Affect video output levels
3385 1 = Disable vertical filter
3387 --------------------------------------------------------------------------------
3388 2974 -------- ?? unknown
3391 29EF -------- ?? unknown
3392 --------------------------------------------------------------------------------
3434 Must be 0x001B (some kind of buffer pointer ?)
3436 When the bits-per-pixel is set to 8, the colour mode is ignored and
3437 assumed to be 8 bit indexed. For 16 & 32 bits-per-pixel the colour depth
3438 is honoured, and when using a colour depth that requires fewer bytes than
3439 allocated the extra bytes are used as padding. So for a 32 bpp with 8 bit
3440 index colour, there are 3 padding bytes per pixel. It's also possible to
3441 select 16bpp with a 32 bit colour mode. This results in the pixel width
3442 being doubled, but the color key will not work as expected in this mode.
3444 Colour key is as it suggests. You designate a colour which will become
3445 completely transparent. When using 565, 555 or 444 colour modes, the
3446 colour key is always 16 bits wide. The colour to key on is set in Reg 2A18.
3448 Local alpha works differently depending on the colour mode. For 32bpp & 8
3449 bit indexed, local alpha is a per-pixel 256 step transparency, with 0 being
3450 transparent and 255 being solid. For the 16bpp modes 555 & 444, the unused
3451 bit(s) act as a simple transparency switch, with 0 being solid & 1 being
3452 fully transparent. There is no local alpha support for 16bit 565.
3454 Global alpha is a 256 step transparency that applies to the entire osd,
3455 with 0 being transparent & 255 being solid.
3457 It's possible to combine colour key, local alpha & global alpha.
3458 --------------------------------------------------------------------------------
3461 osd x coord for left edge
3464 osd y coord for top edge
3468 osd x coord for right edge
3471 osd y coord for bottom edge
3473 For both registers, (0,0) = top left corner of the display area. These
3474 registers do not control the osd size, only where it's positioned & how
3475 much is visible. The visible osd area cannot exceed the right edge of the
3476 display, otherwise the osd will become corrupt. See reg 2A10 for
3478 --------------------------------------------------------------------------------
3483 An index into the osd buffer. Slowly incrementing this moves the osd left,
3484 wrapping around onto the right edge
3485 --------------------------------------------------------------------------------
3488 osd buffer 32 bit word width
3490 Contains the width of the osd measured in 32 bit words. This means that all
3491 colour modes are restricted to a byte width which is divisible by 4.
3492 --------------------------------------------------------------------------------
3495 osd height in pixels
3498 osd line index into buffer
3499 osd will start displaying from this line.
3500 --------------------------------------------------------------------------------
3505 Contains the colour value which will be transparent.
3506 --------------------------------------------------------------------------------
3511 Contains the global alpha value (equiv ivtvfbctl --alpha XX)
3512 --------------------------------------------------------------------------------
3513 2A20 -------- ?? unknown
3516 2A2C -------- ?? unknown
3517 --------------------------------------------------------------------------------
3520 osd colour to change in indexed palette
3524 osd colour for indexed palette
3526 To set the new palette, first load the index of the colour to change into
3527 2A30, then load the new colour into 2A34. The full palette is 256 colours,
3528 so the index range is 0x00-0xFF
3529 --------------------------------------------------------------------------------
3530 2A38 -------- ?? unknown
3531 2A3C -------- ?? unknown
3532 --------------------------------------------------------------------------------
3537 Affects overall brightness, wrapping around to black
3538 --------------------------------------------------------------------------------
3544 --------------------------------------------------------------------------------
3550 --------------------------------------------------------------------------------
3555 Affects overall brightness, wrapping around to black
3556 --------------------------------------------------------------------------------
3562 --------------------------------------------------------------------------------
3568 --------------------------------------------------------------------------------
3569 2A58 -------- ?? unknown
3572 2AFC -------- ?? unknown
3573 --------------------------------------------------------------------------------
3583 --------------------------------------------------------------------------------
3585 The cx231xx DMA engine
3586 ----------------------
3589 This page describes the structures and procedures used by the cx2341x DMA
3595 The cx2341x PCI interface is busmaster capable. This means it has a DMA
3596 engine to efficiently transfer large volumes of data between the card and main
3597 memory without requiring help from a CPU. Like most hardware, it must operate
3598 on contiguous physical memory. This is difficult to come by in large quantities
3599 on virtual memory machines.
3601 Therefore, it also supports a technique called "scatter-gather". The card can
3602 transfer multiple buffers in one operation. Instead of allocating one large
3603 contiguous buffer, the driver can allocate several smaller buffers.
3605 In practice, I've seen the average transfer to be roughly 80K, but transfers
3606 above 128K were not uncommon, particularly at startup. The 128K figure is
3607 important, because that is the largest block that the kernel can normally
3608 allocate. Even still, 128K blocks are hard to come by, so the driver writer is
3609 urged to choose a smaller block size and learn the scatter-gather technique.
3611 Mailbox #10 is reserved for DMA transfer information.
3613 Note: the hardware expects little-endian data ('intel format').
3618 This section describes, in general, the order of events when handling DMA
3619 transfers. Detailed information follows this section.
3621 - The card raises the Encoder interrupt.
3622 - The driver reads the transfer type, offset and size from Mailbox #10.
3623 - The driver constructs the scatter-gather array from enough free dma buffers
3625 - The driver schedules the DMA transfer via the ScheduleDMAtoHost API call.
3626 - The card raises the DMA Complete interrupt.
3627 - The driver checks the DMA status register for any errors.
3628 - The driver post-processes the newly transferred buffers.
3630 NOTE! It is possible that the Encoder and DMA Complete interrupts get raised
3631 simultaneously. (End of the last, start of the next, etc.)
3636 The Flags, Command, Return Value and Timeout fields are ignored.
3639 - Results[0]: Type: 0: MPEG.
3640 - Results[1]: Offset: The position relative to the card's memory space.
3641 - Results[2]: Size: The exact number of bytes to transfer.
3643 My speculation is that since the StartCapture API has a capture type of "RAW"
3644 available, that the type field will have other values that correspond to YUV
3647 Scatter-Gather Array
3648 ~~~~~~~~~~~~~~~~~~~~
3650 The scatter-gather array is a contiguously allocated block of memory that
3651 tells the card the source and destination of each data-block to transfer.
3652 Card "addresses" are derived from the offset supplied by Mailbox #10. Host
3653 addresses are the physical memory location of the target DMA buffer.
3655 Each S-G array element is a struct of three 32-bit words. The first word is
3656 the source address, the second is the destination address. Both take up the
3657 entire 32 bits. The lowest 18 bits of the third word is the transfer byte
3658 count. The high-bit of the third word is the "last" flag. The last-flag tells
3659 the card to raise the DMA_DONE interrupt. From hard personal experience, if
3660 you forget to set this bit, the card will still "work" but the stream will
3661 most likely get corrupted.
3663 The transfer count must be a multiple of 256. Therefore, the driver will need
3664 to track how much data in the target buffer is valid and deal with it
3669 - 32-bit Source Address
3670 - 32-bit Destination Address
3671 - 14-bit reserved (high bit is the last flag)
3677 Register 0x0004 holds the DMA Transfer Status:
3679 - bit 0: read completed
3680 - bit 1: write completed
3681 - bit 2: DMA read error
3682 - bit 3: DMA write error
3683 - bit 4: Scatter-Gather array error
3685 Non-compressed file format
3686 --------------------------
3688 The cx23416 can produce (and the cx23415 can also read) raw YUV output. The
3689 format of a YUV frame is specific to this chip and is called HM12. 'HM' stands
3690 for 'Hauppauge Macroblock', which is a misnomer as 'Conexant Macroblock' would
3693 The format is YUV 4:2:0 which uses 1 Y byte per pixel and 1 U and V byte per
3696 The data is encoded as two macroblock planes, the first containing the Y
3697 values, the second containing UV macroblocks.
3699 The Y plane is divided into blocks of 16x16 pixels from left to right
3700 and from top to bottom. Each block is transmitted in turn, line-by-line.
3702 So the first 16 bytes are the first line of the top-left block, the
3703 second 16 bytes are the second line of the top-left block, etc. After
3704 transmitting this block the first line of the block on the right to the
3705 first block is transmitted, etc.
3707 The UV plane is divided into blocks of 16x8 UV values going from left
3708 to right, top to bottom. Each block is transmitted in turn, line-by-line.
3710 So the first 16 bytes are the first line of the top-left block and
3711 contain 8 UV value pairs (16 bytes in total). The second 16 bytes are the
3712 second line of 8 UV pairs of the top-left block, etc. After transmitting
3713 this block the first line of the block on the right to the first block is
3716 The code below is given as an example on how to convert HM12 to separate
3717 Y, U and V planes. This code assumes frames of 720x576 (PAL) pixels.
3719 The width of a frame is always 720 pixels, regardless of the actual specified
3722 If the height is not a multiple of 32 lines, then the captured video is
3723 missing macroblocks at the end and is unusable. So the height must be a
3726 Raw format c example
3727 ~~~~~~~~~~~~~~~~~~~~
3735 static unsigned char frame[576*720*3/2];
3736 static unsigned char framey[576*720];
3737 static unsigned char frameu[576*720 / 4];
3738 static unsigned char framev[576*720 / 4];
3740 static void de_macro_y(unsigned char* dst, unsigned char *src, int dstride, int w, int h)
3742 unsigned int y, x, i;
3744 // descramble Y plane
3745 // dstride = 720 = w
3746 // The Y plane is divided into blocks of 16x16 pixels
3747 // Each block in transmitted in turn, line-by-line.
3748 for (y = 0; y < h; y += 16) {
3749 for (x = 0; x < w; x += 16) {
3750 for (i = 0; i < 16; i++) {
3751 memcpy(dst + x + (y + i) * dstride, src, 16);
3758 static void de_macro_uv(unsigned char *dstu, unsigned char *dstv, unsigned char *src, int dstride, int w, int h)
3760 unsigned int y, x, i;
3762 // descramble U/V plane
3763 // dstride = 720 / 2 = w
3764 // The U/V values are interlaced (UVUV...).
3765 // Again, the UV plane is divided into blocks of 16x16 UV values.
3766 // Each block in transmitted in turn, line-by-line.
3767 for (y = 0; y < h; y += 16) {
3768 for (x = 0; x < w; x += 8) {
3769 for (i = 0; i < 16; i++) {
3770 int idx = x + (y + i) * dstride;
3772 dstu[idx+0] = src[0]; dstv[idx+0] = src[1];
3773 dstu[idx+1] = src[2]; dstv[idx+1] = src[3];
3774 dstu[idx+2] = src[4]; dstv[idx+2] = src[5];
3775 dstu[idx+3] = src[6]; dstv[idx+3] = src[7];
3776 dstu[idx+4] = src[8]; dstv[idx+4] = src[9];
3777 dstu[idx+5] = src[10]; dstv[idx+5] = src[11];
3778 dstu[idx+6] = src[12]; dstv[idx+6] = src[13];
3779 dstu[idx+7] = src[14]; dstv[idx+7] = src[15];
3786 /*************************************************************************/
3787 int main(int argc, char **argv)
3792 if (argc == 1) fin = stdin;
3793 else fin = fopen(argv[1], "r");
3796 fprintf(stderr, "cannot open input\n");
3799 while (fread(frame, sizeof(frame), 1, fin) == 1) {
3800 de_macro_y(framey, frame, 720, 720, 576);
3801 de_macro_uv(frameu, framev, frame + 720 * 576, 720 / 2, 720 / 2, 576 / 2);
3802 fwrite(framey, sizeof(framey), 1, stdout);
3803 fwrite(framev, sizeof(framev), 1, stdout);
3804 fwrite(frameu, sizeof(frameu), 1, stdout);
3811 Format of embedded V4L2_MPEG_STREAM_VBI_FMT_IVTV VBI data
3812 ---------------------------------------------------------
3814 Author: Hans Verkuil <hverkuil@xs4all.nl>
3817 This section describes the V4L2_MPEG_STREAM_VBI_FMT_IVTV format of the VBI data
3818 embedded in an MPEG-2 program stream. This format is in part dictated by some
3819 hardware limitations of the ivtv driver (the driver for the Conexant cx23415/6
3820 chips), in particular a maximum size for the VBI data. Anything longer is cut
3821 off when the MPEG stream is played back through the cx23415.
3823 The advantage of this format is it is very compact and that all VBI data for
3824 all lines can be stored while still fitting within the maximum allowed size.
3826 The stream ID of the VBI data is 0xBD. The maximum size of the embedded data is
3827 4 + 43 * 36, which is 4 bytes for a header and 2 * 18 VBI lines with a 1 byte
3828 header and a 42 bytes payload each. Anything beyond this limit is cut off by
3829 the cx23415/6 firmware. Besides the data for the VBI lines we also need 36 bits
3830 for a bitmask determining which lines are captured and 4 bytes for a magic cookie,
3831 signifying that this data package contains V4L2_MPEG_STREAM_VBI_FMT_IVTV VBI data.
3832 If all lines are used, then there is no longer room for the bitmask. To solve this
3833 two different magic numbers were introduced:
3835 'itv0': After this magic number two unsigned longs follow. Bits 0-17 of the first
3836 unsigned long denote which lines of the first field are captured. Bits 18-31 of
3837 the first unsigned long and bits 0-3 of the second unsigned long are used for the
3840 'ITV0': This magic number assumes all VBI lines are captured, i.e. it implicitly
3841 implies that the bitmasks are 0xffffffff and 0xf.
3843 After these magic cookies (and the 8 byte bitmask in case of cookie 'itv0') the
3844 captured VBI lines start:
3846 For each line the least significant 4 bits of the first byte contain the data type.
3847 Possible values are shown in the table below. The payload is in the following 42
3850 Here is the list of possible data types:
3854 #define IVTV_SLICED_TYPE_TELETEXT 0x1 // Teletext (uses lines 6-22 for PAL)
3855 #define IVTV_SLICED_TYPE_CC 0x4 // Closed Captions (line 21 NTSC)
3856 #define IVTV_SLICED_TYPE_WSS 0x5 // Wide Screen Signal (line 23 PAL)
3857 #define IVTV_SLICED_TYPE_VPS 0x7 // Video Programming System (PAL) (line 16)