#include "PL_SocketGainer.h" #include "MaterialBuffer.h" #include "logger.h" struct PL_SocketGainer_Internal { uint8_t* buffer; size_t buffSize; size_t buffSizeMax; bool payError; PipeMaterial::PipeMaterialBufferType lastPmType; MB_Frame lastFrame; PL_SocketGainer_Config config; PL_SocketGainer_Internal() : buffer(nullptr), buffSize(0), buffSizeMax(0), payError(true), lastPmType(PipeMaterial::PMT_NONE), lastFrame(), config() { } ~PL_SocketGainer_Internal() { delete[] buffer; buffer = nullptr; } void reset() { buffSize = 0; payError = true; lastPmType = PipeMaterial::PMT_NONE; MB_Frame _lastFrame; lastFrame = _lastFrame; PL_SocketGainer_Config _config; config = _config; if (buffer != nullptr) { delete[] buffer; buffer = nullptr; buffSizeMax = 0; } } }; PipeLineElem* create_PL_SocketGainer() { return new PL_SocketGainer; } PL_SocketGainer::PL_SocketGainer() : internal(new PL_SocketGainer_Internal) { } PL_SocketGainer::~PL_SocketGainer() { delete (PL_SocketGainer_Internal*)internal; internal= nullptr; } bool PL_SocketGainer::init(void* args) { PL_SocketGainer_Internal* in = (PL_SocketGainer_Internal*)internal; in->reset(); if (args != nullptr) { PL_SocketGainer_Config* config = (PL_SocketGainer_Config*)args; in->config = *config; } if (in->config.toWidth <= 0 || in->config.toHeight <= 0) { LOG_ERROR << "Config toWidth and toHeight should > 0" << std::endl; return false; } return true; } void PL_SocketGainer::finit() { PL_SocketGainer_Internal* in = (PL_SocketGainer_Internal*)internal; } bool PL_SocketGainer::pay(const PipeMaterial& pm) { PL_SocketGainer_Internal* in = (PL_SocketGainer_Internal*)internal; in->payError = true; if (pm.buffer == nullptr) return false; bool ret = false; in->lastPmType = pm.type; switch(pm.type) { case PipeMaterial::PMT_BYTES: { //if (in->config.defaultBytesType <= 0 || // in->config.defaultBytesWidth <= 0 || in->config.defaultBytesHeight <= 0) //{ // LOG_ERROR << "defaultBytesType/defaultBytesWidth/defaultBytesHeight not set" << std::endl; // return false; //} // //ret = image_scale(in, (uint8_t*)pm.buffer, pm.buffSize, (MB_Frame::MBFType)(in->config.defaultBytesType), // in->config.defaultBytesWidth, in->config.defaultBytesHeight); } break; case PipeMaterial::PMT_FRAME: { //MB_Frame* frame = (MB_Frame*)pm.buffer; //switch(frame->type) //{ //case MB_Frame::MBFT_YUV420: //case MB_Frame::MBFT_BGRA: // in->lastFrame = *frame; // ret = image_scale(in, (uint8_t*)frame->buffer, frame->buffSize, frame->type, // frame->width, frame->height); // break; //default: // LOG_ERROR << "Only support MBFT_YUV420 / MBFT_BGRA" << std::endl; // return false; //} } break; default: LOG_ERROR << "Only support PMT_BYTES / PMT_FRAME" << std::endl; return false; } in->payError = !ret; return ret; } bool PL_SocketGainer::gain(PipeMaterial& pm) { PL_SocketGainer_Internal* in = (PL_SocketGainer_Internal*)internal; PipeMaterial newPm; newPm.type = PipeMaterial::PMT_NONE; newPm.former = this; switch(in->lastPmType) { case PipeMaterial::PMT_BYTES: { newPm.type = PipeMaterial::PMT_BYTES; newPm.buffer = in->buffer; newPm.buffSize = in->buffSize; } break; case PipeMaterial::PMT_FRAME: { newPm.type = PipeMaterial::PMT_FRAME; newPm.buffer = &(in->lastFrame); newPm.buffSize = 0; in->lastFrame.buffer = in->buffer; in->lastFrame.buffSize = in->buffSize; in->lastFrame.width = in->config.toWidth; in->lastFrame.height = in->config.toHeight; } break; default: LOG_ERROR << "Only support PMT_BYTES / PMT_FRAME" << std::endl; } pm = newPm; return !in->payError; }