UI: Remove obs_source_add and sourceSceneRefs variable
Prunes code used to workaround libobs "user sources" (such as sourceSceneRefs) and instead simply holds its own references and saves sources it chooses with obs_save_sources_filtered.
This commit is contained in:
parent
e3795a2187
commit
3c83be374e
@ -227,12 +227,15 @@ OBSBasic::OBSBasic(QWidget *parent)
|
|||||||
addNudge(Qt::Key_Right, SLOT(NudgeRight()));
|
addNudge(Qt::Key_Right, SLOT(NudgeRight()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SaveAudioDevice(const char *name, int channel, obs_data_t *parent)
|
static void SaveAudioDevice(const char *name, int channel, obs_data_t *parent,
|
||||||
|
vector<OBSSource> &audioSources)
|
||||||
{
|
{
|
||||||
obs_source_t *source = obs_get_output_source(channel);
|
obs_source_t *source = obs_get_output_source(channel);
|
||||||
if (!source)
|
if (!source)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
audioSources.push_back(source);
|
||||||
|
|
||||||
obs_data_t *data = obs_save_source(source);
|
obs_data_t *data = obs_save_source(source);
|
||||||
|
|
||||||
obs_data_set_obj(parent, name, data);
|
obs_data_set_obj(parent, name, data);
|
||||||
@ -243,20 +246,36 @@ static void SaveAudioDevice(const char *name, int channel, obs_data_t *parent)
|
|||||||
|
|
||||||
static obs_data_t *GenerateSaveData(obs_data_array_t *sceneOrder)
|
static obs_data_t *GenerateSaveData(obs_data_array_t *sceneOrder)
|
||||||
{
|
{
|
||||||
obs_data_t *saveData = obs_data_create();
|
obs_data_t *saveData = obs_data_create();
|
||||||
obs_data_array_t *sourcesArray = obs_save_sources();
|
|
||||||
obs_source_t *currentScene = obs_get_output_source(0);
|
vector<OBSSource> audioSources;
|
||||||
const char *sceneName = obs_source_get_name(currentScene);
|
audioSources.reserve(5);
|
||||||
|
|
||||||
|
SaveAudioDevice(DESKTOP_AUDIO_1, 1, saveData, audioSources);
|
||||||
|
SaveAudioDevice(DESKTOP_AUDIO_2, 2, saveData, audioSources);
|
||||||
|
SaveAudioDevice(AUX_AUDIO_1, 3, saveData, audioSources);
|
||||||
|
SaveAudioDevice(AUX_AUDIO_2, 4, saveData, audioSources);
|
||||||
|
SaveAudioDevice(AUX_AUDIO_3, 5, saveData, audioSources);
|
||||||
|
|
||||||
|
auto FilterAudioSources = [&](obs_source_t *source)
|
||||||
|
{
|
||||||
|
return find(begin(audioSources), end(audioSources), source) ==
|
||||||
|
end(audioSources);
|
||||||
|
};
|
||||||
|
using FilterAudioSources_t = decltype(FilterAudioSources);
|
||||||
|
|
||||||
|
obs_data_array_t *sourcesArray = obs_save_sources_filtered(
|
||||||
|
[](void *data, obs_source_t *source)
|
||||||
|
{
|
||||||
|
return (*static_cast<FilterAudioSources_t*>(data))(source);
|
||||||
|
}, static_cast<void*>(&FilterAudioSources));
|
||||||
|
|
||||||
|
obs_source_t *currentScene = obs_get_output_source(0);
|
||||||
|
const char *sceneName = obs_source_get_name(currentScene);
|
||||||
|
|
||||||
const char *sceneCollection = config_get_string(App()->GlobalConfig(),
|
const char *sceneCollection = config_get_string(App()->GlobalConfig(),
|
||||||
"Basic", "SceneCollection");
|
"Basic", "SceneCollection");
|
||||||
|
|
||||||
SaveAudioDevice(DESKTOP_AUDIO_1, 1, saveData);
|
|
||||||
SaveAudioDevice(DESKTOP_AUDIO_2, 2, saveData);
|
|
||||||
SaveAudioDevice(AUX_AUDIO_1, 3, saveData);
|
|
||||||
SaveAudioDevice(AUX_AUDIO_2, 4, saveData);
|
|
||||||
SaveAudioDevice(AUX_AUDIO_3, 5, saveData);
|
|
||||||
|
|
||||||
obs_data_set_string(saveData, "current_scene", sceneName);
|
obs_data_set_string(saveData, "current_scene", sceneName);
|
||||||
obs_data_set_array(saveData, "scene_order", sceneOrder);
|
obs_data_set_array(saveData, "scene_order", sceneOrder);
|
||||||
obs_data_set_string(saveData, "name", sceneCollection);
|
obs_data_set_string(saveData, "name", sceneCollection);
|
||||||
@ -380,9 +399,6 @@ void OBSBasic::CreateDefaultScene(bool firstStart)
|
|||||||
ClearSceneData();
|
ClearSceneData();
|
||||||
|
|
||||||
obs_scene_t *scene = obs_scene_create(Str("Basic.Scene"));
|
obs_scene_t *scene = obs_scene_create(Str("Basic.Scene"));
|
||||||
obs_source_t *source = obs_scene_get_source(scene);
|
|
||||||
|
|
||||||
obs_add_source(source);
|
|
||||||
|
|
||||||
if (firstStart)
|
if (firstStart)
|
||||||
CreateFirstRunSources();
|
CreateFirstRunSources();
|
||||||
@ -422,30 +438,6 @@ void OBSBasic::LoadSceneListOrder(obs_data_array_t *array)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBSBasic::CleanupUnusedSources()
|
|
||||||
{
|
|
||||||
auto removeUnusedSources = [&](obs_source_t *source)
|
|
||||||
{
|
|
||||||
obs_scene_t *scene = obs_scene_from_source(source);
|
|
||||||
if (scene)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (sourceSceneRefs[source] == 0) {
|
|
||||||
sourceSceneRefs.erase(source);
|
|
||||||
obs_source_remove(source);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
using func_type = decltype(removeUnusedSources);
|
|
||||||
|
|
||||||
obs_enum_sources(
|
|
||||||
[](void *f, obs_source_t *source)
|
|
||||||
{
|
|
||||||
(*static_cast<func_type*>(f))(source);
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
static_cast<void*>(&removeUnusedSources));
|
|
||||||
}
|
|
||||||
|
|
||||||
void OBSBasic::Load(const char *file)
|
void OBSBasic::Load(const char *file)
|
||||||
{
|
{
|
||||||
if (!file || !os_file_exists(file)) {
|
if (!file || !os_file_exists(file)) {
|
||||||
@ -513,8 +505,6 @@ void OBSBasic::Load(const char *file)
|
|||||||
|
|
||||||
obs_data_release(data);
|
obs_data_release(data);
|
||||||
|
|
||||||
CleanupUnusedSources();
|
|
||||||
|
|
||||||
disableSaving--;
|
disableSaving--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -776,8 +766,8 @@ void OBSBasic::InitOBSCallbacks()
|
|||||||
ProfileScope("OBSBasic::InitOBSCallbacks");
|
ProfileScope("OBSBasic::InitOBSCallbacks");
|
||||||
|
|
||||||
signalHandlers.reserve(signalHandlers.size() + 6);
|
signalHandlers.reserve(signalHandlers.size() + 6);
|
||||||
signalHandlers.emplace_back(obs_get_signal_handler(), "source_add",
|
signalHandlers.emplace_back(obs_get_signal_handler(), "source_load",
|
||||||
OBSBasic::SourceAdded, this);
|
OBSBasic::SourceLoaded, this);
|
||||||
signalHandlers.emplace_back(obs_get_signal_handler(), "source_remove",
|
signalHandlers.emplace_back(obs_get_signal_handler(), "source_remove",
|
||||||
OBSBasic::SourceRemoved, this);
|
OBSBasic::SourceRemoved, this);
|
||||||
signalHandlers.emplace_back(obs_get_signal_handler(), "channel_change",
|
signalHandlers.emplace_back(obs_get_signal_handler(), "channel_change",
|
||||||
@ -1395,37 +1385,16 @@ void OBSBasic::RemoveScene(OBSSource source)
|
|||||||
delete sel;
|
delete sel;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto DeleteSceneRefs = [&](obs_sceneitem_t *si)
|
|
||||||
{
|
|
||||||
obs_source_t *source = obs_sceneitem_get_source(si);
|
|
||||||
sourceSceneRefs[source] -= 1;
|
|
||||||
|
|
||||||
if (!sourceSceneRefs[source]) {
|
|
||||||
obs_source_remove(source);
|
|
||||||
sourceSceneRefs.erase(source);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
using DeleteSceneRefs_t = decltype(DeleteSceneRefs);
|
|
||||||
|
|
||||||
obs_scene_enum_items(obs_scene_from_source(source),
|
|
||||||
[](obs_scene_t *, obs_sceneitem_t *si, void *data)
|
|
||||||
{
|
|
||||||
(*static_cast<DeleteSceneRefs_t*>(data))(si);
|
|
||||||
return true;
|
|
||||||
}, static_cast<void*>(&DeleteSceneRefs));
|
|
||||||
|
|
||||||
SaveProject();
|
SaveProject();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBSBasic::AddSceneItem(OBSSceneItem item)
|
void OBSBasic::AddSceneItem(OBSSceneItem item)
|
||||||
{
|
{
|
||||||
obs_scene_t *scene = obs_sceneitem_get_scene(item);
|
obs_scene_t *scene = obs_sceneitem_get_scene(item);
|
||||||
obs_source_t *source = obs_sceneitem_get_source(item);
|
|
||||||
|
|
||||||
if (GetCurrentScene() == scene)
|
if (GetCurrentScene() == scene)
|
||||||
InsertSceneItem(item);
|
InsertSceneItem(item);
|
||||||
|
|
||||||
sourceSceneRefs[source] = sourceSceneRefs[source] + 1;
|
|
||||||
SaveProject();
|
SaveProject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1444,16 +1413,6 @@ void OBSBasic::RemoveSceneItem(OBSSceneItem item)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
obs_source_t *source = obs_sceneitem_get_source(item);
|
|
||||||
|
|
||||||
int scenes = sourceSceneRefs[source] - 1;
|
|
||||||
sourceSceneRefs[source] = scenes;
|
|
||||||
|
|
||||||
if (scenes == 0) {
|
|
||||||
obs_source_remove(source);
|
|
||||||
sourceSceneRefs.erase(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
SaveProject();
|
SaveProject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1770,7 +1729,6 @@ void OBSBasic::DuplicateSelectedScene()
|
|||||||
obs_scene_t *scene = obs_scene_duplicate(curScene,
|
obs_scene_t *scene = obs_scene_duplicate(curScene,
|
||||||
name.c_str());
|
name.c_str());
|
||||||
source = obs_scene_get_source(scene);
|
source = obs_scene_get_source(scene);
|
||||||
obs_add_source(source);
|
|
||||||
obs_scene_release(scene);
|
obs_scene_release(scene);
|
||||||
|
|
||||||
obs_set_output_source(0, source);
|
obs_set_output_source(0, source);
|
||||||
@ -1913,7 +1871,7 @@ void OBSBasic::SceneItemDeselected(void *data, calldata_t *params)
|
|||||||
Q_ARG(bool, false));
|
Q_ARG(bool, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBSBasic::SourceAdded(void *data, calldata_t *params)
|
void OBSBasic::SourceLoaded(void *data, calldata_t *params)
|
||||||
{
|
{
|
||||||
OBSBasic *window = static_cast<OBSBasic*>(data);
|
OBSBasic *window = static_cast<OBSBasic*>(data);
|
||||||
obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
|
obs_source_t *source = (obs_source_t*)calldata_ptr(params, "source");
|
||||||
@ -2286,8 +2244,6 @@ void OBSBasic::ClearSceneData()
|
|||||||
|
|
||||||
obs_enum_sources(cb, nullptr);
|
obs_enum_sources(cb, nullptr);
|
||||||
|
|
||||||
sourceSceneRefs.clear();
|
|
||||||
|
|
||||||
disableSaving--;
|
disableSaving--;
|
||||||
|
|
||||||
blog(LOG_INFO, "All scene data cleared");
|
blog(LOG_INFO, "All scene data cleared");
|
||||||
@ -2532,10 +2488,9 @@ void OBSBasic::on_actionAddScene_triggered()
|
|||||||
|
|
||||||
obs_scene_t *scene = obs_scene_create(name.c_str());
|
obs_scene_t *scene = obs_scene_create(name.c_str());
|
||||||
source = obs_scene_get_source(scene);
|
source = obs_scene_get_source(scene);
|
||||||
obs_add_source(source);
|
AddScene(source);
|
||||||
obs_scene_release(scene);
|
|
||||||
|
|
||||||
obs_set_output_source(0, source);
|
obs_set_output_source(0, source);
|
||||||
|
obs_scene_release(scene);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <obs.hpp>
|
#include <obs.hpp>
|
||||||
#include <unordered_map>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "window-main.hpp"
|
#include "window-main.hpp"
|
||||||
@ -71,8 +70,6 @@ class OBSBasic : public OBSMainWindow {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<obs_source_t*, int> sourceSceneRefs;
|
|
||||||
|
|
||||||
std::vector<VolControl*> volumes;
|
std::vector<VolControl*> volumes;
|
||||||
|
|
||||||
std::vector<OBSSignal> signalHandlers;
|
std::vector<OBSSignal> signalHandlers;
|
||||||
@ -170,7 +167,6 @@ private:
|
|||||||
|
|
||||||
void CloseDialogs();
|
void CloseDialogs();
|
||||||
void ClearSceneData();
|
void ClearSceneData();
|
||||||
void CleanupUnusedSources();
|
|
||||||
|
|
||||||
void Nudge(int dist, MoveDir dir);
|
void Nudge(int dist, MoveDir dir);
|
||||||
void OpenProjector(obs_source_t *source, int monitor);
|
void OpenProjector(obs_source_t *source, int monitor);
|
||||||
@ -244,7 +240,7 @@ private:
|
|||||||
static void SceneItemRemoved(void *data, calldata_t *params);
|
static void SceneItemRemoved(void *data, calldata_t *params);
|
||||||
static void SceneItemSelected(void *data, calldata_t *params);
|
static void SceneItemSelected(void *data, calldata_t *params);
|
||||||
static void SceneItemDeselected(void *data, calldata_t *params);
|
static void SceneItemDeselected(void *data, calldata_t *params);
|
||||||
static void SourceAdded(void *data, calldata_t *params);
|
static void SourceLoaded(void *data, calldata_t *params);
|
||||||
static void SourceRemoved(void *data, calldata_t *params);
|
static void SourceRemoved(void *data, calldata_t *params);
|
||||||
static void SourceActivated(void *data, calldata_t *params);
|
static void SourceActivated(void *data, calldata_t *params);
|
||||||
static void SourceDeactivated(void *data, calldata_t *params);
|
static void SourceDeactivated(void *data, calldata_t *params);
|
||||||
|
@ -1543,14 +1543,6 @@ void OBSBasicSettings::LoadAudioSources()
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int i = 0; i < MAX_CHANNELS; i++) {
|
|
||||||
obs_source_t *source = obs_get_output_source(i);
|
|
||||||
if (!source) continue;
|
|
||||||
|
|
||||||
AddSource(source);
|
|
||||||
obs_source_release(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
using AddSource_t = decltype(AddSource);
|
using AddSource_t = decltype(AddSource);
|
||||||
obs_enum_sources([](void *data, obs_source_t *source)
|
obs_enum_sources([](void *data, obs_source_t *source)
|
||||||
{
|
{
|
||||||
|
@ -133,8 +133,6 @@ bool AddNew(QWidget *parent, const char *id, const char *name,
|
|||||||
id, name, NULL, nullptr);
|
id, name, NULL, nullptr);
|
||||||
|
|
||||||
if (source) {
|
if (source) {
|
||||||
obs_add_source(source);
|
|
||||||
|
|
||||||
AddSourceData data;
|
AddSourceData data;
|
||||||
data.source = source;
|
data.source = source;
|
||||||
data.visible = visible;
|
data.visible = visible;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user