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.
354 lines
14 KiB
354 lines
14 KiB
#include "basicCamera.h"
|
|
|
|
// Constructor implementation
|
|
basicCamera::basicCamera(config_setting_t *Settings) : basicObject(), basicPosition(), basicEventHandler() {
|
|
m_eCaps = (objectCaps)(OC_EVENT_HANDLER);
|
|
m_pSettings = Settings;
|
|
m_iStatus = PS_BORN;
|
|
memset(&m_sSourceInfo, 0 , sizeof(SOURCE_INFO));
|
|
//m_sSourceInfo.fSensorSize = ( 1.f / 2.8f ) * .0254f; // in meters
|
|
m_pVideoSource = NULL;
|
|
m_pVideoNode = new videoNode(m_pSettings);
|
|
};
|
|
|
|
// Destructor implementation
|
|
basicCamera::~basicCamera(){
|
|
m_vOSD.clear();
|
|
updateSettings();
|
|
if (m_pVideoNode != NULL){
|
|
m_pVideoNode->setStatus(TH_EXIT);
|
|
delete(m_pVideoNode);
|
|
};
|
|
};
|
|
|
|
bool basicCamera::create(void){
|
|
config_setting_t *pSetting;
|
|
if (m_pSettings == NULL) return false;
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_TYPE);
|
|
if (pSetting == NULL) return false;
|
|
m_sSourceInfo.type = config_setting_get_int(pSetting);
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_TYPE);
|
|
if (pSetting == NULL) return false;
|
|
m_sSourceInfo.subtype = config_setting_get_int(pSetting);
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_WIDTH);
|
|
if (pSetting == NULL) return false;
|
|
m_sSourceInfo.width = config_setting_get_int(pSetting);
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_HEIGHT);
|
|
if (pSetting == NULL) return false;
|
|
m_sSourceInfo.height = config_setting_get_int(pSetting);
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_NAME);
|
|
if (pSetting == NULL) return false;
|
|
sprintf( m_sSourceInfo.deviceName, "%s", config_setting_get_string(pSetting));
|
|
if( m_sSourceInfo.subtype != 1){
|
|
if( m_sSourceInfo.subtype == 0){
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PORT);
|
|
if (pSetting == NULL) return false;
|
|
m_sSourceInfo.capturePin = config_setting_get_int(pSetting);
|
|
};
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PATH);
|
|
if (pSetting == NULL) return false;
|
|
sprintf( m_sSourceInfo.devicePath, "%s", config_setting_get_string(pSetting));
|
|
} else {
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_VIDEO_MRL);
|
|
if (pSetting == NULL) return false;
|
|
sprintf( m_sSourceInfo.onvifVideoMRL, "%s", config_setting_get_string(pSetting));
|
|
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_PICTURE_MRL);
|
|
if (pSetting == NULL) return false;
|
|
sprintf( m_sSourceInfo.onvifPictureMRL, "%s", config_setting_get_string(pSetting));
|
|
};
|
|
/*Location*/
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT);
|
|
if (pSetting == NULL) return false;
|
|
m_sSourceInfo.lat = config_setting_get_float(pSetting);
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON);
|
|
if (pSetting == NULL) return false;
|
|
m_sSourceInfo.lon = config_setting_get_float(pSetting);
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT);
|
|
if (pSetting == NULL) return false;
|
|
m_sSourceInfo.alt = config_setting_get_float(pSetting);
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ROLL);
|
|
if (pSetting == NULL) return false;
|
|
m_sSourceInfo.h_lat = config_setting_get_float(pSetting);
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_PITCH);
|
|
if (pSetting == NULL) return false;
|
|
m_sSourceInfo.h_lon = config_setting_get_float(pSetting);
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_YAW);
|
|
if (pSetting == NULL) return false;
|
|
m_sSourceInfo.h_alt = config_setting_get_float(pSetting);
|
|
setPositionDeg(m_sSourceInfo.lat, m_sSourceInfo.lon, m_sSourceInfo.alt, m_sSourceInfo.h_lat, m_sSourceInfo.h_lon, m_sSourceInfo.h_alt);
|
|
return true;
|
|
};
|
|
|
|
bool basicCamera::create(SOURCE_INFO *SI){
|
|
config_setting_t *pSetting;
|
|
if (m_pSettings == NULL) return false;
|
|
if (SI == NULL) return false;
|
|
memcpy( &m_sSourceInfo, SI, sizeof(SOURCE_INFO) );
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_TYPE);
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_TYPE, CONFIG_TYPE_INT);
|
|
};
|
|
config_setting_set_int(pSetting, m_sSourceInfo.type);
|
|
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_TYPE);
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, BCI_TAG_SOURCE_TYPE, CONFIG_TYPE_INT);
|
|
};
|
|
config_setting_set_int(pSetting, m_sSourceInfo.subtype);
|
|
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_CAMERA_NAME);
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, BCI_TAG_CAMERA_NAME, CONFIG_TYPE_STRING);
|
|
};
|
|
config_setting_set_string(pSetting, m_sSourceInfo.deviceName);
|
|
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_WIDTH);
|
|
//if (SI->frameIsWide){
|
|
// m_sCameraInfo.m_iWidth = g_aFrameWidthStandard_16_9[SI->sizeId];
|
|
//} else {
|
|
// m_sCameraInfo.m_iWidth = g_aFrameWidthStandard_4_3[SI->sizeId];
|
|
//};
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, BCI_TAG_IMAGE_WIDTH, CONFIG_TYPE_INT);
|
|
};
|
|
config_setting_set_int(pSetting, m_sSourceInfo.width);
|
|
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_IMAGE_HEIGHT);
|
|
//if (SI->frameIsWide){
|
|
// m_sCameraInfo.m_iHeight = g_aFrameHeightStandard_16_9[SI->sizeId];
|
|
//} else {
|
|
// m_sCameraInfo.m_iHeight = g_aFrameHeightStandard_4_3[SI->sizeId];
|
|
//};
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, BCI_TAG_IMAGE_HEIGHT, CONFIG_TYPE_INT);
|
|
};
|
|
config_setting_set_int(pSetting, m_sSourceInfo.height);
|
|
|
|
/*Location*/
|
|
//float tLat, tLon, tAlt, tRoll, tPitch, tYaw;
|
|
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT);
|
|
//tLat = systemAnchor::getInstance()->getLat();
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT);
|
|
};
|
|
config_setting_set_float(pSetting, m_sSourceInfo.lat );
|
|
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON);
|
|
//tLon = systemAnchor::getInstance()->getLon();
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT);
|
|
};
|
|
config_setting_set_float(pSetting, m_sSourceInfo.lon);
|
|
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT);
|
|
//tAlt = systemAnchor::getInstance()->getAlt();
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT);
|
|
};
|
|
config_setting_set_float(pSetting, m_sSourceInfo.alt);
|
|
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_PITCH);
|
|
//tPitch = 0.f;
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_PITCH, CONFIG_TYPE_FLOAT);
|
|
};
|
|
config_setting_set_float(pSetting, m_sSourceInfo.h_lon);
|
|
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ROLL);
|
|
//tRoll = 0.f;
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_ROLL, CONFIG_TYPE_FLOAT);
|
|
};
|
|
config_setting_set_float(pSetting, m_sSourceInfo.h_lat);
|
|
|
|
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_YAW);
|
|
//tYaw = 0.f;
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, TAG_POSITION_YAW, CONFIG_TYPE_FLOAT);
|
|
};
|
|
config_setting_set_float(pSetting, m_sSourceInfo.h_alt);
|
|
|
|
setPositionDeg(SI->lat, SI->lon, SI->alt, SI->h_lon, SI->h_lat, SI->h_alt);
|
|
|
|
if( m_sSourceInfo.subtype != 1 ){ // File or Local Source
|
|
if( m_sSourceInfo.subtype == 0 ){ // Local Source
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PORT);
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, BCI_TAG_SOURCE_PORT, CONFIG_TYPE_INT);
|
|
};
|
|
config_setting_set_int(pSetting, m_sSourceInfo.capturePin);
|
|
};
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_SOURCE_PATH);
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, BCI_TAG_SOURCE_PATH, CONFIG_TYPE_STRING);
|
|
};
|
|
config_setting_set_string(pSetting, m_sSourceInfo.devicePath);
|
|
} else {
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_VIDEO_MRL);
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, BCI_TAG_VIDEO_MRL, CONFIG_TYPE_STRING);
|
|
};
|
|
config_setting_set_string(pSetting, m_sSourceInfo.onvifVideoMRL);
|
|
|
|
pSetting = config_setting_get_member(m_pSettings, BCI_TAG_PICTURE_MRL);
|
|
if (pSetting == NULL){
|
|
pSetting = config_setting_add(m_pSettings, BCI_TAG_PICTURE_MRL, CONFIG_TYPE_STRING);
|
|
};
|
|
config_setting_set_string(pSetting, m_sSourceInfo.onvifPictureMRL);
|
|
};
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
return true;
|
|
};
|
|
|
|
void basicCamera::updateSettings(void){
|
|
if(!m_pSettings) return;
|
|
config_setting_t *pSetting;
|
|
int tInt;
|
|
double tFloat;
|
|
CSTR tBuff;
|
|
if (config_setting_lookup_float(m_pSettings, TAG_POSITION_LAT, &tFloat)){
|
|
if (tFloat != getLat()){
|
|
tFloat = getLat();
|
|
pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_LAT);
|
|
config_setting_set_float(pSetting, tFloat);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (config_setting_lookup_float(m_pSettings, TAG_POSITION_LON, &tFloat)){
|
|
if (tFloat != getLon()){
|
|
tFloat = getLon();
|
|
pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_LON);
|
|
config_setting_set_float(pSetting, tFloat);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (config_setting_lookup_float(m_pSettings, TAG_POSITION_ALT, &tFloat)){
|
|
if (tFloat != getAlt()){
|
|
tFloat = getAlt();
|
|
pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_ALT);
|
|
config_setting_set_float(pSetting, tFloat);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (config_setting_lookup_float(m_pSettings, TAG_POSITION_YAW, &tFloat)){
|
|
if (tFloat != getRotZ_deg()){
|
|
tFloat = getRotZ_deg();
|
|
pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_YAW);
|
|
config_setting_set_float(pSetting, tFloat);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (config_setting_lookup_float(m_pSettings, TAG_POSITION_ROLL, &tFloat)){
|
|
if (tFloat != getRotY_deg()){
|
|
tFloat = getRotY_deg();
|
|
pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_ROLL);
|
|
config_setting_set_float(pSetting, tFloat);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (config_setting_lookup_float(m_pSettings, TAG_POSITION_PITCH, &tFloat)){
|
|
if (tFloat != getRotX_deg()){
|
|
tFloat = getRotX_deg();
|
|
pSetting = config_setting_lookup(m_pSettings, TAG_POSITION_PITCH);
|
|
config_setting_set_float(pSetting, tFloat);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (config_setting_lookup_string(m_pSettings, BCI_TAG_CAMERA_NAME, (const char**)&tBuff)){
|
|
if (strcmp(m_sSourceInfo.deviceName, tBuff) != 0){
|
|
pSetting = config_setting_lookup(m_pSettings, BCI_TAG_CAMERA_NAME);
|
|
config_setting_set_string(pSetting, m_sSourceInfo.deviceName);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (config_setting_lookup_int(m_pSettings, BCI_TAG_CAMERA_TYPE, &tInt)){
|
|
if (m_sSourceInfo.type != tInt){
|
|
pSetting = config_setting_lookup(m_pSettings, BCI_TAG_CAMERA_TYPE);
|
|
config_setting_set_int(pSetting, m_sSourceInfo.type);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (config_setting_lookup_int(m_pSettings, BCI_TAG_SOURCE_TYPE, &tInt)){
|
|
if (m_sSourceInfo.subtype != tInt){
|
|
pSetting = config_setting_lookup(m_pSettings, BCI_TAG_SOURCE_TYPE);
|
|
config_setting_set_int(pSetting, m_sSourceInfo.subtype);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (config_setting_lookup_int(m_pSettings, BCI_TAG_IMAGE_WIDTH, &tInt)){
|
|
if (m_sSourceInfo.width != tInt){
|
|
pSetting = config_setting_lookup(m_pSettings, BCI_TAG_IMAGE_WIDTH);
|
|
config_setting_set_int(pSetting, m_sSourceInfo.width);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if (config_setting_lookup_int(m_pSettings, BCI_TAG_IMAGE_HEIGHT, &tInt)){
|
|
if (m_sSourceInfo.height != tInt){
|
|
pSetting = config_setting_lookup(m_pSettings, BCI_TAG_IMAGE_HEIGHT);
|
|
config_setting_set_int(pSetting, m_sSourceInfo.height);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
if(m_sSourceInfo.subtype != 1){
|
|
if(m_sSourceInfo.subtype ==0){
|
|
if (config_setting_lookup_int(m_pSettings, BCI_TAG_SOURCE_PORT, &tInt)){
|
|
if (m_sSourceInfo.capturePin != tInt){
|
|
pSetting = config_setting_lookup(m_pSettings, BCI_TAG_SOURCE_PORT);
|
|
config_setting_set_int(pSetting, m_sSourceInfo.capturePin);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
};
|
|
if (config_setting_lookup_string(m_pSettings, BCI_TAG_SOURCE_PATH, (const char**)&tBuff)){
|
|
if (strcmp(m_sSourceInfo.devicePath, tBuff) != 0){
|
|
pSetting = config_setting_lookup(m_pSettings, BCI_TAG_SOURCE_PATH);
|
|
config_setting_set_string(pSetting, m_sSourceInfo.devicePath);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
};
|
|
if (basicSettingsProvider::getInstance()->isCompromised()) basicSettingsProvider::getInstance()->validate();
|
|
};
|
|
|
|
void basicCamera::dispatchEvent( basicEvent *Evt ){
|
|
if( Evt->m_eClass == EVT_CLASS_SENSOR ) {
|
|
switch (Evt->m_eType){
|
|
case EVT_TARGET_1D:
|
|
case EVT_TARGET_2D_WHITE:
|
|
case EVT_TARGET_2D_BLACK:
|
|
case EVT_TARGET_3D_WHITE:
|
|
case EVT_TARGET_3D_BLACK:
|
|
case EVT_ALARM:
|
|
CLIENT_EVENT *tData;
|
|
tData = ( CLIENT_EVENT *) Evt->m_pEvtData;
|
|
// Basic Camera Reaction - Start Record
|
|
|
|
break;
|
|
default:
|
|
break;
|
|
};
|
|
} else
|
|
if (Evt->m_eClass == EVT_CLASS_VIDEO){
|
|
switch (Evt->m_eType){
|
|
case EVT_COMMAND:
|
|
basicCameraCommand *pData;
|
|
pData = (basicCameraCommand *)Evt->m_pEvtData;
|
|
// Basic Camera Commands
|
|
switch( pData->m_cCode ){
|
|
case CMD_CAMERA_START_RECORD:
|
|
m_pVideoNode->startRecord();
|
|
break;
|
|
case CMD_CAMERA_STOP_RECORD:
|
|
m_pVideoNode->stopRecord();
|
|
break;
|
|
default:
|
|
break;
|
|
};
|
|
break;
|
|
default:
|
|
break;
|
|
};
|
|
};
|
|
};
|