[x265-commits] [x265] use checked mallocs in TComPic::create() and in functions...

Steve Borho steve at borho.org
Wed Feb 5 19:34:47 CET 2014


details:   http://hg.videolan.org/x265/rev/6d0b6602e730
branches:  
changeset: 6012:6d0b6602e730
user:      Steve Borho <steve at borho.org>
date:      Tue Feb 04 21:26:07 2014 -0600
description:
use checked mallocs in TComPic::create() and in functions it calls

This is the most obvious place memory allocation failures will occur, at encoder
startup. So it is best to catch them cleanly.
Subject: [x265] lowres: there was no need to pass an int* as an int32_t*

details:   http://hg.videolan.org/x265/rev/76be476dfed5
branches:  
changeset: 6013:76be476dfed5
user:      Steve Borho <steve at borho.org>
date:      Tue Feb 04 22:06:15 2014 -0600
description:
lowres: there was no need to pass an int* as an int32_t*
Subject: [x265] fix addAvg

details:   http://hg.videolan.org/x265/rev/d20c11f2775f
branches:  
changeset: 6014:d20c11f2775f
user:      Satoshi Nakagawa <nakagawa424 at oki.com>
date:      Wed Feb 05 09:38:06 2014 +0900
description:
fix addAvg
Subject: [x265] Backed out changeset: a88c7bbfba61

details:   http://hg.videolan.org/x265/rev/1374f1168c5c
branches:  
changeset: 6015:1374f1168c5c
user:      Deepthi Nandakumar <deepthi at multicorewareinc.com>
date:      Wed Feb 05 12:59:57 2014 +0530
description:
Backed out changeset: a88c7bbfba61

The addAvg x86 versions have now been fixed
Subject: [x265] lowres: fix gcc/clang compile errors

details:   http://hg.videolan.org/x265/rev/e05898ee63c0
branches:  
changeset: 6016:e05898ee63c0
user:      Steve Borho <steve at borho.org>
date:      Wed Feb 05 11:30:38 2014 -0600
description:
lowres: fix gcc/clang compile errors

gcc doesn't like to jump to labels that bypass variable initializations, even
if they are not used passed the jump
Subject: [x265] encoder: try not to leak memory after malloc failures

details:   http://hg.videolan.org/x265/rev/def14c0234f5
branches:  
changeset: 6017:def14c0234f5
user:      Steve Borho <steve at borho.org>
date:      Wed Feb 05 11:32:47 2014 -0600
description:
encoder: try not to leak memory after malloc failures
Subject: [x265] cuTree: bug fix for frameCostRecalculate

details:   http://hg.videolan.org/x265/rev/0776a6722375
branches:  
changeset: 6018:0776a6722375
user:      Gopu Govindaswamy
date:      Wed Feb 05 12:06:33 2014 -0600
description:
cuTree: bug fix for frameCostRecalculate
Subject: [x265] lowres: initialize weightedCostDelta to avoid Valgrind reporting uninitialized memory

details:   http://hg.videolan.org/x265/rev/8d9abc152370
branches:  
changeset: 6019:8d9abc152370
user:      Gopu Govindaswamy
date:      Wed Feb 05 12:16:57 2014 -0600
description:
lowres: initialize weightedCostDelta to avoid Valgrind reporting uninitialized memory
Subject: [x265] abr: reset ABR to prevent high bitrate peaks in single pass ABR

details:   http://hg.videolan.org/x265/rev/fc86625df0d9
branches:  
changeset: 6020:fc86625df0d9
user:      Aarthi Thirumalai
date:      Wed Feb 05 00:14:12 2014 +0530
description:
abr: reset ABR to prevent high bitrate peaks in single pass ABR

Long series of blank frames in video followed by detailed content causes
heavy ABR underflow and overall bitrates surges high for a long while.
This patch detects this condition in Single pass ABR mode and resets ABR -
to not consider history from blank frames and continue from following
scene-cut.
Subject: [x265] cmake: only officially support 16bpp builds on x64 architectures

