Browse Source

fix block playout build crash from empty collections (#2395)

pull/2396/head
Jason Dove 4 months ago committed by GitHub
parent
commit
e9093d0c48
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 6
      ErsatzTV.Core.Tests/Scheduling/RandomizedContentTests.cs
  3. 14
      ErsatzTV.Core/Scheduling/RandomizedMediaCollectionEnumerator.cs
  4. 14
      ErsatzTV.Core/Scheduling/RandomizedRotatingMediaCollectionEnumerator.cs

1
CHANGELOG.md

@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- ETV will set this automatically when it has permission
- When ETV does not have permission, startup will fail with logged instructions on how to configure MySql
- Fix scaling anamorphic content in locales that don't use period as a decimal separator (e.g. `,`)
- Block schedules: fix playout build crash when empty collection uses random playback order
### Changed
- **BREAKING CHANGE**: change how `Scripted Schedule` system works

6
ErsatzTV.Core.Tests/Scheduling/RandomizedContentTests.cs

@ -13,12 +13,12 @@ public class RandomizedContentTests @@ -13,12 +13,12 @@ public class RandomizedContentTests
private const int KnownSeed = 22295;
private readonly List<int> _expected = new()
{
private readonly List<int> _expected =
[
5, 7, 7, 8, 6, 7, 8, 9, 10, 7, 5, 1, 7, 2, 5, 6, 1, 4, 5, 6, 4, 5, 1, 6, 5, 7, 1, 3, 9, 9, 9, 3,
3, 2, 3, 4, 5, 6, 9, 3, 6, 9, 7, 1, 2, 10, 3, 8, 3, 8, 8, 3, 1, 5, 4, 3, 6, 4, 6, 2, 9, 8, 3, 1, 8, 5,
1, 8, 2, 1, 1, 5, 5, 5, 3, 5, 8, 10, 4, 8, 7, 3, 3, 4, 4, 9, 2, 8, 8, 10, 8, 4, 3, 10, 7, 8, 9, 9
};
];
private CancellationToken _cancellationToken;

14
ErsatzTV.Core/Scheduling/RandomizedMediaCollectionEnumerator.cs

@ -24,10 +24,17 @@ public class RandomizedMediaCollectionEnumerator : IMediaCollectionEnumerator @@ -24,10 +24,17 @@ public class RandomizedMediaCollectionEnumerator : IMediaCollectionEnumerator
State = new CollectionEnumeratorState { Seed = state.Seed };
// we want to move at least once so we start with a random item and not the first
// because _index defaults to 0
while (State.Index <= state.Index)
if (State.Index == state.Index)
{
MoveNext();
}
else
{
while (State.Index <= state.Index)
{
MoveNext();
}
}
}
public void ResetState(CollectionEnumeratorState state) =>
@ -41,6 +48,11 @@ public class RandomizedMediaCollectionEnumerator : IMediaCollectionEnumerator @@ -41,6 +48,11 @@ public class RandomizedMediaCollectionEnumerator : IMediaCollectionEnumerator
public void MoveNext()
{
if (_mediaItems.Count == 0)
{
return;
}
_index = _random.Next() % _mediaItems.Count;
State.Index++;
}

14
ErsatzTV.Core/Scheduling/RandomizedRotatingMediaCollectionEnumerator.cs

@ -48,10 +48,17 @@ public class RandomizedRotatingMediaCollectionEnumerator : IMediaCollectionEnume @@ -48,10 +48,17 @@ public class RandomizedRotatingMediaCollectionEnumerator : IMediaCollectionEnume
State = new CollectionEnumeratorState { Seed = state.Seed };
// we want to move at least once so we start with a random item and not the first
// because _index defaults to 0
while (State.Index <= state.Index)
if (State.Index == state.Index)
{
MoveNext();
}
else
{
while (State.Index <= state.Index)
{
MoveNext();
}
}
}
public void ResetState(CollectionEnumeratorState state) =>
@ -66,6 +73,11 @@ public class RandomizedRotatingMediaCollectionEnumerator : IMediaCollectionEnume @@ -66,6 +73,11 @@ public class RandomizedRotatingMediaCollectionEnumerator : IMediaCollectionEnume
public void MoveNext()
{
var groups = _groupMedia.Keys.ToList();
if (groups.Count == 0)
{
return;
}
int nextRandom = _random.Next();
int groupNumber = nextRandom % groups.Count;

Loading…
Cancel
Save