diff --git a/docs/partials/introduction.md b/docs/partials/introduction.md index 4af3f9a6..48ccfa27 100644 --- a/docs/partials/introduction.md +++ b/docs/partials/introduction.md @@ -186,11 +186,11 @@ enum RequestStatus { Success = 100, - // The `requestType` key is missing from the request data + // The `requestType` field is missing from the request data MissingRequestType = 203, - // The request type is invalid (does not exist) + // The request type is invalid or does not exist UnknownRequestType = 204, - // Generic error code (comment is expected to be provided) + // Generic error code (comment required) GenericError = 205, // A required request parameter is missing @@ -198,10 +198,10 @@ enum RequestStatus { // The request does not have a valid requestData object. MissingRequestData = 301, - // Generic invalid request parameter message + // Generic invalid request parameter message (comment required) InvalidRequestParameter = 400, // A request parameter has the wrong data type - InvalidRequestParameterDataType = 401, + InvalidRequestParameterType = 401, // A request parameter (float or int) is out of valid range RequestParameterOutOfRange = 402, // A request parameter (string or array) is empty and cannot be @@ -213,102 +213,36 @@ enum RequestStatus { OutputRunning = 500, // An output is not running and should be OutputNotRunning = 501, - // Stream is running and cannot be - StreamRunning = 502, - // Stream is not running and should be - StreamNotRunning = 503, - // Record is running and cannot be - RecordRunning = 504, - // Record is not running and should be - RecordNotRunning = 505, - // Record is paused and cannot be - RecordPaused = 506, - // Replay buffer is running and cannot be - ReplayBufferRunning = 507, - // Replay buffer is not running and should be - ReplayBufferNotRunning = 508, - // Replay buffer is disabled and cannot be - ReplayBufferDisabled = 509, + // An output is paused and should not be + OutputPaused = 502, + // An output is disabled and should not be + OutputDisabled = 503, // Studio mode is active and cannot be - StudioModeActive = 510, + StudioModeActive = 504, // Studio mode is not active and should be - StudioModeNotActive = 511, - // Virtualcam is running and cannot be - VirtualcamRunning = 512, - // Virtualcam is not running and should be - VirtualcamNotRunning = 513, + StudioModeNotActive = 505, - // The specified source (obs_source_t) was of the invalid type (Eg. input instead of scene) - InvalidSourceType = 600, - // The specified source (obs_source_t) was not found (generic for input, filter, transition, scene) - SourceNotFound = 601, - // The specified source (obs_source_t) already exists. Applicable to inputs, filters, transitions, scenes - SourceAlreadyExists = 602, - // The specified input (obs_source_t-OBS_SOURCE_TYPE_FILTER) was not found - InputNotFound = 603, + // The resource was not found + ResourceNotFound = 600, + // The resource already exists + ResourceAlreadyExists = 601, + // The type of resource found is invalid + InvalidResourceType = 602, + // There are not enough instances of the resource in order to perform the request + NotEnoughResources = 603, + // The state of the resource is invalid. For example, if the resource is blocked from being accessed + InvalidResourceState = 604, // The specified input (obs_source_t-OBS_SOURCE_TYPE_INPUT) had the wrong kind - InvalidInputKind = 604, - // The specified filter (obs_source_t-OBS_SOURCE_TYPE_FILTER) was not found - FilterNotFound = 605, - // The specified transition (obs_source_t-OBS_SOURCE_TYPE_TRANSITION) was not found - TransitionNotFound = 606, - // The specified transition (obs_source_t-OBS_SOURCE_TYPE_TRANSITION) does not support setting its position (transition is of fixed type) - TransitionDurationFixed = 607, - // The specified scene (obs_source_t-OBS_SOURCE_TYPE_SCENE), (obs_scene_t) was not found - SceneNotFound = 608, - // The specified scene item (obs_sceneitem_t) was not found - SceneItemNotFound = 609, - // The specified scene collection was not found - SceneCollectionNotFound = 610, - // The specified profile was not found - ProfileNotFound = 611, - // The specified output (obs_output_t) was not found - OutputNotFound = 612, - // The specified encoder (obs_encoder_t) was not found - EncoderNotFound = 613, - // The specified service (obs_service_t) was not found - ServiceNotFound = 614, - // The specified hotkey was not found - HotkeyNotFound = 615, - // The specified directory was not found - DirectoryNotFound = 616, - // The specified config item (config_t) was not found. Could be section or parameter name - ConfigParameterNotFound = 617, - // The specified property (obs_properties_t) was not found - PropertyNotFound = 618, - // The specififed key (OBS_KEY_*) was not found - KeyNotFound = 619, - // The specified data realm (OBS_WEBSOCKET_DATA_REALM_*) was not found - DataRealmNotFound = 620, - // The scene collection already exists - SceneCollectionAlreadyExists = 621, - // There are not enough scene collections to perform the action - NotEnoughSceneCollections = 622, - // The profile already exists - ProfileAlreadyExists = 623, - // There are not enough profiles to perform the action - NotEnoughProfiles = 624, - // There are not enough scenes to perform the action - NotEnoughScenes = 625, + InvalidInputKind = 605, - // Processing the request failed unexpectedly - RequestProcessingFailed = 700, - // Starting the Output failed - OutputStartFailed = 701, - // Duplicating the scene item failed - SceneItemDuplicationFailed = 702, - // Rendering the screenshot failed - ScreenshotRenderFailed = 703, - // Encoding the screenshot failed - ScreenshotEncodeFailed = 704, - // Saving the screenshot failed - ScreenshotSaveFailed = 705, - // Creating the directory failed - DirectoryCreationFailed = 706, + // Creating the resource failed + ResourceCreationFailed = 700, + // Performing an action on the resource failed + ResourceActionFailed = 701, + // Processing the request failed unexpectedly (comment required) + RequestProcessingFailed = 702, // The combination of request parameters cannot be used to perform an action - CannotAct = 707, - // Creation of a new stream service failed - StreamServiceCreationFailed = 708, + CannotAct = 703, }; ``` diff --git a/src/requesthandler/RequestHandler.cpp b/src/requesthandler/RequestHandler.cpp index d5ac94ed..b9d07d9c 100644 --- a/src/requesthandler/RequestHandler.cpp +++ b/src/requesthandler/RequestHandler.cpp @@ -59,6 +59,8 @@ const std::map RequestHandler::_handlerMap {"ToggleInputMute", &RequestHandler::ToggleInputMute}, {"GetInputVolume", &RequestHandler::GetInputVolume}, {"SetInputVolume", &RequestHandler::SetInputVolume}, + {"GetInputAudioSyncOffset", &RequestHandler::GetInputAudioSyncOffset}, + {"SetInputAudioSyncOffset", &RequestHandler::SetInputAudioSyncOffset}, {"GetInputAudioMonitorType", &RequestHandler::GetInputAudioMonitorType}, {"SetInputAudioMonitorType", &RequestHandler::SetInputAudioMonitorType}, {"GetInputPropertiesListPropertyItems", &RequestHandler::GetInputPropertiesListPropertyItems}, @@ -74,7 +76,7 @@ const std::map RequestHandler::_handlerMap RequestResult RequestHandler::ProcessRequest(const Request& request) { if (!request.RequestData.is_null() && !request.RequestData.is_object()) - return RequestResult::Error(RequestStatus::InvalidRequestParameterDataType, "Your request data is not an object."); + return RequestResult::Error(RequestStatus::InvalidRequestParameterType, "Your request data is not an object."); if (request.RequestType.empty()) return RequestResult::Error(RequestStatus::MissingRequestType, "Your request is missing a `requestType`"); diff --git a/src/requesthandler/RequestHandler.h b/src/requesthandler/RequestHandler.h index 83b8f9d7..591e60e3 100644 --- a/src/requesthandler/RequestHandler.h +++ b/src/requesthandler/RequestHandler.h @@ -74,6 +74,8 @@ class RequestHandler { RequestResult ToggleInputMute(const Request&); RequestResult GetInputVolume(const Request&); RequestResult SetInputVolume(const Request&); + RequestResult GetInputAudioSyncOffset(const Request&); + RequestResult SetInputAudioSyncOffset(const Request&); RequestResult GetInputAudioMonitorType(const Request&); RequestResult SetInputAudioMonitorType(const Request&); RequestResult GetInputPropertiesListPropertyItems(const Request&); diff --git a/src/requesthandler/RequestHandler_Config.cpp b/src/requesthandler/RequestHandler_Config.cpp index cecca5a9..ddd75313 100644 --- a/src/requesthandler/RequestHandler_Config.cpp +++ b/src/requesthandler/RequestHandler_Config.cpp @@ -20,7 +20,7 @@ RequestResult RequestHandler::GetPersistentData(const Request& request) else if (realm == "OBS_WEBSOCKET_DATA_REALM_PROFILE") persistentDataPath += "/obsWebSocketPersistentData.json"; else - return RequestResult::Error(RequestStatus::DataRealmNotFound, "You have specified an invalid persistent data realm."); + return RequestResult::Error(RequestStatus::ResourceNotFound, "You have specified an invalid persistent data realm."); json responseData; json persistentData; @@ -49,7 +49,7 @@ RequestResult RequestHandler::SetPersistentData(const Request& request) else if (realm == "OBS_WEBSOCKET_DATA_REALM_PROFILE") persistentDataPath += "/obsWebSocketPersistentData.json"; else - return RequestResult::Error(RequestStatus::DataRealmNotFound, "You have specified an invalid persistent data realm."); + return RequestResult::Error(RequestStatus::ResourceNotFound, "You have specified an invalid persistent data realm."); json persistentData = json::object(); Utils::Json::GetJsonFileContent(persistentDataPath, persistentData); @@ -79,7 +79,7 @@ RequestResult RequestHandler::SetCurrentSceneCollection(const Request& request) auto sceneCollections = Utils::Obs::ListHelper::GetSceneCollectionList(); if (std::find(sceneCollections.begin(), sceneCollections.end(), sceneCollectionName) == sceneCollections.end()) - return RequestResult::Error(RequestStatus::SceneCollectionNotFound); + return RequestResult::Error(RequestStatus::ResourceNotFound); std::string currentSceneCollectionName = Utils::Obs::StringHelper::GetCurrentSceneCollection(); // Avoid queueing tasks if nothing will change @@ -103,7 +103,7 @@ RequestResult RequestHandler::CreateSceneCollection(const Request& request) auto sceneCollections = Utils::Obs::ListHelper::GetSceneCollectionList(); if (std::find(sceneCollections.begin(), sceneCollections.end(), sceneCollectionName) != sceneCollections.end()) - return RequestResult::Error(RequestStatus::SceneCollectionAlreadyExists); + return RequestResult::Error(RequestStatus::ResourceAlreadyExists); QMainWindow* mainWindow = reinterpret_cast(obs_frontend_get_main_window()); bool success = false; @@ -133,7 +133,7 @@ RequestResult RequestHandler::SetCurrentProfile(const Request& request) auto profiles = Utils::Obs::ListHelper::GetProfileList(); if (std::find(profiles.begin(), profiles.end(), profileName) == profiles.end()) - return RequestResult::Error(RequestStatus::ProfileNotFound); + return RequestResult::Error(RequestStatus::ResourceNotFound); std::string currentProfileName = Utils::Obs::StringHelper::GetCurrentProfile(); // Avoid queueing tasks if nothing will change @@ -157,7 +157,7 @@ RequestResult RequestHandler::CreateProfile(const Request& request) auto profiles = Utils::Obs::ListHelper::GetProfileList(); if (std::find(profiles.begin(), profiles.end(), profileName) != profiles.end()) - return RequestResult::Error(RequestStatus::ProfileAlreadyExists); + return RequestResult::Error(RequestStatus::ResourceAlreadyExists); QMainWindow* mainWindow = reinterpret_cast(obs_frontend_get_main_window()); QMetaObject::invokeMethod(mainWindow, "NewProfile", Qt::BlockingQueuedConnection, Q_ARG(QString, QString::fromStdString(profileName))); @@ -176,10 +176,10 @@ RequestResult RequestHandler::RemoveProfile(const Request& request) auto profiles = Utils::Obs::ListHelper::GetProfileList(); if (std::find(profiles.begin(), profiles.end(), profileName) == profiles.end()) - return RequestResult::Error(RequestStatus::ProfileNotFound); + return RequestResult::Error(RequestStatus::ResourceNotFound); if (profiles.size() < 2) - return RequestResult::Error(RequestStatus::NotEnoughProfiles); + return RequestResult::Error(RequestStatus::NotEnoughResources); QMainWindow* mainWindow = reinterpret_cast(obs_frontend_get_main_window()); QMetaObject::invokeMethod(mainWindow, "DeleteProfile", Qt::BlockingQueuedConnection, Q_ARG(QString, QString::fromStdString(profileName))); @@ -233,12 +233,12 @@ RequestResult RequestHandler::SetProfileParameter(const Request& request) // Using check helpers here would just make the logic more complicated if (!request.RequestData.contains("parameterValue") || request.RequestData["parameterValue"].is_null()) { if (!config_remove_value(profile, parameterCategory.c_str(), parameterName.c_str())) - return RequestResult::Error(RequestStatus::ConfigParameterNotFound); + return RequestResult::Error(RequestStatus::ResourceNotFound, "There are no existing instances of that profile parameter."); } else if (request.RequestData["parameterValue"].is_string()) { std::string parameterValue = request.RequestData["parameterValue"]; config_set_string(profile, parameterCategory.c_str(), parameterName.c_str(), parameterValue.c_str()); } else { - return RequestResult::Error(RequestStatus::InvalidRequestParameterDataType, "The parameter `parameterValue` must be a string."); + return RequestResult::Error(RequestStatus::InvalidRequestParameterType, "The parameter `parameterValue` must be a string."); } return RequestResult::Success(); @@ -322,7 +322,7 @@ RequestResult RequestHandler::GetStreamServiceSettings(const Request& request) RequestResult RequestHandler::SetStreamServiceSettings(const Request& request) { if (obs_frontend_streaming_active()) - return RequestResult::Error(RequestStatus::StreamRunning); + return RequestResult::Error(RequestStatus::OutputRunning, "You cannot change stream service settings while streaming."); RequestStatus::RequestStatus statusCode; std::string comment; @@ -350,7 +350,7 @@ RequestResult RequestHandler::SetStreamServiceSettings(const Request& request) OBSService newStreamService = obs_service_create(requestedStreamServiceType.c_str(), "obs_websocket_custom_service", requestedStreamServiceSettings, NULL); // TODO: Check service type here, instead of relying on service creation to fail. if (!newStreamService) - return RequestResult::Error(RequestStatus::StreamServiceCreationFailed, "Creating the stream service with the requested streamServiceType failed. It may be an invalid type."); + return RequestResult::Error(RequestStatus::ResourceCreationFailed, "Creating the stream service with the requested streamServiceType failed. It may be an invalid type."); obs_frontend_set_streaming_service(newStreamService); } diff --git a/src/requesthandler/RequestHandler_General.cpp b/src/requesthandler/RequestHandler_General.cpp index 9ab11c67..2dee3844 100644 --- a/src/requesthandler/RequestHandler_General.cpp +++ b/src/requesthandler/RequestHandler_General.cpp @@ -66,7 +66,7 @@ RequestResult RequestHandler::TriggerHotkeyByName(const Request& request) obs_hotkey_t *hotkey = Utils::Obs::SearchHelper::GetHotkeyByName(request.RequestData["hotkeyName"]); if (!hotkey) - return RequestResult::Error(RequestStatus::HotkeyNotFound); + return RequestResult::Error(RequestStatus::ResourceNotFound, "No hotkeys were found by that name."); obs_hotkey_trigger_routed_callback(obs_hotkey_get_id(hotkey), true); diff --git a/src/requesthandler/RequestHandler_Inputs.cpp b/src/requesthandler/RequestHandler_Inputs.cpp index 542e1dee..352cdf50 100644 --- a/src/requesthandler/RequestHandler_Inputs.cpp +++ b/src/requesthandler/RequestHandler_Inputs.cpp @@ -50,7 +50,7 @@ RequestResult RequestHandler::CreateInput(const Request& request) std::string inputName = request.RequestData["inputName"]; OBSSourceAutoRelease existingInput = obs_get_source_by_name(inputName.c_str()); if (existingInput) - return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that input name."); + return RequestResult::Error(RequestStatus::ResourceAlreadyExists, "A source already exists by that input name."); std::string inputKind = request.RequestData["inputKind"]; @@ -99,7 +99,7 @@ RequestResult RequestHandler::SetInputName(const Request& request) OBSSourceAutoRelease existingSource = obs_get_source_by_name(newInputName.c_str()); if (existingSource) - return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that new input name."); + return RequestResult::Error(RequestStatus::ResourceAlreadyExists, "A source already exists by that new input name."); obs_source_set_name(input, newInputName.c_str()); @@ -269,6 +269,35 @@ RequestResult RequestHandler::SetInputVolume(const Request& request) return RequestResult::Success(); } +RequestResult RequestHandler::GetInputAudioSyncOffset(const Request& request) +{ + RequestStatus::RequestStatus statusCode; + std::string comment; + OBSSourceAutoRelease input = request.ValidateInput("inputName", statusCode, comment); + if (!input) + return RequestResult::Error(statusCode, comment); + + json responseData; + // Offset is stored in nanoseconds in OBS. + responseData["inputAudioSyncOffset"] = obs_source_get_sync_offset(input) / 1000000; + + return RequestResult::Success(responseData); +} + +RequestResult RequestHandler::SetInputAudioSyncOffset(const Request& request) +{ + RequestStatus::RequestStatus statusCode; + std::string comment; + OBSSourceAutoRelease input = request.ValidateInput("inputName", statusCode, comment); + if (!(input && request.ValidateNumber("inputAudioSyncOffset", statusCode, comment, -950, 20000))) + return RequestResult::Error(statusCode, comment); + + int64_t syncOffset = request.RequestData["inputAudioSyncOffset"]; + obs_source_set_sync_offset(input, syncOffset * 1000000); + + return RequestResult::Success(); +} + RequestResult RequestHandler::GetInputAudioMonitorType(const Request& request) { RequestStatus::RequestStatus statusCode; diff --git a/src/requesthandler/RequestHandler_Scenes.cpp b/src/requesthandler/RequestHandler_Scenes.cpp index ed1aa81b..b866839c 100644 --- a/src/requesthandler/RequestHandler_Scenes.cpp +++ b/src/requesthandler/RequestHandler_Scenes.cpp @@ -79,7 +79,7 @@ RequestResult RequestHandler::CreateScene(const Request& request) OBSSourceAutoRelease scene = obs_get_source_by_name(sceneName.c_str()); if (scene) - return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that scene name."); + return RequestResult::Error(RequestStatus::ResourceAlreadyExists, "A source already exists by that scene name."); obs_scene_t *createdScene = obs_scene_create(sceneName.c_str()); obs_scene_release(createdScene); @@ -112,7 +112,7 @@ RequestResult RequestHandler::SetSceneName(const Request& request) OBSSourceAutoRelease existingSource = obs_get_source_by_name(newSceneName.c_str()); if (existingSource) - return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that new scene name."); + return RequestResult::Error(RequestStatus::ResourceAlreadyExists, "A source already exists by that new scene name."); obs_source_set_name(scene, newSceneName.c_str()); diff --git a/src/requesthandler/RequestHandler_Sources.cpp b/src/requesthandler/RequestHandler_Sources.cpp index 43ec22e8..7e57ee2c 100644 --- a/src/requesthandler/RequestHandler_Sources.cpp +++ b/src/requesthandler/RequestHandler_Sources.cpp @@ -102,10 +102,10 @@ RequestResult RequestHandler::GetSourceActive(const Request& request) OBSSourceAutoRelease source = obs_get_source_by_name(sourceName.c_str()); if (!source) - return RequestResult::Error(RequestStatus::SourceNotFound); + return RequestResult::Error(RequestStatus::ResourceNotFound); if (obs_source_get_type(source) != OBS_SOURCE_TYPE_INPUT && obs_source_get_type(source) != OBS_SOURCE_TYPE_SCENE) - return RequestResult::Error(RequestStatus::InvalidSourceType, "The specified source is not an input or a scene."); + return RequestResult::Error(RequestStatus::InvalidResourceType, "The specified source is not an input or a scene."); json responseData; responseData["videoActive"] = obs_source_active(source); @@ -124,10 +124,10 @@ RequestResult RequestHandler::GetSourceScreenshot(const Request& request) OBSSourceAutoRelease source = obs_get_source_by_name(sourceName.c_str()); if (!source) - return RequestResult::Error(RequestStatus::SourceNotFound); + return RequestResult::Error(RequestStatus::ResourceNotFound); if (obs_source_get_type(source) != OBS_SOURCE_TYPE_INPUT && obs_source_get_type(source) != OBS_SOURCE_TYPE_SCENE) - return RequestResult::Error(RequestStatus::InvalidSourceType, "The specified source is not an input or a scene."); + return RequestResult::Error(RequestStatus::InvalidResourceType, "The specified source is not an input or a scene."); std::string imageFormat = request.RequestData["imageFormat"]; @@ -163,14 +163,14 @@ RequestResult RequestHandler::GetSourceScreenshot(const Request& request) QImage renderedImage = TakeSourceScreenshot(source, success, requestedWidth, requestedHeight); if (!success) - return RequestResult::Error(RequestStatus::ScreenshotRenderFailed); + return RequestResult::Error(RequestStatus::RequestProcessingFailed, "Failed to render screenshot."); QByteArray encodedImgBytes; QBuffer buffer(&encodedImgBytes); buffer.open(QBuffer::WriteOnly); if (!renderedImage.save(&buffer, imageFormat.c_str(), compressionQuality)) - return RequestResult::Error(RequestStatus::ScreenshotEncodeFailed); + return RequestResult::Error(RequestStatus::RequestProcessingFailed, "Failed to encode screenshot."); buffer.close(); @@ -192,10 +192,10 @@ RequestResult RequestHandler::SaveSourceScreenshot(const Request& request) OBSSourceAutoRelease source = obs_get_source_by_name(sourceName.c_str()); if (!source) - return RequestResult::Error(RequestStatus::SourceNotFound); + return RequestResult::Error(RequestStatus::ResourceNotFound, "No source was found by that name."); if (obs_source_get_type(source) != OBS_SOURCE_TYPE_INPUT && obs_source_get_type(source) != OBS_SOURCE_TYPE_SCENE) - return RequestResult::Error(RequestStatus::InvalidSourceType, "The specified source is not an input or a scene."); + return RequestResult::Error(RequestStatus::InvalidResourceType, "The specified source is not an input or a scene."); std::string imageFormat = request.RequestData["imageFormat"]; @@ -231,18 +231,18 @@ RequestResult RequestHandler::SaveSourceScreenshot(const Request& request) QImage renderedImage = TakeSourceScreenshot(source, success, requestedWidth, requestedHeight); if (!success) - return RequestResult::Error(RequestStatus::ScreenshotRenderFailed); + return RequestResult::Error(RequestStatus::RequestProcessingFailed, "Failed to render screenshot."); std::string imageFilePath = request.RequestData["imageFilePath"]; QFileInfo filePathInfo(QString::fromStdString(imageFilePath)); if (!filePathInfo.absoluteDir().exists()) - return RequestResult::Error(RequestStatus::DirectoryNotFound, "The directory for your file path does not exist."); + return RequestResult::Error(RequestStatus::ResourceNotFound, "The directory for your file path does not exist."); QString absoluteFilePath = filePathInfo.absoluteFilePath(); if (!renderedImage.save(absoluteFilePath, imageFormat.c_str(), compressionQuality)) - return RequestResult::Error(RequestStatus::ScreenshotSaveFailed); + return RequestResult::Error(RequestStatus::RequestProcessingFailed, "Failed to save screenshot."); return RequestResult::Success(); } diff --git a/src/requesthandler/RequestHandler_Stream.cpp b/src/requesthandler/RequestHandler_Stream.cpp index c0bea6e6..8bed1e41 100644 --- a/src/requesthandler/RequestHandler_Stream.cpp +++ b/src/requesthandler/RequestHandler_Stream.cpp @@ -34,7 +34,7 @@ RequestResult RequestHandler::ToggleStream(const Request& request) RequestResult RequestHandler::StartStream(const Request& request) { if (obs_frontend_streaming_active()) - return RequestResult::Error(RequestStatus::StreamRunning); + return RequestResult::Error(RequestStatus::OutputRunning); // TODO: Call signal directly to perform blocking wait obs_frontend_streaming_start(); @@ -45,7 +45,7 @@ RequestResult RequestHandler::StartStream(const Request& request) RequestResult RequestHandler::StopStream(const Request& request) { if (!obs_frontend_streaming_active()) - return RequestResult::Error(RequestStatus::StreamNotRunning); + return RequestResult::Error(RequestStatus::OutputNotRunning); // TODO: Call signal directly to perform blocking wait obs_frontend_streaming_stop(); diff --git a/src/requesthandler/rpc/Request.cpp b/src/requesthandler/rpc/Request.cpp index 8f670d5f..b5f9d8a0 100644 --- a/src/requesthandler/rpc/Request.cpp +++ b/src/requesthandler/rpc/Request.cpp @@ -42,7 +42,7 @@ const bool Request::ValidateNumber(const std::string keyName, RequestStatus::Req return false; if (!RequestData[keyName].is_number()) { - statusCode = RequestStatus::InvalidRequestParameterDataType; + statusCode = RequestStatus::InvalidRequestParameterType; comment = std::string("The parameter `") + keyName + "` must be a number."; return false; } @@ -68,7 +68,7 @@ const bool Request::ValidateString(const std::string keyName, RequestStatus::Req return false; if (!RequestData[keyName].is_string()) { - statusCode = RequestStatus::InvalidRequestParameterDataType; + statusCode = RequestStatus::InvalidRequestParameterType; comment = std::string("The parameter `") + keyName + "` must be a string."; return false; } @@ -88,7 +88,7 @@ const bool Request::ValidateBoolean(const std::string keyName, RequestStatus::Re return false; if (!RequestData[keyName].is_boolean()) { - statusCode = RequestStatus::InvalidRequestParameterDataType; + statusCode = RequestStatus::InvalidRequestParameterType; comment = std::string("The parameter `") + keyName + "` must be boolean."; return false; } @@ -102,7 +102,7 @@ const bool Request::ValidateObject(const std::string keyName, RequestStatus::Req return false; if (!RequestData[keyName].is_object()) { - statusCode = RequestStatus::InvalidRequestParameterDataType; + statusCode = RequestStatus::InvalidRequestParameterType; comment = std::string("The parameter `") + keyName + "` must be an object."; return false; } @@ -122,7 +122,7 @@ const bool Request::ValidateArray(const std::string keyName, RequestStatus::Requ return false; if (!RequestData[keyName].is_array()) { - statusCode = RequestStatus::InvalidRequestParameterDataType; + statusCode = RequestStatus::InvalidRequestParameterType; comment = std::string("The parameter `") + keyName + "` must be an array."; return false; } @@ -145,14 +145,14 @@ obs_source_t *Request::ValidateScene(const std::string keyName, RequestStatus::R obs_source_t *ret = obs_get_source_by_name(sceneName.c_str()); if (!ret) { - statusCode = RequestStatus::SceneNotFound; + statusCode = RequestStatus::ResourceNotFound; comment = std::string("No scene was found by the name of `") + sceneName + "`."; return nullptr; } if (obs_source_get_type(ret) != OBS_SOURCE_TYPE_SCENE) { obs_source_release(ret); - statusCode = RequestStatus::InvalidSourceType; + statusCode = RequestStatus::InvalidResourceType; comment = "The specified source is not a scene."; return nullptr; } @@ -160,7 +160,7 @@ obs_source_t *Request::ValidateScene(const std::string keyName, RequestStatus::R OBSScene scene = obs_scene_from_source(ret); if (obs_scene_is_group(scene)) { obs_source_release(ret); - statusCode = RequestStatus::InvalidSourceType; + statusCode = RequestStatus::InvalidResourceType; comment = "The specified source is not a scene."; return nullptr; } @@ -177,14 +177,14 @@ obs_source_t *Request::ValidateInput(const std::string keyName, RequestStatus::R obs_source_t *ret = obs_get_source_by_name(inputName.c_str()); if (!ret) { - statusCode = RequestStatus::InputNotFound; + statusCode = RequestStatus::ResourceNotFound; comment = std::string("No input was found by the name of `") + inputName + "`."; return nullptr; } if (obs_source_get_type(ret) != OBS_SOURCE_TYPE_INPUT) { obs_source_release(ret); - statusCode = RequestStatus::InvalidSourceType; + statusCode = RequestStatus::InvalidResourceType; comment = "The specified source is not an input."; return nullptr; } diff --git a/src/requesthandler/rpc/RequestStatus.h b/src/requesthandler/rpc/RequestStatus.h index 9563508e..7647715e 100644 --- a/src/requesthandler/rpc/RequestStatus.h +++ b/src/requesthandler/rpc/RequestStatus.h @@ -11,9 +11,9 @@ namespace RequestStatus { // The `requestType` field is missing from the request data MissingRequestType = 203, - // The request type is invalid (does not exist) + // The request type is invalid or does not exist UnknownRequestType = 204, - // Generic error code (comment is expected to be provided) + // Generic error code (comment required) GenericError = 205, // A required request parameter is missing @@ -21,129 +21,50 @@ namespace RequestStatus { // The request does not have a valid requestData object. MissingRequestData = 301, - // Generic invalid request parameter message + // Generic invalid request parameter message (comment required) InvalidRequestParameter = 400, // A request parameter has the wrong data type - InvalidRequestParameterDataType = 401, + InvalidRequestParameterType = 401, // A request parameter (float or int) is out of valid range RequestParameterOutOfRange = 402, // A request parameter (string or array) is empty and cannot be RequestParameterEmpty = 403, // There are too many request parameters (eg. a request takes two optionals, where only one is allowed at a time) TooManyRequestParameters = 404, - InvalidRequestParameterType = 405, // An output is running and cannot be in order to perform the request (generic) OutputRunning = 500, // An output is not running and should be OutputNotRunning = 501, - // Stream is running and cannot be - StreamRunning = 502, - // Stream is not running and should be - StreamNotRunning = 503, - // Record is running and cannot be - RecordRunning = 504, - // Record is not running and should be - RecordNotRunning = 505, - // Record is paused and cannot be - RecordPaused = 506, - // Replay buffer is running and cannot be - ReplayBufferRunning = 507, - // Replay buffer is not running and should be - ReplayBufferNotRunning = 508, - // Replay buffer is disabled and cannot be - ReplayBufferDisabled = 509, + // An output is paused and should not be + OutputPaused = 502, + // An output is disabled and should not be + OutputDisabled = 503, // Studio mode is active and cannot be - StudioModeActive = 510, + StudioModeActive = 504, // Studio mode is not active and should be - StudioModeNotActive = 511, - // Virtualcam is running and cannot be - VirtualcamRunning = 512, - // Virtualcam is not running and should be - VirtualcamNotRunning = 513, - OutputPaused = 514, - OutputDisabled = 515, + StudioModeNotActive = 505, - // The specified source (obs_source_t) was of the invalid type (Eg. input instead of scene) - InvalidSourceType = 600, - // The specified source (obs_source_t) was not found (generic for input, filter, transition, scene) - SourceNotFound = 601, - // The specified source (obs_source_t) already exists. Applicable to inputs, filters, transitions, scenes - SourceAlreadyExists = 602, - // The specified input (obs_source_t-OBS_SOURCE_TYPE_FILTER) was not found - InputNotFound = 603, - // The specified input (obs_source_t-OBS_SOURCE_TYPE_INPUT) had the wrong kind - InvalidInputKind = 604, - // The specified filter (obs_source_t-OBS_SOURCE_TYPE_FILTER) was not found - FilterNotFound = 605, - // The specified transition (obs_source_t-OBS_SOURCE_TYPE_TRANSITION) was not found - TransitionNotFound = 606, - // The specified transition (obs_source_t-OBS_SOURCE_TYPE_TRANSITION) does not support setting its position (transition is of fixed type) - TransitionDurationFixed = 607, - // The specified scene (obs_source_t-OBS_SOURCE_TYPE_SCENE), (obs_scene_t) was not found - SceneNotFound = 608, - // The specified scene item (obs_sceneitem_t) was not found - SceneItemNotFound = 609, - // The specified scene collection was not found - SceneCollectionNotFound = 610, - // The specified profile was not found - ProfileNotFound = 611, - // The specified output (obs_output_t) was not found - OutputNotFound = 612, - // The specified encoder (obs_encoder_t) was not found - EncoderNotFound = 613, - // The specified service (obs_service_t) was not found - ServiceNotFound = 614, - // The specified hotkey was not found - HotkeyNotFound = 615, - // The specified directory was not found - DirectoryNotFound = 616, - // The specified config item (config_t) was not found. Could be section or parameter name - ConfigParameterNotFound = 617, - // The specified property (obs_properties_t) was not found - PropertyNotFound = 618, - // The specififed key (OBS_KEY_*) was not found - KeyNotFound = 619, - // The specified data realm (OBS_WEBSOCKET_DATA_REALM_*) was not found - DataRealmNotFound = 620, - // The scene collection already exists - SceneCollectionAlreadyExists = 621, - // There are not enough scene collections to perform the action - NotEnoughSceneCollections = 622, - // The profile already exists - ProfileAlreadyExists = 623, - // There are not enough profiles to perform the action - NotEnoughProfiles = 624, - // There are not enough scenes to perform the action - NotEnoughScenes = 625, // The resource was not found - ResourceNotFound = 626, + ResourceNotFound = 600, + // The resource already exists + ResourceAlreadyExists = 601, // The type of resource found is invalid - InvalidResourceType = 627, + InvalidResourceType = 602, + // There are not enough instances of the resource in order to perform the request + NotEnoughResources = 603, // The state of the resource is invalid. For example, if the resource is blocked from being accessed - InvalidResourceState = 628, - NotEnoughResources = 629, - ResourceAlreadyExists = 630, + InvalidResourceState = 604, + // The specified input (obs_source_t-OBS_SOURCE_TYPE_INPUT) had the wrong kind + InvalidInputKind = 605, - // Processing the request failed unexpectedly - RequestProcessingFailed = 700, - // Starting the Output failed - OutputStartFailed = 701, - // Duplicating the scene item failed - SceneItemDuplicationFailed = 702, - // Rendering the screenshot failed - ScreenshotRenderFailed = 703, - // Encoding the screenshot failed - ScreenshotEncodeFailed = 704, - // Saving the screenshot failed - ScreenshotSaveFailed = 705, - // Creating the directory failed - DirectoryCreationFailed = 706, + // Creating the resource failed + ResourceCreationFailed = 700, + // Performing an action on the resource failed + ResourceActionFailed = 701, + // Processing the request failed unexpectedly (comment required) + RequestProcessingFailed = 702, // The combination of request parameters cannot be used to perform an action - CannotAct = 707, - // Creation of a new stream service failed - StreamServiceCreationFailed = 708, - ResourceCreationFailed = 709, - ResourceActionFailed = 710, + CannotAct = 703, }; };