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

Add record feature to reconstruct

parent af8f28bf
Branches
No related tags found
1 merge request!127Implements #196 stream capturing
Pipeline #15257 failed
......@@ -15,6 +15,7 @@
#include <ftl/slave.hpp>
#include <ftl/rgbd/group.hpp>
#include <ftl/threads.hpp>
#include <ftl/codecs/writer.hpp>
#include "ilw/ilw.hpp"
#include <ftl/render/splat_render.hpp>
......@@ -159,6 +160,33 @@ static void run(ftl::Configurable *root) {
group.addSource(in);
}
// ---- Recording code -----------------------------------------------------
std::ofstream fileout;
ftl::codecs::Writer writer(fileout);
auto recorder = [&writer](ftl::rgbd::Source *src, const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt) {
writer.write(spkt, pkt);
};
// Allow stream recording
root->on("record", [&group,&fileout,&writer,&recorder](const ftl::config::Event &e) {
if (e.entity->value("record", false)) {
char timestamp[18];
std::time_t t=std::time(NULL);
std::strftime(timestamp, sizeof(timestamp), "%F-%H%M%S", std::localtime(&t));
fileout.open(std::string(timestamp) + ".ftl");
writer.begin();
group.addRawCallback(std::function(recorder));
} else {
group.removeRawCallback(recorder);
writer.end();
fileout.close();
}
});
// -------------------------------------------------------------------------
stream->setLatency(5); // FIXME: This depends on source!?
stream->add(&group);
stream->run();
......
......@@ -5,6 +5,8 @@ set(CODECSRC
src/opencv_encoder.cpp
src/opencv_decoder.cpp
src/generate.cpp
src/writer.cpp
src/reader.cpp
)
if (HAVE_NVPIPE)
......
......@@ -73,12 +73,12 @@ class Group {
* There is no guarantee about order or timing and the callback itself will
* need to ensure synchronisation of timestamps.
*/
void addRawCallback(std::function<void(ftl::rgbd::Source*, const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt)> &);
void addRawCallback(const std::function<void(ftl::rgbd::Source*, const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt)> &);
/**
* Removes a raw data callback from all sources in the group.
*/
void removeRawCallback(std::function<void(ftl::rgbd::Source*, const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt)> &);
void removeRawCallback(const std::function<void(ftl::rgbd::Source*, const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt)> &);
inline std::vector<Source*> sources() const { return sources_; }
......
......@@ -226,13 +226,13 @@ void Group::sync(std::function<bool(ftl::rgbd::FrameSet &)> cb) {
ftl::timer::start(true);
}
void Group::addRawCallback(std::function<void(ftl::rgbd::Source*, const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt)> &f) {
void Group::addRawCallback(const std::function<void(ftl::rgbd::Source*, const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt)> &f) {
for (auto s : sources_) {
s->addRawCallback(f);
}
}
void Group::removeRawCallback(std::function<void(ftl::rgbd::Source*, const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt)> &f) {
void Group::removeRawCallback(const std::function<void(ftl::rgbd::Source*, const ftl::codecs::StreamPacket &spkt, const ftl::codecs::Packet &pkt)> &f) {
for (auto s : sources_) {
s->removeRawCallback(f);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment