Blame view

src/decoder/gb28181/sip/SipServer.h 4.09 KB
c8285c8d   Hu Chunming   GB28181 UDP 有重大进展...
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
  //

  // Created bxc on 2022/11/25.

  //

  

  #ifndef BXC_SIPSERVER_SIPSERVER_H

  #define BXC_SIPSERVER_SIPSERVER_H

  

  extern "C" {

  #include <osip2/osip_mt.h>

  #include <eXosip2/eXosip.h>

  }

  

  #include <map>

  #include <string>

  #include <thread>

  #include <chrono>

  

  #include "./Message/CatalogParser.h"

  

  using namespace std;

  

  class ServerInfo {

  public:

      ServerInfo() {}

  

      ServerInfo(string ua,string nonce, string ip, int port,

                          string sipId, string sipRealm, string sipPass, int sipTimeout, int sipExpiry):

                          mUa(ua),

                          mNonce(nonce),mIp(ip),mPort(port),mSipId(sipId),

                          mSipRealm(sipRealm),mSipPass(sipPass),mSipTimeout(sipTimeout),

                          mSipExpiry(sipExpiry){}

  

      ~ServerInfo() = default;

  public:

      string getUa() const{

          return mUa;

      }

      string  getNonce() const{

          return mNonce;

      }

      string  getIp() const{

          return mIp;

      }

      int getPort() const {

          return mPort;

      }

      string  getSipId() const{

          return mSipId;

      }

      string  getSipRealm() const{

          return mSipRealm;

      }

      string  getSipPass() const{

          return mSipPass;

      }

      int getTimeout() const {

          return mSipTimeout;

      }

      int getExpiry() const {

          return mSipExpiry;

      }

  

  private:

      string mUa;

      string mNonce;//SIP服务随机数值

      string mIp;//SIP服务IP

      int    mPort;//SIP服务端口

      string mSipId; //SIP服务器ID

      string mSipRealm;//SIP服务器域

      string mSipPass;//SIP password

      int mSipTimeout; //SIP timeout

      int mSipExpiry;// SIP到期

  };

  

  class Client {

  public:

      Client(string ip, int port, string device) :

              mIp(ip),

              mPort(port),

              mRtpPort(0),

              mDevice(device),

              mIsReg(false){

      }

      ~Client() = default;

  public:

  

      void setRtpPort(int rtpPort) {

          mRtpPort = rtpPort;

      }

  

      void setReg(bool isReg) {

          mIsReg = isReg;

      }

      string  getDevice() const{

          return mDevice;

      }

      string  getIp() const{

          return mIp;

      }

      int getPort() const{

          return mPort;

      }

  

  private:

      // step1

      string mIp; // client ip

      int mPort; // client port

      string mDevice;// 340200000013200000024

      // step2

      bool mIsReg;

      // step3

      int mRtpPort{};

  

  };

  

  

  class SipServer {

  public:

74d1e6a8   Hu Chunming   完成gb28181大体的代码,未完...
119
120
121
122
123
124
125
126
127
      static SipServer* getInstance(){

  		static SipServer* singleton = nullptr;

  		if (singleton == nullptr){

  			singleton = new SipServer();

  		}

  		return singleton;

  	}

      

  public:

c8285c8d   Hu Chunming   GB28181 UDP 有重大进展...
128
129
      SipServer();

      ~SipServer();

74d1e6a8   Hu Chunming   完成gb28181大体的代码,未完...
130
  

c8285c8d   Hu Chunming   GB28181 UDP 有重大进展...
131
      bool Init(ServerInfo info);

c8285c8d   Hu Chunming   GB28181 UDP 有重大进展...
132
  

74d1e6a8   Hu Chunming   完成gb28181大体的代码,未完...
133
      int RequestInvite_UDP(const char* dst_channel, int rtpPort);

c8285c8d   Hu Chunming   GB28181 UDP 有重大进展...
134
  

74d1e6a8   Hu Chunming   完成gb28181大体的代码,未完...
135
      int RequestInvite_TCP_a(const char* dst_channel, int rtpPort);

c8285c8d   Hu Chunming   GB28181 UDP 有重大进展...
136
  

fe625b06   Hu Chunming   设备状态的检查与定时更新
137
      void close();

c8285c8d   Hu Chunming   GB28181 UDP 有重大进展...
138
139
140
  

  public:

      void event_loop();

fe625b06   Hu Chunming   设备状态的检查与定时更新
141
      void timing_getcatlog();

c8285c8d   Hu Chunming   GB28181 UDP 有重大进展...
142
143
144
145
146
147
  

  private:

      int init_sip_server();

      int sip_event_handle(eXosip_event_t *evtp);

  

      void RequestCatalog(Client* client);

fe625b06   Hu Chunming   设备状态的检查与定时更新
148
      void cacheCatalog();

c8285c8d   Hu Chunming   GB28181 UDP 有重大进展...
149
150
151
152
153
154
155
156
157
158
159
160
  

      void response_message_answer(eXosip_event_t *evtp,int code);

      void response_register(eXosip_event_t *evtp);

      void response_register_401unauthorized(eXosip_event_t *evt);

      void response_message(eXosip_event_t *evtp);

      void response_invite_ack(eXosip_event_t *evtp);

      int request_bye(eXosip_event_t* evtp);// 通知相机停止推流

      int parse_xml(const char* data, const char* s_mark, bool with_s_make, const char* e_mark, bool with_e_make, char* dest);

      void dump_request(eXosip_event_t *evtp);

      void dump_response(eXosip_event_t *evtp);

  

      int clearClientMap();

0af3b245   Hu Chunming   添加多nvr和多摄像头管理
161
162
163
      void deleteClientByDevice(string device);

  

      Client* get_parent_by_id(string id);

fe625b06   Hu Chunming   设备状态的检查与定时更新
164
      bool check_device_status(string id);

c8285c8d   Hu Chunming   GB28181 UDP 有重大进展...
165
166
167
168
169
170
171
  

  private:

      bool mQuit{ false };

      eXosip_t *mSipCtx;

      ServerInfo mInfo;

  

      std::map<std::string, Client *> mClientMap;// <DeviceID,SipClient>

0af3b245   Hu Chunming   添加多nvr和多摄像头管理
172
      std::map<std::string, DeviceInfo> m_device_map;

c8285c8d   Hu Chunming   GB28181 UDP 有重大进展...
173
174
175
176
177
178
  

      thread* m_event_loop_thread;

  };

  

  

  #endif //BXC_SIPSERVER_SIPSERVER_H