]> git.sesse.net Git - nageru/blob - print_latency.cpp
Add a switch to print video latency.
[nageru] / print_latency.cpp
1 #include "print_latency.h"
2 #include "flags.h"
3
4 #include <stdio.h>
5 #include <chrono>
6 #include <string>
7
8 using namespace std;
9 using namespace std::chrono;
10
11 void print_latency(const string &header, const ReceivedTimestamps &received_ts, bool is_b_frame, int *frameno)
12 {
13         if (received_ts.max_ts == steady_clock::time_point::min())
14                 return;
15
16         // 101 is chosen so that it's prime, which is unlikely to get the same frame type every time.
17         if (global_flags.print_video_latency && (++*frameno % 101) == 0) {
18                 const steady_clock::time_point now = steady_clock::now();
19                 printf("%-60s %4.0f ms (lowest-latency input), %4.0f ms (highest-latency input)",
20                         header.c_str(),
21                         1e3 * std::chrono::duration<double>(now - received_ts.max_ts).count(),
22                         1e3 * std::chrono::duration<double>(now - received_ts.min_ts).count());
23
24                 if (is_b_frame) {
25                         printf("  [on B-frame; potential extra latency]\n");
26                 } else {
27                         printf("\n");
28                 }
29         }
30 }