Skip to content

Commit fc6952e

Browse files
committed
api: prepare for fosdem 2025
1 parent 0363e77 commit fc6952e

4 files changed

Lines changed: 60 additions & 24 deletions

File tree

api/mixerapi.conf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ port = 10024
44
#device = '/dev/tty_fosdem_audio_ctl'
55

66
[levels]
7-
interval_web = 100
8-
interval_influx = 1000
9-
influx_host = '127.0.0.1:8086'
7+
interval_web = 50
8+
interval_influx = 500
9+
influx_host = 'control.video.fosdem.org:8086'
1010
influx_db = 'ebur'
1111

1212
[state]
13-
interval_web = 5000
13+
interval_web = 1000
1414
interval_influx = 10000
15-
influx_host = '127.0.0.1:8086'
15+
influx_host = 'control.video.fosdem.org:8086'
1616
influx_db = 'ebur'
1717

1818
[host]
1919
listen = '0.0.0.0'
2020
port = 5080
21+
loglevel = 'INFO'

api/mixerapi/entrypoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def main():
2727

2828
ch = logging.StreamHandler()
2929
ch.setFormatter(logging.Formatter('%(name)s :: %(levelname)s :: %(message)s'))
30-
logging.basicConfig(level=logging.INFO, handlers=[ch])
30+
logging.basicConfig(level=config['host']['loglevel'], handlers=[ch])
3131

3232
log = logging.getLogger('CTRL')
3333

api/mixerapi/levels.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,42 @@ def poll_levels(config, web_state, influx_state):
3535
int_web = config['levels']['interval_web']
3636
int_influxdb = config['levels']['interval_influx']
3737

38-
poll_base = math.gcd(int_web, int_influxdb)
39-
poll_count = math.lcm(int_web, int_influxdb)
38+
gcd = math.gcd(int_web, int_influxdb)
39+
lcm = math.lcm(int_web, int_influxdb)
4040

41-
mult_web = poll_base / int_web
42-
mult_influxdb = poll_base / int_influxdb
41+
# interval between polling cycles
42+
poll_base = gcd
43+
44+
# how often will they get in sync
45+
poll_count = lcm // gcd
46+
47+
mult_web = int_web // gcd
48+
mult_influxdb = int_influxdb // gcd
49+
50+
logger.info(f"Polling cycles: {poll_count}, each {poll_base} ms, web every {mult_web}, influxdb every {mult_influxdb}")
4351

4452
# like `while True`, but counts the cycle, and keeps it from overflowing
4553
for i in itertools.cycle(range(poll_count)):
4654
time.sleep(poll_base / 1000)
4755
levels = helpers.get_all_levels(osc)
4856

4957
if not levels:
58+
logger.error('No levels from mixer')
5059
continue
5160

52-
if i % mult_web == 0 and not web_state.is_set():
53-
web_state.set(lambda x: helpers.merge(x, levels))
54-
55-
if i % mult_influxdb == 0 and not influx_state.is_set():
56-
influx_state.set(lambda x: helpers.merge(x, levels))
61+
if i % mult_web == 0:
62+
logger.debug('polling web')
63+
if web_state.is_set():
64+
logger.debug('no web clients to update')
65+
else:
66+
web_state.set(lambda x: helpers.merge(x, levels))
67+
68+
if i % mult_influxdb == 0:
69+
logger.debug('polling influxdb')
70+
if influx_state.is_set():
71+
logger.warn('influxdb still waiting')
72+
else:
73+
influx_state.set(lambda x: helpers.merge(x, levels))
5774

5875
def push_influxdb(config, influxdb_state):
5976
if not ('influx_host' and 'influx_db') in config['levels']:

api/mixerapi/state.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,43 @@ def poll_state(config, web_state, influx_state):
3636
int_web = config['state']['interval_web']
3737
int_influxdb = config['state']['interval_influx']
3838

39-
poll_base = math.gcd(int_web, int_influxdb)
40-
poll_count = math.lcm(int_web, int_influxdb)
39+
gcd = math.gcd(int_web, int_influxdb)
40+
lcm = math.lcm(int_web, int_influxdb)
4141

42-
mult_web = poll_base / int_web
43-
mult_influxdb = poll_base / int_influxdb
42+
# interval between polling cycles
43+
poll_base = gcd
44+
45+
# how often will they get in sync
46+
poll_count = lcm // gcd
47+
48+
mult_web = int_web // gcd
49+
mult_influxdb = int_influxdb // gcd
50+
51+
logger.info(f"Polling cycles: {poll_count}, each {poll_base} ms, web every {mult_web}, influxdb every {mult_influxdb}")
4452

4553
# like `while True`, but counts the cycle, and keeps it from overflowing
4654
for i in itertools.cycle(range(poll_count)):
4755
time.sleep(poll_base / 1000)
4856
state = osc.get_state()
4957

5058
if not state:
59+
logger.error('No state from mixer')
5160
continue
5261

53-
if i % mult_web == 0 and not web_state.is_set():
54-
web_state.set(lambda x: helpers.merge(x, state))
62+
if i % mult_web == 0:
63+
logger.debug('polling web')
64+
if web_state.is_set():
65+
logger.debug('no web clients to update')
66+
else:
67+
web_state.set(lambda x: helpers.merge(x, state))
68+
69+
if i % mult_influxdb == 0:
70+
logger.debug('polling influxdb')
71+
if influx_state.is_set():
72+
logger.warn('influxdb still waiting')
73+
else:
74+
influx_state.set(lambda x: helpers.merge(x, state))
5575

56-
if i % mult_influxdb == 0 and not influx_state.is_set():
57-
influx_state.set(lambda x: helpers.merge(x, state))
5876

5977
def push_influxdb(config, influxdb_state):
6078
if not ('influx_host' and 'influx_db') in config['state']:
@@ -75,7 +93,7 @@ def push_influxdb(config, influxdb_state):
7593
[f'input_multipliers,box={hostname},ch={ch} multiplier={mult}'
7694
for ch, mult in state['multipliers']['input'].items()] +
7795
[f'output_multipliers,box={hostname},bus={bus} multiplier={mult}'
78-
for bus, mult in state['multipliers']['input'].items()] +
96+
for bus, mult in state['multipliers']['output'].items()] +
7997
[f'mutes,box={hostname},ch={ch},bus={bus} muted={muted}'
8098
for ch, kvp in state['mutes'].items() for bus, muted in kvp.items()]
8199
)

0 commit comments

Comments
 (0)