fix(correspondence): also wait stream matched ready

This commit is contained in:
John Zhao 2019-02-25 12:09:48 +08:00
parent e6d2d3ebe4
commit 5b5ded25c9
2 changed files with 16 additions and 2 deletions

View File

@ -171,9 +171,13 @@ void Correspondence::NotifyStreamDataReady() {
bool Correspondence::IsStreamDataReady() { bool Correspondence::IsStreamDataReady() {
if (stream_datas_.empty()) return false; if (stream_datas_.empty()) return false;
if (stream_match_enabled_) {
if (stream_datas_match_.empty()) return false;
}
if (motion_datas_.empty()) return false; if (motion_datas_.empty()) return false;
std::uint64_t img_stamp = 0; std::uint64_t img_stamp = 0;
std::uint64_t img_macth_stamp = 0;
{ {
std::lock_guard<std::recursive_mutex> _(mtx_stream_datas_); std::lock_guard<std::recursive_mutex> _(mtx_stream_datas_);
auto data = stream_datas_.front(); auto data = stream_datas_.front();
@ -181,6 +185,10 @@ bool Correspondence::IsStreamDataReady() {
LOG(FATAL) << "stream data image info is empty!"; LOG(FATAL) << "stream data image info is empty!";
} }
img_stamp = data.img->timestamp; img_stamp = data.img->timestamp;
if (stream_match_enabled_) {
img_macth_stamp = stream_datas_match_.front().img->timestamp;
}
} }
std::uint64_t imu_stamp = 0; std::uint64_t imu_stamp = 0;
{ {
@ -192,8 +200,13 @@ bool Correspondence::IsStreamDataReady() {
imu_stamp = data.imu->timestamp; imu_stamp = data.imu->timestamp;
} }
if (stream_match_enabled_) {
return img_stamp + stream_interval_us_half_ < imu_stamp
&& img_macth_stamp + stream_interval_us_half_ < imu_stamp;
} else {
return img_stamp + stream_interval_us_half_ < imu_stamp; return img_stamp + stream_interval_us_half_ < imu_stamp;
} }
}
std::vector<api::StreamData> Correspondence::GetReadyStreamData(bool matched) { std::vector<api::StreamData> Correspondence::GetReadyStreamData(bool matched) {
std::uint64_t imu_stamp = 0; std::uint64_t imu_stamp = 0;

View File

@ -15,6 +15,7 @@
#define MYNTEYE_API_CONFIG_H_ #define MYNTEYE_API_CONFIG_H_
#pragma once #pragma once
#include <atomic>
#include <condition_variable> #include <condition_variable>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
@ -57,7 +58,7 @@ class Correspondence {
std::shared_ptr<Device> device_; std::shared_ptr<Device> device_;
Stream stream_; Stream stream_;
Stream stream_match_; Stream stream_match_;
bool stream_match_enabled_; std::atomic_bool stream_match_enabled_;
float stream_interval_us_; float stream_interval_us_;
float stream_interval_us_half_; float stream_interval_us_half_;