예제 #1
0
        private IRepresentationStream CreateBaseURLRepresentationStream()
        {
            Dynamic.TimeRange periodRange = null;
            if (Period.Start != null && Period.Duration != null)
            {
                periodRange = new Dynamic.TimeRange(Period.Start.Value, Period.Duration.Value);
            }

            URI media_uri = AdaptationSet.CalcURL();

            foreach (BaseURL url in BaseURLs)
            {
                if (!string.IsNullOrEmpty(url.BaseUrlValue))
                {
                    media_uri = media_uri.With(url.BaseUrlValue);
                }
            }

            Dynamic.SegmentBase segBase     = SegmentBase();
            var      presentationTimeOffset = segBase.PresentationTimeOffset ?? 0;
            TimeSpan availabilityTimeOffset = segBase.AvailabilityTimeOffset.HasValue ?
                                              TimeSpan.FromSeconds(segBase.AvailabilityTimeOffset.Value) : TimeSpan.MaxValue;

            // Live content elements from Segment Base...
            // Can we have this changing dynamically and available at given time?
            // God forbids...

            return(new Dynamic.BaseRepresentationStream(
                       null,
                       new Dynamic.Segment(media_uri.Uri, null, periodRange),
                       presentationTimeOffset, segBase.TimeShiftBufferDepth,
                       availabilityTimeOffset, segBase.AvailabilityTimeComplete));
        }
예제 #2
0
        private IRepresentationStream CreateListRepresentationStream()
        {
            Dynamic.SegmentList seg     = SegmentList();
            Dynamic.SegmentBase segBase = SegmentBase();

            URL init_url = GetFirst(seg.Initializations) ?? GetFirst(segBase.Initializations);
            URI init_uri = null;

            if (init_url?.SourceURL != null)
            {
                init_uri = AdaptationSet.CalcURL()?.With(init_url.SourceURL);
            }

            // If we still have no init URI, construct one based on BaseURL
            // for that purpose, index range from URL is required. Don't even try without it
            if (init_uri == null && init_url?.Range != null)
            {
                if (this.BaseURL == null)
                {
                    throw new ArgumentNullException("the BaseURL is null");
                }
                init_uri = new URI(this.BaseURL);
            }

            Dynamic.Segment init = init_uri == null ? null : new Dynamic.Segment(init_uri.Uri, init_url?.Range);

            // Live content elements from Segment Base...
            var      presentationTimeOffset = seg.PresentationTimeOffset ?? 0;
            TimeSpan availabilityTimeOffset = seg.AvailabilityTimeOffset.HasValue ?
                                              TimeSpan.FromSeconds(seg.AvailabilityTimeOffset.Value) : TimeSpan.MaxValue;

            Dynamic.ListItem[] items = Dynamic.ListItem.FromXml(
                seg.StartNumber ?? 1,
                Period.Start ?? new TimeSpan(0),
                seg.Timescale ?? 1,
                seg.Duration ?? 0,
                seg.SegmentURLs,
                this.BaseURL);
            return(new Dynamic.ListRepresentationStream(CalcURL().Uri, init, seg.Timescale ?? 1,
                                                        items,
                                                        presentationTimeOffset, seg.TimeShiftBufferDepth,
                                                        availabilityTimeOffset, seg.AvailabilityTimeComplete));
        }
예제 #3
0
        private IRepresentationStream CreateBaseRepresentationStream()
        {
            Dynamic.TimeRange periodRange = null;
            if (Period.Start != null && Period.Duration != null)
            {
                periodRange = new Dynamic.TimeRange(Period.Start.Value, Period.Duration.Value);
            }

            Dynamic.SegmentBase seg = SegmentBase();
            URL init_url            = GetFirst(seg.Initializations);

            string index_range = seg.IndexRange;

            // Live content elements from Segment Base...
            var      presentationTimeOffset = seg.PresentationTimeOffset ?? 0;
            TimeSpan availabilityTimeOffset = seg.AvailabilityTimeOffset.HasValue ?
                                              TimeSpan.FromSeconds(seg.AvailabilityTimeOffset.Value) : TimeSpan.MaxValue;


            URI media_uri = CalcURL();
            URI init_uri  = null;

            // If the init_url.SourceUrl is present,
            // it is relative to AdaptiveSet, not Representation.
            // Representation's BaseURI is for media only.
            if (init_url?.SourceURL != null)
            {
                init_uri = AdaptationSet.CalcURL()?.With(init_url.SourceURL);
            }
            else if (init_url != null)
            {
                init_uri = media_uri;
            }

            if (init_uri == null)
            {
                if (media_uri == null)
                {
                    return(null);
                }

                Dynamic.Segment media = new Dynamic.Segment(media_uri.Uri, null, periodRange);
                Dynamic.Segment index = index_range.Length != 0 ? new Dynamic.Segment(media_uri.Uri, index_range) : null;
                return(new Dynamic.BaseRepresentationStream(null, media,
                                                            presentationTimeOffset, seg.TimeShiftBufferDepth,
                                                            availabilityTimeOffset, seg.AvailabilityTimeComplete,
                                                            index));
            }

            if (media_uri == null)
            {
                return(null);
            }

            return(new Dynamic.BaseRepresentationStream(
                       new Dynamic.Segment(init_uri.Uri, init_url?.Range),
                       new Dynamic.Segment(media_uri.Uri, null, periodRange),
                       presentationTimeOffset, seg.TimeShiftBufferDepth,
                       availabilityTimeOffset, seg.AvailabilityTimeComplete,
                       index_range.Length != 0? new Dynamic.Segment(init_uri.Uri, index_range):null));
        }