Compare commits

..

No commits in common. "main" and "latest" have entirely different histories.
main ... latest

4 changed files with 25 additions and 53 deletions

View file

@ -16,12 +16,10 @@ jobs:
apt-get install -y mingw-w64 zip apt-get install -y mingw-w64 zip
- name: Build - name: Build
run: | run: make
make &&
mv LICENSE LICENSE-AORBR
- name: Create ZIP file - name: Create ZIP file
run: zip -r auto-obs-rb-restart.zip LICENSE-AORBR AutoOBSRBRestart.lua monitor.dll run: zip -r auto-obs-rp-restart.zip LICENSE AutoOBSRPRestart.lua monitor.dll
- name: Create release - name: Create release
uses: akkuman/gitea-release-action@v1 uses: akkuman/gitea-release-action@v1
@ -29,4 +27,4 @@ jobs:
token: ${{ secrets.TOKEN }} token: ${{ secrets.TOKEN }}
name: Latest version name: Latest version
tag_name: latest tag_name: latest
files: auto-obs-rb-restart.zip files: auto-obs-rp-restart.zip

View file

@ -4,10 +4,7 @@ local wait_time = 7200 -- Wait 2 hours before checks
local idle_time = 120 -- Wait for any input in the last 2 minutes local idle_time = 120 -- Wait for any input in the last 2 minutes
function script_description() function script_description()
return [[ return "Automatically restarts the replay buffer when IDLE"
Automatically restarts the replay buffer when IDLE
Author: Mylloon
]]
end end
function script_load() function script_load()
@ -15,52 +12,40 @@ function script_load()
ffi.cdef[[ ffi.cdef[[
void start_hook(void); void start_hook(void);
void stop_hook(void); void stop_hook(void);
long long last_input_received(void); int last_time_input_received(void);
]] ]]
monitor = ffi.load(script_path() .. "monitor.dll") monitor = ffi.load(script_path() .. "monitor.dll")
start_loop()
obs.timer_add(check_restart, wait_time * 1000)
end end
function script_unload() function script_unload()
obs.timer_remove(check_restart) obs.timer_remove(check_restart)
obs.timer_remove(check_idle) obs.timer_remove(check_idle)
monitor.stop_hook()
end end
function start_loop()
print("Start idle")
obs.timer_add(check_restart, wait_time * 1000)
end
function check_restart() function check_restart()
obs.timer_remove(check_restart)
print("Start check every " .. idle_time .. "secs")
monitor.start_hook() monitor.start_hook()
obs.timer_add(check_idle, idle_time * 1000) obs.timer_add(check_idle, idle_time * 1000)
end end
function check_idle() function check_idle()
obs.timer_remove(check_idle)
local current_time = os.time() local current_time = os.time()
local last_input_time = monitor.last_input_received() local last_input_time = monitor.last_time_input_received()
if current_time - last_input_time >= idle_time then if current_time - last_input_time >= wait_time then
monitor.stop_hook() monitor.stop_hook()
obs.timer_remove(check_idle)
print("No activity detected, restart replay buffer") restart_replay_buffer()
obs.obs_frontend_replay_buffer_stop()
obs.timer_add(start_replay_buffer, 2000)
else
obs.timer_add(check_idle, idle_time * 1000)
end end
end end
function restart_replay_buffer()
obs.obs_frontend_replay_buffer_stop()
obs.timer_add(start_replay_buffer, 2000)
end
function start_replay_buffer() function start_replay_buffer()
obs.timer_remove(start_replay_buffer) obs.timer_remove(start_replay_buffer)
obs.obs_frontend_replay_buffer_start() obs.obs_frontend_replay_buffer_start()
start_loop()
end end

View file

@ -1,10 +1,5 @@
# Automatic OBS ReplayBuffer Restart [![status-badge](https://git.mylloon.fr/Anri/auto-obs-rb-restart/badges/workflows/release.yml/badge.svg)](https://git.mylloon.fr/Anri/auto-obs-rb-restart/actions?workflow=release.yml) # Auto OBS RP Restart [![status-badge](https://git.mylloon.fr/Anri/auto-obs-rp-restart/badges/workflows/release.yml/badge.svg)](https://git.mylloon.fr/Anri/auto-obs-rp-restart/actions?workflow=release.yml)
Automatically restarts the replay buffer when IDLE Automatically restarts the replay buffer when IDLE
- [Download the latest release here](https://git.mylloon.fr/Anri/auto-obs-rb-restart/releases/tag/latest) - [Download the latest release here](https://git.mylloon.fr/Anri/auto-obs-rp-restart/releases/tag/latest)
The script wait 2 hours before looking for any input for the last 2 minutes.
If there is none, then it restarts the replay buffer.
Else it waits for the next 2 minutes, etc.
Once restarted, the script wait 2 other hours.

View file

@ -1,32 +1,26 @@
#include <stdatomic.h>
#include <time.h> #include <time.h>
#include <windows.h> #include <windows.h>
static atomic_llong last_input_time = 0; static DWORD last_input_time = 0; // Store the last input time in milliseconds
HHOOK hKeyboardHook = NULL; HHOOK hKeyboardHook;
LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) { LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
if (nCode == HC_ACTION) { if (nCode == HC_ACTION) {
atomic_store(&last_input_time, time(NULL)); last_input_time = GetTickCount();
} }
return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam); return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
} }
__declspec(dllexport) void start_hook(void) { __declspec(dllexport) void start_hook(void) {
if (!hKeyboardHook) { hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProc, NULL, 0);
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProc, NULL, 0);
}
} }
__declspec(dllexport) void stop_hook(void) { __declspec(dllexport) void stop_hook(void) {
if (hKeyboardHook) { UnhookWindowsHookEx(hKeyboardHook);
UnhookWindowsHookEx(hKeyboardHook);
hKeyboardHook = NULL;
}
} }
__declspec(dllexport) long long last_input_received(void) { __declspec(dllexport) int last_time_input_received(void) {
return atomic_load(&last_input_time); return last_input_time;
} }