Commit 85e4585b authored by Alberto Gonzalez's avatar Alberto Gonzalez

Commit 5 concept fork

```----------------------------------------------------------------
- Función completa
- Revisar errores buff en child
```

----------------------------------------------------------------
parent 04fd3db2
...@@ -78,36 +78,55 @@ ...@@ -78,36 +78,55 @@
//END ALBERTO //END ALBERTO
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
//bool debugModeForTesting = true; //CONTROL CENTER
//const int THREADS_NUMBER = 4; bool singleMode = false;
//int nodeId = 0; bool debugMessage = false;
//CONTROL CENTER
sem_t* sem;
vectorModeCostStruct* vector; //GLOBAL VARIABLES
std::string posNode; vectorModeCostStruct* vector; //VECTOR OF PROCESSING RESULTS
bool father; bool father; //TRUE IF THE PROCESS IS NOT A CHILD
int threadNumber; int threadNumber; //NUMBER OF THREAD IF WE ARE IN A CHILD
int posActualNode = 0; //NODE THAT IS BEING PROCESSED
bool ignore_vector; //IGNORE THE VECTOR IF WE ARE UNDER A SPLIT THAT IS NOT QUATERNARY
//GLOBAL VARIABLES
//TOSTRING_VECTOR
void toStringVector() void toStringVector()
{ {
for (int i = 0; i < VECTOR_SIZE; i++) { for (int i = 0; i < VECTOR_SIZE && debugMessage; i++) {
std::cout << vector[i].mode; std::cout << vector[i].mode << ", ";
std::cout << vector[i].cost << std::endl;
}
}
void toStringVector(double Level)
{
int end = 0;
for(int i=Level-1; i>-1 && debugMessage; i--)
{
end += pow(4,i);
}
for (int i = 0; i < end && debugMessage; i++) {
std::cout << vector[i].posFather << ", ";
std::cout << vector[i].threadNumber << ", ";
std::cout << vector[i].mode << ", ";
std::cout << vector[i].cost << std::endl; std::cout << vector[i].cost << std::endl;
} }
} }
void toStringVector(int Level) void toStringVector(int Level)
{ {
int end = 0; int end = 0;
for(int i=Level-1; i>-1; i--) for(int i=Level-1; i>-1 && debugMessage; i--)
{ {
end += pow(4,i); end += pow(4,i);
} }
for (int i = 0; i < end; i++) { for (int i = 0; i < end && debugMessage; i++) {
std::cout << vector[i].posPadre << ", "; std::cout << vector[i].posFather << ", ";
std::cout << vector[i].threadNumber << std::endl; std::cout << vector[i].threadNumber << std::endl;
} }
} }
//TOSTRING_VECTOR
//END ALBERTO CONCEPT FORK //END ALBERTO CONCEPT FORK
...@@ -264,7 +283,7 @@ void EncCu::destroy() ...@@ -264,7 +283,7 @@ void EncCu::destroy()
} }
#endif #endif
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
sem_destroy(sem); //sem_destroy(sem);
munmap(vector, VECTOR_BYTES); munmap(vector, VECTOR_BYTES);
shm_unlink("/myshm"); shm_unlink("/myshm");
//END ALBERTO CONCEPT FORK //END ALBERTO CONCEPT FORK
...@@ -273,7 +292,7 @@ void EncCu::destroy() ...@@ -273,7 +292,7 @@ void EncCu::destroy()
EncCu::~EncCu() EncCu::~EncCu()
{ {
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
sem_destroy(sem); //sem_destroy(sem);
munmap(vector, VECTOR_BYTES); munmap(vector, VECTOR_BYTES);
shm_unlink("/myshm"); shm_unlink("/myshm");
//END ALBERTO CONCEPT FORK //END ALBERTO CONCEPT FORK
...@@ -310,31 +329,24 @@ void EncCu::init( EncLib* pcEncLib, const SPS& sps ) ...@@ -310,31 +329,24 @@ void EncCu::init( EncLib* pcEncLib, const SPS& sps )
m_pcGOPEncoder->setModeCtrl( m_modeCtrl ); m_pcGOPEncoder->setModeCtrl( m_modeCtrl );
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
// Crear memoria compartida para el vector y el semáforo // Crear memoria compartida para el vector
createAndInitSemaphore(); createSharedVector();
//Rellenar el vector
// Inicializar vector de estructuras con valores iniciales de -1
//Estamos en el nivel 0
initStructVector(); initStructVector();
toStringVector(5); //IMPRIMIR 5 (TODOS) LOS NIVELES
toStringVector(5); //IMPRIMIR 5 NIVELES //END ALBERTO CONCEPT
//Comenzamos en el nodo 0 (único) del nivel 0 de 4
posNode.append("0");
} }
void EncCu::createAndInitSemaphore() //ALBERTO CONCEPT FORK
void EncCu::createSharedVector()
{ {
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_init(sem,1,1);
} }
void EncCu::initStructVector() void EncCu::initStructVector()
{ {
vector[0].posPadre=-1; vector[0].posFather=-1;
vector[0].threadNumber=1; vector[0].threadNumber=1;
for (int i = 0; i < VECTOR_SIZE; i++) for (int i = 0; i < VECTOR_SIZE; i++)
{ {
...@@ -349,7 +361,7 @@ void EncCu::initStructVector() ...@@ -349,7 +361,7 @@ void EncCu::initStructVector()
int end = posPadreActual+salto+4; int end = posPadreActual+salto+4;
for(int j=start; j<end; j++)//Actualizar los 4 hijos for(int j=start; j<end; j++)//Actualizar los 4 hijos
{ {
vector[j].posPadre=posPadreActual; vector[j].posFather=posPadreActual;
vector[j].threadNumber=threadNumber++; vector[j].threadNumber=threadNumber++;
} }
} }
...@@ -370,14 +382,13 @@ void EncCu::initStructVector() ...@@ -370,14 +382,13 @@ void EncCu::initStructVector()
int end = posPadreActual+salto+4; int end = posPadreActual+salto+4;
for(int j=start; j<end; j++)//Actualizar los 4 hijos for(int j=start; j<end; j++)//Actualizar los 4 hijos
{ {
vector[j].posPadre=posPadreActual; vector[j].posFather=posPadreActual;
vector[j].threadNumber=threadNumber; vector[j].threadNumber=threadNumber;
} }
updateFatherAndThreadNumbers(2,3,posPadreActual,i); updateFatherAndThreadNumbers(2,3,posPadreActual,i);
} }
} }
} }
void EncCu::updateFatherAndThreadNumbers(int LevelLowIndex, int LevelUpIndex, int posPadreActual, int i) void EncCu::updateFatherAndThreadNumbers(int LevelLowIndex, int LevelUpIndex, int posPadreActual, int i)
{ {
int LevelLow = 0; int LevelLow = 0;
...@@ -393,17 +404,57 @@ void EncCu::updateFatherAndThreadNumbers(int LevelLowIndex, int LevelUpIndex, in ...@@ -393,17 +404,57 @@ void EncCu::updateFatherAndThreadNumbers(int LevelLowIndex, int LevelUpIndex, in
int end = posPadreActual+salto+4; int end = posPadreActual+salto+4;
for(int j=start; j<end; j++)//Actualizar los 4 hijos for(int j=start; j<end; j++)//Actualizar los 4 hijos
{ {
vector[j].posPadre=posPadreActual; vector[j].posFather=posPadreActual;
vector[j].threadNumber=threadNumber; vector[j].threadNumber=threadNumber;
} }
} }
//END ALBERTO CONCEPT FORK void EncCu::cleanCostModeVector()
{
for(int i=0; i<VECTOR_SIZE; i++)
{
vector[i].cost = vector[i].mode = -1;
}
}
//END ALBERTO CONCEPT FORK
// ==================================================================================================================== // ====================================================================================================================
// Public member functions // Public member functions
// ==================================================================================================================== // ====================================================================================================================
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
void EncCu::compressCtuForks(CodingStructure &cs, const UnitArea &area, const unsigned ctuRsAddr, const EnumArray<int, ChannelType> &prevQP, const EnumArray<int, ChannelType> &currQP) void EncCu::compressCtuForks(CodingStructure*& tempCS, CodingStructure*& bestCS, Partitioner& partitioner)
{
if(singleMode)
{
xCompressCU(tempCS, bestCS, partitioner);
}
else
{
cleanCostModeVector();
for (int i = 0; i < 4 ; i++)
{
pid_t pid = fork();
if (pid == 0) { // proceso hijo
father = false;
threadNumber = i+1;
xCompressCU(tempCS, bestCS, partitioner);
exit(0);//proceso hijo muere
}
}
for(int i=0; i<4 ; i++)
{
wait(NULL);
}
father = true;
reduceVector();
toStringVector(5.00);
xCompressCU(tempCS, bestCS, partitioner);
}
}
//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)
{ {
m_modeCtrl->initCTUEncoding( *cs.slice ); m_modeCtrl->initCTUEncoding( *cs.slice );
cs.treeType = TREE_D; cs.treeType = TREE_D;
...@@ -449,7 +500,10 @@ void EncCu::compressCtuForks(CodingStructure &cs, const UnitArea &area, const un ...@@ -449,7 +500,10 @@ void EncCu::compressCtuForks(CodingStructure &cs, const UnitArea &area, const un
currQP[ChannelType::LUMA]; currQP[ChannelType::LUMA];
tempCS->prevQP[ChannelType::LUMA] = bestCS->prevQP[ChannelType::LUMA] = prevQP[ChannelType::LUMA]; tempCS->prevQP[ChannelType::LUMA] = bestCS->prevQP[ChannelType::LUMA] = prevQP[ChannelType::LUMA];
xCompressCU(tempCS, bestCS, partitioner); //ALBERTO CONCEPT FORK
compressCtuForks(tempCS,bestCS,partitioner);
//END ALBERTO CONCEPT FORK
cs.slice->m_mapPltCost[0].clear(); cs.slice->m_mapPltCost[0].clear();
cs.slice->m_mapPltCost[1].clear(); cs.slice->m_mapPltCost[1].clear();
// all signals were already copied during compression if the CTU was split - at this point only the structures are copied to the top level CS // all signals were already copied during compression if the CTU was split - at this point only the structures are copied to the top level CS
...@@ -469,7 +523,18 @@ void EncCu::compressCtuForks(CodingStructure &cs, const UnitArea &area, const un ...@@ -469,7 +523,18 @@ void EncCu::compressCtuForks(CodingStructure &cs, const UnitArea &area, const un
currQP[ChannelType::CHROMA]; currQP[ChannelType::CHROMA];
tempCS->prevQP[ChannelType::CHROMA] = bestCS->prevQP[ChannelType::CHROMA] = prevQP[ChannelType::CHROMA]; tempCS->prevQP[ChannelType::CHROMA] = bestCS->prevQP[ChannelType::CHROMA] = prevQP[ChannelType::CHROMA];
xCompressCU(tempCS, bestCS, partitioner); //ALBERTO CONCEPT FORK
bool activation = false;
if(!singleMode)
{
activation = singleMode = true;
}
compressCtuForks(tempCS,bestCS,partitioner);
if(activation)
{
activation = singleMode = false;
}
//END ALBERTO CONCEPT FORK
const bool copyUnsplitCTUSignals = bestCS->cus.size() == 1; const bool copyUnsplitCTUSignals = bestCS->cus.size() == 1;
cs.useSubStructure(*bestCS, partitioner.chType, CS::getArea(*bestCS, area, partitioner.chType), cs.useSubStructure(*bestCS, partitioner.chType, CS::getArea(*bestCS, area, partitioner.chType),
...@@ -491,36 +556,6 @@ void EncCu::compressCtuForks(CodingStructure &cs, const UnitArea &area, const un ...@@ -491,36 +556,6 @@ void EncCu::compressCtuForks(CodingStructure &cs, const UnitArea &area, const un
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
for (int i = 0; i < 1; i++) {
pid_t pid = fork();
if (pid != 0) { // proceso hijo
father = false;
threadNumber = i+1;
compressCtuForks(cs,area,ctuRsAddr,prevQP,currQP);
exit(0);//proceso hijo muere
}
}
wait(NULL);
father = true;
compressCtuForks(cs,area,ctuRsAddr,prevQP,currQP);
//END ALBERTO CONCEPT FORK
}
// ==================================================================================================================== // ====================================================================================================================
// Protected member functions // Protected member functions
...@@ -898,33 +933,8 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par ...@@ -898,33 +933,8 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par
m_bestBcwIdx.fill(BCW_NUM); m_bestBcwIdx.fill(BCW_NUM);
} }
//ALBERTO CONCEPT FORK EncTestMode savedEncMode;
/*std::cout << "-----------------------------------------------------" << std::endl; bool activeIgnoreVector = false;
int mode = 5;
int lastMode = m_modeCtrl->currTestMode().type;
Se avanza hasta el modo actual requerido por el proceso
while (lastMode != mode)
{
std::cout << "Avanzando modo: " << lastMode << ", buscando modo: " << mode << std::endl;
if (lastMode == mode || !(m_modeCtrl->nextMode(*tempCS, partitioner))) //Si se encuntra mode o no hay mas modes salimos del bucle
{
std::cout << "No otros modos" << ", modo reciente: <" << lastMode << ">" << std::endl;
break;
}
lastMode = m_modeCtrl->currTestMode().type;
}
if (lastMode != mode)
{
std::cout << "El proceso que busca el modo " << mode << " NO ha resultado satisfactorio, no se puede aplicar ese modo para CU" << std::endl;
return; //NO SE PUEDE APLICAR MODO PARA ESTA CU
}
else
{
std::cout << "El proceso que busca el modo " << mode << " SI ha resultado satisfactorio" << std::endl;
}
std::cout << "-----------------------------------------------------" << std::endl;*/
//END ALBERTO CONCEPT FORK
do do
{ {
for (int i = compBegin; i < (compBegin + numComp); i++) for (int i = compBegin; i < (compBegin + numComp); i++)
...@@ -933,8 +943,18 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par ...@@ -933,8 +943,18 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par
tempCS->prevPLT.curPLTSize[comID] = curLastPLTSize[comID]; tempCS->prevPLT.curPLTSize[comID] = curLastPLTSize[comID];
memcpy(tempCS->prevPLT.curPLT[i], curLastPLT[i], curLastPLTSize[comID] * sizeof(Pel)); memcpy(tempCS->prevPLT.curPLT[i], curLastPLT[i], curLastPLTSize[comID] * sizeof(Pel));
} }
EncTestMode currTestMode = m_modeCtrl->currTestMode(); EncTestMode currTestMode = savedEncMode = m_modeCtrl->currTestMode();
//continue; //ALBERTO CONCEPT FORK
bool lastModeAvailable = (!singleMode && father && m_modeCtrl->lastModeAvailable(*tempCS, partitioner) && tempCS->cost == MAX_DOUBLE); //SI SOLO QUEDA UN MODO Y EL COSTE ES MÁXIMO, NO PODEMOS SKIPEAR
bool skipMode = (!singleMode && father && vector[posActualNode].mode!=-1 && vector[posActualNode].mode!=currTestMode.type && !ignore_vector && vector[posActualNode].mode!=ETM_RECO_CACHED && !lastModeAvailable);
bool skipCU = (!singleMode && !father && 1<=posActualNode && posActualNode<=4 && vector[posActualNode].threadNumber!=threadNumber);//SI ESTAMOS EN UN THREAD INCORRECTO SE HACE SKIP
if(debugMessage) { std::cout << "posActualNode:" << posActualNode << ", Vector:" << vector[posActualNode].mode << ", CurrMode:" << currTestMode.type << std::endl;}
if(skipMode)
{
if(debugMessage) { std::cout << "skip" << std::endl; }
continue;
}
//END ALBERTO CONCEPT FORK
currTestMode.maxCostAllowed = maxCostAllowed; currTestMode.maxCostAllowed = maxCostAllowed;
if (pps.getUseDQP() && partitioner.isSepTree(*tempCS) && isChroma( partitioner.chType )) if (pps.getUseDQP() && partitioner.isSepTree(*tempCS) && isChroma( partitioner.chType ))
...@@ -974,7 +994,7 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par ...@@ -974,7 +994,7 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par
} }
} }
#endif #endif
if( currTestMode.type == ETM_INTER_ME ) if( currTestMode.type == ETM_INTER_ME )
{ {
if( ( currTestMode.opts & ETO_IMV ) != 0 ) if( ( currTestMode.opts & ETO_IMV ) != 0 )
...@@ -1022,7 +1042,7 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par ...@@ -1022,7 +1042,7 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par
tempCS->splitRdCostBest = splitRdCostBest; tempCS->splitRdCostBest = splitRdCostBest;
} }
#endif #endif
else if( currTestMode.type == ETM_MERGE_SKIP ) else if( currTestMode.type == ETM_MERGE_SKIP)
{ {
#if JVET_AC0139_UNIFIED_MERGE #if JVET_AC0139_UNIFIED_MERGE
xCheckRDCostUnifiedMerge(tempCS, bestCS, partitioner, currTestMode); xCheckRDCostUnifiedMerge(tempCS, bestCS, partitioner, currTestMode);
...@@ -1045,7 +1065,7 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par ...@@ -1045,7 +1065,7 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par
tempCS->splitRdCostBest = splitRdCostBest; tempCS->splitRdCostBest = splitRdCostBest;
} }
#endif #endif
else if( currTestMode.type == ETM_INTRA ) else if( currTestMode.type == ETM_INTRA || skipCU)
{ {
if (slice.getSPS()->getUseColorTrans() && !CS::isDualITree(*tempCS)) if (slice.getSPS()->getUseColorTrans() && !CS::isDualITree(*tempCS))
{ {
...@@ -1103,6 +1123,10 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par ...@@ -1103,6 +1123,10 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par
} }
else if( isModeSplit( currTestMode ) ) else if( isModeSplit( currTestMode ) )
{ {
//ALBERTO CONCEPT FORK
if(!ignore_vector && currTestMode.type!=ETM_SPLIT_QT) { activeIgnoreVector = ignore_vector = true; }//SI ES LA PRIMERA VEZ QUE NOS ENCONTRAMOS CON UN SPLIT NO QT IGNORAMOS AL VECTOR
//END ALBERTO CONCEPT FORK
if (bestCS->cus.size() != 0) if (bestCS->cus.size() != 0)
{ {
splitmode = bestCS->cus[0]->splitSeries; splitmode = bestCS->cus[0]->splitSeries;
...@@ -1180,6 +1204,9 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par ...@@ -1180,6 +1204,9 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par
memcpy(bestLastPLT[i], bestCS->cus[0]->cs->prevPLT.curPLT[i], bestCS->cus[0]->cs->prevPLT.curPLTSize[comID] * sizeof(Pel)); memcpy(bestLastPLT[i], bestCS->cus[0]->cs->prevPLT.curPLT[i], bestCS->cus[0]->cs->prevPLT.curPLTSize[comID] * sizeof(Pel));
} }
} }
//ALBERTO CONCEPT FORK
if(activeIgnoreVector) { activeIgnoreVector = ignore_vector = false; }//SI SE MARCÓ EN ESTA ITERACIÓN EL IGNORAR AL VECTOR, AL REGRESAR DE DEVUELVE EL VALOR FALSO
//END ALBERTO CONCEPT FORK
} }
else else
{ {
...@@ -1187,9 +1214,20 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par ...@@ -1187,9 +1214,20 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par
} }
} while( m_modeCtrl->nextMode( *tempCS, partitioner ) ); } while( m_modeCtrl->nextMode( *tempCS, partitioner ) );
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// Finishing CU // Finishing CU
//ALBERTO CONCEPT FORK
//PASO 5 -> AL TERMINAR EL BUCLE SE GUARDA EN EL PADRE EL VALOR DEL COSTE Y SE RETORNA
if(debugMessage) { std::cout << "SAVING --> código bucle split " << posActualNode << " : " << " (" << tempCS->area.lheight() <<","<< tempCS->area.lwidth() << ") " << std::endl; }
bool saveModeCost = (!singleMode && !father && vector[posActualNode].mode==-1 && vector[posActualNode].cost==-1 && vector[posActualNode].threadNumber==threadNumber);
if(saveModeCost)
{
vector[posActualNode].mode=savedEncMode.type;
vector[posActualNode].cost=bestCS->cost;
}
//ALBERTO END CONCEPT FORK
if( tempCS->cost == MAX_DOUBLE && bestCS->cost == MAX_DOUBLE ) if( tempCS->cost == MAX_DOUBLE && bestCS->cost == MAX_DOUBLE )
{ {
//although some coding modes were planned to be tried in RDO, no coding mode actually finished encoding due to early termination //although some coding modes were planned to be tried in RDO, no coding mode actually finished encoding due to early termination
...@@ -1280,7 +1318,6 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par ...@@ -1280,7 +1318,6 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par
iter = 0; iter = 0;
} }
//END ALBERTO //END ALBERTO
} }
#if SHARP_LUMA_DELTA_QP || ENABLE_QPA_SUB_CTU #if SHARP_LUMA_DELTA_QP || ENABLE_QPA_SUB_CTU
...@@ -1341,7 +1378,7 @@ int EncCu::determinePosNodeInVector(std::string posNode) ...@@ -1341,7 +1378,7 @@ int EncCu::determinePosNodeInVector(std::string posNode)
if(i==posNode.length()-1 && posNode.length()>1) if(i==posNode.length()-1 && posNode.length()>1)
{ {
bool childToSum = true; bool childToSum = true;
for(int j=i; j-1>0; j--) for(int j=i; j-1>-1; j--)
{ {
int codeParent = posNode[j-1] - '0'; int codeParent = posNode[j-1] - '0';
int codeChild = posNode[j] - '0'; int codeChild = posNode[j] - '0';
...@@ -1363,6 +1400,49 @@ int EncCu::determinePosNodeInVector(std::string posNode) ...@@ -1363,6 +1400,49 @@ int EncCu::determinePosNodeInVector(std::string posNode)
} }
return index; return index;
} }
int EncCu::searchFirstChild(int posFather)
{
int posChild = -1;
for(int i=0; i<VECTOR_SIZE && posChild == -1; i++)
{
if(vector[i].posFather==posFather)
{
posChild = i;
}
}
return posChild;
}
void EncCu::reduceVector()
{
for(int i=VECTOR_SIZE-1 ; (i-4)>=0 ; i=i-4)
{
int valueChild_1 = vector[i-3].cost;
int valueChild_2 = vector[i-2].cost;
int valueChild_3 = vector[i-1].cost;
int valueChild_4 = vector[i].cost;
if(valueChild_1==-1 || valueChild_2==-1 || valueChild_3==-1 || valueChild_4==-1)
{
continue;
}
else
{
int childSum = valueChild_1 + valueChild_2 + valueChild_3 + valueChild_4;
int posFather = vector[i].posFather;
int costFather = vector[posFather].cost;
int modeFather = vector[posFather].mode;
if(costFather <= childSum && modeFather!=ETM_SPLIT_QT)
{
vector[i-3].cost = vector[i-2].cost = vector[i-1].cost = vector[i].cost = -1;
vector[i-3].mode = vector[i-2].mode = vector[i-1].mode = vector[i].mode = -1;
}
else if(costFather > childSum && modeFather!=ETM_SPLIT_QT)
{
vector[posFather].cost = childSum;
vector[posFather].mode = ETM_SPLIT_QT;
}
}
}
}
//END ALBERTO CONCEPT FORK //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 )
...@@ -1484,10 +1564,12 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, ...@@ -1484,10 +1564,12 @@ 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 //ALBERTO CONCEPT FORK
int actualNodeId = 0; //CU COUNTER //PASO 1 -> OBTENEMOS EL PRIMER HIJO DEL NODO ACTUAL
std::string original = posNode; int posChild = searchFirstChild(posActualNode);
//END ALBERTO CONCEPT FORK //END ALBERTO CONCEPT FORK
do do
{ {
const auto &subCUArea = partitioner.currArea(); const auto &subCUArea = partitioner.currArea();
...@@ -1504,32 +1586,25 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, ...@@ -1504,32 +1586,25 @@ 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);
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
posNode.append(std::to_string(actualNodeId)); //INTRODUCIMOS SU ID DENTRO DEL PADRE //PASO 2 -> SI EL SPLIT ES QUAD SE ACTUALIZA NODO ACTUAL
//ELEGIMOS EL THREAD EN EL NIVEL 1 (CONTANDO DESDE 0). if(debugMessage)
if(!father && posNode.length() == 2 && vector[determinePosNodeInVector(posNode)].threadNumber!=threadNumber)
{ {
continue; std::cout << "CONTROL --> código bucle split " << posActualNode << "->" << posChild << " : " << " (" << tempCS->area.lheight() <<","<< tempCS->area.lwidth() << ") " << "->" << " (" << tempSubCS->area.lheight() <<","<< tempSubCS->area.lwidth() <<") " << std::endl;
} }
std::cout << "CONTROL --> código bucle split" << posNode << " : (" << tempSubCS->area.lheight() <<","<< tempSubCS->area.lwidth() <<") " << std::endl; int restorePosActualNode = posActualNode;
/*if(posNode == "0311") bool fatherUpdate = ((!singleMode && !father && split == CU_QUAD_SPLIT) || (!singleMode && father && split == CU_QUAD_SPLIT && !ignore_vector));
{ if(fatherUpdate) { posActualNode=posChild; }
toStringVector();
}*/ //PASO 3 -> LLAMADA RECURSIVA CON EL HIJO QUE AHORA ES EL PADRE
//END ALBERTO CONCEPT FORK xCompressCU(tempSubCS, bestSubCS, partitioner, newMaxCostAllowed);
xCompressCU(tempSubCS, bestSubCS, partitioner, newMaxCostAllowed);//LLAMADA RECURSIVA tempSubCS->bestParent = bestSubCS->bestParent = nullptr;
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
if(tempCS->area.lheight()>=8 && tempCS->area.lwidth()>= 8) //PASO 4 -> AL REGRESAR DE LA LLAMADA SI SE HA MODIFICADO EL PADRE SE RESTAURA EL PADRE Y SE AVANZA AL SIGUIENTE HIJO DE LOS 4
{ if(fatherUpdate) { posActualNode=restorePosActualNode; posChild++;}
int idexPosNode = determinePosNodeInVector(posNode);
if(vector[idexPosNode].mode==-1 && vector[idexPosNode].cost == -1)
{
vector[idexPosNode].mode=encTestMode.type;
vector[idexPosNode].cost=tempSubCS->cost;
}
}
//END ALBERTO CONCEPT FORK //END ALBERTO CONCEPT FORK
tempSubCS->bestParent = bestSubCS->bestParent = nullptr;
if( bestSubCS->cost == MAX_DOUBLE ) if( bestSubCS->cost == MAX_DOUBLE )
{ {
...@@ -1544,14 +1619,10 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, ...@@ -1544,14 +1619,10 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
{ {
tempCS->motionLut = oldMotionLut; tempCS->motionLut = oldMotionLut;
} }
posNode = original;
actualNodeId = 0;
return; return;
} }
bool keepResi = KEEP_PRED_AND_RESI_SIGNALS; bool keepResi = KEEP_PRED_AND_RESI_SIGNALS;
tempCS->useSubStructure( *bestSubCS, partitioner.chType, CS::getArea( *tempCS, subCUArea, partitioner.chType ), KEEP_PRED_AND_RESI_SIGNALS, true, keepResi, keepResi, true ); tempCS->useSubStructure( *bestSubCS, partitioner.chType, CS::getArea( *tempCS, subCUArea, partitioner.chType ), KEEP_PRED_AND_RESI_SIGNALS, true, keepResi, keepResi, true );
if( partitioner.currQgEnable() ) if( partitioner.currQgEnable() )
{ {
tempCS->prevQP[partitioner.chType] = bestSubCS->prevQP[partitioner.chType]; tempCS->prevQP[partitioner.chType] = bestSubCS->prevQP[partitioner.chType];
...@@ -1570,7 +1641,6 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, ...@@ -1570,7 +1641,6 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
CHECK(CU::isInter(*bestSubCS->cus[i]), "all CUs must not be inter mode in an Intra coding region (SCIPU)"); CHECK(CU::isInter(*bestSubCS->cus[i]), "all CUs must not be inter mode in an Intra coding region (SCIPU)");
} }
} }
tempSubCS->releaseIntermediateData(); tempSubCS->releaseIntermediateData();
bestSubCS->releaseIntermediateData(); bestSubCS->releaseIntermediateData();
if( !tempCS->slice->isIntra() && partitioner.isConsIntra() ) if( !tempCS->slice->isIntra() && partitioner.isConsIntra() )
...@@ -1587,28 +1657,15 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, ...@@ -1587,28 +1657,15 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
{ {
tempCS->motionLut = oldMotionLut; tempCS->motionLut = oldMotionLut;
} }
posNode = original;
actualNodeId = 0;
return; return;
} }
} }
} }
//ALBERTO CONCEPT FORK
actualNodeId++;//NOS PONEMOS EN EL PRIMER NODO DE LA PARTICIÓN (AVANZAMOS NODO)
posNode.pop_back(); //LIMPIAMOS NODO ACTUAL DEL VECTOR DEL CÓDIGO (STRING)
//END ALBERTO CONCEPT FORK
} while( partitioner.nextPart( *tempCS ) );//AVANZAMOS A LA SIGIENTE CU GENERADA EN TEMPCS } while( partitioner.nextPart( *tempCS ) );//AVANZAMOS A LA SIGIENTE CU GENERADA EN TEMPCS
//ALBERTO CONCEPT FORK
posNode = original;
actualNodeId = 0;
//END ALBERTO CONCEPT FORK
partitioner.exitCurrSplit(); partitioner.exitCurrSplit();
m_CurrCtx--; m_CurrCtx--;
if( chromaNotSplit ) if( chromaNotSplit )
......
...@@ -232,7 +232,7 @@ struct vectorModeCostStruct { ...@@ -232,7 +232,7 @@ struct vectorModeCostStruct {
int mode; int mode;
double cost; double cost;
int threadNumber; int threadNumber;
int posPadre; int posFather;
}; };
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
const int VECTOR_SIZE = 341; // TREE NODES const int VECTOR_SIZE = 341; // TREE NODES
...@@ -325,12 +325,11 @@ public: ...@@ -325,12 +325,11 @@ public:
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
void createAndInitSemaphore(); void createSharedVector();
void initStructVector(); void initStructVector();
void updateFatherAndThreadNumbers(int LevelLowIndex, int LevelUpIndex, int posPadreActual, int i); void updateFatherAndThreadNumbers(int LevelLowIndex, int LevelUpIndex, int posPadreActual, int i);
//END ALBERTO CONCEPT FORK void cleanCostModeVector();
// END ALBERTO CONCEPT FORK
void setDecCuReshaperInEncCU(EncReshape* pcReshape, ChromaFormat chromaFormatIdc) void setDecCuReshaperInEncCU(EncReshape* pcReshape, ChromaFormat chromaFormatIdc)
{ {
...@@ -344,7 +343,7 @@ public: ...@@ -344,7 +343,7 @@ public:
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
void compressCtuForks(CodingStructure &cs, const UnitArea &area, const unsigned ctuRsAddr, const EnumArray<int, ChannelType> &prevQP, const EnumArray<int, ChannelType> &currQP); void compressCtuForks(CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner);
//END ALBERTO CONCEPT FORK //END ALBERTO CONCEPT FORK
/// CTU analysis function /// CTU analysis function
...@@ -380,7 +379,10 @@ protected: ...@@ -380,7 +379,10 @@ protected:
bool digits_below_or_equal(std::string a, std::string b); bool digits_below_or_equal(std::string a, std::string b);
int determinePosNodeInVectorRec(std::string posNode, std::string posSearch, int index, int counter); int determinePosNodeInVectorRec(std::string posNode, std::string posSearch, int index, int counter);
int determinePosNodeInVector(std::string posNode); int determinePosNodeInVector(std::string posNode);
//END ALBERTO CONCEPT FORK int searchFirstChildEmpty(int posFather);
int searchFirstChild(int posFather);
void reduceVector();
// END ALBERTO CONCEPT FORK
void xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &pm, const EncTestMode &encTestMode, const ModeType modeTypeParent, bool &skipInterPass, double *splitRdCostBest); void xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &pm, const EncTestMode &encTestMode, const ModeType modeTypeParent, bool &skipInterPass, double *splitRdCostBest);
......
...@@ -103,6 +103,13 @@ bool EncModeCtrl::nextMode( const CodingStructure &cs, Partitioner &partitioner ...@@ -103,6 +103,13 @@ bool EncModeCtrl::nextMode( const CodingStructure &cs, Partitioner &partitioner
return !m_ComprCUCtxList.back().testModes.empty(); return !m_ComprCUCtxList.back().testModes.empty();
} }
//ALBERTO CONCEPT FORK
bool EncModeCtrl::lastModeAvailable( const CodingStructure &cs, Partitioner &partitioner )
{
return !m_ComprCUCtxList.empty() && !m_ComprCUCtxList.back().testModes.empty() && m_ComprCUCtxList.back().testModes.size()==1;
}
//END ALBERTO CONCEPT FORK
EncTestMode EncModeCtrl::currTestMode() const EncTestMode EncModeCtrl::currTestMode() const
{ {
return m_ComprCUCtxList.back().testModes.back(); return m_ComprCUCtxList.back().testModes.back();
......
...@@ -326,7 +326,10 @@ public: ...@@ -326,7 +326,10 @@ public:
void init ( EncCfg *pCfg, RateCtrl *pRateCtrl, RdCost *pRdCost ); void init ( EncCfg *pCfg, RateCtrl *pRateCtrl, RdCost *pRdCost );
bool tryModeMaster ( const EncTestMode& encTestmode, const CodingStructure &cs, Partitioner& partitioner ); bool tryModeMaster ( const EncTestMode& encTestmode, const CodingStructure &cs, Partitioner& partitioner );
bool nextMode ( const CodingStructure &cs, Partitioner &partitioner ); bool nextMode ( const CodingStructure &cs, Partitioner &partitioner );
EncTestMode currTestMode () const; //ALBERTO CONCEPT FORK
bool lastModeAvailable(const CodingStructure &cs, Partitioner &partitioner);
//END ALBERTO CONCEPT FORK
EncTestMode currTestMode() const;
EncTestMode lastTestMode () const; EncTestMode lastTestMode () const;
void setEarlySkipDetected (); void setEarlySkipDetected ();
void setIsHashPerfectMatch( bool b ) { m_ComprCUCtxList.back().isHashPerfectMatch = b; } void setIsHashPerfectMatch( bool b ) { m_ComprCUCtxList.back().isHashPerfectMatch = b; }
......
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