diff --git a/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestAudioFingerprinting.cs b/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestAudioFingerprinting.cs index 6bc8f41..528984b 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestAudioFingerprinting.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper.Tests/TestAudioFingerprinting.cs @@ -66,8 +66,8 @@ public class TestAudioFingerprinting [Fact] public void TestIndexGeneration() { - // 0 1 2 3 4 5 6 7 - var fpr = new List(new uint[] { 1, 2, 3, 1, 5, 77, 42, 2 }).AsReadOnly(); + // 0 1 2 3 4 5 6 7 + var fpr = new uint[] { 1, 2, 3, 1, 5, 77, 42, 2 }; var expected = new Dictionary() { {1, 3}, diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Chromaprint.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Chromaprint.cs index 2a28cb6..21f142c 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Chromaprint.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Chromaprint.cs @@ -66,10 +66,10 @@ public static class Chromaprint /// /// Queued episode to fingerprint. /// Numerical fingerprint points. - public static ReadOnlyCollection Fingerprint(QueuedEpisode episode) + public static uint[] Fingerprint(QueuedEpisode episode) { // Try to load this episode from cache before running ffmpeg. - if (LoadCachedFingerprint(episode, out ReadOnlyCollection cachedFingerprint)) + if (LoadCachedFingerprint(episode, out uint[] cachedFingerprint)) { Logger?.LogDebug("Fingerprint cache hit on {File}", episode.Path); return cachedFingerprint; @@ -106,7 +106,7 @@ public static class Chromaprint // Try to cache this fingerprint. CacheFingerprint(episode, results); - return results.AsReadOnly(); + return results.ToArray(); } /// @@ -114,11 +114,11 @@ public static class Chromaprint /// /// Chromaprint fingerprint. /// Inverted index. - public static Dictionary CreateInvertedIndex(ReadOnlyCollection fingerprint) + public static Dictionary CreateInvertedIndex(uint[] fingerprint) { var invIndex = new Dictionary(); - for (int i = 0; i < fingerprint.Count; i++) + for (int i = 0; i < fingerprint.Length; i++) { // Get the current point. var point = fingerprint[i]; @@ -183,11 +183,11 @@ public static class Chromaprint /// Tries to load an episode's fingerprint from cache. If caching is not enabled, calling this function is a no-op. /// /// Episode to try to load from cache. - /// ReadOnlyCollection to store the fingerprint in. + /// Array to store the fingerprint in. /// true if the episode was successfully loaded from cache, false on any other error. - private static bool LoadCachedFingerprint(QueuedEpisode episode, out ReadOnlyCollection fingerprint) + private static bool LoadCachedFingerprint(QueuedEpisode episode, out uint[] fingerprint) { - fingerprint = new List().AsReadOnly(); + fingerprint = Array.Empty(); // If fingerprint caching isn't enabled, don't try to load anything. if (!(Plugin.Instance?.Configuration.CacheFingerprints ?? false)) @@ -228,7 +228,7 @@ public static class Chromaprint return false; } - fingerprint = result.AsReadOnly(); + fingerprint = result.ToArray(); return true; } diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/VisualizationController.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/VisualizationController.cs index 5dbb778..0caad79 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/VisualizationController.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/Controllers/VisualizationController.cs @@ -103,7 +103,7 @@ public class VisualizationController : ControllerBase /// Episode id. /// Read only collection of fingerprint points. [HttpGet("Fingerprint/{Id}")] - public ActionResult> GetEpisodeFingerprint([FromRoute] Guid id) + public ActionResult GetEpisodeFingerprint([FromRoute] Guid id) { var queue = Plugin.Instance!.AnalysisQueue; diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs index 331c1cb..be88502 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/ScheduledTasks/FingerprinterTask.cs @@ -61,7 +61,7 @@ public class FingerprinterTask : IScheduledTask /// Temporary fingerprint cache to speed up reanalysis. /// Fingerprints are removed from this after a season is analyzed. /// - private Dictionary> _fingerprintCache; + private Dictionary _fingerprintCache; /// /// Statistics for the currently running analysis task. @@ -92,7 +92,7 @@ public class FingerprinterTask : IScheduledTask _logger = loggerFactory.CreateLogger(); _queueLogger = loggerFactory.CreateLogger(); - _fingerprintCache = new Dictionary>(); + _fingerprintCache = new Dictionary(); EdlManager.Initialize(_logger); } @@ -431,9 +431,9 @@ public class FingerprinterTask : IScheduledTask /// Intros for the first and second episodes. public (Intro Lhs, Intro Rhs) FingerprintEpisodes( Guid lhsId, - ReadOnlyCollection lhsPoints, + uint[] lhsPoints, Guid rhsId, - ReadOnlyCollection rhsPoints, + uint[] rhsPoints, bool isFirstPass) { // If this isn't running as part of the first analysis pass, don't count this CPU time as first pass time. @@ -468,7 +468,7 @@ public class FingerprinterTask : IScheduledTask // ===== Method 3: Full scan ===== // Compares all elements of the shortest fingerprint to the other fingerprint. - var limit = Math.Min(lhsPoints.Count, rhsPoints.Count); + var limit = Math.Min(lhsPoints.Length, rhsPoints.Length); (lhsRanges, rhsRanges) = ShiftEpisodes(lhsPoints, rhsPoints, -1 * limit, limit); if (lhsRanges.Count > 0) @@ -535,8 +535,8 @@ public class FingerprinterTask : IScheduledTask /// Right episode fingerprint points. /// List of shared TimeRanges between the left and right episodes. private (List Lhs, List Rhs) SearchInvertedIndex( - ReadOnlyCollection lhsPoints, - ReadOnlyCollection rhsPoints) + uint[] lhsPoints, + uint[] rhsPoints) { var lhsRanges = new List(); var rhsRanges = new List(); @@ -579,8 +579,8 @@ public class FingerprinterTask : IScheduledTask /// Lower end of the shift range. /// Upper end of the shift range. private static (List Lhs, List Rhs) ShiftEpisodes( - ReadOnlyCollection lhs, - ReadOnlyCollection rhs, + uint[] lhs, + uint[] rhs, int lower, int upper) { @@ -610,8 +610,8 @@ public class FingerprinterTask : IScheduledTask /// Second fingerprint to compare. /// Amount to shift one fingerprint by. private static (TimeRange Lhs, TimeRange Rhs) FindContiguous( - ReadOnlyCollection lhs, - ReadOnlyCollection rhs, + uint[] lhs, + uint[] rhs, int shiftAmount) { var leftOffset = 0; @@ -630,7 +630,7 @@ public class FingerprinterTask : IScheduledTask // Store similar times for both LHS and RHS. var lhsTimes = new List(); var rhsTimes = new List(); - var upperLimit = Math.Min(lhs.Count, rhs.Count) - Math.Abs(shiftAmount); + var upperLimit = Math.Min(lhs.Length, rhs.Length) - Math.Abs(shiftAmount); // XOR all elements in LHS and RHS, using the shift amount from above. for (var i = 0; i < upperLimit; i++) @@ -785,7 +785,7 @@ public class FingerprinterTask : IScheduledTask // TODO: add limit and make it customizable var count = maxBucket.Episodes.Count - 1; - var goodFingerprints = new List>(); + var goodFingerprints = new List(); foreach (var id in maxBucket.Episodes) { if (!_fingerprintCache.TryGetValue(id, out var fp))