mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
events + requests: fix dynamic runtime support for recording pauses
This commit is contained in:
parent
f9afc5597a
commit
af40aa59ab
@ -22,6 +22,8 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
|
||||
#include <obs-frontend-api.h>
|
||||
#include <obs.hpp>
|
||||
#include <util/platform.h>
|
||||
|
||||
#include "obs-websocket.h"
|
||||
|
||||
#include "Utils.h"
|
||||
@ -764,3 +766,51 @@ obs_data_array_t* Utils::GetSourceFiltersList(obs_source_t* source, bool include
|
||||
|
||||
return enumParams.filters;
|
||||
}
|
||||
|
||||
void getPauseRecordingFunctions(RecordingPausedFunction* recPausedFuncPtr, PauseRecordingFunction* pauseRecFuncPtr)
|
||||
{
|
||||
void* frontendApi = os_dlopen("obs-frontend-api");
|
||||
|
||||
if (recPausedFuncPtr) {
|
||||
*recPausedFuncPtr = (RecordingPausedFunction)os_dlsym(frontendApi, "obs_frontend_recording_paused");
|
||||
}
|
||||
|
||||
if (pauseRecFuncPtr) {
|
||||
*pauseRecFuncPtr = (PauseRecordingFunction)os_dlsym(frontendApi, "obs_frontend_recording_pause");
|
||||
}
|
||||
|
||||
os_dlclose(frontendApi);
|
||||
}
|
||||
|
||||
bool Utils::RecordingPauseSupported()
|
||||
{
|
||||
RecordingPausedFunction recordingPaused = nullptr;
|
||||
PauseRecordingFunction pauseRecording = nullptr;
|
||||
getPauseRecordingFunctions(&recordingPaused, &pauseRecording);
|
||||
|
||||
return (recordingPaused && pauseRecording);
|
||||
}
|
||||
|
||||
bool Utils::RecordingPaused()
|
||||
{
|
||||
RecordingPausedFunction recordingPaused = nullptr;
|
||||
getPauseRecordingFunctions(&recordingPaused, nullptr);
|
||||
|
||||
if (recordingPaused == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return recordingPaused();
|
||||
}
|
||||
|
||||
void Utils::PauseRecording(bool pause)
|
||||
{
|
||||
PauseRecordingFunction pauseRecording = nullptr;
|
||||
getPauseRecordingFunctions(nullptr, &pauseRecording);
|
||||
|
||||
if (pauseRecording == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
pauseRecording(pause);
|
||||
}
|
||||
|
@ -31,6 +31,9 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
||||
#include <obs-module.h>
|
||||
#include <util/config-file.h>
|
||||
|
||||
typedef void(*PauseRecordingFunction)(bool);
|
||||
typedef bool(*RecordingPausedFunction)();
|
||||
|
||||
class Utils {
|
||||
public:
|
||||
static obs_data_array_t* StringListToArray(char** strings, const char* key);
|
||||
@ -78,4 +81,8 @@ class Utils {
|
||||
|
||||
static const char* GetFilenameFormatting();
|
||||
static bool SetFilenameFormatting(const char* filenameFormatting);
|
||||
|
||||
static bool RecordingPauseSupported();
|
||||
static bool RecordingPaused();
|
||||
static void PauseRecording(bool pause);
|
||||
};
|
||||
|
@ -381,7 +381,7 @@ uint64_t WSEvents::getRecordingTime() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (obs_frontend_recording_paused() && _recPauseTime > 0) {
|
||||
if (Utils::RecordingPaused() && _recPauseTime > 0) {
|
||||
return (_recPauseTime - _recStarttime);
|
||||
}
|
||||
|
||||
@ -746,7 +746,7 @@ void WSEvents::OnExit() {
|
||||
void WSEvents::StreamStatus() {
|
||||
bool streamingActive = obs_frontend_streaming_active();
|
||||
bool recordingActive = obs_frontend_recording_active();
|
||||
bool recordingPaused = obs_frontend_recording_paused();
|
||||
bool recordingPaused = Utils::RecordingPaused();
|
||||
bool replayBufferActive = obs_frontend_replay_buffer_active();
|
||||
|
||||
OBSOutputAutoRelease streamOutput = obs_frontend_get_streaming_output();
|
||||
@ -832,7 +832,7 @@ void WSEvents::Heartbeat() {
|
||||
|
||||
bool streamingActive = obs_frontend_streaming_active();
|
||||
bool recordingActive = obs_frontend_recording_active();
|
||||
bool recordingPaused = obs_frontend_recording_paused();
|
||||
bool recordingPaused = Utils::RecordingPaused();
|
||||
|
||||
OBSDataAutoRelease data = obs_data_create();
|
||||
OBSOutputAutoRelease recordOutput = obs_frontend_get_recording_output();
|
||||
|
@ -3,27 +3,17 @@
|
||||
#include <util/platform.h>
|
||||
#include "Utils.h"
|
||||
|
||||
typedef void(*pauseRecordingFunction)(bool);
|
||||
typedef bool(*recordingPausedFunction)();
|
||||
|
||||
HandlerResponse ifCanPause(WSRequestHandler* req, std::function<HandlerResponse(recordingPausedFunction, pauseRecordingFunction)> callback)
|
||||
HandlerResponse ifCanPause(WSRequestHandler* req, std::function<HandlerResponse()> callback)
|
||||
{
|
||||
void* frontendApi = os_dlopen("obs-frontend-api");
|
||||
|
||||
bool (*recordingPaused)() = (bool(*)())os_dlsym(frontendApi, "obs_frontend_recording_paused");
|
||||
void (*pauseRecording)(bool) = (void(*)(bool))os_dlsym(frontendApi, "obs_frontend_recording_pause");
|
||||
|
||||
os_dlclose(frontendApi);
|
||||
|
||||
if (!recordingPaused || !pauseRecording) {
|
||||
return req->SendErrorResponse("recording pause not supported");
|
||||
}
|
||||
|
||||
if (!obs_frontend_recording_active()) {
|
||||
return req->SendErrorResponse("recording is not active");
|
||||
}
|
||||
|
||||
return callback(recordingPaused, pauseRecording);
|
||||
if (!Utils::RecordingPauseSupported()) {
|
||||
return req->SendErrorResponse("recording pauses are not available in this version of OBS Studio");
|
||||
}
|
||||
|
||||
return callback();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,12 +75,12 @@ HandlerResponse WSRequestHandler::HandleStartRecording(WSRequestHandler* req) {
|
||||
* @since 4.7.0
|
||||
*/
|
||||
HandlerResponse WSRequestHandler::HandlePauseRecording(WSRequestHandler* req) {
|
||||
return ifCanPause(req, [req](recordingPausedFunction recordingPaused, pauseRecordingFunction pauseRecording) {
|
||||
if (recordingPaused()) {
|
||||
return ifCanPause(req, [req]() {
|
||||
if (Utils::RecordingPaused()) {
|
||||
return req->SendErrorResponse("recording already paused");
|
||||
}
|
||||
|
||||
pauseRecording(true);
|
||||
Utils::PauseRecording(true);
|
||||
return req->SendOKResponse();
|
||||
});
|
||||
}
|
||||
@ -105,12 +95,12 @@ HandlerResponse WSRequestHandler::HandlePauseRecording(WSRequestHandler* req) {
|
||||
* @since 4.7.0
|
||||
*/
|
||||
HandlerResponse WSRequestHandler::HandleResumeRecording(WSRequestHandler* req) {
|
||||
return ifCanPause(req, [req](recordingPausedFunction recordingPaused, pauseRecordingFunction pauseRecording) {
|
||||
if (!recordingPaused()) {
|
||||
return ifCanPause(req, [req]() {
|
||||
if (!Utils::RecordingPaused()) {
|
||||
return req->SendErrorResponse("recording is not paused");
|
||||
}
|
||||
|
||||
pauseRecording(false);
|
||||
Utils::PauseRecording(false);
|
||||
return req->SendOKResponse();
|
||||
});
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ HandlerResponse WSRequestHandler::HandleGetStreamingStatus(WSRequestHandler* req
|
||||
OBSDataAutoRelease data = obs_data_create();
|
||||
obs_data_set_bool(data, "streaming", obs_frontend_streaming_active());
|
||||
obs_data_set_bool(data, "recording", obs_frontend_recording_active());
|
||||
obs_data_set_bool(data, "recording-paused", obs_frontend_recording_paused());
|
||||
obs_data_set_bool(data, "recording-paused", Utils::RecordingPaused());
|
||||
obs_data_set_bool(data, "preview-only", false);
|
||||
|
||||
if (obs_frontend_streaming_active()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user