Showing the changes to codec/decoder/core/src/au_parser.cpp (1 of 225 files). Show all
Unified · Split
| @@ -1,1027 +1,973 @@ | |||
| 1 | /*! | 1 | /*! |
| 2 | * \copy | 2 | * \copy |
| 3 | * Copyright (c) 2009-2013, Cisco Systems | 3 | * Copyright (c) 2009-2013, Cisco Systems |
| 4 | * All rights reserved. | 4 | * All rights reserved. |
| 5 | * | 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or 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 | * \file au_parser.c | 32 | * \file au_parser.c |
| 33 | * | 33 | * |
| 34 | * \brief Interfaces introduced in Access Unit level based parser | 34 | * \brief Interfaces introduced in Access Unit level based parser |
| 35 | * | 35 | * |
| 36 | * \date 03/10/2009 Created | 36 | * \date 03/10/2009 Created |
| 37 | * | 37 | * |
| 38 | ************************************************************************************* | 38 | ************************************************************************************* |
| 39 | */ | 39 | */ |
| 40 | #include <string.h> | 40 | #include <string.h> |
| 41 | #include "codec_def.h" | 41 | #include "codec_def.h" |
| 42 | #include "ls_defines.h" | 42 | #include "ls_defines.h" |
| 43 | #include "macros.h" | 43 | #include "macros.h" |
| 44 | #include "au_parser.h" | 44 | #include "au_parser.h" |
| 45 | #include "decoder.h" | 45 | #include "decoder.h" |
| 46 | #include "error_code.h" | 46 | #include "error_code.h" |
| 47 | #include "dec_frame.h" | 47 | #include "dec_frame.h" |
| 48 | #include "dec_golomb.h" | 48 | #include "dec_golomb.h" |
| 49 | #include "bit_stream.h" | 49 | #include "bit_stream.h" |
| 50 | #include "utils.h" | 50 | #include "utils.h" |
| 51 | #include "codec_app_def.h" | 51 | #include "codec_app_def.h" |
| 52 | #include "memmgr_nal_unit.h" | 52 | #include "memmgr_nal_unit.h" |
| 53 | #include "decoder_core.h" | 53 | #include "decoder_core.h" |
| 54 | #include "wels_common_basis.h" | 54 | #include "wels_common_basis.h" |
| 55 | #include "decoder_core.h" | 55 | #include "decoder_core.h" |
| 56 | #include "manage_dec_ref.h" | 56 | #include "manage_dec_ref.h" |
| 57 | #include "mem_align.h" | 57 | #include "mem_align.h" |
| 58 | 58 | ||
| 59 | namespace WelsDec { | 59 | namespace WelsDec { |
| 60 | /*! | 60 | /*! |
| 61 | ************************************************************************************* | 61 | ************************************************************************************* |
| 62 | * \brief Start Code Prefix (0x 00 00 00 01) detection | 62 | * \brief Start Code Prefix (0x 00 00 00 01) detection |
| 63 | * | 63 | * |
| 64 | * \param pBuf bitstream payload buffer | 64 | * \param pBuf bitstream payload buffer |
| 65 | * \param pOffset offset between NAL rbsp and original bitsteam that | 65 | * \param pOffset offset between NAL rbsp and original bitsteam that |
| 66 | * start code prefix is seperated from. | 66 | * start code prefix is seperated from. |
| 67 | * \param iBufSize count size of buffer | 67 | * \param iBufSize count size of buffer |
| 68 | * | 68 | * |
| 69 | * \return RBSP buffer of start code prefix exclusive | 69 | * \return RBSP buffer of start code prefix exclusive |
| 70 | * | 70 | * |
| 71 | * \note N/A | 71 | * \note N/A |
| 72 | ************************************************************************************* | 72 | ************************************************************************************* |
| 73 | */ | 73 | */ |
| 74 | uint8_t* DetectStartCodePrefix( const uint8_t *kpBuf, int32_t *pOffset, int32_t iBufSize ) | 74 | uint8_t* DetectStartCodePrefix (const uint8_t* kpBuf, int32_t* pOffset, int32_t iBufSize) { |
| 75 | { | 75 | uint8_t* pBits = (uint8_t*)kpBuf; |
| 76 | uint8_t *pBits = (uint8_t *)kpBuf; | 76 | |
| 77 | 77 | do { | |
| 78 | do { | 78 | int32_t iIdx = 0; |
| 79 | int32_t iIdx = 0; | 79 | while ((iIdx < iBufSize) && (! (*pBits))) { |
| 80 | while( (iIdx<iBufSize) && (!(*pBits)) ){ | 80 | ++ pBits; |
| 81 | ++ pBits; | 81 | ++ iIdx; |
| 82 | ++ iIdx; | 82 | } |
| 83 | } | 83 | if (iIdx >= iBufSize) break; |
| 84 | if( iIdx >= iBufSize ) break; | 84 | |
| 85 | 85 | ++ iIdx; | |
| 86 | ++ iIdx; | 86 | ++ pBits; |
| 87 | ++ pBits; | 87 | |
| 88 | 88 | if ((iIdx >= 3) && ((* (pBits - 1)) == 0x1)) { | |
| 89 | if( (iIdx>=3) && ((*(pBits-1)) == 0x1) ){ | 89 | *pOffset = ((uint32_t)pBits) - ((uint32_t)kpBuf); |
| 90 | *pOffset = ((uint32_t)pBits) - ((uint32_t)kpBuf); | 90 | return pBits; |
| 91 | return pBits; | 91 | } |
| 92 | } | 92 | |
| 93 | 93 | iBufSize -= iIdx; | |
| 94 | iBufSize -= iIdx; | 94 | } while (1); |
| 95 | } while (1); | 95 | |
| 96 | 96 | return NULL; | |
| 97 | return NULL; | 97 | } |
| 98 | } | 98 | |
| 99 | 99 | /*! | |
| 100 | /*! | 100 | ************************************************************************************* |
| 101 | ************************************************************************************* | 101 | * \brief to parse nal unit |
| 102 | * \brief to parse nal unit | 102 | * |
| 103 | * | 103 | * \param pCtx decoder context |
| 104 | * \param pCtx decoder context | 104 | * \param pNalUnitHeader parsed result of NAL Unit Header to output |
| 105 | * \param pNalUnitHeader parsed result of NAL Unit Header to output | 105 | * \param pSrcRbsp bitstream buffer to input |
| 106 | * \param pSrcRbsp bitstream buffer to input | 106 | * \param iSrcRbspLen length size of bitstream buffer payload |
| 107 | * \param iSrcRbspLen length size of bitstream buffer payload | 107 | * \param pSrcNal |
| 108 | * \param pSrcNal | 108 | * \param iSrcNalLen |
| 109 | * \param iSrcNalLen | 109 | * \param pConsumedBytes consumed bytes during parsing |
| 110 | * \param pConsumedBytes consumed bytes during parsing | 110 | * |
| 111 | * | 111 | * \return decoded bytes payload, might be (pSrcRbsp+1) if no escapes |
| 112 | * \return decoded bytes payload, might be (pSrcRbsp+1) if no escapes | 112 | * |
| 113 | * | 113 | * \note N/A |
| 114 | * \note N/A | 114 | ************************************************************************************* |
| 115 | ************************************************************************************* | 115 | */ |
| 116 | */ | 116 | uint8_t* ParseNalHeader (PWelsDecoderContext pCtx, SNalUnitHeader* pNalUnitHeader, uint8_t* pSrcRbsp, |
| 117 | uint8_t* ParseNalHeader( PWelsDecoderContext pCtx, SNalUnitHeader *pNalUnitHeader, uint8_t *pSrcRbsp, int32_t iSrcRbspLen, uint8_t *pSrcNal, int32_t iSrcNalLen, int32_t* pConsumedBytes ) | 117 | int32_t iSrcRbspLen, uint8_t* pSrcNal, int32_t iSrcNalLen, int32_t* pConsumedBytes) { |
| 118 | { | 118 | PNalUnit pCurNal = NULL; |
| 119 | PNalUnit pCurNal = NULL; | 119 | uint8_t* pNal = pSrcRbsp; |
| 120 | uint8_t* pNal = pSrcRbsp; | 120 | int32_t iNalSize = iSrcRbspLen; |
| 121 | int32_t iNalSize = iSrcRbspLen; | 121 | PBitStringAux pBs = NULL; |
| 122 | PBitStringAux pBs = NULL; | 122 | bool_t bExtensionFlag = false; |
| 123 | bool_t bExtensionFlag = false; | 123 | int32_t iErr = ERR_NONE; |
| 124 | int32_t iErr = ERR_NONE; | 124 | int32_t iBitSize = 0; |
| 125 | int32_t iBitSize = 0; | 125 | |
| 126 | 126 | pNalUnitHeader->eNalUnitType = NAL_UNIT_UNSPEC_0;//SHOULD init it. because pCtx->sCurNalHead is common variable. | |
| 127 | pNalUnitHeader->eNalUnitType = NAL_UNIT_UNSPEC_0;//SHOULD init it. because pCtx->sCurNalHead is common variable. | 127 | |
| 128 | 128 | //remove the consecutive ZERO at the end of current NAL in the reverse order.--2011.6.1 | |
| 129 | //remove the consecutive ZERO at the end of current NAL in the reverse order.--2011.6.1 | 129 | { |
| 130 | { | 130 | int32_t iIndex = iSrcRbspLen - 1; |
| 131 | int32_t iIndex = iSrcRbspLen - 1; | 131 | uint8_t uiBsZero = 0; |
| 132 | uint8_t uiBsZero = 0; | 132 | while (iIndex >= 0) { |
| 133 | while ( iIndex >= 0 ) | 133 | uiBsZero = pSrcRbsp[iIndex]; |
| 134 | { | 134 | if (0 == uiBsZero) { |
| 135 | uiBsZero = pSrcRbsp[iIndex]; | 135 | --iNalSize; |
| 136 | if ( 0 == uiBsZero ) | 136 | --iIndex; |
| 137 | { | 137 | } else { |
| 138 | --iNalSize; | 138 | break; |
| 139 | --iIndex; | 139 | } |
| 140 | } | 140 | } |
| 141 | else | 141 | } |
| 142 | { | 142 | |
| 143 | break; | 143 | pNalUnitHeader->uiForbiddenZeroBit = (uint8_t) (pNal[0] >> 7); // uiForbiddenZeroBit |
| 144 | } | 144 | if (pNalUnitHeader->uiForbiddenZeroBit) { //2010.4.14 |
| 145 | } | 145 | return NULL; //uiForbiddenZeroBit should always equal to 0 |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | pNalUnitHeader->uiForbiddenZeroBit = (uint8_t)(pNal[0] >> 7); // uiForbiddenZeroBit | 148 | pNalUnitHeader->uiNalRefIdc = (uint8_t) (pNal[0] >> 5); // uiNalRefIdc |
| 149 | if ( pNalUnitHeader->uiForbiddenZeroBit )//2010.4.14 | 149 | pNalUnitHeader->eNalUnitType = (ENalUnitType) (pNal[0] & 0x1f); // eNalUnitType |
| 150 | { | 150 | |
| 151 | return NULL; //uiForbiddenZeroBit should always equal to 0 | 151 | ++pNal; |
| 152 | } | 152 | --iNalSize; |
| 153 | 153 | ++ (*pConsumedBytes); | |
| 154 | pNalUnitHeader->uiNalRefIdc = (uint8_t)(pNal[0] >> 5); // uiNalRefIdc | 154 | |
| 155 | pNalUnitHeader->eNalUnitType = (ENalUnitType)(pNal[0] & 0x1f); // eNalUnitType | 155 | #ifdef DEBUG_PARSE_INFO |
| 156 | 156 | WelsLog (pCtx, WELS_LOG_INFO, "nal type: %d \n", pNalUnitHeader->eNalUnitType); | |
| 157 | ++pNal; | 157 | #endif |
| 158 | --iNalSize; | 158 | |
| 159 | ++(*pConsumedBytes); | 159 | if (! (IS_SEI_NAL (pNalUnitHeader->eNalUnitType) || IS_SPS_NAL (pNalUnitHeader->eNalUnitType) |
| 160 | 160 | || pCtx->bSpsExistAheadFlag)) { | |
| 161 | #ifdef DEBUG_PARSE_INFO | 161 | WelsLog (pCtx, WELS_LOG_WARNING, |
| 162 | WelsLog(pCtx, WELS_LOG_INFO, "nal type: %d \n", pNalUnitHeader->eNalUnitType); | 162 | "parse_nal(), no exist Sequence Parameter Sets ahead of sequence when try to decode NAL(type:%d).\n", |
| 163 | #endif | 163 | pNalUnitHeader->eNalUnitType); |
| 164 | 164 | pCtx->iErrorCode = dsNoParamSets; | |
| 165 | if ( !(IS_SEI_NAL(pNalUnitHeader->eNalUnitType) || IS_SPS_NAL(pNalUnitHeader->eNalUnitType) || pCtx->bSpsExistAheadFlag) ) | 165 | return NULL; |
| 166 | { | 166 | } |
| 167 | WelsLog( pCtx, WELS_LOG_WARNING, "parse_nal(), no exist Sequence Parameter Sets ahead of sequence when try to decode NAL(type:%d).\n", pNalUnitHeader->eNalUnitType); | 167 | if (! (IS_SEI_NAL (pNalUnitHeader->eNalUnitType) || IS_PARAM_SETS_NALS (pNalUnitHeader->eNalUnitType) |
| 168 | pCtx->iErrorCode = dsNoParamSets; | 168 | || pCtx->bPpsExistAheadFlag)) { |
| 169 | return NULL; | 169 | WelsLog (pCtx, WELS_LOG_WARNING, |
| 170 | } | 170 | "parse_nal(), no exist Picture Parameter Sets ahead of sequence when try to decode NAL(type:%d).\n", |
| 171 | if ( !(IS_SEI_NAL(pNalUnitHeader->eNalUnitType) || IS_PARAM_SETS_NALS(pNalUnitHeader->eNalUnitType) || pCtx->bPpsExistAheadFlag) ) | 171 | pNalUnitHeader->eNalUnitType); |
| 172 | { | 172 | pCtx->iErrorCode = dsNoParamSets; |
| 173 | WelsLog( pCtx, WELS_LOG_WARNING, "parse_nal(), no exist Picture Parameter Sets ahead of sequence when try to decode NAL(type:%d).\n", pNalUnitHeader->eNalUnitType); | 173 | return NULL; |
| 174 | pCtx->iErrorCode = dsNoParamSets; | 174 | } |
| 175 | return NULL; | 175 | if ((IS_VCL_NAL_AVC_BASE (pNalUnitHeader->eNalUnitType) && ! (pCtx->bSpsExistAheadFlag || pCtx->bPpsExistAheadFlag)) || |
| 176 | } | 176 | (IS_NEW_INTRODUCED_NAL (pNalUnitHeader->eNalUnitType) && ! (pCtx->bSpsExistAheadFlag || pCtx->bSubspsExistAheadFlag |
| 177 | if ( (IS_VCL_NAL_AVC_BASE(pNalUnitHeader->eNalUnitType) && !(pCtx->bSpsExistAheadFlag || pCtx->bPpsExistAheadFlag)) || | 177 | || pCtx->bPpsExistAheadFlag))) { |
| 178 | (IS_NEW_INTRODUCED_NAL(pNalUnitHeader->eNalUnitType) && !(pCtx->bSpsExistAheadFlag || pCtx->bSubspsExistAheadFlag || pCtx->bPpsExistAheadFlag) ) ) | 178 | WelsLog (pCtx, WELS_LOG_WARNING, |
| 179 | { | 179 | "ParseNalHeader(), no exist Parameter Sets ahead of sequence when try to decode slice(type:%d).\n", |
| 180 | WelsLog( pCtx, WELS_LOG_WARNING, "ParseNalHeader(), no exist Parameter Sets ahead of sequence when try to decode slice(type:%d).\n", pNalUnitHeader->eNalUnitType); | 180 | pNalUnitHeader->eNalUnitType); |
| 181 | pCtx->iErrorCode |= dsNoParamSets; | 181 | pCtx->iErrorCode |= dsNoParamSets; |
| 182 | return NULL; | 182 | return NULL; |
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | 185 | ||
| 186 | switch(pNalUnitHeader->eNalUnitType){ | 186 | switch (pNalUnitHeader->eNalUnitType) { |
| 187 | case NAL_UNIT_SEI: | 187 | case NAL_UNIT_SEI: |
| 188 | 188 | ||
| 189 | if ( pCtx->pAccessUnitList->uiAvailUnitsNum > 0 ) | 189 | if (pCtx->pAccessUnitList->uiAvailUnitsNum > 0) { |
| 190 | { | 190 | pCtx->pAccessUnitList->uiEndPos = pCtx->pAccessUnitList->uiAvailUnitsNum - 1; |
| 191 | pCtx->pAccessUnitList->uiEndPos = pCtx->pAccessUnitList->uiAvailUnitsNum - 1; | 191 | pCtx->bAuReadyFlag = true; |
| 192 | pCtx->bAuReadyFlag = true; | 192 | } |
| 193 | } | 193 | |
| 194 | 194 | break; | |
| 195 | break; | 195 | |
| 196 | 196 | case NAL_UNIT_SPS: | |
| 197 | case NAL_UNIT_SPS: | 197 | |
| 198 | 198 | if (pCtx->pAccessUnitList->uiAvailUnitsNum > 0) { | |
| 199 | if ( pCtx->pAccessUnitList->uiAvailUnitsNum > 0 ) | 199 | pCtx->pAccessUnitList->uiEndPos = pCtx->pAccessUnitList->uiAvailUnitsNum - 1; |
| 200 | { | 200 | pCtx->bAuReadyFlag = true; |
| 201 | pCtx->pAccessUnitList->uiEndPos = pCtx->pAccessUnitList->uiAvailUnitsNum - 1; | 201 | } |
| 202 | pCtx->bAuReadyFlag = true; | 202 | |
| 203 | } | 203 | break; |
| 204 | 204 | ||
| 205 | break; | 205 | case NAL_UNIT_PREFIX: |
| 206 | 206 | pCurNal = &pCtx->sPrefixNal; | |
| 207 | case NAL_UNIT_PREFIX: | 207 | |
| 208 | pCurNal = &pCtx->sPrefixNal; | 208 | if (iNalSize < NAL_UNIT_HEADER_EXT_SIZE) { |
| 209 | 209 | return NULL; | |
| 210 | if ( iNalSize < NAL_UNIT_HEADER_EXT_SIZE ) | 210 | } |
| 211 | { | 211 | |
| 212 | return NULL; | 212 | DecodeNalHeaderExt (pCurNal, pNal); |
| 213 | } | 213 | |
| 214 | 214 | pNal += NAL_UNIT_HEADER_EXT_SIZE; | |
| 215 | DecodeNalHeaderExt( pCurNal, pNal ); | 215 | iNalSize -= NAL_UNIT_HEADER_EXT_SIZE; |
| 216 | 216 | *pConsumedBytes += NAL_UNIT_HEADER_EXT_SIZE; | |
| 217 | pNal += NAL_UNIT_HEADER_EXT_SIZE; | 217 | |
| 218 | iNalSize -= NAL_UNIT_HEADER_EXT_SIZE; | 218 | pCurNal->sNalHeaderExt.sNalUnitHeader.uiForbiddenZeroBit = pNalUnitHeader->uiForbiddenZeroBit; |
| 219 | *pConsumedBytes += NAL_UNIT_HEADER_EXT_SIZE; | 219 | pCurNal->sNalHeaderExt.sNalUnitHeader.uiNalRefIdc = pNalUnitHeader->uiNalRefIdc; |
| 220 | 220 | pCurNal->sNalHeaderExt.sNalUnitHeader.eNalUnitType = pNalUnitHeader->eNalUnitType; | |
| 221 | pCurNal->sNalHeaderExt.sNalUnitHeader.uiForbiddenZeroBit = pNalUnitHeader->uiForbiddenZeroBit; | 221 | |
| 222 | pCurNal->sNalHeaderExt.sNalUnitHeader.uiNalRefIdc = pNalUnitHeader->uiNalRefIdc; | 222 | pBs = &pCtx->sBs; |
| 223 | pCurNal->sNalHeaderExt.sNalUnitHeader.eNalUnitType = pNalUnitHeader->eNalUnitType; | 223 | |
| 224 | 224 | iBitSize = (iNalSize << 3) - BsGetTrailingBits (pNal + iNalSize - 1); // convert into bit | |
| 225 | pBs = &pCtx->sBs; | 225 | |
| 226 | 226 | InitBits (pBs, pNal, iBitSize); | |
| 227 | iBitSize = (iNalSize<<3) - BsGetTrailingBits( pNal + iNalSize - 1 ); // convert into bit | 227 | |
| 228 | 228 | ParsePrefixNalUnit (pCtx, pBs); | |
| 229 | InitBits( pBs, pNal, iBitSize); | 229 | |
| 230 | 230 | break; | |
| 231 | ParsePrefixNalUnit( pCtx, pBs ); | 231 | case NAL_UNIT_CODED_SLICE_EXT: |
| 232 | 232 | bExtensionFlag = true; | |
| 233 | break; | 233 | case NAL_UNIT_CODED_SLICE: |
| 234 | case NAL_UNIT_CODED_SLICE_EXT: | 234 | case NAL_UNIT_CODED_SLICE_IDR: { |
| 235 | bExtensionFlag = true; | 235 | PAccessUnit pCurAu = NULL; |
| 236 | case NAL_UNIT_CODED_SLICE: | 236 | uint32_t uiAvailNalNum; |
| 237 | case NAL_UNIT_CODED_SLICE_IDR: | 237 | pCurNal = MemGetNextNal (&pCtx->pAccessUnitList); |
| 238 | { | 238 | if (NULL == pCurNal) { |
| 239 | PAccessUnit pCurAu = NULL; | 239 | WelsLog (pCtx, WELS_LOG_WARNING, "MemGetNextNal() fail due out of memory.\n"); |
| 240 | uint32_t uiAvailNalNum; | 240 | pCtx->iErrorCode |= dsOutOfMemory; |
| 241 | pCurNal = MemGetNextNal( &pCtx->pAccessUnitList ); | 241 | return NULL; |
| 242 | if( NULL == pCurNal ) | 242 | } |
| 243 | { | 243 | |
| 244 | WelsLog( pCtx, WELS_LOG_WARNING, "MemGetNextNal() fail due out of memory.\n"); | 244 | pCurNal->sNalHeaderExt.sNalUnitHeader.uiForbiddenZeroBit = pNalUnitHeader->uiForbiddenZeroBit; |
| 245 | pCtx->iErrorCode |= dsOutOfMemory; | 245 | pCurNal->sNalHeaderExt.sNalUnitHeader.uiNalRefIdc = pNalUnitHeader->uiNalRefIdc; |
| 246 | return NULL; | 246 | pCurNal->sNalHeaderExt.sNalUnitHeader.eNalUnitType = pNalUnitHeader->eNalUnitType; |
| 247 | } | 247 | pCurAu = pCtx->pAccessUnitList; |
| 248 | 248 | uiAvailNalNum = pCurAu->uiAvailUnitsNum; | |
| 249 | pCurNal->sNalHeaderExt.sNalUnitHeader.uiForbiddenZeroBit = pNalUnitHeader->uiForbiddenZeroBit; | 249 | |
| 250 | pCurNal->sNalHeaderExt.sNalUnitHeader.uiNalRefIdc = pNalUnitHeader->uiNalRefIdc; | 250 | |
| 251 | pCurNal->sNalHeaderExt.sNalUnitHeader.eNalUnitType = pNalUnitHeader->eNalUnitType; | 251 | if (pNalUnitHeader->eNalUnitType == NAL_UNIT_CODED_SLICE_EXT) { |
| 252 | pCurAu = pCtx->pAccessUnitList; | 252 | if (iNalSize < NAL_UNIT_HEADER_EXT_SIZE) { |
| 253 | uiAvailNalNum = pCurAu->uiAvailUnitsNum; | 253 | return NULL; |
| 254 | 254 | } | |
| 255 | 255 | ||
| 256 | if( pNalUnitHeader->eNalUnitType == NAL_UNIT_CODED_SLICE_EXT ) | 256 | DecodeNalHeaderExt (pCurNal, pNal); |
| 257 | { | 257 | if (pCurNal->sNalHeaderExt.uiQualityId != 0 || |
| 258 | if ( iNalSize < NAL_UNIT_HEADER_EXT_SIZE ) | 258 | pCurNal->sNalHeaderExt.bUseRefBasePicFlag) { |
| 259 | { | 259 | if (pCurNal->sNalHeaderExt.uiQualityId != 0) |
| 260 | return NULL; | 260 | WelsLog (pCtx, WELS_LOG_WARNING, "ParseNalHeader():uiQualityId (%d) != 0, MGS not supported!\n", |
| 261 | } | 261 | pCurNal->sNalHeaderExt.uiQualityId); |
| 262 | 262 | if (pCurNal->sNalHeaderExt.bUseRefBasePicFlag != 0) | |
| 263 | DecodeNalHeaderExt( pCurNal, pNal ); | 263 | WelsLog (pCtx, WELS_LOG_WARNING, "ParseNalHeader():bUseRefBasePicFlag (%d) != 0, MGS not supported!\n", |
| 264 | if( pCurNal->sNalHeaderExt.uiQualityId != 0 || | 264 | pCurNal->sNalHeaderExt.bUseRefBasePicFlag); |
| 265 | pCurNal->sNalHeaderExt.bUseRefBasePicFlag ) | 265 | |
| 266 | { | 266 | pCtx->iErrorCode |= dsInvalidArgument; |
| 267 | if( pCurNal->sNalHeaderExt.uiQualityId != 0 ) | 267 | ForceClearCurrentNal (pCurAu); |
| 268 | WelsLog(pCtx, WELS_LOG_WARNING, "ParseNalHeader():uiQualityId (%d) != 0, MGS not supported!\n", pCurNal->sNalHeaderExt.uiQualityId); | 268 | |
| 269 | if( pCurNal->sNalHeaderExt.bUseRefBasePicFlag != 0 ) | 269 | if (uiAvailNalNum > 1) { |
| 270 | WelsLog(pCtx, WELS_LOG_WARNING, "ParseNalHeader():bUseRefBasePicFlag (%d) != 0, MGS not supported!\n", pCurNal->sNalHeaderExt.bUseRefBasePicFlag); | 270 | pCurAu->uiEndPos = uiAvailNalNum - 2; |
| 271 | 271 | pCtx->bAuReadyFlag = true; | |
| 272 | pCtx->iErrorCode |= dsInvalidArgument; | 272 | } |
| 273 | ForceClearCurrentNal( pCurAu ); | 273 | return NULL; |
| 274 | 274 | } | |
| 275 | if ( uiAvailNalNum > 1 ) | 275 | pNal += NAL_UNIT_HEADER_EXT_SIZE; |
| 276 | { | 276 | iNalSize -= NAL_UNIT_HEADER_EXT_SIZE; |
| 277 | pCurAu->uiEndPos = uiAvailNalNum - 2; | 277 | *pConsumedBytes += NAL_UNIT_HEADER_EXT_SIZE; |
| 278 | pCtx->bAuReadyFlag = true; | 278 | |
| 279 | } | 279 | } else { |
| 280 | return NULL; | 280 | |
| 281 | } | 281 | |
| 282 | pNal += NAL_UNIT_HEADER_EXT_SIZE; | 282 | if (NAL_UNIT_PREFIX == pCtx->sPrefixNal.sNalHeaderExt.sNalUnitHeader.eNalUnitType) { |
| 283 | iNalSize -= NAL_UNIT_HEADER_EXT_SIZE; | 283 | PrefetchNalHeaderExtSyntax (pCtx, pCurNal, &pCtx->sPrefixNal); |
| 284 | *pConsumedBytes += NAL_UNIT_HEADER_EXT_SIZE; | 284 | } |
| 285 | 285 | ||
| 286 | } | 286 | pCurNal->sNalHeaderExt.bIdrFlag = (NAL_UNIT_CODED_SLICE_IDR == pNalUnitHeader->eNalUnitType) ? true : |
| 287 | else | 287 | false; //SHOULD update this flag for AVC if no prefix NAL |
| 288 | { | 288 | pCurNal->sNalHeaderExt.iNoInterLayerPredFlag = 1; |
| 289 | 289 | } | |
| 290 | 290 | ||
| 291 | if ( NAL_UNIT_PREFIX == pCtx->sPrefixNal.sNalHeaderExt.sNalUnitHeader.eNalUnitType ) | 291 | pBs = &pCurAu->pNalUnitsList[uiAvailNalNum - 1]->sNalData.sVclNal.sSliceBitsRead; |
| 292 | { | 292 | iBitSize = (iNalSize << 3) - BsGetTrailingBits (pNal + iNalSize - 1); // convert into bit |
| 293 | PrefetchNalHeaderExtSyntax( pCtx, pCurNal, &pCtx->sPrefixNal ); | 293 | InitBits (pBs, pNal, iBitSize); |
| 294 | } | 294 | iErr = ParseSliceHeaderSyntaxs (pCtx, pBs, bExtensionFlag); |
| 295 | 295 | if (iErr != ERR_NONE) { | |
| 296 | pCurNal->sNalHeaderExt.bIdrFlag = ( NAL_UNIT_CODED_SLICE_IDR == pNalUnitHeader->eNalUnitType ) ? true : false; //SHOULD update this flag for AVC if no prefix NAL | 296 | //if current NAL occur error when parsing, should clean it from pNalUnitsList |
| 297 | pCurNal->sNalHeaderExt.iNoInterLayerPredFlag = 1; | 297 | //otherwise, when Next good NAL decoding, this corrupt NAL is considered as normal NAL and lead to decoder crash |
| 298 | } | 298 | ForceClearCurrentNal (pCurAu); |
| 299 | 299 | ||
| 300 | pBs = &pCurAu->pNalUnitsList[uiAvailNalNum-1]->sNalData.sVclNal.sSliceBitsRead; | 300 | if (uiAvailNalNum > 1) { |
| 301 | iBitSize = (iNalSize<<3) - BsGetTrailingBits( pNal+ iNalSize - 1 ); // convert into bit | 301 | pCurAu->uiEndPos = uiAvailNalNum - 2; |
| 302 | InitBits( pBs, pNal, iBitSize); | 302 | pCtx->bAuReadyFlag = true; |
| 303 | iErr = ParseSliceHeaderSyntaxs( pCtx, pBs, bExtensionFlag ); | 303 | |
| 304 | if ( iErr != ERR_NONE ) | 304 | |
| 305 | { | 305 | } |
| 306 | //if current NAL occur error when parsing, should clean it from pNalUnitsList | 306 | #ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID |
| 307 | //otherwise, when Next good NAL decoding, this corrupt NAL is considered as normal NAL and lead to decoder crash | 307 | if (dsNoParamSets & pCtx->iErrorCode) { |
| 308 | ForceClearCurrentNal( pCurAu ); | 308 | if (uiAvailNalNum <= 1) { //no any data to decode and SPS/PPS ID mismatch, SHOULD request IDR |
| 309 | 309 | #ifdef LONG_TERM_REF | |
| 310 | if ( uiAvailNalNum > 1 ) | 310 | pCtx->bParamSetsLostFlag = true; |
| 311 | { | 311 | #else |
| 312 | pCurAu->uiEndPos = uiAvailNalNum - 2; | 312 | pCtx->bReferenceLostAtT0Flag = true; |
| 313 | pCtx->bAuReadyFlag = true; | 313 | #endif |
| 314 | 314 | ResetParameterSetsState (pCtx); | |
| 315 | 315 | } | |
| 316 | } | 316 | return NULL; |
| 317 | #ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | 317 | } else { |
| 318 | if ( dsNoParamSets & pCtx->iErrorCode ) | 318 | return NULL; |
| 319 | { | 319 | } |
| 320 | if ( uiAvailNalNum <= 1 ) //no any data to decode and SPS/PPS ID mismatch, SHOULD request IDR | 320 | #else |
| 321 | { | 321 | return NULL; |
| 322 | #ifdef LONG_TERM_REF | 322 | #endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID |
| 323 | pCtx->bParamSetsLostFlag = true; | 323 | } |
| 324 | #else | 324 | |
| 325 | pCtx->bReferenceLostAtT0Flag = true; | 325 | if ((uiAvailNalNum > 1) && |
| 326 | #endif | 326 | CheckAccessUnitBoundary (pCurAu->pNalUnitsList[uiAvailNalNum - 1], pCurAu->pNalUnitsList[uiAvailNalNum - 2], |
| 327 | ResetParameterSetsState( pCtx ); | 327 | pCurAu->pNalUnitsList[uiAvailNalNum - 1]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.pSps)) { |
| 328 | } | 328 | pCurAu->uiEndPos = uiAvailNalNum - 2; |
| 329 | return NULL; | 329 | pCtx->bAuReadyFlag = true; |
| 330 | } | 330 | |
| 331 | else | 331 | |
| 332 | { | 332 | } |
| 333 | return NULL; | 333 | } |
| 334 | } | 334 | break; |
| 335 | #else | 335 | default: |
| 336 | return NULL; | 336 | break; |
| 337 | #endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | 337 | } |
| 338 | } | 338 | |
| 339 | 339 | return pNal; | |
| 340 | if ( (uiAvailNalNum > 1) && | 340 | } |
| 341 | CheckAccessUnitBoundary( pCurAu->pNalUnitsList[uiAvailNalNum-1], pCurAu->pNalUnitsList[uiAvailNalNum-2], | 341 | |
| 342 | pCurAu->pNalUnitsList[uiAvailNalNum-1]->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.pSps) ) | 342 | |
| 343 | { | 343 | bool_t CheckAccessUnitBoundaryExt (PNalUnitHeaderExt pLastNalHdrExt, PNalUnitHeaderExt pCurNalHeaderExt, |
| 344 | pCurAu->uiEndPos = uiAvailNalNum - 2; | 344 | PSliceHeader pLastSliceHeader, PSliceHeader pCurSliceHeader) { |
| 345 | pCtx->bAuReadyFlag = true; | 345 | const PSps kpSps = pCurSliceHeader->pSps; |
| 346 | 346 | ||
| 347 | 347 | //Sub-clause 7.1.4.1.1 temporal_id | |
| 348 | } | 348 | if (pLastNalHdrExt->uiTemporalId != pCurNalHeaderExt->uiTemporalId) { |
| 349 | } | 349 | return TRUE; |
| 350 | break; | 350 | } |
| 351 | default: | 351 | |
| 352 | break; | 352 | // Subclause 7.4.1.2.5 |
| 353 | } | 353 | if (pLastSliceHeader->iRedundantPicCnt < pCurSliceHeader->iRedundantPicCnt) |
| 354 | 354 | return FALSE; | |
| 355 | return pNal; | 355 | else if (pLastSliceHeader->iRedundantPicCnt > pCurSliceHeader->iRedundantPicCnt) |
| 356 | } | 356 | return TRUE; |
| 357 | 357 | ||
| 358 | 358 | // Subclause G7.4.1.2.4 | |
| 359 | bool_t CheckAccessUnitBoundaryExt( PNalUnitHeaderExt pLastNalHdrExt, PNalUnitHeaderExt pCurNalHeaderExt, PSliceHeader pLastSliceHeader, PSliceHeader pCurSliceHeader ) | 359 | if (pLastNalHdrExt->uiDependencyId < pCurNalHeaderExt->uiDependencyId) |
| 360 | { | 360 | return FALSE; |
| 361 | const PSps kpSps = pCurSliceHeader->pSps; | 361 | else if (pLastNalHdrExt->uiDependencyId > pCurNalHeaderExt->uiDependencyId) |
| 362 | 362 | return TRUE; | |
| 363 | //Sub-clause 7.1.4.1.1 temporal_id | 363 | if (pLastNalHdrExt->uiQualityId < pCurNalHeaderExt->uiQualityId) |
| 364 | if (pLastNalHdrExt->uiTemporalId != pCurNalHeaderExt->uiTemporalId) { | 364 | return FALSE; |
| 365 | return TRUE; | 365 | else if (pLastNalHdrExt->uiQualityId > pCurNalHeaderExt->uiQualityId) |
| 366 | } | 366 | return TRUE; |
| 367 | 367 | ||
| 368 | // Subclause 7.4.1.2.5 | 368 | // Subclause 7.4.1.2.4 |
| 369 | if ( pLastSliceHeader->iRedundantPicCnt < pCurSliceHeader->iRedundantPicCnt ) | 369 | if (pLastSliceHeader->iFrameNum != pCurSliceHeader->iFrameNum) |
| 370 | return FALSE; | 370 | return TRUE; |
| 371 | else if ( pLastSliceHeader->iRedundantPicCnt > pCurSliceHeader->iRedundantPicCnt ) | 371 | if (pLastSliceHeader->iPpsId != pCurSliceHeader->iPpsId) |
| 372 | return TRUE; | 372 | return TRUE; |
| 373 | 373 | if (pLastSliceHeader->bFieldPicFlag != pCurSliceHeader->bFieldPicFlag) | |
| 374 | // Subclause G7.4.1.2.4 | 374 | return TRUE; |
| 375 | if ( pLastNalHdrExt->uiDependencyId < pCurNalHeaderExt->uiDependencyId ) | 375 | if (pLastSliceHeader->bBottomFiledFlag != pCurSliceHeader->bBottomFiledFlag) |
| 376 | return FALSE; | 376 | return TRUE; |
| 377 | else if ( pLastNalHdrExt->uiDependencyId > pCurNalHeaderExt->uiDependencyId ) | 377 | if ((pLastNalHdrExt->sNalUnitHeader.uiNalRefIdc != NRI_PRI_LOWEST) != (pCurNalHeaderExt->sNalUnitHeader.uiNalRefIdc != |
| 378 | return TRUE; | 378 | NRI_PRI_LOWEST)) |
| 379 | if ( pLastNalHdrExt->uiQualityId < pCurNalHeaderExt->uiQualityId ) | 379 | return TRUE; |
| 380 | return FALSE; | 380 | if (pLastNalHdrExt->bIdrFlag != pCurNalHeaderExt->bIdrFlag) |
| 381 | else if ( pLastNalHdrExt->uiQualityId > pCurNalHeaderExt->uiQualityId ) | 381 | return TRUE; |
| 382 | return TRUE; | 382 | if (pCurNalHeaderExt->bIdrFlag) { |
| 383 | 383 | if (pLastSliceHeader->uiIdrPicId != pCurSliceHeader->uiIdrPicId) | |
| 384 | // Subclause 7.4.1.2.4 | 384 | return TRUE; |
| 385 | if ( pLastSliceHeader->iFrameNum != pCurSliceHeader->iFrameNum ) | 385 | } |
| 386 | return TRUE; | 386 | if (kpSps->uiPocType == 0) { |
| 387 | if ( pLastSliceHeader->iPpsId != pCurSliceHeader->iPpsId ) | 387 | if (pLastSliceHeader->iPicOrderCntLsb != pCurSliceHeader->iPicOrderCntLsb) |
| 388 | return TRUE; | 388 | return TRUE; |
| 389 | if ( pLastSliceHeader->bFieldPicFlag != pCurSliceHeader->bFieldPicFlag ) | 389 | if (pLastSliceHeader->iDeltaPicOrderCntBottom != pCurSliceHeader->iDeltaPicOrderCntBottom) |
| 390 | return TRUE; | 390 | return TRUE; |
| 391 | if ( pLastSliceHeader->bBottomFiledFlag != pCurSliceHeader->bBottomFiledFlag ) | 391 | } else if (kpSps->uiPocType == 1) { |
| 392 | return TRUE; | 392 | if (pLastSliceHeader->iDeltaPicOrderCnt[0] != pCurSliceHeader->iDeltaPicOrderCnt[0]) |
| 393 | if ( (pLastNalHdrExt->sNalUnitHeader.uiNalRefIdc != NRI_PRI_LOWEST) != (pCurNalHeaderExt->sNalUnitHeader.uiNalRefIdc != NRI_PRI_LOWEST) ) | 393 | return TRUE; |
| 394 | return TRUE; | 394 | if (pLastSliceHeader->iDeltaPicOrderCnt[1] != pCurSliceHeader->iDeltaPicOrderCnt[1]) |
| 395 | if ( pLastNalHdrExt->bIdrFlag != pCurNalHeaderExt->bIdrFlag ) | 395 | return TRUE; |
| 396 | return TRUE; | 396 | } |
| 397 | if ( pCurNalHeaderExt->bIdrFlag ){ | 397 | |
| 398 | if ( pLastSliceHeader->uiIdrPicId != pCurSliceHeader->uiIdrPicId ) | 398 | return FALSE; |
| 399 | return TRUE; | 399 | } |
| 400 | } | 400 | |
| 401 | if ( kpSps->uiPocType == 0 ){ | 401 | |
| 402 | if ( pLastSliceHeader->iPicOrderCntLsb != pCurSliceHeader->iPicOrderCntLsb ) | 402 | bool_t CheckAccessUnitBoundary (const PNalUnit kpCurNal, const PNalUnit kpLastNal, const PSps kpSps) { |
| 403 | return TRUE; | 403 | const PNalUnitHeaderExt kpLastNalHeaderExt = &kpLastNal->sNalHeaderExt; |
| 404 | if ( pLastSliceHeader->iDeltaPicOrderCntBottom != pCurSliceHeader->iDeltaPicOrderCntBottom ) | 404 | const PNalUnitHeaderExt kpCurNalHeaderExt = &kpCurNal->sNalHeaderExt; |
| 405 | return TRUE; | 405 | const SSliceHeader* kpLastSliceHeader = &kpLastNal->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader; |
| 406 | } | 406 | const SSliceHeader* kpCurSliceHeader = &kpCurNal->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader; |
| 407 | else if ( kpSps->uiPocType == 1 ){ | 407 | |
| 408 | if ( pLastSliceHeader->iDeltaPicOrderCnt[0] != pCurSliceHeader->iDeltaPicOrderCnt[0] ) | 408 | //Sub-clause 7.1.4.1.1 temporal_id |
| 409 | return TRUE; | 409 | if (kpLastNalHeaderExt->uiTemporalId != kpCurNalHeaderExt->uiTemporalId) { |
| 410 | if ( pLastSliceHeader->iDeltaPicOrderCnt[1] != pCurSliceHeader->iDeltaPicOrderCnt[1] ) | 410 | return TRUE; |
| 411 | return TRUE; | 411 | } |
| 412 | } | 412 | |
| 413 | 413 | // Subclause 7.4.1.2.5 | |
| 414 | return FALSE; | 414 | if (kpLastSliceHeader->iRedundantPicCnt < kpCurSliceHeader->iRedundantPicCnt) |
| 415 | } | 415 | return FALSE; |
| 416 | 416 | else if (kpLastSliceHeader->iRedundantPicCnt > kpCurSliceHeader->iRedundantPicCnt) | |
| 417 | 417 | return TRUE; | |
| 418 | bool_t CheckAccessUnitBoundary( const PNalUnit kpCurNal, const PNalUnit kpLastNal, const PSps kpSps ) | 418 | |
| 419 | { | 419 | // Subclause G7.4.1.2.4 |
| 420 | const PNalUnitHeaderExt kpLastNalHeaderExt = &kpLastNal->sNalHeaderExt; | 420 | if (kpLastNalHeaderExt->uiDependencyId < kpCurNalHeaderExt->uiDependencyId) |
| 421 | const PNalUnitHeaderExt kpCurNalHeaderExt = &kpCurNal->sNalHeaderExt; | 421 | return FALSE; |
| 422 | const SSliceHeader *kpLastSliceHeader = &kpLastNal->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader; | 422 | else if (kpLastNalHeaderExt->uiDependencyId > kpCurNalHeaderExt->uiDependencyId) |
| 423 | const SSliceHeader *kpCurSliceHeader = &kpCurNal->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader; | 423 | return TRUE; |
| 424 | 424 | if (kpLastNalHeaderExt->uiQualityId < kpCurNalHeaderExt->uiQualityId) | |
| 425 | //Sub-clause 7.1.4.1.1 temporal_id | 425 | return FALSE; |
| 426 | if (kpLastNalHeaderExt->uiTemporalId != kpCurNalHeaderExt->uiTemporalId) { | 426 | else if (kpLastNalHeaderExt->uiQualityId > kpCurNalHeaderExt->uiQualityId) |
| 427 | return TRUE; | 427 | return TRUE; |
| 428 | } | 428 | |
| 429 | 429 | // Subclause 7.4.1.2.4 | |
| 430 | // Subclause 7.4.1.2.5 | 430 | if (kpLastSliceHeader->iFrameNum != kpCurSliceHeader->iFrameNum) |
| 431 | if ( kpLastSliceHeader->iRedundantPicCnt < kpCurSliceHeader->iRedundantPicCnt ) | 431 | return TRUE; |
| 432 | return FALSE; | 432 | if (kpLastSliceHeader->iPpsId != kpCurSliceHeader->iPpsId) |
| 433 | else if ( kpLastSliceHeader->iRedundantPicCnt > kpCurSliceHeader->iRedundantPicCnt ) | 433 | return TRUE; |
| 434 | return TRUE; | 434 | if (kpLastSliceHeader->bFieldPicFlag != kpCurSliceHeader->bFieldPicFlag) |
| 435 | 435 | return TRUE; | |
| 436 | // Subclause G7.4.1.2.4 | 436 | if (kpLastSliceHeader->bBottomFiledFlag != kpCurSliceHeader->bBottomFiledFlag) |
| 437 | if ( kpLastNalHeaderExt->uiDependencyId < kpCurNalHeaderExt->uiDependencyId ) | 437 | return TRUE; |
| 438 | return FALSE; | 438 | if ((kpLastNalHeaderExt->sNalUnitHeader.uiNalRefIdc != NRI_PRI_LOWEST) != (kpCurNalHeaderExt->sNalUnitHeader.uiNalRefIdc |
| 439 | else if ( kpLastNalHeaderExt->uiDependencyId > kpCurNalHeaderExt->uiDependencyId ) | 439 | != NRI_PRI_LOWEST)) |
| 440 | return TRUE; | 440 | return TRUE; |
| 441 | if ( kpLastNalHeaderExt->uiQualityId < kpCurNalHeaderExt->uiQualityId ) | 441 | if (kpLastNalHeaderExt->bIdrFlag != kpCurNalHeaderExt->bIdrFlag) |
| 442 | return FALSE; | 442 | return TRUE; |
| 443 | else if ( kpLastNalHeaderExt->uiQualityId > kpCurNalHeaderExt->uiQualityId ) | 443 | if (kpCurNalHeaderExt->bIdrFlag) { |
| 444 | return TRUE; | 444 | if (kpLastSliceHeader->uiIdrPicId != kpCurSliceHeader->uiIdrPicId) |
| 445 | 445 | return TRUE; | |
| 446 | // Subclause 7.4.1.2.4 | 446 | } |
| 447 | if ( kpLastSliceHeader->iFrameNum != kpCurSliceHeader->iFrameNum ) | 447 | if (kpSps->uiPocType == 0) { |
| 448 | return TRUE; | 448 | if (kpLastSliceHeader->iPicOrderCntLsb != kpCurSliceHeader->iPicOrderCntLsb) |
| 449 | if ( kpLastSliceHeader->iPpsId != kpCurSliceHeader->iPpsId ) | 449 | return TRUE; |
| 450 | return TRUE; | 450 | if (kpLastSliceHeader->iDeltaPicOrderCntBottom != kpCurSliceHeader->iDeltaPicOrderCntBottom) |
| 451 | if ( kpLastSliceHeader->bFieldPicFlag != kpCurSliceHeader->bFieldPicFlag ) | 451 | return TRUE; |
| 452 | return TRUE; | 452 | } else if (kpSps->uiPocType == 1) { |
| 453 | if ( kpLastSliceHeader->bBottomFiledFlag != kpCurSliceHeader->bBottomFiledFlag ) | 453 | if (kpLastSliceHeader->iDeltaPicOrderCnt[0] != kpCurSliceHeader->iDeltaPicOrderCnt[0]) |
| 454 | return TRUE; | 454 | return TRUE; |
| 455 | if ( (kpLastNalHeaderExt->sNalUnitHeader.uiNalRefIdc != NRI_PRI_LOWEST) != (kpCurNalHeaderExt->sNalUnitHeader.uiNalRefIdc != NRI_PRI_LOWEST) ) | 455 | if (kpLastSliceHeader->iDeltaPicOrderCnt[1] != kpCurSliceHeader->iDeltaPicOrderCnt[1]) |
| 456 | return TRUE; | 456 | return TRUE; |
| 457 | if ( kpLastNalHeaderExt->bIdrFlag != kpCurNalHeaderExt->bIdrFlag ) | 457 | } |
| 458 | return TRUE; | 458 | |
| 459 | if ( kpCurNalHeaderExt->bIdrFlag ){ | 459 | return FALSE; |
| 460 | if ( kpLastSliceHeader->uiIdrPicId != kpCurSliceHeader->uiIdrPicId ) | 460 | } |
| 461 | return TRUE; | 461 | |
| 462 | } | 462 | /*! |
| 463 | if ( kpSps->uiPocType == 0 ){ | 463 | ************************************************************************************* |
| 464 | if ( kpLastSliceHeader->iPicOrderCntLsb != kpCurSliceHeader->iPicOrderCntLsb ) | 464 | * \brief to parse NON VCL NAL Units |
| 465 | return TRUE; | 465 | * |
| 466 | if ( kpLastSliceHeader->iDeltaPicOrderCntBottom != kpCurSliceHeader->iDeltaPicOrderCntBottom ) | 466 | * \param pCtx decoder context |
| 467 | return TRUE; | 467 | * \param rbsp rbsp buffer of NAL Unit |
| 468 | } | 468 | * \param src_len length of rbsp buffer |
| 469 | else if ( kpSps->uiPocType == 1 ){ | 469 | * |
| 470 | if ( kpLastSliceHeader->iDeltaPicOrderCnt[0] != kpCurSliceHeader->iDeltaPicOrderCnt[0] ) | 470 | * \return 0 - successed |
| 471 | return TRUE; | 471 | * 1 - failed |
| 472 | if ( kpLastSliceHeader->iDeltaPicOrderCnt[1] != kpCurSliceHeader->iDeltaPicOrderCnt[1] ) | 472 | * |
| 473 | return TRUE; | 473 | ************************************************************************************* |
| 474 | } | 474 | */ |
| 475 | 475 | int32_t ParseNonVclNal (PWelsDecoderContext pCtx, uint8_t* pRbsp, const int32_t kiSrcLen) { | |
| 476 | return FALSE; | 476 | PBitStringAux pBs = NULL; |
| 477 | } | 477 | ENalUnitType eNalType = NAL_UNIT_UNSPEC_0; // make initial value as unspecified |
| 478 | 478 | int32_t iPicWidth = 0; | |
| 479 | /*! | 479 | int32_t iPicHeight = 0; |
| 480 | ************************************************************************************* | 480 | int32_t iBitSize = 0; |
| 481 | * \brief to parse NON VCL NAL Units | 481 | int32_t iErr = ERR_NONE; |
| 482 | * | 482 | |
| 483 | * \param pCtx decoder context | 483 | pBs = &pCtx->sBs; // SBitStringAux instance for non VCL NALs decoding |
| 484 | * \param rbsp rbsp buffer of NAL Unit | 484 | iBitSize = (kiSrcLen << 3) - BsGetTrailingBits (pRbsp + kiSrcLen - 1); // convert into bit |
| 485 | * \param src_len length of rbsp buffer | 485 | eNalType = pCtx->sCurNalHead.eNalUnitType; |
| 486 | * | 486 | |
| 487 | * \return 0 - successed | 487 | switch (eNalType) { |
| 488 | * 1 - failed | 488 | case NAL_UNIT_SPS: |
| 489 | * | 489 | case NAL_UNIT_SUBSET_SPS: |
| 490 | ************************************************************************************* | 490 | if (iBitSize > 0) |
| 491 | */ | 491 | InitBits (pBs, pRbsp, iBitSize); |
| 492 | int32_t ParseNonVclNal( PWelsDecoderContext pCtx, uint8_t *pRbsp, const int32_t kiSrcLen ) | 492 | #ifdef DEBUG_PARSE_INFO |
| 493 | { | 493 | WelsLog (pCtx, WELS_LOG_INFO, "parsing nal: %d \n", eNalType); |
| 494 | PBitStringAux pBs = NULL; | 494 | #endif |
| 495 | ENalUnitType eNalType = NAL_UNIT_UNSPEC_0; // make initial value as unspecified | 495 | iErr = ParseSps (pCtx, pBs, &iPicWidth, &iPicHeight); |
| 496 | int32_t iPicWidth = 0; | 496 | if (ERR_NONE != iErr) { // modified for pSps/pSubsetSps invalid, 12/1/2009 |
| 497 | int32_t iPicHeight = 0; | 497 | pCtx->iErrorCode |= dsNoParamSets; |
| 498 | int32_t iBitSize = 0; | 498 | return iErr; |
| 499 | int32_t iErr = ERR_NONE; | 499 | } |
| 500 | 500 | ||
| 501 | pBs = &pCtx->sBs; // SBitStringAux instance for non VCL NALs decoding | 501 | if (ERR_NONE == iErr) |
| 502 | iBitSize = (kiSrcLen<<3) - BsGetTrailingBits( pRbsp + kiSrcLen - 1 ); // convert into bit | 502 | UpdateMaxPictureResolution (pCtx, iPicWidth, iPicHeight); |
| 503 | eNalType = pCtx->sCurNalHead.eNalUnitType; | 503 | |
| 504 | 504 | break; | |
| 505 | switch( eNalType ) { | 505 | |
| 506 | case NAL_UNIT_SPS: | 506 | case NAL_UNIT_PPS: |
| 507 | case NAL_UNIT_SUBSET_SPS: | 507 | if (iBitSize > 0) |
| 508 | if ( iBitSize > 0 ) | 508 | InitBits (pBs, pRbsp, iBitSize); |
| 509 | InitBits( pBs, pRbsp, iBitSize ); | 509 | #ifdef DEBUG_PARSE_INFO |
| 510 | #ifdef DEBUG_PARSE_INFO | 510 | WelsLog (pCtx, WELS_LOG_INFO, "parsing nal: %d \n", eNalType); |
| 511 | WelsLog(pCtx, WELS_LOG_INFO, "parsing nal: %d \n", eNalType); | 511 | #endif |
| 512 | #endif | 512 | iErr = ParsePps (pCtx, &pCtx->sPpsBuffer[0], pBs); |
| 513 | iErr = ParseSps( pCtx, pBs, &iPicWidth, &iPicHeight ); | 513 | if (ERR_NONE != iErr) { // modified for pps invalid, 12/1/2009 |
| 514 | if ( ERR_NONE != iErr ) // modified for pSps/pSubsetSps invalid, 12/1/2009 | 514 | pCtx->iErrorCode |= dsNoParamSets; |
| 515 | { | 515 | return iErr; |
| 516 | pCtx->iErrorCode |= dsNoParamSets; | 516 | } |
| 517 | return iErr; | 517 | |
| 518 | } | 518 | pCtx->bPpsExistAheadFlag = true; |
| 519 | 519 | ||
| 520 | if ( ERR_NONE == iErr ) | 520 | break; |
| 521 | UpdateMaxPictureResolution( pCtx, iPicWidth, iPicHeight ); | 521 | |
| 522 | 522 | case NAL_UNIT_SEI: | |
| 523 | break; | 523 | |
| 524 | 524 | break; | |
| 525 | case NAL_UNIT_PPS: | 525 | |
| 526 | if ( iBitSize > 0 ) | 526 | case NAL_UNIT_PREFIX: |
| 527 | InitBits( pBs, pRbsp, iBitSize ); | 527 | break; |
| 528 | #ifdef DEBUG_PARSE_INFO | 528 | case NAL_UNIT_CODED_SLICE_DPA: |
| 529 | WelsLog(pCtx, WELS_LOG_INFO, "parsing nal: %d \n", eNalType); | 529 | case NAL_UNIT_CODED_SLICE_DPB: |
| 530 | #endif | 530 | case NAL_UNIT_CODED_SLICE_DPC: |
| 531 | iErr = ParsePps( pCtx, &pCtx->sPpsBuffer[0], pBs ); | 531 | |
| 532 | if ( ERR_NONE != iErr ) // modified for pps invalid, 12/1/2009 | 532 | break; |
| 533 | { | 533 | |
| 534 | pCtx->iErrorCode |= dsNoParamSets; | 534 | default: |
| 535 | return iErr; | 535 | break; |
| 536 | } | 536 | } |
| 537 | 537 | ||
| 538 | pCtx->bPpsExistAheadFlag = true; | 538 | return iErr; |
| 539 | 539 | } | |
| 540 | break; | 540 | |
| 541 | 541 | void_t ParseRefBasePicMarking (PBitStringAux pBs, PRefBasePicMarking pRefBasePicMarking) { | |
| 542 | case NAL_UNIT_SEI: | 542 | const bool_t kbAdaptiveMarkingModeFlag = !!BsGetOneBit (pBs); |
| 543 | 543 | pRefBasePicMarking->bAdaptiveRefBasePicMarkingModeFlag = kbAdaptiveMarkingModeFlag; | |
| 544 | break; | 544 | if (kbAdaptiveMarkingModeFlag) { |
| 545 | 545 | int32_t iIdx = 0; | |
| 546 | case NAL_UNIT_PREFIX: | 546 | do { |
| 547 | break; | 547 | const uint32_t kuiMmco = BsGetUe (pBs); |
| 548 | case NAL_UNIT_CODED_SLICE_DPA: | 548 | |
| 549 | case NAL_UNIT_CODED_SLICE_DPB: | 549 | pRefBasePicMarking->mmco_base[iIdx].uiMmcoType = kuiMmco; |
| 550 | case NAL_UNIT_CODED_SLICE_DPC: | 550 | |
| 551 | 551 | if (kuiMmco == MMCO_END) | |
| 552 | break; | 552 | break; |
| 553 | 553 | ||
| 554 | default: | 554 | if (kuiMmco == MMCO_SHORT2UNUSED) { |
| 555 | break; | 555 | pRefBasePicMarking->mmco_base[iIdx].uiDiffOfPicNums = 1 + BsGetUe (pBs); |
| 556 | } | 556 | pRefBasePicMarking->mmco_base[iIdx].iShortFrameNum = 0; |
| 557 | 557 | } else if (kuiMmco == MMCO_LONG2UNUSED) { | |
| 558 | return iErr; | 558 | pRefBasePicMarking->mmco_base[iIdx].uiLongTermPicNum = BsGetUe (pBs); |
| 559 | } | 559 | } |
| 560 | 560 | ++ iIdx; | |
| 561 | void_t ParseRefBasePicMarking ( PBitStringAux pBs, PRefBasePicMarking pRefBasePicMarking ) | 561 | } while (iIdx < MAX_MMCO_COUNT); |
| 562 | { | 562 | } |
| 563 | const bool_t kbAdaptiveMarkingModeFlag = !!BsGetOneBit( pBs ); | 563 | } |
| 564 | pRefBasePicMarking->bAdaptiveRefBasePicMarkingModeFlag = kbAdaptiveMarkingModeFlag; | 564 | |
| 565 | if ( kbAdaptiveMarkingModeFlag ){ | 565 | void_t ParsePrefixNalUnit (PWelsDecoderContext pCtx, PBitStringAux pBs) { |
| 566 | int32_t iIdx = 0; | 566 | PNalUnit pCurNal = &pCtx->sPrefixNal; |
| 567 | do { | 567 | |
| 568 | const uint32_t kuiMmco = BsGetUe( pBs ); | 568 | if (pCurNal->sNalHeaderExt.sNalUnitHeader.uiNalRefIdc != 0) { |
| 569 | 569 | PNalUnitHeaderExt head_ext = &pCurNal->sNalHeaderExt; | |
| 570 | pRefBasePicMarking->mmco_base[iIdx].uiMmcoType = kuiMmco; | 570 | PPrefixNalUnit sPrefixNal = &pCurNal->sNalData.sPrefixNal; |
| 571 | 571 | sPrefixNal->bStoreRefBasePicFlag = !!BsGetOneBit (pBs); | |
| 572 | if (kuiMmco == MMCO_END) | 572 | if ((head_ext->bUseRefBasePicFlag || sPrefixNal->bStoreRefBasePicFlag) && !head_ext->bIdrFlag) { |
| 573 | break; | 573 | ParseRefBasePicMarking (pBs, &sPrefixNal->sRefPicBaseMarking); |
| 574 | 574 | } | |
| 575 | if (kuiMmco == MMCO_SHORT2UNUSED){ | 575 | sPrefixNal->bPrefixNalUnitAdditionalExtFlag = !!BsGetOneBit (pBs); |
| 576 | pRefBasePicMarking->mmco_base[iIdx].uiDiffOfPicNums = 1 + BsGetUe( pBs ); | 576 | if (sPrefixNal->bPrefixNalUnitAdditionalExtFlag) { |
| 577 | pRefBasePicMarking->mmco_base[iIdx].iShortFrameNum = 0; | 577 | sPrefixNal->bPrefixNalUnitExtFlag = !!BsGetOneBit (pBs); |
| 578 | } | 578 | } |
| 579 | else if (kuiMmco == MMCO_LONG2UNUSED){ | 579 | } |
| 580 | pRefBasePicMarking->mmco_base[iIdx].uiLongTermPicNum = BsGetUe( pBs ); | 580 | } |
| 581 | } | 581 | |
| 582 | ++ iIdx; | 582 | |
| 583 | } while(iIdx < MAX_MMCO_COUNT); | 583 | int32_t DecodeSpsSvcExt (PWelsDecoderContext pCtx, PSubsetSps pSpsExt, PBitStringAux pBs) { |
| 584 | } | 584 | PSpsSvcExt pExt = NULL; |
| 585 | } | 585 | uint8_t uiChromaArrayType = 1; |
| 586 | 586 | ||
| 587 | void_t ParsePrefixNalUnit ( PWelsDecoderContext pCtx, PBitStringAux pBs ) | 587 | pExt = &pSpsExt->sSpsSvcExt; |
| 588 | { | 588 | |
| 589 | PNalUnit pCurNal = &pCtx->sPrefixNal; | 589 | pExt->bInterLayerDeblockingFilterCtrlPresentFlag = !!BsGetOneBit (pBs); |
| 590 | 590 | pExt->uiExtendedSpatialScalability = BsGetBits (pBs, 2); | |
| 591 | if ( pCurNal->sNalHeaderExt.sNalUnitHeader.uiNalRefIdc != 0 ){ | 591 | if (pExt->uiExtendedSpatialScalability > 2) { |
| 592 | PNalUnitHeaderExt head_ext = &pCurNal->sNalHeaderExt; | 592 | WelsLog (pCtx, WELS_LOG_WARNING, "DecodeSpsSvcExt():extended_spatial_scalability (%d) != 0, ESS not supported!\n", |
| 593 | PPrefixNalUnit sPrefixNal = &pCurNal->sNalData.sPrefixNal; | 593 | pExt->uiExtendedSpatialScalability); |
| 594 | sPrefixNal->bStoreRefBasePicFlag = !!BsGetOneBit( pBs ); | 594 | return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_INVALID_ESS); |
| 595 | if ( (head_ext->bUseRefBasePicFlag || sPrefixNal->bStoreRefBasePicFlag) && !head_ext->bIdrFlag ) | 595 | } |
| 596 | { | 596 | |
| 597 | ParseRefBasePicMarking ( pBs, &sPrefixNal->sRefPicBaseMarking ); | 597 | pExt->uiChromaPhaseXPlus1Flag = |
| 598 | } | 598 | 0; // FIXME: Incoherent with JVT X201 standard (= 1), but conformance to JSVM (= 0) implementation. |
| 599 | sPrefixNal->bPrefixNalUnitAdditionalExtFlag = !!BsGetOneBit( pBs ); | 599 | pExt->uiChromaPhaseYPlus1 = 1; |
| 600 | if ( sPrefixNal->bPrefixNalUnitAdditionalExtFlag ){ | 600 | uiChromaArrayType = pSpsExt->sSps.uiChromaArrayType; |
| 601 | sPrefixNal->bPrefixNalUnitExtFlag = !!BsGetOneBit( pBs ); | 601 | |
| 602 | } | 602 | pExt->uiChromaPhaseXPlus1Flag = BsGetOneBit (pBs); |
| 603 | } | 603 | pExt->uiChromaPhaseYPlus1 = BsGetBits (pBs, 2); |
| 604 | } | 604 | |
| 605 | 605 | pExt->uiSeqRefLayerChromaPhaseXPlus1Flag = pExt->uiChromaPhaseXPlus1Flag; | |
| 606 | 606 | pExt->uiSeqRefLayerChromaPhaseYPlus1 = pExt->uiChromaPhaseYPlus1; | |
| 607 | int32_t DecodeSpsSvcExt( PWelsDecoderContext pCtx, PSubsetSps pSpsExt, PBitStringAux pBs ) | 607 | memset (&pExt->sSeqScaledRefLayer, 0, sizeof (SPosOffset)); |
| 608 | { | 608 | |
| 609 | PSpsSvcExt pExt = NULL; | 609 | if (pExt->uiExtendedSpatialScalability == 1) { |
| 610 | uint8_t uiChromaArrayType = 1; | 610 | SPosOffset* const kpPos = &pExt->sSeqScaledRefLayer; |
| 611 | 611 | pExt->uiSeqRefLayerChromaPhaseXPlus1Flag = BsGetOneBit (pBs); | |
| 612 | pExt = &pSpsExt->sSpsSvcExt; | 612 | pExt->uiSeqRefLayerChromaPhaseYPlus1 = BsGetBits (pBs, 2); |
| 613 | 613 | ||
| 614 | pExt->bInterLayerDeblockingFilterCtrlPresentFlag = !!BsGetOneBit( pBs ); | 614 | kpPos->iLeftOffset = BsGetSe (pBs); |
| 615 | pExt->uiExtendedSpatialScalability = BsGetBits( pBs, 2 ); | 615 | kpPos->iTopOffset = BsGetSe (pBs); |
| 616 | if ( pExt->uiExtendedSpatialScalability > 2 ) | 616 | kpPos->iRightOffset = BsGetSe (pBs); |
| 617 | { | 617 | kpPos->iBottomOffset = BsGetSe (pBs); |
| 618 | WelsLog(pCtx, WELS_LOG_WARNING, "DecodeSpsSvcExt():extended_spatial_scalability (%d) != 0, ESS not supported!\n", pExt->uiExtendedSpatialScalability); | 618 | } |
| 619 | return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_INVALID_ESS); | 619 | |
| 620 | } | 620 | pExt->bSeqTCoeffLevelPredFlag = !!BsGetOneBit (pBs); |
| 621 | 621 | pExt->bAdaptiveTCoeffLevelPredFlag = false; | |
| 622 | pExt->uiChromaPhaseXPlus1Flag = 0; // FIXME: Incoherent with JVT X201 standard (= 1), but conformance to JSVM (= 0) implementation. | 622 | if (pExt->bSeqTCoeffLevelPredFlag) |
| 623 | pExt->uiChromaPhaseYPlus1 = 1; | 623 | pExt->bAdaptiveTCoeffLevelPredFlag = !!BsGetOneBit (pBs); |
| 624 | uiChromaArrayType = pSpsExt->sSps.uiChromaArrayType; | 624 | pExt->bSliceHeaderRestrictionFlag = !!BsGetOneBit (pBs); |
| 625 | 625 | ||
| 626 | pExt->uiChromaPhaseXPlus1Flag = BsGetOneBit( pBs ); | 626 | |
| 627 | pExt->uiChromaPhaseYPlus1 = BsGetBits( pBs, 2 ); | 627 | |
| 628 | 628 | return 0; | |
| 629 | pExt->uiSeqRefLayerChromaPhaseXPlus1Flag = pExt->uiChromaPhaseXPlus1Flag; | 629 | } |
| 630 | pExt->uiSeqRefLayerChromaPhaseYPlus1 = pExt->uiChromaPhaseYPlus1; | 630 | |
| 631 | memset(&pExt->sSeqScaledRefLayer, 0, sizeof(SPosOffset)); | 631 | /*! |
| 632 | 632 | ************************************************************************************* | |
| 633 | if ( pExt->uiExtendedSpatialScalability == 1 ){ | 633 | * \brief to parse Sequence Parameter Set (SPS) |
| 634 | SPosOffset* const kpPos = &pExt->sSeqScaledRefLayer; | 634 | * |
| 635 | pExt->uiSeqRefLayerChromaPhaseXPlus1Flag = BsGetOneBit( pBs ); | 635 | * \param pCtx Decoder context |
| 636 | pExt->uiSeqRefLayerChromaPhaseYPlus1 = BsGetBits( pBs, 2 ); | 636 | * \param pBsAux bitstream reader auxiliary |
| 637 | 637 | * \param pPicWidth picture width current Sps represented | |
| 638 | kpPos->iLeftOffset = BsGetSe( pBs ); | 638 | * \param pPicHeight picture height current Sps represented |
| 639 | kpPos->iTopOffset = BsGetSe( pBs ); | 639 | * |
| 640 | kpPos->iRightOffset = BsGetSe( pBs ); | 640 | * \return 0 - successed |
| 641 | kpPos->iBottomOffset= BsGetSe( pBs ); | 641 | * 1 - failed |
| 642 | } | 642 | * |
| 643 | 643 | * \note Call it in case eNalUnitType is SPS. | |
| 644 | pExt->bSeqTCoeffLevelPredFlag = !!BsGetOneBit( pBs ); | 644 | ************************************************************************************* |
| 645 | pExt->bAdaptiveTCoeffLevelPredFlag = false; | 645 | */ |
| 646 | if ( pExt->bSeqTCoeffLevelPredFlag ) | 646 | |
| 647 | pExt->bAdaptiveTCoeffLevelPredFlag = !!BsGetOneBit( pBs ); | 647 | |
| 648 | pExt->bSliceHeaderRestrictionFlag = !!BsGetOneBit( pBs ); | 648 | int32_t ParseSps (PWelsDecoderContext pCtx, PBitStringAux pBsAux, int32_t* pPicWidth, int32_t* pPicHeight) { |
| 649 | 649 | PBitStringAux pBs = pBsAux; | |
| 650 | 650 | PSps pSps = NULL; | |
| 651 | 651 | PSubsetSps pSubsetSps = NULL; | |
| 652 | return 0; | 652 | SNalUnitHeader* pNalHead = &pCtx->sCurNalHead; |
| 653 | } | 653 | ProfileIdc uiProfileIdc; |
| 654 | 654 | uint8_t uiLevelIdc; | |
| 655 | /*! | 655 | int32_t iSpsId; |
| 656 | ************************************************************************************* | 656 | bool_t bConstraintSetFlags[6] = { false }; |
| 657 | * \brief to parse Sequence Parameter Set (SPS) | 657 | const bool_t kbUseSubsetFlag = IS_SUBSET_SPS_NAL (pNalHead->eNalUnitType); |
| 658 | * | 658 | |
| 659 | * \param pCtx Decoder context | 659 | |
| 660 | * \param pBsAux bitstream reader auxiliary | 660 | if (kbUseSubsetFlag) { // SubsetSps |
| 661 | * \param pPicWidth picture width current Sps represented | 661 | pCtx->bSubspsExistAheadFlag = true; |
| 662 | * \param pPicHeight picture height current Sps represented | 662 | } else { // Sps |
| 663 | * | 663 | pCtx->bSpsExistAheadFlag = true; |
| 664 | * \return 0 - successed | 664 | |
| 665 | * 1 - failed | 665 | // added for EC, 10/28/2009 |
| 666 | * | 666 | // for safe |
| 667 | * \note Call it in case eNalUnitType is SPS. | 667 | memset (&pCtx->bSpsAvailFlags[0], 0, sizeof (pCtx->bSpsAvailFlags)); |
| 668 | ************************************************************************************* | 668 | memset (&pCtx->bSubspsAvailFlags[0], 0, sizeof (pCtx->bSubspsAvailFlags)); |
| 669 | */ | 669 | memset (&pCtx->bPpsAvailFlags[0], 0, sizeof (pCtx->bPpsAvailFlags)); |
| 670 | 670 | ||
| 671 | 671 | #ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 672 | int32_t ParseSps( PWelsDecoderContext pCtx, PBitStringAux pBsAux, int32_t *pPicWidth, int32_t *pPicHeight ) | 672 | pCtx->iSpsTotalNum = 0; |
| 673 | { | 673 | pCtx->iSubspsTotalNum = 0; |
| 674 | PBitStringAux pBs = pBsAux; | 674 | pCtx->iPpsTotalNum = 0; |
| 675 | PSps pSps = NULL; | 675 | #endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID |
| 676 | PSubsetSps pSubsetSps = NULL; | 676 | } |
| 677 | SNalUnitHeader *pNalHead= &pCtx->sCurNalHead; | 677 | |
| 678 | ProfileIdc uiProfileIdc; | 678 | uiProfileIdc = BsGetBits (pBs, 8); |
| 679 | uint8_t uiLevelIdc; | 679 | bConstraintSetFlags[0] = !!BsGetOneBit (pBs); // constraint_set0_flag |
| 680 | int32_t iSpsId; | 680 | bConstraintSetFlags[1] = !!BsGetOneBit (pBs); // constraint_set1_flag |
| 681 | bool_t bConstraintSetFlags[6] = { false }; | 681 | bConstraintSetFlags[2] = !!BsGetOneBit (pBs); // constraint_set2_flag |
| 682 | const bool_t kbUseSubsetFlag = IS_SUBSET_SPS_NAL(pNalHead->eNalUnitType); | 682 | bConstraintSetFlags[3] = !!BsGetOneBit (pBs); // constraint_set3_flag |
| 683 | 683 | bConstraintSetFlags[4] = !!BsGetOneBit (pBs); // constraint_set4_flag | |
| 684 | 684 | bConstraintSetFlags[5] = !!BsGetOneBit (pBs); // constraint_set5_flag | |
| 685 | if ( kbUseSubsetFlag ) // SubsetSps | 685 | BsGetBits (pBs, 2); // reserved_zero_2bits, equal to 0 |
| 686 | { | 686 | uiLevelIdc = BsGetBits (pBs, 8); // level_idc |
| 687 | pCtx->bSubspsExistAheadFlag = true; | 687 | |
| 688 | } | 688 | iSpsId = BsGetUe (pBs); // seq_parameter_set_id |
| 689 | else // Sps | 689 | |
| 690 | { | 690 | |
| 691 | pCtx->bSpsExistAheadFlag = true; | 691 | if (iSpsId >= MAX_SPS_COUNT || iSpsId < 0) { // Modified to check invalid negative iSpsId, 12/1/2009 |
| 692 | 692 | WelsLog (pCtx, WELS_LOG_WARNING, " iSpsId is out of range! \n"); | |
| 693 | // added for EC, 10/28/2009 | 693 | return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_SPS_ID_OVERFLOW); |
| 694 | // for safe | 694 | } |
| 695 | memset( &pCtx->bSpsAvailFlags[0], 0, sizeof(pCtx->bSpsAvailFlags) ); | 695 | |
| 696 | memset( &pCtx->bSubspsAvailFlags[0], 0, sizeof(pCtx->bSubspsAvailFlags) ); | 696 | if (kbUseSubsetFlag) { |
| 697 | memset( &pCtx->bPpsAvailFlags[0], 0, sizeof(pCtx->bPpsAvailFlags) ); | 697 | #ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID |
| 698 | 698 | pSubsetSps = &pCtx->sSubsetSpsBuffer[pCtx->iSubspsTotalNum]; | |
| 699 | #ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | 699 | pCtx->bSubspsAvailFlags[pCtx->iSubspsTotalNum] = true; |
| 700 | pCtx->iSpsTotalNum = 0; | 700 | |
| 701 | pCtx->iSubspsTotalNum = 0; | 701 | pSubsetSps->sSps.iSpsId = iSpsId; |
| 702 | pCtx->iPpsTotalNum = 0; | 702 | pSps = &pSubsetSps->sSps; |
| 703 | #endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | 703 | ++pCtx->iSubspsTotalNum; |
| 704 | } | 704 | #else |
| 705 | 705 | pSubsetSps = &pCtx->sSubsetSpsBuffer[iSpsId]; | |
| 706 | uiProfileIdc = BsGetBits( pBs, 8 ); | 706 | pSps = &pSubsetSps->sSps; |
| 707 | bConstraintSetFlags[0] = !!BsGetOneBit( pBs ); // constraint_set0_flag | 707 | pCtx->bSubspsAvailFlags[iSpsId] = true; // added for EC, 10/28/2009 |
| 708 | bConstraintSetFlags[1] = !!BsGetOneBit( pBs ); // constraint_set1_flag | 708 | #endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID |
| 709 | bConstraintSetFlags[2] = !!BsGetOneBit( pBs ); // constraint_set2_flag | 709 | } else { |
| 710 | bConstraintSetFlags[3] = !!BsGetOneBit( pBs ); // constraint_set3_flag | 710 | #ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID |
| 711 | bConstraintSetFlags[4] = !!BsGetOneBit( pBs ); // constraint_set4_flag | 711 | pSps = &pCtx->sSpsBuffer[pCtx->iSpsTotalNum]; |
| 712 | bConstraintSetFlags[5] = !!BsGetOneBit( pBs ); // constraint_set5_flag | 712 | pCtx->bSpsAvailFlags[pCtx->iSpsTotalNum] = true; |
| 713 | BsGetBits( pBs, 2 ); // reserved_zero_2bits, equal to 0 | 713 | |
| 714 | uiLevelIdc = BsGetBits( pBs, 8 ); // level_idc | 714 | pSps->iSpsId = iSpsId; |
| 715 | 715 | ++pCtx->iSpsTotalNum; | |
| 716 | iSpsId = BsGetUe( pBs ); // seq_parameter_set_id | 716 | #else |
| 717 | 717 | pSps = &pCtx->sSpsBuffer[iSpsId]; | |
| 718 | 718 | pCtx->bSpsAvailFlags[iSpsId] = true; // added for EC, 10/28/2009 | |
| 719 | if ( iSpsId >= MAX_SPS_COUNT || iSpsId < 0 ) // Modified to check invalid negative iSpsId, 12/1/2009 | 719 | #endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID |
| 720 | { | 720 | } |
| 721 | WelsLog( pCtx, WELS_LOG_WARNING, " iSpsId is out of range! \n"); | 721 | |
| 722 | return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_SPS_ID_OVERFLOW); | 722 | // syntax elements in default |
| 723 | } | 723 | pSps->uiChromaFormatIdc = 1; |
| 724 | 724 | pSps->uiBitDepthLuma = | |
| 725 | if ( kbUseSubsetFlag ) | 725 | pSps->uiBitDepthChroma = 8; |
| 726 | { | 726 | |
| 727 | #ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | 727 | pSps->uiProfileIdc = uiProfileIdc; |
| 728 | pSubsetSps = &pCtx->sSubsetSpsBuffer[pCtx->iSubspsTotalNum]; | 728 | pSps->uiLevelIdc = uiLevelIdc; |
| 729 | pCtx->bSubspsAvailFlags[pCtx->iSubspsTotalNum] = true; | 729 | pSps->iSpsId = iSpsId; |
| 730 | 730 | ||
| 731 | pSubsetSps->sSps.iSpsId = iSpsId; | 731 | if (PRO_SCALABLE_BASELINE == uiProfileIdc || PRO_SCALABLE_HIGH == uiProfileIdc || |
| 732 | pSps = &pSubsetSps->sSps; | 732 | PRO_HIGH == uiProfileIdc || PRO_HIGH10 == uiProfileIdc || |
| 733 | ++pCtx->iSubspsTotalNum; | 733 | PRO_HIGH422 == uiProfileIdc || PRO_HIGH444 == uiProfileIdc || |
| 734 | #else | 734 | PRO_CAVLC444 == uiProfileIdc || 44 == uiProfileIdc) { |
| 735 | pSubsetSps = &pCtx->sSubsetSpsBuffer[iSpsId]; | 735 | |
| 736 | pSps = &pSubsetSps->sSps; | 736 | pSps->uiChromaFormatIdc = BsGetUe (pBs); |
| 737 | pCtx->bSubspsAvailFlags[iSpsId] = true; // added for EC, 10/28/2009 | 737 | if (pSps->uiChromaFormatIdc != 1) { |
| 738 | #endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | 738 | WelsLog (pCtx, WELS_LOG_WARNING, "ParseSps(): chroma_format_idc (%d) = 1 supported.\n", pSps->uiChromaFormatIdc); |
| 739 | } | 739 | return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_NON_BASELINE); |
| 740 | else | 740 | } |
| 741 | { | 741 | pSps->uiChromaArrayType = pSps->uiChromaFormatIdc; |
| 742 | #ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | 742 | pSps->uiBitDepthLuma = 8 + BsGetUe (pBs); |
| 743 | pSps = &pCtx->sSpsBuffer[pCtx->iSpsTotalNum]; | 743 | if (pSps->uiBitDepthLuma != 8) { |
| 744 | pCtx->bSpsAvailFlags[pCtx->iSpsTotalNum] = true; | 744 | WelsLog (pCtx, WELS_LOG_WARNING, "ParseSps(): bit_depth_luma (%d) Only 8 bit supported.\n", pSps->uiBitDepthLuma); |
| 745 | 745 | return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_NON_BASELINE); | |
| 746 | pSps->iSpsId = iSpsId; | 746 | } |
| 747 | ++pCtx->iSpsTotalNum; | 747 | |
| 748 | #else | 748 | pSps->uiBitDepthChroma = 8 + BsGetUe (pBs); |
| 749 | pSps = &pCtx->sSpsBuffer[iSpsId]; | 749 | if (pSps->uiBitDepthChroma != 8) { |
| 750 | pCtx->bSpsAvailFlags[iSpsId] = true; // added for EC, 10/28/2009 | 750 | WelsLog (pCtx, WELS_LOG_WARNING, "ParseSps(): bit_depth_chroma (%d). Only 8 bit supported.\n", pSps->uiBitDepthChroma); |
| 751 | #endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | 751 | return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_NON_BASELINE); |
| 752 | } | 752 | } |
| 753 | 753 | pSps->bQpPrimeYZeroTransfBypassFlag = !!BsGetOneBit (pBs); | |
| 754 | // syntax elements in default | 754 | pSps->bSeqScalingMatrixPresentFlag = !!BsGetOneBit (pBs); |
| 755 | pSps->uiChromaFormatIdc = 1; | 755 | |
| 756 | pSps->uiBitDepthLuma = | 756 | if (pSps->bSeqScalingMatrixPresentFlag) { // For high profile, it is not used in current application. FIXME |
| 757 | pSps->uiBitDepthChroma = 8; | 757 | WelsLog (pCtx, WELS_LOG_WARNING, "ParseSps(): seq_scaling_matrix_present_flag (%d). Feature not supported.\n", |
| 758 | 758 | pSps->bSeqScalingMatrixPresentFlag); | |
| 759 | pSps->uiProfileIdc = uiProfileIdc; | 759 | return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_NON_BASELINE); |
| 760 | pSps->uiLevelIdc = uiLevelIdc; | 760 | } |
| 761 | pSps->iSpsId = iSpsId; | 761 | } |
| 762 | 762 | ||
| 763 | if ( PRO_SCALABLE_BASELINE == uiProfileIdc || PRO_SCALABLE_HIGH == uiProfileIdc || | 763 | pSps->uiLog2MaxFrameNum = 4 + BsGetUe (pBs); // log2_max_frame_num_minus4 |
| 764 | PRO_HIGH == uiProfileIdc || PRO_HIGH10 == uiProfileIdc || | 764 | pSps->uiPocType = BsGetUe (pBs); // pic_order_cnt_type |
| 765 | PRO_HIGH422 == uiProfileIdc || PRO_HIGH444 == uiProfileIdc || | 765 | |
| 766 | PRO_CAVLC444 == uiProfileIdc || 44 == uiProfileIdc ){ | 766 | if (0 == pSps->uiPocType) { |
| 767 | 767 | pSps->iLog2MaxPocLsb = 4 + BsGetUe (pBs); // log2_max_pic_order_cnt_lsb_minus4 | |
| 768 | pSps->uiChromaFormatIdc = BsGetUe( pBs ); | 768 | |
| 769 | if( pSps->uiChromaFormatIdc != 1 ) | 769 | } else if (1 == pSps->uiPocType) { |
| 770 | { | 770 | int32_t i; |
| 771 | WelsLog( pCtx, WELS_LOG_WARNING, "ParseSps(): chroma_format_idc (%d) = 1 supported.\n", pSps->uiChromaFormatIdc); | 771 | pSps->bDeltaPicOrderAlwaysZeroFlag = !!BsGetOneBit (pBs); // bDeltaPicOrderAlwaysZeroFlag |
| 772 | return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_NON_BASELINE); | 772 | pSps->iOffsetForNonRefPic = BsGetSe (pBs); // iOffsetForNonRefPic |
| 773 | } | 773 | pSps->iOffsetForTopToBottomField = BsGetSe (pBs); // iOffsetForTopToBottomField |
| 774 | pSps->uiChromaArrayType = pSps->uiChromaFormatIdc; | 774 | pSps->iNumRefFramesInPocCycle = BsGetUe (pBs); // num_ref_frames_in_pic_order_cnt_cycle |
| 775 | pSps->uiBitDepthLuma = 8 + BsGetUe( pBs ); | 775 | for (i = 0; i < pSps->iNumRefFramesInPocCycle; i++) |
| 776 | if( pSps->uiBitDepthLuma != 8 ) | 776 | pSps->iOffsetForRefFrame[ i ] = BsGetSe (pBs); // iOffsetForRefFrame[ i ] |
| 777 | { | 777 | } |
| 778 | WelsLog( pCtx, WELS_LOG_WARNING, "ParseSps(): bit_depth_luma (%d) Only 8 bit supported.\n", pSps->uiBitDepthLuma); | 778 | if (pSps->uiPocType > 2) { |
| 779 | return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_NON_BASELINE); | 779 | WelsLog (pCtx, WELS_LOG_WARNING, " illegal pic_order_cnt_type: %d ! \n", pSps->uiPocType); |
| 780 | } | 780 | return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_INVALID_POC_TYPE); |
| 781 | 781 | } | |
| 782 | pSps->uiBitDepthChroma = 8 + BsGetUe( pBs ); | 782 | |
| 783 | if( pSps->uiBitDepthChroma != 8 ) | 783 | pSps->iNumRefFrames = BsGetUe (pBs); // max_num_ref_frames |
| 784 | { | 784 | pSps->bGapsInFrameNumValueAllowedFlag = !!BsGetOneBit (pBs); // bGapsInFrameNumValueAllowedFlag |
| 785 | WelsLog( pCtx, WELS_LOG_WARNING, "ParseSps(): bit_depth_chroma (%d). Only 8 bit supported.\n", pSps->uiBitDepthChroma); | 785 | pSps->iMbWidth = 1 + BsGetUe (pBs); // pic_width_in_mbs_minus1 |
| 786 | return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_NON_BASELINE); | 786 | pSps->iMbHeight = 1 + BsGetUe (pBs); // pic_height_in_map_units_minus1 |
| 787 | } | 787 | pSps->uiTotalMbCount = pSps->iMbWidth * pSps->iMbHeight; |
| 788 | pSps->bQpPrimeYZeroTransfBypassFlag = !!BsGetOneBit( pBs ); | 788 | pSps->bFrameMbsOnlyFlag = !!BsGetOneBit (pBs); // frame_mbs_only_flag |
| 789 | pSps->bSeqScalingMatrixPresentFlag = !!BsGetOneBit( pBs ); | 789 | |
| 790 | 790 | if (!pSps->bFrameMbsOnlyFlag) { | |
| 791 | if ( pSps->bSeqScalingMatrixPresentFlag ){ // For high profile, it is not used in current application. FIXME | 791 | WelsLog (pCtx, WELS_LOG_WARNING, "ParseSps(): frame_mbs_only_flag (%d) not supported.\n", pSps->bFrameMbsOnlyFlag); |
| 792 | WelsLog( pCtx, WELS_LOG_WARNING, "ParseSps(): seq_scaling_matrix_present_flag (%d). Feature not supported.\n", pSps->bSeqScalingMatrixPresentFlag); | 792 | return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_MBAFF); |
| 793 | return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_NON_BASELINE); | 793 | } |
| 794 | } | 794 | pSps->bDirect8x8InferenceFlag = !!BsGetOneBit (pBs); // direct_8x8_inference_flag |
| 795 | } | 795 | pSps->bFrameCroppingFlag = !!BsGetOneBit (pBs); // frame_cropping_flag |
| 796 | 796 | if (pSps->bFrameCroppingFlag) { | |
| 797 | pSps->uiLog2MaxFrameNum = 4 + BsGetUe( pBs ); // log2_max_frame_num_minus4 | 797 | pSps->sFrameCrop.iLeftOffset = BsGetUe (pBs); // frame_crop_left_offset |
| 798 | pSps->uiPocType = BsGetUe( pBs ); // pic_order_cnt_type | 798 | pSps->sFrameCrop.iRightOffset = BsGetUe (pBs); // frame_crop_right_offset |
| 799 | 799 | pSps->sFrameCrop.iTopOffset = BsGetUe (pBs); // frame_crop_top_offset | |
| 800 | if ( 0 == pSps->uiPocType ) | 800 | pSps->sFrameCrop.iBottomOffset = BsGetUe (pBs); // frame_crop_bottom_offset |
| 801 | { | 801 | } else { |
| 802 | pSps->iLog2MaxPocLsb = 4 + BsGetUe( pBs ); // log2_max_pic_order_cnt_lsb_minus4 | 802 | pSps->sFrameCrop.iLeftOffset = 0; // frame_crop_left_offset |
| 803 | 803 | pSps->sFrameCrop.iRightOffset = 0; // frame_crop_right_offset | |
| 804 | } | 804 | pSps->sFrameCrop.iTopOffset = 0; // frame_crop_top_offset |
| 805 | else if ( 1 == pSps->uiPocType ) | 805 | pSps->sFrameCrop.iBottomOffset = 0; // frame_crop_bottom_offset |
| 806 | { | 806 | } |
| 807 | int32_t i; | 807 | pSps->bVuiParamPresentFlag = !!BsGetOneBit (pBs); // vui_parameters_present_flag |
| 808 | pSps->bDeltaPicOrderAlwaysZeroFlag = !!BsGetOneBit( pBs ); // bDeltaPicOrderAlwaysZeroFlag | 808 | |
| 809 | pSps->iOffsetForNonRefPic = BsGetSe( pBs ); // iOffsetForNonRefPic | 809 | // Check if SPS SVC extension applicated |
| 810 | pSps->iOffsetForTopToBottomField = BsGetSe( pBs ); // iOffsetForTopToBottomField | 810 | if (kbUseSubsetFlag && (PRO_SCALABLE_BASELINE == uiProfileIdc || PRO_SCALABLE_HIGH == uiProfileIdc)) { |
| 811 | pSps->iNumRefFramesInPocCycle = BsGetUe( pBs ); // num_ref_frames_in_pic_order_cnt_cycle | 811 | if (DecodeSpsSvcExt (pCtx, pSubsetSps, pBs) != ERR_NONE) { |
| 812 | for( i = 0; i < pSps->iNumRefFramesInPocCycle; i++ ) | 812 | return -1; |
| 813 | pSps->iOffsetForRefFrame[ i ] = BsGetSe( pBs ); // iOffsetForRefFrame[ i ] | 813 | } |
| 814 | } | 814 | |
| 815 | if ( pSps->uiPocType > 2 ) | 815 | pSubsetSps->bSvcVuiParamPresentFlag = !!BsGetOneBit (pBs); |
| 816 | { | 816 | if (pSubsetSps->bSvcVuiParamPresentFlag) { |
| 817 | WelsLog( pCtx, WELS_LOG_WARNING, " illegal pic_order_cnt_type: %d ! \n", pSps->uiPocType ); | 817 | } |
| 818 | return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_INVALID_POC_TYPE); | 818 | } |
| 819 | } | 819 | |
| 820 | 820 | ||
| 821 | pSps->iNumRefFrames = BsGetUe( pBs ); // max_num_ref_frames | 821 | if (PRO_SCALABLE_BASELINE == uiProfileIdc || PRO_SCALABLE_HIGH == uiProfileIdc) |
| 822 | pSps->bGapsInFrameNumValueAllowedFlag = !!BsGetOneBit( pBs ); // bGapsInFrameNumValueAllowedFlag | 822 | pCtx->bAvcBasedFlag = false; |
| 823 | pSps->iMbWidth = 1 + BsGetUe( pBs ); // pic_width_in_mbs_minus1 | 823 | else |
| 824 | pSps->iMbHeight = 1 + BsGetUe( pBs ); // pic_height_in_map_units_minus1 | 824 | pCtx->bAvcBasedFlag = true; // added for avc base pBs |
| 825 | pSps->uiTotalMbCount = pSps->iMbWidth * pSps->iMbHeight; | 825 | |
| 826 | pSps->bFrameMbsOnlyFlag = !!BsGetOneBit( pBs ); // frame_mbs_only_flag | 826 | *pPicWidth = pSps->iMbWidth << 4; |
| 827 | 827 | *pPicHeight = pSps->iMbHeight << 4; | |
| 828 | if ( !pSps->bFrameMbsOnlyFlag ) | 828 | |
| 829 | { | 829 | return 0; |
| 830 | WelsLog( pCtx, WELS_LOG_WARNING, "ParseSps(): frame_mbs_only_flag (%d) not supported.\n", pSps->bFrameMbsOnlyFlag); | 830 | } |
| 831 | return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_MBAFF); | 831 | |
| 832 | } | 832 | /*! |
| 833 | pSps->bDirect8x8InferenceFlag = !!BsGetOneBit( pBs ); // direct_8x8_inference_flag | 833 | ************************************************************************************* |
| 834 | pSps->bFrameCroppingFlag = !!BsGetOneBit( pBs ); // frame_cropping_flag | 834 | * \brief to parse Picture Parameter Set (PPS) |
| 835 | if ( pSps->bFrameCroppingFlag ) | 835 | * |
| 836 | { | 836 | * \param pCtx Decoder context |
| 837 | pSps->sFrameCrop.iLeftOffset = BsGetUe( pBs ); // frame_crop_left_offset | 837 | * \param pPpsList pps list |
| 838 | pSps->sFrameCrop.iRightOffset = BsGetUe( pBs ); // frame_crop_right_offset | 838 | * \param pBsAux bitstream reader auxiliary |
| 839 | pSps->sFrameCrop.iTopOffset = BsGetUe( pBs ); // frame_crop_top_offset | 839 | * |
| 840 | pSps->sFrameCrop.iBottomOffset = BsGetUe( pBs ); // frame_crop_bottom_offset | 840 | * \return 0 - successed |
| 841 | } | 841 | * 1 - failed |
| 842 | else | 842 | * |
| 843 | { | 843 | * \note Call it in case eNalUnitType is PPS. |
| 844 | pSps->sFrameCrop.iLeftOffset = 0; // frame_crop_left_offset | 844 | ************************************************************************************* |
| 845 | pSps->sFrameCrop.iRightOffset = 0; // frame_crop_right_offset | 845 | */ |
| 846 | pSps->sFrameCrop.iTopOffset = 0; // frame_crop_top_offset | 846 | int32_t ParsePps (PWelsDecoderContext pCtx, PPps pPpsList, PBitStringAux pBsAux) { |
| 847 | pSps->sFrameCrop.iBottomOffset = 0; // frame_crop_bottom_offset | 847 | |
| 848 | } | 848 | PPps pPps = NULL; |
| 849 | pSps->bVuiParamPresentFlag = !!BsGetOneBit( pBs ); // vui_parameters_present_flag | 849 | uint32_t uiPpsId = 0; |
| 850 | 850 | uint32_t iTmp; | |
| 851 | // Check if SPS SVC extension applicated | 851 | |
| 852 | if ( kbUseSubsetFlag && ( PRO_SCALABLE_BASELINE == uiProfileIdc || PRO_SCALABLE_HIGH == uiProfileIdc ) ) | 852 | uiPpsId = BsGetUe (pBsAux); |
| 853 | { | 853 | if (uiPpsId >= MAX_PPS_COUNT) { |
| 854 | if ( DecodeSpsSvcExt( pCtx, pSubsetSps, pBs ) != ERR_NONE ){ | 854 | return ERR_INFO_PPS_ID_OVERFLOW; |
| 855 | return -1; | 855 | } |
| 856 | } | 856 | |
| 857 | 857 | #ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | |
| 858 | pSubsetSps->bSvcVuiParamPresentFlag = !!BsGetOneBit( pBs ); | 858 | pPps = &pPpsList[pCtx->iPpsTotalNum]; |
| 859 | if ( pSubsetSps->bSvcVuiParamPresentFlag ){ | 859 | #else |
| 860 | } | 860 | pPps = &pPpsList[uiPpsId]; |
| 861 | } | 861 | #endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID |
| 862 | 862 | ||
| 863 | 863 | ||
| 864 | if ( PRO_SCALABLE_BASELINE == uiProfileIdc || PRO_SCALABLE_HIGH == uiProfileIdc ) | 864 | pPps->iPpsId = uiPpsId; |
| 865 | pCtx->bAvcBasedFlag = false; | 865 | pPps->iSpsId = BsGetUe (pBsAux); |
| 866 | else | 866 | |
| 867 | pCtx->bAvcBasedFlag = true; // added for avc base pBs | 867 | if (pPps->iSpsId >= MAX_SPS_COUNT) { |
| 868 | 868 | return ERR_INFO_SPS_ID_OVERFLOW; | |
| 869 | *pPicWidth = pSps->iMbWidth << 4; | 869 | } |
| 870 | *pPicHeight = pSps->iMbHeight << 4; | 870 | |
| 871 | 871 | pPps->bEntropyCodingModeFlag = !!BsGetOneBit (pBsAux); | |
| 872 | return 0; | 872 | pPps->bPicOrderPresentFlag = !!BsGetOneBit (pBsAux); |
| 873 | } | 873 | |
| 874 | 874 | pPps->uiNumSliceGroups = 1 + BsGetUe (pBsAux); | |
| 875 | /*! | 875 | |
| 876 | ************************************************************************************* | 876 | if (pPps->uiNumSliceGroups > MAX_SLICEGROUP_IDS) { |
| 877 | * \brief to parse Picture Parameter Set (PPS) | 877 | return ERR_INFO_INVALID_SLICEGROUP; |
| 878 | * | 878 | } |
| 879 | * \param pCtx Decoder context | 879 | |
| 880 | * \param pPpsList pps list | 880 | if (pPps->uiNumSliceGroups > 1) { |
| 881 | * \param pBsAux bitstream reader auxiliary | 881 | pPps->uiSliceGroupMapType = BsGetUe (pBsAux); |
| 882 | * | 882 | if (pPps->uiSliceGroupMapType > 1) { |
| 883 | * \return 0 - successed | 883 | WelsLog (pCtx, WELS_LOG_WARNING, "ParsePps(): slice_group_map_type (%d): support only 0,1.\n", |
| 884 | * 1 - failed | 884 | pPps->uiSliceGroupMapType); |
| 885 | * | 885 | return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_FMOTYPE); |
| 886 | * \note Call it in case eNalUnitType is PPS. | 886 | } |
| 887 | ************************************************************************************* | 887 | |
| 888 | */ | 888 | switch (pPps->uiSliceGroupMapType) { |
| 889 | int32_t ParsePps( PWelsDecoderContext pCtx, PPps pPpsList, PBitStringAux pBsAux ) | 889 | case 0: |
| 890 | { | 890 | for (iTmp = 0; iTmp < pPps->uiNumSliceGroups; iTmp++) { |
| 891 | 891 | pPps->uiRunLength[iTmp] = 1 + BsGetUe (pBsAux); | |
| 892 | PPps pPps = NULL; | 892 | } |
| 893 | uint32_t uiPpsId = 0; | 893 | break; |
| 894 | uint32_t iTmp; | 894 | default: |
| 895 | 895 | break; | |
| 896 | uiPpsId = BsGetUe(pBsAux); | 896 | } |
| 897 | if ( uiPpsId >= MAX_PPS_COUNT ) | 897 | } |
| 898 | { | 898 | |
| 899 | return ERR_INFO_PPS_ID_OVERFLOW; | 899 | pPps->uiNumRefIdxL0Active = 1 + BsGetUe (pBsAux); |
| 900 | } | 900 | pPps->uiNumRefIdxL1Active = 1 + BsGetUe (pBsAux); |
| 901 | 901 | ||
| 902 | #ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | 902 | if (pPps->uiNumRefIdxL0Active > MAX_REF_PIC_COUNT || |
| 903 | pPps = &pPpsList[pCtx->iPpsTotalNum]; | 903 | pPps->uiNumRefIdxL1Active > MAX_REF_PIC_COUNT) { |
| 904 | #else | 904 | return ERR_INFO_REF_COUNT_OVERFLOW; |
| 905 | pPps = &pPpsList[uiPpsId]; | 905 | } |
| 906 | #endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | 906 | |
| 907 | 907 | pPps->bWeightedPredFlag = !!BsGetOneBit (pBsAux); | |
| 908 | 908 | pPps->uiWeightedBipredIdc = BsGetBits (pBsAux, 2); | |
| 909 | pPps->iPpsId = uiPpsId; | 909 | if (pPps->bWeightedPredFlag || pPps->uiWeightedBipredIdc != 0) { |
| 910 | pPps->iSpsId = BsGetUe(pBsAux); | 910 | WelsLog (pCtx, WELS_LOG_WARNING, "ParsePps(): weighted_pred_flag (%d) weighted_bipred_idc (%d) neither supported.\n", |
| 911 | 911 | pPps->bWeightedPredFlag, pPps->uiWeightedBipredIdc); | |
| 912 | if (pPps->iSpsId >= MAX_SPS_COUNT) | 912 | return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_WP); |
| 913 | { | 913 | } |
| 914 | return ERR_INFO_SPS_ID_OVERFLOW; | 914 | |
| 915 | } | 915 | pPps->iPicInitQp = 26 + BsGetSe (pBsAux); |
| 916 | 916 | pPps->iPicInitQs = 26 + BsGetSe (pBsAux); | |
| 917 | pPps->bEntropyCodingModeFlag = !!BsGetOneBit(pBsAux); | 917 | |
| 918 | pPps->bPicOrderPresentFlag = !!BsGetOneBit(pBsAux); | 918 | pPps->iChromaQpIndexOffset = BsGetSe (pBsAux); |
| 919 | 919 | pPps->bDeblockingFilterControlPresentFlag = !!BsGetOneBit (pBsAux); | |
| 920 | pPps->uiNumSliceGroups = 1 + BsGetUe(pBsAux); | 920 | pPps->bConstainedIntraPredFlag = !!BsGetOneBit (pBsAux); |
| 921 | 921 | pPps->bRedundantPicCntPresentFlag = !!BsGetOneBit (pBsAux); | |
| 922 | if (pPps->uiNumSliceGroups > MAX_SLICEGROUP_IDS) | 922 | |
| 923 | { | 923 | |
| 924 | return ERR_INFO_INVALID_SLICEGROUP; | 924 | #ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID |
| 925 | } | 925 | pCtx->bPpsAvailFlags[pCtx->iPpsTotalNum] = true; |
| 926 | 926 | ++pCtx->iPpsTotalNum; | |
| 927 | if (pPps->uiNumSliceGroups > 1) | 927 | #else |
| 928 | { | 928 | pCtx->bPpsAvailFlags[uiPpsId] = true; // added for EC, 10/28/2009 |
| 929 | pPps->uiSliceGroupMapType = BsGetUe(pBsAux); | 929 | #endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID |
| 930 | if( pPps->uiSliceGroupMapType > 1) | 930 | |
| 931 | { | 931 | return ERR_NONE; |
| 932 | WelsLog( pCtx, WELS_LOG_WARNING, "ParsePps(): slice_group_map_type (%d): support only 0,1.\n", pPps->uiSliceGroupMapType); | 932 | } |
| 933 | return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_FMOTYPE); | 933 | |
| 934 | } | 934 | /*! |
| 935 | 935 | ************************************************************************************* | |
| 936 | switch(pPps->uiSliceGroupMapType) | 936 | * \brief to parse SEI message payload |
| 937 | { | 937 | * |
| 938 | case 0: | 938 | * \param pSei sei message to be parsed output |
| 939 | for (iTmp = 0; iTmp < pPps->uiNumSliceGroups; iTmp++) | 939 | * \param pBsAux bitstream reader auxiliary |
| 940 | { | 940 | * |
| 941 | pPps->uiRunLength[iTmp] = 1 + BsGetUe(pBsAux); | 941 | * \return 0 - successed |
| 942 | } | 942 | * 1 - failed |
| 943 | break; | 943 | * |
| 944 | default: | 944 | * \note Call it in case eNalUnitType is NAL_UNIT_SEI. |
| 945 | break; | 945 | ************************************************************************************* |
| 946 | } | 946 | */ |
| 947 | } | 947 | int32_t ParseSei (void_t* pSei, PBitStringAux pBsAux) { // reserved Sei_Msg type |
| 948 | 948 | ||
| 949 | pPps->uiNumRefIdxL0Active = 1 + BsGetUe(pBsAux); | 949 | |
| 950 | pPps->uiNumRefIdxL1Active = 1 + BsGetUe(pBsAux); | 950 | return ERR_NONE; |
| 951 | 951 | } | |
| 952 | if (pPps->uiNumRefIdxL0Active > MAX_REF_PIC_COUNT || | 952 | |
| 953 | pPps->uiNumRefIdxL1Active > MAX_REF_PIC_COUNT) | 953 | /*! |
| 954 | { | 954 | ************************************************************************************* |
| 955 | return ERR_INFO_REF_COUNT_OVERFLOW; | 955 | * \brief reset fmo list due to got Sps now |
| 956 | } | 956 | * |
| 957 | 957 | * \param pCtx decoder context | |
| 958 | pPps->bWeightedPredFlag = !!BsGetOneBit(pBsAux); | 958 | * |
| 959 | pPps->uiWeightedBipredIdc = BsGetBits(pBsAux, 2); | 959 | * \return count number of fmo context units are reset |
| 960 | if( pPps->bWeightedPredFlag || pPps->uiWeightedBipredIdc != 0 ) | 960 | ************************************************************************************* |
| 961 | { | 961 | */ |
| 962 | WelsLog( pCtx, WELS_LOG_WARNING, "ParsePps(): weighted_pred_flag (%d) weighted_bipred_idc (%d) neither supported.\n", pPps->bWeightedPredFlag, pPps->uiWeightedBipredIdc); | 962 | int32_t ResetFmoList (PWelsDecoderContext pCtx) { |
| 963 | return GENERATE_ERROR_NO(ERR_LEVEL_PARAM_SETS, ERR_INFO_UNSUPPORTED_WP); | 963 | int32_t iCountNum = 0; |
| 964 | } | 964 | if (NULL != pCtx) { |
| 965 | 965 | // Fixed memory leak due to PPS_ID might not be continuous sometimes, 1/5/2010 | |
| 966 | pPps->iPicInitQp = 26 + BsGetSe(pBsAux); | 966 | UninitFmoList (&pCtx->sFmoList[0], MAX_PPS_COUNT, pCtx->iActiveFmoNum); |
| 967 | pPps->iPicInitQs = 26 + BsGetSe(pBsAux); | 967 | iCountNum = pCtx->iActiveFmoNum; |
| 968 | 968 | pCtx->iActiveFmoNum = 0; | |
| 969 | pPps->iChromaQpIndexOffset = BsGetSe(pBsAux); | 969 | } |
| 970 | pPps->bDeblockingFilterControlPresentFlag = !!BsGetOneBit(pBsAux); | 970 | return iCountNum; |
| 971 | pPps->bConstainedIntraPredFlag = !!BsGetOneBit(pBsAux); | 971 | } |
| 972 | pPps->bRedundantPicCntPresentFlag = !!BsGetOneBit(pBsAux); | 972 | |
| 973 | |||
| 974 | |||
| 975 | #ifdef MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | ||
| 976 | pCtx->bPpsAvailFlags[pCtx->iPpsTotalNum] = true; | ||
| 977 | ++pCtx->iPpsTotalNum; | ||
| 978 | #else | ||
| 979 | pCtx->bPpsAvailFlags[uiPpsId] = true; // added for EC, 10/28/2009 | ||
| 980 | #endif //MOSAIC_AVOID_BASED_ON_SPS_PPS_ID | ||
| 981 | |||
| 982 | return ERR_NONE; | ||
| 983 | } | ||
| 984 | |||
| 985 | /*! | ||
| 986 | ************************************************************************************* | ||
| 987 | * \brief to parse SEI message payload | ||
| 988 | * | ||
| 989 | * \param pSei sei message to be parsed output | ||
| 990 | * \param pBsAux bitstream reader auxiliary | ||
| 991 | * | ||
| 992 | * \return 0 - successed | ||
| 993 | * 1 - failed | ||
| 994 | * | ||
| 995 | * \note Call it in case eNalUnitType is NAL_UNIT_SEI. | ||
| 996 | ************************************************************************************* | ||
| 997 | */ | ||
| 998 | int32_t ParseSei( void_t *pSei, PBitStringAux pBsAux ) // reserved Sei_Msg type | ||
| 999 | { | ||
| 1000 | |||
| 1001 | |||
| 1002 | return ERR_NONE; | ||
| 1003 | } | ||
| 1004 | |||
| 1005 | /*! | ||
| 1006 | ************************************************************************************* | ||
| 1007 | * \brief reset fmo list due to got Sps now | ||
| 1008 | * | ||
| 1009 | * \param pCtx decoder context | ||
| 1010 | * | ||
| 1011 | * \return count number of fmo context units are reset | ||
| 1012 | ************************************************************************************* | ||
| 1013 | */ | ||
| 1014 | int32_t ResetFmoList( PWelsDecoderContext pCtx ) | ||
| 1015 | { | ||
| 1016 | int32_t iCountNum = 0; | ||
| 1017 | if ( NULL != pCtx ) | ||
| 1018 | { | ||
| 1019 | // Fixed memory leak due to PPS_ID might not be continuous sometimes, 1/5/2010 | ||
| 1020 | UninitFmoList( &pCtx->sFmoList[0], MAX_PPS_COUNT, pCtx->iActiveFmoNum ); | ||
| 1021 | iCountNum = pCtx->iActiveFmoNum; | ||
| 1022 | pCtx->iActiveFmoNum = 0; | ||
| 1023 | } | ||
| 1024 | return iCountNum; | ||
| 1025 | } | ||
| 1026 | |||
| 1027 | } // namespace WelsDec | 973 | } // namespace WelsDec |