Пример #1
0
        private Segment MakeSegment(TimelineItem item, uint repeat)
        {
            ulong  start = item.Time + (item.Duration * repeat);
            string uri   = media.Get(bandwidth, reprId, item.Number + repeat, start);

            return(MakeSegment(uri, new TimeRange(Scaled(start), Scaled(item.Duration))));
        }
Пример #2
0
        public static TimelineItem[] FromDuration(uint startNumber, TimeSpan start, TimeSpan duration, ulong segDuration, ulong timescale)
        {
            ulong    totalDuration  = (ulong)Math.Ceiling(duration.TotalSeconds * timescale);
            ulong    totalStart     = (ulong)Math.Ceiling(start.TotalSeconds * timescale);
            TimeSpan scaledDuration = TimeSpan.FromSeconds((double)segDuration / timescale);

            ulong count = totalDuration / segDuration;
            ulong end   = count * segDuration;

            TimelineItem[] result = new TimelineItem[totalDuration == end ? 1 : 2];
            result[0].Number   = startNumber;
            result[0].Time     = totalStart;
            result[0].Duration = segDuration;
            result[0].Repeats  = (count - 1);

            if (totalDuration != end)
            {
                result[1].Number   = startNumber + count;
                result[1].Time     = totalStart + end;
                result[1].Duration = totalDuration - end;
                result[1].Repeats  = 0;
            }

            return(result);
        }
Пример #3
0
        public static TimelineItem[] FromXml(uint startNumber, TimeSpan periodStart, TimeSpan?periodEnd, uint timescale, S[] esses)
        {
            ulong offset = (ulong)Math.Ceiling(periodStart.TotalSeconds * timescale);
            ulong start  = 0;

            TimelineItem[] result = new TimelineItem[esses.Length];
            for (int i = 0; i < esses.Length; ++i)
            {
                S s = esses[i];
                if (s.D == null)
                {
                    return(null);
                }

                start = s.T ?? start;

                uint count = 1;
                int  rep   = s.R ?? -1; // non-existing and invalid @r should be treated the same:
                if (rep < 0)
                {
                    if (i < (esses.Length - 1))
                    {
                        // if t[s+1] is present, then r[s] is the ceil of (t[s+1] - t[s])/d[s]
                        ulong nextStart = esses[i + 1].T ?? (start + s.D.Value);
                        ulong chunks    = (ulong)Math.Ceiling(((double)nextStart - start) / s.D.Value);
                        rep = (int)chunks - 1;
                    }
                    else
                    {
                        // else r[s] is the ceil of (PEwc[i] - PSwc[i] - t[s]/ts)*ts/d[s])
                        ulong totalEnd = periodEnd == null ? start + s.D.Value :
                                         (ulong)Math.Ceiling(periodEnd.Value.TotalSeconds * timescale);
                        ulong chunks = (ulong)Math.Ceiling(((double)totalEnd - offset - start) / s.D.Value);
                        rep = (int)chunks - 1;
                    }
                }
                count += (uint)rep;

                result[i].Number   = startNumber;
                result[i].Time     = start + offset;
                result[i].Duration = s.D.Value;
                result[i].Repeats  = (ulong)count - 1;

                start       += s.D.Value * count;
                startNumber += count;
            }
            return(result);
        }