Skip to content

Commit

Permalink
camerad: fix CAM_SYNC requests (#33757)
Browse files Browse the repository at this point in the history
* camerad: fix CAM_SYNC requests

* cast

---------

Co-authored-by: Comma Device <device@comma.ai>
  • Loading branch information
adeebshihadeh and Comma Device authored Oct 9, 2024
1 parent 596d8b1 commit 50baf37
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions system/camerad/cameras/spectra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ int do_cam_control(int fd, int op_code, void *handle, int size) {
return ret;
}

int do_sync_control(int fd, uint32_t id, void *handle, uint32_t size) {
struct cam_private_ioctl_arg arg = {
.id = id,
.size = size,
.ioctl_ptr = (uint64_t)handle,
};
int ret = HANDLE_EINTR(ioctl(fd, CAM_PRIVATE_IOCTL_CMD, &arg));

int32_t ioctl_result = (int32_t)arg.result;
if (ret < 0) {
LOGE("CAM_SYNC error: id %u - errno %d - ret %d - ioctl_result %d", id, errno, ret, ioctl_result);
return ret;
}
if (ioctl_result < 0) {
LOGE("CAM_SYNC error: id %u - errno %d - ret %d - ioctl_result %d", id, errno, ret, ioctl_result);
return ioctl_result;
}
return ret;
}

std::optional<int32_t> device_acquire(int fd, int32_t session_handle, void *data, uint32_t num_resources) {
struct cam_acquire_dev_cmd cmd = {
.session_handle = session_handle,
Expand Down Expand Up @@ -558,7 +578,7 @@ void SpectraCamera::enqueue_buffer(int i, bool dp) {
struct cam_sync_wait sync_wait = {0};
sync_wait.sync_obj = sync_objs[i];
sync_wait.timeout_ms = 50; // max dt tolerance, typical should be 23
ret = do_cam_control(m->cam_sync_fd, CAM_SYNC_WAIT, &sync_wait, sizeof(sync_wait));
ret = do_sync_control(m->cam_sync_fd, CAM_SYNC_WAIT, &sync_wait, sizeof(sync_wait));
if (ret != 0) {
LOGE("failed to wait for sync: %d %d", ret, sync_wait.sync_obj);
// TODO: handle frame drop cleanly
Expand All @@ -570,7 +590,7 @@ void SpectraCamera::enqueue_buffer(int i, bool dp) {
// destroy old output fence
struct cam_sync_info sync_destroy = {0};
sync_destroy.sync_obj = sync_objs[i];
ret = do_cam_control(m->cam_sync_fd, CAM_SYNC_DESTROY, &sync_destroy, sizeof(sync_destroy));
ret = do_sync_control(m->cam_sync_fd, CAM_SYNC_DESTROY, &sync_destroy, sizeof(sync_destroy));
if (ret != 0) {
LOGE("failed to destroy sync object: %d %d", ret, sync_destroy.sync_obj);
}
Expand All @@ -579,7 +599,7 @@ void SpectraCamera::enqueue_buffer(int i, bool dp) {
// create output fence
struct cam_sync_info sync_create = {0};
strcpy(sync_create.name, "NodeOutputPortFence");
ret = do_cam_control(m->cam_sync_fd, CAM_SYNC_CREATE, &sync_create, sizeof(sync_create));
ret = do_sync_control(m->cam_sync_fd, CAM_SYNC_CREATE, &sync_create, sizeof(sync_create));
if (ret != 0) {
LOGE("failed to create fence: %d %d", ret, sync_create.sync_obj);
}
Expand Down

0 comments on commit 50baf37

Please sign in to comment.