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.

232 lines
8.6 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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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_sSourceInfo.type){
  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_sSourceInfo.devicePath , false, -1.f, m_sSourceInfo.capturePin, m_sSourceInfo.width, m_sSourceInfo.height)){
  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_sSourceInfo.devicePath, 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( SOURCE_INFO *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. pSetting = config_setting_add(m_pSettings, BCI_TAG_OPTIC_FOCUS_LENGTH_MIN, CONFIG_TYPE_FLOAT);
  129. config_setting_set_float(pSetting, SI->FLMin);
  130. pSetting = config_setting_add(m_pSettings, BCI_TAG_OPTIC_FOCUS_LENGTH_MAX, CONFIG_TYPE_FLOAT);
  131. config_setting_set_float(pSetting, SI->FLMax);
  132. pSetting = config_setting_add(m_pSettings, BCI_TAG_OPTIC_FOCUS_LENGTH_CUR, CONFIG_TYPE_FLOAT);
  133. config_setting_set_float(pSetting, SI->FLMin);
  134. pSetting = config_setting_add(m_pSettings, BCI_TAG_OPTIC_SENSOR_SIZE, CONFIG_TYPE_FLOAT);
  135. config_setting_set_float(pSetting, SI->fSensorSize);
  136. pSetting = config_setting_add(m_pSettings, BCI_TAG_OPTIC_FOV, CONFIG_TYPE_FLOAT);
  137. tfVal = calcFOV(SI->fSensorSize, SI->FLMin);
  138. config_setting_set_float(pSetting, tfVal);
  139. if (SI->FLMin != SI->FLMax){
  140. // Zoom Ctrl is Enabled
  141. m_sSourceInfo.bZoomEna = true;
  142. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_ZOOM_CTRL, CONFIG_TYPE_BOOL);
  143. config_setting_set_bool(pSetting, true);
  144. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ZOOM_MAX, CONFIG_TYPE_FLOAT);
  145. tfVal = SI->FLMax / SI->FLMin;
  146. config_setting_set_float(pSetting, tfVal);
  147. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ZOOM_ENA_DIGITAL, CONFIG_TYPE_BOOL);
  148. if (SI->fDigitalZoomMax > 0){
  149. config_setting_set_bool(pSetting, true);
  150. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ZOOM_DIGITAL_MAX, CONFIG_TYPE_FLOAT);
  151. config_setting_set_float(pSetting, SI->fDigitalZoomMax);
  152. } else {
  153. config_setting_set_bool(pSetting, false);
  154. };
  155. };
  156. } else {
  157. config_setting_set_bool(pSetting, false);
  158. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_ZOOM_CTRL, CONFIG_TYPE_BOOL);
  159. if (SI->fDigitalZoomMax > 0){
  160. config_setting_set_bool(pSetting, true);
  161. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ZOOM_MAX, CONFIG_TYPE_FLOAT);
  162. tfVal = 1.f;
  163. config_setting_set_float(pSetting, tfVal);
  164. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ZOOM_DIGITAL_MAX, CONFIG_TYPE_FLOAT);
  165. config_setting_set_float(pSetting, SI->fDigitalZoomMax);
  166. } else {
  167. config_setting_set_bool(pSetting, false);
  168. };
  169. };
  170. if( SI->bAutoExposure || SI->fManualExposure > 0 ){
  171. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_EXPOSURE_CTRL, CONFIG_TYPE_BOOL);
  172. config_setting_set_bool(pSetting, true );
  173. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_EXPOSURE_ENA_AUTO, CONFIG_TYPE_BOOL);
  174. config_setting_set_bool(pSetting, 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. };
  178. if( SI->bAutoFocus || SI->fManualFocus > 0 ){
  179. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_FOCUS_CTRL, CONFIG_TYPE_BOOL);
  180. config_setting_set_bool(pSetting, true);
  181. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_FOCUS_ENA_AUTO, CONFIG_TYPE_BOOL);
  182. config_setting_set_bool(pSetting, SI->bAutoFocus);
  183. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_FOCUS_MANUAL_VAL, CONFIG_TYPE_FLOAT);
  184. config_setting_set_float(pSetting, SI->fManualFocus);
  185. };
  186. if( SI->bAutoIris || SI->fManualIris > 0 ){
  187. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_IRIS_CTRL, CONFIG_TYPE_BOOL);
  188. config_setting_set_bool(pSetting, true);
  189. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_IRIS_ENA_AUTO, CONFIG_TYPE_BOOL);
  190. config_setting_set_bool(pSetting, SI->bAutoIris);
  191. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_MANUAL_IRIS_VAL, CONFIG_TYPE_FLOAT);
  192. config_setting_set_float(pSetting, SI->fManualIris);
  193. };
  194. if (SI->bAutoWB || SI->fManualWB){
  195. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_ENA_WB_CTRL, CONFIG_TYPE_BOOL);
  196. config_setting_set_bool(pSetting, true);
  197. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_WB_ENA_AUTO, CONFIG_TYPE_BOOL);
  198. config_setting_set_bool(pSetting, SI->bAutoWB);
  199. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_WB_WB_VAL, CONFIG_TYPE_FLOAT);
  200. config_setting_set_float(pSetting, SI->fManualWB);
  201. };
  202. return create();
  203. };
  204. return false;
  205. };
  206. void objectStaticCamera::updateSettings(void){
  207. if (!m_pSettings) return;
  208. basicCamera::updateSettings();
  209. };
  210. void objectStaticCamera::dispatchEvent(basicEvent *Evt){
  211. };
  212. #undef LOG
  213. #undef ERROR_LOG