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.

374 lines
14 KiB

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) : basicObject(), basicPosition(), basicEventHandler() {
  4. m_eCaps = (objectCaps)(OC_EVENT_HANDLER);
  5. m_pSettings = Settings;
  6. m_iStatus = PS_BORN;
  7. m_sCameraInfo.m_pName = NULL;
  8. m_sCameraInfo.m_pSourcePath = NULL;
  9. m_sCameraInfo.m_bAutoExposure = false;
  10. m_sCameraInfo.m_bAutoFocus = false;
  11. m_sCameraInfo.m_bAutoIris = false;
  12. m_sCameraInfo.m_bAutoWB = false;
  13. m_sCameraInfo.m_bDigitalZoom = false;
  14. m_sCameraInfo.m_bExpoEna = false;
  15. m_sCameraInfo.m_bFocusEna = false;
  16. m_sCameraInfo.m_bIrisEna = false;
  17. m_sCameraInfo.m_bMirrored = false;
  18. m_sCameraInfo.m_bOpticEna = false;
  19. m_sCameraInfo.m_bOpticZoom = false;
  20. m_sCameraInfo.m_bShuterEna = false;
  21. m_sCameraInfo.m_bUpsideDown = false;
  22. m_sCameraInfo.m_bWBEna = false;
  23. m_sCameraInfo.m_bWDR = false;
  24. m_sCameraInfo.m_bWDREna = false;
  25. m_sCameraInfo.m_bZoomEna = false;
  26. m_sCameraInfo.m_bZoomSpeedDynamic = false;
  27. m_sCameraInfo.m_fDigitalZoomMax = -1.f;
  28. m_sCameraInfo.m_fFLCurrent = -1.f;
  29. m_sCameraInfo.m_fFLMax = -1.f;
  30. m_sCameraInfo.m_fFLMin = -1.f;
  31. m_sCameraInfo.m_fFOV = -1.f;
  32. m_sCameraInfo.m_fManualExposure = -1.f;
  33. m_sCameraInfo.m_fManualFocus = -1.f;
  34. m_sCameraInfo.m_fManualIris = -1.f;
  35. m_sCameraInfo.m_fManualShutter = -1.f;
  36. m_sCameraInfo.m_fSensorSize = ( 1.f / 2.8f ) * .0254f; // in meters
  37. m_sCameraInfo.m_fZoomSpeedMax = -1.f;
  38. m_sCameraInfo.m_fZoomSpeedMin = -1.f;
  39. m_sCameraInfo.m_iHeight = -1;
  40. m_sCameraInfo.m_iWidth = -1;
  41. m_sCameraInfo.m_bScaledOutput = false;
  42. m_sCameraInfo.m_iOutputWidth = -1;
  43. m_sCameraInfo.m_iOutputHeight = -1;
  44. m_sCameraInfo.m_iSourcePort = -1;
  45. m_sCameraInfo.m_iSourceType = -1;
  46. m_sCameraInfo.m_iCameraType = -1;
  47. m_sCameraInfo.m_iZoomMax = -1;
  48. m_sCameraInfo.m_iZoomMin = -1;
  49. m_sCameraInfo.m_fMaxRange = -1;
  50. m_pVideoSource = NULL;
  51. m_pVideoNode = new videoNode(m_pSettings);
  52. };
  53. // Destructor implementation
  54. basicCamera::~basicCamera(){
  55. m_vOSD.clear();
  56. updateSettings();
  57. if (m_pVideoNode != NULL){
  58. m_pVideoNode->setStatus(TH_EXIT);
  59. delete(m_pVideoNode);
  60. };
  61. if (m_sCameraInfo.m_pName != NULL)free(m_sCameraInfo.m_pName);
  62. if (m_sCameraInfo.m_pSourcePath != NULL)free(m_sCameraInfo.m_pSourcePath);
  63. };
  64. bool basicCamera::create(void){
  65. config_setting_t *pSetting;
  66. if (m_pSettings == NULL) return false;
  67. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_TYPE);
  68. if (pSetting == NULL) return false;
  69. m_sCameraInfo.m_iCameraType = config_setting_get_int(pSetting);
  70. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_TYPE);
  71. if (pSetting == NULL) return false;
  72. m_sCameraInfo.m_iSourceType = config_setting_get_int(pSetting);
  73. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_WIDTH);
  74. if (pSetting == NULL) return false;
  75. m_sCameraInfo.m_iWidth = config_setting_get_int(pSetting);
  76. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_HEIGHT);
  77. if (pSetting == NULL) return false;
  78. m_sCameraInfo.m_iHeight = config_setting_get_int(pSetting);
  79. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PORT);
  80. if (pSetting == NULL) return false;
  81. m_sCameraInfo.m_iSourcePort = config_setting_get_int(pSetting);
  82. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_NAME);
  83. if (pSetting == NULL) return false;
  84. if (m_sCameraInfo.m_pName == NULL) m_sCameraInfo.m_pName = (CSTR)malloc(255);
  85. sprintf(m_sCameraInfo.m_pName, "%s", config_setting_get_string(pSetting));
  86. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PATH);
  87. if (pSetting == NULL) return false;
  88. if (m_sCameraInfo.m_pSourcePath == NULL) m_sCameraInfo.m_pSourcePath = (CSTR)malloc(255);
  89. sprintf(m_sCameraInfo.m_pSourcePath, "%s", config_setting_get_string(pSetting));
  90. /*Location*/
  91. float tLat, tLon, tAlt, tRoll, tPitch, tYaw;
  92. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT);
  93. if (pSetting == NULL) return false;
  94. tLat = config_setting_get_float(pSetting);
  95. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON);
  96. if (pSetting == NULL) return false;
  97. tLon = config_setting_get_float(pSetting);
  98. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT);
  99. if (pSetting == NULL) return false;
  100. tAlt = config_setting_get_float(pSetting);
  101. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ROLL);
  102. if (pSetting == NULL) return false;
  103. tRoll = config_setting_get_float(pSetting);
  104. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_PITCH);
  105. if (pSetting == NULL) return false;
  106. tPitch = config_setting_get_float(pSetting);
  107. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_YAW);
  108. if (pSetting == NULL) return false;
  109. tYaw = config_setting_get_float(pSetting);
  110. setPositionDeg(tLat, tLon, tAlt, tPitch, tRoll, tYaw);
  111. return true;
  112. };
  113. bool basicCamera::create(mediaSourceInfo *SI){
  114. config_setting_t *pSetting;
  115. if (m_pSettings == NULL) return false;
  116. if (SI == NULL) return false;
  117. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_TYPE);
  118. m_sCameraInfo.m_iCameraType = SI->type;
  119. if (pSetting == NULL){
  120. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_TYPE, CONFIG_TYPE_INT);
  121. };
  122. config_setting_set_int(pSetting, m_sCameraInfo.m_iCameraType);
  123. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_TYPE);
  124. m_sCameraInfo.m_iSourceType = SI->subtype;
  125. if (pSetting == NULL){
  126. pSetting = config_setting_add(m_pSettings, BCI_TAG_SOURCE_TYPE, CONFIG_TYPE_INT);
  127. };
  128. config_setting_set_int(pSetting, m_sCameraInfo.m_iSourceType);
  129. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_WIDTH);
  130. if (SI->frameIsWide){
  131. m_sCameraInfo.m_iWidth = g_aFrameWidthStandard_16_9[SI->sizeId];
  132. } else {
  133. m_sCameraInfo.m_iWidth = g_aFrameWidthStandard_4_3[SI->sizeId];
  134. };
  135. if (pSetting == NULL){
  136. pSetting = config_setting_add(m_pSettings, BCI_TAG_IMAGE_WIDTH, CONFIG_TYPE_INT);
  137. };
  138. config_setting_set_int(pSetting, m_sCameraInfo.m_iWidth);
  139. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_HEIGHT);
  140. if (SI->frameIsWide){
  141. m_sCameraInfo.m_iHeight = g_aFrameHeightStandard_16_9[SI->sizeId];
  142. } else {
  143. m_sCameraInfo.m_iHeight = g_aFrameHeightStandard_4_3[SI->sizeId];
  144. };
  145. if (pSetting == NULL){
  146. pSetting = config_setting_add(m_pSettings, BCI_TAG_IMAGE_HEIGHT, CONFIG_TYPE_INT);
  147. };
  148. config_setting_set_int(pSetting, m_sCameraInfo.m_iWidth);
  149. /*Location*/
  150. float tLat, tLon, tAlt, tRoll, tPitch, tYaw;
  151. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT);
  152. tLat = systemAnchor::getInstance()->getLat();
  153. if (pSetting == NULL){
  154. pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT);
  155. };
  156. config_setting_set_float(pSetting, tLat );
  157. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON);
  158. tLon = systemAnchor::getInstance()->getLon();
  159. if (pSetting == NULL){
  160. pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT);
  161. };
  162. config_setting_set_float(pSetting, tLon);
  163. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT);
  164. tAlt = systemAnchor::getInstance()->getAlt();
  165. if (pSetting == NULL){
  166. pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT);
  167. };
  168. config_setting_set_float(pSetting, tAlt);
  169. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_PITCH);
  170. tPitch = 0.f;
  171. if (pSetting == NULL){
  172. pSetting = config_setting_add(m_pSettings, TAG_POSITION_PITCH, CONFIG_TYPE_FLOAT);
  173. };
  174. config_setting_set_float(pSetting, tPitch);
  175. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ROLL);
  176. tRoll = 0.f;
  177. if (pSetting == NULL){
  178. pSetting = config_setting_add(m_pSettings, TAG_POSITION_ROLL, CONFIG_TYPE_FLOAT);
  179. };
  180. config_setting_set_float(pSetting, tRoll);
  181. pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_YAW);
  182. tYaw = 0.f;
  183. if (pSetting == NULL){
  184. pSetting = config_setting_add(m_pSettings, TAG_POSITION_YAW, CONFIG_TYPE_FLOAT);
  185. };
  186. config_setting_set_float(pSetting, tYaw);
  187. setPositionDeg(tLat, tLon, tAlt, tPitch, tRoll, tYaw);
  188. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PORT);
  189. m_sCameraInfo.m_iSourcePort = SI->capturePin;
  190. if (pSetting == NULL){
  191. pSetting = config_setting_add(m_pSettings, BCI_TAG_SOURCE_PORT, CONFIG_TYPE_INT);
  192. };
  193. config_setting_set_int(pSetting, m_sCameraInfo.m_iSourcePort);
  194. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_NAME);
  195. if (m_sCameraInfo.m_pName == NULL) m_sCameraInfo.m_pName = (CSTR)malloc(255);
  196. sprintf(m_sCameraInfo.m_pName, "%s", SI->deviceName);
  197. if (pSetting == NULL){
  198. pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_NAME, CONFIG_TYPE_STRING);
  199. };
  200. config_setting_set_string(pSetting, m_sCameraInfo.m_pName);
  201. pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PATH);
  202. if (m_sCameraInfo.m_pSourcePath == NULL) m_sCameraInfo.m_pSourcePath = (CSTR)malloc(255);
  203. sprintf(m_sCameraInfo.m_pSourcePath, "%s", SI->devicePath);
  204. if (pSetting == NULL){
  205. pSetting = config_setting_add(m_pSettings, BCI_TAG_SOURCE_PATH, CONFIG_TYPE_STRING);
  206. };
  207. config_setting_set_string(pSetting, m_sCameraInfo.m_pSourcePath);
  208. basicSettingsProvider::getInstance()->compromise();
  209. return create();
  210. };
  211. void basicCamera::updateSettings(void){
  212. if(!m_pSettings) return;
  213. config_setting_t *pSetting;
  214. int tInt;
  215. double tFloat;
  216. CSTR tBuff;
  217. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_LAT, &tFloat)){
  218. if (tFloat != getLat()){
  219. tFloat = getLat();
  220. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_LAT);
  221. config_setting_set_float(pSetting, tFloat);
  222. basicSettingsProvider::getInstance()->compromise();
  223. };
  224. };
  225. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_LON, &tFloat)){
  226. if (tFloat != getLon()){
  227. tFloat = getLon();
  228. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_LON);
  229. config_setting_set_float(pSetting, tFloat);
  230. basicSettingsProvider::getInstance()->compromise();
  231. };
  232. };
  233. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_ALT, &tFloat)){
  234. if (tFloat != getAlt()){
  235. tFloat = getAlt();
  236. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_ALT);
  237. config_setting_set_float(pSetting, tFloat);
  238. basicSettingsProvider::getInstance()->compromise();
  239. };
  240. };
  241. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_YAW, &tFloat)){
  242. if (tFloat != getRotZ_deg()){
  243. tFloat = getRotZ_deg();
  244. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_YAW);
  245. config_setting_set_float(pSetting, tFloat);
  246. basicSettingsProvider::getInstance()->compromise();
  247. };
  248. };
  249. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_ROLL, &tFloat)){
  250. if (tFloat != getRotY_deg()){
  251. tFloat = getRotY_deg();
  252. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_ROLL);
  253. config_setting_set_float(pSetting, tFloat);
  254. basicSettingsProvider::getInstance()->compromise();
  255. };
  256. };
  257. if (config_setting_lookup_float(m_pSettings, TAG_POSITION_PITCH, &tFloat)){
  258. if (tFloat != getRotX_deg()){
  259. tFloat = getRotX_deg();
  260. pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_PITCH);
  261. config_setting_set_float(pSetting, tFloat);
  262. basicSettingsProvider::getInstance()->compromise();
  263. };
  264. };
  265. if (config_setting_lookup_string(m_pSettings, BCI_TAG_CAMERA_NAME, (const char**)&tBuff)){
  266. if (strcmp(m_sCameraInfo.m_pName, tBuff) != 0){
  267. pSetting = config_setting_lookup(m_pSettings, BCI_TAG_CAMERA_NAME);
  268. config_setting_set_string(pSetting, m_sCameraInfo.m_pName);
  269. basicSettingsProvider::getInstance()->compromise();
  270. };
  271. };
  272. if (config_setting_lookup_string(m_pSettings, BCI_TAG_SOURCE_PATH, (const char**)&tBuff)){
  273. if (strcmp(m_sCameraInfo.m_pSourcePath, tBuff) != 0){
  274. pSetting = config_setting_lookup(m_pSettings, BCI_TAG_SOURCE_PATH);
  275. config_setting_set_string(pSetting, m_sCameraInfo.m_pSourcePath);
  276. basicSettingsProvider::getInstance()->compromise();
  277. };
  278. };
  279. if (config_setting_lookup_int(m_pSettings, BCI_TAG_CAMERA_TYPE, &tInt)){
  280. if (m_sCameraInfo.m_iCameraType != tInt){
  281. pSetting = config_setting_lookup(m_pSettings, BCI_TAG_CAMERA_TYPE);
  282. config_setting_set_int(pSetting, m_sCameraInfo.m_iCameraType);
  283. basicSettingsProvider::getInstance()->compromise();
  284. };
  285. };
  286. if (config_setting_lookup_int(m_pSettings, BCI_TAG_SOURCE_TYPE, &tInt)){
  287. if (m_sCameraInfo.m_iSourceType != tInt){
  288. pSetting = config_setting_lookup(m_pSettings, BCI_TAG_SOURCE_TYPE);
  289. config_setting_set_int(pSetting, m_sCameraInfo.m_iSourceType);
  290. basicSettingsProvider::getInstance()->compromise();
  291. };
  292. };
  293. if (config_setting_lookup_int(m_pSettings, BCI_TAG_IMAGE_WIDTH, &tInt)){
  294. if (m_sCameraInfo.m_iWidth != tInt){
  295. pSetting = config_setting_lookup(m_pSettings, BCI_TAG_IMAGE_WIDTH);
  296. config_setting_set_int(pSetting, m_sCameraInfo.m_iWidth);
  297. basicSettingsProvider::getInstance()->compromise();
  298. };
  299. };
  300. if (config_setting_lookup_int(m_pSettings, BCI_TAG_IMAGE_HEIGHT, &tInt)){
  301. if (m_sCameraInfo.m_iHeight != tInt){
  302. pSetting = config_setting_lookup(m_pSettings, BCI_TAG_IMAGE_HEIGHT);
  303. config_setting_set_int(pSetting, m_sCameraInfo.m_iHeight);
  304. basicSettingsProvider::getInstance()->compromise();
  305. };
  306. };
  307. if (config_setting_lookup_int(m_pSettings, BCI_TAG_SOURCE_PORT, &tInt)){
  308. if (m_sCameraInfo.m_iSourcePort != tInt){
  309. pSetting = config_setting_lookup(m_pSettings, BCI_TAG_SOURCE_PORT);
  310. config_setting_set_int(pSetting, m_sCameraInfo.m_iSourcePort);
  311. basicSettingsProvider::getInstance()->compromise();
  312. };
  313. };
  314. if (basicSettingsProvider::getInstance()->isCompromised()) basicSettingsProvider::getInstance()->validate();
  315. };
  316. void basicCamera::dispatchEvent( basicEvent *Evt ){
  317. if( Evt->m_eClass == EVT_CLASS_SENSOR ) {
  318. switch (Evt->m_eType){
  319. case EVT_TARGET:
  320. case EVT_TARGET_WHITE:
  321. case EVT_TARGET_BLACK:
  322. case EVT_ALARM:
  323. CLIENT_EVENT *tData;
  324. tData = ( CLIENT_EVENT *) Evt->m_pEvtData;
  325. // Basic Camera Reaction - Start Record
  326. break;
  327. default:
  328. break;
  329. };
  330. } else
  331. if (Evt->m_eClass == EVT_CLASS_IMAGE){
  332. switch (Evt->m_eType){
  333. case EVT_COMMAND:
  334. basicCameraCommand *pData;
  335. pData = (basicCameraCommand *)Evt->m_pEvtData;
  336. // Basic Camera Commands
  337. switch( pData->m_cCode ){
  338. case CMD_CAMERA_START_RECORD:
  339. m_pVideoNode->startRecord();
  340. break;
  341. case CMD_CAMERA_STOP_RECORD:
  342. m_pVideoNode->stopRecord();
  343. break;
  344. default:
  345. break;
  346. };
  347. break;
  348. default:
  349. break;
  350. };
  351. };
  352. };