Skip to content

Commit

Permalink
streams junk frames
Browse files Browse the repository at this point in the history
  • Loading branch information
Comma Device committed Oct 8, 2024
1 parent 939d306 commit cd62772
Show file tree
Hide file tree
Showing 10 changed files with 1,061 additions and 67 deletions.
2 changes: 2 additions & 0 deletions system/camerad/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ camera_obj = env.Object(['cameras/camera_qcom2.cc', 'cameras/camera_common.cc',
'sensors/ar0231.cc', 'sensors/ox03c10.cc', 'sensors/os04c10.cc'])
env.Program('camerad', ['main.cc', camera_obj], LIBS=libs)

#env.Program('ife', ['cameras/ife.cc', ], LIBS=libs)

if GetOption("extras") and arch == "x86_64":
env.Program('test/test_ae_gray', ['test/test_ae_gray.cc', camera_obj], LIBS=libs)
23 changes: 8 additions & 15 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,34 +64,27 @@ void CameraBuf::init(cl_device_id device_id, cl_context context, SpectraCamera *

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

// RAW frame
const int frame_size = (sensor->frame_height + sensor->extra_height) * sensor->frame_stride;
// camera frame
camera_bufs = std::make_unique<VisionBuf[]>(frame_buf_count);
camera_bufs_metadata = std::make_unique<FrameMetadata[]>(frame_buf_count);

for (int i = 0; i < frame_buf_count; i++) {
camera_bufs[i].allocate(frame_size);
camera_bufs[i].allocate(cam->yuv_size);
camera_bufs[i].init_cl(device_id, context);
}
LOGD("allocated %d CL buffers", frame_buf_count);

out_img_width = sensor->frame_width;
out_img_height = sensor->hdr_offset > 0 ? (sensor->frame_height - sensor->hdr_offset) / 2 : sensor->frame_height;

int nv12_width = VENUS_Y_STRIDE(COLOR_FMT_NV12, out_img_width);
int nv12_height = VENUS_Y_SCANLINES(COLOR_FMT_NV12, out_img_height);
assert(nv12_width == VENUS_UV_STRIDE(COLOR_FMT_NV12, out_img_width));
assert(nv12_height/2 == VENUS_UV_SCANLINES(COLOR_FMT_NV12, out_img_height));
size_t nv12_uv_offset = nv12_width * nv12_height;

// the encoder HW tells us the size it wants after setting it up.
// TODO: VENUS_BUFFER_SIZE should give the size, but it's too small. dependent on encoder settings?
size_t nv12_size = (out_img_width <= 1344 ? 2900 : 2346)*nv12_width;
size_t nv12_size = (out_img_width <= 1344 ? 2900 : 2346)*cam->stride;

vipc_server->create_buffers_with_sizes(stream_type, YUV_BUFFER_COUNT, out_img_width, out_img_height, nv12_size, nv12_width, nv12_uv_offset);
LOGD("created %d YUV vipc buffers with size %dx%d", YUV_BUFFER_COUNT, nv12_width, nv12_height);
vipc_server->create_buffers_with_sizes(stream_type, YUV_BUFFER_COUNT, out_img_width, out_img_height, nv12_size, cam->stride, cam->uv_offset);
LOGD("created %d YUV vipc buffers with size %dx%d", YUV_BUFFER_COUNT, cam->stride, cam->y_height);

imgproc = new ImgProc(device_id, context, this, sensor, cam->cc.camera_num, nv12_width, nv12_uv_offset);
imgproc = new ImgProc(device_id, context, this, sensor, cam->cc.camera_num, cam->stride, cam->uv_offset);
}

