diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a96031ca..2ceb19567 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] ### Fixed - Reduce memory use due to library scan operations +- Fix some instances of filler getting "stuck" when a filler item is encountered that's too long for the gap ### Added - Add `metadata_kind` field to search index to allow searching for items with a particular metdata source diff --git a/ErsatzTV.Core/Scheduling/PlayoutModeSchedulerBase.cs b/ErsatzTV.Core/Scheduling/PlayoutModeSchedulerBase.cs index 6767381c5..e225cae2c 100644 --- a/ErsatzTV.Core/Scheduling/PlayoutModeSchedulerBase.cs +++ b/ErsatzTV.Core/Scheduling/PlayoutModeSchedulerBase.cs @@ -634,7 +634,7 @@ public abstract class PlayoutModeSchedulerBase : IPlayoutModeScheduler whe return result; } - private static List AddDurationFiller( + private List AddDurationFiller( PlayoutBuilderState playoutBuilderState, IMediaCollectionEnumerator enumerator, TimeSpan duration, @@ -643,16 +643,15 @@ public abstract class PlayoutModeSchedulerBase : IPlayoutModeScheduler whe { var result = new List(); - while (enumerator.Current.IsSome) + TimeSpan remainingToFill = duration; + var skipped = false; + while (enumerator.Current.IsSome && remainingToFill > TimeSpan.Zero) { foreach (MediaItem mediaItem in enumerator.Current) { - // TODO: retry up to x times when item doesn't fit? - TimeSpan itemDuration = DurationForMediaItem(mediaItem); - duration -= itemDuration; - if (duration >= TimeSpan.Zero) + if (remainingToFill - itemDuration >= TimeSpan.Zero) { var playoutItem = new PlayoutItem { @@ -666,14 +665,33 @@ public abstract class PlayoutModeSchedulerBase : IPlayoutModeScheduler whe DisableWatermarks = !allowWatermarks }; + remainingToFill -= itemDuration; result.Add(playoutItem); enumerator.MoveNext(); } - } + else if (skipped) + { + // set to zero so it breaks out of the while loop + remainingToFill = TimeSpan.Zero; + } + else + { + if (itemDuration >= duration * 2) + { + _logger.LogWarning( + "Filler item is too long {FillerDuration} to fill {GapDuration}; skipping to next filler item", + itemDuration, + duration); - if (duration < TimeSpan.Zero) - { - break; + skipped = true; + enumerator.MoveNext(); + } + else + { + // set to zero so it breaks out of the while loop + remainingToFill = TimeSpan.Zero; + } + } } }