]> git.sesse.net Git - nageru/blobdiff - nageru/mixer.cpp
Increase the master card timeout to 200 ms.
[nageru] / nageru / mixer.cpp
index 827ab9fd9dfa4b41ca31649d7dcd6cb0d09c9434..cbca327e07663326a0eee26512939d093f1f59e3 100644 (file)
@@ -631,9 +631,7 @@ void Mixer::configure_card(unsigned card_index, CaptureInterface *capture, CardT
                assert(card_type == CardType::FFMPEG_INPUT);
        }
 
-       DeviceSpec device;
-       device = DeviceSpec{InputSourceType::CAPTURE_CARD, card_index};
-       audio_mixer->reset_resampler(device);
+       DeviceSpec device{InputSourceType::CAPTURE_CARD, card_index};
        unsigned num_channels = card_type == CardType::LIVE_CARD ? 8 : 2;
        if (is_active) {
                audio_mixer->set_device_parameters(device, card->capture->get_description(), card_type, num_channels, /*active=*/true);
@@ -643,6 +641,7 @@ void Mixer::configure_card(unsigned card_index, CaptureInterface *capture, CardT
                snprintf(name, sizeof(name), "Fake card %u", card_index + 1);
                audio_mixer->set_device_parameters(device, name, card_type, num_channels, /*active=*/false);
        }
+       audio_mixer->reset_resampler(device);
        audio_mixer->trigger_state_changed_callback();
 
        // Unregister old metrics, if any.
@@ -1472,7 +1471,7 @@ pair<string, string> Mixer::get_channel_color_http(unsigned channel_idx)
 Mixer::OutputFrameInfo Mixer::get_one_frame_from_each_card(unsigned master_card_index, bool master_card_is_output, CaptureCard::NewFrame new_frames[MAX_VIDEO_CARDS], bool has_new_frame[MAX_VIDEO_CARDS], vector<int32_t> raw_audio[MAX_VIDEO_CARDS])
 {
        OutputFrameInfo output_frame_info;
-       constexpr steady_clock::duration master_card_timeout = milliseconds(100);
+       constexpr steady_clock::duration master_card_timeout = milliseconds(200);
 start:
        unique_lock<mutex> lock(card_mutex, defer_lock);
        bool timed_out = false;
@@ -1490,10 +1489,15 @@ start:
                                return !cards[master_card_index].new_frames.empty() ||
                                        cards[master_card_index].capture->get_disconnected();
                        });
+               if (timed_out) {
+                       fprintf(stderr, "WARNING: Master card (%s) did not deliver a frame for %u ms, creating a fake one.\n",
+                               description_for_card(master_card_index).c_str(),
+                               unsigned(duration_cast<milliseconds>(master_card_timeout).count()));
+               }
        }
 
        if (timed_out) {
-               // The master card stalled for 100 ms (possible when it's e.g.
+               // The master card stalled for 200 ms (possible when it's e.g.
                // an SRT card). Send a frame no matter what; this also makes sure
                // any other cards get to empty their queues, and in general,
                // that we make _some_ sort of forward progress.
@@ -1573,6 +1577,14 @@ start:
        fractional_samples = num_samples_times_timebase % TIMEBASE;
        assert(output_frame_info.num_samples >= 0);
 
+       if (timed_out) {
+               DeviceSpec device{InputSourceType::CAPTURE_CARD, master_card_index};
+               bool success;
+               do {
+                       success = audio_mixer->add_silence(device, output_frame_info.num_samples, /*dropped_frames=*/0);
+               } while (!success);
+       }
+
        return output_frame_info;
 }