feat: 部分修复摄像头批量读逻辑

This commit is contained in:
alivender
2025-07-14 12:14:40 +08:00
parent 9b580be5e9
commit c5f0e706a4
2 changed files with 13 additions and 10 deletions

View File

@@ -465,7 +465,7 @@ public class UDPClientPool
// Send address packages in batches of 128, control outstanding
int sentCount = 0;
var startTime = DateTime.Now;
const int batchSize = 128;
const int batchSize = 64;
while (sentCount < pkgList.Count)
{
var elapsed = DateTime.Now - startTime;
@@ -487,11 +487,12 @@ public class UDPClientPool
var ret = await UDPClientPool.SendMultiAddrPackAsync(endPoint, batchPkgs);
if (!ret) return new(new Exception($"Send address package batch failed at segment {sentCount}!"));
sentCount += batchSend;
// Task.Delay(1).Wait();
}
// Wait until enough data is received or timeout
startTime = DateTime.Now;
List<UDPData>? udpDatas = null;
var udpDatas = new List<UDPData>();
while (true)
{
var elapsed = DateTime.Now - startTime;
@@ -504,23 +505,23 @@ public class UDPClientPool
var dataArr = await MsgBus.UDPServer.FindDataArrayAsync(endPoint.Address.ToString(), taskID, timeleft);
if (dataArr.HasValue)
{
udpDatas = dataArr.Value;
udpDatas.AddRange(dataArr.Value);
break;
}
}
}
if (udpDatas is null || udpDatas.Count < readTimes)
return new(new Exception($"Expected {readTimes} UDP data packets but received {udpDatas?.Count ?? 0}"));
if (udpDatas.Count < readTimes)
return new(new Exception($"Expected {readTimes} UDP data packets but received {udpDatas.Count}"));
// Collect and validate all received data
for (var i = 0; i < udpDatas.Count; i++)
{
var bytes = udpDatas[i].Data;
var expectedLen = ((pkgList[i].Options.BurstLength + 1) * 4);
if (bytes.Length != expectedLen)
return new(new Exception($"Expected {expectedLen} bytes but received {bytes.Length} bytes at segment {i}"));
resultData.AddRange(bytes);
if ((bytes.Length - 4) != expectedLen)
return new(new Exception($"Expected {expectedLen} bytes but received {bytes.Length - 4} bytes at segment {i}"));
resultData.AddRange(bytes[4..]);
}
// Validate total data length