mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
Utils: Add more OBS utils
This commit is contained in:
parent
ab12d5f39f
commit
c8eac893f2
@ -1,9 +1,30 @@
|
|||||||
|
#include <obs.hpp>
|
||||||
|
#include <obs-frontend-api.h>
|
||||||
|
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
#include "../plugin-macros.generated.h"
|
#include "../plugin-macros.generated.h"
|
||||||
|
|
||||||
#define CASE(x) case x: return #x;
|
#define CASE(x) case x: return #x;
|
||||||
|
|
||||||
|
std::vector<std::string> ConvertStringArray(char **array)
|
||||||
|
{
|
||||||
|
std::vector<std::string> ret;
|
||||||
|
if (!array)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
size_t index = 0;
|
||||||
|
char* value = nullptr;
|
||||||
|
do {
|
||||||
|
value = array[index];
|
||||||
|
if (value)
|
||||||
|
ret.push_back(value);
|
||||||
|
index++;
|
||||||
|
} while (value);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
std::string Utils::Obs::DataHelper::GetSourceTypeString(obs_source_t *source)
|
std::string Utils::Obs::DataHelper::GetSourceTypeString(obs_source_t *source)
|
||||||
{
|
{
|
||||||
obs_source_type sourceType = obs_source_get_type(source);
|
obs_source_type sourceType = obs_source_get_type(source);
|
||||||
@ -45,3 +66,38 @@ std::string Utils::Obs::DataHelper::GetSourceMediaStateString(obs_source_t *sour
|
|||||||
CASE(OBS_MEDIA_STATE_ERROR)
|
CASE(OBS_MEDIA_STATE_ERROR)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> Utils::Obs::ListHelper::GetSceneCollectionList()
|
||||||
|
{
|
||||||
|
char** sceneCollections = obs_frontend_get_scene_collections();
|
||||||
|
auto ret = ConvertStringArray(sceneCollections);
|
||||||
|
bfree(sceneCollections);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> Utils::Obs::ListHelper::GetProfileList()
|
||||||
|
{
|
||||||
|
char** profiles = obs_frontend_get_profiles();
|
||||||
|
auto ret = ConvertStringArray(profiles);
|
||||||
|
bfree(profiles);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<json> Utils::Obs::ListHelper::GetSceneList()
|
||||||
|
{
|
||||||
|
obs_frontend_source_list sceneList = {};
|
||||||
|
obs_frontend_get_scenes(&sceneList);
|
||||||
|
|
||||||
|
std::vector<json> ret;
|
||||||
|
for (size_t i = 0; i < sceneList.sources.num; i++) {
|
||||||
|
json sceneJson;
|
||||||
|
obs_source_t *scene = sceneList.sources.array[i];
|
||||||
|
sceneJson["sceneName"] = obs_source_get_name(scene);
|
||||||
|
sceneJson["sceneIndex"] = i;
|
||||||
|
ret.push_back(sceneJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_frontend_source_list_free(&sceneList);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -32,5 +32,11 @@ namespace Utils {
|
|||||||
std::string GetSourceMonitorTypeString(obs_source_t *source);
|
std::string GetSourceMonitorTypeString(obs_source_t *source);
|
||||||
std::string GetSourceMediaStateString(obs_source_t *source);
|
std::string GetSourceMediaStateString(obs_source_t *source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace ListHelper {
|
||||||
|
std::vector<std::string> GetSceneCollectionList();
|
||||||
|
std::vector<std::string> GetProfileList();
|
||||||
|
std::vector<json> GetSceneList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user