forked from amkovkov/GranuSightSoftware2
fix: CameraService view finder
Image capturing while view finder work
This commit is contained in:
@@ -79,6 +79,8 @@ public class CameraService : IDisposable
|
||||
private List<MappedBuffer>? _imageCaptureMappedBuffers;
|
||||
private readonly CancellationTokenSource _disposeCts = new CancellationTokenSource();
|
||||
|
||||
public bool IsImageCapturing { get; private set; } = false;
|
||||
|
||||
public CameraService(ILogger<CameraService> logger, CameraServiceConfiguration? configuration = null, bool autoInitialize = false)
|
||||
{
|
||||
_logger = logger;
|
||||
@@ -488,6 +490,8 @@ public class CameraService : IDisposable
|
||||
.CreateLinkedTokenSource(_disposeCts.Token, cancellationToken)
|
||||
.Token;
|
||||
|
||||
IsImageCapturing = true;
|
||||
|
||||
_logger.LogDebug("Capturing {} frame(s)", framesCount);
|
||||
|
||||
OpenCvSharp.Mat? image = null;
|
||||
@@ -501,8 +505,6 @@ public class CameraService : IDisposable
|
||||
{
|
||||
effectiveCancellationToken.ThrowIfCancellationRequested();
|
||||
_logger.LogDebug("Requested {} frame(s), now collected {}", framesCount, planesData.Count());
|
||||
if (File.Exists("/proc/self/status"))
|
||||
_logger.LogDebug("Current RAM Usage: {}", File.ReadAllLines("/proc/self/status").FirstOrDefault(l => l.StartsWith("RssAnon:"))?.Substring("RssAnon:".Length)?.Trim() ?? "UNKNOWN");
|
||||
|
||||
var oldPlanesDataCount = planesData.Count();
|
||||
|
||||
@@ -521,7 +523,7 @@ public class CameraService : IDisposable
|
||||
throw new Exception("Error while request create");
|
||||
requests.Add(request);
|
||||
}
|
||||
_logger.LogDebug("Request(s) created");
|
||||
_logger.LogDebug("{} request(s) created", requests.Count());
|
||||
|
||||
effectiveCancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
@@ -578,6 +580,8 @@ public class CameraService : IDisposable
|
||||
planesData.Add(planeData);
|
||||
}
|
||||
|
||||
_logger.LogDebug("Planes data added");
|
||||
|
||||
if (planesData.Count() - oldPlanesDataCount == requests.Count())
|
||||
cts.SetResult();
|
||||
}
|
||||
@@ -592,8 +596,9 @@ public class CameraService : IDisposable
|
||||
throw new Exception("Error while request queue");
|
||||
}
|
||||
}
|
||||
_logger.LogDebug("Request(s) queued");
|
||||
_logger.LogDebug("{} request(s) queued", requests.Count());
|
||||
await cts.Task.WaitAsync(effectiveCancellationToken);
|
||||
_logger.LogDebug("{} request(s) compilted", requests.Count());
|
||||
_camera.RequestCompleted -= RequestCompleted;
|
||||
|
||||
foreach (var key in fdsData.Keys)
|
||||
@@ -604,9 +609,6 @@ public class CameraService : IDisposable
|
||||
}
|
||||
|
||||
_logger.LogDebug("Frame(s) collected");
|
||||
if (File.Exists("/proc/self/status"))
|
||||
_logger.LogDebug("Current RAM Usage: {}", File.ReadAllLines("/proc/self/status").FirstOrDefault(l => l.StartsWith("RssAnon:"))?.Substring("RssAnon:".Length)?.Trim() ?? "UNKNOWN");
|
||||
|
||||
|
||||
effectiveCancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
@@ -657,6 +659,8 @@ public class CameraService : IDisposable
|
||||
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
|
||||
planesData.Clear();
|
||||
}
|
||||
|
||||
IsImageCapturing = false;
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -707,6 +711,9 @@ public class CameraService : IDisposable
|
||||
|
||||
void TimerElapsed(object? sender, System.Timers.ElapsedEventArgs ea)
|
||||
{
|
||||
if (IsImageCapturing)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
FrameBuffer buffer;
|
||||
@@ -766,6 +773,9 @@ public class CameraService : IDisposable
|
||||
}
|
||||
public (FrameBuffer, StreamConfiguration)? GrabViewFinderFrame()
|
||||
{
|
||||
if (IsImageCapturing)
|
||||
return null;
|
||||
|
||||
FrameBuffer? buffer = null;
|
||||
lock (ViewFinderBufferQueue)
|
||||
if (ViewFinderBufferQueue.Count() > 0)
|
||||
|
||||
Reference in New Issue
Block a user