[x265] [PATCH] Encoder: Removed STL Container Classes and Replaced with Non STL Classes
Gopu Govindaswamy
gopu at multicorewareinc.com
Wed Sep 4 12:20:36 CEST 2013
# HG changeset patch
# User Gopu Govindaswamy <gopu at multicorewareinc.com>
# Date 1378290027 -19800
# Node ID c35e5d8148f07bd13297cc7daa0c9b4f9e288f6a
# Parent 06862133aeccae74f24b792e1df45e81188f6d0e
Encoder: Removed STL Container Classes and Replaced with Non STL Classes
diff -r 06862133aecc -r c35e5d8148f0 source/Lib/TLibCommon/CommonDef.h
--- a/source/Lib/TLibCommon/CommonDef.h Wed Sep 04 13:25:03 2013 +0530
+++ b/source/Lib/TLibCommon/CommonDef.h Wed Sep 04 15:50:27 2013 +0530
@@ -148,10 +148,12 @@
// for use in HM, replaces old xMalloc/xFree macros
#define X265_MALLOC(type, count) x265_malloc(sizeof(type) * (count))
#define X265_FREE(ptr) x265_free(ptr)
+#define X265_REALLOC(Address, type, count) x265_realloc(Address, sizeof(type) * (count))
// new code can use these functions directly
extern void x265_free(void *);
extern void *x265_malloc(size_t size);
+extern void *x265_realloc(void *, size_t size);
// ====================================================================================================================
// Coding tool configuration
diff -r 06862133aecc -r c35e5d8148f0 source/common/common.cpp
--- a/source/common/common.cpp Wed Sep 04 13:25:03 2013 +0530
+++ b/source/common/common.cpp Wed Sep 04 15:50:27 2013 +0530
@@ -61,6 +61,11 @@
return _aligned_malloc(size, ALIGNBYTES);
}
+void *x265_realloc(void *startAddr, size_t size)
+{
+ return _aligned_realloc(startAddr,size, ALIGNBYTES);
+}
+
void x265_free(void *ptr)
{
if (ptr) _aligned_free(ptr);
@@ -88,27 +93,27 @@
{
if (level > param->logLevel)
return;
- std::string log_level;
+ char log_level[25];
switch (level)
{
case X265_LOG_ERROR:
- log_level = "error";
+ strcpy(log_level,"error");
break;
case X265_LOG_WARNING:
- log_level = "warning";
+ strcpy(log_level, "warning");
break;
case X265_LOG_INFO:
- log_level = "info";
+ strcpy(log_level, "info");
break;
case X265_LOG_DEBUG:
- log_level = "debug";
+ strcpy(log_level, "debug");
break;
default:
- log_level = "unknown";
+ strcpy(log_level, "unknown");
break;
}
- fprintf(stderr, "x265 [%s]: ", log_level.c_str());
+ fprintf(stderr, "x265 [%s]: ", log_level);
va_list arg;
va_start(arg, fmt);
vfprintf(stderr, fmt, arg);
diff -r 06862133aecc -r c35e5d8148f0 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp Wed Sep 04 13:25:03 2013 +0530
+++ b/source/encoder/encoder.cpp Wed Sep 04 15:50:27 2013 +0530
@@ -40,18 +40,28 @@
struct x265_t : public TEncTop
{
x265_t();
+ ~x265_t();
- std::vector<x265_nal_t> m_nals;
- std::string m_packetData;
-
+ x265_nal_t *m_nals;
+ char *m_packetData;
+
void configure(x265_param_t *param);
void determineLevelAndProfile(x265_param_t *param);
};
x265_t::x265_t()
{
- m_packetData.reserve(4096);
- m_nals.reserve(4);
+ m_nals = (x265_nal_t *) X265_MALLOC(x265_nal_t, 1);
+ m_packetData = (char *) X265_MALLOC(char, 1);
+}
+
+x265_t::~x265_t()
+{
+ if (m_packetData)
+ X265_FREE(m_packetData);
+
+ if(m_nals)
+ X265_FREE(m_nals);
}
void x265_t::determineLevelAndProfile(x265_param_t *_param)
@@ -324,10 +334,20 @@
AccessUnit au;
if (encoder->getStreamHeaders(au) == 0)
- {
- encoder->m_nals.clear();
- encoder->m_packetData.clear();
-
+ {
+ int memsize = 0;
+ int nalcount = 0;
+ for (AccessUnit::const_iterator t = au.begin(); t != au.end(); t++)
+ {
+ const NALUnitEBSP& temp = **t;
+ memsize += (int) temp.m_nalUnitData.str().size();
+ nalcount++;
+ }
+ encoder->m_packetData = (char *) X265_REALLOC(encoder->m_packetData, char, memsize);
+ encoder->m_nals = (x265_nal_t *) X265_REALLOC(encoder->m_nals, x265_nal_t, nalcount);
+ nalcount = 0;
+ memsize = 0;
+
/* Copy NAL output packets into x265_nal_t structures */
for (AccessUnit::const_iterator it = au.begin(); it != au.end(); it++)
{
@@ -345,35 +365,34 @@
* unit of an access unit in decoding order, as specified by subclause
* 7.4.1.2.3.
*/
- encoder->m_packetData.append(start_code_prefix, 4);
+ ::memcpy(encoder->m_packetData + memsize, start_code_prefix, 4);
size += 4;
}
else
{
- encoder->m_packetData.append(start_code_prefix + 1, 3);
+ ::memcpy(encoder->m_packetData + memsize, start_code_prefix + 1, 3);
size += 3;
}
+ memsize += size;
size_t nalSize = nalu.m_nalUnitData.str().size();
- encoder->m_packetData.append(nalu.m_nalUnitData.str().c_str(), nalSize);
- size += (int)nalSize;
+ ::memcpy(encoder->m_packetData + memsize, nalu.m_nalUnitData.str().c_str(), nalSize);
+ size += (int)nalSize;
+ memsize += (int)nalSize;
- x265_nal_t nal;
- nal.i_type = nalu.m_nalUnitType;
- nal.i_payload = size;
- encoder->m_nals.push_back(nal);
+ encoder->m_nals[nalcount].i_type = nalu.m_nalUnitType;
+ encoder->m_nals[nalcount].i_payload = size;
+ nalcount++;
}
-
- /* Setup payload pointers, now that we're done adding content to m_packetData */
+
size_t offset = 0;
- for (size_t i = 0; i < encoder->m_nals.size(); i++)
+ for (size_t i = 0; i < (size_t)nalcount; i++)
{
- x265_nal_t& nal = encoder->m_nals[i];
- nal.p_payload = (uint8_t*)encoder->m_packetData.c_str() + offset;
- offset += nal.i_payload;
+ encoder->m_nals[i].p_payload = (uint8_t*)encoder->m_packetData + offset;
+ offset += encoder->m_nals[i].i_payload;
}
*pp_nal = &encoder->m_nals[0];
- if (pi_nal) *pi_nal = (int)encoder->m_nals.size();
+ if (pi_nal) *pi_nal = nalcount;
return 0;
}
else
@@ -388,9 +407,21 @@
int numEncoded = encoder->encode(!pic_in, pic_in, pic_out, au);
if (pp_nal && numEncoded)
{
- encoder->m_nals.clear();
- encoder->m_packetData.clear();
+ int memsize = 0;
+ int nalcount = 0;
+
+ for (AccessUnit::const_iterator t = au.begin(); t != au.end(); t++)
+ {
+ const NALUnitEBSP& temp = **t;
+ memsize += (int) temp.m_nalUnitData.str().size();
+ nalcount++;
+ }
+ encoder->m_packetData = (char *) X265_REALLOC(encoder->m_packetData, char, memsize);
+ encoder->m_nals = (x265_nal_t *) X265_REALLOC(encoder->m_nals, x265_nal_t, nalcount);
+ nalcount = 0;
+ memsize = 0;
+
/* Copy NAL output packets into x265_nal_t structures */
for (AccessUnit::const_iterator it = au.begin(); it != au.end(); it++)
{
@@ -408,35 +439,34 @@
* unit of an access unit in decoding order, as specified by subclause
* 7.4.1.2.3.
*/
- encoder->m_packetData.append(start_code_prefix, 4);
+ ::memcpy(encoder->m_packetData + memsize, start_code_prefix, 4);
size += 4;
}
else
{
- encoder->m_packetData.append(start_code_prefix + 1, 3);
+ ::memcpy(encoder->m_packetData + memsize, start_code_prefix + 1, 3);
size += 3;
}
+ memsize += size;
size_t nalSize = nalu.m_nalUnitData.str().size();
- encoder->m_packetData.append(nalu.m_nalUnitData.str().c_str(), nalSize);
+ ::memcpy(encoder->m_packetData + memsize, nalu.m_nalUnitData.str().c_str(), nalSize);
size += (int)nalSize;
+ memsize += (int)nalSize;
- x265_nal_t nal;
- nal.i_type = nalu.m_nalUnitType;
- nal.i_payload = size;
- encoder->m_nals.push_back(nal);
+ encoder->m_nals[nalcount].i_type = nalu.m_nalUnitType;
+ encoder->m_nals[nalcount].i_payload = size;
+ nalcount++;
}
-
- /* Setup payload pointers, now that we're done adding content to m_packetData */
+
size_t offset = 0;
- for (size_t i = 0; i < encoder->m_nals.size(); i++)
+ for (size_t i = 0; i < (size_t) nalcount; i++)
{
- x265_nal_t& nal = encoder->m_nals[i];
- nal.p_payload = (uint8_t*)encoder->m_packetData.c_str() + offset;
- offset += nal.i_payload;
+ encoder->m_nals[i].p_payload = (uint8_t*)encoder->m_packetData + offset;
+ offset += encoder->m_nals[i].i_payload;
}
-
+
*pp_nal = &encoder->m_nals[0];
- if (pi_nal) *pi_nal = (int)encoder->m_nals.size();
+ if (pi_nal) *pi_nal = nalcount;
}
else if (pi_nal)
*pi_nal = 0;
diff -r 06862133aecc -r c35e5d8148f0 source/x265.cpp
--- a/source/x265.cpp Wed Sep 04 13:25:03 2013 +0530
+++ b/source/x265.cpp Wed Sep 04 15:50:27 2013 +0530
@@ -210,27 +210,27 @@
{
if (i_level > cli_log_level)
return;
- std::string s_level;
+ char s_level[25];
switch (i_level)
{
case X265_LOG_ERROR:
- s_level = "error";
+ strcpy(s_level, "error");
break;
case X265_LOG_WARNING:
- s_level = "warning";
+ strcpy(s_level, "warning");
break;
case X265_LOG_INFO:
- s_level = "info";
+ strcpy(s_level, "info");
break;
case X265_LOG_DEBUG:
- s_level = "debug";
+ strcpy(s_level, "debug");
break;
default:
- s_level = "unknown";
+ strcpy(s_level, "unknown");
break;
}
- fprintf(stderr, "x265 [%s]: ", s_level.c_str());
+ fprintf(stderr, "x265 [%s]: ", s_level);
va_list arg;
va_start(arg, fmt);
vfprintf(stderr, fmt, arg);
More information about the x265-devel
mailing list