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.

237 lines
9.3 KiB

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