History

using independent encoder control logic for SAVC case

Karina committed 10 years ago

Commit 0f0d54e1 parent 7bfb96b13 files · +406 −314Browse files

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

Unified · Split

codec/encoder/core/src/encoder.cpp+66−55
@@ -211,7 +211,7 @@ int32_t InitFunctionPointers (sWelsEncCtx* pEncCtx, SWelsSvcCodingParam* pParam, · 210 unmodified lines
211211 /*init pixel average function*/
212212 /*get one column or row pixel when refinement*/
213213 InitMcFunc (&pFuncList->sMcFuncs, uiCpuFlag);
214− InitCoeffFunc (pFuncList,uiCpuFlag,pParam->iEntropyCodingModeFlag);
214+ InitCoeffFunc (pFuncList, uiCpuFlag, pParam->iEntropyCodingModeFlag);
215215
216216 WelsInitEncodingFuncs (pFuncList, uiCpuFlag);
217217 WelsInitReconstructionFuncs (pFuncList, uiCpuFlag);
@@ -226,87 +226,97 @@ int32_t InitFunctionPointers (sWelsEncCtx* pEncCtx, SWelsSvcCodingParam* pParam, · 8 unmodified lines
226226 return iReturn;
227227 }
228228
229−void UpdateFrameNum(sWelsEncCtx* pEncCtx) {
229+void UpdateFrameNum (sWelsEncCtx* pEncCtx, const int32_t kiDidx) {
230+ SSpatialLayerInternal* pParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[kiDidx];
230231 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;
235235 }
236+
236237 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;
239240 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
244242 }
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);
245247 }
246248
247249
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;
261263 }
264+ }
265+ WelsLog (& (pEncCtx->sLogCtx), WELS_LOG_INFO,
266+ "LoadBackFrameNum,bNeedFrameNumIncreasing = %d,iFrameNum = %d,kiDidx = %d", bNeedFrameNumIncreasing,
267+ pParamInternal->iFrameNum, kiDidx);
262268 }
263269
264−/*!
265− * \brief initialize frame coding
266− */
267−void InitFrameCoding (sWelsEncCtx* pEncCtx, const EVideoFrameType keFrameType) {
270+void InitBitStream (sWelsEncCtx* pEncCtx) {
268271 // for bitstream writing
269272 pEncCtx->iPosBsBuffer = 0; // reset bs pBuffer position
270273 pEncCtx->pOut->iNalIndex = 0; // reset NAL index
271274 pEncCtx->pOut->iLayerBsIndex = 0; // reset index of Layer Bs
272275
273276 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];
275283 if (keFrameType == videoFrameTypeP) {
276− ++pEncCtx->iFrameIndex;
284+ ++pParamInternal->iFrameIndex;
277285
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
280289 else
281− pEncCtx->iPOC = 0;
290+ pParamInternal->iPOC = 0;
282291
283− UpdateFrameNum(pEncCtx);
292+ UpdateFrameNum (pEncCtx, kiDidx);
284293
285294 pEncCtx->eNalType = NAL_UNIT_CODED_SLICE;
286295 pEncCtx->eSliceType = P_SLICE;
287296 pEncCtx->eNalPriority = NRI_PRI_HIGH;
288297 } 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;
293302
294303 pEncCtx->eNalType = NAL_UNIT_CODED_SLICE_IDR;
295304 pEncCtx->eSliceType = I_SLICE;
296305 pEncCtx->eNalPriority = NRI_PRI_HIGHEST;
297306
298− pEncCtx->iCodingIndex = 0;
307+ pParamInternal->iCodingIndex = 0;
299308
300309 // reset_ref_list
301310
302311 // rc_init_gop
303312 } 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
306316 else
307− pEncCtx->iPOC = 0;
317+ pParamInternal->iPOC = 0;
308318
309− UpdateFrameNum(pEncCtx);
319+ UpdateFrameNum (pEncCtx, kiDidx);
310320
311321 pEncCtx->eNalType = NAL_UNIT_CODED_SLICE;
312322 pEncCtx->eSliceType = I_SLICE;
@@ -322,11 +332,12 @@ void InitFrameCoding (sWelsEncCtx* pEncCtx, const EVideoFrameType keFrameType) { · 9 unmodified lines
322332 #endif//FRAME_INFO_OUTPUT
323333 }
324334
325−EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum) {
335+EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum, const int32_t kiDidx) {
326336 SWelsSvcCodingParam* pSvcParam = pEncCtx->pSvcParam;
337+ SSpatialLayerInternal* pParamInternal = &pEncCtx->pSvcParam->sDependencyLayers[kiDidx];
327338 EVideoFrameType iFrameType = videoFrameTypeInvalid;
328339 bool bSceneChangeFlag = false;
329−
340+ int32_t iSkipFrameFlag = pSvcParam->bSimulcastAVC?pParamInternal->iSkipFrameFlag:pEncCtx->iSkipFrameFlag;
330341 if (pSvcParam->iUsageType == SCREEN_CONTENT_REAL_TIME) {
331342 if ((!pSvcParam->bEnableSceneChangeDetect) || pEncCtx->pVaa->bIdrPeriodFlag ||
332343 (kiSpatialNum < pSvcParam->iSpatialLayerNum)) {
@@ -334,7 +345,7 @@ EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum · 1 unmodified line
334345 } else {
335346 bSceneChangeFlag = pEncCtx->pVaa->bSceneChangeFlag;
336347 }
337− if (pEncCtx->pVaa->bIdrPeriodFlag || pEncCtx->bEncCurFrmAsIdrFlag || (!pSvcParam->bEnableLongTermReference
348+ if (pEncCtx->pVaa->bIdrPeriodFlag || pParamInternal->bEncCurFrmAsIdrFlag || (!pSvcParam->bEnableLongTermReference
338349 && bSceneChangeFlag)) {
339350 iFrameType = videoFrameTypeIDR;
340351 } else if (pSvcParam->bEnableLongTermReference && (bSceneChangeFlag
@@ -356,11 +367,11 @@ EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum · 15 unmodified lines
356367 } else {
357368 iFrameType = videoFrameTypeP;
358369 }
359− if (videoFrameTypeP == iFrameType && pEncCtx->iSkipFrameFlag > 0) {
360− -- pEncCtx->iSkipFrameFlag;
370+ if (videoFrameTypeP == iFrameType && iSkipFrameFlag > 0) {
371+ pParamInternal->iSkipFrameFlag = 0;
361372 iFrameType = videoFrameTypeSkip;
362373 } else if (videoFrameTypeIDR == iFrameType) {
363− pEncCtx->iCodingIndex = 0;
374+ pParamInternal->iCodingIndex = 0;
364375 pEncCtx->bCurFrameMarkedAsSceneLtr = true;
365376 }
366377
@@ -368,7 +379,7 @@ EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum · 1 unmodified line
368379 // perform scene change detection
369380 if ((!pSvcParam->bEnableSceneChangeDetect) || pEncCtx->pVaa->bIdrPeriodFlag ||
370381 (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
372383 bSceneChangeFlag = false;
373384 } else {
374385 bSceneChangeFlag = pEncCtx->pVaa->bSceneChangeFlag;
@@ -378,13 +389,13 @@ EVideoFrameType DecideFrameType (sWelsEncCtx* pEncCtx, const int8_t kiSpatialNum · 3 unmodified lines
378389 //bIdrPeriodFlag: RC disable || iSpatialNum != pSvcParam->iSpatialLayerNum
379390 //pEncCtx->bEncCurFrmAsIdrFlag: 1. first frame should be IDR; 2. idr pause; 3. idr request
380391 iFrameType = (pEncCtx->pVaa->bIdrPeriodFlag || bSceneChangeFlag
381− || pEncCtx->bEncCurFrmAsIdrFlag) ? videoFrameTypeIDR : videoFrameTypeP;
392+ || pParamInternal->bEncCurFrmAsIdrFlag) ? videoFrameTypeIDR : videoFrameTypeP;
382393
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;
385396 iFrameType = videoFrameTypeSkip;
386397 } else if (videoFrameTypeIDR == iFrameType) {
387− pEncCtx->iCodingIndex = 0;
398+ pParamInternal->iCodingIndex = 0;
388399 }
389400 }
390401 return iFrameType;

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