add nalsize checking UT and fix nalsize control when cabac on

This commit is contained in:
Karina 2016-06-03 13:34:59 +08:00
parent 1fa02f6b07
commit 2171d84f1e
7 changed files with 4724 additions and 4618 deletions

View File

@ -71,7 +71,7 @@ namespace WelsEnc {
#define JUMPPACKETSIZE_CONSTRAINT(max_byte) ( max_byte - AVER_MARGIN_BYTES ) //in bytes
#define JUMPPACKETSIZE_JUDGE(len,mb_idx,max_byte) ( (len) > JUMPPACKETSIZE_CONSTRAINT(max_byte) ) //( (mb_idx+1)%40/*16slice for compare*/ == 0 ) //
//cur_mb_idx is for early tests, can be omit in optimization
#define RESERVED_SLICE_HEADER_SIZE (10) //in bytes
typedef struct TagSlice SSlice;
typedef struct TagDqLayer SDqLayer;
typedef struct TagWelsEncCtx sWelsEncCtx;

View File

@ -588,7 +588,7 @@ int32_t ParamValidationExt (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingPa
case SM_SIZELIMITED_SLICE: {
iMbWidth = (kiPicWidth + 15) >> 4;
iMbHeight = (kiPicHeight + 15) >> 4;
if (pSpatialLayer->sSliceArgument.uiSliceSizeConstraint <= 0) {
if (pSpatialLayer->sSliceArgument.uiSliceSizeConstraint <= MAX_MACROBLOCK_SIZE_IN_BYTE) {
WelsLog (pLogCtx, WELS_LOG_ERROR, "ParamValidationExt(), invalid iSliceSize (%d) settings!",
pSpatialLayer->sSliceArgument.uiSliceSizeConstraint);
return ENC_RETURN_UNSUPPORTED_PARA;
@ -610,6 +610,7 @@ int32_t ParamValidationExt (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingPa
pSpatialLayer->sSliceArgument.uiSliceSizeConstraint = pCodingParam->uiMaxNalSize - NAL_HEADER_ADD_0X30BYTES;
}
}
pSpatialLayer->sSliceArgument.uiSliceSizeConstraint -= RESERVED_SLICE_HEADER_SIZE;
}
break;
default: {

View File

@ -600,10 +600,11 @@ int32_t WelsISliceMdEncDynamic (sWelsEncCtx* pEncCtx, SSlice* pSlice) { //pMd +
SWelsMD sMd;
SDynamicSlicingStack sDss;
sDss.iStartPos = BsGetBitsPos (pBs);
if (pEncCtx->pSvcParam->iEntropyCodingModeFlag) {
WelsInitSliceCabac (pEncCtx, pSlice);
}
sDss.iStartPos = 0;
}else
sDss.iStartPos = BsGetBitsPos (pBs);
for (; ;) {
iCurMbIdx = iNextMbIdx;
pCurMb = &pMbList[ iCurMbIdx ];
@ -1196,10 +1197,12 @@ int32_t WelsMdInterMbLoopOverDynamicSlice (sWelsEncCtx* pEncCtx, SSlice* pSlice,
int32_t iEncReturn = ENC_RETURN_SUCCESS;
SDynamicSlicingStack sDss;
sDss.iStartPos = BsGetBitsPos (pBs);
if (pEncCtx->pSvcParam->iEntropyCodingModeFlag) {
WelsInitSliceCabac (pEncCtx, pSlice);
}
sDss.iStartPos = 0;
}else
sDss.iStartPos = BsGetBitsPos (pBs);
pSlice->iMbSkipRun = 0;
for (;;) {
//DYNAMIC_SLICING_ONE_THREAD - MultiD

View File

@ -127,7 +127,7 @@ static const EncodeFileParam kFileParamArray[] = {
},
{
"res/Cisco_Absolute_Power_1280x720_30fps.yuv",
"84f97cff898055aaf96a303960abb76e12bf24c1", CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, false
"d60627dde96d2e5fb4547e937f1224a3e21698c9", CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, false
},
{
"res/Cisco_Absolute_Power_1280x720_30fps.yuv",
@ -148,12 +148,12 @@ static const EncodeFileParam kFileParamArray[] = {
},
{
"res/Cisco_Absolute_Power_1280x720_30fps.yuv",
"8027935ed347671cb2a181d09cd4380ce2c0da79", SCREEN_CONTENT_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, false
"e85b359a629da713e08895b1d10b016ae1a979a0", SCREEN_CONTENT_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, false
},
//for different strategy
{
"res/Cisco_Absolute_Power_1280x720_30fps.yuv",
"0e1af98bd978e602cc15329ba70a2c4c2afe8016", SCREEN_CONTENT_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, true, true, false
"0178f86f16cb8f23ef70566353dd2e935e469f71", SCREEN_CONTENT_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, true, true, false
},
{
"res/CiscoVT2people_320x192_12fps.yuv",
@ -161,7 +161,7 @@ static const EncodeFileParam kFileParamArray[] = {
},
{
"res/Cisco_Absolute_Power_1280x720_30fps.yuv",
"8942c8811fd0cb086d709734bf9fd5b184772f5e", CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, true
"ef0387ac53e264f5f081afd5ad16baea8c11649a", CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, true
},
{
"res/Cisco_Absolute_Power_1280x720_30fps.yuv",

View File

@ -4,6 +4,7 @@
#include "codec_app_def.h"
#include "svc_enc_slice_segment.h"
#include "test_stdint.h"
#include "utils/FileInputStream.h"
//TODO: consider using BaseEncoderTest class from #include "../BaseEncoderTest.h"
class EncoderInterfaceTest : public ::testing::Test {
@ -1054,3 +1055,104 @@ TEST_F (EncoderInterfaceTest, DiffResolutionCheck) {
// finish
pPtrEnc->Uninitialize();
}
TEST_F (EncoderInterfaceTest, NalSizeChecking) {
// int uiTraceLevel = WELS_LOG_DETAIL;
// pPtrEnc->SetOption (ENCODER_OPTION_TRACE_LEVEL, &uiTraceLevel);
pParamExt->iPicWidth = 1280;
pParamExt->iPicHeight = 720;
pParamExt->iPicWidth += (rand() << 1) % IMAGE_VARY_SIZE;
pParamExt->iPicHeight += (rand() << 1) % IMAGE_VARY_SIZE;
pParamExt->fMaxFrameRate = 30;
pParamExt->iTemporalLayerNum = rand()%3;
pParamExt->iSpatialLayerNum = rand()%4;
pParamExt->iNumRefFrame = AUTO_REF_PIC_COUNT;
pParamExt->iSpatialLayerNum = WELS_CLIP3(pParamExt->iSpatialLayerNum,1,4);
pParamExt->iMultipleThreadIdc = 1;//multi-thread can't control size. will be fixed.
pParamExt->iEntropyCodingModeFlag = rand()%2;
int iMaxNalSize =rand()%5000;
iMaxNalSize = WELS_CLIP3(iMaxNalSize,1000,5000);
pParamExt->uiMaxNalSize = iMaxNalSize;
for(int i = 0;i<pParamExt->iSpatialLayerNum;i++){
pParamExt->sSpatialLayers[i].sSliceArgument.uiSliceMode = SM_SIZELIMITED_SLICE;
pParamExt->sSpatialLayers[i].sSliceArgument.uiSliceSizeConstraint = iMaxNalSize;
pParamExt->sSpatialLayers[i].iVideoHeight = pParamExt->iPicHeight;
pParamExt->sSpatialLayers[i].iVideoWidth = pParamExt->iPicWidth;
int bitrate = rand()%3000000;
pParamExt->sSpatialLayers[i].iSpatialBitrate = WELS_CLIP3(bitrate,500000,3000000) ;
pParamExt->iTargetBitrate+= pParamExt->sSpatialLayers[i].iSpatialBitrate;
pParamExt->sSpatialLayers[i].fFrameRate = 30;
}
int iResult = pPtrEnc->InitializeExt (pParamExt);
const int kiFrameNumber = TEST_FRAMES;
m_iWidth = pParamExt->iPicWidth;
m_iHeight = pParamExt->iPicHeight;
m_iPicResSize = m_iWidth * m_iHeight * 3 >> 1;
delete []pYUV;
pYUV = new unsigned char [m_iPicResSize];
FileInputStream fileStream;
ASSERT_TRUE (fileStream.Open ("res/Cisco_Absolute_Power_1280x720_30fps.yuv"));
PrepareOneSrcFrame();
for (int i = 0; i < kiFrameNumber; i ++) {
if(fileStream.read (pYUV, m_iPicResSize) != m_iPicResSize){
int iStartX = rand() % (m_iPicResSize >> 1);
int iEndX = (iStartX + (rand() % MEM_VARY_SIZE)) % m_iPicResSize;
for (int j = iStartX; j < iEndX; j++)
pYUV[j] = rand() % 256;
}
iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
pSrcPic->uiTimeStamp += 30;
for (int i = 0; i < sFbi.iLayerNum; ++i) {
for (int j = 0; j < sFbi.sLayerInfo[i].iNalCount; ++j) {
int length = sFbi.sLayerInfo[i].pNalLengthInByte[j];
EXPECT_LE (length, iMaxNalSize);
}
}
}
pParamExt->iPicWidth = 1280;
pParamExt->iPicHeight = 720;
pParamExt->iPicWidth += (rand() << 1) % IMAGE_VARY_SIZE;
pParamExt->iPicHeight += (rand() << 1) % IMAGE_VARY_SIZE;
m_iWidth = pParamExt->iPicWidth;
m_iHeight = pParamExt->iPicHeight;
m_iPicResSize = m_iWidth * m_iHeight * 3 >> 1;
delete []pYUV;
pYUV = new unsigned char [m_iPicResSize];
iResult = pPtrEnc->InitializeExt (pParamExt);
PrepareOneSrcFrame();
ENCODER_OPTION eOptionId = ENCODER_OPTION_SVC_ENCODE_PARAM_EXT;
memcpy (pOption, pParamExt, sizeof (SEncParamExt));
pOption ->iPicWidth = m_iWidth;
pOption ->iPicHeight = m_iHeight;
iResult = pPtrEnc->SetOption (eOptionId, pOption);
EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
for (int i = 0; i < kiFrameNumber; i ++) {
int iStartX = rand() % (m_iPicResSize >> 1);
int iEndX = (iStartX + (rand() % MEM_VARY_SIZE)) % m_iPicResSize;
for (int j = iStartX; j < iEndX; j++)
pYUV[j] = rand() % 256;
iResult = pPtrEnc->EncodeFrame (pSrcPic, &sFbi);
EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
pSrcPic->uiTimeStamp += 30;
for (int i = 0; i < sFbi.iLayerNum; ++i) {
for (int j = 0; j < sFbi.sLayerInfo[i].iNalCount; ++j) {
int length = sFbi.sLayerInfo[i].pNalLengthInByte[j];
EXPECT_LE (length, iMaxNalSize);
}
}
}
iResult = pPtrEnc->Uninitialize();
EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
}