-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathget_config_via_ffi.py
68 lines (53 loc) · 1.8 KB
/
get_config_via_ffi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from types import SimpleNamespace as _G
from ctypes import *
from ctypes.util import find_library
import obspython as S
G = _G()
G.obsffi = CDLL(find_library("obs"))
G.obsffi_front = CDLL(find_library("obs-frontend-api"))
def wrap(funcname, restype, argtypes=None, use_lib=None):
"""Simplify wrapping ctypes functions"""
if use_lib is not None:
func = getattr(use_lib, funcname)
else:
func = getattr(G.obsffi, funcname)
func.restype = restype
if argtypes is not None:
func.argtypes = argtypes
G.__dict__[funcname] = func
class Config(Structure):
pass
wrap("obs_frontend_get_profile_config", POINTER(Config), use_lib=G.obsffi_front)
# const char *config_get_string(config_t *config, const char *section,
# const char *name)
wrap("config_get_string", c_char_p, argtypes=[POINTER(Config), c_char_p, c_char_p])
wrap("config_num_sections", c_size_t, argtypes=[POINTER(Config)])
wrap("config_get_section", c_char_p, argtypes=[POINTER(Config), c_size_t])
def output_to_stdout():
cfg = G.obs_frontend_get_profile_config()
e = lambda x: x.encode("utf-8")
s = G.config_get_string(cfg, e("SimpleOutput"), e("FilePath"))
l = G.config_num_sections(cfg)
for i in range(l):
tag = G.config_get_section(cfg, c_size_t(i))
print(s, l)
G.lock = False
G.start_delay = 2
G.duration = 0
G.noise = 999
G.tick = 16
G.tick_mili = G.tick * 0.001
G.interval_sec = 1.05
G.tick_acc = 0
G.callback = output_to_stdout
def event_loop():
"""wait n seconds, then execute callback within certain interval"""
if G.duration > G.start_delay:
G.tick_acc += G.tick_mili
if G.tick_acc > G.interval_sec:
G.callback()
G.tick_acc = 0
return
else:
G.duration += G.tick_mili
S.timer_add(event_loop, G.tick)