Exemple #1
0
        private void doAnalysis(object sender, DoWorkEventArgs e)
        {
            AnalysisParameters analysisParameters = e.Argument as AnalysisParameters;

            pidList = null;

            TunerNodeType tunerNodeType;
            TuningSpec    tuningSpec;

            SatelliteFrequency satelliteFrequency = analysisParameters.ScanningFrequency as SatelliteFrequency;

            if (satelliteFrequency != null)
            {
                tunerNodeType = TunerNodeType.Satellite;
                tuningSpec    = new TuningSpec((Satellite)satelliteFrequency.Provider, satelliteFrequency);
            }
            else
            {
                TerrestrialFrequency terrestrialFrequency = analysisParameters.ScanningFrequency as TerrestrialFrequency;
                if (terrestrialFrequency != null)
                {
                    tunerNodeType = TunerNodeType.Terrestrial;
                    tuningSpec    = new TuningSpec(terrestrialFrequency);
                }
                else
                {
                    CableFrequency cableFrequency = analysisParameters.ScanningFrequency as CableFrequency;
                    if (cableFrequency != null)
                    {
                        tunerNodeType = TunerNodeType.Cable;
                        tuningSpec    = new TuningSpec(cableFrequency);
                    }
                    else
                    {
                        AtscFrequency atscFrequency = analysisParameters.ScanningFrequency as AtscFrequency;
                        if (atscFrequency != null)
                        {
                            if (atscFrequency.TunerType == TunerType.ATSC)
                            {
                                tunerNodeType = TunerNodeType.ATSC;
                            }
                            else
                            {
                                tunerNodeType = TunerNodeType.Cable;
                            }
                            tuningSpec = new TuningSpec(atscFrequency);
                        }
                        else
                        {
                            ClearQamFrequency clearQamFrequency = analysisParameters.ScanningFrequency as ClearQamFrequency;
                            if (clearQamFrequency != null)
                            {
                                tunerNodeType = TunerNodeType.Cable;
                                tuningSpec    = new TuningSpec(clearQamFrequency);
                            }
                            else
                            {
                                ISDBSatelliteFrequency isdbSatelliteFrequency = analysisParameters.ScanningFrequency as ISDBSatelliteFrequency;
                                if (isdbSatelliteFrequency != null)
                                {
                                    tunerNodeType = TunerNodeType.ISDBS;
                                    tuningSpec    = new TuningSpec((Satellite)satelliteFrequency.Provider, isdbSatelliteFrequency);
                                }
                                else
                                {
                                    ISDBTerrestrialFrequency isdbTerrestrialFrequency = analysisParameters.ScanningFrequency as ISDBTerrestrialFrequency;
                                    if (isdbTerrestrialFrequency != null)
                                    {
                                        tunerNodeType = TunerNodeType.ISDBT;
                                        tuningSpec    = new TuningSpec(isdbTerrestrialFrequency);
                                    }
                                    else
                                    {
                                        throw (new InvalidOperationException("Tuning frequency not recognized"));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            Tuner currentTuner = null;
            bool  finished     = false;

            while (!finished)
            {
                if ((sender as BackgroundWorker).CancellationPending)
                {
                    Logger.Instance.Write("Scan abandoned by user");
                    e.Cancel = true;
                    resetEvent.Set();
                    return;
                }

                BDAGraph graph = BDAGraph.FindTuner(analysisParameters.Tuners, tunerNodeType, tuningSpec, currentTuner, analysisParameters.RepeatDiseqc, analysisParameters.SwitchAfterPlay);
                if (graph == null)
                {
                    Logger.Instance.Write("<e> No tuner able to tune frequency " + analysisParameters.ScanningFrequency.ToString());

                    frequencySelectionControl.Invoke(new ShowMessage(showMessage), "No tuner able to tune frequency " + analysisParameters.ScanningFrequency.ToString(),
                                                     MessageBoxButtons.OK, MessageBoxIcon.Error);
                    finished = true;
                }
                else
                {
                    string tuneReply = checkTuning(graph, analysisParameters, sender as BackgroundWorker);

                    if ((sender as BackgroundWorker).CancellationPending)
                    {
                        Logger.Instance.Write("Scan abandoned by user");
                        graph.Dispose();
                        e.Cancel = true;
                        resetEvent.Set();
                        return;
                    }

                    if (tuneReply == null)
                    {
                        try
                        {
                            if (analysisParameters.DumpFileName == null || analysisParameters.DumpFileName == string.Empty)
                            {
                                getData(graph, analysisParameters, sender as BackgroundWorker);
                            }
                            else
                            {
                                SimulationDataProvider dataProvider = new SimulationDataProvider(analysisParameters.DumpFileName, graph.Frequency);
                                string providerReply = dataProvider.Run();
                                if (providerReply != null)
                                {
                                    Logger.Instance.Write("<e> Simulation Data Provider failed");
                                    Logger.Instance.Write("<e> " + providerReply);
                                    frequencySelectionControl.Invoke(new ShowMessage(showMessage), "Simulation Data Provider failed." +
                                                                     Environment.NewLine + Environment.NewLine + providerReply,
                                                                     MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                                else
                                {
                                    getData(dataProvider, analysisParameters, sender as BackgroundWorker);
                                    dataProvider.Stop();
                                }
                            }
                        }
                        catch (IOException ex)
                        {
                            Logger.Instance.Write("<e> Failed to process dump file");
                            Logger.Instance.Write("<e> " + ex.Message);
                            frequencySelectionControl.Invoke(new ShowMessage(showMessage), "Failed to process dump file." +
                                                             Environment.NewLine + Environment.NewLine + ex.Message,
                                                             MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        graph.Dispose();
                        finished = true;
                    }
                    else
                    {
                        Logger.Instance.Write("Failed to tune frequency " + analysisParameters.ScanningFrequency.ToString());
                        graph.Dispose();
                        currentTuner = graph.Tuner;
                    }
                }
            }

            e.Cancel = true;
            resetEvent.Set();
        }
        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);
        }
Exemple #3
0
        public void Run()
        {
            SatelliteDatabase satelliteDatabase = new SatelliteDatabase();

            satelliteDatabase.Load();

            TVDatabase tvDatabase = new TVDatabase();

            tvDatabase.Load();

            epgDatabase = new EPGDatabase();
            epgDatabase.Load();

            Collection <TuningSpec> tuningCollection = new Collection <TuningSpec>();

            foreach (TVStation tvStation in tvDatabase.StationCollection)
            {
                TuningSpec tuningSpec = findTuningSpec(tuningCollection, tvStation);
                if (tuningSpec == null)
                {
                    TuningSpec newTuningSpec = new TuningSpec();
                    newTuningSpec.Satellite         = tvStation.Satellite;
                    newTuningSpec.OriginalNetworkID = tvStation.OriginalNetworkID;
                    newTuningSpec.TransportStreamID = tvStation.TransportStreamID;
                    newTuningSpec.Frequency         = tvStation.Frequency;
                    newTuningSpec.SymbolRate        = tvStation.SymbolRate;
                    newTuningSpec.Tag = new EPGGraph(satelliteDatabase[tvStation.Satellite], newTuningSpec);
                    tuningCollection.Add(newTuningSpec);
                }
            }

            bool     end            = false;
            DateTime lastUpdateTime = DateTime.Now;
            TimeSpan interval       = new TimeSpan(0, 1, 0);

            while (!end)
            {
                foreach (TuningSpec tuningSpec in tuningCollection)
                {
                    EPGGraph currentGraph = tuningSpec.Tag as EPGGraph;
                    currentGraph.Play();

                    EITController eitController = new EITController();

                    while (!eitController.Finished && !end)
                    {
                        Collection <EITEntry> eitCollection = eitController.ProcessEITSections(currentGraph);
                        updateSchedule(eitCollection);

                        if (lastUpdateTime + interval < DateTime.Now)
                        {
                            epgDatabase.UpdateDatabase();
                            lastUpdateTime = DateTime.Now;
                        }
                    }

                    currentGraph.Stop();
                }

                Thread.Sleep(2000);
            }
        }