Skip to content

Commit

Permalink
visionipc: remove RGB support
Browse files Browse the repository at this point in the history
  • Loading branch information
adeebshihadeh committed Oct 7, 2024
1 parent cdcf84f commit c2c60c5
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 75 deletions.
13 changes: 2 additions & 11 deletions msgq/visionipc/tests/test_visionipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def zmq_sleep(t=1):

class TestVisionIpc:

def setup_vipc(self, name, *stream_types, num_buffers=1, rgb=False, width=100, height=100, conflate=False):
def setup_vipc(self, name, *stream_types, num_buffers=1, width=100, height=100, conflate=False):
self.server = VisionIpcServer(name)
for stream_type in stream_types:
self.server.create_buffers(stream_type, num_buffers, rgb, width, height)
self.server.create_buffers(stream_type, num_buffers, width, height)
self.server.start_listener()

if len(stream_types):
Expand Down Expand Up @@ -51,15 +51,6 @@ def test_buffers(self):
del self.client
del self.server

def test_yuv_rgb(self):
_, client_yuv = self.setup_vipc("camerad", VisionStreamType.VISION_STREAM_ROAD, rgb=False)
_, client_rgb = self.setup_vipc("navd", VisionStreamType.VISION_STREAM_MAP, rgb=True)
assert client_rgb.rgb
assert not client_yuv.rgb
del client_yuv
del client_rgb
del self.server

def test_send_single_buffer(self):
self.setup_vipc("camerad", VisionStreamType.VISION_STREAM_ROAD)

Expand Down
8 changes: 0 additions & 8 deletions msgq/visionipc/visionbuf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@ void visionbuf_compute_aligned_width_and_height(int width, int height, int *alig
*aligned_h = height;
}

void VisionBuf::init_rgb(size_t init_width, size_t init_height, size_t init_stride) {
this->rgb = true;
this->width = init_width;
this->height = init_height;
this->stride = init_stride;
}

