]> git.sesse.net Git - nageru/commitdiff
Time out grabbing if we don't get any data.
authorSteinar H. Gunderson <steinar+nageru@gunderson.no>
Sun, 11 Aug 2019 20:38:14 +0000 (22:38 +0200)
committerSteinar H. Gunderson <steinar+nageru@gunderson.no>
Sun, 25 Aug 2019 22:39:08 +0000 (00:39 +0200)
nageru/delay_analyzer.cpp
nageru/delay_analyzer.h

index e720c30a1472b4544c7f4a49a754d819129f25cb..9e8206015de30a80ce74455a0efdd9d12ff6f19f 100644 (file)
@@ -7,6 +7,8 @@
 
 #include <memory>
 
+#include <QTimer>
+
 using namespace bmusb;
 using namespace std;
 using namespace std::chrono;
@@ -14,7 +16,8 @@ using namespace std::placeholders;
 
 DelayAnalyzer::DelayAnalyzer()
        : ui(new Ui::DelayAnalyzer),
-         devices(global_audio_mixer->get_devices(AudioMixer::HOLD_NO_DEVICES))
+         devices(global_audio_mixer->get_devices(AudioMixer::HOLD_NO_DEVICES)),
+         grab_timeout(new QTimer(this))
 {
        ui->setupUi(this);
        connect(ui->grab_btn, &QPushButton::clicked, this, &DelayAnalyzer::grab_clicked);
@@ -27,6 +30,7 @@ DelayAnalyzer::DelayAnalyzer()
                bind(&DelayAnalyzer::channel_selected, this, ui->channel_combo_1));
        connect(ui->channel_combo_2, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
                bind(&DelayAnalyzer::channel_selected, this, ui->channel_combo_2));
+       connect(grab_timeout, &QTimer::timeout, bind(&DelayAnalyzer::grab_timed_out, this));
 
        for (const auto &spec_and_info : devices) {
                QString label(QString::fromStdString(spec_and_info.second.display_name));
@@ -45,6 +49,8 @@ DelayAnalyzer::~DelayAnalyzer()
 void DelayAnalyzer::grab_clicked()
 {
        grabbing = true;
+       grab_timeout->setSingleShot(true);
+       grab_timeout->start(milliseconds(2000));
        clip1.clear();
        clip2.clear();
        ui->peak_display_1->reset_base();
@@ -142,6 +148,15 @@ void DelayAnalyzer::add_audio(DeviceSpec device_spec, const uint8_t *data, unsig
 
        if (clip1.get_length_seconds_after_base(base) >= 1.0 &&
            clip2.get_length_seconds_after_base(base) >= 1.0) {
+               post_to_main_thread([this] {
+                       grab_timeout->stop();
+               });
                grabbing = false;
        }
 }
+
+void DelayAnalyzer::grab_timed_out()
+{
+       grabbing = false;
+       ui->delay_estimate_label->setText("Could not capture audio (timed out).");
+}
index cc75325b19a331cc0bbe23c660e485aa60d6c592..a9770533ef28e07a7ca0a218b4acdb6d45d54eac 100644 (file)
@@ -19,6 +19,7 @@ class DelayAnalyzer;
 }  // namespace Ui
 
 class QComboBox;
+class QTimer;
 
 class DelayAnalyzer : public QMainWindow, public DelayAnalyzerInterface
 {
@@ -32,6 +33,8 @@ public:
        void add_audio(DeviceSpec device_spec, const uint8_t *data, unsigned num_samples, bmusb::AudioFormat audio_format, std::chrono::steady_clock::time_point frame_time) override;
 
 private:
+       void grab_timed_out();
+
        Ui::DelayAnalyzer *ui;
        AudioClip clip1, clip2;
 
@@ -42,6 +45,7 @@ private:
 
        std::atomic<bool> grabbing{false};
        std::map<DeviceSpec, DeviceInfo> devices;
+       QTimer *grab_timeout;
 };
 
 #endif  // !defined(_DELAY_ANALYZER_H)