コード例 #1
0
        /// <summary>
        /// Sets provided configuration to appropriate stream.
        /// </summary>
        /// <param name="config">StreamConfig</param>
        public Task SetStreamConfiguration(StreamConfig config)
        {
            var streamType = config.StreamType();

            logger.Info($"{streamType}: {config.GetType()}");

            if (config is BufferStreamConfig metaData)
            {
                // Use video for buffer depth control.
                if (streamType == StreamType.Video)
                {
                    _dataClock.BufferLimit = metaData.BufferDuration;
                }

                return(Task.CompletedTask);
            }

            if (esStreams[(int)streamType] == null)
            {
                logger.Warn($"Uninitialized stream {streamType}");
                return(Task.CompletedTask);
            }

            if (esStreams[(int)streamType].HaveConfiguration)
            {
                if (!esStreams[(int)streamType].Configuration.IsCompatible(config))
                {
                    esStreams[(int)streamType].Configuration = config;
                    return(Task.CompletedTask);
                }
                logger.Info($"{streamType}: Queuing configuration");
                return(AppendPacket(BufferConfigurationPacket.Create(config)));
            }

            if (_configurationsCollected == null)
            {
                esStreams[(int)streamType].SetStreamConfiguration(config);
            }
            else
            {
                esStreams[(int)streamType].Configuration = config;
                if (AllStreamsHaveConfiguration)
                {
                    _configurationsCollected.TrySetResult(null);
                }

                return(Task.CompletedTask);
            }

            // Check if all initialized streams have configuration &
            // can be started
            if (!AllStreamsHaveConfiguration)
            {
                logger.Info($"Needed config: Video {esStreams[(int)StreamType.Video].Configuration == null} Audio {esStreams[(int)StreamType.Audio].Configuration == null}");
                return(Task.CompletedTask);
            }

            return(PreparePlayback(activeTaskCts.Token));
        }
コード例 #2
0
        /// <summary>
        /// Sets provided configuration to appropriate stream.
        /// </summary>
        /// <param name="config">StreamConfig</param>
        public async Task SetStreamConfiguration(StreamConfig config)
        {
            var streamType = config.StreamType();

            logger.Info($"{streamType}: {config.GetType()}");

            try
            {
                if (config is BufferStreamConfig metaData)
                {
                    // Use video for buffer depth control.
                    if (streamType == StreamType.Video)
                    {
                        _dataClock.UpdateBufferDepth(metaData.BufferDuration);
                    }
                    return;
                }

                if (esStreams[(int)streamType].IsConfigured)
                {
                    logger.Info($"{streamType}: Queuing configuration");
                    AppendPacket(BufferConfigurationPacket.Create(config));
                    return;
                }

                // Don't push config yet. Just store it. Configs may arrive
                // after player gets disowned. Configs should not be pushed, but
                // configuration is needed in order to restore player configuration.
                esStreams[(int)streamType].StoreStreamConfiguration(config);

                // Check if all initialized streams have configuration &
                // can be started
                if (!AllStreamsHaveConfiguration || activeTaskCts.IsCancellationRequested)
                {
                    return;
                }

                SetPlayerConfiguration();
                await PreparePlayback(activeTaskCts.Token);

                SetState(PlayerState.Prepared);
            }
            catch (OperationCanceledException)
            {
                logger.Info("Operation cancelled");
            }
            catch (NullReferenceException)
            {
                // packetQueue can hold ALL StreamTypes, but not all of them
                // have to be supported.
                logger.Warn($"Uninitialized Stream Type {streamType}");
            }
            catch (ObjectDisposedException)
            {
                logger.Info($"{streamType}: Operation Cancelled and disposed");
            }
            catch (InvalidOperationException)
            {
                // Queue has been marked as completed
                logger.Warn($"Data queue terminated for stream: {streamType}");
            }
            catch (UnsupportedStreamException use)
            {
                logger.Error(use, $"{streamType}");
                OnEsStreamError(use.Message);
            }
        }