]> git.sesse.net Git - nageru/blobdiff - kaeru.cpp
Add latency metrics to Kaeru.
[nageru] / kaeru.cpp
index c41a4c2323dec4b21b8188575e9229f5d9bd8b31..23b3c8786ce4ae0336d60f3cdcd85305d4b6a788 100644 (file)
--- a/kaeru.cpp
+++ b/kaeru.cpp
 #include <fcntl.h>
 #include <signal.h>
 #include <unistd.h>
+#include <chrono>
 #include <string>
 
 using namespace bmusb;
 using namespace movit;
 using namespace std;
+using namespace std::chrono;
 using namespace std::placeholders;
 
 Mixer *global_mixer = nullptr;
@@ -76,9 +78,12 @@ void video_frame_callback(FFmpegCapture *video, X264Encoder *x264_encoder, Audio
                          FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format)
 {
        if (video_pts >= 0 && video_frame.len > 0) {
+               ReceivedTimestamps ts;
+               ts.ts.push_back(steady_clock::now());
+
                video_pts = av_rescale_q(video_pts, video_timebase, AVRational{ 1, TIMEBASE });
                int64_t frame_duration = TIMEBASE * video_format.frame_rate_nom / video_format.frame_rate_den;
-               x264_encoder->add_frame(video_pts, frame_duration, video->get_current_frame_ycbcr_format().luma_coefficients, video_frame.data + video_offset, ReceivedTimestamps());
+               x264_encoder->add_frame(video_pts, frame_duration, video->get_current_frame_ycbcr_format().luma_coefficients, video_frame.data + video_offset, ts);
        }
        if (audio_frame.len > 0) {
                // FFmpegCapture takes care of this for us.
@@ -154,6 +159,7 @@ int main(int argc, char *argv[])
                usage(PROGRAM_KAERU);
                exit(1);
        }
+       global_flags.num_cards = 1;  // For latency metrics.
 
        av_register_all();
        avformat_network_init();