Exemplo n.º 1
0
        private void addPid(Collection <PidSpec> pidList, PidSpec newPID)
        {
            foreach (PidSpec oldPID in pidList)
            {
                if (oldPID.Pid == newPID.Pid)
                {
                    return;
                }

                if (oldPID.Pid > newPID.Pid)
                {
                    pidList.Insert(pidList.IndexOf(oldPID), newPID);
                    return;
                }
            }

            pidList.Add(newPID);
        }
Exemplo n.º 2
0
        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");
        }