ref: c01ed5ba8e23d3fe6a701ff4ed90339758f846a8
parent: fea27cab7b93fa0f806ede551a5838f470ca1ed0
author: Karina <ruil2@cisco.com>
date: Thu Dec 1 05:58:00 EST 2016
make SetOption():ENCODER_OPTION_SVC_ENCODE_PARAM_BASE work correclty
--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -473,15 +473,15 @@
* Force key frame
*/
int CWelsH264SVCEncoder::ForceIntraFrame (bool bIDR, int iLayerId) {
- if ( bIDR ) {
+ if (bIDR) {
if (! (m_pEncContext && m_bInitialFlag)) {
return 1;
}
- ForceCodingIDR(m_pEncContext, iLayerId);
+ ForceCodingIDR (m_pEncContext, iLayerId);
} else {
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
- "CWelsH264SVCEncoder::ForceIntraFrame(),nothing to do as bIDR set to false");
+ "CWelsH264SVCEncoder::ForceIntraFrame(),nothing to do as bIDR set to false");
}
return 0;
@@ -741,6 +741,11 @@
m_iMaxPicWidth = iTargetWidth;
m_iMaxPicHeight = iTargetHeight;
}
+ if (sConfig.DetermineTemporalSettings()) {
+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
+ "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_SVC_ENCODE_PARAM_BASE, DetermineTemporalSettings failed!");
+ return cmInitParaError;
+ }
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
"CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_SVC_ENCODE_PARAM_BASE iUsageType = %d,iPicWidth= %d;iPicHeight= %d;iTargetBitrate= %d;fMaxFrameRate= %.6ff;iRCMode= %d",
sEncodingParam.iUsageType,
@@ -1278,7 +1283,8 @@
char strFileName[256] = {0};
const int32_t iDataLength = m_iMaxPicWidth * m_iMaxPicHeight;
- WelsSnprintf (strFileName, sizeof (strFileName), "pic_in_%dx%d.yuv", m_iMaxPicWidth, m_iMaxPicHeight);// confirmed_safe_unsafe_usage
+ WelsSnprintf (strFileName, sizeof (strFileName), "pic_in_%dx%d.yuv", m_iMaxPicWidth,
+ m_iMaxPicHeight);// confirmed_safe_unsafe_usage
switch (pSrcPic->iColorFormat) {
case videoFormatI420:
@@ -1287,8 +1293,8 @@
if (NULL != pFile) {
fwrite (pSrcPic->pData[0], sizeof (uint8_t), pSrcPic->iStride[0]*m_iMaxPicHeight, pFile);
- fwrite (pSrcPic->pData[1], sizeof (uint8_t), pSrcPic->iStride[1]*(m_iMaxPicHeight >> 1), pFile);
- fwrite (pSrcPic->pData[2], sizeof (uint8_t), pSrcPic->iStride[2]*(m_iMaxPicHeight >> 1), pFile);
+ fwrite (pSrcPic->pData[1], sizeof (uint8_t), pSrcPic->iStride[1] * (m_iMaxPicHeight >> 1), pFile);
+ fwrite (pSrcPic->pData[2], sizeof (uint8_t), pSrcPic->iStride[2] * (m_iMaxPicHeight >> 1), pFile);
fflush (pFile);
fclose (pFile);
} else {
--- a/test/api/encode_options_test.cpp
+++ b/test/api/encode_options_test.cpp
@@ -34,7 +34,6 @@
//set a fixed random value
iRandValue = rand() % 256;
}
-
void EncodeDecodeTestAPIBase::RandomParamExtCombination() {
param_.iPicWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 2, MAX_WIDTH);
@@ -320,6 +319,51 @@
//to do
// currently, there are still some error cases even though under condition cmResultSuccess == iResult
// so need to enhance the validation check for any random value of each variable in ParamExt
+
+ if (cmResultSuccess == iResult) {
+ InitialEncDec (param_.iPicWidth, param_.iPicHeight);
+ EncodeOneFrame (0);
+ encToDecData (info, len);
+ pData[0] = pData[1] = pData[2] = 0;
+ memset (&dstBufInfo_, 0, sizeof (SBufferInfo));
+
+ iResult = decoder_->DecodeFrame2 (info.sLayerInfo[0].pBsBuf, len, pData, &dstBufInfo_);
+ ASSERT_TRUE (iResult == cmResultSuccess);
+ iResult = decoder_->DecodeFrame2 (NULL, 0, pData, &dstBufInfo_);
+ ASSERT_TRUE (iResult == cmResultSuccess);
+ EXPECT_EQ (dstBufInfo_.iBufferStatus, 1);
+ }
+ }
+
+ iTraceLevel = WELS_LOG_ERROR;
+ encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
+}
+
+
+TEST_F (EncodeDecodeTestAPI, SetOptionEncParamBase) {
+ int iSpatialLayerNum = 4;
+ int iWidth = WelsClip3 ((((rand() % MAX_WIDTH) >> 1) + 1) << 1, 1 << iSpatialLayerNum, MAX_WIDTH);
+ int iHeight = WelsClip3 ((((rand() % MAX_HEIGHT) >> 1) + 1) << 1, 1 << iSpatialLayerNum, MAX_HEIGHT);
+ float fFrameRate = rand() + 0.5f;
+ int iEncFrameNum = WelsClip3 ((rand() % ENCODE_FRAME_NUM) + 1, 1, ENCODE_FRAME_NUM);
+ int iSliceNum = 1;
+ encoder_->GetDefaultParams (¶m_);
+ prepareParamDefault (iSpatialLayerNum, iSliceNum, iWidth, iHeight, fFrameRate, ¶m_);
+
+ int rv = encoder_->InitializeExt (¶m_);
+ ASSERT_TRUE (rv == cmResultSuccess);
+
+ int iTraceLevel = WELS_LOG_QUIET;
+ rv = encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
+ ASSERT_TRUE (rv == cmResultSuccess);
+
+ for (int i = 0; i < iEncFrameNum; i++) {
+ int iResult;
+ int len = 0;
+ unsigned char* pData[3] = { NULL };
+
+ param_.iTargetBitrate = rand() % BIT_RATE_RANGE;
+ iResult = encoder_->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_BASE, ¶m_);
if (cmResultSuccess == iResult) {
InitialEncDec (param_.iPicWidth, param_.iPicHeight);