History

Restore unix newlines after "Merge pull request #2991 from xiaotianshi2/master"

Some newlines were fixed in "Merge pull request #2997 from GuangweiWang/fix-issue-external", but lots were still left behind.

Martin Storsjö committed 8 years ago

Commit 1fb2f7d1 parent d43bfc114 files · +9238 −9238Browse files

Showing the changes to codec/decoder (7 of 14 files). Show all

Unified · Split

7 files
  1. codec/decoder/core/inc/dec_frame.h +156 −156
  2. codec/decoder/core/src/deblocking.cpp +1383 −1383
  3. codec/decoder/core/src/manage_dec_ref.cpp +897 −897
  4. codec/decoder/core/src/parse_mb_syn_cabac.cpp +1658 −1658
  5. codec/decoder/core/src/rec_mb.cpp +1044 −1044
  6. codec/decoder/plus/inc/welsDecoderExt.h +147 −147
  7. codec/decoder/plus/src/welsDecoderExt.cpp +1016 −1016
codec/decoder/core/inc/dec_frame.h+156−156
@@ -1,156 +1,156 @@
1/*!1/*!
2 * \copy2 * \copy
3 * Copyright (c) 2013, Cisco Systems3 * Copyright (c) 2013, Cisco Systems
4 * All rights reserved.4 * All rights reserved.
5 *5 *
6 * Redistribution and use in source and binary forms, with or without6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions7 * modification, are permitted provided that the following conditions
8 * are met:8 * are met:
9 *9 *
10 * * Redistributions of source code must retain the above copyright10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.11 * notice, this list of conditions and the following disclaimer.
12 *12 *
13 * * Redistributions in binary form must reproduce the above copyright13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the15 * the documentation and/or other materials provided with the
16 * distribution.16 * distribution.
17 *17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.29 * POSSIBILITY OF SUCH DAMAGE.
30 *30 *
31 */31 */
32 32
33//dec_frame.h33//dec_frame.h
34#ifndef WELS_DEC_FRAME_H__34#ifndef WELS_DEC_FRAME_H__
35#define WELS_DEC_FRAME_H__35#define WELS_DEC_FRAME_H__
36 36
37#include "typedefs.h"37#include "typedefs.h"
38#include "wels_const.h"38#include "wels_const.h"
39#include "wels_common_basis.h"39#include "wels_common_basis.h"
40#include "parameter_sets.h"40#include "parameter_sets.h"
41#include "nal_prefix.h"41#include "nal_prefix.h"
42#include "slice.h"42#include "slice.h"
43#include "picture.h"43#include "picture.h"
44#include "bit_stream.h"44#include "bit_stream.h"
45#include "fmo.h"45#include "fmo.h"
46 46
47namespace WelsDec {47namespace WelsDec {
48 48
49///////////////////////////////////DQ Layer level///////////////////////////////////49///////////////////////////////////DQ Layer level///////////////////////////////////
50typedef struct TagDqLayer SDqLayer;50typedef struct TagDqLayer SDqLayer;
51typedef SDqLayer* PDqLayer;51typedef SDqLayer* PDqLayer;
52typedef struct TagLayerInfo {52typedef struct TagLayerInfo {
53 SNalUnitHeaderExt sNalHeaderExt;53 SNalUnitHeaderExt sNalHeaderExt;
54 SSlice sSliceInLayer; // Here Slice identify to Frame on concept54 SSlice sSliceInLayer; // Here Slice identify to Frame on concept
55 PSubsetSps pSubsetSps; // current pSubsetSps used, memory alloc in external55 PSubsetSps pSubsetSps; // current pSubsetSps used, memory alloc in external
56 PSps pSps; // current sps based avc used, memory alloc in external56 PSps pSps; // current sps based avc used, memory alloc in external
57 PPps pPps; // current pps used57 PPps pPps; // current pps used
58} SLayerInfo, *PLayerInfo;58} SLayerInfo, *PLayerInfo;
59/* Layer Representation */59/* Layer Representation */
60 60
61struct TagDqLayer {61struct TagDqLayer {
62 SLayerInfo sLayerInfo;62 SLayerInfo sLayerInfo;
63 63
64 PBitStringAux pBitStringAux; // pointer to SBitStringAux64 PBitStringAux pBitStringAux; // pointer to SBitStringAux
65 PFmo pFmo; // Current fmo context pointer used65 PFmo pFmo; // Current fmo context pointer used
66 uint32_t* pMbType;66 uint32_t* pMbType;
67 int32_t* pSliceIdc; // using int32_t for slice_idc67 int32_t* pSliceIdc; // using int32_t for slice_idc
68 int16_t (*pMv[LIST_A])[MB_BLOCK4x4_NUM][MV_A];68 int16_t (*pMv[LIST_A])[MB_BLOCK4x4_NUM][MV_A];
69 int16_t (*pMvd[LIST_A])[MB_BLOCK4x4_NUM][MV_A];69 int16_t (*pMvd[LIST_A])[MB_BLOCK4x4_NUM][MV_A];
70 int8_t (*pRefIndex[LIST_A])[MB_BLOCK4x4_NUM];70 int8_t (*pRefIndex[LIST_A])[MB_BLOCK4x4_NUM];
71 int8_t (*pDirect)[MB_BLOCK4x4_NUM];71 int8_t (*pDirect)[MB_BLOCK4x4_NUM];
72 bool* pNoSubMbPartSizeLessThan8x8Flag;72 bool* pNoSubMbPartSizeLessThan8x8Flag;
73 bool* pTransformSize8x8Flag;73 bool* pTransformSize8x8Flag;
74 int8_t* pLumaQp;74 int8_t* pLumaQp;
75 int8_t (*pChromaQp)[2];75 int8_t (*pChromaQp)[2];
76 int8_t* pCbp;76 int8_t* pCbp;
77 uint16_t *pCbfDc;77 uint16_t *pCbfDc;
78 int8_t (*pNzc)[24];78 int8_t (*pNzc)[24];
79 int8_t (*pNzcRs)[24];79 int8_t (*pNzcRs)[24];
80 int8_t* pResidualPredFlag;80 int8_t* pResidualPredFlag;
81 int8_t* pInterPredictionDoneFlag;81 int8_t* pInterPredictionDoneFlag;
82 bool* pMbCorrectlyDecodedFlag;82 bool* pMbCorrectlyDecodedFlag;
83 bool* pMbRefConcealedFlag;83 bool* pMbRefConcealedFlag;
84 int16_t (*pScaledTCoeff)[MB_COEFF_LIST_SIZE];84 int16_t (*pScaledTCoeff)[MB_COEFF_LIST_SIZE];
85 int8_t (*pIntraPredMode)[8]; //0~3 top4x4 ; 4~6 left 4x4; 7 intra16x1685 int8_t (*pIntraPredMode)[8]; //0~3 top4x4 ; 4~6 left 4x4; 7 intra16x16
86 int8_t (*pIntra4x4FinalMode)[MB_BLOCK4x4_NUM];86 int8_t (*pIntra4x4FinalMode)[MB_BLOCK4x4_NUM];
87 uint8_t *pIntraNxNAvailFlag;87 uint8_t *pIntraNxNAvailFlag;
88 int8_t* pChromaPredMode;88 int8_t* pChromaPredMode;
89 //uint8_t (*motion_pred_flag[LIST_A])[MB_PARTITION_SIZE]; // 8x889 //uint8_t (*motion_pred_flag[LIST_A])[MB_PARTITION_SIZE]; // 8x8
90 uint32_t (*pSubMbType)[MB_SUB_PARTITION_SIZE];90 uint32_t (*pSubMbType)[MB_SUB_PARTITION_SIZE];
91 int32_t iLumaStride;91 int32_t iLumaStride;
92 int32_t iChromaStride;92 int32_t iChromaStride;
93 uint8_t* pPred[3];93 uint8_t* pPred[3];
94 int32_t iMbX;94 int32_t iMbX;
95 int32_t iMbY;95 int32_t iMbY;
96 int32_t iMbXyIndex;96 int32_t iMbXyIndex;
97 int32_t iMbWidth; // MB width of this picture, equal to sSps.iMbWidth97 int32_t iMbWidth; // MB width of this picture, equal to sSps.iMbWidth
98 int32_t iMbHeight; // MB height of this picture, equal to sSps.iMbHeight;98 int32_t iMbHeight; // MB height of this picture, equal to sSps.iMbHeight;
99 99
100 /* Common syntax elements across all slices of a DQLayer */100 /* Common syntax elements across all slices of a DQLayer */
101 int32_t iSliceIdcBackup;101 int32_t iSliceIdcBackup;
102 uint32_t uiSpsId;102 uint32_t uiSpsId;
103 uint32_t uiPpsId;103 uint32_t uiPpsId;
104 uint32_t uiDisableInterLayerDeblockingFilterIdc;104 uint32_t uiDisableInterLayerDeblockingFilterIdc;
105 int32_t iInterLayerSliceAlphaC0Offset;105 int32_t iInterLayerSliceAlphaC0Offset;
106 int32_t iInterLayerSliceBetaOffset;106 int32_t iInterLayerSliceBetaOffset;
107 //SPosOffset sScaledRefLayer;107 //SPosOffset sScaledRefLayer;
108 int32_t iSliceGroupChangeCycle;108 int32_t iSliceGroupChangeCycle;
109 109
110 PRefPicListReorderSyn pRefPicListReordering;110 PRefPicListReorderSyn pRefPicListReordering;
111 PPredWeightTabSyn pPredWeightTable;111 PPredWeightTabSyn pPredWeightTable;
112 PRefPicMarking pRefPicMarking; // Decoded reference picture marking syntaxs112 PRefPicMarking pRefPicMarking; // Decoded reference picture marking syntaxs
113 PRefBasePicMarking pRefPicBaseMarking;113 PRefBasePicMarking pRefPicBaseMarking;
114 114
115 PPicture pRef; // reference picture pointer115 PPicture pRef; // reference picture pointer
116 PPicture pDec; // reconstruction picture pointer for layer116 PPicture pDec; // reconstruction picture pointer for layer
117 117
118 int16_t iColocMv[2][16][2]; //Colocated MV cache118 int16_t iColocMv[2][16][2]; //Colocated MV cache
119 int8_t iColocRefIndex[2][16]; //Colocated RefIndex cache119 int8_t iColocRefIndex[2][16]; //Colocated RefIndex cache
120 int8_t iColocIntra[16]; //Colocated Intra cache120 int8_t iColocIntra[16]; //Colocated Intra cache
121 121
122 bool bUseWeightPredictionFlag;122 bool bUseWeightPredictionFlag;
123 bool bUseWeightedBiPredIdc;123 bool bUseWeightedBiPredIdc;
124 bool bStoreRefBasePicFlag; // iCurTid == 0 && iCurQid = 0 && bEncodeKeyPic = 1124 bool bStoreRefBasePicFlag; // iCurTid == 0 && iCurQid = 0 && bEncodeKeyPic = 1
125 bool bTCoeffLevelPredFlag;125 bool bTCoeffLevelPredFlag;
126 bool bConstrainedIntraResamplingFlag;126 bool bConstrainedIntraResamplingFlag;
127 uint8_t uiRefLayerDqId;127 uint8_t uiRefLayerDqId;
128 uint8_t uiRefLayerChromaPhaseXPlus1Flag;128 uint8_t uiRefLayerChromaPhaseXPlus1Flag;
129 uint8_t uiRefLayerChromaPhaseYPlus1;129 uint8_t uiRefLayerChromaPhaseYPlus1;
130 uint8_t uiLayerDqId; // dq_id of current layer130 uint8_t uiLayerDqId; // dq_id of current layer
131 bool bUseRefBasePicFlag; // whether reference pic or reference base pic is referred?131 bool bUseRefBasePicFlag; // whether reference pic or reference base pic is referred?
132};132};
133 133
134typedef struct TagGpuAvcLayer {134typedef struct TagGpuAvcLayer {
135 SLayerInfo sLayerInfo;135 SLayerInfo sLayerInfo;
136 PBitStringAux pBitStringAux; // pointer to SBitStringAux136 PBitStringAux pBitStringAux; // pointer to SBitStringAux
137 137
138 uint32_t* pMbType;138 uint32_t* pMbType;
139 int32_t* pSliceIdc; // using int32_t for slice_idc139 int32_t* pSliceIdc; // using int32_t for slice_idc
140 int8_t* pLumaQp;140 int8_t* pLumaQp;
141 int8_t* pCbp;141 int8_t* pCbp;
142 int8_t (*pNzc)[24];142 int8_t (*pNzc)[24];
143 int8_t (*pIntraPredMode)[8]; //0~3 top4x4 ; 4~6 left 4x4; 7 intra16x16143 int8_t (*pIntraPredMode)[8]; //0~3 top4x4 ; 4~6 left 4x4; 7 intra16x16
144 int32_t iMbX;144 int32_t iMbX;
145 int32_t iMbY;145 int32_t iMbY;
146 int32_t iMbXyIndex;146 int32_t iMbXyIndex;
147 int32_t iMbWidth; // MB width of this picture, equal to sSps.iMbWidth147 int32_t iMbWidth; // MB width of this picture, equal to sSps.iMbWidth
148 int32_t iMbHeight; // MB height of this picture, equal to sSps.iMbHeight;148 int32_t iMbHeight; // MB height of this picture, equal to sSps.iMbHeight;
149 149
150} SGpuAvcDqLayer, *PGpuAvcDqLayer;150} SGpuAvcDqLayer, *PGpuAvcDqLayer;
151 151
152///////////////////////////////////////////////////////////////////////152///////////////////////////////////////////////////////////////////////
153 153
154} // namespace WelsDec154} // namespace WelsDec
155 155
156#endif//WELS_DEC_FRAME_H__156#endif//WELS_DEC_FRAME_H__
codec/decoder/core/src/deblocking.cpp+1383−1383
@@ -1,1383 +1,1383 @@
1/*!1/*!
2 * \copy2 * \copy
3 * Copyright (c) 2010-2013, Cisco Systems3 * Copyright (c) 2010-2013, Cisco Systems
4 * All rights reserved.4 * All rights reserved.
5 *5 *
6 * Redistribution and use in source and binary forms, with or without6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions7 * modification, are permitted provided that the following conditions
8 * are met:8 * are met:
9 *9 *
10 * * Redistributions of source code must retain the above copyright10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.11 * notice, this list of conditions and the following disclaimer.
12 *12 *
13 * * Redistributions in binary form must reproduce the above copyright13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the15 * the documentation and/or other materials provided with the
16 * distribution.16 * distribution.
17 *17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.29 * POSSIBILITY OF SUCH DAMAGE.
30 *30 *
31 *31 *
32 * \file deblocking.c32 * \file deblocking.c
33 *33 *
34 * \brief Interfaces introduced in frame deblocking filtering34 * \brief Interfaces introduced in frame deblocking filtering
35 *35 *
36 * \date 08/02/201036 * \date 08/02/2010
37 *37 *
38 *************************************************************************************38 *************************************************************************************
39 */39 */
40 40
41#include "deblocking.h"41#include "deblocking.h"
42#include "deblocking_common.h"42#include "deblocking_common.h"
43#include "cpu_core.h"43#include "cpu_core.h"
44 44
45namespace WelsDec {45namespace WelsDec {
46 46
47#define NO_SUPPORTED_FILTER_IDX (-1)47#define NO_SUPPORTED_FILTER_IDX (-1)
48#define LEFT_FLAG_BIT 048#define LEFT_FLAG_BIT 0
49#define TOP_FLAG_BIT 149#define TOP_FLAG_BIT 1
50#define LEFT_FLAG_MASK 0x0150#define LEFT_FLAG_MASK 0x01
51#define TOP_FLAG_MASK 0x0251#define TOP_FLAG_MASK 0x02
52 52
53#define SAME_MB_DIFF_REFIDX53#define SAME_MB_DIFF_REFIDX
54#define g_kuiAlphaTable(x) g_kuiAlphaTable[(x)+12]54#define g_kuiAlphaTable(x) g_kuiAlphaTable[(x)+12]
55#define g_kiBetaTable(x) g_kiBetaTable[(x)+12]55#define g_kiBetaTable(x) g_kiBetaTable[(x)+12]
56#define g_kiTc0Table(x) g_kiTc0Table[(x)+12]56#define g_kiTc0Table(x) g_kiTc0Table[(x)+12]
57 57
58#define MB_BS_MV(iRefIndex, iMotionVector, iMbXy, iMbBn, iIndex, iNeighIndex) \58#define MB_BS_MV(iRefIndex, iMotionVector, iMbXy, iMbBn, iIndex, iNeighIndex) \
59(\59(\
60 ( iRefIndex[iMbXy][iIndex] - iRefIndex[iMbBn][iNeighIndex] )||\60 ( iRefIndex[iMbXy][iIndex] - iRefIndex[iMbBn][iNeighIndex] )||\
61 ( WELS_ABS( iMotionVector[iMbXy][iIndex][0] - iMotionVector[iMbBn][iNeighIndex][0] ) >= 4 ) ||\61 ( WELS_ABS( iMotionVector[iMbXy][iIndex][0] - iMotionVector[iMbBn][iNeighIndex][0] ) >= 4 ) ||\
62 ( WELS_ABS( iMotionVector[iMbXy][iIndex][1] - iMotionVector[iMbBn][iNeighIndex][1] ) >= 4 )\62 ( WELS_ABS( iMotionVector[iMbXy][iIndex][1] - iMotionVector[iMbBn][iNeighIndex][1] ) >= 4 )\
63)63)
64 64
65#if defined(SAME_MB_DIFF_REFIDX)65#if defined(SAME_MB_DIFF_REFIDX)
66#define SMB_EDGE_MV(iRefIndex, iMotionVector, iIndex, iNeighIndex) \66#define SMB_EDGE_MV(iRefIndex, iMotionVector, iIndex, iNeighIndex) \
67(\67(\
68 ( iRefIndex[iIndex] - iRefIndex[iNeighIndex] )||(\68 ( iRefIndex[iIndex] - iRefIndex[iNeighIndex] )||(\
69 ( WELS_ABS( iMotionVector[iIndex][0] - iMotionVector[iNeighIndex][0] ) &(~3) ) |\69 ( WELS_ABS( iMotionVector[iIndex][0] - iMotionVector[iNeighIndex][0] ) &(~3) ) |\
70 ( WELS_ABS( iMotionVector[iIndex][1] - iMotionVector[iNeighIndex][1] ) &(~3) ))\70 ( WELS_ABS( iMotionVector[iIndex][1] - iMotionVector[iNeighIndex][1] ) &(~3) ))\
71)71)
72#else72#else
73#define SMB_EDGE_MV(iRefIndex, iMotionVector, iIndex, iNeighIndex) \73#define SMB_EDGE_MV(iRefIndex, iMotionVector, iIndex, iNeighIndex) \
74(\74(\
75 !!(( WELS_ABS( iMotionVector[iIndex][0] - iMotionVector[iNeighIndex][0] ) &(~3) ) |( WELS_ABS( iMotionVector[iIndex][1] - iMotionVector[iNeighIndex][1] ) &(~3) ))\75 !!(( WELS_ABS( iMotionVector[iIndex][0] - iMotionVector[iNeighIndex][0] ) &(~3) ) |( WELS_ABS( iMotionVector[iIndex][1] - iMotionVector[iNeighIndex][1] ) &(~3) ))\
76)76)
77#endif77#endif
78 78
79#define BS_EDGE(bsx1, iRefIndex, iMotionVector, iIndex, iNeighIndex) \79#define BS_EDGE(bsx1, iRefIndex, iMotionVector, iIndex, iNeighIndex) \
80( (bsx1|SMB_EDGE_MV(iRefIndex, iMotionVector, iIndex, iNeighIndex))<<((uint8_t)(!!bsx1)))80( (bsx1|SMB_EDGE_MV(iRefIndex, iMotionVector, iIndex, iNeighIndex))<<((uint8_t)(!!bsx1)))
81 81
82#define GET_ALPHA_BETA_FROM_QP(iQp, iAlphaOffset, iBetaOffset, iIndex, iAlpha, iBeta) \82#define GET_ALPHA_BETA_FROM_QP(iQp, iAlphaOffset, iBetaOffset, iIndex, iAlpha, iBeta) \
83{\83{\
84 iIndex = (iQp + iAlphaOffset);\84 iIndex = (iQp + iAlphaOffset);\
85 iAlpha = g_kuiAlphaTable(iIndex);\85 iAlpha = g_kuiAlphaTable(iIndex);\
86 iBeta = g_kiBetaTable((iQp + iBetaOffset));\86 iBeta = g_kiBetaTable((iQp + iBetaOffset));\
87}87}
88 88
89static const uint8_t g_kuiAlphaTable[52 + 24] = { //this table refers to Table 8-16 in H.264/AVC standard89static const uint8_t g_kuiAlphaTable[52 + 24] = { //this table refers to Table 8-16 in H.264/AVC standard
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
92 0, 0, 0, 0, 0, 0, 4, 4, 5, 6,92 0, 0, 0, 0, 0, 0, 4, 4, 5, 6,
93 7, 8, 9, 10, 12, 13, 15, 17, 20, 22,93 7, 8, 9, 10, 12, 13, 15, 17, 20, 22,
94 25, 28, 32, 36, 40, 45, 50, 56, 63, 71,94 25, 28, 32, 36, 40, 45, 50, 56, 63, 71,
95 80, 90, 101, 113, 127, 144, 162, 182, 203, 226,95 80, 90, 101, 113, 127, 144, 162, 182, 203, 226,
96 255, 25596 255, 255
97 , 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 25597 , 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
98};98};
99 99
100static const int8_t g_kiBetaTable[52 + 24] = { //this table refers to Table 8-16 in H.264/AVC standard100static const int8_t g_kiBetaTable[52 + 24] = { //this table refers to Table 8-16 in H.264/AVC standard
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
103 0, 0, 0, 0, 0, 0, 2, 2, 2, 3,103 0, 0, 0, 0, 0, 0, 2, 2, 2, 3,
104 3, 3, 3, 4, 4, 4, 6, 6, 7, 7,104 3, 3, 3, 4, 4, 4, 6, 6, 7, 7,
105 8, 8, 9, 9, 10, 10, 11, 11, 12, 12,105 8, 8, 9, 9, 10, 10, 11, 11, 12, 12,
106 13, 13, 14, 14, 15, 15, 16, 16, 17, 17,106 13, 13, 14, 14, 15, 15, 16, 16, 17, 17,
107 18, 18107 18, 18
108 , 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18108 , 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18
109};109};
110 110
111static const int8_t g_kiTc0Table[52 + 24][4] = { //this table refers Table 8-17 in H.264/AVC standard111static const int8_t g_kiTc0Table[52 + 24][4] = { //this table refers Table 8-17 in H.264/AVC standard
112 { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 },112 { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 },
113 { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 },113 { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 },
114 { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 },114 { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 },
115 { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 },115 { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 },
116 { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 1 },116 { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 0 }, { -1, 0, 0, 1 },
117 { -1, 0, 0, 1 }, { -1, 0, 0, 1 }, { -1, 0, 0, 1 }, { -1, 0, 1, 1 }, { -1, 0, 1, 1 }, { -1, 1, 1, 1 },117 { -1, 0, 0, 1 }, { -1, 0, 0, 1 }, { -1, 0, 0, 1 }, { -1, 0, 1, 1 }, { -1, 0, 1, 1 }, { -1, 1, 1, 1 },
118 { -1, 1, 1, 1 }, { -1, 1, 1, 1 }, { -1, 1, 1, 1 }, { -1, 1, 1, 2 }, { -1, 1, 1, 2 }, { -1, 1, 1, 2 },118 { -1, 1, 1, 1 }, { -1, 1, 1, 1 }, { -1, 1, 1, 1 }, { -1, 1, 1, 2 }, { -1, 1, 1, 2 }, { -1, 1, 1, 2 },
119 { -1, 1, 1, 2 }, { -1, 1, 2, 3 }, { -1, 1, 2, 3 }, { -1, 2, 2, 3 }, { -1, 2, 2, 4 }, { -1, 2, 3, 4 },119 { -1, 1, 1, 2 }, { -1, 1, 2, 3 }, { -1, 1, 2, 3 }, { -1, 2, 2, 3 }, { -1, 2, 2, 4 }, { -1, 2, 3, 4 },
120 { -1, 2, 3, 4 }, { -1, 3, 3, 5 }, { -1, 3, 4, 6 }, { -1, 3, 4, 6 }, { -1, 4, 5, 7 }, { -1, 4, 5, 8 },120 { -1, 2, 3, 4 }, { -1, 3, 3, 5 }, { -1, 3, 4, 6 }, { -1, 3, 4, 6 }, { -1, 4, 5, 7 }, { -1, 4, 5, 8 },
121 { -1, 4, 6, 9 }, { -1, 5, 7, 10 }, { -1, 6, 8, 11 }, { -1, 6, 8, 13 }, { -1, 7, 10, 14 }, { -1, 8, 11, 16 },121 { -1, 4, 6, 9 }, { -1, 5, 7, 10 }, { -1, 6, 8, 11 }, { -1, 6, 8, 13 }, { -1, 7, 10, 14 }, { -1, 8, 11, 16 },
122 { -1, 9, 12, 18 }, { -1, 10, 13, 20 }, { -1, 11, 15, 23 }, { -1, 13, 17, 25 }122 { -1, 9, 12, 18 }, { -1, 10, 13, 20 }, { -1, 11, 15, 23 }, { -1, 13, 17, 25 }
123 , { -1, 13, 17, 25 }, { -1, 13, 17, 25 }, { -1, 13, 17, 25 }, { -1, 13, 17, 25 }, { -1, 13, 17, 25 }, { -1, 13, 17, 25 }123 , { -1, 13, 17, 25 }, { -1, 13, 17, 25 }, { -1, 13, 17, 25 }, { -1, 13, 17, 25 }, { -1, 13, 17, 25 }, { -1, 13, 17, 25 }
124 , { -1, 13, 17, 25 }, { -1, 13, 17, 25 }, { -1, 13, 17, 25 }, { -1, 13, 17, 25 }, { -1, 13, 17, 25 }, { -1, 13, 17, 25 }124 , { -1, 13, 17, 25 }, { -1, 13, 17, 25 }, { -1, 13, 17, 25 }, { -1, 13, 17, 25 }, { -1, 13, 17, 25 }, { -1, 13, 17, 25 }
125};125};
126 126
127static const uint8_t g_kuiTableBIdx[2][8] = {127static const uint8_t g_kuiTableBIdx[2][8] = {
128 {128 {
129 0, 4, 8, 12,129 0, 4, 8, 12,
130 3, 7, 11, 15130 3, 7, 11, 15
131 },131 },
132 132
133 {133 {
134 0, 1, 2, 3,134 0, 1, 2, 3,
135 12, 13, 14, 15135 12, 13, 14, 15
136 },136 },
137};137};
138 138
139static const uint8_t g_kuiTableB8x8Idx[2][16] = {139static const uint8_t g_kuiTableB8x8Idx[2][16] = {
140 {140 {
141 0, 1, 4, 5, 8, 9, 12, 13, // 0 1 | 2 3141 0, 1, 4, 5, 8, 9, 12, 13, // 0 1 | 2 3
142 2, 3, 6, 7, 10, 11, 14, 15 // 4 5 | 6 7142 2, 3, 6, 7, 10, 11, 14, 15 // 4 5 | 6 7
143 }, // ------------143 }, // ------------
144 // 8 9 | 10 11144 // 8 9 | 10 11
145 {145 {
146 // 12 13 | 14 15146 // 12 13 | 14 15
147 0, 1, 4, 5, 2, 3, 6, 7,147 0, 1, 4, 5, 2, 3, 6, 7,
148 8, 9, 12, 13, 10, 11, 14, 15148 8, 9, 12, 13, 10, 11, 14, 15
149 },149 },
150};150};
151 151
152#define TC0_TBL_LOOKUP(tc, iIndexA, pBS, bChroma) \152#define TC0_TBL_LOOKUP(tc, iIndexA, pBS, bChroma) \
153{\153{\
154 tc[0] = g_kiTc0Table(iIndexA)[pBS[0]] + bChroma;\154 tc[0] = g_kiTc0Table(iIndexA)[pBS[0]] + bChroma;\
155 tc[1] = g_kiTc0Table(iIndexA)[pBS[1]] + bChroma;\155 tc[1] = g_kiTc0Table(iIndexA)[pBS[1]] + bChroma;\
156 tc[2] = g_kiTc0Table(iIndexA)[pBS[2]] + bChroma;\156 tc[2] = g_kiTc0Table(iIndexA)[pBS[2]] + bChroma;\
157 tc[3] = g_kiTc0Table(iIndexA)[pBS[3]] + bChroma;\157 tc[3] = g_kiTc0Table(iIndexA)[pBS[3]] + bChroma;\
158}158}
159 159
160void inline DeblockingBSInsideMBAvsbase (int8_t* pNnzTab, uint8_t nBS[2][4][4], int32_t iLShiftFactor) {160void inline DeblockingBSInsideMBAvsbase (int8_t* pNnzTab, uint8_t nBS[2][4][4], int32_t iLShiftFactor) {
161 uint32_t uiNnz32b0, uiNnz32b1, uiNnz32b2, uiNnz32b3;161 uint32_t uiNnz32b0, uiNnz32b1, uiNnz32b2, uiNnz32b3;
162 162
163 uiNnz32b0 = * (uint32_t*) (pNnzTab + 0);163 uiNnz32b0 = * (uint32_t*) (pNnzTab + 0);
164 uiNnz32b1 = * (uint32_t*) (pNnzTab + 4);164 uiNnz32b1 = * (uint32_t*) (pNnzTab + 4);
165 uiNnz32b2 = * (uint32_t*) (pNnzTab + 8);165 uiNnz32b2 = * (uint32_t*) (pNnzTab + 8);
166 uiNnz32b3 = * (uint32_t*) (pNnzTab + 12);166 uiNnz32b3 = * (uint32_t*) (pNnzTab + 12);
167 167
168 nBS[0][1][0] = (pNnzTab[0] | pNnzTab[1]) << iLShiftFactor;168 nBS[0][1][0] = (pNnzTab[0] | pNnzTab[1]) << iLShiftFactor;
169 nBS[0][2][0] = (pNnzTab[1] | pNnzTab[2]) << iLShiftFactor;169 nBS[0][2][0] = (pNnzTab[1] | pNnzTab[2]) << iLShiftFactor;
170 nBS[0][3][0] = (pNnzTab[2] | pNnzTab[3]) << iLShiftFactor;170 nBS[0][3][0] = (pNnzTab[2] | pNnzTab[3]) << iLShiftFactor;
171 171
172 nBS[0][1][1] = (pNnzTab[4] | pNnzTab[5]) << iLShiftFactor;172 nBS[0][1][1] = (pNnzTab[4] | pNnzTab[5]) << iLShiftFactor;
173 nBS[0][2][1] = (pNnzTab[5] | pNnzTab[6]) << iLShiftFactor;173 nBS[0][2][1] = (pNnzTab[5] | pNnzTab[6]) << iLShiftFactor;
174 nBS[0][3][1] = (pNnzTab[6] | pNnzTab[7]) << iLShiftFactor;174 nBS[0][3][1] = (pNnzTab[6] | pNnzTab[7]) << iLShiftFactor;
175 * (uint32_t*)nBS[1][1] = (uiNnz32b0 | uiNnz32b1) << iLShiftFactor;175 * (uint32_t*)nBS[1][1] = (uiNnz32b0 | uiNnz32b1) << iLShiftFactor;
176 176
177 nBS[0][1][2] = (pNnzTab[8] | pNnzTab[9]) << iLShiftFactor;177 nBS[0][1][2] = (pNnzTab[8] | pNnzTab[9]) << iLShiftFactor;
178 nBS[0][2][2] = (pNnzTab[9] | pNnzTab[10]) << iLShiftFactor;178 nBS[0][2][2] = (pNnzTab[9] | pNnzTab[10]) << iLShiftFactor;
179 nBS[0][3][2] = (pNnzTab[10] | pNnzTab[11]) << iLShiftFactor;179 nBS[0][3][2] = (pNnzTab[10] | pNnzTab[11]) << iLShiftFactor;
180 * (uint32_t*)nBS[1][2] = (uiNnz32b1 | uiNnz32b2) << iLShiftFactor;180 * (uint32_t*)nBS[1][2] = (uiNnz32b1 | uiNnz32b2) << iLShiftFactor;
181 181
182 nBS[0][1][3] = (pNnzTab[12] | pNnzTab[13]) << iLShiftFactor;182 nBS[0][1][3] = (pNnzTab[12] | pNnzTab[13]) << iLShiftFactor;
183 nBS[0][2][3] = (pNnzTab[13] | pNnzTab[14]) << iLShiftFactor;183 nBS[0][2][3] = (pNnzTab[13] | pNnzTab[14]) << iLShiftFactor;
184 nBS[0][3][3] = (pNnzTab[14] | pNnzTab[15]) << iLShiftFactor;184 nBS[0][3][3] = (pNnzTab[14] | pNnzTab[15]) << iLShiftFactor;
185 * (uint32_t*)nBS[1][3] = (uiNnz32b2 | uiNnz32b3) << iLShiftFactor;185 * (uint32_t*)nBS[1][3] = (uiNnz32b2 | uiNnz32b3) << iLShiftFactor;
186}186}
187 187
188void inline DeblockingBSInsideMBAvsbase8x8 (int8_t* pNnzTab, uint8_t nBS[2][4][4], int32_t iLShiftFactor) {188void inline DeblockingBSInsideMBAvsbase8x8 (int8_t* pNnzTab, uint8_t nBS[2][4][4], int32_t iLShiftFactor) {
189 int8_t i8x8NnzTab[4];189 int8_t i8x8NnzTab[4];
190 for (int32_t i = 0; i < 4; i++) {190 for (int32_t i = 0; i < 4; i++) {
191 int32_t iBlkIdx = i << 2;191 int32_t iBlkIdx = i << 2;
192 i8x8NnzTab[i] = (pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 1]] |192 i8x8NnzTab[i] = (pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 1]] |
193 pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 2]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 3]]);193 pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 2]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 3]]);
194 }194 }
195 195
196 //vertical196 //vertical
197 nBS[0][2][0] = nBS[0][2][1] = (i8x8NnzTab[0] | i8x8NnzTab[1]) << iLShiftFactor;197 nBS[0][2][0] = nBS[0][2][1] = (i8x8NnzTab[0] | i8x8NnzTab[1]) << iLShiftFactor;
198 nBS[0][2][2] = nBS[0][2][3] = (i8x8NnzTab[2] | i8x8NnzTab[3]) << iLShiftFactor;198 nBS[0][2][2] = nBS[0][2][3] = (i8x8NnzTab[2] | i8x8NnzTab[3]) << iLShiftFactor;
199 //horizontal199 //horizontal
200 nBS[1][2][0] = nBS[1][2][1] = (i8x8NnzTab[0] | i8x8NnzTab[2]) << iLShiftFactor;200 nBS[1][2][0] = nBS[1][2][1] = (i8x8NnzTab[0] | i8x8NnzTab[2]) << iLShiftFactor;
201 nBS[1][2][2] = nBS[1][2][3] = (i8x8NnzTab[1] | i8x8NnzTab[3]) << iLShiftFactor;201 nBS[1][2][2] = nBS[1][2][3] = (i8x8NnzTab[1] | i8x8NnzTab[3]) << iLShiftFactor;
202}202}
203 203
204void static inline DeblockingBSInsideMBNormal (PDqLayer pCurDqLayer, uint8_t nBS[2][4][4], int8_t* pNnzTab,204void static inline DeblockingBSInsideMBNormal (PDqLayer pCurDqLayer, uint8_t nBS[2][4][4], int8_t* pNnzTab,
205 int32_t iMbXy) {205 int32_t iMbXy) {
206 uint32_t uiNnz32b0, uiNnz32b1, uiNnz32b2, uiNnz32b3;206 uint32_t uiNnz32b0, uiNnz32b1, uiNnz32b2, uiNnz32b3;
207 int8_t* iRefIndex = pCurDqLayer->pRefIndex[LIST_0][iMbXy];207 int8_t* iRefIndex = pCurDqLayer->pRefIndex[LIST_0][iMbXy];
208 ENFORCE_STACK_ALIGN_1D (uint8_t, uiBsx4, 4, 4);208 ENFORCE_STACK_ALIGN_1D (uint8_t, uiBsx4, 4, 4);
209 209
210 int8_t i8x8NnzTab[4];210 int8_t i8x8NnzTab[4];
211 211
212 if (pCurDqLayer->pTransformSize8x8Flag[iMbXy]) {212 if (pCurDqLayer->pTransformSize8x8Flag[iMbXy]) {
213 for (int32_t i = 0; i < 4; i++) {213 for (int32_t i = 0; i < 4; i++) {
214 int32_t iBlkIdx = i << 2;214 int32_t iBlkIdx = i << 2;
215 i8x8NnzTab[i] = (pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 1]] |215 i8x8NnzTab[i] = (pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 1]] |
216 pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 2]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 3]]);216 pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 2]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 3]]);
217 }217 }
218 //vertical218 //vertical
219 nBS[0][2][0] = nBS[0][2][1] = BS_EDGE ((i8x8NnzTab[0] | i8x8NnzTab[1]), iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy],219 nBS[0][2][0] = nBS[0][2][1] = BS_EDGE ((i8x8NnzTab[0] | i8x8NnzTab[1]), iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy],
220 g_kuiMbCountScan4Idx[1 << 2], g_kuiMbCountScan4Idx[0]);220 g_kuiMbCountScan4Idx[1 << 2], g_kuiMbCountScan4Idx[0]);
221 nBS[0][2][2] = nBS[0][2][3] = BS_EDGE ((i8x8NnzTab[2] | i8x8NnzTab[3]), iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy],221 nBS[0][2][2] = nBS[0][2][3] = BS_EDGE ((i8x8NnzTab[2] | i8x8NnzTab[3]), iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy],
222 g_kuiMbCountScan4Idx[3 << 2], g_kuiMbCountScan4Idx[2 << 2]);222 g_kuiMbCountScan4Idx[3 << 2], g_kuiMbCountScan4Idx[2 << 2]);
223 223
224 //horizontal224 //horizontal
225 nBS[1][2][0] = nBS[1][2][1] = BS_EDGE ((i8x8NnzTab[0] | i8x8NnzTab[2]), iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy],225 nBS[1][2][0] = nBS[1][2][1] = BS_EDGE ((i8x8NnzTab[0] | i8x8NnzTab[2]), iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy],
226 g_kuiMbCountScan4Idx[2 << 2], g_kuiMbCountScan4Idx[0]);226 g_kuiMbCountScan4Idx[2 << 2], g_kuiMbCountScan4Idx[0]);
227 nBS[1][2][2] = nBS[1][2][3] = BS_EDGE ((i8x8NnzTab[1] | i8x8NnzTab[3]), iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy],227 nBS[1][2][2] = nBS[1][2][3] = BS_EDGE ((i8x8NnzTab[1] | i8x8NnzTab[3]), iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy],
228 g_kuiMbCountScan4Idx[3 << 2], g_kuiMbCountScan4Idx[1 << 2]);228 g_kuiMbCountScan4Idx[3 << 2], g_kuiMbCountScan4Idx[1 << 2]);
229 } else {229 } else {
230 uiNnz32b0 = * (uint32_t*) (pNnzTab + 0);230 uiNnz32b0 = * (uint32_t*) (pNnzTab + 0);
231 uiNnz32b1 = * (uint32_t*) (pNnzTab + 4);231 uiNnz32b1 = * (uint32_t*) (pNnzTab + 4);
232 uiNnz32b2 = * (uint32_t*) (pNnzTab + 8);232 uiNnz32b2 = * (uint32_t*) (pNnzTab + 8);
233 uiNnz32b3 = * (uint32_t*) (pNnzTab + 12);233 uiNnz32b3 = * (uint32_t*) (pNnzTab + 12);
234 234
235 for (int i = 0; i < 3; i++)235 for (int i = 0; i < 3; i++)
236 uiBsx4[i] = pNnzTab[i] | pNnzTab[i + 1];236 uiBsx4[i] = pNnzTab[i] | pNnzTab[i + 1];
237 nBS[0][1][0] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 1, 0);237 nBS[0][1][0] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 1, 0);
238 nBS[0][2][0] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 2, 1);238 nBS[0][2][0] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 2, 1);
239 nBS[0][3][0] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 3, 2);239 nBS[0][3][0] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 3, 2);
240 240
241 for (int i = 0; i < 3; i++)241 for (int i = 0; i < 3; i++)
242 uiBsx4[i] = pNnzTab[4 + i] | pNnzTab[4 + i + 1];242 uiBsx4[i] = pNnzTab[4 + i] | pNnzTab[4 + i + 1];
243 nBS[0][1][1] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 5, 4);243 nBS[0][1][1] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 5, 4);
244 nBS[0][2][1] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 6, 5);244 nBS[0][2][1] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 6, 5);
245 nBS[0][3][1] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 7, 6);245 nBS[0][3][1] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 7, 6);
246 246
247 for (int i = 0; i < 3; i++)247 for (int i = 0; i < 3; i++)
248 uiBsx4[i] = pNnzTab[8 + i] | pNnzTab[8 + i + 1];248 uiBsx4[i] = pNnzTab[8 + i] | pNnzTab[8 + i + 1];
249 nBS[0][1][2] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 9, 8);249 nBS[0][1][2] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 9, 8);
250 nBS[0][2][2] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 10, 9);250 nBS[0][2][2] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 10, 9);
251 nBS[0][3][2] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 11, 10);251 nBS[0][3][2] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 11, 10);
252 252
253 for (int i = 0; i < 3; i++)253 for (int i = 0; i < 3; i++)
254 uiBsx4[i] = pNnzTab[12 + i] | pNnzTab[12 + i + 1];254 uiBsx4[i] = pNnzTab[12 + i] | pNnzTab[12 + i + 1];
255 nBS[0][1][3] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 13, 12);255 nBS[0][1][3] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 13, 12);
256 nBS[0][2][3] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 14, 13);256 nBS[0][2][3] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 14, 13);
257 nBS[0][3][3] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 15, 14);257 nBS[0][3][3] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 15, 14);
258 258
259 // horizontal259 // horizontal
260 * (uint32_t*)uiBsx4 = (uiNnz32b0 | uiNnz32b1);260 * (uint32_t*)uiBsx4 = (uiNnz32b0 | uiNnz32b1);
261 nBS[1][1][0] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 4, 0);261 nBS[1][1][0] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 4, 0);
262 nBS[1][1][1] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 5, 1);262 nBS[1][1][1] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 5, 1);
263 nBS[1][1][2] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 6, 2);263 nBS[1][1][2] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 6, 2);
264 nBS[1][1][3] = BS_EDGE (uiBsx4[3], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 7, 3);264 nBS[1][1][3] = BS_EDGE (uiBsx4[3], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 7, 3);
265 265
266 * (uint32_t*)uiBsx4 = (uiNnz32b1 | uiNnz32b2);266 * (uint32_t*)uiBsx4 = (uiNnz32b1 | uiNnz32b2);
267 nBS[1][2][0] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 8, 4);267 nBS[1][2][0] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 8, 4);
268 nBS[1][2][1] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 9, 5);268 nBS[1][2][1] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 9, 5);
269 nBS[1][2][2] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 10, 6);269 nBS[1][2][2] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 10, 6);
270 nBS[1][2][3] = BS_EDGE (uiBsx4[3], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 11, 7);270 nBS[1][2][3] = BS_EDGE (uiBsx4[3], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 11, 7);
271 271
272 * (uint32_t*)uiBsx4 = (uiNnz32b2 | uiNnz32b3);272 * (uint32_t*)uiBsx4 = (uiNnz32b2 | uiNnz32b3);
273 nBS[1][3][0] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 12, 8);273 nBS[1][3][0] = BS_EDGE (uiBsx4[0], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 12, 8);
274 nBS[1][3][1] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 13, 9);274 nBS[1][3][1] = BS_EDGE (uiBsx4[1], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 13, 9);
275 nBS[1][3][2] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 14, 10);275 nBS[1][3][2] = BS_EDGE (uiBsx4[2], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 14, 10);
276 nBS[1][3][3] = BS_EDGE (uiBsx4[3], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 15, 11);276 nBS[1][3][3] = BS_EDGE (uiBsx4[3], iRefIndex, pCurDqLayer->pMv[LIST_0][iMbXy], 15, 11);
277 }277 }
278}278}
279 279
280void static inline DeblockingBSliceBSInsideMBNormal (PDqLayer pCurDqLayer, uint8_t nBS[2][4][4], int8_t* pNnzTab,280void static inline DeblockingBSliceBSInsideMBNormal (PDqLayer pCurDqLayer, uint8_t nBS[2][4][4], int8_t* pNnzTab,
281 int32_t iMbXy) {281 int32_t iMbXy) {
282 uint32_t uiNnz32b0, uiNnz32b1, uiNnz32b2, uiNnz32b3;282 uint32_t uiNnz32b0, uiNnz32b1, uiNnz32b2, uiNnz32b3;
283 int8_t* iRefIndex[LIST_A];283 int8_t* iRefIndex[LIST_A];
284 iRefIndex[LIST_0] = pCurDqLayer->pRefIndex[LIST_0][iMbXy];284 iRefIndex[LIST_0] = pCurDqLayer->pRefIndex[LIST_0][iMbXy];
285 iRefIndex[LIST_1] = pCurDqLayer->pRefIndex[LIST_1][iMbXy];285 iRefIndex[LIST_1] = pCurDqLayer->pRefIndex[LIST_1][iMbXy];
286 ENFORCE_STACK_ALIGN_1D (uint8_t, uiBsx4, 4, 4);286 ENFORCE_STACK_ALIGN_1D (uint8_t, uiBsx4, 4, 4);
287 287
288 int8_t i8x8NnzTab[4];288 int8_t i8x8NnzTab[4];
289 289
290 if (pCurDqLayer->pTransformSize8x8Flag[iMbXy]) {290 if (pCurDqLayer->pTransformSize8x8Flag[iMbXy]) {
291 for (int32_t i = 0; i < 4; i++) {291 for (int32_t i = 0; i < 4; i++) {
292 int32_t iBlkIdx = i << 2;292 int32_t iBlkIdx = i << 2;
293 i8x8NnzTab[i] = (pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 1]] |293 i8x8NnzTab[i] = (pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 1]] |
294 pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 2]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 3]]);294 pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 2]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 3]]);
295 }295 }
296 //vertical296 //vertical
297 int8_t iIndex = g_kuiMbCountScan4Idx[1 << 2];297 int8_t iIndex = g_kuiMbCountScan4Idx[1 << 2];
298 int8_t iNeigborIndex = g_kuiMbCountScan4Idx[0];298 int8_t iNeigborIndex = g_kuiMbCountScan4Idx[0];
299 nBS[0][2][0] = nBS[0][2][1] = 1;299 nBS[0][2][0] = nBS[0][2][1] = 1;
300 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {300 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
301 if (iRefIndex[listIdx][iIndex] > REF_NOT_IN_LIST && iRefIndex[listIdx][iNeigborIndex] > REF_NOT_IN_LIST) {301 if (iRefIndex[listIdx][iIndex] > REF_NOT_IN_LIST && iRefIndex[listIdx][iNeigborIndex] > REF_NOT_IN_LIST) {
302 nBS[0][2][0] = nBS[0][2][1] = BS_EDGE ((i8x8NnzTab[0] | i8x8NnzTab[1]), iRefIndex[listIdx],302 nBS[0][2][0] = nBS[0][2][1] = BS_EDGE ((i8x8NnzTab[0] | i8x8NnzTab[1]), iRefIndex[listIdx],
303 pCurDqLayer->pMv[listIdx][iMbXy],303 pCurDqLayer->pMv[listIdx][iMbXy],
304 iIndex, iNeigborIndex);304 iIndex, iNeigborIndex);
305 break;305 break;
306 }306 }
307 }307 }
308 iIndex = g_kuiMbCountScan4Idx[3 << 2];308 iIndex = g_kuiMbCountScan4Idx[3 << 2];
309 iNeigborIndex = g_kuiMbCountScan4Idx[2 << 2];309 iNeigborIndex = g_kuiMbCountScan4Idx[2 << 2];
310 nBS[0][2][2] = nBS[0][2][3] = 1;310 nBS[0][2][2] = nBS[0][2][3] = 1;
311 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {311 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
312 if (iRefIndex[listIdx][iIndex] > REF_NOT_IN_LIST && iRefIndex[listIdx][iNeigborIndex] > REF_NOT_IN_LIST) {312 if (iRefIndex[listIdx][iIndex] > REF_NOT_IN_LIST && iRefIndex[listIdx][iNeigborIndex] > REF_NOT_IN_LIST) {
313 nBS[0][2][2] = nBS[0][2][3] = BS_EDGE ((i8x8NnzTab[2] | i8x8NnzTab[3]), iRefIndex[listIdx],313 nBS[0][2][2] = nBS[0][2][3] = BS_EDGE ((i8x8NnzTab[2] | i8x8NnzTab[3]), iRefIndex[listIdx],
314 pCurDqLayer->pMv[listIdx][iMbXy],314 pCurDqLayer->pMv[listIdx][iMbXy],
315 iIndex, iNeigborIndex);315 iIndex, iNeigborIndex);
316 break;316 break;
317 }317 }
318 }318 }
319 319
320 //horizontal320 //horizontal
321 iIndex = g_kuiMbCountScan4Idx[2 << 2];321 iIndex = g_kuiMbCountScan4Idx[2 << 2];
322 iNeigborIndex = g_kuiMbCountScan4Idx[0];322 iNeigborIndex = g_kuiMbCountScan4Idx[0];
323 nBS[1][2][0] = nBS[1][2][1] = 1;323 nBS[1][2][0] = nBS[1][2][1] = 1;
324 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {324 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
325 if (iRefIndex[listIdx][iIndex] > REF_NOT_IN_LIST && iRefIndex[listIdx][iNeigborIndex] > REF_NOT_IN_LIST) {325 if (iRefIndex[listIdx][iIndex] > REF_NOT_IN_LIST && iRefIndex[listIdx][iNeigborIndex] > REF_NOT_IN_LIST) {
326 nBS[1][2][0] = nBS[1][2][1] = BS_EDGE ((i8x8NnzTab[0] | i8x8NnzTab[2]), iRefIndex[listIdx],326 nBS[1][2][0] = nBS[1][2][1] = BS_EDGE ((i8x8NnzTab[0] | i8x8NnzTab[2]), iRefIndex[listIdx],
327 pCurDqLayer->pMv[listIdx][iMbXy],327 pCurDqLayer->pMv[listIdx][iMbXy],
328 iIndex, iNeigborIndex);328 iIndex, iNeigborIndex);
329 break;329 break;
330 }330 }
331 }331 }
332 332
333 iIndex = g_kuiMbCountScan4Idx[3 << 2];333 iIndex = g_kuiMbCountScan4Idx[3 << 2];
334 iNeigborIndex = g_kuiMbCountScan4Idx[1 << 2];334 iNeigborIndex = g_kuiMbCountScan4Idx[1 << 2];
335 nBS[1][2][2] = nBS[1][2][3] = 1;335 nBS[1][2][2] = nBS[1][2][3] = 1;
336 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {336 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
337 if (iRefIndex[listIdx][iIndex] > REF_NOT_IN_LIST && iRefIndex[listIdx][iNeigborIndex] > REF_NOT_IN_LIST) {337 if (iRefIndex[listIdx][iIndex] > REF_NOT_IN_LIST && iRefIndex[listIdx][iNeigborIndex] > REF_NOT_IN_LIST) {
338 nBS[1][2][2] = nBS[1][2][3] = BS_EDGE ((i8x8NnzTab[1] | i8x8NnzTab[3]), iRefIndex[listIdx],338 nBS[1][2][2] = nBS[1][2][3] = BS_EDGE ((i8x8NnzTab[1] | i8x8NnzTab[3]), iRefIndex[listIdx],
339 pCurDqLayer->pMv[listIdx][iMbXy],339 pCurDqLayer->pMv[listIdx][iMbXy],
340 iIndex, iNeigborIndex);340 iIndex, iNeigborIndex);
341 break;341 break;
342 }342 }
343 }343 }
344 } else {344 } else {
345 uiNnz32b0 = * (uint32_t*) (pNnzTab + 0);345 uiNnz32b0 = * (uint32_t*) (pNnzTab + 0);
346 uiNnz32b1 = * (uint32_t*) (pNnzTab + 4);346 uiNnz32b1 = * (uint32_t*) (pNnzTab + 4);
347 uiNnz32b2 = * (uint32_t*) (pNnzTab + 8);347 uiNnz32b2 = * (uint32_t*) (pNnzTab + 8);
348 uiNnz32b3 = * (uint32_t*) (pNnzTab + 12);348 uiNnz32b3 = * (uint32_t*) (pNnzTab + 12);
349 349
350 for (int i = 0; i < 3; i++)350 for (int i = 0; i < 3; i++)
351 uiBsx4[i] = pNnzTab[i] | pNnzTab[i + 1];351 uiBsx4[i] = pNnzTab[i] | pNnzTab[i + 1];
352 nBS[0][1][0] = 1;352 nBS[0][1][0] = 1;
353 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {353 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
354 if (iRefIndex[listIdx][1] > REF_NOT_IN_LIST && iRefIndex[listIdx][0] > REF_NOT_IN_LIST) {354 if (iRefIndex[listIdx][1] > REF_NOT_IN_LIST && iRefIndex[listIdx][0] > REF_NOT_IN_LIST) {
355 nBS[0][1][0] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 1, 0);355 nBS[0][1][0] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 1, 0);
356 break;356 break;
357 }357 }
358 }358 }
359 nBS[0][2][0] = 1;359 nBS[0][2][0] = 1;
360 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {360 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
361 if (iRefIndex[listIdx][2] > REF_NOT_IN_LIST && iRefIndex[listIdx][1] > REF_NOT_IN_LIST) {361 if (iRefIndex[listIdx][2] > REF_NOT_IN_LIST && iRefIndex[listIdx][1] > REF_NOT_IN_LIST) {
362 nBS[0][2][0] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 2, 1);362 nBS[0][2][0] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 2, 1);
363 break;363 break;
364 }364 }
365 }365 }
366 nBS[0][3][0] = 1;366 nBS[0][3][0] = 1;
367 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {367 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
368 if (iRefIndex[listIdx][3] > REF_NOT_IN_LIST && iRefIndex[listIdx][2] > REF_NOT_IN_LIST) {368 if (iRefIndex[listIdx][3] > REF_NOT_IN_LIST && iRefIndex[listIdx][2] > REF_NOT_IN_LIST) {
369 nBS[0][3][0] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 3, 2);369 nBS[0][3][0] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 3, 2);
370 break;370 break;
371 }371 }
372 }372 }
373 373
374 for (int i = 0; i < 3; i++)374 for (int i = 0; i < 3; i++)
375 uiBsx4[i] = pNnzTab[4 + i] | pNnzTab[4 + i + 1];375 uiBsx4[i] = pNnzTab[4 + i] | pNnzTab[4 + i + 1];
376 nBS[0][1][1] = 1;376 nBS[0][1][1] = 1;
377 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {377 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
378 if (iRefIndex[listIdx][5] > REF_NOT_IN_LIST && iRefIndex[listIdx][4] > REF_NOT_IN_LIST) {378 if (iRefIndex[listIdx][5] > REF_NOT_IN_LIST && iRefIndex[listIdx][4] > REF_NOT_IN_LIST) {
379 nBS[0][1][1] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 5, 4);379 nBS[0][1][1] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 5, 4);
380 break;380 break;
381 }381 }
382 }382 }
383 nBS[0][2][1] = 1;383 nBS[0][2][1] = 1;
384 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {384 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
385 if (iRefIndex[listIdx][6] > REF_NOT_IN_LIST && iRefIndex[listIdx][5] > REF_NOT_IN_LIST) {385 if (iRefIndex[listIdx][6] > REF_NOT_IN_LIST && iRefIndex[listIdx][5] > REF_NOT_IN_LIST) {
386 nBS[0][2][1] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 6, 5);386 nBS[0][2][1] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 6, 5);
387 break;387 break;
388 }388 }
389 }389 }
390 nBS[0][3][1] = 1;390 nBS[0][3][1] = 1;
391 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {391 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
392 if (iRefIndex[listIdx][7] > REF_NOT_IN_LIST && iRefIndex[listIdx][6] > REF_NOT_IN_LIST) {392 if (iRefIndex[listIdx][7] > REF_NOT_IN_LIST && iRefIndex[listIdx][6] > REF_NOT_IN_LIST) {
393 nBS[0][3][1] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 7, 6);393 nBS[0][3][1] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 7, 6);
394 break;394 break;
395 }395 }
396 }396 }
397 397
398 for (int i = 0; i < 3; i++)398 for (int i = 0; i < 3; i++)
399 uiBsx4[i] = pNnzTab[8 + i] | pNnzTab[8 + i + 1];399 uiBsx4[i] = pNnzTab[8 + i] | pNnzTab[8 + i + 1];
400 nBS[0][1][2] = 1;400 nBS[0][1][2] = 1;
401 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {401 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
402 if (iRefIndex[listIdx][9] > REF_NOT_IN_LIST && iRefIndex[listIdx][8] > REF_NOT_IN_LIST) {402 if (iRefIndex[listIdx][9] > REF_NOT_IN_LIST && iRefIndex[listIdx][8] > REF_NOT_IN_LIST) {
403 nBS[0][1][2] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 9, 8);403 nBS[0][1][2] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 9, 8);
404 break;404 break;
405 }405 }
406 }406 }
407 nBS[0][2][2] = 1;407 nBS[0][2][2] = 1;
408 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {408 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
409 if (iRefIndex[listIdx][10] > REF_NOT_IN_LIST && iRefIndex[listIdx][9] > REF_NOT_IN_LIST) {409 if (iRefIndex[listIdx][10] > REF_NOT_IN_LIST && iRefIndex[listIdx][9] > REF_NOT_IN_LIST) {
410 nBS[0][2][2] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 10, 9);410 nBS[0][2][2] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 10, 9);
411 break;411 break;
412 }412 }
413 }413 }
414 nBS[0][3][2] = 1;414 nBS[0][3][2] = 1;
415 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {415 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
416 if (iRefIndex[listIdx][11] > REF_NOT_IN_LIST && iRefIndex[listIdx][10] > REF_NOT_IN_LIST) {416 if (iRefIndex[listIdx][11] > REF_NOT_IN_LIST && iRefIndex[listIdx][10] > REF_NOT_IN_LIST) {
417 nBS[0][3][2] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 11, 10);417 nBS[0][3][2] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 11, 10);
418 break;418 break;
419 }419 }
420 }420 }
421 421
422 for (int i = 0; i < 3; i++)422 for (int i = 0; i < 3; i++)
423 uiBsx4[i] = pNnzTab[12 + i] | pNnzTab[12 + i + 1];423 uiBsx4[i] = pNnzTab[12 + i] | pNnzTab[12 + i + 1];
424 nBS[0][1][3] = 1;424 nBS[0][1][3] = 1;
425 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {425 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
426 if (iRefIndex[listIdx][13] > REF_NOT_IN_LIST && iRefIndex[listIdx][12] > REF_NOT_IN_LIST) {426 if (iRefIndex[listIdx][13] > REF_NOT_IN_LIST && iRefIndex[listIdx][12] > REF_NOT_IN_LIST) {
427 nBS[0][1][3] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 13, 12);427 nBS[0][1][3] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 13, 12);
428 break;428 break;
429 }429 }
430 }430 }
431 nBS[0][2][3] = 1;431 nBS[0][2][3] = 1;
432 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {432 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
433 if (iRefIndex[listIdx][14] > REF_NOT_IN_LIST && iRefIndex[listIdx][13] > REF_NOT_IN_LIST) {433 if (iRefIndex[listIdx][14] > REF_NOT_IN_LIST && iRefIndex[listIdx][13] > REF_NOT_IN_LIST) {
434 nBS[0][2][3] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 14, 13);434 nBS[0][2][3] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 14, 13);
435 break;435 break;
436 }436 }
437 }437 }
438 nBS[0][3][3] = 1;438 nBS[0][3][3] = 1;
439 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {439 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
440 if (iRefIndex[listIdx][15] > REF_NOT_IN_LIST && iRefIndex[listIdx][14] > REF_NOT_IN_LIST) {440 if (iRefIndex[listIdx][15] > REF_NOT_IN_LIST && iRefIndex[listIdx][14] > REF_NOT_IN_LIST) {
441 nBS[0][3][3] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 15, 14);441 nBS[0][3][3] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 15, 14);
442 break;442 break;
443 }443 }
444 }444 }
445 445
446 // horizontal446 // horizontal
447 * (uint32_t*)uiBsx4 = (uiNnz32b0 | uiNnz32b1);447 * (uint32_t*)uiBsx4 = (uiNnz32b0 | uiNnz32b1);
448 nBS[1][1][0] = 1;448 nBS[1][1][0] = 1;
449 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {449 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
450 if (iRefIndex[listIdx][4] > REF_NOT_IN_LIST && iRefIndex[listIdx][0] > REF_NOT_IN_LIST) {450 if (iRefIndex[listIdx][4] > REF_NOT_IN_LIST && iRefIndex[listIdx][0] > REF_NOT_IN_LIST) {
451 nBS[1][1][0] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 4, 0);451 nBS[1][1][0] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 4, 0);
452 break;452 break;
453 }453 }
454 }454 }
455 nBS[1][1][1] = 1;455 nBS[1][1][1] = 1;
456 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {456 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
457 if (iRefIndex[listIdx][5] > REF_NOT_IN_LIST && iRefIndex[listIdx][1] > REF_NOT_IN_LIST) {457 if (iRefIndex[listIdx][5] > REF_NOT_IN_LIST && iRefIndex[listIdx][1] > REF_NOT_IN_LIST) {
458 nBS[1][1][1] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 5, 1);458 nBS[1][1][1] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 5, 1);
459 break;459 break;
460 }460 }
461 }461 }
462 nBS[1][1][2] = 1;462 nBS[1][1][2] = 1;
463 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {463 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
464 if (iRefIndex[listIdx][6] > REF_NOT_IN_LIST && iRefIndex[listIdx][2] > REF_NOT_IN_LIST) {464 if (iRefIndex[listIdx][6] > REF_NOT_IN_LIST && iRefIndex[listIdx][2] > REF_NOT_IN_LIST) {
465 nBS[1][1][2] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 6, 2);465 nBS[1][1][2] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 6, 2);
466 break;466 break;
467 }467 }
468 }468 }
469 nBS[1][1][3] = 1;469 nBS[1][1][3] = 1;
470 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {470 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
471 if (iRefIndex[listIdx][7] > REF_NOT_IN_LIST && iRefIndex[listIdx][3] > REF_NOT_IN_LIST) {471 if (iRefIndex[listIdx][7] > REF_NOT_IN_LIST && iRefIndex[listIdx][3] > REF_NOT_IN_LIST) {
472 nBS[1][1][3] = BS_EDGE (uiBsx4[3], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 7, 3);472 nBS[1][1][3] = BS_EDGE (uiBsx4[3], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 7, 3);
473 break;473 break;
474 }474 }
475 }475 }
476 476
477 * (uint32_t*)uiBsx4 = (uiNnz32b1 | uiNnz32b2);477 * (uint32_t*)uiBsx4 = (uiNnz32b1 | uiNnz32b2);
478 nBS[1][2][0] = 1;478 nBS[1][2][0] = 1;
479 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {479 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
480 if (iRefIndex[listIdx][8] > REF_NOT_IN_LIST && iRefIndex[listIdx][4] > REF_NOT_IN_LIST) {480 if (iRefIndex[listIdx][8] > REF_NOT_IN_LIST && iRefIndex[listIdx][4] > REF_NOT_IN_LIST) {
481 nBS[1][2][0] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 8, 4);481 nBS[1][2][0] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 8, 4);
482 break;482 break;
483 }483 }
484 }484 }
485 nBS[1][2][1] = 1;485 nBS[1][2][1] = 1;
486 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {486 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
487 if (iRefIndex[listIdx][9] > REF_NOT_IN_LIST && iRefIndex[listIdx][5] > REF_NOT_IN_LIST) {487 if (iRefIndex[listIdx][9] > REF_NOT_IN_LIST && iRefIndex[listIdx][5] > REF_NOT_IN_LIST) {
488 nBS[1][2][1] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 9, 5);488 nBS[1][2][1] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 9, 5);
489 break;489 break;
490 }490 }
491 }491 }
492 nBS[1][2][2] = 1;492 nBS[1][2][2] = 1;
493 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {493 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
494 if (iRefIndex[listIdx][10] > REF_NOT_IN_LIST && iRefIndex[listIdx][6] > REF_NOT_IN_LIST) {494 if (iRefIndex[listIdx][10] > REF_NOT_IN_LIST && iRefIndex[listIdx][6] > REF_NOT_IN_LIST) {
495 nBS[1][2][2] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 10, 6);495 nBS[1][2][2] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 10, 6);
496 break;496 break;
497 }497 }
498 }498 }
499 nBS[1][2][3] = 1;499 nBS[1][2][3] = 1;
500 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {500 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
501 if (iRefIndex[listIdx][11] > REF_NOT_IN_LIST && iRefIndex[listIdx][7] > REF_NOT_IN_LIST) {501 if (iRefIndex[listIdx][11] > REF_NOT_IN_LIST && iRefIndex[listIdx][7] > REF_NOT_IN_LIST) {
502 nBS[1][2][3] = BS_EDGE (uiBsx4[3], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 11, 7);502 nBS[1][2][3] = BS_EDGE (uiBsx4[3], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 11, 7);
503 break;503 break;
504 }504 }
505 }505 }
506 506
507 * (uint32_t*)uiBsx4 = (uiNnz32b2 | uiNnz32b3);507 * (uint32_t*)uiBsx4 = (uiNnz32b2 | uiNnz32b3);
508 nBS[1][3][0] = 1;508 nBS[1][3][0] = 1;
509 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {509 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
510 if (iRefIndex[listIdx][12] > REF_NOT_IN_LIST && iRefIndex[listIdx][8] > REF_NOT_IN_LIST) {510 if (iRefIndex[listIdx][12] > REF_NOT_IN_LIST && iRefIndex[listIdx][8] > REF_NOT_IN_LIST) {
511 nBS[1][3][0] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 12, 8);511 nBS[1][3][0] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 12, 8);
512 break;512 break;
513 }513 }
514 }514 }
515 nBS[1][3][1] = 1;515 nBS[1][3][1] = 1;
516 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {516 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
517 if (iRefIndex[listIdx][13] > REF_NOT_IN_LIST && iRefIndex[listIdx][9] > REF_NOT_IN_LIST) {517 if (iRefIndex[listIdx][13] > REF_NOT_IN_LIST && iRefIndex[listIdx][9] > REF_NOT_IN_LIST) {
518 nBS[1][3][1] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 13, 9);518 nBS[1][3][1] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 13, 9);
519 break;519 break;
520 }520 }
521 }521 }
522 nBS[1][3][2] = 1;522 nBS[1][3][2] = 1;
523 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {523 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
524 if (iRefIndex[listIdx][14] > REF_NOT_IN_LIST && iRefIndex[listIdx][10] > REF_NOT_IN_LIST) {524 if (iRefIndex[listIdx][14] > REF_NOT_IN_LIST && iRefIndex[listIdx][10] > REF_NOT_IN_LIST) {
525 nBS[1][3][2] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 14, 10);525 nBS[1][3][2] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 14, 10);
526 break;526 break;
527 }527 }
528 }528 }
529 nBS[1][3][3] = 1;529 nBS[1][3][3] = 1;
530 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {530 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
531 if (iRefIndex[listIdx][15] > REF_NOT_IN_LIST && iRefIndex[listIdx][11] > REF_NOT_IN_LIST) {531 if (iRefIndex[listIdx][15] > REF_NOT_IN_LIST && iRefIndex[listIdx][11] > REF_NOT_IN_LIST) {
532 nBS[1][3][3] = BS_EDGE (uiBsx4[3], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 15, 11);532 nBS[1][3][3] = BS_EDGE (uiBsx4[3], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 15, 11);
533 break;533 break;
534 }534 }
535 }535 }
536 }536 }
537}537}
538 538
539 539
540uint32_t DeblockingBsMarginalMBAvcbase (PDqLayer pCurDqLayer, int32_t iEdge, int32_t iNeighMb, int32_t iMbXy) {540uint32_t DeblockingBsMarginalMBAvcbase (PDqLayer pCurDqLayer, int32_t iEdge, int32_t iNeighMb, int32_t iMbXy) {
541 int32_t i, j;541 int32_t i, j;
542 uint32_t uiBSx4;542 uint32_t uiBSx4;
543 uint8_t* pBS = (uint8_t*) (&uiBSx4);543 uint8_t* pBS = (uint8_t*) (&uiBSx4);
544 const uint8_t* pBIdx = &g_kuiTableBIdx[iEdge][0];544 const uint8_t* pBIdx = &g_kuiTableBIdx[iEdge][0];
545 const uint8_t* pBnIdx = &g_kuiTableBIdx[iEdge][4];545 const uint8_t* pBnIdx = &g_kuiTableBIdx[iEdge][4];
546 const uint8_t* pB8x8Idx = &g_kuiTableB8x8Idx[iEdge][0];546 const uint8_t* pB8x8Idx = &g_kuiTableB8x8Idx[iEdge][0];
547 const uint8_t* pBn8x8Idx = &g_kuiTableB8x8Idx[iEdge][8];547 const uint8_t* pBn8x8Idx = &g_kuiTableB8x8Idx[iEdge][8];
548 548
549 if (pCurDqLayer->pTransformSize8x8Flag[iMbXy] && pCurDqLayer->pTransformSize8x8Flag[iNeighMb]) {549 if (pCurDqLayer->pTransformSize8x8Flag[iMbXy] && pCurDqLayer->pTransformSize8x8Flag[iNeighMb]) {
550 for (i = 0; i < 2; i++) {550 for (i = 0; i < 2; i++) {
551 uint8_t uiNzc = 0;551 uint8_t uiNzc = 0;
552 for (j = 0; uiNzc == 0 && j < 4; j++) {552 for (j = 0; uiNzc == 0 && j < 4; j++) {
553 uiNzc |= (pCurDqLayer->pNzc[iMbXy][* (pB8x8Idx + j)] | pCurDqLayer->pNzc[iNeighMb][* (pBn8x8Idx + j)]);553 uiNzc |= (pCurDqLayer->pNzc[iMbXy][* (pB8x8Idx + j)] | pCurDqLayer->pNzc[iNeighMb][* (pBn8x8Idx + j)]);
554 }554 }
555 if (uiNzc) {555 if (uiNzc) {
556 pBS[i << 1] = pBS[1 + (i << 1)] = 2;556 pBS[i << 1] = pBS[1 + (i << 1)] = 2;
557 } else {557 } else {
558 pBS[i << 1] = pBS[1 + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[LIST_0], pCurDqLayer->pMv[LIST_0], iMbXy, iNeighMb,558 pBS[i << 1] = pBS[1 + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[LIST_0], pCurDqLayer->pMv[LIST_0], iMbXy, iNeighMb,
559 *pB8x8Idx, *pBn8x8Idx);559 *pB8x8Idx, *pBn8x8Idx);
560 }560 }
561 pB8x8Idx += 4;561 pB8x8Idx += 4;
562 pBn8x8Idx += 4;562 pBn8x8Idx += 4;
563 }563 }
564 } else if (pCurDqLayer->pTransformSize8x8Flag[iMbXy]) {564 } else if (pCurDqLayer->pTransformSize8x8Flag[iMbXy]) {
565 for (i = 0; i < 2; i++) {565 for (i = 0; i < 2; i++) {
566 uint8_t uiNzc = 0;566 uint8_t uiNzc = 0;
567 for (j = 0; uiNzc == 0 && j < 4; j++) {567 for (j = 0; uiNzc == 0 && j < 4; j++) {
568 uiNzc |= pCurDqLayer->pNzc[iMbXy][* (pB8x8Idx + j)];568 uiNzc |= pCurDqLayer->pNzc[iMbXy][* (pB8x8Idx + j)];
569 }569 }
570 for (j = 0; j < 2; j++) {570 for (j = 0; j < 2; j++) {
571 if (uiNzc | pCurDqLayer->pNzc[iNeighMb][*pBnIdx]) {571 if (uiNzc | pCurDqLayer->pNzc[iNeighMb][*pBnIdx]) {
572 pBS[j + (i << 1)] = 2;572 pBS[j + (i << 1)] = 2;
573 } else {573 } else {
574 pBS[j + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[LIST_0], pCurDqLayer->pMv[LIST_0], iMbXy, iNeighMb, *pB8x8Idx,574 pBS[j + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[LIST_0], pCurDqLayer->pMv[LIST_0], iMbXy, iNeighMb, *pB8x8Idx,
575 *pBnIdx);575 *pBnIdx);
576 }576 }
577 pBnIdx++;577 pBnIdx++;
578 }578 }
579 pB8x8Idx += 4;579 pB8x8Idx += 4;
580 }580 }
581 } else if (pCurDqLayer->pTransformSize8x8Flag[iNeighMb]) {581 } else if (pCurDqLayer->pTransformSize8x8Flag[iNeighMb]) {
582 for (i = 0; i < 2; i++) {582 for (i = 0; i < 2; i++) {
583 uint8_t uiNzc = 0;583 uint8_t uiNzc = 0;
584 for (j = 0; uiNzc == 0 && j < 4; j++) {584 for (j = 0; uiNzc == 0 && j < 4; j++) {
585 uiNzc |= pCurDqLayer->pNzc[iNeighMb][* (pBn8x8Idx + j)];585 uiNzc |= pCurDqLayer->pNzc[iNeighMb][* (pBn8x8Idx + j)];
586 }586 }
587 for (j = 0; j < 2; j++) {587 for (j = 0; j < 2; j++) {
588 if (uiNzc | pCurDqLayer->pNzc[iMbXy][*pBIdx]) {588 if (uiNzc | pCurDqLayer->pNzc[iMbXy][*pBIdx]) {
589 pBS[j + (i << 1)] = 2;589 pBS[j + (i << 1)] = 2;
590 } else {590 } else {
591 pBS[j + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[LIST_0], pCurDqLayer->pMv[LIST_0], iMbXy, iNeighMb, *pBIdx,591 pBS[j + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[LIST_0], pCurDqLayer->pMv[LIST_0], iMbXy, iNeighMb, *pBIdx,
592 *pBn8x8Idx);592 *pBn8x8Idx);
593 }593 }
594 pBIdx++;594 pBIdx++;
595 }595 }
596 pBn8x8Idx += 4;596 pBn8x8Idx += 4;
597 }597 }
598 } else {598 } else {
599 // only 4x4 transform599 // only 4x4 transform
600 for (i = 0; i < 4; i++) {600 for (i = 0; i < 4; i++) {
601 if (pCurDqLayer->pNzc[iMbXy][*pBIdx] | pCurDqLayer->pNzc[iNeighMb][*pBnIdx]) {601 if (pCurDqLayer->pNzc[iMbXy][*pBIdx] | pCurDqLayer->pNzc[iNeighMb][*pBnIdx]) {
602 pBS[i] = 2;602 pBS[i] = 2;
603 } else {603 } else {
604 pBS[i] = MB_BS_MV (pCurDqLayer->pRefIndex[LIST_0], pCurDqLayer->pMv[LIST_0], iMbXy, iNeighMb, *pBIdx,604 pBS[i] = MB_BS_MV (pCurDqLayer->pRefIndex[LIST_0], pCurDqLayer->pMv[LIST_0], iMbXy, iNeighMb, *pBIdx,
605 *pBnIdx);605 *pBnIdx);
606 }606 }
607 pBIdx++;607 pBIdx++;
608 pBnIdx++;608 pBnIdx++;
609 }609 }
610 }610 }
611 611
612 return uiBSx4;612 return uiBSx4;
613}613}
614uint32_t DeblockingBSliceBsMarginalMBAvcbase (PDqLayer pCurDqLayer, int32_t iEdge, int32_t iNeighMb, int32_t iMbXy) {614uint32_t DeblockingBSliceBsMarginalMBAvcbase (PDqLayer pCurDqLayer, int32_t iEdge, int32_t iNeighMb, int32_t iMbXy) {
615 int32_t i, j;615 int32_t i, j;
616 uint32_t uiBSx4;616 uint32_t uiBSx4;
617 uint8_t* pBS = (uint8_t*) (&uiBSx4);617 uint8_t* pBS = (uint8_t*) (&uiBSx4);
618 const uint8_t* pBIdx = &g_kuiTableBIdx[iEdge][0];618 const uint8_t* pBIdx = &g_kuiTableBIdx[iEdge][0];
619 const uint8_t* pBnIdx = &g_kuiTableBIdx[iEdge][4];619 const uint8_t* pBnIdx = &g_kuiTableBIdx[iEdge][4];
620 const uint8_t* pB8x8Idx = &g_kuiTableB8x8Idx[iEdge][0];620 const uint8_t* pB8x8Idx = &g_kuiTableB8x8Idx[iEdge][0];
621 const uint8_t* pBn8x8Idx = &g_kuiTableB8x8Idx[iEdge][8];621 const uint8_t* pBn8x8Idx = &g_kuiTableB8x8Idx[iEdge][8];
622 622
623 if (pCurDqLayer->pTransformSize8x8Flag[iMbXy] && pCurDqLayer->pTransformSize8x8Flag[iNeighMb]) {623 if (pCurDqLayer->pTransformSize8x8Flag[iMbXy] && pCurDqLayer->pTransformSize8x8Flag[iNeighMb]) {
624 for (i = 0; i < 2; i++) {624 for (i = 0; i < 2; i++) {
625 uint8_t uiNzc = 0;625 uint8_t uiNzc = 0;
626 for (j = 0; uiNzc == 0 && j < 4; j++) {626 for (j = 0; uiNzc == 0 && j < 4; j++) {
627 uiNzc |= (pCurDqLayer->pNzc[iMbXy][* (pB8x8Idx + j)] | pCurDqLayer->pNzc[iNeighMb][* (pBn8x8Idx + j)]);627 uiNzc |= (pCurDqLayer->pNzc[iMbXy][* (pB8x8Idx + j)] | pCurDqLayer->pNzc[iNeighMb][* (pBn8x8Idx + j)]);
628 }628 }
629 if (uiNzc) {629 if (uiNzc) {
630 pBS[i << 1] = pBS[1 + (i << 1)] = 2;630 pBS[i << 1] = pBS[1 + (i << 1)] = 2;
631 } else {631 } else {
632 pBS[i << 1] = pBS[1 + (i << 1)] = 1;632 pBS[i << 1] = pBS[1 + (i << 1)] = 1;
633 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {633 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
634 if (pCurDqLayer->pRefIndex[listIdx][iMbXy][*pB8x8Idx] > REF_NOT_IN_LIST634 if (pCurDqLayer->pRefIndex[listIdx][iMbXy][*pB8x8Idx] > REF_NOT_IN_LIST
635 && pCurDqLayer->pRefIndex[listIdx][iMbXy][*pBn8x8Idx] > REF_NOT_IN_LIST) {635 && pCurDqLayer->pRefIndex[listIdx][iMbXy][*pBn8x8Idx] > REF_NOT_IN_LIST) {
636 pBS[i << 1] = pBS[1 + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[listIdx], pCurDqLayer->pMv[listIdx], iMbXy, iNeighMb,636 pBS[i << 1] = pBS[1 + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[listIdx], pCurDqLayer->pMv[listIdx], iMbXy, iNeighMb,
637 *pB8x8Idx, *pBn8x8Idx);637 *pB8x8Idx, *pBn8x8Idx);
638 break;638 break;
639 }639 }
640 }640 }
641 }641 }
642 pB8x8Idx += 4;642 pB8x8Idx += 4;
643 pBn8x8Idx += 4;643 pBn8x8Idx += 4;
644 }644 }
645 } else if (pCurDqLayer->pTransformSize8x8Flag[iMbXy]) {645 } else if (pCurDqLayer->pTransformSize8x8Flag[iMbXy]) {
646 for (i = 0; i < 2; i++) {646 for (i = 0; i < 2; i++) {
647 uint8_t uiNzc = 0;647 uint8_t uiNzc = 0;
648 for (j = 0; uiNzc == 0 && j < 4; j++) {648 for (j = 0; uiNzc == 0 && j < 4; j++) {
649 uiNzc |= pCurDqLayer->pNzc[iMbXy][* (pB8x8Idx + j)];649 uiNzc |= pCurDqLayer->pNzc[iMbXy][* (pB8x8Idx + j)];
650 }650 }
651 for (j = 0; j < 2; j++) {651 for (j = 0; j < 2; j++) {
652 if (uiNzc | pCurDqLayer->pNzc[iNeighMb][*pBnIdx]) {652 if (uiNzc | pCurDqLayer->pNzc[iNeighMb][*pBnIdx]) {
653 pBS[j + (i << 1)] = 2;653 pBS[j + (i << 1)] = 2;
654 } else {654 } else {
655 pBS[j + (i << 1)] = 1;655 pBS[j + (i << 1)] = 1;
656 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {656 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
657 if (pCurDqLayer->pRefIndex[listIdx][iMbXy][*pB8x8Idx] > REF_NOT_IN_LIST657 if (pCurDqLayer->pRefIndex[listIdx][iMbXy][*pB8x8Idx] > REF_NOT_IN_LIST
658 && pCurDqLayer->pRefIndex[listIdx][iMbXy][*pBnIdx] > REF_NOT_IN_LIST) {658 && pCurDqLayer->pRefIndex[listIdx][iMbXy][*pBnIdx] > REF_NOT_IN_LIST) {
659 pBS[j + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[listIdx], pCurDqLayer->pMv[listIdx], iMbXy, iNeighMb, *pB8x8Idx,659 pBS[j + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[listIdx], pCurDqLayer->pMv[listIdx], iMbXy, iNeighMb, *pB8x8Idx,
660 *pBnIdx);660 *pBnIdx);
661 break;661 break;
662 }662 }
663 }663 }
664 }664 }
665 pBnIdx++;665 pBnIdx++;
666 }666 }
667 pB8x8Idx += 4;667 pB8x8Idx += 4;
668 }668 }
669 } else if (pCurDqLayer->pTransformSize8x8Flag[iNeighMb]) {669 } else if (pCurDqLayer->pTransformSize8x8Flag[iNeighMb]) {
670 for (i = 0; i < 2; i++) {670 for (i = 0; i < 2; i++) {
671 uint8_t uiNzc = 0;671 uint8_t uiNzc = 0;
672 for (j = 0; uiNzc == 0 && j < 4; j++) {672 for (j = 0; uiNzc == 0 && j < 4; j++) {
673 uiNzc |= pCurDqLayer->pNzc[iNeighMb][* (pBn8x8Idx + j)];673 uiNzc |= pCurDqLayer->pNzc[iNeighMb][* (pBn8x8Idx + j)];
674 }674 }
675 for (j = 0; j < 2; j++) {675 for (j = 0; j < 2; j++) {
676 if (uiNzc | pCurDqLayer->pNzc[iMbXy][*pBIdx]) {676 if (uiNzc | pCurDqLayer->pNzc[iMbXy][*pBIdx]) {
677 pBS[j + (i << 1)] = 2;677 pBS[j + (i << 1)] = 2;
678 } else {678 } else {
679 pBS[j + (i << 1)] = 1;679 pBS[j + (i << 1)] = 1;
680 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {680 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
681 if (pCurDqLayer->pRefIndex[listIdx][iMbXy][*pBIdx] > REF_NOT_IN_LIST681 if (pCurDqLayer->pRefIndex[listIdx][iMbXy][*pBIdx] > REF_NOT_IN_LIST
682 && pCurDqLayer->pRefIndex[listIdx][iMbXy][*pBn8x8Idx] > REF_NOT_IN_LIST) {682 && pCurDqLayer->pRefIndex[listIdx][iMbXy][*pBn8x8Idx] > REF_NOT_IN_LIST) {
683 pBS[j + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[listIdx], pCurDqLayer->pMv[listIdx], iMbXy, iNeighMb, *pBIdx,683 pBS[j + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[listIdx], pCurDqLayer->pMv[listIdx], iMbXy, iNeighMb, *pBIdx,
684 *pBn8x8Idx);684 *pBn8x8Idx);
685 break;685 break;
686 }686 }
687 }687 }
688 }688 }
689 pBIdx++;689 pBIdx++;
690 }690 }
691 pBn8x8Idx += 4;691 pBn8x8Idx += 4;
692 }692 }
693 } else {693 } else {
694 // only 4x4 transform694 // only 4x4 transform
695 for (i = 0; i < 4; i++) {695 for (i = 0; i < 4; i++) {
696 if (pCurDqLayer->pNzc[iMbXy][*pBIdx] | pCurDqLayer->pNzc[iNeighMb][*pBnIdx]) {696 if (pCurDqLayer->pNzc[iMbXy][*pBIdx] | pCurDqLayer->pNzc[iNeighMb][*pBnIdx]) {
697 pBS[i] = 2;697 pBS[i] = 2;
698 } else {698 } else {
699 pBS[i] = 1;699 pBS[i] = 1;
700 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {700 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
701 if (pCurDqLayer->pRefIndex[listIdx][iMbXy][*pBIdx] > REF_NOT_IN_LIST701 if (pCurDqLayer->pRefIndex[listIdx][iMbXy][*pBIdx] > REF_NOT_IN_LIST
702 && pCurDqLayer->pRefIndex[listIdx][iMbXy][*pBnIdx] > REF_NOT_IN_LIST) {702 && pCurDqLayer->pRefIndex[listIdx][iMbXy][*pBnIdx] > REF_NOT_IN_LIST) {
703 pBS[i] = MB_BS_MV (pCurDqLayer->pRefIndex[listIdx], pCurDqLayer->pMv[listIdx], iMbXy, iNeighMb, *pBIdx, *pBnIdx);703 pBS[i] = MB_BS_MV (pCurDqLayer->pRefIndex[listIdx], pCurDqLayer->pMv[listIdx], iMbXy, iNeighMb, *pBIdx, *pBnIdx);
704 break;704 break;
705 }705 }
706 }706 }
707 }707 }
708 pBIdx++;708 pBIdx++;
709 pBnIdx++;709 pBnIdx++;
710 }710 }
711 }711 }
712 712
713 return uiBSx4;713 return uiBSx4;
714}714}
715int32_t DeblockingAvailableNoInterlayer (PDqLayer pCurDqLayer, int32_t iFilterIdc) {715int32_t DeblockingAvailableNoInterlayer (PDqLayer pCurDqLayer, int32_t iFilterIdc) {
716 int32_t iMbY = pCurDqLayer->iMbY;716 int32_t iMbY = pCurDqLayer->iMbY;
717 int32_t iMbX = pCurDqLayer->iMbX;717 int32_t iMbX = pCurDqLayer->iMbX;
718 int32_t iMbXy = pCurDqLayer->iMbXyIndex;718 int32_t iMbXy = pCurDqLayer->iMbXyIndex;
719 bool bLeftFlag = false;719 bool bLeftFlag = false;
720 bool bTopFlag = false;720 bool bTopFlag = false;
721 721
722 if (2 == iFilterIdc) {722 if (2 == iFilterIdc) {
723 bLeftFlag = (iMbX > 0) && (pCurDqLayer->pSliceIdc[iMbXy] == pCurDqLayer->pSliceIdc[iMbXy - 1]);723 bLeftFlag = (iMbX > 0) && (pCurDqLayer->pSliceIdc[iMbXy] == pCurDqLayer->pSliceIdc[iMbXy - 1]);
724 bTopFlag = (iMbY > 0) && (pCurDqLayer->pSliceIdc[iMbXy] == pCurDqLayer->pSliceIdc[iMbXy - pCurDqLayer->iMbWidth]);724 bTopFlag = (iMbY > 0) && (pCurDqLayer->pSliceIdc[iMbXy] == pCurDqLayer->pSliceIdc[iMbXy - pCurDqLayer->iMbWidth]);
725 } else { //if ( 0 == iFilterIdc )725 } else { //if ( 0 == iFilterIdc )
726 bLeftFlag = (iMbX > 0);726 bLeftFlag = (iMbX > 0);
727 bTopFlag = (iMbY > 0);727 bTopFlag = (iMbY > 0);
728 }728 }
729 return (bLeftFlag << LEFT_FLAG_BIT) | (bTopFlag << TOP_FLAG_BIT);729 return (bLeftFlag << LEFT_FLAG_BIT) | (bTopFlag << TOP_FLAG_BIT);
730}730}
731 731
732void FilteringEdgeLumaH (SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS) {732void FilteringEdgeLumaH (SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS) {
733 int32_t iIndexA;733 int32_t iIndexA;
734 int32_t iAlpha;734 int32_t iAlpha;
735 int32_t iBeta;735 int32_t iBeta;
736 ENFORCE_STACK_ALIGN_1D (int8_t, tc, 4, 16);736 ENFORCE_STACK_ALIGN_1D (int8_t, tc, 4, 16);
737 737
738 GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,738 GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,
739 iBeta);739 iBeta);
740 740
741 if (iAlpha | iBeta) {741 if (iAlpha | iBeta) {
742 TC0_TBL_LOOKUP (tc, iIndexA, pBS, 0);742 TC0_TBL_LOOKUP (tc, iIndexA, pBS, 0);
743 pFilter->pLoopf->pfLumaDeblockingLT4Ver (pPix, iStride, iAlpha, iBeta, tc);743 pFilter->pLoopf->pfLumaDeblockingLT4Ver (pPix, iStride, iAlpha, iBeta, tc);
744 }744 }
745 return;745 return;
746}746}
747 747
748 748
749void FilteringEdgeLumaV (SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS) {749void FilteringEdgeLumaV (SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS) {
750 int32_t iIndexA;750 int32_t iIndexA;
751 int32_t iAlpha;751 int32_t iAlpha;
752 int32_t iBeta;752 int32_t iBeta;
753 ENFORCE_STACK_ALIGN_1D (int8_t, tc, 4, 16);753 ENFORCE_STACK_ALIGN_1D (int8_t, tc, 4, 16);
754 754
755 GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,755 GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,
756 iBeta);756 iBeta);
757 757
758 if (iAlpha | iBeta) {758 if (iAlpha | iBeta) {
759 TC0_TBL_LOOKUP (tc, iIndexA, pBS, 0);759 TC0_TBL_LOOKUP (tc, iIndexA, pBS, 0);
760 pFilter->pLoopf->pfLumaDeblockingLT4Hor (pPix, iStride, iAlpha, iBeta, tc);760 pFilter->pLoopf->pfLumaDeblockingLT4Hor (pPix, iStride, iAlpha, iBeta, tc);
761 }761 }
762 return;762 return;
763}763}
764 764
765 765
766void FilteringEdgeLumaIntraH (SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS) {766void FilteringEdgeLumaIntraH (SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS) {
767 int32_t iIndexA;767 int32_t iIndexA;
768 int32_t iAlpha;768 int32_t iAlpha;
769 int32_t iBeta;769 int32_t iBeta;
770 770
771 GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,771 GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,
772 iBeta);772 iBeta);
773 773
774 if (iAlpha | iBeta) {774 if (iAlpha | iBeta) {
775 pFilter->pLoopf->pfLumaDeblockingEQ4Ver (pPix, iStride, iAlpha, iBeta);775 pFilter->pLoopf->pfLumaDeblockingEQ4Ver (pPix, iStride, iAlpha, iBeta);
776 }776 }
777 return;777 return;
778}778}
779 779
780void FilteringEdgeLumaIntraV (SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS) {780void FilteringEdgeLumaIntraV (SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS) {
781 int32_t iIndexA;781 int32_t iIndexA;
782 int32_t iAlpha;782 int32_t iAlpha;
783 int32_t iBeta;783 int32_t iBeta;
784 784
785 GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,785 GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,
786 iBeta);786 iBeta);
787 787
788 if (iAlpha | iBeta) {788 if (iAlpha | iBeta) {
789 pFilter->pLoopf->pfLumaDeblockingEQ4Hor (pPix, iStride, iAlpha, iBeta);789 pFilter->pLoopf->pfLumaDeblockingEQ4Hor (pPix, iStride, iAlpha, iBeta);
790 }790 }
791 return;791 return;
792}792}
793void FilteringEdgeChromaH (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride,793void FilteringEdgeChromaH (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride,
794 uint8_t* pBS) {794 uint8_t* pBS) {
795 int32_t iIndexA;795 int32_t iIndexA;
796 int32_t iAlpha;796 int32_t iAlpha;
797 int32_t iBeta;797 int32_t iBeta;
798 ENFORCE_STACK_ALIGN_1D (int8_t, tc, 4, 16);798 ENFORCE_STACK_ALIGN_1D (int8_t, tc, 4, 16);
799 if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) {799 if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) {
800 800
801 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,801 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,
802 iBeta);802 iBeta);
803 803
804 if (iAlpha | iBeta) {804 if (iAlpha | iBeta) {
805 TC0_TBL_LOOKUP (tc, iIndexA, pBS, 1);805 TC0_TBL_LOOKUP (tc, iIndexA, pBS, 1);
806 pFilter->pLoopf->pfChromaDeblockingLT4Ver (pPixCb, pPixCr, iStride, iAlpha, iBeta, tc);806 pFilter->pLoopf->pfChromaDeblockingLT4Ver (pPixCb, pPixCr, iStride, iAlpha, iBeta, tc);
807 }807 }
808 } else {808 } else {
809 809
810 for (int i = 0; i < 2; i++) {810 for (int i = 0; i < 2; i++) {
811 811
812 812
813 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,813 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,
814 iBeta);814 iBeta);
815 815
816 if (iAlpha | iBeta) {816 if (iAlpha | iBeta) {
817 uint8_t* pPixCbCr = (i == 0) ? pPixCb : pPixCr;817 uint8_t* pPixCbCr = (i == 0) ? pPixCb : pPixCr;
818 TC0_TBL_LOOKUP (tc, iIndexA, pBS, 1);818 TC0_TBL_LOOKUP (tc, iIndexA, pBS, 1);
819 pFilter->pLoopf->pfChromaDeblockingLT4Ver2 (pPixCbCr, iStride, iAlpha, iBeta, tc);819 pFilter->pLoopf->pfChromaDeblockingLT4Ver2 (pPixCbCr, iStride, iAlpha, iBeta, tc);
820 }820 }
821 821
822 822
823 823
824 }824 }
825 825
826 }826 }
827 return;827 return;
828}828}
829void FilteringEdgeChromaV (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride,829void FilteringEdgeChromaV (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride,
830 uint8_t* pBS) {830 uint8_t* pBS) {
831 int32_t iIndexA;831 int32_t iIndexA;
832 int32_t iAlpha;832 int32_t iAlpha;
833 int32_t iBeta;833 int32_t iBeta;
834 ENFORCE_STACK_ALIGN_1D (int8_t, tc, 4, 16);834 ENFORCE_STACK_ALIGN_1D (int8_t, tc, 4, 16);
835 if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) {835 if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) {
836 836
837 837
838 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,838 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,
839 iBeta);839 iBeta);
840 840
841 if (iAlpha | iBeta) {841 if (iAlpha | iBeta) {
842 TC0_TBL_LOOKUP (tc, iIndexA, pBS, 1);842 TC0_TBL_LOOKUP (tc, iIndexA, pBS, 1);
843 pFilter->pLoopf->pfChromaDeblockingLT4Hor (pPixCb, pPixCr, iStride, iAlpha, iBeta, tc);843 pFilter->pLoopf->pfChromaDeblockingLT4Hor (pPixCb, pPixCr, iStride, iAlpha, iBeta, tc);
844 }844 }
845 845
846 846
847 } else {847 } else {
848 848
849 for (int i = 0; i < 2; i++) {849 for (int i = 0; i < 2; i++) {
850 850
851 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,851 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,
852 iBeta);852 iBeta);
853 853
854 if (iAlpha | iBeta) {854 if (iAlpha | iBeta) {
855 uint8_t* pPixCbCr = (i == 0) ? pPixCb : pPixCr;855 uint8_t* pPixCbCr = (i == 0) ? pPixCb : pPixCr;
856 TC0_TBL_LOOKUP (tc, iIndexA, pBS, 1);856 TC0_TBL_LOOKUP (tc, iIndexA, pBS, 1);
857 pFilter->pLoopf->pfChromaDeblockingLT4Hor2 (pPixCbCr, iStride, iAlpha, iBeta, tc);857 pFilter->pLoopf->pfChromaDeblockingLT4Hor2 (pPixCbCr, iStride, iAlpha, iBeta, tc);
858 }858 }
859 859
860 860
861 }861 }
862 }862 }
863 return;863 return;
864}864}
865 865
866void FilteringEdgeChromaIntraH (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride,866void FilteringEdgeChromaIntraH (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride,
867 uint8_t* pBS) {867 uint8_t* pBS) {
868 int32_t iIndexA;868 int32_t iIndexA;
869 int32_t iAlpha;869 int32_t iAlpha;
870 int32_t iBeta;870 int32_t iBeta;
871 if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) {871 if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) {
872 872
873 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,873 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,
874 iBeta);874 iBeta);
875 875
876 if (iAlpha | iBeta) {876 if (iAlpha | iBeta) {
877 pFilter->pLoopf->pfChromaDeblockingEQ4Ver (pPixCb, pPixCr, iStride, iAlpha, iBeta);877 pFilter->pLoopf->pfChromaDeblockingEQ4Ver (pPixCb, pPixCr, iStride, iAlpha, iBeta);
878 }878 }
879 } else {879 } else {
880 880
881 for (int i = 0; i < 2; i++) {881 for (int i = 0; i < 2; i++) {
882 882
883 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,883 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,
884 iBeta);884 iBeta);
885 885
886 if (iAlpha | iBeta) {886 if (iAlpha | iBeta) {
887 uint8_t* pPixCbCr = (i == 0) ? pPixCb : pPixCr;887 uint8_t* pPixCbCr = (i == 0) ? pPixCb : pPixCr;
888 pFilter->pLoopf->pfChromaDeblockingEQ4Ver2 (pPixCbCr, iStride, iAlpha, iBeta);888 pFilter->pLoopf->pfChromaDeblockingEQ4Ver2 (pPixCbCr, iStride, iAlpha, iBeta);
889 }889 }
890 890
891 }891 }
892 }892 }
893 return;893 return;
894}894}
895 895
896void FilteringEdgeChromaIntraV (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride,896void FilteringEdgeChromaIntraV (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride,
897 uint8_t* pBS) {897 uint8_t* pBS) {
898 int32_t iIndexA;898 int32_t iIndexA;
899 int32_t iAlpha;899 int32_t iAlpha;
900 int32_t iBeta;900 int32_t iBeta;
901 if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) { // QP of cb and cr are the same901 if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) { // QP of cb and cr are the same
902 902
903 903
904 904
905 905
906 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,906 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,
907 iBeta);907 iBeta);
908 if (iAlpha | iBeta) {908 if (iAlpha | iBeta) {
909 pFilter->pLoopf->pfChromaDeblockingEQ4Hor (pPixCb, pPixCr, iStride, iAlpha, iBeta);909 pFilter->pLoopf->pfChromaDeblockingEQ4Hor (pPixCb, pPixCr, iStride, iAlpha, iBeta);
910 }910 }
911 } else {911 } else {
912 912
913 for (int i = 0; i < 2; i++) {913 for (int i = 0; i < 2; i++) {
914 914
915 915
916 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,916 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,
917 iBeta);917 iBeta);
918 if (iAlpha | iBeta) {918 if (iAlpha | iBeta) {
919 uint8_t* pPixCbCr = (i == 0) ? pPixCb : pPixCr;919 uint8_t* pPixCbCr = (i == 0) ? pPixCb : pPixCr;
920 pFilter->pLoopf->pfChromaDeblockingEQ4Hor2 (pPixCbCr, iStride, iAlpha, iBeta);920 pFilter->pLoopf->pfChromaDeblockingEQ4Hor2 (pPixCbCr, iStride, iAlpha, iBeta);
921 }921 }
922 }922 }
923 923
924 }924 }
925 return;925 return;
926}926}
927 927
928 928
929void DeblockingInterMb (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, uint8_t nBS[2][4][4],929void DeblockingInterMb (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, uint8_t nBS[2][4][4],
930 int32_t iBoundryFlag) {930 int32_t iBoundryFlag) {
931 int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex;931 int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex;
932 int32_t iMbX = pCurDqLayer->iMbX;932 int32_t iMbX = pCurDqLayer->iMbX;
933 int32_t iMbY = pCurDqLayer->iMbY;933 int32_t iMbY = pCurDqLayer->iMbY;
934 934
935 int32_t iCurLumaQp = pCurDqLayer->pLumaQp[iMbXyIndex];935 int32_t iCurLumaQp = pCurDqLayer->pLumaQp[iMbXyIndex];
936 //int32_t* iCurChromaQp = pCurDqLayer->pChromaQp[iMbXyIndex];936 //int32_t* iCurChromaQp = pCurDqLayer->pChromaQp[iMbXyIndex];
937 int8_t* pCurChromaQp = pCurDqLayer->pChromaQp[iMbXyIndex];937 int8_t* pCurChromaQp = pCurDqLayer->pChromaQp[iMbXyIndex];
938 int32_t iLineSize = pFilter->iCsStride[0];938 int32_t iLineSize = pFilter->iCsStride[0];
939 int32_t iLineSizeUV = pFilter->iCsStride[1];939 int32_t iLineSizeUV = pFilter->iCsStride[1];
940 940
941 uint8_t* pDestY, * pDestCb, * pDestCr;941 uint8_t* pDestY, * pDestCb, * pDestCr;
942 pDestY = pFilter->pCsData[0] + ((iMbY * iLineSize + iMbX) << 4);942 pDestY = pFilter->pCsData[0] + ((iMbY * iLineSize + iMbX) << 4);
943 pDestCb = pFilter->pCsData[1] + ((iMbY * iLineSizeUV + iMbX) << 3);943 pDestCb = pFilter->pCsData[1] + ((iMbY * iLineSizeUV + iMbX) << 3);
944 pDestCr = pFilter->pCsData[2] + ((iMbY * iLineSizeUV + iMbX) << 3);944 pDestCr = pFilter->pCsData[2] + ((iMbY * iLineSizeUV + iMbX) << 3);
945 945
946//Vertical margrin946//Vertical margrin
947 if (iBoundryFlag & LEFT_FLAG_MASK) {947 if (iBoundryFlag & LEFT_FLAG_MASK) {
948 int32_t iLeftXyIndex = iMbXyIndex - 1;948 int32_t iLeftXyIndex = iMbXyIndex - 1;
949 pFilter->iLumaQP = (iCurLumaQp + pCurDqLayer->pLumaQp[iLeftXyIndex] + 1) >> 1;949 pFilter->iLumaQP = (iCurLumaQp + pCurDqLayer->pLumaQp[iLeftXyIndex] + 1) >> 1;
950 for (int i = 0; i < 2; i++) {950 for (int i = 0; i < 2; i++) {
951 pFilter->iChromaQP[i] = (pCurChromaQp[i] + pCurDqLayer->pChromaQp[iLeftXyIndex][i] + 1) >> 1;951 pFilter->iChromaQP[i] = (pCurChromaQp[i] + pCurDqLayer->pChromaQp[iLeftXyIndex][i] + 1) >> 1;
952 }952 }
953 if (nBS[0][0][0] == 0x04) {953 if (nBS[0][0][0] == 0x04) {
954 FilteringEdgeLumaIntraV (pFilter, pDestY, iLineSize, NULL);954 FilteringEdgeLumaIntraV (pFilter, pDestY, iLineSize, NULL);
955 FilteringEdgeChromaIntraV (pFilter, pDestCb, pDestCr, iLineSizeUV, NULL);955 FilteringEdgeChromaIntraV (pFilter, pDestCb, pDestCr, iLineSizeUV, NULL);
956 } else {956 } else {
957 if (* (uint32_t*)nBS[0][0] != 0) {957 if (* (uint32_t*)nBS[0][0] != 0) {
958 FilteringEdgeLumaV (pFilter, pDestY, iLineSize, nBS[0][0]);958 FilteringEdgeLumaV (pFilter, pDestY, iLineSize, nBS[0][0]);
959 FilteringEdgeChromaV (pFilter, pDestCb, pDestCr, iLineSizeUV, nBS[0][0]);959 FilteringEdgeChromaV (pFilter, pDestCb, pDestCr, iLineSizeUV, nBS[0][0]);
960 }960 }
961 }961 }
962 }962 }
963 963
964 pFilter->iLumaQP = iCurLumaQp;964 pFilter->iLumaQP = iCurLumaQp;
965 pFilter->iChromaQP[0] = pCurChromaQp[0];965 pFilter->iChromaQP[0] = pCurChromaQp[0];
966 pFilter->iChromaQP[1] = pCurChromaQp[1];966 pFilter->iChromaQP[1] = pCurChromaQp[1];
967 967
968 if (* (uint32_t*)nBS[0][1] != 0 && !pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) {968 if (* (uint32_t*)nBS[0][1] != 0 && !pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) {
969 FilteringEdgeLumaV (pFilter, &pDestY[1 << 2], iLineSize, nBS[0][1]);969 FilteringEdgeLumaV (pFilter, &pDestY[1 << 2], iLineSize, nBS[0][1]);
970 }970 }
971 971
972 if (* (uint32_t*)nBS[0][2] != 0) {972 if (* (uint32_t*)nBS[0][2] != 0) {
973 FilteringEdgeLumaV (pFilter, &pDestY[2 << 2], iLineSize, nBS[0][2]);973 FilteringEdgeLumaV (pFilter, &pDestY[2 << 2], iLineSize, nBS[0][2]);
974 FilteringEdgeChromaV (pFilter, &pDestCb[2 << 1], &pDestCr[2 << 1], iLineSizeUV, nBS[0][2]);974 FilteringEdgeChromaV (pFilter, &pDestCb[2 << 1], &pDestCr[2 << 1], iLineSizeUV, nBS[0][2]);
975 }975 }
976 976
977 if (* (uint32_t*)nBS[0][3] != 0 && !pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) {977 if (* (uint32_t*)nBS[0][3] != 0 && !pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) {
978 FilteringEdgeLumaV (pFilter, &pDestY[3 << 2], iLineSize, nBS[0][3]);978 FilteringEdgeLumaV (pFilter, &pDestY[3 << 2], iLineSize, nBS[0][3]);
979 }979 }
980 980
981 if (iBoundryFlag & TOP_FLAG_MASK) {981 if (iBoundryFlag & TOP_FLAG_MASK) {
982 int32_t iTopXyIndex = iMbXyIndex - pCurDqLayer->iMbWidth;982 int32_t iTopXyIndex = iMbXyIndex - pCurDqLayer->iMbWidth;
983 pFilter->iLumaQP = (iCurLumaQp + pCurDqLayer->pLumaQp[iTopXyIndex] + 1) >> 1;983 pFilter->iLumaQP = (iCurLumaQp + pCurDqLayer->pLumaQp[iTopXyIndex] + 1) >> 1;
984 for (int i = 0; i < 2; i++) {984 for (int i = 0; i < 2; i++) {
985 pFilter->iChromaQP[i] = (pCurChromaQp[i] + pCurDqLayer->pChromaQp[iTopXyIndex][i] + 1) >> 1;985 pFilter->iChromaQP[i] = (pCurChromaQp[i] + pCurDqLayer->pChromaQp[iTopXyIndex][i] + 1) >> 1;
986 }986 }
987 987
988 if (nBS[1][0][0] == 0x04) {988 if (nBS[1][0][0] == 0x04) {
989 FilteringEdgeLumaIntraH (pFilter, pDestY, iLineSize, NULL);989 FilteringEdgeLumaIntraH (pFilter, pDestY, iLineSize, NULL);
990 FilteringEdgeChromaIntraH (pFilter, pDestCb, pDestCr, iLineSizeUV, NULL);990 FilteringEdgeChromaIntraH (pFilter, pDestCb, pDestCr, iLineSizeUV, NULL);
991 } else {991 } else {
992 if (* (uint32_t*)nBS[1][0] != 0) {992 if (* (uint32_t*)nBS[1][0] != 0) {
993 FilteringEdgeLumaH (pFilter, pDestY, iLineSize, nBS[1][0]);993 FilteringEdgeLumaH (pFilter, pDestY, iLineSize, nBS[1][0]);
994 FilteringEdgeChromaH (pFilter, pDestCb, pDestCr, iLineSizeUV, nBS[1][0]);994 FilteringEdgeChromaH (pFilter, pDestCb, pDestCr, iLineSizeUV, nBS[1][0]);
995 }995 }
996 }996 }
997 }997 }
998 998
999 pFilter->iLumaQP = iCurLumaQp;999 pFilter->iLumaQP = iCurLumaQp;
1000 pFilter->iChromaQP[0] = pCurChromaQp[0];1000 pFilter->iChromaQP[0] = pCurChromaQp[0];
1001 pFilter->iChromaQP[1] = pCurChromaQp[1];1001 pFilter->iChromaQP[1] = pCurChromaQp[1];
1002 1002
1003 if (* (uint32_t*)nBS[1][1] != 0 && !pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) {1003 if (* (uint32_t*)nBS[1][1] != 0 && !pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) {
1004 FilteringEdgeLumaH (pFilter, &pDestY[ (1 << 2)*iLineSize], iLineSize, nBS[1][1]);1004 FilteringEdgeLumaH (pFilter, &pDestY[ (1 << 2)*iLineSize], iLineSize, nBS[1][1]);
1005 }1005 }
1006 1006
1007 if (* (uint32_t*)nBS[1][2] != 0) {1007 if (* (uint32_t*)nBS[1][2] != 0) {
1008 FilteringEdgeLumaH (pFilter, &pDestY[ (2 << 2)*iLineSize], iLineSize, nBS[1][2]);1008 FilteringEdgeLumaH (pFilter, &pDestY[ (2 << 2)*iLineSize], iLineSize, nBS[1][2]);
1009 FilteringEdgeChromaH (pFilter, &pDestCb[ (2 << 1)*iLineSizeUV], &pDestCr[ (2 << 1)*iLineSizeUV], iLineSizeUV,1009 FilteringEdgeChromaH (pFilter, &pDestCb[ (2 << 1)*iLineSizeUV], &pDestCr[ (2 << 1)*iLineSizeUV], iLineSizeUV,
1010 nBS[1][2]);1010 nBS[1][2]);
1011 }1011 }
1012 1012
1013 if (* (uint32_t*)nBS[1][3] != 0 && !pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) {1013 if (* (uint32_t*)nBS[1][3] != 0 && !pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) {
1014 FilteringEdgeLumaH (pFilter, &pDestY[ (3 << 2)*iLineSize], iLineSize, nBS[1][3]);1014 FilteringEdgeLumaH (pFilter, &pDestY[ (3 << 2)*iLineSize], iLineSize, nBS[1][3]);
1015 }1015 }
1016}1016}
1017 1017
1018void FilteringEdgeLumaHV (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag) {1018void FilteringEdgeLumaHV (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag) {
1019 int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex;1019 int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex;
1020 int32_t iMbX = pCurDqLayer->iMbX;1020 int32_t iMbX = pCurDqLayer->iMbX;
1021 int32_t iMbY = pCurDqLayer->iMbY;1021 int32_t iMbY = pCurDqLayer->iMbY;
1022 int32_t iMbWidth = pCurDqLayer->iMbWidth;1022 int32_t iMbWidth = pCurDqLayer->iMbWidth;
1023 int32_t iLineSize = pFilter->iCsStride[0];1023 int32_t iLineSize = pFilter->iCsStride[0];
1024 1024
1025 uint8_t* pDestY;1025 uint8_t* pDestY;
1026 int32_t iCurQp;1026 int32_t iCurQp;
1027 int32_t iIndexA, iAlpha, iBeta;1027 int32_t iIndexA, iAlpha, iBeta;
1028 1028
1029 ENFORCE_STACK_ALIGN_1D (int8_t, iTc, 4, 16);1029 ENFORCE_STACK_ALIGN_1D (int8_t, iTc, 4, 16);
1030 ENFORCE_STACK_ALIGN_1D (uint8_t, uiBSx4, 4, 4);1030 ENFORCE_STACK_ALIGN_1D (uint8_t, uiBSx4, 4, 4);
1031 1031
1032 pDestY = pFilter->pCsData[0] + ((iMbY * iLineSize + iMbX) << 4);1032 pDestY = pFilter->pCsData[0] + ((iMbY * iLineSize + iMbX) << 4);
1033 iCurQp = pCurDqLayer->pLumaQp[iMbXyIndex];1033 iCurQp = pCurDqLayer->pLumaQp[iMbXyIndex];
1034 1034
1035 * (uint32_t*)uiBSx4 = 0x03030303;1035 * (uint32_t*)uiBSx4 = 0x03030303;
1036 1036
1037 // luma v1037 // luma v
1038 if (iBoundryFlag & LEFT_FLAG_MASK) {1038 if (iBoundryFlag & LEFT_FLAG_MASK) {
1039 pFilter->iLumaQP = (iCurQp + pCurDqLayer->pLumaQp[iMbXyIndex - 1] + 1) >> 1;1039 pFilter->iLumaQP = (iCurQp + pCurDqLayer->pLumaQp[iMbXyIndex - 1] + 1) >> 1;
1040 FilteringEdgeLumaIntraV (pFilter, pDestY, iLineSize, NULL);1040 FilteringEdgeLumaIntraV (pFilter, pDestY, iLineSize, NULL);
1041 }1041 }
1042 1042
1043 pFilter->iLumaQP = iCurQp;1043 pFilter->iLumaQP = iCurQp;
1044 GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,1044 GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,
1045 iBeta);1045 iBeta);
1046 if (iAlpha | iBeta) {1046 if (iAlpha | iBeta) {
1047 TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 0);1047 TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 0);
1048 1048
1049 if (!pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) {1049 if (!pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) {
1050 pFilter->pLoopf->pfLumaDeblockingLT4Hor (&pDestY[1 << 2], iLineSize, iAlpha, iBeta, iTc);1050 pFilter->pLoopf->pfLumaDeblockingLT4Hor (&pDestY[1 << 2], iLineSize, iAlpha, iBeta, iTc);
1051 }1051 }
1052 1052
1053 pFilter->pLoopf->pfLumaDeblockingLT4Hor (&pDestY[2 << 2], iLineSize, iAlpha, iBeta, iTc);1053 pFilter->pLoopf->pfLumaDeblockingLT4Hor (&pDestY[2 << 2], iLineSize, iAlpha, iBeta, iTc);
1054 1054
1055 if (!pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) {1055 if (!pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) {
1056 pFilter->pLoopf->pfLumaDeblockingLT4Hor (&pDestY[3 << 2], iLineSize, iAlpha, iBeta, iTc);1056 pFilter->pLoopf->pfLumaDeblockingLT4Hor (&pDestY[3 << 2], iLineSize, iAlpha, iBeta, iTc);
1057 }1057 }
1058 }1058 }
1059 1059
1060 // luma h1060 // luma h
1061 if (iBoundryFlag & TOP_FLAG_MASK) {1061 if (iBoundryFlag & TOP_FLAG_MASK) {
1062 pFilter->iLumaQP = (iCurQp + pCurDqLayer->pLumaQp[iMbXyIndex - iMbWidth] + 1) >> 1;1062 pFilter->iLumaQP = (iCurQp + pCurDqLayer->pLumaQp[iMbXyIndex - iMbWidth] + 1) >> 1;
1063 FilteringEdgeLumaIntraH (pFilter, pDestY, iLineSize, NULL);1063 FilteringEdgeLumaIntraH (pFilter, pDestY, iLineSize, NULL);
1064 }1064 }
1065 1065
1066 pFilter->iLumaQP = iCurQp;1066 pFilter->iLumaQP = iCurQp;
1067 if (iAlpha | iBeta) {1067 if (iAlpha | iBeta) {
1068 if (!pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) {1068 if (!pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) {
1069 pFilter->pLoopf->pfLumaDeblockingLT4Ver (&pDestY[ (1 << 2)*iLineSize], iLineSize, iAlpha, iBeta, iTc);1069 pFilter->pLoopf->pfLumaDeblockingLT4Ver (&pDestY[ (1 << 2)*iLineSize], iLineSize, iAlpha, iBeta, iTc);
1070 }1070 }
1071 1071
1072 pFilter->pLoopf->pfLumaDeblockingLT4Ver (&pDestY[ (2 << 2)*iLineSize], iLineSize, iAlpha, iBeta, iTc);1072 pFilter->pLoopf->pfLumaDeblockingLT4Ver (&pDestY[ (2 << 2)*iLineSize], iLineSize, iAlpha, iBeta, iTc);
1073 1073
1074 if (!pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) {1074 if (!pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) {
1075 pFilter->pLoopf->pfLumaDeblockingLT4Ver (&pDestY[ (3 << 2)*iLineSize], iLineSize, iAlpha, iBeta, iTc);1075 pFilter->pLoopf->pfLumaDeblockingLT4Ver (&pDestY[ (3 << 2)*iLineSize], iLineSize, iAlpha, iBeta, iTc);
1076 }1076 }
1077 }1077 }
1078}1078}
1079void FilteringEdgeChromaHV (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag) {1079void FilteringEdgeChromaHV (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag) {
1080 int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex;1080 int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex;
1081 int32_t iMbX = pCurDqLayer->iMbX;1081 int32_t iMbX = pCurDqLayer->iMbX;
1082 int32_t iMbY = pCurDqLayer->iMbY;1082 int32_t iMbY = pCurDqLayer->iMbY;
1083 int32_t iMbWidth = pCurDqLayer->iMbWidth;1083 int32_t iMbWidth = pCurDqLayer->iMbWidth;
1084 int32_t iLineSize = pFilter->iCsStride[1];1084 int32_t iLineSize = pFilter->iCsStride[1];
1085 1085
1086 uint8_t* pDestCb;1086 uint8_t* pDestCb;
1087 uint8_t* pDestCr;1087 uint8_t* pDestCr;
1088 //int32_t iCurQp;1088 //int32_t iCurQp;
1089 int8_t* pCurQp;1089 int8_t* pCurQp;
1090 int32_t iIndexA, iAlpha, iBeta;1090 int32_t iIndexA, iAlpha, iBeta;
1091 1091
1092 ENFORCE_STACK_ALIGN_1D (int8_t, iTc, 4, 16);1092 ENFORCE_STACK_ALIGN_1D (int8_t, iTc, 4, 16);
1093 ENFORCE_STACK_ALIGN_1D (uint8_t, uiBSx4, 4, 4);1093 ENFORCE_STACK_ALIGN_1D (uint8_t, uiBSx4, 4, 4);
1094 1094
1095 pDestCb = pFilter->pCsData[1] + ((iMbY * iLineSize + iMbX) << 3);1095 pDestCb = pFilter->pCsData[1] + ((iMbY * iLineSize + iMbX) << 3);
1096 pDestCr = pFilter->pCsData[2] + ((iMbY * iLineSize + iMbX) << 3);1096 pDestCr = pFilter->pCsData[2] + ((iMbY * iLineSize + iMbX) << 3);
1097 pCurQp = pCurDqLayer->pChromaQp[iMbXyIndex];1097 pCurQp = pCurDqLayer->pChromaQp[iMbXyIndex];
1098 1098
1099 * (uint32_t*)uiBSx4 = 0x03030303;1099 * (uint32_t*)uiBSx4 = 0x03030303;
1100 1100
1101 1101
1102// chroma v1102// chroma v
1103 if (iBoundryFlag & LEFT_FLAG_MASK) {1103 if (iBoundryFlag & LEFT_FLAG_MASK) {
1104 1104
1105 for (int i = 0; i < 2; i++) {1105 for (int i = 0; i < 2; i++) {
1106 pFilter->iChromaQP[i] = (pCurQp[i] + pCurDqLayer->pChromaQp[iMbXyIndex - 1][i] + 1) >> 1;1106 pFilter->iChromaQP[i] = (pCurQp[i] + pCurDqLayer->pChromaQp[iMbXyIndex - 1][i] + 1) >> 1;
1107 1107
1108 }1108 }
1109 FilteringEdgeChromaIntraV (pFilter, pDestCb, pDestCr, iLineSize, NULL);1109 FilteringEdgeChromaIntraV (pFilter, pDestCb, pDestCr, iLineSize, NULL);
1110 }1110 }
1111 1111
1112 pFilter->iChromaQP[0] = pCurQp[0];1112 pFilter->iChromaQP[0] = pCurQp[0];
1113 pFilter->iChromaQP[1] = pCurQp[1];1113 pFilter->iChromaQP[1] = pCurQp[1];
1114 if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) {1114 if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) {
1115 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,1115 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,
1116 iBeta);1116 iBeta);
1117 if (iAlpha | iBeta) {1117 if (iAlpha | iBeta) {
1118 TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 1);1118 TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 1);
1119 pFilter->pLoopf->pfChromaDeblockingLT4Hor (&pDestCb[2 << 1], &pDestCr[2 << 1], iLineSize, iAlpha, iBeta, iTc);1119 pFilter->pLoopf->pfChromaDeblockingLT4Hor (&pDestCb[2 << 1], &pDestCr[2 << 1], iLineSize, iAlpha, iBeta, iTc);
1120 }1120 }
1121 } else {1121 } else {
1122 1122
1123 for (int i = 0; i < 2; i++) {1123 for (int i = 0; i < 2; i++) {
1124 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,1124 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,
1125 iBeta);1125 iBeta);
1126 if (iAlpha | iBeta) {1126 if (iAlpha | iBeta) {
1127 uint8_t* pDestCbCr = (i == 0) ? &pDestCb[2 << 1] : &pDestCr[2 << 1];1127 uint8_t* pDestCbCr = (i == 0) ? &pDestCb[2 << 1] : &pDestCr[2 << 1];
1128 TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 1);1128 TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 1);
1129 pFilter->pLoopf->pfChromaDeblockingLT4Hor2 (pDestCbCr, iLineSize, iAlpha, iBeta, iTc);1129 pFilter->pLoopf->pfChromaDeblockingLT4Hor2 (pDestCbCr, iLineSize, iAlpha, iBeta, iTc);
1130 }1130 }
1131 1131
1132 }1132 }
1133 }1133 }
1134 1134
1135 // chroma h1135 // chroma h
1136 1136
1137 if (iBoundryFlag & TOP_FLAG_MASK) {1137 if (iBoundryFlag & TOP_FLAG_MASK) {
1138 for (int i = 0; i < 2; i++) {1138 for (int i = 0; i < 2; i++) {
1139 pFilter->iChromaQP[i] = (pCurQp[i] + pCurDqLayer->pChromaQp[iMbXyIndex - iMbWidth][i] + 1) >> 1;1139 pFilter->iChromaQP[i] = (pCurQp[i] + pCurDqLayer->pChromaQp[iMbXyIndex - iMbWidth][i] + 1) >> 1;
1140 }1140 }
1141 FilteringEdgeChromaIntraH (pFilter, pDestCb, pDestCr, iLineSize, NULL);1141 FilteringEdgeChromaIntraH (pFilter, pDestCb, pDestCr, iLineSize, NULL);
1142 }1142 }
1143 1143
1144 pFilter->iChromaQP[0] = pCurQp[0];1144 pFilter->iChromaQP[0] = pCurQp[0];
1145 pFilter->iChromaQP[1] = pCurQp[1];1145 pFilter->iChromaQP[1] = pCurQp[1];
1146 1146
1147 if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) {1147 if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) {
1148 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,1148 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,
1149 iBeta);1149 iBeta);
1150 if (iAlpha | iBeta) {1150 if (iAlpha | iBeta) {
1151 TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 1);1151 TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 1);
1152 pFilter->pLoopf->pfChromaDeblockingLT4Ver (&pDestCb[ (2 << 1)*iLineSize], &pDestCr[ (2 << 1)*iLineSize], iLineSize,1152 pFilter->pLoopf->pfChromaDeblockingLT4Ver (&pDestCb[ (2 << 1)*iLineSize], &pDestCr[ (2 << 1)*iLineSize], iLineSize,
1153 iAlpha, iBeta, iTc);1153 iAlpha, iBeta, iTc);
1154 }1154 }
1155 } else {1155 } else {
1156 for (int i = 0; i < 2; i++) {1156 for (int i = 0; i < 2; i++) {
1157 1157
1158 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,1158 GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha,
1159 iBeta);1159 iBeta);
1160 if (iAlpha | iBeta) {1160 if (iAlpha | iBeta) {
1161 TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 1);1161 TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 1);
1162 uint8_t* pDestCbCr = (i == 0) ? &pDestCb[ (2 << 1) * iLineSize] : &pDestCr[ (2 << 1) * iLineSize];1162 uint8_t* pDestCbCr = (i == 0) ? &pDestCb[ (2 << 1) * iLineSize] : &pDestCr[ (2 << 1) * iLineSize];
1163 pFilter->pLoopf->pfChromaDeblockingLT4Ver2 (pDestCbCr, iLineSize,1163 pFilter->pLoopf->pfChromaDeblockingLT4Ver2 (pDestCbCr, iLineSize,
1164 iAlpha, iBeta, iTc);1164 iAlpha, iBeta, iTc);
1165 }1165 }
1166 }1166 }
1167 1167
1168 1168
1169 }1169 }
1170}1170}
1171 1171
1172// merge h&v lookup table operation to save performance1172// merge h&v lookup table operation to save performance
1173void DeblockingIntraMb (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag) {1173void DeblockingIntraMb (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag) {
1174 FilteringEdgeLumaHV (pCurDqLayer, pFilter, iBoundryFlag);1174 FilteringEdgeLumaHV (pCurDqLayer, pFilter, iBoundryFlag);
1175 FilteringEdgeChromaHV (pCurDqLayer, pFilter, iBoundryFlag);1175 FilteringEdgeChromaHV (pCurDqLayer, pFilter, iBoundryFlag);
1176}1176}
1177 1177
1178void WelsDeblockingMb (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag) {1178void WelsDeblockingMb (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag) {
1179 uint8_t nBS[2][4][4] = {{{ 0 }}};1179 uint8_t nBS[2][4][4] = {{{ 0 }}};
1180 1180
1181 int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex;1181 int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex;
1182 uint32_t iCurMbType = pCurDqLayer->pMbType[iMbXyIndex];1182 uint32_t iCurMbType = pCurDqLayer->pMbType[iMbXyIndex];
1183 int32_t iMbNb;1183 int32_t iMbNb;
1184 1184
1185 PSlice pSlice = &pCurDqLayer->sLayerInfo.sSliceInLayer;1185 PSlice pSlice = &pCurDqLayer->sLayerInfo.sSliceInLayer;
1186 PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader;1186 PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader;
1187 bool bBSlice = pSliceHeader->eSliceType == B_SLICE;1187 bool bBSlice = pSliceHeader->eSliceType == B_SLICE;
1188 1188
1189 switch (iCurMbType) {1189 switch (iCurMbType) {
1190 case MB_TYPE_INTRA4x4:1190 case MB_TYPE_INTRA4x4:
1191 case MB_TYPE_INTRA8x8:1191 case MB_TYPE_INTRA8x8:
1192 case MB_TYPE_INTRA16x16:1192 case MB_TYPE_INTRA16x16:
1193 case MB_TYPE_INTRA_PCM:1193 case MB_TYPE_INTRA_PCM:
1194 DeblockingIntraMb (pCurDqLayer, pFilter, iBoundryFlag);1194 DeblockingIntraMb (pCurDqLayer, pFilter, iBoundryFlag);
1195 break;1195 break;
1196 default:1196 default:
1197 1197
1198 if (iBoundryFlag & LEFT_FLAG_MASK) {1198 if (iBoundryFlag & LEFT_FLAG_MASK) {
1199 iMbNb = iMbXyIndex - 1;1199 iMbNb = iMbXyIndex - 1;
1200 if (bBSlice) {1200 if (bBSlice) {
1201 * (uint32_t*)nBS[0][0] = IS_INTRA (pCurDqLayer->pMbType[iMbNb]) ? 0x04040404 : DeblockingBSliceBsMarginalMBAvcbase (1201 * (uint32_t*)nBS[0][0] = IS_INTRA (pCurDqLayer->pMbType[iMbNb]) ? 0x04040404 : DeblockingBSliceBsMarginalMBAvcbase (
1202 pCurDqLayer, 0, iMbNb, iMbXyIndex);1202 pCurDqLayer, 0, iMbNb, iMbXyIndex);
1203 } else {1203 } else {
1204 * (uint32_t*)nBS[0][0] = IS_INTRA (pCurDqLayer->pMbType[iMbNb]) ? 0x04040404 : DeblockingBsMarginalMBAvcbase (1204 * (uint32_t*)nBS[0][0] = IS_INTRA (pCurDqLayer->pMbType[iMbNb]) ? 0x04040404 : DeblockingBsMarginalMBAvcbase (
1205 pCurDqLayer, 0, iMbNb, iMbXyIndex);1205 pCurDqLayer, 0, iMbNb, iMbXyIndex);
1206 }1206 }
1207 } else {1207 } else {
1208 * (uint32_t*)nBS[0][0] = 0;1208 * (uint32_t*)nBS[0][0] = 0;
1209 }1209 }
1210 if (iBoundryFlag & TOP_FLAG_MASK) {1210 if (iBoundryFlag & TOP_FLAG_MASK) {
1211 iMbNb = iMbXyIndex - pCurDqLayer->iMbWidth;1211 iMbNb = iMbXyIndex - pCurDqLayer->iMbWidth;
1212 if (bBSlice) {1212 if (bBSlice) {
1213 * (uint32_t*)nBS[1][0] = IS_INTRA (pCurDqLayer->pMbType[iMbNb]) ? 0x04040404 : DeblockingBSliceBsMarginalMBAvcbase (1213 * (uint32_t*)nBS[1][0] = IS_INTRA (pCurDqLayer->pMbType[iMbNb]) ? 0x04040404 : DeblockingBSliceBsMarginalMBAvcbase (
1214 pCurDqLayer, 1, iMbNb, iMbXyIndex);1214 pCurDqLayer, 1, iMbNb, iMbXyIndex);
1215 } else {1215 } else {
1216 * (uint32_t*)nBS[1][0] = IS_INTRA (pCurDqLayer->pMbType[iMbNb]) ? 0x04040404 : DeblockingBsMarginalMBAvcbase (1216 * (uint32_t*)nBS[1][0] = IS_INTRA (pCurDqLayer->pMbType[iMbNb]) ? 0x04040404 : DeblockingBsMarginalMBAvcbase (
1217 pCurDqLayer, 1, iMbNb, iMbXyIndex);1217 pCurDqLayer, 1, iMbNb, iMbXyIndex);
1218 }1218 }
1219 } else {1219 } else {
1220 * (uint32_t*)nBS[1][0] = 0;1220 * (uint32_t*)nBS[1][0] = 0;
1221 }1221 }
1222 //SKIP MB_16x16 or others1222 //SKIP MB_16x16 or others
1223 if (IS_SKIP (iCurMbType)) {1223 if (IS_SKIP (iCurMbType)) {
1224 * (uint32_t*)nBS[0][1] = * (uint32_t*)nBS[0][2] = * (uint32_t*)nBS[0][3] =1224 * (uint32_t*)nBS[0][1] = * (uint32_t*)nBS[0][2] = * (uint32_t*)nBS[0][3] =
1225 * (uint32_t*)nBS[1][1] = * (uint32_t*)nBS[1][2] = * (uint32_t*)nBS[1][3] = 0;1225 * (uint32_t*)nBS[1][1] = * (uint32_t*)nBS[1][2] = * (uint32_t*)nBS[1][3] = 0;
1226 } else {1226 } else {
1227 if (IS_INTER_16x16 (iCurMbType)) {1227 if (IS_INTER_16x16 (iCurMbType)) {
1228 if (!pCurDqLayer->pTransformSize8x8Flag[pCurDqLayer->iMbXyIndex]) {1228 if (!pCurDqLayer->pTransformSize8x8Flag[pCurDqLayer->iMbXyIndex]) {
1229 DeblockingBSInsideMBAvsbase (pCurDqLayer->pNzc[iMbXyIndex], nBS, 1);1229 DeblockingBSInsideMBAvsbase (pCurDqLayer->pNzc[iMbXyIndex], nBS, 1);
1230 } else {1230 } else {
1231 DeblockingBSInsideMBAvsbase8x8 (pCurDqLayer->pNzc[iMbXyIndex], nBS, 1);1231 DeblockingBSInsideMBAvsbase8x8 (pCurDqLayer->pNzc[iMbXyIndex], nBS, 1);
1232 }1232 }
1233 } else {1233 } else {
1234 1234
1235 if (bBSlice) {1235 if (bBSlice) {
1236 DeblockingBSliceBSInsideMBNormal (pCurDqLayer, nBS, pCurDqLayer->pNzc[iMbXyIndex], iMbXyIndex);1236 DeblockingBSliceBSInsideMBNormal (pCurDqLayer, nBS, pCurDqLayer->pNzc[iMbXyIndex], iMbXyIndex);
1237 } else {1237 } else {
1238 DeblockingBSInsideMBNormal (pCurDqLayer, nBS, pCurDqLayer->pNzc[iMbXyIndex], iMbXyIndex);1238 DeblockingBSInsideMBNormal (pCurDqLayer, nBS, pCurDqLayer->pNzc[iMbXyIndex], iMbXyIndex);
1239 }1239 }
1240 }1240 }
1241 }1241 }
1242 DeblockingInterMb (pCurDqLayer, pFilter, nBS, iBoundryFlag);1242 DeblockingInterMb (pCurDqLayer, pFilter, nBS, iBoundryFlag);
1243 break;1243 break;
1244 }1244 }
1245}1245}
1246 1246
1247/*!1247/*!
1248 * \brief AVC slice deblocking filtering target layer1248 * \brief AVC slice deblocking filtering target layer
1249 *1249 *
1250 * \param dec Wels avc decoder context1250 * \param dec Wels avc decoder context
1251 *1251 *
1252 * \return NONE1252 * \return NONE
1253 */1253 */
1254void WelsDeblockingFilterSlice (PWelsDecoderContext pCtx, PDeblockingFilterMbFunc pDeblockMb) {1254void WelsDeblockingFilterSlice (PWelsDecoderContext pCtx, PDeblockingFilterMbFunc pDeblockMb) {
1255 PDqLayer pCurDqLayer = pCtx->pCurDqLayer;1255 PDqLayer pCurDqLayer = pCtx->pCurDqLayer;
1256 PSliceHeaderExt pSliceHeaderExt = &pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt;1256 PSliceHeaderExt pSliceHeaderExt = &pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt;
1257 int32_t iMbWidth = pCurDqLayer->iMbWidth;1257 int32_t iMbWidth = pCurDqLayer->iMbWidth;
1258 int32_t iTotalMbCount = pSliceHeaderExt->sSliceHeader.pSps->uiTotalMbCount;1258 int32_t iTotalMbCount = pSliceHeaderExt->sSliceHeader.pSps->uiTotalMbCount;
1259 1259
1260 SDeblockingFilter pFilter;1260 SDeblockingFilter pFilter;
1261 memset (&pFilter, 0, sizeof (pFilter));1261 memset (&pFilter, 0, sizeof (pFilter));
1262 PFmo pFmo = pCtx->pFmo;1262 PFmo pFmo = pCtx->pFmo;
1263 int32_t iNextMbXyIndex = 0;1263 int32_t iNextMbXyIndex = 0;
1264 int32_t iTotalNumMb = pCurDqLayer->sLayerInfo.sSliceInLayer.iTotalMbInCurSlice;1264 int32_t iTotalNumMb = pCurDqLayer->sLayerInfo.sSliceInLayer.iTotalMbInCurSlice;
1265 int32_t iCountNumMb = 0;1265 int32_t iCountNumMb = 0;
1266 int32_t iBoundryFlag;1266 int32_t iBoundryFlag;
1267 int32_t iFilterIdc = pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.uiDisableDeblockingFilterIdc;1267 int32_t iFilterIdc = pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.uiDisableDeblockingFilterIdc;
1268 1268
1269 /* Step1: parameters set */1269 /* Step1: parameters set */
1270 pFilter.pCsData[0] = pCtx->pDec->pData[0];1270 pFilter.pCsData[0] = pCtx->pDec->pData[0];
1271 pFilter.pCsData[1] = pCtx->pDec->pData[1];1271 pFilter.pCsData[1] = pCtx->pDec->pData[1];
1272 pFilter.pCsData[2] = pCtx->pDec->pData[2];1272 pFilter.pCsData[2] = pCtx->pDec->pData[2];
1273 1273
1274 pFilter.iCsStride[0] = pCtx->pDec->iLinesize[0];1274 pFilter.iCsStride[0] = pCtx->pDec->iLinesize[0];
1275 pFilter.iCsStride[1] = pCtx->pDec->iLinesize[1];1275 pFilter.iCsStride[1] = pCtx->pDec->iLinesize[1];
1276 1276
1277 pFilter.eSliceType = (EWelsSliceType) pCurDqLayer->sLayerInfo.sSliceInLayer.eSliceType;1277 pFilter.eSliceType = (EWelsSliceType) pCurDqLayer->sLayerInfo.sSliceInLayer.eSliceType;
1278 1278
1279 pFilter.iSliceAlphaC0Offset = pSliceHeaderExt->sSliceHeader.iSliceAlphaC0Offset;1279 pFilter.iSliceAlphaC0Offset = pSliceHeaderExt->sSliceHeader.iSliceAlphaC0Offset;
1280 pFilter.iSliceBetaOffset = pSliceHeaderExt->sSliceHeader.iSliceBetaOffset;1280 pFilter.iSliceBetaOffset = pSliceHeaderExt->sSliceHeader.iSliceBetaOffset;
1281 1281
1282 pFilter.pLoopf = &pCtx->sDeblockingFunc;1282 pFilter.pLoopf = &pCtx->sDeblockingFunc;
1283 1283
1284 /* Step2: macroblock deblocking */1284 /* Step2: macroblock deblocking */
1285 if (0 == iFilterIdc || 2 == iFilterIdc) {1285 if (0 == iFilterIdc || 2 == iFilterIdc) {
1286 iNextMbXyIndex = pSliceHeaderExt->sSliceHeader.iFirstMbInSlice;1286 iNextMbXyIndex = pSliceHeaderExt->sSliceHeader.iFirstMbInSlice;
1287 pCurDqLayer->iMbX = iNextMbXyIndex % iMbWidth;1287 pCurDqLayer->iMbX = iNextMbXyIndex % iMbWidth;
1288 pCurDqLayer->iMbY = iNextMbXyIndex / iMbWidth;1288 pCurDqLayer->iMbY = iNextMbXyIndex / iMbWidth;
1289 pCurDqLayer->iMbXyIndex = iNextMbXyIndex;1289 pCurDqLayer->iMbXyIndex = iNextMbXyIndex;
1290 1290
1291 do {1291 do {
1292 iBoundryFlag = DeblockingAvailableNoInterlayer (pCurDqLayer, iFilterIdc);1292 iBoundryFlag = DeblockingAvailableNoInterlayer (pCurDqLayer, iFilterIdc);
1293 1293
1294 pDeblockMb (pCurDqLayer, &pFilter, iBoundryFlag);1294 pDeblockMb (pCurDqLayer, &pFilter, iBoundryFlag);
1295 1295
1296 ++iCountNumMb;1296 ++iCountNumMb;
1297 if (iCountNumMb >= iTotalNumMb) {1297 if (iCountNumMb >= iTotalNumMb) {
1298 break;1298 break;
1299 }1299 }
1300 1300
1301 if (pSliceHeaderExt->sSliceHeader.pPps->uiNumSliceGroups > 1) {1301 if (pSliceHeaderExt->sSliceHeader.pPps->uiNumSliceGroups > 1) {
1302 iNextMbXyIndex = FmoNextMb (pFmo, iNextMbXyIndex);1302 iNextMbXyIndex = FmoNextMb (pFmo, iNextMbXyIndex);
1303 } else {1303 } else {
1304 ++iNextMbXyIndex;1304 ++iNextMbXyIndex;
1305 }1305 }
1306 if (-1 == iNextMbXyIndex || iNextMbXyIndex >= iTotalMbCount) { // slice group boundary or end of a frame1306 if (-1 == iNextMbXyIndex || iNextMbXyIndex >= iTotalMbCount) { // slice group boundary or end of a frame
1307 break;1307 break;
1308 }1308 }
1309 1309
1310 pCurDqLayer->iMbX = iNextMbXyIndex % iMbWidth;1310 pCurDqLayer->iMbX = iNextMbXyIndex % iMbWidth;
1311 pCurDqLayer->iMbY = iNextMbXyIndex / iMbWidth;1311 pCurDqLayer->iMbY = iNextMbXyIndex / iMbWidth;
1312 pCurDqLayer->iMbXyIndex = iNextMbXyIndex;1312 pCurDqLayer->iMbXyIndex = iNextMbXyIndex;
1313 } while (1);1313 } while (1);
1314 }1314 }
1315}1315}
1316/*!1316/*!
1317 * \brief deblocking module initialize1317 * \brief deblocking module initialize
1318 *1318 *
1319 * \param pf1319 * \param pf
1320 * cpu1320 * cpu
1321 *1321 *
1322 * \return NONE1322 * \return NONE
1323 */1323 */
1324 1324
1325void DeblockingInit (SDeblockingFunc* pFunc, int32_t iCpu) {1325void DeblockingInit (SDeblockingFunc* pFunc, int32_t iCpu) {
1326 pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_c;1326 pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_c;
1327 pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_c;1327 pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_c;
1328 pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_c;1328 pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_c;
1329 pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_c;1329 pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_c;
1330 1330
1331 pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_c;1331 pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_c;
1332 pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_c;1332 pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_c;
1333 pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_c;1333 pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_c;
1334 pFunc->pfChromaDeblockingEQ4Hor = DeblockChromaEq4H_c;1334 pFunc->pfChromaDeblockingEQ4Hor = DeblockChromaEq4H_c;
1335 1335
1336 pFunc->pfChromaDeblockingLT4Ver2 = DeblockChromaLt4V2_c;1336 pFunc->pfChromaDeblockingLT4Ver2 = DeblockChromaLt4V2_c;
1337 pFunc->pfChromaDeblockingEQ4Ver2 = DeblockChromaEq4V2_c;1337 pFunc->pfChromaDeblockingEQ4Ver2 = DeblockChromaEq4V2_c;
1338 pFunc->pfChromaDeblockingLT4Hor2 = DeblockChromaLt4H2_c;1338 pFunc->pfChromaDeblockingLT4Hor2 = DeblockChromaLt4H2_c;
1339 pFunc->pfChromaDeblockingEQ4Hor2 = DeblockChromaEq4H2_c;1339 pFunc->pfChromaDeblockingEQ4Hor2 = DeblockChromaEq4H2_c;
1340 1340
1341#ifdef X86_ASM1341#ifdef X86_ASM
1342 if (iCpu & WELS_CPU_SSSE3) {1342 if (iCpu & WELS_CPU_SSSE3) {
1343 pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_ssse3;1343 pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_ssse3;
1344 pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_ssse3;1344 pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_ssse3;
1345 pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_ssse3;1345 pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_ssse3;
1346 pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_ssse3;1346 pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_ssse3;
1347 pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_ssse3;1347 pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_ssse3;
1348 pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_ssse3;1348 pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_ssse3;
1349 pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_ssse3;1349 pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_ssse3;
1350 pFunc->pfChromaDeblockingEQ4Hor = DeblockChromaEq4H_ssse3;1350 pFunc->pfChromaDeblockingEQ4Hor = DeblockChromaEq4H_ssse3;
1351 }1351 }
1352#endif1352#endif
1353 1353
1354#if defined(HAVE_NEON)1354#if defined(HAVE_NEON)
1355 if (iCpu & WELS_CPU_NEON) {1355 if (iCpu & WELS_CPU_NEON) {
1356 pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_neon;1356 pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_neon;
1357 pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_neon;1357 pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_neon;
1358 pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_neon;1358 pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_neon;
1359 pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_neon;1359 pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_neon;
1360 1360
1361 pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_neon;1361 pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_neon;
1362 pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_neon;1362 pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_neon;
1363 pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_neon;1363 pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_neon;
1364 pFunc->pfChromaDeblockingEQ4Hor = DeblockChromaEq4H_neon;1364 pFunc->pfChromaDeblockingEQ4Hor = DeblockChromaEq4H_neon;
1365 }1365 }
1366#endif1366#endif
1367 1367
1368#if defined(HAVE_NEON_AARCH64)1368#if defined(HAVE_NEON_AARCH64)
1369 if (iCpu & WELS_CPU_NEON) {1369 if (iCpu & WELS_CPU_NEON) {
1370 pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_AArch64_neon;1370 pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_AArch64_neon;
1371 pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_AArch64_neon;1371 pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_AArch64_neon;
1372 pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_AArch64_neon;1372 pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_AArch64_neon;
1373 pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_AArch64_neon;1373 pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_AArch64_neon;
1374 1374
1375 pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_AArch64_neon;1375 pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_AArch64_neon;
1376 pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_AArch64_neon;1376 pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_AArch64_neon;
1377 pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_AArch64_neon;1377 pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_AArch64_neon;
1378 pFunc->pfChromaDeblockingEQ4Hor = DeblockChromaEq4H_AArch64_neon;1378 pFunc->pfChromaDeblockingEQ4Hor = DeblockChromaEq4H_AArch64_neon;
1379 }1379 }
1380#endif1380#endif
1381}1381}
1382 1382
1383} // namespace WelsDec1383} // namespace WelsDec
codec/decoder/core/src/manage_dec_ref.cpp+897−897
@@ -1,897 +1,897 @@
1/*!1/*!
2 * \copy2 * \copy
3 * Copyright (c) 2008-2013, Cisco Systems3 * Copyright (c) 2008-2013, Cisco Systems
4 * All rights reserved.4 * All rights reserved.
5 *5 *
6 * Redistribution and use in source and binary forms, with or without6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions7 * modification, are permitted provided that the following conditions
8 * are met:8 * are met:
9 *9 *
10 * * Redistributions of source code must retain the above copyright10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.11 * notice, this list of conditions and the following disclaimer.
12 *12 *
13 * * Redistributions in binary form must reproduce the above copyright13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the15 * the documentation and/or other materials provided with the
16 * distribution.16 * distribution.
17 *17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.29 * POSSIBILITY OF SUCH DAMAGE.
30 *30 *
31 *31 *
32 * manage_dec_ref.cpp32 * manage_dec_ref.cpp
33 *33 *
34 * Abstract34 * Abstract
35 * Implementation for managing reference picture35 * Implementation for managing reference picture
36 *36 *
37 * History37 * History
38 * 07/21/2008 Created38 * 07/21/2008 Created
39 *39 *
40 *****************************************************************************/40 *****************************************************************************/
41 41
42#include "manage_dec_ref.h"42#include "manage_dec_ref.h"
43#include "error_concealment.h"43#include "error_concealment.h"
44#include "error_code.h"44#include "error_code.h"
45 45
46namespace WelsDec {46namespace WelsDec {
47 47
48static PPicture WelsDelShortFromList (PRefPic pRefPic, int32_t iFrameNum);48static PPicture WelsDelShortFromList (PRefPic pRefPic, int32_t iFrameNum);
49static PPicture WelsDelLongFromList (PRefPic pRefPic, uint32_t uiLongTermFrameIdx);49static PPicture WelsDelLongFromList (PRefPic pRefPic, uint32_t uiLongTermFrameIdx);
50static PPicture WelsDelShortFromListSetUnref (PRefPic pRefPic, int32_t iFrameNum);50static PPicture WelsDelShortFromListSetUnref (PRefPic pRefPic, int32_t iFrameNum);
51static PPicture WelsDelLongFromListSetUnref (PRefPic pRefPic, uint32_t uiLongTermFrameIdx);51static PPicture WelsDelLongFromListSetUnref (PRefPic pRefPic, uint32_t uiLongTermFrameIdx);
52 52
53static int32_t MMCO (PWelsDecoderContext pCtx, PRefPicMarking pRefPicMarking);53static int32_t MMCO (PWelsDecoderContext pCtx, PRefPicMarking pRefPicMarking);
54static int32_t MMCOProcess (PWelsDecoderContext pCtx, uint32_t uiMmcoType,54static int32_t MMCOProcess (PWelsDecoderContext pCtx, uint32_t uiMmcoType,
55 int32_t iShortFrameNum, uint32_t uiLongTermPicNum, int32_t iLongTermFrameIdx, int32_t iMaxLongTermFrameIdx);55 int32_t iShortFrameNum, uint32_t uiLongTermPicNum, int32_t iLongTermFrameIdx, int32_t iMaxLongTermFrameIdx);
56static int32_t SlidingWindow (PWelsDecoderContext pCtx);56static int32_t SlidingWindow (PWelsDecoderContext pCtx);
57 57
58static int32_t AddShortTermToList (PRefPic pRefPic, PPicture pPic);58static int32_t AddShortTermToList (PRefPic pRefPic, PPicture pPic);
59static int32_t AddLongTermToList (PRefPic pRefPic, PPicture pPic, int32_t iLongTermFrameIdx, uint32_t uiLongTermPicNum);59static int32_t AddLongTermToList (PRefPic pRefPic, PPicture pPic, int32_t iLongTermFrameIdx, uint32_t uiLongTermPicNum);
60static int32_t MarkAsLongTerm (PRefPic pRefPic, int32_t iFrameNum, int32_t iLongTermFrameIdx,60static int32_t MarkAsLongTerm (PRefPic pRefPic, int32_t iFrameNum, int32_t iLongTermFrameIdx,
61 uint32_t uiLongTermPicNum);61 uint32_t uiLongTermPicNum);
62static int32_t WelsCheckAndRecoverForFutureDecoding (PWelsDecoderContext pCtx);62static int32_t WelsCheckAndRecoverForFutureDecoding (PWelsDecoderContext pCtx);
63#ifdef LONG_TERM_REF63#ifdef LONG_TERM_REF
64int32_t GetLTRFrameIndex (PRefPic pRefPic, int32_t iAncLTRFrameNum);64int32_t GetLTRFrameIndex (PRefPic pRefPic, int32_t iAncLTRFrameNum);
65#endif65#endif
66static int32_t RemainOneBufferInDpbForEC (PWelsDecoderContext pCtx);66static int32_t RemainOneBufferInDpbForEC (PWelsDecoderContext pCtx);
67 67
68static void SetUnRef (PPicture pRef) {68static void SetUnRef (PPicture pRef) {
69 if (NULL != pRef) {69 if (NULL != pRef) {
70 pRef->bUsedAsRef = false;70 pRef->bUsedAsRef = false;
71 pRef->bIsLongRef = false;71 pRef->bIsLongRef = false;
72 pRef->iFrameNum = -1;72 pRef->iFrameNum = -1;
73 pRef->iFrameWrapNum = -1;73 pRef->iFrameWrapNum = -1;
74 //pRef->iFramePoc = 0;74 //pRef->iFramePoc = 0;
75 pRef->iLongTermFrameIdx = -1;75 pRef->iLongTermFrameIdx = -1;
76 pRef->uiLongTermPicNum = 0;76 pRef->uiLongTermPicNum = 0;
77 pRef->uiQualityId = -1;77 pRef->uiQualityId = -1;
78 pRef->uiTemporalId = -1;78 pRef->uiTemporalId = -1;
79 pRef->uiSpatialId = -1;79 pRef->uiSpatialId = -1;
80 pRef->iSpsId = -1;80 pRef->iSpsId = -1;
81 pRef->bIsComplete = false;81 pRef->bIsComplete = false;
82 }82 }
83}83}
84 84
85//reset pRefList when85//reset pRefList when
86// 1.sps arrived that is new sequence starting86// 1.sps arrived that is new sequence starting
87// 2.IDR NAL i.e. 1st layer in IDR AU87// 2.IDR NAL i.e. 1st layer in IDR AU
88 88
89void WelsResetRefPic (PWelsDecoderContext pCtx) {89void WelsResetRefPic (PWelsDecoderContext pCtx) {
90 int32_t i = 0;90 int32_t i = 0;
91 PRefPic pRefPic = &pCtx->sRefPic;91 PRefPic pRefPic = &pCtx->sRefPic;
92 pCtx->sRefPic.uiLongRefCount[LIST_0] = pCtx->sRefPic.uiShortRefCount[LIST_0] = 0;92 pCtx->sRefPic.uiLongRefCount[LIST_0] = pCtx->sRefPic.uiShortRefCount[LIST_0] = 0;
93 93
94 pRefPic->uiRefCount[LIST_0] = 0;94 pRefPic->uiRefCount[LIST_0] = 0;
95 pRefPic->uiRefCount[LIST_1] = 0;95 pRefPic->uiRefCount[LIST_1] = 0;
96 96
97 for (i = 0; i < MAX_DPB_COUNT; i++) {97 for (i = 0; i < MAX_DPB_COUNT; i++) {
98 if (pRefPic->pShortRefList[LIST_0][i] != NULL) {98 if (pRefPic->pShortRefList[LIST_0][i] != NULL) {
99 SetUnRef (pRefPic->pShortRefList[LIST_0][i]);99 SetUnRef (pRefPic->pShortRefList[LIST_0][i]);
100 pRefPic->pShortRefList[LIST_0][i] = NULL;100 pRefPic->pShortRefList[LIST_0][i] = NULL;
101 }101 }
102 }102 }
103 pRefPic->uiShortRefCount[LIST_0] = 0;103 pRefPic->uiShortRefCount[LIST_0] = 0;
104 104
105 for (i = 0; i < MAX_DPB_COUNT; i++) {105 for (i = 0; i < MAX_DPB_COUNT; i++) {
106 if (pRefPic->pLongRefList[LIST_0][i] != NULL) {106 if (pRefPic->pLongRefList[LIST_0][i] != NULL) {
107 SetUnRef (pRefPic->pLongRefList[LIST_0][i]);107 SetUnRef (pRefPic->pLongRefList[LIST_0][i]);
108 pRefPic->pLongRefList[LIST_0][i] = NULL;108 pRefPic->pLongRefList[LIST_0][i] = NULL;
109 }109 }
110 }110 }
111 pRefPic->uiLongRefCount[LIST_0] = 0;111 pRefPic->uiLongRefCount[LIST_0] = 0;
112}112}
113 113
114static int32_t WelsCheckAndRecoverForFutureDecoding (PWelsDecoderContext pCtx) {114static int32_t WelsCheckAndRecoverForFutureDecoding (PWelsDecoderContext pCtx) {
115 if ((pCtx->sRefPic.uiShortRefCount[LIST_0] + pCtx->sRefPic.uiLongRefCount[LIST_0] <= 0) && (pCtx->eSliceType != I_SLICE115 if ((pCtx->sRefPic.uiShortRefCount[LIST_0] + pCtx->sRefPic.uiLongRefCount[LIST_0] <= 0) && (pCtx->eSliceType != I_SLICE
116 && pCtx->eSliceType != SI_SLICE)) {116 && pCtx->eSliceType != SI_SLICE)) {
117 if (pCtx->pParam->eEcActiveIdc !=117 if (pCtx->pParam->eEcActiveIdc !=
118 ERROR_CON_DISABLE) { //IDR lost!, recover it for future decoding with data all set to 0118 ERROR_CON_DISABLE) { //IDR lost!, recover it for future decoding with data all set to 0
119 PPicture pRef = PrefetchPic (pCtx->pPicBuff);119 PPicture pRef = PrefetchPic (pCtx->pPicBuff);
120 if (pRef != NULL) {120 if (pRef != NULL) {
121 // IDR lost, set new121 // IDR lost, set new
122 pRef->bIsComplete = false; // Set complete flag to false for lost IDR ref picture122 pRef->bIsComplete = false; // Set complete flag to false for lost IDR ref picture
123 pRef->iSpsId = pCtx->pSps->iSpsId;123 pRef->iSpsId = pCtx->pSps->iSpsId;
124 pRef->iPpsId = pCtx->pPps->iPpsId;124 pRef->iPpsId = pCtx->pPps->iPpsId;
125 pCtx->iErrorCode |= dsDataErrorConcealed;125 pCtx->iErrorCode |= dsDataErrorConcealed;
126 bool bCopyPrevious = ((ERROR_CON_FRAME_COPY_CROSS_IDR == pCtx->pParam->eEcActiveIdc)126 bool bCopyPrevious = ((ERROR_CON_FRAME_COPY_CROSS_IDR == pCtx->pParam->eEcActiveIdc)
127 || (ERROR_CON_SLICE_COPY_CROSS_IDR == pCtx->pParam->eEcActiveIdc)127 || (ERROR_CON_SLICE_COPY_CROSS_IDR == pCtx->pParam->eEcActiveIdc)
128 || (ERROR_CON_SLICE_COPY_CROSS_IDR_FREEZE_RES_CHANGE == pCtx->pParam->eEcActiveIdc)128 || (ERROR_CON_SLICE_COPY_CROSS_IDR_FREEZE_RES_CHANGE == pCtx->pParam->eEcActiveIdc)
129 || (ERROR_CON_SLICE_MV_COPY_CROSS_IDR == pCtx->pParam->eEcActiveIdc)129 || (ERROR_CON_SLICE_MV_COPY_CROSS_IDR == pCtx->pParam->eEcActiveIdc)
130 || (ERROR_CON_SLICE_MV_COPY_CROSS_IDR_FREEZE_RES_CHANGE == pCtx->pParam->eEcActiveIdc))130 || (ERROR_CON_SLICE_MV_COPY_CROSS_IDR_FREEZE_RES_CHANGE == pCtx->pParam->eEcActiveIdc))
131 && (NULL != pCtx->pPreviousDecodedPictureInDpb);131 && (NULL != pCtx->pPreviousDecodedPictureInDpb);
132 bCopyPrevious = bCopyPrevious && (pRef->iWidthInPixel == pCtx->pPreviousDecodedPictureInDpb->iWidthInPixel)132 bCopyPrevious = bCopyPrevious && (pRef->iWidthInPixel == pCtx->pPreviousDecodedPictureInDpb->iWidthInPixel)
133 && (pRef->iHeightInPixel == pCtx->pPreviousDecodedPictureInDpb->iHeightInPixel);133 && (pRef->iHeightInPixel == pCtx->pPreviousDecodedPictureInDpb->iHeightInPixel);
134 134
135 if (!bCopyPrevious) {135 if (!bCopyPrevious) {
136 memset (pRef->pData[0], 128, pRef->iLinesize[0] * pRef->iHeightInPixel);136 memset (pRef->pData[0], 128, pRef->iLinesize[0] * pRef->iHeightInPixel);
137 memset (pRef->pData[1], 128, pRef->iLinesize[1] * pRef->iHeightInPixel / 2);137 memset (pRef->pData[1], 128, pRef->iLinesize[1] * pRef->iHeightInPixel / 2);
138 memset (pRef->pData[2], 128, pRef->iLinesize[2] * pRef->iHeightInPixel / 2);138 memset (pRef->pData[2], 128, pRef->iLinesize[2] * pRef->iHeightInPixel / 2);
139 } else if (pRef == pCtx->pPreviousDecodedPictureInDpb) {139 } else if (pRef == pCtx->pPreviousDecodedPictureInDpb) {
140 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "WelsInitRefList()::EC memcpy overlap.");140 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "WelsInitRefList()::EC memcpy overlap.");
141 } else {141 } else {
142 memcpy (pRef->pData[0], pCtx->pPreviousDecodedPictureInDpb->pData[0], pRef->iLinesize[0] * pRef->iHeightInPixel);142 memcpy (pRef->pData[0], pCtx->pPreviousDecodedPictureInDpb->pData[0], pRef->iLinesize[0] * pRef->iHeightInPixel);
143 memcpy (pRef->pData[1], pCtx->pPreviousDecodedPictureInDpb->pData[1], pRef->iLinesize[1] * pRef->iHeightInPixel / 2);143 memcpy (pRef->pData[1], pCtx->pPreviousDecodedPictureInDpb->pData[1], pRef->iLinesize[1] * pRef->iHeightInPixel / 2);
144 memcpy (pRef->pData[2], pCtx->pPreviousDecodedPictureInDpb->pData[2], pRef->iLinesize[2] * pRef->iHeightInPixel / 2);144 memcpy (pRef->pData[2], pCtx->pPreviousDecodedPictureInDpb->pData[2], pRef->iLinesize[2] * pRef->iHeightInPixel / 2);
145 }145 }
146 pRef->iFrameNum = 0;146 pRef->iFrameNum = 0;
147 pRef->iFramePoc = 0;147 pRef->iFramePoc = 0;
148 pRef->uiTemporalId = pRef->uiQualityId = 0;148 pRef->uiTemporalId = pRef->uiQualityId = 0;
149 ExpandReferencingPicture (pRef->pData, pRef->iWidthInPixel, pRef->iHeightInPixel, pRef->iLinesize,149 ExpandReferencingPicture (pRef->pData, pRef->iWidthInPixel, pRef->iHeightInPixel, pRef->iLinesize,
150 pCtx->sExpandPicFunc.pfExpandLumaPicture, pCtx->sExpandPicFunc.pfExpandChromaPicture);150 pCtx->sExpandPicFunc.pfExpandLumaPicture, pCtx->sExpandPicFunc.pfExpandChromaPicture);
151 AddShortTermToList (&pCtx->sRefPic, pRef);151 AddShortTermToList (&pCtx->sRefPic, pRef);
152 } else {152 } else {
153 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "WelsInitRefList()::PrefetchPic for EC errors.");153 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "WelsInitRefList()::PrefetchPic for EC errors.");
154 pCtx->iErrorCode |= dsOutOfMemory;154 pCtx->iErrorCode |= dsOutOfMemory;
155 return ERR_INFO_REF_COUNT_OVERFLOW;155 return ERR_INFO_REF_COUNT_OVERFLOW;
156 }156 }
157 }157 }
158 }158 }
159 return ERR_NONE;159 return ERR_NONE;
160}160}
161 161
162static void WrapShortRefPicNum (PWelsDecoderContext pCtx) {162static void WrapShortRefPicNum (PWelsDecoderContext pCtx) {
163 int32_t i;163 int32_t i;
164 PSliceHeader pSliceHeader = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader;164 PSliceHeader pSliceHeader = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader;
165 int32_t iMaxPicNum = 1 << pSliceHeader->pSps->uiLog2MaxFrameNum;165 int32_t iMaxPicNum = 1 << pSliceHeader->pSps->uiLog2MaxFrameNum;
166 PPicture* ppShoreRefList = pCtx->sRefPic.pShortRefList[LIST_0];166 PPicture* ppShoreRefList = pCtx->sRefPic.pShortRefList[LIST_0];
167 int32_t iShortRefCount = pCtx->sRefPic.uiShortRefCount[LIST_0];167 int32_t iShortRefCount = pCtx->sRefPic.uiShortRefCount[LIST_0];
168 //wrap pic num168 //wrap pic num
169 for (i = 0; i < iShortRefCount; i++) {169 for (i = 0; i < iShortRefCount; i++) {
170 if (ppShoreRefList[i]) {170 if (ppShoreRefList[i]) {
171 if (ppShoreRefList[i]->iFrameNum > pSliceHeader->iFrameNum)171 if (ppShoreRefList[i]->iFrameNum > pSliceHeader->iFrameNum)
172 ppShoreRefList[i]->iFrameWrapNum = ppShoreRefList[i]->iFrameNum - iMaxPicNum;172 ppShoreRefList[i]->iFrameWrapNum = ppShoreRefList[i]->iFrameNum - iMaxPicNum;
173 else173 else
174 ppShoreRefList[i]->iFrameWrapNum = ppShoreRefList[i]->iFrameNum;174 ppShoreRefList[i]->iFrameWrapNum = ppShoreRefList[i]->iFrameNum;
175 }175 }
176 }176 }
177}177}
178 178
179/**179/**
180* fills the pRefPic.pRefList LIST_0 and LIST_0 for B-Slice.180* fills the pRefPic.pRefList LIST_0 and LIST_0 for B-Slice.
181*/181*/
182int32_t WelsInitBSliceRefList (PWelsDecoderContext pCtx, int32_t iPoc) {182int32_t WelsInitBSliceRefList (PWelsDecoderContext pCtx, int32_t iPoc) {
183 183
184 int32_t err = WelsCheckAndRecoverForFutureDecoding (pCtx);184 int32_t err = WelsCheckAndRecoverForFutureDecoding (pCtx);
185 if (err != ERR_NONE) return err;185 if (err != ERR_NONE) return err;
186 186
187 WrapShortRefPicNum (pCtx);187 WrapShortRefPicNum (pCtx);
188 188
189 PPicture* ppShoreRefList = pCtx->sRefPic.pShortRefList[LIST_0];189 PPicture* ppShoreRefList = pCtx->sRefPic.pShortRefList[LIST_0];
190 PPicture* ppLongRefList = pCtx->sRefPic.pLongRefList[LIST_0];190 PPicture* ppLongRefList = pCtx->sRefPic.pLongRefList[LIST_0];
191 memset (pCtx->sRefPic.pRefList[LIST_0], 0, MAX_DPB_COUNT * sizeof (PPicture));191 memset (pCtx->sRefPic.pRefList[LIST_0], 0, MAX_DPB_COUNT * sizeof (PPicture));
192 memset (pCtx->sRefPic.pRefList[LIST_1], 0, MAX_DPB_COUNT * sizeof (PPicture));192 memset (pCtx->sRefPic.pRefList[LIST_1], 0, MAX_DPB_COUNT * sizeof (PPicture));
193 int32_t iLSCurrPocCount = 0;193 int32_t iLSCurrPocCount = 0;
194 int32_t iLTCurrPocCount = 0;194 int32_t iLTCurrPocCount = 0;
195 PPicture pLSCurrPocList0[MAX_DPB_COUNT];195 PPicture pLSCurrPocList0[MAX_DPB_COUNT];
196 PPicture pLTCurrPocList0[MAX_DPB_COUNT];196 PPicture pLTCurrPocList0[MAX_DPB_COUNT];
197 for (int32_t i = 0; i < pCtx->sRefPic.uiShortRefCount[LIST_0]; ++i) {197 for (int32_t i = 0; i < pCtx->sRefPic.uiShortRefCount[LIST_0]; ++i) {
198 if (ppShoreRefList[i]->iFramePoc < iPoc) {198 if (ppShoreRefList[i]->iFramePoc < iPoc) {
199 pLSCurrPocList0[iLSCurrPocCount++] = ppShoreRefList[i];199 pLSCurrPocList0[iLSCurrPocCount++] = ppShoreRefList[i];
200 }200 }
201 }201 }
202 for (int32_t i = pCtx->sRefPic.uiShortRefCount[LIST_0] - 1; i >= 0; --i) {202 for (int32_t i = pCtx->sRefPic.uiShortRefCount[LIST_0] - 1; i >= 0; --i) {
203 if (ppShoreRefList[i]->iFramePoc > iPoc) {203 if (ppShoreRefList[i]->iFramePoc > iPoc) {
204 pLTCurrPocList0[iLTCurrPocCount++] = ppShoreRefList[i];204 pLTCurrPocList0[iLTCurrPocCount++] = ppShoreRefList[i];
205 }205 }
206 }206 }
207 if (pCtx->sRefPic.uiLongRefCount[LIST_0] > 1) {207 if (pCtx->sRefPic.uiLongRefCount[LIST_0] > 1) {
208 //long sorts in increasing order208 //long sorts in increasing order
209 PPicture pTemp;209 PPicture pTemp;
210 for (int32_t i = 0; i < pCtx->sRefPic.uiLongRefCount[LIST_0]; ++i) {210 for (int32_t i = 0; i < pCtx->sRefPic.uiLongRefCount[LIST_0]; ++i) {
211 for (int32_t j = i + 1; j < pCtx->sRefPic.uiLongRefCount[LIST_0]; ++j) {211 for (int32_t j = i + 1; j < pCtx->sRefPic.uiLongRefCount[LIST_0]; ++j) {
212 if (ppLongRefList[j]->iFramePoc < ppLongRefList[i]->iFramePoc) {212 if (ppLongRefList[j]->iFramePoc < ppLongRefList[i]->iFramePoc) {
213 pTemp = ppLongRefList[i];213 pTemp = ppLongRefList[i];
214 ppLongRefList[i] = ppLongRefList[j];214 ppLongRefList[i] = ppLongRefList[j];
215 ppLongRefList[j] = pTemp;215 ppLongRefList[j] = pTemp;
216 }216 }
217 }217 }
218 }218 }
219 }219 }
220 int32_t iCurrPocCount = iLSCurrPocCount + iLTCurrPocCount;220 int32_t iCurrPocCount = iLSCurrPocCount + iLTCurrPocCount;
221 int32_t iCount = 0;221 int32_t iCount = 0;
222 //LIST_0222 //LIST_0
223 //short223 //short
224 //It may need to sort LIST_0 and LIST_1 so that they will have the right default orders.224 //It may need to sort LIST_0 and LIST_1 so that they will have the right default orders.
225 for (int32_t i = 0; i < iLSCurrPocCount; ++i) {225 for (int32_t i = 0; i < iLSCurrPocCount; ++i) {
226 pCtx->sRefPic.pRefList[LIST_0][iCount++] = pLSCurrPocList0[i];226 pCtx->sRefPic.pRefList[LIST_0][iCount++] = pLSCurrPocList0[i];
227 }227 }
228 if (iLSCurrPocCount > 1) {228 if (iLSCurrPocCount > 1) {
229 //LIST_0 short sorts in decreasing order229 //LIST_0 short sorts in decreasing order
230 PPicture pTemp;230 PPicture pTemp;
231 for (int32_t i = 0; i < iLSCurrPocCount; ++i) {231 for (int32_t i = 0; i < iLSCurrPocCount; ++i) {
232 for (int32_t j = i + 1; j < iLSCurrPocCount; ++j) {232 for (int32_t j = i + 1; j < iLSCurrPocCount; ++j) {
233 if (pCtx->sRefPic.pRefList[LIST_0][j]->iFramePoc > pCtx->sRefPic.pRefList[LIST_0][i]->iFramePoc) {233 if (pCtx->sRefPic.pRefList[LIST_0][j]->iFramePoc > pCtx->sRefPic.pRefList[LIST_0][i]->iFramePoc) {
234 pTemp = pCtx->sRefPic.pRefList[LIST_0][i];234 pTemp = pCtx->sRefPic.pRefList[LIST_0][i];
235 pCtx->sRefPic.pRefList[LIST_0][i] = pCtx->sRefPic.pRefList[LIST_0][j];235 pCtx->sRefPic.pRefList[LIST_0][i] = pCtx->sRefPic.pRefList[LIST_0][j];
236 pCtx->sRefPic.pRefList[LIST_0][j] = pTemp;236 pCtx->sRefPic.pRefList[LIST_0][j] = pTemp;
237 }237 }
238 }238 }
239 }239 }
240 }240 }
241 for (int32_t i = 0; i < iLTCurrPocCount; ++i) {241 for (int32_t i = 0; i < iLTCurrPocCount; ++i) {
242 pCtx->sRefPic.pRefList[LIST_0][iCount++] = pLTCurrPocList0[i];242 pCtx->sRefPic.pRefList[LIST_0][iCount++] = pLTCurrPocList0[i];
243 }243 }
244 if (iLTCurrPocCount > 1) {244 if (iLTCurrPocCount > 1) {
245 //LIST_0 short sorts in increasing order245 //LIST_0 short sorts in increasing order
246 PPicture pTemp;246 PPicture pTemp;
247 for (int32_t i = iLSCurrPocCount; i < iCurrPocCount; ++i) {247 for (int32_t i = iLSCurrPocCount; i < iCurrPocCount; ++i) {
248 for (int32_t j = i + 1; j < iCurrPocCount; ++j) {248 for (int32_t j = i + 1; j < iCurrPocCount; ++j) {
249 if (pCtx->sRefPic.pRefList[LIST_0][j]->iFramePoc < pCtx->sRefPic.pRefList[LIST_0][i]->iFramePoc) {249 if (pCtx->sRefPic.pRefList[LIST_0][j]->iFramePoc < pCtx->sRefPic.pRefList[LIST_0][i]->iFramePoc) {
250 pTemp = pCtx->sRefPic.pRefList[LIST_0][i];250 pTemp = pCtx->sRefPic.pRefList[LIST_0][i];
251 pCtx->sRefPic.pRefList[LIST_0][i] = pCtx->sRefPic.pRefList[LIST_0][j];251 pCtx->sRefPic.pRefList[LIST_0][i] = pCtx->sRefPic.pRefList[LIST_0][j];
252 pCtx->sRefPic.pRefList[LIST_0][j] = pTemp;252 pCtx->sRefPic.pRefList[LIST_0][j] = pTemp;
253 }253 }
254 }254 }
255 }255 }
256 }256 }
257 //long257 //long
258 for (int32_t i = 0; i < pCtx->sRefPic.uiLongRefCount[LIST_0]; ++i) {258 for (int32_t i = 0; i < pCtx->sRefPic.uiLongRefCount[LIST_0]; ++i) {
259 pCtx->sRefPic.pRefList[LIST_0][iCount++] = ppLongRefList[i];259 pCtx->sRefPic.pRefList[LIST_0][iCount++] = ppLongRefList[i];
260 }260 }
261 pCtx->sRefPic.uiRefCount[LIST_0] = iCount;261 pCtx->sRefPic.uiRefCount[LIST_0] = iCount;
262 262
263 iCount = 0;263 iCount = 0;
264 //LIST_1264 //LIST_1
265 //short265 //short
266 for (int32_t i = 0; i < iLTCurrPocCount; ++i) {266 for (int32_t i = 0; i < iLTCurrPocCount; ++i) {
267 pCtx->sRefPic.pRefList[LIST_1][iCount++] = pLTCurrPocList0[i];267 pCtx->sRefPic.pRefList[LIST_1][iCount++] = pLTCurrPocList0[i];
268 }268 }
269 if (iLTCurrPocCount > 1) {269 if (iLTCurrPocCount > 1) {
270 //LIST_1 short sorts in increasing order270 //LIST_1 short sorts in increasing order
271 PPicture pTemp;271 PPicture pTemp;
272 for (int32_t i = 0; i < iLTCurrPocCount; ++i) {272 for (int32_t i = 0; i < iLTCurrPocCount; ++i) {
273 for (int32_t j = i + 1; j < iLTCurrPocCount; ++j) {273 for (int32_t j = i + 1; j < iLTCurrPocCount; ++j) {
274 if (pCtx->sRefPic.pRefList[LIST_1][j]->iFramePoc < pCtx->sRefPic.pRefList[LIST_1][i]->iFramePoc) {274 if (pCtx->sRefPic.pRefList[LIST_1][j]->iFramePoc < pCtx->sRefPic.pRefList[LIST_1][i]->iFramePoc) {
275 pTemp = pCtx->sRefPic.pRefList[LIST_1][i];275 pTemp = pCtx->sRefPic.pRefList[LIST_1][i];
276 pCtx->sRefPic.pRefList[LIST_1][i] = pCtx->sRefPic.pRefList[LIST_1][j];276 pCtx->sRefPic.pRefList[LIST_1][i] = pCtx->sRefPic.pRefList[LIST_1][j];
277 pCtx->sRefPic.pRefList[LIST_1][j] = pTemp;277 pCtx->sRefPic.pRefList[LIST_1][j] = pTemp;
278 }278 }
279 }279 }
280 }280 }
281 }281 }
282 for (int32_t i = 0; i < iLSCurrPocCount; ++i) {282 for (int32_t i = 0; i < iLSCurrPocCount; ++i) {
283 pCtx->sRefPic.pRefList[LIST_1][iCount++] = pLSCurrPocList0[i];283 pCtx->sRefPic.pRefList[LIST_1][iCount++] = pLSCurrPocList0[i];
284 }284 }
285 if (iLSCurrPocCount > 1) {285 if (iLSCurrPocCount > 1) {
286 //LIST_1 short sorts in decreasing order286 //LIST_1 short sorts in decreasing order
287 PPicture pTemp;287 PPicture pTemp;
288 for (int32_t i = iLTCurrPocCount; i < iCurrPocCount; ++i) {288 for (int32_t i = iLTCurrPocCount; i < iCurrPocCount; ++i) {
289 for (int32_t j = i + 1; j < iCurrPocCount; ++j) {289 for (int32_t j = i + 1; j < iCurrPocCount; ++j) {
290 if (pCtx->sRefPic.pRefList[LIST_1][j]->iFramePoc > pCtx->sRefPic.pRefList[LIST_1][i]->iFramePoc) {290 if (pCtx->sRefPic.pRefList[LIST_1][j]->iFramePoc > pCtx->sRefPic.pRefList[LIST_1][i]->iFramePoc) {
291 pTemp = pCtx->sRefPic.pRefList[LIST_1][i];291 pTemp = pCtx->sRefPic.pRefList[LIST_1][i];
292 pCtx->sRefPic.pRefList[LIST_1][i] = pCtx->sRefPic.pRefList[LIST_1][j];292 pCtx->sRefPic.pRefList[LIST_1][i] = pCtx->sRefPic.pRefList[LIST_1][j];
293 pCtx->sRefPic.pRefList[LIST_1][j] = pTemp;293 pCtx->sRefPic.pRefList[LIST_1][j] = pTemp;
294 }294 }
295 }295 }
296 }296 }
297 }297 }
298 //long298 //long
299 for (int32_t i = 0; i < pCtx->sRefPic.uiLongRefCount[LIST_0]; ++i) {299 for (int32_t i = 0; i < pCtx->sRefPic.uiLongRefCount[LIST_0]; ++i) {
300 pCtx->sRefPic.pRefList[LIST_1][iCount++] = ppLongRefList[i];300 pCtx->sRefPic.pRefList[LIST_1][iCount++] = ppLongRefList[i];
301 }301 }
302 pCtx->sRefPic.uiRefCount[LIST_1] = iCount;302 pCtx->sRefPic.uiRefCount[LIST_1] = iCount;
303 return ERR_NONE;303 return ERR_NONE;
304}304}
305 305
306/**306/**
307 * fills the pRefPic.pRefList.307 * fills the pRefPic.pRefList.
308 */308 */
309int32_t WelsInitRefList (PWelsDecoderContext pCtx, int32_t iPoc) {309int32_t WelsInitRefList (PWelsDecoderContext pCtx, int32_t iPoc) {
310 310
311 int32_t err = WelsCheckAndRecoverForFutureDecoding (pCtx);311 int32_t err = WelsCheckAndRecoverForFutureDecoding (pCtx);
312 if (err != ERR_NONE) return err;312 if (err != ERR_NONE) return err;
313 313
314 WrapShortRefPicNum (pCtx);314 WrapShortRefPicNum (pCtx);
315 315
316 PPicture* ppShoreRefList = pCtx->sRefPic.pShortRefList[LIST_0];316 PPicture* ppShoreRefList = pCtx->sRefPic.pShortRefList[LIST_0];
317 PPicture* ppLongRefList = pCtx->sRefPic.pLongRefList[LIST_0];317 PPicture* ppLongRefList = pCtx->sRefPic.pLongRefList[LIST_0];
318 memset (pCtx->sRefPic.pRefList[LIST_0], 0, MAX_DPB_COUNT * sizeof (PPicture));318 memset (pCtx->sRefPic.pRefList[LIST_0], 0, MAX_DPB_COUNT * sizeof (PPicture));
319 319
320 int32_t i, iCount = 0;320 int32_t i, iCount = 0;
321 //short321 //short
322 for (i = 0; i < pCtx->sRefPic.uiShortRefCount[LIST_0]; ++i) {322 for (i = 0; i < pCtx->sRefPic.uiShortRefCount[LIST_0]; ++i) {
323 pCtx->sRefPic.pRefList[LIST_0][iCount++ ] = ppShoreRefList[i];323 pCtx->sRefPic.pRefList[LIST_0][iCount++ ] = ppShoreRefList[i];
324 }324 }
325 325
326 //long326 //long
327 for (i = 0; i < pCtx->sRefPic.uiLongRefCount[LIST_0] ; ++i) {327 for (i = 0; i < pCtx->sRefPic.uiLongRefCount[LIST_0] ; ++i) {
328 pCtx->sRefPic.pRefList[LIST_0][iCount++ ] = ppLongRefList[i];328 pCtx->sRefPic.pRefList[LIST_0][iCount++ ] = ppLongRefList[i];
329 }329 }
330 pCtx->sRefPic.uiRefCount[LIST_0] = iCount;330 pCtx->sRefPic.uiRefCount[LIST_0] = iCount;
331 331
332 return ERR_NONE;332 return ERR_NONE;
333}333}
334 334
335int32_t WelsReorderRefList (PWelsDecoderContext pCtx) {335int32_t WelsReorderRefList (PWelsDecoderContext pCtx) {
336 336
337 if (pCtx->eSliceType == I_SLICE || pCtx->eSliceType == SI_SLICE) {337 if (pCtx->eSliceType == I_SLICE || pCtx->eSliceType == SI_SLICE) {
338 return ERR_NONE;338 return ERR_NONE;
339 }339 }
340 340
341 PRefPicListReorderSyn pRefPicListReorderSyn = pCtx->pCurDqLayer->pRefPicListReordering;341 PRefPicListReorderSyn pRefPicListReorderSyn = pCtx->pCurDqLayer->pRefPicListReordering;
342 PNalUnitHeaderExt pNalHeaderExt = &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt;342 PNalUnitHeaderExt pNalHeaderExt = &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt;
343 PSliceHeader pSliceHeader = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader;343 PSliceHeader pSliceHeader = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader;
344 int32_t ListCount = 1;344 int32_t ListCount = 1;
345 if (pCtx->eSliceType == B_SLICE) ListCount = 2;345 if (pCtx->eSliceType == B_SLICE) ListCount = 2;
346 for (int32_t listIdx = 0; listIdx < ListCount; ++listIdx) {346 for (int32_t listIdx = 0; listIdx < ListCount; ++listIdx) {
347 PPicture pPic = NULL;347 PPicture pPic = NULL;
348 PPicture* ppRefList = pCtx->sRefPic.pRefList[listIdx];348 PPicture* ppRefList = pCtx->sRefPic.pRefList[listIdx];
349 int32_t iMaxRefIdx = pCtx->pSps->iNumRefFrames;349 int32_t iMaxRefIdx = pCtx->pSps->iNumRefFrames;
350 int32_t iRefCount = pCtx->sRefPic.uiRefCount[listIdx];350 int32_t iRefCount = pCtx->sRefPic.uiRefCount[listIdx];
351 int32_t iPredFrameNum = pSliceHeader->iFrameNum;351 int32_t iPredFrameNum = pSliceHeader->iFrameNum;
352 int32_t iMaxPicNum = 1 << pSliceHeader->pSps->uiLog2MaxFrameNum;352 int32_t iMaxPicNum = 1 << pSliceHeader->pSps->uiLog2MaxFrameNum;
353 int32_t iAbsDiffPicNum = -1;353 int32_t iAbsDiffPicNum = -1;
354 int32_t iReorderingIndex = 0;354 int32_t iReorderingIndex = 0;
355 int32_t i = 0;355 int32_t i = 0;
356 356
357 if (iRefCount <= 0) {357 if (iRefCount <= 0) {
358 pCtx->iErrorCode = dsNoParamSets; //No any reference for decoding, SHOULD request IDR358 pCtx->iErrorCode = dsNoParamSets; //No any reference for decoding, SHOULD request IDR
359 return ERR_INFO_REFERENCE_PIC_LOST;359 return ERR_INFO_REFERENCE_PIC_LOST;
360 }360 }
361 361
362 if (pRefPicListReorderSyn->bRefPicListReorderingFlag[listIdx]) {362 if (pRefPicListReorderSyn->bRefPicListReorderingFlag[listIdx]) {
363 while ((iReorderingIndex < iMaxRefIdx)363 while ((iReorderingIndex < iMaxRefIdx)
364 && (pRefPicListReorderSyn->sReorderingSyn[listIdx][iReorderingIndex].uiReorderingOfPicNumsIdc != 3)) {364 && (pRefPicListReorderSyn->sReorderingSyn[listIdx][iReorderingIndex].uiReorderingOfPicNumsIdc != 3)) {
365 uint16_t uiReorderingOfPicNumsIdc =365 uint16_t uiReorderingOfPicNumsIdc =
366 pRefPicListReorderSyn->sReorderingSyn[listIdx][iReorderingIndex].uiReorderingOfPicNumsIdc;366 pRefPicListReorderSyn->sReorderingSyn[listIdx][iReorderingIndex].uiReorderingOfPicNumsIdc;
367 if (uiReorderingOfPicNumsIdc < 2) {367 if (uiReorderingOfPicNumsIdc < 2) {
368 iAbsDiffPicNum = pRefPicListReorderSyn->sReorderingSyn[listIdx][iReorderingIndex].uiAbsDiffPicNumMinus1 + 1;368 iAbsDiffPicNum = pRefPicListReorderSyn->sReorderingSyn[listIdx][iReorderingIndex].uiAbsDiffPicNumMinus1 + 1;
369 369
370 if (uiReorderingOfPicNumsIdc == 0) {370 if (uiReorderingOfPicNumsIdc == 0) {
371 iPredFrameNum -= iAbsDiffPicNum;371 iPredFrameNum -= iAbsDiffPicNum;
372 } else {372 } else {
373 iPredFrameNum += iAbsDiffPicNum;373 iPredFrameNum += iAbsDiffPicNum;
374 }374 }
375 iPredFrameNum &= iMaxPicNum - 1;375 iPredFrameNum &= iMaxPicNum - 1;
376 376
377 for (i = iMaxRefIdx - 1; i >= 0; i--) {377 for (i = iMaxRefIdx - 1; i >= 0; i--) {
378 if (ppRefList[i] != NULL && ppRefList[i]->iFrameNum == iPredFrameNum && !ppRefList[i]->bIsLongRef) {378 if (ppRefList[i] != NULL && ppRefList[i]->iFrameNum == iPredFrameNum && !ppRefList[i]->bIsLongRef) {
379 if ((pNalHeaderExt->uiQualityId == ppRefList[i]->uiQualityId)379 if ((pNalHeaderExt->uiQualityId == ppRefList[i]->uiQualityId)
380 && (pSliceHeader->iSpsId != ppRefList[i]->iSpsId)) { //check;380 && (pSliceHeader->iSpsId != ppRefList[i]->iSpsId)) { //check;
381 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "WelsReorderRefList()::::BASE LAYER::::iSpsId:%d, ref_sps_id:%d",381 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "WelsReorderRefList()::::BASE LAYER::::iSpsId:%d, ref_sps_id:%d",
382 pSliceHeader->iSpsId, ppRefList[i]->iSpsId);382 pSliceHeader->iSpsId, ppRefList[i]->iSpsId);
383 pCtx->iErrorCode = dsNoParamSets; //cross-IDR reference frame selection, SHOULD request IDR.--383 pCtx->iErrorCode = dsNoParamSets; //cross-IDR reference frame selection, SHOULD request IDR.--
384 return ERR_INFO_REFERENCE_PIC_LOST;384 return ERR_INFO_REFERENCE_PIC_LOST;
385 } else {385 } else {
386 break;386 break;
387 }387 }
388 }388 }
389 }389 }
390 390
391 } else if (uiReorderingOfPicNumsIdc == 2) {391 } else if (uiReorderingOfPicNumsIdc == 2) {
392 for (i = iMaxRefIdx - 1; i >= 0; i--) {392 for (i = iMaxRefIdx - 1; i >= 0; i--) {
393 if (ppRefList[i] != NULL && ppRefList[i]->bIsLongRef393 if (ppRefList[i] != NULL && ppRefList[i]->bIsLongRef
394 && ppRefList[i]->iLongTermFrameIdx ==394 && ppRefList[i]->iLongTermFrameIdx ==
395 pRefPicListReorderSyn->sReorderingSyn[listIdx][iReorderingIndex].uiLongTermPicNum) {395 pRefPicListReorderSyn->sReorderingSyn[listIdx][iReorderingIndex].uiLongTermPicNum) {
396 if ((pNalHeaderExt->uiQualityId == ppRefList[i]->uiQualityId)396 if ((pNalHeaderExt->uiQualityId == ppRefList[i]->uiQualityId)
397 && (pSliceHeader->iSpsId != ppRefList[i]->iSpsId)) { //check;397 && (pSliceHeader->iSpsId != ppRefList[i]->iSpsId)) { //check;
398 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "WelsReorderRefList()::::BASE LAYER::::iSpsId:%d, ref_sps_id:%d",398 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "WelsReorderRefList()::::BASE LAYER::::iSpsId:%d, ref_sps_id:%d",
399 pSliceHeader->iSpsId, ppRefList[i]->iSpsId);399 pSliceHeader->iSpsId, ppRefList[i]->iSpsId);
400 pCtx->iErrorCode = dsNoParamSets; //cross-IDR reference frame selection, SHOULD request IDR.--400 pCtx->iErrorCode = dsNoParamSets; //cross-IDR reference frame selection, SHOULD request IDR.--
401 return ERR_INFO_REFERENCE_PIC_LOST;401 return ERR_INFO_REFERENCE_PIC_LOST;
402 } else {402 } else {
403 break;403 break;
404 }404 }
405 }405 }
406 }406 }
407 }407 }
408 if (i < 0) {408 if (i < 0) {
409 return ERR_INFO_REFERENCE_PIC_LOST;409 return ERR_INFO_REFERENCE_PIC_LOST;
410 }410 }
411 pPic = ppRefList[i];411 pPic = ppRefList[i];
412 if (i > iReorderingIndex) {412 if (i > iReorderingIndex) {
413 memmove (&ppRefList[1 + iReorderingIndex], &ppRefList[iReorderingIndex],413 memmove (&ppRefList[1 + iReorderingIndex], &ppRefList[iReorderingIndex],
414 (i - iReorderingIndex) * sizeof (PPicture)); //confirmed_safe_unsafe_usage414 (i - iReorderingIndex) * sizeof (PPicture)); //confirmed_safe_unsafe_usage
415 } else if (i < iReorderingIndex) {415 } else if (i < iReorderingIndex) {
416 memmove (&ppRefList[1 + iReorderingIndex], &ppRefList[iReorderingIndex],416 memmove (&ppRefList[1 + iReorderingIndex], &ppRefList[iReorderingIndex],
417 (iMaxRefIdx - iReorderingIndex) * sizeof (PPicture));417 (iMaxRefIdx - iReorderingIndex) * sizeof (PPicture));
418 }418 }
419 ppRefList[iReorderingIndex] = pPic;419 ppRefList[iReorderingIndex] = pPic;
420 iReorderingIndex++;420 iReorderingIndex++;
421 }421 }
422 }422 }
423 }423 }
424 return ERR_NONE;424 return ERR_NONE;
425}425}
426 426
427//WelsReorderRefList2 is the test code427//WelsReorderRefList2 is the test code
428int32_t WelsReorderRefList2 (PWelsDecoderContext pCtx) {428int32_t WelsReorderRefList2 (PWelsDecoderContext pCtx) {
429 429
430 if (pCtx->eSliceType == I_SLICE || pCtx->eSliceType == SI_SLICE) {430 if (pCtx->eSliceType == I_SLICE || pCtx->eSliceType == SI_SLICE) {
431 return ERR_NONE;431 return ERR_NONE;
432 }432 }
433 433
434 PRefPicListReorderSyn pRefPicListReorderSyn = pCtx->pCurDqLayer->pRefPicListReordering;434 PRefPicListReorderSyn pRefPicListReorderSyn = pCtx->pCurDqLayer->pRefPicListReordering;
435 PSliceHeader pSliceHeader = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader;435 PSliceHeader pSliceHeader = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader;
436 436
437 PPicture* ppShoreRefList = pCtx->sRefPic.pShortRefList[LIST_0];437 PPicture* ppShoreRefList = pCtx->sRefPic.pShortRefList[LIST_0];
438 int32_t iShortRefCount = pCtx->sRefPic.uiShortRefCount[LIST_0];438 int32_t iShortRefCount = pCtx->sRefPic.uiShortRefCount[LIST_0];
439 PPicture* ppLongRefList = pCtx->sRefPic.pLongRefList[LIST_0];439 PPicture* ppLongRefList = pCtx->sRefPic.pLongRefList[LIST_0];
440 int32_t iLongRefCount = pCtx->sRefPic.uiLongRefCount[LIST_0];440 int32_t iLongRefCount = pCtx->sRefPic.uiLongRefCount[LIST_0];
441 int32_t i = 0;441 int32_t i = 0;
442 int32_t j = 0;442 int32_t j = 0;
443 int32_t k = 0;443 int32_t k = 0;
444 int32_t iMaxRefIdx = pCtx->pSps->iNumRefFrames;444 int32_t iMaxRefIdx = pCtx->pSps->iNumRefFrames;
445 const int32_t iCurFrameNum = pSliceHeader->iFrameNum;445 const int32_t iCurFrameNum = pSliceHeader->iFrameNum;
446 const int32_t iMaxPicNum = 1 << pSliceHeader->pSps->uiLog2MaxFrameNum;446 const int32_t iMaxPicNum = 1 << pSliceHeader->pSps->uiLog2MaxFrameNum;
447 int32_t iListCount = 1;447 int32_t iListCount = 1;
448 if (pCtx->eSliceType == B_SLICE) iListCount = 2;448 if (pCtx->eSliceType == B_SLICE) iListCount = 2;
449 for (int32_t listIdx = 0; listIdx < iListCount; ++listIdx) {449 for (int32_t listIdx = 0; listIdx < iListCount; ++listIdx) {
450 PPicture* ppRefList = pCtx->sRefPic.pRefList[listIdx];450 PPicture* ppRefList = pCtx->sRefPic.pRefList[listIdx];
451 int32_t iCount = 0;451 int32_t iCount = 0;
452 int32_t iRefCount = pSliceHeader->uiRefCount[listIdx];452 int32_t iRefCount = pSliceHeader->uiRefCount[listIdx];
453 int32_t iAbsDiffPicNum = -1;453 int32_t iAbsDiffPicNum = -1;
454 454
455 if (pRefPicListReorderSyn->bRefPicListReorderingFlag[listIdx]) {455 if (pRefPicListReorderSyn->bRefPicListReorderingFlag[listIdx]) {
456 int32_t iPredFrameNum = iCurFrameNum;456 int32_t iPredFrameNum = iCurFrameNum;
457 for (i = 0; pRefPicListReorderSyn->sReorderingSyn[listIdx][i].uiReorderingOfPicNumsIdc != 3; i++) {457 for (i = 0; pRefPicListReorderSyn->sReorderingSyn[listIdx][i].uiReorderingOfPicNumsIdc != 3; i++) {
458 if (iCount >= iMaxRefIdx)458 if (iCount >= iMaxRefIdx)
459 break;459 break;
460 460
461 for (j = iRefCount; j > iCount; j--)461 for (j = iRefCount; j > iCount; j--)
462 ppRefList[j] = ppRefList[j - 1];462 ppRefList[j] = ppRefList[j - 1];
463 463
464 uint16_t uiReorderingOfPicNumsIdc =464 uint16_t uiReorderingOfPicNumsIdc =
465 pRefPicListReorderSyn->sReorderingSyn[listIdx][i].uiReorderingOfPicNumsIdc;465 pRefPicListReorderSyn->sReorderingSyn[listIdx][i].uiReorderingOfPicNumsIdc;
466 466
467 if (uiReorderingOfPicNumsIdc < 2) { // reorder short references467 if (uiReorderingOfPicNumsIdc < 2) { // reorder short references
468 iAbsDiffPicNum = (int32_t) (pRefPicListReorderSyn->sReorderingSyn[listIdx][i].uiAbsDiffPicNumMinus1 + 1);468 iAbsDiffPicNum = (int32_t) (pRefPicListReorderSyn->sReorderingSyn[listIdx][i].uiAbsDiffPicNumMinus1 + 1);
469 if (uiReorderingOfPicNumsIdc == 0) {469 if (uiReorderingOfPicNumsIdc == 0) {
470 if (iPredFrameNum - iAbsDiffPicNum < 0)470 if (iPredFrameNum - iAbsDiffPicNum < 0)
471 iPredFrameNum -= (iAbsDiffPicNum - iMaxPicNum);471 iPredFrameNum -= (iAbsDiffPicNum - iMaxPicNum);
472 else472 else
473 iPredFrameNum -= iAbsDiffPicNum;473 iPredFrameNum -= iAbsDiffPicNum;
474 } else {474 } else {
475 if (iPredFrameNum + iAbsDiffPicNum >= iMaxPicNum)475 if (iPredFrameNum + iAbsDiffPicNum >= iMaxPicNum)
476 iPredFrameNum += (iAbsDiffPicNum - iMaxPicNum);476 iPredFrameNum += (iAbsDiffPicNum - iMaxPicNum);
477 else477 else
478 iPredFrameNum += iAbsDiffPicNum;478 iPredFrameNum += iAbsDiffPicNum;
479 }479 }
480 480
481 if (iPredFrameNum > iCurFrameNum) {481 if (iPredFrameNum > iCurFrameNum) {
482 iPredFrameNum -= iMaxPicNum;482 iPredFrameNum -= iMaxPicNum;
483 }483 }
484 484
485 for (j = 0; j < iShortRefCount; j++) {485 for (j = 0; j < iShortRefCount; j++) {
486 if (ppShoreRefList[j]) {486 if (ppShoreRefList[j]) {
487 if (ppShoreRefList[j]->iFrameWrapNum == iPredFrameNum) {487 if (ppShoreRefList[j]->iFrameWrapNum == iPredFrameNum) {
488 ppRefList[iCount++] = ppShoreRefList[j];488 ppRefList[iCount++] = ppShoreRefList[j];
489 break;489 break;
490 }490 }
491 }491 }
492 }492 }
493 k = iCount;493 k = iCount;
494 for (j = k; j <= iRefCount; j++) {494 for (j = k; j <= iRefCount; j++) {
495 if (ppRefList[j] != NULL) {495 if (ppRefList[j] != NULL) {
496 if (ppRefList[j]->bIsLongRef || ppRefList[j]->iFrameWrapNum != iPredFrameNum)496 if (ppRefList[j]->bIsLongRef || ppRefList[j]->iFrameWrapNum != iPredFrameNum)
497 ppRefList[k++] = ppRefList[j];497 ppRefList[k++] = ppRefList[j];
498 }498 }
499 }499 }
500 } else { // reorder long term references uiReorderingOfPicNumsIdc == 2500 } else { // reorder long term references uiReorderingOfPicNumsIdc == 2
501 iPredFrameNum = pRefPicListReorderSyn->sReorderingSyn[listIdx][i].uiLongTermPicNum;501 iPredFrameNum = pRefPicListReorderSyn->sReorderingSyn[listIdx][i].uiLongTermPicNum;
502 for (j = 0; j < iLongRefCount; j++) {502 for (j = 0; j < iLongRefCount; j++) {
503 if (ppLongRefList[j] != NULL) {503 if (ppLongRefList[j] != NULL) {
504 if (ppLongRefList[j]->uiLongTermPicNum == (uint32_t)iPredFrameNum) {504 if (ppLongRefList[j]->uiLongTermPicNum == (uint32_t)iPredFrameNum) {
505 ppRefList[iCount++] = ppLongRefList[j];505 ppRefList[iCount++] = ppLongRefList[j];
506 break;506 break;
507 }507 }
508 }508 }
509 }509 }
510 k = iCount;510 k = iCount;
511 for (j = k; j <= iRefCount; j++) {511 for (j = k; j <= iRefCount; j++) {
512 if (ppRefList[j] != NULL) {512 if (ppRefList[j] != NULL) {
513 if (!ppRefList[j]->bIsLongRef || ppLongRefList[j]->uiLongTermPicNum != (uint32_t)iPredFrameNum)513 if (!ppRefList[j]->bIsLongRef || ppLongRefList[j]->uiLongTermPicNum != (uint32_t)iPredFrameNum)
514 ppRefList[k++] = ppRefList[j];514 ppRefList[k++] = ppRefList[j];
515 }515 }
516 }516 }
517 }517 }
518 }518 }
519 }519 }
520 520
521 for (i = WELS_MAX (1, WELS_MAX (iCount, pCtx->sRefPic.uiRefCount[listIdx])); i < iRefCount; i++)521 for (i = WELS_MAX (1, WELS_MAX (iCount, pCtx->sRefPic.uiRefCount[listIdx])); i < iRefCount; i++)
522 ppRefList[i] = ppRefList[i - 1];522 ppRefList[i] = ppRefList[i - 1];
523 pCtx->sRefPic.uiRefCount[listIdx] = (uint8_t)WELS_MIN (WELS_MAX (iCount, pCtx->sRefPic.uiRefCount[listIdx]), iRefCount);523 pCtx->sRefPic.uiRefCount[listIdx] = (uint8_t)WELS_MIN (WELS_MAX (iCount, pCtx->sRefPic.uiRefCount[listIdx]), iRefCount);
524 }524 }
525 return ERR_NONE;525 return ERR_NONE;
526}526}
527 527
528int32_t WelsMarkAsRef (PWelsDecoderContext pCtx) {528int32_t WelsMarkAsRef (PWelsDecoderContext pCtx) {
529 PRefPic pRefPic = &pCtx->sRefPic;529 PRefPic pRefPic = &pCtx->sRefPic;
530 PRefPicMarking pRefPicMarking = pCtx->pCurDqLayer->pRefPicMarking;530 PRefPicMarking pRefPicMarking = pCtx->pCurDqLayer->pRefPicMarking;
531 PAccessUnit pCurAU = pCtx->pAccessUnitList;531 PAccessUnit pCurAU = pCtx->pAccessUnitList;
532 bool bIsIDRAU = false;532 bool bIsIDRAU = false;
533 uint32_t j;533 uint32_t j;
534 534
535 int32_t iRet = ERR_NONE;535 int32_t iRet = ERR_NONE;
536 536
537 pCtx->pDec->uiQualityId = pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt.uiQualityId;537 pCtx->pDec->uiQualityId = pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt.uiQualityId;
538 pCtx->pDec->uiTemporalId = pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt.uiTemporalId;538 pCtx->pDec->uiTemporalId = pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt.uiTemporalId;
539 pCtx->pDec->iSpsId = pCtx->pSps->iSpsId;539 pCtx->pDec->iSpsId = pCtx->pSps->iSpsId;
540 pCtx->pDec->iPpsId = pCtx->pPps->iPpsId;540 pCtx->pDec->iPpsId = pCtx->pPps->iPpsId;
541 541
542 for (j = pCurAU->uiStartPos; j <= pCurAU->uiEndPos; j++) {542 for (j = pCurAU->uiStartPos; j <= pCurAU->uiEndPos; j++) {
543 if (pCurAU->pNalUnitsList[j]->sNalHeaderExt.sNalUnitHeader.eNalUnitType == NAL_UNIT_CODED_SLICE_IDR543 if (pCurAU->pNalUnitsList[j]->sNalHeaderExt.sNalUnitHeader.eNalUnitType == NAL_UNIT_CODED_SLICE_IDR
544 || pCurAU->pNalUnitsList[j]->sNalHeaderExt.bIdrFlag) {544 || pCurAU->pNalUnitsList[j]->sNalHeaderExt.bIdrFlag) {
545 bIsIDRAU = true;545 bIsIDRAU = true;
546 break;546 break;
547 }547 }
548 }548 }
549 if (bIsIDRAU) {549 if (bIsIDRAU) {
550 if (pRefPicMarking->bLongTermRefFlag) {550 if (pRefPicMarking->bLongTermRefFlag) {
551 pCtx->sRefPic.iMaxLongTermFrameIdx = 0;551 pCtx->sRefPic.iMaxLongTermFrameIdx = 0;
552 AddLongTermToList (pRefPic, pCtx->pDec, 0, 0);552 AddLongTermToList (pRefPic, pCtx->pDec, 0, 0);
553 } else {553 } else {
554 pCtx->sRefPic.iMaxLongTermFrameIdx = -1;554 pCtx->sRefPic.iMaxLongTermFrameIdx = -1;
555 }555 }
556 } else {556 } else {
557 if (pRefPicMarking->bAdaptiveRefPicMarkingModeFlag) {557 if (pRefPicMarking->bAdaptiveRefPicMarkingModeFlag) {
558 iRet = MMCO (pCtx, pRefPicMarking);558 iRet = MMCO (pCtx, pRefPicMarking);
559 if (iRet != ERR_NONE) {559 if (iRet != ERR_NONE) {
560 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {560 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {
561 iRet = RemainOneBufferInDpbForEC (pCtx);561 iRet = RemainOneBufferInDpbForEC (pCtx);
562 WELS_VERIFY_RETURN_IF (iRet, iRet);562 WELS_VERIFY_RETURN_IF (iRet, iRet);
563 } else {563 } else {
564 return iRet;564 return iRet;
565 }565 }
566 }566 }
567 567
568 if (pCtx->bLastHasMmco5) {568 if (pCtx->bLastHasMmco5) {
569 pCtx->pDec->iFrameNum = 0;569 pCtx->pDec->iFrameNum = 0;
570 pCtx->pDec->iFramePoc = 0;570 pCtx->pDec->iFramePoc = 0;
571 }571 }
572 572
573 } else {573 } else {
574 iRet = SlidingWindow (pCtx);574 iRet = SlidingWindow (pCtx);
575 if (iRet != ERR_NONE) {575 if (iRet != ERR_NONE) {
576 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {576 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {
577 iRet = RemainOneBufferInDpbForEC (pCtx);577 iRet = RemainOneBufferInDpbForEC (pCtx);
578 WELS_VERIFY_RETURN_IF (iRet, iRet);578 WELS_VERIFY_RETURN_IF (iRet, iRet);
579 } else {579 } else {
580 return iRet;580 return iRet;
581 }581 }
582 }582 }
583 }583 }
584 }584 }
585 585
586 if (!pCtx->pDec->bIsLongRef) {586 if (!pCtx->pDec->bIsLongRef) {
587 if (pRefPic->uiLongRefCount[LIST_0] + pRefPic->uiShortRefCount[LIST_0] >= WELS_MAX (1, pCtx->pSps->iNumRefFrames)) {587 if (pRefPic->uiLongRefCount[LIST_0] + pRefPic->uiShortRefCount[LIST_0] >= WELS_MAX (1, pCtx->pSps->iNumRefFrames)) {
588 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {588 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {
589 iRet = RemainOneBufferInDpbForEC (pCtx);589 iRet = RemainOneBufferInDpbForEC (pCtx);
590 WELS_VERIFY_RETURN_IF (iRet, iRet);590 WELS_VERIFY_RETURN_IF (iRet, iRet);
591 } else {591 } else {
592 return ERR_INFO_INVALID_MMCO_REF_NUM_OVERFLOW;592 return ERR_INFO_INVALID_MMCO_REF_NUM_OVERFLOW;
593 }593 }
594 }594 }
595 iRet = AddShortTermToList (pRefPic, pCtx->pDec);595 iRet = AddShortTermToList (pRefPic, pCtx->pDec);
596 }596 }
597 597
598 return iRet;598 return iRet;
599}599}
600 600
601static int32_t MMCO (PWelsDecoderContext pCtx, PRefPicMarking pRefPicMarking) {601static int32_t MMCO (PWelsDecoderContext pCtx, PRefPicMarking pRefPicMarking) {
602 PSps pSps = pCtx->pCurDqLayer->sLayerInfo.pSps;602 PSps pSps = pCtx->pCurDqLayer->sLayerInfo.pSps;
603 int32_t i = 0;603 int32_t i = 0;
604 int32_t iRet = ERR_NONE;604 int32_t iRet = ERR_NONE;
605 for (i = 0; i < MAX_MMCO_COUNT && pRefPicMarking->sMmcoRef[i].uiMmcoType != MMCO_END; i++) {605 for (i = 0; i < MAX_MMCO_COUNT && pRefPicMarking->sMmcoRef[i].uiMmcoType != MMCO_END; i++) {
606 uint32_t uiMmcoType = pRefPicMarking->sMmcoRef[i].uiMmcoType;606 uint32_t uiMmcoType = pRefPicMarking->sMmcoRef[i].uiMmcoType;
607 int32_t iShortFrameNum = (pCtx->iFrameNum - pRefPicMarking->sMmcoRef[i].iDiffOfPicNum) & ((607 int32_t iShortFrameNum = (pCtx->iFrameNum - pRefPicMarking->sMmcoRef[i].iDiffOfPicNum) & ((
608 1 << pSps->uiLog2MaxFrameNum) - 1);608 1 << pSps->uiLog2MaxFrameNum) - 1);
609 uint32_t uiLongTermPicNum = pRefPicMarking->sMmcoRef[i].uiLongTermPicNum;609 uint32_t uiLongTermPicNum = pRefPicMarking->sMmcoRef[i].uiLongTermPicNum;
610 int32_t iLongTermFrameIdx = pRefPicMarking->sMmcoRef[i].iLongTermFrameIdx;610 int32_t iLongTermFrameIdx = pRefPicMarking->sMmcoRef[i].iLongTermFrameIdx;
611 int32_t iMaxLongTermFrameIdx = pRefPicMarking->sMmcoRef[i].iMaxLongTermFrameIdx;611 int32_t iMaxLongTermFrameIdx = pRefPicMarking->sMmcoRef[i].iMaxLongTermFrameIdx;
612 if (uiMmcoType > MMCO_LONG) {612 if (uiMmcoType > MMCO_LONG) {
613 return ERR_INFO_INVALID_MMCO_OPCODE_BASE;613 return ERR_INFO_INVALID_MMCO_OPCODE_BASE;
614 }614 }
615 iRet = MMCOProcess (pCtx, uiMmcoType, iShortFrameNum, uiLongTermPicNum, iLongTermFrameIdx, iMaxLongTermFrameIdx);615 iRet = MMCOProcess (pCtx, uiMmcoType, iShortFrameNum, uiLongTermPicNum, iLongTermFrameIdx, iMaxLongTermFrameIdx);
616 if (iRet != ERR_NONE) {616 if (iRet != ERR_NONE) {
617 return iRet;617 return iRet;
618 }618 }
619 }619 }
620 if (i == MAX_MMCO_COUNT) { //although Rec does not handle this condition, we here prohibit too many MMCO op620 if (i == MAX_MMCO_COUNT) { //although Rec does not handle this condition, we here prohibit too many MMCO op
621 return ERR_INFO_INVALID_MMCO_NUM;621 return ERR_INFO_INVALID_MMCO_NUM;
622 }622 }
623 623
624 return ERR_NONE;624 return ERR_NONE;
625}625}
626static int32_t MMCOProcess (PWelsDecoderContext pCtx, uint32_t uiMmcoType,626static int32_t MMCOProcess (PWelsDecoderContext pCtx, uint32_t uiMmcoType,
627 int32_t iShortFrameNum, uint32_t uiLongTermPicNum, int32_t iLongTermFrameIdx, int32_t iMaxLongTermFrameIdx) {627 int32_t iShortFrameNum, uint32_t uiLongTermPicNum, int32_t iLongTermFrameIdx, int32_t iMaxLongTermFrameIdx) {
628 PRefPic pRefPic = &pCtx->sRefPic;628 PRefPic pRefPic = &pCtx->sRefPic;
629 PPicture pPic = NULL;629 PPicture pPic = NULL;
630 int32_t i = 0;630 int32_t i = 0;
631 int32_t iRet = ERR_NONE;631 int32_t iRet = ERR_NONE;
632 632
633 switch (uiMmcoType) {633 switch (uiMmcoType) {
634 case MMCO_SHORT2UNUSED:634 case MMCO_SHORT2UNUSED:
635 pPic = WelsDelShortFromListSetUnref (pRefPic, iShortFrameNum);635 pPic = WelsDelShortFromListSetUnref (pRefPic, iShortFrameNum);
636 if (pPic == NULL) {636 if (pPic == NULL) {
637 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "MMCO_SHORT2UNUSED: delete an empty entry from short term list");637 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "MMCO_SHORT2UNUSED: delete an empty entry from short term list");
638 }638 }
639 break;639 break;
640 case MMCO_LONG2UNUSED:640 case MMCO_LONG2UNUSED:
641 pPic = WelsDelLongFromListSetUnref (pRefPic, uiLongTermPicNum);641 pPic = WelsDelLongFromListSetUnref (pRefPic, uiLongTermPicNum);
642 if (pPic == NULL) {642 if (pPic == NULL) {
643 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "MMCO_LONG2UNUSED: delete an empty entry from long term list");643 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "MMCO_LONG2UNUSED: delete an empty entry from long term list");
644 }644 }
645 break;645 break;
646 case MMCO_SHORT2LONG:646 case MMCO_SHORT2LONG:
647 if (iLongTermFrameIdx > pRefPic->iMaxLongTermFrameIdx) {647 if (iLongTermFrameIdx > pRefPic->iMaxLongTermFrameIdx) {
648 return ERR_INFO_INVALID_MMCO_LONG_TERM_IDX_EXCEED_MAX;648 return ERR_INFO_INVALID_MMCO_LONG_TERM_IDX_EXCEED_MAX;
649 }649 }
650 pPic = WelsDelShortFromList (pRefPic, iShortFrameNum);650 pPic = WelsDelShortFromList (pRefPic, iShortFrameNum);
651 if (pPic == NULL) {651 if (pPic == NULL) {
652 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "MMCO_LONG2LONG: delete an empty entry from short term list");652 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "MMCO_LONG2LONG: delete an empty entry from short term list");
653 break;653 break;
654 }654 }
655 WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx);655 WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx);
656#ifdef LONG_TERM_REF656#ifdef LONG_TERM_REF
657 pCtx->bCurAuContainLtrMarkSeFlag = true;657 pCtx->bCurAuContainLtrMarkSeFlag = true;
658 pCtx->iFrameNumOfAuMarkedLtr = iShortFrameNum;658 pCtx->iFrameNumOfAuMarkedLtr = iShortFrameNum;
659 WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, "ex_mark_avc():::MMCO_SHORT2LONG:::LTR marking....iFrameNum: %d",659 WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, "ex_mark_avc():::MMCO_SHORT2LONG:::LTR marking....iFrameNum: %d",
660 pCtx->iFrameNumOfAuMarkedLtr);660 pCtx->iFrameNumOfAuMarkedLtr);
661#endif661#endif
662 662
663 MarkAsLongTerm (pRefPic, iShortFrameNum, iLongTermFrameIdx, uiLongTermPicNum);663 MarkAsLongTerm (pRefPic, iShortFrameNum, iLongTermFrameIdx, uiLongTermPicNum);
664 break;664 break;
665 case MMCO_SET_MAX_LONG:665 case MMCO_SET_MAX_LONG:
666 pRefPic->iMaxLongTermFrameIdx = iMaxLongTermFrameIdx;666 pRefPic->iMaxLongTermFrameIdx = iMaxLongTermFrameIdx;
667 for (i = 0 ; i < pRefPic->uiLongRefCount[LIST_0]; i++) {667 for (i = 0 ; i < pRefPic->uiLongRefCount[LIST_0]; i++) {
668 if (pRefPic->pLongRefList[LIST_0][i]->iLongTermFrameIdx > pRefPic->iMaxLongTermFrameIdx) {668 if (pRefPic->pLongRefList[LIST_0][i]->iLongTermFrameIdx > pRefPic->iMaxLongTermFrameIdx) {
669 WelsDelLongFromListSetUnref (pRefPic, pRefPic->pLongRefList[LIST_0][i]->iLongTermFrameIdx);669 WelsDelLongFromListSetUnref (pRefPic, pRefPic->pLongRefList[LIST_0][i]->iLongTermFrameIdx);
670 }670 }
671 }671 }
672 break;672 break;
673 case MMCO_RESET:673 case MMCO_RESET:
674 WelsResetRefPic (pCtx);674 WelsResetRefPic (pCtx);
675 pCtx->bLastHasMmco5 = true;675 pCtx->bLastHasMmco5 = true;
676 break;676 break;
677 case MMCO_LONG:677 case MMCO_LONG:
678 if (iLongTermFrameIdx > pRefPic->iMaxLongTermFrameIdx) {678 if (iLongTermFrameIdx > pRefPic->iMaxLongTermFrameIdx) {
679 return ERR_INFO_INVALID_MMCO_LONG_TERM_IDX_EXCEED_MAX;679 return ERR_INFO_INVALID_MMCO_LONG_TERM_IDX_EXCEED_MAX;
680 }680 }
681 WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx);681 WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx);
682 if (pRefPic->uiLongRefCount[LIST_0] + pRefPic->uiShortRefCount[LIST_0] >= WELS_MAX (1, pCtx->pSps->iNumRefFrames)) {682 if (pRefPic->uiLongRefCount[LIST_0] + pRefPic->uiShortRefCount[LIST_0] >= WELS_MAX (1, pCtx->pSps->iNumRefFrames)) {
683 return ERR_INFO_INVALID_MMCO_REF_NUM_OVERFLOW;683 return ERR_INFO_INVALID_MMCO_REF_NUM_OVERFLOW;
684 }684 }
685#ifdef LONG_TERM_REF685#ifdef LONG_TERM_REF
686 pCtx->bCurAuContainLtrMarkSeFlag = true;686 pCtx->bCurAuContainLtrMarkSeFlag = true;
687 pCtx->iFrameNumOfAuMarkedLtr = pCtx->iFrameNum;687 pCtx->iFrameNumOfAuMarkedLtr = pCtx->iFrameNum;
688 WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, "ex_mark_avc():::MMCO_LONG:::LTR marking....iFrameNum: %d",688 WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, "ex_mark_avc():::MMCO_LONG:::LTR marking....iFrameNum: %d",
689 pCtx->iFrameNum);689 pCtx->iFrameNum);
690#endif690#endif
691 iRet = AddLongTermToList (pRefPic, pCtx->pDec, iLongTermFrameIdx, uiLongTermPicNum);691 iRet = AddLongTermToList (pRefPic, pCtx->pDec, iLongTermFrameIdx, uiLongTermPicNum);
692 break;692 break;
693 default :693 default :
694 break;694 break;
695 }695 }
696 696
697 return iRet;697 return iRet;
698}698}
699 699
700static int32_t SlidingWindow (PWelsDecoderContext pCtx) {700static int32_t SlidingWindow (PWelsDecoderContext pCtx) {
701 PRefPic pRefPic = &pCtx->sRefPic;701 PRefPic pRefPic = &pCtx->sRefPic;
702 PPicture pPic = NULL;702 PPicture pPic = NULL;
703 int32_t i = 0;703 int32_t i = 0;
704 704
705 if (pCtx->sRefPic.uiShortRefCount[LIST_0] + pCtx->sRefPic.uiLongRefCount[LIST_0] >= pCtx->pSps->iNumRefFrames) {705 if (pCtx->sRefPic.uiShortRefCount[LIST_0] + pCtx->sRefPic.uiLongRefCount[LIST_0] >= pCtx->pSps->iNumRefFrames) {
706 if (pCtx->sRefPic.uiShortRefCount[LIST_0] == 0) {706 if (pCtx->sRefPic.uiShortRefCount[LIST_0] == 0) {
707 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "No reference picture in short term list when sliding window");707 WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "No reference picture in short term list when sliding window");
708 return ERR_INFO_INVALID_MMCO_REF_NUM_NOT_ENOUGH;708 return ERR_INFO_INVALID_MMCO_REF_NUM_NOT_ENOUGH;
709 }709 }
710 for (i = pRefPic->uiShortRefCount[LIST_0] - 1; i >= 0; i--) {710 for (i = pRefPic->uiShortRefCount[LIST_0] - 1; i >= 0; i--) {
711 pPic = WelsDelShortFromList (pRefPic, pRefPic->pShortRefList[LIST_0][i]->iFrameNum);711 pPic = WelsDelShortFromList (pRefPic, pRefPic->pShortRefList[LIST_0][i]->iFrameNum);
712 if (pPic) {712 if (pPic) {
713 SetUnRef (pPic);713 SetUnRef (pPic);
714 break;714 break;
715 } else {715 } else {
716 return ERR_INFO_INVALID_MMCO_REF_NUM_OVERFLOW;716 return ERR_INFO_INVALID_MMCO_REF_NUM_OVERFLOW;
717 }717 }
718 }718 }
719 }719 }
720 return ERR_NONE;720 return ERR_NONE;
721}721}
722 722
723static PPicture WelsDelShortFromList (PRefPic pRefPic, int32_t iFrameNum) {723static PPicture WelsDelShortFromList (PRefPic pRefPic, int32_t iFrameNum) {
724 int32_t i = 0;724 int32_t i = 0;
725 int32_t iMoveSize = 0;725 int32_t iMoveSize = 0;
726 PPicture pPic = NULL;726 PPicture pPic = NULL;
727 727
728 for (i = 0; i < pRefPic->uiShortRefCount[LIST_0]; i++) {728 for (i = 0; i < pRefPic->uiShortRefCount[LIST_0]; i++) {
729 if (pRefPic->pShortRefList[LIST_0][i]->iFrameNum == iFrameNum) {729 if (pRefPic->pShortRefList[LIST_0][i]->iFrameNum == iFrameNum) {
730 iMoveSize = pRefPic->uiShortRefCount[LIST_0] - i - 1;730 iMoveSize = pRefPic->uiShortRefCount[LIST_0] - i - 1;
731 pRefPic->pShortRefList[LIST_0][i]->bUsedAsRef = false;731 pRefPic->pShortRefList[LIST_0][i]->bUsedAsRef = false;
732 pPic = pRefPic->pShortRefList[LIST_0][i];732 pPic = pRefPic->pShortRefList[LIST_0][i];
733 pRefPic->pShortRefList[LIST_0][i] = NULL;733 pRefPic->pShortRefList[LIST_0][i] = NULL;
734 if (iMoveSize > 0) {734 if (iMoveSize > 0) {
735 memmove (&pRefPic->pShortRefList[LIST_0][i], &pRefPic->pShortRefList[LIST_0][i + 1],735 memmove (&pRefPic->pShortRefList[LIST_0][i], &pRefPic->pShortRefList[LIST_0][i + 1],
736 iMoveSize * sizeof (PPicture)); //confirmed_safe_unsafe_usage736 iMoveSize * sizeof (PPicture)); //confirmed_safe_unsafe_usage
737 }737 }
738 pRefPic->uiShortRefCount[LIST_0]--;738 pRefPic->uiShortRefCount[LIST_0]--;
739 pRefPic->pShortRefList[LIST_0][pRefPic->uiShortRefCount[LIST_0]] = NULL;739 pRefPic->pShortRefList[LIST_0][pRefPic->uiShortRefCount[LIST_0]] = NULL;
740 break;740 break;
741 }741 }
742 }742 }
743 743
744 return pPic;744 return pPic;
745}745}
746 746
747static PPicture WelsDelShortFromListSetUnref (PRefPic pRefPic, int32_t iFrameNum) {747static PPicture WelsDelShortFromListSetUnref (PRefPic pRefPic, int32_t iFrameNum) {
748 PPicture pPic = WelsDelShortFromList (pRefPic, iFrameNum);748 PPicture pPic = WelsDelShortFromList (pRefPic, iFrameNum);
749 if (pPic) {749 if (pPic) {
750 SetUnRef (pPic);750 SetUnRef (pPic);
751 }751 }
752 return pPic;752 return pPic;
753}753}
754 754
755static PPicture WelsDelLongFromList (PRefPic pRefPic, uint32_t uiLongTermFrameIdx) {755static PPicture WelsDelLongFromList (PRefPic pRefPic, uint32_t uiLongTermFrameIdx) {
756 PPicture pPic = NULL;756 PPicture pPic = NULL;
757 int32_t i = 0;757 int32_t i = 0;
758 for (i = 0; i < pRefPic->uiLongRefCount[LIST_0]; i++) {758 for (i = 0; i < pRefPic->uiLongRefCount[LIST_0]; i++) {
759 pPic = pRefPic->pLongRefList[LIST_0][i];759 pPic = pRefPic->pLongRefList[LIST_0][i];
760 if (pPic->iLongTermFrameIdx == (int32_t)uiLongTermFrameIdx) {760 if (pPic->iLongTermFrameIdx == (int32_t)uiLongTermFrameIdx) {
761 int32_t iMoveSize = pRefPic->uiLongRefCount[LIST_0] - i - 1;761 int32_t iMoveSize = pRefPic->uiLongRefCount[LIST_0] - i - 1;
762 pPic->bUsedAsRef = false;762 pPic->bUsedAsRef = false;
763 pPic->bIsLongRef = false;763 pPic->bIsLongRef = false;
764 if (iMoveSize > 0) {764 if (iMoveSize > 0) {
765 memmove (&pRefPic->pLongRefList[LIST_0][i], &pRefPic->pLongRefList[LIST_0][i + 1],765 memmove (&pRefPic->pLongRefList[LIST_0][i], &pRefPic->pLongRefList[LIST_0][i + 1],
766 iMoveSize * sizeof (PPicture)); //confirmed_safe_unsafe_usage766 iMoveSize * sizeof (PPicture)); //confirmed_safe_unsafe_usage
767 }767 }
768 pRefPic->uiLongRefCount[LIST_0]--;768 pRefPic->uiLongRefCount[LIST_0]--;
769 pRefPic->pLongRefList[LIST_0][pRefPic->uiLongRefCount[LIST_0]] = NULL;769 pRefPic->pLongRefList[LIST_0][pRefPic->uiLongRefCount[LIST_0]] = NULL;
770 return pPic;770 return pPic;
771 }771 }
772 }772 }
773 return NULL;773 return NULL;
774}774}
775 775
776static PPicture WelsDelLongFromListSetUnref (PRefPic pRefPic, uint32_t uiLongTermFrameIdx) {776static PPicture WelsDelLongFromListSetUnref (PRefPic pRefPic, uint32_t uiLongTermFrameIdx) {
777 PPicture pPic = WelsDelLongFromList (pRefPic, uiLongTermFrameIdx);777 PPicture pPic = WelsDelLongFromList (pRefPic, uiLongTermFrameIdx);
778 if (pPic) {778 if (pPic) {
779 SetUnRef (pPic);779 SetUnRef (pPic);
780 }780 }
781 return pPic;781 return pPic;
782}782}
783 783
784static int32_t AddShortTermToList (PRefPic pRefPic, PPicture pPic) {784static int32_t AddShortTermToList (PRefPic pRefPic, PPicture pPic) {
785 pPic->bUsedAsRef = true;785 pPic->bUsedAsRef = true;
786 pPic->bIsLongRef = false;786 pPic->bIsLongRef = false;
787 pPic->iLongTermFrameIdx = -1;787 pPic->iLongTermFrameIdx = -1;
788 if (pRefPic->uiShortRefCount[LIST_0] > 0) {788 if (pRefPic->uiShortRefCount[LIST_0] > 0) {
789 // Check the duplicate frame_num in short ref list789 // Check the duplicate frame_num in short ref list
790 for (int32_t iPos = 0; iPos < pRefPic->uiShortRefCount[LIST_0]; iPos++) {790 for (int32_t iPos = 0; iPos < pRefPic->uiShortRefCount[LIST_0]; iPos++) {
791 if (pPic->iFrameNum == pRefPic->pShortRefList[LIST_0][iPos]->iFrameNum) {791 if (pPic->iFrameNum == pRefPic->pShortRefList[LIST_0][iPos]->iFrameNum) {
792 // Replace the previous ref pic with the new one with the same frame_num792 // Replace the previous ref pic with the new one with the same frame_num
793 pRefPic->pShortRefList[LIST_0][iPos] = pPic;793 pRefPic->pShortRefList[LIST_0][iPos] = pPic;
794 return ERR_INFO_DUPLICATE_FRAME_NUM;794 return ERR_INFO_DUPLICATE_FRAME_NUM;
795 }795 }
796 }796 }
797 797
798 memmove (&pRefPic->pShortRefList[LIST_0][1], &pRefPic->pShortRefList[LIST_0][0],798 memmove (&pRefPic->pShortRefList[LIST_0][1], &pRefPic->pShortRefList[LIST_0][0],
799 pRefPic->uiShortRefCount[LIST_0]*sizeof (PPicture));//confirmed_safe_unsafe_usage799 pRefPic->uiShortRefCount[LIST_0]*sizeof (PPicture));//confirmed_safe_unsafe_usage
800 }800 }
801 pRefPic->pShortRefList[LIST_0][0] = pPic;801 pRefPic->pShortRefList[LIST_0][0] = pPic;
802 pRefPic->uiShortRefCount[LIST_0]++;802 pRefPic->uiShortRefCount[LIST_0]++;
803 return ERR_NONE;803 return ERR_NONE;
804}804}
805 805
806static int32_t AddLongTermToList (PRefPic pRefPic, PPicture pPic, int32_t iLongTermFrameIdx,806static int32_t AddLongTermToList (PRefPic pRefPic, PPicture pPic, int32_t iLongTermFrameIdx,
807 uint32_t uiLongTermPicNum) {807 uint32_t uiLongTermPicNum) {
808 int32_t i = 0;808 int32_t i = 0;
809 809
810 pPic->bUsedAsRef = true;810 pPic->bUsedAsRef = true;
811 pPic->bIsLongRef = true;811 pPic->bIsLongRef = true;
812 pPic->iLongTermFrameIdx = iLongTermFrameIdx;812 pPic->iLongTermFrameIdx = iLongTermFrameIdx;
813 pPic->uiLongTermPicNum = uiLongTermPicNum;813 pPic->uiLongTermPicNum = uiLongTermPicNum;
814 if (pRefPic->uiLongRefCount[LIST_0] == 0) {814 if (pRefPic->uiLongRefCount[LIST_0] == 0) {
815 pRefPic->pLongRefList[LIST_0][pRefPic->uiLongRefCount[LIST_0]] = pPic;815 pRefPic->pLongRefList[LIST_0][pRefPic->uiLongRefCount[LIST_0]] = pPic;
816 } else {816 } else {
817 for (i = 0; i < pRefPic->uiLongRefCount[LIST_0]; i++) {817 for (i = 0; i < pRefPic->uiLongRefCount[LIST_0]; i++) {
818 if (pRefPic->pLongRefList[LIST_0][i]->iLongTermFrameIdx > pPic->iLongTermFrameIdx) {818 if (pRefPic->pLongRefList[LIST_0][i]->iLongTermFrameIdx > pPic->iLongTermFrameIdx) {
819 break;819 break;
820 }820 }
821 }821 }
822 memmove (&pRefPic->pLongRefList[LIST_0][i + 1], &pRefPic->pLongRefList[LIST_0][i],822 memmove (&pRefPic->pLongRefList[LIST_0][i + 1], &pRefPic->pLongRefList[LIST_0][i],
823 (pRefPic->uiLongRefCount[LIST_0] - i)*sizeof (PPicture)); //confirmed_safe_unsafe_usage823 (pRefPic->uiLongRefCount[LIST_0] - i)*sizeof (PPicture)); //confirmed_safe_unsafe_usage
824 pRefPic->pLongRefList[LIST_0][i] = pPic;824 pRefPic->pLongRefList[LIST_0][i] = pPic;
825 }825 }
826 826
827 pRefPic->uiLongRefCount[LIST_0]++;827 pRefPic->uiLongRefCount[LIST_0]++;
828 return ERR_NONE;828 return ERR_NONE;
829}829}
830 830
831static int32_t MarkAsLongTerm (PRefPic pRefPic, int32_t iFrameNum, int32_t iLongTermFrameIdx,831static int32_t MarkAsLongTerm (PRefPic pRefPic, int32_t iFrameNum, int32_t iLongTermFrameIdx,
832 uint32_t uiLongTermPicNum) {832 uint32_t uiLongTermPicNum) {
833 PPicture pPic = NULL;833 PPicture pPic = NULL;
834 int32_t i = 0;834 int32_t i = 0;
835 int32_t iRet = ERR_NONE;835 int32_t iRet = ERR_NONE;
836 WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx);836 WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx);
837 837
838 for (i = 0; i < pRefPic->uiRefCount[LIST_0]; i++) {838 for (i = 0; i < pRefPic->uiRefCount[LIST_0]; i++) {
839 pPic = pRefPic->pRefList[LIST_0][i];839 pPic = pRefPic->pRefList[LIST_0][i];
840 if (pPic->iFrameNum == iFrameNum && !pPic->bIsLongRef) {840 if (pPic->iFrameNum == iFrameNum && !pPic->bIsLongRef) {
841 iRet = AddLongTermToList (pRefPic, pPic, iLongTermFrameIdx, uiLongTermPicNum);841 iRet = AddLongTermToList (pRefPic, pPic, iLongTermFrameIdx, uiLongTermPicNum);
842 break;842 break;
843 }843 }
844 }844 }
845 845
846 return iRet;846 return iRet;
847}847}
848 848
849#ifdef LONG_TERM_REF849#ifdef LONG_TERM_REF
850int32_t GetLTRFrameIndex (PRefPic pRefPic, int32_t iAncLTRFrameNum) {850int32_t GetLTRFrameIndex (PRefPic pRefPic, int32_t iAncLTRFrameNum) {
851 int32_t iLTRFrameIndex = -1;851 int32_t iLTRFrameIndex = -1;
852 PPicture pPic;852 PPicture pPic;
853 for (int i = 0; i < pRefPic->uiLongRefCount[0]; ++i) {853 for (int i = 0; i < pRefPic->uiLongRefCount[0]; ++i) {
854 pPic = pRefPic->pLongRefList[LIST_0][i];854 pPic = pRefPic->pLongRefList[LIST_0][i];
855 if (pPic->iFrameNum == iAncLTRFrameNum) {855 if (pPic->iFrameNum == iAncLTRFrameNum) {
856 return (pPic->iLongTermFrameIdx);856 return (pPic->iLongTermFrameIdx);
857 }857 }
858 }858 }
859 return iLTRFrameIndex;859 return iLTRFrameIndex;
860}860}
861#endif861#endif
862 862
863static int32_t RemainOneBufferInDpbForEC (PWelsDecoderContext pCtx) {863static int32_t RemainOneBufferInDpbForEC (PWelsDecoderContext pCtx) {
864 int32_t iRet = ERR_NONE;864 int32_t iRet = ERR_NONE;
865 PRefPic pRefPic = &pCtx->sRefPic;865 PRefPic pRefPic = &pCtx->sRefPic;
866 if (pRefPic->uiShortRefCount[0] + pRefPic->uiLongRefCount[0] < pCtx->pSps->iNumRefFrames)866 if (pRefPic->uiShortRefCount[0] + pRefPic->uiLongRefCount[0] < pCtx->pSps->iNumRefFrames)
867 return iRet;867 return iRet;
868 868
869 if (pRefPic->uiShortRefCount[0] > 0) {869 if (pRefPic->uiShortRefCount[0] > 0) {
870 iRet = SlidingWindow (pCtx);870 iRet = SlidingWindow (pCtx);
871 } else { //all LTR, remove the smallest long_term_frame_idx871 } else { //all LTR, remove the smallest long_term_frame_idx
872 int32_t iLongTermFrameIdx = 0;872 int32_t iLongTermFrameIdx = 0;
873 int32_t iMaxLongTermFrameIdx = pRefPic->iMaxLongTermFrameIdx;873 int32_t iMaxLongTermFrameIdx = pRefPic->iMaxLongTermFrameIdx;
874#ifdef LONG_TERM_REF874#ifdef LONG_TERM_REF
875 int32_t iCurrLTRFrameIdx = GetLTRFrameIndex (pRefPic, pCtx->iFrameNumOfAuMarkedLtr);875 int32_t iCurrLTRFrameIdx = GetLTRFrameIndex (pRefPic, pCtx->iFrameNumOfAuMarkedLtr);
876#endif876#endif
877 while ((pRefPic->uiLongRefCount[0] >= pCtx->pSps->iNumRefFrames) && (iLongTermFrameIdx <= iMaxLongTermFrameIdx)) {877 while ((pRefPic->uiLongRefCount[0] >= pCtx->pSps->iNumRefFrames) && (iLongTermFrameIdx <= iMaxLongTermFrameIdx)) {
878#ifdef LONG_TERM_REF878#ifdef LONG_TERM_REF
879 if (iLongTermFrameIdx == iCurrLTRFrameIdx) {879 if (iLongTermFrameIdx == iCurrLTRFrameIdx) {
880 iLongTermFrameIdx++;880 iLongTermFrameIdx++;
881 continue;881 continue;
882 }882 }
883#endif883#endif
884 WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx);884 WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx);
885 iLongTermFrameIdx++;885 iLongTermFrameIdx++;
886 }886 }
887 }887 }
888 if (pRefPic->uiShortRefCount[0] + pRefPic->uiLongRefCount[0] >=888 if (pRefPic->uiShortRefCount[0] + pRefPic->uiLongRefCount[0] >=
889 pCtx->pSps->iNumRefFrames) { //fail to remain one empty buffer in DPB889 pCtx->pSps->iNumRefFrames) { //fail to remain one empty buffer in DPB
890 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "RemainOneBufferInDpbForEC(): empty one DPB failed for EC!");890 WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "RemainOneBufferInDpbForEC(): empty one DPB failed for EC!");
891 iRet = ERR_INFO_REF_COUNT_OVERFLOW;891 iRet = ERR_INFO_REF_COUNT_OVERFLOW;
892 }892 }
893 893
894 return iRet;894 return iRet;
895}895}
896 896
897} // namespace WelsDec897} // namespace WelsDec
codec/decoder/core/src/parse_mb_syn_cabac.cpp+1658−1658
@@ -1,1658 +1,1658 @@
1/*!1/*!
2 * \copy2 * \copy
3 * Copyright (c) 2013, Cisco Systems3 * Copyright (c) 2013, Cisco Systems
4 * All rights reserved.4 * All rights reserved.
5 *5 *
6 * Redistribution and use in source and binary forms, with or without6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions7 * modification, are permitted provided that the following conditions
8 * are met:8 * are met:
9 *9 *
10 * * Redistributions of source code must retain the above copyright10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.11 * notice, this list of conditions and the following disclaimer.
12 *12 *
13 * * Redistributions in binary form must reproduce the above copyright13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the15 * the documentation and/or other materials provided with the
16 * distribution.16 * distribution.
17 *17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.29 * POSSIBILITY OF SUCH DAMAGE.
30 *30 *
31 * parse_mb_syn_cabac.cpp: cabac parse for syntax elements31 * parse_mb_syn_cabac.cpp: cabac parse for syntax elements
32 */32 */
33#include "parse_mb_syn_cabac.h"33#include "parse_mb_syn_cabac.h"
34#include "decode_slice.h"34#include "decode_slice.h"
35#include "mv_pred.h"35#include "mv_pred.h"
36#include "error_code.h"36#include "error_code.h"
37#include <stdio.h>37#include <stdio.h>
38namespace WelsDec {38namespace WelsDec {
39#define IDX_UNUSED -139#define IDX_UNUSED -1
40 40
41static const int16_t g_kMaxPos [] = {IDX_UNUSED, 15, 14, 15, 3, 14, 63, 3, 3, 14, 14};41static const int16_t g_kMaxPos [] = {IDX_UNUSED, 15, 14, 15, 3, 14, 63, 3, 3, 14, 14};
42static const int16_t g_kMaxC2 [] = {IDX_UNUSED, 4, 4, 4, 3, 4, 4, 3, 3, 4, 4};42static const int16_t g_kMaxC2 [] = {IDX_UNUSED, 4, 4, 4, 3, 4, 4, 3, 3, 4, 4};
43static const int16_t g_kBlockCat2CtxOffsetCBF[] = {IDX_UNUSED, 0, 4, 8, 12, 16, 0, 12, 12, 16, 16};43static const int16_t g_kBlockCat2CtxOffsetCBF[] = {IDX_UNUSED, 0, 4, 8, 12, 16, 0, 12, 12, 16, 16};
44static const int16_t g_kBlockCat2CtxOffsetMap [] = {IDX_UNUSED, 0, 15, 29, 44, 47, 0, 44, 44, 47, 47};44static const int16_t g_kBlockCat2CtxOffsetMap [] = {IDX_UNUSED, 0, 15, 29, 44, 47, 0, 44, 44, 47, 47};
45static const int16_t g_kBlockCat2CtxOffsetLast[] = {IDX_UNUSED, 0, 15, 29, 44, 47, 0, 44, 44, 47, 47};45static const int16_t g_kBlockCat2CtxOffsetLast[] = {IDX_UNUSED, 0, 15, 29, 44, 47, 0, 44, 44, 47, 47};
46static const int16_t g_kBlockCat2CtxOffsetOne [] = {IDX_UNUSED, 0, 10, 20, 30, 39, 0, 30, 30, 39, 39};46static const int16_t g_kBlockCat2CtxOffsetOne [] = {IDX_UNUSED, 0, 10, 20, 30, 39, 0, 30, 30, 39, 39};
47static const int16_t g_kBlockCat2CtxOffsetAbs [] = {IDX_UNUSED, 0, 10, 20, 30, 39, 0, 30, 30, 39, 39};47static const int16_t g_kBlockCat2CtxOffsetAbs [] = {IDX_UNUSED, 0, 10, 20, 30, 39, 0, 30, 30, 39, 39};
48 48
49const uint8_t g_kTopBlkInsideMb[24] = { //for index with z-order 0~2349const uint8_t g_kTopBlkInsideMb[24] = { //for index with z-order 0~23
50 // 0 1 | 4 5 luma 8*8 block pNonZeroCount[16+8]50 // 0 1 | 4 5 luma 8*8 block pNonZeroCount[16+8]
51 0, 0, 1, 1, // 2 3 | 6 7 0 | 1 0 1 2 351 0, 0, 1, 1, // 2 3 | 6 7 0 | 1 0 1 2 3
52 0, 0, 1, 1, //--------------- --------- 4 5 6 752 0, 0, 1, 1, //--------------- --------- 4 5 6 7
53 1, 1, 1, 1, // 8 9 | 12 13 2 | 3 8 9 10 1153 1, 1, 1, 1, // 8 9 | 12 13 2 | 3 8 9 10 11
54 1, 1, 1, 1, // 10 11 | 14 15-----------------------------> 12 13 14 1554 1, 1, 1, 1, // 10 11 | 14 15-----------------------------> 12 13 14 15
55 0, 0, 1, 1, //---------------- chroma 8*8 block 16 17 18 1955 0, 0, 1, 1, //---------------- chroma 8*8 block 16 17 18 19
56 0, 0, 1, 1 // 16 17 | 20 21 0 1 20 21 22 2356 0, 0, 1, 1 // 16 17 | 20 21 0 1 20 21 22 23
57 // 18 19 | 22 2357 // 18 19 | 22 23
58};58};
59 59
60const uint8_t g_kLeftBlkInsideMb[24] = { //for index with z-order 0~2360const uint8_t g_kLeftBlkInsideMb[24] = { //for index with z-order 0~23
61 // 0 1 | 4 5 luma 8*8 block pNonZeroCount[16+8]61 // 0 1 | 4 5 luma 8*8 block pNonZeroCount[16+8]
62 0, 1, 0, 1, // 2 3 | 6 7 0 | 1 0 1 2 362 0, 1, 0, 1, // 2 3 | 6 7 0 | 1 0 1 2 3
63 1, 1, 1, 1, //--------------- --------- 4 5 6 763 1, 1, 1, 1, //--------------- --------- 4 5 6 7
64 0, 1, 0, 1, // 8 9 | 12 13 2 | 3 8 9 10 1164 0, 1, 0, 1, // 8 9 | 12 13 2 | 3 8 9 10 11
65 1, 1, 1, 1, // 10 11 | 14 15-----------------------------> 12 13 14 1565 1, 1, 1, 1, // 10 11 | 14 15-----------------------------> 12 13 14 15
66 0, 1, 0, 1, //---------------- chroma 8*8 block 16 17 18 1966 0, 1, 0, 1, //---------------- chroma 8*8 block 16 17 18 19
67 0, 1, 0, 1 // 16 17 | 20 21 0 1 20 21 22 2367 0, 1, 0, 1 // 16 17 | 20 21 0 1 20 21 22 23
68 // 18 19 | 22 2368 // 18 19 | 22 23
69};69};
70 70
71static uint32_t DecodeCabacIntraMbType (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, int ctx_base) {71static uint32_t DecodeCabacIntraMbType (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, int ctx_base) {
72 uint32_t uiCode;72 uint32_t uiCode;
73 uint32_t uiMbType = 0;73 uint32_t uiMbType = 0;
74 74
75 PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine;75 PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine;
76 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + ctx_base;76 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + ctx_base;
77 77
78 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx, uiCode));78 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx, uiCode));
79 if (!uiCode) {79 if (!uiCode) {
80 return 0; /* I4x4 */80 return 0; /* I4x4 */
81 }81 }
82 82
83 DecodeTerminateCabac (pCabacDecEngine, uiCode);83 DecodeTerminateCabac (pCabacDecEngine, uiCode);
84 if (uiCode) {84 if (uiCode) {
85 return 25; /* PCM */85 return 25; /* PCM */
86 }86 }
87 uiMbType = 1; /* I16x16 */87 uiMbType = 1; /* I16x16 */
88 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 1, uiCode)); /* cbp_luma != 0 */88 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 1, uiCode)); /* cbp_luma != 0 */
89 uiMbType += 12 * uiCode;89 uiMbType += 12 * uiCode;
90 90
91 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 2, uiCode));91 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 2, uiCode));
92 if (uiCode) {92 if (uiCode) {
93 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 2, uiCode));93 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 2, uiCode));
94 uiMbType += 4 + 4 * uiCode;94 uiMbType += 4 + 4 * uiCode;
95 }95 }
96 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));96 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));
97 uiMbType += 2 * uiCode;97 uiMbType += 2 * uiCode;
98 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));98 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));
99 uiMbType += 1 * uiCode;99 uiMbType += 1 * uiCode;
100 return uiMbType;100 return uiMbType;
101}101}
102 102
103void UpdateP16x8RefIdxCabac (PDqLayer pCurDqLayer, int8_t pRefIndex[LIST_A][30], int32_t iPartIdx, const int8_t iRef,103void UpdateP16x8RefIdxCabac (PDqLayer pCurDqLayer, int8_t pRefIndex[LIST_A][30], int32_t iPartIdx, const int8_t iRef,
104 const int8_t iListIdx) {104 const int8_t iListIdx) {
105 uint32_t iRef32Bit = (uint32_t) iRef;105 uint32_t iRef32Bit = (uint32_t) iRef;
106 const int32_t iRef4Bytes = (iRef32Bit << 24) | (iRef32Bit << 16) | (iRef32Bit << 8) | iRef32Bit;106 const int32_t iRef4Bytes = (iRef32Bit << 24) | (iRef32Bit << 16) | (iRef32Bit << 8) | iRef32Bit;
107 int32_t iMbXy = pCurDqLayer->iMbXyIndex;107 int32_t iMbXy = pCurDqLayer->iMbXyIndex;
108 const uint8_t iScan4Idx = g_kuiScan4[iPartIdx];108 const uint8_t iScan4Idx = g_kuiScan4[iPartIdx];
109 const uint8_t iScan4Idx4 = 4 + iScan4Idx;109 const uint8_t iScan4Idx4 = 4 + iScan4Idx;
110 const uint8_t iCacheIdx = g_kuiCache30ScanIdx[iPartIdx];110 const uint8_t iCacheIdx = g_kuiCache30ScanIdx[iPartIdx];
111 const uint8_t iCacheIdx6 = 6 + iCacheIdx;111 const uint8_t iCacheIdx6 = 6 + iCacheIdx;
112 //mb112 //mb
113 ST32 (&pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx ], iRef4Bytes);113 ST32 (&pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx ], iRef4Bytes);
114 ST32 (&pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx4], iRef4Bytes);114 ST32 (&pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx4], iRef4Bytes);
115 //cache115 //cache
116 ST32 (&pRefIndex[iListIdx][iCacheIdx ], iRef4Bytes);116 ST32 (&pRefIndex[iListIdx][iCacheIdx ], iRef4Bytes);
117 ST32 (&pRefIndex[iListIdx][iCacheIdx6], iRef4Bytes);117 ST32 (&pRefIndex[iListIdx][iCacheIdx6], iRef4Bytes);
118}118}
119 119
120void UpdateP8x16RefIdxCabac (PDqLayer pCurDqLayer, int8_t pRefIndex[LIST_A][30], int32_t iPartIdx, const int8_t iRef,120void UpdateP8x16RefIdxCabac (PDqLayer pCurDqLayer, int8_t pRefIndex[LIST_A][30], int32_t iPartIdx, const int8_t iRef,
121 const int8_t iListIdx) {121 const int8_t iListIdx) {
122 uint16_t iRef16Bit = (uint16_t) iRef;122 uint16_t iRef16Bit = (uint16_t) iRef;
123 const int16_t iRef2Bytes = (iRef16Bit << 8) | iRef16Bit;123 const int16_t iRef2Bytes = (iRef16Bit << 8) | iRef16Bit;
124 int32_t i;124 int32_t i;
125 int32_t iMbXy = pCurDqLayer->iMbXyIndex;125 int32_t iMbXy = pCurDqLayer->iMbXyIndex;
126 for (i = 0; i < 2; i++, iPartIdx += 8) {126 for (i = 0; i < 2; i++, iPartIdx += 8) {
127 const uint8_t iScan4Idx = g_kuiScan4[iPartIdx];127 const uint8_t iScan4Idx = g_kuiScan4[iPartIdx];
128 const uint8_t iCacheIdx = g_kuiCache30ScanIdx[iPartIdx];128 const uint8_t iCacheIdx = g_kuiCache30ScanIdx[iPartIdx];
129 const uint8_t iScan4Idx4 = 4 + iScan4Idx;129 const uint8_t iScan4Idx4 = 4 + iScan4Idx;
130 const uint8_t iCacheIdx6 = 6 + iCacheIdx;130 const uint8_t iCacheIdx6 = 6 + iCacheIdx;
131 //mb131 //mb
132 ST16 (&pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx ], iRef2Bytes);132 ST16 (&pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx ], iRef2Bytes);
133 ST16 (&pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx4], iRef2Bytes);133 ST16 (&pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx4], iRef2Bytes);
134 //cache134 //cache
135 ST16 (&pRefIndex[iListIdx][iCacheIdx ], iRef2Bytes);135 ST16 (&pRefIndex[iListIdx][iCacheIdx ], iRef2Bytes);
136 ST16 (&pRefIndex[iListIdx][iCacheIdx6], iRef2Bytes);136 ST16 (&pRefIndex[iListIdx][iCacheIdx6], iRef2Bytes);
137 }137 }
138}138}
139 139
140void UpdateP8x8RefIdxCabac (PDqLayer pCurDqLayer, int8_t pRefIndex[LIST_A][30], int32_t iPartIdx, const int8_t iRef,140void UpdateP8x8RefIdxCabac (PDqLayer pCurDqLayer, int8_t pRefIndex[LIST_A][30], int32_t iPartIdx, const int8_t iRef,
141 const int8_t iListIdx) {141 const int8_t iListIdx) {
142 int32_t iMbXy = pCurDqLayer->iMbXyIndex;142 int32_t iMbXy = pCurDqLayer->iMbXyIndex;
143 const uint8_t iScan4Idx = g_kuiScan4[iPartIdx];143 const uint8_t iScan4Idx = g_kuiScan4[iPartIdx];
144 pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx] = pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx + 1] =144 pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx] = pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx + 1] =
145 pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx + 4] = pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx + 5] = iRef;145 pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx + 4] = pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx + 5] = iRef;
146}146}
147 147
148void UpdateP8x8DirectCabac (PDqLayer pCurDqLayer, int32_t iPartIdx) {148void UpdateP8x8DirectCabac (PDqLayer pCurDqLayer, int32_t iPartIdx) {
149 int32_t iMbXy = pCurDqLayer->iMbXyIndex;149 int32_t iMbXy = pCurDqLayer->iMbXyIndex;
150 const uint8_t iScan4Idx = g_kuiScan4[iPartIdx];150 const uint8_t iScan4Idx = g_kuiScan4[iPartIdx];
151 pCurDqLayer->pDirect[iMbXy][iScan4Idx] = pCurDqLayer->pDirect[iMbXy][iScan4Idx + 1] =151 pCurDqLayer->pDirect[iMbXy][iScan4Idx] = pCurDqLayer->pDirect[iMbXy][iScan4Idx + 1] =
152 pCurDqLayer->pDirect[iMbXy][iScan4Idx + 4] = pCurDqLayer->pDirect[iMbXy][iScan4Idx + 5] = 1;152 pCurDqLayer->pDirect[iMbXy][iScan4Idx + 4] = pCurDqLayer->pDirect[iMbXy][iScan4Idx + 5] = 1;
153}153}
154 154
155void UpdateP16x16DirectCabac (PDqLayer pCurDqLayer) {155void UpdateP16x16DirectCabac (PDqLayer pCurDqLayer) {
156 int32_t i;156 int32_t i;
157 int32_t iMbXy = pCurDqLayer->iMbXyIndex;157 int32_t iMbXy = pCurDqLayer->iMbXyIndex;
158 const int16_t direct = (1 << 8) | 1;158 const int16_t direct = (1 << 8) | 1;
159 for (i = 0; i < 16; i += 4) {159 for (i = 0; i < 16; i += 4) {
160 const uint8_t kuiScan4Idx = g_kuiScan4[i];160 const uint8_t kuiScan4Idx = g_kuiScan4[i];
161 const uint8_t kuiScan4IdxPlus4 = 4 + kuiScan4Idx;161 const uint8_t kuiScan4IdxPlus4 = 4 + kuiScan4Idx;
162 ST16 (&pCurDqLayer->pDirect[iMbXy][kuiScan4Idx], direct);162 ST16 (&pCurDqLayer->pDirect[iMbXy][kuiScan4Idx], direct);
163 ST16 (&pCurDqLayer->pDirect[iMbXy][kuiScan4IdxPlus4], direct);163 ST16 (&pCurDqLayer->pDirect[iMbXy][kuiScan4IdxPlus4], direct);
164 }164 }
165}165}
166 166
167void UpdateP16x16MvdCabac (SDqLayer* pCurDqLayer, int16_t pMvd[2], const int8_t iListIdx) {167void UpdateP16x16MvdCabac (SDqLayer* pCurDqLayer, int16_t pMvd[2], const int8_t iListIdx) {
168 int32_t pMvd32[2];168 int32_t pMvd32[2];
169 ST32 (&pMvd32[0], LD32 (pMvd));169 ST32 (&pMvd32[0], LD32 (pMvd));
170 ST32 (&pMvd32[1], LD32 (pMvd));170 ST32 (&pMvd32[1], LD32 (pMvd));
171 int32_t i;171 int32_t i;
172 int32_t iMbXy = pCurDqLayer->iMbXyIndex;172 int32_t iMbXy = pCurDqLayer->iMbXyIndex;
173 for (i = 0; i < 16; i += 2) {173 for (i = 0; i < 16; i += 2) {
174 ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][i], LD64 (pMvd32));174 ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][i], LD64 (pMvd32));
175 }175 }
176}176}
177 177
178void UpdateP16x8MvdCabac (SDqLayer* pCurDqLayer, int16_t pMvdCache[LIST_A][30][MV_A], int32_t iPartIdx, int16_t pMvd[2],178void UpdateP16x8MvdCabac (SDqLayer* pCurDqLayer, int16_t pMvdCache[LIST_A][30][MV_A], int32_t iPartIdx, int16_t pMvd[2],
179 const int8_t iListIdx) {179 const int8_t iListIdx) {
180 int32_t pMvd32[2];180 int32_t pMvd32[2];
181 ST32 (&pMvd32[0], LD32 (pMvd));181 ST32 (&pMvd32[0], LD32 (pMvd));
182 ST32 (&pMvd32[1], LD32 (pMvd));182 ST32 (&pMvd32[1], LD32 (pMvd));
183 int32_t i;183 int32_t i;
184 int32_t iMbXy = pCurDqLayer->iMbXyIndex;184 int32_t iMbXy = pCurDqLayer->iMbXyIndex;
185 for (i = 0; i < 2; i++, iPartIdx += 4) {185 for (i = 0; i < 2; i++, iPartIdx += 4) {
186 const uint8_t iScan4Idx = g_kuiScan4[iPartIdx];186 const uint8_t iScan4Idx = g_kuiScan4[iPartIdx];
187 const uint8_t iScan4Idx4 = 4 + iScan4Idx;187 const uint8_t iScan4Idx4 = 4 + iScan4Idx;
188 const uint8_t iCacheIdx = g_kuiCache30ScanIdx[iPartIdx];188 const uint8_t iCacheIdx = g_kuiCache30ScanIdx[iPartIdx];
189 const uint8_t iCacheIdx6 = 6 + iCacheIdx;189 const uint8_t iCacheIdx6 = 6 + iCacheIdx;
190 //mb190 //mb
191 ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][ iScan4Idx ], LD64 (pMvd32));191 ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][ iScan4Idx ], LD64 (pMvd32));
192 ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][ iScan4Idx4], LD64 (pMvd32));192 ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][ iScan4Idx4], LD64 (pMvd32));
193 //cache193 //cache
194 ST64 (pMvdCache[iListIdx][ iCacheIdx ], LD64 (pMvd32));194 ST64 (pMvdCache[iListIdx][ iCacheIdx ], LD64 (pMvd32));
195 ST64 (pMvdCache[iListIdx][ iCacheIdx6], LD64 (pMvd32));195 ST64 (pMvdCache[iListIdx][ iCacheIdx6], LD64 (pMvd32));
196 }196 }
197}197}
198 198
199void UpdateP8x16MvdCabac (SDqLayer* pCurDqLayer, int16_t pMvdCache[LIST_A][30][MV_A], int32_t iPartIdx, int16_t pMvd[2],199void UpdateP8x16MvdCabac (SDqLayer* pCurDqLayer, int16_t pMvdCache[LIST_A][30][MV_A], int32_t iPartIdx, int16_t pMvd[2],
200 const int8_t iListIdx) {200 const int8_t iListIdx) {
201 int32_t pMvd32[2];201 int32_t pMvd32[2];
202 ST32 (&pMvd32[0], LD32 (pMvd));202 ST32 (&pMvd32[0], LD32 (pMvd));
203 ST32 (&pMvd32[1], LD32 (pMvd));203 ST32 (&pMvd32[1], LD32 (pMvd));
204 int32_t i;204 int32_t i;
205 int32_t iMbXy = pCurDqLayer->iMbXyIndex;205 int32_t iMbXy = pCurDqLayer->iMbXyIndex;
206 206
207 for (i = 0; i < 2; i++, iPartIdx += 8) {207 for (i = 0; i < 2; i++, iPartIdx += 8) {
208 const uint8_t iScan4Idx = g_kuiScan4[iPartIdx];208 const uint8_t iScan4Idx = g_kuiScan4[iPartIdx];
209 const uint8_t iCacheIdx = g_kuiCache30ScanIdx[iPartIdx];209 const uint8_t iCacheIdx = g_kuiCache30ScanIdx[iPartIdx];
210 const uint8_t iScan4Idx4 = 4 + iScan4Idx;210 const uint8_t iScan4Idx4 = 4 + iScan4Idx;
211 const uint8_t iCacheIdx6 = 6 + iCacheIdx;211 const uint8_t iCacheIdx6 = 6 + iCacheIdx;
212 //mb212 //mb
213 ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][ iScan4Idx ], LD64 (pMvd32));213 ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][ iScan4Idx ], LD64 (pMvd32));
214 ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][ iScan4Idx4], LD64 (pMvd32));214 ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][ iScan4Idx4], LD64 (pMvd32));
215 //cache215 //cache
216 ST64 (pMvdCache[iListIdx][ iCacheIdx ], LD64 (pMvd32));216 ST64 (pMvdCache[iListIdx][ iCacheIdx ], LD64 (pMvd32));
217 ST64 (pMvdCache[iListIdx][ iCacheIdx6], LD64 (pMvd32));217 ST64 (pMvdCache[iListIdx][ iCacheIdx6], LD64 (pMvd32));
218 }218 }
219}219}
220 220
221int32_t ParseEndOfSliceCabac (PWelsDecoderContext pCtx, uint32_t& uiBinVal) {221int32_t ParseEndOfSliceCabac (PWelsDecoderContext pCtx, uint32_t& uiBinVal) {
222 uiBinVal = 0;222 uiBinVal = 0;
223 WELS_READ_VERIFY (DecodeTerminateCabac (pCtx->pCabacDecEngine, uiBinVal));223 WELS_READ_VERIFY (DecodeTerminateCabac (pCtx->pCabacDecEngine, uiBinVal));
224 return ERR_NONE;224 return ERR_NONE;
225}225}
226 226
227int32_t ParseSkipFlagCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiSkip) {227int32_t ParseSkipFlagCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiSkip) {
228 uiSkip = 0;228 uiSkip = 0;
229 int32_t iCtxInc = NEW_CTX_OFFSET_SKIP;229 int32_t iCtxInc = NEW_CTX_OFFSET_SKIP;
230 iCtxInc += (pNeighAvail->iLeftAvail && !IS_SKIP (pNeighAvail->iLeftType)) + (pNeighAvail->iTopAvail230 iCtxInc += (pNeighAvail->iLeftAvail && !IS_SKIP (pNeighAvail->iLeftType)) + (pNeighAvail->iTopAvail
231 && !IS_SKIP (pNeighAvail->iTopType));231 && !IS_SKIP (pNeighAvail->iTopType));
232 if (B_SLICE == pCtx->eSliceType)232 if (B_SLICE == pCtx->eSliceType)
233 iCtxInc += 13;233 iCtxInc += 13;
234 PWelsCabacCtx pBinCtx = (pCtx->pCabacCtx + iCtxInc);234 PWelsCabacCtx pBinCtx = (pCtx->pCabacCtx + iCtxInc);
235 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pBinCtx, uiSkip));235 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pBinCtx, uiSkip));
236 return ERR_NONE;236 return ERR_NONE;
237}237}
238 238
239 239
240int32_t ParseMBTypeISliceCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiBinVal) {240int32_t ParseMBTypeISliceCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiBinVal) {
241 uint32_t uiCode;241 uint32_t uiCode;
242 int32_t iIdxA = 0, iIdxB = 0;242 int32_t iIdxA = 0, iIdxB = 0;
243 int32_t iCtxInc;243 int32_t iCtxInc;
244 uiBinVal = 0;244 uiBinVal = 0;
245 PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine;245 PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine;
246 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_MB_TYPE_I; //I mode in I slice246 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_MB_TYPE_I; //I mode in I slice
247 iIdxA = (pNeighAvail->iLeftAvail) && (pNeighAvail->iLeftType != MB_TYPE_INTRA4x4247 iIdxA = (pNeighAvail->iLeftAvail) && (pNeighAvail->iLeftType != MB_TYPE_INTRA4x4
248 && pNeighAvail->iLeftType != MB_TYPE_INTRA8x8);248 && pNeighAvail->iLeftType != MB_TYPE_INTRA8x8);
249 iIdxB = (pNeighAvail->iTopAvail) && (pNeighAvail->iTopType != MB_TYPE_INTRA4x4249 iIdxB = (pNeighAvail->iTopAvail) && (pNeighAvail->iTopType != MB_TYPE_INTRA4x4
250 && pNeighAvail->iTopType != MB_TYPE_INTRA8x8);250 && pNeighAvail->iTopType != MB_TYPE_INTRA8x8);
251 iCtxInc = iIdxA + iIdxB;251 iCtxInc = iIdxA + iIdxB;
252 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + iCtxInc, uiCode));252 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + iCtxInc, uiCode));
253 uiBinVal = uiCode;253 uiBinVal = uiCode;
254 if (uiBinVal != 0) { //I16x16254 if (uiBinVal != 0) { //I16x16
255 WELS_READ_VERIFY (DecodeTerminateCabac (pCabacDecEngine, uiCode));255 WELS_READ_VERIFY (DecodeTerminateCabac (pCabacDecEngine, uiCode));
256 if (uiCode == 1)256 if (uiCode == 1)
257 uiBinVal = 25; //I_PCM257 uiBinVal = 25; //I_PCM
258 else {258 else {
259 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));259 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));
260 uiBinVal = 1 + uiCode * 12;260 uiBinVal = 1 + uiCode * 12;
261 //decoding of uiCbp:0,1,2261 //decoding of uiCbp:0,1,2
262 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 4, uiCode));262 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 4, uiCode));
263 if (uiCode != 0) {263 if (uiCode != 0) {
264 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode));264 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode));
265 uiBinVal += 4;265 uiBinVal += 4;
266 if (uiCode != 0)266 if (uiCode != 0)
267 uiBinVal += 4;267 uiBinVal += 4;
268 }268 }
269 //decoding of I pred-mode: 0,1,2,3269 //decoding of I pred-mode: 0,1,2,3
270 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 6, uiCode));270 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 6, uiCode));
271 uiBinVal += (uiCode << 1);271 uiBinVal += (uiCode << 1);
272 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 7, uiCode));272 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 7, uiCode));
273 uiBinVal += uiCode;273 uiBinVal += uiCode;
274 }274 }
275 }275 }
276 //I4x4276 //I4x4
277 return ERR_NONE;277 return ERR_NONE;
278}278}
279 279
280int32_t ParseMBTypePSliceCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiMbType) {280int32_t ParseMBTypePSliceCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiMbType) {
281 uint32_t uiCode;281 uint32_t uiCode;
282 uiMbType = 0;282 uiMbType = 0;
283 PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine;283 PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine;
284 284
285 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_SKIP;285 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_SKIP;
286 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));286 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));
287 if (uiCode) {287 if (uiCode) {
288 // Intra MB288 // Intra MB
289 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 6, uiCode));289 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 6, uiCode));
290 if (uiCode) { // Intra 16x16290 if (uiCode) { // Intra 16x16
291 WELS_READ_VERIFY (DecodeTerminateCabac (pCabacDecEngine, uiCode));291 WELS_READ_VERIFY (DecodeTerminateCabac (pCabacDecEngine, uiCode));
292 if (uiCode) {292 if (uiCode) {
293 uiMbType = 30;293 uiMbType = 30;
294 return ERR_NONE;//MB_TYPE_INTRA_PCM;294 return ERR_NONE;//MB_TYPE_INTRA_PCM;
295 }295 }
296 296
297 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 7, uiCode));297 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 7, uiCode));
298 uiMbType = 6 + uiCode * 12;298 uiMbType = 6 + uiCode * 12;
299 299
300 //uiCbp: 0,1,2300 //uiCbp: 0,1,2
301 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 8, uiCode));301 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 8, uiCode));
302 if (uiCode) {302 if (uiCode) {
303 uiMbType += 4;303 uiMbType += 4;
304 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 8, uiCode));304 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 8, uiCode));
305 if (uiCode)305 if (uiCode)
306 uiMbType += 4;306 uiMbType += 4;
307 }307 }
308 308
309 //IPredMode: 0,1,2,3309 //IPredMode: 0,1,2,3
310 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 9, uiCode));310 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 9, uiCode));
311 uiMbType += (uiCode << 1);311 uiMbType += (uiCode << 1);
312 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 9, uiCode));312 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 9, uiCode));
313 uiMbType += uiCode;313 uiMbType += uiCode;
314 } else314 } else
315 // Intra 4x4315 // Intra 4x4
316 uiMbType = 5;316 uiMbType = 5;
317 } else { // P MB317 } else { // P MB
318 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 4, uiCode));318 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 4, uiCode));
319 if (uiCode) { //second bit319 if (uiCode) { //second bit
320 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 6, uiCode));320 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 6, uiCode));
321 if (uiCode)321 if (uiCode)
322 uiMbType = 1;322 uiMbType = 1;
323 else323 else
324 uiMbType = 2;324 uiMbType = 2;
325 } else {325 } else {
326 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode));326 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode));
327 if (uiCode)327 if (uiCode)
328 uiMbType = 3;328 uiMbType = 3;
329 else329 else
330 uiMbType = 0;330 uiMbType = 0;
331 }331 }
332 }332 }
333 return ERR_NONE;333 return ERR_NONE;
334}334}
335 335
336int32_t ParseMBTypeBSliceCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiMbType) {336int32_t ParseMBTypeBSliceCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiMbType) {
337 uint32_t uiCode;337 uint32_t uiCode;
338 uiMbType = 0;338 uiMbType = 0;
339 int32_t iIdxA = 0, iIdxB = 0;339 int32_t iIdxA = 0, iIdxB = 0;
340 int32_t iCtxInc;340 int32_t iCtxInc;
341 341
342 PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine;342 PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine;
343 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + 27; //B slice343 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + 27; //B slice
344 344
345 iIdxA = (pNeighAvail->iLeftAvail) && !IS_DIRECT (pNeighAvail->iLeftType);345 iIdxA = (pNeighAvail->iLeftAvail) && !IS_DIRECT (pNeighAvail->iLeftType);
346 iIdxB = (pNeighAvail->iTopAvail) && !IS_DIRECT (pNeighAvail->iTopType);346 iIdxB = (pNeighAvail->iTopAvail) && !IS_DIRECT (pNeighAvail->iTopType);
347 347
348 iCtxInc = iIdxA + iIdxB;348 iCtxInc = iIdxA + iIdxB;
349 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + iCtxInc, uiCode));349 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + iCtxInc, uiCode));
350 if (!uiCode)350 if (!uiCode)
351 uiMbType = 0; // Bi_Direct351 uiMbType = 0; // Bi_Direct
352 else {352 else {
353 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));353 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));
354 if (!uiCode) {354 if (!uiCode) {
355 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode));355 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode));
356 uiMbType = 1 + uiCode; // 16x16 L0L1356 uiMbType = 1 + uiCode; // 16x16 L0L1
357 } else {357 } else {
358 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 4, uiCode));358 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 4, uiCode));
359 uiMbType = uiCode << 3;359 uiMbType = uiCode << 3;
360 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode));360 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode));
361 uiMbType |= uiCode << 2;361 uiMbType |= uiCode << 2;
362 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode));362 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode));
363 uiMbType |= uiCode << 1;363 uiMbType |= uiCode << 1;
364 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode));364 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode));
365 uiMbType |= uiCode;365 uiMbType |= uiCode;
366 if (uiMbType < 8) {366 if (uiMbType < 8) {
367 uiMbType += 3;367 uiMbType += 3;
368 return ERR_NONE;368 return ERR_NONE;
369 } else if (uiMbType == 13) {369 } else if (uiMbType == 13) {
370 uiMbType = DecodeCabacIntraMbType (pCtx, pNeighAvail, 32) + 23;370 uiMbType = DecodeCabacIntraMbType (pCtx, pNeighAvail, 32) + 23;
371 return ERR_NONE;371 return ERR_NONE;
372 } else if (uiMbType == 14) {372 } else if (uiMbType == 14) {
373 uiMbType = 11; // Bi8x16373 uiMbType = 11; // Bi8x16
374 return ERR_NONE;374 return ERR_NONE;
375 } else if (uiMbType == 15) {375 } else if (uiMbType == 15) {
376 uiMbType = 22; // 8x8376 uiMbType = 22; // 8x8
377 return ERR_NONE;377 return ERR_NONE;
378 }378 }
379 uiMbType <<= 1;379 uiMbType <<= 1;
380 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode));380 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode));
381 uiMbType |= uiCode;381 uiMbType |= uiCode;
382 uiMbType -= 4;382 uiMbType -= 4;
383 }383 }
384 }384 }
385 return ERR_NONE;385 return ERR_NONE;
386}386}
387 387
388int32_t ParseTransformSize8x8FlagCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail,388int32_t ParseTransformSize8x8FlagCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail,
389 bool& bTransformSize8x8Flag) {389 bool& bTransformSize8x8Flag) {
390 uint32_t uiCode;390 uint32_t uiCode;
391 int32_t iIdxA, iIdxB;391 int32_t iIdxA, iIdxB;
392 int32_t iCtxInc;392 int32_t iCtxInc;
393 PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine;393 PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine;
394 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_TS_8x8_FLAG;394 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_TS_8x8_FLAG;
395 iIdxA = (pNeighAvail->iLeftAvail) && (pCtx->pCurDqLayer->pTransformSize8x8Flag[pCtx->pCurDqLayer->iMbXyIndex - 1]);395 iIdxA = (pNeighAvail->iLeftAvail) && (pCtx->pCurDqLayer->pTransformSize8x8Flag[pCtx->pCurDqLayer->iMbXyIndex - 1]);
396 iIdxB = (pNeighAvail->iTopAvail)396 iIdxB = (pNeighAvail->iTopAvail)
397 && (pCtx->pCurDqLayer->pTransformSize8x8Flag[pCtx->pCurDqLayer->iMbXyIndex - pCtx->pCurDqLayer->iMbWidth]);397 && (pCtx->pCurDqLayer->pTransformSize8x8Flag[pCtx->pCurDqLayer->iMbXyIndex - pCtx->pCurDqLayer->iMbWidth]);
398 iCtxInc = iIdxA + iIdxB;398 iCtxInc = iIdxA + iIdxB;
399 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + iCtxInc, uiCode));399 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + iCtxInc, uiCode));
400 bTransformSize8x8Flag = !!uiCode;400 bTransformSize8x8Flag = !!uiCode;
401 401
402 return ERR_NONE;402 return ERR_NONE;
403}403}
404 404
405int32_t ParseSubMBTypeCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiSubMbType) {405int32_t ParseSubMBTypeCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiSubMbType) {
406 uint32_t uiCode;406 uint32_t uiCode;
407 PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine;407 PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine;
408 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_SUBMB_TYPE;408 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_SUBMB_TYPE;
409 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx, uiCode));409 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx, uiCode));
410 if (uiCode)410 if (uiCode)
411 uiSubMbType = 0;411 uiSubMbType = 0;
412 else {412 else {
413 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 1, uiCode));413 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 1, uiCode));
414 if (uiCode) {414 if (uiCode) {
415 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 2, uiCode));415 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 2, uiCode));
416 uiSubMbType = 3 - uiCode;416 uiSubMbType = 3 - uiCode;
417 } else {417 } else {
418 uiSubMbType = 1;418 uiSubMbType = 1;
419 }419 }
420 }420 }
421 return ERR_NONE;421 return ERR_NONE;
422}422}
423 423
424int32_t ParseBSubMBTypeCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiSubMbType) {424int32_t ParseBSubMBTypeCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiSubMbType) {
425 uint32_t uiCode;425 uint32_t uiCode;
426 PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine;426 PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine;
427 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_B_SUBMB_TYPE;427 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_B_SUBMB_TYPE;
428 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx, uiCode));428 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx, uiCode));
429 if (!uiCode) {429 if (!uiCode) {
430 uiSubMbType = 0; /* B_Direct_8x8 */430 uiSubMbType = 0; /* B_Direct_8x8 */
431 return ERR_NONE;431 return ERR_NONE;
432 }432 }
433 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 1, uiCode));433 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 1, uiCode));
434 if (!uiCode) {434 if (!uiCode) {
435 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));435 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));
436 uiSubMbType = 1 + uiCode; /* B_L0_8x8, B_L1_8x8 */436 uiSubMbType = 1 + uiCode; /* B_L0_8x8, B_L1_8x8 */
437 return ERR_NONE;437 return ERR_NONE;
438 }438 }
439 uiSubMbType = 3;439 uiSubMbType = 3;
440 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 2, uiCode));440 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 2, uiCode));
441 if (uiCode) {441 if (uiCode) {
442 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));442 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));
443 if (uiCode) {443 if (uiCode) {
444 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));444 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));
445 uiSubMbType = 11 + uiCode; /* B_L1_4x4, B_Bi_4x4 */445 uiSubMbType = 11 + uiCode; /* B_L1_4x4, B_Bi_4x4 */
446 return ERR_NONE;446 return ERR_NONE;
447 }447 }
448 uiSubMbType += 4;448 uiSubMbType += 4;
449 }449 }
450 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));450 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));
451 uiSubMbType += 2 * uiCode;451 uiSubMbType += 2 * uiCode;
452 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));452 WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode));
453 uiSubMbType += uiCode;453 uiSubMbType += uiCode;
454 454
455 return ERR_NONE;455 return ERR_NONE;
456}456}
457 457
458int32_t ParseIntraPredModeLumaCabac (PWelsDecoderContext pCtx, int32_t& iBinVal) {458int32_t ParseIntraPredModeLumaCabac (PWelsDecoderContext pCtx, int32_t& iBinVal) {
459 uint32_t uiCode;459 uint32_t uiCode;
460 iBinVal = 0;460 iBinVal = 0;
461 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_IPR, uiCode));461 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_IPR, uiCode));
462 if (uiCode == 1)462 if (uiCode == 1)
463 iBinVal = -1;463 iBinVal = -1;
464 else {464 else {
465 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_IPR + 1, uiCode));465 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_IPR + 1, uiCode));
466 iBinVal |= uiCode;466 iBinVal |= uiCode;
467 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_IPR + 1, uiCode));467 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_IPR + 1, uiCode));
468 iBinVal |= (uiCode << 1);468 iBinVal |= (uiCode << 1);
469 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_IPR + 1, uiCode));469 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_IPR + 1, uiCode));
470 iBinVal |= (uiCode << 2);470 iBinVal |= (uiCode << 2);
471 }471 }
472 return ERR_NONE;472 return ERR_NONE;
473}473}
474 474
475int32_t ParseIntraPredModeChromaCabac (PWelsDecoderContext pCtx, uint8_t uiNeighAvail, int32_t& iBinVal) {475int32_t ParseIntraPredModeChromaCabac (PWelsDecoderContext pCtx, uint8_t uiNeighAvail, int32_t& iBinVal) {
476 uint32_t uiCode;476 uint32_t uiCode;
477 int32_t iIdxA, iIdxB, iCtxInc;477 int32_t iIdxA, iIdxB, iCtxInc;
478 int8_t* pChromaPredMode = pCtx->pCurDqLayer->pChromaPredMode;478 int8_t* pChromaPredMode = pCtx->pCurDqLayer->pChromaPredMode;
479 uint32_t* pMbType = pCtx->pCurDqLayer->pMbType;479 uint32_t* pMbType = pCtx->pCurDqLayer->pMbType;
480 int32_t iLeftAvail = uiNeighAvail & 0x04;480 int32_t iLeftAvail = uiNeighAvail & 0x04;
481 int32_t iTopAvail = uiNeighAvail & 0x01;481 int32_t iTopAvail = uiNeighAvail & 0x01;
482 482
483 int32_t iMbXy = pCtx->pCurDqLayer->iMbXyIndex;483 int32_t iMbXy = pCtx->pCurDqLayer->iMbXyIndex;
484 int32_t iMbXyTop = iMbXy - pCtx->pCurDqLayer->iMbWidth;484 int32_t iMbXyTop = iMbXy - pCtx->pCurDqLayer->iMbWidth;
485 int32_t iMbXyLeft = iMbXy - 1;485 int32_t iMbXyLeft = iMbXy - 1;
486 486
487 iBinVal = 0;487 iBinVal = 0;
488 488
489 iIdxB = iTopAvail && (pChromaPredMode[iMbXyTop] > 0 && pChromaPredMode[iMbXyTop] <= 3)489 iIdxB = iTopAvail && (pChromaPredMode[iMbXyTop] > 0 && pChromaPredMode[iMbXyTop] <= 3)
490 && pMbType[iMbXyTop] != MB_TYPE_INTRA_PCM;490 && pMbType[iMbXyTop] != MB_TYPE_INTRA_PCM;
491 iIdxA = iLeftAvail && (pChromaPredMode[iMbXyLeft] > 0 && pChromaPredMode[iMbXyLeft] <= 3)491 iIdxA = iLeftAvail && (pChromaPredMode[iMbXyLeft] > 0 && pChromaPredMode[iMbXyLeft] <= 3)
492 && pMbType[iMbXyLeft] != MB_TYPE_INTRA_PCM;492 && pMbType[iMbXyLeft] != MB_TYPE_INTRA_PCM;
493 iCtxInc = iIdxA + iIdxB;493 iCtxInc = iIdxA + iIdxB;
494 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CIPR + iCtxInc, uiCode));494 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CIPR + iCtxInc, uiCode));
495 iBinVal = uiCode;495 iBinVal = uiCode;
496 if (iBinVal != 0) {496 if (iBinVal != 0) {
497 uint32_t iSym;497 uint32_t iSym;
498 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CIPR + 3, iSym));498 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CIPR + 3, iSym));
499 if (iSym == 0) {499 if (iSym == 0) {
500 iBinVal = (iSym + 1);500 iBinVal = (iSym + 1);
501 return ERR_NONE;501 return ERR_NONE;
502 }502 }
503 iSym = 0;503 iSym = 0;
504 do {504 do {
505 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CIPR + 3, uiCode));505 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CIPR + 3, uiCode));
506 ++iSym;506 ++iSym;
507 } while ((uiCode != 0) && (iSym < 1));507 } while ((uiCode != 0) && (iSym < 1));
508 508
509 if ((uiCode != 0) && (iSym == 1))509 if ((uiCode != 0) && (iSym == 1))
510 ++ iSym;510 ++ iSym;
511 iBinVal = (iSym + 1);511 iBinVal = (iSym + 1);
512 return ERR_NONE;512 return ERR_NONE;
513 }513 }
514 return ERR_NONE;514 return ERR_NONE;
515}515}
516 516
517int32_t ParseInterPMotionInfoCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCount,517int32_t ParseInterPMotionInfoCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCount,
518 int16_t pMotionVector[LIST_A][30][MV_A], int16_t pMvdCache[LIST_A][30][MV_A], int8_t pRefIndex[LIST_A][30]) {518 int16_t pMotionVector[LIST_A][30][MV_A], int16_t pMvdCache[LIST_A][30][MV_A], int8_t pRefIndex[LIST_A][30]) {
519 PSlice pSlice = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer;519 PSlice pSlice = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer;
520 PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader;520 PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader;
521 PDqLayer pCurDqLayer = pCtx->pCurDqLayer;521 PDqLayer pCurDqLayer = pCtx->pCurDqLayer;
522 PPicture* ppRefPic = pCtx->sRefPic.pRefList[LIST_0];522 PPicture* ppRefPic = pCtx->sRefPic.pRefList[LIST_0];
523 int32_t pRefCount[2];523 int32_t pRefCount[2];
524 int32_t i, j;524 int32_t i, j;
525 int32_t iMbXy = pCurDqLayer->iMbXyIndex;525 int32_t iMbXy = pCurDqLayer->iMbXyIndex;
526 int16_t pMv[4] = {0};526 int16_t pMv[4] = {0};
527 int16_t pMvd[4] = {0};527 int16_t pMvd[4] = {0};
528 int8_t iRef[2] = {0};528 int8_t iRef[2] = {0};
529 int32_t iPartIdx;529 int32_t iPartIdx;
530 int16_t iMinVmv = pSliceHeader->pSps->pSLevelLimits->iMinVmv;530 int16_t iMinVmv = pSliceHeader->pSps->pSLevelLimits->iMinVmv;
531 int16_t iMaxVmv = pSliceHeader->pSps->pSLevelLimits->iMaxVmv;531 int16_t iMaxVmv = pSliceHeader->pSps->pSLevelLimits->iMaxVmv;
532 pRefCount[0] = pSliceHeader->uiRefCount[0];532 pRefCount[0] = pSliceHeader->uiRefCount[0];
533 pRefCount[1] = pSliceHeader->uiRefCount[1];533 pRefCount[1] = pSliceHeader->uiRefCount[1];
534 534
535 switch (pCurDqLayer->pMbType[iMbXy]) {535 switch (pCurDqLayer->pMbType[iMbXy]) {
536 case MB_TYPE_16x16: {536 case MB_TYPE_16x16: {
537 iPartIdx = 0;537 iPartIdx = 0;
538 WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, 0, LIST_0, iPartIdx, pRefCount[0], 0,538 WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, 0, LIST_0, iPartIdx, pRefCount[0], 0,
539 iRef[0]));539 iRef[0]));
540 if ((iRef[0] < 0) || (iRef[0] >= pRefCount[0]) || (ppRefPic[iRef[0]] == NULL)) { //error ref_idx540 if ((iRef[0] < 0) || (iRef[0] >= pRefCount[0]) || (ppRefPic[iRef[0]] == NULL)) { //error ref_idx
541 pCtx->bMbRefConcealed = true;541 pCtx->bMbRefConcealed = true;
542 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {542 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {
543 iRef[0] = 0;543 iRef[0] = 0;
544 pCtx->iErrorCode |= dsBitstreamError;544 pCtx->iErrorCode |= dsBitstreamError;
545 } else {545 } else {
546 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);546 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);
547 }547 }
548 }548 }
549 pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRef[0]]549 pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRef[0]]
550 && ppRefPic[iRef[0]]->bIsComplete);550 && ppRefPic[iRef[0]]->bIsComplete);
551 PredMv (pMotionVector, pRefIndex, LIST_0, 0, 4, iRef[0], pMv);551 PredMv (pMotionVector, pRefIndex, LIST_0, 0, 4, iRef[0], pMv);
552 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 0, pMvd[0]));552 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 0, pMvd[0]));
553 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 1, pMvd[1]));553 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 1, pMvd[1]));
554 pMv[0] += pMvd[0];554 pMv[0] += pMvd[0];
555 pMv[1] += pMvd[1];555 pMv[1] += pMvd[1];
556 WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv");556 WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv");
557 UpdateP16x16MotionInfo (pCurDqLayer, LIST_0, iRef[0], pMv);557 UpdateP16x16MotionInfo (pCurDqLayer, LIST_0, iRef[0], pMv);
558 UpdateP16x16MvdCabac (pCurDqLayer, pMvd, LIST_0);558 UpdateP16x16MvdCabac (pCurDqLayer, pMvd, LIST_0);
559 }559 }
560 break;560 break;
561 case MB_TYPE_16x8:561 case MB_TYPE_16x8:
562 for (i = 0; i < 2; i++) {562 for (i = 0; i < 2; i++) {
563 iPartIdx = i << 3;563 iPartIdx = i << 3;
564 WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, 0, LIST_0, iPartIdx, pRefCount[0], 0,564 WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, 0, LIST_0, iPartIdx, pRefCount[0], 0,
565 iRef[i]));565 iRef[i]));
566 if ((iRef[i] < 0) || (iRef[i] >= pRefCount[0]) || (ppRefPic[iRef[i]] == NULL)) { //error ref_idx566 if ((iRef[i] < 0) || (iRef[i] >= pRefCount[0]) || (ppRefPic[iRef[i]] == NULL)) { //error ref_idx
567 pCtx->bMbRefConcealed = true;567 pCtx->bMbRefConcealed = true;
568 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {568 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {
569 iRef[i] = 0;569 iRef[i] = 0;
570 pCtx->iErrorCode |= dsBitstreamError;570 pCtx->iErrorCode |= dsBitstreamError;
571 } else {571 } else {
572 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);572 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);
573 }573 }
574 }574 }
575 pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRef[i]]575 pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRef[i]]
576 && ppRefPic[iRef[i]]->bIsComplete);576 && ppRefPic[iRef[i]]->bIsComplete);
577 UpdateP16x8RefIdxCabac (pCurDqLayer, pRefIndex, iPartIdx, iRef[i], LIST_0);577 UpdateP16x8RefIdxCabac (pCurDqLayer, pRefIndex, iPartIdx, iRef[i], LIST_0);
578 }578 }
579 for (i = 0; i < 2; i++) {579 for (i = 0; i < 2; i++) {
580 iPartIdx = i << 3;580 iPartIdx = i << 3;
581 PredInter16x8Mv (pMotionVector, pRefIndex, LIST_0, iPartIdx, iRef[i], pMv);581 PredInter16x8Mv (pMotionVector, pRefIndex, LIST_0, iPartIdx, iRef[i], pMv);
582 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 0, pMvd[0]));582 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 0, pMvd[0]));
583 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 1, pMvd[1]));583 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 1, pMvd[1]));
584 pMv[0] += pMvd[0];584 pMv[0] += pMvd[0];
585 pMv[1] += pMvd[1];585 pMv[1] += pMvd[1];
586 WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv");586 WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv");
587 UpdateP16x8MotionInfo (pCurDqLayer, pMotionVector, pRefIndex, LIST_0, iPartIdx, iRef[i], pMv);587 UpdateP16x8MotionInfo (pCurDqLayer, pMotionVector, pRefIndex, LIST_0, iPartIdx, iRef[i], pMv);
588 UpdateP16x8MvdCabac (pCurDqLayer, pMvdCache, iPartIdx, pMvd, LIST_0);588 UpdateP16x8MvdCabac (pCurDqLayer, pMvdCache, iPartIdx, pMvd, LIST_0);
589 }589 }
590 break;590 break;
591 case MB_TYPE_8x16:591 case MB_TYPE_8x16:
592 for (i = 0; i < 2; i++) {592 for (i = 0; i < 2; i++) {
593 iPartIdx = i << 2;593 iPartIdx = i << 2;
594 WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, 0, LIST_0, iPartIdx, pRefCount[0], 0,594 WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, 0, LIST_0, iPartIdx, pRefCount[0], 0,
595 iRef[i]));595 iRef[i]));
596 if ((iRef[i] < 0) || (iRef[i] >= pRefCount[0]) || (ppRefPic[iRef[i]] == NULL)) { //error ref_idx596 if ((iRef[i] < 0) || (iRef[i] >= pRefCount[0]) || (ppRefPic[iRef[i]] == NULL)) { //error ref_idx
597 pCtx->bMbRefConcealed = true;597 pCtx->bMbRefConcealed = true;
598 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {598 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {
599 iRef[i] = 0;599 iRef[i] = 0;
600 pCtx->iErrorCode |= dsBitstreamError;600 pCtx->iErrorCode |= dsBitstreamError;
601 } else {601 } else {
602 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);602 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);
603 }603 }
604 }604 }
605 pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRef[i]]605 pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRef[i]]
606 && ppRefPic[iRef[i]]->bIsComplete);606 && ppRefPic[iRef[i]]->bIsComplete);
607 UpdateP8x16RefIdxCabac (pCurDqLayer, pRefIndex, iPartIdx, iRef[i], LIST_0);607 UpdateP8x16RefIdxCabac (pCurDqLayer, pRefIndex, iPartIdx, iRef[i], LIST_0);
608 }608 }
609 for (i = 0; i < 2; i++) {609 for (i = 0; i < 2; i++) {
610 iPartIdx = i << 2;610 iPartIdx = i << 2;
611 PredInter8x16Mv (pMotionVector, pRefIndex, LIST_0, i << 2, iRef[i], pMv/*&mv[0], &mv[1]*/);611 PredInter8x16Mv (pMotionVector, pRefIndex, LIST_0, i << 2, iRef[i], pMv/*&mv[0], &mv[1]*/);
612 612
613 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 0, pMvd[0]));613 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 0, pMvd[0]));
614 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 1, pMvd[1]));614 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 1, pMvd[1]));
615 pMv[0] += pMvd[0];615 pMv[0] += pMvd[0];
616 pMv[1] += pMvd[1];616 pMv[1] += pMvd[1];
617 WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv");617 WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv");
618 UpdateP8x16MotionInfo (pCurDqLayer, pMotionVector, pRefIndex, LIST_0, iPartIdx, iRef[i], pMv);618 UpdateP8x16MotionInfo (pCurDqLayer, pMotionVector, pRefIndex, LIST_0, iPartIdx, iRef[i], pMv);
619 UpdateP8x16MvdCabac (pCurDqLayer, pMvdCache, iPartIdx, pMvd, LIST_0);619 UpdateP8x16MvdCabac (pCurDqLayer, pMvdCache, iPartIdx, pMvd, LIST_0);
620 }620 }
621 break;621 break;
622 case MB_TYPE_8x8:622 case MB_TYPE_8x8:
623 case MB_TYPE_8x8_REF0: {623 case MB_TYPE_8x8_REF0: {
624 int8_t pRefIdx[4] = {0}, pSubPartCount[4], pPartW[4];624 int8_t pRefIdx[4] = {0}, pSubPartCount[4], pPartW[4];
625 uint32_t uiSubMbType;625 uint32_t uiSubMbType;
626 //sub_mb_type, partition626 //sub_mb_type, partition
627 for (i = 0; i < 4; i++) {627 for (i = 0; i < 4; i++) {
628 WELS_READ_VERIFY (ParseSubMBTypeCabac (pCtx, pNeighAvail, uiSubMbType));628 WELS_READ_VERIFY (ParseSubMBTypeCabac (pCtx, pNeighAvail, uiSubMbType));
629 if (uiSubMbType >= 4) { //invalid sub_mb_type629 if (uiSubMbType >= 4) { //invalid sub_mb_type
630 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_SUB_MB_TYPE);630 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_SUB_MB_TYPE);
631 }631 }
632 pCurDqLayer->pSubMbType[iMbXy][i] = g_ksInterPSubMbTypeInfo[uiSubMbType].iType;632 pCurDqLayer->pSubMbType[iMbXy][i] = g_ksInterPSubMbTypeInfo[uiSubMbType].iType;
633 pSubPartCount[i] = g_ksInterPSubMbTypeInfo[uiSubMbType].iPartCount;633 pSubPartCount[i] = g_ksInterPSubMbTypeInfo[uiSubMbType].iPartCount;
634 pPartW[i] = g_ksInterPSubMbTypeInfo[uiSubMbType].iPartWidth;634 pPartW[i] = g_ksInterPSubMbTypeInfo[uiSubMbType].iPartWidth;
635 635
636 // Need modification when B picture add in, reference to 7.3.5636 // Need modification when B picture add in, reference to 7.3.5
637 pCurDqLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] &= (uiSubMbType == 0);637 pCurDqLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] &= (uiSubMbType == 0);
638 }638 }
639 639
640 for (i = 0; i < 4; i++) {640 for (i = 0; i < 4; i++) {
641 int16_t iIdx8 = i << 2;641 int16_t iIdx8 = i << 2;
642 WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, 0, LIST_0, iIdx8, pRefCount[0], 1,642 WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, 0, LIST_0, iIdx8, pRefCount[0], 1,
643 pRefIdx[i]));643 pRefIdx[i]));
644 if ((pRefIdx[i] < 0) || (pRefIdx[i] >= pRefCount[0]) || (ppRefPic[pRefIdx[i]] == NULL)) { //error ref_idx644 if ((pRefIdx[i] < 0) || (pRefIdx[i] >= pRefCount[0]) || (ppRefPic[pRefIdx[i]] == NULL)) { //error ref_idx
645 pCtx->bMbRefConcealed = true;645 pCtx->bMbRefConcealed = true;
646 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {646 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {
647 pRefIdx[i] = 0;647 pRefIdx[i] = 0;
648 pCtx->iErrorCode |= dsBitstreamError;648 pCtx->iErrorCode |= dsBitstreamError;
649 } else {649 } else {
650 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);650 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);
651 }651 }
652 }652 }
653 pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[pRefIdx[i]]653 pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[pRefIdx[i]]
654 && ppRefPic[pRefIdx[i]]->bIsComplete);654 && ppRefPic[pRefIdx[i]]->bIsComplete);
655 UpdateP8x8RefIdxCabac (pCurDqLayer, pRefIndex, iIdx8, pRefIdx[i], LIST_0);655 UpdateP8x8RefIdxCabac (pCurDqLayer, pRefIndex, iIdx8, pRefIdx[i], LIST_0);
656 }656 }
657 //mv657 //mv
658 for (i = 0; i < 4; i++) {658 for (i = 0; i < 4; i++) {
659 int8_t iPartCount = pSubPartCount[i];659 int8_t iPartCount = pSubPartCount[i];
660 uiSubMbType = pCurDqLayer->pSubMbType[iMbXy][i];660 uiSubMbType = pCurDqLayer->pSubMbType[iMbXy][i];
661 int16_t iPartIdx, iBlockW = pPartW[i];661 int16_t iPartIdx, iBlockW = pPartW[i];
662 uint8_t iScan4Idx, iCacheIdx;662 uint8_t iScan4Idx, iCacheIdx;
663 iCacheIdx = g_kuiCache30ScanIdx[i << 2];663 iCacheIdx = g_kuiCache30ScanIdx[i << 2];
664 pRefIndex[0][iCacheIdx ] = pRefIndex[0][iCacheIdx + 1]664 pRefIndex[0][iCacheIdx ] = pRefIndex[0][iCacheIdx + 1]
665 = pRefIndex[0][iCacheIdx + 6] = pRefIndex[0][iCacheIdx + 7] = pRefIdx[i];665 = pRefIndex[0][iCacheIdx + 6] = pRefIndex[0][iCacheIdx + 7] = pRefIdx[i];
666 666
667 for (j = 0; j < iPartCount; j++) {667 for (j = 0; j < iPartCount; j++) {
668 iPartIdx = (i << 2) + j * iBlockW;668 iPartIdx = (i << 2) + j * iBlockW;
669 iScan4Idx = g_kuiScan4[iPartIdx];669 iScan4Idx = g_kuiScan4[iPartIdx];
670 iCacheIdx = g_kuiCache30ScanIdx[iPartIdx];670 iCacheIdx = g_kuiCache30ScanIdx[iPartIdx];
671 PredMv (pMotionVector, pRefIndex, LIST_0, iPartIdx, iBlockW, pRefIdx[i], pMv);671 PredMv (pMotionVector, pRefIndex, LIST_0, iPartIdx, iBlockW, pRefIdx[i], pMv);
672 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 0, pMvd[0]));672 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 0, pMvd[0]));
673 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 1, pMvd[1]));673 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 1, pMvd[1]));
674 pMv[0] += pMvd[0];674 pMv[0] += pMvd[0];
675 pMv[1] += pMvd[1];675 pMv[1] += pMvd[1];
676 WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv");676 WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv");
677 if (SUB_MB_TYPE_8x8 == uiSubMbType) {677 if (SUB_MB_TYPE_8x8 == uiSubMbType) {
678 ST32 ((pMv + 2), LD32 (pMv));678 ST32 ((pMv + 2), LD32 (pMv));
679 ST32 ((pMvd + 2), LD32 (pMvd));679 ST32 ((pMvd + 2), LD32 (pMvd));
680 ST64 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx], LD64 (pMv));680 ST64 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx], LD64 (pMv));
681 ST64 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx + 4], LD64 (pMv));681 ST64 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx + 4], LD64 (pMv));
682 ST64 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx], LD64 (pMvd));682 ST64 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx], LD64 (pMvd));
683 ST64 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx + 4], LD64 (pMvd));683 ST64 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx + 4], LD64 (pMvd));
684 ST64 (pMotionVector[0][iCacheIdx ], LD64 (pMv));684 ST64 (pMotionVector[0][iCacheIdx ], LD64 (pMv));
685 ST64 (pMotionVector[0][iCacheIdx + 6], LD64 (pMv));685 ST64 (pMotionVector[0][iCacheIdx + 6], LD64 (pMv));
686 ST64 (pMvdCache[0][iCacheIdx ], LD64 (pMvd));686 ST64 (pMvdCache[0][iCacheIdx ], LD64 (pMvd));
687 ST64 (pMvdCache[0][iCacheIdx + 6], LD64 (pMvd));687 ST64 (pMvdCache[0][iCacheIdx + 6], LD64 (pMvd));
688 } else if (SUB_MB_TYPE_8x4 == uiSubMbType) {688 } else if (SUB_MB_TYPE_8x4 == uiSubMbType) {
689 ST32 ((pMv + 2), LD32 (pMv));689 ST32 ((pMv + 2), LD32 (pMv));
690 ST32 ((pMvd + 2), LD32 (pMvd));690 ST32 ((pMvd + 2), LD32 (pMvd));
691 ST64 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx ], LD64 (pMv));691 ST64 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx ], LD64 (pMv));
692 ST64 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx ], LD64 (pMvd));692 ST64 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx ], LD64 (pMvd));
693 ST64 (pMotionVector[0][iCacheIdx ], LD64 (pMv));693 ST64 (pMotionVector[0][iCacheIdx ], LD64 (pMv));
694 ST64 (pMvdCache[0][iCacheIdx ], LD64 (pMvd));694 ST64 (pMvdCache[0][iCacheIdx ], LD64 (pMvd));
695 } else if (SUB_MB_TYPE_4x8 == uiSubMbType) {695 } else if (SUB_MB_TYPE_4x8 == uiSubMbType) {
696 ST32 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx ], LD32 (pMv));696 ST32 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx ], LD32 (pMv));
697 ST32 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx + 4], LD32 (pMv));697 ST32 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx + 4], LD32 (pMv));
698 ST32 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx ], LD32 (pMvd));698 ST32 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx ], LD32 (pMvd));
699 ST32 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx + 4], LD32 (pMvd));699 ST32 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx + 4], LD32 (pMvd));
700 ST32 (pMotionVector[0][iCacheIdx ], LD32 (pMv));700 ST32 (pMotionVector[0][iCacheIdx ], LD32 (pMv));
701 ST32 (pMotionVector[0][iCacheIdx + 6], LD32 (pMv));701 ST32 (pMotionVector[0][iCacheIdx + 6], LD32 (pMv));
702 ST32 (pMvdCache[0][iCacheIdx ], LD32 (pMvd));702 ST32 (pMvdCache[0][iCacheIdx ], LD32 (pMvd));
703 ST32 (pMvdCache[0][iCacheIdx + 6], LD32 (pMvd));703 ST32 (pMvdCache[0][iCacheIdx + 6], LD32 (pMvd));
704 } else { //SUB_MB_TYPE_4x4704 } else { //SUB_MB_TYPE_4x4
705 ST32 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx ], LD32 (pMv));705 ST32 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx ], LD32 (pMv));
706 ST32 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx ], LD32 (pMvd));706 ST32 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx ], LD32 (pMvd));
707 ST32 (pMotionVector[0][iCacheIdx ], LD32 (pMv));707 ST32 (pMotionVector[0][iCacheIdx ], LD32 (pMv));
708 ST32 (pMvdCache[0][iCacheIdx ], LD32 (pMvd));708 ST32 (pMvdCache[0][iCacheIdx ], LD32 (pMvd));
709 }709 }
710 }710 }
711 }711 }
712 }712 }
713 break;713 break;
714 default:714 default:
715 break;715 break;
716 }716 }
717 return ERR_NONE;717 return ERR_NONE;
718}718}
719 719
720int32_t ParseInterBMotionInfoCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCount,720int32_t ParseInterBMotionInfoCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCount,
721 int16_t pMotionVector[LIST_A][30][MV_A], int16_t pMvdCache[LIST_A][30][MV_A], int8_t pRefIndex[LIST_A][30],721 int16_t pMotionVector[LIST_A][30][MV_A], int16_t pMvdCache[LIST_A][30][MV_A], int8_t pRefIndex[LIST_A][30],
722 int8_t pDirect[30]) {722 int8_t pDirect[30]) {
723 PSlice pSlice = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer;723 PSlice pSlice = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer;
724 PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader;724 PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader;
725 PDqLayer pCurDqLayer = pCtx->pCurDqLayer;725 PDqLayer pCurDqLayer = pCtx->pCurDqLayer;
726 int32_t pRefCount[LIST_A];726 int32_t pRefCount[LIST_A];
727 int32_t iMbXy = pCurDqLayer->iMbXyIndex;727 int32_t iMbXy = pCurDqLayer->iMbXyIndex;
728 int16_t pMv[4] = { 0 };728 int16_t pMv[4] = { 0 };
729 int16_t pMvd[4] = { 0 };729 int16_t pMvd[4] = { 0 };
730 int8_t iRef[LIST_A] = { 0 };730 int8_t iRef[LIST_A] = { 0 };
731 int32_t iPartIdx;731 int32_t iPartIdx;
732 int16_t iMinVmv = pSliceHeader->pSps->pSLevelLimits->iMinVmv;732 int16_t iMinVmv = pSliceHeader->pSps->pSLevelLimits->iMinVmv;
733 int16_t iMaxVmv = pSliceHeader->pSps->pSLevelLimits->iMaxVmv;733 int16_t iMaxVmv = pSliceHeader->pSps->pSLevelLimits->iMaxVmv;
734 pRefCount[0] = pSliceHeader->uiRefCount[0];734 pRefCount[0] = pSliceHeader->uiRefCount[0];
735 pRefCount[1] = pSliceHeader->uiRefCount[1];735 pRefCount[1] = pSliceHeader->uiRefCount[1];
736 736
737 MbType mbType = pCurDqLayer->pMbType[iMbXy];737 MbType mbType = pCurDqLayer->pMbType[iMbXy];
738 738
739 if (IS_DIRECT (mbType)) {739 if (IS_DIRECT (mbType)) {
740 740
741 int16_t pMvDirect[LIST_A][2] = { { 0, 0 }, { 0, 0 } };741 int16_t pMvDirect[LIST_A][2] = { { 0, 0 }, { 0, 0 } };
742 if (pSliceHeader->iDirectSpatialMvPredFlag) {742 if (pSliceHeader->iDirectSpatialMvPredFlag) {
743 //predict direct spatial mv743 //predict direct spatial mv
744 PredMvBDirectSpatial (pCtx, pMvDirect, iRef);744 PredMvBDirectSpatial (pCtx, pMvDirect, iRef);
745 } else {745 } else {
746 //temporal direct 16x16 mode746 //temporal direct 16x16 mode
747 ComputeColocated (pCtx);747 ComputeColocated (pCtx);
748 PredBDirectTemporal (pCtx, pMvDirect, iRef);748 PredBDirectTemporal (pCtx, pMvDirect, iRef);
749 }749 }
750 } else if (IS_INTER_16x16 (mbType)) {750 } else if (IS_INTER_16x16 (mbType)) {
751 iPartIdx = 0;751 iPartIdx = 0;
752 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {752 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
753 iRef[listIdx] = REF_NOT_IN_LIST;753 iRef[listIdx] = REF_NOT_IN_LIST;
754 if (IS_DIR (mbType, 0, listIdx)) {754 if (IS_DIR (mbType, 0, listIdx)) {
755 WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, pDirect, listIdx, iPartIdx,755 WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, pDirect, listIdx, iPartIdx,
756 pRefCount[listIdx], 0,756 pRefCount[listIdx], 0,
757 iRef[listIdx]));757 iRef[listIdx]));
758 if ((iRef[listIdx] < 0) || (iRef[listIdx] >= pRefCount[listIdx])758 if ((iRef[listIdx] < 0) || (iRef[listIdx] >= pRefCount[listIdx])
759 || (pCtx->sRefPic.pRefList[listIdx][iRef[listIdx]] == NULL)) { //error ref_idx759 || (pCtx->sRefPic.pRefList[listIdx][iRef[listIdx]] == NULL)) { //error ref_idx
760 pCtx->bMbRefConcealed = true;760 pCtx->bMbRefConcealed = true;
761 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {761 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {
762 iRef[listIdx] = 0;762 iRef[listIdx] = 0;
763 pCtx->iErrorCode |= dsBitstreamError;763 pCtx->iErrorCode |= dsBitstreamError;
764 } else {764 } else {
765 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);765 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);
766 }766 }
767 }767 }
768 pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (pCtx->sRefPic.pRefList[listIdx][iRef[listIdx]]768 pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (pCtx->sRefPic.pRefList[listIdx][iRef[listIdx]]
769 && pCtx->sRefPic.pRefList[listIdx][iRef[listIdx]]->bIsComplete);769 && pCtx->sRefPic.pRefList[listIdx][iRef[listIdx]]->bIsComplete);
770 }770 }
771 }771 }
772 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {772 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
773 if (IS_DIR (mbType, 0, listIdx)) {773 if (IS_DIR (mbType, 0, listIdx)) {
774 PredMv (pMotionVector, pRefIndex, listIdx, 0, 4, iRef[listIdx], pMv);774 PredMv (pMotionVector, pRefIndex, listIdx, 0, 4, iRef[listIdx], pMv);
775 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, listIdx, 0, pMvd[0]));775 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, listIdx, 0, pMvd[0]));
776 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, listIdx, 1, pMvd[1]));776 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, listIdx, 1, pMvd[1]));
777 pMv[0] += pMvd[0];777 pMv[0] += pMvd[0];
778 pMv[1] += pMvd[1];778 pMv[1] += pMvd[1];
779 WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv");779 WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv");
780 } else {780 } else {
781 * (uint32_t*)pMv = * (uint32_t*)pMvd = 0;781 * (uint32_t*)pMv = * (uint32_t*)pMvd = 0;
782 }782 }
783 UpdateP16x16MotionInfo (pCurDqLayer, listIdx, iRef[listIdx], pMv);783 UpdateP16x16MotionInfo (pCurDqLayer, listIdx, iRef[listIdx], pMv);
784 UpdateP16x16MvdCabac (pCurDqLayer, pMvd, listIdx);784 UpdateP16x16MvdCabac (pCurDqLayer, pMvd, listIdx);
785 }785 }
786 } else if (IS_INTER_16x8 (mbType)) {786 } else if (IS_INTER_16x8 (mbType)) {
787 int8_t ref_idx_list[LIST_A][2] = { {REF_NOT_IN_LIST, REF_NOT_IN_LIST}, { REF_NOT_IN_LIST, REF_NOT_IN_LIST } };787 int8_t ref_idx_list[LIST_A][2] = { {REF_NOT_IN_LIST, REF_NOT_IN_LIST}, { REF_NOT_IN_LIST, REF_NOT_IN_LIST } };
788 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {788 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
789 for (int32_t i = 0; i < 2; ++i) {789 for (int32_t i = 0; i < 2; ++i) {
790 iPartIdx = i << 3;790 iPartIdx = i << 3;
791 int8_t ref_idx = REF_NOT_IN_LIST;791 int8_t ref_idx = REF_NOT_IN_LIST;
792 if (IS_DIR (mbType, i, listIdx)) {792 if (IS_DIR (mbType, i, listIdx)) {
793 WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, pDirect, listIdx, iPartIdx,793 WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, pDirect, listIdx, iPartIdx,
794 pRefCount[listIdx], 0, ref_idx));794 pRefCount[listIdx], 0, ref_idx));
795 if ((ref_idx < 0) || (ref_idx >= pRefCount[listIdx])795 if ((ref_idx < 0) || (ref_idx >= pRefCount[listIdx])
796 || (pCtx->sRefPic.pRefList[listIdx][ref_idx] == NULL)) { //error ref_idx796 || (pCtx->sRefPic.pRefList[listIdx][ref_idx] == NULL)) { //error ref_idx
797 pCtx->bMbRefConcealed = true;797 pCtx->bMbRefConcealed = true;
798 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {798 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {
799 ref_idx = 0;799 ref_idx = 0;
800 pCtx->iErrorCode |= dsBitstreamError;800 pCtx->iErrorCode |= dsBitstreamError;
801 } else {801 } else {
802 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);802 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);
803 }803 }
804 }804 }
805 pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (pCtx->sRefPic.pRefList[listIdx][ref_idx]805 pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (pCtx->sRefPic.pRefList[listIdx][ref_idx]
806 && pCtx->sRefPic.pRefList[listIdx][ref_idx]->bIsComplete);806 && pCtx->sRefPic.pRefList[listIdx][ref_idx]->bIsComplete);
807 }807 }
808 UpdateP16x8RefIdxCabac (pCurDqLayer, pRefIndex, iPartIdx, ref_idx, listIdx);808 UpdateP16x8RefIdxCabac (pCurDqLayer, pRefIndex, iPartIdx, ref_idx, listIdx);
809 ref_idx_list[listIdx][i] = ref_idx;809 ref_idx_list[listIdx][i] = ref_idx;
810 }810 }
811 }811 }
812 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {812 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
813 for (int32_t i = 0; i < 2; ++i) {813 for (int32_t i = 0; i < 2; ++i) {
814 iPartIdx = i << 3;814 iPartIdx = i << 3;
815 int8_t ref_idx = ref_idx_list[listIdx][i];815 int8_t ref_idx = ref_idx_list[listIdx][i];
816 if (IS_DIR (mbType, i, listIdx)) {816 if (IS_DIR (mbType, i, listIdx)) {
817 PredInter16x8Mv (pMotionVector, pRefIndex, listIdx, iPartIdx, ref_idx, pMv);817 PredInter16x8Mv (pMotionVector, pRefIndex, listIdx, iPartIdx, ref_idx, pMv);
818 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, listIdx, 0, pMvd[0]));818 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, listIdx, 0, pMvd[0]));
819 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, listIdx, 1, pMvd[1]));819 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, listIdx, 1, pMvd[1]));
820 pMv[0] += pMvd[0];820 pMv[0] += pMvd[0];
821 pMv[1] += pMvd[1];821 pMv[1] += pMvd[1];
822 WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv");822 WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv");
823 } else {823 } else {
824 * (uint32_t*)pMv = * (uint32_t*)pMvd = 0;824 * (uint32_t*)pMv = * (uint32_t*)pMvd = 0;
825 }825 }
826 UpdateP16x8MotionInfo (pCurDqLayer, pMotionVector, pRefIndex, listIdx, iPartIdx, ref_idx, pMv);826 UpdateP16x8MotionInfo (pCurDqLayer, pMotionVector, pRefIndex, listIdx, iPartIdx, ref_idx, pMv);
827 UpdateP16x8MvdCabac (pCurDqLayer, pMvdCache, iPartIdx, pMvd, listIdx);827 UpdateP16x8MvdCabac (pCurDqLayer, pMvdCache, iPartIdx, pMvd, listIdx);
828 }828 }
829 }829 }
830 } else if (IS_INTER_8x16 (mbType)) {830 } else if (IS_INTER_8x16 (mbType)) {
831 int8_t ref_idx_list[LIST_A][2] = { { REF_NOT_IN_LIST, REF_NOT_IN_LIST }, { REF_NOT_IN_LIST, REF_NOT_IN_LIST } };831 int8_t ref_idx_list[LIST_A][2] = { { REF_NOT_IN_LIST, REF_NOT_IN_LIST }, { REF_NOT_IN_LIST, REF_NOT_IN_LIST } };
832 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {832 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
833 for (int32_t i = 0; i < 2; ++i) {833 for (int32_t i = 0; i < 2; ++i) {
834 iPartIdx = i << 2;834 iPartIdx = i << 2;
835 int8_t ref_idx = REF_NOT_IN_LIST;835 int8_t ref_idx = REF_NOT_IN_LIST;
836 if (IS_DIR (mbType, i, listIdx)) {836 if (IS_DIR (mbType, i, listIdx)) {
837 WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, pDirect, listIdx, iPartIdx,837 WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, pDirect, listIdx, iPartIdx,
838 pRefCount[listIdx], 0, ref_idx));838 pRefCount[listIdx], 0, ref_idx));
839 if ((ref_idx < 0) || (ref_idx >= pRefCount[listIdx])839 if ((ref_idx < 0) || (ref_idx >= pRefCount[listIdx])
840 || (pCtx->sRefPic.pRefList[listIdx][ref_idx] == NULL)) { //error ref_idx840 || (pCtx->sRefPic.pRefList[listIdx][ref_idx] == NULL)) { //error ref_idx
841 pCtx->bMbRefConcealed = true;841 pCtx->bMbRefConcealed = true;
842 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {842 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {
843 ref_idx = 0;843 ref_idx = 0;
844 pCtx->iErrorCode |= dsBitstreamError;844 pCtx->iErrorCode |= dsBitstreamError;
845 } else {845 } else {
846 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);846 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);
847 }847 }
848 }848 }
849 pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (pCtx->sRefPic.pRefList[listIdx][ref_idx]849 pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (pCtx->sRefPic.pRefList[listIdx][ref_idx]
850 && pCtx->sRefPic.pRefList[listIdx][ref_idx]->bIsComplete);850 && pCtx->sRefPic.pRefList[listIdx][ref_idx]->bIsComplete);
851 }851 }
852 UpdateP8x16RefIdxCabac (pCurDqLayer, pRefIndex, iPartIdx, ref_idx, listIdx);852 UpdateP8x16RefIdxCabac (pCurDqLayer, pRefIndex, iPartIdx, ref_idx, listIdx);
853 ref_idx_list[listIdx][i] = ref_idx;853 ref_idx_list[listIdx][i] = ref_idx;
854 }854 }
855 }855 }
856 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {856 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
857 for (int32_t i = 0; i < 2; ++i) {857 for (int32_t i = 0; i < 2; ++i) {
858 iPartIdx = i << 2;858 iPartIdx = i << 2;
859 int8_t ref_idx = ref_idx_list[listIdx][i];859 int8_t ref_idx = ref_idx_list[listIdx][i];
860 if (IS_DIR (mbType, i, listIdx)) {860 if (IS_DIR (mbType, i, listIdx)) {
861 PredInter8x16Mv (pMotionVector, pRefIndex, listIdx, iPartIdx, ref_idx, pMv);861 PredInter8x16Mv (pMotionVector, pRefIndex, listIdx, iPartIdx, ref_idx, pMv);
862 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, listIdx, 0, pMvd[0]));862 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, listIdx, 0, pMvd[0]));
863 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, listIdx, 1, pMvd[1]));863 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, listIdx, 1, pMvd[1]));
864 pMv[0] += pMvd[0];864 pMv[0] += pMvd[0];
865 pMv[1] += pMvd[1];865 pMv[1] += pMvd[1];
866 WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv");866 WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv");
867 } else {867 } else {
868 * (uint32_t*)pMv = * (uint32_t*)pMvd = 0;868 * (uint32_t*)pMv = * (uint32_t*)pMvd = 0;
869 }869 }
870 UpdateP8x16MotionInfo (pCurDqLayer, pMotionVector, pRefIndex, listIdx, iPartIdx, ref_idx, pMv);870 UpdateP8x16MotionInfo (pCurDqLayer, pMotionVector, pRefIndex, listIdx, iPartIdx, ref_idx, pMv);
871 UpdateP8x16MvdCabac (pCurDqLayer, pMvdCache, iPartIdx, pMvd, listIdx);871 UpdateP8x16MvdCabac (pCurDqLayer, pMvdCache, iPartIdx, pMvd, listIdx);
872 }872 }
873 }873 }
874 } else if (IS_Inter_8x8 (mbType)) {874 } else if (IS_Inter_8x8 (mbType)) {
875 int8_t pSubPartCount[4], pPartW[4];875 int8_t pSubPartCount[4], pPartW[4];
876 uint32_t uiSubMbType;876 uint32_t uiSubMbType;
877 //sub_mb_type, partition877 //sub_mb_type, partition
878 int16_t pMvDirect[LIST_A][2] = { {0, 0}, {0, 0} };878 int16_t pMvDirect[LIST_A][2] = { {0, 0}, {0, 0} };
879 bool has_direct_called = false;879 bool has_direct_called = false;
880 SubMbType directSubMbType = 0;880 SubMbType directSubMbType = 0;
881 for (int32_t i = 0; i < 4; i++) {881 for (int32_t i = 0; i < 4; i++) {
882 WELS_READ_VERIFY (ParseBSubMBTypeCabac (pCtx, pNeighAvail, uiSubMbType));882 WELS_READ_VERIFY (ParseBSubMBTypeCabac (pCtx, pNeighAvail, uiSubMbType));
883 if (uiSubMbType > 13) { //invalid sub_mb_type883 if (uiSubMbType > 13) { //invalid sub_mb_type
884 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_SUB_MB_TYPE);884 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_SUB_MB_TYPE);
885 }885 }
886// pCurDqLayer->pSubMbType[iMbXy][i] = g_ksInterBSubMbTypeInfo[uiSubMbType].iType;886// pCurDqLayer->pSubMbType[iMbXy][i] = g_ksInterBSubMbTypeInfo[uiSubMbType].iType;
887 pSubPartCount[i] = g_ksInterBSubMbTypeInfo[uiSubMbType].iPartCount;887 pSubPartCount[i] = g_ksInterBSubMbTypeInfo[uiSubMbType].iPartCount;
888 pPartW[i] = g_ksInterBSubMbTypeInfo[uiSubMbType].iPartWidth;888 pPartW[i] = g_ksInterBSubMbTypeInfo[uiSubMbType].iPartWidth;
889 889
890 // Need modification when B picture add in, reference to 7.3.5890 // Need modification when B picture add in, reference to 7.3.5
891 if (pSubPartCount[i] > 1)891 if (pSubPartCount[i] > 1)
892 pCurDqLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = false;892 pCurDqLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = false;
893 893
894 if (IS_DIRECT (g_ksInterBSubMbTypeInfo[uiSubMbType].iType)) {894 if (IS_DIRECT (g_ksInterBSubMbTypeInfo[uiSubMbType].iType)) {
895 if (!has_direct_called) {895 if (!has_direct_called) {
896 if (pSliceHeader->iDirectSpatialMvPredFlag) {896 if (pSliceHeader->iDirectSpatialMvPredFlag) {
897 directSubMbType = PredMvBDirectSpatial (pCtx, pMvDirect, iRef);897 directSubMbType = PredMvBDirectSpatial (pCtx, pMvDirect, iRef);
898 } else {898 } else {
899 //temporal direct mode899 //temporal direct mode
900 ComputeColocated (pCtx);900 ComputeColocated (pCtx);
901 PredBDirectTemporal (pCtx, pMvDirect, iRef);901 PredBDirectTemporal (pCtx, pMvDirect, iRef);
902 }902 }
903 has_direct_called = true;903 has_direct_called = true;
904 }904 }
905 pCurDqLayer->pSubMbType[iMbXy][i] = directSubMbType;905 pCurDqLayer->pSubMbType[iMbXy][i] = directSubMbType;
906 if (IS_SUB_4x4 (pCurDqLayer->pSubMbType[iMbXy][i])) {906 if (IS_SUB_4x4 (pCurDqLayer->pSubMbType[iMbXy][i])) {
907 pSubPartCount[i] = 4;907 pSubPartCount[i] = 4;
908 pPartW[i] = 1;908 pPartW[i] = 1;
909 }909 }
910 } else {910 } else {
911 pCurDqLayer->pSubMbType[iMbXy][i] = g_ksInterBSubMbTypeInfo[uiSubMbType].iType;911 pCurDqLayer->pSubMbType[iMbXy][i] = g_ksInterBSubMbTypeInfo[uiSubMbType].iType;
912 }912 }
913 }913 }
914 for (int32_t i = 0; i < 4; i++) { //Direct 8x8 Ref and mv914 for (int32_t i = 0; i < 4; i++) { //Direct 8x8 Ref and mv
915 915
916 int16_t iIdx8 = i << 2;916 int16_t iIdx8 = i << 2;
917 if (IS_DIRECT (pCurDqLayer->pSubMbType[iMbXy][i])) {917 if (IS_DIRECT (pCurDqLayer->pSubMbType[iMbXy][i])) {
918 918
919 int8_t iPartCount = pSubPartCount[i];919 int8_t iPartCount = pSubPartCount[i];
920 int16_t iPartIdx, iBlockW = pPartW[i];920 int16_t iPartIdx, iBlockW = pPartW[i];
921 uint8_t iScan4Idx, iCacheIdx, iColocIdx;921 uint8_t iScan4Idx, iCacheIdx, iColocIdx;
922 iCacheIdx = g_kuiCache30ScanIdx[iIdx8];922 iCacheIdx = g_kuiCache30ScanIdx[iIdx8];
923 923
924 if (!pSliceHeader->iDirectSpatialMvPredFlag) {924 if (!pSliceHeader->iDirectSpatialMvPredFlag) {
925 iRef[LIST_1] = 0;925 iRef[LIST_1] = 0;
926 if (pCurDqLayer->iColocIntra[g_kuiScan4[iIdx8]]) {926 if (pCurDqLayer->iColocIntra[g_kuiScan4[iIdx8]]) {
927 iRef[LIST_0] = 0;927 iRef[LIST_0] = 0;
928 } else {928 } else {
929 if (pCurDqLayer->iColocRefIndex[LIST_0][iIdx8] >= 0) {929 if (pCurDqLayer->iColocRefIndex[LIST_0][iIdx8] >= 0) {
930 iRef[LIST_0] = pCurDqLayer->iColocRefIndex[LIST_0][iIdx8];930 iRef[LIST_0] = pCurDqLayer->iColocRefIndex[LIST_0][iIdx8];
931 } else {931 } else {
932 iRef[LIST_0] = pCurDqLayer->iColocRefIndex[LIST_1][iIdx8];932 iRef[LIST_0] = pCurDqLayer->iColocRefIndex[LIST_1][iIdx8];
933 }933 }
934 }934 }
935 }935 }
936 for (int32_t j = 0; j < iPartCount; j++) {936 for (int32_t j = 0; j < iPartCount; j++) {
937 iPartIdx = iIdx8 + j * iBlockW;937 iPartIdx = iIdx8 + j * iBlockW;
938 iColocIdx = g_kuiScan4[iPartIdx];938 iColocIdx = g_kuiScan4[iPartIdx];
939 iScan4Idx = g_kuiScan4[iPartIdx];939 iScan4Idx = g_kuiScan4[iPartIdx];
940 iCacheIdx = g_kuiCache30ScanIdx[iPartIdx];940 iCacheIdx = g_kuiCache30ScanIdx[iPartIdx];
941 941
942 if (pSliceHeader->iDirectSpatialMvPredFlag) {942 if (pSliceHeader->iDirectSpatialMvPredFlag) {
943 int16_t pMV[4] = { 0 };943 int16_t pMV[4] = { 0 };
944 if (IS_SUB_8x8 (pCurDqLayer->pSubMbType[iMbXy][i])) {944 if (IS_SUB_8x8 (pCurDqLayer->pSubMbType[iMbXy][i])) {
945 * (uint32_t*)pMV = * (uint32_t*)pMvDirect[LIST_0];945 * (uint32_t*)pMV = * (uint32_t*)pMvDirect[LIST_0];
946 ST32 ((pMV + 2), LD32 (pMV));946 ST32 ((pMV + 2), LD32 (pMV));
947 ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], LD64 (pMV));947 ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], LD64 (pMV));
948 ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx + 4], LD64 (pMV));948 ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx + 4], LD64 (pMV));
949 ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0);949 ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0);
950 ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx + 4], 0);950 ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx + 4], 0);
951 ST64 (pMotionVector[LIST_0][iCacheIdx], LD64 (pMV));951 ST64 (pMotionVector[LIST_0][iCacheIdx], LD64 (pMV));
952 ST64 (pMotionVector[LIST_0][iCacheIdx + 6], LD64 (pMV));952 ST64 (pMotionVector[LIST_0][iCacheIdx + 6], LD64 (pMV));
953 ST64 (pMvdCache[LIST_0][iCacheIdx], 0);953 ST64 (pMvdCache[LIST_0][iCacheIdx], 0);
954 ST64 (pMvdCache[LIST_0][iCacheIdx + 6], 0);954 ST64 (pMvdCache[LIST_0][iCacheIdx + 6], 0);
955 * (uint32_t*)pMV = * (uint32_t*)pMvDirect[LIST_1];955 * (uint32_t*)pMV = * (uint32_t*)pMvDirect[LIST_1];
956 ST32 ((pMV + 2), LD32 (pMV));956 ST32 ((pMV + 2), LD32 (pMV));
957 ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], LD64 (pMV));957 ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], LD64 (pMV));
958 ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx + 4], LD64 (pMV));958 ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx + 4], LD64 (pMV));
959 ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0);959 ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0);
960 ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx + 4], 0);960 ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx + 4], 0);
961 ST64 (pMotionVector[LIST_1][iCacheIdx], LD64 (pMV));961 ST64 (pMotionVector[LIST_1][iCacheIdx], LD64 (pMV));
962 ST64 (pMotionVector[LIST_1][iCacheIdx + 6], LD64 (pMV));962 ST64 (pMotionVector[LIST_1][iCacheIdx + 6], LD64 (pMV));
963 ST64 (pMvdCache[LIST_1][iCacheIdx], 0);963 ST64 (pMvdCache[LIST_1][iCacheIdx], 0);
964 ST64 (pMvdCache[LIST_1][iCacheIdx + 6], 0);964 ST64 (pMvdCache[LIST_1][iCacheIdx + 6], 0);
965 } else { //SUB_4x4965 } else { //SUB_4x4
966 * (uint32_t*)pMV = * (uint32_t*)pMvDirect[LIST_0];966 * (uint32_t*)pMV = * (uint32_t*)pMvDirect[LIST_0];
967 ST32 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], LD32 (pMV));967 ST32 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], LD32 (pMV));
968 ST32 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0);968 ST32 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0);
969 ST32 (pMotionVector[LIST_0][iCacheIdx], LD32 (pMV));969 ST32 (pMotionVector[LIST_0][iCacheIdx], LD32 (pMV));
970 ST32 (pMvdCache[LIST_0][iCacheIdx], 0);970 ST32 (pMvdCache[LIST_0][iCacheIdx], 0);
971 * (uint32_t*)pMV = * (uint32_t*)pMvDirect[LIST_1];971 * (uint32_t*)pMV = * (uint32_t*)pMvDirect[LIST_1];
972 ST32 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], LD32 (pMV));972 ST32 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], LD32 (pMV));
973 ST32 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0);973 ST32 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0);
974 ST32 (pMotionVector[LIST_1][iCacheIdx], LD32 (pMV));974 ST32 (pMotionVector[LIST_1][iCacheIdx], LD32 (pMV));
975 ST32 (pMvdCache[LIST_1][iCacheIdx], 0);975 ST32 (pMvdCache[LIST_1][iCacheIdx], 0);
976 }976 }
977 977
978 if ((* (int32_t*)pMvDirect[LIST_0] | * (int32_t*)pMvDirect[LIST_1])) {978 if ((* (int32_t*)pMvDirect[LIST_0] | * (int32_t*)pMvDirect[LIST_1])) {
979 bool bIsLongRef = pCtx->sRefPic.pRefList[LIST_1][0]->bIsLongRef;979 bool bIsLongRef = pCtx->sRefPic.pRefList[LIST_1][0]->bIsLongRef;
980 uint32_t uiColZeroFlag = (0 == pCurDqLayer->iColocIntra[iColocIdx]) && !bIsLongRef &&980 uint32_t uiColZeroFlag = (0 == pCurDqLayer->iColocIntra[iColocIdx]) && !bIsLongRef &&
981 (pCurDqLayer->iColocRefIndex[LIST_0][iColocIdx] == 0 || (pCurDqLayer->iColocRefIndex[LIST_0][iColocIdx] < 0981 (pCurDqLayer->iColocRefIndex[LIST_0][iColocIdx] == 0 || (pCurDqLayer->iColocRefIndex[LIST_0][iColocIdx] < 0
982 && pCurDqLayer->iColocRefIndex[LIST_1][iColocIdx] == 0));982 && pCurDqLayer->iColocRefIndex[LIST_1][iColocIdx] == 0));
983 const int16_t (*mvColoc)[2] = pCurDqLayer->iColocRefIndex[LIST_0][iColocIdx] == 0 ? pCurDqLayer->iColocMv[LIST_0] :983 const int16_t (*mvColoc)[2] = pCurDqLayer->iColocRefIndex[LIST_0][iColocIdx] == 0 ? pCurDqLayer->iColocMv[LIST_0] :
984 pCurDqLayer->iColocMv[LIST_1];984 pCurDqLayer->iColocMv[LIST_1];
985 const int16_t* mv = mvColoc[iColocIdx];985 const int16_t* mv = mvColoc[iColocIdx];
986 if (IS_SUB_8x8 (pCurDqLayer->pSubMbType[iMbXy][i])) {986 if (IS_SUB_8x8 (pCurDqLayer->pSubMbType[iMbXy][i])) {
987 if (uiColZeroFlag && ((unsigned) (mv[0] + 1) <= 2 && (unsigned) (mv[1] + 1) <= 2)) {987 if (uiColZeroFlag && ((unsigned) (mv[0] + 1) <= 2 && (unsigned) (mv[1] + 1) <= 2)) {
988 if (iRef[LIST_0] == 0) {988 if (iRef[LIST_0] == 0) {
989 ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], 0);989 ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], 0);
990 ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx + 4], 0);990 ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx + 4], 0);
991 ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0);991 ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0);
992 ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx + 4], 0);992 ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx + 4], 0);
993 ST64 (pMotionVector[LIST_0][iCacheIdx], 0);993 ST64 (pMotionVector[LIST_0][iCacheIdx], 0);
994 ST64 (pMotionVector[LIST_0][iCacheIdx + 6], 0);994 ST64 (pMotionVector[LIST_0][iCacheIdx + 6], 0);
995 ST64 (pMvdCache[LIST_0][iCacheIdx], 0);995 ST64 (pMvdCache[LIST_0][iCacheIdx], 0);
996 ST64 (pMvdCache[LIST_0][iCacheIdx + 6], 0);996 ST64 (pMvdCache[LIST_0][iCacheIdx + 6], 0);
997 }997 }
998 998
999 if (iRef[LIST_1] == 0) {999 if (iRef[LIST_1] == 0) {
1000 ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], 0);1000 ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], 0);
1001 ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx + 4], 0);1001 ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx + 4], 0);
1002 ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0);1002 ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0);
1003 ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx + 4], 0);1003 ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx + 4], 0);
1004 ST64 (pMotionVector[LIST_1][iCacheIdx], 0);1004 ST64 (pMotionVector[LIST_1][iCacheIdx], 0);
1005 ST64 (pMotionVector[LIST_1][iCacheIdx + 6], 0);1005 ST64 (pMotionVector[LIST_1][iCacheIdx + 6], 0);
1006 ST64 (pMvdCache[LIST_1][iCacheIdx], 0);1006 ST64 (pMvdCache[LIST_1][iCacheIdx], 0);
1007 ST64 (pMvdCache[LIST_1][iCacheIdx + 6], 0);1007 ST64 (pMvdCache[LIST_1][iCacheIdx + 6], 0);
1008 }1008 }
1009 }1009 }
1010 } else {1010 } else {
1011 if (uiColZeroFlag && ((unsigned) (mv[0] + 1) <= 2 && (unsigned) (mv[1] + 1) <= 2)) {1011 if (uiColZeroFlag && ((unsigned) (mv[0] + 1) <= 2 && (unsigned) (mv[1] + 1) <= 2)) {
1012 if (iRef[LIST_0] == 0) {1012 if (iRef[LIST_0] == 0) {
1013 ST32 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], 0);1013 ST32 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], 0);
1014 ST32 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0);1014 ST32 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0);
1015 ST32 (pMotionVector[LIST_0][iCacheIdx], 0);1015 ST32 (pMotionVector[LIST_0][iCacheIdx], 0);
1016 ST32 (pMvdCache[LIST_0][iCacheIdx], 0);1016 ST32 (pMvdCache[LIST_0][iCacheIdx], 0);
1017 }1017 }
1018 if (iRef[LIST_1] == 0) {1018 if (iRef[LIST_1] == 0) {
1019 ST32 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], 0);1019 ST32 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], 0);
1020 ST32 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0);1020 ST32 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0);
1021 ST32 (pMotionVector[LIST_1][iCacheIdx], 0);1021 ST32 (pMotionVector[LIST_1][iCacheIdx], 0);
1022 ST32 (pMvdCache[LIST_1][iCacheIdx], 0);1022 ST32 (pMvdCache[LIST_1][iCacheIdx], 0);
1023 }1023 }
1024 }1024 }
1025 }1025 }
1026 }1026 }
1027 } else {1027 } else {
1028 int16_t (*mvColoc)[2] = pCurDqLayer->iColocMv[LIST_0];1028 int16_t (*mvColoc)[2] = pCurDqLayer->iColocMv[LIST_0];
1029 int16_t* mv = mvColoc[iColocIdx];1029 int16_t* mv = mvColoc[iColocIdx];
1030 int16_t pMV[4] = { 0 };1030 int16_t pMV[4] = { 0 };
1031 int16_t iMvp[LIST_A][2];1031 int16_t iMvp[LIST_A][2];
1032 if (IS_SUB_8x8 (pCurDqLayer->pSubMbType[iMbXy][i])) {1032 if (IS_SUB_8x8 (pCurDqLayer->pSubMbType[iMbXy][i])) {
1033 iMvp[LIST_0][0] = (pSlice->iMvScale[LIST_0][iRef[LIST_0]] * mv[0] + 128) >> 8;1033 iMvp[LIST_0][0] = (pSlice->iMvScale[LIST_0][iRef[LIST_0]] * mv[0] + 128) >> 8;
1034 iMvp[LIST_0][1] = (pSlice->iMvScale[LIST_0][iRef[LIST_0]] * mv[1] + 128) >> 8;1034 iMvp[LIST_0][1] = (pSlice->iMvScale[LIST_0][iRef[LIST_0]] * mv[1] + 128) >> 8;
1035 ST32 (pMV, LD32 (iMvp[LIST_0]));1035 ST32 (pMV, LD32 (iMvp[LIST_0]));
1036 ST32 ((pMV + 2), LD32 (iMvp[LIST_0]));1036 ST32 ((pMV + 2), LD32 (iMvp[LIST_0]));
1037 ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], LD64 (pMV));1037 ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], LD64 (pMV));
1038 ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx + 4], LD64 (pMV));1038 ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx + 4], LD64 (pMV));
1039 ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0);1039 ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0);
1040 ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx + 4], 0);1040 ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx + 4], 0);
1041 iMvp[LIST_1][0] -= iMvp[LIST_0][0] - mv[0];1041 iMvp[LIST_1][0] -= iMvp[LIST_0][0] - mv[0];
1042 iMvp[LIST_1][1] -= iMvp[LIST_0][0] - mv[1];1042 iMvp[LIST_1][1] -= iMvp[LIST_0][0] - mv[1];
1043 ST32 (pMV, LD32 (iMvp[LIST_1]));1043 ST32 (pMV, LD32 (iMvp[LIST_1]));
1044 ST32 ((pMV + 2), LD32 (iMvp[LIST_1]));1044 ST32 ((pMV + 2), LD32 (iMvp[LIST_1]));
1045 ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], LD64 (pMV));1045 ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], LD64 (pMV));
1046 ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx + 4], LD64 (pMV));1046 ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx + 4], LD64 (pMV));
1047 ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0);1047 ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0);
1048 ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx + 4], 0);1048 ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx + 4], 0);
1049 } else { //SUB_4x41049 } else { //SUB_4x4
1050 iMvp[LIST_0][0] = (pSlice->iMvScale[LIST_0][iRef[LIST_0]] * mv[0] + 128) >> 8;1050 iMvp[LIST_0][0] = (pSlice->iMvScale[LIST_0][iRef[LIST_0]] * mv[0] + 128) >> 8;
1051 iMvp[LIST_0][1] = (pSlice->iMvScale[LIST_0][iRef[LIST_0]] * mv[1] + 128) >> 8;1051 iMvp[LIST_0][1] = (pSlice->iMvScale[LIST_0][iRef[LIST_0]] * mv[1] + 128) >> 8;
1052 ST32 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], LD32 (iMvp[LIST_0]));1052 ST32 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], LD32 (iMvp[LIST_0]));
1053 ST32 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0);1053 ST32 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0);
1054 iMvp[LIST_1][0] -= iMvp[LIST_0][0] - mv[0];1054 iMvp[LIST_1][0] -= iMvp[LIST_0][0] - mv[0];
1055 iMvp[LIST_1][1] -= iMvp[LIST_0][0] - mv[1];1055 iMvp[LIST_1][1] -= iMvp[LIST_0][0] - mv[1];
1056 ST32 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], LD32 (iMvp[LIST_1]));1056 ST32 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], LD32 (iMvp[LIST_1]));
1057 ST32 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0);1057 ST32 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0);
1058 }1058 }
1059 }1059 }
1060 }1060 }
1061 }1061 }
1062 }1062 }
1063 //ref no-direct1063 //ref no-direct
1064 int8_t ref_idx_list[LIST_A][4] = { {REF_NOT_IN_LIST, REF_NOT_IN_LIST}, { REF_NOT_IN_LIST, REF_NOT_IN_LIST } };1064 int8_t ref_idx_list[LIST_A][4] = { {REF_NOT_IN_LIST, REF_NOT_IN_LIST}, { REF_NOT_IN_LIST, REF_NOT_IN_LIST } };
1065 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {1065 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
1066 for (int32_t i = 0; i < 4; i++) {1066 for (int32_t i = 0; i < 4; i++) {
1067 int16_t iIdx8 = i << 2;1067 int16_t iIdx8 = i << 2;
1068 int32_t subMbType = pCurDqLayer->pSubMbType[iMbXy][i];1068 int32_t subMbType = pCurDqLayer->pSubMbType[iMbXy][i];
1069 int8_t iref = REF_NOT_IN_LIST;1069 int8_t iref = REF_NOT_IN_LIST;
1070 if (IS_DIRECT (subMbType)) {1070 if (IS_DIRECT (subMbType)) {
1071 if (pSliceHeader->iDirectSpatialMvPredFlag) {1071 if (pSliceHeader->iDirectSpatialMvPredFlag) {
1072 iref = iRef[listIdx];1072 iref = iRef[listIdx];
1073 } else {1073 } else {
1074 iref = 0;1074 iref = 0;
1075 if (listIdx == LIST_0) {1075 if (listIdx == LIST_0) {
1076 if (!pCurDqLayer->iColocIntra[g_kuiScan4[iIdx8]]) {1076 if (!pCurDqLayer->iColocIntra[g_kuiScan4[iIdx8]]) {
1077 if (pCurDqLayer->iColocRefIndex[LIST_0][iIdx8] >= 0) {1077 if (pCurDqLayer->iColocRefIndex[LIST_0][iIdx8] >= 0) {
1078 iref = pCurDqLayer->iColocRefIndex[LIST_0][iIdx8];1078 iref = pCurDqLayer->iColocRefIndex[LIST_0][iIdx8];
1079 } else {1079 } else {
1080 iref = pCurDqLayer->iColocRefIndex[LIST_1][iIdx8];1080 iref = pCurDqLayer->iColocRefIndex[LIST_1][iIdx8];
1081 }1081 }
1082 }1082 }
1083 }1083 }
1084 }1084 }
1085 UpdateP8x8DirectCabac (pCurDqLayer, iIdx8);1085 UpdateP8x8DirectCabac (pCurDqLayer, iIdx8);
1086 } else {1086 } else {
1087 if (IS_DIR (subMbType, 0, listIdx)) {1087 if (IS_DIR (subMbType, 0, listIdx)) {
1088 WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, pDirect, listIdx, iIdx8,1088 WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, pDirect, listIdx, iIdx8,
1089 pRefCount[listIdx], 1,1089 pRefCount[listIdx], 1,
1090 iref));1090 iref));
1091 if ((iref < 0) || (iref >= pRefCount[listIdx]) || (pCtx->sRefPic.pRefList[listIdx][iref] == NULL)) { //error ref_idx1091 if ((iref < 0) || (iref >= pRefCount[listIdx]) || (pCtx->sRefPic.pRefList[listIdx][iref] == NULL)) { //error ref_idx
1092 pCtx->bMbRefConcealed = true;1092 pCtx->bMbRefConcealed = true;
1093 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {1093 if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) {
1094 iref = 0;1094 iref = 0;
1095 pCtx->iErrorCode |= dsBitstreamError;1095 pCtx->iErrorCode |= dsBitstreamError;
1096 } else {1096 } else {
1097 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);1097 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX);
1098 }1098 }
1099 }1099 }
1100 pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (pCtx->sRefPic.pRefList[listIdx][iref]1100 pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (pCtx->sRefPic.pRefList[listIdx][iref]
1101 && pCtx->sRefPic.pRefList[listIdx][iref]->bIsComplete);1101 && pCtx->sRefPic.pRefList[listIdx][iref]->bIsComplete);
1102 }1102 }
1103 }1103 }
1104 UpdateP8x8RefIdxCabac (pCurDqLayer, pRefIndex, iIdx8, iref, listIdx);1104 UpdateP8x8RefIdxCabac (pCurDqLayer, pRefIndex, iIdx8, iref, listIdx);
1105 ref_idx_list[listIdx][i] = iref;1105 ref_idx_list[listIdx][i] = iref;
1106 }1106 }
1107 }1107 }
1108 //mv1108 //mv
1109 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {1109 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
1110 for (int32_t i = 0; i < 4; i++) {1110 for (int32_t i = 0; i < 4; i++) {
1111 int8_t iPartCount = pSubPartCount[i];1111 int8_t iPartCount = pSubPartCount[i];
1112 int16_t iPartIdx, iBlockW = pPartW[i];1112 int16_t iPartIdx, iBlockW = pPartW[i];
1113 uint8_t iScan4Idx, iCacheIdx;1113 uint8_t iScan4Idx, iCacheIdx;
1114 1114
1115 iCacheIdx = g_kuiCache30ScanIdx[i << 2];1115 iCacheIdx = g_kuiCache30ScanIdx[i << 2];
1116 1116
1117 int8_t iref = ref_idx_list[listIdx][i];1117 int8_t iref = ref_idx_list[listIdx][i];
1118 pRefIndex[listIdx][iCacheIdx] = pRefIndex[listIdx][iCacheIdx + 1]1118 pRefIndex[listIdx][iCacheIdx] = pRefIndex[listIdx][iCacheIdx + 1]
1119 = pRefIndex[listIdx][iCacheIdx + 6] = pRefIndex[listIdx][iCacheIdx + 7] = iref;1119 = pRefIndex[listIdx][iCacheIdx + 6] = pRefIndex[listIdx][iCacheIdx + 7] = iref;
1120 1120
1121 uint32_t subMbType = pCurDqLayer->pSubMbType[iMbXy][i];1121 uint32_t subMbType = pCurDqLayer->pSubMbType[iMbXy][i];
1122 if (IS_DIRECT (subMbType)) {1122 if (IS_DIRECT (subMbType)) {
1123 continue;1123 continue;
1124 }1124 }
1125 bool is_dir = IS_DIR (subMbType, 0, listIdx) > 0;1125 bool is_dir = IS_DIR (subMbType, 0, listIdx) > 0;
1126 for (int32_t j = 0; j < iPartCount; j++) {1126 for (int32_t j = 0; j < iPartCount; j++) {
1127 iPartIdx = (i << 2) + j * iBlockW;1127 iPartIdx = (i << 2) + j * iBlockW;
1128 iScan4Idx = g_kuiScan4[iPartIdx];1128 iScan4Idx = g_kuiScan4[iPartIdx];
1129 iCacheIdx = g_kuiCache30ScanIdx[iPartIdx];1129 iCacheIdx = g_kuiCache30ScanIdx[iPartIdx];
1130 if (is_dir) {1130 if (is_dir) {
1131 PredMv (pMotionVector, pRefIndex, listIdx, iPartIdx, iBlockW, iref, pMv);1131 PredMv (pMotionVector, pRefIndex, listIdx, iPartIdx, iBlockW, iref, pMv);
1132 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, listIdx, 0, pMvd[0]));1132 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, listIdx, 0, pMvd[0]));
1133 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, listIdx, 1, pMvd[1]));1133 WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, listIdx, 1, pMvd[1]));
1134 pMv[0] += pMvd[0];1134 pMv[0] += pMvd[0];
1135 pMv[1] += pMvd[1];1135 pMv[1] += pMvd[1];
1136 WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv");1136 WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv");
1137 } else {1137 } else {
1138 * (uint32_t*)pMv = * (uint32_t*)pMvd = 0;1138 * (uint32_t*)pMv = * (uint32_t*)pMvd = 0;
1139 }1139 }
1140 if (IS_SUB_8x8 (subMbType)) { //MB_TYPE_8x81140 if (IS_SUB_8x8 (subMbType)) { //MB_TYPE_8x8
1141 ST32 ((pMv + 2), LD32 (pMv));1141 ST32 ((pMv + 2), LD32 (pMv));
1142 ST32 ((pMvd + 2), LD32 (pMvd));1142 ST32 ((pMvd + 2), LD32 (pMvd));
1143 ST64 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx], LD64 (pMv));1143 ST64 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx], LD64 (pMv));
1144 ST64 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx + 4], LD64 (pMv));1144 ST64 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx + 4], LD64 (pMv));
1145 ST64 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx], LD64 (pMvd));1145 ST64 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx], LD64 (pMvd));
1146 ST64 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx + 4], LD64 (pMvd));1146 ST64 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx + 4], LD64 (pMvd));
1147 ST64 (pMotionVector[listIdx][iCacheIdx], LD64 (pMv));1147 ST64 (pMotionVector[listIdx][iCacheIdx], LD64 (pMv));
1148 ST64 (pMotionVector[listIdx][iCacheIdx + 6], LD64 (pMv));1148 ST64 (pMotionVector[listIdx][iCacheIdx + 6], LD64 (pMv));
1149 ST64 (pMvdCache[listIdx][iCacheIdx], LD64 (pMvd));1149 ST64 (pMvdCache[listIdx][iCacheIdx], LD64 (pMvd));
1150 ST64 (pMvdCache[listIdx][iCacheIdx + 6], LD64 (pMvd));1150 ST64 (pMvdCache[listIdx][iCacheIdx + 6], LD64 (pMvd));
1151 } else if (IS_SUB_4x4 (subMbType)) { //MB_TYPE_4x41151 } else if (IS_SUB_4x4 (subMbType)) { //MB_TYPE_4x4
1152 ST32 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx], LD32 (pMv));1152 ST32 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx], LD32 (pMv));
1153 ST32 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx], LD32 (pMvd));1153 ST32 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx], LD32 (pMvd));
1154 ST32 (pMotionVector[listIdx][iCacheIdx], LD32 (pMv));1154 ST32 (pMotionVector[listIdx][iCacheIdx], LD32 (pMv));
1155 ST32 (pMvdCache[listIdx][iCacheIdx], LD32 (pMvd));1155 ST32 (pMvdCache[listIdx][iCacheIdx], LD32 (pMvd));
1156 } else if (IS_SUB_4x8 (subMbType)) { //MB_TYPE_4x8 5, 7, 91156 } else if (IS_SUB_4x8 (subMbType)) { //MB_TYPE_4x8 5, 7, 9
1157 ST32 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx], LD32 (pMv));1157 ST32 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx], LD32 (pMv));
1158 ST32 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx + 4], LD32 (pMv));1158 ST32 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx + 4], LD32 (pMv));
1159 ST32 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx], LD32 (pMvd));1159 ST32 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx], LD32 (pMvd));
1160 ST32 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx + 4], LD32 (pMvd));1160 ST32 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx + 4], LD32 (pMvd));
1161 ST32 (pMotionVector[listIdx][iCacheIdx], LD32 (pMv));1161 ST32 (pMotionVector[listIdx][iCacheIdx], LD32 (pMv));
1162 ST32 (pMotionVector[listIdx][iCacheIdx + 6], LD32 (pMv));1162 ST32 (pMotionVector[listIdx][iCacheIdx + 6], LD32 (pMv));
1163 ST32 (pMvdCache[listIdx][iCacheIdx], LD32 (pMvd));1163 ST32 (pMvdCache[listIdx][iCacheIdx], LD32 (pMvd));
1164 ST32 (pMvdCache[listIdx][iCacheIdx + 6], LD32 (pMvd));1164 ST32 (pMvdCache[listIdx][iCacheIdx + 6], LD32 (pMvd));
1165 } else { //MB_TYPE_8x4 4, 6, 81165 } else { //MB_TYPE_8x4 4, 6, 8
1166 ST32 ((pMv + 2), LD32 (pMv));1166 ST32 ((pMv + 2), LD32 (pMv));
1167 ST32 ((pMvd + 2), LD32 (pMvd));1167 ST32 ((pMvd + 2), LD32 (pMvd));
1168 ST64 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx], LD64 (pMv));1168 ST64 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx], LD64 (pMv));
1169 ST64 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx], LD64 (pMvd));1169 ST64 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx], LD64 (pMvd));
1170 ST64 (pMotionVector[listIdx][iCacheIdx], LD64 (pMv));1170 ST64 (pMotionVector[listIdx][iCacheIdx], LD64 (pMv));
1171 ST64 (pMvdCache[listIdx][iCacheIdx], LD64 (pMvd));1171 ST64 (pMvdCache[listIdx][iCacheIdx], LD64 (pMvd));
1172 }1172 }
1173 }1173 }
1174 }1174 }
1175 }1175 }
1176 }1176 }
1177 return ERR_NONE;1177 return ERR_NONE;
1178}1178}
1179 1179
1180int32_t ParseRefIdxCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint8_t* nzc,1180int32_t ParseRefIdxCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint8_t* nzc,
1181 int8_t ref_idx[LIST_A][30], int8_t direct[30],1181 int8_t ref_idx[LIST_A][30], int8_t direct[30],
1182 int32_t iListIdx, int32_t iZOrderIdx, int32_t iActiveRefNum, int32_t b8mode, int8_t& iRefIdxVal) {1182 int32_t iListIdx, int32_t iZOrderIdx, int32_t iActiveRefNum, int32_t b8mode, int8_t& iRefIdxVal) {
1183 if (iActiveRefNum == 1) {1183 if (iActiveRefNum == 1) {
1184 iRefIdxVal = 0;1184 iRefIdxVal = 0;
1185 return ERR_NONE;1185 return ERR_NONE;
1186 }1186 }
1187 uint32_t uiCode;1187 uint32_t uiCode;
1188 int32_t iIdxA = 0, iIdxB = 0;1188 int32_t iIdxA = 0, iIdxB = 0;
1189 int32_t iCtxInc = 0;1189 int32_t iCtxInc = 0;
1190 int8_t* pRefIdxInMB = pCtx->pCurDqLayer->pRefIndex[iListIdx][pCtx->pCurDqLayer->iMbXyIndex];1190 int8_t* pRefIdxInMB = pCtx->pCurDqLayer->pRefIndex[iListIdx][pCtx->pCurDqLayer->iMbXyIndex];
1191 int8_t* pDirect = pCtx->pCurDqLayer->pDirect[pCtx->pCurDqLayer->iMbXyIndex];1191 int8_t* pDirect = pCtx->pCurDqLayer->pDirect[pCtx->pCurDqLayer->iMbXyIndex];
1192 if (iZOrderIdx == 0) {1192 if (iZOrderIdx == 0) {
1193 iIdxB = (pNeighAvail->iTopAvail && pNeighAvail->iTopType != MB_TYPE_INTRA_PCM1193 iIdxB = (pNeighAvail->iTopAvail && pNeighAvail->iTopType != MB_TYPE_INTRA_PCM
1194 && ref_idx[iListIdx][g_kuiCache30ScanIdx[iZOrderIdx] - 6] > 0);1194 && ref_idx[iListIdx][g_kuiCache30ScanIdx[iZOrderIdx] - 6] > 0);
1195 iIdxA = (pNeighAvail->iLeftAvail && pNeighAvail->iLeftType != MB_TYPE_INTRA_PCM1195 iIdxA = (pNeighAvail->iLeftAvail && pNeighAvail->iLeftType != MB_TYPE_INTRA_PCM
1196 && ref_idx[iListIdx][g_kuiCache30ScanIdx[iZOrderIdx] - 1] > 0);1196 && ref_idx[iListIdx][g_kuiCache30ScanIdx[iZOrderIdx] - 1] > 0);
1197 if (pCtx->eSliceType == B_SLICE) {1197 if (pCtx->eSliceType == B_SLICE) {
1198 if (iIdxB > 0 && direct[g_kuiCache30ScanIdx[iZOrderIdx] - 6] == 0) {1198 if (iIdxB > 0 && direct[g_kuiCache30ScanIdx[iZOrderIdx] - 6] == 0) {
1199 iCtxInc += 2;1199 iCtxInc += 2;
1200 }1200 }
1201 if (iIdxA > 0 && direct[g_kuiCache30ScanIdx[iZOrderIdx] - 1] == 0) {1201 if (iIdxA > 0 && direct[g_kuiCache30ScanIdx[iZOrderIdx] - 1] == 0) {
1202 iCtxInc++;1202 iCtxInc++;
1203 }1203 }
1204 }1204 }
1205 } else if (iZOrderIdx == 4) {1205 } else if (iZOrderIdx == 4) {
1206 iIdxB = (pNeighAvail->iTopAvail && pNeighAvail->iTopType != MB_TYPE_INTRA_PCM1206 iIdxB = (pNeighAvail->iTopAvail && pNeighAvail->iTopType != MB_TYPE_INTRA_PCM
1207 && ref_idx[iListIdx][g_kuiCache30ScanIdx[iZOrderIdx] - 6] > 0);1207 && ref_idx[iListIdx][g_kuiCache30ScanIdx[iZOrderIdx] - 6] > 0);
1208 iIdxA = pRefIdxInMB[g_kuiScan4[iZOrderIdx] - 1] > 0;1208 iIdxA = pRefIdxInMB[g_kuiScan4[iZOrderIdx] - 1] > 0;
1209 if (pCtx->eSliceType == B_SLICE) {1209 if (pCtx->eSliceType == B_SLICE) {
1210 if (iIdxB > 0 && direct[g_kuiCache30ScanIdx[iZOrderIdx] - 6] == 0) {1210 if (iIdxB > 0 && direct[g_kuiCache30ScanIdx[iZOrderIdx] - 6] == 0) {
1211 iCtxInc += 2;1211 iCtxInc += 2;
1212 }1212 }
1213 if (iIdxA > 0 && pDirect[g_kuiScan4[iZOrderIdx] - 1] == 0) {1213 if (iIdxA > 0 && pDirect[g_kuiScan4[iZOrderIdx] - 1] == 0) {
1214 iCtxInc ++;1214 iCtxInc ++;
1215 }1215 }
1216 }1216 }
1217 } else if (iZOrderIdx == 8) {1217 } else if (iZOrderIdx == 8) {
1218 1218
1219 iIdxB = pRefIdxInMB[g_kuiScan4[iZOrderIdx] - 4] > 0;1219 iIdxB = pRefIdxInMB[g_kuiScan4[iZOrderIdx] - 4] > 0;
1220 iIdxA = (pNeighAvail->iLeftAvail && pNeighAvail->iLeftType != MB_TYPE_INTRA_PCM1220 iIdxA = (pNeighAvail->iLeftAvail && pNeighAvail->iLeftType != MB_TYPE_INTRA_PCM
1221 && ref_idx[iListIdx][g_kuiCache30ScanIdx[iZOrderIdx] - 1] > 0);1221 && ref_idx[iListIdx][g_kuiCache30ScanIdx[iZOrderIdx] - 1] > 0);
1222 if (pCtx->eSliceType == B_SLICE) {1222 if (pCtx->eSliceType == B_SLICE) {
1223 if (iIdxB > 0 && pDirect[g_kuiScan4[iZOrderIdx] - 4] == 0) {1223 if (iIdxB > 0 && pDirect[g_kuiScan4[iZOrderIdx] - 4] == 0) {
1224 iCtxInc += 2;1224 iCtxInc += 2;
1225 }1225 }
1226 if (iIdxA > 0 && direct[g_kuiCache30ScanIdx[iZOrderIdx] - 1] == 0) {1226 if (iIdxA > 0 && direct[g_kuiCache30ScanIdx[iZOrderIdx] - 1] == 0) {
1227 iCtxInc++;1227 iCtxInc++;
1228 }1228 }
1229 }1229 }
1230 } else {1230 } else {
1231 iIdxB = pRefIdxInMB[g_kuiScan4[iZOrderIdx] - 4] > 0;1231 iIdxB = pRefIdxInMB[g_kuiScan4[iZOrderIdx] - 4] > 0;
1232 iIdxA = pRefIdxInMB[g_kuiScan4[iZOrderIdx] - 1] > 0;1232 iIdxA = pRefIdxInMB[g_kuiScan4[iZOrderIdx] - 1] > 0;
1233 if (pCtx->eSliceType == B_SLICE) {1233 if (pCtx->eSliceType == B_SLICE) {
1234 if (iIdxB > 0 && pDirect[g_kuiScan4[iZOrderIdx] - 4] == 0) {1234 if (iIdxB > 0 && pDirect[g_kuiScan4[iZOrderIdx] - 4] == 0) {
1235 iCtxInc += 2;1235 iCtxInc += 2;
1236 }1236 }
1237 if (iIdxA > 0 && pDirect[g_kuiScan4[iZOrderIdx] - 1] == 0) {1237 if (iIdxA > 0 && pDirect[g_kuiScan4[iZOrderIdx] - 1] == 0) {
1238 iCtxInc++;1238 iCtxInc++;
1239 }1239 }
1240 }1240 }
1241 }1241 }
1242 if (pCtx->eSliceType != B_SLICE) {1242 if (pCtx->eSliceType != B_SLICE) {
1243 iCtxInc = iIdxA + (iIdxB << 1);1243 iCtxInc = iIdxA + (iIdxB << 1);
1244 }1244 }
1245 1245
1246 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_REF_NO + iCtxInc, uiCode));1246 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_REF_NO + iCtxInc, uiCode));
1247 if (uiCode) {1247 if (uiCode) {
1248 WELS_READ_VERIFY (DecodeUnaryBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_REF_NO + 4, 1, uiCode));1248 WELS_READ_VERIFY (DecodeUnaryBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_REF_NO + 4, 1, uiCode));
1249 ++uiCode;1249 ++uiCode;
1250 }1250 }
1251 iRefIdxVal = (int8_t) uiCode;1251 iRefIdxVal = (int8_t) uiCode;
1252 return ERR_NONE;1252 return ERR_NONE;
1253}1253}
1254 1254
1255int32_t ParseMvdInfoCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, int8_t pRefIndex[LIST_A][30],1255int32_t ParseMvdInfoCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, int8_t pRefIndex[LIST_A][30],
1256 int16_t pMvdCache[LIST_A][30][2], int32_t index, int8_t iListIdx, int8_t iMvComp, int16_t& iMvdVal) {1256 int16_t pMvdCache[LIST_A][30][2], int32_t index, int8_t iListIdx, int8_t iMvComp, int16_t& iMvdVal) {
1257 uint32_t uiCode;1257 uint32_t uiCode;
1258 int32_t iIdxA = 0;1258 int32_t iIdxA = 0;
1259 //int32_t sym;1259 //int32_t sym;
1260 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_MVD + iMvComp * CTX_NUM_MVD;1260 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_MVD + iMvComp * CTX_NUM_MVD;
1261 iMvdVal = 0;1261 iMvdVal = 0;
1262 1262
1263 if (pRefIndex[iListIdx][g_kuiCache30ScanIdx[index] - 6] >= 0)1263 if (pRefIndex[iListIdx][g_kuiCache30ScanIdx[index] - 6] >= 0)
1264 iIdxA = WELS_ABS (pMvdCache[iListIdx][g_kuiCache30ScanIdx[index] - 6][iMvComp]);1264 iIdxA = WELS_ABS (pMvdCache[iListIdx][g_kuiCache30ScanIdx[index] - 6][iMvComp]);
1265 if (pRefIndex[iListIdx][g_kuiCache30ScanIdx[index] - 1] >= 0)1265 if (pRefIndex[iListIdx][g_kuiCache30ScanIdx[index] - 1] >= 0)
1266 iIdxA += WELS_ABS (pMvdCache[iListIdx][g_kuiCache30ScanIdx[index] - 1][iMvComp]);1266 iIdxA += WELS_ABS (pMvdCache[iListIdx][g_kuiCache30ScanIdx[index] - 1][iMvComp]);
1267 1267
1268 int32_t iCtxInc = 0;1268 int32_t iCtxInc = 0;
1269 if (iIdxA >= 3)1269 if (iIdxA >= 3)
1270 iCtxInc = 1 + (iIdxA > 32);1270 iCtxInc = 1 + (iIdxA > 32);
1271 1271
1272 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pBinCtx + iCtxInc, uiCode));1272 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pBinCtx + iCtxInc, uiCode));
1273 if (uiCode) {1273 if (uiCode) {
1274 WELS_READ_VERIFY (DecodeUEGMvCabac (pCtx->pCabacDecEngine, pBinCtx + 3, 3, uiCode));1274 WELS_READ_VERIFY (DecodeUEGMvCabac (pCtx->pCabacDecEngine, pBinCtx + 3, 3, uiCode));
1275 iMvdVal = (int16_t) (uiCode + 1);1275 iMvdVal = (int16_t) (uiCode + 1);
1276 WELS_READ_VERIFY (DecodeBypassCabac (pCtx->pCabacDecEngine, uiCode));1276 WELS_READ_VERIFY (DecodeBypassCabac (pCtx->pCabacDecEngine, uiCode));
1277 if (uiCode) {1277 if (uiCode) {
1278 iMvdVal = -iMvdVal;1278 iMvdVal = -iMvdVal;
1279 }1279 }
1280 } else {1280 } else {
1281 iMvdVal = 0;1281 iMvdVal = 0;
1282 }1282 }
1283 return ERR_NONE;1283 return ERR_NONE;
1284}1284}
1285 1285
1286int32_t ParseCbpInfoCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiCbp) {1286int32_t ParseCbpInfoCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiCbp) {
1287 int32_t iIdxA = 0, iIdxB = 0, pALeftMb[2], pBTopMb[2];1287 int32_t iIdxA = 0, iIdxB = 0, pALeftMb[2], pBTopMb[2];
1288 uiCbp = 0;1288 uiCbp = 0;
1289 uint32_t pCbpBit[6];1289 uint32_t pCbpBit[6];
1290 int32_t iCtxInc;1290 int32_t iCtxInc;
1291 1291
1292 //Luma: bit by bit for 4 8x8 blocks in z-order1292 //Luma: bit by bit for 4 8x8 blocks in z-order
1293 pBTopMb[0] = pNeighAvail->iTopAvail && pNeighAvail->iTopType != MB_TYPE_INTRA_PCM1293 pBTopMb[0] = pNeighAvail->iTopAvail && pNeighAvail->iTopType != MB_TYPE_INTRA_PCM
1294 && ((pNeighAvail->iTopCbp & (1 << 2)) == 0);1294 && ((pNeighAvail->iTopCbp & (1 << 2)) == 0);
1295 pBTopMb[1] = pNeighAvail->iTopAvail && pNeighAvail->iTopType != MB_TYPE_INTRA_PCM1295 pBTopMb[1] = pNeighAvail->iTopAvail && pNeighAvail->iTopType != MB_TYPE_INTRA_PCM
1296 && ((pNeighAvail->iTopCbp & (1 << 3)) == 0);1296 && ((pNeighAvail->iTopCbp & (1 << 3)) == 0);
1297 pALeftMb[0] = pNeighAvail->iLeftAvail && pNeighAvail->iLeftType != MB_TYPE_INTRA_PCM1297 pALeftMb[0] = pNeighAvail->iLeftAvail && pNeighAvail->iLeftType != MB_TYPE_INTRA_PCM
1298 && ((pNeighAvail->iLeftCbp & (1 << 1)) == 0);1298 && ((pNeighAvail->iLeftCbp & (1 << 1)) == 0);
1299 pALeftMb[1] = pNeighAvail->iLeftAvail && pNeighAvail->iLeftType != MB_TYPE_INTRA_PCM1299 pALeftMb[1] = pNeighAvail->iLeftAvail && pNeighAvail->iLeftType != MB_TYPE_INTRA_PCM
1300 && ((pNeighAvail->iLeftCbp & (1 << 3)) == 0);1300 && ((pNeighAvail->iLeftCbp & (1 << 3)) == 0);
1301 1301
1302 //left_top 8x8 block1302 //left_top 8x8 block
1303 iCtxInc = pALeftMb[0] + (pBTopMb[0] << 1);1303 iCtxInc = pALeftMb[0] + (pBTopMb[0] << 1);
1304 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + iCtxInc, pCbpBit[0]));1304 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + iCtxInc, pCbpBit[0]));
1305 if (pCbpBit[0])1305 if (pCbpBit[0])
1306 uiCbp += 0x01;1306 uiCbp += 0x01;
1307 1307
1308 //right_top 8x8 block1308 //right_top 8x8 block
1309 iIdxA = !pCbpBit[0];1309 iIdxA = !pCbpBit[0];
1310 iCtxInc = iIdxA + (pBTopMb[1] << 1);1310 iCtxInc = iIdxA + (pBTopMb[1] << 1);
1311 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + iCtxInc, pCbpBit[1]));1311 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + iCtxInc, pCbpBit[1]));
1312 if (pCbpBit[1])1312 if (pCbpBit[1])
1313 uiCbp += 0x02;1313 uiCbp += 0x02;
1314 1314
1315 //left_bottom 8x8 block1315 //left_bottom 8x8 block
1316 iIdxB = !pCbpBit[0];1316 iIdxB = !pCbpBit[0];
1317 iCtxInc = pALeftMb[1] + (iIdxB << 1);1317 iCtxInc = pALeftMb[1] + (iIdxB << 1);
1318 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + iCtxInc, pCbpBit[2]));1318 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + iCtxInc, pCbpBit[2]));
1319 if (pCbpBit[2])1319 if (pCbpBit[2])
1320 uiCbp += 0x04;1320 uiCbp += 0x04;
1321 1321
1322 //right_bottom 8x8 block1322 //right_bottom 8x8 block
1323 iIdxB = !pCbpBit[1];1323 iIdxB = !pCbpBit[1];
1324 iIdxA = !pCbpBit[2];1324 iIdxA = !pCbpBit[2];
1325 iCtxInc = iIdxA + (iIdxB << 1);1325 iCtxInc = iIdxA + (iIdxB << 1);
1326 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + iCtxInc, pCbpBit[3]));1326 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + iCtxInc, pCbpBit[3]));
1327 if (pCbpBit[3])1327 if (pCbpBit[3])
1328 uiCbp += 0x08;1328 uiCbp += 0x08;
1329 1329
1330 if (pCtx->pSps->uiChromaFormatIdc == 0)//monochroma1330 if (pCtx->pSps->uiChromaFormatIdc == 0)//monochroma
1331 return ERR_NONE;1331 return ERR_NONE;
1332 1332
1333 1333
1334 //Chroma: bit by bit1334 //Chroma: bit by bit
1335 iIdxB = pNeighAvail->iTopAvail && (pNeighAvail->iTopType == MB_TYPE_INTRA_PCM || (pNeighAvail->iTopCbp >> 4));1335 iIdxB = pNeighAvail->iTopAvail && (pNeighAvail->iTopType == MB_TYPE_INTRA_PCM || (pNeighAvail->iTopCbp >> 4));
1336 iIdxA = pNeighAvail->iLeftAvail && (pNeighAvail->iLeftType == MB_TYPE_INTRA_PCM || (pNeighAvail->iLeftCbp >> 4));1336 iIdxA = pNeighAvail->iLeftAvail && (pNeighAvail->iLeftType == MB_TYPE_INTRA_PCM || (pNeighAvail->iLeftCbp >> 4));
1337 1337
1338 //BitIdx = 01338 //BitIdx = 0
1339 iCtxInc = iIdxA + (iIdxB << 1);1339 iCtxInc = iIdxA + (iIdxB << 1);
1340 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + CTX_NUM_CBP + iCtxInc,1340 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + CTX_NUM_CBP + iCtxInc,
1341 pCbpBit[4]));1341 pCbpBit[4]));
1342 1342
1343 //BitIdx = 11343 //BitIdx = 1
1344 if (pCbpBit[4]) {1344 if (pCbpBit[4]) {
1345 iIdxB = pNeighAvail->iTopAvail && (pNeighAvail->iTopType == MB_TYPE_INTRA_PCM || (pNeighAvail->iTopCbp >> 4) == 2);1345 iIdxB = pNeighAvail->iTopAvail && (pNeighAvail->iTopType == MB_TYPE_INTRA_PCM || (pNeighAvail->iTopCbp >> 4) == 2);
1346 iIdxA = pNeighAvail->iLeftAvail && (pNeighAvail->iLeftType == MB_TYPE_INTRA_PCM || (pNeighAvail->iLeftCbp >> 4) == 2);1346 iIdxA = pNeighAvail->iLeftAvail && (pNeighAvail->iLeftType == MB_TYPE_INTRA_PCM || (pNeighAvail->iLeftCbp >> 4) == 2);
1347 iCtxInc = iIdxA + (iIdxB << 1);1347 iCtxInc = iIdxA + (iIdxB << 1);
1348 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine,1348 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine,
1349 pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + 2 * CTX_NUM_CBP + iCtxInc,1349 pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + 2 * CTX_NUM_CBP + iCtxInc,
1350 pCbpBit[5]));1350 pCbpBit[5]));
1351 uiCbp += 1 << (4 + pCbpBit[5]);1351 uiCbp += 1 << (4 + pCbpBit[5]);
1352 1352
1353 }1353 }
1354 1354
1355 return ERR_NONE;1355 return ERR_NONE;
1356}1356}
1357 1357
1358int32_t ParseDeltaQpCabac (PWelsDecoderContext pCtx, int32_t& iQpDelta) {1358int32_t ParseDeltaQpCabac (PWelsDecoderContext pCtx, int32_t& iQpDelta) {
1359 uint32_t uiCode;1359 uint32_t uiCode;
1360 PSlice pCurrSlice = & (pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer);1360 PSlice pCurrSlice = & (pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer);
1361 iQpDelta = 0;1361 iQpDelta = 0;
1362 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_DELTA_QP;1362 PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_DELTA_QP;
1363 int32_t iCtxInc = (pCurrSlice->iLastDeltaQp != 0);1363 int32_t iCtxInc = (pCurrSlice->iLastDeltaQp != 0);
1364 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pBinCtx + iCtxInc, uiCode));1364 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pBinCtx + iCtxInc, uiCode));
1365 if (uiCode != 0) {1365 if (uiCode != 0) {
1366 WELS_READ_VERIFY (DecodeUnaryBinCabac (pCtx->pCabacDecEngine, pBinCtx + 2, 1, uiCode));1366 WELS_READ_VERIFY (DecodeUnaryBinCabac (pCtx->pCabacDecEngine, pBinCtx + 2, 1, uiCode));
1367 uiCode++;1367 uiCode++;
1368 iQpDelta = (uiCode + 1) >> 1;1368 iQpDelta = (uiCode + 1) >> 1;
1369 if ((uiCode & 1) == 0)1369 if ((uiCode & 1) == 0)
1370 iQpDelta = - iQpDelta;1370 iQpDelta = - iQpDelta;
1371 }1371 }
1372 pCurrSlice->iLastDeltaQp = iQpDelta;1372 pCurrSlice->iLastDeltaQp = iQpDelta;
1373 return ERR_NONE;1373 return ERR_NONE;
1374}1374}
1375 1375
1376int32_t ParseCbfInfoCabac (PWelsNeighAvail pNeighAvail, uint8_t* pNzcCache, int32_t iZIndex, int32_t iResProperty,1376int32_t ParseCbfInfoCabac (PWelsNeighAvail pNeighAvail, uint8_t* pNzcCache, int32_t iZIndex, int32_t iResProperty,
1377 PWelsDecoderContext pCtx, uint32_t& uiCbfBit) {1377 PWelsDecoderContext pCtx, uint32_t& uiCbfBit) {
1378 int8_t nA, nB/*, zigzag_idx = 0*/;1378 int8_t nA, nB/*, zigzag_idx = 0*/;
1379 int32_t iCurrBlkXy = pCtx->pCurDqLayer->iMbXyIndex;1379 int32_t iCurrBlkXy = pCtx->pCurDqLayer->iMbXyIndex;
1380 int32_t iTopBlkXy = iCurrBlkXy - pCtx->pCurDqLayer->iMbWidth; //default value: MB neighboring1380 int32_t iTopBlkXy = iCurrBlkXy - pCtx->pCurDqLayer->iMbWidth; //default value: MB neighboring
1381 int32_t iLeftBlkXy = iCurrBlkXy - 1; //default value: MB neighboring1381 int32_t iLeftBlkXy = iCurrBlkXy - 1; //default value: MB neighboring
1382 uint16_t* pCbfDc = pCtx->pCurDqLayer->pCbfDc;1382 uint16_t* pCbfDc = pCtx->pCurDqLayer->pCbfDc;
1383 uint32_t* pMbType = pCtx->pCurDqLayer->pMbType;1383 uint32_t* pMbType = pCtx->pCurDqLayer->pMbType;
1384 int32_t iCtxInc;1384 int32_t iCtxInc;
1385 uiCbfBit = 0;1385 uiCbfBit = 0;
1386 nA = nB = (int8_t)!!IS_INTRA (pMbType[iCurrBlkXy]);1386 nA = nB = (int8_t)!!IS_INTRA (pMbType[iCurrBlkXy]);
1387 1387
1388 if (iResProperty == I16_LUMA_DC || iResProperty == CHROMA_DC_U || iResProperty == CHROMA_DC_V) { //DC1388 if (iResProperty == I16_LUMA_DC || iResProperty == CHROMA_DC_U || iResProperty == CHROMA_DC_V) { //DC
1389 if (pNeighAvail->iTopAvail)1389 if (pNeighAvail->iTopAvail)
1390 nB = (pMbType[iTopBlkXy] == MB_TYPE_INTRA_PCM) || ((pCbfDc[iTopBlkXy] >> iResProperty) & 1);1390 nB = (pMbType[iTopBlkXy] == MB_TYPE_INTRA_PCM) || ((pCbfDc[iTopBlkXy] >> iResProperty) & 1);
1391 if (pNeighAvail->iLeftAvail)1391 if (pNeighAvail->iLeftAvail)
1392 nA = (pMbType[iLeftBlkXy] == MB_TYPE_INTRA_PCM) || ((pCbfDc[iLeftBlkXy] >> iResProperty) & 1);1392 nA = (pMbType[iLeftBlkXy] == MB_TYPE_INTRA_PCM) || ((pCbfDc[iLeftBlkXy] >> iResProperty) & 1);
1393 iCtxInc = nA + (nB << 1);1393 iCtxInc = nA + (nB << 1);
1394 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine,1394 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine,
1395 pCtx->pCabacCtx + NEW_CTX_OFFSET_CBF + g_kBlockCat2CtxOffsetCBF[iResProperty] + iCtxInc, uiCbfBit));1395 pCtx->pCabacCtx + NEW_CTX_OFFSET_CBF + g_kBlockCat2CtxOffsetCBF[iResProperty] + iCtxInc, uiCbfBit));
1396 if (uiCbfBit)1396 if (uiCbfBit)
1397 pCbfDc[iCurrBlkXy] |= (1 << iResProperty);1397 pCbfDc[iCurrBlkXy] |= (1 << iResProperty);
1398 } else { //AC1398 } else { //AC
1399 //for 4x4 blk, make sure blk-idx is correct1399 //for 4x4 blk, make sure blk-idx is correct
1400 if (pNzcCache[g_kCacheNzcScanIdx[iZIndex] - 8] != 0xff) { //top blk available1400 if (pNzcCache[g_kCacheNzcScanIdx[iZIndex] - 8] != 0xff) { //top blk available
1401 if (g_kTopBlkInsideMb[iZIndex])1401 if (g_kTopBlkInsideMb[iZIndex])
1402 iTopBlkXy = iCurrBlkXy;1402 iTopBlkXy = iCurrBlkXy;
1403 nB = pNzcCache[g_kCacheNzcScanIdx[iZIndex] - 8] || pMbType[iTopBlkXy] == MB_TYPE_INTRA_PCM;1403 nB = pNzcCache[g_kCacheNzcScanIdx[iZIndex] - 8] || pMbType[iTopBlkXy] == MB_TYPE_INTRA_PCM;
1404 }1404 }
1405 if (pNzcCache[g_kCacheNzcScanIdx[iZIndex] - 1] != 0xff) { //left blk available1405 if (pNzcCache[g_kCacheNzcScanIdx[iZIndex] - 1] != 0xff) { //left blk available
1406 if (g_kLeftBlkInsideMb[iZIndex])1406 if (g_kLeftBlkInsideMb[iZIndex])
1407 iLeftBlkXy = iCurrBlkXy;1407 iLeftBlkXy = iCurrBlkXy;
1408 nA = pNzcCache[g_kCacheNzcScanIdx[iZIndex] - 1] || pMbType[iLeftBlkXy] == MB_TYPE_INTRA_PCM;1408 nA = pNzcCache[g_kCacheNzcScanIdx[iZIndex] - 1] || pMbType[iLeftBlkXy] == MB_TYPE_INTRA_PCM;
1409 }1409 }
1410 1410
1411 iCtxInc = nA + (nB << 1);1411 iCtxInc = nA + (nB << 1);
1412 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine,1412 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine,
1413 pCtx->pCabacCtx + NEW_CTX_OFFSET_CBF + g_kBlockCat2CtxOffsetCBF[iResProperty] + iCtxInc, uiCbfBit));1413 pCtx->pCabacCtx + NEW_CTX_OFFSET_CBF + g_kBlockCat2CtxOffsetCBF[iResProperty] + iCtxInc, uiCbfBit));
1414 }1414 }
1415 return ERR_NONE;1415 return ERR_NONE;
1416}1416}
1417 1417
1418int32_t ParseSignificantMapCabac (int32_t* pSignificantMap, int32_t iResProperty, PWelsDecoderContext pCtx,1418int32_t ParseSignificantMapCabac (int32_t* pSignificantMap, int32_t iResProperty, PWelsDecoderContext pCtx,
1419 uint32_t& uiCoeffNum) {1419 uint32_t& uiCoeffNum) {
1420 uint32_t uiCode;1420 uint32_t uiCode;
1421 1421
1422 PWelsCabacCtx pMapCtx = pCtx->pCabacCtx + (iResProperty == LUMA_DC_AC_8 ? NEW_CTX_OFFSET_MAP_8x8 : NEW_CTX_OFFSET_MAP)1422 PWelsCabacCtx pMapCtx = pCtx->pCabacCtx + (iResProperty == LUMA_DC_AC_8 ? NEW_CTX_OFFSET_MAP_8x8 : NEW_CTX_OFFSET_MAP)
1423 + g_kBlockCat2CtxOffsetMap [iResProperty];1423 + g_kBlockCat2CtxOffsetMap [iResProperty];
1424 PWelsCabacCtx pLastCtx = pCtx->pCabacCtx + (iResProperty == LUMA_DC_AC_8 ? NEW_CTX_OFFSET_LAST_8x8 :1424 PWelsCabacCtx pLastCtx = pCtx->pCabacCtx + (iResProperty == LUMA_DC_AC_8 ? NEW_CTX_OFFSET_LAST_8x8 :
1425 NEW_CTX_OFFSET_LAST) + g_kBlockCat2CtxOffsetLast[iResProperty];1425 NEW_CTX_OFFSET_LAST) + g_kBlockCat2CtxOffsetLast[iResProperty];
1426 1426
1427 1427
1428 int32_t i;1428 int32_t i;
1429 uiCoeffNum = 0;1429 uiCoeffNum = 0;
1430 int32_t i0 = 0;1430 int32_t i0 = 0;
1431 int32_t i1 = g_kMaxPos[iResProperty];1431 int32_t i1 = g_kMaxPos[iResProperty];
1432 1432
1433 int32_t iCtx;1433 int32_t iCtx;
1434 1434
1435 for (i = i0; i < i1; ++i) {1435 for (i = i0; i < i1; ++i) {
1436 iCtx = (iResProperty == LUMA_DC_AC_8 ? g_kuiIdx2CtxSignificantCoeffFlag8x8[i] : i);1436 iCtx = (iResProperty == LUMA_DC_AC_8 ? g_kuiIdx2CtxSignificantCoeffFlag8x8[i] : i);
1437 //read significant1437 //read significant
1438 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pMapCtx + iCtx, uiCode));1438 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pMapCtx + iCtx, uiCode));
1439 if (uiCode) {1439 if (uiCode) {
1440 * (pSignificantMap++) = 1;1440 * (pSignificantMap++) = 1;
1441 ++ uiCoeffNum;1441 ++ uiCoeffNum;
1442 //read last significant1442 //read last significant
1443 iCtx = (iResProperty == LUMA_DC_AC_8 ? g_kuiIdx2CtxLastSignificantCoeffFlag8x8[i] : i);1443 iCtx = (iResProperty == LUMA_DC_AC_8 ? g_kuiIdx2CtxLastSignificantCoeffFlag8x8[i] : i);
1444 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pLastCtx + iCtx, uiCode));1444 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pLastCtx + iCtx, uiCode));
1445 if (uiCode) {1445 if (uiCode) {
1446 memset (pSignificantMap, 0, (i1 - i) * sizeof (int32_t));1446 memset (pSignificantMap, 0, (i1 - i) * sizeof (int32_t));
1447 return ERR_NONE;1447 return ERR_NONE;
1448 }1448 }
1449 } else1449 } else
1450 * (pSignificantMap++) = 0;1450 * (pSignificantMap++) = 0;
1451 }1451 }
1452 1452
1453 //deal with last pSignificantMap if no data1453 //deal with last pSignificantMap if no data
1454 //if(i < i1+1)1454 //if(i < i1+1)
1455 {1455 {
1456 *pSignificantMap = 1;1456 *pSignificantMap = 1;
1457 ++uiCoeffNum;1457 ++uiCoeffNum;
1458 }1458 }
1459 1459
1460 return ERR_NONE;1460 return ERR_NONE;
1461}1461}
1462 1462
1463int32_t ParseSignificantCoeffCabac (int32_t* pSignificant, int32_t iResProperty, PWelsDecoderContext pCtx) {1463int32_t ParseSignificantCoeffCabac (int32_t* pSignificant, int32_t iResProperty, PWelsDecoderContext pCtx) {
1464 uint32_t uiCode;1464 uint32_t uiCode;
1465 PWelsCabacCtx pOneCtx = pCtx->pCabacCtx + (iResProperty == LUMA_DC_AC_8 ? NEW_CTX_OFFSET_ONE_8x8 : NEW_CTX_OFFSET_ONE) +1465 PWelsCabacCtx pOneCtx = pCtx->pCabacCtx + (iResProperty == LUMA_DC_AC_8 ? NEW_CTX_OFFSET_ONE_8x8 : NEW_CTX_OFFSET_ONE) +
1466 g_kBlockCat2CtxOffsetOne[iResProperty];1466 g_kBlockCat2CtxOffsetOne[iResProperty];
1467 PWelsCabacCtx pAbsCtx = pCtx->pCabacCtx + (iResProperty == LUMA_DC_AC_8 ? NEW_CTX_OFFSET_ABS_8x8 : NEW_CTX_OFFSET_ABS) +1467 PWelsCabacCtx pAbsCtx = pCtx->pCabacCtx + (iResProperty == LUMA_DC_AC_8 ? NEW_CTX_OFFSET_ABS_8x8 : NEW_CTX_OFFSET_ABS) +
1468 g_kBlockCat2CtxOffsetAbs[iResProperty];1468 g_kBlockCat2CtxOffsetAbs[iResProperty];
1469 1469
1470 const int16_t iMaxType = g_kMaxC2[iResProperty];1470 const int16_t iMaxType = g_kMaxC2[iResProperty];
1471 int32_t i = g_kMaxPos[iResProperty];1471 int32_t i = g_kMaxPos[iResProperty];
1472 int32_t* pCoff = pSignificant + i;1472 int32_t* pCoff = pSignificant + i;
1473 int32_t c1 = 1;1473 int32_t c1 = 1;
1474 int32_t c2 = 0;1474 int32_t c2 = 0;
1475 for (; i >= 0; --i) {1475 for (; i >= 0; --i) {
1476 if (*pCoff != 0) {1476 if (*pCoff != 0) {
1477 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pOneCtx + c1, uiCode));1477 WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pOneCtx + c1, uiCode));
1478 *pCoff += uiCode;1478 *pCoff += uiCode;
1479 if (*pCoff == 2) {1479 if (*pCoff == 2) {
1480 WELS_READ_VERIFY (DecodeUEGLevelCabac (pCtx->pCabacDecEngine, pAbsCtx + c2, uiCode));1480 WELS_READ_VERIFY (DecodeUEGLevelCabac (pCtx->pCabacDecEngine, pAbsCtx + c2, uiCode));
1481 *pCoff += uiCode;1481 *pCoff += uiCode;
1482 ++c2;1482 ++c2;
1483 c2 = WELS_MIN (c2, iMaxType);1483 c2 = WELS_MIN (c2, iMaxType);
1484 c1 = 0;1484 c1 = 0;
1485 } else if (c1) {1485 } else if (c1) {
1486 ++c1;1486 ++c1;
1487 c1 = WELS_MIN (c1, 4);1487 c1 = WELS_MIN (c1, 4);
1488 }1488 }
1489 WELS_READ_VERIFY (DecodeBypassCabac (pCtx->pCabacDecEngine, uiCode));1489 WELS_READ_VERIFY (DecodeBypassCabac (pCtx->pCabacDecEngine, uiCode));
1490 if (uiCode)1490 if (uiCode)
1491 *pCoff = - *pCoff;1491 *pCoff = - *pCoff;
1492 }1492 }
1493 pCoff--;1493 pCoff--;
1494 }1494 }
1495 return ERR_NONE;1495 return ERR_NONE;
1496}1496}
1497 1497
1498int32_t ParseResidualBlockCabac8x8 (PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCountCache, SBitStringAux* pBsAux,1498int32_t ParseResidualBlockCabac8x8 (PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCountCache, SBitStringAux* pBsAux,
1499 int32_t iIndex, int32_t iMaxNumCoeff, const uint8_t* pScanTable, int32_t iResProperty,1499 int32_t iIndex, int32_t iMaxNumCoeff, const uint8_t* pScanTable, int32_t iResProperty,
1500 short* sTCoeff, /*int mb_mode*/ uint8_t uiQp, PWelsDecoderContext pCtx) {1500 short* sTCoeff, /*int mb_mode*/ uint8_t uiQp, PWelsDecoderContext pCtx) {
1501 uint32_t uiTotalCoeffNum = 0;1501 uint32_t uiTotalCoeffNum = 0;
1502 uint32_t uiCbpBit;1502 uint32_t uiCbpBit;
1503 int32_t pSignificantMap[64] = {0};1503 int32_t pSignificantMap[64] = {0};
1504 1504
1505 int32_t iMbResProperty = 0;1505 int32_t iMbResProperty = 0;
1506 GetMbResProperty (&iMbResProperty, &iResProperty, false);1506 GetMbResProperty (&iMbResProperty, &iResProperty, false);
1507 const uint16_t* pDeQuantMul = (pCtx->bUseScalingList) ? pCtx->pDequant_coeff8x8[iMbResProperty - 6][uiQp] :1507 const uint16_t* pDeQuantMul = (pCtx->bUseScalingList) ? pCtx->pDequant_coeff8x8[iMbResProperty - 6][uiQp] :
1508 g_kuiDequantCoeff8x8[uiQp];1508 g_kuiDequantCoeff8x8[uiQp];
1509 1509
1510 uiCbpBit = 1; // for 8x8, MaxNumCoeff == 64 && uiCbpBit == 11510 uiCbpBit = 1; // for 8x8, MaxNumCoeff == 64 && uiCbpBit == 1
1511 if (uiCbpBit) { //has coeff1511 if (uiCbpBit) { //has coeff
1512 WELS_READ_VERIFY (ParseSignificantMapCabac (pSignificantMap, iResProperty, pCtx, uiTotalCoeffNum));1512 WELS_READ_VERIFY (ParseSignificantMapCabac (pSignificantMap, iResProperty, pCtx, uiTotalCoeffNum));
1513 WELS_READ_VERIFY (ParseSignificantCoeffCabac (pSignificantMap, iResProperty, pCtx));1513 WELS_READ_VERIFY (ParseSignificantCoeffCabac (pSignificantMap, iResProperty, pCtx));
1514 }1514 }
1515 1515
1516 pNonZeroCountCache[g_kCacheNzcScanIdx[iIndex]] =1516 pNonZeroCountCache[g_kCacheNzcScanIdx[iIndex]] =
1517 pNonZeroCountCache[g_kCacheNzcScanIdx[iIndex + 1]] =1517 pNonZeroCountCache[g_kCacheNzcScanIdx[iIndex + 1]] =
1518 pNonZeroCountCache[g_kCacheNzcScanIdx[iIndex + 2]] =1518 pNonZeroCountCache[g_kCacheNzcScanIdx[iIndex + 2]] =
1519 pNonZeroCountCache[g_kCacheNzcScanIdx[iIndex + 3]] = (uint8_t)uiTotalCoeffNum;1519 pNonZeroCountCache[g_kCacheNzcScanIdx[iIndex + 3]] = (uint8_t)uiTotalCoeffNum;
1520 if (uiTotalCoeffNum == 0) {1520 if (uiTotalCoeffNum == 0) {
1521 return ERR_NONE;1521 return ERR_NONE;
1522 }1522 }
1523 int32_t j = 0, i;1523 int32_t j = 0, i;
1524 if (iResProperty == LUMA_DC_AC_8) {1524 if (iResProperty == LUMA_DC_AC_8) {
1525 do {1525 do {
1526 if (pSignificantMap[j] != 0) {1526 if (pSignificantMap[j] != 0) {
1527 i = pScanTable[ j ];1527 i = pScanTable[ j ];
1528 sTCoeff[i] = uiQp >= 36 ? ((pSignificantMap[j] * pDeQuantMul[i]) * (1 << (uiQp / 6 - 6))) : ((1528 sTCoeff[i] = uiQp >= 36 ? ((pSignificantMap[j] * pDeQuantMul[i]) * (1 << (uiQp / 6 - 6))) : ((
1529 pSignificantMap[j] * pDeQuantMul[i] + (1 << (5 - uiQp / 6))) >> (6 - uiQp / 6));1529 pSignificantMap[j] * pDeQuantMul[i] + (1 << (5 - uiQp / 6))) >> (6 - uiQp / 6));
1530 }1530 }
1531 ++j;1531 ++j;
1532 } while (j < 64);1532 } while (j < 64);
1533 }1533 }
1534 1534
1535 return ERR_NONE;1535 return ERR_NONE;
1536}1536}
1537 1537
1538int32_t ParseResidualBlockCabac (PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCountCache, SBitStringAux* pBsAux,1538int32_t ParseResidualBlockCabac (PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCountCache, SBitStringAux* pBsAux,
1539 int32_t iIndex, int32_t iMaxNumCoeff,1539 int32_t iIndex, int32_t iMaxNumCoeff,
1540 const uint8_t* pScanTable, int32_t iResProperty, short* sTCoeff, /*int mb_mode*/ uint8_t uiQp,1540 const uint8_t* pScanTable, int32_t iResProperty, short* sTCoeff, /*int mb_mode*/ uint8_t uiQp,
1541 PWelsDecoderContext pCtx) {1541 PWelsDecoderContext pCtx) {
1542 int32_t iCurNzCacheIdx;1542 int32_t iCurNzCacheIdx;
1543 uint32_t uiTotalCoeffNum = 0;1543 uint32_t uiTotalCoeffNum = 0;
1544 uint32_t uiCbpBit;1544 uint32_t uiCbpBit;
1545 int32_t pSignificantMap[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};1545 int32_t pSignificantMap[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1546 1546
1547 int32_t iMbResProperty = 0;1547 int32_t iMbResProperty = 0;
1548 GetMbResProperty (&iMbResProperty, &iResProperty, false);1548 GetMbResProperty (&iMbResProperty, &iResProperty, false);
1549 const uint16_t* pDeQuantMul = (pCtx->bUseScalingList) ? pCtx->pDequant_coeff4x4[iMbResProperty][uiQp] :1549 const uint16_t* pDeQuantMul = (pCtx->bUseScalingList) ? pCtx->pDequant_coeff4x4[iMbResProperty][uiQp] :
1550 g_kuiDequantCoeff[uiQp];1550 g_kuiDequantCoeff[uiQp];
1551 1551
1552 WELS_READ_VERIFY (ParseCbfInfoCabac (pNeighAvail, pNonZeroCountCache, iIndex, iResProperty, pCtx, uiCbpBit));1552 WELS_READ_VERIFY (ParseCbfInfoCabac (pNeighAvail, pNonZeroCountCache, iIndex, iResProperty, pCtx, uiCbpBit));
1553 if (uiCbpBit) { //has coeff1553 if (uiCbpBit) { //has coeff
1554 WELS_READ_VERIFY (ParseSignificantMapCabac (pSignificantMap, iResProperty, pCtx, uiTotalCoeffNum));1554 WELS_READ_VERIFY (ParseSignificantMapCabac (pSignificantMap, iResProperty, pCtx, uiTotalCoeffNum));
1555 WELS_READ_VERIFY (ParseSignificantCoeffCabac (pSignificantMap, iResProperty, pCtx));1555 WELS_READ_VERIFY (ParseSignificantCoeffCabac (pSignificantMap, iResProperty, pCtx));
1556 }1556 }
1557 1557
1558 iCurNzCacheIdx = g_kCacheNzcScanIdx[iIndex];1558 iCurNzCacheIdx = g_kCacheNzcScanIdx[iIndex];
1559 pNonZeroCountCache[iCurNzCacheIdx] = (uint8_t)uiTotalCoeffNum;1559 pNonZeroCountCache[iCurNzCacheIdx] = (uint8_t)uiTotalCoeffNum;
1560 if (uiTotalCoeffNum == 0) {1560 if (uiTotalCoeffNum == 0) {
1561 return ERR_NONE;1561 return ERR_NONE;
1562 }1562 }
1563 int32_t j = 0;1563 int32_t j = 0;
1564 if (iResProperty == I16_LUMA_DC) {1564 if (iResProperty == I16_LUMA_DC) {
1565 do {1565 do {
1566 sTCoeff[pScanTable[j]] = pSignificantMap[j];1566 sTCoeff[pScanTable[j]] = pSignificantMap[j];
1567 ++j;1567 ++j;
1568 } while (j < 16);1568 } while (j < 16);
1569 WelsLumaDcDequantIdct (sTCoeff, uiQp, pCtx);1569 WelsLumaDcDequantIdct (sTCoeff, uiQp, pCtx);
1570 } else if (iResProperty == CHROMA_DC_U || iResProperty == CHROMA_DC_V) {1570 } else if (iResProperty == CHROMA_DC_U || iResProperty == CHROMA_DC_V) {
1571 do {1571 do {
1572 sTCoeff[pScanTable[j]] = pSignificantMap[j];1572 sTCoeff[pScanTable[j]] = pSignificantMap[j];
1573 ++j;1573 ++j;
1574 } while (j < 4);1574 } while (j < 4);
1575 //iHadamard2x21575 //iHadamard2x2
1576 WelsChromaDcIdct (sTCoeff);1576 WelsChromaDcIdct (sTCoeff);
1577 //scaling1577 //scaling
1578 if (!pCtx->bUseScalingList) {1578 if (!pCtx->bUseScalingList) {
1579 for (j = 0; j < 4; ++j) {1579 for (j = 0; j < 4; ++j) {
1580 sTCoeff[pScanTable[j]] = (int16_t) ((int64_t)sTCoeff[pScanTable[j]] * (int64_t)pDeQuantMul[0] >> 1);1580 sTCoeff[pScanTable[j]] = (int16_t) ((int64_t)sTCoeff[pScanTable[j]] * (int64_t)pDeQuantMul[0] >> 1);
1581 }1581 }
1582 } else { //with scaling list1582 } else { //with scaling list
1583 for (j = 0; j < 4; ++j) {1583 for (j = 0; j < 4; ++j) {
1584 sTCoeff[pScanTable[j]] = (int16_t) ((int64_t)sTCoeff[pScanTable[j]] * (int64_t)pDeQuantMul[0] >> 5);1584 sTCoeff[pScanTable[j]] = (int16_t) ((int64_t)sTCoeff[pScanTable[j]] * (int64_t)pDeQuantMul[0] >> 5);
1585 }1585 }
1586 }1586 }
1587 } else { //luma ac, chroma ac1587 } else { //luma ac, chroma ac
1588 do {1588 do {
1589 if (pSignificantMap[j] != 0) {1589 if (pSignificantMap[j] != 0) {
1590 if (!pCtx->bUseScalingList) {1590 if (!pCtx->bUseScalingList) {
1591 sTCoeff[pScanTable[j]] = pSignificantMap[j] * pDeQuantMul[pScanTable[j] & 0x07];1591 sTCoeff[pScanTable[j]] = pSignificantMap[j] * pDeQuantMul[pScanTable[j] & 0x07];
1592 } else {1592 } else {
1593 sTCoeff[pScanTable[j]] = (int16_t) (((int64_t)pSignificantMap[j] * (int64_t)pDeQuantMul[pScanTable[j]] + 8) >> 4);1593 sTCoeff[pScanTable[j]] = (int16_t) (((int64_t)pSignificantMap[j] * (int64_t)pDeQuantMul[pScanTable[j]] + 8) >> 4);
1594 }1594 }
1595 }1595 }
1596 ++j;1596 ++j;
1597 } while (j < 16);1597 } while (j < 16);
1598 }1598 }
1599 return ERR_NONE;1599 return ERR_NONE;
1600}1600}
1601 1601
1602int32_t ParseIPCMInfoCabac (PWelsDecoderContext pCtx) {1602int32_t ParseIPCMInfoCabac (PWelsDecoderContext pCtx) {
1603 int32_t i;1603 int32_t i;
1604 PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine;1604 PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine;
1605 SBitStringAux* pBsAux = pCtx->pCurDqLayer->pBitStringAux;1605 SBitStringAux* pBsAux = pCtx->pCurDqLayer->pBitStringAux;
1606 SDqLayer* pCurLayer = pCtx->pCurDqLayer;1606 SDqLayer* pCurLayer = pCtx->pCurDqLayer;
1607 int32_t iDstStrideLuma = pCurLayer->pDec->iLinesize[0];1607 int32_t iDstStrideLuma = pCurLayer->pDec->iLinesize[0];
1608 int32_t iDstStrideChroma = pCurLayer->pDec->iLinesize[1];1608 int32_t iDstStrideChroma = pCurLayer->pDec->iLinesize[1];
1609 int32_t iMbX = pCurLayer->iMbX;1609 int32_t iMbX = pCurLayer->iMbX;
1610 int32_t iMbY = pCurLayer->iMbY;1610 int32_t iMbY = pCurLayer->iMbY;
1611 int32_t iMbXy = pCurLayer->iMbXyIndex;1611 int32_t iMbXy = pCurLayer->iMbXyIndex;
1612 1612
1613 int32_t iMbOffsetLuma = (iMbX + iMbY * iDstStrideLuma) << 4;1613 int32_t iMbOffsetLuma = (iMbX + iMbY * iDstStrideLuma) << 4;
1614 int32_t iMbOffsetChroma = (iMbX + iMbY * iDstStrideChroma) << 3;1614 int32_t iMbOffsetChroma = (iMbX + iMbY * iDstStrideChroma) << 3;
1615 1615
1616 uint8_t* pMbDstY = pCtx->pDec->pData[0] + iMbOffsetLuma;1616 uint8_t* pMbDstY = pCtx->pDec->pData[0] + iMbOffsetLuma;
1617 uint8_t* pMbDstU = pCtx->pDec->pData[1] + iMbOffsetChroma;1617 uint8_t* pMbDstU = pCtx->pDec->pData[1] + iMbOffsetChroma;
1618 uint8_t* pMbDstV = pCtx->pDec->pData[2] + iMbOffsetChroma;1618 uint8_t* pMbDstV = pCtx->pDec->pData[2] + iMbOffsetChroma;
1619 1619
1620 uint8_t* pPtrSrc;1620 uint8_t* pPtrSrc;
1621 1621
1622 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA_PCM;1622 pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA_PCM;
1623 RestoreCabacDecEngineToBS (pCabacDecEngine, pBsAux);1623 RestoreCabacDecEngineToBS (pCabacDecEngine, pBsAux);
1624 intX_t iBytesLeft = pBsAux->pEndBuf - pBsAux->pCurBuf;1624 intX_t iBytesLeft = pBsAux->pEndBuf - pBsAux->pCurBuf;
1625 if (iBytesLeft < 384) {1625 if (iBytesLeft < 384) {
1626 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_CABAC_NO_BS_TO_READ);1626 return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_CABAC_NO_BS_TO_READ);
1627 }1627 }
1628 pPtrSrc = pBsAux->pCurBuf;1628 pPtrSrc = pBsAux->pCurBuf;
1629 if (!pCtx->pParam->bParseOnly) {1629 if (!pCtx->pParam->bParseOnly) {
1630 for (i = 0; i < 16; i++) { //luma1630 for (i = 0; i < 16; i++) { //luma
1631 memcpy (pMbDstY, pPtrSrc, 16);1631 memcpy (pMbDstY, pPtrSrc, 16);
1632 pMbDstY += iDstStrideLuma;1632 pMbDstY += iDstStrideLuma;
1633 pPtrSrc += 16;1633 pPtrSrc += 16;
1634 }1634 }
1635 for (i = 0; i < 8; i++) { //cb1635 for (i = 0; i < 8; i++) { //cb
1636 memcpy (pMbDstU, pPtrSrc, 8);1636 memcpy (pMbDstU, pPtrSrc, 8);
1637 pMbDstU += iDstStrideChroma;1637 pMbDstU += iDstStrideChroma;
1638 pPtrSrc += 8;1638 pPtrSrc += 8;
1639 }1639 }
1640 for (i = 0; i < 8; i++) { //cr1640 for (i = 0; i < 8; i++) { //cr
1641 memcpy (pMbDstV, pPtrSrc, 8);1641 memcpy (pMbDstV, pPtrSrc, 8);
1642 pMbDstV += iDstStrideChroma;1642 pMbDstV += iDstStrideChroma;
1643 pPtrSrc += 8;1643 pPtrSrc += 8;
1644 }1644 }
1645 }1645 }
1646 1646
1647 pBsAux->pCurBuf += 384;1647 pBsAux->pCurBuf += 384;
1648 1648
1649 pCurLayer->pLumaQp[iMbXy] = 0;1649 pCurLayer->pLumaQp[iMbXy] = 0;
1650 pCurLayer->pChromaQp[iMbXy][0] = pCurLayer->pChromaQp[iMbXy][1] = 0;1650 pCurLayer->pChromaQp[iMbXy][0] = pCurLayer->pChromaQp[iMbXy][1] = 0;
1651 memset (pCurLayer->pNzc[iMbXy], 16, sizeof (pCurLayer->pNzc[iMbXy]));1651 memset (pCurLayer->pNzc[iMbXy], 16, sizeof (pCurLayer->pNzc[iMbXy]));
1652 1652
1653 //step 4: cabac engine init1653 //step 4: cabac engine init
1654 WELS_READ_VERIFY (InitReadBits (pBsAux, 1));1654 WELS_READ_VERIFY (InitReadBits (pBsAux, 1));
1655 WELS_READ_VERIFY (InitCabacDecEngineFromBS (pCabacDecEngine, pBsAux));1655 WELS_READ_VERIFY (InitCabacDecEngineFromBS (pCabacDecEngine, pBsAux));
1656 return ERR_NONE;1656 return ERR_NONE;
1657}1657}
1658}1658}
codec/decoder/core/src/rec_mb.cpp+1044−1044
@@ -1,1044 +1,1044 @@
1/*!1/*!
2 * \copy2 * \copy
3 * Copyright (c) 2009-2013, Cisco Systems3 * Copyright (c) 2009-2013, Cisco Systems
4 * All rights reserved.4 * All rights reserved.
5 *5 *
6 * Redistribution and use in source and binary forms, with or without6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions7 * modification, are permitted provided that the following conditions
8 * are met:8 * are met:
9 *9 *
10 * * Redistributions of source code must retain the above copyright10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.11 * notice, this list of conditions and the following disclaimer.
12 *12 *
13 * * Redistributions in binary form must reproduce the above copyright13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the15 * the documentation and/or other materials provided with the
16 * distribution.16 * distribution.
17 *17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.29 * POSSIBILITY OF SUCH DAMAGE.
30 *30 *
31 *31 *
32 * \file rec_mb.c32 * \file rec_mb.c
33 *33 *
34 * \brief implementation for all macroblock decoding process after mb syntax parsing and residual decoding with cavlc.34 * \brief implementation for all macroblock decoding process after mb syntax parsing and residual decoding with cavlc.
35 *35 *
36 * \date 3/18/2009 Created36 * \date 3/18/2009 Created
37 *37 *
38 *************************************************************************************38 *************************************************************************************
39 */39 */
40 40
41 41
42#include "rec_mb.h"42#include "rec_mb.h"
43#include "decode_slice.h"43#include "decode_slice.h"
44 44
45namespace WelsDec {45namespace WelsDec {
46 46
47void WelsFillRecNeededMbInfo (PWelsDecoderContext pCtx, bool bOutput, PDqLayer pCurLayer) {47void WelsFillRecNeededMbInfo (PWelsDecoderContext pCtx, bool bOutput, PDqLayer pCurLayer) {
48 PPicture pCurPic = pCtx->pDec;48 PPicture pCurPic = pCtx->pDec;
49 int32_t iLumaStride = pCurPic->iLinesize[0];49 int32_t iLumaStride = pCurPic->iLinesize[0];
50 int32_t iChromaStride = pCurPic->iLinesize[1];50 int32_t iChromaStride = pCurPic->iLinesize[1];
51 int32_t iMbX = pCurLayer->iMbX;51 int32_t iMbX = pCurLayer->iMbX;
52 int32_t iMbY = pCurLayer->iMbY;52 int32_t iMbY = pCurLayer->iMbY;
53 53
54 pCurLayer->iLumaStride = iLumaStride;54 pCurLayer->iLumaStride = iLumaStride;
55 pCurLayer->iChromaStride = iChromaStride;55 pCurLayer->iChromaStride = iChromaStride;
56 56
57 if (bOutput) {57 if (bOutput) {
58 pCurLayer->pPred[0] = pCurPic->pData[0] + ((iMbY * iLumaStride + iMbX) << 4);58 pCurLayer->pPred[0] = pCurPic->pData[0] + ((iMbY * iLumaStride + iMbX) << 4);
59 pCurLayer->pPred[1] = pCurPic->pData[1] + ((iMbY * iChromaStride + iMbX) << 3);59 pCurLayer->pPred[1] = pCurPic->pData[1] + ((iMbY * iChromaStride + iMbX) << 3);
60 pCurLayer->pPred[2] = pCurPic->pData[2] + ((iMbY * iChromaStride + iMbX) << 3);60 pCurLayer->pPred[2] = pCurPic->pData[2] + ((iMbY * iChromaStride + iMbX) << 3);
61 }61 }
62}62}
63 63
64int32_t RecI8x8Mb (int32_t iMbXy, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) {64int32_t RecI8x8Mb (int32_t iMbXy, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) {
65 RecI8x8Luma (iMbXy, pCtx, pScoeffLevel, pDqLayer);65 RecI8x8Luma (iMbXy, pCtx, pScoeffLevel, pDqLayer);
66 RecI4x4Chroma (iMbXy, pCtx, pScoeffLevel, pDqLayer);66 RecI4x4Chroma (iMbXy, pCtx, pScoeffLevel, pDqLayer);
67 return ERR_NONE;67 return ERR_NONE;
68}68}
69 69
70int32_t RecI8x8Luma (int32_t iMbXy, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) {70int32_t RecI8x8Luma (int32_t iMbXy, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) {
71 /*****get local variable from outer variable********/71 /*****get local variable from outer variable********/
72 /*prediction info*/72 /*prediction info*/
73 uint8_t* pPred = pDqLayer->pPred[0];73 uint8_t* pPred = pDqLayer->pPred[0];
74 74
75 int32_t iLumaStride = pDqLayer->iLumaStride;75 int32_t iLumaStride = pDqLayer->iLumaStride;
76 int32_t* pBlockOffset = pCtx->iDecBlockOffsetArray;76 int32_t* pBlockOffset = pCtx->iDecBlockOffsetArray;
77 PGetIntraPred8x8Func* pGetI8x8LumaPredFunc = pCtx->pGetI8x8LumaPredFunc;77 PGetIntraPred8x8Func* pGetI8x8LumaPredFunc = pCtx->pGetI8x8LumaPredFunc;
78 78
79 int8_t* pIntra8x8PredMode = pDqLayer->pIntra4x4FinalMode[iMbXy]; // I_NxN79 int8_t* pIntra8x8PredMode = pDqLayer->pIntra4x4FinalMode[iMbXy]; // I_NxN
80 int16_t* pRS = pScoeffLevel;80 int16_t* pRS = pScoeffLevel;
81 /*itransform info*/81 /*itransform info*/
82 PIdctResAddPredFunc pIdctResAddPredFunc = pCtx->pIdctResAddPredFunc8x8;82 PIdctResAddPredFunc pIdctResAddPredFunc = pCtx->pIdctResAddPredFunc8x8;
83 83
84 /*************local variable********************/84 /*************local variable********************/
85 uint8_t i = 0;85 uint8_t i = 0;
86 bool bTLAvail[4], bTRAvail[4];86 bool bTLAvail[4], bTRAvail[4];
87 // Top-Right : Left : Top-Left : Top87 // Top-Right : Left : Top-Left : Top
88 bTLAvail[0] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x02);88 bTLAvail[0] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x02);
89 bTLAvail[1] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x01);89 bTLAvail[1] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x01);
90 bTLAvail[2] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x04);90 bTLAvail[2] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x04);
91 bTLAvail[3] = true;91 bTLAvail[3] = true;
92 92
93 bTRAvail[0] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x01);93 bTRAvail[0] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x01);
94 bTRAvail[1] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x08);94 bTRAvail[1] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x08);
95 bTRAvail[2] = true;95 bTRAvail[2] = true;
96 bTRAvail[3] = false;96 bTRAvail[3] = false;
97 97
98 /*************real process*********************/98 /*************real process*********************/
99 for (i = 0; i < 4; i++) {99 for (i = 0; i < 4; i++) {
100 100
101 uint8_t* pPredI8x8 = pPred + pBlockOffset[i << 2];101 uint8_t* pPredI8x8 = pPred + pBlockOffset[i << 2];
102 uint8_t uiMode = pIntra8x8PredMode[g_kuiScan4[i << 2]];102 uint8_t uiMode = pIntra8x8PredMode[g_kuiScan4[i << 2]];
103 103
104 pGetI8x8LumaPredFunc[uiMode] (pPredI8x8, iLumaStride, bTLAvail[i], bTRAvail[i]);104 pGetI8x8LumaPredFunc[uiMode] (pPredI8x8, iLumaStride, bTLAvail[i], bTRAvail[i]);
105 105
106 int32_t iIndex = g_kuiMbCountScan4Idx[i << 2];106 int32_t iIndex = g_kuiMbCountScan4Idx[i << 2];
107 if (pDqLayer->pNzc[iMbXy][iIndex] || pDqLayer->pNzc[iMbXy][iIndex + 1] || pDqLayer->pNzc[iMbXy][iIndex + 4]107 if (pDqLayer->pNzc[iMbXy][iIndex] || pDqLayer->pNzc[iMbXy][iIndex + 1] || pDqLayer->pNzc[iMbXy][iIndex + 4]
108 || pDqLayer->pNzc[iMbXy][iIndex + 5]) {108 || pDqLayer->pNzc[iMbXy][iIndex + 5]) {
109 int16_t* pRSI8x8 = &pRS[i << 6];109 int16_t* pRSI8x8 = &pRS[i << 6];
110 pIdctResAddPredFunc (pPredI8x8, iLumaStride, pRSI8x8);110 pIdctResAddPredFunc (pPredI8x8, iLumaStride, pRSI8x8);
111 }111 }
112 }112 }
113 113
114 return ERR_NONE;114 return ERR_NONE;
115}115}
116 116
117int32_t RecI4x4Mb (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) {117int32_t RecI4x4Mb (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) {
118 RecI4x4Luma (iMBXY, pCtx, pScoeffLevel, pDqLayer);118 RecI4x4Luma (iMBXY, pCtx, pScoeffLevel, pDqLayer);
119 RecI4x4Chroma (iMBXY, pCtx, pScoeffLevel, pDqLayer);119 RecI4x4Chroma (iMBXY, pCtx, pScoeffLevel, pDqLayer);
120 return ERR_NONE;120 return ERR_NONE;
121}121}
122 122
123 123
124int32_t RecI4x4Luma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) {124int32_t RecI4x4Luma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) {
125 /*****get local variable from outer variable********/125 /*****get local variable from outer variable********/
126 /*prediction info*/126 /*prediction info*/
127 uint8_t* pPred = pDqLayer->pPred[0];127 uint8_t* pPred = pDqLayer->pPred[0];
128 128
129 int32_t iLumaStride = pDqLayer->iLumaStride;129 int32_t iLumaStride = pDqLayer->iLumaStride;
130 int32_t* pBlockOffset = pCtx->iDecBlockOffsetArray;130 int32_t* pBlockOffset = pCtx->iDecBlockOffsetArray;
131 PGetIntraPredFunc* pGetI4x4LumaPredFunc = pCtx->pGetI4x4LumaPredFunc;131 PGetIntraPredFunc* pGetI4x4LumaPredFunc = pCtx->pGetI4x4LumaPredFunc;
132 132
133 int8_t* pIntra4x4PredMode = pDqLayer->pIntra4x4FinalMode[iMBXY];133 int8_t* pIntra4x4PredMode = pDqLayer->pIntra4x4FinalMode[iMBXY];
134 int16_t* pRS = pScoeffLevel;134 int16_t* pRS = pScoeffLevel;
135 /*itransform info*/135 /*itransform info*/
136 PIdctResAddPredFunc pIdctResAddPredFunc = pCtx->pIdctResAddPredFunc;136 PIdctResAddPredFunc pIdctResAddPredFunc = pCtx->pIdctResAddPredFunc;
137 137
138 138
139 /*************local variable********************/139 /*************local variable********************/
140 uint8_t i = 0;140 uint8_t i = 0;
141 141
142 /*************real process*********************/142 /*************real process*********************/
143 for (i = 0; i < 16; i++) {143 for (i = 0; i < 16; i++) {
144 144
145 uint8_t* pPredI4x4 = pPred + pBlockOffset[i];145 uint8_t* pPredI4x4 = pPred + pBlockOffset[i];
146 uint8_t uiMode = pIntra4x4PredMode[g_kuiScan4[i]];146 uint8_t uiMode = pIntra4x4PredMode[g_kuiScan4[i]];
147 147
148 pGetI4x4LumaPredFunc[uiMode] (pPredI4x4, iLumaStride);148 pGetI4x4LumaPredFunc[uiMode] (pPredI4x4, iLumaStride);
149 149
150 if (pDqLayer->pNzc[iMBXY][g_kuiMbCountScan4Idx[i]]) {150 if (pDqLayer->pNzc[iMBXY][g_kuiMbCountScan4Idx[i]]) {
151 int16_t* pRSI4x4 = &pRS[i << 4];151 int16_t* pRSI4x4 = &pRS[i << 4];
152 pIdctResAddPredFunc (pPredI4x4, iLumaStride, pRSI4x4);152 pIdctResAddPredFunc (pPredI4x4, iLumaStride, pRSI4x4);
153 }153 }
154 }154 }
155 155
156 return ERR_NONE;156 return ERR_NONE;
157}157}
158 158
159 159
160int32_t RecI4x4Chroma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) {160int32_t RecI4x4Chroma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) {
161 int32_t iChromaStride = pCtx->pCurDqLayer->pDec->iLinesize[1];161 int32_t iChromaStride = pCtx->pCurDqLayer->pDec->iLinesize[1];
162 162
163 int8_t iChromaPredMode = pDqLayer->pChromaPredMode[iMBXY];163 int8_t iChromaPredMode = pDqLayer->pChromaPredMode[iMBXY];
164 164
165 PGetIntraPredFunc* pGetIChromaPredFunc = pCtx->pGetIChromaPredFunc;165 PGetIntraPredFunc* pGetIChromaPredFunc = pCtx->pGetIChromaPredFunc;
166 166
167 uint8_t* pPred = pDqLayer->pPred[1];167 uint8_t* pPred = pDqLayer->pPred[1];
168 168
169 pGetIChromaPredFunc[iChromaPredMode] (pPred, iChromaStride);169 pGetIChromaPredFunc[iChromaPredMode] (pPred, iChromaStride);
170 pPred = pDqLayer->pPred[2];170 pPred = pDqLayer->pPred[2];
171 pGetIChromaPredFunc[iChromaPredMode] (pPred, iChromaStride);171 pGetIChromaPredFunc[iChromaPredMode] (pPred, iChromaStride);
172 172
173 RecChroma (iMBXY, pCtx, pScoeffLevel, pDqLayer);173 RecChroma (iMBXY, pCtx, pScoeffLevel, pDqLayer);
174 174
175 return ERR_NONE;175 return ERR_NONE;
176}176}
177 177
178 178
179int32_t RecI16x16Mb (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) {179int32_t RecI16x16Mb (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) {
180 /*decoder use, encoder no use*/180 /*decoder use, encoder no use*/
181 int8_t iI16x16PredMode = pDqLayer->pIntraPredMode[iMBXY][7];181 int8_t iI16x16PredMode = pDqLayer->pIntraPredMode[iMBXY][7];
182 int8_t iChromaPredMode = pDqLayer->pChromaPredMode[iMBXY];182 int8_t iChromaPredMode = pDqLayer->pChromaPredMode[iMBXY];
183 PGetIntraPredFunc* pGetIChromaPredFunc = pCtx->pGetIChromaPredFunc;183 PGetIntraPredFunc* pGetIChromaPredFunc = pCtx->pGetIChromaPredFunc;
184 PGetIntraPredFunc* pGetI16x16LumaPredFunc = pCtx->pGetI16x16LumaPredFunc;184 PGetIntraPredFunc* pGetI16x16LumaPredFunc = pCtx->pGetI16x16LumaPredFunc;
185 int32_t iUVStride = pCtx->pCurDqLayer->pDec->iLinesize[1];185 int32_t iUVStride = pCtx->pCurDqLayer->pDec->iLinesize[1];
186 186
187 /*common use by decoder&encoder*/187 /*common use by decoder&encoder*/
188 int32_t iYStride = pDqLayer->iLumaStride;188 int32_t iYStride = pDqLayer->iLumaStride;
189 int16_t* pRS = pScoeffLevel;189 int16_t* pRS = pScoeffLevel;
190 190
191 uint8_t* pPred = pDqLayer->pPred[0];191 uint8_t* pPred = pDqLayer->pPred[0];
192 192
193 PIdctFourResAddPredFunc pIdctFourResAddPredFunc = pCtx->pIdctFourResAddPredFunc;193 PIdctFourResAddPredFunc pIdctFourResAddPredFunc = pCtx->pIdctFourResAddPredFunc;
194 194
195 /*decode i16x16 y*/195 /*decode i16x16 y*/
196 pGetI16x16LumaPredFunc[iI16x16PredMode] (pPred, iYStride);196 pGetI16x16LumaPredFunc[iI16x16PredMode] (pPred, iYStride);
197 197
198 /*1 mb is divided 16 4x4_block to idct*/198 /*1 mb is divided 16 4x4_block to idct*/
199 const int8_t* pNzc = pDqLayer->pNzc[iMBXY];199 const int8_t* pNzc = pDqLayer->pNzc[iMBXY];
200 pIdctFourResAddPredFunc (pPred + 0 * iYStride + 0, iYStride, pRS + 0 * 64, pNzc + 0);200 pIdctFourResAddPredFunc (pPred + 0 * iYStride + 0, iYStride, pRS + 0 * 64, pNzc + 0);
201 pIdctFourResAddPredFunc (pPred + 0 * iYStride + 8, iYStride, pRS + 1 * 64, pNzc + 2);201 pIdctFourResAddPredFunc (pPred + 0 * iYStride + 8, iYStride, pRS + 1 * 64, pNzc + 2);
202 pIdctFourResAddPredFunc (pPred + 8 * iYStride + 0, iYStride, pRS + 2 * 64, pNzc + 8);202 pIdctFourResAddPredFunc (pPred + 8 * iYStride + 0, iYStride, pRS + 2 * 64, pNzc + 8);
203 pIdctFourResAddPredFunc (pPred + 8 * iYStride + 8, iYStride, pRS + 3 * 64, pNzc + 10);203 pIdctFourResAddPredFunc (pPred + 8 * iYStride + 8, iYStride, pRS + 3 * 64, pNzc + 10);
204 204
205 /*decode intra mb cb&cr*/205 /*decode intra mb cb&cr*/
206 pPred = pDqLayer->pPred[1];206 pPred = pDqLayer->pPred[1];
207 pGetIChromaPredFunc[iChromaPredMode] (pPred, iUVStride);207 pGetIChromaPredFunc[iChromaPredMode] (pPred, iUVStride);
208 pPred = pDqLayer->pPred[2];208 pPred = pDqLayer->pPred[2];
209 pGetIChromaPredFunc[iChromaPredMode] (pPred, iUVStride);209 pGetIChromaPredFunc[iChromaPredMode] (pPred, iUVStride);
210 RecChroma (iMBXY, pCtx, pScoeffLevel, pDqLayer);210 RecChroma (iMBXY, pCtx, pScoeffLevel, pDqLayer);
211 211
212 return ERR_NONE;212 return ERR_NONE;
213}213}
214 214
215 215
216//according to current 8*8 block ref_index to gain reference picture216//according to current 8*8 block ref_index to gain reference picture
217static inline void GetRefPic (sMCRefMember* pMCRefMem, PWelsDecoderContext pCtx, int8_t* pRefIdxList,217static inline void GetRefPic (sMCRefMember* pMCRefMem, PWelsDecoderContext pCtx, int8_t* pRefIdxList,
218 int32_t iIndex, int32_t listIdx) {218 int32_t iIndex, int32_t listIdx) {
219 PPicture pRefPic;219 PPicture pRefPic;
220 220
221 int8_t iRefIdx = pRefIdxList[iIndex];221 int8_t iRefIdx = pRefIdxList[iIndex];
222 if (iRefIdx >= 0) {222 if (iRefIdx >= 0) {
223 pRefPic = pCtx->sRefPic.pRefList[listIdx][iRefIdx];223 pRefPic = pCtx->sRefPic.pRefList[listIdx][iRefIdx];
224 224
225 if (pRefPic != NULL) {225 if (pRefPic != NULL) {
226 pMCRefMem->iSrcLineLuma = pRefPic->iLinesize[0];226 pMCRefMem->iSrcLineLuma = pRefPic->iLinesize[0];
227 pMCRefMem->iSrcLineChroma = pRefPic->iLinesize[1];227 pMCRefMem->iSrcLineChroma = pRefPic->iLinesize[1];
228 228
229 pMCRefMem->pSrcY = pRefPic->pData[0];229 pMCRefMem->pSrcY = pRefPic->pData[0];
230 pMCRefMem->pSrcU = pRefPic->pData[1];230 pMCRefMem->pSrcU = pRefPic->pData[1];
231 pMCRefMem->pSrcV = pRefPic->pData[2];231 pMCRefMem->pSrcV = pRefPic->pData[2];
232 }232 }
233 }233 }
234}234}
235 235
236 236
237#ifndef MC_FLOW_SIMPLE_JUDGE237#ifndef MC_FLOW_SIMPLE_JUDGE
238#define MC_FLOW_SIMPLE_JUDGE 1238#define MC_FLOW_SIMPLE_JUDGE 1
239#endif //MC_FLOW_SIMPLE_JUDGE239#endif //MC_FLOW_SIMPLE_JUDGE
240void BaseMC (sMCRefMember* pMCRefMem, int32_t iXOffset, int32_t iYOffset, SMcFunc* pMCFunc,240void BaseMC (sMCRefMember* pMCRefMem, int32_t iXOffset, int32_t iYOffset, SMcFunc* pMCFunc,
241 int32_t iBlkWidth, int32_t iBlkHeight, int16_t iMVs[2]) {241 int32_t iBlkWidth, int32_t iBlkHeight, int16_t iMVs[2]) {
242 int32_t iFullMVx = (iXOffset << 2) + iMVs[0]; //quarter pixel242 int32_t iFullMVx = (iXOffset << 2) + iMVs[0]; //quarter pixel
243 int32_t iFullMVy = (iYOffset << 2) + iMVs[1];243 int32_t iFullMVy = (iYOffset << 2) + iMVs[1];
244 iFullMVx = WELS_CLIP3 (iFullMVx, ((-PADDING_LENGTH + 2) * (1 << 2)),244 iFullMVx = WELS_CLIP3 (iFullMVx, ((-PADDING_LENGTH + 2) * (1 << 2)),
245 ((pMCRefMem->iPicWidth + PADDING_LENGTH - 19) * (1 << 2)));245 ((pMCRefMem->iPicWidth + PADDING_LENGTH - 19) * (1 << 2)));
246 iFullMVy = WELS_CLIP3 (iFullMVy, ((-PADDING_LENGTH + 2) * (1 << 2)),246 iFullMVy = WELS_CLIP3 (iFullMVy, ((-PADDING_LENGTH + 2) * (1 << 2)),
247 ((pMCRefMem->iPicHeight + PADDING_LENGTH - 19) * (1 << 2)));247 ((pMCRefMem->iPicHeight + PADDING_LENGTH - 19) * (1 << 2)));
248 248
249 int32_t iSrcPixOffsetLuma = (iFullMVx >> 2) + (iFullMVy >> 2) * pMCRefMem->iSrcLineLuma;249 int32_t iSrcPixOffsetLuma = (iFullMVx >> 2) + (iFullMVy >> 2) * pMCRefMem->iSrcLineLuma;
250 int32_t iSrcPixOffsetChroma = (iFullMVx >> 3) + (iFullMVy >> 3) * pMCRefMem->iSrcLineChroma;250 int32_t iSrcPixOffsetChroma = (iFullMVx >> 3) + (iFullMVy >> 3) * pMCRefMem->iSrcLineChroma;
251 251
252 int32_t iBlkWidthChroma = iBlkWidth >> 1;252 int32_t iBlkWidthChroma = iBlkWidth >> 1;
253 int32_t iBlkHeightChroma = iBlkHeight >> 1;253 int32_t iBlkHeightChroma = iBlkHeight >> 1;
254 254
255 uint8_t* pSrcY = pMCRefMem->pSrcY + iSrcPixOffsetLuma;255 uint8_t* pSrcY = pMCRefMem->pSrcY + iSrcPixOffsetLuma;
256 uint8_t* pSrcU = pMCRefMem->pSrcU + iSrcPixOffsetChroma;256 uint8_t* pSrcU = pMCRefMem->pSrcU + iSrcPixOffsetChroma;
257 uint8_t* pSrcV = pMCRefMem->pSrcV + iSrcPixOffsetChroma;257 uint8_t* pSrcV = pMCRefMem->pSrcV + iSrcPixOffsetChroma;
258 uint8_t* pDstY = pMCRefMem->pDstY;258 uint8_t* pDstY = pMCRefMem->pDstY;
259 uint8_t* pDstU = pMCRefMem->pDstU;259 uint8_t* pDstU = pMCRefMem->pDstU;
260 uint8_t* pDstV = pMCRefMem->pDstV;260 uint8_t* pDstV = pMCRefMem->pDstV;
261 261
262 pMCFunc->pMcLumaFunc (pSrcY, pMCRefMem->iSrcLineLuma, pDstY, pMCRefMem->iDstLineLuma, iFullMVx, iFullMVy, iBlkWidth,262 pMCFunc->pMcLumaFunc (pSrcY, pMCRefMem->iSrcLineLuma, pDstY, pMCRefMem->iDstLineLuma, iFullMVx, iFullMVy, iBlkWidth,
263 iBlkHeight);263 iBlkHeight);
264 pMCFunc->pMcChromaFunc (pSrcU, pMCRefMem->iSrcLineChroma, pDstU, pMCRefMem->iDstLineChroma, iFullMVx, iFullMVy,264 pMCFunc->pMcChromaFunc (pSrcU, pMCRefMem->iSrcLineChroma, pDstU, pMCRefMem->iDstLineChroma, iFullMVx, iFullMVy,
265 iBlkWidthChroma, iBlkHeightChroma);265 iBlkWidthChroma, iBlkHeightChroma);
266 pMCFunc->pMcChromaFunc (pSrcV, pMCRefMem->iSrcLineChroma, pDstV, pMCRefMem->iDstLineChroma, iFullMVx, iFullMVy,266 pMCFunc->pMcChromaFunc (pSrcV, pMCRefMem->iSrcLineChroma, pDstV, pMCRefMem->iDstLineChroma, iFullMVx, iFullMVy,
267 iBlkWidthChroma, iBlkHeightChroma);267 iBlkWidthChroma, iBlkHeightChroma);
268 268
269}269}
270 270
271static void WeightPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, int32_t listIdx, int32_t iRefIdx,271static void WeightPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, int32_t listIdx, int32_t iRefIdx,
272 int32_t iBlkWidth,272 int32_t iBlkWidth,
273 int32_t iBlkHeight) {273 int32_t iBlkHeight) {
274 274
275 275
276 int32_t iLog2denom, iWoc, iOoc;276 int32_t iLog2denom, iWoc, iOoc;
277 int32_t iPredTemp, iLineStride;277 int32_t iPredTemp, iLineStride;
278 int32_t iPixel = 0;278 int32_t iPixel = 0;
279 uint8_t* pDst;279 uint8_t* pDst;
280 //luma280 //luma
281 iLog2denom = pCurDqLayer->pPredWeightTable->uiLumaLog2WeightDenom;281 iLog2denom = pCurDqLayer->pPredWeightTable->uiLumaLog2WeightDenom;
282 iWoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iLumaWeight[iRefIdx];282 iWoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iLumaWeight[iRefIdx];
283 iOoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iLumaOffset[iRefIdx];283 iOoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iLumaOffset[iRefIdx];
284 iLineStride = pMCRefMem->iDstLineLuma;284 iLineStride = pMCRefMem->iDstLineLuma;
285 285
286 for (int i = 0; i < iBlkHeight; i++) {286 for (int i = 0; i < iBlkHeight; i++) {
287 for (int j = 0; j < iBlkWidth; j++) {287 for (int j = 0; j < iBlkWidth; j++) {
288 iPixel = j + i * (iLineStride);288 iPixel = j + i * (iLineStride);
289 if (iLog2denom >= 1) {289 if (iLog2denom >= 1) {
290 iPredTemp = ((pMCRefMem->pDstY[iPixel] * iWoc + (1 << (iLog2denom - 1))) >> iLog2denom) + iOoc;290 iPredTemp = ((pMCRefMem->pDstY[iPixel] * iWoc + (1 << (iLog2denom - 1))) >> iLog2denom) + iOoc;
291 291
292 pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255);292 pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255);
293 } else {293 } else {
294 iPredTemp = pMCRefMem->pDstY[iPixel] * iWoc + iOoc;294 iPredTemp = pMCRefMem->pDstY[iPixel] * iWoc + iOoc;
295 295
296 pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255);296 pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255);
297 297
298 }298 }
299 }299 }
300 }300 }
301 301
302 302
303 //UV303 //UV
304 iBlkWidth = iBlkWidth >> 1;304 iBlkWidth = iBlkWidth >> 1;
305 iBlkHeight = iBlkHeight >> 1;305 iBlkHeight = iBlkHeight >> 1;
306 iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom;306 iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom;
307 iLineStride = pMCRefMem->iDstLineChroma;307 iLineStride = pMCRefMem->iDstLineChroma;
308 308
309 for (int i = 0; i < 2; i++) {309 for (int i = 0; i < 2; i++) {
310 310
311 311
312 //iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom;312 //iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom;
313 iWoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iChromaWeight[iRefIdx][i];313 iWoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iChromaWeight[iRefIdx][i];
314 iOoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iChromaOffset[iRefIdx][i];314 iOoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iChromaOffset[iRefIdx][i];
315 pDst = i ? pMCRefMem->pDstV : pMCRefMem->pDstU;315 pDst = i ? pMCRefMem->pDstV : pMCRefMem->pDstU;
316 //iLineStride = pMCRefMem->iDstLineChroma;316 //iLineStride = pMCRefMem->iDstLineChroma;
317 317
318 for (int i = 0; i < iBlkHeight ; i++) {318 for (int i = 0; i < iBlkHeight ; i++) {
319 for (int j = 0; j < iBlkWidth; j++) {319 for (int j = 0; j < iBlkWidth; j++) {
320 iPixel = j + i * (iLineStride);320 iPixel = j + i * (iLineStride);
321 if (iLog2denom >= 1) {321 if (iLog2denom >= 1) {
322 iPredTemp = ((pDst[iPixel] * iWoc + (1 << (iLog2denom - 1))) >> iLog2denom) + iOoc;322 iPredTemp = ((pDst[iPixel] * iWoc + (1 << (iLog2denom - 1))) >> iLog2denom) + iOoc;
323 323
324 pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255);324 pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255);
325 } else {325 } else {
326 iPredTemp = pDst[iPixel] * iWoc + iOoc;326 iPredTemp = pDst[iPixel] * iWoc + iOoc;
327 327
328 pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255);328 pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255);
329 329
330 }330 }
331 }331 }
332 332
333 }333 }
334 334
335 335
336 }336 }
337}337}
338 338
339static void BiWeightPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, sMCRefMember* pTempMCRefMem,339static void BiWeightPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, sMCRefMember* pTempMCRefMem,
340 int32_t iRefIdx1, int32_t iRefIdx2, bool bWeightedBipredIdcIs1, int32_t iBlkWidth,340 int32_t iRefIdx1, int32_t iRefIdx2, bool bWeightedBipredIdcIs1, int32_t iBlkWidth,
341 int32_t iBlkHeight) {341 int32_t iBlkHeight) {
342 int32_t iWoc1 = 0, iOoc1 = 0, iWoc2 = 0, iOoc2 = 0;342 int32_t iWoc1 = 0, iOoc1 = 0, iWoc2 = 0, iOoc2 = 0;
343 int32_t iPredTemp, iLineStride;343 int32_t iPredTemp, iLineStride;
344 int32_t iPixel = 0;344 int32_t iPixel = 0;
345 //luma345 //luma
346 int32_t iLog2denom = pCurDqLayer->pPredWeightTable->uiLumaLog2WeightDenom;346 int32_t iLog2denom = pCurDqLayer->pPredWeightTable->uiLumaLog2WeightDenom;
347 if (bWeightedBipredIdcIs1) {347 if (bWeightedBipredIdcIs1) {
348 iWoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iLumaWeight[iRefIdx1];348 iWoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iLumaWeight[iRefIdx1];
349 iOoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iLumaOffset[iRefIdx1];349 iOoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iLumaOffset[iRefIdx1];
350 iWoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iLumaWeight[iRefIdx2];350 iWoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iLumaWeight[iRefIdx2];
351 iOoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iLumaOffset[iRefIdx2];351 iOoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iLumaOffset[iRefIdx2];
352 } else {352 } else {
353 iWoc1 = pCurDqLayer->pPredWeightTable->iImplicitWeight[iRefIdx1][iRefIdx2];353 iWoc1 = pCurDqLayer->pPredWeightTable->iImplicitWeight[iRefIdx1][iRefIdx2];
354 iWoc2 = 64 - iWoc1;354 iWoc2 = 64 - iWoc1;
355 }355 }
356 iLineStride = pMCRefMem->iDstLineLuma;356 iLineStride = pMCRefMem->iDstLineLuma;
357 357
358 for (int i = 0; i < iBlkHeight; i++) {358 for (int i = 0; i < iBlkHeight; i++) {
359 for (int j = 0; j < iBlkWidth; j++) {359 for (int j = 0; j < iBlkWidth; j++) {
360 iPixel = j + i * (iLineStride);360 iPixel = j + i * (iLineStride);
361 iPredTemp = ((pMCRefMem->pDstY[iPixel] * iWoc1 + pTempMCRefMem->pDstY[iPixel] * iWoc2 + (1 << iLog2denom)) >>361 iPredTemp = ((pMCRefMem->pDstY[iPixel] * iWoc1 + pTempMCRefMem->pDstY[iPixel] * iWoc2 + (1 << iLog2denom)) >>
362 (iLog2denom + 1)) + ((iOoc1 + iOoc2 + 1) >> 1);362 (iLog2denom + 1)) + ((iOoc1 + iOoc2 + 1) >> 1);
363 pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255);363 pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255);
364 }364 }
365 }365 }
366 366
367 //UV367 //UV
368 iBlkWidth = iBlkWidth >> 1;368 iBlkWidth = iBlkWidth >> 1;
369 iBlkHeight = iBlkHeight >> 1;369 iBlkHeight = iBlkHeight >> 1;
370 iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom;370 iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom;
371 iLineStride = pMCRefMem->iDstLineChroma;371 iLineStride = pMCRefMem->iDstLineChroma;
372 372
373 uint8_t* pDst;373 uint8_t* pDst;
374 uint8_t* pTempDst;374 uint8_t* pTempDst;
375 for (int k = 0; k < 2; k++) {375 for (int k = 0; k < 2; k++) {
376 //iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom;376 //iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom;
377 if (bWeightedBipredIdcIs1) {377 if (bWeightedBipredIdcIs1) {
378 iWoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iChromaWeight[iRefIdx1][k];378 iWoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iChromaWeight[iRefIdx1][k];
379 iOoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iChromaOffset[iRefIdx1][k];379 iOoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iChromaOffset[iRefIdx1][k];
380 iWoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iChromaWeight[iRefIdx2][k];380 iWoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iChromaWeight[iRefIdx2][k];
381 iOoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iChromaOffset[iRefIdx2][k];381 iOoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iChromaOffset[iRefIdx2][k];
382 }382 }
383 pDst = k ? pMCRefMem->pDstV : pMCRefMem->pDstU;383 pDst = k ? pMCRefMem->pDstV : pMCRefMem->pDstU;
384 pTempDst = k ? pTempMCRefMem->pDstV : pTempMCRefMem->pDstU;384 pTempDst = k ? pTempMCRefMem->pDstV : pTempMCRefMem->pDstU;
385 //iLineStride = pMCRefMem->iDstLineChroma;385 //iLineStride = pMCRefMem->iDstLineChroma;
386 386
387 for (int i = 0; i < iBlkHeight; i++) {387 for (int i = 0; i < iBlkHeight; i++) {
388 for (int j = 0; j < iBlkWidth; j++) {388 for (int j = 0; j < iBlkWidth; j++) {
389 iPixel = j + i * (iLineStride);389 iPixel = j + i * (iLineStride);
390 iPredTemp = ((pDst[iPixel] * iWoc1 + pTempDst[iPixel] * iWoc2 + (1 << iLog2denom)) >> (iLog2denom + 1)) + ((390 iPredTemp = ((pDst[iPixel] * iWoc1 + pTempDst[iPixel] * iWoc2 + (1 << iLog2denom)) >> (iLog2denom + 1)) + ((
391 iOoc1 + iOoc2 + 1) >> 1);391 iOoc1 + iOoc2 + 1) >> 1);
392 pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255);392 pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255);
393 }393 }
394 }394 }
395 }395 }
396}396}
397 397
398static void BiPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, sMCRefMember* pTempMCRefMem, int32_t iBlkWidth,398static void BiPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, sMCRefMember* pTempMCRefMem, int32_t iBlkWidth,
399 int32_t iBlkHeight) {399 int32_t iBlkHeight) {
400 int32_t iPredTemp, iLineStride;400 int32_t iPredTemp, iLineStride;
401 int32_t iPixel = 0;401 int32_t iPixel = 0;
402 //luma402 //luma
403 iLineStride = pMCRefMem->iDstLineLuma;403 iLineStride = pMCRefMem->iDstLineLuma;
404 404
405 for (int i = 0; i < iBlkHeight; i++) {405 for (int i = 0; i < iBlkHeight; i++) {
406 for (int j = 0; j < iBlkWidth; j++) {406 for (int j = 0; j < iBlkWidth; j++) {
407 iPixel = j + i * (iLineStride);407 iPixel = j + i * (iLineStride);
408 iPredTemp = (pMCRefMem->pDstY[iPixel] + pTempMCRefMem->pDstY[iPixel] + 1) >> 1;408 iPredTemp = (pMCRefMem->pDstY[iPixel] + pTempMCRefMem->pDstY[iPixel] + 1) >> 1;
409 pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255);409 pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255);
410 }410 }
411 }411 }
412 412
413 //UV413 //UV
414 iBlkWidth = iBlkWidth >> 1;414 iBlkWidth = iBlkWidth >> 1;
415 iBlkHeight = iBlkHeight >> 1;415 iBlkHeight = iBlkHeight >> 1;
416 iLineStride = pMCRefMem->iDstLineChroma;416 iLineStride = pMCRefMem->iDstLineChroma;
417 417
418 uint8_t* pDst;418 uint8_t* pDst;
419 uint8_t* pTempDst;419 uint8_t* pTempDst;
420 for (int k = 0; k < 2; k++) {420 for (int k = 0; k < 2; k++) {
421 pDst = k ? pMCRefMem->pDstV : pMCRefMem->pDstU;421 pDst = k ? pMCRefMem->pDstV : pMCRefMem->pDstU;
422 pTempDst = k ? pTempMCRefMem->pDstV : pTempMCRefMem->pDstU;422 pTempDst = k ? pTempMCRefMem->pDstV : pTempMCRefMem->pDstU;
423 //iLineStride = pMCRefMem->iDstLineChroma;423 //iLineStride = pMCRefMem->iDstLineChroma;
424 424
425 for (int i = 0; i < iBlkHeight; i++) {425 for (int i = 0; i < iBlkHeight; i++) {
426 for (int j = 0; j < iBlkWidth; j++) {426 for (int j = 0; j < iBlkWidth; j++) {
427 iPixel = j + i * (iLineStride);427 iPixel = j + i * (iLineStride);
428 iPredTemp = (pDst[iPixel] + pTempDst[iPixel] + 1) >> 1;428 iPredTemp = (pDst[iPixel] + pTempDst[iPixel] + 1) >> 1;
429 pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255);429 pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255);
430 }430 }
431 }431 }
432 }432 }
433}433}
434 434
435void GetInterPred (uint8_t* pPredY, uint8_t* pPredCb, uint8_t* pPredCr, PWelsDecoderContext pCtx) {435void GetInterPred (uint8_t* pPredY, uint8_t* pPredCb, uint8_t* pPredCr, PWelsDecoderContext pCtx) {
436 sMCRefMember pMCRefMem;436 sMCRefMember pMCRefMem;
437 PDqLayer pCurDqLayer = pCtx->pCurDqLayer;437 PDqLayer pCurDqLayer = pCtx->pCurDqLayer;
438 SMcFunc* pMCFunc = &pCtx->sMcFunc;438 SMcFunc* pMCFunc = &pCtx->sMcFunc;
439 439
440 int32_t iMBXY = pCurDqLayer->iMbXyIndex;440 int32_t iMBXY = pCurDqLayer->iMbXyIndex;
441 441
442 int16_t iMVs[2] = {0};442 int16_t iMVs[2] = {0};
443 443
444 uint32_t iMBType = pCurDqLayer->pMbType[iMBXY];444 uint32_t iMBType = pCurDqLayer->pMbType[iMBXY];
445 445
446 int32_t iMBOffsetX = pCurDqLayer->iMbX << 4;446 int32_t iMBOffsetX = pCurDqLayer->iMbX << 4;
447 int32_t iMBOffsetY = pCurDqLayer->iMbY << 4;447 int32_t iMBOffsetY = pCurDqLayer->iMbY << 4;
448 448
449 int32_t iDstLineLuma = pCtx->pDec->iLinesize[0];449 int32_t iDstLineLuma = pCtx->pDec->iLinesize[0];
450 int32_t iDstLineChroma = pCtx->pDec->iLinesize[1];450 int32_t iDstLineChroma = pCtx->pDec->iLinesize[1];
451 451
452 int32_t iBlk8X, iBlk8Y, iBlk4X, iBlk4Y, i, j, iIIdx, iJIdx;452 int32_t iBlk8X, iBlk8Y, iBlk4X, iBlk4Y, i, j, iIIdx, iJIdx;
453 453
454 pMCRefMem.iPicWidth = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbWidth << 4);454 pMCRefMem.iPicWidth = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbWidth << 4);
455 pMCRefMem.iPicHeight = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbHeight << 4);455 pMCRefMem.iPicHeight = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbHeight << 4);
456 456
457 pMCRefMem.pDstY = pPredY;457 pMCRefMem.pDstY = pPredY;
458 pMCRefMem.pDstU = pPredCb;458 pMCRefMem.pDstU = pPredCb;
459 pMCRefMem.pDstV = pPredCr;459 pMCRefMem.pDstV = pPredCr;
460 460
461 pMCRefMem.iDstLineLuma = iDstLineLuma;461 pMCRefMem.iDstLineLuma = iDstLineLuma;
462 pMCRefMem.iDstLineChroma = iDstLineChroma;462 pMCRefMem.iDstLineChroma = iDstLineChroma;
463 463
464 int32_t iRefIndex = 0;464 int32_t iRefIndex = 0;
465 465
466 switch (iMBType) {466 switch (iMBType) {
467 case MB_TYPE_SKIP:467 case MB_TYPE_SKIP:
468 case MB_TYPE_16x16:468 case MB_TYPE_16x16:
469 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0];469 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0];
470 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1];470 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1];
471 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0);471 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0);
472 BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs);472 BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs);
473 473
474 if (pCurDqLayer->bUseWeightPredictionFlag) {474 if (pCurDqLayer->bUseWeightPredictionFlag) {
475 iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0];475 iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0];
476 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 16);476 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 16);
477 }477 }
478 break;478 break;
479 case MB_TYPE_16x8:479 case MB_TYPE_16x8:
480 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0];480 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0];
481 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1];481 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1];
482 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0);482 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0);
483 BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 8, iMVs);483 BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 8, iMVs);
484 484
485 if (pCurDqLayer->bUseWeightPredictionFlag) {485 if (pCurDqLayer->bUseWeightPredictionFlag) {
486 iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0];486 iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0];
487 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 8);487 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 8);
488 }488 }
489 489
490 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][8][0];490 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][8][0];
491 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][8][1];491 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][8][1];
492 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 8, LIST_0);492 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 8, LIST_0);
493 pMCRefMem.pDstY = pPredY + (iDstLineLuma << 3);493 pMCRefMem.pDstY = pPredY + (iDstLineLuma << 3);
494 pMCRefMem.pDstU = pPredCb + (iDstLineChroma << 2);494 pMCRefMem.pDstU = pPredCb + (iDstLineChroma << 2);
495 pMCRefMem.pDstV = pPredCr + (iDstLineChroma << 2);495 pMCRefMem.pDstV = pPredCr + (iDstLineChroma << 2);
496 BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY + 8, pMCFunc, 16, 8, iMVs);496 BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY + 8, pMCFunc, 16, 8, iMVs);
497 497
498 if (pCurDqLayer->bUseWeightPredictionFlag) {498 if (pCurDqLayer->bUseWeightPredictionFlag) {
499 iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][8];499 iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][8];
500 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 8);500 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 8);
501 }501 }
502 break;502 break;
503 case MB_TYPE_8x16:503 case MB_TYPE_8x16:
504 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0];504 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0];
505 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1];505 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1];
506 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0);506 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0);
507 BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 8, 16, iMVs);507 BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 8, 16, iMVs);
508 if (pCurDqLayer->bUseWeightPredictionFlag) {508 if (pCurDqLayer->bUseWeightPredictionFlag) {
509 iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0];509 iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0];
510 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 16);510 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 16);
511 }511 }
512 512
513 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][2][0];513 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][2][0];
514 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][2][1];514 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][2][1];
515 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 2, LIST_0);515 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 2, LIST_0);
516 pMCRefMem.pDstY = pPredY + 8;516 pMCRefMem.pDstY = pPredY + 8;
517 pMCRefMem.pDstU = pPredCb + 4;517 pMCRefMem.pDstU = pPredCb + 4;
518 pMCRefMem.pDstV = pPredCr + 4;518 pMCRefMem.pDstV = pPredCr + 4;
519 BaseMC (&pMCRefMem, iMBOffsetX + 8, iMBOffsetY, pMCFunc, 8, 16, iMVs);519 BaseMC (&pMCRefMem, iMBOffsetX + 8, iMBOffsetY, pMCFunc, 8, 16, iMVs);
520 520
521 if (pCurDqLayer->bUseWeightPredictionFlag) {521 if (pCurDqLayer->bUseWeightPredictionFlag) {
522 iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][2];522 iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][2];
523 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 16);523 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 16);
524 }524 }
525 break;525 break;
526 case MB_TYPE_8x8:526 case MB_TYPE_8x8:
527 case MB_TYPE_8x8_REF0: {527 case MB_TYPE_8x8_REF0: {
528 uint32_t iSubMBType;528 uint32_t iSubMBType;
529 int32_t iXOffset, iYOffset;529 int32_t iXOffset, iYOffset;
530 uint8_t* pDstY, *pDstU, *pDstV;530 uint8_t* pDstY, *pDstU, *pDstV;
531 for (i = 0; i < 4; i++) {531 for (i = 0; i < 4; i++) {
532 iSubMBType = pCurDqLayer->pSubMbType[iMBXY][i];532 iSubMBType = pCurDqLayer->pSubMbType[iMBXY][i];
533 iBlk8X = (i & 1) << 3;533 iBlk8X = (i & 1) << 3;
534 iBlk8Y = (i >> 1) << 3;534 iBlk8Y = (i >> 1) << 3;
535 iXOffset = iMBOffsetX + iBlk8X;535 iXOffset = iMBOffsetX + iBlk8X;
536 iYOffset = iMBOffsetY + iBlk8Y;536 iYOffset = iMBOffsetY + iBlk8Y;
537 537
538 iIIdx = ((i >> 1) << 3) + ((i & 1) << 1);538 iIIdx = ((i >> 1) << 3) + ((i & 1) << 1);
539 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], iIIdx, LIST_0);539 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], iIIdx, LIST_0);
540 iRefIndex = pCurDqLayer->bUseWeightPredictionFlag ? pCurDqLayer->pRefIndex[0][iMBXY][iIIdx] : 0;540 iRefIndex = pCurDqLayer->bUseWeightPredictionFlag ? pCurDqLayer->pRefIndex[0][iMBXY][iIIdx] : 0;
541 541
542 pDstY = pPredY + iBlk8X + iBlk8Y * iDstLineLuma;542 pDstY = pPredY + iBlk8X + iBlk8Y * iDstLineLuma;
543 pDstU = pPredCb + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma;543 pDstU = pPredCb + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma;
544 pDstV = pPredCr + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma;544 pDstV = pPredCr + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma;
545 pMCRefMem.pDstY = pDstY;545 pMCRefMem.pDstY = pDstY;
546 pMCRefMem.pDstU = pDstU;546 pMCRefMem.pDstU = pDstU;
547 pMCRefMem.pDstV = pDstV;547 pMCRefMem.pDstV = pDstV;
548 switch (iSubMBType) {548 switch (iSubMBType) {
549 case SUB_MB_TYPE_8x8:549 case SUB_MB_TYPE_8x8:
550 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0];550 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0];
551 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1];551 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1];
552 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs);552 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs);
553 if (pCurDqLayer->bUseWeightPredictionFlag) {553 if (pCurDqLayer->bUseWeightPredictionFlag) {
554 554
555 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 8);555 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 8);
556 }556 }
557 557
558 break;558 break;
559 case SUB_MB_TYPE_8x4:559 case SUB_MB_TYPE_8x4:
560 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0];560 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0];
561 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1];561 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1];
562 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs);562 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs);
563 if (pCurDqLayer->bUseWeightPredictionFlag) {563 if (pCurDqLayer->bUseWeightPredictionFlag) {
564 564
565 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 4);565 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 4);
566 }566 }
567 567
568 568
569 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 4][0];569 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 4][0];
570 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 4][1];570 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 4][1];
571 pMCRefMem.pDstY += (iDstLineLuma << 2);571 pMCRefMem.pDstY += (iDstLineLuma << 2);
572 pMCRefMem.pDstU += (iDstLineChroma << 1);572 pMCRefMem.pDstU += (iDstLineChroma << 1);
573 pMCRefMem.pDstV += (iDstLineChroma << 1);573 pMCRefMem.pDstV += (iDstLineChroma << 1);
574 BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs);574 BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs);
575 if (pCurDqLayer->bUseWeightPredictionFlag) {575 if (pCurDqLayer->bUseWeightPredictionFlag) {
576 576
577 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 4);577 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 4);
578 }578 }
579 579
580 break;580 break;
581 case SUB_MB_TYPE_4x8:581 case SUB_MB_TYPE_4x8:
582 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0];582 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0];
583 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1];583 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1];
584 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs);584 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs);
585 if (pCurDqLayer->bUseWeightPredictionFlag) {585 if (pCurDqLayer->bUseWeightPredictionFlag) {
586 586
587 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 8);587 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 8);
588 }588 }
589 589
590 590
591 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 1][0];591 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 1][0];
592 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 1][1];592 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 1][1];
593 pMCRefMem.pDstY += 4;593 pMCRefMem.pDstY += 4;
594 pMCRefMem.pDstU += 2;594 pMCRefMem.pDstU += 2;
595 pMCRefMem.pDstV += 2;595 pMCRefMem.pDstV += 2;
596 BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs);596 BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs);
597 if (pCurDqLayer->bUseWeightPredictionFlag) {597 if (pCurDqLayer->bUseWeightPredictionFlag) {
598 598
599 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 8);599 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 8);
600 }600 }
601 601
602 break;602 break;
603 case SUB_MB_TYPE_4x4: {603 case SUB_MB_TYPE_4x4: {
604 for (j = 0; j < 4; j++) {604 for (j = 0; j < 4; j++) {
605 int32_t iUVLineStride;605 int32_t iUVLineStride;
606 iJIdx = ((j >> 1) << 2) + (j & 1);606 iJIdx = ((j >> 1) << 2) + (j & 1);
607 607
608 iBlk4X = (j & 1) << 2;608 iBlk4X = (j & 1) << 2;
609 iBlk4Y = (j >> 1) << 2;609 iBlk4Y = (j >> 1) << 2;
610 610
611 iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma;611 iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma;
612 pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma;612 pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma;
613 pMCRefMem.pDstU = pDstU + iUVLineStride;613 pMCRefMem.pDstU = pDstU + iUVLineStride;
614 pMCRefMem.pDstV = pDstV + iUVLineStride;614 pMCRefMem.pDstV = pDstV + iUVLineStride;
615 615
616 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + iJIdx][0];616 iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + iJIdx][0];
617 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + iJIdx][1];617 iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + iJIdx][1];
618 BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs);618 BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs);
619 if (pCurDqLayer->bUseWeightPredictionFlag) {619 if (pCurDqLayer->bUseWeightPredictionFlag) {
620 620
621 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 4);621 WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 4);
622 }622 }
623 623
624 }624 }
625 }625 }
626 break;626 break;
627 default:627 default:
628 break;628 break;
629 }629 }
630 }630 }
631 }631 }
632 break;632 break;
633 default:633 default:
634 break;634 break;
635 }635 }
636}636}
637 637
638void GetInterBPred (uint8_t* pPredYCbCr[3], uint8_t* pTempPredYCbCr[3], PWelsDecoderContext pCtx) {638void GetInterBPred (uint8_t* pPredYCbCr[3], uint8_t* pTempPredYCbCr[3], PWelsDecoderContext pCtx) {
639 sMCRefMember pMCRefMem;639 sMCRefMember pMCRefMem;
640 sMCRefMember pTempMCRefMem;640 sMCRefMember pTempMCRefMem;
641 641
642 PDqLayer pCurDqLayer = pCtx->pCurDqLayer;642 PDqLayer pCurDqLayer = pCtx->pCurDqLayer;
643 SMcFunc* pMCFunc = &pCtx->sMcFunc;643 SMcFunc* pMCFunc = &pCtx->sMcFunc;
644 644
645 int32_t iMBXY = pCurDqLayer->iMbXyIndex;645 int32_t iMBXY = pCurDqLayer->iMbXyIndex;
646 646
647 int16_t iMVs[2] = { 0 };647 int16_t iMVs[2] = { 0 };
648 648
649 uint32_t iMBType = pCurDqLayer->pMbType[iMBXY];649 uint32_t iMBType = pCurDqLayer->pMbType[iMBXY];
650 650
651 int32_t iMBOffsetX = pCurDqLayer->iMbX << 4;651 int32_t iMBOffsetX = pCurDqLayer->iMbX << 4;
652 int32_t iMBOffsetY = pCurDqLayer->iMbY << 4;652 int32_t iMBOffsetY = pCurDqLayer->iMbY << 4;
653 653
654 int32_t iDstLineLuma = pCtx->pDec->iLinesize[0];654 int32_t iDstLineLuma = pCtx->pDec->iLinesize[0];
655 int32_t iDstLineChroma = pCtx->pDec->iLinesize[1];655 int32_t iDstLineChroma = pCtx->pDec->iLinesize[1];
656 656
657 657
658 pMCRefMem.iPicWidth = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbWidth << 4);658 pMCRefMem.iPicWidth = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbWidth << 4);
659 pMCRefMem.iPicHeight = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbHeight << 4);659 pMCRefMem.iPicHeight = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbHeight << 4);
660 660
661 pMCRefMem.pDstY = pPredYCbCr[0];661 pMCRefMem.pDstY = pPredYCbCr[0];
662 pMCRefMem.pDstU = pPredYCbCr[1];662 pMCRefMem.pDstU = pPredYCbCr[1];
663 pMCRefMem.pDstV = pPredYCbCr[2];663 pMCRefMem.pDstV = pPredYCbCr[2];
664 664
665 pMCRefMem.iDstLineLuma = iDstLineLuma;665 pMCRefMem.iDstLineLuma = iDstLineLuma;
666 pMCRefMem.iDstLineChroma = iDstLineChroma;666 pMCRefMem.iDstLineChroma = iDstLineChroma;
667 667
668 pTempMCRefMem = pMCRefMem;668 pTempMCRefMem = pMCRefMem;
669 pTempMCRefMem.pDstY = pTempPredYCbCr[0];669 pTempMCRefMem.pDstY = pTempPredYCbCr[0];
670 pTempMCRefMem.pDstU = pTempPredYCbCr[1];670 pTempMCRefMem.pDstU = pTempPredYCbCr[1];
671 pTempMCRefMem.pDstV = pTempPredYCbCr[2];671 pTempMCRefMem.pDstV = pTempPredYCbCr[2];
672 672
673 673
674 int32_t iRefIndex1 = 0;674 int32_t iRefIndex1 = 0;
675 int32_t iRefIndex2 = 0;675 int32_t iRefIndex2 = 0;
676 676
677 bool bWeightedBipredIdcIs1 = pCurDqLayer->sLayerInfo.pPps->uiWeightedBipredIdc == 1;677 bool bWeightedBipredIdcIs1 = pCurDqLayer->sLayerInfo.pPps->uiWeightedBipredIdc == 1;
678 678
679 if (IS_INTER_16x16 (iMBType)) {679 if (IS_INTER_16x16 (iMBType)) {
680 if (IS_TYPE_L0 (iMBType) && IS_TYPE_L1 (iMBType)) {680 if (IS_TYPE_L0 (iMBType) && IS_TYPE_L1 (iMBType)) {
681 iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][0][0];681 iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][0][0];
682 iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][0][1];682 iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][0][1];
683 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_0][iMBXY], 0, LIST_0);683 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_0][iMBXY], 0, LIST_0);
684 BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs);684 BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs);
685 685
686 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][0][0];686 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][0][0];
687 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][0][1];687 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][0][1];
688 GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], 0, LIST_1);688 GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], 0, LIST_1);
689 BaseMC (&pTempMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs);689 BaseMC (&pTempMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs);
690 iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][0];690 iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][0];
691 iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][0];691 iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][0];
692 if (pCurDqLayer->bUseWeightedBiPredIdc) {692 if (pCurDqLayer->bUseWeightedBiPredIdc) {
693 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 16, 16);693 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 16, 16);
694 } else {694 } else {
695 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 16, 16);695 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 16, 16);
696 }696 }
697 } else {697 } else {
698 int32_t listIdx = (iMBType & MB_TYPE_P0L0) ? LIST_0 : LIST_1;698 int32_t listIdx = (iMBType & MB_TYPE_P0L0) ? LIST_0 : LIST_1;
699 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][0][0];699 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][0][0];
700 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][0][1];700 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][0][1];
701 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], 0, listIdx);701 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], 0, listIdx);
702 BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs);702 BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs);
703 if (bWeightedBipredIdcIs1) {703 if (bWeightedBipredIdcIs1) {
704 int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][0];704 int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][0];
705 WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 16, 16);705 WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 16, 16);
706 }706 }
707 }707 }
708 } else if (IS_INTER_16x8 (iMBType)) {708 } else if (IS_INTER_16x8 (iMBType)) {
709 for (int32_t i = 0; i < 2; ++i) {709 for (int32_t i = 0; i < 2; ++i) {
710 int32_t iPartIdx = i << 3;710 int32_t iPartIdx = i << 3;
711 uint32_t listCount = 0;711 uint32_t listCount = 0;
712 int32_t lastListIdx = LIST_0;712 int32_t lastListIdx = LIST_0;
713 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {713 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
714 if (IS_DIR (iMBType, i, listIdx)) {714 if (IS_DIR (iMBType, i, listIdx)) {
715 lastListIdx = listIdx;715 lastListIdx = listIdx;
716 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iPartIdx][0];716 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iPartIdx][0];
717 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iPartIdx][1];717 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iPartIdx][1];
718 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], iPartIdx, listIdx);718 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], iPartIdx, listIdx);
719 if (i) {719 if (i) {
720 pMCRefMem.pDstY += (iDstLineLuma << 3);720 pMCRefMem.pDstY += (iDstLineLuma << 3);
721 pMCRefMem.pDstU += (iDstLineChroma << 2);721 pMCRefMem.pDstU += (iDstLineChroma << 2);
722 pMCRefMem.pDstV += (iDstLineChroma << 2);722 pMCRefMem.pDstV += (iDstLineChroma << 2);
723 }723 }
724 BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY + iPartIdx, pMCFunc, 16, 8, iMVs);724 BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY + iPartIdx, pMCFunc, 16, 8, iMVs);
725 if (++listCount == 2) {725 if (++listCount == 2) {
726 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iPartIdx][0];726 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iPartIdx][0];
727 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iPartIdx][1];727 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iPartIdx][1];
728 GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], iPartIdx, LIST_1);728 GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], iPartIdx, LIST_1);
729 if (i) {729 if (i) {
730 pTempMCRefMem.pDstY += (iDstLineLuma << 3);730 pTempMCRefMem.pDstY += (iDstLineLuma << 3);
731 pTempMCRefMem.pDstU += (iDstLineChroma << 2);731 pTempMCRefMem.pDstU += (iDstLineChroma << 2);
732 pTempMCRefMem.pDstV += (iDstLineChroma << 2);732 pTempMCRefMem.pDstV += (iDstLineChroma << 2);
733 }733 }
734 BaseMC (&pTempMCRefMem, iMBOffsetX, iMBOffsetY + iPartIdx, pMCFunc, 16, 8, iMVs);734 BaseMC (&pTempMCRefMem, iMBOffsetX, iMBOffsetY + iPartIdx, pMCFunc, 16, 8, iMVs);
735 if (pCurDqLayer->bUseWeightedBiPredIdc) {735 if (pCurDqLayer->bUseWeightedBiPredIdc) {
736 iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][iPartIdx];736 iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][iPartIdx];
737 iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][iPartIdx];737 iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][iPartIdx];
738 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 16, 8);738 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 16, 8);
739 } else {739 } else {
740 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 16, 8);740 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 16, 8);
741 }741 }
742 }742 }
743 }743 }
744 }744 }
745 if (listCount == 1) {745 if (listCount == 1) {
746 if (bWeightedBipredIdcIs1) {746 if (bWeightedBipredIdcIs1) {
747 int32_t iRefIndex = pCurDqLayer->pRefIndex[lastListIdx][iMBXY][iPartIdx];747 int32_t iRefIndex = pCurDqLayer->pRefIndex[lastListIdx][iMBXY][iPartIdx];
748 WeightPrediction (pCurDqLayer, &pMCRefMem, lastListIdx, iRefIndex, 16, 8);748 WeightPrediction (pCurDqLayer, &pMCRefMem, lastListIdx, iRefIndex, 16, 8);
749 }749 }
750 }750 }
751 }751 }
752 } else if (IS_INTER_8x16 (iMBType)) {752 } else if (IS_INTER_8x16 (iMBType)) {
753 for (int32_t i = 0; i < 2; ++i) {753 for (int32_t i = 0; i < 2; ++i) {
754 uint32_t listCount = 0;754 uint32_t listCount = 0;
755 int32_t lastListIdx = LIST_0;755 int32_t lastListIdx = LIST_0;
756 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {756 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
757 if (IS_DIR (iMBType, i, listIdx)) {757 if (IS_DIR (iMBType, i, listIdx)) {
758 lastListIdx = listIdx;758 lastListIdx = listIdx;
759 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][i << 1][0];759 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][i << 1][0];
760 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][i << 1][1];760 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][i << 1][1];
761 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], i << 1, listIdx);761 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], i << 1, listIdx);
762 if (i) {762 if (i) {
763 pMCRefMem.pDstY += 8;763 pMCRefMem.pDstY += 8;
764 pMCRefMem.pDstU += 4;764 pMCRefMem.pDstU += 4;
765 pMCRefMem.pDstV += 4;765 pMCRefMem.pDstV += 4;
766 }766 }
767 BaseMC (&pMCRefMem, iMBOffsetX + (i ? 8 : 0), iMBOffsetY, pMCFunc, 8, 16, iMVs);767 BaseMC (&pMCRefMem, iMBOffsetX + (i ? 8 : 0), iMBOffsetY, pMCFunc, 8, 16, iMVs);
768 if (++listCount == 2) {768 if (++listCount == 2) {
769 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][i << 1][0];769 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][i << 1][0];
770 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][i << 1][1];770 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][i << 1][1];
771 GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], i << 1, LIST_1);771 GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], i << 1, LIST_1);
772 if (i) {772 if (i) {
773 pTempMCRefMem.pDstY += 8;773 pTempMCRefMem.pDstY += 8;
774 pTempMCRefMem.pDstU += 4;774 pTempMCRefMem.pDstU += 4;
775 pTempMCRefMem.pDstV += 4;775 pTempMCRefMem.pDstV += 4;
776 }776 }
777 BaseMC (&pTempMCRefMem, iMBOffsetX + (i ? 8 : 0), iMBOffsetY, pMCFunc, 8, 16, iMVs);777 BaseMC (&pTempMCRefMem, iMBOffsetX + (i ? 8 : 0), iMBOffsetY, pMCFunc, 8, 16, iMVs);
778 if (pCurDqLayer->bUseWeightedBiPredIdc) {778 if (pCurDqLayer->bUseWeightedBiPredIdc) {
779 iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][i << 1];779 iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][i << 1];
780 iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][i << 1];780 iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][i << 1];
781 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 16);781 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 16);
782 } else {782 } else {
783 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 16);783 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 16);
784 }784 }
785 }785 }
786 }786 }
787 }787 }
788 if (listCount == 1) {788 if (listCount == 1) {
789 if (bWeightedBipredIdcIs1) {789 if (bWeightedBipredIdcIs1) {
790 int32_t iRefIndex = pCurDqLayer->pRefIndex[lastListIdx][iMBXY][i << 1];790 int32_t iRefIndex = pCurDqLayer->pRefIndex[lastListIdx][iMBXY][i << 1];
791 WeightPrediction (pCurDqLayer, &pMCRefMem, lastListIdx, iRefIndex, 8, 16);791 WeightPrediction (pCurDqLayer, &pMCRefMem, lastListIdx, iRefIndex, 8, 16);
792 }792 }
793 }793 }
794 }794 }
795 } else if (IS_Inter_8x8 (iMBType)) {795 } else if (IS_Inter_8x8 (iMBType)) {
796 int32_t iBlk8X, iBlk8Y, iBlk4X, iBlk4Y, iIIdx, iJIdx;796 int32_t iBlk8X, iBlk8Y, iBlk4X, iBlk4Y, iIIdx, iJIdx;
797 uint32_t iSubMBType;797 uint32_t iSubMBType;
798 int32_t iXOffset, iYOffset;798 int32_t iXOffset, iYOffset;
799 uint8_t* pDstY, *pDstU, *pDstV;799 uint8_t* pDstY, *pDstU, *pDstV;
800 uint8_t* pDstY2, *pDstU2, *pDstV2;800 uint8_t* pDstY2, *pDstU2, *pDstV2;
801 for (int32_t i = 0; i < 4; i++) {801 for (int32_t i = 0; i < 4; i++) {
802 iSubMBType = pCurDqLayer->pSubMbType[iMBXY][i];802 iSubMBType = pCurDqLayer->pSubMbType[iMBXY][i];
803 iBlk8X = (i & 1) << 3;803 iBlk8X = (i & 1) << 3;
804 iBlk8Y = (i >> 1) << 3;804 iBlk8Y = (i >> 1) << 3;
805 iXOffset = iMBOffsetX + iBlk8X;805 iXOffset = iMBOffsetX + iBlk8X;
806 iYOffset = iMBOffsetY + iBlk8Y;806 iYOffset = iMBOffsetY + iBlk8Y;
807 807
808 iIIdx = ((i >> 1) << 3) + ((i & 1) << 1);808 iIIdx = ((i >> 1) << 3) + ((i & 1) << 1);
809 809
810 pDstY = pPredYCbCr[0] + iBlk8X + iBlk8Y * iDstLineLuma;810 pDstY = pPredYCbCr[0] + iBlk8X + iBlk8Y * iDstLineLuma;
811 pDstU = pPredYCbCr[1] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma;811 pDstU = pPredYCbCr[1] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma;
812 pDstV = pPredYCbCr[2] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma;812 pDstV = pPredYCbCr[2] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma;
813 pMCRefMem.pDstY = pDstY;813 pMCRefMem.pDstY = pDstY;
814 pMCRefMem.pDstU = pDstU;814 pMCRefMem.pDstU = pDstU;
815 pMCRefMem.pDstV = pDstV;815 pMCRefMem.pDstV = pDstV;
816 816
817 pTempMCRefMem = pMCRefMem;817 pTempMCRefMem = pMCRefMem;
818 pDstY2 = pTempPredYCbCr[0] + iBlk8X + iBlk8Y * iDstLineLuma;818 pDstY2 = pTempPredYCbCr[0] + iBlk8X + iBlk8Y * iDstLineLuma;
819 pDstU2 = pTempPredYCbCr[1] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma;819 pDstU2 = pTempPredYCbCr[1] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma;
820 pDstV2 = pTempPredYCbCr[2] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma;820 pDstV2 = pTempPredYCbCr[2] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma;
821 821
822 pTempMCRefMem.pDstY = pDstY2;822 pTempMCRefMem.pDstY = pDstY2;
823 pTempMCRefMem.pDstU = pDstU2;823 pTempMCRefMem.pDstU = pDstU2;
824 pTempMCRefMem.pDstV = pDstV2;824 pTempMCRefMem.pDstV = pDstV2;
825 825
826 if ((IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType))) {826 if ((IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType))) {
827 iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][iIIdx];827 iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][iIIdx];
828 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_0][iMBXY], iIIdx, LIST_0);828 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_0][iMBXY], iIIdx, LIST_0);
829 829
830 iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][iIIdx];830 iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][iIIdx];
831 GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], iIIdx, LIST_1);831 GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], iIIdx, LIST_1);
832 } else {832 } else {
833 int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1;833 int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1;
834 iRefIndex1 = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx];834 iRefIndex1 = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx];
835 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], iIIdx, listIdx);835 GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], iIIdx, listIdx);
836 }836 }
837 837
838 if (IS_SUB_8x8 (iSubMBType)) {838 if (IS_SUB_8x8 (iSubMBType)) {
839 if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) {839 if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) {
840 iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0];840 iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0];
841 iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1];841 iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1];
842 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs);842 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs);
843 843
844 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0];844 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0];
845 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1];845 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1];
846 BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs);846 BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs);
847 847
848 if (pCurDqLayer->bUseWeightedBiPredIdc) {848 if (pCurDqLayer->bUseWeightedBiPredIdc) {
849 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 8);849 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 8);
850 } else {850 } else {
851 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 8);851 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 8);
852 }852 }
853 } else {853 } else {
854 int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1;854 int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1;
855 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0];855 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0];
856 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1];856 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1];
857 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs);857 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs);
858 if (bWeightedBipredIdcIs1) {858 if (bWeightedBipredIdcIs1) {
859 int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx];859 int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx];
860 WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 8, 8);860 WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 8, 8);
861 }861 }
862 }862 }
863 } else if (IS_SUB_8x4 (iSubMBType)) {863 } else if (IS_SUB_8x4 (iSubMBType)) {
864 if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { //B_Bi_8x4864 if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { //B_Bi_8x4
865 iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0];865 iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0];
866 iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1];866 iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1];
867 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs);867 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs);
868 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0];868 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0];
869 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1];869 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1];
870 BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs);870 BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs);
871 871
872 if (pCurDqLayer->bUseWeightedBiPredIdc) {872 if (pCurDqLayer->bUseWeightedBiPredIdc) {
873 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 4);873 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 4);
874 } else {874 } else {
875 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 4);875 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 4);
876 }876 }
877 877
878 pMCRefMem.pDstY += (iDstLineLuma << 2);878 pMCRefMem.pDstY += (iDstLineLuma << 2);
879 pMCRefMem.pDstU += (iDstLineChroma << 1);879 pMCRefMem.pDstU += (iDstLineChroma << 1);
880 pMCRefMem.pDstV += (iDstLineChroma << 1);880 pMCRefMem.pDstV += (iDstLineChroma << 1);
881 iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 4][0];881 iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 4][0];
882 iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 4][1];882 iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 4][1];
883 BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs);883 BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs);
884 884
885 pTempMCRefMem.pDstY += (iDstLineLuma << 2);885 pTempMCRefMem.pDstY += (iDstLineLuma << 2);
886 pTempMCRefMem.pDstU += (iDstLineChroma << 1);886 pTempMCRefMem.pDstU += (iDstLineChroma << 1);
887 pTempMCRefMem.pDstV += (iDstLineChroma << 1);887 pTempMCRefMem.pDstV += (iDstLineChroma << 1);
888 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 4][0];888 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 4][0];
889 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 4][1];889 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 4][1];
890 BaseMC (&pTempMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs);890 BaseMC (&pTempMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs);
891 891
892 if (pCurDqLayer->bUseWeightedBiPredIdc) {892 if (pCurDqLayer->bUseWeightedBiPredIdc) {
893 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 4);893 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 4);
894 } else {894 } else {
895 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 4);895 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 4);
896 }896 }
897 } else { //B_L0_8x4 B_L1_8x4897 } else { //B_L0_8x4 B_L1_8x4
898 int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1;898 int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1;
899 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0];899 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0];
900 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1];900 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1];
901 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs);901 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs);
902 pMCRefMem.pDstY += (iDstLineLuma << 2);902 pMCRefMem.pDstY += (iDstLineLuma << 2);
903 pMCRefMem.pDstU += (iDstLineChroma << 1);903 pMCRefMem.pDstU += (iDstLineChroma << 1);
904 pMCRefMem.pDstV += (iDstLineChroma << 1);904 pMCRefMem.pDstV += (iDstLineChroma << 1);
905 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 4][0];905 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 4][0];
906 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 4][1];906 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 4][1];
907 BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs);907 BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs);
908 if (bWeightedBipredIdcIs1) {908 if (bWeightedBipredIdcIs1) {
909 int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx];909 int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx];
910 WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 8, 4);910 WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 8, 4);
911 }911 }
912 }912 }
913 } else if (IS_SUB_4x8 (iSubMBType)) {913 } else if (IS_SUB_4x8 (iSubMBType)) {
914 if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { //B_Bi_4x8914 if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { //B_Bi_4x8
915 iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0];915 iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0];
916 iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1];916 iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1];
917 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs);917 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs);
918 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0];918 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0];
919 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1];919 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1];
920 BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs);920 BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs);
921 921
922 if (pCurDqLayer->bUseWeightedBiPredIdc) {922 if (pCurDqLayer->bUseWeightedBiPredIdc) {
923 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 8);923 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 8);
924 } else {924 } else {
925 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 8);925 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 8);
926 }926 }
927 927
928 pMCRefMem.pDstY += 4;928 pMCRefMem.pDstY += 4;
929 pMCRefMem.pDstU += 2;929 pMCRefMem.pDstU += 2;
930 pMCRefMem.pDstV += 2;930 pMCRefMem.pDstV += 2;
931 iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 1][0];931 iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 1][0];
932 iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 1][1];932 iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 1][1];
933 BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs);933 BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs);
934 934
935 pTempMCRefMem.pDstY += 4;935 pTempMCRefMem.pDstY += 4;
936 pTempMCRefMem.pDstU += 2;936 pTempMCRefMem.pDstU += 2;
937 pTempMCRefMem.pDstV += 2;937 pTempMCRefMem.pDstV += 2;
938 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 1][0];938 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 1][0];
939 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 1][1];939 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 1][1];
940 BaseMC (&pTempMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs);940 BaseMC (&pTempMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs);
941 941
942 if (pCurDqLayer->bUseWeightedBiPredIdc) {942 if (pCurDqLayer->bUseWeightedBiPredIdc) {
943 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 8);943 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 8);
944 } else {944 } else {
945 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 8);945 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 8);
946 }946 }
947 } else { //B_L0_4x8 B_L1_4x8947 } else { //B_L0_4x8 B_L1_4x8
948 int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1;948 int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1;
949 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0];949 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0];
950 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1];950 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1];
951 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs);951 BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs);
952 pMCRefMem.pDstY += 4;952 pMCRefMem.pDstY += 4;
953 pMCRefMem.pDstU += 2;953 pMCRefMem.pDstU += 2;
954 pMCRefMem.pDstV += 2;954 pMCRefMem.pDstV += 2;
955 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 1][0];955 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 1][0];
956 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 1][1];956 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 1][1];
957 BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs);957 BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs);
958 if (bWeightedBipredIdcIs1) {958 if (bWeightedBipredIdcIs1) {
959 int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx];959 int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx];
960 WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 4, 8);960 WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 4, 8);
961 }961 }
962 }962 }
963 } else if (IS_SUB_4x4 (iSubMBType)) {963 } else if (IS_SUB_4x4 (iSubMBType)) {
964 if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) {964 if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) {
965 for (int32_t j = 0; j < 4; j++) {965 for (int32_t j = 0; j < 4; j++) {
966 int32_t iUVLineStride;966 int32_t iUVLineStride;
967 iJIdx = ((j >> 1) << 2) + (j & 1);967 iJIdx = ((j >> 1) << 2) + (j & 1);
968 968
969 iBlk4X = (j & 1) << 2;969 iBlk4X = (j & 1) << 2;
970 iBlk4Y = (j >> 1) << 2;970 iBlk4Y = (j >> 1) << 2;
971 971
972 iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma;972 iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma;
973 pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma;973 pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma;
974 pMCRefMem.pDstU = pDstU + iUVLineStride;974 pMCRefMem.pDstU = pDstU + iUVLineStride;
975 pMCRefMem.pDstV = pDstV + iUVLineStride;975 pMCRefMem.pDstV = pDstV + iUVLineStride;
976 976
977 iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + iJIdx][0];977 iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + iJIdx][0];
978 iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + iJIdx][1];978 iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + iJIdx][1];
979 BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs);979 BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs);
980 980
981 pTempMCRefMem.pDstY = pDstY2 + iBlk8X + iBlk8Y * iDstLineLuma;981 pTempMCRefMem.pDstY = pDstY2 + iBlk8X + iBlk8Y * iDstLineLuma;
982 pTempMCRefMem.pDstU = pDstU2 + iUVLineStride;982 pTempMCRefMem.pDstU = pDstU2 + iUVLineStride;
983 pTempMCRefMem.pDstV = pDstV2 + iUVLineStride;;983 pTempMCRefMem.pDstV = pDstV2 + iUVLineStride;;
984 984
985 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + iJIdx][0];985 iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + iJIdx][0];
986 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + iJIdx][1];986 iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + iJIdx][1];
987 BaseMC (&pTempMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs);987 BaseMC (&pTempMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs);
988 988
989 if (pCurDqLayer->bUseWeightedBiPredIdc) {989 if (pCurDqLayer->bUseWeightedBiPredIdc) {
990 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 4);990 BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 4);
991 } else {991 } else {
992 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 4);992 BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 4);
993 }993 }
994 }994 }
995 } else {995 } else {
996 int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1;996 int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1;
997 int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx];997 int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx];
998 for (int32_t j = 0; j < 4; j++) {998 for (int32_t j = 0; j < 4; j++) {
999 int32_t iUVLineStride;999 int32_t iUVLineStride;
1000 iJIdx = ((j >> 1) << 2) + (j & 1);1000 iJIdx = ((j >> 1) << 2) + (j & 1);
1001 1001
1002 iBlk4X = (j & 1) << 2;1002 iBlk4X = (j & 1) << 2;
1003 iBlk4Y = (j >> 1) << 2;1003 iBlk4Y = (j >> 1) << 2;
1004 1004
1005 iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma;1005 iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma;
1006 pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma;1006 pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma;
1007 pMCRefMem.pDstU = pDstU + iUVLineStride;1007 pMCRefMem.pDstU = pDstU + iUVLineStride;
1008 pMCRefMem.pDstV = pDstV + iUVLineStride;1008 pMCRefMem.pDstV = pDstV + iUVLineStride;
1009 1009
1010 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + iJIdx][0];1010 iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + iJIdx][0];
1011 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + iJIdx][1];1011 iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + iJIdx][1];
1012 BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs);1012 BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs);
1013 if (bWeightedBipredIdcIs1) {1013 if (bWeightedBipredIdcIs1) {
1014 WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 4, 4);1014 WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 4, 4);
1015 }1015 }
1016 }1016 }
1017 }1017 }
1018 }1018 }
1019 }1019 }
1020 }1020 }
1021}1021}
1022 1022
1023int32_t RecChroma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) {1023int32_t RecChroma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) {
1024 int32_t iChromaStride = pCtx->pCurDqLayer->pDec->iLinesize[1];1024 int32_t iChromaStride = pCtx->pCurDqLayer->pDec->iLinesize[1];
1025 PIdctFourResAddPredFunc pIdctFourResAddPredFunc = pCtx->pIdctFourResAddPredFunc;1025 PIdctFourResAddPredFunc pIdctFourResAddPredFunc = pCtx->pIdctFourResAddPredFunc;
1026 1026
1027 uint8_t i = 0;1027 uint8_t i = 0;
1028 uint8_t uiCbpC = pDqLayer->pCbp[iMBXY] >> 4;1028 uint8_t uiCbpC = pDqLayer->pCbp[iMBXY] >> 4;
1029 1029
1030 if (1 == uiCbpC || 2 == uiCbpC) {1030 if (1 == uiCbpC || 2 == uiCbpC) {
1031 for (i = 0; i < 2; i++) {1031 for (i = 0; i < 2; i++) {
1032 int16_t* pRS = pScoeffLevel + 256 + (i << 6);1032 int16_t* pRS = pScoeffLevel + 256 + (i << 6);
1033 uint8_t* pPred = pDqLayer->pPred[i + 1];1033 uint8_t* pPred = pDqLayer->pPred[i + 1];
1034 const int8_t* pNzc = pDqLayer->pNzc[iMBXY] + 16 + 2 * i;1034 const int8_t* pNzc = pDqLayer->pNzc[iMBXY] + 16 + 2 * i;
1035 1035
1036 /*1 chroma is divided 4 4x4_block to idct*/1036 /*1 chroma is divided 4 4x4_block to idct*/
1037 pIdctFourResAddPredFunc (pPred, iChromaStride, pRS, pNzc);1037 pIdctFourResAddPredFunc (pPred, iChromaStride, pRS, pNzc);
1038 }1038 }
1039 }1039 }
1040 1040
1041 return ERR_NONE;1041 return ERR_NONE;
1042}1042}
1043 1043
1044} // namespace WelsDec1044} // namespace WelsDec
codec/decoder/plus/inc/welsDecoderExt.h+147−147
@@ -1,147 +1,147 @@
1/*!1/*!
2 * \copy2 * \copy
3 * Copyright (c) 2009-2013, Cisco Systems3 * Copyright (c) 2009-2013, Cisco Systems
4 * All rights reserved.4 * All rights reserved.
5 *5 *
6 * Redistribution and use in source and binary forms, with or without6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions7 * modification, are permitted provided that the following conditions
8 * are met:8 * are met:
9 *9 *
10 * * Redistributions of source code must retain the above copyright10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.11 * notice, this list of conditions and the following disclaimer.
12 *12 *
13 * * Redistributions in binary form must reproduce the above copyright13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the15 * the documentation and/or other materials provided with the
16 * distribution.16 * distribution.
17 *17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.29 * POSSIBILITY OF SUCH DAMAGE.
30 *30 *
31 *31 *
32 * WelsDecoderExt.h32 * WelsDecoderExt.h
33 *33 *
34 * Abstract34 * Abstract
35 * Cisco OpenH264 decoder extension utilization interface35 * Cisco OpenH264 decoder extension utilization interface
36 *36 *
37 * History37 * History
38 * 3/12/2009 Created38 * 3/12/2009 Created
39 *39 *
40 *40 *
41 *************************************************************************/41 *************************************************************************/
42#if !defined(WELS_PLUS_WELSDECODEREXT_H)42#if !defined(WELS_PLUS_WELSDECODEREXT_H)
43#define WELS_PLUS_WELSDECODEREXT_H43#define WELS_PLUS_WELSDECODEREXT_H
44 44
45#include "codec_api.h"45#include "codec_api.h"
46#include "codec_app_def.h"46#include "codec_app_def.h"
47#include "decoder_context.h"47#include "decoder_context.h"
48#include "welsCodecTrace.h"48#include "welsCodecTrace.h"
49#include "cpu.h"49#include "cpu.h"
50 50
51class ISVCDecoder;51class ISVCDecoder;
52 52
53namespace WelsDec {53namespace WelsDec {
54 54
55//#define OUTPUT_BIT_STREAM ////for test to output bitstream55//#define OUTPUT_BIT_STREAM ////for test to output bitstream
56 56
57class CWelsDecoder : public ISVCDecoder {57class CWelsDecoder : public ISVCDecoder {
58 public:58 public:
59 CWelsDecoder (void);59 CWelsDecoder (void);
60 virtual ~CWelsDecoder();60 virtual ~CWelsDecoder();
61 61
62 virtual long EXTAPI Initialize (const SDecodingParam* pParam);62 virtual long EXTAPI Initialize (const SDecodingParam* pParam);
63 virtual long EXTAPI Uninitialize();63 virtual long EXTAPI Uninitialize();
64 64
65 /***************************************************************************65 /***************************************************************************
66 * Description:66 * Description:
67 * Decompress one frame, and output I420 or RGB24(in the future) decoded stream and its length.67 * Decompress one frame, and output I420 or RGB24(in the future) decoded stream and its length.
68 * Input parameters:68 * Input parameters:
69 * Parameter TYPE Description69 * Parameter TYPE Description
70 * pSrc unsigned char* the h264 stream to decode70 * pSrc unsigned char* the h264 stream to decode
71 * srcLength int the length of h264 steam71 * srcLength int the length of h264 steam
72 * pDst unsigned char* buffer pointer of decoded data72 * pDst unsigned char* buffer pointer of decoded data
73 * pDstInfo SBufferInfo& information provided to API including width, height, SW/HW option, etc73 * pDstInfo SBufferInfo& information provided to API including width, height, SW/HW option, etc
74 *74 *
75 * return: if decode frame success return 0, otherwise corresponding error returned.75 * return: if decode frame success return 0, otherwise corresponding error returned.
76 ***************************************************************************/76 ***************************************************************************/
77 virtual DECODING_STATE EXTAPI DecodeFrame (const unsigned char* kpSrc,77 virtual DECODING_STATE EXTAPI DecodeFrame (const unsigned char* kpSrc,
78 const int kiSrcLen,78 const int kiSrcLen,
79 unsigned char** ppDst,79 unsigned char** ppDst,
80 int* pStride,80 int* pStride,
81 int& iWidth,81 int& iWidth,
82 int& iHeight);82 int& iHeight);
83 83
84 virtual DECODING_STATE EXTAPI DecodeFrameNoDelay (const unsigned char* kpSrc,84 virtual DECODING_STATE EXTAPI DecodeFrameNoDelay (const unsigned char* kpSrc,
85 const int kiSrcLen,85 const int kiSrcLen,
86 unsigned char** ppDst,86 unsigned char** ppDst,
87 SBufferInfo* pDstInfo);87 SBufferInfo* pDstInfo);
88 88
89 virtual DECODING_STATE EXTAPI DecodeFrame2 (const unsigned char* kpSrc,89 virtual DECODING_STATE EXTAPI DecodeFrame2 (const unsigned char* kpSrc,
90 const int kiSrcLen,90 const int kiSrcLen,
91 unsigned char** ppDst,91 unsigned char** ppDst,
92 SBufferInfo* pDstInfo);92 SBufferInfo* pDstInfo);
93 93
94 virtual DECODING_STATE EXTAPI FlushFrame (unsigned char** ppDst,94 virtual DECODING_STATE EXTAPI FlushFrame (unsigned char** ppDst,
95 SBufferInfo* pDstInfo);95 SBufferInfo* pDstInfo);
96 96
97 virtual DECODING_STATE EXTAPI DecodeParser (const unsigned char* kpSrc,97 virtual DECODING_STATE EXTAPI DecodeParser (const unsigned char* kpSrc,
98 const int kiSrcLen,98 const int kiSrcLen,
99 SParserBsInfo* pDstInfo);99 SParserBsInfo* pDstInfo);
100 virtual DECODING_STATE EXTAPI DecodeFrameEx (const unsigned char* kpSrc,100 virtual DECODING_STATE EXTAPI DecodeFrameEx (const unsigned char* kpSrc,
101 const int kiSrcLen,101 const int kiSrcLen,
102 unsigned char* pDst,102 unsigned char* pDst,
103 int iDstStride,103 int iDstStride,
104 int& iDstLen,104 int& iDstLen,
105 int& iWidth,105 int& iWidth,
106 int& iHeight,106 int& iHeight,
107 int& color_format);107 int& color_format);
108 108
109 virtual long EXTAPI SetOption (DECODER_OPTION eOptID, void* pOption);109 virtual long EXTAPI SetOption (DECODER_OPTION eOptID, void* pOption);
110 virtual long EXTAPI GetOption (DECODER_OPTION eOptID, void* pOption);110 virtual long EXTAPI GetOption (DECODER_OPTION eOptID, void* pOption);
111 111
112 typedef struct tagPictInfo {112 typedef struct tagPictInfo {
113 SBufferInfo sBufferInfo;113 SBufferInfo sBufferInfo;
114 int32_t iPOC;114 int32_t iPOC;
115 int32_t iFrameNum;115 int32_t iFrameNum;
116 bool bLastGOP;116 bool bLastGOP;
117 unsigned char* pData[3];117 unsigned char* pData[3];
118 } SPictInfo, *PPictInfo;118 } SPictInfo, *PPictInfo;
119 119
120 private:120 private:
121 PWelsDecoderContext m_pDecContext;121 PWelsDecoderContext m_pDecContext;
122 welsCodecTrace* m_pWelsTrace;122 welsCodecTrace* m_pWelsTrace;
123 SPictInfo m_sPictInfoList[16];123 SPictInfo m_sPictInfoList[16];
124 int32_t m_iPictInfoIndex;124 int32_t m_iPictInfoIndex;
125 int32_t m_iMinPOC;125 int32_t m_iMinPOC;
126 int32_t m_iNumOfPicts;126 int32_t m_iNumOfPicts;
127 int32_t m_iLastGOPRemainPicts;127 int32_t m_iLastGOPRemainPicts;
128 int32_t m_LastWrittenPOC;128 int32_t m_LastWrittenPOC;
129 int32_t m_iLargestBufferedPicIndex;129 int32_t m_iLargestBufferedPicIndex;
130 130
131 int32_t InitDecoder (const SDecodingParam* pParam);131 int32_t InitDecoder (const SDecodingParam* pParam);
132 void UninitDecoder (void);132 void UninitDecoder (void);
133 int32_t ResetDecoder();133 int32_t ResetDecoder();
134 134
135 void OutputStatisticsLog (SDecoderStatistics& sDecoderStatistics);135 void OutputStatisticsLog (SDecoderStatistics& sDecoderStatistics);
136 DECODING_STATE ReorderPicturesInDisplay (unsigned char** ppDst, SBufferInfo* pDstInfo);136 DECODING_STATE ReorderPicturesInDisplay (unsigned char** ppDst, SBufferInfo* pDstInfo);
137 137
138#ifdef OUTPUT_BIT_STREAM138#ifdef OUTPUT_BIT_STREAM
139 WelsFileHandle* m_pFBS;139 WelsFileHandle* m_pFBS;
140 WelsFileHandle* m_pFBSSize;140 WelsFileHandle* m_pFBSSize;
141#endif//OUTPUT_BIT_STREAM141#endif//OUTPUT_BIT_STREAM
142 142
143};143};
144 144
145} // namespace WelsDec145} // namespace WelsDec
146 146
147#endif // !defined(WELS_PLUS_WELSDECODEREXT_H)147#endif // !defined(WELS_PLUS_WELSDECODEREXT_H)
codec/decoder/plus/src/welsDecoderExt.cpp+1016−1016
@@ -1,1016 +1,1016 @@
1/*!1/*!
2 * \copy2 * \copy
3 * Copyright (c) 2009-2013, Cisco Systems3 * Copyright (c) 2009-2013, Cisco Systems
4 * All rights reserved.4 * All rights reserved.
5 *5 *
6 * Redistribution and use in source and binary forms, with or without6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions7 * modification, are permitted provided that the following conditions
8 * are met:8 * are met:
9 *9 *
10 * * Redistributions of source code must retain the above copyright10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.11 * notice, this list of conditions and the following disclaimer.
12 *12 *
13 * * Redistributions in binary form must reproduce the above copyright13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the15 * the documentation and/or other materials provided with the
16 * distribution.16 * distribution.
17 *17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.29 * POSSIBILITY OF SUCH DAMAGE.
30 *30 *
31 *31 *
32 * welsDecoderExt.cpp32 * welsDecoderExt.cpp
33 *33 *
34 * Abstract34 * Abstract
35 * Cisco OpenH264 decoder extension utilization35 * Cisco OpenH264 decoder extension utilization
36 *36 *
37 * History37 * History
38 * 3/12/2009 Created38 * 3/12/2009 Created
39 *39 *
40 *40 *
41 ************************************************************************/41 ************************************************************************/
42//#include <assert.h>42//#include <assert.h>
43#include "welsDecoderExt.h"43#include "welsDecoderExt.h"
44#include "welsCodecTrace.h"44#include "welsCodecTrace.h"
45#include "codec_def.h"45#include "codec_def.h"
46#include "typedefs.h"46#include "typedefs.h"
47#include "memory_align.h"47#include "memory_align.h"
48#include "utils.h"48#include "utils.h"
49#include "version.h"49#include "version.h"
50 50
51//#include "macros.h"51//#include "macros.h"
52#include "decoder.h"52#include "decoder.h"
53#include "decoder_core.h"53#include "decoder_core.h"
54#include "error_concealment.h"54#include "error_concealment.h"
55 55
56#include "measure_time.h"56#include "measure_time.h"
57extern "C" {57extern "C" {
58#include "decoder_core.h"58#include "decoder_core.h"
59#include "manage_dec_ref.h"59#include "manage_dec_ref.h"
60}60}
61#include "error_code.h"61#include "error_code.h"
62#include "crt_util_safe_x.h" // Safe CRT routines like util for cross platforms62#include "crt_util_safe_x.h" // Safe CRT routines like util for cross platforms
63#include <time.h>63#include <time.h>
64#if defined(_WIN32) /*&& defined(_DEBUG)*/64#if defined(_WIN32) /*&& defined(_DEBUG)*/
65 65
66#include <windows.h>66#include <windows.h>
67#include <stdio.h>67#include <stdio.h>
68#include <stdarg.h>68#include <stdarg.h>
69#include <sys/types.h>69#include <sys/types.h>
70#else70#else
71#include <sys/time.h>71#include <sys/time.h>
72#endif72#endif
73 73
74#define _PICTURE_REORDERING_ 174#define _PICTURE_REORDERING_ 1
75 75
76static int32_t sIMinInt32 = -0x7FFFFFFF;76static int32_t sIMinInt32 = -0x7FFFFFFF;
77 77
78namespace WelsDec {78namespace WelsDec {
79 79
80//////////////////////////////////////////////////////////////////////80//////////////////////////////////////////////////////////////////////
81// Construction/Destruction81// Construction/Destruction
82//////////////////////////////////////////////////////////////////////82//////////////////////////////////////////////////////////////////////
83 83
84/***************************************************************************84/***************************************************************************
85* Description:85* Description:
86* class CWelsDecoder constructor function, do initialization and86* class CWelsDecoder constructor function, do initialization and
87* alloc memory required87* alloc memory required
88*88*
89* Input parameters: none89* Input parameters: none
90*90*
91* return: none91* return: none
92***************************************************************************/92***************************************************************************/
93CWelsDecoder::CWelsDecoder (void)93CWelsDecoder::CWelsDecoder (void)
94 : m_pDecContext (NULL),94 : m_pDecContext (NULL),
95 m_pWelsTrace (NULL),95 m_pWelsTrace (NULL),
96 m_iPictInfoIndex (0),96 m_iPictInfoIndex (0),
97 m_iMinPOC (sIMinInt32),97 m_iMinPOC (sIMinInt32),
98 m_iNumOfPicts (0),98 m_iNumOfPicts (0),
99 m_iLastGOPRemainPicts (0),99 m_iLastGOPRemainPicts (0),
100 m_LastWrittenPOC (sIMinInt32),100 m_LastWrittenPOC (sIMinInt32),
101 m_iLargestBufferedPicIndex (0) {101 m_iLargestBufferedPicIndex (0) {
102#ifdef OUTPUT_BIT_STREAM102#ifdef OUTPUT_BIT_STREAM
103 char chFileName[1024] = { 0 }; //for .264103 char chFileName[1024] = { 0 }; //for .264
104 int iBufUsed = 0;104 int iBufUsed = 0;
105 int iBufLeft = 1023;105 int iBufLeft = 1023;
106 int iCurUsed;106 int iCurUsed;
107 107
108 char chFileNameSize[1024] = { 0 }; //for .len108 char chFileNameSize[1024] = { 0 }; //for .len
109 int iBufUsedSize = 0;109 int iBufUsedSize = 0;
110 int iBufLeftSize = 1023;110 int iBufLeftSize = 1023;
111 int iCurUsedSize;111 int iCurUsedSize;
112#endif//OUTPUT_BIT_STREAM112#endif//OUTPUT_BIT_STREAM
113 113
114 114
115 m_pWelsTrace = new welsCodecTrace();115 m_pWelsTrace = new welsCodecTrace();
116 if (m_pWelsTrace != NULL) {116 if (m_pWelsTrace != NULL) {
117 m_pWelsTrace->SetCodecInstance (this);117 m_pWelsTrace->SetCodecInstance (this);
118 m_pWelsTrace->SetTraceLevel (WELS_LOG_ERROR);118 m_pWelsTrace->SetTraceLevel (WELS_LOG_ERROR);
119 119
120 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::CWelsDecoder() entry");120 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::CWelsDecoder() entry");
121 }121 }
122 122
123 for (int32_t i = 0; i < 16; ++i) {123 for (int32_t i = 0; i < 16; ++i) {
124 m_sPictInfoList[i].bLastGOP = false;124 m_sPictInfoList[i].bLastGOP = false;
125 m_sPictInfoList[i].iPOC = sIMinInt32;125 m_sPictInfoList[i].iPOC = sIMinInt32;
126 }126 }
127 127
128#ifdef OUTPUT_BIT_STREAM128#ifdef OUTPUT_BIT_STREAM
129 SWelsTime sCurTime;129 SWelsTime sCurTime;
130 130
131 WelsGetTimeOfDay (&sCurTime);131 WelsGetTimeOfDay (&sCurTime);
132 132
133 iCurUsed = WelsSnprintf (chFileName, iBufLeft, "bs_0x%p_", (void*)this);133 iCurUsed = WelsSnprintf (chFileName, iBufLeft, "bs_0x%p_", (void*)this);
134 iCurUsedSize = WelsSnprintf (chFileNameSize, iBufLeftSize, "size_0x%p_", (void*)this);134 iCurUsedSize = WelsSnprintf (chFileNameSize, iBufLeftSize, "size_0x%p_", (void*)this);
135 135
136 iBufUsed += iCurUsed;136 iBufUsed += iCurUsed;
137 iBufLeft -= iCurUsed;137 iBufLeft -= iCurUsed;
138 if (iBufLeft > 0) {138 if (iBufLeft > 0) {
139 iCurUsed = WelsStrftime (&chFileName[iBufUsed], iBufLeft, "%y%m%d%H%M%S", &sCurTime);139 iCurUsed = WelsStrftime (&chFileName[iBufUsed], iBufLeft, "%y%m%d%H%M%S", &sCurTime);
140 iBufUsed += iCurUsed;140 iBufUsed += iCurUsed;
141 iBufLeft -= iCurUsed;141 iBufLeft -= iCurUsed;
142 }142 }
143 143
144 iBufUsedSize += iCurUsedSize;144 iBufUsedSize += iCurUsedSize;
145 iBufLeftSize -= iCurUsedSize;145 iBufLeftSize -= iCurUsedSize;
146 if (iBufLeftSize > 0) {146 if (iBufLeftSize > 0) {
147 iCurUsedSize = WelsStrftime (&chFileNameSize[iBufUsedSize], iBufLeftSize, "%y%m%d%H%M%S", &sCurTime);147 iCurUsedSize = WelsStrftime (&chFileNameSize[iBufUsedSize], iBufLeftSize, "%y%m%d%H%M%S", &sCurTime);
148 iBufUsedSize += iCurUsedSize;148 iBufUsedSize += iCurUsedSize;
149 iBufLeftSize -= iCurUsedSize;149 iBufLeftSize -= iCurUsedSize;
150 }150 }
151 151
152 if (iBufLeft > 0) {152 if (iBufLeft > 0) {
153 iCurUsed = WelsSnprintf (&chFileName[iBufUsed], iBufLeft, ".%03.3u.264", WelsGetMillisecond (&sCurTime));153 iCurUsed = WelsSnprintf (&chFileName[iBufUsed], iBufLeft, ".%03.3u.264", WelsGetMillisecond (&sCurTime));
154 iBufUsed += iCurUsed;154 iBufUsed += iCurUsed;
155 iBufLeft -= iCurUsed;155 iBufLeft -= iCurUsed;
156 }156 }
157 157
158 if (iBufLeftSize > 0) {158 if (iBufLeftSize > 0) {
159 iCurUsedSize = WelsSnprintf (&chFileNameSize[iBufUsedSize], iBufLeftSize, ".%03.3u.len",159 iCurUsedSize = WelsSnprintf (&chFileNameSize[iBufUsedSize], iBufLeftSize, ".%03.3u.len",
160 WelsGetMillisecond (&sCurTime));160 WelsGetMillisecond (&sCurTime));
161 iBufUsedSize += iCurUsedSize;161 iBufUsedSize += iCurUsedSize;
162 iBufLeftSize -= iCurUsedSize;162 iBufLeftSize -= iCurUsedSize;
163 }163 }
164 164
165 165
166 m_pFBS = WelsFopen (chFileName, "wb");166 m_pFBS = WelsFopen (chFileName, "wb");
167 m_pFBSSize = WelsFopen (chFileNameSize, "wb");167 m_pFBSSize = WelsFopen (chFileNameSize, "wb");
168#endif//OUTPUT_BIT_STREAM168#endif//OUTPUT_BIT_STREAM
169}169}
170 170
171/***************************************************************************171/***************************************************************************
172* Description:172* Description:
173* class CWelsDecoder destructor function, destroy allocced memory173* class CWelsDecoder destructor function, destroy allocced memory
174*174*
175* Input parameters: none175* Input parameters: none
176*176*
177* return: none177* return: none
178***************************************************************************/178***************************************************************************/
179CWelsDecoder::~CWelsDecoder() {179CWelsDecoder::~CWelsDecoder() {
180 if (m_pWelsTrace != NULL) {180 if (m_pWelsTrace != NULL) {
181 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::~CWelsDecoder()");181 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::~CWelsDecoder()");
182 }182 }
183 183
184 UninitDecoder();184 UninitDecoder();
185 185
186#ifdef OUTPUT_BIT_STREAM186#ifdef OUTPUT_BIT_STREAM
187 if (m_pFBS) {187 if (m_pFBS) {
188 WelsFclose (m_pFBS);188 WelsFclose (m_pFBS);
189 m_pFBS = NULL;189 m_pFBS = NULL;
190 }190 }
191 if (m_pFBSSize) {191 if (m_pFBSSize) {
192 WelsFclose (m_pFBSSize);192 WelsFclose (m_pFBSSize);
193 m_pFBSSize = NULL;193 m_pFBSSize = NULL;
194 }194 }
195#endif//OUTPUT_BIT_STREAM195#endif//OUTPUT_BIT_STREAM
196 196
197 if (m_pWelsTrace != NULL) {197 if (m_pWelsTrace != NULL) {
198 delete m_pWelsTrace;198 delete m_pWelsTrace;
199 m_pWelsTrace = NULL;199 m_pWelsTrace = NULL;
200 }200 }
201}201}
202 202
203long CWelsDecoder::Initialize (const SDecodingParam* pParam) {203long CWelsDecoder::Initialize (const SDecodingParam* pParam) {
204 int iRet = ERR_NONE;204 int iRet = ERR_NONE;
205 if (m_pWelsTrace == NULL) {205 if (m_pWelsTrace == NULL) {
206 return cmMallocMemeError;206 return cmMallocMemeError;
207 }207 }
208 208
209 if (pParam == NULL) {209 if (pParam == NULL) {
210 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsDecoder::Initialize(), invalid input argument.");210 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsDecoder::Initialize(), invalid input argument.");
211 return cmInitParaError;211 return cmInitParaError;
212 }212 }
213 213
214 // H.264 decoder initialization,including memory allocation,then open it ready to decode214 // H.264 decoder initialization,including memory allocation,then open it ready to decode
215 iRet = InitDecoder (pParam);215 iRet = InitDecoder (pParam);
216 if (iRet)216 if (iRet)
217 return iRet;217 return iRet;
218 218
219 return cmResultSuccess;219 return cmResultSuccess;
220}220}
221 221
222long CWelsDecoder::Uninitialize() {222long CWelsDecoder::Uninitialize() {
223 UninitDecoder();223 UninitDecoder();
224 224
225 return ERR_NONE;225 return ERR_NONE;
226}226}
227 227
228void CWelsDecoder::UninitDecoder (void) {228void CWelsDecoder::UninitDecoder (void) {
229 if (NULL == m_pDecContext)229 if (NULL == m_pDecContext)
230 return;230 return;
231 231
232 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::UninitDecoder(), openh264 codec version = %s.",232 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::UninitDecoder(), openh264 codec version = %s.",
233 VERSION_NUMBER);233 VERSION_NUMBER);
234 234
235 WelsEndDecoder (m_pDecContext);235 WelsEndDecoder (m_pDecContext);
236 236
237 if (m_pDecContext->pMemAlign != NULL) {237 if (m_pDecContext->pMemAlign != NULL) {
238 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,238 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
239 "CWelsDecoder::UninitDecoder(), verify memory usage (%d bytes) after free..",239 "CWelsDecoder::UninitDecoder(), verify memory usage (%d bytes) after free..",
240 m_pDecContext->pMemAlign->WelsGetMemoryUsage());240 m_pDecContext->pMemAlign->WelsGetMemoryUsage());
241 delete m_pDecContext->pMemAlign;241 delete m_pDecContext->pMemAlign;
242 m_pDecContext->pMemAlign = NULL;242 m_pDecContext->pMemAlign = NULL;
243 }243 }
244 244
245 if (NULL != m_pDecContext) {245 if (NULL != m_pDecContext) {
246 WelsFree (m_pDecContext, "m_pDecContext");246 WelsFree (m_pDecContext, "m_pDecContext");
247 247
248 m_pDecContext = NULL;248 m_pDecContext = NULL;
249 }249 }
250}250}
251 251
252// the return value of this function is not suitable, it need report failure info to upper layer.252// the return value of this function is not suitable, it need report failure info to upper layer.
253int32_t CWelsDecoder::InitDecoder (const SDecodingParam* pParam) {253int32_t CWelsDecoder::InitDecoder (const SDecodingParam* pParam) {
254 254
255 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,255 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
256 "CWelsDecoder::init_decoder(), openh264 codec version = %s, ParseOnly = %d",256 "CWelsDecoder::init_decoder(), openh264 codec version = %s, ParseOnly = %d",
257 VERSION_NUMBER, (int32_t)pParam->bParseOnly);257 VERSION_NUMBER, (int32_t)pParam->bParseOnly);
258 258
259 //reset decoder context259 //reset decoder context
260 if (m_pDecContext) //free260 if (m_pDecContext) //free
261 UninitDecoder();261 UninitDecoder();
262 m_pDecContext = (PWelsDecoderContext)WelsMallocz (sizeof (SWelsDecoderContext), "m_pDecContext");262 m_pDecContext = (PWelsDecoderContext)WelsMallocz (sizeof (SWelsDecoderContext), "m_pDecContext");
263 if (NULL == m_pDecContext)263 if (NULL == m_pDecContext)
264 return cmMallocMemeError;264 return cmMallocMemeError;
265 int32_t iCacheLineSize = 16; // on chip cache line size in byte265 int32_t iCacheLineSize = 16; // on chip cache line size in byte
266 m_pDecContext->pMemAlign = new CMemoryAlign (iCacheLineSize);266 m_pDecContext->pMemAlign = new CMemoryAlign (iCacheLineSize);
267 WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, (NULL == m_pDecContext->pMemAlign), UninitDecoder())267 WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, (NULL == m_pDecContext->pMemAlign), UninitDecoder())
268 268
269 //fill in default value into context269 //fill in default value into context
270 WelsDecoderDefaults (m_pDecContext, &m_pWelsTrace->m_sLogCtx);270 WelsDecoderDefaults (m_pDecContext, &m_pWelsTrace->m_sLogCtx);
271 271
272 //check param and update decoder context272 //check param and update decoder context
273 m_pDecContext->pParam = (SDecodingParam*)m_pDecContext->pMemAlign->WelsMallocz (sizeof (SDecodingParam),273 m_pDecContext->pParam = (SDecodingParam*)m_pDecContext->pMemAlign->WelsMallocz (sizeof (SDecodingParam),
274 "SDecodingParam");274 "SDecodingParam");
275 WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, (NULL == m_pDecContext->pParam), UninitDecoder());275 WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, (NULL == m_pDecContext->pParam), UninitDecoder());
276 int32_t iRet = DecoderConfigParam (m_pDecContext, pParam);276 int32_t iRet = DecoderConfigParam (m_pDecContext, pParam);
277 WELS_VERIFY_RETURN_IFNEQ (iRet, cmResultSuccess);277 WELS_VERIFY_RETURN_IFNEQ (iRet, cmResultSuccess);
278 278
279 //init decoder279 //init decoder
280 WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, WelsInitDecoder (m_pDecContext, &m_pWelsTrace->m_sLogCtx),280 WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, WelsInitDecoder (m_pDecContext, &m_pWelsTrace->m_sLogCtx),
281 UninitDecoder())281 UninitDecoder())
282 282
283 return cmResultSuccess;283 return cmResultSuccess;
284}284}
285 285
286int32_t CWelsDecoder::ResetDecoder() {286int32_t CWelsDecoder::ResetDecoder() {
287 // TBC: need to be modified when context and trace point are null287 // TBC: need to be modified when context and trace point are null
288 if (m_pDecContext != NULL && m_pWelsTrace != NULL) {288 if (m_pDecContext != NULL && m_pWelsTrace != NULL) {
289 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "ResetDecoder(), context error code is %d",289 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "ResetDecoder(), context error code is %d",
290 m_pDecContext->iErrorCode);290 m_pDecContext->iErrorCode);
291 SDecodingParam sPrevParam;291 SDecodingParam sPrevParam;
292 memcpy (&sPrevParam, m_pDecContext->pParam, sizeof (SDecodingParam));292 memcpy (&sPrevParam, m_pDecContext->pParam, sizeof (SDecodingParam));
293 293
294 WELS_VERIFY_RETURN_PROC_IF (cmInitParaError, InitDecoder (&sPrevParam), UninitDecoder());294 WELS_VERIFY_RETURN_PROC_IF (cmInitParaError, InitDecoder (&sPrevParam), UninitDecoder());
295 } else if (m_pWelsTrace != NULL) {295 } else if (m_pWelsTrace != NULL) {
296 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "ResetDecoder() failed as decoder context null");296 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "ResetDecoder() failed as decoder context null");
297 }297 }
298 return ERR_INFO_UNINIT;298 return ERR_INFO_UNINIT;
299}299}
300 300
301/*301/*
302 * Set Option302 * Set Option
303 */303 */
304long CWelsDecoder::SetOption (DECODER_OPTION eOptID, void* pOption) {304long CWelsDecoder::SetOption (DECODER_OPTION eOptID, void* pOption) {
305 int iVal = 0;305 int iVal = 0;
306 306
307 if (m_pDecContext == NULL && eOptID != DECODER_OPTION_TRACE_LEVEL &&307 if (m_pDecContext == NULL && eOptID != DECODER_OPTION_TRACE_LEVEL &&
308 eOptID != DECODER_OPTION_TRACE_CALLBACK && eOptID != DECODER_OPTION_TRACE_CALLBACK_CONTEXT)308 eOptID != DECODER_OPTION_TRACE_CALLBACK && eOptID != DECODER_OPTION_TRACE_CALLBACK_CONTEXT)
309 return dsInitialOptExpected;309 return dsInitialOptExpected;
310 if (eOptID == DECODER_OPTION_END_OF_STREAM) { // Indicate bit-stream of the final frame to be decoded310 if (eOptID == DECODER_OPTION_END_OF_STREAM) { // Indicate bit-stream of the final frame to be decoded
311 if (pOption == NULL)311 if (pOption == NULL)
312 return cmInitParaError;312 return cmInitParaError;
313 313
314 iVal = * ((int*)pOption); // boolean value for whether enabled End Of Stream flag314 iVal = * ((int*)pOption); // boolean value for whether enabled End Of Stream flag
315 315
316 m_pDecContext->bEndOfStreamFlag = iVal ? true : false;316 m_pDecContext->bEndOfStreamFlag = iVal ? true : false;
317 317
318 return cmResultSuccess;318 return cmResultSuccess;
319 } else if (eOptID == DECODER_OPTION_ERROR_CON_IDC) { // Indicate error concealment status319 } else if (eOptID == DECODER_OPTION_ERROR_CON_IDC) { // Indicate error concealment status
320 if (pOption == NULL)320 if (pOption == NULL)
321 return cmInitParaError;321 return cmInitParaError;
322 322
323 iVal = * ((int*)pOption); // int value for error concealment idc323 iVal = * ((int*)pOption); // int value for error concealment idc
324 iVal = WELS_CLIP3 (iVal, (int32_t)ERROR_CON_DISABLE, (int32_t)ERROR_CON_SLICE_MV_COPY_CROSS_IDR_FREEZE_RES_CHANGE);324 iVal = WELS_CLIP3 (iVal, (int32_t)ERROR_CON_DISABLE, (int32_t)ERROR_CON_SLICE_MV_COPY_CROSS_IDR_FREEZE_RES_CHANGE);
325 if ((m_pDecContext->pParam->bParseOnly) && (iVal != (int32_t)ERROR_CON_DISABLE)) {325 if ((m_pDecContext->pParam->bParseOnly) && (iVal != (int32_t)ERROR_CON_DISABLE)) {
326 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,326 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
327 "CWelsDecoder::SetOption for ERROR_CON_IDC = %d not allowd for parse only!.", iVal);327 "CWelsDecoder::SetOption for ERROR_CON_IDC = %d not allowd for parse only!.", iVal);
328 return cmInitParaError;328 return cmInitParaError;
329 }329 }
330 330
331 m_pDecContext->pParam->eEcActiveIdc = (ERROR_CON_IDC)iVal;331 m_pDecContext->pParam->eEcActiveIdc = (ERROR_CON_IDC)iVal;
332 InitErrorCon (m_pDecContext);332 InitErrorCon (m_pDecContext);
333 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,333 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
334 "CWelsDecoder::SetOption for ERROR_CON_IDC = %d.", iVal);334 "CWelsDecoder::SetOption for ERROR_CON_IDC = %d.", iVal);
335 335
336 return cmResultSuccess;336 return cmResultSuccess;
337 } else if (eOptID == DECODER_OPTION_TRACE_LEVEL) {337 } else if (eOptID == DECODER_OPTION_TRACE_LEVEL) {
338 if (m_pWelsTrace) {338 if (m_pWelsTrace) {
339 uint32_t level = * ((uint32_t*)pOption);339 uint32_t level = * ((uint32_t*)pOption);
340 m_pWelsTrace->SetTraceLevel (level);340 m_pWelsTrace->SetTraceLevel (level);
341 }341 }
342 return cmResultSuccess;342 return cmResultSuccess;
343 } else if (eOptID == DECODER_OPTION_TRACE_CALLBACK) {343 } else if (eOptID == DECODER_OPTION_TRACE_CALLBACK) {
344 if (m_pWelsTrace) {344 if (m_pWelsTrace) {
345 WelsTraceCallback callback = * ((WelsTraceCallback*)pOption);345 WelsTraceCallback callback = * ((WelsTraceCallback*)pOption);
346 m_pWelsTrace->SetTraceCallback (callback);346 m_pWelsTrace->SetTraceCallback (callback);
347 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,347 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
348 "CWelsDecoder::SetOption():DECODER_OPTION_TRACE_CALLBACK callback = %p.",348 "CWelsDecoder::SetOption():DECODER_OPTION_TRACE_CALLBACK callback = %p.",
349 callback);349 callback);
350 }350 }
351 return cmResultSuccess;351 return cmResultSuccess;
352 } else if (eOptID == DECODER_OPTION_TRACE_CALLBACK_CONTEXT) {352 } else if (eOptID == DECODER_OPTION_TRACE_CALLBACK_CONTEXT) {
353 if (m_pWelsTrace) {353 if (m_pWelsTrace) {
354 void* ctx = * ((void**)pOption);354 void* ctx = * ((void**)pOption);
355 m_pWelsTrace->SetTraceCallbackContext (ctx);355 m_pWelsTrace->SetTraceCallbackContext (ctx);
356 }356 }
357 return cmResultSuccess;357 return cmResultSuccess;
358 } else if (eOptID == DECODER_OPTION_GET_STATISTICS) {358 } else if (eOptID == DECODER_OPTION_GET_STATISTICS) {
359 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING,359 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING,
360 "CWelsDecoder::SetOption():DECODER_OPTION_GET_STATISTICS: this option is get-only!");360 "CWelsDecoder::SetOption():DECODER_OPTION_GET_STATISTICS: this option is get-only!");
361 return cmInitParaError;361 return cmInitParaError;
362 } else if (eOptID == DECODER_OPTION_STATISTICS_LOG_INTERVAL) {362 } else if (eOptID == DECODER_OPTION_STATISTICS_LOG_INTERVAL) {
363 if (pOption) {363 if (pOption) {
364 m_pDecContext->sDecoderStatistics.iStatisticsLogInterval = (* ((unsigned int*)pOption));364 m_pDecContext->sDecoderStatistics.iStatisticsLogInterval = (* ((unsigned int*)pOption));
365 return cmResultSuccess;365 return cmResultSuccess;
366 }366 }
367 } else if (eOptID == DECODER_OPTION_GET_SAR_INFO) {367 } else if (eOptID == DECODER_OPTION_GET_SAR_INFO) {
368 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING,368 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING,
369 "CWelsDecoder::SetOption():DECODER_OPTION_GET_SAR_INFO: this option is get-only!");369 "CWelsDecoder::SetOption():DECODER_OPTION_GET_SAR_INFO: this option is get-only!");
370 return cmInitParaError;370 return cmInitParaError;
371 }371 }
372 return cmInitParaError;372 return cmInitParaError;
373}373}
374 374
375/*375/*
376 * Get Option376 * Get Option
377 */377 */
378long CWelsDecoder::GetOption (DECODER_OPTION eOptID, void* pOption) {378long CWelsDecoder::GetOption (DECODER_OPTION eOptID, void* pOption) {
379 int iVal = 0;379 int iVal = 0;
380 380
381 if (m_pDecContext == NULL)381 if (m_pDecContext == NULL)
382 return cmInitExpected;382 return cmInitExpected;
383 383
384 if (pOption == NULL)384 if (pOption == NULL)
385 return cmInitParaError;385 return cmInitParaError;
386 386
387 if (DECODER_OPTION_END_OF_STREAM == eOptID) {387 if (DECODER_OPTION_END_OF_STREAM == eOptID) {
388 iVal = m_pDecContext->bEndOfStreamFlag;388 iVal = m_pDecContext->bEndOfStreamFlag;
389 * ((int*)pOption) = iVal;389 * ((int*)pOption) = iVal;
390 return cmResultSuccess;390 return cmResultSuccess;
391 }391 }
392#ifdef LONG_TERM_REF392#ifdef LONG_TERM_REF
393 else if (DECODER_OPTION_IDR_PIC_ID == eOptID) {393 else if (DECODER_OPTION_IDR_PIC_ID == eOptID) {
394 iVal = m_pDecContext->uiCurIdrPicId;394 iVal = m_pDecContext->uiCurIdrPicId;
395 * ((int*)pOption) = iVal;395 * ((int*)pOption) = iVal;
396 return cmResultSuccess;396 return cmResultSuccess;
397 } else if (DECODER_OPTION_FRAME_NUM == eOptID) {397 } else if (DECODER_OPTION_FRAME_NUM == eOptID) {
398 iVal = m_pDecContext->iFrameNum;398 iVal = m_pDecContext->iFrameNum;
399 * ((int*)pOption) = iVal;399 * ((int*)pOption) = iVal;
400 return cmResultSuccess;400 return cmResultSuccess;
401 } else if (DECODER_OPTION_LTR_MARKING_FLAG == eOptID) {401 } else if (DECODER_OPTION_LTR_MARKING_FLAG == eOptID) {
402 iVal = m_pDecContext->bCurAuContainLtrMarkSeFlag;402 iVal = m_pDecContext->bCurAuContainLtrMarkSeFlag;
403 * ((int*)pOption) = iVal;403 * ((int*)pOption) = iVal;
404 return cmResultSuccess;404 return cmResultSuccess;
405 } else if (DECODER_OPTION_LTR_MARKED_FRAME_NUM == eOptID) {405 } else if (DECODER_OPTION_LTR_MARKED_FRAME_NUM == eOptID) {
406 iVal = m_pDecContext->iFrameNumOfAuMarkedLtr;406 iVal = m_pDecContext->iFrameNumOfAuMarkedLtr;
407 * ((int*)pOption) = iVal;407 * ((int*)pOption) = iVal;
408 return cmResultSuccess;408 return cmResultSuccess;
409 }409 }
410#endif410#endif
411 else if (DECODER_OPTION_VCL_NAL == eOptID) { //feedback whether or not have VCL NAL in current AU411 else if (DECODER_OPTION_VCL_NAL == eOptID) { //feedback whether or not have VCL NAL in current AU
412 iVal = m_pDecContext->iFeedbackVclNalInAu;412 iVal = m_pDecContext->iFeedbackVclNalInAu;
413 * ((int*)pOption) = iVal;413 * ((int*)pOption) = iVal;
414 return cmResultSuccess;414 return cmResultSuccess;
415 } else if (DECODER_OPTION_TEMPORAL_ID == eOptID) { //if have VCL NAL in current AU, then feedback the temporal ID415 } else if (DECODER_OPTION_TEMPORAL_ID == eOptID) { //if have VCL NAL in current AU, then feedback the temporal ID
416 iVal = m_pDecContext->iFeedbackTidInAu;416 iVal = m_pDecContext->iFeedbackTidInAu;
417 * ((int*)pOption) = iVal;417 * ((int*)pOption) = iVal;
418 return cmResultSuccess;418 return cmResultSuccess;
419 } else if (DECODER_OPTION_IS_REF_PIC == eOptID) {419 } else if (DECODER_OPTION_IS_REF_PIC == eOptID) {
420 iVal = m_pDecContext->iFeedbackNalRefIdc;420 iVal = m_pDecContext->iFeedbackNalRefIdc;
421 if (iVal > 0)421 if (iVal > 0)
422 iVal = 1;422 iVal = 1;
423 * ((int*)pOption) = iVal;423 * ((int*)pOption) = iVal;
424 return cmResultSuccess;424 return cmResultSuccess;
425 } else if (DECODER_OPTION_ERROR_CON_IDC == eOptID) {425 } else if (DECODER_OPTION_ERROR_CON_IDC == eOptID) {
426 iVal = (int)m_pDecContext->pParam->eEcActiveIdc;426 iVal = (int)m_pDecContext->pParam->eEcActiveIdc;
427 * ((int*)pOption) = iVal;427 * ((int*)pOption) = iVal;
428 return cmResultSuccess;428 return cmResultSuccess;
429 } else if (DECODER_OPTION_GET_STATISTICS == eOptID) { // get decoder statistics info for real time debugging429 } else if (DECODER_OPTION_GET_STATISTICS == eOptID) { // get decoder statistics info for real time debugging
430 SDecoderStatistics* pDecoderStatistics = (static_cast<SDecoderStatistics*> (pOption));430 SDecoderStatistics* pDecoderStatistics = (static_cast<SDecoderStatistics*> (pOption));
431 431
432 memcpy (pDecoderStatistics, &m_pDecContext->sDecoderStatistics, sizeof (SDecoderStatistics));432 memcpy (pDecoderStatistics, &m_pDecContext->sDecoderStatistics, sizeof (SDecoderStatistics));
433 433
434 if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount != 0) { //not original status434 if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount != 0) { //not original status
435 pDecoderStatistics->fAverageFrameSpeedInMs = (float) (m_pDecContext->dDecTime) /435 pDecoderStatistics->fAverageFrameSpeedInMs = (float) (m_pDecContext->dDecTime) /
436 (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount);436 (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount);
437 pDecoderStatistics->fActualAverageFrameSpeedInMs = (float) (m_pDecContext->dDecTime) /437 pDecoderStatistics->fActualAverageFrameSpeedInMs = (float) (m_pDecContext->dDecTime) /
438 (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount + m_pDecContext->sDecoderStatistics.uiFreezingIDRNum +438 (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount + m_pDecContext->sDecoderStatistics.uiFreezingIDRNum +
439 m_pDecContext->sDecoderStatistics.uiFreezingNonIDRNum);439 m_pDecContext->sDecoderStatistics.uiFreezingNonIDRNum);
440 }440 }
441 return cmResultSuccess;441 return cmResultSuccess;
442 } else if (eOptID == DECODER_OPTION_STATISTICS_LOG_INTERVAL) {442 } else if (eOptID == DECODER_OPTION_STATISTICS_LOG_INTERVAL) {
443 if (pOption) {443 if (pOption) {
444 iVal = m_pDecContext->sDecoderStatistics.iStatisticsLogInterval;444 iVal = m_pDecContext->sDecoderStatistics.iStatisticsLogInterval;
445 * ((unsigned int*)pOption) = iVal;445 * ((unsigned int*)pOption) = iVal;
446 return cmResultSuccess;446 return cmResultSuccess;
447 }447 }
448 } else if (DECODER_OPTION_GET_SAR_INFO == eOptID) { //get decoder SAR info in VUI448 } else if (DECODER_OPTION_GET_SAR_INFO == eOptID) { //get decoder SAR info in VUI
449 PVuiSarInfo pVuiSarInfo = (static_cast<PVuiSarInfo> (pOption));449 PVuiSarInfo pVuiSarInfo = (static_cast<PVuiSarInfo> (pOption));
450 memset (pVuiSarInfo, 0, sizeof (SVuiSarInfo));450 memset (pVuiSarInfo, 0, sizeof (SVuiSarInfo));
451 if (!m_pDecContext->pSps) {451 if (!m_pDecContext->pSps) {
452 return cmInitExpected;452 return cmInitExpected;
453 } else {453 } else {
454 pVuiSarInfo->uiSarWidth = m_pDecContext->pSps->sVui.uiSarWidth;454 pVuiSarInfo->uiSarWidth = m_pDecContext->pSps->sVui.uiSarWidth;
455 pVuiSarInfo->uiSarHeight = m_pDecContext->pSps->sVui.uiSarHeight;455 pVuiSarInfo->uiSarHeight = m_pDecContext->pSps->sVui.uiSarHeight;
456 pVuiSarInfo->bOverscanAppropriateFlag = m_pDecContext->pSps->sVui.bOverscanAppropriateFlag;456 pVuiSarInfo->bOverscanAppropriateFlag = m_pDecContext->pSps->sVui.bOverscanAppropriateFlag;
457 return cmResultSuccess;457 return cmResultSuccess;
458 }458 }
459 } else if (DECODER_OPTION_PROFILE == eOptID) {459 } else if (DECODER_OPTION_PROFILE == eOptID) {
460 if (!m_pDecContext->pSps) {460 if (!m_pDecContext->pSps) {
461 return cmInitExpected;461 return cmInitExpected;
462 }462 }
463 iVal = (int)m_pDecContext->pSps->uiProfileIdc;463 iVal = (int)m_pDecContext->pSps->uiProfileIdc;
464 * ((int*)pOption) = iVal;464 * ((int*)pOption) = iVal;
465 return cmResultSuccess;465 return cmResultSuccess;
466 } else if (DECODER_OPTION_LEVEL == eOptID) {466 } else if (DECODER_OPTION_LEVEL == eOptID) {
467 if (!m_pDecContext->pSps) {467 if (!m_pDecContext->pSps) {
468 return cmInitExpected;468 return cmInitExpected;
469 }469 }
470 iVal = (int)m_pDecContext->pSps->uiLevelIdc;470 iVal = (int)m_pDecContext->pSps->uiLevelIdc;
471 * ((int*)pOption) = iVal;471 * ((int*)pOption) = iVal;
472 return cmResultSuccess;472 return cmResultSuccess;
473 } else if (DECODER_OPTION_NUM_OF_FRAMES_REMAINING_IN_BUFFER == eOptID) {473 } else if (DECODER_OPTION_NUM_OF_FRAMES_REMAINING_IN_BUFFER == eOptID) {
474 if (m_pDecContext->pSps && m_pDecContext->pSps->uiProfileIdc != 66 && m_pDecContext->pPps->bEntropyCodingModeFlag) {474 if (m_pDecContext->pSps && m_pDecContext->pSps->uiProfileIdc != 66 && m_pDecContext->pPps->bEntropyCodingModeFlag) {
475 * ((int*)pOption) = m_iNumOfPicts > 0 ? m_iNumOfPicts : 0;475 * ((int*)pOption) = m_iNumOfPicts > 0 ? m_iNumOfPicts : 0;
476 }476 }
477 return cmResultSuccess;477 return cmResultSuccess;
478 }478 }
479 479
480 return cmInitParaError;480 return cmInitParaError;
481}481}
482 482
483DECODING_STATE CWelsDecoder::DecodeFrameNoDelay (const unsigned char* kpSrc,483DECODING_STATE CWelsDecoder::DecodeFrameNoDelay (const unsigned char* kpSrc,
484 const int kiSrcLen,484 const int kiSrcLen,
485 unsigned char** ppDst,485 unsigned char** ppDst,
486 SBufferInfo* pDstInfo) {486 SBufferInfo* pDstInfo) {
487 int iRet;487 int iRet;
488 //SBufferInfo sTmpBufferInfo;488 //SBufferInfo sTmpBufferInfo;
489 //unsigned char* ppTmpDst[3] = {NULL, NULL, NULL};489 //unsigned char* ppTmpDst[3] = {NULL, NULL, NULL};
490 iRet = (int)DecodeFrame2 (kpSrc, kiSrcLen, ppDst, pDstInfo);490 iRet = (int)DecodeFrame2 (kpSrc, kiSrcLen, ppDst, pDstInfo);
491 //memcpy (&sTmpBufferInfo, pDstInfo, sizeof (SBufferInfo));491 //memcpy (&sTmpBufferInfo, pDstInfo, sizeof (SBufferInfo));
492 //ppTmpDst[0] = ppDst[0];492 //ppTmpDst[0] = ppDst[0];
493 //ppTmpDst[1] = ppDst[1];493 //ppTmpDst[1] = ppDst[1];
494 //ppTmpDst[2] = ppDst[2];494 //ppTmpDst[2] = ppDst[2];
495 iRet |= DecodeFrame2 (NULL, 0, ppDst, pDstInfo);495 iRet |= DecodeFrame2 (NULL, 0, ppDst, pDstInfo);
496 //if ((pDstInfo->iBufferStatus == 0) && (sTmpBufferInfo.iBufferStatus == 1)) {496 //if ((pDstInfo->iBufferStatus == 0) && (sTmpBufferInfo.iBufferStatus == 1)) {
497 //memcpy (pDstInfo, &sTmpBufferInfo, sizeof (SBufferInfo));497 //memcpy (pDstInfo, &sTmpBufferInfo, sizeof (SBufferInfo));
498 //ppDst[0] = ppTmpDst[0];498 //ppDst[0] = ppTmpDst[0];
499 //ppDst[1] = ppTmpDst[1];499 //ppDst[1] = ppTmpDst[1];
500 //ppDst[2] = ppTmpDst[2];500 //ppDst[2] = ppTmpDst[2];
501 //}501 //}
502 return (DECODING_STATE)iRet;502 return (DECODING_STATE)iRet;
503}503}
504 504
505DECODING_STATE CWelsDecoder::DecodeFrame2 (const unsigned char* kpSrc,505DECODING_STATE CWelsDecoder::DecodeFrame2 (const unsigned char* kpSrc,
506 const int kiSrcLen,506 const int kiSrcLen,
507 unsigned char** ppDst,507 unsigned char** ppDst,
508 SBufferInfo* pDstInfo) {508 SBufferInfo* pDstInfo) {
509 if (m_pDecContext == NULL || m_pDecContext->pParam == NULL) {509 if (m_pDecContext == NULL || m_pDecContext->pParam == NULL) {
510 if (m_pWelsTrace != NULL) {510 if (m_pWelsTrace != NULL) {
511 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "Call DecodeFrame2 without Initialize.\n");511 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "Call DecodeFrame2 without Initialize.\n");
512 }512 }
513 return dsInitialOptExpected;513 return dsInitialOptExpected;
514 }514 }
515 515
516 if (m_pDecContext->pParam->bParseOnly) {516 if (m_pDecContext->pParam->bParseOnly) {
517 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "bParseOnly should be false for this API calling! \n");517 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "bParseOnly should be false for this API calling! \n");
518 m_pDecContext->iErrorCode |= dsInvalidArgument;518 m_pDecContext->iErrorCode |= dsInvalidArgument;
519 return dsInvalidArgument;519 return dsInvalidArgument;
520 }520 }
521 if (CheckBsBuffer (m_pDecContext, kiSrcLen)) {521 if (CheckBsBuffer (m_pDecContext, kiSrcLen)) {
522 if (ResetDecoder())522 if (ResetDecoder())
523 return dsOutOfMemory;523 return dsOutOfMemory;
524 524
525 return dsErrorFree;525 return dsErrorFree;
526 }526 }
527 if (kiSrcLen > 0 && kpSrc != NULL) {527 if (kiSrcLen > 0 && kpSrc != NULL) {
528#ifdef OUTPUT_BIT_STREAM528#ifdef OUTPUT_BIT_STREAM
529 if (m_pFBS) {529 if (m_pFBS) {
530 WelsFwrite (kpSrc, sizeof (unsigned char), kiSrcLen, m_pFBS);530 WelsFwrite (kpSrc, sizeof (unsigned char), kiSrcLen, m_pFBS);
531 WelsFflush (m_pFBS);531 WelsFflush (m_pFBS);
532 }532 }
533 if (m_pFBSSize) {533 if (m_pFBSSize) {
534 WelsFwrite (&kiSrcLen, sizeof (int), 1, m_pFBSSize);534 WelsFwrite (&kiSrcLen, sizeof (int), 1, m_pFBSSize);
535 WelsFflush (m_pFBSSize);535 WelsFflush (m_pFBSSize);
536 }536 }
537#endif//OUTPUT_BIT_STREAM537#endif//OUTPUT_BIT_STREAM
538 m_pDecContext->bEndOfStreamFlag = false;538 m_pDecContext->bEndOfStreamFlag = false;
539 } else {539 } else {
540 //For application MODE, the error detection should be added for safe.540 //For application MODE, the error detection should be added for safe.
541 //But for CONSOLE MODE, when decoding LAST AU, kiSrcLen==0 && kpSrc==NULL.541 //But for CONSOLE MODE, when decoding LAST AU, kiSrcLen==0 && kpSrc==NULL.
542 m_pDecContext->bEndOfStreamFlag = true;542 m_pDecContext->bEndOfStreamFlag = true;
543 m_pDecContext->bInstantDecFlag = true;543 m_pDecContext->bInstantDecFlag = true;
544 }544 }
545 545
546 int64_t iStart, iEnd;546 int64_t iStart, iEnd;
547 iStart = WelsTime();547 iStart = WelsTime();
548 548
549 ppDst[0] = ppDst[1] = ppDst[2] = NULL;549 ppDst[0] = ppDst[1] = ppDst[2] = NULL;
550 m_pDecContext->iErrorCode = dsErrorFree; //initialize at the starting of AU decoding.550 m_pDecContext->iErrorCode = dsErrorFree; //initialize at the starting of AU decoding.
551 m_pDecContext->iFeedbackVclNalInAu = FEEDBACK_UNKNOWN_NAL; //initialize551 m_pDecContext->iFeedbackVclNalInAu = FEEDBACK_UNKNOWN_NAL; //initialize
552 unsigned long long uiInBsTimeStamp = pDstInfo->uiInBsTimeStamp;552 unsigned long long uiInBsTimeStamp = pDstInfo->uiInBsTimeStamp;
553 memset (pDstInfo, 0, sizeof (SBufferInfo));553 memset (pDstInfo, 0, sizeof (SBufferInfo));
554 pDstInfo->uiInBsTimeStamp = uiInBsTimeStamp;554 pDstInfo->uiInBsTimeStamp = uiInBsTimeStamp;
555#ifdef LONG_TERM_REF555#ifdef LONG_TERM_REF
556 m_pDecContext->bReferenceLostAtT0Flag = false; //initialize for LTR556 m_pDecContext->bReferenceLostAtT0Flag = false; //initialize for LTR
557 m_pDecContext->bCurAuContainLtrMarkSeFlag = false;557 m_pDecContext->bCurAuContainLtrMarkSeFlag = false;
558 m_pDecContext->iFrameNumOfAuMarkedLtr = 0;558 m_pDecContext->iFrameNumOfAuMarkedLtr = 0;
559 m_pDecContext->iFrameNum = -1; //initialize559 m_pDecContext->iFrameNum = -1; //initialize
560#endif560#endif
561 561
562 m_pDecContext->iFeedbackTidInAu = -1; //initialize562 m_pDecContext->iFeedbackTidInAu = -1; //initialize
563 m_pDecContext->iFeedbackNalRefIdc = -1; //initialize563 m_pDecContext->iFeedbackNalRefIdc = -1; //initialize
564 if (pDstInfo) {564 if (pDstInfo) {
565 pDstInfo->uiOutYuvTimeStamp = 0;565 pDstInfo->uiOutYuvTimeStamp = 0;
566 m_pDecContext->uiTimeStamp = pDstInfo->uiInBsTimeStamp;566 m_pDecContext->uiTimeStamp = pDstInfo->uiInBsTimeStamp;
567 } else {567 } else {
568 m_pDecContext->uiTimeStamp = 0;568 m_pDecContext->uiTimeStamp = 0;
569 }569 }
570 WelsDecodeBs (m_pDecContext, kpSrc, kiSrcLen, ppDst,570 WelsDecodeBs (m_pDecContext, kpSrc, kiSrcLen, ppDst,
571 pDstInfo, NULL); //iErrorCode has been modified in this function571 pDstInfo, NULL); //iErrorCode has been modified in this function
572 m_pDecContext->bInstantDecFlag = false; //reset no-delay flag572 m_pDecContext->bInstantDecFlag = false; //reset no-delay flag
573 if (m_pDecContext->iErrorCode) {573 if (m_pDecContext->iErrorCode) {
574 EWelsNalUnitType eNalType =574 EWelsNalUnitType eNalType =
575 NAL_UNIT_UNSPEC_0; //for NBR, IDR frames are expected to decode as followed if error decoding an IDR currently575 NAL_UNIT_UNSPEC_0; //for NBR, IDR frames are expected to decode as followed if error decoding an IDR currently
576 576
577 eNalType = m_pDecContext->sCurNalHead.eNalUnitType;577 eNalType = m_pDecContext->sCurNalHead.eNalUnitType;
578 578
579 if (m_pDecContext->iErrorCode & dsOutOfMemory) {579 if (m_pDecContext->iErrorCode & dsOutOfMemory) {
580 if (ResetDecoder())580 if (ResetDecoder())
581 return dsOutOfMemory;581 return dsOutOfMemory;
582 582
583 return dsErrorFree;583 return dsErrorFree;
584 }584 }
585 //for AVC bitstream (excluding AVC with temporal scalability, including TP), as long as error occur, SHOULD notify upper layer key frame loss.585 //for AVC bitstream (excluding AVC with temporal scalability, including TP), as long as error occur, SHOULD notify upper layer key frame loss.
586 if ((IS_PARAM_SETS_NALS (eNalType) || NAL_UNIT_CODED_SLICE_IDR == eNalType) ||586 if ((IS_PARAM_SETS_NALS (eNalType) || NAL_UNIT_CODED_SLICE_IDR == eNalType) ||
587 (VIDEO_BITSTREAM_AVC == m_pDecContext->eVideoType)) {587 (VIDEO_BITSTREAM_AVC == m_pDecContext->eVideoType)) {
588 if (m_pDecContext->pParam->eEcActiveIdc == ERROR_CON_DISABLE) {588 if (m_pDecContext->pParam->eEcActiveIdc == ERROR_CON_DISABLE) {
589#ifdef LONG_TERM_REF589#ifdef LONG_TERM_REF
590 m_pDecContext->bParamSetsLostFlag = true;590 m_pDecContext->bParamSetsLostFlag = true;
591#else591#else
592 m_pDecContext->bReferenceLostAtT0Flag = true;592 m_pDecContext->bReferenceLostAtT0Flag = true;
593#endif593#endif
594 }594 }
595 }595 }
596 596
597 if (m_pDecContext->bPrintFrameErrorTraceFlag) {597 if (m_pDecContext->bPrintFrameErrorTraceFlag) {
598 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "decode failed, failure type:%d \n",598 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "decode failed, failure type:%d \n",
599 m_pDecContext->iErrorCode);599 m_pDecContext->iErrorCode);
600 m_pDecContext->bPrintFrameErrorTraceFlag = false;600 m_pDecContext->bPrintFrameErrorTraceFlag = false;
601 } else {601 } else {
602 m_pDecContext->iIgnoredErrorInfoPacketCount++;602 m_pDecContext->iIgnoredErrorInfoPacketCount++;
603 if (m_pDecContext->iIgnoredErrorInfoPacketCount == INT_MAX) {603 if (m_pDecContext->iIgnoredErrorInfoPacketCount == INT_MAX) {
604 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING, "continuous error reached INT_MAX! Restart as 0.");604 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING, "continuous error reached INT_MAX! Restart as 0.");
605 m_pDecContext->iIgnoredErrorInfoPacketCount = 0;605 m_pDecContext->iIgnoredErrorInfoPacketCount = 0;
606 }606 }
607 }607 }
608 if ((m_pDecContext->pParam->eEcActiveIdc != ERROR_CON_DISABLE) && (pDstInfo->iBufferStatus == 1)) {608 if ((m_pDecContext->pParam->eEcActiveIdc != ERROR_CON_DISABLE) && (pDstInfo->iBufferStatus == 1)) {
609 //TODO after dec status updated609 //TODO after dec status updated
610 m_pDecContext->iErrorCode |= dsDataErrorConcealed;610 m_pDecContext->iErrorCode |= dsDataErrorConcealed;
611 611
612 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;612 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;
613 if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount == 0) { //exceed max value of uint32_t613 if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount == 0) { //exceed max value of uint32_t
614 ResetDecStatNums (&m_pDecContext->sDecoderStatistics);614 ResetDecStatNums (&m_pDecContext->sDecoderStatistics);
615 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;615 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;
616 }616 }
617 int32_t iMbConcealedNum = m_pDecContext->iMbEcedNum + m_pDecContext->iMbEcedPropNum;617 int32_t iMbConcealedNum = m_pDecContext->iMbEcedNum + m_pDecContext->iMbEcedPropNum;
618 m_pDecContext->sDecoderStatistics.uiAvgEcRatio = m_pDecContext->iMbNum == 0 ?618 m_pDecContext->sDecoderStatistics.uiAvgEcRatio = m_pDecContext->iMbNum == 0 ?
619 (m_pDecContext->sDecoderStatistics.uiAvgEcRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) : ((619 (m_pDecContext->sDecoderStatistics.uiAvgEcRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) : ((
620 m_pDecContext->sDecoderStatistics.uiAvgEcRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) + ((620 m_pDecContext->sDecoderStatistics.uiAvgEcRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) + ((
621 iMbConcealedNum * 100) / m_pDecContext->iMbNum));621 iMbConcealedNum * 100) / m_pDecContext->iMbNum));
622 m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio = m_pDecContext->iMbNum == 0 ?622 m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio = m_pDecContext->iMbNum == 0 ?
623 (m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) : ((623 (m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) : ((
624 m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) + ((624 m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) + ((
625 m_pDecContext->iMbEcedPropNum * 100) / m_pDecContext->iMbNum));625 m_pDecContext->iMbEcedPropNum * 100) / m_pDecContext->iMbNum));
626 m_pDecContext->sDecoderStatistics.uiEcFrameNum += (iMbConcealedNum == 0 ? 0 : 1);626 m_pDecContext->sDecoderStatistics.uiEcFrameNum += (iMbConcealedNum == 0 ? 0 : 1);
627 m_pDecContext->sDecoderStatistics.uiAvgEcRatio = m_pDecContext->sDecoderStatistics.uiEcFrameNum == 0 ? 0 :627 m_pDecContext->sDecoderStatistics.uiAvgEcRatio = m_pDecContext->sDecoderStatistics.uiEcFrameNum == 0 ? 0 :
628 m_pDecContext->sDecoderStatistics.uiAvgEcRatio / m_pDecContext->sDecoderStatistics.uiEcFrameNum;628 m_pDecContext->sDecoderStatistics.uiAvgEcRatio / m_pDecContext->sDecoderStatistics.uiEcFrameNum;
629 m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio = m_pDecContext->sDecoderStatistics.uiEcFrameNum == 0 ? 0 :629 m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio = m_pDecContext->sDecoderStatistics.uiEcFrameNum == 0 ? 0 :
630 m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio / m_pDecContext->sDecoderStatistics.uiEcFrameNum;630 m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio / m_pDecContext->sDecoderStatistics.uiEcFrameNum;
631 }631 }
632 iEnd = WelsTime();632 iEnd = WelsTime();
633 m_pDecContext->dDecTime += (iEnd - iStart) / 1e3;633 m_pDecContext->dDecTime += (iEnd - iStart) / 1e3;
634 634
635 OutputStatisticsLog (m_pDecContext->sDecoderStatistics);635 OutputStatisticsLog (m_pDecContext->sDecoderStatistics);
636 636
637#ifdef _PICTURE_REORDERING_637#ifdef _PICTURE_REORDERING_
638 ReorderPicturesInDisplay (ppDst, pDstInfo);638 ReorderPicturesInDisplay (ppDst, pDstInfo);
639#endif639#endif
640 640
641 return (DECODING_STATE)m_pDecContext->iErrorCode;641 return (DECODING_STATE)m_pDecContext->iErrorCode;
642 }642 }
643 // else Error free, the current codec works well643 // else Error free, the current codec works well
644 644
645 if (pDstInfo->iBufferStatus == 1) {645 if (pDstInfo->iBufferStatus == 1) {
646 646
647 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;647 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;
648 if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount == 0) { //exceed max value of uint32_t648 if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount == 0) { //exceed max value of uint32_t
649 ResetDecStatNums (&m_pDecContext->sDecoderStatistics);649 ResetDecStatNums (&m_pDecContext->sDecoderStatistics);
650 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;650 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;
651 }651 }
652 652
653 OutputStatisticsLog (m_pDecContext->sDecoderStatistics);653 OutputStatisticsLog (m_pDecContext->sDecoderStatistics);
654 }654 }
655 iEnd = WelsTime();655 iEnd = WelsTime();
656 m_pDecContext->dDecTime += (iEnd - iStart) / 1e3;656 m_pDecContext->dDecTime += (iEnd - iStart) / 1e3;
657 657
658#ifdef _PICTURE_REORDERING_658#ifdef _PICTURE_REORDERING_
659 ReorderPicturesInDisplay (ppDst, pDstInfo);659 ReorderPicturesInDisplay (ppDst, pDstInfo);
660#endif660#endif
661 return dsErrorFree;661 return dsErrorFree;
662}662}
663 663
664DECODING_STATE CWelsDecoder::FlushFrame (unsigned char** ppDst,664DECODING_STATE CWelsDecoder::FlushFrame (unsigned char** ppDst,
665 SBufferInfo* pDstInfo) {665 SBufferInfo* pDstInfo) {
666 if (m_pDecContext->bEndOfStreamFlag && m_iNumOfPicts > 0) {666 if (m_pDecContext->bEndOfStreamFlag && m_iNumOfPicts > 0) {
667 m_iMinPOC = sIMinInt32;667 m_iMinPOC = sIMinInt32;
668 for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) {668 for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) {
669 if (m_iMinPOC == sIMinInt32 && m_sPictInfoList[i].iPOC > sIMinInt32) {669 if (m_iMinPOC == sIMinInt32 && m_sPictInfoList[i].iPOC > sIMinInt32) {
670 m_iMinPOC = m_sPictInfoList[i].iPOC;670 m_iMinPOC = m_sPictInfoList[i].iPOC;
671 m_iPictInfoIndex = i;671 m_iPictInfoIndex = i;
672 }672 }
673 if (m_sPictInfoList[i].iPOC > sIMinInt32 && m_sPictInfoList[i].iPOC < m_iMinPOC) {673 if (m_sPictInfoList[i].iPOC > sIMinInt32 && m_sPictInfoList[i].iPOC < m_iMinPOC) {
674 m_iMinPOC = m_sPictInfoList[i].iPOC;674 m_iMinPOC = m_sPictInfoList[i].iPOC;
675 m_iPictInfoIndex = i;675 m_iPictInfoIndex = i;
676 }676 }
677 }677 }
678 }678 }
679 if (m_iMinPOC > sIMinInt32) {679 if (m_iMinPOC > sIMinInt32) {
680 m_LastWrittenPOC = m_iMinPOC;680 m_LastWrittenPOC = m_iMinPOC;
681#if defined (_DEBUG)681#if defined (_DEBUG)
682#ifdef _MOTION_VECTOR_DUMP_682#ifdef _MOTION_VECTOR_DUMP_
683 fprintf (stderr, "Output POC: #%d\n", m_LastWrittenPOC);683 fprintf (stderr, "Output POC: #%d\n", m_LastWrittenPOC);
684#endif684#endif
685#endif685#endif
686 memcpy (pDstInfo, &m_sPictInfoList[m_iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo));686 memcpy (pDstInfo, &m_sPictInfoList[m_iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo));
687 ppDst[0] = m_sPictInfoList[m_iPictInfoIndex].pData[0];687 ppDst[0] = m_sPictInfoList[m_iPictInfoIndex].pData[0];
688 ppDst[1] = m_sPictInfoList[m_iPictInfoIndex].pData[1];688 ppDst[1] = m_sPictInfoList[m_iPictInfoIndex].pData[1];
689 ppDst[2] = m_sPictInfoList[m_iPictInfoIndex].pData[2];689 ppDst[2] = m_sPictInfoList[m_iPictInfoIndex].pData[2];
690 m_sPictInfoList[m_iPictInfoIndex].iPOC = sIMinInt32;690 m_sPictInfoList[m_iPictInfoIndex].iPOC = sIMinInt32;
691 m_sPictInfoList[m_iPictInfoIndex].bLastGOP = false;691 m_sPictInfoList[m_iPictInfoIndex].bLastGOP = false;
692 m_iMinPOC = sIMinInt32;692 m_iMinPOC = sIMinInt32;
693 --m_iNumOfPicts;693 --m_iNumOfPicts;
694 }694 }
695 return dsErrorFree;695 return dsErrorFree;
696}696}
697 697
698void CWelsDecoder::OutputStatisticsLog (SDecoderStatistics& sDecoderStatistics) {698void CWelsDecoder::OutputStatisticsLog (SDecoderStatistics& sDecoderStatistics) {
699 if ((sDecoderStatistics.uiDecodedFrameCount > 0) && (sDecoderStatistics.iStatisticsLogInterval > 0)699 if ((sDecoderStatistics.uiDecodedFrameCount > 0) && (sDecoderStatistics.iStatisticsLogInterval > 0)
700 && ((sDecoderStatistics.uiDecodedFrameCount % sDecoderStatistics.iStatisticsLogInterval) == 0)) {700 && ((sDecoderStatistics.uiDecodedFrameCount % sDecoderStatistics.iStatisticsLogInterval) == 0)) {
701 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,701 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
702 "DecoderStatistics: uiWidth=%d, uiHeight=%d, fAverageFrameSpeedInMs=%.1f, fActualAverageFrameSpeedInMs=%.1f, \702 "DecoderStatistics: uiWidth=%d, uiHeight=%d, fAverageFrameSpeedInMs=%.1f, fActualAverageFrameSpeedInMs=%.1f, \
703 uiDecodedFrameCount=%d, uiResolutionChangeTimes=%d, uiIDRCorrectNum=%d, \703 uiDecodedFrameCount=%d, uiResolutionChangeTimes=%d, uiIDRCorrectNum=%d, \
704 uiAvgEcRatio=%d, uiAvgEcPropRatio=%d, uiEcIDRNum=%d, uiEcFrameNum=%d, \704 uiAvgEcRatio=%d, uiAvgEcPropRatio=%d, uiEcIDRNum=%d, uiEcFrameNum=%d, \
705 uiIDRLostNum=%d, uiFreezingIDRNum=%d, uiFreezingNonIDRNum=%d, iAvgLumaQp=%d, \705 uiIDRLostNum=%d, uiFreezingIDRNum=%d, uiFreezingNonIDRNum=%d, iAvgLumaQp=%d, \
706 iSpsReportErrorNum=%d, iSubSpsReportErrorNum=%d, iPpsReportErrorNum=%d, iSpsNoExistNalNum=%d, iSubSpsNoExistNalNum=%d, iPpsNoExistNalNum=%d, \706 iSpsReportErrorNum=%d, iSubSpsReportErrorNum=%d, iPpsReportErrorNum=%d, iSpsNoExistNalNum=%d, iSubSpsNoExistNalNum=%d, iPpsNoExistNalNum=%d, \
707 uiProfile=%d, uiLevel=%d, \707 uiProfile=%d, uiLevel=%d, \
708 iCurrentActiveSpsId=%d, iCurrentActivePpsId=%d,",708 iCurrentActiveSpsId=%d, iCurrentActivePpsId=%d,",
709 sDecoderStatistics.uiWidth,709 sDecoderStatistics.uiWidth,
710 sDecoderStatistics.uiHeight,710 sDecoderStatistics.uiHeight,
711 sDecoderStatistics.fAverageFrameSpeedInMs,711 sDecoderStatistics.fAverageFrameSpeedInMs,
712 sDecoderStatistics.fActualAverageFrameSpeedInMs,712 sDecoderStatistics.fActualAverageFrameSpeedInMs,
713 713
714 sDecoderStatistics.uiDecodedFrameCount,714 sDecoderStatistics.uiDecodedFrameCount,
715 sDecoderStatistics.uiResolutionChangeTimes,715 sDecoderStatistics.uiResolutionChangeTimes,
716 sDecoderStatistics.uiIDRCorrectNum,716 sDecoderStatistics.uiIDRCorrectNum,
717 717
718 sDecoderStatistics.uiAvgEcRatio,718 sDecoderStatistics.uiAvgEcRatio,
719 sDecoderStatistics.uiAvgEcPropRatio,719 sDecoderStatistics.uiAvgEcPropRatio,
720 sDecoderStatistics.uiEcIDRNum,720 sDecoderStatistics.uiEcIDRNum,
721 sDecoderStatistics.uiEcFrameNum,721 sDecoderStatistics.uiEcFrameNum,
722 722
723 sDecoderStatistics.uiIDRLostNum,723 sDecoderStatistics.uiIDRLostNum,
724 sDecoderStatistics.uiFreezingIDRNum,724 sDecoderStatistics.uiFreezingIDRNum,
725 sDecoderStatistics.uiFreezingNonIDRNum,725 sDecoderStatistics.uiFreezingNonIDRNum,
726 sDecoderStatistics.iAvgLumaQp,726 sDecoderStatistics.iAvgLumaQp,
727 727
728 sDecoderStatistics.iSpsReportErrorNum,728 sDecoderStatistics.iSpsReportErrorNum,
729 sDecoderStatistics.iSubSpsReportErrorNum,729 sDecoderStatistics.iSubSpsReportErrorNum,
730 sDecoderStatistics.iPpsReportErrorNum,730 sDecoderStatistics.iPpsReportErrorNum,
731 sDecoderStatistics.iSpsNoExistNalNum,731 sDecoderStatistics.iSpsNoExistNalNum,
732 sDecoderStatistics.iSubSpsNoExistNalNum,732 sDecoderStatistics.iSubSpsNoExistNalNum,
733 sDecoderStatistics.iPpsNoExistNalNum,733 sDecoderStatistics.iPpsNoExistNalNum,
734 734
735 sDecoderStatistics.uiProfile,735 sDecoderStatistics.uiProfile,
736 sDecoderStatistics.uiLevel,736 sDecoderStatistics.uiLevel,
737 737
738 sDecoderStatistics.iCurrentActiveSpsId,738 sDecoderStatistics.iCurrentActiveSpsId,
739 sDecoderStatistics.iCurrentActivePpsId);739 sDecoderStatistics.iCurrentActivePpsId);
740 }740 }
741}741}
742 742
743DECODING_STATE CWelsDecoder::ReorderPicturesInDisplay (unsigned char** ppDst, SBufferInfo* pDstInfo) {743DECODING_STATE CWelsDecoder::ReorderPicturesInDisplay (unsigned char** ppDst, SBufferInfo* pDstInfo) {
744 if (pDstInfo->iBufferStatus == 1 && m_pDecContext->pSps->uiProfileIdc != 66744 if (pDstInfo->iBufferStatus == 1 && m_pDecContext->pSps->uiProfileIdc != 66
745 && m_pDecContext->pPps->bEntropyCodingModeFlag) {745 && m_pDecContext->pPps->bEntropyCodingModeFlag) {
746 if (m_pDecContext->pSliceHeader->iPicOrderCntLsb == 0) {746 if (m_pDecContext->pSliceHeader->iPicOrderCntLsb == 0) {
747 if (m_iNumOfPicts > 0) {747 if (m_iNumOfPicts > 0) {
748 m_iLastGOPRemainPicts = m_iNumOfPicts;748 m_iLastGOPRemainPicts = m_iNumOfPicts;
749 for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) {749 for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) {
750 if (m_sPictInfoList[i].iPOC > sIMinInt32) {750 if (m_sPictInfoList[i].iPOC > sIMinInt32) {
751 m_sPictInfoList[i].bLastGOP = true;751 m_sPictInfoList[i].bLastGOP = true;
752 }752 }
753 }753 }
754 }754 }
755 }755 }
756 for (int32_t i = 0; i < 16; ++i) {756 for (int32_t i = 0; i < 16; ++i) {
757 if (m_sPictInfoList[i].iPOC == sIMinInt32) {757 if (m_sPictInfoList[i].iPOC == sIMinInt32) {
758 memcpy (&m_sPictInfoList[i].sBufferInfo, pDstInfo, sizeof (SBufferInfo));758 memcpy (&m_sPictInfoList[i].sBufferInfo, pDstInfo, sizeof (SBufferInfo));
759 m_sPictInfoList[i].pData[0] = ppDst[0];759 m_sPictInfoList[i].pData[0] = ppDst[0];
760 m_sPictInfoList[i].pData[1] = ppDst[1];760 m_sPictInfoList[i].pData[1] = ppDst[1];
761 m_sPictInfoList[i].pData[2] = ppDst[2];761 m_sPictInfoList[i].pData[2] = ppDst[2];
762 m_sPictInfoList[i].iPOC = m_pDecContext->pSliceHeader->iPicOrderCntLsb;762 m_sPictInfoList[i].iPOC = m_pDecContext->pSliceHeader->iPicOrderCntLsb;
763 m_sPictInfoList[i].iFrameNum = m_pDecContext->pSliceHeader->iFrameNum;763 m_sPictInfoList[i].iFrameNum = m_pDecContext->pSliceHeader->iFrameNum;
764 m_sPictInfoList[i].bLastGOP = false;764 m_sPictInfoList[i].bLastGOP = false;
765 pDstInfo->iBufferStatus = 0;765 pDstInfo->iBufferStatus = 0;
766 ++m_iNumOfPicts;766 ++m_iNumOfPicts;
767 if (i > m_iLargestBufferedPicIndex) {767 if (i > m_iLargestBufferedPicIndex) {
768 m_iLargestBufferedPicIndex = i;768 m_iLargestBufferedPicIndex = i;
769 }769 }
770 break;770 break;
771 }771 }
772 }772 }
773 if (m_iLastGOPRemainPicts > 0) {773 if (m_iLastGOPRemainPicts > 0) {
774 m_iMinPOC = sIMinInt32;774 m_iMinPOC = sIMinInt32;
775 for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) {775 for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) {
776 if (m_iMinPOC == sIMinInt32 && m_sPictInfoList[i].iPOC > sIMinInt32 && m_sPictInfoList[i].bLastGOP) {776 if (m_iMinPOC == sIMinInt32 && m_sPictInfoList[i].iPOC > sIMinInt32 && m_sPictInfoList[i].bLastGOP) {
777 m_iMinPOC = m_sPictInfoList[i].iPOC;777 m_iMinPOC = m_sPictInfoList[i].iPOC;
778 m_iPictInfoIndex = i;778 m_iPictInfoIndex = i;
779 }779 }
780 if (m_sPictInfoList[i].iPOC > sIMinInt32 && m_sPictInfoList[i].iPOC < m_iMinPOC && m_sPictInfoList[i].bLastGOP) {780 if (m_sPictInfoList[i].iPOC > sIMinInt32 && m_sPictInfoList[i].iPOC < m_iMinPOC && m_sPictInfoList[i].bLastGOP) {
781 m_iMinPOC = m_sPictInfoList[i].iPOC;781 m_iMinPOC = m_sPictInfoList[i].iPOC;
782 m_iPictInfoIndex = i;782 m_iPictInfoIndex = i;
783 }783 }
784 }784 }
785 m_LastWrittenPOC = m_iMinPOC;785 m_LastWrittenPOC = m_iMinPOC;
786#if defined (_DEBUG)786#if defined (_DEBUG)
787#ifdef _MOTION_VECTOR_DUMP_787#ifdef _MOTION_VECTOR_DUMP_
788 fprintf (stderr, "Output POC: #%d\n", m_LastWrittenPOC);788 fprintf (stderr, "Output POC: #%d\n", m_LastWrittenPOC);
789#endif789#endif
790#endif790#endif
791 memcpy (pDstInfo, &m_sPictInfoList[m_iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo));791 memcpy (pDstInfo, &m_sPictInfoList[m_iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo));
792 ppDst[0] = m_sPictInfoList[m_iPictInfoIndex].pData[0];792 ppDst[0] = m_sPictInfoList[m_iPictInfoIndex].pData[0];
793 ppDst[1] = m_sPictInfoList[m_iPictInfoIndex].pData[1];793 ppDst[1] = m_sPictInfoList[m_iPictInfoIndex].pData[1];
794 ppDst[2] = m_sPictInfoList[m_iPictInfoIndex].pData[2];794 ppDst[2] = m_sPictInfoList[m_iPictInfoIndex].pData[2];
795 m_sPictInfoList[m_iPictInfoIndex].iPOC = sIMinInt32;795 m_sPictInfoList[m_iPictInfoIndex].iPOC = sIMinInt32;
796 m_sPictInfoList[m_iPictInfoIndex].bLastGOP = false;796 m_sPictInfoList[m_iPictInfoIndex].bLastGOP = false;
797 m_iMinPOC = sIMinInt32;797 m_iMinPOC = sIMinInt32;
798 --m_iNumOfPicts;798 --m_iNumOfPicts;
799 --m_iLastGOPRemainPicts;799 --m_iLastGOPRemainPicts;
800 if (m_iLastGOPRemainPicts == 0) {800 if (m_iLastGOPRemainPicts == 0) {
801 m_LastWrittenPOC = sIMinInt32;801 m_LastWrittenPOC = sIMinInt32;
802 }802 }
803 return dsErrorFree;803 return dsErrorFree;
804 }804 }
805 if (m_iNumOfPicts > 0) {805 if (m_iNumOfPicts > 0) {
806 m_iMinPOC = sIMinInt32;806 m_iMinPOC = sIMinInt32;
807 for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) {807 for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) {
808 if (m_iMinPOC == sIMinInt32 && m_sPictInfoList[i].iPOC > sIMinInt32) {808 if (m_iMinPOC == sIMinInt32 && m_sPictInfoList[i].iPOC > sIMinInt32) {
809 m_iMinPOC = m_sPictInfoList[i].iPOC;809 m_iMinPOC = m_sPictInfoList[i].iPOC;
810 m_iPictInfoIndex = i;810 m_iPictInfoIndex = i;
811 }811 }
812 if (m_sPictInfoList[i].iPOC > sIMinInt32 && m_sPictInfoList[i].iPOC < m_iMinPOC) {812 if (m_sPictInfoList[i].iPOC > sIMinInt32 && m_sPictInfoList[i].iPOC < m_iMinPOC) {
813 m_iMinPOC = m_sPictInfoList[i].iPOC;813 m_iMinPOC = m_sPictInfoList[i].iPOC;
814 m_iPictInfoIndex = i;814 m_iPictInfoIndex = i;
815 }815 }
816 }816 }
817 }817 }
818 if (m_iMinPOC > sIMinInt32) {818 if (m_iMinPOC > sIMinInt32) {
819 if ((m_LastWrittenPOC > sIMinInt32 && m_iMinPOC - m_LastWrittenPOC <= 1)819 if ((m_LastWrittenPOC > sIMinInt32 && m_iMinPOC - m_LastWrittenPOC <= 1)
820 || m_iMinPOC < m_pDecContext->pSliceHeader->iPicOrderCntLsb) {820 || m_iMinPOC < m_pDecContext->pSliceHeader->iPicOrderCntLsb) {
821 m_LastWrittenPOC = m_iMinPOC;821 m_LastWrittenPOC = m_iMinPOC;
822#if defined (_DEBUG)822#if defined (_DEBUG)
823#ifdef _MOTION_VECTOR_DUMP_823#ifdef _MOTION_VECTOR_DUMP_
824 fprintf (stderr, "Output POC: #%d\n", m_LastWrittenPOC);824 fprintf (stderr, "Output POC: #%d\n", m_LastWrittenPOC);
825#endif825#endif
826#endif826#endif
827 memcpy (pDstInfo, &m_sPictInfoList[m_iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo));827 memcpy (pDstInfo, &m_sPictInfoList[m_iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo));
828 ppDst[0] = m_sPictInfoList[m_iPictInfoIndex].pData[0];828 ppDst[0] = m_sPictInfoList[m_iPictInfoIndex].pData[0];
829 ppDst[1] = m_sPictInfoList[m_iPictInfoIndex].pData[1];829 ppDst[1] = m_sPictInfoList[m_iPictInfoIndex].pData[1];
830 ppDst[2] = m_sPictInfoList[m_iPictInfoIndex].pData[2];830 ppDst[2] = m_sPictInfoList[m_iPictInfoIndex].pData[2];
831 m_sPictInfoList[m_iPictInfoIndex].iPOC = sIMinInt32;831 m_sPictInfoList[m_iPictInfoIndex].iPOC = sIMinInt32;
832 m_sPictInfoList[m_iPictInfoIndex].bLastGOP = false;832 m_sPictInfoList[m_iPictInfoIndex].bLastGOP = false;
833 m_iMinPOC = sIMinInt32;833 m_iMinPOC = sIMinInt32;
834 --m_iNumOfPicts;834 --m_iNumOfPicts;
835 return dsErrorFree;835 return dsErrorFree;
836 }836 }
837 }837 }
838 }838 }
839 839
840 return dsErrorFree;840 return dsErrorFree;
841}841}
842 842
843DECODING_STATE CWelsDecoder::DecodeParser (const unsigned char* kpSrc,843DECODING_STATE CWelsDecoder::DecodeParser (const unsigned char* kpSrc,
844 const int kiSrcLen,844 const int kiSrcLen,
845 SParserBsInfo* pDstInfo) {845 SParserBsInfo* pDstInfo) {
846 if (m_pDecContext == NULL || m_pDecContext->pParam == NULL) {846 if (m_pDecContext == NULL || m_pDecContext->pParam == NULL) {
847 if (m_pWelsTrace != NULL) {847 if (m_pWelsTrace != NULL) {
848 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "Call DecodeParser without Initialize.\n");848 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "Call DecodeParser without Initialize.\n");
849 }849 }
850 return dsInitialOptExpected;850 return dsInitialOptExpected;
851 }851 }
852 852
853 if (!m_pDecContext->pParam->bParseOnly) {853 if (!m_pDecContext->pParam->bParseOnly) {
854 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "bParseOnly should be true for this API calling! \n");854 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "bParseOnly should be true for this API calling! \n");
855 m_pDecContext->iErrorCode |= dsInvalidArgument;855 m_pDecContext->iErrorCode |= dsInvalidArgument;
856 return dsInvalidArgument;856 return dsInvalidArgument;
857 }857 }
858 int64_t iEnd, iStart = WelsTime();858 int64_t iEnd, iStart = WelsTime();
859 if (CheckBsBuffer (m_pDecContext, kiSrcLen)) {859 if (CheckBsBuffer (m_pDecContext, kiSrcLen)) {
860 if (ResetDecoder())860 if (ResetDecoder())
861 return dsOutOfMemory;861 return dsOutOfMemory;
862 862
863 return dsErrorFree;863 return dsErrorFree;
864 }864 }
865 if (kiSrcLen > 0 && kpSrc != NULL) {865 if (kiSrcLen > 0 && kpSrc != NULL) {
866#ifdef OUTPUT_BITSTREAM866#ifdef OUTPUT_BITSTREAM
867 if (m_pFBS) {867 if (m_pFBS) {
868 WelsFwrite (kpSrc, sizeof (unsigned char), kiSrcLen, m_pFBS);868 WelsFwrite (kpSrc, sizeof (unsigned char), kiSrcLen, m_pFBS);
869 WelsFflush (m_pFBS);869 WelsFflush (m_pFBS);
870 }870 }
871#endif//OUTPUT_BIT_STREAM871#endif//OUTPUT_BIT_STREAM
872 m_pDecContext->bEndOfStreamFlag = false;872 m_pDecContext->bEndOfStreamFlag = false;
873 } else {873 } else {
874 //For application MODE, the error detection should be added for safe.874 //For application MODE, the error detection should be added for safe.
875 //But for CONSOLE MODE, when decoding LAST AU, kiSrcLen==0 && kpSrc==NULL.875 //But for CONSOLE MODE, when decoding LAST AU, kiSrcLen==0 && kpSrc==NULL.
876 m_pDecContext->bEndOfStreamFlag = true;876 m_pDecContext->bEndOfStreamFlag = true;
877 m_pDecContext->bInstantDecFlag = true;877 m_pDecContext->bInstantDecFlag = true;
878 }878 }
879 879
880 m_pDecContext->iErrorCode = dsErrorFree; //initialize at the starting of AU decoding.880 m_pDecContext->iErrorCode = dsErrorFree; //initialize at the starting of AU decoding.
881 m_pDecContext->pParam->eEcActiveIdc = ERROR_CON_DISABLE; //add protection to disable EC here.881 m_pDecContext->pParam->eEcActiveIdc = ERROR_CON_DISABLE; //add protection to disable EC here.
882 m_pDecContext->iFeedbackNalRefIdc = -1; //initialize882 m_pDecContext->iFeedbackNalRefIdc = -1; //initialize
883 if (!m_pDecContext->bFramePending) { //frame complete883 if (!m_pDecContext->bFramePending) { //frame complete
884 m_pDecContext->pParserBsInfo->iNalNum = 0;884 m_pDecContext->pParserBsInfo->iNalNum = 0;
885 memset (m_pDecContext->pParserBsInfo->pNalLenInByte, 0, MAX_NAL_UNITS_IN_LAYER);885 memset (m_pDecContext->pParserBsInfo->pNalLenInByte, 0, MAX_NAL_UNITS_IN_LAYER);
886 }886 }
887 pDstInfo->iNalNum = 0;887 pDstInfo->iNalNum = 0;
888 pDstInfo->iSpsWidthInPixel = pDstInfo->iSpsHeightInPixel = 0;888 pDstInfo->iSpsWidthInPixel = pDstInfo->iSpsHeightInPixel = 0;
889 if (pDstInfo) {889 if (pDstInfo) {
890 m_pDecContext->uiTimeStamp = pDstInfo->uiInBsTimeStamp;890 m_pDecContext->uiTimeStamp = pDstInfo->uiInBsTimeStamp;
891 pDstInfo->uiOutBsTimeStamp = 0;891 pDstInfo->uiOutBsTimeStamp = 0;
892 } else {892 } else {
893 m_pDecContext->uiTimeStamp = 0;893 m_pDecContext->uiTimeStamp = 0;
894 }894 }
895 WelsDecodeBs (m_pDecContext, kpSrc, kiSrcLen, NULL, NULL, pDstInfo);895 WelsDecodeBs (m_pDecContext, kpSrc, kiSrcLen, NULL, NULL, pDstInfo);
896 if (m_pDecContext->iErrorCode & dsOutOfMemory) {896 if (m_pDecContext->iErrorCode & dsOutOfMemory) {
897 if (ResetDecoder())897 if (ResetDecoder())
898 return dsOutOfMemory;898 return dsOutOfMemory;
899 return dsErrorFree;899 return dsErrorFree;
900 }900 }
901 901
902 if (!m_pDecContext->bFramePending && m_pDecContext->pParserBsInfo->iNalNum) {902 if (!m_pDecContext->bFramePending && m_pDecContext->pParserBsInfo->iNalNum) {
903 memcpy (pDstInfo, m_pDecContext->pParserBsInfo, sizeof (SParserBsInfo));903 memcpy (pDstInfo, m_pDecContext->pParserBsInfo, sizeof (SParserBsInfo));
904 904
905 if (m_pDecContext->iErrorCode == ERR_NONE) { //update statistics: decoding frame count905 if (m_pDecContext->iErrorCode == ERR_NONE) { //update statistics: decoding frame count
906 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;906 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;
907 if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount == 0) { //exceed max value of uint32_t907 if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount == 0) { //exceed max value of uint32_t
908 ResetDecStatNums (&m_pDecContext->sDecoderStatistics);908 ResetDecStatNums (&m_pDecContext->sDecoderStatistics);
909 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;909 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;
910 }910 }
911 }911 }
912 }912 }
913 913
914 m_pDecContext->bInstantDecFlag = false; //reset no-delay flag914 m_pDecContext->bInstantDecFlag = false; //reset no-delay flag
915 915
916 if (m_pDecContext->iErrorCode && m_pDecContext->bPrintFrameErrorTraceFlag) {916 if (m_pDecContext->iErrorCode && m_pDecContext->bPrintFrameErrorTraceFlag) {
917 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "decode failed, failure type:%d \n", m_pDecContext->iErrorCode);917 WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "decode failed, failure type:%d \n", m_pDecContext->iErrorCode);
918 m_pDecContext->bPrintFrameErrorTraceFlag = false;918 m_pDecContext->bPrintFrameErrorTraceFlag = false;
919 }919 }
920 iEnd = WelsTime();920 iEnd = WelsTime();
921 m_pDecContext->dDecTime += (iEnd - iStart) / 1e3;921 m_pDecContext->dDecTime += (iEnd - iStart) / 1e3;
922 922
923 return (DECODING_STATE) m_pDecContext->iErrorCode;923 return (DECODING_STATE) m_pDecContext->iErrorCode;
924}924}
925 925
926DECODING_STATE CWelsDecoder::DecodeFrame (const unsigned char* kpSrc,926DECODING_STATE CWelsDecoder::DecodeFrame (const unsigned char* kpSrc,
927 const int kiSrcLen,927 const int kiSrcLen,
928 unsigned char** ppDst,928 unsigned char** ppDst,
929 int* pStride,929 int* pStride,
930 int& iWidth,930 int& iWidth,
931 int& iHeight) {931 int& iHeight) {
932 DECODING_STATE eDecState = dsErrorFree;932 DECODING_STATE eDecState = dsErrorFree;
933 SBufferInfo DstInfo;933 SBufferInfo DstInfo;
934 934
935 memset (&DstInfo, 0, sizeof (SBufferInfo));935 memset (&DstInfo, 0, sizeof (SBufferInfo));
936 DstInfo.UsrData.sSystemBuffer.iStride[0] = pStride[0];936 DstInfo.UsrData.sSystemBuffer.iStride[0] = pStride[0];
937 DstInfo.UsrData.sSystemBuffer.iStride[1] = pStride[1];937 DstInfo.UsrData.sSystemBuffer.iStride[1] = pStride[1];
938 DstInfo.UsrData.sSystemBuffer.iWidth = iWidth;938 DstInfo.UsrData.sSystemBuffer.iWidth = iWidth;
939 DstInfo.UsrData.sSystemBuffer.iHeight = iHeight;939 DstInfo.UsrData.sSystemBuffer.iHeight = iHeight;
940 940
941 eDecState = DecodeFrame2 (kpSrc, kiSrcLen, ppDst, &DstInfo);941 eDecState = DecodeFrame2 (kpSrc, kiSrcLen, ppDst, &DstInfo);
942 if (eDecState == dsErrorFree) {942 if (eDecState == dsErrorFree) {
943 pStride[0] = DstInfo.UsrData.sSystemBuffer.iStride[0];943 pStride[0] = DstInfo.UsrData.sSystemBuffer.iStride[0];
944 pStride[1] = DstInfo.UsrData.sSystemBuffer.iStride[1];944 pStride[1] = DstInfo.UsrData.sSystemBuffer.iStride[1];
945 iWidth = DstInfo.UsrData.sSystemBuffer.iWidth;945 iWidth = DstInfo.UsrData.sSystemBuffer.iWidth;
946 iHeight = DstInfo.UsrData.sSystemBuffer.iHeight;946 iHeight = DstInfo.UsrData.sSystemBuffer.iHeight;
947 }947 }
948 948
949 return eDecState;949 return eDecState;
950}950}
951 951
952DECODING_STATE CWelsDecoder::DecodeFrameEx (const unsigned char* kpSrc,952DECODING_STATE CWelsDecoder::DecodeFrameEx (const unsigned char* kpSrc,
953 const int kiSrcLen,953 const int kiSrcLen,
954 unsigned char* pDst,954 unsigned char* pDst,
955 int iDstStride,955 int iDstStride,
956 int& iDstLen,956 int& iDstLen,
957 int& iWidth,957 int& iWidth,
958 int& iHeight,958 int& iHeight,
959 int& iColorFormat) {959 int& iColorFormat) {
960 DECODING_STATE state = dsErrorFree;960 DECODING_STATE state = dsErrorFree;
961 961
962 return state;962 return state;
963}963}
964 964
965 965
966} // namespace WelsDec966} // namespace WelsDec
967 967
968 968
969using namespace WelsDec;969using namespace WelsDec;
970/*970/*
971* WelsGetDecoderCapability971* WelsGetDecoderCapability
972* @return: DecCapability information972* @return: DecCapability information
973*/973*/
974int WelsGetDecoderCapability (SDecoderCapability* pDecCapability) {974int WelsGetDecoderCapability (SDecoderCapability* pDecCapability) {
975 memset (pDecCapability, 0, sizeof (SDecoderCapability));975 memset (pDecCapability, 0, sizeof (SDecoderCapability));
976 pDecCapability->iProfileIdc = 66; //Baseline976 pDecCapability->iProfileIdc = 66; //Baseline
977 pDecCapability->iProfileIop = 0xE0; //11100000b977 pDecCapability->iProfileIop = 0xE0; //11100000b
978 pDecCapability->iLevelIdc = 32; //level_idc = 3.2978 pDecCapability->iLevelIdc = 32; //level_idc = 3.2
979 pDecCapability->iMaxMbps = 216000; //from level_idc = 3.2979 pDecCapability->iMaxMbps = 216000; //from level_idc = 3.2
980 pDecCapability->iMaxFs = 5120; //from level_idc = 3.2980 pDecCapability->iMaxFs = 5120; //from level_idc = 3.2
981 pDecCapability->iMaxCpb = 20000; //from level_idc = 3.2981 pDecCapability->iMaxCpb = 20000; //from level_idc = 3.2
982 pDecCapability->iMaxDpb = 20480; //from level_idc = 3.2982 pDecCapability->iMaxDpb = 20480; //from level_idc = 3.2
983 pDecCapability->iMaxBr = 20000; //from level_idc = 3.2983 pDecCapability->iMaxBr = 20000; //from level_idc = 3.2
984 pDecCapability->bRedPicCap = 0; //not support redundant pic984 pDecCapability->bRedPicCap = 0; //not support redundant pic
985 985
986 return ERR_NONE;986 return ERR_NONE;
987}987}
988/* WINAPI is indeed in prefix due to sync to application layer callings!! */988/* WINAPI is indeed in prefix due to sync to application layer callings!! */
989 989
990/*990/*
991* WelsCreateDecoder991* WelsCreateDecoder
992* @return: success in return 0, otherwise failed.992* @return: success in return 0, otherwise failed.
993*/993*/
994long WelsCreateDecoder (ISVCDecoder** ppDecoder) {994long WelsCreateDecoder (ISVCDecoder** ppDecoder) {
995 995
996 if (NULL == ppDecoder) {996 if (NULL == ppDecoder) {
997 return ERR_INVALID_PARAMETERS;997 return ERR_INVALID_PARAMETERS;
998 }998 }
999 999
1000 *ppDecoder = new CWelsDecoder();1000 *ppDecoder = new CWelsDecoder();
1001 1001
1002 if (NULL == *ppDecoder) {1002 if (NULL == *ppDecoder) {
1003 return ERR_MALLOC_FAILED;1003 return ERR_MALLOC_FAILED;
1004 }1004 }
1005 1005
1006 return ERR_NONE;1006 return ERR_NONE;
1007}1007}
1008 1008
1009/*1009/*
1010* WelsDestroyDecoder1010* WelsDestroyDecoder
1011*/1011*/
1012void WelsDestroyDecoder (ISVCDecoder* pDecoder) {1012void WelsDestroyDecoder (ISVCDecoder* pDecoder) {
1013 if (NULL != pDecoder) {1013 if (NULL != pDecoder) {
1014 delete (CWelsDecoder*)pDecoder;1014 delete (CWelsDecoder*)pDecoder;
1015 }1015 }
1016}1016}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t