From f244b7c7e156cd109be13a68ba1096dc2d25f3d0 Mon Sep 17 00:00:00 2001 From: ZwX1616 Date: Thu, 19 Nov 2020 16:12:02 -0800 Subject: [PATCH] tici front/wide encodeIdx msgs (#2564) * different msgs * also add timestamps * keep impatient log, remove the other * meaningless --- selfdrive/camerad/cameras/camera_common.cc | 1 - selfdrive/camerad/cameras/camera_common.h | 1 + selfdrive/camerad/main.cc | 1 + selfdrive/common/visionipc.h | 1 + selfdrive/loggerd/loggerd.cc | 19 +++++++------------ 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/selfdrive/camerad/cameras/camera_common.cc b/selfdrive/camerad/cameras/camera_common.cc index 1500edc1bc..c389dc4973 100644 --- a/selfdrive/camerad/cameras/camera_common.cc +++ b/selfdrive/camerad/cameras/camera_common.cc @@ -213,7 +213,6 @@ void CameraBuf::stop() { void fill_frame_data(cereal::FrameData::Builder &framed, const FrameMetadata &frame_data, uint32_t cnt) { framed.setFrameId(frame_data.frame_id); - framed.setEncodeId(cnt); framed.setTimestampEof(frame_data.timestamp_eof); framed.setFrameLength(frame_data.frame_length); framed.setIntegLines(frame_data.integ_lines); diff --git a/selfdrive/camerad/cameras/camera_common.h b/selfdrive/camerad/cameras/camera_common.h index 232bc7ed5f..fc5fa229d3 100644 --- a/selfdrive/camerad/cameras/camera_common.h +++ b/selfdrive/camerad/cameras/camera_common.h @@ -63,6 +63,7 @@ typedef struct LogCameraInfo { typedef struct FrameMetadata { uint32_t frame_id; + uint64_t timestamp_sof; // only set on tici uint64_t timestamp_eof; unsigned int frame_length; unsigned int integ_lines; diff --git a/selfdrive/camerad/main.cc b/selfdrive/camerad/main.cc index 712a08809b..4809315df2 100644 --- a/selfdrive/camerad/main.cc +++ b/selfdrive/camerad/main.cc @@ -205,6 +205,7 @@ void* visionserver_client_thread(void* arg) { stream_i == VISION_STREAM_YUV_WIDE) { CameraBuf *b = get_camerabuf_by_type(s, (VisionStreamType)stream_i); rep.d.stream_acq.extra.frame_id = b->yuv_metas[idx].frame_id; + rep.d.stream_acq.extra.timestamp_sof = b->yuv_metas[idx].timestamp_sof; rep.d.stream_acq.extra.timestamp_eof = b->yuv_metas[idx].timestamp_eof; } vipc_send(fd, &rep); diff --git a/selfdrive/common/visionipc.h b/selfdrive/common/visionipc.h index 1b216f5255..e20500db6b 100644 --- a/selfdrive/common/visionipc.h +++ b/selfdrive/common/visionipc.h @@ -57,6 +57,7 @@ typedef struct VisionStreamBufs { typedef struct VIPCBufExtra { // only for yuv uint32_t frame_id; + uint64_t timestamp_sof; uint64_t timestamp_eof; } VIPCBufExtra; diff --git a/selfdrive/loggerd/loggerd.cc b/selfdrive/loggerd/loggerd.cc index 4bc50bb16b..51ac005ebe 100644 --- a/selfdrive/loggerd/loggerd.cc +++ b/selfdrive/loggerd/loggerd.cc @@ -67,7 +67,6 @@ LogCameraInfo cameras_logged[LOG_CAMERA_ID_MAX] = { .stream_type = VISION_STREAM_YUV, .filename = "fcamera.hevc", .frame_packet_name = "frame", - .encode_idx_name = "encodeIdx", .fps = MAIN_FPS, .bitrate = MAIN_BITRATE, .is_h265 = true, @@ -78,7 +77,6 @@ LogCameraInfo cameras_logged[LOG_CAMERA_ID_MAX] = { .stream_type = VISION_STREAM_YUV_FRONT, .filename = "dcamera.hevc", .frame_packet_name = "frontFrame", - .encode_idx_name = "frontEncodeIdx", .fps = MAIN_FPS, // on EONs, more compressed this way .bitrate = DCAM_BITRATE, .is_h265 = true, @@ -89,7 +87,6 @@ LogCameraInfo cameras_logged[LOG_CAMERA_ID_MAX] = { .stream_type = VISION_STREAM_YUV_WIDE, .filename = "ecamera.hevc", .frame_packet_name = "wideFrame", - .encode_idx_name = "wideEncodeIdx", .fps = MAIN_FPS, .bitrate = MAIN_BITRATE, .is_h265 = true, @@ -235,9 +232,6 @@ void encoder_thread(RotateState *rotate_state, bool raw_clips, int cam_idx) { s.num_encoder += 1; pthread_mutex_unlock(&s.rotate_lock); - PubSocket *idx_sock = PubSocket::create(s.ctx, cameras_logged[cam_idx].encode_idx_name); - assert(idx_sock != NULL); - LoggerHandle *lh = NULL; while (!do_exit) { @@ -377,8 +371,12 @@ void encoder_thread(RotateState *rotate_state, bool raw_clips, int cam_idx) { // publish encode index MessageBuilder msg; - auto eidx = msg.initEvent().initEncodeIdx(); + // this is really ugly + auto eidx = cam_idx == LOG_CAMERA_ID_DCAMERA ? msg.initEvent().initFrontEncodeIdx() : + (cam_idx == LOG_CAMERA_ID_ECAMERA ? msg.initEvent().initWideEncodeIdx() : msg.initEvent().initEncodeIdx()); eidx.setFrameId(extra.frame_id); + eidx.setTimestampSof(extra.timestamp_sof); + eidx.setTimestampEof(extra.timestamp_eof); #ifdef QCOM2 eidx.setType(cereal::EncodeIndex::Type::FULL_H_E_V_C); #else @@ -390,9 +388,8 @@ void encoder_thread(RotateState *rotate_state, bool raw_clips, int cam_idx) { eidx.setSegmentId(out_id); auto bytes = msg.toBytes(); - - 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); } } @@ -450,8 +447,6 @@ void encoder_thread(RotateState *rotate_state, bool raw_clips, int cam_idx) { visionstream_destroy(&stream); } - delete idx_sock; - if (encoder_inited) { LOG("encoder destroy"); encoder_close(&encoder);