protected void RtpPacketReceived(object sender, RtpListener.RtpPacketReceivedArgs e) { if ((e.Packet.HasPayload) && (e.Packet.PayloadType == 33)) { if (((e.Packet.Payload.Length - 12) % 188) == 0) { double num9 = (((double)(e.Packet.Payload.Length - 12)) / 188.0) - 1.0; for (double j = 0.0; j <= num9; j++) { byte[] tspacketbytes = (byte[])Array.CreateInstance(typeof(byte), 188); Array.Copy(e.Packet.Payload, (int)Math.Round((double)(12.0 + (j * 188))), tspacketbytes, 0, 188); TsHeader header = TsHeader.Decode(tspacketbytes); if (header.Pid == 0) { } //pat.OnTsPacket(destinationarray); //if (pat.IsReady) //{ // retval = true; //} } } OnTsPacketRecieved(new TsPacketArgs(e.Packet.Payload)); } }
public static TsHeader Decode(byte[] buffer) { var header = new TsHeader(); header.SyncByte = buffer[0]; if (header.SyncByte != 0x47) { header.TransportErrorIndicator = true; } header.TransportErrorIndicator = ((buffer[1] & 0x80) == 0x80); if (!header.TransportErrorIndicator) { header.PayloadUnitStartIndicator = ((buffer[1] & 0x40) == 0x40); header.TransportPriority = ((buffer[1] & 0x20) == 0x20); header.Pid = (((buffer[1] & 0x1F) << 8) + buffer[2]); header.TransportScramblingControl = (byte)(buffer[3] & 0xC0); header.AdaptionFieldControl = (byte)((buffer[3] >> 4) & 0x3); header.HasAdaptionField = (buffer[3] & 0x20) == 0x20; header.HasPayload = (buffer[3] & 0x10) == 0x10; header.ContinuityCounter = (byte)(buffer[3] & 0x0F); header.AdaptionFieldLength = 0; header.PayLoadStart = 4; if (header.HasAdaptionField) { header.AdaptionFieldLength = buffer[4]; header.PayLoadStart = (byte)(5 + header.AdaptionFieldLength); } return(header); } return(null); }
public virtual void OnTsPacket(byte[] tsPacket) { TsHeader header = TsHeader.Decode(tsPacket); if (((_pid < 0x1fff) && (header.Pid == _pid)) && header.HasPayload) { int payLoadStart = header.PayLoadStart; int num2 = 0; if (header.PayloadUnitStartIndicator) { num2 = (payLoadStart + tsPacket[payLoadStart]) + 1; if (_section.BufferPos == 0) { payLoadStart += tsPacket[payLoadStart] + 1; } else { payLoadStart++; } } while (payLoadStart < 0xbc) { if (_section.BufferPos == 0) { if (!header.PayloadUnitStartIndicator) { return; } if (tsPacket[payLoadStart] == 0xff) { return; } int sectionLen = this.SnapshotSectionLength(tsPacket, payLoadStart); payLoadStart = this.StartNewTsSection(tsPacket, payLoadStart, sectionLen); } else { if (_section.section_length == -1) { _section.CalcSectionLength(tsPacket, payLoadStart); } if (_section.section_length == 0) { _section.Reset(); return; } int num4 = _section.section_length - _section.BufferPos; if ((num2 != 0) && ((payLoadStart + num4) > num2)) { num4 = num2 - payLoadStart; payLoadStart = this.AddToSection(tsPacket, payLoadStart, num4); _section.section_length = _section.BufferPos - 1; payLoadStart = num2; incompleteSections++; } else { payLoadStart = this.AddToSection(tsPacket, payLoadStart, num4); } } if (_section.SectionComplete() && (_section.section_length > 0)) { this.OnNewSection(_section); if (this.OnSectionDecoded != null) { this.OnSectionDecoded(_section); } _section.Reset(); } num2 = 0; } } }
public virtual void OnTsPacket(byte[] tsPacket) { TsHeader header = TsHeader.Decode(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.PayloadUnitStartIndicator) { 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.PayloadUnitStartIndicator) { 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; } }