// -------------------- IDisposable ----------------------- /// <summary> Release unmanaged resources. </summary> public override void Dispose() { if (Crossbar != null) { Marshal.ReleaseComObject(Crossbar); } Crossbar = null; RelatedInputSource = null; base.Dispose(); }
/// <summary> /// Populate the internal InnerList with sources/physical connectors /// found on the crossbars. Each instance of this class is limited /// to video only or audio only sources ( specified by the isVideoDevice /// parameter on the constructor) so we check each source before adding /// it to the list. /// </summary> 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 relatedPin; PhysicalConnectorType connectorType; hr = crossbar.get_CrossbarPinInfo( true, cIn, out relatedPin, out connectorType ); if ( hr < 0 ) Marshal.ThrowExceptionForHR( hr ); // Is this the correct type?, If so add to the InnerList CrossbarSource source = new CrossbarSource( crossbar, cOut, cIn, connectorType ); if ( connectorType < PhysicalConnectorType.Audio_Tuner ) if ( isVideoDevice ) sources.Add( source ); else if ( !isVideoDevice ) 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 ); } return( sources ); }
/// <summary> /// Populate the internal InnerList with sources/physical connectors /// found on the crossbars. Each instance of this class is limited /// to video only or audio only sources ( specified by the isVideoDevice /// parameter on the constructor) so we check each source before adding /// it to the list. /// </summary> 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 relatedPin; PhysicalConnectorType connectorType; hr = crossbar.get_CrossbarPinInfo(true, cIn, out relatedPin, out connectorType); if (hr < 0) { Marshal.ThrowExceptionForHR(hr); } // Is this the correct type?, If so add to the InnerList CrossbarSource source = new CrossbarSource(crossbar, cOut, cIn, connectorType); if (connectorType < PhysicalConnectorType.Audio_Tuner) { if (isVideoDevice) { sources.Add(source); } else if (!isVideoDevice) { 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); } } return(sources); }
// ------------------ Public Methods -------------------- /// <summary> Populate the collection by looking for commonly implemented property pages. </summary> protected void addFromGraph( ICaptureGraphBuilder2 graphBuilder, IBaseFilter videoDeviceFilter, IBaseFilter audioDeviceFilter, IBaseFilter videoCompressorFilter, IBaseFilter audioCompressorFilter, SourceCollection videoSources, SourceCollection audioSources) { object filter = null; DsGuid cat; DsGuid med; Guid iid; int hr; Trace.Assert(graphBuilder != null); // 1. the video capture filter addIfSupported(videoDeviceFilter, "Video Capture Device"); // 2. the video capture pin cat = new DsGuid(PinCategory.Capture); med = new DsGuid(MediaType.Interleaved); iid = typeof(IAMStreamConfig).GUID; hr = graphBuilder.FindInterface( cat, med, videoDeviceFilter, iid, out filter); if (hr != 0) { med = MediaType.Video; hr = graphBuilder.FindInterface( cat, med, videoDeviceFilter, iid, out filter); if (hr != 0) { filter = null; } } addIfSupported(filter, "Video Capture Pin"); // 3. the video preview pin cat = PinCategory.Preview; med = MediaType.Interleaved; iid = typeof(IAMStreamConfig).GUID; hr = graphBuilder.FindInterface( cat, med, videoDeviceFilter, iid, out filter); if (hr != 0) { med = MediaType.Video; hr = graphBuilder.FindInterface( cat, med, videoDeviceFilter, iid, out filter); if (hr != 0) { filter = null; } } addIfSupported(filter, "Video Preview Pin"); // 4. the video crossbar(s) ArrayList crossbars = new ArrayList(); int num = 1; for (int c = 0; c < videoSources.Count; c++) { CrossbarSource s = videoSources[c] as CrossbarSource; if (s != null) { if (crossbars.IndexOf(s.Crossbar) < 0) { crossbars.Add(s.Crossbar); if (addIfSupported(s.Crossbar, "Video Crossbar " + (num == 1 ? "" : num.ToString()))) { num++; } } } } crossbars.Clear(); // 5. the video compressor addIfSupported(videoCompressorFilter, "Video Compressor"); // 6. the video TV tuner cat = new DsGuid(PinCategory.Capture); med = new DsGuid(MediaType.Interleaved); iid = typeof(IAMTVTuner).GUID; hr = graphBuilder.FindInterface( cat, med, videoDeviceFilter, iid, out filter); if (hr != 0) { med = MediaType.Video; hr = graphBuilder.FindInterface( cat, med, videoDeviceFilter, iid, out filter); if (hr != 0) { filter = null; } } addIfSupported(filter, "TV Tuner"); // 7. the video compressor (VFW) IAMVfwCompressDialogs compressDialog = videoCompressorFilter as IAMVfwCompressDialogs; if (compressDialog != null) { VfwCompressorPropertyPage page = new VfwCompressorPropertyPage("Video Compressor", compressDialog); InnerList.Add(page); } // 8. the audio capture filter addIfSupported(audioDeviceFilter, "Audio Capture Device"); // 9. the audio capture pin cat = new DsGuid(PinCategory.Capture); med = new DsGuid(MediaType.Audio); iid = typeof(IAMStreamConfig).GUID; hr = graphBuilder.FindInterface( cat, med, audioDeviceFilter, iid, out filter); if (hr != 0) { filter = null; } addIfSupported(filter, "Audio Capture Pin"); // 9. the audio preview pin cat = new DsGuid(PinCategory.Preview); med = new DsGuid(MediaType.Audio); iid = typeof(IAMStreamConfig).GUID; hr = graphBuilder.FindInterface( cat, med, audioDeviceFilter, iid, out filter); if (hr != 0) { filter = null; } addIfSupported(filter, "Audio Preview Pin"); // 10. the audio crossbar(s) num = 1; for (int c = 0; c < audioSources.Count; c++) { CrossbarSource s = audioSources[c] as CrossbarSource; if (s != null) { if (crossbars.IndexOf(s.Crossbar) < 0) { crossbars.Add(s.Crossbar); if (addIfSupported(s.Crossbar, "Audio Crossbar " + (num == 1 ? "" : num.ToString()))) { num++; } } } } crossbars.Clear(); // 11. the audio compressor addIfSupported(audioCompressorFilter, "Audio Compressor"); }
/// <summary> /// Populate the internal InnerList with sources/physical connectors /// found on the crossbars. Each instance of this class is limited /// to video only or audio only sources ( specified by the isVideoDevice /// parameter on the constructor) so we check each source before adding /// it to the list. /// </summary> 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 ); }
/// <summary> /// Populate the internal InnerList with sources/physical connectors /// found on the crossbars. Each instance of this class is limited /// to video only or audio only sources ( specified by the isVideoDevice /// parameter on the constructor) so we check each source before adding /// it to the list. /// </summary> 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); }
protected ArrayList findCrossbarSources(ICaptureGraphBuilder2 graphBuilder, IAMCrossbar crossbar, bool isVideoDevice) { int num2; int num3; ArrayList list = new ArrayList(); int errorCode = crossbar.get_PinCounts(out num2, out num3); if (errorCode < 0) { Marshal.ThrowExceptionForHR(errorCode); } for (int i = 0; i < num2; i++) { for (int j = 0; j < num3; j++) { if (crossbar.CanRoute(i, j) == 0) { int num6; PhysicalConnectorType type; errorCode = crossbar.get_CrossbarPinInfo(true, j, out num6, out type); if (errorCode < 0) { Marshal.ThrowExceptionForHR(errorCode); } CrossbarSource source = new CrossbarSource(crossbar, i, j, type); if (type < PhysicalConnectorType.Audio_Tuner) { if (isVideoDevice) { list.Add(source); } else if (!isVideoDevice) { list.Add(source); } } } } } int index = 0; while (index < list.Count) { bool flag = false; CrossbarSource source2 = (CrossbarSource) list[index]; for (int k = 0; k < list.Count; k++) { CrossbarSource source3 = (CrossbarSource) list[k]; if ((source2.OutputPin == source3.OutputPin) && (index != k)) { flag = true; break; } } if (flag) { index++; } else { list.RemoveAt(index); } } return list; }
// -------------------- IDisposable ----------------------- /// <summary> Release unmanaged resources. </summary> public override void Dispose() { if ( Crossbar != null ) Marshal.ReleaseComObject( Crossbar ); Crossbar = null; RelatedInputSource = null; base.Dispose(); }