From 6c67e0d210a1cf2e3ff754185665a117371a0148 Mon Sep 17 00:00:00 2001 From: sophelper <123211521@163.com> Date: Sat, 7 Nov 2026 13:28:03 +0800 Subject: [PATCH] Release SOP camera on stop so recording can open --- .../VVMs/SopPage/SopPageViewModel.cs | 7 +++++- tests/Training.CameraSmoke/Program.cs | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/SopHelper.App/VVMs/SopPage/SopPageViewModel.cs b/src/SopHelper.App/VVMs/SopPage/SopPageViewModel.cs index 7e8686d..f2e4370 100644 --- a/src/SopHelper.App/VVMs/SopPage/SopPageViewModel.cs +++ b/src/SopHelper.App/VVMs/SopPage/SopPageViewModel.cs @@ -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; diff --git a/tests/Training.CameraSmoke/Program.cs b/tests/Training.CameraSmoke/Program.cs index f0b6f94..a832847 100644 --- a/tests/Training.CameraSmoke/Program.cs +++ b/tests/Training.CameraSmoke/Program.cs @@ -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 ready, int timeout = 5000) { var watch = Stopwatch.StartNew();