Old fashion design for PC-104
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.
 
 
 
 
 

336 lines
5.6 KiB

//----------------------------------------------------------------------------
// Laser Guard Ltd.
// Copyright © 2000-2002. All Rights Reserved.
// Version 1.0 01/01/2000
// Last modification: 08/10/2003
// PROJECT:
// SUBSYSTEM:
// FILE: VideoPin.cpp
// AUTHOR: Sergey Chizhevskiy
// OVERVIEW
// ~~~~~~~~
// Source file of VideoPin.cpp
//----------------------------------------------------------------------------
// VideoPin.cpp: implementation of the CVideoPin class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
//#include "chicago.h"
#include "VideoPin.h"
#include "VideoDevice.h"
#include "..\..\LgLib\Version.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CVideoPin::CVideoPin()
{
m_nPinDir = PD_OUTPUT;
m_pCPin = NULL;
m_pAPin = NULL;
m_bLock = FALSE;
m_nCost = INT_MAX;
m_pVideoDevice = NULL;
m_nIndex = -1;
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CVideoPin::CVideoPin") );
}
CVideoPin::~CVideoPin()
{
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CVideoPin::~CVideoPin") );
}
BOOL CVideoPin::Connect( CVideoPin *pPin )
{
ASSERT( m_pCPin == NULL );
ASSERT( pPin->m_pCPin == NULL );
if( pPin->m_nPinDir == m_nPinDir )
return FALSE; // wrong direction
pPin->m_pCPin = this;
m_pCPin = pPin;
return TRUE;
}
BOOL CVideoPin::Associate( CVideoPin *pPin )
{
// check for close association
if( pPin == NULL )
{
if( m_pAPin )
{
m_pAPin->m_pAPin = NULL;
m_pAPin = NULL;
}
}
else
{
ASSERT( pPin->m_nPinDir != m_nPinDir );
if( m_pAPin || pPin->m_pAPin )
return FALSE; // association impossible
pPin->m_pAPin = this;
m_pAPin = pPin;
}
return TRUE;
}
void CVideoPin::GraphClear()
{
SetCost( INT_MAX );
int i;
CVideoPin *pPin;
switch( m_nPinDir )
{
case PD_INPUT:
pPin = GetCPin();
if( pPin )
{
pPin->GraphClear();
}
break;
case PD_OUTPUT:
for( i = 0; i < m_pVideoDevice->GetInputCount(); i++ )
{
pPin = m_pVideoDevice->GetInput(i);
if( pPin )
{
pPin->GraphClear();
}
}
break;
}
}
BOOL CVideoPin::GraphSearch( CVideoPin* pEPin, int nCost )
{
if( pEPin == this )
return TRUE;
SetCost( nCost );
int i, nWays = 0;
CVideoPin *pPin;
switch( m_nPinDir )
{
case PD_INPUT:
for( i = 0; i < m_pVideoDevice->GetOutputCount(); i++ )
{
pPin = m_pVideoDevice->GetOutput(i);
if( !pPin->IsLocked() )
{
if( pPin->GraphSearch( pEPin, nCost + 1 ) )
{
nWays++;
}
}
}
break;
case PD_OUTPUT:
pPin = GetCPin();
if( pPin )
{
if( pPin->GraphSearch( pEPin, nCost ) )
{
nWays++;
}
}
break;
}
return nWays > 0;
}
void CVideoPin::GraphLock()
{
int i;
int nCost;
CVideoPin *pMPin, *pPin;
Lock(); // lock itself
switch( m_nPinDir )
{
case PD_INPUT:
pPin = GetCPin();
if( pPin )
{
pPin->GraphLock();
}
break;
case PD_OUTPUT:
nCost = INT_MAX;
pMPin = NULL;
for( i = 0; i < m_pVideoDevice->GetInputCount(); i++ )
{
pPin = m_pVideoDevice->GetInput(i);
if( !pPin->IsLocked() )
{
if( nCost > pPin->GetCost() )
{
nCost = pPin->GetCost();
pMPin = pPin;
}
}
}
if( pMPin )
{
Associate( pMPin ); // building line by association
pMPin->GraphLock();
}
break;
}
}
BOOL CVideoPin::WayLock( CVideoPin *pEPin )
{
if( m_bLock )
return TRUE; // already locked
if( pEPin )
pEPin->GraphClear(); // from input to output
else
return FALSE; // error in setup
if( GraphSearch( pEPin, 0 ) ) // from output to input
{
pEPin->GraphLock(); // from input to output
return TRUE;
}
return FALSE;
}
BOOL CVideoPin::WayCheck()
{
CVideoPin *pPin;
if( !m_bLock )
return FALSE; // no way locked
switch( m_nPinDir )
{
case PD_INPUT:
pPin = GetAPin();
if( pPin )
{
int nInput = GetIndex();
int nOutput = pPin->GetIndex();
if( m_pVideoDevice->ForceConnection( nInput, nOutput ) )
return pPin->WayCheck();
}
else
{
return TRUE;
}
break;
case PD_OUTPUT:
pPin = GetCPin();
if( pPin )
{
return pPin->WayCheck();
}
break;
}
return FALSE;
}
void CVideoPin::WayUnlock()
{
Unlock();
CVideoPin *pPin;
switch( m_nPinDir )
{
case PD_INPUT:
pPin = GetAPin();
if( pPin )
{
Associate( NULL ); // delete association
pPin->WayUnlock();
}
break;
case PD_OUTPUT:
pPin = GetCPin();
if( pPin )
{
pPin->WayUnlock();
}
break;
}
}
// should be replaced, because can loops forever
int CVideoPin::TestConnection( CVideoPin *pOutputPin )
{
if( !pOutputPin )
return INT_MAX;
CVideoPin *pInputPin = pOutputPin->GetCPin();
if( !pInputPin )
return INT_MAX;
if( pInputPin == this )
return 0;
CVideoDevice *pVideoDevice = pInputPin->m_pVideoDevice;
if( !pVideoDevice )
return INT_MAX;
int nWeightMin = INT_MAX;
for( int i = 0; i < pVideoDevice->GetOutputCount(); i++ )
{
pOutputPin = pVideoDevice->GetOutput(i);
if( !pOutputPin )
continue;
int nWeight = TestConnection( pOutputPin );
if( nWeightMin > nWeight )
{
nWeightMin = nWeight;
}
}
return ( nWeightMin != INT_MAX ) ? nWeightMin + 1 : nWeightMin;
}