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.

303 lines
9.7 KiB

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