|
|
@ -242,6 +242,9 @@ SpectraCamera::SpectraCamera(SpectraMaster *master, const CameraConfig &config, |
|
|
|
cc(config), |
|
|
|
cc(config), |
|
|
|
is_raw(raw) { |
|
|
|
is_raw(raw) { |
|
|
|
mm.init(m->video0_fd); |
|
|
|
mm.init(m->video0_fd); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ife_buf_depth = is_raw ? 4 : VIPC_BUFFER_COUNT; |
|
|
|
|
|
|
|
assert(ife_buf_depth < MAX_IFE_BUFS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SpectraCamera::~SpectraCamera() { |
|
|
|
SpectraCamera::~SpectraCamera() { |
|
|
@ -288,14 +291,15 @@ void SpectraCamera::camera_open(VisionIpcServer *v, cl_device_id device_id, cl_c |
|
|
|
linkDevices(); |
|
|
|
linkDevices(); |
|
|
|
|
|
|
|
|
|
|
|
LOGD("camera init %d", cc.camera_num); |
|
|
|
LOGD("camera init %d", cc.camera_num); |
|
|
|
buf.init(device_id, ctx, this, v, FRAME_BUF_COUNT, cc.stream_type); |
|
|
|
buf.init(device_id, ctx, this, v, ife_buf_depth, cc.stream_type); |
|
|
|
camera_map_bufs(); |
|
|
|
camera_map_bufs(); |
|
|
|
|
|
|
|
enqueue_req_multi(1, ife_buf_depth, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SpectraCamera::enqueue_req_multi(uint64_t start, int n, bool dp) { |
|
|
|
void SpectraCamera::enqueue_req_multi(uint64_t start, int n, bool dp) { |
|
|
|
for (uint64_t i = start; i < start + n; ++i) { |
|
|
|
for (uint64_t i = start; i < start + n; ++i) { |
|
|
|
request_ids[(i - 1) % FRAME_BUF_COUNT] = i; |
|
|
|
request_ids[(i - 1) % ife_buf_depth] = i; |
|
|
|
enqueue_buffer((i - 1) % FRAME_BUF_COUNT, dp); |
|
|
|
enqueue_buffer((i - 1) % ife_buf_depth, dp); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -670,7 +674,7 @@ void SpectraCamera::enqueue_buffer(int i, bool dp) { |
|
|
|
int ret; |
|
|
|
int ret; |
|
|
|
uint64_t request_id = request_ids[i]; |
|
|
|
uint64_t request_id = request_ids[i]; |
|
|
|
|
|
|
|
|
|
|
|
if (buf_handle_raw[i] && sync_objs[i]) { |
|
|
|
if (sync_objs[i]) { |
|
|
|
// wait
|
|
|
|
// wait
|
|
|
|
struct cam_sync_wait sync_wait = {0}; |
|
|
|
struct cam_sync_wait sync_wait = {0}; |
|
|
|
sync_wait.sync_obj = sync_objs[i]; |
|
|
|
sync_wait.sync_obj = sync_objs[i]; |
|
|
@ -733,31 +737,31 @@ void SpectraCamera::enqueue_buffer(int i, bool dp) { |
|
|
|
|
|
|
|
|
|
|
|
void SpectraCamera::camera_map_bufs() { |
|
|
|
void SpectraCamera::camera_map_bufs() { |
|
|
|
int ret; |
|
|
|
int ret; |
|
|
|
for (int i = 0; i < FRAME_BUF_COUNT; i++) { |
|
|
|
for (int i = 0; i < ife_buf_depth; i++) { |
|
|
|
// configure ISP to put the image in place
|
|
|
|
// configure ISP to put the image in place
|
|
|
|
struct cam_mem_mgr_map_cmd mem_mgr_map_cmd = {0}; |
|
|
|
struct cam_mem_mgr_map_cmd mem_mgr_map_cmd = {0}; |
|
|
|
|
|
|
|
mem_mgr_map_cmd.flags = CAM_MEM_FLAG_HW_READ_WRITE; |
|
|
|
mem_mgr_map_cmd.mmu_hdls[0] = m->device_iommu; |
|
|
|
mem_mgr_map_cmd.mmu_hdls[0] = m->device_iommu; |
|
|
|
|
|
|
|
mem_mgr_map_cmd.num_hdl = 1; |
|
|
|
//mem_mgr_map_cmd.mmu_hdls[1] = m->icp_device_iommu;
|
|
|
|
//mem_mgr_map_cmd.mmu_hdls[1] = m->icp_device_iommu;
|
|
|
|
//mem_mgr_map_cmd.num_hdl = 2;
|
|
|
|
//mem_mgr_map_cmd.num_hdl = 2;
|
|
|
|
mem_mgr_map_cmd.num_hdl = 1; |
|
|
|
|
|
|
|
mem_mgr_map_cmd.flags = CAM_MEM_FLAG_HW_READ_WRITE; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// RAW bayer images
|
|
|
|
if (is_raw) { |
|
|
|
mem_mgr_map_cmd.fd = buf.camera_bufs_raw[i].fd; |
|
|
|
// RAW bayer images
|
|
|
|
ret = do_cam_control(m->video0_fd, CAM_REQ_MGR_MAP_BUF, &mem_mgr_map_cmd, sizeof(mem_mgr_map_cmd)); |
|
|
|
mem_mgr_map_cmd.fd = buf.camera_bufs_raw[i].fd; |
|
|
|
assert(ret == 0); |
|
|
|
ret = do_cam_control(m->video0_fd, CAM_REQ_MGR_MAP_BUF, &mem_mgr_map_cmd, sizeof(mem_mgr_map_cmd)); |
|
|
|
LOGD("map buf req: (fd: %d) 0x%x %d", buf.camera_bufs_raw[i].fd, mem_mgr_map_cmd.out.buf_handle, ret); |
|
|
|
assert(ret == 0); |
|
|
|
buf_handle_raw[i] = mem_mgr_map_cmd.out.buf_handle; |
|
|
|
LOGD("map buf req: (fd: %d) 0x%x %d", buf.camera_bufs_raw[i].fd, mem_mgr_map_cmd.out.buf_handle, ret); |
|
|
|
|
|
|
|
buf_handle_raw[i] = mem_mgr_map_cmd.out.buf_handle; |
|
|
|
// TODO: this needs to match camera bufs length
|
|
|
|
} else { |
|
|
|
// final processed images
|
|
|
|
// final processed images
|
|
|
|
VisionBuf *vb = buf.vipc_server->get_buffer(buf.stream_type, i); |
|
|
|
VisionBuf *vb = buf.vipc_server->get_buffer(buf.stream_type, i); |
|
|
|
mem_mgr_map_cmd.fd = vb->fd; |
|
|
|
mem_mgr_map_cmd.fd = vb->fd; |
|
|
|
ret = do_cam_control(m->video0_fd, CAM_REQ_MGR_MAP_BUF, &mem_mgr_map_cmd, sizeof(mem_mgr_map_cmd)); |
|
|
|
ret = do_cam_control(m->video0_fd, CAM_REQ_MGR_MAP_BUF, &mem_mgr_map_cmd, sizeof(mem_mgr_map_cmd)); |
|
|
|
LOGD("map buf req: (fd: %d) 0x%x %d", vb->fd, mem_mgr_map_cmd.out.buf_handle, ret); |
|
|
|
LOGD("map buf req: (fd: %d) 0x%x %d", vb->fd, mem_mgr_map_cmd.out.buf_handle, ret); |
|
|
|
buf_handle_yuv[i] = mem_mgr_map_cmd.out.buf_handle; |
|
|
|
buf_handle_yuv[i] = mem_mgr_map_cmd.out.buf_handle; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
enqueue_req_multi(1, FRAME_BUF_COUNT, 0); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool SpectraCamera::openSensor() { |
|
|
|
bool SpectraCamera::openSensor() { |
|
|
@ -870,7 +874,7 @@ void SpectraCamera::configISP() { |
|
|
|
// allocate IFE memory, then configure it
|
|
|
|
// allocate IFE memory, then configure it
|
|
|
|
ife_cmd.init(m, 67984, 0x20, |
|
|
|
ife_cmd.init(m, 67984, 0x20, |
|
|
|
CAM_MEM_FLAG_HW_READ_WRITE | CAM_MEM_FLAG_KMD_ACCESS | CAM_MEM_FLAG_UMD_ACCESS | CAM_MEM_FLAG_CMD_BUF_TYPE, |
|
|
|
CAM_MEM_FLAG_HW_READ_WRITE | CAM_MEM_FLAG_KMD_ACCESS | CAM_MEM_FLAG_UMD_ACCESS | CAM_MEM_FLAG_CMD_BUF_TYPE, |
|
|
|
m->device_iommu, m->cdm_iommu, FRAME_BUF_COUNT); |
|
|
|
m->device_iommu, m->cdm_iommu, ife_buf_depth); |
|
|
|
if (!is_raw) { |
|
|
|
if (!is_raw) { |
|
|
|
ife_gamma_lut.init(m, 64*sizeof(uint32_t), 0x20, |
|
|
|
ife_gamma_lut.init(m, 64*sizeof(uint32_t), 0x20, |
|
|
|
CAM_MEM_FLAG_HW_READ_WRITE | CAM_MEM_FLAG_KMD_ACCESS | CAM_MEM_FLAG_UMD_ACCESS | CAM_MEM_FLAG_CMD_BUF_TYPE, |
|
|
|
CAM_MEM_FLAG_HW_READ_WRITE | CAM_MEM_FLAG_KMD_ACCESS | CAM_MEM_FLAG_UMD_ACCESS | CAM_MEM_FLAG_CMD_BUF_TYPE, |
|
|
@ -925,7 +929,7 @@ void SpectraCamera::configICP() { |
|
|
|
|
|
|
|
|
|
|
|
// BPS CMD buffer
|
|
|
|
// BPS CMD buffer
|
|
|
|
unsigned char striping_out[] = "\x00"; |
|
|
|
unsigned char striping_out[] = "\x00"; |
|
|
|
bps_cmd.init(m, FRAME_BUF_COUNT*ALIGNED_SIZE(464, 0x20), 0x20, |
|
|
|
bps_cmd.init(m, ife_buf_depth*ALIGNED_SIZE(464, 0x20), 0x20, |
|
|
|
CAM_MEM_FLAG_HW_READ_WRITE | CAM_MEM_FLAG_KMD_ACCESS | CAM_MEM_FLAG_UMD_ACCESS | CAM_MEM_FLAG_CMD_BUF_TYPE | CAM_MEM_FLAG_HW_SHARED_ACCESS, |
|
|
|
CAM_MEM_FLAG_HW_READ_WRITE | CAM_MEM_FLAG_KMD_ACCESS | CAM_MEM_FLAG_UMD_ACCESS | CAM_MEM_FLAG_CMD_BUF_TYPE | CAM_MEM_FLAG_HW_SHARED_ACCESS, |
|
|
|
m->icp_device_iommu); |
|
|
|
m->icp_device_iommu); |
|
|
|
|
|
|
|
|
|
|
@ -1046,9 +1050,8 @@ void SpectraCamera::camera_close() { |
|
|
|
ret = device_control(csiphy_fd, CAM_RELEASE_DEV, session_handle, csiphy_dev_handle); |
|
|
|
ret = device_control(csiphy_fd, CAM_RELEASE_DEV, session_handle, csiphy_dev_handle); |
|
|
|
LOGD("release csiphy: %d", ret); |
|
|
|
LOGD("release csiphy: %d", ret); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < FRAME_BUF_COUNT; i++) { |
|
|
|
for (int i = 0; i < ife_buf_depth; i++) { |
|
|
|
release(m->video0_fd, buf_handle_yuv[i]); |
|
|
|
release(m->video0_fd, is_raw ? buf_handle_raw[i] : buf_handle_yuv[i]); |
|
|
|
release(m->video0_fd, buf_handle_raw[i]); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
LOGD("released buffers"); |
|
|
|
LOGD("released buffers"); |
|
|
|
} |
|
|
|
} |
|
|
@ -1071,13 +1074,13 @@ void SpectraCamera::handle_camera_event(const cam_req_mgr_message *event_data) { |
|
|
|
|
|
|
|
|
|
|
|
if (real_id != 0) { // next ready
|
|
|
|
if (real_id != 0) { // next ready
|
|
|
|
if (real_id == 1) {idx_offset = main_id;} |
|
|
|
if (real_id == 1) {idx_offset = main_id;} |
|
|
|
int buf_idx = (real_id - 1) % FRAME_BUF_COUNT; |
|
|
|
int buf_idx = (real_id - 1) % ife_buf_depth; |
|
|
|
|
|
|
|
|
|
|
|
// check for skipped frames
|
|
|
|
// check for skipped frames
|
|
|
|
if (main_id > frame_id_last + 1 && !skipped) { |
|
|
|
if (main_id > frame_id_last + 1 && !skipped) { |
|
|
|
LOGE("camera %d realign", cc.camera_num); |
|
|
|
LOGE("camera %d realign", cc.camera_num); |
|
|
|
clear_req_queue(); |
|
|
|
clear_req_queue(); |
|
|
|
enqueue_req_multi(real_id + 1, FRAME_BUF_COUNT - 1, 0); |
|
|
|
enqueue_req_multi(real_id + 1, ife_buf_depth - 1, 0); |
|
|
|
skipped = true; |
|
|
|
skipped = true; |
|
|
|
} else if (main_id == frame_id_last + 1) { |
|
|
|
} else if (main_id == frame_id_last + 1) { |
|
|
|
skipped = false; |
|
|
|
skipped = false; |
|
|
@ -1086,7 +1089,7 @@ void SpectraCamera::handle_camera_event(const cam_req_mgr_message *event_data) { |
|
|
|
// check for dropped requests
|
|
|
|
// check for dropped requests
|
|
|
|
if (real_id > request_id_last + 1) { |
|
|
|
if (real_id > request_id_last + 1) { |
|
|
|
LOGE("camera %d dropped requests %ld %ld", cc.camera_num, real_id, request_id_last); |
|
|
|
LOGE("camera %d dropped requests %ld %ld", cc.camera_num, real_id, request_id_last); |
|
|
|
enqueue_req_multi(request_id_last + 1 + FRAME_BUF_COUNT, real_id - (request_id_last + 1), 0); |
|
|
|
enqueue_req_multi(request_id_last + 1 + ife_buf_depth, real_id - (request_id_last + 1), 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// metas
|
|
|
|
// metas
|
|
|
@ -1099,12 +1102,12 @@ void SpectraCamera::handle_camera_event(const cam_req_mgr_message *event_data) { |
|
|
|
meta_data.timestamp_sof = timestamp; // this is timestamped in the kernel's SOF IRQ callback
|
|
|
|
meta_data.timestamp_sof = timestamp; // this is timestamped in the kernel's SOF IRQ callback
|
|
|
|
|
|
|
|
|
|
|
|
// dispatch
|
|
|
|
// dispatch
|
|
|
|
enqueue_req_multi(real_id + FRAME_BUF_COUNT, 1, 1); |
|
|
|
enqueue_req_multi(real_id + ife_buf_depth, 1, 1); |
|
|
|
} else { // not ready
|
|
|
|
} else { // not ready
|
|
|
|
if (main_id > frame_id_last + 10) { |
|
|
|
if (main_id > frame_id_last + 10) { |
|
|
|
LOGE("camera %d reset after half second of no response", cc.camera_num); |
|
|
|
LOGE("camera %d reset after half second of no response", cc.camera_num); |
|
|
|
clear_req_queue(); |
|
|
|
clear_req_queue(); |
|
|
|
enqueue_req_multi(request_id_last + 1, FRAME_BUF_COUNT, 0); |
|
|
|
enqueue_req_multi(request_id_last + 1, ife_buf_depth, 0); |
|
|
|
frame_id_last = main_id; |
|
|
|
frame_id_last = main_id; |
|
|
|
skipped = true; |
|
|
|
skipped = true; |
|
|
|
} |
|
|
|
} |
|
|
|