bool AddNew(QWidget *parent, const char *id, const char *name) { obs_source_t source = obs_get_output_source(0); obs_scene_t scene = obs_scene_from_source(source); bool success = false; if (!source) return false; source = obs_get_source_by_name(name); if (source) { QMessageBox::information(parent, QTStr("NameExists.Title"), QTStr("NameExists.Text")); } else { source = obs_source_create(OBS_SOURCE_TYPE_INPUT, id, name, NULL); if (source) { obs_add_source(source); obs_scene_add(scene, source); success = true; } } obs_source_release(source); obs_scene_release(scene); return success; }
void obs_load_sources(obs_data_array_t *array) { size_t count; size_t i; if (!obs) return; count = obs_data_array_count(array); pthread_mutex_lock(&obs->data.user_sources_mutex); for (i = 0; i < count; i++) { obs_data_t *source_data = obs_data_array_item(array, i); obs_source_t *source = obs_load_source(source_data); obs_add_source(source); obs_source_release(source); obs_data_release(source_data); } /* tell sources that we want to load */ for (i = 0; i < obs->data.user_sources.num; i++) obs_source_load(obs->data.user_sources.array[i]); pthread_mutex_unlock(&obs->data.user_sources_mutex); }
void BiLiOBSMainWid::LoadScene() { obs_data_t* sceneData = BiliConfigFile::LoadSceneData(); if (sceneData) { BiliSceneConfig::Set(sceneData); obs_data_release(sceneData); } //如果加载进来的场景不够3个,就补到三个 std::string firstAddedScene; int sceneCount = 0; for (OBSSource& src : OBSEnumSources()) { if (strcmp(obs_source_get_id(src), "scene") == 0) { ++sceneCount; } } int nextSceneIndex = 1; for (; sceneCount < 3; ++sceneCount) { restartByNewName: std::string sceneName = tr("Scene %1").arg(nextSceneIndex).toUtf8().data(); obs_source_t* existedSource = obs_get_source_by_name(sceneName.c_str()); if (existedSource != 0) { obs_source_release(existedSource); ++nextSceneIndex; goto restartByNewName; } if (firstAddedScene.empty()) { firstAddedScene = sceneName; } obs_scene_t* scene = obs_scene_create(sceneName.c_str()); obs_source_t* sceneSource = obs_scene_get_source(scene); obs_add_source(sceneSource); obs_scene_release(scene); } obs_source_t* currentOutputSource = obs_get_output_source(0); if (!currentOutputSource) { if (!firstAddedScene.empty()) { currentOutputSource = obs_get_source_by_name(firstAddedScene.c_str()); if (currentOutputSource) { obs_set_output_source(0, currentOutputSource); obs_source_release(currentOutputSource); } } } else { obs_source_release(currentOutputSource); } //更新列表控件 sceneListWidgetOperator->NotifyCurrentSceneChanged(); }