[x265] [PATCH RFC ] STL Replace : Removed std::ostringstream replaced with non STL

Gopu Govindaswamy gopu at multicorewareinc.com
Tue Sep 10 13:18:59 CEST 2013


# HG changeset patch
# User Gopu Govindaswamy <gopu at multicorewareinc.com>
# Date 1378811919 -19800
# Node ID 37a8c6d9cea8df0c18c4676ae94a35935358b768
# Parent  ab77d80491d8dec79def409bb4a31a1ed21a6ab3
STL Replace : Removed std::ostringstream replaced with non STL

diff -r ab77d80491d8 -r 37a8c6d9cea8 source/Lib/TLibCommon/NAL.h
--- a/source/Lib/TLibCommon/NAL.h	Tue Sep 10 11:16:15 2013 +0530
+++ b/source/Lib/TLibCommon/NAL.h	Tue Sep 10 16:48:39 2013 +0530
@@ -105,7 +105,8 @@
  */
 struct NALUnitEBSP : public NALUnit
 {
-    std::ostringstream m_nalUnitData;
+    unsigned char *m_nalUnitData;
+    long m_packetSize;
 
     /**
      * convert the OutputNALUnit #nalu# into EBSP format by writing out
diff -r ab77d80491d8 -r 37a8c6d9cea8 source/Lib/TLibEncoder/NALwrite.cpp
--- a/source/Lib/TLibEncoder/NALwrite.cpp	Tue Sep 10 11:16:15 2013 +0530
+++ b/source/Lib/TLibEncoder/NALwrite.cpp	Tue Sep 10 16:48:39 2013 +0530
@@ -48,26 +48,23 @@
 
 static const char emulation_prevention_three_byte[] = { 3 };
 
-void writeNalUnitHeader(ostream& out, OutputNALUnit& nalu)       // nal_unit_header()
+/**
+ * write nalu to bytestream out, performing RBSP anti startcode
+ * emulation as required.  nalu.m_RBSPayload must be byte aligned.
+ */
+void write(unsigned char*& out, OutputNALUnit& nalu, long &packetSize)
 {
+    packetSize = 0;
     TComOutputBitstream bsNALUHeader;
-
     bsNALUHeader.write(0, 1);                 // forbidden_zero_bit
     bsNALUHeader.write(nalu.m_nalUnitType, 6); // nal_unit_type
     bsNALUHeader.write(nalu.m_reservedZero6Bits, 6);                 // nuh_reserved_zero_6bits
     bsNALUHeader.write(nalu.m_temporalId + 1, 3); // nuh_temporal_id_plus1
-
-    out.write(bsNALUHeader.getByteStream(), bsNALUHeader.getByteStreamLength());
-}
-
-/**
- * write nalu to bytestream out, performing RBSP anti startcode
- * emulation as required.  nalu.m_RBSPayload must be byte aligned.
- */
-void write(ostream& out, OutputNALUnit& nalu)
-{
-    writeNalUnitHeader(out, nalu);
-
+    
+    packetSize += bsNALUHeader.getByteStreamLength();
+    out = (unsigned char *) malloc(packetSize);
+    ::memcpy(out, bsNALUHeader.getByteStream(), bsNALUHeader.getByteStreamLength());
+    
     /* write out rsbp_byte's, inserting any required
      * emulation_prevention_three_byte's */
 
@@ -119,7 +116,16 @@
         }
     }
 
-    out.write((char*)&(*rbsp.begin()), rbsp.end() - rbsp.begin());
+    int i = packetSize;
+    out = (unsigned char *) realloc(out, rbsp.end() - rbsp.begin());
+    packetSize += rbsp.end() - rbsp.begin();
+    
+    /* TODO find out the other way to copy the unsigned char* from vector,  memcpy and strcpy is not working here due to '0' chars */
+    for (std::vector<uint8_t>::iterator it = rbsp.begin() ; it != rbsp.end(); ++it)
+    {
+        out[i] =  *it;
+        i++;
+    }
 
     /* 7.4.1.1
      * ... when the last byte of the RBSP data is equal to 0x00 (which can
@@ -128,7 +134,8 @@
      */
     if (rbsp.back() == 0x00)
     {
-        out.write(emulation_prevention_three_byte, 1);
+        out[i] = 3;
+        packetSize += 1;
     }
 }
 
