|
|
@ -90,20 +90,23 @@ struct LoggerdState { |
|
|
|
LoggerdState s; |
|
|
|
LoggerdState s; |
|
|
|
|
|
|
|
|
|
|
|
#ifndef DISABLE_ENCODER |
|
|
|
#ifndef DISABLE_ENCODER |
|
|
|
void encoder_thread(bool is_streaming, bool raw_clips, bool front) { |
|
|
|
void encoder_thread(bool is_streaming, bool raw_clips, int cam_idx) { |
|
|
|
int err; |
|
|
|
int err; |
|
|
|
|
|
|
|
|
|
|
|
if (front) { |
|
|
|
if (cam_idx == 2) { |
|
|
|
char *value; |
|
|
|
// TODO: add this back
|
|
|
|
|
|
|
|
/*char *value;
|
|
|
|
const int result = read_db_value("RecordFront", &value, NULL); |
|
|
|
const int result = read_db_value("RecordFront", &value, NULL); |
|
|
|
if (result != 0) return; |
|
|
|
if (result != 0) return; |
|
|
|
if (value[0] != '1') { free(value); return; } |
|
|
|
if (value[0] != '1') { free(value); return; } |
|
|
|
free(value); |
|
|
|
free(value); |
|
|
|
LOGW("recording front camera"); |
|
|
|
LOGW("recording front camera");*/ |
|
|
|
|
|
|
|
|
|
|
|
set_thread_name("FrontCameraEncoder"); |
|
|
|
set_thread_name("FrontCameraEncoder"); |
|
|
|
} else { |
|
|
|
} else if (cam_idx == 0) { |
|
|
|
set_thread_name("RearCameraEncoder"); |
|
|
|
set_thread_name("RearCameraEncoder"); |
|
|
|
|
|
|
|
} else if (cam_idx == 1) { |
|
|
|
|
|
|
|
set_thread_name("WideCameraEncoder"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
VisionStream stream; |
|
|
|
VisionStream stream; |
|
|
@ -116,17 +119,20 @@ void encoder_thread(bool is_streaming, bool raw_clips, bool front) { |
|
|
|
int encoder_segment = -1; |
|
|
|
int encoder_segment = -1; |
|
|
|
int cnt = 0; |
|
|
|
int cnt = 0; |
|
|
|
|
|
|
|
|
|
|
|
PubSocket *idx_sock = PubSocket::create(s.ctx, front ? "frontEncodeIdx" : "encodeIdx"); |
|
|
|
// TODO: add this back
|
|
|
|
assert(idx_sock != NULL); |
|
|
|
// PubSocket *idx_sock = PubSocket::create(s.ctx, front ? "frontEncodeIdx" : "encodeIdx");
|
|
|
|
|
|
|
|
// assert(idx_sock != NULL);
|
|
|
|
|
|
|
|
|
|
|
|
LoggerHandle *lh = NULL; |
|
|
|
LoggerHandle *lh = NULL; |
|
|
|
|
|
|
|
|
|
|
|
while (!do_exit) { |
|
|
|
while (!do_exit) { |
|
|
|
VisionStreamBufs buf_info; |
|
|
|
VisionStreamBufs buf_info; |
|
|
|
if (front) { |
|
|
|
if (cam_idx == 2) { |
|
|
|
err = visionstream_init(&stream, VISION_STREAM_YUV_FRONT, false, &buf_info); |
|
|
|
err = visionstream_init(&stream, VISION_STREAM_YUV_FRONT, false, &buf_info); |
|
|
|
} else { |
|
|
|
} else if (cam_idx == 0) { |
|
|
|
err = visionstream_init(&stream, VISION_STREAM_YUV, false, &buf_info); |
|
|
|
err = visionstream_init(&stream, VISION_STREAM_YUV, false, &buf_info); |
|
|
|
|
|
|
|
} else if (cam_idx == 1) { |
|
|
|
|
|
|
|
err = visionstream_init(&stream, VISION_STREAM_YUV_WIDE, false, &buf_info); |
|
|
|
} |
|
|
|
} |
|
|
|
if (err != 0) { |
|
|
|
if (err != 0) { |
|
|
|
LOGD("visionstream connect fail"); |
|
|
|
LOGD("visionstream connect fail"); |
|
|
@ -136,11 +142,11 @@ void encoder_thread(bool is_streaming, bool raw_clips, bool front) { |
|
|
|
|
|
|
|
|
|
|
|
if (!encoder_inited) { |
|
|
|
if (!encoder_inited) { |
|
|
|
LOGD("encoder init %dx%d", buf_info.width, buf_info.height); |
|
|
|
LOGD("encoder init %dx%d", buf_info.width, buf_info.height); |
|
|
|
encoder_init(&encoder, front ? "dcamera.hevc" : "fcamera.hevc", buf_info.width, buf_info.height, CAMERA_FPS, front ? 2500000 : 5000000, true, false); |
|
|
|
encoder_init(&encoder, cam_idx == 2 ? "dcamera.hevc" : (cam_idx == 1 ? "ecamera.hevc" : "fcamera.hevc"), buf_info.width, buf_info.height, CAMERA_FPS, cam_idx > 0 ? 2500000 : 5000000, true, false); |
|
|
|
|
|
|
|
|
|
|
|
#ifndef QCOM2 |
|
|
|
#ifndef QCOM2 |
|
|
|
// TODO: fix qcamera on tici
|
|
|
|
// TODO: fix qcamera on tici
|
|
|
|
if (!front) { |
|
|
|
if (cam_idx == 0) { |
|
|
|
encoder_init(&encoder_alt, "qcamera.ts", 480, 360, CAMERA_FPS, 128000, false, true); |
|
|
|
encoder_init(&encoder_alt, "qcamera.ts", 480, 360, CAMERA_FPS, 128000, false, true); |
|
|
|
has_encoder_alt = true; |
|
|
|
has_encoder_alt = true; |
|
|
|
} |
|
|
|
} |
|
|
@ -184,7 +190,7 @@ void encoder_thread(bool is_streaming, bool raw_clips, bool front) { |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool should_rotate = false; |
|
|
|
bool should_rotate = false; |
|
|
|
std::unique_lock<std::mutex> lk(s.lock); |
|
|
|
std::unique_lock<std::mutex> lk(s.lock); |
|
|
|
if (!front) { |
|
|
|
if (cam_idx==0) { |
|
|
|
// wait if log camera is older on back camera
|
|
|
|
// wait if log camera is older on back camera
|
|
|
|
while ( extra.frame_id > s.last_frame_id //if the log camera is older, wait for it to catch up.
|
|
|
|
while ( extra.frame_id > s.last_frame_id //if the log camera is older, wait for it to catch up.
|
|
|
|
&& (extra.frame_id-s.last_frame_id) < 8 // but if its too old then there probably was a discontinuity (visiond restarted)
|
|
|
|
&& (extra.frame_id-s.last_frame_id) < 8 // but if its too old then there probably was a discontinuity (visiond restarted)
|
|
|
@ -235,25 +241,27 @@ void encoder_thread(bool is_streaming, bool raw_clips, bool front) { |
|
|
|
&out_segment_alt, &extra); |
|
|
|
&out_segment_alt, &extra); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: add this back
|
|
|
|
// publish encode index
|
|
|
|
// publish encode index
|
|
|
|
capnp::MallocMessageBuilder msg; |
|
|
|
//capnp::MallocMessageBuilder msg;
|
|
|
|
cereal::Event::Builder event = msg.initRoot<cereal::Event>(); |
|
|
|
//cereal::Event::Builder event = msg.initRoot<cereal::Event>();
|
|
|
|
event.setLogMonoTime(nanos_since_boot()); |
|
|
|
//event.setLogMonoTime(nanos_since_boot());
|
|
|
|
auto eidx = event.initEncodeIdx(); |
|
|
|
//auto eidx = event.initEncodeIdx();
|
|
|
|
eidx.setFrameId(extra.frame_id); |
|
|
|
//eidx.setFrameId(extra.frame_id);
|
|
|
|
eidx.setType(front ? cereal::EncodeIndex::Type::FRONT : cereal::EncodeIndex::Type::FULL_H_E_V_C); |
|
|
|
//eidx.setType(front ? cereal::EncodeIndex::Type::FRONT : cereal::EncodeIndex::Type::FULL_H_E_V_C);
|
|
|
|
eidx.setEncodeId(cnt); |
|
|
|
//eidx.setEncodeId(cnt);
|
|
|
|
eidx.setSegmentNum(out_segment); |
|
|
|
//eidx.setSegmentNum(out_segment);
|
|
|
|
eidx.setSegmentId(out_id); |
|
|
|
//eidx.setSegmentId(out_id);
|
|
|
|
|
|
|
|
|
|
|
|
auto words = capnp::messageToFlatArray(msg); |
|
|
|
//auto words = capnp::messageToFlatArray(msg);
|
|
|
|
auto bytes = words.asBytes(); |
|
|
|
//auto bytes = words.asBytes();
|
|
|
|
if (idx_sock->send((char*)bytes.begin(), bytes.size()) < 0) { |
|
|
|
|
|
|
|
printf("err sending encodeIdx pkt: %s\n", strerror(errno)); |
|
|
|
//if (idx_sock->send((char*)bytes.begin(), bytes.size()) < 0) {
|
|
|
|
} |
|
|
|
// printf("err sending encodeIdx pkt: %s\n", strerror(errno));
|
|
|
|
if (lh) { |
|
|
|
//}
|
|
|
|
lh_log(lh, bytes.begin(), bytes.size(), false); |
|
|
|
//if (lh) {
|
|
|
|
} |
|
|
|
// lh_log(lh, bytes.begin(), bytes.size(), false);
|
|
|
|
|
|
|
|
//}
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (raw_clips) { |
|
|
|
if (raw_clips) { |
|
|
@ -313,7 +321,8 @@ void encoder_thread(bool is_streaming, bool raw_clips, bool front) { |
|
|
|
visionstream_destroy(&stream); |
|
|
|
visionstream_destroy(&stream); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
delete idx_sock; |
|
|
|
// TODO: add this back
|
|
|
|
|
|
|
|
//delete idx_sock;
|
|
|
|
|
|
|
|
|
|
|
|
if (encoder_inited) { |
|
|
|
if (encoder_inited) { |
|
|
|
LOG("encoder destroy"); |
|
|
|
LOG("encoder destroy"); |
|
|
@ -638,10 +647,13 @@ int main(int argc, char** argv) { |
|
|
|
|
|
|
|
|
|
|
|
#ifndef DISABLE_ENCODER |
|
|
|
#ifndef DISABLE_ENCODER |
|
|
|
// rear camera
|
|
|
|
// rear camera
|
|
|
|
std::thread encoder_thread_handle(encoder_thread, is_streaming, false, false); |
|
|
|
std::thread encoder_thread_handle(encoder_thread, is_streaming, false, 0); |
|
|
|
|
|
|
|
|
|
|
|
// front camera
|
|
|
|
// front camera
|
|
|
|
std::thread front_encoder_thread_handle(encoder_thread, false, false, true); |
|
|
|
std::thread front_encoder_thread_handle(encoder_thread, false, false, 2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// wide camera
|
|
|
|
|
|
|
|
std::thread wide_encoder_thread_handle(encoder_thread, false, false, 1); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#if ENABLE_LIDAR |
|
|
|
#if ENABLE_LIDAR |
|
|
@ -718,6 +730,7 @@ int main(int argc, char** argv) { |
|
|
|
|
|
|
|
|
|
|
|
#ifndef DISABLE_ENCODER |
|
|
|
#ifndef DISABLE_ENCODER |
|
|
|
front_encoder_thread_handle.join(); |
|
|
|
front_encoder_thread_handle.join(); |
|
|
|
|
|
|
|
wide_encoder_thread_handle.join(); |
|
|
|
encoder_thread_handle.join(); |
|
|
|
encoder_thread_handle.join(); |
|
|
|
LOGW("encoder joined"); |
|
|
|
LOGW("encoder joined"); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|