public void Dispose() { if (0 != Interlocked.Exchange(ref this._isDisposed, 1)) { return; } this._disposeCancellationTokenSource.Cancel(); using (this._refreshTask) ; using (this._reportingTask) ; this._reportingTask = (SignalTask)null; this._disposeCancellationTokenSource.Dispose(); bool lockTaken = false; object obj = null; try { Monitor.Enter(obj = this._lock, ref lockTaken); this._queues.Clear(); } finally { if (lockTaken) { Monitor.Exit(obj); } } if (null == Interlocked.Exchange <IQueueThrottling>(ref this._queueThrottling, (IQueueThrottling)null)) { return; } Debug.WriteLine("**** BufferingManager.Dispose() _queueThrottling was not null"); }
public SingleStreamMediaManager(Func <IBufferingManager> bufferingManagerFactory, IMediaParserFactory mediaParserFactory, IMediaStreamConfigurator mediaStreamConfigurator, IWebMetadataFactory webMetadataFactory, IWebReaderManager webReaderManager) { if (null == bufferingManagerFactory) { throw new ArgumentNullException("bufferingManagerFactory"); } if (null == mediaParserFactory) { throw new ArgumentNullException("mediaParserFactory"); } if (null == mediaStreamConfigurator) { throw new ArgumentNullException("mediaStreamConfigurator"); } if (null == webMetadataFactory) { throw new ArgumentNullException("webMetadataFactory"); } if (null == webReaderManager) { throw new ArgumentNullException("webReaderManager"); } this._bufferingManagerFactory = bufferingManagerFactory; this._mediaParserFactory = mediaParserFactory; this._mediaStreamConfigurator = mediaStreamConfigurator; this._webMetadataFactory = webMetadataFactory; this._webReaderManager = webReaderManager; this._reportStateTask = new SignalTask(new Func <Task>(this.ReportState)); }
public HlsPlaylistSegmentManager(IProgramStream programStream, IPlatformServices platformServices, CancellationToken cancellationToken) { if (null == programStream) { throw new ArgumentNullException("programStream"); } if (null == platformServices) { throw new ArgumentNullException("platformServices"); } this._programStream = programStream; this._platformServices = platformServices; this._cancellationToken = cancellationToken; HlsPlaylistParameters parameters = HlsPlaylistSettings.Parameters; this._minimumRetry = parameters.MinimumRetry; this._minimumReload = parameters.MinimumReload; this._maximumReload = parameters.MaximumReload; this._excessiveDuration = parameters.ExcessiveDuration; this._abortTokenSource = CancellationTokenSource.CreateLinkedTokenSource(this._cancellationToken); this._isDynamicPlaylist = true; this._readTask = new SignalTask(new Func <Task>(this.ReadSubList), this._abortTokenSource.Token); this._segmentsExpiration = Environment.TickCount; this.Playlist = (IAsyncEnumerable <ISegment>) new HlsPlaylistSegmentManager.PlaylistEnumerable(this); }
public MetadataHandler(SystemMediaTransportControls systemMediaTransportControls, ForegroundNotifier notifier, Func <TimeSpan> getPosition, Action <TimeSpan> reportNextEvent, CancellationToken cancellationToken) { if (null == systemMediaTransportControls) { throw new ArgumentNullException("systemMediaTransportControls"); } if (null == notifier) { throw new ArgumentNullException("notifier"); } if (null == getPosition) { throw new ArgumentNullException("getPosition"); } if (null == reportNextEvent) { throw new ArgumentNullException("reportNextEvent"); } _systemMediaTransportControls = systemMediaTransportControls; _notifier = notifier; _getPosition = getPosition; _reportNextEvent = reportNextEvent; _updateTask = new SignalTask(Update, cancellationToken); _metadataSink = new ActionMetadataSink(_updateTask.Fire); }
protected BackgroundMediaNotifier(Guid id) { _id = id; _sendTask = new SignalTask(() => { for (; ;) { ValueSet valueSet; lock (_queue) { if (_queue.Count < 1) { return(TplTaskExtensions.CompletedTask); } valueSet = _queue.Dequeue(); } try { SendMessage(valueSet); } catch (Exception ex) { Debug.WriteLine("BackgroundAudioNotifier notifier failed: " + ex.Message); } } }); }
private static async Task CleanupReader(SignalTask readTask, CancellationTokenSource cancellationTokenSource) { using (cancellationTokenSource) { using (readTask) { if (null != cancellationTokenSource) { try { if (!cancellationTokenSource.IsCancellationRequested) { cancellationTokenSource.Cancel(); } } catch (Exception ex) { Debug.WriteLine("HlsPlaylistSegmentManager.CleanupReader() cancel failed: " + ex.Message); } } if (null != readTask) { await readTask.WaitAsync().ConfigureAwait(false); } } } }
public HlsPlaylistSegmentManager(IProgramStream programStream, IPlatformServices platformServices, CancellationToken cancellationToken) { if (null == programStream) { throw new ArgumentNullException("programStream"); } if (null == platformServices) { throw new ArgumentNullException("platformServices"); } _programStream = programStream; _platformServices = platformServices; _cancellationToken = cancellationToken; var parameters = HlsPlaylistSettings.Parameters; _minimumRetry = parameters.MinimumRetry; _minimumReload = parameters.MinimumReload; _maximumReload = parameters.MaximumReload; _excessiveDuration = parameters.ExcessiveDuration; _abortTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_cancellationToken); _isDynamicPlaylist = true; _readTask = new SignalTask(ReadSubList, _abortTokenSource.Token); _segmentsExpiration = Environment.TickCount; Playlist = new PlaylistEnumerable(this); }
public ValueSetWorkerQueue(Func <ValueSet, Task> handler) { _signalTask = new SignalTask(async() => { for (; ;) { ValueSet valueSet; lock (_queue) { if (_queue.Count < 1) { break; } valueSet = _queue.Dequeue(); } try { await handler(valueSet).ConfigureAwait(false); } catch (Exception ex) { Debug.WriteLine("NotifierQueue handler failed: " + ex.ExtendedMessage()); } } }); }
public async Task StartAsync() { this.ThrowIfDisposed(); this._cancellationToken.ThrowIfCancellationRequested(); SignalTask oldReadTask = (SignalTask)null; CancellationTokenSource cancellationTokenSource = (CancellationTokenSource)null; bool lockTaken = false; object obj; try { Monitor.Enter(obj = this._segmentLock, ref lockTaken); if (!this._isRunning) { if (this._abortTokenSource.IsCancellationRequested) { cancellationTokenSource = this._abortTokenSource; this._abortTokenSource = CancellationTokenSource.CreateLinkedTokenSource(this._cancellationToken); oldReadTask = this._readTask; this._readTask = new SignalTask(new Func <Task>(this.ReadSubList), this._abortTokenSource.Token); } this._isRunning = true; } else { goto label_15; } } finally { if (lockTaken) { Monitor.Exit(obj); } } await HlsPlaylistSegmentManager.CleanupReader(oldReadTask, cancellationTokenSource).ConfigureAwait(false); if (this._programStream.Segments != null && this._programStream.Segments.Count > 0) { this.UpdatePlaylist(); } ISegment segment = await AsyncEnumerableExtensions.FirstOrDefaultAsync <ISegment>(this.Playlist).ConfigureAwait(false); if (null == segment) { Debug.WriteLine("HlsPlaylistSegmentManager.StartAsync() no segments found"); throw new FileNotFoundException("Unable to find the first segment"); } this.ContentType = await this._programStream.GetContentTypeAsync(this._cancellationToken).ConfigureAwait(false); this.WebReader = WebReaderExtensions.CreateChild(this._programStream.WebReader, (Uri)null, ContentKind.AnyMedia, this.ContentType); label_15 :; }
public BufferingManager(IBufferingPolicy bufferingPolicy, ITsPesPacketPool packetPool) { if (null == bufferingPolicy) { throw new ArgumentNullException("bufferingPolicy"); } if (null == packetPool) { throw new ArgumentNullException("packetPool"); } this._bufferingPolicy = bufferingPolicy; this._packetPool = packetPool; this._refreshTask = new SignalTask((Func <Task>)(() => { this.RefreshHandler(); return(TplTaskExtensions.CompletedTask); }), this._disposeCancellationTokenSource.Token); }
private async Task CleanupReader() { SignalTask readTask; CancellationTokenSource cancellationTokenSource; lock (_segmentLock) { readTask = _readTask; cancellationTokenSource = _abortTokenSource; _abortTokenSource = null; } await CleanupReader(readTask, cancellationTokenSource).ConfigureAwait(false); lock (_segmentLock) { _readTask = null; } }
public async Task StartAsync() { ThrowIfDisposed(); _cancellationToken.ThrowIfCancellationRequested(); SignalTask oldReadTask = null; CancellationTokenSource cancellationTokenSource = null; lock (_segmentLock) { if (!_isRunning) { if (_abortTokenSource.IsCancellationRequested) { cancellationTokenSource = _abortTokenSource; _abortTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_cancellationToken); oldReadTask = _readTask; _readTask = new SignalTask(ReadSubList, _abortTokenSource.Token); } _isRunning = true; } else { return; } } await CleanupReader(oldReadTask, cancellationTokenSource).ConfigureAwait(false); if (_programStream.Segments != null && _programStream.Segments.Count > 0) { UpdatePlaylist(); } var segment = await Playlist.FirstOrDefaultAsync().ConfigureAwait(false); if (null == segment) { Debug.WriteLine("HlsPlaylistSegmentManager.StartAsync() no segments found"); throw new FileNotFoundException("Unable to find the first segment"); } ContentType = await _programStream.GetContentTypeAsync(_cancellationToken).ConfigureAwait(false); WebReader = _programStream.WebReader.CreateChild(null, ContentKind.AnyMedia, ContentType); }
private async Task CleanupReader() { bool lockTaken1 = false; SignalTask readTask; CancellationTokenSource cancellationTokenSource; object obj1; try { Monitor.Enter(obj1 = this._segmentLock, ref lockTaken1); readTask = this._readTask; cancellationTokenSource = this._abortTokenSource; this._abortTokenSource = (CancellationTokenSource)null; } finally { if (lockTaken1) { Monitor.Exit(obj1); } } await HlsPlaylistSegmentManager.CleanupReader(readTask, cancellationTokenSource).ConfigureAwait(false); bool lockTaken2 = false; object obj2; try { Monitor.Enter(obj2 = this._segmentLock, ref lockTaken2); this._readTask = (SignalTask)null; } finally { if (lockTaken2) { Monitor.Exit(obj2); } } }
public void Initialize(IQueueThrottling queueThrottling, Action reportBufferingChange) { Debug.WriteLine("BufferingManager.Initialize()"); if (null == queueThrottling) { throw new ArgumentNullException("queueThrottling"); } if (reportBufferingChange == null) { throw new ArgumentNullException("reportBufferingChange"); } this.ThrowIfDisposed(); if (null != Interlocked.CompareExchange <IQueueThrottling>(ref this._queueThrottling, queueThrottling, (IQueueThrottling)null)) { throw new InvalidOperationException("The buffering manager is in use"); } this.HandleStateChange(); this._reportingTask = new SignalTask((Func <Task>)(() => { reportBufferingChange(); return(TplTaskExtensions.CompletedTask); }), this._disposeCancellationTokenSource.Token); }
public SmMediaManager(ISegmentReaderManagerFactory segmentReaderManagerFactory, IMediaStreamConfigurator mediaStreamConfigurator, Func <IBufferingManager> bufferingManagerFactory, IMediaManagerParameters mediaManagerParameters, IMediaParserFactory mediaParserFactory) { if (null == segmentReaderManagerFactory) { throw new ArgumentNullException("segmentReaderManagerFactory"); } if (null == mediaStreamConfigurator) { throw new ArgumentNullException("mediaStreamConfigurator"); } if (null == bufferingManagerFactory) { throw new ArgumentNullException("bufferingManagerFactory"); } _segmentReaderManagerFactory = segmentReaderManagerFactory; _mediaStreamConfigurator = mediaStreamConfigurator; _bufferingManagerFactory = bufferingManagerFactory; _mediaParserFactory = mediaParserFactory; _programStreamsHandler = mediaManagerParameters.ProgramStreamsHandler; _playbackCancellationTokenSource.Cancel(); _playbackTaskCompletionSource.TrySetResult((object)null); _reportStateTask = new SignalTask(ReportState); }