diff -r ab77d80491d8 -r 37a8c6d9cea8 source/Lib/TLibEncoder/NALwrite.h
--- a/source/Lib/TLibEncoder/NALwrite.h	Tue Sep 10 11:16:15 2013 +0530
+++ b/source/Lib/TLibEncoder/NALwrite.h	Tue Sep 10 16:48:39 2013 +0530
@@ -74,13 +74,13 @@
     TComOutputBitstream m_Bitstream;
 };
 
-void write(std::ostream& out, OutputNALUnit& nalu);
+void write(unsigned char*& out, OutputNALUnit& nalu, long& packetSize);
 void writeRBSPTrailingBits(TComOutputBitstream& bs);
 
 inline NALUnitEBSP::NALUnitEBSP(OutputNALUnit& nalu)
     : NALUnit(nalu)
 {
-    write(m_nalUnitData, nalu);
+    write(m_nalUnitData, nalu, m_packetSize);
 }
 
 void copyNaluData(OutputNALUnit& naluDest, const OutputNALUnit& naluSrc);
diff -r ab77d80491d8 -r 37a8c6d9cea8 source/Lib/TLibEncoder/TEncTop.cpp
--- a/source/Lib/TLibEncoder/TEncTop.cpp	Tue Sep 10 11:16:15 2013 +0530
+++ b/source/Lib/TLibEncoder/TEncTop.cpp	Tue Sep 10 16:48:39 2013 +0530
@@ -550,7 +550,7 @@
     UInt numRBSPBytes = 0;
     for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++)
     {
-        UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size());
+		UInt numRBSPBytes_nal = UInt((*it)->m_packetSize);
 #if VERBOSE_RATE
         printf("*** %6s numBytesInNALunit: %u\n", nalUnitTypeToString((*it)->m_nalUnitType), numRBSPBytes_nal);
 #endif
diff -r ab77d80491d8 -r 37a8c6d9cea8 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Tue Sep 10 11:16:15 2013 +0530
+++ b/source/encoder/encoder.cpp	Tue Sep 10 16:48:39 2013 +0530
@@ -348,7 +348,7 @@
         for (AccessUnit::const_iterator t = au.begin(); t != au.end(); t++)
         {
             const NALUnitEBSP& temp = **t;
-            memsize += (long)temp.m_nalUnitData.str().size() + 4;
+            memsize += (long)temp.m_packetSize + 4;
             nalcount++;
         }
 
@@ -389,8 +389,8 @@
                 size += 3;
             }
             memsize += size;
-            size_t nalSize = nalu.m_nalUnitData.str().size();
-            ::memcpy(encoder->m_packetData + memsize, nalu.m_nalUnitData.str().c_str(), nalSize);
+            size_t nalSize = nalu.m_packetSize;
+            ::memcpy(encoder->m_packetData + memsize, nalu.m_nalUnitData, nalSize);
             size += (int)nalSize;
             memsize += (int)nalSize;
 
@@ -429,7 +429,7 @@
         for (AccessUnit::const_iterator t = au.begin(); t != au.end(); t++)
         {
             const NALUnitEBSP& temp = **t;
-            memsize += (long)temp.m_nalUnitData.str().size() + 4;
+            memsize += (long)temp.m_packetSize + 4;
             nalcount++;
         }
 
@@ -470,8 +470,8 @@
                 size += 3;
             }
             memsize += size;
-            size_t nalSize = nalu.m_nalUnitData.str().size();
-            ::memcpy(encoder->m_packetData + memsize, nalu.m_nalUnitData.str().c_str(), nalSize);
+            size_t nalSize = nalu.m_packetSize;
+            ::memcpy(encoder->m_packetData + memsize, nalu.m_nalUnitData, nalSize);
             size += (int)nalSize;
             memsize += (int)nalSize;
 
@@ -490,6 +490,7 @@
 
         *pp_nal = &encoder->m_nals[0];
         if (pi_nal) *pi_nal =(int) nalcount;
+         
     }
     else if (pi_nal)
         *pi_nal = 0;


More information about the x265-devel mailing list