private async Task <IMediaReader> CreateReaderPipeline(ISegmentManagerReaders segmentManagerReaders)
        {
            MediaReader reader = new MediaReader(this._bufferingManagerFactory(), this._mediaParserFactory, segmentManagerReaders, (IBlockingPool <WorkBuffer>) new WorkBufferBlockingPool(8));
            await reader.InitializeAsync(segmentManagerReaders, new Action(this.CheckConfigurationCompleted), new Action(this._mediaStreamConfigurator.CheckForSamples), this._playbackCancellationTokenSource.Token, this._programStreamsHandler).ConfigureAwait(false);

            return((IMediaReader)reader);
        }
Example #2
0
        public async Task InitializeAsync(ISegmentManagerReaders segmentManagerReaders, Action checkConfiguration, Action checkForSamples, CancellationToken cancellationToken, Action <IProgramStreams> programStreamsHandler)
        {
            this._checkConfiguration = checkConfiguration;
            Task        startReaderTask          = this._segmentReaders.Manager.StartAsync();
            MediaReader localReader              = this;
            QueueWorker <WorkBuffer> queueWorker = new QueueWorker <WorkBuffer>((Action <WorkBuffer>)(wi =>
            {
                IMediaParser mediaParser = localReader._mediaParser;
                if (null == wi)
                {
                    mediaParser.ProcessEndOfData();
                }
                else
                {
                    if (null != wi.Metadata)
                    {
                        mediaParser.StartSegment(wi.Metadata);
                        wi.Metadata = (ISegmentMetadata)null;
                    }
                    mediaParser.ProcessData(wi.Buffer, 0, wi.Length);
                }
            }), (Action <WorkBuffer>)(buffer => this._blockingPool.Free(buffer)));

            this._queueWorker    = queueWorker;
            this._callbackReader = new CallbackReader(segmentManagerReaders.Readers, new Action <WorkBuffer>(queueWorker.Enqueue), this._blockingPool);
            this._bufferingManager.Initialize((IQueueThrottling)queueWorker, checkForSamples);
            try
            {
                await startReaderTask.ConfigureAwait(false);

                ContentType contentType = this._segmentReaders.Manager.ContentType;
                if ((ContentType)null == contentType)
                {
                    Debug.WriteLine("MediaReader.CreateReaderPipeline() unable to determine content type, defaulting to transport stream");
                    contentType = ContentTypes.TransportStream;
                }
                else if (ContentTypes.Binary == contentType)
                {
                    Debug.WriteLine("MediaReader.CreateReaderPipeline() detected binary content, defaulting to transport stream");
                    contentType = ContentTypes.TransportStream;
                }
                MediaParserParameters mediaParserParameters = new MediaParserParameters();
                this._mediaParser = await this._mediaParserFactory.CreateAsync((IMediaParserParameters)mediaParserParameters, contentType, cancellationToken).ConfigureAwait(false);

                if (null == this._mediaParser)
                {
                    throw new NotSupportedException("Unsupported content type: " + (object)contentType);
                }
                this._mediaParser.ConfigurationComplete += new EventHandler(this.ConfigurationComplete);
                this._mediaParser.Initialize(this._bufferingManager, programStreamsHandler);
                this._mediaParser.InitializeStream(this._segmentReaders.Manager.StreamMetadata);
            }
            catch (Exception ex)
            {
                this._bufferingManager.Shutdown((IQueueThrottling)queueWorker);
                throw;
            }
        }
Example #3
0
        async Task<IMediaReader> CreateReaderPipeline(ISegmentManagerReaders segmentManagerReaders)
        {
            var reader = new MediaReader(_bufferingManagerFactory(), _mediaParserFactory, segmentManagerReaders, new WorkBufferBlockingPool(MaxBuffers));

            await reader.InitializeAsync(segmentManagerReaders, CheckConfigurationCompleted,
                _mediaStreamConfigurator.CheckForSamples,
                _playbackCancellationTokenSource.Token, _programStreamsHandler)
                .ConfigureAwait(false);

            return reader;
        }