diff --git a/src/device/device.cc b/src/device/device.cc index 207497f..c42812e 100644 --- a/src/device/device.cc +++ b/src/device/device.cc @@ -351,12 +351,14 @@ void Device::WaitForStreams() { std::vector Device::GetStreamDatas(const Stream &stream) { CHECK(video_streaming_); CHECK_NOTNULL(streams_); + std::lock_guard _(mtx_streams_); return streams_->GetStreamDatas(stream); } device::StreamData Device::GetLatestStreamData(const Stream &stream) { CHECK(video_streaming_); CHECK_NOTNULL(streams_); + std::lock_guard _(mtx_streams_); return streams_->GetLatestStreamData(stream); } @@ -424,14 +426,17 @@ void Device::StartVideoStreaming() { return; } // auto &&time_beg = times::now(); - if (streams_->PushStream(Capabilities::STEREO, data)) { - CallbackPushedStreamData(Stream::LEFT); - CallbackPushedStreamData(Stream::RIGHT); + { + std::lock_guard _(mtx_streams_); + if (streams_->PushStream(Capabilities::STEREO, data)) { + CallbackPushedStreamData(Stream::LEFT); + CallbackPushedStreamData(Stream::RIGHT); + } } continuation(); // VLOG(2) << "Stereo video callback cost " - // << times::count(times::now() - time_beg) - // << " ms"; + // << times::count(times::now() - time_beg) + // << " ms"; }); } else { LOG(FATAL) << "Not any stream capabilities are supported by this device"; diff --git a/src/device/device.h b/src/device/device.h index 9fc86d0..a4dfbb4 100644 --- a/src/device/device.h +++ b/src/device/device.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -272,6 +273,8 @@ class MYNTEYE_API Device { std::map stream_config_requests_; + std::mutex mtx_streams_; + std::shared_ptr channels_; std::shared_ptr motions_;