Adds parameterized invariant tests (Schedule_clock_padded_offline_multimode) exercising schedule-level clock pad + offline advance across a 2-day window (two midnight crossings) through Flood, Duration, and Multiple — previously only PlayoutModeSchedulerOne had any coverage. Fixture uses sub-15-min content so each padded item occupies one :15 slot and Duration's fill-the-block contract tiles exactly (no off-boundary packing). Part 2 (precision): replaces the day-boundary anchor-clamp magnitude heuristic (overrun <= one pad interval on a padded schedule) with a precise signal — the last scheduler now reports the exact offline-pad target it advanced CurrentTime to (transient PlayoutSchedulerResult.ClockPadOfflineTarget, never persisted), and the clamp exempts only when CurrentTime equals that target exactly. A non-offline overrun (Duration/Flood/Multiple ending short of its natural end, a hard-stop, a tail advance) changes CurrentTime away from the target and still clamps, so persisted NextStart no longer shifts by up to an interval. No persisted-schema/migration change. Output byte-identical for all existing goldens. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
155 lines
6.1 KiB
C#
155 lines
6.1 KiB
C#
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Core.Domain.Filler;
|
|
using ErsatzTV.Core.Extensions;
|
|
using ErsatzTV.Core.Interfaces.Scheduling;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace ErsatzTV.Core.Scheduling;
|
|
|
|
public class PlayoutModeSchedulerOne(ILogger logger) : PlayoutModeSchedulerBase<ProgramScheduleItemOne>(logger)
|
|
{
|
|
public override PlayoutSchedulerResult Schedule(
|
|
PlayoutBuilderState playoutBuilderState,
|
|
Dictionary<CollectionKey, IMediaCollectionEnumerator> collectionEnumerators,
|
|
ProgramScheduleItemOne scheduleItem,
|
|
ProgramScheduleItem nextScheduleItem,
|
|
DateTimeOffset hardStop,
|
|
Random random,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var warnings = new PlayoutBuildWarnings();
|
|
|
|
IMediaCollectionEnumerator contentEnumerator =
|
|
collectionEnumerators[CollectionKey.ForScheduleItem(scheduleItem)];
|
|
foreach (MediaItem mediaItem in contentEnumerator.Current)
|
|
{
|
|
// find when we should start this item, based on the current time
|
|
DateTimeOffset itemStartTime = GetStartTimeAfter(
|
|
playoutBuilderState,
|
|
scheduleItem,
|
|
Option<ILogger>.Some(Logger));
|
|
if (itemStartTime >= hardStop)
|
|
{
|
|
playoutBuilderState = playoutBuilderState with { CurrentTime = hardStop };
|
|
break;
|
|
}
|
|
|
|
TimeSpan itemDuration = mediaItem.GetDurationForPlayout();
|
|
List<MediaChapter> itemChapters = ChaptersForMediaItem(mediaItem);
|
|
|
|
var playoutItem = new PlayoutItem
|
|
{
|
|
PlayoutId = playoutBuilderState.PlayoutId,
|
|
MediaItemId = mediaItem.Id,
|
|
Start = itemStartTime.UtcDateTime,
|
|
Finish = itemStartTime.UtcDateTime + itemDuration,
|
|
InPoint = TimeSpan.Zero,
|
|
OutPoint = itemDuration,
|
|
GuideGroup = playoutBuilderState.NextGuideGroup,
|
|
FillerKind = scheduleItem.GuideMode == GuideMode.Filler ||
|
|
contentEnumerator.CurrentIncludeInProgramGuide == false
|
|
? FillerKind.GuideMode
|
|
: FillerKind.None,
|
|
CustomTitle = scheduleItem.CustomTitle,
|
|
PreferredAudioLanguageCode = scheduleItem.PreferredAudioLanguageCode,
|
|
PreferredAudioTitle = scheduleItem.PreferredAudioTitle,
|
|
PreferredSubtitleLanguageCode = scheduleItem.PreferredSubtitleLanguageCode,
|
|
SubtitleMode = scheduleItem.SubtitleMode,
|
|
PlayoutItemWatermarks = [],
|
|
PlayoutItemGraphicsElements = [],
|
|
SchedulingContext = GetSchedulingContext(scheduleItem, null, contentEnumerator)
|
|
};
|
|
|
|
foreach (ProgramScheduleItemWatermark programScheduleItemWatermark in scheduleItem
|
|
.ProgramScheduleItemWatermarks ?? [])
|
|
{
|
|
playoutItem.PlayoutItemWatermarks.Add(
|
|
new PlayoutItemWatermark
|
|
{
|
|
PlayoutItem = playoutItem,
|
|
WatermarkId = programScheduleItemWatermark.WatermarkId
|
|
});
|
|
}
|
|
|
|
foreach (ProgramScheduleItemGraphicsElement programScheduleItemGraphicsElement in scheduleItem
|
|
.ProgramScheduleItemGraphicsElements ?? [])
|
|
{
|
|
playoutItem.PlayoutItemGraphicsElements.Add(
|
|
new PlayoutItemGraphicsElement
|
|
{
|
|
PlayoutItem = playoutItem,
|
|
GraphicsElementId = programScheduleItemGraphicsElement.GraphicsElementId
|
|
});
|
|
}
|
|
|
|
(List<PlayoutItem> playoutItems, DateTimeOffset? clockPadTarget) = AddFiller(
|
|
playoutBuilderState,
|
|
collectionEnumerators,
|
|
scheduleItem,
|
|
playoutItem,
|
|
itemChapters,
|
|
warnings,
|
|
cancellationToken);
|
|
|
|
DateTimeOffset oneEnd = playoutItems.Max(pi => pi.FinishOffset);
|
|
DateTimeOffset? clockPadOfflineTarget = null;
|
|
if (clockPadTarget is { } onePadTarget && onePadTarget > oneEnd)
|
|
{
|
|
oneEnd = onePadTarget;
|
|
clockPadOfflineTarget = onePadTarget;
|
|
}
|
|
|
|
PlayoutBuilderState nextState = playoutBuilderState with
|
|
{
|
|
CurrentTime = oneEnd
|
|
};
|
|
|
|
nextState.ScheduleItemsEnumerator.MoveNext();
|
|
contentEnumerator.MoveNext(itemStartTime);
|
|
|
|
// LogScheduledItem(scheduleItem, mediaItem, itemStartTime);
|
|
|
|
// only play one item from collection, so always advance to the next item
|
|
// Logger.LogDebug(
|
|
// "Advancing to next schedule item after playout mode {PlayoutMode}",
|
|
// "One");
|
|
|
|
DateTimeOffset nextItemStart = GetFillerStartTimeAfter(nextState, nextScheduleItem, hardStop);
|
|
|
|
if (scheduleItem.TailFiller != null)
|
|
{
|
|
(nextState, playoutItems) = AddTailFiller(
|
|
nextState,
|
|
collectionEnumerators,
|
|
scheduleItem,
|
|
playoutItems,
|
|
nextItemStart,
|
|
warnings,
|
|
cancellationToken);
|
|
}
|
|
|
|
if (scheduleItem.FallbackFiller != null)
|
|
{
|
|
(nextState, playoutItems) = AddFallbackFiller(
|
|
nextState,
|
|
collectionEnumerators,
|
|
scheduleItem,
|
|
playoutItems,
|
|
nextItemStart,
|
|
cancellationToken);
|
|
}
|
|
|
|
nextState = nextState with { NextGuideGroup = nextState.IncrementGuideGroup };
|
|
|
|
return new PlayoutSchedulerResult(nextState, playoutItems, warnings)
|
|
{
|
|
ClockPadOfflineTarget = clockPadOfflineTarget
|
|
};
|
|
}
|
|
|
|
return new PlayoutSchedulerResult(playoutBuilderState, [], warnings);
|
|
}
|
|
|
|
protected override string SchedulingContextName => "One";
|
|
}
|