diff --git a/components/rgbd-sources/src/file_source.cpp b/components/rgbd-sources/src/file_source.cpp index f5e0e7b30e1ff75b8458129cca6a0f81975c0fdd..bc0a5fc700ec9b63732761315ec9ccd6fe0e92ad 100644 --- a/components/rgbd-sources/src/file_source.cpp +++ b/components/rgbd-sources/src/file_source.cpp @@ -1,5 +1,7 @@ #include "file_source.hpp" +#include <ftl/timer.hpp> + using ftl::rgbd::detail::FileSource; using ftl::codecs::codec_t; @@ -23,6 +25,8 @@ FileSource::FileSource(ftl::rgbd::Source *s, ftl::codecs::Reader *r, int sid) : decoders_[1] = nullptr; cache_read_ = -1; cache_write_ = 0; + realtime_ = host_->value("realtime", true); + timestamp_ = r->getStartTime(); r->onPacket(sid, [this](const ftl::codecs::StreamPacket &spkt, ftl::codecs::Packet &pkt) { if (pkt.codec == codec_t::POSE) { @@ -34,6 +38,12 @@ FileSource::FileSource(ftl::rgbd::Source *s, ftl::codecs::Reader *r, int sid) : params_ = *camera; has_calibration_ = true; } else { + if (pkt.codec == codec_t::HEVC) { + // Obtain NAL unit type + int nal_type = (pkt.data[4] >> 1) & 0x3F; + // A type of 32 = VPS unit, hence I-Frame in this case so skip past packets + if (nal_type == 32) _removeChannel(spkt.channel); + } cache_[cache_write_].emplace_back(); auto &c = cache_[cache_write_].back(); @@ -48,8 +58,23 @@ FileSource::~FileSource() { } +void FileSource::_removeChannel(int channel) { + int c = 0; + for (auto i=cache_[cache_write_].begin(); i != cache_[cache_write_].end(); ++i) { + if ((*i).spkt.channel == channel) { + ++c; + i = cache_[cache_write_].erase(i); + } + } + DLOG(INFO) << "Skipped " << c << " packets"; +} + bool FileSource::capture(int64_t ts) { - timestamp_ = ts; + if (realtime_) { + timestamp_ = ts; + } else { + timestamp_ += ftl::timer::getInterval(); + } return true; } diff --git a/components/rgbd-sources/src/file_source.hpp b/components/rgbd-sources/src/file_source.hpp index 06f8248846225654c35b70814ae379d4057b707e..810b1b56c170400898a81db9963f6c4c1d4cd5d5 100644 --- a/components/rgbd-sources/src/file_source.hpp +++ b/components/rgbd-sources/src/file_source.hpp @@ -41,6 +41,9 @@ class FileSource : public detail::Source { ftl::codecs::Decoder *decoders_[2]; + bool realtime_; + + void _removeChannel(int channel); void _createDecoder(int ix, const ftl::codecs::Packet &pkt); };