public long SeekTo(
            long granulePos, int preRoll, GetPacketGranuleCountDelegate getPacketGranuleCount)
        {
            if (_reader == null)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            int pageIndex = _reader.FindPage(granulePos);

            int packetIndex;

            if (granulePos == 0)
            {
                // for this, we can generically say the first packet on the first page having a non-zero granule
                packetIndex = 0;
            }
            else
            {
                packetIndex  = FindPacket(pageIndex, ref granulePos, getPacketGranuleCount);
                packetIndex -= preRoll;
            }

            if (!NormalizePacketIndex(ref pageIndex, ref packetIndex))
            {
                throw new ArgumentOutOfRangeException(nameof(granulePos));
            }

            _lastPacket  = null;
            _pageIndex   = pageIndex;
            _packetIndex = packetIndex;
            return(granulePos);
        }
Esempio n. 2
0
        public long SeekTo(long granulePos, int preRoll, GetPacketGranuleCount getPacketGranuleCount)
        {
            if (_reader == null)
            {
                throw new ObjectDisposedException(nameof(PacketProvider));
            }

            int pageIndex;
            int packetIndex;

            if (granulePos == 0)
            {
                // for this, we can generically say the first packet on the first page having a non-zero granule
                pageIndex   = _reader.FirstDataPageIndex;
                packetIndex = 0;
            }
            else
            {
                pageIndex = _reader.FindPage(granulePos);
                if (_reader.HasAllPages && _reader.MaxGranulePosition == granulePos)
                {
                    // allow seek to the offset immediatly after the last available (for what good it'll do)
                    _lastPacket  = null;
                    _pageIndex   = pageIndex;
                    _packetIndex = 0;
                    return(granulePos);
                }
                else
                {
                    packetIndex = FindPacket(pageIndex, ref granulePos, getPacketGranuleCount);
                }
                packetIndex -= preRoll;
            }

            if (!NormalizePacketIndex(ref pageIndex, ref packetIndex))
            {
                throw new ArgumentOutOfRangeException(nameof(granulePos));
            }

            if (pageIndex < _reader.FirstDataPageIndex)
            {
                pageIndex   = _reader.FirstDataPageIndex;
                packetIndex = 0;
            }

            _lastPacket  = null;
            _pageIndex   = pageIndex;
            _packetIndex = packetIndex;
            return(granulePos);
        }