omxVCM4P10_DecodeCoeffsToPairCAVLC.c revision 78e52bfac041d71ce53b5b13c2abf78af742b09d
1/*
2 * Copyright (C) 2007-2008 ARM Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17/* ----------------------------------------------------------------
18 *
19 *
20 * File Name:  omxVCM4P10_DecodeCoeffsToPairCAVLC.c
21 * OpenMAX DL: v1.0.2
22 * Revision:   9641
23 * Date:       Thursday, February 7, 2008
24 *
25 *
26 *
27 *
28 * H.264 decode coefficients module
29 *
30 */
31
32#include "omxtypes.h"
33#include "armOMX.h"
34#include "omxVC.h"
35#include "armCOMM.h"
36#include "armVC.h"
37
38/**
39 * Function:  omxVCM4P10_DecodeCoeffsToPairCAVLC   (6.3.4.1.2)
40 *
41 * Description:
42 * Performs CAVLC decoding and inverse zigzag scan for 4x4 block of
43 * Intra16x16DCLevel, Intra16x16ACLevel, LumaLevel, and ChromaACLevel. Inverse
44 * field scan is not supported. The decoded coefficients in the packed
45 * position-coefficient buffer are stored in reverse zig-zag order, i.e., the
46 * first buffer element contains the last non-zero postion-coefficient pair of
47 * the block. Within each position-coefficient pair, the position entry
48 * indicates the raster-scan position of the coefficient, while the
49 * coefficient entry contains the coefficient value.
50 *
51 * Input Arguments:
52 *
53 *   ppBitStream -Double pointer to current byte in bit stream buffer
54 *   pOffset - Pointer to current bit position in the byte pointed to by
55 *            *ppBitStream; valid in the range [0,7].
56 *   sMaxNumCoeff - Maximum the number of non-zero coefficients in current
57 *            block
58 *   sVLCSelect - VLC table selector, obtained from the number of non-zero
59 *            coefficients contained in the above and left 4x4 blocks.  It is
60 *            equivalent to the variable nC described in H.264 standard table
61 *            9 5, except its value can t be less than zero.
62 *
63 * Output Arguments:
64 *
65 *   ppBitStream - *ppBitStream is updated after each block is decoded.
66 *            Buffer position (*ppPosCoefBuf) is updated upon return, unless
67 *            there are only zero coefficients in the currently decoded block.
68 *             In this case the caller is expected to bypass the
69 *            transform/dequantization of the empty blocks.
70 *   pOffset - *pOffset is updated after each block is decoded
71 *   pNumCoeff - Pointer to the number of nonzero coefficients in this block
72 *   ppPosCoefBuf - Double pointer to destination residual
73 *            coefficient-position pair buffer
74 *
75 * Return Value:
76 *    OMX_Sts_NoErr, if the function runs without error.
77 *
78 *    OMX_Sts_BadArgErr - bad arguments: if one of the following cases occurs:
79 *    -    ppBitStream or pOffset is NULL.
80 *    -    ppPosCoefBuf or pNumCoeff is NULL.
81 *    -    sMaxNumCoeff is not equal to either 15 or 16.
82 *    -    sVLCSelect is less than 0.
83 *
84 *    OMX_Sts_Err - if one of the following is true:
85 *    -    an illegal code is encountered in the bitstream
86 *
87 */
88
89OMXResult omxVCM4P10_DecodeCoeffsToPairCAVLC(
90     const OMX_U8** ppBitStream,
91     OMX_S32* pOffset,
92     OMX_U8* pNumCoeff,
93     OMX_U8**ppPosCoefbuf,
94     OMX_INT sVLCSelect,
95     OMX_INT sMaxNumCoeff
96 )
97{
98    int nTable;
99
100    armRetArgErrIf(ppBitStream==NULL   , OMX_Sts_BadArgErr);
101    armRetArgErrIf(*ppBitStream==NULL  , OMX_Sts_BadArgErr);
102    armRetArgErrIf(pOffset==NULL       , OMX_Sts_BadArgErr);
103    armRetArgErrIf(*pOffset<0          , OMX_Sts_BadArgErr);
104    armRetArgErrIf(*pOffset>7          , OMX_Sts_BadArgErr);
105    armRetArgErrIf(pNumCoeff==NULL     , OMX_Sts_BadArgErr);
106    armRetArgErrIf(ppPosCoefbuf==NULL  , OMX_Sts_BadArgErr);
107    armRetArgErrIf(*ppPosCoefbuf==NULL , OMX_Sts_BadArgErr);
108    armRetArgErrIf(sVLCSelect<0        , OMX_Sts_BadArgErr);
109    armRetArgErrIf(sMaxNumCoeff<15     , OMX_Sts_BadArgErr);
110    armRetArgErrIf(sMaxNumCoeff>16     , OMX_Sts_BadArgErr);
111
112    /* Find VLC table number */
113    if (sVLCSelect<2)
114    {
115        nTable = 0;
116    }
117    else if (sVLCSelect<4)
118    {
119        nTable = 1;
120    }
121    else if (sVLCSelect<8)
122    {
123        nTable = 2;
124    }
125    else /* sVLCSelect >= 8 */
126    {
127        nTable = 3;
128    }
129
130    return armVCM4P10_DecodeCoeffsToPair(ppBitStream, pOffset, pNumCoeff,
131                                         ppPosCoefbuf, nTable, sMaxNumCoeff);
132}
133