]> git.sesse.net Git - nageru/blobdiff - nageru/mixer.cpp
IWYU-fix nageru/*.cpp.
[nageru] / nageru / mixer.cpp
index 2fdbf645e876d89cc39022a411d75f2e92016ba3..b3e60feba560a261d25e63b2fc2fc42c99505bc3 100644 (file)
@@ -1,9 +1,16 @@
-#undef Success
-
 #include "mixer.h"
 
+#include <X11/Xlib.h>
+#include <algorithm>
 #include <assert.h>
+#include <chrono>
+#include <condition_variable>
 #include <epoxy/egl.h>
+#include <functional>
+#include <iterator>
+#include <map>
+#include <math.h>
+#include <memory>
 #include <movit/effect.h>
 #include <movit/effect_chain.h>
 #include <movit/effect_util.h>
 #include <movit/image_format.h>
 #include <movit/init.h>
 #include <movit/resource_pool.h>
+#include <movit/util.h>
+#include <movit/ycbcr.h>
+#include <movit/ycbcr_input.h>
+#include <mutex>
+#include <netinet/in.h>
 #include <pthread.h>
+#include <stddef.h>
+#include <stdint.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <algorithm>
-#include <chrono>
-#include <condition_variable>
-#include <cstddef>
-#include <cstdint>
-#include <memory>
-#include <mutex>
-#include <ratio>
+#include <string.h>
 #include <string>
+#include <sys/socket.h>
+#include <sys/syslog.h>
 #include <thread>
 #include <utility>
 #include <vector>
 #include "DeckLinkAPI.h"
 #include "LinuxCOM.h"
 #include "alsa_output.h"
+#include "audio_mixer.h"
 #include "basic_stats.h"
 #include "bmusb/bmusb.h"
 #include "bmusb/fake_capture.h"
 #ifdef HAVE_CEF
+#undef LOG_INFO
+#undef LOG_WARNING
 #include "cef_capture.h"
 #endif
+#include "card_type.h"
 #include "chroma_subsampler.h"
-#include "shared/context.h"
 #include "decklink_capture.h"
 #include "decklink_output.h"
 #include "decklink_util.h"
 #include "defs.h"
-#include "shared/disk_space_estimator.h"
 #include "ffmpeg_capture.h"
 #include "flags.h"
 #include "image_input.h"
 #include "input_mapping.h"
-#include "shared/metrics.h"
-#include "shared/va_display.h"
+#include "input_state.h"
+#include "libusb.h"
 #include "mjpeg_encoder.h"
 #include "pbo_frame_allocator.h"
-#include "shared/ref_counted_gl_sync.h"
+#include "queue_length_policy.h"
 #include "resampling_queue.h"
+#include "shared/context.h"
+#include "shared/disk_space_estimator.h"
+#include "shared/metrics.h"
+#include "shared/ref_counted_gl_sync.h"
+#include "shared/shared_defs.h"
 #include "shared/timebase.h"
+#include "theme.h"
 #include "timecode_renderer.h"
 #include "v210_converter.h"
 #include "video_encoder.h"
+#include "ycbcr_interpretation.h"
 
 #undef Status
 #include <google/protobuf/util/json_util.h>
@@ -124,7 +142,7 @@ void ensure_texture_resolution(PBOFrameAllocator::Userdata *userdata, unsigned f
                cbcr_width != userdata->last_cbcr_width[field] ||
                cbcr_height != userdata->last_cbcr_height[field];
        const bool recreate_v210_texture =
-               global_flags.ten_bit_input &&
+               global_flags.bit_depth > 8 &&
                (first || v210_width != userdata->last_v210_width[field] || height != userdata->last_height[field]);
 
        if (recreate_main_texture) {
@@ -234,6 +252,16 @@ void JitterHistory::unregister_metrics(const vector<pair<string, string>> &label
 
 void JitterHistory::frame_arrived(steady_clock::time_point now, int64_t frame_duration, size_t dropped_frames)
 {
+       if (frame_duration != last_duration) {
+               // If the frame rate changed, the input clock is also going to change,
+               // so our historical data doesn't make much sense anymore.
+               // Also, format changes typically introduce blips that are not representative
+               // of the typical frame stream. (We make the assumption that format changes
+               // don't happen all the time in regular use; if they did, we should probably
+               // rather keep the history so that we take jitter they may introduce into account.)
+               clear();
+               last_duration = frame_duration;
+       }
        if (expected_timestamp > steady_clock::time_point::min()) {
                expected_timestamp += dropped_frames * nanoseconds(frame_duration * 1000000000 / TIMEBASE);
                double jitter_seconds = fabs(duration<double>(expected_timestamp - now).count());
@@ -354,7 +382,7 @@ Mixer::Mixer(const QSurfaceFormat &format)
                ycbcr_format.luma_coefficients = YCBCR_REC_601;
        }
        ycbcr_format.full_range = false;
-       ycbcr_format.num_levels = 1 << global_flags.x264_bit_depth;
+       ycbcr_format.num_levels = 1 << global_flags.bit_depth;
        ycbcr_format.cb_x_position = 0.0f;
        ycbcr_format.cr_x_position = 0.0f;
        ycbcr_format.cb_y_position = 0.5f;
@@ -368,7 +396,7 @@ Mixer::Mixer(const QSurfaceFormat &format)
        // Display chain; shows the live output produced by the main chain (or rather, a copy of it).
        display_chain.reset(new EffectChain(global_flags.width, global_flags.height, resource_pool.get()));
        check_error();
-       GLenum type = global_flags.x264_bit_depth > 8 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE;
+       GLenum type = global_flags.bit_depth > 8 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE;
        display_input = new YCbCrInput(inout_format, ycbcr_format, global_flags.width, global_flags.height, YCBCR_INPUT_SPLIT_Y_AND_CBCR, type);
        display_chain->add_input(display_input);
        display_chain->add_output(inout_format, OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED);
@@ -419,7 +447,7 @@ Mixer::Mixer(const QSurfaceFormat &format)
 
                                DeckLinkCapture *capture = new DeckLinkCapture(decklink, card_index);
                                DeckLinkOutput *output = new DeckLinkOutput(resource_pool.get(), decklink_output_surface, global_flags.width, global_flags.height, card_index);
-                               if (!output->set_device(decklink)) {
+                               if (!output->set_device(decklink, capture->get_input())) {
                                        delete output;
                                        output = nullptr;
                                }
@@ -501,7 +529,7 @@ Mixer::Mixer(const QSurfaceFormat &format)
 
        chroma_subsampler.reset(new ChromaSubsampler(resource_pool.get()));
 
-       if (global_flags.ten_bit_input) {
+       if (global_flags.bit_depth > 8) {
                if (!v210Converter::has_hardware_support()) {
                        fprintf(stderr, "ERROR: --ten-bit-input requires support for OpenGL compute shaders\n");
                        fprintf(stderr, "       (OpenGL 4.3, or GL_ARB_compute_shader + GL_ARB_shader_image_load_store).\n");
@@ -518,7 +546,7 @@ Mixer::Mixer(const QSurfaceFormat &format)
                v210_converter->precompile_shader(3840);
                v210_converter->precompile_shader(4096);
        }
-       if (global_flags.ten_bit_output) {
+       if (global_flags.bit_depth > 8) {
                if (!v210Converter::has_hardware_support()) {
                        fprintf(stderr, "ERROR: --ten-bit-output requires support for OpenGL compute shaders\n");
                        fprintf(stderr, "       (OpenGL 4.3, or GL_ARB_compute_shader + GL_ARB_shader_image_load_store).\n");
@@ -533,6 +561,7 @@ Mixer::Mixer(const QSurfaceFormat &format)
        if (global_flags.enable_alsa_output) {
                alsa.reset(new ALSAOutput(OUTPUT_FREQUENCY, /*num_channels=*/2));
        }
