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