From 21dd258577c03c071bc9d90b23a6f5d529cef92c Mon Sep 17 00:00:00 2001 From: sladro Date: Mon, 29 Dec 2025 10:59:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=98=B6=E6=AE=B54=E4=B9=8B?= =?UTF-8?q?=E5=89=8D=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/preprocess/preprocess_node.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/plugins/preprocess/preprocess_node.cpp b/plugins/preprocess/preprocess_node.cpp index 889b665..e3ff5ef 100644 --- a/plugins/preprocess/preprocess_node.cpp +++ b/plugins/preprocess/preprocess_node.cpp @@ -302,13 +302,27 @@ private: return; } - size_t out_size = CalcImageSizeStrided(dst_wstride, dst_hstride, out_fmt); - if (out_size == 0 || src_fmt_rga == RK_FORMAT_UNKNOWN || dst_fmt_rga == RK_FORMAT_UNKNOWN) { + // Calculate proper strides (RGA requires aligned strides) + // For YUV formats, wstride is the width of Y plane + // For RGB/BGR formats, wstride is width (not width*3) + int src_wstride = Align16(frame->width); + int src_hstride = Align16(frame->height); + int dst_wstride = Align16(out_w); + int dst_hstride = Align16(out_h); + + if (src_fmt_rga == RK_FORMAT_UNKNOWN || dst_fmt_rga == RK_FORMAT_UNKNOWN) { std::cerr << "[preprocess] unsupported format for RGA\n"; PushToDownstream(frame); return; } + size_t out_size = CalcImageSizeStrided(dst_wstride, dst_hstride, out_fmt); + if (out_size == 0) { + std::cerr << "[preprocess] invalid output size for RGA\n"; + PushToDownstream(frame); + return; + } + // Use DMA-BUF allocation to avoid >4GB address issue with RGA auto dma_buf = DmaAlloc(out_size); if (!dma_buf || !dma_buf->valid()) { @@ -317,14 +331,6 @@ private: return; } - // Calculate proper strides (RGA requires aligned strides) - // For YUV formats, wstride is the width of Y plane - // For RGB/BGR formats, wstride is width (not width*3) - int src_wstride = Align16(frame->width); - int src_hstride = Align16(frame->height); - int dst_wstride = Align16(out_w); - int dst_hstride = Align16(out_h); - if (processed_ < 3) { std::cout << "[preprocess] src: " << frame->width << "x" << frame->height << " fmt=" << static_cast(frame->format) << " rga_fmt=" << src_fmt_rga