]> git.sesse.net Git - nageru/blobdiff - glwidget.cpp
Update the queue length metric after trimming, not before.
[nageru] / glwidget.cpp
index 9d5e02cd3c72e86207298042c155a092e5599d8f..31018d6b95d5436cddc840ab01738b1b30ded18b 100644 (file)
@@ -1,38 +1,39 @@
-#include <qmetatype.h>  // Needs to come before egl.h.
-#include <qdatastream.h>  // Needs to come before egl.h.
-#include <qtextstream.h>  // Needs to come before egl.h.
-#include <qcursor.h>  // Needs to come before egl.h.
-#include <qcoreevent.h>  // Needs to come before egl.h.
-#include <qevent.h>  // Needs to come before egl.h.
-#include <epoxy/gl.h>
-#include <epoxy/egl.h>
-#include <QAction>
-#include <QMenu>
-#include <QSurfaceFormat>
-
 #include "glwidget.h"
 
-#include <stdio.h>
-#include <functional>
-#include <limits>
-#include <mutex>
+#include <assert.h>
+#include <bmusb/bmusb.h>
 #include <movit/effect_chain.h>
 #include <movit/resource_pool.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <QAction>
+#include <QActionGroup>
+#include <QList>
+#include <QMenu>
+#include <QPoint>
+#include <QVariant>
+#include <QWidget>
+#include <functional>
+#include <map>
+#include <mutex>
+#include <utility>
 
+#include "audio_mixer.h"
 #include "context.h"
+#include "context_menus.h"
 #include "flags.h"
 #include "mainwindow.h"
 #include "mixer.h"
-#include "qnamespace.h"
 #include "ref_counted_gl_sync.h"
 
 class QMouseEvent;
-class QWidget;
 
 #undef Success
 #include <movit/util.h>
 #include <string>
 
+
+using namespace movit;
 using namespace std;
 using namespace std::placeholders;
 
@@ -41,12 +42,17 @@ GLWidget::GLWidget(QWidget *parent)
 {
 }
 
-void GLWidget::clean_context()
+GLWidget::~GLWidget()
+{
+}
+
+void GLWidget::shutdown()
 {
        if (resource_pool != nullptr) {
                makeCurrent();
                resource_pool->clean_context();
        }
+       global_mixer->remove_frame_ready_callback(output, this);
 }
 
 void GLWidget::initializeGL()
@@ -58,7 +64,7 @@ void GLWidget::initializeGL()
                global_mainwindow->mixer_created(global_mixer);
                global_mixer->start();
        });
-       global_mixer->set_frame_ready_callback(output, [this]{
+       global_mixer->add_frame_ready_callback(output, this, [this]{
                QMetaObject::invokeMethod(this, "update", Qt::AutoConnection);
        });
        if (output == Mixer::OUTPUT_LIVE) {
@@ -73,14 +79,9 @@ void GLWidget::initializeGL()
                global_mixer->set_color_updated_callback(output, [this](const string &color){
                        emit color_updated(output, color);
                });
-
-               int signal_num = global_mixer->get_channel_signal(output);
-               if (signal_num != -1) {
-                       setContextMenuPolicy(Qt::CustomContextMenu);
-                       connect(this, &QWidget::customContextMenuRequested,
-                               bind(&GLWidget::show_context_menu, this, signal_num, _1));
-               }
        }
+       setContextMenuPolicy(Qt::CustomContextMenu);
+       connect(this, &QWidget::customContextMenuRequested, bind(&GLWidget::show_context_menu, this, _1));
 
        glDisable(GL_BLEND);
        glDisable(GL_DEPTH_TEST);
@@ -108,6 +109,8 @@ void GLWidget::paintGL()
        check_error();
        frame.setup_chain();
        check_error();
+       glDisable(GL_FRAMEBUFFER_SRGB);
+       check_error();
        frame.chain->render_to_screen();
        check_error();
 
@@ -123,7 +126,42 @@ void GLWidget::mousePressEvent(QMouseEvent *event)
        emit clicked();
 }
 
-void GLWidget::show_context_menu(unsigned signal_num, const QPoint &pos)
+void GLWidget::show_context_menu(const QPoint &pos)
+{
+       if (output == Mixer::OUTPUT_LIVE) {
+               show_live_context_menu(pos);
+       }
+       if (output >= Mixer::OUTPUT_INPUT0) {
+               int signal_num = global_mixer->get_channel_signal(output);
+               show_preview_context_menu(signal_num, pos);
+       }
+}
+
+void GLWidget::show_live_context_menu(const QPoint &pos)
+{
+       QPoint global_pos = mapToGlobal(pos);
+
+       QMenu menu;
+
+       // Add a submenu for selecting output card, with an action for each card.
+       QMenu card_submenu;
+       fill_hdmi_sdi_output_device_menu(&card_submenu);
+       card_submenu.setTitle("HDMI/SDI output device");
+       menu.addMenu(&card_submenu);
+
+       // Add a submenu for choosing the output resolution. Since this is
+       // card-dependent, it is disabled if we haven't chosen a card
+       // (but it's still there so that the user will know it exists).
+       QMenu resolution_submenu;
+       fill_hdmi_sdi_output_resolution_menu(&resolution_submenu);
+       resolution_submenu.setTitle("HDMI/SDI output resolution");
+       menu.addMenu(&resolution_submenu);
+
+       // Show the menu; if there's an action selected, it will deal with it itself.
+       menu.exec(global_pos);
+}
+
+void GLWidget::show_preview_context_menu(unsigned signal_num, const QPoint &pos)
 {
        QPoint global_pos = mapToGlobal(pos);
 
@@ -149,6 +187,48 @@ void GLWidget::show_context_menu(unsigned signal_num, const QPoint &pos)
        card_submenu.setTitle("Input source");
        menu.addMenu(&card_submenu);
 
+       // Note that this setting depends on which card is active.
+       // TODO: Consider hiding this for BGRA sources.
+
+       QMenu interpretation_submenu;
+       QActionGroup interpretation_group(&interpretation_submenu);
+
+       YCbCrInterpretation current_interpretation = global_mixer->get_input_ycbcr_interpretation(current_card);
+       {
+               QAction *action = new QAction("Auto", &interpretation_group);
+               action->setCheckable(true);
+               if (current_interpretation.ycbcr_coefficients_auto) {
+                       action->setChecked(true);
+               }
+               action->setData(QList<QVariant>{"interpretation", true, YCBCR_REC_709, false});
+               interpretation_submenu.addAction(action);
+       }
+       for (YCbCrLumaCoefficients ycbcr_coefficients : { YCBCR_REC_709, YCBCR_REC_601 }) {
+               for (bool full_range : { false, true }) {
+                       std::string description;
+                       if (ycbcr_coefficients == YCBCR_REC_709) {
+                               description = "Rec. 709 (HD)";
+                       } else {
+                               description = "Rec. 601 (SD)";
+                       }
+                       if (full_range) {
+                               description += ", full range (nonstandard)";
+                       }
+                       QAction *action = new QAction(QString::fromStdString(description), &interpretation_group);
+                       action->setCheckable(true);
+                       if (!current_interpretation.ycbcr_coefficients_auto &&
+                           ycbcr_coefficients == current_interpretation.ycbcr_coefficients &&
+                           full_range == current_interpretation.full_range) {
+                               action->setChecked(true);
+                       }
+                       action->setData(QList<QVariant>{"interpretation", false, ycbcr_coefficients, full_range});
+                       interpretation_submenu.addAction(action);
+               }
+       }
+
+       interpretation_submenu.setTitle("Input interpretation");
+       menu.addMenu(&interpretation_submenu);
+
        // --- The choices in the next few options depend a lot on which card is active ---
 
        // Add a submenu for selecting video input, with an action for each input.
@@ -239,7 +319,10 @@ void GLWidget::show_context_menu(unsigned signal_num, const QPoint &pos)
        // And a master clock selector.
        QAction *master_clock_action = new QAction("Use as master clock", &menu);
        master_clock_action->setCheckable(true);
-       if (global_mixer->get_master_clock() == signal_num) {
+       if (global_mixer->get_output_card_index() != -1) {
+               master_clock_action->setChecked(false);
+               master_clock_action->setEnabled(false);
+       } else if (global_mixer->get_master_clock() == signal_num) {
                master_clock_action->setChecked(true);
                master_clock_action->setEnabled(false);
        }
@@ -269,6 +352,12 @@ void GLWidget::show_context_menu(unsigned signal_num, const QPoint &pos)
                } else if (selected[0].toString() == "card") {
                        unsigned card_index = selected[1].toUInt(nullptr);
                        global_mixer->set_signal_mapping(signal_num, card_index);
+               } else if (selected[0].toString() == "interpretation") {
+                       YCbCrInterpretation interpretation;
+                       interpretation.ycbcr_coefficients_auto = selected[1].toBool();
+                       interpretation.ycbcr_coefficients = YCbCrLumaCoefficients(selected[2].toUInt(nullptr));
+                       interpretation.full_range = selected[3].toBool();
+                       global_mixer->set_input_ycbcr_interpretation(current_card, interpretation);
                } else {
                        assert(false);
                }