diff --git a/CMakeLists.txt b/CMakeLists.txt index 521998c..d0de3aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,16 @@ cmake_minimum_required(VERSION 3.25) -project(obs-studio-plugin-unix-socket-control) + +set(obs_usc_VERSION_MAJOR 1) +set(obs_usc_VERSION_MINOR 2) +set(obs_usc_VERSION_PATCH 0) +set(obs_usc_VERSION_STR "${obs_usc_VERSION_MAJOR}.${obs_usc_VERSION_MINOR}.${obs_usc_VERSION_PATCH}") + +project(obs-studio-plugin-unix-socket-control VERSION "${obs_usc_VERSION_STR}") + add_compile_options( -Wall -Wextra -Wpedantic - $<$:-O0> + $<$:-Og> ) if(NOT DEFINED CMAKE_BUILD_TYPE OR NOT CMAKE_BUILD_TYPE) diff --git a/src/client.c b/src/client.c index 229d819..efd833b 100644 --- a/src/client.c +++ b/src/client.c @@ -16,6 +16,7 @@ void print_usage(char *name) { printf(" %s\n", name); printf(" [--start-recording \n"); printf(" | --stop-recording\n"); + printf(" | --toggle-recording\n"); printf(" | --start-streaming\n"); printf(" | --stop-streaming\n"); printf(" | --start-replay-buffer\n"); @@ -40,6 +41,8 @@ int main(int argc, char **argv) { type = UNIX_SOCKET_EVENT_STOP_RECORDING; } else if (strncmp(argv[1], "--start-streaming", 17) == 0) { type = UNIX_SOCKET_EVENT_START_STREAMING; + } else if (strncmp(argv[1], "--toggle-recording", 18) == 0) { + type = UNIX_SOCKET_EVENT_TOGGLE_RECORDING; } 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) { @@ -118,6 +121,19 @@ int main(int argc, char **argv) { case UNIX_SOCKET_EVENT_STOP_RECORDING: puts("Sent event \"stop recording\"!"); break; + case UNIX_SOCKET_EVENT_TOGGLE_RECORDING: + switch(buffer[1]) { + case UNIX_SOCKET_EVENT_START_RECORDING: + puts("Sent event \"toggle recording\", stream STARTED!\n"); + break; + case UNIX_SOCKET_EVENT_STOP_RECORDING: + puts("Sent event \"toggle recording\", stream STOPPED!\n"); + break; + default: + puts("Sent event \"toggle recording\", stream status UNKNOWN!\n"); + break; + } + break; case UNIX_SOCKET_EVENT_START_STREAMING: puts("Sent event \"start streaming\"!"); break; diff --git a/src/common_constants.h b/src/common_constants.h index a11befb..99464a8 100644 --- a/src/common_constants.h +++ b/src/common_constants.h @@ -12,7 +12,8 @@ typedef enum UnixSocketEventType { UNIX_SOCKET_EVENT_GET_STATUS, UNIX_SOCKET_EVENT_START_REPLAY_BUFFER, UNIX_SOCKET_EVENT_STOP_REPLAY_BUFFER, - UNIX_SOCKET_EVENT_SAVE_REPLAY_BUFFER + UNIX_SOCKET_EVENT_SAVE_REPLAY_BUFFER, + UNIX_SOCKET_EVENT_TOGGLE_RECORDING } UnixSocketEventType; #endif diff --git a/src/socket.c b/src/socket.c index 6f938e1..2a8206a 100644 --- a/src/socket.c +++ b/src/socket.c @@ -78,6 +78,15 @@ int unix_socket_handler_thread_function(void *ud) { } else if (buffer[0] == UNIX_SOCKET_EVENT_STOP_RECORDING) { obs_frontend_recording_stop(); ret_buffer[0] = UNIX_SOCKET_EVENT_NOP; + } else if (buffer[0] == UNIX_SOCKET_EVENT_TOGGLE_RECORDING) { + ret_buffer[0] = UNIX_SOCKET_EVENT_TOGGLE_RECORDING; + if (obs_frontend_recording_active()) { + obs_frontend_recording_stop(); + ret_buffer[1] = UNIX_SOCKET_EVENT_STOP_RECORDING; + } else { + obs_frontend_recording_start(); + ret_buffer[1] = UNIX_SOCKET_EVENT_START_RECORDING; + } } else if (buffer[0] == UNIX_SOCKET_EVENT_START_STREAMING) { obs_frontend_streaming_start(); ret_buffer[0] = UNIX_SOCKET_EVENT_NOP;