ref: 7e8cde055fc2bfb50f088ff6c4208564fcb263ba
parent: cef43e30fe3bb83ca72bdf431ac5fa7efa356dc2
author: ruil2 <[email protected]>
date: Wed Sep 3 09:28:14 EDT 2014
add UT for LTR setopton and fix crash issue
--- a/codec/encoder/core/inc/extern.h
+++ b/codec/encoder/core/inc/extern.h
@@ -108,7 +108,7 @@
int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNew);
void WelsEncoderApplyFrameRate (SWelsSvcCodingParam* pParam);
void WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int32_t iLayer);
-void WelsEncoderApplyLTR (SLogContext* pLogCtx, sWelsEncCtx*pCtx,SLTRConfig* pLTRValue);
+void WelsEncoderApplyLTR (SLogContext* pLogCtx, sWelsEncCtx** ppCtx, SLTRConfig* pLTRValue);
int32_t FilterLTRRecoveryRequest (sWelsEncCtx* pCtx, SLTRRecoverRequest* pLTRRecoverRequest);
void FilterLTRMarkingFeedback (sWelsEncCtx* pCtx, SLTRMarkingFeedback* pLTRMarkingFeedback);
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -3825,10 +3825,10 @@
return 0;
}
-void WelsEncoderApplyLTR (SLogContext* pLogCtx, sWelsEncCtx* pCtx, SLTRConfig* pLTRValue) {
+void WelsEncoderApplyLTR (SLogContext* pLogCtx, sWelsEncCtx** ppCtx, SLTRConfig* pLTRValue) {
SWelsSvcCodingParam sConfig;
int32_t iNumRefFrame = 1;
- memcpy (&sConfig, pCtx->pSvcParam, sizeof (SWelsSvcCodingParam));
+ memcpy (&sConfig, (*ppCtx)->pSvcParam, sizeof (SWelsSvcCodingParam));
sConfig.bEnableLongTermReference = pLTRValue->bEnableLongTermReference;
sConfig.iLTRRefNum = pLTRValue->iLTRRefNum;
int32_t uiGopSize = 1 << (sConfig.iTemporalLayerNum - 1);
@@ -3856,9 +3856,9 @@
if (sConfig.iNumRefFrame > sConfig.iMaxNumRefFrame)
sConfig.iMaxNumRefFrame = sConfig.iNumRefFrame;
- WelsLog (pLogCtx, WELS_LOG_WARNING, " CWelsH264SVCEncoder::SetOption enable LTR = %d,ltrnum = %d",
+ WelsLog (pLogCtx, WELS_LOG_INFO, " CWelsH264SVCEncoder::SetOption enable LTR = %d,ltrnum = %d",
sConfig.bEnableLongTermReference, sConfig.iLTRRefNum);
- WelsEncoderParamAdjust (&pCtx, &sConfig);
+ WelsEncoderParamAdjust (ppCtx, &sConfig);
}
int32_t DynSliceRealloc (sWelsEncCtx* pCtx,
SFrameBSInfo* pFrameBsInfo,
--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -343,7 +343,7 @@
m_iMaxPicWidth = pCfg->iPicWidth;
m_iMaxPicHeight = pCfg->iPicHeight;
- TraceParamInfo(pCfg);
+ TraceParamInfo (pCfg);
if (WelsInitEncoderExt (&m_pEncContext, pCfg, &m_pWelsTrace->m_sLogCtx)) {
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), WelsInitEncoderExt failed.");
Uninitialize();
@@ -525,57 +525,57 @@
"doesn't support the number of reference frame(%d) change to auto select mode", iNumRef);
}
}
-void CWelsH264SVCEncoder::TraceParamInfo(SEncParamExt *pParam){
- WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
- "iUsageType = %d,iPicWidth= %d;iPicHeight= %d;iTargetBitrate= %d;iMaxBitrate= %d;iRCMode= %d;iPaddingFlag= %d;iTemporalLayerNum= %d;iSpatialLayerNum= %d;fFrameRate= %.6ff;uiIntraPeriod= %d;\
+void CWelsH264SVCEncoder::TraceParamInfo (SEncParamExt* pParam) {
+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
+ "iUsageType = %d,iPicWidth= %d;iPicHeight= %d;iTargetBitrate= %d;iMaxBitrate= %d;iRCMode= %d;iPaddingFlag= %d;iTemporalLayerNum= %d;iSpatialLayerNum= %d;fFrameRate= %.6ff;uiIntraPeriod= %d;\
bEnableSpsPpsIdAddition = %d;bPrefixNalAddingCtrl = %d;bEnableDenoise= %d;bEnableBackgroundDetection= %d;bEnableAdaptiveQuant= %d;bEnableFrameSkip= %d;bEnableLongTermReference= %d;iLtrMarkPeriod= %d;\
iComplexityMode = %d;iNumRefFrame = %d;iEntropyCodingModeFlag = %d;uiMaxNalSize = %d;iLTRRefNum = %d;iMultipleThreadIdc = %d;iLoopFilterDisableIdc = %d",
- pParam->iUsageType,
- pParam->iPicWidth,
- pParam->iPicHeight,
- pParam->iTargetBitrate,
- pParam->iMaxBitrate,
- pParam->iRCMode,
- pParam->iPaddingFlag,
- pParam->iTemporalLayerNum,
- pParam->iSpatialLayerNum,
- pParam->fMaxFrameRate,
- pParam->uiIntraPeriod,
- pParam->bEnableSpsPpsIdAddition,
- pParam->bPrefixNalAddingCtrl,
- pParam->bEnableDenoise,
- pParam->bEnableBackgroundDetection,
- pParam->bEnableAdaptiveQuant,
- pParam->bEnableFrameSkip,
- pParam->bEnableLongTermReference,
- pParam->iLtrMarkPeriod,
- pParam->iComplexityMode,
- pParam->iNumRefFrame,
- pParam->iEntropyCodingModeFlag,
- pParam->uiMaxNalSize,
- pParam->iLTRRefNum,
- pParam->iMultipleThreadIdc,
- pParam->iLoopFilterDisableIdc
- );
- int32_t i = 0;
- while (i < pParam->iSpatialLayerNum) {
- SSpatialLayerConfig* pSpatialCfg = &pParam->sSpatialLayers[i];
- WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
- "sSpatialLayers[%d]: .iVideoWidth= %d; .iVideoHeight= %d; .fFrameRate= %.6ff; .iSpatialBitrate= %d; .iMaxSpatialBitrate= %d; .sSliceCfg.uiSliceMode= %d; .sSliceCfg.sSliceArgument.iSliceNum= %d; .sSliceCfg.sSliceArgument.uiSliceSizeConstraint= %d;\
+ pParam->iUsageType,
+ pParam->iPicWidth,
+ pParam->iPicHeight,
+ pParam->iTargetBitrate,
+ pParam->iMaxBitrate,
+ pParam->iRCMode,
+ pParam->iPaddingFlag,
+ pParam->iTemporalLayerNum,
+ pParam->iSpatialLayerNum,
+ pParam->fMaxFrameRate,
+ pParam->uiIntraPeriod,
+ pParam->bEnableSpsPpsIdAddition,
+ pParam->bPrefixNalAddingCtrl,
+ pParam->bEnableDenoise,
+ pParam->bEnableBackgroundDetection,
+ pParam->bEnableAdaptiveQuant,
+ pParam->bEnableFrameSkip,
+ pParam->bEnableLongTermReference,
+ pParam->iLtrMarkPeriod,
+ pParam->iComplexityMode,
+ pParam->iNumRefFrame,
+ pParam->iEntropyCodingModeFlag,
+ pParam->uiMaxNalSize,
+ pParam->iLTRRefNum,
+ pParam->iMultipleThreadIdc,
+ pParam->iLoopFilterDisableIdc
+ );
+ int32_t i = 0;
+ while (i < pParam->iSpatialLayerNum) {
+ SSpatialLayerConfig* pSpatialCfg = &pParam->sSpatialLayers[i];
+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
+ "sSpatialLayers[%d]: .iVideoWidth= %d; .iVideoHeight= %d; .fFrameRate= %.6ff; .iSpatialBitrate= %d; .iMaxSpatialBitrate= %d; .sSliceCfg.uiSliceMode= %d; .sSliceCfg.sSliceArgument.iSliceNum= %d; .sSliceCfg.sSliceArgument.uiSliceSizeConstraint= %d;\
uiProfileIdc = %d;uiLevelIdc = %d",
- i, pSpatialCfg->iVideoWidth,
- pSpatialCfg->iVideoHeight,
- pSpatialCfg->fFrameRate,
- pSpatialCfg->iSpatialBitrate,
- pSpatialCfg->iMaxSpatialBitrate,
- pSpatialCfg->sSliceCfg.uiSliceMode,
- pSpatialCfg->sSliceCfg.sSliceArgument.uiSliceNum,
- pSpatialCfg->sSliceCfg.sSliceArgument.uiSliceSizeConstraint,
- pSpatialCfg->uiProfileIdc,
- pSpatialCfg->uiLevelIdc
- );
- ++ i;
- }
+ i, pSpatialCfg->iVideoWidth,
+ pSpatialCfg->iVideoHeight,
+ pSpatialCfg->fFrameRate,
+ pSpatialCfg->iSpatialBitrate,
+ pSpatialCfg->iMaxSpatialBitrate,
+ pSpatialCfg->sSliceCfg.uiSliceMode,
+ pSpatialCfg->sSliceCfg.sSliceArgument.uiSliceNum,
+ pSpatialCfg->sSliceCfg.sSliceArgument.uiSliceSizeConstraint,
+ pSpatialCfg->uiProfileIdc,
+ pSpatialCfg->uiLevelIdc
+ );
+ ++ i;
+ }
}
/************************************************************************
* InDataFormat, IDRInterval, SVC Encode Param, Frame Rate, Bitrate,..
@@ -642,7 +642,7 @@
int32_t iTargetHeight = 0;
memcpy (&sEncodingParam, pOption, sizeof (SEncParamExt)); // confirmed_safe_unsafe_usage
- TraceParamInfo(&sEncodingParam);
+ TraceParamInfo (&sEncodingParam);
#ifdef OUTPUT_BIT_STREAM
if (sEncodingParam.sSpatialLayers[sEncodingParam.iSpatialLayerNum - 1].iVideoWidth !=
m_pEncContext->pSvcParam->sDependencyLayers[m_pEncContext->pSvcParam->iSpatialLayerNum - 1].iActualWidth) {
@@ -808,7 +808,7 @@
break;
case ENCODER_OPTION_LTR: {
SLTRConfig* pLTRValue = ((SLTRConfig*) (pOption));
- WelsEncoderApplyLTR (&m_pWelsTrace->m_sLogCtx, m_pEncContext, pLTRValue);
+ WelsEncoderApplyLTR (&m_pWelsTrace->m_sLogCtx, &m_pEncContext, pLTRValue);
}
break;
case ENCODER_OPTION_ENABLE_SSEI: {
--- a/test/encoder/EncUT_InterfaceTest.cpp
+++ b/test/encoder/EncUT_InterfaceTest.cpp
@@ -1,6 +1,8 @@
#include <gtest/gtest.h>
#include "codec_def.h"
#include "codec_api.h"
+#include "utils/BufferedData.h"
+#include "utils/FileInputStream.h"
#include "BaseEncoderTest.h"
class EncInterfaceCallTest : public ::testing::Test, public BaseEncoderTest {
@@ -12,6 +14,9 @@
BaseEncoderTest::TearDown();
};
+ virtual void onEncodeFrame (const SFrameBSInfo& frameInfo) {
+ //nothing
+ }
//testing case
};
@@ -34,3 +39,67 @@
uiTraceLevel = WELS_LOG_ERROR;
encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &uiTraceLevel);
}
+
+void outputData() {
+
+}
+
+TEST_F (EncInterfaceCallTest, SetOptionLTR) {
+
+ int iTotalFrameNum = 100;
+ int iFrameNum = 0;
+ int frameSize = 0;
+ int ret = cmResultSuccess;
+ int width = 320;
+ int height = 192;
+
+
+ SEncParamBase baseparam;
+ memset (&baseparam, 0, sizeof (SEncParamBase));
+
+ baseparam.iUsageType = CAMERA_VIDEO_REAL_TIME;
+ baseparam.fMaxFrameRate = 12;
+ baseparam.iPicWidth = width;
+ baseparam.iPicHeight = height;
+ baseparam.iTargetBitrate = 5000000;
+ encoder_->Initialize (&baseparam);
+
+ frameSize = width * height * 3 / 2;
+
+ BufferedData buf;
+ buf.SetLength (frameSize);
+ ASSERT_TRUE (buf.Length() == (size_t)frameSize);
+
+ SFrameBSInfo info;
+ memset (&info, 0, sizeof (SFrameBSInfo));
+
+ SSourcePicture pic;
+ memset (&pic, 0, sizeof (SSourcePicture));
+ pic.iPicWidth = width;
+ pic.iPicHeight = height;
+ pic.iColorFormat = videoFormatI420;
+ pic.iStride[0] = pic.iPicWidth;
+ pic.iStride[1] = pic.iStride[2] = pic.iPicWidth >> 1;
+ pic.pData[0] = buf.data();
+ pic.pData[1] = pic.pData[0] + width * height;
+ pic.pData[2] = pic.pData[1] + (width * height >> 2);
+
+ SLTRConfig config;
+ config.bEnableLongTermReference = true;
+ config.iLTRRefNum = rand() % 4;
+ encoder_->SetOption (ENCODER_OPTION_LTR, &config);
+ do {
+ FileInputStream fileStream;
+ ASSERT_TRUE (fileStream.Open ("res/CiscoVT2people_320x192_12fps.yuv"));
+
+ while (fileStream.read (buf.data(), frameSize) == frameSize) {
+ ret = encoder_->EncodeFrame (&pic, &info);
+ ASSERT_TRUE (ret == cmResultSuccess);
+ if (info.eFrameType != videoFrameTypeSkip && this != NULL) {
+ this->onEncodeFrame (info);
+ iFrameNum++;
+ }
+ }
+ } while (iFrameNum < iTotalFrameNum);
+
+}
\ No newline at end of file