Release SOP camera on stop so recording can open
This commit is contained in:
parent
a708a71f7a
commit
6c67e0d210
@ -521,7 +521,12 @@ public class SopPageViewModel : ViewModelBase
|
||||
{
|
||||
if (IsRunning)
|
||||
{
|
||||
await Task.Run(_pipeline.Stop);
|
||||
await Task.Run(() =>
|
||||
{
|
||||
_pipeline.Stop();
|
||||
// Recording opens its own capture session; stopping SOP must release the device.
|
||||
_camera.Disconnect();
|
||||
});
|
||||
IsRunning = false;
|
||||
StatusText = "已停止";
|
||||
return;
|
||||
|
||||
@ -24,12 +24,35 @@ internal static class Program
|
||||
TestViewModel(root);
|
||||
TestCloseWhileConnecting(root);
|
||||
TestStalledCamera(root);
|
||||
TestSopStopReleasesCamera();
|
||||
Console.WriteLine("PASS: recording and camera lifecycle checks; artifacts: " + root);
|
||||
return 0;
|
||||
}
|
||||
catch (Exception e) { Console.Error.WriteLine(e); return 1; }
|
||||
}
|
||||
private static void Require(bool condition, string error) { if (!condition) throw new Exception(error); }
|
||||
private static void TestSopStopReleasesCamera()
|
||||
{
|
||||
using var camera = new FakeCamera();
|
||||
using var pipeline = new SopHelper.Engine.Pipeline.DetectionPipeline(camera);
|
||||
var sop = new SopHelper.VVMs.SopPage.SopPageViewModel(camera, pipeline,
|
||||
new SopHelper.Engine.Sop.SopEngine(), null!);
|
||||
try
|
||||
{
|
||||
for (var cycle = 0; cycle < 2; cycle++)
|
||||
{
|
||||
camera.ConnectAsync(new CameraInfo { Name = "Test" }).GetAwaiter().GetResult();
|
||||
PumpUntil(() => sop.IsConnected);
|
||||
sop.IsRunning = true;
|
||||
sop.StartStopCommand.Execute();
|
||||
PumpUntil(() => sop.CanSelectCamera);
|
||||
Require(!camera.IsConnected && !camera.IsGrabbing && !sop.IsConnected && !sop.IsRunning,
|
||||
"SOP stop retained camera ownership and would block recording");
|
||||
}
|
||||
Console.WriteLine("PASS: repeated SOP stop releases device and clears recording entry blockers");
|
||||
}
|
||||
finally { sop.Destroy(); }
|
||||
}
|
||||
private static void PumpUntil(Func<bool> ready, int timeout = 5000)
|
||||
{
|
||||
var watch = Stopwatch.StartNew();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user