public void DataEventsOnMultipleConfigurationChange() { Assert.DoesNotThrow( () => { using (var bufferController = new StreamBufferController(Observable.Return <PlayerState>(PlayerState.Playing))) { bufferController.Initialize(StreamType.Audio); bufferController.Initialize(StreamType.Video); var dataArgsHolder = new DataRequest[(int)StreamType.Count]; var configsToSet = 0; using (bufferController.DataNeededStateChanged() .Subscribe(a => { dataArgsHolder[(int)a.StreamType] = a; configsToSet++; }, SynchronizationContext.Current)) { var audio = new MetaDataStreamConfig { Bandwidth = 987654321, BufferDuration = TimeSpan.FromSeconds(15), Stream = StreamType.Audio }; var video = new MetaDataStreamConfig { Bandwidth = 123456789, BufferDuration = TimeSpan.FromSeconds(13), Stream = StreamType.Video }; bufferController.SetMetaDataConfiguration(audio); bufferController.SetMetaDataConfiguration(video); SpinWait.SpinUntil(() => dataArgsHolder[(int)StreamType.Audio] != null && dataArgsHolder[(int)StreamType.Video] != null, TimeSpan.FromSeconds(2)); Assert.IsTrue( dataArgsHolder[(int)StreamType.Audio].CompareMetaData(audio), $"Expected: Same Result: {audio} {dataArgsHolder[(int)StreamType.Audio]}"); Assert.IsTrue( dataArgsHolder[(int)StreamType.Video].CompareMetaData(video), $"Expected: Same Result: {video} {dataArgsHolder[(int)StreamType.Audio]}"); } } }); }
/// <summary> /// Sets provided configuration to appropriate stream. /// </summary> /// <param name="config">StreamConfig</param> public void SetStreamConfiguration(BufferConfigurationPacket config) { var streamType = config.StreamType; logger.Info($"{streamType}:"); try { if (config.Config is MetaDataStreamConfig metaData) { bufferController.SetMetaDataConfiguration(metaData); return; } var pushResult = esStreams[(int)streamType].SetStreamConfig(config); // Configuration queued. Do not prepare stream :) if (pushResult == EsStream.SetStreamConfigResult.ConfigQueued) { return; } // Check if all initialized streams are configured if (!AllStreamsConfigured) { return; } var token = activeTaskCts.Token; bufferController.ResetBuffers(); 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 (OperationCanceledException) { logger.Info($"{streamType}: Operation Cancelled"); } 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); } }