[x265] [PATCH 4 of 5] predict: combine and check allocations and return failures

Steve Borho steve at borho.org
Thu Sep 25 05:32:07 CEST 2014


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1411599279 18000
#      Wed Sep 24 17:54:39 2014 -0500
# Node ID 4c2125567cf55b099b7fff3724e07c6b1e77ba5a
# Parent  56633b36885a4df6d01b615c025286ed6b9d7fdf
predict: combine and check allocations and return failures

diff -r 56633b36885a -r 4c2125567cf5 source/encoder/predict.cpp
--- a/source/encoder/predict.cpp	Wed Sep 24 17:46:57 2014 -0500
+++ b/source/encoder/predict.cpp	Wed Sep 24 17:54:39 2014 -0500
@@ -49,32 +49,30 @@
 {
     X265_FREE(m_predBuf);
     X265_FREE(m_refAbove);
-    X265_FREE(m_refAboveFlt);
-    X265_FREE(m_refLeft);
-    X265_FREE(m_refLeftFlt);
     X265_FREE(m_immedVals);
-
     m_predShortYuv[0].destroy();
     m_predShortYuv[1].destroy();
 }
 
-void Predict::allocBuffers(int csp)
+bool Predict::allocBuffers(int csp)
 {
     m_csp = csp;
 
     int predBufHeight = ((MAX_CU_SIZE + 2) << 4);
     int predBufStride = ((MAX_CU_SIZE + 8) << 4);
-    m_predBuf = X265_MALLOC(pixel, predBufStride * predBufHeight);
+    CHECKED_MALLOC(m_predBuf, pixel, predBufStride * predBufHeight);
+    CHECKED_MALLOC(m_immedVals, int16_t, 64 * (64 + NTAPS_LUMA - 1));
+    CHECKED_MALLOC(m_refAbove, pixel, 12 * MAX_CU_SIZE);
 
-    m_refAbove = X265_MALLOC(pixel, 3 * MAX_CU_SIZE);
-    m_refAboveFlt = X265_MALLOC(pixel, 3 * MAX_CU_SIZE);
-    m_refLeft = X265_MALLOC(pixel, 3 * MAX_CU_SIZE);
-    m_refLeftFlt = X265_MALLOC(pixel, 3 * MAX_CU_SIZE);
+    m_refAboveFlt = m_refAbove + 3 * MAX_CU_SIZE;
+    m_refLeft = m_refAboveFlt + 3 * MAX_CU_SIZE;
+    m_refLeftFlt = m_refLeft + 3 * MAX_CU_SIZE;
 
-    m_predShortYuv[0].create(MAX_CU_SIZE, MAX_CU_SIZE, csp);
-    m_predShortYuv[1].create(MAX_CU_SIZE, MAX_CU_SIZE, csp);
+    return m_predShortYuv[0].create(MAX_CU_SIZE, MAX_CU_SIZE, csp) &&
+           m_predShortYuv[1].create(MAX_CU_SIZE, MAX_CU_SIZE, csp);
 
-    m_immedVals = X265_MALLOC(int16_t, 64 * (64 + NTAPS_LUMA - 1));
+fail:
+    return false;
 }
 
 void Predict::predIntraLumaAng(uint32_t dirMode, pixel* dst, intptr_t stride, uint32_t log2TrSize)
diff -r 56633b36885a -r 4c2125567cf5 source/encoder/predict.h
--- a/source/encoder/predict.h	Wed Sep 24 17:46:57 2014 -0500
+++ b/source/encoder/predict.h	Wed Sep 24 17:54:39 2014 -0500
@@ -80,7 +80,7 @@
     Predict();
     ~Predict();
 
-    void allocBuffers(int csp);
+    bool allocBuffers(int csp);
 
     /* prepMotionCompensation needs to be called to prepare MC with CU-relevant data */
     void prepMotionCompensation(TComDataCU* cu, int partIdx);
diff -r 56633b36885a -r 4c2125567cf5 source/encoder/search.cpp
--- a/source/encoder/search.cpp	Wed Sep 24 17:46:57 2014 -0500
+++ b/source/encoder/search.cpp	Wed Sep 24 17:54:39 2014 -0500
@@ -77,7 +77,7 @@
 
     m_rdCost.setPsyRdScale(param->psyRd);
 
-    Predict::allocBuffers(param->internalCsp);
+    ok &= Predict::allocBuffers(param->internalCsp);
     ok &= m_predTempYuv.create(MAX_CU_SIZE, MAX_CU_SIZE, param->internalCsp);
     m_me.setSearchMethod(param->searchMethod);
     m_me.setSubpelRefine(param->subpelRefine);


More information about the x265-devel mailing list