houxiao
2017-03-23 d1452b28907abdb5247c0584ba2e1fcc9bd14410
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "FaceCache.h"
#include "PipeLine.h"
#include "MaterialBuffer.h"
#include "PL_SensetimeFaceTrack.h"
#include <logger.h>
#include <Logger/src/logger.hpp>
 
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;
    }
    
    
}