/// <summary> /// Scans the specified transponder. /// </summary> /// <param name="channel">The channel.</param> /// <param name="settings">The settings.</param> /// <returns></returns> public List <IChannel> Scan(IChannel channel, ScanParameters settings) { try { _card.IsScanning = true; _card.Scan(0, channel); _analyzer = GetAnalyzer(); if (_analyzer == null) { Log.Log.WriteFile("Scan: no analyzer interface available"); return(new List <IChannel>()); } ResetSignalUpdate(); if (_card.IsTunerLocked == false) { Thread.Sleep(settings.TimeOutTune * 1000); ResetSignalUpdate(); } Log.Log.WriteFile("Scan: tuner locked:{0} signal:{1} quality:{2}", _card.IsTunerLocked, _card.SignalLevel, _card.SignalQuality); if (_card.IsTunerLocked || _card.SignalLevel > 0 || _card.SignalQuality > 0) { try { _event = new ManualResetEvent(false); _analyzer.SetCallBack(this); _analyzer.Start(_enableWaitForVCT); _event.WaitOne(settings.TimeOutSDT * 1000, true); int found = 0; short channelCount; _analyzer.GetCount(out channelCount); List <IChannel> channelsFound = new List <IChannel>(); for (int i = 0; i < channelCount; ++i) { int networkId; int transportId; int serviceId; short majorChannel; short minorChannel; short frequency; short freeCAMode; short serviceType; short modulation; IntPtr providerName; IntPtr serviceName; short pmtPid; short hasVideo; short hasAudio; short hasCaDescriptor; short lcn; _analyzer.GetChannel((short)i, out networkId, out transportId, out serviceId, out majorChannel, out minorChannel, out frequency, out lcn, out freeCAMode, out serviceType, out modulation, out providerName, out serviceName, out pmtPid, out hasVideo, out hasAudio, out hasCaDescriptor); string name = DvbTextConverter.Convert(serviceName, ""); Log.Log.Write("{0}) 0x{1:X} 0x{2:X} 0x{3:X} 0x{4:X} {5} type:{6:X}", i, networkId, transportId, serviceId, pmtPid, name, serviceType); found++; ChannelInfo info = new ChannelInfo(); info.networkID = networkId; info.transportStreamID = transportId; info.serviceID = serviceId; info.majorChannel = majorChannel; info.minorChannel = minorChannel; info.freq = frequency; info.LCN = lcn; info.serviceType = serviceType; info.modulation = modulation; info.service_provider_name = DvbTextConverter.Convert(providerName, ""); info.service_name = DvbTextConverter.Convert(serviceName, ""); info.scrambled = (freeCAMode != 0 || hasCaDescriptor != 0); info.network_pmt_PID = pmtPid; if (IsValidChannel(info, hasAudio, hasVideo)) { if (info.service_name.Length == 0) { SetNameForUnknownChannel(channel, info); } IChannel result = CreateNewChannel(channel, info); if (result != null) { channelsFound.Add(result); } } else { Log.Log.Write( "Found Unknown: {0} {1} type:{2} onid:{3:X} tsid:{4:X} sid:{5:X} pmt:{6:X} hasVideo:{7} hasAudio:{8}", info.service_provider_name, info.service_name, info.serviceType, info.networkID, info.transportStreamID, info.serviceID, info.network_pmt_PID, hasVideo, hasAudio); } } Log.Log.Write("Scan Got {0} from {1} channels", found, channelCount); return(channelsFound); } finally { if (_analyzer != null) { _analyzer.SetCallBack(null); _analyzer.Stop(); } _event.Close(); } } else { Log.Log.WriteFile("Scan: no signal detected"); return(new List <IChannel>()); } } finally { _card.IsScanning = false; } }
///<summary> /// Scan NIT channel ///</summary> ///<param name="channel">Channel</param> ///<param name="settings">Scan Parameters</param> ///<returns>Found channels</returns> public List <IChannel> ScanNIT(IChannel channel, ScanParameters settings) { try { _card.IsScanning = true; _card.Scan(0, channel); _analyzer = GetAnalyzer(); if (_analyzer == null) { Log.Log.WriteFile("Scan: no analyzer interface available"); return(new List <IChannel>()); } _analyzer.SetCallBack(null); _analyzer.ScanNIT(); Thread.Sleep(settings.TimeOutTune * 1000); ResetSignalUpdate(); Log.Log.WriteFile("ScanNIT: tuner locked:{0} signal:{1} quality:{2}", _card.IsTunerLocked, _card.SignalLevel, _card.SignalQuality); if (_card.IsTunerLocked || _card.SignalLevel > 0 || _card.SignalQuality > 0) { int count; _event = new ManualResetEvent(false); _event.WaitOne(16000, true); _event.Close(); List <IChannel> channelsFound = new List <IChannel>(); _analyzer.GetNITCount(out count); for (int i = 0; i < count; ++i) { int freq, pol, mod, symbolrate, bandwidth, innerfec, rollOff, chType; IntPtr ptrName; _analyzer.GetNITChannel((short)i, out chType, out freq, out pol, out mod, out symbolrate, out bandwidth, out innerfec, out rollOff, out ptrName); string name = DvbTextConverter.Convert(ptrName, ""); if (chType == 0) { DVBSChannel ch = new DVBSChannel(); ch.Name = name; ch.Frequency = freq; Log.Log.Debug("{0},{1},{2},{3}", freq, mod, pol, symbolrate); switch (mod) { default: case 0: ch.ModulationType = ModulationType.ModNotSet; break; //case 1: ch.ModulationType = ModulationType.ModQpsk; break; case 2: ch.ModulationType = ModulationType.Mod8Psk; break; case 3: ch.ModulationType = ModulationType.Mod16Qam; break; } ch.SymbolRate = symbolrate; ch.InnerFecRate = (BinaryConvolutionCodeRate)innerfec; ch.Polarisation = (Polarisation)pol; ch.Rolloff = (RollOff)rollOff; channelsFound.Add(ch); } else if (chType == 1) { DVBCChannel ch = new DVBCChannel(); ch.Name = name; ch.Frequency = freq; ch.ModulationType = (ModulationType)mod; ch.SymbolRate = symbolrate; channelsFound.Add(ch); } else if (chType == 2) { DVBTChannel ch = new DVBTChannel(); ch.Name = name; ch.Frequency = freq; ch.BandWidth = bandwidth; channelsFound.Add(ch); } } _analyzer.StopNIT(); return(channelsFound); } else { Log.Log.WriteFile("Scan: no signal detected"); return(new List <IChannel>()); } } finally { if (_analyzer != null) { _analyzer.StopNIT(); } _card.IsScanning = false; } }
/// <summary> /// Tunes to the channel specified and will start scanning for any channel /// </summary> /// <param name="channel">channel to tune to</param> /// <param name="settings"></param> /// <returns>list of channels found</returns> public List <IChannel> Scan(IChannel channel, ScanParameters settings) { _card.IsScanning = true; _card.Tune(0, channel); if (_card.IsTunerLocked) { if (channel.IsTv) { if (_card.VideoFrequency == _previousFrequency) { return(new List <IChannel>()); } _previousFrequency = _card.VideoFrequency; } if (channel.IsTv) { try { _scanner = _card.GetChannelScanner(); _event = new ManualResetEvent(false); _scanner.SetCallBack(this); _scanner.Start(); _event.WaitOne(settings.TimeOutAnalog * 1000, true); IntPtr serviceName; _scanner.GetChannel(out serviceName); _scanner.Stop(); string channelName = DvbTextConverter.Convert(serviceName, ""); int pos = channelName.LastIndexOf("teletext", StringComparison.InvariantCultureIgnoreCase); if (pos != -1) { channelName = channelName.Substring(0, pos); } //Some times channel name includes program name after : pos = channelName.LastIndexOf(":"); if (pos != -1) { channelName = channelName.Substring(0, pos); } channelName = channelName.TrimEnd(new char[] { '\'', '\"', '´', '`' }); channelName = channelName.Trim(); if (channelName != "") { channel.Name = ""; for (int x = 0; x < channelName.Length; ++x) { char k = channelName[x]; if (k < (char)32 || k > (char)127) { break; } channel.Name += k.ToString(); } } } finally { if (_scanner != null) { _scanner.SetCallBack(null); _scanner.Stop(); } if (_event != null) { _event.Close(); } } } List <IChannel> list = new List <IChannel>(); list.Add(channel); _card.IsScanning = false; return(list); } _card.IsScanning = false; return(null); }