<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Sep 24, 2013 at 5:26 PM, Gopu Govindaswamy <span dir="ltr"><<a href="mailto:gopu@multicorewareinc.com" target="_blank">gopu@multicorewareinc.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Gopu Govindaswamy <<a href="mailto:gopu@multicorewareinc.com">gopu@multicorewareinc.com</a>><br>
# Date 1380019510 -19800<br>
# Node ID 70ba2b3b7bc972ed04f5fd135d940e4759315fa8<br>
# Parent a8f6f62217d5e519f99a004c420e5906ac900f2f<br>
Encoder: do not use std::list for the class AccessUnit<br>
<br>
diff -r a8f6f62217d5 -r 70ba2b3b7bc9 source/Lib/TLibEncoder/TEncTop.cpp<br>
--- a/source/Lib/TLibEncoder/TEncTop.cpp Tue Sep 24 14:22:02 2013 +0530<br>
+++ b/source/Lib/TLibEncoder/TEncTop.cpp Tue Sep 24 16:15:10 2013 +0530<br>
@@ -114,14 +114,16 @@<br>
for (int i = 0; i < param.frameNumThreads; i++)<br>
{<br>
// Ensure frame encoder is idle before destroying it<br>
- AccessUnit tmp;<br>
- m_frameEncoder[i].getEncodedPicture(tmp);<br>
- for (AccessUnit::const_iterator it = tmp.begin(); it != tmp.end(); it++)<br>
+ NALUnitEBSP **nalunits = NULL;<br>
+ m_frameEncoder[i].getEncodedPicture(nalunits);<br>
+ if (nalunits)<br>
{<br>
- const NALUnitEBSP& nalu = **it;<br>
- free(nalu.m_nalUnitData);<br>
+ for (int nalcount = 0; nalunits[nalcount] != NULL; nalcount++)<br>
+ {<br>
+ const NALUnitEBSP& nalu = *nalunits[nalcount];<br>
+ free(nalu.m_nalUnitData);<br>
+ }<br>
}<br>
-<br>
m_frameEncoder[i].destroy();<br>
}<br>
<br>
@@ -161,9 +163,9 @@<br>
}<br>
}<br>
<br>
-int TEncTop::getStreamHeaders(AccessUnit& accessUnit)<br>
+int TEncTop::getStreamHeaders(NALUnitEBSP **nalunits)<br>
{<br>
- return m_frameEncoder->getStreamHeaders(accessUnit);<br>
+ return m_frameEncoder->getStreamHeaders(nalunits);<br>
}<br>
<br>
/**<br>
@@ -173,7 +175,7 @@<br>
\param accessUnitsOut output bitstream<br>
\retval number of encoded pictures<br>
*/<br>
-int TEncTop::encode(bool flush, const x265_picture_t* pic_in, x265_picture_t *pic_out, AccessUnit& accessUnitOut)<br>
+int TEncTop::encode(bool flush, const x265_picture_t* pic_in, x265_picture_t *pic_out, NALUnitEBSP **nalunits)<br>
{<br>
if (pic_in)<br>
{<br>
@@ -213,7 +215,7 @@<br>
// getEncodedPicture() should block until the FrameEncoder has completed<br>
// encoding the frame. This is how back-pressure through the API is<br>
// accomplished when the encoder is full.<br>
- TComPic *out = curEncoder->getEncodedPicture(accessUnitOut);<br>
+ TComPic *out = curEncoder->getEncodedPicture(nalunits);<br>
<br>
if (!out && flush)<br>
{<br>
@@ -227,7 +229,7 @@<br>
{<br>
curEncoder = &m_frameEncoder[m_curEncoder];<br>
m_curEncoder = (m_curEncoder + 1) % param.frameNumThreads;<br>
- out = curEncoder->getEncodedPicture(accessUnitOut);<br>
+ out = curEncoder->getEncodedPicture(nalunits);<br>
}<br>
while (!out && flushed != m_curEncoder);<br>
}<br>
@@ -259,7 +261,7 @@<br>
pic_out->stride[2] = recpic->getCStride();<br>
}<br>
<br>
- double bits = calculateHashAndPSNR(out, accessUnitOut);<br>
+ double bits = calculateHashAndPSNR(out, nalunits);<br>
// Allow this frame to be recycled if no frame encoders are using it for reference<br>
ATOMIC_DEC(&out->m_countRefEncoders);<br>
<br>
@@ -487,7 +489,7 @@<br>
<br>
/* Returns Number of bits in current encoded pic */<br>
<br>
-double TEncTop::calculateHashAndPSNR(TComPic* pic, AccessUnit& accessUnit)<br>
+double TEncTop::calculateHashAndPSNR(TComPic* pic, NALUnitEBSP **nalunits)<br>
{<br>
TComPicYuv* recon = pic->getPicYuvRec();<br>
TComPicYuv* orig = pic->getPicYuvOrg();<br>
@@ -544,7 +546,10 @@<br>
m_frameEncoder->m_seiWriter.writeSEImessage(onalu.m_Bitstream, sei_recon_picture_digest, pic->getSlice()->getSPS());<br>
writeRBSPTrailingBits(onalu.m_Bitstream);<br>
<br>
- accessUnit.insert(accessUnit.end(), new NALUnitEBSP(onalu));<br>
+ int count = 0;<br>
+ while(nalunits[count] != NULL)<br>
+ count++;<br>
+ nalunits[count]->init(onalu);<br>
}<br></blockquote><div><br></div><div>Isn't nalunits[count] supposed to be initalized , if its null - before calling its init() ?</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
/* calculate the size of the access unit, excluding:<br>
@@ -552,13 +557,14 @@<br>
* - SEI NAL units<br>
*/<br>
UInt numRBSPBytes = 0;<br>
- for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++)<br>
+ int count = 0;<br>
+ for (;nalunits[count] != NULL; count++)<br>
{<br>
- UInt numRBSPBytes_nal = (*it)->m_packetSize;<br>
+ UInt numRBSPBytes_nal = nalunits[count]->m_packetSize;<br>
#if VERBOSE_RATE<br>
printf("*** %6s numBytesInNALunit: %u\n", nalUnitTypeToString((*it)->m_nalUnitType), numRBSPBytes_nal);<br>
#endif<br>
- if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)<br>
+ if (nalunits[count]->m_nalUnitType != NAL_UNIT_PREFIX_SEI && nalunits[count]->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)<br>
{<br>
numRBSPBytes += numRBSPBytes_nal;<br>
}<br>
diff -r a8f6f62217d5 -r 70ba2b3b7bc9 source/Lib/TLibEncoder/TEncTop.h<br>
--- a/source/Lib/TLibEncoder/TEncTop.h Tue Sep 24 14:22:02 2013 +0530<br>
+++ b/source/Lib/TLibEncoder/TEncTop.h Tue Sep 24 16:15:10 2013 +0530<br>
@@ -101,9 +101,9 @@<br>
void xInitSPS(TComSPS *sps);<br>
void xInitPPS(TComPPS *pps);<br>
<br>
- int encode(bool bEos, const x265_picture_t* pic, x265_picture_t *pic_out, AccessUnit& accessUnit);<br>
+ int encode(bool bEos, const x265_picture_t* pic, x265_picture_t *pic_out, NALUnitEBSP **nalunits);<br>
<br>
- int getStreamHeaders(AccessUnit& accessUnit);<br>
+ int getStreamHeaders(NALUnitEBSP **nalunits);<br>
<br>
double printSummary();<br>
<br>
@@ -113,7 +113,7 @@<br>
<br>
protected:<br>
<br>
- double calculateHashAndPSNR(TComPic* pic, AccessUnit&); // Returns total number of bits for encoded pic<br>
+ double calculateHashAndPSNR(TComPic* pic, NALUnitEBSP **nalunits); // Returns total number of bits for encoded pic<br>
};<br>
}<br>
//! \}<br>
diff -r a8f6f62217d5 -r 70ba2b3b7bc9 source/encoder/encoder.cpp<br>
--- a/source/encoder/encoder.cpp Tue Sep 24 14:22:02 2013 +0530<br>
+++ b/source/encoder/encoder.cpp Tue Sep 24 16:15:10 2013 +0530<br>
@@ -47,7 +47,7 @@<br>
<br>
void configure(x265_param_t *param);<br>
void determineLevelAndProfile(x265_param_t *param);<br>
- int extract_naldata(AccessUnit &au, size_t &nalcount);<br>
+ int extract_naldata(NALUnitEBSP **nalunits, size_t &nalcount);<br>
};<br>
<br>
x265_t::x265_t()<br>
@@ -364,19 +364,18 @@<br>
if (!pp_nal)<br>
return 0;<br>
<br>
- AccessUnit au;<br>
- if (!encoder->getStreamHeaders(au))<br>
+ NALUnitEBSP *nalunits[5] = {0, 0, 0, 0, 0};<br>
+ if (!encoder->getStreamHeaders(nalunits))<br>
{<br>
size_t nalcount;<br>
- if (!encoder->extract_naldata(au, nalcount))<br>
+ if (!encoder->extract_naldata(nalunits, nalcount))<br>
{<br>
*pp_nal = &encoder->m_nals[0];<br>
if (pi_nal) *pi_nal = (int)nalcount;<br>
- for (AccessUnit::const_iterator t = au.begin(); t != au.end(); t++)<br>
+ for (nalcount = 0; nalcount < MAX_NAL_UNITS; nalcount++)<br>
{<br>
- X265_FREE(*t);<br>
+ X265_FREE(nalunits[nalcount]);<br>
}<br>
- au.clear();<br>
return 0;<br>
}<br>
return -1;<br>
@@ -388,17 +387,21 @@<br>
extern "C"<br>
int x265_encoder_encode(x265_t *encoder, x265_nal_t **pp_nal, int *pi_nal, x265_picture_t *pic_in, x265_picture_t *pic_out)<br>
{<br>
- AccessUnit au;<br>
-<br>
- int numEncoded = encoder->encode(!pic_in, pic_in, pic_out, au);<br>
+ NALUnitEBSP *nalunits[5] = {0, 0, 0, 0, 0};<br>
+ int numEncoded = encoder->encode(!pic_in, pic_in, pic_out, nalunits);<br>
<br>
if (pp_nal && numEncoded)<br>
{<br>
size_t nalcount;<br>
- encoder->extract_naldata(au, nalcount);<br>
+ encoder->extract_naldata(nalunits, nalcount);<br>
<br>
*pp_nal = &encoder->m_nals[0];<br>
if (pi_nal) *pi_nal =(int) nalcount;<br>
+<br>
+ for (nalcount = 0; nalcount < MAX_NAL_UNITS; nalcount++)<br>
+ {<br>
+ X265_FREE(nalunits[nalcount]);<br>
+ }<br>
}<br>
else if (pi_nal)<br>
*pi_nal = 0;<br>
@@ -428,19 +431,18 @@<br>
BitCost::destroy();<br>
}<br>
<br>
-int x265_t::extract_naldata(AccessUnit &au, size_t &nalcount)<br>
+int x265_t::extract_naldata(NALUnitEBSP **nalunits, size_t &nalcount)<br>
{<br>
uint32_t memsize = 0;<br>
uint32_t offset = 0;<br>
<br>
nalcount = 0;<br>
- for (AccessUnit::const_iterator t = au.begin(); t != au.end(); t++)<br>
+ for (; nalunits[nalcount] != NULL; nalcount++)<br>
{<br>
- const NALUnitEBSP& temp = **t;<br>
+ const NALUnitEBSP& temp = *nalunits[nalcount];<br>
memsize += temp.m_packetSize + 4;<br>
- nalcount++;<br>
}<br>
-<br>
+<br>
X265_FREE(m_packetData);<br>
X265_FREE(m_nals);<br>
CHECKED_MALLOC(m_packetData, char, memsize);<br>
@@ -450,13 +452,13 @@<br>
memsize = 0;<br>
<br>
/* Copy NAL output packets into x265_nal_t structures */<br>
- for (AccessUnit::const_iterator it = au.begin(); it != au.end(); it++)<br>
+ for (; nalunits[nalcount] != NULL; nalcount++)<br>
{<br>
- const NALUnitEBSP& nalu = **it;<br>
+ const NALUnitEBSP& nalu = *nalunits[nalcount];<br>
uint32_t size = 0; /* size of annexB unit in bytes */<br>
<br>
static const char start_code_prefix[] = { 0, 0, 0, 1 };<br>
- if (it == au.begin() || nalu.m_nalUnitType == NAL_UNIT_SPS || nalu.m_nalUnitType == NAL_UNIT_PPS)<br>
+ if (nalcount == 0 || nalu.m_nalUnitType == NAL_UNIT_SPS || nalu.m_nalUnitType == NAL_UNIT_PPS)<br>
{<br>
/* From AVC, When any of the following conditions are fulfilled, the<br>
* zero_byte syntax element shall be present:<br>
@@ -482,7 +484,6 @@<br>
<br>
m_nals[nalcount].i_type = nalu.m_nalUnitType;<br>
m_nals[nalcount].i_payload = size;<br>
- nalcount++;<br>
free(nalu.m_nalUnitData);<br>
}<br>
<br>
diff -r a8f6f62217d5 -r 70ba2b3b7bc9 source/encoder/frameencoder.cpp<br>
--- a/source/encoder/frameencoder.cpp Tue Sep 24 14:22:02 2013 +0530<br>
+++ b/source/encoder/frameencoder.cpp Tue Sep 24 16:15:10 2013 +0530<br>
@@ -55,7 +55,11 @@<br>
, m_cfg(NULL)<br>
, m_pic(NULL)<br>
, m_rows(NULL)<br>
-{}<br>
+{<br>
+ for (int i = 0; i < 5; i++)<br>
+ m_accessUnit[i] = NULL;<br>
+ m_nalcount = 0;<br>
+}<br>
<br>
void FrameEncoder::setThreadPool(ThreadPool *p)<br>
{<br>
@@ -158,12 +162,11 @@<br>
start();<br>
}<br>
<br>
-int FrameEncoder::getStreamHeaders(AccessUnit& accessUnit)<br>
+int FrameEncoder::getStreamHeaders(NALUnitEBSP **nalunits)<br>
{<br>
TEncEntropy* entropyCoder = getEntropyCoder(0);<br>
<br>
entropyCoder->setEntropyCoder(&m_cavlcCoder, NULL);<br>
- NALUnitEBSP *tmp[MAX_NAL_UNITS] = {0, 0, 0, 0, 0};<br>
int count = 0;<br>
<br>
/* headers for start of bitstream */<br>
@@ -171,27 +174,24 @@<br>
entropyCoder->setBitstream(&nalu.m_Bitstream);<br>
entropyCoder->encodeVPS(m_cfg->getVPS());<br>
writeRBSPTrailingBits(nalu.m_Bitstream);<br>
- CHECKED_MALLOC(tmp[count], NALUnitEBSP, 1);<br>
- tmp[count]->init(nalu);<br>
- accessUnit.push_back(tmp[count]);<br>
+ CHECKED_MALLOC(nalunits[count], NALUnitEBSP, 1);<br>
+ nalunits[count]->init(nalu);<br>
count++;<br>
<br>
nalu = NALUnit(NAL_UNIT_SPS);<br>
entropyCoder->setBitstream(&nalu.m_Bitstream);<br>
entropyCoder->encodeSPS(&m_sps);<br>
writeRBSPTrailingBits(nalu.m_Bitstream);<br>
- CHECKED_MALLOC(tmp[count], NALUnitEBSP, 1);<br>
- tmp[count]->init(nalu);<br>
- accessUnit.push_back(tmp[count]);<br>
+ CHECKED_MALLOC(nalunits[count], NALUnitEBSP, 1);<br>
+ nalunits[count]->init(nalu);<br>
count++;<br>
<br>
nalu = NALUnit(NAL_UNIT_PPS);<br>
entropyCoder->setBitstream(&nalu.m_Bitstream);<br>
entropyCoder->encodePPS(&m_pps);<br>
writeRBSPTrailingBits(nalu.m_Bitstream);<br>
- CHECKED_MALLOC(tmp[count], NALUnitEBSP, 1);<br>
- tmp[count]->init(nalu);<br>
- accessUnit.push_back(tmp[count]);<br>
+ CHECKED_MALLOC(nalunits[count], NALUnitEBSP, 1);<br>
+ nalunits[count]->init(nalu);<br>
count++;<br>
<br>
if (m_cfg->getActiveParameterSetsSEIEnabled())<br>
@@ -206,9 +206,8 @@<br>
entropyCoder->setBitstream(&nalu.m_Bitstream);<br>
m_seiWriter.writeSEImessage(nalu.m_Bitstream, sei, &m_sps);<br>
writeRBSPTrailingBits(nalu.m_Bitstream);<br>
- CHECKED_MALLOC(tmp[count], NALUnitEBSP, 1);<br>
- tmp[count]->init(nalu);<br>
- accessUnit.push_back(tmp[count]);<br>
+ CHECKED_MALLOC(nalunits[count], NALUnitEBSP, 1);<br>
+ nalunits[count]->init(nalu);<br>
count++;<br>
}<br>
<br>
@@ -224,9 +223,8 @@<br>
entropyCoder->setBitstream(&nalu.m_Bitstream);<br>
m_seiWriter.writeSEImessage(nalu.m_Bitstream, sei, &m_sps);<br>
writeRBSPTrailingBits(nalu.m_Bitstream);<br>
- CHECKED_MALLOC(tmp[count], NALUnitEBSP, 1);<br>
- tmp[count]->init(nalu);<br>
- accessUnit.push_back(tmp[count]);<br>
+ CHECKED_MALLOC(nalunits[count], NALUnitEBSP, 1);<br>
+ nalunits[count]->init(nalu);<br>
}<br>
return 0;<br>
<br>
@@ -294,7 +292,7 @@<br>
void FrameEncoder::compressFrame()<br>
{<br>
PPAScopeEvent(FrameEncoder_compressFrame);<br>
-<br>
+ m_nalcount = 0;<br>
TEncEntropy* entropyCoder = getEntropyCoder(0);<br>
TComSlice* slice = m_pic->getSlice();<br>
<br>
@@ -476,7 +474,7 @@<br>
}<br>
<br>
m_wp.xRestoreWPparam(slice);<br>
-<br>
+ OutputNALUnit nalu(slice->getNalUnitType(), 0);<br>
if ((m_cfg->getRecoveryPointSEIEnabled()) && (slice->getSliceType() == I_SLICE))<br>
{<br>
if (m_cfg->getGradualDecodingRefreshInfoEnabled() && !slice->getRapPicFlag())<br>
@@ -489,7 +487,9 @@<br>
<br>
m_seiWriter.writeSEImessage(nalu.m_Bitstream, seiGradualDecodingRefreshInfo, slice->getSPS());<br>
writeRBSPTrailingBits(nalu.m_Bitstream);<br>
- m_accessUnit.push_back(new NALUnitEBSP(nalu));<br>
+ CHECKED_MALLOC(m_accessUnit[m_nalcount], NALUnitEBSP, 1);<br>
+ m_accessUnit[m_nalcount]->init(nalu);<br>
+ m_nalcount++;<br>
}<br>
// Recovery point SEI<br>
OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI);<br>
@@ -501,7 +501,9 @@<br>
<br>
m_seiWriter.writeSEImessage(nalu.m_Bitstream, sei_recovery_point, slice->getSPS());<br>
writeRBSPTrailingBits(nalu.m_Bitstream);<br>
- m_accessUnit.push_back(new NALUnitEBSP(nalu));<br>
+ CHECKED_MALLOC(m_accessUnit[m_nalcount], NALUnitEBSP, 1);<br>
+ m_accessUnit[m_nalcount]->init(nalu);<br>
+ m_nalcount++;<br>
}<br>
<br>
/* use the main bitstream buffer for storing the marshaled picture */<br>
@@ -535,7 +537,6 @@<br>
entropyCoder->resetEntropy();<br>
<br>
/* start slice NALunit */<br>
- OutputNALUnit nalu(slice->getNalUnitType(), 0);<br>
bool sliceSegment = !slice->isNextSlice();<br>
entropyCoder->setBitstream(&nalu.m_Bitstream);<br>
entropyCoder->encodeSliceHeader(slice);<br>
@@ -635,8 +636,9 @@<br>
}<br>
entropyCoder->setBitstream(&nalu.m_Bitstream);<br>
bitstreamRedirect->clear();<br>
-<br>
- m_accessUnit.push_back(new NALUnitEBSP(nalu));<br>
+ CHECKED_MALLOC(m_accessUnit[m_nalcount], NALUnitEBSP, 1);<br>
+ m_accessUnit[m_nalcount]->init(nalu);<br>
+ m_nalcount++;<br>
<br>
if (m_sps.getUseSAO())<br>
{<br>
@@ -658,6 +660,8 @@<br>
}<br>
}<br>
<br>
+fail:<br>
+<br>
delete[] outStreams;<br>
delete bitstreamRedirect;<br>
}<br>
@@ -1001,7 +1005,7 @@<br>
}<br>
}<br>
<br>
-TComPic *FrameEncoder::getEncodedPicture(AccessUnit& accessUnit)<br>
+TComPic *FrameEncoder::getEncodedPicture(NALUnitEBSP **nalunits)<br>
{<br>
if (m_pic)<br>
{<br>
@@ -1011,8 +1015,8 @@<br>
TComPic *ret = m_pic;<br>
m_pic = NULL;<br>
<br>
- // move NALs from member variable list to end of user's container<br>
- accessUnit.splice(accessUnit.end(), m_accessUnit);<br>
+ // move NALs from member variable to end of user's container<br>
+ ::memcpy(nalunits, m_accessUnit, sizeof(NALUnitEBSP) * m_nalcount);<br>
return ret;<br>
}<br>
<br>
diff -r a8f6f62217d5 -r 70ba2b3b7bc9 source/encoder/frameencoder.h<br>
--- a/source/encoder/frameencoder.h Tue Sep 24 14:22:02 2013 +0530<br>
+++ b/source/encoder/frameencoder.h Tue Sep 24 16:15:10 2013 +0530<br>
@@ -135,7 +135,7 @@<br>
}<br>
}<br>
<br>
- int getStreamHeaders(AccessUnit& accessUnitOut);<br>
+ int getStreamHeaders(NALUnitEBSP **nalunits);<br>
<br>
void initSlice(TComPic* pic);<br>
<br>
@@ -148,7 +148,7 @@<br>
void encodeSlice(TComOutputBitstream* substreams);<br>
<br>
/* blocks until worker thread is done, returns encoded picture and bitstream */<br>
- TComPic *getEncodedPicture(AccessUnit& accessUnit);<br>
+ TComPic *getEncodedPicture(NALUnitEBSP **nalunits);<br>
<br>
// worker thread<br>
void threadMain();<br>
@@ -178,7 +178,8 @@<br>
<br>
/* Picture being encoded, and its output NAL list */<br>
TComPic* m_pic;<br>
- AccessUnit m_accessUnit;<br>
+ NALUnitEBSP *m_accessUnit[5];<br>
+ int m_nalcount;<br>
<br>
int m_numRows;<br>
int m_filterRowDelay;<br>
_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
</blockquote></div><br></div></div>