走设备管理服务时本机不再登录录像机

校验循环里在判断 peer 之前就调了 _playback.ClockOffset(),而它内部会
初始化 HCNetSDK 并登录 NVR —— 于是「走设备管理服务」之后本机又登了一次,
既出现「明明检查过又检查一遍」的观感,也正好抵消了共用会话池的意义
(海康并发登录通常只有 6~16)。

- 时钟对齐挪进 peer is null 的本机分支
- 走边端时结果行标注「(设备管理服务)」,本机不碰录像机

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
liufumingren 2026-10-22 03:32:48 +08:00
parent 85db722384
commit 7b4705c73c
2 changed files with 23 additions and 16 deletions

View File

@ -1348,15 +1348,8 @@ public partial class MainWindow : Window
{
var credential = await CredentialAsync(stream.NvrId, ct);
// 本机与录像机时钟不一致时,回放会整体错位(短窗口甚至直接截掉面单)
var clock = _playback.ClockOffset(credential.Host, credential.Port,
credential.Username, credential.Password);
if (clockNoted.Add(stream.NvrId) && Math.Abs(clock.TotalSeconds) >= 2)
{
lines.Add($"[时钟] 录像机与本机相差 {clock.TotalSeconds:+0.0;-0.0} 秒,回放时间已按录像机对齐");
ShowPlayback(string.Join(Environment.NewLine, lines));
}
// 时钟对齐只有**本机直连录像机**时才需要(回放会整体错位)。
// 走设备管理服务时本机不该登录 NVR —— 那正是「共用会话池」要避免的并发登录。
var hasRecord = false;
var frames = 0;
string? error = null;
@ -1384,21 +1377,35 @@ public partial class MainWindow : Window
if (peer is null)
{
// 本机直连:先和录像机对时(否则短窗口会整体错位甚至截掉面单)
var clock = _playback.ClockOffset(credential.Host, credential.Port,
credential.Username, credential.Password);
if (clockNoted.Add(stream.NvrId) && Math.Abs(clock.TotalSeconds) >= 2)
{
lines.Add($"[时钟] 录像机与本机相差 {clock.TotalSeconds:+0.0;-0.0} 秒,回放时间已按录像机对齐");
ShowPlayback(string.Join(Environment.NewLine, lines));
}
var check = await _playback.CheckAsync(credential.Host, credential.Port,
credential.Username, credential.Password, stream.ChannelNo,
stream.StartTime, stream.EndTime, ct);
hasRecord = check.HasRecord;
frames = check.Frames;
error = check.Error;
lines.Add(hasRecord
? $"[有录像] {stream.DisplayName} {FormatRange(stream, clock)}{(frames > 0 ? $" 试拉 {frames} 帧" : "")}"
: $"[无录像] {stream.DisplayName} {FormatRange(stream, clock)} {error}");
}
else
{
// 走设备管理服务:只报结果,本机不碰录像机
lines.Add(hasRecord
? $"[有录像] {stream.DisplayName} {FormatRange(stream, TimeSpan.Zero)}(设备管理服务){(frames > 0 ? $" 试拉 {frames} 帧" : "")}"
: $"[无录像] {stream.DisplayName} {FormatRange(stream, TimeSpan.Zero)} {error}(设备管理服务)");
}
if (hasRecord) valid.Add(stream);
// SDK 路径不数帧(返回 -1),只有 RTSP 兜底才有帧数
var frameText = frames > 0 ? $" 试拉 {frames} 帧" : "";
lines.Add(hasRecord
? $"[有录像] {stream.DisplayName} {FormatRange(stream, clock)}{frameText}"
: $"[无录像] {stream.DisplayName} {FormatRange(stream, clock)} {error}");
}
catch (Exception ex)
{

View File

@ -42,7 +42,7 @@
<ServerBaseUrl Condition="'$(Configuration)' == 'Debug' and '$(ServerBaseUrl)' == ''">http://127.0.0.1:7300</ServerBaseUrl>
<ServerBaseUrl Condition="'$(Configuration)' == 'Release' and '$(ServerBaseUrl)' == ''">https://packs.example.com</ServerBaseUrl>
<Version>1.0.110</Version>
<Version>1.0.111</Version>
<Product>浜戜粨瑙嗛婧簮杞欢</Product>
<Company>浜戜粨</Company>
<AssemblyTitle>浜戜粨瑙嗛婧簮杞欢锛堟湰鏈烘湇鍔★級</AssemblyTitle>