You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

269 lines
16 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __ONVIF_MEDIA_OBSERVER_HEADER__
  2. #define __ONVIF_MEDIA_OBSERVER_HEADER__
  3. #ifdef __linux__
  4. #include <fcntl.h>
  5. #else
  6. #include <winsock2.h>
  7. #endif
  8. #include "../../components/base/basicLogCollection.h"
  9. #include "../../components/base/basicSettingsProvider.h"
  10. #include "../protocol/xmlParser.h"
  11. #include <iostream>
  12. #include <string>
  13. #include <vector>
  14. #pragma warning(disable : 4251)
  15. #define MAX_BUFF_SIZE 102400 // 100K
  16. #define HTTPMU_HOST_ADDRESS "239.255.255.250"
  17. #define HTTPMU_HOST_PORT 3702
  18. /*
  19. #define SEARCH_REQUEST_STRING "M-SEARCH * HTTP/1.1\r\nST:ssdp:all\r\nMX: 3\r\nMAN:\"ssdp:discover\"\r\nHOST: 239.255.255.250:1900\r\n\r\n"
  20. //*/
  21. /*
  22. #define SEARCH_REQUEST_STRING "M-SEARCH * HTTP/1.1\r\n" \
  23. "ST:ssdp:all\r\n" \
  24. "MX: 3\r\n" \
  25. "MAN:\"ssdp:discover\"\r\n" \
  26. "HOST: 239.255.255.250:3702\r\n" \
  27. "\r\n"
  28. //*/
  29. #define SEARCH_REQUEST_STRING_0 \
  30. "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" \
  31. "<SOAP:Envelope xmlns:SOAP=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:DISCOVERY=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" " \
  32. "xmlns:ssdp=\"http://example.com/wsdp/sample/print\">\n" \
  33. "<SOAP:Header>\n" \
  34. "<wsa:MessageID>urn:uuid:ac9823ee-6813-498c-8c1b-6272a22353f7</wsa:MessageID>\n" \
  35. "<wsa:Action>\n" \
  36. "http ://schemas.xmlsoap.org/ws/2005/04/discovery/Probe\n" \
  37. "</wsa:Action>\n" \
  38. "<wsa:To>urn:schemas-xmlsoap-org:ws:2005:04:discovery</wsa:To>\n" \
  39. "</SOAP:Header>\n" \
  40. "<SOAP:Body>\n" \
  41. "<DISCOVERY:Probe>\n" \
  42. "<DISCOVERY:Types>ssdp:any</DISCOVERY:Types>\n" \
  43. "</DISCOVERY:Probe>\n" \
  44. "</SOAP:Body>\n" \
  45. "</SOAP:Envelope>\r\n\r\n"
  46. #define SEARCH_REQUEST_STRING_1 \
  47. "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" \
  48. "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:SOAP-ENC=\"http://www.w3.org/2003/05/soap-encoding\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " \
  49. "xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:wsdd=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" xmlns:tds=\"http://www.onvif.org/ver10/device/wsdl\" xmlns:dn=\"http://www.onvif.org/ver10/network/wsdl\">" \
  50. "<SOAP-ENV:Header>" \
  51. "<wsa:MessageID>urn:uuid:ac9823ee-6813-498c-8c1b-6272a22353f7</wsa:MessageID>" \
  52. "<wsa:To SOAP-ENV:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>\n" \
  53. "<wsa:Action SOAP-ENV:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2005/04/discovery/ProbeMatches</wsa:Action>" \
  54. "</SOAP-ENV:Header>" \
  55. "<SOAP-ENV:Body>" \
  56. "<wsdd:ProbeMatches>" \
  57. "<wsdd:ProbeMatch>" \
  58. "<wsdd:Types>dn:NetworkVideoTransmitter tds:Device</wsdd:Types>" \
  59. "<wsdd:Scopes>onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/type/audio_encoder onvif://www.onvif.org/type/ptz onvif://www.onvif.org/hardware/HD_PREDATOR " \
  60. "onvif://www.onvif.org/name/PREDATOR onvif://www.onvif.org/location/</wsdd:Scopes>" \
  61. "<wsdd:XAddrs>SERVICE_URI</wsdd:XAddrs>" \
  62. "<wsdd:MetadataVersion>1</wsdd:MetadataVersion>" \
  63. "</wsdd:ProbeMatch>" \
  64. "</wsdd:ProbeMatches>" \
  65. "<DISCOVERY:Probe>\n" \
  66. "<DISCOVERY:Types>dn:NetworkVideoTransmitter tds:Device</DISCOVERY:Types>\n" \
  67. "</DISCOVERY:Probe>\n" \
  68. "</SOAP-ENV:Body>" \
  69. "</SOAP-ENV:Envelope>"
  70. #define SEARCH_REQUEST_STRING \
  71. "<? xml version=\"1.0\" encoding=\"UTF-8\" ?>" \
  72. "<e:Envelope xmlns:e=\"http://www.w3.org/2003/05/soap-envelope\" " \
  73. "xmlns:w=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" " \
  74. "xmlns:d=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" " \
  75. "xmlns:dn=\"http://www.onvif.org/ver10/network/wsdl\"> " \
  76. "<e:Header>" \
  77. "<w:MessageID>uuid:84ede3de-7dec-11d0-c360-f01234567890</w:MessageID>" \
  78. "<w:To e:mustUnderstand=\"true\">urn:schemas-xmlsoap-org:ws:2005:04:discovery</w:To>" \
  79. "<w:Action a:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</w:Action>" \
  80. "</e:Header>" \
  81. "<e:Body><d:Probe><d:Types>dn:NetworkVideoTransmitter</d:Types></d:Probe></e:Body></e:Envelope>"
  82. #define HTTP_OK "200 OK"
  83. #define DEFAULT_HTTP_PORT 80
  84. /******************************************************************
  85. ** Action Defines *
  86. *******************************************************************/
  87. #define HTTP_HEADER_ACTION \
  88. "POST %s HTTP/1.1\r\n" \
  89. "HOST: %s:%u\r\n" \
  90. "SOAPACTION:\"%s#%s\"\r\n" \
  91. "CONTENT-TYPE: text/xml ; charset=\"utf-8\"\r\n" \
  92. "Content-Length: %d \r\n\r\n"
  93. #define SOAP_ACTION \
  94. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" \
  95. "<s:Envelope xmlns:s=" \
  96. "\"http://schemas.xmlsoap.org/soap/envelope/\" " \
  97. "s:encodingStyle=" \
  98. "\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n" \
  99. "<s:Body>\r\n" \
  100. "<u:%s xmlns:u=\"%s\">\r\n%s" \
  101. "</u:%s>\r\n" \
  102. "</s:Body>\r\n" \
  103. "</s:Envelope>\r\n"
  104. #define PORT_MAPPING_LEASE_TIME "63072000" // two year
  105. #define ADD_PORT_MAPPING_PARAMS \
  106. "<NewRemoteHost></NewRemoteHost>\r\n" \
  107. "<NewExternalPort>%u</NewExternalPort>\r\n" \
  108. "<NewProtocol>%s</NewProtocol>\r\n" \
  109. "<NewInternalPort>%u</NewInternalPort>\r\n" \
  110. "<NewInternalClient>%s</NewInternalClient>\r\n" \
  111. "<NewEnabled>1</NewEnabled>\r\n" \
  112. "<NewPortMappingDescription>%s</NewPortMappingDescription>\r\n" \
  113. "<NewLeaseDuration>" PORT_MAPPING_LEASE_TIME "</NewLeaseDuration>\r\n"
  114. class onvifMediaObserver;
  115. typedef struct S_resultWoWo
  116. {
  117. int wowoID;
  118. char Types[256];
  119. char XAddrs[1024];
  120. } resultWoWo;
  121. typedef vector<resultWoWo *> vectorWoWoResults;
  122. typedef struct S_probeWoWo
  123. {
  124. int AddressID;
  125. char IpAddress[16];
  126. int Port;
  127. int socketFD;
  128. char buff[MAX_BUFF_SIZE + 1];
  129. CSTR send_buff;
  130. CSTR recv_buff;
  131. struct sockaddr_in r_address;
  132. bool bOptVal;
  133. int bOptLen;
  134. int iOptLen;
  135. int RetVal;
  136. int index;
  137. int step;
  138. onvifMediaObserver * observer;
  139. } probeWoWo;
  140. typedef struct S_onvifObserverThread
  141. {
  142. #ifdef __linux__
  143. int m_dwThreadID;
  144. pthread_t m_hThreadHandle;
  145. #else
  146. DWORD m_dwThreadID;
  147. HANDLE m_hThreadHandle;
  148. #endif
  149. probeWoWo * context;
  150. } onvifObserverThread;
  151. typedef vector<onvifObserverThread *> onvifObserverThreads;
  152. /**
  153. * TODO: Add class description
  154. *
  155. * @author Gagua
  156. */
  157. class onvifMediaObserver
  158. {
  159. private:
  160. basicLogCollection * m_pLog;
  161. basicSettingsProvider * m_pSettings;
  162. config_setting_t * m_pSettingsNode;
  163. enumeratorInfo m_vLocalDevices;
  164. localIpAddresses * m_pIpAddresses;
  165. sourcePool m_vUsedDevices;
  166. vectorWoWoResults m_vResultPool;
  167. onvifObserverThreads m_vThreads;
  168. bool m_bWSAOK;
  169. int m_nStatus;
  170. // OnvifClientDevice *m_pDevice;
  171. public:
  172. // Method to fetch singleton instance.
  173. static onvifMediaObserver * getInstance();
  174. // Destructor
  175. virtual ~onvifMediaObserver();
  176. int getNetworkCounts()
  177. {
  178. return m_pIpAddresses->size();
  179. }
  180. bool startDiscovery(void);
  181. localIpAddresses * getNetworks(void)
  182. {
  183. return m_pIpAddresses;
  184. }
  185. vectorWoWoResults * getResults(void)
  186. {
  187. return &m_vResultPool;
  188. }
  189. int getStatus()
  190. {
  191. return m_nStatus;
  192. }
  193. protected:
  194. // Constructor - protected so users cannot call it.
  195. onvifMediaObserver();
  196. private:
  197. bool startProbe(CSTR IP, int ID, int stp);
  198. bool loadAssignedSources(void);
  199. static void * probeThreadProc(void *);
  200. probeWoWo * init_WoWo(CSTR ADR, int ID, int stp = 1);
  201. // private static member referencing the single instance of the object
  202. // TODO: Replace mediaVideoSourceManager with the type of object you want to
  203. // return the single instance of
  204. static onvifMediaObserver * _instance;
  205. // Copy constructor
  206. // Declared but not defined to prevent auto-generated
  207. // copy constructor. Refer to "Effective C++" by Meyers
  208. onvifMediaObserver(const onvifMediaObserver & src);
  209. // Assignment operator
  210. // Declared but not defined to prevent auto-generated
  211. // assignment operator. Refer to "Effective C++" by Meyers
  212. onvifMediaObserver & operator=(const onvifMediaObserver & src);
  213. };
  214. // Destructor implementation
  215. inline onvifMediaObserver::~onvifMediaObserver() {}
  216. // TODO: Uncomment the copy constructor when you need it.
  217. // inline mediaVideoSourceManager::mediaVideoSourceManager(const mediaVideoSourceManager& src)
  218. //{
  219. // // TODO: copy
  220. //}
  221. // TODO: Uncomment the assignment operator when you need it.
  222. // inline mediaVideoSourceManager& mediaVideoSourceManager::operator=(const mediaVideoSourceManager& rhs)
  223. //{
  224. // if (this == &rhs) {
  225. // return *this;
  226. // }
  227. //
  228. // // TODO: assignment
  229. //
  230. // return *this;
  231. //}
  232. #endif