Skip to content
Snippets Groups Projects
Commit 6ae40708 authored by Iiro Rastas's avatar Iiro Rastas
Browse files

Fix reconstruction snapshots

Reconstruction snapshots now include pose and calibration packets, so
that they can actually be reconstructed. Recording options in the
configuration have also been moved from the root to controls.
parent 063e057c
No related branches found
No related tags found
1 merge request!194Recording enhancements
Pipeline #17057 passed
This commit is part of merge request !194. Comments created here will be created in the context of that merge request.
......@@ -308,8 +308,10 @@ void MediaPanel::snapshot3D(ftl::gui::Camera *camera, const std::string &filenam
auto tagvalue = tag.value();
auto configurables = ftl::config::findByTag(tagvalue);
if (configurables.size() > 0) {
ftl::Configurable *configurable = configurables[0];
configurable->set("3D-snapshot", filename);
ftl::Configurable *configurable = ftl::config::find(configurables[0]->getID() + "/controls");
if (configurable) {
configurable->set("3D-snapshot", filename);
}
}
}
}
......@@ -320,11 +322,13 @@ void MediaPanel::startRecording3D(ftl::gui::Camera *camera, const std::string &f
auto tagvalue = tag.value();
auto configurables = ftl::config::findByTag(tagvalue);
if (configurables.size() > 0) {
ftl::Configurable *configurable = configurables[0];
configurable->set("record-name", filename);
configurable->set("record", true);
sceneRecording_ = std::optional<ftl::Configurable*>(configurable);
recordbutton_->setTextColor(nanogui::Color(1.0f,0.1f,0.1f,1.0f));
ftl::Configurable *configurable = ftl::config::find(configurables[0]->getID() + "/controls");
if (configurable) {
configurable->set("record-name", filename);
configurable->set("record", true);
sceneRecording_ = std::optional<ftl::Configurable*>(configurable);
recordbutton_->setTextColor(nanogui::Color(1.0f,0.1f,0.1f,1.0f));
}
}
}
}
......
......@@ -137,10 +137,10 @@ static void run(ftl::Configurable *root) {
// Controls
auto *controls = ftl::create<ftl::Configurable>(root, "controls");
net->start();
net->waitConnections();
std::vector<int> sourcecounts;
// Add sources from the configuration file as a single group.
......@@ -275,7 +275,7 @@ static void run(ftl::Configurable *root) {
std::ofstream snapshotout;
ftl::codecs::Writer snapshotwriter(snapshotout);
root->set("record", false);
controls->set("record", false);
int64_t timestamp = -1;
bool writingSnapshot = false;
......@@ -294,8 +294,12 @@ static void run(ftl::Configurable *root) {
// IFrame is one of the first two frames seen. In this case a
// part of the frame might already have been missed, so the
// IFrame after that one is captured instead.
if (precedingFrames.size() >= 2) {
bool isIFrame = false;
// Write all pose and calibration packets.
if ((int)spkt.channel >= 64) {
snapshotwriter.write(s, pkt);
} else if (precedingFrames.size() >= 2) {
bool isIFrame = true;
switch (pkt.codec) {
case ftl::codecs::codec_t::H264:
isIFrame = ftl::codecs::h264::isIFrame(pkt.data);
......@@ -326,7 +330,7 @@ static void run(ftl::Configurable *root) {
}
// Allow stream recording
root->on("record", [&fileout,&writer,&sources](const ftl::config::Event &e) {
controls->on("record", [&fileout,&writer,&sources](const ftl::config::Event &e) {
if (e.entity->value("record", false)) {
char timestamp[18];
std::time_t t=std::time(NULL);
......@@ -348,7 +352,7 @@ static void run(ftl::Configurable *root) {
}
});
root->on("3D-snapshot", [&snapshotout,&snapshotwriter,&writingSnapshot,&precedingFrames,&followingFrames](const ftl::config::Event &e) {
controls->on("3D-snapshot", [&snapshotout,&snapshotwriter,&writingSnapshot,&precedingFrames,&followingFrames,&sources](const ftl::config::Event &e) {
if (!snapshotwriter.active()) {
char timestamp[18];
std::time_t t=std::time(NULL);
......@@ -358,6 +362,12 @@ static void run(ftl::Configurable *root) {
precedingFrames.clear();
followingFrames.clear();
snapshotwriter.begin();
for (size_t i=0; i<sources.size(); ++i) {
//writeSourceProperties(writer, i, sources[i]);
sources[i]->inject(Channel::Calibration, sources[i]->parameters(), Channel::Left, sources[i]->getCapabilities());
sources[i]->inject(sources[i]->getPose());
}
}
});
......
......@@ -220,11 +220,6 @@ class Source : public ftl::Configurable {
void inject(const Eigen::Matrix4d &pose);
template <typename... ARGS>
std::pair<ftl::codecs::StreamPacket, ftl::codecs::Packet> make_packet(ftl::codecs::Channel c, ARGS... args);
std::pair<ftl::codecs::StreamPacket, ftl::codecs::Packet> make_packet(const Eigen::Matrix4d &pose);
protected:
detail::Source *impl_;
Eigen::Matrix4d pose_;
......@@ -260,30 +255,6 @@ class VectorBuffer {
std::vector<unsigned char> &vector_;
};
template <typename... ARGS>
std::pair<ftl::codecs::StreamPacket, ftl::codecs::Packet> ftl::rgbd::Source::make_packet(ftl::codecs::Channel c, ARGS... args) {
auto data = std::make_tuple(args...);
ftl::codecs::StreamPacket spkt;
ftl::codecs::Packet pkt;
spkt.timestamp = impl_->timestamp_;
std::cout << "Timestamp set." << '\n';
spkt.channel = c;
spkt.channel_count = 0;
spkt.streamID = 0;
pkt.codec = ftl::codecs::codec_t::MSGPACK;
pkt.block_number = 0;
pkt.block_total = 1;
pkt.definition = ftl::codecs::definition_t::Any;
pkt.flags = 0;
VectorBuffer buf(pkt.data);
msgpack::pack(buf, data);
return std::make_pair(spkt, pkt);
}
template <typename... ARGS>
void ftl::rgbd::Source::inject(ftl::codecs::Channel c, ARGS... args) {
if (!impl_) return;
......
......@@ -327,24 +327,6 @@ void Source::notify(int64_t ts, cv::cuda::GpuMat &c1, cv::cuda::GpuMat &c2) {
if (callback_) callback_(ts, c1, c2);
}
std::pair<ftl::codecs::StreamPacket, ftl::codecs::Packet> Source::make_packet(const Eigen::Matrix4d &pose) {
ftl::codecs::StreamPacket spkt;
ftl::codecs::Packet pkt;
spkt.timestamp = impl_->timestamp_;
spkt.channel_count = 0;
spkt.channel = Channel::Pose;
spkt.streamID = 0;
pkt.codec = ftl::codecs::codec_t::POSE;
pkt.definition = ftl::codecs::definition_t::Any;
pkt.block_number = 0;
pkt.block_total = 1;
pkt.flags = 0;
pkt.data = std::move(std::vector<uint8_t>((uint8_t*)pose.data(), (uint8_t*)pose.data() + 4*4*sizeof(double)));
return std::make_pair(spkt, pkt);
}
void Source::inject(const Eigen::Matrix4d &pose) {
ftl::codecs::StreamPacket spkt;
ftl::codecs::Packet pkt;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment