Ejemplo n.º 1
0
        public VorbisReader(Stream stream, bool closeStreamOnDispose)
            : this()
        {
            var bufferedStream = new BufferedReadStream(stream);

            bufferedStream.CloseBaseStream = closeStreamOnDispose;

            // try Ogg first
            var oggContainer = new Ogg.ContainerReader(bufferedStream, closeStreamOnDispose);

            if (!LoadContainer(oggContainer))
            {
                // oops, not Ogg!
                // we don't support any other container types yet, so error out
                // TODO: Add Matroska fallback
                bufferedStream.Close();
                throw new InvalidDataException("Could not determine container type!");
            }
            _containerReader = oggContainer;

            if (_decoders.Count == 0)
            {
                throw new InvalidDataException("No Vorbis data found!");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new instance of <see cref="VorbisReader"/> reading from the specified stream,
        /// optionally taking ownership of it.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> to read from.</param>
        /// <param name="leaveOpen"><c>false</c> to close the stream when disposed, otherwise <c>true</c>.</param>
        public VorbisReader(Stream stream, bool leaveOpen = false)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            _decoders = new List <IStreamDecoder>();

            var containerReader = CreateContainerReader(stream, leaveOpen);

            containerReader.NewStreamCallback = ProcessNewStream;

            if (!containerReader.TryInit() || _decoders.Count == 0)
            {
                containerReader.NewStreamCallback = null;
                containerReader.Dispose();

                if (!leaveOpen)
                {
                    stream.Dispose();
                }

                throw new InvalidDataException("Could not load the specified container.");
            }

            _leaveOpen       = leaveOpen;
            _containerReader = containerReader;
            _streamDecoder   = _decoders[0];
        }
Ejemplo n.º 3
0
 bool LoadContainer(IContainerReader containerReader)
 {
     containerReader.NewStream += NewStream;
     if (!containerReader.Init())
     {
         containerReader.NewStream -= NewStream;
         return(false);
     }
     return(true);
 }
Ejemplo n.º 4
0
 bool LoadContainer(IContainerReader containerReader)
 {
     containerReader.NewStream += NewStream;
     if (!containerReader.Init())
     {
         containerReader.NewStream -= NewStream;
         return false;
     }
     return true;
 }
Ejemplo n.º 5
0
        public VorbisReader(IContainerReader containerReader)
            : this()
        {
            if (!LoadContainer(containerReader))
            {
                throw new InvalidDataException("Container did not initialize!");
            }
            _containerReader = containerReader;

            if (_decoders.Count == 0) throw new InvalidDataException("No Vorbis data found!");
        }
Ejemplo n.º 6
0
 public VorbisReader(IContainerReader containerReader)
     : this()
 {
     if (!LoadContainer(containerReader))
     {
         throw new InvalidDataException("Container did not initialize!");
     }
     _containerReader = containerReader;
     if (_decoders.Count == 0)
     {
         throw new InvalidDataException("No Vorbis data found!");
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a new instance of <see cref="VorbisSampleProvider"/>.
        /// </summary>
        /// <param name="sourceStream">The stream to read for data.</param>
        public VorbisSampleProvider(System.IO.Stream sourceStream, bool closeOnDispose = false)
        {
            _containerReader = new NVorbis.Ogg.ContainerReader(sourceStream, closeOnDispose)
            {
                NewStreamCallback = ProcessNewStream
            };
            CanSeek = _containerReader.CanSeek;
            if (!_containerReader.TryInit())
            {
                throw new ArgumentException("Could not initialize container!");
            }

            if (!GetNextDecoder(true).HasValue)
            {
                throw new InvalidOperationException("Container initialized, but no stream found?");
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Cleans up resources used by this instance.
        /// </summary>
        public void Dispose()
        {
            var foundCurrent = false;

            foreach (var decoder in _streamDecoders)
            {
                foundCurrent |= decoder == _streamDecoder;
                decoder.Dispose();
            }
            _streamDecoders.Clear();
            if (!foundCurrent)
            {
                _streamDecoder.Dispose();
            }

            _containerReader?.Dispose();
            _containerReader = null;
        }
Ejemplo n.º 9
0
 public void Dispose()
 {
     if (_decoders != null)
     {
         foreach (VorbisStreamDecoder decoder in _decoders)
         {
             decoder.Dispose();
         }
         _decoders.Clear();
         _decoders = null;
     }
     if (_containerReader != null)
     {
         _containerReader.NewStream -= NewStream;
         _containerReader.Dispose();
         _containerReader = null;
     }
 }
Ejemplo n.º 10
0
        public VorbisReader(Stream stream, bool closeStreamOnDispose)
            : this()
        {
            var bufferedStream = new BufferedReadStream(stream);
            bufferedStream.CloseBaseStream = closeStreamOnDispose;

            // try Ogg first
            var oggContainer = new Ogg.ContainerReader(bufferedStream, closeStreamOnDispose);
            if (!LoadContainer(oggContainer))
            {
                // oops, not Ogg!
                // we don't support any other container types yet, so error out
                bufferedStream.Close();
                throw new InvalidDataException("Could not determine container type!");
            }
            _containerReader = oggContainer;

            if (_decoders.Count == 0) throw new InvalidDataException("No Vorbis data found!");
        }
        public VorbisReader(Stream stream, bool leaveOpen) : this()
        {
            // try Ogg first
            var oggContainer = new Ogg.OggContainerReader(stream, leaveOpen);

            if (!LoadContainer(oggContainer))
            {
                // oops, not Ogg!
                // we don't support any other container types yet, so error out
                // TODO: Add Matroska fallback
                oggContainer.Dispose();
                throw new InvalidDataException("Could not determine container type.");
            }
            _containerReader = oggContainer;

            if (_decoders.Count == 0)
            {
                throw new InvalidDataException("No Vorbis data found.");
            }
        }
Ejemplo n.º 12
0
        public VorbisReader(Stream stream, bool closeStreamOnDispose)
            : this()
        {
            BufferedReadStream bufferedReadStream = new BufferedReadStream(stream)
            {
                CloseBaseStream = closeStreamOnDispose
            };
            ContainerReader containerReader = new ContainerReader(bufferedReadStream, closeStreamOnDispose);

            if (!LoadContainer(containerReader))
            {
                bufferedReadStream.Dispose();
                throw new InvalidDataException("Could not determine container type!");
            }
            _containerReader = containerReader;
            if (_decoders.Count == 0)
            {
                throw new InvalidDataException("No Vorbis data found!");
            }
        }
Ejemplo n.º 13
0
        public VorbisReader(Stream stream, bool closeStreamOnDispose)
            : this()
        {
            var oggContainer = new Ogg.ContainerReader(stream, closeStreamOnDispose);

            if (!LoadContainer(oggContainer))
            {
                // oops, not Ogg!
                // we don't support any other container types here, so error out
                if (closeStreamOnDispose)
                {
                    stream.Close();
                }
                throw new InvalidDataException("Could not determine container type!");
            }
            _containerReader = oggContainer;

            if (_decoders.Count == 0)
            {
                throw new InvalidDataException("No Vorbis data found!");
            }
        }
Ejemplo n.º 14
0
        public void Dispose()
        {
            if (_decoders != null)
            {
                foreach (var decoder in _decoders)
                {
                    decoder.Dispose();
                }
                _decoders.Clear();
                _decoders = null;
            }

            if (_containerReader != null)
            {
                _containerReader.NewStream -= NewStream;
                _containerReader.Dispose();
                _containerReader = null;
            }
        }
Ejemplo n.º 15
0
 VorbisAudioStream(IContainerReader containerReader)
     : this(new VorbisReader(containerReader))
 {
 }
Ejemplo n.º 16
0
 VorbisAudioStream(IContainerReader containerReader) : this(new VorbisReader(containerReader))
 {
 }