Skip to content

Commit

Permalink
camerad: IFE debayer support (#33720)
Browse files Browse the repository at this point in the history
* ife is up

* split out cdm, bps needs this too

* straight to vipc buffer

* start reducing the diff

* support both

* disable for now

* cleanup

---------

Co-authored-by: Comma Device <[email protected]>
  • Loading branch information
adeebshihadeh and Comma Device authored Oct 12, 2024
1 parent 6f40dec commit 8e8f61a
Show file tree
Hide file tree
Showing 11 changed files with 931 additions and 85 deletions.
2 changes: 1 addition & 1 deletion msgq_repo
Submodule msgq_repo updated 0 files
2 changes: 1 addition & 1 deletion system/camerad/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Import('env', 'arch', 'messaging', 'common', 'gpucommon', 'visionipc')
libs = ['pthread', common, 'jpeg', 'OpenCL', messaging, visionipc, gpucommon]

camera_obj = env.Object(['cameras/camera_qcom2.cc', 'cameras/camera_common.cc', 'cameras/spectra.cc',
'sensors/ar0231.cc', 'sensors/ox03c10.cc', 'sensors/os04c10.cc'])
'cameras/cdm.cc', 'sensors/ar0231.cc', 'sensors/ox03c10.cc', 'sensors/os04c10.cc'])
env.Program('camerad', ['main.cc', camera_obj], LIBS=libs)

if GetOption("extras") and arch == "x86_64":
Expand Down
27 changes: 13 additions & 14 deletions system/camerad/cameras/camera_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "common/clutil.h"
#include "common/swaglog.h"
#include "third_party/linux/include/msm_media_info.h"

#include "system/camerad/cameras/spectra.h"

