Example #1
0
        private static bool getStations(TuningFrequency frequency)
        {
            bool tuned = tuneFrequency(frequency);
            if (!tuned)
                return (false);

            FrequencyScanner frequencyScanner = new FrequencyScanner(graph);
            Collection<TVStation> stations = frequencyScanner.FindTVStations(frequency);

            if (stations != null)
            {
                Logger.Instance.Write("Found " + stations.Count + " stations on frequency " + frequency);
                int addedCount = 0;

                foreach (TVStation tvStation in stations)
                {
                    TVStation excludedStation = TVStation.FindExcludedStation(tvStation.OriginalNetworkID, tvStation.TransportStreamID, tvStation.ServiceID);
                    if (excludedStation == null)
                    {
                        if (tvStation.NextFollowingAvailable && tvStation.ScheduleAvailable)
                        {
                            bool added = TVStation.AddStation(tvStation);
                            if (added)
                            {
                                //allStations.Add(tvStation);
                                addedCount++;
                                Logger.Instance.Write("Included station: " + tvStation.FixedLengthName + " (" + tvStation.FullID + " Service type " + tvStation.ServiceType + ")");
                            }
                        }
                        else
                            Logger.Instance.Write("Excluded station: " + tvStation.FixedLengthName + " (" + tvStation.FullID + " Service type " + tvStation.ServiceType + ") No EPG data");
                    }
                    else
                        Logger.Instance.Write("Excluded station: " + tvStation.FixedLengthName + " (" + tvStation.FullID + " Service type " + tvStation.ServiceType + ")");
                }

                Logger.Instance.Write("Added " + addedCount + " stations for frequency " + frequency);
            }
            frequencyScanner = null;
            return (true);
        }
        private void getData(ISampleDataProvider dataProvider, AnalysisParameters analysisParameters, BackgroundWorker worker)
        {
            Logger.Instance.Write("Starting analysis");

            analysisParameters.ScanningFrequency.CollectionType = CollectionType.MHEG5;
            FrequencyScanner frequencyScanner = new FrequencyScanner(dataProvider, worker);
            Collection<TVStation> stations = frequencyScanner.FindTVStations();

            pidList = new Collection<PidSpec>();

            dataProvider.ChangePidMapping(new int[] { -1 });

            IntPtr memoryPointer = dataProvider.BufferAddress;
            int currentOffset = 0;

            byte[] buffer = new byte[188];
            DateTime startTime = DateTime.Now;
            int packetCount = 0;
            int errorPackets = 0;
            int nullPackets = 0;

            while ((DateTime.Now - startTime).TotalSeconds < analysisParameters.DataCollectionTimeout && !worker.CancellationPending)
            {
                if (currentOffset >= dataProvider.BufferSpaceUsed)
                {
                    Thread.Sleep(2000);
                    if (currentOffset >= dataProvider.BufferSpaceUsed)
                    {
                        Logger.Instance.Write("Analysis resetting pid after " + packetCount + " packets (errors = " + errorPackets + " null = " + nullPackets + ")");
                        dataProvider.ChangePidMapping(new int[] { -1 });
                        currentOffset = 0;
                    }
                }
                else
                {
                    IntPtr currentPointer = new IntPtr(memoryPointer.ToInt64() + currentOffset + 136);
                    Marshal.Copy(currentPointer, buffer, 0, 188);
                    packetCount++;

                    /*if (dumpCount < 10000)
                    {
                        Logger.Instance.Dump("atsc " + dumpCount, buffer, buffer.Length);
                        dumpCount++;
                    }*/

                    TransportPacket transportPacket = new TransportPacket();

                    try
                    {
                        transportPacket.Process(buffer);

                        if (transportPacket.ErrorIndicator)
                            errorPackets++;
                        if (transportPacket.IsNullPacket)
                            nullPackets++;

                        if (!transportPacket.ErrorIndicator)
                        {
                            bool ignorePid = checkPid(transportPacket.PID, stations);
                            if (!ignorePid)
                            {
                                PidSpec pidSpec = findPidSpec(pidList, transportPacket.PID);
                                if (pidSpec == null)
                                {
                                    pidSpec = new PidSpec(transportPacket.PID);
                                    addPid(pidList, new PidSpec(transportPacket.PID));
                                }
                                pidSpec.ProcessPacket(buffer, transportPacket);
                            }
                        }
                        else
                            Logger.Instance.Write("Transport packet error in packet " + packetCount);

                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        Logger.Instance.Write("Failed to parse packet " + packetCount);
                    }

                    currentOffset += buffer.Length;
                }
            }

            Logger.Instance.Write("Analysis completed: " + pidList.Count + " PID's loaded from " + packetCount + " packets");
        }
