[x265] [PATCH 4 of 4] Adding few checks and an init() function in MotionRefrence class

shazeb at multicorewareinc.com shazeb at multicorewareinc.com
Tue Oct 1 09:51:47 CEST 2013


# HG changeset patch
# User Shazeb Nawaz Khan <shazeb at multicorewareinc.com>
# Date 1380608621 -19800
#      Tue Oct 01 11:53:41 2013 +0530
# Node ID 051ccb452f2442ec9c054e2c8758df1843058bab
# Parent  0da50ad39b4137976e4e2b295c32e1a710843b60
Adding few checks and an init() function in MotionRefrence class...

to properly signal malloc failure for 'fpelPlane'; handling to be added later

diff -r 0da50ad39b41 -r 051ccb452f24 source/Lib/TLibCommon/TComPicYuv.cpp
--- a/source/Lib/TLibCommon/TComPicYuv.cpp	Tue Oct 01 11:38:34 2013 +0530
+++ b/source/Lib/TLibCommon/TComPicYuv.cpp	Tue Oct 01 11:53:41 2013 +0530
@@ -250,7 +250,8 @@
         else if (mref->isWeighted == false)
             return mref;
     }
-    mref = new MotionReference(this, w);
+    mref = new MotionReference();
+    mref->init(this, w);
     mref->m_next = m_refList;
     m_refList = mref;
     return mref;
diff -r 0da50ad39b41 -r 051ccb452f24 source/common/reference.cpp
--- a/source/common/reference.cpp	Tue Oct 01 11:38:34 2013 +0530
+++ b/source/common/reference.cpp	Tue Oct 01 11:53:41 2013 +0530
@@ -24,6 +24,7 @@
 
 #include "TLibCommon/TypeDef.h"
 #include "TLibCommon/TComPicYuv.h"
+#include "TLibCommon/TComPic.h"
 #include "TLibCommon/TComSlice.h"
 #include "primitives.h"
 #include "reference.h"
@@ -51,12 +52,16 @@
     return false;
 }
 
-MotionReference::MotionReference(TComPicYuv* pic, wpScalingParam *w)
+MotionReference::MotionReference()
+{}
+
+int MotionReference::init(TComPicYuv* pic, wpScalingParam *w)
 {
     m_reconPic = pic;
     lumaStride = pic->getStride();
     m_startPad = pic->m_lumaMarginY * lumaStride + pic->m_lumaMarginX;
     m_next = NULL;
+    isWeighted = false;
 
     if (w)
     {
@@ -66,17 +71,20 @@
         size_t padheight = height + pic->m_lumaMarginY * 2;
 
         setWeight(*w);
-        fpelPlane = (pixel*)X265_MALLOC(pixel,  padwidth * padheight) + m_startPad;
+        fpelPlane = (pixel*)X265_MALLOC(pixel,  padwidth * padheight);
+        if (fpelPlane) fpelPlane += m_startPad;
+        else return -1;
     }
     else
     {
         /* directly reference the pre-extended integer pel plane */
         fpelPlane = pic->m_picBufY + m_startPad;
     }
+    return 0;
 }
 
 MotionReference::~MotionReference()
 {
-    if (isWeighted)
-        X265_FREE(fpelPlane);
+    if (isWeighted && fpelPlane)
+        X265_FREE(fpelPlane - m_startPad);
 }
diff -r 0da50ad39b41 -r 051ccb452f24 source/common/reference.h
--- a/source/common/reference.h	Tue Oct 01 11:38:34 2013 +0530
+++ b/source/common/reference.h	Tue Oct 01 11:53:41 2013 +0530
@@ -30,6 +30,7 @@
 // private x265 namespace
 
 class TComPicYuv;
+class TComPic;
 struct WpScalingParam;
 typedef WpScalingParam wpScalingParam;
 
@@ -56,9 +57,9 @@
 {
 public:
 
-    MotionReference(TComPicYuv*, wpScalingParam* w = NULL);
-
+    MotionReference();
     ~MotionReference();
+    int  init(TComPicYuv*, wpScalingParam* w = NULL);
 
     MotionReference *m_next;
     TComPicYuv      *m_reconPic;


More information about the x265-devel mailing list