+       output_card_is_master = global_flags.output_card_is_master;
        if (global_flags.output_card != -1) {
                desired_output_card_index = global_flags.output_card;
                set_output_card_internal(global_flags.output_card);
@@ -569,9 +598,7 @@ Mixer::~Mixer()
 void Mixer::configure_card(unsigned card_index, CaptureInterface *capture, CardType card_type, DeckLinkOutput *output, bool is_srt_card)
 {
        bool is_active = capture != nullptr;
-       if (is_active) {
-               printf("Configuring card %d...\n", card_index);
-       } else {
+       if (!is_active) {
                assert(card_type == CardType::FAKE_CAPTURE);
        }
 
@@ -598,7 +625,7 @@ void Mixer::configure_card(unsigned card_index, CaptureInterface *capture, CardT
                pixel_format = capture->get_current_pixel_format();
        } else if (card_type == CardType::CEF_INPUT) {
                pixel_format = PixelFormat_8BitBGRA;
-       } else if (global_flags.ten_bit_input) {
+       } else if (global_flags.bit_depth > 8) {
                pixel_format = PixelFormat_10BitYCbCr;
        } else {
                pixel_format = PixelFormat_8BitYCbCr;
@@ -607,7 +634,7 @@ void Mixer::configure_card(unsigned card_index, CaptureInterface *capture, CardT
        if (is_active) {
                card->capture->set_frame_callback(bind(&Mixer::bm_frame, this, card_index, _1, _2, _3, _4, _5, _6, _7));
                if (card->frame_allocator == nullptr) {
-                       card->frame_allocator.reset(new PBOFrameAllocator(pixel_format, 8 << 20, global_flags.width, global_flags.height, card_index, mjpeg_encoder.get()));  // 8 MB.
+                       card->frame_allocator.reset(new PBOFrameAllocator(pixel_format, FRAME_SIZE, global_flags.width, global_flags.height, card_index, mjpeg_encoder.get()));
                } else {
                        // The format could have changed, but we cannot reset the allocator
                        // and create a new one from scratch, since there may be allocated
@@ -616,7 +643,7 @@ void Mixer::configure_card(unsigned card_index, CaptureInterface *capture, CardT
                        // any old ones as they come back. This takes the mutex while
                        // allocating, but nothing should really be sending frames in there
                        // right now anyway (start_bm_capture() has not been called yet).
-                       card->frame_allocator->reconfigure(pixel_format, 8 << 20, global_flags.width, global_flags.height, card_index, mjpeg_encoder.get());
+                       card->frame_allocator->reconfigure(pixel_format, FRAME_SIZE, global_flags.width, global_flags.height, card_index, mjpeg_encoder.get());
                }
                card->capture->set_video_frame_allocator(card->frame_allocator.get());
                if (card->surface == nullptr) {
@@ -668,71 +695,7 @@ void Mixer::configure_card(unsigned card_index, CaptureInterface *capture, CardT
                global_metrics.remove_if_exists("input_frame_rate_den", labels);
                global_metrics.remove_if_exists("input_sample_rate_hz", labels);
 
-               // SRT metrics.
-
-               // Global measurements (counters).
-               global_metrics.remove_if_exists("srt_uptime_seconds", labels);
-               global_metrics.remove_if_exists("srt_send_duration_seconds", labels);
-               global_metrics.remove_if_exists("srt_sent_bytes", labels);
-               global_metrics.remove_if_exists("srt_received_bytes", labels);
-
-               vector<pair<string, string>> packet_labels = card->labels;
-               packet_labels.emplace_back("type", "normal");
-               global_metrics.remove_if_exists("srt_sent_packets", packet_labels);
-               global_metrics.remove_if_exists("srt_received_packets", packet_labels);
-
-               packet_labels.back().second = "lost";
-               global_metrics.remove_if_exists("srt_sent_packets", packet_labels);
-               global_metrics.remove_if_exists("srt_received_packets", packet_labels);
-
-               packet_labels.back().second = "retransmitted";
-               global_metrics.remove_if_exists("srt_sent_packets", packet_labels);
-               global_metrics.remove_if_exists("srt_sent_bytes", packet_labels);
-
-               packet_labels.back().second = "ack";
-               global_metrics.remove_if_exists("srt_sent_packets", packet_labels);
-               global_metrics.remove_if_exists("srt_received_packets", packet_labels);
-
-               packet_labels.back().second = "nak";
-               global_metrics.remove_if_exists("srt_sent_packets", packet_labels);
-               global_metrics.remove_if_exists("srt_received_packets", packet_labels);
-
-               packet_labels.back().second = "dropped";
-               global_metrics.remove_if_exists("srt_sent_packets", packet_labels);
-               global_metrics.remove_if_exists("srt_received_packets", packet_labels);
-               global_metrics.remove_if_exists("srt_sent_bytes", packet_labels);
-               global_metrics.remove_if_exists("srt_received_bytes", packet_labels);
-
-               packet_labels.back().second = "undecryptable";
-               global_metrics.remove_if_exists("srt_received_packets", packet_labels);
-               global_metrics.remove_if_exists("srt_received_bytes", packet_labels);
-
-               global_metrics.remove_if_exists("srt_filter_sent_extra_packets", labels);
-               global_metrics.remove_if_exists("srt_filter_received_extra_packets", labels);
-               global_metrics.remove_if_exists("srt_filter_received_rebuilt_packets", labels);
-               global_metrics.remove_if_exists("srt_filter_received_lost_packets", labels);
-
-               // Instant measurements (gauges).
-               global_metrics.remove_if_exists("srt_packet_sending_period_seconds", labels);
-               global_metrics.remove_if_exists("srt_flow_window_packets", labels);
-               global_metrics.remove_if_exists("srt_congestion_window_packets", labels);
-               global_metrics.remove_if_exists("srt_flight_size_packets", labels);
-               global_metrics.remove_if_exists("srt_rtt_seconds", labels);
-               global_metrics.remove_if_exists("srt_estimated_bandwidth_bits_per_second", labels);
-               global_metrics.remove_if_exists("srt_bandwidth_ceiling_bits_per_second", labels);
-               global_metrics.remove_if_exists("srt_send_buffer_available_bytes", labels);
-               global_metrics.remove_if_exists("srt_receive_buffer_available_bytes", labels);
-               global_metrics.remove_if_exists("srt_mss_bytes", labels);
-
-               global_metrics.remove_if_exists("srt_sender_unacked_packets", labels);
-               global_metrics.remove_if_exists("srt_sender_unacked_bytes", labels);
-               global_metrics.remove_if_exists("srt_sender_unacked_timespan_seconds", labels);
-               global_metrics.remove_if_exists("srt_sender_delivery_delay_seconds", labels);
-
-               global_metrics.remove_if_exists("srt_receiver_unacked_packets", labels);
-               global_metrics.remove_if_exists("srt_receiver_unacked_bytes", labels);
-               global_metrics.remove_if_exists("srt_receiver_unacked_timespan_seconds", labels);
-               global_metrics.remove_if_exists("srt_receiver_delivery_delay_seconds", labels);
+               card->srt_metrics.deinit(labels);
        }
 
        if (is_active) {
@@ -781,69 +744,7 @@ void Mixer::configure_card(unsigned card_index, CaptureInterface *capture, CardT
                global_metrics.add("input_sample_rate_hz", labels, &card->metric_input_sample_rate_hz, Metrics::TYPE_GAUGE);
 
                if (is_srt_card) {
-                       // Global measurements (counters).
-                       global_metrics.add("srt_uptime_seconds", labels, &card->metric_srt_uptime_seconds);
-                       global_metrics.add("srt_send_duration_seconds", labels, &card->metric_srt_send_duration_seconds);
-                       global_metrics.add("srt_sent_bytes", labels, &card->metric_srt_sent_bytes);
-                       global_metrics.add("srt_received_bytes", labels, &card->metric_srt_received_bytes);
-
-                       vector<pair<string, string>> packet_labels = labels;
-                       packet_labels.emplace_back("type", "normal");
-                       global_metrics.add("srt_sent_packets", packet_labels, &card->metric_srt_sent_packets_normal);
-                       global_metrics.add("srt_received_packets", packet_labels, &card->metric_srt_received_packets_normal);
-
-                       packet_labels.back().second = "lost";
-                       global_metrics.add("srt_sent_packets", packet_labels, &card->metric_srt_sent_packets_lost);
-                       global_metrics.add("srt_received_packets", packet_labels, &card->metric_srt_received_packets_lost);
-
-                       packet_labels.back().second = "retransmitted";
-                       global_metrics.add("srt_sent_packets", packet_labels, &card->metric_srt_sent_packets_retransmitted);
-                       global_metrics.add("srt_sent_bytes", packet_labels, &card->metric_srt_sent_bytes_retransmitted);
-
-                       packet_labels.back().second = "ack";
-                       global_metrics.add("srt_sent_packets", packet_labels, &card->metric_srt_sent_packets_ack);
-                       global_metrics.add("srt_received_packets", packet_labels, &card->metric_srt_received_packets_ack);
-
-                       packet_labels.back().second = "nak";
-                       global_metrics.add("srt_sent_packets", packet_labels, &card->metric_srt_sent_packets_nak);
-                       global_metrics.add("srt_received_packets", packet_labels, &card->metric_srt_received_packets_nak);
-
-                       packet_labels.back().second = "dropped";
-                       global_metrics.add("srt_sent_packets", packet_labels, &card->metric_srt_sent_packets_dropped);
-                       global_metrics.add("srt_received_packets", packet_labels, &card->metric_srt_received_packets_dropped);
-                       global_metrics.add("srt_sent_bytes", packet_labels, &card->metric_srt_sent_bytes_dropped);
-                       global_metrics.add("srt_received_bytes", packet_labels, &card->metric_srt_received_bytes_dropped);
-
-                       packet_labels.back().second = "undecryptable";
-                       global_metrics.add("srt_received_packets", packet_labels, &card->metric_srt_received_packets_undecryptable);
-                       global_metrics.add("srt_received_bytes", packet_labels, &card->metric_srt_received_bytes_undecryptable);
-
-                       global_metrics.add("srt_filter_sent_extra_packets", labels, &card->metric_srt_filter_sent_packets);
-                       global_metrics.add("srt_filter_received_extra_packets", labels, &card->metric_srt_filter_received_extra_packets);
-                       global_metrics.add("srt_filter_received_rebuilt_packets", labels, &card->metric_srt_filter_received_rebuilt_packets);
-                       global_metrics.add("srt_filter_received_lost_packets", labels, &card->metric_srt_filter_received_lost_packets);
-
-                       // Instant measurements (gauges).
-                       global_metrics.add("srt_packet_sending_period_seconds", labels, &card->metric_srt_packet_sending_period_seconds, Metrics::TYPE_GAUGE);
-                       global_metrics.add("srt_flow_window_packets", labels, &card->metric_srt_flow_window_packets, Metrics::TYPE_GAUGE);
-                       global_metrics.add("srt_congestion_window_packets", labels, &card->metric_srt_congestion_window_packets, Metrics::TYPE_GAUGE);
-                       global_metrics.add("srt_flight_size_packets", labels, &card->metric_srt_flight_size_packets, Metrics::TYPE_GAUGE);
-                       global_metrics.add("srt_rtt_seconds", labels, &card->metric_srt_rtt_seconds, Metrics::TYPE_GAUGE);
-                       global_metrics.add("srt_estimated_bandwidth_bits_per_second", labels, &card->metric_srt_estimated_bandwidth_bits_per_second, Metrics::TYPE_GAUGE);
-                       global_metrics.add("srt_bandwidth_ceiling_bits_per_second", labels, &card->metric_srt_bandwidth_ceiling_bits_per_second, Metrics::TYPE_GAUGE);
-                       global_metrics.add("srt_send_buffer_available_bytes", labels, &card->metric_srt_send_buffer_available_bytes, Metrics::TYPE_GAUGE);
-                       global_metrics.add("srt_receive_buffer_available_bytes", labels, &card->metric_srt_receive_buffer_available_bytes, Metrics::TYPE_GAUGE);
-                       global_metrics.add("srt_mss_bytes", labels, &card->metric_srt_mss_bytes, Metrics::TYPE_GAUGE);
-
-                       global_metrics.add("srt_sender_unacked_packets", labels, &card->metric_srt_sender_unacked_packets, Metrics::TYPE_GAUGE);
-                       global_metrics.add("srt_sender_unacked_bytes", labels, &card->metric_srt_sender_unacked_bytes, Metrics::TYPE_GAUGE);
-                       global_metrics.add("srt_sender_unacked_timespan_seconds", labels, &card->metric_srt_sender_unacked_timespan_seconds, Metrics::TYPE_GAUGE);
-                       global_metrics.add("srt_sender_delivery_delay_seconds", labels, &card->metric_srt_sender_delivery_delay_seconds, Metrics::TYPE_GAUGE);
-
-                       global_metrics.add("srt_receiver_unacked_packets", labels, &card->metric_srt_receiver_unacked_packets, Metrics::TYPE_GAUGE);
-                       global_metrics.add("srt_receiver_unacked_bytes", labels, &card->metric_srt_receiver_unacked_bytes, Metrics::TYPE_GAUGE);
-                       global_metrics.add("srt_receiver_unacked_timespan_seconds", labels, &card->metric_srt_receiver_unacked_timespan_seconds, Metrics::TYPE_GAUGE);
-                       global_metrics.add("srt_receiver_delivery_delay_seconds", labels, &card->metric_srt_receiver_delivery_delay_seconds, Metrics::TYPE_GAUGE);
+                       card->srt_metrics.init(labels);
                }
 
                card->labels = labels;
@@ -889,7 +790,7 @@ void Mixer::set_output_card_internal(int card_index)
                card->jitter_history.clear();
                card->capture->start_bm_capture();
                desired_output_video_mode = output_video_mode = card->output->pick_video_mode(desired_output_video_mode);
-               card->output->start_output(desired_output_video_mode, pts_int);
+               card->output->start_output(desired_output_video_mode, pts_int, /*is_master_card=*/output_card_is_master);
        }
        output_card_index = card_index;
        output_jitter_history.clear();
@@ -970,7 +871,7 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode,
        // (Could be nonintegral, but resampling will save us then.)
        const int silence_samples = OUTPUT_FREQUENCY * video_format.frame_rate_den / video_format.frame_rate_nom;
 
-       if (dropped_frames > MAX_FPS * 2) {
+       if (dropped_frames > TYPICAL_FPS * 2) {
                fprintf(stderr, "%s lost more than two seconds (or time code jumping around; from 0x%04x to 0x%04x), resetting resampler\n",
                        description_for_card(card_index).c_str(), card->last_timecode, timecode);
                audio_mixer->reset_resampler(device);
@@ -1038,7 +939,7 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode,
        if (card->type == CardType::FFMPEG_INPUT) {
                int srt_sock = static_cast<FFmpegCapture *>(card->capture.get())->get_srt_sock();
                if (srt_sock != -1) {
-                       update_srt_stats(srt_sock, card);
+                       card->srt_metrics.update_srt_stats(srt_sock);
                }
        }
 #endif
@@ -1276,7 +1177,7 @@ void Mixer::thread_func()
                        DeckLinkOutput *output = cards[output_card_index].output.get();
                        output->end_output();
                        desired_output_video_mode = output_video_mode = output->pick_video_mode(desired_output_video_mode);
-                       output->start_output(desired_output_video_mode, pts_int);
+                       output->start_output(desired_output_video_mode, pts_int, /*is_master_card=*/output_card_is_master);
                }
 
                {
@@ -1289,7 +1190,7 @@ void Mixer::thread_func()
 
                bool master_card_is_output;
                unsigned master_card_index;
-               if (output_card_index != -1) {
+               if (output_card_index != -1 && output_card_is_master) {
                        master_card_is_output = true;
                        master_card_index = output_card_index;
                } else {
@@ -1396,7 +1297,7 @@ void Mixer::thread_func()
 
 bool Mixer::input_card_is_master_clock(unsigned card_index, unsigned master_card_index) const
 {
-       if (output_card_index != -1) {
+       if (output_card_index != -1 && output_card_is_master) {
                // The output card (ie., cards[output_card_index].output) is the master clock,
                // so no input card (ie., cards[card_index].capture) is.
                return false;
@@ -1715,7 +1616,7 @@ void Mixer::handle_hotplugged_cards()
                        FFmpegCapture *capture = new FFmpegCapture(sock, stream_id);
                        capture->set_card_index(free_card_index);
                        configure_card(free_card_index, capture, CardType::FFMPEG_INPUT, /*output=*/nullptr, /*is_srt_card=*/true);
-                       update_srt_stats(sock, card);  // Initial zero stats.
+                       card->srt_metrics.update_srt_stats(sock);  // Initial zero stats.
                        card->last_srt_stream_id = stream_id;
                        card->jitter_history.clear();
                        capture->set_card_disconnected_callback(bind(&Mixer::bm_hotplug_remove, this, free_card_index));
@@ -1810,7 +1711,7 @@ void Mixer::render_one_frame(int64_t duration)
        output_ycbcr_format.chroma_subsampling_y = 1;
        output_ycbcr_format.luma_coefficients = ycbcr_output_coefficients;
        output_ycbcr_format.full_range = false;
-       output_ycbcr_format.num_levels = 1 << global_flags.x264_bit_depth;
+       output_ycbcr_format.num_levels = 1 << global_flags.bit_depth;
        chain->change_ycbcr_output_format(output_ycbcr_format);
 
        // Render main chain. If we're using zerocopy Quick Sync encoding
@@ -1823,8 +1724,8 @@ void Mixer::render_one_frame(int64_t duration)
        GLuint y_tex, cbcr_full_tex, cbcr_tex;
        GLuint y_copy_tex, cbcr_copy_tex = 0;
        GLuint y_display_tex, cbcr_display_tex;
-       GLenum y_type = (global_flags.x264_bit_depth > 8) ? GL_R16 : GL_R8;
-       GLenum cbcr_type = (global_flags.x264_bit_depth > 8) ? GL_RG16 : GL_RG8;
+       GLenum y_type = (global_flags.bit_depth > 8) ? GL_R16 : GL_R8;
+       GLenum cbcr_type = (global_flags.bit_depth > 8) ? GL_RG16 : GL_RG8;
        const bool is_zerocopy = video_encoder->is_zerocopy();
        if (is_zerocopy) {
                cbcr_full_tex = resource_pool->create_2d_texture(cbcr_type, global_flags.width, global_flags.height);
@@ -2016,7 +1917,7 @@ void Mixer::set_input_ycbcr_interpretation(unsigned card_index, const YCbCrInter
 void Mixer::start_mode_scanning(unsigned card_index)
 {
        assert(card_index < MAX_VIDEO_CARDS);
-       if (cards[card_index].capture != nullptr) {
+       if (cards[card_index].capture == nullptr) {
                // Inactive card. Should never happen.
                return;
        }
@@ -2191,7 +2092,13 @@ void Mixer::start_srt()
        addr.sin6_family = AF_INET6;
        addr.sin6_port = htons(global_flags.srt_port);
 
-       int err = srt_bind(sock, (sockaddr *)&addr, sizeof(addr));
+       int zero = 0;
+       int err = srt_setsockopt(sock, /*level=*/0, SRTO_IPV6ONLY, &zero, sizeof(zero));
+       if (err != 0) {
+               fprintf(stderr, "srt_setsockopt(SRTO_IPV6ONLY): %s\n", srt_getlasterror_str());
+               abort();
+       }
+       err = srt_bind(sock, (sockaddr *)&addr, sizeof(addr));
        if (err != 0) {
                fprintf(stderr, "srt_bind: %s\n", srt_getlasterror_str());
                abort();
@@ -2227,59 +2134,6 @@ void Mixer::start_srt()
 }
 #endif
 
-#ifdef HAVE_SRT
-void Mixer::update_srt_stats(int srt_sock, Mixer::CaptureCard *card)
-{
-       SRT_TRACEBSTATS stats;
-       srt_bistats(srt_sock, &stats, /*clear=*/0, /*instantaneous=*/1);
-
-       card->metric_srt_uptime_seconds = stats.msTimeStamp * 1e-3;
-       card->metric_srt_send_duration_seconds = stats.usSndDurationTotal * 1e-6;
-       card->metric_srt_sent_bytes = stats.byteSentTotal;
-       card->metric_srt_received_bytes = stats.byteRecvTotal;
-       card->metric_srt_sent_packets_normal = stats.pktSentTotal;
-       card->metric_srt_received_packets_normal = stats.pktRecvTotal;
-       card->metric_srt_sent_packets_lost = stats.pktSndLossTotal;
-       card->metric_srt_received_packets_lost = stats.pktRcvLossTotal;
-       card->metric_srt_sent_packets_retransmitted = stats.pktRetransTotal;
-       card->metric_srt_sent_bytes_retransmitted = stats.byteRetransTotal;
-       card->metric_srt_sent_packets_ack = stats.pktSentACKTotal;
-       card->metric_srt_received_packets_ack = stats.pktRecvACKTotal;
-       card->metric_srt_sent_packets_nak = stats.pktSentNAKTotal;
-       card->metric_srt_received_packets_nak = stats.pktRecvNAKTotal;
-       card->metric_srt_sent_packets_dropped = stats.pktSndDropTotal;
-       card->metric_srt_received_packets_dropped = stats.pktRcvDropTotal;
-       card->metric_srt_sent_bytes_dropped = stats.byteSndDropTotal;
-       card->metric_srt_received_bytes_dropped = stats.byteRcvDropTotal;
-       card->metric_srt_received_packets_undecryptable = stats.pktRcvUndecryptTotal;
-       card->metric_srt_received_bytes_undecryptable = stats.byteRcvUndecryptTotal;
-       card->metric_srt_filter_sent_packets = stats.pktSndFilterExtraTotal;
-       card->metric_srt_filter_received_extra_packets = stats.pktRcvFilterExtraTotal;
-       card->metric_srt_filter_received_rebuilt_packets = stats.pktRcvFilterSupplyTotal;
-       card->metric_srt_filter_received_lost_packets = stats.pktRcvFilterLossTotal;
-
-       // Gauges.
-       card->metric_srt_packet_sending_period_seconds = stats.usPktSndPeriod * 1e-6;
-       card->metric_srt_flow_window_packets = stats.pktFlowWindow;
-       card->metric_srt_congestion_window_packets = stats.pktCongestionWindow;
-       card->metric_srt_flight_size_packets = stats.pktFlightSize;
-       card->metric_srt_rtt_seconds = stats.msRTT * 1e-3;
-       card->metric_srt_estimated_bandwidth_bits_per_second = stats.mbpsBandwidth * 1e6;
-       card->metric_srt_bandwidth_ceiling_bits_per_second = stats.mbpsMaxBW * 1e6;
-       card->metric_srt_send_buffer_available_bytes = stats.byteAvailSndBuf;
-       card->metric_srt_receive_buffer_available_bytes = stats.byteAvailRcvBuf;
-       card->metric_srt_mss_bytes = stats.byteMSS;
-       card->metric_srt_sender_unacked_packets = stats.pktSndBuf;
-       card->metric_srt_sender_unacked_bytes = stats.byteSndBuf;
-       card->metric_srt_sender_unacked_timespan_seconds = stats.msSndBuf * 1e-3;
-       card->metric_srt_sender_delivery_delay_seconds = stats.msSndTsbPdDelay * 1e-3;
-       card->metric_srt_receiver_unacked_packets = stats.pktRcvBuf;
-       card->metric_srt_receiver_unacked_bytes = stats.byteRcvBuf;
-       card->metric_srt_receiver_unacked_timespan_seconds = stats.msRcvBuf * 1e-3;
-       card->metric_srt_receiver_delivery_delay_seconds = stats.msRcvTsbPdDelay * 1e-3;
-}
-#endif
-
 string Mixer::description_for_card(unsigned card_index)
 {
        CaptureCard *card = &cards[card_index];