X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=print_latency.cpp;fp=print_latency.cpp;h=0b0a1ae483e9bb2ce3ce6df15413942f89870b82;hb=63a912898083c06cc75f336f8d9a367a707e378a;hp=0000000000000000000000000000000000000000;hpb=112ce67402abfb6163403697c8a4f0fb736101ca;p=nageru diff --git a/print_latency.cpp b/print_latency.cpp new file mode 100644 index 0000000..0b0a1ae --- /dev/null +++ b/print_latency.cpp @@ -0,0 +1,30 @@ +#include "print_latency.h" +#include "flags.h" + +#include +#include +#include + +using namespace std; +using namespace std::chrono; + +void print_latency(const string &header, const ReceivedTimestamps &received_ts, bool is_b_frame, int *frameno) +{ + if (received_ts.max_ts == steady_clock::time_point::min()) + return; + + // 101 is chosen so that it's prime, which is unlikely to get the same frame type every time. + if (global_flags.print_video_latency && (++*frameno % 101) == 0) { + const steady_clock::time_point now = steady_clock::now(); + printf("%-60s %4.0f ms (lowest-latency input), %4.0f ms (highest-latency input)", + header.c_str(), + 1e3 * std::chrono::duration(now - received_ts.max_ts).count(), + 1e3 * std::chrono::duration(now - received_ts.min_ts).count()); + + if (is_b_frame) { + printf(" [on B-frame; potential extra latency]\n"); + } else { + printf("\n"); + } + } +}