📄 h263_vld_h.asm
字号:
* ========================================================================= ** TEXAS INSTRUMENTS, INC. ** ** NAME ** h263_vld ** ** 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) ** inter = Flag: Set to 1 if INTER block, zero if INTRA ** ** The function places decoded data in the idct[] array. Also, it ** returns a two-bit error code as its return value: Bit 0 of the ** return value denotes whether the zig-zag array was overrun, and ** bit 1 denotes whether an invalid VLC symbol was encountered. A ** return value of 0 denotes no error. ** ** DESCRIPTION ** This code performs the variable length decode of a H.263 ** bit_stream using the Table 16 and Table 17 of the H.263 ** 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. ** ** This code handles both cases of INTER and INTRA. For INTER ** blocks the DC term is encoded as an AC coefficient and it is ** possible to have up to 64 terms. The code sets the error flag ** appropriately for either INTER or INTRA blocks. ** ** ** The following is the implementation: ** ** This routine performs VLD on the AC terms in a Huffman coded 8x8 ** block for H.263 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: *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -