Esempio n. 1
0
        private unsafe bool AddPage(PageHeader hdr)
        {
            // get our packet reader (create one if we have to)
            if (!_packetReaders.TryGetValue(hdr.StreamSerial, out var packetReader))
            {
                packetReader = new OggPacketReader(this, hdr.StreamSerial);
            }

            // save off the container bits
            packetReader.ContainerBits += _containerBits;
            _containerBits              = 0;

            // get our flags prepped
            bool isContinued    = hdr.SegCount == 1 && hdr.LastPacketContinues;
            bool isContinuation = (hdr.Flags & OggPageFlags.ContinuesPacket) == OggPageFlags.ContinuesPacket;
            bool isEOS          = false;
            bool isResync       = hdr.IsResync;

            // add all the packets, making sure to update flags as needed
            long dataOffset = hdr.DataOffset;
            int  count      = hdr.SegCount;

            for (int i = 0; i < hdr.SegCount; i++)
            {
                int size   = hdr.PacketSizes[i];
                var packet = OggPacketPool.Rent(this, dataOffset, size);
                packet.PageGranulePosition = hdr.GranulePosition;
                packet.IsEndOfStream       = isEOS;
                packet.PageSequenceNumber  = hdr.SequenceNumber;
                packet.IsContinued         = isContinued;
                packet.IsContinuation      = isContinuation;
                packet.IsResync            = isResync;
                packetReader.AddPacket(packet);

                // update the offset into the stream for each packet
                dataOffset += size;

                // only the first packet in a page can be a continuation or resync
                isContinuation = false;
                isResync       = false;

                // only the last packet in a page can be continued or flagged end of stream
                if (--count == 1)
                {
                    isContinued = hdr.LastPacketContinues;
                    isEOS       = (hdr.Flags & OggPageFlags.EndOfStream) == OggPageFlags.EndOfStream;
                }
            }

            // if the packet reader list doesn't include the serial in question, add it to the list and indicate a new stream to the caller
            if (!_packetReaders.ContainsKey(hdr.StreamSerial))
            {
                _packetReaders.Add(hdr.StreamSerial, packetReader);
                return(true);
            }
            else
            {
                // otherwise, indicate an existing stream to the caller
                return(false);
            }
        }
Esempio n. 2
0
 // packet reader bits...
 internal void DisposePacketReader(OggPacketReader packetReader)
 {
     _disposedStreamSerials.Add(packetReader.StreamSerial);
     _packetReaders.Remove(packetReader.StreamSerial);
 }
 public DebugView(OggPacketReader reader)
 {
     _reader = reader ?? throw new ArgumentNullException();
 }