]> git.sesse.net Git - nageru/commitdiff
Make the right-click menu legal on signals connected to FFmpeg cards.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 22 Apr 2018 21:00:52 +0000 (23:00 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 22 Apr 2018 21:00:52 +0000 (23:00 +0200)
audio_mixer.cpp
glwidget.cpp
mixer.cpp
mixer.h
theme.lua

index d2617f65e4fc1b4ba90648f22453928cb2f698db..e7d545f69c6320c25cddcde039f3b100d8332529 100644 (file)
@@ -953,11 +953,15 @@ void AudioMixer::serialize_device(DeviceSpec device_spec, DeviceSpecProto *devic
 
 void AudioMixer::set_simple_input(unsigned card_index)
 {
+       assert(card_index < num_capture_cards + num_ffmpeg_inputs);
        InputMapping new_input_mapping;
        InputMapping::Bus input;
        input.name = "Main";
-       input.device.type = InputSourceType::CAPTURE_CARD;
-       input.device.index = card_index;
+       if (card_index >= num_capture_cards) {
+               input.device = DeviceSpec{InputSourceType::FFMPEG_VIDEO_INPUT, card_index - num_capture_cards};
+       } else {
+               input.device = DeviceSpec{InputSourceType::CAPTURE_CARD, card_index};
+       }
        input.source_channel[0] = 0;
        input.source_channel[1] = 1;
 
@@ -977,6 +981,11 @@ unsigned AudioMixer::get_simple_input() const
            input_mapping.buses[0].source_channel[0] == 0 &&
            input_mapping.buses[0].source_channel[1] == 1) {
                return input_mapping.buses[0].device.index;
+       } else if (input_mapping.buses.size() == 1 &&
+                  input_mapping.buses[0].device.type == InputSourceType::FFMPEG_VIDEO_INPUT &&
+                  input_mapping.buses[0].source_channel[0] == 0 &&
+                  input_mapping.buses[0].source_channel[1] == 1) {
+               return input_mapping.buses[0].device.index + num_capture_cards;
        } else {
                return numeric_limits<unsigned>::max();
        }
index 307e3e462a4796793f9037c33c9e550fe8832e9c..7caee374becc777d2af42575d58427bac5848d6b 100644 (file)
@@ -177,135 +177,140 @@ void GLWidget::show_preview_context_menu(unsigned signal_num, const QPoint &pos)
 
        unsigned num_cards = global_mixer->get_num_cards();
        unsigned current_card = global_mixer->map_signal(signal_num);
-       for (unsigned card_index = 0; card_index < num_cards; ++card_index) {
-               QString description(QString::fromStdString(global_mixer->get_card_description(card_index)));
-               QAction *action = new QAction(description, &card_group);
-               action->setCheckable(true);
-               if (current_card == card_index) {
-                       action->setChecked(true);
+       bool is_ffmpeg = global_mixer->card_is_ffmpeg(current_card);
+
+       if (!is_ffmpeg) {  // FFmpeg inputs are not connected to any card; they're locked to a given input and have a given Y'CbCr interpretatio and have a given Y'CbCr interpretationn.
+               for (unsigned card_index = 0; card_index < num_cards; ++card_index) {
+                       QString description(QString::fromStdString(global_mixer->get_card_description(card_index)));
+                       QAction *action = new QAction(description, &card_group);
+                       action->setCheckable(true);
+                       if (current_card == card_index) {
+                               action->setChecked(true);
+                       }
+                       action->setData(QList<QVariant>{"card", card_index});
+                       card_submenu.addAction(action);
                }
-               action->setData(QList<QVariant>{"card", card_index});
-               card_submenu.addAction(action);
-       }
 
-       card_submenu.setTitle("Input source");
-       menu.addMenu(&card_submenu);
+               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.
+               // Note that this setting depends on which card is active.
 
-       QMenu interpretation_submenu;
-       QActionGroup interpretation_group(&interpretation_submenu);
+               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);
+               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 &&
-                           ycbcr_coefficients == current_interpretation.ycbcr_coefficients &&
-                           full_range == current_interpretation.full_range) {
+                       if (current_interpretation.ycbcr_coefficients_auto) {
                                action->setChecked(true);
                        }
-                       action->setData(QList<QVariant>{"interpretation", false, ycbcr_coefficients, full_range});
+                       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);
+               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.
-       QMenu video_input_submenu;
-       QActionGroup video_input_group(&video_input_submenu);
-       std::map<uint32_t, string> video_inputs = global_mixer->get_available_video_inputs(current_card);
-       uint32_t current_video_input = global_mixer->get_current_video_input(current_card);
-       for (const auto &mode : video_inputs) {
-               QString description(QString::fromStdString(mode.second));
-               QAction *action = new QAction(description, &video_input_group);
-               action->setCheckable(true);
-               if (mode.first == current_video_input) {
-                       action->setChecked(true);
+       bool has_auto_mode = false;
+       if (!is_ffmpeg) {
+               // Add a submenu for selecting video input, with an action for each input.
+               QMenu video_input_submenu;
+               QActionGroup video_input_group(&video_input_submenu);
+               std::map<uint32_t, string> video_inputs = global_mixer->get_available_video_inputs(current_card);
+               uint32_t current_video_input = global_mixer->get_current_video_input(current_card);
+               for (const auto &mode : video_inputs) {
+                       QString description(QString::fromStdString(mode.second));
+                       QAction *action = new QAction(description, &video_input_group);
+                       action->setCheckable(true);
+                       if (mode.first == current_video_input) {
+                               action->setChecked(true);
+                       }
+                       action->setData(QList<QVariant>{"video_input", mode.first});
+                       video_input_submenu.addAction(action);
                }
-               action->setData(QList<QVariant>{"video_input", mode.first});
-               video_input_submenu.addAction(action);
-       }
 
-       video_input_submenu.setTitle("Video input");
-       menu.addMenu(&video_input_submenu);
-
-       // The same for audio input.
-       QMenu audio_input_submenu;
-       QActionGroup audio_input_group(&audio_input_submenu);
-       std::map<uint32_t, string> audio_inputs = global_mixer->get_available_audio_inputs(current_card);
-       uint32_t current_audio_input = global_mixer->get_current_audio_input(current_card);
-       for (const auto &mode : audio_inputs) {
-               QString description(QString::fromStdString(mode.second));
-               QAction *action = new QAction(description, &audio_input_group);
-               action->setCheckable(true);
-               if (mode.first == current_audio_input) {
-                       action->setChecked(true);
+               video_input_submenu.setTitle("Video input");
+               menu.addMenu(&video_input_submenu);
+
+               // The same for audio input.
+               QMenu audio_input_submenu;
+               QActionGroup audio_input_group(&audio_input_submenu);
+               std::map<uint32_t, string> audio_inputs = global_mixer->get_available_audio_inputs(current_card);
+               uint32_t current_audio_input = global_mixer->get_current_audio_input(current_card);
+               for (const auto &mode : audio_inputs) {
+                       QString description(QString::fromStdString(mode.second));
+                       QAction *action = new QAction(description, &audio_input_group);
+                       action->setCheckable(true);
+                       if (mode.first == current_audio_input) {
+                               action->setChecked(true);
+                       }
+                       action->setData(QList<QVariant>{"audio_input", mode.first});
+                       audio_input_submenu.addAction(action);
                }
-               action->setData(QList<QVariant>{"audio_input", mode.first});
-               audio_input_submenu.addAction(action);
-       }
 
-       audio_input_submenu.setTitle("Audio input");
-       menu.addMenu(&audio_input_submenu);
+               audio_input_submenu.setTitle("Audio input");
+               menu.addMenu(&audio_input_submenu);
+
+               // The same for resolution.
+               QMenu mode_submenu;
+               QActionGroup mode_group(&mode_submenu);
+               std::map<uint32_t, bmusb::VideoMode> video_modes = global_mixer->get_available_video_modes(current_card);
+               uint32_t current_video_mode = global_mixer->get_current_video_mode(current_card);
+               for (const auto &mode : video_modes) {
+                       QString description(QString::fromStdString(mode.second.name));
+                       QAction *action = new QAction(description, &mode_group);
+                       action->setCheckable(true);
+                       if (mode.first == current_video_mode) {
+                               action->setChecked(true);
+                       }
+                       action->setData(QList<QVariant>{"video_mode", mode.first});
+                       mode_submenu.addAction(action);
 
-       // The same for resolution.
-       QMenu mode_submenu;
-       QActionGroup mode_group(&mode_submenu);
-       std::map<uint32_t, bmusb::VideoMode> video_modes = global_mixer->get_available_video_modes(current_card);
-       uint32_t current_video_mode = global_mixer->get_current_video_mode(current_card);
-       bool has_auto_mode = false;
-       for (const auto &mode : video_modes) {
-               QString description(QString::fromStdString(mode.second.name));
-               QAction *action = new QAction(description, &mode_group);
-               action->setCheckable(true);
-               if (mode.first == current_video_mode) {
-                       action->setChecked(true);
+                       // TODO: Relying on the 0 value here (from bmusb.h) is ugly, it should be a named constant.
+                       if (mode.first == 0) {
+                               has_auto_mode = true;
+                       }
                }
-               action->setData(QList<QVariant>{"video_mode", mode.first});
-               mode_submenu.addAction(action);
 
-               // TODO: Relying on the 0 value here (from bmusb.h) is ugly, it should be a named constant.
-               if (mode.first == 0) {
-                       has_auto_mode = true;
+               // Add a “scan” menu if there's no “auto” mode.
+               if (!has_auto_mode) {
+                       QAction *action = new QAction("Scan", &mode_group);
+                       action->setData(QList<QVariant>{"video_mode", 0});
+                       mode_submenu.addSeparator();
+                       mode_submenu.addAction(action);
                }
-       }
 
-       // Add a “scan” menu if there's no “auto” mode.
-       if (!has_auto_mode) {
-               QAction *action = new QAction("Scan", &mode_group);
-               action->setData(QList<QVariant>{"video_mode", 0});
-               mode_submenu.addSeparator();
-               mode_submenu.addAction(action);
+               mode_submenu.setTitle("Input mode");
+               menu.addMenu(&mode_submenu);
        }
 
-       mode_submenu.setTitle("Input mode");
-       menu.addMenu(&mode_submenu);
-
        // --- End of card-dependent choices ---
 
        // Add an audio source selector.
index 23658103e222d94383525e20f07911573c451e4d..73a59d5a3a0745b60e5e327cb866895f30f3ac11 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -1018,7 +1018,7 @@ void Mixer::thread_func()
                } else {
                        master_card_is_output = false;
                        master_card_index = theme->map_signal(master_clock_channel);
-                       assert(master_card_index < num_cards);
+                       assert(master_card_index < num_cards + num_video_inputs);
                }
 
                OutputFrameInfo output_frame_info = get_one_frame_from_each_card(master_card_index, master_card_is_output, new_frames, has_new_frame);
diff --git a/mixer.h b/mixer.h
index d8a9c8badf527e0e6dfcf2867156a10ad4677c9c..03a51636a2cee982c9b46bb643921c2fe77cffde 100644 (file)
--- a/mixer.h
+++ b/mixer.h
@@ -322,6 +322,11 @@ public:
                return cards[card_index].output != nullptr;
        }
 
+       bool card_is_ffmpeg(unsigned card_index) const {
+               assert(card_index < num_cards + num_video_inputs);
+               return cards[card_index].type == CardType::FFMPEG_INPUT;
+       }
+
        std::map<uint32_t, bmusb::VideoMode> get_available_video_modes(unsigned card_index) const {
                assert(card_index < num_cards);
                return cards[card_index].capture->get_available_video_modes();
index 77a1ff15cde855daf459367af3be3adc764d77d4..0f3ce72ad9ed050ab0b8fddccf1364367bb82afb 100644 (file)
--- a/theme.lua
+++ b/theme.lua
@@ -323,9 +323,11 @@ end
 
 -- API ENTRY POINT
 -- Returns, given a channel number, which signal it corresponds to (starting from 0).
--- Should return -1 if the channel does not correspond to a simple signal.
--- (The information is used for whether right-click on the channel should bring up
--- an input selector or not.)
+-- Should return -1 if the channel does not correspond to a simple signal
+-- (one connected to a capture card, or a video input). The information is used for
+-- whether right-click on the channel should bring up a context menu or not,
+-- typically containing an input selector, resolution menu etc.
+--
 -- Called once for each channel, at the start of the program.
 -- Will never be called for live (0) or preview (1).
 function channel_signal(channel)