diff --git a/src/client.c b/src/client.c index 9979ce4..229d819 100644 --- a/src/client.c +++ b/src/client.c @@ -18,6 +18,9 @@ void print_usage(char *name) { printf(" | --stop-recording\n"); printf(" | --start-streaming\n"); printf(" | --stop-streaming\n"); + printf(" | --start-replay-buffer\n"); + printf(" | --stop-replay-buffer\n"); + printf(" | --save-replay-buffer\n"); printf(" | --get-status]\n"); } @@ -39,6 +42,12 @@ int main(int argc, char **argv) { type = UNIX_SOCKET_EVENT_START_STREAMING; } else if (strncmp(argv[1], "--stop-streaming", 16) == 0) { type = UNIX_SOCKET_EVENT_STOP_STREAMING; + } else if (strncmp(argv[1], "--start-replay-buffer", 21) == 0) { + type = UNIX_SOCKET_EVENT_START_REPLAY_BUFFER; + } else if (strncmp(argv[1], "--stop-replay-buffer", 20) == 0) { + type = UNIX_SOCKET_EVENT_STOP_REPLAY_BUFFER; + } else if (strncmp(argv[1], "--save-replay-buffer", 20) == 0) { + type = UNIX_SOCKET_EVENT_SAVE_REPLAY_BUFFER; } else if (strncmp(argv[1], "--get-status", 12) == 0) { type = UNIX_SOCKET_EVENT_GET_STATUS; } else { @@ -94,9 +103,10 @@ int main(int argc, char **argv) { } if (type == UNIX_SOCKET_EVENT_GET_STATUS && buffer[0] == UNIX_SOCKET_EVENT_GET_STATUS) { - printf("Is recording: %s\nIs streaming: %s\n", + printf("Is recording: %s\nIs streaming: %s\nReplay buffer active: %s\n", (buffer[1] & 1) != 0 ? "true" : "false", - (buffer[1] & 2) != 0 ? "true" : "false"); + (buffer[1] & 2) != 0 ? "true" : "false", + (buffer[1] & 4) != 0 ? "true" : "false"); } else if (buffer[0] != UNIX_SOCKET_EVENT_NOP) { // Error. TODO handle this. return 7; @@ -114,6 +124,15 @@ int main(int argc, char **argv) { case UNIX_SOCKET_EVENT_STOP_STREAMING: puts("Sent event \"stop streaming\"!"); break; + case UNIX_SOCKET_EVENT_START_REPLAY_BUFFER: + puts("Sent event \"start replay-buffer\"!"); + break; + case UNIX_SOCKET_EVENT_STOP_REPLAY_BUFFER: + puts("Sent event \"stop replay-buffer\"!"); + break; + case UNIX_SOCKET_EVENT_SAVE_REPLAY_BUFFER: + puts("Sent event \"save replay-buffer\"!"); + break; default: // Error. TODO handle this return 8; diff --git a/src/common_constants.h b/src/common_constants.h index 9a7a4cb..a11befb 100644 --- a/src/common_constants.h +++ b/src/common_constants.h @@ -9,7 +9,10 @@ typedef enum UnixSocketEventType { UNIX_SOCKET_EVENT_STOP_RECORDING, UNIX_SOCKET_EVENT_START_STREAMING, UNIX_SOCKET_EVENT_STOP_STREAMING, - UNIX_SOCKET_EVENT_GET_STATUS + UNIX_SOCKET_EVENT_GET_STATUS, + UNIX_SOCKET_EVENT_START_REPLAY_BUFFER, + UNIX_SOCKET_EVENT_STOP_REPLAY_BUFFER, + UNIX_SOCKET_EVENT_SAVE_REPLAY_BUFFER } UnixSocketEventType; #endif diff --git a/src/socket.c b/src/socket.c index a1c2c95..6f938e1 100644 --- a/src/socket.c +++ b/src/socket.c @@ -1,4 +1,5 @@ #include "socket.h" +#include "common_constants.h" // standard library includes #include @@ -91,6 +92,23 @@ int unix_socket_handler_thread_function(void *ud) { if (obs_frontend_streaming_active()) { ret_buffer[1] |= 2; } + if (obs_frontend_replay_buffer_active()) { + ret_buffer[1] |= 4; + } + } else if (buffer[0] == UNIX_SOCKET_EVENT_START_REPLAY_BUFFER) { + obs_frontend_replay_buffer_start(); + ret_buffer[0] = UNIX_SOCKET_EVENT_NOP; + } else if (buffer[0] == UNIX_SOCKET_EVENT_STOP_REPLAY_BUFFER) { + obs_frontend_replay_buffer_stop(); + ret_buffer[0] = UNIX_SOCKET_EVENT_NOP; + } else if (buffer[0] == UNIX_SOCKET_EVENT_SAVE_REPLAY_BUFFER) { + if (obs_frontend_replay_buffer_active()) { + obs_frontend_replay_buffer_save(); + ret_buffer[0] = UNIX_SOCKET_EVENT_NOP; + } else { + ret = -1; + break; + } } ret = 0; break;