• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2  * \copy
3  *     Copyright (c)  2009-2013, Cisco Systems
4  *     All rights reserved.
5  *
6  *     Redistribution and use in source and binary forms, with or without
7  *     modification, are permitted provided that the following conditions
8  *     are met:
9  *
10  *        * Redistributions of source code must retain the above copyright
11  *          notice, this list of conditions and the following disclaimer.
12  *
13  *        * Redistributions in binary form must reproduce the above copyright
14  *          notice, this list of conditions and the following disclaimer in
15  *          the documentation and/or other materials provided with the
16  *          distribution.
17  *
18  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  *     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  *     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  *     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  *     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  *     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  *     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  *     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  *     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *     POSSIBILITY OF SUCH DAMAGE.
30  *
31  * \file    cabac_decoder.h
32  *
33  * \brief   Interfaces introduced for cabac decoder
34  *
35  * \date    10/10/2014 Created
36  *
37  *************************************************************************************
38  */
39 #ifndef WELS_CABAC_DECODER_H__
40 #define WELS_CABAC_DECODER_H__
41 
42 #include "decoder_context.h"
43 #include "error_code.h"
44 #include "wels_common_defs.h"
45 namespace WelsDec {
46 static const uint8_t g_kRenormTable256[256] = {
47   6, 6, 6, 6, 6, 6, 6, 6,
48   5, 5, 5, 5, 5, 5, 5, 5,
49   4, 4, 4, 4, 4, 4, 4, 4,
50   4, 4, 4, 4, 4, 4, 4, 4,
51   3, 3, 3, 3, 3, 3, 3, 3,
52   3, 3, 3, 3, 3, 3, 3, 3,
53   3, 3, 3, 3, 3, 3, 3, 3,
54   3, 3, 3, 3, 3, 3, 3, 3,
55   2, 2, 2, 2, 2, 2, 2, 2,
56   2, 2, 2, 2, 2, 2, 2, 2,
57   2, 2, 2, 2, 2, 2, 2, 2,
58   2, 2, 2, 2, 2, 2, 2, 2,
59   2, 2, 2, 2, 2, 2, 2, 2,
60   2, 2, 2, 2, 2, 2, 2, 2,
61   2, 2, 2, 2, 2, 2, 2, 2,
62   2, 2, 2, 2, 2, 2, 2, 2,
63   1, 1, 1, 1, 1, 1, 1, 1,
64   1, 1, 1, 1, 1, 1, 1, 1,
65   1, 1, 1, 1, 1, 1, 1, 1,
66   1, 1, 1, 1, 1, 1, 1, 1,
67   1, 1, 1, 1, 1, 1, 1, 1,
68   1, 1, 1, 1, 1, 1, 1, 1,
69   1, 1, 1, 1, 1, 1, 1, 1,
70   1, 1, 1, 1, 1, 1, 1, 1,
71   1, 1, 1, 1, 1, 1, 1, 1,
72   1, 1, 1, 1, 1, 1, 1, 1,
73   1, 1, 1, 1, 1, 1, 1, 1,
74   1, 1, 1, 1, 1, 1, 1, 1,
75   1, 1, 1, 1, 1, 1, 1, 1,
76   1, 1, 1, 1, 1, 1, 1, 1,
77   1, 1, 1, 1, 1, 1, 1, 1,
78   1, 1, 1, 1, 1, 1, 1, 1
79 };
80 
81 
82 //1. CABAC context initialization
83 void WelsCabacGlobalInit (PWelsDecoderContext pCabacCtx);
84 void WelsCabacContextInit (PWelsDecoderContext  pCtx, uint8_t eSliceType, int32_t iCabacInitIdc, int32_t iQp);
85 
86 //2. decoding Engine initialization
87 int32_t InitCabacDecEngineFromBS (PWelsCabacDecEngine pDecEngine, SBitStringAux* pBsAux);
88 void RestoreCabacDecEngineToBS (PWelsCabacDecEngine pDecEngine, SBitStringAux* pBsAux);
89 //3. actual decoding
90 int32_t Read32BitsCabac (PWelsCabacDecEngine pDecEngine, uint32_t& uiValue, int32_t& iNumBitsRead);
91 int32_t DecodeBinCabac (PWelsCabacDecEngine pDecEngine, PWelsCabacCtx pBinCtx, uint32_t& uiBit);
92 int32_t DecodeBypassCabac (PWelsCabacDecEngine pDecEngine, uint32_t& uiBinVal);
93 int32_t  DecodeTerminateCabac (PWelsCabacDecEngine pDecEngine, uint32_t& uiBinVal);
94 
95 //4. unary parsing
96 int32_t DecodeUnaryBinCabac (PWelsCabacDecEngine pDecEngine, PWelsCabacCtx pBinCtx, int32_t iCtxOffset,
97                              uint32_t& uiSymVal);
98 
99 //5. EXGk parsing
100 int32_t DecodeExpBypassCabac (PWelsCabacDecEngine pDecEngine, int32_t iCount, uint32_t& uiSymVal);
101 uint32_t DecodeUEGLevelCabac (PWelsCabacDecEngine pDecEngine, PWelsCabacCtx pBinCtx, uint32_t& uiBinVal);
102 int32_t DecodeUEGMvCabac (PWelsCabacDecEngine pDecEngine, PWelsCabacCtx pBinCtx, uint32_t iMaxC,  uint32_t& uiCode);
103 
104 #define WELS_CABAC_HALF    0x01FE
105 #define WELS_CABAC_QUARTER 0x0100
106 #define WELS_CABAC_FALSE_RETURN(iErrorInfo) \
107 if(iErrorInfo) { \
108   return iErrorInfo; \
109 }
110 }
111 #endif
112