private static bool tuneFrequency(TuningFrequency frequency) { Logger.Instance.Write("Tuning to frequency " + frequency.Frequency + " on " + frequency.TunerType); TuningSpec tuningSpec; TunerNodeType tunerNodeType; int frequencyRetries = 0; if (frequency.TunerType == TunerType.Satellite) { tuningSpec = new TuningSpec(Satellite.CurrentSatellite, (SatelliteFrequency)frequency); tunerNodeType = TunerNodeType.Satellite; } else if (frequency.TunerType == TunerType.Terrestrial) { tuningSpec = new TuningSpec((TerrestrialFrequency)frequency); tunerNodeType = TunerNodeType.Terrestrial; } else { tuningSpec = new TuningSpec((CableFrequency)frequency); tunerNodeType = TunerNodeType.Cable; } bool finished = false; while (!finished) { graph = BDAGraph.FindTuner(RunParameters.SelectedTuner, tunerNodeType, tuningSpec); if (graph == null) { Logger.Instance.Write("Tuner not available"); return (false); } TimeSpan timeout = new TimeSpan(); bool done = false; bool locked = false; if (RunParameters.Options.Contains("NOSIGLOCK")) { Logger.Instance.Write("Option NOSIGLOCK: No lock check, wait 5 seconds instead"); locked = true; Thread.Sleep(5000); } else { while (!done) { if (cancelGraph) { graph.Dispose(); return (false); } locked = graph.SignalLocked; if (!locked) { int signalQuality = graph.SignalQuality; if (signalQuality > 0) { Logger.Instance.Write("Signal not locked but signal quality > 0"); locked = true; done = true; } else { Logger.Instance.Write("Signal not locked and signal quality not > 0"); Thread.Sleep(1000); timeout = timeout.Add(new TimeSpan(0, 0, 1)); done = (timeout.TotalSeconds == RunParameters.LockTimeout.TotalSeconds); } } else done = true; } } if (!locked) { Logger.Instance.Write("Failed to acquire signal"); graph.Dispose(); if (frequencyRetries == 1) return (false); else { frequencyRetries++; Logger.Instance.Write("Retrying frequency"); } } else { finished = true; Logger.Instance.Write("Signal acquired: lock is " + graph.SignalLocked + " quality is " + graph.SignalQuality + " strength is " + graph.SignalStrength); } } return (true); }
private void getData(BDAGraph graph, DumpParameters dumpParameters, BackgroundWorker worker) { Logger.Instance.Write(string.Format("Starting dump to {0}",dumpParameters.FileName)); int[] newPids; if (dumpParameters.PidList != null && dumpParameters.PidList.Count != 0) { newPids = new int[dumpParameters.PidList.Count]; for (int index = 0; index < dumpParameters.PidList.Count; index++) newPids[index] = dumpParameters.PidList[index]; } else { newPids = new int[1]; newPids[0] = -1; } graph.ChangePidMapping(newPids); DateTime startTime = DateTime.Now; int lastSize = 0; while (!worker.CancellationPending) { Thread.Sleep(100); int increment = 5; if (dumpParameters.PidList != null && dumpParameters.PidList.Count != 0) increment = 1; int buffer_space = graph.BufferSpaceUsed/(1024*1024); if (buffer_space > 40) { graph.clear_buffer(); } int size = graph.DumpFileSize / (1024 * 1024); if (size >= lastSize + increment) { Logger.Instance.Write("Record/Buffer sizes: (" + size + "/"+buffer_space+")"); worker.ReportProgress((int)size); lastSize = size; } } finalSize = graph.DumpFileSize; Logger.Instance.Write("Dump completed - file size now " + finalSize + " bytes"); }
private string checkTuning(BDAGraph graph, DumpParameters dumpParameters, BackgroundWorker worker) { TimeSpan timeout = new TimeSpan(); bool done = false; bool locked = false; int frequencyRetries = 0; while (!done) { if (worker.CancellationPending) { Logger.Instance.Write("Dump abandoned by user"); return (null); } locked = graph.SignalLocked; if (!locked) { int signalQuality = graph.SignalQuality; if (signalQuality > 0) { Logger.Instance.Write("Signal not locked but signal quality > 0"); locked = true; done = true; } else { if (!dumpParameters.UseSignalPresent) { Logger.Instance.Write("Signal not locked and signal quality not > 0"); Thread.Sleep(1000); timeout = timeout.Add(new TimeSpan(0, 0, 1)); done = (timeout.TotalSeconds == dumpParameters.SignalLockTimeout); } else { bool signalPresent = graph.SignalPresent; if (signalPresent) { Logger.Instance.Write("Signal present"); locked = true; done = true; } else { Logger.Instance.Write("Signal not present"); Thread.Sleep(1000); timeout = timeout.Add(new TimeSpan(0, 0, 1)); done = (timeout.TotalSeconds == dumpParameters.SignalLockTimeout); } } if (done) { done = (frequencyRetries == 2); if (done) Logger.Instance.Write("<e> Failed to acquire signal"); else { Logger.Instance.Write("Retrying frequency"); timeout = new TimeSpan(); frequencyRetries++; } } } } else { Logger.Instance.Write("Signal acquired: lock is " + graph.SignalLocked + " quality is " + graph.SignalQuality + " strength is " + graph.SignalStrength); done = true; } } if (locked) return (null); else return ("<e> The tuner failed to acquire a signal for frequency " + dumpParameters.ScanningFrequency.ToString()); }
private static BDAGraph checkTunerAvailability(Tuner tuner, TuningSpec tuningSpec, bool repeatDiseqc, bool switchAfterPlay, string dumpFileName) { if (!RunParameters.Instance.DebugIDs.Contains("USEDVBLINK")) { if (tuner.Name.ToUpperInvariant().StartsWith("DVBLINK")) return (null); } BDAGraph graph = new BDAGraph("BDA", tuningSpec, tuner, dumpFileName); graph.LogFilters(); if (tuningSpec.Frequency.TunerType == TunerType.Satellite && ((SatelliteFrequency)tuningSpec.Frequency).SatelliteDish.DiseqcSwitch != null) return (checkDiseqcAvailability(graph, tuner, tuningSpec, repeatDiseqc, switchAfterPlay)); else { if (graph.Play()) return (graph); else { Logger.Instance.Write("Tuner in use - ignored: " + tuner.Name); graph.Dispose(); return (null); } } }
private static BDAGraph checkDiseqcAvailability(BDAGraph graph, Tuner tuner, TuningSpec tuningSpec, bool repeatDiseqc, bool switchAfterPlay) { if (RunParameters.Instance.Options.Contains("USESAFEDISEQC")) { Logger.Instance.Write("Processing using safe DiSEqC switching method"); if (!graph.Play()) { Logger.Instance.Write("Tuner in use - ignored: " + tuner.Name); graph.Dispose(); return (null); } graph.Dispose(); graph = new BDAGraph("BDA", tuningSpec, tuner); } else Logger.Instance.Write("Processing using unsafe DiSEqC switching method"); SwitchReply switchReply = SwitchReply.NotSet; if (!switchAfterPlay) { Logger.Instance.Write("Processing Diseqc command before running graph"); switchReply = DiseqcHandlerBase.ProcessDisEqcSwitch(tuningSpec, tuner, graph.tunerFilter); Thread.Sleep(500); } if (!graph.Play()) { Logger.Instance.Write("Tuner in use - ignored: " + tuner.Name); graph.Dispose(); return (null); } if (switchReply == SwitchReply.Failed && repeatDiseqc) { Logger.Instance.Write("Repeating DiSEqC command due to initial failure"); switchReply = DiseqcHandlerBase.ProcessDisEqcSwitch(tuningSpec, tuner, graph.tunerFilter); } else { if (switchAfterPlay) { Logger.Instance.Write("Processing Diseqc command after running graph"); switchReply = DiseqcHandlerBase.ProcessDisEqcSwitch(tuningSpec, tuner, graph.tunerFilter); } } return (graph); }
/// <summary> /// Initialize a new instance of the BDAGraph1 class for dumping a transport stream. /// </summary> /// <param name="componentName">The name of the current component.</param> /// <param name="tuningSpec">A tuning spec instance with details of the tuning requirements.</param> /// <param name="tunerSpec">A tuner spec instance specifying the tuner to be used.</param> /// <param name="dumpFileName">The name of the dump file.</param> public BDAGraph(string componentName, TuningSpec tuningSpec, Tuner tunerSpec, string dumpFileName) : base(componentName) { currentGraph = this; this.tuningSpec = tuningSpec; this.tunerSpec = tunerSpec; createTuningSpace(tuningSpec); createTuneRequest(tuningSpace, tuningSpec); this.dumpFileName = dumpFileName; buildGraph(tuningSpace, tunerSpec, tuningSpec); }