Base: Lots of changes

This commit is contained in:
tt2468 2021-08-27 04:19:42 -07:00
parent 16697fb65e
commit 0547e1f2da
12 changed files with 91 additions and 30 deletions

View File

@ -101,7 +101,7 @@ WebSocketProtocol::ProcessResult WebSocketProtocol::ProcessMessage(SessionPtr se
} }
RequestHandler requestHandler; RequestHandler requestHandler;
Request request(session->RpcVersion(), session->IgnoreNonFatalRequestChecks(), incomingMessage["requestType"], incomingMessage["requestData"]); Request request(session, incomingMessage["requestType"], incomingMessage["requestData"]);
RequestResult requestResult = requestHandler.ProcessRequest(request); RequestResult requestResult = requestHandler.ProcessRequest(request);
@ -144,7 +144,7 @@ WebSocketProtocol::ProcessResult WebSocketProtocol::ProcessMessage(SessionPtr se
if (!requestJson["requestType"].is_string()) if (!requestJson["requestType"].is_string())
requestJson["requestType"] = ""; requestJson["requestType"] = "";
Request request(session->RpcVersion(), session->IgnoreNonFatalRequestChecks(), requestJson["requestType"], requestJson["requestData"]); Request request(session, requestJson["requestType"], requestJson["requestData"]);
RequestResult requestResult = requestHandler.ProcessRequest(request); RequestResult requestResult = requestHandler.ProcessRequest(request);

View File

@ -8,24 +8,6 @@
#include "../obs-websocket.h" #include "../obs-websocket.h"
#include "../WebSocketServer.h" #include "../WebSocketServer.h"
enum ObsOutputState {
OBS_WEBSOCKET_OUTPUT_STARTING,
OBS_WEBSOCKET_OUTPUT_STARTED,
OBS_WEBSOCKET_OUTPUT_STOPPING,
OBS_WEBSOCKET_OUTPUT_STOPPED,
OBS_WEBSOCKET_OUTPUT_PAUSED,
OBS_WEBSOCKET_OUTPUT_RESUMED
};
enum ObsMediaInputAction {
OBS_WEBSOCKET_MEDIA_INPUT_ACTION_PAUSE,
OBS_WEBSOCKET_MEDIA_INPUT_ACTION_PLAY,
OBS_WEBSOCKET_MEDIA_INPUT_ACTION_RESTART,
OBS_WEBSOCKET_MEDIA_INPUT_ACTION_STOP,
OBS_WEBSOCKET_MEDIA_INPUT_ACTION_NEXT,
OBS_WEBSOCKET_MEDIA_INPUT_ACTION_PREVIOUS
};
template <typename T> T* GetCalldataPointer(const calldata_t *data, const char* name) { template <typename T> T* GetCalldataPointer(const calldata_t *data, const char* name) {
void *ptr = nullptr; void *ptr = nullptr;
calldata_get_ptr(data, name, &ptr); calldata_get_ptr(data, name, &ptr);

View File

@ -20,6 +20,7 @@ ConfigPtr _config;
WebSocketServerPtr _webSocketServer; WebSocketServerPtr _webSocketServer;
EventHandlerPtr _eventHandler; EventHandlerPtr _eventHandler;
SettingsDialog *_settingsDialog = nullptr; SettingsDialog *_settingsDialog = nullptr;
os_cpu_usage_info_t* _cpuUsageInfo;
void ___source_dummy_addref(obs_source_t*) {} void ___source_dummy_addref(obs_source_t*) {}
void ___sceneitem_dummy_addref(obs_sceneitem_t*) {}; void ___sceneitem_dummy_addref(obs_sceneitem_t*) {};
@ -55,12 +56,14 @@ bool obs_module_load(void)
QAction* menuAction = (QAction*)obs_frontend_add_tools_menu_qaction(menuActionText); QAction* menuAction = (QAction*)obs_frontend_add_tools_menu_qaction(menuActionText);
QObject::connect(menuAction, &QAction::triggered, [] { _settingsDialog->ToggleShowHide(); }); QObject::connect(menuAction, &QAction::triggered, [] { _settingsDialog->ToggleShowHide(); });
// Loading finished _cpuUsageInfo = os_cpu_usage_info_start();
blog(LOG_INFO, "[obs_module_load] Module loaded.");
if (_config->ServerEnabled) if (_config->ServerEnabled)
_webSocketServer->Start(); _webSocketServer->Start();
// Loading finished
blog(LOG_INFO, "[obs_module_load] Module loaded.");
return true; return true;
} }
@ -80,6 +83,8 @@ void obs_module_unload()
_config->Save(); _config->Save();
_config.reset(); _config.reset();
os_cpu_usage_info_destroy(_cpuUsageInfo);
blog(LOG_INFO, "[obs_module_unload] Finished shutting down."); blog(LOG_INFO, "[obs_module_unload] Finished shutting down.");
} }
@ -97,3 +102,8 @@ EventHandlerPtr GetEventHandler()
{ {
return _eventHandler; return _eventHandler;
} }
os_cpu_usage_info_t* GetCpuUsageInfo()
{
return _cpuUsageInfo;
}

