#include "FaceCache.h" #include "PipeLine.h" #include "MaterialBuffer.h" #include "PL_SensetimeFaceTrack.h" #include #include struct FcPmBreackerContext { uint8_t frameYUV[1920*1080*4]; size_t frameYUVSize; uint8_t frameRGB[1920*1080*4]; size_t frameRGBSize; st_ff_vect_t faceFeatures; bool dataAvailable; FcPmBreackerContext() : frameYUV(), frameYUVSize(0), frameRGB(), frameRGBSize(0), faceFeatures(), dataAvailable(false) { } void reset() { frameYUVSize = 0; frameRGBSize = 0; dataAvailable = false; faceFeatures.clear(); } bool convertYUV420ToRGB() { } }; bool fc_pm_breaker_ptr(const PipeMaterial* pm, void* args) { FcPmBreackerContext* ctx = (FcPmBreackerContext*)args; const st_ff_vect_t& faceFeatures(*(const st_ff_vect_t*)(pm->buffer)); ctx->faceFeatures = faceFeatures; ctx->dataAvailable &= true; return false; } bool fc_pm_breaker_frame(const PipeMaterial* pm, void* args) { FcPmBreackerContext* ctx = (FcPmBreackerContext*)args; const MB_Frame* lastFrame((const MB_Frame*)(pm->buffer)); if (lastFrame->type != MB_Frame::MBFT_YUV420) { ctx->dataAvailable &= false; return false; } if (lastFrame->buffSize == 0) { ctx->dataAvailable &= false; return false; } ctx->frameYUVSize = lastFrame->buffSize; memcpy(ctx->frameYUV, lastFrame->buffer, ctx->frameYUVSize); ctx->dataAvailable &= true; return false; } FaceCache::FaceCache() : _ctx(new FcPmBreackerContext) { } FaceCache::~FaceCache() { delete (FcPmBreackerContext*)_ctx; } // returns count of face int FaceCache::cachePm(const PipeMaterial& pm) { FcPmBreackerContext& ctx(*(FcPmBreackerContext*)_ctx); ctx.reset(); ctx.dataAvailable = 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); if (ctx.dataAvailable) return ctx.faceFeatures.size(); else return 0; } bool FaceCache::getFaceListPb(uint8_t* buffer, size_t& buffSize) { return false; } bool FaceCache::getFaceListImage(int* buffIdx, size_t& count, uint8_t* buffImg, size_t& buffImgSize) { return false; } bool FaceCache::extractFace() { FcPmBreackerContext& ctx(*(FcPmBreackerContext*)_ctx); if (ctx.frameRGBSize == 0) { if (! ctx.convertYUV420ToRGB()) return false; } }