Example #3
0
        /// <summary>
        /// Get the stations using specified pid's.
        /// </summary>
        /// <param name="dataProvider">The sample data provider.</param>
        /// <param name="worker">The BackgroundWorker instance running the collection.</param>
        /// <param name="pids">An array of pid's to search.</param>
        protected void GetStationData(ISampleDataProvider dataProvider, BackgroundWorker worker, int[] pids)
        {
            Collection<TVStation> stations;

            if (!RunParameters.Instance.Options.Contains("USESTOREDSTATIONINFO"))
            {
                FrequencyScanner frequencyScanner = new FrequencyScanner(dataProvider, pids, true, worker);
                frequencyScanner.UseActualFrequency = false;
                stations = frequencyScanner.FindTVStations();
                if (worker.CancellationPending)
                    return;
            }
            else
            {
                if (!stationCacheLoaded)
                {
                    stations = TVStation.Load(Path.Combine(RunParameters.DataDirectory, "Station Cache.xml"));
                    if (stations == null)
                        return;

                    setMHEG5Pid(dataProvider, stations);
                    stationCacheLoaded = true;
                }
                else
                {
                    setMHEG5Pid(dataProvider, TVStation.StationCollection);
                    return;
                }
            }

            foreach (TVStation tvStation in stations)
            {
                bool include = checkChannelFilters(tvStation);

                if (include)
                {
                    TVStation existingStation = TVStation.FindStation(tvStation.OriginalNetworkID, tvStation.TransportStreamID, tvStation.ServiceID);
                    if (existingStation == null)
                    {
                        tvStation.CollectionType = dataProvider.Frequency.CollectionType;
                        bool added = TVStation.AddStation(tvStation);
                        if (added)
                            Logger.Instance.Write("Included station: " + getStationDescription(tvStation));
                    }
                    else
                    {
                        if (!existingStation.Excluded)
                        {
                            existingStation.Update(tvStation);
                            Logger.Instance.Write("Included station: " + getStationDescription(tvStation));
                        }
                        else
                            Logger.Instance.Write("Excluded station: " + getStationDescription(tvStation));
                    }
                }
                else
                    Logger.Instance.Write("Excluded station: " + getStationDescription(tvStation));

            }

            Logger.Instance.Write("Station count now: " + TVStation.StationCollection.Count);
        }
Example #4
0
        /// <summary>
        /// Get the stations using specified pid's.
        /// </summary>
        /// <param name="dataProvider">The sample data provider.</param>
        /// <param name="worker">The BackgroundWorker instance running the collection.</param>
        /// <param name="pids">An array of pid's to search.</param>
        protected void GetStationData(ISampleDataProvider dataProvider, BackgroundWorker worker, int[] pids)
        {
            Collection <TVStation> stations;

            if (!RunParameters.Instance.Options.Contains("USESTOREDSTATIONINFO"))
            {
                FrequencyScanner frequencyScanner = new FrequencyScanner(dataProvider, pids, true, worker);
                frequencyScanner.UseActualFrequency = false;
                stations = frequencyScanner.FindTVStations();
                if (worker.CancellationPending)
                {
                    return;
                }
            }
            else
            {
                if (!stationCacheLoaded)
                {
                    stations = TVStation.Load(Path.Combine(RunParameters.DataDirectory, "Station Cache.xml"));
                    if (stations == null)
                    {
                        return;
                    }

                    setMHEG5Pid(dataProvider, stations);
                    stationCacheLoaded = true;
                }
                else
                {
                    setMHEG5Pid(dataProvider, TVStation.StationCollection);
                    return;
                }
            }

            foreach (TVStation tvStation in stations)
            {
                bool include = checkChannelFilters(tvStation);

                if (include)
                {
                    TVStation existingStation = TVStation.FindStation(tvStation.OriginalNetworkID, tvStation.TransportStreamID, tvStation.ServiceID);
                    if (existingStation == null)
                    {
                        tvStation.CollectionType = dataProvider.Frequency.CollectionType;
                        bool added = TVStation.AddStation(tvStation);
                        if (added)
                        {
                            Logger.Instance.Write("Included station: " + getStationDescription(tvStation));
                        }
                    }
                    else
                    {
                        if (!existingStation.Excluded)
                        {
                            existingStation.Update(tvStation);
                            Logger.Instance.Write("Included station: " + getStationDescription(tvStation));
                        }
                        else
                        {
                            Logger.Instance.Write("Excluded station: " + getStationDescription(tvStation));
                        }
                    }
                }
                else
                {
                    Logger.Instance.Write("Excluded station: " + getStationDescription(tvStation));
                }
            }

            Logger.Instance.Write("Station count now: " + TVStation.StationCollection.Count);
        }