From c1f1bd35d8c8e2cb9ff97c3535bb2dd04d55a51d Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 19 Dec 2018 00:30:23 +0100 Subject: [PATCH] Add support for querying tally information from Nageru. --- futatabi/flags.cpp | 8 ++++- futatabi/flags.h | 1 + futatabi/mainwindow.cpp | 30 +++++++++++++++++ futatabi/mainwindow.h | 8 +++++ futatabi/mainwindow.ui | 74 +++++++++++++++++++++++++++++++++++++---- meson.build | 2 +- 6 files changed, 114 insertions(+), 9 deletions(-) diff --git a/futatabi/flags.cpp b/futatabi/flags.cpp index 1c606b1..9e15399 100644 --- a/futatabi/flags.cpp +++ b/futatabi/flags.cpp @@ -16,7 +16,8 @@ int flow_initialized_interpolation_quality; enum LongOption { OPTION_HELP = 1000, OPTION_SLOW_DOWN_INPUT = 1001, - OPTION_HTTP_PORT = 1002 + OPTION_HTTP_PORT = 1002, + OPTION_TALLY_URL = 1003 }; void usage() @@ -37,6 +38,7 @@ void usage() fprintf(stderr, " 4 = best (not realtime on any current GPU)\n"); fprintf(stderr, " -d, --working-directory DIR where to store frames and database\n"); fprintf(stderr, " --http-port PORT which port to listen on for output\n"); + fprintf(stderr, " --tally-url URL URL to get tally color from (polled every 100 ms)\n"); } void parse_flags(int argc, char * const argv[]) @@ -50,6 +52,7 @@ void parse_flags(int argc, char * const argv[]) { "interpolation-quality", required_argument, 0, 'q' }, { "working-directory", required_argument, 0, 'd' }, { "http-port", required_argument, 0, OPTION_HTTP_PORT }, + { "tally-url", required_argument, 0, OPTION_TALLY_URL }, { 0, 0, 0, 0 } }; for ( ;; ) { @@ -91,6 +94,9 @@ void parse_flags(int argc, char * const argv[]) case OPTION_HTTP_PORT: global_flags.http_port = atoi(optarg); break; + case OPTION_TALLY_URL: + global_flags.tally_url = optarg; + break; case OPTION_HELP: usage(); exit(0); diff --git a/futatabi/flags.h b/futatabi/flags.h index a25b7e5..5b7d32e 100644 --- a/futatabi/flags.h +++ b/futatabi/flags.h @@ -14,6 +14,7 @@ struct Flags { bool interpolation_quality_set = false; uint16_t http_port = DEFAULT_HTTPD_PORT; double output_framerate = 60000.0 / 1001.0; + std::string tally_url; }; extern Flags global_flags; diff --git a/futatabi/mainwindow.cpp b/futatabi/mainwindow.cpp index d4c63bd..8982b5f 100644 --- a/futatabi/mainwindow.cpp +++ b/futatabi/mainwindow.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -191,6 +192,10 @@ MainWindow::MainWindow() } } change_num_cameras(); + + if (!global_flags.tally_url.empty()) { + start_tally(); + } } void MainWindow::change_num_cameras() @@ -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); +} diff --git a/futatabi/mainwindow.h b/futatabi/mainwindow.h index 8492eb3..5d7104a 100644 --- a/futatabi/mainwindow.h +++ b/futatabi/mainwindow.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -88,6 +89,10 @@ private: }; std::vector displays; + // Used to get tally information, if a tally URL is set. + QNetworkAccessManager http; + QNetworkReply *http_reply = nullptr; + void change_num_cameras(); void cue_in_clicked(); void cue_out_clicked(); @@ -135,6 +140,9 @@ private: template void replace_model(QTableView *view, Model **model, Model *new_model); + void start_tally(); + void tally_received(); + private slots: void relayout(); }; diff --git a/futatabi/mainwindow.ui b/futatabi/mainwindow.ui index 212f3bd..0f471e0 100644 --- a/futatabi/mainwindow.ui +++ b/futatabi/mainwindow.ui @@ -183,18 +183,48 @@ + + 3 + - - - - - + + + true + + + QFrame::NoFrame + + + QFrame::Plain + + 0 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + + + + - + Preview output @@ -210,7 +240,37 @@ - + + + true + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + diff --git a/meson.build b/meson.build index 46060a0..b537dd3 100644 --- a/meson.build +++ b/meson.build @@ -21,7 +21,7 @@ luajitdep = dependency('luajit') movitdep = dependency('movit') protobufdep = dependency('protobuf') qcustomplotdep = cxx.find_library('qcustomplot') -qt5deps = dependency('qt5', modules: ['Core', 'Gui', 'Widgets', 'OpenGLExtensions', 'OpenGL', 'PrintSupport']) +qt5deps = dependency('qt5', modules: ['Core', 'Gui', 'Widgets', 'OpenGLExtensions', 'OpenGL', 'Network']) sdl2_imagedep = dependency('SDL2_image') sdl2dep = dependency('sdl2') sqlite3dep = dependency('sqlite3') -- 2.39.2