diff --git a/plugins/ai_face_det/ai_face_det_node.cpp b/plugins/ai_face_det/ai_face_det_node.cpp index 684ce12..e93c327 100644 --- a/plugins/ai_face_det/ai_face_det_node.cpp +++ b/plugins/ai_face_det/ai_face_det_node.cpp @@ -14,6 +14,7 @@ #include "ai_scheduler.h" #include "face/face_result.h" #include "node.h" +#include "utils/dma_alloc.h" #include "utils/logger.h" namespace rk3588 { @@ -515,6 +516,18 @@ private: #if defined(RK3588_ENABLE_RKNN) void Run(FramePtr frame) { if (!frame->data || frame->data_size == 0) return; + + struct ScopedDmaCpuAccess { + int fd = -1; + bool active = false; + explicit ScopedDmaCpuAccess(int f) : fd(f), active(f >= 0) { + if (active) DmaSyncStartFd(fd); + } + ~ScopedDmaCpuAccess() { + if (active) DmaSyncEndFd(fd); + } + } sync(frame->dma_fd); + if (frame->format != PixelFormat::RGB && frame->format != PixelFormat::BGR) { std::cerr << "[ai_face_det] input must be RGB/BGR\n"; return; diff --git a/plugins/ai_face_recog/ai_face_recog_node.cpp b/plugins/ai_face_recog/ai_face_recog_node.cpp index 1c20833..7056c56 100644 --- a/plugins/ai_face_recog/ai_face_recog_node.cpp +++ b/plugins/ai_face_recog/ai_face_recog_node.cpp @@ -15,6 +15,7 @@ #include "ai_scheduler.h" #include "face/face_result.h" #include "node.h" +#include "utils/dma_alloc.h" #include "utils/logger.h" #if defined(RK3588_ENABLE_SQLITE3) @@ -776,6 +777,18 @@ private: void Run(FramePtr frame) { if (!frame->face_det || frame->face_det->faces.empty()) return; if (!frame->data || frame->data_size == 0) return; + + struct ScopedDmaCpuAccess { + int fd = -1; + bool active = false; + explicit ScopedDmaCpuAccess(int f) : fd(f), active(f >= 0) { + if (active) DmaSyncStartFd(fd); + } + ~ScopedDmaCpuAccess() { + if (active) DmaSyncEndFd(fd); + } + } sync(frame->dma_fd); + if (frame->format != PixelFormat::RGB && frame->format != PixelFormat::BGR) { std::cerr << "[ai_face_recog] input must be RGB/BGR\n"; return; diff --git a/plugins/ai_yolo/ai_yolo_node.cpp b/plugins/ai_yolo/ai_yolo_node.cpp index fb0871b..ac726be 100644 --- a/plugins/ai_yolo/ai_yolo_node.cpp +++ b/plugins/ai_yolo/ai_yolo_node.cpp @@ -11,6 +11,7 @@ #include "ai_scheduler.h" #include "node.h" +#include "utils/dma_alloc.h" #include "utils/logger.h" #if defined(RK3588_ENABLE_RKNN) @@ -407,6 +408,17 @@ private: void RunInference(FramePtr frame) { if (!frame->data || frame->data_size == 0) return; + struct ScopedDmaCpuAccess { + int fd = -1; + bool active = false; + explicit ScopedDmaCpuAccess(int f) : fd(f), active(f >= 0) { + if (active) DmaSyncStartFd(fd); + } + ~ScopedDmaCpuAccess() { + if (active) DmaSyncEndFd(fd); + } + } sync(frame->dma_fd); + bool is_rgb = (frame->format == PixelFormat::RGB || frame->format == PixelFormat::BGR); if (!is_rgb) { std::cerr << "[ai_yolo] input must be RGB/BGR, got other format\n";