Beispiel #1
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];
        }
Beispiel #2
0
        private async Task UpdatePage(int page)
        {
            Debug.WriteLine($"Update page: {page}");

            var links = await _insecamSelector.GetSourceLinksAsync(page);

            if (Sources == null)
            {
                Sources = new ObservableCollectionExtended <PlayerViewModel>();

                foreach (var item in links)
                {
                    IStreamDecoder decoder = Locator.Current.GetService <IStreamDecoder>();

                    Sources.Add(new PlayerViewModel(decoder)
                    {
                        Location = item.Location,
                        Uri      = item.StreamUri
                    });
                }
            }
            else
            {
                for (int i = 0; i < links.Count; i++)
                {
                    Sources[i].Location = links[i].Location;
                    Sources[i].Uri      = links[i].StreamUri;
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Create an AssemblyInfo
 /// </summary>
 /// <param name="sourceAssembly">The assembly whose embedded resources we want</param>
 /// <param name="resourcePrefix">The name that prefixes the files. Normally the default namespace</param>
 /// <param name="decoder">Instance of IStreamDecoder</param>
 public AssemblyInfo(Assembly sourceAssembly, string resourcePrefix, IStreamDecoder decoder)
 {
     _assembly = sourceAssembly;
     _resource_prefix = resourcePrefix;
     _all_resource_names = _assembly.GetManifestResourceNames();
     _decoder = decoder;
     Array.Sort(_all_resource_names);    // Just to help during development. It's easier to find files in order...
 }
 private void disposeDecoder()
 {
     if (_decoder != null)
     {
         _decoder.VideoFrameEvent -= onDisplay;
         _decoder.Dispose();
     }
     _decoder = null;
 }
 public void InitHeader(byte[] buffer)
 {
     disposeDecoder();
     _decoder = getDecoder(buffer);
     if (_decoder != null)
     {
         _decoder.VideoFrameEvent += onDisplay;
     }
 }
Beispiel #6
0
        public PlayerViewModel(IStreamDecoder decoder)
        {
            _decoder = decoder;

            this.WhenAnyValue(x => x.Uri)
            .Where(uri => !string.IsNullOrEmpty(uri))
            .Subscribe(UpdateSource);

            Observable
            .FromEventPattern <FrameReceivedEventArgs>(_decoder, nameof(IStreamDecoder.OnFrameReceived))
            //.SubscribeOn(TaskPoolScheduler.Default)
            .ObserveOn(new SynchronizationContextScheduler(SynchronizationContext.Current))
            .Subscribe(x => { Frame = x.EventArgs.Frame; });
        }
Beispiel #7
0
        private bool SwitchToDecoder(IStreamDecoder nextDecoder)
        {
            _streamDecoder = nextDecoder;
            _hasEnded      = false;

            var channels   = WaveFormat?.Channels;
            var sampleRate = WaveFormat?.SampleRate;

            WaveFormat = WaveFormat.CreateIeeeFloatWaveFormat(_streamDecoder.SampleRate, _streamDecoder.Channels);

            if ((channels ?? WaveFormat.Channels) != WaveFormat.Channels || (sampleRate ?? WaveFormat.SampleRate) != WaveFormat.SampleRate)
            {
                WaveFormatChange?.Invoke(this, EventArgs.Empty);
                return(true);
            }

            StreamChange?.Invoke(this, EventArgs.Empty);
            return(false);
        }
Beispiel #8
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="closeOnDispose"><see langword="true"/> to take ownership and clean up the instance when disposed, otherwise <see langword="false"/>.</param>
        public VorbisReader(Stream stream, bool closeOnDispose = true)
        {
            _decoders = new List <IStreamDecoder>();

            var containerReader = CreateContainerReader(stream, closeOnDispose);

            containerReader.NewStreamCallback = ProcessNewStream;

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

                if (closeOnDispose)
                {
                    stream.Dispose();
                }

                throw new ArgumentException("Could not load the specified container!", nameof(containerReader));
            }
            _closeOnDispose  = closeOnDispose;
            _containerReader = containerReader;
            _streamDecoder   = _decoders[0];
        }
 /// <summary>
 /// Creates a new instance of <see cref="NewStreamEventArgs"/> with the specified <see cref="IStreamDecoder"/>.
 /// </summary>
 /// <param name="streamDecoder">An <see cref="IStreamDecoder"/> instance.</param>
 public NewStreamEventArgs(IStreamDecoder streamDecoder)
 {
     StreamDecoder = streamDecoder ?? throw new ArgumentNullException(nameof(streamDecoder));
     IgnoreStream  = false;
 }
Beispiel #10
0
 /// <summary>
 /// Creates a new instance of <see cref="VorbisSampleProvider"/> that will read from a single specified decoder stream.
 /// </summary>
 /// <param name="streamDecoder">The decoder to read from.</param>
 /// <param name="allowSeek">Sets whether to allow seek operations to be attempted on this stream.  Note that setting this to <see langword="true"/>
 /// when the underlying stream doesn't support it will still generate an exception from the decoder when attempting seek operations.</param>
 public VorbisSampleProvider(IStreamDecoder streamDecoder, bool allowSeek)
 {
     _streamDecoders.AddLast(streamDecoder);
     SwitchToDecoder(streamDecoder);
     CanSeek = allowSeek;
 }
Beispiel #11
0
 private void InitializeInstance(Assembly root, string resourcePrefix, string folder)
 {
     _entry_assembly = root;
     _decoder = new NullDecoder();
     AssemblyInfo info = AddAssembly(_entry_assembly, resourcePrefix);
     if (folder != null) {
         info.Mount(folder);
     }
 }