Showing the changes to codec/decoder/core/src/decode_slice.cpp (1 of 4 files). Show all
Unified · Split
| @@ -1,2402 +1,2402 @@ | |||
| 1 | /*! | 1 | /*! |
| 2 | * \copy | 2 | * \copy |
| 3 | * Copyright (c) 2008-2013, Cisco Systems | 3 | * Copyright (c) 2008-2013, Cisco Systems |
| 4 | * All rights reserved. | 4 | * All rights reserved. |
| 5 | * | 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: | 8 | * are met: |
| 9 | * | 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright | 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * | 12 | * |
| 13 | * * Redistributions in binary form must reproduce the above copyright | 13 | * * Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in | 14 | * notice, this list of conditions and the following disclaimer in |
| 15 | * the documentation and/or other materials provided with the | 15 | * the documentation and/or other materials provided with the |
| 16 | * distribution. | 16 | * distribution. |
| 17 | * | 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 22 | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | 22 | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | 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 | 28 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. |
| 30 | * | 30 | * |
| 31 | * | 31 | * |
| 32 | * Abstract | 32 | * Abstract |
| 33 | * current slice decoding | 33 | * current slice decoding |
| 34 | * | 34 | * |
| 35 | * History | 35 | * History |
| 36 | * 07/10/2008 Created | 36 | * 07/10/2008 Created |
| 37 | * 08/09/2013 Modified | 37 | * 08/09/2013 Modified |
| 38 | * | 38 | * |
| 39 | *****************************************************************************/ | 39 | *****************************************************************************/ |
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | #include "deblocking.h" | 42 | #include "deblocking.h" |
| 43 | 43 | ||
| 44 | #include "decode_slice.h" | 44 | #include "decode_slice.h" |
| 45 | 45 | ||
| 46 | #include "parse_mb_syn_cavlc.h" | 46 | #include "parse_mb_syn_cavlc.h" |
| 47 | #include "parse_mb_syn_cabac.h" | 47 | #include "parse_mb_syn_cabac.h" |
| 48 | #include "rec_mb.h" | 48 | #include "rec_mb.h" |
| 49 | #include "mv_pred.h" | 49 | #include "mv_pred.h" |
| 50 | 50 | ||
| 51 | #include "cpu_core.h" | 51 | #include "cpu_core.h" |
| 52 | 52 | ||
| 53 | namespace WelsDec { | 53 | namespace WelsDec { |
| 54 | 54 | ||
| 55 | static inline int32_t iAbs (int32_t x) { | 55 | static inline int32_t iAbs (int32_t x) { |
| 56 | static const int32_t INT_BITS = (sizeof (int) * CHAR_BIT) - 1; | 56 | static const int32_t INT_BITS = (sizeof (int) * CHAR_BIT) - 1; |
| 57 | int32_t y = x >> INT_BITS; | 57 | int32_t y = x >> INT_BITS; |
| 58 | return (x ^ y) - y; | 58 | return (x ^ y) - y; |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | extern PPicture AllocPicture (PWelsDecoderContext pCtx, const int32_t kiPicWidth, const int32_t kiPicHeight); | 61 | extern PPicture AllocPicture (PWelsDecoderContext pCtx, const int32_t kiPicWidth, const int32_t kiPicHeight); |
| 62 | 62 | ||
| 63 | int32_t WelsTargetSliceConstruction (PWelsDecoderContext pCtx) { | 63 | int32_t WelsTargetSliceConstruction (PWelsDecoderContext pCtx) { |
| 64 | PDqLayer pCurLayer = pCtx->pCurDqLayer; | 64 | PDqLayer pCurLayer = pCtx->pCurDqLayer; |
| 65 | PSlice pCurSlice = &pCurLayer->sLayerInfo.sSliceInLayer; | 65 | PSlice pCurSlice = &pCurLayer->sLayerInfo.sSliceInLayer; |
| 66 | PSliceHeader pSliceHeader = &pCurSlice->sSliceHeaderExt.sSliceHeader; | 66 | PSliceHeader pSliceHeader = &pCurSlice->sSliceHeaderExt.sSliceHeader; |
| 67 | 67 | ||
| 68 | int32_t iTotalMbTargetLayer = pSliceHeader->pSps->uiTotalMbCount; | 68 | int32_t iTotalMbTargetLayer = pSliceHeader->pSps->uiTotalMbCount; |
| 69 | 69 | ||
| 70 | int32_t iCurLayerWidth = pCurLayer->iMbWidth << 4; | 70 | int32_t iCurLayerWidth = pCurLayer->iMbWidth << 4; |
| 71 | int32_t iCurLayerHeight = pCurLayer->iMbHeight << 4; | 71 | int32_t iCurLayerHeight = pCurLayer->iMbHeight << 4; |
| 72 | 72 | ||
| 73 | int32_t iNextMbXyIndex = 0; | 73 | int32_t iNextMbXyIndex = 0; |
| 74 | PFmo pFmo = pCtx->pFmo; | 74 | PFmo pFmo = pCtx->pFmo; |
| 75 | 75 | ||
| 76 | int32_t iTotalNumMb = pCurSlice->iTotalMbInCurSlice; | 76 | int32_t iTotalNumMb = pCurSlice->iTotalMbInCurSlice; |
| 77 | int32_t iCountNumMb = 0; | 77 | int32_t iCountNumMb = 0; |
| 78 | PDeblockingFilterMbFunc pDeblockMb; | 78 | PDeblockingFilterMbFunc pDeblockMb; |
| 79 | 79 | ||
| 80 | if (!pCtx->bAvcBasedFlag && iCurLayerWidth != pCtx->iCurSeqIntervalMaxPicWidth) { | 80 | if (!pCtx->bAvcBasedFlag && iCurLayerWidth != pCtx->iCurSeqIntervalMaxPicWidth) { |
| 81 | return ERR_INFO_WIDTH_MISMATCH; | 81 | return ERR_INFO_WIDTH_MISMATCH; |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | iNextMbXyIndex = pSliceHeader->iFirstMbInSlice; | 84 | iNextMbXyIndex = pSliceHeader->iFirstMbInSlice; |
| 85 | pCurLayer->iMbX = iNextMbXyIndex % pCurLayer->iMbWidth; | 85 | pCurLayer->iMbX = iNextMbXyIndex % pCurLayer->iMbWidth; |
| 86 | pCurLayer->iMbY = iNextMbXyIndex / pCurLayer->iMbWidth; | 86 | pCurLayer->iMbY = iNextMbXyIndex / pCurLayer->iMbWidth; |
| 87 | pCurLayer->iMbXyIndex = iNextMbXyIndex; | 87 | pCurLayer->iMbXyIndex = iNextMbXyIndex; |
| 88 | 88 | ||
| 89 | if (0 == iNextMbXyIndex) { | 89 | if (0 == iNextMbXyIndex) { |
| 90 | pCurLayer->pDec->iSpsId = pCtx->pSps->iSpsId; | 90 | pCurLayer->pDec->iSpsId = pCtx->pSps->iSpsId; |
| 91 | pCurLayer->pDec->iPpsId = pCtx->pPps->iPpsId; | 91 | pCurLayer->pDec->iPpsId = pCtx->pPps->iPpsId; |
| 92 | 92 | ||
| 93 | pCurLayer->pDec->uiQualityId = pCurLayer->sLayerInfo.sNalHeaderExt.uiQualityId; | 93 | pCurLayer->pDec->uiQualityId = pCurLayer->sLayerInfo.sNalHeaderExt.uiQualityId; |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | do { | 96 | do { |
| 97 | if (iCountNumMb >= iTotalNumMb) { | 97 | if (iCountNumMb >= iTotalNumMb) { |
| 98 | break; | 98 | break; |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | if (!pCtx->pParam->bParseOnly) { //for parse only, actual recon MB unnecessary | 101 | if (!pCtx->pParam->bParseOnly) { //for parse only, actual recon MB unnecessary |
| 102 | if (WelsTargetMbConstruction (pCtx)) { | 102 | if (WelsTargetMbConstruction (pCtx)) { |
| 103 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, | 103 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, |
| 104 | "WelsTargetSliceConstruction():::MB(%d, %d) construction error. pCurSlice_type:%d", | 104 | "WelsTargetSliceConstruction():::MB(%d, %d) construction error. pCurSlice_type:%d", |
| 105 | pCurLayer->iMbX, pCurLayer->iMbY, pCurSlice->eSliceType); | 105 | pCurLayer->iMbX, pCurLayer->iMbY, pCurSlice->eSliceType); |
| 106 | 106 | ||
| 107 | return ERR_INFO_MB_RECON_FAIL; | 107 | return ERR_INFO_MB_RECON_FAIL; |
| 108 | } | 108 | } |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | ++iCountNumMb; | 111 | ++iCountNumMb; |
| 112 | if (!pCurLayer->pMbCorrectlyDecodedFlag[iNextMbXyIndex]) { //already con-ed, overwrite | 112 | if (!pCurLayer->pMbCorrectlyDecodedFlag[iNextMbXyIndex]) { //already con-ed, overwrite |
| 113 | pCurLayer->pMbCorrectlyDecodedFlag[iNextMbXyIndex] = true; | 113 | pCurLayer->pMbCorrectlyDecodedFlag[iNextMbXyIndex] = true; |
| 114 | pCtx->pDec->iMbEcedPropNum += (pCurLayer->pMbRefConcealedFlag[iNextMbXyIndex] ? 1 : 0); | 114 | pCtx->pDec->iMbEcedPropNum += (pCurLayer->pMbRefConcealedFlag[iNextMbXyIndex] ? 1 : 0); |
| 115 | ++pCtx->iTotalNumMbRec; | 115 | ++pCtx->iTotalNumMbRec; |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | if (pCtx->iTotalNumMbRec > iTotalMbTargetLayer) { | 118 | if (pCtx->iTotalNumMbRec > iTotalMbTargetLayer) { |
| 119 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, | 119 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, |
| 120 | "WelsTargetSliceConstruction():::pCtx->iTotalNumMbRec:%d, iTotalMbTargetLayer:%d", | 120 | "WelsTargetSliceConstruction():::pCtx->iTotalNumMbRec:%d, iTotalMbTargetLayer:%d", |
| 121 | pCtx->iTotalNumMbRec, iTotalMbTargetLayer); | 121 | pCtx->iTotalNumMbRec, iTotalMbTargetLayer); |
| 122 | 122 | ||
| 123 | return ERR_INFO_MB_NUM_EXCEED_FAIL; | 123 | return ERR_INFO_MB_NUM_EXCEED_FAIL; |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | if (pSliceHeader->pPps->uiNumSliceGroups > 1) { | 126 | if (pSliceHeader->pPps->uiNumSliceGroups > 1) { |
| 127 | iNextMbXyIndex = FmoNextMb (pFmo, iNextMbXyIndex); | 127 | iNextMbXyIndex = FmoNextMb (pFmo, iNextMbXyIndex); |
| 128 | } else { | 128 | } else { |
| 129 | ++iNextMbXyIndex; | 129 | ++iNextMbXyIndex; |
| 130 | } | 130 | } |
| 131 | if (-1 == iNextMbXyIndex || iNextMbXyIndex >= iTotalMbTargetLayer) { // slice group boundary or end of a frame | 131 | if (-1 == iNextMbXyIndex || iNextMbXyIndex >= iTotalMbTargetLayer) { // slice group boundary or end of a frame |
| 132 | break; | 132 | break; |
| 133 | } | 133 | } |
| 134 | pCurLayer->iMbX = iNextMbXyIndex % pCurLayer->iMbWidth; | 134 | pCurLayer->iMbX = iNextMbXyIndex % pCurLayer->iMbWidth; |
| 135 | pCurLayer->iMbY = iNextMbXyIndex / pCurLayer->iMbWidth; | 135 | pCurLayer->iMbY = iNextMbXyIndex / pCurLayer->iMbWidth; |
| 136 | pCurLayer->iMbXyIndex = iNextMbXyIndex; | 136 | pCurLayer->iMbXyIndex = iNextMbXyIndex; |
| 137 | } while (1); | 137 | } while (1); |
| 138 | 138 | ||
| 139 | pCtx->pDec->iWidthInPixel = iCurLayerWidth; | 139 | pCtx->pDec->iWidthInPixel = iCurLayerWidth; |
| 140 | pCtx->pDec->iHeightInPixel = iCurLayerHeight; | 140 | pCtx->pDec->iHeightInPixel = iCurLayerHeight; |
| 141 | 141 | ||
| 142 | if ((pCurSlice->eSliceType != I_SLICE) && (pCurSlice->eSliceType != P_SLICE) && (pCurSlice->eSliceType != B_SLICE)) | 142 | if ((pCurSlice->eSliceType != I_SLICE) && (pCurSlice->eSliceType != P_SLICE) && (pCurSlice->eSliceType != B_SLICE)) |
| 143 | return ERR_NONE; //no error but just ignore the type unsupported | 143 | return ERR_NONE; //no error but just ignore the type unsupported |
| 144 | 144 | ||
| 145 | if (pCtx->pParam->bParseOnly) //for parse only, deblocking should not go on | 145 | if (pCtx->pParam->bParseOnly) //for parse only, deblocking should not go on |
| 146 | return ERR_NONE; | 146 | return ERR_NONE; |
| 147 | 147 | ||
| 148 | pDeblockMb = WelsDeblockingMb; | 148 | pDeblockMb = WelsDeblockingMb; |
| 149 | 149 | ||
| 150 | if (1 == pSliceHeader->uiDisableDeblockingFilterIdc | 150 | if (1 == pSliceHeader->uiDisableDeblockingFilterIdc |
| 151 | || pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer.iTotalMbInCurSlice <= 0) { | 151 | || pCtx->pCurDqLayer->sLayerInfo.sSliceInLayer.iTotalMbInCurSlice <= 0) { |
| 152 | return ERR_NONE;//NO_SUPPORTED_FILTER_IDX | 152 | return ERR_NONE;//NO_SUPPORTED_FILTER_IDX |
| 153 | } else { | 153 | } else { |
| 154 | WelsDeblockingFilterSlice (pCtx, pDeblockMb); | 154 | WelsDeblockingFilterSlice (pCtx, pDeblockMb); |
| 155 | } | 155 | } |
| 156 | // any other filter_idc not supported here, 7/22/2010 | 156 | // any other filter_idc not supported here, 7/22/2010 |
| 157 | 157 | ||
| 158 | return ERR_NONE; | 158 | return ERR_NONE; |
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | int32_t WelsMbInterSampleConstruction (PWelsDecoderContext pCtx, PDqLayer pCurLayer, | 161 | int32_t WelsMbInterSampleConstruction (PWelsDecoderContext pCtx, PDqLayer pCurLayer, |
| 162 | uint8_t* pDstY, uint8_t* pDstU, uint8_t* pDstV, int32_t iStrideL, int32_t iStrideC) { | 162 | uint8_t* pDstY, uint8_t* pDstU, uint8_t* pDstV, int32_t iStrideL, int32_t iStrideC) { |
| 163 | int32_t iMbXy = pCurLayer->iMbXyIndex; | 163 | int32_t iMbXy = pCurLayer->iMbXyIndex; |
| 164 | int32_t i, iIndex, iOffset; | 164 | int32_t i, iIndex, iOffset; |
| 165 | 165 | ||
| 166 | if (pCurLayer->pTransformSize8x8Flag[iMbXy]) { | 166 | if (pCurLayer->pTransformSize8x8Flag[iMbXy]) { |
| 167 | for (i = 0; i < 4; i++) { | 167 | for (i = 0; i < 4; i++) { |
| 168 | iIndex = g_kuiMbCountScan4Idx[i << 2]; | 168 | iIndex = g_kuiMbCountScan4Idx[i << 2]; |
| 169 | if (pCurLayer->pNzc[iMbXy][iIndex] || pCurLayer->pNzc[iMbXy][iIndex + 1] || pCurLayer->pNzc[iMbXy][iIndex + 4] | 169 | if (pCurLayer->pNzc[iMbXy][iIndex] || pCurLayer->pNzc[iMbXy][iIndex + 1] || pCurLayer->pNzc[iMbXy][iIndex + 4] |
| 170 | || pCurLayer->pNzc[iMbXy][iIndex + 5]) { | 170 | || pCurLayer->pNzc[iMbXy][iIndex + 5]) { |
| 171 | iOffset = ((iIndex >> 2) << 2) * iStrideL + ((iIndex % 4) << 2); | 171 | iOffset = ((iIndex >> 2) << 2) * iStrideL + ((iIndex % 4) << 2); |
| 172 | pCtx->pIdctResAddPredFunc8x8 (pDstY + iOffset, iStrideL, pCurLayer->pScaledTCoeff[iMbXy] + (i << 6)); | 172 | pCtx->pIdctResAddPredFunc8x8 (pDstY + iOffset, iStrideL, pCurLayer->pScaledTCoeff[iMbXy] + (i << 6)); |
| 173 | } | 173 | } |
| 174 | } | 174 | } |
| 175 | } else { | 175 | } else { |
| 176 | // luma. | 176 | // luma. |
| 177 | const int8_t* pNzc = pCurLayer->pNzc[iMbXy]; | 177 | const int8_t* pNzc = pCurLayer->pNzc[iMbXy]; |
| 178 | int16_t* pScaledTCoeff = pCurLayer->pScaledTCoeff[iMbXy]; | 178 | int16_t* pScaledTCoeff = pCurLayer->pScaledTCoeff[iMbXy]; |
| 179 | pCtx->pIdctFourResAddPredFunc (pDstY + 0 * iStrideL + 0, iStrideL, pScaledTCoeff + 0 * 64, pNzc + 0); | 179 | pCtx->pIdctFourResAddPredFunc (pDstY + 0 * iStrideL + 0, iStrideL, pScaledTCoeff + 0 * 64, pNzc + 0); |
| 180 | pCtx->pIdctFourResAddPredFunc (pDstY + 0 * iStrideL + 8, iStrideL, pScaledTCoeff + 1 * 64, pNzc + 2); | 180 | pCtx->pIdctFourResAddPredFunc (pDstY + 0 * iStrideL + 8, iStrideL, pScaledTCoeff + 1 * 64, pNzc + 2); |
| 181 | pCtx->pIdctFourResAddPredFunc (pDstY + 8 * iStrideL + 0, iStrideL, pScaledTCoeff + 2 * 64, pNzc + 8); | 181 | pCtx->pIdctFourResAddPredFunc (pDstY + 8 * iStrideL + 0, iStrideL, pScaledTCoeff + 2 * 64, pNzc + 8); |
| 182 | pCtx->pIdctFourResAddPredFunc (pDstY + 8 * iStrideL + 8, iStrideL, pScaledTCoeff + 3 * 64, pNzc + 10); | 182 | pCtx->pIdctFourResAddPredFunc (pDstY + 8 * iStrideL + 8, iStrideL, pScaledTCoeff + 3 * 64, pNzc + 10); |
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | const int8_t* pNzc = pCurLayer->pNzc[iMbXy]; | 185 | const int8_t* pNzc = pCurLayer->pNzc[iMbXy]; |
| 186 | int16_t* pScaledTCoeff = pCurLayer->pScaledTCoeff[iMbXy]; | 186 | int16_t* pScaledTCoeff = pCurLayer->pScaledTCoeff[iMbXy]; |
| 187 | // Cb. | 187 | // Cb. |
| 188 | pCtx->pIdctFourResAddPredFunc (pDstU, iStrideC, pScaledTCoeff + 4 * 64, pNzc + 16); | 188 | pCtx->pIdctFourResAddPredFunc (pDstU, iStrideC, pScaledTCoeff + 4 * 64, pNzc + 16); |
| 189 | // Cr. | 189 | // Cr. |
| 190 | pCtx->pIdctFourResAddPredFunc (pDstV, iStrideC, pScaledTCoeff + 5 * 64, pNzc + 18); | 190 | pCtx->pIdctFourResAddPredFunc (pDstV, iStrideC, pScaledTCoeff + 5 * 64, pNzc + 18); |
| 191 | 191 | ||
| 192 | return ERR_NONE; | 192 | return ERR_NONE; |
| 193 | } | 193 | } |
| 194 | int32_t WelsMbInterConstruction (PWelsDecoderContext pCtx, PDqLayer pCurLayer) { | 194 | int32_t WelsMbInterConstruction (PWelsDecoderContext pCtx, PDqLayer pCurLayer) { |
| 195 | int32_t iMbX = pCurLayer->iMbX; | 195 | int32_t iMbX = pCurLayer->iMbX; |
| 196 | int32_t iMbY = pCurLayer->iMbY; | 196 | int32_t iMbY = pCurLayer->iMbY; |
| 197 | uint8_t* pDstY, *pDstCb, *pDstCr; | 197 | uint8_t* pDstY, *pDstCb, *pDstCr; |
| 198 | 198 | ||
| 199 | int32_t iLumaStride = pCtx->pDec->iLinesize[0]; | 199 | int32_t iLumaStride = pCtx->pDec->iLinesize[0]; |
| 200 | int32_t iChromaStride = pCtx->pDec->iLinesize[1]; | 200 | int32_t iChromaStride = pCtx->pDec->iLinesize[1]; |
| 201 | 201 | ||
| 202 | pDstY = pCurLayer->pDec->pData[0] + ((iMbY * iLumaStride + iMbX) << 4); | 202 | pDstY = pCurLayer->pDec->pData[0] + ((iMbY * iLumaStride + iMbX) << 4); |
| 203 | pDstCb = pCurLayer->pDec->pData[1] + ((iMbY * iChromaStride + iMbX) << 3); | 203 | pDstCb = pCurLayer->pDec->pData[1] + ((iMbY * iChromaStride + iMbX) << 3); |
| 204 | pDstCr = pCurLayer->pDec->pData[2] + ((iMbY * iChromaStride + iMbX) << 3); | 204 | pDstCr = pCurLayer->pDec->pData[2] + ((iMbY * iChromaStride + iMbX) << 3); |
| 205 | 205 | ||
| 206 | if (pCtx->eSliceType == P_SLICE) { | 206 | if (pCtx->eSliceType == P_SLICE) { |
| 207 | GetInterPred (pDstY, pDstCb, pDstCr, pCtx); | 207 | GetInterPred (pDstY, pDstCb, pDstCr, pCtx); |
| 208 | } else { | 208 | } else { |
| 209 | if (pCtx->pTempDec == NULL) | 209 | if (pCtx->pTempDec == NULL) |
| 210 | pCtx->pTempDec = AllocPicture (pCtx, pCtx->pSps->iMbWidth << 4, pCtx->pSps->iMbHeight << 4); | 210 | pCtx->pTempDec = AllocPicture (pCtx, pCtx->pSps->iMbWidth << 4, pCtx->pSps->iMbHeight << 4); |
| 211 | uint8_t* pTempDstYCbCr[3]; | 211 | uint8_t* pTempDstYCbCr[3]; |
| 212 | uint8_t* pDstYCbCr[3]; | 212 | uint8_t* pDstYCbCr[3]; |
| 213 | pTempDstYCbCr[0] = pCtx->pTempDec->pData[0] + ((iMbY * iLumaStride + iMbX) << 4); | 213 | pTempDstYCbCr[0] = pCtx->pTempDec->pData[0] + ((iMbY * iLumaStride + iMbX) << 4); |
| 214 | pTempDstYCbCr[1] = pCtx->pTempDec->pData[1] + ((iMbY * iChromaStride + iMbX) << 3); | 214 | pTempDstYCbCr[1] = pCtx->pTempDec->pData[1] + ((iMbY * iChromaStride + iMbX) << 3); |
| 215 | pTempDstYCbCr[2] = pCtx->pTempDec->pData[2] + ((iMbY * iChromaStride + iMbX) << 3); | 215 | pTempDstYCbCr[2] = pCtx->pTempDec->pData[2] + ((iMbY * iChromaStride + iMbX) << 3); |
| 216 | pDstYCbCr[0] = pDstY; | 216 | pDstYCbCr[0] = pDstY; |
| 217 | pDstYCbCr[1] = pDstCb; | 217 | pDstYCbCr[1] = pDstCb; |
| 218 | pDstYCbCr[2] = pDstCr; | 218 | pDstYCbCr[2] = pDstCr; |
| 219 | GetInterBPred (pDstYCbCr, pTempDstYCbCr, pCtx); | 219 | GetInterBPred (pDstYCbCr, pTempDstYCbCr, pCtx); |
| 220 | } | 220 | } |
| 221 | WelsMbInterSampleConstruction (pCtx, pCurLayer, pDstY, pDstCb, pDstCr, iLumaStride, iChromaStride); | 221 | WelsMbInterSampleConstruction (pCtx, pCurLayer, pDstY, pDstCb, pDstCr, iLumaStride, iChromaStride); |
| 222 | 222 | ||
| 223 | pCtx->sBlockFunc.pWelsSetNonZeroCountFunc ( | 223 | pCtx->sBlockFunc.pWelsSetNonZeroCountFunc ( |
| 224 | pCurLayer->pNzc[pCurLayer->iMbXyIndex]); // set all none-zero nzc to 1; dbk can be opti! | 224 | pCurLayer->pNzc[pCurLayer->iMbXyIndex]); // set all none-zero nzc to 1; dbk can be opti! |
| 225 | return ERR_NONE; | 225 | return ERR_NONE; |
| 226 | } | 226 | } |
| 227 | 227 | ||
| 228 | void WelsLumaDcDequantIdct (int16_t* pBlock, int32_t iQp, PWelsDecoderContext pCtx) { | 228 | void WelsLumaDcDequantIdct (int16_t* pBlock, int32_t iQp, PWelsDecoderContext pCtx) { |
| 229 | const int32_t kiQMul = pCtx->bUseScalingList ? pCtx->pDequant_coeff4x4[0][iQp][0] : (g_kuiDequantCoeff[iQp][0] << 4); | 229 | const int32_t kiQMul = pCtx->bUseScalingList ? pCtx->pDequant_coeff4x4[0][iQp][0] : (g_kuiDequantCoeff[iQp][0] << 4); |
| 230 | #define STRIDE 16 | 230 | #define STRIDE 16 |
| 231 | int32_t i; | 231 | int32_t i; |
| 232 | int32_t iTemp[16]; //FIXME check if this is a good idea | 232 | int32_t iTemp[16]; //FIXME check if this is a good idea |
| 233 | int16_t* pBlk = pBlock; | 233 | int16_t* pBlk = pBlock; |
| 234 | static const int32_t kiXOffset[4] = {0, STRIDE, STRIDE << 2, 5 * STRIDE}; | 234 | static const int32_t kiXOffset[4] = {0, STRIDE, STRIDE << 2, 5 * STRIDE}; |
| 235 | static const int32_t kiYOffset[4] = {0, STRIDE << 1, STRIDE << 3, 10 * STRIDE}; | 235 | static const int32_t kiYOffset[4] = {0, STRIDE << 1, STRIDE << 3, 10 * STRIDE}; |
| 236 | 236 | ||
| 237 | for (i = 0; i < 4; i++) { | 237 | for (i = 0; i < 4; i++) { |
| 238 | const int32_t kiOffset = kiYOffset[i]; | 238 | const int32_t kiOffset = kiYOffset[i]; |
| 239 | const int32_t kiX1 = kiOffset + kiXOffset[2]; | 239 | const int32_t kiX1 = kiOffset + kiXOffset[2]; |
| 240 | const int32_t kiX2 = STRIDE + kiOffset; | 240 | const int32_t kiX2 = STRIDE + kiOffset; |
| 241 | const int32_t kiX3 = kiOffset + kiXOffset[3]; | 241 | const int32_t kiX3 = kiOffset + kiXOffset[3]; |
| 242 | const int32_t kiI4 = i << 2; // 4*i | 242 | const int32_t kiI4 = i << 2; // 4*i |
| 243 | const int32_t kiZ0 = pBlk[kiOffset] + pBlk[kiX1]; | 243 | const int32_t kiZ0 = pBlk[kiOffset] + pBlk[kiX1]; |
| 244 | const int32_t kiZ1 = pBlk[kiOffset] - pBlk[kiX1]; | 244 | const int32_t kiZ1 = pBlk[kiOffset] - pBlk[kiX1]; |
| 245 | const int32_t kiZ2 = pBlk[kiX2] - pBlk[kiX3]; | 245 | const int32_t kiZ2 = pBlk[kiX2] - pBlk[kiX3]; |
| 246 | const int32_t kiZ3 = pBlk[kiX2] + pBlk[kiX3]; | 246 | const int32_t kiZ3 = pBlk[kiX2] + pBlk[kiX3]; |
| 247 | 247 | ||
| 248 | iTemp[kiI4] = kiZ0 + kiZ3; | 248 | iTemp[kiI4] = kiZ0 + kiZ3; |
| 249 | iTemp[1 + kiI4] = kiZ1 + kiZ2; | 249 | iTemp[1 + kiI4] = kiZ1 + kiZ2; |
| 250 | iTemp[2 + kiI4] = kiZ1 - kiZ2; | 250 | iTemp[2 + kiI4] = kiZ1 - kiZ2; |
| 251 | iTemp[3 + kiI4] = kiZ0 - kiZ3; | 251 | iTemp[3 + kiI4] = kiZ0 - kiZ3; |
| 252 | } | 252 | } |
| 253 | 253 | ||
| 254 | for (i = 0; i < 4; i++) { | 254 | for (i = 0; i < 4; i++) { |
| 255 | const int32_t kiOffset = kiXOffset[i]; | 255 | const int32_t kiOffset = kiXOffset[i]; |
| 256 | const int32_t kiI4 = 4 + i; | 256 | const int32_t kiI4 = 4 + i; |
| 257 | const int32_t kiZ0 = iTemp[i] + iTemp[4 + kiI4]; | 257 | const int32_t kiZ0 = iTemp[i] + iTemp[4 + kiI4]; |
| 258 | const int32_t kiZ1 = iTemp[i] - iTemp[4 + kiI4]; | 258 | const int32_t kiZ1 = iTemp[i] - iTemp[4 + kiI4]; |
| 259 | const int32_t kiZ2 = iTemp[kiI4] - iTemp[8 + kiI4]; | 259 | const int32_t kiZ2 = iTemp[kiI4] - iTemp[8 + kiI4]; |
| 260 | const int32_t kiZ3 = iTemp[kiI4] + iTemp[8 + kiI4]; | 260 | const int32_t kiZ3 = iTemp[kiI4] + iTemp[8 + kiI4]; |
| 261 | 261 | ||
| 262 | pBlk[kiOffset] = ((kiZ0 + kiZ3) * kiQMul + (1 << 5)) >> 6; //FIXME think about merging this into decode_resdual | 262 | pBlk[kiOffset] = ((kiZ0 + kiZ3) * kiQMul + (1 << 5)) >> 6; //FIXME think about merging this into decode_resdual |
| 263 | pBlk[kiYOffset[1] + kiOffset] = ((kiZ1 + kiZ2) * kiQMul + (1 << 5)) >> 6; | 263 | pBlk[kiYOffset[1] + kiOffset] = ((kiZ1 + kiZ2) * kiQMul + (1 << 5)) >> 6; |
| 264 | pBlk[kiYOffset[2] + kiOffset] = ((kiZ1 - kiZ2) * kiQMul + (1 << 5)) >> 6; | 264 | pBlk[kiYOffset[2] + kiOffset] = ((kiZ1 - kiZ2) * kiQMul + (1 << 5)) >> 6; |
| 265 | pBlk[kiYOffset[3] + kiOffset] = ((kiZ0 - kiZ3) * kiQMul + (1 << 5)) >> 6; | 265 | pBlk[kiYOffset[3] + kiOffset] = ((kiZ0 - kiZ3) * kiQMul + (1 << 5)) >> 6; |
| 266 | } | 266 | } |
| 267 | #undef STRIDE | 267 | #undef STRIDE |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | int32_t WelsMbIntraPredictionConstruction (PWelsDecoderContext pCtx, PDqLayer pCurLayer, bool bOutput) { | 270 | int32_t WelsMbIntraPredictionConstruction (PWelsDecoderContext pCtx, PDqLayer pCurLayer, bool bOutput) { |
| 271 | //seems IPCM should not enter this path | 271 | //seems IPCM should not enter this path |
| 272 | int32_t iMbXy = pCurLayer->iMbXyIndex; | 272 | int32_t iMbXy = pCurLayer->iMbXyIndex; |
| 273 | 273 | ||
| 274 | WelsFillRecNeededMbInfo (pCtx, bOutput, pCurLayer); | 274 | WelsFillRecNeededMbInfo (pCtx, bOutput, pCurLayer); |
| 275 | 275 | ||
| 276 | if (IS_INTRA16x16 (pCurLayer->pMbType[iMbXy])) { | 276 | if (IS_INTRA16x16 (pCurLayer->pMbType[iMbXy])) { |
| 277 | RecI16x16Mb (iMbXy, pCtx, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer); | 277 | RecI16x16Mb (iMbXy, pCtx, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer); |
| 278 | } else if (IS_INTRA8x8 (pCurLayer->pMbType[iMbXy])) { | 278 | } else if (IS_INTRA8x8 (pCurLayer->pMbType[iMbXy])) { |
| 279 | RecI8x8Mb (iMbXy, pCtx, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer); | 279 | RecI8x8Mb (iMbXy, pCtx, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer); |
| 280 | } else if (IS_INTRA4x4 (pCurLayer->pMbType[iMbXy])) { | 280 | } else if (IS_INTRA4x4 (pCurLayer->pMbType[iMbXy])) { |
| 281 | RecI4x4Mb (iMbXy, pCtx, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer); | 281 | RecI4x4Mb (iMbXy, pCtx, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer); |
| 282 | } | 282 | } |
| 283 | return ERR_NONE; | 283 | return ERR_NONE; |
| 284 | } | 284 | } |
| 285 | 285 | ||
| 286 | int32_t WelsMbInterPrediction (PWelsDecoderContext pCtx, PDqLayer pCurLayer) { | 286 | int32_t WelsMbInterPrediction (PWelsDecoderContext pCtx, PDqLayer pCurLayer) { |
| 287 | int32_t iMbX = pCurLayer->iMbX; | 287 | int32_t iMbX = pCurLayer->iMbX; |
| 288 | int32_t iMbY = pCurLayer->iMbY; | 288 | int32_t iMbY = pCurLayer->iMbY; |
| 289 | uint8_t* pDstY, *pDstCb, *pDstCr; | 289 | uint8_t* pDstY, *pDstCb, *pDstCr; |
| 290 | 290 | ||
| 291 | int32_t iLumaStride = pCtx->pDec->iLinesize[0]; | 291 | int32_t iLumaStride = pCtx->pDec->iLinesize[0]; |
| 292 | int32_t iChromaStride = pCtx->pDec->iLinesize[1]; | 292 | int32_t iChromaStride = pCtx->pDec->iLinesize[1]; |
| 293 | 293 | ||
| 294 | pDstY = pCurLayer->pDec->pData[0] + ((iMbY * iLumaStride + iMbX) << 4); | 294 | pDstY = pCurLayer->pDec->pData[0] + ((iMbY * iLumaStride + iMbX) << 4); |
| 295 | pDstCb = pCurLayer->pDec->pData[1] + ((iMbY * iChromaStride + iMbX) << 3); | 295 | pDstCb = pCurLayer->pDec->pData[1] + ((iMbY * iChromaStride + iMbX) << 3); |
| 296 | pDstCr = pCurLayer->pDec->pData[2] + ((iMbY * iChromaStride + iMbX) << 3); | 296 | pDstCr = pCurLayer->pDec->pData[2] + ((iMbY * iChromaStride + iMbX) << 3); |
| 297 | 297 | ||
| 298 | if (pCtx->eSliceType == P_SLICE) { | 298 | if (pCtx->eSliceType == P_SLICE) { |
| 299 | GetInterPred (pDstY, pDstCb, pDstCr, pCtx); | 299 | GetInterPred (pDstY, pDstCb, pDstCr, pCtx); |
| 300 | } else { | 300 | } else { |
| 301 | if (pCtx->pTempDec == NULL) | 301 | if (pCtx->pTempDec == NULL) |
| 302 | pCtx->pTempDec = AllocPicture (pCtx, pCtx->pSps->iMbWidth << 4, pCtx->pSps->iMbHeight << 4); | 302 | pCtx->pTempDec = AllocPicture (pCtx, pCtx->pSps->iMbWidth << 4, pCtx->pSps->iMbHeight << 4); |
| 303 | uint8_t* pTempDstYCbCr[3]; | 303 | uint8_t* pTempDstYCbCr[3]; |
| 304 | uint8_t* pDstYCbCr[3]; | 304 | uint8_t* pDstYCbCr[3]; |
| 305 | pTempDstYCbCr[0] = pCtx->pTempDec->pData[0] + ((iMbY * iLumaStride + iMbX) << 4); | 305 | pTempDstYCbCr[0] = pCtx->pTempDec->pData[0] + ((iMbY * iLumaStride + iMbX) << 4); |
| 306 | pTempDstYCbCr[1] = pCtx->pTempDec->pData[1] + ((iMbY * iChromaStride + iMbX) << 3); | 306 | pTempDstYCbCr[1] = pCtx->pTempDec->pData[1] + ((iMbY * iChromaStride + iMbX) << 3); |
| 307 | pTempDstYCbCr[2] = pCtx->pTempDec->pData[2] + ((iMbY * iChromaStride + iMbX) << 3); | 307 | pTempDstYCbCr[2] = pCtx->pTempDec->pData[2] + ((iMbY * iChromaStride + iMbX) << 3); |
| 308 | pDstYCbCr[0] = pDstY; | 308 | pDstYCbCr[0] = pDstY; |
| 309 | pDstYCbCr[1] = pDstCb; | 309 | pDstYCbCr[1] = pDstCb; |
| 310 | pDstYCbCr[2] = pDstCr; | 310 | pDstYCbCr[2] = pDstCr; |
| 311 | GetInterBPred (pDstYCbCr, pTempDstYCbCr, pCtx); | 311 | GetInterBPred (pDstYCbCr, pTempDstYCbCr, pCtx); |
| 312 | } | 312 | } |
| 313 | return ERR_NONE; | 313 | return ERR_NONE; |
| 314 | } | 314 | } |
| 315 | 315 | ||
| 316 | int32_t WelsTargetMbConstruction (PWelsDecoderContext pCtx) { | 316 | int32_t WelsTargetMbConstruction (PWelsDecoderContext pCtx) { |
| 317 | PDqLayer pCurLayer = pCtx->pCurDqLayer; | 317 | PDqLayer pCurLayer = pCtx->pCurDqLayer; |
| 318 | if (MB_TYPE_INTRA_PCM == pCurLayer->pMbType[pCurLayer->iMbXyIndex]) { | 318 | if (MB_TYPE_INTRA_PCM == pCurLayer->pMbType[pCurLayer->iMbXyIndex]) { |
| 319 | //already decoded and reconstructed when parsing | 319 | //already decoded and reconstructed when parsing |
| 320 | return ERR_NONE; | 320 | return ERR_NONE; |
| 321 | } else if (IS_INTRA (pCurLayer->pMbType[pCurLayer->iMbXyIndex])) { | 321 | } else if (IS_INTRA (pCurLayer->pMbType[pCurLayer->iMbXyIndex])) { |
| 322 | WelsMbIntraPredictionConstruction (pCtx, pCurLayer, 1); | 322 | WelsMbIntraPredictionConstruction (pCtx, pCurLayer, 1); |
| 323 | } else if (IS_INTER (pCurLayer->pMbType[pCurLayer->iMbXyIndex])) { //InterMB | 323 | } else if (IS_INTER (pCurLayer->pMbType[pCurLayer->iMbXyIndex])) { //InterMB |
| 324 | if (0 == pCurLayer->pCbp[pCurLayer->iMbXyIndex]) { //uiCbp==0 include SKIP | 324 | if (0 == pCurLayer->pCbp[pCurLayer->iMbXyIndex]) { //uiCbp==0 include SKIP |
| 325 | WelsMbInterPrediction (pCtx, pCurLayer); | 325 | WelsMbInterPrediction (pCtx, pCurLayer); |
| 326 | } else { | 326 | } else { |
| 327 | WelsMbInterConstruction (pCtx, pCurLayer); | 327 | WelsMbInterConstruction (pCtx, pCurLayer); |
| 328 | } | 328 | } |
| 329 | } else { | 329 | } else { |
| 330 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "WelsTargetMbConstruction():::::Unknown MB type: %d", | 330 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "WelsTargetMbConstruction():::::Unknown MB type: %d", |
| 331 | pCurLayer->pMbType[pCurLayer->iMbXyIndex]); | 331 | pCurLayer->pMbType[pCurLayer->iMbXyIndex]); |
| 332 | return ERR_INFO_MB_RECON_FAIL; | 332 | return ERR_INFO_MB_RECON_FAIL; |
| 333 | } | 333 | } |
| 334 | 334 | ||
| 335 | return ERR_NONE; | 335 | return ERR_NONE; |
| 336 | } | 336 | } |
| 337 | 337 | ||
| 338 | void WelsChromaDcIdct (int16_t* pBlock) { | 338 | void WelsChromaDcIdct (int16_t* pBlock) { |
| 339 | int32_t iStride = 32; | 339 | int32_t iStride = 32; |
| 340 | int32_t iXStride = 16; | 340 | int32_t iXStride = 16; |
| 341 | int32_t iStride1 = iXStride + iStride; | 341 | int32_t iStride1 = iXStride + iStride; |
| 342 | int16_t* pBlk = pBlock; | 342 | int16_t* pBlk = pBlock; |
| 343 | int32_t iA, iB, iC, iD, iE; | 343 | int32_t iA, iB, iC, iD, iE; |
| 344 | 344 | ||
| 345 | iA = pBlk[0]; | 345 | iA = pBlk[0]; |
| 346 | iB = pBlk[iXStride]; | 346 | iB = pBlk[iXStride]; |
| 347 | iC = pBlk[iStride]; | 347 | iC = pBlk[iStride]; |
| 348 | iD = pBlk[iStride1]; | 348 | iD = pBlk[iStride1]; |
| 349 | 349 | ||
| 350 | iE = iA - iB; | 350 | iE = iA - iB; |
| 351 | iA += iB; | 351 | iA += iB; |
| 352 | iB = iC - iD; | 352 | iB = iC - iD; |
| 353 | iC += iD; | 353 | iC += iD; |
| 354 | 354 | ||
| 355 | pBlk[0] = (iA + iC); | 355 | pBlk[0] = (iA + iC); |
| 356 | pBlk[iXStride] = (iE + iB); | 356 | pBlk[iXStride] = (iE + iB); |
| 357 | pBlk[iStride] = (iA - iC); | 357 | pBlk[iStride] = (iA - iC); |
| 358 | pBlk[iStride1] = (iE - iB); | 358 | pBlk[iStride1] = (iE - iB); |
| 359 | } | 359 | } |
| 360 | 360 | ||
| 361 | void WelsMapNxNNeighToSampleNormal (PWelsNeighAvail pNeighAvail, int32_t* pSampleAvail) { | 361 | void WelsMapNxNNeighToSampleNormal (PWelsNeighAvail pNeighAvail, int32_t* pSampleAvail) { |
| 362 | if (pNeighAvail->iLeftAvail) { //left | 362 | if (pNeighAvail->iLeftAvail) { //left |
| 363 | pSampleAvail[ 6] = | 363 | pSampleAvail[ 6] = |
| 364 | pSampleAvail[12] = | 364 | pSampleAvail[12] = |
| 365 | pSampleAvail[18] = | 365 | pSampleAvail[18] = |
| 366 | pSampleAvail[24] = 1; | 366 | pSampleAvail[24] = 1; |
| 367 | } | 367 | } |
| 368 | if (pNeighAvail->iLeftTopAvail) { //top_left | 368 | if (pNeighAvail->iLeftTopAvail) { //top_left |
| 369 | pSampleAvail[0] = 1; | 369 | pSampleAvail[0] = 1; |
| 370 | } | 370 | } |
| 371 | if (pNeighAvail->iTopAvail) { //top | 371 | if (pNeighAvail->iTopAvail) { //top |
| 372 | pSampleAvail[1] = | 372 | pSampleAvail[1] = |
| 373 | pSampleAvail[2] = | 373 | pSampleAvail[2] = |
| 374 | pSampleAvail[3] = | 374 | pSampleAvail[3] = |
| 375 | pSampleAvail[4] = 1; | 375 | pSampleAvail[4] = 1; |
| 376 | } | 376 | } |
| 377 | if (pNeighAvail->iRightTopAvail) { //top_right | 377 | if (pNeighAvail->iRightTopAvail) { //top_right |
| 378 | pSampleAvail[5] = 1; | 378 | pSampleAvail[5] = 1; |
| 379 | } | 379 | } |
| 380 | } | 380 | } |
| 381 | 381 | ||
| 382 | void WelsMapNxNNeighToSampleConstrain1 (PWelsNeighAvail pNeighAvail, int32_t* pSampleAvail) { | 382 | void WelsMapNxNNeighToSampleConstrain1 (PWelsNeighAvail pNeighAvail, int32_t* pSampleAvail) { |
| 383 | if (pNeighAvail->iLeftAvail && IS_INTRA (pNeighAvail->iLeftType)) { //left | 383 | if (pNeighAvail->iLeftAvail && IS_INTRA (pNeighAvail->iLeftType)) { //left |
| 384 | pSampleAvail[ 6] = | 384 | pSampleAvail[ 6] = |
| 385 | pSampleAvail[12] = | 385 | pSampleAvail[12] = |
| 386 | pSampleAvail[18] = | 386 | pSampleAvail[18] = |
| 387 | pSampleAvail[24] = 1; | 387 | pSampleAvail[24] = 1; |
| 388 | } | 388 | } |
| 389 | if (pNeighAvail->iLeftTopAvail && IS_INTRA (pNeighAvail->iLeftTopType)) { //top_left | 389 | if (pNeighAvail->iLeftTopAvail && IS_INTRA (pNeighAvail->iLeftTopType)) { //top_left |
| 390 | pSampleAvail[0] = 1; | 390 | pSampleAvail[0] = 1; |
| 391 | } | 391 | } |
| 392 | if (pNeighAvail->iTopAvail && IS_INTRA (pNeighAvail->iTopType)) { //top | 392 | if (pNeighAvail->iTopAvail && IS_INTRA (pNeighAvail->iTopType)) { //top |
| 393 | pSampleAvail[1] = | 393 | pSampleAvail[1] = |
| 394 | pSampleAvail[2] = | 394 | pSampleAvail[2] = |
| 395 | pSampleAvail[3] = | 395 | pSampleAvail[3] = |
| 396 | pSampleAvail[4] = 1; | 396 | pSampleAvail[4] = 1; |
| 397 | } | 397 | } |
| 398 | if (pNeighAvail->iRightTopAvail && IS_INTRA (pNeighAvail->iRightTopType)) { //top_right | 398 | if (pNeighAvail->iRightTopAvail && IS_INTRA (pNeighAvail->iRightTopType)) { //top_right |
| 399 | pSampleAvail[5] = 1; | 399 | pSampleAvail[5] = 1; |
| 400 | } | 400 | } |
| 401 | } | 401 | } |
| 402 | void WelsMap16x16NeighToSampleNormal (PWelsNeighAvail pNeighAvail, uint8_t* pSampleAvail) { | 402 | void WelsMap16x16NeighToSampleNormal (PWelsNeighAvail pNeighAvail, uint8_t* pSampleAvail) { |
| 403 | if (pNeighAvail->iLeftAvail) { | 403 | if (pNeighAvail->iLeftAvail) { |
| 404 | *pSampleAvail = (1 << 2); | 404 | *pSampleAvail = (1 << 2); |
| 405 | } | 405 | } |
| 406 | if (pNeighAvail->iLeftTopAvail) { | 406 | if (pNeighAvail->iLeftTopAvail) { |
| 407 | *pSampleAvail |= (1 << 1); | 407 | *pSampleAvail |= (1 << 1); |
| 408 | } | 408 | } |
| 409 | if (pNeighAvail->iTopAvail) { | 409 | if (pNeighAvail->iTopAvail) { |
| 410 | *pSampleAvail |= 1; | 410 | *pSampleAvail |= 1; |
| 411 | } | 411 | } |
| 412 | } | 412 | } |
| 413 | 413 | ||
| 414 | void WelsMap16x16NeighToSampleConstrain1 (PWelsNeighAvail pNeighAvail, uint8_t* pSampleAvail) { | 414 | void WelsMap16x16NeighToSampleConstrain1 (PWelsNeighAvail pNeighAvail, uint8_t* pSampleAvail) { |
| 415 | if (pNeighAvail->iLeftAvail && IS_INTRA (pNeighAvail->iLeftType)) { | 415 | if (pNeighAvail->iLeftAvail && IS_INTRA (pNeighAvail->iLeftType)) { |
| 416 | *pSampleAvail = (1 << 2); | 416 | *pSampleAvail = (1 << 2); |
| 417 | } | 417 | } |
| 418 | if (pNeighAvail->iLeftTopAvail && IS_INTRA (pNeighAvail->iLeftTopType)) { | 418 | if (pNeighAvail->iLeftTopAvail && IS_INTRA (pNeighAvail->iLeftTopType)) { |
| 419 | *pSampleAvail |= (1 << 1); | 419 | *pSampleAvail |= (1 << 1); |
| 420 | } | 420 | } |
| 421 | if (pNeighAvail->iTopAvail && IS_INTRA (pNeighAvail->iTopType)) { | 421 | if (pNeighAvail->iTopAvail && IS_INTRA (pNeighAvail->iTopType)) { |
| 422 | *pSampleAvail |= 1; | 422 | *pSampleAvail |= 1; |
| 423 | } | 423 | } |
| 424 | } | 424 | } |
| 425 | 425 | ||
| 426 | int32_t ParseIntra4x4Mode (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, int8_t* pIntraPredMode, | 426 | int32_t ParseIntra4x4Mode (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, int8_t* pIntraPredMode, |
| 427 | PBitStringAux pBs, | 427 | PBitStringAux pBs, |
| 428 | PDqLayer pCurDqLayer) { | 428 | PDqLayer pCurDqLayer) { |
| 429 | int32_t iSampleAvail[5 * 6] = { 0 }; //initialize as 0 | 429 | int32_t iSampleAvail[5 * 6] = { 0 }; //initialize as 0 |
| 430 | int32_t iMbXy = pCurDqLayer->iMbXyIndex; | 430 | int32_t iMbXy = pCurDqLayer->iMbXyIndex; |
| 431 | int32_t iFinalMode, i; | 431 | int32_t iFinalMode, i; |
| 432 | 432 | ||
| 433 | uint8_t uiNeighAvail = 0; | 433 | uint8_t uiNeighAvail = 0; |
| 434 | uint32_t uiCode; | 434 | uint32_t uiCode; |
| 435 | int32_t iCode; | 435 | int32_t iCode; |
| 436 | pCtx->pMapNxNNeighToSampleFunc (pNeighAvail, iSampleAvail); | 436 | pCtx->pMapNxNNeighToSampleFunc (pNeighAvail, iSampleAvail); |
| 437 | uiNeighAvail = (iSampleAvail[6] << 2) | (iSampleAvail[0] << 1) | (iSampleAvail[1]); | 437 | uiNeighAvail = (iSampleAvail[6] << 2) | (iSampleAvail[0] << 1) | (iSampleAvail[1]); |
| 438 | for (i = 0; i < 16; i++) { | 438 | for (i = 0; i < 16; i++) { |
| 439 | int32_t iPrevIntra4x4PredMode = 0; | 439 | int32_t iPrevIntra4x4PredMode = 0; |
| 440 | if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) { | 440 | if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) { |
| 441 | WELS_READ_VERIFY (ParseIntraPredModeLumaCabac (pCtx, iCode)); | 441 | WELS_READ_VERIFY (ParseIntraPredModeLumaCabac (pCtx, iCode)); |
| 442 | iPrevIntra4x4PredMode = iCode; | 442 | iPrevIntra4x4PredMode = iCode; |
| 443 | } else { | 443 | } else { |
| 444 | WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); | 444 | WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); |
| 445 | iPrevIntra4x4PredMode = uiCode; | 445 | iPrevIntra4x4PredMode = uiCode; |
| 446 | } | 446 | } |
| 447 | const int32_t kiPredMode = PredIntra4x4Mode (pIntraPredMode, i); | 447 | const int32_t kiPredMode = PredIntra4x4Mode (pIntraPredMode, i); |
| 448 | 448 | ||
| 449 | int8_t iBestMode; | 449 | int8_t iBestMode; |
| 450 | if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) { | 450 | if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) { |
| 451 | if (iPrevIntra4x4PredMode == -1) | 451 | if (iPrevIntra4x4PredMode == -1) |
| 452 | iBestMode = kiPredMode; | 452 | iBestMode = kiPredMode; |
| 453 | else | 453 | else |
| 454 | iBestMode = iPrevIntra4x4PredMode + (iPrevIntra4x4PredMode >= kiPredMode); | 454 | iBestMode = iPrevIntra4x4PredMode + (iPrevIntra4x4PredMode >= kiPredMode); |
| 455 | } else { | 455 | } else { |
| 456 | if (iPrevIntra4x4PredMode) { | 456 | if (iPrevIntra4x4PredMode) { |
| 457 | iBestMode = kiPredMode; | 457 | iBestMode = kiPredMode; |
| 458 | } else { | 458 | } else { |
| 459 | WELS_READ_VERIFY (BsGetBits (pBs, 3, &uiCode)); | 459 | WELS_READ_VERIFY (BsGetBits (pBs, 3, &uiCode)); |
| 460 | iBestMode = uiCode + ((int32_t) uiCode >= kiPredMode); | 460 | iBestMode = uiCode + ((int32_t) uiCode >= kiPredMode); |
| 461 | } | 461 | } |
| 462 | } | 462 | } |
| 463 | 463 | ||
| 464 | iFinalMode = CheckIntraNxNPredMode (&iSampleAvail[0], &iBestMode, i, false); | 464 | iFinalMode = CheckIntraNxNPredMode (&iSampleAvail[0], &iBestMode, i, false); |
| 465 | if (iFinalMode == GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INVALID_INTRA4X4_MODE)) { | 465 | if (iFinalMode == GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INVALID_INTRA4X4_MODE)) { |
| 466 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I4x4_PRED_MODE); | 466 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I4x4_PRED_MODE); |
| 467 | } | 467 | } |
| 468 | 468 | ||
| 469 | pCurDqLayer->pIntra4x4FinalMode[iMbXy][g_kuiScan4[i]] = iFinalMode; | 469 | pCurDqLayer->pIntra4x4FinalMode[iMbXy][g_kuiScan4[i]] = iFinalMode; |
| 470 | 470 | ||
| 471 | pIntraPredMode[g_kuiScan8[i]] = iBestMode; | 471 | pIntraPredMode[g_kuiScan8[i]] = iBestMode; |
| 472 | 472 | ||
| 473 | iSampleAvail[g_kuiCache30ScanIdx[i]] = 1; | 473 | iSampleAvail[g_kuiCache30ScanIdx[i]] = 1; |
| 474 | } | 474 | } |
| 475 | ST32 (&pCurDqLayer->pIntraPredMode[iMbXy][0], LD32 (&pIntraPredMode[1 + 8 * 4])); | 475 | ST32 (&pCurDqLayer->pIntraPredMode[iMbXy][0], LD32 (&pIntraPredMode[1 + 8 * 4])); |
| 476 | pCurDqLayer->pIntraPredMode[iMbXy][4] = pIntraPredMode[4 + 8 * 1]; | 476 | pCurDqLayer->pIntraPredMode[iMbXy][4] = pIntraPredMode[4 + 8 * 1]; |
| 477 | pCurDqLayer->pIntraPredMode[iMbXy][5] = pIntraPredMode[4 + 8 * 2]; | 477 | pCurDqLayer->pIntraPredMode[iMbXy][5] = pIntraPredMode[4 + 8 * 2]; |
| 478 | pCurDqLayer->pIntraPredMode[iMbXy][6] = pIntraPredMode[4 + 8 * 3]; | 478 | pCurDqLayer->pIntraPredMode[iMbXy][6] = pIntraPredMode[4 + 8 * 3]; |
| 479 | 479 | ||
| 480 | if (pCtx->pSps->uiChromaFormatIdc == 0)//no need parse chroma | 480 | if (pCtx->pSps->uiChromaFormatIdc == 0)//no need parse chroma |
| 481 | return ERR_NONE; | 481 | return ERR_NONE; |
| 482 | 482 | ||
| 483 | if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) { | 483 | if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) { |
| 484 | WELS_READ_VERIFY (ParseIntraPredModeChromaCabac (pCtx, uiNeighAvail, iCode)); | 484 | WELS_READ_VERIFY (ParseIntraPredModeChromaCabac (pCtx, uiNeighAvail, iCode)); |
| 485 | if (iCode > MAX_PRED_MODE_ID_CHROMA) { | 485 | if (iCode > MAX_PRED_MODE_ID_CHROMA) { |
| 486 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); | 486 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); |
| 487 | } | 487 | } |
| 488 | pCurDqLayer->pChromaPredMode[iMbXy] = iCode; | 488 | pCurDqLayer->pChromaPredMode[iMbXy] = iCode; |
| 489 | } else { | 489 | } else { |
| 490 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //intra_chroma_pred_mode | 490 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //intra_chroma_pred_mode |
| 491 | if (uiCode > MAX_PRED_MODE_ID_CHROMA) { | 491 | if (uiCode > MAX_PRED_MODE_ID_CHROMA) { |
| 492 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); | 492 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); |
| 493 | } | 493 | } |
| 494 | pCurDqLayer->pChromaPredMode[iMbXy] = uiCode; | 494 | pCurDqLayer->pChromaPredMode[iMbXy] = uiCode; |
| 495 | } | 495 | } |
| 496 | 496 | ||
| 497 | if (-1 == pCurDqLayer->pChromaPredMode[iMbXy] | 497 | if (-1 == pCurDqLayer->pChromaPredMode[iMbXy] |
| 498 | || CheckIntraChromaPredMode (uiNeighAvail, &pCurDqLayer->pChromaPredMode[iMbXy])) { | 498 | || CheckIntraChromaPredMode (uiNeighAvail, &pCurDqLayer->pChromaPredMode[iMbXy])) { |
| 499 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); | 499 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); |
| 500 | } | 500 | } |
| 501 | return ERR_NONE; | 501 | return ERR_NONE; |
| 502 | } | 502 | } |
| 503 | 503 | ||
| 504 | int32_t ParseIntra8x8Mode (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, int8_t* pIntraPredMode, | 504 | int32_t ParseIntra8x8Mode (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, int8_t* pIntraPredMode, |
| 505 | PBitStringAux pBs, | 505 | PBitStringAux pBs, |
| 506 | PDqLayer pCurDqLayer) { | 506 | PDqLayer pCurDqLayer) { |
| 507 | // Similar with Intra_4x4, can put them together when needed | 507 | // Similar with Intra_4x4, can put them together when needed |
| 508 | int32_t iSampleAvail[5 * 6] = { 0 }; //initialize as 0 | 508 | int32_t iSampleAvail[5 * 6] = { 0 }; //initialize as 0 |
| 509 | int32_t iMbXy = pCurDqLayer->iMbXyIndex; | 509 | int32_t iMbXy = pCurDqLayer->iMbXyIndex; |
| 510 | int32_t iFinalMode, i; | 510 | int32_t iFinalMode, i; |
| 511 | 511 | ||
| 512 | uint8_t uiNeighAvail = 0; | 512 | uint8_t uiNeighAvail = 0; |
| 513 | uint32_t uiCode; | 513 | uint32_t uiCode; |
| 514 | int32_t iCode; | 514 | int32_t iCode; |
| 515 | pCtx->pMapNxNNeighToSampleFunc (pNeighAvail, iSampleAvail); | 515 | pCtx->pMapNxNNeighToSampleFunc (pNeighAvail, iSampleAvail); |
| 516 | // Top-Right : Left : Top-Left : Top | 516 | // Top-Right : Left : Top-Left : Top |
| 517 | uiNeighAvail = (iSampleAvail[5] << 3) | (iSampleAvail[6] << 2) | (iSampleAvail[0] << 1) | (iSampleAvail[1]); | 517 | uiNeighAvail = (iSampleAvail[5] << 3) | (iSampleAvail[6] << 2) | (iSampleAvail[0] << 1) | (iSampleAvail[1]); |
| 518 | 518 | ||
| 519 | pCurDqLayer->pIntraNxNAvailFlag[iMbXy] = uiNeighAvail; | 519 | pCurDqLayer->pIntraNxNAvailFlag[iMbXy] = uiNeighAvail; |
| 520 | 520 | ||
| 521 | for (i = 0; i < 4; i++) { | 521 | for (i = 0; i < 4; i++) { |
| 522 | int32_t iPrevIntra4x4PredMode = 0; | 522 | int32_t iPrevIntra4x4PredMode = 0; |
| 523 | if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) { | 523 | if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) { |
| 524 | WELS_READ_VERIFY (ParseIntraPredModeLumaCabac (pCtx, iCode)); | 524 | WELS_READ_VERIFY (ParseIntraPredModeLumaCabac (pCtx, iCode)); |
| 525 | iPrevIntra4x4PredMode = iCode; | 525 | iPrevIntra4x4PredMode = iCode; |
| 526 | } else { | 526 | } else { |
| 527 | WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); | 527 | WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); |
| 528 | iPrevIntra4x4PredMode = uiCode; | 528 | iPrevIntra4x4PredMode = uiCode; |
| 529 | } | 529 | } |
| 530 | const int32_t kiPredMode = PredIntra4x4Mode (pIntraPredMode, i << 2); | 530 | const int32_t kiPredMode = PredIntra4x4Mode (pIntraPredMode, i << 2); |
| 531 | 531 | ||
| 532 | int8_t iBestMode; | 532 | int8_t iBestMode; |
| 533 | if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) { | 533 | if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) { |
| 534 | if (iPrevIntra4x4PredMode == -1) | 534 | if (iPrevIntra4x4PredMode == -1) |
| 535 | iBestMode = kiPredMode; | 535 | iBestMode = kiPredMode; |
| 536 | else | 536 | else |
| 537 | iBestMode = iPrevIntra4x4PredMode + (iPrevIntra4x4PredMode >= kiPredMode); | 537 | iBestMode = iPrevIntra4x4PredMode + (iPrevIntra4x4PredMode >= kiPredMode); |
| 538 | } else { | 538 | } else { |
| 539 | if (iPrevIntra4x4PredMode) { | 539 | if (iPrevIntra4x4PredMode) { |
| 540 | iBestMode = kiPredMode; | 540 | iBestMode = kiPredMode; |
| 541 | } else { | 541 | } else { |
| 542 | WELS_READ_VERIFY (BsGetBits (pBs, 3, &uiCode)); | 542 | WELS_READ_VERIFY (BsGetBits (pBs, 3, &uiCode)); |
| 543 | iBestMode = uiCode + ((int32_t) uiCode >= kiPredMode); | 543 | iBestMode = uiCode + ((int32_t) uiCode >= kiPredMode); |
| 544 | } | 544 | } |
| 545 | } | 545 | } |
| 546 | 546 | ||
| 547 | iFinalMode = CheckIntraNxNPredMode (&iSampleAvail[0], &iBestMode, i << 2, true); | 547 | iFinalMode = CheckIntraNxNPredMode (&iSampleAvail[0], &iBestMode, i << 2, true); |
| 548 | 548 | ||
| 549 | if (iFinalMode == GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INVALID_INTRA4X4_MODE)) { | 549 | if (iFinalMode == GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INVALID_INTRA4X4_MODE)) { |
| 550 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I4x4_PRED_MODE); | 550 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I4x4_PRED_MODE); |
| 551 | } | 551 | } |
| 552 | 552 | ||
| 553 | for (int j = 0; j < 4; j++) { | 553 | for (int j = 0; j < 4; j++) { |
| 554 | pCurDqLayer->pIntra4x4FinalMode[iMbXy][g_kuiScan4[ (i << 2) + j]] = iFinalMode; | 554 | pCurDqLayer->pIntra4x4FinalMode[iMbXy][g_kuiScan4[ (i << 2) + j]] = iFinalMode; |
| 555 | pIntraPredMode[g_kuiScan8[ (i << 2) + j]] = iBestMode; | 555 | pIntraPredMode[g_kuiScan8[ (i << 2) + j]] = iBestMode; |
| 556 | iSampleAvail[g_kuiCache30ScanIdx[ (i << 2) + j]] = 1; | 556 | iSampleAvail[g_kuiCache30ScanIdx[ (i << 2) + j]] = 1; |
| 557 | } | 557 | } |
| 558 | } | 558 | } |
| 559 | ST32 (&pCurDqLayer->pIntraPredMode[iMbXy][0], LD32 (&pIntraPredMode[1 + 8 * 4])); | 559 | ST32 (&pCurDqLayer->pIntraPredMode[iMbXy][0], LD32 (&pIntraPredMode[1 + 8 * 4])); |
| 560 | pCurDqLayer->pIntraPredMode[iMbXy][4] = pIntraPredMode[4 + 8 * 1]; | 560 | pCurDqLayer->pIntraPredMode[iMbXy][4] = pIntraPredMode[4 + 8 * 1]; |
| 561 | pCurDqLayer->pIntraPredMode[iMbXy][5] = pIntraPredMode[4 + 8 * 2]; | 561 | pCurDqLayer->pIntraPredMode[iMbXy][5] = pIntraPredMode[4 + 8 * 2]; |
| 562 | pCurDqLayer->pIntraPredMode[iMbXy][6] = pIntraPredMode[4 + 8 * 3]; | 562 | pCurDqLayer->pIntraPredMode[iMbXy][6] = pIntraPredMode[4 + 8 * 3]; |
| 563 | 563 | ||
| 564 | if (pCtx->pSps->uiChromaFormatIdc == 0) | 564 | if (pCtx->pSps->uiChromaFormatIdc == 0) |
| 565 | return ERR_NONE; | 565 | return ERR_NONE; |
| 566 | 566 | ||
| 567 | if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) { | 567 | if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) { |
| 568 | WELS_READ_VERIFY (ParseIntraPredModeChromaCabac (pCtx, uiNeighAvail, iCode)); | 568 | WELS_READ_VERIFY (ParseIntraPredModeChromaCabac (pCtx, uiNeighAvail, iCode)); |
| 569 | if (iCode > MAX_PRED_MODE_ID_CHROMA) { | 569 | if (iCode > MAX_PRED_MODE_ID_CHROMA) { |
| 570 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); | 570 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); |
| 571 | } | 571 | } |
| 572 | pCurDqLayer->pChromaPredMode[iMbXy] = iCode; | 572 | pCurDqLayer->pChromaPredMode[iMbXy] = iCode; |
| 573 | } else { | 573 | } else { |
| 574 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //intra_chroma_pred_mode | 574 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //intra_chroma_pred_mode |
| 575 | if (uiCode > MAX_PRED_MODE_ID_CHROMA) { | 575 | if (uiCode > MAX_PRED_MODE_ID_CHROMA) { |
| 576 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); | 576 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); |
| 577 | } | 577 | } |
| 578 | pCurDqLayer->pChromaPredMode[iMbXy] = uiCode; | 578 | pCurDqLayer->pChromaPredMode[iMbXy] = uiCode; |
| 579 | } | 579 | } |
| 580 | 580 | ||
| 581 | if (-1 == pCurDqLayer->pChromaPredMode[iMbXy] | 581 | if (-1 == pCurDqLayer->pChromaPredMode[iMbXy] |
| 582 | || CheckIntraChromaPredMode (uiNeighAvail, &pCurDqLayer->pChromaPredMode[iMbXy])) { | 582 | || CheckIntraChromaPredMode (uiNeighAvail, &pCurDqLayer->pChromaPredMode[iMbXy])) { |
| 583 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); | 583 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); |
| 584 | } | 584 | } |
| 585 | 585 | ||
| 586 | return ERR_NONE; | 586 | return ERR_NONE; |
| 587 | } | 587 | } |
| 588 | 588 | ||
| 589 | int32_t ParseIntra16x16Mode (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, PBitStringAux pBs, | 589 | int32_t ParseIntra16x16Mode (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, PBitStringAux pBs, |
| 590 | PDqLayer pCurDqLayer) { | 590 | PDqLayer pCurDqLayer) { |
| 591 | int32_t iMbXy = pCurDqLayer->iMbXyIndex; | 591 | int32_t iMbXy = pCurDqLayer->iMbXyIndex; |
| 592 | uint8_t uiNeighAvail = 0; //0x07 = 0 1 1 1, means left, top-left, top avail or not. (1: avail, 0: unavail) | 592 | uint8_t uiNeighAvail = 0; //0x07 = 0 1 1 1, means left, top-left, top avail or not. (1: avail, 0: unavail) |
| 593 | uint32_t uiCode; | 593 | uint32_t uiCode; |
| 594 | int32_t iCode; | 594 | int32_t iCode; |
| 595 | pCtx->pMap16x16NeighToSampleFunc (pNeighAvail, &uiNeighAvail); | 595 | pCtx->pMap16x16NeighToSampleFunc (pNeighAvail, &uiNeighAvail); |
| 596 | 596 | ||
| 597 | if (CheckIntra16x16PredMode (uiNeighAvail, | 597 | if (CheckIntra16x16PredMode (uiNeighAvail, |
| 598 | &pCurDqLayer->pIntraPredMode[iMbXy][7])) { //invalid iPredMode, must stop decoding | 598 | &pCurDqLayer->pIntraPredMode[iMbXy][7])) { //invalid iPredMode, must stop decoding |
| 599 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I16x16_PRED_MODE); | 599 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I16x16_PRED_MODE); |
| 600 | } | 600 | } |
| 601 | if (pCtx->pSps->uiChromaFormatIdc == 0) | 601 | if (pCtx->pSps->uiChromaFormatIdc == 0) |
| 602 | return ERR_NONE; | 602 | return ERR_NONE; |
| 603 | 603 | ||
| 604 | if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) { | 604 | if (pCurDqLayer->sLayerInfo.pPps->bEntropyCodingModeFlag) { |
| 605 | WELS_READ_VERIFY (ParseIntraPredModeChromaCabac (pCtx, uiNeighAvail, iCode)); | 605 | WELS_READ_VERIFY (ParseIntraPredModeChromaCabac (pCtx, uiNeighAvail, iCode)); |
| 606 | if (iCode > MAX_PRED_MODE_ID_CHROMA) { | 606 | if (iCode > MAX_PRED_MODE_ID_CHROMA) { |
| 607 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); | 607 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); |
| 608 | } | 608 | } |
| 609 | pCurDqLayer->pChromaPredMode[iMbXy] = iCode; | 609 | pCurDqLayer->pChromaPredMode[iMbXy] = iCode; |
| 610 | } else { | 610 | } else { |
| 611 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //intra_chroma_pred_mode | 611 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //intra_chroma_pred_mode |
| 612 | if (uiCode > MAX_PRED_MODE_ID_CHROMA) { | 612 | if (uiCode > MAX_PRED_MODE_ID_CHROMA) { |
| 613 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); | 613 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); |
| 614 | } | 614 | } |
| 615 | pCurDqLayer->pChromaPredMode[iMbXy] = uiCode; | 615 | pCurDqLayer->pChromaPredMode[iMbXy] = uiCode; |
| 616 | } | 616 | } |
| 617 | if (-1 == pCurDqLayer->pChromaPredMode[iMbXy] | 617 | if (-1 == pCurDqLayer->pChromaPredMode[iMbXy] |
| 618 | || CheckIntraChromaPredMode (uiNeighAvail, &pCurDqLayer->pChromaPredMode[iMbXy])) { | 618 | || CheckIntraChromaPredMode (uiNeighAvail, &pCurDqLayer->pChromaPredMode[iMbXy])) { |
| 619 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); | 619 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_I_CHROMA_PRED_MODE); |
| 620 | } | 620 | } |
| 621 | 621 | ||
| 622 | return ERR_NONE; | 622 | return ERR_NONE; |
| 623 | } | 623 | } |
| 624 | 624 | ||
| 625 | int32_t WelsDecodeMbCabacISliceBaseMode0 (PWelsDecoderContext pCtx, uint32_t& uiEosFlag) { | 625 | int32_t WelsDecodeMbCabacISliceBaseMode0 (PWelsDecoderContext pCtx, uint32_t& uiEosFlag) { |
| 626 | PDqLayer pCurLayer = pCtx->pCurDqLayer; | 626 | PDqLayer pCurLayer = pCtx->pCurDqLayer; |
| 627 | PBitStringAux pBsAux = pCurLayer->pBitStringAux; | 627 | PBitStringAux pBsAux = pCurLayer->pBitStringAux; |
| 628 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; | 628 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; |
| 629 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | 629 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; |
| 630 | SWelsNeighAvail sNeighAvail; | 630 | SWelsNeighAvail sNeighAvail; |
| 631 | int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart; | 631 | int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart; |
| 632 | int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd; | 632 | int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd; |
| 633 | int32_t iMbXy = pCurLayer->iMbXyIndex; | 633 | int32_t iMbXy = pCurLayer->iMbXyIndex; |
| 634 | int32_t i; | 634 | int32_t i; |
| 635 | uint32_t uiMbType = 0, uiCbp = 0, uiCbpLuma = 0, uiCbpChroma = 0; | 635 | uint32_t uiMbType = 0, uiCbp = 0, uiCbpLuma = 0, uiCbpChroma = 0; |
| 636 | 636 | ||
| 637 | ENFORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16); | 637 | ENFORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16); |
| 638 | 638 | ||
| 639 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; | 639 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; |
| 640 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; | 640 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; |
| 641 | 641 | ||
| 642 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; | 642 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; |
| 643 | pCurLayer->pResidualPredFlag[iMbXy] = pSlice->sSliceHeaderExt.bDefaultResidualPredFlag; | 643 | pCurLayer->pResidualPredFlag[iMbXy] = pSlice->sSliceHeaderExt.bDefaultResidualPredFlag; |
| 644 | GetNeighborAvailMbType (&sNeighAvail, pCurLayer); | 644 | GetNeighborAvailMbType (&sNeighAvail, pCurLayer); |
| 645 | WELS_READ_VERIFY (ParseMBTypeISliceCabac (pCtx, &sNeighAvail, uiMbType)); | 645 | WELS_READ_VERIFY (ParseMBTypeISliceCabac (pCtx, &sNeighAvail, uiMbType)); |
| 646 | if (uiMbType > 25) { | 646 | if (uiMbType > 25) { |
| 647 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); | 647 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); |
| 648 | } else if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 | 648 | } else if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 |
| 649 | && uiMbType <= 24))) { | 649 | && uiMbType <= 24))) { |
| 650 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); | 650 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); |
| 651 | } else if (25 == uiMbType) { //I_PCM | 651 | } else if (25 == uiMbType) { //I_PCM |
| 652 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "I_PCM mode exists in I slice!"); | 652 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "I_PCM mode exists in I slice!"); |
| 653 | WELS_READ_VERIFY (ParseIPCMInfoCabac (pCtx)); | 653 | WELS_READ_VERIFY (ParseIPCMInfoCabac (pCtx)); |
| 654 | pSlice->iLastDeltaQp = 0; | 654 | pSlice->iLastDeltaQp = 0; |
| 655 | WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag)); | 655 | WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag)); |
| 656 | if (uiEosFlag) { | 656 | if (uiEosFlag) { |
| 657 | RestoreCabacDecEngineToBS (pCtx->pCabacDecEngine, pCtx->pCurDqLayer->pBitStringAux); | 657 | RestoreCabacDecEngineToBS (pCtx->pCabacDecEngine, pCtx->pCurDqLayer->pBitStringAux); |
| 658 | } | 658 | } |
| 659 | return ERR_NONE; | 659 | return ERR_NONE; |
| 660 | } else if (0 == uiMbType) { //I4x4 | 660 | } else if (0 == uiMbType) { //I4x4 |
| 661 | ENFORCE_STACK_ALIGN_1D (int8_t, pIntraPredMode, 48, 16); | 661 | ENFORCE_STACK_ALIGN_1D (int8_t, pIntraPredMode, 48, 16); |
| 662 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA4x4; | 662 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA4x4; |
| 663 | if (pCtx->pPps->bTransform8x8ModeFlag) { | 663 | if (pCtx->pPps->bTransform8x8ModeFlag) { |
| 664 | // Transform 8x8 cabac will be added soon | 664 | // Transform 8x8 cabac will be added soon |
| 665 | WELS_READ_VERIFY (ParseTransformSize8x8FlagCabac (pCtx, &sNeighAvail, pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy])); | 665 | WELS_READ_VERIFY (ParseTransformSize8x8FlagCabac (pCtx, &sNeighAvail, pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy])); |
| 666 | } | 666 | } |
| 667 | if (pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { | 667 | if (pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { |
| 668 | uiMbType = pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA8x8; | 668 | uiMbType = pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA8x8; |
| 669 | pCtx->pFillInfoCacheIntraNxNFunc (&sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); | 669 | pCtx->pFillInfoCacheIntraNxNFunc (&sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); |
| 670 | WELS_READ_VERIFY (ParseIntra8x8Mode (pCtx, &sNeighAvail, pIntraPredMode, pBsAux, pCurLayer)); | 670 | WELS_READ_VERIFY (ParseIntra8x8Mode (pCtx, &sNeighAvail, pIntraPredMode, pBsAux, pCurLayer)); |
| 671 | } else { | 671 | } else { |
| 672 | pCtx->pFillInfoCacheIntraNxNFunc (&sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); | 672 | pCtx->pFillInfoCacheIntraNxNFunc (&sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); |
| 673 | WELS_READ_VERIFY (ParseIntra4x4Mode (pCtx, &sNeighAvail, pIntraPredMode, pBsAux, pCurLayer)); | 673 | WELS_READ_VERIFY (ParseIntra4x4Mode (pCtx, &sNeighAvail, pIntraPredMode, pBsAux, pCurLayer)); |
| 674 | } | 674 | } |
| 675 | //get uiCbp for I4x4 | 675 | //get uiCbp for I4x4 |
| 676 | WELS_READ_VERIFY (ParseCbpInfoCabac (pCtx, &sNeighAvail, uiCbp)); | 676 | WELS_READ_VERIFY (ParseCbpInfoCabac (pCtx, &sNeighAvail, uiCbp)); |
| 677 | pCurLayer->pCbp[iMbXy] = uiCbp; | 677 | pCurLayer->pCbp[iMbXy] = uiCbp; |
| 678 | pSlice->iLastDeltaQp = uiCbp == 0 ? 0 : pSlice->iLastDeltaQp; | 678 | pSlice->iLastDeltaQp = uiCbp == 0 ? 0 : pSlice->iLastDeltaQp; |
| 679 | uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? uiCbp >> 4 : 0; | 679 | uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? uiCbp >> 4 : 0; |
| 680 | uiCbpLuma = uiCbp & 15; | 680 | uiCbpLuma = uiCbp & 15; |
| 681 | } else { //I16x16; | 681 | } else { //I16x16; |
| 682 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16; | 682 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16; |
| 683 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; | 683 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; |
| 684 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; | 684 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; |
| 685 | pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3; | 685 | pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3; |
| 686 | pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2]; | 686 | pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2]; |
| 687 | uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0 ; | 687 | uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0 ; |
| 688 | uiCbpLuma = pCurLayer->pCbp[iMbXy] & 15; | 688 | uiCbpLuma = pCurLayer->pCbp[iMbXy] & 15; |
| 689 | WelsFillCacheNonZeroCount (&sNeighAvail, pNonZeroCount, pCurLayer); | 689 | WelsFillCacheNonZeroCount (&sNeighAvail, pNonZeroCount, pCurLayer); |
| 690 | WELS_READ_VERIFY (ParseIntra16x16Mode (pCtx, &sNeighAvail, pBsAux, pCurLayer)); | 690 | WELS_READ_VERIFY (ParseIntra16x16Mode (pCtx, &sNeighAvail, pBsAux, pCurLayer)); |
| 691 | } | 691 | } |
| 692 | 692 | ||
| 693 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); | 693 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); |
| 694 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); | 694 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); |
| 695 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); | 695 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); |
| 696 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); | 696 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); |
| 697 | ST32 (&pCurLayer->pNzc[iMbXy][16], 0); | 697 | ST32 (&pCurLayer->pNzc[iMbXy][16], 0); |
| 698 | ST32 (&pCurLayer->pNzc[iMbXy][20], 0); | 698 | ST32 (&pCurLayer->pNzc[iMbXy][20], 0); |
| 699 | pCurLayer->pCbfDc[iMbXy] = 0; | 699 | pCurLayer->pCbfDc[iMbXy] = 0; |
| 700 | 700 | ||
| 701 | if (pCurLayer->pCbp[iMbXy] == 0 && IS_INTRANxN (pCurLayer->pMbType[iMbXy])) { | 701 | if (pCurLayer->pCbp[iMbXy] == 0 && IS_INTRANxN (pCurLayer->pMbType[iMbXy])) { |
| 702 | pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; | 702 | pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; |
| 703 | for (i = 0; i < 2; i++) { | 703 | for (i = 0; i < 2; i++) { |
| 704 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 ((pCurLayer->pLumaQp[iMbXy] + | 704 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 ((pCurLayer->pLumaQp[iMbXy] + |
| 705 | pSliceHeader->pPps->iChromaQpIndexOffset[i]), 0, 51)]; | 705 | pSliceHeader->pPps->iChromaQpIndexOffset[i]), 0, 51)]; |
| 706 | } | 706 | } |
| 707 | } | 707 | } |
| 708 | 708 | ||
| 709 | if (pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { | 709 | if (pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { |
| 710 | memset (pCurLayer->pScaledTCoeff[iMbXy], 0, 384 * sizeof (pCurLayer->pScaledTCoeff[iMbXy][0])); | 710 | memset (pCurLayer->pScaledTCoeff[iMbXy], 0, 384 * sizeof (pCurLayer->pScaledTCoeff[iMbXy][0])); |
| 711 | int32_t iQpDelta, iId8x8, iId4x4; | 711 | int32_t iQpDelta, iId8x8, iId4x4; |
| 712 | WELS_READ_VERIFY (ParseDeltaQpCabac (pCtx, iQpDelta)); | 712 | WELS_READ_VERIFY (ParseDeltaQpCabac (pCtx, iQpDelta)); |
| 713 | if (iQpDelta > 25 || iQpDelta < -26) {//out of iQpDelta range | 713 | if (iQpDelta > 25 || iQpDelta < -26) {//out of iQpDelta range |
| 714 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_QP); | 714 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_QP); |
| 715 | } | 715 | } |
| 716 | pCurLayer->pLumaQp[iMbXy] = (pSlice->iLastMbQp + iQpDelta + 52) % 52; //update last_mb_qp | 716 | pCurLayer->pLumaQp[iMbXy] = (pSlice->iLastMbQp + iQpDelta + 52) % 52; //update last_mb_qp |
| 717 | pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy]; | 717 | pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy]; |
| 718 | for (i = 0; i < 2; i++) { | 718 | for (i = 0; i < 2; i++) { |
| 719 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 ((pSlice->iLastMbQp + | 719 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 ((pSlice->iLastMbQp + |
| 720 | pSliceHeader->pPps->iChromaQpIndexOffset[i]), 0, 51)]; | 720 | pSliceHeader->pPps->iChromaQpIndexOffset[i]), 0, 51)]; |
| 721 | } | 721 | } |
| 722 | if (MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { | 722 | if (MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { |
| 723 | //step1: Luma DC | 723 | //step1: Luma DC |
| 724 | WELS_READ_VERIFY (ParseResidualBlockCabac (&sNeighAvail, pNonZeroCount, pBsAux, 0, 16, g_kuiLumaDcZigzagScan, | 724 | WELS_READ_VERIFY (ParseResidualBlockCabac (&sNeighAvail, pNonZeroCount, pBsAux, 0, 16, g_kuiLumaDcZigzagScan, |
| 725 | I16_LUMA_DC, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx)); | 725 | I16_LUMA_DC, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx)); |
| 726 | //step2: Luma AC | 726 | //step2: Luma AC |
| 727 | if (uiCbpLuma) { | 727 | if (uiCbpLuma) { |
| 728 | for (i = 0; i < 16; i++) { | 728 | for (i = 0; i < 16; i++) { |
| 729 | WELS_READ_VERIFY (ParseResidualBlockCabac (&sNeighAvail, pNonZeroCount, pBsAux, i, | 729 | WELS_READ_VERIFY (ParseResidualBlockCabac (&sNeighAvail, pNonZeroCount, pBsAux, i, |
| 730 | iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), I16_LUMA_AC, | 730 | iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), I16_LUMA_AC, |
| 731 | pCurLayer->pScaledTCoeff[iMbXy] + (i << 4), pCurLayer->pLumaQp[iMbXy], pCtx)); | 731 | pCurLayer->pScaledTCoeff[iMbXy] + (i << 4), pCurLayer->pLumaQp[iMbXy], pCtx)); |
| 732 | } | 732 | } |
| 733 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); | 733 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); |
| 734 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); | 734 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); |
| 735 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); | 735 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); |
| 736 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); | 736 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); |
| 737 | } else { //pNonZeroCount = 0 | 737 | } else { //pNonZeroCount = 0 |
| 738 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); | 738 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); |
| 739 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); | 739 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); |
| 740 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); | 740 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); |
| 741 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); | 741 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); |
| 742 | } | 742 | } |
| 743 | } else { //non-MB_TYPE_INTRA16x16 | 743 | } else { //non-MB_TYPE_INTRA16x16 |
| 744 | if (pCurLayer->pTransformSize8x8Flag[iMbXy]) { | 744 | if (pCurLayer->pTransformSize8x8Flag[iMbXy]) { |
| 745 | // Transform 8x8 support for CABAC | 745 | // Transform 8x8 support for CABAC |
| 746 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { | 746 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { |
| 747 | if (uiCbpLuma & (1 << iId8x8)) { | 747 | if (uiCbpLuma & (1 << iId8x8)) { |
| 748 | WELS_READ_VERIFY (ParseResidualBlockCabac8x8 (&sNeighAvail, pNonZeroCount, pBsAux, (iId8x8 << 2), | 748 | WELS_READ_VERIFY (ParseResidualBlockCabac8x8 (&sNeighAvail, pNonZeroCount, pBsAux, (iId8x8 << 2), |
| 749 | iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan8x8 + iScanIdxStart, LUMA_DC_AC_INTRA_8, | 749 | iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan8x8 + iScanIdxStart, LUMA_DC_AC_INTRA_8, |
| 750 | pCurLayer->pScaledTCoeff[iMbXy] + (iId8x8 << 6), pCurLayer->pLumaQp[iMbXy], pCtx)); | 750 | pCurLayer->pScaledTCoeff[iMbXy] + (iId8x8 << 6), pCurLayer->pLumaQp[iMbXy], pCtx)); |
| 751 | } else { | 751 | } else { |
| 752 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2)]], 0); | 752 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2)]], 0); |
| 753 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2) + 2]], 0); | 753 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2) + 2]], 0); |
| 754 | } | 754 | } |
| 755 | } | 755 | } |
| 756 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); | 756 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); |
| 757 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); | 757 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); |
| 758 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); | 758 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); |
| 759 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); | 759 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); |
| 760 | } else { | 760 | } else { |
| 761 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { | 761 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { |
| 762 | if (uiCbpLuma & (1 << iId8x8)) { | 762 | if (uiCbpLuma & (1 << iId8x8)) { |
| 763 | int32_t iIdx = (iId8x8 << 2); | 763 | int32_t iIdx = (iId8x8 << 2); |
| 764 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { | 764 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 765 | //Luma (DC and AC decoding together) | 765 | //Luma (DC and AC decoding together) |
| 766 | WELS_READ_VERIFY (ParseResidualBlockCabac (&sNeighAvail, pNonZeroCount, pBsAux, iIdx, iScanIdxEnd - iScanIdxStart + 1, | 766 | WELS_READ_VERIFY (ParseResidualBlockCabac (&sNeighAvail, pNonZeroCount, pBsAux, iIdx, iScanIdxEnd - iScanIdxStart + 1, |
| 767 | g_kuiZigzagScan + iScanIdxStart, LUMA_DC_AC_INTRA, pCurLayer->pScaledTCoeff[iMbXy] + (iIdx << 4), | 767 | g_kuiZigzagScan + iScanIdxStart, LUMA_DC_AC_INTRA, pCurLayer->pScaledTCoeff[iMbXy] + (iIdx << 4), |
| 768 | pCurLayer->pLumaQp[iMbXy], pCtx)); | 768 | pCurLayer->pLumaQp[iMbXy], pCtx)); |
| 769 | iIdx++; | 769 | iIdx++; |
| 770 | } | 770 | } |
| 771 | } else { | 771 | } else { |
| 772 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2)]], 0); | 772 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2)]], 0); |
| 773 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2) + 2]], 0); | 773 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2) + 2]], 0); |
| 774 | } | 774 | } |
| 775 | } | 775 | } |
| 776 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); | 776 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); |
| 777 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); | 777 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); |
| 778 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); | 778 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); |
| 779 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); | 779 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); |
| 780 | } | 780 | } |
| 781 | } | 781 | } |
| 782 | int32_t iMbResProperty; | 782 | int32_t iMbResProperty; |
| 783 | //chroma | 783 | //chroma |
| 784 | //step1: DC | 784 | //step1: DC |
| 785 | if (1 == uiCbpChroma || 2 == uiCbpChroma) { | 785 | if (1 == uiCbpChroma || 2 == uiCbpChroma) { |
| 786 | //Cb Cr | 786 | //Cb Cr |
| 787 | for (i = 0; i < 2; i++) { | 787 | for (i = 0; i < 2; i++) { |
| 788 | iMbResProperty = i ? CHROMA_DC_V : CHROMA_DC_U; | 788 | iMbResProperty = i ? CHROMA_DC_V : CHROMA_DC_U; |
| 789 | WELS_READ_VERIFY (ParseResidualBlockCabac (&sNeighAvail, pNonZeroCount, pBsAux, 16 + (i << 2), 4, g_kuiChromaDcScan, | 789 | WELS_READ_VERIFY (ParseResidualBlockCabac (&sNeighAvail, pNonZeroCount, pBsAux, 16 + (i << 2), 4, g_kuiChromaDcScan, |
| 790 | iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6), pCurLayer->pChromaQp[iMbXy][i], pCtx)); | 790 | iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6), pCurLayer->pChromaQp[iMbXy][i], pCtx)); |
| 791 | } | 791 | } |
| 792 | } | 792 | } |
| 793 | 793 | ||
| 794 | //step2: AC | 794 | //step2: AC |
| 795 | if (2 == uiCbpChroma) { | 795 | if (2 == uiCbpChroma) { |
| 796 | for (i = 0; i < 2; i++) { //Cb Cr | 796 | for (i = 0; i < 2; i++) { //Cb Cr |
| 797 | iMbResProperty = i ? CHROMA_AC_V : CHROMA_AC_U; | 797 | iMbResProperty = i ? CHROMA_AC_V : CHROMA_AC_U; |
| 798 | int32_t iIdx = 16 + (i << 2); | 798 | int32_t iIdx = 16 + (i << 2); |
| 799 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { | 799 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 800 | WELS_READ_VERIFY (ParseResidualBlockCabac (&sNeighAvail, pNonZeroCount, pBsAux, iIdx, | 800 | WELS_READ_VERIFY (ParseResidualBlockCabac (&sNeighAvail, pNonZeroCount, pBsAux, iIdx, |
| 801 | iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), iMbResProperty, | 801 | iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), iMbResProperty, |
| 802 | pCurLayer->pScaledTCoeff[iMbXy] + (iIdx << 4), pCurLayer->pChromaQp[iMbXy][i], pCtx)); | 802 | pCurLayer->pScaledTCoeff[iMbXy] + (iIdx << 4), pCurLayer->pChromaQp[iMbXy][i], pCtx)); |
| 803 | iIdx++; | 803 | iIdx++; |
| 804 | } | 804 | } |
| 805 | } | 805 | } |
| 806 | ST16 (&pCurLayer->pNzc[iMbXy][16], LD16 (&pNonZeroCount[6 + 8 * 1])); | 806 | ST16 (&pCurLayer->pNzc[iMbXy][16], LD16 (&pNonZeroCount[6 + 8 * 1])); |
| 807 | ST16 (&pCurLayer->pNzc[iMbXy][20], LD16 (&pNonZeroCount[6 + 8 * 2])); | 807 | ST16 (&pCurLayer->pNzc[iMbXy][20], LD16 (&pNonZeroCount[6 + 8 * 2])); |
| 808 | ST16 (&pCurLayer->pNzc[iMbXy][18], LD16 (&pNonZeroCount[6 + 8 * 4])); | 808 | ST16 (&pCurLayer->pNzc[iMbXy][18], LD16 (&pNonZeroCount[6 + 8 * 4])); |
| 809 | ST16 (&pCurLayer->pNzc[iMbXy][22], LD16 (&pNonZeroCount[6 + 8 * 5])); | 809 | ST16 (&pCurLayer->pNzc[iMbXy][22], LD16 (&pNonZeroCount[6 + 8 * 5])); |
| 810 | } else { | 810 | } else { |
| 811 | ST16 (&pCurLayer->pNzc[iMbXy][16], 0); | 811 | ST16 (&pCurLayer->pNzc[iMbXy][16], 0); |
| 812 | ST16 (&pCurLayer->pNzc[iMbXy][20], 0); | 812 | ST16 (&pCurLayer->pNzc[iMbXy][20], 0); |
| 813 | ST16 (&pCurLayer->pNzc[iMbXy][18], 0); | 813 | ST16 (&pCurLayer->pNzc[iMbXy][18], 0); |
| 814 | ST16 (&pCurLayer->pNzc[iMbXy][22], 0); | 814 | ST16 (&pCurLayer->pNzc[iMbXy][22], 0); |
| 815 | } | 815 | } |
| 816 | } else { | 816 | } else { |
| 817 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); | 817 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); |
| 818 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); | 818 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); |
| 819 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); | 819 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); |
| 820 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); | 820 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); |
| 821 | ST32 (&pCurLayer->pNzc[iMbXy][16], 0); | 821 | ST32 (&pCurLayer->pNzc[iMbXy][16], 0); |
| 822 | ST32 (&pCurLayer->pNzc[iMbXy][20], 0); | 822 | ST32 (&pCurLayer->pNzc[iMbXy][20], 0); |
| 823 | } | 823 | } |
| 824 | 824 | ||
| 825 | WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag)); | 825 | WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag)); |
| 826 | if (uiEosFlag) { | 826 | if (uiEosFlag) { |
| 827 | RestoreCabacDecEngineToBS (pCtx->pCabacDecEngine, pCtx->pCurDqLayer->pBitStringAux); | 827 | RestoreCabacDecEngineToBS (pCtx->pCabacDecEngine, pCtx->pCurDqLayer->pBitStringAux); |
| 828 | } | 828 | } |
| 829 | return ERR_NONE; | 829 | return ERR_NONE; |
| 830 | } | 830 | } |
| 831 | 831 | ||
| 832 | int32_t WelsDecodeMbCabacISlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uint32_t& uiEosFlag) { | 832 | int32_t WelsDecodeMbCabacISlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uint32_t& uiEosFlag) { |
| 833 | WELS_READ_VERIFY (WelsDecodeMbCabacISliceBaseMode0 (pCtx, uiEosFlag)); | 833 | WELS_READ_VERIFY (WelsDecodeMbCabacISliceBaseMode0 (pCtx, uiEosFlag)); |
| 834 | return ERR_NONE; | 834 | return ERR_NONE; |
| 835 | } | 835 | } |
| 836 | 836 | ||
| 837 | int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiEosFlag) { | 837 | int32_t WelsDecodeMbCabacPSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiEosFlag) { |
| 838 | PDqLayer pCurLayer = pCtx->pCurDqLayer; | 838 | PDqLayer pCurLayer = pCtx->pCurDqLayer; |
| 839 | PBitStringAux pBsAux = pCurLayer->pBitStringAux; | 839 | PBitStringAux pBsAux = pCurLayer->pBitStringAux; |
| 840 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; | 840 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; |
| 841 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | 841 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; |
| 842 | 842 | ||
| 843 | int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart; | 843 | int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart; |
| 844 | int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd; | 844 | int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd; |
| 845 | int32_t iMbXy = pCurLayer->iMbXyIndex; | 845 | int32_t iMbXy = pCurLayer->iMbXyIndex; |
| 846 | int32_t iMbResProperty; | 846 | int32_t iMbResProperty; |
| 847 | int32_t i; | 847 | int32_t i; |
| 848 | uint32_t uiMbType = 0, uiCbp = 0, uiCbpLuma = 0, uiCbpChroma = 0; | 848 | uint32_t uiMbType = 0, uiCbp = 0, uiCbpLuma = 0, uiCbpChroma = 0; |
| 849 | 849 | ||
| 850 | ENFORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16); | 850 | ENFORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16); |
| 851 | 851 | ||
| 852 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; | 852 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; |
| 853 | 853 | ||
| 854 | WELS_READ_VERIFY (ParseMBTypePSliceCabac (pCtx, pNeighAvail, uiMbType)); | 854 | WELS_READ_VERIFY (ParseMBTypePSliceCabac (pCtx, pNeighAvail, uiMbType)); |
| 855 | // uiMbType = 4 is not allowded. | 855 | // uiMbType = 4 is not allowded. |
| 856 | if (uiMbType < 4) { //Inter mode | 856 | if (uiMbType < 4) { //Inter mode |
| 857 | int16_t pMotionVector[LIST_A][30][MV_A]; | 857 | int16_t pMotionVector[LIST_A][30][MV_A]; |
| 858 | int16_t pMvdCache[LIST_A][30][MV_A]; | 858 | int16_t pMvdCache[LIST_A][30][MV_A]; |
| 859 | int8_t pRefIndex[LIST_A][30]; | 859 | int8_t pRefIndex[LIST_A][30]; |
| 860 | pCurLayer->pMbType[iMbXy] = g_ksInterPMbTypeInfo[uiMbType].iType; | 860 | pCurLayer->pMbType[iMbXy] = g_ksInterPMbTypeInfo[uiMbType].iType; |
| 861 | WelsFillCacheInterCabac (pNeighAvail, pNonZeroCount, pMotionVector, pMvdCache, pRefIndex, pCurLayer); | 861 | WelsFillCacheInterCabac (pNeighAvail, pNonZeroCount, pMotionVector, pMvdCache, pRefIndex, pCurLayer); |
| 862 | WELS_READ_VERIFY (ParseInterPMotionInfoCabac (pCtx, pNeighAvail, pNonZeroCount, pMotionVector, pMvdCache, pRefIndex)); | 862 | WELS_READ_VERIFY (ParseInterPMotionInfoCabac (pCtx, pNeighAvail, pNonZeroCount, pMotionVector, pMvdCache, pRefIndex)); |
| 863 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; | 863 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; |
| 864 | } else { //Intra mode | 864 | } else { //Intra mode |
| 865 | uiMbType -= 5; | 865 | uiMbType -= 5; |
| 866 | if (uiMbType > 25) | 866 | if (uiMbType > 25) |
| 867 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); | 867 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); |
| 868 | if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 && uiMbType <= 24))) | 868 | if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 && uiMbType <= 24))) |
| 869 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); | 869 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); |
| 870 | 870 | ||
| 871 | if (25 == uiMbType) { //I_PCM | 871 | if (25 == uiMbType) { //I_PCM |
| 872 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "I_PCM mode exists in P slice!"); | 872 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "I_PCM mode exists in P slice!"); |
| 873 | WELS_READ_VERIFY (ParseIPCMInfoCabac (pCtx)); | 873 | WELS_READ_VERIFY (ParseIPCMInfoCabac (pCtx)); |
| 874 | pSlice->iLastDeltaQp = 0; | 874 | pSlice->iLastDeltaQp = 0; |
| 875 | WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag)); | 875 | WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag)); |
| 876 | if (uiEosFlag) { | 876 | if (uiEosFlag) { |
| 877 | RestoreCabacDecEngineToBS (pCtx->pCabacDecEngine, pCtx->pCurDqLayer->pBitStringAux); | 877 | RestoreCabacDecEngineToBS (pCtx->pCabacDecEngine, pCtx->pCurDqLayer->pBitStringAux); |
| 878 | } | 878 | } |
| 879 | return ERR_NONE; | 879 | return ERR_NONE; |
| 880 | } else { //normal Intra mode | 880 | } else { //normal Intra mode |
| 881 | if (0 == uiMbType) { //Intra4x4 | 881 | if (0 == uiMbType) { //Intra4x4 |
| 882 | ENFORCE_STACK_ALIGN_1D (int8_t, pIntraPredMode, 48, 16); | 882 | ENFORCE_STACK_ALIGN_1D (int8_t, pIntraPredMode, 48, 16); |
| 883 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA4x4; | 883 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA4x4; |
| 884 | if (pCtx->pPps->bTransform8x8ModeFlag) { | 884 | if (pCtx->pPps->bTransform8x8ModeFlag) { |
| 885 | WELS_READ_VERIFY (ParseTransformSize8x8FlagCabac (pCtx, pNeighAvail, pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy])); | 885 | WELS_READ_VERIFY (ParseTransformSize8x8FlagCabac (pCtx, pNeighAvail, pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy])); |
| 886 | } | 886 | } |
| 887 | if (pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { | 887 | if (pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { |
| 888 | uiMbType = pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA8x8; | 888 | uiMbType = pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA8x8; |
| 889 | pCtx->pFillInfoCacheIntraNxNFunc (pNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); | 889 | pCtx->pFillInfoCacheIntraNxNFunc (pNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); |
| 890 | WELS_READ_VERIFY (ParseIntra8x8Mode (pCtx, pNeighAvail, pIntraPredMode, pBsAux, pCurLayer)); | 890 | WELS_READ_VERIFY (ParseIntra8x8Mode (pCtx, pNeighAvail, pIntraPredMode, pBsAux, pCurLayer)); |
| 891 | } else { | 891 | } else { |
| 892 | pCtx->pFillInfoCacheIntraNxNFunc (pNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); | 892 | pCtx->pFillInfoCacheIntraNxNFunc (pNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); |
| 893 | WELS_READ_VERIFY (ParseIntra4x4Mode (pCtx, pNeighAvail, pIntraPredMode, pBsAux, pCurLayer)); | 893 | WELS_READ_VERIFY (ParseIntra4x4Mode (pCtx, pNeighAvail, pIntraPredMode, pBsAux, pCurLayer)); |
| 894 | } | 894 | } |
| 895 | } else { //Intra16x16 | 895 | } else { //Intra16x16 |
| 896 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16; | 896 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16; |
| 897 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; | 897 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; |
| 898 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; | 898 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; |
| 899 | pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3; | 899 | pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3; |
| 900 | pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2]; | 900 | pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2]; |
| 901 | uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0; | 901 | uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0; |
| 902 | uiCbpLuma = pCurLayer->pCbp[iMbXy] & 15; | 902 | uiCbpLuma = pCurLayer->pCbp[iMbXy] & 15; |
| 903 | WelsFillCacheNonZeroCount (pNeighAvail, pNonZeroCount, pCurLayer); | 903 | WelsFillCacheNonZeroCount (pNeighAvail, pNonZeroCount, pCurLayer); |
| 904 | WELS_READ_VERIFY (ParseIntra16x16Mode (pCtx, pNeighAvail, pBsAux, pCurLayer)); | 904 | WELS_READ_VERIFY (ParseIntra16x16Mode (pCtx, pNeighAvail, pBsAux, pCurLayer)); |
| 905 | } | 905 | } |
| 906 | } | 906 | } |
| 907 | } | 907 | } |
| 908 | 908 | ||
| 909 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); | 909 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); |
| 910 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); | 910 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); |
| 911 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); | 911 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); |
| 912 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); | 912 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); |
| 913 | ST32 (&pCurLayer->pNzc[iMbXy][16], 0); | 913 | ST32 (&pCurLayer->pNzc[iMbXy][16], 0); |
| 914 | ST32 (&pCurLayer->pNzc[iMbXy][20], 0); | 914 | ST32 (&pCurLayer->pNzc[iMbXy][20], 0); |
| 915 | 915 | ||
| 916 | if (MB_TYPE_INTRA16x16 != pCurLayer->pMbType[iMbXy]) { | 916 | if (MB_TYPE_INTRA16x16 != pCurLayer->pMbType[iMbXy]) { |
| 917 | WELS_READ_VERIFY (ParseCbpInfoCabac (pCtx, pNeighAvail, uiCbp)); | 917 | WELS_READ_VERIFY (ParseCbpInfoCabac (pCtx, pNeighAvail, uiCbp)); |
| 918 | 918 | ||
| 919 | pCurLayer->pCbp[iMbXy] = uiCbp; | 919 | pCurLayer->pCbp[iMbXy] = uiCbp; |
| 920 | pSlice->iLastDeltaQp = uiCbp == 0 ? 0 : pSlice->iLastDeltaQp; | 920 | pSlice->iLastDeltaQp = uiCbp == 0 ? 0 : pSlice->iLastDeltaQp; |
| 921 | uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0 ; | 921 | uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0 ; |
| 922 | uiCbpLuma = pCurLayer->pCbp[iMbXy] & 15; | 922 | uiCbpLuma = pCurLayer->pCbp[iMbXy] & 15; |
| 923 | } | 923 | } |
| 924 | 924 | ||
| 925 | if (pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { | 925 | if (pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { |
| 926 | 926 | ||
| 927 | if (MB_TYPE_INTRA16x16 != pCurLayer->pMbType[iMbXy]) { | 927 | if (MB_TYPE_INTRA16x16 != pCurLayer->pMbType[iMbXy]) { |
| 928 | // Need modification when B picutre add in | 928 | // Need modification when B picutre add in |
| 929 | bool bNeedParseTransformSize8x8Flag = | 929 | bool bNeedParseTransformSize8x8Flag = |
| 930 | (((pCurLayer->pMbType[iMbXy] >= MB_TYPE_16x16 && pCurLayer->pMbType[iMbXy] <= MB_TYPE_8x16) | 930 | (((pCurLayer->pMbType[iMbXy] >= MB_TYPE_16x16 && pCurLayer->pMbType[iMbXy] <= MB_TYPE_8x16) |
| 931 | || pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy]) | 931 | || pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy]) |
| 932 | && (pCurLayer->pMbType[iMbXy] != MB_TYPE_INTRA8x8) | 932 | && (pCurLayer->pMbType[iMbXy] != MB_TYPE_INTRA8x8) |
| 933 | && (pCurLayer->pMbType[iMbXy] != MB_TYPE_INTRA4x4) | 933 | && (pCurLayer->pMbType[iMbXy] != MB_TYPE_INTRA4x4) |
| 934 | && ((pCurLayer->pCbp[iMbXy] & 0x0F) > 0) | 934 | && ((pCurLayer->pCbp[iMbXy] & 0x0F) > 0) |
| 935 | && (pCtx->pPps->bTransform8x8ModeFlag)); | 935 | && (pCtx->pPps->bTransform8x8ModeFlag)); |
| 936 | 936 | ||
| 937 | if (bNeedParseTransformSize8x8Flag) { | 937 | if (bNeedParseTransformSize8x8Flag) { |
| 938 | WELS_READ_VERIFY (ParseTransformSize8x8FlagCabac (pCtx, pNeighAvail, | 938 | WELS_READ_VERIFY (ParseTransformSize8x8FlagCabac (pCtx, pNeighAvail, |
| 939 | pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy])); //transform_size_8x8_flag | 939 | pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy])); //transform_size_8x8_flag |
| 940 | } | 940 | } |
| 941 | } | 941 | } |
| 942 | 942 | ||
| 943 | memset (pCurLayer->pScaledTCoeff[iMbXy], 0, 384 * sizeof (pCurLayer->pScaledTCoeff[iMbXy][0])); | 943 | memset (pCurLayer->pScaledTCoeff[iMbXy], 0, 384 * sizeof (pCurLayer->pScaledTCoeff[iMbXy][0])); |
| 944 | 944 | ||
| 945 | int32_t iQpDelta, iId8x8, iId4x4; | 945 | int32_t iQpDelta, iId8x8, iId4x4; |
| 946 | 946 | ||
| 947 | WELS_READ_VERIFY (ParseDeltaQpCabac (pCtx, iQpDelta)); | 947 | WELS_READ_VERIFY (ParseDeltaQpCabac (pCtx, iQpDelta)); |
| 948 | if (iQpDelta > 25 || iQpDelta < -26) { //out of iQpDelta range | 948 | if (iQpDelta > 25 || iQpDelta < -26) { //out of iQpDelta range |
| 949 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_QP); | 949 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_QP); |
| 950 | } | 950 | } |
| 951 | pCurLayer->pLumaQp[iMbXy] = (pSlice->iLastMbQp + iQpDelta + 52) % 52; //update last_mb_qp | 951 | pCurLayer->pLumaQp[iMbXy] = (pSlice->iLastMbQp + iQpDelta + 52) % 52; //update last_mb_qp |
| 952 | pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy]; | 952 | pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy]; |
| 953 | for (i = 0; i < 2; i++) { | 953 | for (i = 0; i < 2; i++) { |
| 954 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pSlice->iLastMbQp + | 954 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pSlice->iLastMbQp + |
| 955 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; | 955 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; |
| 956 | } | 956 | } |
| 957 | 957 | ||
| 958 | if (MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { | 958 | if (MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { |
| 959 | //step1: Luma DC | 959 | //step1: Luma DC |
| 960 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, 0, 16, g_kuiLumaDcZigzagScan, | 960 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, 0, 16, g_kuiLumaDcZigzagScan, |
| 961 | I16_LUMA_DC, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx)); | 961 | I16_LUMA_DC, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx)); |
| 962 | //step2: Luma AC | 962 | //step2: Luma AC |
| 963 | if (uiCbpLuma) { | 963 | if (uiCbpLuma) { |
| 964 | for (i = 0; i < 16; i++) { | 964 | for (i = 0; i < 16; i++) { |
| 965 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, i, iScanIdxEnd - WELS_MAX (iScanIdxStart, | 965 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, i, iScanIdxEnd - WELS_MAX (iScanIdxStart, |
| 966 | 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i << 4), | 966 | 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i << 4), |
| 967 | pCurLayer->pLumaQp[iMbXy], pCtx)); | 967 | pCurLayer->pLumaQp[iMbXy], pCtx)); |
| 968 | } | 968 | } |
| 969 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); | 969 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); |
| 970 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); | 970 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); |
| 971 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); | 971 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); |
| 972 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); | 972 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); |
| 973 | } else { | 973 | } else { |
| 974 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); | 974 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); |
| 975 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); | 975 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); |
| 976 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); | 976 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); |
| 977 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); | 977 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); |
| 978 | } | 978 | } |
| 979 | } else { //non-MB_TYPE_INTRA16x16 | 979 | } else { //non-MB_TYPE_INTRA16x16 |
| 980 | if (pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { | 980 | if (pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { |
| 981 | // Transform 8x8 support for CABAC | 981 | // Transform 8x8 support for CABAC |
| 982 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { | 982 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { |
| 983 | if (uiCbpLuma & (1 << iId8x8)) { | 983 | if (uiCbpLuma & (1 << iId8x8)) { |
| 984 | WELS_READ_VERIFY (ParseResidualBlockCabac8x8 (pNeighAvail, pNonZeroCount, pBsAux, (iId8x8 << 2), | 984 | WELS_READ_VERIFY (ParseResidualBlockCabac8x8 (pNeighAvail, pNonZeroCount, pBsAux, (iId8x8 << 2), |
| 985 | iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan8x8 + iScanIdxStart, | 985 | iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan8x8 + iScanIdxStart, |
| 986 | IS_INTRA (pCurLayer->pMbType[iMbXy]) ? LUMA_DC_AC_INTRA_8 : LUMA_DC_AC_INTER_8, | 986 | IS_INTRA (pCurLayer->pMbType[iMbXy]) ? LUMA_DC_AC_INTRA_8 : LUMA_DC_AC_INTER_8, |
| 987 | pCurLayer->pScaledTCoeff[iMbXy] + (iId8x8 << 6), pCurLayer->pLumaQp[iMbXy], pCtx)); | 987 | pCurLayer->pScaledTCoeff[iMbXy] + (iId8x8 << 6), pCurLayer->pLumaQp[iMbXy], pCtx)); |
| 988 | } else { | 988 | } else { |
| 989 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2)]], 0); | 989 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2)]], 0); |
| 990 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2) + 2]], 0); | 990 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2) + 2]], 0); |
| 991 | } | 991 | } |
| 992 | } | 992 | } |
| 993 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); | 993 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); |
| 994 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); | 994 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); |
| 995 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); | 995 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); |
| 996 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); | 996 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); |
| 997 | } else { | 997 | } else { |
| 998 | iMbResProperty = (IS_INTRA (pCurLayer->pMbType[iMbXy])) ? LUMA_DC_AC_INTRA : LUMA_DC_AC_INTER; | 998 | iMbResProperty = (IS_INTRA (pCurLayer->pMbType[iMbXy])) ? LUMA_DC_AC_INTRA : LUMA_DC_AC_INTER; |
| 999 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { | 999 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { |
| 1000 | if (uiCbpLuma & (1 << iId8x8)) { | 1000 | if (uiCbpLuma & (1 << iId8x8)) { |
| 1001 | int32_t iIdx = (iId8x8 << 2); | 1001 | int32_t iIdx = (iId8x8 << 2); |
| 1002 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { | 1002 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 1003 | //Luma (DC and AC decoding together) | 1003 | //Luma (DC and AC decoding together) |
| 1004 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, iIdx, iScanIdxEnd - iScanIdxStart + 1, | 1004 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, iIdx, iScanIdxEnd - iScanIdxStart + 1, |
| 1005 | g_kuiZigzagScan + iScanIdxStart, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIdx << 4), | 1005 | g_kuiZigzagScan + iScanIdxStart, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIdx << 4), |
| 1006 | pCurLayer->pLumaQp[iMbXy], | 1006 | pCurLayer->pLumaQp[iMbXy], |
| 1007 | pCtx)); | 1007 | pCtx)); |
| 1008 | iIdx++; | 1008 | iIdx++; |
| 1009 | } | 1009 | } |
| 1010 | } else { | 1010 | } else { |
| 1011 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[iId8x8 << 2]], 0); | 1011 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[iId8x8 << 2]], 0); |
| 1012 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2) + 2]], 0); | 1012 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2) + 2]], 0); |
| 1013 | } | 1013 | } |
| 1014 | } | 1014 | } |
| 1015 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); | 1015 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); |
| 1016 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); | 1016 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); |
| 1017 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); | 1017 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); |
| 1018 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); | 1018 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); |
| 1019 | } | 1019 | } |
| 1020 | } | 1020 | } |
| 1021 | 1021 | ||
| 1022 | //chroma | 1022 | //chroma |
| 1023 | //step1: DC | 1023 | //step1: DC |
| 1024 | if (1 == uiCbpChroma || 2 == uiCbpChroma) { | 1024 | if (1 == uiCbpChroma || 2 == uiCbpChroma) { |
| 1025 | for (i = 0; i < 2; i++) { | 1025 | for (i = 0; i < 2; i++) { |
| 1026 | if (IS_INTRA (pCurLayer->pMbType[iMbXy])) | 1026 | if (IS_INTRA (pCurLayer->pMbType[iMbXy])) |
| 1027 | iMbResProperty = i ? CHROMA_DC_V : CHROMA_DC_U; | 1027 | iMbResProperty = i ? CHROMA_DC_V : CHROMA_DC_U; |
| 1028 | else | 1028 | else |
| 1029 | iMbResProperty = i ? CHROMA_DC_V_INTER : CHROMA_DC_U_INTER; | 1029 | iMbResProperty = i ? CHROMA_DC_V_INTER : CHROMA_DC_U_INTER; |
| 1030 | 1030 | ||
| 1031 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, 16 + (i << 2), 4, g_kuiChromaDcScan, | 1031 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, 16 + (i << 2), 4, g_kuiChromaDcScan, |
| 1032 | iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6), pCurLayer->pChromaQp[iMbXy][i], pCtx)); | 1032 | iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6), pCurLayer->pChromaQp[iMbXy][i], pCtx)); |
| 1033 | } | 1033 | } |
| 1034 | } | 1034 | } |
| 1035 | //step2: AC | 1035 | //step2: AC |
| 1036 | if (2 == uiCbpChroma) { | 1036 | if (2 == uiCbpChroma) { |
| 1037 | for (i = 0; i < 2; i++) { | 1037 | for (i = 0; i < 2; i++) { |
| 1038 | if (IS_INTRA (pCurLayer->pMbType[iMbXy])) | 1038 | if (IS_INTRA (pCurLayer->pMbType[iMbXy])) |
| 1039 | iMbResProperty = i ? CHROMA_AC_V : CHROMA_AC_U; | 1039 | iMbResProperty = i ? CHROMA_AC_V : CHROMA_AC_U; |
| 1040 | else | 1040 | else |
| 1041 | iMbResProperty = i ? CHROMA_AC_V_INTER : CHROMA_AC_U_INTER; | 1041 | iMbResProperty = i ? CHROMA_AC_V_INTER : CHROMA_AC_U_INTER; |
| 1042 | int32_t index = 16 + (i << 2); | 1042 | int32_t index = 16 + (i << 2); |
| 1043 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { | 1043 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 1044 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, index, | 1044 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, index, |
| 1045 | iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), | 1045 | iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), |
| 1046 | iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (index << 4), pCurLayer->pChromaQp[iMbXy][i], pCtx)); | 1046 | iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (index << 4), pCurLayer->pChromaQp[iMbXy][i], pCtx)); |
| 1047 | index++; | 1047 | index++; |
| 1048 | } | 1048 | } |
| 1049 | } | 1049 | } |
| 1050 | ST16 (&pCurLayer->pNzc[iMbXy][16], LD16 (&pNonZeroCount[6 + 8 * 1])); | 1050 | ST16 (&pCurLayer->pNzc[iMbXy][16], LD16 (&pNonZeroCount[6 + 8 * 1])); |
| 1051 | ST16 (&pCurLayer->pNzc[iMbXy][20], LD16 (&pNonZeroCount[6 + 8 * 2])); | 1051 | ST16 (&pCurLayer->pNzc[iMbXy][20], LD16 (&pNonZeroCount[6 + 8 * 2])); |
| 1052 | ST16 (&pCurLayer->pNzc[iMbXy][18], LD16 (&pNonZeroCount[6 + 8 * 4])); | 1052 | ST16 (&pCurLayer->pNzc[iMbXy][18], LD16 (&pNonZeroCount[6 + 8 * 4])); |
| 1053 | ST16 (&pCurLayer->pNzc[iMbXy][22], LD16 (&pNonZeroCount[6 + 8 * 5])); | 1053 | ST16 (&pCurLayer->pNzc[iMbXy][22], LD16 (&pNonZeroCount[6 + 8 * 5])); |
| 1054 | } else { | 1054 | } else { |
| 1055 | ST32 (&pCurLayer->pNzc[iMbXy][16], 0); | 1055 | ST32 (&pCurLayer->pNzc[iMbXy][16], 0); |
| 1056 | ST32 (&pCurLayer->pNzc[iMbXy][20], 0); | 1056 | ST32 (&pCurLayer->pNzc[iMbXy][20], 0); |
| 1057 | } | 1057 | } |
| 1058 | } else { | 1058 | } else { |
| 1059 | pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; | 1059 | pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; |
| 1060 | for (i = 0; i < 2; i++) { | 1060 | for (i = 0; i < 2; i++) { |
| 1061 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pCurLayer->pLumaQp[iMbXy] + | 1061 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pCurLayer->pLumaQp[iMbXy] + |
| 1062 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; | 1062 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; |
| 1063 | } | 1063 | } |
| 1064 | } | 1064 | } |
| 1065 | 1065 | ||
| 1066 | WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag)); | 1066 | WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag)); |
| 1067 | if (uiEosFlag) { | 1067 | if (uiEosFlag) { |
| 1068 | RestoreCabacDecEngineToBS (pCtx->pCabacDecEngine, pCtx->pCurDqLayer->pBitStringAux); | 1068 | RestoreCabacDecEngineToBS (pCtx->pCabacDecEngine, pCtx->pCurDqLayer->pBitStringAux); |
| 1069 | } | 1069 | } |
| 1070 | 1070 | ||
| 1071 | return ERR_NONE; | 1071 | return ERR_NONE; |
| 1072 | } | 1072 | } |
| 1073 | 1073 | ||
| 1074 | int32_t WelsDecodeMbCabacBSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiEosFlag) { | 1074 | int32_t WelsDecodeMbCabacBSliceBaseMode0 (PWelsDecoderContext pCtx, PWelsNeighAvail pNeighAvail, uint32_t& uiEosFlag) { |
| 1075 | PDqLayer pCurLayer = pCtx->pCurDqLayer; | 1075 | PDqLayer pCurLayer = pCtx->pCurDqLayer; |
| 1076 | PBitStringAux pBsAux = pCurLayer->pBitStringAux; | 1076 | PBitStringAux pBsAux = pCurLayer->pBitStringAux; |
| 1077 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; | 1077 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; |
| 1078 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | 1078 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; |
| 1079 | 1079 | ||
| 1080 | int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart; | 1080 | int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart; |
| 1081 | int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd; | 1081 | int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd; |
| 1082 | int32_t iMbXy = pCurLayer->iMbXyIndex; | 1082 | int32_t iMbXy = pCurLayer->iMbXyIndex; |
| 1083 | int32_t iMbResProperty; | 1083 | int32_t iMbResProperty; |
| 1084 | int32_t i; | 1084 | int32_t i; |
| 1085 | uint32_t uiMbType = 0, uiCbp = 0, uiCbpLuma = 0, uiCbpChroma = 0; | 1085 | uint32_t uiMbType = 0, uiCbp = 0, uiCbpLuma = 0, uiCbpChroma = 0; |
| 1086 | 1086 | ||
| 1087 | ENFORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16); | 1087 | ENFORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16); |
| 1088 | 1088 | ||
| 1089 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; | 1089 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; |
| 1090 | 1090 | ||
| 1091 | WELS_READ_VERIFY (ParseMBTypeBSliceCabac (pCtx, pNeighAvail, uiMbType)); | 1091 | WELS_READ_VERIFY (ParseMBTypeBSliceCabac (pCtx, pNeighAvail, uiMbType)); |
| 1092 | 1092 | ||
| 1093 | if (uiMbType < 23) { //Inter B mode | 1093 | if (uiMbType < 23) { //Inter B mode |
| 1094 | int16_t pMotionVector[LIST_A][30][MV_A]; | 1094 | int16_t pMotionVector[LIST_A][30][MV_A]; |
| 1095 | int16_t pMvdCache[LIST_A][30][MV_A]; | 1095 | int16_t pMvdCache[LIST_A][30][MV_A]; |
| 1096 | int8_t pRefIndex[LIST_A][30]; | 1096 | int8_t pRefIndex[LIST_A][30]; |
| 1097 | int8_t pDirect[30]; | 1097 | int8_t pDirect[30]; |
| 1098 | pCurLayer->pMbType[iMbXy] = g_ksInterBMbTypeInfo[uiMbType].iType; | 1098 | pCurLayer->pMbType[iMbXy] = g_ksInterBMbTypeInfo[uiMbType].iType; |
| 1099 | WelsFillCacheInterCabac (pNeighAvail, pNonZeroCount, pMotionVector, pMvdCache, pRefIndex, pCurLayer); | 1099 | WelsFillCacheInterCabac (pNeighAvail, pNonZeroCount, pMotionVector, pMvdCache, pRefIndex, pCurLayer); |
| 1100 | WelsFillDirectCacheCabac (pNeighAvail, pDirect, pCurLayer); | 1100 | WelsFillDirectCacheCabac (pNeighAvail, pDirect, pCurLayer); |
| 1101 | WELS_READ_VERIFY (ParseInterBMotionInfoCabac (pCtx, pNeighAvail, pNonZeroCount, pMotionVector, pMvdCache, pRefIndex, | 1101 | WELS_READ_VERIFY (ParseInterBMotionInfoCabac (pCtx, pNeighAvail, pNonZeroCount, pMotionVector, pMvdCache, pRefIndex, |
| 1102 | pDirect)); | 1102 | pDirect)); |
| 1103 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; | 1103 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; |
| 1104 | } else { //Intra mode | 1104 | } else { //Intra mode |
| 1105 | uiMbType -= 23; | 1105 | uiMbType -= 23; |
| 1106 | if (uiMbType > 25) | 1106 | if (uiMbType > 25) |
| 1107 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); | 1107 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); |
| 1108 | if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 && uiMbType <= 24))) | 1108 | if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 && uiMbType <= 24))) |
| 1109 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); | 1109 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); |
| 1110 | 1110 | ||
| 1111 | if (25 == uiMbType) { //I_PCM | 1111 | if (25 == uiMbType) { //I_PCM |
| 1112 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "I_PCM mode exists in P slice!"); | 1112 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "I_PCM mode exists in P slice!"); |
| 1113 | WELS_READ_VERIFY (ParseIPCMInfoCabac (pCtx)); | 1113 | WELS_READ_VERIFY (ParseIPCMInfoCabac (pCtx)); |
| 1114 | pSlice->iLastDeltaQp = 0; | 1114 | pSlice->iLastDeltaQp = 0; |
| 1115 | WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag)); | 1115 | WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag)); |
| 1116 | if (uiEosFlag) { | 1116 | if (uiEosFlag) { |
| 1117 | RestoreCabacDecEngineToBS (pCtx->pCabacDecEngine, pCtx->pCurDqLayer->pBitStringAux); | 1117 | RestoreCabacDecEngineToBS (pCtx->pCabacDecEngine, pCtx->pCurDqLayer->pBitStringAux); |
| 1118 | } | 1118 | } |
| 1119 | return ERR_NONE; | 1119 | return ERR_NONE; |
| 1120 | } else { //normal Intra mode | 1120 | } else { //normal Intra mode |
| 1121 | if (0 == uiMbType) { //Intra4x4 | 1121 | if (0 == uiMbType) { //Intra4x4 |
| 1122 | ENFORCE_STACK_ALIGN_1D (int8_t, pIntraPredMode, 48, 16); | 1122 | ENFORCE_STACK_ALIGN_1D (int8_t, pIntraPredMode, 48, 16); |
| 1123 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA4x4; | 1123 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA4x4; |
| 1124 | if (pCtx->pPps->bTransform8x8ModeFlag) { | 1124 | if (pCtx->pPps->bTransform8x8ModeFlag) { |
| 1125 | WELS_READ_VERIFY (ParseTransformSize8x8FlagCabac (pCtx, pNeighAvail, pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy])); | 1125 | WELS_READ_VERIFY (ParseTransformSize8x8FlagCabac (pCtx, pNeighAvail, pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy])); |
| 1126 | } | 1126 | } |
| 1127 | if (pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { | 1127 | if (pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { |
| 1128 | uiMbType = pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA8x8; | 1128 | uiMbType = pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA8x8; |
| 1129 | pCtx->pFillInfoCacheIntraNxNFunc (pNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); | 1129 | pCtx->pFillInfoCacheIntraNxNFunc (pNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); |
| 1130 | WELS_READ_VERIFY (ParseIntra8x8Mode (pCtx, pNeighAvail, pIntraPredMode, pBsAux, pCurLayer)); | 1130 | WELS_READ_VERIFY (ParseIntra8x8Mode (pCtx, pNeighAvail, pIntraPredMode, pBsAux, pCurLayer)); |
| 1131 | } else { | 1131 | } else { |
| 1132 | pCtx->pFillInfoCacheIntraNxNFunc (pNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); | 1132 | pCtx->pFillInfoCacheIntraNxNFunc (pNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); |
| 1133 | WELS_READ_VERIFY (ParseIntra4x4Mode (pCtx, pNeighAvail, pIntraPredMode, pBsAux, pCurLayer)); | 1133 | WELS_READ_VERIFY (ParseIntra4x4Mode (pCtx, pNeighAvail, pIntraPredMode, pBsAux, pCurLayer)); |
| 1134 | } | 1134 | } |
| 1135 | } else { //Intra16x16 | 1135 | } else { //Intra16x16 |
| 1136 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16; | 1136 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16; |
| 1137 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; | 1137 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; |
| 1138 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; | 1138 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; |
| 1139 | pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3; | 1139 | pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3; |
| 1140 | pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2]; | 1140 | pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2]; |
| 1141 | uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0; | 1141 | uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0; |
| 1142 | uiCbpLuma = pCurLayer->pCbp[iMbXy] & 15; | 1142 | uiCbpLuma = pCurLayer->pCbp[iMbXy] & 15; |
| 1143 | WelsFillCacheNonZeroCount (pNeighAvail, pNonZeroCount, pCurLayer); | 1143 | WelsFillCacheNonZeroCount (pNeighAvail, pNonZeroCount, pCurLayer); |
| 1144 | WELS_READ_VERIFY (ParseIntra16x16Mode (pCtx, pNeighAvail, pBsAux, pCurLayer)); | 1144 | WELS_READ_VERIFY (ParseIntra16x16Mode (pCtx, pNeighAvail, pBsAux, pCurLayer)); |
| 1145 | } | 1145 | } |
| 1146 | } | 1146 | } |
| 1147 | } | 1147 | } |
| 1148 | 1148 | ||
| 1149 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); | 1149 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); |
| 1150 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); | 1150 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); |
| 1151 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); | 1151 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); |
| 1152 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); | 1152 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); |
| 1153 | ST32 (&pCurLayer->pNzc[iMbXy][16], 0); | 1153 | ST32 (&pCurLayer->pNzc[iMbXy][16], 0); |
| 1154 | ST32 (&pCurLayer->pNzc[iMbXy][20], 0); | 1154 | ST32 (&pCurLayer->pNzc[iMbXy][20], 0); |
| 1155 | 1155 | ||
| 1156 | if (MB_TYPE_INTRA16x16 != pCurLayer->pMbType[iMbXy]) { | 1156 | if (MB_TYPE_INTRA16x16 != pCurLayer->pMbType[iMbXy]) { |
| 1157 | WELS_READ_VERIFY (ParseCbpInfoCabac (pCtx, pNeighAvail, uiCbp)); | 1157 | WELS_READ_VERIFY (ParseCbpInfoCabac (pCtx, pNeighAvail, uiCbp)); |
| 1158 | 1158 | ||
| 1159 | pCurLayer->pCbp[iMbXy] = uiCbp; | 1159 | pCurLayer->pCbp[iMbXy] = uiCbp; |
| 1160 | pSlice->iLastDeltaQp = uiCbp == 0 ? 0 : pSlice->iLastDeltaQp; | 1160 | pSlice->iLastDeltaQp = uiCbp == 0 ? 0 : pSlice->iLastDeltaQp; |
| 1161 | uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0; | 1161 | uiCbpChroma = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0; |
| 1162 | uiCbpLuma = pCurLayer->pCbp[iMbXy] & 15; | 1162 | uiCbpLuma = pCurLayer->pCbp[iMbXy] & 15; |
| 1163 | } | 1163 | } |
| 1164 | 1164 | ||
| 1165 | if (pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { | 1165 | if (pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { |
| 1166 | 1166 | ||
| 1167 | if (MB_TYPE_INTRA16x16 != pCurLayer->pMbType[iMbXy]) { | 1167 | if (MB_TYPE_INTRA16x16 != pCurLayer->pMbType[iMbXy]) { |
| 1168 | // Need modification when B picutre add in | 1168 | // Need modification when B picutre add in |
| 1169 | bool bNeedParseTransformSize8x8Flag = | 1169 | bool bNeedParseTransformSize8x8Flag = |
| 1170 | (((IS_INTER_16x16 (pCurLayer->pMbType[iMbXy]) || IS_DIRECT (pCurLayer->pMbType[iMbXy]) | 1170 | (((IS_INTER_16x16 (pCurLayer->pMbType[iMbXy]) || IS_DIRECT (pCurLayer->pMbType[iMbXy]) |
| 1171 | || IS_INTER_16x8 (pCurLayer->pMbType[iMbXy]) || IS_INTER_8x16 (pCurLayer->pMbType[iMbXy])) | 1171 | || IS_INTER_16x8 (pCurLayer->pMbType[iMbXy]) || IS_INTER_8x16 (pCurLayer->pMbType[iMbXy])) |
| 1172 | || pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy]) | 1172 | || pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy]) |
| 1173 | && (pCurLayer->pMbType[iMbXy] != MB_TYPE_INTRA8x8) | 1173 | && (pCurLayer->pMbType[iMbXy] != MB_TYPE_INTRA8x8) |
| 1174 | && (pCurLayer->pMbType[iMbXy] != MB_TYPE_INTRA4x4) | 1174 | && (pCurLayer->pMbType[iMbXy] != MB_TYPE_INTRA4x4) |
| 1175 | && ((pCurLayer->pCbp[iMbXy] & 0x0F) > 0) | 1175 | && ((pCurLayer->pCbp[iMbXy] & 0x0F) > 0) |
| 1176 | && (pCtx->pPps->bTransform8x8ModeFlag)); | 1176 | && (pCtx->pPps->bTransform8x8ModeFlag)); |
| 1177 | 1177 | ||
| 1178 | if (bNeedParseTransformSize8x8Flag) { | 1178 | if (bNeedParseTransformSize8x8Flag) { |
| 1179 | WELS_READ_VERIFY (ParseTransformSize8x8FlagCabac (pCtx, pNeighAvail, | 1179 | WELS_READ_VERIFY (ParseTransformSize8x8FlagCabac (pCtx, pNeighAvail, |
| 1180 | pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy])); //transform_size_8x8_flag | 1180 | pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy])); //transform_size_8x8_flag |
| 1181 | } | 1181 | } |
| 1182 | } | 1182 | } |
| 1183 | 1183 | ||
| 1184 | memset (pCurLayer->pScaledTCoeff[iMbXy], 0, 384 * sizeof (pCurLayer->pScaledTCoeff[iMbXy][0])); | 1184 | memset (pCurLayer->pScaledTCoeff[iMbXy], 0, 384 * sizeof (pCurLayer->pScaledTCoeff[iMbXy][0])); |
| 1185 | 1185 | ||
| 1186 | int32_t iQpDelta, iId8x8, iId4x4; | 1186 | int32_t iQpDelta, iId8x8, iId4x4; |
| 1187 | 1187 | ||
| 1188 | WELS_READ_VERIFY (ParseDeltaQpCabac (pCtx, iQpDelta)); | 1188 | WELS_READ_VERIFY (ParseDeltaQpCabac (pCtx, iQpDelta)); |
| 1189 | if (iQpDelta > 25 || iQpDelta < -26) { //out of iQpDelta range | 1189 | if (iQpDelta > 25 || iQpDelta < -26) { //out of iQpDelta range |
| 1190 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_QP); | 1190 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_QP); |
| 1191 | } | 1191 | } |
| 1192 | pCurLayer->pLumaQp[iMbXy] = (pSlice->iLastMbQp + iQpDelta + 52) % 52; //update last_mb_qp | 1192 | pCurLayer->pLumaQp[iMbXy] = (pSlice->iLastMbQp + iQpDelta + 52) % 52; //update last_mb_qp |
| 1193 | pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy]; | 1193 | pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy]; |
| 1194 | for (i = 0; i < 2; i++) { | 1194 | for (i = 0; i < 2; i++) { |
| 1195 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pSlice->iLastMbQp + | 1195 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pSlice->iLastMbQp + |
| 1196 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; | 1196 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; |
| 1197 | } | 1197 | } |
| 1198 | 1198 | ||
| 1199 | if (MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { | 1199 | if (MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { |
| 1200 | //step1: Luma DC | 1200 | //step1: Luma DC |
| 1201 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, 0, 16, g_kuiLumaDcZigzagScan, | 1201 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, 0, 16, g_kuiLumaDcZigzagScan, |
| 1202 | I16_LUMA_DC, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx)); | 1202 | I16_LUMA_DC, pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx)); |
| 1203 | //step2: Luma AC | 1203 | //step2: Luma AC |
| 1204 | if (uiCbpLuma) { | 1204 | if (uiCbpLuma) { |
| 1205 | for (i = 0; i < 16; i++) { | 1205 | for (i = 0; i < 16; i++) { |
| 1206 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, i, iScanIdxEnd - WELS_MAX (iScanIdxStart, | 1206 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, i, iScanIdxEnd - WELS_MAX (iScanIdxStart, |
| 1207 | 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i << 4), | 1207 | 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i << 4), |
| 1208 | pCurLayer->pLumaQp[iMbXy], pCtx)); | 1208 | pCurLayer->pLumaQp[iMbXy], pCtx)); |
| 1209 | } | 1209 | } |
| 1210 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); | 1210 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); |
| 1211 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); | 1211 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); |
| 1212 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); | 1212 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); |
| 1213 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); | 1213 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); |
| 1214 | } else { | 1214 | } else { |
| 1215 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); | 1215 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); |
| 1216 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); | 1216 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); |
| 1217 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); | 1217 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); |
| 1218 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); | 1218 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); |
| 1219 | } | 1219 | } |
| 1220 | } else { //non-MB_TYPE_INTRA16x16 | 1220 | } else { //non-MB_TYPE_INTRA16x16 |
| 1221 | if (pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { | 1221 | if (pCtx->pCurDqLayer->pTransformSize8x8Flag[iMbXy]) { |
| 1222 | // Transform 8x8 support for CABAC | 1222 | // Transform 8x8 support for CABAC |
| 1223 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { | 1223 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { |
| 1224 | if (uiCbpLuma & (1 << iId8x8)) { | 1224 | if (uiCbpLuma & (1 << iId8x8)) { |
| 1225 | WELS_READ_VERIFY (ParseResidualBlockCabac8x8 (pNeighAvail, pNonZeroCount, pBsAux, (iId8x8 << 2), | 1225 | WELS_READ_VERIFY (ParseResidualBlockCabac8x8 (pNeighAvail, pNonZeroCount, pBsAux, (iId8x8 << 2), |
| 1226 | iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan8x8 + iScanIdxStart, | 1226 | iScanIdxEnd - iScanIdxStart + 1, g_kuiZigzagScan8x8 + iScanIdxStart, |
| 1227 | IS_INTRA (pCurLayer->pMbType[iMbXy]) ? LUMA_DC_AC_INTRA_8 : LUMA_DC_AC_INTER_8, | 1227 | IS_INTRA (pCurLayer->pMbType[iMbXy]) ? LUMA_DC_AC_INTRA_8 : LUMA_DC_AC_INTER_8, |
| 1228 | pCurLayer->pScaledTCoeff[iMbXy] + (iId8x8 << 6), pCurLayer->pLumaQp[iMbXy], pCtx)); | 1228 | pCurLayer->pScaledTCoeff[iMbXy] + (iId8x8 << 6), pCurLayer->pLumaQp[iMbXy], pCtx)); |
| 1229 | } else { | 1229 | } else { |
| 1230 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2)]], 0); | 1230 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2)]], 0); |
| 1231 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2) + 2]], 0); | 1231 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2) + 2]], 0); |
| 1232 | } | 1232 | } |
| 1233 | } | 1233 | } |
| 1234 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); | 1234 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); |
| 1235 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); | 1235 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); |
| 1236 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); | 1236 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); |
| 1237 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); | 1237 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); |
| 1238 | } else { | 1238 | } else { |
| 1239 | iMbResProperty = (IS_INTRA (pCurLayer->pMbType[iMbXy])) ? LUMA_DC_AC_INTRA : LUMA_DC_AC_INTER; | 1239 | iMbResProperty = (IS_INTRA (pCurLayer->pMbType[iMbXy])) ? LUMA_DC_AC_INTRA : LUMA_DC_AC_INTER; |
| 1240 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { | 1240 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { |
| 1241 | if (uiCbpLuma & (1 << iId8x8)) { | 1241 | if (uiCbpLuma & (1 << iId8x8)) { |
| 1242 | int32_t iIdx = (iId8x8 << 2); | 1242 | int32_t iIdx = (iId8x8 << 2); |
| 1243 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { | 1243 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 1244 | //Luma (DC and AC decoding together) | 1244 | //Luma (DC and AC decoding together) |
| 1245 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, iIdx, iScanIdxEnd - iScanIdxStart + 1, | 1245 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, iIdx, iScanIdxEnd - iScanIdxStart + 1, |
| 1246 | g_kuiZigzagScan + iScanIdxStart, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIdx << 4), | 1246 | g_kuiZigzagScan + iScanIdxStart, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIdx << 4), |
| 1247 | pCurLayer->pLumaQp[iMbXy], | 1247 | pCurLayer->pLumaQp[iMbXy], |
| 1248 | pCtx)); | 1248 | pCtx)); |
| 1249 | iIdx++; | 1249 | iIdx++; |
| 1250 | } | 1250 | } |
| 1251 | } else { | 1251 | } else { |
| 1252 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[iId8x8 << 2]], 0); | 1252 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[iId8x8 << 2]], 0); |
| 1253 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2) + 2]], 0); | 1253 | ST16 (&pNonZeroCount[g_kCacheNzcScanIdx[ (iId8x8 << 2) + 2]], 0); |
| 1254 | } | 1254 | } |
| 1255 | } | 1255 | } |
| 1256 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); | 1256 | ST32 (&pCurLayer->pNzc[iMbXy][0], LD32 (&pNonZeroCount[1 + 8 * 1])); |
| 1257 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); | 1257 | ST32 (&pCurLayer->pNzc[iMbXy][4], LD32 (&pNonZeroCount[1 + 8 * 2])); |
| 1258 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); | 1258 | ST32 (&pCurLayer->pNzc[iMbXy][8], LD32 (&pNonZeroCount[1 + 8 * 3])); |
| 1259 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); | 1259 | ST32 (&pCurLayer->pNzc[iMbXy][12], LD32 (&pNonZeroCount[1 + 8 * 4])); |
| 1260 | } | 1260 | } |
| 1261 | } | 1261 | } |
| 1262 | 1262 | ||
| 1263 | //chroma | 1263 | //chroma |
| 1264 | //step1: DC | 1264 | //step1: DC |
| 1265 | if (1 == uiCbpChroma || 2 == uiCbpChroma) { | 1265 | if (1 == uiCbpChroma || 2 == uiCbpChroma) { |
| 1266 | for (i = 0; i < 2; i++) { | 1266 | for (i = 0; i < 2; i++) { |
| 1267 | if (IS_INTRA (pCurLayer->pMbType[iMbXy])) | 1267 | if (IS_INTRA (pCurLayer->pMbType[iMbXy])) |
| 1268 | iMbResProperty = i ? CHROMA_DC_V : CHROMA_DC_U; | 1268 | iMbResProperty = i ? CHROMA_DC_V : CHROMA_DC_U; |
| 1269 | else | 1269 | else |
| 1270 | iMbResProperty = i ? CHROMA_DC_V_INTER : CHROMA_DC_U_INTER; | 1270 | iMbResProperty = i ? CHROMA_DC_V_INTER : CHROMA_DC_U_INTER; |
| 1271 | 1271 | ||
| 1272 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, 16 + (i << 2), 4, g_kuiChromaDcScan, | 1272 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, 16 + (i << 2), 4, g_kuiChromaDcScan, |
| 1273 | iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6), pCurLayer->pChromaQp[iMbXy][i], pCtx)); | 1273 | iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6), pCurLayer->pChromaQp[iMbXy][i], pCtx)); |
| 1274 | } | 1274 | } |
| 1275 | } | 1275 | } |
| 1276 | //step2: AC | 1276 | //step2: AC |
| 1277 | if (2 == uiCbpChroma) { | 1277 | if (2 == uiCbpChroma) { |
| 1278 | for (i = 0; i < 2; i++) { | 1278 | for (i = 0; i < 2; i++) { |
| 1279 | if (IS_INTRA (pCurLayer->pMbType[iMbXy])) | 1279 | if (IS_INTRA (pCurLayer->pMbType[iMbXy])) |
| 1280 | iMbResProperty = i ? CHROMA_AC_V : CHROMA_AC_U; | 1280 | iMbResProperty = i ? CHROMA_AC_V : CHROMA_AC_U; |
| 1281 | else | 1281 | else |
| 1282 | iMbResProperty = i ? CHROMA_AC_V_INTER : CHROMA_AC_U_INTER; | 1282 | iMbResProperty = i ? CHROMA_AC_V_INTER : CHROMA_AC_U_INTER; |
| 1283 | int32_t index = 16 + (i << 2); | 1283 | int32_t index = 16 + (i << 2); |
| 1284 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { | 1284 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 1285 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, index, | 1285 | WELS_READ_VERIFY (ParseResidualBlockCabac (pNeighAvail, pNonZeroCount, pBsAux, index, |
| 1286 | iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), | 1286 | iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), |
| 1287 | iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (index << 4), pCurLayer->pChromaQp[iMbXy][i], pCtx)); | 1287 | iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (index << 4), pCurLayer->pChromaQp[iMbXy][i], pCtx)); |
| 1288 | index++; | 1288 | index++; |
| 1289 | } | 1289 | } |
| 1290 | } | 1290 | } |
| 1291 | ST16 (&pCurLayer->pNzc[iMbXy][16], LD16 (&pNonZeroCount[6 + 8 * 1])); | 1291 | ST16 (&pCurLayer->pNzc[iMbXy][16], LD16 (&pNonZeroCount[6 + 8 * 1])); |
| 1292 | ST16 (&pCurLayer->pNzc[iMbXy][20], LD16 (&pNonZeroCount[6 + 8 * 2])); | 1292 | ST16 (&pCurLayer->pNzc[iMbXy][20], LD16 (&pNonZeroCount[6 + 8 * 2])); |
| 1293 | ST16 (&pCurLayer->pNzc[iMbXy][18], LD16 (&pNonZeroCount[6 + 8 * 4])); | 1293 | ST16 (&pCurLayer->pNzc[iMbXy][18], LD16 (&pNonZeroCount[6 + 8 * 4])); |
| 1294 | ST16 (&pCurLayer->pNzc[iMbXy][22], LD16 (&pNonZeroCount[6 + 8 * 5])); | 1294 | ST16 (&pCurLayer->pNzc[iMbXy][22], LD16 (&pNonZeroCount[6 + 8 * 5])); |
| 1295 | } else { | 1295 | } else { |
| 1296 | ST32 (&pCurLayer->pNzc[iMbXy][16], 0); | 1296 | ST32 (&pCurLayer->pNzc[iMbXy][16], 0); |
| 1297 | ST32 (&pCurLayer->pNzc[iMbXy][20], 0); | 1297 | ST32 (&pCurLayer->pNzc[iMbXy][20], 0); |
| 1298 | } | 1298 | } |
| 1299 | } else { | 1299 | } else { |
| 1300 | pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; | 1300 | pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; |
| 1301 | for (i = 0; i < 2; i++) { | 1301 | for (i = 0; i < 2; i++) { |
| 1302 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pCurLayer->pLumaQp[iMbXy] + | 1302 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pCurLayer->pLumaQp[iMbXy] + |
| 1303 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; | 1303 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; |
| 1304 | } | 1304 | } |
| 1305 | } | 1305 | } |
| 1306 | 1306 | ||
| 1307 | WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag)); | 1307 | WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag)); |
| 1308 | if (uiEosFlag) { | 1308 | if (uiEosFlag) { |
| 1309 | RestoreCabacDecEngineToBS (pCtx->pCabacDecEngine, pCtx->pCurDqLayer->pBitStringAux); | 1309 | RestoreCabacDecEngineToBS (pCtx->pCabacDecEngine, pCtx->pCurDqLayer->pBitStringAux); |
| 1310 | } | 1310 | } |
| 1311 | 1311 | ||
| 1312 | return ERR_NONE; | 1312 | return ERR_NONE; |
| 1313 | } | 1313 | } |
| 1314 | 1314 | ||
| 1315 | 1315 | ||
| 1316 | int32_t WelsDecodeMbCabacPSlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uint32_t& uiEosFlag) { | 1316 | int32_t WelsDecodeMbCabacPSlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uint32_t& uiEosFlag) { |
| 1317 | PDqLayer pCurLayer = pCtx->pCurDqLayer; | 1317 | PDqLayer pCurLayer = pCtx->pCurDqLayer; |
| 1318 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; | 1318 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; |
| 1319 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | 1319 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; |
| 1320 | PPicture* ppRefPic = pCtx->sRefPic.pRefList[LIST_0]; | 1320 | PPicture* ppRefPic = pCtx->sRefPic.pRefList[LIST_0]; |
| 1321 | uint32_t uiCode; | 1321 | uint32_t uiCode; |
| 1322 | int32_t iMbXy = pCurLayer->iMbXyIndex; | 1322 | int32_t iMbXy = pCurLayer->iMbXyIndex; |
| 1323 | int32_t i; | 1323 | int32_t i; |
| 1324 | SWelsNeighAvail uiNeighAvail; | 1324 | SWelsNeighAvail uiNeighAvail; |
| 1325 | pCurLayer->pCbp[iMbXy] = 0; | 1325 | pCurLayer->pCbp[iMbXy] = 0; |
| 1326 | pCurLayer->pCbfDc[iMbXy] = 0; | 1326 | pCurLayer->pCbfDc[iMbXy] = 0; |
| 1327 | pCurLayer->pChromaPredMode[iMbXy] = C_PRED_DC; | 1327 | pCurLayer->pChromaPredMode[iMbXy] = C_PRED_DC; |
| 1328 | 1328 | ||
| 1329 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; | 1329 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; |
| 1330 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; | 1330 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; |
| 1331 | 1331 | ||
| 1332 | GetNeighborAvailMbType (&uiNeighAvail, pCurLayer); | 1332 | GetNeighborAvailMbType (&uiNeighAvail, pCurLayer); |
| 1333 | WELS_READ_VERIFY (ParseSkipFlagCabac (pCtx, &uiNeighAvail, uiCode)); | 1333 | WELS_READ_VERIFY (ParseSkipFlagCabac (pCtx, &uiNeighAvail, uiCode)); |
| 1334 | 1334 | ||
| 1335 | if (uiCode) { | 1335 | if (uiCode) { |
| 1336 | int16_t pMv[2] = {0}; | 1336 | int16_t pMv[2] = {0}; |
| 1337 | pCurLayer->pMbType[iMbXy] = MB_TYPE_SKIP; | 1337 | pCurLayer->pMbType[iMbXy] = MB_TYPE_SKIP; |
| 1338 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); | 1338 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); |
| 1339 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); | 1339 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); |
| 1340 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); | 1340 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); |
| 1341 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); | 1341 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); |
| 1342 | ST32 (&pCurLayer->pNzc[iMbXy][16], 0); | 1342 | ST32 (&pCurLayer->pNzc[iMbXy][16], 0); |
| 1343 | ST32 (&pCurLayer->pNzc[iMbXy][20], 0); | 1343 | ST32 (&pCurLayer->pNzc[iMbXy][20], 0); |
| 1344 | 1344 | ||
| 1345 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; | 1345 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; |
| 1346 | memset (pCurLayer->pRefIndex[0][iMbXy], 0, sizeof (int8_t) * 16); | 1346 | memset (pCurLayer->pRefIndex[0][iMbXy], 0, sizeof (int8_t) * 16); |
| 1347 | pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[0] && ppRefPic[0]->bIsComplete); | 1347 | pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[0] && ppRefPic[0]->bIsComplete); |
| 1348 | //predict mv | 1348 | //predict mv |
| 1349 | PredPSkipMvFromNeighbor (pCurLayer, pMv); | 1349 | PredPSkipMvFromNeighbor (pCurLayer, pMv); |
| 1350 | for (i = 0; i < 16; i++) { | 1350 | for (i = 0; i < 16; i++) { |
| 1351 | ST32 (pCurLayer->pMv[0][iMbXy][i], * (uint32_t*)pMv); | 1351 | ST32 (pCurLayer->pMv[0][iMbXy][i], * (uint32_t*)pMv); |
| 1352 | ST32 (pCurLayer->pMvd[0][iMbXy][i], 0); | 1352 | ST32 (pCurLayer->pMvd[0][iMbXy][i], 0); |
| 1353 | } | 1353 | } |
| 1354 | 1354 | ||
| 1355 | //if (!pSlice->sSliceHeaderExt.bDefaultResidualPredFlag) { | 1355 | //if (!pSlice->sSliceHeaderExt.bDefaultResidualPredFlag) { |
| 1356 | // memset (pCurLayer->pScaledTCoeff[iMbXy], 0, 384 * sizeof (int16_t)); | 1356 | // memset (pCurLayer->pScaledTCoeff[iMbXy], 0, 384 * sizeof (int16_t)); |
| 1357 | //} | 1357 | //} |
| 1358 | 1358 | ||
| 1359 | //reset rS | 1359 | //reset rS |
| 1360 | pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; //??????????????? dqaunt of previous mb | 1360 | pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; //??????????????? dqaunt of previous mb |
| 1361 | for (i = 0; i < 2; i++) { | 1361 | for (i = 0; i < 2; i++) { |
| 1362 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pCurLayer->pLumaQp[iMbXy] + | 1362 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pCurLayer->pLumaQp[iMbXy] + |
| 1363 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; | 1363 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; |
| 1364 | } | 1364 | } |
| 1365 | 1365 | ||
| 1366 | //for neighboring CABAC usage | 1366 | //for neighboring CABAC usage |
| 1367 | pSlice->iLastDeltaQp = 0; | 1367 | pSlice->iLastDeltaQp = 0; |
| 1368 | 1368 | ||
| 1369 | WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag)); | 1369 | WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag)); |
| 1370 | 1370 | ||
| 1371 | return ERR_NONE; | 1371 | return ERR_NONE; |
| 1372 | } | 1372 | } |
| 1373 | 1373 | ||
| 1374 | WELS_READ_VERIFY (WelsDecodeMbCabacPSliceBaseMode0 (pCtx, &uiNeighAvail, uiEosFlag)); | 1374 | WELS_READ_VERIFY (WelsDecodeMbCabacPSliceBaseMode0 (pCtx, &uiNeighAvail, uiEosFlag)); |
| 1375 | return ERR_NONE; | 1375 | return ERR_NONE; |
| 1376 | } | 1376 | } |
| 1377 | 1377 | ||
| 1378 | 1378 | ||
| 1379 | int32_t WelsDecodeMbCabacBSlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uint32_t& uiEosFlag) { | 1379 | int32_t WelsDecodeMbCabacBSlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uint32_t& uiEosFlag) { |
| 1380 | PDqLayer pCurLayer = pCtx->pCurDqLayer; | 1380 | PDqLayer pCurLayer = pCtx->pCurDqLayer; |
| 1381 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; | 1381 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; |
| 1382 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | 1382 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; |
| 1383 | PPicture* ppRefPicL0 = pCtx->sRefPic.pRefList[LIST_0]; | 1383 | PPicture* ppRefPicL0 = pCtx->sRefPic.pRefList[LIST_0]; |
| 1384 | PPicture* ppRefPicL1 = pCtx->sRefPic.pRefList[LIST_1]; | 1384 | PPicture* ppRefPicL1 = pCtx->sRefPic.pRefList[LIST_1]; |
| 1385 | uint32_t uiCode; | 1385 | uint32_t uiCode; |
| 1386 | int32_t iMbXy = pCurLayer->iMbXyIndex; | 1386 | int32_t iMbXy = pCurLayer->iMbXyIndex; |
| 1387 | int32_t i; | 1387 | int32_t i; |
| 1388 | SWelsNeighAvail uiNeighAvail; | 1388 | SWelsNeighAvail uiNeighAvail; |
| 1389 | pCurLayer->pCbp[iMbXy] = 0; | 1389 | pCurLayer->pCbp[iMbXy] = 0; |
| 1390 | pCurLayer->pCbfDc[iMbXy] = 0; | 1390 | pCurLayer->pCbfDc[iMbXy] = 0; |
| 1391 | pCurLayer->pChromaPredMode[iMbXy] = C_PRED_DC; | 1391 | pCurLayer->pChromaPredMode[iMbXy] = C_PRED_DC; |
| 1392 | 1392 | ||
| 1393 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; | 1393 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; |
| 1394 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; | 1394 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; |
| 1395 | 1395 | ||
| 1396 | GetNeighborAvailMbType (&uiNeighAvail, pCurLayer); | 1396 | GetNeighborAvailMbType (&uiNeighAvail, pCurLayer); |
| 1397 | WELS_READ_VERIFY (ParseSkipFlagCabac (pCtx, &uiNeighAvail, uiCode)); | 1397 | WELS_READ_VERIFY (ParseSkipFlagCabac (pCtx, &uiNeighAvail, uiCode)); |
| 1398 | 1398 | ||
| 1399 | memset (pCurLayer->pDirect[iMbXy], 0, sizeof (int8_t) * 16); | 1399 | memset (pCurLayer->pDirect[iMbXy], 0, sizeof (int8_t) * 16); |
| 1400 | 1400 | ||
| 1401 | if (uiCode) { | 1401 | if (uiCode) { |
| 1402 | int16_t pMv[LIST_A][2] = { {0, 0}, { 0, 0 } }; | 1402 | int16_t pMv[LIST_A][2] = { {0, 0}, { 0, 0 } }; |
| 1403 | int8_t ref[LIST_A] = { 0 }; | 1403 | int8_t ref[LIST_A] = { 0 }; |
| 1404 | pCurLayer->pMbType[iMbXy] = MB_TYPE_SKIP | MB_TYPE_DIRECT; | 1404 | pCurLayer->pMbType[iMbXy] = MB_TYPE_SKIP | MB_TYPE_DIRECT; |
| 1405 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); | 1405 | ST32 (&pCurLayer->pNzc[iMbXy][0], 0); |
| 1406 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); | 1406 | ST32 (&pCurLayer->pNzc[iMbXy][4], 0); |
| 1407 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); | 1407 | ST32 (&pCurLayer->pNzc[iMbXy][8], 0); |
| 1408 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); | 1408 | ST32 (&pCurLayer->pNzc[iMbXy][12], 0); |
| 1409 | ST32 (&pCurLayer->pNzc[iMbXy][16], 0); | 1409 | ST32 (&pCurLayer->pNzc[iMbXy][16], 0); |
| 1410 | ST32 (&pCurLayer->pNzc[iMbXy][20], 0); | 1410 | ST32 (&pCurLayer->pNzc[iMbXy][20], 0); |
| 1411 | 1411 | ||
| 1412 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; | 1412 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; |
| 1413 | memset (pCurLayer->pRefIndex[LIST_0][iMbXy], 0, sizeof (int8_t) * 16); | 1413 | memset (pCurLayer->pRefIndex[LIST_0][iMbXy], 0, sizeof (int8_t) * 16); |
| 1414 | memset (pCurLayer->pRefIndex[LIST_1][iMbXy], 0, sizeof (int8_t) * 16); | 1414 | memset (pCurLayer->pRefIndex[LIST_1][iMbXy], 0, sizeof (int8_t) * 16); |
| 1415 | pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPicL0[0] && ppRefPicL0[0]->bIsComplete) | 1415 | pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPicL0[0] && ppRefPicL0[0]->bIsComplete) |
| 1416 | || ! (ppRefPicL1[0] && ppRefPicL1[0]->bIsComplete); | 1416 | || ! (ppRefPicL1[0] && ppRefPicL1[0]->bIsComplete); |
| 1417 | 1417 | ||
| 1418 | if (pSliceHeader->iDirectSpatialMvPredFlag) { | 1418 | if (pSliceHeader->iDirectSpatialMvPredFlag) { |
| 1419 | 1419 | ||
| 1420 | //predict direct spatial mv | 1420 | //predict direct spatial mv |
| 1421 | PredMvBDirectSpatial (pCtx, pMv, ref); | 1421 | PredMvBDirectSpatial (pCtx, pMv, ref); |
| 1422 | } else { | 1422 | } else { |
| 1423 | //temporal direct mode | 1423 | //temporal direct mode |
| 1424 | ComputeColocated (pCtx); | 1424 | ComputeColocated (pCtx); |
| 1425 | PredBDirectTemporal (pCtx, pMv, ref); | 1425 | PredBDirectTemporal (pCtx, pMv, ref); |
| 1426 | } | 1426 | } |
| 1427 | 1427 | ||
| 1428 | //reset rS | 1428 | //reset rS |
| 1429 | pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; //??????????????? dqaunt of previous mb | 1429 | pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; //??????????????? dqaunt of previous mb |
| 1430 | for (i = 0; i < 2; i++) { | 1430 | for (i = 0; i < 2; i++) { |
| 1431 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pCurLayer->pLumaQp[iMbXy] + | 1431 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pCurLayer->pLumaQp[iMbXy] + |
| 1432 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; | 1432 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; |
| 1433 | } | 1433 | } |
| 1434 | 1434 | ||
| 1435 | //for neighboring CABAC usage | 1435 | //for neighboring CABAC usage |
| 1436 | pSlice->iLastDeltaQp = 0; | 1436 | pSlice->iLastDeltaQp = 0; |
| 1437 | 1437 | ||
| 1438 | WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag)); | 1438 | WELS_READ_VERIFY (ParseEndOfSliceCabac (pCtx, uiEosFlag)); |
| 1439 | 1439 | ||
| 1440 | return ERR_NONE; | 1440 | return ERR_NONE; |
| 1441 | } | 1441 | } |
| 1442 | 1442 | ||
| 1443 | WELS_READ_VERIFY (WelsDecodeMbCabacBSliceBaseMode0 (pCtx, &uiNeighAvail, uiEosFlag)); | 1443 | WELS_READ_VERIFY (WelsDecodeMbCabacBSliceBaseMode0 (pCtx, &uiNeighAvail, uiEosFlag)); |
| 1444 | return ERR_NONE; | 1444 | return ERR_NONE; |
| 1445 | } | 1445 | } |
| 1446 | 1446 | ||
| 1447 | // Calculate deqaunt coeff scaling list value | 1447 | // Calculate deqaunt coeff scaling list value |
| 1448 | int32_t WelsCalcDeqCoeffScalingList (PWelsDecoderContext pCtx) { | 1448 | int32_t WelsCalcDeqCoeffScalingList (PWelsDecoderContext pCtx) { |
| 1449 | if (pCtx->pSps->bSeqScalingMatrixPresentFlag || pCtx->pPps->bPicScalingMatrixPresentFlag) { | 1449 | if (pCtx->pSps->bSeqScalingMatrixPresentFlag || pCtx->pPps->bPicScalingMatrixPresentFlag) { |
| 1450 | pCtx->bUseScalingList = true; | 1450 | pCtx->bUseScalingList = true; |
| 1451 | 1451 | ||
| 1452 | if (!pCtx->bDequantCoeff4x4Init || (pCtx->iDequantCoeffPpsid != pCtx->pPps->iPpsId)) { | 1452 | if (!pCtx->bDequantCoeff4x4Init || (pCtx->iDequantCoeffPpsid != pCtx->pPps->iPpsId)) { |
| 1453 | int i, q, x, y; | 1453 | int i, q, x, y; |
| 1454 | //Init dequant coeff value for different QP | 1454 | //Init dequant coeff value for different QP |
| 1455 | for (i = 0; i < 6; i++) { | 1455 | for (i = 0; i < 6; i++) { |
| 1456 | pCtx->pDequant_coeff4x4[i] = pCtx->pDequant_coeff_buffer4x4[i]; | 1456 | pCtx->pDequant_coeff4x4[i] = pCtx->pDequant_coeff_buffer4x4[i]; |
| 1457 | pCtx->pDequant_coeff8x8[i] = pCtx->pDequant_coeff_buffer8x8[i]; | 1457 | pCtx->pDequant_coeff8x8[i] = pCtx->pDequant_coeff_buffer8x8[i]; |
| 1458 | for (q = 0; q < 51; q++) { | 1458 | for (q = 0; q < 51; q++) { |
| 1459 | for (x = 0; x < 16; x++) { | 1459 | for (x = 0; x < 16; x++) { |
| 1460 | pCtx->pDequant_coeff4x4[i][q][x] = pCtx->pPps->bPicScalingMatrixPresentFlag ? pCtx->pPps->iScalingList4x4[i][x] * | 1460 | pCtx->pDequant_coeff4x4[i][q][x] = pCtx->pPps->bPicScalingMatrixPresentFlag ? pCtx->pPps->iScalingList4x4[i][x] * |
| 1461 | g_kuiDequantCoeff[q][x & 0x07] : pCtx->pSps->iScalingList4x4[i][x] * g_kuiDequantCoeff[q][x & 0x07]; | 1461 | g_kuiDequantCoeff[q][x & 0x07] : pCtx->pSps->iScalingList4x4[i][x] * g_kuiDequantCoeff[q][x & 0x07]; |
| 1462 | } | 1462 | } |
| 1463 | for (y = 0; y < 64; y++) { | 1463 | for (y = 0; y < 64; y++) { |
| 1464 | pCtx->pDequant_coeff8x8[i][q][y] = pCtx->pPps->bPicScalingMatrixPresentFlag ? pCtx->pPps->iScalingList8x8[i][y] * | 1464 | pCtx->pDequant_coeff8x8[i][q][y] = pCtx->pPps->bPicScalingMatrixPresentFlag ? pCtx->pPps->iScalingList8x8[i][y] * |
| 1465 | g_kuiMatrixV[q % 6][y / 8][y % 8] : pCtx->pSps->iScalingList8x8[i][y] * g_kuiMatrixV[q % 6][y / 8][y % 8]; | 1465 | g_kuiMatrixV[q % 6][y / 8][y % 8] : pCtx->pSps->iScalingList8x8[i][y] * g_kuiMatrixV[q % 6][y / 8][y % 8]; |
| 1466 | } | 1466 | } |
| 1467 | } | 1467 | } |
| 1468 | } | 1468 | } |
| 1469 | pCtx->bDequantCoeff4x4Init = true; | 1469 | pCtx->bDequantCoeff4x4Init = true; |
| 1470 | pCtx->iDequantCoeffPpsid = pCtx->pPps->iPpsId; | 1470 | pCtx->iDequantCoeffPpsid = pCtx->pPps->iPpsId; |
| 1471 | } | 1471 | } |
| 1472 | } else | 1472 | } else |
| 1473 | pCtx->bUseScalingList = false; | 1473 | pCtx->bUseScalingList = false; |
| 1474 | return ERR_NONE; | 1474 | return ERR_NONE; |
| 1475 | } | 1475 | } |
| 1476 | 1476 | ||
| 1477 | int32_t WelsDecodeSlice (PWelsDecoderContext pCtx, bool bFirstSliceInLayer, PNalUnit pNalCur) { | 1477 | int32_t WelsDecodeSlice (PWelsDecoderContext pCtx, bool bFirstSliceInLayer, PNalUnit pNalCur) { |
| 1478 | PDqLayer pCurLayer = pCtx->pCurDqLayer; | 1478 | PDqLayer pCurLayer = pCtx->pCurDqLayer; |
| 1479 | PFmo pFmo = pCtx->pFmo; | 1479 | PFmo pFmo = pCtx->pFmo; |
| 1480 | int32_t iRet; | 1480 | int32_t iRet; |
| 1481 | int32_t iNextMbXyIndex, iSliceIdc; | 1481 | int32_t iNextMbXyIndex, iSliceIdc; |
| 1482 | 1482 | ||
| 1483 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; | 1483 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; |
| 1484 | PSliceHeaderExt pSliceHeaderExt = &pSlice->sSliceHeaderExt; | 1484 | PSliceHeaderExt pSliceHeaderExt = &pSlice->sSliceHeaderExt; |
| 1485 | PSliceHeader pSliceHeader = &pSliceHeaderExt->sSliceHeader; | 1485 | PSliceHeader pSliceHeader = &pSliceHeaderExt->sSliceHeader; |
| 1486 | int32_t iMbX, iMbY; | 1486 | int32_t iMbX, iMbY; |
| 1487 | const int32_t kiCountNumMb = pSliceHeader->pSps->uiTotalMbCount; //need to be correct when fmo or multi slice | 1487 | const int32_t kiCountNumMb = pSliceHeader->pSps->uiTotalMbCount; //need to be correct when fmo or multi slice |
| 1488 | uint32_t uiEosFlag = 0; | 1488 | uint32_t uiEosFlag = 0; |
| 1489 | PWelsDecMbFunc pDecMbFunc; | 1489 | PWelsDecMbFunc pDecMbFunc; |
| 1490 | 1490 | ||
| 1491 | pSlice->iTotalMbInCurSlice = 0; //initialize at the starting of slice decoding. | 1491 | pSlice->iTotalMbInCurSlice = 0; //initialize at the starting of slice decoding. |
| 1492 | 1492 | ||
| 1493 | if (pCtx->pPps->bEntropyCodingModeFlag) { | 1493 | if (pCtx->pPps->bEntropyCodingModeFlag) { |
| 1494 | if (pSlice->sSliceHeaderExt.bAdaptiveMotionPredFlag || | 1494 | if (pSlice->sSliceHeaderExt.bAdaptiveMotionPredFlag || |
| 1495 | pSlice->sSliceHeaderExt.bAdaptiveBaseModeFlag || | 1495 | pSlice->sSliceHeaderExt.bAdaptiveBaseModeFlag || |
| 1496 | pSlice->sSliceHeaderExt.bAdaptiveResidualPredFlag) { | 1496 | pSlice->sSliceHeaderExt.bAdaptiveResidualPredFlag) { |
| 1497 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, | 1497 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, |
| 1498 | "WelsDecodeSlice()::::ILP flag exist, not supported with CABAC enabled!"); | 1498 | "WelsDecodeSlice()::::ILP flag exist, not supported with CABAC enabled!"); |
| 1499 | pCtx->iErrorCode |= dsBitstreamError; | 1499 | pCtx->iErrorCode |= dsBitstreamError; |
| 1500 | return dsBitstreamError; | 1500 | return dsBitstreamError; |
| 1501 | } | 1501 | } |
| 1502 | if (P_SLICE == pSliceHeader->eSliceType) | 1502 | if (P_SLICE == pSliceHeader->eSliceType) |
| 1503 | pDecMbFunc = WelsDecodeMbCabacPSlice; | 1503 | pDecMbFunc = WelsDecodeMbCabacPSlice; |
| 1504 | else if (B_SLICE == pSliceHeader->eSliceType) | 1504 | else if (B_SLICE == pSliceHeader->eSliceType) |
| 1505 | pDecMbFunc = WelsDecodeMbCabacBSlice; | 1505 | pDecMbFunc = WelsDecodeMbCabacBSlice; |
| 1506 | else //I_SLICE. B_SLICE is being supported | 1506 | else //I_SLICE. B_SLICE is being supported |
| 1507 | pDecMbFunc = WelsDecodeMbCabacISlice; | 1507 | pDecMbFunc = WelsDecodeMbCabacISlice; |
| 1508 | } else { | 1508 | } else { |
| 1509 | if (P_SLICE == pSliceHeader->eSliceType) { | 1509 | if (P_SLICE == pSliceHeader->eSliceType) { |
| 1510 | pDecMbFunc = WelsDecodeMbCavlcPSlice; | 1510 | pDecMbFunc = WelsDecodeMbCavlcPSlice; |
| 1511 | } else { //I_SLICE | 1511 | } else { //I_SLICE |
| 1512 | pDecMbFunc = WelsDecodeMbCavlcISlice; | 1512 | pDecMbFunc = WelsDecodeMbCavlcISlice; |
| 1513 | } | 1513 | } |
| 1514 | } | 1514 | } |
| 1515 | 1515 | ||
| 1516 | if (pSliceHeader->pPps->bConstainedIntraPredFlag) { | 1516 | if (pSliceHeader->pPps->bConstainedIntraPredFlag) { |
| 1517 | pCtx->pFillInfoCacheIntraNxNFunc = WelsFillCacheConstrain1IntraNxN; | 1517 | pCtx->pFillInfoCacheIntraNxNFunc = WelsFillCacheConstrain1IntraNxN; |
| 1518 | pCtx->pMapNxNNeighToSampleFunc = WelsMapNxNNeighToSampleConstrain1; | 1518 | pCtx->pMapNxNNeighToSampleFunc = WelsMapNxNNeighToSampleConstrain1; |
| 1519 | pCtx->pMap16x16NeighToSampleFunc = WelsMap16x16NeighToSampleConstrain1; | 1519 | pCtx->pMap16x16NeighToSampleFunc = WelsMap16x16NeighToSampleConstrain1; |
| 1520 | } else { | 1520 | } else { |
| 1521 | pCtx->pFillInfoCacheIntraNxNFunc = WelsFillCacheConstrain0IntraNxN; | 1521 | pCtx->pFillInfoCacheIntraNxNFunc = WelsFillCacheConstrain0IntraNxN; |
| 1522 | pCtx->pMapNxNNeighToSampleFunc = WelsMapNxNNeighToSampleNormal; | 1522 | pCtx->pMapNxNNeighToSampleFunc = WelsMapNxNNeighToSampleNormal; |
| 1523 | pCtx->pMap16x16NeighToSampleFunc = WelsMap16x16NeighToSampleNormal; | 1523 | pCtx->pMap16x16NeighToSampleFunc = WelsMap16x16NeighToSampleNormal; |
| 1524 | } | 1524 | } |
| 1525 | 1525 | ||
| 1526 | pCtx->eSliceType = pSliceHeader->eSliceType; | 1526 | pCtx->eSliceType = pSliceHeader->eSliceType; |
| 1527 | if (pCurLayer->sLayerInfo.pPps->bEntropyCodingModeFlag == 1) { | 1527 | if (pCurLayer->sLayerInfo.pPps->bEntropyCodingModeFlag == 1) { |
| 1528 | int32_t iQp = pSlice->sSliceHeaderExt.sSliceHeader.iSliceQp; | 1528 | int32_t iQp = pSlice->sSliceHeaderExt.sSliceHeader.iSliceQp; |
| 1529 | int32_t iCabacInitIdc = pSlice->sSliceHeaderExt.sSliceHeader.iCabacInitIdc; | 1529 | int32_t iCabacInitIdc = pSlice->sSliceHeaderExt.sSliceHeader.iCabacInitIdc; |
| 1530 | WelsCabacContextInit (pCtx, pSlice->eSliceType, iCabacInitIdc, iQp); | 1530 | WelsCabacContextInit (pCtx, pSlice->eSliceType, iCabacInitIdc, iQp); |
| 1531 | //InitCabacCtx (pCtx->pCabacCtx, pSlice->eSliceType, iCabacInitIdc, iQp); | 1531 | //InitCabacCtx (pCtx->pCabacCtx, pSlice->eSliceType, iCabacInitIdc, iQp); |
| 1532 | pSlice->iLastDeltaQp = 0; | 1532 | pSlice->iLastDeltaQp = 0; |
| 1533 | WELS_READ_VERIFY (InitCabacDecEngineFromBS (pCtx->pCabacDecEngine, pCtx->pCurDqLayer->pBitStringAux)); | 1533 | WELS_READ_VERIFY (InitCabacDecEngineFromBS (pCtx->pCabacDecEngine, pCtx->pCurDqLayer->pBitStringAux)); |
| 1534 | } | 1534 | } |
| 1535 | //try to calculate the dequant_coeff | 1535 | //try to calculate the dequant_coeff |
| 1536 | WelsCalcDeqCoeffScalingList (pCtx); | 1536 | WelsCalcDeqCoeffScalingList (pCtx); |
| 1537 | 1537 | ||
| 1538 | iNextMbXyIndex = pSliceHeader->iFirstMbInSlice; | 1538 | iNextMbXyIndex = pSliceHeader->iFirstMbInSlice; |
| 1539 | iMbX = iNextMbXyIndex % pCurLayer->iMbWidth; | 1539 | iMbX = iNextMbXyIndex % pCurLayer->iMbWidth; |
| 1540 | iMbY = iNextMbXyIndex / pCurLayer->iMbWidth; // error is introduced by multiple slices case, 11/23/2009 | 1540 | iMbY = iNextMbXyIndex / pCurLayer->iMbWidth; // error is introduced by multiple slices case, 11/23/2009 |
| 1541 | pSlice->iMbSkipRun = -1; | 1541 | pSlice->iMbSkipRun = -1; |
| 1542 | iSliceIdc = (pSliceHeader->iFirstMbInSlice << 7) + pCurLayer->uiLayerDqId; | 1542 | iSliceIdc = (pSliceHeader->iFirstMbInSlice << 7) + pCurLayer->uiLayerDqId; |
| 1543 | 1543 | ||
| 1544 | pCurLayer->iMbX = iMbX; | 1544 | pCurLayer->iMbX = iMbX; |
| 1545 | pCurLayer->iMbY = iMbY; | 1545 | pCurLayer->iMbY = iMbY; |
| 1546 | pCurLayer->iMbXyIndex = iNextMbXyIndex; | 1546 | pCurLayer->iMbXyIndex = iNextMbXyIndex; |
| 1547 | 1547 | ||
| 1548 | do { | 1548 | do { |
| 1549 | if ((-1 == iNextMbXyIndex) || (iNextMbXyIndex >= kiCountNumMb)) { // slice group boundary or end of a frame | 1549 | if ((-1 == iNextMbXyIndex) || (iNextMbXyIndex >= kiCountNumMb)) { // slice group boundary or end of a frame |
| 1550 | break; | 1550 | break; |
| 1551 | } | 1551 | } |
| 1552 | 1552 | ||
| 1553 | pCurLayer->pSliceIdc[iNextMbXyIndex] = iSliceIdc; | 1553 | pCurLayer->pSliceIdc[iNextMbXyIndex] = iSliceIdc; |
| 1554 | pCtx->bMbRefConcealed = false; | 1554 | pCtx->bMbRefConcealed = false; |
| 1555 | iRet = pDecMbFunc (pCtx, pNalCur, uiEosFlag); | 1555 | iRet = pDecMbFunc (pCtx, pNalCur, uiEosFlag); |
| 1556 | pCurLayer->pMbRefConcealedFlag[iNextMbXyIndex] = pCtx->bMbRefConcealed; | 1556 | pCurLayer->pMbRefConcealedFlag[iNextMbXyIndex] = pCtx->bMbRefConcealed; |
| 1557 | if (iRet != ERR_NONE) { | 1557 | if (iRet != ERR_NONE) { |
| 1558 | return iRet; | 1558 | return iRet; |
| 1559 | } | 1559 | } |
| 1560 | 1560 | ||
| 1561 | ++pSlice->iTotalMbInCurSlice; | 1561 | ++pSlice->iTotalMbInCurSlice; |
| 1562 | if (uiEosFlag) { //end of slice | 1562 | if (uiEosFlag) { //end of slice |
| 1563 | break; | 1563 | break; |
| 1564 | } | 1564 | } |
| 1565 | if (pSliceHeader->pPps->uiNumSliceGroups > 1) { | 1565 | if (pSliceHeader->pPps->uiNumSliceGroups > 1) { |
| 1566 | iNextMbXyIndex = FmoNextMb (pFmo, iNextMbXyIndex); | 1566 | iNextMbXyIndex = FmoNextMb (pFmo, iNextMbXyIndex); |
| 1567 | } else { | 1567 | } else { |
| 1568 | ++iNextMbXyIndex; | 1568 | ++iNextMbXyIndex; |
| 1569 | } | 1569 | } |
| 1570 | iMbX = iNextMbXyIndex % pCurLayer->iMbWidth; | 1570 | iMbX = iNextMbXyIndex % pCurLayer->iMbWidth; |
| 1571 | iMbY = iNextMbXyIndex / pCurLayer->iMbWidth; | 1571 | iMbY = iNextMbXyIndex / pCurLayer->iMbWidth; |
| 1572 | pCurLayer->iMbX = iMbX; | 1572 | pCurLayer->iMbX = iMbX; |
| 1573 | pCurLayer->iMbY = iMbY; | 1573 | pCurLayer->iMbY = iMbY; |
| 1574 | pCurLayer->iMbXyIndex = iNextMbXyIndex; | 1574 | pCurLayer->iMbXyIndex = iNextMbXyIndex; |
| 1575 | } while (1); | 1575 | } while (1); |
| 1576 | 1576 | ||
| 1577 | return ERR_NONE; | 1577 | return ERR_NONE; |
| 1578 | } | 1578 | } |
| 1579 | 1579 | ||
| 1580 | int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { | 1580 | int32_t WelsActualDecodeMbCavlcISlice (PWelsDecoderContext pCtx) { |
| 1581 | SVlcTable* pVlcTable = &pCtx->sVlcTable; | 1581 | SVlcTable* pVlcTable = &pCtx->sVlcTable; |
| 1582 | PDqLayer pCurLayer = pCtx->pCurDqLayer; | 1582 | PDqLayer pCurLayer = pCtx->pCurDqLayer; |
| 1583 | PBitStringAux pBs = pCurLayer->pBitStringAux; | 1583 | PBitStringAux pBs = pCurLayer->pBitStringAux; |
| 1584 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; | 1584 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; |
| 1585 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | 1585 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; |
| 1586 | 1586 | ||
| 1587 | SWelsNeighAvail sNeighAvail; | 1587 | SWelsNeighAvail sNeighAvail; |
| 1588 | int32_t iMbResProperty; | 1588 | int32_t iMbResProperty; |
| 1589 | 1589 | ||
| 1590 | int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart; | 1590 | int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart; |
| 1591 | int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd; | 1591 | int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd; |
| 1592 | 1592 | ||
| 1593 | int32_t iMbX = pCurLayer->iMbX; | 1593 | int32_t iMbX = pCurLayer->iMbX; |
| 1594 | int32_t iMbY = pCurLayer->iMbY; | 1594 | int32_t iMbY = pCurLayer->iMbY; |
| 1595 | const int32_t iMbXy = pCurLayer->iMbXyIndex; | 1595 | const int32_t iMbXy = pCurLayer->iMbXyIndex; |
| 1596 | int8_t* pNzc = pCurLayer->pNzc[iMbXy]; | 1596 | int8_t* pNzc = pCurLayer->pNzc[iMbXy]; |
| 1597 | int32_t i; | 1597 | int32_t i; |
| 1598 | int32_t iRet = ERR_NONE; | 1598 | int32_t iRet = ERR_NONE; |
| 1599 | uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0; | 1599 | uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0; |
| 1600 | uint32_t uiCode; | 1600 | uint32_t uiCode; |
| 1601 | int32_t iCode; | 1601 | int32_t iCode; |
| 1602 | 1602 | ||
| 1603 | ENFORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16); | 1603 | ENFORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16); |
| 1604 | GetNeighborAvailMbType (&sNeighAvail, pCurLayer); | 1604 | GetNeighborAvailMbType (&sNeighAvail, pCurLayer); |
| 1605 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; | 1605 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; |
| 1606 | pCurLayer->pResidualPredFlag[iMbXy] = pSlice->sSliceHeaderExt.bDefaultResidualPredFlag; | 1606 | pCurLayer->pResidualPredFlag[iMbXy] = pSlice->sSliceHeaderExt.bDefaultResidualPredFlag; |
| 1607 | 1607 | ||
| 1608 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; | 1608 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; |
| 1609 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; | 1609 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; |
| 1610 | 1610 | ||
| 1611 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //uiMbType | 1611 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //uiMbType |
| 1612 | uiMbType = uiCode; | 1612 | uiMbType = uiCode; |
| 1613 | if (uiMbType > 25) | 1613 | if (uiMbType > 25) |
| 1614 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); | 1614 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); |
| 1615 | if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 && uiMbType <= 24))) | 1615 | if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 && uiMbType <= 24))) |
| 1616 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); | 1616 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); |
| 1617 | 1617 | ||
| 1618 | if (25 == uiMbType) { | 1618 | if (25 == uiMbType) { |
| 1619 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "I_PCM mode exists in I slice!"); | 1619 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "I_PCM mode exists in I slice!"); |
| 1620 | int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0]; | 1620 | int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0]; |
| 1621 | int32_t iDecStrideC = pCurLayer->pDec->iLinesize[1]; | 1621 | int32_t iDecStrideC = pCurLayer->pDec->iLinesize[1]; |
| 1622 | 1622 | ||
| 1623 | int32_t iOffsetL = (iMbX + iMbY * iDecStrideL) << 4; | 1623 | int32_t iOffsetL = (iMbX + iMbY * iDecStrideL) << 4; |
| 1624 | int32_t iOffsetC = (iMbX + iMbY * iDecStrideC) << 3; | 1624 | int32_t iOffsetC = (iMbX + iMbY * iDecStrideC) << 3; |
| 1625 | 1625 | ||
| 1626 | uint8_t* pDecY = pCurLayer->pDec->pData[0] + iOffsetL; | 1626 | uint8_t* pDecY = pCurLayer->pDec->pData[0] + iOffsetL; |
| 1627 | uint8_t* pDecU = pCurLayer->pDec->pData[1] + iOffsetC; | 1627 | uint8_t* pDecU = pCurLayer->pDec->pData[1] + iOffsetC; |
| 1628 | uint8_t* pDecV = pCurLayer->pDec->pData[2] + iOffsetC; | 1628 | uint8_t* pDecV = pCurLayer->pDec->pData[2] + iOffsetC; |
| 1629 | 1629 | ||
| 1630 | uint8_t* pTmpBsBuf; | 1630 | uint8_t* pTmpBsBuf; |
| 1631 | 1631 | ||
| 1632 | 1632 | ||
| 1633 | int32_t i; | 1633 | int32_t i; |
| 1634 | int32_t iCopySizeY = (sizeof (uint8_t) << 4); | 1634 | int32_t iCopySizeY = (sizeof (uint8_t) << 4); |
| 1635 | int32_t iCopySizeUV = (sizeof (uint8_t) << 3); | 1635 | int32_t iCopySizeUV = (sizeof (uint8_t) << 3); |
| 1636 | 1636 | ||
| 1637 | int32_t iIndex = ((-pBs->iLeftBits) >> 3) + 2; | 1637 | int32_t iIndex = ((-pBs->iLeftBits) >> 3) + 2; |
| 1638 | 1638 | ||
| 1639 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA_PCM; | 1639 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA_PCM; |
| 1640 | 1640 | ||
| 1641 | //step 1: locating bit-stream pointer [must align into integer byte] | 1641 | //step 1: locating bit-stream pointer [must align into integer byte] |
| 1642 | pBs->pCurBuf -= iIndex; | 1642 | pBs->pCurBuf -= iIndex; |
| 1643 | 1643 | ||
| 1644 | //step 2: copy pixel from bit-stream into fdec [reconstruction] | 1644 | //step 2: copy pixel from bit-stream into fdec [reconstruction] |
| 1645 | pTmpBsBuf = pBs->pCurBuf; | 1645 | pTmpBsBuf = pBs->pCurBuf; |
| 1646 | if (!pCtx->pParam->bParseOnly) { | 1646 | if (!pCtx->pParam->bParseOnly) { |
| 1647 | for (i = 0; i < 16; i++) { //luma | 1647 | for (i = 0; i < 16; i++) { //luma |
| 1648 | memcpy (pDecY, pTmpBsBuf, iCopySizeY); | 1648 | memcpy (pDecY, pTmpBsBuf, iCopySizeY); |
| 1649 | pDecY += iDecStrideL; | 1649 | pDecY += iDecStrideL; |
| 1650 | pTmpBsBuf += 16; | 1650 | pTmpBsBuf += 16; |
| 1651 | } | 1651 | } |
| 1652 | for (i = 0; i < 8; i++) { //cb | 1652 | for (i = 0; i < 8; i++) { //cb |
| 1653 | memcpy (pDecU, pTmpBsBuf, iCopySizeUV); | 1653 | memcpy (pDecU, pTmpBsBuf, iCopySizeUV); |
| 1654 | pDecU += iDecStrideC; | 1654 | pDecU += iDecStrideC; |
| 1655 | pTmpBsBuf += 8; | 1655 | pTmpBsBuf += 8; |
| 1656 | } | 1656 | } |
| 1657 | for (i = 0; i < 8; i++) { //cr | 1657 | for (i = 0; i < 8; i++) { //cr |
| 1658 | memcpy (pDecV, pTmpBsBuf, iCopySizeUV); | 1658 | memcpy (pDecV, pTmpBsBuf, iCopySizeUV); |
| 1659 | pDecV += iDecStrideC; | 1659 | pDecV += iDecStrideC; |
| 1660 | pTmpBsBuf += 8; | 1660 | pTmpBsBuf += 8; |
| 1661 | } | 1661 | } |
| 1662 | } | 1662 | } |
| 1663 | 1663 | ||
| 1664 | pBs->pCurBuf += 384; | 1664 | pBs->pCurBuf += 384; |
| 1665 | 1665 | ||
| 1666 | //step 3: update QP and pNonZeroCount | 1666 | //step 3: update QP and pNonZeroCount |
| 1667 | pCurLayer->pLumaQp[iMbXy] = 0; | 1667 | pCurLayer->pLumaQp[iMbXy] = 0; |
| 1668 | memset (pCurLayer->pChromaQp[iMbXy], 0, sizeof (pCurLayer->pChromaQp[iMbXy])); | 1668 | memset (pCurLayer->pChromaQp[iMbXy], 0, sizeof (pCurLayer->pChromaQp[iMbXy])); |
| 1669 | memset (pNzc, 16, sizeof (pCurLayer->pNzc[iMbXy])); //Rec. 9.2.1 for PCM, nzc=16 | 1669 | memset (pNzc, 16, sizeof (pCurLayer->pNzc[iMbXy])); //Rec. 9.2.1 for PCM, nzc=16 |
| 1670 | WELS_READ_VERIFY (InitReadBits (pBs, 0)); | 1670 | WELS_READ_VERIFY (InitReadBits (pBs, 0)); |
| 1671 | return ERR_NONE; | 1671 | return ERR_NONE; |
| 1672 | } else if (0 == uiMbType) { //reference to JM | 1672 | } else if (0 == uiMbType) { //reference to JM |
| 1673 | ENFORCE_STACK_ALIGN_1D (int8_t, pIntraPredMode, 48, 16); | 1673 | ENFORCE_STACK_ALIGN_1D (int8_t, pIntraPredMode, 48, 16); |
| 1674 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA4x4; | 1674 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA4x4; |
| 1675 | if (pCtx->pPps->bTransform8x8ModeFlag) { | 1675 | if (pCtx->pPps->bTransform8x8ModeFlag) { |
| 1676 | WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //transform_size_8x8_flag | 1676 | WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //transform_size_8x8_flag |
| 1677 | pCurLayer->pTransformSize8x8Flag[iMbXy] = !!uiCode; | 1677 | pCurLayer->pTransformSize8x8Flag[iMbXy] = !!uiCode; |
| 1678 | if (pCurLayer->pTransformSize8x8Flag[iMbXy]) { | 1678 | if (pCurLayer->pTransformSize8x8Flag[iMbXy]) { |
| 1679 | uiMbType = pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA8x8; | 1679 | uiMbType = pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA8x8; |
| 1680 | } | 1680 | } |
| 1681 | } | 1681 | } |
| 1682 | if (!pCurLayer->pTransformSize8x8Flag[iMbXy]) { | 1682 | if (!pCurLayer->pTransformSize8x8Flag[iMbXy]) { |
| 1683 | pCtx->pFillInfoCacheIntraNxNFunc (&sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); | 1683 | pCtx->pFillInfoCacheIntraNxNFunc (&sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); |
| 1684 | WELS_READ_VERIFY (ParseIntra4x4Mode (pCtx, &sNeighAvail, pIntraPredMode, pBs, pCurLayer)); | 1684 | WELS_READ_VERIFY (ParseIntra4x4Mode (pCtx, &sNeighAvail, pIntraPredMode, pBs, pCurLayer)); |
| 1685 | } else { | 1685 | } else { |
| 1686 | pCtx->pFillInfoCacheIntraNxNFunc (&sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); | 1686 | pCtx->pFillInfoCacheIntraNxNFunc (&sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); |
| 1687 | WELS_READ_VERIFY (ParseIntra8x8Mode (pCtx, &sNeighAvail, pIntraPredMode, pBs, pCurLayer)); | 1687 | WELS_READ_VERIFY (ParseIntra8x8Mode (pCtx, &sNeighAvail, pIntraPredMode, pBs, pCurLayer)); |
| 1688 | } | 1688 | } |
| 1689 | 1689 | ||
| 1690 | //uiCbp | 1690 | //uiCbp |
| 1691 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //coded_block_pattern | 1691 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //coded_block_pattern |
| 1692 | uiCbp = uiCode; | 1692 | uiCbp = uiCode; |
| 1693 | //G.9.1 Alternative parsing process for coded pBlock pattern | 1693 | //G.9.1 Alternative parsing process for coded pBlock pattern |
| 1694 | if (pCtx->pSps->uiChromaFormatIdc && (uiCbp > 47)) | 1694 | if (pCtx->pSps->uiChromaFormatIdc && (uiCbp > 47)) |
| 1695 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_CBP); | 1695 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_CBP); |
| 1696 | if (!pCtx->pSps->uiChromaFormatIdc && (uiCbp > 15)) | 1696 | if (!pCtx->pSps->uiChromaFormatIdc && (uiCbp > 15)) |
| 1697 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_CBP); | 1697 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_CBP); |
| 1698 | 1698 | ||
| 1699 | if (pCtx->pSps->uiChromaFormatIdc) | 1699 | if (pCtx->pSps->uiChromaFormatIdc) |
| 1700 | uiCbp = g_kuiIntra4x4CbpTable[uiCbp]; | 1700 | uiCbp = g_kuiIntra4x4CbpTable[uiCbp]; |
| 1701 | else | 1701 | else |
| 1702 | uiCbp = g_kuiIntra4x4CbpTable400[uiCbp]; | 1702 | uiCbp = g_kuiIntra4x4CbpTable400[uiCbp]; |
| 1703 | pCurLayer->pCbp[iMbXy] = uiCbp; | 1703 | pCurLayer->pCbp[iMbXy] = uiCbp; |
| 1704 | uiCbpC = uiCbp >> 4; | 1704 | uiCbpC = uiCbp >> 4; |
| 1705 | uiCbpL = uiCbp & 15; | 1705 | uiCbpL = uiCbp & 15; |
| 1706 | } else { //I_PCM exclude, we can ignore it | 1706 | } else { //I_PCM exclude, we can ignore it |
| 1707 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16; | 1707 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16; |
| 1708 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; | 1708 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; |
| 1709 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; | 1709 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; |
| 1710 | pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3; | 1710 | pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3; |
| 1711 | pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2]; | 1711 | pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2]; |
| 1712 | uiCbpC = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0; | 1712 | uiCbpC = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0; |
| 1713 | uiCbpL = pCurLayer->pCbp[iMbXy] & 15; | 1713 | uiCbpL = pCurLayer->pCbp[iMbXy] & 15; |
| 1714 | WelsFillCacheNonZeroCount (&sNeighAvail, pNonZeroCount, pCurLayer); | 1714 | WelsFillCacheNonZeroCount (&sNeighAvail, pNonZeroCount, pCurLayer); |
| 1715 | WELS_READ_VERIFY (ParseIntra16x16Mode (pCtx, &sNeighAvail, pBs, pCurLayer)); | 1715 | WELS_READ_VERIFY (ParseIntra16x16Mode (pCtx, &sNeighAvail, pBs, pCurLayer)); |
| 1716 | } | 1716 | } |
| 1717 | 1717 | ||
| 1718 | ST32A4 (&pNzc[0], 0); | 1718 | ST32A4 (&pNzc[0], 0); |
| 1719 | ST32A4 (&pNzc[4], 0); | 1719 | ST32A4 (&pNzc[4], 0); |
| 1720 | ST32A4 (&pNzc[8], 0); | 1720 | ST32A4 (&pNzc[8], 0); |
| 1721 | ST32A4 (&pNzc[12], 0); | 1721 | ST32A4 (&pNzc[12], 0); |
| 1722 | ST32A4 (&pNzc[16], 0); | 1722 | ST32A4 (&pNzc[16], 0); |
| 1723 | ST32A4 (&pNzc[20], 0); | 1723 | ST32A4 (&pNzc[20], 0); |
| 1724 | 1724 | ||
| 1725 | if (pCurLayer->pCbp[iMbXy] == 0 && IS_INTRANxN (pCurLayer->pMbType[iMbXy])) { | 1725 | if (pCurLayer->pCbp[iMbXy] == 0 && IS_INTRANxN (pCurLayer->pMbType[iMbXy])) { |
| 1726 | pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; | 1726 | pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; |
| 1727 | for (i = 0; i < 2; i++) { | 1727 | for (i = 0; i < 2; i++) { |
| 1728 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pCurLayer->pLumaQp[iMbXy] + | 1728 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pCurLayer->pLumaQp[iMbXy] + |
| 1729 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; | 1729 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; |
| 1730 | } | 1730 | } |
| 1731 | 1731 | ||
| 1732 | } | 1732 | } |
| 1733 | 1733 | ||
| 1734 | if (pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { | 1734 | if (pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { |
| 1735 | memset (pCurLayer->pScaledTCoeff[iMbXy], 0, 384 * sizeof (pCurLayer->pScaledTCoeff[iMbXy][0])); | 1735 | memset (pCurLayer->pScaledTCoeff[iMbXy], 0, 384 * sizeof (pCurLayer->pScaledTCoeff[iMbXy][0])); |
| 1736 | int32_t iQpDelta, iId8x8, iId4x4; | 1736 | int32_t iQpDelta, iId8x8, iId4x4; |
| 1737 | 1737 | ||
| 1738 | WELS_READ_VERIFY (BsGetSe (pBs, &iCode)); //mb_qp_delta | 1738 | WELS_READ_VERIFY (BsGetSe (pBs, &iCode)); //mb_qp_delta |
| 1739 | iQpDelta = iCode; | 1739 | iQpDelta = iCode; |
| 1740 | 1740 | ||
| 1741 | if (iQpDelta > 25 || iQpDelta < -26) { //out of iQpDelta range | 1741 | if (iQpDelta > 25 || iQpDelta < -26) { //out of iQpDelta range |
| 1742 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_QP); | 1742 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_QP); |
| 1743 | } | 1743 | } |
| 1744 | 1744 | ||
| 1745 | pCurLayer->pLumaQp[iMbXy] = (pSlice->iLastMbQp + iQpDelta + 52) % 52; //update last_mb_qp | 1745 | pCurLayer->pLumaQp[iMbXy] = (pSlice->iLastMbQp + iQpDelta + 52) % 52; //update last_mb_qp |
| 1746 | pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy]; | 1746 | pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy]; |
| 1747 | for (i = 0; i < 2; i++) { | 1747 | for (i = 0; i < 2; i++) { |
| 1748 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pSlice->iLastMbQp + | 1748 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pSlice->iLastMbQp + |
| 1749 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, | 1749 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, |
| 1750 | 51)]; | 1750 | 51)]; |
| 1751 | } | 1751 | } |
| 1752 | 1752 | ||
| 1753 | 1753 | ||
| 1754 | BsStartCavlc (pBs); | 1754 | BsStartCavlc (pBs); |
| 1755 | 1755 | ||
| 1756 | if (MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { | 1756 | if (MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { |
| 1757 | //step1: Luma DC | 1757 | //step1: Luma DC |
| 1758 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, 0, 16, g_kuiLumaDcZigzagScan, I16_LUMA_DC, | 1758 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, 0, 16, g_kuiLumaDcZigzagScan, I16_LUMA_DC, |
| 1759 | pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) { | 1759 | pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) { |
| 1760 | return iRet;//abnormal | 1760 | return iRet;//abnormal |
| 1761 | } | 1761 | } |
| 1762 | //step2: Luma AC | 1762 | //step2: Luma AC |
| 1763 | if (uiCbpL) { | 1763 | if (uiCbpL) { |
| 1764 | for (i = 0; i < 16; i++) { | 1764 | for (i = 0; i < 16; i++) { |
| 1765 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, i, iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, | 1765 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, i, iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, |
| 1766 | g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i << 4), | 1766 | g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i << 4), |
| 1767 | pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) { | 1767 | pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) { |
| 1768 | return iRet;//abnormal | 1768 | return iRet;//abnormal |
| 1769 | } | 1769 | } |
| 1770 | } | 1770 | } |
| 1771 | ST32A4 (&pNzc[0], LD32 (&pNonZeroCount[1 + 8 * 1])); | 1771 | ST32A4 (&pNzc[0], LD32 (&pNonZeroCount[1 + 8 * 1])); |
| 1772 | ST32A4 (&pNzc[4], LD32 (&pNonZeroCount[1 + 8 * 2])); | 1772 | ST32A4 (&pNzc[4], LD32 (&pNonZeroCount[1 + 8 * 2])); |
| 1773 | ST32A4 (&pNzc[8], LD32 (&pNonZeroCount[1 + 8 * 3])); | 1773 | ST32A4 (&pNzc[8], LD32 (&pNonZeroCount[1 + 8 * 3])); |
| 1774 | ST32A4 (&pNzc[12], LD32 (&pNonZeroCount[1 + 8 * 4])); | 1774 | ST32A4 (&pNzc[12], LD32 (&pNonZeroCount[1 + 8 * 4])); |
| 1775 | } | 1775 | } |
| 1776 | } else { //non-MB_TYPE_INTRA16x16 | 1776 | } else { //non-MB_TYPE_INTRA16x16 |
| 1777 | if (pCurLayer->pTransformSize8x8Flag[iMbXy]) { | 1777 | if (pCurLayer->pTransformSize8x8Flag[iMbXy]) { |
| 1778 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { | 1778 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { |
| 1779 | iMbResProperty = (IS_INTRA (pCurLayer->pMbType[iMbXy])) ? LUMA_DC_AC_INTRA_8 : LUMA_DC_AC_INTER_8; | 1779 | iMbResProperty = (IS_INTRA (pCurLayer->pMbType[iMbXy])) ? LUMA_DC_AC_INTRA_8 : LUMA_DC_AC_INTER_8; |
| 1780 | if (uiCbpL & (1 << iId8x8)) { | 1780 | if (uiCbpL & (1 << iId8x8)) { |
| 1781 | int32_t iIndex = (iId8x8 << 2); | 1781 | int32_t iIndex = (iId8x8 << 2); |
| 1782 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { | 1782 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 1783 | if ((iRet = WelsResidualBlockCavlc8x8 (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - iScanIdxStart + 1, | 1783 | if ((iRet = WelsResidualBlockCavlc8x8 (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - iScanIdxStart + 1, |
| 1784 | g_kuiZigzagScan8x8 + iScanIdxStart, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iId8x8 << 6), iId4x4, | 1784 | g_kuiZigzagScan8x8 + iScanIdxStart, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iId8x8 << 6), iId4x4, |
| 1785 | pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) { | 1785 | pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) { |
| 1786 | return iRet; | 1786 | return iRet; |
| 1787 | } | 1787 | } |
| 1788 | iIndex++; | 1788 | iIndex++; |
| 1789 | } | 1789 | } |
| 1790 | } else { | 1790 | } else { |
| 1791 | ST16 (&pNonZeroCount[g_kuiCache48CountScan4Idx[iId8x8 << 2]], 0); | 1791 | ST16 (&pNonZeroCount[g_kuiCache48CountScan4Idx[iId8x8 << 2]], 0); |
| 1792 | ST16 (&pNonZeroCount[g_kuiCache48CountScan4Idx[ (iId8x8 << 2) + 2]], 0); | 1792 | ST16 (&pNonZeroCount[g_kuiCache48CountScan4Idx[ (iId8x8 << 2) + 2]], 0); |
| 1793 | } | 1793 | } |
| 1794 | } | 1794 | } |
| 1795 | ST32A4 (&pNzc[0], LD32 (&pNonZeroCount[1 + 8 * 1])); | 1795 | ST32A4 (&pNzc[0], LD32 (&pNonZeroCount[1 + 8 * 1])); |
| 1796 | ST32A4 (&pNzc[4], LD32 (&pNonZeroCount[1 + 8 * 2])); | 1796 | ST32A4 (&pNzc[4], LD32 (&pNonZeroCount[1 + 8 * 2])); |
| 1797 | ST32A4 (&pNzc[8], LD32 (&pNonZeroCount[1 + 8 * 3])); | 1797 | ST32A4 (&pNzc[8], LD32 (&pNonZeroCount[1 + 8 * 3])); |
| 1798 | ST32A4 (&pNzc[12], LD32 (&pNonZeroCount[1 + 8 * 4])); | 1798 | ST32A4 (&pNzc[12], LD32 (&pNonZeroCount[1 + 8 * 4])); |
| 1799 | } else { | 1799 | } else { |
| 1800 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { | 1800 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { |
| 1801 | if (uiCbpL & (1 << iId8x8)) { | 1801 | if (uiCbpL & (1 << iId8x8)) { |
| 1802 | int32_t iIndex = (iId8x8 << 2); | 1802 | int32_t iIndex = (iId8x8 << 2); |
| 1803 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { | 1803 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 1804 | //Luma (DC and AC decoding together) | 1804 | //Luma (DC and AC decoding together) |
| 1805 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - iScanIdxStart + 1, | 1805 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - iScanIdxStart + 1, |
| 1806 | g_kuiZigzagScan + iScanIdxStart, LUMA_DC_AC_INTRA, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), | 1806 | g_kuiZigzagScan + iScanIdxStart, LUMA_DC_AC_INTRA, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), |
| 1807 | pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) { | 1807 | pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) { |
| 1808 | return iRet;//abnormal | 1808 | return iRet;//abnormal |
| 1809 | } | 1809 | } |
| 1810 | iIndex++; | 1810 | iIndex++; |
| 1811 | } | 1811 | } |
| 1812 | } else { | 1812 | } else { |
| 1813 | ST16 (&pNonZeroCount[g_kuiCache48CountScan4Idx[ (iId8x8 << 2)]], 0); | 1813 | ST16 (&pNonZeroCount[g_kuiCache48CountScan4Idx[ (iId8x8 << 2)]], 0); |
| 1814 | ST16 (&pNonZeroCount[g_kuiCache48CountScan4Idx[ (iId8x8 << 2) + 2]], 0); | 1814 | ST16 (&pNonZeroCount[g_kuiCache48CountScan4Idx[ (iId8x8 << 2) + 2]], 0); |
| 1815 | } | 1815 | } |
| 1816 | } | 1816 | } |
| 1817 | ST32A4 (&pNzc[0], LD32 (&pNonZeroCount[1 + 8 * 1])); | 1817 | ST32A4 (&pNzc[0], LD32 (&pNonZeroCount[1 + 8 * 1])); |
| 1818 | ST32A4 (&pNzc[4], LD32 (&pNonZeroCount[1 + 8 * 2])); | 1818 | ST32A4 (&pNzc[4], LD32 (&pNonZeroCount[1 + 8 * 2])); |
| 1819 | ST32A4 (&pNzc[8], LD32 (&pNonZeroCount[1 + 8 * 3])); | 1819 | ST32A4 (&pNzc[8], LD32 (&pNonZeroCount[1 + 8 * 3])); |
| 1820 | ST32A4 (&pNzc[12], LD32 (&pNonZeroCount[1 + 8 * 4])); | 1820 | ST32A4 (&pNzc[12], LD32 (&pNonZeroCount[1 + 8 * 4])); |
| 1821 | } | 1821 | } |
| 1822 | } | 1822 | } |
| 1823 | 1823 | ||
| 1824 | //chroma | 1824 | //chroma |
| 1825 | //step1: DC | 1825 | //step1: DC |
| 1826 | if (1 == uiCbpC || 2 == uiCbpC) { | 1826 | if (1 == uiCbpC || 2 == uiCbpC) { |
| 1827 | for (i = 0; i < 2; i++) { //Cb Cr | 1827 | for (i = 0; i < 2; i++) { //Cb Cr |
| 1828 | iMbResProperty = i ? CHROMA_DC_V : CHROMA_DC_U; | 1828 | iMbResProperty = i ? CHROMA_DC_V : CHROMA_DC_U; |
| 1829 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, 16 + (i << 2), 4, g_kuiChromaDcScan, iMbResProperty, | 1829 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, 16 + (i << 2), 4, g_kuiChromaDcScan, iMbResProperty, |
| 1830 | pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6), pCurLayer->pChromaQp[iMbXy][i], pCtx)) != ERR_NONE) { | 1830 | pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6), pCurLayer->pChromaQp[iMbXy][i], pCtx)) != ERR_NONE) { |
| 1831 | return iRet;//abnormal | 1831 | return iRet;//abnormal |
| 1832 | } | 1832 | } |
| 1833 | } | 1833 | } |
| 1834 | } | 1834 | } |
| 1835 | 1835 | ||
| 1836 | //step2: AC | 1836 | //step2: AC |
| 1837 | if (2 == uiCbpC) { | 1837 | if (2 == uiCbpC) { |
| 1838 | for (i = 0; i < 2; i++) { //Cb Cr | 1838 | for (i = 0; i < 2; i++) { //Cb Cr |
| 1839 | iMbResProperty = i ? CHROMA_AC_V : CHROMA_AC_U; | 1839 | iMbResProperty = i ? CHROMA_AC_V : CHROMA_AC_U; |
| 1840 | int32_t iIndex = 16 + (i << 2); | 1840 | int32_t iIndex = 16 + (i << 2); |
| 1841 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { | 1841 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 1842 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - WELS_MAX (iScanIdxStart, | 1842 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - WELS_MAX (iScanIdxStart, |
| 1843 | 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), | 1843 | 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), |
| 1844 | pCurLayer->pChromaQp[iMbXy][i], pCtx)) != ERR_NONE) { | 1844 | pCurLayer->pChromaQp[iMbXy][i], pCtx)) != ERR_NONE) { |
| 1845 | return iRet;//abnormal | 1845 | return iRet;//abnormal |
| 1846 | } | 1846 | } |
| 1847 | iIndex++; | 1847 | iIndex++; |
| 1848 | } | 1848 | } |
| 1849 | } | 1849 | } |
| 1850 | ST16A2 (&pNzc[16], LD16A2 (&pNonZeroCount[6 + 8 * 1])); | 1850 | ST16A2 (&pNzc[16], LD16A2 (&pNonZeroCount[6 + 8 * 1])); |
| 1851 | ST16A2 (&pNzc[20], LD16A2 (&pNonZeroCount[6 + 8 * 2])); | 1851 | ST16A2 (&pNzc[20], LD16A2 (&pNonZeroCount[6 + 8 * 2])); |
| 1852 | ST16A2 (&pNzc[18], LD16A2 (&pNonZeroCount[6 + 8 * 4])); | 1852 | ST16A2 (&pNzc[18], LD16A2 (&pNonZeroCount[6 + 8 * 4])); |
| 1853 | ST16A2 (&pNzc[22], LD16A2 (&pNonZeroCount[6 + 8 * 5])); | 1853 | ST16A2 (&pNzc[22], LD16A2 (&pNonZeroCount[6 + 8 * 5])); |
| 1854 | } | 1854 | } |
| 1855 | BsEndCavlc (pBs); | 1855 | BsEndCavlc (pBs); |
| 1856 | } | 1856 | } |
| 1857 | 1857 | ||
| 1858 | return ERR_NONE; | 1858 | return ERR_NONE; |
| 1859 | } | 1859 | } |
| 1860 | 1860 | ||
| 1861 | int32_t WelsDecodeMbCavlcISlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uint32_t& uiEosFlag) { | 1861 | int32_t WelsDecodeMbCavlcISlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uint32_t& uiEosFlag) { |
| 1862 | PDqLayer pCurLayer = pCtx->pCurDqLayer; | 1862 | PDqLayer pCurLayer = pCtx->pCurDqLayer; |
| 1863 | PBitStringAux pBs = pCurLayer->pBitStringAux; | 1863 | PBitStringAux pBs = pCurLayer->pBitStringAux; |
| 1864 | PSliceHeaderExt pSliceHeaderExt = &pCurLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt; | 1864 | PSliceHeaderExt pSliceHeaderExt = &pCurLayer->sLayerInfo.sSliceInLayer.sSliceHeaderExt; |
| 1865 | int32_t iBaseModeFlag; | 1865 | int32_t iBaseModeFlag; |
| 1866 | int32_t iRet = 0; //should have the return value to indicate decoding error or not, It's NECESSARY--2010.4.15 | 1866 | int32_t iRet = 0; //should have the return value to indicate decoding error or not, It's NECESSARY--2010.4.15 |
| 1867 | uint32_t uiCode; | 1867 | uint32_t uiCode; |
| 1868 | intX_t iUsedBits; | 1868 | intX_t iUsedBits; |
| 1869 | if (pSliceHeaderExt->bAdaptiveBaseModeFlag == 1) { | 1869 | if (pSliceHeaderExt->bAdaptiveBaseModeFlag == 1) { |
| 1870 | WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //base_mode_flag | 1870 | WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //base_mode_flag |
| 1871 | iBaseModeFlag = uiCode; | 1871 | iBaseModeFlag = uiCode; |
| 1872 | } else { | 1872 | } else { |
| 1873 | iBaseModeFlag = pSliceHeaderExt->bDefaultBaseModeFlag; | 1873 | iBaseModeFlag = pSliceHeaderExt->bDefaultBaseModeFlag; |
| 1874 | } | 1874 | } |
| 1875 | if (!iBaseModeFlag) { | 1875 | if (!iBaseModeFlag) { |
| 1876 | iRet = WelsActualDecodeMbCavlcISlice (pCtx); | 1876 | iRet = WelsActualDecodeMbCavlcISlice (pCtx); |
| 1877 | } else { | 1877 | } else { |
| 1878 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "iBaseModeFlag (%d) != 0, inter-layer prediction not supported.", | 1878 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "iBaseModeFlag (%d) != 0, inter-layer prediction not supported.", |
| 1879 | iBaseModeFlag); | 1879 | iBaseModeFlag); |
| 1880 | return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_ILP); | 1880 | return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_ILP); |
| 1881 | } | 1881 | } |
| 1882 | if (iRet) { //occur error when parsing, MUST STOP decoding | 1882 | if (iRet) { //occur error when parsing, MUST STOP decoding |
| 1883 | return iRet; | 1883 | return iRet; |
| 1884 | } | 1884 | } |
| 1885 | 1885 | ||
| 1886 | // check whether there is left bits to read next time in case multiple slices | 1886 | // check whether there is left bits to read next time in case multiple slices |
| 1887 | iUsedBits = ((pBs->pCurBuf - pBs->pStartBuf) << 3) - (16 - pBs->iLeftBits); | 1887 | iUsedBits = ((pBs->pCurBuf - pBs->pStartBuf) << 3) - (16 - pBs->iLeftBits); |
| 1888 | // sub 1, for stop bit | 1888 | // sub 1, for stop bit |
| 1889 | if ((iUsedBits == (pBs->iBits - 1)) && (0 >= pCurLayer->sLayerInfo.sSliceInLayer.iMbSkipRun)) { // slice boundary | 1889 | if ((iUsedBits == (pBs->iBits - 1)) && (0 >= pCurLayer->sLayerInfo.sSliceInLayer.iMbSkipRun)) { // slice boundary |
| 1890 | uiEosFlag = 1; | 1890 | uiEosFlag = 1; |
| 1891 | } | 1891 | } |
| 1892 | if (iUsedBits > (pBs->iBits - | 1892 | if (iUsedBits > (pBs->iBits - |
| 1893 | 1)) { //When BS incomplete, as long as find it, SHOULD stop decoding to avoid mosaic or crash. | 1893 | 1)) { //When BS incomplete, as long as find it, SHOULD stop decoding to avoid mosaic or crash. |
| 1894 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, | 1894 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, |
| 1895 | "WelsDecodeMbCavlcISlice()::::pBs incomplete, iUsedBits:%" PRId64 " > pBs->iBits:%d, MUST stop decoding.", | 1895 | "WelsDecodeMbCavlcISlice()::::pBs incomplete, iUsedBits:%" PRId64 " > pBs->iBits:%d, MUST stop decoding.", |
| 1896 | (int64_t) iUsedBits, pBs->iBits); | 1896 | (int64_t) iUsedBits, pBs->iBits); |
| 1897 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_BS_INCOMPLETE); | 1897 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_BS_INCOMPLETE); |
| 1898 | } | 1898 | } |
| 1899 | return ERR_NONE; | 1899 | return ERR_NONE; |
| 1900 | } | 1900 | } |
| 1901 | 1901 | ||
| 1902 | int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { | 1902 | int32_t WelsActualDecodeMbCavlcPSlice (PWelsDecoderContext pCtx) { |
| 1903 | SVlcTable* pVlcTable = &pCtx->sVlcTable; | 1903 | SVlcTable* pVlcTable = &pCtx->sVlcTable; |
| 1904 | PDqLayer pCurLayer = pCtx->pCurDqLayer; | 1904 | PDqLayer pCurLayer = pCtx->pCurDqLayer; |
| 1905 | PBitStringAux pBs = pCurLayer->pBitStringAux; | 1905 | PBitStringAux pBs = pCurLayer->pBitStringAux; |
| 1906 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; | 1906 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; |
| 1907 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | 1907 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; |
| 1908 | 1908 | ||
| 1909 | int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart; | 1909 | int32_t iScanIdxStart = pSlice->sSliceHeaderExt.uiScanIdxStart; |
| 1910 | int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd; | 1910 | int32_t iScanIdxEnd = pSlice->sSliceHeaderExt.uiScanIdxEnd; |
| 1911 | 1911 | ||
| 1912 | SWelsNeighAvail sNeighAvail; | 1912 | SWelsNeighAvail sNeighAvail; |
| 1913 | int32_t iMbX = pCurLayer->iMbX; | 1913 | int32_t iMbX = pCurLayer->iMbX; |
| 1914 | int32_t iMbY = pCurLayer->iMbY; | 1914 | int32_t iMbY = pCurLayer->iMbY; |
| 1915 | const int32_t iMbXy = pCurLayer->iMbXyIndex; | 1915 | const int32_t iMbXy = pCurLayer->iMbXyIndex; |
| 1916 | int8_t* pNzc = pCurLayer->pNzc[iMbXy]; | 1916 | int8_t* pNzc = pCurLayer->pNzc[iMbXy]; |
| 1917 | int32_t i; | 1917 | int32_t i; |
| 1918 | int32_t iRet = ERR_NONE; | 1918 | int32_t iRet = ERR_NONE; |
| 1919 | uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0; | 1919 | uint32_t uiMbType = 0, uiCbp = 0, uiCbpL = 0, uiCbpC = 0; |
| 1920 | uint32_t uiCode; | 1920 | uint32_t uiCode; |
| 1921 | int32_t iCode; | 1921 | int32_t iCode; |
| 1922 | int32_t iMbResProperty; | 1922 | int32_t iMbResProperty; |
| 1923 | 1923 | ||
| 1924 | GetNeighborAvailMbType (&sNeighAvail, pCurLayer); | 1924 | GetNeighborAvailMbType (&sNeighAvail, pCurLayer); |
| 1925 | ENFORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16); | 1925 | ENFORCE_STACK_ALIGN_1D (uint8_t, pNonZeroCount, 48, 16); |
| 1926 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;//2009.10.23 | 1926 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0;//2009.10.23 |
| 1927 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //uiMbType | 1927 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //uiMbType |
| 1928 | uiMbType = uiCode; | 1928 | uiMbType = uiCode; |
| 1929 | if (uiMbType < 5) { //inter MB type | 1929 | if (uiMbType < 5) { //inter MB type |
| 1930 | int16_t iMotionVector[LIST_A][30][MV_A]; | 1930 | int16_t iMotionVector[LIST_A][30][MV_A]; |
| 1931 | int8_t iRefIndex[LIST_A][30]; | 1931 | int8_t iRefIndex[LIST_A][30]; |
| 1932 | pCurLayer->pMbType[iMbXy] = g_ksInterPMbTypeInfo[uiMbType].iType; | 1932 | pCurLayer->pMbType[iMbXy] = g_ksInterPMbTypeInfo[uiMbType].iType; |
| 1933 | WelsFillCacheInter (&sNeighAvail, pNonZeroCount, iMotionVector, iRefIndex, pCurLayer); | 1933 | WelsFillCacheInter (&sNeighAvail, pNonZeroCount, iMotionVector, iRefIndex, pCurLayer); |
| 1934 | 1934 | ||
| 1935 | if ((iRet = ParseInterInfo (pCtx, iMotionVector, iRefIndex, pBs)) != ERR_NONE) { | 1935 | if ((iRet = ParseInterInfo (pCtx, iMotionVector, iRefIndex, pBs)) != ERR_NONE) { |
| 1936 | return iRet;//abnormal | 1936 | return iRet;//abnormal |
| 1937 | } | 1937 | } |
| 1938 | 1938 | ||
| 1939 | if (pSlice->sSliceHeaderExt.bAdaptiveResidualPredFlag == 1) { | 1939 | if (pSlice->sSliceHeaderExt.bAdaptiveResidualPredFlag == 1) { |
| 1940 | WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //residual_prediction_flag | 1940 | WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //residual_prediction_flag |
| 1941 | pCurLayer->pResidualPredFlag[iMbXy] = uiCode; | 1941 | pCurLayer->pResidualPredFlag[iMbXy] = uiCode; |
| 1942 | } else { | 1942 | } else { |
| 1943 | pCurLayer->pResidualPredFlag[iMbXy] = pSlice->sSliceHeaderExt.bDefaultResidualPredFlag; | 1943 | pCurLayer->pResidualPredFlag[iMbXy] = pSlice->sSliceHeaderExt.bDefaultResidualPredFlag; |
| 1944 | } | 1944 | } |
| 1945 | 1945 | ||
| 1946 | if (pCurLayer->pResidualPredFlag[iMbXy] == 0) { | 1946 | if (pCurLayer->pResidualPredFlag[iMbXy] == 0) { |
| 1947 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; | 1947 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; |
| 1948 | } else { | 1948 | } else { |
| 1949 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "residual_pred_flag = 1 not supported."); | 1949 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "residual_pred_flag = 1 not supported."); |
| 1950 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_UNSUPPORTED_ILP); | 1950 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_UNSUPPORTED_ILP); |
| 1951 | } | 1951 | } |
| 1952 | } else { //intra MB type | 1952 | } else { //intra MB type |
| 1953 | uiMbType -= 5; | 1953 | uiMbType -= 5; |
| 1954 | if (uiMbType > 25) | 1954 | if (uiMbType > 25) |
| 1955 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); | 1955 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); |
| 1956 | if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 && uiMbType <= 24))) | 1956 | if (!pCtx->pSps->uiChromaFormatIdc && ((uiMbType >= 5 && uiMbType <= 12) || (uiMbType >= 17 && uiMbType <= 24))) |
| 1957 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); | 1957 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_TYPE); |
| 1958 | 1958 | ||
| 1959 | if (25 == uiMbType) { | 1959 | if (25 == uiMbType) { |
| 1960 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "I_PCM mode exists in P slice!"); | 1960 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_DEBUG, "I_PCM mode exists in P slice!"); |
| 1961 | int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0]; | 1961 | int32_t iDecStrideL = pCurLayer->pDec->iLinesize[0]; |
| 1962 | int32_t iDecStrideC = pCurLayer->pDec->iLinesize[1]; | 1962 | int32_t iDecStrideC = pCurLayer->pDec->iLinesize[1]; |
| 1963 | 1963 | ||
| 1964 | int32_t iOffsetL = (iMbX + iMbY * iDecStrideL) << 4; | 1964 | int32_t iOffsetL = (iMbX + iMbY * iDecStrideL) << 4; |
| 1965 | int32_t iOffsetC = (iMbX + iMbY * iDecStrideC) << 3; | 1965 | int32_t iOffsetC = (iMbX + iMbY * iDecStrideC) << 3; |
| 1966 | 1966 | ||
| 1967 | uint8_t* pDecY = pCurLayer->pDec->pData[0] + iOffsetL; | 1967 | uint8_t* pDecY = pCurLayer->pDec->pData[0] + iOffsetL; |
| 1968 | uint8_t* pDecU = pCurLayer->pDec->pData[1] + iOffsetC; | 1968 | uint8_t* pDecU = pCurLayer->pDec->pData[1] + iOffsetC; |
| 1969 | uint8_t* pDecV = pCurLayer->pDec->pData[2] + iOffsetC; | 1969 | uint8_t* pDecV = pCurLayer->pDec->pData[2] + iOffsetC; |
| 1970 | 1970 | ||
| 1971 | uint8_t* pTmpBsBuf; | 1971 | uint8_t* pTmpBsBuf; |
| 1972 | 1972 | ||
| 1973 | int32_t i; | 1973 | int32_t i; |
| 1974 | int32_t iCopySizeY = (sizeof (uint8_t) << 4); | 1974 | int32_t iCopySizeY = (sizeof (uint8_t) << 4); |
| 1975 | int32_t iCopySizeUV = (sizeof (uint8_t) << 3); | 1975 | int32_t iCopySizeUV = (sizeof (uint8_t) << 3); |
| 1976 | 1976 | ||
| 1977 | int32_t iIndex = ((-pBs->iLeftBits) >> 3) + 2; | 1977 | int32_t iIndex = ((-pBs->iLeftBits) >> 3) + 2; |
| 1978 | 1978 | ||
| 1979 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA_PCM; | 1979 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA_PCM; |
| 1980 | 1980 | ||
| 1981 | //step 1: locating bit-stream pointer [must align into integer byte] | 1981 | //step 1: locating bit-stream pointer [must align into integer byte] |
| 1982 | pBs->pCurBuf -= iIndex; | 1982 | pBs->pCurBuf -= iIndex; |
| 1983 | 1983 | ||
| 1984 | //step 2: copy pixel from bit-stream into fdec [reconstruction] | 1984 | //step 2: copy pixel from bit-stream into fdec [reconstruction] |
| 1985 | pTmpBsBuf = pBs->pCurBuf; | 1985 | pTmpBsBuf = pBs->pCurBuf; |
| 1986 | if (!pCtx->pParam->bParseOnly) { | 1986 | if (!pCtx->pParam->bParseOnly) { |
| 1987 | for (i = 0; i < 16; i++) { //luma | 1987 | for (i = 0; i < 16; i++) { //luma |
| 1988 | memcpy (pDecY, pTmpBsBuf, iCopySizeY); | 1988 | memcpy (pDecY, pTmpBsBuf, iCopySizeY); |
| 1989 | pDecY += iDecStrideL; | 1989 | pDecY += iDecStrideL; |
| 1990 | pTmpBsBuf += 16; | 1990 | pTmpBsBuf += 16; |
| 1991 | } | 1991 | } |
| 1992 | 1992 | ||
| 1993 | for (i = 0; i < 8; i++) { //cb | 1993 | for (i = 0; i < 8; i++) { //cb |
| 1994 | memcpy (pDecU, pTmpBsBuf, iCopySizeUV); | 1994 | memcpy (pDecU, pTmpBsBuf, iCopySizeUV); |
| 1995 | pDecU += iDecStrideC; | 1995 | pDecU += iDecStrideC; |
| 1996 | pTmpBsBuf += 8; | 1996 | pTmpBsBuf += 8; |
| 1997 | } | 1997 | } |
| 1998 | for (i = 0; i < 8; i++) { //cr | 1998 | for (i = 0; i < 8; i++) { //cr |
| 1999 | memcpy (pDecV, pTmpBsBuf, iCopySizeUV); | 1999 | memcpy (pDecV, pTmpBsBuf, iCopySizeUV); |
| 2000 | pDecV += iDecStrideC; | 2000 | pDecV += iDecStrideC; |
| 2001 | pTmpBsBuf += 8; | 2001 | pTmpBsBuf += 8; |
| 2002 | } | 2002 | } |
| 2003 | } | 2003 | } |
| 2004 | 2004 | ||
| 2005 | pBs->pCurBuf += 384; | 2005 | pBs->pCurBuf += 384; |
| 2006 | 2006 | ||
| 2007 | //step 3: update QP and pNonZeroCount | 2007 | //step 3: update QP and pNonZeroCount |
| 2008 | pCurLayer->pLumaQp[iMbXy] = 0; | 2008 | pCurLayer->pLumaQp[iMbXy] = 0; |
| 2009 | pCurLayer->pChromaQp[iMbXy][0] = pCurLayer->pChromaQp[iMbXy][1] = 0; | 2009 | pCurLayer->pChromaQp[iMbXy][0] = pCurLayer->pChromaQp[iMbXy][1] = 0; |
| 2010 | //Rec. 9.2.1 for PCM, nzc=16 | 2010 | //Rec. 9.2.1 for PCM, nzc=16 |
| 2011 | ST32A4 (&pNzc[0], 0x10101010); | 2011 | ST32A4 (&pNzc[0], 0x10101010); |
| 2012 | ST32A4 (&pNzc[4], 0x10101010); | 2012 | ST32A4 (&pNzc[4], 0x10101010); |
| 2013 | ST32A4 (&pNzc[8], 0x10101010); | 2013 | ST32A4 (&pNzc[8], 0x10101010); |
| 2014 | ST32A4 (&pNzc[12], 0x10101010); | 2014 | ST32A4 (&pNzc[12], 0x10101010); |
| 2015 | ST32A4 (&pNzc[16], 0x10101010); | 2015 | ST32A4 (&pNzc[16], 0x10101010); |
| 2016 | ST32A4 (&pNzc[20], 0x10101010); | 2016 | ST32A4 (&pNzc[20], 0x10101010); |
| 2017 | WELS_READ_VERIFY (InitReadBits (pBs, 0)); | 2017 | WELS_READ_VERIFY (InitReadBits (pBs, 0)); |
| 2018 | return ERR_NONE; | 2018 | return ERR_NONE; |
| 2019 | } else { | 2019 | } else { |
| 2020 | if (0 == uiMbType) { | 2020 | if (0 == uiMbType) { |
| 2021 | ENFORCE_STACK_ALIGN_1D (int8_t, pIntraPredMode, 48, 16); | 2021 | ENFORCE_STACK_ALIGN_1D (int8_t, pIntraPredMode, 48, 16); |
| 2022 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA4x4; | 2022 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA4x4; |
| 2023 | if (pCtx->pPps->bTransform8x8ModeFlag) { | 2023 | if (pCtx->pPps->bTransform8x8ModeFlag) { |
| 2024 | WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //transform_size_8x8_flag | 2024 | WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //transform_size_8x8_flag |
| 2025 | pCurLayer->pTransformSize8x8Flag[iMbXy] = !!uiCode; | 2025 | pCurLayer->pTransformSize8x8Flag[iMbXy] = !!uiCode; |
| 2026 | if (pCurLayer->pTransformSize8x8Flag[iMbXy]) { | 2026 | if (pCurLayer->pTransformSize8x8Flag[iMbXy]) { |
| 2027 | uiMbType = pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA8x8; | 2027 | uiMbType = pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA8x8; |
| 2028 | } | 2028 | } |
| 2029 | } | 2029 | } |
| 2030 | if (!pCurLayer->pTransformSize8x8Flag[iMbXy]) { | 2030 | if (!pCurLayer->pTransformSize8x8Flag[iMbXy]) { |
| 2031 | pCtx->pFillInfoCacheIntraNxNFunc (&sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); | 2031 | pCtx->pFillInfoCacheIntraNxNFunc (&sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); |
| 2032 | WELS_READ_VERIFY (ParseIntra4x4Mode (pCtx, &sNeighAvail, pIntraPredMode, pBs, pCurLayer)); | 2032 | WELS_READ_VERIFY (ParseIntra4x4Mode (pCtx, &sNeighAvail, pIntraPredMode, pBs, pCurLayer)); |
| 2033 | } else { | 2033 | } else { |
| 2034 | pCtx->pFillInfoCacheIntraNxNFunc (&sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); | 2034 | pCtx->pFillInfoCacheIntraNxNFunc (&sNeighAvail, pNonZeroCount, pIntraPredMode, pCurLayer); |
| 2035 | WELS_READ_VERIFY (ParseIntra8x8Mode (pCtx, &sNeighAvail, pIntraPredMode, pBs, pCurLayer)); | 2035 | WELS_READ_VERIFY (ParseIntra8x8Mode (pCtx, &sNeighAvail, pIntraPredMode, pBs, pCurLayer)); |
| 2036 | } | 2036 | } |
| 2037 | } else { //I_PCM exclude, we can ignore it | 2037 | } else { //I_PCM exclude, we can ignore it |
| 2038 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16; | 2038 | pCurLayer->pMbType[iMbXy] = MB_TYPE_INTRA16x16; |
| 2039 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; | 2039 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; |
| 2040 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; | 2040 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; |
| 2041 | pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3; | 2041 | pCurLayer->pIntraPredMode[iMbXy][7] = (uiMbType - 1) & 3; |
| 2042 | pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2]; | 2042 | pCurLayer->pCbp[iMbXy] = g_kuiI16CbpTable[ (uiMbType - 1) >> 2]; |
| 2043 | uiCbpC = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0; | 2043 | uiCbpC = pCtx->pSps->uiChromaFormatIdc ? pCurLayer->pCbp[iMbXy] >> 4 : 0; |
| 2044 | uiCbpL = pCurLayer->pCbp[iMbXy] & 15; | 2044 | uiCbpL = pCurLayer->pCbp[iMbXy] & 15; |
| 2045 | WelsFillCacheNonZeroCount (&sNeighAvail, pNonZeroCount, pCurLayer); | 2045 | WelsFillCacheNonZeroCount (&sNeighAvail, pNonZeroCount, pCurLayer); |
| 2046 | if ((iRet = ParseIntra16x16Mode (pCtx, &sNeighAvail, pBs, pCurLayer)) != ERR_NONE) { | 2046 | if ((iRet = ParseIntra16x16Mode (pCtx, &sNeighAvail, pBs, pCurLayer)) != ERR_NONE) { |
| 2047 | return iRet; | 2047 | return iRet; |
| 2048 | } | 2048 | } |
| 2049 | } | 2049 | } |
| 2050 | } | 2050 | } |
| 2051 | } | 2051 | } |
| 2052 | 2052 | ||
| 2053 | if (MB_TYPE_INTRA16x16 != pCurLayer->pMbType[iMbXy]) { | 2053 | if (MB_TYPE_INTRA16x16 != pCurLayer->pMbType[iMbXy]) { |
| 2054 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //coded_block_pattern | 2054 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //coded_block_pattern |
| 2055 | uiCbp = uiCode; | 2055 | uiCbp = uiCode; |
| 2056 | { | 2056 | { |
| 2057 | if (pCtx->pSps->uiChromaFormatIdc && (uiCbp > 47)) | 2057 | if (pCtx->pSps->uiChromaFormatIdc && (uiCbp > 47)) |
| 2058 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_CBP); | 2058 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_CBP); |
| 2059 | if (!pCtx->pSps->uiChromaFormatIdc && (uiCbp > 15)) | 2059 | if (!pCtx->pSps->uiChromaFormatIdc && (uiCbp > 15)) |
| 2060 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_CBP); | 2060 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_CBP); |
| 2061 | if (MB_TYPE_INTRA4x4 == pCurLayer->pMbType[iMbXy] || MB_TYPE_INTRA8x8 == pCurLayer->pMbType[iMbXy]) { | 2061 | if (MB_TYPE_INTRA4x4 == pCurLayer->pMbType[iMbXy] || MB_TYPE_INTRA8x8 == pCurLayer->pMbType[iMbXy]) { |
| 2062 | 2062 | ||
| 2063 | uiCbp = pCtx->pSps->uiChromaFormatIdc ? g_kuiIntra4x4CbpTable[uiCbp] : g_kuiIntra4x4CbpTable400[uiCbp]; | 2063 | uiCbp = pCtx->pSps->uiChromaFormatIdc ? g_kuiIntra4x4CbpTable[uiCbp] : g_kuiIntra4x4CbpTable400[uiCbp]; |
| 2064 | } else //inter | 2064 | } else //inter |
| 2065 | uiCbp = pCtx->pSps->uiChromaFormatIdc ? g_kuiInterCbpTable[uiCbp] : g_kuiInterCbpTable400[uiCbp]; | 2065 | uiCbp = pCtx->pSps->uiChromaFormatIdc ? g_kuiInterCbpTable[uiCbp] : g_kuiInterCbpTable400[uiCbp]; |
| 2066 | } | 2066 | } |
| 2067 | 2067 | ||
| 2068 | pCurLayer->pCbp[iMbXy] = uiCbp; | 2068 | pCurLayer->pCbp[iMbXy] = uiCbp; |
| 2069 | uiCbpC = pCurLayer->pCbp[iMbXy] >> 4; | 2069 | uiCbpC = pCurLayer->pCbp[iMbXy] >> 4; |
| 2070 | uiCbpL = pCurLayer->pCbp[iMbXy] & 15; | 2070 | uiCbpL = pCurLayer->pCbp[iMbXy] & 15; |
| 2071 | 2071 | ||
| 2072 | // Need modification when B picutre add in | 2072 | // Need modification when B picutre add in |
| 2073 | bool bNeedParseTransformSize8x8Flag = | 2073 | bool bNeedParseTransformSize8x8Flag = |
| 2074 | (((pCurLayer->pMbType[iMbXy] >= MB_TYPE_16x16 && pCurLayer->pMbType[iMbXy] <= MB_TYPE_8x16) | 2074 | (((pCurLayer->pMbType[iMbXy] >= MB_TYPE_16x16 && pCurLayer->pMbType[iMbXy] <= MB_TYPE_8x16) |
| 2075 | || pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy]) | 2075 | || pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy]) |
| 2076 | && (pCurLayer->pMbType[iMbXy] != MB_TYPE_INTRA8x8) | 2076 | && (pCurLayer->pMbType[iMbXy] != MB_TYPE_INTRA8x8) |
| 2077 | && (pCurLayer->pMbType[iMbXy] != MB_TYPE_INTRA4x4) | 2077 | && (pCurLayer->pMbType[iMbXy] != MB_TYPE_INTRA4x4) |
| 2078 | && (uiCbpL > 0) | 2078 | && (uiCbpL > 0) |
| 2079 | && (pCtx->pPps->bTransform8x8ModeFlag)); | 2079 | && (pCtx->pPps->bTransform8x8ModeFlag)); |
| 2080 | 2080 | ||
| 2081 | if (bNeedParseTransformSize8x8Flag) { | 2081 | if (bNeedParseTransformSize8x8Flag) { |
| 2082 | WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //transform_size_8x8_flag | 2082 | WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //transform_size_8x8_flag |
| 2083 | pCurLayer->pTransformSize8x8Flag[iMbXy] = !!uiCode; | 2083 | pCurLayer->pTransformSize8x8Flag[iMbXy] = !!uiCode; |
| 2084 | } | 2084 | } |
| 2085 | } | 2085 | } |
| 2086 | 2086 | ||
| 2087 | ST32A4 (&pNzc[0], 0); | 2087 | ST32A4 (&pNzc[0], 0); |
| 2088 | ST32A4 (&pNzc[4], 0); | 2088 | ST32A4 (&pNzc[4], 0); |
| 2089 | ST32A4 (&pNzc[8], 0); | 2089 | ST32A4 (&pNzc[8], 0); |
| 2090 | ST32A4 (&pNzc[12], 0); | 2090 | ST32A4 (&pNzc[12], 0); |
| 2091 | ST32A4 (&pNzc[16], 0); | 2091 | ST32A4 (&pNzc[16], 0); |
| 2092 | ST32A4 (&pNzc[20], 0); | 2092 | ST32A4 (&pNzc[20], 0); |
| 2093 | if (pCurLayer->pCbp[iMbXy] == 0 && !IS_INTRA16x16 (pCurLayer->pMbType[iMbXy]) && !IS_I_BL (pCurLayer->pMbType[iMbXy])) { | 2093 | if (pCurLayer->pCbp[iMbXy] == 0 && !IS_INTRA16x16 (pCurLayer->pMbType[iMbXy]) && !IS_I_BL (pCurLayer->pMbType[iMbXy])) { |
| 2094 | pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; | 2094 | pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; |
| 2095 | for (i = 0; i < 2; i++) { | 2095 | for (i = 0; i < 2; i++) { |
| 2096 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pCurLayer->pLumaQp[iMbXy] + | 2096 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pCurLayer->pLumaQp[iMbXy] + |
| 2097 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; | 2097 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; |
| 2098 | } | 2098 | } |
| 2099 | } | 2099 | } |
| 2100 | 2100 | ||
| 2101 | if (pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { | 2101 | if (pCurLayer->pCbp[iMbXy] || MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { |
| 2102 | int32_t iQpDelta, iId8x8, iId4x4; | 2102 | int32_t iQpDelta, iId8x8, iId4x4; |
| 2103 | memset (pCurLayer->pScaledTCoeff[iMbXy], 0, MB_COEFF_LIST_SIZE * sizeof (int16_t)); | 2103 | memset (pCurLayer->pScaledTCoeff[iMbXy], 0, MB_COEFF_LIST_SIZE * sizeof (int16_t)); |
| 2104 | WELS_READ_VERIFY (BsGetSe (pBs, &iCode)); //mb_qp_delta | 2104 | WELS_READ_VERIFY (BsGetSe (pBs, &iCode)); //mb_qp_delta |
| 2105 | iQpDelta = iCode; | 2105 | iQpDelta = iCode; |
| 2106 | 2106 | ||
| 2107 | if (iQpDelta > 25 || iQpDelta < -26) { //out of iQpDelta range | 2107 | if (iQpDelta > 25 || iQpDelta < -26) { //out of iQpDelta range |
| 2108 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_QP); | 2108 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_QP); |
| 2109 | } | 2109 | } |
| 2110 | 2110 | ||
| 2111 | pCurLayer->pLumaQp[iMbXy] = (pSlice->iLastMbQp + iQpDelta + 52) % 52; //update last_mb_qp | 2111 | pCurLayer->pLumaQp[iMbXy] = (pSlice->iLastMbQp + iQpDelta + 52) % 52; //update last_mb_qp |
| 2112 | pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy]; | 2112 | pSlice->iLastMbQp = pCurLayer->pLumaQp[iMbXy]; |
| 2113 | for (i = 0; i < 2; i++) { | 2113 | for (i = 0; i < 2; i++) { |
| 2114 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pSlice->iLastMbQp + | 2114 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pSlice->iLastMbQp + |
| 2115 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, | 2115 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, |
| 2116 | 51)]; | 2116 | 51)]; |
| 2117 | } | 2117 | } |
| 2118 | 2118 | ||
| 2119 | BsStartCavlc (pBs); | 2119 | BsStartCavlc (pBs); |
| 2120 | 2120 | ||
| 2121 | if (MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { | 2121 | if (MB_TYPE_INTRA16x16 == pCurLayer->pMbType[iMbXy]) { |
| 2122 | //step1: Luma DC | 2122 | //step1: Luma DC |
| 2123 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, 0, 16, g_kuiLumaDcZigzagScan, I16_LUMA_DC, | 2123 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, 0, 16, g_kuiLumaDcZigzagScan, I16_LUMA_DC, |
| 2124 | pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) { | 2124 | pCurLayer->pScaledTCoeff[iMbXy], pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) { |
| 2125 | return iRet;//abnormal | 2125 | return iRet;//abnormal |
| 2126 | } | 2126 | } |
| 2127 | //step2: Luma AC | 2127 | //step2: Luma AC |
| 2128 | if (uiCbpL) { | 2128 | if (uiCbpL) { |
| 2129 | for (i = 0; i < 16; i++) { | 2129 | for (i = 0; i < 16; i++) { |
| 2130 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, i, iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, | 2130 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, i, iScanIdxEnd - WELS_MAX (iScanIdxStart, 1) + 1, |
| 2131 | g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i << 4), | 2131 | g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), I16_LUMA_AC, pCurLayer->pScaledTCoeff[iMbXy] + (i << 4), |
| 2132 | pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) { | 2132 | pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) { |
| 2133 | return iRet;//abnormal | 2133 | return iRet;//abnormal |
| 2134 | } | 2134 | } |
| 2135 | } | 2135 | } |
| 2136 | ST32A4 (&pNzc[0], LD32 (&pNonZeroCount[1 + 8 * 1])); | 2136 | ST32A4 (&pNzc[0], LD32 (&pNonZeroCount[1 + 8 * 1])); |
| 2137 | ST32A4 (&pNzc[4], LD32 (&pNonZeroCount[1 + 8 * 2])); | 2137 | ST32A4 (&pNzc[4], LD32 (&pNonZeroCount[1 + 8 * 2])); |
| 2138 | ST32A4 (&pNzc[8], LD32 (&pNonZeroCount[1 + 8 * 3])); | 2138 | ST32A4 (&pNzc[8], LD32 (&pNonZeroCount[1 + 8 * 3])); |
| 2139 | ST32A4 (&pNzc[12], LD32 (&pNonZeroCount[1 + 8 * 4])); | 2139 | ST32A4 (&pNzc[12], LD32 (&pNonZeroCount[1 + 8 * 4])); |
| 2140 | } | 2140 | } |
| 2141 | } else { //non-MB_TYPE_INTRA16x16 | 2141 | } else { //non-MB_TYPE_INTRA16x16 |
| 2142 | if (pCurLayer->pTransformSize8x8Flag[iMbXy]) { | 2142 | if (pCurLayer->pTransformSize8x8Flag[iMbXy]) { |
| 2143 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { | 2143 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { |
| 2144 | iMbResProperty = (IS_INTRA (pCurLayer->pMbType[iMbXy])) ? LUMA_DC_AC_INTRA_8 : LUMA_DC_AC_INTER_8; | 2144 | iMbResProperty = (IS_INTRA (pCurLayer->pMbType[iMbXy])) ? LUMA_DC_AC_INTRA_8 : LUMA_DC_AC_INTER_8; |
| 2145 | if (uiCbpL & (1 << iId8x8)) { | 2145 | if (uiCbpL & (1 << iId8x8)) { |
| 2146 | int32_t iIndex = (iId8x8 << 2); | 2146 | int32_t iIndex = (iId8x8 << 2); |
| 2147 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { | 2147 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 2148 | if ((iRet = WelsResidualBlockCavlc8x8 (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - iScanIdxStart + 1, | 2148 | if ((iRet = WelsResidualBlockCavlc8x8 (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - iScanIdxStart + 1, |
| 2149 | g_kuiZigzagScan8x8 + iScanIdxStart, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iId8x8 << 6), iId4x4, | 2149 | g_kuiZigzagScan8x8 + iScanIdxStart, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iId8x8 << 6), iId4x4, |
| 2150 | pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) { | 2150 | pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) { |
| 2151 | return iRet; | 2151 | return iRet; |
| 2152 | } | 2152 | } |
| 2153 | iIndex++; | 2153 | iIndex++; |
| 2154 | } | 2154 | } |
| 2155 | } else { | 2155 | } else { |
| 2156 | ST16 (&pNonZeroCount[g_kuiCache48CountScan4Idx[iId8x8 << 2]], 0); | 2156 | ST16 (&pNonZeroCount[g_kuiCache48CountScan4Idx[iId8x8 << 2]], 0); |
| 2157 | ST16 (&pNonZeroCount[g_kuiCache48CountScan4Idx[ (iId8x8 << 2) + 2]], 0); | 2157 | ST16 (&pNonZeroCount[g_kuiCache48CountScan4Idx[ (iId8x8 << 2) + 2]], 0); |
| 2158 | } | 2158 | } |
| 2159 | } | 2159 | } |
| 2160 | ST32A4 (&pNzc[0], LD32 (&pNonZeroCount[1 + 8 * 1])); | 2160 | ST32A4 (&pNzc[0], LD32 (&pNonZeroCount[1 + 8 * 1])); |
| 2161 | ST32A4 (&pNzc[4], LD32 (&pNonZeroCount[1 + 8 * 2])); | 2161 | ST32A4 (&pNzc[4], LD32 (&pNonZeroCount[1 + 8 * 2])); |
| 2162 | ST32A4 (&pNzc[8], LD32 (&pNonZeroCount[1 + 8 * 3])); | 2162 | ST32A4 (&pNzc[8], LD32 (&pNonZeroCount[1 + 8 * 3])); |
| 2163 | ST32A4 (&pNzc[12], LD32 (&pNonZeroCount[1 + 8 * 4])); | 2163 | ST32A4 (&pNzc[12], LD32 (&pNonZeroCount[1 + 8 * 4])); |
| 2164 | } else { // Normal T4x4 | 2164 | } else { // Normal T4x4 |
| 2165 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { | 2165 | for (iId8x8 = 0; iId8x8 < 4; iId8x8++) { |
| 2166 | iMbResProperty = (IS_INTRA (pCurLayer->pMbType[iMbXy])) ? LUMA_DC_AC_INTRA : LUMA_DC_AC_INTER; | 2166 | iMbResProperty = (IS_INTRA (pCurLayer->pMbType[iMbXy])) ? LUMA_DC_AC_INTRA : LUMA_DC_AC_INTER; |
| 2167 | if (uiCbpL & (1 << iId8x8)) { | 2167 | if (uiCbpL & (1 << iId8x8)) { |
| 2168 | int32_t iIndex = (iId8x8 << 2); | 2168 | int32_t iIndex = (iId8x8 << 2); |
| 2169 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { | 2169 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 2170 | //Luma (DC and AC decoding together) | 2170 | //Luma (DC and AC decoding together) |
| 2171 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - iScanIdxStart + 1, | 2171 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - iScanIdxStart + 1, |
| 2172 | g_kuiZigzagScan + iScanIdxStart, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), | 2172 | g_kuiZigzagScan + iScanIdxStart, iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), |
| 2173 | pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) { | 2173 | pCurLayer->pLumaQp[iMbXy], pCtx)) != ERR_NONE) { |
| 2174 | return iRet;//abnormal | 2174 | return iRet;//abnormal |
| 2175 | } | 2175 | } |
| 2176 | iIndex++; | 2176 | iIndex++; |
| 2177 | } | 2177 | } |
| 2178 | } else { | 2178 | } else { |
| 2179 | ST16 (&pNonZeroCount[g_kuiCache48CountScan4Idx[iId8x8 << 2]], 0); | 2179 | ST16 (&pNonZeroCount[g_kuiCache48CountScan4Idx[iId8x8 << 2]], 0); |
| 2180 | ST16 (&pNonZeroCount[g_kuiCache48CountScan4Idx[ (iId8x8 << 2) + 2]], 0); | 2180 | ST16 (&pNonZeroCount[g_kuiCache48CountScan4Idx[ (iId8x8 << 2) + 2]], 0); |
| 2181 | } | 2181 | } |
| 2182 | } | 2182 | } |
| 2183 | ST32A4 (&pNzc[0], LD32 (&pNonZeroCount[1 + 8 * 1])); | 2183 | ST32A4 (&pNzc[0], LD32 (&pNonZeroCount[1 + 8 * 1])); |
| 2184 | ST32A4 (&pNzc[4], LD32 (&pNonZeroCount[1 + 8 * 2])); | 2184 | ST32A4 (&pNzc[4], LD32 (&pNonZeroCount[1 + 8 * 2])); |
| 2185 | ST32A4 (&pNzc[8], LD32 (&pNonZeroCount[1 + 8 * 3])); | 2185 | ST32A4 (&pNzc[8], LD32 (&pNonZeroCount[1 + 8 * 3])); |
| 2186 | ST32A4 (&pNzc[12], LD32 (&pNonZeroCount[1 + 8 * 4])); | 2186 | ST32A4 (&pNzc[12], LD32 (&pNonZeroCount[1 + 8 * 4])); |
| 2187 | } | 2187 | } |
| 2188 | } | 2188 | } |
| 2189 | 2189 | ||
| 2190 | 2190 | ||
| 2191 | //chroma | 2191 | //chroma |
| 2192 | //step1: DC | 2192 | //step1: DC |
| 2193 | if (1 == uiCbpC || 2 == uiCbpC) { | 2193 | if (1 == uiCbpC || 2 == uiCbpC) { |
| 2194 | for (i = 0; i < 2; i++) { //Cb Cr | 2194 | for (i = 0; i < 2; i++) { //Cb Cr |
| 2195 | if (IS_INTRA (pCurLayer->pMbType[iMbXy])) | 2195 | if (IS_INTRA (pCurLayer->pMbType[iMbXy])) |
| 2196 | iMbResProperty = i ? CHROMA_DC_V : CHROMA_DC_U; | 2196 | iMbResProperty = i ? CHROMA_DC_V : CHROMA_DC_U; |
| 2197 | else | 2197 | else |
| 2198 | iMbResProperty = i ? CHROMA_DC_V_INTER : CHROMA_DC_U_INTER; | 2198 | iMbResProperty = i ? CHROMA_DC_V_INTER : CHROMA_DC_U_INTER; |
| 2199 | 2199 | ||
| 2200 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, 16 + (i << 2), 4, g_kuiChromaDcScan, iMbResProperty, | 2200 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, 16 + (i << 2), 4, g_kuiChromaDcScan, iMbResProperty, |
| 2201 | pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6), pCurLayer->pChromaQp[iMbXy][i], pCtx)) != ERR_NONE) { | 2201 | pCurLayer->pScaledTCoeff[iMbXy] + 256 + (i << 6), pCurLayer->pChromaQp[iMbXy][i], pCtx)) != ERR_NONE) { |
| 2202 | return iRet;//abnormal | 2202 | return iRet;//abnormal |
| 2203 | } | 2203 | } |
| 2204 | } | 2204 | } |
| 2205 | } else { | 2205 | } else { |
| 2206 | } | 2206 | } |
| 2207 | //step2: AC | 2207 | //step2: AC |
| 2208 | if (2 == uiCbpC) { | 2208 | if (2 == uiCbpC) { |
| 2209 | for (i = 0; i < 2; i++) { //Cb Cr | 2209 | for (i = 0; i < 2; i++) { //Cb Cr |
| 2210 | if (IS_INTRA (pCurLayer->pMbType[iMbXy])) | 2210 | if (IS_INTRA (pCurLayer->pMbType[iMbXy])) |
| 2211 | iMbResProperty = i ? CHROMA_AC_V : CHROMA_AC_U; | 2211 | iMbResProperty = i ? CHROMA_AC_V : CHROMA_AC_U; |
| 2212 | else | 2212 | else |
| 2213 | iMbResProperty = i ? CHROMA_AC_V_INTER : CHROMA_AC_U_INTER; | 2213 | iMbResProperty = i ? CHROMA_AC_V_INTER : CHROMA_AC_U_INTER; |
| 2214 | 2214 | ||
| 2215 | int32_t iIndex = 16 + (i << 2); | 2215 | int32_t iIndex = 16 + (i << 2); |
| 2216 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { | 2216 | for (iId4x4 = 0; iId4x4 < 4; iId4x4++) { |
| 2217 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - WELS_MAX (iScanIdxStart, | 2217 | if ((iRet = WelsResidualBlockCavlc (pVlcTable, pNonZeroCount, pBs, iIndex, iScanIdxEnd - WELS_MAX (iScanIdxStart, |
| 2218 | 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), | 2218 | 1) + 1, g_kuiZigzagScan + WELS_MAX (iScanIdxStart, 1), iMbResProperty, pCurLayer->pScaledTCoeff[iMbXy] + (iIndex << 4), |
| 2219 | pCurLayer->pChromaQp[iMbXy][i], pCtx)) != ERR_NONE) { | 2219 | pCurLayer->pChromaQp[iMbXy][i], pCtx)) != ERR_NONE) { |
| 2220 | return iRet;//abnormal | 2220 | return iRet;//abnormal |
| 2221 | } | 2221 | } |
| 2222 | iIndex++; | 2222 | iIndex++; |
| 2223 | } | 2223 | } |
| 2224 | } | 2224 | } |
| 2225 | ST16A2 (&pNzc[16], LD16A2 (&pNonZeroCount[6 + 8 * 1])); | 2225 | ST16A2 (&pNzc[16], LD16A2 (&pNonZeroCount[6 + 8 * 1])); |
| 2226 | ST16A2 (&pNzc[20], LD16A2 (&pNonZeroCount[6 + 8 * 2])); | 2226 | ST16A2 (&pNzc[20], LD16A2 (&pNonZeroCount[6 + 8 * 2])); |
| 2227 | ST16A2 (&pNzc[18], LD16A2 (&pNonZeroCount[6 + 8 * 4])); | 2227 | ST16A2 (&pNzc[18], LD16A2 (&pNonZeroCount[6 + 8 * 4])); |
| 2228 | ST16A2 (&pNzc[22], LD16A2 (&pNonZeroCount[6 + 8 * 5])); | 2228 | ST16A2 (&pNzc[22], LD16A2 (&pNonZeroCount[6 + 8 * 5])); |
| 2229 | } | 2229 | } |
| 2230 | BsEndCavlc (pBs); | 2230 | BsEndCavlc (pBs); |
| 2231 | } | 2231 | } |
| 2232 | 2232 | ||
| 2233 | return ERR_NONE; | 2233 | return ERR_NONE; |
| 2234 | } | 2234 | } |
| 2235 | 2235 | ||
| 2236 | int32_t WelsDecodeMbCavlcPSlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uint32_t& uiEosFlag) { | 2236 | int32_t WelsDecodeMbCavlcPSlice (PWelsDecoderContext pCtx, PNalUnit pNalCur, uint32_t& uiEosFlag) { |
| 2237 | PDqLayer pCurLayer = pCtx->pCurDqLayer; | 2237 | PDqLayer pCurLayer = pCtx->pCurDqLayer; |
| 2238 | PBitStringAux pBs = pCurLayer->pBitStringAux; | 2238 | PBitStringAux pBs = pCurLayer->pBitStringAux; |
| 2239 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; | 2239 | PSlice pSlice = &pCurLayer->sLayerInfo.sSliceInLayer; |
| 2240 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; | 2240 | PSliceHeader pSliceHeader = &pSlice->sSliceHeaderExt.sSliceHeader; |
| 2241 | PPicture* ppRefPic = pCtx->sRefPic.pRefList[LIST_0]; | 2241 | PPicture* ppRefPic = pCtx->sRefPic.pRefList[LIST_0]; |
| 2242 | intX_t iUsedBits; | 2242 | intX_t iUsedBits; |
| 2243 | const int32_t iMbXy = pCurLayer->iMbXyIndex; | 2243 | const int32_t iMbXy = pCurLayer->iMbXyIndex; |
| 2244 | int8_t* pNzc = pCurLayer->pNzc[iMbXy]; | 2244 | int8_t* pNzc = pCurLayer->pNzc[iMbXy]; |
| 2245 | int32_t iBaseModeFlag, i; | 2245 | int32_t iBaseModeFlag, i; |
| 2246 | int32_t iRet = 0; //should have the return value to indicate decoding error or not, It's NECESSARY--2010.4.15 | 2246 | int32_t iRet = 0; //should have the return value to indicate decoding error or not, It's NECESSARY--2010.4.15 |
| 2247 | uint32_t uiCode; | 2247 | uint32_t uiCode; |
| 2248 | 2248 | ||
| 2249 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; | 2249 | pCurLayer->pNoSubMbPartSizeLessThan8x8Flag[iMbXy] = true; |
| 2250 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; | 2250 | pCurLayer->pTransformSize8x8Flag[iMbXy] = false; |
| 2251 | 2251 | ||
| 2252 | if (-1 == pSlice->iMbSkipRun) { | 2252 | if (-1 == pSlice->iMbSkipRun) { |
| 2253 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //mb_skip_run | 2253 | WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //mb_skip_run |
| 2254 | pSlice->iMbSkipRun = uiCode; | 2254 | pSlice->iMbSkipRun = uiCode; |
| 2255 | if (-1 == pSlice->iMbSkipRun) { | 2255 | if (-1 == pSlice->iMbSkipRun) { |
| 2256 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_SKIP_RUN); | 2256 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_INVALID_MB_SKIP_RUN); |
| 2257 | } | 2257 | } |
| 2258 | } | 2258 | } |
| 2259 | if (pSlice->iMbSkipRun--) { | 2259 | if (pSlice->iMbSkipRun--) { |
| 2260 | int16_t iMv[2]; | 2260 | int16_t iMv[2]; |
| 2261 | 2261 | ||
| 2262 | pCurLayer->pMbType[iMbXy] = MB_TYPE_SKIP; | 2262 | pCurLayer->pMbType[iMbXy] = MB_TYPE_SKIP; |
| 2263 | ST32A4 (&pNzc[0], 0); | 2263 | ST32A4 (&pNzc[0], 0); |
| 2264 | ST32A4 (&pNzc[4], 0); | 2264 | ST32A4 (&pNzc[4], 0); |
| 2265 | ST32A4 (&pNzc[8], 0); | 2265 | ST32A4 (&pNzc[8], 0); |
| 2266 | ST32A4 (&pNzc[12], 0); | 2266 | ST32A4 (&pNzc[12], 0); |
| 2267 | ST32A4 (&pNzc[16], 0); | 2267 | ST32A4 (&pNzc[16], 0); |
| 2268 | ST32A4 (&pNzc[20], 0); | 2268 | ST32A4 (&pNzc[20], 0); |
| 2269 | 2269 | ||
| 2270 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; | 2270 | pCurLayer->pInterPredictionDoneFlag[iMbXy] = 0; |
| 2271 | memset (pCurLayer->pRefIndex[0][iMbXy], 0, sizeof (int8_t) * 16); | 2271 | memset (pCurLayer->pRefIndex[0][iMbXy], 0, sizeof (int8_t) * 16); |
| 2272 | pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[0] && ppRefPic[0]->bIsComplete); | 2272 | pCtx->bMbRefConcealed = pCtx->bRPLRError || pCtx->bMbRefConcealed || ! (ppRefPic[0] && ppRefPic[0]->bIsComplete); |
| 2273 | //predict iMv | 2273 | //predict iMv |
| 2274 | PredPSkipMvFromNeighbor (pCurLayer, iMv); | 2274 | PredPSkipMvFromNeighbor (pCurLayer, iMv); |
| 2275 | for (i = 0; i < 16; i++) { | 2275 | for (i = 0; i < 16; i++) { |
| 2276 | ST32A2 (pCurLayer->pMv[0][iMbXy][i], * (uint32_t*)iMv); | 2276 | ST32A2 (pCurLayer->pMv[0][iMbXy][i], * (uint32_t*)iMv); |
| 2277 | } | 2277 | } |
| 2278 | 2278 | ||
| 2279 | //if (!pSlice->sSliceHeaderExt.bDefaultResidualPredFlag) { | 2279 | //if (!pSlice->sSliceHeaderExt.bDefaultResidualPredFlag) { |
| 2280 | // memset (pCurLayer->pScaledTCoeff[iMbXy], 0, 384 * sizeof (int16_t)); | 2280 | // memset (pCurLayer->pScaledTCoeff[iMbXy], 0, 384 * sizeof (int16_t)); |
| 2281 | //} | 2281 | //} |
| 2282 | 2282 | ||
| 2283 | //reset rS | 2283 | //reset rS |
| 2284 | if (!pSlice->sSliceHeaderExt.bDefaultResidualPredFlag || | 2284 | if (!pSlice->sSliceHeaderExt.bDefaultResidualPredFlag || |
| 2285 | (pNalCur->sNalHeaderExt.uiQualityId == 0 && pNalCur->sNalHeaderExt.uiDependencyId == 0)) { | 2285 | (pNalCur->sNalHeaderExt.uiQualityId == 0 && pNalCur->sNalHeaderExt.uiDependencyId == 0)) { |
| 2286 | pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; | 2286 | pCurLayer->pLumaQp[iMbXy] = pSlice->iLastMbQp; |
| 2287 | for (i = 0; i < 2; i++) { | 2287 | for (i = 0; i < 2; i++) { |
| 2288 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pCurLayer->pLumaQp[iMbXy] + | 2288 | pCurLayer->pChromaQp[iMbXy][i] = g_kuiChromaQpTable[WELS_CLIP3 (pCurLayer->pLumaQp[iMbXy] + |
| 2289 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; | 2289 | pSliceHeader->pPps->iChromaQpIndexOffset[i], 0, 51)]; |
| 2290 | } | 2290 | } |
| 2291 | } | 2291 | } |
| 2292 | 2292 | ||
| 2293 | pCurLayer->pCbp[iMbXy] = 0; | 2293 | pCurLayer->pCbp[iMbXy] = 0; |
| 2294 | } else { | 2294 | } else { |
| 2295 | if (pSlice->sSliceHeaderExt.bAdaptiveBaseModeFlag == 1) { | 2295 | if (pSlice->sSliceHeaderExt.bAdaptiveBaseModeFlag == 1) { |
| 2296 | WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //base_mode_flag | 2296 | WELS_READ_VERIFY (BsGetOneBit (pBs, &uiCode)); //base_mode_flag |
| 2297 | iBaseModeFlag = uiCode; | 2297 | iBaseModeFlag = uiCode; |
| 2298 | } else { | 2298 | } else { |
| 2299 | iBaseModeFlag = pSlice->sSliceHeaderExt.bDefaultBaseModeFlag; | 2299 | iBaseModeFlag = pSlice->sSliceHeaderExt.bDefaultBaseModeFlag; |
| 2300 | } | 2300 | } |
| 2301 | if (!iBaseModeFlag) { | 2301 | if (!iBaseModeFlag) { |
| 2302 | iRet = WelsActualDecodeMbCavlcPSlice (pCtx); | 2302 | iRet = WelsActualDecodeMbCavlcPSlice (pCtx); |
| 2303 | } else { | 2303 | } else { |
| 2304 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "iBaseModeFlag (%d) != 0, inter-layer prediction not supported.", | 2304 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, "iBaseModeFlag (%d) != 0, inter-layer prediction not supported.", |
| 2305 | iBaseModeFlag); | 2305 | iBaseModeFlag); |
| 2306 | return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_ILP); | 2306 | return GENERATE_ERROR_NO (ERR_LEVEL_SLICE_HEADER, ERR_INFO_UNSUPPORTED_ILP); |
| 2307 | } | 2307 | } |
| 2308 | if (iRet) { //occur error when parsing, MUST STOP decoding | 2308 | if (iRet) { //occur error when parsing, MUST STOP decoding |
| 2309 | return iRet; | 2309 | return iRet; |
| 2310 | } | 2310 | } |
| 2311 | } | 2311 | } |
| 2312 | // check whether there is left bits to read next time in case multiple slices | 2312 | // check whether there is left bits to read next time in case multiple slices |
| 2313 | iUsedBits = ((pBs->pCurBuf - pBs->pStartBuf) << 3) - (16 - pBs->iLeftBits); | 2313 | iUsedBits = ((pBs->pCurBuf - pBs->pStartBuf) << 3) - (16 - pBs->iLeftBits); |
| 2314 | // sub 1, for stop bit | 2314 | // sub 1, for stop bit |
| 2315 | if ((iUsedBits == (pBs->iBits - 1)) && (0 >= pCurLayer->sLayerInfo.sSliceInLayer.iMbSkipRun)) { // slice boundary | 2315 | if ((iUsedBits == (pBs->iBits - 1)) && (0 >= pCurLayer->sLayerInfo.sSliceInLayer.iMbSkipRun)) { // slice boundary |
| 2316 | uiEosFlag = 1; | 2316 | uiEosFlag = 1; |
| 2317 | } | 2317 | } |
| 2318 | if (iUsedBits > (pBs->iBits - | 2318 | if (iUsedBits > (pBs->iBits - |
| 2319 | 1)) { //When BS incomplete, as long as find it, SHOULD stop decoding to avoid mosaic or crash. | 2319 | 1)) { //When BS incomplete, as long as find it, SHOULD stop decoding to avoid mosaic or crash. |
| 2320 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, | 2320 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_WARNING, |
| 2321 | "WelsDecodeMbCavlcISlice()::::pBs incomplete, iUsedBits:%" PRId64 " > pBs->iBits:%d, MUST stop decoding.", | 2321 | "WelsDecodeMbCavlcISlice()::::pBs incomplete, iUsedBits:%" PRId64 " > pBs->iBits:%d, MUST stop decoding.", |
| 2322 | (int64_t) iUsedBits, pBs->iBits); | 2322 | (int64_t) iUsedBits, pBs->iBits); |
| 2323 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_BS_INCOMPLETE); | 2323 | return GENERATE_ERROR_NO (ERR_LEVEL_MB_DATA, ERR_INFO_BS_INCOMPLETE); |
| 2324 | } | 2324 | } |
| 2325 | return ERR_NONE; | 2325 | return ERR_NONE; |
| 2326 | } | 2326 | } |
| 2327 | 2327 | ||
| 2328 | void WelsBlockFuncInit (SBlockFunc* pFunc, int32_t iCpu) { | 2328 | void WelsBlockFuncInit (SBlockFunc* pFunc, int32_t iCpu) { |
| 2329 | pFunc->pWelsSetNonZeroCountFunc = WelsNonZeroCount_c; | 2329 | pFunc->pWelsSetNonZeroCountFunc = WelsNonZeroCount_c; |
| 2330 | pFunc->pWelsBlockZero16x16Func = WelsBlockZero16x16_c; | 2330 | pFunc->pWelsBlockZero16x16Func = WelsBlockZero16x16_c; |
| 2331 | pFunc->pWelsBlockZero8x8Func = WelsBlockZero8x8_c; | 2331 | pFunc->pWelsBlockZero8x8Func = WelsBlockZero8x8_c; |
| 2332 | 2332 | ||
| 2333 | #ifdef HAVE_NEON | 2333 | #ifdef HAVE_NEON |
| 2334 | if (iCpu & WELS_CPU_NEON) { | 2334 | if (iCpu & WELS_CPU_NEON) { |
| 2335 | pFunc->pWelsSetNonZeroCountFunc = WelsNonZeroCount_neon; | 2335 | pFunc->pWelsSetNonZeroCountFunc = WelsNonZeroCount_neon; |
| 2336 | pFunc->pWelsBlockZero16x16Func = WelsBlockZero16x16_neon; | 2336 | pFunc->pWelsBlockZero16x16Func = WelsBlockZero16x16_neon; |
| 2337 | pFunc->pWelsBlockZero8x8Func = WelsBlockZero8x8_neon; | 2337 | pFunc->pWelsBlockZero8x8Func = WelsBlockZero8x8_neon; |
| 2338 | } | 2338 | } |
| 2339 | #endif | 2339 | #endif |
| 2340 | 2340 | ||
| 2341 | #ifdef HAVE_NEON_AARCH64 | 2341 | #ifdef HAVE_NEON_AARCH64 |
| 2342 | if (iCpu & WELS_CPU_NEON) { | 2342 | if (iCpu & WELS_CPU_NEON) { |
| 2343 | pFunc->pWelsSetNonZeroCountFunc = WelsNonZeroCount_AArch64_neon; | 2343 | pFunc->pWelsSetNonZeroCountFunc = WelsNonZeroCount_AArch64_neon; |
| 2344 | pFunc->pWelsBlockZero16x16Func = WelsBlockZero16x16_AArch64_neon; | 2344 | pFunc->pWelsBlockZero16x16Func = WelsBlockZero16x16_AArch64_neon; |
| 2345 | pFunc->pWelsBlockZero8x8Func = WelsBlockZero8x8_AArch64_neon; | 2345 | pFunc->pWelsBlockZero8x8Func = WelsBlockZero8x8_AArch64_neon; |
| 2346 | } | 2346 | } |
| 2347 | #endif | 2347 | #endif |
| 2348 | 2348 | ||
| 2349 | #if defined(X86_ASM) | 2349 | #if defined(X86_ASM) |
| 2350 | if (iCpu & WELS_CPU_SSE2) { | 2350 | if (iCpu & WELS_CPU_SSE2) { |
| 2351 | pFunc->pWelsSetNonZeroCountFunc = WelsNonZeroCount_sse2; | 2351 | pFunc->pWelsSetNonZeroCountFunc = WelsNonZeroCount_sse2; |
| 2352 | pFunc->pWelsBlockZero16x16Func = WelsBlockZero16x16_sse2; | 2352 | pFunc->pWelsBlockZero16x16Func = WelsBlockZero16x16_sse2; |
| 2353 | pFunc->pWelsBlockZero8x8Func = WelsBlockZero8x8_sse2; | 2353 | pFunc->pWelsBlockZero8x8Func = WelsBlockZero8x8_sse2; |
| 2354 | } | 2354 | } |
| 2355 | #endif | 2355 | #endif |
| 2356 | 2356 | ||
| 2357 | } | 2357 | } |
| 2358 | 2358 | ||
| 2359 | void WelsBlockInit (int16_t* pBlock, int iW, int iH, int iStride, uint8_t uiVal) { | 2359 | void WelsBlockInit (int16_t* pBlock, int iW, int iH, int iStride, uint8_t uiVal) { |
| 2360 | int32_t i; | 2360 | int32_t i; |
| 2361 | int16_t* pDst = pBlock; | 2361 | int16_t* pDst = pBlock; |
| 2362 | 2362 | ||
| 2363 | for (i = 0; i < iH; i++) { | 2363 | for (i = 0; i < iH; i++) { |
| 2364 | memset (pDst, uiVal, iW * sizeof (int16_t)); | 2364 | memset (pDst, uiVal, iW * sizeof (int16_t)); |
| 2365 | pDst += iStride; | 2365 | pDst += iStride; |
| 2366 | } | 2366 | } |
| 2367 | } | 2367 | } |
| 2368 | void WelsBlockZero16x16_c (int16_t* pBlock, int32_t iStride) { | 2368 | void WelsBlockZero16x16_c (int16_t* pBlock, int32_t iStride) { |
| 2369 | WelsBlockInit (pBlock, 16, 16, iStride, 0); | 2369 | WelsBlockInit (pBlock, 16, 16, iStride, 0); |
| 2370 | } | 2370 | } |
| 2371 | 2371 | ||
| 2372 | void WelsBlockZero8x8_c (int16_t* pBlock, int32_t iStride) { | 2372 | void WelsBlockZero8x8_c (int16_t* pBlock, int32_t iStride) { |
| 2373 | WelsBlockInit (pBlock, 8, 8, iStride, 0); | 2373 | WelsBlockInit (pBlock, 8, 8, iStride, 0); |
| 2374 | } | 2374 | } |
| 2375 | bool ComputeColocated (PWelsDecoderContext pCtx) { | 2375 | bool ComputeColocated (PWelsDecoderContext pCtx) { |
| 2376 | PDqLayer pCurLayer = pCtx->pCurDqLayer; | 2376 | PDqLayer pCurLayer = pCtx->pCurDqLayer; |
| 2377 | PSlice pCurSlice = &pCurLayer->sLayerInfo.sSliceInLayer; | 2377 | PSlice pCurSlice = &pCurLayer->sLayerInfo.sSliceInLayer; |
| 2378 | PSliceHeader pSliceHeader = &pCurSlice->sSliceHeaderExt.sSliceHeader; | 2378 | PSliceHeader pSliceHeader = &pCurSlice->sSliceHeaderExt.sSliceHeader; |
| 2379 | if (!pSliceHeader->iDirectSpatialMvPredFlag) { | 2379 | if (!pSliceHeader->iDirectSpatialMvPredFlag) { |
| 2380 | uint32_t uiShortRefCount = pCtx->sRefPic.uiShortRefCount[LIST_0]; | 2380 | uint32_t uiShortRefCount = pCtx->sRefPic.uiShortRefCount[LIST_0]; |
| 2381 | for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { | 2381 | for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { |
| 2382 | for (uint32_t i = 0; i < uiShortRefCount; ++i) { | 2382 | for (uint32_t i = 0; i < uiShortRefCount; ++i) { |
| 2383 | int32_t iTRb = WELS_CLIP3 (-128, 127, pSliceHeader->iPicOrderCntLsb - pCtx->sRefPic.pRefList[listIdx][i]->iFramePoc); | 2383 | int32_t iTRb = WELS_CLIP3 (-128, 127, pSliceHeader->iPicOrderCntLsb - pCtx->sRefPic.pRefList[listIdx][i]->iFramePoc); |
| 2384 | int32_t iTRp = WELS_CLIP3 (-128, 127, | 2384 | int32_t iTRp = WELS_CLIP3 (-128, 127, |
| 2385 | pCtx->sRefPic.pRefList[LIST_1][i]->iFramePoc - pCtx->sRefPic.pRefList[LIST_0][i]->iFramePoc); | 2385 | pCtx->sRefPic.pRefList[LIST_1][i]->iFramePoc - pCtx->sRefPic.pRefList[LIST_0][i]->iFramePoc); |
| 2386 | if (iTRp != 0) { | 2386 | if (iTRp != 0) { |
| 2387 | int32_t prescale = (16384 + iAbs (iTRp / 2)) / iTRp; | 2387 | int32_t prescale = (16384 + iAbs (iTRp / 2)) / iTRp; |
| 2388 | pCurSlice->iMvScale[listIdx][i] = WELS_CLIP3 (-1024, 1023, (iTRb * prescale + 32) >> 6); | 2388 | pCurSlice->iMvScale[listIdx][i] = WELS_CLIP3 (-1024, 1023, (iTRb * prescale + 32) >> 6); |
| 2389 | } else { | 2389 | } else { |
| 2390 | pCurSlice->iMvScale[listIdx][i] = 0x03FFF; | 2390 | pCurSlice->iMvScale[listIdx][i] = 0x03FFF; |
| 2391 | } | 2391 | } |
| 2392 | } | 2392 | } |
| 2393 | } | 2393 | } |
| 2394 | } | 2394 | } |
| 2395 | //Implement the following | 2395 | //Implement the following |
| 2396 | //get Mv_colocated_L1 | 2396 | //get Mv_colocated_L1 |
| 2397 | //and do calculation | 2397 | //and do calculation |
| 2398 | //iMvp[LIST_0] = Mv_colocated_L1 * (POC(cur) - POC(L0))/POC(L1) - POC(L0)) | 2398 | //iMvp[LIST_0] = Mv_colocated_L1 * (POC(cur) - POC(L0))/POC(L1) - POC(L0)) |
| 2399 | //iMvp[LIST_1] = Mv_colocated_L1 * (POC(cur) - POC(L1))/POC(L1) - POC(L0)) | 2399 | //iMvp[LIST_1] = Mv_colocated_L1 * (POC(cur) - POC(L1))/POC(L1) - POC(L0)) |
| 2400 | return true; | 2400 | return true; |
| 2401 | } | 2401 | } |
| 2402 | } // namespace WelsDec | 2402 | } // namespace WelsDec |