houxiao
2017-01-10 43af8d48ca0d2ec219a7641d5555fe4c2479b047
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
119
120
121
122
123
124
125
126
127
128
#include "PipeLine.h"
#include "PL_RTSPClient.h"
#include "PL_RTSPServer.h"
#include "PL_H264Decoder.h"
#include "PL_H264Encoder.h"
#include "PL_AVFrameYUV420.h"
#include "PL_AVFrameBGRA.h"
#include "PL_Queue.h"
#include "PL_Scale.h"
#include "PL_Fork.h"
#include "PL_SensetimeFaceTrack.h"
#include "PL_DlibFaceTrack.h"
 
#include "PipeLinePool.h"
 
#include "ev_server.h" 
#include "ev_proto.h"
 
#include "logger.h"
 
PipeLinePool g_PipeLinePool;
 
evclient_proc_t evclient_proc;
 
bool ev_proc_SensetimeFaceDetect(EVClientStub& client)
{
}
 
bool ev_proc(EVClientStub& client)
{
    EVPHeader* evpHeader = (EVPHeader*)client.recvBuff;
    //#todo check cmd and size
 
    //#test send 01000B0000004142434445
    //LOG_DEBUG << "cmd=" << evpHeader->cmd << ", size=" << evpHeader->size << ", \t" << (char*)(evpHeader + sizeof(EVPHeader));
    //return true;
    
    PipeLine* pipeLine = nullptr;
    if (g_PipeLinePool.wait_free())
        pipeLine = g_PipeLinePool.get_free();
    
    if (pipeLine == nullptr)
    {
        LOG_WARN << "can't get free pipeline";//#todo send err packet
        return false;
    }
    
    PipeMaterial pm;
    // fill
    
    PipeLineElem* plElem = pipeLine.pipe(&pm);
    if (! pipeLine.check_pipe_complete(plElem))
    {
        LOG_WARN << "pipeline not complete";
        g_PipeLinePool.release(pipeLine);//#todo send err packet
        return false;
    }
    
    if (!plElem->gain(pm))
    {
        LOG_WARN << "pipeline gain error";
        g_PipeLinePool.release(pipeLine);//#todo send err packet
        return false;
    }
 
    if (pm.type == PipeMaterial::PMT_PM_LIST)
    {
        PipeMaterial& facePM = ((PipeMaterial*)(pm.buffer))[1];
        st_ff_vect_t& faceFeatures = *((st_ff_vect_t*)facePM.buffer);
        LOG_NOTICE << "faceFeatures " << faceFeatures.size();
        //#todo send result packet
    }
    
    g_PipeLinePool.release(pipeLine);
    return false;
}
 
int main(int argc, char** argv)
{
    initLogger(LV_DEBUG);
    
    PipeLine::register_global_elem_creator("PL_SensetimeFaceTrack", create_PL_SensetimeFaceTrack);
    
    g_PipeLinePool = new PipeLinePool(true);
    
    for (int i = 0; i < 5; i++)
    {
        PipeLine* pipeLine = new PipeLine;
 
        {//payer//#todo
        }
        
        {
            SensetimeFaceTrackConfig config;
            config.generate_face_feature = true;
            PL_SensetimeFaceTrack* sensetimeFaceTrack = (PL_SensetimeFaceTrack*)pipeLine->push_elem("PL_SensetimeFaceTrack");
            bool ret = sensetimeFaceTrack->init(&config);
            if (!ret)
            {
                LOG_ERROR << "sensetimeFaceTrack init error";
                exit(EXIT_FAILURE);
            }
        }
        
        g_PipeLinePool.manage(pipeLine);
    }
    
    evclient_proc = ev_proc;
    return server_main(argc, argv);
 
    while(true)
        {
            //LOG_ERROR << "begin pipe";
 
            PipeMaterial pm;
            if (pipeLine.pipe(&pm) == sensetimeFaceTrack);
            sensetimeFaceTrack->gain(pm);
 
            if (pm.type == PipeMaterial::PMT_PM_LIST)
                {
                    PipeMaterial& facePM = ((PipeMaterial*)(pm.buffer))[1];
                    st_ff_vect_t& faceFeatures = *((st_ff_vect_t*)facePM.buffer);
                    LOG_NOTICE << "faceFeatures " << faceFeatures.size();
                }
 
            //LOG_ERROR << "end pipe";
        }
}