From 3e17f865bbd3bbabb3841227ed0774c8fb74efef Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sat, 12 Oct 2024 11:01:41 -0700 Subject: [PATCH] visionipc: get arbitrary buffers from server (#633) --- msgq/visionipc/visionipc_server.cc | 10 ++++++++-- msgq/visionipc/visionipc_server.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/msgq/visionipc/visionipc_server.cc b/msgq/visionipc/visionipc_server.cc index 611456b..5f80d01 100644 --- a/msgq/visionipc/visionipc_server.cc +++ b/msgq/visionipc/visionipc_server.cc @@ -160,11 +160,17 @@ void VisionIpcServer::listener(){ -VisionBuf * VisionIpcServer::get_buffer(VisionStreamType type){ +VisionBuf * VisionIpcServer::get_buffer(VisionStreamType type, int idx){ // Do we want to keep track if the buffer has been sent out yet and warn user? assert(buffers.count(type)); auto b = buffers[type]; - return b[cur_idx[type]++ % b.size()]; + if (idx < 0) { + idx = cur_idx[type]++ % b.size(); + } else { + assert(idx < b.size() && idx >= 0); + cur_idx[type] = idx; + } + return b[idx]; } void VisionIpcServer::send(VisionBuf * buf, VisionIpcBufExtra * extra, bool sync){ diff --git a/msgq/visionipc/visionipc_server.h b/msgq/visionipc/visionipc_server.h index c8d25eb..b96f498 100644 --- a/msgq/visionipc/visionipc_server.h +++ b/msgq/visionipc/visionipc_server.h @@ -33,7 +33,7 @@ class VisionIpcServer { VisionIpcServer(std::string name, cl_device_id device_id=nullptr, cl_context ctx=nullptr); ~VisionIpcServer(); - VisionBuf * get_buffer(VisionStreamType type); + VisionBuf * get_buffer(VisionStreamType type, int idx = -1); void create_buffers(VisionStreamType type, size_t num_buffers, size_t width, size_t height); void create_buffers_with_sizes(VisionStreamType type, size_t num_buffers, size_t width, size_t height, size_t size, size_t stride, size_t uv_offset);