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