From ea4bb0ff87ad61b02994e470972b8b4403542cfe Mon Sep 17 00:00:00 2001 From: sladro Date: Mon, 5 Jan 2026 16:22:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/preprocess/preprocess_node.cpp | 49 +++++++++++--------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/plugins/preprocess/preprocess_node.cpp b/plugins/preprocess/preprocess_node.cpp index 6d47e37..1e91fd4 100644 --- a/plugins/preprocess/preprocess_node.cpp +++ b/plugins/preprocess/preprocess_node.cpp @@ -199,7 +199,8 @@ public: if (!fmt_str.empty()) { dst_fmt_ = ParseFormat(fmt_str); } - use_rga_ = config.ValueOr("use_rga", true); + const bool requested_use_rga = config.ValueOr("use_rga", true); + use_rga_ = requested_use_rga; input_queue_ = ctx.input_queue; if (!input_queue_) { @@ -213,6 +214,10 @@ public: output_queues_ = ctx.output_queues; #if !defined(RK3588_ENABLE_RGA) + if (requested_use_rga) { + std::cerr << "[preprocess] use_rga=true but RGA not enabled at build time\n"; + return false; + } use_rga_ = false; #endif #if !defined(RK3588_ENABLE_FFMPEG) @@ -244,7 +249,9 @@ public: #if defined(RK3588_ENABLE_RGA) if (use_rga_) { - ProcessRga(frame); + if (!ProcessRga(frame)) { + return NodeStatus::ERROR; + } } else { ProcessSwscale(frame); } @@ -257,14 +264,6 @@ public: } private: - void FallbackToSwscaleOrPassthrough(FramePtr frame) { -#if defined(RK3588_ENABLE_FFMPEG) - ProcessSwscale(std::move(frame)); -#else - PushToDownstream(std::move(frame)); -#endif - } - void PushToDownstream(FramePtr frame) { for (auto& q : output_queues_) { q->Push(frame); @@ -280,7 +279,7 @@ private: } #if defined(RK3588_ENABLE_RGA) - void ProcessRga(FramePtr frame) { + bool ProcessRga(FramePtr frame) { PixelFormat out_fmt = (dst_fmt_ != PixelFormat::UNKNOWN) ? dst_fmt_ : frame->format; int out_w = dst_w_; int out_h = dst_h_; @@ -307,7 +306,7 @@ private: std::cout << "[preprocess] passthrough frame " << frame->frame_id << " " << frame->width << "x" << frame->height << " (no change)\n"; } - return; + return true; } // Calculate proper strides (RGA requires aligned strides) @@ -320,23 +319,20 @@ private: if (src_fmt_rga == RK_FORMAT_UNKNOWN || dst_fmt_rga == RK_FORMAT_UNKNOWN) { std::cerr << "[preprocess] unsupported format for RGA\n"; - FallbackToSwscaleOrPassthrough(frame); - return; + return false; } size_t out_size = CalcImageSizeStrided(dst_wstride, dst_hstride, out_fmt); if (out_size == 0) { std::cerr << "[preprocess] invalid output size for RGA\n"; - FallbackToSwscaleOrPassthrough(frame); - return; + return false; } // Use DMA-BUF allocation to avoid >4GB address issue with RGA auto dma_buf = DmaAlloc(out_size); if (!dma_buf || !dma_buf->valid()) { std::cerr << "[preprocess] DMA alloc failed\n"; - FallbackToSwscaleOrPassthrough(frame); - return; + return false; } if (processed_ < 3) { @@ -362,19 +358,16 @@ private: src_dma_buf = DmaAlloc(src_size); if (!src_dma_buf || !src_dma_buf->valid()) { std::cerr << "[preprocess] DMA alloc for src failed\n"; - FallbackToSwscaleOrPassthrough(frame); - return; + return false; } if (!CopyToStridedBuffer(*frame, src_dma_buf->data(), src_dma_buf->size, src_wstride, src_hstride)) { std::cerr << "[preprocess] copy src to DMA failed\n"; - FallbackToSwscaleOrPassthrough(frame); - return; + return false; } src_buf = wrapbuffer_fd_t(src_dma_buf->fd, frame->width, frame->height, src_wstride, src_hstride, src_fmt_rga); } else { - FallbackToSwscaleOrPassthrough(frame); - return; + return false; } // Use DMA fd for destination buffer @@ -388,8 +381,7 @@ private: auto tmp_dma = DmaAlloc(CalcImageSizeStrided(dst_wstride, dst_hstride, frame->format)); if (!tmp_dma || !tmp_dma->valid()) { std::cerr << "[preprocess] DMA alloc for tmp failed\n"; - FallbackToSwscaleOrPassthrough(frame); - return; + return false; } rga_buffer_t tmp = wrapbuffer_fd_t(tmp_dma->fd, out_w, out_h, dst_wstride, dst_hstride, src_fmt_rga); @@ -405,8 +397,7 @@ private: if (status != IM_STATUS_SUCCESS) { std::cerr << "[preprocess] RGA failed: " << imStrError(status) << "\n"; - FallbackToSwscaleOrPassthrough(frame); - return; + return false; } auto out_frame = std::make_shared(); @@ -434,6 +425,8 @@ private: << " " << frame->width << "x" << frame->height << " -> " << out_w << "x" << out_h << "\n"; } + + return true; } #endif