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.

484 lines
14 KiB

7 years ago
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
7 years ago
​
​
7 years ago
​
​
7 years ago
​
​
7 years ago
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
7 years ago
​
7 years ago
​
​
7 years ago
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
7 years ago
​
7 years ago
​
​
​
​
​
​
​
7 years ago
​
7 years ago
​
7 years ago
​
​
​
7 years ago
​
7 years ago
​
​
​
7 years ago
​
7 years ago
​
​
​
7 years ago
​
7 years ago
​
​
​
7 years ago
​
7 years ago
​
​
​
7 years ago
​
7 years ago
​
​
​
7 years ago
​
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
7 years ago
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
7 years ago
7 years ago
​
​
​
​
​
7 years ago
7 years ago
​
​
​
​
​
7 years ago
7 years ago
​
​
​
​
​
7 years ago
7 years ago
​
​
​
​
​
7 years ago
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
7 years ago
​
  1. #include "basicCamera.h"
  2. // Constructor implementation
  3. basicCamera::basicCamera(config_setting_t * Settings) :
  4. basicObject(),
  5. basicPosition(),
  6. basicEventHandler()
  7. {
  8. m_eCaps = (objectCaps) (OC_EVENT_HANDLER);
  9. m_pSettings = Settings;
  10. m_iStatus = PS_BORN;
  11. memset(&m_sSourceInfo, 0, sizeof(SOURCE_INFO));
  12. // m_sSourceInfo.fSensorSize = ( 1.f / 2.8f ) * .0254f; // in meters
  13. m_pVideoSource = NULL;
  14. m_pVideoNode = new videoNode(m_pSettings);
  15. }
  16. // Destructor implementation
  17. basicCamera::~basicCamera()
  18. {
  19. m_vOSD.clear();
  20. updateSettings();
  21. if (m_pVideoNode != NULL)
  22. {
  23. m_pVideoNode->setStatus(TH_EXIT);
  24. delete(m_pVideoNode);
  25. };
  26. }
  27. bool basicCamera::create(void)
  28. {
  29. config_setting_t * pSetting;
  30. if (m_pSettings == NULL)
  31. {
  32. return false;
  33. }
  34. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_TYPE);
  35. if (pSetting == NULL)
  36. {
  37. return false;
  38. }
  39. m_sSourceInfo.type = config_setting_get_int(pSetting);
  40. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_TYPE);
  41. if (pSetting == NULL)
  42. {
  43. return false;
  44. }
  45. m_sSourceInfo.subtype = config_setting_get_int(pSetting);
  46. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_WIDTH);
  47. if (pSetting == NULL)
  48. {
  49. return false;
  50. }
  51. m_sSourceInfo.width = config_setting_get_int(pSetting);
  52. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_HEIGHT);
  53. if (pSetting == NULL)
  54. {
  55. return false;
  56. }
  57. m_sSourceInfo.height = config_setting_get_int(pSetting);
  58. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_NAME);
  59. if (pSetting == NULL)
  60. {
  61. return false;
  62. }
  63. sprintf(m_sSourceInfo.deviceName, "%s", config_setting_get_string(pSetting));
  64. if (m_sSourceInfo.subtype != 1)
  65. {
  66. if (m_sSourceInfo.subtype == 0)
  67. {
  68. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PORT);
  69. if (pSetting == NULL)
  70. {
  71. return false;
  72. }
  73. m_sSourceInfo.capturePin = config_setting_get_int(pSetting);
  74. };
  75. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PATH);
  76. if (pSetting == NULL)
  77. {
  78. return false;
  79. }
  80. sprintf(m_sSourceInfo.devicePath, "%s", config_setting_get_string(pSetting));
  81. }
  82. else
  83. {
  84. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_VIDEO_MRL);
  85. if (pSetting == NULL)
  86. {
  87. return false;
  88. }
  89. sprintf(m_sSourceInfo.onvifVideoMRL, "%s", config_setting_get_string(pSetting));
  90. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_PICTURE_MRL);
  91. if (pSetting == NULL)
  92. {
  93. return false;
  94. }
  95. sprintf(m_sSourceInfo.onvifPictureMRL, "%s", config_setting_get_string(pSetting));
  96. };
  97. /*Location*/
  98. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT);
  99. if (pSetting == NULL)
  100. {
  101. return false;
  102. }
  103. m_sSourceInfo.lat = (float) config_setting_get_float(pSetting);
  104. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON);
  105. if (pSetting == NULL)
  106. {
  107. return false;
  108. }
  109. m_sSourceInfo.lon = (float) config_setting_get_float(pSetting);
  110. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT);
  111. if (pSetting == NULL)
  112. {
  113. return false;
  114. }
  115. m_sSourceInfo.alt = (float) config_setting_get_float(pSetting);
  116. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ROLL);
  117. if (pSetting == NULL)
  118. {
  119. return false;
  120. }
  121. m_sSourceInfo.h_lat = (float) config_setting_get_float(pSetting);
  122. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_PITCH);
  123. if (pSetting == NULL)
  124. {
  125. return false;
  126. }
  127. m_sSourceInfo.h_lon = (float) config_setting_get_float(pSetting);
  128. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_YAW);
  129. if (pSetting == NULL)
  130. {
  131. return false;
  132. }
  133. m_sSourceInfo.h_alt = (float) config_setting_get_float(pSetting);
  134. setPositionDeg(m_sSourceInfo.lat, m_sSourceInfo.lon, m_sSourceInfo.alt, m_sSourceInfo.h_lat, m_sSourceInfo.h_lon, m_sSourceInfo.h_alt);
  135. return true;
  136. }
  137. bool basicCamera::create(SOURCE_INFO * SI)
  138. {
  139. config_setting_t * pSetting;
  140. if (m_pSettings == NULL)
  141. {
  142. return false;
  143. }
  144. if (SI == NULL)
  145. {
  146. return false;
  147. }
  148. memcpy(&m_sSourceInfo, SI, sizeof(SOURCE_INFO));
  149. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_TYPE);
  150. if (pSetting == NULL)
  151. {
  152. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_TYPE, CONFIG_TYPE_INT);
  153. };
  154. config_setting_set_int(pSetting, m_sSourceInfo.type);
  155. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_TYPE);
  156. if (pSetting == NULL)
  157. {
  158. pSetting = config_setting_add(m_pSettings, BCI_TAG_SOURCE_TYPE, CONFIG_TYPE_INT);
  159. };
  160. config_setting_set_int(pSetting, m_sSourceInfo.subtype);
  161. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_NAME);
  162. if (pSetting == NULL)
  163. {
  164. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_NAME, CONFIG_TYPE_STRING);
  165. };
  166. config_setting_set_string(pSetting, m_sSourceInfo.deviceName);
  167. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_WIDTH);
  168. // if (SI->frameIsWide){
  169. // m_sCameraInfo.m_iWidth = g_aFrameWidthStandard_16_9[SI->sizeId];
  170. // } else {
  171. // m_sCameraInfo.m_iWidth = g_aFrameWidthStandard_4_3[SI->sizeId];
  172. // };
  173. if (pSetting == NULL)
  174. {
  175. pSetting = config_setting_add(m_pSettings, BCI_TAG_IMAGE_WIDTH, CONFIG_TYPE_INT);
  176. };
  177. config_setting_set_int(pSetting, m_sSourceInfo.width);
  178. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_HEIGHT);
  179. // if (SI->frameIsWide){
  180. // m_sCameraInfo.m_iHeight = g_aFrameHeightStandard_16_9[SI->sizeId];
  181. // } else {
  182. // m_sCameraInfo.m_iHeight = g_aFrameHeightStandard_4_3[SI->sizeId];
  183. // };
  184. if (pSetting == NULL)
  185. {
  186. pSetting = config_setting_add(m_pSettings, BCI_TAG_IMAGE_HEIGHT, CONFIG_TYPE_INT);
  187. };
  188. config_setting_set_int(pSetting, m_sSourceInfo.height);
  189. /*Location*/
  190. // float tLat, tLon, tAlt, tRoll, tPitch, tYaw;
  191. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT);
  192. // tLat = systemAnchor::getInstance()->getLat();
  193. if (pSetting == NULL)
  194. {
  195. pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT);
  196. };
  197. config_setting_set_float(pSetting, m_sSourceInfo.lat);
  198. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON);
  199. // tLon = systemAnchor::getInstance()->getLon();
  200. if (pSetting == NULL)
  201. {
  202. pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT);
  203. };
  204. config_setting_set_float(pSetting, m_sSourceInfo.lon);
  205. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT);
  206. // tAlt = systemAnchor::getInstance()->getAlt();
  207. if (pSetting == NULL)
  208. {
  209. pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT);
  210. };
  211. config_setting_set_float(pSetting, m_sSourceInfo.alt);
  212. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_PITCH);
  213. // tPitch = 0.f;
  214. if (pSetting == NULL)
  215. {
  216. pSetting = config_setting_add(m_pSettings, TAG_POSITION_PITCH, CONFIG_TYPE_FLOAT);
  217. };
  218. config_setting_set_float(pSetting, m_sSourceInfo.h_lon);
  219. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ROLL);
  220. // tRoll = 0.f;
  221. if (pSetting == NULL)
  222. {
  223. pSetting = config_setting_add(m_pSettings, TAG_POSITION_ROLL, CONFIG_TYPE_FLOAT);
  224. };
  225. config_setting_set_float(pSetting, m_sSourceInfo.h_lat);
  226. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_YAW);
  227. // tYaw = 0.f;
  228. if (pSetting == NULL)
  229. {
  230. pSetting = config_setting_add(m_pSettings, TAG_POSITION_YAW, CONFIG_TYPE_FLOAT);
  231. };
  232. config_setting_set_float(pSetting, m_sSourceInfo.h_alt);
  233. setPositionDeg(SI->lat, SI->lon, SI->alt, SI->h_lon, SI->h_lat, SI->h_alt);
  234. if (m_sSourceInfo.subtype != 1)
  235. { // File or Local Source
  236. if (m_sSourceInfo.subtype == 0)
  237. { // Local Source
  238. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PORT);
  239. if (pSetting == NULL)
  240. {
  241. pSetting = config_setting_add(m_pSettings, BCI_TAG_SOURCE_PORT, CONFIG_TYPE_INT);
  242. };
  243. config_setting_set_int(pSetting, m_sSourceInfo.capturePin);
  244. };
  245. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PATH);
  246. if (pSetting == NULL)
  247. {
  248. pSetting = config_setting_add(m_pSettings, BCI_TAG_SOURCE_PATH, CONFIG_TYPE_STRING);
  249. };
  250. config_setting_set_string(pSetting, m_sSourceInfo.devicePath);
  251. }
  252. else
  253. {
  254. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_VIDEO_MRL);
  255. if (pSetting == NULL)
  256. {
  257. pSetting = config_setting_add(m_pSettings, BCI_TAG_VIDEO_MRL, CONFIG_TYPE_STRING);
  258. };
  259. config_setting_set_string(pSetting, m_sSourceInfo.onvifVideoMRL);
  260. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_PICTURE_MRL);
  261. if (pSetting == NULL)
  262. {
  263. pSetting = config_setting_add(m_pSettings, BCI_TAG_PICTURE_MRL, CONFIG_TYPE_STRING);
  264. };
  265. config_setting_set_string(pSetting, m_sSourceInfo.onvifPictureMRL);
  266. };
  267. basicSettingsProvider::getInstance()->compromise();
  268. return true;
  269. }
  270. void basicCamera::updateSettings(void)
  271. {
  272. if (! m_pSettings)
  273. {
  274. return;
  275. }
  276. config_setting_t * pSetting;
  277. int tInt;
  278. double tFloat;
  279. CSTR tBuff;
  280. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_LAT, &tFloat))
  281. {
  282. if (tFloat != getLat())
  283. {
  284. tFloat = getLat();
  285. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_LAT);
  286. config_setting_set_float(pSetting, tFloat);
  287. basicSettingsProvider::getInstance()->compromise();
  288. };
  289. };
  290. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_LON, &tFloat))
  291. {
  292. if (tFloat != getLon())
  293. {
  294. tFloat = getLon();
  295. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_LON);
  296. config_setting_set_float(pSetting, tFloat);
  297. basicSettingsProvider::getInstance()->compromise();
  298. };
  299. };
  300. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_ALT, &tFloat))
  301. {
  302. if (tFloat != getAlt())
  303. {
  304. tFloat = getAlt();
  305. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_ALT);
  306. config_setting_set_float(pSetting, tFloat);
  307. basicSettingsProvider::getInstance()->compromise();
  308. };
  309. };
  310. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_YAW, &tFloat))
  311. {
  312. if (tFloat != getRotZ_deg())
  313. {
  314. tFloat = getRotZ_deg();
  315. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_YAW);
  316. config_setting_set_float(pSetting, tFloat);
  317. basicSettingsProvider::getInstance()->compromise();
  318. };
  319. };
  320. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_ROLL, &tFloat))
  321. {
  322. if (tFloat != getRotY_deg())
  323. {
  324. tFloat = getRotY_deg();
  325. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_ROLL);
  326. config_setting_set_float(pSetting, tFloat);
  327. basicSettingsProvider::getInstance()->compromise();
  328. };
  329. };
  330. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_PITCH, &tFloat))
  331. {
  332. if (tFloat != getRotX_deg())
  333. {
  334. tFloat = getRotX_deg();
  335. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_PITCH);
  336. config_setting_set_float(pSetting, tFloat);
  337. basicSettingsProvider::getInstance()->compromise();
  338. };
  339. };
  340. if (config_setting_lookup_string(m_pSettings, BCI_TAG_CAMERA_NAME, (const char **) &tBuff))
  341. {
  342. if (strcmp(m_sSourceInfo.deviceName, tBuff) != 0)
  343. {
  344. pSetting = config_setting_lookup(m_pSettings, BCI_TAG_CAMERA_NAME);
  345. config_setting_set_string(pSetting, m_sSourceInfo.deviceName);
  346. basicSettingsProvider::getInstance()->compromise();
  347. };
  348. };
  349. if (config_setting_lookup_int(m_pSettings, BCI_TAG_CAMERA_TYPE, &tInt))
  350. {
  351. if (m_sSourceInfo.type != tInt)
  352. {
  353. pSetting = config_setting_lookup(m_pSettings, BCI_TAG_CAMERA_TYPE);
  354. config_setting_set_int(pSetting, m_sSourceInfo.type);
  355. basicSettingsProvider::getInstance()->compromise();
  356. };
  357. };
  358. if (config_setting_lookup_int(m_pSettings, BCI_TAG_SOURCE_TYPE, &tInt))
  359. {
  360. if (m_sSourceInfo.subtype != tInt)
  361. {
  362. pSetting = config_setting_lookup(m_pSettings, BCI_TAG_SOURCE_TYPE);
  363. config_setting_set_int(pSetting, m_sSourceInfo.subtype);
  364. basicSettingsProvider::getInstance()->compromise();
  365. };
  366. };
  367. if (config_setting_lookup_int(m_pSettings, BCI_TAG_IMAGE_WIDTH, &tInt))
  368. {
  369. if (m_sSourceInfo.width != tInt)
  370. {
  371. pSetting = config_setting_lookup(m_pSettings, BCI_TAG_IMAGE_WIDTH);
  372. config_setting_set_int(pSetting, m_sSourceInfo.width);
  373. basicSettingsProvider::getInstance()->compromise();
  374. };
  375. };
  376. if (config_setting_lookup_int(m_pSettings, BCI_TAG_IMAGE_HEIGHT, &tInt))
  377. {
  378. if (m_sSourceInfo.height != tInt)
  379. {
  380. pSetting = config_setting_lookup(m_pSettings, BCI_TAG_IMAGE_HEIGHT);
  381. config_setting_set_int(pSetting, m_sSourceInfo.height);
  382. basicSettingsProvider::getInstance()->compromise();
  383. };
  384. };
  385. if (m_sSourceInfo.subtype != 1)
  386. {
  387. if (m_sSourceInfo.subtype == 0)
  388. {
  389. if (config_setting_lookup_int(m_pSettings, BCI_TAG_SOURCE_PORT, &tInt))
  390. {
  391. if (m_sSourceInfo.capturePin != tInt)
  392. {
  393. pSetting = config_setting_lookup(m_pSettings, BCI_TAG_SOURCE_PORT);
  394. config_setting_set_int(pSetting, m_sSourceInfo.capturePin);
  395. basicSettingsProvider::getInstance()->compromise();
  396. };
  397. };
  398. };
  399. if (config_setting_lookup_string(m_pSettings, BCI_TAG_SOURCE_PATH, (const char **) &tBuff))
  400. {
  401. if (strcmp(m_sSourceInfo.devicePath, tBuff) != 0)
  402. {
  403. pSetting = config_setting_lookup(m_pSettings, BCI_TAG_SOURCE_PATH);
  404. config_setting_set_string(pSetting, m_sSourceInfo.devicePath);
  405. basicSettingsProvider::getInstance()->compromise();
  406. };
  407. };
  408. };
  409. if (basicSettingsProvider::getInstance()->isCompromised())
  410. {
  411. basicSettingsProvider::getInstance()->validate();
  412. }
  413. }
  414. void basicCamera::dispatchEvent(EVENT_CONTAINER * Evt)
  415. {
  416. switch (Evt->m_eClass)
  417. {
  418. case EVT_CLASS_SENSOR_LGS:
  419. case EVT_CLASS_SENSOR_LFS:
  420. case EVT_CLASS_SENSOR_MND:
  421. case EVT_CLASS_SENSOR_PLS_210:
  422. case EVT_CLASS_SENSOR_PLS_360:
  423. case EVT_CLASS_SENSOR_ALS:
  424. case EVT_CLASS_SENSOR_3D:
  425. {
  426. switch (Evt->m_eType)
  427. {
  428. case EVT_TARGET_1D:
  429. case EVT_TARGET_2D_WHITE:
  430. case EVT_TARGET_2D_BLACK:
  431. case EVT_TARGET_3D_WHITE:
  432. case EVT_TARGET_3D_BLACK:
  433. case EVT_ALARM:
  434. CLIENT_EVENT * tData;
  435. tData = (CLIENT_EVENT *) Evt->m_pEvtData;
  436. // Basic Camera Reaction - Start Record
  437. break;
  438. default: break;
  439. };
  440. break;
  441. };
  442. case EVT_CLASS_VIDEO:
  443. {
  444. switch (Evt->m_eType)
  445. {
  446. case EVT_COMMAND:
  447. basicCameraCommand * pData;
  448. pData = (basicCameraCommand *) Evt->m_pEvtData;
  449. // Basic Camera Commands
  450. switch (pData->m_cCode)
  451. {
  452. case CMD_CAMERA_START_RECORD: m_pVideoNode->startRecord(); break;
  453. case CMD_CAMERA_STOP_RECORD : m_pVideoNode->stopRecord(); break;
  454. default : break;
  455. };
  456. break;
  457. default: break;
  458. };
  459. break;
  460. };
  461. };
  462. }