]> git.sesse.net Git - nageru/blobdiff - mixer.cpp
Add an exported metrics for number of connected clients.
[nageru] / mixer.cpp
index 857d62bf4fc2ab5367ba2bf1f3332fa2728fc616..4b45b511e686e91be148035deb62caeb7fbd4eb2 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -42,6 +42,7 @@
 #include "ffmpeg_capture.h"
 #include "flags.h"
 #include "input_mapping.h"
+#include "metrics.h"
 #include "pbo_frame_allocator.h"
 #include "ref_counted_gl_sync.h"
 #include "resampling_queue.h"
@@ -388,6 +389,10 @@ Mixer::Mixer(const QSurfaceFormat &format, unsigned num_cards)
                desired_output_card_index = global_flags.output_card;
                set_output_card_internal(global_flags.output_card);
        }
+
+       global_metrics.register_int_metric("num_frames", &metrics_num_frames);
+       global_metrics.register_int_metric("dropped_frames", &metrics_dropped_frames);
+       global_metrics.register_double_metric("uptime", &metrics_uptime);
 }
 
 Mixer::~Mixer()
@@ -427,7 +432,7 @@ void Mixer::configure_card(unsigned card_index, CaptureInterface *capture, CardT
 
        PixelFormat pixel_format;
        if (card_type == CardType::FFMPEG_INPUT) {
-               pixel_format = PixelFormat_8BitBGRA;
+               pixel_format = capture->get_current_pixel_format();
        } else if (global_flags.ten_bit_input) {
                pixel_format = PixelFormat_10BitYCbCr;
        } else {
@@ -643,6 +648,7 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode,
                // a deinterlacer to actually get this right.
                assert(video_format.height % 2 == 0);
                video_format.height /= 2;
+               cbcr_height /= 2;
                assert(frame_length % 2 == 0);
                frame_length /= 2;
                num_fields = 2;
@@ -714,6 +720,13 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode,
                        case PixelFormat_8BitBGRA: {
                                size_t field_start = video_offset + video_format.stride * field_start_line;
                                upload_texture(userdata->tex_rgba[field], video_format.width, video_format.height, video_format.stride, interlaced_stride, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, field_start);
+                               // These could be asked to deliver mipmaps at any time.
+                               glBindTexture(GL_TEXTURE_2D, userdata->tex_rgba[field]);
+                               check_error();
+                               glGenerateMipmap(GL_TEXTURE_2D);
+                               check_error();
+                               glBindTexture(GL_TEXTURE_2D, 0);
+                               check_error();
                                break;
                        }
                        default:
@@ -863,6 +876,11 @@ void Mixer::thread_func()
 
                now = steady_clock::now();
                double elapsed = duration<double>(now - start).count();
+
+               metrics_num_frames = frame_num;
+               metrics_dropped_frames = stats_dropped_frames;
+               metrics_uptime = elapsed;
+
                if (frame_num % 100 == 0) {
                        printf("%d frames (%d dropped) in %.3f seconds = %.1f fps (%.1f ms/frame)",
                                frame_num, stats_dropped_frames, elapsed, frame_num / elapsed,