Merge pull request #2088 from shihuade/RDBugFixed_V2.1_Push

replace LayerBsInfo with FrameBsInfo in thread-based private data str…
This commit is contained in:
HaiboZhu 2015-08-28 10:04:16 +08:00
commit 96de6e0158
7 changed files with 41 additions and 23 deletions

View File

@ -112,6 +112,7 @@ void WelsEncoderApplyFrameRate (SWelsSvcCodingParam* pParam);
int32_t WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int32_t iLayer);
int32_t WelsEncoderApplyBitVaryRang(SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int32_t iRang);
int32_t WelsEncoderApplyLTR (SLogContext* pLogCtx, sWelsEncCtx** ppCtx, SLTRConfig* pLTRValue);
int32_t DynSliceRealloc(sWelsEncCtx* pCtx,SFrameBSInfo* pFrameBsInfo,SLayerBSInfo* pLayerBsInfo);
int32_t FilterLTRRecoveryRequest (sWelsEncCtx* pCtx, SLTRRecoverRequest* pLTRRecoverRequest);
void CheckProfileSetting (SLogContext* pLogCtx,SWelsSvcCodingParam* pParam,int32_t iLayer, EProfileIdc uiProfileIdc);
void CheckLevelSetting (SLogContext* pLogCtx,SWelsSvcCodingParam* pParam,int32_t iLayer, ELevelIdc uiLevelIdc);

View File

@ -57,7 +57,7 @@
typedef struct TagSliceThreadPrivateData {
void* pWelsPEncCtx;
SLayerBSInfo* pLayerBs;
SFrameBSInfo* pFrameBsInfo;
int32_t iSliceIndex; // slice index, zero based
int32_t iThreadIndex; // thread index, zero based

View File

@ -77,7 +77,7 @@ int32_t* pNalLen;
int32_t iCountNals; // count number of NAL in list
// SVC: num_sps (MAX_D) + num_pps (MAX_D) + num_vcl (MAX_D * MAX_Q)
int32_t iNalIndex; // coding NAL currently, 0 based
int32_t iLayerBsIndex; // layer index of bit stream for SFrameBsIfo
// bool bAnnexBFlag; // annexeb flag, to figure it pOut the packetization mode whether need 4 bytes (0 0 0 1) of start code prefix
} SWelsEncoderOutput;

View File

@ -80,8 +80,8 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg);
int32_t CreateSliceThreads (sWelsEncCtx* pCtx);
int32_t FiredSliceThreads (sWelsEncCtx* pCtx, SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList,
WELS_EVENT* pMasterEventsList, SLayerBSInfo* pLayerBsInfo,
const uint32_t kuiNumThreads/*, int32_t *iLayerNum*/, SSliceCtx* pSliceCtx, const bool kbIsDynamicSlicingMode);
WELS_EVENT* pMasterEventsList, SFrameBSInfo* pFrameBsInfo,
const uint32_t kuiNumThreads, SSliceCtx* pSliceCtx, const bool kbIsDynamicSlicingMode);
int32_t DynamicDetectCpuCores();

View File

@ -233,6 +233,7 @@ void InitFrameCoding (sWelsEncCtx* pEncCtx, const EVideoFrameType keFrameType) {
// for bitstream writing
pEncCtx->iPosBsBuffer = 0; // reset bs pBuffer position
pEncCtx->pOut->iNalIndex = 0; // reset NAL index
pEncCtx->pOut->iLayerBsIndex = 0; // reset index of Layer Bs
InitBits (&pEncCtx->pOut->sBsWrite, pEncCtx->pOut->pBsBuffer, pEncCtx->pOut->uiSize);

View File

@ -1812,8 +1812,9 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx, SExistingParasetList* pExistingPa
WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut->sNalList), FreeMemorySvc (ppCtx))
(*ppCtx)->pOut->pNalLen = (int32_t*)pMa->WelsMallocz (iCountNals * sizeof (int32_t), "pOut->pNalLen");
WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut->pNalLen), FreeMemorySvc (ppCtx))
(*ppCtx)->pOut->iCountNals = iCountNals;
(*ppCtx)->pOut->iNalIndex = 0;
(*ppCtx)->pOut->iCountNals = iCountNals;
(*ppCtx)->pOut->iNalIndex = 0;
(*ppCtx)->pOut->iLayerBsIndex = 0;
(*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iTotalLength, "pFrameBs");
@ -3520,8 +3521,10 @@ int32_t WriteSsvcParaset (sWelsEncCtx* pCtx, const int32_t kiSpatialNum,
//point to next pLayerBsInfo
++ pLayerBsInfo;
++ pCtx->pOut->iLayerBsIndex;
pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
//update for external countings
++ iLayerNum;
iFrameSize += iNonVclSize;
@ -3557,6 +3560,7 @@ int32_t WriteSavcParaset (sWelsEncCtx* pCtx, const int32_t kiSpatialNum,
//point to next pLayerBsInfo
++ pLayerBsInfo;
++ pCtx->pOut->iLayerBsIndex;
pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
//update for external countings
@ -3588,6 +3592,7 @@ int32_t WriteSavcParaset (sWelsEncCtx* pCtx, const int32_t kiSpatialNum,
//point to next pLayerBsInfo
++ pLayerBsInfo;
++ pCtx->pOut->iLayerBsIndex;
pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
//update for external countings
@ -3636,6 +3641,7 @@ int32_t WriteSavcParaset_Listing (sWelsEncCtx* pCtx, const int32_t kiSpatialNum,
//point to next pLayerBsInfo
++ pLayerBsInfo;
++ pCtx->pOut->iLayerBsIndex;
pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
//update for external countings
@ -3671,6 +3677,7 @@ int32_t WriteSavcParaset_Listing (sWelsEncCtx* pCtx, const int32_t kiSpatialNum,
//point to next pLayerBsInfo
++ pLayerBsInfo;
++ pCtx->pOut->iLayerBsIndex;
pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
//update for external countings
@ -3692,8 +3699,9 @@ int32_t WriteSavcParaset_Listing (sWelsEncCtx* pCtx, const int32_t kiSpatialNum,
void StackBackEncoderStatus (sWelsEncCtx* pEncCtx,
EVideoFrameType keFrameType) {
// for bitstream writing
pEncCtx->iPosBsBuffer = 0; // reset bs pBuffer position
pEncCtx->pOut->iNalIndex = 0; // reset NAL index
pEncCtx->iPosBsBuffer = 0; // reset bs pBuffer position
pEncCtx->pOut->iNalIndex = 0; // reset NAL index
pEncCtx->pOut->iLayerBsIndex = 0; // reset index of Layer Bs
InitBits (&pEncCtx->pOut->sBsWrite, pEncCtx->pOut->pBsBuffer, pEncCtx->pOut->uiSize);
if ((keFrameType == videoFrameTypeP) || (keFrameType == videoFrameTypeI)) {
@ -4033,7 +4041,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
iRet = FiredSliceThreads (pCtx, &pCtx->pSliceThreading->pThreadPEncCtx[0],
&pCtx->pSliceThreading->pReadySliceCodingEvent[0],
&pCtx->pSliceThreading->pThreadMasterEvent[0],
pLayerBsInfo, iSliceCount, pCtx->pCurDqLayer->pSliceEncCtx, false);
pFbi, iSliceCount, pCtx->pCurDqLayer->pSliceEncCtx, false);
if (iRet) {
WelsLog (pLogCtx, WELS_LOG_ERROR,
"[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!",
@ -4073,7 +4081,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
iRet = FiredSliceThreads (pCtx, &pCtx->pSliceThreading->pThreadPEncCtx[0],
&pCtx->pSliceThreading->pReadySliceCodingEvent[0],
&pCtx->pSliceThreading->pThreadMasterEvent[0],
pLayerBsInfo, iNumThreadsRunning, pCtx->pCurDqLayer->pSliceEncCtx, false);
pFbi, iNumThreadsRunning, pCtx->pCurDqLayer->pSliceEncCtx, false);
if (iRet) {
WelsLog (pLogCtx, WELS_LOG_ERROR,
"[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!",
@ -4120,7 +4128,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
iRet = FiredSliceThreads (pCtx, &pCtx->pSliceThreading->pThreadPEncCtx[0],
&pCtx->pSliceThreading->pReadySliceCodingEvent[0],
&pCtx->pSliceThreading->pThreadMasterEvent[0],
pLayerBsInfo, kiPartitionCnt, pCtx->pCurDqLayer->pSliceEncCtx, true);
pFbi, kiPartitionCnt, pCtx->pCurDqLayer->pSliceEncCtx, true);
if (iRet) {
WelsLog (pLogCtx, WELS_LOG_ERROR,
"[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!",
@ -4332,6 +4340,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
iCountNal = pLayerBsInfo->iNalCount;
++ iLayerNum;
++ pLayerBsInfo;
++ pCtx->pOut->iLayerBsIndex;
pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + iCountNal;
@ -4360,6 +4369,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
pLayerBsInfo->iNalCount = 1;
pLayerBsInfo->pNalLengthInByte[0] = iPaddingNalSize;
++ pLayerBsInfo;
++ pCtx->pOut->iLayerBsIndex;
pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
pLayerBsInfo->pNalLengthInByte = (pLayerBsInfo - 1)->pNalLengthInByte + 1;
++ iLayerNum;
@ -4928,6 +4938,7 @@ int32_t DynSliceRealloc (sWelsEncCtx* pCtx,
pCurLayer->pSliceEncCtx->iMaxSliceNumConstraint = iMaxSliceNum;
return ENC_RETURN_SUCCESS;
}
int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx,
SFrameBSInfo* pFrameBSInfo,
SLayerBSInfo* pLayerBsInfo,

View File

@ -602,7 +602,7 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32
while (iIdx < kiCountSlicesCoded) {
pSliceBs = &pCtx->pSliceBs[iSliceIdx];
if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) {
if (iPartitionIdx > 0) {
if (iSliceIdx > 0) {
int32_t iNalIdx = 0;
const int32_t iCountNal = pSliceBs->iNalIndex;
@ -706,7 +706,10 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) {
&pEventsList[0],
&pEncPEncCtx->pSliceThreading->pThreadMasterEvent[iEventIdx]); // blocking until at least one event is signalled
if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) { // start pSlice coding signal waited
SLayerBSInfo* pLbi = pPrivateData->pLayerBs;
int iLayerIndex = pEncPEncCtx->pOut->iLayerBsIndex;
SFrameBSInfo* pFrameBsInfo = pPrivateData->pFrameBsInfo;
SLayerBSInfo* pLbi = &pFrameBsInfo->sLayerInfo [iLayerIndex];
const int32_t kiCurDid = pEncPEncCtx->uiDependencyId;
SWelsSvcCodingParam* pCodingParam = pEncPEncCtx->pSvcParam;
SSpatialLayerConfig* pParamD = &pCodingParam->sSpatialLayers[kiCurDid];
@ -868,7 +871,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) {
WelsUnloadNalForSlice (pSliceBs);
if (0 == kiPartitionId) {
if (0 == iSliceIdx) {
iReturn = WriteSliceBs (pEncPEncCtx, pLbi->pBsBuf,
&pLbi->pNalLengthInByte[pLbi->iNalCount],
pEncPEncCtx->iFrameBsSize - pEncPEncCtx->iPosBsBuffer,
@ -969,16 +972,18 @@ int32_t CreateSliceThreads (sWelsEncCtx* pCtx) {
}
int32_t FiredSliceThreads (sWelsEncCtx* pCtx, SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList,
WELS_EVENT* pMasterEventsList, SLayerBSInfo* pLbi,
WELS_EVENT* pMasterEventsList, SFrameBSInfo* pFrameBsInfo,
const uint32_t uiNumThreads, SSliceCtx* pSliceCtx, const bool bIsDynamicSlicingMode) {
int32_t iEndMbIdx = 0;
int32_t iIdx = 0;
const int32_t kiEventCnt = uiNumThreads;
int32_t iEndMbIdx = 0;
int32_t iIdx = 0;
const int32_t kiEventCnt = uiNumThreads;
int32_t iLayerBsIdx = pCtx->pOut->iLayerBsIndex;
SLayerBSInfo* pLbi = &pFrameBsInfo->sLayerInfo[iLayerBsIdx];
if (pPriData == NULL || pLbi == NULL || kiEventCnt <= 0 || pEventsList == NULL) {
if (pPriData == NULL || pFrameBsInfo == NULL || pLbi == NULL || kiEventCnt <= 0 || pEventsList == NULL) {
WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR,
"FiredSliceThreads(), fail due pPriData == %p || pLbi == %p || iEventCnt(%d) <= 0 || pEventsList == %p!!",
(void*)pPriData, (void*)pLbi, uiNumThreads, (void*)pEventsList);
"FiredSliceThreads(), fail due pPriData == %p ||pFrameBsInfo == %p || pLbi == %p || iEventCnt(%d) <= 0 || pEventsList == %p!!",
(void*)pPriData, (void*)pFrameBsInfo, (void*)pLbi, uiNumThreads, (void*)pEventsList);
return 1;
}
@ -1003,8 +1008,8 @@ int32_t FiredSliceThreads (sWelsEncCtx* pCtx, SSliceThreadPrivateData* pPriData,
iIdx = 0;
while (iIdx < kiEventCnt) {
pPriData[iIdx].pLayerBs = pLbi;
pPriData[iIdx].iSliceIndex = iIdx;
pPriData[iIdx].pFrameBsInfo = pFrameBsInfo;
pPriData[iIdx].iSliceIndex = iIdx;
SetOneSliceBsBufferUnderMultithread (pCtx, iIdx, iIdx);
if (pEventsList[iIdx])
WelsEventSignal (&pEventsList[iIdx]);