Beispiel #1
0
        private int GetSegmentIndex(TimeSpan pointInTime)
        {
            if (Count == 0)
            {
                return(-1);
            }

            var             searcher = new TimelineSearchStartTimeDuration();
            TimelineItemRep lookFor  = new TimelineItemRep
            {
                TimeScaled = pointInTime
            };

            var idx = Array.BinarySearch(timelineAll, timelineAvailable.Offset, timelineAvailable.Count,
                                         lookFor, searcher);

            if (idx < 0)
            {
                Logger.Error($"Failed to find segment in @time. FA={timeline[0].TimeScaled} Req={pointInTime} LA={timeline[(int)Count - 1].TimeScaled}");
            }


            // Index Search is based on timelineAll. Access is done on timeline thus offset subtraction
            // In fail case, simply larger negative value will be returned.
            //
            return(idx - timelineAvailable.Offset);
        }
Beispiel #2
0
        private uint?GetStartSegmentDynamicFromTimeline()
        {
            var maxRange = timeline.Count;

            if (maxRange == 0)
            {
                return(null);
            }

            maxRange -= 1;
            var timeShiftBufferDepth = parameters.Document.TimeShiftBufferDepth ?? TimeSpan.Zero;

            // Start by Time is calculated as:
            // Start Segment Time = Representation Start Time +
            //                      First available segment - First segment in playlist +
            //                      1/4*timeShiftBufferDepth
            //
            // This implies that MAX buffer time for dynamic content is 3/4*timeShiftBufferDepth
            //
            var startTime = timeline[0].TimeScaled;

            startTime += TimeSpan.FromSeconds(timeShiftBufferDepth.TotalSeconds / 4);

            var             searcher = new TimelineSearchStartTimeDuration();
            TimelineItemRep lookFor  = new TimelineItemRep
            {
                TimeScaled = startTime
            };

            var idx = Array.BinarySearch(timelineAll, 0, timelineAll.Length,
                                         lookFor, searcher);

            if (idx < 0)
            {
                var last = timelineAll.Length - 1;
                Logger.Error($"Failed to find start segment @time. FAll={timelineAll[0].Number}/{timelineAll[0].TimeScaled} T={startTime} LAll={timelineAll[last].Number}/{timelineAll[last].TimeScaled}");
                return(null);
            }

            // Sanity check for availability
            if (timelineAll[idx].TimeToLive == TimeSpan.Zero)
            {
                var last = timelineAll.Length - 1;
                Logger.Error($"Start segment found {timelineAll[idx].Number} is unavailable FAll={timelineAll[0].Number}/{timelineAll[0].TimeScaled} T={startTime} TTL={timelineAll[idx].TimeToLive} LAll={timelineAll[last].Number}/{timelineAll[last].TimeScaled}");
                return(null);
            }
            return((uint?)timelineAll[idx].Number);
        }