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.
 
 
 
 
 
 

844 lines
29 KiB

#include "rgooseCamera.h"
#include "../components/base/basicCameraInfo.h"
#include "../components/object/objectSystemAnchor.h"
#include "../hardware/uart/serialPort.h"
#include "../hardware/uart/serialSOL.h"
#include "../data/protocol/protocolPTZ_VISCA.h"
#include "../data/protocol/protocolPTZ_ONVIF.h"
#include "../data/protocol/protocolPTZ_PELCO.h"
#include "rgooseKernel.h"
#include "rgooseModuleEmbedVideo.h"
#define LOG( X ) m_pLog->Log( "RCAM", this, X )
#ifdef DEBUG
#define LOG_ERROR( X ) {\
char _tBfrErrMSG2w34[256];\
sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
m_pLog->Log( "RCAM", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
}
#else
#define LOG_ERROR( X ) m_pLog->Log( "RCAM", this, _LOG_ERROR, X );
#endif
// all sizes in mm
static float AC_imager_diag[12] = { 5.0f, 5.68f, 6.0f, 6.592f, 8.0f, 8.933f, 11.0f, 16.0f, 22.5f, 30.1f, 43.3f, 69.7f };
static float AC_imager_width[12] = { 4.0f, 4.536f, 4.8f, 5.27f, 6.4f, 7.176f, 8.8f, 12.8f, 18.0f, 25.1f, 36.0f, 56.0f };
static float AC_imager_height[12] = { 3.0f, 3.416f, 3.6f, 3.96f, 4.8f, 5.319f, 6.6f, 9.6f, 13.5f, 16.7f, 24.0f, 41.5f };
ARGUS_Camera::ARGUS_Camera(): basicThread(){
m_pLog = basicLogCollection::getInstance();
m_pEvtHeap = basicEventHeap::getInstance();
m_pDBC = argusDBC::getInstance();
m_tTimeTSeconds = 0;
m_pPosition = NULL;
m_pProtocol = NULL;
m_pTransport = NULL;
m_bState = 0;
m_bBusy = true;
m_fMaxRange = m_fMinHFov = m_fMaxHFov = m_fMinVFov = m_fMaxVFov = .0f;
m_nRelativeMoveCounter = 0;
m_bRelativeMoveMatrix = 0;
m_fSpeedRise = 0.03f;
m_fRM_Pan = m_fRM_Tilt = m_fRM_Zoom = .0f;
m_bSourceConnected = false;
m_pSource = NULL;
};
ARGUS_Camera::~ARGUS_Camera(){
LOG("Destruct");
m_mQPROTECTOR.unlock();
waitThreadEnd( true );
LOG("Thread Del OK");
if( m_pTransport!= NULL ) {
if( m_sCamData.uart_id ) {
DBC_UART_DATA *tData = NULL;
tData = m_pDBC->getUartData( m_sCamData.uart_id );
switch( tData->type ) {
case UART_TYPE_HARDWARE:{
delete((serialPort*)m_pTransport);
break;
};
case UART_TYPE_SOL:{
delete((serialSOL*)m_pTransport);
break;
};
};
}
};
LOG("Transport Del OK");
if( m_pProtocol != NULL ) {
switch( m_sCamData.protocol ) {
case CAM_CTRL_PROTO_VISCA:
delete( (protocolPTZ_VISCA *) m_pProtocol );
break;
case CAM_CTRL_PROTO_PELCO:
delete( (protocolPTZ_PELCO *) m_pProtocol );
break;
case CAM_CTRL_PROTO_ONVIF:
delete( (protocolPTZ_ONVIF *) m_pProtocol );
break;
default:
delete( m_pProtocol );
};
};
LOG("Proto Del OK");
if( m_pPosition != NULL ) delete( m_pPosition );
LOG("Pos Del OK");
if( m_bSourceConnected ){
if( m_pSource != NULL ){
m_pSource->_close();
delete( m_pSource );
};
};
LOG("Stream Del OK");
};
bool ARGUS_Camera::create( uint32_t id ){
DBC_CAM_DATA * tData = m_pDBC->getCamData( id );
if( tData != NULL ) {
memcpy( &m_sCamData, tData, sizeof(DBC_CAM_DATA) );
free( tData );
} else {
LOG_ERROR("Cannot Fetch CAM Data from Database!");
return false;
};
if( m_sCamData.max_range == .0f ){
m_fMaxRange = calcMaxDistance_mm( AC_imager_diag[m_sCamData.imager_type], m_sCamData.max_f, 1280 );
} else {
m_fMaxRange = m_sCamData.max_range;
};
m_fMinHFov = calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_sCamData.min_f );
m_fMaxHFov = calcFOV_mm( AC_imager_width[m_sCamData.imager_type], m_sCamData.max_f );
m_fMinVFov = calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_sCamData.min_f );
m_fMaxVFov = calcFOV_mm( AC_imager_height[m_sCamData.imager_type], m_sCamData.max_f );
if( m_sCamData.ptz_speed_step > .0f ) {
m_fSpeedRise = m_sCamData.ptz_speed_step;
};
#ifdef DEBUG
char tB[128];
LOG("Camera Info:");
sprintf( tB, "Maximal Range: %0.2f m. ", m_fMaxRange);
LOG(tB);
sprintf( tB, "Maximal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMinHFov, m_fMinVFov );
LOG(tB);
sprintf( tB, "Minimal FOVs, Horizontal: %0.2f Vertical: %0.2f", m_fMaxHFov, m_fMaxVFov );
LOG(tB);
#endif
m_pPosition = new basicPosition( m_sCamData.lat, m_sCamData.lon, m_sCamData.alt, m_sCamData.roll, m_sCamData.pitch, m_sCamData.yaw );
if( m_pPosition == NULL ) {
LOG_ERROR("Position Constructor Failure!");
return false;
};
if( m_pProtocol != NULL ){
LOG_ERROR("Cannot Start: Service Already Running!");
return false;
};
switch( m_sCamData.protocol ){
case CAM_CTRL_PROTO_VISCA: {
#ifdef DEBUG
LOG("VISCA");
#endif
m_pProtocol = (protocolPTZ *) new protocolPTZ_VISCA();
if( m_pProtocol!= NULL ) {
DBC_UART_DATA *tData = NULL;
tData = m_pDBC->getUartData( m_sCamData.uart_id );
if( tData!= NULL ) {
basicTransport *tTransport = NULL;
switch( tData->type ) {
case UART_TYPE_HARDWARE:{ // Hardware
serialPort *tT = NULL;
tT = new serialPort();
if( tT!= NULL ){
if( tT->create( tData->path, tData->speed ) ){
tTransport = (basicTransport *) tT;
} else {
delete( tT );
};
};
break;
};
case UART_TYPE_SOL:{ // E2S
serialSOL *tT = NULL;
tT = new serialSOL( (SOL_TYPE) tData->mode );
if( tT!= NULL ){
if( tT->create( tData->path, tData->port, tData->speed ) ){
tTransport = (basicTransport *) tT;
} else {
delete( tT );
};
};
break;
};
};
if( tTransport!= NULL ) {
m_pProtocol->setTransport( tTransport );
};
free( tData );
};
};
break;
};
case CAM_CTRL_PROTO_PELCO:{
#ifdef DEBUG
LOG("PELCO");
#endif
m_pProtocol = (protocolPTZ *) new protocolPTZ_PELCO();
if( m_pProtocol!= NULL ) {
DBC_UART_DATA *tData = NULL;
tData = m_pDBC->getUartData( m_sCamData.uart_id );
if( tData!= NULL ) {
basicTransport *tTransport = NULL;
switch( tData->type ) {
case UART_TYPE_HARDWARE:{
#ifdef DEBUG
LOG("HW Port");
#endif
serialPort *tT = NULL;
tT = new serialPort();
if( tT!= NULL ){
if( tT->create( tData->path, tData->speed ) ){
tTransport = (basicTransport *) tT;
} else {
delete( tT );
};
};
break;
};
case UART_TYPE_SOL:{
#ifdef DEBUG
LOG("SOL Port");
#endif
serialSOL *tT = NULL;
tT = new serialSOL( (SOL_TYPE)tData->mode );
if( tT!= NULL ){
if( tT->create( tData->path, tData->port, tData->speed ) ){
tTransport = (basicTransport *) tT;
} else {
delete( tT );
};
};
break;
};
#ifdef DEBUG
default: LOG_ERROR("Unknown Port Type!");
#endif
};
if( tTransport!= NULL ) {
LOG( "Bind Transport Port!" );
if( m_pProtocol->setTransport( tTransport )){
if( !m_pProtocol->create() ){
LOG_ERROR("Protocol <<< Create >>> Failure!");
};
} else {
LOG_ERROR("Binding Port Failure!");
};
} else LOG_ERROR("Transport Creation Failure!");
free( tData );
}
#ifdef DEBUG
else LOG_ERROR("No Uart DATA loaddesd!");
#endif
}
#ifdef DEBUG
else LOG_ERROR("Protocol NEW failure!");
#endif
break;
};
case CAM_CTRL_PROTO_ONVIF:{
#ifdef DEBUG
LOG("ONVIF");
#endif
m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.username, m_sCamData.password );
if( m_pProtocol!=NULL ) {
if( !m_pProtocol->create() ) {
LOG_ERROR("Error Creating Proto!");
delete( (protocolPTZ_ONVIF*) m_pProtocol );
m_pProtocol = NULL;
};
};
break;
};
default:{
#ifdef DEBUG
LOG("Camera Has no defined control protocol");
#endif
};
};
if( m_pProtocol == NULL ) {
if(m_sCamData.protocol == 0 ) {
m_sCamData.online = true;
} else LOG_ERROR("No Proto Created!");
} else {
#ifdef DEBUG
LOG("Proto is OK");
#endif
m_sCamData.online = init();
};
return m_sCamData.online;
};
void ARGUS_Camera::setBusy( bool Status ){
m_bBusy = Status;
};
bool ARGUS_Camera::relativeMove( float PanSPD, float TiltSPD, float ZoomSPD ){
if( m_sCamData.online ) {
uint32_t MoveMatrix = 0;
if( PanSPD != .0f ){
if( PanSPD > 0 ) {
MoveMatrix |= PTZ_DRIVE_PAN_RIGHT;
} else {
MoveMatrix |= PTZ_DRIVE_PAN_LEFT;
};
};
if( TiltSPD != .0f ){
if( TiltSPD > 0 ) {
MoveMatrix |= PTZ_DRIVE_TILT_UP;
} else {
MoveMatrix |= PTZ_DRIVE_TILT_DOWN;
};
};
if( ZoomSPD != .0f ){
if( ZoomSPD > 0 ) {
MoveMatrix |= PTZ_DRIVE_ZOOM_WIDE;
} else {
MoveMatrix |= PTZ_DRIVE_ZOOM_TELE;
};
};
if( MoveMatrix != 0 ) {
m_pProtocol->setPTZSpeed( fabs(PanSPD), fabs(TiltSPD), fabs(ZoomSPD) );
};
return m_pProtocol->move( MoveMatrix );
};
return false;
};
bool ARGUS_Camera::relativeStop(){
if( m_sCamData.online ) {
return m_pProtocol->move( 0 );
};
return false;
};
bool ARGUS_Camera::absoluteMove( float PanPOS, float TiltPOS, float ZoomPOS ){
if( m_sCamData.online ) {
CAM_PTZ_CMD *tCMD = (CAM_PTZ_CMD*) malloc( sizeof(CAM_PTZ_CMD));
if( tCMD ) {
memset( tCMD, 0 , sizeof(CAM_PTZ_CMD));
tCMD->CMD = PTZ_ABSOLUTE;
tCMD->PAN = PanPOS;
tCMD->TILT = TiltPOS;
tCMD->ZOOM = ZoomPOS;
m_mQPROTECTOR.lock();
m_qCAM_CMD.push( tCMD );
m_mQPROTECTOR.unlock();
return true;
};
};
return false;
};
void ARGUS_Camera::m_fThreadProc( void ){
m_bThreadStatus = TH_WORKING;
while( m_bThreadStatus < TH_ENDED ) {
//Local Recorder
if( m_bSourceConnected ) {
};
DBC_PUSHED_CMD * PUSHED = m_pDBC->getCamPushedCMD( m_sCamData.id );
if( PUSHED ) {
if( ( PUSHED->CMD & ARGUS_CAM_PCMD_CMD_MASK ) == ARGUS_CAM_PCMD_CMD_MASK ) {
switch( PUSHED->CMD ) {
case 0x80:{
//m_bWM = ANODE_WM_2D_ISSUE_FULL_RESET;
break;
};
case 0x81:{
//m_bWM = ANODE_WM_2D_GET_FAST_DRAW;
break;
};
case 0x82:{
break;
};
};
} else {
//Direct Movment Mode
if( PUSHED->CMD == ARGUS_CAM_PCMD_STOP ) {
m_bState = CAM_WS_STOP_MOVE;
} else {
char tB[64];
if( m_bState!= CAM_WS_AUTOMATED_MOVE ) m_nRelativeMoveCounter = 0;
m_bRelativeMoveMatrix = ( PUSHED->CMD ) >> 1;
m_bState = CAM_WS_AUTOMATED_MOVE;
};
};
free( PUSHED );
};
switch( m_bState ) {
case CAM_WS_INIT:{
#ifdef DEBUG
LOG("Init Camera - PowerMode");
#endif
if( m_pProtocol->initCamera() ) m_bState = CAM_WS_WHITE_BALLANCE;
break;
};
case CAM_WS_WHITE_BALLANCE:{
#ifdef DEBUG
LOG("Set WB");
#endif
if( m_pProtocol->setWhiteBalanceMode( WB_AUTO ) ) m_bState = CAM_WS_BACKLIGHT;
break;
};
case CAM_WS_BACKLIGHT:{
#ifdef DEBUG
LOG("Set BLC");
#endif
if( m_pProtocol->setBackLightMode( true ) ) m_bState = CAM_WS_AUTO_FOCUS;
//if( m_pProtocol->goHomePosition() ) m_bState++;
break;
};
case CAM_WS_AUTO_FOCUS:{
#ifdef DEBUG
LOG("Set AF");
#endif
if( m_pProtocol->setAutoFocus( true ) ) m_bState = CAM_WS_INIT_GO_HOME;
break;
};
case CAM_WS_INIT_GO_HOME:{
#ifdef DEBUG
LOG("INIT GO -1 -1 -1");
#endif
if( m_pProtocol->goAbsolute( -1, -1, -1 ) ){
m_bState = CAM_WS_READY;
setBusy( false );
};
break;
};
case CAM_WS_AUTOMATED_MOVE:{
m_nRelativeMoveCounter++;
if( ( m_bRelativeMoveMatrix & 0x03 ) != 0 ) {
//Pan Move
if( ( m_bRelativeMoveMatrix & 0x01 ) == 0 ) {
m_fRM_Pan -= m_fSpeedRise;
} else {
m_fRM_Pan += m_fSpeedRise;
};
};
if( ( m_bRelativeMoveMatrix & 0x0C ) != 0 ) {
//TILT Move
if( ( m_bRelativeMoveMatrix & 0x04 ) == 0 ) {
m_fRM_Tilt -= m_fSpeedRise;
} else {
m_fRM_Tilt += m_fSpeedRise;
}
};
if( ( m_bRelativeMoveMatrix & 0x30 ) != 0 ) {
//ZOOM Move
if( ( m_bRelativeMoveMatrix & 0x10 ) == 0 ) {
//Wide
m_fRM_Zoom -= m_fSpeedRise;
} else {
//Tele
m_fRM_Zoom += m_fSpeedRise;
};
};
if( m_fRM_Pan < -1.0f ) m_fRM_Pan = -1.0f;
if( m_fRM_Pan > 1.0f ) m_fRM_Pan = 1.0f;
if( m_fRM_Tilt < -1.0f ) m_fRM_Tilt = -1.0f;
if( m_fRM_Tilt > 1.0f ) m_fRM_Tilt = 1.0f;
if( m_fRM_Zoom < -1.0f ) m_fRM_Zoom = -1.0f;
if( m_fRM_Zoom > 1.0f ) m_fRM_Zoom = 1.0f;
setBusy( true );
if( !relativeMove( m_fRM_Pan, m_fRM_Tilt, m_fRM_Zoom ) ){
m_bState = CAM_WS_READY;
};
setBusy( false );
break;
};
case CAM_WS_STOP_MOVE:{
m_fRM_Pan = .0f;
m_fRM_Pan = .0f;
m_fRM_Tilt = .0f;
m_fRM_Tilt = .0f;
m_fRM_Zoom = .0f;
m_fRM_Zoom = .0f;
setBusy( true );
if( relativeStop() ){
m_bState = CAM_WS_READY;
};
setBusy( false );
break;
}
case CAM_WS_READY:{
m_mQPROTECTOR.lock();
if( m_qCAM_CMD.size() ){
char tB[128];
sprintf( tB,"Queue: %d commands!", m_qCAM_CMD.size() );
LOG( tB );
CAM_PTZ_CMD *tCMD = m_qCAM_CMD.front();
if( tCMD ) {
m_qCAM_CMD.pop();
m_mQPROTECTOR.unlock();
switch( tCMD->CMD ) {
case PTZ_STOP:{
m_pProtocol->goStop();
setBusy( false );
break;
};
case PTZ_MOVE:{
uint32_t MoveMatrix = 0;
if( m_pProtocol->setPTZSpeed( tCMD->PAN, tCMD->TILT, tCMD->ZOOM ) ){
SLEEP( 5 );
m_pProtocol->move( MoveMatrix );
};
break;
};
case PTZ_ABSOLUTE:{
setBusy( true );
if( !m_pProtocol->goAbsolute( tCMD->PAN, tCMD->TILT, tCMD->ZOOM ) ) {
LOG_ERROR("Cannot Issue goAbsolute Command!");
//SLEEP( 1000 );
};
setBusy( false );
break;
};
case PTZ_RELOAD_CAMERA:{
LOG("Exit Command Rcpt");
m_bThreadStatus = TH_ENDED;
setBusy( true );
};
};
free( tCMD );
} else {
m_mQPROTECTOR.unlock();
LOG_ERROR("Error Fetching CMD from Queue");
SLEEP( DEFAULT_THREAD_SLEEP_TIME );
};
} else {
m_mQPROTECTOR.unlock();
SLEEP( DEFAULT_THREAD_SLEEP_TIME );
};
break;
};
case CAM_WS_END:{
LOG("Exit Command Rcpt");
m_bThreadStatus = TH_ENDED;
setBusy( true );
break;
};
};
SLEEP( DEFAULT_THREAD_SLEEP_TIME );
};
LOG("CTRL Loop End!");
};
bool ARGUS_Camera::inTheFOV( float lat, float lon, float alt ){
bool RetVal = false;
char tB[128];
if( m_pPosition == NULL ) return RetVal;
position3D * tPOS;
transform_3 * tTrans = NULL;
tPOS = new position3D();
if( tPOS == NULL ) return RetVal;
tPOS->setPositionWGS84( lat, lon, alt );
tTrans = m_pPosition->getTransform();
if(tTrans == NULL ){
delete( tPOS );
return RetVal;
};
vector_3 A, B;
C3D_SPH_DEGREES tSph;
C3D_DECART tLoc;
tLoc = tPOS->getXYZ();
A[0]= tLoc.x; A[1]= tLoc.y; A[2]= tLoc.z;
tTrans->get_vector_local(A, B);
tLoc.x = B[0]; tLoc.y = B[1]; tLoc.z = B[2];
decart2spherical( tLoc, tSph );
// sprintf( tB,"Object Dist: %0.2f ... cam range: %0.2f", tSph.r, m_fMaxRange );
// LOG( tB );
RetVal = ( tSph.r < m_fMaxRange );
if( RetVal ) {
//Checking if FOV is OK
bool pOK = false;
bool tOK = false;
float HS = AC_imager_width[m_sCamData.imager_type];
float VS = AC_imager_height[m_sCamData.imager_type];
float HS2 = HS * HS;
float VS2 = VS * VS;
float IR = HS / VS;
float IR2 = IR * IR;
if( m_sCamData.pan_angles == 0 ) {
// Fixed Camera
pOK = ( tSph.fi > ( m_fMaxHFov / -2.0f ) ) && ( tSph.fi < ( m_fMaxHFov / 2.0f ) );
} else {
if( m_sCamData.pan_angles > 359 ) {
// Endless Pan
pOK = true;
} else {
// Partial Pan
switch( m_sCamData.pan_model ) {
case 1: {
// Regular Pan
float tFOV = 0.5f * ( m_fMinHFov + ( m_fMaxHFov - m_fMinHFov ) * ( tSph.r / m_fMaxRange ) ) ;
float tRad = deg2rad( tSph.fi );
// sprintf( tB, "FOV: %0.3f CC: %0.3f", tFOV, tRad );
//LOG( tB );
pOK = ( tRad > ( -1.0 * tFOV ) ) && ( tRad < ( deg2rad( m_sCamData.pan_angles ) + tFOV ) ) ;
break;
};
case 2:{
break;
};
case 3:{
break;
};
};
};
};
if( m_sCamData.tilt_angles == 0 ) {
//Fixed Camera
tOK = ( tSph.tetta > ( m_fMaxVFov / -2.0f ) ) && ( tSph.tetta < ( m_fMaxVFov / 2.0f ) );
} else {
if( m_sCamData.tilt_angles > 89 ) {
// Endless Tilt
tOK = true;
} else {
// Partial Tilt
switch( m_sCamData.tilt_model ) {
case 1: {
// Regular Tilt
float tFOV = 0.5f * ( m_fMinVFov + ( m_fMaxVFov - m_fMinVFov ) * ( tSph.r / m_fMaxRange ) ) ;
float tRad = deg2rad( tSph.tetta );
tOK = ( tRad > ( -1.0 * tFOV ) ) && ( tRad < ( deg2rad( m_sCamData.tilt_angles ) + tFOV ) ) ;
break;
};
case 2:{
break;
};
};
};
};
//sprintf( tB, "Pan: %d Tilt: %d", pOK, tOK );
//LOG( tB );
RetVal = ( pOK && tOK );
} else {
//LOG("Object Too Far!");
}
delete( tPOS );
return RetVal;
};
bool ARGUS_Camera::lookAtWGS84( uint32_t TargetRefID, float lat, float lon, float alt ){
C3D_WGS84_LOC tWGS;
C3D_SPH_DEGREES tSph;
char tB[128];
//sprintf(tB,"LookAt: %0.5f %0.5f %0.2f", lat, lon, alt );
//LOG( tB );
if( m_bBusy ){
//LOG("CAM BUSY!");
return false;
};
// Exit for fixed Cam
if( ( m_sCamData.pan_model == 0 ) && ( m_sCamData.tilt_model == 0 ) ) return true;
// Exit for unpositioned Cam
if( m_pPosition == NULL ) return false;
tWGS.lat = lat;
tWGS.lon = lon;
tWGS.alt = alt;
systemAnchor* tSystem = systemAnchor::getInstance();
if( tSystem != NULL ) {
tSystem->convertToLocal( m_pPosition, tWGS, tSph );
} else {
LOG_ERROR("No SYSTEM ANCHOR!");
return false;
};
//sprintf( tB, "local coords: %0.2fm. %0.2f° %0.2f°", tSph.r, tSph.tetta, tSph.fi );
//LOG( tB );
float fZ, fT, fP;
if( m_fMaxRange > 0.0f ) {
if( tSph.r > m_fMaxRange ) {
fZ = 1;
} else {
fZ = tSph.r / m_fMaxRange;
};
} else fZ = 0.f;
switch( m_sCamData.pan_model ){
case 1:{
fP = ( 2.0 / m_sCamData.pan_angles ) * tSph.tetta - 1.0;
break;
};
case 2:{
fP = ( 2.0 / 360.0 ) * tSph.tetta - 1.0;
};
};
switch( m_sCamData.tilt_model ) {
case 1:{
fT = -2.0f * ( ( m_sCamData.tilt_angles - tSph.fi ) / m_sCamData.tilt_angles ) + 1.0;
break;
};
case 2:{
fT = ( 2.0 / m_sCamData.tilt_angles ) * ( m_sCamData.tilt_angles - tSph.fi ) - 1.0;
break;
};
};
//sprintf(tB,"EVT:%d AM: %0.2f %0.2f %0.2f", TargetRefID, fP, fT, fZ );
//LOG( tB );
if( absoluteMove( fP, fT, fZ ) ) {
#ifdef DEBUG
//LOG("CHECK CAMERA STREAMS");
#endif
EVENT_CONTAINER *tEVT;
DBC_INT_LIST *tStreams;
tStreams = m_pDBC->listCamMediaStreams( m_sCamData.id );
if( tStreams!= NULL ) {
for( uint32_t idx = 0; idx < tStreams->size(); idx++ ) {
tEVT = createBasicTargetedEvent( m_sCamData.node_id, tStreams->at(idx), EVT_CLASS_VIDEO, EVT_CAPTURE_START );
if( tEVT != NULL ) {
tEVT->m_ref_id = TargetRefID;
m_pEvtHeap->broadcast( tEVT );
};
};
delete( tStreams );
};
return true;
};
return false;
};
bool ARGUS_Camera::captureFrame( CSTR fileName, uint8_t compression ){
if( m_bSourceConnected ) {
if( m_pSource != NULL ) {
};
};
return false;
};
bool ARGUS_Camera::connectToStream( uint32_t id ){
if( id ){
argusKernelModule * tKM = NULL;
argusKernel * tKRNL = NULL;
argusModuleFactory * tMF = NULL;
if( m_pDBC == NULL ) {
LOG_ERROR("No Database Connector!");
return false;
};
tKRNL = argusKernel::getInstance();
if( tKRNL ) {
tMF = tKRNL->getModuleFactory();
if( tMF ) {
tKM = tMF->getModule( ARGUS_MODULE_EMBED_VIDEO );
} else {
LOG_ERROR("No ModuleFactory Instance!");
return false;
};
} else {
LOG_ERROR("No Kernel Instance!");
return false;
};
if( tKM ) {
DBC_MEDIA_STREAM_DATA *tDATA = m_pDBC->getMediaStreamData( id );
if( tDATA ) {
LOG( tDATA->mrl_proto );
m_sMediaSource.mediaStreamId = id;
m_pSource = new videoAVLIBSource( &m_sMediaSource );
if( m_pSource != NULL ) {
char tMRL[1024];
#ifdef DEBUG
LOG("Source OK");
#endif
int tW = ((argusModuleEmbedVideo*)tKM)->getWidh();
//int tH = ((argusModuleEmbedVideo*)tKM)->getHeight();
if( tW > 0 ) {
m_pSource->setProportionalByWidth( tW );
//m_pSource->setSize( tW, tH );
};
if( strncmp( tDATA->mrl_proto, "v4l2", 4 ) == 0 ){
sprintf( tMRL, tDATA->mrl );
} else {
DBC_CAM_DATA *tCAM = m_pDBC->getCamData( tDATA->source_id );
if( tCAM ) {
sprintf( tMRL, "%s://%s:%s@%s:%d%s", tDATA->mrl_proto, tCAM->username, tCAM->password, tCAM->ip, tDATA->mrl_port, tDATA->mrl );
free( tCAM );
} else {
LOG_ERROR("Error Getting CAM Data!");
delete( m_pSource );
m_pSource = NULL;
return false;
};
};
LOG( tMRL );
if( m_pSource->_open( tMRL ) ) {
m_pSource->attachDestination( (argusModuleEmbedVideo*) tKM );
#ifdef DEBUG
LOG("Finish!");
#endif
m_bSourceConnected = true;
} else {
LOG_ERROR("Can not Open Video Source!");
delete( m_pSource );
m_pSource = NULL;
};
} else {
LOG_ERROR("Video Source Stream Failure!");
};
free( tDATA );
};
}
#ifdef DEBUG
else LOG("No Video Module!")
#endif
;
};
return m_bSourceConnected;
};
bool ARGUS_Camera::disconnectFromStream( void ){
if( m_bSourceConnected ) {
if( m_pSource ){
delete( m_pSource );
m_pSource = NULL;
};
m_bSourceConnected = false;
};
return !m_bSourceConnected;
};
#undef LOG
#undef LOG_ERROR