From fb3f5dd1694f917ad2bd77b019b5ad3df8ecc2eb Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 18 Feb 2025 22:58:53 -0800 Subject: [PATCH] camerad: make handle_camera_event readable (#34620) * renames * lil more --------- Co-authored-by: Comma Device --- system/camerad/cameras/spectra.cc | 54 ++++++++++++++++--------------- system/camerad/cameras/spectra.h | 6 ++-- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/system/camerad/cameras/spectra.cc b/system/camerad/cameras/spectra.cc index c4e41d62b3..34bd565e29 100644 --- a/system/camerad/cameras/spectra.cc +++ b/system/camerad/cameras/spectra.cc @@ -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; } } } diff --git a/system/camerad/cameras/spectra.h b/system/camerad/cameras/spectra.h index bf35cf129e..71113d07b3 100644 --- a/system/camerad/cameras/spectra.h +++ b/system/camerad/cameras/spectra.h @@ -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;