Skip to content
Snippets Groups Projects
Commit 7d4749bc authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Working receiver

parent c2591d97
No related branches found
No related tags found
1 merge request!212Major refactor of frame streaming
Pipeline #17881 passed
......@@ -158,9 +158,10 @@ static void run(ftl::Configurable *root) {
ftl::codecs::Channels channels;
std::vector<Source*> sources;
// Create a vector of all input RGB-Depth sources
auto sources = ftl::createArray<Source>(root, "sources", net);
if (sources.size() > 0) {
if (root->getConfig()["sources"].size() > 0) {
sources = ftl::createArray<Source>(root, "sources", net);
auto *gen = createSourceGenerator(sources);
auto reconstr = ftl::create<ftl::Reconstruction>(root, "0", "0");
reconstr->setGenerator(gen);
......@@ -224,8 +225,8 @@ static void run(ftl::Configurable *root) {
tags.push_back(root->getID()+"/virtual");
root->set("tags", tags);
int o = root->value("origin_pose", 0) % sources.size();
vs->setPose(sources[o]->getPose());
//int o = root->value("origin_pose", 0) % sources.size();
//vs->setPose(sources[o]->getPose());
......
......@@ -144,6 +144,8 @@ void Builder::onFrameSet(const std::function<bool(ftl::rgbd::FrameSet &)> &cb) {
// The buffers are invalid after callback so mark stale
fs->stale = true;
LOG(INFO) << "PROCESS FRAMESET";
//ftl::pool.push([this,fs,cb](int) {
try {
cb(*fs);
......
......@@ -47,10 +47,12 @@ class Receiver : public ftl::Configurable, public ftl::rgbd::Generator {
int64_t timestamp_;
struct InternalStates {
InternalStates();
int64_t timestamp;
ftl::rgbd::FrameState state;
ftl::rgbd::Frame frame;
std::vector<ftl::codecs::Decoder*> decoders;
ftl::codecs::Decoder* decoders[32];
};
std::vector<InternalStates> frames_;
......@@ -59,6 +61,7 @@ class Receiver : public ftl::Configurable, public ftl::rgbd::Generator {
void _processCalibration(InternalStates &frame, const ftl::codecs::Packet &pkt);
void _processConfig(InternalStates &frame, const ftl::codecs::Packet &pkt);
void _createDecoder(InternalStates &frame, int chan, const ftl::codecs::Packet &pkt);
InternalStates &_getFrame(const ftl::codecs::StreamPacket &spkt);
};
}
......
......@@ -53,6 +53,8 @@ bool File::tick() {
return false;
}
LOG(INFO) << "FILE TICK";
//UNIQUE_LOCK(mtx_, lk);
std::unique_lock<std::mutex> lk(mutex_, std::defer_lock);
if (!lk.try_lock()) return true;
......
......@@ -8,6 +8,7 @@ using ftl::codecs::Channel;
Receiver::Receiver(nlohmann::json &config) : ftl::Configurable(config), stream_(nullptr) {
timestamp_ = 0;
second_channel_ = Channel::Depth;
}
Receiver::~Receiver() {
......@@ -70,6 +71,17 @@ void Receiver::_createDecoder(InternalStates &frame, int chan, const ftl::codecs
frame.decoders[chan] = ftl::codecs::allocateDecoder(pkt);
}
Receiver::InternalStates::InternalStates() {
for (int i=0; i<32; ++i) decoders[i] = nullptr;
}
Receiver::InternalStates &Receiver::_getFrame(const StreamPacket &spkt) {
if (frames_.size() <= spkt.frameNumber()) frames_.resize(spkt.frameNumber()+1);
auto &f = frames_[spkt.frameNumber()];
if (!f.frame.origin()) f.frame.setOrigin(&f.state);
return f;
}
void Receiver::setStream(ftl::stream::Stream *s) {
stream_ = s;
......@@ -83,8 +95,7 @@ void Receiver::setStream(ftl::stream::Stream *s) {
const cv::Size size = cv::Size(ftl::codecs::getWidth(pkt.definition), ftl::codecs::getHeight(pkt.definition));
//NetFrame &frame = queue_.getFrame(spkt.timestamp, size, CV_8UC4, (isFloatChannel(chan) ? CV_32FC1 : CV_8UC4));
InternalStates &frame = frames_[spkt.frameNumber()];
if (!frame.frame.origin()) frame.frame.setOrigin(&frame.state);
InternalStates &frame = _getFrame(spkt);
// Deal with the special channels...
switch (rchan) {
......@@ -93,13 +104,15 @@ void Receiver::setStream(ftl::stream::Stream *s) {
case Channel::Pose : _processPose(frame, pkt); return;
}
if (rchan != Channel::Colour && rchan != chan) return;
if (frame.state.getLeft().width == 0) {
LOG(WARNING) << "Missing calibration, skipping frame";
return;
}
frame.timestamp = spkt.timestamp;
if (timestamp_ > 0 && frame.timestamp <= timestamp_) {
if (frame.frame.hasChannel(spkt.channel)) {
LOG(ERROR) << "Duplicate frame - " << frame.timestamp << " received=" << int(rchan) << " uri=";
return;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment