Commit a6dc44a0 authored by Alberto Gonzalez's avatar Alberto Gonzalez

Commit 2 concept fork

-----------------------------------
- Código String de división de CUs
(terminar con la pos del vector en función del método de debajo).
- Método para detectar posiciones del vector,
 en función del código String de división.
 ---------------------------------
parent 14d3d492
...@@ -65,6 +65,8 @@ ...@@ -65,6 +65,8 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include <string>
#include <math.h>
//END ALBERTO CONCEPT FORK //END ALBERTO CONCEPT FORK
//! \ingroup EncoderLib //! \ingroup EncoderLib
...@@ -80,10 +82,13 @@ struct vectorModeCostStruct { ...@@ -80,10 +82,13 @@ struct vectorModeCostStruct {
int mode; int mode;
double cost; double cost;
}; };
const int VECTOR_SIZE = 1 << 10; // 4^10 bool debugModeForTesting = true;
const int VECTOR_BYTES = VECTOR_SIZE * sizeof(int); const int VECTOR_SIZE = 341; // NODOS DEL TREE
const int VECTOR_BYTES = VECTOR_SIZE * sizeof(vectorModeCostStruct);
sem_t* sem; sem_t* sem;
vectorModeCostStruct* vector; vectorModeCostStruct* vector;
int nodeId = 0;
std::string posNode;
//END ALBERTO CONCEPT FORK //END ALBERTO CONCEPT FORK
// ==================================================================================================================== // ====================================================================================================================
...@@ -239,10 +244,20 @@ void EncCu::destroy() ...@@ -239,10 +244,20 @@ void EncCu::destroy()
buf.destroy(); buf.destroy();
} }
#endif #endif
//ALBERTO CONCEPT FORK
sem_destroy(sem);
munmap(vector, VECTOR_BYTES);
shm_unlink("/myshm");
//END ALBERTO CONCEPT FORK
} }
EncCu::~EncCu() EncCu::~EncCu()
{ {
//ALBERTO CONCEPT FORK
sem_destroy(sem);
munmap(vector, VECTOR_BYTES);
shm_unlink("/myshm");
//END ALBERTO CONCEPT FORK
} }
/** \param pcEncLib pointer of encoder class /** \param pcEncLib pointer of encoder class
...@@ -274,31 +289,33 @@ void EncCu::init( EncLib* pcEncLib, const SPS& sps ) ...@@ -274,31 +289,33 @@ void EncCu::init( EncLib* pcEncLib, const SPS& sps )
m_pcGOPEncoder = pcEncLib->getGOPEncoder(); m_pcGOPEncoder = pcEncLib->getGOPEncoder();
m_pcGOPEncoder->setModeCtrl( m_modeCtrl ); m_pcGOPEncoder->setModeCtrl( m_modeCtrl );
}
// ====================================================================================================================
// Public member functions
// ====================================================================================================================
void EncCu::compressCtu(CodingStructure &cs, const UnitArea &area, const unsigned ctuRsAddr, const EnumArray<int, ChannelType> &prevQP, const EnumArray<int, ChannelType> &currQP)
{
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
// Crear memoria compartida para el vector y el semáforo // Crear memoria compartida para el vector y el semáforo
int fd = shm_open("/myshm", O_CREAT | O_RDWR, 0666); int fd = shm_open("/myshm", O_CREAT | O_RDWR, 0666);
ftruncate(fd, VECTOR_BYTES + sizeof(sem_t)); ftruncate(fd, VECTOR_BYTES + sizeof(sem_t));
vector = (vectorModeCostStruct*) mmap(NULL, VECTOR_BYTES, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); vector = (vectorModeCostStruct*) mmap(NULL, VECTOR_BYTES, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
sem = (sem_t*) (vector + VECTOR_SIZE); sem = (sem_t*) (vector + VECTOR_SIZE);
sem_init(sem, 1, 1); sem_init(sem,1,1);
// Inicializar vector de estructuras con valores iniciales de -1
for (int i = 0; i < VECTOR_SIZE; i++) { for (int i = 0; i < VECTOR_SIZE; i++) {
pid_t pid = fork(); vector[i].mode = -1;
if (pid == 0) { // proceso hijo vector[i].cost = -1;
// acceder al vector en la posición i }
sem_wait(sem);
vectorModeCostStruct structura; //Comenzamos en el nodo 0 (único) del nivel 0 de 4
vector[i] = structura; posNode.append("0");
sem_post(sem);
//END ALBERTO CONCEPT FORK //END ALBERTO CONCEPT FORK
}
// ====================================================================================================================
// Public member functions
// ====================================================================================================================
//ALBERTO CONCEPT FORK
void EncCu::compressCtuForks(CodingStructure &cs, const UnitArea &area, const unsigned ctuRsAddr, const EnumArray<int, ChannelType> &prevQP, const EnumArray<int, ChannelType> &currQP)
{
m_modeCtrl->initCTUEncoding( *cs.slice ); m_modeCtrl->initCTUEncoding( *cs.slice );
cs.treeType = TREE_D; cs.treeType = TREE_D;
...@@ -384,13 +401,33 @@ void EncCu::compressCtu(CodingStructure &cs, const UnitArea &area, const unsigne ...@@ -384,13 +401,33 @@ void EncCu::compressCtu(CodingStructure &cs, const UnitArea &area, const unsigne
CHECK( bestCS->cus.empty() , "No possible encoding found" ); CHECK( bestCS->cus.empty() , "No possible encoding found" );
CHECK( bestCS->cus[0]->predMode == NUMBER_OF_PREDICTION_MODES, "No possible encoding found" ); CHECK( bestCS->cus[0]->predMode == NUMBER_OF_PREDICTION_MODES, "No possible encoding found" );
CHECK( bestCS->cost == MAX_DOUBLE , "No possible encoding found" ); CHECK( bestCS->cost == MAX_DOUBLE , "No possible encoding found" );
}
//END ALBERTO CONCEPT FORK
void EncCu::compressCtu(CodingStructure &cs, const UnitArea &area, const unsigned ctuRsAddr, const EnumArray<int, ChannelType> &prevQP, const EnumArray<int, ChannelType> &currQP)
{
if(debugModeForTesting)
{
debugModeForTesting = false;
vector[4].mode=1;
vector[4].cost=6;
}
else
{
std::cout << vector[4].mode << "== 1?, " << vector[4].cost << "==6?" << std::endl;
}
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
exit(0); for (int i = 0; i < 1; i++) {
pid_t pid = fork();
if (pid == 0) { // proceso hijo
compressCtuForks(cs,area,ctuRsAddr,prevQP,currQP);
exit(0);//proceso hijo muere
}
else{
compressCtuForks(cs,area,ctuRsAddr,prevQP,currQP);
} }
} }
//END ALBERTO CONCEPT FORK //END ALBERTO CONCEPT FORK
munmap(vector, VECTOR_BYTES);
shm_unlink("/myshm");
} }
// ==================================================================================================================== // ====================================================================================================================
...@@ -770,10 +807,10 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par ...@@ -770,10 +807,10 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par
} }
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
std::cout << "-----------------------------------------------------" << std::endl; /*std::cout << "-----------------------------------------------------" << std::endl;
int mode = 5; int mode = 5;
int lastMode = m_modeCtrl->currTestMode().type; int lastMode = m_modeCtrl->currTestMode().type;
/*Se avanza hasta el modo actual requerido por el proceso*/ Se avanza hasta el modo actual requerido por el proceso
while (lastMode != mode) while (lastMode != mode)
{ {
std::cout << "Avanzando modo: " << lastMode << ", buscando modo: " << mode << std::endl; std::cout << "Avanzando modo: " << lastMode << ", buscando modo: " << mode << std::endl;
...@@ -793,7 +830,7 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par ...@@ -793,7 +830,7 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par
{ {
std::cout << "El proceso que busca el modo " << mode << " SI ha resultado satisfactorio" << std::endl; std::cout << "El proceso que busca el modo " << mode << " SI ha resultado satisfactorio" << std::endl;
} }
std::cout << "-----------------------------------------------------" << std::endl; std::cout << "-----------------------------------------------------" << std::endl;*/
//END ALBERTO CONCEPT FORK //END ALBERTO CONCEPT FORK
do do
...@@ -1202,6 +1239,96 @@ void EncCu::updateLambda(Slice *slice, const int dQP, ...@@ -1202,6 +1239,96 @@ void EncCu::updateLambda(Slice *slice, const int dQP,
} }
#endif // SHARP_LUMA_DELTA_QP || ENABLE_QPA_SUB_CTU #endif // SHARP_LUMA_DELTA_QP || ENABLE_QPA_SUB_CTU
//ALBERTO CONCEPT FORK
int LEVEL0 = 1;
int LEVEL1 = 4;
int LEVEL2 = 16;
int LEVEL3 = 64;
int LEVEL4 = 256;
int levelValues [5] = {LEVEL0,LEVEL1,LEVEL2,LEVEL3,LEVEL4};
int EncCu::determinePosNodeInVector(std::string posNode)
{
int index = -1;
for(int i=0; i<posNode.length();i++)
{
if(i==posNode.length()-1 && posNode.length()>1)
{
bool childToSum = true;
for(int j=i; j-1>0; j--)
{
int codeParent = posNode[j-1] - '0';
int codeChild = posNode[j] - '0';
int nodesParentLevel = levelValues[j-1];
int NodesOtherChild = codeParent * nodesParentLevel;
int NodesChild = 0;
if(childToSum)
{
childToSum = false;
NodesChild = (codeChild + 1);
}
index += NodesOtherChild + NodesChild;
}
}
else
{
index += levelValues[i];
}
}
/*for(int i=0; i<posNode.length(); i++)
{
double multFactor = 1;
for(int j=1; j<=i; j++)
{
double code = posNode[j] - '0';
multFactor *= (code+1)/4;
}
int levelNodes = levelValues[i]*multFactor;
index += levelNodes;
}*/
return index;
}
/*
return determinePosNodeInVectorRec(posNode,"",0,0);
}
bool EncCu::digits_below_or_equal(std::string a, std::string b) {
if (a.length() > b.length()) {
return false;
}
for (int i = 0; i < a.length(); i++) {
if (a[i] > b[i]) {
return false;
}
}
return true;
}
int EncCu::determinePosNodeInVectorRec(std::string posNode, std::string posSearch, int index, int counter)
{
if(posNode == posSearch)
{
return counter;
}
else
{
if(index < 4 && digits_below_or_equal(posSearch,posNode))
{
posSearch.append(std::to_string(index));
index++;
counter += pow(4,posSearch.length());
return determinePosNodeInVectorRec(posNode,posSearch,index, counter);
}
else
{
index = 0;
counter++;
return determinePosNodeInVectorRec(posNode,posSearch,index, counter);
}
}
}*/
//END ALBERTO CONCEPT FORK
void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner, const EncTestMode& encTestMode, const ModeType modeTypeParent, bool &skipInterPass, double *splitRdCostBest ) void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner, const EncTestMode& encTestMode, const ModeType modeTypeParent, bool &skipInterPass, double *splitRdCostBest )
{ {
const int qp = encTestMode.qp; const int qp = encTestMode.qp;
...@@ -1321,9 +1448,14 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, ...@@ -1321,9 +1448,14 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
{ {
m_pcInterSearch->savePrevUniMvInfo(tempCS->area.Y(), tmpUniMvInfo, isUniMvInfoSaved); m_pcInterSearch->savePrevUniMvInfo(tempCS->area.Y(), tmpUniMvInfo, isUniMvInfoSaved);
} }
//ALBERTO CONCEPT FORK
int actualNodeId = 0;
//END ALBERTO CONCEPT FORK
do do
{ {
//ALBERTO CONCEPT FORK
posNode.append(std::to_string(actualNodeId));
//END ALBERTO CONCEPT FORK
const auto &subCUArea = partitioner.currArea(); const auto &subCUArea = partitioner.currArea();
if( tempCS->picture->Y().contains( subCUArea.lumaPos() ) ) if( tempCS->picture->Y().contains( subCUArea.lumaPos() ) )
...@@ -1339,7 +1471,16 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, ...@@ -1339,7 +1471,16 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
tempSubCS->bestParent = bestSubCS->bestParent = bestCS; tempSubCS->bestParent = bestSubCS->bestParent = bestCS;
double newMaxCostAllowed = isLuma(partitioner.chType) ? std::min(encTestMode.maxCostAllowed, bestCS->cost - m_pcRdCost->calcRdCost(tempCS->fracBits, tempCS->dist)) : MAX_DOUBLE; double newMaxCostAllowed = isLuma(partitioner.chType) ? std::min(encTestMode.maxCostAllowed, bestCS->cost - m_pcRdCost->calcRdCost(tempCS->fracBits, tempCS->dist)) : MAX_DOUBLE;
newMaxCostAllowed = std::max(0.0, newMaxCostAllowed); newMaxCostAllowed = std::max(0.0, newMaxCostAllowed);
xCompressCU(tempSubCS, bestSubCS, partitioner, newMaxCostAllowed); xCompressCU(tempSubCS, bestSubCS, partitioner, newMaxCostAllowed);//LLAMADA RECURSIVA
//ALBERTO CONCEPT FORK
int idexPosNode = determinePosNodeInVector("00000");
if(vector[idexPosNode].mode==-1 && vector[idexPosNode].cost == -1)
{
//vector[idexPosNode]->mode=3;
//vector[idexPosNode]->cost=bestSubCS->cost;
}
//END ALBERTO CONCEPT FORK
tempSubCS->bestParent = bestSubCS->bestParent = nullptr; tempSubCS->bestParent = bestSubCS->bestParent = nullptr;
if( bestSubCS->cost == MAX_DOUBLE ) if( bestSubCS->cost == MAX_DOUBLE )
...@@ -1400,6 +1541,9 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, ...@@ -1400,6 +1541,9 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
} }
} }
} }
//ALBERTO CONCEPT FORK
actualNodeId++;
//END ALBERTO CONCEPT FORK
} while( partitioner.nextPart( *tempCS ) ); } while( partitioner.nextPart( *tempCS ) );
partitioner.exitCurrSplit(); partitioner.exitCurrSplit();
......
...@@ -55,6 +55,11 @@ ...@@ -55,6 +55,11 @@
#include "InterSearch.h" #include "InterSearch.h"
#include "RateCtrl.h" #include "RateCtrl.h"
#include "EncModeCtrl.h" #include "EncModeCtrl.h"
//ALBERTO CONCEPT FORK
#include "string"
//END ALBERTO CONCEPT FORK
//! \ingroup EncoderLib //! \ingroup EncoderLib
//! \{ //! \{
...@@ -311,9 +316,14 @@ public: ...@@ -311,9 +316,14 @@ public:
/// destroy internal buffers /// destroy internal buffers
void destroy (); void destroy ();
//ALBERT CONCEPT FORK
void compressCtuForks(CodingStructure &cs, const UnitArea &area, const unsigned ctuRsAddr, const EnumArray<int, ChannelType> &prevQP, const EnumArray<int, ChannelType> &currQP);
//END ALBERTO CONCEPT FORK
/// CTU analysis function /// CTU analysis function
void compressCtu(CodingStructure &cs, const UnitArea &area, const unsigned ctuRsAddr, void compressCtu(CodingStructure &cs, const UnitArea &area, const unsigned ctuRsAddr, const EnumArray<int, ChannelType> &prevQP, const EnumArray<int, ChannelType> &currQP);
const EnumArray<int, ChannelType> &prevQP, const EnumArray<int, ChannelType> &currQP);
/// CTU encoding function /// CTU encoding function
int updateCtuDataISlice ( const CPelBuf buf ); int updateCtuDataISlice ( const CPelBuf buf );
...@@ -335,12 +345,18 @@ protected: ...@@ -335,12 +345,18 @@ protected:
void xCalDebCost ( CodingStructure &cs, Partitioner &partitioner, bool calDist = false ); void xCalDebCost ( CodingStructure &cs, Partitioner &partitioner, bool calDist = false );
Distortion getDistortionDb ( CodingStructure &cs, CPelBuf org, CPelBuf reco, ComponentID compID, const CompArea& compArea, bool afterDb ); Distortion getDistortionDb ( CodingStructure &cs, CPelBuf org, CPelBuf reco, ComponentID compID, const CompArea& compArea, bool afterDb );
void xCompressCU ( CodingStructure*& tempCS, CodingStructure*& bestCS, Partitioner& pm, double maxCostAllowed = MAX_DOUBLE ); void xCompressCU(CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &pm, double maxCostAllowed = MAX_DOUBLE);
bool bool
xCheckBestMode ( CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &pm, const EncTestMode& encTestmode ); xCheckBestMode ( CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &pm, const EncTestMode& encTestmode );
void xCheckModeSplit ( CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &pm, const EncTestMode& encTestMode, const ModeType modeTypeParent, bool &skipInterPass, double *splitRdCostBest); //ALBERTO CONCEPT FORK
bool digits_below_or_equal(std::string a, std::string b);
int determinePosNodeInVectorRec(std::string posNode, std::string posSearch, int index, int counter);
int determinePosNodeInVector(std::string posNode);
//END ALBERTO CONCEPT FORK
void xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &pm, const EncTestMode &encTestMode, const ModeType modeTypeParent, bool &skipInterPass, double *splitRdCostBest);
bool xCheckRDCostIntra(CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &pm, const EncTestMode& encTestMode, bool adaptiveColorTrans); bool xCheckRDCostIntra(CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &pm, const EncTestMode& encTestMode, bool adaptiveColorTrans);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment