python-audio-autotest-3.10 1.5.12rc0__py3-none-any.whl → 1.5.12rc3__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 +193 -88
- 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.12rc0.dist-info → python_audio_autotest_3_10-1.5.12rc3.dist-info}/METADATA +1 -1
- python_audio_autotest_3_10-1.5.12rc3.dist-info/RECORD +25 -0
- python_audio_autotest_3_10-1.5.12rc0.dist-info/RECORD +0 -25
- {python_audio_autotest_3_10-1.5.12rc0.dist-info → python_audio_autotest_3_10-1.5.12rc3.dist-info}/WHEEL +0 -0
- {python_audio_autotest_3_10-1.5.12rc0.dist-info → python_audio_autotest_3_10-1.5.12rc3.dist-info}/licenses/LICENSE +0 -0
- {python_audio_autotest_3_10-1.5.12rc0.dist-info → python_audio_autotest_3_10-1.5.12rc3.dist-info}/top_level.txt +0 -0
pyaatlibs/audioworker.py
CHANGED
@@ -10,6 +10,7 @@ from pyaatlibs.adbutils import Adb
|
|
10
10
|
from pyaatlibs.appinterface import AppInterface
|
11
11
|
from pyaatlibs.audiofunction import DetectionStateListener
|
12
12
|
|
13
|
+
|
13
14
|
# from Android SDK 32
|
14
15
|
class RecordInputSrc(IntEnum):
|
15
16
|
DEFAULT = 0
|
@@ -24,18 +25,21 @@ class RecordInputSrc(IntEnum):
|
|
24
25
|
UNPROCESSED = auto()
|
25
26
|
VOICE_PERFORMANCE = auto()
|
26
27
|
|
28
|
+
|
27
29
|
# align with audioworker
|
28
30
|
class RecordPerf(IntEnum):
|
29
31
|
NONE = 10
|
30
32
|
POWER_SAVING = auto()
|
31
33
|
LOW_LATENCY = auto()
|
32
34
|
|
35
|
+
|
33
36
|
# align with audioworker
|
34
37
|
class RecordApi(IntEnum):
|
35
38
|
NONE = 0
|
36
39
|
OPENSLES = auto()
|
37
40
|
AAUDIO = auto()
|
38
41
|
|
42
|
+
|
39
43
|
class PlaybackStream(IntEnum):
|
40
44
|
VOICE_CALL = 0
|
41
45
|
SYSTEM = auto()
|
@@ -46,6 +50,7 @@ class PlaybackStream(IntEnum):
|
|
46
50
|
DTMF = 8
|
47
51
|
ACCESSIBILITY = 10
|
48
52
|
|
53
|
+
|
49
54
|
class PlaybackContentType(IntEnum):
|
50
55
|
UNKNOWN = 0
|
51
56
|
SPEECH = auto()
|
@@ -54,6 +59,7 @@ class PlaybackContentType(IntEnum):
|
|
54
59
|
SONIFICATION = auto()
|
55
60
|
ULTRASOUND = 1997
|
56
61
|
|
62
|
+
|
57
63
|
class PlaybackUsage(IntEnum):
|
58
64
|
UNKNOWN = 0
|
59
65
|
MEDIA = auto()
|
@@ -69,20 +75,23 @@ class PlaybackUsage(IntEnum):
|
|
69
75
|
GAME = auto()
|
70
76
|
ASSISTANT = auto()
|
71
77
|
|
78
|
+
|
72
79
|
class PlaybackPerformanceMode(IntEnum):
|
73
80
|
NOT_SET = -1
|
74
81
|
NONE = auto()
|
75
82
|
LOW_LATENCY = auto()
|
76
83
|
POWER_SAVING = auto()
|
77
84
|
|
85
|
+
|
78
86
|
class TaskIndex(IntEnum):
|
79
87
|
ALL = -1
|
80
88
|
|
89
|
+
|
81
90
|
class AudioWorkerApp(AppInterface):
|
82
91
|
TAG = "AudioWorkerApp"
|
83
92
|
APK_PATHS = [
|
84
93
|
os.path.join(ROOT_DIR, "apk", "debug", "audioworker.apk"),
|
85
|
-
os.path.join(os.path.dirname(os.path.realpath(__file__)), "apk", "audioworker.apk")
|
94
|
+
os.path.join(os.path.dirname(os.path.realpath(__file__)), "apk", "audioworker.apk"),
|
86
95
|
]
|
87
96
|
INTENT_PREFIX = "am broadcast -a"
|
88
97
|
AUDIOWORKER_INTENT_PREFIX = "com.google.audioworker.intent."
|
@@ -90,7 +99,9 @@ class AudioWorkerApp(AppInterface):
|
|
90
99
|
PACKAGE = "com.google.audioworker"
|
91
100
|
MAINACTIVITY = ".activities.MainActivity"
|
92
101
|
|
93
|
-
DATA_FOLDER =
|
102
|
+
DATA_FOLDER = (
|
103
|
+
"/storage/emulated/0/Android/data/com.google.audioworker/files/Google-AudioWorker-data"
|
104
|
+
)
|
94
105
|
|
95
106
|
@staticmethod
|
96
107
|
def get_apk_path():
|
@@ -98,11 +109,16 @@ class AudioWorkerApp(AppInterface):
|
|
98
109
|
if os.path.exists(path):
|
99
110
|
return path
|
100
111
|
|
101
|
-
raise(RuntimeError("no apk file is found."))
|
112
|
+
raise (RuntimeError("no apk file is found."))
|
102
113
|
|
103
114
|
@staticmethod
|
104
115
|
def get_apk_version():
|
105
|
-
|
116
|
+
out = subprocess.check_output(["strings", __class__.get_apk_path()], text=True)
|
117
|
+
for line in out.splitlines():
|
118
|
+
if "python-audio-autotest" not in line:
|
119
|
+
continue
|
120
|
+
return line.strip().replace("%", "")
|
121
|
+
return None
|
106
122
|
|
107
123
|
@staticmethod
|
108
124
|
def get_version_from_device(serialno=None):
|
@@ -112,16 +128,28 @@ class AudioWorkerApp(AppInterface):
|
|
112
128
|
|
113
129
|
out, _ = Adb.execute(
|
114
130
|
["shell", "dumpsys package com.google.audioworker | grep versionName"],
|
115
|
-
serialno=serialno
|
131
|
+
serialno=serialno,
|
132
|
+
)
|
133
|
+
|
134
|
+
version_from_device = out.strip().partition("versionName=")[-1]
|
135
|
+
version_from_apk = __class__.get_apk_version()
|
136
|
+
if version_from_device != version_from_apk:
|
137
|
+
__class__.log(
|
138
|
+
"get_version_from_device: the version got from package manager and from apk file"
|
139
|
+
f" don't match. (version_from_device: {version_from_device}, version_from_apk:"
|
140
|
+
f" {version_from_apk})"
|
141
|
+
)
|
116
142
|
|
117
|
-
return
|
143
|
+
return version_from_device
|
118
144
|
|
119
145
|
@classmethod
|
120
146
|
def install(child, grant=False, serialno=None, tolog=True):
|
121
147
|
super().install(grant=grant, serialno=serialno, tolog=tolog)
|
122
148
|
__class__.log(
|
123
149
|
"install: the installed version is '{}'".format(
|
124
|
-
__class__.get_version_from_device(serialno=serialno)
|
150
|
+
__class__.get_version_from_device(serialno=serialno)
|
151
|
+
)
|
152
|
+
)
|
125
153
|
|
126
154
|
@staticmethod
|
127
155
|
def get_launch_component():
|
@@ -146,7 +174,7 @@ class AudioWorkerApp(AppInterface):
|
|
146
174
|
ack_funcs = [
|
147
175
|
__class__.playback_info,
|
148
176
|
__class__.record_info,
|
149
|
-
__class__.voip_info
|
177
|
+
__class__.voip_info,
|
150
178
|
]
|
151
179
|
|
152
180
|
for func in ack_funcs:
|
@@ -177,16 +205,25 @@ class AudioWorkerApp(AppInterface):
|
|
177
205
|
cmd_arr += ["--es", key]
|
178
206
|
cmd_arr.append(str(value))
|
179
207
|
|
180
|
-
__class__.device_shell(
|
181
|
-
device=device, serialno=serialno, cmd=" ".join(cmd_arr), tolog=tolog)
|
208
|
+
__class__.device_shell(device=device, serialno=serialno, cmd=" ".join(cmd_arr), tolog=tolog)
|
182
209
|
|
183
210
|
@staticmethod
|
184
211
|
def playback_nonoffload(
|
185
|
-
device=None,
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
212
|
+
device=None,
|
213
|
+
serialno=None,
|
214
|
+
freqs=[440.0],
|
215
|
+
playback_id=0,
|
216
|
+
file="null",
|
217
|
+
stream_type=PlaybackStream.MUSIC,
|
218
|
+
performance_mode=PlaybackPerformanceMode.NOT_SET,
|
219
|
+
content_type=PlaybackContentType.MUSIC,
|
220
|
+
usage=PlaybackUsage.MEDIA,
|
221
|
+
fs=16000,
|
222
|
+
nch=2,
|
223
|
+
amp=0.6,
|
224
|
+
bit_depth=16,
|
225
|
+
low_latency_mode=False,
|
226
|
+
):
|
190
227
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "playback.start"
|
191
228
|
configs = {
|
192
229
|
"type": "non-offload",
|
@@ -201,7 +238,7 @@ class AudioWorkerApp(AppInterface):
|
|
201
238
|
"stream-type": stream_type,
|
202
239
|
"usage": usage,
|
203
240
|
"content-type": content_type,
|
204
|
-
"performance-mode": performance_mode
|
241
|
+
"performance-mode": performance_mode,
|
205
242
|
}
|
206
243
|
__class__.send_intent(device, serialno, name, configs)
|
207
244
|
|
@@ -211,15 +248,25 @@ class AudioWorkerApp(AppInterface):
|
|
211
248
|
configs = {
|
212
249
|
"type": "non-offload",
|
213
250
|
"playback-id": playback_id,
|
214
|
-
"seek-position-ms"
|
251
|
+
"seek-position-ms": seek_position_ms,
|
215
252
|
}
|
216
253
|
__class__.send_intent(device, serialno, name, configs)
|
217
254
|
|
218
255
|
@staticmethod
|
219
256
|
def playback_offload(
|
220
|
-
device=None,
|
221
|
-
|
222
|
-
|
257
|
+
device=None,
|
258
|
+
serialno=None,
|
259
|
+
file="null",
|
260
|
+
stream_type=PlaybackStream.MUSIC,
|
261
|
+
content_type=PlaybackContentType.MUSIC,
|
262
|
+
usage=PlaybackUsage.MEDIA,
|
263
|
+
freqs=[440.0],
|
264
|
+
playback_id=0,
|
265
|
+
fs=16000,
|
266
|
+
nch=2,
|
267
|
+
amp=0.6,
|
268
|
+
bit_depth=16,
|
269
|
+
):
|
223
270
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "playback.start"
|
224
271
|
configs = {
|
225
272
|
"type": "offload",
|
@@ -242,13 +289,19 @@ class AudioWorkerApp(AppInterface):
|
|
242
289
|
configs = {
|
243
290
|
"type": "offload",
|
244
291
|
"playback-id": playback_id,
|
245
|
-
"seek-position-ms"
|
292
|
+
"seek-position-ms": seek_position_ms,
|
246
293
|
}
|
247
294
|
__class__.send_intent(device, serialno, name, configs)
|
248
295
|
|
249
296
|
@staticmethod
|
250
297
|
def _common_info(
|
251
|
-
device=None,
|
298
|
+
device=None,
|
299
|
+
serialno=None,
|
300
|
+
ctype=None,
|
301
|
+
controller=None,
|
302
|
+
tolog=False,
|
303
|
+
extra_params={},
|
304
|
+
):
|
252
305
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "{}.info".format(ctype)
|
253
306
|
ts = datetime.datetime.timestamp(datetime.datetime.now())
|
254
307
|
ts = int(ts * 1000)
|
@@ -261,7 +314,8 @@ class AudioWorkerApp(AppInterface):
|
|
261
314
|
retry = 10
|
262
315
|
while retry > 0:
|
263
316
|
out, err = __class__.device_shell(
|
264
|
-
None, serialno, cmd="cat {}".format(filepath), tolog=tolog
|
317
|
+
None, serialno, cmd="cat {}".format(filepath), tolog=tolog
|
318
|
+
)
|
265
319
|
if len(out) == 0:
|
266
320
|
time.sleep(0.5)
|
267
321
|
retry -= 1
|
@@ -276,8 +330,9 @@ class AudioWorkerApp(AppInterface):
|
|
276
330
|
return {}
|
277
331
|
|
278
332
|
import traceback
|
333
|
+
|
279
334
|
try:
|
280
|
-
info_timestamp = float(out[0].strip().split("::")[1]) / 1000.
|
335
|
+
info_timestamp = float(out[0].strip().split("::")[-1]) / 1000.0
|
281
336
|
info_t = datetime.datetime.fromtimestamp(info_timestamp)
|
282
337
|
# if (datetime.datetime.now() - info_t).total_seconds() > 1:
|
283
338
|
# return None
|
@@ -290,7 +345,8 @@ class AudioWorkerApp(AppInterface):
|
|
290
345
|
@staticmethod
|
291
346
|
def playback_info(device=None, serialno=None, tolog=False):
|
292
347
|
return __class__._common_info(
|
293
|
-
device, serialno, "playback", "PlaybackController", tolog=tolog
|
348
|
+
device, serialno, "playback", "PlaybackController", tolog=tolog
|
349
|
+
)
|
294
350
|
|
295
351
|
@staticmethod
|
296
352
|
def playback_stop(device=None, serialno=None, tolog=False):
|
@@ -301,18 +357,20 @@ class AudioWorkerApp(AppInterface):
|
|
301
357
|
|
302
358
|
for pbtype in info.keys():
|
303
359
|
for pbid in info[pbtype].keys():
|
304
|
-
configs = {
|
305
|
-
"type": pbtype,
|
306
|
-
"playback-id": int(pbid)
|
307
|
-
}
|
360
|
+
configs = {"type": pbtype, "playback-id": int(pbid)}
|
308
361
|
__class__.send_intent(device, serialno, name, configs)
|
309
362
|
|
310
363
|
@staticmethod
|
311
364
|
def record_info(device=None, serialno=None, task_index=TaskIndex.ALL, tolog=False):
|
312
365
|
task_index = int(task_index)
|
313
366
|
info = __class__._common_info(
|
314
|
-
device,
|
315
|
-
|
367
|
+
device,
|
368
|
+
serialno,
|
369
|
+
"record",
|
370
|
+
"RecordController",
|
371
|
+
extra_params={"task-index": task_index},
|
372
|
+
tolog=tolog,
|
373
|
+
)
|
316
374
|
if info == None:
|
317
375
|
return None
|
318
376
|
|
@@ -334,11 +392,7 @@ class AudioWorkerApp(AppInterface):
|
|
334
392
|
|
335
393
|
task_index = int(task_index)
|
336
394
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "{}.detect.register".format(prefix)
|
337
|
-
configs = {
|
338
|
-
"class": dclass,
|
339
|
-
"params": params,
|
340
|
-
"task-index": task_index
|
341
|
-
}
|
395
|
+
configs = {"class": dclass, "params": params, "task-index": task_index}
|
342
396
|
__class__.send_intent(device, serialno, name, configs)
|
343
397
|
|
344
398
|
@staticmethod
|
@@ -348,10 +402,7 @@ class AudioWorkerApp(AppInterface):
|
|
348
402
|
|
349
403
|
task_index = int(task_index)
|
350
404
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "{}.detect.unregister".format(prefix)
|
351
|
-
configs = {
|
352
|
-
"class-handle": chandle,
|
353
|
-
"task-index": task_index
|
354
|
-
}
|
405
|
+
configs = {"class-handle": chandle, "task-index": task_index}
|
355
406
|
__class__.send_intent(device, serialno, name, configs)
|
356
407
|
|
357
408
|
@staticmethod
|
@@ -375,17 +426,23 @@ class AudioWorkerApp(AppInterface):
|
|
375
426
|
|
376
427
|
task_index = int(task_index)
|
377
428
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "{}.detect.setparams".format(prefix)
|
378
|
-
configs = {
|
379
|
-
"class-handle": chandle,
|
380
|
-
"params": params,
|
381
|
-
"task-index": task_index
|
382
|
-
}
|
429
|
+
configs = {"class-handle": chandle, "params": params, "task-index": task_index}
|
383
430
|
__class__.send_intent(device, serialno, name, configs)
|
384
431
|
|
385
432
|
@staticmethod
|
386
433
|
def record_start(
|
387
|
-
device=None,
|
388
|
-
|
434
|
+
device=None,
|
435
|
+
serialno=None,
|
436
|
+
fs=16000,
|
437
|
+
nch=2,
|
438
|
+
bit_depth=16,
|
439
|
+
btsco_on=True,
|
440
|
+
perf=None,
|
441
|
+
input_src=None,
|
442
|
+
api=None,
|
443
|
+
dump_buffer_ms=1000,
|
444
|
+
task_index=0,
|
445
|
+
):
|
389
446
|
task_index = int(task_index)
|
390
447
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "record.start"
|
391
448
|
configs = {
|
@@ -397,7 +454,7 @@ class AudioWorkerApp(AppInterface):
|
|
397
454
|
"audio-perf": int(perf) if perf is not None else perf,
|
398
455
|
"audio-api": int(api) if api is not None else api,
|
399
456
|
"dump-buffer-ms": dump_buffer_ms,
|
400
|
-
"task-index"
|
457
|
+
"task-index": task_index,
|
401
458
|
}
|
402
459
|
__class__.send_intent(device, serialno, name, configs)
|
403
460
|
|
@@ -438,7 +495,8 @@ class AudioWorkerApp(AppInterface):
|
|
438
495
|
|
439
496
|
@staticmethod
|
440
497
|
def record_detector_set_params(
|
441
|
-
device=None, serialno=None, chandle=None, params={}, task_index=0
|
498
|
+
device=None, serialno=None, chandle=None, params={}, task_index=0
|
499
|
+
):
|
442
500
|
__class__.tx_detector_set_params("record", device, serialno, chandle, params, task_index)
|
443
501
|
|
444
502
|
@staticmethod
|
@@ -446,8 +504,21 @@ class AudioWorkerApp(AppInterface):
|
|
446
504
|
return __class__._common_info(device, serialno, "voip", "VoIPController", tolog=tolog)
|
447
505
|
|
448
506
|
@staticmethod
|
449
|
-
def voip_start(
|
450
|
-
|
507
|
+
def voip_start(
|
508
|
+
device=None,
|
509
|
+
serialno=None,
|
510
|
+
rxfreq=440.0,
|
511
|
+
rxamp=0.6,
|
512
|
+
rxspkr=False,
|
513
|
+
rxfile="null",
|
514
|
+
rxfs=8000,
|
515
|
+
txfs=8000,
|
516
|
+
rxnch=1,
|
517
|
+
txnch=1,
|
518
|
+
rxbit_depth=16,
|
519
|
+
txbit_depth=16,
|
520
|
+
dump_buffer_ms=0,
|
521
|
+
):
|
451
522
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "voip.start"
|
452
523
|
configs = {
|
453
524
|
"rx-target-freq": rxfreq,
|
@@ -460,7 +531,7 @@ class AudioWorkerApp(AppInterface):
|
|
460
531
|
"tx-sampling-freq": txfs,
|
461
532
|
"tx-num-channels": txnch,
|
462
533
|
"tx-pcm-bit-width": txbit_depth,
|
463
|
-
"tx-dump-buffer-ms": dump_buffer_ms
|
534
|
+
"tx-dump-buffer-ms": dump_buffer_ms,
|
464
535
|
}
|
465
536
|
__class__.send_intent(device, serialno, name, configs)
|
466
537
|
|
@@ -472,9 +543,7 @@ class AudioWorkerApp(AppInterface):
|
|
472
543
|
@staticmethod
|
473
544
|
def voip_use_speaker(device=None, serialno=None, use=True):
|
474
545
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "voip.config"
|
475
|
-
configs = {
|
476
|
-
"rx-use-spkr": use
|
477
|
-
}
|
546
|
+
configs = {"rx-use-spkr": use}
|
478
547
|
__class__.send_intent(device, serialno, name, configs)
|
479
548
|
|
480
549
|
@staticmethod
|
@@ -484,10 +553,7 @@ class AudioWorkerApp(AppInterface):
|
|
484
553
|
@staticmethod
|
485
554
|
def voip_change_configs(device=None, serialno=None, rxfreq=-1, rxamp=-1):
|
486
555
|
name = __class__.AUDIOWORKER_INTENT_PREFIX + "voip.config"
|
487
|
-
configs = {
|
488
|
-
"rx-target-freq": rxfreq,
|
489
|
-
"rx-amplitude": rxamp
|
490
|
-
}
|
556
|
+
configs = {"rx-target-freq": rxfreq, "rx-amplitude": rxamp}
|
491
557
|
__class__.send_intent(device, serialno, name, configs)
|
492
558
|
|
493
559
|
@staticmethod
|
@@ -530,13 +596,24 @@ from pyaatlibs.audiofunction import ToneDetectorThread, ToneDetector
|
|
530
596
|
from pyaatlibs.aatapp import AATAppToneDetectorThread
|
531
597
|
from pyaatlibs.logger import Logger
|
532
598
|
|
599
|
+
|
533
600
|
class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
601
|
+
|
602
|
+
def __init__(
|
603
|
+
self,
|
604
|
+
serialno,
|
605
|
+
target_freq,
|
606
|
+
detector_reg_func,
|
607
|
+
detector_unreg_func,
|
608
|
+
detector_setparams_func,
|
609
|
+
info_func,
|
610
|
+
parse_detector_func,
|
611
|
+
callback=None,
|
612
|
+
listener=None,
|
613
|
+
):
|
538
614
|
super(AudioWorkerToneDetectorThread, self).__init__(
|
539
|
-
serialno=serialno, target_freq=target_freq, callback=callback
|
615
|
+
serialno=serialno, target_freq=target_freq, callback=callback
|
616
|
+
)
|
540
617
|
self.serialno = serialno
|
541
618
|
self.chandle = None
|
542
619
|
self.listener = listener
|
@@ -545,8 +622,11 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
545
622
|
self.detector_setparams_func = detector_setparams_func
|
546
623
|
self.info_func = info_func
|
547
624
|
self.parse_detector_func = parse_detector_func
|
548
|
-
self.detector_reg_func(
|
549
|
-
|
625
|
+
self.detector_reg_func(
|
626
|
+
serialno=serialno,
|
627
|
+
dclass="ToneDetector",
|
628
|
+
params={"target-freq": [target_freq]},
|
629
|
+
)
|
550
630
|
|
551
631
|
def get_tag(self):
|
552
632
|
return "AudioWorkerToneDetectorThread"
|
@@ -651,7 +731,9 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
651
731
|
info = self.info_func(serialno=self.serialno)
|
652
732
|
if not info:
|
653
733
|
Logger.log(
|
654
|
-
"{}::get_info".format(self.get_tag()),
|
734
|
+
"{}::get_info".format(self.get_tag()),
|
735
|
+
"no active record, null info returned",
|
736
|
+
)
|
655
737
|
return
|
656
738
|
|
657
739
|
detectors = self.parse_detector_func(info)
|
@@ -664,7 +746,8 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
664
746
|
if chandle:
|
665
747
|
Logger.log(
|
666
748
|
"{}::get_info".format(self.get_tag()),
|
667
|
-
"found detector handle: {} for target {} Hz".format(chandle, self.target_freq)
|
749
|
+
"found detector handle: {} for target {} Hz".format(chandle, self.target_freq),
|
750
|
+
)
|
668
751
|
|
669
752
|
if not chandle:
|
670
753
|
Logger.log("{}::get_info".format(self.get_tag()), "no detector handle!")
|
@@ -678,14 +761,22 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
678
761
|
return
|
679
762
|
|
680
763
|
self.detector_setparams_func(
|
681
|
-
serialno=self.serialno,
|
682
|
-
|
764
|
+
serialno=self.serialno,
|
765
|
+
chandle=self.chandle,
|
766
|
+
params={"dump-history": str(enable).lower()},
|
767
|
+
)
|
683
768
|
|
684
769
|
def set_target_frequency(self, target_freq):
|
685
770
|
self.target_freq = target_freq
|
686
771
|
self.detector_setparams_func(
|
687
|
-
serialno=self.serialno,
|
688
|
-
|
772
|
+
serialno=self.serialno,
|
773
|
+
chandle=self.chandle,
|
774
|
+
params={
|
775
|
+
"target-freq": [target_freq],
|
776
|
+
"clear-target": "false",
|
777
|
+
"dump-history": "true",
|
778
|
+
},
|
779
|
+
)
|
689
780
|
self.shared_vars["msg"] = None
|
690
781
|
|
691
782
|
def run(self):
|
@@ -695,7 +786,7 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
695
786
|
"last_state": None,
|
696
787
|
"msg": None,
|
697
788
|
"tictoc": TicToc(),
|
698
|
-
"state_keep_ms": 0
|
789
|
+
"state_keep_ms": 0,
|
699
790
|
}
|
700
791
|
|
701
792
|
self.extra = {}
|
@@ -709,15 +800,14 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
709
800
|
def freq_cb(msg):
|
710
801
|
line = msg.splitlines()[0].strip()
|
711
802
|
strs = line.split()
|
712
|
-
t = datetime.datetime.fromtimestamp(float(strs[0][:-1]) / 1000.)
|
803
|
+
t = datetime.datetime.fromtimestamp(float(strs[0][:-1]) / 1000.0)
|
713
804
|
freq = float(strs[1])
|
714
805
|
|
715
806
|
if not self.target_detected(freq):
|
716
|
-
self.push_to_dump(
|
717
|
-
"the frequency {} Hz is not the target".format(freq))
|
807
|
+
self.push_to_dump("the frequency {} Hz is not the target".format(freq))
|
718
808
|
return
|
719
809
|
|
720
|
-
active =
|
810
|
+
active = strs[2].lower() == "active"
|
721
811
|
|
722
812
|
if not self.shared_vars["start_time"]:
|
723
813
|
self.shared_vars["start_time"] = t
|
@@ -725,7 +815,9 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
725
815
|
if active != self.shared_vars["last_state"]:
|
726
816
|
self.push_to_dump(
|
727
817
|
"the detection state has been changed from {} to {}".format(
|
728
|
-
self.shared_vars["last_state"], active
|
818
|
+
self.shared_vars["last_state"], active
|
819
|
+
)
|
820
|
+
)
|
729
821
|
self.shared_vars["last_state"] = active
|
730
822
|
self.shared_vars["start_time"] = t
|
731
823
|
self.shared_vars["tictoc"].toc()
|
@@ -736,14 +828,19 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
736
828
|
|
737
829
|
self.shared_vars["state_keep_ms"] += self.shared_vars["tictoc"].toc()
|
738
830
|
if self.shared_vars["state_keep_ms"] > 200:
|
739
|
-
event =
|
831
|
+
event = (
|
740
832
|
ToneDetector.Event.TONE_DETECTED if active else ToneDetector.Event.TONE_MISSING
|
833
|
+
)
|
741
834
|
if self.shared_vars["last_event"] != event:
|
742
835
|
self.shared_vars["last_event"] = event
|
743
|
-
Logger.log(
|
836
|
+
Logger.log(
|
837
|
+
self.get_tag(),
|
744
838
|
"send_cb({}, {}) on {} Hz".format(
|
745
|
-
t_str,
|
746
|
-
else "TONE_MISSING",
|
839
|
+
t_str,
|
840
|
+
"TONE_DETECTED" if active else "TONE_MISSING",
|
841
|
+
self.target_freq,
|
842
|
+
),
|
843
|
+
)
|
747
844
|
if self.cb != None:
|
748
845
|
self.cb((t_str, event))
|
749
846
|
if isinstance(self.listener, DetectionStateListener):
|
@@ -761,15 +858,20 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
761
858
|
|
762
859
|
adb_tictoc.tic()
|
763
860
|
msg_in_device, _ = Adb.execute(
|
764
|
-
cmd=[
|
765
|
-
"
|
766
|
-
|
861
|
+
cmd=[
|
862
|
+
"shell",
|
863
|
+
"cat {}/{}.txt".format(AudioWorkerApp.DATA_FOLDER, self.chandle),
|
864
|
+
],
|
865
|
+
serialno=self.serialno,
|
866
|
+
tolog=False,
|
867
|
+
)
|
767
868
|
elapsed = adb_tictoc.toc()
|
768
869
|
|
769
870
|
msg_in_device = map(lambda x: x.strip(), msg_in_device.splitlines())
|
770
871
|
msg_in_device = [x for x in msg_in_device if self.target_detected(float(x.split()[1]))]
|
771
|
-
self.shared_vars["msg"] =
|
872
|
+
self.shared_vars["msg"] = (
|
772
873
|
msg_in_device[-1] if len(msg_in_device) > 0 else self.shared_vars["msg"]
|
874
|
+
)
|
773
875
|
|
774
876
|
if elapsed > self.extra["adb-read-prop-max-elapsed"]:
|
775
877
|
self.extra["adb-read-prop-max-elapsed"] = elapsed
|
@@ -777,11 +879,14 @@ class AudioWorkerToneDetectorThread(AATAppToneDetectorThread):
|
|
777
879
|
if self.shared_vars["msg"]:
|
778
880
|
try:
|
779
881
|
self.push_to_dump(
|
780
|
-
"{} (adb-shell elapsed: {} ms)".format(self.shared_vars["msg"], elapsed)
|
882
|
+
"{} (adb-shell elapsed: {} ms)".format(self.shared_vars["msg"], elapsed)
|
883
|
+
)
|
781
884
|
freq_cb(self.shared_vars["msg"])
|
782
885
|
except Exception as e:
|
783
886
|
Logger.log(
|
784
|
-
self.get_tag(),
|
887
|
+
self.get_tag(),
|
888
|
+
"crashed in freq_cb('{}')".format(self.shared_vars["msg"]),
|
889
|
+
)
|
785
890
|
Logger.log(self.get_tag(), str(e))
|
786
891
|
|
787
892
|
elapsed = freq_cb_tictoc.toc()
|
pyaatlibs/logcatlistener.py
CHANGED
@@ -14,7 +14,9 @@ try:
|
|
14
14
|
except ImportError:
|
15
15
|
import Queue as queue
|
16
16
|
|
17
|
+
|
17
18
|
class LogcatOutputThread(threading.Thread):
|
19
|
+
|
18
20
|
def __init__(self, serialno, buffername):
|
19
21
|
super(LogcatOutputThread, self).__init__()
|
20
22
|
self.serialno = serialno
|
@@ -44,9 +46,12 @@ class LogcatOutputThread(threading.Thread):
|
|
44
46
|
preexec_fn = None if platform.system() == "Windows" else os.setsid
|
45
47
|
cmd = ["adb", "-s", self.serialno, "logcat"]
|
46
48
|
cmd = cmd + ["-b", self.buffername] if self.buffername else cmd
|
47
|
-
Logger.log(
|
48
|
-
|
49
|
-
|
49
|
+
Logger.log(
|
50
|
+
"LogcatOutputThread", "threadloop is listening with the command '{}'".format(cmd)
|
51
|
+
)
|
52
|
+
self.proc = subprocess.Popen(
|
53
|
+
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=preexec_fn
|
54
|
+
)
|
50
55
|
while not self.stoprequest.isSet():
|
51
56
|
if self.proc.poll() != None:
|
52
57
|
break
|
@@ -56,9 +61,9 @@ class LogcatOutputThread(threading.Thread):
|
|
56
61
|
if sys.version_info.major > 2:
|
57
62
|
line = line.decode("utf-8", errors="ignore")
|
58
63
|
|
59
|
-
if not self.lasttime_update_timer.is_alive():
|
64
|
+
if not self.lasttime_update_timer.is_alive(): # start for the first time
|
60
65
|
self.lasttime_update_timer.start()
|
61
|
-
else:
|
66
|
+
else: # reset for the followings
|
62
67
|
self.lasttime_update_timer.reset()
|
63
68
|
self._handle_logcat_msg(line)
|
64
69
|
|
@@ -74,11 +79,14 @@ class LogcatOutputThread(threading.Thread):
|
|
74
79
|
if pattern in msg:
|
75
80
|
self.listeners[pattern].cb(pattern=pattern, msg=msg)
|
76
81
|
|
82
|
+
|
77
83
|
class LogcatEvent(object):
|
84
|
+
|
78
85
|
def __init__(self, pattern=None, cb=None):
|
79
86
|
self.pattern = pattern
|
80
87
|
self.cb = cb
|
81
88
|
|
89
|
+
|
82
90
|
class LogcatListener(object):
|
83
91
|
WORK_THREADS = {}
|
84
92
|
|
@@ -88,8 +96,10 @@ class LogcatListener(object):
|
|
88
96
|
|
89
97
|
for threadname, th in LogcatListener.WORK_THREADS.items():
|
90
98
|
Logger.log("LogcatListener::dump", "thread[{}]".format(threadname))
|
91
|
-
Logger.log(
|
92
|
-
"
|
99
|
+
Logger.log(
|
100
|
+
"LogcatListener::dump",
|
101
|
+
" - Last time processing: {} ms ago".format(th.lasttime_update_timer.get_time()),
|
102
|
+
)
|
93
103
|
for event_pattern in th.listeners.keys():
|
94
104
|
Logger.log("LogcatListener::dump", " - pattern '{}'".format(event_pattern))
|
95
105
|
|
@@ -119,7 +129,8 @@ class LogcatListener(object):
|
|
119
129
|
threadname = "{}-{}".format(serialno, buffername)
|
120
130
|
if threadname in LogcatListener.WORK_THREADS.keys():
|
121
131
|
Logger.log(
|
122
|
-
"LogcatListener", "there is an existing running thread ({}).".format(threadname)
|
132
|
+
"LogcatListener", "there is an existing running thread ({}).".format(threadname)
|
133
|
+
)
|
123
134
|
if not flush:
|
124
135
|
Logger.log("LogcatListener", "skip the initialization.")
|
125
136
|
return
|