コード例 #1
0
        public virtual async Task <TMediaStreamSource> CreateMediaStreamSourceAsync(Uri source, CancellationToken cancellationToken)
        {
            Debug.WriteLine("MediaStreamFacadeBase.CreateMediaStreamSourceAsync() " + (object)source);
            if ((Uri)null != source && !source.IsAbsoluteUri)
            {
                throw new ArgumentException("source must be absolute: " + (object)source);
            }
            CancellationTokenSource closeCts = CancellationTokenSource.CreateLinkedTokenSource(this._disposeCancellationTokenSource.Token);

            if (!this._closeCancellationTokenSource.IsCancellationRequested)
            {
                this._closeCancellationTokenSource.Cancel();
            }
            Exception          exception;
            TMediaStreamSource mediaStreamSource;

            try
            {
                using (CancellationTokenSource linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, closeCts.Token))
                {
                    linkedTokenSource.CancelAfter(MediaStreamFacadeSettings.Parameters.CreateTimeout);
                    IMediaManager mediaManager = this.MediaManager;
                    if (null != mediaManager)
                    {
                        await this.StopMediaAsync(mediaManager, linkedTokenSource.Token).ConfigureAwait(false);
                    }
                    this._closeCancellationTokenSource.Dispose();
                    this._closeCancellationTokenSource = closeCts;
                    if ((Uri)null == source)
                    {
                        mediaStreamSource = default(TMediaStreamSource);
                        goto label_21;
                    }
                    else
                    {
                        IMediaManager mediaManager1 = this.MediaManager;
                        if (mediaManager1 == null)
                        {
                            mediaManager1 = await this.CreateMediaManagerAsync(linkedTokenSource.Token).ConfigureAwait(false);
                        }
                        mediaManager = mediaManager1;
                        IMediaStreamConfigurator configurator = await mediaManager.OpenMediaAsync((ICollection <Uri>) new Uri[1]
                        {
                            source
                        }, linkedTokenSource.Token).ConfigureAwait(false);

                        TMediaStreamSource mss = await configurator.CreateMediaStreamSourceAsync <TMediaStreamSource>(linkedTokenSource.Token).ConfigureAwait(false);

                        mediaStreamSource = mss;
                        goto label_21;
                    }
                }
            }
            catch (OperationCanceledException ex)
            {
                exception = (Exception)ex;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("MediaStreamFacadeBase.CreateAsync() failed: " + ExceptionExtensions.ExtendedMessage(ex));
                exception = (Exception) new AggregateException(ex.Message, ex);
            }
            await this.CloseAsync().ConfigureAwait(false);

            throw exception;
label_21:
            return(mediaStreamSource);
        }