diff --git a/src/capture/video_presets.cpp b/src/capture/video_presets.cpp index 57b8096a..e1fc4350 100644 --- a/src/capture/video_presets.cpp +++ b/src/capture/video_presets.cpp @@ -95,8 +95,10 @@ void kvideopreset_lock(const bool isLocked) void kvideopreset_activate_preset(const video_preset_s *const preset) { - if (LOCKED || !kc_has_signal() || !preset) - { + if ( + !preset || + (LOCKED && (preset != MOST_RECENT_ACTIVE_PRESET)) + ){ return; } @@ -150,12 +152,12 @@ void kvideopreset_remove_all_presets(void) void kvideopreset_apply_current_active_preset(void) { - if (LOCKED || !kc_has_signal()) + if (!kc_has_signal()) { return; } - const video_preset_s *activePreset = strongest_activating_preset(); + const video_preset_s *activePreset = (LOCKED? MOST_RECENT_ACTIVE_PRESET : strongest_activating_preset()); if (activePreset) { @@ -266,6 +268,16 @@ void video_properties_s::to_capture_device_properties( const std::string &nameSpace ) { +#if defined(CAPTURE_BACKEND_VISION_V4L) || defined(CAPTURE_BACKEND_GENERIC_V4L) + // If the namespace is empty, the values would modify the current capture + // parameters. But if there's no signal, the parameters won't be available + // for modification via V4L and we'd be wasting time trying to change them. + if (!kc_has_signal() && nameSpace.empty()) + { + return; + } +#endif + for (const auto &[propName, value]: properties) { kc_set_device_property((propName + nameSpace), value); diff --git a/src/capture/vision_v4l/ic_v4l_video_parameters.cpp b/src/capture/vision_v4l/ic_v4l_video_parameters.cpp index 3ba0b18b..73856fa0 100644 --- a/src/capture/vision_v4l/ic_v4l_video_parameters.cpp +++ b/src/capture/vision_v4l/ic_v4l_video_parameters.cpp @@ -29,7 +29,7 @@ bool ic_v4l_controls_c::set_value(const int newValue, const ic_v4l_controls_c::t { if (this->v4l_id(control) < 0) { - DEBUG(("Asked to modify an unrecognized V4L control. Ignoring it.")); + DEBUG(("Asked to modify a V4L control that isn't available. Ignoring this.")); return false; } diff --git a/src/display/qt/widgets/VideoPresetList.cpp b/src/display/qt/widgets/VideoPresetList.cpp index b93ed4a2..81622281 100644 --- a/src/display/qt/widgets/VideoPresetList.cpp +++ b/src/display/qt/widgets/VideoPresetList.cpp @@ -129,6 +129,21 @@ int VideoPresetList::find_preset_idx_in_list(const int presetId) return -1; } +int VideoPresetList::find_preset_idx_in_list(const QString &targetLabel) +{ + for (int i = 0; i < this->count(); i++) + { + const auto *preset = kvideopreset_get_preset_ptr(this->itemData(i).toUInt()); + const auto label = this->make_preset_item_label(preset); + if (label == targetLabel) + { + return i; + } + } + + return -1; +} + void VideoPresetList::update_preset_item_label(const unsigned presetId) { const auto *const preset = kvideopreset_get_preset_ptr(presetId); diff --git a/src/display/qt/widgets/VideoPresetList.h b/src/display/qt/widgets/VideoPresetList.h index 1231c961..5772341c 100644 --- a/src/display/qt/widgets/VideoPresetList.h +++ b/src/display/qt/widgets/VideoPresetList.h @@ -22,8 +22,7 @@ class VideoPresetList : public QComboBox ~VideoPresetList(void); - void add_preset(const unsigned presetId, - const bool blockSignal = false); + void add_preset(const unsigned presetId, const bool blockSignal = false); // Removes the given present from the list, and sets the list's index // to the one given. If the given preset doesn't exist in the list, no @@ -40,6 +39,15 @@ class VideoPresetList : public QComboBox // no preset is selected. video_preset_s* current_preset(void) const; + // Creates and returns a string to be displayed as the list item label for + // the given present should the preset be added. + QString make_preset_item_label(const video_preset_s *const preset); + + // Returns the list index of the given preset; or -1 if the list doesn't + // contain the preset. + int find_preset_idx_in_list(const int presetId); + int find_preset_idx_in_list(const QString &targetLabel); + signals: void preset_added(const unsigned presetId); @@ -51,17 +59,9 @@ class VideoPresetList : public QComboBox void preset_selected(const unsigned presetId); - void preset_label_changed(const unsigned presetId, - const QString &newLabel); + void preset_label_changed(const unsigned presetId, const QString &newLabel); private: - // Returns the list index of the given preset; or -1 if the list doesn't - // contain the preset. - int find_preset_idx_in_list(const int presetId); - - // Creates and returns a string to be displayed as the list item label for - // the given present should the preset be added. - QString make_preset_item_label(const video_preset_s *const preset); }; #endif diff --git a/src/display/qt/windows/ControlPanel/VideoPresets.cpp b/src/display/qt/windows/ControlPanel/VideoPresets.cpp index 3a494028..b83ce9f9 100644 --- a/src/display/qt/windows/ControlPanel/VideoPresets.cpp +++ b/src/display/qt/windows/ControlPanel/VideoPresets.cpp @@ -167,7 +167,7 @@ control_panel::VideoPresets::VideoPresets(QWidget *parent) : connect(ui->comboBox_presetList, QOverload::of(&QComboBox::currentIndexChanged), this, [this](const int index) { - kpers_set_value(INI_GROUP_VIDEO_PRESETS, "SelectedPresetIndex", std::max(index, 0)); + kpers_set_value(INI_GROUP_VIDEO_PRESETS, "SelectedPreset", ui->comboBox_presetList->make_preset_item_label(ui->comboBox_presetList->current_preset())); }); connect(ui->comboBox_presetList, &VideoPresetList::preset_selected, this, [this] @@ -532,7 +532,7 @@ void control_panel::VideoPresets::update_active_preset_indicator(void) void control_panel::VideoPresets::assign_presets(const std::vector &presets) { - const unsigned idx = kpers_value_of(INI_GROUP_VIDEO_PRESETS, "SelectedPresetIndex", 0).toUInt(); + const QString selectedLabel = kpers_value_of(INI_GROUP_VIDEO_PRESETS, "SelectedPreset", "").toString(); ui->comboBox_presetList->clear(); @@ -544,8 +544,9 @@ void control_panel::VideoPresets::assign_presets(const std::vectorcomboBox_presetList->sort_alphabetically(); - ui->comboBox_presetList->setCurrentIndex(-1); - ui->comboBox_presetList->setCurrentIndex(std::min(int(idx), (ui->comboBox_presetList->count() - 1))); + const int idx = ui->comboBox_presetList->find_preset_idx_in_list(selectedLabel); + ui->comboBox_presetList->setCurrentIndex(std::max(idx, 0)); + emit ui->comboBox_presetList->preset_selected(ui->comboBox_presetList->current_preset()->id); return; }