📄 h263_vld_n.sa
字号:
* ========================================================================= ** TEXAS INSTRUMENTS, INC. ** ** NAME ** h263_vld ** S** USAGE ** This routine is C-callable and can be called as: ** ** int h263_vld ** ( ** unsigned int *restrict ** *restrict bufPtr, ** int *restrict bitPtr, ** const unsigned short *restrict tab, ** const unsigned char *restrict len, ** short q, int dq, ** const unsigned char *restrict zz, ** short *restrict idct, ** int inter ** ) ** ** ** bufPtr = pointer to VLD buffer word pointer. ** bitPtr = pointer to the number of valid bits.n VLD_buffer ** tab = pointer to VLC Coeff/Run table. ** len = pointer to VLC Length table. ** Q = Quantization value. ** dq = Quant/Mismatch control value. ** zz = Ptr to zig-zag scan table. ** idct = 8x8 IDCT Coeff block. (Output) ** ** (See the C compiler reference guide.) ** ** DESCRIPTION ** ** This code performs the variable length decode of a H 63 bit_stream ** using the Table 16 and Table 17 of the H 63 standard. The function ** accepts a packed Variable length encoded buffer and returns the idct ** array for one block. This function also returns state variables that ** allow chaining for calling it multiple times to perform VLD for a ** macro-block.The function returns 0 if a valid VLD decode of a block ** was performed and a 1 if the block had an error. ** ** The following is the implementation: ** ** This routine performs VLD on the AC terms in a Huffman coded 8x8 ** block for H 63 decode. Inverse Quantization, Run-Length Decode ** and Zig-Zag reordering are performed on each coefficient before ** it is written to the IDCT array. The IDCT array is presumed to ** prezeroed by the calling function. ** ** Error detection is performed by detecting invalid Huffman codes ** and for run-values which send the run-length decode outside the ** current 8x8 block. No test is made, however, to determine if the ** bitstream input underflows. The user is advised to place a ** sentinel bitstream at the end of the VLD buffer to prevent buffer ** underflow in the case of an error. ** ** The bitstream is processed in word-sized chunks, using word-wide ** loads from the bitstream. Therefore, it is necessary to store the ** bitstream in "word order". For example, consider the following ** bitstream: (leftmost bits are earliest in time.) ** ** +--------------------------------+---------------------- ** |ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef|ghijklmnopqrstuvwxyz . . . ** +--------------------------------+---------------------- ** Word 0 Word 1 ** ** The VLD routine will read the bitstream a word at a time, as ** labeled above. On a little endian CPU, this implies that the ** bit-stream will be stored as follows in memory: ** ** +--------+--------+--------+--------+----- ** |YZabcdef|QRSTUVWX|IJKLMNOP|ABCDEFGH| . . . ** +--------+--------+--------+--------+----- ** | Byte 0 Byte 1 Byte 2 Byte 3 | ** |<------------ Word 0 ------------->| ** ** The VLC codes fall into several different classes. The VLD ** attempts to isolate what VLC code it has by looking at various ** ranges of bits. The following diagram illustrates the various ** regions of the bitstream that are extracted into different ** variables. ** ** 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 ** 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 ** +------------------------------------------------- ** |A B C D E F G H I J K L M N O P Q R S T U V W . . . ** +------------------------------------------------- ** |<--f5--->| | | | | ** |<----f7----->| | | | ** |<------f9------->| | | ** |<-------idx2------>| | ** |<---------idx1-------->| ** ** ** The Len/Run/Last lookup for VLD then proceeds as follows: ** ** -- If 'f5' is less than 4, then we have a code in the range ** 00000xxxxx to 00011xxxxx. ** ** -- For 00000xxxxxxx codes, lookup tab[idx1]. Since f5 ** is zero (and therefore bits A...E are zero), idx1 has ** 7 significant bits. Therefore, the lookup occurs over ** over the range [0,127]. ** ** -- For 00001xxxxx thru 00011xxxxx codes, lookup ** tab[64 + idx0]. For this range of codes, idx0 >= 64, ** and has 7 significant bits. Therefore, the lookup ** occurs over the range [128,191]. ** ** -- If 'f5' is not less than 4, then we need to look at the ** first 7 bits to determine what code we have. ** ** -- For 001xxxx through 1xxxxxx codes, lookup ** tab[176 + f7]. We know that f7 >= 32, so therefore, ** the lookup will occur over the range [198,303]. ** ** -- If 'f7' equals 3, we have an escape code of the form ** 0000011Lrrrrrrllllllll, where 'L' is the LAST flag, ** 'rrrrrr' is the Run, and 'llllllll' is the signed level. ** ** ** The length of the VLC code is determined with one pair of ** lookups. ** ** -- If 'f5' is less than 4, then we have a code in the range ** 00000xxxxx to 00011xxxxx. For this case, we look up the ** length at len[f9]. This lookup occurs over the range ** [0,63]. ** ** -- If 'f5' is >= 4, we use the first 5 bits to look in the ** length table. We look at len[60 + f5]. Since f5 >= 4, ** this lookup occurs over the range [64, 91]. ** ** The actual code table contains 304 entires to get multiple of 8. ** Each code word is stored in the table in the following format: ** The code word used in this context refers to the run, level ** associated with each Huffman code word that is decoded and not ** to the Huffman code word itself. ** ** Last(1/0) RUNVALUE LEVEL ** 14 13....8 7....0 ** ** Each code word thus has a pad of 2 bits and is stored as a half ** word ** ** Example: ** ** 1) Code: 0000 0000 110s Run: 0 Level: 11 ** ** Clearly for this code f5 the first 5 bits from the left are zero.** first 12 bits from the left are extracted in idx1. If the upper ** 5 bits are zero then idx1 can have a maximum value of upto 127. ** In this case this value will be either 13 or 14 depending on the ** sign bit. ** 0 000000 001011 -------------> 0x0b ** ** ** The length table is a set of values constructed as follows. The ** code words are taken and divided into two categories for this ** purpose: ** Class 1: Codes 00000xxxxx...00011xxxxx ** Class 2: Codes 001xxxxx.. xxxx ** Therfore it can be seen that under class 2 there can be a set of ** 32 codes and under class 1 there are 60 enties that the given ** code table maps into. Therfore there are a total of 32 entries. ** This can be seen by way of example: ** ** Code at Index: 50 of the Table 16 in H 63 spec ** ** Run: 19 Level: 1 Code: 0000 1110 1s and falls under Class 1 ** When the 9 left most bits are examined this gives us 29. The ** 29th entry in the length table gives us the length of the code ** word as 10. ** ** ** Similarly a code at Index 40 of the Table 16 in H 63 spec ** ** Run: 10 Level: 1 Code: 0010110s. This comes under Class 2 and ** hence the 5 left most bits are extracted to give an index of 5 ** The code lengths for these class of codes is stored with an *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -