History

re-structure SWelsDecoderContext and others and prepare for the support of multi-threading support.

xiaotiansf committed 7 years ago

Commit 2f5ecec1 parent 9ed97c729 files · +2285 −1568Browse files

Showing the changes to codec/decoder/plus/src/welsDecoderExt.cpp (1 of 29 files). Show all

Unified · Split

codec/decoder/plus/src/welsDecoderExt.cpp+50−38
@@ -257,6 +257,10 @@ int32_t CWelsDecoder::InitDecoder (const SDecodingParam* pParam) { · 256 unmodified lines
257 VERSION_NUMBER, (int32_t)pParam->bParseOnly);257 VERSION_NUMBER, (int32_t)pParam->bParseOnly);
258 258
259 //reset decoder context259 //reset decoder context
260 memset (&m_sDecoderStatistics, 0, sizeof (SDecoderStatistics));
261 memset (&m_sLastDecPicInfo, 0, sizeof (SWelsLastDecPicInfo));
262 memset (&m_sVlcTable, 0, sizeof (SVlcTable));
263 WelsDecoderLastDecPicInfoDefaults (m_sLastDecPicInfo);
260 if (m_pDecContext) //free264 if (m_pDecContext) //free
261 UninitDecoder();265 UninitDecoder();
262 m_pDecContext = (PWelsDecoderContext)WelsMallocz (sizeof (SWelsDecoderContext), "m_pDecContext");266 m_pDecContext = (PWelsDecoderContext)WelsMallocz (sizeof (SWelsDecoderContext), "m_pDecContext");
@@ -267,7 +271,11 @@ int32_t CWelsDecoder::InitDecoder (const SDecodingParam* pParam) { · 4 unmodified lines
267 WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, (NULL == m_pDecContext->pMemAlign), UninitDecoder())271 WELS_VERIFY_RETURN_PROC_IF (cmMallocMemeError, (NULL == m_pDecContext->pMemAlign), UninitDecoder())
268 272
269 //fill in default value into context273 //fill in default value into context
274 m_pDecContext->pLastDecPicInfo = &m_sLastDecPicInfo;
275 m_pDecContext->pDecoderStatistics = &m_sDecoderStatistics;
276 m_pDecContext->pVlcTable = &m_sVlcTable;
270 WelsDecoderDefaults (m_pDecContext, &m_pWelsTrace->m_sLogCtx);277 WelsDecoderDefaults (m_pDecContext, &m_pWelsTrace->m_sLogCtx);
278 WelsDecoderSpsPpsDefaults (m_pDecContext->sSpsPpsCtx);
271 279
272 //check param and update decoder context280 //check param and update decoder context
273 m_pDecContext->pParam = (SDecodingParam*)m_pDecContext->pMemAlign->WelsMallocz (sizeof (SDecodingParam),281 m_pDecContext->pParam = (SDecodingParam*)m_pDecContext->pMemAlign->WelsMallocz (sizeof (SDecodingParam),
@@ -364,7 +372,7 @@ long CWelsDecoder::SetOption (DECODER_OPTION eOptID, void* pOption) { · 90 unmodified lines
364 return cmInitParaError;372 return cmInitParaError;
365 } else if (eOptID == DECODER_OPTION_STATISTICS_LOG_INTERVAL) {373 } else if (eOptID == DECODER_OPTION_STATISTICS_LOG_INTERVAL) {
366 if (pOption) {374 if (pOption) {
367 m_pDecContext->sDecoderStatistics.iStatisticsLogInterval = (* ((unsigned int*)pOption));375 m_pDecContext->pDecoderStatistics->iStatisticsLogInterval = (* ((unsigned int*)pOption));
368 return cmResultSuccess;376 return cmResultSuccess;
369 }377 }
370 } else if (eOptID == DECODER_OPTION_GET_SAR_INFO) {378 } else if (eOptID == DECODER_OPTION_GET_SAR_INFO) {
@@ -432,19 +440,19 @@ long CWelsDecoder::GetOption (DECODER_OPTION eOptID, void* pOption) { · 61 unmodified lines
432 } else if (DECODER_OPTION_GET_STATISTICS == eOptID) { // get decoder statistics info for real time debugging440 } else if (DECODER_OPTION_GET_STATISTICS == eOptID) { // get decoder statistics info for real time debugging
433 SDecoderStatistics* pDecoderStatistics = (static_cast<SDecoderStatistics*> (pOption));441 SDecoderStatistics* pDecoderStatistics = (static_cast<SDecoderStatistics*> (pOption));
434 442
435 memcpy (pDecoderStatistics, &m_pDecContext->sDecoderStatistics, sizeof (SDecoderStatistics));443 memcpy (pDecoderStatistics, m_pDecContext->pDecoderStatistics, sizeof (SDecoderStatistics));
436 444
437 if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount != 0) { //not original status445 if (m_pDecContext->pDecoderStatistics->uiDecodedFrameCount != 0) { //not original status
438 pDecoderStatistics->fAverageFrameSpeedInMs = (float) (m_pDecContext->dDecTime) /446 pDecoderStatistics->fAverageFrameSpeedInMs = (float) (m_pDecContext->dDecTime) /
439 (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount);447 (m_pDecContext->pDecoderStatistics->uiDecodedFrameCount);
440 pDecoderStatistics->fActualAverageFrameSpeedInMs = (float) (m_pDecContext->dDecTime) /448 pDecoderStatistics->fActualAverageFrameSpeedInMs = (float) (m_pDecContext->dDecTime) /
441 (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount + m_pDecContext->sDecoderStatistics.uiFreezingIDRNum +449 (m_pDecContext->pDecoderStatistics->uiDecodedFrameCount + m_pDecContext->pDecoderStatistics->uiFreezingIDRNum +
442 m_pDecContext->sDecoderStatistics.uiFreezingNonIDRNum);450 m_pDecContext->pDecoderStatistics->uiFreezingNonIDRNum);
443 }451 }
444 return cmResultSuccess;452 return cmResultSuccess;
445 } else if (eOptID == DECODER_OPTION_STATISTICS_LOG_INTERVAL) {453 } else if (eOptID == DECODER_OPTION_STATISTICS_LOG_INTERVAL) {
446 if (pOption) {454 if (pOption) {
447 iVal = m_pDecContext->sDecoderStatistics.iStatisticsLogInterval;455 iVal = m_pDecContext->pDecoderStatistics->iStatisticsLogInterval;
448 * ((unsigned int*)pOption) = iVal;456 * ((unsigned int*)pOption) = iVal;
449 return cmResultSuccess;457 return cmResultSuccess;
450 }458 }
@@ -626,30 +634,30 @@ DECODING_STATE CWelsDecoder::DecodeFrame2 (const unsigned char* kpSrc, · 175 unmodified lines
626 //TODO after dec status updated634 //TODO after dec status updated
627 m_pDecContext->iErrorCode |= dsDataErrorConcealed;635 m_pDecContext->iErrorCode |= dsDataErrorConcealed;
628 636
629 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;637 m_pDecContext->pDecoderStatistics->uiDecodedFrameCount++;
630 if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount == 0) { //exceed max value of uint32_t638 if (m_pDecContext->pDecoderStatistics->uiDecodedFrameCount == 0) { //exceed max value of uint32_t
631 ResetDecStatNums (&m_pDecContext->sDecoderStatistics);639 ResetDecStatNums (m_pDecContext->pDecoderStatistics);
632 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;640 m_pDecContext->pDecoderStatistics->uiDecodedFrameCount++;
633 }641 }
634 int32_t iMbConcealedNum = m_pDecContext->iMbEcedNum + m_pDecContext->iMbEcedPropNum;642 int32_t iMbConcealedNum = m_pDecContext->iMbEcedNum + m_pDecContext->iMbEcedPropNum;
635 m_pDecContext->sDecoderStatistics.uiAvgEcRatio = m_pDecContext->iMbNum == 0 ?643 m_pDecContext->pDecoderStatistics->uiAvgEcRatio = m_pDecContext->iMbNum == 0 ?
636 (m_pDecContext->sDecoderStatistics.uiAvgEcRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) : ((644 (m_pDecContext->pDecoderStatistics->uiAvgEcRatio * m_pDecContext->pDecoderStatistics->uiEcFrameNum) : ((
637 m_pDecContext->sDecoderStatistics.uiAvgEcRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) + ((645 m_pDecContext->pDecoderStatistics->uiAvgEcRatio * m_pDecContext->pDecoderStatistics->uiEcFrameNum) + ((
638 iMbConcealedNum * 100) / m_pDecContext->iMbNum));646 iMbConcealedNum * 100) / m_pDecContext->iMbNum));
639 m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio = m_pDecContext->iMbNum == 0 ?647 m_pDecContext->pDecoderStatistics->uiAvgEcPropRatio = m_pDecContext->iMbNum == 0 ?
640 (m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) : ((648 (m_pDecContext->pDecoderStatistics->uiAvgEcPropRatio * m_pDecContext->pDecoderStatistics->uiEcFrameNum) : ((
641 m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio * m_pDecContext->sDecoderStatistics.uiEcFrameNum) + ((649 m_pDecContext->pDecoderStatistics->uiAvgEcPropRatio * m_pDecContext->pDecoderStatistics->uiEcFrameNum) + ((
642 m_pDecContext->iMbEcedPropNum * 100) / m_pDecContext->iMbNum));650 m_pDecContext->iMbEcedPropNum * 100) / m_pDecContext->iMbNum));
643 m_pDecContext->sDecoderStatistics.uiEcFrameNum += (iMbConcealedNum == 0 ? 0 : 1);651 m_pDecContext->pDecoderStatistics->uiEcFrameNum += (iMbConcealedNum == 0 ? 0 : 1);
644 m_pDecContext->sDecoderStatistics.uiAvgEcRatio = m_pDecContext->sDecoderStatistics.uiEcFrameNum == 0 ? 0 :652 m_pDecContext->pDecoderStatistics->uiAvgEcRatio = m_pDecContext->pDecoderStatistics->uiEcFrameNum == 0 ? 0 :
645 m_pDecContext->sDecoderStatistics.uiAvgEcRatio / m_pDecContext->sDecoderStatistics.uiEcFrameNum;653 m_pDecContext->pDecoderStatistics->uiAvgEcRatio / m_pDecContext->pDecoderStatistics->uiEcFrameNum;
646 m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio = m_pDecContext->sDecoderStatistics.uiEcFrameNum == 0 ? 0 :654 m_pDecContext->pDecoderStatistics->uiAvgEcPropRatio = m_pDecContext->pDecoderStatistics->uiEcFrameNum == 0 ? 0 :
647 m_pDecContext->sDecoderStatistics.uiAvgEcPropRatio / m_pDecContext->sDecoderStatistics.uiEcFrameNum;655 m_pDecContext->pDecoderStatistics->uiAvgEcPropRatio / m_pDecContext->pDecoderStatistics->uiEcFrameNum;
648 }656 }
649 iEnd = WelsTime();657 iEnd = WelsTime();
650 m_pDecContext->dDecTime += (iEnd - iStart) / 1e3;658 m_pDecContext->dDecTime += (iEnd - iStart) / 1e3;
651 659
652 OutputStatisticsLog (m_pDecContext->sDecoderStatistics);660 OutputStatisticsLog (*m_pDecContext->pDecoderStatistics);
653 661
654#ifdef _PICTURE_REORDERING_662#ifdef _PICTURE_REORDERING_
655 ReorderPicturesInDisplay (ppDst, pDstInfo);663 ReorderPicturesInDisplay (ppDst, pDstInfo);
@@ -661,13 +669,13 @@ DECODING_STATE CWelsDecoder::DecodeFrame2 (const unsigned char* kpSrc, · 5 unmodified lines
661 669
662 if (pDstInfo->iBufferStatus == 1) {670 if (pDstInfo->iBufferStatus == 1) {
663 671
664 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;672 m_pDecContext->pDecoderStatistics->uiDecodedFrameCount++;
665 if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount == 0) { //exceed max value of uint32_t673 if (m_pDecContext->pDecoderStatistics->uiDecodedFrameCount == 0) { //exceed max value of uint32_t
666 ResetDecStatNums (&m_pDecContext->sDecoderStatistics);674 ResetDecStatNums (m_pDecContext->pDecoderStatistics);
667 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;675 m_pDecContext->pDecoderStatistics->uiDecodedFrameCount++;
668 }676 }
669 677
670 OutputStatisticsLog (m_pDecContext->sDecoderStatistics);678 OutputStatisticsLog (*m_pDecContext->pDecoderStatistics);
671 }679 }
672 iEnd = WelsTime();680 iEnd = WelsTime();
673 m_pDecContext->dDecTime += (iEnd - iStart) / 1e3;681 m_pDecContext->dDecTime += (iEnd - iStart) / 1e3;
@@ -761,19 +769,22 @@ void CWelsDecoder::OutputStatisticsLog (SDecoderStatistics& sDecoderStatistics) · 87 unmodified lines
761 769
762DECODING_STATE CWelsDecoder::ReorderPicturesInDisplay (unsigned char** ppDst, SBufferInfo* pDstInfo) {770DECODING_STATE CWelsDecoder::ReorderPicturesInDisplay (unsigned char** ppDst, SBufferInfo* pDstInfo) {
763 DECODING_STATE iRet = dsErrorFree;771 DECODING_STATE iRet = dsErrorFree;
764 if (pDstInfo->iBufferStatus == 1 && m_pDecContext->pSps->uiProfileIdc != 66772 if (pDstInfo->iBufferStatus == 0) {
765 && m_pDecContext->pSps->uiProfileIdc != 83) {773 return iRet;
774 }
775 ++m_pDecContext->uiDecodingTimeStamp;
776 if (m_pDecContext->pSps->uiProfileIdc != 66 && m_pDecContext->pSps->uiProfileIdc != 83) {
766 /*if (m_pDecContext->pSliceHeader->iPicOrderCntLsb == 0) {777 /*if (m_pDecContext->pSliceHeader->iPicOrderCntLsb == 0) {
767 m_LastWrittenPOC = 0;778 m_LastWrittenPOC = 0;
768 return dsErrorFree;779 return dsErrorFree;
769 }780 }
770 if (m_iNumOfPicts == 0 && m_pDecContext->pPreviousDecodedPictureInDpb->bNewSeqBegin781 if (m_iNumOfPicts == 0 && m_pDecContext->pLastDecPicInfo->pPreviousDecodedPictureInDpb->bNewSeqBegin
771 && m_pDecContext->eSliceType != I_SLICE) {782 && m_pDecContext->eSliceType != I_SLICE) {
772 m_LastWrittenPOC = m_pDecContext->pSliceHeader->iPicOrderCntLsb;783 m_LastWrittenPOC = m_pDecContext->pSliceHeader->iPicOrderCntLsb;
773 return dsErrorFree;784 return dsErrorFree;
774 }*/785 }*/
775 if (m_iNumOfPicts && m_pDecContext->pPreviousDecodedPictureInDpb786 if (m_iNumOfPicts && m_pDecContext->pLastDecPicInfo->pPreviousDecodedPictureInDpb
776 && m_pDecContext->pPreviousDecodedPictureInDpb->bNewSeqBegin) {787 && m_pDecContext->pLastDecPicInfo->pPreviousDecodedPictureInDpb->bNewSeqBegin) {
777 m_iLastGOPRemainPicts = m_iNumOfPicts;788 m_iLastGOPRemainPicts = m_iNumOfPicts;
778 for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) {789 for (int32_t i = 0; i <= m_iLargestBufferedPicIndex; ++i) {
779 if (m_sPictInfoList[i].iPOC > sIMinInt32) {790 if (m_sPictInfoList[i].iPOC > sIMinInt32) {
@@ -807,7 +818,8 @@ DECODING_STATE CWelsDecoder::ReorderPicturesInDisplay (unsigned char** ppDst, SB · 27 unmodified lines
807 m_sPictInfoList[i].pData[1] = ppDst[1];818 m_sPictInfoList[i].pData[1] = ppDst[1];
808 m_sPictInfoList[i].pData[2] = ppDst[2];819 m_sPictInfoList[i].pData[2] = ppDst[2];
809 m_sPictInfoList[i].iPOC = m_pDecContext->pSliceHeader->iPicOrderCntLsb;820 m_sPictInfoList[i].iPOC = m_pDecContext->pSliceHeader->iPicOrderCntLsb;
810 m_sPictInfoList[i].iPicBuffIdx = m_pDecContext->pPicBuff->iCurrentIdx;821 m_sPictInfoList[i].uiDecodingTimeStamp = m_pDecContext->uiDecodingTimeStamp;
822 m_sPictInfoList[i].iPicBuffIdx = m_pDecContext->pLastDecPicInfo->pPreviousDecodedPictureInDpb->iPicBuffIdx;
811 m_pDecContext->pPicBuff->ppPic[m_sPictInfoList[i].iPicBuffIdx]->bAvailableFlag = false;823 m_pDecContext->pPicBuff->ppPic[m_sPictInfoList[i].iPicBuffIdx]->bAvailableFlag = false;
812 m_sPictInfoList[i].bLastGOP = false;824 m_sPictInfoList[i].bLastGOP = false;
813 pDstInfo->iBufferStatus = 0;825 pDstInfo->iBufferStatus = 0;
@@ -955,10 +967,10 @@ DECODING_STATE CWelsDecoder::DecodeParser (const unsigned char* kpSrc, · 141 unmodified lines
955 memcpy (pDstInfo, m_pDecContext->pParserBsInfo, sizeof (SParserBsInfo));967 memcpy (pDstInfo, m_pDecContext->pParserBsInfo, sizeof (SParserBsInfo));
956 968
957 if (m_pDecContext->iErrorCode == ERR_NONE) { //update statistics: decoding frame count969 if (m_pDecContext->iErrorCode == ERR_NONE) { //update statistics: decoding frame count
958 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;970 m_pDecContext->pDecoderStatistics->uiDecodedFrameCount++;
959 if (m_pDecContext->sDecoderStatistics.uiDecodedFrameCount == 0) { //exceed max value of uint32_t971 if (m_pDecContext->pDecoderStatistics->uiDecodedFrameCount == 0) { //exceed max value of uint32_t
960 ResetDecStatNums (&m_pDecContext->sDecoderStatistics);972 ResetDecStatNums (m_pDecContext->pDecoderStatistics);
961 m_pDecContext->sDecoderStatistics.uiDecodedFrameCount++;973 m_pDecContext->pDecoderStatistics->uiDecodedFrameCount++;
962 }974 }
963 }975 }
964 }976 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t