Skip to content

Commit

Permalink
encoderd: refactor VideoEncoder::publisher_publish to standardize mem…
Browse files Browse the repository at this point in the history
…ber variable access (#34342)

remove redundant pointer parameter
  • Loading branch information
deanlee authored Jan 12, 2025
1 parent 1068779 commit 47b13f5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
22 changes: 11 additions & 11 deletions system/loggerd/encoder/encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ VideoEncoder::VideoEncoder(const EncoderInfo &encoder_info, int in_width, int in
pm.reset(new PubMaster(pubs));
}

void VideoEncoder::publisher_publish(VideoEncoder *e, int segment_num, uint32_t idx, VisionIpcBufExtra &extra,
void VideoEncoder::publisher_publish(int segment_num, uint32_t idx, VisionIpcBufExtra &extra,
unsigned int flags, kj::ArrayPtr<capnp::byte> header, kj::ArrayPtr<capnp::byte> dat) {
// broadcast packet
MessageBuilder msg;
auto event = msg.initEvent(true);
auto edat = (event.*(e->encoder_info.init_encode_data_func))();
auto edat = (event.*(encoder_info.init_encode_data_func))();
auto edata = edat.initIdx();
struct timespec ts;
timespec_get(&ts, TIME_UTC);
edat.setUnixTimestampNanos((uint64_t)ts.tv_sec*1000000000 + ts.tv_nsec);
edata.setFrameId(extra.frame_id);
edata.setTimestampSof(extra.timestamp_sof);
edata.setTimestampEof(extra.timestamp_eof);
edata.setType(e->encoder_info.encode_type);
edata.setEncodeId(e->cnt++);
edata.setType(encoder_info.encode_type);
edata.setEncodeId(cnt++);
edata.setSegmentNum(segment_num);
edata.setSegmentId(idx);
edata.setFlags(flags);
Expand All @@ -39,21 +39,21 @@ void VideoEncoder::publisher_publish(VideoEncoder *e, int segment_num, uint32_t
if (flags & V4L2_BUF_FLAG_KEYFRAME) edat.setHeader(header);

uint32_t bytes_size = capnp::computeSerializedSizeInWords(msg) * sizeof(capnp::word);
if (e->msg_cache.size() < bytes_size) {
e->msg_cache.resize(bytes_size);
if (msg_cache.size() < bytes_size) {
msg_cache.resize(bytes_size);
}
kj::ArrayOutputStream output_stream(kj::ArrayPtr<capnp::byte>(e->msg_cache.data(), bytes_size));
kj::ArrayOutputStream output_stream(kj::ArrayPtr<capnp::byte>(msg_cache.data(), bytes_size));
capnp::writeMessage(output_stream, msg);
e->pm->send(e->encoder_info.publish_name, e->msg_cache.data(), bytes_size);
pm->send(encoder_info.publish_name, msg_cache.data(), bytes_size);

// Publish keyframe thumbnail
if ((flags & V4L2_BUF_FLAG_KEYFRAME) && e->encoder_info.thumbnail_name != NULL) {
if ((flags & V4L2_BUF_FLAG_KEYFRAME) && encoder_info.thumbnail_name != NULL) {
MessageBuilder tm;
auto thumbnail = tm.initEvent().initThumbnail();
thumbnail.setFrameId(extra.frame_id);
thumbnail.setTimestampEof(extra.timestamp_eof);
thumbnail.setThumbnail(dat);
thumbnail.setEncoding(cereal::Thumbnail::Encoding::KEYFRAME);
pm->send(e->encoder_info.thumbnail_name, tm);
pm->send(encoder_info.thumbnail_name, tm);
}
}
}
2 changes: 1 addition & 1 deletion system/loggerd/encoder/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class VideoEncoder {
virtual void encoder_open(const char* path) = 0;
virtual void encoder_close() = 0;

void publisher_publish(VideoEncoder *e, int segment_num, uint32_t idx, VisionIpcBufExtra &extra, unsigned int flags, kj::ArrayPtr<capnp::byte> header, kj::ArrayPtr<capnp::byte> dat);
void publisher_publish(int segment_num, uint32_t idx, VisionIpcBufExtra &extra, unsigned int flags, kj::ArrayPtr<capnp::byte> header, kj::ArrayPtr<capnp::byte> dat);

protected:
void publish_thumbnail(uint32_t frame_id, uint64_t timestamp_eof, kj::ArrayPtr<capnp::byte> dat);
Expand Down
2 changes: 1 addition & 1 deletion system/loggerd/encoder/ffmpeg_encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ int FfmpegEncoder::encode_frame(VisionBuf* buf, VisionIpcBufExtra *extra) {
printf("%20s got %8d bytes flags %8x idx %4d id %8d\n", encoder_info.publish_name, pkt.size, pkt.flags, counter, extra->frame_id);
}

publisher_publish(this, segment_num, counter, *extra,
publisher_publish(segment_num, counter, *extra,
(pkt.flags & AV_PKT_FLAG_KEY) ? V4L2_BUF_FLAG_KEYFRAME : 0,
kj::arrayPtr<capnp::byte>(pkt.data, (size_t)0), // TODO: get the header
kj::arrayPtr<capnp::byte>(pkt.data, pkt.size));
Expand Down
2 changes: 1 addition & 1 deletion system/loggerd/encoder/v4l_encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void V4LEncoder::dequeue_handler(V4LEncoder *e) {
assert(extra.timestamp_eof/1000 == ts); // stay in sync
frame_id = extra.frame_id;
++idx;
e->publisher_publish(e, e->segment_num, idx, extra, flags, header, kj::arrayPtr<capnp::byte>(buf, bytesused));
e->publisher_publish(e->segment_num, idx, extra, flags, header, kj::arrayPtr<capnp::byte>(buf, bytesused));
}

if (env_debug_encoder) {
Expand Down

0 comments on commit 47b13f5

Please sign in to comment.