obs-studio的源

来源:互联网 发布:该域名升级访问中 编辑:程序博客网 时间:2024/06/02 12:41

当你点击添加源时,会弹出obs支持的所有源的菜单,代码见window-basic-main.cpp,每个Menu iterm对应一个source

QMenu *OBSBasic::CreateAddSourcePopupMenu(){const char *type;bool foundValues = false;size_t idx = 0;QMenu *popup = new QMenu(QTStr("Add"), this);auto getActionAfter = [] (QMenu *menu, const QString &name){QList<QAction*> actions = menu->actions();for (QAction *menuAction : actions) {if (menuAction->text().compare(name) >= 0)return menuAction;}return (QAction*)nullptr;};auto addSource = [this, getActionAfter] (QMenu *popup,const char *type, const char *name){QString qname = QT_UTF8(name);QAction *popupItem = new QAction(qname, this);popupItem->setData(QT_UTF8(type));connect(popupItem, SIGNAL(triggered(bool)),this, SLOT(AddSourceFromAction()));QAction *after = getActionAfter(popup, qname);popup->insertAction(after, popupItem);};while (obs_enum_input_types(idx++, &type)) {const char *name = obs_source_get_display_name(type);uint32_t caps = obs_get_source_output_flags(type);if ((caps & OBS_SOURCE_DEPRECATED) == 0) {addSource(popup, type, name);foundValues = true;}}addSource(popup, "scene", Str("Basic.Scene"));if (!foundValues) {delete popup;popup = nullptr;}return popup;}


添加源时,创建的PopMenu,每个QAction,,关联一个AddSourceFromeAction

QAction *popupItem = new QAction(qname, this);popupItem->setData(QT_UTF8(type));connect(popupItem, SIGNAL(triggered(bool)),this, SLOT(AddSourceFromAction()));

void OBSBasic::AddSourceFromAction(){QAction *action = qobject_cast<QAction*>(sender());if (!action)return;AddSource(QT_TO_UTF8(action->data().toString()));}
void OBSBasic::AddSource(const char *id){if (id && *id) {OBSBasicSourceSelect sourceSelect(this, id);sourceSelect.exec();if (sourceSelect.newSource)CreatePropertiesWindow(sourceSelect.newSource);}}
选择一个源时,会初始化OBSBasicSourceSelect。

你可以为新添加的源设置名字,当点击确定时,会调用AddNew,创建一个新的source

bool AddNew(QWidget *parent, const char *id, const char *name,const bool visible, OBSSource &newSource){OBSBasic     *main = reinterpret_cast<OBSBasic*>(App()->GetMainWindow());OBSScene     scene = main->GetCurrentScene();bool         success = false;if (!scene)return false;obs_source_t *source = obs_get_source_by_name(name);if (source) {QMessageBox::information(parent,QTStr("NameExists.Title"),QTStr("NameExists.Text"));} else {source = obs_source_create(id, name, NULL, nullptr);if (source) {AddSourceData data;data.source = source;data.visible = visible;obs_scene_atomic_update(scene, AddSource, &data);newSource = source;success = true;}}obs_source_release(source);return success;}

设置该source的一些属性

          

void OBSBasic::CreatePropertiesWindow(obs_source_t *source){if (properties)properties->close();properties = new OBSBasicProperties(this, source);properties->Init();properties->setAttribute(Qt::WA_DeleteOnClose, true);}

OBSBasicProperties内部又会创建OBSPropertiesView。

例如如果当前加入的源是窗口捕获,

会调用

void OBSPropertiesView::AddProperty(obs_property_t *property,QFormLayout *layout)
{

   ///

 AddList();


///

QWidget *OBSPropertiesView::AddList(obs_property_t *prop, bool &warning){const char       *name  = obs_property_name(prop);QComboBox        *combo = new QComboBox();obs_combo_type   type   = obs_property_list_type(prop);obs_combo_format format = obs_property_list_format(prop);size_t           count  = obs_property_list_item_count(prop);int              idx    = -1;for (size_t i = 0; i < count; i++)AddComboItem(combo, prop, format, i);if (type == OBS_COMBO_TYPE_EDITABLE)combo->setEditable(true);combo->setMaxVisibleItems(40);combo->setToolTip(QT_UTF8(obs_property_long_description(prop)));string value = from_obs_data(settings, name, format);if (format == OBS_COMBO_FORMAT_STRING &&type == OBS_COMBO_TYPE_EDITABLE) {combo->lineEdit()->setText(QT_UTF8(value.c_str()));} else {idx = combo->findData(QByteArray(value.c_str()));}if (type == OBS_COMBO_TYPE_EDITABLE)return NewWidget(prop, combo,SIGNAL(editTextChanged(const QString &)));if (idx != -1)combo->setCurrentIndex(idx);if (obs_data_has_autoselect_value(settings, name)) {string autoselect =from_obs_data_autoselect(settings, name, format);int id = combo->findData(QT_UTF8(autoselect.c_str()));if (id != -1 && id != idx) {QString actual   = combo->itemText(id);QString selected = combo->itemText(idx);QString combined = QTStr("Basic.PropertiesWindow.AutoSelectFormat");combo->setItemText(idx,combined.arg(selected).arg(actual));}}

枚举出当前的窗口信息,填充到对应的combox中

static void AddComboItem(QComboBox *combo, obs_property_t *prop,obs_combo_format format, size_t idx){const char *name = obs_property_list_item_name(prop, idx);QVariant var;if (format == OBS_COMBO_FORMAT_INT) {long long val = obs_property_list_item_int(prop, idx);var = QVariant::fromValue<long long>(val);} else if (format == OBS_COMBO_FORMAT_FLOAT) {double val = obs_property_list_item_float(prop, idx);var = QVariant::fromValue<double>(val);} else if (format == OBS_COMBO_FORMAT_STRING) {var = QByteArray(obs_property_list_item_string(prop, idx));}combo->addItem(QT_UTF8(name), var);if (!obs_property_list_item_disabled(prop, idx))return;int index = combo->findText(QT_UTF8(name));if (index < 0)return;QStandardItemModel *model =dynamic_cast<QStandardItemModel*>(combo->model());if (!model)return;QStandardItem *item = model->item(index);item->setFlags(Qt::NoItemFlags);}


选中会弹出 该窗口的preview

0 0