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.

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