details:   http://hg.videolan.org/x265/rev/2f54c7616ef8
branches:  
changeset: 6021:2f54c7616ef8
user:      Steve Borho <steve at borho.org>
date:      Wed Feb 05 12:34:25 2014 -0600
description:
cmake: only officially support 16bpp builds on x64 architectures

diffstat:

 source/CMakeLists.txt                |   11 ++-
 source/Lib/TLibCommon/TComDataCU.cpp |  151 ++++++++++++++++------------------
 source/Lib/TLibCommon/TComDataCU.h   |    2 +-
 source/Lib/TLibCommon/TComPic.cpp    |   25 +++--
 source/Lib/TLibCommon/TComPic.h      |    2 +-
 source/Lib/TLibCommon/TComPicSym.cpp |   17 ++-
 source/Lib/TLibCommon/TComPicSym.h   |    2 +-
 source/Lib/TLibCommon/TComPicYuv.cpp |   39 +++-----
 source/Lib/TLibCommon/TComPicYuv.h   |    2 +-
 source/common/lowres.cpp             |   39 +++++---
 source/common/lowres.h               |    2 +-
 source/common/x86/asm-primitives.cpp |    2 -
 source/common/x86/mc-a.asm           |    6 +-
 source/encoder/encoder.cpp           |   11 ++-
 source/encoder/ratecontrol.cpp       |   87 ++++++++++++++++---
 source/encoder/ratecontrol.h         |    6 +-
 source/encoder/slicetype.cpp         |    2 +-
 source/x265.cpp                      |   11 +-
 18 files changed, 247 insertions(+), 170 deletions(-)

diffs (truncated from 831 to 300 lines):

diff -r bed6e485d6c1 -r 2f54c7616ef8 source/CMakeLists.txt
--- a/source/CMakeLists.txt	Tue Feb 04 17:30:50 2014 -0600
+++ b/source/CMakeLists.txt	Wed Feb 05 12:34:25 2014 -0600
@@ -137,7 +137,16 @@ if(YASM_FOUND AND X86)
 endif()
 
 # Build options
-option(HIGH_BIT_DEPTH "Use 16bit pixels internally" OFF)
+
+if(X64)
+    # NOTE: We only officially support 16bit-per-pixel compiles of x265
+    # on 64bit architectures. 16bpp plus large resolution plus slow
+    # preset plus 32bit address space usually means malloc failure.  You
+    # can disable this if(X64) check if you desparately need a 32bit
+    # build with 10bit/12bit support, but this violates the "shrink wrap
+    # license" so to speak.  If it breaks you get to keep both halves.
+    option(HIGH_BIT_DEPTH "Store pixels as 16bit values" OFF)
+endif(X64)
 if(HIGH_BIT_DEPTH)
     add_definitions(-DHIGH_BIT_DEPTH=1)
 else(HIGH_BIT_DEPTH)
diff -r bed6e485d6c1 -r 2f54c7616ef8 source/Lib/TLibCommon/TComDataCU.cpp
--- a/source/Lib/TLibCommon/TComDataCU.cpp	Tue Feb 04 17:30:50 2014 -0600
+++ b/source/Lib/TLibCommon/TComDataCU.cpp	Wed Feb 05 12:34:25 2014 -0600
@@ -104,7 +104,7 @@ TComDataCU::TComDataCU()
 TComDataCU::~TComDataCU()
 {}
 
