Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 14 files). Show all
Unified · Split
| @@ -79,8 +79,10 @@ int32_t WelsBitRateVerification (SLogContext* pLogCtx, SSpatialLayerConfig* pLay · 78 unmodified lines | ||
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | // deal with LEVEL_MAX_BR and MAX_BR setting |
| 82 | − const int32_t iLevelMaxBitrate = (pLayerParam->uiLevelIdc != LEVEL_UNKNOWN) ? (g_ksLevelLimits[pLayerParam->uiLevelIdc - | |
| 83 | − 1].uiMaxBR * CpbBrNalFactor) : UNSPECIFIED_BIT_RATE; | |
| 82 | + const SLevelLimits* pCurLevelLimit = g_ksLevelLimits; | |
| 83 | + while ((pCurLevelLimit->uiLevelIdc != LEVEL_5_2) && (pCurLevelLimit->uiLevelIdc != pLayerParam->uiLevelIdc)) | |
| 84 | + pCurLevelLimit++; | |
| 85 | + const int32_t iLevelMaxBitrate = pCurLevelLimit->uiMaxBR * CpbBrNalFactor; | |
| 84 | 86 | const int32_t iLevel52MaxBitrate = g_ksLevelLimits[LEVEL_NUMBER - 1].uiMaxBR * CpbBrNalFactor; |
| 85 | 87 | if (UNSPECIFIED_BIT_RATE != iLevelMaxBitrate) { |
| 86 | 88 | if ((pLayerParam->iMaxSpatialBitrate == UNSPECIFIED_BIT_RATE) |
| @@ -91,7 +93,7 @@ int32_t WelsBitRateVerification (SLogContext* pLogCtx, SSpatialLayerConfig* pLay · 4 unmodified lines | ||
| 91 | 93 | pLayerParam->iMaxSpatialBitrate, pLayerParam->uiLevelIdc); |
| 92 | 94 | } else if (pLayerParam->iMaxSpatialBitrate > iLevelMaxBitrate) { |
| 93 | 95 | ELevelIdc iCurLevel = pLayerParam->uiLevelIdc; |
| 94 | − WelsAdjustLevel (pLayerParam); | |
| 96 | + WelsAdjustLevel (pLayerParam, pCurLevelLimit); | |
| 95 | 97 | WelsLog (pLogCtx, WELS_LOG_INFO, |
| 96 | 98 | "LevelIdc is changed from (%d) to (%d) according to the iMaxSpatialBitrate(%d)", |
| 97 | 99 | iCurLevel, pLayerParam->uiLevelIdc, pLayerParam->iMaxSpatialBitrate); |
| @@ -123,36 +125,55 @@ int32_t WelsBitRateVerification (SLogContext* pLogCtx, SSpatialLayerConfig* pLay · 25 unmodified lines | ||
| 123 | 125 | |
| 124 | 126 | void CheckProfileSetting (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int32_t iLayer, EProfileIdc uiProfileIdc) { |
| 125 | 127 | SSpatialLayerConfig* pLayerInfo = &pParam->sSpatialLayers[iLayer]; |
| 126 | − if (PRO_UNKNOWN == uiProfileIdc) { | |
| 127 | − pLayerInfo->uiProfileIdc = (((iLayer == SPATIAL_LAYER_0) | |
| 128 | − || pParam->bSimulcastAVC) ? PRO_BASELINE : PRO_SCALABLE_BASELINE); | |
| 129 | − } else { | |
| 130 | − pLayerInfo->uiProfileIdc = uiProfileIdc; | |
| 131 | − if ((iLayer == SPATIAL_LAYER_0) && (uiProfileIdc != PRO_BASELINE)) { | |
| 132 | − WelsLog (pLogCtx, WELS_LOG_WARNING, "doesn't support profile(%d), change to baseline profile", | |
| 128 | + pLayerInfo->uiProfileIdc = uiProfileIdc; | |
| 129 | + if (pParam->bSimulcastAVC) { | |
| 130 | + if ((uiProfileIdc != PRO_BASELINE) && (uiProfileIdc != PRO_MAIN) && (uiProfileIdc != PRO_HIGH)) { | |
| 131 | + WelsLog (pLogCtx, WELS_LOG_WARNING, "layerId(%d) doesn't support profile(%d), change to baseline profile", iLayer, | |
| 133 | 132 | uiProfileIdc); |
| 134 | 133 | pLayerInfo->uiProfileIdc = PRO_BASELINE; |
| 135 | 134 | } |
| 136 | − if (iLayer > SPATIAL_LAYER_0) { | |
| 137 | − if (pParam->bSimulcastAVC && (uiProfileIdc != PRO_BASELINE)) { | |
| 138 | − pLayerInfo->uiProfileIdc = PRO_BASELINE; | |
| 139 | − WelsLog (pLogCtx, WELS_LOG_WARNING, "doesn't support profile(%d) with bSimulcastAVC, change to baseline profile", | |
| 135 | + if (pParam->iEntropyCodingModeFlag && pLayerInfo->uiProfileIdc == PRO_BASELINE) { | |
| 136 | + pLayerInfo->uiProfileIdc = PRO_MAIN; | |
| 137 | + WelsLog (pLogCtx, WELS_LOG_WARNING, "layerId(%d) change to main profile because cabac is enabled", iLayer); | |
| 138 | + } | |
| 139 | + } else { | |
| 140 | + if (iLayer == SPATIAL_LAYER_0) { | |
| 141 | + if ((uiProfileIdc != PRO_BASELINE) && (uiProfileIdc != PRO_MAIN) && (uiProfileIdc != PRO_HIGH)) { | |
| 142 | + WelsLog (pLogCtx, WELS_LOG_WARNING, "layerId(%d) doesn't support profile(%d), change to baseline profile", iLayer, | |
| 140 | 143 | uiProfileIdc); |
| 141 | − } | |
| 142 | − if ((uiProfileIdc != PRO_BASELINE) || (uiProfileIdc != PRO_SCALABLE_BASELINE)) { | |
| 143 | 144 | pLayerInfo->uiProfileIdc = PRO_BASELINE; |
| 144 | − WelsLog (pLogCtx, WELS_LOG_WARNING, "doesn't support profile(%d), change to baseline profile", | |
| 145 | − uiProfileIdc); | |
| 145 | + } | |
| 146 | + if (pParam->iEntropyCodingModeFlag && (pLayerInfo->uiProfileIdc == PRO_BASELINE)) { | |
| 147 | + pLayerInfo->uiProfileIdc = PRO_MAIN; | |
| 148 | + WelsLog (pLogCtx, WELS_LOG_WARNING, "layerId(%d) change to main profile because cabac is enabled", iLayer); | |
| 149 | + } | |
| 150 | + } else { | |
| 151 | + if ((uiProfileIdc != PRO_SCALABLE_BASELINE) && (uiProfileIdc != PRO_SCALABLE_HIGH)) { | |
| 152 | + pLayerInfo->uiProfileIdc = PRO_SCALABLE_BASELINE; | |
| 153 | + WelsLog (pLogCtx, WELS_LOG_WARNING, "layerId(%d) doesn't support profile(%d), change to scalable baseline profile", | |
| 154 | + iLayer, uiProfileIdc); | |
| 155 | + } | |
| 156 | + if (pParam->iEntropyCodingModeFlag && (pLayerInfo->uiProfileIdc == PRO_SCALABLE_BASELINE)) { | |
| 157 | + pLayerInfo->uiProfileIdc = PRO_SCALABLE_HIGH; | |
| 158 | + WelsLog (pLogCtx, WELS_LOG_WARNING, "layerId(%d) change to scalable hight profile because cabac is enabled", iLayer); | |
| 146 | 159 | } |
| 147 | 160 | } |
| 148 | 161 | } |
| 149 | 162 | } |
| 150 | 163 | void CheckLevelSetting (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int32_t iLayer, ELevelIdc uiLevelIdc) { |
| 151 | 164 | SSpatialLayerConfig* pLayerInfo = &pParam->sSpatialLayers[iLayer]; |
| 152 | − pLayerInfo->uiLevelIdc = uiLevelIdc; | |
| 153 | − if (uiLevelIdc > LEVEL_5_2) { | |
| 154 | − WelsLog (pLogCtx, WELS_LOG_INFO, "change unexpected levelidc(%d) setting to LEVEL_UNKNOWN", pLayerInfo->uiLevelIdc); | |
| 155 | − pLayerInfo->uiLevelIdc = LEVEL_UNKNOWN; | |
| 165 | + pLayerInfo->uiLevelIdc = LEVEL_UNKNOWN; | |
| 166 | + int32_t iLevelIdx = LEVEL_NUMBER - 1; | |
| 167 | + do { | |
| 168 | + if (g_ksLevelLimits[iLevelIdx].uiLevelIdc == uiLevelIdc) { | |
| 169 | + pLayerInfo->uiLevelIdc = uiLevelIdc; | |
| 170 | + break; | |
| 171 | + } | |
| 172 | + iLevelIdx--; | |
| 173 | + } while (iLevelIdx >= 0); | |
| 174 | + if (pLayerInfo->uiLevelIdc == LEVEL_UNKNOWN) { | |
| 175 | + WelsLog (pLogCtx, WELS_LOG_INFO, "change unexpected levelidc(%d) setting to LEVEL_5_2", pLayerInfo->uiLevelIdc); | |
| 176 | + pLayerInfo->uiLevelIdc = LEVEL_5_2; | |
| 156 | 177 | } |
| 157 | 178 | } |
| 158 | 179 | void CheckReferenceNumSetting (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int32_t iNumRef) { |
| @@ -1626,8 +1647,11 @@ void GetMvMvdRange (SWelsSvcCodingParam* pParam, int32_t& iMvRange, int32_t& iMv · 1467 unmodified lines | ||
| 1626 | 1647 | if (pParam->sSpatialLayers[iLayer].uiLevelIdc < iMinLevelIdc) |
| 1627 | 1648 | iMinLevelIdc = pParam->sSpatialLayers[iLayer].uiLevelIdc; |
| 1628 | 1649 | } |
| 1629 | − iMinMv = (g_ksLevelLimits[iMinLevelIdc - 1].iMinVmv) >> 2; | |
| 1630 | − iMaxMv = (g_ksLevelLimits[iMinLevelIdc - 1].iMaxVmv) >> 2; | |
| 1650 | + const SLevelLimits* pLevelLimit = g_ksLevelLimits; | |
| 1651 | + while ((pLevelLimit->uiLevelIdc != LEVEL_5_2) && (pLevelLimit->uiLevelIdc != iMinLevelIdc)) | |
| 1652 | + pLevelLimit++; | |
| 1653 | + iMinMv = (pLevelLimit->iMinVmv) >> 2; | |
| 1654 | + iMaxMv = (pLevelLimit->iMaxVmv) >> 2; | |
| 1631 | 1655 | |
| 1632 | 1656 | iMvRange = WELS_MIN (WELS_ABS (iMinMv), iMaxMv); |
| 1633 | 1657 | |
| @@ -3990,9 +4014,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 2356 unmodified lines | ||
| 3990 | 4014 | iFrameSize += iLayerSize; |
| 3991 | 4015 | //check MinCr |
| 3992 | 4016 | { |
| 3993 | − int32_t iImageSize = (pParam->iVideoWidth * pParam->iVideoHeight * 3) >> 1; | |
| 3994 | − int32_t iMinCr = g_ksLevelLimits[pParam->uiLevelIdc - 1].uiMinCR; | |
| 3995 | − if (iFrameSize > (iImageSize / iMinCr)) | |
| 4017 | + int32_t iMinCrFrameSize = (pParam->iVideoWidth * pParam->iVideoHeight * 3) >> 2; //MinCr = 2; | |
| 4018 | + if (pParam->uiLevelIdc == LEVEL_3_1 || pParam->uiLevelIdc == LEVEL_3_2 || pParam->uiLevelIdc == LEVEL_4_0) | |
| 4019 | + iMinCrFrameSize >>= 1; //MinCr = 4 | |
| 4020 | + if (iFrameSize > iMinCrFrameSize) | |
| 3996 | 4021 | WelsLog (pLogCtx, WELS_LOG_WARNING, |
| 3997 | 4022 | "WelsEncoderEncodeExt()MinCr Checking,codec bitstream size is larger than Level limitation"); |
| 3998 | 4023 | } |