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.

239 lines
8.9 KiB

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