派生自 development/c++

chenshijun
2019-04-10 b5ac5f7d1e0f79d332dcddc3dabd8709b1e2a2ea
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
//
// Created by ps on 18-9-26.
//
 
#ifndef RTSPANALYSMANAGER
#define RTSPANALYSMANAGER
 
#include <iostream>
#include <map>
#include "RtspCaptureElement.h"
#include "RtspImageRedis.h"
//#include "../GB28181DecoderModel/VideoCaptureElementWithRtp.h"
#include "pushStream/PushStreamAppPipeController.h"
//#include <VideoCaptureElementWithRtp.h>
#include <QiaoJia/DB/LDBTool.h>
#include <basic/util/app/AppPreference.hpp>
#include "RtspAnalysServer.h"
 
#include "NsqMsgTool.hpp"
//#include <GB28181DecoderModel/VideoCaptureElementWithRtp.h>
//#include <VideoToImageMulth/rpc/RtspAnalysServer.h>
 
//using BASICGB28181::VideoCaptureElementWithRtp;
//外部使用的全局指针
extern void *gRtspAnalysManagerCamera;
 
//用来实现recordVideo的RPC的接口类
class RtspAnalysManager : public ::RtspAnalys::RtspAnalysServer {
 
public:
 
    RtspAnalysManager() : m_maxCount(50), m_currentCount(0) {
        m_lDBTool = new LDBTool;
        init();
        IMPORT_APP_ARGS;
        //nsq   set callback func
        DBG("NsqMsgConsumer Init");
        DBG("argv[0]:" << argv[0]);
        if(argv[0][0] == '.' && argv[0][1] == '/'){
            string pName(argv[0]+2, argv[0]+strlen(argv[0]));
            DBG("pName:" << pName);
            nsqMsgConsumer = new BasicMsg::Nsq::NsqMsgConsumer("127.0.0.1", "4150", pName,
                                                               to_string(appPref.getIntData("RpcVTIMPort")));
        }else{
            string pName(argv[0]);
            DBG("pName:" << pName);
            nsqMsgConsumer = new BasicMsg::Nsq::NsqMsgConsumer("127.0.0.1", "4150", pName,
                                                               to_string(appPref.getIntData("RpcVTIMPort")));
        }
 
        nsqMsgConsumer->setMessageCallback(std::bind(&OnMsgFunc, std::placeholders::_1, this));
        nsqMsgConsumer->init();
        DBG("NsqMsgConsumer Init END!!");
    }
 
    RtspAnalysManager(LDBTool *_dbTool);
 
    virtual ::std::string recordVideo(const ::std::string &, const ::Ice::Current & = ::Ice::emptyCurrent);
 
    virtual ~RtspAnalysManager();
 
    int addCamera(const std::string &, const std::string &rtsp);
 
    int removeCamera(const std::string &);
 
    int removeAll();
 
    int getMaxCamCount();
 
    int getCurrentCamCount();
 
    // 根据camId保存img到Redis,img的Key为imageName
    bool SaveImageToRedis(const std::string &camId, const std::string &imageName, const cv::Mat &img);
 
private:
    void init();
 
    static void OnMsgFunc(void *msgPtr, void *pThisPtr);
 
private:
 
    //nsq
    BasicMsg::Nsq::NsqMsgConsumer *nsqMsgConsumer;
 
    RWLock m_imgRedisCRwLock;
 
    LDBTool *m_lDBTool;
 
    int m_GB28181_Enable;
 
    //保存CamID和RtspCaptureElement的映射关系
    std::map<std::string, RtspCaptureElement *> m_controllers;
 
    //保存CamID和VideoCaptureElementWithRtp的映射关系
//    std::map<std::string, BASICGB28181::VideoCaptureElementWithRtp *> m_controllers_videoCapElem;
    std::map<std::string, PushStreamAppPipeController *> m_controllers_videoCapElem;
 
    //保存CamID和RtspImageRedisElement的映射关系
    std::map<std::string, RtspImageRedisElement *> m_imgRedisControllers;
    //当前摄像头的数量
    int m_currentCount;
    // 摄像头的最大数量
    int m_maxCount;
 
};
 
 
#endif //VIDEOANALYSFROMHC_RTSPANALYSELEMENT_H