houxiao
2017-08-17 0250edfd9c4d453f25a2f9827698ccf87ff5afff
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
#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 "logger.h"
 
int main(int argc, char** argv)
{
    initLogger(LV_INFO);
 
    PipeLine pipeLine;
    
    PipeLine::register_global_elem_creator("PL_RTSPClient", create_PL_RTSPClient);
    //PipeLine::register_global_elem_creator("PL_RTSPServer", create_PL_RTSPServer);
    PipeLine::register_global_elem_creator("PL_H264Decoder", create_PL_H264Decoder);
    PipeLine::register_global_elem_creator("PL_AVFrameYUV420", create_PL_AVFrameYUV420);
    //PipeLine::register_global_elem_creator("PL_H264Encoder", create_PL_H264Encoder);
    //PipeLine::register_global_elem_creator("PL_Queue", create_PL_Queue);
    PipeLine::register_global_elem_creator("PL_Scale", create_PL_Scale);
    //PipeLine::register_global_elem_creator("PL_Fork", create_PL_Scale);
    
    pipeLine.register_elem_creator("PL_SensetimeFaceTrack", create_PL_SensetimeFaceTrack);
    
    {
        PL_RTSPClient* rtspClient = (PL_RTSPClient*)pipeLine.push_elem("PL_RTSPClient");
        PL_RTSPClient_Config rtspConfig;
        rtspConfig.progName = argv[0];
        rtspConfig.rtspURL = argv[1];
        rtspConfig.aux = true; // ffmpeg need aux, but live555 not
        rtspConfig.verbosityLevel = 1;
        rtspConfig.tunnelOverHTTPPortNum = 0;
        rtspConfig.args = nullptr;
        bool ret = rtspClient->init(&rtspConfig);
        if (!ret)
        {
            LOG_ERROR << "rtspClient.init error" << std::endl;
            exit(EXIT_FAILURE);
        }
    }
 
    {
        PL_H264Decoder* h264Decoder = (PL_H264Decoder*)pipeLine.push_elem("PL_H264Decoder");
        bool ret = h264Decoder->init(nullptr);
        if (!ret)
        {
            LOG_ERROR << "PL_H264Decoder.init error" << std::endl;
            exit(EXIT_FAILURE);
        }
    }
 
    {
        PL_AVFrameYUV420* avFrameYUV420 = (PL_AVFrameYUV420*)pipeLine.push_elem("PL_AVFrameYUV420");
        bool ret = avFrameYUV420->init(nullptr);
        if (!ret)
        {
            LOG_ERROR << "PL_AVFrameYUV420.init error" << std::endl;
            exit(EXIT_FAILURE);
        }
    }
    
    {
        PL_Scale_Config config;
        config.toWidth = 800;
        config.toHeight = 600;
        PL_Scale* ple = (PL_Scale*)pipeLine.push_elem("PL_Scale");
        bool ret = ple->init(&config);
        if (!ret)
        {
            LOG_ERROR << "PL_Scale.init error" << std::endl;
            exit(EXIT_FAILURE);
        }
    }
 
    PL_SensetimeFaceTrack* sensetimeFaceTrack;
    {
        SensetimeFaceTrackConfig config;
        config.generate_face_feature = true;
        sensetimeFaceTrack = (PL_SensetimeFaceTrack*)pipeLine.push_elem("PL_SensetimeFaceTrack");
        sensetimeFaceTrack->init(&config);
    }
 
    while(true)
    {
        //LOG_ERROR << "begin pipe" << std::endl;
        
        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() << std::endl;
        }
        
        //LOG_ERROR << "end pipe" << std::endl;
    }
}