Exemplo n.º 1
0
        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);
                    }
                }
            });
        }
Exemplo n.º 2
0
        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());
                    }
                }
            });
        }
Exemplo n.º 3
0
        public AudioMetadataHandler(CancellationToken cancellationToken)
        {
            _updateTask = new SignalTask(Update, cancellationToken);

            _metadataSink = new ActionMetadataSink(_updateTask.Fire);

            _timer = new Timer(obj => ((AudioMetadataHandler)obj).Refresh(), this, Timeout.Infinite, Timeout.Infinite);
        }
Exemplo n.º 4
0
        protected MediaDumpBase(Action<IProgramStreams> programStreamsHandler)
        {
            _programStreamsHandler = programStreamsHandler;
            BufferPool = new BufferPool(new DefaultBufferPoolParameters
            {
                BaseSize = 5 * 64 * 1024,
                Pools = 2
            });

            PacketPool = new TsPesPacketPool(BufferPool);
            _bufferingManager = new NullBufferingManager(PacketPool);

            _streamReader = new SignalTask(ReadStreams);
        }
Exemplo n.º 5
0
        public BufferingManager(IBufferingPolicy bufferingPolicy, ITsPesPacketPool packetPool)
        {
            if (null == bufferingPolicy)
                throw new ArgumentNullException(nameof(bufferingPolicy));
            if (null == packetPool)
                throw new ArgumentNullException(nameof(packetPool));

            _bufferingPolicy = bufferingPolicy;
            _packetPool = packetPool;

            _refreshTask = new SignalTask(() =>
            {
                RefreshHandler();

                return TplTaskExtensions.CompletedTask;
            }, _disposeCancellationTokenSource.Token);
        }
Exemplo n.º 6
0
        public MetadataHandler(SystemMediaTransportControls systemMediaTransportControls, ForegroundNotifier notifier, Func<TimeSpan> getPosition, Action<TimeSpan> reportNextEvent, CancellationToken cancellationToken)
        {
            if (null == systemMediaTransportControls)
                throw new ArgumentNullException(nameof(systemMediaTransportControls));
            if (null == notifier)
                throw new ArgumentNullException(nameof(notifier));
            if (null == getPosition)
                throw new ArgumentNullException(nameof(getPosition));
            if (null == reportNextEvent)
                throw new ArgumentNullException(nameof(reportNextEvent));

            _systemMediaTransportControls = systemMediaTransportControls;
            _notifier = notifier;
            _getPosition = getPosition;
            _reportNextEvent = reportNextEvent;

            _updateTask = new SignalTask(Update, cancellationToken);

            _metadataSink = new ActionMetadataSink(_updateTask.Fire);
        }
Exemplo n.º 7
0
        public SingleStreamMediaManager(Func<IBufferingManager> bufferingManagerFactory, IMediaParserFactory mediaParserFactory,
            IMediaStreamConfigurator mediaStreamConfigurator, IWebMetadataFactory webMetadataFactory, IWebReaderManager webReaderManager)
        {
            if (null == bufferingManagerFactory)
                throw new ArgumentNullException(nameof(bufferingManagerFactory));
            if (null == mediaParserFactory)
                throw new ArgumentNullException(nameof(mediaParserFactory));
            if (null == mediaStreamConfigurator)
                throw new ArgumentNullException(nameof(mediaStreamConfigurator));
            if (null == webMetadataFactory)
                throw new ArgumentNullException(nameof(webMetadataFactory));
            if (null == webReaderManager)
                throw new ArgumentNullException(nameof(webReaderManager));

            _bufferingManagerFactory = bufferingManagerFactory;
            _mediaParserFactory = mediaParserFactory;
            _mediaStreamConfigurator = mediaStreamConfigurator;
            _webMetadataFactory = webMetadataFactory;
            _webReaderManager = webReaderManager;

            _reportStateTask = new SignalTask(ReportState);
        }
