| 597 | } |
| 598 | |
| 599 | void RcDecideTargetBitsTimestamp (sWelsEncCtx* pEncCtx) { |
| 600 | //decide one frame bits allocated |
| 601 | SWelsSvcRc* pWelsSvcRc = &pEncCtx->pWelsSvcRc[pEncCtx->uiDependencyId]; |
| 602 | SSpatialLayerConfig* pDLayerParam = &pEncCtx->pSvcParam->sSpatialLayers[pEncCtx->uiDependencyId]; |
| 603 | int32_t iTl = pEncCtx->uiTemporalId; |
| 604 | SRCTemporal* pTOverRc = &pWelsSvcRc->pTemporalOverRc[iTl]; |
| 605 | pWelsSvcRc->iCurrentBitsLevel = BITS_NORMAL; |
| 606 | |
| 607 | if (pEncCtx->eSliceType == I_SLICE) { |
| 608 | int32_t iBufferTh = static_cast<int32_t> (pWelsSvcRc->iBufferSizeSkip - pWelsSvcRc->iBufferFullnessSkip); |
| 609 | if (iBufferTh <= 0) { |
| 610 | pWelsSvcRc->iCurrentBitsLevel = BITS_EXCEEDED; |
| 611 | pWelsSvcRc->iTargetBits = pTOverRc->iMinBitsTl; |
| 612 | } else { |
| 613 | int32_t iMaxTh = iBufferTh * 3 / 4; |
| 614 | int32_t iMinTh = static_cast<int32_t>((pDLayerParam->fFrameRate < 8) ? iBufferTh * 1.0 / 4 : iBufferTh * 2 / pDLayerParam->fFrameRate); |
| 615 | if (pDLayerParam->fFrameRate < (IDR_BITRATE_RATIO + 1)) |
| 616 | pWelsSvcRc->iTargetBits = static_cast<int32_t> (((double) (pDLayerParam->iSpatialBitrate) / (double) ( |
| 617 | pDLayerParam->fFrameRate))); |
| 618 | else |
| 619 | pWelsSvcRc->iTargetBits = static_cast<int32_t> (((double) (pDLayerParam->iSpatialBitrate) / (double) ( |
| 620 | pDLayerParam->fFrameRate) * IDR_BITRATE_RATIO)); |
| 621 | WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG, |
| 622 | "iMaxTh = %d,iMinTh = %d,pWelsSvcRc->iTargetBits = %d,pWelsSvcRc->iBufferSizeSkip = %d, pWelsSvcRc->iBufferFullnessSkip= %" |
| 623 | PRId64, |
| 624 | iMaxTh, iMinTh, pWelsSvcRc->iTargetBits, pWelsSvcRc->iBufferSizeSkip, pWelsSvcRc->iBufferFullnessSkip); |
| 625 | pWelsSvcRc->iTargetBits = WELS_CLIP3 (pWelsSvcRc->iTargetBits, iMinTh, iMaxTh); |
| 626 | } |
| 627 | |
| 628 | } else { |
| 629 | int32_t iBufferTh = static_cast<int32_t> (pWelsSvcRc->iBufferSizeSkip - pWelsSvcRc->iBufferFullnessSkip); |
| 630 | if (iBufferTh <= 0) { |
| 631 | pWelsSvcRc->iCurrentBitsLevel = BITS_EXCEEDED; |
| 632 | pWelsSvcRc->iTargetBits = pTOverRc->iMinBitsTl; |
| 633 | WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG, |
| 634 | "iMaxTh = %d,pWelsSvcRc->iTargetBits = %d,pWelsSvcRc->iBufferSizeSkip = %d, pWelsSvcRc->iBufferFullnessSkip= %" PRId64, |
| 635 | iBufferTh, pWelsSvcRc->iTargetBits, pWelsSvcRc->iBufferSizeSkip, pWelsSvcRc->iBufferFullnessSkip); |
| 636 | } else { |
| 637 | |
| 638 | SSpatialLayerInternal* pDLayerParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[pEncCtx->uiDependencyId]; |
| 639 | const int32_t kiGopSize = (1 << pDLayerParamInternal->iDecompositionStages); |
| 640 | int32_t iAverageFrameSize = (int32_t) ((double) (pDLayerParam->iSpatialBitrate) / (double) (pDLayerParam->fFrameRate)); |
| 641 | const int32_t kiGopBits = iAverageFrameSize * kiGopSize; |
| 642 | pWelsSvcRc->iTargetBits = WELS_DIV_ROUND (pTOverRc->iTlayerWeight * kiGopBits, INT_MULTIPLY * 10 * 2); |
| 643 | |
| 644 | int32_t iMaxTh = iBufferTh / 2; |
| 645 | int32_t iMinTh = static_cast<int32_t>((pDLayerParam->fFrameRate < 8) ? iBufferTh * 1.0 / 4 : iBufferTh * 2 / pDLayerParam->fFrameRate); |
| 646 | WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_DEBUG, |
| 647 | "iMaxTh = %d,iMinTh = %d,pWelsSvcRc->iTargetBits = %d,pWelsSvcRc->iBufferSizeSkip = %d, pWelsSvcRc->iBufferFullnessSkip= % " |
| 648 | PRId64, |
| 649 | iMaxTh, iMinTh, pWelsSvcRc->iTargetBits, pWelsSvcRc->iBufferSizeSkip, pWelsSvcRc->iBufferFullnessSkip); |
| 650 | pWelsSvcRc->iTargetBits = WELS_CLIP3 (pWelsSvcRc->iTargetBits, iMinTh, iMaxTh); |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | void RcInitGomParameters (sWelsEncCtx* pEncCtx) { |
| 656 | SSlice** ppSliceInLayer = pEncCtx->pCurDqLayer->ppSliceInLayer; |
no test coverage detected