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.

246 lines
10 KiB

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