]> git.sesse.net Git - nageru/blob - print_latency.h
Fix an issue where the mixer lagging too much behind CEF would cause us to display...
[nageru] / print_latency.h
1 #ifndef _PRINT_LATENCY_H
2 #define _PRINT_LATENCY_H 1
3
4 // A small utility function to print the latency between two end points
5 // (typically when the frame was received from the video card, and some
6 // point when the frame is ready to be output in some form).
7
8 #include <chrono>
9 #include <string>
10 #include <vector>
11
12 #include "ref_counted_frame.h"
13 #include "metrics.h"
14
15 // Since every output frame is based on multiple input frames, we need
16 // more than one start timestamp; one for each input.
17 // For all of these, steady_clock::time_point::min() is used for “not set”.
18 struct ReceivedTimestamps {
19         std::vector<std::chrono::steady_clock::time_point> ts;
20 };
21 struct LatencyHistogram {
22         void init(const std::string &measuring_point);  // Initializes histograms and registers them in global_metrics.
23
24         // Indices: card number, frame history number, b-frame or not (1/0, where 2 counts both).
25         std::vector<std::vector<std::unique_ptr<Summary[]>>> summaries;
26 };
27
28 ReceivedTimestamps find_received_timestamp(const std::vector<RefCountedFrame> &input_frames);
29
30 void print_latency(const char *header, const ReceivedTimestamps &received_ts, bool is_b_frame, int *frameno, LatencyHistogram *histogram);
31
32 #endif  // !defined(_PRINT_LATENCY_H)