#include "PL_Payer.h"
|
#include "MaterialBuffer.h"
|
#include "logger.h"
|
|
#include <string.h> // for memcpy
|
|
struct PL_Payer_Internal
|
{
|
PL_Payer_Config config;
|
PipeMaterial lastPm;
|
MB_Frame lastFrame;
|
|
PL_Payer_Internal() :
|
config(), lastPm(), lastFrame()
|
{
|
}
|
|
~PL_Payer_Internal()
|
{
|
}
|
|
void reset()
|
{
|
PL_Payer_Config _config;
|
config = _config;
|
|
PipeMaterial _lastPm;
|
lastPm = _lastPm;
|
|
MB_Frame _lastFrame;
|
lastFrame = _lastFrame;
|
}
|
};
|
|
PipeLineElem* create_PL_Payer()
|
{
|
return new PL_Payer;
|
}
|
|
PL_Payer::PL_Payer() : internal(new PL_Payer_Internal)
|
{
|
}
|
|
PL_Payer::~PL_Payer()
|
{
|
}
|
|
bool PL_Payer::init(void* args)
|
{
|
PL_Payer_Internal* in = (PL_Payer_Internal*)internal;
|
in->reset();
|
|
if (args != nullptr)
|
{
|
PL_Payer_Config* config = (PL_Payer_Config*)args;
|
in->config = *config;
|
}
|
|
return true;
|
}
|
|
void PL_Payer::finit()
|
{
|
PL_Payer_Internal* in = (PL_Payer_Internal*)internal;
|
|
}
|
|
void pl_payer_deleter_func(PipeMaterial* pm)
|
{//#todo
|
}
|
|
bool PL_Payer::pay(const PipeMaterial& pm)
|
{
|
PL_Payer_Internal* in = (PL_Payer_Internal*)internal;
|
|
in->lastPm = pm;
|
|
if (in->config.copyData)
|
{
|
switch(pm.type)
|
{
|
case PipeMaterial::PMT_BYTES:
|
{
|
in->lastPm.buffer = new uint8_t[pm.buffSize];
|
memcpy(in->lastPm.buffer, pm.buffer, pm.buffSize);
|
in->lastPm.args = in;
|
in->lastPm.deleter = pl_payer_deleter_func;
|
}
|
break;
|
case PipeMaterial::PMT_FRAME:
|
{
|
MB_Frame* pmFrame = (MB_Frame*)(pm.buffer);
|
in->lastFrame = *pmFrame;
|
in->lastFrame.buffer = new uint8_t[pmFrame->buffSize];
|
memcpy(in->lastFrame.buffer, pmFrame->buffer, pmFrame->buffSize);
|
|
in->lastPm.buffer = &(in->lastFrame);
|
in->lastPm.args = in;
|
in->lastPm.deleter = pl_payer_deleter_func;
|
}
|
break;
|
default:
|
//#todo support list or pm::copier operator
|
LOG_ERROR << "Only support PMT_BYTES / PMT_FRAME" << std::endl;
|
}
|
}
|
|
in->lastPm.former = this;
|
return true;
|
}
|
|
bool PL_Payer::gain(PipeMaterial& pm)
|
{
|
//PL_Payer_Internal* in = (PL_Payer_Internal*)internal;
|
//
|
//pm = in->lastPm;
|
//
|
//return true;
|
|
return false;
|
}
|