2021-11-24 09:53:49 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
2023-08-24 04:25:17 +08:00
|
|
|
#include <vector>
|
|
|
|
|
|
2021-11-24 09:53:49 +08:00
|
|
|
#include "cereal/messaging/messaging.h"
|
|
|
|
|
#include "cereal/services.h"
|
|
|
|
|
#include "cereal/visionipc/visionipc_client.h"
|
2022-06-19 14:43:49 -07:00
|
|
|
#include "system/camerad/cameras/camera_common.h"
|
2023-07-16 01:39:40 +08:00
|
|
|
#include "system/hardware/hw.h"
|
2022-05-18 14:11:57 -07:00
|
|
|
#include "common/params.h"
|
|
|
|
|
#include "common/swaglog.h"
|
|
|
|
|
#include "common/util.h"
|
2021-11-24 09:53:49 +08:00
|
|
|
|
2023-03-08 11:20:49 -08:00
|
|
|
#include "system/loggerd/logger.h"
|
2021-11-24 09:53:49 +08:00
|
|
|
|
|
|
|
|
constexpr int MAIN_FPS = 20;
|
2023-08-11 15:34:25 -07:00
|
|
|
const int MAIN_BITRATE = 1e7;
|
|
|
|
|
const int LIVESTREAM_BITRATE = 1e6;
|
|
|
|
|
const int QCAM_BITRATE = 256000;
|
2021-11-24 09:53:49 +08:00
|
|
|
|
2023-07-16 01:39:40 +08:00
|
|
|
#define NO_CAMERA_PATIENCE 500 // fall back to time-based rotation if all cameras are dead
|
|
|
|
|
|
|
|
|
|
#define INIT_ENCODE_FUNCTIONS(encode_type) \
|
|
|
|
|
.get_encode_data_func = &cereal::Event::Reader::get##encode_type##Data, \
|
|
|
|
|
.set_encode_idx_func = &cereal::Event::Builder::set##encode_type##Idx, \
|
|
|
|
|
.init_encode_data_func = &cereal::Event::Builder::init##encode_type##Data
|
2021-11-24 09:53:49 +08:00
|
|
|
|
|
|
|
|
const bool LOGGERD_TEST = getenv("LOGGERD_TEST");
|
|
|
|
|
const int SEGMENT_LENGTH = LOGGERD_TEST ? atoi(getenv("LOGGERD_SEGMENT_LENGTH")) : 60;
|
|
|
|
|
|
2023-07-20 21:30:26 +01:00
|
|
|
constexpr char PRESERVE_ATTR_NAME[] = "user.preserve";
|
|
|
|
|
constexpr char PRESERVE_ATTR_VALUE = '1';
|
2023-06-11 22:23:40 -07:00
|
|
|
class EncoderInfo {
|
|
|
|
|
public:
|
|
|
|
|
const char *publish_name;
|
2024-05-19 08:46:34 +08:00
|
|
|
const char *thumbnail_name = NULL;
|
2023-08-11 15:34:25 -07:00
|
|
|
const char *filename = NULL;
|
2023-06-11 22:23:40 -07:00
|
|
|
bool record = true;
|
2024-02-02 12:53:12 -08:00
|
|
|
int frame_width = -1;
|
|
|
|
|
int frame_height = -1;
|
2023-06-11 22:23:40 -07:00
|
|
|
int fps = MAIN_FPS;
|
|
|
|
|
int bitrate = MAIN_BITRATE;
|
2023-07-16 01:39:40 +08:00
|
|
|
cereal::EncodeIndex::Type encode_type = Hardware::PC() ? cereal::EncodeIndex::Type::BIG_BOX_LOSSLESS
|
|
|
|
|
: cereal::EncodeIndex::Type::FULL_H_E_V_C;
|
2023-06-12 00:08:00 -07:00
|
|
|
::cereal::EncodeData::Reader (cereal::Event::Reader::*get_encode_data_func)() const;
|
|
|
|
|
void (cereal::Event::Builder::*set_encode_idx_func)(::cereal::EncodeIndex::Reader);
|
2023-07-16 01:39:40 +08:00
|
|
|
cereal::EncodeData::Builder (cereal::Event::Builder::*init_encode_data_func)();
|
2023-06-11 22:23:40 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class LogCameraInfo {
|
|
|
|
|
public:
|
2023-06-11 23:25:16 -07:00
|
|
|
const char *thread_name;
|
2023-06-11 22:23:40 -07:00
|
|
|
int fps = MAIN_FPS;
|
|
|
|
|
CameraType type;
|
2021-12-05 13:08:55 +08:00
|
|
|
VisionStreamType stream_type;
|
2023-06-11 22:23:40 -07:00
|
|
|
std::vector<EncoderInfo> encoder_infos;
|
2021-12-05 13:08:55 +08:00
|
|
|
};
|
|
|
|
|
|
2023-06-11 22:23:40 -07:00
|
|
|
const EncoderInfo main_road_encoder_info = {
|
|
|
|
|
.publish_name = "roadEncodeData",
|
|
|
|
|
.filename = "fcamera.hevc",
|
2023-07-16 01:39:40 +08:00
|
|
|
INIT_ENCODE_FUNCTIONS(RoadEncode),
|
2023-06-11 22:23:40 -07:00
|
|
|
};
|
2023-08-11 15:34:25 -07:00
|
|
|
|
2023-06-11 22:23:40 -07:00
|
|
|
const EncoderInfo main_wide_road_encoder_info = {
|
|
|
|
|
.publish_name = "wideRoadEncodeData",
|
|
|
|
|
.filename = "ecamera.hevc",
|
2023-07-16 01:39:40 +08:00
|
|
|
INIT_ENCODE_FUNCTIONS(WideRoadEncode),
|
2023-06-11 22:23:40 -07:00
|
|
|
};
|
2023-08-11 15:34:25 -07:00
|
|
|
|
2023-06-11 22:23:40 -07:00
|
|
|
const EncoderInfo main_driver_encoder_info = {
|
2023-07-17 22:55:20 +01:00
|
|
|
.publish_name = "driverEncodeData",
|
2023-06-11 22:23:40 -07:00
|
|
|
.filename = "dcamera.hevc",
|
|
|
|
|
.record = Params().getBool("RecordFront"),
|
2023-07-16 01:39:40 +08:00
|
|
|
INIT_ENCODE_FUNCTIONS(DriverEncode),
|
2021-11-24 09:53:49 +08:00
|
|
|
};
|
2023-06-11 22:23:40 -07:00
|
|
|
|
2023-08-11 15:34:25 -07:00
|
|
|
const EncoderInfo stream_road_encoder_info = {
|
|
|
|
|
.publish_name = "livestreamRoadEncodeData",
|
2024-05-19 08:46:34 +08:00
|
|
|
//.thumbnail_name = "thumbnail",
|
2023-08-11 15:34:25 -07:00
|
|
|
.encode_type = cereal::EncodeIndex::Type::QCAMERA_H264,
|
|
|
|
|
.record = false,
|
|
|
|
|
.bitrate = LIVESTREAM_BITRATE,
|
|
|
|
|
INIT_ENCODE_FUNCTIONS(LivestreamRoadEncode),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const EncoderInfo stream_wide_road_encoder_info = {
|
|
|
|
|
.publish_name = "livestreamWideRoadEncodeData",
|
|
|
|
|
.encode_type = cereal::EncodeIndex::Type::QCAMERA_H264,
|
|
|
|
|
.record = false,
|
|
|
|
|
.bitrate = LIVESTREAM_BITRATE,
|
|
|
|
|
INIT_ENCODE_FUNCTIONS(LivestreamWideRoadEncode),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const EncoderInfo stream_driver_encoder_info = {
|
|
|
|
|
.publish_name = "livestreamDriverEncodeData",
|
|
|
|
|
.encode_type = cereal::EncodeIndex::Type::QCAMERA_H264,
|
|
|
|
|
.record = false,
|
|
|
|
|
.bitrate = LIVESTREAM_BITRATE,
|
|
|
|
|
INIT_ENCODE_FUNCTIONS(LivestreamDriverEncode),
|
|
|
|
|
};
|
|
|
|
|
|
2023-06-11 22:23:40 -07:00
|
|
|
const EncoderInfo qcam_encoder_info = {
|
|
|
|
|
.publish_name = "qRoadEncodeData",
|
2021-11-24 09:53:49 +08:00
|
|
|
.filename = "qcamera.ts",
|
2023-08-11 15:34:25 -07:00
|
|
|
.bitrate = QCAM_BITRATE,
|
2023-06-11 22:23:40 -07:00
|
|
|
.encode_type = cereal::EncodeIndex::Type::QCAMERA_H264,
|
2022-06-02 15:20:51 +02:00
|
|
|
.frame_width = 526,
|
|
|
|
|
.frame_height = 330,
|
2023-07-16 01:39:40 +08:00
|
|
|
INIT_ENCODE_FUNCTIONS(QRoadEncode),
|
2021-11-24 09:53:49 +08:00
|
|
|
};
|
2023-06-11 22:23:40 -07:00
|
|
|
|
|
|
|
|
const LogCameraInfo road_camera_info{
|
2023-07-17 22:55:20 +01:00
|
|
|
.thread_name = "road_cam_encoder",
|
|
|
|
|
.type = RoadCam,
|
|
|
|
|
.stream_type = VISION_STREAM_ROAD,
|
|
|
|
|
.encoder_infos = {main_road_encoder_info, qcam_encoder_info}
|
|
|
|
|
};
|
2023-06-11 22:23:40 -07:00
|
|
|
|
|
|
|
|
const LogCameraInfo wide_road_camera_info{
|
2023-07-17 22:55:20 +01:00
|
|
|
.thread_name = "wide_road_cam_encoder",
|
|
|
|
|
.type = WideRoadCam,
|
|
|
|
|
.stream_type = VISION_STREAM_WIDE_ROAD,
|
|
|
|
|
.encoder_infos = {main_wide_road_encoder_info}
|
|
|
|
|
};
|
2023-07-16 01:39:40 +08:00
|
|
|
|
2023-06-11 22:23:40 -07:00
|
|
|
const LogCameraInfo driver_camera_info{
|
2023-07-17 22:55:20 +01:00
|
|
|
.thread_name = "driver_cam_encoder",
|
|
|
|
|
.type = DriverCam,
|
|
|
|
|
.stream_type = VISION_STREAM_DRIVER,
|
|
|
|
|
.encoder_infos = {main_driver_encoder_info}
|
|
|
|
|
};
|
2023-06-11 22:23:40 -07:00
|
|
|
|
2023-08-11 15:34:25 -07:00
|
|
|
const LogCameraInfo stream_road_camera_info{
|
|
|
|
|
.thread_name = "road_cam_encoder",
|
|
|
|
|
.type = RoadCam,
|
|
|
|
|
.stream_type = VISION_STREAM_ROAD,
|
|
|
|
|
.encoder_infos = {stream_road_encoder_info}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const LogCameraInfo stream_wide_road_camera_info{
|
|
|
|
|
.thread_name = "wide_road_cam_encoder",
|
|
|
|
|
.type = WideRoadCam,
|
|
|
|
|
.stream_type = VISION_STREAM_WIDE_ROAD,
|
|
|
|
|
.encoder_infos = {stream_wide_road_encoder_info}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const LogCameraInfo stream_driver_camera_info{
|
|
|
|
|
.thread_name = "driver_cam_encoder",
|
|
|
|
|
.type = DriverCam,
|
|
|
|
|
.stream_type = VISION_STREAM_DRIVER,
|
|
|
|
|
.encoder_infos = {stream_driver_encoder_info}
|
|
|
|
|
};
|
|
|
|
|
|
2023-06-11 22:23:40 -07:00
|
|
|
const LogCameraInfo cameras_logged[] = {road_camera_info, wide_road_camera_info, driver_camera_info};
|
2023-08-11 15:34:25 -07:00
|
|
|
const LogCameraInfo stream_cameras_logged[] = {stream_road_camera_info, stream_wide_road_camera_info, stream_driver_camera_info};
|