public async Task <ISegmentManager> CreateAsync(ISegmentManagerParameters parameters, ContentType contentType, CancellationToken cancellationToken)
        {
            ISubProgram subProgram = await this._hlsPlaylistSegmentManagerPolicy.CreateSubProgramAsync(parameters.Source, contentType, cancellationToken).ConfigureAwait(false);

            HlsPlaylistSegmentManager segmentManager = new HlsPlaylistSegmentManager(subProgram.Video, this._platformServices, cancellationToken);

            return((ISegmentManager)segmentManager);
        }
Beispiel #2
0
 public PlaylistEnumerator(HlsPlaylistSegmentManager segmentManager)
 {
     if (null == segmentManager)
     {
         throw new ArgumentNullException("segmentManager");
     }
     this._segmentManager = segmentManager;
 }
Beispiel #3
0
        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 :;
        }
Beispiel #4
0
        private ISegment[] ResyncSegments()
        {
            ISegment[] segmentArray1 = (ISegment[])null;
            int        num           = -1;

            foreach (ISegment[] segmentArray2 in this._dynamicPlaylists)
            {
                num = segmentArray2.Length;
                if (null == segmentArray1)
                {
                    this._segmentList.AddRange((IEnumerable <ISegment>)segmentArray2);
                    segmentArray1 = segmentArray2;
                }
                else
                {
                    bool flag = false;
                    for (int index1 = 0; index1 < segmentArray1.Length; ++index1)
                    {
                        if (HlsPlaylistSegmentManager.SegmentsMatch(segmentArray1[index1], segmentArray2[0]))
                        {
                            for (int index2 = 1; index2 < segmentArray2.Length; ++index2)
                            {
                                if (index1 + index2 >= segmentArray1.Length || !HlsPlaylistSegmentManager.SegmentsMatch(segmentArray1[index1 + index2], segmentArray2[index2]))
                                {
                                    this._segmentList.Add(segmentArray2[index2]);
                                }
                            }
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        this._segmentList.AddRange((IEnumerable <ISegment>)segmentArray2);
                    }
                    segmentArray1 = segmentArray2;
                }
            }
            ISegment[] segmentArray3 = this._segmentList.ToArray();
            this._segmentList.Clear();
            this.SetDynamicStartIndex((IList <ISegment>)segmentArray3, segmentArray3.Length - num - 1);
            return(segmentArray3);
        }
Beispiel #5
0
        private void UnlockedUpdatePlaylist(bool isDynamicPlaylist, ISegment[] segments)
        {
            bool flag = false;

            if (isDynamicPlaylist || this._dynamicPlaylists.Count > 0)
            {
                ISegment[] segmentArray = Enumerable.LastOrDefault <ISegment[]>((IEnumerable <ISegment[]>) this._dynamicPlaylists);
                if (segments.Length > 0)
                {
                    if (segmentArray != null && HlsPlaylistSegmentManager.SegmentsMatch(segmentArray[0], segments[0]) && segmentArray.Length == segments.Length)
                    {
                        Debug.WriteLine("HlsPlaylistSegmentManager.UpdatePlaylist(): need reload ({0})", (object)DateTimeOffset.Now);
                        int num = Environment.TickCount + (int)Math.Round(2.0 * this._minimumRetry.TotalMilliseconds);
                        if (this._segmentsExpiration < num)
                        {
                            this._segmentsExpiration = num;
                        }
                        flag = true;
                    }
                    else
                    {
                        this._dynamicPlaylists.Add(segments);
                        if (this._dynamicPlaylists.Count > 4)
                        {
                            this._dynamicPlaylists.RemoveAt(0);
                        }
                    }
                }
                if (!flag)
                {
                    segments = this.ResyncSegments();
                    if (isDynamicPlaylist)
                    {
                        this.UpdateDynamicPlaylistExpiration((IList <ISegment>)segments);
                    }
                }
            }
            if (flag)
            {
                return;
            }
            this._segments = segments;
        }
Beispiel #6
0
        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);
                }
            }
        }