//public IList<IPlaylistItem> Build() //{ // DateTime startTime, stopTime; // if (_beginItem!=null && _endItem != null) // { // startTime = _beginItem.ScheduleInfo.StopTime; // stopTime = _endItem.ScheduleInfo.StartTime; // } // else // { // if (_beginItem != null) // { // startTime = _beginItem.ScheduleInfo.StopTime; // stopTime = DateTime.MaxValue; // } // else // _endItem != null // { // stopTime = _endItem.ScheduleInfo.StartTime; // if(_autoList.Count>0 && _breakList.Count > 0) // { // var autoStartTime = _autoList[0].ScheduleInfo.StartTime; // var breakStartTime = _breakList[0].ScheduleInfo.StartTime; // startTime = autoStartTime < breakStartTime ? autoStartTime : breakStartTime; // } // else if (_autoList.Count > 0) // { // startTime = _autoList[0].ScheduleInfo.StartTime; // } // else if (_breakList.Count > 0) // { // startTime = _breakList[0].ScheduleInfo.StartTime; // } // else // { // startTime = stopTime; // } // startTime = startTime > stopTime ? stopTime : startTime; // } // } // var result = new List<IPlaylistItem>(); // Build(startTime, stopTime, result); // return result; //} //private void Build(DateTime startTime, DateTime stopTime, IList<PlaybillItem> result) //{ // PlaybillItem autoItem = null; // PlaybillItem breakItem = null; // while (startTime < stopTime) // { // if (autoItem == null && _autoList.Count > 0) // { // autoItem = _autoList[0]; // _autoList.RemoveAt(0); // } // if (breakItem==null && _breakList.Count > 0) // { // autoItem = _breakList[0]; // _breakList.RemoveAt(0); // } // if(autoItem!=null && breakItem != null) // { // if (startTime < breakItem.ScheduleInfo.StartTime) // { // var duration = breakItem.ScheduleInfo.StartTime.Subtract(startTime); // if (duration >= autoItem.PlaySource.PlayRange.Duration) // { // duration = autoItem.PlaySource.PlayRange.Duration; // var info = autoItem.ScheduleInfo; // info = new ScheduleInfo(startTime, duration, info.ScheduleMode); // autoItem.ScheduleInfo = info; // result.Add(autoItem); // autoItem = null; // startTime = info.StopTime; // } // else // { // PlaybillItem first = null, second = null; // // 注:autoItem可能本身是个片断。 // Split(autoItem, duration, out first, out second); // var info = autoItem.ScheduleInfo; // info = new ScheduleInfo(startTime, duration, info.ScheduleMode); // first.ScheduleInfo = info; // result.Add(first); // autoItem = second; // startTime = info.StopTime; // } // } // else // { // Debug.Assert(startTime == breakItem.ScheduleInfo.StartTime); // result.Add(breakItem); // breakItem = null; // startTime = breakItem.ScheduleInfo.StopTime; // } // } // else if (autoItem != null) // breakItem == null // { // var duration = stopTime.Subtract(startTime); // if (duration >= autoItem.PlaySource.PlayRange.Duration) // { // duration = autoItem.PlaySource.PlayRange.Duration; // var info = autoItem.ScheduleInfo; // info = new ScheduleInfo(startTime, duration, info.ScheduleMode); // autoItem.ScheduleInfo = info; // result.Add(autoItem); // autoItem = null; // startTime = info.StopTime; // } // else // { // var info = autoItem.ScheduleInfo; // info = new ScheduleInfo(startTime, duration, info.ScheduleMode); // autoItem.ScheduleInfo = info; // result.Add(autoItem); // autoItem = null; // startTime = info.StopTime; // } // } // else if (breakItem != null) // autoItem == null // { // if (startTime < breakItem.ScheduleInfo.StartTime) // { // var duration = breakItem.ScheduleInfo.StartTime.Subtract(startTime); // PlaybillItem autoPaddingItem = CreateAutoPaddingItem(startTime, duration); // result.Add(autoPaddingItem); // startTime = autoPaddingItem.ScheduleInfo.StopTime; // breakItem.ScheduleInfo.StartTime; // } // else // { // Debug.Assert(startTime == breakItem.ScheduleInfo.StartTime); // result.Add(breakItem); // startTime = breakItem.ScheduleInfo.StopTime; // breakItem = null; // } // } // else // { // if (stopTime != DateTime.MaxValue) // { // PlaybillItem autoPaddingItem = CreateAutoPaddingItem(startTime, stopTime.Subtract(startTime)); // result.Add(autoPaddingItem); // } // startTime = stopTime; // } // } // Debug.Assert(_breakList.Count == 0); // while (_autoList.Count > 0) // { // autoItem = _autoList[0]; // _autoList.RemoveAt(0); // var info = autoItem.ScheduleInfo; // info = new ScheduleInfo(startTime, TimeSpan.Zero, info.ScheduleMode); // autoItem.ScheduleInfo = info; // result.Add(autoItem); // } //} private PlaybillItem CreateAutoPaddingItem(DateTime startTime, TimeSpan duration) { var result = PlaybillItem.CreateAutoPadding(duration); result.ScheduleInfo = new ScheduleInfo(startTime, duration, ScheduleMode.Auto); return(result); }
public void Dispose() { _autoList.Clear(); _breakList.Clear(); _resultList.Clear(); _timingItem = null; _beginTime = null; _endTime = null; }
public override PlaybillItem Merge(PlaybillItem nextItem) { if (!CanMerge(nextItem)) { throw new InvalidOperationException(); } // Note: 是否在自动垫片上操作? PlaySource mergedSource = ((PlaySourceSegment)this.PlaySource).Merge(nextItem.PlaySource); return(CreateInternal(mergedSource)); }
public override bool CanMerge(PlaybillItem nextItem) { if (nextItem == null) { throw new ArgumentNullException("nextItem"); } // Note: 是否在自动垫片上操作? var segment = this.PlaySource as PlaySourceSegment; return(segment != null?segment.CanMerge(nextItem.PlaySource) : false); }
private void AddAuto(PlaybillItem playbillItem) { if (!playbillItem.IsAutoPadding()) // 移除自动垫片。 { PlaybillItem prevItem = _autoList.Count > 0 ? _autoList[_autoList.Count - 1] : null; if (prevItem != null && prevItem.CanMerge(playbillItem)) { _autoList[_autoList.Count - 1] = prevItem.Merge(playbillItem); } else { _autoList.Add(playbillItem); } } }
internal void Set(DateTime beginTime, DateTime endTime, PlaybillItem timingItem) { Debug.Assert(beginTime < endTime); if (timingItem != null) { if (timingItem.ScheduleMode != ScheduleMode.Timing) { throw new ArgumentException("必须是定时播。", "timingItem"); } Debug.Assert(beginTime <= timingItem.ScheduleInfo.StartTime && endTime >= timingItem.ScheduleInfo.StopTime); } _beginTime = beginTime; _endTime = endTime; _timingItem = timingItem; }
public PlaybillItem TakeTiming() { PlaybillItem breakItem = null; PlaybillItem result = null; if (_breakList.Count > 0) { breakItem = _breakList[0]; } if (_timingItem != null && breakItem != null) { if (_timingItem.ScheduleInfo.StartTime < breakItem.ScheduleInfo.StartTime) { result = _timingItem; _timingItem = null; } else { _breakList.RemoveAt(0); result = breakItem; } } else { if (_timingItem != null) { result = _timingItem; _timingItem = null; } else if (breakItem != null) { _breakList.RemoveAt(0); result = breakItem; } } return(result); }
public void Add(PlaybillItem playbillItem) { if (playbillItem == null) { throw new ArgumentNullException("playbillItem"); } var scheduleMode = playbillItem.ScheduleMode; if (scheduleMode != ScheduleMode.Auto && scheduleMode != ScheduleMode.TimingBreak) { throw new ArgumentException("必须是顺播或定时插播。", "playbillItem"); } if (scheduleMode == ScheduleMode.Auto) { AddAuto(playbillItem); } else { AddBreak(playbillItem); } }
public override void Split(TimeSpan duration, out PlaybillItem first, out PlaybillItem second) { if (duration <= TimeSpan.Zero) { throw new ArgumentOutOfRangeException("duration", string.Format("<{0}>无效,必须大于TimeSpan.Zero。", duration)); } // Note: 是否在自动垫片上操作? PlayRange firstRange, secondRange; this.PlaySource.Break(duration, out firstRange, out secondRange); var segment = this.PlaySource as PlaySourceSegment; NormalPlaySource source = segment != null ? segment.PlaySource : (NormalPlaySource)this.PlaySource; var firstSource = PlaySourceSegment.Create(source, firstRange); first = CreateInternal(firstSource); var secondSource = PlaySourceSegment.Create(source, secondRange); second = CreateInternal(secondSource); }
public static bool IsTimingBreak(this PlaybillItem playbillItem) { return(playbillItem.ScheduleMode == ScheduleMode.TimingBreak); }
public abstract PlaybillItem Merge(PlaybillItem nextItem);
public static bool IsTruncated(this PlaybillItem playbillItem) { // Note: 定时播和定时插播应该总是返回false。 return(playbillItem.ScheduleInfo.Duration < playbillItem.PlaySource.PlayRange.Duration); }
internal PlaylistSegmentBuildData GetBuidData(DateTime beginTime, DateTime endTime, PlaybillItem timingItem) { // ensure _buildData has no data. _buildData.Set(beginTime, endTime, timingItem); return(_buildData); }
public override void Split(TimeSpan duration, out PlaybillItem first, out PlaybillItem second) { throw new InvalidOperationException(); }
private void AddBreak(PlaybillItem breakItem) { Debug.Assert(_beginTime <= breakItem.ScheduleInfo.StartTime && _endTime >= breakItem.ScheduleInfo.StopTime); _breakList.Add(breakItem); }
private void AddTiming2(DateTime startTime, IPlaySource playSource) { // 验证操作的合法性。 ValidatePlayDuration(playSource.PlayRange.Duration); ValidateStartTime(startTime, false); EnsureNoTimingConflict(startTime, playSource.PlayRange.Duration); // 触发事件前置事件。 List <PlaybillItem> tempList = new List <PlaybillItem>(); // 重新计算调度信息。 DateTime beginTime; var prevIndex = _playlist.FindLastIndex(i => !i.IsSkipped() && i.ScheduleInfo.StopTime <= startTime); if (prevIndex == -1) { if (_playlist.Count == 0) { if (_playlist.HasMinStartTime() && _playlist.MinStartTime.Value < startTime) { beginTime = _playlist.MinStartTime.Value; } else { beginTime = startTime; } } else { beginTime = _playlist[0].ScheduleInfo.StartTime; // startTime; beginTime = beginTime > startTime ? startTime : beginTime; } // [prevIndex+1, index-1], 注:index-prevIndex+1 // 替换范围:[prevIndex+1, index-1] (删除的起始索引0==prevIndex+1,数量index==index-prevIndex-1) } else { beginTime = _playlist[prevIndex].ScheduleInfo.StopTime; // 注:prevIndex可能等于index-1。 // 当prevIndex小于index-1时。 // 替换范围:[prevIndex + 1, index-1] (删除的起始索引prevIndex + 1,数量index-prevIndex-1 ) // 当prevIndex等于index-1时。(删除的起始索引prevIndex + 1==index,数量index-prevIndex-1==0 ) // 在index处插入0个或1个。 } DateTime endTime; var nextIndex = _playlist.FindFirstIndex(prevIndex + 1, i => !i.IsSkipped() && i.ScheduleInfo.ScheduleMode == ScheduleMode.Timing && i.ScheduleInfo.StartTime > startTime); //beginTime = playItem.ScheduleInfo.StopTime; if (nextIndex == -1) { endTime = DateTime.MaxValue; nextIndex = _playlist.Count; // [index + 1, _playlist.Count - 1], 注:index + 1可能等于_playlist.Count - 1 // 替换范围:[index + 1, _playlist.Count - 1] (删除的起始索引index + 1, 数量nextIndex-index-1==_playlist.Count-index-1) } else { endTime = _playlist[nextIndex].ScheduleInfo.StartTime; // 注:nextIndex可能等于index+1。 // 当nextIndex大于index+1时。 // 替换范围:[index+1, nextIndex-1] (删除的起始索引index+1,数量nextIndex-index-1 ) // 当nextIndex等于index+1时。(删除的起始索引index+1, 数量nextIndex-index-1==0 ) // 在index+1处插入0个或1个。 } PlaybillItem playItem = PlaybillItem.CreateTiming(startTime, new NormalPlaySource(playSource), false); Debug.Assert(beginTime <= endTime); Debug.Assert(beginTime <= startTime && endTime > playItem.ScheduleInfo.StopTime); for (int i = prevIndex + 1; i < nextIndex; i++) { tempList.Add(_playlist[i].PlaybillItem); //builder.Add(_playlist[i].PlaybillItem); } // case 1: prevIndex + 1==nextIndex-1,替换起始位置prevIndex + 1,删除数量1 (nextIndex-1-prevIndex) // case 2: prevIndex + 1<nextIndex-1,替换起始位置prevIndex + 1,删除数量1 (nextIndex-1-prevIndex) // case 3: prevIndex + 1>nextIndex-1 // 替换范围为[prevIndex + 1, nextIndex-1] // 触发事件(表示操作完成)。 }
private void AddTiming(DateTime startTime, IPlaySource playSource) { // 验证操作的合法性。 ValidatePlayDuration(playSource.PlayRange.Duration); ValidateStartTime(startTime, false); EnsureNoTimingConflict(startTime, playSource.PlayRange.Duration); // 获取插入位置。 // 第一个开始时间大于等于startTime的索引(-1表示列表为空或开始时间全部小于startTime) int index = FindTimingInsertIndex(startTime); //_playlist.FindFirstIndex((i)=>!i.IsSkipped() && i.ScheduleInfo.StartTime>=startTime); //index = index < 0 ? _playlist.Count : index; // 下面的处理代码确保顺播片断不会被定时播分隔。 var tempIndex = index; while (tempIndex < _playlist.Count) { var item = _playlist[tempIndex]; if (item.ScheduleInfo.ScheduleMode == ScheduleMode.Timing) { break; } else if (item.ScheduleInfo.ScheduleMode == ScheduleMode.TimingBreak) { continue; } else if (!item.IsSegment() || item.IsFirstSegment()) { break; } else { if (tempIndex != index) { var temp = _playlist[tempIndex]; _playlist.RemoveAt(tempIndex); _playlist.Insert(index, temp); } index++; } tempIndex++; } // 触发事件前置事件。 PlaybillItem playItem = PlaybillItem.CreateTiming(startTime, new NormalPlaySource(playSource), false); Insert(index, playItem); // 重新计算调度信息。 DateTime beginTime; DateTime endTime; if (index == 0) { if (_playlist.HasMinStartTime() && _playlist.MinStartTime.Value < startTime) { beginTime = _playlist.MinStartTime.Value; endTime = startTime; using (var builder = Build()) { Replace(0, 0, builder.Build(beginTime, endTime)); } } } else if (index > 0) // 有前部片断 { var prevIndex = _playlist.FindLastIndex(index - 1, i => !i.IsSkipped() && i.ScheduleInfo.StopTime <= startTime); endTime = startTime; if (prevIndex == -1) { beginTime = _playlist[0].ScheduleInfo.StartTime; // startTime; beginTime = beginTime > endTime ? endTime : beginTime; // [prevIndex+1, index-1], 注:index-prevIndex+1 // 替换范围:[prevIndex+1, index-1] (删除的起始索引0==prevIndex+1,数量index==index-prevIndex-1) } else { beginTime = _playlist[prevIndex].ScheduleInfo.StopTime; // 注:prevIndex可能等于index-1。 // 当prevIndex小于index-1时。 // 替换范围:[prevIndex + 1, index-1] (删除的起始索引prevIndex + 1,数量index-prevIndex-1 ) // 当prevIndex等于index-1时。(删除的起始索引prevIndex + 1==index,数量index-prevIndex-1==0 ) // 在index处插入0个或1个。 } using (var builder = Build()) { for (int i = prevIndex + 1; i < index; i++) { builder.Add(_playlist[i].PlaybillItem); } Replace(prevIndex + 1, index - prevIndex - 1, builder.Build(beginTime, endTime)); } } if (index < _playlist.Count - 1) // 有后部片断 { var nextIndex = _playlist.FindFirstIndex(index + 1, i => !i.IsSkipped() && i.ScheduleInfo.ScheduleMode == ScheduleMode.Timing); beginTime = playItem.ScheduleInfo.StopTime; if (nextIndex == -1) { endTime = DateTime.MaxValue; nextIndex = _playlist.Count; // [index + 1, _playlist.Count - 1], 注:index + 1可能等于_playlist.Count - 1 // 替换范围:[index + 1, _playlist.Count - 1] (删除的起始索引index + 1, 数量nextIndex-index-1==_playlist.Count-index-1) } else { endTime = _playlist[nextIndex].ScheduleInfo.StartTime; // 注:nextIndex可能等于index+1。 // 当nextIndex大于index+1时。 // 替换范围:[index+1, nextIndex-1] (删除的起始索引index+1,数量nextIndex-index-1 ) // 当nextIndex等于index+1时。(删除的起始索引index+1, 数量nextIndex-index-1==0 ) // 在index+1处插入0个或1个。 } using (var builder = Build()) { for (int i = index + 1; i < nextIndex; i++) { builder.Add(_playlist[i].PlaybillItem); } Replace(index + 1, nextIndex - index - 1, builder.Build(beginTime, endTime)); } } // 触发事件(表示操作完成)。 }
public abstract void Split(TimeSpan duration, out PlaybillItem first, out PlaybillItem second);
public static bool IsAutoPadding(this PlaybillItem playbillItem) { return(playbillItem.ScheduleMode == ScheduleMode.Auto); }
public static bool IsSkipped(this PlaybillItem playbillItem) { // Note: 定时播和定时插播应该总是返回false。 return(playbillItem.ScheduleInfo.Duration == TimeSpan.Zero); }
public override PlaybillItem Merge(PlaybillItem nextItem) { throw new InvalidOperationException(); }
private void Split(PlaybillItem autoItem, TimeSpan duration, out PlaybillItem first, out PlaybillItem second) { autoItem.Split(duration, out first, out second); }
private void Build2(PlaylistSegmentBuildData buildData) { DateTime startTime = buildData.BeginTime; DateTime stopTime = buildData.EndTime; IList <PlaybillItem> result = buildData.Result; PlaybillItem autoItem = null; PlaybillItem timingItem = null; while (startTime < stopTime) { if (autoItem == null) { autoItem = buildData.TakeAuto(); // _autoList[0]; } if (timingItem == null) { autoItem = buildData.TakeTiming(); // _breakList[0]; } if (autoItem != null && timingItem != null) { if (startTime < timingItem.ScheduleInfo.StartTime) { var duration = timingItem.ScheduleInfo.StartTime.Subtract(startTime); if (duration >= autoItem.PlaySource.PlayRange.Duration) { duration = autoItem.PlaySource.PlayRange.Duration; var info = autoItem.ScheduleInfo; info = new ScheduleInfo(startTime, duration, info.ScheduleMode); autoItem.ScheduleInfo = info; result.Add(autoItem); autoItem = null; startTime = info.StopTime; } else { if (timingItem.ScheduleMode == ScheduleMode.TimingBreak) { PlaybillItem first = null, second = null; // 注:autoItem可能本身是个片断。 Split(autoItem, duration, out first, out second); var info = autoItem.ScheduleInfo; info = new ScheduleInfo(startTime, duration, info.ScheduleMode); first.ScheduleInfo = info; result.Add(first); autoItem = second; startTime = info.StopTime; } else { // 截短。 var info = autoItem.ScheduleInfo; info = new ScheduleInfo(startTime, duration, info.ScheduleMode); autoItem.ScheduleInfo = info; result.Add(autoItem); autoItem = null; startTime = info.StopTime; } } } else { Debug.Assert(startTime == timingItem.ScheduleInfo.StartTime); if (timingItem.ScheduleMode == ScheduleMode.TimingBreak || !autoItem.IsSegment) { result.Add(timingItem); timingItem = null; startTime = timingItem.ScheduleInfo.StopTime; } else { Debug.Assert(!autoItem.IsFirstSegment); // 完全截掉。 var info = autoItem.ScheduleInfo; info = new ScheduleInfo(startTime, TimeSpan.Zero, info.ScheduleMode); autoItem.ScheduleInfo = info; result.Add(autoItem); autoItem = null; startTime = info.StopTime; } } } else if (autoItem != null) // timingItem == null { var duration = stopTime.Subtract(startTime); if (duration >= autoItem.PlaySource.PlayRange.Duration) { duration = autoItem.PlaySource.PlayRange.Duration; var info = autoItem.ScheduleInfo; info = new ScheduleInfo(startTime, duration, info.ScheduleMode); autoItem.ScheduleInfo = info; result.Add(autoItem); autoItem = null; startTime = info.StopTime; } else { var info = autoItem.ScheduleInfo; info = new ScheduleInfo(startTime, duration, info.ScheduleMode); autoItem.ScheduleInfo = info; result.Add(autoItem); autoItem = null; startTime = info.StopTime; } } else if (timingItem != null) // autoItem == null { if (startTime < timingItem.ScheduleInfo.StartTime) { var duration = timingItem.ScheduleInfo.StartTime.Subtract(startTime); PlaybillItem autoPaddingItem = CreateAutoPaddingItem(startTime, duration); result.Add(autoPaddingItem); startTime = autoPaddingItem.ScheduleInfo.StopTime; // breakItem.ScheduleInfo.StartTime; } else { Debug.Assert(startTime == timingItem.ScheduleInfo.StartTime); result.Add(timingItem); startTime = timingItem.ScheduleInfo.StopTime; timingItem = null; } } else { if (stopTime != DateTime.MaxValue) { PlaybillItem autoPaddingItem = CreateAutoPaddingItem(startTime, stopTime.Subtract(startTime)); result.Add(autoPaddingItem); } startTime = stopTime; } } Debug.Assert(buildData.TakeTiming() == null); autoItem = buildData.TakeAuto(); while (autoItem != null) { var info = autoItem.ScheduleInfo; info = new ScheduleInfo(startTime, TimeSpan.Zero, info.ScheduleMode); autoItem.ScheduleInfo = info; result.Add(autoItem); autoItem = buildData.TakeAuto(); } }
public override bool CanMerge(PlaybillItem nextItem) { return(false); }
public abstract bool CanMerge(PlaybillItem nextItem);