Showing the changes to codec/encoder/core/src/encoder.cpp (1 of 13 files). Show all
Unified · Split
| @@ -211,7 +211,7 @@ int32_t InitFunctionPointers (sWelsEncCtx* pEncCtx, SWelsSvcCodingParam* pParam, · 210 unmodified lines | ||
| 211 | 211 | /*init pixel average function*/ |
| 212 | 212 | /*get one column or row pixel when refinement*/ |
| 213 | 213 | InitMcFunc (&pFuncList->sMcFuncs, uiCpuFlag); |
| 214 | − InitCoeffFunc (pFuncList,uiCpuFlag,pParam->iEntropyCodingModeFlag); | |
| 214 | + InitCoeffFunc (pFuncList, uiCpuFlag, pParam->iEntropyCodingModeFlag); | |
| 215 | 215 | |
| 216 | 216 | WelsInitEncodingFuncs (pFuncList, uiCpuFlag); |
| 217 | 217 | WelsInitReconstructionFuncs (pFuncList, uiCpuFlag); |
| @@ -226,87 +226,97 @@ int32_t InitFunctionPointers (sWelsEncCtx* pEncCtx, SWelsSvcCodingParam* pParam, · 8 unmodified lines | ||
| 226 | 226 | return iReturn; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | −void UpdateFrameNum(sWelsEncCtx* pEncCtx) { | |
| 229 | +void UpdateFrameNum (sWelsEncCtx* pEncCtx, const int32_t kiDidx) { | |
| 230 | + SSpatialLayerInternal* pParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[kiDidx]; | |
| 230 | 231 | bool bNeedFrameNumIncreasing = false; |
| 231 | − for (int32_t i=0; i<MAX_DEPENDENCY_LAYER; i++) { | |
| 232 | − if (NRI_PRI_LOWEST != pEncCtx->eLastNalPriority[i]) { | |
| 233 | − bNeedFrameNumIncreasing = true; | |
| 234 | − } | |
| 232 | + | |
| 233 | + if (NRI_PRI_LOWEST != pEncCtx->eLastNalPriority[kiDidx]) { | |
| 234 | + bNeedFrameNumIncreasing = true; | |
| 235 | 235 | } |
| 236 | + | |
| 236 | 237 | if (bNeedFrameNumIncreasing) { |
| 237 | − if (pEncCtx->iFrameNum < (1 << pEncCtx->pSps->uiLog2MaxFrameNum) - 1) | |
| 238 | − ++ pEncCtx->iFrameNum; | |
| 238 | + if (pParamInternal->iFrameNum < (1 << pEncCtx->pSps->uiLog2MaxFrameNum) - 1) | |
| 239 | + ++ pParamInternal->iFrameNum; | |
| 239 | 240 | else |
| 240 | − pEncCtx->iFrameNum = 0; // if iFrameNum overflow | |
| 241 | − } | |
| 242 | − for (int32_t i=0; i<MAX_DEPENDENCY_LAYER; i++) { | |
| 243 | − pEncCtx->eLastNalPriority[i] = NRI_PRI_LOWEST; | |
| 241 | + pParamInternal->iFrameNum = 0; // if iFrameNum overflow | |
| 244 | 242 | } |
| 243 | + | |
| 244 | + pEncCtx->eLastNalPriority[kiDidx] = NRI_PRI_LOWEST; | |
| 245 | + WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_INFO, "UpdateFrameNum,bNeedFrameNumIncreasing = %d,iFrameNum = %d,kiDidx = %d", | |
| 246 | + bNeedFrameNumIncreasing, pParamInternal->iFrameNum, kiDidx); | |
| 245 | 247 | } |
| 246 | 248 | |
| 247 | 249 | |
| 248 | −void LoadBackFrameNum(sWelsEncCtx* pEncCtx) { | |
| 249 | − bool bNeedFrameNumIncreasing = false; | |
| 250 | − for (int32_t i=0; i<MAX_DEPENDENCY_LAYER; i++) { | |
| 251 | − if (NRI_PRI_LOWEST != pEncCtx->eLastNalPriority[i]) { | |
| 252 | − bNeedFrameNumIncreasing = true; | |
| 253 | − } | |
| 254 | − } | |
| 255 | − if (bNeedFrameNumIncreasing) { | |
| 256 | − if (pEncCtx->iFrameNum != 0) { | |
| 257 | − pEncCtx->iFrameNum --; | |
| 258 | − } else { | |
| 259 | − pEncCtx->iFrameNum = (1 << pEncCtx->pSps->uiLog2MaxFrameNum) - 1; | |
| 260 | − } | |
| 250 | +void LoadBackFrameNum (sWelsEncCtx* pEncCtx, const int32_t kiDidx) { | |
| 251 | + SSpatialLayerInternal* pParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[kiDidx]; | |
| 252 | + bool bNeedFrameNumIncreasing = false; | |
| 253 | + | |
| 254 | + if (NRI_PRI_LOWEST != pEncCtx->eLastNalPriority[kiDidx]) { | |
| 255 | + bNeedFrameNumIncreasing = true; | |
| 256 | + } | |
| 257 | + | |
| 258 | + if (bNeedFrameNumIncreasing) { | |
| 259 | + if (pParamInternal->iFrameNum != 0) { | |
| 260 | + pParamInternal->iFrameNum --; | |
| 261 | + } else { | |
| 262 | + pParamInternal->iFrameNum = (1 << pEncCtx->pSps->uiLog2MaxFrameNum) - 1; | |
| 261 | 263 | } |
| 264 | + } | |
| 265 | + WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_INFO, | |
| 266 | + "LoadBackFrameNum,bNeedFrameNumIncreasing = %d,iFrameNum = %d,kiDidx = %d", bNeedFrameNumIncreasing, | |
| 267 | + pParamInternal->iFrameNum, kiDidx); | |
| 262 | 268 | } |
| 263 | 269 | |
| 264 | −/*! | |
| 265 | − * \brief initialize frame coding | |
| 266 | − */ | |
| 267 | −void InitFrameCoding (sWelsEncCtx* pEncCtx, const EVideoFrameType keFrameType) { | |
| 270 | +void InitBitStream (sWelsEncCtx* pEncCtx) { | |
| 268 | 271 | // for bitstream writing |
| 269 | 272 | pEncCtx->iPosBsBuffer = 0; // reset bs pBuffer position |
| 270 | 273 | pEncCtx->pOut->iNalIndex = 0; // reset NAL index |
| 271 | 274 | pEncCtx->pOut->iLayerBsIndex = 0; // reset index of Layer Bs |
| 272 | 275 | |
| 273 | 276 | InitBits (&pEncCtx->pOut->sBsWrite, pEncCtx->pOut->pBsBuffer, pEncCtx->pOut->uiSize); |
| 274 | − | |
| 277 | +} | |
| 278 | +/*! | |
| 279 | + * \brief initialize frame coding | |
| 280 | + */ | |
| 281 | +void InitFrameCoding (sWelsEncCtx* pEncCtx, const EVideoFrameType keFrameType, const int32_t kiDidx) { | |
| 282 | + SSpatialLayerInternal* pParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[kiDidx]; | |
| 275 | 283 | if (keFrameType == videoFrameTypeP) { |
| 276 | − ++pEncCtx->iFrameIndex; | |
| 284 | + ++pParamInternal->iFrameIndex; | |
| 277 | 285 | |
| 278 | − if (pEncCtx->iPOC < (1 << pEncCtx->pSps->iLog2MaxPocLsb) - 2) // if iPOC type is no 0, this need be modification | |
| 279 | − pEncCtx->iPOC += 2; // for POC type 0 | |
| 286 | + if (pParamInternal->iPOC < (1 << pEncCtx->pSps->iLog2MaxPocLsb) - | |
| 287 | + 2) // if iPOC type is no 0, this need be modification | |
| 288 | + pParamInternal->iPOC += 2; // for POC type 0 | |
| 280 | 289 | else |
| 281 | − pEncCtx->iPOC = 0; | |
| 290 | + pParamInternal->iPOC = 0; | |
| 282 | 291 | |
| 283 | − UpdateFrameNum(pEncCtx); | |
| 292 | + UpdateFrameNum (pEncCtx, kiDidx); | |
| 284 | 293 | |
| 285 | 294 | pEncCtx->eNalType = NAL_UNIT_CODED_SLICE; |
| 286 | 295 | pEncCtx->eSliceType = P_SLICE; |
| 287 | 296 | pEncCtx->eNalPriority = NRI_PRI_HIGH; |
| 288 | 297 | } else if (keFrameType == videoFrameTypeIDR) { |
| 289 | − pEncCtx->iFrameNum = 0; | |
| 290 | − pEncCtx->iPOC = 0; | |
| 291 | − pEncCtx->bEncCurFrmAsIdrFlag = false; | |
| 292 | − pEncCtx->iFrameIndex = 0; | |
| 298 | + pParamInternal->iFrameNum = 0; | |
| 299 | + pParamInternal->iPOC = 0; | |
| 300 | + pParamInternal->bEncCurFrmAsIdrFlag = false; | |
| 301 | + pParamInternal->iFrameIndex = 0; | |
| 293 | 302 | |
| 294 | 303 | pEncCtx->eNalType = NAL_UNIT_CODED_SLICE_IDR; |
| 295 | 304 | pEncCtx->eSliceType = I_SLICE; |
| 296 | 305 | pEncCtx->eNalPriority = NRI_PRI_HIGHEST; |
| 297 | 306 | |
| 298 | − pEncCtx->iCodingIndex = 0; | |
| 307 | + pParamInternal->iCodingIndex = 0; | |
| 299 | 308 | |
| 300 | 309 | // reset_ref_list |
| 301 | 310 | |
| 302 | 311 | // rc_init_gop |
| 303 | 312 | } else if (keFrameType == videoFrameTypeI) { |
| 304 | − if (pEncCtx->iPOC < (1 << pEncCtx->pSps->iLog2MaxPocLsb) - 2) // if iPOC type is no 0, this need be modification | |
| 305 | − pEncCtx->iPOC += 2; // for POC type 0 | |
| 313 | + if (pParamInternal->iPOC < (1 << pEncCtx->pSps->iLog2MaxPocLsb) - | |
| 314 | + 2) // if iPOC type is no 0, this need be modification | |
| 315 | + pParamInternal->iPOC += 2; // for POC type 0 | |
| 306 | 316 | else |
| 307 | − pEncCtx->iPOC = 0; | |
| 317 | + pParamInternal->iPOC = 0; | |
| 308 | 318 | |
| 309 | − UpdateFrameNum(pEncCtx); | |
| 319 | + UpdateFrameNum (pEncCtx, kiDidx); | |
| 310 | 320 | |
| 311 | 321 | pEncCtx->eNalType = NAL_UNIT_CODED_SLICE; |
| 312 | 322 | pEncCtx->eSliceType = I_SLICE; |
| @@ -322,11 +332,12 @@ void InitFrameCoding (sWelsEncCtx* pEncCtx, const EVideoFrameType keFrameType) { · 9 unmodified lines | ||
| 322 | 332 | #endif//FRAME_INFO_OUTPUT |
| 323 | 333 | } |
| 324 | 334 | |
| 325 | −EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum) { | |
| 335 | +EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum, const int32_t kiDidx) { | |
| 326 | 336 | SWelsSvcCodingParam* pSvcParam = pEncCtx->pSvcParam; |
| 337 | + SSpatialLayerInternal* pParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[kiDidx]; | |
| 327 | 338 | EVideoFrameType iFrameType = videoFrameTypeInvalid; |
| 328 | 339 | bool bSceneChangeFlag = false; |
| 329 | − | |
| 340 | + int32_t iSkipFrameFlag = pSvcParam->bSimulcastAVC?pParamInternal->iSkipFrameFlag:pEncCtx->iSkipFrameFlag; | |
| 330 | 341 | if (pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) { |
| 331 | 342 | if ((!pSvcParam->bEnableSceneChangeDetect) || pEncCtx->pVaa->bIdrPeriodFlag || |
| 332 | 343 | (kiSpatialNum < pSvcParam->iSpatialLayerNum)) { |
| @@ -334,7 +345,7 @@ EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum · 1 unmodified line | ||
| 334 | 345 | } else { |
| 335 | 346 | bSceneChangeFlag = pEncCtx->pVaa->bSceneChangeFlag; |
| 336 | 347 | } |
| 337 | − if (pEncCtx->pVaa->bIdrPeriodFlag || pEncCtx->bEncCurFrmAsIdrFlag || (!pSvcParam->bEnableLongTermReference | |
| 348 | + if (pEncCtx->pVaa->bIdrPeriodFlag || pParamInternal->bEncCurFrmAsIdrFlag || (!pSvcParam->bEnableLongTermReference | |
| 338 | 349 | && bSceneChangeFlag)) { |
| 339 | 350 | iFrameType = videoFrameTypeIDR; |
| 340 | 351 | } else if (pSvcParam->bEnableLongTermReference && (bSceneChangeFlag |
| @@ -356,11 +367,11 @@ EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum · 15 unmodified lines | ||
| 356 | 367 | } else { |
| 357 | 368 | iFrameType = videoFrameTypeP; |
| 358 | 369 | } |
| 359 | − if (videoFrameTypeP == iFrameType && pEncCtx->iSkipFrameFlag > 0) { | |
| 360 | − -- pEncCtx->iSkipFrameFlag; | |
| 370 | + if (videoFrameTypeP == iFrameType && iSkipFrameFlag > 0) { | |
| 371 | + pParamInternal->iSkipFrameFlag = 0; | |
| 361 | 372 | iFrameType = videoFrameTypeSkip; |
| 362 | 373 | } else if (videoFrameTypeIDR == iFrameType) { |
| 363 | − pEncCtx->iCodingIndex = 0; | |
| 374 | + pParamInternal->iCodingIndex = 0; | |
| 364 | 375 | pEncCtx->bCurFrameMarkedAsSceneLtr = true; |
| 365 | 376 | } |
| 366 | 377 | |
| @@ -368,7 +379,7 @@ EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum · 1 unmodified line | ||
| 368 | 379 | // perform scene change detection |
| 369 | 380 | if ((!pSvcParam->bEnableSceneChangeDetect) || pEncCtx->pVaa->bIdrPeriodFlag || |
| 370 | 381 | (kiSpatialNum < pSvcParam->iSpatialLayerNum) |
| 371 | − || (pEncCtx->iFrameIndex < (VGOP_SIZE << 1))) { // avoid too frequent I frame coding, rc control | |
| 382 | + || (pParamInternal->iFrameIndex < (VGOP_SIZE << 1))) { // avoid too frequent I frame coding, rc control | |
| 372 | 383 | bSceneChangeFlag = false; |
| 373 | 384 | } else { |
| 374 | 385 | bSceneChangeFlag = pEncCtx->pVaa->bSceneChangeFlag; |
| @@ -378,13 +389,13 @@ EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum · 3 unmodified lines | ||
| 378 | 389 | //bIdrPeriodFlag: RC disable || iSpatialNum != pSvcParam->iSpatialLayerNum |
| 379 | 390 | //pEncCtx->bEncCurFrmAsIdrFlag: 1. first frame should be IDR; 2. idr pause; 3. idr request |
| 380 | 391 | iFrameType = (pEncCtx->pVaa->bIdrPeriodFlag || bSceneChangeFlag |
| 381 | − || pEncCtx->bEncCurFrmAsIdrFlag) ? videoFrameTypeIDR : videoFrameTypeP; | |
| 392 | + || pParamInternal->bEncCurFrmAsIdrFlag) ? videoFrameTypeIDR : videoFrameTypeP; | |
| 382 | 393 | |
| 383 | − if (videoFrameTypeP == iFrameType && pEncCtx->iSkipFrameFlag > 0) { // for frame skip, 1/5/2010 | |
| 384 | − -- pEncCtx->iSkipFrameFlag; | |
| 394 | + if (videoFrameTypeP == iFrameType && iSkipFrameFlag > 0) { // for frame skip, 1/5/2010 | |
| 395 | + pParamInternal->iSkipFrameFlag = 0; | |
| 385 | 396 | iFrameType = videoFrameTypeSkip; |
| 386 | 397 | } else if (videoFrameTypeIDR == iFrameType) { |
| 387 | − pEncCtx->iCodingIndex = 0; | |
| 398 | + pParamInternal->iCodingIndex = 0; | |
| 388 | 399 | } |
| 389 | 400 | } |
| 390 | 401 | return iFrameType; |