178e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar/*
278e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Copyright (C) 2007-2008 ARM Limited
378e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
478e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Licensed under the Apache License, Version 2.0 (the "License");
578e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * you may not use this file except in compliance with the License.
678e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * You may obtain a copy of the License at
778e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
878e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *      http://www.apache.org/licenses/LICENSE-2.0
978e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
1078e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Unless required by applicable law or agreed to in writing, software
1178e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * distributed under the License is distributed on an "AS IS" BASIS,
1278e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1378e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * See the License for the specific language governing permissions and
1478e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * limitations under the License.
1578e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar *
1678e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar */
170c1bc742181ded4930842b46e9507372f0b1b963James Dong/* ----------------------------------------------------------------
180c1bc742181ded4930842b46e9507372f0b1b963James Dong *
190c1bc742181ded4930842b46e9507372f0b1b963James Dong *
200c1bc742181ded4930842b46e9507372f0b1b963James Dong * File Name:  omxVCM4P10_DecodeCoeffsToPairCAVLC.c
210c1bc742181ded4930842b46e9507372f0b1b963James Dong * OpenMAX DL: v1.0.2
220c1bc742181ded4930842b46e9507372f0b1b963James Dong * Revision:   9641
230c1bc742181ded4930842b46e9507372f0b1b963James Dong * Date:       Thursday, February 7, 2008
240c1bc742181ded4930842b46e9507372f0b1b963James Dong *
250c1bc742181ded4930842b46e9507372f0b1b963James Dong *
260c1bc742181ded4930842b46e9507372f0b1b963James Dong *
270c1bc742181ded4930842b46e9507372f0b1b963James Dong *
280c1bc742181ded4930842b46e9507372f0b1b963James Dong * H.264 decode coefficients module
290c1bc742181ded4930842b46e9507372f0b1b963James Dong *
300c1bc742181ded4930842b46e9507372f0b1b963James Dong */
310c1bc742181ded4930842b46e9507372f0b1b963James Dong
320c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxtypes.h"
330c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armOMX.h"
340c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxVC.h"
350c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armCOMM.h"
360c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVC.h"
370c1bc742181ded4930842b46e9507372f0b1b963James Dong
380c1bc742181ded4930842b46e9507372f0b1b963James Dong/**
390c1bc742181ded4930842b46e9507372f0b1b963James Dong * Function:  omxVCM4P10_DecodeCoeffsToPairCAVLC   (6.3.4.1.2)
400c1bc742181ded4930842b46e9507372f0b1b963James Dong *
410c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description:
420c1bc742181ded4930842b46e9507372f0b1b963James Dong * Performs CAVLC decoding and inverse zigzag scan for 4x4 block of
430c1bc742181ded4930842b46e9507372f0b1b963James Dong * Intra16x16DCLevel, Intra16x16ACLevel, LumaLevel, and ChromaACLevel. Inverse
440c1bc742181ded4930842b46e9507372f0b1b963James Dong * field scan is not supported. The decoded coefficients in the packed
450c1bc742181ded4930842b46e9507372f0b1b963James Dong * position-coefficient buffer are stored in reverse zig-zag order, i.e., the
460c1bc742181ded4930842b46e9507372f0b1b963James Dong * first buffer element contains the last non-zero postion-coefficient pair of
470c1bc742181ded4930842b46e9507372f0b1b963James Dong * the block. Within each position-coefficient pair, the position entry
480c1bc742181ded4930842b46e9507372f0b1b963James Dong * indicates the raster-scan position of the coefficient, while the
490c1bc742181ded4930842b46e9507372f0b1b963James Dong * coefficient entry contains the coefficient value.
500c1bc742181ded4930842b46e9507372f0b1b963James Dong *
510c1bc742181ded4930842b46e9507372f0b1b963James Dong * Input Arguments:
520c1bc742181ded4930842b46e9507372f0b1b963James Dong *
530c1bc742181ded4930842b46e9507372f0b1b963James Dong *   ppBitStream -Double pointer to current byte in bit stream buffer
540c1bc742181ded4930842b46e9507372f0b1b963James Dong *   pOffset - Pointer to current bit position in the byte pointed to by
550c1bc742181ded4930842b46e9507372f0b1b963James Dong *            *ppBitStream; valid in the range [0,7].
560c1bc742181ded4930842b46e9507372f0b1b963James Dong *   sMaxNumCoeff - Maximum the number of non-zero coefficients in current
570c1bc742181ded4930842b46e9507372f0b1b963James Dong *            block
580c1bc742181ded4930842b46e9507372f0b1b963James Dong *   sVLCSelect - VLC table selector, obtained from the number of non-zero
590c1bc742181ded4930842b46e9507372f0b1b963James Dong *            coefficients contained in the above and left 4x4 blocks.  It is
600c1bc742181ded4930842b46e9507372f0b1b963James Dong *            equivalent to the variable nC described in H.264 standard table
610c1bc742181ded4930842b46e9507372f0b1b963James Dong *            9 5, except its value can t be less than zero.
620c1bc742181ded4930842b46e9507372f0b1b963James Dong *
630c1bc742181ded4930842b46e9507372f0b1b963James Dong * Output Arguments:
640c1bc742181ded4930842b46e9507372f0b1b963James Dong *
650c1bc742181ded4930842b46e9507372f0b1b963James Dong *   ppBitStream - *ppBitStream is updated after each block is decoded.
660c1bc742181ded4930842b46e9507372f0b1b963James Dong *            Buffer position (*ppPosCoefBuf) is updated upon return, unless
670c1bc742181ded4930842b46e9507372f0b1b963James Dong *            there are only zero coefficients in the currently decoded block.
680c1bc742181ded4930842b46e9507372f0b1b963James Dong *             In this case the caller is expected to bypass the
690c1bc742181ded4930842b46e9507372f0b1b963James Dong *            transform/dequantization of the empty blocks.
700c1bc742181ded4930842b46e9507372f0b1b963James Dong *   pOffset - *pOffset is updated after each block is decoded
710c1bc742181ded4930842b46e9507372f0b1b963James Dong *   pNumCoeff - Pointer to the number of nonzero coefficients in this block
720c1bc742181ded4930842b46e9507372f0b1b963James Dong *   ppPosCoefBuf - Double pointer to destination residual
730c1bc742181ded4930842b46e9507372f0b1b963James Dong *            coefficient-position pair buffer
740c1bc742181ded4930842b46e9507372f0b1b963James Dong *
750c1bc742181ded4930842b46e9507372f0b1b963James Dong * Return Value:
760c1bc742181ded4930842b46e9507372f0b1b963James Dong *    OMX_Sts_NoErr, if the function runs without error.
770c1bc742181ded4930842b46e9507372f0b1b963James Dong *
780c1bc742181ded4930842b46e9507372f0b1b963James Dong *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs:
790c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    ppBitStream or pOffset is NULL.
800c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    ppPosCoefBuf or pNumCoeff is NULL.
810c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    sMaxNumCoeff is not equal to either 15 or 16.
820c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    sVLCSelect is less than 0.
830c1bc742181ded4930842b46e9507372f0b1b963James Dong *
840c1bc742181ded4930842b46e9507372f0b1b963James Dong *    OMX_Sts_Err - if one of the following is true:
850c1bc742181ded4930842b46e9507372f0b1b963James Dong *    -    an illegal code is encountered in the bitstream
860c1bc742181ded4930842b46e9507372f0b1b963James Dong *
870c1bc742181ded4930842b46e9507372f0b1b963James Dong */
880c1bc742181ded4930842b46e9507372f0b1b963James Dong
890c1bc742181ded4930842b46e9507372f0b1b963James DongOMXResult omxVCM4P10_DecodeCoeffsToPairCAVLC(
900c1bc742181ded4930842b46e9507372f0b1b963James Dong     const OMX_U8** ppBitStream,
910c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_S32* pOffset,
920c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_U8* pNumCoeff,
930c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_U8**ppPosCoefbuf,
940c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_INT sVLCSelect,
950c1bc742181ded4930842b46e9507372f0b1b963James Dong     OMX_INT sMaxNumCoeff
960c1bc742181ded4930842b46e9507372f0b1b963James Dong )
970c1bc742181ded4930842b46e9507372f0b1b963James Dong{
980c1bc742181ded4930842b46e9507372f0b1b963James Dong    int nTable;
990c1bc742181ded4930842b46e9507372f0b1b963James Dong
1000c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(ppBitStream==NULL   , OMX_Sts_BadArgErr);
1010c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(*ppBitStream==NULL  , OMX_Sts_BadArgErr);
1020c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(pOffset==NULL       , OMX_Sts_BadArgErr);
1030c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(*pOffset<0          , OMX_Sts_BadArgErr);
1040c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(*pOffset>7          , OMX_Sts_BadArgErr);
1050c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(pNumCoeff==NULL     , OMX_Sts_BadArgErr);
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(ppPosCoefbuf==NULL  , OMX_Sts_BadArgErr);
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(*ppPosCoefbuf==NULL , OMX_Sts_BadArgErr);
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(sVLCSelect<0        , OMX_Sts_BadArgErr);
1090c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(sMaxNumCoeff<15     , OMX_Sts_BadArgErr);
1100c1bc742181ded4930842b46e9507372f0b1b963James Dong    armRetArgErrIf(sMaxNumCoeff>16     , OMX_Sts_BadArgErr);
1110c1bc742181ded4930842b46e9507372f0b1b963James Dong
1120c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Find VLC table number */
1130c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (sVLCSelect<2)
1140c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1150c1bc742181ded4930842b46e9507372f0b1b963James Dong        nTable = 0;
1160c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1170c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (sVLCSelect<4)
1180c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1190c1bc742181ded4930842b46e9507372f0b1b963James Dong        nTable = 1;
1200c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1210c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (sVLCSelect<8)
1220c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1230c1bc742181ded4930842b46e9507372f0b1b963James Dong        nTable = 2;
1240c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1250c1bc742181ded4930842b46e9507372f0b1b963James Dong    else /* sVLCSelect >= 8 */
1260c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1270c1bc742181ded4930842b46e9507372f0b1b963James Dong        nTable = 3;
1280c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1290c1bc742181ded4930842b46e9507372f0b1b963James Dong
1300c1bc742181ded4930842b46e9507372f0b1b963James Dong    return armVCM4P10_DecodeCoeffsToPair(ppBitStream, pOffset, pNumCoeff,
1310c1bc742181ded4930842b46e9507372f0b1b963James Dong                                         ppPosCoefbuf, nTable, sMaxNumCoeff);
1320c1bc742181ded4930842b46e9507372f0b1b963James Dong}
133