Exemplo n.º 8
0
        public SmMediaManager(ISegmentReaderManagerFactory segmentReaderManagerFactory,
            IMediaStreamConfigurator mediaStreamConfigurator, Func<IBufferingManager> bufferingManagerFactory,
            IMediaManagerParameters mediaManagerParameters, IMediaParserFactory mediaParserFactory)
        {
            if (null == segmentReaderManagerFactory)
                throw new ArgumentNullException(nameof(segmentReaderManagerFactory));
            if (null == mediaStreamConfigurator)
                throw new ArgumentNullException(nameof(mediaStreamConfigurator));
            if (null == bufferingManagerFactory)
                throw new ArgumentNullException(nameof(bufferingManagerFactory));

            _segmentReaderManagerFactory = segmentReaderManagerFactory;
            _mediaStreamConfigurator = mediaStreamConfigurator;
            _bufferingManagerFactory = bufferingManagerFactory;
            _mediaParserFactory = mediaParserFactory;
            _programStreamsHandler = mediaManagerParameters.ProgramStreamsHandler;

            // Start with a canceled token (i.e., we are not playing)
            _playbackCancellationTokenSource.Cancel();
            _playbackTaskCompletionSource.TrySetResult(null);

            _reportStateTask = new SignalTask(ReportState);
        }
 public FifoTaskScheduler(CancellationToken cancellationToken)
 {
     this._workerTask = new SignalTask(new Func <Task>(this.Worker), cancellationToken);
 }
Exemplo n.º 10
0
 public AsyncFifoWorker()
 {
     this._signalTask = new SignalTask(new Func <Task>(this.Worker));
 }
Exemplo n.º 11
0
 public AsyncFifoWorker(CancellationToken cancellationToken)
 {
     this._signalTask = new SignalTask(new Func <Task>(this.Worker), cancellationToken);
 }
Exemplo n.º 12
0
        public void Dispose()
        {
            if (0 != Interlocked.Exchange(ref _isDisposed, 1))
                return;

            _disposeCancellationTokenSource.Cancel();

            using (_refreshTask)
            { }

            using (_reportingTask)
            { }
            _reportingTask = null;

            _disposeCancellationTokenSource.Dispose();

            lock (_lock)
            {
                _queues.Clear();
            }

            var queueThrottling = Interlocked.Exchange(ref _queueThrottling, null);

            if (null != queueThrottling)
                Debug.WriteLine("**** BufferingManager.Dispose() _queueThrottling was not null");
        }
Exemplo n.º 13
0
 public FifoTaskScheduler(CancellationToken cancellationToken)
 {
     _workerTask = new SignalTask(Worker, cancellationToken);
 }
Exemplo n.º 14
0
 public QueueWorker(Action <TWorkItem> callback, Action <TWorkItem> cleanup)
 {
     this._callback   = callback;
     this._cleanup    = cleanup;
     this._workerTask = SignalTask.Create(new Action(this.Worker));
 }
Exemplo n.º 15
0
 public AsyncFifoWorker()
 {
     _signalTask = new SignalTask(Worker);
 }
Exemplo n.º 16
0
 public AsyncFifoWorker(CancellationToken cancellationToken)
 {
     _signalTask = new SignalTask(Worker, cancellationToken);
 }
Exemplo n.º 17
0
        public void Initialize(IQueueThrottling queueThrottling, Action reportBufferingChange)
        {
            Debug.WriteLine("BufferingManager.Initialize()");

            if (null == queueThrottling)
                throw new ArgumentNullException(nameof(queueThrottling));
            if (reportBufferingChange == null)
                throw new ArgumentNullException(nameof(reportBufferingChange));

            ThrowIfDisposed();

            if (null != Interlocked.CompareExchange(ref _queueThrottling, queueThrottling, null))
                throw new InvalidOperationException("The buffering manager is in use");

            HandleStateChange();

            _reportingTask = new SignalTask(() =>
            {
                reportBufferingChange();

                return TplTaskExtensions.CompletedTask;
            }, _disposeCancellationTokenSource.Token);
        }