]> git.sesse.net Git - nageru/blobdiff - futatabi/mainwindow.cpp
Make the SDL dependencies optional.
[nageru] / futatabi / mainwindow.cpp
index d4c63bd6cfa7e4d755fbb7496f0da4d0dd558b01..38a50df371886d4045a31993e5fa93ae19699061 100644 (file)
@@ -15,6 +15,7 @@
 #include <QFileDialog>
 #include <QMessageBox>
 #include <QMouseEvent>
+#include <QNetworkReply>
 #include <QShortcut>
 #include <QTimer>
 #include <QWheelEvent>
@@ -180,17 +181,21 @@ MainWindow::MainWindow()
                this, &MainWindow::clip_list_selection_changed);
 
        // Find out how many cameras we have in the existing frames;
-       // if none, we start with a single camera.
-       num_cameras = 1;
+       // if none, we start with two cameras.
+       num_cameras = 2;
        {
                lock_guard<mutex> lock(frame_mu);
-               for (size_t stream_idx = 1; stream_idx < MAX_STREAMS; ++stream_idx) {
+               for (size_t stream_idx = 2; stream_idx < MAX_STREAMS; ++stream_idx) {
                        if (!frames[stream_idx].empty()) {
                                num_cameras = stream_idx + 1;
                        }
                }
        }
        change_num_cameras();
+
+       if (!global_flags.tally_url.empty()) {
+               start_tally();
+       }
 }
 
 void MainWindow::change_num_cameras()
@@ -1007,7 +1012,7 @@ void MainWindow::quality_toggled(int quality, bool checked)
 void MainWindow::highlight_camera_input(int stream_idx)
 {
        for (unsigned i = 0; i < num_cameras; ++i) {
-               if (stream_idx == i) {
+               if (unsigned(stream_idx) == i) {
                        displays[i].frame->setStyleSheet("background: rgb(0,255,0)");
                } else {
                        displays[i].frame->setStyleSheet("");
@@ -1053,3 +1058,28 @@ void MainWindow::replace_model(QTableView *view, Model **model, Model *new_model
        *model = new_model;
        connect(new_model, &Model::any_content_changed, this, &MainWindow::content_changed);
 }
+
+void MainWindow::start_tally()
+{
+       http_reply = http.get(QNetworkRequest(QString::fromStdString(global_flags.tally_url)));
+       connect(http_reply, &QNetworkReply::finished, this, &MainWindow::tally_received);
+}
+
+void MainWindow::tally_received()
+{
+       unsigned time_to_next_tally_ms;
+       if (http_reply->error()) {
+               fprintf(stderr, "HTTP get of '%s' failed: %s\n", global_flags.tally_url.c_str(),
+                       http_reply->errorString().toStdString().c_str());
+               ui->live_frame->setStyleSheet("");
+               time_to_next_tally_ms = 1000;
+       } else {
+               string contents = http_reply->readAll().toStdString();
+               ui->live_frame->setStyleSheet(QString::fromStdString("background: " + contents));
+               time_to_next_tally_ms = 100;
+       }
+       http_reply->deleteLater();
+       http_reply = nullptr;
+
+       QTimer::singleShot(time_to_next_tally_ms, this, &MainWindow::start_tally);
+}