Newer
Older
#include <voltu/room.hpp>
#include "room_impl.hpp"
#include "frame_impl.hpp"
#include <voltu/types/errors.hpp>
using voltu::internal::RoomImpl;
RoomImpl::RoomImpl(ftl::stream::Feed* feed)
: feed_(feed)
{
}
RoomImpl::~RoomImpl()
{
if (filter_) filter_->remove();
}
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
bool RoomImpl::waitNextFrame(int64_t timeout)
{
if (!filter_)
{
filter_ = feed_->filter(fsids_, {ftl::codecs::Channel::Colour, ftl::codecs::Channel::Depth});
filter_->on([this](const std::shared_ptr<ftl::data::FrameSet> &fs)
{
UNIQUE_LOCK(mutex_, lk);
last_seen_ = std::max(last_seen_, fs->timestamp());
cv_.notify_all();
return true;
});
}
std::unique_lock<std::mutex> lk(mutex_);
if (last_read_ >= last_seen_)
{
if (timeout > 0)
{
cv_.wait_for(lk, std::chrono::seconds(timeout), [this] {
return last_read_ < last_seen_;
});
return last_read_ < last_seen_;
}
else if (timeout == 0)
{
return false;
}
else
{
cv_.wait(lk, [this] {
return last_read_ < last_seen_;
});
}
}
return true;
}
voltu::FramePtr RoomImpl::getFrame()
{
auto f = std::make_shared<voltu::internal::FrameImpl>();
std::unique_lock<std::mutex> lk(mutex_);
int count = 0;
for (auto fsid : fsids_)
{
auto fs = feed_->getFrameSet(fsid);
if (!fs) continue;
f->pushFrameSet(fs);
last_read_ = std::max(last_read_, fs->timestamp());
++count;
}
if (count == 0) throw voltu::exceptions::NoFrame();
return f;
}
std::string RoomImpl::getName()
{
return "";
}
void RoomImpl::addFrameSet(uint32_t fsid)
{
fsids_.insert(fsid);
}
bool RoomImpl::active()
{
return ftl::running;
}