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

Add latency information

parent 7fe8f444
No related branches found
No related tags found
1 merge request!316Resolves #343 GUI and Frame Refactor
...@@ -30,13 +30,16 @@ void Camera::update(double delta) { ...@@ -30,13 +30,16 @@ void Camera::update(double delta) {
if (nframes_ < 0) { return; } if (nframes_ < 0) { return; }
if (nframes_ > update_fps_freq_) { if (nframes_ > update_fps_freq_) {
float n = nframes_; float n = nframes_;
float l = latency_ / n;
nframes_ = 0; nframes_ = 0;
latency_ = 0;
auto t = glfwGetTime(); auto t = glfwGetTime();
float diff = t - last_; float diff = t - last_;
last_ = t; last_ = t;
auto *mod = screen->getModule<ftl::gui2::Statistics>(); auto *mod = screen->getModule<ftl::gui2::Statistics>();
mod->getJSON(StatisticsPanel::PERFORMANCE_INFO)["FPS"] = n/diff; mod->getJSON(StatisticsPanel::PERFORMANCE_INFO)["FPS"] = n/diff;
mod->getJSON(StatisticsPanel::PERFORMANCE_INFO)["Latency"] = l;
if (live_) mod->getJSON(StatisticsPanel::MEDIA_STATUS)["LIVE"] = nlohmann::json{{"icon", ENTYPO_ICON_VIDEO_CAMERA},{"value", true},{"colour","#0000FF"},{"size",28}}; if (live_) mod->getJSON(StatisticsPanel::MEDIA_STATUS)["LIVE"] = nlohmann::json{{"icon", ENTYPO_ICON_VIDEO_CAMERA},{"value", true},{"colour","#0000FF"},{"size",28}};
auto ptr = std::atomic_load(&latest_); auto ptr = std::atomic_load(&latest_);
...@@ -285,6 +288,7 @@ void Camera::activate(ftl::data::FrameID id) { ...@@ -285,6 +288,7 @@ void Camera::activate(ftl::data::FrameID id) {
screen->redraw(); screen->redraw();
nframes_++; nframes_++;
latency_ += ftl::timer::get_time() - fs->localTimestamp;
return true; return true;
} }
); );
......
...@@ -77,6 +77,7 @@ private: ...@@ -77,6 +77,7 @@ private:
bool vr_=false; bool vr_=false;
float last_=0.0f; float last_=0.0f;
std::atomic_int16_t nframes_=0; std::atomic_int16_t nframes_=0;
std::atomic_int64_t latency_=0;
int update_fps_freq_=30; // fps counter update frequency (frames) int update_fps_freq_=30; // fps counter update frequency (frames)
ftl::data::FrameSetPtr current_fs_; ftl::data::FrameSetPtr current_fs_;
......
...@@ -59,9 +59,8 @@ struct StreamPacketV4 { ...@@ -59,9 +59,8 @@ struct StreamPacketV4 {
inline int frameNumber() const { return (version >= 4) ? frame_number : streamID; } inline int frameNumber() const { return (version >= 4) ? frame_number : streamID; }
inline size_t frameSetID() const { return (version >= 4) ? streamID : 0; } inline size_t frameSetID() const { return (version >= 4) ? streamID : 0; }
inline int64_t localTimestamp() const { return timestamp + originClockDelta; }
int64_t originClockDelta; // Not message packet / saved int64_t localTimestamp; // Not message packet / saved
unsigned int hint_capability; // Is this a video stream, for example unsigned int hint_capability; // Is this a video stream, for example
size_t hint_source_total; // Number of tracks per frame to expect size_t hint_source_total; // Number of tracks per frame to expect
...@@ -86,9 +85,8 @@ struct StreamPacket { ...@@ -86,9 +85,8 @@ struct StreamPacket {
inline int frameNumber() const { return (version >= 4) ? frame_number : streamID; } inline int frameNumber() const { return (version >= 4) ? frame_number : streamID; }
inline size_t frameSetID() const { return (version >= 4) ? streamID : 0; } inline size_t frameSetID() const { return (version >= 4) ? streamID : 0; }
inline int64_t localTimestamp() const { return timestamp + originClockDelta; }
int64_t originClockDelta; // Not message packet / saved int64_t localTimestamp; // Not message packet / saved
unsigned int hint_capability; // Is this a video stream, for example unsigned int hint_capability; // Is this a video stream, for example
size_t hint_source_total; // Number of tracks per frame to expect size_t hint_source_total; // Number of tracks per frame to expect
int retry_count = 0; // Decode retry count int retry_count = 0; // Decode retry count
......
...@@ -88,6 +88,7 @@ std::shared_ptr<ftl::data::FrameSet> LocalBuilder::getNextFrameSet(int64_t ts) { ...@@ -88,6 +88,7 @@ std::shared_ptr<ftl::data::FrameSet> LocalBuilder::getNextFrameSet(int64_t ts) {
// Must lock to ensure no updates can happen here // Must lock to ensure no updates can happen here
UNIQUE_LOCK(fs->smtx, lk2); UNIQUE_LOCK(fs->smtx, lk2);
fs->changeTimestamp(ts); fs->changeTimestamp(ts);
fs->localTimestamp = ts;
fs->store(); fs->store();
//for (auto &f : fs->frames) { //for (auto &f : fs->frames) {
// f.store(); // f.store();
...@@ -421,6 +422,7 @@ std::shared_ptr<ftl::data::FrameSet> ForeignBuilder::_addFrameset(int64_t timest ...@@ -421,6 +422,7 @@ std::shared_ptr<ftl::data::FrameSet> ForeignBuilder::_addFrameset(int64_t timest
newf->count = 0; newf->count = 0;
newf->mask = 0; newf->mask = 0;
newf->localTimestamp = timestamp;
newf->clearFlags(); newf->clearFlags();
// Insertion sort by timestamp // Insertion sort by timestamp
......
...@@ -206,6 +206,7 @@ void File::_patchPackets(ftl::codecs::StreamPacket &spkt, ftl::codecs::Packet &p ...@@ -206,6 +206,7 @@ void File::_patchPackets(ftl::codecs::StreamPacket &spkt, ftl::codecs::Packet &p
} }
spkt.version = 5; spkt.version = 5;
spkt.localTimestamp = spkt.timestamp;
// Fix for flags corruption // Fix for flags corruption
if (pkt.data.size() == 0) { if (pkt.data.size() == 0) {
......
...@@ -169,7 +169,7 @@ bool Net::begin() { ...@@ -169,7 +169,7 @@ bool Net::begin() {
StreamPacket spkt = spkt_raw; StreamPacket spkt = spkt_raw;
// FIXME: see #335 // FIXME: see #335
//spkt.timestamp -= clock_adjust_; //spkt.timestamp -= clock_adjust_;
spkt.originClockDelta = clock_adjust_; spkt.localTimestamp = now - ttimeoff;
spkt.hint_capability = 0; spkt.hint_capability = 0;
spkt.hint_source_total = 0; spkt.hint_source_total = 0;
//LOG(INFO) << "LATENCY: " << ftl::timer::get_time() - spkt.localTimestamp() << " : " << spkt.timestamp << " - " << clock_adjust_; //LOG(INFO) << "LATENCY: " << ftl::timer::get_time() - spkt.localTimestamp() << " : " << spkt.timestamp << " - " << clock_adjust_;
......
...@@ -209,6 +209,7 @@ void Receiver::_processData(const StreamPacket &spkt, const Packet &pkt) { ...@@ -209,6 +209,7 @@ void Receiver::_processData(const StreamPacket &spkt, const Packet &pkt) {
//UNIQUE_LOCK(vidstate.mutex, lk); //UNIQUE_LOCK(vidstate.mutex, lk);
timestamp_ = spkt.timestamp; timestamp_ = spkt.timestamp;
fs->completed(spkt.frame_number); fs->completed(spkt.frame_number);
fs->localTimestamp = spkt.localTimestamp;
} }
/*const auto *cs = stream_; /*const auto *cs = stream_;
...@@ -258,6 +259,7 @@ void Receiver::_processAudio(const StreamPacket &spkt, const Packet &pkt) { ...@@ -258,6 +259,7 @@ void Receiver::_processAudio(const StreamPacket &spkt, const Packet &pkt) {
//UNIQUE_LOCK(vidstate.mutex, lk); //UNIQUE_LOCK(vidstate.mutex, lk);
timestamp_ = spkt.timestamp; timestamp_ = spkt.timestamp;
fs->completed(spkt.frame_number); fs->completed(spkt.frame_number);
fs->localTimestamp = spkt.localTimestamp;
} }
// Generate settings from packet data // Generate settings from packet data
...@@ -435,6 +437,7 @@ void Receiver::_processVideo(const StreamPacket &spkt, const Packet &pkt) { ...@@ -435,6 +437,7 @@ void Receiver::_processVideo(const StreamPacket &spkt, const Packet &pkt) {
UNIQUE_LOCK(vidstate.mutex, lk); UNIQUE_LOCK(vidstate.mutex, lk);
timestamp_ = spkt.timestamp; timestamp_ = spkt.timestamp;
fs->completed(spkt.frame_number+i); fs->completed(spkt.frame_number+i);
fs->localTimestamp = spkt.localTimestamp;
} }
} }
} }
...@@ -458,6 +461,7 @@ void Receiver::processPackets(const StreamPacket &spkt, const Packet &pkt) { ...@@ -458,6 +461,7 @@ void Receiver::processPackets(const StreamPacket &spkt, const Packet &pkt) {
//UNIQUE_LOCK(vidstate.mutex, lk); // FIXME: Should have a lock here... //UNIQUE_LOCK(vidstate.mutex, lk); // FIXME: Should have a lock here...
timestamp_ = spkt.timestamp; timestamp_ = spkt.timestamp;
fs->completed(frame.source()); fs->completed(frame.source());
fs->localTimestamp = spkt.localTimestamp;
} }
//if (frame.availableAll(sel)) { //if (frame.availableAll(sel)) {
......
...@@ -38,7 +38,7 @@ class FrameSet : public ftl::data::Frame { ...@@ -38,7 +38,7 @@ class FrameSet : public ftl::data::Frame {
//int id=0; //int id=0;
//int64_t timestamp; // Millisecond timestamp of all frames //int64_t timestamp; // Millisecond timestamp of all frames
int64_t originClockDelta; int64_t localTimestamp;
std::vector<Frame> frames; std::vector<Frame> frames;
std::atomic<int> count; // Number of valid frames std::atomic<int> count; // Number of valid frames
std::atomic<unsigned int> mask; // Mask of all sources that contributed std::atomic<unsigned int> mask; // Mask of all sources that contributed
...@@ -47,8 +47,6 @@ class FrameSet : public ftl::data::Frame { ...@@ -47,8 +47,6 @@ class FrameSet : public ftl::data::Frame {
//Eigen::Matrix4d pose; // Set to identity by default. //Eigen::Matrix4d pose; // Set to identity by default.
inline int64_t localTimestamp() const { return timestamp() + originClockDelta; }
inline void set(FSFlag f) { flags_ |= (1 << static_cast<int>(f)); } inline void set(FSFlag f) { flags_ |= (1 << static_cast<int>(f)); }
inline void clear(FSFlag f) { flags_ &= ~(1 << static_cast<int>(f)); } inline void clear(FSFlag f) { flags_ &= ~(1 << static_cast<int>(f)); }
inline bool test(FSFlag f) const { return flags_ & (1 << static_cast<int>(f)); } inline bool test(FSFlag f) const { return flags_ & (1 << static_cast<int>(f)); }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment