/// <summary> /// Disposes this instance. /// </summary> public override void Dispose() { if (_graphBuilder == null) { return; } if (!CheckThreadId()) { return; } base.Dispose(); Log.Log.WriteFile("b2c2:Decompose"); _interfaceB2C2DataCtrl = null; _interfaceB2C2TunerCtrl = null; if (_filterB2C2Adapter != null) { Release.ComObject("tuner filter", _filterB2C2Adapter); _filterB2C2Adapter = 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); } }
public static void GetTunerInformation(out uint numberOfTuners, out List <DeviceInfo> deviceList) { numberOfTuners = 0; deviceList = new List <DeviceInfo>(); //========================================================================================================= // add the B2C2 specific filters //========================================================================================================= IBaseFilter filterB2C2Adapter = Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_B2C2Adapter, false)) as IBaseFilter; if (filterB2C2Adapter == null) { Log.Log.Error("b2c2:GetTunerCapabilities() _filterB2C2Adapter not found"); return; } IB2C2MPEG2DataCtrl6 interfaceB2C2DataCtrl = filterB2C2Adapter as IB2C2MPEG2DataCtrl6; if (interfaceB2C2DataCtrl == null) { Log.Log.Error("b2c2: cannot get IB2C2MPEG2DataCtrl6"); return; } int deviceInfoSize = Marshal.SizeOf(typeof(tagDEVICE_INFORMATION)) * 16; IntPtr ptDeviceInfo = Marshal.AllocHGlobal(deviceInfoSize); numberOfTuners = 16; int hr = interfaceB2C2DataCtrl.GetDeviceList(ptDeviceInfo, ref deviceInfoSize, ref numberOfTuners); if (hr != 0) { Log.Log.Error("b2c2: GetDeviceList failed:0x{0:X}", hr); } Log.Log.WriteFile("Result: " + numberOfTuners); long currentPtr = ptDeviceInfo.ToInt64(); // Must work both on x86 and x64 for (int i = 0; i < numberOfTuners; i++) { IntPtr RectPtr = new IntPtr(currentPtr); tagDEVICE_INFORMATION tc = (tagDEVICE_INFORMATION)Marshal.PtrToStructure(RectPtr, typeof(tagDEVICE_INFORMATION)); CardType cardType = CardType.Unknown; switch (tc.eTunerModulation) { case TunerType.ttSat: cardType = CardType.DvbS; break; case TunerType.ttCable: cardType = CardType.DvbC; break; case TunerType.ttTerrestrial: cardType = CardType.DvbT; break; case TunerType.ttATSC: cardType = CardType.Atsc; break; case TunerType.ttUnknown: cardType = CardType.Unknown; break; } DeviceInfo device = new DeviceInfo { DeviceId = tc.dwDeviceID, Name = tc.wsProductName + " (" + tc.wsProductRevision + ")", CardType = cardType, DevicePath = String.Format("device:{0}_{1}_{2}_[{3:X02}:{4:X02}:{5:X02}:{6:X02}:{7:X02}:{8:X02}]", tc.eBusInterface, tc.dwDeviceID, tc.dwProductID, tc.ucMACAddress[0], tc.ucMACAddress[1], tc.ucMACAddress[2], tc.ucMACAddress[3], tc.ucMACAddress[4], tc.ucMACAddress[5]) }; deviceList.Add(device); currentPtr += Marshal.SizeOf(typeof(tagDEVICE_INFORMATION)); } Marshal.FreeHGlobal(ptDeviceInfo); // Release all used object Release.ComObject("tuner filter", filterB2C2Adapter); }
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); } }
/// <summary> /// Disposes this instance. /// </summary> public override void Dispose() { if (_graphBuilder == null) return; if (!CheckThreadId()) return; base.Dispose(); Log.Log.WriteFile("b2c2:Decompose"); _interfaceB2C2DataCtrl = null; _interfaceB2C2TunerCtrl = null; if (_filterB2C2Adapter != null) { Release.ComObject("tuner filter", _filterB2C2Adapter); _filterB2C2Adapter = null; } }