mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
General: code style refresh
This commit is contained in:
75
Utils.cpp
75
Utils.cpp
@ -49,14 +49,16 @@ obs_data_array_t* string_list_to_array(char** strings, char* key)
|
||||
return list;
|
||||
}
|
||||
|
||||
obs_data_array_t* Utils::GetSceneItems(obs_source_t *source) {
|
||||
obs_data_array_t* Utils::GetSceneItems(obs_source_t* source)
|
||||
{
|
||||
obs_data_array_t* items = obs_data_array_create();
|
||||
obs_scene_t* scene = obs_scene_from_source(source);
|
||||
if (scene == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
obs_scene_enum_items(scene, [](obs_scene_t *scene, obs_sceneitem_t *currentItem, void *param) {
|
||||
if (!scene)
|
||||
return nullptr;
|
||||
|
||||
obs_scene_enum_items(scene, [](obs_scene_t* scene, obs_sceneitem_t* currentItem, void* param)
|
||||
{
|
||||
obs_data_array_t* data = static_cast<obs_data_array_t* >(param);
|
||||
|
||||
obs_data_t* item_data = GetSceneItemData(currentItem);
|
||||
@ -69,10 +71,10 @@ obs_data_array_t* Utils::GetSceneItems(obs_source_t *source) {
|
||||
return items;
|
||||
}
|
||||
|
||||
obs_data_t* Utils::GetSceneItemData(obs_sceneitem_t *item) {
|
||||
if (!item) {
|
||||
return NULL;
|
||||
}
|
||||
obs_data_t* Utils::GetSceneItemData(obs_sceneitem_t* item)
|
||||
{
|
||||
if (!item)
|
||||
return nullptr;
|
||||
|
||||
vec2 pos;
|
||||
obs_sceneitem_get_pos(item, &pos);
|
||||
@ -102,7 +104,8 @@ obs_data_t* Utils::GetSceneItemData(obs_sceneitem_t *item) {
|
||||
return data;
|
||||
}
|
||||
|
||||
obs_sceneitem_t* Utils::GetSceneItemFromName(obs_source_t* source, const char* name) {
|
||||
obs_sceneitem_t* Utils::GetSceneItemFromName(obs_source_t* source, const char* name)
|
||||
{
|
||||
struct current_search {
|
||||
const char* query;
|
||||
obs_sceneitem_t* result;
|
||||
@ -110,20 +113,21 @@ obs_sceneitem_t* Utils::GetSceneItemFromName(obs_source_t* source, const char* n
|
||||
|
||||
current_search search;
|
||||
search.query = name;
|
||||
search.result = NULL;
|
||||
search.result = nullptr;
|
||||
|
||||
obs_scene_t* scene = obs_scene_from_source(source);
|
||||
if (scene == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (scene == nullptr)
|
||||
return nullptr;
|
||||
|
||||
obs_scene_enum_items(scene, [](obs_scene_t *scene, obs_sceneitem_t *currentItem, void *param) {
|
||||
obs_scene_enum_items(scene, [](obs_scene_t* scene, obs_sceneitem_t* currentItem, void* param)
|
||||
{
|
||||
current_search* search = static_cast<current_search* >(param);
|
||||
|
||||
const char* currentItemName =
|
||||
obs_source_get_name(obs_sceneitem_get_source(currentItem));
|
||||
|
||||
if (strcmp(currentItemName, search->query) == 0) {
|
||||
if (strcmp(currentItemName, search->query) == 0)
|
||||
{
|
||||
search->result = currentItem;
|
||||
obs_sceneitem_addref(search->result);
|
||||
return false;
|
||||
@ -135,17 +139,20 @@ obs_sceneitem_t* Utils::GetSceneItemFromName(obs_source_t* source, const char* n
|
||||
return search.result;
|
||||
}
|
||||
|
||||
obs_source_t* Utils::GetTransitionFromName(const char *search_name) {
|
||||
obs_source_t* Utils::GetTransitionFromName(const char* search_name)
|
||||
{
|
||||
obs_source_t* found_transition = NULL;
|
||||
|
||||
obs_frontend_source_list transition_list = {};
|
||||
obs_frontend_get_transitions(&transition_list);
|
||||
|
||||
for (size_t i = 0; i < transition_list.sources.num; i++) {
|
||||
for (size_t i = 0; i < transition_list.sources.num; i++)
|
||||
{
|
||||
obs_source_t* transition = transition_list.sources.array[i];
|
||||
|
||||
const char* transition_name = obs_source_get_name(transition);
|
||||
if (strcmp(transition_name, search_name) == 0) {
|
||||
if (strcmp(transition_name, search_name) == 0)
|
||||
{
|
||||
found_transition = transition;
|
||||
obs_source_addref(found_transition);
|
||||
break;
|
||||
@ -157,24 +164,26 @@ obs_source_t* Utils::GetTransitionFromName(const char *search_name) {
|
||||
return found_transition;
|
||||
}
|
||||
|
||||
obs_source_t* Utils::GetSceneFromNameOrCurrent(const char *scene_name) {
|
||||
obs_source_t* scene;
|
||||
if (!scene_name || !strlen(scene_name)) {
|
||||
obs_source_t* Utils::GetSceneFromNameOrCurrent(const char* scene_name)
|
||||
{
|
||||
obs_source_t* scene = nullptr;
|
||||
|
||||
if (!scene_name || !strlen(scene_name))
|
||||
scene = obs_frontend_get_current_scene();
|
||||
}
|
||||
else {
|
||||
else
|
||||
scene = obs_get_source_by_name(scene_name);
|
||||
}
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
obs_data_array_t* Utils::GetScenes() {
|
||||
obs_data_array_t* Utils::GetScenes()
|
||||
{
|
||||
obs_frontend_source_list sceneList = {};
|
||||
obs_frontend_get_scenes(&sceneList);
|
||||
|
||||
obs_data_array_t* scenes = obs_data_array_create();
|
||||
for (size_t i = 0; i < sceneList.sources.num; i++) {
|
||||
for (size_t i = 0; i < sceneList.sources.num; i++)
|
||||
{
|
||||
obs_source_t* scene = sceneList.sources.array[i];
|
||||
|
||||
obs_data_t* scene_data = GetSceneData(scene);
|
||||
@ -188,7 +197,8 @@ obs_data_array_t* Utils::GetScenes() {
|
||||
return scenes;
|
||||
}
|
||||
|
||||
obs_data_t* Utils::GetSceneData(obs_source *source) {
|
||||
obs_data_t* Utils::GetSceneData(obs_source* source)
|
||||
{
|
||||
obs_data_array_t* scene_items = GetSceneItems(source);
|
||||
|
||||
obs_data_t* sceneData = obs_data_create();
|
||||
@ -227,24 +237,18 @@ int Utils::GetTransitionDuration()
|
||||
{
|
||||
QSpinBox* control = GetTransitionDurationControl();
|
||||
if (control)
|
||||
{
|
||||
return control->value();
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void Utils::SetTransitionDuration(int ms)
|
||||
{
|
||||
QSpinBox* control = GetTransitionDurationControl();
|
||||
|
||||
if (control && ms >= 0)
|
||||
{
|
||||
control->setValue(ms);
|
||||
}
|
||||
}
|
||||
|
||||
bool Utils::SetTransitionByName(const char* transition_name)
|
||||
{
|
||||
@ -412,7 +416,6 @@ void Utils::SysTrayNotify(QString &text, QSystemTrayIcon::MessageIcon icon, QStr
|
||||
return;
|
||||
|
||||
QSystemTrayIcon* trayIcon = GetTrayIcon();
|
||||
|
||||
if (trayIcon)
|
||||
trayIcon->showMessage(title, text, icon);
|
||||
}
|
||||
@ -420,9 +423,7 @@ void Utils::SysTrayNotify(QString &text, QSystemTrayIcon::MessageIcon icon, QStr
|
||||
QString Utils::FormatIPAddress(QHostAddress &addr)
|
||||
{
|
||||
if (addr.protocol() == QAbstractSocket::IPv4Protocol)
|
||||
{
|
||||
QString v4addr = addr.toString().replace("::fff:", "");
|
||||
}
|
||||
|
||||
return addr.toString();
|
||||
}
|
||||
|
20
WSEvents.cpp
20
WSEvents.cpp
@ -210,9 +210,8 @@ void WSEvents::broadcastUpdate(const char *updateType, obs_data_t *additionalFie
|
||||
bfree((void*)ts);
|
||||
}
|
||||
|
||||
if (additionalFields != NULL) {
|
||||
if (additionalFields != NULL)
|
||||
obs_data_apply(update, additionalFields);
|
||||
}
|
||||
|
||||
_srv->broadcast(obs_data_get_json(update));
|
||||
|
||||
@ -231,7 +230,8 @@ void WSEvents::connectTransitionSignals(obs_source_t* transition)
|
||||
{
|
||||
transition_handler = obs_source_get_signal_handler(transition);
|
||||
signal_handler_connect(transition_handler,
|
||||
"transition_start", OnTransitionBegin, this); }
|
||||
"transition_start", OnTransitionBegin, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
transition_handler = nullptr;
|
||||
@ -447,22 +447,22 @@ void WSEvents::StreamStatus()
|
||||
|
||||
obs_output_t* stream_output = obs_frontend_get_streaming_output();
|
||||
|
||||
if (!stream_output || !streaming_active) {
|
||||
if (stream_output) {
|
||||
if (!stream_output || !streaming_active)
|
||||
{
|
||||
if (stream_output)
|
||||
obs_output_release(stream_output);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t bytes_sent = obs_output_get_total_bytes(stream_output);
|
||||
uint64_t bytes_sent_time = os_gettime_ns();
|
||||
|
||||
if (bytes_sent < _lastBytesSent) {
|
||||
if (bytes_sent < _lastBytesSent)
|
||||
bytes_sent = 0;
|
||||
}
|
||||
if (bytes_sent == 0) {
|
||||
|
||||
if (bytes_sent == 0)
|
||||
_lastBytesSent = 0;
|
||||
}
|
||||
|
||||
uint64_t bytes_between = bytes_sent - _lastBytesSent;
|
||||
double time_passed =
|
||||
|
@ -100,9 +100,7 @@ void WSRequestHandler::processIncomingMessage(QString textMessage)
|
||||
if (!data)
|
||||
{
|
||||
if (!msg)
|
||||
{
|
||||
msg = "<null pointer>";
|
||||
}
|
||||
|
||||
blog(LOG_ERROR, "invalid JSON payload received for '%s'", msg);
|
||||
SendErrorResponse("invalid JSON payload");
|
||||
@ -474,9 +472,7 @@ void WSRequestHandler::HandleGetCurrentTransition(WSRequestHandler *req)
|
||||
obs_source_get_name(current_transition));
|
||||
|
||||
if (!obs_transition_fixed(current_transition))
|
||||
{
|
||||
obs_data_set_int(response, "duration", Utils::GetTransitionDuration());
|
||||
}
|
||||
|
||||
req->SendOKResponse(response);
|
||||
|
||||
|
@ -49,7 +49,6 @@ WSServer::WSServer(QObject *parent) :
|
||||
WSServer::~WSServer()
|
||||
{
|
||||
Stop();
|
||||
|
||||
delete _serverThread;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user