protected override void ParseSection(TsPacket packet, int offset, int length) { if (length < 5) { return; } int num1 = offset; byte[] buffer = packet.Buffer; int num2 = num1 + length; int num3 = num1 + 2; byte[] numArray1 = buffer; int index1 = num3; int num4 = 1; int num5 = index1 + num4; byte num6 = numArray1[index1]; int num7 = (int)num6 & 1; byte num8 = (byte)((int)num6 >> 1 & 31); byte[] numArray2 = buffer; int index2 = num5; int num9 = 1; int num10 = index2 + num9; byte num11 = numArray2[index2]; byte[] numArray3 = buffer; int index3 = num10; int num12 = 1; int offset1 = index3 + num12; byte num13 = numArray3[index3]; TsDescriptors.Parse(this._descriptorFactory, buffer, offset1, num2 - offset1); }
public void Add(TsPacket packet) { if (packet.IsStart) _index = 0; else { // Ignore duplicates and other nonsense var nextCount = (_count + 1) & 0x0f; if (packet.ContinuityCount != nextCount) return; } _count = packet.ContinuityCount; var length = packet.PayloadLength; if (_index + length <= _buffer.Length) { packet.CopyTo(_buffer, _index); _index += length; if (null != _handler) _handler(this); } }
public void Add(TsPacket packet) { if (packet.IsStart) { this._index = 0; } else { int num = this._count + 1 & 15; if (packet.ContinuityCount != num) { return; } } this._count = packet.ContinuityCount; int payloadLength = packet.PayloadLength; if (this._index + payloadLength > this._buffer.Length) { return; } packet.CopyTo(this._buffer, this._index); this._index += payloadLength; if (null != this._handler) { this._handler(this); } }
private void AddPcr(TsPacket packet) { if (packet == null || !packet.Pcr.HasValue) { return; } this._pcrIndex = new int?(packet.TsIndex); this._pcr = packet.Pcr; }
public void Add(TsPacket packet) { if (null == _handler) return; // Don't bother parsing if we can't do anything with the results. if (null != packet) { if (packet.IsStart) { if (0 == _length && _index > _startIndex) Flush(); _index = _startIndex; ParseHeader(packet); } if (null != _bufferEntry) { if (_index + packet.BufferLength > _bufferEntry.Buffer.Length) { var requiredLength = _index - _startIndex + packet.BufferLength; var newLength = Math.Max(requiredLength, 512); if (_index < _bufferEntry.Buffer.Length / 2) newLength *= 2; var newBuffer = _bufferPool.Allocate(newLength); Array.Copy(_bufferEntry.Buffer, _startIndex, newBuffer.Buffer, 0, _index - _startIndex); _bufferPool.Free(_bufferEntry); _bufferEntry = newBuffer; _index -= _startIndex; _startIndex = 0; } packet.CopyTo(_bufferEntry.Buffer, _index); _index += packet.BufferLength; } } if (null == packet || _length > 0 && _index - _startIndex == _length) Flush(); if (null == packet && null != _bufferEntry) { _bufferPool.Free(_bufferEntry); _bufferEntry = null; } if (null == packet && null != _handler) _handler(null); // Propagate end-of-stream }
internal void Add(TsPacket packet) { if (null == packet) // Ignore end-of-stream return; var i0 = packet.BufferOffset; var i = i0; var buffer = packet.Buffer; var length = packet.BufferLength; if (length < MinimumPsiSize) return; var pointer = buffer[i++]; i += pointer; if (i + MinimumPsiSize >= i0 + length) return; var tableIdOffset = i; var table_id = buffer[i++]; if (_tableId != table_id) return; var section_length = (buffer[i] << 8) | buffer[i + 1]; i += 2; var section_syntax_indicator = 0 != (section_length & (1 << 15)); if (0 != (section_length & (1 << 14))) return; section_length &= 0x0fff; if (section_length > MaximumSectionLength) return; if (section_length + i - i0 > length) return; var checksumLength = section_length + i - tableIdOffset; var validChecksum = Crc32Msb.Validate(buffer, tableIdOffset, checksumLength); if (!validChecksum) return; var sectionIndex = i; var sectionLength = section_length - CrcSize; ParseSection(packet, sectionIndex, sectionLength); }
public void Add(TsPacket packet) { if (null == this._handler) { return; } if (null != packet) { if (packet.IsStart) { if ((int)this._length == 0 && this._index > this._startIndex) { this.Flush(); } this._index = this._startIndex; this.ParseHeader(packet); } if (null != this._bufferEntry) { if (this._index + packet.BufferLength > this._bufferEntry.Buffer.Length) { int minSize = Math.Max(this._index - this._startIndex + packet.BufferLength, 512); if (this._index < this._bufferEntry.Buffer.Length / 2) { minSize *= 2; } BufferInstance bufferInstance = this._bufferPool.Allocate(minSize); Array.Copy((Array)this._bufferEntry.Buffer, this._startIndex, (Array)bufferInstance.Buffer, 0, this._index - this._startIndex); this._bufferPool.Free(this._bufferEntry); this._bufferEntry = bufferInstance; this._index -= this._startIndex; this._startIndex = 0; } packet.CopyTo(this._bufferEntry.Buffer, this._index); this._index += packet.BufferLength; } } if (packet == null || this._length > 0U && (long)(this._index - this._startIndex) == (long)this._length) { this.Flush(); } if (packet == null && null != this._bufferEntry) { this._bufferPool.Free(this._bufferEntry); this._bufferEntry = (BufferInstance)null; } if (packet != null || null == this._handler) { return; } this._handler((TsPesPacket)null); }
private void ParseHeader(TsPacket packet) { if (packet.BufferLength < 6) { return; } int bufferOffset = packet.BufferOffset; int index1 = bufferOffset; byte[] buffer = packet.Buffer; uint num1 = (uint)((int)buffer[index1] << 16 | (int)buffer[index1 + 1] << 8) | (uint)buffer[index1 + 2]; int num2 = index1 + 3; if (1 != (int)num1) { return; } byte[] numArray = buffer; int index2 = num2; int num3 = 1; int index3 = index2 + num3; this._streamId = numArray[index2]; uint num4 = (uint)buffer[index3] << 8 | (uint)buffer[index3 + 1]; int num5 = index3 + 2; int minSize = 4096; if (num4 > 0U) { this._length = num4 + (uint)(num5 - bufferOffset); minSize = (int)this._length; } else { this._length = 0U; } if (this._bufferEntry != null && this._bufferEntry.Buffer.Length - this._startIndex < minSize) { this._bufferPool.Free(this._bufferEntry); this._bufferEntry = (BufferInstance)null; } if (null == this._bufferEntry) { this._bufferEntry = this._bufferPool.Allocate(minSize); this._startIndex = 0; } this._index = this._startIndex; }
protected override void ParseSection(TsPacket packet, int offset, int length) { if (length < MinimumDescriptionTableLength) return; var i = offset; var buffer = packet.Buffer; var sectionEnd = i + length; i += 2; // Skip reserved var version_number = buffer[i++]; var current_next_indicator = version_number & 1; version_number = (byte)((version_number >> 1) & 0x1f); var section_number = buffer[i++]; var last_section_number = buffer[i++]; var descriptors = _descriptorFactory.Parse(buffer, i, sectionEnd - i); }
protected override void ParseSection(TsPacket packet, int offset, int length) { if (length < 5) { return; } int index1 = offset; byte[] buffer = packet.Buffer; int num1 = index1 + length; this._transportStreamId = (int)buffer[index1] << 8 | (int)buffer[index1 + 1]; int num2 = index1 + 2; byte[] numArray1 = buffer; int index2 = num2; int num3 = 1; int num4 = index2 + num3; byte num5 = numArray1[index2]; this._currentNextIndicator = 0 != ((int)num5 & 1); byte num6 = (byte)((uint)(byte)((uint)num5 >> 1) & 31U); byte[] numArray2 = buffer; int index3 = num4; int num7 = 1; int num8 = index3 + num7; byte num9 = numArray2[index3]; byte[] numArray3 = buffer; int index4 = num8; int num10 = 1; int index5 = index4 + num10; byte num11 = numArray3[index4]; if ((int)this._lastSectionNumber > 0 && (int)num11 != (int)this._lastSectionNumber || (int)num11 < (int)num9) { return; } if (this._hasData) { if ((int)this._versionNumber != (int)num6) { return; } ++this._sectionNumber; if ((int)this._sectionNumber != (int)num9 || (int)this._lastSectionNumber != (int)num11) { return; } } else { if (0 != (int)num9) { return; } this._sectionNumber = (byte)0; this._lastSectionNumber = num11; this._versionNumber = (uint)num6; this._hasData = true; } while (index5 + 4 <= num1) { int program_number = (int)buffer[index5] << 8 | (int)buffer[index5 + 1]; int index6 = index5 + 2; uint pid = (uint)buffer[index6] << 8 | (uint)buffer[index6 + 1]; pid &= 8191U; index5 = index6 + 2; if (!Enumerable.Any <TsProgramAssociationTable.ProgramAssociation>((IEnumerable <TsProgramAssociationTable.ProgramAssociation>) this._newPrograms, (Func <TsProgramAssociationTable.ProgramAssociation, bool>)(p => (int)p.Pid == (int)pid && p.ProgramNumber == program_number)) && this._programFilter(program_number)) { this._newPrograms.Add(new TsProgramAssociationTable.ProgramAssociation() { ProgramNumber = program_number, Pid = pid }); } } if ((int)this._sectionNumber != (int)this._lastSectionNumber || !this._currentNextIndicator) { return; } this.Activate(); }
public bool Parse(int tsIndex, byte[] buffer, int index) { this.TsIndex = tsIndex; this._buffer = buffer; int num1 = index; this.IsSkip = false; int num2 = 71; byte[] numArray1 = buffer; int index1 = num1; int num3 = 1; int num4 = index1 + num3; int num5 = (int)numArray1[index1]; if (num2 != num5) { this.IsSkip = true; return(false); } byte[] numArray2 = buffer; int index2 = num4; int num6 = 1; int num7 = index2 + num6; this.Pid = (uint)numArray2[index2] << 8; TsPacket tsPacket = this; int num8 = (int)tsPacket.Pid; byte[] numArray3 = buffer; int index3 = num7; int num9 = 1; int num10 = index3 + num9; int num11 = (int)numArray3[index3]; int num12 = num8 | num11; tsPacket.Pid = (uint)num12; this._transportErrorIndicator = 0 != ((int)this.Pid & 32768); this.IsStart = 0 != ((int)this.Pid & 16384); this._transportPriority = 0 != ((int)this.Pid & 8192); this.Pid &= 8191U; if (8191 == (int)this.Pid) { this.IsSkip = true; return(true); } if (this._transportErrorIndicator) { this.IsSkip = true; return(true); } byte[] numArray4 = buffer; int index4 = num10; int num13 = 1; int num14 = index4 + num13; byte num15 = numArray4[index4]; this._transportScramblingControl = (int)num15 >> 6 & 3; this._adaptationFieldControl = (int)num15 >> 4 & 3; if (0 == this._adaptationFieldControl) { this.IsSkip = true; } this.ContinuityCount = (int)num15 & 15; this._payloadIndex = num14; this._payloadLength = 188 - (num14 - index); this.IsDiscontinuos = false; this.Pcr = new ulong?(); if (0 != (this._adaptationFieldControl & 2)) { byte[] numArray5 = buffer; int index5 = num14; int num16 = 1; int num17 = index5 + num16; this._adaptationLength = (int)numArray5[index5]; if (2 == this._adaptationFieldControl) { if (this._adaptationLength != 183) { Debug.WriteLine("Invalid adaptation_field_length (without payload): " + (object)this._adaptationLength); this._adaptationLength = 183; } } else if (3 == this._adaptationFieldControl && this._adaptationLength > 182 && 183 != this._adaptationLength) { Debug.WriteLine("Invalid adaptation_field_length (with payload): " + (object)this._adaptationLength); this._adaptationLength = 183; } ++this._payloadIndex; --this._payloadLength; if (this._adaptationLength > 0) { int num18 = this._adaptationLength; if (this._payloadLength < this._adaptationLength) { return(false); } this._payloadIndex += this._adaptationLength; this._payloadLength -= this._adaptationLength; byte[] numArray6 = buffer; int index6 = num17; int num19 = 1; int index7 = index6 + num19; this._adaptationFlags = numArray6[index6]; int num20 = num18 - 1; this.IsDiscontinuos = 0 != ((int)this._adaptationFlags & 128); if (0 != ((int)this._adaptationFlags & 16)) { if (num20 < 6) { return(false); } this.Pcr = new ulong?(this.ReadTime(buffer, index7)); int num21 = index7 + 6; int num22 = num20 - 6; } } } else { this._adaptationLength = 0; } return(true); }
protected override void ParseSection(TsPacket packet, int offset, int length) { if (length < MinimumProgramMapSize) return; var i = offset; var buffer = packet.Buffer; var program_number = (buffer[i] << 8) | buffer[i + 1]; i += 2; var version_number = buffer[i++]; var current_next_indicator = 0 != (version_number & 1); version_number >>= 1; version_number &= 0x1f; var section_number = buffer[i++]; var last_section_number = buffer[i++]; if (last_section_number < section_number) return; var PCR_PID = ((uint)buffer[i] << 8) | buffer[i + 1]; i += 2; PCR_PID &= 0x1fff; _pcrPid = PCR_PID; var program_info_length = (buffer[i] << 8) | buffer[i + 1]; i += 2; program_info_length &= 0x0fff; if (i - offset + program_info_length >= length) return; TsDescriptor[] programDescriptors = null; if (program_info_length > 0) { //Debug.WriteLine("TsProgramMapTable.Add() program descriptor for program " + program_number); //TsDescriptors.DebugWrite(buffer, i, program_info_length); programDescriptors = _descriptorFactory.Parse(buffer, i, program_info_length).ToArray(); } _newProgramDescriptors = programDescriptors; i += program_info_length; var mappingEnd = offset + length; while (i + 5 <= mappingEnd) { var stream_type = buffer[i++]; var elementary_PID = ((uint)buffer[i] << 8) | buffer[i + 1]; i += 2; elementary_PID &= 0x1fff; var ES_info_length = (buffer[i] << 8) | buffer[i + 1]; i += 2; ES_info_length &= 0x0fff; if (i + ES_info_length > mappingEnd) return; TsDescriptor[] streamDescriptors = null; if (ES_info_length > 0) { //Debug.WriteLine("TsProgramMapTable.Add() ES descriptor for PID " + elementary_PID); //TsDescriptors.DebugWrite(buffer, i, ES_info_length); streamDescriptors = _descriptorFactory.Parse(buffer, i, ES_info_length).ToArray(); } i += ES_info_length; var streamType = TsStreamType.FindStreamType(stream_type); var programMap = new ProgramMap { Pid = elementary_PID, StreamType = streamType, StreamDescriptors = streamDescriptors }; _newProgramStreams[elementary_PID] = programMap; } if (section_number == last_section_number) MapProgramStreams(); }
void AddPcr(TsPacket packet) { if (null == packet || !packet.Pcr.HasValue) return; _pcrIndex = packet.TsIndex; _pcr = packet.Pcr; }
void ParseHeader(TsPacket packet) { var length = packet.BufferLength; if (length < 6) return; var i0 = packet.BufferOffset; var i = i0; var buffer = packet.Buffer; var packet_start_code_prefix = ((uint)buffer[i] << 16) | ((uint)buffer[i + 1] << 8) | buffer[i + 2]; i += 3; if (1 != packet_start_code_prefix) return; _streamId = buffer[i++]; var packet_length = ((uint)buffer[i] << 8) | buffer[i + 1]; i += 2; var bufferLength = DefaultPacketSize; if (packet_length > 0) { _length = packet_length + (uint)(i - i0); bufferLength = (int)_length; } else _length = 0; // If we still have a buffer, make sure the size is reasonable. if (null != _bufferEntry && _bufferEntry.Buffer.Length - _startIndex < bufferLength) { _bufferPool.Free(_bufferEntry); _bufferEntry = null; } if (null == _bufferEntry) { _bufferEntry = _bufferPool.Allocate(bufferLength); _startIndex = 0; } _index = _startIndex; }
protected abstract void ParseSection(TsPacket packet, int offset, int length);
protected override void ParseSection(TsPacket packet, int offset, int length) { if (length < 9) { return; } int index1 = offset; byte[] buffer = packet.Buffer; int num1 = (int)buffer[index1] << 8 | (int)buffer[index1 + 1]; int num2 = index1 + 2; byte[] numArray1 = buffer; int index2 = num2; int num3 = 1; int num4 = index2 + num3; byte num5 = numArray1[index2]; bool flag = 0 != ((int)num5 & 1); byte num6 = (byte)((uint)(byte)((uint)num5 >> 1) & 31U); byte[] numArray2 = buffer; int index3 = num4; int num7 = 1; int num8 = index3 + num7; byte num9 = numArray2[index3]; byte[] numArray3 = buffer; int index4 = num8; int num10 = 1; int index5 = index4 + num10; byte num11 = numArray3[index4]; if ((int)num11 < (int)num9) { return; } uint num12 = (uint)buffer[index5] << 8 | (uint)buffer[index5 + 1]; int index6 = index5 + 2; this._pcrPid = num12 & 8191U; int num13 = (int)buffer[index6] << 8 | (int)buffer[index6 + 1]; int offset1 = index6 + 2; int length1 = num13 & 4095; if (offset1 - offset + length1 >= length) { return; } TsDescriptor[] tsDescriptorArray1 = (TsDescriptor[])null; if (length1 > 0) { tsDescriptorArray1 = Enumerable.ToArray <TsDescriptor>(TsDescriptors.Parse(this._descriptorFactory, buffer, offset1, length1)); } this._newProgramDescriptors = tsDescriptorArray1; int num14 = offset1 + length1; int num15 = offset + length; while (num14 + 5 <= num15) { byte[] numArray4 = buffer; int index7 = num14; int num16 = 1; int index8 = index7 + num16; byte streamType1 = numArray4[index7]; uint num17 = (uint)buffer[index8] << 8 | (uint)buffer[index8 + 1]; int index9 = index8 + 2; uint index10 = num17 & 8191U; int num18 = (int)buffer[index9] << 8 | (int)buffer[index9 + 1]; int offset2 = index9 + 2; int length2 = num18 & 4095; if (offset2 + length2 > num15) { return; } TsDescriptor[] tsDescriptorArray2 = (TsDescriptor[])null; if (length2 > 0) { tsDescriptorArray2 = Enumerable.ToArray <TsDescriptor>(TsDescriptors.Parse(this._descriptorFactory, buffer, offset2, length2)); } num14 = offset2 + length2; TsStreamType streamType2 = TsStreamType.FindStreamType(streamType1); TsProgramMapTable.ProgramMap programMap = new TsProgramMapTable.ProgramMap() { Pid = index10, StreamType = streamType2, StreamDescriptors = tsDescriptorArray2 }; this._newProgramStreams[index10] = programMap; } if ((int)num9 != (int)num11) { return; } this.MapProgramStreams(); }
internal void Add(TsPacket packet) { if (null == packet) { return; } int bufferOffset = packet.BufferOffset; int num1 = bufferOffset; byte[] buffer = packet.Buffer; int bufferLength = packet.BufferLength; if (bufferLength < 4) { return; } byte[] numArray1 = buffer; int index1 = num1; int num2 = 1; int num3 = index1 + num2 + (int)numArray1[index1]; if (num3 + 4 >= bufferOffset + bufferLength) { return; } int offset1 = num3; byte[] numArray2 = buffer; int index2 = num3; int num4 = 1; int index3 = index2 + num4; if ((int)this._tableId != (int)numArray2[index2]) { return; } int num5 = (int)buffer[index3] << 8 | (int)buffer[index3 + 1]; int num6 = index3 + 2; bool flag = 0 != (num5 & 32768); if (0 != (num5 & 16384)) { return; } int num7 = num5 & 4095; if (num7 > 1021 || num7 + num6 - bufferOffset > bufferLength) { return; } int length1 = num7 + num6 - offset1; if (!Crc32Msb.Validate(buffer, offset1, length1)) { return; } int offset2 = num6; int length2 = num7 - 4; this.ParseSection(packet, offset2, length2); }