| 1 |
#!/usr/bin/env python3 |
| 2 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 3 |
# Copyright (C) 2018 Takashi Sakamoto |
| 4 |
|
| 5 |
from sys import exit |
| 6 |
from time import sleep |
| 7 |
from signal import signal, SIGINT |
| 8 |
from json import dumps |
| 9 |
|
| 10 |
from hinawa_utils.misc.cli_kit import CliKit |
| 11 |
from hinawa_utils.dice.dice_extended_unit import DiceExtendedUnit |
| 12 |
|
| 13 |
|
| 14 |
def _print_stream_params(direction, index, params): |
| 15 |
print('{0} stream {1}:'.format(direction.upper(), index)) |
| 16 |
print(' pcm: {0}'.format(params['pcm'])) |
| 17 |
print(' midi: {0}'.format(params['midi'])) |
| 18 |
print(' formation:') |
| 19 |
for i, name in enumerate(params['formation']): |
| 20 |
print(' {0}: {1}'.format(i, name)) |
| 21 |
print(' ac3: 0x{0:08x}'.format(params['ac3'])) |
| 22 |
|
| 23 |
|
| 24 |
def handle_current_status(unit, args): |
| 25 |
print('Capabilities:') |
| 26 |
for category in ('general', 'router', 'mixer'): |
| 27 |
print(' {0}:'.format(category)) |
| 28 |
for name, cap in unit.get_caps(category).items(): |
| 29 |
print(' {0}: {1}'.format(name, cap)) |
| 30 |
print('Stream configurations:') |
| 31 |
rate = unit.get_sampling_rate() |
| 32 |
stream_params = unit.get_stream_params(rate) |
| 33 |
for direction, params in stream_params.items(): |
| 34 |
for i, param in enumerate(params): |
| 35 |
_print_stream_params(direction, i, param) |
| 36 |
print('Standalone setting:') |
| 37 |
source = unit.get_standalone_clock_source() |
| 38 |
print(' clock source: {0}'.format(source)) |
| 39 |
for key, val in unit.get_standalone_clock_source_params(source).items(): |
| 40 |
print(' {0}: {1}'.format(key, val)) |
| 41 |
|
| 42 |
print('Output sources:') |
| 43 |
targets = unit.get_output_labels() |
| 44 |
for target in targets: |
| 45 |
source = unit.get_output_source(target) |
| 46 |
if source != 'None': |
| 47 |
print(' {0} {1}'.format(target, source)) |
| 48 |
|
| 49 |
print('Capture sources:') |
| 50 |
targets = unit.get_tx_stream_labels() |
| 51 |
for target in targets: |
| 52 |
source = unit.get_tx_stream_source(target) |
| 53 |
if source != 'None': |
| 54 |
print(' {0} {1}'.format(target, source)) |
| 55 |
|
| 56 |
print('Mixer sources:') |
| 57 |
targets = unit.get_mixer_input_labels() |
| 58 |
for target in targets: |
| 59 |
source = unit.get_mixer_source(target) |
| 60 |
if source != 'None': |
| 61 |
print(' {0} {1}'.format(target, source)) |
| 62 |
|
| 63 |
print('Mixer setting:') |
| 64 |
for output in unit.get_mixer_output_labels(): |
| 65 |
for input in unit.get_mixer_input_labels(): |
| 66 |
source = unit.get_mixer_source(input) |
| 67 |
if source == 'None': |
| 68 |
continue |
| 69 |
gain_r = unit.get_mixer_gain(output, input, 0) |
| 70 |
gain_l = unit.get_mixer_gain(output, input, 1) |
| 71 |
print(' {0} {1}({2}): {3} dB, {4} dB'.format( |
| 72 |
output, input, source, gain_r, gain_l)) |
| 73 |
|
| 74 |
return True |
| 75 |
|
| 76 |
|
| 77 |
def _print_dot_formatted_text(inputs, tx_stream_map, rx_streams, output_map, |
| 78 |
mixer_in_map, mixer_out_map): |
| 79 |
input_labels = {} |
| 80 |
tx_stream_labels = {} |
| 81 |
rx_stream_labels = {} |
| 82 |
mixer_in_labels = {} |
| 83 |
mixer_out_labels = {} |
| 84 |
output_labels = {} |
| 85 |
print('digraph {') |
| 86 |
print(' labelloc = "t"') |
| 87 |
print(' rankdir = "LR"') |
| 88 |
print(' subgraph cluster_input {') |
| 89 |
print(' label = "inputs"') |
| 90 |
print(' graph [rank = "min"]') |
| 91 |
for i, input in enumerate(inputs): |
| 92 |
if input != 'None': |
| 93 |
label = 'in{0}'.format(i) |
| 94 |
input_labels[input] = label |
| 95 |
print(' {0} [label = "{1}"]'.format(label, input)) |
| 96 |
print(' }') |
| 97 |
print(' subgraph cluster_1394bus {') |
| 98 |
print(' label = "1394 Bus"') |
| 99 |
print(' graph [rank = "source"]') |
| 100 |
print(' subgraph cluster_1394_bus_out {') |
| 101 |
print(' label = "1394 bus out"') |
| 102 |
print(' graph [rank = "min"]') |
| 103 |
for i, tx_stream in enumerate(tx_stream_map): |
| 104 |
label = 'tx{0}'.format(i) |
| 105 |
tx_stream_labels[tx_stream] = label |
| 106 |
print(' {0} [label = "{1}"]'.format(label, tx_stream)) |
| 107 |
print(' }') |
| 108 |
print(' subgraph cluster_1394_bus_in {') |
| 109 |
print(' label = "1394 bus in"') |
| 110 |
print(' graph [rank = "max"]') |
| 111 |
for i, rx_stream in enumerate(rx_streams): |
| 112 |
label = 'rx{0}'.format(i) |
| 113 |
rx_stream_labels[rx_stream] = label |
| 114 |
print(' {0} [label = "{1}"]'.format(label, rx_stream)) |
| 115 |
print(' }') |
| 116 |
print(' }') |
| 117 |
print(' subgraph cluster_mixer {') |
| 118 |
print(' label = "mixer"') |
| 119 |
print(' graph [rank = "sink"]') |
| 120 |
print(' subgraph cluster_mixer_input {') |
| 121 |
print(' label = "inputs"') |
| 122 |
for i, mixer_in in enumerate(mixer_in_map): |
| 123 |
label = 'mix_in{0}'.format(i) |
| 124 |
mixer_in_labels[mixer_in] = label |
| 125 |
print(' {0} [label = "{1}"]'.format(label, mixer_in)) |
| 126 |
print(' }') |
| 127 |
print(' subgraph cluster_mixer_output {') |
| 128 |
print(' label = "outputs"') |
| 129 |
for i, mixer_out in enumerate(mixer_out_map): |
| 130 |
label = 'mix_out{0}'.format(i) |
| 131 |
mixer_out_labels[mixer_out] = label |
| 132 |
print(' {0} [label = "{1}"]'.format(label, mixer_out)) |
| 133 |
print(' }') |
| 134 |
print(' }') |
| 135 |
print(' subgraph cluster_output {') |
| 136 |
print(' label = "outputs"') |
| 137 |
print(' graph [rank = "max"]') |
| 138 |
for i, output in enumerate(output_map): |
| 139 |
label = 'out{0}'.format(i) |
| 140 |
output_labels[output] = label |
| 141 |
print(' out{0} [label = "{1}"]'.format(i, output)) |
| 142 |
print(' }') |
| 143 |
|
| 144 |
for mixer_in, mixer_in_src in mixer_in_map.items(): |
| 145 |
if mixer_in_src == 'None': |
| 146 |
continue |
| 147 |
if mixer_in_src in input_labels: |
| 148 |
input_label = input_labels[mixer_in_src] |
| 149 |
elif mixer_in_src in rx_stream_labels: |
| 150 |
input_label = rx_stream_labels[mixer_in_src] |
| 151 |
mixer_in_label = mixer_in_labels[mixer_in] |
| 152 |
print(' {0} -> {1}'.format(input_label, mixer_in_label)) |
| 153 |
|
| 154 |
for tx_stream, tx_stream_src in tx_stream_map.items(): |
| 155 |
if tx_stream_src == 'None': |
| 156 |
continue |
| 157 |
if tx_stream_src not in input_labels: |
| 158 |
continue |
| 159 |
input_label = input_labels[tx_stream_src] |
| 160 |
tx_stream_label = tx_stream_labels[tx_stream] |
| 161 |
print(' {0} -> {1}'.format(input_label, tx_stream_label)) |
| 162 |
|
| 163 |
for mixer_out, mixer_ins in mixer_out_map.items(): |
| 164 |
for mixer_in in mixer_ins: |
| 165 |
if mixer_in in mixer_in_labels: |
| 166 |
mixer_in_label = mixer_in_labels[mixer_in] |
| 167 |
mixer_out_label = mixer_out_labels[mixer_out] |
| 168 |
print(' {0} -> {1}'.format(mixer_in_label, mixer_out_label)) |
| 169 |
|
| 170 |
for output, output_src in output_map.items(): |
| 171 |
output_label = output_labels[output] |
| 172 |
if output_src in mixer_out_labels: |
| 173 |
input_label = mixer_out_labels[output_src] |
| 174 |
elif output_src in input_labels: |
| 175 |
input_label = input_labels[output_src] |
| 176 |
elif output_src in rx_stream_labels: |
| 177 |
input_label = rx_stream_labels[output_src] |
| 178 |
else: |
| 179 |
continue |
| 180 |
print(' {0} -> {1}'.format(input_label, output_label)) |
| 181 |
|
| 182 |
print('}') |
| 183 |
|
| 184 |
|
| 185 |
def _print_json_formatted_text(inputs, tx_stream_map, rx_streams, output_map, |
| 186 |
mixer_in_map, mixer_out_map): |
| 187 |
data = { |
| 188 |
'inputs': inputs, |
| 189 |
'tx-stream-map': tx_stream_map, |
| 190 |
'rx-streams': rx_streams, |
| 191 |
'output-map': output_map, |
| 192 |
'mixer-in-map': mixer_in_map, |
| 193 |
'mixer-out-map': mixer_out_map, |
| 194 |
} |
| 195 |
print(dumps(data)) |
| 196 |
|
| 197 |
|
| 198 |
def _print_pretty_format(inputs, tx_stream_map, rx_streams, output_map, |
| 199 |
mixer_in_map, mixer_out_map): |
| 200 |
print('Inputs:') |
| 201 |
for input in inputs: |
| 202 |
print(' {0}'.format(input)) |
| 203 |
print('Tx streams:') |
| 204 |
for tx_stream, tx_stream_src in tx_stream_map.items(): |
| 205 |
print(' {0: <16} -> {1}'.format(tx_stream_src, tx_stream)) |
| 206 |
print('Rx streams:') |
| 207 |
for rx_stream in rx_streams: |
| 208 |
print(' {0}'.format(rx_stream)) |
| 209 |
print('Outputs') |
| 210 |
for output, output_src in output_map.items(): |
| 211 |
print(' {0: <16} -> {1}'.format(output_src, output)) |
| 212 |
print('Mixer-inputs:') |
| 213 |
for mixer_in, mixer_in_src in mixer_in_map.items(): |
| 214 |
print(' {0: <16} -> {1}'.format(mixer_in_src, mixer_in)) |
| 215 |
print('Mixer-outputs:') |
| 216 |
for mixer_out, mixer_out_srcs in mixer_out_map.items(): |
| 217 |
for mixer_out_src in mixer_out_srcs: |
| 218 |
print(' {0: <16} -> {1}'.format(mixer_out_src, mixer_out)) |
| 219 |
|
| 220 |
|
| 221 |
def handle_current_routing(unit, args): |
| 222 |
ops = { |
| 223 |
'graphviz': _print_dot_formatted_text, |
| 224 |
'json': _print_json_formatted_text, |
| 225 |
'pretty': _print_pretty_format, |
| 226 |
} |
| 227 |
if len(args) >= 1 and args[0] in ops: |
| 228 |
op = args[0] |
| 229 |
tx_stream_map = {} |
| 230 |
for tx_stream in unit.get_tx_stream_labels(): |
| 231 |
tx_stream_map[tx_stream] = unit.get_tx_stream_source(tx_stream) |
| 232 |
|
| 233 |
output_map = {} |
| 234 |
for output in unit.get_output_labels(): |
| 235 |
output_map[output] = unit.get_output_source(output) |
| 236 |
|
| 237 |
mixer_in_map = {} |
| 238 |
for mixer_in in unit.get_mixer_input_labels(): |
| 239 |
mixer_in_map[mixer_in] = unit.get_mixer_source(mixer_in) |
| 240 |
|
| 241 |
inputs = [] |
| 242 |
rx_streams = [] |
| 243 |
for input in unit.get_mixer_source_labels(): |
| 244 |
if input.find('Stream-') != 0: |
| 245 |
inputs.append(input) |
| 246 |
else: |
| 247 |
rx_streams.append(input) |
| 248 |
|
| 249 |
mixer_out_map = {} |
| 250 |
for mixer_out in unit.get_mixer_output_labels(): |
| 251 |
if mixer_out not in mixer_out_map: |
| 252 |
mixer_out_map[mixer_out] = [] |
| 253 |
for mixer_in, mixer_in_src in mixer_in_map.items(): |
| 254 |
if mixer_in_src == 'None': |
| 255 |
continue |
| 256 |
if (unit.get_mixer_gain(mixer_out, mixer_in, 0) != -float('inf') or |
| 257 |
unit.get_mixer_gain(mixer_out, mixer_in, 1) != -float('inf')): |
| 258 |
mixer_out_map[mixer_out].append(mixer_in) |
| 259 |
|
| 260 |
ops[op](inputs, tx_stream_map, rx_streams, output_map, mixer_in_map, |
| 261 |
mixer_out_map) |
| 262 |
return True |
| 263 |
print('Argument for print-routing command') |
| 264 |
print(' print-routing OP') |
| 265 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 266 |
return False |
| 267 |
|
| 268 |
|
| 269 |
def handle_stream_params(unit, args): |
| 270 |
rates = unit.get_supported_sampling_rates() |
| 271 |
if len(args) >= 1 and int(args[0]) in rates: |
| 272 |
rate = int(args[0]) |
| 273 |
stream_params = unit.get_stream_params(rate) |
| 274 |
for direction, params in stream_params.items(): |
| 275 |
for i, param in enumerate(params): |
| 276 |
_print_stream_params(direction, i, param) |
| 277 |
return True |
| 278 |
print('Argument for stream-params command:') |
| 279 |
print(' stream-params RATE') |
| 280 |
print(' RATE: [{0}]'.format('|'.join(map(str, rates)))) |
| 281 |
return False |
| 282 |
|
| 283 |
|
| 284 |
def handle_router_entries(unit, args): |
| 285 |
rates = unit.get_supported_sampling_rates() |
| 286 |
if len(args) >= 1 and int(args[0]) in rates: |
| 287 |
rate = int(args[0]) |
| 288 |
entries = unit.get_router_entries(rate) |
| 289 |
for entry in entries: |
| 290 |
print(' {0: <16} -> {1}'.format(entry['src'], entry['dst'])) |
| 291 |
return True |
| 292 |
print('Argument for router-entries command:') |
| 293 |
print(' router-entries RATE') |
| 294 |
print(' RATE: [{0}]'.format('|'.join(map(str, rates)))) |
| 295 |
return False |
| 296 |
|
| 297 |
|
| 298 |
def _handle_target_source(unit, args, cmd, targets_func, sources_func, |
| 299 |
set_func, get_func): |
| 300 |
ops = ('set', 'get') |
| 301 |
targets = targets_func() |
| 302 |
srcs = sources_func() |
| 303 |
if len(args) >= 2: |
| 304 |
target, op = args[0:2] |
| 305 |
if target in targets and op in ops: |
| 306 |
if op == 'set' and len(args) >= 3 and args[2] in srcs: |
| 307 |
src = args[2] |
| 308 |
set_func(target, src) |
| 309 |
return True |
| 310 |
elif op == 'get': |
| 311 |
print(get_func(target)) |
| 312 |
return True |
| 313 |
print('Arguments for {0} command:'.format(cmd)) |
| 314 |
print(' {0} TARGET OP [SOURCE]'.format(cmd)) |
| 315 |
print(' TARGET: [{0}]'.format('|'.join(targets))) |
| 316 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 317 |
print(' SOURCE: [{0}] if OP=set'.format('|'.join(srcs))) |
| 318 |
return False |
| 319 |
|
| 320 |
|
| 321 |
def handle_output_source(unit, args): |
| 322 |
return _handle_target_source(unit, args, 'output-source', |
| 323 |
unit.get_output_labels, unit.get_output_source_labels, |
| 324 |
unit.set_output_source, unit.get_output_source) |
| 325 |
|
| 326 |
|
| 327 |
def handle_capture_source(unit, args): |
| 328 |
return _handle_target_source(unit, args, 'capture-source', |
| 329 |
unit.get_tx_stream_labels, unit.get_tx_stream_source_labels, |
| 330 |
unit.set_tx_stream_source, unit.get_tx_stream_source) |
| 331 |
|
| 332 |
|
| 333 |
def handle_mixer_source(unit, args): |
| 334 |
return _handle_target_source(unit, args, 'mixer-source', |
| 335 |
unit.get_mixer_input_labels, unit.get_mixer_source_labels, |
| 336 |
unit.set_mixer_source, unit.get_mixer_source) |
| 337 |
|
| 338 |
|
| 339 |
def handle_mixer_gain(unit, args): |
| 340 |
chs = ('0', '1') |
| 341 |
ops = ('set', 'get') |
| 342 |
outputs = unit.get_mixer_output_labels() |
| 343 |
inputs = unit.get_mixer_input_labels() |
| 344 |
if len(args) >= 4: |
| 345 |
output, input, ch, op = args[0:4] |
| 346 |
if output in outputs and input in inputs and ch in chs and op in ops: |
| 347 |
ch = int(ch) |
| 348 |
if op == 'set' and len(args) >= 5: |
| 349 |
db = float(args[4]) |
| 350 |
unit.set_mixer_gain(output, input, ch, db) |
| 351 |
return True |
| 352 |
elif op == 'get': |
| 353 |
db = unit.get_mixer_gain(output, input, ch) |
| 354 |
print('{:.3f}'.format(db)) |
| 355 |
return True |
| 356 |
print('Arguments for mixer-gain command:') |
| 357 |
print(' mixer-gain OUTPUT INPUT CH ITEM OP [dB]') |
| 358 |
print(' OUTPUT: [{0}]'.format('|'.join(outputs))) |
| 359 |
srcs = [] |
| 360 |
for input in inputs: |
| 361 |
src = unit.get_mixer_source(input) |
| 362 |
if src != 'None': |
| 363 |
srcs.append('{0}(={1})'.format(input, src)) |
| 364 |
print(' INPUT: [{0}]'.format('|'.join(srcs))) |
| 365 |
print(' CH: [{0}]'.format('|'.join(chs))) |
| 366 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 367 |
print(' dB: [-inf,-84.00..4.00] if OP=set ') |
| 368 |
print('Saturation state:') |
| 369 |
for output, saturation in unit.get_mixer_saturations().items(): |
| 370 |
print(' {0}: {1}/{2}'.format(output, saturation[0], saturation[1])) |
| 371 |
return False |
| 372 |
|
| 373 |
|
| 374 |
def handle_mixer_panning(unit, args): |
| 375 |
chs = ('0', '1') |
| 376 |
ops = ('set', 'get') |
| 377 |
outputs = unit.get_mixer_output_labels() |
| 378 |
inputs = unit.get_mixer_input_labels() |
| 379 |
if len(args) >= 4: |
| 380 |
output, input, ch, op = args[0:4] |
| 381 |
if output in outputs and input in inputs and ch in chs and op in ops: |
| 382 |
ch = int(ch) |
| 383 |
if op == 'set' and len(args) >= 5: |
| 384 |
balance = float(args[4]) |
| 385 |
unit.set_mixer_balance(output, input, ch, balance) |
| 386 |
return True |
| 387 |
elif op == 'get': |
| 388 |
balance = unit.get_mixer_balance(output, input, ch) |
| 389 |
print('{:.3f}'.format(balance)) |
| 390 |
return True |
| 391 |
print('Arguments for mixer-panning command:') |
| 392 |
print(' mixer-panning OUTPUT INPUT CH ITEM OP [BALANCE]') |
| 393 |
print(' OUTPUT: [{0}]'.format('|'.join(outputs))) |
| 394 |
srcs = [] |
| 395 |
for input in inputs: |
| 396 |
src = unit.get_mixer_source(input) |
| 397 |
if src != 'None': |
| 398 |
srcs.append('{0}(={1})'.format(input, src)) |
| 399 |
print(' INPUT: [{0}]'.format('|'.join(srcs))) |
| 400 |
print(' CH: [{0}]'.format('|'.join(chs))) |
| 401 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 402 |
print(' BALANCE:[0.00...100.00] (left-right) if OP=set ') |
| 403 |
return False |
| 404 |
|
| 405 |
|
| 406 |
def handle_standalone_clock(unit, args): |
| 407 |
ops = ('set', 'get') |
| 408 |
clocks = unit.get_supported_clock_sources() |
| 409 |
if len(args) >= 1 and args[0] in ops: |
| 410 |
op = args[0] |
| 411 |
if op == 'set' and len(args) >= 2 and args[1] in clocks: |
| 412 |
clock = args[1] |
| 413 |
unit.set_standalone_clock_source(clock) |
| 414 |
return True |
| 415 |
elif op == 'get': |
| 416 |
print(unit.get_standalone_clock_source()) |
| 417 |
return True |
| 418 |
print('Arguments for standalone-clock command:') |
| 419 |
print(' standalone-clock OP [CLOCK]') |
| 420 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 421 |
print(' CLOCK: [{0}]'.format('|'.join(clocks))) |
| 422 |
return False |
| 423 |
|
| 424 |
|
| 425 |
def handle_standalone_params(unit, args): |
| 426 |
ops = ('set', 'get') |
| 427 |
clocks = unit.get_supported_clock_sources() |
| 428 |
if len(args) >= 2: |
| 429 |
clk, op = args[0:2] |
| 430 |
if clk in clocks and op in ops: |
| 431 |
param_options = unit.get_standalone_clock_source_param_options(clk) |
| 432 |
if op == 'set' and len(args) >= 3: |
| 433 |
params = {} |
| 434 |
for entry in args[2].split(','): |
| 435 |
if entry.count('=') != 1: |
| 436 |
continue |
| 437 |
if entry.find('=') > 0: |
| 438 |
key, val = entry.split('=') |
| 439 |
if key not in param_options: |
| 440 |
continue |
| 441 |
options = param_options[key] |
| 442 |
if isinstance(options, int): |
| 443 |
params[key] = int(val) |
| 444 |
elif (isinstance(options, list) and |
| 445 |
isinstance(options[0], int)): |
| 446 |
params[key] = int(val) |
| 447 |
else: |
| 448 |
params[key] = val |
| 449 |
unit.set_standalone_clock_source_params(clk, params) |
| 450 |
return True |
| 451 |
elif op == 'get': |
| 452 |
params = unit.get_standalone_clock_source_params(clk) |
| 453 |
for name, value in params.items(): |
| 454 |
print('{0}={1}'.format(name, value)) |
| 455 |
return True |
| 456 |
print('Arguments for standalone-params command:') |
| 457 |
print(' standalone-params CLOCK OP [MODE]') |
| 458 |
print(' CLOCK: [{0}]'.format('|'.join(clocks))) |
| 459 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 460 |
print(' MODE:') |
| 461 |
for clk in clocks: |
| 462 |
params = unit.get_standalone_clock_source_param_options(clk) |
| 463 |
for mode, options in params.items(): |
| 464 |
if isinstance(options, int): |
| 465 |
vals = 'integer(up tp {0})'.format(options) |
| 466 |
elif mode == 'rate': |
| 467 |
vals = '|'.join(map(str, options)) |
| 468 |
else: |
| 469 |
vals = '|'.join(options) |
| 470 |
print(' {0}=[{1}] if CLOCK={2}'.format(mode, vals, clk)) |
| 471 |
return False |
| 472 |
|
| 473 |
|
| 474 |
def handle_listen_metering(unit, args): |
| 475 |
# This is handled by another context. |
| 476 |
def handle_unix_signal(signum, frame): |
| 477 |
exit() |
| 478 |
signal(SIGINT, handle_unix_signal) |
| 479 |
while 1: |
| 480 |
meters = unit.get_metering() |
| 481 |
for src_blk_id, src_blk_params in unit.get_metering().items(): |
| 482 |
for src_blk_ch, dst_params in src_blk_params.items(): |
| 483 |
for dst_blk_id, dst_blk_params in dst_params.items(): |
| 484 |
for dst_blk_ch, peak in dst_blk_params.items(): |
| 485 |
print(src_blk_id, src_blk_ch, |
| 486 |
dst_blk_id, dst_blk_ch, peak) |
| 487 |
print('') |
| 488 |
sleep(0.1) |
| 489 |
return True |
| 490 |
|
| 491 |
|
| 492 |
def handle_storage_operation(unit, args): |
| 493 |
ops = { |
| 494 |
'store': unit.store_to_storage, |
| 495 |
'load': unit.load_from_storage |
| 496 |
} |
| 497 |
if len(args) >= 1 and args[0] in ops: |
| 498 |
categories = ops[args[0]]() |
| 499 |
for category in categories: |
| 500 |
print('{0} is processed.'.format(category)) |
| 501 |
return True |
| 502 |
print('Arguments for store-config command:') |
| 503 |
print(' store-config OP') |
| 504 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 505 |
return False |
| 506 |
|
| 507 |
|
| 508 |
cmds = { |
| 509 |
'current-status': handle_current_status, |
| 510 |
'current-routing': handle_current_routing, |
| 511 |
'stream-params': handle_stream_params, |
| 512 |
'router-entries': handle_router_entries, |
| 513 |
'output-source': handle_output_source, |
| 514 |
'capture-source': handle_capture_source, |
| 515 |
'mixer-source': handle_mixer_source, |
| 516 |
'mixer-gain': handle_mixer_gain, |
| 517 |
'mixer-panning': handle_mixer_panning, |
| 518 |
'standalone-clock': handle_standalone_clock, |
| 519 |
'standalone-params': handle_standalone_params, |
| 520 |
'listen-metering': handle_listen_metering, |
| 521 |
} |
| 522 |
|
| 523 |
fullpath = CliKit.seek_snd_unit_path() |
| 524 |
if fullpath: |
| 525 |
with DiceExtendedUnit(fullpath) as unit: |
| 526 |
if (unit.get_caps('general')['storage-available'] and |
| 527 |
unit.get_caps('general')['storable-stream-conf'] and |
| 528 |
unit.get_caps('router')['is-storable'] and |
| 529 |
unit.get_caps('mixer')['is-storable']): |
| 530 |
cmds['storage-operation'] = handle_storage_operation |
| 531 |
CliKit.dispatch_command(unit, cmds) |