View File

@ -2,6 +2,7 @@
#include <memory> #include <memory>
#include <obs.hpp> #include <obs.hpp>
#include <util/platform.h>
// Autorelease object definitions // Autorelease object definitions
void ___source_dummy_addref(obs_source_t*); void ___source_dummy_addref(obs_source_t*);
@ -39,3 +40,5 @@ ConfigPtr GetConfig();
WebSocketServerPtr GetWebSocketServer(); WebSocketServerPtr GetWebSocketServer();
EventHandlerPtr GetEventHandler(); EventHandlerPtr GetEventHandler();
os_cpu_usage_info_t* GetCpuUsageInfo();

View File

@ -6,6 +6,7 @@ const std::map<std::string, RequestMethodHandler> RequestHandler::_handlerMap
// General // General
{"GetVersion", &RequestHandler::GetVersion}, {"GetVersion", &RequestHandler::GetVersion},
{"BroadcastCustomEvent", &RequestHandler::BroadcastCustomEvent}, {"BroadcastCustomEvent", &RequestHandler::BroadcastCustomEvent},
{"GetStats", &RequestHandler::GetStats},
{"GetHotkeyList", &RequestHandler::GetHotkeyList}, {"GetHotkeyList", &RequestHandler::GetHotkeyList},
{"TriggerHotkeyByName", &RequestHandler::TriggerHotkeyByName}, {"TriggerHotkeyByName", &RequestHandler::TriggerHotkeyByName},
{"TriggerHotkeyByKeySequence", &RequestHandler::TriggerHotkeyByKeySequence}, {"TriggerHotkeyByKeySequence", &RequestHandler::TriggerHotkeyByKeySequence},

View File

@ -21,6 +21,7 @@ class RequestHandler {
// General // General
RequestResult GetVersion(const Request&); RequestResult GetVersion(const Request&);
RequestResult BroadcastCustomEvent(const Request&); RequestResult BroadcastCustomEvent(const Request&);
RequestResult GetStats(const Request&);
RequestResult GetHotkeyList(const Request&); RequestResult GetHotkeyList(const Request&);
RequestResult TriggerHotkeyByName(const Request&); RequestResult TriggerHotkeyByName(const Request&);
RequestResult TriggerHotkeyByKeySequence(const Request&); RequestResult TriggerHotkeyByKeySequence(const Request&);

View File

@ -40,6 +40,16 @@ RequestResult RequestHandler::BroadcastCustomEvent(const Request& request)
return RequestResult::Success(); return RequestResult::Success();
} }
RequestResult RequestHandler::GetStats(const Request& request)
{
json responseData = Utils::Obs::DataHelper::GetStats();
responseData["webSocketSessionIncomingMessages"] = request.Session->IncomingMessages();
responseData["webSocketSessionOutgoingMessages"] = request.Session->OutgoingMessages();
return RequestResult::Success(responseData);
}
RequestResult RequestHandler::GetHotkeyList(const Request& request) RequestResult RequestHandler::GetHotkeyList(const Request& request)
{ {
json responseData; json responseData;

View File

@ -3,12 +3,16 @@
RequestResult RequestHandler::GetStreamStatus(const Request& request) RequestResult RequestHandler::GetStreamStatus(const Request& request)
{ {
json responseData;
OBSOutputAutoRelease streamOutput = obs_frontend_get_streaming_output(); OBSOutputAutoRelease streamOutput = obs_frontend_get_streaming_output();
json responseData;
responseData["outputActive"] = obs_output_active(streamOutput); responseData["outputActive"] = obs_output_active(streamOutput);
responseData["outputReconnecting"] = obs_output_reconnecting(streamOutput);
responseData["outputTimecode"] = Utils::Obs::StringHelper::GetOutputTimecodeString(streamOutput); responseData["outputTimecode"] = Utils::Obs::StringHelper::GetOutputTimecodeString(streamOutput);
responseData["outputDuration"] = Utils::Obs::NumberHelper::GetOutputDuration(streamOutput); responseData["outputDuration"] = Utils::Obs::NumberHelper::GetOutputDuration(streamOutput);
responseData["outputBytes"] = (uint64_t)obs_output_get_total_bytes(streamOutput);
responseData["outputSkippedFrames"] = obs_output_get_frames_dropped(streamOutput);
responseData["outputTotalFrames"] = obs_output_get_total_frames(streamOutput);
return RequestResult::Success(responseData); return RequestResult::Success(responseData);
} }

View File

@ -10,11 +10,12 @@ json GetDefaultJsonObject(json requestData)
return requestData; return requestData;
} }
Request::Request(uint8_t rpcVersion, bool ignoreNonFatalRequestChecks, std::string requestType, json requestData) : Request::Request(SessionPtr session, std::string requestType, json requestData) :
RpcVersion(rpcVersion), Session(session),
IgnoreNonFatalRequestChecks(ignoreNonFatalRequestChecks), RpcVersion(session->RpcVersion()),
RequestData(GetDefaultJsonObject(requestData)), IgnoreNonFatalRequestChecks(session->IgnoreNonFatalRequestChecks()),
RequestType(requestType) RequestType(requestType),
RequestData(GetDefaultJsonObject(requestData))
{ {
} }

View File

