예제 #1
0
        /// <summary>
        /// Sets provided configuration to appropriate stream.
        /// </summary>
        /// <param name="config">StreamConfig</param>
        public async Task SetStreamConfiguration(BufferConfigurationPacket config)
        {
            var streamType = config.StreamType;

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

            try
            {
                if (config.Config is BufferStreamConfig metaData)
                {
                    await _dataClock.UpdateBufferDepth(metaData.StreamType(), metaData.BufferDuration);
                }

                var pushResult = esStreams[(int)streamType].SetStreamConfiguration(config);

                if (pushResult == EsStream.SetStreamConfigResult.QueueConfiguration)
                {
                    AppendPacket(config);
                    return;
                }

                esStreams[(int)streamType].PushStreamConfiguration();

                // Check if all initialized streams are configured
                if (!AllStreamsConfigured)
                {
                    return;
                }

                var token = activeTaskCts.Token;
                await StreamPrepare(token);
            }
            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);
            }
        }
예제 #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);
            }
        }