History

Squashed merge from writenal_refactor2

sijchen committed 12 years ago

Commit e45e8591 parent a921bc616 files · +431 −263Browse files

Showing the changes to codec/encoder/core/src/svc_encode_slice.cpp (1 of 16 files). Show all

Unified · Split

codec/encoder/core/src/svc_encode_slice.cpp+45−21
@@ -50,7 +50,7 @@ · 49 unmodified lines
50namespace WelsSVCEnc {50namespace WelsSVCEnc {
51//#define ENC_TRACE51//#define ENC_TRACE
52 52
53typedef void (*PWelsCodingSliceFunc) (sWelsEncCtx* pCtx, SSlice* pSlice);53typedef int32_t (*PWelsCodingSliceFunc) (sWelsEncCtx* pCtx, SSlice* pSlice);
54typedef void (*PWelsSliceHeaderWriteFunc) (SBitStringAux* pBs, SDqLayer* pCurLayer, SSlice* pSlice,54typedef void (*PWelsSliceHeaderWriteFunc) (SBitStringAux* pBs, SDqLayer* pCurLayer, SSlice* pSlice,
55 int32_t* pPpsIdDelta);55 int32_t* pPpsIdDelta);
56 56
@@ -465,7 +465,7 @@ void OutputPMbWithoutConstructCsRsNoCopy (sWelsEncCtx* pCtx, SDqLayer* pDq, SSli · 408 unmodified lines
465//encapsulate two kinds of reconstruction:465//encapsulate two kinds of reconstruction:
466//first. store base or highest Dependency Layer with only one quality (without CS RS reconstruction)466//first. store base or highest Dependency Layer with only one quality (without CS RS reconstruction)
467//second. lower than highest Dependency Layer, and for every Dependency Layer with one quality layer(single layer)467//second. lower than highest Dependency Layer, and for every Dependency Layer with one quality layer(single layer)
468void WelsISliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + encoding468int32_t WelsISliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + encoding
469 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;469 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;
470 SSliceCtx* pSliceCtx = pCurLayer->pSliceEncCtx;470 SSliceCtx* pSliceCtx = pCurLayer->pSliceEncCtx;
471 SMbCache* pMbCache = &pSlice->sMbCacheInfo;471 SMbCache* pMbCache = &pSlice->sMbCacheInfo;
@@ -479,6 +479,7 @@ void WelsISliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + encoding · 7 unmodified lines
479 const int32_t kiSliceIdx = pSlice->uiSliceIdx;479 const int32_t kiSliceIdx = pSlice->uiSliceIdx;
480 const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;480 const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;
481 SWelsMD sMd;481 SWelsMD sMd;
482 int32_t iEncReturn = ENC_RETURN_SUCCESS;
482 483
483 for (; ;) {484 for (; ;) {
484 iCurMbIdx = iNextMbIdx;485 iCurMbIdx = iNextMbIdx;
@@ -494,7 +495,9 @@ void WelsISliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + encoding · 9 unmodified lines
494 WelsMdIntraMb (pEncCtx, &sMd, pCurMb, pMbCache);495 WelsMdIntraMb (pEncCtx, &sMd, pCurMb, pMbCache);
495 UpdateNonZeroCountCache (pCurMb, pMbCache);496 UpdateNonZeroCountCache (pCurMb, pMbCache);
496 497
497 WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);498 iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);
499 if (ENC_RETURN_SUCCESS != iEncReturn)
500 return iEncReturn;
498 501
499 pCurMb->uiSliceIdc = kiSliceIdx;502 pCurMb->uiSliceIdc = kiSliceIdx;
500 503
@@ -511,10 +514,12 @@ void WelsISliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + encoding · 10 unmodified lines
511 break;514 break;
512 }515 }
513 }516 }
517
518 return ENC_RETURN_SUCCESS;
514}519}
515 520
516// Only for intra dynamic slicing521// Only for intra dynamic slicing
517void WelsISliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + encoding522int32_t WelsISliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + encoding
518 SBitStringAux* pBs = pSlice->pSliceBsa;523 SBitStringAux* pBs = pSlice->pSliceBsa;
519 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;524 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;
520 SSliceCtx* pSliceCtx = pCurLayer->pSliceEncCtx;525 SSliceCtx* pSliceCtx = pCurLayer->pSliceEncCtx;
@@ -529,6 +534,7 @@ void WelsISliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + enc · 8 unmodified lines
529 const int32_t kiSliceIdx = pSlice->uiSliceIdx;534 const int32_t kiSliceIdx = pSlice->uiSliceIdx;
530 const int32_t kiPartitionId = (kiSliceIdx % pEncCtx->iActiveThreadsNum);535 const int32_t kiPartitionId = (kiSliceIdx % pEncCtx->iActiveThreadsNum);
531 const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;536 const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;
537 int32_t iEncReturn = ENC_RETURN_SUCCESS;
532 538
533 SWelsMD sMd;539 SWelsMD sMd;
534 SDynamicSlicingStack sDss;540 SDynamicSlicingStack sDss;
@@ -557,7 +563,9 @@ void WelsISliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + enc · 22 unmodified lines
557 sDss.uiBsStackCurBits = pBs->uiCurBits;563 sDss.uiBsStackCurBits = pBs->uiCurBits;
558 sDss.iBsStackLeftBits = pBs->iLeftBits;564 sDss.iBsStackLeftBits = pBs->iLeftBits;
559 565
560 WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);566 iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);
567 if (ENC_RETURN_SUCCESS != iEncReturn)
568 return iEncReturn;
561 569
562 sDss.iCurrentPos = BsGetBitsPos (pBs);570 sDss.iCurrentPos = BsGetBitsPos (pBs);
563 571
@@ -574,6 +582,7 @@ void WelsISliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + enc · 10 unmodified lines
574 break;582 break;
575 }583 }
576 584
585
577 pCurMb->uiSliceIdc = kiSliceIdx;586 pCurMb->uiSliceIdc = kiSliceIdx;
578 587
579#if defined(MB_TYPES_CHECK)588#if defined(MB_TYPES_CHECK)
@@ -593,12 +602,13 @@ void WelsISliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd + enc · 13 unmodified lines
593 break;602 break;
594 }603 }
595 }604 }
605 return iEncReturn;
596}606}
597 607
598//encapsulate two kinds of reconstruction:608//encapsulate two kinds of reconstruction:
599// first. store base or highest Dependency Layer with only one quality (without CS RS reconstruction)609// first. store base or highest Dependency Layer with only one quality (without CS RS reconstruction)
600// second. lower than highest Dependency Layer, and for every Dependency Layer with one quality layer(single layer)610// second. lower than highest Dependency Layer, and for every Dependency Layer with one quality layer(single layer)
601void WelsPSliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice, const bool kbIsHighestDlayerFlag) { //pMd + encoding611int32_t WelsPSliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice, const bool kbIsHighestDlayerFlag) { //pMd + encoding
602 const SSliceHeaderExt* kpShExt = &pSlice->sSliceHeaderExt;612 const SSliceHeaderExt* kpShExt = &pSlice->sSliceHeaderExt;
603 const SSliceHeader* kpSh = &kpShExt->sSliceHeader;613 const SSliceHeader* kpSh = &kpShExt->sSliceHeader;
604 const int32_t kiSliceFirstMbXY = kpSh->iFirstMbInSlice;614 const int32_t kiSliceFirstMbXY = kpSh->iFirstMbInSlice;
@@ -610,10 +620,10 @@ void WelsPSliceMdEnc (sWelsEncCtx* pEncCtx, SSlice* pSlice, const bool kbIsHigh · 5 unmodified lines
610 memset (&sMd.sMe, 0, sizeof (sMd.sMe));620 memset (&sMd.sMe, 0, sizeof (sMd.sMe));
611 621
612 //pMb loop622 //pMb loop
613 WelsMdInterMbLoop (pEncCtx, pSlice, &sMd, kiSliceFirstMbXY);623 return WelsMdInterMbLoop (pEncCtx, pSlice, &sMd, kiSliceFirstMbXY);
614}624}
615 625
616void WelsPSliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice, const bool kbIsHighestDlayerFlag) {626int32_t WelsPSliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice, const bool kbIsHighestDlayerFlag) {
617 const SSliceHeaderExt* kpShExt = &pSlice->sSliceHeaderExt;627 const SSliceHeaderExt* kpShExt = &pSlice->sSliceHeaderExt;
618 const SSliceHeader* kpSh = &kpShExt->sSliceHeader;628 const SSliceHeader* kpSh = &kpShExt->sSliceHeader;
619 const int32_t kiSliceFirstMbXY = kpSh->iFirstMbInSlice;629 const int32_t kiSliceFirstMbXY = kpSh->iFirstMbInSlice;
@@ -625,10 +635,10 @@ void WelsPSliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice, const bool kb · 5 unmodified lines
625 memset (&sMd.sMe, 0, sizeof (sMd.sMe));635 memset (&sMd.sMe, 0, sizeof (sMd.sMe));
626 636
627 //mb loop637 //mb loop
628 WelsMdInterMbLoopOverDynamicSlice (pEncCtx, pSlice, &sMd, kiSliceFirstMbXY);638 return WelsMdInterMbLoopOverDynamicSlice (pEncCtx, pSlice, &sMd, kiSliceFirstMbXY);
629}639}
630 640
631void WelsCodePSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice) {641int32_t WelsCodePSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice) {
632 //pSlice-level init should be outside and before this function642 //pSlice-level init should be outside and before this function
633 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;643 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;
634 644
@@ -644,10 +654,10 @@ void WelsCodePSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice) { · 9 unmodified lines
644 //initial pMd pointer654 //initial pMd pointer
645 pEncCtx->pFuncList->pfInterMd = WelsMdInterMb;655 pEncCtx->pFuncList->pfInterMd = WelsMdInterMb;
646 }656 }
647 WelsPSliceMdEnc (pEncCtx, pSlice, kbHighestSpatial);657 return WelsPSliceMdEnc (pEncCtx, pSlice, kbHighestSpatial);
648}658}
649 659
650void WelsCodePOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice) {660int32_t WelsCodePOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice) {
651 //pSlice-level init should be outside and before this function661 //pSlice-level init should be outside and before this function
652 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;662 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;
653 663
@@ -663,22 +673,22 @@ void WelsCodePOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice) { · 9 unmodified lines
663 //initial pMd pointer673 //initial pMd pointer
664 pEncCtx->pFuncList->pfInterMd = WelsMdInterMb;674 pEncCtx->pFuncList->pfInterMd = WelsMdInterMb;
665 }675 }
666 WelsPSliceMdEncDynamic (pEncCtx, pSlice, kbHighestSpatial);676 return WelsPSliceMdEncDynamic (pEncCtx, pSlice, kbHighestSpatial);
667}677}
668 678
669// 1st index: 0: for P pSlice; 1: for I pSlice;679// 1st index: 0: for P pSlice; 1: for I pSlice;
670// 2nd index: 0: for non-dynamic pSlice; 1: for dynamic I pSlice;680// 2nd index: 0: for non-dynamic pSlice; 1: for dynamic I pSlice;
671const PWelsCodingSliceFunc g_pWelsSliceCoding[2][2] = {681PWelsCodingSliceFunc g_pWelsSliceCoding[2][2] = {
672 { WelsCodePSlice, WelsCodePOverDynamicSlice }, // P SSlice682 { WelsCodePSlice, WelsCodePOverDynamicSlice }, // P SSlice
673 { WelsISliceMdEnc, WelsISliceMdEncDynamic } // I SSlice683 { WelsISliceMdEnc, WelsISliceMdEncDynamic } // I SSlice
674};684};
675const PWelsSliceHeaderWriteFunc g_pWelsWriteSliceHeader[2] = { // 0: for base; 1: for ext;685PWelsSliceHeaderWriteFunc g_pWelsWriteSliceHeader[2] = { // 0: for base; 1: for ext;
676 WelsSliceHeaderWrite,686 WelsSliceHeaderWrite,
677 WelsSliceHeaderExtWrite687 WelsSliceHeaderExtWrite
678};688};
679 689
680 690
681void WelsCodeOneSlice (sWelsEncCtx* pEncCtx, const int32_t kiSliceIdx, const int32_t kiNalType) {691int32_t WelsCodeOneSlice (sWelsEncCtx* pEncCtx, const int32_t kiSliceIdx, const int32_t kiNalType) {
682 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;692 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;
683 SNalUnitHeaderExt* pNalHeadExt = &pCurLayer->sLayerInfo.sNalHeaderExt;693 SNalUnitHeaderExt* pNalHeadExt = &pCurLayer->sLayerInfo.sNalHeaderExt;
684 SSlice* pCurSlice = &pCurLayer->sLayerInfo.pSliceInLayer[kiSliceIdx];694 SSlice* pCurSlice = &pCurLayer->sLayerInfo.pSliceInLayer[kiSliceIdx];
@@ -715,11 +725,15 @@ void WelsCodeOneSlice (sWelsEncCtx* pEncCtx, const int32_t kiSliceIdx, const int · 30 unmodified lines
715 725
716 pCurSlice->uiLastMbQp = pCurLayer->sLayerInfo.pPpsP->iPicInitQp + pCurSlice->sSliceHeaderExt.sSliceHeader.iSliceQpDelta;726 pCurSlice->uiLastMbQp = pCurLayer->sLayerInfo.pPpsP->iPicInitQp + pCurSlice->sSliceHeaderExt.sSliceHeader.iSliceQpDelta;
717 727
718 g_pWelsSliceCoding[pNalHeadExt->bIdrFlag][kiDynamicSliceFlag] (pEncCtx, pCurSlice);728 int32_t iEncReturn = g_pWelsSliceCoding[pNalHeadExt->bIdrFlag][kiDynamicSliceFlag] (pEncCtx, pCurSlice);
729 if (ENC_RETURN_SUCCESS != iEncReturn)
730 return iEncReturn;
719 731
720 BsRbspTrailingBits (pBs);732 BsRbspTrailingBits (pBs);
721 733
722 BsFlush (pBs);734 BsFlush (pBs);
735
736 return ENC_RETURN_SUCCESS;
723}737}
724 738
725//pFunc: UpdateMbNeighbourInfoForNextSlice()739//pFunc: UpdateMbNeighbourInfoForNextSlice()
@@ -905,7 +919,7 @@ bool DynSlcJudgeSliceBoundaryStepBack (void* pCtx, void* pSlice, SSliceCtx* pSli · 179 unmodified lines
905// pMb loop919// pMb loop
906///////////////920///////////////
907// for inter non-dynamic pSlice921// for inter non-dynamic pSlice
908void WelsMdInterMbLoop (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd, const int32_t kiSliceFirstMbXY) {922int32_t WelsMdInterMbLoop (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd, const int32_t kiSliceFirstMbXY) {
909 SWelsMD* pMd = (SWelsMD*)pWelsMd;923 SWelsMD* pMd = (SWelsMD*)pWelsMd;
910 SBitStringAux* pBs = pSlice->pSliceBsa;924 SBitStringAux* pBs = pSlice->pSliceBsa;
911 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;925 SDqLayer* pCurLayer = pEncCtx->pCurDqLayer;
@@ -923,6 +937,7 @@ void WelsMdInterMbLoop (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd, con · 11 unmodified lines
923 uint16_t* pMvdCostTableInter = &pEncCtx->pMvdCostTableInter[kiMvdInterTableSize];937 uint16_t* pMvdCostTableInter = &pEncCtx->pMvdCostTableInter[kiMvdInterTableSize];
924 const int32_t kiSliceIdx = pSlice->uiSliceIdx;938 const int32_t kiSliceIdx = pSlice->uiSliceIdx;
925 const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;939 const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;
940 int32_t iEncReturn = ENC_RETURN_SUCCESS;
926 941
927 for (;;) {942 for (;;) {
928 //point to current pMb943 //point to current pMb
@@ -958,7 +973,9 @@ void WelsMdInterMbLoop (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd, con · 29 unmodified lines
958 } else {973 } else {
959 BsWriteUE (pBs, iMbSkipRun);974 BsWriteUE (pBs, iMbSkipRun);
960 iMbSkipRun = 0;975 iMbSkipRun = 0;
961 WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);976 iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);
977 if (ENC_RETURN_SUCCESS != iEncReturn)
978 return iEncReturn;
962 }979 }
963 980
964 //step (7): reconstruct current MB981 //step (7): reconstruct current MB
@@ -984,10 +1001,12 @@ void WelsMdInterMbLoop (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd, con · 19 unmodified lines
984 if (iMbSkipRun) {1001 if (iMbSkipRun) {
985 BsWriteUE (pBs, iMbSkipRun);1002 BsWriteUE (pBs, iMbSkipRun);
986 }1003 }
1004
1005 return iEncReturn;
987}1006}
988 1007
989// Only for inter dynamic slicing1008// Only for inter dynamic slicing
990void WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd,1009int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, void* pWelsMd,
991 const int32_t kiSliceFirstMbXY) {1010 const int32_t kiSliceFirstMbXY) {
992 SWelsMD* pMd = (SWelsMD*)pWelsMd;1011 SWelsMD* pMd = (SWelsMD*)pWelsMd;
993 SBitStringAux* pBs = pSlice->pSliceBsa;1012 SBitStringAux* pBs = pSlice->pSliceBsa;
@@ -1007,6 +1026,7 @@ void WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, vo · 13 unmodified lines
1007 const int32_t kiSliceIdx = pSlice->uiSliceIdx;1026 const int32_t kiSliceIdx = pSlice->uiSliceIdx;
1008 const int32_t kiPartitionId = (kiSliceIdx % pEncCtx->iActiveThreadsNum);1027 const int32_t kiPartitionId = (kiSliceIdx % pEncCtx->iActiveThreadsNum);
1009 const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;1028 const uint8_t kuiChromaQpIndexOffset = pCurLayer->sLayerInfo.pPpsP->uiChromaQpIndexOffset;
1029 int32_t iEncReturn = ENC_RETURN_SUCCESS;
1010 1030
1011 SDynamicSlicingStack sDss;1031 SDynamicSlicingStack sDss;
1012 sDss.iStartPos = BsGetBitsPos (pBs);1032 sDss.iStartPos = BsGetBitsPos (pBs);
@@ -1063,7 +1083,9 @@ void WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, vo · 50 unmodified lines
1063 } else {1083 } else {
1064 BsWriteUE (pBs, iMbSkipRun);1084 BsWriteUE (pBs, iMbSkipRun);
1065 iMbSkipRun = 0;1085 iMbSkipRun = 0;
1066 WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);1086 iEncReturn = WelsSpatialWriteMbSyn (pEncCtx, pSlice, pCurMb);
1087 if (ENC_RETURN_SUCCESS != iEncReturn)
1088 return iEncReturn;
1067 }1089 }
1068 1090
1069 //DYNAMIC_SLICING_ONE_THREAD - MultiD1091 //DYNAMIC_SLICING_ONE_THREAD - MultiD
@@ -1108,6 +1130,8 @@ void WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice, vo · 38 unmodified lines
1108 if (iMbSkipRun) {1130 if (iMbSkipRun) {
1109 BsWriteUE (pBs, iMbSkipRun);1131 BsWriteUE (pBs, iMbSkipRun);
1110 }1132 }
1133
1134 return iEncReturn;
1111}1135}
1112 1136
1113}//namespace WelsSVCEnc1137}//namespace WelsSVCEnc

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