Expand Down Expand Up @@ -65,16 +64,13 @@ void CameraBuf::init(cl_device_id device_id, cl_context context, SpectraCamera *

const SensorInfo *sensor = cam->sensor.get();

camera_bufs = std::make_unique<VisionBuf[]>(frame_buf_count);
is_raw = cam->is_raw;
camera_bufs_raw = std::make_unique<VisionBuf[]>(frame_buf_count);
camera_bufs_metadata = std::make_unique<FrameMetadata[]>(frame_buf_count);
frame_metadata = std::make_unique<FrameMetadata[]>(frame_buf_count);

// RAW + final frames from ISP
const int raw_frame_size = (sensor->frame_height + sensor->extra_height) * sensor->frame_stride;
for (int i = 0; i < frame_buf_count; i++) {
camera_bufs[i].allocate(cam->yuv_size);
camera_bufs[i].init_cl(device_id, context);

camera_bufs_raw[i].allocate(raw_frame_size);
camera_bufs_raw[i].init_cl(device_id, context);
}
Expand All @@ -95,7 +91,6 @@ void CameraBuf::init(cl_device_id device_id, cl_context context, SpectraCamera *

CameraBuf::~CameraBuf() {
for (int i = 0; i < frame_buf_count; i++) {
camera_bufs[i].free();
camera_bufs_raw[i].free();
}
if (imgproc) delete imgproc;
Expand All @@ -104,18 +99,22 @@ CameraBuf::~CameraBuf() {
bool CameraBuf::acquire(int expo_time) {
if (!safe_queue.try_pop(cur_buf_idx, 50)) return false;

if (camera_bufs_metadata[cur_buf_idx].frame_id == -1) {
if (frame_metadata[cur_buf_idx].frame_id == -1) {
LOGE("no frame data? wtf");
return false;
}

cur_frame_data = camera_bufs_metadata[cur_buf_idx];
cur_yuv_buf = vipc_server->get_buffer(stream_type);
cur_frame_data = frame_metadata[cur_buf_idx];
cur_camera_buf = &camera_bufs_raw[cur_buf_idx];

double start_time = millis_since_boot();
imgproc->runKernel(camera_bufs_raw[cur_buf_idx].buf_cl, cur_yuv_buf->buf_cl, out_img_width, out_img_height, expo_time);
cur_frame_data.processing_time = (millis_since_boot() - start_time) / 1000.0;
if (is_raw) {
cur_yuv_buf = vipc_server->get_buffer(stream_type);

double start_time = millis_since_boot();
imgproc->runKernel(camera_bufs_raw[cur_buf_idx].buf_cl, cur_yuv_buf->buf_cl, out_img_width, out_img_height, expo_time);
cur_frame_data.processing_time = (millis_since_boot() - start_time) / 1000.0;
} else {
cur_yuv_buf = vipc_server->get_buffer(stream_type, cur_buf_idx);
}

VisionIpcBufExtra extra = {
cur_frame_data.frame_id,
Expand Down
9 changes: 5 additions & 4 deletions system/camerad/cameras/camera_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@ class ImgProc;

class CameraBuf {
private:
VisionIpcServer *vipc_server;
ImgProc *imgproc = nullptr;
VisionStreamType stream_type;
int cur_buf_idx;
SafeQueue<int> safe_queue;
int frame_buf_count;
bool is_raw;

public:
VisionIpcServer *vipc_server;
VisionStreamType stream_type;

FrameMetadata cur_frame_data;
VisionBuf *cur_yuv_buf;
VisionBuf *cur_camera_buf;
std::unique_ptr<VisionBuf[]> camera_bufs;
std::unique_ptr<VisionBuf[]> camera_bufs_raw;
std::unique_ptr<FrameMetadata[]> camera_bufs_metadata;
std::unique_ptr<FrameMetadata[]> frame_metadata;
int out_img_width, out_img_height;

CameraBuf() = default;
Expand Down
4 changes: 2 additions & 2 deletions system/camerad/cameras/camera_qcom2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CameraState {

float fl_pix = 0;

CameraState(SpectraMaster *master, const CameraConfig &config) : camera(master, config) {};
CameraState(SpectraMaster *master, const CameraConfig &config) : camera(master, config, true /*config.camera_num == 2*/) {};
~CameraState();
void init(VisionIpcServer *v, cl_device_id device_id, cl_context ctx);
void update_exposure_score(float desired_ev, int exp_t, int exp_g_idx, float exp_gain);
Expand Down Expand Up @@ -285,7 +285,7 @@ void camerad_thread() {
std::vector<std::unique_ptr<CameraState>> cams;
for (const auto &config : {ROAD_CAMERA_CONFIG, WIDE_ROAD_CAMERA_CONFIG, DRIVER_CAMERA_CONFIG}) {
auto cam = std::make_unique<CameraState>(&m, config);
cam->init(&v, device_id ,ctx);
cam->init(&v, device_id, ctx);
cams.emplace_back(std::move(cam));
}

Expand Down
33 changes: 33 additions & 0 deletions system/camerad/cameras/cdm.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "cdm.h"

int write_cont(uint8_t *dst, uint32_t reg, std::vector<uint32_t> vals) {
struct cdm_regcontinuous_cmd *cmd = (struct cdm_regcontinuous_cmd*)dst;
cmd->cmd = CAM_CDM_CMD_REG_CONT;
cmd->count = vals.size();
cmd->offset = reg;
cmd->reserved0 = 0;
cmd->reserved1 = 0;

uint32_t *vd = (uint32_t*)(dst + sizeof(struct cdm_regcontinuous_cmd));
for (int i = 0; i < vals.size(); i++) {
*vd = vals[i];
vd++;
}

return sizeof(struct cdm_regcontinuous_cmd) + vals.size()*sizeof(uint32_t);
}

int write_random(uint8_t *dst, std::vector<uint32_t> vals) {
struct cdm_regrandom_cmd *cmd = (struct cdm_regrandom_cmd*)dst;
cmd->cmd = CAM_CDM_CMD_REG_RANDOM;
cmd->count = vals.size() / 2;
cmd->reserved = 0;

uint32_t *vd = (uint32_t*)(dst + sizeof(struct cdm_regrandom_cmd));
for (int i = 0; i < vals.size(); i++) {
*vd = vals[i];
vd++;
}

return sizeof(struct cdm_regrandom_cmd) + vals.size()*sizeof(uint32_t);
}
12 changes: 12 additions & 0 deletions system/camerad/cameras/cdm.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#pragma once

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <memory>

// our helpers
int write_random(uint8_t *dst, std::vector<uint32_t> vals);
int write_cont(uint8_t *dst, uint32_t reg, std::vector<uint32_t> vals);

// from drivers/media/platform/msm/camera/cam_cdm/cam_cdm_util.{c,h}

enum cam_cdm_command {
Expand Down
Loading

0 comments on commit 8e8f61a

Please sign in to comment.