void TestCanRoute() { int hr; int opin, ipin; hr = m_ixbar.get_PinCounts(out opin, out ipin); DsError.ThrowExceptionForHR(hr); for (int x = 0; x < ipin; x++) { for (int y = 0; y < opin; y++) { hr = m_ixbar.CanRoute(y, x); if (hr == 0) { // If we can route, try it hr = m_ixbar.Route(y, x); Debug.Assert(hr == 0); } else if (hr == 1) { // If we can't route, we should get S_FALSE hr = m_ixbar.Route(y, x); Debug.Assert(hr == 1); } else { DsError.ThrowExceptionForHR(hr); } } } }
public int ConnectAudio(IAMCrossbar pXBar, bool bActivate) { // Look for the Audio Decoder output pin. int i = 0; int hr = FindCrossbarPin(pXBar, PhysicalConnectorType.Audio_AudioDecoder, PinDirection.Output, out i); if (hr >= 0) { if (bActivate) // Activate the audio. { // Look for the Audio Tuner input pin. int j = 0; hr = FindCrossbarPin(pXBar, PhysicalConnectorType.Audio_Tuner, PinDirection.Input, out j); if (hr >= 0) { return(pXBar.Route(i, j)); } } else // Mute the audio { return(pXBar.Route(i, -1)); } } return(-1); }
public void ChangeVideoInputSource(PhysicalConnectorType inputType) { if (crossbar != null) { int numOutputPins; int numInputPins; int hr = crossbar.get_PinCounts(out numOutputPins, out numInputPins); DsError.ThrowExceptionForHR(hr); int outputPin = -1; //get the video output pin for (int i = 0; i < numOutputPins; i++) { int relatedPin; PhysicalConnectorType physicalType; hr = crossbar.get_CrossbarPinInfo(false, i, out relatedPin, out physicalType); DsError.ThrowExceptionForHR(hr); //VideoDecoder //AudioDecoder if (physicalType == PhysicalConnectorType.Video_VideoDecoder) { outputPin = i; break; } } int inputPin = -1; for (int i = 0; i < numInputPins; i++) { int relatedPin; PhysicalConnectorType physicalType; hr = crossbar.get_CrossbarPinInfo(true, i, out relatedPin, out physicalType); DsError.ThrowExceptionForHR(hr); if (physicalType == inputType) { inputPin = i; break; } } if (outputPin != -1 && inputPin != -1) { hr = crossbar.Route(outputPin, inputPin); videoInputDeviceSource = inputType; DsError.ThrowExceptionForHR(hr); } } }
// Token: 0x06000045 RID: 69 RVA: 0x00003694 File Offset: 0x00001894 private void SetCurrentCrossbarInput(IAMCrossbar crossbar, VideoInput videoInput) { int num; int num2; if (videoInput.Type != PhysicalConnectorType.Default && crossbar.get_PinCounts(out num, out num2) == 0) { int num3 = -1; int num4 = -1; for (int i = 0; i < num; i++) { int num5; PhysicalConnectorType physicalConnectorType; if (crossbar.get_CrossbarPinInfo(false, i, out num5, out physicalConnectorType) == 0 && physicalConnectorType == PhysicalConnectorType.VideoDecoder) { num3 = i; break; } } for (int j = 0; j < num2; j++) { int num5; PhysicalConnectorType physicalConnectorType; if (crossbar.get_CrossbarPinInfo(true, j, out num5, out physicalConnectorType) == 0 && physicalConnectorType == videoInput.Type && j == videoInput.Index) { num4 = j; break; } } if (num4 != -1 && num3 != -1 && crossbar.CanRoute(num3, num4) == 0) { crossbar.Route(num3, num4); } } }
private void SetCurrentCrossbarInput(IAMCrossbar crossbar, VideoInput videoInput) { if (videoInput.Type == PhysicalConnectorType.Default || crossbar.get_PinCounts(out int outputPinCount, out int inputPinCount) != 0) { return; } int num = -1; int num2 = -1; int pinIndexRelated; PhysicalConnectorType physicalType; for (int i = 0; i < outputPinCount; i++) { if (crossbar.get_CrossbarPinInfo(isInputPin: false, i, out pinIndexRelated, out physicalType) == 0 && physicalType == PhysicalConnectorType.VideoDecoder) { num = i; break; } } for (int j = 0; j < inputPinCount; j++) { if (crossbar.get_CrossbarPinInfo(isInputPin: true, j, out pinIndexRelated, out physicalType) == 0 && physicalType == videoInput.Type && j == videoInput.Index) { num2 = j; break; } } if (num2 != -1 && num != -1 && crossbar.CanRoute(num, num2) == 0) { crossbar.Route(num, num2); } }
private void PerformTuning(IChannel channel) { Log.Log.WriteFile("HDPVR: Tune"); AnalogChannel analogChannel = channel as AnalogChannel; if (analogChannel == null) { throw new NullReferenceException(); } // Set up the crossbar. IAMCrossbar crossBarFilter = _filterCrossBar as IAMCrossbar; // Video if ((_previousChannel == null || _previousChannel.VideoSource != analogChannel.VideoSource) && _videoPinMap.ContainsKey(analogChannel.VideoSource)) { Log.Log.WriteFile("HDPVR: video input -> {0}", analogChannel.VideoSource); crossBarFilter.Route(_videoOutPinIndex, _videoPinMap[analogChannel.VideoSource]); } // Audio if (analogChannel.AudioSource == AnalogChannel.AudioInputType.Automatic) { if (_videoPinRelatedAudioMap.ContainsKey(analogChannel.VideoSource)) { Log.Log.WriteFile("HDPVR: audio input -> (auto)"); crossBarFilter.Route(_audioOutPinIndex, _videoPinRelatedAudioMap[analogChannel.VideoSource]); } } else if ((_previousChannel == null || _previousChannel.AudioSource != analogChannel.AudioSource) && _audioPinMap.ContainsKey(analogChannel.AudioSource)) { Log.Log.WriteFile("HDPVR: audio input -> {0}", analogChannel.AudioSource); crossBarFilter.Route(_audioOutPinIndex, _audioPinMap[analogChannel.AudioSource]); } _lastSignalUpdate = DateTime.MinValue; _tunerLocked = false; _previousChannel = analogChannel; Log.Log.WriteFile("HDPVR: Tuned to channel {0}", channel.Name); if (_graphState == GraphState.Idle) { _graphState = GraphState.Created; } _lastSignalUpdate = DateTime.MinValue; }
void SetupVideoCrossbar() { int hr; crossBar = (IAMCrossbar)atiCrossbar; hr = crossBar.Route(0, 2); // input pin 2 is S-Video if (hr < 0) { Marshal.ThrowExceptionForHR(hr); } }
private void SetCurrentCrossbarInput(IAMCrossbar crossbar, VideoInput videoInput) { if (videoInput.Type != PhysicalConnectorType.Default) { int inPinsCount, outPinsCount; if (crossbar.get_PinCounts(out outPinsCount, out inPinsCount) == 0) { int videoOutputPinIndex = -1; int videoInputPinIndex = -1; int pinIndexRelated; PhysicalConnectorType type; for (int i = 0; i < outPinsCount; i++) { if (crossbar.get_CrossbarPinInfo(false, i, out pinIndexRelated, out type) != 0) { continue; } if (type == PhysicalConnectorType.VideoDecoder) { videoOutputPinIndex = i; break; } } for (int i = 0; i < inPinsCount; i++) { if (crossbar.get_CrossbarPinInfo(true, i, out pinIndexRelated, out type) != 0) { continue; } if ((type == videoInput.Type) && (i == videoInput.Index)) { videoInputPinIndex = i; break; } } if ((videoInputPinIndex != -1) && (videoOutputPinIndex != -1) && (crossbar.CanRoute(videoOutputPinIndex, videoInputPinIndex) == 0)) { crossbar.Route(videoOutputPinIndex, videoInputPinIndex); } } } }
public static void ConnectToCrossbarSource(IAMCrossbar crossbar, int inputPinIndex) { if (crossbar != null) { int routedTo; int videoDecoderOutPinIndex = FindVideoDecoderOutputPin(crossbar, out routedTo); int hr = crossbar.Route(videoDecoderOutPinIndex, inputPinIndex); DsError.ThrowExceptionForHR(hr); Trace.WriteLine(string.Format("ConnectToCrossbarSource: Crossbar Input Pin {0} routed to Output Pin {1}.", inputPinIndex, videoDecoderOutPinIndex)); Settings.Default.UsesTunerCrossbar = true; Settings.Default.CrossbarInputPin = inputPinIndex; Settings.Default.CrossbarOutputPin = videoDecoderOutPinIndex; Settings.Default.Save(); } }
/// <summary> /// Indicates if it is a special plextor card /// </summary> /// <returns>true, if it is a special plextor card</returns> public void PerformTune(AnalogChannel channel) { if (_currentChannel != null) { bool updateRequired = _currentChannel.IsTv == channel.IsTv; if (updateRequired || (_currentChannel.VideoSource != channel.VideoSource && _videoPinMap.ContainsKey(channel.VideoSource))) { _crossBarFilter.Route(_videoOutPinIndex, _videoPinMap[channel.VideoSource]); updateRequired = true; } if (_audioOutPinIndex == -1) { return; } if (updateRequired || _currentChannel.AudioSource != channel.AudioSource) { if (channel.AudioSource == AnalogChannel.AudioInputType.Automatic && _videoPinRelatedAudioMap.ContainsKey(channel.VideoSource)) { _crossBarFilter.Route(_audioOutPinIndex, _videoPinRelatedAudioMap[channel.VideoSource]); } else if (_audioPinMap.ContainsKey(channel.AudioSource)) { _crossBarFilter.Route(_audioOutPinIndex, _audioPinMap[channel.AudioSource]); } } } else { if (_videoPinMap.ContainsKey(channel.VideoSource)) { _crossBarFilter.Route(_videoOutPinIndex, _videoPinMap[channel.VideoSource]); } if (_audioOutPinIndex == -1) { return; } if (channel.AudioSource == AnalogChannel.AudioInputType.Automatic && _videoPinRelatedAudioMap.ContainsKey(channel.VideoSource)) { _crossBarFilter.Route(_audioOutPinIndex, _videoPinRelatedAudioMap[channel.VideoSource]); } else if (_audioPinMap.ContainsKey(channel.AudioSource)) { _crossBarFilter.Route(_audioOutPinIndex, _audioPinMap[channel.AudioSource]); } } _currentChannel = channel; }
public void RouteCrossbarPins(DirectShowLib.PhysicalConnectorType outputConnectorType, DirectShowLib.PhysicalConnectorType inputConnectorType) { int hr; if (_amCrossbar != null) { int i; int j; i = FindCrossbarPin(outputConnectorType, false); if (i != -1) { j = FindCrossbarPin(inputConnectorType, true); if (j != -1) { hr = _amCrossbar.Route(i, j); DsError.ThrowExceptionForHR(hr); } } } }
private void SetInputAndSystem() { //TODO how can we support more than 1 card? if (SourceConfig.DeviceAddress == null) { throw new SourceConfigException("You must specify a DeviceAddress!"); } //Route the SourceConfig's selected input _crossbarAPI = (IAMCrossbar)_crossbar; int hr = _crossbarAPI.Route(0, SourceConfig.DeviceAddress.Input); DsError.ThrowExceptionForHR(hr); //declare that our input is NTSC _captureDecoder = (IAMAnalogVideoDecoder)_captureFilter; hr = _captureDecoder.put_TVFormat(AnalogVideoStandard.NTSC_M); //HACK NTSC is hard coded DsError.ThrowExceptionForHR(hr); }
private static void SetCrossbarInput(IAMCrossbar crossbar, Camera_NET.VideoInput videoInput) { int num; int num2; if (((videoInput.Type != Camera_NET.VideoInput.PhysicalConnectorType_Default) && (videoInput.Index != -1)) && (crossbar.get_PinCounts(out num2, out num) == 0)) { int num5; PhysicalConnectorType type; int outputPinIndex = -1; int inputPinIndex = -1; for (int i = 0; i < num2; i++) { if ((crossbar.get_CrossbarPinInfo(false, i, out num5, out type) == 0) && (type == PhysicalConnectorType.Video_VideoDecoder)) { outputPinIndex = i; break; } } for (int j = 0; j < num; j++) { if (((crossbar.get_CrossbarPinInfo(true, j, out num5, out type) == 0) && (type == videoInput.Type)) && (j == videoInput.Index)) { inputPinIndex = j; break; } } if ((inputPinIndex == -1) || (outputPinIndex == -1)) { throw new Exception("Can't find routing pins."); } if (crossbar.CanRoute(outputPinIndex, inputPinIndex) != 0) { throw new Exception("Can't route from selected VideoInput to VideoDecoder."); } DsError.ThrowExceptionForHR(crossbar.Route(outputPinIndex, inputPinIndex)); } }
public void SetupTunerAndCrossbar(ICaptureGraphBuilder2 graphBuilder, IBaseFilter deviceFilter) { if (settings.UsesTunerCrossbar) { object o; int hr = graphBuilder.FindInterface(null, null, deviceFilter, typeof(IAMTVTuner).GUID, out o); if (hr >= 0) { hr = graphBuilder.FindInterface(null, null, deviceFilter, typeof(IAMCrossbar).GUID, out o); if (hr >= 0) { IAMCrossbar crossbar = (IAMCrossbar)o; if (crossbar != null) { hr = crossbar.Route(settings.CrossbarOutputPin, settings.CrossbarInputPin); DsError.ThrowExceptionForHR(hr); } } } } }
/// <summary> /// Sets type of input connected to video output of the crossbar. /// </summary> /// <param name="crossbar">The crossbar of device.</param> /// <param name="videoInput">Video input of device.</param> /// <seealso cref="CrossbarAvailable"/> private static void SetCrossbarInput(IAMCrossbar crossbar, VideoInput videoInput) { if (videoInput.Type != VideoInput.PhysicalConnectorType_Default && videoInput.Index != -1) { int inPinsCount, outPinsCount; // gen number of pins in the crossbar if (crossbar.get_PinCounts(out outPinsCount, out inPinsCount) == 0) { int videoOutputPinIndex = -1; int videoInputPinIndex = -1; int pinIndexRelated; PhysicalConnectorType type; // find index of the video output pin for (int i = 0; i < outPinsCount; i++) { if (crossbar.get_CrossbarPinInfo(false, i, out pinIndexRelated, out type) != 0) continue; if (type == PhysicalConnectorType.Video_VideoDecoder) { videoOutputPinIndex = i; break; } } // find index of the required input pin for (int i = 0; i < inPinsCount; i++) { if (crossbar.get_CrossbarPinInfo(true, i, out pinIndexRelated, out type) != 0) continue; if ((type == videoInput.Type) && (i == videoInput.Index)) { videoInputPinIndex = i; break; } } // try connecting pins if ((videoInputPinIndex != -1) && (videoOutputPinIndex != -1)) { if (crossbar.CanRoute(videoOutputPinIndex, videoInputPinIndex) == 0) { int hr = crossbar.Route(videoOutputPinIndex, videoInputPinIndex); DsError.ThrowExceptionForHR(hr); } else { throw new Exception("Can't route from selected VideoInput to VideoDecoder."); } } else { throw new Exception("Can't find routing pins."); } } } }
/// <summary> build the capture graph for grabber. </summary> private void SetupGraph(DsDevice dev, AMMediaType media) { int hr; ISampleGrabber sampGrabber = null; IBaseFilter capFilter = null; ICaptureGraphBuilder2 capGraph = null; // Get the graphbuilder object m_FilterGraph = (IFilterGraph2) new FilterGraph(); m_mediaCtrl = m_FilterGraph as IMediaControl; try { // Get the ICaptureGraphBuilder2 capGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2(); /* * // check for crossbar * var capDevices2 = DsDevice.GetDevicesOfCat(FilterCategory.AMKSCrossbar); * if (capDevices2.Length > 0) * { * * IBaseFilter cross; * hr = m_FilterGraph.AddSourceFilterForMoniker(capDevices2[0].Mon, null, "crossbar", out cross); * ISpecifyPropertyPages pProp = cross as ISpecifyPropertyPages; * * //Get the name of the filter from the FilterInfo struct * FilterInfo filterInfo; * hr = cross.QueryFilterInfo(out filterInfo); * DsError.ThrowExceptionForHR(hr); * * // Get the propertypages from the property bag * DsCAUUID caGUID; * hr = pProp.GetPages(out caGUID); * DsError.ThrowExceptionForHR(hr); * * //Create and display the OlePropertyFrame * object oDevice = (object)cross; * hr = NativeMethods.OleCreatePropertyFrame(IntPtr.Zero, 0, 0, filterInfo.achName, 1, ref oDevice, caGUID.cElems, caGUID.pElems, 0, 0, IntPtr.Zero); * DsError.ThrowExceptionForHR(hr); * * Marshal.ReleaseComObject(oDevice); * * //IAMCrossbar crossbar2 = cross as IAMCrossbar; * //int inputPinCount, outputPinCount; * //crossbar2.get_PinCounts(out inputPinCount, out outputPinCount); * //crossbar2.Route(0, (int)PhysicalConnectorType.Video_Composite); * cross = null; * }*/ // Get the SampleGrabber interface sampGrabber = (ISampleGrabber) new SampleGrabber(); // Start building the graph hr = capGraph.SetFiltergraph(m_FilterGraph); DsError.ThrowExceptionForHR(hr); // Add the video device hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, "Video input", out capFilter); DsError.ThrowExceptionForHR(hr); // add video crossbar // thanks to Andrew Fernie - this is to get tv tuner cards working IAMCrossbar crossbar = null; object o; hr = capGraph.FindInterface(PinCategory.Capture, MediaType.Video, capFilter, typeof(IAMCrossbar).GUID, out o); if (hr >= 0) { crossbar = (IAMCrossbar)o; int oPin, iPin; int ovLink, ivLink; ovLink = ivLink = 0; crossbar.get_PinCounts(out oPin, out iPin); int pIdxRel; PhysicalConnectorType tp; for (int i = 0; i < iPin; i++) { crossbar.get_CrossbarPinInfo(true, i, out pIdxRel, out tp); if (tp == PhysicalConnectorType.Video_Composite) { ivLink = i; } } for (int i = 0; i < oPin; i++) { crossbar.get_CrossbarPinInfo(false, i, out pIdxRel, out tp); if (tp == PhysicalConnectorType.Video_VideoDecoder) { ovLink = i; } } try { crossbar.Route(ovLink, ivLink); o = null; } catch { throw new Exception("Failed to get IAMCrossbar"); } } //add AVI Decompressor IBaseFilter pAVIDecompressor = (IBaseFilter) new AVIDec(); hr = m_FilterGraph.AddFilter(pAVIDecompressor, "AVI Decompressor"); DsError.ThrowExceptionForHR(hr); // IBaseFilter baseGrabFlt = (IBaseFilter)sampGrabber; ConfigureSampleGrabber(sampGrabber); // Add the frame grabber to the graph hr = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber"); DsError.ThrowExceptionForHR(hr); SetConfigParms(capGraph, capFilter, media); hr = capGraph.RenderStream(PinCategory.Capture, MediaType.Video, capFilter, pAVIDecompressor, baseGrabFlt); if (hr < 0) { hr = capGraph.RenderStream(PinCategory.Capture, MediaType.Video, capFilter, null, baseGrabFlt); } DsError.ThrowExceptionForHR(hr); SaveSizeInfo(sampGrabber); } finally { if (capFilter != null) { Marshal.ReleaseComObject(capFilter); capFilter = null; } if (sampGrabber != null) { Marshal.ReleaseComObject(sampGrabber); sampGrabber = null; } if (capGraph != null) { Marshal.ReleaseComObject(capGraph); capGraph = null; } } }
/// <summary> /// Sets type of input connected to video output of the crossbar. /// </summary> /// <param name="crossbar">The crossbar of device.</param> /// <param name="videoInput">Video input of device.</param> /// <seealso cref="CrossbarAvailable"/> public static void SetCrossbarInput(IAMCrossbar crossbar, VideoInput videoInput) { if (videoInput.Type != VideoInput.PhysicalConnectorType_Default && videoInput.Index != -1) { int inPinsCount, outPinsCount; // gen number of pins in the crossbar if (crossbar.get_PinCounts(out outPinsCount, out inPinsCount) == 0) { int videoOutputPinIndex = -1; int videoInputPinIndex = -1; int pinIndexRelated; PhysicalConnectorType type; // find index of the video output pin for (int i = 0; i < outPinsCount; i++) { if (crossbar.get_CrossbarPinInfo(false, i, out pinIndexRelated, out type) != 0) { continue; } if (type == PhysicalConnectorType.Video_VideoDecoder) { videoOutputPinIndex = i; break; } } // find index of the required input pin for (int i = 0; i < inPinsCount; i++) { if (crossbar.get_CrossbarPinInfo(true, i, out pinIndexRelated, out type) != 0) { continue; } if ((type == videoInput.Type) && (i == videoInput.Index)) { videoInputPinIndex = i; break; } } // try connecting pins if ((videoInputPinIndex != -1) && (videoOutputPinIndex != -1)) { if (crossbar.CanRoute(videoOutputPinIndex, videoInputPinIndex) == 0) { int hr = crossbar.Route(videoOutputPinIndex, videoInputPinIndex); DsError.ThrowExceptionForHR(hr); } else { throw new Exception("Can't route from selected VideoInput to VideoDecoder."); } } else { throw new Exception("Can't find routing pins."); } } } }
void AdjustCrossbarPin() { IAMCrossbar crossbar = null; object o = null; int hr; hr = captureGraphBuilder.FindInterface( PinCategory.Capture, MediaType.Video, sourceFilter, typeof(IAMCrossbar).GUID, out o); if (hr >= 0) { crossbar = (IAMCrossbar)o; int numOutPin, numInPin; int nOutputAudioLink, nInputAudioLink, nOutputVideoLink, nInputVideoLink; nOutputAudioLink = nInputAudioLink = nOutputVideoLink = nInputVideoLink = -1; crossbar.get_PinCounts(out numOutPin, out numInPin); int pIdxRel; PhysicalConnectorType pct; for (int i = 0; i < numInPin; i++) { crossbar.get_CrossbarPinInfo(true, i, out pIdxRel, out pct); Log.log(pct.ToString()); //if (pct == PhysicalConnectorType.Audio_Tuner) nInputAudioLink = i; if (pct == PhysicalConnectorType.Video_Composite) { nInputVideoLink = i; } if (nInputAudioLink != -1 && nInputVideoLink != -1) { break; } } for (int i = 0; i < numOutPin; i++) { crossbar.get_CrossbarPinInfo(false, i, out pIdxRel, out pct); Log.log(pct.ToString()); //if (pct == PhysicalConnectorType.Audio_AudioDecoder) nOutputAudioLink = i; if (pct == PhysicalConnectorType.Video_VideoDecoder) { nOutputVideoLink = i; } if (nOutputAudioLink != -1 && nOutputVideoLink != 1) { break; } } try { if (crossbar.Route(nOutputVideoLink, nInputVideoLink) >= 0) { o = null; } else { o = null; } } catch { o = null; } } }
public int ConnectAudio(IAMCrossbar pXBar, bool bActivate) { // Look for the Audio Decoder output pin. int i = 0; int hr = FindCrossbarPin(pXBar, PhysicalConnectorType.Audio_AudioDecoder, PinDirection.Output, out i); if (hr >= 0) { if (bActivate) // Activate the audio. { // Look for the Audio Tuner input pin. int j = 0; hr = FindCrossbarPin(pXBar, PhysicalConnectorType.Audio_Tuner, PinDirection.Input, out j); if (hr >= 0) { return pXBar.Route(i, j); } } else // Mute the audio { return pXBar.Route(i, -1); } } return -1; }
void SetupVideoCrossbar() { int hr; crossBar = (IAMCrossbar)atiCrossbar; hr = crossBar.Route(0, 2); // input pin 2 is S-Video if (hr < 0) Marshal.ThrowExceptionForHR(hr); }
// Set type of input connected to video output of the crossbar private void SetCurrentCrossbarInput( IAMCrossbar crossbar, VideoInput videoInput ) { if ( videoInput.Type != PhysicalConnectorType.Default ) { int inPinsCount, outPinsCount; // gen number of pins in the crossbar if ( crossbar.get_PinCounts( out outPinsCount, out inPinsCount ) == 0 ) { int videoOutputPinIndex = -1; int videoInputPinIndex = -1; int pinIndexRelated; PhysicalConnectorType type; // find index of the video output pin for ( int i = 0; i < outPinsCount; i++ ) { if ( crossbar.get_CrossbarPinInfo( false, i, out pinIndexRelated, out type ) != 0 ) continue; if ( type == PhysicalConnectorType.VideoDecoder ) { videoOutputPinIndex = i; break; } } // find index of the required input pin for ( int i = 0; i < inPinsCount; i++ ) { if ( crossbar.get_CrossbarPinInfo( true, i, out pinIndexRelated, out type ) != 0 ) continue; if ( ( type == videoInput.Type ) && ( i == videoInput.Index ) ) { videoInputPinIndex = i; break; } } // try connecting pins if ( ( videoInputPinIndex != -1 ) && ( videoOutputPinIndex != -1 ) && ( crossbar.CanRoute( videoOutputPinIndex, videoInputPinIndex ) == 0 ) ) { crossbar.Route( videoOutputPinIndex, videoInputPinIndex ); } } } }
/// <summary> build the capture graph for grabber. </summary> private void SetupGraph(DsDevice dev, AMMediaType media) { int hr; ISampleGrabber sampGrabber = null; IBaseFilter capFilter = null; ICaptureGraphBuilder2 capGraph = null; // Get the graphbuilder object m_FilterGraph = (IFilterGraph2) new FilterGraph(); m_mediaCtrl = m_FilterGraph as IMediaControl; try { // Get the ICaptureGraphBuilder2 capGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2(); // Get the SampleGrabber interface sampGrabber = (ISampleGrabber) new SampleGrabber(); // Start building the graph hr = capGraph.SetFiltergraph(m_FilterGraph); DsError.ThrowExceptionForHR(hr); // Add the video device hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, "Video input", out capFilter); DsError.ThrowExceptionForHR(hr); // add video crossbar // thanks to Andrew Fernie - this is to get tv tuner cards working IAMCrossbar crossbar = null; object o; hr = capGraph.FindInterface(PinCategory.Capture, MediaType.Video, capFilter, typeof(IAMCrossbar).GUID, out o); if (hr >= 0) { crossbar = (IAMCrossbar)o; int oPin, iPin; int ovLink, ivLink; ovLink = ivLink = 0; crossbar.get_PinCounts(out oPin, out iPin); int pIdxRel; PhysicalConnectorType tp; for (int i = 0; i < iPin; i++) { crossbar.get_CrossbarPinInfo(true, i, out pIdxRel, out tp); if (tp == PhysicalConnectorType.Video_Composite) { ivLink = i; } } for (int i = 0; i < oPin; i++) { crossbar.get_CrossbarPinInfo(false, i, out pIdxRel, out tp); if (tp == PhysicalConnectorType.Video_VideoDecoder) { ovLink = i; } } try { crossbar.Route(ovLink, ivLink); o = null; } catch { throw new Exception("Failed to get IAMCrossbar"); } } //add AVI Decompressor IBaseFilter pAVIDecompressor = (IBaseFilter) new AVIDec(); hr = m_FilterGraph.AddFilter(pAVIDecompressor, "AVI Decompressor"); DsError.ThrowExceptionForHR(hr); // IBaseFilter baseGrabFlt = (IBaseFilter)sampGrabber; ConfigureSampleGrabber(sampGrabber); // Add the frame grabber to the graph hr = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber"); DsError.ThrowExceptionForHR(hr); SetConfigParms(capGraph, capFilter, media); hr = capGraph.RenderStream(PinCategory.Capture, MediaType.Video, capFilter, pAVIDecompressor, baseGrabFlt); if (hr < 0) { hr = capGraph.RenderStream(PinCategory.Capture, MediaType.Video, capFilter, null, baseGrabFlt); } DsError.ThrowExceptionForHR(hr); SaveSizeInfo(sampGrabber); } finally { if (capFilter != null) { Marshal.ReleaseComObject(capFilter); capFilter = null; } if (sampGrabber != null) { Marshal.ReleaseComObject(sampGrabber); sampGrabber = null; } if (capGraph != null) { Marshal.ReleaseComObject(capGraph); capGraph = null; } } }