Пример #1
0
        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);
            }
        }
 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);
 }