Compare commits

...

5 commits
latest ... main

Author SHA1 Message Date
4dd5fd95fe
Add prints
All checks were successful
Upload release / build (push) Successful in 40s
2024-10-09 12:31:11 +02:00
cf9880281f
only one timer at a time, usage of atomic
All checks were successful
Upload release / build (push) Successful in 33s
2024-10-07 22:41:12 +02:00
1f5e245541
remove mouse support
All checks were successful
Upload release / build (push) Successful in 29s
2024-10-07 22:14:33 +02:00
39dadd8cfa
add mouse event, fix project name, add dll behaviour
Some checks failed
Upload release / build (push) Has been cancelled
2024-10-07 21:53:11 +02:00
5bd7ff14e2
fix time
All checks were successful
Upload release / build (push) Successful in 2m37s
2024-10-07 21:20:48 +02:00
4 changed files with 53 additions and 25 deletions

View file

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

View file

@ -4,7 +4,10 @@ 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 "Automatically restarts the replay buffer when IDLE" return [[
Automatically restarts the replay buffer when IDLE
Author: Mylloon
]]
end end
function script_load() function script_load()
@ -12,40 +15,52 @@ function script_load()
ffi.cdef[[ ffi.cdef[[
void start_hook(void); void start_hook(void);
void stop_hook(void); void stop_hook(void);
int last_time_input_received(void); long long last_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()
local current_time = os.time()
local last_input_time = monitor.last_time_input_received()
if current_time - last_input_time >= wait_time then
monitor.stop_hook()
obs.timer_remove(check_idle) obs.timer_remove(check_idle)
restart_replay_buffer() local current_time = os.time()
end local last_input_time = monitor.last_input_received()
end
function restart_replay_buffer() if current_time - last_input_time >= idle_time then
monitor.stop_hook()
print("No activity detected, restart replay buffer")
obs.obs_frontend_replay_buffer_stop() obs.obs_frontend_replay_buffer_stop()
obs.timer_add(start_replay_buffer, 2000) obs.timer_add(start_replay_buffer, 2000)
else
obs.timer_add(check_idle, idle_time * 1000)
end
end 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,5 +1,10 @@
# 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) # 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)
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-rp-restart/releases/tag/latest) - [Download the latest release here](https://git.mylloon.fr/Anri/auto-obs-rb-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,26 +1,32 @@
#include <stdatomic.h>
#include <time.h> #include <time.h>
#include <windows.h> #include <windows.h>
static DWORD last_input_time = 0; // Store the last input time in milliseconds static atomic_llong last_input_time = 0;
HHOOK hKeyboardHook; HHOOK hKeyboardHook = NULL;
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) {
last_input_time = GetTickCount(); atomic_store(&last_input_time, time(NULL));
} }
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) int last_time_input_received(void) { __declspec(dllexport) long long last_input_received(void) {
return last_input_time; return atomic_load(&last_input_time);
} }