Esempio n. 1
0
    private void AnalyzeTs()
    {
      if (!System.IO.File.Exists(tsFile))
      {
        MessageBox.Show("The ts file doesn't exists.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return;
      }
      PrBar.Value = 0;
      WriteLog("Analyzer running...");
      byte[] tsPacket;
      
      reader = new BufferedTsFileReader();
      if (!reader.Open(tsFile, 50000))
      {
        MessageBox.Show("Error opening the ts file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return;
      }
      if (!reader.SeekToFirstPacket())
      {
        MessageBox.Show("No snyc byte found in whole file. Doesn't seem to be a valid ts file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return;
      }
      TsHeader header;

      TreeNode patNode= new TreeNode("PAT");
      PatParser patParser = new PatParser(patNode);
      TreeNode catNode = new TreeNode("CAT");
      CatParser catParser = new CatParser(catNode);
      TreeNode linkageNode = new TreeNode("ChannelLinkage");
      ChannelLinkageParser linkageParser = new ChannelLinkageParser(linkageNode);
      TreeNode sdtNode = new TreeNode("SDT");
      SdtParser sdtParser = new SdtParser(sdtNode);
      TreeNode nitNode = new TreeNode("NIT");
      NITParser nitParser = new NITParser(nitNode);
      PacketChecker checker = new PacketChecker(double.Parse(edPcrDiff.Text));
      EitParser eitParser = new EitParser(this);

      int maxPATPidsCount = 0;
       while (reader.GetNextPacket(out tsPacket, out header))
      {
        checker.ProcessPacket(tsPacket, header);
        if (header.TransportError) continue;
        if (header.Pid >= 0x1FFF) continue;

        List<ushort> streamPids = patParser.GetPmtStreamPids();
        checker.AddPidsToCheck(streamPids);
        if (!patParser.IsReady)
          patParser.OnTsPacket(tsPacket);
        else
        {
          
          if (!(bool)patNode.Tag)
          {
            WriteLog("- PAT and PMT parsers finished.");
            AddThreadSafeSectionNode(patNode);
            patNode.Tag = true;
          }
          patParser.Reset();
          if (maxPATPidsCount != streamPids.Count)
          {
            if (maxPATPidsCount > 0)
              WriteLog("- [Warning] Got different number of pmts and pid than in prev. run. prev. max=" + maxPATPidsCount.ToString() + " current=" + streamPids.Count.ToString());
            if (maxPATPidsCount<streamPids.Count)
              maxPATPidsCount = streamPids.Count;
          }
        }
        if (!catParser.IsReady)
          catParser.OnTsPacket(tsPacket);
        else
        {
          if (!(bool)catNode.Tag)
          {
            WriteLog("- CAT parser finished.");
            AddThreadSafeSectionNode(catNode);
            catNode.Tag = true;
          }
        }
        nitParser.OnTsPacket(tsPacket);
        linkageParser.OnTsPacket(tsPacket);
        sdtParser.OnTsPacket(tsPacket);
        eitParser.OnTsPacket(tsPacket);
        PrBar.Value = reader.GetPositionInPercent();
        if (stopThread) break;
      }
      reader.Close();
      PrBar.Value = 100;
      WriteLog("Finished.");
      ThreadSafeSort();
      WriteLog("Incomplete sections=" + PatParser.incompleteSections.ToString());
      WriteLog("max PAT/PMT pid count: " + maxPATPidsCount.ToString());
      if (!(bool)patNode.Tag)
        AddThreadSafeSectionNode(patNode);
      nitNode.Text += " (" + nitParser.GetChannelCount().ToString() + " channels)";
      AddThreadSafeSectionNode(nitNode);
      sdtNode.Text = "SDT (" + sdtParser.GetServiceCount().ToString() + " services)";
      AddThreadSafeSectionNode(sdtNode);
      AddThreadSafeSectionNode(linkageNode);
      WriteLog(checker.GetStatistics());
      WriteLog(checker.GetErrorDetails());
    }
Esempio n. 2
0
        private void AnalyzeTs()
        {
            if (!System.IO.File.Exists(tsFile))
            {
                MessageBox.Show("The ts file doesn't exists.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            PrBar.Value = 0;
            WriteLog("Analyzer running...");
            byte[] tsPacket;

            reader = new BufferedTsFileReader();
            if (!reader.Open(tsFile, 50000))
            {
                MessageBox.Show("Error opening the ts file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!reader.SeekToFirstPacket())
            {
                MessageBox.Show("No snyc byte found in whole file. Doesn't seem to be a valid ts file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            TsHeader header;

            TreeNode             patNode       = new TreeNode("PAT");
            PatParser            patParser     = new PatParser(patNode);
            TreeNode             catNode       = new TreeNode("CAT");
            CatParser            catParser     = new CatParser(catNode);
            TreeNode             linkageNode   = new TreeNode("ChannelLinkage");
            ChannelLinkageParser linkageParser = new ChannelLinkageParser(linkageNode);
            TreeNode             sdtNode       = new TreeNode("SDT");
            SdtParser            sdtParser     = new SdtParser(sdtNode);
            TreeNode             nitNode       = new TreeNode("NIT");
            NITParser            nitParser     = new NITParser(nitNode);
            PacketChecker        checker       = new PacketChecker(double.Parse(edPcrDiff.Text));
            EitParser            eitParser     = new EitParser(this);

            int maxPATPidsCount = 0;

            while (reader.GetNextPacket(out tsPacket, out header))
            {
                checker.ProcessPacket(tsPacket, header);
                if (header.TransportError)
                {
                    continue;
                }
                if (header.Pid >= 0x1FFF)
                {
                    continue;
                }

                List <ushort> streamPids = patParser.GetPmtStreamPids();
                checker.AddPidsToCheck(streamPids);
                if (!patParser.IsReady)
                {
                    patParser.OnTsPacket(tsPacket);
                }
                else
                {
                    if (!(bool)patNode.Tag)
                    {
                        WriteLog("- PAT and PMT parsers finished.");
                        AddThreadSafeSectionNode(patNode);
                        patNode.Tag = true;
                    }
                    patParser.Reset();
                    if (maxPATPidsCount != streamPids.Count)
                    {
                        if (maxPATPidsCount > 0)
                        {
                            WriteLog("- [Warning] Got different number of pmts and pid than in prev. run. prev. max=" + maxPATPidsCount.ToString() + " current=" + streamPids.Count.ToString());
                        }
                        if (maxPATPidsCount < streamPids.Count)
                        {
                            maxPATPidsCount = streamPids.Count;
                        }
                    }
                }
                if (!catParser.IsReady)
                {
                    catParser.OnTsPacket(tsPacket);
                }
                else
                {
                    if (!(bool)catNode.Tag)
                    {
                        WriteLog("- CAT parser finished.");
                        AddThreadSafeSectionNode(catNode);
                        catNode.Tag = true;
                    }
                }
                nitParser.OnTsPacket(tsPacket);
                linkageParser.OnTsPacket(tsPacket);
                sdtParser.OnTsPacket(tsPacket);
                eitParser.OnTsPacket(tsPacket);
                PrBar.Value = reader.GetPositionInPercent();
                if (stopThread)
                {
                    break;
                }
            }
            reader.Close();
            PrBar.Value = 100;
            WriteLog("Finished.");
            ThreadSafeSort();
            WriteLog("Incomplete sections=" + PatParser.incompleteSections.ToString());
            WriteLog("max PAT/PMT pid count: " + maxPATPidsCount.ToString());
            if (!(bool)patNode.Tag)
            {
                AddThreadSafeSectionNode(patNode);
            }
            nitNode.Text += " (" + nitParser.GetChannelCount().ToString() + " channels)";
            AddThreadSafeSectionNode(nitNode);
            sdtNode.Text = "SDT (" + sdtParser.GetServiceCount().ToString() + " services)";
            AddThreadSafeSectionNode(sdtNode);
            AddThreadSafeSectionNode(linkageNode);
            WriteLog(checker.GetStatistics());
            WriteLog(checker.GetErrorDetails());
        }