// 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); } } }
protected override void Dispose(bool disposing) { if (disposing) { ForceReleaseComObject(_tuner); _tuner = null; ForceReleaseComObject(_tvaudio); _tvaudio = null; ForceReleaseComObject(_crossbar2); _crossbar2 = null; ForceReleaseComObject(_videoEncoder); _videoEncoder = null; ForceReleaseComObject(_audioEncoder); _audioEncoder = null; ForceReleaseComObject(_mpeg2Demux); _mpeg2Demux = null; ForceReleaseComObject(_leadYUVColorConverter); _leadYUVColorConverter = null; ForceReleaseComObject(_frameRateController); _frameRateController = null; ForceReleaseComObject(_audioVolumeFilter); _audioVolumeFilter = null; ForceReleaseComObject(_amTvTuner); _amTvTuner = null; ForceReleaseComObject(_amCrossbar); _amCrossbar = null; } base.Dispose(disposing); }
private static Camera_NET.VideoInput GetCrossbarInput(IAMCrossbar crossbar) { int num; int num2; Camera_NET.VideoInput input = Camera_NET.VideoInput.Default; if (crossbar.get_PinCounts(out num2, out num) == 0) { int num4; int num6; int outputPinIndex = -1; for (int i = 0; i < num2; i++) { PhysicalConnectorType type; if ((crossbar.get_CrossbarPinInfo(false, i, out num4, out type) == 0) && (type == PhysicalConnectorType.Video_VideoDecoder)) { outputPinIndex = i; break; } } if ((outputPinIndex != -1) && (crossbar.get_IsRoutedTo(outputPinIndex, out num6) == 0)) { PhysicalConnectorType type2; crossbar.get_CrossbarPinInfo(true, num6, out num4, out type2); input = new Camera_NET.VideoInput(num6, type2); } } return(input); }
private void ConfigTV() { int hr; object o; hr = _captureGraphBuilder.FindInterface(null, null, _captureFilter, typeof(IAMTVTuner).GUID, out o); if (hr >= 0) { _amTvTuner = (IAMTVTuner)o; o = null; hr = _captureGraphBuilder.FindInterface(null, null, _captureFilter, typeof(IAMCrossbar).GUID, out o); if (hr >= 0) { _amCrossbar = (IAMCrossbar)o; o = null; } else { throw new Exception("IAMCrossbar interface not found"); } } else { throw new Exception("IAMTVTuner interface not found"); } hr = _amTvTuner.put_InputType(0, (DirectShowLib.TunerInputType)_tvConfig.AnalogTunerInputType); DsError.ThrowExceptionForHR(hr); }
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); } }
// Token: 0x060001A5 RID: 421 RVA: 0x00012390 File Offset: 0x00010590 internal CrossbarSource(IAMCrossbar crossbar, int outputPin, int inputPin, PhysicalConnectorType connectorType) { this.Crossbar = crossbar; this.OutputPin = outputPin; this.InputPin = inputPin; this.ConnectorType = connectorType; }
//protected override void ConfigureVMR9InWindowlessMode(int numberOfStream) //{ // int hr = 0; // IVMRFilterConfig9 filterConfig = this.videoRenderer as IVMRFilterConfig9; // // Configure VMR-9 in Windowsless mode // hr = filterConfig.SetRenderingMode(VMR9Mode.Windowless); // DsError.ThrowExceptionForHR(hr); // // With 1 input stream // hr = filterConfig.SetNumberOfStreams(numberOfStream); // DsError.ThrowExceptionForHR(hr); // IVMRWindowlessControl9 windowlessControl = this.videoRenderer as IVMRWindowlessControl9; // // The main form is hosting the VMR-9 // hr = windowlessControl.SetVideoClippingWindow(this.hostingControl.Handle); // DsError.ThrowExceptionForHR(hr); // // Keep the aspect-ratio OK // //hr = windowlessControl.SetAspectRatioMode(VMR9AspectRatioMode.LetterBox); // hr = windowlessControl.SetAspectRatioMode(VMR9AspectRatioMode.None); // DsError.ThrowExceptionForHR(hr); // // Init the VMR-9 with default size values // OnResizeMoveHandler(null, null); // // Add Windows Messages handlers // AddHandlers(); //} public int FindCrossbarPin(IAMCrossbar pXBar, PhysicalConnectorType PhysicalType, PinDirection Dir, out int pIndex) { pIndex = -1; bool bInput = (Dir == PinDirection.Input ? true : false); // Find out how many pins the crossbar has. int cOut, cIn; int hr = pXBar.get_PinCounts(out cOut, out cIn); if (hr < 0) { return(hr); } // Enumerate pins and look for a matching pin. int count = (bInput ? cIn : cOut); for (int i = 0; i < count; i++) { int iRelated = 0; PhysicalConnectorType ThisPhysicalType = 0; hr = pXBar.get_CrossbarPinInfo(bInput, i, out iRelated, out ThisPhysicalType); if (hr >= 0 && ThisPhysicalType == PhysicalType) { // Found a match, return the index. pIndex = i; return(0); } } // Did not find a matching pin. return(-1); }
private VideoInput[] ColletCrossbarVideoInputs(IAMCrossbar crossbar) { lock (cacheCrossbarVideoInputs) { if (cacheCrossbarVideoInputs.ContainsKey(deviceMoniker)) { return(cacheCrossbarVideoInputs[deviceMoniker]); } List <VideoInput> list = new List <VideoInput>(); if (crossbar != null && crossbar.get_PinCounts(out int _, out int inputPinCount) == 0) { for (int i = 0; i < inputPinCount; i++) { if (crossbar.get_CrossbarPinInfo(isInputPin: true, i, out int _, out PhysicalConnectorType physicalType) == 0 && physicalType < PhysicalConnectorType.AudioTuner) { list.Add(new VideoInput(i, physicalType)); } } } VideoInput[] array = new VideoInput[list.Count]; list.CopyTo(array); cacheCrossbarVideoInputs.Add(deviceMoniker, array); return(array); } }
private int FindVideoDecoderOutputPin(IAMCrossbar crossbar) { int rv = -1; int outputPinsCount; int inputPinsCount; int hr = crossbar.get_PinCounts(out outputPinsCount, out inputPinsCount); DsError.ThrowExceptionForHR(hr); for (int i = 0; i < outputPinsCount; i++) { int relatedIndex; PhysicalConnectorType connectorType; hr = crossbar.get_CrossbarPinInfo(false, i, out relatedIndex, out connectorType); if (hr == 0) { int inputPinIndex; crossbar.get_IsRoutedTo(i, out inputPinIndex); Trace.WriteLine(string.Format("Crossbar Output Pin {0}: '{1}' routed to pin {2}", i, GetPhysicalPinName(connectorType), inputPinIndex)); if (connectorType == PhysicalConnectorType.Video_VideoDecoder) { rv = i; } } } return(rv); }
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); }
// Token: 0x06000044 RID: 68 RVA: 0x00003620 File Offset: 0x00001820 private VideoInput GetCurrentCrossbarInput(IAMCrossbar crossbar) { VideoInput result = VideoInput.Default1; int num; int num2; if (crossbar.get_PinCounts(out num, out num2) == 0) { int num3 = -1; for (int i = 0; i < num; i++) { int num4; PhysicalConnectorType physicalConnectorType; if (crossbar.get_CrossbarPinInfo(false, i, out num4, out physicalConnectorType) == 0 && physicalConnectorType == PhysicalConnectorType.VideoDecoder) { num3 = i; break; } } int num5; if (num3 != -1 && crossbar.get_IsRoutedTo(num3, out num5) == 0) { int num4; PhysicalConnectorType type; int num6 = crossbar.get_CrossbarPinInfo(true, num5, out num4, out type); result = new VideoInput(num5, type); } } return(result); }
protected void ConfigTV() { int hr; object o; hr = _captureGraphBuilder.FindInterface(null, null, _captureFilter, typeof(IAMTVTuner).GUID, out o); if (hr >= 0) { _amTvTuner = (IAMTVTuner)o; hr = _amTvTuner.put_InputType(0, AppUser.Current.TunerInputType); DsError.ThrowExceptionForHR(hr); o = null; hr = _captureGraphBuilder.FindInterface(null, null, _captureFilter, typeof(IAMCrossbar).GUID, out o); if (hr >= 0) { _amCrossbar = (IAMCrossbar)o; o = null; } else { throw new Exception("IAMCrossbar interface not found"); } } else { throw new Exception("IAMTVTuner interface not found"); } hr = _amTvTuner.put_InputType(0, AppUser.Current.TunerInputType); DsError.ThrowExceptionForHR(hr); }
internal CrossbarSource(IAMCrossbar crossbar, int outputPin, int inputPin, PhysicalConnectorType connectorType) { Crossbar = crossbar; OutputPin = outputPin; _InputPin = inputPin; _ConnectorType = connectorType; this.Name = getName(connectorType); }
// -------------------- Constructors/Destructors ---------------------- /// <summary> Constructor. This class cannot be created directly. </summary> internal CrossbarSource( IAMCrossbar crossbar, int outputPin, int inputPin, PhysicalConnectorType connectorType ) { this.Crossbar = crossbar; this.OutputPin = outputPin; this.InputPin = inputPin; this.ConnectorType = connectorType; this.name = getName( connectorType ); }
public override void Dispose(bool disposing) { AppLogger.Message("WinTV.Dispose"); if (disposing) { if (_tuner != null) { Marshal.ReleaseComObject(_tuner); _tuner = null; } if (_tvaudio != null) { Marshal.ReleaseComObject(_tvaudio); _tvaudio = null; } if (_crossbar2 != null) { Marshal.ReleaseComObject(_crossbar2); _crossbar2 = null; } if (_videoEncoder != null) { Marshal.ReleaseComObject(_videoEncoder); _videoEncoder = null; } if (_audioEncoder != null) { Marshal.ReleaseComObject(_audioEncoder); _audioEncoder = null; } if (_mpeg2Demux != null) { Marshal.ReleaseComObject(_mpeg2Demux); _mpeg2Demux = null; } if (_captureFilter != null) { Marshal.ReleaseComObject(_captureFilter); _captureFilter = null; } if (_hcwColorConverter != null) { Marshal.ReleaseComObject(_hcwColorConverter); _hcwColorConverter = null; } if (_amTvTuner != null) { Marshal.ReleaseComObject(_amTvTuner); _amTvTuner = null; } if (_amCrossbar != null) { Marshal.ReleaseComObject(_amCrossbar); _amCrossbar = null; } } base.Dispose(disposing); }
public override void Dispose() { if (this.Crossbar != null) { Marshal.ReleaseComObject(this.Crossbar); } this.Crossbar = null; base.Dispose(); }
/// <summary> Constructor. This class cannot be created directly. </summary> internal CrossbarSource(IAMCrossbar crossbar, int outputPin, int inputPin, int relatedInputPin, PhysicalConnectorType connectorType) { this.Crossbar = crossbar; this.OutputPin = outputPin; this.InputPin = inputPin; this.RelatedInputPin = relatedInputPin; this.ConnectorType = connectorType; this.name = getName(connectorType); }
/// <summary> Constructor. This class cannot be created directly. </summary> internal CrossbarSource(IAMCrossbar crossbar, int outputPin, int inputPin, int relatedInputPin, PhysicalConnectorType connectorType) { Crossbar = crossbar; OutputPin = outputPin; InputPin = inputPin; RelatedInputPin = relatedInputPin; ConnectorType = connectorType; name = GetName(connectorType); }
// -------------------- IDisposable ----------------------- /// <summary> Release unmanaged resources. </summary> public override void Dispose() { if (Crossbar != null) { Marshal.ReleaseComObject(Crossbar); } Crossbar = null; RelatedInputSource = null; base.Dispose(); }
void SetupVideoCrossbar() { int hr; crossBar = (IAMCrossbar)atiCrossbar; hr = crossBar.Route(0, 2); // input pin 2 is S-Video if (hr < 0) { Marshal.ThrowExceptionForHR(hr); } }
void BuildGraph() { DsDevice [] devs; string s; devs = DsDevice.GetDevicesOfCat(FilterCategory.AMKSCrossbar); DsDevice dev = devs[0]; dev.Mon.GetDisplayName(null, null, out s); m_ixbar = Marshal.BindToMoniker(s) as IAMCrossbar; }
public void ClearGraph() { CaptureGraph = null; MediaControl = null; MediaEvent = null; IamAvd = null; VideoDef = null; VideoPreview = null; XBar = null; VideoWindow = null; VideoWindowVr = null; }
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); } } } }
/// <summary> /// Closes and releases all used interfaces. /// </summary> public void CloseInterfaces() { if (VMRenderer != null) { Marshal.ReleaseComObject(VMRenderer); VMRenderer = null; WindowlessCtrl = null; IMFVideoDisplayControl = null; MixerBitmap = null; } if (Processer != null) { Marshal.ReleaseComObject(Processer); AudioRender = null; } if (AudioRender != null) { Marshal.ReleaseComObject(AudioRender); AudioRender = null; } if (FilterGraph != null) { Marshal.ReleaseComObject(FilterGraph); FilterGraph = null; MediaControl = null; } if (SmartTee != null) { Marshal.ReleaseComObject(SmartTee); SmartTee = null; } if (SampleGrabber != null) { Marshal.ReleaseComObject(SampleGrabber); SampleGrabber = null; SampleGrabberFilter = null; } if (CaptureFilter != null) { Marshal.ReleaseComObject(CaptureFilter); CaptureFilter = null; } if (Crossbar != null) { Marshal.ReleaseComObject(Crossbar); Crossbar = null; } }
private void DoCrossbarOperation(string deviceName, CrossbarCallback callback) { IGraphBuilder graphBuilder = null; ICaptureGraphBuilder2 captureGraphBuilder = null; IBaseFilter theDevice = null; try { graphBuilder = (IGraphBuilder) new FilterGraph(); captureGraphBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2(); theDevice = CreateFilter(FilterCategory.VideoInputDevice, deviceName); // Attach the filter graph to the capture graph int hr = captureGraphBuilder.SetFiltergraph(graphBuilder); DsError.ThrowExceptionForHR(hr); // Add the Video input device to the graph hr = graphBuilder.AddFilter(theDevice, "source filter"); DsError.ThrowExceptionForHR(hr); // Render any preview pin of the device hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, theDevice, null, null); DsError.ThrowExceptionForHR(hr); IAMCrossbar crossbar = null; object o; hr = captureGraphBuilder.FindInterface(null, null, theDevice, typeof(IAMCrossbar).GUID, out o); if (hr >= 0) { crossbar = (IAMCrossbar)o; o = null; if (crossbar != null) { callback(crossbar); return; } } callback(null); } finally { Marshal.ReleaseComObject(theDevice); Marshal.ReleaseComObject(graphBuilder); Marshal.ReleaseComObject(captureGraphBuilder); } }
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; }
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(); } }
private VideoInput GetCurrentCrossbarInput(IAMCrossbar crossbar) { VideoInput videoInput = VideoInput.Default; int inPinsCount, outPinsCount; if (crossbar.get_PinCounts(out outPinsCount, out inPinsCount) == 0) { int videoOutputPinIndex = -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; } } if (videoOutputPinIndex != -1) { int videoInputPinIndex; if (crossbar.get_IsRoutedTo(videoOutputPinIndex, out videoInputPinIndex) == 0) { PhysicalConnectorType inputType; crossbar.get_CrossbarPinInfo(true, videoInputPinIndex, out pinIndexRelated, out inputType); videoInput = new VideoInput(videoInputPinIndex, inputType); } } } return(videoInput); }
// Does not AddRef the returned *Pin private int GetCrossbarPinAtIndex(IAMCrossbar crossbar, int pinIndex, bool isInputPin, out IPin pin) { pin = null; if (crossbar == null) { return(-1); } int cntInPins, cntOutPins; if (crossbar.get_PinCounts(out cntOutPins, out cntInPins) != 0) { return(unchecked ((int)0x80004005)); //E_FAIL; } int trueIndex = isInputPin ? pinIndex : pinIndex + cntInPins; IBaseFilter filter = crossbar as IBaseFilter; if (filter != null) { IEnumPins enumPins = null; if (filter.EnumPins(out enumPins) == 0) { int i = 0; IPin [] pins = new IPin[1]; //22 int n; //22 while(enumPins.Next(1, pins, out n) == 0) while (enumPins.Next(1, pins, IntPtr.Zero) == 0) { //pP.Release(); if (i == trueIndex) { pin = pins[0]; break; } Marshal.ReleaseComObject(pins[0]); i++; } Marshal.ReleaseComObject(enumPins); } //pFilter.Release(); } return(pin != null ? 0 : unchecked ((int)0x80004005)); //E_FAIL; }
/// <summary> /// Gets type of input connected to video output of the crossbar. /// </summary> /// <param name="crossbar">The crossbar of device.</param> /// <returns>Video input of device</returns> /// <seealso cref="CrossbarAvailable"/> public static VideoInput GetCrossbarInput(IAMCrossbar crossbar) { VideoInput videoInput = VideoInput.Default; int inPinsCount, outPinsCount; // gen number of pins in the crossbar if (crossbar.get_PinCounts(out outPinsCount, out inPinsCount) == 0) { int videoOutputPinIndex = -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; } } if (videoOutputPinIndex != -1) { int videoInputPinIndex; // get index of the input pin connected to the output if (crossbar.get_IsRoutedTo(videoOutputPinIndex, out videoInputPinIndex) == 0) { PhysicalConnectorType inputType; crossbar.get_CrossbarPinInfo(true, videoInputPinIndex, out pinIndexRelated, out inputType); videoInput = new VideoInput(videoInputPinIndex, inputType); } } } return(videoInput); }
private VideoInput[] ColletCrossbarVideoInputs(IAMCrossbar crossbar) { lock ( cacheCrossbarVideoInputs ) { if (cacheCrossbarVideoInputs.ContainsKey(deviceMoniker)) { return(cacheCrossbarVideoInputs[deviceMoniker]); } List <VideoInput> videoInputsList = new List <VideoInput>( ); if (crossbar != null) { int inPinsCount, outPinsCount; if (crossbar.get_PinCounts(out outPinsCount, out inPinsCount) == 0) { for (int i = 0; i < inPinsCount; i++) { int pinIndexRelated; PhysicalConnectorType type; if (crossbar.get_CrossbarPinInfo(true, i, out pinIndexRelated, out type) != 0) { continue; } if (type < PhysicalConnectorType.AudioTuner) { videoInputsList.Add(new VideoInput(i, type)); } } } } VideoInput[] videoInputs = new VideoInput[videoInputsList.Count]; videoInputsList.CopyTo(videoInputs); cacheCrossbarVideoInputs.Add(deviceMoniker, videoInputs); return(videoInputs); } }
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); }
public static void LoadCrossbarSources(IAMCrossbar crossbar, ComboBox cbxCrossbarInput) { int connectedInputPin = -1; int videoDecoderOutPinIndex = FindVideoDecoderOutputPin(crossbar, out connectedInputPin); cbxCrossbarInput.Enabled = videoDecoderOutPinIndex != -1; Trace.WriteLine(string.Format("Loading crossbar dropdown on {0}\r\nVideo decoder output pin is {1} which is routed to pin {2}.", GetParentFormName(cbxCrossbarInput), videoDecoderOutPinIndex, connectedInputPin)); int outputPinsCount; int inputPinsCount; int hr = crossbar.get_PinCounts(out outputPinsCount, out inputPinsCount); DsError.ThrowExceptionForHR(hr); for (int i = 0; i < inputPinsCount; i++) { int relatedIndex; PhysicalConnectorType connectorType; hr = crossbar.get_CrossbarPinInfo(true, i, out relatedIndex, out connectorType); if (hr == 0) { Trace.WriteLine(string.Format("Crossbar Input Pin {0}: {1}", i, GetPhysicalPinName(connectorType))); if (IsVideoPin(connectorType)) { int addedIdnex = cbxCrossbarInput.Items.Add( new CrossbarPinEntry() { PinIndex = i, PinName = GetPhysicalPinName(connectorType) } ); if (connectedInputPin == i) cbxCrossbarInput.SelectedIndex = addedIdnex; } } } cbxCrossbarInput.Enabled = true; }
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)); } }
//protected override void ConfigureVMR9InWindowlessMode(int numberOfStream) //{ // int hr = 0; // IVMRFilterConfig9 filterConfig = this.videoRenderer as IVMRFilterConfig9; // // Configure VMR-9 in Windowsless mode // hr = filterConfig.SetRenderingMode(VMR9Mode.Windowless); // DsError.ThrowExceptionForHR(hr); // // With 1 input stream // hr = filterConfig.SetNumberOfStreams(numberOfStream); // DsError.ThrowExceptionForHR(hr); // IVMRWindowlessControl9 windowlessControl = this.videoRenderer as IVMRWindowlessControl9; // // The main form is hosting the VMR-9 // hr = windowlessControl.SetVideoClippingWindow(this.hostingControl.Handle); // DsError.ThrowExceptionForHR(hr); // // Keep the aspect-ratio OK // //hr = windowlessControl.SetAspectRatioMode(VMR9AspectRatioMode.LetterBox); // hr = windowlessControl.SetAspectRatioMode(VMR9AspectRatioMode.None); // DsError.ThrowExceptionForHR(hr); // // Init the VMR-9 with default size values // OnResizeMoveHandler(null, null); // // Add Windows Messages handlers // AddHandlers(); //} public int FindCrossbarPin(IAMCrossbar pXBar, PhysicalConnectorType PhysicalType, PinDirection Dir, out int pIndex) { pIndex = -1; bool bInput = (Dir == PinDirection.Input ? true : false); // Find out how many pins the crossbar has. int cOut, cIn; int hr = pXBar.get_PinCounts(out cOut, out cIn); if (hr < 0) return hr; // Enumerate pins and look for a matching pin. int count = (bInput ? cIn : cOut); for (int i = 0; i < count; i++) { int iRelated = 0; PhysicalConnectorType ThisPhysicalType = 0; hr = pXBar.get_CrossbarPinInfo(bInput, i, out iRelated, out ThisPhysicalType); if (hr >= 0 && ThisPhysicalType == PhysicalType) { // Found a match, return the index. pIndex = i; return 0; } } // Did not find a matching pin. return -1; }
// -------------------- IDisposable ----------------------- /// <summary> Release unmanaged resources. </summary> public override void Dispose() { if ( Crossbar != null ) Marshal.ReleaseComObject( Crossbar ); Crossbar = null; base.Dispose(); }
/// <summary> /// Insert the crossbar and other upstream filters if the device /// needs them. /// </summary> private void InsertCrossbar() { // Build upstream filters (crossbar) GCHandle hCat = GCHandle.Alloc(LOOK_UPSTREAM_ONLY, GCHandleType.Pinned); try { IntPtr pCat = hCat.AddrOfPinnedObject(); Guid g = Marshal.GenerateGuidForType(typeof(IAMCrossbar)); ICaptureGraphBuilder2 icgb2 = CaptureGraphBuilder2Class.CreateInstance(); icgb2.SetFiltergraph((IGraphBuilder)fgm); object oCB; icgb2.RemoteFindInterface(pCat, IntPtr.Zero, filter, ref g, out oCB); iCB = (IAMCrossbar)oCB; } catch(COMException ce) { if((uint)ce.ErrorCode != 0x80004005) // IAMCrossbar not found { string msg = DShowError._AMGetErrorText(ce.ErrorCode); Trace.WriteLine(msg); throw new Exception(string.Format(CultureInfo.CurrentCulture, Strings.DirectshowErrortext, msg), ce); } } finally { hCat.Free(); } }
// Get type of input connected to video output of the crossbar private VideoInput GetCurrentCrossbarInput( IAMCrossbar crossbar ) { VideoInput videoInput = VideoInput.Default; int inPinsCount, outPinsCount; // gen number of pins in the crossbar if ( crossbar.get_PinCounts( out outPinsCount, out inPinsCount ) == 0 ) { int videoOutputPinIndex = -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; } } if ( videoOutputPinIndex != -1 ) { int videoInputPinIndex; // get index of the input pin connected to the output if ( crossbar.get_IsRoutedTo( videoOutputPinIndex, out videoInputPinIndex ) == 0 ) { PhysicalConnectorType inputType; crossbar.get_CrossbarPinInfo( true, videoInputPinIndex, out pinIndexRelated, out inputType ); videoInput = new VideoInput( videoInputPinIndex, inputType ); } } } return videoInput; }
/// <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 Routing(Routing routing) { leftRouting = routing.leftRouting; rightRouting = routing.rightRouting; inputIndex = routing.inputIndex; outputIndex = routing.outputIndex; inputIndexRelated = routing.inputIndexRelated; outputIndexRelated = routing.outputIndexRelated; crossbar = routing.crossbar; inputPhysicalType = routing.inputPhysicalType; outputPhysicalType = routing.outputPhysicalType; depth = routing.depth; inputName = routing.inputName; }
private static int FindVideoDecoderOutputPin(IAMCrossbar crossbar) { int rv = -1; int outputPinsCount; int inputPinsCount; int hr = crossbar.get_PinCounts(out outputPinsCount, out inputPinsCount); DsError.ThrowExceptionForHR(hr); for (int i = 0; i < outputPinsCount; i++) { int relatedIndex; PhysicalConnectorType connectorType; hr = crossbar.get_CrossbarPinInfo(false, i, out relatedIndex, out connectorType); if (hr == 0) { int inputPinIndex; crossbar.get_IsRoutedTo(i, out inputPinIndex); Trace.WriteLine(string.Format("Crossbar Output Pin {0}: '{1}' routed to pin {2}", i, GetPhysicalPinName(connectorType), inputPinIndex)); if (connectorType == PhysicalConnectorType.Video_VideoDecoder) rv = i; } } return rv; }
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; }
/// <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 ); }
void SetupVideoCrossbar() { int hr; crossBar = (IAMCrossbar)atiCrossbar; hr = crossBar.Route(0, 2); // input pin 2 is S-Video if (hr < 0) Marshal.ThrowExceptionForHR(hr); }
public static string DumpCrossbar(IAMCrossbar iCB) { string ret = "\r\nCrossbar\r\n"; if(iCB != null) { ArrayList pins = GetPins((IBaseFilter)iCB); ArrayList inputPins = GetPins(pins, _PinDirection.PINDIR_INPUT); ArrayList outputPins = GetPins(pins, _PinDirection.PINDIR_OUTPUT); int inPins, outPins; iCB.get_PinCounts(out outPins, out inPins); ret += "\tInput Pins...\r\n"; for(int inIndex = 0; inIndex < inPins; inIndex++) { int related, type; iCB.get_CrossbarPinInfo(true, inIndex, out related, out type); ret += string.Format(CultureInfo.CurrentCulture, "\t{0}, Related input pin: {1}\r\n", Pin.Name((IPin)inputPins[inIndex]), related); } ret += "\r\n\tOutput Pins..."; for(int outIndex = 0; outIndex < outPins; outIndex++) { int related, type, routed; iCB.get_CrossbarPinInfo(false, outIndex, out related, out type); iCB.get_IsRoutedTo(outIndex, out routed); ret += string.Format(CultureInfo.CurrentCulture, "\r\n\t{0}, Related output pin: {1}, Routed input pin: {2}" + Environment.NewLine, Pin.Name((IPin)outputPins[outIndex]), related, routed); ret += "\tSwitching Matrix (which input pins this output pin can accept): "; for(int inIndex = 0; inIndex < inPins; inIndex++) { ret += string.Format(CultureInfo.CurrentCulture, "{0}-{1}", inIndex, (iCB.CanRoute(outIndex, inIndex) == 0) ? "Yes " : "No "); } } } return ret; }
public void CloseResources() { CloseInterfaces(); lock (this) { if (latestBitmap != null) { latestBitmap.Dispose(); latestBitmap = null; } if (samplGrabber != null) { Marshal.ReleaseComObject(samplGrabber); samplGrabber = null; } if (capBuilder != null) { Marshal.ReleaseComObject(capBuilder); capBuilder = null; } if (capFilter != null) { Marshal.ReleaseComObject(capFilter); capFilter = null; } if (Settings.Default.VideoGraphDebugMode) { if (rot != null) { rot.Dispose(); rot = null; } } crossbar = null; } }
private void InitTuner(ICaptureGraphBuilder2 captureGraphBuilder) { Object o; var hr = captureGraphBuilder.FindInterface(null, null, videoDevice, typeof(IAMTVTuner).GUID, out o); if (hr >= 0) { tuner = (IAMTVTuner)o; //tuner.put_Mode(AMTunerModeType.TV); o = null; //find crossbar var list = findCrossbars(captureGraphBuilder, (IBaseFilter)tuner); /*hr = captureGraphBuilder.FindInterface(null, null, (IBaseFilter)Tuner, typeof(IAMCrossbar).GUID, out o); if (hr >= 0) { crossbar = (IAMCrossbar)o; InitCrossbar(); } else crossbar = null; */ if (list.Count > 0) { crossbar = (IAMCrossbar)list[0]; InitCrossbar(); } o = null; // find amtvaudio hr = captureGraphBuilder.FindInterface(null, null, videoDevice, typeof(IAMTVAudio).GUID, out o); if (hr >= 0) { TVAudio = (IAMTVAudio)o; } o = null; // find IAMAnalogVideoDecoder hr = captureGraphBuilder.FindInterface(null, null, videoDevice, typeof(IAMAnalogVideoDecoder).GUID, out o); if (hr >= 0) { analogVideoDecoder = (o as IAMAnalogVideoDecoder); AnalogVideoStandard avs; analogVideoDecoder.get_TVFormat(out avs); } o = null; } else tuner = null; }
public void SetupGraph(DsDevice dev, bool runOCR, VideoFormatHelper.SupportedVideoFormat selectedFormat, ref float iFrameRate, ref int iWidth, ref int iHeight) { try { filterGraph = (IFilterGraph2)new FilterGraph(); mediaCtrl = filterGraph as IMediaControl; capBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2(); samplGrabber = (ISampleGrabber)new SampleGrabber(); int hr = capBuilder.SetFiltergraph(filterGraph); DsError.ThrowExceptionForHR(hr); if (Settings.Default.VideoGraphDebugMode) { if (rot != null) { rot.Dispose(); rot = null; } rot = new DsROTEntry(filterGraph); } SetupGraphInternal(dev, selectedFormat, ref iFrameRate, ref iWidth, ref iHeight); // Now that sizes are fixed/known, store the sizes SaveSizeInfo(samplGrabber); crossbar = CrossbarHelper.SetupTunerAndCrossbar(capBuilder, capFilter); latestBitmap = new Bitmap(iWidth, iHeight, PixelFormat.Format24bppRgb); fullRect = new Rectangle(0, 0, latestBitmap.Width, latestBitmap.Height); NativeHelpers.SetupCamera( Settings.Default.CameraModel, iWidth, iHeight, Settings.Default.HorizontalFlip, Settings.Default.VerticalFlip, Settings.Default.IsIntegrating, (float)Settings.Default.MinSignatureDiffRatio, (float)Settings.Default.MinSignatureDiff, Settings.Default.GammaDiff, Settings.Default.ForceNewFrameOnLockedRate, dev.Name, selectedFormat.AsSerialized(), selectedFormat.FrameRate); NativeHelpers.SetupAav(Settings.Default.RecordStatusSectionOnly ? AavImageLayout.StatusSectionOnly : Settings.Default.AavImageLayout, Settings.Default.AavCompression); ocrEnabled = false; string errorMessage; if (runOCR) { OcrConfiguration ocrConfig = OcrSettings.Instance[Settings.Default.SelectedOcrConfiguration]; errorMessage = NativeHelpers.SetupBasicOcrMetrix(ocrConfig); if (errorMessage != null && callbacksObject != null) callbacksObject.OnError(-1, errorMessage); else { NativeHelpers.SetupOcr(ocrConfig); ocrEnabled = true; } } else { errorMessage = NativeHelpers.SetupTimestampPreservation(false, 0, 0); if (errorMessage != null && callbacksObject != null) callbacksObject.OnError(-1, errorMessage); } } catch { CloseResources(); if (callbacksObject != null) callbacksObject.OnError(-1, "Error initialising the camera. The selected video mode may not be supported by the camera."); throw; } }
/// <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."); } } } }
// Does not AddRef the returned *Pin private int GetCrossbarPinAtIndex(IAMCrossbar crossbar, int pinIndex, bool isInputPin, out IPin pin) { pin = null; if (crossbar == null) return -1; int cntInPins, cntOutPins; if (crossbar.get_PinCounts(out cntOutPins, out cntInPins) != 0) return unchecked((int)0x80004005); //E_FAIL; int trueIndex = isInputPin ? pinIndex : pinIndex + cntInPins; IBaseFilter filter = crossbar as IBaseFilter; if (filter != null) { IEnumPins enumPins = null; if (filter.EnumPins(out enumPins) == 0) { int i = 0; IPin [] pins = new IPin[1]; //22 int n; //22 while(enumPins.Next(1, pins, out n) == 0) while (enumPins.Next(1, pins, IntPtr.Zero) == 0) { //pP.Release(); if (i == trueIndex) { pin = pins[0]; break; } Marshal.ReleaseComObject(pins[0]); i++; } Marshal.ReleaseComObject(enumPins); } //pFilter.Release(); } return pin != null ? 0 : unchecked((int)0x80004005); //E_FAIL; }
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; }
/// <summary> /// Closes and releases all used interfaces. /// </summary> public void CloseInterfaces() { if (VMRenderer != null) { Marshal.ReleaseComObject(VMRenderer); VMRenderer = null; WindowlessCtrl = null; MixerBitmap = null; } if (FilterGraph != null) { Marshal.ReleaseComObject(FilterGraph); FilterGraph = null; MediaControl = null; } if (SmartTee != null) { Marshal.ReleaseComObject(SmartTee); SmartTee = null; } if (SampleGrabber != null) { Marshal.ReleaseComObject(SampleGrabber); SampleGrabber = null; SampleGrabberFilter = null; } if (CaptureFilter != null) { Marshal.ReleaseComObject(CaptureFilter); CaptureFilter = null; } if (Crossbar != null) { Marshal.ReleaseComObject(Crossbar); Crossbar = null; } }
/// <summary> /// Creates the filter by trying to detect it /// </summary> /// <param name="tuner">The tuner component</param> /// <param name="graph">The stored graph</param> /// <param name="graphBuilder">The graphBuilder</param> /// <returns>true, if the graph building was successful</returns> private bool CreateAutomaticFilterInstance(Graph graph, IFilterGraph2 graphBuilder, Tuner tuner) { _audioTunerIn = null; DsDevice[] devices; //get list of all crossbar devices installed on this system try { devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSCrossbar); devices = DeviceSorter.Sort(devices, graph.Tuner.Name); } catch (Exception) { Log.Log.WriteFile("analog: AddCrossBarFilter no crossbar devices found"); return false; } if (devices == null || devices.Length == 0) { Log.Log.WriteFile("analog: AddCrossBarFilter no crossbar devices found"); return false; } //try each crossbar for (int i = 0; i < devices.Length; i++) { IBaseFilter tmp; Log.Log.WriteFile("analog: AddCrossBarFilter try:{0} {1}", devices[i].Name, i); //if crossbar is already in use then we can skip it if (DevicesInUse.Instance.IsUsed(devices[i])) continue; int hr; try { //add the crossbar to the graph hr = graphBuilder.AddSourceFilterForMoniker(devices[i].Mon, null, devices[i].Name, out tmp); } catch (Exception) { Log.Log.WriteFile("analog: cannot add filter to graph"); continue; } if (hr != 0) { //failed. try next crossbar if (tmp != null) { graphBuilder.RemoveFilter(tmp); Release.ComObject("CrossBarFilter", tmp); } continue; } _crossBarFilter = (IAMCrossbar)tmp; CheckCapabilities(); if (_videoOutPinIndex == -1) { Log.Log.WriteFile("analog: AddCrossbarFilter no video output found"); graphBuilder.RemoveFilter(tmp); _crossBarFilter = null; Release.ComObject("CrossBarFilter", tmp); continue; } // Check that the crossbar has a tuner video input pin. IPin pinIn = null; if (_videoPinMap.ContainsKey(AnalogChannel.VideoInputType.Tuner)) { pinIn = DsFindPin.ByDirection(tmp, PinDirection.Input, _videoPinMap[AnalogChannel.VideoInputType.Tuner]); } if (pinIn == null) { // no pin found, continue with next crossbar Log.Log.WriteFile("analog: AddCrossBarFilter no video tuner input pin detected"); if (tmp != null) { graphBuilder.RemoveFilter(tmp); _crossBarFilter = null; Release.ComObject("CrossBarFilter", tmp); } continue; } //connect tv tuner->crossbar int tempVideoPinIndex; if (FilterGraphTools.ConnectFilter(graphBuilder, tuner.Filter, pinIn, out tempVideoPinIndex)) { // Got it, we're done _filterCrossBar = tmp; _crossBarDevice = devices[i]; DevicesInUse.Instance.Add(_crossBarDevice); if (_audioTunerIn == null) { _audioTunerIn = DsFindPin.ByDirection(_filterCrossBar, PinDirection.Input, _audioPinMap[AnalogChannel.AudioInputType.Tuner]); } Release.ComObject("crossbar videotuner pin", pinIn); _videoOut = DsFindPin.ByDirection(_filterCrossBar, PinDirection.Output, _videoOutPinIndex); if (_audioOutPinIndex != -1) { _audioOut = DsFindPin.ByDirection(_filterCrossBar, PinDirection.Output, _audioOutPinIndex); } Log.Log.WriteFile("analog: AddCrossBarFilter succeeded"); graph.Crossbar.AudioOut = _audioOutPinIndex; graph.Crossbar.AudioPinMap = _audioPinMap; graph.Crossbar.Name = _crossBarDevice.Name; graph.Crossbar.VideoOut = _videoOutPinIndex; graph.Crossbar.VideoPinMap = _videoPinMap; graph.Crossbar.VideoPinRelatedAudioMap = _videoPinRelatedAudioMap; graph.Tuner.VideoPin = tempVideoPinIndex; break; } // cannot connect tv tuner to crossbar, try next crossbar device graphBuilder.RemoveFilter(tmp); Release.ComObject("crossbar videotuner pin", pinIn); Release.ComObject("crossbar filter", tmp); } return _filterCrossBar != null; }
// Collect all video inputs of the specified crossbar private VideoInput[] ColletCrossbarVideoInputs( IAMCrossbar crossbar ) { lock ( cacheCrossbarVideoInputs ) { if ( cacheCrossbarVideoInputs.ContainsKey( deviceMoniker ) ) { return cacheCrossbarVideoInputs[deviceMoniker]; } List<VideoInput> videoInputsList = new List<VideoInput>( ); if ( crossbar != null ) { int inPinsCount, outPinsCount; // gen number of pins in the crossbar if ( crossbar.get_PinCounts( out outPinsCount, out inPinsCount ) == 0 ) { // collect all video inputs for ( int i = 0; i < inPinsCount; i++ ) { int pinIndexRelated; PhysicalConnectorType type; if ( crossbar.get_CrossbarPinInfo( true, i, out pinIndexRelated, out type ) != 0 ) continue; if ( type < PhysicalConnectorType.AudioTuner ) { videoInputsList.Add( new VideoInput( i, type ) ); } } } } VideoInput[] videoInputs = new VideoInput[videoInputsList.Count]; videoInputsList.CopyTo( videoInputs ); cacheCrossbarVideoInputs.Add( deviceMoniker, videoInputs ); return videoInputs; } }
/// <summary> /// Creates the filter based on the configuration file /// </summary> /// <param name="tuner">The tuner component</param> /// <param name="graph">The stored graph</param> /// <param name="graphBuilder">The graphBuilder</param> /// <returns>true, if the graph building was successful</returns> private bool CreateConfigurationBasedFilterInstance(Graph graph, IFilterGraph2 graphBuilder, Tuner tuner) { string deviceName = graph.Crossbar.Name; _audioTunerIn = null; DsDevice[] devices; //get list of all crossbar devices installed on this system try { devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSCrossbar); devices = DeviceSorter.Sort(devices, graph.Tuner.Name); } catch (Exception) { Log.Log.WriteFile("analog: AddCrossBarFilter no crossbar devices found"); return false; } if (devices == null || devices.Length == 0) { Log.Log.WriteFile("analog: AddCrossBarFilter no crossbar devices found"); return false; } //try each crossbar for (int i = 0; i < devices.Length; i++) { IBaseFilter tmp; //if crossbar is already in use then we can skip it if (DevicesInUse.Instance.IsUsed(devices[i])) continue; if (!deviceName.Equals(devices[i].Name)) continue; Log.Log.WriteFile("analog: AddCrossBarFilter use:{0} {1}", devices[i].Name, i); int hr; try { //add the crossbar to the graph hr = graphBuilder.AddSourceFilterForMoniker(devices[i].Mon, null, devices[i].Name, out tmp); } catch (Exception) { Log.Log.WriteFile("analog: cannot add filter to graph"); continue; } if (hr != 0) { //failed. try next crossbar if (tmp != null) { graphBuilder.RemoveFilter(tmp); Release.ComObject("CrossBarFilter", tmp); } continue; } _crossBarFilter = (IAMCrossbar)tmp; _videoPinMap = graph.Crossbar.VideoPinMap; _audioPinMap = graph.Crossbar.AudioPinMap; _videoPinRelatedAudioMap = graph.Crossbar.VideoPinRelatedAudioMap; _videoOutPinIndex = graph.Crossbar.VideoOut; _audioOutPinIndex = graph.Crossbar.AudioOut; if (_videoOutPinIndex == -1) { Log.Log.WriteFile("analog: AddCrossbarFilter no video output found"); graphBuilder.RemoveFilter(tmp); _crossBarFilter = null; Release.ComObject("CrossBarFilter", tmp); continue; } //connect tv tuner->crossbar IPin tunerOut = DsFindPin.ByDirection(tuner.Filter, PinDirection.Output, graph.Tuner.VideoPin); if (tunerOut != null && _videoPinMap.ContainsKey(AnalogChannel.VideoInputType.Tuner) && FilterGraphTools.ConnectPin(graphBuilder, tunerOut, tmp, _videoPinMap[AnalogChannel.VideoInputType.Tuner])) { // Got it, we're done _filterCrossBar = tmp; _crossBarDevice = devices[i]; DevicesInUse.Instance.Add(_crossBarDevice); if (_audioTunerIn == null) { _audioTunerIn = DsFindPin.ByDirection(_filterCrossBar, PinDirection.Input, _audioPinMap[AnalogChannel.AudioInputType.Tuner]); } Release.ComObject("tuner video out", tunerOut); _videoOut = DsFindPin.ByDirection(_filterCrossBar, PinDirection.Output, _videoOutPinIndex); if (_audioOutPinIndex != -1) { _audioOut = DsFindPin.ByDirection(_filterCrossBar, PinDirection.Output, _audioOutPinIndex); } Log.Log.WriteFile("analog: AddCrossBarFilter succeeded"); break; } // cannot connect tv tuner to crossbar, try next crossbar device if (tmp != null) { graphBuilder.RemoveFilter(tmp); Release.ComObject("crossbarFilter filter", tmp); } if (tunerOut != null) { Release.ComObject("tuner video out", tunerOut); } } return _filterCrossBar != null; }
// 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> do cleanup and release DirectShow. </summary> void CloseInterfaces() { int hr; #if DEBUG if (rotCookie != 0) DsROT.RemoveGraphFromRot(ref rotCookie); #endif if (mediaCtrl != null) { hr = mediaCtrl.Stop(); Marshal.ReleaseComObject(mediaCtrl); mediaCtrl = null; } if (mediaEvt != null) { Marshal.ReleaseComObject(mediaEvt); mediaEvt = null; } if (baseGrabFlt != null) { Marshal.ReleaseComObject(baseGrabFlt); baseGrabFlt = null; } if (sampleGrabber != null) { Marshal.ReleaseComObject(sampleGrabber); sampleGrabber = null; } if (grabberConfig != null) { Marshal.ReleaseComObject(grabberConfig); grabberConfig = null; } if (capGraph != null) { Marshal.ReleaseComObject(capGraph); capGraph = null; } if (graphBuilder != null) { Marshal.ReleaseComObject(graphBuilder); graphBuilder = null; } if (dev != null) { dev.Dispose(); dev = null; } if (wmVideoDecoder != null) { Marshal.ReleaseComObject(wmVideoDecoder); wmVideoDecoder = null; } if (capFilter != null) { Marshal.ReleaseComObject(capFilter); capFilter = null; } if (capDevices != null) { foreach (DsDevice d in capDevices) d.Dispose(); capDevices = null; } if (atiCrossbar != null) { Marshal.ReleaseComObject(atiCrossbar); atiCrossbar = null; } if (motionVector != null) { Marshal.ReleaseComObject(motionVector); motionVector = null; } if (teeSplitter != null) { Marshal.ReleaseComObject(teeSplitter); teeSplitter = null; } if (videoRenderer != null) { Marshal.ReleaseComObject(videoRenderer); videoRenderer = null; } if (vectorGrabber != null) { //vectorGrabber.SetCallback(null); // FIXME: sometimes, this causes an exception Marshal.ReleaseComObject(vectorGrabber); vectorGrabber = null; } if (crossBar != null) { Marshal.ReleaseComObject(crossBar); crossBar = null; } }