camerad: make handle_camera_event readable (#34620)

* renames

* lil more

---------

Co-authored-by: Comma Device <device@comma.ai>
pull/34622/head
Adeeb Shihadeh 2 months ago committed by GitHub
parent 51ba8f796d
commit fb3f5dd169
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 54
      system/camerad/cameras/spectra.cc
  2. 6
      system/camerad/cameras/spectra.h

@ -1370,50 +1370,52 @@ void SpectraCamera::camera_close() {
void SpectraCamera::handle_camera_event(const cam_req_mgr_message *event_data) {
if (!enabled) return;
uint64_t timestamp = event_data->u.frame_msg.timestamp;
uint64_t main_id = event_data->u.frame_msg.frame_id;
uint64_t real_id = event_data->u.frame_msg.request_id;
// ID from the qcom camera request manager
uint64_t request_id = event_data->u.frame_msg.request_id;
if (real_id != 0) { // next ready
if (real_id == 1) {
idx_offset = main_id;
// raw as opposed to our re-indexed frame ID
uint64_t frame_id_raw = event_data->u.frame_msg.frame_id;
if (request_id != 0) { // next ready
if (request_id == 1) {
frame_id_offset = frame_id_raw;
}
int buf_idx = (real_id - 1) % ife_buf_depth;
int buf_idx = (request_id - 1) % ife_buf_depth;
// check for skipped frames
if (main_id > frame_id_last + 1 && !skipped) {
// check for skipped_last frames
if (frame_id_raw > frame_id_raw_last + 1 && !skipped_last) {
LOGE("camera %d realign", cc.camera_num);
clear_req_queue();
enqueue_req_multi(real_id + 1, ife_buf_depth - 1, 0);
skipped = true;
} else if (main_id == frame_id_last + 1) {
skipped = false;
enqueue_req_multi(request_id + 1, ife_buf_depth - 1, 0);
skipped_last = true;
} else if (frame_id_raw == frame_id_raw_last + 1) {
skipped_last = false;
}
// check for dropped requests
if (real_id > request_id_last + 1) {
LOGE("camera %d dropped requests %ld %ld", cc.camera_num, real_id, request_id_last);
enqueue_req_multi(request_id_last + 1 + ife_buf_depth, real_id - (request_id_last + 1), 0);
if (request_id > request_id_last + 1) {
LOGE("camera %d dropped requests %ld %ld", cc.camera_num, request_id, request_id_last);
enqueue_req_multi(request_id_last + 1 + ife_buf_depth, request_id - (request_id_last + 1), 0);
}
// metas
frame_id_last = main_id;
request_id_last = real_id;
frame_id_raw_last = frame_id_raw;
request_id_last = request_id;
auto &meta_data = buf.frame_metadata[buf_idx];
meta_data.frame_id = main_id - idx_offset;
meta_data.request_id = real_id;
meta_data.timestamp_sof = timestamp; // this is timestamped in the kernel's SOF IRQ callback
meta_data.frame_id = frame_id_raw - frame_id_offset;
meta_data.request_id = request_id;
meta_data.timestamp_sof = event_data->u.frame_msg.timestamp; // this is timestamped in the kernel's SOF IRQ callback
// dispatch
enqueue_req_multi(real_id + ife_buf_depth, 1, 1);
// wait for this frame's EOF, then queue up the next one
enqueue_req_multi(request_id + ife_buf_depth, 1, 1);
} else { // not ready
if (main_id > frame_id_last + 10) {
if (frame_id_raw > frame_id_raw_last + 10) {
LOGE("camera %d reset after half second of no response", cc.camera_num);
clear_req_queue();
enqueue_req_multi(request_id_last + 1, ife_buf_depth, 0);
frame_id_last = main_id;
skipped = true;
frame_id_raw_last = frame_id_raw;
skipped_last = true;
}
}
}

@ -188,9 +188,9 @@ public:
int sync_objs_bps[MAX_IFE_BUFS] = {};
uint64_t request_ids[MAX_IFE_BUFS] = {};
uint64_t request_id_last = 0;
uint64_t frame_id_last = 0;
uint64_t idx_offset = 0;
bool skipped = true;
uint64_t frame_id_raw_last = 0;
uint64_t frame_id_offset = 0;
bool skipped_last = true;
SpectraOutputType output_type;

Loading…
Cancel
Save