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 @@
#include <sys/mman.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string>
#include <math.h>
//END ALBERTO CONCEPT FORK
//! \ingroup EncoderLib
......@@ -80,10 +82,13 @@ struct vectorModeCostStruct {
int mode;
double cost;
};
const int VECTOR_SIZE = 1 << 10; // 4^10
const int VECTOR_BYTES = VECTOR_SIZE * sizeof(int);
bool debugModeForTesting = true;
const int VECTOR_SIZE = 341; // NODOS DEL TREE
const int VECTOR_BYTES = VECTOR_SIZE * sizeof(vectorModeCostStruct);
sem_t* sem;
vectorModeCostStruct* vector;
int nodeId = 0;
std::string posNode;
//END ALBERTO CONCEPT FORK
// ====================================================================================================================
......@@ -239,10 +244,20 @@ void EncCu::destroy()
buf.destroy();
}
#endif
//ALBERTO CONCEPT FORK
sem_destroy(sem);
munmap(vector, VECTOR_BYTES);
shm_unlink("/myshm");
//END ALBERTO CONCEPT FORK
}
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
......@@ -274,32 +289,34 @@ void EncCu::init( EncLib* pcEncLib, const SPS& sps )
m_pcGOPEncoder = pcEncLib->getGOPEncoder();
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
// Crear memoria compartida para el vector y el semáforo
int fd = shm_open("/myshm", O_CREAT | O_RDWR, 0666);
ftruncate(fd, VECTOR_BYTES + sizeof(sem_t));
vector = (vectorModeCostStruct*) mmap(NULL, VECTOR_BYTES, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
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++) {
pid_t pid = fork();
if (pid == 0) { // proceso hijo
// acceder al vector en la posición i
sem_wait(sem);
vectorModeCostStruct structura;
vector[i] = structura;
sem_post(sem);
vector[i].mode = -1;
vector[i].cost = -1;
}
//Comenzamos en el nodo 0 (único) del nivel 0 de 4
posNode.append("0");
//END ALBERTO CONCEPT FORK
m_modeCtrl->initCTUEncoding( *cs.slice );
}
// ====================================================================================================================
// 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 );
cs.treeType = TREE_D;
cs.slice->m_mapPltCost[0].clear();
......@@ -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[0]->predMode == NUMBER_OF_PREDICTION_MODES, "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
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
munmap(vector, VECTOR_BYTES);
shm_unlink("/myshm");
}
// ====================================================================================================================
......@@ -770,10 +807,10 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par
}
//ALBERTO CONCEPT FORK
std::cout << "-----------------------------------------------------" << std::endl;
/*std::cout << "-----------------------------------------------------" << std::endl;
int mode = 5;
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)
{
std::cout << "Avanzando modo: " << lastMode << ", buscando modo: " << mode << std::endl;
......@@ -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 << "-----------------------------------------------------" << std::endl;
std::cout << "-----------------------------------------------------" << std::endl;*/
//END ALBERTO CONCEPT FORK
do
......@@ -1202,6 +1239,96 @@ void EncCu::updateLambda(Slice *slice, const int dQP,
}
#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 )
{
const int qp = encTestMode.qp;
......@@ -1321,9 +1448,14 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
{
m_pcInterSearch->savePrevUniMvInfo(tempCS->area.Y(), tmpUniMvInfo, isUniMvInfoSaved);
}
//ALBERTO CONCEPT FORK
int actualNodeId = 0;
//END ALBERTO CONCEPT FORK
do
{
//ALBERTO CONCEPT FORK
posNode.append(std::to_string(actualNodeId));
//END ALBERTO CONCEPT FORK
const auto &subCUArea = partitioner.currArea();
if( tempCS->picture->Y().contains( subCUArea.lumaPos() ) )
......@@ -1339,7 +1471,16 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&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;
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;
if( bestSubCS->cost == MAX_DOUBLE )
......@@ -1400,6 +1541,9 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
}
}
}
//ALBERTO CONCEPT FORK
actualNodeId++;
//END ALBERTO CONCEPT FORK
} while( partitioner.nextPart( *tempCS ) );
partitioner.exitCurrSplit();
......
......@@ -55,6 +55,11 @@
#include "InterSearch.h"
#include "RateCtrl.h"
#include "EncModeCtrl.h"
//ALBERTO CONCEPT FORK
#include "string"
//END ALBERTO CONCEPT FORK
//! \ingroup EncoderLib
//! \{
......@@ -311,9 +316,14 @@ public:
/// destroy internal buffers
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
void compressCtu(CodingStructure &cs, const UnitArea &area, const unsigned ctuRsAddr,
const EnumArray<int, ChannelType> &prevQP, const EnumArray<int, ChannelType> &currQP);
void compressCtu(CodingStructure &cs, const UnitArea &area, const unsigned ctuRsAddr, const EnumArray<int, ChannelType> &prevQP, const EnumArray<int, ChannelType> &currQP);
/// CTU encoding function
int updateCtuDataISlice ( const CPelBuf buf );
......@@ -335,12 +345,18 @@ protected:
void xCalDebCost ( CodingStructure &cs, Partitioner &partitioner, bool calDist = false );
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
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);
......
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