[x265] [PATCH] frameencoder: use CHECKED_MALLOC in getStreamHeaders()

Gopu Govindaswamy gopu at multicorewareinc.com
Fri Sep 20 11:14:55 CEST 2013


# HG changeset patch
# User Gopu Govindaswamy <gopu at multicorewareinc.com>
# Date 1379668464 -19800
# Node ID a8e2b71692b961115b291d327192e6bcfe209089
# Parent  3692f665008c8ce96a97872b92bb83aa34ef1049
frameencoder: use CHECKED_MALLOC in getStreamHeaders()

diff -r 3692f665008c -r a8e2b71692b9 source/Lib/TLibCommon/NAL.h
--- a/source/Lib/TLibCommon/NAL.h	Fri Sep 20 12:44:07 2013 +0530
+++ b/source/Lib/TLibCommon/NAL.h	Fri Sep 20 14:44:24 2013 +0530
@@ -114,6 +114,7 @@
      * emulation_prevention_three_byte symbols.
      */
     NALUnitEBSP(OutputNALUnit& nalu);
+    void init(OutputNALUnit& nalu);
 };
 }
 //! \}
diff -r 3692f665008c -r a8e2b71692b9 source/Lib/TLibEncoder/NALwrite.h
--- a/source/Lib/TLibEncoder/NALwrite.h	Fri Sep 20 12:44:07 2013 +0530
+++ b/source/Lib/TLibEncoder/NALwrite.h	Fri Sep 20 14:44:24 2013 +0530
@@ -83,6 +83,14 @@
     write(m_nalUnitData, nalu, m_packetSize);
 }
 
+void inline NALUnitEBSP::init(OutputNALUnit& nalu)
+{
+    m_nalUnitType = nalu.m_nalUnitType;
+    m_temporalId = nalu.m_temporalId;
+    m_reservedZero6Bits = nalu.m_reservedZero6Bits;
+    write(m_nalUnitData, nalu, m_packetSize);
+}
+
 void copyNaluData(OutputNALUnit& naluDest, const OutputNALUnit& naluSrc);
 }
 
diff -r 3692f665008c -r a8e2b71692b9 source/common/common.h
--- a/source/common/common.h	Fri Sep 20 12:44:07 2013 +0530
+++ b/source/common/common.h	Fri Sep 20 14:44:24 2013 +0530
@@ -95,6 +95,7 @@
 #define X265_MIN4(a, b, c, d) X265_MIN((a), X265_MIN3((b), (c), (d)))
 #define X265_MAX4(a, b, c, d) X265_MAX((a), X265_MAX3((b), (c), (d)))
 #define QP_BD_OFFSET (6*(X265_DEPTH-8))
+#define MAX_NAL_UNITS 5
 
 #define CHECKED_MALLOC(var, type, count )\
 {\
diff -r 3692f665008c -r a8e2b71692b9 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Fri Sep 20 12:44:07 2013 +0530
+++ b/source/encoder/encoder.cpp	Fri Sep 20 14:44:24 2013 +0530
@@ -368,6 +368,11 @@
         {
             *pp_nal = &encoder->m_nals[0];
             if (pi_nal) *pi_nal = (int)nalcount;
+            for (AccessUnit::const_iterator t = au.begin(); t != au.end(); t++)
+            {
+                X265_FREE(*t);
+            }
+            au.clear();
             return 0;
         }
         return -1;
@@ -485,7 +490,6 @@
             m_nals[i].p_payload = (uint8_t*)m_packetData + offset;
             offset += m_nals[i].i_payload;
         }
-
         return 0;
 fail:
         return -1;
diff -r 3692f665008c -r a8e2b71692b9 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Fri Sep 20 12:44:07 2013 +0530
+++ b/source/encoder/frameencoder.cpp	Fri Sep 20 14:44:24 2013 +0530
@@ -163,25 +163,36 @@
     TEncEntropy* entropyCoder = getEntropyCoder(0);
 
     entropyCoder->setEntropyCoder(&m_cavlcCoder, NULL);
+    NALUnitEBSP *tmp[MAX_NAL_UNITS] = {0, 0, 0, 0, 0};
+    int count = 0;
 
     /* headers for start of bitstream */
     OutputNALUnit nalu(NAL_UNIT_VPS);
     entropyCoder->setBitstream(&nalu.m_Bitstream);
     entropyCoder->encodeVPS(m_cfg->getVPS());
     writeRBSPTrailingBits(nalu.m_Bitstream);
-    accessUnit.push_back(new NALUnitEBSP(nalu));
+    CHECKED_MALLOC(tmp[count], NALUnitEBSP, 1);
+    tmp[count]->init(nalu);
+    accessUnit.push_back(tmp[count]);
+    count++;
 
     nalu = NALUnit(NAL_UNIT_SPS);
     entropyCoder->setBitstream(&nalu.m_Bitstream);
     entropyCoder->encodeSPS(&m_sps);
     writeRBSPTrailingBits(nalu.m_Bitstream);
-    accessUnit.push_back(new NALUnitEBSP(nalu));
+    CHECKED_MALLOC(tmp[count], NALUnitEBSP, 1);
+    tmp[count]->init(nalu);
+    accessUnit.push_back(tmp[count]);
+    count++;
 
     nalu = NALUnit(NAL_UNIT_PPS);
     entropyCoder->setBitstream(&nalu.m_Bitstream);
     entropyCoder->encodePPS(&m_pps);
     writeRBSPTrailingBits(nalu.m_Bitstream);
-    accessUnit.push_back(new NALUnitEBSP(nalu));
+    CHECKED_MALLOC(tmp[count], NALUnitEBSP, 1);
+    tmp[count]->init(nalu);
+    accessUnit.push_back(tmp[count]);
+    count++;
 
     if (m_cfg->getActiveParameterSetsSEIEnabled())
     {
@@ -195,7 +206,10 @@
         entropyCoder->setBitstream(&nalu.m_Bitstream);
         m_seiWriter.writeSEImessage(nalu.m_Bitstream, sei, &m_sps);
         writeRBSPTrailingBits(nalu.m_Bitstream);
-        accessUnit.push_back(new NALUnitEBSP(nalu));
+        CHECKED_MALLOC(tmp[count], NALUnitEBSP, 1);
+        tmp[count]->init(nalu);
+        accessUnit.push_back(tmp[count]);
+        count++;
     }
 
     if (m_cfg->getDisplayOrientationSEIAngle())
@@ -210,9 +224,14 @@
         entropyCoder->setBitstream(&nalu.m_Bitstream);
         m_seiWriter.writeSEImessage(nalu.m_Bitstream, sei, &m_sps);
         writeRBSPTrailingBits(nalu.m_Bitstream);
-        accessUnit.push_back(new NALUnitEBSP(nalu));
+        CHECKED_MALLOC(tmp[count], NALUnitEBSP, 1);
+        tmp[count]->init(nalu);
+        accessUnit.push_back(tmp[count]);
     }
     return 0;
+    
+fail:
+    return -1;
 }
 
 void FrameEncoder::initSlice(TComPic* pic)


More information about the x265-devel mailing list