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