示例#1
0
        private PlaylistSegmentBuildData CreatePlaylistSegmentBuildData(DateTime stopTime)
        {
            var data = new PlaylistSegmentBuildData();

            data.StartTime = this.StartTime; // this.StartTime;
            data.StopTime  = this.StopTime ?? stopTime;

            for (int i = 0; i < _playItems.Count; i++)
            {
                ScheduleItem item = new ScheduleItem(_playItems[i]);
                if (item.ScheduleMode == PlayScheduleMode.Auto)
                {
                    data.AddAuto(item);
                }
                else
                {
                    data.InsertTiming(item);
                }
            }

            if (_newTimingBreakItems != null)
            {
                var newTimingBreakList = _newTimingBreakItems.Values;

                for (int i = 0; i < newTimingBreakList.Count; i++)
                {
                    ScheduleItem item = new ScheduleItem(newTimingBreakList[i]);
                    data.InsertTiming(item);
                }
            }

            return(data);
        }
示例#2
0
 internal IPlaylistSegmentBuilder CreateBuilder(DateTime maxStopTime)
 {
     if (this.IsDirty)
     {
         PlaylistSegmentBuildData buildData = CreatePlaylistSegmentBuildData(maxStopTime);
         return(new PlaylistSegmentBuilder(buildData));
     }
     else
     {
         return(new NullPlaylistSegmentBuilder(_playItems));
     }
 }
示例#3
0
        private void Build(PlaylistSegmentBuildData data)
        {
            ScheduleItem autoItem        = null;
            ScheduleItem timingBreakItem = null;

            DateTime startTime = data.StartTime;

            ScheduleItem timingItem = data.TakeTiming();

            if (timingItem != null)
            {
                data.AddResult(timingItem);
                startTime = timingItem.CalculatedStopTime;
            }

            autoItem        = data.TakeAuto();
            timingBreakItem = data.TakeTimingBreak();

            while (startTime < data.StopTime && (autoItem != null || timingBreakItem != null))
            {
                if (timingBreakItem != null)
                {
                    #region 1
                    if (startTime < timingBreakItem.StartTime)
                    {
                        #region 1.1
                        TimeSpan maxDuration = timingBreakItem.StartTime.Subtract(startTime);
                        if (autoItem != null)
                        {
                            autoItem.StartTime = startTime;
                            if (maxDuration >= autoItem.CalculatedPlayDuration)
                            {
                                data.AddResult(autoItem);
                                startTime = autoItem.CalculatedStopTime;

                                autoItem = data.TakeAuto();
                            }
                            else
                            {
                                // 分片。
                                ScheduleItem first  = null;
                                ScheduleItem second = null;
                                autoItem.Split(maxDuration, out first, out second);
                                first.StartTime = startTime;
                                data.AddResult(first);
                                startTime = first.CalculatedStopTime;
                                autoItem  = second;
                            }
                        }
                        else
                        {
                            // 插入自动垫片。
                            ScheduleItem autoPadding = CreateAutoPadding(startTime, maxDuration);
                            data.AddResult(autoPadding);
                            startTime = autoPadding.CalculatedStopTime;
                        }
                        #endregion 1.1
                    }
                    else
                    {
                        // 插入定时插播。
                        #region 1.2
                        Debug.Assert(startTime == timingBreakItem.StartTime);

                        data.AddResult(timingBreakItem);
                        startTime       = timingBreakItem.CalculatedStopTime;
                        timingBreakItem = data.TakeTimingBreak();
                        #endregion 1.2
                    }
                    #endregion 1
                }
                else
                {
                    #region 2
                    var maxDuration = data.StopTime.Subtract(startTime);
                    autoItem.StartTime = startTime;
                    if (autoItem.CalculatedPlayDuration > maxDuration)
                    {
                        // 截短。
                        autoItem.CalculatedPlayDuration = maxDuration;
                    }
                    data.AddResult(autoItem);
                    startTime = autoItem.CalculatedStopTime;
                    autoItem  = data.TakeAuto();
                    #endregion 2
                }
            }

            // startTime>=data.StopTime || (autoItem==null && timingBreakItem==null)
            Debug.Assert(timingBreakItem == null);

            while (autoItem != null)
            {
                // 完全截断。
                autoItem.StartTime = data.StopTime;
                autoItem.CalculatedPlayDuration = TimeSpan.Zero;

                data.AddResult(autoItem);
                autoItem = data.TakeAuto();
            }

            if (startTime < data.StopTime && data.StopTime != DateTime.MaxValue)
            {
                // 插入自动垫片。
                ScheduleItem autoPadding = CreateAutoPadding(startTime, data.StopTime.Subtract(startTime));
                data.AddResult(autoPadding);
                startTime = autoPadding.CalculatedStopTime;
            }

            //return data.Result;
        }
示例#4
0
 public PlaylistSegmentBuilder(PlaylistSegmentBuildData data)
 {
     this.Build(data);
     _scheduleItems = data.Result;
 }