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

Support looping and speed control

parent b179e142
No related branches found
No related tags found
1 merge request!135Implements #201 file stream pausing
......@@ -96,6 +96,9 @@ static void run(ftl::Configurable *root) {
Universe *net = ftl::create<Universe>(root, "net");
ftl::ctrl::Slave slave(net, root);
// Controls
auto *controls = ftl::create<ftl::Configurable>(root, "controls");
net->start();
net->waitConnections();
......@@ -165,10 +168,6 @@ static void run(ftl::Configurable *root) {
ftl::rgbd::Group *group = new ftl::rgbd::Group;
ftl::ILW *align = ftl::create<ftl::ILW>(root, "merge");
// Controls
auto *controls = ftl::create<ftl::Configurable>(root, "controls");
controls->set("paused", false);
int o = root->value("origin_pose", 0) % sources.size();
virt->setPose(sources[o]->getPose());
......
......@@ -3,28 +3,28 @@
using ftl::rgbd::Player;
Player::Player(std::istream &s) : reader_(s) {
Player::Player(std::istream &s) : stream_(&s), reader_(s) {
auto *c = ftl::config::find("/controls");
if (c) {
paused_ = c->value("paused", false);
c->on("paused", [this](const ftl::config::Event &e) {
LOG(INFO) << "PAUSED";
c->on("paused", [this,c](const ftl::config::Event &e) {
paused_ = c->value("paused", false);
});
looping_ = c->value("looping", true);
c->on("looping", [this,c](const ftl::config::Event &e) {
looping_ = c->value("looping", false);
c->on("looping", [this](const ftl::config::Event &e) {
LOG(INFO) << "LOOPED";
});
speed_ = c->value("speed", 1.0f);
c->on("speed", [this](const ftl::config::Event &e) {
LOG(INFO) << "SPEED";
c->on("speed", [this,c](const ftl::config::Event &e) {
speed_ = c->value("speed", 1.0f);
});
reversed_ = c->value("reverse", false);
c->on("reverse", [this](const ftl::config::Event &e) {
LOG(INFO) << "REVERSE";
c->on("reverse", [this,c](const ftl::config::Event &e) {
reversed_ = c->value("reverse", false);
});
}
}
......@@ -34,7 +34,24 @@ Player::~Player() {
}
bool Player::read(int64_t ts) {
return reader_.read(ts);
if (paused_) return true;
int64_t adjusted_ts = int64_t(float(ts - reader_.getStartTime()) * speed_) + reader_.getStartTime();
LOG(INFO) << "Adjusted = " << adjusted_ts;
bool res = reader_.read(adjusted_ts);
if (looping_ && !res) {
reader_.end();
stream_->clear();
stream_->seekg(0);
if (!reader_.begin()) {
LOG(ERROR) << "Could not loop";
return false;
}
return true;
}
return res;
}
void Player::onPacket(int streamID, const std::function<void(const ftl::codecs::StreamPacket &, ftl::codecs::Packet &)> &f) {
......
......@@ -25,6 +25,7 @@ class Player {
inline int64_t getStartTime() { return reader_.getStartTime(); }
private:
std::istream *stream_;
ftl::codecs::Reader reader_;
bool paused_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment