camerad: prep part 2 (#33584)

* no camerastate in sensors

* bring this over

* and encoder
pull/33583/head
Adeeb Shihadeh 7 months ago committed by GitHub
parent 5378e63812
commit 718835a825
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      system/camerad/cameras/camera_qcom2.cc
  2. 13
      system/camerad/sensors/ar0231.cc
  3. 4
      system/camerad/sensors/sensor.h
  4. 6
      system/loggerd/encoder/encoder.h

@ -953,7 +953,7 @@ void CameraState::run() {
} }
// Process camera registers and set camera exposure // Process camera registers and set camera exposure
sensor->processRegisters(this, framed); sensor->processRegisters((uint8_t *)buf.cur_camera_buf->addr, framed);
set_camera_exposure(set_exposure_target(&buf, ae_xywh, 2, cc.stream_type != VISION_STREAM_DRIVER ? 2 : 4)); set_camera_exposure(set_exposure_target(&buf, ae_xywh, 2, cc.stream_type != VISION_STREAM_DRIVER ? 2 : 4));
// Send the message // Send the message

@ -2,7 +2,6 @@
#include "common/swaglog.h" #include "common/swaglog.h"
#include "system/camerad/cameras/camera_common.h" #include "system/camerad/cameras/camera_common.h"
#include "system/camerad/cameras/camera_qcom2.h"
#include "system/camerad/sensors/sensor.h" #include "system/camerad/sensors/sensor.h"
namespace { namespace {
@ -17,7 +16,7 @@ const float sensor_analog_gains_AR0231[] = {
5.0 / 4.0, 6.0 / 4.0, 6.0 / 3.0, 7.0 / 3.0, // 8, 9, 10, 11 5.0 / 4.0, 6.0 / 4.0, 6.0 / 3.0, 7.0 / 3.0, // 8, 9, 10, 11
7.0 / 2.0, 8.0 / 2.0, 8.0 / 1.0}; // 12, 13, 14, 15 = bypass 7.0 / 2.0, 8.0 / 2.0, 8.0 / 1.0}; // 12, 13, 14, 15 = bypass
std::map<uint16_t, std::pair<int, int>> ar0231_build_register_lut(CameraState *c, uint8_t *data) { std::map<uint16_t, std::pair<int, int>> ar0231_build_register_lut(const AR0231 *s, uint8_t *data) {
// This function builds a lookup table from register address, to a pair of indices in the // This function builds a lookup table from register address, to a pair of indices in the
// buffer where to read this address. The buffer contains padding bytes, // buffer where to read this address. The buffer contains padding bytes,
// as well as markers to indicate the type of the next byte. // as well as markers to indicate the type of the next byte.
@ -33,7 +32,7 @@ std::map<uint16_t, std::pair<int, int>> ar0231_build_register_lut(CameraState *c
std::map<uint16_t, std::pair<int, int>> registers; std::map<uint16_t, std::pair<int, int>> registers;
for (int register_row = 0; register_row < 2; register_row++) { for (int register_row = 0; register_row < 2; register_row++) {
uint8_t *registers_raw = data + c->sensor->frame_stride * register_row; uint8_t *registers_raw = data + s->frame_stride * register_row;
assert(registers_raw[0] == 0x0a); // Start of line assert(registers_raw[0] == 0x0a); // Start of line
int value_tag_count = 0; int value_tag_count = 0;
@ -58,7 +57,7 @@ std::map<uint16_t, std::pair<int, int>> ar0231_build_register_lut(CameraState *c
cur_addr += 2; cur_addr += 2;
first_val_idx = val_idx; first_val_idx = val_idx;
} else { } else {
registers[cur_addr] = std::make_pair(first_val_idx + c->sensor->frame_stride * register_row, val_idx + c->sensor->frame_stride * register_row); registers[cur_addr] = std::make_pair(first_val_idx + s->frame_stride * register_row, val_idx + s->frame_stride * register_row);
} }
value_tag_count++; value_tag_count++;
@ -119,9 +118,9 @@ AR0231::AR0231() {
target_grey_factor = 1.0; target_grey_factor = 1.0;
} }
void AR0231::processRegisters(CameraState *c, cereal::FrameData::Builder &framed) const { void AR0231::processRegisters(uint8_t *cur_buf, cereal::FrameData::Builder &framed) const {
const uint8_t expected_preamble[] = {0x0a, 0xaa, 0x55, 0x20, 0xa5, 0x55}; const uint8_t expected_preamble[] = {0x0a, 0xaa, 0x55, 0x20, 0xa5, 0x55};
uint8_t *data = (uint8_t *)c->buf.cur_camera_buf->addr + c->sensor->registers_offset; uint8_t *data = cur_buf + registers_offset;
if (memcmp(data, expected_preamble, std::size(expected_preamble)) != 0) { if (memcmp(data, expected_preamble, std::size(expected_preamble)) != 0) {
LOGE("unexpected register data found"); LOGE("unexpected register data found");
@ -129,7 +128,7 @@ void AR0231::processRegisters(CameraState *c, cereal::FrameData::Builder &framed
} }
if (ar0231_register_lut.empty()) { if (ar0231_register_lut.empty()) {
ar0231_register_lut = ar0231_build_register_lut(c, data); ar0231_register_lut = ar0231_build_register_lut(this, data);
} }
std::map<uint16_t, uint16_t> registers; std::map<uint16_t, uint16_t> registers;
for (uint16_t addr : {0x2000, 0x2002, 0x20b0, 0x20b2, 0x30c6, 0x30c8, 0x30ca, 0x30cc}) { for (uint16_t addr : {0x2000, 0x2002, 0x20b0, 0x20b2, 0x30c6, 0x30c8, 0x30ca, 0x30cc}) {

@ -19,7 +19,7 @@ public:
virtual std::vector<i2c_random_wr_payload> getExposureRegisters(int exposure_time, int new_exp_g, bool dc_gain_enabled) const { return {}; } virtual std::vector<i2c_random_wr_payload> getExposureRegisters(int exposure_time, int new_exp_g, bool dc_gain_enabled) const { return {}; }
virtual float getExposureScore(float desired_ev, int exp_t, int exp_g_idx, float exp_gain, int gain_idx) const {return 0; } virtual float getExposureScore(float desired_ev, int exp_t, int exp_g_idx, float exp_gain, int gain_idx) const {return 0; }
virtual int getSlaveAddress(int port) const { assert(0); } virtual int getSlaveAddress(int port) const { assert(0); }
virtual void processRegisters(CameraState *c, cereal::FrameData::Builder &framed) const {} virtual void processRegisters(uint8_t *cur_buf, cereal::FrameData::Builder &framed) const {}
cereal::FrameData::ImageSensor image_sensor = cereal::FrameData::ImageSensor::UNKNOWN; cereal::FrameData::ImageSensor image_sensor = cereal::FrameData::ImageSensor::UNKNOWN;
float pixel_size_mm; float pixel_size_mm;
@ -68,7 +68,7 @@ public:
std::vector<i2c_random_wr_payload> getExposureRegisters(int exposure_time, int new_exp_g, bool dc_gain_enabled) const override; std::vector<i2c_random_wr_payload> getExposureRegisters(int exposure_time, int new_exp_g, bool dc_gain_enabled) const override;
float getExposureScore(float desired_ev, int exp_t, int exp_g_idx, float exp_gain, int gain_idx) const override; float getExposureScore(float desired_ev, int exp_t, int exp_g_idx, float exp_gain, int gain_idx) const override;
int getSlaveAddress(int port) const override; int getSlaveAddress(int port) const override;
void processRegisters(CameraState *c, cereal::FrameData::Builder &framed) const override; void processRegisters(uint8_t *cur_buf, cereal::FrameData::Builder &framed) const override;
private: private:
mutable std::map<uint16_t, std::pair<int, int>> ar0231_register_lut; mutable std::map<uint16_t, std::pair<int, int>> ar0231_register_lut;

@ -1,5 +1,9 @@
#pragma once #pragma once
// has to be in this order
#include "third_party/linux/include/v4l2-controls.h"
#include <linux/videodev2.h>
#include <cassert> #include <cassert>
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
@ -12,8 +16,6 @@
#include "system/camerad/cameras/camera_common.h" #include "system/camerad/cameras/camera_common.h"
#include "system/loggerd/loggerd.h" #include "system/loggerd/loggerd.h"
#define V4L2_BUF_FLAG_KEYFRAME 8
class VideoEncoder { class VideoEncoder {
public: public:
VideoEncoder(const EncoderInfo &encoder_info, int in_width, int in_height); VideoEncoder(const EncoderInfo &encoder_info, int in_width, int in_height);

Loading…
Cancel
Save