refact validate and init logic for fixed sliceMode
Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 2 files). Show all
Unified · Split
| @@ -165,6 +165,83 @@ void CheckReferenceNumSetting (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam · 164 unmodified lines | ||
| 165 | 165 | "doesn't support the number of reference frame(%d) change to auto select mode", iNumRef); |
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | + | |
| 169 | +int32_t SliceArgumentValidationFixedSliceMode(SLogContext* pLogCtx, | |
| 170 | + SSliceArgument* pSliceArgument, const RC_MODES kiRCMode, | |
| 171 | + const int32_t kiPicWidth, const int32_t kiPicHeight) { | |
| 172 | + int32_t iCpuCores = 0; | |
| 173 | + int32_t iIdx = 0; | |
| 174 | + const int32_t iMbWidth = (kiPicWidth + 15) >> 4; | |
| 175 | + const int32_t iMbHeight = (kiPicHeight + 15) >> 4; | |
| 176 | + const int32_t iMbNumInFrame = iMbWidth * iMbHeight; | |
| 177 | + bool bSingleMode = false; | |
| 178 | + | |
| 179 | + pSliceArgument->uiSliceSizeConstraint = 0; | |
| 180 | + | |
| 181 | + if (pSliceArgument->uiSliceNum == 0) { | |
| 182 | + WelsCPUFeatureDetect (&iCpuCores); | |
| 183 | + pSliceArgument->uiSliceNum = iCpuCores; | |
| 184 | + } | |
| 185 | + | |
| 186 | + if (pSliceArgument->uiSliceNum <= 1) { | |
| 187 | + WelsLog (pLogCtx, WELS_LOG_INFO, "SliceArgumentValidationFixedSliceMode(), uiSliceNum(%d) you set for SM_FIXEDSLCNUM_SLICE, now turn to SM_SINGLE_SLICE type!", | |
| 188 | + pSliceArgument->uiSliceNum); | |
| 189 | + bSingleMode = true; | |
| 190 | + } | |
| 191 | + | |
| 192 | + // considering the coding efficient and performance, | |
| 193 | + // iCountMbNum constraint by MIN_NUM_MB_PER_SLICE condition of multi-pSlice mode settting | |
| 194 | + if (iMbNumInFrame <= MIN_NUM_MB_PER_SLICE) { | |
| 195 | + WelsLog (pLogCtx, WELS_LOG_INFO, "SliceArgumentValidationFixedSliceMode(), uiSliceNum(%d) you set for SM_FIXEDSLCNUM_SLICE, now turn to SM_SINGLE_SLICE type as CountMbNum less than MIN_NUM_MB_PER_SLICE!", | |
| 196 | + pSliceArgument->uiSliceNum); | |
| 197 | + bSingleMode = true; | |
| 198 | + } | |
| 199 | + | |
| 200 | + if (bSingleMode) { | |
| 201 | + pSliceArgument->uiSliceMode = SM_SINGLE_SLICE; | |
| 202 | + pSliceArgument->uiSliceNum = 1; | |
| 203 | + for (iIdx = 0; iIdx < MAX_SLICES_NUM; iIdx++) { | |
| 204 | + pSliceArgument->uiSliceMbNum[iIdx] = 0; | |
| 205 | + } | |
| 206 | + return ENC_RETURN_SUCCESS; | |
| 207 | + } | |
| 208 | + | |
| 209 | + if (pSliceArgument->uiSliceNum > MAX_SLICES_NUM) { | |
| 210 | + pSliceArgument->uiSliceNum = MAX_SLICES_NUM; | |
| 211 | + WelsLog (pLogCtx, WELS_LOG_WARNING, "SliceArgumentValidationFixedSliceMode(), uiSliceNum exceed MAX_SLICES_NUM! So setting slice num eqaul to MAX_SLICES_NUM(%d)!", | |
| 212 | + pSliceArgument->uiSliceNum); | |
| 213 | + } | |
| 214 | + | |
| 215 | + if (kiRCMode != RC_OFF_MODE) { // multiple slices verify with gom | |
| 216 | + //check uiSliceNum and set uiSliceMbNum with current uiSliceNum | |
| 217 | + if (!GomValidCheckSliceNum (iMbWidth, iMbHeight, &pSliceArgument->uiSliceNum)) { | |
| 218 | + WelsLog (pLogCtx, WELS_LOG_WARNING, "SliceArgumentValidationFixedSliceMode(), unsupported setting with Resolution and uiSliceNum combination under RC on! So uiSliceNum is changed to %d!", | |
| 219 | + pSliceArgument->uiSliceNum); | |
| 220 | + } | |
| 221 | + | |
| 222 | + if (pSliceArgument->uiSliceNum <= 1 || | |
| 223 | + !GomValidCheckSliceMbNum (iMbWidth, iMbHeight, pSliceArgument)) { | |
| 224 | + WelsLog (pLogCtx, WELS_LOG_ERROR, | |
| 225 | + "SliceArgumentValidationFixedSliceMode(), unsupported setting with Resolution and uiSliceNum (%d) combination under RC on! Consider setting single slice with this resolution!", | |
| 226 | + pSliceArgument->uiSliceNum); | |
| 227 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 228 | + } | |
| 229 | + } else if (!CheckFixedSliceNumMultiSliceSetting (iMbNumInFrame, pSliceArgument)) { | |
| 230 | + //check uiSliceMbNum with current uiSliceNum | |
| 231 | + WelsLog (pLogCtx, WELS_LOG_ERROR, | |
| 232 | + "SliceArgumentValidationFixedSliceMode(), invalid uiSliceMbNum (%d) settings!,now turn to SM_SINGLE_SLICE type", | |
| 233 | + pSliceArgument->uiSliceMbNum[0]); | |
| 234 | + pSliceArgument->uiSliceMode = SM_SINGLE_SLICE; | |
| 235 | + pSliceArgument->uiSliceNum = 1; | |
| 236 | + for (iIdx = 0; iIdx < MAX_SLICES_NUM; iIdx++) { | |
| 237 | + pSliceArgument->uiSliceMbNum[iIdx] = 0; | |
| 238 | + } | |
| 239 | + } | |
| 240 | + | |
| 241 | + return ENC_RETURN_SUCCESS; | |
| 242 | +} | |
| 243 | + | |
| 244 | + | |
| 168 | 245 | /*! |
| 169 | 246 | * \brief validate checking in parameter configuration |
| 170 | 247 | * \pParam pParam SWelsSvcCodingParam* |
| @@ -398,6 +475,7 @@ int32_t ParamValidationExt (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingPa · 227 unmodified lines | ||
| 398 | 475 | uint32_t iMbHeight = 0; |
| 399 | 476 | int32_t iMbNumInFrame = 0; |
| 400 | 477 | uint32_t iMaxSliceNum = MAX_SLICES_NUM; |
| 478 | + int32_t iReturn = 0; | |
| 401 | 479 | if ((kiPicWidth <= 0) || (kiPicHeight <= 0) || (kiPicWidth > MAX_WIDTH) || (kiPicHeight > MAX_HEIGHT)) { |
| 402 | 480 | WelsLog (pLogCtx, WELS_LOG_ERROR, |
| 403 | 481 | "ParamValidationExt(),width(1-%d),height(1-%d)invalid %d x %d in dependency layer settings!", MAX_WIDTH, MAX_HEIGHT, |
| @@ -436,68 +514,10 @@ int32_t ParamValidationExt (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingPa · 32 unmodified lines | ||
| 436 | 514 | } |
| 437 | 515 | break; |
| 438 | 516 | case SM_FIXEDSLCNUM_SLICE: { |
| 439 | − pSpatialLayer->sSliceArgument.uiSliceSizeConstraint = 0; | |
| 440 | − | |
| 441 | − iMbWidth = (kiPicWidth + 15) >> 4; | |
| 442 | − iMbHeight = (kiPicHeight + 15) >> 4; | |
| 443 | − iMbNumInFrame = iMbWidth * iMbHeight; | |
| 444 | − iMaxSliceNum = MAX_SLICES_NUM; | |
| 445 | − if (pSpatialLayer->sSliceArgument.uiSliceNum == 0) { | |
| 446 | − int32_t uiCpuCores = 0; | |
| 447 | − WelsCPUFeatureDetect (&uiCpuCores); // detect cpu capacity features | |
| 448 | − pSpatialLayer->sSliceArgument.uiSliceNum = uiCpuCores; | |
| 449 | − | |
| 450 | − if (uiCpuCores <= 1) { | |
| 451 | − WelsLog (pLogCtx, WELS_LOG_INFO, "ParamValidationExt(), uiCpuCores = 1, switched to SM_SINGLE_SLICE"); | |
| 452 | − pSpatialLayer->sSliceArgument.uiSliceMode = SM_SINGLE_SLICE; | |
| 453 | − pSpatialLayer->sSliceArgument.uiSliceNum = 1; | |
| 454 | − pSpatialLayer->sSliceArgument.uiSliceSizeConstraint = 0; | |
| 455 | − for (iIdx = 0; iIdx < MAX_SLICES_NUM; iIdx++) { | |
| 456 | − pSpatialLayer->sSliceArgument.uiSliceMbNum[iIdx] = 0; | |
| 457 | − } | |
| 458 | − break; | |
| 459 | − } | |
| 460 | − } | |
| 461 | − if (pSpatialLayer->sSliceArgument.uiSliceNum > iMaxSliceNum) { | |
| 462 | − WelsLog (pLogCtx, WELS_LOG_ERROR, "ParamValidationExt(), invalid uiSliceNum (%d) settings!", | |
| 463 | − pSpatialLayer->sSliceArgument.uiSliceNum); | |
| 464 | − return ENC_RETURN_UNSUPPORTED_PARA; | |
| 465 | − } | |
| 466 | − if (pSpatialLayer->sSliceArgument.uiSliceNum == 1) { | |
| 467 | − WelsLog (pLogCtx, WELS_LOG_DEBUG, | |
| 468 | − "ParamValidationExt(), uiSliceNum(%d) you set for SM_FIXEDSLCNUM_SLICE, now turn to SM_SINGLE_SLICE type!", | |
| 469 | − pSpatialLayer->sSliceArgument.uiSliceNum); | |
| 470 | − pSpatialLayer->sSliceArgument.uiSliceMode = SM_SINGLE_SLICE; | |
| 471 | − break; | |
| 472 | − } | |
| 473 | − if (pCodingParam->iRCMode != RC_OFF_MODE) { // multiple slices verify with gom | |
| 474 | − //check uiSliceNum and set uiSliceMbNum with current uiSliceNum | |
| 475 | − if (!GomValidCheckSliceNum (iMbWidth, iMbHeight, &pSpatialLayer->sSliceArgument.uiSliceNum)) { | |
| 476 | − WelsLog (pLogCtx, WELS_LOG_WARNING, | |
| 477 | − "ParamValidationExt(), unsupported setting with Resolution and uiSliceNum combination under RC on! So uiSliceNum is changed to %d!", | |
| 478 | − pSpatialLayer->sSliceArgument.uiSliceNum); | |
| 479 | − } | |
| 480 | − if (pSpatialLayer->sSliceArgument.uiSliceNum <= 1 || | |
| 481 | − !GomValidCheckSliceMbNum (iMbWidth, iMbHeight, &pSpatialLayer->sSliceArgument)) { | |
| 482 | − WelsLog (pLogCtx, WELS_LOG_ERROR, | |
| 483 | − "ParamValidationExt(), unsupported setting with Resolution and uiSliceNum (%d) combination under RC on! Consider setting single slice with this resolution!", | |
| 484 | − pSpatialLayer->sSliceArgument.uiSliceNum); | |
| 485 | − return ENC_RETURN_UNSUPPORTED_PARA; | |
| 486 | − } | |
| 487 | − assert (pSpatialLayer->sSliceArgument.uiSliceNum > 1); | |
| 488 | − } else if (!CheckFixedSliceNumMultiSliceSetting (iMbNumInFrame, | |
| 489 | − &pSpatialLayer->sSliceArgument)) { // verify interleave mode settings | |
| 490 | − //check uiSliceMbNum with current uiSliceNum | |
| 491 | − WelsLog (pLogCtx, WELS_LOG_ERROR, "ParamValidationExt(), invalid uiSliceMbNum (%d) settings!", | |
| 492 | − pSpatialLayer->sSliceArgument.uiSliceMbNum[0]); | |
| 517 | + iReturn = SliceArgumentValidationFixedSliceMode(pLogCtx, &pSpatialLayer->sSliceArgument, pCodingParam->iRCMode, | |
| 518 | + kiPicWidth, kiPicHeight); | |
| 519 | + if(iReturn) | |
| 493 | 520 | return ENC_RETURN_UNSUPPORTED_PARA; |
| 494 | − } | |
| 495 | − // considering the coding efficient and performance, iCountMbNum constraint by MIN_NUM_MB_PER_SLICE condition of multi-pSlice mode settting | |
| 496 | − if (iMbNumInFrame <= MIN_NUM_MB_PER_SLICE) { | |
| 497 | − pSpatialLayer->sSliceArgument.uiSliceMode = SM_SINGLE_SLICE; | |
| 498 | − pSpatialLayer->sSliceArgument.uiSliceNum = 1; | |
| 499 | − break; | |
| 500 | − } | |
| 501 | 521 | } |
| 502 | 522 | break; |
| 503 | 523 | case SM_RASTER_SLICE: { |
| @@ -2232,10 +2252,8 @@ int32_t InitSliceSettings (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingPar · 1728 unmodified lines | ||
| 2232 | 2252 | |
| 2233 | 2253 | do { |
| 2234 | 2254 | SSpatialLayerConfig* pDlp = &pCodingParam->sSpatialLayers[iSpatialIdx]; |
| 2235 | − SSliceArgument* pSliceArgument = &pDlp->sSliceArgument; | |
| 2236 | − const int32_t kiMbWidth = (pDlp->iVideoWidth + 15) >> 4; | |
| 2237 | − const int32_t kiMbHeight = (pDlp->iVideoHeight + 15) >> 4; | |
| 2238 | − const int32_t kiMbNumInFrame = kiMbWidth * kiMbHeight; | |
| 2255 | + SSliceArgument* pSliceArgument = &pDlp->sSliceArgument; | |
| 2256 | + int32_t iReturn = 0; | |
| 2239 | 2257 | int32_t iSliceNum = (SM_FIXEDSLCNUM_SLICE == pSliceArgument->uiSliceMode && 0==pSliceArgument->uiSliceNum) ? kiCpuCores : pSliceArgument->uiSliceNum; |
| 2240 | 2258 | // NOTE: Per design, in case MT/DYNAMIC_SLICE_ASSIGN enabled, for SM_FIXEDSLCNUM_SLICE mode, |
| 2241 | 2259 | // uiSliceNum of current spatial layer settings equals to uiCpuCores number; SM_SIZELIMITED_SLICE mode, |
| @@ -2246,80 +2264,17 @@ int32_t InitSliceSettings (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingPar · 4 unmodified lines | ||
| 2246 | 2264 | case SM_SIZELIMITED_SLICE: |
| 2247 | 2265 | iMaxSliceCount = AVERSLICENUM_CONSTRAINT; |
| 2248 | 2266 | break; // go through for SM_SIZELIMITED_SLICE? |
| 2249 | − case SM_FIXEDSLCNUM_SLICE: | |
| 2250 | − if (iSliceNum > iMaxSliceCount) { | |
| 2251 | − iMaxSliceCount = iSliceNum; | |
| 2252 | − } | |
| 2253 | − if (0==iSliceNum) { | |
| 2254 | − //the auto slice num logic | |
| 2255 | − pDlp->sSliceArgument.uiSliceNum = kiCpuCores; | |
| 2256 | − | |
| 2257 | − if (0==kiCpuCores){ | |
| 2258 | − int32_t uiCpuCores = 0; | |
| 2259 | − WelsCPUFeatureDetect (&uiCpuCores); // detect cpu capacity features | |
| 2260 | − pDlp->sSliceArgument.uiSliceNum = uiCpuCores; | |
| 2261 | − | |
| 2262 | − if (uiCpuCores == 1) { | |
| 2263 | − WelsLog (pLogCtx, WELS_LOG_INFO, "InitSliceSettings(), uiCpuCores = 1, switched to SM_SINGLE_SLICE"); | |
| 2264 | − pDlp->sSliceArgument.uiSliceMode = SM_SINGLE_SLICE; | |
| 2265 | − pDlp->sSliceArgument.uiSliceNum = 1; | |
| 2266 | − pDlp->sSliceArgument.uiSliceSizeConstraint = 0; | |
| 2267 | − for (int32_t iIdx = 0; iIdx < MAX_SLICES_NUM; iIdx++) { | |
| 2268 | − pDlp->sSliceArgument.uiSliceMbNum[iIdx] = 0; | |
| 2269 | − } | |
| 2270 | − break; | |
| 2271 | − } | |
| 2272 | − } | |
| 2273 | − | |
| 2274 | − if (pDlp->sSliceArgument.uiSliceNum == 1) { | |
| 2275 | − WelsLog (pLogCtx, WELS_LOG_DEBUG, | |
| 2276 | − "InitSliceSettings(), uiSliceNum(%d) you set for SM_AUTO_SLICE, now turn to SM_SINGLE_SLICE type!", | |
| 2277 | − pDlp->sSliceArgument.uiSliceNum); | |
| 2278 | − pDlp->sSliceArgument.uiSliceMode = SM_SINGLE_SLICE; | |
| 2279 | − break; | |
| 2280 | − } | |
| 2281 | − | |
| 2282 | − if (pDlp->sSliceArgument.uiSliceNum > MAX_SLICES_NUM) { | |
| 2283 | − pDlp->sSliceArgument.uiSliceNum = MAX_SLICES_NUM; | |
| 2284 | − } | |
| 2285 | − iMaxSliceCount = WELS_MAX(iMaxSliceCount, pDlp->sSliceArgument.uiSliceNum); | |
| 2267 | + case SM_FIXEDSLCNUM_SLICE: { | |
| 2268 | + iReturn = SliceArgumentValidationFixedSliceMode(pLogCtx, &pDlp->sSliceArgument, pCodingParam->iRCMode, | |
| 2269 | + pDlp->iVideoWidth, pDlp->iVideoHeight); | |
| 2270 | + if(iReturn) | |
| 2271 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 2286 | 2272 | |
| 2287 | − if (pCodingParam->iRCMode != RC_OFF_MODE) { // multiple slices verify with gom | |
| 2288 | − //check uiSliceNum and set uiSliceMbNum with current uiSliceNum | |
| 2289 | − if (!GomValidCheckSliceNum (kiMbWidth, kiMbHeight, &pDlp->sSliceArgument.uiSliceNum)) { | |
| 2290 | − WelsLog (pLogCtx, WELS_LOG_WARNING, | |
| 2291 | − "InitSliceSettings(), unsupported setting with Resolution and uiSliceNum combination under RC on! So uiSliceNum is changed to %d!", | |
| 2292 | − pDlp->sSliceArgument.uiSliceNum); | |
| 2293 | − } | |
| 2294 | − if (pDlp->sSliceArgument.uiSliceNum <= 1 || | |
| 2295 | − !GomValidCheckSliceMbNum (kiMbWidth, kiMbHeight, &pDlp->sSliceArgument)) { | |
| 2296 | − WelsLog (pLogCtx, WELS_LOG_ERROR, | |
| 2297 | − "InitSliceSettings(), unsupported setting with Resolution and uiSliceNum (%d) combination under RC on! Consider setting single slice with this resolution!", | |
| 2298 | − pDlp->sSliceArgument.uiSliceNum); | |
| 2299 | − return ENC_RETURN_INVALIDINPUT; | |
| 2300 | − } | |
| 2301 | − } else if (!CheckFixedSliceNumMultiSliceSetting (kiMbNumInFrame, | |
| 2302 | − &pDlp->sSliceArgument)) { // verify interleave mode settings | |
| 2303 | − //check uiSliceMbNum with current uiSliceNum | |
| 2304 | − WelsLog (pLogCtx, WELS_LOG_ERROR, | |
| 2305 | − "InitSliceSettings(), invalid uiSliceMbNum (%d) settings!,now turn to SM_SINGLE_SLICE type", | |
| 2306 | − pDlp->sSliceArgument.uiSliceMbNum[0]); | |
| 2307 | − pDlp->sSliceArgument.uiSliceMode = SM_SINGLE_SLICE; | |
| 2308 | − pDlp->sSliceArgument.uiSliceNum = 1; | |
| 2309 | − } | |
| 2310 | − // considering the coding efficient and performance, iCountMbNum constraint by MIN_NUM_MB_PER_SLICE condition of multi-pSlice mode settting | |
| 2311 | − if (kiMbNumInFrame <= MIN_NUM_MB_PER_SLICE) { | |
| 2312 | − pDlp->sSliceArgument.uiSliceMode = SM_SINGLE_SLICE; | |
| 2313 | − pDlp->sSliceArgument.uiSliceNum = 1; | |
| 2314 | − break; | |
| 2315 | − } | |
| 2316 | − } | |
| 2317 | − // need perform check due uiSliceNum might change, although has been initialized somewhere outside | |
| 2318 | − if (pCodingParam->iRCMode != RC_OFF_MODE) { | |
| 2319 | − GomValidCheckSliceMbNum (kiMbWidth, kiMbHeight, pSliceArgument); | |
| 2320 | − } else { | |
| 2321 | − CheckFixedSliceNumMultiSliceSetting (kiMbNumInFrame, pSliceArgument); | |
| 2273 | + if (pSliceArgument->uiSliceNum > iMaxSliceCount) { | |
| 2274 | + iMaxSliceCount = pSliceArgument->uiSliceNum; | |
| 2322 | 2275 | } |
| 2276 | + | |
| 2277 | + } | |
| 2323 | 2278 | break; |
| 2324 | 2279 | case SM_SINGLE_SLICE: |
| 2325 | 2280 | if (iSliceNum > iMaxSliceCount) |
| @@ -3838,8 +3793,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 1512 unmodified lines | ||
| 3838 | 3793 | switch (pParam->sSliceArgument.uiSliceMode) { |
| 3839 | 3794 | case SM_FIXEDSLCNUM_SLICE: { |
| 3840 | 3795 | if ((iCurDid > 0) && (pSvcParam->iMultipleThreadIdc > 1) && |
| 3841 | − (pSvcParam->sSpatialLayers[iCurDid].sSliceArgument.uiSliceMode == SM_FIXEDSLCNUM_SLICE | |
| 3842 | − && pSvcParam->bUseLoadBalancing | |
| 3796 | + (pSvcParam->bUseLoadBalancing | |
| 3843 | 3797 | && pSvcParam->iMultipleThreadIdc >= pSvcParam->sSpatialLayers[iCurDid].sSliceArgument.uiSliceNum) |
| 3844 | 3798 | ) |
| 3845 | 3799 | AdjustEnhanceLayer (pCtx, iCurDid); |