@ -1,11 +1,12 @@
#pragma once #pragma once
#include "RequestStatus.h" #include "RequestStatus.h"
#include "../../WebSocketSession.h"
#include "../../utils/Utils.h" #include "../../utils/Utils.h"
struct Request struct Request
{ {
Request(const uint8_t rpcVersion, const bool ignoreNonFatalRequestChecks, const std::string requestType, const json requestData = nullptr); Request(SessionPtr session, const std::string requestType, const json requestData = nullptr);
const bool HasRequestData() const const bool HasRequestData() const
{ {
@ -22,6 +23,7 @@ struct Request
obs_source_t *ValidateScene(const std::string keyName, RequestStatus::RequestStatus &statusCode, std::string &comment) const; obs_source_t *ValidateScene(const std::string keyName, RequestStatus::RequestStatus &statusCode, std::string &comment) const;
obs_source_t *ValidateInput(const std::string keyName, RequestStatus::RequestStatus &statusCode, std::string &comment) const; obs_source_t *ValidateInput(const std::string keyName, RequestStatus::RequestStatus &statusCode, std::string &comment) const;
SessionPtr Session;
const uint8_t RpcVersion; const uint8_t RpcVersion;
const bool IgnoreNonFatalRequestChecks; const bool IgnoreNonFatalRequestChecks;
const std::string RequestType; const std::string RequestType;

View File

@ -1,6 +1,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <QString> #include <QString>
#include <obs-frontend-api.h> #include <obs-frontend-api.h>
#include <util/config-file.h>
#include <util/util_uint64.h> #include <util/util_uint64.h>
#include "Obs.h" #include "Obs.h"
@ -332,6 +333,29 @@ std::vector<std::string> Utils::Obs::ListHelper::GetInputKindList(bool unversion
return ret; return ret;
} }
json Utils::Obs::DataHelper::GetStats()
{
json ret;
config_t* currentProfile = obs_frontend_get_profile_config();
const char* outputMode = config_get_string(currentProfile, "Output", "Mode");
const char* recordPath = strcmp(outputMode, "Advanced") ? config_get_string(currentProfile, "SimpleOutput", "FilePath") : config_get_string(currentProfile, "AdvOut", "RecFilePath");
video_t* video = obs_get_video();
ret["cpuUsage"] = os_cpu_usage_info_query(GetCpuUsageInfo());
ret["memoryUsage"] = (double)os_get_proc_resident_size() / (1024.0 * 1024.0);
ret["availableDiskSpace"] = (double)os_get_free_disk_space(recordPath) / (1024.0 * 1024.0);
ret["activeFps"] = obs_get_active_fps();
ret["averageFrameRenderTime"] = (double)obs_get_average_frame_time_ns() / 1000000.0;
ret["renderSkippedFrames"] = obs_get_lagged_frames();
ret["renderTotalFrames"] = obs_get_total_frames();
ret["outputSkippedFrames"] = video_output_get_skipped_frames(video);
ret["outputTotalFrames"] = video_output_get_total_frames(video);
return ret;
}
obs_hotkey_t *Utils::Obs::SearchHelper::GetHotkeyByName(std::string name) obs_hotkey_t *Utils::Obs::SearchHelper::GetHotkeyByName(std::string name)
{ {
auto hotkeys = ListHelper::GetHotkeyList(); auto hotkeys = ListHelper::GetHotkeyList();

View File

@ -5,6 +5,25 @@
#include "Json.h" #include "Json.h"
enum ObsOutputState {
OBS_WEBSOCKET_OUTPUT_STARTING,
OBS_WEBSOCKET_OUTPUT_STARTED,
OBS_WEBSOCKET_OUTPUT_STOPPING,
OBS_WEBSOCKET_OUTPUT_STOPPED,
OBS_WEBSOCKET_OUTPUT_RECONNECTING,
OBS_WEBSOCKET_OUTPUT_PAUSED,
OBS_WEBSOCKET_OUTPUT_RESUMED
};
enum ObsMediaInputAction {
OBS_WEBSOCKET_MEDIA_INPUT_ACTION_PAUSE,
OBS_WEBSOCKET_MEDIA_INPUT_ACTION_PLAY,
OBS_WEBSOCKET_MEDIA_INPUT_ACTION_RESTART,
OBS_WEBSOCKET_MEDIA_INPUT_ACTION_STOP,
OBS_WEBSOCKET_MEDIA_INPUT_ACTION_NEXT,
OBS_WEBSOCKET_MEDIA_INPUT_ACTION_PREVIOUS
};
namespace Utils { namespace Utils {
namespace Obs { namespace Obs {
namespace StringHelper { namespace StringHelper {
@ -35,6 +54,10 @@ namespace Utils {
std::vector<std::string> GetInputKindList(bool unversioned = false, bool includeDisabled = false); std::vector<std::string> GetInputKindList(bool unversioned = false, bool includeDisabled = false);
} }
namespace DataHelper {
json GetStats();
}
namespace SearchHelper { namespace SearchHelper {
obs_hotkey_t *GetHotkeyByName(std::string name); obs_hotkey_t *GetHotkeyByName(std::string name);
} }