Keep resized DMA buffers alive through inference

This commit is contained in:
tian 2026-03-14 21:48:04 +08:00
parent b5dc20f7bf
commit f033efb3b9
2 changed files with 17 additions and 4 deletions

View File

@ -571,6 +571,8 @@ private:
const uint8_t* model_input_data = nullptr;
size_t model_input_size = 0;
int model_input_dma_fd = -1;
Frame resized_frame;
if (image_processor_ && win_w > 0 && win_h > 0) {
Frame crop_frame;
@ -583,7 +585,6 @@ private:
crop_frame.plane_count = 1;
crop_frame.planes[0] = {crop_buf.data(), crop_frame.stride, static_cast<int>(crop_buf.size()), 0};
Frame resized_frame;
resized_frame.width = model_w_;
resized_frame.height = model_h_;
resized_frame.format = PixelFormat::RGB;
@ -595,7 +596,11 @@ private:
? resized_frame.planes[0].stride
: (resized_frame.stride > 0 ? resized_frame.stride : model_w_ * 3);
const size_t packed_size = static_cast<size_t>(model_w_) * static_cast<size_t>(model_h_) * 3;
if (resized_data && resized_stride > 0) {
if (resized_frame.DmaFd() >= 0 && resized_data) {
model_input_data = resized_data;
model_input_size = resized_frame.data_size > 0 ? resized_frame.data_size : packed_size;
model_input_dma_fd = resized_frame.DmaFd();
} else if (resized_data && resized_stride > 0) {
if (packed_size > input_buf_.size()) input_buf_.resize(packed_size);
for (int row = 0; row < model_h_; ++row) {
memcpy(input_buf_.data() + static_cast<size_t>(row) * static_cast<size_t>(model_w_) * 3,
@ -622,6 +627,7 @@ private:
input.is_nhwc = true;
input.data = model_input_data;
input.size = model_input_size;
input.dma_fd = model_input_dma_fd;
input.type = RKNN_TENSOR_UINT8;
auto r = infer_backend_->InferBorrowed(model_handle_, input);

View File

@ -900,6 +900,7 @@ private:
const size_t input_row = static_cast<size_t>(model_input_w_) * 3;
const size_t input_size = input_row * static_cast<size_t>(model_input_h_);
resized_input_.resize(input_size);
Frame resized_frame;
if (exact_model_input) {
for (int y = 0; y < h; ++y) {
@ -918,7 +919,6 @@ private:
src_frame.plane_count = 1;
src_frame.planes[0] = {src_frame.data, src_stride, static_cast<int>(frame->data_size), 0};
Frame resized_frame;
resized_frame.width = model_input_w_;
resized_frame.height = model_input_h_;
resized_frame.format = PixelFormat::RGB;
@ -929,7 +929,14 @@ private:
const int resized_stride = resized_frame.planes[0].stride > 0
? resized_frame.planes[0].stride
: (resized_frame.stride > 0 ? resized_frame.stride : static_cast<int>(input_row));
if (resized_data && resized_stride > 0) {
if (resized_frame.DmaFd() >= 0 && resized_data) {
input.data = resized_data;
input.size = resized_frame.data_size > 0 ? resized_frame.data_size : input_size;
input.width = model_input_w_;
input.height = model_input_h_;
input.dma_fd = resized_frame.DmaFd();
input.dma_offset = 0;
} else if (resized_data && resized_stride > 0) {
for (int y = 0; y < model_input_h_; ++y) {
memcpy(resized_input_.data() + static_cast<size_t>(y) * input_row,
resized_data + static_cast<size_t>(y) * static_cast<size_t>(resized_stride),