This commit is contained in:
zhoujie 2026-03-14 22:57:47 +08:00
parent f8420cd3b5
commit 8e779dce30
2 changed files with 18 additions and 5 deletions

View File

@ -101,11 +101,19 @@ int8_t Preprocess_Execute(const RawImageBuffer_t *input,
if (tgt_h > h)
tgt_h = h;
/* ---- 缓冲区容量越界检查 ---- */
uint32_t required_bytes = (uint32_t)tgt_w * tgt_h * 2u;
if (out_buffer->HeadOffset + required_bytes > out_buffer->TotalCapacity) {
return -3; /* 输出缓冲区空间不足 */
/* 输出缓冲区容量限制:等比缩小目标尺寸直到适合 */
uint32_t max_payload = out_buffer->TotalCapacity - out_buffer->HeadOffset;
if ((uint32_t)tgt_w * tgt_h * 2u > max_payload) {
uint16_t orig_w = tgt_w, orig_h = tgt_h;
while ((uint32_t)tgt_w * tgt_h * 2u > max_payload && (tgt_w > 1 || tgt_h > 1)) {
tgt_w = (tgt_w + 1) / 2;
tgt_h = (tgt_h + 1) / 2;
}
DBG_PORT("PP: target clamped %dx%d -> %dx%d (buf=%d)\r\n",
(int)orig_w, (int)orig_h, (int)tgt_w, (int)tgt_h, (int)max_payload);
}
uint32_t required_bytes = (uint32_t)tgt_w * tgt_h * 2u;
/* 判断是否需要滑窗计算,或直接导出全图 */
if (tgt_w == w && tgt_h == h) {

View File

@ -315,13 +315,15 @@ static void parse_and_dispatch_tlv(TcpStreamCtx_t *ctx, const uint8_t *packet,
g_TcpLogic.has_valid_config = 1;
cfg_updated = 1;
qdx_port_mutex_unlock(g_TcpLogic.config_mutex);
DBG_LOGIC("<< [%s] Config2D: En=%d %dx%d Fps=%d "
DBG_LOGIC("<< [%s] Config2D: En=%d %dx%d Tgt=%dx%d Fps=%d "
"Trig=%d Burst=%d Intv=%d Thresh=%d "
"ROI(%d,%d,%d,%d) NGio=%d\r\n",
ctx->label,
(int)g_TcpLogic.cached_cfg2d.Enabled,
(int)g_TcpLogic.cached_cfg2d.Width,
(int)g_TcpLogic.cached_cfg2d.Height,
(int)g_TcpLogic.cached_cfg2d.TargetWidth,
(int)g_TcpLogic.cached_cfg2d.TargetHeight,
(int)g_TcpLogic.cached_cfg2d.Fps,
(int)g_TcpLogic.cached_cfg2d.TriggerMode,
(int)g_TcpLogic.cached_cfg2d.TriggerBurstCount,
@ -380,6 +382,9 @@ static void parse_and_dispatch_tlv(TcpStreamCtx_t *ctx, const uint8_t *packet,
}
break;
}
case TYPE_HANDSHAKE:
/* Server echoes handshake info — safe to ignore */
break;
default:
DBG_LOGIC("<< [%s] Unknown TLV type=0x%02x len=%d\r\n",
ctx->label, (int)type, (int)len);