From cefe00c964d41f5ac15f13bc83b3e389d8965a5e Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sun, 21 Jul 2024 20:36:45 -0700 Subject: [PATCH] Revert "camerad: add CameraConfig struct for initializing CameraState in constructor (#33034)" This reverts commit dc886e195f9815c77b721a8a438bbdffe9067e38. --- system/camerad/cameras/camera_common.h | 3 ++ system/camerad/cameras/camera_qcom2.cc | 43 +++++++++--------------- system/camerad/cameras/camera_qcom2.h | 46 +++++--------------------- 3 files changed, 27 insertions(+), 65 deletions(-) diff --git a/system/camerad/cameras/camera_common.h b/system/camerad/cameras/camera_common.h index f97940b669fb63..555362ab8bc7ab 100644 --- a/system/camerad/cameras/camera_common.h +++ b/system/camerad/cameras/camera_common.h @@ -18,6 +18,9 @@ enum CameraType { }; // for debugging +const bool env_disable_road = getenv("DISABLE_ROAD") != NULL; +const bool env_disable_wide_road = getenv("DISABLE_WIDE_ROAD") != NULL; +const bool env_disable_driver = getenv("DISABLE_DRIVER") != NULL; const bool env_debug_frames = getenv("DEBUG_FRAMES") != NULL; const bool env_log_raw_frames = getenv("LOG_RAW_FRAMES") != NULL; const bool env_ctrl_exp_from_params = getenv("CTRL_EXP_FROM_PARAMS") != NULL; diff --git a/system/camerad/cameras/camera_qcom2.cc b/system/camerad/cameras/camera_qcom2.cc index 2eba1e36155542..47ea5ded4d8e0d 100644 --- a/system/camerad/cameras/camera_qcom2.cc +++ b/system/camerad/cameras/camera_qcom2.cc @@ -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 threads; diff --git a/system/camerad/cameras/camera_qcom2.h b/system/camerad/cameras/camera_qcom2.h index bdebeef9f80225..0b15c9c3f04f06 100644 --- a/system/camerad/cameras/camera_qcom2.h +++ b/system/camerad/cameras/camera_qcom2.h @@ -11,41 +11,15 @@ #define FRAME_BUF_COUNT 4 -struct CameraConfig { - int camera_num; - VisionStreamType stream_type; - float focal_len; // millimeters - bool enabled; -}; - -const CameraConfig WIDE_ROAD_CAMERA_CONFIG = { - .camera_num = 0, - .stream_type = VISION_STREAM_WIDE_ROAD, - .focal_len = 1.71, - .enabled = !getenv("DISABLE_WIDE_ROAD"), -}; - -const CameraConfig ROAD_CAMERA_CONFIG = { - .camera_num = 1, - .stream_type = VISION_STREAM_ROAD, - .focal_len = 8.0, - .enabled = !getenv("DISABLE_ROAD"), -}; - -const CameraConfig DRIVER_CAMERA_CONFIG = { - .camera_num = 2, - .stream_type = VISION_STREAM_DRIVER, - .focal_len = 1.71, - .enabled = !getenv("DISABLE_DRIVER"), -}; +#define ROAD_FL_MM 8.0f +#define WIDE_FL_MM 1.71f +#define DRIVER_FL_MM 1.71f class CameraState { public: MultiCameraState *multi_cam_state; std::unique_ptr ci; bool enabled; - VisionStreamType stream_type; - float focal_len; std::mutex exp_lock; @@ -70,18 +44,17 @@ class CameraState { int camera_num; float fl_pix; - CameraState(MultiCameraState *multi_camera_state, const CameraConfig &config); void handle_camera_event(void *evdat); void update_exposure_score(float desired_ev, int exp_t, int exp_g_idx, float exp_gain); void set_camera_exposure(float grey_frac); void sensors_start(); - void camera_open(); + void camera_open(MultiCameraState *multi_cam_state, int camera_num, bool enabled); void set_exposure_rect(); void sensor_set_parameters(); - void camera_map_bufs(); - void camera_init(VisionIpcServer *v, cl_device_id device_id, cl_context ctx); + void camera_map_bufs(MultiCameraState *s); + void camera_init(MultiCameraState *s, VisionIpcServer *v, cl_device_id device_id, cl_context ctx, VisionStreamType yuv_type, float focal_len); void camera_close(); int32_t session_handle; @@ -117,10 +90,7 @@ class CameraState { Params params; }; -class MultiCameraState { -public: - MultiCameraState(); - +typedef struct MultiCameraState { unique_fd video0_fd; unique_fd cam_sync_fd; unique_fd isp_fd; @@ -132,4 +102,4 @@ class MultiCameraState { CameraState driver_cam; PubMaster *pm; -}; +} MultiCameraState;