#include "PL_BlockPredictor.h"
|
#include "MaterialBuffer.h"
|
#include "logger.h"
|
#include "MediaHelper.h"
|
|
#include <string.h> // for memcpy
|
#include <opencv2/core/mat.hpp>
|
#include <opencv2/imgproc.hpp>
|
|
struct PL_BlockPredictor_Internal
|
{
|
uint8_t* buffer;
|
size_t buffSize;
|
|
PL_BlockPredictor_Config config;
|
PipeMaterial pmList[2];
|
MB_Frame lastMbfBuffOrigin;
|
MB_Frame lastMbfBuffCopy;
|
|
bool payError;
|
|
PL_BlockPredictor_Internal() :
|
buffer(nullptr), buffSize(), config(), pmList(),
|
lastMbfBuffOrigin(), lastMbfBuffCopy(),
|
payError(true)
|
{
|
}
|
|
~PL_BlockPredictor_Internal()
|
{
|
reset();
|
}
|
|
void reset()
|
{
|
delete buffer;
|
buffer = nullptr;
|
buffSize = 0;
|
|
PL_BlockPredictor_Config _config;
|
config = _config;
|
|
PipeMaterial _pm;
|
pmList[0] = _pm;
|
pmList[1] = _pm;
|
|
MB_Frame _lastMbfBuff;
|
lastMbfBuffOrigin = _lastMbfBuff;
|
lastMbfBuffCopy = _lastMbfBuff;
|
|
payError = true;
|
}
|
};
|
|
PipeLineElem* create_PL_BlockPredictor()
|
{
|
return new PL_BlockPredictor;
|
}
|
|
PL_BlockPredictor::PL_BlockPredictor() : internal(new PL_BlockPredictor_Internal)
|
{
|
}
|
|
PL_BlockPredictor::~PL_BlockPredictor()
|
{
|
delete (PL_BlockPredictor_Internal*)internal;
|
internal= nullptr;
|
}
|
|
bool PL_BlockPredictor::init(void* args)
|
{
|
PL_BlockPredictor_Internal* in = (PL_BlockPredictor_Internal*)internal;
|
in->reset();
|
|
if (args != nullptr)
|
{
|
PL_BlockPredictor_Config* config = (PL_BlockPredictor_Config*)args;
|
in->config = *config;
|
}
|
|
return true;
|
}
|
|
void PL_BlockPredictor::finit()
|
{
|
PL_BlockPredictor_Internal* in = (PL_BlockPredictor_Internal*)internal;
|
|
}
|
|
bool PL_BlockPredictor::pay(const PipeMaterial& pm)
|
{
|
PL_BlockPredictor_Internal* in = (PL_BlockPredictor_Internal*)internal;
|
in->payError = true;
|
pm.breake(PipeMaterial::PMT_PTR, MB_Frame::MBFT__FIRST, fc_pm_breaker_ptr, _ctx);
|
pm.breake(PipeMaterial::PMT_FRAME, MB_Frame::MBFT__FIRST, fc_pm_breaker_frame, _ctx);
|
|
//#todo support RGB
|
|
return !(in->payError);
|
}
|
|
bool PL_BlockPredictor::gain(PipeMaterial& pm)
|
{
|
PL_BlockPredictor_Internal* in = (PL_BlockPredictor_Internal*)internal;
|
|
if (in->payError)
|
{
|
pm.former = this;
|
return false;
|
}
|
|
if (!in->config.copyData)
|
{
|
pm.type = PipeMaterial::PMT_FRAME;
|
pm.buffer = &(in->lastMbfBuffOrigin);
|
pm.buffSize = 0;
|
}
|
else
|
{
|
in->pmList[0].type = PipeMaterial::PMT_FRAME;
|
in->pmList[0].buffer = &(in->lastMbfBuffCopy);
|
in->pmList[0].buffSize = 0;
|
in->pmList[0].former = this;
|
|
in->pmList[1].type = PipeMaterial::PMT_FRAME;
|
in->pmList[1].buffer = &(in->lastMbfBuffOrigin);
|
in->pmList[1].buffSize = 0;
|
in->pmList[1].former = this;
|
|
pm.type = PipeMaterial::PMT_PM_LIST;
|
pm.buffer = in->pmList;
|
pm.buffSize = sizeof(in->pmList) / sizeof(PipeMaterial);
|
}
|
|
pm.former = this;
|
return true;
|
}
|