void VisionBuf::init_yuv(size_t init_width, size_t init_height, size_t init_stride, size_t init_uv_offset){
this->rgb = false;
this->width = init_width;
this->height = init_height;
this->stride = init_stride;
Expand Down
2 changes: 0 additions & 2 deletions msgq/visionipc/visionbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class VisionBuf {
uint64_t *frame_id;
int fd = 0;

bool rgb = false;
size_t width = 0;
size_t height = 0;
size_t stride = 0;
Expand All @@ -54,7 +53,6 @@ class VisionBuf {
void allocate(size_t len);
void import();
void init_cl(cl_device_id device_id, cl_context ctx);
void init_rgb(size_t width, size_t height, size_t stride);
void init_yuv(size_t width, size_t height, size_t stride, size_t uv_offset);
int sync(int dir);
int free();
Expand Down
5 changes: 2 additions & 3 deletions msgq/visionipc/visionipc.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ cdef extern from "msgq/visionipc/visionbuf.h":

cdef cppclass VisionBuf:
void * addr
bool rgb
size_t len
size_t width
size_t height
Expand All @@ -42,8 +41,8 @@ cdef extern from "msgq/visionipc/visionipc_server.h":

cdef cppclass VisionIpcServer:
VisionIpcServer(string, void*, void*)
void create_buffers(VisionStreamType, size_t, bool, size_t, size_t)
void create_buffers_with_sizes(VisionStreamType, size_t, bool, size_t, size_t, size_t, size_t, size_t)
void create_buffers(VisionStreamType, size_t, size_t, size_t)
void create_buffers_with_sizes(VisionStreamType, size_t, size_t, size_t, size_t, size_t, size_t)
VisionBuf * get_buffer(VisionStreamType)
void send(VisionBuf *, VisionIpcBufExtra *, bool)
void start_listener()
Expand Down
6 changes: 1 addition & 5 deletions msgq/visionipc/visionipc_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ bool VisionIpcClient::connect(bool blocking){
buffers[i] = bufs[i];
buffers[i].fd = fds[i];
buffers[i].import();
if (buffers[i].rgb) {
buffers[i].init_rgb(buffers[i].width, buffers[i].height, buffers[i].stride);
} else {
buffers[i].init_yuv(buffers[i].width, buffers[i].height, buffers[i].stride, buffers[i].uv_offset);
}
buffers[i].init_yuv(buffers[i].width, buffers[i].height, buffers[i].stride, buffers[i].uv_offset);

if (device_id) buffers[i].init_cl(device_id, ctx);
}
Expand Down
16 changes: 4 additions & 12 deletions msgq/visionipc/visionipc_pyx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,18 @@ cdef class VisionBuf:
def uv_offset(self):
return self.buf.uv_offset

@property
def rgb(self):
return self.buf.rgb


cdef class VisionIpcServer:
cdef cppVisionIpcServer * server

def __init__(self, string name):
self.server = new cppVisionIpcServer(name, NULL, NULL)

def create_buffers(self, VisionStreamType tp, size_t num_buffers, bool rgb, size_t width, size_t height):
self.server.create_buffers(tp, num_buffers, rgb, width, height)
def create_buffers(self, VisionStreamType tp, size_t num_buffers, size_t width, size_t height):
self.server.create_buffers(tp, num_buffers, width, height)

def create_buffers_with_sizes(self, VisionStreamType tp, size_t num_buffers, bool rgb, size_t width, size_t height, size_t size, size_t stride, size_t uv_offset):
self.server.create_buffers_with_sizes(tp, num_buffers, rgb, width, height, size, stride, uv_offset)
def create_buffers_with_sizes(self, VisionStreamType tp, size_t num_buffers, size_t width, size_t height, size_t size, size_t stride, size_t uv_offset):
self.server.create_buffers_with_sizes(tp, num_buffers, width, height, size, stride, uv_offset)

def send(self, VisionStreamType tp, const unsigned char[:] data, uint32_t frame_id=0, uint64_t timestamp_sof=0, uint64_t timestamp_eof=0):
cdef cppVisionBuf * buf = self.server.get_buffer(tp)
Expand Down Expand Up @@ -123,10 +119,6 @@ cdef class VisionIpcClient:
def uv_offset(self):
return self.client.buffers[0].uv_offset if self.client.num_buffers else None

@property
def rgb(self):
return self.client.buffers[0].rgb if self.client.num_buffers else None

@property
def buffer_len(self):
return self.client.buffers[0].len if self.client.num_buffers else None
Expand Down
20 changes: 7 additions & 13 deletions msgq/visionipc/visionipc_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ VisionIpcServer::VisionIpcServer(std::string name, cl_device_id device_id, cl_co
server_id = distribution(rd);
}

void VisionIpcServer::create_buffers(VisionStreamType type, size_t num_buffers, bool rgb, size_t width, size_t height){
void VisionIpcServer::create_buffers(VisionStreamType type, size_t num_buffers, size_t width, size_t height){
// TODO: assert that this type is not created yet
assert(num_buffers < VISIONIPC_MAX_FDS);
int aligned_w = 0, aligned_h = 0;
Expand All @@ -47,20 +47,14 @@ void VisionIpcServer::create_buffers(VisionStreamType type, size_t num_buffers,
size_t stride = 0;
size_t uv_offset = 0;

if (rgb) {
visionbuf_compute_aligned_width_and_height(width, height, &aligned_w, &aligned_h);
size = (size_t)aligned_w * (size_t)aligned_h * 3;
stride = aligned_w * 3;
} else {
size = width * height * 3 / 2;
stride = width;
uv_offset = width * height;
}
size = width * height * 3 / 2;
stride = width;
uv_offset = width * height;

create_buffers_with_sizes(type, num_buffers, rgb, width, height, size, stride, uv_offset);
create_buffers_with_sizes(type, num_buffers, width, height, size, stride, uv_offset);
}

void VisionIpcServer::create_buffers_with_sizes(VisionStreamType type, size_t num_buffers, bool rgb, size_t width, size_t height, size_t size, size_t stride, size_t uv_offset) {
void VisionIpcServer::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) {
// Create map + alloc requested buffers
for (size_t i = 0; i < num_buffers; i++){
VisionBuf* buf = new VisionBuf();
Expand All @@ -70,7 +64,7 @@ void VisionIpcServer::create_buffers_with_sizes(VisionStreamType type, size_t nu

if (device_id) buf->init_cl(device_id, ctx);

rgb ? buf->init_rgb(width, height, stride) : buf->init_yuv(width, height, stride, uv_offset);
buf->init_yuv(width, height, stride, uv_offset);

buffers[type].push_back(buf);
}
Expand Down
4 changes: 2 additions & 2 deletions msgq/visionipc/visionipc_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class VisionIpcServer {

VisionBuf * get_buffer(VisionStreamType type);

void create_buffers(VisionStreamType type, size_t num_buffers, bool rgb, size_t width, size_t height);
void create_buffers_with_sizes(VisionStreamType type, size_t num_buffers, bool rgb, size_t width, size_t height, size_t size, size_t stride, size_t uv_offset);
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);
void send(VisionBuf * buf, VisionIpcBufExtra * extra, bool sync=true);
void start_listener();
};
23 changes: 4 additions & 19 deletions msgq/visionipc/visionipc_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static void zmq_sleep(int milliseconds=1000){

TEST_CASE("Connecting"){
VisionIpcServer server("camerad");
server.create_buffers(VISION_STREAM_ROAD, 1, false, 100, 100);
server.create_buffers(VISION_STREAM_ROAD, 1, 100, 100);
server.start_listener();

VisionIpcClient client = VisionIpcClient("camerad", VISION_STREAM_ROAD, false);
Expand All @@ -26,8 +26,8 @@ TEST_CASE("Connecting"){

TEST_CASE("getAvailableStreams"){
VisionIpcServer server("camerad");
server.create_buffers(VISION_STREAM_ROAD, 1, false, 100, 100);
server.create_buffers(VISION_STREAM_WIDE_ROAD, 1, false, 100, 100);
server.create_buffers(VISION_STREAM_ROAD, 1, 100, 100);
server.create_buffers(VISION_STREAM_WIDE_ROAD, 1, 100, 100);
server.start_listener();
auto available_streams = VisionIpcClient::getAvailableStreams("camerad");
REQUIRE(available_streams.size() == 2);
Expand All @@ -38,7 +38,7 @@ TEST_CASE("getAvailableStreams"){
TEST_CASE("Check buffers"){
size_t width = 100, height = 200, num_buffers = 5;
VisionIpcServer server("camerad");
server.create_buffers(VISION_STREAM_ROAD, num_buffers, false, width, height);
server.create_buffers(VISION_STREAM_ROAD, num_buffers, width, height);
server.start_listener();

VisionIpcClient client = VisionIpcClient("camerad", VISION_STREAM_ROAD, false);
Expand All @@ -50,21 +50,6 @@ TEST_CASE("Check buffers"){
REQUIRE(client.num_buffers == num_buffers);
}

TEST_CASE("Check yuv/rgb"){
VisionIpcServer server("camerad");
server.create_buffers(VISION_STREAM_ROAD, 1, false, 100, 100);
server.create_buffers(VISION_STREAM_MAP, 1, true, 100, 100);
server.start_listener();

VisionIpcClient client_yuv = VisionIpcClient("camerad", VISION_STREAM_ROAD, false);
VisionIpcClient client_rgb = VisionIpcClient("camerad", VISION_STREAM_MAP, false);
client_yuv.connect();
client_rgb.connect();

REQUIRE(client_rgb.buffers[0].rgb == true);
REQUIRE(client_yuv.buffers[0].rgb == false);
}

TEST_CASE("Send single buffer"){
VisionIpcServer server("camerad");
server.create_buffers(VISION_STREAM_ROAD, 1, true, 100, 100);
Expand Down

0 comments on commit c2c60c5

Please sign in to comment.