ref: f5fd7420a9bd1ae723c7aec8e6408e188dd8265b
parent: fb901269effd746c8a2318b1393a581e18f142ae
parent: 3873addc3d9f701972955ed6283d1b2cddd6c635
author: sijchen <sijchen@cisco.com>
date: Tue Feb 2 11:31:05 EST 2016
Merge pull request #2351 from huili2/fix_width_height_enc_constraint fix frame size constraints for width and height
--- a/codec/common/inc/utils.h
+++ b/codec/common/inc/utils.h
@@ -43,8 +43,7 @@
#include "typedefs.h"
#define MAX_LOG_SIZE 1024
-#define MAX_WIDTH (4096)
-#define MAX_HEIGHT (2304)//MAX_FS_LEVEL51 (36864); MAX_FS_LEVEL51*256/4096 = 2304
+#define MAX_MBS_PER_FRAME 36864 //in accordance with max level support in Rec
/*
* Function pointer declaration for various tool sets
*/
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -485,10 +485,10 @@
int32_t iMbNumInFrame = 0;
uint32_t iMaxSliceNum = MAX_SLICES_NUM;
int32_t iReturn = 0;
- if ((kiPicWidth <= 0) || (kiPicHeight <= 0) || (kiPicWidth > MAX_WIDTH) || (kiPicHeight > MAX_HEIGHT)) {
+ if ((kiPicWidth <= 0) || (kiPicHeight <= 0) || (kiPicWidth * kiPicHeight > (MAX_MBS_PER_FRAME << 8))) {
WelsLog (pLogCtx, WELS_LOG_ERROR,
- "ParamValidationExt(),width(1-%d),height(1-%d)invalid %d x %d in dependency layer settings!", MAX_WIDTH, MAX_HEIGHT,
- kiPicWidth, kiPicHeight);
+ "ParamValidationExt(), width > 0, height > 0, width * height <= %d, invalid %d x %d in dependency layer settings!",
+ (MAX_MBS_PER_FRAME << 8), kiPicWidth, kiPicHeight);
return ENC_RETURN_UNSUPPORTED_PARA;
}
if ((kiPicWidth & 0x0F) != 0 || (kiPicHeight & 0x0F) != 0) {
--- a/codec/encoder/core/src/wels_preprocess.cpp
+++ b/codec/encoder/core/src/wels_preprocess.cpp
@@ -1346,13 +1346,13 @@
const int32_t kiDstStrideUV = pDstPic->iLineSize[1];
if (pSrcY) {
- if (iSrcWidth <= 0 || iSrcWidth > MAX_WIDTH || iSrcHeight <= 0 || iSrcHeight > MAX_HEIGHT)
+ if (iSrcWidth <= 0 || iSrcHeight <= 0 || (iSrcWidth * iSrcHeight > (MAX_MBS_PER_FRAME << 8)))
return;
if (kiSrcTopOffsetY >= iSrcHeight || kiSrcLeftOffsetY >= iSrcWidth || iSrcWidth > kiSrcStrideY)
return;
}
if (pDstY) {
- if (kiTargetWidth <= 0 || kiTargetWidth > MAX_WIDTH || kiTargetHeight <= 0 || kiTargetHeight > MAX_HEIGHT)
+ if (kiTargetWidth <= 0 || kiTargetHeight <= 0 || (kiTargetWidth * kiTargetHeight > (MAX_MBS_PER_FRAME << 8)))
return;
if (kiTargetWidth > kiDstStrideY)
return;
--- a/codec/processing/src/common/WelsFrameWork.cpp
+++ b/codec/processing/src/common/WelsFrameWork.cpp
@@ -233,8 +233,8 @@
}
if (pSrcPixMap.pPixel[0]) {
- if (pSrcPixMap.sRect.iRectWidth <= 0 || pSrcPixMap.sRect.iRectWidth > MAX_WIDTH || pSrcPixMap.sRect.iRectHeight <= 0
- || pSrcPixMap.sRect.iRectHeight > MAX_HEIGHT)
+ if (pSrcPixMap.sRect.iRectWidth <= 0 || pSrcPixMap.sRect.iRectHeight <= 0
+ || pSrcPixMap.sRect.iRectWidth * pSrcPixMap.sRect.iRectHeight > (MAX_MBS_PER_FRAME << 8))
goto exit;
if (pSrcPixMap.sRect.iRectTop >= pSrcPixMap.sRect.iRectHeight
|| pSrcPixMap.sRect.iRectLeft >= pSrcPixMap.sRect.iRectWidth || pSrcPixMap.sRect.iRectWidth > pSrcPixMap.iStride[0])
@@ -241,8 +241,8 @@
goto exit;
}
if (pDstPixMap.pPixel[0]) {
- if (pDstPixMap.sRect.iRectWidth <= 0 || pDstPixMap.sRect.iRectWidth > MAX_WIDTH || pDstPixMap.sRect.iRectHeight <= 0
- || pDstPixMap.sRect.iRectHeight > MAX_HEIGHT)
+ if (pDstPixMap.sRect.iRectWidth <= 0 || pDstPixMap.sRect.iRectHeight <= 0
+ || pDstPixMap.sRect.iRectWidth * pDstPixMap.sRect.iRectHeight > (MAX_MBS_PER_FRAME << 8))
goto exit;
if (pDstPixMap.sRect.iRectTop >= pDstPixMap.sRect.iRectHeight
|| pDstPixMap.sRect.iRectLeft >= pDstPixMap.sRect.iRectWidth || pDstPixMap.sRect.iRectWidth > pDstPixMap.iStride[0])
--- a/codec/processing/src/common/util.h
+++ b/codec/processing/src/common/util.h
@@ -54,8 +54,7 @@
WELSVP_NAMESPACE_BEGIN
-#define MAX_WIDTH (4096)
-#define MAX_HEIGHT (2304)//MAX_FS_LEVEL51 (36864); MAX_FS_LEVEL51*256/4096 = 2304
+#define MAX_MBS_PER_FRAME 36864 //in accordance with max level support in Rec
#define MB_WIDTH_LUMA (16)
#define PESN (1e-6) // desired float precision
--- a/test/encoder/EncUT_EncoderExt.cpp
+++ b/test/encoder/EncUT_EncoderExt.cpp
@@ -573,11 +573,28 @@
iResult = pPtrEnc->Initialize (&sEncParamBase);
EXPECT_EQ (iResult, static_cast<int> (cmInitParaError));
- //TODO: add checking max in interface and then enable this checking
- //GetValidEncParamBase(&sEncParamBase);
- //sEncParamBase.iPicWidth = rand()+(MAX_HEIGHT+1);
- //iResult = pPtrEnc->Initialize (&sEncParamBase);
- //EXPECT_EQ (iResult, static_cast<int> (cmInitParaError));
+ //iPicWidth * iPicHeight <= 36864 * 16 * 16, from Level 5.2 constraint
+ //Initialize test: FALSE
+ GetValidEncParamBase (&sEncParamBase);
+ sEncParamBase.iPicWidth = 5000;
+ sEncParamBase.iPicHeight = 5000;
+ iResult = pPtrEnc->Initialize (&sEncParamBase);
+ EXPECT_EQ (iResult, static_cast<int> (cmInitParaError));
+ //Initialize test: TRUE, with SetOption test following
+ GetValidEncParamBase (&sEncParamBase);
+ sEncParamBase.iPicWidth = 36864;
+ sEncParamBase.iPicHeight = 256;
+ iResult = pPtrEnc->Initialize (&sEncParamBase);
+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+ sEncParamBase.iPicWidth = 256;
+ sEncParamBase.iPicHeight = 36864;
+ iResult = pPtrEnc->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_BASE, &sEncParamBase);
+ EXPECT_EQ (iResult, static_cast<int> (cmResultSuccess));
+ sEncParamBase.iPicWidth = 5000;
+ sEncParamBase.iPicHeight = 5000;
+ iResult = pPtrEnc->SetOption (ENCODER_OPTION_SVC_ENCODE_PARAM_BASE, &sEncParamBase);
+ EXPECT_EQ (iResult, static_cast<int> (cmInitParaError));
+ pPtrEnc->Uninitialize();
//iTargetBitrate
GetValidEncParamBase (&sEncParamBase);