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.

400 lines
9.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "objectCamera_ONVIF_PTZ.h"
  2. #include "../../data/onvif/include/onvifclient.hpp"
  3. #define LOG(X) m_pLog->Log("objectCamera_ONVIF_PTZ", this, X)
  4. #define LOG_ERROR(X) m_pLog->Log("objectCamera_ONVIF_PTZ", this, _LOG_ERROR, X)
  5. objectCamera_ONVIF_PTZ::objectCamera_ONVIF_PTZ(config_setting_t * Settings) :
  6. basicCameraPTZ(Settings)
  7. {
  8. m_pLog = basicLogCollection::getInstance();
  9. m_eControllProtocolType = PTZ_PROTO_ONVIF;
  10. m_pDeviceURI = NULL;
  11. m_pAccessUser = NULL;
  12. m_pAccessPassword = NULL;
  13. m_pProfileToken = NULL;
  14. }
  15. objectCamera_ONVIF_PTZ::~objectCamera_ONVIF_PTZ()
  16. {
  17. // Delete Video Source
  18. if (m_pVideoSource != NULL)
  19. {
  20. delete((videoAVLIBSource *) m_pVideoSource);
  21. };
  22. if (m_pDeviceURI != NULL)
  23. {
  24. delete(m_pDeviceURI);
  25. };
  26. if (m_pAccessUser != NULL)
  27. {
  28. delete(m_pAccessUser);
  29. };
  30. if (m_pAccessPassword != NULL)
  31. {
  32. delete(m_pAccessPassword);
  33. };
  34. }
  35. bool objectCamera_ONVIF_PTZ::create(void)
  36. {
  37. config_setting_t * pSetting;
  38. if (m_pSettings == NULL)
  39. {
  40. return false;
  41. }
  42. /* Load Srom Settings */
  43. if (! basicCameraPTZ::create())
  44. {
  45. return false;
  46. }
  47. pSetting = config_setting_get_member(m_pSettings, "DEVICE_URI");
  48. if (pSetting == NULL)
  49. {
  50. return false;
  51. }
  52. if (m_pDeviceURI == NULL)
  53. {
  54. m_pDeviceURI = (CSTR) malloc(255);
  55. }
  56. sprintf(m_pDeviceURI, "%s", config_setting_get_string(pSetting));
  57. pSetting = config_setting_get_member(m_pSettings, "ONVIF_USER");
  58. if (pSetting == NULL)
  59. {
  60. return false;
  61. }
  62. if (m_pAccessUser == NULL)
  63. {
  64. m_pAccessUser = (CSTR) malloc(255);
  65. }
  66. sprintf(m_pAccessUser, "%s", config_setting_get_string(pSetting));
  67. pSetting = config_setting_get_member(m_pSettings, "ONVIF_PASSWORD");
  68. if (pSetting == NULL)
  69. {
  70. return false;
  71. }
  72. if (m_pAccessPassword == NULL)
  73. {
  74. m_pAccessPassword = (CSTR) malloc(255);
  75. }
  76. sprintf(m_pAccessPassword, "%s", config_setting_get_string(pSetting));
  77. pSetting = config_setting_get_member(m_pSettings, "PROFILE_ID");
  78. if (pSetting == NULL)
  79. {
  80. return false;
  81. }
  82. m_nProfileID = config_setting_get_int(pSetting);
  83. // Init OnVif device Node
  84. m_pDeviceNode = new OnvifClientDevice(std::string(m_pDeviceURI), std::string(m_pAccessUser), std::string(m_pAccessPassword));
  85. if (m_pDeviceNode == NULL)
  86. {
  87. return false;
  88. }
  89. int RetVal;
  90. RetVal = m_pDeviceNode->GetCapabilities();
  91. if (RetVal == SOAP_ERR)
  92. {
  93. return false;
  94. }
  95. OnvifClientMedia media(*m_pDeviceNode);
  96. _trt__GetProfilesResponse profiles;
  97. RetVal = media.GetProfiles(profiles);
  98. if (RetVal == SOAP_ERR)
  99. {
  100. return false;
  101. }
  102. _trt__GetSnapshotUriResponse SnapshotUriResponse;
  103. _trt__GetStreamUriResponse StreamUriResponse;
  104. tt__StreamSetup StreamSetup;
  105. tt__MediaUri a;
  106. RetVal = media.GetSnapshotUri(SnapshotUriResponse, profiles.Profiles.at(m_nProfileID)->token);
  107. if (RetVal == SOAP_ERR)
  108. {
  109. return false;
  110. }
  111. RetVal = media.GetStreamUri(StreamUriResponse, StreamSetup, profiles.Profiles.at(m_nProfileID)->token);
  112. if (RetVal == SOAP_ERR)
  113. {
  114. return false;
  115. }
  116. m_pProfileToken = new std::string(profiles.Profiles.at(m_nProfileID)->token);
  117. m_pPtzNode = new OnvifClientPTZ(*m_pDeviceNode);
  118. if (m_pPtzNode == NULL)
  119. {
  120. return false;
  121. }
  122. RetVal = m_pPtzNode->Initialize();
  123. if (RetVal == SOAP_ERR)
  124. {
  125. return false;
  126. }
  127. if (m_sCameraInfo.m_pSourcePath == NULL)
  128. {
  129. m_sCameraInfo.m_pSourcePath = (CSTR) malloc(1024);
  130. }
  131. char prefix[8], postfix[1024];
  132. memcpy(prefix, StreamUriResponse.MediaUri->Uri.c_str(), 7);
  133. prefix[7] = '\0';
  134. memcpy(postfix, StreamUriResponse.MediaUri->Uri.c_str() + 7, strlen(StreamUriResponse.MediaUri->Uri.c_str()) - 7);
  135. postfix[strlen(StreamUriResponse.MediaUri->Uri.c_str()) - 7] = '\0';
  136. sprintf(m_sCameraInfo.m_pSourcePath, "%s%s:%s@%s", prefix, m_pAccessUser, m_pAccessPassword, postfix);
  137. // init video
  138. videoAVLIBSource * tSource;
  139. tSource = new videoAVLIBSource();
  140. if (tSource->open((CSTR) m_sCameraInfo.m_pSourcePath, false, 25, m_sCameraInfo.m_iSourcePort, m_sCameraInfo.m_iWidth, m_sCameraInfo.m_iHeight))
  141. {
  142. // tNode->setTimeLapse(3000);
  143. tSource->attachDestination(m_pVideoNode);
  144. tSource->setStreaming(true);
  145. m_pVideoSource = (basicMediaSource *) tSource;
  146. }
  147. else
  148. {
  149. delete tSource;
  150. return false;
  151. };
  152. return true;
  153. }
  154. bool objectCamera_ONVIF_PTZ::create(mediaSourceInfo * SI)
  155. {
  156. config_setting_t * pSetting;
  157. if (m_pSettings == NULL)
  158. {
  159. return false;
  160. }
  161. if (SI == NULL)
  162. {
  163. return false;
  164. }
  165. if (! basicCameraPTZ::create(SI))
  166. {
  167. return false;
  168. }
  169. pSetting = config_setting_get_member(m_pSettings, "DEVICE_URI");
  170. if (m_pDeviceURI == NULL)
  171. {
  172. m_pDeviceURI = (CSTR) malloc(255);
  173. }
  174. sprintf(m_pDeviceURI, "%s", SI->devicePath);
  175. if (pSetting == NULL)
  176. {
  177. pSetting = config_setting_add(m_pSettings, "DEVICE_URI", CONFIG_TYPE_STRING);
  178. };
  179. config_setting_set_string(pSetting, m_pDeviceURI);
  180. pSetting = config_setting_get_member(m_pSettings, "ONVIF_USER");
  181. if (m_pAccessUser == NULL)
  182. {
  183. m_pAccessUser = (CSTR) malloc(255);
  184. }
  185. sprintf(m_pAccessUser, "%s", SI->deviceName);
  186. if (pSetting == NULL)
  187. {
  188. pSetting = config_setting_add(m_pSettings, "ONVIF_USER", CONFIG_TYPE_STRING);
  189. };
  190. config_setting_set_string(pSetting, m_pAccessUser);
  191. pSetting = config_setting_get_member(m_pSettings, "ONVIF_PASSWORD");
  192. if (m_pAccessPassword == NULL)
  193. {
  194. m_pAccessPassword = (CSTR) malloc(255);
  195. }
  196. sprintf(m_pAccessPassword, "%s", SI->deviceName);
  197. if (pSetting == NULL)
  198. {
  199. pSetting = config_setting_add(m_pSettings, "ONVIF_PASSWORD", CONFIG_TYPE_STRING);
  200. };
  201. config_setting_set_string(pSetting, m_pAccessPassword);
  202. pSetting = config_setting_get_member(m_pSettings, "PROFILE_ID");
  203. m_nProfileID = SI->comTransportType;
  204. if (pSetting == NULL)
  205. {
  206. pSetting = config_setting_add(m_pSettings, "PROFILE_ID", CONFIG_TYPE_INT);
  207. };
  208. config_setting_set_int(pSetting, m_nProfileID);
  209. basicSettingsProvider::getInstance()->compromise();
  210. return create();
  211. }
  212. void objectCamera_ONVIF_PTZ::dispatch(basicEvent * Evt)
  213. {
  214. if (Evt->m_eClass == EVT_CLASS_SENSOR)
  215. {
  216. switch (Evt->m_eType)
  217. {
  218. case EVT_ALARM:
  219. // Basic Camera Reaction
  220. break;
  221. default: break;
  222. };
  223. }
  224. else if (Evt->m_eClass == EVT_CLASS_IMAGE)
  225. {
  226. switch (Evt->m_eType)
  227. {
  228. case EVT_COMMAND:
  229. basicCameraCommand * pData;
  230. pData = (basicCameraCommand *) Evt->m_pEvtData;
  231. // Basic Camera Commands
  232. switch (pData->m_cCode)
  233. {
  234. case CMD_CAMERA_INIT:
  235. // m_pProtocol->init();
  236. break;
  237. case CMD_CAMERA_SET_PTZ:
  238. // m_pProtocol->goAbsolute( cP, cT, cZ );
  239. break;
  240. default: break;
  241. };
  242. break;
  243. default: break;
  244. };
  245. };
  246. }
  247. void objectCamera_ONVIF_PTZ::cmdBeginPanLeft(void)
  248. {
  249. // m_pProtocol->goLeft();
  250. //_tptz__RelativeMoveResponse Responce;
  251. // tt__PTZVector Trans;
  252. _tptz__ContinuousMoveResponse Response;
  253. tt__Vector2D PanTilt; /* optional element of type tt:Vector2D */
  254. tt__Vector1D Zoom;
  255. tt__PTZSpeed Speed;
  256. LONG64 Timeout;
  257. Timeout = 5000;
  258. PanTilt.x = -1.f;
  259. PanTilt.y = 0.f;
  260. Zoom.x = 0.f;
  261. Speed.PanTilt = &PanTilt;
  262. Speed.Zoom = &Zoom;
  263. m_pPtzNode->ContinuousMove(Response, Speed, Timeout, *m_pProfileToken);
  264. // m_pPtzNode->RelativeMove(Responce, Trans, )
  265. }
  266. void objectCamera_ONVIF_PTZ::cmdBeginPanRight(void)
  267. {
  268. // m_pProtocol->goRight();
  269. _tptz__ContinuousMoveResponse Response;
  270. tt__Vector2D PanTilt; /* optional element of type tt:Vector2D */
  271. tt__Vector1D Zoom;
  272. tt__PTZSpeed Speed;
  273. LONG64 Timeout;
  274. Timeout = 5000;
  275. PanTilt.x = 1.f;
  276. PanTilt.y = 0.f;
  277. Zoom.x = 0.f;
  278. Speed.PanTilt = &PanTilt;
  279. Speed.Zoom = &Zoom;
  280. m_pPtzNode->ContinuousMove(Response, Speed, Timeout, *m_pProfileToken);
  281. }
  282. void objectCamera_ONVIF_PTZ::cmdEndManualPan(void)
  283. {
  284. // m_pProtocol->goStop();
  285. _tptz__StopResponse Responce;
  286. m_pPtzNode->Stop(Responce, true, true, *m_pProfileToken);
  287. }
  288. void objectCamera_ONVIF_PTZ::cmdBeginTiltUp(void)
  289. {
  290. // m_pProtocol->goUp();
  291. _tptz__ContinuousMoveResponse Response;
  292. tt__Vector2D PanTilt; /* optional element of type tt:Vector2D */
  293. tt__Vector1D Zoom;
  294. tt__PTZSpeed Speed;
  295. LONG64 Timeout;
  296. Timeout = 5000;
  297. PanTilt.x = 0.f;
  298. PanTilt.y = 1.f;
  299. Zoom.x = 0.f;
  300. Speed.PanTilt = &PanTilt;
  301. Speed.Zoom = &Zoom;
  302. m_pPtzNode->ContinuousMove(Response, Speed, Timeout, *m_pProfileToken);
  303. }
  304. void objectCamera_ONVIF_PTZ::cmdBeginTiltDown(void)
  305. {
  306. // m_pProtocol->goDown();
  307. _tptz__ContinuousMoveResponse Response;
  308. tt__Vector2D PanTilt; /* optional element of type tt:Vector2D */
  309. tt__Vector1D Zoom;
  310. tt__PTZSpeed Speed;
  311. LONG64 Timeout;
  312. Timeout = 5000;
  313. PanTilt.x = 0.f;
  314. PanTilt.y = -1.f;
  315. Zoom.x = 0.f;
  316. Speed.PanTilt = &PanTilt;
  317. Speed.Zoom = &Zoom;
  318. m_pPtzNode->ContinuousMove(Response, Speed, Timeout, *m_pProfileToken);
  319. }
  320. void objectCamera_ONVIF_PTZ::cmdEndManualTilt(void)
  321. {
  322. // m_pProtocol->goStop();
  323. _tptz__StopResponse Responce;
  324. m_pPtzNode->Stop(Responce, true, true, *m_pProfileToken);
  325. }
  326. void objectCamera_ONVIF_PTZ::cmdBeginZoomWide(void)
  327. {
  328. // m_pProtocol->startZoomWide();
  329. _tptz__ContinuousMoveResponse Response;
  330. tt__Vector2D PanTilt; /* optional element of type tt:Vector2D */
  331. tt__Vector1D Zoom;
  332. tt__PTZSpeed Speed;
  333. LONG64 Timeout;
  334. Timeout = 5000;
  335. PanTilt.x = 0.f;
  336. PanTilt.y = 0.f;
  337. Zoom.x = -1.f;
  338. Speed.PanTilt = &PanTilt;
  339. Speed.Zoom = &Zoom;
  340. m_pPtzNode->ContinuousMove(Response, Speed, Timeout, *m_pProfileToken);
  341. }
  342. void objectCamera_ONVIF_PTZ::cmdBeginZoomTele(void)
  343. {
  344. // m_pProtocol->startZoomTele();
  345. _tptz__ContinuousMoveResponse Response;
  346. tt__Vector2D PanTilt; /* optional element of type tt:Vector2D */
  347. tt__Vector1D Zoom;
  348. tt__PTZSpeed Speed;
  349. LONG64 Timeout;
  350. Timeout = 5000;
  351. PanTilt.x = 0.f;
  352. PanTilt.y = 0.f;
  353. Zoom.x = 1.f;
  354. Speed.PanTilt = &PanTilt;
  355. Speed.Zoom = &Zoom;
  356. m_pPtzNode->ContinuousMove(Response, Speed, Timeout, *m_pProfileToken);
  357. }
  358. void objectCamera_ONVIF_PTZ::cmdEndManualZoom(void)
  359. {
  360. // m_pProtocol->stopZoom();
  361. _tptz__StopResponse Responce;
  362. m_pPtzNode->Stop(Responce, true, true, *m_pProfileToken);
  363. }
  364. #undef LOG
  365. #undef LOG_ERROR