1 #include "print_latency.h"
10 using namespace std::chrono;
12 ReceivedTimestamps find_received_timestamp(const vector<RefCountedFrame> &input_frames)
14 // Find min and max timestamp of all input frames that have a timestamp.
15 steady_clock::time_point min_ts = steady_clock::time_point::max(), max_ts = steady_clock::time_point::min();
16 for (const RefCountedFrame &input_frame : input_frames) {
17 if (input_frame && input_frame->received_timestamp > steady_clock::time_point::min()) {
18 min_ts = min(min_ts, input_frame->received_timestamp);
19 max_ts = max(max_ts, input_frame->received_timestamp);
22 return { min_ts, max_ts };
25 void print_latency(const string &header, const ReceivedTimestamps &received_ts, bool is_b_frame, int *frameno)
27 if (received_ts.max_ts == steady_clock::time_point::min())
30 // 101 is chosen so that it's prime, which is unlikely to get the same frame type every time.
31 if (global_flags.print_video_latency && (++*frameno % 101) == 0) {
32 const steady_clock::time_point now = steady_clock::now();
33 printf("%-60s %4.0f ms (lowest-latency input), %4.0f ms (highest-latency input)",
35 1e3 * std::chrono::duration<double>(now - received_ts.max_ts).count(),
36 1e3 * std::chrono::duration<double>(now - received_ts.min_ts).count());
39 printf(" [on B-frame; potential extra latency]\n");