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.

287 lines
8.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "objectStaticCamera.h"
  2. #define LOG(X) m_pLog->Log("objectStatic", this, X)
  3. #define LOG_ERROR(X) m_pLog->Log("objectStatic", this, _LOG_ERROR, X)
  4. objectStaticCamera::objectStaticCamera(config_setting_t * Settings) :
  5. basicCamera(Settings)
  6. {
  7. m_pLog = basicLogCollection::getInstance();
  8. }
  9. objectStaticCamera::~objectStaticCamera()
  10. {
  11. if (m_pVideoSource != NULL)
  12. {
  13. delete((videoAVLIBSource *) m_pVideoSource);
  14. }
  15. }
  16. bool objectStaticCamera::create(void)
  17. {
  18. if (m_pSettings == NULL)
  19. {
  20. return false;
  21. }
  22. if (! basicCamera::create())
  23. {
  24. return false;
  25. }
  26. // init video
  27. switch (m_sSourceInfo.type)
  28. {
  29. case 0:
  30. {
  31. videoAVLIBSource * tSource;
  32. videoAVLIBDestination * tRecorder;
  33. tRecorder = new videoAVLIBDestination();
  34. tSource = new videoAVLIBSource();
  35. if (tSource == NULL)
  36. {
  37. return false;
  38. };
  39. if (tSource->_open((CSTR) m_sSourceInfo.devicePath, false, -1.f, m_sSourceInfo.capturePin, m_sSourceInfo.width, m_sSourceInfo.height))
  40. {
  41. #ifndef NO_VIDEO_FILTERS
  42. // Filter
  43. switch (0)
  44. {
  45. case 1:
  46. m_pVideoAnalyzer = new blobDetector();
  47. if (m_pVideoAnalyzer != NULL)
  48. {
  49. //((blobDetector*)m_pVideoAnalyzer)->attachPTZ(this);
  50. };
  51. break;
  52. case 2 : m_pVideoAnalyzer = new motionDetector(); break;
  53. case 3 : m_pVideoAnalyzer = new opticalFlowDetector(); break;
  54. case 4 : m_pVideoAnalyzer = new surfDetector(); break;
  55. case 5 : m_pVideoAnalyzer = new vlfeatDetector(); break;
  56. default: m_pVideoAnalyzer = NULL; break;
  57. };
  58. if (m_pVideoAnalyzer != NULL)
  59. {
  60. m_pVideoAnalyzer->attachDestination(m_pVideoNode);
  61. m_pVideoAnalyzer->setStreaming(true);
  62. m_pVideoAnalyzer->setPIP(false);
  63. m_pVideoAnalyzer->init();
  64. tSource->attachDestination(m_pVideoAnalyzer);
  65. tSource->setStreaming(true);
  66. }
  67. else
  68. #endif
  69. {
  70. // tNode->setTimeLapse(3000);
  71. tSource->attachDestination(m_pVideoNode);
  72. tSource->setStreaming(true);
  73. };
  74. m_pVideoSource = (basicMediaSource *) tSource;
  75. m_pVideoNode->connect(tRecorder);
  76. }
  77. else
  78. {
  79. delete tRecorder;
  80. delete tSource;
  81. return false;
  82. };
  83. break;
  84. };
  85. case 1:
  86. {
  87. videoAVLIBSource * tSource;
  88. videoAVLIBDestination * tRecorder;
  89. tRecorder = new videoAVLIBDestination();
  90. tSource = new videoAVLIBSource();
  91. if (tSource == NULL)
  92. {
  93. return false;
  94. };
  95. if (tSource->_open((CSTR) m_sSourceInfo.devicePath, false))
  96. {
  97. #ifndef NO_VIDEO_FILTERS
  98. // Filter
  99. switch (0)
  100. {
  101. case 1:
  102. m_pVideoAnalyzer = new blobDetector();
  103. if (m_pVideoAnalyzer != NULL)
  104. {
  105. //((blobDetector*)m_pVideoAnalyzer)->attachPTZ(this);
  106. };
  107. break;
  108. case 2 : m_pVideoAnalyzer = new motionDetector(); break;
  109. case 3 : m_pVideoAnalyzer = new opticalFlowDetector(); break;
  110. case 4 : m_pVideoAnalyzer = new surfDetector(); break;
  111. case 5 : m_pVideoAnalyzer = new vlfeatDetector(); break;
  112. default: m_pVideoAnalyzer = NULL; break;
  113. };
  114. if (m_pVideoAnalyzer != NULL)
  115. {
  116. m_pVideoAnalyzer->attachDestination(m_pVideoNode);
  117. m_pVideoAnalyzer->setStreaming(true);
  118. m_pVideoAnalyzer->setPIP(false);
  119. m_pVideoAnalyzer->init();
  120. tSource->attachDestination(m_pVideoAnalyzer);
  121. tSource->setStreaming(true);
  122. }
  123. else
  124. #endif
  125. {
  126. // tNode->setTimeLapse(3000);
  127. tSource->attachDestination(m_pVideoNode);
  128. tSource->setStreaming(true);
  129. };
  130. m_pVideoSource = (basicMediaSource *) tSource;
  131. m_pVideoNode->connect(tRecorder);
  132. }
  133. else
  134. {
  135. delete tRecorder;
  136. delete tSource;
  137. return false;
  138. };
  139. break;
  140. };
  141. default: return false;
  142. };
  143. return true;
  144. }
  145. bool objectStaticCamera::create(SOURCE_INFO * SI)
  146. {
  147. /* This Method Only to Create New Instances */
  148. if (m_pSettings == NULL)
  149. {
  150. return false;
  151. }
  152. if (SI == NULL)
  153. {
  154. return false;
  155. }
  156. if (basicCamera::create(SI))
  157. {
  158. config_setting_t * pSetting;
  159. float tfVal;
  160. int tiVal;
  161. pSetting = config_setting_add(m_pSettings, BCI_TAG_OPTIC_DATA_ENA, CONFIG_TYPE_BOOL);
  162. if (pSetting == NULL)
  163. {
  164. LOG_ERROR("Some Trouble to create Camera Settings!");
  165. return false;
  166. };
  167. if (SI->FLMin > 0 && SI->FLMax > 0)
  168. {
  169. config_setting_set_bool(pSetting, true);
  170. pSetting = config_setting_add(m_pSettings, BCI_TAG_OPTIC_FOCUS_LENGTH_MIN, CONFIG_TYPE_FLOAT);
  171. config_setting_set_float(pSetting, SI->FLMin);
  172. pSetting = config_setting_add(m_pSettings, BCI_TAG_OPTIC_FOCUS_LENGTH_MAX, CONFIG_TYPE_FLOAT);
  173. config_setting_set_float(pSetting, SI->FLMax);
  174. pSetting = config_setting_add(m_pSettings, BCI_TAG_OPTIC_FOCUS_LENGTH_CUR, CONFIG_TYPE_FLOAT);
  175. config_setting_set_float(pSetting, SI->FLMin);
  176. pSetting = config_setting_add(m_pSettings, BCI_TAG_OPTIC_SENSOR_SIZE, CONFIG_TYPE_FLOAT);
  177. config_setting_set_float(pSetting, SI->fSensorSize);
  178. pSetting = config_setting_add(m_pSettings, BCI_TAG_OPTIC_FOV, CONFIG_TYPE_FLOAT);
  179. tfVal = calcFOV(SI->fSensorSize, SI->FLMin);
  180. config_setting_set_float(pSetting, tfVal);
  181. if (SI->FLMin != SI->FLMax)
  182. {
  183. // Zoom Ctrl is Enabled
  184. m_sSourceInfo.bZoomEna = true;
  185. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_ZOOM_CTRL, CONFIG_TYPE_BOOL);
  186. config_setting_set_bool(pSetting, true);
  187. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ZOOM_MAX, CONFIG_TYPE_FLOAT);
  188. tfVal = SI->FLMax / SI->FLMin;
  189. config_setting_set_float(pSetting, tfVal);
  190. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ZOOM_ENA_DIGITAL, CONFIG_TYPE_BOOL);
  191. if (SI->fDigitalZoomMax > 0)
  192. {
  193. config_setting_set_bool(pSetting, true);
  194. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ZOOM_DIGITAL_MAX, CONFIG_TYPE_FLOAT);
  195. config_setting_set_float(pSetting, SI->fDigitalZoomMax);
  196. }
  197. else
  198. {
  199. config_setting_set_bool(pSetting, false);
  200. };
  201. };
  202. }
  203. else
  204. {
  205. config_setting_set_bool(pSetting, false);
  206. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_ZOOM_CTRL, CONFIG_TYPE_BOOL);
  207. if (SI->fDigitalZoomMax > 0)
  208. {
  209. config_setting_set_bool(pSetting, true);
  210. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ZOOM_MAX, CONFIG_TYPE_FLOAT);
  211. tfVal = 1.f;
  212. config_setting_set_float(pSetting, tfVal);
  213. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ZOOM_DIGITAL_MAX, CONFIG_TYPE_FLOAT);
  214. config_setting_set_float(pSetting, SI->fDigitalZoomMax);
  215. }
  216. else
  217. {
  218. config_setting_set_bool(pSetting, false);
  219. };
  220. };
  221. if (SI->bAutoExposure || SI->fManualExposure > 0)
  222. {
  223. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_EXPOSURE_CTRL, CONFIG_TYPE_BOOL);
  224. config_setting_set_bool(pSetting, true);
  225. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_EXPOSURE_ENA_AUTO, CONFIG_TYPE_BOOL);
  226. config_setting_set_bool(pSetting, SI->bAutoExposure);
  227. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_MANUAL_EXPOSURE_VAL, CONFIG_TYPE_FLOAT);
  228. config_setting_set_float(pSetting, SI->fManualExposure);
  229. };
  230. if (SI->bAutoFocus || SI->fManualFocus > 0)
  231. {
  232. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_FOCUS_CTRL, CONFIG_TYPE_BOOL);
  233. config_setting_set_bool(pSetting, true);
  234. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_FOCUS_ENA_AUTO, CONFIG_TYPE_BOOL);
  235. config_setting_set_bool(pSetting, SI->bAutoFocus);
  236. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_FOCUS_MANUAL_VAL, CONFIG_TYPE_FLOAT);
  237. config_setting_set_float(pSetting, SI->fManualFocus);
  238. };
  239. if (SI->bAutoIris || SI->fManualIris > 0)
  240. {
  241. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_IRIS_CTRL, CONFIG_TYPE_BOOL);
  242. config_setting_set_bool(pSetting, true);
  243. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_IRIS_ENA_AUTO, CONFIG_TYPE_BOOL);
  244. config_setting_set_bool(pSetting, SI->bAutoIris);
  245. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_MANUAL_IRIS_VAL, CONFIG_TYPE_FLOAT);
  246. config_setting_set_float(pSetting, SI->fManualIris);
  247. };
  248. if (SI->bAutoWB || SI->fManualWB)
  249. {
  250. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_WB_CTRL, CONFIG_TYPE_BOOL);
  251. config_setting_set_bool(pSetting, true);
  252. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_WB_ENA_AUTO, CONFIG_TYPE_BOOL);
  253. config_setting_set_bool(pSetting, SI->bAutoWB);
  254. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_WB_WB_VAL, CONFIG_TYPE_FLOAT);
  255. config_setting_set_float(pSetting, SI->fManualWB);
  256. };
  257. return create();
  258. };
  259. return false;
  260. }
  261. void objectStaticCamera::updateSettings(void)
  262. {
  263. if (! m_pSettings)
  264. {
  265. return;
  266. }
  267. basicCamera::updateSettings();
  268. }
  269. void objectStaticCamera::dispatchEvent(basicEvent * Evt) {}
  270. #undef LOG
  271. #undef ERROR_LOG