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.
228 lines
6.5 KiB
228 lines
6.5 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: LgHWVideoSwitch.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of LgHWVideoSwitchDevice.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "LgHWVideoCamera.h"
|
|
#include "LgHWVideoEngine.h"
|
|
#include "LgHWVideoCapture.h"
|
|
#include "LgHWVideoPin.h"
|
|
#include "LgHWVideoSwitch.h"
|
|
#include "LgHWVideoJob.h"
|
|
|
|
|
|
CLgHWVideoSwitch::CLgHWVideoSwitch()
|
|
{
|
|
// initialize request counter
|
|
m_nRequestCount = 0;
|
|
}
|
|
|
|
CLgHWVideoSwitch::~CLgHWVideoSwitch()
|
|
{
|
|
Destroy();
|
|
}
|
|
|
|
BOOL CLgHWVideoSwitch::Create( INT nInput, INT nOutput )
|
|
{
|
|
// initialize inputs
|
|
for( INT i = 0; i < nInput; i++ )
|
|
{
|
|
CLgHWVideoPin *pInput = new CLgHWVideoPin;
|
|
if( !pInput )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitch::Create"), _T("new CLgHWVideoPin for input failed") );
|
|
return FALSE;
|
|
}
|
|
|
|
// set pin index
|
|
pInput->SetIndex( i );
|
|
|
|
// link input to itself
|
|
if( !SwitchToInputLinkP::Link( pInput ) )
|
|
{
|
|
delete pInput;
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitch::Create"), _T("Link( pInput ) failed") );
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
// initialize outputs
|
|
for( i = 0; i < nOutput; i++ )
|
|
{
|
|
CLgHWVideoPin *pOutput = new CLgHWVideoPin;
|
|
if( !pOutput )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitch::Create"), _T("new CLgHWVideoPin for output failed") );
|
|
return FALSE;
|
|
}
|
|
|
|
// set pin index
|
|
pOutput->SetIndex( i );
|
|
|
|
// link output to itself
|
|
if( !SwitchToOutputLinkP::Link( pOutput ) )
|
|
{
|
|
delete pOutput;
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitch::Create"), _T("Link( pOutput ) failed") );
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CLgHWVideoSwitch::Destroy()
|
|
{
|
|
// delete all pins
|
|
CLgLocker LockInput( &SwitchToInputLinkP::GetLock() );
|
|
while( SwitchToInputLinkP::GetCount() )
|
|
delete *SwitchToInputLinkP::GetAt(0);
|
|
|
|
CLgLocker LockOutput( &SwitchToOutputLinkP::GetLock() );
|
|
while( SwitchToOutputLinkP::GetCount() )
|
|
delete *SwitchToOutputLinkP::GetAt(0);
|
|
|
|
SwitchToJobLinkP::Unlink();
|
|
}
|
|
|
|
BOOL CLgHWVideoSwitch::Link( CLgLink<CLgHWVideoJob,CLgHWVideoSwitch> *pJob )
|
|
{
|
|
if( !SwitchToJobLinkP::Link( pJob ) )
|
|
return FALSE;
|
|
|
|
return CheckJobArray();
|
|
}
|
|
|
|
// notification about switching
|
|
void CLgHWVideoSwitch::OnHWVideoSwitchDeviceSwitch( INT nInput, INT nOutput )
|
|
{
|
|
// protect from simultaneus access
|
|
CLgLocker LockOutput( &SwitchToOutputLinkP::GetLock() );
|
|
CLgLocker LockInput( &SwitchToInputLinkP::GetLock() );
|
|
|
|
CLgArray< CLgLink<CLgHWVideoPin,CLgHWVideoSwitch,CLgHWVideoPinOutput>* >& arrOutput = *this;
|
|
CLgArray< CLgLink<CLgHWVideoPin,CLgHWVideoSwitch,CLgHWVideoPinInput>* >& arrInput = *this;
|
|
|
|
// validate input and output
|
|
if( nInput < 0 || nInput >= arrInput.GetCount() || nOutput < 0 || nOutput >= arrOutput.GetCount() )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitch::OnHWVideoSwitchDeviceSwitch"), _T("Parameters are incorrect (%d,%d)"), nInput, nOutput );
|
|
return;
|
|
}
|
|
|
|
// perform internal interconnection
|
|
CLgHWVideoPin *pInputPin = *arrInput[nInput];
|
|
CLgHWVideoPin *pOutputPin = *arrOutput[nOutput];
|
|
|
|
// unlink previous associations
|
|
pInputPin->PinToInsideLinkSP::Unlink();
|
|
pOutputPin->PinToInsideLinkSP::Unlink();
|
|
|
|
// establish new association
|
|
if( !pInputPin->PinToInsideLinkSP::Link( pOutputPin ) )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitch::OnHWVideoSwitchDeviceSwitch"), _T("Link failed") );
|
|
return;
|
|
}
|
|
|
|
// protect from simultaneus access ???
|
|
CLgLocker LockJobOutput( &pInputPin->PinToJobOutputLinkSP::GetLock() );
|
|
CLgLocker LockJobInput( &pInputPin->PinToJobInputLinkSP::GetLock() );
|
|
|
|
CLgHWVideoJob *pJobInput = pInputPin->PinToJobInputLinkSP::GetLinkThis();
|
|
CLgHWVideoJob *pJobOutput = pOutputPin->PinToJobOutputLinkSP::GetLinkThis();
|
|
if( pJobInput != pJobOutput )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitch::OnHWVideoSwitchDeviceSwitch"), _T("Job input is not equal job output") );
|
|
return;
|
|
}
|
|
|
|
// delete job due its performation
|
|
delete pJobInput;
|
|
/*
|
|
CLgArray< CLgLink<CLgHWVideoJob,CLgHWVideoSwitch>* >& arrJob = *this;
|
|
// update jobs array
|
|
for( INT i = 0; i < arrJob.GetCount(); i++ )
|
|
{
|
|
CLgHWVideoJob *pJob = *arrJob[i];
|
|
if( !pJob )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitch::OnHWVideoSwitchDeviceSwitch"), _T("Job is NULL") );
|
|
return;
|
|
}
|
|
|
|
CLgHWVideoPin *pInput = *pJob;
|
|
CLgHWVideoPin *pOutput = *pJob;
|
|
|
|
if( !pInput || !pOutput )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitch::OnHWVideoSwitchDeviceSwitch"), _T("Job has wrong input or output associations (%p,%p)"), pInput, pOutput );
|
|
return;
|
|
}
|
|
|
|
// if job had been done
|
|
if( pInput->GetIndex() == nInput && pOutput->GetIndex() == nOutput )
|
|
{
|
|
delete pJob;
|
|
break;
|
|
}
|
|
}
|
|
*/
|
|
// decrease number of issued requests
|
|
m_nRequestCount--;
|
|
|
|
// start next job
|
|
CheckJobArray();
|
|
}
|
|
|
|
BOOL CLgHWVideoSwitch::CheckJobArray()
|
|
{
|
|
// protect from simultaneus access
|
|
CLgLocker LockJob( &SwitchToJobLinkP::GetLock() );
|
|
|
|
CLgArray< CLgLink<CLgHWVideoJob,CLgHWVideoSwitch>* >& arrJob = *this;
|
|
|
|
// if all jobs had been done or there is outstanding request
|
|
if( m_nRequestCount || !arrJob.GetCount() )
|
|
return TRUE;
|
|
|
|
// get next job
|
|
CLgHWVideoJob *pJob = *arrJob[0];
|
|
if( !pJob )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitch::CheckJobArray"), _T("Job is NULL") );
|
|
return FALSE;
|
|
}
|
|
|
|
// protect from simultaneus access
|
|
CLgLocker LockJobOutput( &pJob->JobToOutputLinkSP::GetLock() );
|
|
CLgLocker LockJobInput( &pJob->JobToInputLinkSP::GetLock() );
|
|
|
|
// get job pins
|
|
CLgHWVideoPin *pInput = pJob->JobToInputLinkSP::GetLinkThis();
|
|
CLgHWVideoPin *pOutput = pJob->JobToOutputLinkSP::GetLinkThis();
|
|
if( !pInput || !pOutput )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgHWVideoSwitch::CheckJobArray"), _T("Job has wrong input or output associations (%p,%p)"), pInput, pOutput );
|
|
return FALSE;
|
|
}
|
|
|
|
// start next job
|
|
if( !HWVideoSwitchDeviceSwitch( pInput->GetIndex(), pOutput->GetIndex() ) )
|
|
return FALSE;
|
|
|
|
// increase number of issued requests
|
|
m_nRequestCount++;
|
|
|
|
return TRUE;
|
|
}
|
|
|