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-frontend-api.h>
|
||||||
#include <obs.hpp>
|
#include <obs.hpp>
|
||||||
|
#include <util/platform.h>
|
||||||
|
|
||||||
#include "obs-websocket.h"
|
#include "obs-websocket.h"
|
||||||
|
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
@ -764,3 +766,51 @@ obs_data_array_t* Utils::GetSourceFiltersList(obs_source_t* source, bool include
|
|||||||
|
|
||||||
return enumParams.filters;
|
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 <obs-module.h>
|
||||||
#include <util/config-file.h>
|
#include <util/config-file.h>
|
||||||
|
|
||||||
|
typedef void(*PauseRecordingFunction)(bool);
|
||||||
|
typedef bool(*RecordingPausedFunction)();
|
||||||
|
|
||||||
class Utils {
|
class Utils {
|
||||||
public:
|
public:
|
||||||
static obs_data_array_t* StringListToArray(char** strings, const char* key);
|
static obs_data_array_t* StringListToArray(char** strings, const char* key);
|
||||||
@ -78,4 +81,8 @@ class Utils {
|
|||||||
|
|
||||||
static const char* GetFilenameFormatting();
|
static const char* GetFilenameFormatting();
|
||||||
static bool SetFilenameFormatting(const char* filenameFormatting);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obs_frontend_recording_paused() && _recPauseTime > 0) {
|
if (Utils::RecordingPaused() && _recPauseTime > 0) {
|
||||||
return (_recPauseTime - _recStarttime);
|
return (_recPauseTime - _recStarttime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -746,7 +746,7 @@ void WSEvents::OnExit() {
|
|||||||
void WSEvents::StreamStatus() {
|
void WSEvents::StreamStatus() {
|
||||||
bool streamingActive = obs_frontend_streaming_active();
|
bool streamingActive = obs_frontend_streaming_active();
|
||||||
bool recordingActive = obs_frontend_recording_active();
|
bool recordingActive = obs_frontend_recording_active();
|
||||||
bool recordingPaused = obs_frontend_recording_paused();
|
bool recordingPaused = Utils::RecordingPaused();
|
||||||
bool replayBufferActive = obs_frontend_replay_buffer_active();
|
bool replayBufferActive = obs_frontend_replay_buffer_active();
|
||||||
|
|
||||||
OBSOutputAutoRelease streamOutput = obs_frontend_get_streaming_output();
|
OBSOutputAutoRelease streamOutput = obs_frontend_get_streaming_output();
|
||||||
@ -832,7 +832,7 @@ void WSEvents::Heartbeat() {
|
|||||||
|
|
||||||
bool streamingActive = obs_frontend_streaming_active();
|
bool streamingActive = obs_frontend_streaming_active();
|
||||||
bool recordingActive = obs_frontend_recording_active();
|
bool recordingActive = obs_frontend_recording_active();
|
||||||
bool recordingPaused = obs_frontend_recording_paused();
|
bool recordingPaused = Utils::RecordingPaused();
|
||||||
|
|
||||||
OBSDataAutoRelease data = obs_data_create();
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
OBSOutputAutoRelease recordOutput = obs_frontend_get_recording_output();
|
OBSOutputAutoRelease recordOutput = obs_frontend_get_recording_output();
|
||||||
|
@ -3,27 +3,17 @@
|
|||||||
#include <util/platform.h>
|
#include <util/platform.h>
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
typedef void(*pauseRecordingFunction)(bool);
|
HandlerResponse ifCanPause(WSRequestHandler* req, std::function<HandlerResponse()> callback)
|
||||||
typedef bool(*recordingPausedFunction)();
|
|
||||||
|
|
||||||
HandlerResponse ifCanPause(WSRequestHandler* req, std::function<HandlerResponse(recordingPausedFunction, pauseRecordingFunction)> 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()) {
|
if (!obs_frontend_recording_active()) {
|
||||||
return req->SendErrorResponse("recording is not 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
|
* @since 4.7.0
|
||||||
*/
|
*/
|
||||||
HandlerResponse WSRequestHandler::HandlePauseRecording(WSRequestHandler* req) {
|
HandlerResponse WSRequestHandler::HandlePauseRecording(WSRequestHandler* req) {
|
||||||
return ifCanPause(req, [req](recordingPausedFunction recordingPaused, pauseRecordingFunction pauseRecording) {
|
return ifCanPause(req, [req]() {
|
||||||
if (recordingPaused()) {
|
if (Utils::RecordingPaused()) {
|
||||||
return req->SendErrorResponse("recording already paused");
|
return req->SendErrorResponse("recording already paused");
|
||||||
}
|
}
|
||||||
|
|
||||||
pauseRecording(true);
|
Utils::PauseRecording(true);
|
||||||
return req->SendOKResponse();
|
return req->SendOKResponse();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -105,12 +95,12 @@ HandlerResponse WSRequestHandler::HandlePauseRecording(WSRequestHandler* req) {
|
|||||||
* @since 4.7.0
|
* @since 4.7.0
|
||||||
*/
|
*/
|
||||||
HandlerResponse WSRequestHandler::HandleResumeRecording(WSRequestHandler* req) {
|
HandlerResponse WSRequestHandler::HandleResumeRecording(WSRequestHandler* req) {
|
||||||
return ifCanPause(req, [req](recordingPausedFunction recordingPaused, pauseRecordingFunction pauseRecording) {
|
return ifCanPause(req, [req]() {
|
||||||
if (!recordingPaused()) {
|
if (!Utils::RecordingPaused()) {
|
||||||
return req->SendErrorResponse("recording is not paused");
|
return req->SendErrorResponse("recording is not paused");
|
||||||
}
|
}
|
||||||
|
|
||||||
pauseRecording(false);
|
Utils::PauseRecording(false);
|
||||||
return req->SendOKResponse();
|
return req->SendOKResponse();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ HandlerResponse WSRequestHandler::HandleGetStreamingStatus(WSRequestHandler* req
|
|||||||
OBSDataAutoRelease data = obs_data_create();
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
obs_data_set_bool(data, "streaming", obs_frontend_streaming_active());
|
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", 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);
|
obs_data_set_bool(data, "preview-only", false);
|
||||||
|
|
||||||
if (obs_frontend_streaming_active()) {
|
if (obs_frontend_streaming_active()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user