Example #1
0
        /// <summary>
        /// Creates an opus decoder and reads from the ogg stream until a data packet is encountered,
        /// queuing it up for future decoding. Tags are also parsed if they are encountered.
        /// </summary>
        /// <returns>True if the stream is valid and ready to be decoded</returns>
        private bool Initialize()
        {
            try
            {
                var oggContainerReader = new OggContainerReader(_stream, true);
                if (!oggContainerReader.Init())
                {
                    LastError = "Could not initialize stream";
                    return(false);
                }

                if (oggContainerReader.StreamSerials.Length == 0)
                {
                    LastError = "Initialization failed: No elementary streams found in input file";
                    return(false);
                }

                int firstStreamSerial = oggContainerReader.StreamSerials[0];
                _packetProvider = oggContainerReader.GetStream(firstStreamSerial);

                if (CanSeek)
                {
                    GranuleCount = _packetProvider.GetGranuleCount();
                    PageCount    = _packetProvider.GetTotalPageCount();
                }

                QueueNextPacket();

                return(true);
            }
            catch (Exception e)
            {
                LastError = "Unknown initialization error: " + e.Message;
                return(false);
            }
        }
Example #2
0
 internal long GetLastGranulePos()
 {
     return(_packetProvider.GetGranuleCount());
 }