private TsPesPacket AllocatePacketWithOwnedBuffer(BufferInstance bufferEntry) { TsPesPacket tsPesPacket = this._packetPool.Allocate(); tsPesPacket.BufferEntry = bufferEntry; tsPesPacket.Clear(); return(tsPesPacket); }
public TsPesPacket AllocatePesPacket(BufferInstance bufferEntry) { if (null == bufferEntry) { throw new ArgumentNullException("bufferEntry"); } bufferEntry.Reference(); return(this.AllocatePacketWithOwnedBuffer(bufferEntry)); }
public void Clear() { this._startIndex = 0; this._index = 0; this._length = 0U; if (null == this._bufferEntry) { return; } this._bufferPool.Free(this._bufferEntry); this._bufferEntry = (Utility.BufferInstance)null; }
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; } Utility.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 = (Utility.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 = (Utility.BufferInstance)null; } if (null == this._bufferEntry) { this._bufferEntry = this._bufferPool.Allocate(minSize); this._startIndex = 0; } this._index = this._startIndex; }
public void FreePesPacket(TsPesPacket packet) { if (null == packet) { throw new ArgumentNullException("packet"); } BufferInstance bufferInstance = packet.BufferEntry; if (null != bufferInstance) { for (int index = packet.Index; index < packet.Index + packet.Length; ++index) { packet.Buffer[index] = (byte)204; } packet.BufferEntry = (BufferInstance)null; this._bufferPool.Free(bufferInstance); } packet.Index = int.MinValue; packet.Length = int.MinValue; packet.PresentationTimestamp = TimeSpan.MaxValue; packet.DecodeTimestamp = new TimeSpan?(TimeSpan.MaxValue); this._packetPool.Free(packet); }