/// <summary> /// Builds the graph. /// </summary> public override void BuildGraph() { try { Log.Log.WriteFile("b2c2: build graph"); if (_graphState != GraphState.Idle) { Log.Log.Error("b2c2: Graph already built"); throw new TvException("Graph already built"); } DevicesInUse.Instance.Add(_tunerDevice); _managedThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId; _graphBuilder = (IFilterGraph2) new FilterGraph(); _rotEntry = new DsROTEntry(_graphBuilder); _capBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2(); _capBuilder.SetFiltergraph(_graphBuilder); //========================================================================================================= // add the B2C2 specific filters //========================================================================================================= Log.Log.WriteFile("b2c2:CreateGraph() create B2C2 adapter"); _filterB2C2Adapter = Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_B2C2Adapter, false)) as IBaseFilter; Log.Log.WriteFile("b2c2: Filter instance: " + _filterB2C2Adapter); if (_filterB2C2Adapter == null) { Log.Log.Error("b2c2:creategraph() _filterB2C2Adapter not found"); DevicesInUse.Instance.Remove(_tunerDevice); return; } Log.Log.WriteFile("b2c2:creategraph() add filters to graph"); int hr = _graphBuilder.AddFilter(_filterB2C2Adapter, "B2C2-Source"); if (hr != 0) { Log.Log.Error("b2c2: FAILED to add B2C2-Adapter"); DevicesInUse.Instance.Remove(_tunerDevice); return; } // get interfaces _interfaceB2C2TunerCtrl = _filterB2C2Adapter as IB2C2MPEG2TunerCtrl4; if (_interfaceB2C2TunerCtrl == null) { Log.Log.Error("b2c2: cannot get IB2C2MPEG2TunerCtrl4"); DevicesInUse.Instance.Remove(_tunerDevice); return; } _interfaceB2C2DataCtrl = _filterB2C2Adapter as IB2C2MPEG2DataCtrl6; if (_interfaceB2C2DataCtrl == null) { Log.Log.Error("b2c2: cannot get IB2C2MPEG2DataCtrl6"); DevicesInUse.Instance.Remove(_tunerDevice); return; } hr = _interfaceB2C2DataCtrl.SelectDevice(_deviceInfo.DeviceId); if (hr != 0) { Log.Log.Error("b2c2: select device failed: {0:X}", hr); } //========================================================================================================= // initialize B2C2 tuner //========================================================================================================= Log.Log.WriteFile("b2c2: Initialize Tuner()"); hr = _interfaceB2C2TunerCtrl.Initialize(); if (hr != 0) { //System.Diagnostics.Debugger.Launch(); Log.Log.Error("b2c2: Tuner initialize failed:0x{0:X}", hr); // if the B2C2 card is detected as analogue, it needs a device reset ((IMediaControl)_graphBuilder).Stop(); FreeAllSubChannels(); FilterGraphTools.RemoveAllFilters(_graphBuilder); if (_graphBuilder != null) { Release.ComObject("graph builder", _graphBuilder); _graphBuilder = null; } if (_capBuilder != null) { Release.ComObject("capBuilder", _capBuilder); _capBuilder = null; } DevicesInUse.Instance.Remove(_tunerDevice); CardPresent = false; return; } // call checklock once, the return value dont matter hr = _interfaceB2C2TunerCtrl.CheckLock(); AddTsWriterFilterToGraph(); IBaseFilter lastFilter; ConnectInfTeeToB2C2(out lastFilter); AddMdPlugs(ref lastFilter); if (!ConnectTsWriter(lastFilter)) { throw new TvExceptionGraphBuildingFailed("Graph building failed"); } SendHwPids(new List <ushort>()); _graphState = GraphState.Created; } catch (Exception ex) { Log.Log.Write(ex); Dispose(); _graphState = GraphState.Idle; throw new TvExceptionGraphBuildingFailed("Graph building failed", ex); } }
private void GetTunerCapabilities() { Log.Log.WriteFile("b2c2: GetTunerCapabilities"); _graphBuilder = (IFilterGraph2)new FilterGraph(); _rotEntry = new DsROTEntry(_graphBuilder); _capBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2(); _capBuilder.SetFiltergraph(_graphBuilder); //========================================================================================================= // add the B2C2 specific filters //========================================================================================================= Log.Log.WriteFile("b2c2:GetTunerCapabilities() create B2C2 adapter"); _filterB2C2Adapter = Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_B2C2Adapter, false)) as IBaseFilter; if (_filterB2C2Adapter == null) { Log.Log.Error("b2c2:GetTunerCapabilities() _filterB2C2Adapter not found"); return; } _interfaceB2C2TunerCtrl = _filterB2C2Adapter as IB2C2MPEG2TunerCtrl4; if (_interfaceB2C2TunerCtrl == null) { Log.Log.Error("b2c2: cannot get IB2C2MPEG2TunerCtrl4"); return; } _interfaceB2C2DataCtrl = _filterB2C2Adapter as IB2C2MPEG2DataCtrl6; if (_interfaceB2C2DataCtrl == null) { Log.Log.Error("b2c2: cannot get IB2C2MPEG2DataCtrl6"); return; } int hr = _interfaceB2C2DataCtrl.SelectDevice(_deviceInfo.DeviceId); if (hr != 0) { Log.Log.Error("b2c2: select device failed: {0:X}", hr); } //========================================================================================================= // Get tuner type (DVBS, DVBC, DVBT, ATSC) //========================================================================================================= int lTunerCapSize = Marshal.SizeOf(typeof(tTunerCapabilities)); IntPtr ptCaps = Marshal.AllocHGlobal(lTunerCapSize); hr = _interfaceB2C2TunerCtrl.GetTunerCapabilities(ptCaps, ref lTunerCapSize); if (hr != 0) { Log.Log.Error("b2c2: Tuner Type failed:0x{0:X}", hr); return; } tTunerCapabilities tc = (tTunerCapabilities)Marshal.PtrToStructure(ptCaps, typeof(tTunerCapabilities)); switch (tc.eModulation) { case TunerType.ttSat: Log.Log.WriteFile("b2c2: Card type = DVBS"); _cardType = CardType.DvbS; break; case TunerType.ttCable: Log.Log.WriteFile("b2c2: Card type = DVBC"); _cardType = CardType.DvbC; break; case TunerType.ttTerrestrial: Log.Log.WriteFile("b2c2: Card type = DVBT"); _cardType = CardType.DvbT; break; case TunerType.ttATSC: Log.Log.WriteFile("b2c2: Card type = ATSC"); _cardType = CardType.Atsc; break; case TunerType.ttUnknown: Log.Log.WriteFile("b2c2: Card type = unknown?"); _cardType = CardType.Unknown; break; } Marshal.FreeHGlobal(ptCaps); // Release all used object if (_filterB2C2Adapter != null) { Release.ComObject("tuner filter", _filterB2C2Adapter); _filterB2C2Adapter = null; } _rotEntry.Dispose(); if (_capBuilder != null) { Release.ComObject("capture builder", _capBuilder); _capBuilder = null; } if (_graphBuilder != null) { Release.ComObject("graph builder", _graphBuilder); _graphBuilder = null; } }
private void GetTunerCapabilities() { Log.Log.WriteFile("b2c2: GetTunerCapabilities"); _graphBuilder = (IFilterGraph2) new FilterGraph(); _rotEntry = new DsROTEntry(_graphBuilder); _capBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2(); _capBuilder.SetFiltergraph(_graphBuilder); //========================================================================================================= // add the B2C2 specific filters //========================================================================================================= Log.Log.WriteFile("b2c2:GetTunerCapabilities() create B2C2 adapter"); _filterB2C2Adapter = Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_B2C2Adapter, false)) as IBaseFilter; if (_filterB2C2Adapter == null) { Log.Log.Error("b2c2:GetTunerCapabilities() _filterB2C2Adapter not found"); return; } _interfaceB2C2TunerCtrl = _filterB2C2Adapter as IB2C2MPEG2TunerCtrl4; if (_interfaceB2C2TunerCtrl == null) { Log.Log.Error("b2c2: cannot get IB2C2MPEG2TunerCtrl4"); return; } _interfaceB2C2DataCtrl = _filterB2C2Adapter as IB2C2MPEG2DataCtrl6; if (_interfaceB2C2DataCtrl == null) { Log.Log.Error("b2c2: cannot get IB2C2MPEG2DataCtrl6"); return; } int hr = _interfaceB2C2DataCtrl.SelectDevice(_deviceInfo.DeviceId); if (hr != 0) { Log.Log.Error("b2c2: select device failed: {0:X}", hr); } //========================================================================================================= // Get tuner type (DVBS, DVBC, DVBT, ATSC) //========================================================================================================= int lTunerCapSize = Marshal.SizeOf(typeof(tTunerCapabilities)); IntPtr ptCaps = Marshal.AllocHGlobal(lTunerCapSize); hr = _interfaceB2C2TunerCtrl.GetTunerCapabilities(ptCaps, ref lTunerCapSize); if (hr != 0) { Log.Log.Error("b2c2: Tuner Type failed:0x{0:X}", hr); return; } tTunerCapabilities tc = (tTunerCapabilities)Marshal.PtrToStructure(ptCaps, typeof(tTunerCapabilities)); switch (tc.eModulation) { case TunerType.ttSat: Log.Log.WriteFile("b2c2: Card type = DVBS"); _cardType = CardType.DvbS; break; case TunerType.ttCable: Log.Log.WriteFile("b2c2: Card type = DVBC"); _cardType = CardType.DvbC; break; case TunerType.ttTerrestrial: Log.Log.WriteFile("b2c2: Card type = DVBT"); _cardType = CardType.DvbT; break; case TunerType.ttATSC: Log.Log.WriteFile("b2c2: Card type = ATSC"); _cardType = CardType.Atsc; break; case TunerType.ttUnknown: Log.Log.WriteFile("b2c2: Card type = unknown?"); _cardType = CardType.Unknown; break; } Marshal.FreeHGlobal(ptCaps); // Release all used object if (_filterB2C2Adapter != null) { Release.ComObject("tuner filter", _filterB2C2Adapter); _filterB2C2Adapter = null; } _rotEntry.Dispose(); if (_capBuilder != null) { Release.ComObject("capture builder", _capBuilder); _capBuilder = null; } if (_graphBuilder != null) { Release.ComObject("graph builder", _graphBuilder); _graphBuilder = null; } }
/// <summary> /// Builds the graph. /// </summary> public override void BuildGraph() { try { Log.Log.WriteFile("b2c2: build graph"); if (_graphState != GraphState.Idle) { Log.Log.Error("b2c2: Graph already built"); throw new TvException("Graph already built"); } DevicesInUse.Instance.Add(_tunerDevice); _managedThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId; _graphBuilder = (IFilterGraph2)new FilterGraph(); _rotEntry = new DsROTEntry(_graphBuilder); _capBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2(); _capBuilder.SetFiltergraph(_graphBuilder); //========================================================================================================= // add the B2C2 specific filters //========================================================================================================= Log.Log.WriteFile("b2c2:CreateGraph() create B2C2 adapter"); _filterB2C2Adapter = Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_B2C2Adapter, false)) as IBaseFilter; Log.Log.WriteFile("b2c2: Filter instance: " + _filterB2C2Adapter); if (_filterB2C2Adapter == null) { Log.Log.Error("b2c2:creategraph() _filterB2C2Adapter not found"); DevicesInUse.Instance.Remove(_tunerDevice); return; } Log.Log.WriteFile("b2c2:creategraph() add filters to graph"); int hr = _graphBuilder.AddFilter(_filterB2C2Adapter, "B2C2-Source"); if (hr != 0) { Log.Log.Error("b2c2: FAILED to add B2C2-Adapter"); DevicesInUse.Instance.Remove(_tunerDevice); return; } // get interfaces _interfaceB2C2TunerCtrl = _filterB2C2Adapter as IB2C2MPEG2TunerCtrl4; if (_interfaceB2C2TunerCtrl == null) { Log.Log.Error("b2c2: cannot get IB2C2MPEG2TunerCtrl4"); DevicesInUse.Instance.Remove(_tunerDevice); return; } _interfaceB2C2DataCtrl = _filterB2C2Adapter as IB2C2MPEG2DataCtrl6; if (_interfaceB2C2DataCtrl == null) { Log.Log.Error("b2c2: cannot get IB2C2MPEG2DataCtrl6"); DevicesInUse.Instance.Remove(_tunerDevice); return; } hr = _interfaceB2C2DataCtrl.SelectDevice(_deviceInfo.DeviceId); if (hr != 0) { Log.Log.Error("b2c2: select device failed: {0:X}", hr); } //========================================================================================================= // initialize B2C2 tuner //========================================================================================================= Log.Log.WriteFile("b2c2: Initialize Tuner()"); hr = _interfaceB2C2TunerCtrl.Initialize(); if (hr != 0) { //System.Diagnostics.Debugger.Launch(); Log.Log.Error("b2c2: Tuner initialize failed:0x{0:X}", hr); // if the B2C2 card is detected as analogue, it needs a device reset ((IMediaControl)_graphBuilder).Stop(); FreeAllSubChannels(); FilterGraphTools.RemoveAllFilters(_graphBuilder); if (_graphBuilder != null) { Release.ComObject("graph builder", _graphBuilder); _graphBuilder = null; } if (_capBuilder != null) { Release.ComObject("capBuilder", _capBuilder); _capBuilder = null; } DevicesInUse.Instance.Remove(_tunerDevice); CardPresent = false; return; } // call checklock once, the return value dont matter hr = _interfaceB2C2TunerCtrl.CheckLock(); AddTsWriterFilterToGraph(); IBaseFilter lastFilter; ConnectInfTeeToB2C2(out lastFilter); AddMdPlugs(ref lastFilter); if (!ConnectTsWriter(lastFilter)) { throw new TvExceptionGraphBuildingFailed("Graph building failed"); } SendHwPids(new List<ushort>()); _graphState = GraphState.Created; } catch (Exception ex) { Log.Log.Write(ex); Dispose(); _graphState = GraphState.Idle; throw new TvExceptionGraphBuildingFailed("Graph building failed", ex); } }