예제 #1
0
        private void CheckPtsDts(TsHeader header, byte[] tsPacket, ref PidInfo pi)
        {
            if (!pi.shouldCheck)
            {
                return;
            }
            ulong offset = PacketContainsPtsDts(header, tsPacket, ref pi);

            if (offset == 0)
            {
                return;
            }
            Pcr pts; Pcr dts;

            PcrUtils.DecodePtsDts(tsPacket, offset, out pts, out dts);
            if (pi.lastPts.isValid)
            {
                TimeSpan diff = pts.ToDateTime() - pi.lastPts.ToDateTime();
                if (diff.TotalSeconds > diffAllowed)
                {
                    pi.ptsErrorTexts.Add("last pts: " + pi.lastPts.ToDateTime().ToString("HH:MM:ss") + " current pts: " + pts.ToDateTime().ToString("HH:MM:ss"));
                    totalPtsErrors++;
                }
            }
            pi.lastPts = pts;
        }
예제 #2
0
 public bool GetNextPacket(out byte[] tsPacket, out TsHeader header)
 {
   header = new TsHeader();
   tsPacket = new byte[TS_PACKET_SIZE];
   if (_reader.Read(tsPacket, 0, TS_PACKET_SIZE) != TS_PACKET_SIZE)
     return false;
   //check for sync byte and transport error bit
   header = new TsHeader(tsPacket);
   return true;
 }
 public bool GetNextPacket(out byte[] tsPacket, out TsHeader header)
 {
     header   = new TsHeader();
     tsPacket = new byte[TS_PACKET_SIZE];
     if (_reader.Read(tsPacket, 0, TS_PACKET_SIZE) != TS_PACKET_SIZE)
     {
         return(false);
     }
     //check for sync byte and transport error bit
     header = new TsHeader(tsPacket);
     return(true);
 }
예제 #4
0
 private ulong PacketContainsPtsDts(TsHeader header, byte[] tsPacket, ref PidInfo pi)
 {
   if (!header.PayloadUnitStart)
     return 0;
   if (header.PayLoadStart > 185 && header.HasPayload)
   {
     totalPayloadStartErrors++;
     pi.payloadStartErrorTexts.Add(" payloadStart=" + header.PayLoadStart.ToString() + " HasAdaption=" + header.HasAdaptionField.ToString() + " HasPayload=" + header.HasPayload.ToString() + " AdaptionFieldSize=" + tsPacket[4].ToString());
     return 0;
   }
   if (!header.HasPayload)
     return 0;
   return header.PayLoadStart;
 }
예제 #5
0
 private void CheckPcr(TsHeader header, byte[] tsPacket, ref PidInfo pi)
 {
   if (!pi.shouldCheck) return;
   if (!PacketContainsPcr(header, tsPacket)) return;
   Pcr pcr = new Pcr(tsPacket);
   if (pi.lastPcr.isValid)
   {
     TimeSpan diff = pcr.ToDateTime() - pi.lastPcr.ToDateTime();
     if (diff.TotalSeconds > diffAllowed)
     {
       pi.pcrErrorTexts.Add("last pcr: " + pi.lastPcr.ToDateTime().ToString("HH:MM:ss") + " current pcr: " + pcr.ToDateTime().ToString("HH:MM:ss"));
       totalPcrErrors++;
     }
   }
   pi.lastPcr = pcr;
 }
예제 #6
0
 private void CheckPtsDts(TsHeader header, byte[] tsPacket, ref PidInfo pi)
 {
   if (!pi.shouldCheck) return;
   ulong offset = PacketContainsPtsDts(header, tsPacket, ref pi);
   if (offset == 0) return;
   Pcr pts; Pcr dts;
   PcrUtils.DecodePtsDts(tsPacket, offset, out pts, out dts);
   if (pi.lastPts.isValid)
   {
     TimeSpan diff = pts.ToDateTime() - pi.lastPts.ToDateTime();
     if (diff.TotalSeconds > diffAllowed)
     {
       pi.ptsErrorTexts.Add("last pts: " + pi.lastPts.ToDateTime().ToString("HH:MM:ss") + " current pts: " + pts.ToDateTime().ToString("HH:MM:ss"));
       totalPtsErrors++;
     }
   }
   pi.lastPts = pts;
 }
예제 #7
0
 private ulong PacketContainsPtsDts(TsHeader header, byte[] tsPacket, ref PidInfo pi)
 {
     if (!header.PayloadUnitStart)
     {
         return(0);
     }
     if (header.PayLoadStart > 185 && header.HasPayload)
     {
         totalPayloadStartErrors++;
         pi.payloadStartErrorTexts.Add(" payloadStart=" + header.PayLoadStart.ToString() + " HasAdaption=" + header.HasAdaptionField.ToString() + " HasPayload=" + header.HasPayload.ToString() + " AdaptionFieldSize=" + tsPacket[4].ToString());
         return(0);
     }
     if (!header.HasPayload)
     {
         return(0);
     }
     return(header.PayLoadStart);
 }
예제 #8
0
        public void ProcessPacket(byte[] tsPacket, TsHeader header)
        {
            if (header.TransportError)
            {
                droppedPackets++;
                return;
            }
            if (!pids.ContainsKey(header.Pid))
            {
                pids.Add(header.Pid, new PidInfo());
            }

            PidInfo pi = pids[header.Pid];

            CheckContinuityCounter((byte)(tsPacket[3] & 0xF), ref pi);
            if (header.Pid > 0x1f) // don't check pids which contain SI information
            {
                CheckPcr(header, tsPacket, ref pi);
                CheckPtsDts(header, tsPacket, ref pi);
            }
            pids[header.Pid] = pi;
        }
