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

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: VideoPin.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of VideoPin.cpp
  13. //----------------------------------------------------------------------------
  14. // VideoPin.cpp: implementation of the CVideoPin class.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. //#include "chicago.h"
  19. #include "VideoPin.h"
  20. #include "VideoDevice.h"
  21. #include "..\..\LgLib\Version.h"
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char THIS_FILE[]=__FILE__;
  25. #define new DEBUG_NEW
  26. #endif
  27. //////////////////////////////////////////////////////////////////////
  28. // Construction/Destruction
  29. //////////////////////////////////////////////////////////////////////
  30. CVideoPin::CVideoPin()
  31. {
  32. m_nPinDir = PD_OUTPUT;
  33. m_pCPin = NULL;
  34. m_pAPin = NULL;
  35. m_bLock = FALSE;
  36. m_nCost = INT_MAX;
  37. m_pVideoDevice = NULL;
  38. m_nIndex = -1;
  39. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CVideoPin::CVideoPin") );
  40. }
  41. CVideoPin::~CVideoPin()
  42. {
  43. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CVideoPin::~CVideoPin") );
  44. }
  45. BOOL CVideoPin::Connect( CVideoPin *pPin )
  46. {
  47. ASSERT( m_pCPin == NULL );
  48. ASSERT( pPin->m_pCPin == NULL );
  49. if( pPin->m_nPinDir == m_nPinDir )
  50. return FALSE; // wrong direction
  51. pPin->m_pCPin = this;
  52. m_pCPin = pPin;
  53. return TRUE;
  54. }
  55. BOOL CVideoPin::Associate( CVideoPin *pPin )
  56. {
  57. // check for close association
  58. if( pPin == NULL )
  59. {
  60. if( m_pAPin )
  61. {
  62. m_pAPin->m_pAPin = NULL;
  63. m_pAPin = NULL;
  64. }
  65. }
  66. else
  67. {
  68. ASSERT( pPin->m_nPinDir != m_nPinDir );
  69. if( m_pAPin || pPin->m_pAPin )
  70. return FALSE; // association impossible
  71. pPin->m_pAPin = this;
  72. m_pAPin = pPin;
  73. }
  74. return TRUE;
  75. }
  76. void CVideoPin::GraphClear()
  77. {
  78. SetCost( INT_MAX );
  79. int i;
  80. CVideoPin *pPin;
  81. switch( m_nPinDir )
  82. {
  83. case PD_INPUT:
  84. pPin = GetCPin();
  85. if( pPin )
  86. {
  87. pPin->GraphClear();
  88. }
  89. break;
  90. case PD_OUTPUT:
  91. for( i = 0; i < m_pVideoDevice->GetInputCount(); i++ )
  92. {
  93. pPin = m_pVideoDevice->GetInput(i);
  94. if( pPin )
  95. {
  96. pPin->GraphClear();
  97. }
  98. }
  99. break;
  100. }
  101. }
  102. BOOL CVideoPin::GraphSearch( CVideoPin* pEPin, int nCost )
  103. {
  104. if( pEPin == this )
  105. return TRUE;
  106. SetCost( nCost );
  107. int i, nWays = 0;
  108. CVideoPin *pPin;
  109. switch( m_nPinDir )
  110. {
  111. case PD_INPUT:
  112. for( i = 0; i < m_pVideoDevice->GetOutputCount(); i++ )
  113. {
  114. pPin = m_pVideoDevice->GetOutput(i);
  115. if( !pPin->IsLocked() )
  116. {
  117. if( pPin->GraphSearch( pEPin, nCost + 1 ) )
  118. {
  119. nWays++;
  120. }
  121. }
  122. }
  123. break;
  124. case PD_OUTPUT:
  125. pPin = GetCPin();
  126. if( pPin )
  127. {
  128. if( pPin->GraphSearch( pEPin, nCost ) )
  129. {
  130. nWays++;
  131. }
  132. }
  133. break;
  134. }
  135. return nWays > 0;
  136. }
  137. void CVideoPin::GraphLock()
  138. {
  139. int i;
  140. int nCost;
  141. CVideoPin *pMPin, *pPin;
  142. Lock(); // lock itself
  143. switch( m_nPinDir )
  144. {
  145. case PD_INPUT:
  146. pPin = GetCPin();
  147. if( pPin )
  148. {
  149. pPin->GraphLock();
  150. }
  151. break;
  152. case PD_OUTPUT:
  153. nCost = INT_MAX;
  154. pMPin = NULL;
  155. for( i = 0; i < m_pVideoDevice->GetInputCount(); i++ )
  156. {
  157. pPin = m_pVideoDevice->GetInput(i);
  158. if( !pPin->IsLocked() )
  159. {
  160. if( nCost > pPin->GetCost() )
  161. {
  162. nCost = pPin->GetCost();
  163. pMPin = pPin;
  164. }
  165. }
  166. }
  167. if( pMPin )
  168. {
  169. Associate( pMPin ); // building line by association
  170. pMPin->GraphLock();
  171. }
  172. break;
  173. }
  174. }
  175. BOOL CVideoPin::WayLock( CVideoPin *pEPin )
  176. {
  177. if( m_bLock )
  178. return TRUE; // already locked
  179. if( pEPin )
  180. pEPin->GraphClear(); // from input to output
  181. else
  182. return FALSE; // error in setup
  183. if( GraphSearch( pEPin, 0 ) ) // from output to input
  184. {
  185. pEPin->GraphLock(); // from input to output
  186. return TRUE;
  187. }
  188. return FALSE;
  189. }
  190. BOOL CVideoPin::WayCheck()
  191. {
  192. CVideoPin *pPin;
  193. if( !m_bLock )
  194. return FALSE; // no way locked
  195. switch( m_nPinDir )
  196. {
  197. case PD_INPUT:
  198. pPin = GetAPin();
  199. if( pPin )
  200. {
  201. int nInput = GetIndex();
  202. int nOutput = pPin->GetIndex();
  203. if( m_pVideoDevice->ForceConnection( nInput, nOutput ) )
  204. return pPin->WayCheck();
  205. }
  206. else
  207. {
  208. return TRUE;
  209. }
  210. break;
  211. case PD_OUTPUT:
  212. pPin = GetCPin();
  213. if( pPin )
  214. {
  215. return pPin->WayCheck();
  216. }
  217. break;
  218. }
  219. return FALSE;
  220. }
  221. void CVideoPin::WayUnlock()
  222. {
  223. Unlock();
  224. CVideoPin *pPin;
  225. switch( m_nPinDir )
  226. {
  227. case PD_INPUT:
  228. pPin = GetAPin();
  229. if( pPin )
  230. {
  231. Associate( NULL ); // delete association
  232. pPin->WayUnlock();
  233. }
  234. break;
  235. case PD_OUTPUT:
  236. pPin = GetCPin();
  237. if( pPin )
  238. {
  239. pPin->WayUnlock();
  240. }
  241. break;
  242. }
  243. }
  244. // should be replaced, because can loops forever
  245. int CVideoPin::TestConnection( CVideoPin *pOutputPin )
  246. {
  247. if( !pOutputPin )
  248. return INT_MAX;
  249. CVideoPin *pInputPin = pOutputPin->GetCPin();
  250. if( !pInputPin )
  251. return INT_MAX;
  252. if( pInputPin == this )
  253. return 0;
  254. CVideoDevice *pVideoDevice = pInputPin->m_pVideoDevice;
  255. if( !pVideoDevice )
  256. return INT_MAX;
  257. int nWeightMin = INT_MAX;
  258. for( int i = 0; i < pVideoDevice->GetOutputCount(); i++ )
  259. {
  260. pOutputPin = pVideoDevice->GetOutput(i);
  261. if( !pOutputPin )
  262. continue;
  263. int nWeight = TestConnection( pOutputPin );
  264. if( nWeightMin > nWeight )
  265. {
  266. nWeightMin = nWeight;
  267. }
  268. }
  269. return ( nWeightMin != INT_MAX ) ? nWeightMin + 1 : nWeightMin;
  270. }