python-audio-autotest-3.10 1.5.12rc1__py3-none-any.whl → 1.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyaatlibs/__init__.py +3 -2
- pyaatlibs/aatapp.py +92 -26
- pyaatlibs/activitystatemachine.py +4 -1
- pyaatlibs/adbutils.py +63 -35
- pyaatlibs/apk/audioworker.apk +0 -0
- pyaatlibs/appinterface.py +57 -22
- pyaatlibs/argutils.py +2 -0
- pyaatlibs/audiofunction.py +59 -27
- pyaatlibs/audiosignalframelogger.py +10 -9
- pyaatlibs/audiothread.py +32 -25
- pyaatlibs/audioworker.py +211 -90
- pyaatlibs/logcatlistener.py +19 -8
- pyaatlibs/logger.py +21 -8
- pyaatlibs/signalanalyzer.py +3 -1
- pyaatlibs/signalmatcher.py +14 -9
- pyaatlibs/tests/audioworker_test.py +168 -162
- pyaatlibs/timeutils.py +14 -5
- pyaatlibs/trials.py +9 -3
- {python_audio_autotest_3_10-1.5.12rc1.dist-info → python_audio_autotest_3_10-1.6.dist-info}/METADATA +1 -1
- python_audio_autotest_3_10-1.6.dist-info/RECORD +25 -0
- python_audio_autotest_3_10-1.5.12rc1.dist-info/RECORD +0 -25
- {python_audio_autotest_3_10-1.5.12rc1.dist-info → python_audio_autotest_3_10-1.6.dist-info}/WHEEL +0 -0
- {python_audio_autotest_3_10-1.5.12rc1.dist-info → python_audio_autotest_3_10-1.6.dist-info}/licenses/LICENSE +0 -0
- {python_audio_autotest_3_10-1.5.12rc1.dist-info → python_audio_autotest_3_10-1.6.dist-info}/top_level.txt +0 -0
pyaatlibs/audioworker.py
CHANGED
@@ -3,6 +3,7 @@ import subprocess
|
|
3
3
|
import json
|
4
4
|
import datetime
|
5
5
|
import time
|
6
|
+
import re
|
6
7
|
from enum import IntEnum, auto
|
7
8
|
|
8
9
|
from pyaatlibs import ROOT_DIR
|
@@ -10,6 +11,7 @@ from pyaatlibs.adbutils import Adb
|
|
10
11
|
from pyaatlibs.appinterface import AppInterface
|
11
12
|
from pyaatlibs.audiofunction import DetectionStateListener
|
12
13
|
|
14
|
+
|
13
15
|
# from Android SDK 32
|
14
16
|
class RecordInputSrc(IntEnum):
|
15
17
|
DEFAULT = 0
|
@@ -24,18 +26,21 @@ class RecordInputSrc(IntEnum):
|
|
24
26
|
UNPROCESSED = auto()
|
25
27
|
VOICE_PERFORMANCE = auto()
|
26
28
|
|
29
|
+
|
27
30
|
# align with audioworker
|
28
31
|
class RecordPerf(IntEnum):
|
29
32
|
NONE = 10
|
30
33
|
POWER_SAVING = auto()
|
31
34
|
LOW_LATENCY = auto()
|
32
35
|
|
36
|
+
|
33
37
|
# align with audioworker
|
34
38
|
class RecordApi(IntEnum):
|
35
39
|
NONE = 0
|
36
40
|
OPENSLES = auto()
|
37
41
|
AAUDIO = auto()
|
38
42
|
|
43
|
+
|
39
44
|
class PlaybackStream(IntEnum):
|
40
45
|
VOICE_CALL = 0
|
41
46
|
SYSTEM = auto()
|
@@ -46,6 +51,7 @@ class PlaybackStream(IntEnum):
|
|
46
51
|
DTMF = 8
|
47
52
|
ACCESSIBILITY = 10
|
48
53
|
|
54
|
+
|
49
55
|
class PlaybackContentType(IntEnum):
|
50
56
|
UNKNOWN = 0
|
51
57
|
SPEECH = auto()
|
@@ -54,6 +60,7 @@ class PlaybackContentType(IntEnum):
|
|
54
60
|
SONIFICATION = auto()
|
55
61
|
ULTRASOUND = 1997
|
56
62
|
|
63
|
+
|
57
64
|
class PlaybackUsage(IntEnum):
|
58
65
|
UNKNOWN = 0
|
59
66
|
MEDIA = auto()
|
@@ -69,20 +76,23 @@ class PlaybackUsage(IntEnum):
|
|
69
76
|
GAME = auto()
|
70
77
|
ASSISTANT = auto()
|
71
78
|
|
79
|
+
|
72
80
|
class PlaybackPerformanceMode(IntEnum):
|
73
81
|
NOT_SET = -1
|
74
82
|
NONE = auto()
|
75
83
|
LOW_LATENCY = auto()
|
76
84
|
POWER_SAVING = auto()
|
77
85
|
|
86
|
+
|
78
87
|
class TaskIndex(IntEnum):
|
79
88
|
ALL = -1
|
80
89
|
|
90
|
+
|
81
91
|
class AudioWorkerApp(AppInterface):
|
82
92
|
TAG = "AudioWorkerApp"
|
83
93
|
APK_PATHS = [
|
84
94
|
os.path.join(ROOT_DIR, "apk", "debug", "audioworker.apk"),
|
85
|
-
os.path.join(os.path.dirname(os.path.realpath(__file__)), "apk", "audioworker.apk")
|
95
|
+
os.path.join(os.path.dirname(os.path.realpath(__file__)), "apk", "audioworker.apk"),
|
86
96
|
]
|
87
97
|
INTENT_PREFIX = "am broadcast -a"
|
88
98
|
AUDIOWORKER_INTENT_PREFIX = "com.google.audioworker.intent."
|
@@ -90,9 +100,7 @@ class AudioWorkerApp(AppInterface):
|
|
90
100
|
PACKAGE = "com.google.audioworker"
|
91
101
|
MAINACTIVITY = ".activities.MainActivity"
|
92
102
|
|
93
|
-
DATA_FOLDER =
|
94
|
-
"/storage/emulated/0/Android/data/com.google.audioworker/files/Google-AudioWorker-data"
|
95
|
-
)
|
103
|
+
DATA_FOLDER = "/sdcard/Google-AudioWorker-data"
|
96
104
|
|
97
105
|
@staticmethod
|
98
106
|
def get_apk_path():
|
@@ -100,11 +108,16 @@ class AudioWorkerApp(AppInterface):
|
|
100
108
|
if os.path.exists(path):
|
101
109
|
return path
|
102
110
|
|
103
|
-
raise(RuntimeError("no apk file is found."))
|
111
|
+
raise (RuntimeError("no apk file is found."))
|
104
112
|
|
105
113
|
@staticmethod
|
106
114
|
def get_apk_version():
|
107
|
-
|
115
|
+
out = subprocess.check_output(["strings", __class__.get_apk_path()], text=True)
|
116
|
+
for line in out.splitlines():
|
117
|
+
if "python-audio-autotest" not in line:
|
118
|
+
continue
|
119
|
+
return line.strip()[1:]
|
120
|
+
return None
|
108
121
|
|
109
122
|
@staticmethod
|
110
123
|
def get_version_from_device(serialno=None):
|
@@ -114,16 +127,47 @@ class AudioWorkerApp(AppInterface):
|
|
114
127
|
|
115
128
|
out, _ = Adb.execute(
|
116
129
|
["shell", "dumpsys package com.google.audioworker | grep versionName"],
|
117
|
-
serialno=serialno
|
130
|
+
serialno=serialno,
|
131
|
+
)
|
132
|
+
|
133
|
+
version_from_device = out.strip().partition("versionName=")[-1]
|
134
|
+
version_from_apk = __class__.get_apk_version()
|
135
|
+
if version_from_device != version_from_apk:
|
136
|
+
__class__.log(
|
137
|
+
"get_version_from_device: the version got from package manager and from apk file"
|
138
|
+
f" don't match. (version_from_device: {version_from_device}, version_from_apk:"
|
139
|
+
f" {version_from_apk})"
|
140
|
+
)
|
118
141
|
|
119
|
-
return
|
142
|
+
return version_from_device
|
120
143
|
|
121
144
|
@classmethod
|
122
145
|
def install(child, grant=False, serialno=None, tolog=True):
|
123
146
|
super().install(grant=grant, serialno=serialno, tolog=tolog)
|
147
|
+
if not child.installed(serialno=serialno, tolog=tolog):
|
148
|
+
__class__.log("install: it was not installed, something was wrong.")
|
149
|
+
return
|
150
|
+
|
151
|
+
if grant:
|
152
|
+
__class__.grant_special_permissions(serialno=serialno)
|
153
|
+
|
124
154
|
__class__.log(
|
125
155
|
"install: the installed version is '{}'".format(
|
126
|
-
__class__.get_version_from_device(serialno=serialno)
|
156
|
+
__class__.get_version_from_device(serialno=serialno)
|
157
|
+
)
|
158
|
+
)
|
159
|
+
|
160
|
+
@classmethod
|
161
|
+
def grant_permissions(child, serialno=None, tolog=True, warning=True):
|
162
|
+
super().grant_permissions(serialno=serialno, tolog=tolog, warning=warning)
|
163
|
+
__class__.grant_special_permissions(serialno=serialno)
|
164
|
+
|
165
|
+
@staticmethod
|
166
|
+
def grant_special_permissions(serialno=None):
|
167
|
+
Adb.execute(
|
168
|
+
["shell", f"appops set {__class__.PACKAGE} MANAGE_EXTERNAL_STORAGE allow"],
|
169
|
+
serialno=serialno,
|
170
|
+
)
|
127
171
|
|
128
172
|
@staticmethod
|
129
173
|
def get_launch_component():
|
@@ -148,7 +192,7 @@ class AudioWorkerApp(AppInterface):
|
|
148
192
|
ack_funcs = [
|
149
193
|
__class__.playback_info,
|
150
194
|
__class__.record_info,
|
151
|
-
__class__.voip_info
|
195
|
+
__class__.voip_info,
|
152
196
|
]
|
153
197
|
|
154
198
|
for func in ack_funcs:
|
@@ -179,16 +223,25 @@ class AudioWorkerApp(AppInterface):
|
|
179
223
|
cmd_arr += ["--es", key]
|
180
224
|
cmd_arr.append(str(value))
|
181
225
|
|
182
|
-
__class__.device_shell(
|
183
|
-
device=device, serialno=serialno, cmd=" ".join(cmd_arr), tolog=tolog)
|
226
|
+
__class__.device_shell(device=device, serialno=serialno, cmd=" ".join(cmd_arr), tolog=tolog)
|
184
227
|
|
185
228
|
@staticmethod
|
186
229
|
def playback_nonoffload(
|
187
|
-
device=None,
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
230
|
+
device=None,
|
231
|
+
serialno=None,
|
232
|
+
freqs=[440.0],
|
233
|
+
playback_id=0,
|
234
|
+
file="null",
|
235
|
+
stream_type=PlaybackStream.MUSIC,
|
236
|
+
performance_mode=PlaybackPerformanceMode.NOT_SET,
|
237
|
+
content_type=PlaybackContentType.MUSIC,
|
238
|
+
usage=PlaybackUsage.MEDIA,
|
239
|
+
fs=16000,
|
240
|
+
nch=2,
|
241
|
+
amp=0.6,
|
242
|
+
bit_depth=16,
|
243
|
+
low_latency_mode=False,
|
244
|
+
):
|
192
245
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "playback.start"
|
193
246
|
configs = {
|
194
247
|
"type": "non-offload",
|
@@ -203,7 +256,7 @@ class AudioWorkerApp(AppInterface):
|
|
203
256
|
"stream-type": stream_type,
|
204
257
|
"usage": usage,
|
205
258
|
"content-type": content_type,
|
206
|
-
"performance-mode": performance_mode
|
259
|
+
"performance-mode": performance_mode,
|
207
260
|
}
|
208
261
|
__class__.send_intent(device, serialno, name, configs)
|
209
262
|
|
@@ -213,15 +266,25 @@ class AudioWorkerApp(AppInterface):
|
|
213
266
|
configs = {
|
214
267
|
"type": "non-offload",
|
215
268
|
"playback-id": playback_id,
|
216
|
-
"seek-position-ms"
|
269
|
+
"seek-position-ms": seek_position_ms,
|
217
270
|
}
|
218
271
|
__class__.send_intent(device, serialno, name, configs)
|
219
272
|
|
220
273
|
@staticmethod
|
221
274
|
def playback_offload(
|
222
|
-
device=None,
|
223
|
-
|
224
|
-
|
275
|
+
device=None,
|
276
|
+
serialno=None,
|
277
|
+
file="null",
|
278
|
+
stream_type=PlaybackStream.MUSIC,
|
279
|
+
content_type=PlaybackContentType.MUSIC,
|
280
|
+
usage=PlaybackUsage.MEDIA,
|
281
|
+
freqs=[440.0],
|
282
|
+
playback_id=0,
|
283
|
+
fs=16000,
|
284
|
+
nch=2,
|
285
|
+
amp=0.6,
|
286
|
+
bit_depth=16,
|
287
|
+
):
|
225
288
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "playback.start"
|
226
289
|
configs = {
|
227
290
|
"type": "offload",
|
@@ -244,13 +307,19 @@ class AudioWorkerApp(AppInterface):
|
|
244
307
|
configs = {
|
245
308
|
"type": "offload",
|
246
309
|
"playback-id": playback_id,
|
247
|
-
"seek-position-ms"
|
310
|
+
"seek-position-ms": seek_position_ms,
|
248
311
|
}
|
249
312
|
__class__.send_intent(device, serialno, name, configs)
|
250
313
|
|
251
314
|
@staticmethod
|
252
315
|
def _common_info(
|
253
|
-
device=None,
|
316
|
+
device=None,
|
317
|
+
serialno=None,
|
318
|
+
ctype=None,
|
319
|
+
controller=None,
|
320
|
+
tolog=False,
|
321
|
+
extra_params={},
|
322
|
+
):
|
254
323
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "{}.info".format(ctype)
|
255
324
|
ts = datetime.datetime.timestamp(datetime.datetime.now())
|
256
325
|
ts = int(ts * 1000)
|
@@ -263,7 +332,8 @@ class AudioWorkerApp(AppInterface):
|
|
263
332
|
retry = 10
|
264
333
|
while retry > 0:
|
265
334
|
out, err = __class__.device_shell(
|
266
|
-
None, serialno, cmd="cat {}".format(filepath), tolog=tolog
|
335
|
+
None, serialno, cmd="cat {}".format(filepath), tolog=tolog
|
336
|
+
)
|
267
337
|
if len(out) == 0:
|
268
338
|
time.sleep(0.5)
|
269
339
|
retry -= 1
|
@@ -278,8 +348,9 @@ class AudioWorkerApp(AppInterface):
|
|
278
348
|
return {}
|
279
349
|
|
280
350
|
import traceback
|
351
|
+
|
281
352
|
try:
|
282
|
-
info_timestamp = float(out[0].strip().split("::")[-1]) / 1000.
|
353
|
+
info_timestamp = float(out[0].strip().split("::")[-1]) / 1000.0
|
283
354
|
info_t = datetime.datetime.fromtimestamp(info_timestamp)
|
284
355
|
# if (datetime.datetime.now() - info_t).total_seconds() > 1:
|
285
356
|
# return None
|
@@ -292,7 +363,8 @@ class AudioWorkerApp(AppInterface):
|
|
292
363
|
@staticmethod
|
293
364
|
def playback_info(device=None, serialno=None, tolog=False):
|
294
365
|
return __class__._common_info(
|
295
|
-
device, serialno, "playback", "PlaybackController", tolog=tolog
|
366
|
+
device, serialno, "playback", "PlaybackController", tolog=tolog
|
367
|
+
)
|
296
368
|
|
297
369
|
@staticmethod
|
298
370
|
def playback_stop(device=None, serialno=None, tolog=False):
|
@@ -303,18 +375,20 @@ class AudioWorkerApp(AppInterface):
|
|
303
375
|
|
304
376
|
for pbtype in info.keys():
|
305
377
|
for pbid in info[pbtype].keys():
|
306
|
-
configs = {
|
307
|
-
"type": pbtype,
|
308
|
-
"playback-id": int(pbid)
|
309
|
-
}
|
378
|
+
configs = {"type": pbtype, "playback-id": int(pbid)}
|
310
379
|
__class__.send_intent(device, serialno, name, configs)
|
311
380
|
|
312
381
|
@staticmethod
|
313
382
|
def record_info(device=None, serialno=None, task_index=TaskIndex.ALL, tolog=False):
|
314
383
|
task_index = int(task_index)
|
315
384
|
info = __class__._common_info(
|
316
|
-
device,
|
317
|
-
|
385
|
+
device,
|
386
|
+
serialno,
|
387
|
+
"record",
|
388
|
+
"RecordController",
|
389
|
+
extra_params={"task-index": task_index},
|
390
|
+
tolog=tolog,
|
391
|
+
)
|
318
392
|
if info == None:
|
319
393
|
return None
|
320
394
|
|
@@ -336,11 +410,7 @@ class AudioWorkerApp(AppInterface):
|
|
336
410
|
|
337
411
|
task_index = int(task_index)
|
338
412
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "{}.detect.register".format(prefix)
|
339
|
-
configs = {
|
340
|
-
"class": dclass,
|
341
|
-
"params": params,
|
342
|
-
"task-index": task_index
|
343
|
-
}
|
413
|
+
configs = {"class": dclass, "params": params, "task-index": task_index}
|
344
414
|
__class__.send_intent(device, serialno, name, configs)
|
345
415
|
|
346
416
|
@staticmethod
|
@@ -350,10 +420,7 @@ class AudioWorkerApp(AppInterface):
|
|
350
420
|
|
351
421
|
task_index = int(task_index)
|
352
422
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "{}.detect.unregister".format(prefix)
|
353
|
-
configs = {
|
354
|
-
"class-handle": chandle,
|
355
|
-
"task-index": task_index
|
356
|
-
}
|
423
|
+
configs = {"class-handle": chandle, "task-index": task_index}
|
357
424
|
__class__.send_intent(device, serialno, name, configs)
|
358
425
|
|
359
426
|
@staticmethod
|
@@ -377,17 +444,23 @@ class AudioWorkerApp(AppInterface):
|
|
377
444
|
|
378
445
|
task_index = int(task_index)
|
379
446
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "{}.detect.setparams".format(prefix)
|
380
|
-
configs = {
|
381
|
-
"class-handle": chandle,
|
382
|
-
"params": params,
|
383
|
-
"task-index": task_index
|
384
|
-
}
|
447
|
+
configs = {"class-handle": chandle, "params": params, "task-index": task_index}
|
385
448
|
__class__.send_intent(device, serialno, name, configs)
|
386
449
|
|
387
450
|
@staticmethod
|
388
451
|
def record_start(
|
389
|
-
device=None,
|
390
|
-
|
452
|
+
device=None,
|
453
|
+
serialno=None,
|
454
|
+
fs=16000,
|
455
|
+
nch=2,
|
456
|
+
bit_depth=16,
|
457
|
+
btsco_on=True,
|
458
|
+
perf=None,
|
459
|
+
input_src=None,
|
460
|
+
api=None,
|
461
|
+
dump_buffer_ms=1000,
|
462
|
+
task_index=0,
|
463
|
+
):
|
391
464
|
task_index = int(task_index)
|
392
465
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "record.start"
|
393
466
|
configs = {
|
@@ -399,7 +472,7 @@ class AudioWorkerApp(AppInterface):
|
|
399
472
|
"audio-perf": int(perf) if perf is not None else perf,
|
400
473
|
"audio-api": int(api) if api is not None else api,
|
401
474
|
"dump-buffer-ms": dump_buffer_ms,
|
402
|
-
"task-index"
|
475
|
+
"task-index": task_index,
|
403
476
|
}
|
404
477
|
__class__.send_intent(device, serialno, name, configs)
|
405
478
|
|
@@ -440,7 +513,8 @@ class AudioWorkerApp(AppInterface):
|
|
440
513
|
|
441
514
|
@staticmethod
|
442
515
|
def record_detector_set_params(
|
443
|
-
device=None, serialno=None, chandle=None, params={}, task_index=0
|
516
|
+
device=None, serialno=None, chandle=None, params={}, task_index=0
|
517
|
+
):
|
444
518
|
__class__.tx_detector_set_params("record", device, serialno, chandle, params, task_index)
|
445
519
|
|
446
520
|
@staticmethod
|
@@ -448,8 +522,21 @@ class AudioWorkerApp(AppInterface):
|
|
448
522
|
return __class__._common_info(device, serialno, "voip", "VoIPController", tolog=tolog)
|
449
523
|
|
450
524
|
@staticmethod
|
451
|
-
def voip_start(
|
452
|
-
|
525
|
+
def voip_start(
|
526
|
+
device=None,
|
527
|
+
serialno=None,
|
528
|
+
rxfreq=440.0,
|
529
|
+
rxamp=0.6,
|
530
|
+
rxspkr=False,
|
531
|
+
rxfile="null",
|
532
|
+
rxfs=8000,
|
533
|
+
txfs=8000,
|
534
|
+
rxnch=1,
|
535
|
+
txnch=1,
|
536
|
+
rxbit_depth=16,
|
537
|
+
txbit_depth=16,
|
538
|
+
dump_buffer_ms=0,
|
539
|
+
):
|
453
540
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "voip.start"
|
454
541
|
configs = {
|
455
542
|
"rx-target-freq": rxfreq,
|
@@ -462,7 +549,7 @@ class AudioWorkerApp(AppInterface):
|
|
462
549
|
"tx-sampling-freq": txfs,
|
463
550
|
"tx-num-channels": txnch,
|
464
551
|
"tx-pcm-bit-width": txbit_depth,
|
465
|
-
"tx-dump-buffer-ms": dump_buffer_ms
|
552
|
+
"tx-dump-buffer-ms": dump_buffer_ms,
|
466
553
|
}
|
467
554
|
__class__.send_intent(device, serialno, name, configs)
|
468
555
|
|
@@ -474,9 +561,7 @@ class AudioWorkerApp(AppInterface):
|
|
474
561
|
@staticmethod
|
475
562
|
def voip_use_speaker(device=None, serialno=None, use=True):
|
476
563
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "voip.config"
|
477
|
-
configs = {
|
478
|
-
"rx-use-spkr": use
|
479
|
-
}
|
564
|
+
configs = {"rx-use-spkr": use}
|
480
565
|
__class__.send_intent(device, serialno, name, configs)
|
481
566
|
|
482
567
|
@staticmethod
|
@@ -486,10 +571,7 @@ class AudioWorkerApp(AppInterface):
|
|
486
571
|
@staticmethod
|
487
572
|
def voip_change_configs(device=None, serialno=None, rxfreq=-1, rxamp=-1):
|
488
573
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "voip.config"
|
489
|
-
configs = {
|
490
|
-
"rx-target-freq": rxfreq,
|
491
|
-
"rx-amplitude": rxamp
|
492
|
-
}
|
574
|
+
configs = {"rx-target-freq": rxfreq, "rx-amplitude": rxamp}
|
493
575
|
__class__.send_intent(device, serialno, name, configs)
|
494
576
|
|
495
577
|
@staticmethod
|
@@ -532,13 +614,24 @@ from pyaatlibs.audiofunction import ToneDetectorThread, ToneDetector
|
|
532
614
|
from pyaatlibs.aatapp import AATAppToneDetectorThread
|
533
615
|
from pyaatlibs.logger import Logger
|
534
616
|
|
617
|
+
|
535
618
|
class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
619
|
+
|
620
|
+
def __init__(
|
621
|
+
self,
|
622
|
+
serialno,
|
623
|
+
target_freq,
|
624
|
+
detector_reg_func,
|
625
|
+
detector_unreg_func,
|
626
|
+
detector_setparams_func,
|
627
|
+
info_func,
|
628
|
+
parse_detector_func,
|
629
|
+
callback=None,
|
630
|
+
listener=None,
|
631
|
+
):
|
540
632
|
super(AudioWorkerToneDetectorThread, self).__init__(
|
541
|
-
serialno=serialno, target_freq=target_freq, callback=callback
|
633
|
+
serialno=serialno, target_freq=target_freq, callback=callback
|
634
|
+
)
|
542
635
|
self.serialno = serialno
|
543
636
|
self.chandle = None
|
544
637
|
self.listener = listener
|
@@ -547,8 +640,11 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
547
640
|
self.detector_setparams_func = detector_setparams_func
|
548
641
|
self.info_func = info_func
|
549
642
|
self.parse_detector_func = parse_detector_func
|
550
|
-
self.detector_reg_func(
|
551
|
-
|
643
|
+
self.detector_reg_func(
|
644
|
+
serialno=serialno,
|
645
|
+
dclass="ToneDetector",
|
646
|
+
params={"target-freq": [target_freq]},
|
647
|
+
)
|
552
648
|
|
553
649
|
def get_tag(self):
|
554
650
|
return "AudioWorkerToneDetectorThread"
|
@@ -653,7 +749,9 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
653
749
|
info = self.info_func(serialno=self.serialno)
|
654
750
|
if not info:
|
655
751
|
Logger.log(
|
656
|
-
"{}::get_info".format(self.get_tag()),
|
752
|
+
"{}::get_info".format(self.get_tag()),
|
753
|
+
"no active record, null info returned",
|
754
|
+
)
|
657
755
|
return
|
658
756
|
|
659
757
|
detectors = self.parse_detector_func(info)
|
@@ -666,7 +764,8 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
666
764
|
if chandle:
|
667
765
|
Logger.log(
|
668
766
|
"{}::get_info".format(self.get_tag()),
|
669
|
-
"found detector handle: {} for target {} Hz".format(chandle, self.target_freq)
|
767
|
+
"found detector handle: {} for target {} Hz".format(chandle, self.target_freq),
|
768
|
+
)
|
670
769
|
|
671
770
|
if not chandle:
|
672
771
|
Logger.log("{}::get_info".format(self.get_tag()), "no detector handle!")
|
@@ -680,14 +779,22 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
680
779
|
return
|
681
780
|
|
682
781
|
self.detector_setparams_func(
|
683
|
-
serialno=self.serialno,
|
684
|
-
|
782
|
+
serialno=self.serialno,
|
783
|
+
chandle=self.chandle,
|
784
|
+
params={"dump-history": str(enable).lower()},
|
785
|
+
)
|
685
786
|
|
686
787
|
def set_target_frequency(self, target_freq):
|
687
788
|
self.target_freq = target_freq
|
688
789
|
self.detector_setparams_func(
|
689
|
-
serialno=self.serialno,
|
690
|
-
|
790
|
+
serialno=self.serialno,
|
791
|
+
chandle=self.chandle,
|
792
|
+
params={
|
793
|
+
"target-freq": [target_freq],
|
794
|
+
"clear-target": "false",
|
795
|
+
"dump-history": "true",
|
796
|
+
},
|
797
|
+
)
|
691
798
|
self.shared_vars["msg"] = None
|
692
799
|
|
693
800
|
def run(self):
|
@@ -697,7 +804,7 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
697
804
|
"last_state": None,
|
698
805
|
"msg": None,
|
699
806
|
"tictoc": TicToc(),
|
700
|
-
"state_keep_ms": 0
|
807
|
+
"state_keep_ms": 0,
|
701
808
|
}
|
702
809
|
|
703
810
|
self.extra = {}
|
@@ -711,15 +818,14 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
711
818
|
def freq_cb(msg):
|
712
819
|
line = msg.splitlines()[0].strip()
|
713
820
|
strs = line.split()
|
714
|
-
t = datetime.datetime.fromtimestamp(float(strs[0][:-1]) / 1000.)
|
821
|
+
t = datetime.datetime.fromtimestamp(float(strs[0][:-1]) / 1000.0)
|
715
822
|
freq = float(strs[1])
|
716
823
|
|
717
824
|
if not self.target_detected(freq):
|
718
|
-
self.push_to_dump(
|
719
|
-
"the frequency {} Hz is not the target".format(freq))
|
825
|
+
self.push_to_dump("the frequency {} Hz is not the target".format(freq))
|
720
826
|
return
|
721
827
|
|
722
|
-
active =
|
828
|
+
active = strs[2].lower() == "active"
|
723
829
|
|
724
830
|
if not self.shared_vars["start_time"]:
|
725
831
|
self.shared_vars["start_time"] = t
|
@@ -727,7 +833,9 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
727
833
|
if active != self.shared_vars["last_state"]:
|
728
834
|
self.push_to_dump(
|
729
835
|
"the detection state has been changed from {} to {}".format(
|
730
|
-
self.shared_vars["last_state"], active
|
836
|
+
self.shared_vars["last_state"], active
|
837
|
+
)
|
838
|
+
)
|
731
839
|
self.shared_vars["last_state"] = active
|
732
840
|
self.shared_vars["start_time"] = t
|
733
841
|
self.shared_vars["tictoc"].toc()
|
@@ -738,14 +846,19 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
738
846
|
|
739
847
|
self.shared_vars["state_keep_ms"] += self.shared_vars["tictoc"].toc()
|
740
848
|
if self.shared_vars["state_keep_ms"] > 200:
|
741
|
-
event =
|
849
|
+
event = (
|
742
850
|
ToneDetector.Event.TONE_DETECTED if active else ToneDetector.Event.TONE_MISSING
|
851
|
+
)
|
743
852
|
if self.shared_vars["last_event"] != event:
|
744
853
|
self.shared_vars["last_event"] = event
|
745
|
-
Logger.log(
|
854
|
+
Logger.log(
|
855
|
+
self.get_tag(),
|
746
856
|
"send_cb({}, {}) on {} Hz".format(
|
747
|
-
t_str,
|
748
|
-
else "TONE_MISSING",
|
857
|
+
t_str,
|
858
|
+
"TONE_DETECTED" if active else "TONE_MISSING",
|
859
|
+
self.target_freq,
|
860
|
+
),
|
861
|
+
)
|
749
862
|
if self.cb != None:
|
750
863
|
self.cb((t_str, event))
|
751
864
|
if isinstance(self.listener, DetectionStateListener):
|
@@ -763,15 +876,20 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
763
876
|
|
764
877
|
adb_tictoc.tic()
|
765
878
|
msg_in_device, _ = Adb.execute(
|
766
|
-
cmd=[
|
767
|
-
"
|
768
|
-
|
879
|
+
cmd=[
|
880
|
+
"shell",
|
881
|
+
"cat {}/{}.txt".format(AudioWorkerApp.DATA_FOLDER, self.chandle),
|
882
|
+
],
|
883
|
+
serialno=self.serialno,
|
884
|
+
tolog=False,
|
885
|
+
)
|
769
886
|
elapsed = adb_tictoc.toc()
|
770
887
|
|
771
888
|
msg_in_device = map(lambda x: x.strip(), msg_in_device.splitlines())
|
772
889
|
msg_in_device = [x for x in msg_in_device if self.target_detected(float(x.split()[1]))]
|
773
|
-
self.shared_vars["msg"] =
|
890
|
+
self.shared_vars["msg"] = (
|
774
891
|
msg_in_device[-1] if len(msg_in_device) > 0 else self.shared_vars["msg"]
|
892
|
+
)
|
775
893
|
|
776
894
|
if elapsed > self.extra["adb-read-prop-max-elapsed"]:
|
777
895
|
self.extra["adb-read-prop-max-elapsed"] = elapsed
|
@@ -779,11 +897,14 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
779
897
|
if self.shared_vars["msg"]:
|
780
898
|
try:
|
781
899
|
self.push_to_dump(
|
782
|
-
"{} (adb-shell elapsed: {} ms)".format(self.shared_vars["msg"], elapsed)
|
900
|
+
"{} (adb-shell elapsed: {} ms)".format(self.shared_vars["msg"], elapsed)
|
901
|
+
)
|
783
902
|
freq_cb(self.shared_vars["msg"])
|
784
903
|
except Exception as e:
|
785
904
|
Logger.log(
|
786
|
-
self.get_tag(),
|
905
|
+
self.get_tag(),
|
906
|
+
"crashed in freq_cb('{}')".format(self.shared_vars["msg"]),
|
907
|
+
)
|
787
908
|
Logger.log(self.get_tag(), str(e))
|
788
909
|
|
789
910
|
elapsed = freq_cb_tictoc.toc()
|