Merge pull request #2491 from ruil2/nalsize
add nalsize checking UT and fix nalsize control when cabac on
This commit is contained in:
commit
d35647ec3b
@ -71,7 +71,6 @@ 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
|
||||
|
||||
typedef struct TagSlice SSlice;
|
||||
typedef struct TagDqLayer SDqLayer;
|
||||
typedef struct TagWelsEncCtx sWelsEncCtx;
|
||||
|
@ -132,7 +132,7 @@
|
||||
|
||||
#define INVALID_ID (-1)
|
||||
|
||||
#define NAL_HEADER_ADD_0X30BYTES 50
|
||||
#define NAL_HEADER_ADD_0X30BYTES 20
|
||||
|
||||
#define SLICE_NUM_EXPAND_COEF 2
|
||||
|
||||
|
@ -588,9 +588,9 @@ int32_t ParamValidationExt (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingPa
|
||||
case SM_SIZELIMITED_SLICE: {
|
||||
iMbWidth = (kiPicWidth + 15) >> 4;
|
||||
iMbHeight = (kiPicHeight + 15) >> 4;
|
||||
if (pSpatialLayer->sSliceArgument.uiSliceSizeConstraint <= 0) {
|
||||
WelsLog (pLogCtx, WELS_LOG_ERROR, "ParamValidationExt(), invalid iSliceSize (%d) settings!",
|
||||
pSpatialLayer->sSliceArgument.uiSliceSizeConstraint);
|
||||
if (pSpatialLayer->sSliceArgument.uiSliceSizeConstraint <= MAX_MACROBLOCK_SIZE_IN_BYTE) {
|
||||
WelsLog (pLogCtx, WELS_LOG_ERROR, "ParamValidationExt(), invalid iSliceSize (%d) settings!should be larger than MAX_MACROBLOCK_SIZE_IN_BYTE(%d)",
|
||||
pSpatialLayer->sSliceArgument.uiSliceSizeConstraint,MAX_MACROBLOCK_SIZE_IN_BYTE);
|
||||
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 -= NAL_HEADER_ADD_0X30BYTES;
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
|
@ -600,9 +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;
|
||||
@ -1196,9 +1198,11 @@ 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 (;;) {
|
||||
|
@ -134,7 +134,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
|
||||
"8bc8813ee262b356e53eec6dbdc3c88d7d2b7b5c", CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, false
|
||||
},
|
||||
{
|
||||
"res/Cisco_Absolute_Power_1280x720_30fps.yuv",
|
||||
@ -162,12 +162,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
|
||||
"9e35aac6ee12b4516fbee114bc532faae23df76d", 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
|
||||
"1a6dc4f84cada651c4c8b24f879c858e35c2e813", SCREEN_CONTENT_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, true, true, false
|
||||
},
|
||||
{
|
||||
"res/CiscoVT2people_320x192_12fps.yuv",
|
||||
@ -175,7 +175,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
|
||||
"f5a92b7a0c00691e04bf1306c8251a74f989e4e2", CAMERA_VIDEO_REAL_TIME, 1280, 720, 30.0f, SM_SIZELIMITED_SLICE, false, 1, false, false, true
|
||||
},
|
||||
{
|
||||
"res/Cisco_Absolute_Power_1280x720_30fps.yuv",
|
||||
|
@ -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,98 @@ 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;
|
||||
if(pYUV)
|
||||
delete []pYUV;
|
||||
pYUV = new unsigned char [m_iPicResSize];
|
||||
ASSERT_TRUE (pYUV != NULL);
|
||||
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){
|
||||
break;
|
||||
}
|
||||
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];
|
||||
ASSERT_TRUE (pYUV != NULL);
|
||||
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 ++) {
|
||||
PrepareOneSrcFrame();
|
||||
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));
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user