|
|
|
@ -47,7 +47,6 @@ |
|
|
|
|
|
|
|
|
|
#ifndef DISABLE_ENCODER |
|
|
|
|
#include "encoder.h" |
|
|
|
|
#include "raw_logger.h" |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#define MAIN_BITRATE 5000000 |
|
|
|
@ -111,8 +110,6 @@ LogCameraInfo cameras_logged[LOG_CAMERA_ID_MAX] = { |
|
|
|
|
|
|
|
|
|
#define LOG_ROOT "/data/media/0/realdata" |
|
|
|
|
|
|
|
|
|
#define RAW_CLIP_LENGTH 100 // 5 seconds at 20fps
|
|
|
|
|
#define RAW_CLIP_FREQUENCY (randrange(61, 8*60)) // once every ~4 minutes
|
|
|
|
|
|
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
@ -202,7 +199,7 @@ struct LoggerdState { |
|
|
|
|
LoggerdState s; |
|
|
|
|
|
|
|
|
|
#ifndef DISABLE_ENCODER |
|
|
|
|
void encoder_thread(RotateState *rotate_state, bool raw_clips, int cam_idx) { |
|
|
|
|
void encoder_thread(RotateState *rotate_state, int cam_idx) { |
|
|
|
|
|
|
|
|
|
switch (cam_idx) { |
|
|
|
|
case LOG_CAMERA_ID_DCAMERA: { |
|
|
|
@ -272,15 +269,6 @@ void encoder_thread(RotateState *rotate_state, bool raw_clips, int cam_idx) { |
|
|
|
|
encoder_inited = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// dont log a raw clip in the first minute
|
|
|
|
|
double rawlogger_start_time = seconds_since_boot()+RAW_CLIP_FREQUENCY; |
|
|
|
|
int rawlogger_clip_cnt = 0; |
|
|
|
|
RawLogger *rawlogger = NULL; |
|
|
|
|
|
|
|
|
|
if (raw_clips) { |
|
|
|
|
rawlogger = new RawLogger("prcamera", buf_info.width, buf_info.height, MAIN_FPS); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
while (!do_exit) { |
|
|
|
|
VIPCBufExtra extra; |
|
|
|
|
VIPCBuf* buf = visionstream_get(&stream, &extra); |
|
|
|
@ -317,9 +305,6 @@ void encoder_thread(RotateState *rotate_state, bool raw_clips, int cam_idx) { |
|
|
|
|
if (has_encoder_alt) { |
|
|
|
|
encoder_rotate(&encoder_alt, s.segment_path, s.rotate_segment); |
|
|
|
|
} |
|
|
|
|
if (raw_clips) { |
|
|
|
|
rawlogger->Rotate(s.segment_path, s.rotate_segment); |
|
|
|
|
} |
|
|
|
|
encoder_segment = s.rotate_segment; |
|
|
|
|
if (lh) { |
|
|
|
|
lh_close(lh); |
|
|
|
@ -399,44 +384,6 @@ void encoder_thread(RotateState *rotate_state, bool raw_clips, int cam_idx) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (raw_clips) { |
|
|
|
|
double ts = seconds_since_boot(); |
|
|
|
|
if (ts > rawlogger_start_time) { |
|
|
|
|
// encode raw if in clip
|
|
|
|
|
int out_segment = -1; |
|
|
|
|
int out_id = rawlogger->LogFrame(cnt, y, u, v, &out_segment); |
|
|
|
|
|
|
|
|
|
if (rawlogger_clip_cnt == 0) { |
|
|
|
|
LOG("starting raw clip in seg %d", out_segment); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// publish encode index
|
|
|
|
|
MessageBuilder msg; |
|
|
|
|
auto eidx = msg.initEvent().initEncodeIdx(); |
|
|
|
|
eidx.setFrameId(extra.frame_id); |
|
|
|
|
eidx.setType(cereal::EncodeIndex::Type::FULL_LOSSLESS_CLIP); |
|
|
|
|
eidx.setEncodeId(cnt); |
|
|
|
|
eidx.setSegmentNum(out_segment); |
|
|
|
|
eidx.setSegmentId(out_id); |
|
|
|
|
|
|
|
|
|
auto bytes = msg.toBytes(); |
|
|
|
|
if (lh) { |
|
|
|
|
lh_log(lh, bytes.begin(), bytes.size(), false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// close rawlogger if clip ended
|
|
|
|
|
rawlogger_clip_cnt++; |
|
|
|
|
if (rawlogger_clip_cnt >= RAW_CLIP_LENGTH) { |
|
|
|
|
rawlogger->Close(); |
|
|
|
|
|
|
|
|
|
rawlogger_clip_cnt = 0; |
|
|
|
|
rawlogger_start_time = ts+RAW_CLIP_FREQUENCY; |
|
|
|
|
|
|
|
|
|
LOG("ending raw clip in seg %d, next in %.1f sec", out_segment, rawlogger_start_time-ts); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cnt++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -445,11 +392,6 @@ void encoder_thread(RotateState *rotate_state, bool raw_clips, int cam_idx) { |
|
|
|
|
lh = NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (raw_clips) { |
|
|
|
|
rawlogger->Close(); |
|
|
|
|
delete rawlogger; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
visionstream_destroy(&stream); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -675,17 +617,17 @@ int main(int argc, char** argv) { |
|
|
|
|
pthread_mutex_init(&s.rotate_lock, NULL); |
|
|
|
|
#ifndef DISABLE_ENCODER |
|
|
|
|
// rear camera
|
|
|
|
|
std::thread encoder_thread_handle(encoder_thread, &s.rotate_state[LOG_CAMERA_ID_FCAMERA], false, LOG_CAMERA_ID_FCAMERA); |
|
|
|
|
std::thread encoder_thread_handle(encoder_thread, &s.rotate_state[LOG_CAMERA_ID_FCAMERA], LOG_CAMERA_ID_FCAMERA); |
|
|
|
|
s.rotate_state[LOG_CAMERA_ID_FCAMERA].enabled = true; |
|
|
|
|
// front camera
|
|
|
|
|
std::thread front_encoder_thread_handle; |
|
|
|
|
if (record_front) { |
|
|
|
|
front_encoder_thread_handle = std::thread(encoder_thread, &s.rotate_state[LOG_CAMERA_ID_DCAMERA], false, LOG_CAMERA_ID_DCAMERA); |
|
|
|
|
front_encoder_thread_handle = std::thread(encoder_thread, &s.rotate_state[LOG_CAMERA_ID_DCAMERA], LOG_CAMERA_ID_DCAMERA); |
|
|
|
|
s.rotate_state[LOG_CAMERA_ID_DCAMERA].enabled = true; |
|
|
|
|
} |
|
|
|
|
#ifdef QCOM2 |
|
|
|
|
// wide camera
|
|
|
|
|
std::thread wide_encoder_thread_handle(encoder_thread, &s.rotate_state[LOG_CAMERA_ID_ECAMERA], false, LOG_CAMERA_ID_ECAMERA); |
|
|
|
|
std::thread wide_encoder_thread_handle(encoder_thread, &s.rotate_state[LOG_CAMERA_ID_ECAMERA], LOG_CAMERA_ID_ECAMERA); |
|
|
|
|
s.rotate_state[LOG_CAMERA_ID_ECAMERA].enabled = true; |
|
|
|
|
#endif |
|
|
|
|
#endif |
|
|
|
|