1 #include "Utils.h" 2 3 #include "WSRequestHandler.h" 4 5 /** 6 * Toggle the Replay Buffer on/off. 7 * 8 * @api requests 9 * @name StartStopReplayBuffer 10 * @category replay buffer 11 * @since 4.2.0 12 */ StartStopReplayBuffer(const RpcRequest & request)13RpcResponse WSRequestHandler::StartStopReplayBuffer(const RpcRequest& request) { 14 if (obs_frontend_replay_buffer_active()) { 15 obs_frontend_replay_buffer_stop(); 16 } else { 17 Utils::StartReplayBuffer(); 18 } 19 return request.success(); 20 } 21 22 /** 23 * Start recording into the Replay Buffer. 24 * Will return an `error` if the Replay Buffer is already active or if the 25 * "Save Replay Buffer" hotkey is not set in OBS' settings. 26 * Setting this hotkey is mandatory, even when triggering saves only 27 * through obs-websocket. 28 * 29 * @api requests 30 * @name StartReplayBuffer 31 * @category replay buffer 32 * @since 4.2.0 33 */ StartReplayBuffer(const RpcRequest & request)34RpcResponse WSRequestHandler::StartReplayBuffer(const RpcRequest& request) { 35 if (!Utils::ReplayBufferEnabled()) { 36 return request.failed("replay buffer disabled in settings"); 37 } 38 39 if (obs_frontend_replay_buffer_active() == true) { 40 return request.failed("replay buffer already active"); 41 } 42 43 Utils::StartReplayBuffer(); 44 return request.success(); 45 } 46 47 /** 48 * Stop recording into the Replay Buffer. 49 * Will return an `error` if the Replay Buffer is not active. 50 * 51 * @api requests 52 * @name StopReplayBuffer 53 * @category replay buffer 54 * @since 4.2.0 55 */ StopReplayBuffer(const RpcRequest & request)56RpcResponse WSRequestHandler::StopReplayBuffer(const RpcRequest& request) { 57 if (obs_frontend_replay_buffer_active() == true) { 58 obs_frontend_replay_buffer_stop(); 59 return request.success(); 60 } else { 61 return request.failed("replay buffer not active"); 62 } 63 } 64 65 /** 66 * Flush and save the contents of the Replay Buffer to disk. This is 67 * basically the same as triggering the "Save Replay Buffer" hotkey. 68 * Will return an `error` if the Replay Buffer is not active. 69 * 70 * @api requests 71 * @name SaveReplayBuffer 72 * @category replay buffer 73 * @since 4.2.0 74 */ SaveReplayBuffer(const RpcRequest & request)75RpcResponse WSRequestHandler::SaveReplayBuffer(const RpcRequest& request) { 76 if (!obs_frontend_replay_buffer_active()) { 77 return request.failed("replay buffer not active"); 78 } 79 80 OBSOutputAutoRelease replayOutput = obs_frontend_get_replay_buffer_output(); 81 82 calldata_t cd = { 0 }; 83 proc_handler_t* ph = obs_output_get_proc_handler(replayOutput); 84 proc_handler_call(ph, "save", &cd); 85 calldata_free(&cd); 86 87 return request.success(); 88 } 89