replay: fix possible segfault in CameraServer (#22556)

old-commit-hash: 20b0ae0e65c9e5237a6b9f89329d31254ffab20e
This commit is contained in:
Dean Lee
2021-10-16 06:34:54 +08:00
committed by GitHub
parent 3802eab361
commit 50cf6fd948
2 changed files with 11 additions and 4 deletions
+7
View File
@@ -60,5 +60,12 @@ void CameraServer::thread() {
} else {
std::cout << "camera[" << type << "] failed to get frame:" << eidx.getSegmentId() << std::endl;
}
--publishing_;
}
}
void CameraServer::pushFrame(CameraType type, FrameReader *fr, const cereal::EncodeIndex::Reader &eidx) {
++publishing_;
queue_.push({type, fr, eidx});
}
+4 -4
View File
@@ -10,11 +10,9 @@ class CameraServer {
public:
CameraServer();
~CameraServer();
inline void pushFrame(CameraType type, FrameReader* fr, const cereal::EncodeIndex::Reader& eidx) {
queue_.push({type, fr, eidx});
}
void pushFrame(CameraType type, FrameReader* fr, const cereal::EncodeIndex::Reader& eidx);
inline void waitFinish() {
while (!queue_.empty()) usleep(0);
while (publishing_ > 0) usleep(0);
}
protected:
@@ -33,6 +31,8 @@ protected:
{.rgb_type = VISION_STREAM_RGB_FRONT, .yuv_type = VISION_STREAM_YUV_FRONT},
{.rgb_type = VISION_STREAM_RGB_WIDE, .yuv_type = VISION_STREAM_YUV_WIDE},
};
std::atomic<int> publishing_ = 0;
std::thread camera_thread_;
std::unique_ptr<VisionIpcServer> vipc_server_;
SafeQueue<std::tuple<CameraType, FrameReader*, const cereal::EncodeIndex::Reader>> queue_;