Exemplo n.º 1
0
static void LoadAudioDevice(const char *name, int channel, obs_data_t *parent) {

	obs_data_t *data = obs_data_get_obj(parent, name);
	if (!data)
		return;

	obs_source_t *source = obs_load_source(data);
	if (source) {
		obs_set_output_source(channel, source);
		obs_source_release(source);
	}

	obs_data_release(data);
}
Exemplo n.º 2
0
static void obs_free_data(void)
{
	struct obs_data *data = &obs->data;
	uint32_t i;

	for (i = 0; i < MAX_CHANNELS; i++)
		obs_set_output_source(i, NULL);

	while (data->displays.num)
		obs_display_destroy(data->displays.array[0]);

	pthread_mutex_lock(&obs->data.sources_mutex);
	for (i = 0; i < data->sources.num; i++)
		obs_source_release(data->sources.array[i]);
	da_free(data->sources);
	pthread_mutex_unlock(&obs->data.sources_mutex);
}
Exemplo n.º 3
0
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();
}
Exemplo n.º 4
0
void BiLiOBSMainWid::mLoad(const char *file)
{
	LoadScene();
	LoadAudioDeviceConfig();
	LoadFrontendHotkeys();

#if 0
	if (!file || !os_file_exists(file)) {
		blog(LOG_INFO, "No scene file found, creating default scene");
		mCreateDefaultScene(true);
		mSaveProject();
		return;
	}

	mDisableSaving++;

	obs_data_t *data = obs_data_create_from_json_file_safe(file, "bak");
	if (!data) {
		mDisableSaving--;
		blog(LOG_ERROR, "Failed to load '%s', creating default scene",
				file);
		mCreateDefaultScene(true);
		mSaveProject();
		return;
	}

	mClearSceneData();

	obs_data_array_t *sceneOrder = obs_data_get_array(data, "scene_order");
	obs_data_array_t *sources    = obs_data_get_array(data, "sources");
	const char       *sceneName = obs_data_get_string(data,
			"current_scene");

	const char *curSceneCollection = config_get_string(
			App()->mGetGlobalConfig(), "Basic", "SceneCollection");

	obs_data_set_default_string(data, "name", curSceneCollection);

	const char       *name = obs_data_get_string(data, "name");
	obs_source_t     *curScene;

	if (!name || !*name)
		name = curSceneCollection;

	LoadAudioDevice(DESKTOP_AUDIO_1, 1, data);
	LoadAudioDevice(DESKTOP_AUDIO_2, 2, data);
	LoadAudioDevice(AUX_AUDIO_1,     3, data);
	LoadAudioDevice(AUX_AUDIO_2,     4, data);
	LoadAudioDevice(AUX_AUDIO_3,     5, data);

	obs_load_sources(sources);

	if (sceneOrder)
		mLoadSceneListOrder(sceneOrder);

	curScene = obs_get_source_by_name(sceneName);
	obs_set_output_source(0, curScene);
	obs_source_release(curScene);

	obs_data_array_release(sources);
	obs_data_array_release(sceneOrder);

	std::string file_base = strrchr(file, '/') + 1;
	file_base.erase(file_base.size() - 5, 5);

	config_set_string(App()->mGetGlobalConfig(), "Basic", "SceneCollection",
			name);
	config_set_string(App()->mGetGlobalConfig(), "Basic", "SceneCollectionFile",
			file_base.c_str());

	obs_data_release(data);

	mCleanupUnusedSources();

	mDisableSaving--;
#endif
}
Exemplo n.º 5
0
int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdLine,
		int numCmd)
{
	HWND hwnd = NULL;
	base_set_log_handler(do_log);

	try {
		hwnd = CreateTestWindow(instance);
		if (!hwnd)
			throw "Couldn't create main window";

		/* ------------------------------------------------------ */
		/* create OBS */
		CreateOBS(hwnd);

		/* ------------------------------------------------------ */
		/* load module */
		if (obs_load_module("test-input") != 0)
			throw "Couldn't load module";

		/* ------------------------------------------------------ */
		/* create source */
		SourceContext source = obs_source_create(SOURCE_INPUT,
				"random", "some randon source", NULL);
		if (!source)
			throw "Couldn't create random test source";

		/* ------------------------------------------------------ */
		/* create filter */
		SourceContext filter = obs_source_create(SOURCE_FILTER,
				"test", "a nice little green filter", NULL);
		if (!filter)
			throw "Couldn't create test filter";
		obs_source_filter_add(source, filter);

		/* ------------------------------------------------------ */
		/* create scene and add source to scene (twice) */
		SceneContext scene = obs_scene_create("test scene");
		if (!scene)
			throw "Couldn't create scene";

		AddTestItems(scene, source);

		/* ------------------------------------------------------ */
		/* set the scene as the primary draw source and go */
		obs_set_output_source(0, source);

		MSG msg;
		while (GetMessage(&msg, NULL, 0, 0)) {
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

	} catch (char *error) {
		MessageBoxA(NULL, error, NULL, 0);
	}

	obs_shutdown();

	blog(LOG_INFO, "Number of memory leaks: %llu", bnum_allocs());
	DestroyWindow(hwnd);

	return 0;
}