History

Merge pull request #713 from licaiguo/overwriteactivesps

overwriteactivesps

huili2 committed 12 years ago

Commit 7d99aa42 parents 9b03223 79ed7444 files · +114 −51Browse files

Showing the changes to codec/decoder (4 of 4 files). Show all

Unified · Split

4 files
  1. codec/decoder/core/inc/decoder_context.h +11 −3
  2. codec/decoder/core/src/au_parser.cpp +63 −19
  3. codec/decoder/core/src/decoder.cpp +23 −27
  4. codec/decoder/core/src/decoder_core.cpp +17 −2
codec/decoder/core/inc/decoder_context.h+11−3
@@ -156,6 +156,13 @@ typedef struct TagExpandPicFunc { · 155 unmodified lines
156156 PExpandPictureFunc pExpandChromaPicture[2];
157157 } SExpandPicFunc;
158158
159+enum {
160+ OVERWRITE_NONE = 0,
161+ OVERWRITE_PPS = 1,
162+ OVERWRITE_SPS = 1 << 1,
163+ OVERWRITE_SUBSETSPS = 1 << 2
164+};
165+
159166 /*
160167 * SWelsDecoderContext: to maintail all modules data over decoder@framework
161168 */
@@ -231,14 +238,14 @@ typedef struct TagWelsDecoderContext { · 69 unmodified lines
231238
232239 SPosOffset sFrameCrop;
233240
234− SSps sSpsBuffer[MAX_SPS_COUNT];
235− SPps sPpsBuffer[MAX_PPS_COUNT];
241+ SSps sSpsBuffer[MAX_SPS_COUNT + 1];
242+ SPps sPpsBuffer[MAX_PPS_COUNT + 1];
236243 PSliceHeader pSliceHeader;
237244
238245 PPicBuff pPicBuff[LIST_A]; // Initially allocated memory for pictures which are used in decoding.
239246 int32_t iPicQueueNumber;
240247
241− SSubsetSps sSubsetSpsBuffer[MAX_SPS_COUNT];
248+ SSubsetSps sSubsetSpsBuffer[MAX_SPS_COUNT + 1];
242249 SNalUnit sPrefixNal;
243250
244251 PAccessUnit pAccessUnitList; // current access unit list to be performed
@@ -279,6 +286,7 @@ typedef struct TagWelsDecoderContext { · 34 unmodified lines
279286 uint16_t uiCurIdrPicId;
280287 #endif
281288 bool bNewSeqBegin;
289+ int iOverwriteFlags;
282290 int32_t iErrorConMethod; //
283291 PPicture pPreviousDecodedPictureInDpb; //pointer to previously decoded picture in DPB for error concealment
284292 PGetIntraPredFunc pGetI16x16LumaPredFunc[7]; //h264_predict_copy_16x16;
codec/decoder/core/src/au_parser.cpp+63−19
@@ -174,8 +174,6 @@ uint8_t* ParseNalHeader (PWelsDecoderContext pCtx, SNalUnitHeader* pNalUnitHeade · 173 unmodified lines
174174
175175 switch (pNalUnitHeader->eNalUnitType) {
176176 case NAL_UNIT_SEI:
177− case NAL_UNIT_SPS:
178− case NAL_UNIT_PPS:
179177 if (pCtx->pAccessUnitList->uiAvailUnitsNum > 0) {
180178 pCtx->pAccessUnitList->uiEndPos = pCtx->pAccessUnitList->uiAvailUnitsNum - 1;
181179 pCtx->bAuReadyFlag = true;
@@ -730,6 +728,14 @@ const SLevelLimits* GetLevelLimits (int32_t iLevelIdx, bool bConstraint3) { · 548 unmodified lines
730728 return NULL;
731729 }
732730
731+bool CheckSpsActive (PWelsDecoderContext pCtx, PSps pSps) {
732+ for (int i = 0; i < MAX_LAYER_NUM; i++) {
733+ if (pCtx->pActiveLayerSps[i] == pSps)
734+ return true;
735+ }
736+ return false;
737+}
738+
733739 #define SPS_LOG2_MAX_FRAME_NUM_MINUS4_MAX 12
734740 #define SPS_LOG2_MAX_PIC_ORDER_CNT_LSB_MINUS4_MAX 12
735741 #define SPS_NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE_MAX 255
@@ -792,15 +798,9 @@ int32_t ParseSps (PWelsDecoderContext pCtx, PBitStringAux pBsAux, int32_t* pPicW · 56 unmodified lines
792798 return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_SPS_ID_OVERFLOW);
793799 }
794800 iSpsId = uiCode;
795−
796− if (kbUseSubsetFlag) {
797− pCtx->bSubspsAvailFlags[iSpsId] = false;
798− } else {
799− pCtx->bSpsAvailFlags[iSpsId] = false;
800− }
801801 pSubsetSps = &sTempSubsetSps;
802802 pSps = &sTempSubsetSps.sSps;
803− memset (pSubsetSps, 0, sizeof(SSubsetSps));
803+ memset (pSubsetSps, 0, sizeof (SSubsetSps));
804804 const SLevelLimits* pSLevelLimits = GetLevelLimits (uiLevelIdc, bConstraintSetFlags[3]);
805805 if (NULL == pSLevelLimits) {
806806 WelsLog (pCtx, WELS_LOG_WARNING, "ParseSps(): level_idx (%d).\n", uiLevelIdc);
@@ -897,7 +897,7 @@ int32_t ParseSps (PWelsDecoderContext pCtx, PBitStringAux pBsAux, int32_t* pPicW · 90 unmodified lines
897897 WelsLog (pCtx, WELS_LOG_ERROR, "pic_width_in_mbs(%d) exceeds the maximum allowed!\n", pSps->iMbWidth);
898898 return GENERATE_ERROR_NO (ERR_LEVEL_PARAM_SETS, ERR_INFO_INVALID_MAX_MB_SIZE);
899899 }
900− if (((uint64_t)pSps->iMbWidth * (uint64_t)pSps->iMbWidth) > (uint64_t)(8 * pSLevelLimits->iMaxFS)) {
900+ if (((uint64_t)pSps->iMbWidth * (uint64_t)pSps->iMbWidth) > (uint64_t) (8 * pSLevelLimits->iMaxFS)) {
901901 WelsLog (pCtx, WELS_LOG_WARNING, " the pic_width_in_mbs exceeds the level limits!\n");
902902 }
903903 WELS_READ_VERIFY (BsGetUe (pBs, &uiCode)); //pic_height_in_map_units_minus1
@@ -978,12 +978,45 @@ int32_t ParseSps (PWelsDecoderContext pCtx, PBitStringAux pBsAux, int32_t* pPicW · 74 unmodified lines
978978
979979 *pPicWidth = pSps->iMbWidth << 4;
980980 *pPicHeight = pSps->iMbHeight << 4;
981+ PSps pTmpSps = NULL;
981982 if (kbUseSubsetFlag) {
982− memcpy (&pCtx->sSubsetSpsBuffer[iSpsId], pSubsetSps, sizeof(SSubsetSps));
983+ pTmpSps = &pCtx->sSubsetSpsBuffer[iSpsId].sSps;
984+ } else {
985+ pTmpSps = &pCtx->sSpsBuffer[iSpsId];
986+ }
987+ if (CheckSpsActive (pCtx, pTmpSps)) {
988+ // we are overwriting the active sps, copy a temp buffer
989+ if (kbUseSubsetFlag) {
990+ if (memcmp (&pCtx->sSubsetSpsBuffer[iSpsId], pSubsetSps, sizeof (SSubsetSps)) != 0) {
991+ if (pCtx->pAccessUnitList->uiAvailUnitsNum > 0) {
992+ memcpy (&pCtx->sSubsetSpsBuffer[MAX_SPS_COUNT], pSubsetSps, sizeof (SSubsetSps));
993+ pCtx->bAuReadyFlag = true;
994+ pCtx->pAccessUnitList->uiEndPos = pCtx->pAccessUnitList->uiAvailUnitsNum - 1;
995+ pCtx->iOverwriteFlags |= OVERWRITE_SUBSETSPS;
996+ } else {
997+ memcpy (&pCtx->sSubsetSpsBuffer[iSpsId], pSubsetSps, sizeof (SSubsetSps));
998+ }
999+ }
1000+ } else {
1001+ if (memcmp (&pCtx->sSpsBuffer[iSpsId], pSps, sizeof (SSps)) != 0) {
1002+ if (pCtx->pAccessUnitList->uiAvailUnitsNum > 0) {
1003+ memcpy (&pCtx->sSpsBuffer[MAX_SPS_COUNT], pSps, sizeof (SSps));
1004+ pCtx->iOverwriteFlags |= OVERWRITE_SPS;
1005+ pCtx->bAuReadyFlag = true;
1006+ pCtx->pAccessUnitList->uiEndPos = pCtx->pAccessUnitList->uiAvailUnitsNum - 1;
1007+ } else {
1008+ memcpy (&pCtx->sSpsBuffer[iSpsId], pSps, sizeof (SSps));
1009+ }
1010+ }
1011+ }
1012+ }
1013+ // Not overwrite active sps, just copy to final place
1014+ else if (kbUseSubsetFlag) {
1015+ memcpy (&pCtx->sSubsetSpsBuffer[iSpsId], pSubsetSps, sizeof (SSubsetSps));
9831016 pCtx->bSubspsAvailFlags[iSpsId] = true;
9841017 pCtx->bSubspsExistAheadFlag = true;
9851018 } else {
986− memcpy (&pCtx->sSpsBuffer[iSpsId], pSps, sizeof(SSps));
1019+ memcpy (&pCtx->sSpsBuffer[iSpsId], pSps, sizeof (SSps));
9871020 pCtx->bSpsAvailFlags[iSpsId] = true;
9881021 pCtx->bSpsExistAheadFlag = true;
9891022 }
@@ -1018,10 +1051,8 @@ int32_t ParsePps (PWelsDecoderContext pCtx, PPps pPpsList, PBitStringAux pBsAux) · 28 unmodified lines
10181051 if (uiPpsId >= MAX_PPS_COUNT) {
10191052 return ERR_INFO_PPS_ID_OVERFLOW;
10201053 }
1021−
1022− pCtx->bPpsAvailFlags[uiPpsId] = false;
10231054 pPps = &sTempPps;
1024− memset (pPps, 0, sizeof(SPps));
1055+ memset (pPps, 0, sizeof (SPps));
10251056
10261057 pPps->iPpsId = uiPpsId;
10271058 WELS_READ_VERIFY (BsGetUe (pBsAux, &uiCode)); //seq_parameter_set_id
@@ -1102,10 +1133,23 @@ int32_t ParsePps (PWelsDecoderContext pCtx, PPps pPpsList, PBitStringAux pBsAux) · 74 unmodified lines
11021133 pPps->bConstainedIntraPredFlag = !!uiCode;
11031134 WELS_READ_VERIFY (BsGetOneBit (pBsAux, &uiCode)); //redundant_pic_cnt_present_flag
11041135 pPps->bRedundantPicCntPresentFlag = !!uiCode;
1105−
1106− memcpy (&pCtx->sPpsBuffer[uiPpsId], pPps, sizeof(SPps));
1107− pCtx->bPpsAvailFlags[uiPpsId] = true;
1108−
1136+ if (pCtx->pAccessUnitList->uiAvailUnitsNum > 0) {
1137+ PNalUnit pLastNalUnit = pCtx->pAccessUnitList->pNalUnitsList[pCtx->pAccessUnitList->uiAvailUnitsNum - 1];
1138+ PPps pLastPps = pLastNalUnit->sNalData.sVclNal.sSliceHeaderExt.sSliceHeader.pPps;
1139+ // the active pps is overwrite, write to a temp place
1140+ if (pLastPps == &pCtx->sPpsBuffer[uiPpsId] && memcmp (&pCtx->sPpsBuffer[uiPpsId], pPps, sizeof (*pPps)) != 0) {
1141+ memcpy (&pCtx->sPpsBuffer[MAX_PPS_COUNT], pPps, sizeof (SPps));
1142+ pCtx->iOverwriteFlags |= OVERWRITE_PPS;
1143+ pCtx->bAuReadyFlag = true;
1144+ pCtx->pAccessUnitList->uiEndPos = pCtx->pAccessUnitList->uiAvailUnitsNum - 1;
1145+ } else {
1146+ memcpy (&pCtx->sPpsBuffer[uiPpsId], pPps, sizeof (SPps));
1147+ pCtx->bPpsAvailFlags[uiPpsId] = true;
1148+ }
1149+ } else {
1150+ memcpy (&pCtx->sPpsBuffer[uiPpsId], pPps, sizeof (SPps));
1151+ pCtx->bPpsAvailFlags[uiPpsId] = true;
1152+ }
11091153 return ERR_NONE;
11101154 }
11111155
codec/decoder/core/src/decoder.cpp+23−27
@@ -61,7 +61,7 @@ extern PPicture AllocPicture (PWelsDecoderContext pCtx, const int32_t kiPicWidth · 60 unmodified lines
6161 extern void FreePicture (PPicture pPic);
6262
6363 inline void GetValueOf4Bytes (uint8_t* pDstNal, int32_t iDdstIdx) {
64− ST32(pDstNal, iDdstIdx);
64+ ST32 (pDstNal, iDdstIdx);
6565 }
6666
6767 static int32_t CreatePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, const int32_t kiSize,
@@ -422,7 +422,7 @@ int32_t WelsDecodeBs (PWelsDecoderContext pCtx, const uint8_t* kpBsBuf, const in · 354 unmodified lines
422422 int32_t iSrcConsumed = 0; // consumed bit count of source bs
423423 int32_t iDstIdx = 0; //the size of current NAL after 0x03 removal and 00 00 01 removal
424424 int32_t iSrcLength = 0; //the total size of current AU or NAL
425−
425+ int32_t iRet = 0;
426426 int32_t iConsumedBytes = 0;
427427 int32_t iOffset = 0;
428428
@@ -462,7 +462,9 @@ int32_t WelsDecodeBs (PWelsDecoderContext pCtx, const uint8_t* kpBsBuf, const in · 33 unmodified lines
462462
463463 iConsumedBytes = 0;
464464 pNalPayload = ParseNalHeader (pCtx, &pCtx->sCurNalHead, pDstNal, iDstIdx, pSrcNal - 3, iSrcIdx + 3, &iConsumedBytes);
465−
465+ if (IS_PARAM_SETS_NALS (pCtx->sCurNalHead.eNalUnitType) && pNalPayload) {
466+ iRet = ParseNonVclNal (pCtx, pNalPayload, iDstIdx - iConsumedBytes);
467+ }
466468 if (pCtx->bAuReadyFlag) {
467469 ConstructAccessUnit (pCtx, ppDst, pDstBufInfo);
468470
@@ -481,20 +483,17 @@ int32_t WelsDecodeBs (PWelsDecoderContext pCtx, const uint8_t* kpBsBuf, const in · 12 unmodified lines
481483 //Do error concealment here
482484 ImplementErrorCon (pCtx);
483485 }
484−
485− if ((IS_PARAM_SETS_NALS (pCtx->sCurNalHead.eNalUnitType) || IS_SEI_NAL (pCtx->sCurNalHead.eNalUnitType)) &&
486− pNalPayload) {
487− if (ParseNonVclNal (pCtx, pNalPayload, iDstIdx - iConsumedBytes)) {
488− if (dsNoParamSets & pCtx->iErrorCode) {
486+ if (iRet) {
487+ iRet = 0;
488+ if (dsNoParamSets & pCtx->iErrorCode) {
489489 #ifdef LONG_TERM_REF
490− pCtx->bParamSetsLostFlag = true;
490+ pCtx->bParamSetsLostFlag = true;
491491 #else
492− pCtx->bReferenceLostAtT0Flag = true;
492+ pCtx->bReferenceLostAtT0Flag = true;
493493 #endif
494− ResetParameterSetsState (pCtx);
495− }
496− return pCtx->iErrorCode;
494+ ResetParameterSetsState (pCtx);
497495 }
496+ return pCtx->iErrorCode;
498497 }
499498
500499 pDstNal += iDstIdx; //update current position
@@ -521,7 +520,9 @@ int32_t WelsDecodeBs (PWelsDecoderContext pCtx, const uint8_t* kpBsBuf, const in · 20 unmodified lines
521520
522521 iConsumedBytes = 0;
523522 pNalPayload = ParseNalHeader (pCtx, &pCtx->sCurNalHead, pDstNal, iDstIdx, pSrcNal - 3, iSrcIdx + 3, &iConsumedBytes);
524−
523+ if (IS_PARAM_SETS_NALS (pCtx->sCurNalHead.eNalUnitType) && pNalPayload) {
524+ iRet = ParseNonVclNal (pCtx, pNalPayload, iDstIdx - iConsumedBytes);
525+ }
525526 if (pCtx->bAuReadyFlag) {
526527 ConstructAccessUnit (pCtx, ppDst, pDstBufInfo);
527528
@@ -537,22 +538,18 @@ int32_t WelsDecodeBs (PWelsDecoderContext pCtx, const uint8_t* kpBsBuf, const in · 9 unmodified lines
537538 //Do error concealment here
538539 ImplementErrorCon (pCtx);
539540 }
540−
541− if ((IS_PARAM_SETS_NALS (pCtx->sCurNalHead.eNalUnitType) || IS_SEI_NAL (pCtx->sCurNalHead.eNalUnitType))
542− && pNalPayload) {
543− if (ParseNonVclNal (pCtx, pNalPayload, iDstIdx - iConsumedBytes)) {
544− if (dsNoParamSets & pCtx->iErrorCode) {
541+ if (iRet) {
542+ iRet = 0;
543+ if (dsNoParamSets & pCtx->iErrorCode) {
545544 #ifdef LONG_TERM_REF
546− pCtx->bParamSetsLostFlag = true;
545+ pCtx->bParamSetsLostFlag = true;
547546 #else
548− pCtx->bReferenceLostAtT0Flag = true;
547+ pCtx->bReferenceLostAtT0Flag = true;
549548 #endif
550− ResetParameterSetsState (pCtx);
551− }
552− return pCtx->iErrorCode;
549+ ResetParameterSetsState (pCtx);
553550 }
551+ return pCtx->iErrorCode;
554552 }
555−
556553 pDstNal += iDstIdx;
557554 pRawData->pCurPos = pDstNal; //init the pCurPos for next NAL(s) storage
558555 } else { /* no supplementary picture payload input, but stored a picture */
@@ -575,7 +572,6 @@ int32_t WelsDecodeBs (PWelsDecoderContext pCtx, const uint8_t* kpBsBuf, const in · 16 unmodified lines
575572 ResetParameterSetsState (pCtx);
576573 return pCtx->iErrorCode;
577574 }
578− //Do error concealment here
579575 ImplementErrorCon (pCtx);
580576 }
581577 }
@@ -663,7 +659,7 @@ void AssignFuncPointerForRec (PWelsDecoderContext pCtx) { · 81 unmodified lines
663659 pCtx->pIdctResAddPredFunc = IdctResAddPred_c;
664660
665661 #if defined(HAVE_NEON)
666− if ( pCtx->uiCpuFlag & WELS_CPU_NEON ) {
662+ if (pCtx->uiCpuFlag & WELS_CPU_NEON) {
667663 pCtx->pIdctResAddPredFunc = IdctResAddPred_neon;
668664
669665 pCtx->pGetI16x16LumaPredFunc[I16_PRED_DC] = WelsDecoderI16x16LumaPredDc_neon;
codec/decoder/core/src/decoder_core.cpp+17−2
@@ -1531,6 +1531,20 @@ static bool CheckNewSeqBeginAndUpdateActiveLayerSps(PWelsDecoderContext pCtx) { · 1530 unmodified lines
15311531 return bNewSeq;
15321532 }
15331533
1534+static void WriteBackActiveParameters(PWelsDecoderContext pCtx) {
1535+ if (pCtx->iOverwriteFlags & OVERWRITE_PPS) {
1536+ memcpy(&pCtx->sPpsBuffer[pCtx->sPpsBuffer[MAX_PPS_COUNT].iPpsId], &pCtx->sPpsBuffer[MAX_PPS_COUNT], sizeof(SPps));
1537+ pCtx->bNewSeqBegin = true;
1538+ }
1539+ if (pCtx->iOverwriteFlags & OVERWRITE_SPS) {
1540+ memcpy(&pCtx->sSpsBuffer[pCtx->sSpsBuffer[MAX_SPS_COUNT].iSpsId], &pCtx->sSpsBuffer[MAX_SPS_COUNT], sizeof(SSps));
1541+ pCtx->bNewSeqBegin = true;
1542+ }
1543+ if (pCtx->iOverwriteFlags & OVERWRITE_SUBSETSPS) {
1544+ memcpy(&pCtx->sSubsetSpsBuffer[pCtx->sSubsetSpsBuffer[MAX_SPS_COUNT].sSps.iSpsId], &pCtx->sSubsetSpsBuffer[MAX_SPS_COUNT], sizeof(SSubsetSps));
1545+ }
1546+ pCtx->iOverwriteFlags = OVERWRITE_NONE;
1547+}
15341548 /*
15351549 * ConstructAccessUnit
15361550 * construct an access unit for given input bitstream, maybe partial NAL Unit, one or more Units are involved to
@@ -1548,12 +1562,12 @@ int32_t ConstructAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBufferI · 11 unmodified lines
15481562 int32_t iWidth;
15491563 int32_t iHeight;
15501564 int32_t iStride[2] = { 0 };
1551−
15521565 PAccessUnit pCurAu = pCtx->pAccessUnitList;
15531566
15541567 pCtx->bAuReadyFlag = false;
15551568 pCtx->bLastHasMmco5 = false;
1556− pCtx->bNewSeqBegin = CheckNewSeqBeginAndUpdateActiveLayerSps(pCtx);
1569+ bool bTmpNewSeqBegin = CheckNewSeqBeginAndUpdateActiveLayerSps(pCtx);
1570+ pCtx->bNewSeqBegin = pCtx->bNewSeqBegin && bTmpNewSeqBegin;
15571571 iErr = WelsDecodeAccessUnitStart (pCtx);
15581572 GetVclNalTemporalId (pCtx);
15591573
@@ -1584,6 +1598,7 @@ int32_t ConstructAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBufferI · 24 unmodified lines
15841598
15851599 WelsDecodeAccessUnitEnd (pCtx);
15861600 pCtx->bNewSeqBegin = false;
1601+ WriteBackActiveParameters(pCtx);
15871602 if (ERR_NONE != iErr) {
15881603 WelsLog (pCtx, WELS_LOG_INFO, "returned error from decoding:[0x%x]\n", iErr);
15891604 return iErr;

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