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.
469 lines
12 KiB
469 lines
12 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 12/11/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: VideoBase.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of VideoBase.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "chicago.h"
|
|
#include "VideoBase.h"
|
|
#include "..\DLIB\VideoWnd.h"
|
|
#include "VideoFrameWnd.h"
|
|
#include "VideoListWnd.h"
|
|
#include "..\dlib\Settings.h"
|
|
#include "..\..\lglib\video\directshowstreamvideo.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
CVideoBase::CVideoBase()
|
|
{
|
|
// m_pDSConfiguration = NULL;
|
|
m_nVideo = 0;
|
|
m_pVideoFrameWnd = NULL;
|
|
m_pVideoListWnd = NULL;
|
|
m_pCameraNavigateDlg = NULL;
|
|
m_pSensorArray = NULL;
|
|
m_bCameraSwitchLock = FALSE;
|
|
m_nVideoFormat = VF_NONE;
|
|
m_pSettings = NULL;
|
|
m_nVideoFPS = 3;
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CVideoBase::CVideoBase") );
|
|
}
|
|
|
|
CVideoBase::~CVideoBase()
|
|
{
|
|
Destroy();
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CVideoBase::~CVideoBase") );
|
|
}
|
|
|
|
BOOL CVideoBase::InitDirectShow(CWnd *pBaseWnd, CSettings *pSettings )
|
|
{
|
|
// normal processing
|
|
if( !m_DirectShowBase.Create() )
|
|
return FALSE;
|
|
|
|
if( !pSettings )
|
|
return FALSE;
|
|
|
|
m_pSettings = pSettings;
|
|
m_nVideoFormat = VF_PAL;
|
|
m_pSettings->Load( _T("VIDEO_STANDART"), &m_nVideoFormat );
|
|
m_nVideoFPS = 0;
|
|
m_pSettings->Load( _T("VIDEO_FPS"), &m_nVideoFPS );
|
|
|
|
if( !pBaseWnd )
|
|
return FALSE;
|
|
|
|
for( int i = 0; i < m_DirectShowBase.GetDirectShowStreamCount(); i++ )
|
|
{
|
|
CDirectShowStreamVideo *pDirectShowStream = m_DirectShowBase.GetDirectShowStream( i );
|
|
|
|
/* switch( m_nVideoFormat )
|
|
{
|
|
case VF_PAL: pDirectShowStream->SetVideoStandart( AnalogVideo_PAL_B ); break;
|
|
case VF_NTSC: pDirectShowStream->SetVideoStandart( AnalogVideo_NTSC_M ); break;
|
|
}
|
|
*/
|
|
pDirectShowStream->SetVideoFPS( m_nVideoFPS );
|
|
|
|
for( int j = 0; j < pDirectShowStream->GetVideoSourceCount(); j++ )
|
|
{
|
|
CDDVideoWnd *pDDVideoWnd = new CDDVideoWnd( m_pSensorArray );
|
|
if( !pDDVideoWnd )
|
|
break;
|
|
|
|
if( !pDDVideoWnd->Create( pBaseWnd, -100, -100, 16, 12, NULL ) )
|
|
{
|
|
delete pDDVideoWnd;
|
|
break;
|
|
}
|
|
|
|
m_ArrayDDVideoWnd.Add( pDDVideoWnd );
|
|
}
|
|
}
|
|
|
|
return m_DirectShowBase.Start();
|
|
}
|
|
|
|
BOOL CVideoBase::InitVideoForWindows( CWnd* pBaseWnd, CSettings* )
|
|
{
|
|
/* CVideoForWindowsWnd *pVFW = new CVideoForWindowsWnd;
|
|
if( !pVFW )
|
|
return FALSE;
|
|
|
|
if( pVFW->Create( pBaseWnd, -100, -100, 16, 12 ) )
|
|
{
|
|
m_ArrayDDVideoWnd.Add( pVFW );
|
|
return TRUE;
|
|
}
|
|
|
|
delete pVFW;
|
|
*/
|
|
return FALSE;
|
|
}
|
|
|
|
BOOL CVideoBase::Create( CWnd *pBaseWnd, CSettings *pSettings )
|
|
{
|
|
// return TRUE;
|
|
|
|
Destroy();
|
|
|
|
BOOL bError = FALSE;
|
|
|
|
// if demo mode
|
|
if( m_pSensorArray->IsDemo() )
|
|
{
|
|
TCHAR pName[][MAX_PATH] =
|
|
{
|
|
"demo1.avi",
|
|
"demo2.avi",
|
|
};
|
|
|
|
for( INT i = 0; i < 2; i++ )
|
|
{
|
|
if( !m_DirectShowStreamMovie[i].Create( pName[i] ) )
|
|
continue;
|
|
|
|
CDDVideoWnd *pDDVideoWnd = new CDDVideoWnd( m_pSensorArray );
|
|
if( !pDDVideoWnd )
|
|
continue;
|
|
|
|
if( !pDDVideoWnd->Create( pBaseWnd, -100, -100, 16, 12, NULL ) )
|
|
{
|
|
delete pDDVideoWnd;
|
|
continue;
|
|
}
|
|
|
|
m_DirectShowStreamMovie[i].Link( pDDVideoWnd, 0 );
|
|
|
|
pDDVideoWnd->SetVideoBase( this );
|
|
|
|
m_ArrayDDVideoWnd.Add( pDDVideoWnd );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if( !InitDirectShow( pBaseWnd, pSettings ))
|
|
bError = TRUE;
|
|
}
|
|
|
|
if( !bError )
|
|
{
|
|
for( INT i = 0; i < m_pSensorArray->GetVideoCaptureDeviceCount(); i++ )
|
|
{
|
|
CVideoCaptureDevice *pDevice = m_pSensorArray->GetVideoCaptureDevice(i);
|
|
|
|
INT nVideoStandard = AnalogVideo_PAL_B;
|
|
switch( pDevice ? pDevice->GetVideoStandard() : 0 )
|
|
{
|
|
case 0: nVideoStandard = AnalogVideo_PAL_B; break;
|
|
case 1: nVideoStandard = AnalogVideo_NTSC_M; break;
|
|
}
|
|
|
|
for( INT j = 0; j < m_pSensorArray->GetVideoCaptureDevice(i)->GetInputCount(); j++ )
|
|
{
|
|
// if pin connected to any device
|
|
if( pDevice->GetInput(j)->GetCPin() )
|
|
{
|
|
CVideoCaptureWnd *pDDVideoWnd = AllocVideoWnd( pDevice->GetVideoDeviceID() ? (pDevice->GetVideoDeviceID() - 1) : 0, j, nVideoStandard );
|
|
if( !pDDVideoWnd )
|
|
{
|
|
bError = TRUE;
|
|
break;
|
|
}
|
|
|
|
pDevice->AssignCaptureSource( j, pDDVideoWnd );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return !bError;
|
|
}
|
|
|
|
void CVideoBase::Destroy()
|
|
{
|
|
if( m_pSettings )
|
|
{
|
|
m_pSettings->Save( _T("VIDEO_STANDART"), m_nVideoFormat );
|
|
m_pSettings->Save( _T("VIDEO_FPS"), m_nVideoFPS );
|
|
m_pSettings = NULL;
|
|
}
|
|
m_nVideoFormat = VF_NONE;
|
|
|
|
m_DirectShowBase.Destroy();
|
|
|
|
m_DirectShowStreamMovie[0].Destroy();
|
|
m_DirectShowStreamMovie[1].Destroy();
|
|
m_DirectShowStreamMovie[2].Destroy();
|
|
m_DirectShowStreamMovie[3].Destroy();
|
|
|
|
for( int i = 0; i < m_ArrayDDVideoWnd.GetCount(); i++ )
|
|
{
|
|
if( m_ArrayDDVideoWnd[i] )
|
|
{
|
|
m_ArrayDDVideoWnd[i]->DestroyWindow();
|
|
delete m_ArrayDDVideoWnd[i];
|
|
}
|
|
}
|
|
m_ArrayDDVideoWnd.RemoveAll();
|
|
|
|
m_nVideo = 0;
|
|
}
|
|
|
|
CVideoCaptureWnd *CVideoBase::AllocVideoWnd( INT nBoard, INT nInput, INT nVideoStandard )
|
|
{
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CVideoBase::AllocVideoWnd"), _T("Board %d, Input %d"), nBoard, nInput );
|
|
|
|
// if demonstration mode
|
|
if( m_pSensorArray->IsDemo() )
|
|
{
|
|
if( m_ArrayDDVideoWnd.GetCount() > m_nVideo )
|
|
{
|
|
m_ArrayDDVideoWnd[m_nVideo]->SetVideoBase( this );
|
|
return m_ArrayDDVideoWnd[ m_nVideo++ ];
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
// normal processing
|
|
for( INT i = 0; i < m_DirectShowBase.GetDirectShowStreamCount(); i++ )
|
|
{
|
|
CDirectShowStreamVideo *pDirectShowStream = m_DirectShowBase.GetDirectShowStream( i );
|
|
for( int j = 0; j < pDirectShowStream->GetVideoSourceCount(); j++ )
|
|
{
|
|
if( i == nBoard && j == nInput )
|
|
{
|
|
pDirectShowStream->Link( static_cast<CDirectShowVideo*>( static_cast<CDDVideoWnd*>( m_ArrayDDVideoWnd[m_nVideo] ) ), j );
|
|
|
|
pDirectShowStream->SetVideoStandart( nVideoStandard );
|
|
|
|
m_ArrayDDVideoWnd[m_nVideo]->SetVideoBase( this );
|
|
return m_ArrayDDVideoWnd[ m_nVideo++ ];
|
|
}
|
|
}
|
|
}
|
|
|
|
if( m_ArrayDDVideoWnd.GetCount() > m_nVideo )
|
|
{
|
|
m_ArrayDDVideoWnd[ m_nVideo ]->SetVideoBase( this );
|
|
return m_ArrayDDVideoWnd[ m_nVideo++ ];
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
void CVideoBase::SetControlledVideo( CVideoCaptureWnd *pNewWnd )
|
|
{
|
|
if( m_bCameraSwitchLock )
|
|
return;
|
|
|
|
if( !m_pVideoFrameWnd )
|
|
return;
|
|
if( !m_pVideoListWnd )
|
|
return;
|
|
if( !m_pCameraNavigateDlg )
|
|
return;
|
|
if( !pNewWnd )
|
|
return;
|
|
|
|
// compare with current window
|
|
CVideoCaptureWnd *pCurrentWnd = static_cast<CVideoCaptureWnd*>( m_pVideoFrameWnd->GetVideoWnd() );
|
|
if( pCurrentWnd == pNewWnd )
|
|
{
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CVideoBase::SetControlledVideo", "Video %p already is in main video wnd", pCurrentWnd );
|
|
|
|
// IMPORTENT!!!: notify camera control dlg about video switching
|
|
m_pCameraNavigateDlg->SetVideoSource( pNewWnd );
|
|
return;
|
|
}
|
|
|
|
// remove new window from "video list" wnd
|
|
if( !m_pVideoListWnd->Remove( pNewWnd ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_WARNING, this, "CVideoBase::SetControlledVideo", "Can't remove new video wnd from list" );
|
|
return;
|
|
}
|
|
|
|
// add old video window to "video list"
|
|
m_pVideoListWnd->Add( pCurrentWnd );
|
|
|
|
// assign new video for main video viewport
|
|
m_pVideoFrameWnd->SetVideoWnd( pNewWnd );
|
|
|
|
// notify camera control dlg about video switching
|
|
m_pCameraNavigateDlg->SetVideoSource( pNewWnd );
|
|
|
|
// log information
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CVideoBase::SetControlledVideo", "Set video wnd %p", pNewWnd );
|
|
}
|
|
|
|
// NOTE: should be rewitten !!!
|
|
void CVideoBase::Initialize()
|
|
{
|
|
// log info
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CVideoBase::Initialize", "Start..." );
|
|
|
|
ASSERT( m_pSensorArray );
|
|
|
|
for( int nCamera = 0; nCamera < m_pSensorArray->GetVideoCameraCount(); nCamera++ )
|
|
{
|
|
CVideoCamera *pVideoCamera = m_pSensorArray->GetVideoCamera( nCamera );
|
|
|
|
ASSERT( pVideoCamera );
|
|
|
|
for( int nVideoCaptureDevice = 0; nVideoCaptureDevice < m_pSensorArray->GetVideoCaptureDeviceCount(); nVideoCaptureDevice++ )
|
|
{
|
|
CVideoCaptureDevice *pVideoCaptureDevice = m_pSensorArray->GetVideoCaptureDevice( nVideoCaptureDevice );
|
|
if( !pVideoCaptureDevice )
|
|
continue;
|
|
|
|
int nVideoInputPin = pVideoCaptureDevice->GetAvailiblePin( pVideoCamera->GetOutput(0) );
|
|
if( nVideoInputPin < 0 )
|
|
continue;
|
|
|
|
CVideoCaptureSource *pVideoCaptureSource = pVideoCaptureDevice->GetCaptureSource( nVideoInputPin );
|
|
if( !pVideoCaptureSource )
|
|
continue;
|
|
|
|
for( int nSensor = 0; nSensor < m_pSensorArray->GetSensorCount(); nSensor++ )
|
|
{
|
|
CSensor *pSensor = m_pSensorArray->GetSensor( nSensor );
|
|
if( !pSensor )
|
|
continue;
|
|
|
|
// update maximum image count
|
|
if( pVideoCamera == pSensor->GetVideoCamera() )
|
|
pVideoCaptureSource->UpdateMaxPreviewImageCount( pSensor->GetImageCount() );
|
|
}
|
|
}
|
|
}
|
|
|
|
for( INT i = 0; i < m_pSensorArray->GetVideoCaptureDeviceCount(); i++ )
|
|
{
|
|
CVideoCaptureDevice *pVideoCaptureDevice = m_pSensorArray->GetVideoCaptureDevice( i );
|
|
|
|
ASSERT( pVideoCaptureDevice );
|
|
|
|
for( int nInputPin = 0; nInputPin < m_ArrayDDVideoWnd.GetCount(); nInputPin++ )
|
|
{
|
|
for( int nCamera = 0; nCamera < m_pSensorArray->GetVideoCameraCount(); nCamera++ )
|
|
{
|
|
CVideoCamera *pVideoCamera = m_pSensorArray->GetVideoCamera( nCamera );
|
|
|
|
ASSERT( pVideoCamera );
|
|
|
|
if( !pVideoCamera->IsLock() )
|
|
{
|
|
int nWeight = pVideoCaptureDevice->GetInput( nInputPin )->TestConnection( pVideoCamera->GetOutput(0) );
|
|
if( nWeight < INT_MAX )
|
|
{
|
|
pVideoCamera->Lock();
|
|
pVideoCamera->Connect( pVideoCaptureDevice->GetInput( nInputPin ) );
|
|
pVideoCamera->AssignCaptureSource( pVideoCaptureDevice->GetCaptureSource( nInputPin ) );
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for( nCamera = 0; nCamera < m_pSensorArray->GetVideoCameraCount(); nCamera++ )
|
|
{
|
|
CVideoCamera *pVideoCamera = m_pSensorArray->GetVideoCamera( nCamera );
|
|
|
|
ASSERT( pVideoCamera );
|
|
|
|
if( pVideoCamera->IsLock() )
|
|
pVideoCamera->Unlock();
|
|
}
|
|
|
|
// log info
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CVideoBase::Initialize", "Done." );
|
|
}
|
|
|
|
void CVideoBase::UpdateInfo(BOOL bOddUpdate)
|
|
{
|
|
|
|
}
|
|
|
|
BOOL CVideoBase::SetVideoFPS( INT nFPS )
|
|
{
|
|
if( m_nVideoFPS == nFPS )
|
|
return TRUE;
|
|
|
|
m_nVideoFPS = nFPS;
|
|
|
|
for( int i = 0; i < m_DirectShowBase.GetDirectShowStreamCount(); i++ )
|
|
{
|
|
CDirectShowStreamVideo *pDirectShowStream = m_DirectShowBase.GetDirectShowStream( i );
|
|
pDirectShowStream->SetVideoFPS( m_nVideoFPS );
|
|
}
|
|
|
|
if( m_pSettings )
|
|
m_pSettings->Save( _T("VIDEO_FPS"), m_nVideoFPS );
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CVideoBase::SetVideoFormat( INT nFormat )
|
|
{
|
|
if( m_nVideoFormat == nFormat )
|
|
return TRUE;
|
|
|
|
m_nVideoFormat = nFormat;
|
|
|
|
for( int i = 0; i < m_DirectShowBase.GetDirectShowStreamCount(); i++ )
|
|
{
|
|
CDirectShowStreamVideo *pDirectShowStream = m_DirectShowBase.GetDirectShowStream( i );
|
|
switch( m_nVideoFormat )
|
|
{
|
|
case VF_PAL: pDirectShowStream->SetVideoStandart( AnalogVideo_PAL_B ); break;
|
|
case VF_NTSC: pDirectShowStream->SetVideoStandart( AnalogVideo_NTSC_M ); break;
|
|
}
|
|
}
|
|
|
|
// restart video engine
|
|
m_DirectShowBase.Stop();
|
|
m_DirectShowBase.Start();
|
|
|
|
if( m_pSettings )
|
|
m_pSettings->Save( _T("VIDEO_STANDART"), m_nVideoFormat );
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
void CVideoBase::UpdateDemo( CVideoCaptureWnd* pVideoWnd, double SampleTime )
|
|
{
|
|
if( m_pSensorArray->IsDemo() )
|
|
{
|
|
for( INT i = 0; i < m_ArrayDDVideoWnd.GetCount(); i++ )
|
|
{
|
|
if( m_ArrayDDVideoWnd[i] == pVideoWnd )
|
|
{
|
|
m_pSensorArray->UpdateDemo( i, SampleTime );
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void CVideoBase::OnChangeSettings()
|
|
{
|
|
for( INT i = 0; i < m_ArrayDDVideoWnd.GetCount(); i++ )
|
|
static_cast<CDDVideoWnd*>(m_ArrayDDVideoWnd[i])->OnChangeSettings() ;
|
|
}
|