예제 #9
0
        private void CheckPcr(TsHeader header, byte[] tsPacket, ref PidInfo pi)
        {
            if (!pi.shouldCheck)
            {
                return;
            }
            if (!PacketContainsPcr(header, tsPacket))
            {
                return;
            }
            Pcr pcr = new Pcr(tsPacket);

            if (pi.lastPcr.isValid)
            {
                TimeSpan diff = pcr.ToDateTime() - pi.lastPcr.ToDateTime();
                if (diff.TotalSeconds > diffAllowed)
                {
                    pi.pcrErrorTexts.Add("last pcr: " + pi.lastPcr.ToDateTime().ToString("HH:MM:ss") + " current pcr: " + pcr.ToDateTime().ToString("HH:MM:ss"));
                    totalPcrErrors++;
                }
            }
            pi.lastPcr = pcr;
        }
        public virtual void OnTsPacket(byte[] tsPacket)
        {
            TsHeader header = new TsHeader(tsPacket);

            if (m_pid >= 0x1fff)
            {
                return;
            }
            if (header.Pid != m_pid)
            {
                return;
            }
            if (!header.HasPayload)
            {
                return;
            }

            int start = header.PayLoadStart;

            int pointer_field = 0;

            if (header.PayloadUnitStart)
            {
                pointer_field = start + tsPacket[start] + 1;
                if (m_section.BufferPos == 0)
                {
                    start += tsPacket[start] + 1;
                }
                else
                {
                    start++;
                }
            }
            while (start < 188)
            {
                if (m_section.BufferPos == 0)
                {
                    if (!header.PayloadUnitStart)
                    {
                        return;
                    }
                    if (tsPacket[start] == 0xFF)
                    {
                        return;
                    }
                    int section_length = SnapshotSectionLength(tsPacket, start);
                    start = StartNewSection(tsPacket, start, section_length);
                }
                else
                {
                    if (m_section.section_length == -1)
                    {
                        m_section.CalcSectionLength(tsPacket, start);
                    }
                    if (m_section.section_length == 0)
                    {
                        m_section.Reset();
                        return;
                    }
                    int len = m_section.section_length - m_section.BufferPos;
                    if (pointer_field != 0 && ((start + len) > pointer_field))
                    {
                        len   = pointer_field - start;
                        start = AddToSection(tsPacket, start, len);
                        m_section.section_length = m_section.BufferPos - 1;
                        start = pointer_field;
                        incompleteSections++;
                    }
                    else
                    {
                        start = AddToSection(tsPacket, start, len);
                    }
                }
                if (m_section.SectionComplete() && m_section.section_length > 0)
                {
                    OnNewSection(m_section);
                    if (OnSectionDecoded != null)
                    {
                        OnSectionDecoded(m_section);
                    }
                    m_section.Reset();
                }
                pointer_field = 0;
            }
        }
예제 #11
0
 private bool PacketContainsPcr(TsHeader header, byte[] tsPacket)
 {
   return (header.HasAdaptionField && (tsPacket[5] & 0x10) == 0x10);
 }
예제 #12
0
    public void ProcessPacket(byte[] tsPacket,TsHeader header)
    {
      if (header.TransportError)
      {
        droppedPackets++;
        return;
      }
      if (!pids.ContainsKey(header.Pid))
        pids.Add(header.Pid, new PidInfo());

      PidInfo pi = pids[header.Pid];
      CheckContinuityCounter((byte)(tsPacket[3] & 0xF), ref pi);
      if (header.Pid > 0x1f) // don't check pids which contain SI information
      {
        CheckPcr(header, tsPacket, ref pi);
        CheckPtsDts(header, tsPacket, ref pi);
      }
      pids[header.Pid] = pi;
    }
예제 #13
0
    public virtual void OnTsPacket(byte[] tsPacket)
    {
      TsHeader header = new TsHeader(tsPacket);
      if (m_pid >= 0x1fff) return;
      if (header.Pid != m_pid) return;
      if (!header.HasPayload) return;

      int start = header.PayLoadStart;

      int pointer_field = 0;

      if (header.PayloadUnitStart)
      {
        pointer_field = start + tsPacket[start]+1;
        if (m_section.BufferPos == 0)
          start += tsPacket[start] + 1;
        else
          start++;
      }
      while (start < 188)
      {
        if (m_section.BufferPos == 0)
        {
          if (!header.PayloadUnitStart) return;
          if (tsPacket[start] == 0xFF) return;
          int section_length = SnapshotSectionLength(tsPacket, start);
          start = StartNewSection(tsPacket, start, section_length);
        }
        else
        {
          if (m_section.section_length == -1)
            m_section.CalcSectionLength(tsPacket, start);
          if (m_section.section_length == 0)
          {
            m_section.Reset();
            return;
          }
          int len = m_section.section_length - m_section.BufferPos;
          if (pointer_field != 0 && ((start + len) > pointer_field))
          {
            len = pointer_field - start;
            start = AddToSection(tsPacket, start, len);
            m_section.section_length = m_section.BufferPos - 1;
            start = pointer_field;
            incompleteSections++;
          }
          else
            start = AddToSection(tsPacket, start, len);
        }
        if (m_section.SectionComplete() && m_section.section_length > 0)
        {
          OnNewSection(m_section);
          if (OnSectionDecoded != null)
            OnSectionDecoded(m_section);
          m_section.Reset();
        }
        pointer_field=0;
      }
    }
예제 #14
0
 private bool PacketContainsPcr(TsHeader header, byte[] tsPacket)
 {
     return(header.HasAdaptionField && (tsPacket[5] & 0x10) == 0x10);
 }