Showing the changes to codec/encoder/core/src/wels_task_encoder.cpp (1 of 14 files). Show all
Unified · Split
| @@ -112,13 +112,12 @@ WelsErrorType CWelsSliceEncodingTask::InitTask() { · 111 unmodified lines | |||
| 112 | return ENC_RETURN_UNEXPECTED; | 112 | return ENC_RETURN_UNEXPECTED; |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | //m_pCtx->iEncoderError = InitOneSliceInThread (m_pCtx, m_pSlice, m_iThreadIdx, m_pCtx->uiDependencyId, m_iSliceIdx); | 115 | int32_t iReturn = InitOneSliceInThread (m_pCtx, m_pSlice, m_iThreadIdx, m_pCtx->uiDependencyId, m_iSliceIdx); |
| 116 | //WELS_VERIFY_RETURN_IFNEQ (m_pCtx->iEncoderError, ENC_RETURN_SUCCESS) | 116 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) |
| 117 | m_pSlice = &m_pCtx->pCurDqLayer->sSliceThreadInfo.pSliceInThread[0][m_iSliceIdx]; | ||
| 118 | m_pSliceBs = &m_pSlice->sSliceBs; | 117 | m_pSliceBs = &m_pSlice->sSliceBs; |
| 119 | 118 | ||
| 120 | m_pSliceBs->uiBsPos = 0; | 119 | iReturn = SetSliceBoundaryInfo(m_pCtx->pCurDqLayer, m_pSlice, m_iSliceIdx); |
| 121 | m_pSliceBs->iNalIndex = 0; | 120 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) |
| 122 | 121 | ||
| 123 | m_pCtx->iEncoderError = SetSliceBoundaryInfo(m_pCtx->pCurDqLayer, m_pSlice, m_iSliceIdx); | 122 | m_pCtx->iEncoderError = SetSliceBoundaryInfo(m_pCtx->pCurDqLayer, m_pSlice, m_iSliceIdx); |
| 124 | WELS_VERIFY_RETURN_IFNEQ (m_pCtx->iEncoderError, ENC_RETURN_SUCCESS) | 123 | WELS_VERIFY_RETURN_IFNEQ (m_pCtx->iEncoderError, ENC_RETURN_SUCCESS) |
| @@ -150,6 +149,7 @@ void CWelsSliceEncodingTask::FinishTask() { · 25 unmodified lines | |||
| 150 | } | 149 | } |
| 151 | 150 | ||
| 152 | WelsErrorType CWelsSliceEncodingTask::ExecuteTask() { | 151 | WelsErrorType CWelsSliceEncodingTask::ExecuteTask() { |
| 152 | |||
| 153 | #if MT_DEBUG_BS_WR | 153 | #if MT_DEBUG_BS_WR |
| 154 | m_pSliceBs->bSliceCodedFlag = false; | 154 | m_pSliceBs->bSliceCodedFlag = false; |
| 155 | #endif//MT_DEBUG_BS_WR | 155 | #endif//MT_DEBUG_BS_WR |
| @@ -176,7 +176,6 @@ WelsErrorType CWelsSliceEncodingTask::ExecuteTask() { · 20 unmodified lines | |||
| 176 | 176 | ||
| 177 | m_iSliceSize = 0; | 177 | m_iSliceSize = 0; |
| 178 | iReturn = WriteSliceBs (m_pCtx, m_pSliceBs, m_iSliceIdx, m_iSliceSize); | 178 | iReturn = WriteSliceBs (m_pCtx, m_pSliceBs, m_iSliceIdx, m_iSliceSize); |
| 179 | |||
| 180 | if (ENC_RETURN_SUCCESS != iReturn) { | 179 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 181 | WelsLog (&m_pCtx->sLogCtx, WELS_LOG_WARNING, | 180 | WelsLog (&m_pCtx->sLogCtx, WELS_LOG_WARNING, |
| 182 | "[MT] CWelsSliceEncodingTask ExecuteTask(), WriteSliceBs not successful: coding_idx %d, um_iSliceIdx %d", | 181 | "[MT] CWelsSliceEncodingTask ExecuteTask(), WriteSliceBs not successful: coding_idx %d, um_iSliceIdx %d", |
| @@ -185,7 +184,7 @@ WelsErrorType CWelsSliceEncodingTask::ExecuteTask() { · 2 unmodified lines | |||
| 185 | return iReturn; | 184 | return iReturn; |
| 186 | } | 185 | } |
| 187 | 186 | ||
| 188 | m_pCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (m_pCtx->pCurDqLayer, m_pCtx->pFuncList, m_iSliceIdx); | 187 | m_pCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (m_pCtx->pCurDqLayer, m_pCtx->pFuncList, m_pSlice); |
| 189 | 188 | ||
| 190 | WelsLog (&m_pCtx->sLogCtx, WELS_LOG_DETAIL, | 189 | WelsLog (&m_pCtx->sLogCtx, WELS_LOG_DETAIL, |
| 191 | "@pSlice=%-6d sliceType:%c idc:%d size:%-6d", m_iSliceIdx, | 190 | "@pSlice=%-6d sliceType:%c idc:%d size:%-6d", m_iSliceIdx, |
| @@ -196,9 +195,7 @@ WelsErrorType CWelsSliceEncodingTask::ExecuteTask() { · 4 unmodified lines | |||
| 196 | #if MT_DEBUG_BS_WR | 195 | #if MT_DEBUG_BS_WR |
| 197 | m_pSliceBs->bSliceCodedFlag = true; | 196 | m_pSliceBs->bSliceCodedFlag = true; |
| 198 | #endif//MT_DEBUG_BS_WR | 197 | #endif//MT_DEBUG_BS_WR |
| 199 | 198 | m_pCtx->pCurDqLayer->sSliceThreadInfo.iEncodedSliceNumInThread[m_iThreadIdx] ++; | |
| 200 | //m_pCtx->pCurDqLayer->sSliceThreadInfo.iEncodedSliceNumInThread[m_iThreadIdx] ++; | ||
| 201 | |||
| 202 | return ENC_RETURN_SUCCESS; | 199 | return ENC_RETURN_SUCCESS; |
| 203 | } | 200 | } |
| 204 | 201 | ||
| @@ -238,38 +235,42 @@ void CWelsLoadBalancingSlicingEncodingTask::FinishTask() { · 33 unmodified lines | |||
| 238 | WelsErrorType CWelsConstrainedSizeSlicingEncodingTask::ExecuteTask() { | 235 | WelsErrorType CWelsConstrainedSizeSlicingEncodingTask::ExecuteTask() { |
| 239 | 236 | ||
| 240 | SDqLayer* pCurDq = m_pCtx->pCurDqLayer; | 237 | SDqLayer* pCurDq = m_pCtx->pCurDqLayer; |
| 241 | SSliceCtx* pSliceCtx = &pCurDq->sSliceEncCtx; | ||
| 242 | const int32_t kiSliceIdxStep = m_pCtx->iActiveThreadsNum; | 238 | const int32_t kiSliceIdxStep = m_pCtx->iActiveThreadsNum; |
| 243 | SSpatialLayerInternal* pParamInternal = &m_pCtx->pSvcParam->sDependencyLayers[m_pCtx->uiDependencyId]; | 239 | SSpatialLayerInternal* pParamInternal = &m_pCtx->pSvcParam->sDependencyLayers[m_pCtx->uiDependencyId]; |
| 244 | const int32_t kiPartitionId = m_iSliceIdx % kiSliceIdxStep; | 240 | const int32_t kiPartitionId = m_iSliceIdx % kiSliceIdxStep; |
| 245 | const int32_t kiFirstMbInPartition = pCurDq->pFirstMbIdxOfPartition[kiPartitionId]; | 241 | const int32_t kiFirstMbInPartition = pCurDq->FirstMbIdxOfPartition[kiPartitionId]; |
| 246 | const int32_t kiEndMbIdxInPartition = pCurDq->pEndMbIdxOfPartition[kiPartitionId]; | 242 | const int32_t kiEndMbIdxInPartition = pCurDq->EndMbIdxOfPartition[kiPartitionId]; |
| 247 | m_pSlice = &pCurDq->sSliceThreadInfo.pSliceInThread[0][m_iSliceIdx]; | 243 | const int32_t kiCodedSliceNumByThread = pCurDq->sSliceThreadInfo.iEncodedSliceNumInThread[m_iThreadIdx]; |
| 244 | m_pSlice = &pCurDq->sSliceThreadInfo.pSliceInThread[m_iThreadIdx][kiCodedSliceNumByThread]; | ||
| 248 | m_pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = kiFirstMbInPartition; | 245 | m_pSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = kiFirstMbInPartition; |
| 249 | pCurDq->pNumSliceCodedOfPartition[kiPartitionId] = 1; | 246 | int32_t iReturn = 0; |
| 250 | pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId] = 0; | 247 | bool bNeedReallocate = false; |
| 251 | 248 | ||
| 252 | //deal with partition: TODO: here SSliceThreadPrivateData is just for parition info and actually has little relationship with threadbuffer, and iThreadIndex is not used in threadpool model, need renaming after removing old logic to avoid confusion | 249 | //deal with partition: TODO: here SSliceThreadPrivateData is just for parition info and actually has little relationship with threadbuffer, and iThreadIndex is not used in threadpool model, need renaming after removing old logic to avoid confusion |
| 250 | int32_t iDiffMbIdx = kiEndMbIdxInPartition - kiFirstMbInPartition; | ||
| 251 | if( 0 == iDiffMbIdx) { | ||
| 252 | m_pSlice->iSliceIdx = -1; | ||
| 253 | return ENC_RETURN_SUCCESS; | ||
| 254 | } | ||
| 253 | 255 | ||
| 254 | int32_t iAnyMbLeftInPartition = kiEndMbIdxInPartition - kiFirstMbInPartition + 1; | 256 | int32_t iAnyMbLeftInPartition = iDiffMbIdx + 1; |
| 255 | int32_t iLocalSliceIdx = m_iSliceIdx; | 257 | int32_t iLocalSliceIdx = m_iSliceIdx; |
| 256 | while (iAnyMbLeftInPartition > 0) { | 258 | while (iAnyMbLeftInPartition > 0) { |
| 257 | //TODO: will reallocate | 259 | bNeedReallocate = (pCurDq->sSliceThreadInfo.iEncodedSliceNumInThread[m_iThreadIdx] |
| 258 | if (iLocalSliceIdx >= pSliceCtx->iMaxSliceNumConstraint) { | 260 | >= pCurDq->sSliceThreadInfo.iMaxSliceNumInThread[m_iThreadIdx] -1) ? true : false; |
| 259 | WelsLog (&m_pCtx->sLogCtx, WELS_LOG_WARNING, | 261 | if (bNeedReallocate) { |
| 260 | "[MT] CWelsConstrainedSizeSlicingEncodingTask ExecuteTask() coding_idx %d, uiLocalSliceIdx %d, pSliceCtx->iMaxSliceNumConstraint %d", | 262 | WelsMutexLock (&m_pCtx->pSliceThreading->mutexThreadSlcBuffReallocate); |
| 261 | pParamInternal->iCodingIndex, | 263 | //for memory statistic variable |
| 262 | iLocalSliceIdx, pSliceCtx->iMaxSliceNumConstraint); | 264 | iReturn = ReallocateSliceInThread(m_pCtx, pCurDq, m_pCtx->uiDependencyId, m_iThreadIdx); |
| 263 | return ENC_RETURN_KNOWN_ISSUE; | 265 | WelsMutexUnlock (&m_pCtx->pSliceThreading->mutexThreadSlcBuffReallocate); |
| 264 | } | 266 | if (ENC_RETURN_SUCCESS != iReturn) { |
| 267 | return iReturn; | ||
| 268 | } | ||
| 269 | } | ||
| 265 | 270 | ||
| 266 | m_pSlice = &pCurDq->sSliceThreadInfo.pSliceInThread[0][iLocalSliceIdx]; | 271 | iReturn = InitOneSliceInThread (m_pCtx, m_pSlice, m_iThreadIdx, m_pCtx->uiDependencyId, iLocalSliceIdx); |
| 272 | WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS) | ||
| 267 | m_pSliceBs = &m_pSlice->sSliceBs; | 273 | m_pSliceBs = &m_pSlice->sSliceBs; |
| 268 | |||
| 269 | m_pSliceBs->uiBsPos = 0; | ||
| 270 | m_pSliceBs->iNalIndex = 0; | ||
| 271 | |||
| 272 | SetOneSliceBsBufferUnderMultithread (m_pCtx, m_iThreadIdx, m_pSlice); | ||
| 273 | InitBits (&m_pSliceBs->sBsWrite, m_pSliceBs->pBsBuffer, m_pSliceBs->uiSize); | 274 | InitBits (&m_pSliceBs->sBsWrite, m_pSliceBs->pBsBuffer, m_pSliceBs->uiSize); |
| 274 | 275 | ||
| 275 | if (m_bNeedPrefix) { | 276 | if (m_bNeedPrefix) { |
| @@ -302,7 +303,7 @@ WelsErrorType CWelsConstrainedSizeSlicingEncodingTask::ExecuteTask() { · 26 unmodified lines | |||
| 302 | return iReturn; | 303 | return iReturn; |
| 303 | } | 304 | } |
| 304 | 305 | ||
| 305 | m_pCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, m_pCtx->pFuncList, iLocalSliceIdx); | 306 | m_pCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, m_pCtx->pFuncList, m_pSlice); |
| 306 | 307 | ||
| 307 | WelsLog (&m_pCtx->sLogCtx, WELS_LOG_DETAIL, | 308 | WelsLog (&m_pCtx->sLogCtx, WELS_LOG_DETAIL, |
| 308 | "@pSlice=%-6d sliceType:%c idc:%d size:%-6d\n", | 309 | "@pSlice=%-6d sliceType:%c idc:%d size:%-6d\n", |
| @@ -313,12 +314,14 @@ WelsErrorType CWelsConstrainedSizeSlicingEncodingTask::ExecuteTask() { · 4 unmodified lines | |||
| 313 | ); | 314 | ); |
| 314 | 315 | ||
| 315 | WelsLog (&m_pCtx->sLogCtx, WELS_LOG_DEBUG, | 316 | WelsLog (&m_pCtx->sLogCtx, WELS_LOG_DEBUG, |
| 316 | "[MT] CWelsConstrainedSizeSlicingEncodingTask(), coding_idx %d, iPartitionId %d, m_iThreadIdx %d, iLocalSliceIdx %d, m_iSliceSize %d, ParamValidationExt(), invalid uiMaxNalSizeiEndMbInPartition %d, pCurDq->pLastCodedMbIdxOfPartition[%d] %d\n", | 317 | "[MT] CWelsConstrainedSizeSlicingEncodingTask(), coding_idx %d, iPartitionId %d, m_iThreadIdx %d, iLocalSliceIdx %d, m_iSliceSize %d, ParamValidationExt(), invalid uiMaxNalSizeiEndMbInPartition %d, pCurDq->LastCodedMbIdxOfPartition[%d] %d\n", |
| 317 | pParamInternal->iCodingIndex, kiPartitionId, m_iThreadIdx, iLocalSliceIdx, m_iSliceSize, | 318 | pParamInternal->iCodingIndex, kiPartitionId, m_iThreadIdx, iLocalSliceIdx, m_iSliceSize, |
| 318 | kiEndMbIdxInPartition, kiPartitionId, pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId]); | 319 | kiEndMbIdxInPartition, kiPartitionId, pCurDq->LastCodedMbIdxOfPartition[kiPartitionId]); |
| 319 | 320 | ||
| 320 | iAnyMbLeftInPartition = kiEndMbIdxInPartition - pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId]; | 321 | iAnyMbLeftInPartition = kiEndMbIdxInPartition - pCurDq->LastCodedMbIdxOfPartition[kiPartitionId]; |
| 321 | iLocalSliceIdx += kiSliceIdxStep; | 322 | iLocalSliceIdx += kiSliceIdxStep; |
| 323 | m_pCtx->pCurDqLayer->sSliceThreadInfo.iEncodedSliceNumInThread[m_iThreadIdx] ++; | ||
| 324 | |||
| 322 | } | 325 | } |
| 323 | 326 | ||
| 324 | return ENC_RETURN_SUCCESS; | 327 | return ENC_RETURN_SUCCESS; |