コード例 #1
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;
            }
        }
コード例 #2
0
        private async Task StopReadingAsync()
        {
            CallbackReader callbackReader = this._callbackReader;

            if (null != callbackReader)
            {
                try
                {
                    await callbackReader.StopAsync().ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("MediaReader.StopReadingAsync(): callback reader stop failed: " + ex.Message);
                }
            }
        }
コード例 #3
0
 public void Dispose()
 {
     if (0 != Interlocked.Exchange(ref this._isDisposed, 1))
     {
         return;
     }
     using (this._callbackReader)
         ;
     using (this._queueWorker)
         ;
     using (this._blockingPool)
         ;
     using (this._mediaParser)
         ;
     this._callbackReader   = (CallbackReader)null;
     this._queueWorker      = (QueueWorker <WorkBuffer>)null;
     this._blockingPool     = (IBlockingPool <WorkBuffer>)null;
     this._mediaParser      = (IMediaParser)null;
     this._bufferingManager = (IBufferingManager)null;
     this._segmentReaders   = (ISegmentManagerReaders)null;
 }