Some newlines were fixed in "Merge pull request #2997 from GuangweiWang/fix-issue-external", but lots were still left behind.
Showing the changes to codec/decoder (7 of 14 files). Show all
Unified · Split
| @@ -1,156 +1,156 @@ | ||
| 1 | −/*! | |
| 2 | − * \copy | |
| 3 | − * Copyright (c) 2013, Cisco Systems | |
| 4 | − * All rights reserved. | |
| 5 | − * | |
| 6 | − * Redistribution and use in source and binary forms, with or without | |
| 7 | − * modification, are permitted provided that the following conditions | |
| 8 | − * are met: | |
| 9 | − * | |
| 10 | − * * Redistributions of source code must retain the above copyright | |
| 11 | − * notice, this list of conditions and the following disclaimer. | |
| 12 | − * | |
| 13 | − * * Redistributions in binary form must reproduce the above copyright | |
| 14 | − * notice, this list of conditions and the following disclaimer in | |
| 15 | − * the documentation and/or other materials provided with the | |
| 16 | − * distribution. | |
| 17 | − * | |
| 18 | − * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 | − * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 | − * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 21 | − * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 22 | − * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 23 | − * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 24 | − * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 | − * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 26 | − * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 | − * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
| 28 | − * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | − * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | − * | |
| 31 | − */ | |
| 32 | − | |
| 33 | −//dec_frame.h | |
| 34 | −#ifndef WELS_DEC_FRAME_H__ | |
| 35 | −#define WELS_DEC_FRAME_H__ | |
| 36 | − | |
| 37 | −#include "typedefs.h" | |
| 38 | −#include "wels_const.h" | |
| 39 | −#include "wels_common_basis.h" | |
| 40 | −#include "parameter_sets.h" | |
| 41 | −#include "nal_prefix.h" | |
| 42 | −#include "slice.h" | |
| 43 | −#include "picture.h" | |
| 44 | −#include "bit_stream.h" | |
| 45 | −#include "fmo.h" | |
| 46 | − | |
| 47 | −namespace WelsDec { | |
| 48 | − | |
| 49 | −///////////////////////////////////DQ Layer level/////////////////////////////////// | |
| 50 | −typedef struct TagDqLayer SDqLayer; | |
| 51 | −typedef SDqLayer* PDqLayer; | |
| 52 | −typedef struct TagLayerInfo { | |
| 53 | − SNalUnitHeaderExt sNalHeaderExt; | |
| 54 | − SSlice sSliceInLayer; // Here Slice identify to Frame on concept | |
| 55 | − PSubsetSps pSubsetSps; // current pSubsetSps used, memory alloc in external | |
| 56 | − PSps pSps; // current sps based avc used, memory alloc in external | |
| 57 | − PPps pPps; // current pps used | |
| 58 | −} SLayerInfo, *PLayerInfo; | |
| 59 | −/* Layer Representation */ | |
| 60 | − | |
| 61 | −struct TagDqLayer { | |
| 62 | − SLayerInfo sLayerInfo; | |
| 63 | − | |
| 64 | − PBitStringAux pBitStringAux; // pointer to SBitStringAux | |
| 65 | − PFmo pFmo; // Current fmo context pointer used | |
| 66 | − uint32_t* pMbType; | |
| 67 | − int32_t* pSliceIdc; // using int32_t for slice_idc | |
| 68 | − int16_t (*pMv[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]; | |
| 71 | − int8_t (*pDirect)[MB_BLOCK4x4_NUM]; | |
| 72 | − bool* pNoSubMbPartSizeLessThan8x8Flag; | |
| 73 | − bool* pTransformSize8x8Flag; | |
| 74 | − int8_t* pLumaQp; | |
| 75 | − int8_t (*pChromaQp)[2]; | |
| 76 | − int8_t* pCbp; | |
| 77 | − uint16_t *pCbfDc; | |
| 78 | − int8_t (*pNzc)[24]; | |
| 79 | − int8_t (*pNzcRs)[24]; | |
| 80 | − int8_t* pResidualPredFlag; | |
| 81 | − int8_t* pInterPredictionDoneFlag; | |
| 82 | − bool* pMbCorrectlyDecodedFlag; | |
| 83 | − bool* pMbRefConcealedFlag; | |
| 84 | − int16_t (*pScaledTCoeff)[MB_COEFF_LIST_SIZE]; | |
| 85 | − int8_t (*pIntraPredMode)[8]; //0~3 top4x4 ; 4~6 left 4x4; 7 intra16x16 | |
| 86 | − int8_t (*pIntra4x4FinalMode)[MB_BLOCK4x4_NUM]; | |
| 87 | − uint8_t *pIntraNxNAvailFlag; | |
| 88 | − int8_t* pChromaPredMode; | |
| 89 | − //uint8_t (*motion_pred_flag[LIST_A])[MB_PARTITION_SIZE]; // 8x8 | |
| 90 | − uint32_t (*pSubMbType)[MB_SUB_PARTITION_SIZE]; | |
| 91 | − int32_t iLumaStride; | |
| 92 | − int32_t iChromaStride; | |
| 93 | − uint8_t* pPred[3]; | |
| 94 | − int32_t iMbX; | |
| 95 | − int32_t iMbY; | |
| 96 | − int32_t iMbXyIndex; | |
| 97 | − 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; | |
| 99 | − | |
| 100 | − /* Common syntax elements across all slices of a DQLayer */ | |
| 101 | − int32_t iSliceIdcBackup; | |
| 102 | − uint32_t uiSpsId; | |
| 103 | − uint32_t uiPpsId; | |
| 104 | − uint32_t uiDisableInterLayerDeblockingFilterIdc; | |
| 105 | − int32_t iInterLayerSliceAlphaC0Offset; | |
| 106 | − int32_t iInterLayerSliceBetaOffset; | |
| 107 | − //SPosOffset sScaledRefLayer; | |
| 108 | − int32_t iSliceGroupChangeCycle; | |
| 109 | − | |
| 110 | − PRefPicListReorderSyn pRefPicListReordering; | |
| 111 | − PPredWeightTabSyn pPredWeightTable; | |
| 112 | − PRefPicMarking pRefPicMarking; // Decoded reference picture marking syntaxs | |
| 113 | − PRefBasePicMarking pRefPicBaseMarking; | |
| 114 | − | |
| 115 | − PPicture pRef; // reference picture pointer | |
| 116 | − PPicture pDec; // reconstruction picture pointer for layer | |
| 117 | − | |
| 118 | − int16_t iColocMv[2][16][2]; //Colocated MV cache | |
| 119 | − int8_t iColocRefIndex[2][16]; //Colocated RefIndex cache | |
| 120 | − int8_t iColocIntra[16]; //Colocated Intra cache | |
| 121 | − | |
| 122 | − bool bUseWeightPredictionFlag; | |
| 123 | − bool bUseWeightedBiPredIdc; | |
| 124 | − bool bStoreRefBasePicFlag; // iCurTid == 0 && iCurQid = 0 && bEncodeKeyPic = 1 | |
| 125 | − bool bTCoeffLevelPredFlag; | |
| 126 | − bool bConstrainedIntraResamplingFlag; | |
| 127 | − uint8_t uiRefLayerDqId; | |
| 128 | − uint8_t uiRefLayerChromaPhaseXPlus1Flag; | |
| 129 | − uint8_t uiRefLayerChromaPhaseYPlus1; | |
| 130 | − uint8_t uiLayerDqId; // dq_id of current layer | |
| 131 | − bool bUseRefBasePicFlag; // whether reference pic or reference base pic is referred? | |
| 132 | −}; | |
| 133 | − | |
| 134 | −typedef struct TagGpuAvcLayer { | |
| 135 | − SLayerInfo sLayerInfo; | |
| 136 | − PBitStringAux pBitStringAux; // pointer to SBitStringAux | |
| 137 | − | |
| 138 | − uint32_t* pMbType; | |
| 139 | − int32_t* pSliceIdc; // using int32_t for slice_idc | |
| 140 | − int8_t* pLumaQp; | |
| 141 | − int8_t* pCbp; | |
| 142 | − int8_t (*pNzc)[24]; | |
| 143 | − int8_t (*pIntraPredMode)[8]; //0~3 top4x4 ; 4~6 left 4x4; 7 intra16x16 | |
| 144 | − int32_t iMbX; | |
| 145 | − int32_t iMbY; | |
| 146 | − int32_t iMbXyIndex; | |
| 147 | − 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; | |
| 149 | − | |
| 150 | −} SGpuAvcDqLayer, *PGpuAvcDqLayer; | |
| 151 | − | |
| 152 | −/////////////////////////////////////////////////////////////////////// | |
| 153 | − | |
| 154 | −} // namespace WelsDec | |
| 155 | − | |
| 156 | −#endif//WELS_DEC_FRAME_H__ | |
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 2013, Cisco Systems | |
| 4 | + * All rights reserved. | |
| 5 | + * | |
| 6 | + * Redistribution and use in source and binary forms, with or without | |
| 7 | + * modification, are permitted provided that the following conditions | |
| 8 | + * are met: | |
| 9 | + * | |
| 10 | + * * Redistributions of source code must retain the above copyright | |
| 11 | + * notice, this list of conditions and the following disclaimer. | |
| 12 | + * | |
| 13 | + * * Redistributions in binary form must reproduce the above copyright | |
| 14 | + * notice, this list of conditions and the following disclaimer in | |
| 15 | + * the documentation and/or other materials provided with the | |
| 16 | + * distribution. | |
| 17 | + * | |
| 18 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 21 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 22 | + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 23 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 26 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
| 28 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | + * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | + * | |
| 31 | + */ | |
| 32 | + | |
| 33 | +//dec_frame.h | |
| 34 | +#ifndef WELS_DEC_FRAME_H__ | |
| 35 | +#define WELS_DEC_FRAME_H__ | |
| 36 | + | |
| 37 | +#include "typedefs.h" | |
| 38 | +#include "wels_const.h" | |
| 39 | +#include "wels_common_basis.h" | |
| 40 | +#include "parameter_sets.h" | |
| 41 | +#include "nal_prefix.h" | |
| 42 | +#include "slice.h" | |
| 43 | +#include "picture.h" | |
| 44 | +#include "bit_stream.h" | |
| 45 | +#include "fmo.h" | |
| 46 | + | |
| 47 | +namespace WelsDec { | |
| 48 | + | |
| 49 | +///////////////////////////////////DQ Layer level/////////////////////////////////// | |
| 50 | +typedef struct TagDqLayer SDqLayer; | |
| 51 | +typedef SDqLayer* PDqLayer; | |
| 52 | +typedef struct TagLayerInfo { | |
| 53 | + SNalUnitHeaderExt sNalHeaderExt; | |
| 54 | + SSlice sSliceInLayer; // Here Slice identify to Frame on concept | |
| 55 | + PSubsetSps pSubsetSps; // current pSubsetSps used, memory alloc in external | |
| 56 | + PSps pSps; // current sps based avc used, memory alloc in external | |
| 57 | + PPps pPps; // current pps used | |
| 58 | +} SLayerInfo, *PLayerInfo; | |
| 59 | +/* Layer Representation */ | |
| 60 | + | |
| 61 | +struct TagDqLayer { | |
| 62 | + SLayerInfo sLayerInfo; | |
| 63 | + | |
| 64 | + PBitStringAux pBitStringAux; // pointer to SBitStringAux | |
| 65 | + PFmo pFmo; // Current fmo context pointer used | |
| 66 | + uint32_t* pMbType; | |
| 67 | + int32_t* pSliceIdc; // using int32_t for slice_idc | |
| 68 | + int16_t (*pMv[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]; | |
| 71 | + int8_t (*pDirect)[MB_BLOCK4x4_NUM]; | |
| 72 | + bool* pNoSubMbPartSizeLessThan8x8Flag; | |
| 73 | + bool* pTransformSize8x8Flag; | |
| 74 | + int8_t* pLumaQp; | |
| 75 | + int8_t (*pChromaQp)[2]; | |
| 76 | + int8_t* pCbp; | |
| 77 | + uint16_t *pCbfDc; | |
| 78 | + int8_t (*pNzc)[24]; | |
| 79 | + int8_t (*pNzcRs)[24]; | |
| 80 | + int8_t* pResidualPredFlag; | |
| 81 | + int8_t* pInterPredictionDoneFlag; | |
| 82 | + bool* pMbCorrectlyDecodedFlag; | |
| 83 | + bool* pMbRefConcealedFlag; | |
| 84 | + int16_t (*pScaledTCoeff)[MB_COEFF_LIST_SIZE]; | |
| 85 | + int8_t (*pIntraPredMode)[8]; //0~3 top4x4 ; 4~6 left 4x4; 7 intra16x16 | |
| 86 | + int8_t (*pIntra4x4FinalMode)[MB_BLOCK4x4_NUM]; | |
| 87 | + uint8_t *pIntraNxNAvailFlag; | |
| 88 | + int8_t* pChromaPredMode; | |
| 89 | + //uint8_t (*motion_pred_flag[LIST_A])[MB_PARTITION_SIZE]; // 8x8 | |
| 90 | + uint32_t (*pSubMbType)[MB_SUB_PARTITION_SIZE]; | |
| 91 | + int32_t iLumaStride; | |
| 92 | + int32_t iChromaStride; | |
| 93 | + uint8_t* pPred[3]; | |
| 94 | + int32_t iMbX; | |
| 95 | + int32_t iMbY; | |
| 96 | + int32_t iMbXyIndex; | |
| 97 | + 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; | |
| 99 | + | |
| 100 | + /* Common syntax elements across all slices of a DQLayer */ | |
| 101 | + int32_t iSliceIdcBackup; | |
| 102 | + uint32_t uiSpsId; | |
| 103 | + uint32_t uiPpsId; | |
| 104 | + uint32_t uiDisableInterLayerDeblockingFilterIdc; | |
| 105 | + int32_t iInterLayerSliceAlphaC0Offset; | |
| 106 | + int32_t iInterLayerSliceBetaOffset; | |
| 107 | + //SPosOffset sScaledRefLayer; | |
| 108 | + int32_t iSliceGroupChangeCycle; | |
| 109 | + | |
| 110 | + PRefPicListReorderSyn pRefPicListReordering; | |
| 111 | + PPredWeightTabSyn pPredWeightTable; | |
| 112 | + PRefPicMarking pRefPicMarking; // Decoded reference picture marking syntaxs | |
| 113 | + PRefBasePicMarking pRefPicBaseMarking; | |
| 114 | + | |
| 115 | + PPicture pRef; // reference picture pointer | |
| 116 | + PPicture pDec; // reconstruction picture pointer for layer | |
| 117 | + | |
| 118 | + int16_t iColocMv[2][16][2]; //Colocated MV cache | |
| 119 | + int8_t iColocRefIndex[2][16]; //Colocated RefIndex cache | |
| 120 | + int8_t iColocIntra[16]; //Colocated Intra cache | |
| 121 | + | |
| 122 | + bool bUseWeightPredictionFlag; | |
| 123 | + bool bUseWeightedBiPredIdc; | |
| 124 | + bool bStoreRefBasePicFlag; // iCurTid == 0 && iCurQid = 0 && bEncodeKeyPic = 1 | |
| 125 | + bool bTCoeffLevelPredFlag; | |
| 126 | + bool bConstrainedIntraResamplingFlag; | |
| 127 | + uint8_t uiRefLayerDqId; | |
| 128 | + uint8_t uiRefLayerChromaPhaseXPlus1Flag; | |
| 129 | + uint8_t uiRefLayerChromaPhaseYPlus1; | |
| 130 | + uint8_t uiLayerDqId; // dq_id of current layer | |
| 131 | + bool bUseRefBasePicFlag; // whether reference pic or reference base pic is referred? | |
| 132 | +}; | |
| 133 | + | |
| 134 | +typedef struct TagGpuAvcLayer { | |
| 135 | + SLayerInfo sLayerInfo; | |
| 136 | + PBitStringAux pBitStringAux; // pointer to SBitStringAux | |
| 137 | + | |
| 138 | + uint32_t* pMbType; | |
| 139 | + int32_t* pSliceIdc; // using int32_t for slice_idc | |
| 140 | + int8_t* pLumaQp; | |
| 141 | + int8_t* pCbp; | |
| 142 | + int8_t (*pNzc)[24]; | |
| 143 | + int8_t (*pIntraPredMode)[8]; //0~3 top4x4 ; 4~6 left 4x4; 7 intra16x16 | |
| 144 | + int32_t iMbX; | |
| 145 | + int32_t iMbY; | |
| 146 | + int32_t iMbXyIndex; | |
| 147 | + 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; | |
| 149 | + | |
| 150 | +} SGpuAvcDqLayer, *PGpuAvcDqLayer; | |
| 151 | + | |
| 152 | +/////////////////////////////////////////////////////////////////////// | |
| 153 | + | |
| 154 | +} // namespace WelsDec | |
| 155 | + | |
| 156 | +#endif//WELS_DEC_FRAME_H__ | |
| @@ -1,1383 +1,1383 @@ | ||
| 1 | −/*! | |
| 2 | − * \copy | |
| 3 | − * Copyright (c) 2010-2013, Cisco Systems | |
| 4 | − * All rights reserved. | |
| 5 | − * | |
| 6 | − * Redistribution and use in source and binary forms, with or without | |
| 7 | − * modification, are permitted provided that the following conditions | |
| 8 | − * are met: | |
| 9 | − * | |
| 10 | − * * Redistributions of source code must retain the above copyright | |
| 11 | − * notice, this list of conditions and the following disclaimer. | |
| 12 | − * | |
| 13 | − * * Redistributions in binary form must reproduce the above copyright | |
| 14 | − * notice, this list of conditions and the following disclaimer in | |
| 15 | − * the documentation and/or other materials provided with the | |
| 16 | − * distribution. | |
| 17 | − * | |
| 18 | − * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 | − * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 | − * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 21 | − * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 22 | − * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 23 | − * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 24 | − * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 | − * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 26 | − * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 | − * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
| 28 | − * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | − * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | − * | |
| 31 | − * | |
| 32 | − * \file deblocking.c | |
| 33 | − * | |
| 34 | − * \brief Interfaces introduced in frame deblocking filtering | |
| 35 | − * | |
| 36 | − * \date 08/02/2010 | |
| 37 | − * | |
| 38 | − ************************************************************************************* | |
| 39 | − */ | |
| 40 | − | |
| 41 | −#include "deblocking.h" | |
| 42 | −#include "deblocking_common.h" | |
| 43 | −#include "cpu_core.h" | |
| 44 | − | |
| 45 | −namespace WelsDec { | |
| 46 | − | |
| 47 | −#define NO_SUPPORTED_FILTER_IDX (-1) | |
| 48 | −#define LEFT_FLAG_BIT 0 | |
| 49 | −#define TOP_FLAG_BIT 1 | |
| 50 | −#define LEFT_FLAG_MASK 0x01 | |
| 51 | −#define TOP_FLAG_MASK 0x02 | |
| 52 | − | |
| 53 | −#define SAME_MB_DIFF_REFIDX | |
| 54 | −#define g_kuiAlphaTable(x) g_kuiAlphaTable[(x)+12] | |
| 55 | −#define g_kiBetaTable(x) g_kiBetaTable[(x)+12] | |
| 56 | −#define g_kiTc0Table(x) g_kiTc0Table[(x)+12] | |
| 57 | − | |
| 58 | −#define MB_BS_MV(iRefIndex, iMotionVector, iMbXy, iMbBn, iIndex, iNeighIndex) \ | |
| 59 | −(\ | |
| 60 | − ( iRefIndex[iMbXy][iIndex] - iRefIndex[iMbBn][iNeighIndex] )||\ | |
| 61 | − ( WELS_ABS( iMotionVector[iMbXy][iIndex][0] - iMotionVector[iMbBn][iNeighIndex][0] ) >= 4 ) ||\ | |
| 62 | − ( WELS_ABS( iMotionVector[iMbXy][iIndex][1] - iMotionVector[iMbBn][iNeighIndex][1] ) >= 4 )\ | |
| 63 | −) | |
| 64 | − | |
| 65 | −#if defined(SAME_MB_DIFF_REFIDX) | |
| 66 | −#define SMB_EDGE_MV(iRefIndex, iMotionVector, iIndex, iNeighIndex) \ | |
| 67 | −(\ | |
| 68 | − ( iRefIndex[iIndex] - iRefIndex[iNeighIndex] )||(\ | |
| 69 | − ( WELS_ABS( iMotionVector[iIndex][0] - iMotionVector[iNeighIndex][0] ) &(~3) ) |\ | |
| 70 | − ( WELS_ABS( iMotionVector[iIndex][1] - iMotionVector[iNeighIndex][1] ) &(~3) ))\ | |
| 71 | −) | |
| 72 | −#else | |
| 73 | −#define SMB_EDGE_MV(iRefIndex, iMotionVector, iIndex, iNeighIndex) \ | |
| 74 | −(\ | |
| 75 | − !!(( WELS_ABS( iMotionVector[iIndex][0] - iMotionVector[iNeighIndex][0] ) &(~3) ) |( WELS_ABS( iMotionVector[iIndex][1] - iMotionVector[iNeighIndex][1] ) &(~3) ))\ | |
| 76 | −) | |
| 77 | −#endif | |
| 78 | − | |
| 79 | −#define BS_EDGE(bsx1, iRefIndex, iMotionVector, iIndex, iNeighIndex) \ | |
| 80 | −( (bsx1|SMB_EDGE_MV(iRefIndex, iMotionVector, iIndex, iNeighIndex))<<((uint8_t)(!!bsx1))) | |
| 81 | − | |
| 82 | −#define GET_ALPHA_BETA_FROM_QP(iQp, iAlphaOffset, iBetaOffset, iIndex, iAlpha, iBeta) \ | |
| 83 | −{\ | |
| 84 | − iIndex = (iQp + iAlphaOffset);\ | |
| 85 | − iAlpha = g_kuiAlphaTable(iIndex);\ | |
| 86 | − iBeta = g_kiBetaTable((iQp + iBetaOffset));\ | |
| 87 | −} | |
| 88 | − | |
| 89 | −static 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, | |
| 91 | − 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 92 | − 0, 0, 0, 0, 0, 0, 4, 4, 5, 6, | |
| 93 | − 7, 8, 9, 10, 12, 13, 15, 17, 20, 22, | |
| 94 | − 25, 28, 32, 36, 40, 45, 50, 56, 63, 71, | |
| 95 | − 80, 90, 101, 113, 127, 144, 162, 182, 203, 226, | |
| 96 | − 255, 255 | |
| 97 | − , 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 | |
| 98 | −}; | |
| 99 | − | |
| 100 | −static 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, | |
| 102 | − 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 103 | − 0, 0, 0, 0, 0, 0, 2, 2, 2, 3, | |
| 104 | − 3, 3, 3, 4, 4, 4, 6, 6, 7, 7, | |
| 105 | − 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, | |
| 106 | − 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, | |
| 107 | − 18, 18 | |
| 108 | − , 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18 | |
| 109 | −}; | |
| 110 | − | |
| 111 | −static 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 }, | |
| 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 }, | |
| 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 }, | |
| 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 }, | |
| 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 }, | |
| 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 } | |
| 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 } | |
| 125 | −}; | |
| 126 | − | |
| 127 | −static const uint8_t g_kuiTableBIdx[2][8] = { | |
| 128 | − { | |
| 129 | − 0, 4, 8, 12, | |
| 130 | − 3, 7, 11, 15 | |
| 131 | − }, | |
| 132 | − | |
| 133 | − { | |
| 134 | − 0, 1, 2, 3, | |
| 135 | − 12, 13, 14, 15 | |
| 136 | − }, | |
| 137 | −}; | |
| 138 | − | |
| 139 | −static const uint8_t g_kuiTableB8x8Idx[2][16] = { | |
| 140 | − { | |
| 141 | − 0, 1, 4, 5, 8, 9, 12, 13, // 0 1 | 2 3 | |
| 142 | − 2, 3, 6, 7, 10, 11, 14, 15 // 4 5 | 6 7 | |
| 143 | − }, // ------------ | |
| 144 | − // 8 9 | 10 11 | |
| 145 | − { | |
| 146 | − // 12 13 | 14 15 | |
| 147 | − 0, 1, 4, 5, 2, 3, 6, 7, | |
| 148 | − 8, 9, 12, 13, 10, 11, 14, 15 | |
| 149 | − }, | |
| 150 | −}; | |
| 151 | − | |
| 152 | −#define TC0_TBL_LOOKUP(tc, iIndexA, pBS, bChroma) \ | |
| 153 | −{\ | |
| 154 | − tc[0] = g_kiTc0Table(iIndexA)[pBS[0]] + bChroma;\ | |
| 155 | − tc[1] = g_kiTc0Table(iIndexA)[pBS[1]] + bChroma;\ | |
| 156 | − tc[2] = g_kiTc0Table(iIndexA)[pBS[2]] + bChroma;\ | |
| 157 | − tc[3] = g_kiTc0Table(iIndexA)[pBS[3]] + bChroma;\ | |
| 158 | −} | |
| 159 | − | |
| 160 | −void inline DeblockingBSInsideMBAvsbase (int8_t* pNnzTab, uint8_t nBS[2][4][4], int32_t iLShiftFactor) { | |
| 161 | − uint32_t uiNnz32b0, uiNnz32b1, uiNnz32b2, uiNnz32b3; | |
| 162 | − | |
| 163 | − uiNnz32b0 = * (uint32_t*) (pNnzTab + 0); | |
| 164 | − uiNnz32b1 = * (uint32_t*) (pNnzTab + 4); | |
| 165 | − uiNnz32b2 = * (uint32_t*) (pNnzTab + 8); | |
| 166 | − uiNnz32b3 = * (uint32_t*) (pNnzTab + 12); | |
| 167 | − | |
| 168 | − nBS[0][1][0] = (pNnzTab[0] | pNnzTab[1]) << iLShiftFactor; | |
| 169 | − nBS[0][2][0] = (pNnzTab[1] | pNnzTab[2]) << iLShiftFactor; | |
| 170 | − nBS[0][3][0] = (pNnzTab[2] | pNnzTab[3]) << iLShiftFactor; | |
| 171 | − | |
| 172 | − nBS[0][1][1] = (pNnzTab[4] | pNnzTab[5]) << iLShiftFactor; | |
| 173 | − nBS[0][2][1] = (pNnzTab[5] | pNnzTab[6]) << iLShiftFactor; | |
| 174 | − nBS[0][3][1] = (pNnzTab[6] | pNnzTab[7]) << iLShiftFactor; | |
| 175 | − * (uint32_t*)nBS[1][1] = (uiNnz32b0 | uiNnz32b1) << iLShiftFactor; | |
| 176 | − | |
| 177 | − nBS[0][1][2] = (pNnzTab[8] | pNnzTab[9]) << iLShiftFactor; | |
| 178 | − nBS[0][2][2] = (pNnzTab[9] | pNnzTab[10]) << iLShiftFactor; | |
| 179 | − nBS[0][3][2] = (pNnzTab[10] | pNnzTab[11]) << iLShiftFactor; | |
| 180 | − * (uint32_t*)nBS[1][2] = (uiNnz32b1 | uiNnz32b2) << iLShiftFactor; | |
| 181 | − | |
| 182 | − nBS[0][1][3] = (pNnzTab[12] | pNnzTab[13]) << iLShiftFactor; | |
| 183 | − nBS[0][2][3] = (pNnzTab[13] | pNnzTab[14]) << iLShiftFactor; | |
| 184 | − nBS[0][3][3] = (pNnzTab[14] | pNnzTab[15]) << iLShiftFactor; | |
| 185 | − * (uint32_t*)nBS[1][3] = (uiNnz32b2 | uiNnz32b3) << iLShiftFactor; | |
| 186 | −} | |
| 187 | − | |
| 188 | −void inline DeblockingBSInsideMBAvsbase8x8 (int8_t* pNnzTab, uint8_t nBS[2][4][4], int32_t iLShiftFactor) { | |
| 189 | − int8_t i8x8NnzTab[4]; | |
| 190 | − for (int32_t i = 0; i < 4; i++) { | |
| 191 | − int32_t iBlkIdx = i << 2; | |
| 192 | − i8x8NnzTab[i] = (pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 1]] | | |
| 193 | − pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 2]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 3]]); | |
| 194 | − } | |
| 195 | − | |
| 196 | − //vertical | |
| 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; | |
| 199 | − //horizontal | |
| 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; | |
| 202 | −} | |
| 203 | − | |
| 204 | −void static inline DeblockingBSInsideMBNormal (PDqLayer pCurDqLayer, uint8_t nBS[2][4][4], int8_t* pNnzTab, | |
| 205 | − int32_t iMbXy) { | |
| 206 | − uint32_t uiNnz32b0, uiNnz32b1, uiNnz32b2, uiNnz32b3; | |
| 207 | − int8_t* iRefIndex = pCurDqLayer->pRefIndex[LIST_0][iMbXy]; | |
| 208 | − ENFORCE_STACK_ALIGN_1D (uint8_t, uiBsx4, 4, 4); | |
| 209 | − | |
| 210 | − int8_t i8x8NnzTab[4]; | |
| 211 | − | |
| 212 | − if (pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { | |
| 213 | − for (int32_t i = 0; i < 4; i++) { | |
| 214 | − int32_t iBlkIdx = i << 2; | |
| 215 | − i8x8NnzTab[i] = (pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 1]] | | |
| 216 | − pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 2]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 3]]); | |
| 217 | − } | |
| 218 | − //vertical | |
| 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]); | |
| 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]); | |
| 223 | − | |
| 224 | − //horizontal | |
| 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]); | |
| 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]); | |
| 229 | − } else { | |
| 230 | − uiNnz32b0 = * (uint32_t*) (pNnzTab + 0); | |
| 231 | − uiNnz32b1 = * (uint32_t*) (pNnzTab + 4); | |
| 232 | − uiNnz32b2 = * (uint32_t*) (pNnzTab + 8); | |
| 233 | − uiNnz32b3 = * (uint32_t*) (pNnzTab + 12); | |
| 234 | − | |
| 235 | − for (int i = 0; i < 3; i++) | |
| 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); | |
| 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); | |
| 240 | − | |
| 241 | − for (int i = 0; i < 3; i++) | |
| 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); | |
| 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); | |
| 246 | − | |
| 247 | − for (int i = 0; i < 3; i++) | |
| 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); | |
| 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); | |
| 252 | − | |
| 253 | − for (int i = 0; i < 3; i++) | |
| 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); | |
| 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); | |
| 258 | − | |
| 259 | − // horizontal | |
| 260 | − * (uint32_t*)uiBsx4 = (uiNnz32b0 | uiNnz32b1); | |
| 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); | |
| 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); | |
| 265 | − | |
| 266 | − * (uint32_t*)uiBsx4 = (uiNnz32b1 | uiNnz32b2); | |
| 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); | |
| 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); | |
| 271 | − | |
| 272 | − * (uint32_t*)uiBsx4 = (uiNnz32b2 | uiNnz32b3); | |
| 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); | |
| 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); | |
| 277 | − } | |
| 278 | −} | |
| 279 | − | |
| 280 | −void static inline DeblockingBSliceBSInsideMBNormal (PDqLayer pCurDqLayer, uint8_t nBS[2][4][4], int8_t* pNnzTab, | |
| 281 | − int32_t iMbXy) { | |
| 282 | − uint32_t uiNnz32b0, uiNnz32b1, uiNnz32b2, uiNnz32b3; | |
| 283 | − int8_t* iRefIndex[LIST_A]; | |
| 284 | − iRefIndex[LIST_0] = pCurDqLayer->pRefIndex[LIST_0][iMbXy]; | |
| 285 | − iRefIndex[LIST_1] = pCurDqLayer->pRefIndex[LIST_1][iMbXy]; | |
| 286 | − ENFORCE_STACK_ALIGN_1D (uint8_t, uiBsx4, 4, 4); | |
| 287 | − | |
| 288 | − int8_t i8x8NnzTab[4]; | |
| 289 | − | |
| 290 | − if (pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { | |
| 291 | − for (int32_t i = 0; i < 4; i++) { | |
| 292 | − int32_t iBlkIdx = i << 2; | |
| 293 | − i8x8NnzTab[i] = (pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 1]] | | |
| 294 | − pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 2]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 3]]); | |
| 295 | − } | |
| 296 | − //vertical | |
| 297 | − int8_t iIndex = g_kuiMbCountScan4Idx[1 << 2]; | |
| 298 | − int8_t iNeigborIndex = g_kuiMbCountScan4Idx[0]; | |
| 299 | − nBS[0][2][0] = nBS[0][2][1] = 1; | |
| 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) { | |
| 302 | − nBS[0][2][0] = nBS[0][2][1] = BS_EDGE ((i8x8NnzTab[0] | i8x8NnzTab[1]), iRefIndex[listIdx], | |
| 303 | − pCurDqLayer->pMv[listIdx][iMbXy], | |
| 304 | − iIndex, iNeigborIndex); | |
| 305 | − break; | |
| 306 | − } | |
| 307 | − } | |
| 308 | − iIndex = g_kuiMbCountScan4Idx[3 << 2]; | |
| 309 | − iNeigborIndex = g_kuiMbCountScan4Idx[2 << 2]; | |
| 310 | − nBS[0][2][2] = nBS[0][2][3] = 1; | |
| 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) { | |
| 313 | − nBS[0][2][2] = nBS[0][2][3] = BS_EDGE ((i8x8NnzTab[2] | i8x8NnzTab[3]), iRefIndex[listIdx], | |
| 314 | − pCurDqLayer->pMv[listIdx][iMbXy], | |
| 315 | − iIndex, iNeigborIndex); | |
| 316 | − break; | |
| 317 | − } | |
| 318 | − } | |
| 319 | − | |
| 320 | − //horizontal | |
| 321 | − iIndex = g_kuiMbCountScan4Idx[2 << 2]; | |
| 322 | − iNeigborIndex = g_kuiMbCountScan4Idx[0]; | |
| 323 | − nBS[1][2][0] = nBS[1][2][1] = 1; | |
| 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) { | |
| 326 | − nBS[1][2][0] = nBS[1][2][1] = BS_EDGE ((i8x8NnzTab[0] | i8x8NnzTab[2]), iRefIndex[listIdx], | |
| 327 | − pCurDqLayer->pMv[listIdx][iMbXy], | |
| 328 | − iIndex, iNeigborIndex); | |
| 329 | − break; | |
| 330 | − } | |
| 331 | − } | |
| 332 | − | |
| 333 | − iIndex = g_kuiMbCountScan4Idx[3 << 2]; | |
| 334 | − iNeigborIndex = g_kuiMbCountScan4Idx[1 << 2]; | |
| 335 | − nBS[1][2][2] = nBS[1][2][3] = 1; | |
| 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) { | |
| 338 | − nBS[1][2][2] = nBS[1][2][3] = BS_EDGE ((i8x8NnzTab[1] | i8x8NnzTab[3]), iRefIndex[listIdx], | |
| 339 | − pCurDqLayer->pMv[listIdx][iMbXy], | |
| 340 | − iIndex, iNeigborIndex); | |
| 341 | − break; | |
| 342 | − } | |
| 343 | − } | |
| 344 | − } else { | |
| 345 | − uiNnz32b0 = * (uint32_t*) (pNnzTab + 0); | |
| 346 | − uiNnz32b1 = * (uint32_t*) (pNnzTab + 4); | |
| 347 | − uiNnz32b2 = * (uint32_t*) (pNnzTab + 8); | |
| 348 | − uiNnz32b3 = * (uint32_t*) (pNnzTab + 12); | |
| 349 | − | |
| 350 | − for (int i = 0; i < 3; i++) | |
| 351 | − uiBsx4[i] = pNnzTab[i] | pNnzTab[i + 1]; | |
| 352 | − nBS[0][1][0] = 1; | |
| 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) { | |
| 355 | − nBS[0][1][0] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 1, 0); | |
| 356 | − break; | |
| 357 | − } | |
| 358 | − } | |
| 359 | − nBS[0][2][0] = 1; | |
| 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) { | |
| 362 | − nBS[0][2][0] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 2, 1); | |
| 363 | − break; | |
| 364 | − } | |
| 365 | − } | |
| 366 | − nBS[0][3][0] = 1; | |
| 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) { | |
| 369 | − nBS[0][3][0] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 3, 2); | |
| 370 | − break; | |
| 371 | − } | |
| 372 | − } | |
| 373 | − | |
| 374 | − for (int i = 0; i < 3; i++) | |
| 375 | − uiBsx4[i] = pNnzTab[4 + i] | pNnzTab[4 + i + 1]; | |
| 376 | − nBS[0][1][1] = 1; | |
| 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) { | |
| 379 | − nBS[0][1][1] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 5, 4); | |
| 380 | − break; | |
| 381 | − } | |
| 382 | − } | |
| 383 | − nBS[0][2][1] = 1; | |
| 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) { | |
| 386 | − nBS[0][2][1] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 6, 5); | |
| 387 | − break; | |
| 388 | − } | |
| 389 | − } | |
| 390 | − nBS[0][3][1] = 1; | |
| 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) { | |
| 393 | − nBS[0][3][1] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 7, 6); | |
| 394 | − break; | |
| 395 | − } | |
| 396 | − } | |
| 397 | − | |
| 398 | − for (int i = 0; i < 3; i++) | |
| 399 | − uiBsx4[i] = pNnzTab[8 + i] | pNnzTab[8 + i + 1]; | |
| 400 | − nBS[0][1][2] = 1; | |
| 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) { | |
| 403 | − nBS[0][1][2] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 9, 8); | |
| 404 | − break; | |
| 405 | − } | |
| 406 | − } | |
| 407 | − nBS[0][2][2] = 1; | |
| 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) { | |
| 410 | − nBS[0][2][2] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 10, 9); | |
| 411 | − break; | |
| 412 | − } | |
| 413 | − } | |
| 414 | − nBS[0][3][2] = 1; | |
| 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) { | |
| 417 | − nBS[0][3][2] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 11, 10); | |
| 418 | − break; | |
| 419 | − } | |
| 420 | − } | |
| 421 | − | |
| 422 | − for (int i = 0; i < 3; i++) | |
| 423 | − uiBsx4[i] = pNnzTab[12 + i] | pNnzTab[12 + i + 1]; | |
| 424 | − nBS[0][1][3] = 1; | |
| 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) { | |
| 427 | − nBS[0][1][3] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 13, 12); | |
| 428 | − break; | |
| 429 | − } | |
| 430 | − } | |
| 431 | − nBS[0][2][3] = 1; | |
| 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) { | |
| 434 | − nBS[0][2][3] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 14, 13); | |
| 435 | − break; | |
| 436 | − } | |
| 437 | − } | |
| 438 | − nBS[0][3][3] = 1; | |
| 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) { | |
| 441 | − nBS[0][3][3] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 15, 14); | |
| 442 | − break; | |
| 443 | − } | |
| 444 | − } | |
| 445 | − | |
| 446 | − // horizontal | |
| 447 | − * (uint32_t*)uiBsx4 = (uiNnz32b0 | uiNnz32b1); | |
| 448 | − nBS[1][1][0] = 1; | |
| 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) { | |
| 451 | − nBS[1][1][0] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 4, 0); | |
| 452 | − break; | |
| 453 | − } | |
| 454 | − } | |
| 455 | − nBS[1][1][1] = 1; | |
| 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) { | |
| 458 | − nBS[1][1][1] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 5, 1); | |
| 459 | − break; | |
| 460 | − } | |
| 461 | − } | |
| 462 | − nBS[1][1][2] = 1; | |
| 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) { | |
| 465 | − nBS[1][1][2] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 6, 2); | |
| 466 | − break; | |
| 467 | − } | |
| 468 | − } | |
| 469 | − nBS[1][1][3] = 1; | |
| 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) { | |
| 472 | − nBS[1][1][3] = BS_EDGE (uiBsx4[3], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 7, 3); | |
| 473 | − break; | |
| 474 | − } | |
| 475 | − } | |
| 476 | − | |
| 477 | − * (uint32_t*)uiBsx4 = (uiNnz32b1 | uiNnz32b2); | |
| 478 | − nBS[1][2][0] = 1; | |
| 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) { | |
| 481 | − nBS[1][2][0] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 8, 4); | |
| 482 | − break; | |
| 483 | − } | |
| 484 | − } | |
| 485 | − nBS[1][2][1] = 1; | |
| 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) { | |
| 488 | − nBS[1][2][1] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 9, 5); | |
| 489 | − break; | |
| 490 | − } | |
| 491 | − } | |
| 492 | − nBS[1][2][2] = 1; | |
| 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) { | |
| 495 | − nBS[1][2][2] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 10, 6); | |
| 496 | − break; | |
| 497 | − } | |
| 498 | − } | |
| 499 | − nBS[1][2][3] = 1; | |
| 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) { | |
| 502 | − nBS[1][2][3] = BS_EDGE (uiBsx4[3], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 11, 7); | |
| 503 | − break; | |
| 504 | − } | |
| 505 | − } | |
| 506 | − | |
| 507 | − * (uint32_t*)uiBsx4 = (uiNnz32b2 | uiNnz32b3); | |
| 508 | − nBS[1][3][0] = 1; | |
| 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) { | |
| 511 | − nBS[1][3][0] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 12, 8); | |
| 512 | − break; | |
| 513 | − } | |
| 514 | − } | |
| 515 | − nBS[1][3][1] = 1; | |
| 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) { | |
| 518 | − nBS[1][3][1] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 13, 9); | |
| 519 | − break; | |
| 520 | − } | |
| 521 | − } | |
| 522 | − nBS[1][3][2] = 1; | |
| 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) { | |
| 525 | − nBS[1][3][2] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 14, 10); | |
| 526 | − break; | |
| 527 | − } | |
| 528 | − } | |
| 529 | − nBS[1][3][3] = 1; | |
| 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) { | |
| 532 | − nBS[1][3][3] = BS_EDGE (uiBsx4[3], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 15, 11); | |
| 533 | − break; | |
| 534 | − } | |
| 535 | − } | |
| 536 | − } | |
| 537 | −} | |
| 538 | − | |
| 539 | − | |
| 540 | −uint32_t DeblockingBsMarginalMBAvcbase (PDqLayer pCurDqLayer, int32_t iEdge, int32_t iNeighMb, int32_t iMbXy) { | |
| 541 | − int32_t i, j; | |
| 542 | − uint32_t uiBSx4; | |
| 543 | − uint8_t* pBS = (uint8_t*) (&uiBSx4); | |
| 544 | − const uint8_t* pBIdx = &g_kuiTableBIdx[iEdge][0]; | |
| 545 | − const uint8_t* pBnIdx = &g_kuiTableBIdx[iEdge][4]; | |
| 546 | − const uint8_t* pB8x8Idx = &g_kuiTableB8x8Idx[iEdge][0]; | |
| 547 | − const uint8_t* pBn8x8Idx = &g_kuiTableB8x8Idx[iEdge][8]; | |
| 548 | − | |
| 549 | − if (pCurDqLayer->pTransformSize8x8Flag[iMbXy] && pCurDqLayer->pTransformSize8x8Flag[iNeighMb]) { | |
| 550 | − for (i = 0; i < 2; i++) { | |
| 551 | − uint8_t uiNzc = 0; | |
| 552 | − for (j = 0; uiNzc == 0 && j < 4; j++) { | |
| 553 | − uiNzc |= (pCurDqLayer->pNzc[iMbXy][* (pB8x8Idx + j)] | pCurDqLayer->pNzc[iNeighMb][* (pBn8x8Idx + j)]); | |
| 554 | − } | |
| 555 | − if (uiNzc) { | |
| 556 | − pBS[i << 1] = pBS[1 + (i << 1)] = 2; | |
| 557 | − } else { | |
| 558 | − pBS[i << 1] = pBS[1 + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[LIST_0], pCurDqLayer->pMv[LIST_0], iMbXy, iNeighMb, | |
| 559 | − *pB8x8Idx, *pBn8x8Idx); | |
| 560 | − } | |
| 561 | − pB8x8Idx += 4; | |
| 562 | − pBn8x8Idx += 4; | |
| 563 | − } | |
| 564 | − } else if (pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { | |
| 565 | − for (i = 0; i < 2; i++) { | |
| 566 | − uint8_t uiNzc = 0; | |
| 567 | − for (j = 0; uiNzc == 0 && j < 4; j++) { | |
| 568 | − uiNzc |= pCurDqLayer->pNzc[iMbXy][* (pB8x8Idx + j)]; | |
| 569 | − } | |
| 570 | − for (j = 0; j < 2; j++) { | |
| 571 | − if (uiNzc | pCurDqLayer->pNzc[iNeighMb][*pBnIdx]) { | |
| 572 | − pBS[j + (i << 1)] = 2; | |
| 573 | − } else { | |
| 574 | − pBS[j + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[LIST_0], pCurDqLayer->pMv[LIST_0], iMbXy, iNeighMb, *pB8x8Idx, | |
| 575 | − *pBnIdx); | |
| 576 | − } | |
| 577 | − pBnIdx++; | |
| 578 | − } | |
| 579 | − pB8x8Idx += 4; | |
| 580 | − } | |
| 581 | − } else if (pCurDqLayer->pTransformSize8x8Flag[iNeighMb]) { | |
| 582 | − for (i = 0; i < 2; i++) { | |
| 583 | − uint8_t uiNzc = 0; | |
| 584 | − for (j = 0; uiNzc == 0 && j < 4; j++) { | |
| 585 | − uiNzc |= pCurDqLayer->pNzc[iNeighMb][* (pBn8x8Idx + j)]; | |
| 586 | − } | |
| 587 | − for (j = 0; j < 2; j++) { | |
| 588 | − if (uiNzc | pCurDqLayer->pNzc[iMbXy][*pBIdx]) { | |
| 589 | − pBS[j + (i << 1)] = 2; | |
| 590 | − } else { | |
| 591 | − pBS[j + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[LIST_0], pCurDqLayer->pMv[LIST_0], iMbXy, iNeighMb, *pBIdx, | |
| 592 | − *pBn8x8Idx); | |
| 593 | − } | |
| 594 | − pBIdx++; | |
| 595 | − } | |
| 596 | − pBn8x8Idx += 4; | |
| 597 | − } | |
| 598 | − } else { | |
| 599 | − // only 4x4 transform | |
| 600 | − for (i = 0; i < 4; i++) { | |
| 601 | − if (pCurDqLayer->pNzc[iMbXy][*pBIdx] | pCurDqLayer->pNzc[iNeighMb][*pBnIdx]) { | |
| 602 | − pBS[i] = 2; | |
| 603 | − } else { | |
| 604 | − pBS[i] = MB_BS_MV (pCurDqLayer->pRefIndex[LIST_0], pCurDqLayer->pMv[LIST_0], iMbXy, iNeighMb, *pBIdx, | |
| 605 | − *pBnIdx); | |
| 606 | − } | |
| 607 | − pBIdx++; | |
| 608 | − pBnIdx++; | |
| 609 | − } | |
| 610 | − } | |
| 611 | − | |
| 612 | − return uiBSx4; | |
| 613 | −} | |
| 614 | −uint32_t DeblockingBSliceBsMarginalMBAvcbase (PDqLayer pCurDqLayer, int32_t iEdge, int32_t iNeighMb, int32_t iMbXy) { | |
| 615 | − int32_t i, j; | |
| 616 | − uint32_t uiBSx4; | |
| 617 | − uint8_t* pBS = (uint8_t*) (&uiBSx4); | |
| 618 | − const uint8_t* pBIdx = &g_kuiTableBIdx[iEdge][0]; | |
| 619 | − const uint8_t* pBnIdx = &g_kuiTableBIdx[iEdge][4]; | |
| 620 | − const uint8_t* pB8x8Idx = &g_kuiTableB8x8Idx[iEdge][0]; | |
| 621 | − const uint8_t* pBn8x8Idx = &g_kuiTableB8x8Idx[iEdge][8]; | |
| 622 | − | |
| 623 | − if (pCurDqLayer->pTransformSize8x8Flag[iMbXy] && pCurDqLayer->pTransformSize8x8Flag[iNeighMb]) { | |
| 624 | − for (i = 0; i < 2; i++) { | |
| 625 | − uint8_t uiNzc = 0; | |
| 626 | − for (j = 0; uiNzc == 0 && j < 4; j++) { | |
| 627 | − uiNzc |= (pCurDqLayer->pNzc[iMbXy][* (pB8x8Idx + j)] | pCurDqLayer->pNzc[iNeighMb][* (pBn8x8Idx + j)]); | |
| 628 | − } | |
| 629 | − if (uiNzc) { | |
| 630 | − pBS[i << 1] = pBS[1 + (i << 1)] = 2; | |
| 631 | − } else { | |
| 632 | − pBS[i << 1] = pBS[1 + (i << 1)] = 1; | |
| 633 | − for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 634 | − if (pCurDqLayer->pRefIndex[listIdx][iMbXy][*pB8x8Idx] > 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, | |
| 637 | − *pB8x8Idx, *pBn8x8Idx); | |
| 638 | − break; | |
| 639 | − } | |
| 640 | − } | |
| 641 | − } | |
| 642 | − pB8x8Idx += 4; | |
| 643 | − pBn8x8Idx += 4; | |
| 644 | − } | |
| 645 | − } else if (pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { | |
| 646 | − for (i = 0; i < 2; i++) { | |
| 647 | − uint8_t uiNzc = 0; | |
| 648 | − for (j = 0; uiNzc == 0 && j < 4; j++) { | |
| 649 | − uiNzc |= pCurDqLayer->pNzc[iMbXy][* (pB8x8Idx + j)]; | |
| 650 | − } | |
| 651 | − for (j = 0; j < 2; j++) { | |
| 652 | − if (uiNzc | pCurDqLayer->pNzc[iNeighMb][*pBnIdx]) { | |
| 653 | − pBS[j + (i << 1)] = 2; | |
| 654 | − } else { | |
| 655 | − pBS[j + (i << 1)] = 1; | |
| 656 | − for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 657 | − if (pCurDqLayer->pRefIndex[listIdx][iMbXy][*pB8x8Idx] > 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, | |
| 660 | − *pBnIdx); | |
| 661 | − break; | |
| 662 | − } | |
| 663 | − } | |
| 664 | − } | |
| 665 | − pBnIdx++; | |
| 666 | − } | |
| 667 | − pB8x8Idx += 4; | |
| 668 | − } | |
| 669 | − } else if (pCurDqLayer->pTransformSize8x8Flag[iNeighMb]) { | |
| 670 | − for (i = 0; i < 2; i++) { | |
| 671 | − uint8_t uiNzc = 0; | |
| 672 | − for (j = 0; uiNzc == 0 && j < 4; j++) { | |
| 673 | − uiNzc |= pCurDqLayer->pNzc[iNeighMb][* (pBn8x8Idx + j)]; | |
| 674 | − } | |
| 675 | − for (j = 0; j < 2; j++) { | |
| 676 | − if (uiNzc | pCurDqLayer->pNzc[iMbXy][*pBIdx]) { | |
| 677 | − pBS[j + (i << 1)] = 2; | |
| 678 | − } else { | |
| 679 | − pBS[j + (i << 1)] = 1; | |
| 680 | − for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 681 | − if (pCurDqLayer->pRefIndex[listIdx][iMbXy][*pBIdx] > 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, | |
| 684 | − *pBn8x8Idx); | |
| 685 | − break; | |
| 686 | − } | |
| 687 | − } | |
| 688 | − } | |
| 689 | − pBIdx++; | |
| 690 | − } | |
| 691 | − pBn8x8Idx += 4; | |
| 692 | − } | |
| 693 | − } else { | |
| 694 | − // only 4x4 transform | |
| 695 | − for (i = 0; i < 4; i++) { | |
| 696 | − if (pCurDqLayer->pNzc[iMbXy][*pBIdx] | pCurDqLayer->pNzc[iNeighMb][*pBnIdx]) { | |
| 697 | − pBS[i] = 2; | |
| 698 | − } else { | |
| 699 | − pBS[i] = 1; | |
| 700 | − for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 701 | − if (pCurDqLayer->pRefIndex[listIdx][iMbXy][*pBIdx] > 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); | |
| 704 | − break; | |
| 705 | − } | |
| 706 | − } | |
| 707 | − } | |
| 708 | − pBIdx++; | |
| 709 | − pBnIdx++; | |
| 710 | − } | |
| 711 | − } | |
| 712 | − | |
| 713 | − return uiBSx4; | |
| 714 | −} | |
| 715 | −int32_t DeblockingAvailableNoInterlayer (PDqLayer pCurDqLayer, int32_t iFilterIdc) { | |
| 716 | − int32_t iMbY = pCurDqLayer->iMbY; | |
| 717 | − int32_t iMbX = pCurDqLayer->iMbX; | |
| 718 | − int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 719 | − bool bLeftFlag = false; | |
| 720 | − bool bTopFlag = false; | |
| 721 | − | |
| 722 | − if (2 == iFilterIdc) { | |
| 723 | − bLeftFlag = (iMbX > 0) && (pCurDqLayer->pSliceIdc[iMbXy] == pCurDqLayer->pSliceIdc[iMbXy - 1]); | |
| 724 | − bTopFlag = (iMbY > 0) && (pCurDqLayer->pSliceIdc[iMbXy] == pCurDqLayer->pSliceIdc[iMbXy - pCurDqLayer->iMbWidth]); | |
| 725 | − } else { //if ( 0 == iFilterIdc ) | |
| 726 | − bLeftFlag = (iMbX > 0); | |
| 727 | − bTopFlag = (iMbY > 0); | |
| 728 | − } | |
| 729 | − return (bLeftFlag << LEFT_FLAG_BIT) | (bTopFlag << TOP_FLAG_BIT); | |
| 730 | −} | |
| 731 | − | |
| 732 | −void FilteringEdgeLumaH (SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS) { | |
| 733 | − int32_t iIndexA; | |
| 734 | − int32_t iAlpha; | |
| 735 | − int32_t iBeta; | |
| 736 | − ENFORCE_STACK_ALIGN_1D (int8_t, tc, 4, 16); | |
| 737 | − | |
| 738 | − GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 739 | − iBeta); | |
| 740 | − | |
| 741 | − if (iAlpha | iBeta) { | |
| 742 | − TC0_TBL_LOOKUP (tc, iIndexA, pBS, 0); | |
| 743 | − pFilter->pLoopf->pfLumaDeblockingLT4Ver (pPix, iStride, iAlpha, iBeta, tc); | |
| 744 | − } | |
| 745 | − return; | |
| 746 | −} | |
| 747 | − | |
| 748 | − | |
| 749 | −void FilteringEdgeLumaV (SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS) { | |
| 750 | − int32_t iIndexA; | |
| 751 | − int32_t iAlpha; | |
| 752 | − int32_t iBeta; | |
| 753 | − ENFORCE_STACK_ALIGN_1D (int8_t, tc, 4, 16); | |
| 754 | − | |
| 755 | − GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 756 | − iBeta); | |
| 757 | − | |
| 758 | − if (iAlpha | iBeta) { | |
| 759 | − TC0_TBL_LOOKUP (tc, iIndexA, pBS, 0); | |
| 760 | − pFilter->pLoopf->pfLumaDeblockingLT4Hor (pPix, iStride, iAlpha, iBeta, tc); | |
| 761 | − } | |
| 762 | − return; | |
| 763 | −} | |
| 764 | − | |
| 765 | − | |
| 766 | −void FilteringEdgeLumaIntraH (SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS) { | |
| 767 | − int32_t iIndexA; | |
| 768 | − int32_t iAlpha; | |
| 769 | − int32_t iBeta; | |
| 770 | − | |
| 771 | − GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 772 | − iBeta); | |
| 773 | − | |
| 774 | − if (iAlpha | iBeta) { | |
| 775 | − pFilter->pLoopf->pfLumaDeblockingEQ4Ver (pPix, iStride, iAlpha, iBeta); | |
| 776 | − } | |
| 777 | − return; | |
| 778 | −} | |
| 779 | − | |
| 780 | −void FilteringEdgeLumaIntraV (SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS) { | |
| 781 | − int32_t iIndexA; | |
| 782 | − int32_t iAlpha; | |
| 783 | − int32_t iBeta; | |
| 784 | − | |
| 785 | − GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 786 | − iBeta); | |
| 787 | − | |
| 788 | − if (iAlpha | iBeta) { | |
| 789 | − pFilter->pLoopf->pfLumaDeblockingEQ4Hor (pPix, iStride, iAlpha, iBeta); | |
| 790 | − } | |
| 791 | − return; | |
| 792 | −} | |
| 793 | −void FilteringEdgeChromaH (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, | |
| 794 | − uint8_t* pBS) { | |
| 795 | − int32_t iIndexA; | |
| 796 | − int32_t iAlpha; | |
| 797 | − int32_t iBeta; | |
| 798 | − ENFORCE_STACK_ALIGN_1D (int8_t, tc, 4, 16); | |
| 799 | − if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) { | |
| 800 | − | |
| 801 | − GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 802 | − iBeta); | |
| 803 | − | |
| 804 | − if (iAlpha | iBeta) { | |
| 805 | − TC0_TBL_LOOKUP (tc, iIndexA, pBS, 1); | |
| 806 | − pFilter->pLoopf->pfChromaDeblockingLT4Ver (pPixCb, pPixCr, iStride, iAlpha, iBeta, tc); | |
| 807 | − } | |
| 808 | − } else { | |
| 809 | − | |
| 810 | − for (int i = 0; i < 2; i++) { | |
| 811 | − | |
| 812 | − | |
| 813 | − GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 814 | − iBeta); | |
| 815 | − | |
| 816 | − if (iAlpha | iBeta) { | |
| 817 | − uint8_t* pPixCbCr = (i == 0) ? pPixCb : pPixCr; | |
| 818 | − TC0_TBL_LOOKUP (tc, iIndexA, pBS, 1); | |
| 819 | − pFilter->pLoopf->pfChromaDeblockingLT4Ver2 (pPixCbCr, iStride, iAlpha, iBeta, tc); | |
| 820 | − } | |
| 821 | − | |
| 822 | − | |
| 823 | − | |
| 824 | − } | |
| 825 | − | |
| 826 | − } | |
| 827 | − return; | |
| 828 | −} | |
| 829 | −void FilteringEdgeChromaV (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, | |
| 830 | − uint8_t* pBS) { | |
| 831 | − int32_t iIndexA; | |
| 832 | − int32_t iAlpha; | |
| 833 | − int32_t iBeta; | |
| 834 | − ENFORCE_STACK_ALIGN_1D (int8_t, tc, 4, 16); | |
| 835 | − if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) { | |
| 836 | − | |
| 837 | − | |
| 838 | − GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 839 | − iBeta); | |
| 840 | − | |
| 841 | − if (iAlpha | iBeta) { | |
| 842 | − TC0_TBL_LOOKUP (tc, iIndexA, pBS, 1); | |
| 843 | − pFilter->pLoopf->pfChromaDeblockingLT4Hor (pPixCb, pPixCr, iStride, iAlpha, iBeta, tc); | |
| 844 | − } | |
| 845 | − | |
| 846 | − | |
| 847 | − } else { | |
| 848 | − | |
| 849 | − for (int i = 0; i < 2; i++) { | |
| 850 | − | |
| 851 | − GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 852 | − iBeta); | |
| 853 | − | |
| 854 | − if (iAlpha | iBeta) { | |
| 855 | − uint8_t* pPixCbCr = (i == 0) ? pPixCb : pPixCr; | |
| 856 | − TC0_TBL_LOOKUP (tc, iIndexA, pBS, 1); | |
| 857 | − pFilter->pLoopf->pfChromaDeblockingLT4Hor2 (pPixCbCr, iStride, iAlpha, iBeta, tc); | |
| 858 | − } | |
| 859 | − | |
| 860 | − | |
| 861 | − } | |
| 862 | − } | |
| 863 | − return; | |
| 864 | −} | |
| 865 | − | |
| 866 | −void FilteringEdgeChromaIntraH (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, | |
| 867 | − uint8_t* pBS) { | |
| 868 | − int32_t iIndexA; | |
| 869 | − int32_t iAlpha; | |
| 870 | − int32_t iBeta; | |
| 871 | − if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) { | |
| 872 | − | |
| 873 | − GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 874 | − iBeta); | |
| 875 | − | |
| 876 | − if (iAlpha | iBeta) { | |
| 877 | − pFilter->pLoopf->pfChromaDeblockingEQ4Ver (pPixCb, pPixCr, iStride, iAlpha, iBeta); | |
| 878 | − } | |
| 879 | − } else { | |
| 880 | − | |
| 881 | − for (int i = 0; i < 2; i++) { | |
| 882 | − | |
| 883 | − GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 884 | − iBeta); | |
| 885 | − | |
| 886 | − if (iAlpha | iBeta) { | |
| 887 | − uint8_t* pPixCbCr = (i == 0) ? pPixCb : pPixCr; | |
| 888 | − pFilter->pLoopf->pfChromaDeblockingEQ4Ver2 (pPixCbCr, iStride, iAlpha, iBeta); | |
| 889 | − } | |
| 890 | − | |
| 891 | − } | |
| 892 | − } | |
| 893 | − return; | |
| 894 | −} | |
| 895 | − | |
| 896 | −void FilteringEdgeChromaIntraV (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, | |
| 897 | − uint8_t* pBS) { | |
| 898 | − int32_t iIndexA; | |
| 899 | − int32_t iAlpha; | |
| 900 | − int32_t iBeta; | |
| 901 | − if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) { // QP of cb and cr are the same | |
| 902 | − | |
| 903 | − | |
| 904 | − | |
| 905 | − | |
| 906 | − GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 907 | − iBeta); | |
| 908 | − if (iAlpha | iBeta) { | |
| 909 | − pFilter->pLoopf->pfChromaDeblockingEQ4Hor (pPixCb, pPixCr, iStride, iAlpha, iBeta); | |
| 910 | − } | |
| 911 | − } else { | |
| 912 | − | |
| 913 | − for (int i = 0; i < 2; i++) { | |
| 914 | − | |
| 915 | − | |
| 916 | − GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 917 | − iBeta); | |
| 918 | − if (iAlpha | iBeta) { | |
| 919 | − uint8_t* pPixCbCr = (i == 0) ? pPixCb : pPixCr; | |
| 920 | − pFilter->pLoopf->pfChromaDeblockingEQ4Hor2 (pPixCbCr, iStride, iAlpha, iBeta); | |
| 921 | − } | |
| 922 | − } | |
| 923 | − | |
| 924 | − } | |
| 925 | − return; | |
| 926 | −} | |
| 927 | − | |
| 928 | − | |
| 929 | −void DeblockingInterMb (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, uint8_t nBS[2][4][4], | |
| 930 | − int32_t iBoundryFlag) { | |
| 931 | − int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex; | |
| 932 | − int32_t iMbX = pCurDqLayer->iMbX; | |
| 933 | − int32_t iMbY = pCurDqLayer->iMbY; | |
| 934 | − | |
| 935 | − int32_t iCurLumaQp = pCurDqLayer->pLumaQp[iMbXyIndex]; | |
| 936 | − //int32_t* iCurChromaQp = pCurDqLayer->pChromaQp[iMbXyIndex]; | |
| 937 | − int8_t* pCurChromaQp = pCurDqLayer->pChromaQp[iMbXyIndex]; | |
| 938 | − int32_t iLineSize = pFilter->iCsStride[0]; | |
| 939 | − int32_t iLineSizeUV = pFilter->iCsStride[1]; | |
| 940 | − | |
| 941 | − uint8_t* pDestY, * pDestCb, * pDestCr; | |
| 942 | − pDestY = pFilter->pCsData[0] + ((iMbY * iLineSize + iMbX) << 4); | |
| 943 | − pDestCb = pFilter->pCsData[1] + ((iMbY * iLineSizeUV + iMbX) << 3); | |
| 944 | − pDestCr = pFilter->pCsData[2] + ((iMbY * iLineSizeUV + iMbX) << 3); | |
| 945 | − | |
| 946 | −//Vertical margrin | |
| 947 | − if (iBoundryFlag & LEFT_FLAG_MASK) { | |
| 948 | − int32_t iLeftXyIndex = iMbXyIndex - 1; | |
| 949 | − pFilter->iLumaQP = (iCurLumaQp + pCurDqLayer->pLumaQp[iLeftXyIndex] + 1) >> 1; | |
| 950 | − for (int i = 0; i < 2; i++) { | |
| 951 | − pFilter->iChromaQP[i] = (pCurChromaQp[i] + pCurDqLayer->pChromaQp[iLeftXyIndex][i] + 1) >> 1; | |
| 952 | − } | |
| 953 | − if (nBS[0][0][0] == 0x04) { | |
| 954 | − FilteringEdgeLumaIntraV (pFilter, pDestY, iLineSize, NULL); | |
| 955 | − FilteringEdgeChromaIntraV (pFilter, pDestCb, pDestCr, iLineSizeUV, NULL); | |
| 956 | − } else { | |
| 957 | − if (* (uint32_t*)nBS[0][0] != 0) { | |
| 958 | − FilteringEdgeLumaV (pFilter, pDestY, iLineSize, nBS[0][0]); | |
| 959 | − FilteringEdgeChromaV (pFilter, pDestCb, pDestCr, iLineSizeUV, nBS[0][0]); | |
| 960 | − } | |
| 961 | − } | |
| 962 | − } | |
| 963 | − | |
| 964 | − pFilter->iLumaQP = iCurLumaQp; | |
| 965 | − pFilter->iChromaQP[0] = pCurChromaQp[0]; | |
| 966 | − pFilter->iChromaQP[1] = pCurChromaQp[1]; | |
| 967 | − | |
| 968 | − if (* (uint32_t*)nBS[0][1] != 0 && !pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) { | |
| 969 | − FilteringEdgeLumaV (pFilter, &pDestY[1 << 2], iLineSize, nBS[0][1]); | |
| 970 | − } | |
| 971 | − | |
| 972 | − if (* (uint32_t*)nBS[0][2] != 0) { | |
| 973 | − FilteringEdgeLumaV (pFilter, &pDestY[2 << 2], iLineSize, nBS[0][2]); | |
| 974 | − FilteringEdgeChromaV (pFilter, &pDestCb[2 << 1], &pDestCr[2 << 1], iLineSizeUV, nBS[0][2]); | |
| 975 | − } | |
| 976 | − | |
| 977 | − if (* (uint32_t*)nBS[0][3] != 0 && !pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) { | |
| 978 | − FilteringEdgeLumaV (pFilter, &pDestY[3 << 2], iLineSize, nBS[0][3]); | |
| 979 | − } | |
| 980 | − | |
| 981 | − if (iBoundryFlag & TOP_FLAG_MASK) { | |
| 982 | − int32_t iTopXyIndex = iMbXyIndex - pCurDqLayer->iMbWidth; | |
| 983 | − pFilter->iLumaQP = (iCurLumaQp + pCurDqLayer->pLumaQp[iTopXyIndex] + 1) >> 1; | |
| 984 | − for (int i = 0; i < 2; i++) { | |
| 985 | − pFilter->iChromaQP[i] = (pCurChromaQp[i] + pCurDqLayer->pChromaQp[iTopXyIndex][i] + 1) >> 1; | |
| 986 | − } | |
| 987 | − | |
| 988 | − if (nBS[1][0][0] == 0x04) { | |
| 989 | − FilteringEdgeLumaIntraH (pFilter, pDestY, iLineSize, NULL); | |
| 990 | − FilteringEdgeChromaIntraH (pFilter, pDestCb, pDestCr, iLineSizeUV, NULL); | |
| 991 | − } else { | |
| 992 | − if (* (uint32_t*)nBS[1][0] != 0) { | |
| 993 | − FilteringEdgeLumaH (pFilter, pDestY, iLineSize, nBS[1][0]); | |
| 994 | − FilteringEdgeChromaH (pFilter, pDestCb, pDestCr, iLineSizeUV, nBS[1][0]); | |
| 995 | − } | |
| 996 | − } | |
| 997 | − } | |
| 998 | − | |
| 999 | − pFilter->iLumaQP = iCurLumaQp; | |
| 1000 | − pFilter->iChromaQP[0] = pCurChromaQp[0]; | |
| 1001 | − pFilter->iChromaQP[1] = pCurChromaQp[1]; | |
| 1002 | − | |
| 1003 | − if (* (uint32_t*)nBS[1][1] != 0 && !pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) { | |
| 1004 | − FilteringEdgeLumaH (pFilter, &pDestY[ (1 << 2)*iLineSize], iLineSize, nBS[1][1]); | |
| 1005 | − } | |
| 1006 | − | |
| 1007 | − if (* (uint32_t*)nBS[1][2] != 0) { | |
| 1008 | − FilteringEdgeLumaH (pFilter, &pDestY[ (2 << 2)*iLineSize], iLineSize, nBS[1][2]); | |
| 1009 | − FilteringEdgeChromaH (pFilter, &pDestCb[ (2 << 1)*iLineSizeUV], &pDestCr[ (2 << 1)*iLineSizeUV], iLineSizeUV, | |
| 1010 | − nBS[1][2]); | |
| 1011 | − } | |
| 1012 | − | |
| 1013 | − if (* (uint32_t*)nBS[1][3] != 0 && !pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) { | |
| 1014 | − FilteringEdgeLumaH (pFilter, &pDestY[ (3 << 2)*iLineSize], iLineSize, nBS[1][3]); | |
| 1015 | − } | |
| 1016 | −} | |
| 1017 | − | |
| 1018 | −void FilteringEdgeLumaHV (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag) { | |
| 1019 | − int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex; | |
| 1020 | − int32_t iMbX = pCurDqLayer->iMbX; | |
| 1021 | − int32_t iMbY = pCurDqLayer->iMbY; | |
| 1022 | − int32_t iMbWidth = pCurDqLayer->iMbWidth; | |
| 1023 | − int32_t iLineSize = pFilter->iCsStride[0]; | |
| 1024 | − | |
| 1025 | − uint8_t* pDestY; | |
| 1026 | − int32_t iCurQp; | |
| 1027 | − int32_t iIndexA, iAlpha, iBeta; | |
| 1028 | − | |
| 1029 | − ENFORCE_STACK_ALIGN_1D (int8_t, iTc, 4, 16); | |
| 1030 | − ENFORCE_STACK_ALIGN_1D (uint8_t, uiBSx4, 4, 4); | |
| 1031 | − | |
| 1032 | − pDestY = pFilter->pCsData[0] + ((iMbY * iLineSize + iMbX) << 4); | |
| 1033 | − iCurQp = pCurDqLayer->pLumaQp[iMbXyIndex]; | |
| 1034 | − | |
| 1035 | − * (uint32_t*)uiBSx4 = 0x03030303; | |
| 1036 | − | |
| 1037 | − // luma v | |
| 1038 | − if (iBoundryFlag & LEFT_FLAG_MASK) { | |
| 1039 | − pFilter->iLumaQP = (iCurQp + pCurDqLayer->pLumaQp[iMbXyIndex - 1] + 1) >> 1; | |
| 1040 | − FilteringEdgeLumaIntraV (pFilter, pDestY, iLineSize, NULL); | |
| 1041 | − } | |
| 1042 | − | |
| 1043 | − pFilter->iLumaQP = iCurQp; | |
| 1044 | − GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 1045 | − iBeta); | |
| 1046 | − if (iAlpha | iBeta) { | |
| 1047 | − TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 0); | |
| 1048 | − | |
| 1049 | − if (!pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) { | |
| 1050 | − pFilter->pLoopf->pfLumaDeblockingLT4Hor (&pDestY[1 << 2], iLineSize, iAlpha, iBeta, iTc); | |
| 1051 | − } | |
| 1052 | − | |
| 1053 | − pFilter->pLoopf->pfLumaDeblockingLT4Hor (&pDestY[2 << 2], iLineSize, iAlpha, iBeta, iTc); | |
| 1054 | − | |
| 1055 | − if (!pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) { | |
| 1056 | − pFilter->pLoopf->pfLumaDeblockingLT4Hor (&pDestY[3 << 2], iLineSize, iAlpha, iBeta, iTc); | |
| 1057 | − } | |
| 1058 | − } | |
| 1059 | − | |
| 1060 | − // luma h | |
| 1061 | − if (iBoundryFlag & TOP_FLAG_MASK) { | |
| 1062 | − pFilter->iLumaQP = (iCurQp + pCurDqLayer->pLumaQp[iMbXyIndex - iMbWidth] + 1) >> 1; | |
| 1063 | − FilteringEdgeLumaIntraH (pFilter, pDestY, iLineSize, NULL); | |
| 1064 | − } | |
| 1065 | − | |
| 1066 | − pFilter->iLumaQP = iCurQp; | |
| 1067 | − if (iAlpha | iBeta) { | |
| 1068 | − if (!pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) { | |
| 1069 | − pFilter->pLoopf->pfLumaDeblockingLT4Ver (&pDestY[ (1 << 2)*iLineSize], iLineSize, iAlpha, iBeta, iTc); | |
| 1070 | − } | |
| 1071 | − | |
| 1072 | − pFilter->pLoopf->pfLumaDeblockingLT4Ver (&pDestY[ (2 << 2)*iLineSize], iLineSize, iAlpha, iBeta, iTc); | |
| 1073 | − | |
| 1074 | − if (!pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) { | |
| 1075 | − pFilter->pLoopf->pfLumaDeblockingLT4Ver (&pDestY[ (3 << 2)*iLineSize], iLineSize, iAlpha, iBeta, iTc); | |
| 1076 | − } | |
| 1077 | − } | |
| 1078 | −} | |
| 1079 | −void FilteringEdgeChromaHV (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag) { | |
| 1080 | − int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex; | |
| 1081 | − int32_t iMbX = pCurDqLayer->iMbX; | |
| 1082 | − int32_t iMbY = pCurDqLayer->iMbY; | |
| 1083 | − int32_t iMbWidth = pCurDqLayer->iMbWidth; | |
| 1084 | − int32_t iLineSize = pFilter->iCsStride[1]; | |
| 1085 | − | |
| 1086 | − uint8_t* pDestCb; | |
| 1087 | − uint8_t* pDestCr; | |
| 1088 | − //int32_t iCurQp; | |
| 1089 | − int8_t* pCurQp; | |
| 1090 | − int32_t iIndexA, iAlpha, iBeta; | |
| 1091 | − | |
| 1092 | − ENFORCE_STACK_ALIGN_1D (int8_t, iTc, 4, 16); | |
| 1093 | − ENFORCE_STACK_ALIGN_1D (uint8_t, uiBSx4, 4, 4); | |
| 1094 | − | |
| 1095 | − pDestCb = pFilter->pCsData[1] + ((iMbY * iLineSize + iMbX) << 3); | |
| 1096 | − pDestCr = pFilter->pCsData[2] + ((iMbY * iLineSize + iMbX) << 3); | |
| 1097 | − pCurQp = pCurDqLayer->pChromaQp[iMbXyIndex]; | |
| 1098 | − | |
| 1099 | − * (uint32_t*)uiBSx4 = 0x03030303; | |
| 1100 | − | |
| 1101 | − | |
| 1102 | −// chroma v | |
| 1103 | − if (iBoundryFlag & LEFT_FLAG_MASK) { | |
| 1104 | − | |
| 1105 | − for (int i = 0; i < 2; i++) { | |
| 1106 | − pFilter->iChromaQP[i] = (pCurQp[i] + pCurDqLayer->pChromaQp[iMbXyIndex - 1][i] + 1) >> 1; | |
| 1107 | − | |
| 1108 | − } | |
| 1109 | − FilteringEdgeChromaIntraV (pFilter, pDestCb, pDestCr, iLineSize, NULL); | |
| 1110 | − } | |
| 1111 | − | |
| 1112 | − pFilter->iChromaQP[0] = pCurQp[0]; | |
| 1113 | − pFilter->iChromaQP[1] = pCurQp[1]; | |
| 1114 | − if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) { | |
| 1115 | − GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 1116 | − iBeta); | |
| 1117 | − if (iAlpha | iBeta) { | |
| 1118 | − TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 1); | |
| 1119 | − pFilter->pLoopf->pfChromaDeblockingLT4Hor (&pDestCb[2 << 1], &pDestCr[2 << 1], iLineSize, iAlpha, iBeta, iTc); | |
| 1120 | − } | |
| 1121 | − } else { | |
| 1122 | − | |
| 1123 | − for (int i = 0; i < 2; i++) { | |
| 1124 | − GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 1125 | − iBeta); | |
| 1126 | − if (iAlpha | iBeta) { | |
| 1127 | − uint8_t* pDestCbCr = (i == 0) ? &pDestCb[2 << 1] : &pDestCr[2 << 1]; | |
| 1128 | − TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 1); | |
| 1129 | − pFilter->pLoopf->pfChromaDeblockingLT4Hor2 (pDestCbCr, iLineSize, iAlpha, iBeta, iTc); | |
| 1130 | − } | |
| 1131 | − | |
| 1132 | − } | |
| 1133 | − } | |
| 1134 | − | |
| 1135 | − // chroma h | |
| 1136 | − | |
| 1137 | − if (iBoundryFlag & TOP_FLAG_MASK) { | |
| 1138 | − for (int i = 0; i < 2; i++) { | |
| 1139 | − pFilter->iChromaQP[i] = (pCurQp[i] + pCurDqLayer->pChromaQp[iMbXyIndex - iMbWidth][i] + 1) >> 1; | |
| 1140 | − } | |
| 1141 | − FilteringEdgeChromaIntraH (pFilter, pDestCb, pDestCr, iLineSize, NULL); | |
| 1142 | − } | |
| 1143 | − | |
| 1144 | − pFilter->iChromaQP[0] = pCurQp[0]; | |
| 1145 | − pFilter->iChromaQP[1] = pCurQp[1]; | |
| 1146 | − | |
| 1147 | − if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) { | |
| 1148 | − GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 1149 | − iBeta); | |
| 1150 | − if (iAlpha | iBeta) { | |
| 1151 | − TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 1); | |
| 1152 | − pFilter->pLoopf->pfChromaDeblockingLT4Ver (&pDestCb[ (2 << 1)*iLineSize], &pDestCr[ (2 << 1)*iLineSize], iLineSize, | |
| 1153 | − iAlpha, iBeta, iTc); | |
| 1154 | − } | |
| 1155 | − } else { | |
| 1156 | − for (int i = 0; i < 2; i++) { | |
| 1157 | − | |
| 1158 | − GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 1159 | − iBeta); | |
| 1160 | − if (iAlpha | iBeta) { | |
| 1161 | − TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 1); | |
| 1162 | − uint8_t* pDestCbCr = (i == 0) ? &pDestCb[ (2 << 1) * iLineSize] : &pDestCr[ (2 << 1) * iLineSize]; | |
| 1163 | − pFilter->pLoopf->pfChromaDeblockingLT4Ver2 (pDestCbCr, iLineSize, | |
| 1164 | − iAlpha, iBeta, iTc); | |
| 1165 | − } | |
| 1166 | − } | |
| 1167 | − | |
| 1168 | − | |
| 1169 | − } | |
| 1170 | −} | |
| 1171 | − | |
| 1172 | −// merge h&v lookup table operation to save performance | |
| 1173 | −void DeblockingIntraMb (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag) { | |
| 1174 | − FilteringEdgeLumaHV (pCurDqLayer, pFilter, iBoundryFlag); | |
| 1175 | − FilteringEdgeChromaHV (pCurDqLayer, pFilter, iBoundryFlag); | |
| 1176 | −} | |
| 1177 | − | |
| 1178 | −void WelsDeblockingMb (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag) { | |
| 1179 | − uint8_t nBS[2][4][4] = {{{ 0 }}}; | |
| 1180 | − | |
| 1181 | − int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex; | |
| 1182 | − uint32_t iCurMbType = pCurDqLayer->pMbType[iMbXyIndex]; | |
| 1183 | − int32_t iMbNb; | |
| 1184 | − | |
| 1185 | − PSlice pSlice = &pCurDqLayer->sLayerInfo.sSliceInLayer; | |
| 1186 | − PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | |
| 1187 | − bool bBSlice = pSliceHeader->eSliceType == B_SLICE; | |
| 1188 | − | |
| 1189 | − switch (iCurMbType) { | |
| 1190 | − case MB_TYPE_INTRA4x4: | |
| 1191 | − case MB_TYPE_INTRA8x8: | |
| 1192 | − case MB_TYPE_INTRA16x16: | |
| 1193 | − case MB_TYPE_INTRA_PCM: | |
| 1194 | − DeblockingIntraMb (pCurDqLayer, pFilter, iBoundryFlag); | |
| 1195 | − break; | |
| 1196 | − default: | |
| 1197 | − | |
| 1198 | − if (iBoundryFlag & LEFT_FLAG_MASK) { | |
| 1199 | − iMbNb = iMbXyIndex - 1; | |
| 1200 | − if (bBSlice) { | |
| 1201 | − * (uint32_t*)nBS[0][0] = IS_INTRA (pCurDqLayer->pMbType[iMbNb]) ? 0x04040404 : DeblockingBSliceBsMarginalMBAvcbase ( | |
| 1202 | − pCurDqLayer, 0, iMbNb, iMbXyIndex); | |
| 1203 | − } else { | |
| 1204 | − * (uint32_t*)nBS[0][0] = IS_INTRA (pCurDqLayer->pMbType[iMbNb]) ? 0x04040404 : DeblockingBsMarginalMBAvcbase ( | |
| 1205 | − pCurDqLayer, 0, iMbNb, iMbXyIndex); | |
| 1206 | − } | |
| 1207 | − } else { | |
| 1208 | − * (uint32_t*)nBS[0][0] = 0; | |
| 1209 | − } | |
| 1210 | − if (iBoundryFlag & TOP_FLAG_MASK) { | |
| 1211 | − iMbNb = iMbXyIndex - pCurDqLayer->iMbWidth; | |
| 1212 | − if (bBSlice) { | |
| 1213 | − * (uint32_t*)nBS[1][0] = IS_INTRA (pCurDqLayer->pMbType[iMbNb]) ? 0x04040404 : DeblockingBSliceBsMarginalMBAvcbase ( | |
| 1214 | − pCurDqLayer, 1, iMbNb, iMbXyIndex); | |
| 1215 | − } else { | |
| 1216 | − * (uint32_t*)nBS[1][0] = IS_INTRA (pCurDqLayer->pMbType[iMbNb]) ? 0x04040404 : DeblockingBsMarginalMBAvcbase ( | |
| 1217 | − pCurDqLayer, 1, iMbNb, iMbXyIndex); | |
| 1218 | − } | |
| 1219 | − } else { | |
| 1220 | − * (uint32_t*)nBS[1][0] = 0; | |
| 1221 | − } | |
| 1222 | − //SKIP MB_16x16 or others | |
| 1223 | − if (IS_SKIP (iCurMbType)) { | |
| 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; | |
| 1226 | − } else { | |
| 1227 | − if (IS_INTER_16x16 (iCurMbType)) { | |
| 1228 | − if (!pCurDqLayer->pTransformSize8x8Flag[pCurDqLayer->iMbXyIndex]) { | |
| 1229 | − DeblockingBSInsideMBAvsbase (pCurDqLayer->pNzc[iMbXyIndex], nBS, 1); | |
| 1230 | − } else { | |
| 1231 | − DeblockingBSInsideMBAvsbase8x8 (pCurDqLayer->pNzc[iMbXyIndex], nBS, 1); | |
| 1232 | − } | |
| 1233 | − } else { | |
| 1234 | − | |
| 1235 | − if (bBSlice) { | |
| 1236 | − DeblockingBSliceBSInsideMBNormal (pCurDqLayer, nBS, pCurDqLayer->pNzc[iMbXyIndex], iMbXyIndex); | |
| 1237 | − } else { | |
| 1238 | − DeblockingBSInsideMBNormal (pCurDqLayer, nBS, pCurDqLayer->pNzc[iMbXyIndex], iMbXyIndex); | |
| 1239 | − } | |
| 1240 | − } | |
| 1241 | − } | |
| 1242 | − DeblockingInterMb (pCurDqLayer, pFilter, nBS, iBoundryFlag); | |
| 1243 | − break; | |
| 1244 | − } | |
| 1245 | −} | |
| 1246 | − | |
| 1247 | −/*! | |
| 1248 | − * \brief AVC slice deblocking filtering target layer | |
| 1249 | − * | |
| 1250 | − * \param dec Wels avc decoder context | |
| 1251 | − * | |
| 1252 | − * \return NONE | |
| 1253 | − */ | |
| 1254 | −void WelsDeblockingFilterSlice (PWelsDecoderContext pCtx, PDeblockingFilterMbFunc pDeblockMb) { | |
| 1255 | − PDqLayer pCurDqLayer = pCtx->pCurDqLayer; | |
| 1256 | − PSliceHeaderExt pSliceHeaderExt = &pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt; | |
| 1257 | − int32_t iMbWidth = pCurDqLayer->iMbWidth; | |
| 1258 | − int32_t iTotalMbCount = pSliceHeaderExt->sSliceHeader.pSps->uiTotalMbCount; | |
| 1259 | − | |
| 1260 | − SDeblockingFilter pFilter; | |
| 1261 | − memset (&pFilter, 0, sizeof (pFilter)); | |
| 1262 | − PFmo pFmo = pCtx->pFmo; | |
| 1263 | − int32_t iNextMbXyIndex = 0; | |
| 1264 | − int32_t iTotalNumMb = pCurDqLayer->sLayerInfo.sSliceInLayer.iTotalMbInCurSlice; | |
| 1265 | − int32_t iCountNumMb = 0; | |
| 1266 | − int32_t iBoundryFlag; | |
| 1267 | − int32_t iFilterIdc = pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.uiDisableDeblockingFilterIdc; | |
| 1268 | − | |
| 1269 | − /* Step1: parameters set */ | |
| 1270 | − pFilter.pCsData[0] = pCtx->pDec->pData[0]; | |
| 1271 | − pFilter.pCsData[1] = pCtx->pDec->pData[1]; | |
| 1272 | − pFilter.pCsData[2] = pCtx->pDec->pData[2]; | |
| 1273 | − | |
| 1274 | − pFilter.iCsStride[0] = pCtx->pDec->iLinesize[0]; | |
| 1275 | − pFilter.iCsStride[1] = pCtx->pDec->iLinesize[1]; | |
| 1276 | − | |
| 1277 | − pFilter.eSliceType = (EWelsSliceType) pCurDqLayer->sLayerInfo.sSliceInLayer.eSliceType; | |
| 1278 | − | |
| 1279 | − pFilter.iSliceAlphaC0Offset = pSliceHeaderExt->sSliceHeader.iSliceAlphaC0Offset; | |
| 1280 | − pFilter.iSliceBetaOffset = pSliceHeaderExt->sSliceHeader.iSliceBetaOffset; | |
| 1281 | − | |
| 1282 | − pFilter.pLoopf = &pCtx->sDeblockingFunc; | |
| 1283 | − | |
| 1284 | − /* Step2: macroblock deblocking */ | |
| 1285 | − if (0 == iFilterIdc || 2 == iFilterIdc) { | |
| 1286 | − iNextMbXyIndex = pSliceHeaderExt->sSliceHeader.iFirstMbInSlice; | |
| 1287 | − pCurDqLayer->iMbX = iNextMbXyIndex % iMbWidth; | |
| 1288 | − pCurDqLayer->iMbY = iNextMbXyIndex / iMbWidth; | |
| 1289 | − pCurDqLayer->iMbXyIndex = iNextMbXyIndex; | |
| 1290 | − | |
| 1291 | − do { | |
| 1292 | − iBoundryFlag = DeblockingAvailableNoInterlayer (pCurDqLayer, iFilterIdc); | |
| 1293 | − | |
| 1294 | − pDeblockMb (pCurDqLayer, &pFilter, iBoundryFlag); | |
| 1295 | − | |
| 1296 | − ++iCountNumMb; | |
| 1297 | − if (iCountNumMb >= iTotalNumMb) { | |
| 1298 | − break; | |
| 1299 | − } | |
| 1300 | − | |
| 1301 | − if (pSliceHeaderExt->sSliceHeader.pPps->uiNumSliceGroups > 1) { | |
| 1302 | − iNextMbXyIndex = FmoNextMb (pFmo, iNextMbXyIndex); | |
| 1303 | − } else { | |
| 1304 | − ++iNextMbXyIndex; | |
| 1305 | − } | |
| 1306 | − if (-1 == iNextMbXyIndex || iNextMbXyIndex >= iTotalMbCount) { // slice group boundary or end of a frame | |
| 1307 | − break; | |
| 1308 | − } | |
| 1309 | − | |
| 1310 | − pCurDqLayer->iMbX = iNextMbXyIndex % iMbWidth; | |
| 1311 | − pCurDqLayer->iMbY = iNextMbXyIndex / iMbWidth; | |
| 1312 | − pCurDqLayer->iMbXyIndex = iNextMbXyIndex; | |
| 1313 | − } while (1); | |
| 1314 | − } | |
| 1315 | −} | |
| 1316 | −/*! | |
| 1317 | − * \brief deblocking module initialize | |
| 1318 | − * | |
| 1319 | − * \param pf | |
| 1320 | − * cpu | |
| 1321 | − * | |
| 1322 | − * \return NONE | |
| 1323 | − */ | |
| 1324 | − | |
| 1325 | −void DeblockingInit (SDeblockingFunc* pFunc, int32_t iCpu) { | |
| 1326 | − pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_c; | |
| 1327 | − pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_c; | |
| 1328 | − pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_c; | |
| 1329 | − pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_c; | |
| 1330 | − | |
| 1331 | − pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_c; | |
| 1332 | − pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_c; | |
| 1333 | − pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_c; | |
| 1334 | − pFunc->pfChromaDeblockingEQ4Hor = DeblockChromaEq4H_c; | |
| 1335 | − | |
| 1336 | − pFunc->pfChromaDeblockingLT4Ver2 = DeblockChromaLt4V2_c; | |
| 1337 | − pFunc->pfChromaDeblockingEQ4Ver2 = DeblockChromaEq4V2_c; | |
| 1338 | − pFunc->pfChromaDeblockingLT4Hor2 = DeblockChromaLt4H2_c; | |
| 1339 | − pFunc->pfChromaDeblockingEQ4Hor2 = DeblockChromaEq4H2_c; | |
| 1340 | − | |
| 1341 | −#ifdef X86_ASM | |
| 1342 | − if (iCpu & WELS_CPU_SSSE3) { | |
| 1343 | − pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_ssse3; | |
| 1344 | − pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_ssse3; | |
| 1345 | − pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_ssse3; | |
| 1346 | − pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_ssse3; | |
| 1347 | − pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_ssse3; | |
| 1348 | − pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_ssse3; | |
| 1349 | − pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_ssse3; | |
| 1350 | − pFunc->pfChromaDeblockingEQ4Hor = DeblockChromaEq4H_ssse3; | |
| 1351 | − } | |
| 1352 | −#endif | |
| 1353 | − | |
| 1354 | −#if defined(HAVE_NEON) | |
| 1355 | − if (iCpu & WELS_CPU_NEON) { | |
| 1356 | − pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_neon; | |
| 1357 | − pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_neon; | |
| 1358 | − pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_neon; | |
| 1359 | − pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_neon; | |
| 1360 | − | |
| 1361 | − pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_neon; | |
| 1362 | − pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_neon; | |
| 1363 | − pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_neon; | |
| 1364 | − pFunc->pfChromaDeblockingEQ4Hor = DeblockChromaEq4H_neon; | |
| 1365 | − } | |
| 1366 | −#endif | |
| 1367 | − | |
| 1368 | −#if defined(HAVE_NEON_AARCH64) | |
| 1369 | − if (iCpu & WELS_CPU_NEON) { | |
| 1370 | − pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_AArch64_neon; | |
| 1371 | − pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_AArch64_neon; | |
| 1372 | − pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_AArch64_neon; | |
| 1373 | − pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_AArch64_neon; | |
| 1374 | − | |
| 1375 | − pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_AArch64_neon; | |
| 1376 | − pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_AArch64_neon; | |
| 1377 | − pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_AArch64_neon; | |
| 1378 | − pFunc->pfChromaDeblockingEQ4Hor = DeblockChromaEq4H_AArch64_neon; | |
| 1379 | − } | |
| 1380 | −#endif | |
| 1381 | −} | |
| 1382 | − | |
| 1383 | −} // namespace WelsDec | |
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 2010-2013, Cisco Systems | |
| 4 | + * All rights reserved. | |
| 5 | + * | |
| 6 | + * Redistribution and use in source and binary forms, with or without | |
| 7 | + * modification, are permitted provided that the following conditions | |
| 8 | + * are met: | |
| 9 | + * | |
| 10 | + * * Redistributions of source code must retain the above copyright | |
| 11 | + * notice, this list of conditions and the following disclaimer. | |
| 12 | + * | |
| 13 | + * * Redistributions in binary form must reproduce the above copyright | |
| 14 | + * notice, this list of conditions and the following disclaimer in | |
| 15 | + * the documentation and/or other materials provided with the | |
| 16 | + * distribution. | |
| 17 | + * | |
| 18 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 21 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 22 | + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 23 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 26 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
| 28 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | + * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | + * | |
| 31 | + * | |
| 32 | + * \file deblocking.c | |
| 33 | + * | |
| 34 | + * \brief Interfaces introduced in frame deblocking filtering | |
| 35 | + * | |
| 36 | + * \date 08/02/2010 | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | + | |
| 41 | +#include "deblocking.h" | |
| 42 | +#include "deblocking_common.h" | |
| 43 | +#include "cpu_core.h" | |
| 44 | + | |
| 45 | +namespace WelsDec { | |
| 46 | + | |
| 47 | +#define NO_SUPPORTED_FILTER_IDX (-1) | |
| 48 | +#define LEFT_FLAG_BIT 0 | |
| 49 | +#define TOP_FLAG_BIT 1 | |
| 50 | +#define LEFT_FLAG_MASK 0x01 | |
| 51 | +#define TOP_FLAG_MASK 0x02 | |
| 52 | + | |
| 53 | +#define SAME_MB_DIFF_REFIDX | |
| 54 | +#define g_kuiAlphaTable(x) g_kuiAlphaTable[(x)+12] | |
| 55 | +#define g_kiBetaTable(x) g_kiBetaTable[(x)+12] | |
| 56 | +#define g_kiTc0Table(x) g_kiTc0Table[(x)+12] | |
| 57 | + | |
| 58 | +#define MB_BS_MV(iRefIndex, iMotionVector, iMbXy, iMbBn, iIndex, iNeighIndex) \ | |
| 59 | +(\ | |
| 60 | + ( iRefIndex[iMbXy][iIndex] - iRefIndex[iMbBn][iNeighIndex] )||\ | |
| 61 | + ( WELS_ABS( iMotionVector[iMbXy][iIndex][0] - iMotionVector[iMbBn][iNeighIndex][0] ) >= 4 ) ||\ | |
| 62 | + ( WELS_ABS( iMotionVector[iMbXy][iIndex][1] - iMotionVector[iMbBn][iNeighIndex][1] ) >= 4 )\ | |
| 63 | +) | |
| 64 | + | |
| 65 | +#if defined(SAME_MB_DIFF_REFIDX) | |
| 66 | +#define SMB_EDGE_MV(iRefIndex, iMotionVector, iIndex, iNeighIndex) \ | |
| 67 | +(\ | |
| 68 | + ( iRefIndex[iIndex] - iRefIndex[iNeighIndex] )||(\ | |
| 69 | + ( WELS_ABS( iMotionVector[iIndex][0] - iMotionVector[iNeighIndex][0] ) &(~3) ) |\ | |
| 70 | + ( WELS_ABS( iMotionVector[iIndex][1] - iMotionVector[iNeighIndex][1] ) &(~3) ))\ | |
| 71 | +) | |
| 72 | +#else | |
| 73 | +#define SMB_EDGE_MV(iRefIndex, iMotionVector, iIndex, iNeighIndex) \ | |
| 74 | +(\ | |
| 75 | + !!(( WELS_ABS( iMotionVector[iIndex][0] - iMotionVector[iNeighIndex][0] ) &(~3) ) |( WELS_ABS( iMotionVector[iIndex][1] - iMotionVector[iNeighIndex][1] ) &(~3) ))\ | |
| 76 | +) | |
| 77 | +#endif | |
| 78 | + | |
| 79 | +#define BS_EDGE(bsx1, iRefIndex, iMotionVector, iIndex, iNeighIndex) \ | |
| 80 | +( (bsx1|SMB_EDGE_MV(iRefIndex, iMotionVector, iIndex, iNeighIndex))<<((uint8_t)(!!bsx1))) | |
| 81 | + | |
| 82 | +#define GET_ALPHA_BETA_FROM_QP(iQp, iAlphaOffset, iBetaOffset, iIndex, iAlpha, iBeta) \ | |
| 83 | +{\ | |
| 84 | + iIndex = (iQp + iAlphaOffset);\ | |
| 85 | + iAlpha = g_kuiAlphaTable(iIndex);\ | |
| 86 | + iBeta = g_kiBetaTable((iQp + iBetaOffset));\ | |
| 87 | +} | |
| 88 | + | |
| 89 | +static 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, | |
| 91 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 92 | + 0, 0, 0, 0, 0, 0, 4, 4, 5, 6, | |
| 93 | + 7, 8, 9, 10, 12, 13, 15, 17, 20, 22, | |
| 94 | + 25, 28, 32, 36, 40, 45, 50, 56, 63, 71, | |
| 95 | + 80, 90, 101, 113, 127, 144, 162, 182, 203, 226, | |
| 96 | + 255, 255 | |
| 97 | + , 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 | |
| 98 | +}; | |
| 99 | + | |
| 100 | +static 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, | |
| 102 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 103 | + 0, 0, 0, 0, 0, 0, 2, 2, 2, 3, | |
| 104 | + 3, 3, 3, 4, 4, 4, 6, 6, 7, 7, | |
| 105 | + 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, | |
| 106 | + 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, | |
| 107 | + 18, 18 | |
| 108 | + , 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18 | |
| 109 | +}; | |
| 110 | + | |
| 111 | +static 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 }, | |
| 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 }, | |
| 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 }, | |
| 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 }, | |
| 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 }, | |
| 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 } | |
| 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 } | |
| 125 | +}; | |
| 126 | + | |
| 127 | +static const uint8_t g_kuiTableBIdx[2][8] = { | |
| 128 | + { | |
| 129 | + 0, 4, 8, 12, | |
| 130 | + 3, 7, 11, 15 | |
| 131 | + }, | |
| 132 | + | |
| 133 | + { | |
| 134 | + 0, 1, 2, 3, | |
| 135 | + 12, 13, 14, 15 | |
| 136 | + }, | |
| 137 | +}; | |
| 138 | + | |
| 139 | +static const uint8_t g_kuiTableB8x8Idx[2][16] = { | |
| 140 | + { | |
| 141 | + 0, 1, 4, 5, 8, 9, 12, 13, // 0 1 | 2 3 | |
| 142 | + 2, 3, 6, 7, 10, 11, 14, 15 // 4 5 | 6 7 | |
| 143 | + }, // ------------ | |
| 144 | + // 8 9 | 10 11 | |
| 145 | + { | |
| 146 | + // 12 13 | 14 15 | |
| 147 | + 0, 1, 4, 5, 2, 3, 6, 7, | |
| 148 | + 8, 9, 12, 13, 10, 11, 14, 15 | |
| 149 | + }, | |
| 150 | +}; | |
| 151 | + | |
| 152 | +#define TC0_TBL_LOOKUP(tc, iIndexA, pBS, bChroma) \ | |
| 153 | +{\ | |
| 154 | + tc[0] = g_kiTc0Table(iIndexA)[pBS[0]] + bChroma;\ | |
| 155 | + tc[1] = g_kiTc0Table(iIndexA)[pBS[1]] + bChroma;\ | |
| 156 | + tc[2] = g_kiTc0Table(iIndexA)[pBS[2]] + bChroma;\ | |
| 157 | + tc[3] = g_kiTc0Table(iIndexA)[pBS[3]] + bChroma;\ | |
| 158 | +} | |
| 159 | + | |
| 160 | +void inline DeblockingBSInsideMBAvsbase (int8_t* pNnzTab, uint8_t nBS[2][4][4], int32_t iLShiftFactor) { | |
| 161 | + uint32_t uiNnz32b0, uiNnz32b1, uiNnz32b2, uiNnz32b3; | |
| 162 | + | |
| 163 | + uiNnz32b0 = * (uint32_t*) (pNnzTab + 0); | |
| 164 | + uiNnz32b1 = * (uint32_t*) (pNnzTab + 4); | |
| 165 | + uiNnz32b2 = * (uint32_t*) (pNnzTab + 8); | |
| 166 | + uiNnz32b3 = * (uint32_t*) (pNnzTab + 12); | |
| 167 | + | |
| 168 | + nBS[0][1][0] = (pNnzTab[0] | pNnzTab[1]) << iLShiftFactor; | |
| 169 | + nBS[0][2][0] = (pNnzTab[1] | pNnzTab[2]) << iLShiftFactor; | |
| 170 | + nBS[0][3][0] = (pNnzTab[2] | pNnzTab[3]) << iLShiftFactor; | |
| 171 | + | |
| 172 | + nBS[0][1][1] = (pNnzTab[4] | pNnzTab[5]) << iLShiftFactor; | |
| 173 | + nBS[0][2][1] = (pNnzTab[5] | pNnzTab[6]) << iLShiftFactor; | |
| 174 | + nBS[0][3][1] = (pNnzTab[6] | pNnzTab[7]) << iLShiftFactor; | |
| 175 | + * (uint32_t*)nBS[1][1] = (uiNnz32b0 | uiNnz32b1) << iLShiftFactor; | |
| 176 | + | |
| 177 | + nBS[0][1][2] = (pNnzTab[8] | pNnzTab[9]) << iLShiftFactor; | |
| 178 | + nBS[0][2][2] = (pNnzTab[9] | pNnzTab[10]) << iLShiftFactor; | |
| 179 | + nBS[0][3][2] = (pNnzTab[10] | pNnzTab[11]) << iLShiftFactor; | |
| 180 | + * (uint32_t*)nBS[1][2] = (uiNnz32b1 | uiNnz32b2) << iLShiftFactor; | |
| 181 | + | |
| 182 | + nBS[0][1][3] = (pNnzTab[12] | pNnzTab[13]) << iLShiftFactor; | |
| 183 | + nBS[0][2][3] = (pNnzTab[13] | pNnzTab[14]) << iLShiftFactor; | |
| 184 | + nBS[0][3][3] = (pNnzTab[14] | pNnzTab[15]) << iLShiftFactor; | |
| 185 | + * (uint32_t*)nBS[1][3] = (uiNnz32b2 | uiNnz32b3) << iLShiftFactor; | |
| 186 | +} | |
| 187 | + | |
| 188 | +void inline DeblockingBSInsideMBAvsbase8x8 (int8_t* pNnzTab, uint8_t nBS[2][4][4], int32_t iLShiftFactor) { | |
| 189 | + int8_t i8x8NnzTab[4]; | |
| 190 | + for (int32_t i = 0; i < 4; i++) { | |
| 191 | + int32_t iBlkIdx = i << 2; | |
| 192 | + i8x8NnzTab[i] = (pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 1]] | | |
| 193 | + pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 2]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 3]]); | |
| 194 | + } | |
| 195 | + | |
| 196 | + //vertical | |
| 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; | |
| 199 | + //horizontal | |
| 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; | |
| 202 | +} | |
| 203 | + | |
| 204 | +void static inline DeblockingBSInsideMBNormal (PDqLayer pCurDqLayer, uint8_t nBS[2][4][4], int8_t* pNnzTab, | |
| 205 | + int32_t iMbXy) { | |
| 206 | + uint32_t uiNnz32b0, uiNnz32b1, uiNnz32b2, uiNnz32b3; | |
| 207 | + int8_t* iRefIndex = pCurDqLayer->pRefIndex[LIST_0][iMbXy]; | |
| 208 | + ENFORCE_STACK_ALIGN_1D (uint8_t, uiBsx4, 4, 4); | |
| 209 | + | |
| 210 | + int8_t i8x8NnzTab[4]; | |
| 211 | + | |
| 212 | + if (pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { | |
| 213 | + for (int32_t i = 0; i < 4; i++) { | |
| 214 | + int32_t iBlkIdx = i << 2; | |
| 215 | + i8x8NnzTab[i] = (pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 1]] | | |
| 216 | + pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 2]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 3]]); | |
| 217 | + } | |
| 218 | + //vertical | |
| 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]); | |
| 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]); | |
| 223 | + | |
| 224 | + //horizontal | |
| 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]); | |
| 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]); | |
| 229 | + } else { | |
| 230 | + uiNnz32b0 = * (uint32_t*) (pNnzTab + 0); | |
| 231 | + uiNnz32b1 = * (uint32_t*) (pNnzTab + 4); | |
| 232 | + uiNnz32b2 = * (uint32_t*) (pNnzTab + 8); | |
| 233 | + uiNnz32b3 = * (uint32_t*) (pNnzTab + 12); | |
| 234 | + | |
| 235 | + for (int i = 0; i < 3; i++) | |
| 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); | |
| 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); | |
| 240 | + | |
| 241 | + for (int i = 0; i < 3; i++) | |
| 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); | |
| 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); | |
| 246 | + | |
| 247 | + for (int i = 0; i < 3; i++) | |
| 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); | |
| 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); | |
| 252 | + | |
| 253 | + for (int i = 0; i < 3; i++) | |
| 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); | |
| 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); | |
| 258 | + | |
| 259 | + // horizontal | |
| 260 | + * (uint32_t*)uiBsx4 = (uiNnz32b0 | uiNnz32b1); | |
| 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); | |
| 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); | |
| 265 | + | |
| 266 | + * (uint32_t*)uiBsx4 = (uiNnz32b1 | uiNnz32b2); | |
| 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); | |
| 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); | |
| 271 | + | |
| 272 | + * (uint32_t*)uiBsx4 = (uiNnz32b2 | uiNnz32b3); | |
| 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); | |
| 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); | |
| 277 | + } | |
| 278 | +} | |
| 279 | + | |
| 280 | +void static inline DeblockingBSliceBSInsideMBNormal (PDqLayer pCurDqLayer, uint8_t nBS[2][4][4], int8_t* pNnzTab, | |
| 281 | + int32_t iMbXy) { | |
| 282 | + uint32_t uiNnz32b0, uiNnz32b1, uiNnz32b2, uiNnz32b3; | |
| 283 | + int8_t* iRefIndex[LIST_A]; | |
| 284 | + iRefIndex[LIST_0] = pCurDqLayer->pRefIndex[LIST_0][iMbXy]; | |
| 285 | + iRefIndex[LIST_1] = pCurDqLayer->pRefIndex[LIST_1][iMbXy]; | |
| 286 | + ENFORCE_STACK_ALIGN_1D (uint8_t, uiBsx4, 4, 4); | |
| 287 | + | |
| 288 | + int8_t i8x8NnzTab[4]; | |
| 289 | + | |
| 290 | + if (pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { | |
| 291 | + for (int32_t i = 0; i < 4; i++) { | |
| 292 | + int32_t iBlkIdx = i << 2; | |
| 293 | + i8x8NnzTab[i] = (pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 1]] | | |
| 294 | + pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 2]] | pNnzTab[g_kuiMbCountScan4Idx[iBlkIdx + 3]]); | |
| 295 | + } | |
| 296 | + //vertical | |
| 297 | + int8_t iIndex = g_kuiMbCountScan4Idx[1 << 2]; | |
| 298 | + int8_t iNeigborIndex = g_kuiMbCountScan4Idx[0]; | |
| 299 | + nBS[0][2][0] = nBS[0][2][1] = 1; | |
| 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) { | |
| 302 | + nBS[0][2][0] = nBS[0][2][1] = BS_EDGE ((i8x8NnzTab[0] | i8x8NnzTab[1]), iRefIndex[listIdx], | |
| 303 | + pCurDqLayer->pMv[listIdx][iMbXy], | |
| 304 | + iIndex, iNeigborIndex); | |
| 305 | + break; | |
| 306 | + } | |
| 307 | + } | |
| 308 | + iIndex = g_kuiMbCountScan4Idx[3 << 2]; | |
| 309 | + iNeigborIndex = g_kuiMbCountScan4Idx[2 << 2]; | |
| 310 | + nBS[0][2][2] = nBS[0][2][3] = 1; | |
| 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) { | |
| 313 | + nBS[0][2][2] = nBS[0][2][3] = BS_EDGE ((i8x8NnzTab[2] | i8x8NnzTab[3]), iRefIndex[listIdx], | |
| 314 | + pCurDqLayer->pMv[listIdx][iMbXy], | |
| 315 | + iIndex, iNeigborIndex); | |
| 316 | + break; | |
| 317 | + } | |
| 318 | + } | |
| 319 | + | |
| 320 | + //horizontal | |
| 321 | + iIndex = g_kuiMbCountScan4Idx[2 << 2]; | |
| 322 | + iNeigborIndex = g_kuiMbCountScan4Idx[0]; | |
| 323 | + nBS[1][2][0] = nBS[1][2][1] = 1; | |
| 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) { | |
| 326 | + nBS[1][2][0] = nBS[1][2][1] = BS_EDGE ((i8x8NnzTab[0] | i8x8NnzTab[2]), iRefIndex[listIdx], | |
| 327 | + pCurDqLayer->pMv[listIdx][iMbXy], | |
| 328 | + iIndex, iNeigborIndex); | |
| 329 | + break; | |
| 330 | + } | |
| 331 | + } | |
| 332 | + | |
| 333 | + iIndex = g_kuiMbCountScan4Idx[3 << 2]; | |
| 334 | + iNeigborIndex = g_kuiMbCountScan4Idx[1 << 2]; | |
| 335 | + nBS[1][2][2] = nBS[1][2][3] = 1; | |
| 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) { | |
| 338 | + nBS[1][2][2] = nBS[1][2][3] = BS_EDGE ((i8x8NnzTab[1] | i8x8NnzTab[3]), iRefIndex[listIdx], | |
| 339 | + pCurDqLayer->pMv[listIdx][iMbXy], | |
| 340 | + iIndex, iNeigborIndex); | |
| 341 | + break; | |
| 342 | + } | |
| 343 | + } | |
| 344 | + } else { | |
| 345 | + uiNnz32b0 = * (uint32_t*) (pNnzTab + 0); | |
| 346 | + uiNnz32b1 = * (uint32_t*) (pNnzTab + 4); | |
| 347 | + uiNnz32b2 = * (uint32_t*) (pNnzTab + 8); | |
| 348 | + uiNnz32b3 = * (uint32_t*) (pNnzTab + 12); | |
| 349 | + | |
| 350 | + for (int i = 0; i < 3; i++) | |
| 351 | + uiBsx4[i] = pNnzTab[i] | pNnzTab[i + 1]; | |
| 352 | + nBS[0][1][0] = 1; | |
| 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) { | |
| 355 | + nBS[0][1][0] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 1, 0); | |
| 356 | + break; | |
| 357 | + } | |
| 358 | + } | |
| 359 | + nBS[0][2][0] = 1; | |
| 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) { | |
| 362 | + nBS[0][2][0] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 2, 1); | |
| 363 | + break; | |
| 364 | + } | |
| 365 | + } | |
| 366 | + nBS[0][3][0] = 1; | |
| 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) { | |
| 369 | + nBS[0][3][0] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 3, 2); | |
| 370 | + break; | |
| 371 | + } | |
| 372 | + } | |
| 373 | + | |
| 374 | + for (int i = 0; i < 3; i++) | |
| 375 | + uiBsx4[i] = pNnzTab[4 + i] | pNnzTab[4 + i + 1]; | |
| 376 | + nBS[0][1][1] = 1; | |
| 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) { | |
| 379 | + nBS[0][1][1] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 5, 4); | |
| 380 | + break; | |
| 381 | + } | |
| 382 | + } | |
| 383 | + nBS[0][2][1] = 1; | |
| 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) { | |
| 386 | + nBS[0][2][1] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 6, 5); | |
| 387 | + break; | |
| 388 | + } | |
| 389 | + } | |
| 390 | + nBS[0][3][1] = 1; | |
| 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) { | |
| 393 | + nBS[0][3][1] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 7, 6); | |
| 394 | + break; | |
| 395 | + } | |
| 396 | + } | |
| 397 | + | |
| 398 | + for (int i = 0; i < 3; i++) | |
| 399 | + uiBsx4[i] = pNnzTab[8 + i] | pNnzTab[8 + i + 1]; | |
| 400 | + nBS[0][1][2] = 1; | |
| 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) { | |
| 403 | + nBS[0][1][2] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 9, 8); | |
| 404 | + break; | |
| 405 | + } | |
| 406 | + } | |
| 407 | + nBS[0][2][2] = 1; | |
| 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) { | |
| 410 | + nBS[0][2][2] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 10, 9); | |
| 411 | + break; | |
| 412 | + } | |
| 413 | + } | |
| 414 | + nBS[0][3][2] = 1; | |
| 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) { | |
| 417 | + nBS[0][3][2] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 11, 10); | |
| 418 | + break; | |
| 419 | + } | |
| 420 | + } | |
| 421 | + | |
| 422 | + for (int i = 0; i < 3; i++) | |
| 423 | + uiBsx4[i] = pNnzTab[12 + i] | pNnzTab[12 + i + 1]; | |
| 424 | + nBS[0][1][3] = 1; | |
| 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) { | |
| 427 | + nBS[0][1][3] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 13, 12); | |
| 428 | + break; | |
| 429 | + } | |
| 430 | + } | |
| 431 | + nBS[0][2][3] = 1; | |
| 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) { | |
| 434 | + nBS[0][2][3] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 14, 13); | |
| 435 | + break; | |
| 436 | + } | |
| 437 | + } | |
| 438 | + nBS[0][3][3] = 1; | |
| 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) { | |
| 441 | + nBS[0][3][3] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 15, 14); | |
| 442 | + break; | |
| 443 | + } | |
| 444 | + } | |
| 445 | + | |
| 446 | + // horizontal | |
| 447 | + * (uint32_t*)uiBsx4 = (uiNnz32b0 | uiNnz32b1); | |
| 448 | + nBS[1][1][0] = 1; | |
| 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) { | |
| 451 | + nBS[1][1][0] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 4, 0); | |
| 452 | + break; | |
| 453 | + } | |
| 454 | + } | |
| 455 | + nBS[1][1][1] = 1; | |
| 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) { | |
| 458 | + nBS[1][1][1] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 5, 1); | |
| 459 | + break; | |
| 460 | + } | |
| 461 | + } | |
| 462 | + nBS[1][1][2] = 1; | |
| 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) { | |
| 465 | + nBS[1][1][2] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 6, 2); | |
| 466 | + break; | |
| 467 | + } | |
| 468 | + } | |
| 469 | + nBS[1][1][3] = 1; | |
| 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) { | |
| 472 | + nBS[1][1][3] = BS_EDGE (uiBsx4[3], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 7, 3); | |
| 473 | + break; | |
| 474 | + } | |
| 475 | + } | |
| 476 | + | |
| 477 | + * (uint32_t*)uiBsx4 = (uiNnz32b1 | uiNnz32b2); | |
| 478 | + nBS[1][2][0] = 1; | |
| 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) { | |
| 481 | + nBS[1][2][0] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 8, 4); | |
| 482 | + break; | |
| 483 | + } | |
| 484 | + } | |
| 485 | + nBS[1][2][1] = 1; | |
| 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) { | |
| 488 | + nBS[1][2][1] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 9, 5); | |
| 489 | + break; | |
| 490 | + } | |
| 491 | + } | |
| 492 | + nBS[1][2][2] = 1; | |
| 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) { | |
| 495 | + nBS[1][2][2] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 10, 6); | |
| 496 | + break; | |
| 497 | + } | |
| 498 | + } | |
| 499 | + nBS[1][2][3] = 1; | |
| 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) { | |
| 502 | + nBS[1][2][3] = BS_EDGE (uiBsx4[3], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 11, 7); | |
| 503 | + break; | |
| 504 | + } | |
| 505 | + } | |
| 506 | + | |
| 507 | + * (uint32_t*)uiBsx4 = (uiNnz32b2 | uiNnz32b3); | |
| 508 | + nBS[1][3][0] = 1; | |
| 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) { | |
| 511 | + nBS[1][3][0] = BS_EDGE (uiBsx4[0], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 12, 8); | |
| 512 | + break; | |
| 513 | + } | |
| 514 | + } | |
| 515 | + nBS[1][3][1] = 1; | |
| 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) { | |
| 518 | + nBS[1][3][1] = BS_EDGE (uiBsx4[1], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 13, 9); | |
| 519 | + break; | |
| 520 | + } | |
| 521 | + } | |
| 522 | + nBS[1][3][2] = 1; | |
| 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) { | |
| 525 | + nBS[1][3][2] = BS_EDGE (uiBsx4[2], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 14, 10); | |
| 526 | + break; | |
| 527 | + } | |
| 528 | + } | |
| 529 | + nBS[1][3][3] = 1; | |
| 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) { | |
| 532 | + nBS[1][3][3] = BS_EDGE (uiBsx4[3], iRefIndex[listIdx], pCurDqLayer->pMv[listIdx][iMbXy], 15, 11); | |
| 533 | + break; | |
| 534 | + } | |
| 535 | + } | |
| 536 | + } | |
| 537 | +} | |
| 538 | + | |
| 539 | + | |
| 540 | +uint32_t DeblockingBsMarginalMBAvcbase (PDqLayer pCurDqLayer, int32_t iEdge, int32_t iNeighMb, int32_t iMbXy) { | |
| 541 | + int32_t i, j; | |
| 542 | + uint32_t uiBSx4; | |
| 543 | + uint8_t* pBS = (uint8_t*) (&uiBSx4); | |
| 544 | + const uint8_t* pBIdx = &g_kuiTableBIdx[iEdge][0]; | |
| 545 | + const uint8_t* pBnIdx = &g_kuiTableBIdx[iEdge][4]; | |
| 546 | + const uint8_t* pB8x8Idx = &g_kuiTableB8x8Idx[iEdge][0]; | |
| 547 | + const uint8_t* pBn8x8Idx = &g_kuiTableB8x8Idx[iEdge][8]; | |
| 548 | + | |
| 549 | + if (pCurDqLayer->pTransformSize8x8Flag[iMbXy] && pCurDqLayer->pTransformSize8x8Flag[iNeighMb]) { | |
| 550 | + for (i = 0; i < 2; i++) { | |
| 551 | + uint8_t uiNzc = 0; | |
| 552 | + for (j = 0; uiNzc == 0 && j < 4; j++) { | |
| 553 | + uiNzc |= (pCurDqLayer->pNzc[iMbXy][* (pB8x8Idx + j)] | pCurDqLayer->pNzc[iNeighMb][* (pBn8x8Idx + j)]); | |
| 554 | + } | |
| 555 | + if (uiNzc) { | |
| 556 | + pBS[i << 1] = pBS[1 + (i << 1)] = 2; | |
| 557 | + } else { | |
| 558 | + pBS[i << 1] = pBS[1 + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[LIST_0], pCurDqLayer->pMv[LIST_0], iMbXy, iNeighMb, | |
| 559 | + *pB8x8Idx, *pBn8x8Idx); | |
| 560 | + } | |
| 561 | + pB8x8Idx += 4; | |
| 562 | + pBn8x8Idx += 4; | |
| 563 | + } | |
| 564 | + } else if (pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { | |
| 565 | + for (i = 0; i < 2; i++) { | |
| 566 | + uint8_t uiNzc = 0; | |
| 567 | + for (j = 0; uiNzc == 0 && j < 4; j++) { | |
| 568 | + uiNzc |= pCurDqLayer->pNzc[iMbXy][* (pB8x8Idx + j)]; | |
| 569 | + } | |
| 570 | + for (j = 0; j < 2; j++) { | |
| 571 | + if (uiNzc | pCurDqLayer->pNzc[iNeighMb][*pBnIdx]) { | |
| 572 | + pBS[j + (i << 1)] = 2; | |
| 573 | + } else { | |
| 574 | + pBS[j + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[LIST_0], pCurDqLayer->pMv[LIST_0], iMbXy, iNeighMb, *pB8x8Idx, | |
| 575 | + *pBnIdx); | |
| 576 | + } | |
| 577 | + pBnIdx++; | |
| 578 | + } | |
| 579 | + pB8x8Idx += 4; | |
| 580 | + } | |
| 581 | + } else if (pCurDqLayer->pTransformSize8x8Flag[iNeighMb]) { | |
| 582 | + for (i = 0; i < 2; i++) { | |
| 583 | + uint8_t uiNzc = 0; | |
| 584 | + for (j = 0; uiNzc == 0 && j < 4; j++) { | |
| 585 | + uiNzc |= pCurDqLayer->pNzc[iNeighMb][* (pBn8x8Idx + j)]; | |
| 586 | + } | |
| 587 | + for (j = 0; j < 2; j++) { | |
| 588 | + if (uiNzc | pCurDqLayer->pNzc[iMbXy][*pBIdx]) { | |
| 589 | + pBS[j + (i << 1)] = 2; | |
| 590 | + } else { | |
| 591 | + pBS[j + (i << 1)] = MB_BS_MV (pCurDqLayer->pRefIndex[LIST_0], pCurDqLayer->pMv[LIST_0], iMbXy, iNeighMb, *pBIdx, | |
| 592 | + *pBn8x8Idx); | |
| 593 | + } | |
| 594 | + pBIdx++; | |
| 595 | + } | |
| 596 | + pBn8x8Idx += 4; | |
| 597 | + } | |
| 598 | + } else { | |
| 599 | + // only 4x4 transform | |
| 600 | + for (i = 0; i < 4; i++) { | |
| 601 | + if (pCurDqLayer->pNzc[iMbXy][*pBIdx] | pCurDqLayer->pNzc[iNeighMb][*pBnIdx]) { | |
| 602 | + pBS[i] = 2; | |
| 603 | + } else { | |
| 604 | + pBS[i] = MB_BS_MV (pCurDqLayer->pRefIndex[LIST_0], pCurDqLayer->pMv[LIST_0], iMbXy, iNeighMb, *pBIdx, | |
| 605 | + *pBnIdx); | |
| 606 | + } | |
| 607 | + pBIdx++; | |
| 608 | + pBnIdx++; | |
| 609 | + } | |
| 610 | + } | |
| 611 | + | |
| 612 | + return uiBSx4; | |
| 613 | +} | |
| 614 | +uint32_t DeblockingBSliceBsMarginalMBAvcbase (PDqLayer pCurDqLayer, int32_t iEdge, int32_t iNeighMb, int32_t iMbXy) { | |
| 615 | + int32_t i, j; | |
| 616 | + uint32_t uiBSx4; | |
| 617 | + uint8_t* pBS = (uint8_t*) (&uiBSx4); | |
| 618 | + const uint8_t* pBIdx = &g_kuiTableBIdx[iEdge][0]; | |
| 619 | + const uint8_t* pBnIdx = &g_kuiTableBIdx[iEdge][4]; | |
| 620 | + const uint8_t* pB8x8Idx = &g_kuiTableB8x8Idx[iEdge][0]; | |
| 621 | + const uint8_t* pBn8x8Idx = &g_kuiTableB8x8Idx[iEdge][8]; | |
| 622 | + | |
| 623 | + if (pCurDqLayer->pTransformSize8x8Flag[iMbXy] && pCurDqLayer->pTransformSize8x8Flag[iNeighMb]) { | |
| 624 | + for (i = 0; i < 2; i++) { | |
| 625 | + uint8_t uiNzc = 0; | |
| 626 | + for (j = 0; uiNzc == 0 && j < 4; j++) { | |
| 627 | + uiNzc |= (pCurDqLayer->pNzc[iMbXy][* (pB8x8Idx + j)] | pCurDqLayer->pNzc[iNeighMb][* (pBn8x8Idx + j)]); | |
| 628 | + } | |
| 629 | + if (uiNzc) { | |
| 630 | + pBS[i << 1] = pBS[1 + (i << 1)] = 2; | |
| 631 | + } else { | |
| 632 | + pBS[i << 1] = pBS[1 + (i << 1)] = 1; | |
| 633 | + for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 634 | + if (pCurDqLayer->pRefIndex[listIdx][iMbXy][*pB8x8Idx] > 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, | |
| 637 | + *pB8x8Idx, *pBn8x8Idx); | |
| 638 | + break; | |
| 639 | + } | |
| 640 | + } | |
| 641 | + } | |
| 642 | + pB8x8Idx += 4; | |
| 643 | + pBn8x8Idx += 4; | |
| 644 | + } | |
| 645 | + } else if (pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { | |
| 646 | + for (i = 0; i < 2; i++) { | |
| 647 | + uint8_t uiNzc = 0; | |
| 648 | + for (j = 0; uiNzc == 0 && j < 4; j++) { | |
| 649 | + uiNzc |= pCurDqLayer->pNzc[iMbXy][* (pB8x8Idx + j)]; | |
| 650 | + } | |
| 651 | + for (j = 0; j < 2; j++) { | |
| 652 | + if (uiNzc | pCurDqLayer->pNzc[iNeighMb][*pBnIdx]) { | |
| 653 | + pBS[j + (i << 1)] = 2; | |
| 654 | + } else { | |
| 655 | + pBS[j + (i << 1)] = 1; | |
| 656 | + for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 657 | + if (pCurDqLayer->pRefIndex[listIdx][iMbXy][*pB8x8Idx] > 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, | |
| 660 | + *pBnIdx); | |
| 661 | + break; | |
| 662 | + } | |
| 663 | + } | |
| 664 | + } | |
| 665 | + pBnIdx++; | |
| 666 | + } | |
| 667 | + pB8x8Idx += 4; | |
| 668 | + } | |
| 669 | + } else if (pCurDqLayer->pTransformSize8x8Flag[iNeighMb]) { | |
| 670 | + for (i = 0; i < 2; i++) { | |
| 671 | + uint8_t uiNzc = 0; | |
| 672 | + for (j = 0; uiNzc == 0 && j < 4; j++) { | |
| 673 | + uiNzc |= pCurDqLayer->pNzc[iNeighMb][* (pBn8x8Idx + j)]; | |
| 674 | + } | |
| 675 | + for (j = 0; j < 2; j++) { | |
| 676 | + if (uiNzc | pCurDqLayer->pNzc[iMbXy][*pBIdx]) { | |
| 677 | + pBS[j + (i << 1)] = 2; | |
| 678 | + } else { | |
| 679 | + pBS[j + (i << 1)] = 1; | |
| 680 | + for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 681 | + if (pCurDqLayer->pRefIndex[listIdx][iMbXy][*pBIdx] > 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, | |
| 684 | + *pBn8x8Idx); | |
| 685 | + break; | |
| 686 | + } | |
| 687 | + } | |
| 688 | + } | |
| 689 | + pBIdx++; | |
| 690 | + } | |
| 691 | + pBn8x8Idx += 4; | |
| 692 | + } | |
| 693 | + } else { | |
| 694 | + // only 4x4 transform | |
| 695 | + for (i = 0; i < 4; i++) { | |
| 696 | + if (pCurDqLayer->pNzc[iMbXy][*pBIdx] | pCurDqLayer->pNzc[iNeighMb][*pBnIdx]) { | |
| 697 | + pBS[i] = 2; | |
| 698 | + } else { | |
| 699 | + pBS[i] = 1; | |
| 700 | + for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 701 | + if (pCurDqLayer->pRefIndex[listIdx][iMbXy][*pBIdx] > 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); | |
| 704 | + break; | |
| 705 | + } | |
| 706 | + } | |
| 707 | + } | |
| 708 | + pBIdx++; | |
| 709 | + pBnIdx++; | |
| 710 | + } | |
| 711 | + } | |
| 712 | + | |
| 713 | + return uiBSx4; | |
| 714 | +} | |
| 715 | +int32_t DeblockingAvailableNoInterlayer (PDqLayer pCurDqLayer, int32_t iFilterIdc) { | |
| 716 | + int32_t iMbY = pCurDqLayer->iMbY; | |
| 717 | + int32_t iMbX = pCurDqLayer->iMbX; | |
| 718 | + int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 719 | + bool bLeftFlag = false; | |
| 720 | + bool bTopFlag = false; | |
| 721 | + | |
| 722 | + if (2 == iFilterIdc) { | |
| 723 | + bLeftFlag = (iMbX > 0) && (pCurDqLayer->pSliceIdc[iMbXy] == pCurDqLayer->pSliceIdc[iMbXy - 1]); | |
| 724 | + bTopFlag = (iMbY > 0) && (pCurDqLayer->pSliceIdc[iMbXy] == pCurDqLayer->pSliceIdc[iMbXy - pCurDqLayer->iMbWidth]); | |
| 725 | + } else { //if ( 0 == iFilterIdc ) | |
| 726 | + bLeftFlag = (iMbX > 0); | |
| 727 | + bTopFlag = (iMbY > 0); | |
| 728 | + } | |
| 729 | + return (bLeftFlag << LEFT_FLAG_BIT) | (bTopFlag << TOP_FLAG_BIT); | |
| 730 | +} | |
| 731 | + | |
| 732 | +void FilteringEdgeLumaH (SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS) { | |
| 733 | + int32_t iIndexA; | |
| 734 | + int32_t iAlpha; | |
| 735 | + int32_t iBeta; | |
| 736 | + ENFORCE_STACK_ALIGN_1D (int8_t, tc, 4, 16); | |
| 737 | + | |
| 738 | + GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 739 | + iBeta); | |
| 740 | + | |
| 741 | + if (iAlpha | iBeta) { | |
| 742 | + TC0_TBL_LOOKUP (tc, iIndexA, pBS, 0); | |
| 743 | + pFilter->pLoopf->pfLumaDeblockingLT4Ver (pPix, iStride, iAlpha, iBeta, tc); | |
| 744 | + } | |
| 745 | + return; | |
| 746 | +} | |
| 747 | + | |
| 748 | + | |
| 749 | +void FilteringEdgeLumaV (SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS) { | |
| 750 | + int32_t iIndexA; | |
| 751 | + int32_t iAlpha; | |
| 752 | + int32_t iBeta; | |
| 753 | + ENFORCE_STACK_ALIGN_1D (int8_t, tc, 4, 16); | |
| 754 | + | |
| 755 | + GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 756 | + iBeta); | |
| 757 | + | |
| 758 | + if (iAlpha | iBeta) { | |
| 759 | + TC0_TBL_LOOKUP (tc, iIndexA, pBS, 0); | |
| 760 | + pFilter->pLoopf->pfLumaDeblockingLT4Hor (pPix, iStride, iAlpha, iBeta, tc); | |
| 761 | + } | |
| 762 | + return; | |
| 763 | +} | |
| 764 | + | |
| 765 | + | |
| 766 | +void FilteringEdgeLumaIntraH (SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS) { | |
| 767 | + int32_t iIndexA; | |
| 768 | + int32_t iAlpha; | |
| 769 | + int32_t iBeta; | |
| 770 | + | |
| 771 | + GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 772 | + iBeta); | |
| 773 | + | |
| 774 | + if (iAlpha | iBeta) { | |
| 775 | + pFilter->pLoopf->pfLumaDeblockingEQ4Ver (pPix, iStride, iAlpha, iBeta); | |
| 776 | + } | |
| 777 | + return; | |
| 778 | +} | |
| 779 | + | |
| 780 | +void FilteringEdgeLumaIntraV (SDeblockingFilter* pFilter, uint8_t* pPix, int32_t iStride, uint8_t* pBS) { | |
| 781 | + int32_t iIndexA; | |
| 782 | + int32_t iAlpha; | |
| 783 | + int32_t iBeta; | |
| 784 | + | |
| 785 | + GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 786 | + iBeta); | |
| 787 | + | |
| 788 | + if (iAlpha | iBeta) { | |
| 789 | + pFilter->pLoopf->pfLumaDeblockingEQ4Hor (pPix, iStride, iAlpha, iBeta); | |
| 790 | + } | |
| 791 | + return; | |
| 792 | +} | |
| 793 | +void FilteringEdgeChromaH (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, | |
| 794 | + uint8_t* pBS) { | |
| 795 | + int32_t iIndexA; | |
| 796 | + int32_t iAlpha; | |
| 797 | + int32_t iBeta; | |
| 798 | + ENFORCE_STACK_ALIGN_1D (int8_t, tc, 4, 16); | |
| 799 | + if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) { | |
| 800 | + | |
| 801 | + GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 802 | + iBeta); | |
| 803 | + | |
| 804 | + if (iAlpha | iBeta) { | |
| 805 | + TC0_TBL_LOOKUP (tc, iIndexA, pBS, 1); | |
| 806 | + pFilter->pLoopf->pfChromaDeblockingLT4Ver (pPixCb, pPixCr, iStride, iAlpha, iBeta, tc); | |
| 807 | + } | |
| 808 | + } else { | |
| 809 | + | |
| 810 | + for (int i = 0; i < 2; i++) { | |
| 811 | + | |
| 812 | + | |
| 813 | + GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 814 | + iBeta); | |
| 815 | + | |
| 816 | + if (iAlpha | iBeta) { | |
| 817 | + uint8_t* pPixCbCr = (i == 0) ? pPixCb : pPixCr; | |
| 818 | + TC0_TBL_LOOKUP (tc, iIndexA, pBS, 1); | |
| 819 | + pFilter->pLoopf->pfChromaDeblockingLT4Ver2 (pPixCbCr, iStride, iAlpha, iBeta, tc); | |
| 820 | + } | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + } | |
| 825 | + | |
| 826 | + } | |
| 827 | + return; | |
| 828 | +} | |
| 829 | +void FilteringEdgeChromaV (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, | |
| 830 | + uint8_t* pBS) { | |
| 831 | + int32_t iIndexA; | |
| 832 | + int32_t iAlpha; | |
| 833 | + int32_t iBeta; | |
| 834 | + ENFORCE_STACK_ALIGN_1D (int8_t, tc, 4, 16); | |
| 835 | + if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) { | |
| 836 | + | |
| 837 | + | |
| 838 | + GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 839 | + iBeta); | |
| 840 | + | |
| 841 | + if (iAlpha | iBeta) { | |
| 842 | + TC0_TBL_LOOKUP (tc, iIndexA, pBS, 1); | |
| 843 | + pFilter->pLoopf->pfChromaDeblockingLT4Hor (pPixCb, pPixCr, iStride, iAlpha, iBeta, tc); | |
| 844 | + } | |
| 845 | + | |
| 846 | + | |
| 847 | + } else { | |
| 848 | + | |
| 849 | + for (int i = 0; i < 2; i++) { | |
| 850 | + | |
| 851 | + GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 852 | + iBeta); | |
| 853 | + | |
| 854 | + if (iAlpha | iBeta) { | |
| 855 | + uint8_t* pPixCbCr = (i == 0) ? pPixCb : pPixCr; | |
| 856 | + TC0_TBL_LOOKUP (tc, iIndexA, pBS, 1); | |
| 857 | + pFilter->pLoopf->pfChromaDeblockingLT4Hor2 (pPixCbCr, iStride, iAlpha, iBeta, tc); | |
| 858 | + } | |
| 859 | + | |
| 860 | + | |
| 861 | + } | |
| 862 | + } | |
| 863 | + return; | |
| 864 | +} | |
| 865 | + | |
| 866 | +void FilteringEdgeChromaIntraH (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, | |
| 867 | + uint8_t* pBS) { | |
| 868 | + int32_t iIndexA; | |
| 869 | + int32_t iAlpha; | |
| 870 | + int32_t iBeta; | |
| 871 | + if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) { | |
| 872 | + | |
| 873 | + GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 874 | + iBeta); | |
| 875 | + | |
| 876 | + if (iAlpha | iBeta) { | |
| 877 | + pFilter->pLoopf->pfChromaDeblockingEQ4Ver (pPixCb, pPixCr, iStride, iAlpha, iBeta); | |
| 878 | + } | |
| 879 | + } else { | |
| 880 | + | |
| 881 | + for (int i = 0; i < 2; i++) { | |
| 882 | + | |
| 883 | + GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 884 | + iBeta); | |
| 885 | + | |
| 886 | + if (iAlpha | iBeta) { | |
| 887 | + uint8_t* pPixCbCr = (i == 0) ? pPixCb : pPixCr; | |
| 888 | + pFilter->pLoopf->pfChromaDeblockingEQ4Ver2 (pPixCbCr, iStride, iAlpha, iBeta); | |
| 889 | + } | |
| 890 | + | |
| 891 | + } | |
| 892 | + } | |
| 893 | + return; | |
| 894 | +} | |
| 895 | + | |
| 896 | +void FilteringEdgeChromaIntraV (SDeblockingFilter* pFilter, uint8_t* pPixCb, uint8_t* pPixCr, int32_t iStride, | |
| 897 | + uint8_t* pBS) { | |
| 898 | + int32_t iIndexA; | |
| 899 | + int32_t iAlpha; | |
| 900 | + int32_t iBeta; | |
| 901 | + if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) { // QP of cb and cr are the same | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 907 | + iBeta); | |
| 908 | + if (iAlpha | iBeta) { | |
| 909 | + pFilter->pLoopf->pfChromaDeblockingEQ4Hor (pPixCb, pPixCr, iStride, iAlpha, iBeta); | |
| 910 | + } | |
| 911 | + } else { | |
| 912 | + | |
| 913 | + for (int i = 0; i < 2; i++) { | |
| 914 | + | |
| 915 | + | |
| 916 | + GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 917 | + iBeta); | |
| 918 | + if (iAlpha | iBeta) { | |
| 919 | + uint8_t* pPixCbCr = (i == 0) ? pPixCb : pPixCr; | |
| 920 | + pFilter->pLoopf->pfChromaDeblockingEQ4Hor2 (pPixCbCr, iStride, iAlpha, iBeta); | |
| 921 | + } | |
| 922 | + } | |
| 923 | + | |
| 924 | + } | |
| 925 | + return; | |
| 926 | +} | |
| 927 | + | |
| 928 | + | |
| 929 | +void DeblockingInterMb (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, uint8_t nBS[2][4][4], | |
| 930 | + int32_t iBoundryFlag) { | |
| 931 | + int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex; | |
| 932 | + int32_t iMbX = pCurDqLayer->iMbX; | |
| 933 | + int32_t iMbY = pCurDqLayer->iMbY; | |
| 934 | + | |
| 935 | + int32_t iCurLumaQp = pCurDqLayer->pLumaQp[iMbXyIndex]; | |
| 936 | + //int32_t* iCurChromaQp = pCurDqLayer->pChromaQp[iMbXyIndex]; | |
| 937 | + int8_t* pCurChromaQp = pCurDqLayer->pChromaQp[iMbXyIndex]; | |
| 938 | + int32_t iLineSize = pFilter->iCsStride[0]; | |
| 939 | + int32_t iLineSizeUV = pFilter->iCsStride[1]; | |
| 940 | + | |
| 941 | + uint8_t* pDestY, * pDestCb, * pDestCr; | |
| 942 | + pDestY = pFilter->pCsData[0] + ((iMbY * iLineSize + iMbX) << 4); | |
| 943 | + pDestCb = pFilter->pCsData[1] + ((iMbY * iLineSizeUV + iMbX) << 3); | |
| 944 | + pDestCr = pFilter->pCsData[2] + ((iMbY * iLineSizeUV + iMbX) << 3); | |
| 945 | + | |
| 946 | +//Vertical margrin | |
| 947 | + if (iBoundryFlag & LEFT_FLAG_MASK) { | |
| 948 | + int32_t iLeftXyIndex = iMbXyIndex - 1; | |
| 949 | + pFilter->iLumaQP = (iCurLumaQp + pCurDqLayer->pLumaQp[iLeftXyIndex] + 1) >> 1; | |
| 950 | + for (int i = 0; i < 2; i++) { | |
| 951 | + pFilter->iChromaQP[i] = (pCurChromaQp[i] + pCurDqLayer->pChromaQp[iLeftXyIndex][i] + 1) >> 1; | |
| 952 | + } | |
| 953 | + if (nBS[0][0][0] == 0x04) { | |
| 954 | + FilteringEdgeLumaIntraV (pFilter, pDestY, iLineSize, NULL); | |
| 955 | + FilteringEdgeChromaIntraV (pFilter, pDestCb, pDestCr, iLineSizeUV, NULL); | |
| 956 | + } else { | |
| 957 | + if (* (uint32_t*)nBS[0][0] != 0) { | |
| 958 | + FilteringEdgeLumaV (pFilter, pDestY, iLineSize, nBS[0][0]); | |
| 959 | + FilteringEdgeChromaV (pFilter, pDestCb, pDestCr, iLineSizeUV, nBS[0][0]); | |
| 960 | + } | |
| 961 | + } | |
| 962 | + } | |
| 963 | + | |
| 964 | + pFilter->iLumaQP = iCurLumaQp; | |
| 965 | + pFilter->iChromaQP[0] = pCurChromaQp[0]; | |
| 966 | + pFilter->iChromaQP[1] = pCurChromaQp[1]; | |
| 967 | + | |
| 968 | + if (* (uint32_t*)nBS[0][1] != 0 && !pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) { | |
| 969 | + FilteringEdgeLumaV (pFilter, &pDestY[1 << 2], iLineSize, nBS[0][1]); | |
| 970 | + } | |
| 971 | + | |
| 972 | + if (* (uint32_t*)nBS[0][2] != 0) { | |
| 973 | + FilteringEdgeLumaV (pFilter, &pDestY[2 << 2], iLineSize, nBS[0][2]); | |
| 974 | + FilteringEdgeChromaV (pFilter, &pDestCb[2 << 1], &pDestCr[2 << 1], iLineSizeUV, nBS[0][2]); | |
| 975 | + } | |
| 976 | + | |
| 977 | + if (* (uint32_t*)nBS[0][3] != 0 && !pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) { | |
| 978 | + FilteringEdgeLumaV (pFilter, &pDestY[3 << 2], iLineSize, nBS[0][3]); | |
| 979 | + } | |
| 980 | + | |
| 981 | + if (iBoundryFlag & TOP_FLAG_MASK) { | |
| 982 | + int32_t iTopXyIndex = iMbXyIndex - pCurDqLayer->iMbWidth; | |
| 983 | + pFilter->iLumaQP = (iCurLumaQp + pCurDqLayer->pLumaQp[iTopXyIndex] + 1) >> 1; | |
| 984 | + for (int i = 0; i < 2; i++) { | |
| 985 | + pFilter->iChromaQP[i] = (pCurChromaQp[i] + pCurDqLayer->pChromaQp[iTopXyIndex][i] + 1) >> 1; | |
| 986 | + } | |
| 987 | + | |
| 988 | + if (nBS[1][0][0] == 0x04) { | |
| 989 | + FilteringEdgeLumaIntraH (pFilter, pDestY, iLineSize, NULL); | |
| 990 | + FilteringEdgeChromaIntraH (pFilter, pDestCb, pDestCr, iLineSizeUV, NULL); | |
| 991 | + } else { | |
| 992 | + if (* (uint32_t*)nBS[1][0] != 0) { | |
| 993 | + FilteringEdgeLumaH (pFilter, pDestY, iLineSize, nBS[1][0]); | |
| 994 | + FilteringEdgeChromaH (pFilter, pDestCb, pDestCr, iLineSizeUV, nBS[1][0]); | |
| 995 | + } | |
| 996 | + } | |
| 997 | + } | |
| 998 | + | |
| 999 | + pFilter->iLumaQP = iCurLumaQp; | |
| 1000 | + pFilter->iChromaQP[0] = pCurChromaQp[0]; | |
| 1001 | + pFilter->iChromaQP[1] = pCurChromaQp[1]; | |
| 1002 | + | |
| 1003 | + if (* (uint32_t*)nBS[1][1] != 0 && !pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) { | |
| 1004 | + FilteringEdgeLumaH (pFilter, &pDestY[ (1 << 2)*iLineSize], iLineSize, nBS[1][1]); | |
| 1005 | + } | |
| 1006 | + | |
| 1007 | + if (* (uint32_t*)nBS[1][2] != 0) { | |
| 1008 | + FilteringEdgeLumaH (pFilter, &pDestY[ (2 << 2)*iLineSize], iLineSize, nBS[1][2]); | |
| 1009 | + FilteringEdgeChromaH (pFilter, &pDestCb[ (2 << 1)*iLineSizeUV], &pDestCr[ (2 << 1)*iLineSizeUV], iLineSizeUV, | |
| 1010 | + nBS[1][2]); | |
| 1011 | + } | |
| 1012 | + | |
| 1013 | + if (* (uint32_t*)nBS[1][3] != 0 && !pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) { | |
| 1014 | + FilteringEdgeLumaH (pFilter, &pDestY[ (3 << 2)*iLineSize], iLineSize, nBS[1][3]); | |
| 1015 | + } | |
| 1016 | +} | |
| 1017 | + | |
| 1018 | +void FilteringEdgeLumaHV (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag) { | |
| 1019 | + int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex; | |
| 1020 | + int32_t iMbX = pCurDqLayer->iMbX; | |
| 1021 | + int32_t iMbY = pCurDqLayer->iMbY; | |
| 1022 | + int32_t iMbWidth = pCurDqLayer->iMbWidth; | |
| 1023 | + int32_t iLineSize = pFilter->iCsStride[0]; | |
| 1024 | + | |
| 1025 | + uint8_t* pDestY; | |
| 1026 | + int32_t iCurQp; | |
| 1027 | + int32_t iIndexA, iAlpha, iBeta; | |
| 1028 | + | |
| 1029 | + ENFORCE_STACK_ALIGN_1D (int8_t, iTc, 4, 16); | |
| 1030 | + ENFORCE_STACK_ALIGN_1D (uint8_t, uiBSx4, 4, 4); | |
| 1031 | + | |
| 1032 | + pDestY = pFilter->pCsData[0] + ((iMbY * iLineSize + iMbX) << 4); | |
| 1033 | + iCurQp = pCurDqLayer->pLumaQp[iMbXyIndex]; | |
| 1034 | + | |
| 1035 | + * (uint32_t*)uiBSx4 = 0x03030303; | |
| 1036 | + | |
| 1037 | + // luma v | |
| 1038 | + if (iBoundryFlag & LEFT_FLAG_MASK) { | |
| 1039 | + pFilter->iLumaQP = (iCurQp + pCurDqLayer->pLumaQp[iMbXyIndex - 1] + 1) >> 1; | |
| 1040 | + FilteringEdgeLumaIntraV (pFilter, pDestY, iLineSize, NULL); | |
| 1041 | + } | |
| 1042 | + | |
| 1043 | + pFilter->iLumaQP = iCurQp; | |
| 1044 | + GET_ALPHA_BETA_FROM_QP (pFilter->iLumaQP, pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 1045 | + iBeta); | |
| 1046 | + if (iAlpha | iBeta) { | |
| 1047 | + TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 0); | |
| 1048 | + | |
| 1049 | + if (!pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) { | |
| 1050 | + pFilter->pLoopf->pfLumaDeblockingLT4Hor (&pDestY[1 << 2], iLineSize, iAlpha, iBeta, iTc); | |
| 1051 | + } | |
| 1052 | + | |
| 1053 | + pFilter->pLoopf->pfLumaDeblockingLT4Hor (&pDestY[2 << 2], iLineSize, iAlpha, iBeta, iTc); | |
| 1054 | + | |
| 1055 | + if (!pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) { | |
| 1056 | + pFilter->pLoopf->pfLumaDeblockingLT4Hor (&pDestY[3 << 2], iLineSize, iAlpha, iBeta, iTc); | |
| 1057 | + } | |
| 1058 | + } | |
| 1059 | + | |
| 1060 | + // luma h | |
| 1061 | + if (iBoundryFlag & TOP_FLAG_MASK) { | |
| 1062 | + pFilter->iLumaQP = (iCurQp + pCurDqLayer->pLumaQp[iMbXyIndex - iMbWidth] + 1) >> 1; | |
| 1063 | + FilteringEdgeLumaIntraH (pFilter, pDestY, iLineSize, NULL); | |
| 1064 | + } | |
| 1065 | + | |
| 1066 | + pFilter->iLumaQP = iCurQp; | |
| 1067 | + if (iAlpha | iBeta) { | |
| 1068 | + if (!pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) { | |
| 1069 | + pFilter->pLoopf->pfLumaDeblockingLT4Ver (&pDestY[ (1 << 2)*iLineSize], iLineSize, iAlpha, iBeta, iTc); | |
| 1070 | + } | |
| 1071 | + | |
| 1072 | + pFilter->pLoopf->pfLumaDeblockingLT4Ver (&pDestY[ (2 << 2)*iLineSize], iLineSize, iAlpha, iBeta, iTc); | |
| 1073 | + | |
| 1074 | + if (!pCurDqLayer->pTransformSize8x8Flag[iMbXyIndex]) { | |
| 1075 | + pFilter->pLoopf->pfLumaDeblockingLT4Ver (&pDestY[ (3 << 2)*iLineSize], iLineSize, iAlpha, iBeta, iTc); | |
| 1076 | + } | |
| 1077 | + } | |
| 1078 | +} | |
| 1079 | +void FilteringEdgeChromaHV (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag) { | |
| 1080 | + int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex; | |
| 1081 | + int32_t iMbX = pCurDqLayer->iMbX; | |
| 1082 | + int32_t iMbY = pCurDqLayer->iMbY; | |
| 1083 | + int32_t iMbWidth = pCurDqLayer->iMbWidth; | |
| 1084 | + int32_t iLineSize = pFilter->iCsStride[1]; | |
| 1085 | + | |
| 1086 | + uint8_t* pDestCb; | |
| 1087 | + uint8_t* pDestCr; | |
| 1088 | + //int32_t iCurQp; | |
| 1089 | + int8_t* pCurQp; | |
| 1090 | + int32_t iIndexA, iAlpha, iBeta; | |
| 1091 | + | |
| 1092 | + ENFORCE_STACK_ALIGN_1D (int8_t, iTc, 4, 16); | |
| 1093 | + ENFORCE_STACK_ALIGN_1D (uint8_t, uiBSx4, 4, 4); | |
| 1094 | + | |
| 1095 | + pDestCb = pFilter->pCsData[1] + ((iMbY * iLineSize + iMbX) << 3); | |
| 1096 | + pDestCr = pFilter->pCsData[2] + ((iMbY * iLineSize + iMbX) << 3); | |
| 1097 | + pCurQp = pCurDqLayer->pChromaQp[iMbXyIndex]; | |
| 1098 | + | |
| 1099 | + * (uint32_t*)uiBSx4 = 0x03030303; | |
| 1100 | + | |
| 1101 | + | |
| 1102 | +// chroma v | |
| 1103 | + if (iBoundryFlag & LEFT_FLAG_MASK) { | |
| 1104 | + | |
| 1105 | + for (int i = 0; i < 2; i++) { | |
| 1106 | + pFilter->iChromaQP[i] = (pCurQp[i] + pCurDqLayer->pChromaQp[iMbXyIndex - 1][i] + 1) >> 1; | |
| 1107 | + | |
| 1108 | + } | |
| 1109 | + FilteringEdgeChromaIntraV (pFilter, pDestCb, pDestCr, iLineSize, NULL); | |
| 1110 | + } | |
| 1111 | + | |
| 1112 | + pFilter->iChromaQP[0] = pCurQp[0]; | |
| 1113 | + pFilter->iChromaQP[1] = pCurQp[1]; | |
| 1114 | + if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) { | |
| 1115 | + GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 1116 | + iBeta); | |
| 1117 | + if (iAlpha | iBeta) { | |
| 1118 | + TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 1); | |
| 1119 | + pFilter->pLoopf->pfChromaDeblockingLT4Hor (&pDestCb[2 << 1], &pDestCr[2 << 1], iLineSize, iAlpha, iBeta, iTc); | |
| 1120 | + } | |
| 1121 | + } else { | |
| 1122 | + | |
| 1123 | + for (int i = 0; i < 2; i++) { | |
| 1124 | + GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 1125 | + iBeta); | |
| 1126 | + if (iAlpha | iBeta) { | |
| 1127 | + uint8_t* pDestCbCr = (i == 0) ? &pDestCb[2 << 1] : &pDestCr[2 << 1]; | |
| 1128 | + TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 1); | |
| 1129 | + pFilter->pLoopf->pfChromaDeblockingLT4Hor2 (pDestCbCr, iLineSize, iAlpha, iBeta, iTc); | |
| 1130 | + } | |
| 1131 | + | |
| 1132 | + } | |
| 1133 | + } | |
| 1134 | + | |
| 1135 | + // chroma h | |
| 1136 | + | |
| 1137 | + if (iBoundryFlag & TOP_FLAG_MASK) { | |
| 1138 | + for (int i = 0; i < 2; i++) { | |
| 1139 | + pFilter->iChromaQP[i] = (pCurQp[i] + pCurDqLayer->pChromaQp[iMbXyIndex - iMbWidth][i] + 1) >> 1; | |
| 1140 | + } | |
| 1141 | + FilteringEdgeChromaIntraH (pFilter, pDestCb, pDestCr, iLineSize, NULL); | |
| 1142 | + } | |
| 1143 | + | |
| 1144 | + pFilter->iChromaQP[0] = pCurQp[0]; | |
| 1145 | + pFilter->iChromaQP[1] = pCurQp[1]; | |
| 1146 | + | |
| 1147 | + if (pFilter->iChromaQP[0] == pFilter->iChromaQP[1]) { | |
| 1148 | + GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[0], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 1149 | + iBeta); | |
| 1150 | + if (iAlpha | iBeta) { | |
| 1151 | + TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 1); | |
| 1152 | + pFilter->pLoopf->pfChromaDeblockingLT4Ver (&pDestCb[ (2 << 1)*iLineSize], &pDestCr[ (2 << 1)*iLineSize], iLineSize, | |
| 1153 | + iAlpha, iBeta, iTc); | |
| 1154 | + } | |
| 1155 | + } else { | |
| 1156 | + for (int i = 0; i < 2; i++) { | |
| 1157 | + | |
| 1158 | + GET_ALPHA_BETA_FROM_QP (pFilter->iChromaQP[i], pFilter->iSliceAlphaC0Offset, pFilter->iSliceBetaOffset, iIndexA, iAlpha, | |
| 1159 | + iBeta); | |
| 1160 | + if (iAlpha | iBeta) { | |
| 1161 | + TC0_TBL_LOOKUP (iTc, iIndexA, uiBSx4, 1); | |
| 1162 | + uint8_t* pDestCbCr = (i == 0) ? &pDestCb[ (2 << 1) * iLineSize] : &pDestCr[ (2 << 1) * iLineSize]; | |
| 1163 | + pFilter->pLoopf->pfChromaDeblockingLT4Ver2 (pDestCbCr, iLineSize, | |
| 1164 | + iAlpha, iBeta, iTc); | |
| 1165 | + } | |
| 1166 | + } | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + } | |
| 1170 | +} | |
| 1171 | + | |
| 1172 | +// merge h&v lookup table operation to save performance | |
| 1173 | +void DeblockingIntraMb (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag) { | |
| 1174 | + FilteringEdgeLumaHV (pCurDqLayer, pFilter, iBoundryFlag); | |
| 1175 | + FilteringEdgeChromaHV (pCurDqLayer, pFilter, iBoundryFlag); | |
| 1176 | +} | |
| 1177 | + | |
| 1178 | +void WelsDeblockingMb (PDqLayer pCurDqLayer, PDeblockingFilter pFilter, int32_t iBoundryFlag) { | |
| 1179 | + uint8_t nBS[2][4][4] = {{{ 0 }}}; | |
| 1180 | + | |
| 1181 | + int32_t iMbXyIndex = pCurDqLayer->iMbXyIndex; | |
| 1182 | + uint32_t iCurMbType = pCurDqLayer->pMbType[iMbXyIndex]; | |
| 1183 | + int32_t iMbNb; | |
| 1184 | + | |
| 1185 | + PSlice pSlice = &pCurDqLayer->sLayerInfo.sSliceInLayer; | |
| 1186 | + PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | |
| 1187 | + bool bBSlice = pSliceHeader->eSliceType == B_SLICE; | |
| 1188 | + | |
| 1189 | + switch (iCurMbType) { | |
| 1190 | + case MB_TYPE_INTRA4x4: | |
| 1191 | + case MB_TYPE_INTRA8x8: | |
| 1192 | + case MB_TYPE_INTRA16x16: | |
| 1193 | + case MB_TYPE_INTRA_PCM: | |
| 1194 | + DeblockingIntraMb (pCurDqLayer, pFilter, iBoundryFlag); | |
| 1195 | + break; | |
| 1196 | + default: | |
| 1197 | + | |
| 1198 | + if (iBoundryFlag & LEFT_FLAG_MASK) { | |
| 1199 | + iMbNb = iMbXyIndex - 1; | |
| 1200 | + if (bBSlice) { | |
| 1201 | + * (uint32_t*)nBS[0][0] = IS_INTRA (pCurDqLayer->pMbType[iMbNb]) ? 0x04040404 : DeblockingBSliceBsMarginalMBAvcbase ( | |
| 1202 | + pCurDqLayer, 0, iMbNb, iMbXyIndex); | |
| 1203 | + } else { | |
| 1204 | + * (uint32_t*)nBS[0][0] = IS_INTRA (pCurDqLayer->pMbType[iMbNb]) ? 0x04040404 : DeblockingBsMarginalMBAvcbase ( | |
| 1205 | + pCurDqLayer, 0, iMbNb, iMbXyIndex); | |
| 1206 | + } | |
| 1207 | + } else { | |
| 1208 | + * (uint32_t*)nBS[0][0] = 0; | |
| 1209 | + } | |
| 1210 | + if (iBoundryFlag & TOP_FLAG_MASK) { | |
| 1211 | + iMbNb = iMbXyIndex - pCurDqLayer->iMbWidth; | |
| 1212 | + if (bBSlice) { | |
| 1213 | + * (uint32_t*)nBS[1][0] = IS_INTRA (pCurDqLayer->pMbType[iMbNb]) ? 0x04040404 : DeblockingBSliceBsMarginalMBAvcbase ( | |
| 1214 | + pCurDqLayer, 1, iMbNb, iMbXyIndex); | |
| 1215 | + } else { | |
| 1216 | + * (uint32_t*)nBS[1][0] = IS_INTRA (pCurDqLayer->pMbType[iMbNb]) ? 0x04040404 : DeblockingBsMarginalMBAvcbase ( | |
| 1217 | + pCurDqLayer, 1, iMbNb, iMbXyIndex); | |
| 1218 | + } | |
| 1219 | + } else { | |
| 1220 | + * (uint32_t*)nBS[1][0] = 0; | |
| 1221 | + } | |
| 1222 | + //SKIP MB_16x16 or others | |
| 1223 | + if (IS_SKIP (iCurMbType)) { | |
| 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; | |
| 1226 | + } else { | |
| 1227 | + if (IS_INTER_16x16 (iCurMbType)) { | |
| 1228 | + if (!pCurDqLayer->pTransformSize8x8Flag[pCurDqLayer->iMbXyIndex]) { | |
| 1229 | + DeblockingBSInsideMBAvsbase (pCurDqLayer->pNzc[iMbXyIndex], nBS, 1); | |
| 1230 | + } else { | |
| 1231 | + DeblockingBSInsideMBAvsbase8x8 (pCurDqLayer->pNzc[iMbXyIndex], nBS, 1); | |
| 1232 | + } | |
| 1233 | + } else { | |
| 1234 | + | |
| 1235 | + if (bBSlice) { | |
| 1236 | + DeblockingBSliceBSInsideMBNormal (pCurDqLayer, nBS, pCurDqLayer->pNzc[iMbXyIndex], iMbXyIndex); | |
| 1237 | + } else { | |
| 1238 | + DeblockingBSInsideMBNormal (pCurDqLayer, nBS, pCurDqLayer->pNzc[iMbXyIndex], iMbXyIndex); | |
| 1239 | + } | |
| 1240 | + } | |
| 1241 | + } | |
| 1242 | + DeblockingInterMb (pCurDqLayer, pFilter, nBS, iBoundryFlag); | |
| 1243 | + break; | |
| 1244 | + } | |
| 1245 | +} | |
| 1246 | + | |
| 1247 | +/*! | |
| 1248 | + * \brief AVC slice deblocking filtering target layer | |
| 1249 | + * | |
| 1250 | + * \param dec Wels avc decoder context | |
| 1251 | + * | |
| 1252 | + * \return NONE | |
| 1253 | + */ | |
| 1254 | +void WelsDeblockingFilterSlice (PWelsDecoderContext pCtx, PDeblockingFilterMbFunc pDeblockMb) { | |
| 1255 | + PDqLayer pCurDqLayer = pCtx->pCurDqLayer; | |
| 1256 | + PSliceHeaderExt pSliceHeaderExt = &pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt; | |
| 1257 | + int32_t iMbWidth = pCurDqLayer->iMbWidth; | |
| 1258 | + int32_t iTotalMbCount = pSliceHeaderExt->sSliceHeader.pSps->uiTotalMbCount; | |
| 1259 | + | |
| 1260 | + SDeblockingFilter pFilter; | |
| 1261 | + memset (&pFilter, 0, sizeof (pFilter)); | |
| 1262 | + PFmo pFmo = pCtx->pFmo; | |
| 1263 | + int32_t iNextMbXyIndex = 0; | |
| 1264 | + int32_t iTotalNumMb = pCurDqLayer->sLayerInfo.sSliceInLayer.iTotalMbInCurSlice; | |
| 1265 | + int32_t iCountNumMb = 0; | |
| 1266 | + int32_t iBoundryFlag; | |
| 1267 | + int32_t iFilterIdc = pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.uiDisableDeblockingFilterIdc; | |
| 1268 | + | |
| 1269 | + /* Step1: parameters set */ | |
| 1270 | + pFilter.pCsData[0] = pCtx->pDec->pData[0]; | |
| 1271 | + pFilter.pCsData[1] = pCtx->pDec->pData[1]; | |
| 1272 | + pFilter.pCsData[2] = pCtx->pDec->pData[2]; | |
| 1273 | + | |
| 1274 | + pFilter.iCsStride[0] = pCtx->pDec->iLinesize[0]; | |
| 1275 | + pFilter.iCsStride[1] = pCtx->pDec->iLinesize[1]; | |
| 1276 | + | |
| 1277 | + pFilter.eSliceType = (EWelsSliceType) pCurDqLayer->sLayerInfo.sSliceInLayer.eSliceType; | |
| 1278 | + | |
| 1279 | + pFilter.iSliceAlphaC0Offset = pSliceHeaderExt->sSliceHeader.iSliceAlphaC0Offset; | |
| 1280 | + pFilter.iSliceBetaOffset = pSliceHeaderExt->sSliceHeader.iSliceBetaOffset; | |
| 1281 | + | |
| 1282 | + pFilter.pLoopf = &pCtx->sDeblockingFunc; | |
| 1283 | + | |
| 1284 | + /* Step2: macroblock deblocking */ | |
| 1285 | + if (0 == iFilterIdc || 2 == iFilterIdc) { | |
| 1286 | + iNextMbXyIndex = pSliceHeaderExt->sSliceHeader.iFirstMbInSlice; | |
| 1287 | + pCurDqLayer->iMbX = iNextMbXyIndex % iMbWidth; | |
| 1288 | + pCurDqLayer->iMbY = iNextMbXyIndex / iMbWidth; | |
| 1289 | + pCurDqLayer->iMbXyIndex = iNextMbXyIndex; | |
| 1290 | + | |
| 1291 | + do { | |
| 1292 | + iBoundryFlag = DeblockingAvailableNoInterlayer (pCurDqLayer, iFilterIdc); | |
| 1293 | + | |
| 1294 | + pDeblockMb (pCurDqLayer, &pFilter, iBoundryFlag); | |
| 1295 | + | |
| 1296 | + ++iCountNumMb; | |
| 1297 | + if (iCountNumMb >= iTotalNumMb) { | |
| 1298 | + break; | |
| 1299 | + } | |
| 1300 | + | |
| 1301 | + if (pSliceHeaderExt->sSliceHeader.pPps->uiNumSliceGroups > 1) { | |
| 1302 | + iNextMbXyIndex = FmoNextMb (pFmo, iNextMbXyIndex); | |
| 1303 | + } else { | |
| 1304 | + ++iNextMbXyIndex; | |
| 1305 | + } | |
| 1306 | + if (-1 == iNextMbXyIndex || iNextMbXyIndex >= iTotalMbCount) { // slice group boundary or end of a frame | |
| 1307 | + break; | |
| 1308 | + } | |
| 1309 | + | |
| 1310 | + pCurDqLayer->iMbX = iNextMbXyIndex % iMbWidth; | |
| 1311 | + pCurDqLayer->iMbY = iNextMbXyIndex / iMbWidth; | |
| 1312 | + pCurDqLayer->iMbXyIndex = iNextMbXyIndex; | |
| 1313 | + } while (1); | |
| 1314 | + } | |
| 1315 | +} | |
| 1316 | +/*! | |
| 1317 | + * \brief deblocking module initialize | |
| 1318 | + * | |
| 1319 | + * \param pf | |
| 1320 | + * cpu | |
| 1321 | + * | |
| 1322 | + * \return NONE | |
| 1323 | + */ | |
| 1324 | + | |
| 1325 | +void DeblockingInit (SDeblockingFunc* pFunc, int32_t iCpu) { | |
| 1326 | + pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_c; | |
| 1327 | + pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_c; | |
| 1328 | + pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_c; | |
| 1329 | + pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_c; | |
| 1330 | + | |
| 1331 | + pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_c; | |
| 1332 | + pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_c; | |
| 1333 | + pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_c; | |
| 1334 | + pFunc->pfChromaDeblockingEQ4Hor = DeblockChromaEq4H_c; | |
| 1335 | + | |
| 1336 | + pFunc->pfChromaDeblockingLT4Ver2 = DeblockChromaLt4V2_c; | |
| 1337 | + pFunc->pfChromaDeblockingEQ4Ver2 = DeblockChromaEq4V2_c; | |
| 1338 | + pFunc->pfChromaDeblockingLT4Hor2 = DeblockChromaLt4H2_c; | |
| 1339 | + pFunc->pfChromaDeblockingEQ4Hor2 = DeblockChromaEq4H2_c; | |
| 1340 | + | |
| 1341 | +#ifdef X86_ASM | |
| 1342 | + if (iCpu & WELS_CPU_SSSE3) { | |
| 1343 | + pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_ssse3; | |
| 1344 | + pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_ssse3; | |
| 1345 | + pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_ssse3; | |
| 1346 | + pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_ssse3; | |
| 1347 | + pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_ssse3; | |
| 1348 | + pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_ssse3; | |
| 1349 | + pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_ssse3; | |
| 1350 | + pFunc->pfChromaDeblockingEQ4Hor = DeblockChromaEq4H_ssse3; | |
| 1351 | + } | |
| 1352 | +#endif | |
| 1353 | + | |
| 1354 | +#if defined(HAVE_NEON) | |
| 1355 | + if (iCpu & WELS_CPU_NEON) { | |
| 1356 | + pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_neon; | |
| 1357 | + pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_neon; | |
| 1358 | + pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_neon; | |
| 1359 | + pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_neon; | |
| 1360 | + | |
| 1361 | + pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_neon; | |
| 1362 | + pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_neon; | |
| 1363 | + pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_neon; | |
| 1364 | + pFunc->pfChromaDeblockingEQ4Hor = DeblockChromaEq4H_neon; | |
| 1365 | + } | |
| 1366 | +#endif | |
| 1367 | + | |
| 1368 | +#if defined(HAVE_NEON_AARCH64) | |
| 1369 | + if (iCpu & WELS_CPU_NEON) { | |
| 1370 | + pFunc->pfLumaDeblockingLT4Ver = DeblockLumaLt4V_AArch64_neon; | |
| 1371 | + pFunc->pfLumaDeblockingEQ4Ver = DeblockLumaEq4V_AArch64_neon; | |
| 1372 | + pFunc->pfLumaDeblockingLT4Hor = DeblockLumaLt4H_AArch64_neon; | |
| 1373 | + pFunc->pfLumaDeblockingEQ4Hor = DeblockLumaEq4H_AArch64_neon; | |
| 1374 | + | |
| 1375 | + pFunc->pfChromaDeblockingLT4Ver = DeblockChromaLt4V_AArch64_neon; | |
| 1376 | + pFunc->pfChromaDeblockingEQ4Ver = DeblockChromaEq4V_AArch64_neon; | |
| 1377 | + pFunc->pfChromaDeblockingLT4Hor = DeblockChromaLt4H_AArch64_neon; | |
| 1378 | + pFunc->pfChromaDeblockingEQ4Hor = DeblockChromaEq4H_AArch64_neon; | |
| 1379 | + } | |
| 1380 | +#endif | |
| 1381 | +} | |
| 1382 | + | |
| 1383 | +} // namespace WelsDec | |
| @@ -1,897 +1,897 @@ | ||
| 1 | −/*! | |
| 2 | − * \copy | |
| 3 | − * Copyright (c) 2008-2013, Cisco Systems | |
| 4 | − * All rights reserved. | |
| 5 | − * | |
| 6 | − * Redistribution and use in source and binary forms, with or without | |
| 7 | − * modification, are permitted provided that the following conditions | |
| 8 | − * are met: | |
| 9 | − * | |
| 10 | − * * Redistributions of source code must retain the above copyright | |
| 11 | − * notice, this list of conditions and the following disclaimer. | |
| 12 | − * | |
| 13 | − * * Redistributions in binary form must reproduce the above copyright | |
| 14 | − * notice, this list of conditions and the following disclaimer in | |
| 15 | − * the documentation and/or other materials provided with the | |
| 16 | − * distribution. | |
| 17 | − * | |
| 18 | − * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 | − * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 | − * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 21 | − * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 22 | − * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 23 | − * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 24 | − * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 | − * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 26 | − * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 | − * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
| 28 | − * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | − * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | − * | |
| 31 | − * | |
| 32 | − * manage_dec_ref.cpp | |
| 33 | − * | |
| 34 | − * Abstract | |
| 35 | − * Implementation for managing reference picture | |
| 36 | − * | |
| 37 | − * History | |
| 38 | − * 07/21/2008 Created | |
| 39 | − * | |
| 40 | − *****************************************************************************/ | |
| 41 | − | |
| 42 | −#include "manage_dec_ref.h" | |
| 43 | −#include "error_concealment.h" | |
| 44 | −#include "error_code.h" | |
| 45 | − | |
| 46 | −namespace WelsDec { | |
| 47 | − | |
| 48 | −static PPicture WelsDelShortFromList (PRefPic pRefPic, int32_t iFrameNum); | |
| 49 | −static PPicture WelsDelLongFromList (PRefPic pRefPic, uint32_t uiLongTermFrameIdx); | |
| 50 | −static PPicture WelsDelShortFromListSetUnref (PRefPic pRefPic, int32_t iFrameNum); | |
| 51 | −static PPicture WelsDelLongFromListSetUnref (PRefPic pRefPic, uint32_t uiLongTermFrameIdx); | |
| 52 | − | |
| 53 | −static int32_t MMCO (PWelsDecoderContext pCtx, PRefPicMarking pRefPicMarking); | |
| 54 | −static int32_t MMCOProcess (PWelsDecoderContext pCtx, uint32_t uiMmcoType, | |
| 55 | − int32_t iShortFrameNum, uint32_t uiLongTermPicNum, int32_t iLongTermFrameIdx, int32_t iMaxLongTermFrameIdx); | |
| 56 | −static int32_t SlidingWindow (PWelsDecoderContext pCtx); | |
| 57 | − | |
| 58 | −static int32_t AddShortTermToList (PRefPic pRefPic, PPicture pPic); | |
| 59 | −static int32_t AddLongTermToList (PRefPic pRefPic, PPicture pPic, int32_t iLongTermFrameIdx, uint32_t uiLongTermPicNum); | |
| 60 | −static int32_t MarkAsLongTerm (PRefPic pRefPic, int32_t iFrameNum, int32_t iLongTermFrameIdx, | |
| 61 | − uint32_t uiLongTermPicNum); | |
| 62 | −static int32_t WelsCheckAndRecoverForFutureDecoding (PWelsDecoderContext pCtx); | |
| 63 | −#ifdef LONG_TERM_REF | |
| 64 | −int32_t GetLTRFrameIndex (PRefPic pRefPic, int32_t iAncLTRFrameNum); | |
| 65 | −#endif | |
| 66 | −static int32_t RemainOneBufferInDpbForEC (PWelsDecoderContext pCtx); | |
| 67 | − | |
| 68 | −static void SetUnRef (PPicture pRef) { | |
| 69 | − if (NULL != pRef) { | |
| 70 | − pRef->bUsedAsRef = false; | |
| 71 | − pRef->bIsLongRef = false; | |
| 72 | − pRef->iFrameNum = -1; | |
| 73 | − pRef->iFrameWrapNum = -1; | |
| 74 | − //pRef->iFramePoc = 0; | |
| 75 | − pRef->iLongTermFrameIdx = -1; | |
| 76 | − pRef->uiLongTermPicNum = 0; | |
| 77 | − pRef->uiQualityId = -1; | |
| 78 | − pRef->uiTemporalId = -1; | |
| 79 | − pRef->uiSpatialId = -1; | |
| 80 | − pRef->iSpsId = -1; | |
| 81 | − pRef->bIsComplete = false; | |
| 82 | − } | |
| 83 | −} | |
| 84 | − | |
| 85 | −//reset pRefList when | |
| 86 | −// 1.sps arrived that is new sequence starting | |
| 87 | −// 2.IDR NAL i.e. 1st layer in IDR AU | |
| 88 | − | |
| 89 | −void WelsResetRefPic (PWelsDecoderContext pCtx) { | |
| 90 | − int32_t i = 0; | |
| 91 | − PRefPic pRefPic = &pCtx->sRefPic; | |
| 92 | − pCtx->sRefPic.uiLongRefCount[LIST_0] = pCtx->sRefPic.uiShortRefCount[LIST_0] = 0; | |
| 93 | − | |
| 94 | − pRefPic->uiRefCount[LIST_0] = 0; | |
| 95 | − pRefPic->uiRefCount[LIST_1] = 0; | |
| 96 | − | |
| 97 | − for (i = 0; i < MAX_DPB_COUNT; i++) { | |
| 98 | − if (pRefPic->pShortRefList[LIST_0][i] != NULL) { | |
| 99 | − SetUnRef (pRefPic->pShortRefList[LIST_0][i]); | |
| 100 | − pRefPic->pShortRefList[LIST_0][i] = NULL; | |
| 101 | − } | |
| 102 | − } | |
| 103 | − pRefPic->uiShortRefCount[LIST_0] = 0; | |
| 104 | − | |
| 105 | − for (i = 0; i < MAX_DPB_COUNT; i++) { | |
| 106 | − if (pRefPic->pLongRefList[LIST_0][i] != NULL) { | |
| 107 | − SetUnRef (pRefPic->pLongRefList[LIST_0][i]); | |
| 108 | − pRefPic->pLongRefList[LIST_0][i] = NULL; | |
| 109 | − } | |
| 110 | − } | |
| 111 | − pRefPic->uiLongRefCount[LIST_0] = 0; | |
| 112 | −} | |
| 113 | − | |
| 114 | −static int32_t WelsCheckAndRecoverForFutureDecoding (PWelsDecoderContext pCtx) { | |
| 115 | − if ((pCtx->sRefPic.uiShortRefCount[LIST_0] + pCtx->sRefPic.uiLongRefCount[LIST_0] <= 0) && (pCtx->eSliceType != I_SLICE | |
| 116 | − && pCtx->eSliceType != SI_SLICE)) { | |
| 117 | − if (pCtx->pParam->eEcActiveIdc != | |
| 118 | − ERROR_CON_DISABLE) { //IDR lost!, recover it for future decoding with data all set to 0 | |
| 119 | − PPicture pRef = PrefetchPic (pCtx->pPicBuff); | |
| 120 | − if (pRef != NULL) { | |
| 121 | − // IDR lost, set new | |
| 122 | − pRef->bIsComplete = false; // Set complete flag to false for lost IDR ref picture | |
| 123 | − pRef->iSpsId = pCtx->pSps->iSpsId; | |
| 124 | − pRef->iPpsId = pCtx->pPps->iPpsId; | |
| 125 | − pCtx->iErrorCode |= dsDataErrorConcealed; | |
| 126 | − bool bCopyPrevious = ((ERROR_CON_FRAME_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) | |
| 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)) | |
| 131 | − && (NULL != pCtx->pPreviousDecodedPictureInDpb); | |
| 132 | − bCopyPrevious = bCopyPrevious && (pRef->iWidthInPixel == pCtx->pPreviousDecodedPictureInDpb->iWidthInPixel) | |
| 133 | − && (pRef->iHeightInPixel == pCtx->pPreviousDecodedPictureInDpb->iHeightInPixel); | |
| 134 | − | |
| 135 | − if (!bCopyPrevious) { | |
| 136 | − memset (pRef->pData[0], 128, pRef->iLinesize[0] * pRef->iHeightInPixel); | |
| 137 | − memset (pRef->pData[1], 128, pRef->iLinesize[1] * pRef->iHeightInPixel / 2); | |
| 138 | − memset (pRef->pData[2], 128, pRef->iLinesize[2] * pRef->iHeightInPixel / 2); | |
| 139 | − } else if (pRef == pCtx->pPreviousDecodedPictureInDpb) { | |
| 140 | − WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "WelsInitRefList()::EC memcpy overlap."); | |
| 141 | − } else { | |
| 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); | |
| 144 | − memcpy (pRef->pData[2], pCtx->pPreviousDecodedPictureInDpb->pData[2], pRef->iLinesize[2] * pRef->iHeightInPixel / 2); | |
| 145 | − } | |
| 146 | − pRef->iFrameNum = 0; | |
| 147 | − pRef->iFramePoc = 0; | |
| 148 | − pRef->uiTemporalId = pRef->uiQualityId = 0; | |
| 149 | − ExpandReferencingPicture (pRef->pData, pRef->iWidthInPixel, pRef->iHeightInPixel, pRef->iLinesize, | |
| 150 | − pCtx->sExpandPicFunc.pfExpandLumaPicture, pCtx->sExpandPicFunc.pfExpandChromaPicture); | |
| 151 | − AddShortTermToList (&pCtx->sRefPic, pRef); | |
| 152 | − } else { | |
| 153 | − WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "WelsInitRefList()::PrefetchPic for EC errors."); | |
| 154 | − pCtx->iErrorCode |= dsOutOfMemory; | |
| 155 | − return ERR_INFO_REF_COUNT_OVERFLOW; | |
| 156 | − } | |
| 157 | − } | |
| 158 | − } | |
| 159 | − return ERR_NONE; | |
| 160 | −} | |
| 161 | − | |
| 162 | −static void WrapShortRefPicNum (PWelsDecoderContext pCtx) { | |
| 163 | − int32_t i; | |
| 164 | − PSliceHeader pSliceHeader = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader; | |
| 165 | − int32_t iMaxPicNum = 1 << pSliceHeader->pSps->uiLog2MaxFrameNum; | |
| 166 | − PPicture* ppShoreRefList = pCtx->sRefPic.pShortRefList[LIST_0]; | |
| 167 | − int32_t iShortRefCount = pCtx->sRefPic.uiShortRefCount[LIST_0]; | |
| 168 | − //wrap pic num | |
| 169 | − for (i = 0; i < iShortRefCount; i++) { | |
| 170 | − if (ppShoreRefList[i]) { | |
| 171 | − if (ppShoreRefList[i]->iFrameNum > pSliceHeader->iFrameNum) | |
| 172 | − ppShoreRefList[i]->iFrameWrapNum = ppShoreRefList[i]->iFrameNum - iMaxPicNum; | |
| 173 | − else | |
| 174 | − ppShoreRefList[i]->iFrameWrapNum = ppShoreRefList[i]->iFrameNum; | |
| 175 | − } | |
| 176 | − } | |
| 177 | −} | |
| 178 | − | |
| 179 | −/** | |
| 180 | −* fills the pRefPic.pRefList LIST_0 and LIST_0 for B-Slice. | |
| 181 | −*/ | |
| 182 | −int32_t WelsInitBSliceRefList (PWelsDecoderContext pCtx, int32_t iPoc) { | |
| 183 | − | |
| 184 | − int32_t err = WelsCheckAndRecoverForFutureDecoding (pCtx); | |
| 185 | − if (err != ERR_NONE) return err; | |
| 186 | − | |
| 187 | − WrapShortRefPicNum (pCtx); | |
| 188 | − | |
| 189 | − PPicture* ppShoreRefList = pCtx->sRefPic.pShortRefList[LIST_0]; | |
| 190 | − PPicture* ppLongRefList = pCtx->sRefPic.pLongRefList[LIST_0]; | |
| 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)); | |
| 193 | − int32_t iLSCurrPocCount = 0; | |
| 194 | − int32_t iLTCurrPocCount = 0; | |
| 195 | − PPicture pLSCurrPocList0[MAX_DPB_COUNT]; | |
| 196 | − PPicture pLTCurrPocList0[MAX_DPB_COUNT]; | |
| 197 | − for (int32_t i = 0; i < pCtx->sRefPic.uiShortRefCount[LIST_0]; ++i) { | |
| 198 | − if (ppShoreRefList[i]->iFramePoc < iPoc) { | |
| 199 | − pLSCurrPocList0[iLSCurrPocCount++] = ppShoreRefList[i]; | |
| 200 | − } | |
| 201 | − } | |
| 202 | − for (int32_t i = pCtx->sRefPic.uiShortRefCount[LIST_0] - 1; i >= 0; --i) { | |
| 203 | − if (ppShoreRefList[i]->iFramePoc > iPoc) { | |
| 204 | − pLTCurrPocList0[iLTCurrPocCount++] = ppShoreRefList[i]; | |
| 205 | − } | |
| 206 | − } | |
| 207 | − if (pCtx->sRefPic.uiLongRefCount[LIST_0] > 1) { | |
| 208 | − //long sorts in increasing order | |
| 209 | − PPicture pTemp; | |
| 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) { | |
| 212 | − if (ppLongRefList[j]->iFramePoc < ppLongRefList[i]->iFramePoc) { | |
| 213 | − pTemp = ppLongRefList[i]; | |
| 214 | − ppLongRefList[i] = ppLongRefList[j]; | |
| 215 | − ppLongRefList[j] = pTemp; | |
| 216 | − } | |
| 217 | − } | |
| 218 | − } | |
| 219 | − } | |
| 220 | − int32_t iCurrPocCount = iLSCurrPocCount + iLTCurrPocCount; | |
| 221 | − int32_t iCount = 0; | |
| 222 | − //LIST_0 | |
| 223 | − //short | |
| 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) { | |
| 226 | − pCtx->sRefPic.pRefList[LIST_0][iCount++] = pLSCurrPocList0[i]; | |
| 227 | − } | |
| 228 | − if (iLSCurrPocCount > 1) { | |
| 229 | − //LIST_0 short sorts in decreasing order | |
| 230 | − PPicture pTemp; | |
| 231 | − for (int32_t i = 0; i < iLSCurrPocCount; ++i) { | |
| 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) { | |
| 234 | − pTemp = pCtx->sRefPic.pRefList[LIST_0][i]; | |
| 235 | − pCtx->sRefPic.pRefList[LIST_0][i] = pCtx->sRefPic.pRefList[LIST_0][j]; | |
| 236 | − pCtx->sRefPic.pRefList[LIST_0][j] = pTemp; | |
| 237 | − } | |
| 238 | − } | |
| 239 | − } | |
| 240 | − } | |
| 241 | − for (int32_t i = 0; i < iLTCurrPocCount; ++i) { | |
| 242 | − pCtx->sRefPic.pRefList[LIST_0][iCount++] = pLTCurrPocList0[i]; | |
| 243 | − } | |
| 244 | − if (iLTCurrPocCount > 1) { | |
| 245 | − //LIST_0 short sorts in increasing order | |
| 246 | − PPicture pTemp; | |
| 247 | − for (int32_t i = iLSCurrPocCount; i < iCurrPocCount; ++i) { | |
| 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) { | |
| 250 | − pTemp = pCtx->sRefPic.pRefList[LIST_0][i]; | |
| 251 | − pCtx->sRefPic.pRefList[LIST_0][i] = pCtx->sRefPic.pRefList[LIST_0][j]; | |
| 252 | − pCtx->sRefPic.pRefList[LIST_0][j] = pTemp; | |
| 253 | − } | |
| 254 | − } | |
| 255 | − } | |
| 256 | − } | |
| 257 | − //long | |
| 258 | − for (int32_t i = 0; i < pCtx->sRefPic.uiLongRefCount[LIST_0]; ++i) { | |
| 259 | − pCtx->sRefPic.pRefList[LIST_0][iCount++] = ppLongRefList[i]; | |
| 260 | − } | |
| 261 | − pCtx->sRefPic.uiRefCount[LIST_0] = iCount; | |
| 262 | − | |
| 263 | − iCount = 0; | |
| 264 | − //LIST_1 | |
| 265 | − //short | |
| 266 | − for (int32_t i = 0; i < iLTCurrPocCount; ++i) { | |
| 267 | − pCtx->sRefPic.pRefList[LIST_1][iCount++] = pLTCurrPocList0[i]; | |
| 268 | − } | |
| 269 | − if (iLTCurrPocCount > 1) { | |
| 270 | − //LIST_1 short sorts in increasing order | |
| 271 | − PPicture pTemp; | |
| 272 | − for (int32_t i = 0; i < iLTCurrPocCount; ++i) { | |
| 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) { | |
| 275 | − pTemp = pCtx->sRefPic.pRefList[LIST_1][i]; | |
| 276 | − pCtx->sRefPic.pRefList[LIST_1][i] = pCtx->sRefPic.pRefList[LIST_1][j]; | |
| 277 | − pCtx->sRefPic.pRefList[LIST_1][j] = pTemp; | |
| 278 | − } | |
| 279 | − } | |
| 280 | − } | |
| 281 | − } | |
| 282 | − for (int32_t i = 0; i < iLSCurrPocCount; ++i) { | |
| 283 | − pCtx->sRefPic.pRefList[LIST_1][iCount++] = pLSCurrPocList0[i]; | |
| 284 | − } | |
| 285 | − if (iLSCurrPocCount > 1) { | |
| 286 | − //LIST_1 short sorts in decreasing order | |
| 287 | − PPicture pTemp; | |
| 288 | − for (int32_t i = iLTCurrPocCount; i < iCurrPocCount; ++i) { | |
| 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) { | |
| 291 | − pTemp = pCtx->sRefPic.pRefList[LIST_1][i]; | |
| 292 | − pCtx->sRefPic.pRefList[LIST_1][i] = pCtx->sRefPic.pRefList[LIST_1][j]; | |
| 293 | − pCtx->sRefPic.pRefList[LIST_1][j] = pTemp; | |
| 294 | − } | |
| 295 | − } | |
| 296 | − } | |
| 297 | − } | |
| 298 | − //long | |
| 299 | − for (int32_t i = 0; i < pCtx->sRefPic.uiLongRefCount[LIST_0]; ++i) { | |
| 300 | − pCtx->sRefPic.pRefList[LIST_1][iCount++] = ppLongRefList[i]; | |
| 301 | − } | |
| 302 | − pCtx->sRefPic.uiRefCount[LIST_1] = iCount; | |
| 303 | − return ERR_NONE; | |
| 304 | −} | |
| 305 | − | |
| 306 | −/** | |
| 307 | − * fills the pRefPic.pRefList. | |
| 308 | − */ | |
| 309 | −int32_t WelsInitRefList (PWelsDecoderContext pCtx, int32_t iPoc) { | |
| 310 | − | |
| 311 | − int32_t err = WelsCheckAndRecoverForFutureDecoding (pCtx); | |
| 312 | − if (err != ERR_NONE) return err; | |
| 313 | − | |
| 314 | − WrapShortRefPicNum (pCtx); | |
| 315 | − | |
| 316 | − PPicture* ppShoreRefList = pCtx->sRefPic.pShortRefList[LIST_0]; | |
| 317 | − PPicture* ppLongRefList = pCtx->sRefPic.pLongRefList[LIST_0]; | |
| 318 | − memset (pCtx->sRefPic.pRefList[LIST_0], 0, MAX_DPB_COUNT * sizeof (PPicture)); | |
| 319 | − | |
| 320 | − int32_t i, iCount = 0; | |
| 321 | − //short | |
| 322 | − for (i = 0; i < pCtx->sRefPic.uiShortRefCount[LIST_0]; ++i) { | |
| 323 | − pCtx->sRefPic.pRefList[LIST_0][iCount++ ] = ppShoreRefList[i]; | |
| 324 | − } | |
| 325 | − | |
| 326 | − //long | |
| 327 | − for (i = 0; i < pCtx->sRefPic.uiLongRefCount[LIST_0] ; ++i) { | |
| 328 | − pCtx->sRefPic.pRefList[LIST_0][iCount++ ] = ppLongRefList[i]; | |
| 329 | − } | |
| 330 | − pCtx->sRefPic.uiRefCount[LIST_0] = iCount; | |
| 331 | − | |
| 332 | − return ERR_NONE; | |
| 333 | −} | |
| 334 | − | |
| 335 | −int32_t WelsReorderRefList (PWelsDecoderContext pCtx) { | |
| 336 | − | |
| 337 | − if (pCtx->eSliceType == I_SLICE || pCtx->eSliceType == SI_SLICE) { | |
| 338 | − return ERR_NONE; | |
| 339 | − } | |
| 340 | − | |
| 341 | − PRefPicListReorderSyn pRefPicListReorderSyn = pCtx->pCurDqLayer->pRefPicListReordering; | |
| 342 | − PNalUnitHeaderExt pNalHeaderExt = &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt; | |
| 343 | − PSliceHeader pSliceHeader = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader; | |
| 344 | − int32_t ListCount = 1; | |
| 345 | − if (pCtx->eSliceType == B_SLICE) ListCount = 2; | |
| 346 | − for (int32_t listIdx = 0; listIdx < ListCount; ++listIdx) { | |
| 347 | − PPicture pPic = NULL; | |
| 348 | − PPicture* ppRefList = pCtx->sRefPic.pRefList[listIdx]; | |
| 349 | − int32_t iMaxRefIdx = pCtx->pSps->iNumRefFrames; | |
| 350 | − int32_t iRefCount = pCtx->sRefPic.uiRefCount[listIdx]; | |
| 351 | − int32_t iPredFrameNum = pSliceHeader->iFrameNum; | |
| 352 | − int32_t iMaxPicNum = 1 << pSliceHeader->pSps->uiLog2MaxFrameNum; | |
| 353 | − int32_t iAbsDiffPicNum = -1; | |
| 354 | − int32_t iReorderingIndex = 0; | |
| 355 | − int32_t i = 0; | |
| 356 | − | |
| 357 | − if (iRefCount <= 0) { | |
| 358 | − pCtx->iErrorCode = dsNoParamSets; //No any reference for decoding, SHOULD request IDR | |
| 359 | − return ERR_INFO_REFERENCE_PIC_LOST; | |
| 360 | − } | |
| 361 | − | |
| 362 | − if (pRefPicListReorderSyn->bRefPicListReorderingFlag[listIdx]) { | |
| 363 | − while ((iReorderingIndex < iMaxRefIdx) | |
| 364 | − && (pRefPicListReorderSyn->sReorderingSyn[listIdx][iReorderingIndex].uiReorderingOfPicNumsIdc != 3)) { | |
| 365 | − uint16_t uiReorderingOfPicNumsIdc = | |
| 366 | − pRefPicListReorderSyn->sReorderingSyn[listIdx][iReorderingIndex].uiReorderingOfPicNumsIdc; | |
| 367 | − if (uiReorderingOfPicNumsIdc < 2) { | |
| 368 | − iAbsDiffPicNum = pRefPicListReorderSyn->sReorderingSyn[listIdx][iReorderingIndex].uiAbsDiffPicNumMinus1 + 1; | |
| 369 | − | |
| 370 | − if (uiReorderingOfPicNumsIdc == 0) { | |
| 371 | − iPredFrameNum -= iAbsDiffPicNum; | |
| 372 | − } else { | |
| 373 | − iPredFrameNum += iAbsDiffPicNum; | |
| 374 | − } | |
| 375 | − iPredFrameNum &= iMaxPicNum - 1; | |
| 376 | − | |
| 377 | − for (i = iMaxRefIdx - 1; i >= 0; i--) { | |
| 378 | − if (ppRefList[i] != NULL && ppRefList[i]->iFrameNum == iPredFrameNum && !ppRefList[i]->bIsLongRef) { | |
| 379 | − if ((pNalHeaderExt->uiQualityId == ppRefList[i]->uiQualityId) | |
| 380 | − && (pSliceHeader->iSpsId != ppRefList[i]->iSpsId)) { //check; | |
| 381 | − WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "WelsReorderRefList()::::BASE LAYER::::iSpsId:%d, ref_sps_id:%d", | |
| 382 | − pSliceHeader->iSpsId, ppRefList[i]->iSpsId); | |
| 383 | − pCtx->iErrorCode = dsNoParamSets; //cross-IDR reference frame selection, SHOULD request IDR.-- | |
| 384 | − return ERR_INFO_REFERENCE_PIC_LOST; | |
| 385 | − } else { | |
| 386 | − break; | |
| 387 | − } | |
| 388 | − } | |
| 389 | − } | |
| 390 | − | |
| 391 | − } else if (uiReorderingOfPicNumsIdc == 2) { | |
| 392 | − for (i = iMaxRefIdx - 1; i >= 0; i--) { | |
| 393 | − if (ppRefList[i] != NULL && ppRefList[i]->bIsLongRef | |
| 394 | − && ppRefList[i]->iLongTermFrameIdx == | |
| 395 | − pRefPicListReorderSyn->sReorderingSyn[listIdx][iReorderingIndex].uiLongTermPicNum) { | |
| 396 | − if ((pNalHeaderExt->uiQualityId == ppRefList[i]->uiQualityId) | |
| 397 | − && (pSliceHeader->iSpsId != ppRefList[i]->iSpsId)) { //check; | |
| 398 | − WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "WelsReorderRefList()::::BASE LAYER::::iSpsId:%d, ref_sps_id:%d", | |
| 399 | − pSliceHeader->iSpsId, ppRefList[i]->iSpsId); | |
| 400 | − pCtx->iErrorCode = dsNoParamSets; //cross-IDR reference frame selection, SHOULD request IDR.-- | |
| 401 | − return ERR_INFO_REFERENCE_PIC_LOST; | |
| 402 | − } else { | |
| 403 | − break; | |
| 404 | − } | |
| 405 | − } | |
| 406 | − } | |
| 407 | − } | |
| 408 | − if (i < 0) { | |
| 409 | − return ERR_INFO_REFERENCE_PIC_LOST; | |
| 410 | − } | |
| 411 | − pPic = ppRefList[i]; | |
| 412 | − if (i > iReorderingIndex) { | |
| 413 | − memmove (&ppRefList[1 + iReorderingIndex], &ppRefList[iReorderingIndex], | |
| 414 | − (i - iReorderingIndex) * sizeof (PPicture)); //confirmed_safe_unsafe_usage | |
| 415 | − } else if (i < iReorderingIndex) { | |
| 416 | − memmove (&ppRefList[1 + iReorderingIndex], &ppRefList[iReorderingIndex], | |
| 417 | − (iMaxRefIdx - iReorderingIndex) * sizeof (PPicture)); | |
| 418 | − } | |
| 419 | − ppRefList[iReorderingIndex] = pPic; | |
| 420 | − iReorderingIndex++; | |
| 421 | − } | |
| 422 | − } | |
| 423 | − } | |
| 424 | − return ERR_NONE; | |
| 425 | −} | |
| 426 | − | |
| 427 | −//WelsReorderRefList2 is the test code | |
| 428 | −int32_t WelsReorderRefList2 (PWelsDecoderContext pCtx) { | |
| 429 | − | |
| 430 | − if (pCtx->eSliceType == I_SLICE || pCtx->eSliceType == SI_SLICE) { | |
| 431 | − return ERR_NONE; | |
| 432 | − } | |
| 433 | − | |
| 434 | − PRefPicListReorderSyn pRefPicListReorderSyn = pCtx->pCurDqLayer->pRefPicListReordering; | |
| 435 | − PSliceHeader pSliceHeader = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader; | |
| 436 | − | |
| 437 | − PPicture* ppShoreRefList = pCtx->sRefPic.pShortRefList[LIST_0]; | |
| 438 | − int32_t iShortRefCount = pCtx->sRefPic.uiShortRefCount[LIST_0]; | |
| 439 | − PPicture* ppLongRefList = pCtx->sRefPic.pLongRefList[LIST_0]; | |
| 440 | − int32_t iLongRefCount = pCtx->sRefPic.uiLongRefCount[LIST_0]; | |
| 441 | − int32_t i = 0; | |
| 442 | − int32_t j = 0; | |
| 443 | − int32_t k = 0; | |
| 444 | − int32_t iMaxRefIdx = pCtx->pSps->iNumRefFrames; | |
| 445 | − const int32_t iCurFrameNum = pSliceHeader->iFrameNum; | |
| 446 | − const int32_t iMaxPicNum = 1 << pSliceHeader->pSps->uiLog2MaxFrameNum; | |
| 447 | − int32_t iListCount = 1; | |
| 448 | − if (pCtx->eSliceType == B_SLICE) iListCount = 2; | |
| 449 | − for (int32_t listIdx = 0; listIdx < iListCount; ++listIdx) { | |
| 450 | − PPicture* ppRefList = pCtx->sRefPic.pRefList[listIdx]; | |
| 451 | − int32_t iCount = 0; | |
| 452 | − int32_t iRefCount = pSliceHeader->uiRefCount[listIdx]; | |
| 453 | − int32_t iAbsDiffPicNum = -1; | |
| 454 | − | |
| 455 | − if (pRefPicListReorderSyn->bRefPicListReorderingFlag[listIdx]) { | |
| 456 | − int32_t iPredFrameNum = iCurFrameNum; | |
| 457 | − for (i = 0; pRefPicListReorderSyn->sReorderingSyn[listIdx][i].uiReorderingOfPicNumsIdc != 3; i++) { | |
| 458 | − if (iCount >= iMaxRefIdx) | |
| 459 | − break; | |
| 460 | − | |
| 461 | − for (j = iRefCount; j > iCount; j--) | |
| 462 | − ppRefList[j] = ppRefList[j - 1]; | |
| 463 | − | |
| 464 | − uint16_t uiReorderingOfPicNumsIdc = | |
| 465 | − pRefPicListReorderSyn->sReorderingSyn[listIdx][i].uiReorderingOfPicNumsIdc; | |
| 466 | − | |
| 467 | − if (uiReorderingOfPicNumsIdc < 2) { // reorder short references | |
| 468 | − iAbsDiffPicNum = (int32_t) (pRefPicListReorderSyn->sReorderingSyn[listIdx][i].uiAbsDiffPicNumMinus1 + 1); | |
| 469 | − if (uiReorderingOfPicNumsIdc == 0) { | |
| 470 | − if (iPredFrameNum - iAbsDiffPicNum < 0) | |
| 471 | − iPredFrameNum -= (iAbsDiffPicNum - iMaxPicNum); | |
| 472 | − else | |
| 473 | − iPredFrameNum -= iAbsDiffPicNum; | |
| 474 | − } else { | |
| 475 | − if (iPredFrameNum + iAbsDiffPicNum >= iMaxPicNum) | |
| 476 | − iPredFrameNum += (iAbsDiffPicNum - iMaxPicNum); | |
| 477 | − else | |
| 478 | − iPredFrameNum += iAbsDiffPicNum; | |
| 479 | − } | |
| 480 | − | |
| 481 | − if (iPredFrameNum > iCurFrameNum) { | |
| 482 | − iPredFrameNum -= iMaxPicNum; | |
| 483 | − } | |
| 484 | − | |
| 485 | − for (j = 0; j < iShortRefCount; j++) { | |
| 486 | − if (ppShoreRefList[j]) { | |
| 487 | − if (ppShoreRefList[j]->iFrameWrapNum == iPredFrameNum) { | |
| 488 | − ppRefList[iCount++] = ppShoreRefList[j]; | |
| 489 | − break; | |
| 490 | − } | |
| 491 | − } | |
| 492 | − } | |
| 493 | − k = iCount; | |
| 494 | − for (j = k; j <= iRefCount; j++) { | |
| 495 | − if (ppRefList[j] != NULL) { | |
| 496 | − if (ppRefList[j]->bIsLongRef || ppRefList[j]->iFrameWrapNum != iPredFrameNum) | |
| 497 | − ppRefList[k++] = ppRefList[j]; | |
| 498 | − } | |
| 499 | − } | |
| 500 | − } else { // reorder long term references uiReorderingOfPicNumsIdc == 2 | |
| 501 | − iPredFrameNum = pRefPicListReorderSyn->sReorderingSyn[listIdx][i].uiLongTermPicNum; | |
| 502 | − for (j = 0; j < iLongRefCount; j++) { | |
| 503 | − if (ppLongRefList[j] != NULL) { | |
| 504 | − if (ppLongRefList[j]->uiLongTermPicNum == (uint32_t)iPredFrameNum) { | |
| 505 | − ppRefList[iCount++] = ppLongRefList[j]; | |
| 506 | − break; | |
| 507 | − } | |
| 508 | − } | |
| 509 | − } | |
| 510 | − k = iCount; | |
| 511 | − for (j = k; j <= iRefCount; j++) { | |
| 512 | − if (ppRefList[j] != NULL) { | |
| 513 | − if (!ppRefList[j]->bIsLongRef || ppLongRefList[j]->uiLongTermPicNum != (uint32_t)iPredFrameNum) | |
| 514 | − ppRefList[k++] = ppRefList[j]; | |
| 515 | − } | |
| 516 | − } | |
| 517 | − } | |
| 518 | − } | |
| 519 | − } | |
| 520 | − | |
| 521 | − for (i = WELS_MAX (1, WELS_MAX (iCount, pCtx->sRefPic.uiRefCount[listIdx])); i < iRefCount; i++) | |
| 522 | − ppRefList[i] = ppRefList[i - 1]; | |
| 523 | − pCtx->sRefPic.uiRefCount[listIdx] = (uint8_t)WELS_MIN (WELS_MAX (iCount, pCtx->sRefPic.uiRefCount[listIdx]), iRefCount); | |
| 524 | − } | |
| 525 | − return ERR_NONE; | |
| 526 | −} | |
| 527 | − | |
| 528 | −int32_t WelsMarkAsRef (PWelsDecoderContext pCtx) { | |
| 529 | − PRefPic pRefPic = &pCtx->sRefPic; | |
| 530 | − PRefPicMarking pRefPicMarking = pCtx->pCurDqLayer->pRefPicMarking; | |
| 531 | − PAccessUnit pCurAU = pCtx->pAccessUnitList; | |
| 532 | − bool bIsIDRAU = false; | |
| 533 | − uint32_t j; | |
| 534 | − | |
| 535 | − int32_t iRet = ERR_NONE; | |
| 536 | − | |
| 537 | − pCtx->pDec->uiQualityId = pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt.uiQualityId; | |
| 538 | − pCtx->pDec->uiTemporalId = pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt.uiTemporalId; | |
| 539 | − pCtx->pDec->iSpsId = pCtx->pSps->iSpsId; | |
| 540 | − pCtx->pDec->iPpsId = pCtx->pPps->iPpsId; | |
| 541 | − | |
| 542 | − for (j = pCurAU->uiStartPos; j <= pCurAU->uiEndPos; j++) { | |
| 543 | − if (pCurAU->pNalUnitsList[j]->sNalHeaderExt.sNalUnitHeader.eNalUnitType == NAL_UNIT_CODED_SLICE_IDR | |
| 544 | − || pCurAU->pNalUnitsList[j]->sNalHeaderExt.bIdrFlag) { | |
| 545 | − bIsIDRAU = true; | |
| 546 | − break; | |
| 547 | − } | |
| 548 | − } | |
| 549 | − if (bIsIDRAU) { | |
| 550 | − if (pRefPicMarking->bLongTermRefFlag) { | |
| 551 | − pCtx->sRefPic.iMaxLongTermFrameIdx = 0; | |
| 552 | − AddLongTermToList (pRefPic, pCtx->pDec, 0, 0); | |
| 553 | − } else { | |
| 554 | − pCtx->sRefPic.iMaxLongTermFrameIdx = -1; | |
| 555 | − } | |
| 556 | − } else { | |
| 557 | − if (pRefPicMarking->bAdaptiveRefPicMarkingModeFlag) { | |
| 558 | − iRet = MMCO (pCtx, pRefPicMarking); | |
| 559 | − if (iRet != ERR_NONE) { | |
| 560 | − if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 561 | − iRet = RemainOneBufferInDpbForEC (pCtx); | |
| 562 | − WELS_VERIFY_RETURN_IF (iRet, iRet); | |
| 563 | − } else { | |
| 564 | − return iRet; | |
| 565 | − } | |
| 566 | − } | |
| 567 | − | |
| 568 | − if (pCtx->bLastHasMmco5) { | |
| 569 | − pCtx->pDec->iFrameNum = 0; | |
| 570 | − pCtx->pDec->iFramePoc = 0; | |
| 571 | − } | |
| 572 | − | |
| 573 | − } else { | |
| 574 | − iRet = SlidingWindow (pCtx); | |
| 575 | − if (iRet != ERR_NONE) { | |
| 576 | − if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 577 | − iRet = RemainOneBufferInDpbForEC (pCtx); | |
| 578 | − WELS_VERIFY_RETURN_IF (iRet, iRet); | |
| 579 | − } else { | |
| 580 | − return iRet; | |
| 581 | − } | |
| 582 | − } | |
| 583 | − } | |
| 584 | − } | |
| 585 | − | |
| 586 | − if (!pCtx->pDec->bIsLongRef) { | |
| 587 | − if (pRefPic->uiLongRefCount[LIST_0] + pRefPic->uiShortRefCount[LIST_0] >= WELS_MAX (1, pCtx->pSps->iNumRefFrames)) { | |
| 588 | − if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 589 | − iRet = RemainOneBufferInDpbForEC (pCtx); | |
| 590 | − WELS_VERIFY_RETURN_IF (iRet, iRet); | |
| 591 | − } else { | |
| 592 | − return ERR_INFO_INVALID_MMCO_REF_NUM_OVERFLOW; | |
| 593 | − } | |
| 594 | − } | |
| 595 | − iRet = AddShortTermToList (pRefPic, pCtx->pDec); | |
| 596 | − } | |
| 597 | − | |
| 598 | − return iRet; | |
| 599 | −} | |
| 600 | − | |
| 601 | −static int32_t MMCO (PWelsDecoderContext pCtx, PRefPicMarking pRefPicMarking) { | |
| 602 | − PSps pSps = pCtx->pCurDqLayer->sLayerInfo.pSps; | |
| 603 | − int32_t i = 0; | |
| 604 | − int32_t iRet = ERR_NONE; | |
| 605 | − for (i = 0; i < MAX_MMCO_COUNT && pRefPicMarking->sMmcoRef[i].uiMmcoType != MMCO_END; i++) { | |
| 606 | − uint32_t uiMmcoType = pRefPicMarking->sMmcoRef[i].uiMmcoType; | |
| 607 | − int32_t iShortFrameNum = (pCtx->iFrameNum - pRefPicMarking->sMmcoRef[i].iDiffOfPicNum) & (( | |
| 608 | − 1 << pSps->uiLog2MaxFrameNum) - 1); | |
| 609 | − uint32_t uiLongTermPicNum = pRefPicMarking->sMmcoRef[i].uiLongTermPicNum; | |
| 610 | − int32_t iLongTermFrameIdx = pRefPicMarking->sMmcoRef[i].iLongTermFrameIdx; | |
| 611 | − int32_t iMaxLongTermFrameIdx = pRefPicMarking->sMmcoRef[i].iMaxLongTermFrameIdx; | |
| 612 | − if (uiMmcoType > MMCO_LONG) { | |
| 613 | − return ERR_INFO_INVALID_MMCO_OPCODE_BASE; | |
| 614 | − } | |
| 615 | − iRet = MMCOProcess (pCtx, uiMmcoType, iShortFrameNum, uiLongTermPicNum, iLongTermFrameIdx, iMaxLongTermFrameIdx); | |
| 616 | − if (iRet != ERR_NONE) { | |
| 617 | − return iRet; | |
| 618 | − } | |
| 619 | − } | |
| 620 | − 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; | |
| 622 | − } | |
| 623 | − | |
| 624 | − return ERR_NONE; | |
| 625 | −} | |
| 626 | −static int32_t MMCOProcess (PWelsDecoderContext pCtx, uint32_t uiMmcoType, | |
| 627 | − int32_t iShortFrameNum, uint32_t uiLongTermPicNum, int32_t iLongTermFrameIdx, int32_t iMaxLongTermFrameIdx) { | |
| 628 | − PRefPic pRefPic = &pCtx->sRefPic; | |
| 629 | − PPicture pPic = NULL; | |
| 630 | − int32_t i = 0; | |
| 631 | − int32_t iRet = ERR_NONE; | |
| 632 | − | |
| 633 | − switch (uiMmcoType) { | |
| 634 | − case MMCO_SHORT2UNUSED: | |
| 635 | − pPic = WelsDelShortFromListSetUnref (pRefPic, iShortFrameNum); | |
| 636 | − if (pPic == NULL) { | |
| 637 | − WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "MMCO_SHORT2UNUSED: delete an empty entry from short term list"); | |
| 638 | − } | |
| 639 | − break; | |
| 640 | − case MMCO_LONG2UNUSED: | |
| 641 | − pPic = WelsDelLongFromListSetUnref (pRefPic, uiLongTermPicNum); | |
| 642 | − if (pPic == NULL) { | |
| 643 | − WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "MMCO_LONG2UNUSED: delete an empty entry from long term list"); | |
| 644 | − } | |
| 645 | − break; | |
| 646 | − case MMCO_SHORT2LONG: | |
| 647 | − if (iLongTermFrameIdx > pRefPic->iMaxLongTermFrameIdx) { | |
| 648 | − return ERR_INFO_INVALID_MMCO_LONG_TERM_IDX_EXCEED_MAX; | |
| 649 | − } | |
| 650 | − pPic = WelsDelShortFromList (pRefPic, iShortFrameNum); | |
| 651 | − if (pPic == NULL) { | |
| 652 | − WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "MMCO_LONG2LONG: delete an empty entry from short term list"); | |
| 653 | − break; | |
| 654 | − } | |
| 655 | − WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx); | |
| 656 | −#ifdef LONG_TERM_REF | |
| 657 | − pCtx->bCurAuContainLtrMarkSeFlag = true; | |
| 658 | − pCtx->iFrameNumOfAuMarkedLtr = iShortFrameNum; | |
| 659 | − WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, "ex_mark_avc():::MMCO_SHORT2LONG:::LTR marking....iFrameNum: %d", | |
| 660 | − pCtx->iFrameNumOfAuMarkedLtr); | |
| 661 | −#endif | |
| 662 | − | |
| 663 | − MarkAsLongTerm (pRefPic, iShortFrameNum, iLongTermFrameIdx, uiLongTermPicNum); | |
| 664 | − break; | |
| 665 | − case MMCO_SET_MAX_LONG: | |
| 666 | − pRefPic->iMaxLongTermFrameIdx = iMaxLongTermFrameIdx; | |
| 667 | − for (i = 0 ; i < pRefPic->uiLongRefCount[LIST_0]; i++) { | |
| 668 | − if (pRefPic->pLongRefList[LIST_0][i]->iLongTermFrameIdx > pRefPic->iMaxLongTermFrameIdx) { | |
| 669 | − WelsDelLongFromListSetUnref (pRefPic, pRefPic->pLongRefList[LIST_0][i]->iLongTermFrameIdx); | |
| 670 | − } | |
| 671 | − } | |
| 672 | − break; | |
| 673 | − case MMCO_RESET: | |
| 674 | − WelsResetRefPic (pCtx); | |
| 675 | − pCtx->bLastHasMmco5 = true; | |
| 676 | − break; | |
| 677 | − case MMCO_LONG: | |
| 678 | − if (iLongTermFrameIdx > pRefPic->iMaxLongTermFrameIdx) { | |
| 679 | − return ERR_INFO_INVALID_MMCO_LONG_TERM_IDX_EXCEED_MAX; | |
| 680 | − } | |
| 681 | − WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx); | |
| 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; | |
| 684 | − } | |
| 685 | −#ifdef LONG_TERM_REF | |
| 686 | − pCtx->bCurAuContainLtrMarkSeFlag = true; | |
| 687 | − pCtx->iFrameNumOfAuMarkedLtr = pCtx->iFrameNum; | |
| 688 | − WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, "ex_mark_avc():::MMCO_LONG:::LTR marking....iFrameNum: %d", | |
| 689 | − pCtx->iFrameNum); | |
| 690 | −#endif | |
| 691 | − iRet = AddLongTermToList (pRefPic, pCtx->pDec, iLongTermFrameIdx, uiLongTermPicNum); | |
| 692 | − break; | |
| 693 | − default : | |
| 694 | − break; | |
| 695 | − } | |
| 696 | − | |
| 697 | − return iRet; | |
| 698 | −} | |
| 699 | − | |
| 700 | −static int32_t SlidingWindow (PWelsDecoderContext pCtx) { | |
| 701 | − PRefPic pRefPic = &pCtx->sRefPic; | |
| 702 | − PPicture pPic = NULL; | |
| 703 | − int32_t i = 0; | |
| 704 | − | |
| 705 | − if (pCtx->sRefPic.uiShortRefCount[LIST_0] + pCtx->sRefPic.uiLongRefCount[LIST_0] >= pCtx->pSps->iNumRefFrames) { | |
| 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"); | |
| 708 | − return ERR_INFO_INVALID_MMCO_REF_NUM_NOT_ENOUGH; | |
| 709 | − } | |
| 710 | − for (i = pRefPic->uiShortRefCount[LIST_0] - 1; i >= 0; i--) { | |
| 711 | − pPic = WelsDelShortFromList (pRefPic, pRefPic->pShortRefList[LIST_0][i]->iFrameNum); | |
| 712 | − if (pPic) { | |
| 713 | − SetUnRef (pPic); | |
| 714 | − break; | |
| 715 | − } else { | |
| 716 | − return ERR_INFO_INVALID_MMCO_REF_NUM_OVERFLOW; | |
| 717 | − } | |
| 718 | − } | |
| 719 | − } | |
| 720 | − return ERR_NONE; | |
| 721 | −} | |
| 722 | − | |
| 723 | −static PPicture WelsDelShortFromList (PRefPic pRefPic, int32_t iFrameNum) { | |
| 724 | − int32_t i = 0; | |
| 725 | − int32_t iMoveSize = 0; | |
| 726 | − PPicture pPic = NULL; | |
| 727 | − | |
| 728 | − for (i = 0; i < pRefPic->uiShortRefCount[LIST_0]; i++) { | |
| 729 | − if (pRefPic->pShortRefList[LIST_0][i]->iFrameNum == iFrameNum) { | |
| 730 | − iMoveSize = pRefPic->uiShortRefCount[LIST_0] - i - 1; | |
| 731 | − pRefPic->pShortRefList[LIST_0][i]->bUsedAsRef = false; | |
| 732 | − pPic = pRefPic->pShortRefList[LIST_0][i]; | |
| 733 | − pRefPic->pShortRefList[LIST_0][i] = NULL; | |
| 734 | − if (iMoveSize > 0) { | |
| 735 | − memmove (&pRefPic->pShortRefList[LIST_0][i], &pRefPic->pShortRefList[LIST_0][i + 1], | |
| 736 | − iMoveSize * sizeof (PPicture)); //confirmed_safe_unsafe_usage | |
| 737 | − } | |
| 738 | − pRefPic->uiShortRefCount[LIST_0]--; | |
| 739 | − pRefPic->pShortRefList[LIST_0][pRefPic->uiShortRefCount[LIST_0]] = NULL; | |
| 740 | − break; | |
| 741 | − } | |
| 742 | − } | |
| 743 | − | |
| 744 | − return pPic; | |
| 745 | −} | |
| 746 | − | |
| 747 | −static PPicture WelsDelShortFromListSetUnref (PRefPic pRefPic, int32_t iFrameNum) { | |
| 748 | − PPicture pPic = WelsDelShortFromList (pRefPic, iFrameNum); | |
| 749 | − if (pPic) { | |
| 750 | − SetUnRef (pPic); | |
| 751 | − } | |
| 752 | − return pPic; | |
| 753 | −} | |
| 754 | − | |
| 755 | −static PPicture WelsDelLongFromList (PRefPic pRefPic, uint32_t uiLongTermFrameIdx) { | |
| 756 | − PPicture pPic = NULL; | |
| 757 | − int32_t i = 0; | |
| 758 | − for (i = 0; i < pRefPic->uiLongRefCount[LIST_0]; i++) { | |
| 759 | − pPic = pRefPic->pLongRefList[LIST_0][i]; | |
| 760 | − if (pPic->iLongTermFrameIdx == (int32_t)uiLongTermFrameIdx) { | |
| 761 | − int32_t iMoveSize = pRefPic->uiLongRefCount[LIST_0] - i - 1; | |
| 762 | − pPic->bUsedAsRef = false; | |
| 763 | − pPic->bIsLongRef = false; | |
| 764 | − if (iMoveSize > 0) { | |
| 765 | − memmove (&pRefPic->pLongRefList[LIST_0][i], &pRefPic->pLongRefList[LIST_0][i + 1], | |
| 766 | − iMoveSize * sizeof (PPicture)); //confirmed_safe_unsafe_usage | |
| 767 | − } | |
| 768 | − pRefPic->uiLongRefCount[LIST_0]--; | |
| 769 | − pRefPic->pLongRefList[LIST_0][pRefPic->uiLongRefCount[LIST_0]] = NULL; | |
| 770 | − return pPic; | |
| 771 | − } | |
| 772 | − } | |
| 773 | − return NULL; | |
| 774 | −} | |
| 775 | − | |
| 776 | −static PPicture WelsDelLongFromListSetUnref (PRefPic pRefPic, uint32_t uiLongTermFrameIdx) { | |
| 777 | − PPicture pPic = WelsDelLongFromList (pRefPic, uiLongTermFrameIdx); | |
| 778 | − if (pPic) { | |
| 779 | − SetUnRef (pPic); | |
| 780 | − } | |
| 781 | − return pPic; | |
| 782 | −} | |
| 783 | − | |
| 784 | −static int32_t AddShortTermToList (PRefPic pRefPic, PPicture pPic) { | |
| 785 | − pPic->bUsedAsRef = true; | |
| 786 | − pPic->bIsLongRef = false; | |
| 787 | − pPic->iLongTermFrameIdx = -1; | |
| 788 | − if (pRefPic->uiShortRefCount[LIST_0] > 0) { | |
| 789 | − // Check the duplicate frame_num in short ref list | |
| 790 | − for (int32_t iPos = 0; iPos < pRefPic->uiShortRefCount[LIST_0]; iPos++) { | |
| 791 | − if (pPic->iFrameNum == pRefPic->pShortRefList[LIST_0][iPos]->iFrameNum) { | |
| 792 | − // Replace the previous ref pic with the new one with the same frame_num | |
| 793 | − pRefPic->pShortRefList[LIST_0][iPos] = pPic; | |
| 794 | − return ERR_INFO_DUPLICATE_FRAME_NUM; | |
| 795 | − } | |
| 796 | − } | |
| 797 | − | |
| 798 | − memmove (&pRefPic->pShortRefList[LIST_0][1], &pRefPic->pShortRefList[LIST_0][0], | |
| 799 | − pRefPic->uiShortRefCount[LIST_0]*sizeof (PPicture));//confirmed_safe_unsafe_usage | |
| 800 | − } | |
| 801 | − pRefPic->pShortRefList[LIST_0][0] = pPic; | |
| 802 | − pRefPic->uiShortRefCount[LIST_0]++; | |
| 803 | − return ERR_NONE; | |
| 804 | −} | |
| 805 | − | |
| 806 | −static int32_t AddLongTermToList (PRefPic pRefPic, PPicture pPic, int32_t iLongTermFrameIdx, | |
| 807 | − uint32_t uiLongTermPicNum) { | |
| 808 | − int32_t i = 0; | |
| 809 | − | |
| 810 | − pPic->bUsedAsRef = true; | |
| 811 | − pPic->bIsLongRef = true; | |
| 812 | − pPic->iLongTermFrameIdx = iLongTermFrameIdx; | |
| 813 | − pPic->uiLongTermPicNum = uiLongTermPicNum; | |
| 814 | − if (pRefPic->uiLongRefCount[LIST_0] == 0) { | |
| 815 | − pRefPic->pLongRefList[LIST_0][pRefPic->uiLongRefCount[LIST_0]] = pPic; | |
| 816 | − } else { | |
| 817 | − for (i = 0; i < pRefPic->uiLongRefCount[LIST_0]; i++) { | |
| 818 | − if (pRefPic->pLongRefList[LIST_0][i]->iLongTermFrameIdx > pPic->iLongTermFrameIdx) { | |
| 819 | − break; | |
| 820 | − } | |
| 821 | − } | |
| 822 | − memmove (&pRefPic->pLongRefList[LIST_0][i + 1], &pRefPic->pLongRefList[LIST_0][i], | |
| 823 | − (pRefPic->uiLongRefCount[LIST_0] - i)*sizeof (PPicture)); //confirmed_safe_unsafe_usage | |
| 824 | − pRefPic->pLongRefList[LIST_0][i] = pPic; | |
| 825 | − } | |
| 826 | − | |
| 827 | − pRefPic->uiLongRefCount[LIST_0]++; | |
| 828 | − return ERR_NONE; | |
| 829 | −} | |
| 830 | − | |
| 831 | −static int32_t MarkAsLongTerm (PRefPic pRefPic, int32_t iFrameNum, int32_t iLongTermFrameIdx, | |
| 832 | − uint32_t uiLongTermPicNum) { | |
| 833 | − PPicture pPic = NULL; | |
| 834 | − int32_t i = 0; | |
| 835 | − int32_t iRet = ERR_NONE; | |
| 836 | − WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx); | |
| 837 | − | |
| 838 | − for (i = 0; i < pRefPic->uiRefCount[LIST_0]; i++) { | |
| 839 | − pPic = pRefPic->pRefList[LIST_0][i]; | |
| 840 | − if (pPic->iFrameNum == iFrameNum && !pPic->bIsLongRef) { | |
| 841 | − iRet = AddLongTermToList (pRefPic, pPic, iLongTermFrameIdx, uiLongTermPicNum); | |
| 842 | − break; | |
| 843 | − } | |
| 844 | − } | |
| 845 | − | |
| 846 | − return iRet; | |
| 847 | −} | |
| 848 | − | |
| 849 | −#ifdef LONG_TERM_REF | |
| 850 | −int32_t GetLTRFrameIndex (PRefPic pRefPic, int32_t iAncLTRFrameNum) { | |
| 851 | − int32_t iLTRFrameIndex = -1; | |
| 852 | − PPicture pPic; | |
| 853 | − for (int i = 0; i < pRefPic->uiLongRefCount[0]; ++i) { | |
| 854 | − pPic = pRefPic->pLongRefList[LIST_0][i]; | |
| 855 | − if (pPic->iFrameNum == iAncLTRFrameNum) { | |
| 856 | − return (pPic->iLongTermFrameIdx); | |
| 857 | − } | |
| 858 | − } | |
| 859 | − return iLTRFrameIndex; | |
| 860 | −} | |
| 861 | −#endif | |
| 862 | − | |
| 863 | −static int32_t RemainOneBufferInDpbForEC (PWelsDecoderContext pCtx) { | |
| 864 | − int32_t iRet = ERR_NONE; | |
| 865 | − PRefPic pRefPic = &pCtx->sRefPic; | |
| 866 | − if (pRefPic->uiShortRefCount[0] + pRefPic->uiLongRefCount[0] < pCtx->pSps->iNumRefFrames) | |
| 867 | − return iRet; | |
| 868 | − | |
| 869 | − if (pRefPic->uiShortRefCount[0] > 0) { | |
| 870 | − iRet = SlidingWindow (pCtx); | |
| 871 | − } else { //all LTR, remove the smallest long_term_frame_idx | |
| 872 | − int32_t iLongTermFrameIdx = 0; | |
| 873 | − int32_t iMaxLongTermFrameIdx = pRefPic->iMaxLongTermFrameIdx; | |
| 874 | −#ifdef LONG_TERM_REF | |
| 875 | − int32_t iCurrLTRFrameIdx = GetLTRFrameIndex (pRefPic, pCtx->iFrameNumOfAuMarkedLtr); | |
| 876 | −#endif | |
| 877 | − while ((pRefPic->uiLongRefCount[0] >= pCtx->pSps->iNumRefFrames) && (iLongTermFrameIdx <= iMaxLongTermFrameIdx)) { | |
| 878 | −#ifdef LONG_TERM_REF | |
| 879 | − if (iLongTermFrameIdx == iCurrLTRFrameIdx) { | |
| 880 | − iLongTermFrameIdx++; | |
| 881 | − continue; | |
| 882 | − } | |
| 883 | −#endif | |
| 884 | − WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx); | |
| 885 | − iLongTermFrameIdx++; | |
| 886 | − } | |
| 887 | − } | |
| 888 | − if (pRefPic->uiShortRefCount[0] + pRefPic->uiLongRefCount[0] >= | |
| 889 | − 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!"); | |
| 891 | − iRet = ERR_INFO_REF_COUNT_OVERFLOW; | |
| 892 | − } | |
| 893 | − | |
| 894 | − return iRet; | |
| 895 | −} | |
| 896 | − | |
| 897 | −} // namespace WelsDec | |
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 2008-2013, Cisco Systems | |
| 4 | + * All rights reserved. | |
| 5 | + * | |
| 6 | + * Redistribution and use in source and binary forms, with or without | |
| 7 | + * modification, are permitted provided that the following conditions | |
| 8 | + * are met: | |
| 9 | + * | |
| 10 | + * * Redistributions of source code must retain the above copyright | |
| 11 | + * notice, this list of conditions and the following disclaimer. | |
| 12 | + * | |
| 13 | + * * Redistributions in binary form must reproduce the above copyright | |
| 14 | + * notice, this list of conditions and the following disclaimer in | |
| 15 | + * the documentation and/or other materials provided with the | |
| 16 | + * distribution. | |
| 17 | + * | |
| 18 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 21 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 22 | + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 23 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 26 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
| 28 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | + * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | + * | |
| 31 | + * | |
| 32 | + * manage_dec_ref.cpp | |
| 33 | + * | |
| 34 | + * Abstract | |
| 35 | + * Implementation for managing reference picture | |
| 36 | + * | |
| 37 | + * History | |
| 38 | + * 07/21/2008 Created | |
| 39 | + * | |
| 40 | + *****************************************************************************/ | |
| 41 | + | |
| 42 | +#include "manage_dec_ref.h" | |
| 43 | +#include "error_concealment.h" | |
| 44 | +#include "error_code.h" | |
| 45 | + | |
| 46 | +namespace WelsDec { | |
| 47 | + | |
| 48 | +static PPicture WelsDelShortFromList (PRefPic pRefPic, int32_t iFrameNum); | |
| 49 | +static PPicture WelsDelLongFromList (PRefPic pRefPic, uint32_t uiLongTermFrameIdx); | |
| 50 | +static PPicture WelsDelShortFromListSetUnref (PRefPic pRefPic, int32_t iFrameNum); | |
| 51 | +static PPicture WelsDelLongFromListSetUnref (PRefPic pRefPic, uint32_t uiLongTermFrameIdx); | |
| 52 | + | |
| 53 | +static int32_t MMCO (PWelsDecoderContext pCtx, PRefPicMarking pRefPicMarking); | |
| 54 | +static int32_t MMCOProcess (PWelsDecoderContext pCtx, uint32_t uiMmcoType, | |
| 55 | + int32_t iShortFrameNum, uint32_t uiLongTermPicNum, int32_t iLongTermFrameIdx, int32_t iMaxLongTermFrameIdx); | |
| 56 | +static int32_t SlidingWindow (PWelsDecoderContext pCtx); | |
| 57 | + | |
| 58 | +static int32_t AddShortTermToList (PRefPic pRefPic, PPicture pPic); | |
| 59 | +static int32_t AddLongTermToList (PRefPic pRefPic, PPicture pPic, int32_t iLongTermFrameIdx, uint32_t uiLongTermPicNum); | |
| 60 | +static int32_t MarkAsLongTerm (PRefPic pRefPic, int32_t iFrameNum, int32_t iLongTermFrameIdx, | |
| 61 | + uint32_t uiLongTermPicNum); | |
| 62 | +static int32_t WelsCheckAndRecoverForFutureDecoding (PWelsDecoderContext pCtx); | |
| 63 | +#ifdef LONG_TERM_REF | |
| 64 | +int32_t GetLTRFrameIndex (PRefPic pRefPic, int32_t iAncLTRFrameNum); | |
| 65 | +#endif | |
| 66 | +static int32_t RemainOneBufferInDpbForEC (PWelsDecoderContext pCtx); | |
| 67 | + | |
| 68 | +static void SetUnRef (PPicture pRef) { | |
| 69 | + if (NULL != pRef) { | |
| 70 | + pRef->bUsedAsRef = false; | |
| 71 | + pRef->bIsLongRef = false; | |
| 72 | + pRef->iFrameNum = -1; | |
| 73 | + pRef->iFrameWrapNum = -1; | |
| 74 | + //pRef->iFramePoc = 0; | |
| 75 | + pRef->iLongTermFrameIdx = -1; | |
| 76 | + pRef->uiLongTermPicNum = 0; | |
| 77 | + pRef->uiQualityId = -1; | |
| 78 | + pRef->uiTemporalId = -1; | |
| 79 | + pRef->uiSpatialId = -1; | |
| 80 | + pRef->iSpsId = -1; | |
| 81 | + pRef->bIsComplete = false; | |
| 82 | + } | |
| 83 | +} | |
| 84 | + | |
| 85 | +//reset pRefList when | |
| 86 | +// 1.sps arrived that is new sequence starting | |
| 87 | +// 2.IDR NAL i.e. 1st layer in IDR AU | |
| 88 | + | |
| 89 | +void WelsResetRefPic (PWelsDecoderContext pCtx) { | |
| 90 | + int32_t i = 0; | |
| 91 | + PRefPic pRefPic = &pCtx->sRefPic; | |
| 92 | + pCtx->sRefPic.uiLongRefCount[LIST_0] = pCtx->sRefPic.uiShortRefCount[LIST_0] = 0; | |
| 93 | + | |
| 94 | + pRefPic->uiRefCount[LIST_0] = 0; | |
| 95 | + pRefPic->uiRefCount[LIST_1] = 0; | |
| 96 | + | |
| 97 | + for (i = 0; i < MAX_DPB_COUNT; i++) { | |
| 98 | + if (pRefPic->pShortRefList[LIST_0][i] != NULL) { | |
| 99 | + SetUnRef (pRefPic->pShortRefList[LIST_0][i]); | |
| 100 | + pRefPic->pShortRefList[LIST_0][i] = NULL; | |
| 101 | + } | |
| 102 | + } | |
| 103 | + pRefPic->uiShortRefCount[LIST_0] = 0; | |
| 104 | + | |
| 105 | + for (i = 0; i < MAX_DPB_COUNT; i++) { | |
| 106 | + if (pRefPic->pLongRefList[LIST_0][i] != NULL) { | |
| 107 | + SetUnRef (pRefPic->pLongRefList[LIST_0][i]); | |
| 108 | + pRefPic->pLongRefList[LIST_0][i] = NULL; | |
| 109 | + } | |
| 110 | + } | |
| 111 | + pRefPic->uiLongRefCount[LIST_0] = 0; | |
| 112 | +} | |
| 113 | + | |
| 114 | +static int32_t WelsCheckAndRecoverForFutureDecoding (PWelsDecoderContext pCtx) { | |
| 115 | + if ((pCtx->sRefPic.uiShortRefCount[LIST_0] + pCtx->sRefPic.uiLongRefCount[LIST_0] <= 0) && (pCtx->eSliceType != I_SLICE | |
| 116 | + && pCtx->eSliceType != SI_SLICE)) { | |
| 117 | + if (pCtx->pParam->eEcActiveIdc != | |
| 118 | + ERROR_CON_DISABLE) { //IDR lost!, recover it for future decoding with data all set to 0 | |
| 119 | + PPicture pRef = PrefetchPic (pCtx->pPicBuff); | |
| 120 | + if (pRef != NULL) { | |
| 121 | + // IDR lost, set new | |
| 122 | + pRef->bIsComplete = false; // Set complete flag to false for lost IDR ref picture | |
| 123 | + pRef->iSpsId = pCtx->pSps->iSpsId; | |
| 124 | + pRef->iPpsId = pCtx->pPps->iPpsId; | |
| 125 | + pCtx->iErrorCode |= dsDataErrorConcealed; | |
| 126 | + bool bCopyPrevious = ((ERROR_CON_FRAME_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) | |
| 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)) | |
| 131 | + && (NULL != pCtx->pPreviousDecodedPictureInDpb); | |
| 132 | + bCopyPrevious = bCopyPrevious && (pRef->iWidthInPixel == pCtx->pPreviousDecodedPictureInDpb->iWidthInPixel) | |
| 133 | + && (pRef->iHeightInPixel == pCtx->pPreviousDecodedPictureInDpb->iHeightInPixel); | |
| 134 | + | |
| 135 | + if (!bCopyPrevious) { | |
| 136 | + memset (pRef->pData[0], 128, pRef->iLinesize[0] * pRef->iHeightInPixel); | |
| 137 | + memset (pRef->pData[1], 128, pRef->iLinesize[1] * pRef->iHeightInPixel / 2); | |
| 138 | + memset (pRef->pData[2], 128, pRef->iLinesize[2] * pRef->iHeightInPixel / 2); | |
| 139 | + } else if (pRef == pCtx->pPreviousDecodedPictureInDpb) { | |
| 140 | + WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "WelsInitRefList()::EC memcpy overlap."); | |
| 141 | + } else { | |
| 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); | |
| 144 | + memcpy (pRef->pData[2], pCtx->pPreviousDecodedPictureInDpb->pData[2], pRef->iLinesize[2] * pRef->iHeightInPixel / 2); | |
| 145 | + } | |
| 146 | + pRef->iFrameNum = 0; | |
| 147 | + pRef->iFramePoc = 0; | |
| 148 | + pRef->uiTemporalId = pRef->uiQualityId = 0; | |
| 149 | + ExpandReferencingPicture (pRef->pData, pRef->iWidthInPixel, pRef->iHeightInPixel, pRef->iLinesize, | |
| 150 | + pCtx->sExpandPicFunc.pfExpandLumaPicture, pCtx->sExpandPicFunc.pfExpandChromaPicture); | |
| 151 | + AddShortTermToList (&pCtx->sRefPic, pRef); | |
| 152 | + } else { | |
| 153 | + WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "WelsInitRefList()::PrefetchPic for EC errors."); | |
| 154 | + pCtx->iErrorCode |= dsOutOfMemory; | |
| 155 | + return ERR_INFO_REF_COUNT_OVERFLOW; | |
| 156 | + } | |
| 157 | + } | |
| 158 | + } | |
| 159 | + return ERR_NONE; | |
| 160 | +} | |
| 161 | + | |
| 162 | +static void WrapShortRefPicNum (PWelsDecoderContext pCtx) { | |
| 163 | + int32_t i; | |
| 164 | + PSliceHeader pSliceHeader = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader; | |
| 165 | + int32_t iMaxPicNum = 1 << pSliceHeader->pSps->uiLog2MaxFrameNum; | |
| 166 | + PPicture* ppShoreRefList = pCtx->sRefPic.pShortRefList[LIST_0]; | |
| 167 | + int32_t iShortRefCount = pCtx->sRefPic.uiShortRefCount[LIST_0]; | |
| 168 | + //wrap pic num | |
| 169 | + for (i = 0; i < iShortRefCount; i++) { | |
| 170 | + if (ppShoreRefList[i]) { | |
| 171 | + if (ppShoreRefList[i]->iFrameNum > pSliceHeader->iFrameNum) | |
| 172 | + ppShoreRefList[i]->iFrameWrapNum = ppShoreRefList[i]->iFrameNum - iMaxPicNum; | |
| 173 | + else | |
| 174 | + ppShoreRefList[i]->iFrameWrapNum = ppShoreRefList[i]->iFrameNum; | |
| 175 | + } | |
| 176 | + } | |
| 177 | +} | |
| 178 | + | |
| 179 | +/** | |
| 180 | +* fills the pRefPic.pRefList LIST_0 and LIST_0 for B-Slice. | |
| 181 | +*/ | |
| 182 | +int32_t WelsInitBSliceRefList (PWelsDecoderContext pCtx, int32_t iPoc) { | |
| 183 | + | |
| 184 | + int32_t err = WelsCheckAndRecoverForFutureDecoding (pCtx); | |
| 185 | + if (err != ERR_NONE) return err; | |
| 186 | + | |
| 187 | + WrapShortRefPicNum (pCtx); | |
| 188 | + | |
| 189 | + PPicture* ppShoreRefList = pCtx->sRefPic.pShortRefList[LIST_0]; | |
| 190 | + PPicture* ppLongRefList = pCtx->sRefPic.pLongRefList[LIST_0]; | |
| 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)); | |
| 193 | + int32_t iLSCurrPocCount = 0; | |
| 194 | + int32_t iLTCurrPocCount = 0; | |
| 195 | + PPicture pLSCurrPocList0[MAX_DPB_COUNT]; | |
| 196 | + PPicture pLTCurrPocList0[MAX_DPB_COUNT]; | |
| 197 | + for (int32_t i = 0; i < pCtx->sRefPic.uiShortRefCount[LIST_0]; ++i) { | |
| 198 | + if (ppShoreRefList[i]->iFramePoc < iPoc) { | |
| 199 | + pLSCurrPocList0[iLSCurrPocCount++] = ppShoreRefList[i]; | |
| 200 | + } | |
| 201 | + } | |
| 202 | + for (int32_t i = pCtx->sRefPic.uiShortRefCount[LIST_0] - 1; i >= 0; --i) { | |
| 203 | + if (ppShoreRefList[i]->iFramePoc > iPoc) { | |
| 204 | + pLTCurrPocList0[iLTCurrPocCount++] = ppShoreRefList[i]; | |
| 205 | + } | |
| 206 | + } | |
| 207 | + if (pCtx->sRefPic.uiLongRefCount[LIST_0] > 1) { | |
| 208 | + //long sorts in increasing order | |
| 209 | + PPicture pTemp; | |
| 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) { | |
| 212 | + if (ppLongRefList[j]->iFramePoc < ppLongRefList[i]->iFramePoc) { | |
| 213 | + pTemp = ppLongRefList[i]; | |
| 214 | + ppLongRefList[i] = ppLongRefList[j]; | |
| 215 | + ppLongRefList[j] = pTemp; | |
| 216 | + } | |
| 217 | + } | |
| 218 | + } | |
| 219 | + } | |
| 220 | + int32_t iCurrPocCount = iLSCurrPocCount + iLTCurrPocCount; | |
| 221 | + int32_t iCount = 0; | |
| 222 | + //LIST_0 | |
| 223 | + //short | |
| 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) { | |
| 226 | + pCtx->sRefPic.pRefList[LIST_0][iCount++] = pLSCurrPocList0[i]; | |
| 227 | + } | |
| 228 | + if (iLSCurrPocCount > 1) { | |
| 229 | + //LIST_0 short sorts in decreasing order | |
| 230 | + PPicture pTemp; | |
| 231 | + for (int32_t i = 0; i < iLSCurrPocCount; ++i) { | |
| 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) { | |
| 234 | + pTemp = pCtx->sRefPic.pRefList[LIST_0][i]; | |
| 235 | + pCtx->sRefPic.pRefList[LIST_0][i] = pCtx->sRefPic.pRefList[LIST_0][j]; | |
| 236 | + pCtx->sRefPic.pRefList[LIST_0][j] = pTemp; | |
| 237 | + } | |
| 238 | + } | |
| 239 | + } | |
| 240 | + } | |
| 241 | + for (int32_t i = 0; i < iLTCurrPocCount; ++i) { | |
| 242 | + pCtx->sRefPic.pRefList[LIST_0][iCount++] = pLTCurrPocList0[i]; | |
| 243 | + } | |
| 244 | + if (iLTCurrPocCount > 1) { | |
| 245 | + //LIST_0 short sorts in increasing order | |
| 246 | + PPicture pTemp; | |
| 247 | + for (int32_t i = iLSCurrPocCount; i < iCurrPocCount; ++i) { | |
| 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) { | |
| 250 | + pTemp = pCtx->sRefPic.pRefList[LIST_0][i]; | |
| 251 | + pCtx->sRefPic.pRefList[LIST_0][i] = pCtx->sRefPic.pRefList[LIST_0][j]; | |
| 252 | + pCtx->sRefPic.pRefList[LIST_0][j] = pTemp; | |
| 253 | + } | |
| 254 | + } | |
| 255 | + } | |
| 256 | + } | |
| 257 | + //long | |
| 258 | + for (int32_t i = 0; i < pCtx->sRefPic.uiLongRefCount[LIST_0]; ++i) { | |
| 259 | + pCtx->sRefPic.pRefList[LIST_0][iCount++] = ppLongRefList[i]; | |
| 260 | + } | |
| 261 | + pCtx->sRefPic.uiRefCount[LIST_0] = iCount; | |
| 262 | + | |
| 263 | + iCount = 0; | |
| 264 | + //LIST_1 | |
| 265 | + //short | |
| 266 | + for (int32_t i = 0; i < iLTCurrPocCount; ++i) { | |
| 267 | + pCtx->sRefPic.pRefList[LIST_1][iCount++] = pLTCurrPocList0[i]; | |
| 268 | + } | |
| 269 | + if (iLTCurrPocCount > 1) { | |
| 270 | + //LIST_1 short sorts in increasing order | |
| 271 | + PPicture pTemp; | |
| 272 | + for (int32_t i = 0; i < iLTCurrPocCount; ++i) { | |
| 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) { | |
| 275 | + pTemp = pCtx->sRefPic.pRefList[LIST_1][i]; | |
| 276 | + pCtx->sRefPic.pRefList[LIST_1][i] = pCtx->sRefPic.pRefList[LIST_1][j]; | |
| 277 | + pCtx->sRefPic.pRefList[LIST_1][j] = pTemp; | |
| 278 | + } | |
| 279 | + } | |
| 280 | + } | |
| 281 | + } | |
| 282 | + for (int32_t i = 0; i < iLSCurrPocCount; ++i) { | |
| 283 | + pCtx->sRefPic.pRefList[LIST_1][iCount++] = pLSCurrPocList0[i]; | |
| 284 | + } | |
| 285 | + if (iLSCurrPocCount > 1) { | |
| 286 | + //LIST_1 short sorts in decreasing order | |
| 287 | + PPicture pTemp; | |
| 288 | + for (int32_t i = iLTCurrPocCount; i < iCurrPocCount; ++i) { | |
| 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) { | |
| 291 | + pTemp = pCtx->sRefPic.pRefList[LIST_1][i]; | |
| 292 | + pCtx->sRefPic.pRefList[LIST_1][i] = pCtx->sRefPic.pRefList[LIST_1][j]; | |
| 293 | + pCtx->sRefPic.pRefList[LIST_1][j] = pTemp; | |
| 294 | + } | |
| 295 | + } | |
| 296 | + } | |
| 297 | + } | |
| 298 | + //long | |
| 299 | + for (int32_t i = 0; i < pCtx->sRefPic.uiLongRefCount[LIST_0]; ++i) { | |
| 300 | + pCtx->sRefPic.pRefList[LIST_1][iCount++] = ppLongRefList[i]; | |
| 301 | + } | |
| 302 | + pCtx->sRefPic.uiRefCount[LIST_1] = iCount; | |
| 303 | + return ERR_NONE; | |
| 304 | +} | |
| 305 | + | |
| 306 | +/** | |
| 307 | + * fills the pRefPic.pRefList. | |
| 308 | + */ | |
| 309 | +int32_t WelsInitRefList (PWelsDecoderContext pCtx, int32_t iPoc) { | |
| 310 | + | |
| 311 | + int32_t err = WelsCheckAndRecoverForFutureDecoding (pCtx); | |
| 312 | + if (err != ERR_NONE) return err; | |
| 313 | + | |
| 314 | + WrapShortRefPicNum (pCtx); | |
| 315 | + | |
| 316 | + PPicture* ppShoreRefList = pCtx->sRefPic.pShortRefList[LIST_0]; | |
| 317 | + PPicture* ppLongRefList = pCtx->sRefPic.pLongRefList[LIST_0]; | |
| 318 | + memset (pCtx->sRefPic.pRefList[LIST_0], 0, MAX_DPB_COUNT * sizeof (PPicture)); | |
| 319 | + | |
| 320 | + int32_t i, iCount = 0; | |
| 321 | + //short | |
| 322 | + for (i = 0; i < pCtx->sRefPic.uiShortRefCount[LIST_0]; ++i) { | |
| 323 | + pCtx->sRefPic.pRefList[LIST_0][iCount++ ] = ppShoreRefList[i]; | |
| 324 | + } | |
| 325 | + | |
| 326 | + //long | |
| 327 | + for (i = 0; i < pCtx->sRefPic.uiLongRefCount[LIST_0] ; ++i) { | |
| 328 | + pCtx->sRefPic.pRefList[LIST_0][iCount++ ] = ppLongRefList[i]; | |
| 329 | + } | |
| 330 | + pCtx->sRefPic.uiRefCount[LIST_0] = iCount; | |
| 331 | + | |
| 332 | + return ERR_NONE; | |
| 333 | +} | |
| 334 | + | |
| 335 | +int32_t WelsReorderRefList (PWelsDecoderContext pCtx) { | |
| 336 | + | |
| 337 | + if (pCtx->eSliceType == I_SLICE || pCtx->eSliceType == SI_SLICE) { | |
| 338 | + return ERR_NONE; | |
| 339 | + } | |
| 340 | + | |
| 341 | + PRefPicListReorderSyn pRefPicListReorderSyn = pCtx->pCurDqLayer->pRefPicListReordering; | |
| 342 | + PNalUnitHeaderExt pNalHeaderExt = &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt; | |
| 343 | + PSliceHeader pSliceHeader = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader; | |
| 344 | + int32_t ListCount = 1; | |
| 345 | + if (pCtx->eSliceType == B_SLICE) ListCount = 2; | |
| 346 | + for (int32_t listIdx = 0; listIdx < ListCount; ++listIdx) { | |
| 347 | + PPicture pPic = NULL; | |
| 348 | + PPicture* ppRefList = pCtx->sRefPic.pRefList[listIdx]; | |
| 349 | + int32_t iMaxRefIdx = pCtx->pSps->iNumRefFrames; | |
| 350 | + int32_t iRefCount = pCtx->sRefPic.uiRefCount[listIdx]; | |
| 351 | + int32_t iPredFrameNum = pSliceHeader->iFrameNum; | |
| 352 | + int32_t iMaxPicNum = 1 << pSliceHeader->pSps->uiLog2MaxFrameNum; | |
| 353 | + int32_t iAbsDiffPicNum = -1; | |
| 354 | + int32_t iReorderingIndex = 0; | |
| 355 | + int32_t i = 0; | |
| 356 | + | |
| 357 | + if (iRefCount <= 0) { | |
| 358 | + pCtx->iErrorCode = dsNoParamSets; //No any reference for decoding, SHOULD request IDR | |
| 359 | + return ERR_INFO_REFERENCE_PIC_LOST; | |
| 360 | + } | |
| 361 | + | |
| 362 | + if (pRefPicListReorderSyn->bRefPicListReorderingFlag[listIdx]) { | |
| 363 | + while ((iReorderingIndex < iMaxRefIdx) | |
| 364 | + && (pRefPicListReorderSyn->sReorderingSyn[listIdx][iReorderingIndex].uiReorderingOfPicNumsIdc != 3)) { | |
| 365 | + uint16_t uiReorderingOfPicNumsIdc = | |
| 366 | + pRefPicListReorderSyn->sReorderingSyn[listIdx][iReorderingIndex].uiReorderingOfPicNumsIdc; | |
| 367 | + if (uiReorderingOfPicNumsIdc < 2) { | |
| 368 | + iAbsDiffPicNum = pRefPicListReorderSyn->sReorderingSyn[listIdx][iReorderingIndex].uiAbsDiffPicNumMinus1 + 1; | |
| 369 | + | |
| 370 | + if (uiReorderingOfPicNumsIdc == 0) { | |
| 371 | + iPredFrameNum -= iAbsDiffPicNum; | |
| 372 | + } else { | |
| 373 | + iPredFrameNum += iAbsDiffPicNum; | |
| 374 | + } | |
| 375 | + iPredFrameNum &= iMaxPicNum - 1; | |
| 376 | + | |
| 377 | + for (i = iMaxRefIdx - 1; i >= 0; i--) { | |
| 378 | + if (ppRefList[i] != NULL && ppRefList[i]->iFrameNum == iPredFrameNum && !ppRefList[i]->bIsLongRef) { | |
| 379 | + if ((pNalHeaderExt->uiQualityId == ppRefList[i]->uiQualityId) | |
| 380 | + && (pSliceHeader->iSpsId != ppRefList[i]->iSpsId)) { //check; | |
| 381 | + WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "WelsReorderRefList()::::BASE LAYER::::iSpsId:%d, ref_sps_id:%d", | |
| 382 | + pSliceHeader->iSpsId, ppRefList[i]->iSpsId); | |
| 383 | + pCtx->iErrorCode = dsNoParamSets; //cross-IDR reference frame selection, SHOULD request IDR.-- | |
| 384 | + return ERR_INFO_REFERENCE_PIC_LOST; | |
| 385 | + } else { | |
| 386 | + break; | |
| 387 | + } | |
| 388 | + } | |
| 389 | + } | |
| 390 | + | |
| 391 | + } else if (uiReorderingOfPicNumsIdc == 2) { | |
| 392 | + for (i = iMaxRefIdx - 1; i >= 0; i--) { | |
| 393 | + if (ppRefList[i] != NULL && ppRefList[i]->bIsLongRef | |
| 394 | + && ppRefList[i]->iLongTermFrameIdx == | |
| 395 | + pRefPicListReorderSyn->sReorderingSyn[listIdx][iReorderingIndex].uiLongTermPicNum) { | |
| 396 | + if ((pNalHeaderExt->uiQualityId == ppRefList[i]->uiQualityId) | |
| 397 | + && (pSliceHeader->iSpsId != ppRefList[i]->iSpsId)) { //check; | |
| 398 | + WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "WelsReorderRefList()::::BASE LAYER::::iSpsId:%d, ref_sps_id:%d", | |
| 399 | + pSliceHeader->iSpsId, ppRefList[i]->iSpsId); | |
| 400 | + pCtx->iErrorCode = dsNoParamSets; //cross-IDR reference frame selection, SHOULD request IDR.-- | |
| 401 | + return ERR_INFO_REFERENCE_PIC_LOST; | |
| 402 | + } else { | |
| 403 | + break; | |
| 404 | + } | |
| 405 | + } | |
| 406 | + } | |
| 407 | + } | |
| 408 | + if (i < 0) { | |
| 409 | + return ERR_INFO_REFERENCE_PIC_LOST; | |
| 410 | + } | |
| 411 | + pPic = ppRefList[i]; | |
| 412 | + if (i > iReorderingIndex) { | |
| 413 | + memmove (&ppRefList[1 + iReorderingIndex], &ppRefList[iReorderingIndex], | |
| 414 | + (i - iReorderingIndex) * sizeof (PPicture)); //confirmed_safe_unsafe_usage | |
| 415 | + } else if (i < iReorderingIndex) { | |
| 416 | + memmove (&ppRefList[1 + iReorderingIndex], &ppRefList[iReorderingIndex], | |
| 417 | + (iMaxRefIdx - iReorderingIndex) * sizeof (PPicture)); | |
| 418 | + } | |
| 419 | + ppRefList[iReorderingIndex] = pPic; | |
| 420 | + iReorderingIndex++; | |
| 421 | + } | |
| 422 | + } | |
| 423 | + } | |
| 424 | + return ERR_NONE; | |
| 425 | +} | |
| 426 | + | |
| 427 | +//WelsReorderRefList2 is the test code | |
| 428 | +int32_t WelsReorderRefList2 (PWelsDecoderContext pCtx) { | |
| 429 | + | |
| 430 | + if (pCtx->eSliceType == I_SLICE || pCtx->eSliceType == SI_SLICE) { | |
| 431 | + return ERR_NONE; | |
| 432 | + } | |
| 433 | + | |
| 434 | + PRefPicListReorderSyn pRefPicListReorderSyn = pCtx->pCurDqLayer->pRefPicListReordering; | |
| 435 | + PSliceHeader pSliceHeader = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader; | |
| 436 | + | |
| 437 | + PPicture* ppShoreRefList = pCtx->sRefPic.pShortRefList[LIST_0]; | |
| 438 | + int32_t iShortRefCount = pCtx->sRefPic.uiShortRefCount[LIST_0]; | |
| 439 | + PPicture* ppLongRefList = pCtx->sRefPic.pLongRefList[LIST_0]; | |
| 440 | + int32_t iLongRefCount = pCtx->sRefPic.uiLongRefCount[LIST_0]; | |
| 441 | + int32_t i = 0; | |
| 442 | + int32_t j = 0; | |
| 443 | + int32_t k = 0; | |
| 444 | + int32_t iMaxRefIdx = pCtx->pSps->iNumRefFrames; | |
| 445 | + const int32_t iCurFrameNum = pSliceHeader->iFrameNum; | |
| 446 | + const int32_t iMaxPicNum = 1 << pSliceHeader->pSps->uiLog2MaxFrameNum; | |
| 447 | + int32_t iListCount = 1; | |
| 448 | + if (pCtx->eSliceType == B_SLICE) iListCount = 2; | |
| 449 | + for (int32_t listIdx = 0; listIdx < iListCount; ++listIdx) { | |
| 450 | + PPicture* ppRefList = pCtx->sRefPic.pRefList[listIdx]; | |
| 451 | + int32_t iCount = 0; | |
| 452 | + int32_t iRefCount = pSliceHeader->uiRefCount[listIdx]; | |
| 453 | + int32_t iAbsDiffPicNum = -1; | |
| 454 | + | |
| 455 | + if (pRefPicListReorderSyn->bRefPicListReorderingFlag[listIdx]) { | |
| 456 | + int32_t iPredFrameNum = iCurFrameNum; | |
| 457 | + for (i = 0; pRefPicListReorderSyn->sReorderingSyn[listIdx][i].uiReorderingOfPicNumsIdc != 3; i++) { | |
| 458 | + if (iCount >= iMaxRefIdx) | |
| 459 | + break; | |
| 460 | + | |
| 461 | + for (j = iRefCount; j > iCount; j--) | |
| 462 | + ppRefList[j] = ppRefList[j - 1]; | |
| 463 | + | |
| 464 | + uint16_t uiReorderingOfPicNumsIdc = | |
| 465 | + pRefPicListReorderSyn->sReorderingSyn[listIdx][i].uiReorderingOfPicNumsIdc; | |
| 466 | + | |
| 467 | + if (uiReorderingOfPicNumsIdc < 2) { // reorder short references | |
| 468 | + iAbsDiffPicNum = (int32_t) (pRefPicListReorderSyn->sReorderingSyn[listIdx][i].uiAbsDiffPicNumMinus1 + 1); | |
| 469 | + if (uiReorderingOfPicNumsIdc == 0) { | |
| 470 | + if (iPredFrameNum - iAbsDiffPicNum < 0) | |
| 471 | + iPredFrameNum -= (iAbsDiffPicNum - iMaxPicNum); | |
| 472 | + else | |
| 473 | + iPredFrameNum -= iAbsDiffPicNum; | |
| 474 | + } else { | |
| 475 | + if (iPredFrameNum + iAbsDiffPicNum >= iMaxPicNum) | |
| 476 | + iPredFrameNum += (iAbsDiffPicNum - iMaxPicNum); | |
| 477 | + else | |
| 478 | + iPredFrameNum += iAbsDiffPicNum; | |
| 479 | + } | |
| 480 | + | |
| 481 | + if (iPredFrameNum > iCurFrameNum) { | |
| 482 | + iPredFrameNum -= iMaxPicNum; | |
| 483 | + } | |
| 484 | + | |
| 485 | + for (j = 0; j < iShortRefCount; j++) { | |
| 486 | + if (ppShoreRefList[j]) { | |
| 487 | + if (ppShoreRefList[j]->iFrameWrapNum == iPredFrameNum) { | |
| 488 | + ppRefList[iCount++] = ppShoreRefList[j]; | |
| 489 | + break; | |
| 490 | + } | |
| 491 | + } | |
| 492 | + } | |
| 493 | + k = iCount; | |
| 494 | + for (j = k; j <= iRefCount; j++) { | |
| 495 | + if (ppRefList[j] != NULL) { | |
| 496 | + if (ppRefList[j]->bIsLongRef || ppRefList[j]->iFrameWrapNum != iPredFrameNum) | |
| 497 | + ppRefList[k++] = ppRefList[j]; | |
| 498 | + } | |
| 499 | + } | |
| 500 | + } else { // reorder long term references uiReorderingOfPicNumsIdc == 2 | |
| 501 | + iPredFrameNum = pRefPicListReorderSyn->sReorderingSyn[listIdx][i].uiLongTermPicNum; | |
| 502 | + for (j = 0; j < iLongRefCount; j++) { | |
| 503 | + if (ppLongRefList[j] != NULL) { | |
| 504 | + if (ppLongRefList[j]->uiLongTermPicNum == (uint32_t)iPredFrameNum) { | |
| 505 | + ppRefList[iCount++] = ppLongRefList[j]; | |
| 506 | + break; | |
| 507 | + } | |
| 508 | + } | |
| 509 | + } | |
| 510 | + k = iCount; | |
| 511 | + for (j = k; j <= iRefCount; j++) { | |
| 512 | + if (ppRefList[j] != NULL) { | |
| 513 | + if (!ppRefList[j]->bIsLongRef || ppLongRefList[j]->uiLongTermPicNum != (uint32_t)iPredFrameNum) | |
| 514 | + ppRefList[k++] = ppRefList[j]; | |
| 515 | + } | |
| 516 | + } | |
| 517 | + } | |
| 518 | + } | |
| 519 | + } | |
| 520 | + | |
| 521 | + for (i = WELS_MAX (1, WELS_MAX (iCount, pCtx->sRefPic.uiRefCount[listIdx])); i < iRefCount; i++) | |
| 522 | + ppRefList[i] = ppRefList[i - 1]; | |
| 523 | + pCtx->sRefPic.uiRefCount[listIdx] = (uint8_t)WELS_MIN (WELS_MAX (iCount, pCtx->sRefPic.uiRefCount[listIdx]), iRefCount); | |
| 524 | + } | |
| 525 | + return ERR_NONE; | |
| 526 | +} | |
| 527 | + | |
| 528 | +int32_t WelsMarkAsRef (PWelsDecoderContext pCtx) { | |
| 529 | + PRefPic pRefPic = &pCtx->sRefPic; | |
| 530 | + PRefPicMarking pRefPicMarking = pCtx->pCurDqLayer->pRefPicMarking; | |
| 531 | + PAccessUnit pCurAU = pCtx->pAccessUnitList; | |
| 532 | + bool bIsIDRAU = false; | |
| 533 | + uint32_t j; | |
| 534 | + | |
| 535 | + int32_t iRet = ERR_NONE; | |
| 536 | + | |
| 537 | + pCtx->pDec->uiQualityId = pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt.uiQualityId; | |
| 538 | + pCtx->pDec->uiTemporalId = pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt.uiTemporalId; | |
| 539 | + pCtx->pDec->iSpsId = pCtx->pSps->iSpsId; | |
| 540 | + pCtx->pDec->iPpsId = pCtx->pPps->iPpsId; | |
| 541 | + | |
| 542 | + for (j = pCurAU->uiStartPos; j <= pCurAU->uiEndPos; j++) { | |
| 543 | + if (pCurAU->pNalUnitsList[j]->sNalHeaderExt.sNalUnitHeader.eNalUnitType == NAL_UNIT_CODED_SLICE_IDR | |
| 544 | + || pCurAU->pNalUnitsList[j]->sNalHeaderExt.bIdrFlag) { | |
| 545 | + bIsIDRAU = true; | |
| 546 | + break; | |
| 547 | + } | |
| 548 | + } | |
| 549 | + if (bIsIDRAU) { | |
| 550 | + if (pRefPicMarking->bLongTermRefFlag) { | |
| 551 | + pCtx->sRefPic.iMaxLongTermFrameIdx = 0; | |
| 552 | + AddLongTermToList (pRefPic, pCtx->pDec, 0, 0); | |
| 553 | + } else { | |
| 554 | + pCtx->sRefPic.iMaxLongTermFrameIdx = -1; | |
| 555 | + } | |
| 556 | + } else { | |
| 557 | + if (pRefPicMarking->bAdaptiveRefPicMarkingModeFlag) { | |
| 558 | + iRet = MMCO (pCtx, pRefPicMarking); | |
| 559 | + if (iRet != ERR_NONE) { | |
| 560 | + if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 561 | + iRet = RemainOneBufferInDpbForEC (pCtx); | |
| 562 | + WELS_VERIFY_RETURN_IF (iRet, iRet); | |
| 563 | + } else { | |
| 564 | + return iRet; | |
| 565 | + } | |
| 566 | + } | |
| 567 | + | |
| 568 | + if (pCtx->bLastHasMmco5) { | |
| 569 | + pCtx->pDec->iFrameNum = 0; | |
| 570 | + pCtx->pDec->iFramePoc = 0; | |
| 571 | + } | |
| 572 | + | |
| 573 | + } else { | |
| 574 | + iRet = SlidingWindow (pCtx); | |
| 575 | + if (iRet != ERR_NONE) { | |
| 576 | + if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 577 | + iRet = RemainOneBufferInDpbForEC (pCtx); | |
| 578 | + WELS_VERIFY_RETURN_IF (iRet, iRet); | |
| 579 | + } else { | |
| 580 | + return iRet; | |
| 581 | + } | |
| 582 | + } | |
| 583 | + } | |
| 584 | + } | |
| 585 | + | |
| 586 | + if (!pCtx->pDec->bIsLongRef) { | |
| 587 | + if (pRefPic->uiLongRefCount[LIST_0] + pRefPic->uiShortRefCount[LIST_0] >= WELS_MAX (1, pCtx->pSps->iNumRefFrames)) { | |
| 588 | + if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 589 | + iRet = RemainOneBufferInDpbForEC (pCtx); | |
| 590 | + WELS_VERIFY_RETURN_IF (iRet, iRet); | |
| 591 | + } else { | |
| 592 | + return ERR_INFO_INVALID_MMCO_REF_NUM_OVERFLOW; | |
| 593 | + } | |
| 594 | + } | |
| 595 | + iRet = AddShortTermToList (pRefPic, pCtx->pDec); | |
| 596 | + } | |
| 597 | + | |
| 598 | + return iRet; | |
| 599 | +} | |
| 600 | + | |
| 601 | +static int32_t MMCO (PWelsDecoderContext pCtx, PRefPicMarking pRefPicMarking) { | |
| 602 | + PSps pSps = pCtx->pCurDqLayer->sLayerInfo.pSps; | |
| 603 | + int32_t i = 0; | |
| 604 | + int32_t iRet = ERR_NONE; | |
| 605 | + for (i = 0; i < MAX_MMCO_COUNT && pRefPicMarking->sMmcoRef[i].uiMmcoType != MMCO_END; i++) { | |
| 606 | + uint32_t uiMmcoType = pRefPicMarking->sMmcoRef[i].uiMmcoType; | |
| 607 | + int32_t iShortFrameNum = (pCtx->iFrameNum - pRefPicMarking->sMmcoRef[i].iDiffOfPicNum) & (( | |
| 608 | + 1 << pSps->uiLog2MaxFrameNum) - 1); | |
| 609 | + uint32_t uiLongTermPicNum = pRefPicMarking->sMmcoRef[i].uiLongTermPicNum; | |
| 610 | + int32_t iLongTermFrameIdx = pRefPicMarking->sMmcoRef[i].iLongTermFrameIdx; | |
| 611 | + int32_t iMaxLongTermFrameIdx = pRefPicMarking->sMmcoRef[i].iMaxLongTermFrameIdx; | |
| 612 | + if (uiMmcoType > MMCO_LONG) { | |
| 613 | + return ERR_INFO_INVALID_MMCO_OPCODE_BASE; | |
| 614 | + } | |
| 615 | + iRet = MMCOProcess (pCtx, uiMmcoType, iShortFrameNum, uiLongTermPicNum, iLongTermFrameIdx, iMaxLongTermFrameIdx); | |
| 616 | + if (iRet != ERR_NONE) { | |
| 617 | + return iRet; | |
| 618 | + } | |
| 619 | + } | |
| 620 | + 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; | |
| 622 | + } | |
| 623 | + | |
| 624 | + return ERR_NONE; | |
| 625 | +} | |
| 626 | +static int32_t MMCOProcess (PWelsDecoderContext pCtx, uint32_t uiMmcoType, | |
| 627 | + int32_t iShortFrameNum, uint32_t uiLongTermPicNum, int32_t iLongTermFrameIdx, int32_t iMaxLongTermFrameIdx) { | |
| 628 | + PRefPic pRefPic = &pCtx->sRefPic; | |
| 629 | + PPicture pPic = NULL; | |
| 630 | + int32_t i = 0; | |
| 631 | + int32_t iRet = ERR_NONE; | |
| 632 | + | |
| 633 | + switch (uiMmcoType) { | |
| 634 | + case MMCO_SHORT2UNUSED: | |
| 635 | + pPic = WelsDelShortFromListSetUnref (pRefPic, iShortFrameNum); | |
| 636 | + if (pPic == NULL) { | |
| 637 | + WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "MMCO_SHORT2UNUSED: delete an empty entry from short term list"); | |
| 638 | + } | |
| 639 | + break; | |
| 640 | + case MMCO_LONG2UNUSED: | |
| 641 | + pPic = WelsDelLongFromListSetUnref (pRefPic, uiLongTermPicNum); | |
| 642 | + if (pPic == NULL) { | |
| 643 | + WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "MMCO_LONG2UNUSED: delete an empty entry from long term list"); | |
| 644 | + } | |
| 645 | + break; | |
| 646 | + case MMCO_SHORT2LONG: | |
| 647 | + if (iLongTermFrameIdx > pRefPic->iMaxLongTermFrameIdx) { | |
| 648 | + return ERR_INFO_INVALID_MMCO_LONG_TERM_IDX_EXCEED_MAX; | |
| 649 | + } | |
| 650 | + pPic = WelsDelShortFromList (pRefPic, iShortFrameNum); | |
| 651 | + if (pPic == NULL) { | |
| 652 | + WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "MMCO_LONG2LONG: delete an empty entry from short term list"); | |
| 653 | + break; | |
| 654 | + } | |
| 655 | + WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx); | |
| 656 | +#ifdef LONG_TERM_REF | |
| 657 | + pCtx->bCurAuContainLtrMarkSeFlag = true; | |
| 658 | + pCtx->iFrameNumOfAuMarkedLtr = iShortFrameNum; | |
| 659 | + WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, "ex_mark_avc():::MMCO_SHORT2LONG:::LTR marking....iFrameNum: %d", | |
| 660 | + pCtx->iFrameNumOfAuMarkedLtr); | |
| 661 | +#endif | |
| 662 | + | |
| 663 | + MarkAsLongTerm (pRefPic, iShortFrameNum, iLongTermFrameIdx, uiLongTermPicNum); | |
| 664 | + break; | |
| 665 | + case MMCO_SET_MAX_LONG: | |
| 666 | + pRefPic->iMaxLongTermFrameIdx = iMaxLongTermFrameIdx; | |
| 667 | + for (i = 0 ; i < pRefPic->uiLongRefCount[LIST_0]; i++) { | |
| 668 | + if (pRefPic->pLongRefList[LIST_0][i]->iLongTermFrameIdx > pRefPic->iMaxLongTermFrameIdx) { | |
| 669 | + WelsDelLongFromListSetUnref (pRefPic, pRefPic->pLongRefList[LIST_0][i]->iLongTermFrameIdx); | |
| 670 | + } | |
| 671 | + } | |
| 672 | + break; | |
| 673 | + case MMCO_RESET: | |
| 674 | + WelsResetRefPic (pCtx); | |
| 675 | + pCtx->bLastHasMmco5 = true; | |
| 676 | + break; | |
| 677 | + case MMCO_LONG: | |
| 678 | + if (iLongTermFrameIdx > pRefPic->iMaxLongTermFrameIdx) { | |
| 679 | + return ERR_INFO_INVALID_MMCO_LONG_TERM_IDX_EXCEED_MAX; | |
| 680 | + } | |
| 681 | + WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx); | |
| 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; | |
| 684 | + } | |
| 685 | +#ifdef LONG_TERM_REF | |
| 686 | + pCtx->bCurAuContainLtrMarkSeFlag = true; | |
| 687 | + pCtx->iFrameNumOfAuMarkedLtr = pCtx->iFrameNum; | |
| 688 | + WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, "ex_mark_avc():::MMCO_LONG:::LTR marking....iFrameNum: %d", | |
| 689 | + pCtx->iFrameNum); | |
| 690 | +#endif | |
| 691 | + iRet = AddLongTermToList (pRefPic, pCtx->pDec, iLongTermFrameIdx, uiLongTermPicNum); | |
| 692 | + break; | |
| 693 | + default : | |
| 694 | + break; | |
| 695 | + } | |
| 696 | + | |
| 697 | + return iRet; | |
| 698 | +} | |
| 699 | + | |
| 700 | +static int32_t SlidingWindow (PWelsDecoderContext pCtx) { | |
| 701 | + PRefPic pRefPic = &pCtx->sRefPic; | |
| 702 | + PPicture pPic = NULL; | |
| 703 | + int32_t i = 0; | |
| 704 | + | |
| 705 | + if (pCtx->sRefPic.uiShortRefCount[LIST_0] + pCtx->sRefPic.uiLongRefCount[LIST_0] >= pCtx->pSps->iNumRefFrames) { | |
| 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"); | |
| 708 | + return ERR_INFO_INVALID_MMCO_REF_NUM_NOT_ENOUGH; | |
| 709 | + } | |
| 710 | + for (i = pRefPic->uiShortRefCount[LIST_0] - 1; i >= 0; i--) { | |
| 711 | + pPic = WelsDelShortFromList (pRefPic, pRefPic->pShortRefList[LIST_0][i]->iFrameNum); | |
| 712 | + if (pPic) { | |
| 713 | + SetUnRef (pPic); | |
| 714 | + break; | |
| 715 | + } else { | |
| 716 | + return ERR_INFO_INVALID_MMCO_REF_NUM_OVERFLOW; | |
| 717 | + } | |
| 718 | + } | |
| 719 | + } | |
| 720 | + return ERR_NONE; | |
| 721 | +} | |
| 722 | + | |
| 723 | +static PPicture WelsDelShortFromList (PRefPic pRefPic, int32_t iFrameNum) { | |
| 724 | + int32_t i = 0; | |
| 725 | + int32_t iMoveSize = 0; | |
| 726 | + PPicture pPic = NULL; | |
| 727 | + | |
| 728 | + for (i = 0; i < pRefPic->uiShortRefCount[LIST_0]; i++) { | |
| 729 | + if (pRefPic->pShortRefList[LIST_0][i]->iFrameNum == iFrameNum) { | |
| 730 | + iMoveSize = pRefPic->uiShortRefCount[LIST_0] - i - 1; | |
| 731 | + pRefPic->pShortRefList[LIST_0][i]->bUsedAsRef = false; | |
| 732 | + pPic = pRefPic->pShortRefList[LIST_0][i]; | |
| 733 | + pRefPic->pShortRefList[LIST_0][i] = NULL; | |
| 734 | + if (iMoveSize > 0) { | |
| 735 | + memmove (&pRefPic->pShortRefList[LIST_0][i], &pRefPic->pShortRefList[LIST_0][i + 1], | |
| 736 | + iMoveSize * sizeof (PPicture)); //confirmed_safe_unsafe_usage | |
| 737 | + } | |
| 738 | + pRefPic->uiShortRefCount[LIST_0]--; | |
| 739 | + pRefPic->pShortRefList[LIST_0][pRefPic->uiShortRefCount[LIST_0]] = NULL; | |
| 740 | + break; | |
| 741 | + } | |
| 742 | + } | |
| 743 | + | |
| 744 | + return pPic; | |
| 745 | +} | |
| 746 | + | |
| 747 | +static PPicture WelsDelShortFromListSetUnref (PRefPic pRefPic, int32_t iFrameNum) { | |
| 748 | + PPicture pPic = WelsDelShortFromList (pRefPic, iFrameNum); | |
| 749 | + if (pPic) { | |
| 750 | + SetUnRef (pPic); | |
| 751 | + } | |
| 752 | + return pPic; | |
| 753 | +} | |
| 754 | + | |
| 755 | +static PPicture WelsDelLongFromList (PRefPic pRefPic, uint32_t uiLongTermFrameIdx) { | |
| 756 | + PPicture pPic = NULL; | |
| 757 | + int32_t i = 0; | |
| 758 | + for (i = 0; i < pRefPic->uiLongRefCount[LIST_0]; i++) { | |
| 759 | + pPic = pRefPic->pLongRefList[LIST_0][i]; | |
| 760 | + if (pPic->iLongTermFrameIdx == (int32_t)uiLongTermFrameIdx) { | |
| 761 | + int32_t iMoveSize = pRefPic->uiLongRefCount[LIST_0] - i - 1; | |
| 762 | + pPic->bUsedAsRef = false; | |
| 763 | + pPic->bIsLongRef = false; | |
| 764 | + if (iMoveSize > 0) { | |
| 765 | + memmove (&pRefPic->pLongRefList[LIST_0][i], &pRefPic->pLongRefList[LIST_0][i + 1], | |
| 766 | + iMoveSize * sizeof (PPicture)); //confirmed_safe_unsafe_usage | |
| 767 | + } | |
| 768 | + pRefPic->uiLongRefCount[LIST_0]--; | |
| 769 | + pRefPic->pLongRefList[LIST_0][pRefPic->uiLongRefCount[LIST_0]] = NULL; | |
| 770 | + return pPic; | |
| 771 | + } | |
| 772 | + } | |
| 773 | + return NULL; | |
| 774 | +} | |
| 775 | + | |
| 776 | +static PPicture WelsDelLongFromListSetUnref (PRefPic pRefPic, uint32_t uiLongTermFrameIdx) { | |
| 777 | + PPicture pPic = WelsDelLongFromList (pRefPic, uiLongTermFrameIdx); | |
| 778 | + if (pPic) { | |
| 779 | + SetUnRef (pPic); | |
| 780 | + } | |
| 781 | + return pPic; | |
| 782 | +} | |
| 783 | + | |
| 784 | +static int32_t AddShortTermToList (PRefPic pRefPic, PPicture pPic) { | |
| 785 | + pPic->bUsedAsRef = true; | |
| 786 | + pPic->bIsLongRef = false; | |
| 787 | + pPic->iLongTermFrameIdx = -1; | |
| 788 | + if (pRefPic->uiShortRefCount[LIST_0] > 0) { | |
| 789 | + // Check the duplicate frame_num in short ref list | |
| 790 | + for (int32_t iPos = 0; iPos < pRefPic->uiShortRefCount[LIST_0]; iPos++) { | |
| 791 | + if (pPic->iFrameNum == pRefPic->pShortRefList[LIST_0][iPos]->iFrameNum) { | |
| 792 | + // Replace the previous ref pic with the new one with the same frame_num | |
| 793 | + pRefPic->pShortRefList[LIST_0][iPos] = pPic; | |
| 794 | + return ERR_INFO_DUPLICATE_FRAME_NUM; | |
| 795 | + } | |
| 796 | + } | |
| 797 | + | |
| 798 | + memmove (&pRefPic->pShortRefList[LIST_0][1], &pRefPic->pShortRefList[LIST_0][0], | |
| 799 | + pRefPic->uiShortRefCount[LIST_0]*sizeof (PPicture));//confirmed_safe_unsafe_usage | |
| 800 | + } | |
| 801 | + pRefPic->pShortRefList[LIST_0][0] = pPic; | |
| 802 | + pRefPic->uiShortRefCount[LIST_0]++; | |
| 803 | + return ERR_NONE; | |
| 804 | +} | |
| 805 | + | |
| 806 | +static int32_t AddLongTermToList (PRefPic pRefPic, PPicture pPic, int32_t iLongTermFrameIdx, | |
| 807 | + uint32_t uiLongTermPicNum) { | |
| 808 | + int32_t i = 0; | |
| 809 | + | |
| 810 | + pPic->bUsedAsRef = true; | |
| 811 | + pPic->bIsLongRef = true; | |
| 812 | + pPic->iLongTermFrameIdx = iLongTermFrameIdx; | |
| 813 | + pPic->uiLongTermPicNum = uiLongTermPicNum; | |
| 814 | + if (pRefPic->uiLongRefCount[LIST_0] == 0) { | |
| 815 | + pRefPic->pLongRefList[LIST_0][pRefPic->uiLongRefCount[LIST_0]] = pPic; | |
| 816 | + } else { | |
| 817 | + for (i = 0; i < pRefPic->uiLongRefCount[LIST_0]; i++) { | |
| 818 | + if (pRefPic->pLongRefList[LIST_0][i]->iLongTermFrameIdx > pPic->iLongTermFrameIdx) { | |
| 819 | + break; | |
| 820 | + } | |
| 821 | + } | |
| 822 | + memmove (&pRefPic->pLongRefList[LIST_0][i + 1], &pRefPic->pLongRefList[LIST_0][i], | |
| 823 | + (pRefPic->uiLongRefCount[LIST_0] - i)*sizeof (PPicture)); //confirmed_safe_unsafe_usage | |
| 824 | + pRefPic->pLongRefList[LIST_0][i] = pPic; | |
| 825 | + } | |
| 826 | + | |
| 827 | + pRefPic->uiLongRefCount[LIST_0]++; | |
| 828 | + return ERR_NONE; | |
| 829 | +} | |
| 830 | + | |
| 831 | +static int32_t MarkAsLongTerm (PRefPic pRefPic, int32_t iFrameNum, int32_t iLongTermFrameIdx, | |
| 832 | + uint32_t uiLongTermPicNum) { | |
| 833 | + PPicture pPic = NULL; | |
| 834 | + int32_t i = 0; | |
| 835 | + int32_t iRet = ERR_NONE; | |
| 836 | + WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx); | |
| 837 | + | |
| 838 | + for (i = 0; i < pRefPic->uiRefCount[LIST_0]; i++) { | |
| 839 | + pPic = pRefPic->pRefList[LIST_0][i]; | |
| 840 | + if (pPic->iFrameNum == iFrameNum && !pPic->bIsLongRef) { | |
| 841 | + iRet = AddLongTermToList (pRefPic, pPic, iLongTermFrameIdx, uiLongTermPicNum); | |
| 842 | + break; | |
| 843 | + } | |
| 844 | + } | |
| 845 | + | |
| 846 | + return iRet; | |
| 847 | +} | |
| 848 | + | |
| 849 | +#ifdef LONG_TERM_REF | |
| 850 | +int32_t GetLTRFrameIndex (PRefPic pRefPic, int32_t iAncLTRFrameNum) { | |
| 851 | + int32_t iLTRFrameIndex = -1; | |
| 852 | + PPicture pPic; | |
| 853 | + for (int i = 0; i < pRefPic->uiLongRefCount[0]; ++i) { | |
| 854 | + pPic = pRefPic->pLongRefList[LIST_0][i]; | |
| 855 | + if (pPic->iFrameNum == iAncLTRFrameNum) { | |
| 856 | + return (pPic->iLongTermFrameIdx); | |
| 857 | + } | |
| 858 | + } | |
| 859 | + return iLTRFrameIndex; | |
| 860 | +} | |
| 861 | +#endif | |
| 862 | + | |
| 863 | +static int32_t RemainOneBufferInDpbForEC (PWelsDecoderContext pCtx) { | |
| 864 | + int32_t iRet = ERR_NONE; | |
| 865 | + PRefPic pRefPic = &pCtx->sRefPic; | |
| 866 | + if (pRefPic->uiShortRefCount[0] + pRefPic->uiLongRefCount[0] < pCtx->pSps->iNumRefFrames) | |
| 867 | + return iRet; | |
| 868 | + | |
| 869 | + if (pRefPic->uiShortRefCount[0] > 0) { | |
| 870 | + iRet = SlidingWindow (pCtx); | |
| 871 | + } else { //all LTR, remove the smallest long_term_frame_idx | |
| 872 | + int32_t iLongTermFrameIdx = 0; | |
| 873 | + int32_t iMaxLongTermFrameIdx = pRefPic->iMaxLongTermFrameIdx; | |
| 874 | +#ifdef LONG_TERM_REF | |
| 875 | + int32_t iCurrLTRFrameIdx = GetLTRFrameIndex (pRefPic, pCtx->iFrameNumOfAuMarkedLtr); | |
| 876 | +#endif | |
| 877 | + while ((pRefPic->uiLongRefCount[0] >= pCtx->pSps->iNumRefFrames) && (iLongTermFrameIdx <= iMaxLongTermFrameIdx)) { | |
| 878 | +#ifdef LONG_TERM_REF | |
| 879 | + if (iLongTermFrameIdx == iCurrLTRFrameIdx) { | |
| 880 | + iLongTermFrameIdx++; | |
| 881 | + continue; | |
| 882 | + } | |
| 883 | +#endif | |
| 884 | + WelsDelLongFromListSetUnref (pRefPic, iLongTermFrameIdx); | |
| 885 | + iLongTermFrameIdx++; | |
| 886 | + } | |
| 887 | + } | |
| 888 | + if (pRefPic->uiShortRefCount[0] + pRefPic->uiLongRefCount[0] >= | |
| 889 | + 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!"); | |
| 891 | + iRet = ERR_INFO_REF_COUNT_OVERFLOW; | |
| 892 | + } | |
| 893 | + | |
| 894 | + return iRet; | |
| 895 | +} | |
| 896 | + | |
| 897 | +} // namespace WelsDec | |
| @@ -1,1658 +1,1658 @@ | ||
| 1 | −/*! | |
| 2 | − * \copy | |
| 3 | − * Copyright (c) 2013, Cisco Systems | |
| 4 | − * All rights reserved. | |
| 5 | − * | |
| 6 | − * Redistribution and use in source and binary forms, with or without | |
| 7 | − * modification, are permitted provided that the following conditions | |
| 8 | − * are met: | |
| 9 | − * | |
| 10 | − * * Redistributions of source code must retain the above copyright | |
| 11 | − * notice, this list of conditions and the following disclaimer. | |
| 12 | − * | |
| 13 | − * * Redistributions in binary form must reproduce the above copyright | |
| 14 | − * notice, this list of conditions and the following disclaimer in | |
| 15 | − * the documentation and/or other materials provided with the | |
| 16 | − * distribution. | |
| 17 | − * | |
| 18 | − * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 | − * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 | − * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 21 | − * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 22 | − * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 23 | − * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 24 | − * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 | − * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 26 | − * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 | − * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
| 28 | − * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | − * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | − * | |
| 31 | − * parse_mb_syn_cabac.cpp: cabac parse for syntax elements | |
| 32 | − */ | |
| 33 | −#include "parse_mb_syn_cabac.h" | |
| 34 | −#include "decode_slice.h" | |
| 35 | −#include "mv_pred.h" | |
| 36 | −#include "error_code.h" | |
| 37 | −#include <stdio.h> | |
| 38 | −namespace WelsDec { | |
| 39 | −#define IDX_UNUSED -1 | |
| 40 | − | |
| 41 | −static const int16_t g_kMaxPos [] = {IDX_UNUSED, 15, 14, 15, 3, 14, 63, 3, 3, 14, 14}; | |
| 42 | −static const int16_t g_kMaxC2 [] = {IDX_UNUSED, 4, 4, 4, 3, 4, 4, 3, 3, 4, 4}; | |
| 43 | −static const int16_t g_kBlockCat2CtxOffsetCBF[] = {IDX_UNUSED, 0, 4, 8, 12, 16, 0, 12, 12, 16, 16}; | |
| 44 | −static const int16_t g_kBlockCat2CtxOffsetMap [] = {IDX_UNUSED, 0, 15, 29, 44, 47, 0, 44, 44, 47, 47}; | |
| 45 | −static const int16_t g_kBlockCat2CtxOffsetLast[] = {IDX_UNUSED, 0, 15, 29, 44, 47, 0, 44, 44, 47, 47}; | |
| 46 | −static const int16_t g_kBlockCat2CtxOffsetOne [] = {IDX_UNUSED, 0, 10, 20, 30, 39, 0, 30, 30, 39, 39}; | |
| 47 | −static const int16_t g_kBlockCat2CtxOffsetAbs [] = {IDX_UNUSED, 0, 10, 20, 30, 39, 0, 30, 30, 39, 39}; | |
| 48 | − | |
| 49 | −const uint8_t g_kTopBlkInsideMb[24] = { //for index with z-order 0~23 | |
| 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 3 | |
| 52 | − 0, 0, 1, 1, //--------------- --------- 4 5 6 7 | |
| 53 | − 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 15 | |
| 55 | − 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 23 | |
| 57 | − // 18 19 | 22 23 | |
| 58 | −}; | |
| 59 | − | |
| 60 | −const uint8_t g_kLeftBlkInsideMb[24] = { //for index with z-order 0~23 | |
| 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 3 | |
| 63 | − 1, 1, 1, 1, //--------------- --------- 4 5 6 7 | |
| 64 | − 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 15 | |
| 66 | − 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 23 | |
| 68 | − // 18 19 | 22 23 | |
| 69 | −}; | |
| 70 | − | |
| 71 | −static uint32_t DecodeCabacIntraMbType (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, int ctx_base) { | |
| 72 | − uint32_t uiCode; | |
| 73 | − uint32_t uiMbType = 0; | |
| 74 | − | |
| 75 | − PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine; | |
| 76 | − PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + ctx_base; | |
| 77 | − | |
| 78 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx, uiCode)); | |
| 79 | − if (!uiCode) { | |
| 80 | − return 0; /* I4x4 */ | |
| 81 | − } | |
| 82 | − | |
| 83 | − DecodeTerminateCabac (pCabacDecEngine, uiCode); | |
| 84 | − if (uiCode) { | |
| 85 | − return 25; /* PCM */ | |
| 86 | − } | |
| 87 | − uiMbType = 1; /* I16x16 */ | |
| 88 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 1, uiCode)); /* cbp_luma != 0 */ | |
| 89 | − uiMbType += 12 * uiCode; | |
| 90 | − | |
| 91 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 2, uiCode)); | |
| 92 | − if (uiCode) { | |
| 93 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 2, uiCode)); | |
| 94 | − uiMbType += 4 + 4 * uiCode; | |
| 95 | − } | |
| 96 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 97 | − uiMbType += 2 * uiCode; | |
| 98 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 99 | − uiMbType += 1 * uiCode; | |
| 100 | − return uiMbType; | |
| 101 | −} | |
| 102 | − | |
| 103 | −void UpdateP16x8RefIdxCabac (PDqLayer pCurDqLayer, int8_t pRefIndex[LIST_A][30], int32_t iPartIdx, const int8_t iRef, | |
| 104 | − const int8_t iListIdx) { | |
| 105 | − uint32_t iRef32Bit = (uint32_t) iRef; | |
| 106 | − const int32_t iRef4Bytes = (iRef32Bit << 24) | (iRef32Bit << 16) | (iRef32Bit << 8) | iRef32Bit; | |
| 107 | − int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 108 | − const uint8_t iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 109 | − const uint8_t iScan4Idx4 = 4 + iScan4Idx; | |
| 110 | − const uint8_t iCacheIdx = g_kuiCache30ScanIdx[iPartIdx]; | |
| 111 | − const uint8_t iCacheIdx6 = 6 + iCacheIdx; | |
| 112 | − //mb | |
| 113 | − ST32 (&pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx ], iRef4Bytes); | |
| 114 | − ST32 (&pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx4], iRef4Bytes); | |
| 115 | − //cache | |
| 116 | − ST32 (&pRefIndex[iListIdx][iCacheIdx ], iRef4Bytes); | |
| 117 | − ST32 (&pRefIndex[iListIdx][iCacheIdx6], iRef4Bytes); | |
| 118 | −} | |
| 119 | − | |
| 120 | −void UpdateP8x16RefIdxCabac (PDqLayer pCurDqLayer, int8_t pRefIndex[LIST_A][30], int32_t iPartIdx, const int8_t iRef, | |
| 121 | − const int8_t iListIdx) { | |
| 122 | − uint16_t iRef16Bit = (uint16_t) iRef; | |
| 123 | − const int16_t iRef2Bytes = (iRef16Bit << 8) | iRef16Bit; | |
| 124 | − int32_t i; | |
| 125 | − int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 126 | − for (i = 0; i < 2; i++, iPartIdx += 8) { | |
| 127 | − const uint8_t iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 128 | − const uint8_t iCacheIdx = g_kuiCache30ScanIdx[iPartIdx]; | |
| 129 | − const uint8_t iScan4Idx4 = 4 + iScan4Idx; | |
| 130 | − const uint8_t iCacheIdx6 = 6 + iCacheIdx; | |
| 131 | − //mb | |
| 132 | − ST16 (&pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx ], iRef2Bytes); | |
| 133 | − ST16 (&pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx4], iRef2Bytes); | |
| 134 | − //cache | |
| 135 | − ST16 (&pRefIndex[iListIdx][iCacheIdx ], iRef2Bytes); | |
| 136 | − ST16 (&pRefIndex[iListIdx][iCacheIdx6], iRef2Bytes); | |
| 137 | − } | |
| 138 | −} | |
| 139 | − | |
| 140 | −void UpdateP8x8RefIdxCabac (PDqLayer pCurDqLayer, int8_t pRefIndex[LIST_A][30], int32_t iPartIdx, const int8_t iRef, | |
| 141 | − const int8_t iListIdx) { | |
| 142 | − int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 143 | − const uint8_t iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 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; | |
| 146 | −} | |
| 147 | − | |
| 148 | −void UpdateP8x8DirectCabac (PDqLayer pCurDqLayer, int32_t iPartIdx) { | |
| 149 | − int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 150 | − const uint8_t iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 151 | − pCurDqLayer->pDirect[iMbXy][iScan4Idx] = pCurDqLayer->pDirect[iMbXy][iScan4Idx + 1] = | |
| 152 | − pCurDqLayer->pDirect[iMbXy][iScan4Idx + 4] = pCurDqLayer->pDirect[iMbXy][iScan4Idx + 5] = 1; | |
| 153 | −} | |
| 154 | − | |
| 155 | −void UpdateP16x16DirectCabac (PDqLayer pCurDqLayer) { | |
| 156 | − int32_t i; | |
| 157 | − int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 158 | − const int16_t direct = (1 << 8) | 1; | |
| 159 | − for (i = 0; i < 16; i += 4) { | |
| 160 | − const uint8_t kuiScan4Idx = g_kuiScan4[i]; | |
| 161 | − const uint8_t kuiScan4IdxPlus4 = 4 + kuiScan4Idx; | |
| 162 | − ST16 (&pCurDqLayer->pDirect[iMbXy][kuiScan4Idx], direct); | |
| 163 | − ST16 (&pCurDqLayer->pDirect[iMbXy][kuiScan4IdxPlus4], direct); | |
| 164 | − } | |
| 165 | −} | |
| 166 | − | |
| 167 | −void UpdateP16x16MvdCabac (SDqLayer* pCurDqLayer, int16_t pMvd[2], const int8_t iListIdx) { | |
| 168 | − int32_t pMvd32[2]; | |
| 169 | − ST32 (&pMvd32[0], LD32 (pMvd)); | |
| 170 | − ST32 (&pMvd32[1], LD32 (pMvd)); | |
| 171 | − int32_t i; | |
| 172 | − int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 173 | − for (i = 0; i < 16; i += 2) { | |
| 174 | − ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][i], LD64 (pMvd32)); | |
| 175 | − } | |
| 176 | −} | |
| 177 | − | |
| 178 | −void UpdateP16x8MvdCabac (SDqLayer* pCurDqLayer, int16_t pMvdCache[LIST_A][30][MV_A], int32_t iPartIdx, int16_t pMvd[2], | |
| 179 | − const int8_t iListIdx) { | |
| 180 | − int32_t pMvd32[2]; | |
| 181 | − ST32 (&pMvd32[0], LD32 (pMvd)); | |
| 182 | − ST32 (&pMvd32[1], LD32 (pMvd)); | |
| 183 | − int32_t i; | |
| 184 | − int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 185 | − for (i = 0; i < 2; i++, iPartIdx += 4) { | |
| 186 | − const uint8_t iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 187 | − const uint8_t iScan4Idx4 = 4 + iScan4Idx; | |
| 188 | − const uint8_t iCacheIdx = g_kuiCache30ScanIdx[iPartIdx]; | |
| 189 | − const uint8_t iCacheIdx6 = 6 + iCacheIdx; | |
| 190 | − //mb | |
| 191 | − ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][ iScan4Idx ], LD64 (pMvd32)); | |
| 192 | − ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][ iScan4Idx4], LD64 (pMvd32)); | |
| 193 | − //cache | |
| 194 | − ST64 (pMvdCache[iListIdx][ iCacheIdx ], LD64 (pMvd32)); | |
| 195 | − ST64 (pMvdCache[iListIdx][ iCacheIdx6], LD64 (pMvd32)); | |
| 196 | − } | |
| 197 | −} | |
| 198 | − | |
| 199 | −void UpdateP8x16MvdCabac (SDqLayer* pCurDqLayer, int16_t pMvdCache[LIST_A][30][MV_A], int32_t iPartIdx, int16_t pMvd[2], | |
| 200 | − const int8_t iListIdx) { | |
| 201 | − int32_t pMvd32[2]; | |
| 202 | − ST32 (&pMvd32[0], LD32 (pMvd)); | |
| 203 | − ST32 (&pMvd32[1], LD32 (pMvd)); | |
| 204 | − int32_t i; | |
| 205 | − int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 206 | − | |
| 207 | − for (i = 0; i < 2; i++, iPartIdx += 8) { | |
| 208 | − const uint8_t iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 209 | − const uint8_t iCacheIdx = g_kuiCache30ScanIdx[iPartIdx]; | |
| 210 | − const uint8_t iScan4Idx4 = 4 + iScan4Idx; | |
| 211 | − const uint8_t iCacheIdx6 = 6 + iCacheIdx; | |
| 212 | − //mb | |
| 213 | − ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][ iScan4Idx ], LD64 (pMvd32)); | |
| 214 | − ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][ iScan4Idx4], LD64 (pMvd32)); | |
| 215 | − //cache | |
| 216 | − ST64 (pMvdCache[iListIdx][ iCacheIdx ], LD64 (pMvd32)); | |
| 217 | − ST64 (pMvdCache[iListIdx][ iCacheIdx6], LD64 (pMvd32)); | |
| 218 | − } | |
| 219 | −} | |
| 220 | − | |
| 221 | −int32_t ParseEndOfSliceCabac (PWelsDecoderContext pCtx, uint32_t& uiBinVal) { | |
| 222 | − uiBinVal = 0; | |
| 223 | − WELS_READ_VERIFY (DecodeTerminateCabac (pCtx->pCabacDecEngine, uiBinVal)); | |
| 224 | − return ERR_NONE; | |
| 225 | −} | |
| 226 | − | |
| 227 | −int32_t ParseSkipFlagCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiSkip) { | |
| 228 | − uiSkip = 0; | |
| 229 | − int32_t iCtxInc = NEW_CTX_OFFSET_SKIP; | |
| 230 | − iCtxInc += (pNeighAvail->iLeftAvail && !IS_SKIP (pNeighAvail->iLeftType)) + (pNeighAvail->iTopAvail | |
| 231 | − && !IS_SKIP (pNeighAvail->iTopType)); | |
| 232 | − if (B_SLICE == pCtx->eSliceType) | |
| 233 | − iCtxInc += 13; | |
| 234 | − PWelsCabacCtx pBinCtx = (pCtx->pCabacCtx + iCtxInc); | |
| 235 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pBinCtx, uiSkip)); | |
| 236 | − return ERR_NONE; | |
| 237 | −} | |
| 238 | − | |
| 239 | − | |
| 240 | −int32_t ParseMBTypeISliceCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiBinVal) { | |
| 241 | − uint32_t uiCode; | |
| 242 | − int32_t iIdxA = 0, iIdxB = 0; | |
| 243 | − int32_t iCtxInc; | |
| 244 | − uiBinVal = 0; | |
| 245 | − PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine; | |
| 246 | − PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_MB_TYPE_I; //I mode in I slice | |
| 247 | − iIdxA = (pNeighAvail->iLeftAvail) && (pNeighAvail->iLeftType != MB_TYPE_INTRA4x4 | |
| 248 | − && pNeighAvail->iLeftType != MB_TYPE_INTRA8x8); | |
| 249 | − iIdxB = (pNeighAvail->iTopAvail) && (pNeighAvail->iTopType != MB_TYPE_INTRA4x4 | |
| 250 | − && pNeighAvail->iTopType != MB_TYPE_INTRA8x8); | |
| 251 | − iCtxInc = iIdxA + iIdxB; | |
| 252 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + iCtxInc, uiCode)); | |
| 253 | − uiBinVal = uiCode; | |
| 254 | − if (uiBinVal != 0) { //I16x16 | |
| 255 | − WELS_READ_VERIFY (DecodeTerminateCabac (pCabacDecEngine, uiCode)); | |
| 256 | − if (uiCode == 1) | |
| 257 | − uiBinVal = 25; //I_PCM | |
| 258 | − else { | |
| 259 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 260 | − uiBinVal = 1 + uiCode * 12; | |
| 261 | − //decoding of uiCbp:0,1,2 | |
| 262 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 4, uiCode)); | |
| 263 | − if (uiCode != 0) { | |
| 264 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode)); | |
| 265 | − uiBinVal += 4; | |
| 266 | − if (uiCode != 0) | |
| 267 | − uiBinVal += 4; | |
| 268 | − } | |
| 269 | − //decoding of I pred-mode: 0,1,2,3 | |
| 270 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 6, uiCode)); | |
| 271 | − uiBinVal += (uiCode << 1); | |
| 272 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 7, uiCode)); | |
| 273 | − uiBinVal += uiCode; | |
| 274 | − } | |
| 275 | − } | |
| 276 | − //I4x4 | |
| 277 | − return ERR_NONE; | |
| 278 | −} | |
| 279 | − | |
| 280 | −int32_t ParseMBTypePSliceCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiMbType) { | |
| 281 | − uint32_t uiCode; | |
| 282 | − uiMbType = 0; | |
| 283 | − PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine; | |
| 284 | − | |
| 285 | − PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_SKIP; | |
| 286 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 287 | − if (uiCode) { | |
| 288 | − // Intra MB | |
| 289 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 6, uiCode)); | |
| 290 | − if (uiCode) { // Intra 16x16 | |
| 291 | − WELS_READ_VERIFY (DecodeTerminateCabac (pCabacDecEngine, uiCode)); | |
| 292 | − if (uiCode) { | |
| 293 | − uiMbType = 30; | |
| 294 | − return ERR_NONE;//MB_TYPE_INTRA_PCM; | |
| 295 | − } | |
| 296 | − | |
| 297 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 7, uiCode)); | |
| 298 | − uiMbType = 6 + uiCode * 12; | |
| 299 | − | |
| 300 | − //uiCbp: 0,1,2 | |
| 301 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 8, uiCode)); | |
| 302 | − if (uiCode) { | |
| 303 | − uiMbType += 4; | |
| 304 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 8, uiCode)); | |
| 305 | − if (uiCode) | |
| 306 | − uiMbType += 4; | |
| 307 | − } | |
| 308 | − | |
| 309 | − //IPredMode: 0,1,2,3 | |
| 310 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 9, uiCode)); | |
| 311 | − uiMbType += (uiCode << 1); | |
| 312 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 9, uiCode)); | |
| 313 | − uiMbType += uiCode; | |
| 314 | − } else | |
| 315 | − // Intra 4x4 | |
| 316 | − uiMbType = 5; | |
| 317 | − } else { // P MB | |
| 318 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 4, uiCode)); | |
| 319 | − if (uiCode) { //second bit | |
| 320 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 6, uiCode)); | |
| 321 | − if (uiCode) | |
| 322 | − uiMbType = 1; | |
| 323 | − else | |
| 324 | − uiMbType = 2; | |
| 325 | − } else { | |
| 326 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode)); | |
| 327 | − if (uiCode) | |
| 328 | − uiMbType = 3; | |
| 329 | − else | |
| 330 | − uiMbType = 0; | |
| 331 | − } | |
| 332 | − } | |
| 333 | − return ERR_NONE; | |
| 334 | −} | |
| 335 | − | |
| 336 | −int32_t ParseMBTypeBSliceCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiMbType) { | |
| 337 | − uint32_t uiCode; | |
| 338 | − uiMbType = 0; | |
| 339 | − int32_t iIdxA = 0, iIdxB = 0; | |
| 340 | − int32_t iCtxInc; | |
| 341 | − | |
| 342 | − PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine; | |
| 343 | − PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + 27; //B slice | |
| 344 | − | |
| 345 | − iIdxA = (pNeighAvail->iLeftAvail) && !IS_DIRECT (pNeighAvail->iLeftType); | |
| 346 | − iIdxB = (pNeighAvail->iTopAvail) && !IS_DIRECT (pNeighAvail->iTopType); | |
| 347 | − | |
| 348 | − iCtxInc = iIdxA + iIdxB; | |
| 349 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + iCtxInc, uiCode)); | |
| 350 | − if (!uiCode) | |
| 351 | − uiMbType = 0; // Bi_Direct | |
| 352 | − else { | |
| 353 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 354 | − if (!uiCode) { | |
| 355 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode)); | |
| 356 | − uiMbType = 1 + uiCode; // 16x16 L0L1 | |
| 357 | − } else { | |
| 358 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 4, uiCode)); | |
| 359 | − uiMbType = uiCode << 3; | |
| 360 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode)); | |
| 361 | − uiMbType |= uiCode << 2; | |
| 362 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode)); | |
| 363 | − uiMbType |= uiCode << 1; | |
| 364 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode)); | |
| 365 | − uiMbType |= uiCode; | |
| 366 | − if (uiMbType < 8) { | |
| 367 | − uiMbType += 3; | |
| 368 | − return ERR_NONE; | |
| 369 | − } else if (uiMbType == 13) { | |
| 370 | − uiMbType = DecodeCabacIntraMbType (pCtx, pNeighAvail, 32) + 23; | |
| 371 | − return ERR_NONE; | |
| 372 | − } else if (uiMbType == 14) { | |
| 373 | − uiMbType = 11; // Bi8x16 | |
| 374 | − return ERR_NONE; | |
| 375 | − } else if (uiMbType == 15) { | |
| 376 | − uiMbType = 22; // 8x8 | |
| 377 | − return ERR_NONE; | |
| 378 | − } | |
| 379 | − uiMbType <<= 1; | |
| 380 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode)); | |
| 381 | − uiMbType |= uiCode; | |
| 382 | − uiMbType -= 4; | |
| 383 | − } | |
| 384 | − } | |
| 385 | − return ERR_NONE; | |
| 386 | −} | |
| 387 | − | |
| 388 | −int32_t ParseTransformSize8x8FlagCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, | |
| 389 | − bool& bTransformSize8x8Flag) { | |
| 390 | − uint32_t uiCode; | |
| 391 | − int32_t iIdxA, iIdxB; | |
| 392 | − int32_t iCtxInc; | |
| 393 | − PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine; | |
| 394 | − PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_TS_8x8_FLAG; | |
| 395 | − iIdxA = (pNeighAvail->iLeftAvail) && (pCtx->pCurDqLayer->pTransformSize8x8Flag[pCtx->pCurDqLayer->iMbXyIndex - 1]); | |
| 396 | − iIdxB = (pNeighAvail->iTopAvail) | |
| 397 | − && (pCtx->pCurDqLayer->pTransformSize8x8Flag[pCtx->pCurDqLayer->iMbXyIndex - pCtx->pCurDqLayer->iMbWidth]); | |
| 398 | − iCtxInc = iIdxA + iIdxB; | |
| 399 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + iCtxInc, uiCode)); | |
| 400 | − bTransformSize8x8Flag = !!uiCode; | |
| 401 | − | |
| 402 | − return ERR_NONE; | |
| 403 | −} | |
| 404 | − | |
| 405 | −int32_t ParseSubMBTypeCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiSubMbType) { | |
| 406 | − uint32_t uiCode; | |
| 407 | − PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine; | |
| 408 | − PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_SUBMB_TYPE; | |
| 409 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx, uiCode)); | |
| 410 | − if (uiCode) | |
| 411 | − uiSubMbType = 0; | |
| 412 | − else { | |
| 413 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 1, uiCode)); | |
| 414 | − if (uiCode) { | |
| 415 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 2, uiCode)); | |
| 416 | − uiSubMbType = 3 - uiCode; | |
| 417 | − } else { | |
| 418 | − uiSubMbType = 1; | |
| 419 | − } | |
| 420 | − } | |
| 421 | − return ERR_NONE; | |
| 422 | −} | |
| 423 | − | |
| 424 | −int32_t ParseBSubMBTypeCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiSubMbType) { | |
| 425 | − uint32_t uiCode; | |
| 426 | − PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine; | |
| 427 | − PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_B_SUBMB_TYPE; | |
| 428 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx, uiCode)); | |
| 429 | − if (!uiCode) { | |
| 430 | − uiSubMbType = 0; /* B_Direct_8x8 */ | |
| 431 | − return ERR_NONE; | |
| 432 | − } | |
| 433 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 1, uiCode)); | |
| 434 | − if (!uiCode) { | |
| 435 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 436 | − uiSubMbType = 1 + uiCode; /* B_L0_8x8, B_L1_8x8 */ | |
| 437 | − return ERR_NONE; | |
| 438 | − } | |
| 439 | − uiSubMbType = 3; | |
| 440 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 2, uiCode)); | |
| 441 | − if (uiCode) { | |
| 442 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 443 | − if (uiCode) { | |
| 444 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 445 | − uiSubMbType = 11 + uiCode; /* B_L1_4x4, B_Bi_4x4 */ | |
| 446 | − return ERR_NONE; | |
| 447 | − } | |
| 448 | − uiSubMbType += 4; | |
| 449 | − } | |
| 450 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 451 | − uiSubMbType += 2 * uiCode; | |
| 452 | − WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 453 | − uiSubMbType += uiCode; | |
| 454 | − | |
| 455 | − return ERR_NONE; | |
| 456 | −} | |
| 457 | − | |
| 458 | −int32_t ParseIntraPredModeLumaCabac (PWelsDecoderContext pCtx, int32_t& iBinVal) { | |
| 459 | − uint32_t uiCode; | |
| 460 | − iBinVal = 0; | |
| 461 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_IPR, uiCode)); | |
| 462 | − if (uiCode == 1) | |
| 463 | − iBinVal = -1; | |
| 464 | − else { | |
| 465 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_IPR + 1, uiCode)); | |
| 466 | − iBinVal |= uiCode; | |
| 467 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_IPR + 1, uiCode)); | |
| 468 | − iBinVal |= (uiCode << 1); | |
| 469 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_IPR + 1, uiCode)); | |
| 470 | − iBinVal |= (uiCode << 2); | |
| 471 | − } | |
| 472 | − return ERR_NONE; | |
| 473 | −} | |
| 474 | − | |
| 475 | −int32_t ParseIntraPredModeChromaCabac (PWelsDecoderContext pCtx, uint8_t uiNeighAvail, int32_t& iBinVal) { | |
| 476 | − uint32_t uiCode; | |
| 477 | − int32_t iIdxA, iIdxB, iCtxInc; | |
| 478 | − int8_t* pChromaPredMode = pCtx->pCurDqLayer->pChromaPredMode; | |
| 479 | − uint32_t* pMbType = pCtx->pCurDqLayer->pMbType; | |
| 480 | − int32_t iLeftAvail = uiNeighAvail & 0x04; | |
| 481 | − int32_t iTopAvail = uiNeighAvail & 0x01; | |
| 482 | − | |
| 483 | − int32_t iMbXy = pCtx->pCurDqLayer->iMbXyIndex; | |
| 484 | − int32_t iMbXyTop = iMbXy - pCtx->pCurDqLayer->iMbWidth; | |
| 485 | − int32_t iMbXyLeft = iMbXy - 1; | |
| 486 | − | |
| 487 | − iBinVal = 0; | |
| 488 | − | |
| 489 | − iIdxB = iTopAvail && (pChromaPredMode[iMbXyTop] > 0 && pChromaPredMode[iMbXyTop] <= 3) | |
| 490 | − && pMbType[iMbXyTop] != MB_TYPE_INTRA_PCM; | |
| 491 | − iIdxA = iLeftAvail && (pChromaPredMode[iMbXyLeft] > 0 && pChromaPredMode[iMbXyLeft] <= 3) | |
| 492 | − && pMbType[iMbXyLeft] != MB_TYPE_INTRA_PCM; | |
| 493 | − iCtxInc = iIdxA + iIdxB; | |
| 494 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CIPR + iCtxInc, uiCode)); | |
| 495 | − iBinVal = uiCode; | |
| 496 | − if (iBinVal != 0) { | |
| 497 | − uint32_t iSym; | |
| 498 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CIPR + 3, iSym)); | |
| 499 | − if (iSym == 0) { | |
| 500 | − iBinVal = (iSym + 1); | |
| 501 | − return ERR_NONE; | |
| 502 | − } | |
| 503 | − iSym = 0; | |
| 504 | − do { | |
| 505 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CIPR + 3, uiCode)); | |
| 506 | − ++iSym; | |
| 507 | − } while ((uiCode != 0) && (iSym < 1)); | |
| 508 | − | |
| 509 | − if ((uiCode != 0) && (iSym == 1)) | |
| 510 | − ++ iSym; | |
| 511 | − iBinVal = (iSym + 1); | |
| 512 | − return ERR_NONE; | |
| 513 | − } | |
| 514 | − return ERR_NONE; | |
| 515 | −} | |
| 516 | − | |
| 517 | −int32_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]) { | |
| 519 | − PSlice pSlice = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer; | |
| 520 | − PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | |
| 521 | − PDqLayer pCurDqLayer = pCtx->pCurDqLayer; | |
| 522 | − PPicture* ppRefPic = pCtx->sRefPic.pRefList[LIST_0]; | |
| 523 | − int32_t pRefCount[2]; | |
| 524 | − int32_t i, j; | |
| 525 | − int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 526 | − int16_t pMv[4] = {0}; | |
| 527 | − int16_t pMvd[4] = {0}; | |
| 528 | − int8_t iRef[2] = {0}; | |
| 529 | − int32_t iPartIdx; | |
| 530 | − int16_t iMinVmv = pSliceHeader->pSps->pSLevelLimits->iMinVmv; | |
| 531 | − int16_t iMaxVmv = pSliceHeader->pSps->pSLevelLimits->iMaxVmv; | |
| 532 | − pRefCount[0] = pSliceHeader->uiRefCount[0]; | |
| 533 | − pRefCount[1] = pSliceHeader->uiRefCount[1]; | |
| 534 | − | |
| 535 | − switch (pCurDqLayer->pMbType[iMbXy]) { | |
| 536 | − case MB_TYPE_16x16: { | |
| 537 | − iPartIdx = 0; | |
| 538 | − WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, 0, LIST_0, iPartIdx, pRefCount[0], 0, | |
| 539 | − iRef[0])); | |
| 540 | − if ((iRef[0] < 0) || (iRef[0] >= pRefCount[0]) || (ppRefPic[iRef[0]] == NULL)) { //error ref_idx | |
| 541 | − pCtx->bMbRefConcealed = true; | |
| 542 | − if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 543 | − iRef[0] = 0; | |
| 544 | − pCtx->iErrorCode |= dsBitstreamError; | |
| 545 | − } else { | |
| 546 | − return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX); | |
| 547 | − } | |
| 548 | − } | |
| 549 | − pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRef[0]] | |
| 550 | − && ppRefPic[iRef[0]]->bIsComplete); | |
| 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])); | |
| 553 | − WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 1, pMvd[1])); | |
| 554 | − pMv[0] += pMvd[0]; | |
| 555 | − pMv[1] += pMvd[1]; | |
| 556 | − WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv"); | |
| 557 | − UpdateP16x16MotionInfo (pCurDqLayer, LIST_0, iRef[0], pMv); | |
| 558 | − UpdateP16x16MvdCabac (pCurDqLayer, pMvd, LIST_0); | |
| 559 | − } | |
| 560 | − break; | |
| 561 | − case MB_TYPE_16x8: | |
| 562 | − for (i = 0; i < 2; i++) { | |
| 563 | − iPartIdx = i << 3; | |
| 564 | − WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, 0, LIST_0, iPartIdx, pRefCount[0], 0, | |
| 565 | − iRef[i])); | |
| 566 | − if ((iRef[i] < 0) || (iRef[i] >= pRefCount[0]) || (ppRefPic[iRef[i]] == NULL)) { //error ref_idx | |
| 567 | − pCtx->bMbRefConcealed = true; | |
| 568 | − if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 569 | − iRef[i] = 0; | |
| 570 | − pCtx->iErrorCode |= dsBitstreamError; | |
| 571 | − } else { | |
| 572 | − return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX); | |
| 573 | − } | |
| 574 | − } | |
| 575 | − pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRef[i]] | |
| 576 | − && ppRefPic[iRef[i]]->bIsComplete); | |
| 577 | − UpdateP16x8RefIdxCabac (pCurDqLayer, pRefIndex, iPartIdx, iRef[i], LIST_0); | |
| 578 | − } | |
| 579 | − for (i = 0; i < 2; i++) { | |
| 580 | − iPartIdx = i << 3; | |
| 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])); | |
| 583 | − WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 1, pMvd[1])); | |
| 584 | − pMv[0] += pMvd[0]; | |
| 585 | − pMv[1] += pMvd[1]; | |
| 586 | − WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv"); | |
| 587 | − UpdateP16x8MotionInfo (pCurDqLayer, pMotionVector, pRefIndex, LIST_0, iPartIdx, iRef[i], pMv); | |
| 588 | − UpdateP16x8MvdCabac (pCurDqLayer, pMvdCache, iPartIdx, pMvd, LIST_0); | |
| 589 | − } | |
| 590 | − break; | |
| 591 | − case MB_TYPE_8x16: | |
| 592 | − for (i = 0; i < 2; i++) { | |
| 593 | − iPartIdx = i << 2; | |
| 594 | − WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, 0, LIST_0, iPartIdx, pRefCount[0], 0, | |
| 595 | − iRef[i])); | |
| 596 | − if ((iRef[i] < 0) || (iRef[i] >= pRefCount[0]) || (ppRefPic[iRef[i]] == NULL)) { //error ref_idx | |
| 597 | − pCtx->bMbRefConcealed = true; | |
| 598 | − if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 599 | − iRef[i] = 0; | |
| 600 | − pCtx->iErrorCode |= dsBitstreamError; | |
| 601 | − } else { | |
| 602 | − return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX); | |
| 603 | − } | |
| 604 | − } | |
| 605 | − pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRef[i]] | |
| 606 | − && ppRefPic[iRef[i]]->bIsComplete); | |
| 607 | − UpdateP8x16RefIdxCabac (pCurDqLayer, pRefIndex, iPartIdx, iRef[i], LIST_0); | |
| 608 | − } | |
| 609 | − for (i = 0; i < 2; i++) { | |
| 610 | − iPartIdx = i << 2; | |
| 611 | − PredInter8x16Mv (pMotionVector, pRefIndex, LIST_0, i << 2, iRef[i], pMv/*&mv[0], &mv[1]*/); | |
| 612 | − | |
| 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])); | |
| 615 | − pMv[0] += pMvd[0]; | |
| 616 | − pMv[1] += pMvd[1]; | |
| 617 | − WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv"); | |
| 618 | − UpdateP8x16MotionInfo (pCurDqLayer, pMotionVector, pRefIndex, LIST_0, iPartIdx, iRef[i], pMv); | |
| 619 | − UpdateP8x16MvdCabac (pCurDqLayer, pMvdCache, iPartIdx, pMvd, LIST_0); | |
| 620 | − } | |
| 621 | − break; | |
| 622 | − case MB_TYPE_8x8: | |
| 623 | − case MB_TYPE_8x8_REF0: { | |
| 624 | − int8_t pRefIdx[4] = {0}, pSubPartCount[4], pPartW[4]; | |
| 625 | − uint32_t uiSubMbType; | |
| 626 | − //sub_mb_type, partition | |
| 627 | − for (i = 0; i < 4; i++) { | |
| 628 | − WELS_READ_VERIFY (ParseSubMBTypeCabac (pCtx, pNeighAvail, uiSubMbType)); | |
| 629 | − if (uiSubMbType >= 4) { //invalid sub_mb_type | |
| 630 | − return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_SUB_MB_TYPE); | |
| 631 | − } | |
| 632 | − pCurDqLayer->pSubMbType[iMbXy][i] = g_ksInterPSubMbTypeInfo[uiSubMbType].iType; | |
| 633 | − pSubPartCount[i] = g_ksInterPSubMbTypeInfo[uiSubMbType].iPartCount; | |
| 634 | − pPartW[i] = g_ksInterPSubMbTypeInfo[uiSubMbType].iPartWidth; | |
| 635 | − | |
| 636 | − // Need modification when B picture add in, reference to 7.3.5 | |
| 637 | − pCurDqLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] &= (uiSubMbType == 0); | |
| 638 | − } | |
| 639 | − | |
| 640 | − for (i = 0; i < 4; i++) { | |
| 641 | − int16_t iIdx8 = i << 2; | |
| 642 | − WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, 0, LIST_0, iIdx8, pRefCount[0], 1, | |
| 643 | − pRefIdx[i])); | |
| 644 | − if ((pRefIdx[i] < 0) || (pRefIdx[i] >= pRefCount[0]) || (ppRefPic[pRefIdx[i]] == NULL)) { //error ref_idx | |
| 645 | − pCtx->bMbRefConcealed = true; | |
| 646 | − if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 647 | − pRefIdx[i] = 0; | |
| 648 | − pCtx->iErrorCode |= dsBitstreamError; | |
| 649 | − } else { | |
| 650 | − return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX); | |
| 651 | − } | |
| 652 | − } | |
| 653 | − pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[pRefIdx[i]] | |
| 654 | − && ppRefPic[pRefIdx[i]]->bIsComplete); | |
| 655 | − UpdateP8x8RefIdxCabac (pCurDqLayer, pRefIndex, iIdx8, pRefIdx[i], LIST_0); | |
| 656 | − } | |
| 657 | − //mv | |
| 658 | − for (i = 0; i < 4; i++) { | |
| 659 | − int8_t iPartCount = pSubPartCount[i]; | |
| 660 | − uiSubMbType = pCurDqLayer->pSubMbType[iMbXy][i]; | |
| 661 | − int16_t iPartIdx, iBlockW = pPartW[i]; | |
| 662 | − uint8_t iScan4Idx, iCacheIdx; | |
| 663 | − iCacheIdx = g_kuiCache30ScanIdx[i << 2]; | |
| 664 | − pRefIndex[0][iCacheIdx ] = pRefIndex[0][iCacheIdx + 1] | |
| 665 | − = pRefIndex[0][iCacheIdx + 6] = pRefIndex[0][iCacheIdx + 7] = pRefIdx[i]; | |
| 666 | − | |
| 667 | − for (j = 0; j < iPartCount; j++) { | |
| 668 | − iPartIdx = (i << 2) + j * iBlockW; | |
| 669 | − iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 670 | − iCacheIdx = g_kuiCache30ScanIdx[iPartIdx]; | |
| 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])); | |
| 673 | − WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 1, pMvd[1])); | |
| 674 | − pMv[0] += pMvd[0]; | |
| 675 | − pMv[1] += pMvd[1]; | |
| 676 | − WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv"); | |
| 677 | − if (SUB_MB_TYPE_8x8 == uiSubMbType) { | |
| 678 | − ST32 ((pMv + 2), LD32 (pMv)); | |
| 679 | − ST32 ((pMvd + 2), LD32 (pMvd)); | |
| 680 | − ST64 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx], LD64 (pMv)); | |
| 681 | − ST64 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx + 4], LD64 (pMv)); | |
| 682 | − ST64 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx], LD64 (pMvd)); | |
| 683 | − ST64 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx + 4], LD64 (pMvd)); | |
| 684 | − ST64 (pMotionVector[0][iCacheIdx ], LD64 (pMv)); | |
| 685 | − ST64 (pMotionVector[0][iCacheIdx + 6], LD64 (pMv)); | |
| 686 | − ST64 (pMvdCache[0][iCacheIdx ], LD64 (pMvd)); | |
| 687 | − ST64 (pMvdCache[0][iCacheIdx + 6], LD64 (pMvd)); | |
| 688 | − } else if (SUB_MB_TYPE_8x4 == uiSubMbType) { | |
| 689 | − ST32 ((pMv + 2), LD32 (pMv)); | |
| 690 | − ST32 ((pMvd + 2), LD32 (pMvd)); | |
| 691 | − ST64 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx ], LD64 (pMv)); | |
| 692 | − ST64 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx ], LD64 (pMvd)); | |
| 693 | − ST64 (pMotionVector[0][iCacheIdx ], LD64 (pMv)); | |
| 694 | − ST64 (pMvdCache[0][iCacheIdx ], LD64 (pMvd)); | |
| 695 | − } else if (SUB_MB_TYPE_4x8 == uiSubMbType) { | |
| 696 | − ST32 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx ], LD32 (pMv)); | |
| 697 | − ST32 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx + 4], LD32 (pMv)); | |
| 698 | − ST32 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx ], LD32 (pMvd)); | |
| 699 | − ST32 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx + 4], LD32 (pMvd)); | |
| 700 | − ST32 (pMotionVector[0][iCacheIdx ], LD32 (pMv)); | |
| 701 | − ST32 (pMotionVector[0][iCacheIdx + 6], LD32 (pMv)); | |
| 702 | − ST32 (pMvdCache[0][iCacheIdx ], LD32 (pMvd)); | |
| 703 | − ST32 (pMvdCache[0][iCacheIdx + 6], LD32 (pMvd)); | |
| 704 | − } else { //SUB_MB_TYPE_4x4 | |
| 705 | − ST32 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx ], LD32 (pMv)); | |
| 706 | − ST32 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx ], LD32 (pMvd)); | |
| 707 | − ST32 (pMotionVector[0][iCacheIdx ], LD32 (pMv)); | |
| 708 | − ST32 (pMvdCache[0][iCacheIdx ], LD32 (pMvd)); | |
| 709 | − } | |
| 710 | − } | |
| 711 | − } | |
| 712 | − } | |
| 713 | − break; | |
| 714 | − default: | |
| 715 | − break; | |
| 716 | − } | |
| 717 | − return ERR_NONE; | |
| 718 | −} | |
| 719 | − | |
| 720 | −int32_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], | |
| 722 | − int8_t pDirect[30]) { | |
| 723 | − PSlice pSlice = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer; | |
| 724 | − PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | |
| 725 | − PDqLayer pCurDqLayer = pCtx->pCurDqLayer; | |
| 726 | − int32_t pRefCount[LIST_A]; | |
| 727 | − int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 728 | − int16_t pMv[4] = { 0 }; | |
| 729 | − int16_t pMvd[4] = { 0 }; | |
| 730 | − int8_t iRef[LIST_A] = { 0 }; | |
| 731 | − int32_t iPartIdx; | |
| 732 | − int16_t iMinVmv = pSliceHeader->pSps->pSLevelLimits->iMinVmv; | |
| 733 | − int16_t iMaxVmv = pSliceHeader->pSps->pSLevelLimits->iMaxVmv; | |
| 734 | − pRefCount[0] = pSliceHeader->uiRefCount[0]; | |
| 735 | − pRefCount[1] = pSliceHeader->uiRefCount[1]; | |
| 736 | − | |
| 737 | − MbType mbType = pCurDqLayer->pMbType[iMbXy]; | |
| 738 | − | |
| 739 | − if (IS_DIRECT (mbType)) { | |
| 740 | − | |
| 741 | − int16_t pMvDirect[LIST_A][2] = { { 0, 0 }, { 0, 0 } }; | |
| 742 | − if (pSliceHeader->iDirectSpatialMvPredFlag) { | |
| 743 | − //predict direct spatial mv | |
| 744 | − PredMvBDirectSpatial (pCtx, pMvDirect, iRef); | |
| 745 | − } else { | |
| 746 | − //temporal direct 16x16 mode | |
| 747 | − ComputeColocated (pCtx); | |
| 748 | − PredBDirectTemporal (pCtx, pMvDirect, iRef); | |
| 749 | − } | |
| 750 | − } else if (IS_INTER_16x16 (mbType)) { | |
| 751 | − iPartIdx = 0; | |
| 752 | − for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 753 | − iRef[listIdx] = REF_NOT_IN_LIST; | |
| 754 | − if (IS_DIR (mbType, 0, listIdx)) { | |
| 755 | − WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, pDirect, listIdx, iPartIdx, | |
| 756 | − pRefCount[listIdx], 0, | |
| 757 | − iRef[listIdx])); | |
| 758 | − if ((iRef[listIdx] < 0) || (iRef[listIdx] >= pRefCount[listIdx]) | |
| 759 | − || (pCtx->sRefPic.pRefList[listIdx][iRef[listIdx]] == NULL)) { //error ref_idx | |
| 760 | − pCtx->bMbRefConcealed = true; | |
| 761 | − if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 762 | − iRef[listIdx] = 0; | |
| 763 | − pCtx->iErrorCode |= dsBitstreamError; | |
| 764 | − } else { | |
| 765 | − return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX); | |
| 766 | − } | |
| 767 | − } | |
| 768 | − pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (pCtx->sRefPic.pRefList[listIdx][iRef[listIdx]] | |
| 769 | − && pCtx->sRefPic.pRefList[listIdx][iRef[listIdx]]->bIsComplete); | |
| 770 | − } | |
| 771 | − } | |
| 772 | − for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 773 | − if (IS_DIR (mbType, 0, listIdx)) { | |
| 774 | − PredMv (pMotionVector, pRefIndex, listIdx, 0, 4, iRef[listIdx], pMv); | |
| 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])); | |
| 777 | − pMv[0] += pMvd[0]; | |
| 778 | − pMv[1] += pMvd[1]; | |
| 779 | − WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv"); | |
| 780 | − } else { | |
| 781 | − * (uint32_t*)pMv = * (uint32_t*)pMvd = 0; | |
| 782 | − } | |
| 783 | − UpdateP16x16MotionInfo (pCurDqLayer, listIdx, iRef[listIdx], pMv); | |
| 784 | − UpdateP16x16MvdCabac (pCurDqLayer, pMvd, listIdx); | |
| 785 | − } | |
| 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 } }; | |
| 788 | − for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 789 | − for (int32_t i = 0; i < 2; ++i) { | |
| 790 | − iPartIdx = i << 3; | |
| 791 | − int8_t ref_idx = REF_NOT_IN_LIST; | |
| 792 | − if (IS_DIR (mbType, i, listIdx)) { | |
| 793 | − WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, pDirect, listIdx, iPartIdx, | |
| 794 | − pRefCount[listIdx], 0, ref_idx)); | |
| 795 | − if ((ref_idx < 0) || (ref_idx >= pRefCount[listIdx]) | |
| 796 | − || (pCtx->sRefPic.pRefList[listIdx][ref_idx] == NULL)) { //error ref_idx | |
| 797 | − pCtx->bMbRefConcealed = true; | |
| 798 | − if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 799 | − ref_idx = 0; | |
| 800 | − pCtx->iErrorCode |= dsBitstreamError; | |
| 801 | − } else { | |
| 802 | − return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX); | |
| 803 | − } | |
| 804 | − } | |
| 805 | − pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (pCtx->sRefPic.pRefList[listIdx][ref_idx] | |
| 806 | − && pCtx->sRefPic.pRefList[listIdx][ref_idx]->bIsComplete); | |
| 807 | − } | |
| 808 | − UpdateP16x8RefIdxCabac (pCurDqLayer, pRefIndex, iPartIdx, ref_idx, listIdx); | |
| 809 | − ref_idx_list[listIdx][i] = ref_idx; | |
| 810 | − } | |
| 811 | − } | |
| 812 | − for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 813 | − for (int32_t i = 0; i < 2; ++i) { | |
| 814 | − iPartIdx = i << 3; | |
| 815 | − int8_t ref_idx = ref_idx_list[listIdx][i]; | |
| 816 | − if (IS_DIR (mbType, i, listIdx)) { | |
| 817 | − PredInter16x8Mv (pMotionVector, pRefIndex, listIdx, iPartIdx, ref_idx, pMv); | |
| 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])); | |
| 820 | − pMv[0] += pMvd[0]; | |
| 821 | − pMv[1] += pMvd[1]; | |
| 822 | − WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv"); | |
| 823 | − } else { | |
| 824 | − * (uint32_t*)pMv = * (uint32_t*)pMvd = 0; | |
| 825 | − } | |
| 826 | − UpdateP16x8MotionInfo (pCurDqLayer, pMotionVector, pRefIndex, listIdx, iPartIdx, ref_idx, pMv); | |
| 827 | − UpdateP16x8MvdCabac (pCurDqLayer, pMvdCache, iPartIdx, pMvd, listIdx); | |
| 828 | − } | |
| 829 | − } | |
| 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 } }; | |
| 832 | − for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 833 | − for (int32_t i = 0; i < 2; ++i) { | |
| 834 | − iPartIdx = i << 2; | |
| 835 | − int8_t ref_idx = REF_NOT_IN_LIST; | |
| 836 | − if (IS_DIR (mbType, i, listIdx)) { | |
| 837 | − WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, pDirect, listIdx, iPartIdx, | |
| 838 | − pRefCount[listIdx], 0, ref_idx)); | |
| 839 | − if ((ref_idx < 0) || (ref_idx >= pRefCount[listIdx]) | |
| 840 | − || (pCtx->sRefPic.pRefList[listIdx][ref_idx] == NULL)) { //error ref_idx | |
| 841 | − pCtx->bMbRefConcealed = true; | |
| 842 | − if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 843 | − ref_idx = 0; | |
| 844 | − pCtx->iErrorCode |= dsBitstreamError; | |
| 845 | − } else { | |
| 846 | − return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX); | |
| 847 | − } | |
| 848 | − } | |
| 849 | − pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (pCtx->sRefPic.pRefList[listIdx][ref_idx] | |
| 850 | − && pCtx->sRefPic.pRefList[listIdx][ref_idx]->bIsComplete); | |
| 851 | − } | |
| 852 | − UpdateP8x16RefIdxCabac (pCurDqLayer, pRefIndex, iPartIdx, ref_idx, listIdx); | |
| 853 | − ref_idx_list[listIdx][i] = ref_idx; | |
| 854 | − } | |
| 855 | − } | |
| 856 | − for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 857 | − for (int32_t i = 0; i < 2; ++i) { | |
| 858 | − iPartIdx = i << 2; | |
| 859 | − int8_t ref_idx = ref_idx_list[listIdx][i]; | |
| 860 | − if (IS_DIR (mbType, i, listIdx)) { | |
| 861 | − PredInter8x16Mv (pMotionVector, pRefIndex, listIdx, iPartIdx, ref_idx, pMv); | |
| 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])); | |
| 864 | − pMv[0] += pMvd[0]; | |
| 865 | − pMv[1] += pMvd[1]; | |
| 866 | − WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv"); | |
| 867 | − } else { | |
| 868 | − * (uint32_t*)pMv = * (uint32_t*)pMvd = 0; | |
| 869 | − } | |
| 870 | − UpdateP8x16MotionInfo (pCurDqLayer, pMotionVector, pRefIndex, listIdx, iPartIdx, ref_idx, pMv); | |
| 871 | − UpdateP8x16MvdCabac (pCurDqLayer, pMvdCache, iPartIdx, pMvd, listIdx); | |
| 872 | − } | |
| 873 | − } | |
| 874 | − } else if (IS_Inter_8x8 (mbType)) { | |
| 875 | − int8_t pSubPartCount[4], pPartW[4]; | |
| 876 | − uint32_t uiSubMbType; | |
| 877 | − //sub_mb_type, partition | |
| 878 | − int16_t pMvDirect[LIST_A][2] = { {0, 0}, {0, 0} }; | |
| 879 | − bool has_direct_called = false; | |
| 880 | − SubMbType directSubMbType = 0; | |
| 881 | − for (int32_t i = 0; i < 4; i++) { | |
| 882 | − WELS_READ_VERIFY (ParseBSubMBTypeCabac (pCtx, pNeighAvail, uiSubMbType)); | |
| 883 | − if (uiSubMbType > 13) { //invalid sub_mb_type | |
| 884 | − return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_SUB_MB_TYPE); | |
| 885 | − } | |
| 886 | −// pCurDqLayer->pSubMbType[iMbXy][i] = g_ksInterBSubMbTypeInfo[uiSubMbType].iType; | |
| 887 | − pSubPartCount[i] = g_ksInterBSubMbTypeInfo[uiSubMbType].iPartCount; | |
| 888 | − pPartW[i] = g_ksInterBSubMbTypeInfo[uiSubMbType].iPartWidth; | |
| 889 | − | |
| 890 | − // Need modification when B picture add in, reference to 7.3.5 | |
| 891 | − if (pSubPartCount[i] > 1) | |
| 892 | − pCurDqLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = false; | |
| 893 | − | |
| 894 | − if (IS_DIRECT (g_ksInterBSubMbTypeInfo[uiSubMbType].iType)) { | |
| 895 | − if (!has_direct_called) { | |
| 896 | − if (pSliceHeader->iDirectSpatialMvPredFlag) { | |
| 897 | − directSubMbType = PredMvBDirectSpatial (pCtx, pMvDirect, iRef); | |
| 898 | − } else { | |
| 899 | − //temporal direct mode | |
| 900 | − ComputeColocated (pCtx); | |
| 901 | − PredBDirectTemporal (pCtx, pMvDirect, iRef); | |
| 902 | − } | |
| 903 | − has_direct_called = true; | |
| 904 | − } | |
| 905 | − pCurDqLayer->pSubMbType[iMbXy][i] = directSubMbType; | |
| 906 | − if (IS_SUB_4x4 (pCurDqLayer->pSubMbType[iMbXy][i])) { | |
| 907 | − pSubPartCount[i] = 4; | |
| 908 | − pPartW[i] = 1; | |
| 909 | − } | |
| 910 | − } else { | |
| 911 | − pCurDqLayer->pSubMbType[iMbXy][i] = g_ksInterBSubMbTypeInfo[uiSubMbType].iType; | |
| 912 | − } | |
| 913 | − } | |
| 914 | − for (int32_t i = 0; i < 4; i++) { //Direct 8x8 Ref and mv | |
| 915 | − | |
| 916 | − int16_t iIdx8 = i << 2; | |
| 917 | − if (IS_DIRECT (pCurDqLayer->pSubMbType[iMbXy][i])) { | |
| 918 | − | |
| 919 | − int8_t iPartCount = pSubPartCount[i]; | |
| 920 | − int16_t iPartIdx, iBlockW = pPartW[i]; | |
| 921 | − uint8_t iScan4Idx, iCacheIdx, iColocIdx; | |
| 922 | − iCacheIdx = g_kuiCache30ScanIdx[iIdx8]; | |
| 923 | − | |
| 924 | − if (!pSliceHeader->iDirectSpatialMvPredFlag) { | |
| 925 | − iRef[LIST_1] = 0; | |
| 926 | − if (pCurDqLayer->iColocIntra[g_kuiScan4[iIdx8]]) { | |
| 927 | − iRef[LIST_0] = 0; | |
| 928 | − } else { | |
| 929 | − if (pCurDqLayer->iColocRefIndex[LIST_0][iIdx8] >= 0) { | |
| 930 | − iRef[LIST_0] = pCurDqLayer->iColocRefIndex[LIST_0][iIdx8]; | |
| 931 | − } else { | |
| 932 | − iRef[LIST_0] = pCurDqLayer->iColocRefIndex[LIST_1][iIdx8]; | |
| 933 | − } | |
| 934 | − } | |
| 935 | − } | |
| 936 | − for (int32_t j = 0; j < iPartCount; j++) { | |
| 937 | − iPartIdx = iIdx8 + j * iBlockW; | |
| 938 | − iColocIdx = g_kuiScan4[iPartIdx]; | |
| 939 | − iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 940 | − iCacheIdx = g_kuiCache30ScanIdx[iPartIdx]; | |
| 941 | − | |
| 942 | − if (pSliceHeader->iDirectSpatialMvPredFlag) { | |
| 943 | − int16_t pMV[4] = { 0 }; | |
| 944 | − if (IS_SUB_8x8 (pCurDqLayer->pSubMbType[iMbXy][i])) { | |
| 945 | − * (uint32_t*)pMV = * (uint32_t*)pMvDirect[LIST_0]; | |
| 946 | − ST32 ((pMV + 2), LD32 (pMV)); | |
| 947 | − ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], LD64 (pMV)); | |
| 948 | − ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx + 4], LD64 (pMV)); | |
| 949 | − ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0); | |
| 950 | − ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx + 4], 0); | |
| 951 | − ST64 (pMotionVector[LIST_0][iCacheIdx], LD64 (pMV)); | |
| 952 | − ST64 (pMotionVector[LIST_0][iCacheIdx + 6], LD64 (pMV)); | |
| 953 | − ST64 (pMvdCache[LIST_0][iCacheIdx], 0); | |
| 954 | − ST64 (pMvdCache[LIST_0][iCacheIdx + 6], 0); | |
| 955 | − * (uint32_t*)pMV = * (uint32_t*)pMvDirect[LIST_1]; | |
| 956 | − ST32 ((pMV + 2), LD32 (pMV)); | |
| 957 | − ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], LD64 (pMV)); | |
| 958 | − ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx + 4], LD64 (pMV)); | |
| 959 | − ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0); | |
| 960 | − ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx + 4], 0); | |
| 961 | − ST64 (pMotionVector[LIST_1][iCacheIdx], LD64 (pMV)); | |
| 962 | − ST64 (pMotionVector[LIST_1][iCacheIdx + 6], LD64 (pMV)); | |
| 963 | − ST64 (pMvdCache[LIST_1][iCacheIdx], 0); | |
| 964 | − ST64 (pMvdCache[LIST_1][iCacheIdx + 6], 0); | |
| 965 | − } else { //SUB_4x4 | |
| 966 | − * (uint32_t*)pMV = * (uint32_t*)pMvDirect[LIST_0]; | |
| 967 | − ST32 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], LD32 (pMV)); | |
| 968 | − ST32 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0); | |
| 969 | − ST32 (pMotionVector[LIST_0][iCacheIdx], LD32 (pMV)); | |
| 970 | − ST32 (pMvdCache[LIST_0][iCacheIdx], 0); | |
| 971 | − * (uint32_t*)pMV = * (uint32_t*)pMvDirect[LIST_1]; | |
| 972 | − ST32 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], LD32 (pMV)); | |
| 973 | − ST32 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0); | |
| 974 | − ST32 (pMotionVector[LIST_1][iCacheIdx], LD32 (pMV)); | |
| 975 | − ST32 (pMvdCache[LIST_1][iCacheIdx], 0); | |
| 976 | − } | |
| 977 | − | |
| 978 | − if ((* (int32_t*)pMvDirect[LIST_0] | * (int32_t*)pMvDirect[LIST_1])) { | |
| 979 | − bool bIsLongRef = pCtx->sRefPic.pRefList[LIST_1][0]->bIsLongRef; | |
| 980 | − uint32_t uiColZeroFlag = (0 == pCurDqLayer->iColocIntra[iColocIdx]) && !bIsLongRef && | |
| 981 | − (pCurDqLayer->iColocRefIndex[LIST_0][iColocIdx] == 0 || (pCurDqLayer->iColocRefIndex[LIST_0][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] : | |
| 984 | − pCurDqLayer->iColocMv[LIST_1]; | |
| 985 | − const int16_t* mv = mvColoc[iColocIdx]; | |
| 986 | − if (IS_SUB_8x8 (pCurDqLayer->pSubMbType[iMbXy][i])) { | |
| 987 | − if (uiColZeroFlag && ((unsigned) (mv[0] + 1) <= 2 && (unsigned) (mv[1] + 1) <= 2)) { | |
| 988 | − if (iRef[LIST_0] == 0) { | |
| 989 | − ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], 0); | |
| 990 | − ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx + 4], 0); | |
| 991 | − ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0); | |
| 992 | − ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx + 4], 0); | |
| 993 | − ST64 (pMotionVector[LIST_0][iCacheIdx], 0); | |
| 994 | − ST64 (pMotionVector[LIST_0][iCacheIdx + 6], 0); | |
| 995 | − ST64 (pMvdCache[LIST_0][iCacheIdx], 0); | |
| 996 | − ST64 (pMvdCache[LIST_0][iCacheIdx + 6], 0); | |
| 997 | − } | |
| 998 | − | |
| 999 | − if (iRef[LIST_1] == 0) { | |
| 1000 | − ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], 0); | |
| 1001 | − ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx + 4], 0); | |
| 1002 | − ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0); | |
| 1003 | − ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx + 4], 0); | |
| 1004 | − ST64 (pMotionVector[LIST_1][iCacheIdx], 0); | |
| 1005 | − ST64 (pMotionVector[LIST_1][iCacheIdx + 6], 0); | |
| 1006 | − ST64 (pMvdCache[LIST_1][iCacheIdx], 0); | |
| 1007 | − ST64 (pMvdCache[LIST_1][iCacheIdx + 6], 0); | |
| 1008 | − } | |
| 1009 | − } | |
| 1010 | − } else { | |
| 1011 | − if (uiColZeroFlag && ((unsigned) (mv[0] + 1) <= 2 && (unsigned) (mv[1] + 1) <= 2)) { | |
| 1012 | − if (iRef[LIST_0] == 0) { | |
| 1013 | − ST32 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], 0); | |
| 1014 | − ST32 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0); | |
| 1015 | − ST32 (pMotionVector[LIST_0][iCacheIdx], 0); | |
| 1016 | − ST32 (pMvdCache[LIST_0][iCacheIdx], 0); | |
| 1017 | − } | |
| 1018 | − if (iRef[LIST_1] == 0) { | |
| 1019 | − ST32 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], 0); | |
| 1020 | − ST32 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0); | |
| 1021 | − ST32 (pMotionVector[LIST_1][iCacheIdx], 0); | |
| 1022 | − ST32 (pMvdCache[LIST_1][iCacheIdx], 0); | |
| 1023 | − } | |
| 1024 | − } | |
| 1025 | − } | |
| 1026 | − } | |
| 1027 | − } else { | |
| 1028 | − int16_t (*mvColoc)[2] = pCurDqLayer->iColocMv[LIST_0]; | |
| 1029 | − int16_t* mv = mvColoc[iColocIdx]; | |
| 1030 | − int16_t pMV[4] = { 0 }; | |
| 1031 | − int16_t iMvp[LIST_A][2]; | |
| 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; | |
| 1034 | − iMvp[LIST_0][1] = (pSlice->iMvScale[LIST_0][iRef[LIST_0]] * mv[1] + 128) >> 8; | |
| 1035 | − ST32 (pMV, LD32 (iMvp[LIST_0])); | |
| 1036 | − ST32 ((pMV + 2), LD32 (iMvp[LIST_0])); | |
| 1037 | − ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], LD64 (pMV)); | |
| 1038 | − ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx + 4], LD64 (pMV)); | |
| 1039 | − ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0); | |
| 1040 | − ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx + 4], 0); | |
| 1041 | − iMvp[LIST_1][0] -= iMvp[LIST_0][0] - mv[0]; | |
| 1042 | − iMvp[LIST_1][1] -= iMvp[LIST_0][0] - mv[1]; | |
| 1043 | − ST32 (pMV, LD32 (iMvp[LIST_1])); | |
| 1044 | − ST32 ((pMV + 2), LD32 (iMvp[LIST_1])); | |
| 1045 | − ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], LD64 (pMV)); | |
| 1046 | − ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx + 4], LD64 (pMV)); | |
| 1047 | − ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0); | |
| 1048 | − ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx + 4], 0); | |
| 1049 | − } else { //SUB_4x4 | |
| 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; | |
| 1052 | − ST32 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], LD32 (iMvp[LIST_0])); | |
| 1053 | − ST32 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0); | |
| 1054 | − iMvp[LIST_1][0] -= iMvp[LIST_0][0] - mv[0]; | |
| 1055 | − iMvp[LIST_1][1] -= iMvp[LIST_0][0] - mv[1]; | |
| 1056 | − ST32 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], LD32 (iMvp[LIST_1])); | |
| 1057 | − ST32 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0); | |
| 1058 | − } | |
| 1059 | − } | |
| 1060 | − } | |
| 1061 | − } | |
| 1062 | − } | |
| 1063 | − //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 } }; | |
| 1065 | − for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 1066 | − for (int32_t i = 0; i < 4; i++) { | |
| 1067 | − int16_t iIdx8 = i << 2; | |
| 1068 | − int32_t subMbType = pCurDqLayer->pSubMbType[iMbXy][i]; | |
| 1069 | − int8_t iref = REF_NOT_IN_LIST; | |
| 1070 | − if (IS_DIRECT (subMbType)) { | |
| 1071 | − if (pSliceHeader->iDirectSpatialMvPredFlag) { | |
| 1072 | − iref = iRef[listIdx]; | |
| 1073 | − } else { | |
| 1074 | − iref = 0; | |
| 1075 | − if (listIdx == LIST_0) { | |
| 1076 | − if (!pCurDqLayer->iColocIntra[g_kuiScan4[iIdx8]]) { | |
| 1077 | − if (pCurDqLayer->iColocRefIndex[LIST_0][iIdx8] >= 0) { | |
| 1078 | − iref = pCurDqLayer->iColocRefIndex[LIST_0][iIdx8]; | |
| 1079 | − } else { | |
| 1080 | − iref = pCurDqLayer->iColocRefIndex[LIST_1][iIdx8]; | |
| 1081 | − } | |
| 1082 | − } | |
| 1083 | − } | |
| 1084 | − } | |
| 1085 | − UpdateP8x8DirectCabac (pCurDqLayer, iIdx8); | |
| 1086 | − } else { | |
| 1087 | − if (IS_DIR (subMbType, 0, listIdx)) { | |
| 1088 | − WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, pDirect, listIdx, iIdx8, | |
| 1089 | − pRefCount[listIdx], 1, | |
| 1090 | − iref)); | |
| 1091 | − if ((iref < 0) || (iref >= pRefCount[listIdx]) || (pCtx->sRefPic.pRefList[listIdx][iref] == NULL)) { //error ref_idx | |
| 1092 | − pCtx->bMbRefConcealed = true; | |
| 1093 | − if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 1094 | − iref = 0; | |
| 1095 | − pCtx->iErrorCode |= dsBitstreamError; | |
| 1096 | − } else { | |
| 1097 | − return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX); | |
| 1098 | − } | |
| 1099 | − } | |
| 1100 | − pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (pCtx->sRefPic.pRefList[listIdx][iref] | |
| 1101 | − && pCtx->sRefPic.pRefList[listIdx][iref]->bIsComplete); | |
| 1102 | − } | |
| 1103 | − } | |
| 1104 | − UpdateP8x8RefIdxCabac (pCurDqLayer, pRefIndex, iIdx8, iref, listIdx); | |
| 1105 | − ref_idx_list[listIdx][i] = iref; | |
| 1106 | − } | |
| 1107 | − } | |
| 1108 | − //mv | |
| 1109 | − for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 1110 | − for (int32_t i = 0; i < 4; i++) { | |
| 1111 | − int8_t iPartCount = pSubPartCount[i]; | |
| 1112 | − int16_t iPartIdx, iBlockW = pPartW[i]; | |
| 1113 | − uint8_t iScan4Idx, iCacheIdx; | |
| 1114 | − | |
| 1115 | − iCacheIdx = g_kuiCache30ScanIdx[i << 2]; | |
| 1116 | − | |
| 1117 | − int8_t iref = ref_idx_list[listIdx][i]; | |
| 1118 | − pRefIndex[listIdx][iCacheIdx] = pRefIndex[listIdx][iCacheIdx + 1] | |
| 1119 | − = pRefIndex[listIdx][iCacheIdx + 6] = pRefIndex[listIdx][iCacheIdx + 7] = iref; | |
| 1120 | − | |
| 1121 | − uint32_t subMbType = pCurDqLayer->pSubMbType[iMbXy][i]; | |
| 1122 | − if (IS_DIRECT (subMbType)) { | |
| 1123 | − continue; | |
| 1124 | − } | |
| 1125 | − bool is_dir = IS_DIR (subMbType, 0, listIdx) > 0; | |
| 1126 | − for (int32_t j = 0; j < iPartCount; j++) { | |
| 1127 | − iPartIdx = (i << 2) + j * iBlockW; | |
| 1128 | − iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 1129 | − iCacheIdx = g_kuiCache30ScanIdx[iPartIdx]; | |
| 1130 | − if (is_dir) { | |
| 1131 | − PredMv (pMotionVector, pRefIndex, listIdx, iPartIdx, iBlockW, iref, pMv); | |
| 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])); | |
| 1134 | − pMv[0] += pMvd[0]; | |
| 1135 | − pMv[1] += pMvd[1]; | |
| 1136 | − WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv"); | |
| 1137 | − } else { | |
| 1138 | − * (uint32_t*)pMv = * (uint32_t*)pMvd = 0; | |
| 1139 | − } | |
| 1140 | − if (IS_SUB_8x8 (subMbType)) { //MB_TYPE_8x8 | |
| 1141 | − ST32 ((pMv + 2), LD32 (pMv)); | |
| 1142 | − ST32 ((pMvd + 2), LD32 (pMvd)); | |
| 1143 | − ST64 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx], LD64 (pMv)); | |
| 1144 | − ST64 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx + 4], LD64 (pMv)); | |
| 1145 | − ST64 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx], LD64 (pMvd)); | |
| 1146 | − ST64 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx + 4], LD64 (pMvd)); | |
| 1147 | − ST64 (pMotionVector[listIdx][iCacheIdx], LD64 (pMv)); | |
| 1148 | − ST64 (pMotionVector[listIdx][iCacheIdx + 6], LD64 (pMv)); | |
| 1149 | − ST64 (pMvdCache[listIdx][iCacheIdx], LD64 (pMvd)); | |
| 1150 | − ST64 (pMvdCache[listIdx][iCacheIdx + 6], LD64 (pMvd)); | |
| 1151 | − } else if (IS_SUB_4x4 (subMbType)) { //MB_TYPE_4x4 | |
| 1152 | − ST32 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx], LD32 (pMv)); | |
| 1153 | − ST32 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx], LD32 (pMvd)); | |
| 1154 | − ST32 (pMotionVector[listIdx][iCacheIdx], LD32 (pMv)); | |
| 1155 | − ST32 (pMvdCache[listIdx][iCacheIdx], LD32 (pMvd)); | |
| 1156 | − } else if (IS_SUB_4x8 (subMbType)) { //MB_TYPE_4x8 5, 7, 9 | |
| 1157 | − ST32 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx], LD32 (pMv)); | |
| 1158 | − ST32 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx + 4], LD32 (pMv)); | |
| 1159 | − ST32 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx], LD32 (pMvd)); | |
| 1160 | − ST32 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx + 4], LD32 (pMvd)); | |
| 1161 | − ST32 (pMotionVector[listIdx][iCacheIdx], LD32 (pMv)); | |
| 1162 | − ST32 (pMotionVector[listIdx][iCacheIdx + 6], LD32 (pMv)); | |
| 1163 | − ST32 (pMvdCache[listIdx][iCacheIdx], LD32 (pMvd)); | |
| 1164 | − ST32 (pMvdCache[listIdx][iCacheIdx + 6], LD32 (pMvd)); | |
| 1165 | − } else { //MB_TYPE_8x4 4, 6, 8 | |
| 1166 | − ST32 ((pMv + 2), LD32 (pMv)); | |
| 1167 | − ST32 ((pMvd + 2), LD32 (pMvd)); | |
| 1168 | − ST64 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx], LD64 (pMv)); | |
| 1169 | − ST64 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx], LD64 (pMvd)); | |
| 1170 | − ST64 (pMotionVector[listIdx][iCacheIdx], LD64 (pMv)); | |
| 1171 | − ST64 (pMvdCache[listIdx][iCacheIdx], LD64 (pMvd)); | |
| 1172 | − } | |
| 1173 | − } | |
| 1174 | − } | |
| 1175 | − } | |
| 1176 | − } | |
| 1177 | − return ERR_NONE; | |
| 1178 | −} | |
| 1179 | − | |
| 1180 | −int32_t ParseRefIdxCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint8_t* nzc, | |
| 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) { | |
| 1183 | − if (iActiveRefNum == 1) { | |
| 1184 | − iRefIdxVal = 0; | |
| 1185 | − return ERR_NONE; | |
| 1186 | − } | |
| 1187 | − uint32_t uiCode; | |
| 1188 | − int32_t iIdxA = 0, iIdxB = 0; | |
| 1189 | − int32_t iCtxInc = 0; | |
| 1190 | − int8_t* pRefIdxInMB = pCtx->pCurDqLayer->pRefIndex[iListIdx][pCtx->pCurDqLayer->iMbXyIndex]; | |
| 1191 | − int8_t* pDirect = pCtx->pCurDqLayer->pDirect[pCtx->pCurDqLayer->iMbXyIndex]; | |
| 1192 | − if (iZOrderIdx == 0) { | |
| 1193 | − iIdxB = (pNeighAvail->iTopAvail && pNeighAvail->iTopType != MB_TYPE_INTRA_PCM | |
| 1194 | − && ref_idx[iListIdx][g_kuiCache30ScanIdx[iZOrderIdx] - 6] > 0); | |
| 1195 | − iIdxA = (pNeighAvail->iLeftAvail && pNeighAvail->iLeftType != MB_TYPE_INTRA_PCM | |
| 1196 | − && ref_idx[iListIdx][g_kuiCache30ScanIdx[iZOrderIdx] - 1] > 0); | |
| 1197 | − if (pCtx->eSliceType == B_SLICE) { | |
| 1198 | − if (iIdxB > 0 && direct[g_kuiCache30ScanIdx[iZOrderIdx] - 6] == 0) { | |
| 1199 | − iCtxInc += 2; | |
| 1200 | − } | |
| 1201 | − if (iIdxA > 0 && direct[g_kuiCache30ScanIdx[iZOrderIdx] - 1] == 0) { | |
| 1202 | − iCtxInc++; | |
| 1203 | − } | |
| 1204 | − } | |
| 1205 | − } else if (iZOrderIdx == 4) { | |
| 1206 | − iIdxB = (pNeighAvail->iTopAvail && pNeighAvail->iTopType != MB_TYPE_INTRA_PCM | |
| 1207 | − && ref_idx[iListIdx][g_kuiCache30ScanIdx[iZOrderIdx] - 6] > 0); | |
| 1208 | − iIdxA = pRefIdxInMB[g_kuiScan4[iZOrderIdx] - 1] > 0; | |
| 1209 | − if (pCtx->eSliceType == B_SLICE) { | |
| 1210 | − if (iIdxB > 0 && direct[g_kuiCache30ScanIdx[iZOrderIdx] - 6] == 0) { | |
| 1211 | − iCtxInc += 2; | |
| 1212 | − } | |
| 1213 | − if (iIdxA > 0 && pDirect[g_kuiScan4[iZOrderIdx] - 1] == 0) { | |
| 1214 | − iCtxInc ++; | |
| 1215 | − } | |
| 1216 | − } | |
| 1217 | − } else if (iZOrderIdx == 8) { | |
| 1218 | − | |
| 1219 | − iIdxB = pRefIdxInMB[g_kuiScan4[iZOrderIdx] - 4] > 0; | |
| 1220 | − iIdxA = (pNeighAvail->iLeftAvail && pNeighAvail->iLeftType != MB_TYPE_INTRA_PCM | |
| 1221 | − && ref_idx[iListIdx][g_kuiCache30ScanIdx[iZOrderIdx] - 1] > 0); | |
| 1222 | − if (pCtx->eSliceType == B_SLICE) { | |
| 1223 | − if (iIdxB > 0 && pDirect[g_kuiScan4[iZOrderIdx] - 4] == 0) { | |
| 1224 | − iCtxInc += 2; | |
| 1225 | − } | |
| 1226 | − if (iIdxA > 0 && direct[g_kuiCache30ScanIdx[iZOrderIdx] - 1] == 0) { | |
| 1227 | − iCtxInc++; | |
| 1228 | − } | |
| 1229 | − } | |
| 1230 | − } else { | |
| 1231 | − iIdxB = pRefIdxInMB[g_kuiScan4[iZOrderIdx] - 4] > 0; | |
| 1232 | − iIdxA = pRefIdxInMB[g_kuiScan4[iZOrderIdx] - 1] > 0; | |
| 1233 | − if (pCtx->eSliceType == B_SLICE) { | |
| 1234 | − if (iIdxB > 0 && pDirect[g_kuiScan4[iZOrderIdx] - 4] == 0) { | |
| 1235 | − iCtxInc += 2; | |
| 1236 | − } | |
| 1237 | − if (iIdxA > 0 && pDirect[g_kuiScan4[iZOrderIdx] - 1] == 0) { | |
| 1238 | − iCtxInc++; | |
| 1239 | − } | |
| 1240 | − } | |
| 1241 | − } | |
| 1242 | − if (pCtx->eSliceType != B_SLICE) { | |
| 1243 | − iCtxInc = iIdxA + (iIdxB << 1); | |
| 1244 | − } | |
| 1245 | − | |
| 1246 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_REF_NO + iCtxInc, uiCode)); | |
| 1247 | − if (uiCode) { | |
| 1248 | − WELS_READ_VERIFY (DecodeUnaryBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_REF_NO + 4, 1, uiCode)); | |
| 1249 | − ++uiCode; | |
| 1250 | − } | |
| 1251 | − iRefIdxVal = (int8_t) uiCode; | |
| 1252 | − return ERR_NONE; | |
| 1253 | −} | |
| 1254 | − | |
| 1255 | −int32_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) { | |
| 1257 | − uint32_t uiCode; | |
| 1258 | − int32_t iIdxA = 0; | |
| 1259 | − //int32_t sym; | |
| 1260 | − PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_MVD + iMvComp * CTX_NUM_MVD; | |
| 1261 | − iMvdVal = 0; | |
| 1262 | − | |
| 1263 | − if (pRefIndex[iListIdx][g_kuiCache30ScanIdx[index] - 6] >= 0) | |
| 1264 | − iIdxA = WELS_ABS (pMvdCache[iListIdx][g_kuiCache30ScanIdx[index] - 6][iMvComp]); | |
| 1265 | − if (pRefIndex[iListIdx][g_kuiCache30ScanIdx[index] - 1] >= 0) | |
| 1266 | − iIdxA += WELS_ABS (pMvdCache[iListIdx][g_kuiCache30ScanIdx[index] - 1][iMvComp]); | |
| 1267 | − | |
| 1268 | − int32_t iCtxInc = 0; | |
| 1269 | − if (iIdxA >= 3) | |
| 1270 | − iCtxInc = 1 + (iIdxA > 32); | |
| 1271 | − | |
| 1272 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pBinCtx + iCtxInc, uiCode)); | |
| 1273 | − if (uiCode) { | |
| 1274 | − WELS_READ_VERIFY (DecodeUEGMvCabac (pCtx->pCabacDecEngine, pBinCtx + 3, 3, uiCode)); | |
| 1275 | − iMvdVal = (int16_t) (uiCode + 1); | |
| 1276 | − WELS_READ_VERIFY (DecodeBypassCabac (pCtx->pCabacDecEngine, uiCode)); | |
| 1277 | − if (uiCode) { | |
| 1278 | − iMvdVal = -iMvdVal; | |
| 1279 | − } | |
| 1280 | − } else { | |
| 1281 | − iMvdVal = 0; | |
| 1282 | − } | |
| 1283 | − return ERR_NONE; | |
| 1284 | −} | |
| 1285 | − | |
| 1286 | −int32_t ParseCbpInfoCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiCbp) { | |
| 1287 | − int32_t iIdxA = 0, iIdxB = 0, pALeftMb[2], pBTopMb[2]; | |
| 1288 | − uiCbp = 0; | |
| 1289 | − uint32_t pCbpBit[6]; | |
| 1290 | − int32_t iCtxInc; | |
| 1291 | − | |
| 1292 | − //Luma: bit by bit for 4 8x8 blocks in z-order | |
| 1293 | − pBTopMb[0] = pNeighAvail->iTopAvail && pNeighAvail->iTopType != MB_TYPE_INTRA_PCM | |
| 1294 | − && ((pNeighAvail->iTopCbp & (1 << 2)) == 0); | |
| 1295 | − pBTopMb[1] = pNeighAvail->iTopAvail && pNeighAvail->iTopType != MB_TYPE_INTRA_PCM | |
| 1296 | − && ((pNeighAvail->iTopCbp & (1 << 3)) == 0); | |
| 1297 | − pALeftMb[0] = pNeighAvail->iLeftAvail && pNeighAvail->iLeftType != MB_TYPE_INTRA_PCM | |
| 1298 | − && ((pNeighAvail->iLeftCbp & (1 << 1)) == 0); | |
| 1299 | − pALeftMb[1] = pNeighAvail->iLeftAvail && pNeighAvail->iLeftType != MB_TYPE_INTRA_PCM | |
| 1300 | − && ((pNeighAvail->iLeftCbp & (1 << 3)) == 0); | |
| 1301 | − | |
| 1302 | − //left_top 8x8 block | |
| 1303 | − iCtxInc = pALeftMb[0] + (pBTopMb[0] << 1); | |
| 1304 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + iCtxInc, pCbpBit[0])); | |
| 1305 | − if (pCbpBit[0]) | |
| 1306 | − uiCbp += 0x01; | |
| 1307 | − | |
| 1308 | − //right_top 8x8 block | |
| 1309 | − iIdxA = !pCbpBit[0]; | |
| 1310 | − iCtxInc = iIdxA + (pBTopMb[1] << 1); | |
| 1311 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + iCtxInc, pCbpBit[1])); | |
| 1312 | − if (pCbpBit[1]) | |
| 1313 | − uiCbp += 0x02; | |
| 1314 | − | |
| 1315 | − //left_bottom 8x8 block | |
| 1316 | − iIdxB = !pCbpBit[0]; | |
| 1317 | − iCtxInc = pALeftMb[1] + (iIdxB << 1); | |
| 1318 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + iCtxInc, pCbpBit[2])); | |
| 1319 | − if (pCbpBit[2]) | |
| 1320 | − uiCbp += 0x04; | |
| 1321 | − | |
| 1322 | − //right_bottom 8x8 block | |
| 1323 | − iIdxB = !pCbpBit[1]; | |
| 1324 | − iIdxA = !pCbpBit[2]; | |
| 1325 | − iCtxInc = iIdxA + (iIdxB << 1); | |
| 1326 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + iCtxInc, pCbpBit[3])); | |
| 1327 | − if (pCbpBit[3]) | |
| 1328 | − uiCbp += 0x08; | |
| 1329 | − | |
| 1330 | − if (pCtx->pSps->uiChromaFormatIdc == 0)//monochroma | |
| 1331 | − return ERR_NONE; | |
| 1332 | − | |
| 1333 | − | |
| 1334 | − //Chroma: bit by bit | |
| 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)); | |
| 1337 | − | |
| 1338 | − //BitIdx = 0 | |
| 1339 | − iCtxInc = iIdxA + (iIdxB << 1); | |
| 1340 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + CTX_NUM_CBP + iCtxInc, | |
| 1341 | − pCbpBit[4])); | |
| 1342 | − | |
| 1343 | − //BitIdx = 1 | |
| 1344 | − if (pCbpBit[4]) { | |
| 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); | |
| 1347 | − iCtxInc = iIdxA + (iIdxB << 1); | |
| 1348 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, | |
| 1349 | − pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + 2 * CTX_NUM_CBP + iCtxInc, | |
| 1350 | − pCbpBit[5])); | |
| 1351 | − uiCbp += 1 << (4 + pCbpBit[5]); | |
| 1352 | − | |
| 1353 | − } | |
| 1354 | − | |
| 1355 | − return ERR_NONE; | |
| 1356 | −} | |
| 1357 | − | |
| 1358 | −int32_t ParseDeltaQpCabac (PWelsDecoderContext pCtx, int32_t& iQpDelta) { | |
| 1359 | − uint32_t uiCode; | |
| 1360 | − PSlice pCurrSlice = & (pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer); | |
| 1361 | − iQpDelta = 0; | |
| 1362 | − PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_DELTA_QP; | |
| 1363 | − int32_t iCtxInc = (pCurrSlice->iLastDeltaQp != 0); | |
| 1364 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pBinCtx + iCtxInc, uiCode)); | |
| 1365 | − if (uiCode != 0) { | |
| 1366 | − WELS_READ_VERIFY (DecodeUnaryBinCabac (pCtx->pCabacDecEngine, pBinCtx + 2, 1, uiCode)); | |
| 1367 | − uiCode++; | |
| 1368 | − iQpDelta = (uiCode + 1) >> 1; | |
| 1369 | − if ((uiCode & 1) == 0) | |
| 1370 | − iQpDelta = - iQpDelta; | |
| 1371 | − } | |
| 1372 | − pCurrSlice->iLastDeltaQp = iQpDelta; | |
| 1373 | − return ERR_NONE; | |
| 1374 | −} | |
| 1375 | − | |
| 1376 | −int32_t ParseCbfInfoCabac (PWelsNeighAvail pNeighAvail, uint8_t* pNzcCache, int32_t iZIndex, int32_t iResProperty, | |
| 1377 | − PWelsDecoderContext pCtx, uint32_t& uiCbfBit) { | |
| 1378 | − int8_t nA, nB/*, zigzag_idx = 0*/; | |
| 1379 | − int32_t iCurrBlkXy = pCtx->pCurDqLayer->iMbXyIndex; | |
| 1380 | − int32_t iTopBlkXy = iCurrBlkXy - pCtx->pCurDqLayer->iMbWidth; //default value: MB neighboring | |
| 1381 | − int32_t iLeftBlkXy = iCurrBlkXy - 1; //default value: MB neighboring | |
| 1382 | − uint16_t* pCbfDc = pCtx->pCurDqLayer->pCbfDc; | |
| 1383 | − uint32_t* pMbType = pCtx->pCurDqLayer->pMbType; | |
| 1384 | − int32_t iCtxInc; | |
| 1385 | − uiCbfBit = 0; | |
| 1386 | − nA = nB = (int8_t)!!IS_INTRA (pMbType[iCurrBlkXy]); | |
| 1387 | − | |
| 1388 | − if (iResProperty == I16_LUMA_DC || iResProperty == CHROMA_DC_U || iResProperty == CHROMA_DC_V) { //DC | |
| 1389 | − if (pNeighAvail->iTopAvail) | |
| 1390 | − nB = (pMbType[iTopBlkXy] == MB_TYPE_INTRA_PCM) || ((pCbfDc[iTopBlkXy] >> iResProperty) & 1); | |
| 1391 | − if (pNeighAvail->iLeftAvail) | |
| 1392 | − nA = (pMbType[iLeftBlkXy] == MB_TYPE_INTRA_PCM) || ((pCbfDc[iLeftBlkXy] >> iResProperty) & 1); | |
| 1393 | − iCtxInc = nA + (nB << 1); | |
| 1394 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, | |
| 1395 | − pCtx->pCabacCtx + NEW_CTX_OFFSET_CBF + g_kBlockCat2CtxOffsetCBF[iResProperty] + iCtxInc, uiCbfBit)); | |
| 1396 | − if (uiCbfBit) | |
| 1397 | − pCbfDc[iCurrBlkXy] |= (1 << iResProperty); | |
| 1398 | − } else { //AC | |
| 1399 | − //for 4x4 blk, make sure blk-idx is correct | |
| 1400 | − if (pNzcCache[g_kCacheNzcScanIdx[iZIndex] - 8] != 0xff) { //top blk available | |
| 1401 | − if (g_kTopBlkInsideMb[iZIndex]) | |
| 1402 | − iTopBlkXy = iCurrBlkXy; | |
| 1403 | − nB = pNzcCache[g_kCacheNzcScanIdx[iZIndex] - 8] || pMbType[iTopBlkXy] == MB_TYPE_INTRA_PCM; | |
| 1404 | − } | |
| 1405 | − if (pNzcCache[g_kCacheNzcScanIdx[iZIndex] - 1] != 0xff) { //left blk available | |
| 1406 | − if (g_kLeftBlkInsideMb[iZIndex]) | |
| 1407 | − iLeftBlkXy = iCurrBlkXy; | |
| 1408 | − nA = pNzcCache[g_kCacheNzcScanIdx[iZIndex] - 1] || pMbType[iLeftBlkXy] == MB_TYPE_INTRA_PCM; | |
| 1409 | − } | |
| 1410 | − | |
| 1411 | − iCtxInc = nA + (nB << 1); | |
| 1412 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, | |
| 1413 | − pCtx->pCabacCtx + NEW_CTX_OFFSET_CBF + g_kBlockCat2CtxOffsetCBF[iResProperty] + iCtxInc, uiCbfBit)); | |
| 1414 | − } | |
| 1415 | − return ERR_NONE; | |
| 1416 | −} | |
| 1417 | − | |
| 1418 | −int32_t ParseSignificantMapCabac (int32_t* pSignificantMap, int32_t iResProperty, PWelsDecoderContext pCtx, | |
| 1419 | − uint32_t& uiCoeffNum) { | |
| 1420 | − uint32_t uiCode; | |
| 1421 | − | |
| 1422 | − PWelsCabacCtx pMapCtx = pCtx->pCabacCtx + (iResProperty == LUMA_DC_AC_8 ? NEW_CTX_OFFSET_MAP_8x8 : NEW_CTX_OFFSET_MAP) | |
| 1423 | − + g_kBlockCat2CtxOffsetMap [iResProperty]; | |
| 1424 | − PWelsCabacCtx pLastCtx = pCtx->pCabacCtx + (iResProperty == LUMA_DC_AC_8 ? NEW_CTX_OFFSET_LAST_8x8 : | |
| 1425 | − NEW_CTX_OFFSET_LAST) + g_kBlockCat2CtxOffsetLast[iResProperty]; | |
| 1426 | − | |
| 1427 | − | |
| 1428 | − int32_t i; | |
| 1429 | − uiCoeffNum = 0; | |
| 1430 | − int32_t i0 = 0; | |
| 1431 | − int32_t i1 = g_kMaxPos[iResProperty]; | |
| 1432 | − | |
| 1433 | − int32_t iCtx; | |
| 1434 | − | |
| 1435 | − for (i = i0; i < i1; ++i) { | |
| 1436 | − iCtx = (iResProperty == LUMA_DC_AC_8 ? g_kuiIdx2CtxSignificantCoeffFlag8x8[i] : i); | |
| 1437 | − //read significant | |
| 1438 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pMapCtx + iCtx, uiCode)); | |
| 1439 | − if (uiCode) { | |
| 1440 | − * (pSignificantMap++) = 1; | |
| 1441 | − ++ uiCoeffNum; | |
| 1442 | − //read last significant | |
| 1443 | − iCtx = (iResProperty == LUMA_DC_AC_8 ? g_kuiIdx2CtxLastSignificantCoeffFlag8x8[i] : i); | |
| 1444 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pLastCtx + iCtx, uiCode)); | |
| 1445 | − if (uiCode) { | |
| 1446 | − memset (pSignificantMap, 0, (i1 - i) * sizeof (int32_t)); | |
| 1447 | − return ERR_NONE; | |
| 1448 | − } | |
| 1449 | − } else | |
| 1450 | − * (pSignificantMap++) = 0; | |
| 1451 | − } | |
| 1452 | − | |
| 1453 | − //deal with last pSignificantMap if no data | |
| 1454 | − //if(i < i1+1) | |
| 1455 | − { | |
| 1456 | − *pSignificantMap = 1; | |
| 1457 | − ++uiCoeffNum; | |
| 1458 | − } | |
| 1459 | − | |
| 1460 | − return ERR_NONE; | |
| 1461 | −} | |
| 1462 | − | |
| 1463 | −int32_t ParseSignificantCoeffCabac (int32_t* pSignificant, int32_t iResProperty, PWelsDecoderContext pCtx) { | |
| 1464 | − uint32_t uiCode; | |
| 1465 | − PWelsCabacCtx pOneCtx = pCtx->pCabacCtx + (iResProperty == LUMA_DC_AC_8 ? NEW_CTX_OFFSET_ONE_8x8 : NEW_CTX_OFFSET_ONE) + | |
| 1466 | − g_kBlockCat2CtxOffsetOne[iResProperty]; | |
| 1467 | − PWelsCabacCtx pAbsCtx = pCtx->pCabacCtx + (iResProperty == LUMA_DC_AC_8 ? NEW_CTX_OFFSET_ABS_8x8 : NEW_CTX_OFFSET_ABS) + | |
| 1468 | − g_kBlockCat2CtxOffsetAbs[iResProperty]; | |
| 1469 | − | |
| 1470 | − const int16_t iMaxType = g_kMaxC2[iResProperty]; | |
| 1471 | − int32_t i = g_kMaxPos[iResProperty]; | |
| 1472 | − int32_t* pCoff = pSignificant + i; | |
| 1473 | − int32_t c1 = 1; | |
| 1474 | − int32_t c2 = 0; | |
| 1475 | − for (; i >= 0; --i) { | |
| 1476 | − if (*pCoff != 0) { | |
| 1477 | − WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pOneCtx + c1, uiCode)); | |
| 1478 | − *pCoff += uiCode; | |
| 1479 | − if (*pCoff == 2) { | |
| 1480 | − WELS_READ_VERIFY (DecodeUEGLevelCabac (pCtx->pCabacDecEngine, pAbsCtx + c2, uiCode)); | |
| 1481 | − *pCoff += uiCode; | |
| 1482 | − ++c2; | |
| 1483 | − c2 = WELS_MIN (c2, iMaxType); | |
| 1484 | − c1 = 0; | |
| 1485 | − } else if (c1) { | |
| 1486 | − ++c1; | |
| 1487 | − c1 = WELS_MIN (c1, 4); | |
| 1488 | − } | |
| 1489 | − WELS_READ_VERIFY (DecodeBypassCabac (pCtx->pCabacDecEngine, uiCode)); | |
| 1490 | − if (uiCode) | |
| 1491 | − *pCoff = - *pCoff; | |
| 1492 | − } | |
| 1493 | − pCoff--; | |
| 1494 | − } | |
| 1495 | − return ERR_NONE; | |
| 1496 | −} | |
| 1497 | − | |
| 1498 | −int32_t ParseResidualBlockCabac8x8 (PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCountCache, SBitStringAux* pBsAux, | |
| 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) { | |
| 1501 | − uint32_t uiTotalCoeffNum = 0; | |
| 1502 | − uint32_t uiCbpBit; | |
| 1503 | − int32_t pSignificantMap[64] = {0}; | |
| 1504 | − | |
| 1505 | − int32_t iMbResProperty = 0; | |
| 1506 | − GetMbResProperty (&iMbResProperty, &iResProperty, false); | |
| 1507 | − const uint16_t* pDeQuantMul = (pCtx->bUseScalingList) ? pCtx->pDequant_coeff8x8[iMbResProperty - 6][uiQp] : | |
| 1508 | − g_kuiDequantCoeff8x8[uiQp]; | |
| 1509 | − | |
| 1510 | − uiCbpBit = 1; // for 8x8, MaxNumCoeff == 64 && uiCbpBit == 1 | |
| 1511 | − if (uiCbpBit) { //has coeff | |
| 1512 | − WELS_READ_VERIFY (ParseSignificantMapCabac (pSignificantMap, iResProperty, pCtx, uiTotalCoeffNum)); | |
| 1513 | − WELS_READ_VERIFY (ParseSignificantCoeffCabac (pSignificantMap, iResProperty, pCtx)); | |
| 1514 | − } | |
| 1515 | − | |
| 1516 | − pNonZeroCountCache[g_kCacheNzcScanIdx[iIndex]] = | |
| 1517 | − pNonZeroCountCache[g_kCacheNzcScanIdx[iIndex + 1]] = | |
| 1518 | − pNonZeroCountCache[g_kCacheNzcScanIdx[iIndex + 2]] = | |
| 1519 | − pNonZeroCountCache[g_kCacheNzcScanIdx[iIndex + 3]] = (uint8_t)uiTotalCoeffNum; | |
| 1520 | − if (uiTotalCoeffNum == 0) { | |
| 1521 | − return ERR_NONE; | |
| 1522 | − } | |
| 1523 | − int32_t j = 0, i; | |
| 1524 | − if (iResProperty == LUMA_DC_AC_8) { | |
| 1525 | − do { | |
| 1526 | − if (pSignificantMap[j] != 0) { | |
| 1527 | − i = pScanTable[ j ]; | |
| 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)); | |
| 1530 | − } | |
| 1531 | − ++j; | |
| 1532 | − } while (j < 64); | |
| 1533 | − } | |
| 1534 | − | |
| 1535 | − return ERR_NONE; | |
| 1536 | −} | |
| 1537 | − | |
| 1538 | −int32_t ParseResidualBlockCabac (PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCountCache, SBitStringAux* pBsAux, | |
| 1539 | − int32_t iIndex, int32_t iMaxNumCoeff, | |
| 1540 | − const uint8_t* pScanTable, int32_t iResProperty, short* sTCoeff, /*int mb_mode*/ uint8_t uiQp, | |
| 1541 | − PWelsDecoderContext pCtx) { | |
| 1542 | − int32_t iCurNzCacheIdx; | |
| 1543 | − uint32_t uiTotalCoeffNum = 0; | |
| 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}; | |
| 1546 | − | |
| 1547 | − int32_t iMbResProperty = 0; | |
| 1548 | − GetMbResProperty (&iMbResProperty, &iResProperty, false); | |
| 1549 | − const uint16_t* pDeQuantMul = (pCtx->bUseScalingList) ? pCtx->pDequant_coeff4x4[iMbResProperty][uiQp] : | |
| 1550 | − g_kuiDequantCoeff[uiQp]; | |
| 1551 | − | |
| 1552 | − WELS_READ_VERIFY (ParseCbfInfoCabac (pNeighAvail, pNonZeroCountCache, iIndex, iResProperty, pCtx, uiCbpBit)); | |
| 1553 | − if (uiCbpBit) { //has coeff | |
| 1554 | − WELS_READ_VERIFY (ParseSignificantMapCabac (pSignificantMap, iResProperty, pCtx, uiTotalCoeffNum)); | |
| 1555 | − WELS_READ_VERIFY (ParseSignificantCoeffCabac (pSignificantMap, iResProperty, pCtx)); | |
| 1556 | − } | |
| 1557 | − | |
| 1558 | − iCurNzCacheIdx = g_kCacheNzcScanIdx[iIndex]; | |
| 1559 | − pNonZeroCountCache[iCurNzCacheIdx] = (uint8_t)uiTotalCoeffNum; | |
| 1560 | − if (uiTotalCoeffNum == 0) { | |
| 1561 | − return ERR_NONE; | |
| 1562 | − } | |
| 1563 | − int32_t j = 0; | |
| 1564 | − if (iResProperty == I16_LUMA_DC) { | |
| 1565 | − do { | |
| 1566 | − sTCoeff[pScanTable[j]] = pSignificantMap[j]; | |
| 1567 | − ++j; | |
| 1568 | − } while (j < 16); | |
| 1569 | − WelsLumaDcDequantIdct (sTCoeff, uiQp, pCtx); | |
| 1570 | − } else if (iResProperty == CHROMA_DC_U || iResProperty == CHROMA_DC_V) { | |
| 1571 | − do { | |
| 1572 | − sTCoeff[pScanTable[j]] = pSignificantMap[j]; | |
| 1573 | − ++j; | |
| 1574 | − } while (j < 4); | |
| 1575 | − //iHadamard2x2 | |
| 1576 | − WelsChromaDcIdct (sTCoeff); | |
| 1577 | − //scaling | |
| 1578 | − if (!pCtx->bUseScalingList) { | |
| 1579 | − for (j = 0; j < 4; ++j) { | |
| 1580 | − sTCoeff[pScanTable[j]] = (int16_t) ((int64_t)sTCoeff[pScanTable[j]] * (int64_t)pDeQuantMul[0] >> 1); | |
| 1581 | − } | |
| 1582 | − } else { //with scaling list | |
| 1583 | − for (j = 0; j < 4; ++j) { | |
| 1584 | − sTCoeff[pScanTable[j]] = (int16_t) ((int64_t)sTCoeff[pScanTable[j]] * (int64_t)pDeQuantMul[0] >> 5); | |
| 1585 | − } | |
| 1586 | − } | |
| 1587 | − } else { //luma ac, chroma ac | |
| 1588 | − do { | |
| 1589 | − if (pSignificantMap[j] != 0) { | |
| 1590 | − if (!pCtx->bUseScalingList) { | |
| 1591 | − sTCoeff[pScanTable[j]] = pSignificantMap[j] * pDeQuantMul[pScanTable[j] & 0x07]; | |
| 1592 | − } else { | |
| 1593 | − sTCoeff[pScanTable[j]] = (int16_t) (((int64_t)pSignificantMap[j] * (int64_t)pDeQuantMul[pScanTable[j]] + 8) >> 4); | |
| 1594 | − } | |
| 1595 | − } | |
| 1596 | − ++j; | |
| 1597 | − } while (j < 16); | |
| 1598 | − } | |
| 1599 | − return ERR_NONE; | |
| 1600 | −} | |
| 1601 | − | |
| 1602 | −int32_t ParseIPCMInfoCabac (PWelsDecoderContext pCtx) { | |
| 1603 | − int32_t i; | |
| 1604 | − PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine; | |
| 1605 | − SBitStringAux* pBsAux = pCtx->pCurDqLayer->pBitStringAux; | |
| 1606 | − SDqLayer* pCurLayer = pCtx->pCurDqLayer; | |
| 1607 | − int32_t iDstStrideLuma = pCurLayer->pDec->iLinesize[0]; | |
| 1608 | − int32_t iDstStrideChroma = pCurLayer->pDec->iLinesize[1]; | |
| 1609 | − int32_t iMbX = pCurLayer->iMbX; | |
| 1610 | − int32_t iMbY = pCurLayer->iMbY; | |
| 1611 | − int32_t iMbXy = pCurLayer->iMbXyIndex; | |
| 1612 | − | |
| 1613 | − int32_t iMbOffsetLuma = (iMbX + iMbY * iDstStrideLuma) << 4; | |
| 1614 | − int32_t iMbOffsetChroma = (iMbX + iMbY * iDstStrideChroma) << 3; | |
| 1615 | − | |
| 1616 | − uint8_t* pMbDstY = pCtx->pDec->pData[0] + iMbOffsetLuma; | |
| 1617 | − uint8_t* pMbDstU = pCtx->pDec->pData[1] + iMbOffsetChroma; | |
| 1618 | − uint8_t* pMbDstV = pCtx->pDec->pData[2] + iMbOffsetChroma; | |
| 1619 | − | |
| 1620 | − uint8_t* pPtrSrc; | |
| 1621 | − | |
| 1622 | − pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA_PCM; | |
| 1623 | − RestoreCabacDecEngineToBS (pCabacDecEngine, pBsAux); | |
| 1624 | − intX_t iBytesLeft = pBsAux->pEndBuf - pBsAux->pCurBuf; | |
| 1625 | − if (iBytesLeft < 384) { | |
| 1626 | − return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_CABAC_NO_BS_TO_READ); | |
| 1627 | − } | |
| 1628 | − pPtrSrc = pBsAux->pCurBuf; | |
| 1629 | − if (!pCtx->pParam->bParseOnly) { | |
| 1630 | − for (i = 0; i < 16; i++) { //luma | |
| 1631 | − memcpy (pMbDstY, pPtrSrc, 16); | |
| 1632 | − pMbDstY += iDstStrideLuma; | |
| 1633 | − pPtrSrc += 16; | |
| 1634 | − } | |
| 1635 | − for (i = 0; i < 8; i++) { //cb | |
| 1636 | − memcpy (pMbDstU, pPtrSrc, 8); | |
| 1637 | − pMbDstU += iDstStrideChroma; | |
| 1638 | − pPtrSrc += 8; | |
| 1639 | − } | |
| 1640 | − for (i = 0; i < 8; i++) { //cr | |
| 1641 | − memcpy (pMbDstV, pPtrSrc, 8); | |
| 1642 | − pMbDstV += iDstStrideChroma; | |
| 1643 | − pPtrSrc += 8; | |
| 1644 | − } | |
| 1645 | − } | |
| 1646 | − | |
| 1647 | − pBsAux->pCurBuf += 384; | |
| 1648 | − | |
| 1649 | − pCurLayer->pLumaQp[iMbXy] = 0; | |
| 1650 | − pCurLayer->pChromaQp[iMbXy][0] = pCurLayer->pChromaQp[iMbXy][1] = 0; | |
| 1651 | − memset (pCurLayer->pNzc[iMbXy], 16, sizeof (pCurLayer->pNzc[iMbXy])); | |
| 1652 | − | |
| 1653 | − //step 4: cabac engine init | |
| 1654 | − WELS_READ_VERIFY (InitReadBits (pBsAux, 1)); | |
| 1655 | − WELS_READ_VERIFY (InitCabacDecEngineFromBS (pCabacDecEngine, pBsAux)); | |
| 1656 | − return ERR_NONE; | |
| 1657 | −} | |
| 1658 | −} | |
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 2013, Cisco Systems | |
| 4 | + * All rights reserved. | |
| 5 | + * | |
| 6 | + * Redistribution and use in source and binary forms, with or without | |
| 7 | + * modification, are permitted provided that the following conditions | |
| 8 | + * are met: | |
| 9 | + * | |
| 10 | + * * Redistributions of source code must retain the above copyright | |
| 11 | + * notice, this list of conditions and the following disclaimer. | |
| 12 | + * | |
| 13 | + * * Redistributions in binary form must reproduce the above copyright | |
| 14 | + * notice, this list of conditions and the following disclaimer in | |
| 15 | + * the documentation and/or other materials provided with the | |
| 16 | + * distribution. | |
| 17 | + * | |
| 18 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 21 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 22 | + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 23 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 26 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
| 28 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | + * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | + * | |
| 31 | + * parse_mb_syn_cabac.cpp: cabac parse for syntax elements | |
| 32 | + */ | |
| 33 | +#include "parse_mb_syn_cabac.h" | |
| 34 | +#include "decode_slice.h" | |
| 35 | +#include "mv_pred.h" | |
| 36 | +#include "error_code.h" | |
| 37 | +#include <stdio.h> | |
| 38 | +namespace WelsDec { | |
| 39 | +#define IDX_UNUSED -1 | |
| 40 | + | |
| 41 | +static const int16_t g_kMaxPos [] = {IDX_UNUSED, 15, 14, 15, 3, 14, 63, 3, 3, 14, 14}; | |
| 42 | +static const int16_t g_kMaxC2 [] = {IDX_UNUSED, 4, 4, 4, 3, 4, 4, 3, 3, 4, 4}; | |
| 43 | +static const int16_t g_kBlockCat2CtxOffsetCBF[] = {IDX_UNUSED, 0, 4, 8, 12, 16, 0, 12, 12, 16, 16}; | |
| 44 | +static const int16_t g_kBlockCat2CtxOffsetMap [] = {IDX_UNUSED, 0, 15, 29, 44, 47, 0, 44, 44, 47, 47}; | |
| 45 | +static const int16_t g_kBlockCat2CtxOffsetLast[] = {IDX_UNUSED, 0, 15, 29, 44, 47, 0, 44, 44, 47, 47}; | |
| 46 | +static const int16_t g_kBlockCat2CtxOffsetOne [] = {IDX_UNUSED, 0, 10, 20, 30, 39, 0, 30, 30, 39, 39}; | |
| 47 | +static const int16_t g_kBlockCat2CtxOffsetAbs [] = {IDX_UNUSED, 0, 10, 20, 30, 39, 0, 30, 30, 39, 39}; | |
| 48 | + | |
| 49 | +const uint8_t g_kTopBlkInsideMb[24] = { //for index with z-order 0~23 | |
| 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 3 | |
| 52 | + 0, 0, 1, 1, //--------------- --------- 4 5 6 7 | |
| 53 | + 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 15 | |
| 55 | + 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 23 | |
| 57 | + // 18 19 | 22 23 | |
| 58 | +}; | |
| 59 | + | |
| 60 | +const uint8_t g_kLeftBlkInsideMb[24] = { //for index with z-order 0~23 | |
| 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 3 | |
| 63 | + 1, 1, 1, 1, //--------------- --------- 4 5 6 7 | |
| 64 | + 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 15 | |
| 66 | + 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 23 | |
| 68 | + // 18 19 | 22 23 | |
| 69 | +}; | |
| 70 | + | |
| 71 | +static uint32_t DecodeCabacIntraMbType (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, int ctx_base) { | |
| 72 | + uint32_t uiCode; | |
| 73 | + uint32_t uiMbType = 0; | |
| 74 | + | |
| 75 | + PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine; | |
| 76 | + PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + ctx_base; | |
| 77 | + | |
| 78 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx, uiCode)); | |
| 79 | + if (!uiCode) { | |
| 80 | + return 0; /* I4x4 */ | |
| 81 | + } | |
| 82 | + | |
| 83 | + DecodeTerminateCabac (pCabacDecEngine, uiCode); | |
| 84 | + if (uiCode) { | |
| 85 | + return 25; /* PCM */ | |
| 86 | + } | |
| 87 | + uiMbType = 1; /* I16x16 */ | |
| 88 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 1, uiCode)); /* cbp_luma != 0 */ | |
| 89 | + uiMbType += 12 * uiCode; | |
| 90 | + | |
| 91 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 2, uiCode)); | |
| 92 | + if (uiCode) { | |
| 93 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 2, uiCode)); | |
| 94 | + uiMbType += 4 + 4 * uiCode; | |
| 95 | + } | |
| 96 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 97 | + uiMbType += 2 * uiCode; | |
| 98 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 99 | + uiMbType += 1 * uiCode; | |
| 100 | + return uiMbType; | |
| 101 | +} | |
| 102 | + | |
| 103 | +void UpdateP16x8RefIdxCabac (PDqLayer pCurDqLayer, int8_t pRefIndex[LIST_A][30], int32_t iPartIdx, const int8_t iRef, | |
| 104 | + const int8_t iListIdx) { | |
| 105 | + uint32_t iRef32Bit = (uint32_t) iRef; | |
| 106 | + const int32_t iRef4Bytes = (iRef32Bit << 24) | (iRef32Bit << 16) | (iRef32Bit << 8) | iRef32Bit; | |
| 107 | + int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 108 | + const uint8_t iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 109 | + const uint8_t iScan4Idx4 = 4 + iScan4Idx; | |
| 110 | + const uint8_t iCacheIdx = g_kuiCache30ScanIdx[iPartIdx]; | |
| 111 | + const uint8_t iCacheIdx6 = 6 + iCacheIdx; | |
| 112 | + //mb | |
| 113 | + ST32 (&pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx ], iRef4Bytes); | |
| 114 | + ST32 (&pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx4], iRef4Bytes); | |
| 115 | + //cache | |
| 116 | + ST32 (&pRefIndex[iListIdx][iCacheIdx ], iRef4Bytes); | |
| 117 | + ST32 (&pRefIndex[iListIdx][iCacheIdx6], iRef4Bytes); | |
| 118 | +} | |
| 119 | + | |
| 120 | +void UpdateP8x16RefIdxCabac (PDqLayer pCurDqLayer, int8_t pRefIndex[LIST_A][30], int32_t iPartIdx, const int8_t iRef, | |
| 121 | + const int8_t iListIdx) { | |
| 122 | + uint16_t iRef16Bit = (uint16_t) iRef; | |
| 123 | + const int16_t iRef2Bytes = (iRef16Bit << 8) | iRef16Bit; | |
| 124 | + int32_t i; | |
| 125 | + int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 126 | + for (i = 0; i < 2; i++, iPartIdx += 8) { | |
| 127 | + const uint8_t iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 128 | + const uint8_t iCacheIdx = g_kuiCache30ScanIdx[iPartIdx]; | |
| 129 | + const uint8_t iScan4Idx4 = 4 + iScan4Idx; | |
| 130 | + const uint8_t iCacheIdx6 = 6 + iCacheIdx; | |
| 131 | + //mb | |
| 132 | + ST16 (&pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx ], iRef2Bytes); | |
| 133 | + ST16 (&pCurDqLayer->pRefIndex[iListIdx][iMbXy][iScan4Idx4], iRef2Bytes); | |
| 134 | + //cache | |
| 135 | + ST16 (&pRefIndex[iListIdx][iCacheIdx ], iRef2Bytes); | |
| 136 | + ST16 (&pRefIndex[iListIdx][iCacheIdx6], iRef2Bytes); | |
| 137 | + } | |
| 138 | +} | |
| 139 | + | |
| 140 | +void UpdateP8x8RefIdxCabac (PDqLayer pCurDqLayer, int8_t pRefIndex[LIST_A][30], int32_t iPartIdx, const int8_t iRef, | |
| 141 | + const int8_t iListIdx) { | |
| 142 | + int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 143 | + const uint8_t iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 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; | |
| 146 | +} | |
| 147 | + | |
| 148 | +void UpdateP8x8DirectCabac (PDqLayer pCurDqLayer, int32_t iPartIdx) { | |
| 149 | + int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 150 | + const uint8_t iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 151 | + pCurDqLayer->pDirect[iMbXy][iScan4Idx] = pCurDqLayer->pDirect[iMbXy][iScan4Idx + 1] = | |
| 152 | + pCurDqLayer->pDirect[iMbXy][iScan4Idx + 4] = pCurDqLayer->pDirect[iMbXy][iScan4Idx + 5] = 1; | |
| 153 | +} | |
| 154 | + | |
| 155 | +void UpdateP16x16DirectCabac (PDqLayer pCurDqLayer) { | |
| 156 | + int32_t i; | |
| 157 | + int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 158 | + const int16_t direct = (1 << 8) | 1; | |
| 159 | + for (i = 0; i < 16; i += 4) { | |
| 160 | + const uint8_t kuiScan4Idx = g_kuiScan4[i]; | |
| 161 | + const uint8_t kuiScan4IdxPlus4 = 4 + kuiScan4Idx; | |
| 162 | + ST16 (&pCurDqLayer->pDirect[iMbXy][kuiScan4Idx], direct); | |
| 163 | + ST16 (&pCurDqLayer->pDirect[iMbXy][kuiScan4IdxPlus4], direct); | |
| 164 | + } | |
| 165 | +} | |
| 166 | + | |
| 167 | +void UpdateP16x16MvdCabac (SDqLayer* pCurDqLayer, int16_t pMvd[2], const int8_t iListIdx) { | |
| 168 | + int32_t pMvd32[2]; | |
| 169 | + ST32 (&pMvd32[0], LD32 (pMvd)); | |
| 170 | + ST32 (&pMvd32[1], LD32 (pMvd)); | |
| 171 | + int32_t i; | |
| 172 | + int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 173 | + for (i = 0; i < 16; i += 2) { | |
| 174 | + ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][i], LD64 (pMvd32)); | |
| 175 | + } | |
| 176 | +} | |
| 177 | + | |
| 178 | +void UpdateP16x8MvdCabac (SDqLayer* pCurDqLayer, int16_t pMvdCache[LIST_A][30][MV_A], int32_t iPartIdx, int16_t pMvd[2], | |
| 179 | + const int8_t iListIdx) { | |
| 180 | + int32_t pMvd32[2]; | |
| 181 | + ST32 (&pMvd32[0], LD32 (pMvd)); | |
| 182 | + ST32 (&pMvd32[1], LD32 (pMvd)); | |
| 183 | + int32_t i; | |
| 184 | + int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 185 | + for (i = 0; i < 2; i++, iPartIdx += 4) { | |
| 186 | + const uint8_t iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 187 | + const uint8_t iScan4Idx4 = 4 + iScan4Idx; | |
| 188 | + const uint8_t iCacheIdx = g_kuiCache30ScanIdx[iPartIdx]; | |
| 189 | + const uint8_t iCacheIdx6 = 6 + iCacheIdx; | |
| 190 | + //mb | |
| 191 | + ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][ iScan4Idx ], LD64 (pMvd32)); | |
| 192 | + ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][ iScan4Idx4], LD64 (pMvd32)); | |
| 193 | + //cache | |
| 194 | + ST64 (pMvdCache[iListIdx][ iCacheIdx ], LD64 (pMvd32)); | |
| 195 | + ST64 (pMvdCache[iListIdx][ iCacheIdx6], LD64 (pMvd32)); | |
| 196 | + } | |
| 197 | +} | |
| 198 | + | |
| 199 | +void UpdateP8x16MvdCabac (SDqLayer* pCurDqLayer, int16_t pMvdCache[LIST_A][30][MV_A], int32_t iPartIdx, int16_t pMvd[2], | |
| 200 | + const int8_t iListIdx) { | |
| 201 | + int32_t pMvd32[2]; | |
| 202 | + ST32 (&pMvd32[0], LD32 (pMvd)); | |
| 203 | + ST32 (&pMvd32[1], LD32 (pMvd)); | |
| 204 | + int32_t i; | |
| 205 | + int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 206 | + | |
| 207 | + for (i = 0; i < 2; i++, iPartIdx += 8) { | |
| 208 | + const uint8_t iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 209 | + const uint8_t iCacheIdx = g_kuiCache30ScanIdx[iPartIdx]; | |
| 210 | + const uint8_t iScan4Idx4 = 4 + iScan4Idx; | |
| 211 | + const uint8_t iCacheIdx6 = 6 + iCacheIdx; | |
| 212 | + //mb | |
| 213 | + ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][ iScan4Idx ], LD64 (pMvd32)); | |
| 214 | + ST64 (pCurDqLayer->pMvd[iListIdx][iMbXy][ iScan4Idx4], LD64 (pMvd32)); | |
| 215 | + //cache | |
| 216 | + ST64 (pMvdCache[iListIdx][ iCacheIdx ], LD64 (pMvd32)); | |
| 217 | + ST64 (pMvdCache[iListIdx][ iCacheIdx6], LD64 (pMvd32)); | |
| 218 | + } | |
| 219 | +} | |
| 220 | + | |
| 221 | +int32_t ParseEndOfSliceCabac (PWelsDecoderContext pCtx, uint32_t& uiBinVal) { | |
| 222 | + uiBinVal = 0; | |
| 223 | + WELS_READ_VERIFY (DecodeTerminateCabac (pCtx->pCabacDecEngine, uiBinVal)); | |
| 224 | + return ERR_NONE; | |
| 225 | +} | |
| 226 | + | |
| 227 | +int32_t ParseSkipFlagCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiSkip) { | |
| 228 | + uiSkip = 0; | |
| 229 | + int32_t iCtxInc = NEW_CTX_OFFSET_SKIP; | |
| 230 | + iCtxInc += (pNeighAvail->iLeftAvail && !IS_SKIP (pNeighAvail->iLeftType)) + (pNeighAvail->iTopAvail | |
| 231 | + && !IS_SKIP (pNeighAvail->iTopType)); | |
| 232 | + if (B_SLICE == pCtx->eSliceType) | |
| 233 | + iCtxInc += 13; | |
| 234 | + PWelsCabacCtx pBinCtx = (pCtx->pCabacCtx + iCtxInc); | |
| 235 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pBinCtx, uiSkip)); | |
| 236 | + return ERR_NONE; | |
| 237 | +} | |
| 238 | + | |
| 239 | + | |
| 240 | +int32_t ParseMBTypeISliceCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiBinVal) { | |
| 241 | + uint32_t uiCode; | |
| 242 | + int32_t iIdxA = 0, iIdxB = 0; | |
| 243 | + int32_t iCtxInc; | |
| 244 | + uiBinVal = 0; | |
| 245 | + PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine; | |
| 246 | + PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_MB_TYPE_I; //I mode in I slice | |
| 247 | + iIdxA = (pNeighAvail->iLeftAvail) && (pNeighAvail->iLeftType != MB_TYPE_INTRA4x4 | |
| 248 | + && pNeighAvail->iLeftType != MB_TYPE_INTRA8x8); | |
| 249 | + iIdxB = (pNeighAvail->iTopAvail) && (pNeighAvail->iTopType != MB_TYPE_INTRA4x4 | |
| 250 | + && pNeighAvail->iTopType != MB_TYPE_INTRA8x8); | |
| 251 | + iCtxInc = iIdxA + iIdxB; | |
| 252 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + iCtxInc, uiCode)); | |
| 253 | + uiBinVal = uiCode; | |
| 254 | + if (uiBinVal != 0) { //I16x16 | |
| 255 | + WELS_READ_VERIFY (DecodeTerminateCabac (pCabacDecEngine, uiCode)); | |
| 256 | + if (uiCode == 1) | |
| 257 | + uiBinVal = 25; //I_PCM | |
| 258 | + else { | |
| 259 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 260 | + uiBinVal = 1 + uiCode * 12; | |
| 261 | + //decoding of uiCbp:0,1,2 | |
| 262 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 4, uiCode)); | |
| 263 | + if (uiCode != 0) { | |
| 264 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode)); | |
| 265 | + uiBinVal += 4; | |
| 266 | + if (uiCode != 0) | |
| 267 | + uiBinVal += 4; | |
| 268 | + } | |
| 269 | + //decoding of I pred-mode: 0,1,2,3 | |
| 270 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 6, uiCode)); | |
| 271 | + uiBinVal += (uiCode << 1); | |
| 272 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 7, uiCode)); | |
| 273 | + uiBinVal += uiCode; | |
| 274 | + } | |
| 275 | + } | |
| 276 | + //I4x4 | |
| 277 | + return ERR_NONE; | |
| 278 | +} | |
| 279 | + | |
| 280 | +int32_t ParseMBTypePSliceCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiMbType) { | |
| 281 | + uint32_t uiCode; | |
| 282 | + uiMbType = 0; | |
| 283 | + PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine; | |
| 284 | + | |
| 285 | + PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_SKIP; | |
| 286 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 287 | + if (uiCode) { | |
| 288 | + // Intra MB | |
| 289 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 6, uiCode)); | |
| 290 | + if (uiCode) { // Intra 16x16 | |
| 291 | + WELS_READ_VERIFY (DecodeTerminateCabac (pCabacDecEngine, uiCode)); | |
| 292 | + if (uiCode) { | |
| 293 | + uiMbType = 30; | |
| 294 | + return ERR_NONE;//MB_TYPE_INTRA_PCM; | |
| 295 | + } | |
| 296 | + | |
| 297 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 7, uiCode)); | |
| 298 | + uiMbType = 6 + uiCode * 12; | |
| 299 | + | |
| 300 | + //uiCbp: 0,1,2 | |
| 301 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 8, uiCode)); | |
| 302 | + if (uiCode) { | |
| 303 | + uiMbType += 4; | |
| 304 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 8, uiCode)); | |
| 305 | + if (uiCode) | |
| 306 | + uiMbType += 4; | |
| 307 | + } | |
| 308 | + | |
| 309 | + //IPredMode: 0,1,2,3 | |
| 310 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 9, uiCode)); | |
| 311 | + uiMbType += (uiCode << 1); | |
| 312 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 9, uiCode)); | |
| 313 | + uiMbType += uiCode; | |
| 314 | + } else | |
| 315 | + // Intra 4x4 | |
| 316 | + uiMbType = 5; | |
| 317 | + } else { // P MB | |
| 318 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 4, uiCode)); | |
| 319 | + if (uiCode) { //second bit | |
| 320 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 6, uiCode)); | |
| 321 | + if (uiCode) | |
| 322 | + uiMbType = 1; | |
| 323 | + else | |
| 324 | + uiMbType = 2; | |
| 325 | + } else { | |
| 326 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode)); | |
| 327 | + if (uiCode) | |
| 328 | + uiMbType = 3; | |
| 329 | + else | |
| 330 | + uiMbType = 0; | |
| 331 | + } | |
| 332 | + } | |
| 333 | + return ERR_NONE; | |
| 334 | +} | |
| 335 | + | |
| 336 | +int32_t ParseMBTypeBSliceCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiMbType) { | |
| 337 | + uint32_t uiCode; | |
| 338 | + uiMbType = 0; | |
| 339 | + int32_t iIdxA = 0, iIdxB = 0; | |
| 340 | + int32_t iCtxInc; | |
| 341 | + | |
| 342 | + PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine; | |
| 343 | + PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + 27; //B slice | |
| 344 | + | |
| 345 | + iIdxA = (pNeighAvail->iLeftAvail) && !IS_DIRECT (pNeighAvail->iLeftType); | |
| 346 | + iIdxB = (pNeighAvail->iTopAvail) && !IS_DIRECT (pNeighAvail->iTopType); | |
| 347 | + | |
| 348 | + iCtxInc = iIdxA + iIdxB; | |
| 349 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + iCtxInc, uiCode)); | |
| 350 | + if (!uiCode) | |
| 351 | + uiMbType = 0; // Bi_Direct | |
| 352 | + else { | |
| 353 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 354 | + if (!uiCode) { | |
| 355 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode)); | |
| 356 | + uiMbType = 1 + uiCode; // 16x16 L0L1 | |
| 357 | + } else { | |
| 358 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 4, uiCode)); | |
| 359 | + uiMbType = uiCode << 3; | |
| 360 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode)); | |
| 361 | + uiMbType |= uiCode << 2; | |
| 362 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode)); | |
| 363 | + uiMbType |= uiCode << 1; | |
| 364 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode)); | |
| 365 | + uiMbType |= uiCode; | |
| 366 | + if (uiMbType < 8) { | |
| 367 | + uiMbType += 3; | |
| 368 | + return ERR_NONE; | |
| 369 | + } else if (uiMbType == 13) { | |
| 370 | + uiMbType = DecodeCabacIntraMbType (pCtx, pNeighAvail, 32) + 23; | |
| 371 | + return ERR_NONE; | |
| 372 | + } else if (uiMbType == 14) { | |
| 373 | + uiMbType = 11; // Bi8x16 | |
| 374 | + return ERR_NONE; | |
| 375 | + } else if (uiMbType == 15) { | |
| 376 | + uiMbType = 22; // 8x8 | |
| 377 | + return ERR_NONE; | |
| 378 | + } | |
| 379 | + uiMbType <<= 1; | |
| 380 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 5, uiCode)); | |
| 381 | + uiMbType |= uiCode; | |
| 382 | + uiMbType -= 4; | |
| 383 | + } | |
| 384 | + } | |
| 385 | + return ERR_NONE; | |
| 386 | +} | |
| 387 | + | |
| 388 | +int32_t ParseTransformSize8x8FlagCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, | |
| 389 | + bool& bTransformSize8x8Flag) { | |
| 390 | + uint32_t uiCode; | |
| 391 | + int32_t iIdxA, iIdxB; | |
| 392 | + int32_t iCtxInc; | |
| 393 | + PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine; | |
| 394 | + PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_TS_8x8_FLAG; | |
| 395 | + iIdxA = (pNeighAvail->iLeftAvail) && (pCtx->pCurDqLayer->pTransformSize8x8Flag[pCtx->pCurDqLayer->iMbXyIndex - 1]); | |
| 396 | + iIdxB = (pNeighAvail->iTopAvail) | |
| 397 | + && (pCtx->pCurDqLayer->pTransformSize8x8Flag[pCtx->pCurDqLayer->iMbXyIndex - pCtx->pCurDqLayer->iMbWidth]); | |
| 398 | + iCtxInc = iIdxA + iIdxB; | |
| 399 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + iCtxInc, uiCode)); | |
| 400 | + bTransformSize8x8Flag = !!uiCode; | |
| 401 | + | |
| 402 | + return ERR_NONE; | |
| 403 | +} | |
| 404 | + | |
| 405 | +int32_t ParseSubMBTypeCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiSubMbType) { | |
| 406 | + uint32_t uiCode; | |
| 407 | + PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine; | |
| 408 | + PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_SUBMB_TYPE; | |
| 409 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx, uiCode)); | |
| 410 | + if (uiCode) | |
| 411 | + uiSubMbType = 0; | |
| 412 | + else { | |
| 413 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 1, uiCode)); | |
| 414 | + if (uiCode) { | |
| 415 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 2, uiCode)); | |
| 416 | + uiSubMbType = 3 - uiCode; | |
| 417 | + } else { | |
| 418 | + uiSubMbType = 1; | |
| 419 | + } | |
| 420 | + } | |
| 421 | + return ERR_NONE; | |
| 422 | +} | |
| 423 | + | |
| 424 | +int32_t ParseBSubMBTypeCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiSubMbType) { | |
| 425 | + uint32_t uiCode; | |
| 426 | + PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine; | |
| 427 | + PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_B_SUBMB_TYPE; | |
| 428 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx, uiCode)); | |
| 429 | + if (!uiCode) { | |
| 430 | + uiSubMbType = 0; /* B_Direct_8x8 */ | |
| 431 | + return ERR_NONE; | |
| 432 | + } | |
| 433 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 1, uiCode)); | |
| 434 | + if (!uiCode) { | |
| 435 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 436 | + uiSubMbType = 1 + uiCode; /* B_L0_8x8, B_L1_8x8 */ | |
| 437 | + return ERR_NONE; | |
| 438 | + } | |
| 439 | + uiSubMbType = 3; | |
| 440 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 2, uiCode)); | |
| 441 | + if (uiCode) { | |
| 442 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 443 | + if (uiCode) { | |
| 444 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 445 | + uiSubMbType = 11 + uiCode; /* B_L1_4x4, B_Bi_4x4 */ | |
| 446 | + return ERR_NONE; | |
| 447 | + } | |
| 448 | + uiSubMbType += 4; | |
| 449 | + } | |
| 450 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 451 | + uiSubMbType += 2 * uiCode; | |
| 452 | + WELS_READ_VERIFY (DecodeBinCabac (pCabacDecEngine, pBinCtx + 3, uiCode)); | |
| 453 | + uiSubMbType += uiCode; | |
| 454 | + | |
| 455 | + return ERR_NONE; | |
| 456 | +} | |
| 457 | + | |
| 458 | +int32_t ParseIntraPredModeLumaCabac (PWelsDecoderContext pCtx, int32_t& iBinVal) { | |
| 459 | + uint32_t uiCode; | |
| 460 | + iBinVal = 0; | |
| 461 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_IPR, uiCode)); | |
| 462 | + if (uiCode == 1) | |
| 463 | + iBinVal = -1; | |
| 464 | + else { | |
| 465 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_IPR + 1, uiCode)); | |
| 466 | + iBinVal |= uiCode; | |
| 467 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_IPR + 1, uiCode)); | |
| 468 | + iBinVal |= (uiCode << 1); | |
| 469 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_IPR + 1, uiCode)); | |
| 470 | + iBinVal |= (uiCode << 2); | |
| 471 | + } | |
| 472 | + return ERR_NONE; | |
| 473 | +} | |
| 474 | + | |
| 475 | +int32_t ParseIntraPredModeChromaCabac (PWelsDecoderContext pCtx, uint8_t uiNeighAvail, int32_t& iBinVal) { | |
| 476 | + uint32_t uiCode; | |
| 477 | + int32_t iIdxA, iIdxB, iCtxInc; | |
| 478 | + int8_t* pChromaPredMode = pCtx->pCurDqLayer->pChromaPredMode; | |
| 479 | + uint32_t* pMbType = pCtx->pCurDqLayer->pMbType; | |
| 480 | + int32_t iLeftAvail = uiNeighAvail & 0x04; | |
| 481 | + int32_t iTopAvail = uiNeighAvail & 0x01; | |
| 482 | + | |
| 483 | + int32_t iMbXy = pCtx->pCurDqLayer->iMbXyIndex; | |
| 484 | + int32_t iMbXyTop = iMbXy - pCtx->pCurDqLayer->iMbWidth; | |
| 485 | + int32_t iMbXyLeft = iMbXy - 1; | |
| 486 | + | |
| 487 | + iBinVal = 0; | |
| 488 | + | |
| 489 | + iIdxB = iTopAvail && (pChromaPredMode[iMbXyTop] > 0 && pChromaPredMode[iMbXyTop] <= 3) | |
| 490 | + && pMbType[iMbXyTop] != MB_TYPE_INTRA_PCM; | |
| 491 | + iIdxA = iLeftAvail && (pChromaPredMode[iMbXyLeft] > 0 && pChromaPredMode[iMbXyLeft] <= 3) | |
| 492 | + && pMbType[iMbXyLeft] != MB_TYPE_INTRA_PCM; | |
| 493 | + iCtxInc = iIdxA + iIdxB; | |
| 494 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CIPR + iCtxInc, uiCode)); | |
| 495 | + iBinVal = uiCode; | |
| 496 | + if (iBinVal != 0) { | |
| 497 | + uint32_t iSym; | |
| 498 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CIPR + 3, iSym)); | |
| 499 | + if (iSym == 0) { | |
| 500 | + iBinVal = (iSym + 1); | |
| 501 | + return ERR_NONE; | |
| 502 | + } | |
| 503 | + iSym = 0; | |
| 504 | + do { | |
| 505 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CIPR + 3, uiCode)); | |
| 506 | + ++iSym; | |
| 507 | + } while ((uiCode != 0) && (iSym < 1)); | |
| 508 | + | |
| 509 | + if ((uiCode != 0) && (iSym == 1)) | |
| 510 | + ++ iSym; | |
| 511 | + iBinVal = (iSym + 1); | |
| 512 | + return ERR_NONE; | |
| 513 | + } | |
| 514 | + return ERR_NONE; | |
| 515 | +} | |
| 516 | + | |
| 517 | +int32_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]) { | |
| 519 | + PSlice pSlice = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer; | |
| 520 | + PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | |
| 521 | + PDqLayer pCurDqLayer = pCtx->pCurDqLayer; | |
| 522 | + PPicture* ppRefPic = pCtx->sRefPic.pRefList[LIST_0]; | |
| 523 | + int32_t pRefCount[2]; | |
| 524 | + int32_t i, j; | |
| 525 | + int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 526 | + int16_t pMv[4] = {0}; | |
| 527 | + int16_t pMvd[4] = {0}; | |
| 528 | + int8_t iRef[2] = {0}; | |
| 529 | + int32_t iPartIdx; | |
| 530 | + int16_t iMinVmv = pSliceHeader->pSps->pSLevelLimits->iMinVmv; | |
| 531 | + int16_t iMaxVmv = pSliceHeader->pSps->pSLevelLimits->iMaxVmv; | |
| 532 | + pRefCount[0] = pSliceHeader->uiRefCount[0]; | |
| 533 | + pRefCount[1] = pSliceHeader->uiRefCount[1]; | |
| 534 | + | |
| 535 | + switch (pCurDqLayer->pMbType[iMbXy]) { | |
| 536 | + case MB_TYPE_16x16: { | |
| 537 | + iPartIdx = 0; | |
| 538 | + WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, 0, LIST_0, iPartIdx, pRefCount[0], 0, | |
| 539 | + iRef[0])); | |
| 540 | + if ((iRef[0] < 0) || (iRef[0] >= pRefCount[0]) || (ppRefPic[iRef[0]] == NULL)) { //error ref_idx | |
| 541 | + pCtx->bMbRefConcealed = true; | |
| 542 | + if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 543 | + iRef[0] = 0; | |
| 544 | + pCtx->iErrorCode |= dsBitstreamError; | |
| 545 | + } else { | |
| 546 | + return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX); | |
| 547 | + } | |
| 548 | + } | |
| 549 | + pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRef[0]] | |
| 550 | + && ppRefPic[iRef[0]]->bIsComplete); | |
| 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])); | |
| 553 | + WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 1, pMvd[1])); | |
| 554 | + pMv[0] += pMvd[0]; | |
| 555 | + pMv[1] += pMvd[1]; | |
| 556 | + WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv"); | |
| 557 | + UpdateP16x16MotionInfo (pCurDqLayer, LIST_0, iRef[0], pMv); | |
| 558 | + UpdateP16x16MvdCabac (pCurDqLayer, pMvd, LIST_0); | |
| 559 | + } | |
| 560 | + break; | |
| 561 | + case MB_TYPE_16x8: | |
| 562 | + for (i = 0; i < 2; i++) { | |
| 563 | + iPartIdx = i << 3; | |
| 564 | + WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, 0, LIST_0, iPartIdx, pRefCount[0], 0, | |
| 565 | + iRef[i])); | |
| 566 | + if ((iRef[i] < 0) || (iRef[i] >= pRefCount[0]) || (ppRefPic[iRef[i]] == NULL)) { //error ref_idx | |
| 567 | + pCtx->bMbRefConcealed = true; | |
| 568 | + if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 569 | + iRef[i] = 0; | |
| 570 | + pCtx->iErrorCode |= dsBitstreamError; | |
| 571 | + } else { | |
| 572 | + return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX); | |
| 573 | + } | |
| 574 | + } | |
| 575 | + pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRef[i]] | |
| 576 | + && ppRefPic[iRef[i]]->bIsComplete); | |
| 577 | + UpdateP16x8RefIdxCabac (pCurDqLayer, pRefIndex, iPartIdx, iRef[i], LIST_0); | |
| 578 | + } | |
| 579 | + for (i = 0; i < 2; i++) { | |
| 580 | + iPartIdx = i << 3; | |
| 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])); | |
| 583 | + WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 1, pMvd[1])); | |
| 584 | + pMv[0] += pMvd[0]; | |
| 585 | + pMv[1] += pMvd[1]; | |
| 586 | + WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv"); | |
| 587 | + UpdateP16x8MotionInfo (pCurDqLayer, pMotionVector, pRefIndex, LIST_0, iPartIdx, iRef[i], pMv); | |
| 588 | + UpdateP16x8MvdCabac (pCurDqLayer, pMvdCache, iPartIdx, pMvd, LIST_0); | |
| 589 | + } | |
| 590 | + break; | |
| 591 | + case MB_TYPE_8x16: | |
| 592 | + for (i = 0; i < 2; i++) { | |
| 593 | + iPartIdx = i << 2; | |
| 594 | + WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, 0, LIST_0, iPartIdx, pRefCount[0], 0, | |
| 595 | + iRef[i])); | |
| 596 | + if ((iRef[i] < 0) || (iRef[i] >= pRefCount[0]) || (ppRefPic[iRef[i]] == NULL)) { //error ref_idx | |
| 597 | + pCtx->bMbRefConcealed = true; | |
| 598 | + if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 599 | + iRef[i] = 0; | |
| 600 | + pCtx->iErrorCode |= dsBitstreamError; | |
| 601 | + } else { | |
| 602 | + return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX); | |
| 603 | + } | |
| 604 | + } | |
| 605 | + pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[iRef[i]] | |
| 606 | + && ppRefPic[iRef[i]]->bIsComplete); | |
| 607 | + UpdateP8x16RefIdxCabac (pCurDqLayer, pRefIndex, iPartIdx, iRef[i], LIST_0); | |
| 608 | + } | |
| 609 | + for (i = 0; i < 2; i++) { | |
| 610 | + iPartIdx = i << 2; | |
| 611 | + PredInter8x16Mv (pMotionVector, pRefIndex, LIST_0, i << 2, iRef[i], pMv/*&mv[0], &mv[1]*/); | |
| 612 | + | |
| 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])); | |
| 615 | + pMv[0] += pMvd[0]; | |
| 616 | + pMv[1] += pMvd[1]; | |
| 617 | + WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv"); | |
| 618 | + UpdateP8x16MotionInfo (pCurDqLayer, pMotionVector, pRefIndex, LIST_0, iPartIdx, iRef[i], pMv); | |
| 619 | + UpdateP8x16MvdCabac (pCurDqLayer, pMvdCache, iPartIdx, pMvd, LIST_0); | |
| 620 | + } | |
| 621 | + break; | |
| 622 | + case MB_TYPE_8x8: | |
| 623 | + case MB_TYPE_8x8_REF0: { | |
| 624 | + int8_t pRefIdx[4] = {0}, pSubPartCount[4], pPartW[4]; | |
| 625 | + uint32_t uiSubMbType; | |
| 626 | + //sub_mb_type, partition | |
| 627 | + for (i = 0; i < 4; i++) { | |
| 628 | + WELS_READ_VERIFY (ParseSubMBTypeCabac (pCtx, pNeighAvail, uiSubMbType)); | |
| 629 | + if (uiSubMbType >= 4) { //invalid sub_mb_type | |
| 630 | + return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_SUB_MB_TYPE); | |
| 631 | + } | |
| 632 | + pCurDqLayer->pSubMbType[iMbXy][i] = g_ksInterPSubMbTypeInfo[uiSubMbType].iType; | |
| 633 | + pSubPartCount[i] = g_ksInterPSubMbTypeInfo[uiSubMbType].iPartCount; | |
| 634 | + pPartW[i] = g_ksInterPSubMbTypeInfo[uiSubMbType].iPartWidth; | |
| 635 | + | |
| 636 | + // Need modification when B picture add in, reference to 7.3.5 | |
| 637 | + pCurDqLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] &= (uiSubMbType == 0); | |
| 638 | + } | |
| 639 | + | |
| 640 | + for (i = 0; i < 4; i++) { | |
| 641 | + int16_t iIdx8 = i << 2; | |
| 642 | + WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, 0, LIST_0, iIdx8, pRefCount[0], 1, | |
| 643 | + pRefIdx[i])); | |
| 644 | + if ((pRefIdx[i] < 0) || (pRefIdx[i] >= pRefCount[0]) || (ppRefPic[pRefIdx[i]] == NULL)) { //error ref_idx | |
| 645 | + pCtx->bMbRefConcealed = true; | |
| 646 | + if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 647 | + pRefIdx[i] = 0; | |
| 648 | + pCtx->iErrorCode |= dsBitstreamError; | |
| 649 | + } else { | |
| 650 | + return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX); | |
| 651 | + } | |
| 652 | + } | |
| 653 | + pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[pRefIdx[i]] | |
| 654 | + && ppRefPic[pRefIdx[i]]->bIsComplete); | |
| 655 | + UpdateP8x8RefIdxCabac (pCurDqLayer, pRefIndex, iIdx8, pRefIdx[i], LIST_0); | |
| 656 | + } | |
| 657 | + //mv | |
| 658 | + for (i = 0; i < 4; i++) { | |
| 659 | + int8_t iPartCount = pSubPartCount[i]; | |
| 660 | + uiSubMbType = pCurDqLayer->pSubMbType[iMbXy][i]; | |
| 661 | + int16_t iPartIdx, iBlockW = pPartW[i]; | |
| 662 | + uint8_t iScan4Idx, iCacheIdx; | |
| 663 | + iCacheIdx = g_kuiCache30ScanIdx[i << 2]; | |
| 664 | + pRefIndex[0][iCacheIdx ] = pRefIndex[0][iCacheIdx + 1] | |
| 665 | + = pRefIndex[0][iCacheIdx + 6] = pRefIndex[0][iCacheIdx + 7] = pRefIdx[i]; | |
| 666 | + | |
| 667 | + for (j = 0; j < iPartCount; j++) { | |
| 668 | + iPartIdx = (i << 2) + j * iBlockW; | |
| 669 | + iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 670 | + iCacheIdx = g_kuiCache30ScanIdx[iPartIdx]; | |
| 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])); | |
| 673 | + WELS_READ_VERIFY (ParseMvdInfoCabac (pCtx, pNeighAvail, pRefIndex, pMvdCache, iPartIdx, LIST_0, 1, pMvd[1])); | |
| 674 | + pMv[0] += pMvd[0]; | |
| 675 | + pMv[1] += pMvd[1]; | |
| 676 | + WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv"); | |
| 677 | + if (SUB_MB_TYPE_8x8 == uiSubMbType) { | |
| 678 | + ST32 ((pMv + 2), LD32 (pMv)); | |
| 679 | + ST32 ((pMvd + 2), LD32 (pMvd)); | |
| 680 | + ST64 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx], LD64 (pMv)); | |
| 681 | + ST64 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx + 4], LD64 (pMv)); | |
| 682 | + ST64 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx], LD64 (pMvd)); | |
| 683 | + ST64 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx + 4], LD64 (pMvd)); | |
| 684 | + ST64 (pMotionVector[0][iCacheIdx ], LD64 (pMv)); | |
| 685 | + ST64 (pMotionVector[0][iCacheIdx + 6], LD64 (pMv)); | |
| 686 | + ST64 (pMvdCache[0][iCacheIdx ], LD64 (pMvd)); | |
| 687 | + ST64 (pMvdCache[0][iCacheIdx + 6], LD64 (pMvd)); | |
| 688 | + } else if (SUB_MB_TYPE_8x4 == uiSubMbType) { | |
| 689 | + ST32 ((pMv + 2), LD32 (pMv)); | |
| 690 | + ST32 ((pMvd + 2), LD32 (pMvd)); | |
| 691 | + ST64 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx ], LD64 (pMv)); | |
| 692 | + ST64 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx ], LD64 (pMvd)); | |
| 693 | + ST64 (pMotionVector[0][iCacheIdx ], LD64 (pMv)); | |
| 694 | + ST64 (pMvdCache[0][iCacheIdx ], LD64 (pMvd)); | |
| 695 | + } else if (SUB_MB_TYPE_4x8 == uiSubMbType) { | |
| 696 | + ST32 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx ], LD32 (pMv)); | |
| 697 | + ST32 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx + 4], LD32 (pMv)); | |
| 698 | + ST32 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx ], LD32 (pMvd)); | |
| 699 | + ST32 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx + 4], LD32 (pMvd)); | |
| 700 | + ST32 (pMotionVector[0][iCacheIdx ], LD32 (pMv)); | |
| 701 | + ST32 (pMotionVector[0][iCacheIdx + 6], LD32 (pMv)); | |
| 702 | + ST32 (pMvdCache[0][iCacheIdx ], LD32 (pMvd)); | |
| 703 | + ST32 (pMvdCache[0][iCacheIdx + 6], LD32 (pMvd)); | |
| 704 | + } else { //SUB_MB_TYPE_4x4 | |
| 705 | + ST32 (pCurDqLayer->pMv[0][iMbXy][iScan4Idx ], LD32 (pMv)); | |
| 706 | + ST32 (pCurDqLayer->pMvd[0][iMbXy][iScan4Idx ], LD32 (pMvd)); | |
| 707 | + ST32 (pMotionVector[0][iCacheIdx ], LD32 (pMv)); | |
| 708 | + ST32 (pMvdCache[0][iCacheIdx ], LD32 (pMvd)); | |
| 709 | + } | |
| 710 | + } | |
| 711 | + } | |
| 712 | + } | |
| 713 | + break; | |
| 714 | + default: | |
| 715 | + break; | |
| 716 | + } | |
| 717 | + return ERR_NONE; | |
| 718 | +} | |
| 719 | + | |
| 720 | +int32_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], | |
| 722 | + int8_t pDirect[30]) { | |
| 723 | + PSlice pSlice = &pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer; | |
| 724 | + PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | |
| 725 | + PDqLayer pCurDqLayer = pCtx->pCurDqLayer; | |
| 726 | + int32_t pRefCount[LIST_A]; | |
| 727 | + int32_t iMbXy = pCurDqLayer->iMbXyIndex; | |
| 728 | + int16_t pMv[4] = { 0 }; | |
| 729 | + int16_t pMvd[4] = { 0 }; | |
| 730 | + int8_t iRef[LIST_A] = { 0 }; | |
| 731 | + int32_t iPartIdx; | |
| 732 | + int16_t iMinVmv = pSliceHeader->pSps->pSLevelLimits->iMinVmv; | |
| 733 | + int16_t iMaxVmv = pSliceHeader->pSps->pSLevelLimits->iMaxVmv; | |
| 734 | + pRefCount[0] = pSliceHeader->uiRefCount[0]; | |
| 735 | + pRefCount[1] = pSliceHeader->uiRefCount[1]; | |
| 736 | + | |
| 737 | + MbType mbType = pCurDqLayer->pMbType[iMbXy]; | |
| 738 | + | |
| 739 | + if (IS_DIRECT (mbType)) { | |
| 740 | + | |
| 741 | + int16_t pMvDirect[LIST_A][2] = { { 0, 0 }, { 0, 0 } }; | |
| 742 | + if (pSliceHeader->iDirectSpatialMvPredFlag) { | |
| 743 | + //predict direct spatial mv | |
| 744 | + PredMvBDirectSpatial (pCtx, pMvDirect, iRef); | |
| 745 | + } else { | |
| 746 | + //temporal direct 16x16 mode | |
| 747 | + ComputeColocated (pCtx); | |
| 748 | + PredBDirectTemporal (pCtx, pMvDirect, iRef); | |
| 749 | + } | |
| 750 | + } else if (IS_INTER_16x16 (mbType)) { | |
| 751 | + iPartIdx = 0; | |
| 752 | + for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 753 | + iRef[listIdx] = REF_NOT_IN_LIST; | |
| 754 | + if (IS_DIR (mbType, 0, listIdx)) { | |
| 755 | + WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, pDirect, listIdx, iPartIdx, | |
| 756 | + pRefCount[listIdx], 0, | |
| 757 | + iRef[listIdx])); | |
| 758 | + if ((iRef[listIdx] < 0) || (iRef[listIdx] >= pRefCount[listIdx]) | |
| 759 | + || (pCtx->sRefPic.pRefList[listIdx][iRef[listIdx]] == NULL)) { //error ref_idx | |
| 760 | + pCtx->bMbRefConcealed = true; | |
| 761 | + if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 762 | + iRef[listIdx] = 0; | |
| 763 | + pCtx->iErrorCode |= dsBitstreamError; | |
| 764 | + } else { | |
| 765 | + return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX); | |
| 766 | + } | |
| 767 | + } | |
| 768 | + pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (pCtx->sRefPic.pRefList[listIdx][iRef[listIdx]] | |
| 769 | + && pCtx->sRefPic.pRefList[listIdx][iRef[listIdx]]->bIsComplete); | |
| 770 | + } | |
| 771 | + } | |
| 772 | + for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 773 | + if (IS_DIR (mbType, 0, listIdx)) { | |
| 774 | + PredMv (pMotionVector, pRefIndex, listIdx, 0, 4, iRef[listIdx], pMv); | |
| 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])); | |
| 777 | + pMv[0] += pMvd[0]; | |
| 778 | + pMv[1] += pMvd[1]; | |
| 779 | + WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv"); | |
| 780 | + } else { | |
| 781 | + * (uint32_t*)pMv = * (uint32_t*)pMvd = 0; | |
| 782 | + } | |
| 783 | + UpdateP16x16MotionInfo (pCurDqLayer, listIdx, iRef[listIdx], pMv); | |
| 784 | + UpdateP16x16MvdCabac (pCurDqLayer, pMvd, listIdx); | |
| 785 | + } | |
| 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 } }; | |
| 788 | + for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 789 | + for (int32_t i = 0; i < 2; ++i) { | |
| 790 | + iPartIdx = i << 3; | |
| 791 | + int8_t ref_idx = REF_NOT_IN_LIST; | |
| 792 | + if (IS_DIR (mbType, i, listIdx)) { | |
| 793 | + WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, pDirect, listIdx, iPartIdx, | |
| 794 | + pRefCount[listIdx], 0, ref_idx)); | |
| 795 | + if ((ref_idx < 0) || (ref_idx >= pRefCount[listIdx]) | |
| 796 | + || (pCtx->sRefPic.pRefList[listIdx][ref_idx] == NULL)) { //error ref_idx | |
| 797 | + pCtx->bMbRefConcealed = true; | |
| 798 | + if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 799 | + ref_idx = 0; | |
| 800 | + pCtx->iErrorCode |= dsBitstreamError; | |
| 801 | + } else { | |
| 802 | + return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX); | |
| 803 | + } | |
| 804 | + } | |
| 805 | + pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (pCtx->sRefPic.pRefList[listIdx][ref_idx] | |
| 806 | + && pCtx->sRefPic.pRefList[listIdx][ref_idx]->bIsComplete); | |
| 807 | + } | |
| 808 | + UpdateP16x8RefIdxCabac (pCurDqLayer, pRefIndex, iPartIdx, ref_idx, listIdx); | |
| 809 | + ref_idx_list[listIdx][i] = ref_idx; | |
| 810 | + } | |
| 811 | + } | |
| 812 | + for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 813 | + for (int32_t i = 0; i < 2; ++i) { | |
| 814 | + iPartIdx = i << 3; | |
| 815 | + int8_t ref_idx = ref_idx_list[listIdx][i]; | |
| 816 | + if (IS_DIR (mbType, i, listIdx)) { | |
| 817 | + PredInter16x8Mv (pMotionVector, pRefIndex, listIdx, iPartIdx, ref_idx, pMv); | |
| 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])); | |
| 820 | + pMv[0] += pMvd[0]; | |
| 821 | + pMv[1] += pMvd[1]; | |
| 822 | + WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv"); | |
| 823 | + } else { | |
| 824 | + * (uint32_t*)pMv = * (uint32_t*)pMvd = 0; | |
| 825 | + } | |
| 826 | + UpdateP16x8MotionInfo (pCurDqLayer, pMotionVector, pRefIndex, listIdx, iPartIdx, ref_idx, pMv); | |
| 827 | + UpdateP16x8MvdCabac (pCurDqLayer, pMvdCache, iPartIdx, pMvd, listIdx); | |
| 828 | + } | |
| 829 | + } | |
| 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 } }; | |
| 832 | + for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 833 | + for (int32_t i = 0; i < 2; ++i) { | |
| 834 | + iPartIdx = i << 2; | |
| 835 | + int8_t ref_idx = REF_NOT_IN_LIST; | |
| 836 | + if (IS_DIR (mbType, i, listIdx)) { | |
| 837 | + WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, pDirect, listIdx, iPartIdx, | |
| 838 | + pRefCount[listIdx], 0, ref_idx)); | |
| 839 | + if ((ref_idx < 0) || (ref_idx >= pRefCount[listIdx]) | |
| 840 | + || (pCtx->sRefPic.pRefList[listIdx][ref_idx] == NULL)) { //error ref_idx | |
| 841 | + pCtx->bMbRefConcealed = true; | |
| 842 | + if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 843 | + ref_idx = 0; | |
| 844 | + pCtx->iErrorCode |= dsBitstreamError; | |
| 845 | + } else { | |
| 846 | + return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX); | |
| 847 | + } | |
| 848 | + } | |
| 849 | + pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (pCtx->sRefPic.pRefList[listIdx][ref_idx] | |
| 850 | + && pCtx->sRefPic.pRefList[listIdx][ref_idx]->bIsComplete); | |
| 851 | + } | |
| 852 | + UpdateP8x16RefIdxCabac (pCurDqLayer, pRefIndex, iPartIdx, ref_idx, listIdx); | |
| 853 | + ref_idx_list[listIdx][i] = ref_idx; | |
| 854 | + } | |
| 855 | + } | |
| 856 | + for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 857 | + for (int32_t i = 0; i < 2; ++i) { | |
| 858 | + iPartIdx = i << 2; | |
| 859 | + int8_t ref_idx = ref_idx_list[listIdx][i]; | |
| 860 | + if (IS_DIR (mbType, i, listIdx)) { | |
| 861 | + PredInter8x16Mv (pMotionVector, pRefIndex, listIdx, iPartIdx, ref_idx, pMv); | |
| 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])); | |
| 864 | + pMv[0] += pMvd[0]; | |
| 865 | + pMv[1] += pMvd[1]; | |
| 866 | + WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv"); | |
| 867 | + } else { | |
| 868 | + * (uint32_t*)pMv = * (uint32_t*)pMvd = 0; | |
| 869 | + } | |
| 870 | + UpdateP8x16MotionInfo (pCurDqLayer, pMotionVector, pRefIndex, listIdx, iPartIdx, ref_idx, pMv); | |
| 871 | + UpdateP8x16MvdCabac (pCurDqLayer, pMvdCache, iPartIdx, pMvd, listIdx); | |
| 872 | + } | |
| 873 | + } | |
| 874 | + } else if (IS_Inter_8x8 (mbType)) { | |
| 875 | + int8_t pSubPartCount[4], pPartW[4]; | |
| 876 | + uint32_t uiSubMbType; | |
| 877 | + //sub_mb_type, partition | |
| 878 | + int16_t pMvDirect[LIST_A][2] = { {0, 0}, {0, 0} }; | |
| 879 | + bool has_direct_called = false; | |
| 880 | + SubMbType directSubMbType = 0; | |
| 881 | + for (int32_t i = 0; i < 4; i++) { | |
| 882 | + WELS_READ_VERIFY (ParseBSubMBTypeCabac (pCtx, pNeighAvail, uiSubMbType)); | |
| 883 | + if (uiSubMbType > 13) { //invalid sub_mb_type | |
| 884 | + return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_SUB_MB_TYPE); | |
| 885 | + } | |
| 886 | +// pCurDqLayer->pSubMbType[iMbXy][i] = g_ksInterBSubMbTypeInfo[uiSubMbType].iType; | |
| 887 | + pSubPartCount[i] = g_ksInterBSubMbTypeInfo[uiSubMbType].iPartCount; | |
| 888 | + pPartW[i] = g_ksInterBSubMbTypeInfo[uiSubMbType].iPartWidth; | |
| 889 | + | |
| 890 | + // Need modification when B picture add in, reference to 7.3.5 | |
| 891 | + if (pSubPartCount[i] > 1) | |
| 892 | + pCurDqLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = false; | |
| 893 | + | |
| 894 | + if (IS_DIRECT (g_ksInterBSubMbTypeInfo[uiSubMbType].iType)) { | |
| 895 | + if (!has_direct_called) { | |
| 896 | + if (pSliceHeader->iDirectSpatialMvPredFlag) { | |
| 897 | + directSubMbType = PredMvBDirectSpatial (pCtx, pMvDirect, iRef); | |
| 898 | + } else { | |
| 899 | + //temporal direct mode | |
| 900 | + ComputeColocated (pCtx); | |
| 901 | + PredBDirectTemporal (pCtx, pMvDirect, iRef); | |
| 902 | + } | |
| 903 | + has_direct_called = true; | |
| 904 | + } | |
| 905 | + pCurDqLayer->pSubMbType[iMbXy][i] = directSubMbType; | |
| 906 | + if (IS_SUB_4x4 (pCurDqLayer->pSubMbType[iMbXy][i])) { | |
| 907 | + pSubPartCount[i] = 4; | |
| 908 | + pPartW[i] = 1; | |
| 909 | + } | |
| 910 | + } else { | |
| 911 | + pCurDqLayer->pSubMbType[iMbXy][i] = g_ksInterBSubMbTypeInfo[uiSubMbType].iType; | |
| 912 | + } | |
| 913 | + } | |
| 914 | + for (int32_t i = 0; i < 4; i++) { //Direct 8x8 Ref and mv | |
| 915 | + | |
| 916 | + int16_t iIdx8 = i << 2; | |
| 917 | + if (IS_DIRECT (pCurDqLayer->pSubMbType[iMbXy][i])) { | |
| 918 | + | |
| 919 | + int8_t iPartCount = pSubPartCount[i]; | |
| 920 | + int16_t iPartIdx, iBlockW = pPartW[i]; | |
| 921 | + uint8_t iScan4Idx, iCacheIdx, iColocIdx; | |
| 922 | + iCacheIdx = g_kuiCache30ScanIdx[iIdx8]; | |
| 923 | + | |
| 924 | + if (!pSliceHeader->iDirectSpatialMvPredFlag) { | |
| 925 | + iRef[LIST_1] = 0; | |
| 926 | + if (pCurDqLayer->iColocIntra[g_kuiScan4[iIdx8]]) { | |
| 927 | + iRef[LIST_0] = 0; | |
| 928 | + } else { | |
| 929 | + if (pCurDqLayer->iColocRefIndex[LIST_0][iIdx8] >= 0) { | |
| 930 | + iRef[LIST_0] = pCurDqLayer->iColocRefIndex[LIST_0][iIdx8]; | |
| 931 | + } else { | |
| 932 | + iRef[LIST_0] = pCurDqLayer->iColocRefIndex[LIST_1][iIdx8]; | |
| 933 | + } | |
| 934 | + } | |
| 935 | + } | |
| 936 | + for (int32_t j = 0; j < iPartCount; j++) { | |
| 937 | + iPartIdx = iIdx8 + j * iBlockW; | |
| 938 | + iColocIdx = g_kuiScan4[iPartIdx]; | |
| 939 | + iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 940 | + iCacheIdx = g_kuiCache30ScanIdx[iPartIdx]; | |
| 941 | + | |
| 942 | + if (pSliceHeader->iDirectSpatialMvPredFlag) { | |
| 943 | + int16_t pMV[4] = { 0 }; | |
| 944 | + if (IS_SUB_8x8 (pCurDqLayer->pSubMbType[iMbXy][i])) { | |
| 945 | + * (uint32_t*)pMV = * (uint32_t*)pMvDirect[LIST_0]; | |
| 946 | + ST32 ((pMV + 2), LD32 (pMV)); | |
| 947 | + ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], LD64 (pMV)); | |
| 948 | + ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx + 4], LD64 (pMV)); | |
| 949 | + ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0); | |
| 950 | + ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx + 4], 0); | |
| 951 | + ST64 (pMotionVector[LIST_0][iCacheIdx], LD64 (pMV)); | |
| 952 | + ST64 (pMotionVector[LIST_0][iCacheIdx + 6], LD64 (pMV)); | |
| 953 | + ST64 (pMvdCache[LIST_0][iCacheIdx], 0); | |
| 954 | + ST64 (pMvdCache[LIST_0][iCacheIdx + 6], 0); | |
| 955 | + * (uint32_t*)pMV = * (uint32_t*)pMvDirect[LIST_1]; | |
| 956 | + ST32 ((pMV + 2), LD32 (pMV)); | |
| 957 | + ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], LD64 (pMV)); | |
| 958 | + ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx + 4], LD64 (pMV)); | |
| 959 | + ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0); | |
| 960 | + ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx + 4], 0); | |
| 961 | + ST64 (pMotionVector[LIST_1][iCacheIdx], LD64 (pMV)); | |
| 962 | + ST64 (pMotionVector[LIST_1][iCacheIdx + 6], LD64 (pMV)); | |
| 963 | + ST64 (pMvdCache[LIST_1][iCacheIdx], 0); | |
| 964 | + ST64 (pMvdCache[LIST_1][iCacheIdx + 6], 0); | |
| 965 | + } else { //SUB_4x4 | |
| 966 | + * (uint32_t*)pMV = * (uint32_t*)pMvDirect[LIST_0]; | |
| 967 | + ST32 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], LD32 (pMV)); | |
| 968 | + ST32 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0); | |
| 969 | + ST32 (pMotionVector[LIST_0][iCacheIdx], LD32 (pMV)); | |
| 970 | + ST32 (pMvdCache[LIST_0][iCacheIdx], 0); | |
| 971 | + * (uint32_t*)pMV = * (uint32_t*)pMvDirect[LIST_1]; | |
| 972 | + ST32 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], LD32 (pMV)); | |
| 973 | + ST32 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0); | |
| 974 | + ST32 (pMotionVector[LIST_1][iCacheIdx], LD32 (pMV)); | |
| 975 | + ST32 (pMvdCache[LIST_1][iCacheIdx], 0); | |
| 976 | + } | |
| 977 | + | |
| 978 | + if ((* (int32_t*)pMvDirect[LIST_0] | * (int32_t*)pMvDirect[LIST_1])) { | |
| 979 | + bool bIsLongRef = pCtx->sRefPic.pRefList[LIST_1][0]->bIsLongRef; | |
| 980 | + uint32_t uiColZeroFlag = (0 == pCurDqLayer->iColocIntra[iColocIdx]) && !bIsLongRef && | |
| 981 | + (pCurDqLayer->iColocRefIndex[LIST_0][iColocIdx] == 0 || (pCurDqLayer->iColocRefIndex[LIST_0][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] : | |
| 984 | + pCurDqLayer->iColocMv[LIST_1]; | |
| 985 | + const int16_t* mv = mvColoc[iColocIdx]; | |
| 986 | + if (IS_SUB_8x8 (pCurDqLayer->pSubMbType[iMbXy][i])) { | |
| 987 | + if (uiColZeroFlag && ((unsigned) (mv[0] + 1) <= 2 && (unsigned) (mv[1] + 1) <= 2)) { | |
| 988 | + if (iRef[LIST_0] == 0) { | |
| 989 | + ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], 0); | |
| 990 | + ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx + 4], 0); | |
| 991 | + ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0); | |
| 992 | + ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx + 4], 0); | |
| 993 | + ST64 (pMotionVector[LIST_0][iCacheIdx], 0); | |
| 994 | + ST64 (pMotionVector[LIST_0][iCacheIdx + 6], 0); | |
| 995 | + ST64 (pMvdCache[LIST_0][iCacheIdx], 0); | |
| 996 | + ST64 (pMvdCache[LIST_0][iCacheIdx + 6], 0); | |
| 997 | + } | |
| 998 | + | |
| 999 | + if (iRef[LIST_1] == 0) { | |
| 1000 | + ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], 0); | |
| 1001 | + ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx + 4], 0); | |
| 1002 | + ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0); | |
| 1003 | + ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx + 4], 0); | |
| 1004 | + ST64 (pMotionVector[LIST_1][iCacheIdx], 0); | |
| 1005 | + ST64 (pMotionVector[LIST_1][iCacheIdx + 6], 0); | |
| 1006 | + ST64 (pMvdCache[LIST_1][iCacheIdx], 0); | |
| 1007 | + ST64 (pMvdCache[LIST_1][iCacheIdx + 6], 0); | |
| 1008 | + } | |
| 1009 | + } | |
| 1010 | + } else { | |
| 1011 | + if (uiColZeroFlag && ((unsigned) (mv[0] + 1) <= 2 && (unsigned) (mv[1] + 1) <= 2)) { | |
| 1012 | + if (iRef[LIST_0] == 0) { | |
| 1013 | + ST32 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], 0); | |
| 1014 | + ST32 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0); | |
| 1015 | + ST32 (pMotionVector[LIST_0][iCacheIdx], 0); | |
| 1016 | + ST32 (pMvdCache[LIST_0][iCacheIdx], 0); | |
| 1017 | + } | |
| 1018 | + if (iRef[LIST_1] == 0) { | |
| 1019 | + ST32 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], 0); | |
| 1020 | + ST32 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0); | |
| 1021 | + ST32 (pMotionVector[LIST_1][iCacheIdx], 0); | |
| 1022 | + ST32 (pMvdCache[LIST_1][iCacheIdx], 0); | |
| 1023 | + } | |
| 1024 | + } | |
| 1025 | + } | |
| 1026 | + } | |
| 1027 | + } else { | |
| 1028 | + int16_t (*mvColoc)[2] = pCurDqLayer->iColocMv[LIST_0]; | |
| 1029 | + int16_t* mv = mvColoc[iColocIdx]; | |
| 1030 | + int16_t pMV[4] = { 0 }; | |
| 1031 | + int16_t iMvp[LIST_A][2]; | |
| 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; | |
| 1034 | + iMvp[LIST_0][1] = (pSlice->iMvScale[LIST_0][iRef[LIST_0]] * mv[1] + 128) >> 8; | |
| 1035 | + ST32 (pMV, LD32 (iMvp[LIST_0])); | |
| 1036 | + ST32 ((pMV + 2), LD32 (iMvp[LIST_0])); | |
| 1037 | + ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], LD64 (pMV)); | |
| 1038 | + ST64 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx + 4], LD64 (pMV)); | |
| 1039 | + ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0); | |
| 1040 | + ST64 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx + 4], 0); | |
| 1041 | + iMvp[LIST_1][0] -= iMvp[LIST_0][0] - mv[0]; | |
| 1042 | + iMvp[LIST_1][1] -= iMvp[LIST_0][0] - mv[1]; | |
| 1043 | + ST32 (pMV, LD32 (iMvp[LIST_1])); | |
| 1044 | + ST32 ((pMV + 2), LD32 (iMvp[LIST_1])); | |
| 1045 | + ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], LD64 (pMV)); | |
| 1046 | + ST64 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx + 4], LD64 (pMV)); | |
| 1047 | + ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0); | |
| 1048 | + ST64 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx + 4], 0); | |
| 1049 | + } else { //SUB_4x4 | |
| 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; | |
| 1052 | + ST32 (pCurDqLayer->pMv[LIST_0][iMbXy][iScan4Idx], LD32 (iMvp[LIST_0])); | |
| 1053 | + ST32 (pCurDqLayer->pMvd[LIST_0][iMbXy][iScan4Idx], 0); | |
| 1054 | + iMvp[LIST_1][0] -= iMvp[LIST_0][0] - mv[0]; | |
| 1055 | + iMvp[LIST_1][1] -= iMvp[LIST_0][0] - mv[1]; | |
| 1056 | + ST32 (pCurDqLayer->pMv[LIST_1][iMbXy][iScan4Idx], LD32 (iMvp[LIST_1])); | |
| 1057 | + ST32 (pCurDqLayer->pMvd[LIST_1][iMbXy][iScan4Idx], 0); | |
| 1058 | + } | |
| 1059 | + } | |
| 1060 | + } | |
| 1061 | + } | |
| 1062 | + } | |
| 1063 | + //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 } }; | |
| 1065 | + for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 1066 | + for (int32_t i = 0; i < 4; i++) { | |
| 1067 | + int16_t iIdx8 = i << 2; | |
| 1068 | + int32_t subMbType = pCurDqLayer->pSubMbType[iMbXy][i]; | |
| 1069 | + int8_t iref = REF_NOT_IN_LIST; | |
| 1070 | + if (IS_DIRECT (subMbType)) { | |
| 1071 | + if (pSliceHeader->iDirectSpatialMvPredFlag) { | |
| 1072 | + iref = iRef[listIdx]; | |
| 1073 | + } else { | |
| 1074 | + iref = 0; | |
| 1075 | + if (listIdx == LIST_0) { | |
| 1076 | + if (!pCurDqLayer->iColocIntra[g_kuiScan4[iIdx8]]) { | |
| 1077 | + if (pCurDqLayer->iColocRefIndex[LIST_0][iIdx8] >= 0) { | |
| 1078 | + iref = pCurDqLayer->iColocRefIndex[LIST_0][iIdx8]; | |
| 1079 | + } else { | |
| 1080 | + iref = pCurDqLayer->iColocRefIndex[LIST_1][iIdx8]; | |
| 1081 | + } | |
| 1082 | + } | |
| 1083 | + } | |
| 1084 | + } | |
| 1085 | + UpdateP8x8DirectCabac (pCurDqLayer, iIdx8); | |
| 1086 | + } else { | |
| 1087 | + if (IS_DIR (subMbType, 0, listIdx)) { | |
| 1088 | + WELS_READ_VERIFY (ParseRefIdxCabac (pCtx, pNeighAvail, pNonZeroCount, pRefIndex, pDirect, listIdx, iIdx8, | |
| 1089 | + pRefCount[listIdx], 1, | |
| 1090 | + iref)); | |
| 1091 | + if ((iref < 0) || (iref >= pRefCount[listIdx]) || (pCtx->sRefPic.pRefList[listIdx][iref] == NULL)) { //error ref_idx | |
| 1092 | + pCtx->bMbRefConcealed = true; | |
| 1093 | + if (pCtx->pParam->eEcActiveIdc != ERROR_CON_DISABLE) { | |
| 1094 | + iref = 0; | |
| 1095 | + pCtx->iErrorCode |= dsBitstreamError; | |
| 1096 | + } else { | |
| 1097 | + return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_REF_INDEX); | |
| 1098 | + } | |
| 1099 | + } | |
| 1100 | + pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (pCtx->sRefPic.pRefList[listIdx][iref] | |
| 1101 | + && pCtx->sRefPic.pRefList[listIdx][iref]->bIsComplete); | |
| 1102 | + } | |
| 1103 | + } | |
| 1104 | + UpdateP8x8RefIdxCabac (pCurDqLayer, pRefIndex, iIdx8, iref, listIdx); | |
| 1105 | + ref_idx_list[listIdx][i] = iref; | |
| 1106 | + } | |
| 1107 | + } | |
| 1108 | + //mv | |
| 1109 | + for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 1110 | + for (int32_t i = 0; i < 4; i++) { | |
| 1111 | + int8_t iPartCount = pSubPartCount[i]; | |
| 1112 | + int16_t iPartIdx, iBlockW = pPartW[i]; | |
| 1113 | + uint8_t iScan4Idx, iCacheIdx; | |
| 1114 | + | |
| 1115 | + iCacheIdx = g_kuiCache30ScanIdx[i << 2]; | |
| 1116 | + | |
| 1117 | + int8_t iref = ref_idx_list[listIdx][i]; | |
| 1118 | + pRefIndex[listIdx][iCacheIdx] = pRefIndex[listIdx][iCacheIdx + 1] | |
| 1119 | + = pRefIndex[listIdx][iCacheIdx + 6] = pRefIndex[listIdx][iCacheIdx + 7] = iref; | |
| 1120 | + | |
| 1121 | + uint32_t subMbType = pCurDqLayer->pSubMbType[iMbXy][i]; | |
| 1122 | + if (IS_DIRECT (subMbType)) { | |
| 1123 | + continue; | |
| 1124 | + } | |
| 1125 | + bool is_dir = IS_DIR (subMbType, 0, listIdx) > 0; | |
| 1126 | + for (int32_t j = 0; j < iPartCount; j++) { | |
| 1127 | + iPartIdx = (i << 2) + j * iBlockW; | |
| 1128 | + iScan4Idx = g_kuiScan4[iPartIdx]; | |
| 1129 | + iCacheIdx = g_kuiCache30ScanIdx[iPartIdx]; | |
| 1130 | + if (is_dir) { | |
| 1131 | + PredMv (pMotionVector, pRefIndex, listIdx, iPartIdx, iBlockW, iref, pMv); | |
| 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])); | |
| 1134 | + pMv[0] += pMvd[0]; | |
| 1135 | + pMv[1] += pMvd[1]; | |
| 1136 | + WELS_CHECK_SE_BOTH_WARNING (pMv[1], iMinVmv, iMaxVmv, "vertical mv"); | |
| 1137 | + } else { | |
| 1138 | + * (uint32_t*)pMv = * (uint32_t*)pMvd = 0; | |
| 1139 | + } | |
| 1140 | + if (IS_SUB_8x8 (subMbType)) { //MB_TYPE_8x8 | |
| 1141 | + ST32 ((pMv + 2), LD32 (pMv)); | |
| 1142 | + ST32 ((pMvd + 2), LD32 (pMvd)); | |
| 1143 | + ST64 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx], LD64 (pMv)); | |
| 1144 | + ST64 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx + 4], LD64 (pMv)); | |
| 1145 | + ST64 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx], LD64 (pMvd)); | |
| 1146 | + ST64 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx + 4], LD64 (pMvd)); | |
| 1147 | + ST64 (pMotionVector[listIdx][iCacheIdx], LD64 (pMv)); | |
| 1148 | + ST64 (pMotionVector[listIdx][iCacheIdx + 6], LD64 (pMv)); | |
| 1149 | + ST64 (pMvdCache[listIdx][iCacheIdx], LD64 (pMvd)); | |
| 1150 | + ST64 (pMvdCache[listIdx][iCacheIdx + 6], LD64 (pMvd)); | |
| 1151 | + } else if (IS_SUB_4x4 (subMbType)) { //MB_TYPE_4x4 | |
| 1152 | + ST32 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx], LD32 (pMv)); | |
| 1153 | + ST32 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx], LD32 (pMvd)); | |
| 1154 | + ST32 (pMotionVector[listIdx][iCacheIdx], LD32 (pMv)); | |
| 1155 | + ST32 (pMvdCache[listIdx][iCacheIdx], LD32 (pMvd)); | |
| 1156 | + } else if (IS_SUB_4x8 (subMbType)) { //MB_TYPE_4x8 5, 7, 9 | |
| 1157 | + ST32 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx], LD32 (pMv)); | |
| 1158 | + ST32 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx + 4], LD32 (pMv)); | |
| 1159 | + ST32 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx], LD32 (pMvd)); | |
| 1160 | + ST32 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx + 4], LD32 (pMvd)); | |
| 1161 | + ST32 (pMotionVector[listIdx][iCacheIdx], LD32 (pMv)); | |
| 1162 | + ST32 (pMotionVector[listIdx][iCacheIdx + 6], LD32 (pMv)); | |
| 1163 | + ST32 (pMvdCache[listIdx][iCacheIdx], LD32 (pMvd)); | |
| 1164 | + ST32 (pMvdCache[listIdx][iCacheIdx + 6], LD32 (pMvd)); | |
| 1165 | + } else { //MB_TYPE_8x4 4, 6, 8 | |
| 1166 | + ST32 ((pMv + 2), LD32 (pMv)); | |
| 1167 | + ST32 ((pMvd + 2), LD32 (pMvd)); | |
| 1168 | + ST64 (pCurDqLayer->pMv[listIdx][iMbXy][iScan4Idx], LD64 (pMv)); | |
| 1169 | + ST64 (pCurDqLayer->pMvd[listIdx][iMbXy][iScan4Idx], LD64 (pMvd)); | |
| 1170 | + ST64 (pMotionVector[listIdx][iCacheIdx], LD64 (pMv)); | |
| 1171 | + ST64 (pMvdCache[listIdx][iCacheIdx], LD64 (pMvd)); | |
| 1172 | + } | |
| 1173 | + } | |
| 1174 | + } | |
| 1175 | + } | |
| 1176 | + } | |
| 1177 | + return ERR_NONE; | |
| 1178 | +} | |
| 1179 | + | |
| 1180 | +int32_t ParseRefIdxCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint8_t* nzc, | |
| 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) { | |
| 1183 | + if (iActiveRefNum == 1) { | |
| 1184 | + iRefIdxVal = 0; | |
| 1185 | + return ERR_NONE; | |
| 1186 | + } | |
| 1187 | + uint32_t uiCode; | |
| 1188 | + int32_t iIdxA = 0, iIdxB = 0; | |
| 1189 | + int32_t iCtxInc = 0; | |
| 1190 | + int8_t* pRefIdxInMB = pCtx->pCurDqLayer->pRefIndex[iListIdx][pCtx->pCurDqLayer->iMbXyIndex]; | |
| 1191 | + int8_t* pDirect = pCtx->pCurDqLayer->pDirect[pCtx->pCurDqLayer->iMbXyIndex]; | |
| 1192 | + if (iZOrderIdx == 0) { | |
| 1193 | + iIdxB = (pNeighAvail->iTopAvail && pNeighAvail->iTopType != MB_TYPE_INTRA_PCM | |
| 1194 | + && ref_idx[iListIdx][g_kuiCache30ScanIdx[iZOrderIdx] - 6] > 0); | |
| 1195 | + iIdxA = (pNeighAvail->iLeftAvail && pNeighAvail->iLeftType != MB_TYPE_INTRA_PCM | |
| 1196 | + && ref_idx[iListIdx][g_kuiCache30ScanIdx[iZOrderIdx] - 1] > 0); | |
| 1197 | + if (pCtx->eSliceType == B_SLICE) { | |
| 1198 | + if (iIdxB > 0 && direct[g_kuiCache30ScanIdx[iZOrderIdx] - 6] == 0) { | |
| 1199 | + iCtxInc += 2; | |
| 1200 | + } | |
| 1201 | + if (iIdxA > 0 && direct[g_kuiCache30ScanIdx[iZOrderIdx] - 1] == 0) { | |
| 1202 | + iCtxInc++; | |
| 1203 | + } | |
| 1204 | + } | |
| 1205 | + } else if (iZOrderIdx == 4) { | |
| 1206 | + iIdxB = (pNeighAvail->iTopAvail && pNeighAvail->iTopType != MB_TYPE_INTRA_PCM | |
| 1207 | + && ref_idx[iListIdx][g_kuiCache30ScanIdx[iZOrderIdx] - 6] > 0); | |
| 1208 | + iIdxA = pRefIdxInMB[g_kuiScan4[iZOrderIdx] - 1] > 0; | |
| 1209 | + if (pCtx->eSliceType == B_SLICE) { | |
| 1210 | + if (iIdxB > 0 && direct[g_kuiCache30ScanIdx[iZOrderIdx] - 6] == 0) { | |
| 1211 | + iCtxInc += 2; | |
| 1212 | + } | |
| 1213 | + if (iIdxA > 0 && pDirect[g_kuiScan4[iZOrderIdx] - 1] == 0) { | |
| 1214 | + iCtxInc ++; | |
| 1215 | + } | |
| 1216 | + } | |
| 1217 | + } else if (iZOrderIdx == 8) { | |
| 1218 | + | |
| 1219 | + iIdxB = pRefIdxInMB[g_kuiScan4[iZOrderIdx] - 4] > 0; | |
| 1220 | + iIdxA = (pNeighAvail->iLeftAvail && pNeighAvail->iLeftType != MB_TYPE_INTRA_PCM | |
| 1221 | + && ref_idx[iListIdx][g_kuiCache30ScanIdx[iZOrderIdx] - 1] > 0); | |
| 1222 | + if (pCtx->eSliceType == B_SLICE) { | |
| 1223 | + if (iIdxB > 0 && pDirect[g_kuiScan4[iZOrderIdx] - 4] == 0) { | |
| 1224 | + iCtxInc += 2; | |
| 1225 | + } | |
| 1226 | + if (iIdxA > 0 && direct[g_kuiCache30ScanIdx[iZOrderIdx] - 1] == 0) { | |
| 1227 | + iCtxInc++; | |
| 1228 | + } | |
| 1229 | + } | |
| 1230 | + } else { | |
| 1231 | + iIdxB = pRefIdxInMB[g_kuiScan4[iZOrderIdx] - 4] > 0; | |
| 1232 | + iIdxA = pRefIdxInMB[g_kuiScan4[iZOrderIdx] - 1] > 0; | |
| 1233 | + if (pCtx->eSliceType == B_SLICE) { | |
| 1234 | + if (iIdxB > 0 && pDirect[g_kuiScan4[iZOrderIdx] - 4] == 0) { | |
| 1235 | + iCtxInc += 2; | |
| 1236 | + } | |
| 1237 | + if (iIdxA > 0 && pDirect[g_kuiScan4[iZOrderIdx] - 1] == 0) { | |
| 1238 | + iCtxInc++; | |
| 1239 | + } | |
| 1240 | + } | |
| 1241 | + } | |
| 1242 | + if (pCtx->eSliceType != B_SLICE) { | |
| 1243 | + iCtxInc = iIdxA + (iIdxB << 1); | |
| 1244 | + } | |
| 1245 | + | |
| 1246 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_REF_NO + iCtxInc, uiCode)); | |
| 1247 | + if (uiCode) { | |
| 1248 | + WELS_READ_VERIFY (DecodeUnaryBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_REF_NO + 4, 1, uiCode)); | |
| 1249 | + ++uiCode; | |
| 1250 | + } | |
| 1251 | + iRefIdxVal = (int8_t) uiCode; | |
| 1252 | + return ERR_NONE; | |
| 1253 | +} | |
| 1254 | + | |
| 1255 | +int32_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) { | |
| 1257 | + uint32_t uiCode; | |
| 1258 | + int32_t iIdxA = 0; | |
| 1259 | + //int32_t sym; | |
| 1260 | + PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_MVD + iMvComp * CTX_NUM_MVD; | |
| 1261 | + iMvdVal = 0; | |
| 1262 | + | |
| 1263 | + if (pRefIndex[iListIdx][g_kuiCache30ScanIdx[index] - 6] >= 0) | |
| 1264 | + iIdxA = WELS_ABS (pMvdCache[iListIdx][g_kuiCache30ScanIdx[index] - 6][iMvComp]); | |
| 1265 | + if (pRefIndex[iListIdx][g_kuiCache30ScanIdx[index] - 1] >= 0) | |
| 1266 | + iIdxA += WELS_ABS (pMvdCache[iListIdx][g_kuiCache30ScanIdx[index] - 1][iMvComp]); | |
| 1267 | + | |
| 1268 | + int32_t iCtxInc = 0; | |
| 1269 | + if (iIdxA >= 3) | |
| 1270 | + iCtxInc = 1 + (iIdxA > 32); | |
| 1271 | + | |
| 1272 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pBinCtx + iCtxInc, uiCode)); | |
| 1273 | + if (uiCode) { | |
| 1274 | + WELS_READ_VERIFY (DecodeUEGMvCabac (pCtx->pCabacDecEngine, pBinCtx + 3, 3, uiCode)); | |
| 1275 | + iMvdVal = (int16_t) (uiCode + 1); | |
| 1276 | + WELS_READ_VERIFY (DecodeBypassCabac (pCtx->pCabacDecEngine, uiCode)); | |
| 1277 | + if (uiCode) { | |
| 1278 | + iMvdVal = -iMvdVal; | |
| 1279 | + } | |
| 1280 | + } else { | |
| 1281 | + iMvdVal = 0; | |
| 1282 | + } | |
| 1283 | + return ERR_NONE; | |
| 1284 | +} | |
| 1285 | + | |
| 1286 | +int32_t ParseCbpInfoCabac (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiCbp) { | |
| 1287 | + int32_t iIdxA = 0, iIdxB = 0, pALeftMb[2], pBTopMb[2]; | |
| 1288 | + uiCbp = 0; | |
| 1289 | + uint32_t pCbpBit[6]; | |
| 1290 | + int32_t iCtxInc; | |
| 1291 | + | |
| 1292 | + //Luma: bit by bit for 4 8x8 blocks in z-order | |
| 1293 | + pBTopMb[0] = pNeighAvail->iTopAvail && pNeighAvail->iTopType != MB_TYPE_INTRA_PCM | |
| 1294 | + && ((pNeighAvail->iTopCbp & (1 << 2)) == 0); | |
| 1295 | + pBTopMb[1] = pNeighAvail->iTopAvail && pNeighAvail->iTopType != MB_TYPE_INTRA_PCM | |
| 1296 | + && ((pNeighAvail->iTopCbp & (1 << 3)) == 0); | |
| 1297 | + pALeftMb[0] = pNeighAvail->iLeftAvail && pNeighAvail->iLeftType != MB_TYPE_INTRA_PCM | |
| 1298 | + && ((pNeighAvail->iLeftCbp & (1 << 1)) == 0); | |
| 1299 | + pALeftMb[1] = pNeighAvail->iLeftAvail && pNeighAvail->iLeftType != MB_TYPE_INTRA_PCM | |
| 1300 | + && ((pNeighAvail->iLeftCbp & (1 << 3)) == 0); | |
| 1301 | + | |
| 1302 | + //left_top 8x8 block | |
| 1303 | + iCtxInc = pALeftMb[0] + (pBTopMb[0] << 1); | |
| 1304 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + iCtxInc, pCbpBit[0])); | |
| 1305 | + if (pCbpBit[0]) | |
| 1306 | + uiCbp += 0x01; | |
| 1307 | + | |
| 1308 | + //right_top 8x8 block | |
| 1309 | + iIdxA = !pCbpBit[0]; | |
| 1310 | + iCtxInc = iIdxA + (pBTopMb[1] << 1); | |
| 1311 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + iCtxInc, pCbpBit[1])); | |
| 1312 | + if (pCbpBit[1]) | |
| 1313 | + uiCbp += 0x02; | |
| 1314 | + | |
| 1315 | + //left_bottom 8x8 block | |
| 1316 | + iIdxB = !pCbpBit[0]; | |
| 1317 | + iCtxInc = pALeftMb[1] + (iIdxB << 1); | |
| 1318 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + iCtxInc, pCbpBit[2])); | |
| 1319 | + if (pCbpBit[2]) | |
| 1320 | + uiCbp += 0x04; | |
| 1321 | + | |
| 1322 | + //right_bottom 8x8 block | |
| 1323 | + iIdxB = !pCbpBit[1]; | |
| 1324 | + iIdxA = !pCbpBit[2]; | |
| 1325 | + iCtxInc = iIdxA + (iIdxB << 1); | |
| 1326 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + iCtxInc, pCbpBit[3])); | |
| 1327 | + if (pCbpBit[3]) | |
| 1328 | + uiCbp += 0x08; | |
| 1329 | + | |
| 1330 | + if (pCtx->pSps->uiChromaFormatIdc == 0)//monochroma | |
| 1331 | + return ERR_NONE; | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + //Chroma: bit by bit | |
| 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)); | |
| 1337 | + | |
| 1338 | + //BitIdx = 0 | |
| 1339 | + iCtxInc = iIdxA + (iIdxB << 1); | |
| 1340 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + CTX_NUM_CBP + iCtxInc, | |
| 1341 | + pCbpBit[4])); | |
| 1342 | + | |
| 1343 | + //BitIdx = 1 | |
| 1344 | + if (pCbpBit[4]) { | |
| 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); | |
| 1347 | + iCtxInc = iIdxA + (iIdxB << 1); | |
| 1348 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, | |
| 1349 | + pCtx->pCabacCtx + NEW_CTX_OFFSET_CBP + 2 * CTX_NUM_CBP + iCtxInc, | |
| 1350 | + pCbpBit[5])); | |
| 1351 | + uiCbp += 1 << (4 + pCbpBit[5]); | |
| 1352 | + | |
| 1353 | + } | |
| 1354 | + | |
| 1355 | + return ERR_NONE; | |
| 1356 | +} | |
| 1357 | + | |
| 1358 | +int32_t ParseDeltaQpCabac (PWelsDecoderContext pCtx, int32_t& iQpDelta) { | |
| 1359 | + uint32_t uiCode; | |
| 1360 | + PSlice pCurrSlice = & (pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer); | |
| 1361 | + iQpDelta = 0; | |
| 1362 | + PWelsCabacCtx pBinCtx = pCtx->pCabacCtx + NEW_CTX_OFFSET_DELTA_QP; | |
| 1363 | + int32_t iCtxInc = (pCurrSlice->iLastDeltaQp != 0); | |
| 1364 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pBinCtx + iCtxInc, uiCode)); | |
| 1365 | + if (uiCode != 0) { | |
| 1366 | + WELS_READ_VERIFY (DecodeUnaryBinCabac (pCtx->pCabacDecEngine, pBinCtx + 2, 1, uiCode)); | |
| 1367 | + uiCode++; | |
| 1368 | + iQpDelta = (uiCode + 1) >> 1; | |
| 1369 | + if ((uiCode & 1) == 0) | |
| 1370 | + iQpDelta = - iQpDelta; | |
| 1371 | + } | |
| 1372 | + pCurrSlice->iLastDeltaQp = iQpDelta; | |
| 1373 | + return ERR_NONE; | |
| 1374 | +} | |
| 1375 | + | |
| 1376 | +int32_t ParseCbfInfoCabac (PWelsNeighAvail pNeighAvail, uint8_t* pNzcCache, int32_t iZIndex, int32_t iResProperty, | |
| 1377 | + PWelsDecoderContext pCtx, uint32_t& uiCbfBit) { | |
| 1378 | + int8_t nA, nB/*, zigzag_idx = 0*/; | |
| 1379 | + int32_t iCurrBlkXy = pCtx->pCurDqLayer->iMbXyIndex; | |
| 1380 | + int32_t iTopBlkXy = iCurrBlkXy - pCtx->pCurDqLayer->iMbWidth; //default value: MB neighboring | |
| 1381 | + int32_t iLeftBlkXy = iCurrBlkXy - 1; //default value: MB neighboring | |
| 1382 | + uint16_t* pCbfDc = pCtx->pCurDqLayer->pCbfDc; | |
| 1383 | + uint32_t* pMbType = pCtx->pCurDqLayer->pMbType; | |
| 1384 | + int32_t iCtxInc; | |
| 1385 | + uiCbfBit = 0; | |
| 1386 | + nA = nB = (int8_t)!!IS_INTRA (pMbType[iCurrBlkXy]); | |
| 1387 | + | |
| 1388 | + if (iResProperty == I16_LUMA_DC || iResProperty == CHROMA_DC_U || iResProperty == CHROMA_DC_V) { //DC | |
| 1389 | + if (pNeighAvail->iTopAvail) | |
| 1390 | + nB = (pMbType[iTopBlkXy] == MB_TYPE_INTRA_PCM) || ((pCbfDc[iTopBlkXy] >> iResProperty) & 1); | |
| 1391 | + if (pNeighAvail->iLeftAvail) | |
| 1392 | + nA = (pMbType[iLeftBlkXy] == MB_TYPE_INTRA_PCM) || ((pCbfDc[iLeftBlkXy] >> iResProperty) & 1); | |
| 1393 | + iCtxInc = nA + (nB << 1); | |
| 1394 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, | |
| 1395 | + pCtx->pCabacCtx + NEW_CTX_OFFSET_CBF + g_kBlockCat2CtxOffsetCBF[iResProperty] + iCtxInc, uiCbfBit)); | |
| 1396 | + if (uiCbfBit) | |
| 1397 | + pCbfDc[iCurrBlkXy] |= (1 << iResProperty); | |
| 1398 | + } else { //AC | |
| 1399 | + //for 4x4 blk, make sure blk-idx is correct | |
| 1400 | + if (pNzcCache[g_kCacheNzcScanIdx[iZIndex] - 8] != 0xff) { //top blk available | |
| 1401 | + if (g_kTopBlkInsideMb[iZIndex]) | |
| 1402 | + iTopBlkXy = iCurrBlkXy; | |
| 1403 | + nB = pNzcCache[g_kCacheNzcScanIdx[iZIndex] - 8] || pMbType[iTopBlkXy] == MB_TYPE_INTRA_PCM; | |
| 1404 | + } | |
| 1405 | + if (pNzcCache[g_kCacheNzcScanIdx[iZIndex] - 1] != 0xff) { //left blk available | |
| 1406 | + if (g_kLeftBlkInsideMb[iZIndex]) | |
| 1407 | + iLeftBlkXy = iCurrBlkXy; | |
| 1408 | + nA = pNzcCache[g_kCacheNzcScanIdx[iZIndex] - 1] || pMbType[iLeftBlkXy] == MB_TYPE_INTRA_PCM; | |
| 1409 | + } | |
| 1410 | + | |
| 1411 | + iCtxInc = nA + (nB << 1); | |
| 1412 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, | |
| 1413 | + pCtx->pCabacCtx + NEW_CTX_OFFSET_CBF + g_kBlockCat2CtxOffsetCBF[iResProperty] + iCtxInc, uiCbfBit)); | |
| 1414 | + } | |
| 1415 | + return ERR_NONE; | |
| 1416 | +} | |
| 1417 | + | |
| 1418 | +int32_t ParseSignificantMapCabac (int32_t* pSignificantMap, int32_t iResProperty, PWelsDecoderContext pCtx, | |
| 1419 | + uint32_t& uiCoeffNum) { | |
| 1420 | + uint32_t uiCode; | |
| 1421 | + | |
| 1422 | + PWelsCabacCtx pMapCtx = pCtx->pCabacCtx + (iResProperty == LUMA_DC_AC_8 ? NEW_CTX_OFFSET_MAP_8x8 : NEW_CTX_OFFSET_MAP) | |
| 1423 | + + g_kBlockCat2CtxOffsetMap [iResProperty]; | |
| 1424 | + PWelsCabacCtx pLastCtx = pCtx->pCabacCtx + (iResProperty == LUMA_DC_AC_8 ? NEW_CTX_OFFSET_LAST_8x8 : | |
| 1425 | + NEW_CTX_OFFSET_LAST) + g_kBlockCat2CtxOffsetLast[iResProperty]; | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + int32_t i; | |
| 1429 | + uiCoeffNum = 0; | |
| 1430 | + int32_t i0 = 0; | |
| 1431 | + int32_t i1 = g_kMaxPos[iResProperty]; | |
| 1432 | + | |
| 1433 | + int32_t iCtx; | |
| 1434 | + | |
| 1435 | + for (i = i0; i < i1; ++i) { | |
| 1436 | + iCtx = (iResProperty == LUMA_DC_AC_8 ? g_kuiIdx2CtxSignificantCoeffFlag8x8[i] : i); | |
| 1437 | + //read significant | |
| 1438 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pMapCtx + iCtx, uiCode)); | |
| 1439 | + if (uiCode) { | |
| 1440 | + * (pSignificantMap++) = 1; | |
| 1441 | + ++ uiCoeffNum; | |
| 1442 | + //read last significant | |
| 1443 | + iCtx = (iResProperty == LUMA_DC_AC_8 ? g_kuiIdx2CtxLastSignificantCoeffFlag8x8[i] : i); | |
| 1444 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pLastCtx + iCtx, uiCode)); | |
| 1445 | + if (uiCode) { | |
| 1446 | + memset (pSignificantMap, 0, (i1 - i) * sizeof (int32_t)); | |
| 1447 | + return ERR_NONE; | |
| 1448 | + } | |
| 1449 | + } else | |
| 1450 | + * (pSignificantMap++) = 0; | |
| 1451 | + } | |
| 1452 | + | |
| 1453 | + //deal with last pSignificantMap if no data | |
| 1454 | + //if(i < i1+1) | |
| 1455 | + { | |
| 1456 | + *pSignificantMap = 1; | |
| 1457 | + ++uiCoeffNum; | |
| 1458 | + } | |
| 1459 | + | |
| 1460 | + return ERR_NONE; | |
| 1461 | +} | |
| 1462 | + | |
| 1463 | +int32_t ParseSignificantCoeffCabac (int32_t* pSignificant, int32_t iResProperty, PWelsDecoderContext pCtx) { | |
| 1464 | + uint32_t uiCode; | |
| 1465 | + PWelsCabacCtx pOneCtx = pCtx->pCabacCtx + (iResProperty == LUMA_DC_AC_8 ? NEW_CTX_OFFSET_ONE_8x8 : NEW_CTX_OFFSET_ONE) + | |
| 1466 | + g_kBlockCat2CtxOffsetOne[iResProperty]; | |
| 1467 | + PWelsCabacCtx pAbsCtx = pCtx->pCabacCtx + (iResProperty == LUMA_DC_AC_8 ? NEW_CTX_OFFSET_ABS_8x8 : NEW_CTX_OFFSET_ABS) + | |
| 1468 | + g_kBlockCat2CtxOffsetAbs[iResProperty]; | |
| 1469 | + | |
| 1470 | + const int16_t iMaxType = g_kMaxC2[iResProperty]; | |
| 1471 | + int32_t i = g_kMaxPos[iResProperty]; | |
| 1472 | + int32_t* pCoff = pSignificant + i; | |
| 1473 | + int32_t c1 = 1; | |
| 1474 | + int32_t c2 = 0; | |
| 1475 | + for (; i >= 0; --i) { | |
| 1476 | + if (*pCoff != 0) { | |
| 1477 | + WELS_READ_VERIFY (DecodeBinCabac (pCtx->pCabacDecEngine, pOneCtx + c1, uiCode)); | |
| 1478 | + *pCoff += uiCode; | |
| 1479 | + if (*pCoff == 2) { | |
| 1480 | + WELS_READ_VERIFY (DecodeUEGLevelCabac (pCtx->pCabacDecEngine, pAbsCtx + c2, uiCode)); | |
| 1481 | + *pCoff += uiCode; | |
| 1482 | + ++c2; | |
| 1483 | + c2 = WELS_MIN (c2, iMaxType); | |
| 1484 | + c1 = 0; | |
| 1485 | + } else if (c1) { | |
| 1486 | + ++c1; | |
| 1487 | + c1 = WELS_MIN (c1, 4); | |
| 1488 | + } | |
| 1489 | + WELS_READ_VERIFY (DecodeBypassCabac (pCtx->pCabacDecEngine, uiCode)); | |
| 1490 | + if (uiCode) | |
| 1491 | + *pCoff = - *pCoff; | |
| 1492 | + } | |
| 1493 | + pCoff--; | |
| 1494 | + } | |
| 1495 | + return ERR_NONE; | |
| 1496 | +} | |
| 1497 | + | |
| 1498 | +int32_t ParseResidualBlockCabac8x8 (PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCountCache, SBitStringAux* pBsAux, | |
| 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) { | |
| 1501 | + uint32_t uiTotalCoeffNum = 0; | |
| 1502 | + uint32_t uiCbpBit; | |
| 1503 | + int32_t pSignificantMap[64] = {0}; | |
| 1504 | + | |
| 1505 | + int32_t iMbResProperty = 0; | |
| 1506 | + GetMbResProperty (&iMbResProperty, &iResProperty, false); | |
| 1507 | + const uint16_t* pDeQuantMul = (pCtx->bUseScalingList) ? pCtx->pDequant_coeff8x8[iMbResProperty - 6][uiQp] : | |
| 1508 | + g_kuiDequantCoeff8x8[uiQp]; | |
| 1509 | + | |
| 1510 | + uiCbpBit = 1; // for 8x8, MaxNumCoeff == 64 && uiCbpBit == 1 | |
| 1511 | + if (uiCbpBit) { //has coeff | |
| 1512 | + WELS_READ_VERIFY (ParseSignificantMapCabac (pSignificantMap, iResProperty, pCtx, uiTotalCoeffNum)); | |
| 1513 | + WELS_READ_VERIFY (ParseSignificantCoeffCabac (pSignificantMap, iResProperty, pCtx)); | |
| 1514 | + } | |
| 1515 | + | |
| 1516 | + pNonZeroCountCache[g_kCacheNzcScanIdx[iIndex]] = | |
| 1517 | + pNonZeroCountCache[g_kCacheNzcScanIdx[iIndex + 1]] = | |
| 1518 | + pNonZeroCountCache[g_kCacheNzcScanIdx[iIndex + 2]] = | |
| 1519 | + pNonZeroCountCache[g_kCacheNzcScanIdx[iIndex + 3]] = (uint8_t)uiTotalCoeffNum; | |
| 1520 | + if (uiTotalCoeffNum == 0) { | |
| 1521 | + return ERR_NONE; | |
| 1522 | + } | |
| 1523 | + int32_t j = 0, i; | |
| 1524 | + if (iResProperty == LUMA_DC_AC_8) { | |
| 1525 | + do { | |
| 1526 | + if (pSignificantMap[j] != 0) { | |
| 1527 | + i = pScanTable[ j ]; | |
| 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)); | |
| 1530 | + } | |
| 1531 | + ++j; | |
| 1532 | + } while (j < 64); | |
| 1533 | + } | |
| 1534 | + | |
| 1535 | + return ERR_NONE; | |
| 1536 | +} | |
| 1537 | + | |
| 1538 | +int32_t ParseResidualBlockCabac (PWelsNeighAvail pNeighAvail, uint8_t* pNonZeroCountCache, SBitStringAux* pBsAux, | |
| 1539 | + int32_t iIndex, int32_t iMaxNumCoeff, | |
| 1540 | + const uint8_t* pScanTable, int32_t iResProperty, short* sTCoeff, /*int mb_mode*/ uint8_t uiQp, | |
| 1541 | + PWelsDecoderContext pCtx) { | |
| 1542 | + int32_t iCurNzCacheIdx; | |
| 1543 | + uint32_t uiTotalCoeffNum = 0; | |
| 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}; | |
| 1546 | + | |
| 1547 | + int32_t iMbResProperty = 0; | |
| 1548 | + GetMbResProperty (&iMbResProperty, &iResProperty, false); | |
| 1549 | + const uint16_t* pDeQuantMul = (pCtx->bUseScalingList) ? pCtx->pDequant_coeff4x4[iMbResProperty][uiQp] : | |
| 1550 | + g_kuiDequantCoeff[uiQp]; | |
| 1551 | + | |
| 1552 | + WELS_READ_VERIFY (ParseCbfInfoCabac (pNeighAvail, pNonZeroCountCache, iIndex, iResProperty, pCtx, uiCbpBit)); | |
| 1553 | + if (uiCbpBit) { //has coeff | |
| 1554 | + WELS_READ_VERIFY (ParseSignificantMapCabac (pSignificantMap, iResProperty, pCtx, uiTotalCoeffNum)); | |
| 1555 | + WELS_READ_VERIFY (ParseSignificantCoeffCabac (pSignificantMap, iResProperty, pCtx)); | |
| 1556 | + } | |
| 1557 | + | |
| 1558 | + iCurNzCacheIdx = g_kCacheNzcScanIdx[iIndex]; | |
| 1559 | + pNonZeroCountCache[iCurNzCacheIdx] = (uint8_t)uiTotalCoeffNum; | |
| 1560 | + if (uiTotalCoeffNum == 0) { | |
| 1561 | + return ERR_NONE; | |
| 1562 | + } | |
| 1563 | + int32_t j = 0; | |
| 1564 | + if (iResProperty == I16_LUMA_DC) { | |
| 1565 | + do { | |
| 1566 | + sTCoeff[pScanTable[j]] = pSignificantMap[j]; | |
| 1567 | + ++j; | |
| 1568 | + } while (j < 16); | |
| 1569 | + WelsLumaDcDequantIdct (sTCoeff, uiQp, pCtx); | |
| 1570 | + } else if (iResProperty == CHROMA_DC_U || iResProperty == CHROMA_DC_V) { | |
| 1571 | + do { | |
| 1572 | + sTCoeff[pScanTable[j]] = pSignificantMap[j]; | |
| 1573 | + ++j; | |
| 1574 | + } while (j < 4); | |
| 1575 | + //iHadamard2x2 | |
| 1576 | + WelsChromaDcIdct (sTCoeff); | |
| 1577 | + //scaling | |
| 1578 | + if (!pCtx->bUseScalingList) { | |
| 1579 | + for (j = 0; j < 4; ++j) { | |
| 1580 | + sTCoeff[pScanTable[j]] = (int16_t) ((int64_t)sTCoeff[pScanTable[j]] * (int64_t)pDeQuantMul[0] >> 1); | |
| 1581 | + } | |
| 1582 | + } else { //with scaling list | |
| 1583 | + for (j = 0; j < 4; ++j) { | |
| 1584 | + sTCoeff[pScanTable[j]] = (int16_t) ((int64_t)sTCoeff[pScanTable[j]] * (int64_t)pDeQuantMul[0] >> 5); | |
| 1585 | + } | |
| 1586 | + } | |
| 1587 | + } else { //luma ac, chroma ac | |
| 1588 | + do { | |
| 1589 | + if (pSignificantMap[j] != 0) { | |
| 1590 | + if (!pCtx->bUseScalingList) { | |
| 1591 | + sTCoeff[pScanTable[j]] = pSignificantMap[j] * pDeQuantMul[pScanTable[j] & 0x07]; | |
| 1592 | + } else { | |
| 1593 | + sTCoeff[pScanTable[j]] = (int16_t) (((int64_t)pSignificantMap[j] * (int64_t)pDeQuantMul[pScanTable[j]] + 8) >> 4); | |
| 1594 | + } | |
| 1595 | + } | |
| 1596 | + ++j; | |
| 1597 | + } while (j < 16); | |
| 1598 | + } | |
| 1599 | + return ERR_NONE; | |
| 1600 | +} | |
| 1601 | + | |
| 1602 | +int32_t ParseIPCMInfoCabac (PWelsDecoderContext pCtx) { | |
| 1603 | + int32_t i; | |
| 1604 | + PWelsCabacDecEngine pCabacDecEngine = pCtx->pCabacDecEngine; | |
| 1605 | + SBitStringAux* pBsAux = pCtx->pCurDqLayer->pBitStringAux; | |
| 1606 | + SDqLayer* pCurLayer = pCtx->pCurDqLayer; | |
| 1607 | + int32_t iDstStrideLuma = pCurLayer->pDec->iLinesize[0]; | |
| 1608 | + int32_t iDstStrideChroma = pCurLayer->pDec->iLinesize[1]; | |
| 1609 | + int32_t iMbX = pCurLayer->iMbX; | |
| 1610 | + int32_t iMbY = pCurLayer->iMbY; | |
| 1611 | + int32_t iMbXy = pCurLayer->iMbXyIndex; | |
| 1612 | + | |
| 1613 | + int32_t iMbOffsetLuma = (iMbX + iMbY * iDstStrideLuma) << 4; | |
| 1614 | + int32_t iMbOffsetChroma = (iMbX + iMbY * iDstStrideChroma) << 3; | |
| 1615 | + | |
| 1616 | + uint8_t* pMbDstY = pCtx->pDec->pData[0] + iMbOffsetLuma; | |
| 1617 | + uint8_t* pMbDstU = pCtx->pDec->pData[1] + iMbOffsetChroma; | |
| 1618 | + uint8_t* pMbDstV = pCtx->pDec->pData[2] + iMbOffsetChroma; | |
| 1619 | + | |
| 1620 | + uint8_t* pPtrSrc; | |
| 1621 | + | |
| 1622 | + pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA_PCM; | |
| 1623 | + RestoreCabacDecEngineToBS (pCabacDecEngine, pBsAux); | |
| 1624 | + intX_t iBytesLeft = pBsAux->pEndBuf - pBsAux->pCurBuf; | |
| 1625 | + if (iBytesLeft < 384) { | |
| 1626 | + return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_CABAC_NO_BS_TO_READ); | |
| 1627 | + } | |
| 1628 | + pPtrSrc = pBsAux->pCurBuf; | |
| 1629 | + if (!pCtx->pParam->bParseOnly) { | |
| 1630 | + for (i = 0; i < 16; i++) { //luma | |
| 1631 | + memcpy (pMbDstY, pPtrSrc, 16); | |
| 1632 | + pMbDstY += iDstStrideLuma; | |
| 1633 | + pPtrSrc += 16; | |
| 1634 | + } | |
| 1635 | + for (i = 0; i < 8; i++) { //cb | |
| 1636 | + memcpy (pMbDstU, pPtrSrc, 8); | |
| 1637 | + pMbDstU += iDstStrideChroma; | |
| 1638 | + pPtrSrc += 8; | |
| 1639 | + } | |
| 1640 | + for (i = 0; i < 8; i++) { //cr | |
| 1641 | + memcpy (pMbDstV, pPtrSrc, 8); | |
| 1642 | + pMbDstV += iDstStrideChroma; | |
| 1643 | + pPtrSrc += 8; | |
| 1644 | + } | |
| 1645 | + } | |
| 1646 | + | |
| 1647 | + pBsAux->pCurBuf += 384; | |
| 1648 | + | |
| 1649 | + pCurLayer->pLumaQp[iMbXy] = 0; | |
| 1650 | + pCurLayer->pChromaQp[iMbXy][0] = pCurLayer->pChromaQp[iMbXy][1] = 0; | |
| 1651 | + memset (pCurLayer->pNzc[iMbXy], 16, sizeof (pCurLayer->pNzc[iMbXy])); | |
| 1652 | + | |
| 1653 | + //step 4: cabac engine init | |
| 1654 | + WELS_READ_VERIFY (InitReadBits (pBsAux, 1)); | |
| 1655 | + WELS_READ_VERIFY (InitCabacDecEngineFromBS (pCabacDecEngine, pBsAux)); | |
| 1656 | + return ERR_NONE; | |
| 1657 | +} | |
| 1658 | +} | |
| @@ -1,1044 +1,1044 @@ | ||
| 1 | −/*! | |
| 2 | − * \copy | |
| 3 | − * Copyright (c) 2009-2013, Cisco Systems | |
| 4 | − * All rights reserved. | |
| 5 | − * | |
| 6 | − * Redistribution and use in source and binary forms, with or without | |
| 7 | − * modification, are permitted provided that the following conditions | |
| 8 | − * are met: | |
| 9 | − * | |
| 10 | − * * Redistributions of source code must retain the above copyright | |
| 11 | − * notice, this list of conditions and the following disclaimer. | |
| 12 | − * | |
| 13 | − * * Redistributions in binary form must reproduce the above copyright | |
| 14 | − * notice, this list of conditions and the following disclaimer in | |
| 15 | − * the documentation and/or other materials provided with the | |
| 16 | − * distribution. | |
| 17 | − * | |
| 18 | − * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 | − * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 | − * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 21 | − * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 22 | − * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 23 | − * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 24 | − * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 | − * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 26 | − * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 | − * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
| 28 | − * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | − * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | − * | |
| 31 | − * | |
| 32 | − * \file rec_mb.c | |
| 33 | − * | |
| 34 | − * \brief implementation for all macroblock decoding process after mb syntax parsing and residual decoding with cavlc. | |
| 35 | − * | |
| 36 | − * \date 3/18/2009 Created | |
| 37 | − * | |
| 38 | − ************************************************************************************* | |
| 39 | − */ | |
| 40 | − | |
| 41 | − | |
| 42 | −#include "rec_mb.h" | |
| 43 | −#include "decode_slice.h" | |
| 44 | − | |
| 45 | −namespace WelsDec { | |
| 46 | − | |
| 47 | −void WelsFillRecNeededMbInfo (PWelsDecoderContext pCtx, bool bOutput, PDqLayer pCurLayer) { | |
| 48 | − PPicture pCurPic = pCtx->pDec; | |
| 49 | − int32_t iLumaStride = pCurPic->iLinesize[0]; | |
| 50 | − int32_t iChromaStride = pCurPic->iLinesize[1]; | |
| 51 | − int32_t iMbX = pCurLayer->iMbX; | |
| 52 | − int32_t iMbY = pCurLayer->iMbY; | |
| 53 | − | |
| 54 | − pCurLayer->iLumaStride = iLumaStride; | |
| 55 | − pCurLayer->iChromaStride = iChromaStride; | |
| 56 | − | |
| 57 | − if (bOutput) { | |
| 58 | − pCurLayer->pPred[0] = pCurPic->pData[0] + ((iMbY * iLumaStride + iMbX) << 4); | |
| 59 | − pCurLayer->pPred[1] = pCurPic->pData[1] + ((iMbY * iChromaStride + iMbX) << 3); | |
| 60 | − pCurLayer->pPred[2] = pCurPic->pData[2] + ((iMbY * iChromaStride + iMbX) << 3); | |
| 61 | − } | |
| 62 | −} | |
| 63 | − | |
| 64 | −int32_t RecI8x8Mb (int32_t iMbXy, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 65 | − RecI8x8Luma (iMbXy, pCtx, pScoeffLevel, pDqLayer); | |
| 66 | − RecI4x4Chroma (iMbXy, pCtx, pScoeffLevel, pDqLayer); | |
| 67 | − return ERR_NONE; | |
| 68 | −} | |
| 69 | − | |
| 70 | −int32_t RecI8x8Luma (int32_t iMbXy, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 71 | − /*****get local variable from outer variable********/ | |
| 72 | − /*prediction info*/ | |
| 73 | − uint8_t* pPred = pDqLayer->pPred[0]; | |
| 74 | − | |
| 75 | − int32_t iLumaStride = pDqLayer->iLumaStride; | |
| 76 | − int32_t* pBlockOffset = pCtx->iDecBlockOffsetArray; | |
| 77 | − PGetIntraPred8x8Func* pGetI8x8LumaPredFunc = pCtx->pGetI8x8LumaPredFunc; | |
| 78 | − | |
| 79 | − int8_t* pIntra8x8PredMode = pDqLayer->pIntra4x4FinalMode[iMbXy]; // I_NxN | |
| 80 | − int16_t* pRS = pScoeffLevel; | |
| 81 | − /*itransform info*/ | |
| 82 | − PIdctResAddPredFunc pIdctResAddPredFunc = pCtx->pIdctResAddPredFunc8x8; | |
| 83 | − | |
| 84 | − /*************local variable********************/ | |
| 85 | − uint8_t i = 0; | |
| 86 | − bool bTLAvail[4], bTRAvail[4]; | |
| 87 | − // Top-Right : Left : Top-Left : Top | |
| 88 | − bTLAvail[0] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x02); | |
| 89 | − bTLAvail[1] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x01); | |
| 90 | − bTLAvail[2] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x04); | |
| 91 | − bTLAvail[3] = true; | |
| 92 | − | |
| 93 | − bTRAvail[0] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x01); | |
| 94 | − bTRAvail[1] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x08); | |
| 95 | − bTRAvail[2] = true; | |
| 96 | − bTRAvail[3] = false; | |
| 97 | − | |
| 98 | − /*************real process*********************/ | |
| 99 | − for (i = 0; i < 4; i++) { | |
| 100 | − | |
| 101 | − uint8_t* pPredI8x8 = pPred + pBlockOffset[i << 2]; | |
| 102 | − uint8_t uiMode = pIntra8x8PredMode[g_kuiScan4[i << 2]]; | |
| 103 | − | |
| 104 | − pGetI8x8LumaPredFunc[uiMode] (pPredI8x8, iLumaStride, bTLAvail[i], bTRAvail[i]); | |
| 105 | − | |
| 106 | − int32_t iIndex = g_kuiMbCountScan4Idx[i << 2]; | |
| 107 | − if (pDqLayer->pNzc[iMbXy][iIndex] || pDqLayer->pNzc[iMbXy][iIndex + 1] || pDqLayer->pNzc[iMbXy][iIndex + 4] | |
| 108 | − || pDqLayer->pNzc[iMbXy][iIndex + 5]) { | |
| 109 | − int16_t* pRSI8x8 = &pRS[i << 6]; | |
| 110 | − pIdctResAddPredFunc (pPredI8x8, iLumaStride, pRSI8x8); | |
| 111 | − } | |
| 112 | − } | |
| 113 | − | |
| 114 | − return ERR_NONE; | |
| 115 | −} | |
| 116 | − | |
| 117 | −int32_t RecI4x4Mb (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 118 | − RecI4x4Luma (iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 119 | − RecI4x4Chroma (iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 120 | − return ERR_NONE; | |
| 121 | −} | |
| 122 | − | |
| 123 | − | |
| 124 | −int32_t RecI4x4Luma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 125 | − /*****get local variable from outer variable********/ | |
| 126 | − /*prediction info*/ | |
| 127 | − uint8_t* pPred = pDqLayer->pPred[0]; | |
| 128 | − | |
| 129 | − int32_t iLumaStride = pDqLayer->iLumaStride; | |
| 130 | − int32_t* pBlockOffset = pCtx->iDecBlockOffsetArray; | |
| 131 | − PGetIntraPredFunc* pGetI4x4LumaPredFunc = pCtx->pGetI4x4LumaPredFunc; | |
| 132 | − | |
| 133 | − int8_t* pIntra4x4PredMode = pDqLayer->pIntra4x4FinalMode[iMBXY]; | |
| 134 | − int16_t* pRS = pScoeffLevel; | |
| 135 | − /*itransform info*/ | |
| 136 | − PIdctResAddPredFunc pIdctResAddPredFunc = pCtx->pIdctResAddPredFunc; | |
| 137 | − | |
| 138 | − | |
| 139 | − /*************local variable********************/ | |
| 140 | − uint8_t i = 0; | |
| 141 | − | |
| 142 | − /*************real process*********************/ | |
| 143 | − for (i = 0; i < 16; i++) { | |
| 144 | − | |
| 145 | − uint8_t* pPredI4x4 = pPred + pBlockOffset[i]; | |
| 146 | − uint8_t uiMode = pIntra4x4PredMode[g_kuiScan4[i]]; | |
| 147 | − | |
| 148 | − pGetI4x4LumaPredFunc[uiMode] (pPredI4x4, iLumaStride); | |
| 149 | − | |
| 150 | − if (pDqLayer->pNzc[iMBXY][g_kuiMbCountScan4Idx[i]]) { | |
| 151 | − int16_t* pRSI4x4 = &pRS[i << 4]; | |
| 152 | − pIdctResAddPredFunc (pPredI4x4, iLumaStride, pRSI4x4); | |
| 153 | − } | |
| 154 | − } | |
| 155 | − | |
| 156 | − return ERR_NONE; | |
| 157 | −} | |
| 158 | − | |
| 159 | − | |
| 160 | −int32_t RecI4x4Chroma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 161 | − int32_t iChromaStride = pCtx->pCurDqLayer->pDec->iLinesize[1]; | |
| 162 | − | |
| 163 | − int8_t iChromaPredMode = pDqLayer->pChromaPredMode[iMBXY]; | |
| 164 | − | |
| 165 | − PGetIntraPredFunc* pGetIChromaPredFunc = pCtx->pGetIChromaPredFunc; | |
| 166 | − | |
| 167 | − uint8_t* pPred = pDqLayer->pPred[1]; | |
| 168 | − | |
| 169 | − pGetIChromaPredFunc[iChromaPredMode] (pPred, iChromaStride); | |
| 170 | − pPred = pDqLayer->pPred[2]; | |
| 171 | − pGetIChromaPredFunc[iChromaPredMode] (pPred, iChromaStride); | |
| 172 | − | |
| 173 | − RecChroma (iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 174 | − | |
| 175 | − return ERR_NONE; | |
| 176 | −} | |
| 177 | − | |
| 178 | − | |
| 179 | −int32_t RecI16x16Mb (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 180 | − /*decoder use, encoder no use*/ | |
| 181 | − int8_t iI16x16PredMode = pDqLayer->pIntraPredMode[iMBXY][7]; | |
| 182 | − int8_t iChromaPredMode = pDqLayer->pChromaPredMode[iMBXY]; | |
| 183 | − PGetIntraPredFunc* pGetIChromaPredFunc = pCtx->pGetIChromaPredFunc; | |
| 184 | − PGetIntraPredFunc* pGetI16x16LumaPredFunc = pCtx->pGetI16x16LumaPredFunc; | |
| 185 | − int32_t iUVStride = pCtx->pCurDqLayer->pDec->iLinesize[1]; | |
| 186 | − | |
| 187 | − /*common use by decoder&encoder*/ | |
| 188 | − int32_t iYStride = pDqLayer->iLumaStride; | |
| 189 | − int16_t* pRS = pScoeffLevel; | |
| 190 | − | |
| 191 | − uint8_t* pPred = pDqLayer->pPred[0]; | |
| 192 | − | |
| 193 | − PIdctFourResAddPredFunc pIdctFourResAddPredFunc = pCtx->pIdctFourResAddPredFunc; | |
| 194 | − | |
| 195 | − /*decode i16x16 y*/ | |
| 196 | − pGetI16x16LumaPredFunc[iI16x16PredMode] (pPred, iYStride); | |
| 197 | − | |
| 198 | − /*1 mb is divided 16 4x4_block to idct*/ | |
| 199 | − const int8_t* pNzc = pDqLayer->pNzc[iMBXY]; | |
| 200 | − pIdctFourResAddPredFunc (pPred + 0 * iYStride + 0, iYStride, pRS + 0 * 64, pNzc + 0); | |
| 201 | − pIdctFourResAddPredFunc (pPred + 0 * iYStride + 8, iYStride, pRS + 1 * 64, pNzc + 2); | |
| 202 | − pIdctFourResAddPredFunc (pPred + 8 * iYStride + 0, iYStride, pRS + 2 * 64, pNzc + 8); | |
| 203 | − pIdctFourResAddPredFunc (pPred + 8 * iYStride + 8, iYStride, pRS + 3 * 64, pNzc + 10); | |
| 204 | − | |
| 205 | − /*decode intra mb cb&cr*/ | |
| 206 | − pPred = pDqLayer->pPred[1]; | |
| 207 | − pGetIChromaPredFunc[iChromaPredMode] (pPred, iUVStride); | |
| 208 | − pPred = pDqLayer->pPred[2]; | |
| 209 | − pGetIChromaPredFunc[iChromaPredMode] (pPred, iUVStride); | |
| 210 | − RecChroma (iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 211 | − | |
| 212 | − return ERR_NONE; | |
| 213 | −} | |
| 214 | − | |
| 215 | − | |
| 216 | −//according to current 8*8 block ref_index to gain reference picture | |
| 217 | −static inline void GetRefPic (sMCRefMember* pMCRefMem, PWelsDecoderContext pCtx, int8_t* pRefIdxList, | |
| 218 | − int32_t iIndex, int32_t listIdx) { | |
| 219 | − PPicture pRefPic; | |
| 220 | − | |
| 221 | − int8_t iRefIdx = pRefIdxList[iIndex]; | |
| 222 | − if (iRefIdx >= 0) { | |
| 223 | − pRefPic = pCtx->sRefPic.pRefList[listIdx][iRefIdx]; | |
| 224 | − | |
| 225 | − if (pRefPic != NULL) { | |
| 226 | − pMCRefMem->iSrcLineLuma = pRefPic->iLinesize[0]; | |
| 227 | − pMCRefMem->iSrcLineChroma = pRefPic->iLinesize[1]; | |
| 228 | − | |
| 229 | − pMCRefMem->pSrcY = pRefPic->pData[0]; | |
| 230 | − pMCRefMem->pSrcU = pRefPic->pData[1]; | |
| 231 | − pMCRefMem->pSrcV = pRefPic->pData[2]; | |
| 232 | − } | |
| 233 | − } | |
| 234 | −} | |
| 235 | − | |
| 236 | − | |
| 237 | −#ifndef MC_FLOW_SIMPLE_JUDGE | |
| 238 | −#define MC_FLOW_SIMPLE_JUDGE 1 | |
| 239 | −#endif //MC_FLOW_SIMPLE_JUDGE | |
| 240 | −void BaseMC (sMCRefMember* pMCRefMem, int32_t iXOffset, int32_t iYOffset, SMcFunc* pMCFunc, | |
| 241 | − int32_t iBlkWidth, int32_t iBlkHeight, int16_t iMVs[2]) { | |
| 242 | − int32_t iFullMVx = (iXOffset << 2) + iMVs[0]; //quarter pixel | |
| 243 | − int32_t iFullMVy = (iYOffset << 2) + iMVs[1]; | |
| 244 | − iFullMVx = WELS_CLIP3 (iFullMVx, ((-PADDING_LENGTH + 2) * (1 << 2)), | |
| 245 | − ((pMCRefMem->iPicWidth + PADDING_LENGTH - 19) * (1 << 2))); | |
| 246 | − iFullMVy = WELS_CLIP3 (iFullMVy, ((-PADDING_LENGTH + 2) * (1 << 2)), | |
| 247 | − ((pMCRefMem->iPicHeight + PADDING_LENGTH - 19) * (1 << 2))); | |
| 248 | − | |
| 249 | − int32_t iSrcPixOffsetLuma = (iFullMVx >> 2) + (iFullMVy >> 2) * pMCRefMem->iSrcLineLuma; | |
| 250 | − int32_t iSrcPixOffsetChroma = (iFullMVx >> 3) + (iFullMVy >> 3) * pMCRefMem->iSrcLineChroma; | |
| 251 | − | |
| 252 | − int32_t iBlkWidthChroma = iBlkWidth >> 1; | |
| 253 | − int32_t iBlkHeightChroma = iBlkHeight >> 1; | |
| 254 | − | |
| 255 | − uint8_t* pSrcY = pMCRefMem->pSrcY + iSrcPixOffsetLuma; | |
| 256 | − uint8_t* pSrcU = pMCRefMem->pSrcU + iSrcPixOffsetChroma; | |
| 257 | − uint8_t* pSrcV = pMCRefMem->pSrcV + iSrcPixOffsetChroma; | |
| 258 | − uint8_t* pDstY = pMCRefMem->pDstY; | |
| 259 | − uint8_t* pDstU = pMCRefMem->pDstU; | |
| 260 | − uint8_t* pDstV = pMCRefMem->pDstV; | |
| 261 | − | |
| 262 | − pMCFunc->pMcLumaFunc (pSrcY, pMCRefMem->iSrcLineLuma, pDstY, pMCRefMem->iDstLineLuma, iFullMVx, iFullMVy, iBlkWidth, | |
| 263 | − iBlkHeight); | |
| 264 | − pMCFunc->pMcChromaFunc (pSrcU, pMCRefMem->iSrcLineChroma, pDstU, pMCRefMem->iDstLineChroma, iFullMVx, iFullMVy, | |
| 265 | − iBlkWidthChroma, iBlkHeightChroma); | |
| 266 | − pMCFunc->pMcChromaFunc (pSrcV, pMCRefMem->iSrcLineChroma, pDstV, pMCRefMem->iDstLineChroma, iFullMVx, iFullMVy, | |
| 267 | − iBlkWidthChroma, iBlkHeightChroma); | |
| 268 | − | |
| 269 | −} | |
| 270 | − | |
| 271 | −static void WeightPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, int32_t listIdx, int32_t iRefIdx, | |
| 272 | − int32_t iBlkWidth, | |
| 273 | − int32_t iBlkHeight) { | |
| 274 | − | |
| 275 | − | |
| 276 | − int32_t iLog2denom, iWoc, iOoc; | |
| 277 | − int32_t iPredTemp, iLineStride; | |
| 278 | − int32_t iPixel = 0; | |
| 279 | − uint8_t* pDst; | |
| 280 | − //luma | |
| 281 | − iLog2denom = pCurDqLayer->pPredWeightTable->uiLumaLog2WeightDenom; | |
| 282 | − iWoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iLumaWeight[iRefIdx]; | |
| 283 | − iOoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iLumaOffset[iRefIdx]; | |
| 284 | − iLineStride = pMCRefMem->iDstLineLuma; | |
| 285 | − | |
| 286 | − for (int i = 0; i < iBlkHeight; i++) { | |
| 287 | − for (int j = 0; j < iBlkWidth; j++) { | |
| 288 | − iPixel = j + i * (iLineStride); | |
| 289 | − if (iLog2denom >= 1) { | |
| 290 | − iPredTemp = ((pMCRefMem->pDstY[iPixel] * iWoc + (1 << (iLog2denom - 1))) >> iLog2denom) + iOoc; | |
| 291 | − | |
| 292 | − pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 293 | − } else { | |
| 294 | − iPredTemp = pMCRefMem->pDstY[iPixel] * iWoc + iOoc; | |
| 295 | − | |
| 296 | − pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 297 | − | |
| 298 | − } | |
| 299 | − } | |
| 300 | − } | |
| 301 | − | |
| 302 | − | |
| 303 | − //UV | |
| 304 | − iBlkWidth = iBlkWidth >> 1; | |
| 305 | − iBlkHeight = iBlkHeight >> 1; | |
| 306 | − iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom; | |
| 307 | − iLineStride = pMCRefMem->iDstLineChroma; | |
| 308 | − | |
| 309 | − for (int i = 0; i < 2; i++) { | |
| 310 | − | |
| 311 | − | |
| 312 | − //iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom; | |
| 313 | − iWoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iChromaWeight[iRefIdx][i]; | |
| 314 | − iOoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iChromaOffset[iRefIdx][i]; | |
| 315 | − pDst = i ? pMCRefMem->pDstV : pMCRefMem->pDstU; | |
| 316 | − //iLineStride = pMCRefMem->iDstLineChroma; | |
| 317 | − | |
| 318 | − for (int i = 0; i < iBlkHeight ; i++) { | |
| 319 | − for (int j = 0; j < iBlkWidth; j++) { | |
| 320 | − iPixel = j + i * (iLineStride); | |
| 321 | − if (iLog2denom >= 1) { | |
| 322 | − iPredTemp = ((pDst[iPixel] * iWoc + (1 << (iLog2denom - 1))) >> iLog2denom) + iOoc; | |
| 323 | − | |
| 324 | − pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 325 | − } else { | |
| 326 | − iPredTemp = pDst[iPixel] * iWoc + iOoc; | |
| 327 | − | |
| 328 | − pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 329 | − | |
| 330 | − } | |
| 331 | − } | |
| 332 | − | |
| 333 | − } | |
| 334 | − | |
| 335 | − | |
| 336 | − } | |
| 337 | −} | |
| 338 | − | |
| 339 | −static void BiWeightPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, sMCRefMember* pTempMCRefMem, | |
| 340 | − int32_t iRefIdx1, int32_t iRefIdx2, bool bWeightedBipredIdcIs1, int32_t iBlkWidth, | |
| 341 | − int32_t iBlkHeight) { | |
| 342 | − int32_t iWoc1 = 0, iOoc1 = 0, iWoc2 = 0, iOoc2 = 0; | |
| 343 | − int32_t iPredTemp, iLineStride; | |
| 344 | − int32_t iPixel = 0; | |
| 345 | − //luma | |
| 346 | − int32_t iLog2denom = pCurDqLayer->pPredWeightTable->uiLumaLog2WeightDenom; | |
| 347 | − if (bWeightedBipredIdcIs1) { | |
| 348 | − iWoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iLumaWeight[iRefIdx1]; | |
| 349 | − iOoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iLumaOffset[iRefIdx1]; | |
| 350 | − iWoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iLumaWeight[iRefIdx2]; | |
| 351 | − iOoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iLumaOffset[iRefIdx2]; | |
| 352 | − } else { | |
| 353 | − iWoc1 = pCurDqLayer->pPredWeightTable->iImplicitWeight[iRefIdx1][iRefIdx2]; | |
| 354 | − iWoc2 = 64 - iWoc1; | |
| 355 | − } | |
| 356 | − iLineStride = pMCRefMem->iDstLineLuma; | |
| 357 | − | |
| 358 | − for (int i = 0; i < iBlkHeight; i++) { | |
| 359 | − for (int j = 0; j < iBlkWidth; j++) { | |
| 360 | − iPixel = j + i * (iLineStride); | |
| 361 | − iPredTemp = ((pMCRefMem->pDstY[iPixel] * iWoc1 + pTempMCRefMem->pDstY[iPixel] * iWoc2 + (1 << iLog2denom)) >> | |
| 362 | − (iLog2denom + 1)) + ((iOoc1 + iOoc2 + 1) >> 1); | |
| 363 | − pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 364 | − } | |
| 365 | − } | |
| 366 | − | |
| 367 | − //UV | |
| 368 | − iBlkWidth = iBlkWidth >> 1; | |
| 369 | − iBlkHeight = iBlkHeight >> 1; | |
| 370 | − iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom; | |
| 371 | − iLineStride = pMCRefMem->iDstLineChroma; | |
| 372 | − | |
| 373 | − uint8_t* pDst; | |
| 374 | − uint8_t* pTempDst; | |
| 375 | − for (int k = 0; k < 2; k++) { | |
| 376 | − //iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom; | |
| 377 | − if (bWeightedBipredIdcIs1) { | |
| 378 | − iWoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iChromaWeight[iRefIdx1][k]; | |
| 379 | − iOoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iChromaOffset[iRefIdx1][k]; | |
| 380 | − iWoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iChromaWeight[iRefIdx2][k]; | |
| 381 | − iOoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iChromaOffset[iRefIdx2][k]; | |
| 382 | − } | |
| 383 | − pDst = k ? pMCRefMem->pDstV : pMCRefMem->pDstU; | |
| 384 | − pTempDst = k ? pTempMCRefMem->pDstV : pTempMCRefMem->pDstU; | |
| 385 | − //iLineStride = pMCRefMem->iDstLineChroma; | |
| 386 | − | |
| 387 | − for (int i = 0; i < iBlkHeight; i++) { | |
| 388 | − for (int j = 0; j < iBlkWidth; j++) { | |
| 389 | − iPixel = j + i * (iLineStride); | |
| 390 | − iPredTemp = ((pDst[iPixel] * iWoc1 + pTempDst[iPixel] * iWoc2 + (1 << iLog2denom)) >> (iLog2denom + 1)) + (( | |
| 391 | − iOoc1 + iOoc2 + 1) >> 1); | |
| 392 | − pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 393 | − } | |
| 394 | − } | |
| 395 | − } | |
| 396 | −} | |
| 397 | − | |
| 398 | −static void BiPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, sMCRefMember* pTempMCRefMem, int32_t iBlkWidth, | |
| 399 | − int32_t iBlkHeight) { | |
| 400 | − int32_t iPredTemp, iLineStride; | |
| 401 | − int32_t iPixel = 0; | |
| 402 | − //luma | |
| 403 | − iLineStride = pMCRefMem->iDstLineLuma; | |
| 404 | − | |
| 405 | − for (int i = 0; i < iBlkHeight; i++) { | |
| 406 | − for (int j = 0; j < iBlkWidth; j++) { | |
| 407 | − iPixel = j + i * (iLineStride); | |
| 408 | − iPredTemp = (pMCRefMem->pDstY[iPixel] + pTempMCRefMem->pDstY[iPixel] + 1) >> 1; | |
| 409 | − pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 410 | − } | |
| 411 | − } | |
| 412 | − | |
| 413 | − //UV | |
| 414 | − iBlkWidth = iBlkWidth >> 1; | |
| 415 | − iBlkHeight = iBlkHeight >> 1; | |
| 416 | − iLineStride = pMCRefMem->iDstLineChroma; | |
| 417 | − | |
| 418 | − uint8_t* pDst; | |
| 419 | − uint8_t* pTempDst; | |
| 420 | − for (int k = 0; k < 2; k++) { | |
| 421 | − pDst = k ? pMCRefMem->pDstV : pMCRefMem->pDstU; | |
| 422 | − pTempDst = k ? pTempMCRefMem->pDstV : pTempMCRefMem->pDstU; | |
| 423 | − //iLineStride = pMCRefMem->iDstLineChroma; | |
| 424 | − | |
| 425 | − for (int i = 0; i < iBlkHeight; i++) { | |
| 426 | − for (int j = 0; j < iBlkWidth; j++) { | |
| 427 | − iPixel = j + i * (iLineStride); | |
| 428 | − iPredTemp = (pDst[iPixel] + pTempDst[iPixel] + 1) >> 1; | |
| 429 | − pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 430 | − } | |
| 431 | − } | |
| 432 | − } | |
| 433 | −} | |
| 434 | − | |
| 435 | −void GetInterPred (uint8_t* pPredY, uint8_t* pPredCb, uint8_t* pPredCr, PWelsDecoderContext pCtx) { | |
| 436 | − sMCRefMember pMCRefMem; | |
| 437 | − PDqLayer pCurDqLayer = pCtx->pCurDqLayer; | |
| 438 | − SMcFunc* pMCFunc = &pCtx->sMcFunc; | |
| 439 | − | |
| 440 | − int32_t iMBXY = pCurDqLayer->iMbXyIndex; | |
| 441 | − | |
| 442 | − int16_t iMVs[2] = {0}; | |
| 443 | − | |
| 444 | − uint32_t iMBType = pCurDqLayer->pMbType[iMBXY]; | |
| 445 | − | |
| 446 | − int32_t iMBOffsetX = pCurDqLayer->iMbX << 4; | |
| 447 | − int32_t iMBOffsetY = pCurDqLayer->iMbY << 4; | |
| 448 | − | |
| 449 | − int32_t iDstLineLuma = pCtx->pDec->iLinesize[0]; | |
| 450 | − int32_t iDstLineChroma = pCtx->pDec->iLinesize[1]; | |
| 451 | − | |
| 452 | − int32_t iBlk8X, iBlk8Y, iBlk4X, iBlk4Y, i, j, iIIdx, iJIdx; | |
| 453 | − | |
| 454 | − pMCRefMem.iPicWidth = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbWidth << 4); | |
| 455 | − pMCRefMem.iPicHeight = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbHeight << 4); | |
| 456 | − | |
| 457 | − pMCRefMem.pDstY = pPredY; | |
| 458 | − pMCRefMem.pDstU = pPredCb; | |
| 459 | − pMCRefMem.pDstV = pPredCr; | |
| 460 | − | |
| 461 | − pMCRefMem.iDstLineLuma = iDstLineLuma; | |
| 462 | − pMCRefMem.iDstLineChroma = iDstLineChroma; | |
| 463 | − | |
| 464 | − int32_t iRefIndex = 0; | |
| 465 | − | |
| 466 | − switch (iMBType) { | |
| 467 | − case MB_TYPE_SKIP: | |
| 468 | − case MB_TYPE_16x16: | |
| 469 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0]; | |
| 470 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1]; | |
| 471 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0); | |
| 472 | − BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs); | |
| 473 | − | |
| 474 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 475 | − iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0]; | |
| 476 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 16); | |
| 477 | − } | |
| 478 | − break; | |
| 479 | − case MB_TYPE_16x8: | |
| 480 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0]; | |
| 481 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1]; | |
| 482 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0); | |
| 483 | − BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 8, iMVs); | |
| 484 | − | |
| 485 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 486 | − iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0]; | |
| 487 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 8); | |
| 488 | − } | |
| 489 | − | |
| 490 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][8][0]; | |
| 491 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][8][1]; | |
| 492 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 8, LIST_0); | |
| 493 | − pMCRefMem.pDstY = pPredY + (iDstLineLuma << 3); | |
| 494 | − pMCRefMem.pDstU = pPredCb + (iDstLineChroma << 2); | |
| 495 | − pMCRefMem.pDstV = pPredCr + (iDstLineChroma << 2); | |
| 496 | − BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY + 8, pMCFunc, 16, 8, iMVs); | |
| 497 | − | |
| 498 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 499 | − iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][8]; | |
| 500 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 8); | |
| 501 | − } | |
| 502 | − break; | |
| 503 | − case MB_TYPE_8x16: | |
| 504 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0]; | |
| 505 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1]; | |
| 506 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0); | |
| 507 | − BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 508 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 509 | − iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0]; | |
| 510 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 16); | |
| 511 | − } | |
| 512 | − | |
| 513 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][2][0]; | |
| 514 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][2][1]; | |
| 515 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 2, LIST_0); | |
| 516 | − pMCRefMem.pDstY = pPredY + 8; | |
| 517 | − pMCRefMem.pDstU = pPredCb + 4; | |
| 518 | − pMCRefMem.pDstV = pPredCr + 4; | |
| 519 | − BaseMC (&pMCRefMem, iMBOffsetX + 8, iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 520 | − | |
| 521 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 522 | − iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][2]; | |
| 523 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 16); | |
| 524 | − } | |
| 525 | − break; | |
| 526 | − case MB_TYPE_8x8: | |
| 527 | − case MB_TYPE_8x8_REF0: { | |
| 528 | − uint32_t iSubMBType; | |
| 529 | − int32_t iXOffset, iYOffset; | |
| 530 | − uint8_t* pDstY, *pDstU, *pDstV; | |
| 531 | − for (i = 0; i < 4; i++) { | |
| 532 | − iSubMBType = pCurDqLayer->pSubMbType[iMBXY][i]; | |
| 533 | − iBlk8X = (i & 1) << 3; | |
| 534 | − iBlk8Y = (i >> 1) << 3; | |
| 535 | − iXOffset = iMBOffsetX + iBlk8X; | |
| 536 | − iYOffset = iMBOffsetY + iBlk8Y; | |
| 537 | − | |
| 538 | − iIIdx = ((i >> 1) << 3) + ((i & 1) << 1); | |
| 539 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], iIIdx, LIST_0); | |
| 540 | − iRefIndex = pCurDqLayer->bUseWeightPredictionFlag ? pCurDqLayer->pRefIndex[0][iMBXY][iIIdx] : 0; | |
| 541 | − | |
| 542 | − pDstY = pPredY + iBlk8X + iBlk8Y * iDstLineLuma; | |
| 543 | − pDstU = pPredCb + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 544 | − pDstV = pPredCr + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 545 | − pMCRefMem.pDstY = pDstY; | |
| 546 | − pMCRefMem.pDstU = pDstU; | |
| 547 | − pMCRefMem.pDstV = pDstV; | |
| 548 | − switch (iSubMBType) { | |
| 549 | − case SUB_MB_TYPE_8x8: | |
| 550 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0]; | |
| 551 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1]; | |
| 552 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs); | |
| 553 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 554 | − | |
| 555 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 8); | |
| 556 | − } | |
| 557 | − | |
| 558 | − break; | |
| 559 | − case SUB_MB_TYPE_8x4: | |
| 560 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0]; | |
| 561 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1]; | |
| 562 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs); | |
| 563 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 564 | − | |
| 565 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 4); | |
| 566 | − } | |
| 567 | − | |
| 568 | − | |
| 569 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 4][0]; | |
| 570 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 4][1]; | |
| 571 | − pMCRefMem.pDstY += (iDstLineLuma << 2); | |
| 572 | − pMCRefMem.pDstU += (iDstLineChroma << 1); | |
| 573 | − pMCRefMem.pDstV += (iDstLineChroma << 1); | |
| 574 | − BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs); | |
| 575 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 576 | − | |
| 577 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 4); | |
| 578 | − } | |
| 579 | − | |
| 580 | − break; | |
| 581 | − case SUB_MB_TYPE_4x8: | |
| 582 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0]; | |
| 583 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1]; | |
| 584 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 585 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 586 | − | |
| 587 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 8); | |
| 588 | − } | |
| 589 | − | |
| 590 | − | |
| 591 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 1][0]; | |
| 592 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 1][1]; | |
| 593 | − pMCRefMem.pDstY += 4; | |
| 594 | − pMCRefMem.pDstU += 2; | |
| 595 | − pMCRefMem.pDstV += 2; | |
| 596 | − BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 597 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 598 | − | |
| 599 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 8); | |
| 600 | − } | |
| 601 | − | |
| 602 | − break; | |
| 603 | − case SUB_MB_TYPE_4x4: { | |
| 604 | − for (j = 0; j < 4; j++) { | |
| 605 | − int32_t iUVLineStride; | |
| 606 | − iJIdx = ((j >> 1) << 2) + (j & 1); | |
| 607 | − | |
| 608 | − iBlk4X = (j & 1) << 2; | |
| 609 | − iBlk4Y = (j >> 1) << 2; | |
| 610 | − | |
| 611 | − iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma; | |
| 612 | − pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma; | |
| 613 | − pMCRefMem.pDstU = pDstU + iUVLineStride; | |
| 614 | − pMCRefMem.pDstV = pDstV + iUVLineStride; | |
| 615 | − | |
| 616 | − iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + iJIdx][0]; | |
| 617 | − iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + iJIdx][1]; | |
| 618 | − BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs); | |
| 619 | − if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 620 | − | |
| 621 | − WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 4); | |
| 622 | − } | |
| 623 | − | |
| 624 | − } | |
| 625 | − } | |
| 626 | − break; | |
| 627 | − default: | |
| 628 | − break; | |
| 629 | − } | |
| 630 | − } | |
| 631 | − } | |
| 632 | − break; | |
| 633 | − default: | |
| 634 | − break; | |
| 635 | − } | |
| 636 | −} | |
| 637 | − | |
| 638 | −void GetInterBPred (uint8_t* pPredYCbCr[3], uint8_t* pTempPredYCbCr[3], PWelsDecoderContext pCtx) { | |
| 639 | − sMCRefMember pMCRefMem; | |
| 640 | − sMCRefMember pTempMCRefMem; | |
| 641 | − | |
| 642 | − PDqLayer pCurDqLayer = pCtx->pCurDqLayer; | |
| 643 | − SMcFunc* pMCFunc = &pCtx->sMcFunc; | |
| 644 | − | |
| 645 | − int32_t iMBXY = pCurDqLayer->iMbXyIndex; | |
| 646 | − | |
| 647 | − int16_t iMVs[2] = { 0 }; | |
| 648 | − | |
| 649 | − uint32_t iMBType = pCurDqLayer->pMbType[iMBXY]; | |
| 650 | − | |
| 651 | − int32_t iMBOffsetX = pCurDqLayer->iMbX << 4; | |
| 652 | − int32_t iMBOffsetY = pCurDqLayer->iMbY << 4; | |
| 653 | − | |
| 654 | − int32_t iDstLineLuma = pCtx->pDec->iLinesize[0]; | |
| 655 | − int32_t iDstLineChroma = pCtx->pDec->iLinesize[1]; | |
| 656 | − | |
| 657 | − | |
| 658 | − pMCRefMem.iPicWidth = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbWidth << 4); | |
| 659 | − pMCRefMem.iPicHeight = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbHeight << 4); | |
| 660 | − | |
| 661 | − pMCRefMem.pDstY = pPredYCbCr[0]; | |
| 662 | − pMCRefMem.pDstU = pPredYCbCr[1]; | |
| 663 | − pMCRefMem.pDstV = pPredYCbCr[2]; | |
| 664 | − | |
| 665 | − pMCRefMem.iDstLineLuma = iDstLineLuma; | |
| 666 | − pMCRefMem.iDstLineChroma = iDstLineChroma; | |
| 667 | − | |
| 668 | − pTempMCRefMem = pMCRefMem; | |
| 669 | − pTempMCRefMem.pDstY = pTempPredYCbCr[0]; | |
| 670 | − pTempMCRefMem.pDstU = pTempPredYCbCr[1]; | |
| 671 | − pTempMCRefMem.pDstV = pTempPredYCbCr[2]; | |
| 672 | − | |
| 673 | − | |
| 674 | − int32_t iRefIndex1 = 0; | |
| 675 | − int32_t iRefIndex2 = 0; | |
| 676 | − | |
| 677 | − bool bWeightedBipredIdcIs1 = pCurDqLayer->sLayerInfo.pPps->uiWeightedBipredIdc == 1; | |
| 678 | − | |
| 679 | − if (IS_INTER_16x16 (iMBType)) { | |
| 680 | − if (IS_TYPE_L0 (iMBType) && IS_TYPE_L1 (iMBType)) { | |
| 681 | − iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][0][0]; | |
| 682 | − iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][0][1]; | |
| 683 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_0][iMBXY], 0, LIST_0); | |
| 684 | − BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs); | |
| 685 | − | |
| 686 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][0][0]; | |
| 687 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][0][1]; | |
| 688 | − GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], 0, LIST_1); | |
| 689 | − BaseMC (&pTempMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs); | |
| 690 | − iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][0]; | |
| 691 | − iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][0]; | |
| 692 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 693 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 16, 16); | |
| 694 | − } else { | |
| 695 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 16, 16); | |
| 696 | − } | |
| 697 | − } else { | |
| 698 | − int32_t listIdx = (iMBType & MB_TYPE_P0L0) ? LIST_0 : LIST_1; | |
| 699 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][0][0]; | |
| 700 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][0][1]; | |
| 701 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], 0, listIdx); | |
| 702 | − BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs); | |
| 703 | − if (bWeightedBipredIdcIs1) { | |
| 704 | − int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][0]; | |
| 705 | − WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 16, 16); | |
| 706 | − } | |
| 707 | − } | |
| 708 | − } else if (IS_INTER_16x8 (iMBType)) { | |
| 709 | − for (int32_t i = 0; i < 2; ++i) { | |
| 710 | − int32_t iPartIdx = i << 3; | |
| 711 | − uint32_t listCount = 0; | |
| 712 | − int32_t lastListIdx = LIST_0; | |
| 713 | − for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 714 | − if (IS_DIR (iMBType, i, listIdx)) { | |
| 715 | − lastListIdx = listIdx; | |
| 716 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iPartIdx][0]; | |
| 717 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iPartIdx][1]; | |
| 718 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], iPartIdx, listIdx); | |
| 719 | − if (i) { | |
| 720 | − pMCRefMem.pDstY += (iDstLineLuma << 3); | |
| 721 | − pMCRefMem.pDstU += (iDstLineChroma << 2); | |
| 722 | − pMCRefMem.pDstV += (iDstLineChroma << 2); | |
| 723 | − } | |
| 724 | − BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY + iPartIdx, pMCFunc, 16, 8, iMVs); | |
| 725 | − if (++listCount == 2) { | |
| 726 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iPartIdx][0]; | |
| 727 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iPartIdx][1]; | |
| 728 | − GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], iPartIdx, LIST_1); | |
| 729 | − if (i) { | |
| 730 | − pTempMCRefMem.pDstY += (iDstLineLuma << 3); | |
| 731 | − pTempMCRefMem.pDstU += (iDstLineChroma << 2); | |
| 732 | − pTempMCRefMem.pDstV += (iDstLineChroma << 2); | |
| 733 | − } | |
| 734 | − BaseMC (&pTempMCRefMem, iMBOffsetX, iMBOffsetY + iPartIdx, pMCFunc, 16, 8, iMVs); | |
| 735 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 736 | − iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][iPartIdx]; | |
| 737 | − iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][iPartIdx]; | |
| 738 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 16, 8); | |
| 739 | − } else { | |
| 740 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 16, 8); | |
| 741 | − } | |
| 742 | − } | |
| 743 | − } | |
| 744 | − } | |
| 745 | − if (listCount == 1) { | |
| 746 | − if (bWeightedBipredIdcIs1) { | |
| 747 | − int32_t iRefIndex = pCurDqLayer->pRefIndex[lastListIdx][iMBXY][iPartIdx]; | |
| 748 | − WeightPrediction (pCurDqLayer, &pMCRefMem, lastListIdx, iRefIndex, 16, 8); | |
| 749 | − } | |
| 750 | − } | |
| 751 | − } | |
| 752 | − } else if (IS_INTER_8x16 (iMBType)) { | |
| 753 | − for (int32_t i = 0; i < 2; ++i) { | |
| 754 | − uint32_t listCount = 0; | |
| 755 | − int32_t lastListIdx = LIST_0; | |
| 756 | − for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 757 | − if (IS_DIR (iMBType, i, listIdx)) { | |
| 758 | − lastListIdx = listIdx; | |
| 759 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][i << 1][0]; | |
| 760 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][i << 1][1]; | |
| 761 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], i << 1, listIdx); | |
| 762 | − if (i) { | |
| 763 | − pMCRefMem.pDstY += 8; | |
| 764 | − pMCRefMem.pDstU += 4; | |
| 765 | − pMCRefMem.pDstV += 4; | |
| 766 | − } | |
| 767 | − BaseMC (&pMCRefMem, iMBOffsetX + (i ? 8 : 0), iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 768 | − if (++listCount == 2) { | |
| 769 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][i << 1][0]; | |
| 770 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][i << 1][1]; | |
| 771 | − GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], i << 1, LIST_1); | |
| 772 | − if (i) { | |
| 773 | − pTempMCRefMem.pDstY += 8; | |
| 774 | − pTempMCRefMem.pDstU += 4; | |
| 775 | − pTempMCRefMem.pDstV += 4; | |
| 776 | − } | |
| 777 | − BaseMC (&pTempMCRefMem, iMBOffsetX + (i ? 8 : 0), iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 778 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 779 | − iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][i << 1]; | |
| 780 | − iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][i << 1]; | |
| 781 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 16); | |
| 782 | − } else { | |
| 783 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 16); | |
| 784 | − } | |
| 785 | − } | |
| 786 | − } | |
| 787 | − } | |
| 788 | − if (listCount == 1) { | |
| 789 | − if (bWeightedBipredIdcIs1) { | |
| 790 | − int32_t iRefIndex = pCurDqLayer->pRefIndex[lastListIdx][iMBXY][i << 1]; | |
| 791 | − WeightPrediction (pCurDqLayer, &pMCRefMem, lastListIdx, iRefIndex, 8, 16); | |
| 792 | − } | |
| 793 | − } | |
| 794 | − } | |
| 795 | − } else if (IS_Inter_8x8 (iMBType)) { | |
| 796 | − int32_t iBlk8X, iBlk8Y, iBlk4X, iBlk4Y, iIIdx, iJIdx; | |
| 797 | − uint32_t iSubMBType; | |
| 798 | − int32_t iXOffset, iYOffset; | |
| 799 | − uint8_t* pDstY, *pDstU, *pDstV; | |
| 800 | − uint8_t* pDstY2, *pDstU2, *pDstV2; | |
| 801 | − for (int32_t i = 0; i < 4; i++) { | |
| 802 | − iSubMBType = pCurDqLayer->pSubMbType[iMBXY][i]; | |
| 803 | − iBlk8X = (i & 1) << 3; | |
| 804 | − iBlk8Y = (i >> 1) << 3; | |
| 805 | − iXOffset = iMBOffsetX + iBlk8X; | |
| 806 | − iYOffset = iMBOffsetY + iBlk8Y; | |
| 807 | − | |
| 808 | − iIIdx = ((i >> 1) << 3) + ((i & 1) << 1); | |
| 809 | − | |
| 810 | − pDstY = pPredYCbCr[0] + iBlk8X + iBlk8Y * iDstLineLuma; | |
| 811 | − pDstU = pPredYCbCr[1] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 812 | − pDstV = pPredYCbCr[2] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 813 | − pMCRefMem.pDstY = pDstY; | |
| 814 | − pMCRefMem.pDstU = pDstU; | |
| 815 | − pMCRefMem.pDstV = pDstV; | |
| 816 | − | |
| 817 | − pTempMCRefMem = pMCRefMem; | |
| 818 | − pDstY2 = pTempPredYCbCr[0] + iBlk8X + iBlk8Y * iDstLineLuma; | |
| 819 | − pDstU2 = pTempPredYCbCr[1] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 820 | − pDstV2 = pTempPredYCbCr[2] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 821 | − | |
| 822 | − pTempMCRefMem.pDstY = pDstY2; | |
| 823 | − pTempMCRefMem.pDstU = pDstU2; | |
| 824 | − pTempMCRefMem.pDstV = pDstV2; | |
| 825 | − | |
| 826 | − if ((IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType))) { | |
| 827 | − iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][iIIdx]; | |
| 828 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_0][iMBXY], iIIdx, LIST_0); | |
| 829 | − | |
| 830 | − iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][iIIdx]; | |
| 831 | − GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], iIIdx, LIST_1); | |
| 832 | − } else { | |
| 833 | − int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 834 | − iRefIndex1 = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 835 | − GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], iIIdx, listIdx); | |
| 836 | − } | |
| 837 | − | |
| 838 | − if (IS_SUB_8x8 (iSubMBType)) { | |
| 839 | − if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { | |
| 840 | − iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0]; | |
| 841 | − iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1]; | |
| 842 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs); | |
| 843 | − | |
| 844 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0]; | |
| 845 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1]; | |
| 846 | − BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs); | |
| 847 | − | |
| 848 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 849 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 8); | |
| 850 | − } else { | |
| 851 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 8); | |
| 852 | − } | |
| 853 | − } else { | |
| 854 | − int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 855 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0]; | |
| 856 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1]; | |
| 857 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs); | |
| 858 | − if (bWeightedBipredIdcIs1) { | |
| 859 | − int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 860 | − WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 8, 8); | |
| 861 | − } | |
| 862 | − } | |
| 863 | − } else if (IS_SUB_8x4 (iSubMBType)) { | |
| 864 | − if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { //B_Bi_8x4 | |
| 865 | − iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0]; | |
| 866 | − iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1]; | |
| 867 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs); | |
| 868 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0]; | |
| 869 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1]; | |
| 870 | − BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs); | |
| 871 | − | |
| 872 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 873 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 4); | |
| 874 | − } else { | |
| 875 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 4); | |
| 876 | − } | |
| 877 | − | |
| 878 | − pMCRefMem.pDstY += (iDstLineLuma << 2); | |
| 879 | − pMCRefMem.pDstU += (iDstLineChroma << 1); | |
| 880 | − pMCRefMem.pDstV += (iDstLineChroma << 1); | |
| 881 | − iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 4][0]; | |
| 882 | − iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 4][1]; | |
| 883 | − BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs); | |
| 884 | − | |
| 885 | − pTempMCRefMem.pDstY += (iDstLineLuma << 2); | |
| 886 | − pTempMCRefMem.pDstU += (iDstLineChroma << 1); | |
| 887 | − pTempMCRefMem.pDstV += (iDstLineChroma << 1); | |
| 888 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 4][0]; | |
| 889 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 4][1]; | |
| 890 | − BaseMC (&pTempMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs); | |
| 891 | − | |
| 892 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 893 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 4); | |
| 894 | − } else { | |
| 895 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 4); | |
| 896 | − } | |
| 897 | − } else { //B_L0_8x4 B_L1_8x4 | |
| 898 | − int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 899 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0]; | |
| 900 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1]; | |
| 901 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs); | |
| 902 | − pMCRefMem.pDstY += (iDstLineLuma << 2); | |
| 903 | − pMCRefMem.pDstU += (iDstLineChroma << 1); | |
| 904 | − pMCRefMem.pDstV += (iDstLineChroma << 1); | |
| 905 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 4][0]; | |
| 906 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 4][1]; | |
| 907 | − BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs); | |
| 908 | − if (bWeightedBipredIdcIs1) { | |
| 909 | − int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 910 | − WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 8, 4); | |
| 911 | − } | |
| 912 | − } | |
| 913 | − } else if (IS_SUB_4x8 (iSubMBType)) { | |
| 914 | − if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { //B_Bi_4x8 | |
| 915 | − iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0]; | |
| 916 | − iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1]; | |
| 917 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 918 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0]; | |
| 919 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1]; | |
| 920 | − BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 921 | − | |
| 922 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 923 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 8); | |
| 924 | − } else { | |
| 925 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 8); | |
| 926 | − } | |
| 927 | − | |
| 928 | − pMCRefMem.pDstY += 4; | |
| 929 | − pMCRefMem.pDstU += 2; | |
| 930 | − pMCRefMem.pDstV += 2; | |
| 931 | − iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 1][0]; | |
| 932 | − iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 1][1]; | |
| 933 | − BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 934 | − | |
| 935 | − pTempMCRefMem.pDstY += 4; | |
| 936 | − pTempMCRefMem.pDstU += 2; | |
| 937 | − pTempMCRefMem.pDstV += 2; | |
| 938 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 1][0]; | |
| 939 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 1][1]; | |
| 940 | − BaseMC (&pTempMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 941 | − | |
| 942 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 943 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 8); | |
| 944 | − } else { | |
| 945 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 8); | |
| 946 | − } | |
| 947 | − } else { //B_L0_4x8 B_L1_4x8 | |
| 948 | − int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 949 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0]; | |
| 950 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1]; | |
| 951 | − BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 952 | − pMCRefMem.pDstY += 4; | |
| 953 | − pMCRefMem.pDstU += 2; | |
| 954 | − pMCRefMem.pDstV += 2; | |
| 955 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 1][0]; | |
| 956 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 1][1]; | |
| 957 | − BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 958 | − if (bWeightedBipredIdcIs1) { | |
| 959 | − int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 960 | − WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 4, 8); | |
| 961 | − } | |
| 962 | − } | |
| 963 | − } else if (IS_SUB_4x4 (iSubMBType)) { | |
| 964 | − if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { | |
| 965 | − for (int32_t j = 0; j < 4; j++) { | |
| 966 | − int32_t iUVLineStride; | |
| 967 | − iJIdx = ((j >> 1) << 2) + (j & 1); | |
| 968 | − | |
| 969 | − iBlk4X = (j & 1) << 2; | |
| 970 | − iBlk4Y = (j >> 1) << 2; | |
| 971 | − | |
| 972 | − iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma; | |
| 973 | − pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma; | |
| 974 | − pMCRefMem.pDstU = pDstU + iUVLineStride; | |
| 975 | − pMCRefMem.pDstV = pDstV + iUVLineStride; | |
| 976 | − | |
| 977 | − iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + iJIdx][0]; | |
| 978 | − iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + iJIdx][1]; | |
| 979 | − BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs); | |
| 980 | − | |
| 981 | − pTempMCRefMem.pDstY = pDstY2 + iBlk8X + iBlk8Y * iDstLineLuma; | |
| 982 | − pTempMCRefMem.pDstU = pDstU2 + iUVLineStride; | |
| 983 | − pTempMCRefMem.pDstV = pDstV2 + iUVLineStride;; | |
| 984 | − | |
| 985 | − iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + iJIdx][0]; | |
| 986 | − iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + iJIdx][1]; | |
| 987 | − BaseMC (&pTempMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs); | |
| 988 | − | |
| 989 | − if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 990 | − BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 4); | |
| 991 | − } else { | |
| 992 | − BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 4); | |
| 993 | − } | |
| 994 | − } | |
| 995 | − } else { | |
| 996 | − int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 997 | − int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 998 | − for (int32_t j = 0; j < 4; j++) { | |
| 999 | − int32_t iUVLineStride; | |
| 1000 | − iJIdx = ((j >> 1) << 2) + (j & 1); | |
| 1001 | − | |
| 1002 | − iBlk4X = (j & 1) << 2; | |
| 1003 | − iBlk4Y = (j >> 1) << 2; | |
| 1004 | − | |
| 1005 | − iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma; | |
| 1006 | − pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma; | |
| 1007 | − pMCRefMem.pDstU = pDstU + iUVLineStride; | |
| 1008 | − pMCRefMem.pDstV = pDstV + iUVLineStride; | |
| 1009 | − | |
| 1010 | − iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + iJIdx][0]; | |
| 1011 | − iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + iJIdx][1]; | |
| 1012 | − BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs); | |
| 1013 | − if (bWeightedBipredIdcIs1) { | |
| 1014 | − WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 4, 4); | |
| 1015 | − } | |
| 1016 | − } | |
| 1017 | − } | |
| 1018 | − } | |
| 1019 | − } | |
| 1020 | − } | |
| 1021 | −} | |
| 1022 | − | |
| 1023 | −int32_t RecChroma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 1024 | − int32_t iChromaStride = pCtx->pCurDqLayer->pDec->iLinesize[1]; | |
| 1025 | − PIdctFourResAddPredFunc pIdctFourResAddPredFunc = pCtx->pIdctFourResAddPredFunc; | |
| 1026 | − | |
| 1027 | − uint8_t i = 0; | |
| 1028 | − uint8_t uiCbpC = pDqLayer->pCbp[iMBXY] >> 4; | |
| 1029 | − | |
| 1030 | − if (1 == uiCbpC || 2 == uiCbpC) { | |
| 1031 | − for (i = 0; i < 2; i++) { | |
| 1032 | − int16_t* pRS = pScoeffLevel + 256 + (i << 6); | |
| 1033 | − uint8_t* pPred = pDqLayer->pPred[i + 1]; | |
| 1034 | − const int8_t* pNzc = pDqLayer->pNzc[iMBXY] + 16 + 2 * i; | |
| 1035 | − | |
| 1036 | − /*1 chroma is divided 4 4x4_block to idct*/ | |
| 1037 | − pIdctFourResAddPredFunc (pPred, iChromaStride, pRS, pNzc); | |
| 1038 | − } | |
| 1039 | − } | |
| 1040 | − | |
| 1041 | − return ERR_NONE; | |
| 1042 | −} | |
| 1043 | − | |
| 1044 | −} // namespace WelsDec | |
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 2009-2013, Cisco Systems | |
| 4 | + * All rights reserved. | |
| 5 | + * | |
| 6 | + * Redistribution and use in source and binary forms, with or without | |
| 7 | + * modification, are permitted provided that the following conditions | |
| 8 | + * are met: | |
| 9 | + * | |
| 10 | + * * Redistributions of source code must retain the above copyright | |
| 11 | + * notice, this list of conditions and the following disclaimer. | |
| 12 | + * | |
| 13 | + * * Redistributions in binary form must reproduce the above copyright | |
| 14 | + * notice, this list of conditions and the following disclaimer in | |
| 15 | + * the documentation and/or other materials provided with the | |
| 16 | + * distribution. | |
| 17 | + * | |
| 18 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 21 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 22 | + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 23 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 26 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
| 28 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | + * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | + * | |
| 31 | + * | |
| 32 | + * \file rec_mb.c | |
| 33 | + * | |
| 34 | + * \brief implementation for all macroblock decoding process after mb syntax parsing and residual decoding with cavlc. | |
| 35 | + * | |
| 36 | + * \date 3/18/2009 Created | |
| 37 | + * | |
| 38 | + ************************************************************************************* | |
| 39 | + */ | |
| 40 | + | |
| 41 | + | |
| 42 | +#include "rec_mb.h" | |
| 43 | +#include "decode_slice.h" | |
| 44 | + | |
| 45 | +namespace WelsDec { | |
| 46 | + | |
| 47 | +void WelsFillRecNeededMbInfo (PWelsDecoderContext pCtx, bool bOutput, PDqLayer pCurLayer) { | |
| 48 | + PPicture pCurPic = pCtx->pDec; | |
| 49 | + int32_t iLumaStride = pCurPic->iLinesize[0]; | |
| 50 | + int32_t iChromaStride = pCurPic->iLinesize[1]; | |
| 51 | + int32_t iMbX = pCurLayer->iMbX; | |
| 52 | + int32_t iMbY = pCurLayer->iMbY; | |
| 53 | + | |
| 54 | + pCurLayer->iLumaStride = iLumaStride; | |
| 55 | + pCurLayer->iChromaStride = iChromaStride; | |
| 56 | + | |
| 57 | + if (bOutput) { | |
| 58 | + pCurLayer->pPred[0] = pCurPic->pData[0] + ((iMbY * iLumaStride + iMbX) << 4); | |
| 59 | + pCurLayer->pPred[1] = pCurPic->pData[1] + ((iMbY * iChromaStride + iMbX) << 3); | |
| 60 | + pCurLayer->pPred[2] = pCurPic->pData[2] + ((iMbY * iChromaStride + iMbX) << 3); | |
| 61 | + } | |
| 62 | +} | |
| 63 | + | |
| 64 | +int32_t RecI8x8Mb (int32_t iMbXy, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 65 | + RecI8x8Luma (iMbXy, pCtx, pScoeffLevel, pDqLayer); | |
| 66 | + RecI4x4Chroma (iMbXy, pCtx, pScoeffLevel, pDqLayer); | |
| 67 | + return ERR_NONE; | |
| 68 | +} | |
| 69 | + | |
| 70 | +int32_t RecI8x8Luma (int32_t iMbXy, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 71 | + /*****get local variable from outer variable********/ | |
| 72 | + /*prediction info*/ | |
| 73 | + uint8_t* pPred = pDqLayer->pPred[0]; | |
| 74 | + | |
| 75 | + int32_t iLumaStride = pDqLayer->iLumaStride; | |
| 76 | + int32_t* pBlockOffset = pCtx->iDecBlockOffsetArray; | |
| 77 | + PGetIntraPred8x8Func* pGetI8x8LumaPredFunc = pCtx->pGetI8x8LumaPredFunc; | |
| 78 | + | |
| 79 | + int8_t* pIntra8x8PredMode = pDqLayer->pIntra4x4FinalMode[iMbXy]; // I_NxN | |
| 80 | + int16_t* pRS = pScoeffLevel; | |
| 81 | + /*itransform info*/ | |
| 82 | + PIdctResAddPredFunc pIdctResAddPredFunc = pCtx->pIdctResAddPredFunc8x8; | |
| 83 | + | |
| 84 | + /*************local variable********************/ | |
| 85 | + uint8_t i = 0; | |
| 86 | + bool bTLAvail[4], bTRAvail[4]; | |
| 87 | + // Top-Right : Left : Top-Left : Top | |
| 88 | + bTLAvail[0] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x02); | |
| 89 | + bTLAvail[1] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x01); | |
| 90 | + bTLAvail[2] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x04); | |
| 91 | + bTLAvail[3] = true; | |
| 92 | + | |
| 93 | + bTRAvail[0] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x01); | |
| 94 | + bTRAvail[1] = !! (pDqLayer->pIntraNxNAvailFlag[iMbXy] & 0x08); | |
| 95 | + bTRAvail[2] = true; | |
| 96 | + bTRAvail[3] = false; | |
| 97 | + | |
| 98 | + /*************real process*********************/ | |
| 99 | + for (i = 0; i < 4; i++) { | |
| 100 | + | |
| 101 | + uint8_t* pPredI8x8 = pPred + pBlockOffset[i << 2]; | |
| 102 | + uint8_t uiMode = pIntra8x8PredMode[g_kuiScan4[i << 2]]; | |
| 103 | + | |
| 104 | + pGetI8x8LumaPredFunc[uiMode] (pPredI8x8, iLumaStride, bTLAvail[i], bTRAvail[i]); | |
| 105 | + | |
| 106 | + int32_t iIndex = g_kuiMbCountScan4Idx[i << 2]; | |
| 107 | + if (pDqLayer->pNzc[iMbXy][iIndex] || pDqLayer->pNzc[iMbXy][iIndex + 1] || pDqLayer->pNzc[iMbXy][iIndex + 4] | |
| 108 | + || pDqLayer->pNzc[iMbXy][iIndex + 5]) { | |
| 109 | + int16_t* pRSI8x8 = &pRS[i << 6]; | |
| 110 | + pIdctResAddPredFunc (pPredI8x8, iLumaStride, pRSI8x8); | |
| 111 | + } | |
| 112 | + } | |
| 113 | + | |
| 114 | + return ERR_NONE; | |
| 115 | +} | |
| 116 | + | |
| 117 | +int32_t RecI4x4Mb (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 118 | + RecI4x4Luma (iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 119 | + RecI4x4Chroma (iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 120 | + return ERR_NONE; | |
| 121 | +} | |
| 122 | + | |
| 123 | + | |
| 124 | +int32_t RecI4x4Luma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 125 | + /*****get local variable from outer variable********/ | |
| 126 | + /*prediction info*/ | |
| 127 | + uint8_t* pPred = pDqLayer->pPred[0]; | |
| 128 | + | |
| 129 | + int32_t iLumaStride = pDqLayer->iLumaStride; | |
| 130 | + int32_t* pBlockOffset = pCtx->iDecBlockOffsetArray; | |
| 131 | + PGetIntraPredFunc* pGetI4x4LumaPredFunc = pCtx->pGetI4x4LumaPredFunc; | |
| 132 | + | |
| 133 | + int8_t* pIntra4x4PredMode = pDqLayer->pIntra4x4FinalMode[iMBXY]; | |
| 134 | + int16_t* pRS = pScoeffLevel; | |
| 135 | + /*itransform info*/ | |
| 136 | + PIdctResAddPredFunc pIdctResAddPredFunc = pCtx->pIdctResAddPredFunc; | |
| 137 | + | |
| 138 | + | |
| 139 | + /*************local variable********************/ | |
| 140 | + uint8_t i = 0; | |
| 141 | + | |
| 142 | + /*************real process*********************/ | |
| 143 | + for (i = 0; i < 16; i++) { | |
| 144 | + | |
| 145 | + uint8_t* pPredI4x4 = pPred + pBlockOffset[i]; | |
| 146 | + uint8_t uiMode = pIntra4x4PredMode[g_kuiScan4[i]]; | |
| 147 | + | |
| 148 | + pGetI4x4LumaPredFunc[uiMode] (pPredI4x4, iLumaStride); | |
| 149 | + | |
| 150 | + if (pDqLayer->pNzc[iMBXY][g_kuiMbCountScan4Idx[i]]) { | |
| 151 | + int16_t* pRSI4x4 = &pRS[i << 4]; | |
| 152 | + pIdctResAddPredFunc (pPredI4x4, iLumaStride, pRSI4x4); | |
| 153 | + } | |
| 154 | + } | |
| 155 | + | |
| 156 | + return ERR_NONE; | |
| 157 | +} | |
| 158 | + | |
| 159 | + | |
| 160 | +int32_t RecI4x4Chroma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 161 | + int32_t iChromaStride = pCtx->pCurDqLayer->pDec->iLinesize[1]; | |
| 162 | + | |
| 163 | + int8_t iChromaPredMode = pDqLayer->pChromaPredMode[iMBXY]; | |
| 164 | + | |
| 165 | + PGetIntraPredFunc* pGetIChromaPredFunc = pCtx->pGetIChromaPredFunc; | |
| 166 | + | |
| 167 | + uint8_t* pPred = pDqLayer->pPred[1]; | |
| 168 | + | |
| 169 | + pGetIChromaPredFunc[iChromaPredMode] (pPred, iChromaStride); | |
| 170 | + pPred = pDqLayer->pPred[2]; | |
| 171 | + pGetIChromaPredFunc[iChromaPredMode] (pPred, iChromaStride); | |
| 172 | + | |
| 173 | + RecChroma (iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 174 | + | |
| 175 | + return ERR_NONE; | |
| 176 | +} | |
| 177 | + | |
| 178 | + | |
| 179 | +int32_t RecI16x16Mb (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 180 | + /*decoder use, encoder no use*/ | |
| 181 | + int8_t iI16x16PredMode = pDqLayer->pIntraPredMode[iMBXY][7]; | |
| 182 | + int8_t iChromaPredMode = pDqLayer->pChromaPredMode[iMBXY]; | |
| 183 | + PGetIntraPredFunc* pGetIChromaPredFunc = pCtx->pGetIChromaPredFunc; | |
| 184 | + PGetIntraPredFunc* pGetI16x16LumaPredFunc = pCtx->pGetI16x16LumaPredFunc; | |
| 185 | + int32_t iUVStride = pCtx->pCurDqLayer->pDec->iLinesize[1]; | |
| 186 | + | |
| 187 | + /*common use by decoder&encoder*/ | |
| 188 | + int32_t iYStride = pDqLayer->iLumaStride; | |
| 189 | + int16_t* pRS = pScoeffLevel; | |
| 190 | + | |
| 191 | + uint8_t* pPred = pDqLayer->pPred[0]; | |
| 192 | + | |
| 193 | + PIdctFourResAddPredFunc pIdctFourResAddPredFunc = pCtx->pIdctFourResAddPredFunc; | |
| 194 | + | |
| 195 | + /*decode i16x16 y*/ | |
| 196 | + pGetI16x16LumaPredFunc[iI16x16PredMode] (pPred, iYStride); | |
| 197 | + | |
| 198 | + /*1 mb is divided 16 4x4_block to idct*/ | |
| 199 | + const int8_t* pNzc = pDqLayer->pNzc[iMBXY]; | |
| 200 | + pIdctFourResAddPredFunc (pPred + 0 * iYStride + 0, iYStride, pRS + 0 * 64, pNzc + 0); | |
| 201 | + pIdctFourResAddPredFunc (pPred + 0 * iYStride + 8, iYStride, pRS + 1 * 64, pNzc + 2); | |
| 202 | + pIdctFourResAddPredFunc (pPred + 8 * iYStride + 0, iYStride, pRS + 2 * 64, pNzc + 8); | |
| 203 | + pIdctFourResAddPredFunc (pPred + 8 * iYStride + 8, iYStride, pRS + 3 * 64, pNzc + 10); | |
| 204 | + | |
| 205 | + /*decode intra mb cb&cr*/ | |
| 206 | + pPred = pDqLayer->pPred[1]; | |
| 207 | + pGetIChromaPredFunc[iChromaPredMode] (pPred, iUVStride); | |
| 208 | + pPred = pDqLayer->pPred[2]; | |
| 209 | + pGetIChromaPredFunc[iChromaPredMode] (pPred, iUVStride); | |
| 210 | + RecChroma (iMBXY, pCtx, pScoeffLevel, pDqLayer); | |
| 211 | + | |
| 212 | + return ERR_NONE; | |
| 213 | +} | |
| 214 | + | |
| 215 | + | |
| 216 | +//according to current 8*8 block ref_index to gain reference picture | |
| 217 | +static inline void GetRefPic (sMCRefMember* pMCRefMem, PWelsDecoderContext pCtx, int8_t* pRefIdxList, | |
| 218 | + int32_t iIndex, int32_t listIdx) { | |
| 219 | + PPicture pRefPic; | |
| 220 | + | |
| 221 | + int8_t iRefIdx = pRefIdxList[iIndex]; | |
| 222 | + if (iRefIdx >= 0) { | |
| 223 | + pRefPic = pCtx->sRefPic.pRefList[listIdx][iRefIdx]; | |
| 224 | + | |
| 225 | + if (pRefPic != NULL) { | |
| 226 | + pMCRefMem->iSrcLineLuma = pRefPic->iLinesize[0]; | |
| 227 | + pMCRefMem->iSrcLineChroma = pRefPic->iLinesize[1]; | |
| 228 | + | |
| 229 | + pMCRefMem->pSrcY = pRefPic->pData[0]; | |
| 230 | + pMCRefMem->pSrcU = pRefPic->pData[1]; | |
| 231 | + pMCRefMem->pSrcV = pRefPic->pData[2]; | |
| 232 | + } | |
| 233 | + } | |
| 234 | +} | |
| 235 | + | |
| 236 | + | |
| 237 | +#ifndef MC_FLOW_SIMPLE_JUDGE | |
| 238 | +#define MC_FLOW_SIMPLE_JUDGE 1 | |
| 239 | +#endif //MC_FLOW_SIMPLE_JUDGE | |
| 240 | +void BaseMC (sMCRefMember* pMCRefMem, int32_t iXOffset, int32_t iYOffset, SMcFunc* pMCFunc, | |
| 241 | + int32_t iBlkWidth, int32_t iBlkHeight, int16_t iMVs[2]) { | |
| 242 | + int32_t iFullMVx = (iXOffset << 2) + iMVs[0]; //quarter pixel | |
| 243 | + int32_t iFullMVy = (iYOffset << 2) + iMVs[1]; | |
| 244 | + iFullMVx = WELS_CLIP3 (iFullMVx, ((-PADDING_LENGTH + 2) * (1 << 2)), | |
| 245 | + ((pMCRefMem->iPicWidth + PADDING_LENGTH - 19) * (1 << 2))); | |
| 246 | + iFullMVy = WELS_CLIP3 (iFullMVy, ((-PADDING_LENGTH + 2) * (1 << 2)), | |
| 247 | + ((pMCRefMem->iPicHeight + PADDING_LENGTH - 19) * (1 << 2))); | |
| 248 | + | |
| 249 | + int32_t iSrcPixOffsetLuma = (iFullMVx >> 2) + (iFullMVy >> 2) * pMCRefMem->iSrcLineLuma; | |
| 250 | + int32_t iSrcPixOffsetChroma = (iFullMVx >> 3) + (iFullMVy >> 3) * pMCRefMem->iSrcLineChroma; | |
| 251 | + | |
| 252 | + int32_t iBlkWidthChroma = iBlkWidth >> 1; | |
| 253 | + int32_t iBlkHeightChroma = iBlkHeight >> 1; | |
| 254 | + | |
| 255 | + uint8_t* pSrcY = pMCRefMem->pSrcY + iSrcPixOffsetLuma; | |
| 256 | + uint8_t* pSrcU = pMCRefMem->pSrcU + iSrcPixOffsetChroma; | |
| 257 | + uint8_t* pSrcV = pMCRefMem->pSrcV + iSrcPixOffsetChroma; | |
| 258 | + uint8_t* pDstY = pMCRefMem->pDstY; | |
| 259 | + uint8_t* pDstU = pMCRefMem->pDstU; | |
| 260 | + uint8_t* pDstV = pMCRefMem->pDstV; | |
| 261 | + | |
| 262 | + pMCFunc->pMcLumaFunc (pSrcY, pMCRefMem->iSrcLineLuma, pDstY, pMCRefMem->iDstLineLuma, iFullMVx, iFullMVy, iBlkWidth, | |
| 263 | + iBlkHeight); | |
| 264 | + pMCFunc->pMcChromaFunc (pSrcU, pMCRefMem->iSrcLineChroma, pDstU, pMCRefMem->iDstLineChroma, iFullMVx, iFullMVy, | |
| 265 | + iBlkWidthChroma, iBlkHeightChroma); | |
| 266 | + pMCFunc->pMcChromaFunc (pSrcV, pMCRefMem->iSrcLineChroma, pDstV, pMCRefMem->iDstLineChroma, iFullMVx, iFullMVy, | |
| 267 | + iBlkWidthChroma, iBlkHeightChroma); | |
| 268 | + | |
| 269 | +} | |
| 270 | + | |
| 271 | +static void WeightPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, int32_t listIdx, int32_t iRefIdx, | |
| 272 | + int32_t iBlkWidth, | |
| 273 | + int32_t iBlkHeight) { | |
| 274 | + | |
| 275 | + | |
| 276 | + int32_t iLog2denom, iWoc, iOoc; | |
| 277 | + int32_t iPredTemp, iLineStride; | |
| 278 | + int32_t iPixel = 0; | |
| 279 | + uint8_t* pDst; | |
| 280 | + //luma | |
| 281 | + iLog2denom = pCurDqLayer->pPredWeightTable->uiLumaLog2WeightDenom; | |
| 282 | + iWoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iLumaWeight[iRefIdx]; | |
| 283 | + iOoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iLumaOffset[iRefIdx]; | |
| 284 | + iLineStride = pMCRefMem->iDstLineLuma; | |
| 285 | + | |
| 286 | + for (int i = 0; i < iBlkHeight; i++) { | |
| 287 | + for (int j = 0; j < iBlkWidth; j++) { | |
| 288 | + iPixel = j + i * (iLineStride); | |
| 289 | + if (iLog2denom >= 1) { | |
| 290 | + iPredTemp = ((pMCRefMem->pDstY[iPixel] * iWoc + (1 << (iLog2denom - 1))) >> iLog2denom) + iOoc; | |
| 291 | + | |
| 292 | + pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 293 | + } else { | |
| 294 | + iPredTemp = pMCRefMem->pDstY[iPixel] * iWoc + iOoc; | |
| 295 | + | |
| 296 | + pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 297 | + | |
| 298 | + } | |
| 299 | + } | |
| 300 | + } | |
| 301 | + | |
| 302 | + | |
| 303 | + //UV | |
| 304 | + iBlkWidth = iBlkWidth >> 1; | |
| 305 | + iBlkHeight = iBlkHeight >> 1; | |
| 306 | + iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom; | |
| 307 | + iLineStride = pMCRefMem->iDstLineChroma; | |
| 308 | + | |
| 309 | + for (int i = 0; i < 2; i++) { | |
| 310 | + | |
| 311 | + | |
| 312 | + //iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom; | |
| 313 | + iWoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iChromaWeight[iRefIdx][i]; | |
| 314 | + iOoc = pCurDqLayer->pPredWeightTable->sPredList[listIdx].iChromaOffset[iRefIdx][i]; | |
| 315 | + pDst = i ? pMCRefMem->pDstV : pMCRefMem->pDstU; | |
| 316 | + //iLineStride = pMCRefMem->iDstLineChroma; | |
| 317 | + | |
| 318 | + for (int i = 0; i < iBlkHeight ; i++) { | |
| 319 | + for (int j = 0; j < iBlkWidth; j++) { | |
| 320 | + iPixel = j + i * (iLineStride); | |
| 321 | + if (iLog2denom >= 1) { | |
| 322 | + iPredTemp = ((pDst[iPixel] * iWoc + (1 << (iLog2denom - 1))) >> iLog2denom) + iOoc; | |
| 323 | + | |
| 324 | + pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 325 | + } else { | |
| 326 | + iPredTemp = pDst[iPixel] * iWoc + iOoc; | |
| 327 | + | |
| 328 | + pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 329 | + | |
| 330 | + } | |
| 331 | + } | |
| 332 | + | |
| 333 | + } | |
| 334 | + | |
| 335 | + | |
| 336 | + } | |
| 337 | +} | |
| 338 | + | |
| 339 | +static void BiWeightPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, sMCRefMember* pTempMCRefMem, | |
| 340 | + int32_t iRefIdx1, int32_t iRefIdx2, bool bWeightedBipredIdcIs1, int32_t iBlkWidth, | |
| 341 | + int32_t iBlkHeight) { | |
| 342 | + int32_t iWoc1 = 0, iOoc1 = 0, iWoc2 = 0, iOoc2 = 0; | |
| 343 | + int32_t iPredTemp, iLineStride; | |
| 344 | + int32_t iPixel = 0; | |
| 345 | + //luma | |
| 346 | + int32_t iLog2denom = pCurDqLayer->pPredWeightTable->uiLumaLog2WeightDenom; | |
| 347 | + if (bWeightedBipredIdcIs1) { | |
| 348 | + iWoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iLumaWeight[iRefIdx1]; | |
| 349 | + iOoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iLumaOffset[iRefIdx1]; | |
| 350 | + iWoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iLumaWeight[iRefIdx2]; | |
| 351 | + iOoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iLumaOffset[iRefIdx2]; | |
| 352 | + } else { | |
| 353 | + iWoc1 = pCurDqLayer->pPredWeightTable->iImplicitWeight[iRefIdx1][iRefIdx2]; | |
| 354 | + iWoc2 = 64 - iWoc1; | |
| 355 | + } | |
| 356 | + iLineStride = pMCRefMem->iDstLineLuma; | |
| 357 | + | |
| 358 | + for (int i = 0; i < iBlkHeight; i++) { | |
| 359 | + for (int j = 0; j < iBlkWidth; j++) { | |
| 360 | + iPixel = j + i * (iLineStride); | |
| 361 | + iPredTemp = ((pMCRefMem->pDstY[iPixel] * iWoc1 + pTempMCRefMem->pDstY[iPixel] * iWoc2 + (1 << iLog2denom)) >> | |
| 362 | + (iLog2denom + 1)) + ((iOoc1 + iOoc2 + 1) >> 1); | |
| 363 | + pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 364 | + } | |
| 365 | + } | |
| 366 | + | |
| 367 | + //UV | |
| 368 | + iBlkWidth = iBlkWidth >> 1; | |
| 369 | + iBlkHeight = iBlkHeight >> 1; | |
| 370 | + iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom; | |
| 371 | + iLineStride = pMCRefMem->iDstLineChroma; | |
| 372 | + | |
| 373 | + uint8_t* pDst; | |
| 374 | + uint8_t* pTempDst; | |
| 375 | + for (int k = 0; k < 2; k++) { | |
| 376 | + //iLog2denom = pCurDqLayer->pPredWeightTable->uiChromaLog2WeightDenom; | |
| 377 | + if (bWeightedBipredIdcIs1) { | |
| 378 | + iWoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iChromaWeight[iRefIdx1][k]; | |
| 379 | + iOoc1 = pCurDqLayer->pPredWeightTable->sPredList[LIST_0].iChromaOffset[iRefIdx1][k]; | |
| 380 | + iWoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iChromaWeight[iRefIdx2][k]; | |
| 381 | + iOoc2 = pCurDqLayer->pPredWeightTable->sPredList[LIST_1].iChromaOffset[iRefIdx2][k]; | |
| 382 | + } | |
| 383 | + pDst = k ? pMCRefMem->pDstV : pMCRefMem->pDstU; | |
| 384 | + pTempDst = k ? pTempMCRefMem->pDstV : pTempMCRefMem->pDstU; | |
| 385 | + //iLineStride = pMCRefMem->iDstLineChroma; | |
| 386 | + | |
| 387 | + for (int i = 0; i < iBlkHeight; i++) { | |
| 388 | + for (int j = 0; j < iBlkWidth; j++) { | |
| 389 | + iPixel = j + i * (iLineStride); | |
| 390 | + iPredTemp = ((pDst[iPixel] * iWoc1 + pTempDst[iPixel] * iWoc2 + (1 << iLog2denom)) >> (iLog2denom + 1)) + (( | |
| 391 | + iOoc1 + iOoc2 + 1) >> 1); | |
| 392 | + pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 393 | + } | |
| 394 | + } | |
| 395 | + } | |
| 396 | +} | |
| 397 | + | |
| 398 | +static void BiPrediction (PDqLayer pCurDqLayer, sMCRefMember* pMCRefMem, sMCRefMember* pTempMCRefMem, int32_t iBlkWidth, | |
| 399 | + int32_t iBlkHeight) { | |
| 400 | + int32_t iPredTemp, iLineStride; | |
| 401 | + int32_t iPixel = 0; | |
| 402 | + //luma | |
| 403 | + iLineStride = pMCRefMem->iDstLineLuma; | |
| 404 | + | |
| 405 | + for (int i = 0; i < iBlkHeight; i++) { | |
| 406 | + for (int j = 0; j < iBlkWidth; j++) { | |
| 407 | + iPixel = j + i * (iLineStride); | |
| 408 | + iPredTemp = (pMCRefMem->pDstY[iPixel] + pTempMCRefMem->pDstY[iPixel] + 1) >> 1; | |
| 409 | + pMCRefMem->pDstY[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 410 | + } | |
| 411 | + } | |
| 412 | + | |
| 413 | + //UV | |
| 414 | + iBlkWidth = iBlkWidth >> 1; | |
| 415 | + iBlkHeight = iBlkHeight >> 1; | |
| 416 | + iLineStride = pMCRefMem->iDstLineChroma; | |
| 417 | + | |
| 418 | + uint8_t* pDst; | |
| 419 | + uint8_t* pTempDst; | |
| 420 | + for (int k = 0; k < 2; k++) { | |
| 421 | + pDst = k ? pMCRefMem->pDstV : pMCRefMem->pDstU; | |
| 422 | + pTempDst = k ? pTempMCRefMem->pDstV : pTempMCRefMem->pDstU; | |
| 423 | + //iLineStride = pMCRefMem->iDstLineChroma; | |
| 424 | + | |
| 425 | + for (int i = 0; i < iBlkHeight; i++) { | |
| 426 | + for (int j = 0; j < iBlkWidth; j++) { | |
| 427 | + iPixel = j + i * (iLineStride); | |
| 428 | + iPredTemp = (pDst[iPixel] + pTempDst[iPixel] + 1) >> 1; | |
| 429 | + pDst[iPixel] = WELS_CLIP3 (iPredTemp, 0, 255); | |
| 430 | + } | |
| 431 | + } | |
| 432 | + } | |
| 433 | +} | |
| 434 | + | |
| 435 | +void GetInterPred (uint8_t* pPredY, uint8_t* pPredCb, uint8_t* pPredCr, PWelsDecoderContext pCtx) { | |
| 436 | + sMCRefMember pMCRefMem; | |
| 437 | + PDqLayer pCurDqLayer = pCtx->pCurDqLayer; | |
| 438 | + SMcFunc* pMCFunc = &pCtx->sMcFunc; | |
| 439 | + | |
| 440 | + int32_t iMBXY = pCurDqLayer->iMbXyIndex; | |
| 441 | + | |
| 442 | + int16_t iMVs[2] = {0}; | |
| 443 | + | |
| 444 | + uint32_t iMBType = pCurDqLayer->pMbType[iMBXY]; | |
| 445 | + | |
| 446 | + int32_t iMBOffsetX = pCurDqLayer->iMbX << 4; | |
| 447 | + int32_t iMBOffsetY = pCurDqLayer->iMbY << 4; | |
| 448 | + | |
| 449 | + int32_t iDstLineLuma = pCtx->pDec->iLinesize[0]; | |
| 450 | + int32_t iDstLineChroma = pCtx->pDec->iLinesize[1]; | |
| 451 | + | |
| 452 | + int32_t iBlk8X, iBlk8Y, iBlk4X, iBlk4Y, i, j, iIIdx, iJIdx; | |
| 453 | + | |
| 454 | + pMCRefMem.iPicWidth = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbWidth << 4); | |
| 455 | + pMCRefMem.iPicHeight = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbHeight << 4); | |
| 456 | + | |
| 457 | + pMCRefMem.pDstY = pPredY; | |
| 458 | + pMCRefMem.pDstU = pPredCb; | |
| 459 | + pMCRefMem.pDstV = pPredCr; | |
| 460 | + | |
| 461 | + pMCRefMem.iDstLineLuma = iDstLineLuma; | |
| 462 | + pMCRefMem.iDstLineChroma = iDstLineChroma; | |
| 463 | + | |
| 464 | + int32_t iRefIndex = 0; | |
| 465 | + | |
| 466 | + switch (iMBType) { | |
| 467 | + case MB_TYPE_SKIP: | |
| 468 | + case MB_TYPE_16x16: | |
| 469 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0]; | |
| 470 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1]; | |
| 471 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0); | |
| 472 | + BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs); | |
| 473 | + | |
| 474 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 475 | + iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0]; | |
| 476 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 16); | |
| 477 | + } | |
| 478 | + break; | |
| 479 | + case MB_TYPE_16x8: | |
| 480 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0]; | |
| 481 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1]; | |
| 482 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0); | |
| 483 | + BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 8, iMVs); | |
| 484 | + | |
| 485 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 486 | + iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0]; | |
| 487 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 8); | |
| 488 | + } | |
| 489 | + | |
| 490 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][8][0]; | |
| 491 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][8][1]; | |
| 492 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 8, LIST_0); | |
| 493 | + pMCRefMem.pDstY = pPredY + (iDstLineLuma << 3); | |
| 494 | + pMCRefMem.pDstU = pPredCb + (iDstLineChroma << 2); | |
| 495 | + pMCRefMem.pDstV = pPredCr + (iDstLineChroma << 2); | |
| 496 | + BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY + 8, pMCFunc, 16, 8, iMVs); | |
| 497 | + | |
| 498 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 499 | + iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][8]; | |
| 500 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 16, 8); | |
| 501 | + } | |
| 502 | + break; | |
| 503 | + case MB_TYPE_8x16: | |
| 504 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][0][0]; | |
| 505 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][0][1]; | |
| 506 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 0, LIST_0); | |
| 507 | + BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 508 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 509 | + iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][0]; | |
| 510 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 16); | |
| 511 | + } | |
| 512 | + | |
| 513 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][2][0]; | |
| 514 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][2][1]; | |
| 515 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], 2, LIST_0); | |
| 516 | + pMCRefMem.pDstY = pPredY + 8; | |
| 517 | + pMCRefMem.pDstU = pPredCb + 4; | |
| 518 | + pMCRefMem.pDstV = pPredCr + 4; | |
| 519 | + BaseMC (&pMCRefMem, iMBOffsetX + 8, iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 520 | + | |
| 521 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 522 | + iRefIndex = pCurDqLayer->pRefIndex[0][iMBXY][2]; | |
| 523 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 16); | |
| 524 | + } | |
| 525 | + break; | |
| 526 | + case MB_TYPE_8x8: | |
| 527 | + case MB_TYPE_8x8_REF0: { | |
| 528 | + uint32_t iSubMBType; | |
| 529 | + int32_t iXOffset, iYOffset; | |
| 530 | + uint8_t* pDstY, *pDstU, *pDstV; | |
| 531 | + for (i = 0; i < 4; i++) { | |
| 532 | + iSubMBType = pCurDqLayer->pSubMbType[iMBXY][i]; | |
| 533 | + iBlk8X = (i & 1) << 3; | |
| 534 | + iBlk8Y = (i >> 1) << 3; | |
| 535 | + iXOffset = iMBOffsetX + iBlk8X; | |
| 536 | + iYOffset = iMBOffsetY + iBlk8Y; | |
| 537 | + | |
| 538 | + iIIdx = ((i >> 1) << 3) + ((i & 1) << 1); | |
| 539 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[0][iMBXY], iIIdx, LIST_0); | |
| 540 | + iRefIndex = pCurDqLayer->bUseWeightPredictionFlag ? pCurDqLayer->pRefIndex[0][iMBXY][iIIdx] : 0; | |
| 541 | + | |
| 542 | + pDstY = pPredY + iBlk8X + iBlk8Y * iDstLineLuma; | |
| 543 | + pDstU = pPredCb + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 544 | + pDstV = pPredCr + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 545 | + pMCRefMem.pDstY = pDstY; | |
| 546 | + pMCRefMem.pDstU = pDstU; | |
| 547 | + pMCRefMem.pDstV = pDstV; | |
| 548 | + switch (iSubMBType) { | |
| 549 | + case SUB_MB_TYPE_8x8: | |
| 550 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0]; | |
| 551 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1]; | |
| 552 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs); | |
| 553 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 554 | + | |
| 555 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 8); | |
| 556 | + } | |
| 557 | + | |
| 558 | + break; | |
| 559 | + case SUB_MB_TYPE_8x4: | |
| 560 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0]; | |
| 561 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1]; | |
| 562 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs); | |
| 563 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 564 | + | |
| 565 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 4); | |
| 566 | + } | |
| 567 | + | |
| 568 | + | |
| 569 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 4][0]; | |
| 570 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 4][1]; | |
| 571 | + pMCRefMem.pDstY += (iDstLineLuma << 2); | |
| 572 | + pMCRefMem.pDstU += (iDstLineChroma << 1); | |
| 573 | + pMCRefMem.pDstV += (iDstLineChroma << 1); | |
| 574 | + BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs); | |
| 575 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 576 | + | |
| 577 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 8, 4); | |
| 578 | + } | |
| 579 | + | |
| 580 | + break; | |
| 581 | + case SUB_MB_TYPE_4x8: | |
| 582 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx][0]; | |
| 583 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx][1]; | |
| 584 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 585 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 586 | + | |
| 587 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 8); | |
| 588 | + } | |
| 589 | + | |
| 590 | + | |
| 591 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 1][0]; | |
| 592 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + 1][1]; | |
| 593 | + pMCRefMem.pDstY += 4; | |
| 594 | + pMCRefMem.pDstU += 2; | |
| 595 | + pMCRefMem.pDstV += 2; | |
| 596 | + BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 597 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 598 | + | |
| 599 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 8); | |
| 600 | + } | |
| 601 | + | |
| 602 | + break; | |
| 603 | + case SUB_MB_TYPE_4x4: { | |
| 604 | + for (j = 0; j < 4; j++) { | |
| 605 | + int32_t iUVLineStride; | |
| 606 | + iJIdx = ((j >> 1) << 2) + (j & 1); | |
| 607 | + | |
| 608 | + iBlk4X = (j & 1) << 2; | |
| 609 | + iBlk4Y = (j >> 1) << 2; | |
| 610 | + | |
| 611 | + iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma; | |
| 612 | + pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma; | |
| 613 | + pMCRefMem.pDstU = pDstU + iUVLineStride; | |
| 614 | + pMCRefMem.pDstV = pDstV + iUVLineStride; | |
| 615 | + | |
| 616 | + iMVs[0] = pCurDqLayer->pMv[0][iMBXY][iIIdx + iJIdx][0]; | |
| 617 | + iMVs[1] = pCurDqLayer->pMv[0][iMBXY][iIIdx + iJIdx][1]; | |
| 618 | + BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs); | |
| 619 | + if (pCurDqLayer->bUseWeightPredictionFlag) { | |
| 620 | + | |
| 621 | + WeightPrediction (pCurDqLayer, &pMCRefMem, LIST_0, iRefIndex, 4, 4); | |
| 622 | + } | |
| 623 | + | |
| 624 | + } | |
| 625 | + } | |
| 626 | + break; | |
| 627 | + default: | |
| 628 | + break; | |
| 629 | + } | |
| 630 | + } | |
| 631 | + } | |
| 632 | + break; | |
| 633 | + default: | |
| 634 | + break; | |
| 635 | + } | |
| 636 | +} | |
| 637 | + | |
| 638 | +void GetInterBPred (uint8_t* pPredYCbCr[3], uint8_t* pTempPredYCbCr[3], PWelsDecoderContext pCtx) { | |
| 639 | + sMCRefMember pMCRefMem; | |
| 640 | + sMCRefMember pTempMCRefMem; | |
| 641 | + | |
| 642 | + PDqLayer pCurDqLayer = pCtx->pCurDqLayer; | |
| 643 | + SMcFunc* pMCFunc = &pCtx->sMcFunc; | |
| 644 | + | |
| 645 | + int32_t iMBXY = pCurDqLayer->iMbXyIndex; | |
| 646 | + | |
| 647 | + int16_t iMVs[2] = { 0 }; | |
| 648 | + | |
| 649 | + uint32_t iMBType = pCurDqLayer->pMbType[iMBXY]; | |
| 650 | + | |
| 651 | + int32_t iMBOffsetX = pCurDqLayer->iMbX << 4; | |
| 652 | + int32_t iMBOffsetY = pCurDqLayer->iMbY << 4; | |
| 653 | + | |
| 654 | + int32_t iDstLineLuma = pCtx->pDec->iLinesize[0]; | |
| 655 | + int32_t iDstLineChroma = pCtx->pDec->iLinesize[1]; | |
| 656 | + | |
| 657 | + | |
| 658 | + pMCRefMem.iPicWidth = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbWidth << 4); | |
| 659 | + pMCRefMem.iPicHeight = (pCurDqLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt.sSliceHeader.iMbHeight << 4); | |
| 660 | + | |
| 661 | + pMCRefMem.pDstY = pPredYCbCr[0]; | |
| 662 | + pMCRefMem.pDstU = pPredYCbCr[1]; | |
| 663 | + pMCRefMem.pDstV = pPredYCbCr[2]; | |
| 664 | + | |
| 665 | + pMCRefMem.iDstLineLuma = iDstLineLuma; | |
| 666 | + pMCRefMem.iDstLineChroma = iDstLineChroma; | |
| 667 | + | |
| 668 | + pTempMCRefMem = pMCRefMem; | |
| 669 | + pTempMCRefMem.pDstY = pTempPredYCbCr[0]; | |
| 670 | + pTempMCRefMem.pDstU = pTempPredYCbCr[1]; | |
| 671 | + pTempMCRefMem.pDstV = pTempPredYCbCr[2]; | |
| 672 | + | |
| 673 | + | |
| 674 | + int32_t iRefIndex1 = 0; | |
| 675 | + int32_t iRefIndex2 = 0; | |
| 676 | + | |
| 677 | + bool bWeightedBipredIdcIs1 = pCurDqLayer->sLayerInfo.pPps->uiWeightedBipredIdc == 1; | |
| 678 | + | |
| 679 | + if (IS_INTER_16x16 (iMBType)) { | |
| 680 | + if (IS_TYPE_L0 (iMBType) && IS_TYPE_L1 (iMBType)) { | |
| 681 | + iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][0][0]; | |
| 682 | + iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][0][1]; | |
| 683 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_0][iMBXY], 0, LIST_0); | |
| 684 | + BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs); | |
| 685 | + | |
| 686 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][0][0]; | |
| 687 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][0][1]; | |
| 688 | + GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], 0, LIST_1); | |
| 689 | + BaseMC (&pTempMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs); | |
| 690 | + iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][0]; | |
| 691 | + iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][0]; | |
| 692 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 693 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 16, 16); | |
| 694 | + } else { | |
| 695 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 16, 16); | |
| 696 | + } | |
| 697 | + } else { | |
| 698 | + int32_t listIdx = (iMBType & MB_TYPE_P0L0) ? LIST_0 : LIST_1; | |
| 699 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][0][0]; | |
| 700 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][0][1]; | |
| 701 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], 0, listIdx); | |
| 702 | + BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY, pMCFunc, 16, 16, iMVs); | |
| 703 | + if (bWeightedBipredIdcIs1) { | |
| 704 | + int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][0]; | |
| 705 | + WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 16, 16); | |
| 706 | + } | |
| 707 | + } | |
| 708 | + } else if (IS_INTER_16x8 (iMBType)) { | |
| 709 | + for (int32_t i = 0; i < 2; ++i) { | |
| 710 | + int32_t iPartIdx = i << 3; | |
| 711 | + uint32_t listCount = 0; | |
| 712 | + int32_t lastListIdx = LIST_0; | |
| 713 | + for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 714 | + if (IS_DIR (iMBType, i, listIdx)) { | |
| 715 | + lastListIdx = listIdx; | |
| 716 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iPartIdx][0]; | |
| 717 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iPartIdx][1]; | |
| 718 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], iPartIdx, listIdx); | |
| 719 | + if (i) { | |
| 720 | + pMCRefMem.pDstY += (iDstLineLuma << 3); | |
| 721 | + pMCRefMem.pDstU += (iDstLineChroma << 2); | |
| 722 | + pMCRefMem.pDstV += (iDstLineChroma << 2); | |
| 723 | + } | |
| 724 | + BaseMC (&pMCRefMem, iMBOffsetX, iMBOffsetY + iPartIdx, pMCFunc, 16, 8, iMVs); | |
| 725 | + if (++listCount == 2) { | |
| 726 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iPartIdx][0]; | |
| 727 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iPartIdx][1]; | |
| 728 | + GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], iPartIdx, LIST_1); | |
| 729 | + if (i) { | |
| 730 | + pTempMCRefMem.pDstY += (iDstLineLuma << 3); | |
| 731 | + pTempMCRefMem.pDstU += (iDstLineChroma << 2); | |
| 732 | + pTempMCRefMem.pDstV += (iDstLineChroma << 2); | |
| 733 | + } | |
| 734 | + BaseMC (&pTempMCRefMem, iMBOffsetX, iMBOffsetY + iPartIdx, pMCFunc, 16, 8, iMVs); | |
| 735 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 736 | + iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][iPartIdx]; | |
| 737 | + iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][iPartIdx]; | |
| 738 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 16, 8); | |
| 739 | + } else { | |
| 740 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 16, 8); | |
| 741 | + } | |
| 742 | + } | |
| 743 | + } | |
| 744 | + } | |
| 745 | + if (listCount == 1) { | |
| 746 | + if (bWeightedBipredIdcIs1) { | |
| 747 | + int32_t iRefIndex = pCurDqLayer->pRefIndex[lastListIdx][iMBXY][iPartIdx]; | |
| 748 | + WeightPrediction (pCurDqLayer, &pMCRefMem, lastListIdx, iRefIndex, 16, 8); | |
| 749 | + } | |
| 750 | + } | |
| 751 | + } | |
| 752 | + } else if (IS_INTER_8x16 (iMBType)) { | |
| 753 | + for (int32_t i = 0; i < 2; ++i) { | |
| 754 | + uint32_t listCount = 0; | |
| 755 | + int32_t lastListIdx = LIST_0; | |
| 756 | + for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | |
| 757 | + if (IS_DIR (iMBType, i, listIdx)) { | |
| 758 | + lastListIdx = listIdx; | |
| 759 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][i << 1][0]; | |
| 760 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][i << 1][1]; | |
| 761 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], i << 1, listIdx); | |
| 762 | + if (i) { | |
| 763 | + pMCRefMem.pDstY += 8; | |
| 764 | + pMCRefMem.pDstU += 4; | |
| 765 | + pMCRefMem.pDstV += 4; | |
| 766 | + } | |
| 767 | + BaseMC (&pMCRefMem, iMBOffsetX + (i ? 8 : 0), iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 768 | + if (++listCount == 2) { | |
| 769 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][i << 1][0]; | |
| 770 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][i << 1][1]; | |
| 771 | + GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], i << 1, LIST_1); | |
| 772 | + if (i) { | |
| 773 | + pTempMCRefMem.pDstY += 8; | |
| 774 | + pTempMCRefMem.pDstU += 4; | |
| 775 | + pTempMCRefMem.pDstV += 4; | |
| 776 | + } | |
| 777 | + BaseMC (&pTempMCRefMem, iMBOffsetX + (i ? 8 : 0), iMBOffsetY, pMCFunc, 8, 16, iMVs); | |
| 778 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 779 | + iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][i << 1]; | |
| 780 | + iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][i << 1]; | |
| 781 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 16); | |
| 782 | + } else { | |
| 783 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 16); | |
| 784 | + } | |
| 785 | + } | |
| 786 | + } | |
| 787 | + } | |
| 788 | + if (listCount == 1) { | |
| 789 | + if (bWeightedBipredIdcIs1) { | |
| 790 | + int32_t iRefIndex = pCurDqLayer->pRefIndex[lastListIdx][iMBXY][i << 1]; | |
| 791 | + WeightPrediction (pCurDqLayer, &pMCRefMem, lastListIdx, iRefIndex, 8, 16); | |
| 792 | + } | |
| 793 | + } | |
| 794 | + } | |
| 795 | + } else if (IS_Inter_8x8 (iMBType)) { | |
| 796 | + int32_t iBlk8X, iBlk8Y, iBlk4X, iBlk4Y, iIIdx, iJIdx; | |
| 797 | + uint32_t iSubMBType; | |
| 798 | + int32_t iXOffset, iYOffset; | |
| 799 | + uint8_t* pDstY, *pDstU, *pDstV; | |
| 800 | + uint8_t* pDstY2, *pDstU2, *pDstV2; | |
| 801 | + for (int32_t i = 0; i < 4; i++) { | |
| 802 | + iSubMBType = pCurDqLayer->pSubMbType[iMBXY][i]; | |
| 803 | + iBlk8X = (i & 1) << 3; | |
| 804 | + iBlk8Y = (i >> 1) << 3; | |
| 805 | + iXOffset = iMBOffsetX + iBlk8X; | |
| 806 | + iYOffset = iMBOffsetY + iBlk8Y; | |
| 807 | + | |
| 808 | + iIIdx = ((i >> 1) << 3) + ((i & 1) << 1); | |
| 809 | + | |
| 810 | + pDstY = pPredYCbCr[0] + iBlk8X + iBlk8Y * iDstLineLuma; | |
| 811 | + pDstU = pPredYCbCr[1] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 812 | + pDstV = pPredYCbCr[2] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 813 | + pMCRefMem.pDstY = pDstY; | |
| 814 | + pMCRefMem.pDstU = pDstU; | |
| 815 | + pMCRefMem.pDstV = pDstV; | |
| 816 | + | |
| 817 | + pTempMCRefMem = pMCRefMem; | |
| 818 | + pDstY2 = pTempPredYCbCr[0] + iBlk8X + iBlk8Y * iDstLineLuma; | |
| 819 | + pDstU2 = pTempPredYCbCr[1] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 820 | + pDstV2 = pTempPredYCbCr[2] + (iBlk8X >> 1) + (iBlk8Y >> 1) * iDstLineChroma; | |
| 821 | + | |
| 822 | + pTempMCRefMem.pDstY = pDstY2; | |
| 823 | + pTempMCRefMem.pDstU = pDstU2; | |
| 824 | + pTempMCRefMem.pDstV = pDstV2; | |
| 825 | + | |
| 826 | + if ((IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType))) { | |
| 827 | + iRefIndex1 = pCurDqLayer->pRefIndex[LIST_0][iMBXY][iIIdx]; | |
| 828 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_0][iMBXY], iIIdx, LIST_0); | |
| 829 | + | |
| 830 | + iRefIndex2 = pCurDqLayer->pRefIndex[LIST_1][iMBXY][iIIdx]; | |
| 831 | + GetRefPic (&pTempMCRefMem, pCtx, pCurDqLayer->pRefIndex[LIST_1][iMBXY], iIIdx, LIST_1); | |
| 832 | + } else { | |
| 833 | + int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 834 | + iRefIndex1 = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 835 | + GetRefPic (&pMCRefMem, pCtx, pCurDqLayer->pRefIndex[listIdx][iMBXY], iIIdx, listIdx); | |
| 836 | + } | |
| 837 | + | |
| 838 | + if (IS_SUB_8x8 (iSubMBType)) { | |
| 839 | + if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { | |
| 840 | + iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0]; | |
| 841 | + iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1]; | |
| 842 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs); | |
| 843 | + | |
| 844 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0]; | |
| 845 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1]; | |
| 846 | + BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs); | |
| 847 | + | |
| 848 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 849 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 8); | |
| 850 | + } else { | |
| 851 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 8); | |
| 852 | + } | |
| 853 | + } else { | |
| 854 | + int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 855 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0]; | |
| 856 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1]; | |
| 857 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 8, iMVs); | |
| 858 | + if (bWeightedBipredIdcIs1) { | |
| 859 | + int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 860 | + WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 8, 8); | |
| 861 | + } | |
| 862 | + } | |
| 863 | + } else if (IS_SUB_8x4 (iSubMBType)) { | |
| 864 | + if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { //B_Bi_8x4 | |
| 865 | + iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0]; | |
| 866 | + iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1]; | |
| 867 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs); | |
| 868 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0]; | |
| 869 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1]; | |
| 870 | + BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs); | |
| 871 | + | |
| 872 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 873 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 4); | |
| 874 | + } else { | |
| 875 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 4); | |
| 876 | + } | |
| 877 | + | |
| 878 | + pMCRefMem.pDstY += (iDstLineLuma << 2); | |
| 879 | + pMCRefMem.pDstU += (iDstLineChroma << 1); | |
| 880 | + pMCRefMem.pDstV += (iDstLineChroma << 1); | |
| 881 | + iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 4][0]; | |
| 882 | + iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 4][1]; | |
| 883 | + BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs); | |
| 884 | + | |
| 885 | + pTempMCRefMem.pDstY += (iDstLineLuma << 2); | |
| 886 | + pTempMCRefMem.pDstU += (iDstLineChroma << 1); | |
| 887 | + pTempMCRefMem.pDstV += (iDstLineChroma << 1); | |
| 888 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 4][0]; | |
| 889 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 4][1]; | |
| 890 | + BaseMC (&pTempMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs); | |
| 891 | + | |
| 892 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 893 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 8, 4); | |
| 894 | + } else { | |
| 895 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 8, 4); | |
| 896 | + } | |
| 897 | + } else { //B_L0_8x4 B_L1_8x4 | |
| 898 | + int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 899 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0]; | |
| 900 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1]; | |
| 901 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 8, 4, iMVs); | |
| 902 | + pMCRefMem.pDstY += (iDstLineLuma << 2); | |
| 903 | + pMCRefMem.pDstU += (iDstLineChroma << 1); | |
| 904 | + pMCRefMem.pDstV += (iDstLineChroma << 1); | |
| 905 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 4][0]; | |
| 906 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 4][1]; | |
| 907 | + BaseMC (&pMCRefMem, iXOffset, iYOffset + 4, pMCFunc, 8, 4, iMVs); | |
| 908 | + if (bWeightedBipredIdcIs1) { | |
| 909 | + int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 910 | + WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 8, 4); | |
| 911 | + } | |
| 912 | + } | |
| 913 | + } else if (IS_SUB_4x8 (iSubMBType)) { | |
| 914 | + if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { //B_Bi_4x8 | |
| 915 | + iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][0]; | |
| 916 | + iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx][1]; | |
| 917 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 918 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][0]; | |
| 919 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx][1]; | |
| 920 | + BaseMC (&pTempMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 921 | + | |
| 922 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 923 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 8); | |
| 924 | + } else { | |
| 925 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 8); | |
| 926 | + } | |
| 927 | + | |
| 928 | + pMCRefMem.pDstY += 4; | |
| 929 | + pMCRefMem.pDstU += 2; | |
| 930 | + pMCRefMem.pDstV += 2; | |
| 931 | + iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 1][0]; | |
| 932 | + iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + 1][1]; | |
| 933 | + BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 934 | + | |
| 935 | + pTempMCRefMem.pDstY += 4; | |
| 936 | + pTempMCRefMem.pDstU += 2; | |
| 937 | + pTempMCRefMem.pDstV += 2; | |
| 938 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 1][0]; | |
| 939 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + 1][1]; | |
| 940 | + BaseMC (&pTempMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 941 | + | |
| 942 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 943 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 8); | |
| 944 | + } else { | |
| 945 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 8); | |
| 946 | + } | |
| 947 | + } else { //B_L0_4x8 B_L1_4x8 | |
| 948 | + int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 949 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][0]; | |
| 950 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx][1]; | |
| 951 | + BaseMC (&pMCRefMem, iXOffset, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 952 | + pMCRefMem.pDstY += 4; | |
| 953 | + pMCRefMem.pDstU += 2; | |
| 954 | + pMCRefMem.pDstV += 2; | |
| 955 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 1][0]; | |
| 956 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + 1][1]; | |
| 957 | + BaseMC (&pMCRefMem, iXOffset + 4, iYOffset, pMCFunc, 4, 8, iMVs); | |
| 958 | + if (bWeightedBipredIdcIs1) { | |
| 959 | + int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 960 | + WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 4, 8); | |
| 961 | + } | |
| 962 | + } | |
| 963 | + } else if (IS_SUB_4x4 (iSubMBType)) { | |
| 964 | + if (IS_TYPE_L0 (iSubMBType) && IS_TYPE_L1 (iSubMBType)) { | |
| 965 | + for (int32_t j = 0; j < 4; j++) { | |
| 966 | + int32_t iUVLineStride; | |
| 967 | + iJIdx = ((j >> 1) << 2) + (j & 1); | |
| 968 | + | |
| 969 | + iBlk4X = (j & 1) << 2; | |
| 970 | + iBlk4Y = (j >> 1) << 2; | |
| 971 | + | |
| 972 | + iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma; | |
| 973 | + pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma; | |
| 974 | + pMCRefMem.pDstU = pDstU + iUVLineStride; | |
| 975 | + pMCRefMem.pDstV = pDstV + iUVLineStride; | |
| 976 | + | |
| 977 | + iMVs[0] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + iJIdx][0]; | |
| 978 | + iMVs[1] = pCurDqLayer->pMv[LIST_0][iMBXY][iIIdx + iJIdx][1]; | |
| 979 | + BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs); | |
| 980 | + | |
| 981 | + pTempMCRefMem.pDstY = pDstY2 + iBlk8X + iBlk8Y * iDstLineLuma; | |
| 982 | + pTempMCRefMem.pDstU = pDstU2 + iUVLineStride; | |
| 983 | + pTempMCRefMem.pDstV = pDstV2 + iUVLineStride;; | |
| 984 | + | |
| 985 | + iMVs[0] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + iJIdx][0]; | |
| 986 | + iMVs[1] = pCurDqLayer->pMv[LIST_1][iMBXY][iIIdx + iJIdx][1]; | |
| 987 | + BaseMC (&pTempMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs); | |
| 988 | + | |
| 989 | + if (pCurDqLayer->bUseWeightedBiPredIdc) { | |
| 990 | + BiWeightPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, iRefIndex1, iRefIndex2, bWeightedBipredIdcIs1, 4, 4); | |
| 991 | + } else { | |
| 992 | + BiPrediction (pCurDqLayer, &pMCRefMem, &pTempMCRefMem, 4, 4); | |
| 993 | + } | |
| 994 | + } | |
| 995 | + } else { | |
| 996 | + int32_t listIdx = IS_TYPE_L0 (iSubMBType) ? LIST_0 : LIST_1; | |
| 997 | + int32_t iRefIndex = pCurDqLayer->pRefIndex[listIdx][iMBXY][iIIdx]; | |
| 998 | + for (int32_t j = 0; j < 4; j++) { | |
| 999 | + int32_t iUVLineStride; | |
| 1000 | + iJIdx = ((j >> 1) << 2) + (j & 1); | |
| 1001 | + | |
| 1002 | + iBlk4X = (j & 1) << 2; | |
| 1003 | + iBlk4Y = (j >> 1) << 2; | |
| 1004 | + | |
| 1005 | + iUVLineStride = (iBlk4X >> 1) + (iBlk4Y >> 1) * iDstLineChroma; | |
| 1006 | + pMCRefMem.pDstY = pDstY + iBlk4X + iBlk4Y * iDstLineLuma; | |
| 1007 | + pMCRefMem.pDstU = pDstU + iUVLineStride; | |
| 1008 | + pMCRefMem.pDstV = pDstV + iUVLineStride; | |
| 1009 | + | |
| 1010 | + iMVs[0] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + iJIdx][0]; | |
| 1011 | + iMVs[1] = pCurDqLayer->pMv[listIdx][iMBXY][iIIdx + iJIdx][1]; | |
| 1012 | + BaseMC (&pMCRefMem, iXOffset + iBlk4X, iYOffset + iBlk4Y, pMCFunc, 4, 4, iMVs); | |
| 1013 | + if (bWeightedBipredIdcIs1) { | |
| 1014 | + WeightPrediction (pCurDqLayer, &pMCRefMem, listIdx, iRefIndex, 4, 4); | |
| 1015 | + } | |
| 1016 | + } | |
| 1017 | + } | |
| 1018 | + } | |
| 1019 | + } | |
| 1020 | + } | |
| 1021 | +} | |
| 1022 | + | |
| 1023 | +int32_t RecChroma (int32_t iMBXY, PWelsDecoderContext pCtx, int16_t* pScoeffLevel, PDqLayer pDqLayer) { | |
| 1024 | + int32_t iChromaStride = pCtx->pCurDqLayer->pDec->iLinesize[1]; | |
| 1025 | + PIdctFourResAddPredFunc pIdctFourResAddPredFunc = pCtx->pIdctFourResAddPredFunc; | |
| 1026 | + | |
| 1027 | + uint8_t i = 0; | |
| 1028 | + uint8_t uiCbpC = pDqLayer->pCbp[iMBXY] >> 4; | |
| 1029 | + | |
| 1030 | + if (1 == uiCbpC || 2 == uiCbpC) { | |
| 1031 | + for (i = 0; i < 2; i++) { | |
| 1032 | + int16_t* pRS = pScoeffLevel + 256 + (i << 6); | |
| 1033 | + uint8_t* pPred = pDqLayer->pPred[i + 1]; | |
| 1034 | + const int8_t* pNzc = pDqLayer->pNzc[iMBXY] + 16 + 2 * i; | |
| 1035 | + | |
| 1036 | + /*1 chroma is divided 4 4x4_block to idct*/ | |
| 1037 | + pIdctFourResAddPredFunc (pPred, iChromaStride, pRS, pNzc); | |
| 1038 | + } | |
| 1039 | + } | |
| 1040 | + | |
| 1041 | + return ERR_NONE; | |
| 1042 | +} | |
| 1043 | + | |
| 1044 | +} // namespace WelsDec | |
| @@ -1,147 +1,147 @@ | ||
| 1 | −/*! | |
| 2 | − * \copy | |
| 3 | − * Copyright (c) 2009-2013, Cisco Systems | |
| 4 | − * All rights reserved. | |
| 5 | − * | |
| 6 | − * Redistribution and use in source and binary forms, with or without | |
| 7 | − * modification, are permitted provided that the following conditions | |
| 8 | − * are met: | |
| 9 | − * | |
| 10 | − * * Redistributions of source code must retain the above copyright | |
| 11 | − * notice, this list of conditions and the following disclaimer. | |
| 12 | − * | |
| 13 | − * * Redistributions in binary form must reproduce the above copyright | |
| 14 | − * notice, this list of conditions and the following disclaimer in | |
| 15 | − * the documentation and/or other materials provided with the | |
| 16 | − * distribution. | |
| 17 | − * | |
| 18 | − * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 | − * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 | − * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 21 | − * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 22 | − * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 23 | − * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 24 | − * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 | − * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 26 | − * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 | − * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
| 28 | − * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | − * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | − * | |
| 31 | − * | |
| 32 | − * WelsDecoderExt.h | |
| 33 | − * | |
| 34 | − * Abstract | |
| 35 | − * Cisco OpenH264 decoder extension utilization interface | |
| 36 | − * | |
| 37 | − * History | |
| 38 | − * 3/12/2009 Created | |
| 39 | − * | |
| 40 | − * | |
| 41 | − *************************************************************************/ | |
| 42 | −#if !defined(WELS_PLUS_WELSDECODEREXT_H) | |
| 43 | −#define WELS_PLUS_WELSDECODEREXT_H | |
| 44 | − | |
| 45 | −#include "codec_api.h" | |
| 46 | −#include "codec_app_def.h" | |
| 47 | −#include "decoder_context.h" | |
| 48 | −#include "welsCodecTrace.h" | |
| 49 | −#include "cpu.h" | |
| 50 | − | |
| 51 | −class ISVCDecoder; | |
| 52 | − | |
| 53 | −namespace WelsDec { | |
| 54 | − | |
| 55 | −//#define OUTPUT_BIT_STREAM ////for test to output bitstream | |
| 56 | − | |
| 57 | −class CWelsDecoder : public ISVCDecoder { | |
| 58 | − public: | |
| 59 | − CWelsDecoder (void); | |
| 60 | − virtual ~CWelsDecoder(); | |
| 61 | − | |
| 62 | − virtual long EXTAPI Initialize (const SDecodingParam* pParam); | |
| 63 | − virtual long EXTAPI Uninitialize(); | |
| 64 | − | |
| 65 | − /*************************************************************************** | |
| 66 | − * Description: | |
| 67 | − * Decompress one frame, and output I420 or RGB24(in the future) decoded stream and its length. | |
| 68 | − * Input parameters: | |
| 69 | − * Parameter TYPE Description | |
| 70 | − * pSrc unsigned char* the h264 stream to decode | |
| 71 | − * srcLength int the length of h264 steam | |
| 72 | − * pDst unsigned char* buffer pointer of decoded data | |
| 73 | − * pDstInfo SBufferInfo& information provided to API including width, height, SW/HW option, etc | |
| 74 | − * | |
| 75 | − * return: if decode frame success return 0, otherwise corresponding error returned. | |
| 76 | − ***************************************************************************/ | |
| 77 | − virtual DECODING_STATE EXTAPI DecodeFrame (const unsigned char* kpSrc, | |
| 78 | − const int kiSrcLen, | |
| 79 | − unsigned char** ppDst, | |
| 80 | − int* pStride, | |
| 81 | − int& iWidth, | |
| 82 | − int& iHeight); | |
| 83 | − | |
| 84 | − virtual DECODING_STATE EXTAPI DecodeFrameNoDelay (const unsigned char* kpSrc, | |
| 85 | − const int kiSrcLen, | |
| 86 | − unsigned char** ppDst, | |
| 87 | − SBufferInfo* pDstInfo); | |
| 88 | − | |
| 89 | − virtual DECODING_STATE EXTAPI DecodeFrame2 (const unsigned char* kpSrc, | |
| 90 | − const int kiSrcLen, | |
| 91 | − unsigned char** ppDst, | |
| 92 | − SBufferInfo* pDstInfo); | |
| 93 | − | |
| 94 | − virtual DECODING_STATE EXTAPI FlushFrame (unsigned char** ppDst, | |
| 95 | − SBufferInfo* pDstInfo); | |
| 96 | − | |
| 97 | − virtual DECODING_STATE EXTAPI DecodeParser (const unsigned char* kpSrc, | |
| 98 | − const int kiSrcLen, | |
| 99 | − SParserBsInfo* pDstInfo); | |
| 100 | − virtual DECODING_STATE EXTAPI DecodeFrameEx (const unsigned char* kpSrc, | |
| 101 | − const int kiSrcLen, | |
| 102 | − unsigned char* pDst, | |
| 103 | − int iDstStride, | |
| 104 | − int& iDstLen, | |
| 105 | − int& iWidth, | |
| 106 | − int& iHeight, | |
| 107 | − int& color_format); | |
| 108 | − | |
| 109 | − virtual long EXTAPI SetOption (DECODER_OPTION eOptID, void* pOption); | |
| 110 | − virtual long EXTAPI GetOption (DECODER_OPTION eOptID, void* pOption); | |
| 111 | − | |
| 112 | − typedef struct tagPictInfo { | |
| 113 | − SBufferInfo sBufferInfo; | |
| 114 | − int32_t iPOC; | |
| 115 | − int32_t iFrameNum; | |
| 116 | − bool bLastGOP; | |
| 117 | − unsigned char* pData[3]; | |
| 118 | − } SPictInfo, *PPictInfo; | |
| 119 | − | |
| 120 | − private: | |
| 121 | − PWelsDecoderContext m_pDecContext; | |
| 122 | − welsCodecTrace* m_pWelsTrace; | |
| 123 | − SPictInfo m_sPictInfoList[16]; | |
| 124 | − int32_t m_iPictInfoIndex; | |
| 125 | − int32_t m_iMinPOC; | |
| 126 | − int32_t m_iNumOfPicts; | |
| 127 | − int32_t m_iLastGOPRemainPicts; | |
| 128 | − int32_t m_LastWrittenPOC; | |
| 129 | − int32_t m_iLargestBufferedPicIndex; | |
| 130 | − | |
| 131 | − int32_t InitDecoder (const SDecodingParam* pParam); | |
| 132 | − void UninitDecoder (void); | |
| 133 | − int32_t ResetDecoder(); | |
| 134 | − | |
| 135 | − void OutputStatisticsLog (SDecoderStatistics& sDecoderStatistics); | |
| 136 | − DECODING_STATE ReorderPicturesInDisplay (unsigned char** ppDst, SBufferInfo* pDstInfo); | |
| 137 | − | |
| 138 | −#ifdef OUTPUT_BIT_STREAM | |
| 139 | − WelsFileHandle* m_pFBS; | |
| 140 | − WelsFileHandle* m_pFBSSize; | |
| 141 | −#endif//OUTPUT_BIT_STREAM | |
| 142 | − | |
| 143 | −}; | |
| 144 | − | |
| 145 | −} // namespace WelsDec | |
| 146 | − | |
| 147 | −#endif // !defined(WELS_PLUS_WELSDECODEREXT_H) | |
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 2009-2013, Cisco Systems | |
| 4 | + * All rights reserved. | |
| 5 | + * | |
| 6 | + * Redistribution and use in source and binary forms, with or without | |
| 7 | + * modification, are permitted provided that the following conditions | |
| 8 | + * are met: | |
| 9 | + * | |
| 10 | + * * Redistributions of source code must retain the above copyright | |
| 11 | + * notice, this list of conditions and the following disclaimer. | |
| 12 | + * | |
| 13 | + * * Redistributions in binary form must reproduce the above copyright | |
| 14 | + * notice, this list of conditions and the following disclaimer in | |
| 15 | + * the documentation and/or other materials provided with the | |
| 16 | + * distribution. | |
| 17 | + * | |
| 18 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 21 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 22 | + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 23 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 26 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
| 28 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | + * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | + * | |
| 31 | + * | |
| 32 | + * WelsDecoderExt.h | |
| 33 | + * | |
| 34 | + * Abstract | |
| 35 | + * Cisco OpenH264 decoder extension utilization interface | |
| 36 | + * | |
| 37 | + * History | |
| 38 | + * 3/12/2009 Created | |
| 39 | + * | |
| 40 | + * | |
| 41 | + *************************************************************************/ | |
| 42 | +#if !defined(WELS_PLUS_WELSDECODEREXT_H) | |
| 43 | +#define WELS_PLUS_WELSDECODEREXT_H | |
| 44 | + | |
| 45 | +#include "codec_api.h" | |
| 46 | +#include "codec_app_def.h" | |
| 47 | +#include "decoder_context.h" | |
| 48 | +#include "welsCodecTrace.h" | |
| 49 | +#include "cpu.h" | |
| 50 | + | |
| 51 | +class ISVCDecoder; | |
| 52 | + | |
| 53 | +namespace WelsDec { | |
| 54 | + | |
| 55 | +//#define OUTPUT_BIT_STREAM ////for test to output bitstream | |
| 56 | + | |
| 57 | +class CWelsDecoder : public ISVCDecoder { | |
| 58 | + public: | |
| 59 | + CWelsDecoder (void); | |
| 60 | + virtual ~CWelsDecoder(); | |
| 61 | + | |
| 62 | + virtual long EXTAPI Initialize (const SDecodingParam* pParam); | |
| 63 | + virtual long EXTAPI Uninitialize(); | |
| 64 | + | |
| 65 | + /*************************************************************************** | |
| 66 | + * Description: | |
| 67 | + * Decompress one frame, and output I420 or RGB24(in the future) decoded stream and its length. | |
| 68 | + * Input parameters: | |
| 69 | + * Parameter TYPE Description | |
| 70 | + * pSrc unsigned char* the h264 stream to decode | |
| 71 | + * srcLength int the length of h264 steam | |
| 72 | + * pDst unsigned char* buffer pointer of decoded data | |
| 73 | + * pDstInfo SBufferInfo& information provided to API including width, height, SW/HW option, etc | |
| 74 | + * | |
| 75 | + * return: if decode frame success return 0, otherwise corresponding error returned. | |
| 76 | + ***************************************************************************/ | |
| 77 | + virtual DECODING_STATE EXTAPI DecodeFrame (const unsigned char* kpSrc, | |
| 78 | + const int kiSrcLen, | |
| 79 | + unsigned char** ppDst, | |
| 80 | + int* pStride, | |
| 81 | + int& iWidth, | |
| 82 | + int& iHeight); | |
| 83 | + | |
| 84 | + virtual DECODING_STATE EXTAPI DecodeFrameNoDelay (const unsigned char* kpSrc, | |
| 85 | + const int kiSrcLen, | |
| 86 | + unsigned char** ppDst, | |
| 87 | + SBufferInfo* pDstInfo); | |
| 88 | + | |
| 89 | + virtual DECODING_STATE EXTAPI DecodeFrame2 (const unsigned char* kpSrc, | |
| 90 | + const int kiSrcLen, | |
| 91 | + unsigned char** ppDst, | |
| 92 | + SBufferInfo* pDstInfo); | |
| 93 | + | |
| 94 | + virtual DECODING_STATE EXTAPI FlushFrame (unsigned char** ppDst, | |
| 95 | + SBufferInfo* pDstInfo); | |
| 96 | + | |
| 97 | + virtual DECODING_STATE EXTAPI DecodeParser (const unsigned char* kpSrc, | |
| 98 | + const int kiSrcLen, | |
| 99 | + SParserBsInfo* pDstInfo); | |
| 100 | + virtual DECODING_STATE EXTAPI DecodeFrameEx (const unsigned char* kpSrc, | |
| 101 | + const int kiSrcLen, | |
| 102 | + unsigned char* pDst, | |
| 103 | + int iDstStride, | |
| 104 | + int& iDstLen, | |
| 105 | + int& iWidth, | |
| 106 | + int& iHeight, | |
| 107 | + int& color_format); | |
| 108 | + | |
| 109 | + virtual long EXTAPI SetOption (DECODER_OPTION eOptID, void* pOption); | |
| 110 | + virtual long EXTAPI GetOption (DECODER_OPTION eOptID, void* pOption); | |
| 111 | + | |
| 112 | + typedef struct tagPictInfo { | |
| 113 | + SBufferInfo sBufferInfo; | |
| 114 | + int32_t iPOC; | |
| 115 | + int32_t iFrameNum; | |
| 116 | + bool bLastGOP; | |
| 117 | + unsigned char* pData[3]; | |
| 118 | + } SPictInfo, *PPictInfo; | |
| 119 | + | |
| 120 | + private: | |
| 121 | + PWelsDecoderContext m_pDecContext; | |
| 122 | + welsCodecTrace* m_pWelsTrace; | |
| 123 | + SPictInfo m_sPictInfoList[16]; | |
| 124 | + int32_t m_iPictInfoIndex; | |
| 125 | + int32_t m_iMinPOC; | |
| 126 | + int32_t m_iNumOfPicts; | |
| 127 | + int32_t m_iLastGOPRemainPicts; | |
| 128 | + int32_t m_LastWrittenPOC; | |
| 129 | + int32_t m_iLargestBufferedPicIndex; | |
| 130 | + | |
| 131 | + int32_t InitDecoder (const SDecodingParam* pParam); | |
| 132 | + void UninitDecoder (void); | |
| 133 | + int32_t ResetDecoder(); | |
| 134 | + | |
| 135 | + void OutputStatisticsLog (SDecoderStatistics& sDecoderStatistics); | |
| 136 | + DECODING_STATE ReorderPicturesInDisplay (unsigned char** ppDst, SBufferInfo* pDstInfo); | |
| 137 | + | |
| 138 | +#ifdef OUTPUT_BIT_STREAM | |
| 139 | + WelsFileHandle* m_pFBS; | |
| 140 | + WelsFileHandle* m_pFBSSize; | |
| 141 | +#endif//OUTPUT_BIT_STREAM | |
| 142 | + | |
| 143 | +}; | |
| 144 | + | |
| 145 | +} // namespace WelsDec | |
| 146 | + | |
| 147 | +#endif // !defined(WELS_PLUS_WELSDECODEREXT_H) | |
| @@ -1,1016 +1,1016 @@ | ||
| 1 | −/*! | |
| 2 | − * \copy | |
| 3 | − * Copyright (c) 2009-2013, Cisco Systems | |
| 4 | − * All rights reserved. | |
| 5 | − * | |
| 6 | − * Redistribution and use in source and binary forms, with or without | |
| 7 | − * modification, are permitted provided that the following conditions | |
| 8 | − * are met: | |
| 9 | − * | |
| 10 | − * * Redistributions of source code must retain the above copyright | |
| 11 | − * notice, this list of conditions and the following disclaimer. | |
| 12 | − * | |
| 13 | − * * Redistributions in binary form must reproduce the above copyright | |
| 14 | − * notice, this list of conditions and the following disclaimer in | |
| 15 | − * the documentation and/or other materials provided with the | |
| 16 | − * distribution. | |
| 17 | − * | |
| 18 | − * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 | − * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 | − * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 21 | − * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 22 | − * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 23 | − * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 24 | − * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 | − * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 26 | − * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 | − * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
| 28 | − * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | − * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | − * | |
| 31 | − * | |
| 32 | − * welsDecoderExt.cpp | |
| 33 | − * | |
| 34 | − * Abstract | |
| 35 | − * Cisco OpenH264 decoder extension utilization | |
| 36 | − * | |
| 37 | − * History | |
| 38 | − * 3/12/2009 Created | |
| 39 | − * | |
| 40 | − * | |
| 41 | − ************************************************************************/ | |
| 42 | −//#include <assert.h> | |
| 43 | −#include "welsDecoderExt.h" | |
| 44 | −#include "welsCodecTrace.h" | |
| 45 | −#include "codec_def.h" | |
| 46 | −#include "typedefs.h" | |
| 47 | −#include "memory_align.h" | |
| 48 | −#include "utils.h" | |
| 49 | −#include "version.h" | |
| 50 | − | |
| 51 | −//#include "macros.h" | |
| 52 | −#include "decoder.h" | |
| 53 | −#include "decoder_core.h" | |
| 54 | −#include "error_concealment.h" | |
| 55 | − | |
| 56 | −#include "measure_time.h" | |
| 57 | −extern "C" { | |
| 58 | −#include "decoder_core.h" | |
| 59 | −#include "manage_dec_ref.h" | |
| 60 | −} | |
| 61 | −#include "error_code.h" | |
| 62 | −#include "crt_util_safe_x.h" // Safe CRT routines like util for cross platforms | |
| 63 | −#include <time.h> | |
| 64 | −#if defined(_WIN32) /*&& defined(_DEBUG)*/ | |
| 65 | − | |
| 66 | −#include <windows.h> | |
| 67 | −#include <stdio.h> | |
| 68 | −#include <stdarg.h> | |
| 69 | −#include <sys/types.h> | |
| 70 | −#else | |
| 71 | −#include <sys/time.h> | |
| 72 | −#endif | |
| 73 | − | |
| 74 | −#define _PICTURE_REORDERING_ 1 | |
| 75 | − | |
| 76 | −static int32_t sIMinInt32 = -0x7FFFFFFF; | |
| 77 | − | |
| 78 | −namespace WelsDec { | |
| 79 | − | |
| 80 | −////////////////////////////////////////////////////////////////////// | |
| 81 | −// Construction/Destruction | |
| 82 | −////////////////////////////////////////////////////////////////////// | |
| 83 | − | |
| 84 | −/*************************************************************************** | |
| 85 | −* Description: | |
| 86 | −* class CWelsDecoder constructor function, do initialization and | |
| 87 | −* alloc memory required | |
| 88 | −* | |
| 89 | −* Input parameters: none | |
| 90 | −* | |
| 91 | −* return: none | |
| 92 | −***************************************************************************/ | |
| 93 | −CWelsDecoder::CWelsDecoder (void) | |
| 94 | − : m_pDecContext (NULL), | |
| 95 | − m_pWelsTrace (NULL), | |
| 96 | − m_iPictInfoIndex (0), | |
| 97 | − m_iMinPOC (sIMinInt32), | |
| 98 | − m_iNumOfPicts (0), | |
| 99 | − m_iLastGOPRemainPicts (0), | |
| 100 | − m_LastWrittenPOC (sIMinInt32), | |
| 101 | − m_iLargestBufferedPicIndex (0) { | |
| 102 | −#ifdef OUTPUT_BIT_STREAM | |
| 103 | − char chFileName[1024] = { 0 }; //for .264 | |
| 104 | − int iBufUsed = 0; | |
| 105 | − int iBufLeft = 1023; | |
| 106 | − int iCurUsed; | |
| 107 | − | |
| 108 | − char chFileNameSize[1024] = { 0 }; //for .len | |
| 109 | − int iBufUsedSize = 0; | |
| 110 | − int iBufLeftSize = 1023; | |
| 111 | − int iCurUsedSize; | |
| 112 | −#endif//OUTPUT_BIT_STREAM | |
| 113 | − | |
| 114 | − | |
| 115 | − m_pWelsTrace = new welsCodecTrace(); | |
| 116 | − if (m_pWelsTrace != NULL) { | |
| 117 | − m_pWelsTrace->SetCodecInstance (this); | |
| 118 | − m_pWelsTrace->SetTraceLevel (WELS_LOG_ERROR); | |
| 119 | − | |
| 120 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::CWelsDecoder() entry"); | |
| 121 | − } | |
| 122 | − | |
| 123 | − for (int32_t i = 0; i < 16; ++i) { | |
| 124 | − m_sPictInfoList[i].bLastGOP = false; | |
| 125 | − m_sPictInfoList[i].iPOC = sIMinInt32; | |
| 126 | − } | |
| 127 | − | |
| 128 | −#ifdef OUTPUT_BIT_STREAM | |
| 129 | − SWelsTime sCurTime; | |
| 130 | − | |
| 131 | − WelsGetTimeOfDay (&sCurTime); | |
| 132 | − | |
| 133 | − iCurUsed = WelsSnprintf (chFileName, iBufLeft, "bs_0x%p_", (void*)this); | |
| 134 | − iCurUsedSize = WelsSnprintf (chFileNameSize, iBufLeftSize, "size_0x%p_", (void*)this); | |
| 135 | − | |
| 136 | − iBufUsed += iCurUsed; | |
| 137 | − iBufLeft -= iCurUsed; | |
| 138 | − if (iBufLeft > 0) { | |
| 139 | − iCurUsed = WelsStrftime (&chFileName[iBufUsed], iBufLeft, "%y%m%d%H%M%S", &sCurTime); | |
| 140 | − iBufUsed += iCurUsed; | |
| 141 | − iBufLeft -= iCurUsed; | |
| 142 | − } | |
| 143 | − | |
| 144 | − iBufUsedSize += iCurUsedSize; | |
| 145 | − iBufLeftSize -= iCurUsedSize; | |
| 146 | − if (iBufLeftSize > 0) { | |
| 147 | − iCurUsedSize = WelsStrftime (&chFileNameSize[iBufUsedSize], iBufLeftSize, "%y%m%d%H%M%S", &sCurTime); | |
| 148 | − iBufUsedSize += iCurUsedSize; | |
| 149 | − iBufLeftSize -= iCurUsedSize; | |
| 150 | − } | |
| 151 | − | |
| 152 | − if (iBufLeft > 0) { | |
| 153 | − iCurUsed = WelsSnprintf (&chFileName[iBufUsed], iBufLeft, ".%03.3u.264", WelsGetMillisecond (&sCurTime)); | |
| 154 | − iBufUsed += iCurUsed; | |
| 155 | − iBufLeft -= iCurUsed; | |
| 156 | − } | |
| 157 | − | |
| 158 | − if (iBufLeftSize > 0) { | |
| 159 | − iCurUsedSize = WelsSnprintf (&chFileNameSize[iBufUsedSize], iBufLeftSize, ".%03.3u.len", | |
| 160 | − WelsGetMillisecond (&sCurTime)); | |
| 161 | − iBufUsedSize += iCurUsedSize; | |
| 162 | − iBufLeftSize -= iCurUsedSize; | |
| 163 | − } | |
| 164 | − | |
| 165 | − | |
| 166 | − m_pFBS = WelsFopen (chFileName, "wb"); | |
| 167 | − m_pFBSSize = WelsFopen (chFileNameSize, "wb"); | |
| 168 | −#endif//OUTPUT_BIT_STREAM | |
| 169 | −} | |
| 170 | − | |
| 171 | −/*************************************************************************** | |
| 172 | −* Description: | |
| 173 | −* class CWelsDecoder destructor function, destroy allocced memory | |
| 174 | −* | |
| 175 | −* Input parameters: none | |
| 176 | −* | |
| 177 | −* return: none | |
| 178 | −***************************************************************************/ | |
| 179 | −CWelsDecoder::~CWelsDecoder() { | |
| 180 | − if (m_pWelsTrace != NULL) { | |
| 181 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::~CWelsDecoder()"); | |
| 182 | − } | |
| 183 | − | |
| 184 | − UninitDecoder(); | |
| 185 | − | |
| 186 | −#ifdef OUTPUT_BIT_STREAM | |
| 187 | − if (m_pFBS) { | |
| 188 | − WelsFclose (m_pFBS); | |
| 189 | − m_pFBS = NULL; | |
| 190 | − } | |
| 191 | − if (m_pFBSSize) { | |
| 192 | − WelsFclose (m_pFBSSize); | |
| 193 | − m_pFBSSize = NULL; | |
| 194 | − } | |
| 195 | −#endif//OUTPUT_BIT_STREAM | |
| 196 | − | |
| 197 | − if (m_pWelsTrace != NULL) { | |
| 198 | − delete m_pWelsTrace; | |
| 199 | − m_pWelsTrace = NULL; | |
| 200 | − } | |
| 201 | −} | |
| 202 | − | |
| 203 | −long CWelsDecoder::Initialize (const SDecodingParam* pParam) { | |
| 204 | − int iRet = ERR_NONE; | |
| 205 | − if (m_pWelsTrace == NULL) { | |
| 206 | − return cmMallocMemeError; | |
| 207 | − } | |
| 208 | − | |
| 209 | − if (pParam == NULL) { | |
| 210 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsDecoder::Initialize(), invalid input argument."); | |
| 211 | − return cmInitParaError; | |
| 212 | − } | |
| 213 | − | |
| 214 | − // H.264 decoder initialization,including memory allocation,then open it ready to decode | |
| 215 | − iRet = InitDecoder (pParam); | |
| 216 | − if (iRet) | |
| 217 | − return iRet; | |
| 218 | − | |
| 219 | − return cmResultSuccess; | |
| 220 | −} | |
| 221 | − | |
| 222 | −long CWelsDecoder::Uninitialize() { | |
| 223 | − UninitDecoder(); | |
| 224 | − | |
| 225 | − return ERR_NONE; | |
| 226 | −} | |
| 227 | − | |
| 228 | −void CWelsDecoder::UninitDecoder (void) { | |
| 229 | − if (NULL == m_pDecContext) | |
| 230 | − return; | |
| 231 | − | |
| 232 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::UninitDecoder(), openh264 codec version = %s.", | |
| 233 | − VERSION_NUMBER); | |
| 234 | − | |
| 235 | − WelsEndDecoder (m_pDecContext); | |
| 236 | − | |
| 237 | − if (m_pDecContext->pMemAlign != NULL) { | |
| 238 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 239 | − "CWelsDecoder::UninitDecoder(), verify memory usage (%d bytes) after free..", | |
| 240 | − m_pDecContext->pMemAlign->WelsGetMemoryUsage()); | |
| 241 | − delete m_pDecContext->pMemAlign; | |
| 242 | − m_pDecContext->pMemAlign = NULL; | |
| 243 | − } | |
| 244 | − | |
| 245 | − if (NULL != m_pDecContext) { | |
| 246 | − WelsFree (m_pDecContext, "m_pDecContext"); | |
| 247 | − | |
| 248 | − m_pDecContext = NULL; | |
| 249 | − } | |
| 250 | −} | |
| 251 | − | |
| 252 | −// the return value of this function is not suitable, it need report failure info to upper layer. | |
| 253 | −int32_t CWelsDecoder::InitDecoder (const SDecodingParam* pParam) { | |
| 254 | − | |
| 255 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 256 | − "CWelsDecoder::init_decoder(), openh264 codec version = %s, ParseOnly = %d", | |
| 257 | − VERSION_NUMBER, (int32_t)pParam->bParseOnly); | |
| 258 | − | |
| 259 | − //reset decoder context | |
| 260 | − if (m_pDecContext) //free | |
| 261 | − UninitDecoder(); | |
| 262 | − m_pDecContext = (PWelsDecoderContext)WelsMallocz (sizeof (SWelsDecoderContext), "m_pDecContext"); | |
| 263 | − if (NULL == m_pDecContext) | |
| 264 | − return cmMallocMemeError; | |
| 265 | − int32_t iCacheLineSize = 16; // on chip cache line size in byte | |
| 266 | − m_pDecContext->pMemAlign = new CMemoryAlign (iCacheLineSize); | |
| 267 | − WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, (NULL == m_pDecContext->pMemAlign), UninitDecoder()) | |
| 268 | − | |
| 269 | − //fill in default value into context | |
| 270 | − WelsDecoderDefaults (m_pDecContext, &m_pWelsTrace->m_sLogCtx); | |
| 271 | − | |
| 272 | − //check param and update decoder context | |
| 273 | − m_pDecContext->pParam = (SDecodingParam*)m_pDecContext->pMemAlign->WelsMallocz (sizeof (SDecodingParam), | |
| 274 | − "SDecodingParam"); | |
| 275 | − WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, (NULL == m_pDecContext->pParam), UninitDecoder()); | |
| 276 | − int32_t iRet = DecoderConfigParam (m_pDecContext, pParam); | |
| 277 | − WELS_VERIFY_RETURN_IFNEQ (iRet, cmResultSuccess); | |
| 278 | − | |
| 279 | − //init decoder | |
| 280 | − WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, WelsInitDecoder (m_pDecContext, &m_pWelsTrace->m_sLogCtx), | |
| 281 | − UninitDecoder()) | |
| 282 | − | |
| 283 | − return cmResultSuccess; | |
| 284 | −} | |
| 285 | − | |
| 286 | −int32_t CWelsDecoder::ResetDecoder() { | |
| 287 | − // TBC: need to be modified when context and trace point are null | |
| 288 | − if (m_pDecContext != NULL && m_pWelsTrace != NULL) { | |
| 289 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "ResetDecoder(), context error code is %d", | |
| 290 | − m_pDecContext->iErrorCode); | |
| 291 | − SDecodingParam sPrevParam; | |
| 292 | − memcpy (&sPrevParam, m_pDecContext->pParam, sizeof (SDecodingParam)); | |
| 293 | − | |
| 294 | − WELS_VERIFY_RETURN_PROC_IF (cmInitParaError, InitDecoder (&sPrevParam), UninitDecoder()); | |
| 295 | − } else if (m_pWelsTrace != NULL) { | |
| 296 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "ResetDecoder() failed as decoder context null"); | |
| 297 | − } | |
| 298 | − return ERR_INFO_UNINIT; | |
| 299 | −} | |
| 300 | − | |
| 301 | −/* | |
| 302 | − * Set Option | |
| 303 | − */ | |
| 304 | −long CWelsDecoder::SetOption (DECODER_OPTION eOptID, void* pOption) { | |
| 305 | − int iVal = 0; | |
| 306 | − | |
| 307 | − if (m_pDecContext == NULL && eOptID != DECODER_OPTION_TRACE_LEVEL && | |
| 308 | − eOptID != DECODER_OPTION_TRACE_CALLBACK && eOptID != DECODER_OPTION_TRACE_CALLBACK_CONTEXT) | |
| 309 | − return dsInitialOptExpected; | |
| 310 | − if (eOptID == DECODER_OPTION_END_OF_STREAM) { // Indicate bit-stream of the final frame to be decoded | |
| 311 | − if (pOption == NULL) | |
| 312 | − return cmInitParaError; | |
| 313 | − | |
| 314 | − iVal = * ((int*)pOption); // boolean value for whether enabled End Of Stream flag | |
| 315 | − | |
| 316 | − m_pDecContext->bEndOfStreamFlag = iVal ? true : false; | |
| 317 | − | |
| 318 | − return cmResultSuccess; | |
| 319 | − } else if (eOptID == DECODER_OPTION_ERROR_CON_IDC) { // Indicate error concealment status | |
| 320 | − if (pOption == NULL) | |
| 321 | − return cmInitParaError; | |
| 322 | − | |
| 323 | − 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); | |
| 325 | − if ((m_pDecContext->pParam->bParseOnly) && (iVal != (int32_t)ERROR_CON_DISABLE)) { | |
| 326 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 327 | − "CWelsDecoder::SetOption for ERROR_CON_IDC = %d not allowd for parse only!.", iVal); | |
| 328 | − return cmInitParaError; | |
| 329 | − } | |
| 330 | − | |
| 331 | − m_pDecContext->pParam->eEcActiveIdc = (ERROR_CON_IDC)iVal; | |
| 332 | − InitErrorCon (m_pDecContext); | |
| 333 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 334 | − "CWelsDecoder::SetOption for ERROR_CON_IDC = %d.", iVal); | |
| 335 | − | |
| 336 | − return cmResultSuccess; | |
| 337 | − } else if (eOptID == DECODER_OPTION_TRACE_LEVEL) { | |
| 338 | − if (m_pWelsTrace) { | |
| 339 | − uint32_t level = * ((uint32_t*)pOption); | |
| 340 | − m_pWelsTrace->SetTraceLevel (level); | |
| 341 | − } | |
| 342 | − return cmResultSuccess; | |
| 343 | − } else if (eOptID == DECODER_OPTION_TRACE_CALLBACK) { | |
| 344 | − if (m_pWelsTrace) { | |
| 345 | − WelsTraceCallback callback = * ((WelsTraceCallback*)pOption); | |
| 346 | − m_pWelsTrace->SetTraceCallback (callback); | |
| 347 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 348 | − "CWelsDecoder::SetOption():DECODER_OPTION_TRACE_CALLBACK callback = %p.", | |
| 349 | − callback); | |
| 350 | − } | |
| 351 | − return cmResultSuccess; | |
| 352 | − } else if (eOptID == DECODER_OPTION_TRACE_CALLBACK_CONTEXT) { | |
| 353 | − if (m_pWelsTrace) { | |
| 354 | − void* ctx = * ((void**)pOption); | |
| 355 | − m_pWelsTrace->SetTraceCallbackContext (ctx); | |
| 356 | − } | |
| 357 | − return cmResultSuccess; | |
| 358 | − } else if (eOptID == DECODER_OPTION_GET_STATISTICS) { | |
| 359 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING, | |
| 360 | − "CWelsDecoder::SetOption():DECODER_OPTION_GET_STATISTICS: this option is get-only!"); | |
| 361 | − return cmInitParaError; | |
| 362 | − } else if (eOptID == DECODER_OPTION_STATISTICS_LOG_INTERVAL) { | |
| 363 | − if (pOption) { | |
| 364 | − m_pDecContext->sDecoderStatistics.iStatisticsLogInterval = (* ((unsigned int*)pOption)); | |
| 365 | − return cmResultSuccess; | |
| 366 | − } | |
| 367 | − } else if (eOptID == DECODER_OPTION_GET_SAR_INFO) { | |
| 368 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING, | |
| 369 | − "CWelsDecoder::SetOption():DECODER_OPTION_GET_SAR_INFO: this option is get-only!"); | |
| 370 | − return cmInitParaError; | |
| 371 | − } | |
| 372 | − return cmInitParaError; | |
| 373 | −} | |
| 374 | − | |
| 375 | −/* | |
| 376 | − * Get Option | |
| 377 | − */ | |
| 378 | −long CWelsDecoder::GetOption (DECODER_OPTION eOptID, void* pOption) { | |
| 379 | − int iVal = 0; | |
| 380 | − | |
| 381 | − if (m_pDecContext == NULL) | |
| 382 | − return cmInitExpected; | |
| 383 | − | |
| 384 | − if (pOption == NULL) | |
| 385 | − return cmInitParaError; | |
| 386 | − | |
| 387 | − if (DECODER_OPTION_END_OF_STREAM == eOptID) { | |
| 388 | − iVal = m_pDecContext->bEndOfStreamFlag; | |
| 389 | − * ((int*)pOption) = iVal; | |
| 390 | − return cmResultSuccess; | |
| 391 | − } | |
| 392 | −#ifdef LONG_TERM_REF | |
| 393 | − else if (DECODER_OPTION_IDR_PIC_ID == eOptID) { | |
| 394 | − iVal = m_pDecContext->uiCurIdrPicId; | |
| 395 | − * ((int*)pOption) = iVal; | |
| 396 | − return cmResultSuccess; | |
| 397 | − } else if (DECODER_OPTION_FRAME_NUM == eOptID) { | |
| 398 | − iVal = m_pDecContext->iFrameNum; | |
| 399 | − * ((int*)pOption) = iVal; | |
| 400 | − return cmResultSuccess; | |
| 401 | − } else if (DECODER_OPTION_LTR_MARKING_FLAG == eOptID) { | |
| 402 | − iVal = m_pDecContext->bCurAuContainLtrMarkSeFlag; | |
| 403 | − * ((int*)pOption) = iVal; | |
| 404 | − return cmResultSuccess; | |
| 405 | − } else if (DECODER_OPTION_LTR_MARKED_FRAME_NUM == eOptID) { | |
| 406 | − iVal = m_pDecContext->iFrameNumOfAuMarkedLtr; | |
| 407 | − * ((int*)pOption) = iVal; | |
| 408 | − return cmResultSuccess; | |
| 409 | − } | |
| 410 | −#endif | |
| 411 | − else if (DECODER_OPTION_VCL_NAL == eOptID) { //feedback whether or not have VCL NAL in current AU | |
| 412 | − iVal = m_pDecContext->iFeedbackVclNalInAu; | |
| 413 | − * ((int*)pOption) = iVal; | |
| 414 | − return cmResultSuccess; | |
| 415 | − } else if (DECODER_OPTION_TEMPORAL_ID == eOptID) { //if have VCL NAL in current AU, then feedback the temporal ID | |
| 416 | − iVal = m_pDecContext->iFeedbackTidInAu; | |
| 417 | − * ((int*)pOption) = iVal; | |
| 418 | − return cmResultSuccess; | |
| 419 | − } else if (DECODER_OPTION_IS_REF_PIC == eOptID) { | |
| 420 | − iVal = m_pDecContext->iFeedbackNalRefIdc; | |
| 421 | − if (iVal > 0) | |
| 422 | − iVal = 1; | |
| 423 | − * ((int*)pOption) = iVal; | |
| 424 | − return cmResultSuccess; | |
| 425 | − } else if (DECODER_OPTION_ERROR_CON_IDC == eOptID) { | |
| 426 | − iVal = (int)m_pDecContext->pParam->eEcActiveIdc; | |
| 427 | − * ((int*)pOption) = iVal; | |
| 428 | − return cmResultSuccess; | |
| 429 | − } else if (DECODER_OPTION_GET_STATISTICS == eOptID) { // get decoder statistics info for real time debugging | |
| 430 | − SDecoderStatistics* pDecoderStatistics = (static_cast<SDecoderStatistics*> (pOption)); | |
| 431 | − | |
| 432 | − memcpy (pDecoderStatistics, &m_pDecContext->sDecoderStatistics, sizeof (SDecoderStatistics)); | |
| 433 | − | |
| 434 | − if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount != 0) { //not original status | |
| 435 | − pDecoderStatistics->fAverageFrameSpeedInMs = (float) (m_pDecContext->dDecTime) / | |
| 436 | − (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount); | |
| 437 | − pDecoderStatistics->fActualAverageFrameSpeedInMs = (float) (m_pDecContext->dDecTime) / | |
| 438 | − (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount + m_pDecContext->sDecoderStatistics.uiFreezingIDRNum + | |
| 439 | − m_pDecContext->sDecoderStatistics.uiFreezingNonIDRNum); | |
| 440 | − } | |
| 441 | − return cmResultSuccess; | |
| 442 | − } else if (eOptID == DECODER_OPTION_STATISTICS_LOG_INTERVAL) { | |
| 443 | − if (pOption) { | |
| 444 | − iVal = m_pDecContext->sDecoderStatistics.iStatisticsLogInterval; | |
| 445 | − * ((unsigned int*)pOption) = iVal; | |
| 446 | − return cmResultSuccess; | |
| 447 | − } | |
| 448 | − } else if (DECODER_OPTION_GET_SAR_INFO == eOptID) { //get decoder SAR info in VUI | |
| 449 | − PVuiSarInfo pVuiSarInfo = (static_cast<PVuiSarInfo> (pOption)); | |
| 450 | − memset (pVuiSarInfo, 0, sizeof (SVuiSarInfo)); | |
| 451 | − if (!m_pDecContext->pSps) { | |
| 452 | − return cmInitExpected; | |
| 453 | − } else { | |
| 454 | − pVuiSarInfo->uiSarWidth = m_pDecContext->pSps->sVui.uiSarWidth; | |
| 455 | − pVuiSarInfo->uiSarHeight = m_pDecContext->pSps->sVui.uiSarHeight; | |
| 456 | − pVuiSarInfo->bOverscanAppropriateFlag = m_pDecContext->pSps->sVui.bOverscanAppropriateFlag; | |
| 457 | − return cmResultSuccess; | |
| 458 | − } | |
| 459 | − } else if (DECODER_OPTION_PROFILE == eOptID) { | |
| 460 | − if (!m_pDecContext->pSps) { | |
| 461 | − return cmInitExpected; | |
| 462 | − } | |
| 463 | − iVal = (int)m_pDecContext->pSps->uiProfileIdc; | |
| 464 | − * ((int*)pOption) = iVal; | |
| 465 | − return cmResultSuccess; | |
| 466 | − } else if (DECODER_OPTION_LEVEL == eOptID) { | |
| 467 | − if (!m_pDecContext->pSps) { | |
| 468 | − return cmInitExpected; | |
| 469 | − } | |
| 470 | − iVal = (int)m_pDecContext->pSps->uiLevelIdc; | |
| 471 | − * ((int*)pOption) = iVal; | |
| 472 | − return cmResultSuccess; | |
| 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) { | |
| 475 | − * ((int*)pOption) = m_iNumOfPicts > 0 ? m_iNumOfPicts : 0; | |
| 476 | − } | |
| 477 | − return cmResultSuccess; | |
| 478 | − } | |
| 479 | − | |
| 480 | − return cmInitParaError; | |
| 481 | −} | |
| 482 | − | |
| 483 | −DECODING_STATE CWelsDecoder::DecodeFrameNoDelay (const unsigned char* kpSrc, | |
| 484 | − const int kiSrcLen, | |
| 485 | − unsigned char** ppDst, | |
| 486 | − SBufferInfo* pDstInfo) { | |
| 487 | − int iRet; | |
| 488 | − //SBufferInfo sTmpBufferInfo; | |
| 489 | − //unsigned char* ppTmpDst[3] = {NULL, NULL, NULL}; | |
| 490 | − iRet = (int)DecodeFrame2 (kpSrc, kiSrcLen, ppDst, pDstInfo); | |
| 491 | − //memcpy (&sTmpBufferInfo, pDstInfo, sizeof (SBufferInfo)); | |
| 492 | − //ppTmpDst[0] = ppDst[0]; | |
| 493 | − //ppTmpDst[1] = ppDst[1]; | |
| 494 | − //ppTmpDst[2] = ppDst[2]; | |
| 495 | − iRet |= DecodeFrame2 (NULL, 0, ppDst, pDstInfo); | |
| 496 | − //if ((pDstInfo->iBufferStatus == 0) && (sTmpBufferInfo.iBufferStatus == 1)) { | |
| 497 | − //memcpy (pDstInfo, &sTmpBufferInfo, sizeof (SBufferInfo)); | |
| 498 | − //ppDst[0] = ppTmpDst[0]; | |
| 499 | − //ppDst[1] = ppTmpDst[1]; | |
| 500 | − //ppDst[2] = ppTmpDst[2]; | |
| 501 | − //} | |
| 502 | − return (DECODING_STATE)iRet; | |
| 503 | −} | |
| 504 | − | |
| 505 | −DECODING_STATE CWelsDecoder::DecodeFrame2 (const unsigned char* kpSrc, | |
| 506 | − const int kiSrcLen, | |
| 507 | − unsigned char** ppDst, | |
| 508 | − SBufferInfo* pDstInfo) { | |
| 509 | − if (m_pDecContext == NULL || m_pDecContext->pParam == NULL) { | |
| 510 | − if (m_pWelsTrace != NULL) { | |
| 511 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "Call DecodeFrame2 without Initialize.\n"); | |
| 512 | − } | |
| 513 | − return dsInitialOptExpected; | |
| 514 | − } | |
| 515 | − | |
| 516 | − if (m_pDecContext->pParam->bParseOnly) { | |
| 517 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "bParseOnly should be false for this API calling! \n"); | |
| 518 | − m_pDecContext->iErrorCode |= dsInvalidArgument; | |
| 519 | − return dsInvalidArgument; | |
| 520 | − } | |
| 521 | − if (CheckBsBuffer (m_pDecContext, kiSrcLen)) { | |
| 522 | − if (ResetDecoder()) | |
| 523 | − return dsOutOfMemory; | |
| 524 | − | |
| 525 | − return dsErrorFree; | |
| 526 | − } | |
| 527 | − if (kiSrcLen > 0 && kpSrc != NULL) { | |
| 528 | −#ifdef OUTPUT_BIT_STREAM | |
| 529 | − if (m_pFBS) { | |
| 530 | − WelsFwrite (kpSrc, sizeof (unsigned char), kiSrcLen, m_pFBS); | |
| 531 | − WelsFflush (m_pFBS); | |
| 532 | − } | |
| 533 | − if (m_pFBSSize) { | |
| 534 | − WelsFwrite (&kiSrcLen, sizeof (int), 1, m_pFBSSize); | |
| 535 | − WelsFflush (m_pFBSSize); | |
| 536 | − } | |
| 537 | −#endif//OUTPUT_BIT_STREAM | |
| 538 | − m_pDecContext->bEndOfStreamFlag = false; | |
| 539 | − } else { | |
| 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. | |
| 542 | − m_pDecContext->bEndOfStreamFlag = true; | |
| 543 | − m_pDecContext->bInstantDecFlag = true; | |
| 544 | − } | |
| 545 | − | |
| 546 | − int64_t iStart, iEnd; | |
| 547 | − iStart = WelsTime(); | |
| 548 | − | |
| 549 | − ppDst[0] = ppDst[1] = ppDst[2] = NULL; | |
| 550 | − m_pDecContext->iErrorCode = dsErrorFree; //initialize at the starting of AU decoding. | |
| 551 | − m_pDecContext->iFeedbackVclNalInAu = FEEDBACK_UNKNOWN_NAL; //initialize | |
| 552 | − unsigned long long uiInBsTimeStamp = pDstInfo->uiInBsTimeStamp; | |
| 553 | − memset (pDstInfo, 0, sizeof (SBufferInfo)); | |
| 554 | − pDstInfo->uiInBsTimeStamp = uiInBsTimeStamp; | |
| 555 | −#ifdef LONG_TERM_REF | |
| 556 | − m_pDecContext->bReferenceLostAtT0Flag = false; //initialize for LTR | |
| 557 | − m_pDecContext->bCurAuContainLtrMarkSeFlag = false; | |
| 558 | − m_pDecContext->iFrameNumOfAuMarkedLtr = 0; | |
| 559 | − m_pDecContext->iFrameNum = -1; //initialize | |
| 560 | −#endif | |
| 561 | − | |
| 562 | − m_pDecContext->iFeedbackTidInAu = -1; //initialize | |
| 563 | − m_pDecContext->iFeedbackNalRefIdc = -1; //initialize | |
| 564 | − if (pDstInfo) { | |
| 565 | − pDstInfo->uiOutYuvTimeStamp = 0; | |
| 566 | − m_pDecContext->uiTimeStamp = pDstInfo->uiInBsTimeStamp; | |
| 567 | − } else { | |
| 568 | − m_pDecContext->uiTimeStamp = 0; | |
| 569 | − } | |
| 570 | − WelsDecodeBs (m_pDecContext, kpSrc, kiSrcLen, ppDst, | |
| 571 | − pDstInfo, NULL); //iErrorCode has been modified in this function | |
| 572 | − m_pDecContext->bInstantDecFlag = false; //reset no-delay flag | |
| 573 | − if (m_pDecContext->iErrorCode) { | |
| 574 | − EWelsNalUnitType eNalType = | |
| 575 | − NAL_UNIT_UNSPEC_0; //for NBR, IDR frames are expected to decode as followed if error decoding an IDR currently | |
| 576 | − | |
| 577 | − eNalType = m_pDecContext->sCurNalHead.eNalUnitType; | |
| 578 | − | |
| 579 | − if (m_pDecContext->iErrorCode & dsOutOfMemory) { | |
| 580 | − if (ResetDecoder()) | |
| 581 | − return dsOutOfMemory; | |
| 582 | − | |
| 583 | − return dsErrorFree; | |
| 584 | − } | |
| 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) || | |
| 587 | − (VIDEO_BITSTREAM_AVC == m_pDecContext->eVideoType)) { | |
| 588 | − if (m_pDecContext->pParam->eEcActiveIdc == ERROR_CON_DISABLE) { | |
| 589 | −#ifdef LONG_TERM_REF | |
| 590 | − m_pDecContext->bParamSetsLostFlag = true; | |
| 591 | −#else | |
| 592 | − m_pDecContext->bReferenceLostAtT0Flag = true; | |
| 593 | −#endif | |
| 594 | − } | |
| 595 | − } | |
| 596 | − | |
| 597 | − if (m_pDecContext->bPrintFrameErrorTraceFlag) { | |
| 598 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "decode failed, failure type:%d \n", | |
| 599 | − m_pDecContext->iErrorCode); | |
| 600 | − m_pDecContext->bPrintFrameErrorTraceFlag = false; | |
| 601 | − } else { | |
| 602 | − m_pDecContext->iIgnoredErrorInfoPacketCount++; | |
| 603 | − if (m_pDecContext->iIgnoredErrorInfoPacketCount == INT_MAX) { | |
| 604 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING, "continuous error reached INT_MAX! Restart as 0."); | |
| 605 | − m_pDecContext->iIgnoredErrorInfoPacketCount = 0; | |
| 606 | − } | |
| 607 | − } | |
| 608 | − if ((m_pDecContext->pParam->eEcActiveIdc != ERROR_CON_DISABLE) && (pDstInfo->iBufferStatus == 1)) { | |
| 609 | − //TODO after dec status updated | |
| 610 | − m_pDecContext->iErrorCode |= dsDataErrorConcealed; | |
| 611 | − | |
| 612 | − m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++; | |
| 613 | − if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount == 0) { //exceed max value of uint32_t | |
| 614 | − ResetDecStatNums (&m_pDecContext->sDecoderStatistics); | |
| 615 | − m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++; | |
| 616 | − } | |
| 617 | − int32_t iMbConcealedNum = m_pDecContext->iMbEcedNum + m_pDecContext->iMbEcedPropNum; | |
| 618 | − m_pDecContext->sDecoderStatistics.uiAvgEcRatio = m_pDecContext->iMbNum == 0 ? | |
| 619 | − (m_pDecContext->sDecoderStatistics.uiAvgEcRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) : (( | |
| 620 | − m_pDecContext->sDecoderStatistics.uiAvgEcRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) + (( | |
| 621 | − iMbConcealedNum * 100) / m_pDecContext->iMbNum)); | |
| 622 | − m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio = m_pDecContext->iMbNum == 0 ? | |
| 623 | − (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)); | |
| 626 | − m_pDecContext->sDecoderStatistics.uiEcFrameNum += (iMbConcealedNum == 0 ? 0 : 1); | |
| 627 | − m_pDecContext->sDecoderStatistics.uiAvgEcRatio = m_pDecContext->sDecoderStatistics.uiEcFrameNum == 0 ? 0 : | |
| 628 | − m_pDecContext->sDecoderStatistics.uiAvgEcRatio / m_pDecContext->sDecoderStatistics.uiEcFrameNum; | |
| 629 | − m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio = m_pDecContext->sDecoderStatistics.uiEcFrameNum == 0 ? 0 : | |
| 630 | − m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio / m_pDecContext->sDecoderStatistics.uiEcFrameNum; | |
| 631 | − } | |
| 632 | − iEnd = WelsTime(); | |
| 633 | − m_pDecContext->dDecTime += (iEnd - iStart) / 1e3; | |
| 634 | − | |
| 635 | − OutputStatisticsLog (m_pDecContext->sDecoderStatistics); | |
| 636 | − | |
| 637 | −#ifdef _PICTURE_REORDERING_ | |
| 638 | − ReorderPicturesInDisplay (ppDst, pDstInfo); | |
| 639 | −#endif | |
| 640 | − | |
| 641 | − return (DECODING_STATE)m_pDecContext->iErrorCode; | |
| 642 | − } | |
| 643 | − // else Error free, the current codec works well | |
| 644 | − | |
| 645 | − if (pDstInfo->iBufferStatus == 1) { | |
| 646 | − | |
| 647 | − m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++; | |
| 648 | − if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount == 0) { //exceed max value of uint32_t | |
| 649 | − ResetDecStatNums (&m_pDecContext->sDecoderStatistics); | |
| 650 | − m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++; | |
| 651 | − } | |
| 652 | − | |
| 653 | − OutputStatisticsLog (m_pDecContext->sDecoderStatistics); | |
| 654 | − } | |
| 655 | − iEnd = WelsTime(); | |
| 656 | − m_pDecContext->dDecTime += (iEnd - iStart) / 1e3; | |
| 657 | − | |
| 658 | −#ifdef _PICTURE_REORDERING_ | |
| 659 | − ReorderPicturesInDisplay (ppDst, pDstInfo); | |
| 660 | −#endif | |
| 661 | − return dsErrorFree; | |
| 662 | −} | |
| 663 | − | |
| 664 | −DECODING_STATE CWelsDecoder::FlushFrame (unsigned char** ppDst, | |
| 665 | − SBufferInfo* pDstInfo) { | |
| 666 | − if (m_pDecContext->bEndOfStreamFlag && m_iNumOfPicts > 0) { | |
| 667 | − m_iMinPOC = sIMinInt32; | |
| 668 | − for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) { | |
| 669 | − if (m_iMinPOC == sIMinInt32 && m_sPictInfoList[i].iPOC > sIMinInt32) { | |
| 670 | − m_iMinPOC = m_sPictInfoList[i].iPOC; | |
| 671 | − m_iPictInfoIndex = i; | |
| 672 | − } | |
| 673 | − if (m_sPictInfoList[i].iPOC > sIMinInt32 && m_sPictInfoList[i].iPOC < m_iMinPOC) { | |
| 674 | − m_iMinPOC = m_sPictInfoList[i].iPOC; | |
| 675 | − m_iPictInfoIndex = i; | |
| 676 | − } | |
| 677 | − } | |
| 678 | − } | |
| 679 | − if (m_iMinPOC > sIMinInt32) { | |
| 680 | − m_LastWrittenPOC = m_iMinPOC; | |
| 681 | −#if defined (_DEBUG) | |
| 682 | −#ifdef _MOTION_VECTOR_DUMP_ | |
| 683 | − fprintf (stderr, "Output POC: #%d\n", m_LastWrittenPOC); | |
| 684 | −#endif | |
| 685 | −#endif | |
| 686 | − memcpy (pDstInfo, &m_sPictInfoList[m_iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo)); | |
| 687 | − ppDst[0] = m_sPictInfoList[m_iPictInfoIndex].pData[0]; | |
| 688 | − ppDst[1] = m_sPictInfoList[m_iPictInfoIndex].pData[1]; | |
| 689 | − ppDst[2] = m_sPictInfoList[m_iPictInfoIndex].pData[2]; | |
| 690 | − m_sPictInfoList[m_iPictInfoIndex].iPOC = sIMinInt32; | |
| 691 | − m_sPictInfoList[m_iPictInfoIndex].bLastGOP = false; | |
| 692 | − m_iMinPOC = sIMinInt32; | |
| 693 | − --m_iNumOfPicts; | |
| 694 | − } | |
| 695 | − return dsErrorFree; | |
| 696 | −} | |
| 697 | − | |
| 698 | −void CWelsDecoder::OutputStatisticsLog (SDecoderStatistics& sDecoderStatistics) { | |
| 699 | − if ((sDecoderStatistics.uiDecodedFrameCount > 0) && (sDecoderStatistics.iStatisticsLogInterval > 0) | |
| 700 | − && ((sDecoderStatistics.uiDecodedFrameCount % sDecoderStatistics.iStatisticsLogInterval) == 0)) { | |
| 701 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 702 | − "DecoderStatistics: uiWidth=%d, uiHeight=%d, fAverageFrameSpeedInMs=%.1f, fActualAverageFrameSpeedInMs=%.1f, \ | |
| 703 | − uiDecodedFrameCount=%d, uiResolutionChangeTimes=%d, uiIDRCorrectNum=%d, \ | |
| 704 | − uiAvgEcRatio=%d, uiAvgEcPropRatio=%d, uiEcIDRNum=%d, uiEcFrameNum=%d, \ | |
| 705 | − uiIDRLostNum=%d, uiFreezingIDRNum=%d, uiFreezingNonIDRNum=%d, iAvgLumaQp=%d, \ | |
| 706 | − iSpsReportErrorNum=%d, iSubSpsReportErrorNum=%d, iPpsReportErrorNum=%d, iSpsNoExistNalNum=%d, iSubSpsNoExistNalNum=%d, iPpsNoExistNalNum=%d, \ | |
| 707 | − uiProfile=%d, uiLevel=%d, \ | |
| 708 | − iCurrentActiveSpsId=%d, iCurrentActivePpsId=%d,", | |
| 709 | − sDecoderStatistics.uiWidth, | |
| 710 | − sDecoderStatistics.uiHeight, | |
| 711 | − sDecoderStatistics.fAverageFrameSpeedInMs, | |
| 712 | − sDecoderStatistics.fActualAverageFrameSpeedInMs, | |
| 713 | − | |
| 714 | − sDecoderStatistics.uiDecodedFrameCount, | |
| 715 | − sDecoderStatistics.uiResolutionChangeTimes, | |
| 716 | − sDecoderStatistics.uiIDRCorrectNum, | |
| 717 | − | |
| 718 | − sDecoderStatistics.uiAvgEcRatio, | |
| 719 | − sDecoderStatistics.uiAvgEcPropRatio, | |
| 720 | − sDecoderStatistics.uiEcIDRNum, | |
| 721 | − sDecoderStatistics.uiEcFrameNum, | |
| 722 | − | |
| 723 | − sDecoderStatistics.uiIDRLostNum, | |
| 724 | − sDecoderStatistics.uiFreezingIDRNum, | |
| 725 | − sDecoderStatistics.uiFreezingNonIDRNum, | |
| 726 | − sDecoderStatistics.iAvgLumaQp, | |
| 727 | − | |
| 728 | − sDecoderStatistics.iSpsReportErrorNum, | |
| 729 | − sDecoderStatistics.iSubSpsReportErrorNum, | |
| 730 | − sDecoderStatistics.iPpsReportErrorNum, | |
| 731 | − sDecoderStatistics.iSpsNoExistNalNum, | |
| 732 | − sDecoderStatistics.iSubSpsNoExistNalNum, | |
| 733 | − sDecoderStatistics.iPpsNoExistNalNum, | |
| 734 | − | |
| 735 | − sDecoderStatistics.uiProfile, | |
| 736 | − sDecoderStatistics.uiLevel, | |
| 737 | − | |
| 738 | − sDecoderStatistics.iCurrentActiveSpsId, | |
| 739 | − sDecoderStatistics.iCurrentActivePpsId); | |
| 740 | − } | |
| 741 | −} | |
| 742 | − | |
| 743 | −DECODING_STATE CWelsDecoder::ReorderPicturesInDisplay (unsigned char** ppDst, SBufferInfo* pDstInfo) { | |
| 744 | − if (pDstInfo->iBufferStatus == 1 && m_pDecContext->pSps->uiProfileIdc != 66 | |
| 745 | − && m_pDecContext->pPps->bEntropyCodingModeFlag) { | |
| 746 | − if (m_pDecContext->pSliceHeader->iPicOrderCntLsb == 0) { | |
| 747 | − if (m_iNumOfPicts > 0) { | |
| 748 | − m_iLastGOPRemainPicts = m_iNumOfPicts; | |
| 749 | − for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) { | |
| 750 | − if (m_sPictInfoList[i].iPOC > sIMinInt32) { | |
| 751 | − m_sPictInfoList[i].bLastGOP = true; | |
| 752 | − } | |
| 753 | − } | |
| 754 | − } | |
| 755 | − } | |
| 756 | − for (int32_t i = 0; i < 16; ++i) { | |
| 757 | − if (m_sPictInfoList[i].iPOC == sIMinInt32) { | |
| 758 | − memcpy (&m_sPictInfoList[i].sBufferInfo, pDstInfo, sizeof (SBufferInfo)); | |
| 759 | − m_sPictInfoList[i].pData[0] = ppDst[0]; | |
| 760 | − m_sPictInfoList[i].pData[1] = ppDst[1]; | |
| 761 | − m_sPictInfoList[i].pData[2] = ppDst[2]; | |
| 762 | − m_sPictInfoList[i].iPOC = m_pDecContext->pSliceHeader->iPicOrderCntLsb; | |
| 763 | − m_sPictInfoList[i].iFrameNum = m_pDecContext->pSliceHeader->iFrameNum; | |
| 764 | − m_sPictInfoList[i].bLastGOP = false; | |
| 765 | − pDstInfo->iBufferStatus = 0; | |
| 766 | − ++m_iNumOfPicts; | |
| 767 | − if (i > m_iLargestBufferedPicIndex) { | |
| 768 | − m_iLargestBufferedPicIndex = i; | |
| 769 | − } | |
| 770 | − break; | |
| 771 | − } | |
| 772 | − } | |
| 773 | − if (m_iLastGOPRemainPicts > 0) { | |
| 774 | − m_iMinPOC = sIMinInt32; | |
| 775 | − for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) { | |
| 776 | − if (m_iMinPOC == sIMinInt32 && m_sPictInfoList[i].iPOC > sIMinInt32 && m_sPictInfoList[i].bLastGOP) { | |
| 777 | − m_iMinPOC = m_sPictInfoList[i].iPOC; | |
| 778 | − m_iPictInfoIndex = i; | |
| 779 | − } | |
| 780 | − if (m_sPictInfoList[i].iPOC > sIMinInt32 && m_sPictInfoList[i].iPOC < m_iMinPOC && m_sPictInfoList[i].bLastGOP) { | |
| 781 | − m_iMinPOC = m_sPictInfoList[i].iPOC; | |
| 782 | − m_iPictInfoIndex = i; | |
| 783 | − } | |
| 784 | − } | |
| 785 | − m_LastWrittenPOC = m_iMinPOC; | |
| 786 | −#if defined (_DEBUG) | |
| 787 | −#ifdef _MOTION_VECTOR_DUMP_ | |
| 788 | − fprintf (stderr, "Output POC: #%d\n", m_LastWrittenPOC); | |
| 789 | −#endif | |
| 790 | −#endif | |
| 791 | − memcpy (pDstInfo, &m_sPictInfoList[m_iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo)); | |
| 792 | − ppDst[0] = m_sPictInfoList[m_iPictInfoIndex].pData[0]; | |
| 793 | − ppDst[1] = m_sPictInfoList[m_iPictInfoIndex].pData[1]; | |
| 794 | − ppDst[2] = m_sPictInfoList[m_iPictInfoIndex].pData[2]; | |
| 795 | − m_sPictInfoList[m_iPictInfoIndex].iPOC = sIMinInt32; | |
| 796 | − m_sPictInfoList[m_iPictInfoIndex].bLastGOP = false; | |
| 797 | − m_iMinPOC = sIMinInt32; | |
| 798 | − --m_iNumOfPicts; | |
| 799 | − --m_iLastGOPRemainPicts; | |
| 800 | − if (m_iLastGOPRemainPicts == 0) { | |
| 801 | − m_LastWrittenPOC = sIMinInt32; | |
| 802 | − } | |
| 803 | − return dsErrorFree; | |
| 804 | − } | |
| 805 | − if (m_iNumOfPicts > 0) { | |
| 806 | − m_iMinPOC = sIMinInt32; | |
| 807 | − for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) { | |
| 808 | − if (m_iMinPOC == sIMinInt32 && m_sPictInfoList[i].iPOC > sIMinInt32) { | |
| 809 | − m_iMinPOC = m_sPictInfoList[i].iPOC; | |
| 810 | − m_iPictInfoIndex = i; | |
| 811 | − } | |
| 812 | − if (m_sPictInfoList[i].iPOC > sIMinInt32 && m_sPictInfoList[i].iPOC < m_iMinPOC) { | |
| 813 | − m_iMinPOC = m_sPictInfoList[i].iPOC; | |
| 814 | − m_iPictInfoIndex = i; | |
| 815 | − } | |
| 816 | − } | |
| 817 | − } | |
| 818 | − if (m_iMinPOC > sIMinInt32) { | |
| 819 | − if ((m_LastWrittenPOC > sIMinInt32 && m_iMinPOC - m_LastWrittenPOC <= 1) | |
| 820 | − || m_iMinPOC < m_pDecContext->pSliceHeader->iPicOrderCntLsb) { | |
| 821 | − m_LastWrittenPOC = m_iMinPOC; | |
| 822 | −#if defined (_DEBUG) | |
| 823 | −#ifdef _MOTION_VECTOR_DUMP_ | |
| 824 | − fprintf (stderr, "Output POC: #%d\n", m_LastWrittenPOC); | |
| 825 | −#endif | |
| 826 | −#endif | |
| 827 | − memcpy (pDstInfo, &m_sPictInfoList[m_iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo)); | |
| 828 | − ppDst[0] = m_sPictInfoList[m_iPictInfoIndex].pData[0]; | |
| 829 | − ppDst[1] = m_sPictInfoList[m_iPictInfoIndex].pData[1]; | |
| 830 | − ppDst[2] = m_sPictInfoList[m_iPictInfoIndex].pData[2]; | |
| 831 | − m_sPictInfoList[m_iPictInfoIndex].iPOC = sIMinInt32; | |
| 832 | − m_sPictInfoList[m_iPictInfoIndex].bLastGOP = false; | |
| 833 | − m_iMinPOC = sIMinInt32; | |
| 834 | − --m_iNumOfPicts; | |
| 835 | − return dsErrorFree; | |
| 836 | − } | |
| 837 | − } | |
| 838 | − } | |
| 839 | − | |
| 840 | − return dsErrorFree; | |
| 841 | −} | |
| 842 | − | |
| 843 | −DECODING_STATE CWelsDecoder::DecodeParser (const unsigned char* kpSrc, | |
| 844 | − const int kiSrcLen, | |
| 845 | − SParserBsInfo* pDstInfo) { | |
| 846 | − if (m_pDecContext == NULL || m_pDecContext->pParam == NULL) { | |
| 847 | − if (m_pWelsTrace != NULL) { | |
| 848 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "Call DecodeParser without Initialize.\n"); | |
| 849 | − } | |
| 850 | − return dsInitialOptExpected; | |
| 851 | − } | |
| 852 | − | |
| 853 | − if (!m_pDecContext->pParam->bParseOnly) { | |
| 854 | − WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "bParseOnly should be true for this API calling! \n"); | |
| 855 | − m_pDecContext->iErrorCode |= dsInvalidArgument; | |
| 856 | − return dsInvalidArgument; | |
| 857 | − } | |
| 858 | − int64_t iEnd, iStart = WelsTime(); | |
| 859 | − if (CheckBsBuffer (m_pDecContext, kiSrcLen)) { | |
| 860 | − if (ResetDecoder()) | |
| 861 | − return dsOutOfMemory; | |
| 862 | − | |
| 863 | − return dsErrorFree; | |
| 864 | − } | |
| 865 | − if (kiSrcLen > 0 && kpSrc != NULL) { | |
| 866 | −#ifdef OUTPUT_BITSTREAM | |
| 867 | − if (m_pFBS) { | |
| 868 | − WelsFwrite (kpSrc, sizeof (unsigned char), kiSrcLen, m_pFBS); | |
| 869 | − WelsFflush (m_pFBS); | |
| 870 | − } | |
| 871 | −#endif//OUTPUT_BIT_STREAM | |
| 872 | − m_pDecContext->bEndOfStreamFlag = false; | |
| 873 | − } else { | |
| 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. | |
| 876 | − m_pDecContext->bEndOfStreamFlag = true; | |
| 877 | − m_pDecContext->bInstantDecFlag = true; | |
| 878 | − } | |
| 879 | − | |
| 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. | |
| 882 | − m_pDecContext->iFeedbackNalRefIdc = -1; //initialize | |
| 883 | − if (!m_pDecContext->bFramePending) { //frame complete | |
| 884 | − m_pDecContext->pParserBsInfo->iNalNum = 0; | |
| 885 | − memset (m_pDecContext->pParserBsInfo->pNalLenInByte, 0, MAX_NAL_UNITS_IN_LAYER); | |
| 886 | − } | |
| 887 | − pDstInfo->iNalNum = 0; | |
| 888 | − pDstInfo->iSpsWidthInPixel = pDstInfo->iSpsHeightInPixel = 0; | |
| 889 | − if (pDstInfo) { | |
| 890 | − m_pDecContext->uiTimeStamp = pDstInfo->uiInBsTimeStamp; | |
| 891 | − pDstInfo->uiOutBsTimeStamp = 0; | |
| 892 | − } else { | |
| 893 | − m_pDecContext->uiTimeStamp = 0; | |
| 894 | − } | |
| 895 | − WelsDecodeBs (m_pDecContext, kpSrc, kiSrcLen, NULL, NULL, pDstInfo); | |
| 896 | − if (m_pDecContext->iErrorCode & dsOutOfMemory) { | |
| 897 | − if (ResetDecoder()) | |
| 898 | − return dsOutOfMemory; | |
| 899 | − return dsErrorFree; | |
| 900 | − } | |
| 901 | − | |
| 902 | − if (!m_pDecContext->bFramePending && m_pDecContext->pParserBsInfo->iNalNum) { | |
| 903 | − memcpy (pDstInfo, m_pDecContext->pParserBsInfo, sizeof (SParserBsInfo)); | |
| 904 | − | |
| 905 | − if (m_pDecContext->iErrorCode == ERR_NONE) { //update statistics: decoding frame count | |
| 906 | − m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++; | |
| 907 | − if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount == 0) { //exceed max value of uint32_t | |
| 908 | − ResetDecStatNums (&m_pDecContext->sDecoderStatistics); | |
| 909 | − m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++; | |
| 910 | − } | |
| 911 | − } | |
| 912 | − } | |
| 913 | − | |
| 914 | − m_pDecContext->bInstantDecFlag = false; //reset no-delay flag | |
| 915 | − | |
| 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); | |
| 918 | − m_pDecContext->bPrintFrameErrorTraceFlag = false; | |
| 919 | − } | |
| 920 | − iEnd = WelsTime(); | |
| 921 | − m_pDecContext->dDecTime += (iEnd - iStart) / 1e3; | |
| 922 | − | |
| 923 | − return (DECODING_STATE) m_pDecContext->iErrorCode; | |
| 924 | −} | |
| 925 | − | |
| 926 | −DECODING_STATE CWelsDecoder::DecodeFrame (const unsigned char* kpSrc, | |
| 927 | − const int kiSrcLen, | |
| 928 | − unsigned char** ppDst, | |
| 929 | − int* pStride, | |
| 930 | − int& iWidth, | |
| 931 | − int& iHeight) { | |
| 932 | − DECODING_STATE eDecState = dsErrorFree; | |
| 933 | − SBufferInfo DstInfo; | |
| 934 | − | |
| 935 | − memset (&DstInfo, 0, sizeof (SBufferInfo)); | |
| 936 | − DstInfo.UsrData.sSystemBuffer.iStride[0] = pStride[0]; | |
| 937 | − DstInfo.UsrData.sSystemBuffer.iStride[1] = pStride[1]; | |
| 938 | − DstInfo.UsrData.sSystemBuffer.iWidth = iWidth; | |
| 939 | − DstInfo.UsrData.sSystemBuffer.iHeight = iHeight; | |
| 940 | − | |
| 941 | − eDecState = DecodeFrame2 (kpSrc, kiSrcLen, ppDst, &DstInfo); | |
| 942 | − if (eDecState == dsErrorFree) { | |
| 943 | − pStride[0] = DstInfo.UsrData.sSystemBuffer.iStride[0]; | |
| 944 | − pStride[1] = DstInfo.UsrData.sSystemBuffer.iStride[1]; | |
| 945 | − iWidth = DstInfo.UsrData.sSystemBuffer.iWidth; | |
| 946 | − iHeight = DstInfo.UsrData.sSystemBuffer.iHeight; | |
| 947 | − } | |
| 948 | − | |
| 949 | − return eDecState; | |
| 950 | −} | |
| 951 | − | |
| 952 | −DECODING_STATE CWelsDecoder::DecodeFrameEx (const unsigned char* kpSrc, | |
| 953 | − const int kiSrcLen, | |
| 954 | − unsigned char* pDst, | |
| 955 | − int iDstStride, | |
| 956 | − int& iDstLen, | |
| 957 | − int& iWidth, | |
| 958 | − int& iHeight, | |
| 959 | − int& iColorFormat) { | |
| 960 | − DECODING_STATE state = dsErrorFree; | |
| 961 | − | |
| 962 | − return state; | |
| 963 | −} | |
| 964 | − | |
| 965 | − | |
| 966 | −} // namespace WelsDec | |
| 967 | − | |
| 968 | − | |
| 969 | −using namespace WelsDec; | |
| 970 | −/* | |
| 971 | −* WelsGetDecoderCapability | |
| 972 | −* @return: DecCapability information | |
| 973 | −*/ | |
| 974 | −int WelsGetDecoderCapability (SDecoderCapability* pDecCapability) { | |
| 975 | − memset (pDecCapability, 0, sizeof (SDecoderCapability)); | |
| 976 | − pDecCapability->iProfileIdc = 66; //Baseline | |
| 977 | − pDecCapability->iProfileIop = 0xE0; //11100000b | |
| 978 | − pDecCapability->iLevelIdc = 32; //level_idc = 3.2 | |
| 979 | − pDecCapability->iMaxMbps = 216000; //from level_idc = 3.2 | |
| 980 | − pDecCapability->iMaxFs = 5120; //from level_idc = 3.2 | |
| 981 | − pDecCapability->iMaxCpb = 20000; //from level_idc = 3.2 | |
| 982 | − pDecCapability->iMaxDpb = 20480; //from level_idc = 3.2 | |
| 983 | − pDecCapability->iMaxBr = 20000; //from level_idc = 3.2 | |
| 984 | − pDecCapability->bRedPicCap = 0; //not support redundant pic | |
| 985 | − | |
| 986 | − return ERR_NONE; | |
| 987 | −} | |
| 988 | −/* WINAPI is indeed in prefix due to sync to application layer callings!! */ | |
| 989 | − | |
| 990 | −/* | |
| 991 | −* WelsCreateDecoder | |
| 992 | −* @return: success in return 0, otherwise failed. | |
| 993 | −*/ | |
| 994 | −long WelsCreateDecoder (ISVCDecoder** ppDecoder) { | |
| 995 | − | |
| 996 | − if (NULL == ppDecoder) { | |
| 997 | − return ERR_INVALID_PARAMETERS; | |
| 998 | − } | |
| 999 | − | |
| 1000 | − *ppDecoder = new CWelsDecoder(); | |
| 1001 | − | |
| 1002 | − if (NULL == *ppDecoder) { | |
| 1003 | − return ERR_MALLOC_FAILED; | |
| 1004 | − } | |
| 1005 | − | |
| 1006 | − return ERR_NONE; | |
| 1007 | −} | |
| 1008 | − | |
| 1009 | −/* | |
| 1010 | −* WelsDestroyDecoder | |
| 1011 | −*/ | |
| 1012 | −void WelsDestroyDecoder (ISVCDecoder* pDecoder) { | |
| 1013 | − if (NULL != pDecoder) { | |
| 1014 | − delete (CWelsDecoder*)pDecoder; | |
| 1015 | − } | |
| 1016 | −} | |
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 2009-2013, Cisco Systems | |
| 4 | + * All rights reserved. | |
| 5 | + * | |
| 6 | + * Redistribution and use in source and binary forms, with or without | |
| 7 | + * modification, are permitted provided that the following conditions | |
| 8 | + * are met: | |
| 9 | + * | |
| 10 | + * * Redistributions of source code must retain the above copyright | |
| 11 | + * notice, this list of conditions and the following disclaimer. | |
| 12 | + * | |
| 13 | + * * Redistributions in binary form must reproduce the above copyright | |
| 14 | + * notice, this list of conditions and the following disclaimer in | |
| 15 | + * the documentation and/or other materials provided with the | |
| 16 | + * distribution. | |
| 17 | + * | |
| 18 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
| 21 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
| 22 | + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 23 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 24 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 25 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 26 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 27 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
| 28 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 29 | + * POSSIBILITY OF SUCH DAMAGE. | |
| 30 | + * | |
| 31 | + * | |
| 32 | + * welsDecoderExt.cpp | |
| 33 | + * | |
| 34 | + * Abstract | |
| 35 | + * Cisco OpenH264 decoder extension utilization | |
| 36 | + * | |
| 37 | + * History | |
| 38 | + * 3/12/2009 Created | |
| 39 | + * | |
| 40 | + * | |
| 41 | + ************************************************************************/ | |
| 42 | +//#include <assert.h> | |
| 43 | +#include "welsDecoderExt.h" | |
| 44 | +#include "welsCodecTrace.h" | |
| 45 | +#include "codec_def.h" | |
| 46 | +#include "typedefs.h" | |
| 47 | +#include "memory_align.h" | |
| 48 | +#include "utils.h" | |
| 49 | +#include "version.h" | |
| 50 | + | |
| 51 | +//#include "macros.h" | |
| 52 | +#include "decoder.h" | |
| 53 | +#include "decoder_core.h" | |
| 54 | +#include "error_concealment.h" | |
| 55 | + | |
| 56 | +#include "measure_time.h" | |
| 57 | +extern "C" { | |
| 58 | +#include "decoder_core.h" | |
| 59 | +#include "manage_dec_ref.h" | |
| 60 | +} | |
| 61 | +#include "error_code.h" | |
| 62 | +#include "crt_util_safe_x.h" // Safe CRT routines like util for cross platforms | |
| 63 | +#include <time.h> | |
| 64 | +#if defined(_WIN32) /*&& defined(_DEBUG)*/ | |
| 65 | + | |
| 66 | +#include <windows.h> | |
| 67 | +#include <stdio.h> | |
| 68 | +#include <stdarg.h> | |
| 69 | +#include <sys/types.h> | |
| 70 | +#else | |
| 71 | +#include <sys/time.h> | |
| 72 | +#endif | |
| 73 | + | |
| 74 | +#define _PICTURE_REORDERING_ 1 | |
| 75 | + | |
| 76 | +static int32_t sIMinInt32 = -0x7FFFFFFF; | |
| 77 | + | |
| 78 | +namespace WelsDec { | |
| 79 | + | |
| 80 | +////////////////////////////////////////////////////////////////////// | |
| 81 | +// Construction/Destruction | |
| 82 | +////////////////////////////////////////////////////////////////////// | |
| 83 | + | |
| 84 | +/*************************************************************************** | |
| 85 | +* Description: | |
| 86 | +* class CWelsDecoder constructor function, do initialization and | |
| 87 | +* alloc memory required | |
| 88 | +* | |
| 89 | +* Input parameters: none | |
| 90 | +* | |
| 91 | +* return: none | |
| 92 | +***************************************************************************/ | |
| 93 | +CWelsDecoder::CWelsDecoder (void) | |
| 94 | + : m_pDecContext (NULL), | |
| 95 | + m_pWelsTrace (NULL), | |
| 96 | + m_iPictInfoIndex (0), | |
| 97 | + m_iMinPOC (sIMinInt32), | |
| 98 | + m_iNumOfPicts (0), | |
| 99 | + m_iLastGOPRemainPicts (0), | |
| 100 | + m_LastWrittenPOC (sIMinInt32), | |
| 101 | + m_iLargestBufferedPicIndex (0) { | |
| 102 | +#ifdef OUTPUT_BIT_STREAM | |
| 103 | + char chFileName[1024] = { 0 }; //for .264 | |
| 104 | + int iBufUsed = 0; | |
| 105 | + int iBufLeft = 1023; | |
| 106 | + int iCurUsed; | |
| 107 | + | |
| 108 | + char chFileNameSize[1024] = { 0 }; //for .len | |
| 109 | + int iBufUsedSize = 0; | |
| 110 | + int iBufLeftSize = 1023; | |
| 111 | + int iCurUsedSize; | |
| 112 | +#endif//OUTPUT_BIT_STREAM | |
| 113 | + | |
| 114 | + | |
| 115 | + m_pWelsTrace = new welsCodecTrace(); | |
| 116 | + if (m_pWelsTrace != NULL) { | |
| 117 | + m_pWelsTrace->SetCodecInstance (this); | |
| 118 | + m_pWelsTrace->SetTraceLevel (WELS_LOG_ERROR); | |
| 119 | + | |
| 120 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::CWelsDecoder() entry"); | |
| 121 | + } | |
| 122 | + | |
| 123 | + for (int32_t i = 0; i < 16; ++i) { | |
| 124 | + m_sPictInfoList[i].bLastGOP = false; | |
| 125 | + m_sPictInfoList[i].iPOC = sIMinInt32; | |
| 126 | + } | |
| 127 | + | |
| 128 | +#ifdef OUTPUT_BIT_STREAM | |
| 129 | + SWelsTime sCurTime; | |
| 130 | + | |
| 131 | + WelsGetTimeOfDay (&sCurTime); | |
| 132 | + | |
| 133 | + iCurUsed = WelsSnprintf (chFileName, iBufLeft, "bs_0x%p_", (void*)this); | |
| 134 | + iCurUsedSize = WelsSnprintf (chFileNameSize, iBufLeftSize, "size_0x%p_", (void*)this); | |
| 135 | + | |
| 136 | + iBufUsed += iCurUsed; | |
| 137 | + iBufLeft -= iCurUsed; | |
| 138 | + if (iBufLeft > 0) { | |
| 139 | + iCurUsed = WelsStrftime (&chFileName[iBufUsed], iBufLeft, "%y%m%d%H%M%S", &sCurTime); | |
| 140 | + iBufUsed += iCurUsed; | |
| 141 | + iBufLeft -= iCurUsed; | |
| 142 | + } | |
| 143 | + | |
| 144 | + iBufUsedSize += iCurUsedSize; | |
| 145 | + iBufLeftSize -= iCurUsedSize; | |
| 146 | + if (iBufLeftSize > 0) { | |
| 147 | + iCurUsedSize = WelsStrftime (&chFileNameSize[iBufUsedSize], iBufLeftSize, "%y%m%d%H%M%S", &sCurTime); | |
| 148 | + iBufUsedSize += iCurUsedSize; | |
| 149 | + iBufLeftSize -= iCurUsedSize; | |
| 150 | + } | |
| 151 | + | |
| 152 | + if (iBufLeft > 0) { | |
| 153 | + iCurUsed = WelsSnprintf (&chFileName[iBufUsed], iBufLeft, ".%03.3u.264", WelsGetMillisecond (&sCurTime)); | |
| 154 | + iBufUsed += iCurUsed; | |
| 155 | + iBufLeft -= iCurUsed; | |
| 156 | + } | |
| 157 | + | |
| 158 | + if (iBufLeftSize > 0) { | |
| 159 | + iCurUsedSize = WelsSnprintf (&chFileNameSize[iBufUsedSize], iBufLeftSize, ".%03.3u.len", | |
| 160 | + WelsGetMillisecond (&sCurTime)); | |
| 161 | + iBufUsedSize += iCurUsedSize; | |
| 162 | + iBufLeftSize -= iCurUsedSize; | |
| 163 | + } | |
| 164 | + | |
| 165 | + | |
| 166 | + m_pFBS = WelsFopen (chFileName, "wb"); | |
| 167 | + m_pFBSSize = WelsFopen (chFileNameSize, "wb"); | |
| 168 | +#endif//OUTPUT_BIT_STREAM | |
| 169 | +} | |
| 170 | + | |
| 171 | +/*************************************************************************** | |
| 172 | +* Description: | |
| 173 | +* class CWelsDecoder destructor function, destroy allocced memory | |
| 174 | +* | |
| 175 | +* Input parameters: none | |
| 176 | +* | |
| 177 | +* return: none | |
| 178 | +***************************************************************************/ | |
| 179 | +CWelsDecoder::~CWelsDecoder() { | |
| 180 | + if (m_pWelsTrace != NULL) { | |
| 181 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::~CWelsDecoder()"); | |
| 182 | + } | |
| 183 | + | |
| 184 | + UninitDecoder(); | |
| 185 | + | |
| 186 | +#ifdef OUTPUT_BIT_STREAM | |
| 187 | + if (m_pFBS) { | |
| 188 | + WelsFclose (m_pFBS); | |
| 189 | + m_pFBS = NULL; | |
| 190 | + } | |
| 191 | + if (m_pFBSSize) { | |
| 192 | + WelsFclose (m_pFBSSize); | |
| 193 | + m_pFBSSize = NULL; | |
| 194 | + } | |
| 195 | +#endif//OUTPUT_BIT_STREAM | |
| 196 | + | |
| 197 | + if (m_pWelsTrace != NULL) { | |
| 198 | + delete m_pWelsTrace; | |
| 199 | + m_pWelsTrace = NULL; | |
| 200 | + } | |
| 201 | +} | |
| 202 | + | |
| 203 | +long CWelsDecoder::Initialize (const SDecodingParam* pParam) { | |
| 204 | + int iRet = ERR_NONE; | |
| 205 | + if (m_pWelsTrace == NULL) { | |
| 206 | + return cmMallocMemeError; | |
| 207 | + } | |
| 208 | + | |
| 209 | + if (pParam == NULL) { | |
| 210 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsDecoder::Initialize(), invalid input argument."); | |
| 211 | + return cmInitParaError; | |
| 212 | + } | |
| 213 | + | |
| 214 | + // H.264 decoder initialization,including memory allocation,then open it ready to decode | |
| 215 | + iRet = InitDecoder (pParam); | |
| 216 | + if (iRet) | |
| 217 | + return iRet; | |
| 218 | + | |
| 219 | + return cmResultSuccess; | |
| 220 | +} | |
| 221 | + | |
| 222 | +long CWelsDecoder::Uninitialize() { | |
| 223 | + UninitDecoder(); | |
| 224 | + | |
| 225 | + return ERR_NONE; | |
| 226 | +} | |
| 227 | + | |
| 228 | +void CWelsDecoder::UninitDecoder (void) { | |
| 229 | + if (NULL == m_pDecContext) | |
| 230 | + return; | |
| 231 | + | |
| 232 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::UninitDecoder(), openh264 codec version = %s.", | |
| 233 | + VERSION_NUMBER); | |
| 234 | + | |
| 235 | + WelsEndDecoder (m_pDecContext); | |
| 236 | + | |
| 237 | + if (m_pDecContext->pMemAlign != NULL) { | |
| 238 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 239 | + "CWelsDecoder::UninitDecoder(), verify memory usage (%d bytes) after free..", | |
| 240 | + m_pDecContext->pMemAlign->WelsGetMemoryUsage()); | |
| 241 | + delete m_pDecContext->pMemAlign; | |
| 242 | + m_pDecContext->pMemAlign = NULL; | |
| 243 | + } | |
| 244 | + | |
| 245 | + if (NULL != m_pDecContext) { | |
| 246 | + WelsFree (m_pDecContext, "m_pDecContext"); | |
| 247 | + | |
| 248 | + m_pDecContext = NULL; | |
| 249 | + } | |
| 250 | +} | |
| 251 | + | |
| 252 | +// the return value of this function is not suitable, it need report failure info to upper layer. | |
| 253 | +int32_t CWelsDecoder::InitDecoder (const SDecodingParam* pParam) { | |
| 254 | + | |
| 255 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 256 | + "CWelsDecoder::init_decoder(), openh264 codec version = %s, ParseOnly = %d", | |
| 257 | + VERSION_NUMBER, (int32_t)pParam->bParseOnly); | |
| 258 | + | |
| 259 | + //reset decoder context | |
| 260 | + if (m_pDecContext) //free | |
| 261 | + UninitDecoder(); | |
| 262 | + m_pDecContext = (PWelsDecoderContext)WelsMallocz (sizeof (SWelsDecoderContext), "m_pDecContext"); | |
| 263 | + if (NULL == m_pDecContext) | |
| 264 | + return cmMallocMemeError; | |
| 265 | + int32_t iCacheLineSize = 16; // on chip cache line size in byte | |
| 266 | + m_pDecContext->pMemAlign = new CMemoryAlign (iCacheLineSize); | |
| 267 | + WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, (NULL == m_pDecContext->pMemAlign), UninitDecoder()) | |
| 268 | + | |
| 269 | + //fill in default value into context | |
| 270 | + WelsDecoderDefaults (m_pDecContext, &m_pWelsTrace->m_sLogCtx); | |
| 271 | + | |
| 272 | + //check param and update decoder context | |
| 273 | + m_pDecContext->pParam = (SDecodingParam*)m_pDecContext->pMemAlign->WelsMallocz (sizeof (SDecodingParam), | |
| 274 | + "SDecodingParam"); | |
| 275 | + WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, (NULL == m_pDecContext->pParam), UninitDecoder()); | |
| 276 | + int32_t iRet = DecoderConfigParam (m_pDecContext, pParam); | |
| 277 | + WELS_VERIFY_RETURN_IFNEQ (iRet, cmResultSuccess); | |
| 278 | + | |
| 279 | + //init decoder | |
| 280 | + WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, WelsInitDecoder (m_pDecContext, &m_pWelsTrace->m_sLogCtx), | |
| 281 | + UninitDecoder()) | |
| 282 | + | |
| 283 | + return cmResultSuccess; | |
| 284 | +} | |
| 285 | + | |
| 286 | +int32_t CWelsDecoder::ResetDecoder() { | |
| 287 | + // TBC: need to be modified when context and trace point are null | |
| 288 | + if (m_pDecContext != NULL && m_pWelsTrace != NULL) { | |
| 289 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "ResetDecoder(), context error code is %d", | |
| 290 | + m_pDecContext->iErrorCode); | |
| 291 | + SDecodingParam sPrevParam; | |
| 292 | + memcpy (&sPrevParam, m_pDecContext->pParam, sizeof (SDecodingParam)); | |
| 293 | + | |
| 294 | + WELS_VERIFY_RETURN_PROC_IF (cmInitParaError, InitDecoder (&sPrevParam), UninitDecoder()); | |
| 295 | + } else if (m_pWelsTrace != NULL) { | |
| 296 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "ResetDecoder() failed as decoder context null"); | |
| 297 | + } | |
| 298 | + return ERR_INFO_UNINIT; | |
| 299 | +} | |
| 300 | + | |
| 301 | +/* | |
| 302 | + * Set Option | |
| 303 | + */ | |
| 304 | +long CWelsDecoder::SetOption (DECODER_OPTION eOptID, void* pOption) { | |
| 305 | + int iVal = 0; | |
| 306 | + | |
| 307 | + if (m_pDecContext == NULL && eOptID != DECODER_OPTION_TRACE_LEVEL && | |
| 308 | + eOptID != DECODER_OPTION_TRACE_CALLBACK && eOptID != DECODER_OPTION_TRACE_CALLBACK_CONTEXT) | |
| 309 | + return dsInitialOptExpected; | |
| 310 | + if (eOptID == DECODER_OPTION_END_OF_STREAM) { // Indicate bit-stream of the final frame to be decoded | |
| 311 | + if (pOption == NULL) | |
| 312 | + return cmInitParaError; | |
| 313 | + | |
| 314 | + iVal = * ((int*)pOption); // boolean value for whether enabled End Of Stream flag | |
| 315 | + | |
| 316 | + m_pDecContext->bEndOfStreamFlag = iVal ? true : false; | |
| 317 | + | |
| 318 | + return cmResultSuccess; | |
| 319 | + } else if (eOptID == DECODER_OPTION_ERROR_CON_IDC) { // Indicate error concealment status | |
| 320 | + if (pOption == NULL) | |
| 321 | + return cmInitParaError; | |
| 322 | + | |
| 323 | + 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); | |
| 325 | + if ((m_pDecContext->pParam->bParseOnly) && (iVal != (int32_t)ERROR_CON_DISABLE)) { | |
| 326 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 327 | + "CWelsDecoder::SetOption for ERROR_CON_IDC = %d not allowd for parse only!.", iVal); | |
| 328 | + return cmInitParaError; | |
| 329 | + } | |
| 330 | + | |
| 331 | + m_pDecContext->pParam->eEcActiveIdc = (ERROR_CON_IDC)iVal; | |
| 332 | + InitErrorCon (m_pDecContext); | |
| 333 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 334 | + "CWelsDecoder::SetOption for ERROR_CON_IDC = %d.", iVal); | |
| 335 | + | |
| 336 | + return cmResultSuccess; | |
| 337 | + } else if (eOptID == DECODER_OPTION_TRACE_LEVEL) { | |
| 338 | + if (m_pWelsTrace) { | |
| 339 | + uint32_t level = * ((uint32_t*)pOption); | |
| 340 | + m_pWelsTrace->SetTraceLevel (level); | |
| 341 | + } | |
| 342 | + return cmResultSuccess; | |
| 343 | + } else if (eOptID == DECODER_OPTION_TRACE_CALLBACK) { | |
| 344 | + if (m_pWelsTrace) { | |
| 345 | + WelsTraceCallback callback = * ((WelsTraceCallback*)pOption); | |
| 346 | + m_pWelsTrace->SetTraceCallback (callback); | |
| 347 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 348 | + "CWelsDecoder::SetOption():DECODER_OPTION_TRACE_CALLBACK callback = %p.", | |
| 349 | + callback); | |
| 350 | + } | |
| 351 | + return cmResultSuccess; | |
| 352 | + } else if (eOptID == DECODER_OPTION_TRACE_CALLBACK_CONTEXT) { | |
| 353 | + if (m_pWelsTrace) { | |
| 354 | + void* ctx = * ((void**)pOption); | |
| 355 | + m_pWelsTrace->SetTraceCallbackContext (ctx); | |
| 356 | + } | |
| 357 | + return cmResultSuccess; | |
| 358 | + } else if (eOptID == DECODER_OPTION_GET_STATISTICS) { | |
| 359 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING, | |
| 360 | + "CWelsDecoder::SetOption():DECODER_OPTION_GET_STATISTICS: this option is get-only!"); | |
| 361 | + return cmInitParaError; | |
| 362 | + } else if (eOptID == DECODER_OPTION_STATISTICS_LOG_INTERVAL) { | |
| 363 | + if (pOption) { | |
| 364 | + m_pDecContext->sDecoderStatistics.iStatisticsLogInterval = (* ((unsigned int*)pOption)); | |
| 365 | + return cmResultSuccess; | |
| 366 | + } | |
| 367 | + } else if (eOptID == DECODER_OPTION_GET_SAR_INFO) { | |
| 368 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING, | |
| 369 | + "CWelsDecoder::SetOption():DECODER_OPTION_GET_SAR_INFO: this option is get-only!"); | |
| 370 | + return cmInitParaError; | |
| 371 | + } | |
| 372 | + return cmInitParaError; | |
| 373 | +} | |
| 374 | + | |
| 375 | +/* | |
| 376 | + * Get Option | |
| 377 | + */ | |
| 378 | +long CWelsDecoder::GetOption (DECODER_OPTION eOptID, void* pOption) { | |
| 379 | + int iVal = 0; | |
| 380 | + | |
| 381 | + if (m_pDecContext == NULL) | |
| 382 | + return cmInitExpected; | |
| 383 | + | |
| 384 | + if (pOption == NULL) | |
| 385 | + return cmInitParaError; | |
| 386 | + | |
| 387 | + if (DECODER_OPTION_END_OF_STREAM == eOptID) { | |
| 388 | + iVal = m_pDecContext->bEndOfStreamFlag; | |
| 389 | + * ((int*)pOption) = iVal; | |
| 390 | + return cmResultSuccess; | |
| 391 | + } | |
| 392 | +#ifdef LONG_TERM_REF | |
| 393 | + else if (DECODER_OPTION_IDR_PIC_ID == eOptID) { | |
| 394 | + iVal = m_pDecContext->uiCurIdrPicId; | |
| 395 | + * ((int*)pOption) = iVal; | |
| 396 | + return cmResultSuccess; | |
| 397 | + } else if (DECODER_OPTION_FRAME_NUM == eOptID) { | |
| 398 | + iVal = m_pDecContext->iFrameNum; | |
| 399 | + * ((int*)pOption) = iVal; | |
| 400 | + return cmResultSuccess; | |
| 401 | + } else if (DECODER_OPTION_LTR_MARKING_FLAG == eOptID) { | |
| 402 | + iVal = m_pDecContext->bCurAuContainLtrMarkSeFlag; | |
| 403 | + * ((int*)pOption) = iVal; | |
| 404 | + return cmResultSuccess; | |
| 405 | + } else if (DECODER_OPTION_LTR_MARKED_FRAME_NUM == eOptID) { | |
| 406 | + iVal = m_pDecContext->iFrameNumOfAuMarkedLtr; | |
| 407 | + * ((int*)pOption) = iVal; | |
| 408 | + return cmResultSuccess; | |
| 409 | + } | |
| 410 | +#endif | |
| 411 | + else if (DECODER_OPTION_VCL_NAL == eOptID) { //feedback whether or not have VCL NAL in current AU | |
| 412 | + iVal = m_pDecContext->iFeedbackVclNalInAu; | |
| 413 | + * ((int*)pOption) = iVal; | |
| 414 | + return cmResultSuccess; | |
| 415 | + } else if (DECODER_OPTION_TEMPORAL_ID == eOptID) { //if have VCL NAL in current AU, then feedback the temporal ID | |
| 416 | + iVal = m_pDecContext->iFeedbackTidInAu; | |
| 417 | + * ((int*)pOption) = iVal; | |
| 418 | + return cmResultSuccess; | |
| 419 | + } else if (DECODER_OPTION_IS_REF_PIC == eOptID) { | |
| 420 | + iVal = m_pDecContext->iFeedbackNalRefIdc; | |
| 421 | + if (iVal > 0) | |
| 422 | + iVal = 1; | |
| 423 | + * ((int*)pOption) = iVal; | |
| 424 | + return cmResultSuccess; | |
| 425 | + } else if (DECODER_OPTION_ERROR_CON_IDC == eOptID) { | |
| 426 | + iVal = (int)m_pDecContext->pParam->eEcActiveIdc; | |
| 427 | + * ((int*)pOption) = iVal; | |
| 428 | + return cmResultSuccess; | |
| 429 | + } else if (DECODER_OPTION_GET_STATISTICS == eOptID) { // get decoder statistics info for real time debugging | |
| 430 | + SDecoderStatistics* pDecoderStatistics = (static_cast<SDecoderStatistics*> (pOption)); | |
| 431 | + | |
| 432 | + memcpy (pDecoderStatistics, &m_pDecContext->sDecoderStatistics, sizeof (SDecoderStatistics)); | |
| 433 | + | |
| 434 | + if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount != 0) { //not original status | |
| 435 | + pDecoderStatistics->fAverageFrameSpeedInMs = (float) (m_pDecContext->dDecTime) / | |
| 436 | + (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount); | |
| 437 | + pDecoderStatistics->fActualAverageFrameSpeedInMs = (float) (m_pDecContext->dDecTime) / | |
| 438 | + (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount + m_pDecContext->sDecoderStatistics.uiFreezingIDRNum + | |
| 439 | + m_pDecContext->sDecoderStatistics.uiFreezingNonIDRNum); | |
| 440 | + } | |
| 441 | + return cmResultSuccess; | |
| 442 | + } else if (eOptID == DECODER_OPTION_STATISTICS_LOG_INTERVAL) { | |
| 443 | + if (pOption) { | |
| 444 | + iVal = m_pDecContext->sDecoderStatistics.iStatisticsLogInterval; | |
| 445 | + * ((unsigned int*)pOption) = iVal; | |
| 446 | + return cmResultSuccess; | |
| 447 | + } | |
| 448 | + } else if (DECODER_OPTION_GET_SAR_INFO == eOptID) { //get decoder SAR info in VUI | |
| 449 | + PVuiSarInfo pVuiSarInfo = (static_cast<PVuiSarInfo> (pOption)); | |
| 450 | + memset (pVuiSarInfo, 0, sizeof (SVuiSarInfo)); | |
| 451 | + if (!m_pDecContext->pSps) { | |
| 452 | + return cmInitExpected; | |
| 453 | + } else { | |
| 454 | + pVuiSarInfo->uiSarWidth = m_pDecContext->pSps->sVui.uiSarWidth; | |
| 455 | + pVuiSarInfo->uiSarHeight = m_pDecContext->pSps->sVui.uiSarHeight; | |
| 456 | + pVuiSarInfo->bOverscanAppropriateFlag = m_pDecContext->pSps->sVui.bOverscanAppropriateFlag; | |
| 457 | + return cmResultSuccess; | |
| 458 | + } | |
| 459 | + } else if (DECODER_OPTION_PROFILE == eOptID) { | |
| 460 | + if (!m_pDecContext->pSps) { | |
| 461 | + return cmInitExpected; | |
| 462 | + } | |
| 463 | + iVal = (int)m_pDecContext->pSps->uiProfileIdc; | |
| 464 | + * ((int*)pOption) = iVal; | |
| 465 | + return cmResultSuccess; | |
| 466 | + } else if (DECODER_OPTION_LEVEL == eOptID) { | |
| 467 | + if (!m_pDecContext->pSps) { | |
| 468 | + return cmInitExpected; | |
| 469 | + } | |
| 470 | + iVal = (int)m_pDecContext->pSps->uiLevelIdc; | |
| 471 | + * ((int*)pOption) = iVal; | |
| 472 | + return cmResultSuccess; | |
| 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) { | |
| 475 | + * ((int*)pOption) = m_iNumOfPicts > 0 ? m_iNumOfPicts : 0; | |
| 476 | + } | |
| 477 | + return cmResultSuccess; | |
| 478 | + } | |
| 479 | + | |
| 480 | + return cmInitParaError; | |
| 481 | +} | |
| 482 | + | |
| 483 | +DECODING_STATE CWelsDecoder::DecodeFrameNoDelay (const unsigned char* kpSrc, | |
| 484 | + const int kiSrcLen, | |
| 485 | + unsigned char** ppDst, | |
| 486 | + SBufferInfo* pDstInfo) { | |
| 487 | + int iRet; | |
| 488 | + //SBufferInfo sTmpBufferInfo; | |
| 489 | + //unsigned char* ppTmpDst[3] = {NULL, NULL, NULL}; | |
| 490 | + iRet = (int)DecodeFrame2 (kpSrc, kiSrcLen, ppDst, pDstInfo); | |
| 491 | + //memcpy (&sTmpBufferInfo, pDstInfo, sizeof (SBufferInfo)); | |
| 492 | + //ppTmpDst[0] = ppDst[0]; | |
| 493 | + //ppTmpDst[1] = ppDst[1]; | |
| 494 | + //ppTmpDst[2] = ppDst[2]; | |
| 495 | + iRet |= DecodeFrame2 (NULL, 0, ppDst, pDstInfo); | |
| 496 | + //if ((pDstInfo->iBufferStatus == 0) && (sTmpBufferInfo.iBufferStatus == 1)) { | |
| 497 | + //memcpy (pDstInfo, &sTmpBufferInfo, sizeof (SBufferInfo)); | |
| 498 | + //ppDst[0] = ppTmpDst[0]; | |
| 499 | + //ppDst[1] = ppTmpDst[1]; | |
| 500 | + //ppDst[2] = ppTmpDst[2]; | |
| 501 | + //} | |
| 502 | + return (DECODING_STATE)iRet; | |
| 503 | +} | |
| 504 | + | |
| 505 | +DECODING_STATE CWelsDecoder::DecodeFrame2 (const unsigned char* kpSrc, | |
| 506 | + const int kiSrcLen, | |
| 507 | + unsigned char** ppDst, | |
| 508 | + SBufferInfo* pDstInfo) { | |
| 509 | + if (m_pDecContext == NULL || m_pDecContext->pParam == NULL) { | |
| 510 | + if (m_pWelsTrace != NULL) { | |
| 511 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "Call DecodeFrame2 without Initialize.\n"); | |
| 512 | + } | |
| 513 | + return dsInitialOptExpected; | |
| 514 | + } | |
| 515 | + | |
| 516 | + if (m_pDecContext->pParam->bParseOnly) { | |
| 517 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "bParseOnly should be false for this API calling! \n"); | |
| 518 | + m_pDecContext->iErrorCode |= dsInvalidArgument; | |
| 519 | + return dsInvalidArgument; | |
| 520 | + } | |
| 521 | + if (CheckBsBuffer (m_pDecContext, kiSrcLen)) { | |
| 522 | + if (ResetDecoder()) | |
| 523 | + return dsOutOfMemory; | |
| 524 | + | |
| 525 | + return dsErrorFree; | |
| 526 | + } | |
| 527 | + if (kiSrcLen > 0 && kpSrc != NULL) { | |
| 528 | +#ifdef OUTPUT_BIT_STREAM | |
| 529 | + if (m_pFBS) { | |
| 530 | + WelsFwrite (kpSrc, sizeof (unsigned char), kiSrcLen, m_pFBS); | |
| 531 | + WelsFflush (m_pFBS); | |
| 532 | + } | |
| 533 | + if (m_pFBSSize) { | |
| 534 | + WelsFwrite (&kiSrcLen, sizeof (int), 1, m_pFBSSize); | |
| 535 | + WelsFflush (m_pFBSSize); | |
| 536 | + } | |
| 537 | +#endif//OUTPUT_BIT_STREAM | |
| 538 | + m_pDecContext->bEndOfStreamFlag = false; | |
| 539 | + } else { | |
| 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. | |
| 542 | + m_pDecContext->bEndOfStreamFlag = true; | |
| 543 | + m_pDecContext->bInstantDecFlag = true; | |
| 544 | + } | |
| 545 | + | |
| 546 | + int64_t iStart, iEnd; | |
| 547 | + iStart = WelsTime(); | |
| 548 | + | |
| 549 | + ppDst[0] = ppDst[1] = ppDst[2] = NULL; | |
| 550 | + m_pDecContext->iErrorCode = dsErrorFree; //initialize at the starting of AU decoding. | |
| 551 | + m_pDecContext->iFeedbackVclNalInAu = FEEDBACK_UNKNOWN_NAL; //initialize | |
| 552 | + unsigned long long uiInBsTimeStamp = pDstInfo->uiInBsTimeStamp; | |
| 553 | + memset (pDstInfo, 0, sizeof (SBufferInfo)); | |
| 554 | + pDstInfo->uiInBsTimeStamp = uiInBsTimeStamp; | |
| 555 | +#ifdef LONG_TERM_REF | |
| 556 | + m_pDecContext->bReferenceLostAtT0Flag = false; //initialize for LTR | |
| 557 | + m_pDecContext->bCurAuContainLtrMarkSeFlag = false; | |
| 558 | + m_pDecContext->iFrameNumOfAuMarkedLtr = 0; | |
| 559 | + m_pDecContext->iFrameNum = -1; //initialize | |
| 560 | +#endif | |
| 561 | + | |
| 562 | + m_pDecContext->iFeedbackTidInAu = -1; //initialize | |
| 563 | + m_pDecContext->iFeedbackNalRefIdc = -1; //initialize | |
| 564 | + if (pDstInfo) { | |
| 565 | + pDstInfo->uiOutYuvTimeStamp = 0; | |
| 566 | + m_pDecContext->uiTimeStamp = pDstInfo->uiInBsTimeStamp; | |
| 567 | + } else { | |
| 568 | + m_pDecContext->uiTimeStamp = 0; | |
| 569 | + } | |
| 570 | + WelsDecodeBs (m_pDecContext, kpSrc, kiSrcLen, ppDst, | |
| 571 | + pDstInfo, NULL); //iErrorCode has been modified in this function | |
| 572 | + m_pDecContext->bInstantDecFlag = false; //reset no-delay flag | |
| 573 | + if (m_pDecContext->iErrorCode) { | |
| 574 | + EWelsNalUnitType eNalType = | |
| 575 | + NAL_UNIT_UNSPEC_0; //for NBR, IDR frames are expected to decode as followed if error decoding an IDR currently | |
| 576 | + | |
| 577 | + eNalType = m_pDecContext->sCurNalHead.eNalUnitType; | |
| 578 | + | |
| 579 | + if (m_pDecContext->iErrorCode & dsOutOfMemory) { | |
| 580 | + if (ResetDecoder()) | |
| 581 | + return dsOutOfMemory; | |
| 582 | + | |
| 583 | + return dsErrorFree; | |
| 584 | + } | |
| 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) || | |
| 587 | + (VIDEO_BITSTREAM_AVC == m_pDecContext->eVideoType)) { | |
| 588 | + if (m_pDecContext->pParam->eEcActiveIdc == ERROR_CON_DISABLE) { | |
| 589 | +#ifdef LONG_TERM_REF | |
| 590 | + m_pDecContext->bParamSetsLostFlag = true; | |
| 591 | +#else | |
| 592 | + m_pDecContext->bReferenceLostAtT0Flag = true; | |
| 593 | +#endif | |
| 594 | + } | |
| 595 | + } | |
| 596 | + | |
| 597 | + if (m_pDecContext->bPrintFrameErrorTraceFlag) { | |
| 598 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "decode failed, failure type:%d \n", | |
| 599 | + m_pDecContext->iErrorCode); | |
| 600 | + m_pDecContext->bPrintFrameErrorTraceFlag = false; | |
| 601 | + } else { | |
| 602 | + m_pDecContext->iIgnoredErrorInfoPacketCount++; | |
| 603 | + if (m_pDecContext->iIgnoredErrorInfoPacketCount == INT_MAX) { | |
| 604 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING, "continuous error reached INT_MAX! Restart as 0."); | |
| 605 | + m_pDecContext->iIgnoredErrorInfoPacketCount = 0; | |
| 606 | + } | |
| 607 | + } | |
| 608 | + if ((m_pDecContext->pParam->eEcActiveIdc != ERROR_CON_DISABLE) && (pDstInfo->iBufferStatus == 1)) { | |
| 609 | + //TODO after dec status updated | |
| 610 | + m_pDecContext->iErrorCode |= dsDataErrorConcealed; | |
| 611 | + | |
| 612 | + m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++; | |
| 613 | + if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount == 0) { //exceed max value of uint32_t | |
| 614 | + ResetDecStatNums (&m_pDecContext->sDecoderStatistics); | |
| 615 | + m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++; | |
| 616 | + } | |
| 617 | + int32_t iMbConcealedNum = m_pDecContext->iMbEcedNum + m_pDecContext->iMbEcedPropNum; | |
| 618 | + m_pDecContext->sDecoderStatistics.uiAvgEcRatio = m_pDecContext->iMbNum == 0 ? | |
| 619 | + (m_pDecContext->sDecoderStatistics.uiAvgEcRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) : (( | |
| 620 | + m_pDecContext->sDecoderStatistics.uiAvgEcRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) + (( | |
| 621 | + iMbConcealedNum * 100) / m_pDecContext->iMbNum)); | |
| 622 | + m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio = m_pDecContext->iMbNum == 0 ? | |
| 623 | + (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)); | |
| 626 | + m_pDecContext->sDecoderStatistics.uiEcFrameNum += (iMbConcealedNum == 0 ? 0 : 1); | |
| 627 | + m_pDecContext->sDecoderStatistics.uiAvgEcRatio = m_pDecContext->sDecoderStatistics.uiEcFrameNum == 0 ? 0 : | |
| 628 | + m_pDecContext->sDecoderStatistics.uiAvgEcRatio / m_pDecContext->sDecoderStatistics.uiEcFrameNum; | |
| 629 | + m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio = m_pDecContext->sDecoderStatistics.uiEcFrameNum == 0 ? 0 : | |
| 630 | + m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio / m_pDecContext->sDecoderStatistics.uiEcFrameNum; | |
| 631 | + } | |
| 632 | + iEnd = WelsTime(); | |
| 633 | + m_pDecContext->dDecTime += (iEnd - iStart) / 1e3; | |
| 634 | + | |
| 635 | + OutputStatisticsLog (m_pDecContext->sDecoderStatistics); | |
| 636 | + | |
| 637 | +#ifdef _PICTURE_REORDERING_ | |
| 638 | + ReorderPicturesInDisplay (ppDst, pDstInfo); | |
| 639 | +#endif | |
| 640 | + | |
| 641 | + return (DECODING_STATE)m_pDecContext->iErrorCode; | |
| 642 | + } | |
| 643 | + // else Error free, the current codec works well | |
| 644 | + | |
| 645 | + if (pDstInfo->iBufferStatus == 1) { | |
| 646 | + | |
| 647 | + m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++; | |
| 648 | + if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount == 0) { //exceed max value of uint32_t | |
| 649 | + ResetDecStatNums (&m_pDecContext->sDecoderStatistics); | |
| 650 | + m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++; | |
| 651 | + } | |
| 652 | + | |
| 653 | + OutputStatisticsLog (m_pDecContext->sDecoderStatistics); | |
| 654 | + } | |
| 655 | + iEnd = WelsTime(); | |
| 656 | + m_pDecContext->dDecTime += (iEnd - iStart) / 1e3; | |
| 657 | + | |
| 658 | +#ifdef _PICTURE_REORDERING_ | |
| 659 | + ReorderPicturesInDisplay (ppDst, pDstInfo); | |
| 660 | +#endif | |
| 661 | + return dsErrorFree; | |
| 662 | +} | |
| 663 | + | |
| 664 | +DECODING_STATE CWelsDecoder::FlushFrame (unsigned char** ppDst, | |
| 665 | + SBufferInfo* pDstInfo) { | |
| 666 | + if (m_pDecContext->bEndOfStreamFlag && m_iNumOfPicts > 0) { | |
| 667 | + m_iMinPOC = sIMinInt32; | |
| 668 | + for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) { | |
| 669 | + if (m_iMinPOC == sIMinInt32 && m_sPictInfoList[i].iPOC > sIMinInt32) { | |
| 670 | + m_iMinPOC = m_sPictInfoList[i].iPOC; | |
| 671 | + m_iPictInfoIndex = i; | |
| 672 | + } | |
| 673 | + if (m_sPictInfoList[i].iPOC > sIMinInt32 && m_sPictInfoList[i].iPOC < m_iMinPOC) { | |
| 674 | + m_iMinPOC = m_sPictInfoList[i].iPOC; | |
| 675 | + m_iPictInfoIndex = i; | |
| 676 | + } | |
| 677 | + } | |
| 678 | + } | |
| 679 | + if (m_iMinPOC > sIMinInt32) { | |
| 680 | + m_LastWrittenPOC = m_iMinPOC; | |
| 681 | +#if defined (_DEBUG) | |
| 682 | +#ifdef _MOTION_VECTOR_DUMP_ | |
| 683 | + fprintf (stderr, "Output POC: #%d\n", m_LastWrittenPOC); | |
| 684 | +#endif | |
| 685 | +#endif | |
| 686 | + memcpy (pDstInfo, &m_sPictInfoList[m_iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo)); | |
| 687 | + ppDst[0] = m_sPictInfoList[m_iPictInfoIndex].pData[0]; | |
| 688 | + ppDst[1] = m_sPictInfoList[m_iPictInfoIndex].pData[1]; | |
| 689 | + ppDst[2] = m_sPictInfoList[m_iPictInfoIndex].pData[2]; | |
| 690 | + m_sPictInfoList[m_iPictInfoIndex].iPOC = sIMinInt32; | |
| 691 | + m_sPictInfoList[m_iPictInfoIndex].bLastGOP = false; | |
| 692 | + m_iMinPOC = sIMinInt32; | |
| 693 | + --m_iNumOfPicts; | |
| 694 | + } | |
| 695 | + return dsErrorFree; | |
| 696 | +} | |
| 697 | + | |
| 698 | +void CWelsDecoder::OutputStatisticsLog (SDecoderStatistics& sDecoderStatistics) { | |
| 699 | + if ((sDecoderStatistics.uiDecodedFrameCount > 0) && (sDecoderStatistics.iStatisticsLogInterval > 0) | |
| 700 | + && ((sDecoderStatistics.uiDecodedFrameCount % sDecoderStatistics.iStatisticsLogInterval) == 0)) { | |
| 701 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, | |
| 702 | + "DecoderStatistics: uiWidth=%d, uiHeight=%d, fAverageFrameSpeedInMs=%.1f, fActualAverageFrameSpeedInMs=%.1f, \ | |
| 703 | + uiDecodedFrameCount=%d, uiResolutionChangeTimes=%d, uiIDRCorrectNum=%d, \ | |
| 704 | + uiAvgEcRatio=%d, uiAvgEcPropRatio=%d, uiEcIDRNum=%d, uiEcFrameNum=%d, \ | |
| 705 | + uiIDRLostNum=%d, uiFreezingIDRNum=%d, uiFreezingNonIDRNum=%d, iAvgLumaQp=%d, \ | |
| 706 | + iSpsReportErrorNum=%d, iSubSpsReportErrorNum=%d, iPpsReportErrorNum=%d, iSpsNoExistNalNum=%d, iSubSpsNoExistNalNum=%d, iPpsNoExistNalNum=%d, \ | |
| 707 | + uiProfile=%d, uiLevel=%d, \ | |
| 708 | + iCurrentActiveSpsId=%d, iCurrentActivePpsId=%d,", | |
| 709 | + sDecoderStatistics.uiWidth, | |
| 710 | + sDecoderStatistics.uiHeight, | |
| 711 | + sDecoderStatistics.fAverageFrameSpeedInMs, | |
| 712 | + sDecoderStatistics.fActualAverageFrameSpeedInMs, | |
| 713 | + | |
| 714 | + sDecoderStatistics.uiDecodedFrameCount, | |
| 715 | + sDecoderStatistics.uiResolutionChangeTimes, | |
| 716 | + sDecoderStatistics.uiIDRCorrectNum, | |
| 717 | + | |
| 718 | + sDecoderStatistics.uiAvgEcRatio, | |
| 719 | + sDecoderStatistics.uiAvgEcPropRatio, | |
| 720 | + sDecoderStatistics.uiEcIDRNum, | |
| 721 | + sDecoderStatistics.uiEcFrameNum, | |
| 722 | + | |
| 723 | + sDecoderStatistics.uiIDRLostNum, | |
| 724 | + sDecoderStatistics.uiFreezingIDRNum, | |
| 725 | + sDecoderStatistics.uiFreezingNonIDRNum, | |
| 726 | + sDecoderStatistics.iAvgLumaQp, | |
| 727 | + | |
| 728 | + sDecoderStatistics.iSpsReportErrorNum, | |
| 729 | + sDecoderStatistics.iSubSpsReportErrorNum, | |
| 730 | + sDecoderStatistics.iPpsReportErrorNum, | |
| 731 | + sDecoderStatistics.iSpsNoExistNalNum, | |
| 732 | + sDecoderStatistics.iSubSpsNoExistNalNum, | |
| 733 | + sDecoderStatistics.iPpsNoExistNalNum, | |
| 734 | + | |
| 735 | + sDecoderStatistics.uiProfile, | |
| 736 | + sDecoderStatistics.uiLevel, | |
| 737 | + | |
| 738 | + sDecoderStatistics.iCurrentActiveSpsId, | |
| 739 | + sDecoderStatistics.iCurrentActivePpsId); | |
| 740 | + } | |
| 741 | +} | |
| 742 | + | |
| 743 | +DECODING_STATE CWelsDecoder::ReorderPicturesInDisplay (unsigned char** ppDst, SBufferInfo* pDstInfo) { | |
| 744 | + if (pDstInfo->iBufferStatus == 1 && m_pDecContext->pSps->uiProfileIdc != 66 | |
| 745 | + && m_pDecContext->pPps->bEntropyCodingModeFlag) { | |
| 746 | + if (m_pDecContext->pSliceHeader->iPicOrderCntLsb == 0) { | |
| 747 | + if (m_iNumOfPicts > 0) { | |
| 748 | + m_iLastGOPRemainPicts = m_iNumOfPicts; | |
| 749 | + for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) { | |
| 750 | + if (m_sPictInfoList[i].iPOC > sIMinInt32) { | |
| 751 | + m_sPictInfoList[i].bLastGOP = true; | |
| 752 | + } | |
| 753 | + } | |
| 754 | + } | |
| 755 | + } | |
| 756 | + for (int32_t i = 0; i < 16; ++i) { | |
| 757 | + if (m_sPictInfoList[i].iPOC == sIMinInt32) { | |
| 758 | + memcpy (&m_sPictInfoList[i].sBufferInfo, pDstInfo, sizeof (SBufferInfo)); | |
| 759 | + m_sPictInfoList[i].pData[0] = ppDst[0]; | |
| 760 | + m_sPictInfoList[i].pData[1] = ppDst[1]; | |
| 761 | + m_sPictInfoList[i].pData[2] = ppDst[2]; | |
| 762 | + m_sPictInfoList[i].iPOC = m_pDecContext->pSliceHeader->iPicOrderCntLsb; | |
| 763 | + m_sPictInfoList[i].iFrameNum = m_pDecContext->pSliceHeader->iFrameNum; | |
| 764 | + m_sPictInfoList[i].bLastGOP = false; | |
| 765 | + pDstInfo->iBufferStatus = 0; | |
| 766 | + ++m_iNumOfPicts; | |
| 767 | + if (i > m_iLargestBufferedPicIndex) { | |
| 768 | + m_iLargestBufferedPicIndex = i; | |
| 769 | + } | |
| 770 | + break; | |
| 771 | + } | |
| 772 | + } | |
| 773 | + if (m_iLastGOPRemainPicts > 0) { | |
| 774 | + m_iMinPOC = sIMinInt32; | |
| 775 | + for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) { | |
| 776 | + if (m_iMinPOC == sIMinInt32 && m_sPictInfoList[i].iPOC > sIMinInt32 && m_sPictInfoList[i].bLastGOP) { | |
| 777 | + m_iMinPOC = m_sPictInfoList[i].iPOC; | |
| 778 | + m_iPictInfoIndex = i; | |
| 779 | + } | |
| 780 | + if (m_sPictInfoList[i].iPOC > sIMinInt32 && m_sPictInfoList[i].iPOC < m_iMinPOC && m_sPictInfoList[i].bLastGOP) { | |
| 781 | + m_iMinPOC = m_sPictInfoList[i].iPOC; | |
| 782 | + m_iPictInfoIndex = i; | |
| 783 | + } | |
| 784 | + } | |
| 785 | + m_LastWrittenPOC = m_iMinPOC; | |
| 786 | +#if defined (_DEBUG) | |
| 787 | +#ifdef _MOTION_VECTOR_DUMP_ | |
| 788 | + fprintf (stderr, "Output POC: #%d\n", m_LastWrittenPOC); | |
| 789 | +#endif | |
| 790 | +#endif | |
| 791 | + memcpy (pDstInfo, &m_sPictInfoList[m_iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo)); | |
| 792 | + ppDst[0] = m_sPictInfoList[m_iPictInfoIndex].pData[0]; | |
| 793 | + ppDst[1] = m_sPictInfoList[m_iPictInfoIndex].pData[1]; | |
| 794 | + ppDst[2] = m_sPictInfoList[m_iPictInfoIndex].pData[2]; | |
| 795 | + m_sPictInfoList[m_iPictInfoIndex].iPOC = sIMinInt32; | |
| 796 | + m_sPictInfoList[m_iPictInfoIndex].bLastGOP = false; | |
| 797 | + m_iMinPOC = sIMinInt32; | |
| 798 | + --m_iNumOfPicts; | |
| 799 | + --m_iLastGOPRemainPicts; | |
| 800 | + if (m_iLastGOPRemainPicts == 0) { | |
| 801 | + m_LastWrittenPOC = sIMinInt32; | |
| 802 | + } | |
| 803 | + return dsErrorFree; | |
| 804 | + } | |
| 805 | + if (m_iNumOfPicts > 0) { | |
| 806 | + m_iMinPOC = sIMinInt32; | |
| 807 | + for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) { | |
| 808 | + if (m_iMinPOC == sIMinInt32 && m_sPictInfoList[i].iPOC > sIMinInt32) { | |
| 809 | + m_iMinPOC = m_sPictInfoList[i].iPOC; | |
| 810 | + m_iPictInfoIndex = i; | |
| 811 | + } | |
| 812 | + if (m_sPictInfoList[i].iPOC > sIMinInt32 && m_sPictInfoList[i].iPOC < m_iMinPOC) { | |
| 813 | + m_iMinPOC = m_sPictInfoList[i].iPOC; | |
| 814 | + m_iPictInfoIndex = i; | |
| 815 | + } | |
| 816 | + } | |
| 817 | + } | |
| 818 | + if (m_iMinPOC > sIMinInt32) { | |
| 819 | + if ((m_LastWrittenPOC > sIMinInt32 && m_iMinPOC - m_LastWrittenPOC <= 1) | |
| 820 | + || m_iMinPOC < m_pDecContext->pSliceHeader->iPicOrderCntLsb) { | |
| 821 | + m_LastWrittenPOC = m_iMinPOC; | |
| 822 | +#if defined (_DEBUG) | |
| 823 | +#ifdef _MOTION_VECTOR_DUMP_ | |
| 824 | + fprintf (stderr, "Output POC: #%d\n", m_LastWrittenPOC); | |
| 825 | +#endif | |
| 826 | +#endif | |
| 827 | + memcpy (pDstInfo, &m_sPictInfoList[m_iPictInfoIndex].sBufferInfo, sizeof (SBufferInfo)); | |
| 828 | + ppDst[0] = m_sPictInfoList[m_iPictInfoIndex].pData[0]; | |
| 829 | + ppDst[1] = m_sPictInfoList[m_iPictInfoIndex].pData[1]; | |
| 830 | + ppDst[2] = m_sPictInfoList[m_iPictInfoIndex].pData[2]; | |
| 831 | + m_sPictInfoList[m_iPictInfoIndex].iPOC = sIMinInt32; | |
| 832 | + m_sPictInfoList[m_iPictInfoIndex].bLastGOP = false; | |
| 833 | + m_iMinPOC = sIMinInt32; | |
| 834 | + --m_iNumOfPicts; | |
| 835 | + return dsErrorFree; | |
| 836 | + } | |
| 837 | + } | |
| 838 | + } | |
| 839 | + | |
| 840 | + return dsErrorFree; | |
| 841 | +} | |
| 842 | + | |
| 843 | +DECODING_STATE CWelsDecoder::DecodeParser (const unsigned char* kpSrc, | |
| 844 | + const int kiSrcLen, | |
| 845 | + SParserBsInfo* pDstInfo) { | |
| 846 | + if (m_pDecContext == NULL || m_pDecContext->pParam == NULL) { | |
| 847 | + if (m_pWelsTrace != NULL) { | |
| 848 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "Call DecodeParser without Initialize.\n"); | |
| 849 | + } | |
| 850 | + return dsInitialOptExpected; | |
| 851 | + } | |
| 852 | + | |
| 853 | + if (!m_pDecContext->pParam->bParseOnly) { | |
| 854 | + WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "bParseOnly should be true for this API calling! \n"); | |
| 855 | + m_pDecContext->iErrorCode |= dsInvalidArgument; | |
| 856 | + return dsInvalidArgument; | |
| 857 | + } | |
| 858 | + int64_t iEnd, iStart = WelsTime(); | |
| 859 | + if (CheckBsBuffer (m_pDecContext, kiSrcLen)) { | |
| 860 | + if (ResetDecoder()) | |
| 861 | + return dsOutOfMemory; | |
| 862 | + | |
| 863 | + return dsErrorFree; | |
| 864 | + } | |
| 865 | + if (kiSrcLen > 0 && kpSrc != NULL) { | |
| 866 | +#ifdef OUTPUT_BITSTREAM | |
| 867 | + if (m_pFBS) { | |
| 868 | + WelsFwrite (kpSrc, sizeof (unsigned char), kiSrcLen, m_pFBS); | |
| 869 | + WelsFflush (m_pFBS); | |
| 870 | + } | |
| 871 | +#endif//OUTPUT_BIT_STREAM | |
| 872 | + m_pDecContext->bEndOfStreamFlag = false; | |
| 873 | + } else { | |
| 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. | |
| 876 | + m_pDecContext->bEndOfStreamFlag = true; | |
| 877 | + m_pDecContext->bInstantDecFlag = true; | |
| 878 | + } | |
| 879 | + | |
| 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. | |
| 882 | + m_pDecContext->iFeedbackNalRefIdc = -1; //initialize | |
| 883 | + if (!m_pDecContext->bFramePending) { //frame complete | |
| 884 | + m_pDecContext->pParserBsInfo->iNalNum = 0; | |
| 885 | + memset (m_pDecContext->pParserBsInfo->pNalLenInByte, 0, MAX_NAL_UNITS_IN_LAYER); | |
| 886 | + } | |
| 887 | + pDstInfo->iNalNum = 0; | |
| 888 | + pDstInfo->iSpsWidthInPixel = pDstInfo->iSpsHeightInPixel = 0; | |
| 889 | + if (pDstInfo) { | |
| 890 | + m_pDecContext->uiTimeStamp = pDstInfo->uiInBsTimeStamp; | |
| 891 | + pDstInfo->uiOutBsTimeStamp = 0; | |
| 892 | + } else { | |
| 893 | + m_pDecContext->uiTimeStamp = 0; | |
| 894 | + } | |
| 895 | + WelsDecodeBs (m_pDecContext, kpSrc, kiSrcLen, NULL, NULL, pDstInfo); | |
| 896 | + if (m_pDecContext->iErrorCode & dsOutOfMemory) { | |
| 897 | + if (ResetDecoder()) | |
| 898 | + return dsOutOfMemory; | |
| 899 | + return dsErrorFree; | |
| 900 | + } | |
| 901 | + | |
| 902 | + if (!m_pDecContext->bFramePending && m_pDecContext->pParserBsInfo->iNalNum) { | |
| 903 | + memcpy (pDstInfo, m_pDecContext->pParserBsInfo, sizeof (SParserBsInfo)); | |
| 904 | + | |
| 905 | + if (m_pDecContext->iErrorCode == ERR_NONE) { //update statistics: decoding frame count | |
| 906 | + m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++; | |
| 907 | + if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount == 0) { //exceed max value of uint32_t | |
| 908 | + ResetDecStatNums (&m_pDecContext->sDecoderStatistics); | |
| 909 | + m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++; | |
| 910 | + } | |
| 911 | + } | |
| 912 | + } | |
| 913 | + | |
| 914 | + m_pDecContext->bInstantDecFlag = false; //reset no-delay flag | |
| 915 | + | |
| 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); | |
| 918 | + m_pDecContext->bPrintFrameErrorTraceFlag = false; | |
| 919 | + } | |
| 920 | + iEnd = WelsTime(); | |
| 921 | + m_pDecContext->dDecTime += (iEnd - iStart) / 1e3; | |
| 922 | + | |
| 923 | + return (DECODING_STATE) m_pDecContext->iErrorCode; | |
| 924 | +} | |
| 925 | + | |
| 926 | +DECODING_STATE CWelsDecoder::DecodeFrame (const unsigned char* kpSrc, | |
| 927 | + const int kiSrcLen, | |
| 928 | + unsigned char** ppDst, | |
| 929 | + int* pStride, | |
| 930 | + int& iWidth, | |
| 931 | + int& iHeight) { | |
| 932 | + DECODING_STATE eDecState = dsErrorFree; | |
| 933 | + SBufferInfo DstInfo; | |
| 934 | + | |
| 935 | + memset (&DstInfo, 0, sizeof (SBufferInfo)); | |
| 936 | + DstInfo.UsrData.sSystemBuffer.iStride[0] = pStride[0]; | |
| 937 | + DstInfo.UsrData.sSystemBuffer.iStride[1] = pStride[1]; | |
| 938 | + DstInfo.UsrData.sSystemBuffer.iWidth = iWidth; | |
| 939 | + DstInfo.UsrData.sSystemBuffer.iHeight = iHeight; | |
| 940 | + | |
| 941 | + eDecState = DecodeFrame2 (kpSrc, kiSrcLen, ppDst, &DstInfo); | |
| 942 | + if (eDecState == dsErrorFree) { | |
| 943 | + pStride[0] = DstInfo.UsrData.sSystemBuffer.iStride[0]; | |
| 944 | + pStride[1] = DstInfo.UsrData.sSystemBuffer.iStride[1]; | |
| 945 | + iWidth = DstInfo.UsrData.sSystemBuffer.iWidth; | |
| 946 | + iHeight = DstInfo.UsrData.sSystemBuffer.iHeight; | |
| 947 | + } | |
| 948 | + | |
| 949 | + return eDecState; | |
| 950 | +} | |
| 951 | + | |
| 952 | +DECODING_STATE CWelsDecoder::DecodeFrameEx (const unsigned char* kpSrc, | |
| 953 | + const int kiSrcLen, | |
| 954 | + unsigned char* pDst, | |
| 955 | + int iDstStride, | |
| 956 | + int& iDstLen, | |
| 957 | + int& iWidth, | |
| 958 | + int& iHeight, | |
| 959 | + int& iColorFormat) { | |
| 960 | + DECODING_STATE state = dsErrorFree; | |
| 961 | + | |
| 962 | + return state; | |
| 963 | +} | |
| 964 | + | |
| 965 | + | |
| 966 | +} // namespace WelsDec | |
| 967 | + | |
| 968 | + | |
| 969 | +using namespace WelsDec; | |
| 970 | +/* | |
| 971 | +* WelsGetDecoderCapability | |
| 972 | +* @return: DecCapability information | |
| 973 | +*/ | |
| 974 | +int WelsGetDecoderCapability (SDecoderCapability* pDecCapability) { | |
| 975 | + memset (pDecCapability, 0, sizeof (SDecoderCapability)); | |
| 976 | + pDecCapability->iProfileIdc = 66; //Baseline | |
| 977 | + pDecCapability->iProfileIop = 0xE0; //11100000b | |
| 978 | + pDecCapability->iLevelIdc = 32; //level_idc = 3.2 | |
| 979 | + pDecCapability->iMaxMbps = 216000; //from level_idc = 3.2 | |
| 980 | + pDecCapability->iMaxFs = 5120; //from level_idc = 3.2 | |
| 981 | + pDecCapability->iMaxCpb = 20000; //from level_idc = 3.2 | |
| 982 | + pDecCapability->iMaxDpb = 20480; //from level_idc = 3.2 | |
| 983 | + pDecCapability->iMaxBr = 20000; //from level_idc = 3.2 | |
| 984 | + pDecCapability->bRedPicCap = 0; //not support redundant pic | |
| 985 | + | |
| 986 | + return ERR_NONE; | |
| 987 | +} | |
| 988 | +/* WINAPI is indeed in prefix due to sync to application layer callings!! */ | |
| 989 | + | |
| 990 | +/* | |
| 991 | +* WelsCreateDecoder | |
| 992 | +* @return: success in return 0, otherwise failed. | |
| 993 | +*/ | |
| 994 | +long WelsCreateDecoder (ISVCDecoder** ppDecoder) { | |
| 995 | + | |
| 996 | + if (NULL == ppDecoder) { | |
| 997 | + return ERR_INVALID_PARAMETERS; | |
| 998 | + } | |
| 999 | + | |
| 1000 | + *ppDecoder = new CWelsDecoder(); | |
| 1001 | + | |
| 1002 | + if (NULL == *ppDecoder) { | |
| 1003 | + return ERR_MALLOC_FAILED; | |
| 1004 | + } | |
| 1005 | + | |
| 1006 | + return ERR_NONE; | |
| 1007 | +} | |
| 1008 | + | |
| 1009 | +/* | |
| 1010 | +* WelsDestroyDecoder | |
| 1011 | +*/ | |
| 1012 | +void WelsDestroyDecoder (ISVCDecoder* pDecoder) { | |
| 1013 | + if (NULL != pDecoder) { | |
| 1014 | + delete (CWelsDecoder*)pDecoder; | |
| 1015 | + } | |
| 1016 | +} | |