CameraBuf::~CameraBuf() {
Expand All @@ -115,7 +107,8 @@ bool CameraBuf::acquire(int expo_time) {
cur_camera_buf = &camera_bufs[cur_buf_idx];

double start_time = millis_since_boot();
imgproc->runKernel(camera_bufs[cur_buf_idx].buf_cl, cur_yuv_buf->buf_cl, out_img_width, out_img_height, expo_time);
//imgproc->runKernel(camera_bufs[cur_buf_idx].buf_cl, cur_yuv_buf->buf_cl, out_img_width, out_img_height, expo_time);
memcpy(cur_yuv_buf->addr, cur_camera_buf->addr, cur_camera_buf->len);
cur_frame_data.processing_time = (millis_since_boot() - start_time) / 1000.0;

VisionIpcBufExtra extra = {
Expand Down
3 changes: 0 additions & 3 deletions system/camerad/cameras/camera_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ const int YUV_BUFFER_COUNT = 20;
typedef struct FrameMetadata {
uint32_t frame_id;
uint32_t request_id;

// Timestamps
uint64_t timestamp_sof;
uint64_t timestamp_eof;

float processing_time;
} FrameMetadata;

Expand Down
10 changes: 5 additions & 5 deletions system/camerad/cameras/camera_qcom2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class CameraState {
};

void CameraState::init(VisionIpcServer *v, cl_device_id device_id, cl_context ctx) {
if (!camera.enabled) return;

camera.camera_open(v, device_id, ctx);

fl_pix = camera.cc.focal_len / camera.sensor->pixel_size_mm;
Expand All @@ -73,7 +75,7 @@ void CameraState::init(VisionIpcServer *v, cl_device_id device_id, cl_context ct
gain_idx = camera.sensor->analog_gain_rec_idx;
cur_ev[0] = cur_ev[1] = cur_ev[2] = get_gain_factor() * camera.sensor->sensor_analog_gains[gain_idx] * exposure_time;

if (camera.enabled) thread = std::thread(&CameraState::run, this);
thread = std::thread(&CameraState::run, this);
}

CameraState::~CameraState() {
Expand Down Expand Up @@ -250,9 +252,7 @@ void CameraState::run() {
framed.setSensor(camera.sensor->image_sensor);

// Log raw frames for road camera
if (env_log_raw_frames && camera.cc.stream_type == VISION_STREAM_ROAD && cnt % 100 == 5) { // no overlap with qlog decimation
framed.setImage(get_raw_frame_image(&camera.buf));
}
framed.setImage(get_raw_frame_image(&camera.buf));

// Process camera registers and set camera exposure
camera.sensor->processRegisters((uint8_t *)camera.buf.cur_camera_buf->addr, framed);
Expand Down Expand Up @@ -318,7 +318,7 @@ void camerad_thread() {
}

for (auto &cam : cams) {
if (event_data->session_hdl == cam->camera.session_handle) {
if (cam->camera.enabled && event_data->session_hdl == cam->camera.session_handle) {
cam->camera.handle_camera_event(event_data);
break;
}
Expand Down
66 changes: 66 additions & 0 deletions system/camerad/cameras/cdm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// from drivers/media/platform/msm/camera/cam_cdm/cam_cdm_util.{c,h}

enum cam_cdm_command {
CAM_CDM_CMD_UNUSED = 0x0,
CAM_CDM_CMD_DMI = 0x1,
CAM_CDM_CMD_NOT_DEFINED = 0x2,
CAM_CDM_CMD_REG_CONT = 0x3,
CAM_CDM_CMD_REG_RANDOM = 0x4,
CAM_CDM_CMD_BUFF_INDIRECT = 0x5,
CAM_CDM_CMD_GEN_IRQ = 0x6,
CAM_CDM_CMD_WAIT_EVENT = 0x7,
CAM_CDM_CMD_CHANGE_BASE = 0x8,
CAM_CDM_CMD_PERF_CTRL = 0x9,
CAM_CDM_CMD_DMI_32 = 0xa,
CAM_CDM_CMD_DMI_64 = 0xb,
CAM_CDM_CMD_PRIVATE_BASE = 0xc,
CAM_CDM_CMD_SWD_DMI_32 = (CAM_CDM_CMD_PRIVATE_BASE + 0x64),
CAM_CDM_CMD_SWD_DMI_64 = (CAM_CDM_CMD_PRIVATE_BASE + 0x65),
CAM_CDM_CMD_PRIVATE_BASE_MAX = 0x7F
};

/**
* struct cdm_regrandom_cmd - Definition for CDM random register command.
* @count: Number of register writes
* @reserved: reserved bits
* @cmd: Command ID (CDMCmd)
*/
struct cdm_regrandom_cmd {
unsigned int count : 16;
unsigned int reserved : 8;
unsigned int cmd : 8;
} __attribute__((__packed__));

/**
* struct cdm_regcontinuous_cmd - Definition for a CDM register range command.
* @count: Number of register writes
* @reserved0: reserved bits
* @cmd: Command ID (CDMCmd)
* @offset: Start address of the range of registers
* @reserved1: reserved bits
*/
struct cdm_regcontinuous_cmd {
unsigned int count : 16;
unsigned int reserved0 : 8;
unsigned int cmd : 8;
unsigned int offset : 24;
unsigned int reserved1 : 8;
} __attribute__((__packed__));

/**
* struct cdm_dmi_cmd - Definition for a CDM DMI command.
* @length: Number of bytes in LUT - 1
* @reserved: reserved bits
* @cmd: Command ID (CDMCmd)
* @addr: Address of the LUT in memory
* @DMIAddr: Address of the target DMI config register
* @DMISel: DMI identifier
*/
struct cdm_dmi_cmd {
unsigned int length : 16;
unsigned int reserved : 8;
unsigned int cmd : 8;
unsigned int addr;
unsigned int DMIAddr : 24;
unsigned int DMISel : 8;
} __attribute__((__packed__));
Loading

0 comments on commit cd62772

Please sign in to comment.