aboutsummaryrefslogtreecommitdiff
path: root/Emby.Drawing/ImageProcessor.cs
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2015-04-28 11:03:34 -0400
committerLuke <luke.pulverenti@gmail.com>2015-04-28 11:03:34 -0400
commit23da60856958e1a219cccafeb002ae182b3f812a (patch)
tree52dfd1706f6ae3c8a6d133a105cc09d07d470db1 /Emby.Drawing/ImageProcessor.cs
parente14fa7d8e5b8c97eafec6670797958593e4506f8 (diff)
parent0442de79f4d2ad5d577cb7a5220386f23a7b3f12 (diff)
Merge pull request #1089 from MediaBrowser/dev
3.0.5597.0
Diffstat (limited to 'Emby.Drawing/ImageProcessor.cs')
-rw-r--r--Emby.Drawing/ImageProcessor.cs55
1 files changed, 52 insertions, 3 deletions
diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs
index 55c6f6455..9ad72d73f 100644
--- a/Emby.Drawing/ImageProcessor.cs
+++ b/Emby.Drawing/ImageProcessor.cs
@@ -51,8 +51,13 @@ namespace Emby.Drawing
private readonly IJsonSerializer _jsonSerializer;
private readonly IServerApplicationPaths _appPaths;
private readonly IImageEncoder _imageEncoder;
+ private readonly SemaphoreSlim _imageProcessingSemaphore;
- public ImageProcessor(ILogger logger, IServerApplicationPaths appPaths, IFileSystem fileSystem, IJsonSerializer jsonSerializer, IImageEncoder imageEncoder)
+ public ImageProcessor(ILogger logger,
+ IServerApplicationPaths appPaths,
+ IFileSystem fileSystem,
+ IJsonSerializer jsonSerializer,
+ IImageEncoder imageEncoder)
{
_logger = logger;
_fileSystem = fileSystem;
@@ -88,6 +93,8 @@ namespace Emby.Drawing
}
_cachedImagedSizes = new ConcurrentDictionary<Guid, ImageSize>(sizeDictionary);
+ var count = Environment.ProcessorCount;
+ _imageProcessingSemaphore = new SemaphoreSlim(count, count);
}
public string[] SupportedInputFormats
@@ -201,6 +208,8 @@ namespace Emby.Drawing
await semaphore.WaitAsync().ConfigureAwait(false);
+ var imageProcessingLockTaken = false;
+
try
{
CheckDisposed();
@@ -212,11 +221,20 @@ namespace Emby.Drawing
Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
+ await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false);
+
+ imageProcessingLockTaken = true;
+
_imageEncoder.EncodeImage(originalImagePath, cacheFilePath, newWidth, newHeight, quality, options);
}
}
finally
{
+ if (imageProcessingLockTaken)
+ {
+ _imageProcessingSemaphore.Release();
+ }
+
semaphore.Release();
}
@@ -254,10 +272,15 @@ namespace Emby.Drawing
return GetResult(croppedImagePath);
}
+ var imageProcessingLockTaken = false;
+
try
{
Directory.CreateDirectory(Path.GetDirectoryName(croppedImagePath));
+ await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false);
+ imageProcessingLockTaken = true;
+
_imageEncoder.CropWhiteSpace(originalImagePath, croppedImagePath);
}
catch (Exception ex)
@@ -269,6 +292,11 @@ namespace Emby.Drawing
}
finally
{
+ if (imageProcessingLockTaken)
+ {
+ _imageProcessingSemaphore.Release();
+ }
+
semaphore.Release();
}
@@ -592,13 +620,25 @@ namespace Emby.Drawing
return enhancedImagePath;
}
+ var imageProcessingLockTaken = false;
+
try
{
Directory.CreateDirectory(Path.GetDirectoryName(enhancedImagePath));
+
+ await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false);
+
+ imageProcessingLockTaken = true;
+
await ExecuteImageEnhancers(supportedEnhancers, originalImagePath, enhancedImagePath, item, imageType, imageIndex).ConfigureAwait(false);
}
finally
{
+ if (imageProcessingLockTaken)
+ {
+ _imageProcessingSemaphore.Release();
+ }
+
semaphore.Release();
}
@@ -717,9 +757,18 @@ namespace Emby.Drawing
return Path.Combine(path, filename);
}
- public void CreateImageCollage(ImageCollageOptions options)
+ public async Task CreateImageCollage(ImageCollageOptions options)
{
- _imageEncoder.CreateImageCollage(options);
+ await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false);
+
+ try
+ {
+ _imageEncoder.CreateImageCollage(options);
+ }
+ finally
+ {
+ _imageProcessingSemaphore.Release();
+ }
}
public IEnumerable<IImageEnhancer> GetSupportedEnhancers(IHasImages item, ImageType imageType)