Skip to content

Commit

Permalink
Revert "camerad: add CameraConfig struct for initializing CameraState…
Browse files Browse the repository at this point in the history
… in constructor (commaai#33034)"

This reverts commit dc886e1.
  • Loading branch information
adeebshihadeh committed Jul 22, 2024
1 parent dc886e1 commit cefe00c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 65 deletions.
3 changes: 3 additions & 0 deletions system/camerad/cameras/camera_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
43 changes: 16 additions & 27 deletions system/camerad/cameras/camera_qcom2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"});
}
Expand Down Expand Up @@ -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");
}

Expand Down Expand Up @@ -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;
Expand Down
46 changes: 8 additions & 38 deletions system/camerad/cameras/camera_qcom2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<const SensorInfo> ci;
bool enabled;
VisionStreamType stream_type;
float focal_len;

std::mutex exp_lock;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -132,4 +102,4 @@ class MultiCameraState {
CameraState driver_cam;

PubMaster *pm;
};
} MultiCameraState;

0 comments on commit cefe00c

Please sign in to comment.