10c1bc742181ded4930842b46e9507372f0b1b963James Dong/* ----------------------------------------------------------------
20c1bc742181ded4930842b46e9507372f0b1b963James Dong *
30c1bc742181ded4930842b46e9507372f0b1b963James Dong *
40c1bc742181ded4930842b46e9507372f0b1b963James Dong * File Name:  omxVCM4P10_DecodeCoeffsToPairCAVLC.c
50c1bc742181ded4930842b46e9507372f0b1b963James Dong * OpenMAX DL: v1.0.2
60c1bc742181ded4930842b46e9507372f0b1b963James Dong * Revision:   9641
70c1bc742181ded4930842b46e9507372f0b1b963James Dong * Date:       Thursday, February 7, 2008
80c1bc742181ded4930842b46e9507372f0b1b963James Dong *
90c1bc742181ded4930842b46e9507372f0b1b963James Dong * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
100c1bc742181ded4930842b46e9507372f0b1b963James Dong *
110c1bc742181ded4930842b46e9507372f0b1b963James Dong *
120c1bc742181ded4930842b46e9507372f0b1b963James Dong *
130c1bc742181ded4930842b46e9507372f0b1b963James Dong * H.264 decode coefficients module
140c1bc742181ded4930842b46e9507372f0b1b963James Dong *
150c1bc742181ded4930842b46e9507372f0b1b963James Dong */
160c1bc742181ded4930842b46e9507372f0b1b963James Dong
170c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxtypes.h"
180c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armOMX.h"
190c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxVC.h"
200c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armCOMM.h"
210c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVC.h"
220c1bc742181ded4930842b46e9507372f0b1b963James Dong
230c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
240c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function:  omxVCM4P10_DecodeCoeffsToPairCAVLC   (6.3.4.1.2)
250c1bc742181ded4930842b46e9507372f0b1b963James Dong *
260c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
270c1bc742181ded4930842b46e9507372f0b1b963James Dong * Performs CAVLC decoding and inverse zigzag scan for 4x4 block of
280c1bc742181ded4930842b46e9507372f0b1b963James Dong * Intra16x16DCLevel, Intra16x16ACLevel, LumaLevel, and ChromaACLevel. Inverse
290c1bc742181ded4930842b46e9507372f0b1b963James Dong * field scan is not supported. The decoded coefficients in the packed
300c1bc742181ded4930842b46e9507372f0b1b963James Dong * position-coefficient buffer are stored in reverse zig-zag order, i.e., the
310c1bc742181ded4930842b46e9507372f0b1b963James Dong * first buffer element contains the last non-zero postion-coefficient pair of
320c1bc742181ded4930842b46e9507372f0b1b963James Dong * the block. Within each position-coefficient pair, the position entry
330c1bc742181ded4930842b46e9507372f0b1b963James Dong * indicates the raster-scan position of the coefficient, while the
340c1bc742181ded4930842b46e9507372f0b1b963James Dong * coefficient entry contains the coefficient value.
350c1bc742181ded4930842b46e9507372f0b1b963James Dong *
360c1bc742181ded4930842b46e9507372f0b1b963James Dong * Input Arguments:
370c1bc742181ded4930842b46e9507372f0b1b963James Dong *
380c1bc742181ded4930842b46e9507372f0b1b963James Dong *   ppBitStream -Double pointer to current byte in bit stream buffer
390c1bc742181ded4930842b46e9507372f0b1b963James Dong *   pOffset - Pointer to current bit position in the byte pointed to by
400c1bc742181ded4930842b46e9507372f0b1b963James Dong *            *ppBitStream; valid in the range [0,7].
410c1bc742181ded4930842b46e9507372f0b1b963James Dong *   sMaxNumCoeff - Maximum the number of non-zero coefficients in current
420c1bc742181ded4930842b46e9507372f0b1b963James Dong *            block
430c1bc742181ded4930842b46e9507372f0b1b963James Dong *   sVLCSelect - VLC table selector, obtained from the number of non-zero
440c1bc742181ded4930842b46e9507372f0b1b963James Dong *            coefficients contained in the above and left 4x4 blocks.  It is
450c1bc742181ded4930842b46e9507372f0b1b963James Dong *            equivalent to the variable nC described in H.264 standard table
460c1bc742181ded4930842b46e9507372f0b1b963James Dong *            9 5, except its value can t be less than zero.
470c1bc742181ded4930842b46e9507372f0b1b963James Dong *
480c1bc742181ded4930842b46e9507372f0b1b963James Dong * Output Arguments:
490c1bc742181ded4930842b46e9507372f0b1b963James Dong *
500c1bc742181ded4930842b46e9507372f0b1b963James Dong *   ppBitStream - *ppBitStream is updated after each block is decoded.
510c1bc742181ded4930842b46e9507372f0b1b963James Dong *            Buffer position (*ppPosCoefBuf) is updated upon return, unless
520c1bc742181ded4930842b46e9507372f0b1b963James Dong *            there are only zero coefficients in the currently decoded block.
530c1bc742181ded4930842b46e9507372f0b1b963James Dong *             In this case the caller is expected to bypass the
540c1bc742181ded4930842b46e9507372f0b1b963James Dong *            transform/dequantization of the empty blocks.
550c1bc742181ded4930842b46e9507372f0b1b963James Dong *   pOffset - *pOffset is updated after each block is decoded
560c1bc742181ded4930842b46e9507372f0b1b963James Dong *   pNumCoeff - Pointer to the number of nonzero coefficients in this block
570c1bc742181ded4930842b46e9507372f0b1b963James Dong *   ppPosCoefBuf - Double pointer to destination residual
580c1bc742181ded4930842b46e9507372f0b1b963James Dong *            coefficient-position pair buffer
590c1bc742181ded4930842b46e9507372f0b1b963James Dong *
600c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
610c1bc742181ded4930842b46e9507372f0b1b963James Dong *    OMX_Sts_NoErr, if the function runs without error.
620c1bc742181ded4930842b46e9507372f0b1b963James Dong *
630c1bc742181ded4930842b46e9507372f0b1b963James Dong *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs:
640c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    ppBitStream or pOffset is NULL.
650c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    ppPosCoefBuf or pNumCoeff is NULL.
660c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    sMaxNumCoeff is not equal to either 15 or 16.
670c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    sVLCSelect is less than 0.
680c1bc742181ded4930842b46e9507372f0b1b963James Dong *
690c1bc742181ded4930842b46e9507372f0b1b963James Dong *    OMX_Sts_Err - if one of the following is true:
700c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    an illegal code is encountered in the bitstream
710c1bc742181ded4930842b46e9507372f0b1b963James Dong *
720c1bc742181ded4930842b46e9507372f0b1b963James Dong */
730c1bc742181ded4930842b46e9507372f0b1b963James Dong
740c1bc742181ded4930842b46e9507372f0b1b963James DongOMXResult omxVCM4P10_DecodeCoeffsToPairCAVLC(
750c1bc742181ded4930842b46e9507372f0b1b963James Dong     const OMX_U8** ppBitStream,
760c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_S32* pOffset,
770c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_U8* pNumCoeff,
780c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_U8**ppPosCoefbuf,
790c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_INT sVLCSelect,
800c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_INT sMaxNumCoeff
810c1bc742181ded4930842b46e9507372f0b1b963James Dong )
820c1bc742181ded4930842b46e9507372f0b1b963James Dong{
830c1bc742181ded4930842b46e9507372f0b1b963James Dong    int nTable;
840c1bc742181ded4930842b46e9507372f0b1b963James Dong
850c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(ppBitStream==NULL   , OMX_Sts_BadArgErr);
860c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(*ppBitStream==NULL  , OMX_Sts_BadArgErr);
870c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(pOffset==NULL       , OMX_Sts_BadArgErr);
880c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(*pOffset<0          , OMX_Sts_BadArgErr);
890c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(*pOffset>7          , OMX_Sts_BadArgErr);
900c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(pNumCoeff==NULL     , OMX_Sts_BadArgErr);
910c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(ppPosCoefbuf==NULL  , OMX_Sts_BadArgErr);
920c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(*ppPosCoefbuf==NULL , OMX_Sts_BadArgErr);
930c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(sVLCSelect<0        , OMX_Sts_BadArgErr);
940c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(sMaxNumCoeff<15     , OMX_Sts_BadArgErr);
950c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(sMaxNumCoeff>16     , OMX_Sts_BadArgErr);
960c1bc742181ded4930842b46e9507372f0b1b963James Dong
970c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Find VLC table number */
980c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (sVLCSelect<2)
990c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1000c1bc742181ded4930842b46e9507372f0b1b963James Dong        nTable = 0;
1010c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1020c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (sVLCSelect<4)
1030c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1040c1bc742181ded4930842b46e9507372f0b1b963James Dong        nTable = 1;
1050c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (sVLCSelect<8)
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong        nTable = 2;
1090c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1100c1bc742181ded4930842b46e9507372f0b1b963James Dong    else /* sVLCSelect >= 8 */
1110c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1120c1bc742181ded4930842b46e9507372f0b1b963James Dong        nTable = 3;
1130c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1140c1bc742181ded4930842b46e9507372f0b1b963James Dong
1150c1bc742181ded4930842b46e9507372f0b1b963James Dong    return armVCM4P10_DecodeCoeffsToPair(ppBitStream, pOffset, pNumCoeff,
1160c1bc742181ded4930842b46e9507372f0b1b963James Dong                                         ppPosCoefbuf, nTable, sMaxNumCoeff);
1170c1bc742181ded4930842b46e9507372f0b1b963James Dong}
118