chenke
2017-08-09 784f977cc7f9b9aad8cc3528a4f2026c1f686a0a
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
#ifndef __CAMERAWRAPPER_CLIENT_H__
#define __CAMERAWRAPPER_CLIENT_H__
 
#define MAX_FACE 5
#define MAX_FACE_WIDTH 240
#define MAX_FACE_HEIGHT 320
#include "FaceCache.h"
 
#include <PipeLine.h>
#include <PL_RTSPClient.h>
#include <PL_AndroidMediaCodecDecoder.h>
#include <PL_AndroidSurfaceViewRender.h>
#include <PL_SensetimeFaceTrackMultiTrd.h>
#include <PL_Paint.h>
#include <PL_Scale.h>
//#include "looper.h"
#include <android/native_window_jni.h>
#include <media/NdkMediaCodec.h>
 
#include <pthread.h>
#include <jni.h>
 
class CameraWrapper
{
public:
    PipeLine* pipeLineDecoderDetector;
    PipeLine* pipeLineAnalyzer;
    PipeLine* pipeLineRender;
 
    PL_RTSPClient_Config rtspConfig;
    PL_AndroidMediaCodecDecoder_Config amcdConfig;
    PL_AndroidSurfaceViewRender_Config asvrConfig;
    SensetimeFaceTrackConfig sftConfig;
    PL_Scale_Config plScaleCfg;
 
    int cameraIdx;
    JavaVM* javaVM;
    JNIEnv* javaEnv;
    jclass faceCallbackClazz;
    jmethodID faceCallbackFunc;
    void* windowRender;
    void* windowDecode;
 
    pthread_t decoder_thid;
    pthread_t live_daemon_thid;
    pthread_mutex_t live_daemon_mut;
    bool running;
    volatile bool killed;
    time_t lastAliveTime;
 
    bool faceCacheLocked;
    //FaceCache faceCache;
    FaceCacheForPLBG faceCache;
 
    PLPLContext plplContext;
 
    std::map<int, std::wstring> faceLabels;
 
    std::string fontPath;
 
    CameraWrapper() : 
        pipeLineDecoderDetector(nullptr), pipeLineAnalyzer(nullptr), pipeLineRender(nullptr), rtspConfig(), amcdConfig(), asvrConfig(), sftConfig(),
        cameraIdx(0), javaVM(nullptr), javaEnv(nullptr), faceCallbackClazz(0), faceCallbackFunc(0), windowRender(nullptr), windowDecode(nullptr),
        decoder_thid(0), live_daemon_thid(0), live_daemon_mut(), running(false), killed(false), lastAliveTime(0),
        faceCacheLocked(false), faceCache(),
        plplContext(), faceLabels(), fontPath()
    {
    }
    
    ~CameraWrapper();
    
    bool start();
    void stop();
    bool initPl();
 
    void lockFace();
    void releaseFace();
    void fireFaceCount(int faceCount);
    void setFaceLabel(int st_track_id, const std::wstring& label);
 
private:
    static void* decoder_thd(void *arg);
    static void* live_daemon_thd(void *arg);
 
    bool resetPl();
    bool initPl_DecoderPl();
};
 
#endif