Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoderd: fix SIGABRT caused by buffer extras out-of-sync with buffers #34432

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions system/loggerd/encoder/v4l_encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ void V4LEncoder::dequeue_handler(V4LEncoder *e) {
// save header
header = kj::heapArray<capnp::byte>(buf, bytesused);
} else {
VisionIpcBufExtra extra = e->extras.pop();
VisionIpcBufExtra extra = {};
{
std::lock_guard<std::mutex> lock(e->buffer_extras_mutex);
extra = e->buffer_extras[index];
}
assert(extra.timestamp_eof/1000 == ts); // stay in sync
frame_id = extra.frame_id;
++idx;
Expand Down Expand Up @@ -290,8 +294,11 @@ int V4LEncoder::encode_frame(VisionBuf* buf, VisionIpcBufExtra *extra) {
// reserve buffer
int buffer_in = free_buf_in.pop();

// push buffer
extras.push(*extra);
{
std::lock_guard<std::mutex> lock(buffer_extras_mutex);
buffer_extras[buffer_in] = *extra;
}

//buf->sync(VISIONBUF_SYNC_TO_DEVICE);
queue_buffer(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, buffer_in, buf, timestamp);

Expand All @@ -308,7 +315,6 @@ void V4LEncoder::encoder_close() {
checked_ioctl(fd, VIDIOC_ENCODER_CMD, &encoder_cmd);
// join waits for V4L2_QCOM_BUF_FLAG_EOS
dequeue_handler_thread.join();
assert(extras.empty());
}
this->is_open = false;
}
Expand Down
6 changes: 5 additions & 1 deletion system/loggerd/encoder/v4l_encoder.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#include <array>
#include <mutex>

#include "common/queue.h"
#include "system/loggerd/encoder/encoder.h"

Expand All @@ -20,7 +23,8 @@ class V4LEncoder : public VideoEncoder {
int segment_num = -1;
int counter = 0;

SafeQueue<VisionIpcBufExtra> extras;
std::mutex buffer_extras_mutex;
std::array<VisionIpcBufExtra, BUF_OUT_COUNT> buffer_extras = {};

static void dequeue_handler(V4LEncoder *e);
std::thread dequeue_handler_thread;
Expand Down
Loading