Showing the changes to codec/decoder/core/src/decoder.cpp (1 of 225 files). Show all
Unified · Split
| @@ -65,151 +65,136 @@ · 64 unmodified lines | ||
| 65 | 65 | |
| 66 | 66 | namespace WelsDec { |
| 67 | 67 | |
| 68 | −extern PPicture AllocPicture( PWelsDecoderContext pCtx,const int32_t kiPicWidth, const int32_t kiPicHeight ); | |
| 68 | +extern PPicture AllocPicture (PWelsDecoderContext pCtx, const int32_t kiPicWidth, const int32_t kiPicHeight); | |
| 69 | 69 | |
| 70 | −extern void_t FreePicture( PPicture pPic ); | |
| 70 | +extern void_t FreePicture (PPicture pPic); | |
| 71 | 71 | |
| 72 | 72 | #ifdef WORDS_BIGENDIAN |
| 73 | −inline void_t GetValueOf4Bytes( uint8_t* pDstNal, int32_t iDdstIdx ) | |
| 74 | −{ | |
| 75 | − pDstNal[0] = (iDdstIdx & 0xff000000) >> 24; | |
| 76 | − pDstNal[1] = (iDdstIdx & 0xff0000) >> 16; | |
| 77 | − pDstNal[2] = (iDdstIdx & 0xff00) >> 8; | |
| 78 | − pDstNal[3] = (iDdstIdx & 0xff); | |
| 73 | +inline void_t GetValueOf4Bytes (uint8_t* pDstNal, int32_t iDdstIdx) { | |
| 74 | + pDstNal[0] = (iDdstIdx & 0xff000000) >> 24; | |
| 75 | + pDstNal[1] = (iDdstIdx & 0xff0000) >> 16; | |
| 76 | + pDstNal[2] = (iDdstIdx & 0xff00) >> 8; | |
| 77 | + pDstNal[3] = (iDdstIdx & 0xff); | |
| 79 | 78 | } |
| 80 | 79 | #else //WORDS_BIGENDIAN |
| 81 | −inline void_t GetValueOf4Bytes( uint8_t* pDstNal, int32_t iDdstIdx ) | |
| 82 | −{ | |
| 83 | − pDstNal[0] = (iDdstIdx & 0xff); | |
| 84 | − pDstNal[1] = (iDdstIdx & 0xff00) >> 8; | |
| 85 | − pDstNal[2] = (iDdstIdx & 0xff0000) >> 16; | |
| 86 | − pDstNal[3] = (iDdstIdx & 0xff000000) >> 24; | |
| 80 | +inline void_t GetValueOf4Bytes (uint8_t* pDstNal, int32_t iDdstIdx) { | |
| 81 | + pDstNal[0] = (iDdstIdx & 0xff); | |
| 82 | + pDstNal[1] = (iDdstIdx & 0xff00) >> 8; | |
| 83 | + pDstNal[2] = (iDdstIdx & 0xff0000) >> 16; | |
| 84 | + pDstNal[3] = (iDdstIdx & 0xff000000) >> 24; | |
| 87 | 85 | } |
| 88 | 86 | #endif //WORDS_BIGENDIAN |
| 89 | 87 | |
| 90 | −static int32_t CreatePicBuff(PWelsDecoderContext pCtx, PPicBuff *ppPicBuf, const int32_t kiSize, const int32_t kiPicWidth, const int32_t kiPicHeight) | |
| 91 | −{ | |
| 92 | − PPicBuff pPicBuf = NULL; | |
| 93 | − int32_t iPicIdx = 0; | |
| 94 | − if (kiSize <= 0 || kiPicWidth <= 0 || kiPicHeight <= 0) | |
| 95 | − { | |
| 96 | − return 1; | |
| 97 | − } | |
| 98 | − | |
| 99 | − pPicBuf = (PPicBuff)WelsMalloc( sizeof(SPicBuff), "PPicBuff" ); | |
| 100 | − | |
| 101 | − if ( NULL == pPicBuf ) | |
| 102 | − { | |
| 103 | − return 1; | |
| 104 | − } | |
| 105 | − | |
| 106 | − pPicBuf->ppPic = (PPicture *)WelsMalloc(kiSize * sizeof(PPicture), "PPicture*"); | |
| 107 | − | |
| 108 | − if ( NULL == pPicBuf->ppPic ) | |
| 109 | − { | |
| 110 | − return 1; | |
| 111 | − } | |
| 112 | − for (iPicIdx = 0; iPicIdx < kiSize; ++ iPicIdx) | |
| 113 | − { | |
| 114 | − PPicture pPic = AllocPicture( pCtx, kiPicWidth, kiPicHeight ); | |
| 115 | − if ( NULL == pPic ) | |
| 116 | − { | |
| 117 | − return 1; | |
| 118 | − } | |
| 119 | − pPicBuf->ppPic[iPicIdx] = pPic; | |
| 120 | − } | |
| 121 | − | |
| 122 | − // initialize context in queue | |
| 123 | − pPicBuf->iCapacity = kiSize; | |
| 124 | − pPicBuf->iCurrentIdx = 0; | |
| 125 | − *ppPicBuf = pPicBuf; | |
| 126 | − | |
| 127 | − return 0; | |
| 88 | +static int32_t CreatePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, const int32_t kiSize, | |
| 89 | + const int32_t kiPicWidth, const int32_t kiPicHeight) { | |
| 90 | + PPicBuff pPicBuf = NULL; | |
| 91 | + int32_t iPicIdx = 0; | |
| 92 | + if (kiSize <= 0 || kiPicWidth <= 0 || kiPicHeight <= 0) { | |
| 93 | + return 1; | |
| 94 | + } | |
| 95 | + | |
| 96 | + pPicBuf = (PPicBuff)WelsMalloc (sizeof (SPicBuff), "PPicBuff"); | |
| 97 | + | |
| 98 | + if (NULL == pPicBuf) { | |
| 99 | + return 1; | |
| 100 | + } | |
| 101 | + | |
| 102 | + pPicBuf->ppPic = (PPicture*)WelsMalloc (kiSize * sizeof (PPicture), "PPicture*"); | |
| 103 | + | |
| 104 | + if (NULL == pPicBuf->ppPic) { | |
| 105 | + return 1; | |
| 106 | + } | |
| 107 | + for (iPicIdx = 0; iPicIdx < kiSize; ++ iPicIdx) { | |
| 108 | + PPicture pPic = AllocPicture (pCtx, kiPicWidth, kiPicHeight); | |
| 109 | + if (NULL == pPic) { | |
| 110 | + return 1; | |
| 111 | + } | |
| 112 | + pPicBuf->ppPic[iPicIdx] = pPic; | |
| 113 | + } | |
| 114 | + | |
| 115 | + // initialize context in queue | |
| 116 | + pPicBuf->iCapacity = kiSize; | |
| 117 | + pPicBuf->iCurrentIdx = 0; | |
| 118 | + *ppPicBuf = pPicBuf; | |
| 119 | + | |
| 120 | + return 0; | |
| 128 | 121 | } |
| 129 | 122 | |
| 130 | −static void_t DestroyPicBuff( PPicBuff *ppPicBuf ) | |
| 131 | −{ | |
| 132 | − PPicBuff pPicBuf = NULL; | |
| 133 | − | |
| 134 | − if ( NULL == ppPicBuf || NULL == *ppPicBuf ) | |
| 135 | − return; | |
| 136 | − | |
| 137 | − pPicBuf = *ppPicBuf; | |
| 138 | − while(pPicBuf->ppPic != NULL) | |
| 139 | − { | |
| 140 | − int32_t iPicIdx = 0; | |
| 141 | − while (iPicIdx < pPicBuf->iCapacity) | |
| 142 | − { | |
| 143 | − PPicture pPic = pPicBuf->ppPic[iPicIdx]; | |
| 144 | − if(pPic != NULL) | |
| 145 | − { | |
| 146 | − FreePicture( pPic ); | |
| 147 | − } | |
| 148 | − pPic = NULL; | |
| 149 | − ++ iPicIdx; | |
| 150 | − } | |
| 151 | − | |
| 152 | − WelsFree(pPicBuf->ppPic, "pPicBuf->queue"); | |
| 153 | − | |
| 154 | − pPicBuf->ppPic = NULL; | |
| 155 | − } | |
| 156 | − pPicBuf->iCapacity = 0; | |
| 157 | − pPicBuf->iCurrentIdx= 0; | |
| 158 | − | |
| 159 | − WelsFree( pPicBuf, "pPicBuf" ); | |
| 160 | − | |
| 161 | − pPicBuf = NULL; | |
| 162 | − *ppPicBuf = NULL; | |
| 123 | +static void_t DestroyPicBuff (PPicBuff* ppPicBuf) { | |
| 124 | + PPicBuff pPicBuf = NULL; | |
| 125 | + | |
| 126 | + if (NULL == ppPicBuf || NULL == *ppPicBuf) | |
| 127 | + return; | |
| 128 | + | |
| 129 | + pPicBuf = *ppPicBuf; | |
| 130 | + while (pPicBuf->ppPic != NULL) { | |
| 131 | + int32_t iPicIdx = 0; | |
| 132 | + while (iPicIdx < pPicBuf->iCapacity) { | |
| 133 | + PPicture pPic = pPicBuf->ppPic[iPicIdx]; | |
| 134 | + if (pPic != NULL) { | |
| 135 | + FreePicture (pPic); | |
| 136 | + } | |
| 137 | + pPic = NULL; | |
| 138 | + ++ iPicIdx; | |
| 139 | + } | |
| 140 | + | |
| 141 | + WelsFree (pPicBuf->ppPic, "pPicBuf->queue"); | |
| 142 | + | |
| 143 | + pPicBuf->ppPic = NULL; | |
| 144 | + } | |
| 145 | + pPicBuf->iCapacity = 0; | |
| 146 | + pPicBuf->iCurrentIdx = 0; | |
| 147 | + | |
| 148 | + WelsFree (pPicBuf, "pPicBuf"); | |
| 149 | + | |
| 150 | + pPicBuf = NULL; | |
| 151 | + *ppPicBuf = NULL; | |
| 163 | 152 | } |
| 164 | 153 | /* |
| 165 | 154 | * fill data fields in default for decoder context |
| 166 | 155 | */ |
| 167 | −void_t WelsDecoderDefaults( PWelsDecoderContext pCtx ) | |
| 168 | −{ | |
| 169 | − int32_t iCpuCores = 1; | |
| 170 | − memset( pCtx, 0, sizeof(SWelsDecoderContext) ); // fill zero first | |
| 156 | +void_t WelsDecoderDefaults (PWelsDecoderContext pCtx) { | |
| 157 | + int32_t iCpuCores = 1; | |
| 158 | + memset (pCtx, 0, sizeof (SWelsDecoderContext)); // fill zero first | |
| 159 | + | |
| 160 | + pCtx->pArgDec = NULL; | |
| 161 | + | |
| 162 | + pCtx->iOutputColorFormat = videoFormatI420; // yuv in default | |
| 163 | + pCtx->bHaveGotMemory = false; // not ever request memory blocks for decoder context related | |
| 164 | + pCtx->uiCpuFlag = 0; | |
| 171 | 165 | |
| 172 | − pCtx->pArgDec = NULL; | |
| 166 | + pCtx->bAuReadyFlag = 0; // au data is not ready | |
| 173 | 167 | |
| 174 | − pCtx->iOutputColorFormat = videoFormatI420; // yuv in default | |
| 175 | − pCtx->bHaveGotMemory = false; // not ever request memory blocks for decoder context related | |
| 176 | − pCtx->uiCpuFlag = 0; | |
| 177 | − | |
| 178 | − pCtx->bAuReadyFlag = 0; // au data is not ready | |
| 179 | − | |
| 180 | 168 | |
| 181 | − g_uiCacheLineSize = 16; | |
| 169 | + g_uiCacheLineSize = 16; | |
| 182 | 170 | #if defined(X86_ASM) |
| 183 | − pCtx->uiCpuFlag = WelsCPUFeatureDetect(&iCpuCores); | |
| 171 | + pCtx->uiCpuFlag = WelsCPUFeatureDetect (&iCpuCores); | |
| 184 | 172 | #ifdef HAVE_CACHE_LINE_ALIGN |
| 185 | − if ( pCtx->uiCpuFlag & WELS_CPU_CACHELINE_64 ) | |
| 186 | − { | |
| 187 | − g_uiCacheLineSize = 64; | |
| 188 | − } | |
| 189 | − else if ( pCtx->uiCpuFlag & WELS_CPU_CACHELINE_32 ) | |
| 190 | − { | |
| 191 | − g_uiCacheLineSize = 32; | |
| 192 | − } | |
| 173 | + if (pCtx->uiCpuFlag & WELS_CPU_CACHELINE_64) { | |
| 174 | + g_uiCacheLineSize = 64; | |
| 175 | + } else if (pCtx->uiCpuFlag & WELS_CPU_CACHELINE_32) { | |
| 176 | + g_uiCacheLineSize = 32; | |
| 177 | + } | |
| 193 | 178 | #endif//HAVE_CACHE_LINE_ALIGN |
| 194 | 179 | #endif//X86_ASM |
| 195 | 180 | |
| 196 | − pCtx->iImgWidthInPixel = 0; | |
| 197 | − pCtx->iImgHeightInPixel = 0; // alloc picture data when picture size is available | |
| 181 | + pCtx->iImgWidthInPixel = 0; | |
| 182 | + pCtx->iImgHeightInPixel = 0; // alloc picture data when picture size is available | |
| 183 | + | |
| 184 | + pCtx->iFrameNum = -1; | |
| 185 | + pCtx->iPrevFrameNum = -1; | |
| 186 | + pCtx->iErrorCode = ERR_NONE; | |
| 187 | + | |
| 188 | + pCtx->pDec = NULL; | |
| 198 | 189 | |
| 199 | − pCtx->iFrameNum = -1; | |
| 200 | − pCtx->iPrevFrameNum = -1; | |
| 201 | − pCtx->iErrorCode = ERR_NONE; | |
| 202 | − | |
| 203 | − pCtx->pDec = NULL; | |
| 190 | + WelsResetRefPic (pCtx); | |
| 204 | 191 | |
| 205 | − WelsResetRefPic(pCtx); | |
| 206 | − | |
| 207 | − pCtx->iActiveFmoNum = 0; | |
| 192 | + pCtx->iActiveFmoNum = 0; | |
| 208 | 193 | |
| 209 | − pCtx->pPicBuff[LIST_0] = NULL; | |
| 210 | − pCtx->pPicBuff[LIST_1] = NULL; | |
| 194 | + pCtx->pPicBuff[LIST_0] = NULL; | |
| 195 | + pCtx->pPicBuff[LIST_1] = NULL; | |
| 211 | 196 | |
| 212 | − pCtx->bAvcBasedFlag = true; | |
| 197 | + pCtx->bAvcBasedFlag = true; | |
| 213 | 198 | |
| 214 | 199 | } |
| 215 | 200 | |
| @@ -221,231 +206,212 @@ void_t WelsDecoderDefaults( PWelsDecoderContext pCtx ) · 5 unmodified lines | ||
| 221 | 206 | /* |
| 222 | 207 | * get size of reference picture list in target layer incoming, = (iNumRefFrames x 2) |
| 223 | 208 | */ |
| 224 | −static inline int32_t GetTargetRefListSize( PWelsDecoderContext pCtx ) | |
| 225 | −{ | |
| 226 | − bool_t *pSubsetSpsAvail= &pCtx->bSubspsAvailFlags[0]; | |
| 227 | − bool_t *pSpsAvail = &pCtx->bSpsAvailFlags[0]; | |
| 228 | − int32_t iSubsetIdx = -1; | |
| 229 | − int32_t iSpsIdx = -1; | |
| 230 | − bool_t bExistSubsetSps = false; | |
| 231 | − int32_t bExistSps = false; | |
| 232 | − int32_t iPos = MAX_SPS_COUNT - 1; | |
| 233 | − int32_t iNumRefFrames = 0; | |
| 234 | − | |
| 235 | − while (iPos >= 0) | |
| 236 | − { | |
| 237 | − if ( pSubsetSpsAvail[iPos] ) | |
| 238 | − { | |
| 239 | − bExistSubsetSps = true; | |
| 240 | − iSubsetIdx = iPos; | |
| 241 | − break; | |
| 242 | − } | |
| 243 | − -- iPos; | |
| 244 | − } | |
| 245 | − | |
| 246 | − if ( !bExistSubsetSps ) | |
| 247 | − { | |
| 248 | − iPos = MAX_SPS_COUNT - 1; | |
| 249 | − while (iPos >= 0) | |
| 250 | − { | |
| 251 | − if ( pSpsAvail[iPos] ) | |
| 252 | − { | |
| 253 | − bExistSps = true; | |
| 254 | − iSpsIdx = iPos; | |
| 255 | − break; | |
| 256 | − } | |
| 257 | − -- iPos; | |
| 258 | − } | |
| 259 | − } | |
| 260 | − | |
| 261 | − if ( !(bExistSubsetSps || bExistSps) ) | |
| 262 | − { | |
| 263 | − iNumRefFrames = MAX_REF_PIC_COUNT; | |
| 264 | − } | |
| 265 | − else | |
| 266 | − { | |
| 267 | − PSps pSps = bExistSubsetSps ? (&pCtx->sSubsetSpsBuffer[iSubsetIdx].sSps) : (&pCtx->sSpsBuffer[iSpsIdx]); | |
| 268 | − | |
| 269 | − iNumRefFrames = (pSps->iNumRefFrames ) + 1; | |
| 270 | − } | |
| 271 | − | |
| 272 | − if ( 0 == iNumRefFrames ) | |
| 273 | − iNumRefFrames = (MIN_REF_PIC_COUNT); | |
| 274 | − | |
| 209 | +static inline int32_t GetTargetRefListSize (PWelsDecoderContext pCtx) { | |
| 210 | + bool_t* pSubsetSpsAvail = &pCtx->bSubspsAvailFlags[0]; | |
| 211 | + bool_t* pSpsAvail = &pCtx->bSpsAvailFlags[0]; | |
| 212 | + int32_t iSubsetIdx = -1; | |
| 213 | + int32_t iSpsIdx = -1; | |
| 214 | + bool_t bExistSubsetSps = false; | |
| 215 | + int32_t bExistSps = false; | |
| 216 | + int32_t iPos = MAX_SPS_COUNT - 1; | |
| 217 | + int32_t iNumRefFrames = 0; | |
| 218 | + | |
| 219 | + while (iPos >= 0) { | |
| 220 | + if (pSubsetSpsAvail[iPos]) { | |
| 221 | + bExistSubsetSps = true; | |
| 222 | + iSubsetIdx = iPos; | |
| 223 | + break; | |
| 224 | + } | |
| 225 | + -- iPos; | |
| 226 | + } | |
| 227 | + | |
| 228 | + if (!bExistSubsetSps) { | |
| 229 | + iPos = MAX_SPS_COUNT - 1; | |
| 230 | + while (iPos >= 0) { | |
| 231 | + if (pSpsAvail[iPos]) { | |
| 232 | + bExistSps = true; | |
| 233 | + iSpsIdx = iPos; | |
| 234 | + break; | |
| 235 | + } | |
| 236 | + -- iPos; | |
| 237 | + } | |
| 238 | + } | |
| 239 | + | |
| 240 | + if (! (bExistSubsetSps || bExistSps)) { | |
| 241 | + iNumRefFrames = MAX_REF_PIC_COUNT; | |
| 242 | + } else { | |
| 243 | + PSps pSps = bExistSubsetSps ? (&pCtx->sSubsetSpsBuffer[iSubsetIdx].sSps) : (&pCtx->sSpsBuffer[iSpsIdx]); | |
| 244 | + | |
| 245 | + iNumRefFrames = (pSps->iNumRefFrames) + 1; | |
| 246 | + } | |
| 247 | + | |
| 248 | + if (0 == iNumRefFrames) | |
| 249 | + iNumRefFrames = (MIN_REF_PIC_COUNT); | |
| 250 | + | |
| 275 | 251 | #ifdef LONG_TERM_REF |
| 276 | − //pic_queue size minimum set 2 | |
| 277 | − if (iNumRefFrames <2) | |
| 278 | − { | |
| 279 | − iNumRefFrames = 2; | |
| 280 | − } | |
| 252 | + //pic_queue size minimum set 2 | |
| 253 | + if (iNumRefFrames < 2) { | |
| 254 | + iNumRefFrames = 2; | |
| 255 | + } | |
| 281 | 256 | #endif |
| 282 | 257 | |
| 283 | − return iNumRefFrames; | |
| 258 | + return iNumRefFrames; | |
| 284 | 259 | } |
| 285 | 260 | |
| 286 | 261 | /* |
| 287 | 262 | * request memory blocks for decoder avc part |
| 288 | 263 | */ |
| 289 | −int32_t WelsRequestMem( PWelsDecoderContext pCtx, const int32_t kiMbWidth, const int32_t kiMbHeight ) | |
| 290 | −{ | |
| 291 | − const int32_t kiPicWidth = kiMbWidth << 4; | |
| 292 | − const int32_t kiPicHeight = kiMbHeight << 4; | |
| 293 | − int32_t iErr = ERR_NONE; | |
| 294 | − | |
| 295 | − int32_t iListIdx = 0; //, mb_blocks = 0; | |
| 296 | − int32_t iPicQueueSize = 0; // adaptive size of picture queue, = (pSps->iNumRefFrames x 2) | |
| 297 | − bool_t bNeedChangePicQueue = true; | |
| 298 | − | |
| 299 | − WELS_VERIFY_RETURN_IF( ERR_INFO_INVALID_PARAM, ( NULL == pCtx || kiPicWidth <= 0 || kiPicHeight <= 0 ) ) | |
| 300 | − | |
| 301 | − // Fixed the issue about different gop size over last, 5/17/2010 | |
| 302 | − // get picture queue size currently | |
| 303 | − iPicQueueSize = GetTargetRefListSize( pCtx ); // adaptive size of picture queue, = (pSps->iNumRefFrames x 2) | |
| 304 | − pCtx->iPicQueueNumber = iPicQueueSize; | |
| 305 | − if ( pCtx->pPicBuff[LIST_0] != NULL && pCtx->pPicBuff[LIST_0]->iCapacity == iPicQueueSize ) // comparing current picture queue size requested and previous allocation picture queue | |
| 306 | − bNeedChangePicQueue = false; | |
| 307 | − // HD based pic buffer need consider memory size consumed when switch from 720p to other lower size | |
| 308 | − WELS_VERIFY_RETURN_IF( ERR_NONE, pCtx->bHaveGotMemory && ( kiPicWidth == pCtx->iImgWidthInPixel && kiPicHeight == pCtx->iImgHeightInPixel ) && (!bNeedChangePicQueue) ) // have same scaled buffer | |
| 309 | − | |
| 310 | − // sync update pRefList | |
| 311 | − WelsResetRefPic( pCtx ); // added to sync update ref list due to pictures are free | |
| 312 | − | |
| 313 | − // for Recycled_Pic_Queue | |
| 314 | − for ( iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx ) | |
| 315 | − { | |
| 316 | − PPicBuff *ppPic = &pCtx->pPicBuff[iListIdx]; | |
| 317 | − if ( NULL != ppPic && NULL != *ppPic ) | |
| 318 | − { | |
| 319 | − DestroyPicBuff( ppPic ); | |
| 320 | − } | |
| 321 | − } | |
| 322 | − | |
| 323 | − // currently only active for LIST_0 due to have no B frames | |
| 324 | − iErr = CreatePicBuff( pCtx, &pCtx->pPicBuff[LIST_0], iPicQueueSize, kiPicWidth, kiPicHeight ); | |
| 325 | − if ( iErr != ERR_NONE ) | |
| 326 | − return iErr; | |
| 327 | − | |
| 328 | − | |
| 329 | − pCtx->iImgWidthInPixel = kiPicWidth; // target width of image to be reconstruted while decoding | |
| 330 | − pCtx->iImgHeightInPixel = kiPicHeight; // target height of image to be reconstruted while decoding | |
| 331 | − | |
| 332 | − pCtx->bHaveGotMemory = true; // global memory for decoder context related is requested | |
| 333 | − pCtx->pDec = NULL; // need prefetch a new pic due to spatial size changed | |
| 334 | − return ERR_NONE; | |
| 264 | +int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const int32_t kiMbHeight) { | |
| 265 | + const int32_t kiPicWidth = kiMbWidth << 4; | |
| 266 | + const int32_t kiPicHeight = kiMbHeight << 4; | |
| 267 | + int32_t iErr = ERR_NONE; | |
| 268 | + | |
| 269 | + int32_t iListIdx = 0; //, mb_blocks = 0; | |
| 270 | + int32_t iPicQueueSize = 0; // adaptive size of picture queue, = (pSps->iNumRefFrames x 2) | |
| 271 | + bool_t bNeedChangePicQueue = true; | |
| 272 | + | |
| 273 | + WELS_VERIFY_RETURN_IF (ERR_INFO_INVALID_PARAM, (NULL == pCtx || kiPicWidth <= 0 || kiPicHeight <= 0)) | |
| 274 | + | |
| 275 | + // Fixed the issue about different gop size over last, 5/17/2010 | |
| 276 | + // get picture queue size currently | |
| 277 | + iPicQueueSize = GetTargetRefListSize (pCtx); // adaptive size of picture queue, = (pSps->iNumRefFrames x 2) | |
| 278 | + pCtx->iPicQueueNumber = iPicQueueSize; | |
| 279 | + if (pCtx->pPicBuff[LIST_0] != NULL | |
| 280 | + && pCtx->pPicBuff[LIST_0]->iCapacity == | |
| 281 | + iPicQueueSize) // comparing current picture queue size requested and previous allocation picture queue | |
| 282 | + bNeedChangePicQueue = false; | |
| 283 | + // HD based pic buffer need consider memory size consumed when switch from 720p to other lower size | |
| 284 | + WELS_VERIFY_RETURN_IF (ERR_NONE, pCtx->bHaveGotMemory && (kiPicWidth == pCtx->iImgWidthInPixel | |
| 285 | + && kiPicHeight == pCtx->iImgHeightInPixel) && (!bNeedChangePicQueue)) // have same scaled buffer | |
| 286 | + | |
| 287 | + // sync update pRefList | |
| 288 | + WelsResetRefPic (pCtx); // added to sync update ref list due to pictures are free | |
| 289 | + | |
| 290 | + // for Recycled_Pic_Queue | |
| 291 | + for (iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx) { | |
| 292 | + PPicBuff* ppPic = &pCtx->pPicBuff[iListIdx]; | |
| 293 | + if (NULL != ppPic && NULL != *ppPic) { | |
| 294 | + DestroyPicBuff (ppPic); | |
| 295 | + } | |
| 296 | + } | |
| 297 | + | |
| 298 | + // currently only active for LIST_0 due to have no B frames | |
| 299 | + iErr = CreatePicBuff (pCtx, &pCtx->pPicBuff[LIST_0], iPicQueueSize, kiPicWidth, kiPicHeight); | |
| 300 | + if (iErr != ERR_NONE) | |
| 301 | + return iErr; | |
| 302 | + | |
| 303 | + | |
| 304 | + pCtx->iImgWidthInPixel = kiPicWidth; // target width of image to be reconstruted while decoding | |
| 305 | + pCtx->iImgHeightInPixel = kiPicHeight; // target height of image to be reconstruted while decoding | |
| 306 | + | |
| 307 | + pCtx->bHaveGotMemory = true; // global memory for decoder context related is requested | |
| 308 | + pCtx->pDec = NULL; // need prefetch a new pic due to spatial size changed | |
| 309 | + return ERR_NONE; | |
| 335 | 310 | } |
| 336 | 311 | |
| 337 | 312 | /* |
| 338 | 313 | * free memory blocks in avc |
| 339 | 314 | */ |
| 340 | −void_t WelsFreeMem( PWelsDecoderContext pCtx ) | |
| 341 | −{ | |
| 342 | − int32_t iListIdx = 0; | |
| 343 | − | |
| 344 | − /* TODO: free memory blocks introduced in avc */ | |
| 345 | − ResetFmoList( pCtx ); | |
| 346 | − | |
| 347 | − WelsResetRefPic( pCtx ); | |
| 348 | − | |
| 349 | − // for sPicBuff | |
| 350 | − for ( iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx ) | |
| 351 | − { | |
| 352 | − PPicBuff *pPicBuff = &pCtx->pPicBuff[iListIdx]; | |
| 353 | − if ( NULL != pPicBuff && NULL != *pPicBuff ) | |
| 354 | − { | |
| 355 | − DestroyPicBuff( pPicBuff ); | |
| 356 | − } | |
| 357 | − } | |
| 358 | − | |
| 359 | − // added for safe memory | |
| 360 | − pCtx->iImgWidthInPixel = 0; | |
| 361 | − pCtx->iImgHeightInPixel = 0; | |
| 362 | − pCtx->bHaveGotMemory = false; | |
| 363 | − | |
| 315 | +void_t WelsFreeMem (PWelsDecoderContext pCtx) { | |
| 316 | + int32_t iListIdx = 0; | |
| 317 | + | |
| 318 | + /* TODO: free memory blocks introduced in avc */ | |
| 319 | + ResetFmoList (pCtx); | |
| 320 | + | |
| 321 | + WelsResetRefPic (pCtx); | |
| 322 | + | |
| 323 | + // for sPicBuff | |
| 324 | + for (iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx) { | |
| 325 | + PPicBuff* pPicBuff = &pCtx->pPicBuff[iListIdx]; | |
| 326 | + if (NULL != pPicBuff && NULL != *pPicBuff) { | |
| 327 | + DestroyPicBuff (pPicBuff); | |
| 328 | + } | |
| 329 | + } | |
| 330 | + | |
| 331 | + // added for safe memory | |
| 332 | + pCtx->iImgWidthInPixel = 0; | |
| 333 | + pCtx->iImgHeightInPixel = 0; | |
| 334 | + pCtx->bHaveGotMemory = false; | |
| 335 | + | |
| 364 | 336 | } |
| 365 | 337 | |
| 366 | 338 | /*! |
| 367 | − * \brief Open decoder | |
| 339 | + * \brief Open decoder | |
| 368 | 340 | */ |
| 369 | −void_t WelsOpenDecoder( PWelsDecoderContext pCtx ) | |
| 370 | −{ | |
| 371 | − // function pointers | |
| 372 | − //initial MC function pointer-- | |
| 373 | − InitMcFunc(&(pCtx->sMcFunc), pCtx->uiCpuFlag); | |
| 374 | − | |
| 375 | − InitExpandPictureFunc(&(pCtx->sExpandPicFunc), pCtx->uiCpuFlag); | |
| 376 | − AssignFuncPointerForRec(pCtx); | |
| 377 | − | |
| 378 | − // vlc tables | |
| 379 | − InitVlcTable(&pCtx->sVlcTable); | |
| 380 | − | |
| 381 | − // startup memory | |
| 382 | − if ( ERR_NONE != WelsInitMemory( pCtx ) ) | |
| 383 | − return; | |
| 384 | − | |
| 385 | − pCtx->iMaxWidthInSps = 0; | |
| 386 | − pCtx->iMaxHeightInSps = 0; | |
| 341 | +void_t WelsOpenDecoder (PWelsDecoderContext pCtx) { | |
| 342 | + // function pointers | |
| 343 | + //initial MC function pointer-- | |
| 344 | + InitMcFunc (& (pCtx->sMcFunc), pCtx->uiCpuFlag); | |
| 345 | + | |
| 346 | + InitExpandPictureFunc (& (pCtx->sExpandPicFunc), pCtx->uiCpuFlag); | |
| 347 | + AssignFuncPointerForRec (pCtx); | |
| 348 | + | |
| 349 | + // vlc tables | |
| 350 | + InitVlcTable (&pCtx->sVlcTable); | |
| 351 | + | |
| 352 | + // startup memory | |
| 353 | + if (ERR_NONE != WelsInitMemory (pCtx)) | |
| 354 | + return; | |
| 355 | + | |
| 356 | + pCtx->iMaxWidthInSps = 0; | |
| 357 | + pCtx->iMaxHeightInSps = 0; | |
| 387 | 358 | #ifdef LONG_TERM_REF |
| 388 | − pCtx->bParamSetsLostFlag = true; | |
| 359 | + pCtx->bParamSetsLostFlag = true; | |
| 389 | 360 | #else |
| 390 | − pCtx->bReferenceLostAtT0Flag = true; // should be true to waiting IDR at incoming AU bits following, 6/4/2010 | |
| 361 | + pCtx->bReferenceLostAtT0Flag = true; // should be true to waiting IDR at incoming AU bits following, 6/4/2010 | |
| 391 | 362 | #endif //LONG_TERM_REF |
| 392 | 363 | } |
| 393 | 364 | |
| 394 | 365 | /*! |
| 395 | − * \brief Close decoder | |
| 366 | + * \brief Close decoder | |
| 396 | 367 | */ |
| 397 | −void_t WelsCloseDecoder( PWelsDecoderContext pCtx ) | |
| 398 | −{ | |
| 399 | − WelsFreeMem( pCtx ); | |
| 400 | − | |
| 401 | − WelsFreeMemory( pCtx ); | |
| 368 | +void_t WelsCloseDecoder (PWelsDecoderContext pCtx) { | |
| 369 | + WelsFreeMem (pCtx); | |
| 402 | 370 | |
| 403 | − UninitialDqLayersContext( pCtx ); | |
| 371 | + WelsFreeMemory (pCtx); | |
| 372 | + | |
| 373 | + UninitialDqLayersContext (pCtx); | |
| 404 | 374 | |
| 405 | 375 | #ifdef LONG_TERM_REF |
| 406 | − pCtx->bParamSetsLostFlag = false; | |
| 376 | + pCtx->bParamSetsLostFlag = false; | |
| 407 | 377 | #else |
| 408 | − pCtx->bReferenceLostAtT0Flag = false; | |
| 378 | + pCtx->bReferenceLostAtT0Flag = false; | |
| 409 | 379 | #endif |
| 410 | 380 | } |
| 411 | 381 | |
| 412 | 382 | /*! |
| 413 | − * \brief configure decoder parameters | |
| 383 | + * \brief configure decoder parameters | |
| 414 | 384 | */ |
| 415 | −int32_t DecoderConfigParam ( PWelsDecoderContext pCtx, const void_t* kpParam ) | |
| 416 | −{ | |
| 417 | − if ( NULL == pCtx || NULL == kpParam ) | |
| 418 | − return 1; | |
| 385 | +int32_t DecoderConfigParam (PWelsDecoderContext pCtx, const void_t* kpParam) { | |
| 386 | + if (NULL == pCtx || NULL == kpParam) | |
| 387 | + return 1; | |
| 419 | 388 | |
| 420 | − pCtx->pParam = (SDecodingParam *)WelsMalloc( sizeof(SDecodingParam), "SDecodingParam" ); | |
| 389 | + pCtx->pParam = (SDecodingParam*)WelsMalloc (sizeof (SDecodingParam), "SDecodingParam"); | |
| 421 | 390 | |
| 422 | − if ( NULL == pCtx->pParam ) | |
| 423 | − return 1; | |
| 391 | + if (NULL == pCtx->pParam) | |
| 392 | + return 1; | |
| 424 | 393 | |
| 425 | − memcpy( pCtx->pParam, kpParam, sizeof(SDecodingParam) ); | |
| 426 | − pCtx->iOutputColorFormat = pCtx->pParam->iOutputColorFormat; | |
| 427 | − pCtx->bErrorResilienceFlag = pCtx->pParam->uiEcActiveFlag ? true : false; | |
| 394 | + memcpy (pCtx->pParam, kpParam, sizeof (SDecodingParam)); | |
| 395 | + pCtx->iOutputColorFormat = pCtx->pParam->iOutputColorFormat; | |
| 396 | + pCtx->bErrorResilienceFlag = pCtx->pParam->uiEcActiveFlag ? true : false; | |
| 428 | 397 | |
| 429 | − if ( VIDEO_BITSTREAM_SVC == pCtx->pParam->sVideoProperty.eVideoBsType || | |
| 430 | − VIDEO_BITSTREAM_AVC == pCtx->pParam->sVideoProperty.eVideoBsType ) | |
| 431 | − { | |
| 432 | − pCtx->eVideoType = pCtx->pParam->sVideoProperty.eVideoBsType; | |
| 433 | − } | |
| 434 | − else | |
| 435 | − { | |
| 436 | − pCtx->eVideoType = VIDEO_BITSTREAM_DEFAULT; | |
| 437 | − } | |
| 398 | + if (VIDEO_BITSTREAM_SVC == pCtx->pParam->sVideoProperty.eVideoBsType || | |
| 399 | + VIDEO_BITSTREAM_AVC == pCtx->pParam->sVideoProperty.eVideoBsType) { | |
| 400 | + pCtx->eVideoType = pCtx->pParam->sVideoProperty.eVideoBsType; | |
| 401 | + } else { | |
| 402 | + pCtx->eVideoType = VIDEO_BITSTREAM_DEFAULT; | |
| 403 | + } | |
| 438 | 404 | |
| 439 | − WelsLog(pCtx, WELS_LOG_INFO, "eVideoType: %d\n", pCtx->eVideoType); | |
| 405 | + WelsLog (pCtx, WELS_LOG_INFO, "eVideoType: %d\n", pCtx->eVideoType); | |
| 440 | 406 | |
| 441 | − return 0; | |
| 407 | + return 0; | |
| 442 | 408 | } |
| 443 | 409 | |
| 444 | −/*! | |
| 410 | +/*! | |
| 445 | 411 | ************************************************************************************* |
| 446 | − * \brief Initialize Wels decoder parameters and memory | |
| 412 | + * \brief Initialize Wels decoder parameters and memory | |
| 447 | 413 | * |
| 448 | − * \param pCtx input context to be initialized at first stage | |
| 414 | + * \param pCtx input context to be initialized at first stage | |
| 449 | 415 | * |
| 450 | 416 | * \return 0 - successed |
| 451 | 417 | * \return 1 - failed |
| @@ -453,59 +419,56 @@ int32_t DecoderConfigParam ( PWelsDecoderContext pCtx, const void_t* kpParam ) · 1 unmodified line | ||
| 453 | 419 | * \note N/A |
| 454 | 420 | ************************************************************************************* |
| 455 | 421 | */ |
| 456 | −int32_t WelsInitDecoder( PWelsDecoderContext pCtx, void_t * pTraceHandle, PWelsLogCallbackFunc pLog ) | |
| 457 | −{ | |
| 458 | − if ( pCtx == NULL ){ | |
| 459 | − return ERR_INFO_INVALID_PTR; | |
| 460 | − } | |
| 422 | +int32_t WelsInitDecoder (PWelsDecoderContext pCtx, void_t* pTraceHandle, PWelsLogCallbackFunc pLog) { | |
| 423 | + if (pCtx == NULL) { | |
| 424 | + return ERR_INFO_INVALID_PTR; | |
| 425 | + } | |
| 426 | + | |
| 427 | + // default | |
| 428 | + WelsDecoderDefaults (pCtx); | |
| 461 | 429 | |
| 462 | − // default | |
| 463 | − WelsDecoderDefaults( pCtx ); | |
| 430 | + pCtx->pTraceHandle = pTraceHandle; | |
| 464 | 431 | |
| 465 | − pCtx->pTraceHandle = pTraceHandle; | |
| 432 | + g_pLog = pLog; | |
| 466 | 433 | |
| 467 | − g_pLog = pLog; | |
| 434 | + // open decoder | |
| 435 | + WelsOpenDecoder (pCtx); | |
| 468 | 436 | |
| 469 | − // open decoder | |
| 470 | − WelsOpenDecoder( pCtx ); | |
| 471 | − | |
| 472 | − // decode mode setting | |
| 473 | − pCtx->iDecoderMode = SW_MODE; | |
| 474 | − pCtx->iSetMode = AUTO_MODE; | |
| 475 | − pCtx->iDecoderOutputProperty = BUFFER_HOST; | |
| 476 | − pCtx->iModeSwitchType = 0; // 0: do not do mode switch | |
| 437 | + // decode mode setting | |
| 438 | + pCtx->iDecoderMode = SW_MODE; | |
| 439 | + pCtx->iSetMode = AUTO_MODE; | |
| 440 | + pCtx->iDecoderOutputProperty = BUFFER_HOST; | |
| 441 | + pCtx->iModeSwitchType = 0; // 0: do not do mode switch | |
| 477 | 442 | |
| 478 | 443 | |
| 479 | − return ERR_NONE; | |
| 444 | + return ERR_NONE; | |
| 480 | 445 | } |
| 481 | 446 | |
| 482 | −/*! | |
| 447 | +/*! | |
| 483 | 448 | ************************************************************************************* |
| 484 | 449 | * \brief Uninitialize Wels decoder parameters and memory |
| 485 | 450 | * |
| 486 | − * \param pCtx input context to be uninitialized at release stage | |
| 451 | + * \param pCtx input context to be uninitialized at release stage | |
| 487 | 452 | * |
| 488 | 453 | * \return NONE |
| 489 | 454 | * |
| 490 | 455 | * \note N/A |
| 491 | 456 | ************************************************************************************* |
| 492 | 457 | */ |
| 493 | −void_t WelsEndDecoder( PWelsDecoderContext pCtx ) | |
| 494 | −{ | |
| 495 | − // close decoder | |
| 496 | − WelsCloseDecoder( pCtx ); | |
| 458 | +void_t WelsEndDecoder (PWelsDecoderContext pCtx) { | |
| 459 | + // close decoder | |
| 460 | + WelsCloseDecoder (pCtx); | |
| 497 | 461 | } |
| 498 | 462 | |
| 499 | −void_t GetVclNalTemporalId( PWelsDecoderContext pCtx ) | |
| 500 | −{ | |
| 501 | − PAccessUnit pAccessUnit = pCtx->pAccessUnitList; | |
| 502 | − int32_t idx = pAccessUnit->uiStartPos; | |
| 463 | +void_t GetVclNalTemporalId (PWelsDecoderContext pCtx) { | |
| 464 | + PAccessUnit pAccessUnit = pCtx->pAccessUnitList; | |
| 465 | + int32_t idx = pAccessUnit->uiStartPos; | |
| 503 | 466 | |
| 504 | − pCtx->iFeedbackVclNalInAu = FEEDBACK_VCL_NAL; | |
| 505 | − pCtx->iFeedbackTidInAu = pAccessUnit->pNalUnitsList[idx]->sNalHeaderExt.uiTemporalId; | |
| 467 | + pCtx->iFeedbackVclNalInAu = FEEDBACK_VCL_NAL; | |
| 468 | + pCtx->iFeedbackTidInAu = pAccessUnit->pNalUnitsList[idx]->sNalHeaderExt.uiTemporalId; | |
| 506 | 469 | } |
| 507 | 470 | |
| 508 | −/*! | |
| 471 | +/*! | |
| 509 | 472 | ************************************************************************************* |
| 510 | 473 | * \brief First entrance to decoding core interface. |
| 511 | 474 | * |
| @@ -521,210 +484,183 @@ void_t GetVclNalTemporalId( PWelsDecoderContext pCtx ) · 9 unmodified lines | ||
| 521 | 484 | * \note N/A |
| 522 | 485 | ************************************************************************************* |
| 523 | 486 | */ |
| 524 | −int32_t WelsDecodeBs( PWelsDecoderContext pCtx, const uint8_t *kpBsBuf, const int32_t kiBsLen, | |
| 525 | − uint8_t **ppDst, SBufferInfo* pDstBufInfo) | |
| 526 | −{ | |
| 527 | − if ( !pCtx->bEndOfStreamFlag) | |
| 528 | − { | |
| 529 | − SDataBuffer* pRawData = &pCtx->sRawData; | |
| 530 | − | |
| 531 | − int32_t iSrcIdx = 0; //the index of source bit-stream till now after parsing one or more NALs | |
| 532 | − int32_t iSrcConsumed = 0; // consumed bit count of source bs | |
| 533 | − int32_t iDstIdx = 0; //the size of current NAL after 0x03 removal and 00 00 01 removal | |
| 534 | − int32_t iSrcLength = 0; //the total size of current AU or NAL | |
| 535 | − | |
| 536 | − int32_t iConsumedBytes = 0; | |
| 537 | − int32_t iOffset = 0; | |
| 538 | − | |
| 539 | − uint8_t* pSrcNal = NULL; | |
| 540 | − uint8_t* pDstNal = NULL; | |
| 541 | − uint8_t *pNalPayload = NULL; | |
| 542 | − | |
| 543 | − | |
| 544 | − if ( NULL == DetectStartCodePrefix( kpBsBuf, &iOffset, kiBsLen ) ) //CAN'T find the 00 00 01 start prefix from the source buffer | |
| 545 | − { | |
| 546 | − return dsBitstreamError; | |
| 547 | − } | |
| 548 | − | |
| 549 | − pSrcNal = const_cast<uint8_t*> (kpBsBuf) + iOffset; | |
| 550 | − iSrcLength = kiBsLen - iOffset; | |
| 551 | − | |
| 552 | − if ( (kiBsLen + 4) > ( pRawData->pEnd - pRawData->pCurPos ) ) | |
| 553 | − { | |
| 554 | − pRawData->pCurPos = pRawData->pHead; | |
| 555 | − } | |
| 556 | − | |
| 557 | − | |
| 558 | − //copy raw data from source buffer (application) to raw data buffer (codec inside) | |
| 559 | − //0x03 removal and extract all of NAL Unit from current raw data | |
| 560 | − pDstNal = pRawData->pCurPos + 4; //4-bytes used to write the length of current NAL rbsp | |
| 561 | − | |
| 562 | − while ( iSrcConsumed < iSrcLength ) | |
| 563 | − { | |
| 564 | − if ( ( 2 + iSrcConsumed < iSrcLength ) && | |
| 565 | − ( 0 == LD16(pSrcNal+iSrcIdx) ) && | |
| 566 | − ( (pSrcNal[2+iSrcIdx]==0x03) || (pSrcNal[2+iSrcIdx]==0x01) ) ) | |
| 567 | − { | |
| 568 | − if ( pSrcNal[2+iSrcIdx] == 0x03 ) | |
| 569 | − { | |
| 570 | − ST16(pDstNal+iDstIdx, 0); | |
| 571 | − iDstIdx += 2; | |
| 572 | − iSrcIdx += 3; | |
| 573 | − iSrcConsumed += 3; | |
| 574 | − } | |
| 575 | − else | |
| 576 | − { | |
| 577 | − GetValueOf4Bytes( pDstNal-4, iDstIdx ); //pDstNal-4 (non-aligned by 4) in Solaris10(SPARC). Given value by byte. | |
| 578 | − | |
| 579 | − iConsumedBytes = 0; | |
| 580 | − pNalPayload = ParseNalHeader( pCtx, &pCtx->sCurNalHead, pDstNal, iDstIdx, pSrcNal-3, iSrcIdx+3, &iConsumedBytes ); | |
| 581 | − | |
| 582 | − if (pCtx->bAuReadyFlag) | |
| 583 | − { | |
| 584 | − ConstructAccessUnit( pCtx, ppDst, pDstBufInfo ); | |
| 585 | − | |
| 586 | − if ( (dsOutOfMemory | dsNoParamSets) & pCtx->iErrorCode) | |
| 587 | − { | |
| 487 | +int32_t WelsDecodeBs (PWelsDecoderContext pCtx, const uint8_t* kpBsBuf, const int32_t kiBsLen, | |
| 488 | + uint8_t** ppDst, SBufferInfo* pDstBufInfo) { | |
| 489 | + if (!pCtx->bEndOfStreamFlag) { | |
| 490 | + SDataBuffer* pRawData = &pCtx->sRawData; | |
| 491 | + | |
| 492 | + int32_t iSrcIdx = 0; //the index of source bit-stream till now after parsing one or more NALs | |
| 493 | + int32_t iSrcConsumed = 0; // consumed bit count of source bs | |
| 494 | + int32_t iDstIdx = 0; //the size of current NAL after 0x03 removal and 00 00 01 removal | |
| 495 | + int32_t iSrcLength = 0; //the total size of current AU or NAL | |
| 496 | + | |
| 497 | + int32_t iConsumedBytes = 0; | |
| 498 | + int32_t iOffset = 0; | |
| 499 | + | |
| 500 | + uint8_t* pSrcNal = NULL; | |
| 501 | + uint8_t* pDstNal = NULL; | |
| 502 | + uint8_t* pNalPayload = NULL; | |
| 503 | + | |
| 504 | + | |
| 505 | + if (NULL == DetectStartCodePrefix (kpBsBuf, &iOffset, | |
| 506 | + kiBsLen)) { //CAN'T find the 00 00 01 start prefix from the source buffer | |
| 507 | + return dsBitstreamError; | |
| 508 | + } | |
| 509 | + | |
| 510 | + pSrcNal = const_cast<uint8_t*> (kpBsBuf) + iOffset; | |
| 511 | + iSrcLength = kiBsLen - iOffset; | |
| 512 | + | |
| 513 | + if ((kiBsLen + 4) > (pRawData->pEnd - pRawData->pCurPos)) { | |
| 514 | + pRawData->pCurPos = pRawData->pHead; | |
| 515 | + } | |
| 516 | + | |
| 517 | + | |
| 518 | + //copy raw data from source buffer (application) to raw data buffer (codec inside) | |
| 519 | + //0x03 removal and extract all of NAL Unit from current raw data | |
| 520 | + pDstNal = pRawData->pCurPos + 4; //4-bytes used to write the length of current NAL rbsp | |
| 521 | + | |
| 522 | + while (iSrcConsumed < iSrcLength) { | |
| 523 | + if ((2 + iSrcConsumed < iSrcLength) && | |
| 524 | + (0 == LD16 (pSrcNal + iSrcIdx)) && | |
| 525 | + ((pSrcNal[2 + iSrcIdx] == 0x03) || (pSrcNal[2 + iSrcIdx] == 0x01))) { | |
| 526 | + if (pSrcNal[2 + iSrcIdx] == 0x03) { | |
| 527 | + ST16 (pDstNal + iDstIdx, 0); | |
| 528 | + iDstIdx += 2; | |
| 529 | + iSrcIdx += 3; | |
| 530 | + iSrcConsumed += 3; | |
| 531 | + } else { | |
| 532 | + GetValueOf4Bytes (pDstNal - 4, iDstIdx); //pDstNal-4 (non-aligned by 4) in Solaris10(SPARC). Given value by byte. | |
| 533 | + | |
| 534 | + iConsumedBytes = 0; | |
| 535 | + pNalPayload = ParseNalHeader (pCtx, &pCtx->sCurNalHead, pDstNal, iDstIdx, pSrcNal - 3, iSrcIdx + 3, &iConsumedBytes); | |
| 536 | + | |
| 537 | + if (pCtx->bAuReadyFlag) { | |
| 538 | + ConstructAccessUnit (pCtx, ppDst, pDstBufInfo); | |
| 539 | + | |
| 540 | + if ((dsOutOfMemory | dsNoParamSets) & pCtx->iErrorCode) { | |
| 588 | 541 | #ifdef LONG_TERM_REF |
| 589 | − pCtx->bParamSetsLostFlag = true; | |
| 542 | + pCtx->bParamSetsLostFlag = true; | |
| 590 | 543 | #else |
| 591 | − pCtx->bReferenceLostAtT0Flag = true; | |
| 544 | + pCtx->bReferenceLostAtT0Flag = true; | |
| 592 | 545 | #endif |
| 593 | − ResetParameterSetsState( pCtx ); | |
| 594 | − | |
| 595 | − if( dsOutOfMemory & pCtx->iErrorCode){ | |
| 596 | − return pCtx->iErrorCode; | |
| 597 | − } | |
| 598 | − } | |
| 599 | − } | |
| 600 | − | |
| 601 | − if( (IS_PARAM_SETS_NALS(pCtx->sCurNalHead.eNalUnitType) || IS_SEI_NAL(pCtx->sCurNalHead.eNalUnitType)) && | |
| 602 | − pNalPayload ) | |
| 603 | − { | |
| 604 | − if ( ParseNonVclNal( pCtx, pNalPayload, iDstIdx-iConsumedBytes ) ) | |
| 605 | − { | |
| 606 | − if ( dsNoParamSets & pCtx->iErrorCode ) | |
| 607 | − { | |
| 546 | + ResetParameterSetsState (pCtx); | |
| 547 | + | |
| 548 | + if (dsOutOfMemory & pCtx->iErrorCode) { | |
| 549 | + return pCtx->iErrorCode; | |
| 550 | + } | |
| 551 | + } | |
| 552 | + } | |
| 553 | + | |
| 554 | + if ((IS_PARAM_SETS_NALS (pCtx->sCurNalHead.eNalUnitType) || IS_SEI_NAL (pCtx->sCurNalHead.eNalUnitType)) && | |
| 555 | + pNalPayload) { | |
| 556 | + if (ParseNonVclNal (pCtx, pNalPayload, iDstIdx - iConsumedBytes)) { | |
| 557 | + if (dsNoParamSets & pCtx->iErrorCode) { | |
| 608 | 558 | #ifdef LONG_TERM_REF |
| 609 | − pCtx->bParamSetsLostFlag = true; | |
| 559 | + pCtx->bParamSetsLostFlag = true; | |
| 610 | 560 | #else |
| 611 | − pCtx->bReferenceLostAtT0Flag = true; | |
| 561 | + pCtx->bReferenceLostAtT0Flag = true; | |
| 612 | 562 | #endif |
| 613 | − ResetParameterSetsState( pCtx ); | |
| 614 | − } | |
| 615 | − return pCtx->iErrorCode; | |
| 616 | − } | |
| 617 | − } | |
| 618 | − | |
| 619 | − pDstNal += iDstIdx; //update current position | |
| 620 | − if ( (iSrcLength - iSrcConsumed + 4) > (pRawData->pEnd - pDstNal) ) | |
| 621 | − { | |
| 622 | − pRawData->pCurPos = pRawData->pHead; | |
| 623 | − } | |
| 624 | − else | |
| 625 | − { | |
| 626 | − pRawData->pCurPos = pDstNal; | |
| 627 | − } | |
| 628 | − pDstNal = pRawData->pCurPos + 4; //init, 4 bytes used to store the next NAL | |
| 629 | − | |
| 630 | − pSrcNal += iSrcIdx+3; | |
| 631 | − iSrcConsumed += 3; | |
| 632 | − iSrcIdx = 0; | |
| 633 | − iDstIdx = 0; //reset 0, used to statistic the length of next NAL | |
| 634 | − } | |
| 635 | − continue; | |
| 636 | − } | |
| 637 | − pDstNal[iDstIdx++] = pSrcNal[iSrcIdx++]; | |
| 638 | − iSrcConsumed++; | |
| 639 | − } | |
| 640 | − | |
| 641 | − //last NAL decoding | |
| 642 | − GetValueOf4Bytes( pDstNal-4, iDstIdx ); //pDstNal-4 (non-aligned by 4) in Solaris10(SPARC). Given value by byte. | |
| 643 | − | |
| 644 | − iConsumedBytes = 0; | |
| 645 | − pNalPayload = ParseNalHeader( pCtx, &pCtx->sCurNalHead, pDstNal, iDstIdx, pSrcNal-3, iSrcIdx+3, &iConsumedBytes ); | |
| 646 | − | |
| 647 | − if (pCtx->bAuReadyFlag) | |
| 648 | − { | |
| 649 | − ConstructAccessUnit( pCtx, ppDst, pDstBufInfo ); | |
| 650 | − | |
| 651 | − if ( (dsOutOfMemory | dsNoParamSets) & pCtx->iErrorCode) | |
| 652 | − { | |
| 563 | + ResetParameterSetsState (pCtx); | |
| 564 | + } | |
| 565 | + return pCtx->iErrorCode; | |
| 566 | + } | |
| 567 | + } | |
| 568 | + | |
| 569 | + pDstNal += iDstIdx; //update current position | |
| 570 | + if ((iSrcLength - iSrcConsumed + 4) > (pRawData->pEnd - pDstNal)) { | |
| 571 | + pRawData->pCurPos = pRawData->pHead; | |
| 572 | + } else { | |
| 573 | + pRawData->pCurPos = pDstNal; | |
| 574 | + } | |
| 575 | + pDstNal = pRawData->pCurPos + 4; //init, 4 bytes used to store the next NAL | |
| 576 | + | |
| 577 | + pSrcNal += iSrcIdx + 3; | |
| 578 | + iSrcConsumed += 3; | |
| 579 | + iSrcIdx = 0; | |
| 580 | + iDstIdx = 0; //reset 0, used to statistic the length of next NAL | |
| 581 | + } | |
| 582 | + continue; | |
| 583 | + } | |
| 584 | + pDstNal[iDstIdx++] = pSrcNal[iSrcIdx++]; | |
| 585 | + iSrcConsumed++; | |
| 586 | + } | |
| 587 | + | |
| 588 | + //last NAL decoding | |
| 589 | + GetValueOf4Bytes (pDstNal - 4, iDstIdx); //pDstNal-4 (non-aligned by 4) in Solaris10(SPARC). Given value by byte. | |
| 590 | + | |
| 591 | + iConsumedBytes = 0; | |
| 592 | + pNalPayload = ParseNalHeader (pCtx, &pCtx->sCurNalHead, pDstNal, iDstIdx, pSrcNal - 3, iSrcIdx + 3, &iConsumedBytes); | |
| 593 | + | |
| 594 | + if (pCtx->bAuReadyFlag) { | |
| 595 | + ConstructAccessUnit (pCtx, ppDst, pDstBufInfo); | |
| 596 | + | |
| 597 | + if ((dsOutOfMemory | dsNoParamSets) & pCtx->iErrorCode) { | |
| 653 | 598 | #ifdef LONG_TERM_REF |
| 654 | − pCtx->bParamSetsLostFlag = true; | |
| 599 | + pCtx->bParamSetsLostFlag = true; | |
| 655 | 600 | #else |
| 656 | − pCtx->bReferenceLostAtT0Flag = true; | |
| 601 | + pCtx->bReferenceLostAtT0Flag = true; | |
| 657 | 602 | #endif |
| 658 | − ResetParameterSetsState( pCtx ); | |
| 659 | − return pCtx->iErrorCode; | |
| 660 | − } | |
| 661 | − } | |
| 662 | − | |
| 663 | − if( (IS_PARAM_SETS_NALS(pCtx->sCurNalHead.eNalUnitType) || IS_SEI_NAL(pCtx->sCurNalHead.eNalUnitType)) && pNalPayload ) | |
| 664 | − { | |
| 665 | − if ( ParseNonVclNal( pCtx, pNalPayload, iDstIdx-iConsumedBytes ) ) | |
| 666 | − { | |
| 667 | − if ( dsNoParamSets & pCtx->iErrorCode ) | |
| 668 | − { | |
| 603 | + ResetParameterSetsState (pCtx); | |
| 604 | + return pCtx->iErrorCode; | |
| 605 | + } | |
| 606 | + } | |
| 607 | + | |
| 608 | + if ((IS_PARAM_SETS_NALS (pCtx->sCurNalHead.eNalUnitType) || IS_SEI_NAL (pCtx->sCurNalHead.eNalUnitType)) | |
| 609 | + && pNalPayload) { | |
| 610 | + if (ParseNonVclNal (pCtx, pNalPayload, iDstIdx - iConsumedBytes)) { | |
| 611 | + if (dsNoParamSets & pCtx->iErrorCode) { | |
| 669 | 612 | #ifdef LONG_TERM_REF |
| 670 | − pCtx->bParamSetsLostFlag = true; | |
| 613 | + pCtx->bParamSetsLostFlag = true; | |
| 671 | 614 | #else |
| 672 | − pCtx->bReferenceLostAtT0Flag = true; | |
| 615 | + pCtx->bReferenceLostAtT0Flag = true; | |
| 673 | 616 | #endif |
| 674 | − ResetParameterSetsState( pCtx ); | |
| 675 | − } | |
| 676 | − return pCtx->iErrorCode; | |
| 677 | − } | |
| 678 | − } | |
| 679 | − | |
| 680 | − pDstNal += iDstIdx; | |
| 681 | − pRawData->pCurPos = pDstNal; //init the pCurPos for next NAL(s) storage | |
| 682 | − } | |
| 683 | − else /* no supplementary picture payload input, but stored a picture */ | |
| 684 | − { | |
| 685 | − PAccessUnit pCurAu = pCtx->pAccessUnitList; // current access unit, it will never point to NULL after decode's successful initialization | |
| 686 | − | |
| 687 | − if ( pCurAu->uiAvailUnitsNum == 0 ) | |
| 688 | − { | |
| 689 | − return pCtx->iErrorCode; | |
| 690 | − } | |
| 691 | − else | |
| 692 | − { | |
| 693 | − pCtx->pAccessUnitList->uiEndPos = pCtx->pAccessUnitList->uiAvailUnitsNum - 1; | |
| 694 | − | |
| 695 | − ConstructAccessUnit( pCtx, ppDst, pDstBufInfo ); | |
| 696 | − | |
| 697 | − if ( (dsOutOfMemory | dsNoParamSets) & pCtx->iErrorCode) | |
| 698 | − { | |
| 617 | + ResetParameterSetsState (pCtx); | |
| 618 | + } | |
| 619 | + return pCtx->iErrorCode; | |
| 620 | + } | |
| 621 | + } | |
| 622 | + | |
| 623 | + pDstNal += iDstIdx; | |
| 624 | + pRawData->pCurPos = pDstNal; //init the pCurPos for next NAL(s) storage | |
| 625 | + } else { /* no supplementary picture payload input, but stored a picture */ | |
| 626 | + PAccessUnit pCurAu = | |
| 627 | + pCtx->pAccessUnitList; // current access unit, it will never point to NULL after decode's successful initialization | |
| 628 | + | |
| 629 | + if (pCurAu->uiAvailUnitsNum == 0) { | |
| 630 | + return pCtx->iErrorCode; | |
| 631 | + } else { | |
| 632 | + pCtx->pAccessUnitList->uiEndPos = pCtx->pAccessUnitList->uiAvailUnitsNum - 1; | |
| 633 | + | |
| 634 | + ConstructAccessUnit (pCtx, ppDst, pDstBufInfo); | |
| 635 | + | |
| 636 | + if ((dsOutOfMemory | dsNoParamSets) & pCtx->iErrorCode) { | |
| 699 | 637 | #ifdef LONG_TERM_REF |
| 700 | − pCtx->bParamSetsLostFlag = true; | |
| 638 | + pCtx->bParamSetsLostFlag = true; | |
| 701 | 639 | #else |
| 702 | − pCtx->bReferenceLostAtT0Flag = true; | |
| 640 | + pCtx->bReferenceLostAtT0Flag = true; | |
| 703 | 641 | #endif |
| 704 | − ResetParameterSetsState( pCtx ); | |
| 705 | − return pCtx->iErrorCode; | |
| 706 | − } | |
| 707 | − | |
| 708 | − } | |
| 709 | − } | |
| 710 | − | |
| 711 | − return pCtx->iErrorCode; | |
| 642 | + ResetParameterSetsState (pCtx); | |
| 643 | + return pCtx->iErrorCode; | |
| 644 | + } | |
| 645 | + | |
| 646 | + } | |
| 647 | + } | |
| 648 | + | |
| 649 | + return pCtx->iErrorCode; | |
| 712 | 650 | } |
| 713 | 651 | |
| 714 | 652 | /* |
| 715 | 653 | * set colorspace format in decoder |
| 716 | 654 | */ |
| 717 | −int32_t DecoderSetCsp(PWelsDecoderContext pCtx, const int32_t kiColorFormat) | |
| 718 | −{ | |
| 719 | − WELS_VERIFY_RETURN_IF( 1, (NULL == pCtx) ); | |
| 655 | +int32_t DecoderSetCsp (PWelsDecoderContext pCtx, const int32_t kiColorFormat) { | |
| 656 | + WELS_VERIFY_RETURN_IF (1, (NULL == pCtx)); | |
| 720 | 657 | |
| 721 | − pCtx->iOutputColorFormat = kiColorFormat; | |
| 722 | − if ( pCtx->pParam != NULL ) | |
| 723 | − { | |
| 724 | − pCtx->pParam->iOutputColorFormat = kiColorFormat; | |
| 725 | − } | |
| 658 | + pCtx->iOutputColorFormat = kiColorFormat; | |
| 659 | + if (pCtx->pParam != NULL) { | |
| 660 | + pCtx->pParam->iOutputColorFormat = kiColorFormat; | |
| 661 | + } | |
| 726 | 662 | |
| 727 | − return 0; | |
| 663 | + return 0; | |
| 728 | 664 | } |
| 729 | 665 | |
| 730 | 666 | /*! |
| @@ -733,118 +669,110 @@ int32_t DecoderSetCsp(PWelsDecoderContext pCtx, const int32_t kiColorFormat) · 2 unmodified lines | ||
| 733 | 669 | * ( MB coordinate and parts of data within decoder context structure ) |
| 734 | 670 | * \param pCtx Wels decoder context |
| 735 | 671 | * \param iMbWidth MB width |
| 736 | − * \pram iMbHeight MB height | |
| 672 | + * \pram iMbHeight MB height | |
| 737 | 673 | * \return 0 - successful; none 0 - something wrong |
| 738 | 674 | */ |
| 739 | −int32_t SyncPictureResolutionExt( PWelsDecoderContext pCtx, const int32_t kiMbWidth, const int32_t kiMbHeight ) | |
| 740 | −{ | |
| 741 | − int32_t iErr = ERR_NONE; | |
| 742 | − const int32_t kiPicWidth = kiMbWidth << 4; | |
| 743 | − const int32_t kiPicHeight = kiMbHeight<< 4; | |
| 744 | − | |
| 745 | − iErr = WelsRequestMem( pCtx, kiMbWidth, kiMbHeight ); // common memory used | |
| 746 | − if ( ERR_NONE != iErr ) | |
| 747 | − { | |
| 748 | − WelsLog( pCtx, WELS_LOG_WARNING, "SyncPictureResolutionExt()::WelsRequestMem--buffer allocated failure.\n" ); | |
| 749 | − pCtx->iErrorCode = dsOutOfMemory; | |
| 750 | − return iErr; | |
| 751 | − } | |
| 752 | − | |
| 753 | − iErr = InitialDqLayersContext( pCtx, kiPicWidth, kiPicHeight ); | |
| 754 | − if ( ERR_NONE != iErr ) | |
| 755 | − { | |
| 756 | − WelsLog( pCtx, WELS_LOG_WARNING, "SyncPictureResolutionExt()::InitialDqLayersContext--buffer allocated failure.\n" ); | |
| 757 | − pCtx->iErrorCode = dsOutOfMemory; | |
| 758 | − } | |
| 759 | − | |
| 760 | − return iErr; | |
| 675 | +int32_t SyncPictureResolutionExt (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const int32_t kiMbHeight) { | |
| 676 | + int32_t iErr = ERR_NONE; | |
| 677 | + const int32_t kiPicWidth = kiMbWidth << 4; | |
| 678 | + const int32_t kiPicHeight = kiMbHeight << 4; | |
| 679 | + | |
| 680 | + iErr = WelsRequestMem (pCtx, kiMbWidth, kiMbHeight); // common memory used | |
| 681 | + if (ERR_NONE != iErr) { | |
| 682 | + WelsLog (pCtx, WELS_LOG_WARNING, "SyncPictureResolutionExt()::WelsRequestMem--buffer allocated failure.\n"); | |
| 683 | + pCtx->iErrorCode = dsOutOfMemory; | |
| 684 | + return iErr; | |
| 685 | + } | |
| 686 | + | |
| 687 | + iErr = InitialDqLayersContext (pCtx, kiPicWidth, kiPicHeight); | |
| 688 | + if (ERR_NONE != iErr) { | |
| 689 | + WelsLog (pCtx, WELS_LOG_WARNING, "SyncPictureResolutionExt()::InitialDqLayersContext--buffer allocated failure.\n"); | |
| 690 | + pCtx->iErrorCode = dsOutOfMemory; | |
| 691 | + } | |
| 692 | + | |
| 693 | + return iErr; | |
| 761 | 694 | } |
| 762 | 695 | |
| 763 | 696 | /*! |
| 764 | 697 | * \brief update maximal picture width and height if applicable when receiving a SPS NAL |
| 765 | 698 | */ |
| 766 | −void_t UpdateMaxPictureResolution( PWelsDecoderContext pCtx, const int32_t kiCurWidth, const int32_t kiCurHeight ) | |
| 767 | −{ | |
| 768 | − //any dimension larger than that of current dimension, should modify the max-dimension | |
| 769 | − if ( kiCurWidth > pCtx->iMaxWidthInSps || kiCurHeight > pCtx->iMaxHeightInSps) | |
| 770 | − { | |
| 771 | − pCtx->iMaxWidthInSps = kiCurWidth; | |
| 772 | − pCtx->iMaxHeightInSps = kiCurHeight; | |
| 773 | − } | |
| 774 | − | |
| 775 | − return; | |
| 699 | +void_t UpdateMaxPictureResolution (PWelsDecoderContext pCtx, const int32_t kiCurWidth, const int32_t kiCurHeight) { | |
| 700 | + //any dimension larger than that of current dimension, should modify the max-dimension | |
| 701 | + if (kiCurWidth > pCtx->iMaxWidthInSps || kiCurHeight > pCtx->iMaxHeightInSps) { | |
| 702 | + pCtx->iMaxWidthInSps = kiCurWidth; | |
| 703 | + pCtx->iMaxHeightInSps = kiCurHeight; | |
| 704 | + } | |
| 705 | + | |
| 706 | + return; | |
| 776 | 707 | } |
| 777 | 708 | |
| 778 | −void_t AssignFuncPointerForRec(PWelsDecoderContext pCtx) | |
| 779 | −{ | |
| 780 | − pCtx->pGetI16x16LumaPredFunc[I16_PRED_V ] = WelsI16x16LumaPredV_c; | |
| 781 | − pCtx->pGetI16x16LumaPredFunc[I16_PRED_H ] = WelsI16x16LumaPredH_c; | |
| 782 | − pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC ] = WelsI16x16LumaPredDc_c; | |
| 783 | − pCtx->pGetI16x16LumaPredFunc[I16_PRED_P ] = WelsI16x16LumaPredPlane_c; | |
| 784 | − pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC_L ] = WelsI16x16LumaPredDcLeft_c; | |
| 785 | − pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC_T ] = WelsI16x16LumaPredDcTop_c; | |
| 786 | − pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC_128] = WelsI16x16LumaPredDcNA_c; | |
| 787 | − | |
| 788 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_V ] = WelsI4x4LumaPredV_c; | |
| 789 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_H ] = WelsI4x4LumaPredH_c; | |
| 790 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_DC ] = WelsI4x4LumaPredDc_c; | |
| 791 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_DC_L ] = WelsI4x4LumaPredDcLeft_c; | |
| 792 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_DC_T ] = WelsI4x4LumaPredDcTop_c; | |
| 793 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_DC_128] = WelsI4x4LumaPredDcNA_c; | |
| 794 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_DDL ] = WelsI4x4LumaPredDDL_c; | |
| 795 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_DDL_TOP] = WelsI4x4LumaPredDDLTop_c; | |
| 796 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_DDR ] = WelsI4x4LumaPredDDR_c; | |
| 797 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_VL ] = WelsI4x4LumaPredVL_c; | |
| 798 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_VL_TOP] = WelsI4x4LumaPredVLTop_c; | |
| 799 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_VR ] = WelsI4x4LumaPredVR_c; | |
| 800 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_HU ] = WelsI4x4LumaPredHU_c; | |
| 801 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_HD ] = WelsI4x4LumaPredHD_c; | |
| 802 | − | |
| 803 | − pCtx->pGetIChromaPredFunc[C_PRED_DC ] = WelsIChromaPredDc_c; | |
| 804 | − pCtx->pGetIChromaPredFunc[C_PRED_H ] = WelsIChromaPredH_c; | |
| 805 | − pCtx->pGetIChromaPredFunc[C_PRED_V ] = WelsIChromaPredV_c; | |
| 806 | − pCtx->pGetIChromaPredFunc[C_PRED_P ] = WelsIChromaPredPlane_c; | |
| 807 | − pCtx->pGetIChromaPredFunc[C_PRED_DC_L ] = WelsIChromaPredDcLeft_c; | |
| 808 | − pCtx->pGetIChromaPredFunc[C_PRED_DC_T ] = WelsIChromaPredDcTop_c; | |
| 809 | − pCtx->pGetIChromaPredFunc[C_PRED_DC_128] = WelsIChromaPredDcNA_c; | |
| 810 | − | |
| 811 | − InitDctClipTable(); | |
| 812 | − pCtx->pIdctResAddPredFunc = IdctResAddPred_c; | |
| 709 | +void_t AssignFuncPointerForRec (PWelsDecoderContext pCtx) { | |
| 710 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_V ] = WelsI16x16LumaPredV_c; | |
| 711 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_H ] = WelsI16x16LumaPredH_c; | |
| 712 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC ] = WelsI16x16LumaPredDc_c; | |
| 713 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_P ] = WelsI16x16LumaPredPlane_c; | |
| 714 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC_L ] = WelsI16x16LumaPredDcLeft_c; | |
| 715 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC_T ] = WelsI16x16LumaPredDcTop_c; | |
| 716 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC_128] = WelsI16x16LumaPredDcNA_c; | |
| 717 | + | |
| 718 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_V ] = WelsI4x4LumaPredV_c; | |
| 719 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_H ] = WelsI4x4LumaPredH_c; | |
| 720 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DC ] = WelsI4x4LumaPredDc_c; | |
| 721 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DC_L ] = WelsI4x4LumaPredDcLeft_c; | |
| 722 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DC_T ] = WelsI4x4LumaPredDcTop_c; | |
| 723 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DC_128] = WelsI4x4LumaPredDcNA_c; | |
| 724 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DDL ] = WelsI4x4LumaPredDDL_c; | |
| 725 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DDL_TOP] = WelsI4x4LumaPredDDLTop_c; | |
| 726 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DDR ] = WelsI4x4LumaPredDDR_c; | |
| 727 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_VL ] = WelsI4x4LumaPredVL_c; | |
| 728 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_VL_TOP] = WelsI4x4LumaPredVLTop_c; | |
| 729 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_VR ] = WelsI4x4LumaPredVR_c; | |
| 730 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_HU ] = WelsI4x4LumaPredHU_c; | |
| 731 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_HD ] = WelsI4x4LumaPredHD_c; | |
| 732 | + | |
| 733 | + pCtx->pGetIChromaPredFunc[C_PRED_DC ] = WelsIChromaPredDc_c; | |
| 734 | + pCtx->pGetIChromaPredFunc[C_PRED_H ] = WelsIChromaPredH_c; | |
| 735 | + pCtx->pGetIChromaPredFunc[C_PRED_V ] = WelsIChromaPredV_c; | |
| 736 | + pCtx->pGetIChromaPredFunc[C_PRED_P ] = WelsIChromaPredPlane_c; | |
| 737 | + pCtx->pGetIChromaPredFunc[C_PRED_DC_L ] = WelsIChromaPredDcLeft_c; | |
| 738 | + pCtx->pGetIChromaPredFunc[C_PRED_DC_T ] = WelsIChromaPredDcTop_c; | |
| 739 | + pCtx->pGetIChromaPredFunc[C_PRED_DC_128] = WelsIChromaPredDcNA_c; | |
| 740 | + | |
| 741 | + InitDctClipTable(); | |
| 742 | + pCtx->pIdctResAddPredFunc = IdctResAddPred_c; | |
| 813 | 743 | |
| 814 | 744 | #if defined(X86_ASM) |
| 815 | − if ( pCtx->uiCpuFlag & WELS_CPU_MMXEXT ) | |
| 816 | − { | |
| 817 | − pCtx->pIdctResAddPredFunc = IdctResAddPred_mmx; | |
| 818 | − | |
| 819 | − /////////mmx code opt--- | |
| 820 | − pCtx->pGetIChromaPredFunc[C_PRED_H] = WelsIChromaPredH_mmx; | |
| 821 | − pCtx->pGetIChromaPredFunc[C_PRED_V] = WelsIChromaPredV_mmx; | |
| 822 | − pCtx->pGetIChromaPredFunc[C_PRED_DC_L ] = WelsIChromaPredDcLeft_mmx; | |
| 823 | − pCtx->pGetIChromaPredFunc[C_PRED_DC_128] = WelsIChromaPredDcNA_mmx; | |
| 824 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_DDR] = WelsI4x4LumaPredDDR_mmx; | |
| 825 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_HD ] = WelsI4x4LumaPredHD_mmx; | |
| 826 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_HU ] = WelsI4x4LumaPredHU_mmx; | |
| 827 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_VR ] = WelsI4x4LumaPredVR_mmx; | |
| 828 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_DDL] = WelsI4x4LumaPredDDL_mmx; | |
| 829 | − pCtx->pGetI4x4LumaPredFunc[I4_PRED_VL ] = WelsI4x4LumaPredVL_mmx; | |
| 830 | − } | |
| 831 | − if ( pCtx->uiCpuFlag & WELS_CPU_SSE2 ) | |
| 832 | − { | |
| 833 | − /////////sse2 code opt--- | |
| 834 | − pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC] = WelsI16x16LumaPredDc_sse2; | |
| 835 | − pCtx->pGetI16x16LumaPredFunc[I16_PRED_P] = WelsI16x16LumaPredPlane_sse2; | |
| 836 | − pCtx->pGetI16x16LumaPredFunc[I16_PRED_H] = WelsI16x16LumaPredH_sse2; | |
| 837 | − pCtx->pGetI16x16LumaPredFunc[I16_PRED_V] = WelsI16x16LumaPredV_sse2; | |
| 838 | − pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC_T ] = WelsI16x16LumaPredDcTop_sse2; | |
| 839 | − pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC_128] = WelsI16x16LumaPredDcNA_sse2; | |
| 840 | − pCtx->pGetIChromaPredFunc[C_PRED_P ] = WelsIChromaPredPlane_sse2; | |
| 841 | − pCtx->pGetIChromaPredFunc[C_PRED_DC] = WelsIChromaPredDc_sse2; | |
| 842 | − pCtx->pGetIChromaPredFunc[C_PRED_DC_T] = WelsIChromaPredDcTop_sse2; | |
| 843 | − } | |
| 745 | + if (pCtx->uiCpuFlag & WELS_CPU_MMXEXT) { | |
| 746 | + pCtx->pIdctResAddPredFunc = IdctResAddPred_mmx; | |
| 747 | + | |
| 748 | + /////////mmx code opt--- | |
| 749 | + pCtx->pGetIChromaPredFunc[C_PRED_H] = WelsIChromaPredH_mmx; | |
| 750 | + pCtx->pGetIChromaPredFunc[C_PRED_V] = WelsIChromaPredV_mmx; | |
| 751 | + pCtx->pGetIChromaPredFunc[C_PRED_DC_L ] = WelsIChromaPredDcLeft_mmx; | |
| 752 | + pCtx->pGetIChromaPredFunc[C_PRED_DC_128] = WelsIChromaPredDcNA_mmx; | |
| 753 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DDR] = WelsI4x4LumaPredDDR_mmx; | |
| 754 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_HD ] = WelsI4x4LumaPredHD_mmx; | |
| 755 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_HU ] = WelsI4x4LumaPredHU_mmx; | |
| 756 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_VR ] = WelsI4x4LumaPredVR_mmx; | |
| 757 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_DDL] = WelsI4x4LumaPredDDL_mmx; | |
| 758 | + pCtx->pGetI4x4LumaPredFunc[I4_PRED_VL ] = WelsI4x4LumaPredVL_mmx; | |
| 759 | + } | |
| 760 | + if (pCtx->uiCpuFlag & WELS_CPU_SSE2) { | |
| 761 | + /////////sse2 code opt--- | |
| 762 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC] = WelsI16x16LumaPredDc_sse2; | |
| 763 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_P] = WelsI16x16LumaPredPlane_sse2; | |
| 764 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_H] = WelsI16x16LumaPredH_sse2; | |
| 765 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_V] = WelsI16x16LumaPredV_sse2; | |
| 766 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC_T ] = WelsI16x16LumaPredDcTop_sse2; | |
| 767 | + pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC_128] = WelsI16x16LumaPredDcNA_sse2; | |
| 768 | + pCtx->pGetIChromaPredFunc[C_PRED_P ] = WelsIChromaPredPlane_sse2; | |
| 769 | + pCtx->pGetIChromaPredFunc[C_PRED_DC] = WelsIChromaPredDc_sse2; | |
| 770 | + pCtx->pGetIChromaPredFunc[C_PRED_DC_T] = WelsIChromaPredDcTop_sse2; | |
| 771 | + } | |
| 844 | 772 | #endif |
| 845 | − DeblockingInit(&pCtx->sDeblockingFunc, pCtx->uiCpuFlag); | |
| 773 | + DeblockingInit (&pCtx->sDeblockingFunc, pCtx->uiCpuFlag); | |
| 846 | 774 | |
| 847 | − WelsBlockFuncInit(&pCtx->sBlockFunc, pCtx->uiCpuFlag); | |
| 775 | + WelsBlockFuncInit (&pCtx->sBlockFunc, pCtx->uiCpuFlag); | |
| 848 | 776 | } |
| 849 | 777 | |
| 850 | 778 | } // namespace WelsDec |