[x265] [PATCH RFC ] List Implementation
Gopu Govindaswamy
gopu at multicorewareinc.com
Wed Sep 11 14:02:04 CEST 2013
# HG changeset patch
# User Gopu Govindaswamy <gopu at multicorewareinc.com>
# Date 1378899885 -19800
# Node ID 98ee31af129b524005ff8dba503d46b0a83a598b
# Parent 275f2d5f9b0a782fd3ec36d95268545d96473e2e
List Implementation
diff -r 275f2d5f9b0a -r 98ee31af129b source/Lib/TLibCommon/AccessUnit.h
--- a/source/Lib/TLibCommon/AccessUnit.h Wed Sep 11 12:16:50 2013 +0530
+++ b/source/Lib/TLibCommon/AccessUnit.h Wed Sep 11 17:14:45 2013 +0530
@@ -40,7 +40,8 @@
#define _ACCESS_UNIT_ 1
#include "NAL.h"
-#include <list>
+
+#include "list.h"
namespace x265 {
// private namespace
@@ -60,7 +61,8 @@
* The AccessUnit owns all pointers stored within. Destroying the
* AccessUnit will delete all contained objects.
*/
-class AccessUnit : public std::list<NALUnitEBSP*>
+
+/*class AccessUnit : public std::list<NALUnitEBSP*>
{
public: ~AccessUnit()
{
@@ -69,6 +71,32 @@
delete *it;
}
}
+};*/
+
+class AccessUnitn : public List<NALUnitEBSP*>
+{
+public : ~AccessUnitn()
+ {
+ if(this)
+ {
+ NALUnitEBSP *temp;
+ while(this->head != NULL)
+ {
+ temp = (NALUnitEBSP *) this->head->value;
+
+ printf("%d \n", temp->m_packetSize);
+ if(temp)
+ delete temp;
+
+ this->head = this->head->next;
+ }
+ if(this->head)
+ {
+ temp = (NALUnitEBSP *) this->head->value;
+ delete temp;
+ }
+ }
+ }
};
}
diff -r 275f2d5f9b0a -r 98ee31af129b source/Lib/TLibEncoder/TEncTop.cpp
--- a/source/Lib/TLibEncoder/TEncTop.cpp Wed Sep 11 12:16:50 2013 +0530
+++ b/source/Lib/TLibEncoder/TEncTop.cpp Wed Sep 11 17:14:45 2013 +0530
@@ -113,7 +113,7 @@
for (int i = 0; i < param.frameNumThreads; i++)
{
// Ensure frame encoder is idle before destroying it
- AccessUnit tmp;
+ AccessUnitn tmp;
m_frameEncoder[i].getEncodedPicture(tmp);
m_frameEncoder[i].destroy();
}
@@ -157,7 +157,7 @@
}
}
-int TEncTop::getStreamHeaders(AccessUnit& accessUnit)
+int TEncTop::getStreamHeaders(AccessUnitn& accessUnit)
{
return m_frameEncoder->getStreamHeaders(accessUnit);
}
@@ -169,7 +169,7 @@
\param accessUnitsOut output bitstream
\retval number of encoded pictures
*/
-int TEncTop::encode(bool flush, const x265_picture_t* pic_in, x265_picture_t *pic_out, AccessUnit& accessUnitOut)
+int TEncTop::encode(bool flush, const x265_picture_t* pic_in, x265_picture_t *pic_out, AccessUnitn& accessUnitOut)
{
if (pic_in)
{
@@ -483,7 +483,7 @@
/* Returns Number of bits in current encoded pic */
-double TEncTop::calculateHashAndPSNR(TComPic* pic, AccessUnit& accessUnit)
+double TEncTop::calculateHashAndPSNR(TComPic* pic, AccessUnitn& accessUnit)
{
TComPicYuv* recon = pic->getPicYuvRec();
TComPicYuv* orig = pic->getPicYuvOrg();
@@ -540,14 +540,14 @@
m_frameEncoder->m_seiWriter.writeSEImessage(onalu.m_Bitstream, sei_recon_picture_digest, pic->getSlice()->getSPS());
writeRBSPTrailingBits(onalu.m_Bitstream);
- accessUnit.insert(accessUnit.end(), new NALUnitEBSP(onalu));
+ accessUnit.push_back(new NALUnitEBSP(onalu));
}
/* calculate the size of the access unit, excluding:
* - any AnnexB contributions (start_code_prefix, zero_byte, etc.,)
* - SEI NAL units
*/
- UInt numRBSPBytes = 0;
+ /* UInt numRBSPBytes = 0;
for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++)
{
UInt numRBSPBytes_nal = (*it)->m_packetSize;
@@ -558,7 +558,24 @@
{
numRBSPBytes += numRBSPBytes_nal;
}
- }
+ } */
+
+
+ UInt numRBSPBytes = 0;
+ do
+ {
+ UInt numRBSPBytes_nal = accessUnit.head->value->m_packetSize;
+
+#if VERBOSE_RATE
+ printf("*** %6s numBytesInNALunit: %u\n", nalUnitTypeToString(accessUnit.head->value->m_nalUnitType), numRBSPBytes_nal);
+#endif
+
+ if (accessUnit.head->value->m_nalUnitType != NAL_UNIT_PREFIX_SEI && accessUnit.head->value->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)
+ {
+ numRBSPBytes += numRBSPBytes_nal;
+ }
+
+ }while(accessUnit.head->next != NULL && (accessUnit.head = accessUnit.head->next));
UInt bits = numRBSPBytes * 8;
diff -r 275f2d5f9b0a -r 98ee31af129b source/Lib/TLibEncoder/TEncTop.h
--- a/source/Lib/TLibEncoder/TEncTop.h Wed Sep 11 12:16:50 2013 +0530
+++ b/source/Lib/TLibEncoder/TEncTop.h Wed Sep 11 17:14:45 2013 +0530
@@ -101,9 +101,9 @@
void xInitSPS(TComSPS *sps);
void xInitPPS(TComPPS *pps);
- int encode(bool bEos, const x265_picture_t* pic, x265_picture_t *pic_out, AccessUnit& accessUnit);
+ int encode(bool bEos, const x265_picture_t* pic, x265_picture_t *pic_out, AccessUnitn& accessUnit);
- int getStreamHeaders(AccessUnit& accessUnit);
+ int getStreamHeaders(AccessUnitn& accessUnit);
double printSummary();
@@ -113,7 +113,7 @@
protected:
- double calculateHashAndPSNR(TComPic* pic, AccessUnit&); // Returns total number of bits for encoded pic
+ double calculateHashAndPSNR(TComPic* pic, AccessUnitn&); // Returns total number of bits for encoded pic
};
}
//! \}
diff -r 275f2d5f9b0a -r 98ee31af129b source/common/list.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/source/common/list.h Wed Sep 11 17:14:45 2013 +0530
@@ -0,0 +1,153 @@
+#include "common.h"
+
+template <class T>
+class List
+{
+private:
+
+ struct Node
+ {
+ T value;
+ Node * next;
+ Node(T value1, Node * next1 = NULL)
+ {
+ value = value1;
+ next = next1;
+ }
+ };
+
+public:
+
+ Node* head;
+ T size;
+
+ List()
+ {
+ head = 0;
+ size = 0;
+ }
+
+ T getSize() { return size; }
+
+ inline bool isEmpty()
+ {
+ if(head == NULL)
+ return true;
+ else
+ return false;
+ }
+
+ inline T* begin() { return head };
+
+ inline T* end()
+ {
+ while( head->next != NULL)
+ {
+ head = head->next;
+ }
+ return head;
+ }
+
+ inline void push_back(T value)
+ {
+ if (head == NULL)
+ head = new Node(value);
+ else
+ {
+ Node * nodePtr = head;
+ while (nodePtr->next != NULL)
+ nodePtr = nodePtr->next;
+
+ nodePtr->next = new Node(value);
+ }
+ size += 1;
+ }
+
+ inline void push_front(T value)
+ {
+ if (head == NULL)
+ head = new Node(value);
+ else
+ {
+ Node *nodeptr;
+ nodeptr = new Node(value);
+ nodeptr->next = head;
+ head = nodeptr;
+ }
+ size += 1;
+ }
+
+ inline void pop_front()
+ {
+ if(head != NULL)
+ {
+ if(head->next == NULL)
+ delete head;
+ else
+ {
+ Node *temp = head->next;
+ delete head;
+ head = temp;
+ }
+
+ size -= 1;
+ }
+ }
+
+ inline void pop_back()
+ {
+ if (head != NULL)
+ {
+ if(head->next == NULL)
+ delete head;
+ else
+ {
+ Node *ptr = head, *ptr1;
+ while(ptr->next != NULL)
+ {
+ ptr1 = ptr;
+ ptr = ptr->next;
+ }
+ delete ptr1->next;
+ ptr1->next = NULL;
+ }
+ size -= 1;
+ }
+ }
+
+ inline void pus_at_position(T value, int pos)
+ {
+ if (head == NULL)
+ head = new Node(value);
+ {
+ int offset = 0;
+ Node *ptr, *temp;
+ temp = head;
+ while(temp->next != NULL)
+ {
+ if(offset == pos-2)
+ {
+ ptr = new Node(value);
+ ptr->next = temp->next;
+ temp->next = ptr;
+ size += 1;
+ break;
+ }
+ temp = temp->next;
+ offset++;
+ }
+ }
+ }
+
+ inline void remove_all()
+ {
+ Node *temp = head;
+ Node *rm;
+ while(temp->next != NULL)
+ {
+ rm = temp->next;
+ delete temp;
+ temp = rm;
+ }
+ }
+};
\ No newline at end of file
diff -r 275f2d5f9b0a -r 98ee31af129b source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp Wed Sep 11 12:16:50 2013 +0530
+++ b/source/encoder/encoder.cpp Wed Sep 11 17:14:45 2013 +0530
@@ -340,65 +340,71 @@
if (!pp_nal)
return 0;
- AccessUnit au;
+ AccessUnitn au, tmp;
if (encoder->getStreamHeaders(au) == 0)
{
UInt memsize = 0;
int nalcount = 0;
- for (AccessUnit::const_iterator t = au.begin(); t != au.end(); t++)
- {
- const NALUnitEBSP& temp = **t;
- memsize += temp.m_packetSize + 4;
- nalcount++;
- }
- if (encoder->m_packetData)
- X265_FREE(encoder->m_packetData);
+ tmp = au;
+ NALUnitEBSP *temp;
+
+ do
+ {
+ temp = (NALUnitEBSP *) tmp.head->value;
+ memsize += temp->m_packetSize + 4;
+ nalcount++;
- if (encoder->m_nals)
- X265_FREE(encoder->m_nals);
+ } while(tmp.head->next != NULL && (tmp.head = tmp.head->next));
- encoder->m_packetData = (char*)X265_MALLOC(char, memsize);
- encoder->m_nals = (x265_nal_t*)X265_MALLOC(x265_nal_t, nalcount);
- nalcount = 0;
- memsize = 0;
+ if (encoder->m_packetData)
+ X265_FREE(encoder->m_packetData);
- /* Copy NAL output packets into x265_nal_t structures */
- for (AccessUnit::const_iterator it = au.begin(); it != au.end(); it++)
- {
- const NALUnitEBSP& nalu = **it;
- int size = 0; /* size of annexB unit in bytes */
-
- static const char start_code_prefix[] = { 0, 0, 0, 1 };
- if (it == au.begin() || nalu.m_nalUnitType == NAL_UNIT_SPS || nalu.m_nalUnitType == NAL_UNIT_PPS)
- {
- /* From AVC, When any of the following conditions are fulfilled, the
- * zero_byte syntax element shall be present:
- * - the nal_unit_type within the nal_unit() is equal to 7 (sequence
- * parameter set) or 8 (picture parameter set),
- * - the byte stream NAL unit syntax structure contains the first NAL
- * unit of an access unit in decoding order, as specified by subclause
- * 7.4.1.2.3.
- */
- ::memcpy(encoder->m_packetData + memsize, start_code_prefix, 4);
- size += 4;
- }
- else
- {
- ::memcpy(encoder->m_packetData + memsize, start_code_prefix + 1, 3);
- size += 3;
- }
- memsize += size;
- size_t nalSize = nalu.m_packetSize;
- ::memcpy(encoder->m_packetData + memsize, nalu.m_nalUnitData, nalSize);
- size += (int)nalSize;
- memsize += (int)nalSize;
+ if (encoder->m_nals)
+ X265_FREE(encoder->m_nals);
- encoder->m_nals[nalcount].i_type = nalu.m_nalUnitType;
- encoder->m_nals[nalcount].i_payload = size;
- nalcount++;
- free(nalu.m_nalUnitData);
- }
+ encoder->m_packetData = (char*)X265_MALLOC(char, memsize);
+ encoder->m_nals = (x265_nal_t*)X265_MALLOC(x265_nal_t, nalcount);
+ nalcount = 0;
+ memsize = 0;
+ tmp = au;
+
+ do
+ {
+ const NALUnitEBSP *nalu = (NALUnitEBSP *) tmp.head->value;
+ int size = 0; /* size of annexB unit in bytes */
+
+ static const char start_code_prefix[] = { 0, 0, 0, 1 };
+ if (nalu->m_nalUnitType == NAL_UNIT_SPS || nalu->m_nalUnitType == NAL_UNIT_PPS || size == 0)
+ {
+ /* From AVC, When any of the following conditions are fulfilled, the
+ * zero_byte syntax element shall be present:
+ * - the nal_unit_type within the nal_unit() is equal to 7 (sequence
+ * parameter set) or 8 (picture parameter set),
+ * - the byte stream NAL unit syntax structure contains the first NAL
+ * unit of an access unit in decoding order, as specified by subclause
+ * 7.4.1.2.3.
+ */
+ ::memcpy(encoder->m_packetData + memsize, start_code_prefix, 4);
+ size += 4;
+ }
+ else
+ {
+ ::memcpy(encoder->m_packetData + memsize, start_code_prefix + 1, 3);
+ size += 3;
+ }
+ memsize += size;
+ size_t nalSize = nalu->m_packetSize;
+ ::memcpy(encoder->m_packetData + memsize, nalu->m_nalUnitData, nalSize);
+ size += (int)nalSize;
+ memsize += (int)nalSize;
+
+ encoder->m_nals[nalcount].i_type = nalu->m_nalUnitType;
+ encoder->m_nals[nalcount].i_payload = size;
+ nalcount++;
+ free(nalu->m_nalUnitData);
+
+ } while (tmp.head->next != NULL && (tmp.head = tmp.head->next));
/* Setup payload pointers, now that we're done adding content to m_packetData */
size_t offset = 0;
@@ -410,6 +416,7 @@
*pp_nal = &encoder->m_nals[0];
if (pi_nal) *pi_nal = (int)nalcount;
+
return 0;
}
else
@@ -419,7 +426,7 @@
extern "C"
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)
{
- AccessUnit au;
+ AccessUnitn au, tmp;
int numEncoded = encoder->encode(!pic_in, pic_in, pic_out, au);
@@ -427,60 +434,66 @@
{
UInt memsize = 0;
int nalcount = 0;
- for (AccessUnit::const_iterator t = au.begin(); t != au.end(); t++)
- {
- const NALUnitEBSP& temp = **t;
- memsize += temp.m_packetSize + 4;
- nalcount++;
- }
- if (encoder->m_nals)
- X265_FREE(encoder->m_nals);
+ tmp = au;
+ NALUnitEBSP *temp;
- if (encoder->m_packetData)
- X265_FREE(encoder->m_packetData);
+ do
+ {
+ temp = (NALUnitEBSP *) tmp.head->value;
+ memsize += temp->m_packetSize + 4;
+ nalcount++;
- encoder->m_packetData = (char*)X265_MALLOC(char, memsize);
- encoder->m_nals = (x265_nal_t*)X265_MALLOC(x265_nal_t, nalcount);
- nalcount = 0;
- memsize = 0;
+ } while(tmp.head->next != NULL && (tmp.head = tmp.head->next));
- /* Copy NAL output packets into x265_nal_t structures */
- for (AccessUnit::const_iterator it = au.begin(); it != au.end(); it++)
- {
- const NALUnitEBSP& nalu = **it;
- int size = 0; /* size of annexB unit in bytes */
-
- static const char start_code_prefix[] = { 0, 0, 0, 1 };
- if (it == au.begin() || nalu.m_nalUnitType == NAL_UNIT_SPS || nalu.m_nalUnitType == NAL_UNIT_PPS)
- {
- /* From AVC, When any of the following conditions are fulfilled, the
- * zero_byte syntax element shall be present:
- * - the nal_unit_type within the nal_unit() is equal to 7 (sequence
- * parameter set) or 8 (picture parameter set),
- * - the byte stream NAL unit syntax structure contains the first NAL
- * unit of an access unit in decoding order, as specified by subclause
- * 7.4.1.2.3.
- */
- ::memcpy(encoder->m_packetData + memsize, start_code_prefix, 4);
- size += 4;
- }
- else
- {
- ::memcpy(encoder->m_packetData + memsize, start_code_prefix + 1, 3);
- size += 3;
- }
- memsize += size;
- size_t nalSize = nalu.m_packetSize;
- ::memcpy(encoder->m_packetData + memsize, nalu.m_nalUnitData, nalSize);
- size += (int)nalSize;
- memsize += (int)nalSize;
+ if (encoder->m_packetData)
+ X265_FREE(encoder->m_packetData);
- encoder->m_nals[nalcount].i_type = nalu.m_nalUnitType;
- encoder->m_nals[nalcount].i_payload = size;
- nalcount++;
- free(nalu.m_nalUnitData);
- }
+ if (encoder->m_nals)
+ X265_FREE(encoder->m_nals);
+
+ encoder->m_packetData = (char*)X265_MALLOC(char, memsize);
+ encoder->m_nals = (x265_nal_t*)X265_MALLOC(x265_nal_t, nalcount);
+ nalcount = 0;
+ memsize = 0;
+ tmp = au;
+
+ do
+ {
+ const NALUnitEBSP *nalu = (NALUnitEBSP *) tmp.head->value;
+ int size = 0; /* size of annexB unit in bytes */
+
+ static const char start_code_prefix[] = { 0, 0, 0, 1 };
+ if (nalu->m_nalUnitType == NAL_UNIT_SPS || nalu->m_nalUnitType == NAL_UNIT_PPS || size == 0)
+ {
+ /* From AVC, When any of the following conditions are fulfilled, the
+ * zero_byte syntax element shall be present:
+ * - the nal_unit_type within the nal_unit() is equal to 7 (sequence
+ * parameter set) or 8 (picture parameter set),
+ * - the byte stream NAL unit syntax structure contains the first NAL
+ * unit of an access unit in decoding order, as specified by subclause
+ * 7.4.1.2.3.
+ */
+ ::memcpy(encoder->m_packetData + memsize, start_code_prefix, 4);
+ size += 4;
+ }
+ else
+ {
+ ::memcpy(encoder->m_packetData + memsize, start_code_prefix + 1, 3);
+ size += 3;
+ }
+ memsize += size;
+ size_t nalSize = nalu->m_packetSize;
+ ::memcpy(encoder->m_packetData + memsize, nalu->m_nalUnitData, nalSize);
+ size += (int)nalSize;
+ memsize += (int)nalSize;
+
+ encoder->m_nals[nalcount].i_type = nalu->m_nalUnitType;
+ encoder->m_nals[nalcount].i_payload = size;
+ nalcount++;
+ free(nalu->m_nalUnitData);
+
+ } while (tmp.head->next != NULL && (tmp.head = tmp.head->next));
/* Setup payload pointers, now that we're done adding content to m_packetData */
size_t offset = 0;
@@ -495,6 +508,7 @@
}
else if (pi_nal)
*pi_nal = 0;
+
return numEncoded;
}
diff -r 275f2d5f9b0a -r 98ee31af129b source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp Wed Sep 11 12:16:50 2013 +0530
+++ b/source/encoder/frameencoder.cpp Wed Sep 11 17:14:45 2013 +0530
@@ -156,7 +156,7 @@
start();
}
-int FrameEncoder::getStreamHeaders(AccessUnit& accessUnit)
+int FrameEncoder::getStreamHeaders(AccessUnitn& accessUnit)
{
TEncEntropy* entropyCoder = getEntropyCoder(0);
@@ -212,7 +212,6 @@
}
return 0;
}
-
void FrameEncoder::initSlice(TComPic* pic)
{
m_pic = pic;
@@ -955,7 +954,7 @@
}
}
-TComPic *FrameEncoder::getEncodedPicture(AccessUnit& accessUnit)
+TComPic *FrameEncoder::getEncodedPicture(AccessUnitn& accessUnit)
{
if (m_pic)
{
@@ -966,7 +965,13 @@
m_pic = NULL;
// move NALs from member variable list to end of user's container
- accessUnit.splice(accessUnit.end(), m_accessUnit);
+ //accessUnit.splice(accessUnit.end(), m_accessUnit);
+
+ do
+ {
+ accessUnit.push_back(m_accessUnit.head->value);
+ }while(m_accessUnit.head->next != NULL && (m_accessUnit.head = m_accessUnit.head->next));
+
return ret;
}
diff -r 275f2d5f9b0a -r 98ee31af129b source/encoder/frameencoder.h
--- a/source/encoder/frameencoder.h Wed Sep 11 12:16:50 2013 +0530
+++ b/source/encoder/frameencoder.h Wed Sep 11 17:14:45 2013 +0530
@@ -88,7 +88,8 @@
}
}
- int getStreamHeaders(AccessUnit& accessUnitOut);
+
+ int getStreamHeaders(AccessUnitn& accessUnitOut);
void initSlice(TComPic* pic);
@@ -101,7 +102,7 @@
void encodeSlice(TComOutputBitstream* substreams);
/* blocks until worker thread is done, returns encoded picture and bitstream */
- TComPic *getEncodedPicture(AccessUnit& accessUnit);
+ TComPic *getEncodedPicture(AccessUnitn& accessUnit);
// worker thread
void threadMain()
@@ -143,7 +144,7 @@
/* Picture being encoded, and its output NAL list */
TComPic* m_pic;
- AccessUnit m_accessUnit;
+ AccessUnitn m_accessUnit;
int m_numRows;
int m_filterRowDelay;
diff -r 275f2d5f9b0a -r 98ee31af129b source/test/testbench.cpp
--- a/source/test/testbench.cpp Wed Sep 11 12:16:50 2013 +0530
+++ b/source/test/testbench.cpp Wed Sep 11 17:14:45 2013 +0530
@@ -30,6 +30,7 @@
#include "mbdstharness.h"
#include "ipfilterharness.h"
#include "intrapredharness.h"
+#include "vector.h"
#include <stdio.h>
#include <stdlib.h>
@@ -66,6 +67,7 @@
int main(int argc, char *argv[])
{
+
int cpuid = instrset_detect(); // Detect supported instruction set
const char *testname = 0;
int cpuid_user = -1;
More information about the x265-devel
mailing list