shithub: openh264

Download patch

ref: 2211324e2b3aefbfbd9f27afb5017de6e11f6fe5
parent: fba745f04e224b8133aa483237f05243ab5e7318
author: Sijia Chen <sijchen@cisco.com>
date: Tue Feb 3 10:14:36 EST 2015

add a para check for max_nal_size

--- a/codec/encoder/core/inc/wels_const.h
+++ b/codec/encoder/core/inc/wels_const.h
@@ -106,8 +106,10 @@
 #endif//PPS_BUFFER_SIZE
 
 #if !defined(MAX_MACROBLOCK_SIZE_IN_BYTE)
-#define MAX_MACROBLOCK_SIZE_IN_BYTE		800 //3200*2/8
+#define MAX_MACROBLOCK_SIZE_IN_BYTE		400 //3200/8, 3200 is from Annex A.3.1.(n)
 #endif
+
+#define MAX_MACROBLOCK_SIZE_IN_BYTE_x2 (MAX_MACROBLOCK_SIZE_IN_BYTE<<1)
 
 #if defined(NUM_SPATIAL_LAYERS_CONSTRAINT)
 #define MAX_DEPENDENCY_LAYER		MAX_SPATIAL_LAYER_NUM	// Maximal dependency layer
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -529,9 +529,9 @@
         return ENC_RETURN_UNSUPPORTED_PARA;
       }
 
-      if (pCodingParam->uiMaxNalSize <= NAL_HEADER_ADD_0X30BYTES) {
-        WelsLog (pLogCtx, WELS_LOG_ERROR, "ParamValidationExt(), invalid uiMaxNalSize (%d) settings!",
-                 pCodingParam->uiMaxNalSize);
+      if (pCodingParam->uiMaxNalSize <= (NAL_HEADER_ADD_0X30BYTES + MAX_MACROBLOCK_SIZE_IN_BYTE)) {
+        WelsLog (pLogCtx, WELS_LOG_ERROR, "ParamValidationExt(), invalid uiMaxNalSize (%d) settings! should be larger than (NAL_HEADER_ADD_0X30BYTES + MAX_MACROBLOCK_SIZE_IN_BYTE)(%d)",
+                 pCodingParam->uiMaxNalSize, (NAL_HEADER_ADD_0X30BYTES + MAX_MACROBLOCK_SIZE_IN_BYTE));
         return ENC_RETURN_UNSUPPORTED_PARA;
       }
 
@@ -1740,7 +1740,7 @@
     fCompressRatioThr	= COMPRESS_RATIO_THR;
 
     iLayerBsSize = WELS_ROUND (((3 * fDlp->iVideoWidth * fDlp->iVideoHeight) >> 1) * fCompressRatioThr) +
-                   MAX_MACROBLOCK_SIZE_IN_BYTE;
+                   MAX_MACROBLOCK_SIZE_IN_BYTE_x2;
     iLayerBsSize	= WELS_ALIGN (iLayerBsSize, 4);			// 4 bytes alinged
     iVclLayersBsSizeCount += iLayerBsSize;
     ++ iIndex;
--- a/codec/encoder/core/src/svc_set_mb_syn_cavlc.cpp
+++ b/codec/encoder/core/src/svc_set_mb_syn_cavlc.cpp
@@ -212,7 +212,7 @@
   const intX_t iLeftLength = pBs->pBufEnd - pBs->pBufPtr - 1;
   assert (iLeftLength > 0);
 
-  if (iLeftLength < MAX_MACROBLOCK_SIZE_IN_BYTE) {
+  if (iLeftLength < MAX_MACROBLOCK_SIZE_IN_BYTE_x2) {
     return ENC_RETURN_MEMALLOCERR;
     //TODO: call the realloc&copy instead
   }