Restore lock stream datas

This commit is contained in:
John Zhao 2018-06-01 16:50:15 +08:00
parent 9c20d62763
commit 7451b6417d
2 changed files with 13 additions and 5 deletions

View File

@ -351,12 +351,14 @@ void Device::WaitForStreams() {
std::vector<device::StreamData> Device::GetStreamDatas(const Stream &stream) { std::vector<device::StreamData> Device::GetStreamDatas(const Stream &stream) {
CHECK(video_streaming_); CHECK(video_streaming_);
CHECK_NOTNULL(streams_); CHECK_NOTNULL(streams_);
std::lock_guard<std::mutex> _(mtx_streams_);
return streams_->GetStreamDatas(stream); return streams_->GetStreamDatas(stream);
} }
device::StreamData Device::GetLatestStreamData(const Stream &stream) { device::StreamData Device::GetLatestStreamData(const Stream &stream) {
CHECK(video_streaming_); CHECK(video_streaming_);
CHECK_NOTNULL(streams_); CHECK_NOTNULL(streams_);
std::lock_guard<std::mutex> _(mtx_streams_);
return streams_->GetLatestStreamData(stream); return streams_->GetLatestStreamData(stream);
} }
@ -424,10 +426,13 @@ void Device::StartVideoStreaming() {
return; return;
} }
// auto &&time_beg = times::now(); // auto &&time_beg = times::now();
{
std::lock_guard<std::mutex> _(mtx_streams_);
if (streams_->PushStream(Capabilities::STEREO, data)) { if (streams_->PushStream(Capabilities::STEREO, data)) {
CallbackPushedStreamData(Stream::LEFT); CallbackPushedStreamData(Stream::LEFT);
CallbackPushedStreamData(Stream::RIGHT); CallbackPushedStreamData(Stream::RIGHT);
} }
}
continuation(); continuation();
// VLOG(2) << "Stereo video callback cost " // VLOG(2) << "Stereo video callback cost "
// << times::count<times::milliseconds>(times::now() - time_beg) // << times::count<times::milliseconds>(times::now() - time_beg)

View File

@ -18,6 +18,7 @@
#include <limits> #include <limits>
#include <map> #include <map>
#include <memory> #include <memory>
#include <mutex>
#include <string> #include <string>
#include <vector> #include <vector>
@ -272,6 +273,8 @@ class MYNTEYE_API Device {
std::map<Capabilities, StreamRequest> stream_config_requests_; std::map<Capabilities, StreamRequest> stream_config_requests_;
std::mutex mtx_streams_;
std::shared_ptr<Channels> channels_; std::shared_ptr<Channels> channels_;
std::shared_ptr<Motions> motions_; std::shared_ptr<Motions> motions_;