protected ArrayList findCrossbarSources(ICaptureGraphBuilder2 graphBuilder, IAMCrossbar crossbar, bool isVideoDevice)
{
ArrayList sources = new ArrayList();
int hr;
int numOutPins;
int numInPins;
hr = crossbar.get_PinCounts( out numOutPins, out numInPins );
if ( hr < 0 )
Marshal.ThrowExceptionForHR( hr );
// We loop through every combination of output and input pin
// to see which combinations match.
// Loop through output pins
for ( int cOut = 0; cOut < numOutPins; cOut++ )
{
// Loop through input pins
for ( int cIn = 0; cIn < numInPins; cIn++ )
{
// Can this combination be routed?
hr = crossbar.CanRoute( cOut, cIn );
if ( hr == 0 )
{
// Yes, this can be routed
int relatedInputPin;
PhysicalConnectorType connectorType;
hr = crossbar.get_CrossbarPinInfo( true, cIn, out relatedInputPin, out connectorType );
if ( hr < 0 )
Marshal.ThrowExceptionForHR( hr );
// Add it to the list
CrossbarSource source = new CrossbarSource( crossbar, cOut, cIn, relatedInputPin, connectorType );
sources.Add( source );
}
}
}
// Some silly drivers (*cough* Nvidia *cough*) add crossbars
// with no real choices. Every input can only be routed to
// one output. Loop through every Source and see if there
// at least one other Source with the same output pin.
int refIndex = 0;
while ( refIndex < sources.Count )
{
bool found = false;
CrossbarSource refSource = (CrossbarSource) sources[refIndex];
for ( int c = 0; c < sources.Count; c++ )
{
CrossbarSource s = (CrossbarSource) sources[c];
if ( ( refSource.OutputPin == s.OutputPin ) && ( refIndex != c ) )
{
found = true;
break;
}
}
if ( found )
refIndex++;
else
sources.RemoveAt( refIndex );
}
// Some of the video input pins have related audio pins
// that should be connected at the same time. We noted the pin number
// in the CrossbarSource.RelatedInputPin. Now that we have all
// the sources, lookup the CrossbarSource object associated with
// that pin
foreach ( CrossbarSource source in sources )
{
if ( source.RelatedInputPin != -1 )
{
foreach( CrossbarSource related in sources )
{
if ( source.RelatedInputPin == related.InputPin )
source.RelatedInputSource = related;
}
}
}
// Remove any sources that are not of the correct type
for (int c=0; c<sources.Count; c++)
{
if ( ((CrossbarSource)sources[c]).ConnectorType < PhysicalConnectorType.Audio_Tuner )
{
if ( !isVideoDevice )
{
sources.RemoveAt( c );
c--;
}
}
else
{
if ( isVideoDevice )
{
sources.RemoveAt( c );
c--;
}
}
}
return( sources );
}