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.

225 lines
9.0 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "objectStaticCamera.h"
  2. objectStaticCamera::objectStaticCamera(config_setting_t *Settings) : basicCamera( Settings ){
  3. m_pLog = basicLogCollection::getInstance();
  4. };
  5. objectStaticCamera::~objectStaticCamera(){
  6. if (m_pVideoSource != NULL) delete ((videoAVLIBSource *)m_pVideoSource );
  7. };
  8. bool objectStaticCamera::create(void){
  9. if (m_pSettings == NULL) return false;
  10. if (!basicCamera::create()) return false;
  11. //init video
  12. switch (m_sCameraInfo.m_iSourceType){
  13. case 0:{
  14. videoAVLIBSource *tSource;
  15. videoAVLIBDestination *tRecorder;
  16. tRecorder = new videoAVLIBDestination();
  17. tSource = new videoAVLIBSource();
  18. if (tSource == NULL){
  19. return false;
  20. };
  21. if (tSource->_open((CSTR)m_sCameraInfo.m_pSourcePath, false, -1.f, m_sCameraInfo.m_iSourcePort, m_sCameraInfo.m_iWidth, m_sCameraInfo.m_iHeight)){
  22. #ifndef NO_VIDEO_FILTERS
  23. //Filter
  24. switch (0){
  25. case 1:
  26. m_pVideoAnalyzer = new blobDetector();
  27. if (m_pVideoAnalyzer != NULL){
  28. //((blobDetector*)m_pVideoAnalyzer)->attachPTZ(this);
  29. };
  30. break;
  31. case 2: m_pVideoAnalyzer = new motionDetector(); break;
  32. case 3: m_pVideoAnalyzer = new opticalFlowDetector(); break;
  33. case 4: m_pVideoAnalyzer = new surfDetector(); break;
  34. case 5: m_pVideoAnalyzer = new vlfeatDetector(); break;
  35. default: m_pVideoAnalyzer = NULL; break;
  36. };
  37. if (m_pVideoAnalyzer != NULL){
  38. m_pVideoAnalyzer->attachDestination(m_pVideoNode);
  39. m_pVideoAnalyzer->setStreaming(true);
  40. m_pVideoAnalyzer->setPIP(false);
  41. m_pVideoAnalyzer->init();
  42. tSource->attachDestination(m_pVideoAnalyzer);
  43. tSource->setStreaming(true);
  44. } else
  45. #endif
  46. {
  47. //tNode->setTimeLapse(3000);
  48. tSource->attachDestination(m_pVideoNode);
  49. tSource->setStreaming(true);
  50. };
  51. m_pVideoSource = (basicMediaSource *)tSource;
  52. m_pVideoNode->connect(tRecorder);
  53. } else {
  54. delete tRecorder;
  55. delete tSource;
  56. return false;
  57. };
  58. break;
  59. };
  60. case 1:{
  61. videoAVLIBSource *tSource;
  62. videoAVLIBDestination *tRecorder;
  63. tRecorder = new videoAVLIBDestination();
  64. tSource = new videoAVLIBSource();
  65. if (tSource == NULL){
  66. return false;
  67. };
  68. if (tSource->_open((CSTR)m_sCameraInfo.m_pSourcePath, false)){
  69. #ifndef NO_VIDEO_FILTERS
  70. //Filter
  71. switch (0){
  72. case 1:
  73. m_pVideoAnalyzer = new blobDetector();
  74. if (m_pVideoAnalyzer != NULL){
  75. //((blobDetector*)m_pVideoAnalyzer)->attachPTZ(this);
  76. };
  77. break;
  78. case 2: m_pVideoAnalyzer = new motionDetector(); break;
  79. case 3: m_pVideoAnalyzer = new opticalFlowDetector(); break;
  80. case 4: m_pVideoAnalyzer = new surfDetector(); break;
  81. case 5: m_pVideoAnalyzer = new vlfeatDetector(); break;
  82. default: m_pVideoAnalyzer = NULL; break;
  83. };
  84. if (m_pVideoAnalyzer != NULL){
  85. m_pVideoAnalyzer->attachDestination(m_pVideoNode);
  86. m_pVideoAnalyzer->setStreaming(true);
  87. m_pVideoAnalyzer->setPIP(false);
  88. m_pVideoAnalyzer->init();
  89. tSource->attachDestination(m_pVideoAnalyzer);
  90. tSource->setStreaming(true);
  91. }else
  92. #endif
  93. {
  94. //tNode->setTimeLapse(3000);
  95. tSource->attachDestination(m_pVideoNode);
  96. tSource->setStreaming(true);
  97. };
  98. m_pVideoSource = (basicMediaSource *)tSource;
  99. m_pVideoNode->connect(tRecorder);
  100. } else {
  101. delete tRecorder;
  102. delete tSource;
  103. return false;
  104. };
  105. break;
  106. };
  107. default: return false;
  108. };
  109. return true;
  110. };
  111. bool objectStaticCamera::create(mediaSourceInfo *SI){
  112. /* This Method Only to Create New Instances */
  113. if ( m_pSettings == NULL) return false;
  114. if ( SI == NULL) return false;
  115. if (basicCamera::create(SI)){
  116. config_setting_t *pSetting;
  117. float tfVal;
  118. int tiVal;
  119. pSetting = config_setting_add(m_pSettings, BCI_TAG_OPTIC_DATA_ENA, CONFIG_TYPE_BOOL);
  120. if (SI->FLMin > 0 && SI->FLMax > 0){
  121. config_setting_set_bool(pSetting, true);
  122. m_sCameraInfo.m_bOpticEna = true;
  123. m_sCameraInfo.m_fFLMin = SI->FLMin;
  124. m_sCameraInfo.m_fFLMax = SI->FLMax;
  125. m_sCameraInfo.m_fFLCurrent = SI->FLMin;
  126. pSetting = config_setting_add(m_pSettings, BCI_TAG_OPTIC_FOCUS_LENGTH_MIN, CONFIG_TYPE_FLOAT);
  127. config_setting_set_float(pSetting, SI->FLMin);
  128. pSetting = config_setting_add(m_pSettings, BCI_TAG_OPTIC_FOCUS_LENGTH_MAX, CONFIG_TYPE_FLOAT);
  129. config_setting_set_float(pSetting, SI->FLMax);
  130. pSetting = config_setting_add(m_pSettings, BCI_TAG_OPTIC_FOCUS_LENGTH_CUR, CONFIG_TYPE_FLOAT);
  131. config_setting_set_float(pSetting, SI->FLMin);
  132. pSetting = config_setting_add(m_pSettings, BCI_TAG_OPTIC_SENSOR_SIZE, CONFIG_TYPE_FLOAT);
  133. config_setting_set_float(pSetting, SI->fSensorSize);
  134. pSetting = config_setting_add(m_pSettings, BCI_TAG_OPTIC_FOV, CONFIG_TYPE_FLOAT);
  135. tfVal = calcFOV(SI->fSensorSize, SI->FLMin);
  136. config_setting_set_float(pSetting, tfVal);
  137. if (SI->FLMin != SI->FLMax){
  138. // Zoom Ctrl is Enabled
  139. m_sCameraInfo.m_bZoomEna = true;
  140. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_ZOOM_CTRL, CONFIG_TYPE_BOOL);
  141. config_setting_set_bool(pSetting, true);
  142. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ZOOM_MAX, CONFIG_TYPE_FLOAT);
  143. tfVal = SI->FLMax / SI->FLMin;
  144. config_setting_set_float(pSetting, tfVal);
  145. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ZOOM_ENA_DIGITAL, CONFIG_TYPE_BOOL);
  146. if (SI->fDigitalZoomMax > 0){
  147. config_setting_set_bool(pSetting, true);
  148. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ZOOM_DIGITAL_MAX, CONFIG_TYPE_FLOAT);
  149. config_setting_set_float(pSetting, SI->fDigitalZoomMax);
  150. } else {
  151. config_setting_set_bool(pSetting, false);
  152. };
  153. };
  154. } else {
  155. config_setting_set_bool(pSetting, false);
  156. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_ZOOM_CTRL, CONFIG_TYPE_BOOL);
  157. if (SI->fDigitalZoomMax > 0){
  158. config_setting_set_bool(pSetting, true);
  159. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ZOOM_MAX, CONFIG_TYPE_FLOAT);
  160. tfVal = 1.f;
  161. config_setting_set_float(pSetting, tfVal);
  162. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ZOOM_DIGITAL_MAX, CONFIG_TYPE_FLOAT);
  163. config_setting_set_float(pSetting, SI->fDigitalZoomMax);
  164. } else {
  165. config_setting_set_bool(pSetting, false);
  166. };
  167. };
  168. if( SI->bAutoExposure || SI->fManualExposure > 0 ){
  169. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_EXPOSURE_CTRL, CONFIG_TYPE_BOOL);
  170. config_setting_set_bool(pSetting, true );
  171. m_sCameraInfo.m_bExpoEna = true;
  172. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_EXPOSURE_ENA_AUTO, CONFIG_TYPE_BOOL);
  173. config_setting_set_bool(pSetting, SI->bAutoExposure );
  174. m_sCameraInfo.m_bAutoExposure = SI->bAutoExposure;
  175. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_MANUAL_EXPOSURE_VAL, CONFIG_TYPE_FLOAT);
  176. config_setting_set_float(pSetting, SI->fManualExposure);
  177. m_sCameraInfo.m_fManualExposure = SI->fManualExposure;
  178. };
  179. if( SI->bAutoFocus || SI->fManualFocus > 0 ){
  180. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_FOCUS_CTRL, CONFIG_TYPE_BOOL);
  181. config_setting_set_bool(pSetting, true);
  182. m_sCameraInfo.m_bFocusEna = true;
  183. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_FOCUS_ENA_AUTO, CONFIG_TYPE_BOOL);
  184. config_setting_set_bool(pSetting, SI->bAutoFocus);
  185. m_sCameraInfo.m_bAutoFocus = SI->bAutoFocus;
  186. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_FOCUS_MANUAL_VAL, CONFIG_TYPE_FLOAT);
  187. config_setting_set_float(pSetting, SI->fManualFocus);
  188. m_sCameraInfo.m_fManualFocus = SI->fManualFocus;
  189. };
  190. if( SI->bAutoIris || SI->fManualIris > 0 ){
  191. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_IRIS_CTRL, CONFIG_TYPE_BOOL);
  192. config_setting_set_bool(pSetting, true);
  193. m_sCameraInfo.m_bIrisEna = true;
  194. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_IRIS_ENA_AUTO, CONFIG_TYPE_BOOL);
  195. config_setting_set_bool(pSetting, SI->bAutoIris);
  196. m_sCameraInfo.m_bAutoIris = SI->bAutoIris;
  197. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_MANUAL_IRIS_VAL, CONFIG_TYPE_FLOAT);
  198. config_setting_set_float(pSetting, SI->fManualIris);
  199. m_sCameraInfo.m_fManualIris = SI->fManualIris;
  200. };
  201. if (SI->bAutoWB || SI->fManualWB){
  202. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_WB_CTRL, CONFIG_TYPE_BOOL);
  203. config_setting_set_bool(pSetting, true);
  204. m_sCameraInfo.m_bWBEna = true;
  205. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_WB_ENA_AUTO, CONFIG_TYPE_BOOL);
  206. config_setting_set_bool(pSetting, SI->bAutoWB);
  207. m_sCameraInfo.m_bAutoWB = SI->bAutoWB;
  208. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_WB_WB_VAL, CONFIG_TYPE_FLOAT);
  209. config_setting_set_float(pSetting, SI->fManualWB);
  210. m_sCameraInfo.m_fManualWB = SI->fManualWB;
  211. };
  212. return create();
  213. };
  214. return false;
  215. };
  216. void objectStaticCamera::updateSettings(void){
  217. if (!m_pSettings) return;
  218. basicCamera::updateSettings();
  219. };
  220. void objectStaticCamera::dispatchEvent(basicEvent *Evt){
  221. };