History

add decide frame type for screen content

ruil2 committed 12 years ago

Commit 2eff8081 parent 082248d3 files · +64 −23Browse files

Showing the changes to codec/encoder/core/src/encoder.cpp (1 of 3 files). Show all

Unified · Split

codec/encoder/core/src/encoder.cpp+58−23
@@ -77,8 +77,8 @@ int32_t InitPic (const void* kpSrc, const int32_t kiColorspace, const int32_t ki · 76 unmodified lines
7777 pSrcPic->iPicHeight = kiHeight;
7878
7979 //currently encoder only supports videoFormatI420.
80− if((kiColorspace & (~videoFormatVFlip))!= videoFormatI420)
81− return 2;
80+ if ((kiColorspace & (~videoFormatVFlip)) != videoFormatI420)
81+ return 2;
8282 switch (kiColorspace & (~videoFormatVFlip)) {
8383 case videoFormatI420:
8484 case videoFormatYV12:
@@ -184,7 +184,7 @@ int32_t InitFunctionPointers (SWelsFuncPtrList* pFuncList, SWelsSvcCodingParam* · 99 unmodified lines
184184 WelsInitIntraPredFuncs (pFuncList, uiCpuFlag);
185185
186186 /* ME func */
187− WelsInitMeFunc(pFuncList, uiCpuFlag, SCREEN_CONTENT_REAL_TIME==pParam->iUsageType);
187+ WelsInitMeFunc (pFuncList, uiCpuFlag, SCREEN_CONTENT_REAL_TIME == pParam->iUsageType);
188188
189189 /* sad, satd, average */
190190 WelsInitSampleSadFunc (pFuncList, uiCpuFlag);
@@ -207,7 +207,7 @@ int32_t InitFunctionPointers (SWelsFuncPtrList* pFuncList, SWelsSvcCodingParam* · 16 unmodified lines
207207 WelsBlockFuncInit (&pFuncList->pfSetNZCZero, uiCpuFlag);
208208
209209 InitFillNeighborCacheInterFunc (pFuncList, pParam->bEnableBackgroundDetection);
210− InitRefListMgrFunc(pFuncList,pParam->iUsageType);
210+ InitRefListMgrFunc (pFuncList, pParam->iUsageType);
211211 return iReturn;
212212 }
213213
@@ -285,28 +285,63 @@ EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum · 71 unmodified lines
285285 EVideoFrameType iFrameType = videoFrameTypeInvalid;
286286 bool bSceneChangeFlag = false;
287287
288− // perform scene change detection
289− if ((!pSvcParam->bEnableSceneChangeDetect) || pEncCtx->pVaa->bIdrPeriodFlag ||
290− (kiSpatialNum < pSvcParam->iSpatialLayerNum)
291− || (pEncCtx->iFrameIndex < (VGOP_SIZE << 1))) { // avoid too frequent I frame coding, rc control
292− bSceneChangeFlag = false;
288+ if (pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
289+ if ((!pSvcParam->bEnableSceneChangeDetect) || pEncCtx->pVaa->bIdrPeriodFlag ||
290+ (kiSpatialNum < pSvcParam->iSpatialLayerNum)) {
291+ bSceneChangeFlag = false;
292+ } else {
293+ bSceneChangeFlag = pEncCtx->pVaa->bSceneChangeFlag;
294+ }
295+ pEncCtx->bCurFrameMarkedAsSceneLtr = false;
296+ if (pEncCtx->pVaa->bIdrPeriodFlag || pEncCtx->bEncCurFrmAsIdrFlag || (!pSvcParam->bEnableLongTermReference
297+ && bSceneChangeFlag)) {
298+ iFrameType = videoFrameTypeIDR;
299+ } else if (pSvcParam->bEnableLongTermReference && (bSceneChangeFlag
300+ || pEncCtx->pVaa->eSceneChangeIdc == LARGE_CHANGED_SCENE)) {
301+ int iActualLtrcount = 0;
302+ SPicture** pLongTermRefList = pEncCtx->ppRefPicListExt[0]->pLongRefList;
303+ for (int i = 0; i < pSvcParam->iLTRRefNum; ++i) {
304+ if (NULL != pLongTermRefList[i] && pLongTermRefList[i]->bUsedAsRef && pLongTermRefList[i]->bIsLongRef
305+ && pLongTermRefList[i]->bIsSceneLTR) {
306+ ++iActualLtrcount;
307+ }
308+ }
309+ if (iActualLtrcount == pSvcParam->iLTRRefNum && bSceneChangeFlag) {
310+ iFrameType = videoFrameTypeIDR;
311+ } else {
312+ iFrameType = videoFrameTypeP;
313+ pEncCtx->bCurFrameMarkedAsSceneLtr = true;
314+ }
315+ } else {
316+ iFrameType = videoFrameTypeP;
317+ }
318+ if (videoFrameTypeIDR == iFrameType) {
319+ pEncCtx->iCodingIndex = 0;
320+ pEncCtx->bCurFrameMarkedAsSceneLtr = true;
321+ }
293322 } else {
294− bSceneChangeFlag = pEncCtx->pVaa->bSceneChangeFlag;
295− }
323+ // perform scene change detection
324+ if ((!pSvcParam->bEnableSceneChangeDetect) || pEncCtx->pVaa->bIdrPeriodFlag ||
325+ (kiSpatialNum < pSvcParam->iSpatialLayerNum)
326+ || (pEncCtx->iFrameIndex < (VGOP_SIZE << 1))) { // avoid too frequent I frame coding, rc control
327+ bSceneChangeFlag = false;
328+ } else {
329+ bSceneChangeFlag = pEncCtx->pVaa->bSceneChangeFlag;
330+ }
296331
297− //scene_changed_flag: RC enable && iSpatialNum == pSvcParam->iSpatialLayerNum
298− //bIdrPeriodFlag: RC disable || iSpatialNum != pSvcParam->iSpatialLayerNum
299− //pEncCtx->bEncCurFrmAsIdrFlag: 1. first frame should be IDR; 2. idr pause; 3. idr request
300− iFrameType = (pEncCtx->pVaa->bIdrPeriodFlag || bSceneChangeFlag
301− || pEncCtx->bEncCurFrmAsIdrFlag) ? videoFrameTypeIDR : videoFrameTypeP;
302−
303− if (videoFrameTypeP == iFrameType && pEncCtx->iSkipFrameFlag > 0) { // for frame skip, 1/5/2010
304− -- pEncCtx->iSkipFrameFlag;
305− iFrameType = videoFrameTypeSkip;
306− } else if (videoFrameTypeIDR == iFrameType) {
307− pEncCtx->iCodingIndex = 0;
332+ //scene_changed_flag: RC enable && iSpatialNum == pSvcParam->iSpatialLayerNum
333+ //bIdrPeriodFlag: RC disable || iSpatialNum != pSvcParam->iSpatialLayerNum
334+ //pEncCtx->bEncCurFrmAsIdrFlag: 1. first frame should be IDR; 2. idr pause; 3. idr request
335+ iFrameType = (pEncCtx->pVaa->bIdrPeriodFlag || bSceneChangeFlag
336+ || pEncCtx->bEncCurFrmAsIdrFlag) ? videoFrameTypeIDR : videoFrameTypeP;
337+
338+ if (videoFrameTypeP == iFrameType && pEncCtx->iSkipFrameFlag > 0) { // for frame skip, 1/5/2010
339+ -- pEncCtx->iSkipFrameFlag;
340+ iFrameType = videoFrameTypeSkip;
341+ } else if (videoFrameTypeIDR == iFrameType) {
342+ pEncCtx->iCodingIndex = 0;
343+ }
308344 }
309−
310345 return iFrameType;
311346 }
312347

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t