-void TComDataCU::create(uint32_t numPartition, uint32_t width, uint32_t height, int unitSize, int csp)
+bool TComDataCU::create(uint32_t numPartition, uint32_t width, uint32_t height, int unitSize, int csp)
 {
     m_hChromaShift = CHROMA_H_SHIFT(csp);
     m_vChromaShift = CHROMA_V_SHIFT(csp);
@@ -121,90 +121,85 @@ void TComDataCU::create(uint32_t numPart
     tmp = g_convertToBit[tmp] + 2;
     m_unitMask = ~((1 << tmp) - 1);
 
-    m_qp     = X265_MALLOC(char,  numPartition);
-    m_depth  = X265_MALLOC(UChar, numPartition);
-    m_width  = X265_MALLOC(UChar, numPartition);
-    m_height = X265_MALLOC(UChar, numPartition);
-
-    m_skipFlag = new bool[numPartition];
-
-    m_partSizes = new char[numPartition];
-    memset(m_partSizes, SIZE_NONE, numPartition * sizeof(*m_partSizes));
-    m_predModes = new char[numPartition];
-    m_cuTransquantBypass = new bool[numPartition];
-
-    m_bMergeFlags     = X265_MALLOC(bool,  numPartition);
-    m_mergeIndex      = X265_MALLOC(UChar, numPartition);
-    m_lumaIntraDir    = X265_MALLOC(UChar, numPartition);
-    m_chromaIntraDir  = X265_MALLOC(UChar, numPartition);
-    m_interDir        = X265_MALLOC(UChar, numPartition);
-
-    m_trIdx            = X265_MALLOC(UChar, numPartition);
-    m_transformSkip[0] = X265_MALLOC(UChar, numPartition);
-    m_transformSkip[1] = X265_MALLOC(UChar, numPartition);
-    m_transformSkip[2] = X265_MALLOC(UChar, numPartition);
-
-    m_cbf[0] = X265_MALLOC(UChar, numPartition);
-    m_cbf[1] = X265_MALLOC(UChar, numPartition);
-    m_cbf[2] = X265_MALLOC(UChar, numPartition);
-
-    m_mvpIdx[0] = new char[numPartition];
-    m_mvpIdx[1] = new char[numPartition];
-
-    m_trCoeffY  = X265_MALLOC(TCoeff, width * height);
-    m_trCoeffCb = X265_MALLOC(TCoeff, (width >> m_hChromaShift) * (height >> m_vChromaShift));
-    m_trCoeffCr = X265_MALLOC(TCoeff, (width >> m_hChromaShift) * (height >> m_vChromaShift));
-
-    m_iPCMFlags   = X265_MALLOC(bool, numPartition);
-    m_iPCMSampleY  = X265_MALLOC(Pel, width * height);
-    m_iPCMSampleCb = X265_MALLOC(Pel, (width >> m_hChromaShift) * (height >> m_vChromaShift));
-    m_iPCMSampleCr = X265_MALLOC(Pel, (width >> m_hChromaShift) * (height >> m_vChromaShift));
-
     m_cuMvField[0].create(numPartition);
     m_cuMvField[1].create(numPartition);
 
-    // create pattern memory
-    m_pattern = X265_MALLOC(TComPattern, 1);
+    CHECKED_MALLOC(m_qp, char,  numPartition);
+    CHECKED_MALLOC(m_depth, UChar, numPartition);
+    CHECKED_MALLOC(m_width, UChar, numPartition);
+    CHECKED_MALLOC(m_height, UChar, numPartition);
+    CHECKED_MALLOC(m_skipFlag, bool, numPartition);
+    CHECKED_MALLOC(m_partSizes, char, numPartition);
+    CHECKED_MALLOC(m_predModes, char, numPartition);
+    CHECKED_MALLOC(m_cuTransquantBypass, bool, numPartition);
+
+    CHECKED_MALLOC(m_bMergeFlags, bool,  numPartition);
+    CHECKED_MALLOC(m_mergeIndex, UChar, numPartition);
+    CHECKED_MALLOC(m_lumaIntraDir, UChar, numPartition);
+    CHECKED_MALLOC(m_chromaIntraDir, UChar, numPartition);
+    CHECKED_MALLOC(m_interDir, UChar, numPartition);
+
+    CHECKED_MALLOC(m_trIdx, UChar, numPartition);
+    CHECKED_MALLOC(m_transformSkip[0], UChar, numPartition);
+    CHECKED_MALLOC(m_transformSkip[1], UChar, numPartition);
+    CHECKED_MALLOC(m_transformSkip[2], UChar, numPartition);
+
+    CHECKED_MALLOC(m_cbf[0], UChar, numPartition);
+    CHECKED_MALLOC(m_cbf[1], UChar, numPartition);
+    CHECKED_MALLOC(m_cbf[2], UChar, numPartition);
+
+    CHECKED_MALLOC(m_mvpIdx[0], char, numPartition);
+    CHECKED_MALLOC(m_mvpIdx[1], char, numPartition);
+
+    CHECKED_MALLOC(m_trCoeffY, TCoeff, width * height);
+    CHECKED_MALLOC(m_trCoeffCb, TCoeff, (width >> m_hChromaShift) * (height >> m_vChromaShift));
+    CHECKED_MALLOC(m_trCoeffCr, TCoeff, (width >> m_hChromaShift) * (height >> m_vChromaShift));
+
+    CHECKED_MALLOC(m_iPCMFlags, bool, numPartition);
+    CHECKED_MALLOC(m_iPCMSampleY, Pel, width * height);
+    CHECKED_MALLOC(m_iPCMSampleCb, Pel, (width >> m_hChromaShift) * (height >> m_vChromaShift));
+    CHECKED_MALLOC(m_iPCMSampleCr, Pel, (width >> m_hChromaShift) * (height >> m_vChromaShift));
+    CHECKED_MALLOC(m_pattern, TComPattern, 1);
+
+    memset(m_partSizes, SIZE_NONE, numPartition * sizeof(*m_partSizes));
+    return m_pattern;
+
+fail:
+    return false;
 }
 
 void TComDataCU::destroy()
 {
-    if (m_pattern) { X265_FREE(m_pattern); m_pattern = NULL; }
-    if (m_qp) { X265_FREE(m_qp); m_qp = NULL; }
-    if (m_depth) { X265_FREE(m_depth); m_depth = NULL; }
-    if (m_width) { X265_FREE(m_width); m_width = NULL; }
-    if (m_height) { X265_FREE(m_height); m_height = NULL; }
-    if (m_cbf[0]) { X265_FREE(m_cbf[0]); m_cbf[0] = NULL; }
-    if (m_cbf[1]) { X265_FREE(m_cbf[1]); m_cbf[1] = NULL; }
-    if (m_cbf[2]) { X265_FREE(m_cbf[2]); m_cbf[2] = NULL; }
-    if (m_interDir) { X265_FREE(m_interDir); m_interDir = NULL; }
-    if (m_bMergeFlags) { X265_FREE(m_bMergeFlags); m_bMergeFlags = NULL; }
-    if (m_mergeIndex) { X265_FREE(m_mergeIndex); m_mergeIndex = NULL; }
-    if (m_lumaIntraDir) { X265_FREE(m_lumaIntraDir); m_lumaIntraDir = NULL; }
-    if (m_chromaIntraDir) { X265_FREE(m_chromaIntraDir); m_chromaIntraDir = NULL; }
-    if (m_trIdx) { X265_FREE(m_trIdx); m_trIdx = NULL; }
-    if (m_transformSkip[0]) { X265_FREE(m_transformSkip[0]); m_transformSkip[0] = NULL; }
-    if (m_transformSkip[1]) { X265_FREE(m_transformSkip[1]); m_transformSkip[1] = NULL; }
-    if (m_transformSkip[2]) { X265_FREE(m_transformSkip[2]); m_transformSkip[2] = NULL; }
-    if (m_trCoeffY) { X265_FREE(m_trCoeffY); m_trCoeffY = NULL; }
-    if (m_trCoeffCb) { X265_FREE(m_trCoeffCb); m_trCoeffCb = NULL; }
-    if (m_trCoeffCr) { X265_FREE(m_trCoeffCr); m_trCoeffCr = NULL; }
-    if (m_iPCMFlags) { X265_FREE(m_iPCMFlags); m_iPCMFlags = NULL; }
-    if (m_iPCMSampleY) { X265_FREE(m_iPCMSampleY); m_iPCMSampleY = NULL; }
-    if (m_iPCMSampleCb) { X265_FREE(m_iPCMSampleCb); m_iPCMSampleCb = NULL; }
-    if (m_iPCMSampleCr) { X265_FREE(m_iPCMSampleCr); m_iPCMSampleCr = NULL; }
-    delete[] m_cuTransquantBypass;
-    m_cuTransquantBypass = NULL;
-    delete[] m_mvpIdx[0];
-    m_mvpIdx[0] = NULL;
-    delete[] m_mvpIdx[1];
-    m_mvpIdx[1] = NULL;
-    delete[] m_skipFlag;
-    m_skipFlag = NULL;
-    delete[] m_partSizes;
-    m_partSizes = NULL;
-    delete[] m_predModes;
-    m_predModes = NULL;
+    X265_FREE(m_pattern);
+    X265_FREE(m_qp);
+    X265_FREE(m_depth);
+    X265_FREE(m_width);
+    X265_FREE(m_height);
+    X265_FREE(m_cbf[0]);
+    X265_FREE(m_cbf[1]);
+    X265_FREE(m_cbf[2]);
+    X265_FREE(m_interDir);
+    X265_FREE(m_bMergeFlags);
+    X265_FREE(m_mergeIndex);
+    X265_FREE(m_lumaIntraDir);
+    X265_FREE(m_chromaIntraDir);
+    X265_FREE(m_trIdx);
+    X265_FREE(m_transformSkip[0]);
+    X265_FREE(m_transformSkip[1]);
+    X265_FREE(m_transformSkip[2]);
+    X265_FREE(m_trCoeffY);
+    X265_FREE(m_trCoeffCb);
+    X265_FREE(m_trCoeffCr);
+    X265_FREE(m_iPCMFlags);
+    X265_FREE(m_iPCMSampleY);
+    X265_FREE(m_iPCMSampleCb);
+    X265_FREE(m_iPCMSampleCr);
+    X265_FREE(m_mvpIdx[0]);
+    X265_FREE(m_mvpIdx[1]);
+    X265_FREE(m_cuTransquantBypass);
+    X265_FREE(m_skipFlag);
+    X265_FREE(m_partSizes);
+    X265_FREE(m_predModes);
 
     m_cuMvField[0].destroy();
     m_cuMvField[1].destroy();
diff -r bed6e485d6c1 -r 2f54c7616ef8 source/Lib/TLibCommon/TComDataCU.h
--- a/source/Lib/TLibCommon/TComDataCU.h	Tue Feb 04 17:30:50 2014 -0600
+++ b/source/Lib/TLibCommon/TComDataCU.h	Wed Feb 05 12:34:25 2014 -0600
@@ -186,7 +186,7 @@ public:
     // create / destroy / initialize / copy
     // -------------------------------------------------------------------------------------------------------------------
 
-    void          create(uint32_t numPartition, uint32_t width, uint32_t height, int unitSize, int csp);
+    bool          create(uint32_t numPartition, uint32_t width, uint32_t height, int unitSize, int csp);
     void          destroy();
 
     void          initCU(TComPic* pic, uint32_t cuAddr);
diff -r bed6e485d6c1 -r 2f54c7616ef8 source/Lib/TLibCommon/TComPic.cpp
--- a/source/Lib/TLibCommon/TComPic.cpp	Tue Feb 04 17:30:50 2014 -0600
+++ b/source/Lib/TLibCommon/TComPic.cpp	Wed Feb 05 12:34:25 2014 -0600
@@ -74,25 +74,26 @@ TComPic::TComPic()
 TComPic::~TComPic()
 {}
 
-void TComPic::create(TEncCfg* cfg)
+bool TComPic::create(TEncCfg* cfg)
 {
-    m_picSym = new TComPicSym;
-    m_picSym->create(cfg->param.sourceWidth, cfg->param.sourceHeight, cfg->param.internalCsp, g_maxCUWidth, g_maxCUHeight, g_maxCUDepth);
-
-    m_origPicYuv = new TComPicYuv;
-    m_origPicYuv->create(cfg->param.sourceWidth, cfg->param.sourceHeight, cfg->param.internalCsp, g_maxCUWidth, g_maxCUHeight, g_maxCUDepth);
-
-    m_reconPicYuv = new TComPicYuv;
-    m_reconPicYuv->create(cfg->param.sourceWidth, cfg->param.sourceHeight, cfg->param.internalCsp, g_maxCUWidth, g_maxCUHeight, g_maxCUDepth);
-
     /* store conformance window parameters with picture */
     m_conformanceWindow = cfg->m_conformanceWindow;
 
     /* store display window parameters with picture */
     m_defaultDisplayWindow = cfg->getDefaultDisplayWindow();
 
-    /* configure lowres dimensions */
-    m_lowres.create(m_origPicYuv, cfg->param.bframes, &cfg->param.rc.aqMode);
+    m_picSym = new TComPicSym;
+    m_origPicYuv = new TComPicYuv;
+    m_reconPicYuv = new TComPicYuv;
+    if (!m_picSym || !m_origPicYuv || !m_reconPicYuv)
+        return false;
+
+    bool ok = true;
+    ok &= m_picSym->create(cfg->param.sourceWidth, cfg->param.sourceHeight, cfg->param.internalCsp, g_maxCUWidth, g_maxCUHeight, g_maxCUDepth);
+    ok &= m_origPicYuv->create(cfg->param.sourceWidth, cfg->param.sourceHeight, cfg->param.internalCsp, g_maxCUWidth, g_maxCUHeight, g_maxCUDepth);
+    ok &= m_reconPicYuv->create(cfg->param.sourceWidth, cfg->param.sourceHeight, cfg->param.internalCsp, g_maxCUWidth, g_maxCUHeight, g_maxCUDepth);
+    ok &= m_lowres.create(m_origPicYuv, cfg->param.bframes, &cfg->param.rc.aqMode);
+    return ok;
 }
 
 void TComPic::destroy(int bframes)
diff -r bed6e485d6c1 -r 2f54c7616ef8 source/Lib/TLibCommon/TComPic.h
--- a/source/Lib/TLibCommon/TComPic.h	Tue Feb 04 17:30:50 2014 -0600
+++ b/source/Lib/TLibCommon/TComPic.h	Wed Feb 05 12:34:25 2014 -0600
@@ -105,7 +105,7 @@ public:
     TComPic();
     virtual ~TComPic();
 
-    void          create(TEncCfg* cfg);
+    bool          create(TEncCfg* cfg);
 
     virtual void  destroy(int bframes);
 
diff -r bed6e485d6c1 -r 2f54c7616ef8 source/Lib/TLibCommon/TComPicSym.cpp
--- a/source/Lib/TLibCommon/TComPicSym.cpp	Tue Feb 04 17:30:50 2014 -0600
+++ b/source/Lib/TLibCommon/TComPicSym.cpp	Wed Feb 05 12:34:25 2014 -0600
@@ -63,10 +63,11 @@ TComPicSym::TComPicSym()
     , m_cuData(NULL)
 {}
 
-void TComPicSym::create(int picWidth, int picHeight, int picCsp, uint32_t maxWidth, uint32_t maxHeight, uint32_t maxDepth)
+bool TComPicSym::create(int picWidth, int picHeight, int picCsp, uint32_t maxWidth, uint32_t maxHeight, uint32_t maxDepth)
 {
     uint32_t i;
 
+    m_saoParam        = NULL;
     m_totalDepth      = maxDepth;
     m_numPartitions   = 1 << (m_totalDepth << 1);
 
@@ -83,16 +84,21 @@ void TComPicSym::create(int picWidth, in
     m_heightInCU      = (picHeight % m_maxCUHeight) ? picHeight / m_maxCUHeight + 1 : picHeight / m_maxCUHeight;
 
     m_numCUsInFrame   = m_widthInCU * m_heightInCU;
-    m_cuData          = new TComDataCU*[m_numCUsInFrame];
 
     m_slice = new TComSlice;
+    m_cuData = new TComDataCU*[m_numCUsInFrame];
+    if (!m_slice || !m_cuData)
+        return false;
+
     for (i = 0; i < m_numCUsInFrame; i++)
     {
         m_cuData[i] = new TComDataCU;
-        m_cuData[i]->create(m_numPartitions, m_maxCUWidth, m_maxCUHeight, m_maxCUWidth >> m_totalDepth, picCsp);
+        if (!m_cuData[i])
+            return false;
+        if (!m_cuData[i]->create(m_numPartitions, m_maxCUWidth, m_maxCUHeight, m_maxCUWidth >> m_totalDepth, picCsp))
+            return false;
     }
-
-    m_saoParam = NULL;


More information about the x265-commits mailing list