def voip_task_run(device, serialno, num_iter=1): log("voip_task_run++") trials = [] # AATApp.voip_use_speaker(device) time.sleep(2) th = DetectionStateChangeListenerThread() th.start() log("ToneDetector.start_listen(target_freq={})".format(serialno, OUT_FREQ)) ToneDetector.start_listen( target_freq=OUT_FREQ, cb=lambda event: th.tone_detected_event_cb(event)) AATApp.voip_start(device) for i in range(num_iter): log("-------- dev_voip_rx_task #{} --------".format(i + 1)) trial = Trial(taskname="voip_rx") trial.put_extra(name="iter_id", value=i + 1) time.sleep(1) th.reset() log("trigger_asr() for idle") trigger_asr(serialno) #time.sleep(2) if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time...") trial.invalidate( errormsg="early return, possible reason: rx no sound") trials.append(trial) continue time.sleep(1) log("trigger_asr()") #AATApp.trigger_ssr(device) trigger_asr(serialno) if PARTIAL_RAMDUMP_ENABLED: handle_ssr_ui() log("Waiting for ASR recovery") elapsed = th.wait_for_event( DetectionStateChangeListenerThread.Event.RISING_EDGE, timeout=10) log("elapsed: {} ms".format(elapsed)) if PARTIAL_RAMDUMP_ENABLED: log("Waiting for the partial ramdump completed") handle_ssr_ui() if elapsed >= 0 and not PARTIAL_RAMDUMP_ENABLED: time.sleep(10 - elapsed / 1000.0) trial.put_extra(name="elapsed", value=elapsed) trials.append(trial) log("-------- dev_voip_rx_task done --------") log("ToneDetector.stop_listen()") ToneDetector.stop_listen() th.join() th = DetectionStateChangeListenerThread() th.start() time.sleep(2) AATApp.voip_mute_output(device) time.sleep(10) log("ToneDetector.start_listen(serialno={}, target_freq={})".format( serialno, None)) ToneDetector.start_listen( serialno=serialno, target_freq=None, cb=lambda event: th.tone_detected_event_cb(event)) for i in range(num_iter): log("-------- dev_voip_tx_task #{} --------".format(i + 1)) trial = Trial(taskname="voip_tx") trial.put_extra(name="iter_id", value=i + 1) time.sleep(2) log("trigger_asr() for idle") trigger_asr(serialno) #time.sleep(2) log("AudioFunction.play_sound(out_freq={})".format(OUT_FREQ)) AudioFunction.play_sound(out_freq=OUT_FREQ) th.reset() if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time...") trial.invalidate( errormsg="early return, possible reason: tx no sound") trials.append(trial) continue time.sleep(2) log("trigger_asr()") #AATApp.trigger_ssr(device) trigger_asr(serialno) if PARTIAL_RAMDUMP_ENABLED: handle_ssr_ui() log("Waiting for ASR recovery") elapsed = th.wait_for_event( DetectionStateChangeListenerThread.Event.RISING_EDGE, timeout=10) log("elapsed: {} ms".format(elapsed)) if PARTIAL_RAMDUMP_ENABLED: log("Waiting for the partial ramdump completed") handle_ssr_ui() if elapsed >= 0 and not PARTIAL_RAMDUMP_ENABLED: time.sleep(10 - elapsed / 1000.0) trial.put_extra(name="elapsed", value=elapsed) trials.append(trial) log("AudioFunction.stop_audio()") AudioFunction.stop_audio() log("-------- dev_voip_tx_task done --------") log("dev_voip_stop") AATApp.voip_stop(device) time.sleep(5) log("ToneDetector.stop_listen()") ToneDetector.stop_listen() th.join() log("voip_task_run--") return trials
def voip_task_run(device, serialno, num_iter=1): log("voip_task_run++") trials = [] AATApp.voip_use_speaker(device) time.sleep(2) th = DetectionStateChangeListenerThread() th.start() log("ToneDetector.start_listen(target_freq={})".format(serialno, OUT_FREQ)) ToneDetector.start_listen(target_freq=OUT_FREQ, cb=lambda event: th.tone_detected_event_cb(event)) AATApp.voip_start(device) for i in range(num_iter): log("-------- dev_voip_rx_task #{} --------".format(i+1)) trial = Trial(taskname="voip_rx") trial.put_extra(name="iter_id", value=i+1) time.sleep(1) th.reset() if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time...") trial.invalidate(errormsg="early return, possible reason: rx no sound") trials.append(trial) continue else: log("--> VOIP: rx pass") time.sleep(1) trials.append(trial) log("-------- dev_voip_rx_task done --------") log("ToneDetector.stop_listen()") ToneDetector.stop_listen() th.join() th = DetectionStateChangeListenerThread() th.start() time.sleep(2) log("-> VOIP: mute output") AATApp.voip_mute_output(device) time.sleep(10) log("ToneDetector.start_listen(serialno={}, target_freq={})".format(serialno, None)) ToneDetector.start_listen(serialno=serialno, target_freq=None, cb=lambda event: th.tone_detected_event_cb(event)) for i in range(num_iter): log("-------- dev_voip_tx_task #{} --------".format(i+1)) trial = Trial(taskname="voip_tx") trial.put_extra(name="iter_id", value=i+1) time.sleep(2) log("AudioFunction.play_sound(out_freq={})".format(OUT_FREQ)) AudioFunction.play_sound(out_freq=OUT_FREQ) th.reset() if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the iteration this time...") trial.invalidate(errormsg="early return, possible reason: tx no sound") trials.append(trial) continue else: log("--> VOIP: tx pass") time.sleep(2) trials.append(trial) log("AudioFunction.stop_audio()") AudioFunction.stop_audio() log("-------- dev_voip_tx_task done --------") log("dev_voip_stop") AATApp.voip_stop(device) time.sleep(5) log("ToneDetector.stop_listen()") ToneDetector.stop_listen() th.join() log("voip_task_run--") return trials