mirror of https://github.com/ErsatzTV/ErsatzTV.git
Browse Source
* use temp file pool to limit disk use * keep aspect ratio and crop when scaling cover art for blurred background * fix typopull/504/head
16 changed files with 96 additions and 7 deletions
@ -0,0 +1,9 @@ |
|||||||
|
namespace ErsatzTV.Core.FFmpeg |
||||||
|
{ |
||||||
|
public enum TempFileCategory |
||||||
|
{ |
||||||
|
DrawText = 0, |
||||||
|
SongBackground = 1, |
||||||
|
CoverArt = 2 |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,35 @@ |
|||||||
|
using System.Collections.Generic; |
||||||
|
using System.IO; |
||||||
|
using ErsatzTV.Core.Interfaces.FFmpeg; |
||||||
|
|
||||||
|
namespace ErsatzTV.Core.FFmpeg |
||||||
|
{ |
||||||
|
public class TempFilePool : ITempFilePool |
||||||
|
{ |
||||||
|
private const int ItemLimit = 10; |
||||||
|
private readonly Dictionary<TempFileCategory, int> _state = new(); |
||||||
|
private readonly object _lock = new(); |
||||||
|
|
||||||
|
public string GetNextTempFile(TempFileCategory category) |
||||||
|
{ |
||||||
|
lock (_lock) |
||||||
|
{ |
||||||
|
var index = 0; |
||||||
|
|
||||||
|
if (_state.TryGetValue(category, out int current)) |
||||||
|
{ |
||||||
|
index = (current + 1) % ItemLimit; |
||||||
|
} |
||||||
|
|
||||||
|
_state[category] = index; |
||||||
|
|
||||||
|
return GetFileName(category, index); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static string GetFileName(TempFileCategory category, int index) |
||||||
|
{ |
||||||
|
return Path.Combine(FileSystemLayout.TempFilePoolFolder, $"{category}_{index}".ToLowerInvariant()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,9 @@ |
|||||||
|
using ErsatzTV.Core.FFmpeg; |
||||||
|
|
||||||
|
namespace ErsatzTV.Core.Interfaces.FFmpeg |
||||||
|
{ |
||||||
|
public interface ITempFilePool |
||||||
|
{ |
||||||
|
string GetNextTempFile(TempFileCategory category); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue