|
|
|
@ -26,14 +26,6 @@ const int MIPI_SETTLE_CNT = 33; // Calculated by camera_freqs.py |
|
|
|
|
|
|
|
|
|
extern ExitHandler do_exit; |
|
|
|
|
|
|
|
|
|
CameraState::CameraState(MultiCameraState *multi_camera_state, const CameraConfig &config) |
|
|
|
|
: multi_cam_state(multi_camera_state), |
|
|
|
|
camera_num(config.camera_num), |
|
|
|
|
stream_type(config.stream_type), |
|
|
|
|
focal_len(config.focal_len), |
|
|
|
|
enabled(config.enabled) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int CameraState::clear_req_queue() { |
|
|
|
|
struct cam_req_mgr_flush_info req_mgr_flush_request = {0}; |
|
|
|
|
req_mgr_flush_request.session_hdl = session_handle; |
|
|
|
@ -442,36 +434,39 @@ void CameraState::sensor_set_parameters() { |
|
|
|
|
cur_ev[0] = cur_ev[1] = cur_ev[2] = (1 + dc_gain_weight * (ci->dc_gain_factor-1) / ci->dc_gain_max_weight) * ci->sensor_analog_gains[gain_idx] * exposure_time; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CameraState::camera_map_bufs() { |
|
|
|
|
void CameraState::camera_map_bufs(MultiCameraState *s) { |
|
|
|
|
for (int i = 0; i < FRAME_BUF_COUNT; i++) { |
|
|
|
|
// configure ISP to put the image in place
|
|
|
|
|
struct cam_mem_mgr_map_cmd mem_mgr_map_cmd = {0}; |
|
|
|
|
mem_mgr_map_cmd.mmu_hdls[0] = multi_cam_state->device_iommu; |
|
|
|
|
mem_mgr_map_cmd.mmu_hdls[0] = s->device_iommu; |
|
|
|
|
mem_mgr_map_cmd.num_hdl = 1; |
|
|
|
|
mem_mgr_map_cmd.flags = CAM_MEM_FLAG_HW_READ_WRITE; |
|
|
|
|
mem_mgr_map_cmd.fd = buf.camera_bufs[i].fd; |
|
|
|
|
int ret = do_cam_control(multi_cam_state->video0_fd, CAM_REQ_MGR_MAP_BUF, &mem_mgr_map_cmd, sizeof(mem_mgr_map_cmd)); |
|
|
|
|
int ret = do_cam_control(s->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[i].fd, mem_mgr_map_cmd.out.buf_handle, ret); |
|
|
|
|
buf_handle[i] = mem_mgr_map_cmd.out.buf_handle; |
|
|
|
|
} |
|
|
|
|
enqueue_req_multi(1, FRAME_BUF_COUNT, 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CameraState::camera_init(VisionIpcServer * v, cl_device_id device_id, cl_context ctx) { |
|
|
|
|
void CameraState::camera_init(MultiCameraState *s, VisionIpcServer * v, cl_device_id device_id, cl_context ctx, VisionStreamType yuv_type, float focal_len) { |
|
|
|
|
if (!enabled) return; |
|
|
|
|
|
|
|
|
|
LOGD("camera init %d", camera_num); |
|
|
|
|
request_id_last = 0; |
|
|
|
|
skipped = true; |
|
|
|
|
|
|
|
|
|
buf.init(device_id, ctx, this, v, FRAME_BUF_COUNT, stream_type); |
|
|
|
|
camera_map_bufs(); |
|
|
|
|
buf.init(device_id, ctx, this, v, FRAME_BUF_COUNT, yuv_type); |
|
|
|
|
camera_map_bufs(s); |
|
|
|
|
|
|
|
|
|
fl_pix = focal_len / ci->pixel_size_mm; |
|
|
|
|
set_exposure_rect(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CameraState::camera_open() { |
|
|
|
|
void CameraState::camera_open(MultiCameraState *multi_cam_state_, int camera_num_, bool enabled_) { |
|
|
|
|
multi_cam_state = multi_cam_state_; |
|
|
|
|
camera_num = camera_num_; |
|
|
|
|
enabled = enabled_; |
|
|
|
|
if (!enabled) return; |
|
|
|
|
|
|
|
|
|
sensor_fd = open_v4l_by_name_and_index("cam-sensor-driver", camera_num); |
|
|
|
@ -649,9 +644,9 @@ void CameraState::camera_open() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void cameras_init(VisionIpcServer *v, MultiCameraState *s, cl_device_id device_id, cl_context ctx) { |
|
|
|
|
s->driver_cam.camera_init(v, device_id, ctx); |
|
|
|
|
s->road_cam.camera_init(v, device_id, ctx); |
|
|
|
|
s->wide_road_cam.camera_init(v, device_id, ctx); |
|
|
|
|
s->driver_cam.camera_init(s, v, device_id, ctx, VISION_STREAM_DRIVER, DRIVER_FL_MM); |
|
|
|
|
s->road_cam.camera_init(s, v, device_id, ctx, VISION_STREAM_ROAD, ROAD_FL_MM); |
|
|
|
|
s->wide_road_cam.camera_init(s, v, device_id, ctx, VISION_STREAM_WIDE_ROAD, WIDE_FL_MM); |
|
|
|
|
|
|
|
|
|
s->pm = new PubMaster({"roadCameraState", "driverCameraState", "wideRoadCameraState", "thumbnail"}); |
|
|
|
|
} |
|
|
|
@ -695,11 +690,11 @@ void cameras_open(MultiCameraState *s) { |
|
|
|
|
ret = HANDLE_EINTR(ioctl(s->video0_fd, VIDIOC_SUBSCRIBE_EVENT, &sub)); |
|
|
|
|
LOGD("req mgr subscribe: %d", ret); |
|
|
|
|
|
|
|
|
|
s->driver_cam.camera_open(); |
|
|
|
|
s->driver_cam.camera_open(s, 2, !env_disable_driver); |
|
|
|
|
LOGD("driver camera opened"); |
|
|
|
|
s->road_cam.camera_open(); |
|
|
|
|
s->road_cam.camera_open(s, 1, !env_disable_road); |
|
|
|
|
LOGD("road camera opened"); |
|
|
|
|
s->wide_road_cam.camera_open(); |
|
|
|
|
s->wide_road_cam.camera_open(s, 0, !env_disable_wide_road); |
|
|
|
|
LOGD("wide road camera opened"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -961,12 +956,6 @@ void process_road_camera(MultiCameraState *s, CameraState *c, int cnt) { |
|
|
|
|
c->set_camera_exposure(set_exposure_target(b, c->ae_xywh, skip, skip)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
MultiCameraState::MultiCameraState() |
|
|
|
|
: driver_cam(this, DRIVER_CAMERA_CONFIG), |
|
|
|
|
road_cam(this, ROAD_CAMERA_CONFIG), |
|
|
|
|
wide_road_cam(this, WIDE_ROAD_CAMERA_CONFIG) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void cameras_run(MultiCameraState *s) { |
|
|
|
|
LOG("-- Starting threads"); |
|
|
|
|
std::vector<std::thread> threads; |
|
|
|
|