Retry GetFrameCountCached up to 3x, clear cmd output caches on new file

This commit is contained in:
n00mkrad
2022-04-05 18:07:05 +02:00
parent dd98b02355
commit 483aa46ebb
7 changed files with 42 additions and 11 deletions

View File

@@ -9,9 +9,9 @@ namespace Flowframes.Media
{
class GetFrameCountCached
{
public static Dictionary<QueryInfo, int> cache = new Dictionary<QueryInfo, int>();
private static Dictionary<QueryInfo, int> cache = new Dictionary<QueryInfo, int>();
public static async Task<int> GetFrameCountAsync(string path)
public static async Task<int> GetFrameCountAsync(string path, int retryCount = 3)
{
Logger.Log($"Getting frame count ({path})", true);
@@ -35,8 +35,23 @@ namespace Flowframes.Media
else
frameCount = await FfmpegCommands.GetFrameCountAsync(path);
Logger.Log($"Adding hash with value {frameCount} to cache.", true);
cache.Add(hash, frameCount);
if(frameCount > 0)
{
Logger.Log($"Adding hash with value {frameCount} to cache.", true);
cache.Add(hash, frameCount);
}
else
{
if (retryCount > 0)
{
Logger.Log($"Got {frameCount} frames, retrying ({retryCount} left)", true);
frameCount = await GetFrameCountAsync(path, retryCount - 1);
}
else
{
Logger.Log($"Failed to get frames and out of retries ({frameCount} frames for {path})", true);
}
}
return frameCount;
}
@@ -58,5 +73,10 @@ namespace Flowframes.Media
return 0;
}
public static void Clear ()
{
cache.Clear();
}
}
}