diff --git a/components/streams/include/ftl/streams/filestream.hpp b/components/streams/include/ftl/streams/filestream.hpp index be415989073ba51345f13e0117f17320192e911b..a5d75b9477d07ad464ac28dc007100a34c337bdc 100644 --- a/components/streams/include/ftl/streams/filestream.hpp +++ b/components/streams/include/ftl/streams/filestream.hpp @@ -66,6 +66,7 @@ class File : public Stream { int64_t timestart_; int64_t timestamp_; int64_t interval_; + int64_t first_ts_; bool active_; int version_; ftl::timer::TimerHandle timer_; diff --git a/components/streams/src/filestream.cpp b/components/streams/src/filestream.cpp index f8ee805b04d3335d94b16c50d4c6539f9e88c44a..705388a2eea2657af8cb53405cd960c4e6ce540a 100644 --- a/components/streams/src/filestream.cpp +++ b/components/streams/src/filestream.cpp @@ -41,6 +41,7 @@ bool File::_checkFile() { int count = 10; int64_t ts = -1000; int min_ts_diff = 1000; + first_ts_ = 10000000; while (count > 0) { std::tuple<ftl::codecs::StreamPacket,ftl::codecs::Packet> data; @@ -51,6 +52,8 @@ bool File::_checkFile() { auto &spkt = std::get<0>(data); auto &pkt = std::get<1>(data); + if (spkt.timestamp < first_ts_) first_ts_ = spkt.timestamp; + if (spkt.timestamp > 0 && int(spkt.channel) < 32) { if (spkt.timestamp > ts) { --count; @@ -219,7 +222,7 @@ bool File::tick(int64_t ts) { // Adjust timestamp // FIXME: A potential bug where multiple times are merged into one? - std::get<0>(data).timestamp = ((std::get<0>(data).timestamp) / interval_) * interval_ + timestart_; + std::get<0>(data).timestamp = (((std::get<0>(data).timestamp) - first_ts_) / interval_) * interval_ + timestart_; // Maintain availability of channels. available(0) += std::get<0>(data).channel;