Bugfix-FFmpegWrapper (#125)

Co-authored-by: rlauu <46294892+rlauu@users.noreply.github.com>
This commit is contained in:
rlauuzo 2024-04-19 21:21:06 +02:00 committed by GitHub
parent a07111d5e1
commit 13a317dce1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 16 deletions

View File

@ -81,7 +81,7 @@ public class TestAudioFingerprinting
{77, 5},
};
var actual = FFmpegWrapper.CreateInvertedIndex(Guid.NewGuid(), fpr);
var actual = FFmpegWrapper.CreateInvertedIndex(Guid.NewGuid(), fpr, AnalysisMode.Introduction);
Assert.Equal(expected, actual);
}

View File

@ -261,8 +261,8 @@ public class ChromaprintAnalyzer : IMediaFileAnalyzer
var rhsRanges = new List<TimeRange>();
// Generate inverted indexes for the left and right episodes.
var lhsIndex = FFmpegWrapper.CreateInvertedIndex(lhsId, lhsPoints);
var rhsIndex = FFmpegWrapper.CreateInvertedIndex(rhsId, rhsPoints);
var lhsIndex = FFmpegWrapper.CreateInvertedIndex(lhsId, lhsPoints, this._analysisMode);
var rhsIndex = FFmpegWrapper.CreateInvertedIndex(rhsId, rhsPoints, this._analysisMode);
var indexShifts = new HashSet<int>();
// For all audio points in the left episode, check if the right episode has a point which matches exactly.

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
@ -14,8 +15,6 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper;
/// </summary>
public static class FFmpegWrapper
{
private static readonly object InvertedIndexCacheLock = new();
/// <summary>
/// Used with FFmpeg's silencedetect filter to extract the start and end times of silence.
/// </summary>
@ -34,7 +33,7 @@ public static class FFmpegWrapper
private static Dictionary<string, string> ChromaprintLogs { get; set; } = new();
private static Dictionary<Guid, Dictionary<uint, int>> InvertedIndexCache { get; set; } = new();
private static ConcurrentDictionary<AnalysisMode, ConcurrentDictionary<Guid, Dictionary<uint, int>>> InvertedIndexCache { get; set; } = new();
/// <summary>
/// Check that the installed version of ffmpeg supports chromaprint.
@ -137,15 +136,16 @@ public static class FFmpegWrapper
/// </summary>
/// <param name="id">Episode ID.</param>
/// <param name="fingerprint">Chromaprint fingerprint.</param>
/// <param name="mode">Mode.</param>
/// <returns>Inverted index.</returns>
public static Dictionary<uint, int> CreateInvertedIndex(Guid id, uint[] fingerprint)
public static Dictionary<uint, int> CreateInvertedIndex(Guid id, uint[] fingerprint, AnalysisMode mode)
{
lock (InvertedIndexCacheLock)
var innerDictionary = InvertedIndexCache.GetOrAdd(mode, _ => new ConcurrentDictionary<Guid, Dictionary<uint, int>>());
// Check if cached for the ID
if (innerDictionary.TryGetValue(id, out var cached))
{
if (InvertedIndexCache.TryGetValue(id, out var cached))
{
return cached;
}
return cached;
}
var invIndex = new Dictionary<uint, int>();
@ -159,10 +159,7 @@ public static class FFmpegWrapper
invIndex[point] = i;
}
lock (InvertedIndexCacheLock)
{
InvertedIndexCache[id] = invIndex;
}
innerDictionary[id] = invIndex;
return invIndex;
}