Ejemplo n.º 1
0
def record_task_run(device, serialno):
    log("dev_record_start")
    AATApp.record_start(device)
    time.sleep(2)

    th = DetectionStateChangeListenerThread()
    th.start()

    log("ToneDetector.start_listen(serialno={}, target_freq={})".format(
        serialno, OUT_FREQ))
    ToneDetector.start_listen(
        serialno=serialno,
        target_freq=OUT_FREQ,
        cb=lambda event: th.tone_detected_event_cb(event))
    log("AudioFunction.play_sound(out_freq={})".format(OUT_FREQ))
    AudioFunction.play_sound(out_freq=OUT_FREQ)

    time.sleep(3)

    def stop_then_play():
        log("thread stops the playback")
        AudioFunction.stop_audio()
        time.sleep(4)
        log("thread starts the playback")
        AudioFunction.play_sound(out_freq=OUT_FREQ)
        log("thread returns")

    threading.Thread(target=stop_then_play).start()
    log("Waiting for {} Hz pure tone detected".format(OUT_FREQ))
    elapsed = th.wait_for_event(
        DetectionStateChangeListenerThread.Event.RISING_EDGE, timeout=10)
    log("elapsed: {} ms".format(elapsed))

    time.sleep(1)

    log("Trying to wait a timeout event")
    elapsed = th.wait_for_event(
        DetectionStateChangeListenerThread.Event.FALLING_EDGE, timeout=10)
    log("elapsed: {} ms".format(elapsed))

    log("dev_record_stop")
    AATApp.record_stop(device)

    log("ToneDetector.stop_listen()")
    ToneDetector.stop_listen()
    th.join()

    AudioFunction.stop_audio()
Ejemplo n.º 2
0
def playback_task_run(device):
    log("dev_playback_start(nonoffload)")
    AATApp.playback_nonoffload(device)

    th = DetectionStateChangeListenerThread()
    th.start()

    log("ToneDetector.start_listen(target_freq={})".format(OUT_FREQ))
    ToneDetector.start_listen(
        target_freq=OUT_FREQ,
        cb=lambda event: th.tone_detected_event_cb(event))

    # Waiting for the event of tone detected, blocking with a 5 secs timeout
    if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE,
                         timeout=5) < 0:
        log("the tone was not detected, abort the function...")
        AATApp.playback_stop(device)
        return

    time.sleep(1)

    # The thread just stops the playback and then continues
    def dev_stop_then_play():
        log("thread stops the playback")
        AATApp.playback_stop(device)
        time.sleep(4)
        log("thread starts the playback")
        AATApp.playback_nonoffload(device)
        log("thread returns")

    threading.Thread(target=dev_stop_then_play).start()
    log("Waiting for {} Hz pure tone detected".format(OUT_FREQ))

    # Waiting the event that the tone is detected again after the tone is missing
    elapsed = th.wait_for_event(
        DetectionStateChangeListenerThread.Event.RISING_EDGE, timeout=10)
    log("elapsed: {} ms".format(elapsed))

    log("ToneDetector.stop_listen()")
    ToneDetector.stop_listen()
    th.join()

    log("dev_playback_stop(nonoffload)")
    AATApp.playback_stop(device)
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
def playback_task_run(device, serialno, num_iter=1):
    log("playback_task_run++")

    trials = []

    th = DetectionStateChangeListenerThread()
    th.start()

    log("ToneDetector.start_listen(target_freq={})".format(OUT_FREQ))
    ToneDetector.start_listen(
        target_freq=OUT_FREQ,
        cb=lambda event: th.tone_detected_event_cb(event))

    funcs = {
        "nonoffload": AATApp.playback_nonoffload,
        "offload": AATApp.playback_offload
    }

    for i in range(num_iter):
        log("-------- playback_task #{} --------".format(i + 1))
        for name, func in funcs.items():
            trial = Trial(taskname="playback_{}".format(name))
            trial.put_extra(name="iter_id", value=i + 1)

            log("dev_playback_{}_start".format(name))
            time.sleep(1)
            th.reset()
            log("trigger_asr() for idle")
            trigger_asr(serialno)
            #time.sleep(2)
            log("reset DetectionStateChangeListener")
            func(device)

            if th.wait_for_event(
                    DetectionStateChangeListenerThread.Event.ACTIVE,
                    timeout=5) < 0:
                log("the tone was not detected, abort the iteration this time..."
                    )
                AATApp.playback_stop(device)
                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 SSR 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_playback_stop")
            AATApp.playback_stop(device)
            th.wait_for_event(
                DetectionStateChangeListenerThread.Event.INACTIVE, timeout=5)

    log("-------- playback_task done --------")
    log("ToneDetector.stop_listen()")
    ToneDetector.stop_listen()
    th.join()

    log("playback_task_run--")
    return trials
Ejemplo n.º 5
0
def control_GoogleMusic(device, serialno, num_iter=1):
    # Google Music
    # play
    # pause
    # resume
    # seek
    # forward
    # offload/non-offload
    log("GoogleMusic playback++")

    packageGM = "com.google.android.music"
    activityGM = "com.android.music.activitymanagement.TopLevelActivity"
    componentGM = packageGM + "/" + activityGM
    cmd = " ".join(["am", "force-stop", packageGM])

    th = DetectionStateChangeListenerThread()
    th.start()

    log("ToneDetector.start_listen(target_freq={})".format(OUT_FREQ))
    ToneDetector.start_listen(
        target_freq=OUT_FREQ,
        cb=lambda event: th.tone_detected_event_cb(event))

    device.wake()
    log("wake")
    time.sleep(1)
    device.startActivity(componentGM)
    log("startActivity")
    time.sleep(5)
    device.touch(700, 1100)
    log("into tool bar 1")
    time.sleep(2)
    device.touch(700, 2500)  # into tool bar
    log("into tool bar 2")
    time.sleep(2)

    #-------------------------------------------
    th.reset()

    device.touch(720, 2400)  # play
    log("play1")

    if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE,
                         timeout=5) < 0:
        log("the tone was not detected...")
        device.shell(cmd)
        return

    time.sleep(2)

    device.touch(720, 2400)  # pause
    log("pause")

    elapsed = th.wait_for_event(
        DetectionStateChangeListenerThread.Event.RISING_EDGE, timeout=10)
    if elapsed < 0:
        log("the tone was not pause...")
        device.shell(cmd)
        return

    time.sleep(2)

    device.touch(720, 2400)  # play
    log("play2")

    if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE,
                         timeout=5) < 0:
        log("the tone was not resume...")
        device.shell(cmd)
        return

    time.sleep(5)

    device.touch(30, 2200)  # seek-1
    log("seek-1")

    if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE,
                         timeout=5) < 0:
        log("the tone was not seek-1...")
        device.shell(cmd)
        return

    time.sleep(5)

    device.touch(1000, 2200)  # seek-1
    log("seek-2")

    if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE,
                         timeout=5) < 0:
        log("the tone was not seek-1...")
        device.shell(cmd)
        return

    time.sleep(5)

    device.touch(1000, 2400)  # next
    log("next")

    if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE,
                         timeout=5) < 0:
        log("the tone was not next...")
        device.shell(cmd)
        return

    time.sleep(5)

    device.touch(720, 2400)  # stop
    log("stop")

    elapsed = th.wait_for_event(
        DetectionStateChangeListenerThread.Event.RISING_EDGE, timeout=10)
    if elapsed < 0:
        log("the tone was not stop...")
        device.shell(cmd)
        return

    time.sleep(5)
    log("ToneDetector.stop_listen()")
    ToneDetector.stop_listen()

    device.shell(cmd)
    log("complete playback task")
    th.join()
Ejemplo n.º 6
0
def playback_task2_run(device, num_iter=1):
    package = "com.htc.audiofunctionsdemo"
    activity = ".activities.MainActivity"
    component = package + "/" + activity

    log("playback_task2_run++")
    device.startActivity(component=component)

    th = DetectionStateChangeListenerThread()
    th.start()

    log("ToneDetector.start_listen(target_freq={})".format(OUT_FREQ))
    ToneDetector.start_listen(
        target_freq=OUT_FREQ,
        cb=lambda event: th.tone_detected_event_cb(event))

    funcs = {
        "nonoffload": AATApp.playback_nonoffload,
    }

    formats = {
        "1k_Stereo_48k_16bits_aac.aac": 1000,
        "1k_Stereo_48k_16bits_wav.wav": 1000,
        "1k_Stereo_96k_24bits_flac.flac": 1000
    }

    freqss = {440, 1100, 1150}

    for i in range(num_iter):
        log("-------- playback_task2 #{} --------".format(i + 1))
        for name, func in funcs.items():
            log("dev_playback_{}_start".format(name))

            for file, freq in formats.items():

                log("ToneDetector.start_listen(target_freq={})".format(freq))
                ToneDetector.start_listen(
                    target_freq=freq,
                    cb=lambda event: th.tone_detected_event_cb(event))

                log("dev_playback_{}_start".format(name))
                time.sleep(2)
                th.reset()
                log("reset DetectionStateChangeListener")
                func(device, file)

                log("-> playback start:")
                if th.wait_for_event(
                        DetectionStateChangeListenerThread.Event.ACTIVE,
                        timeout=5) < 0:
                    log("the tone was not detected, abort the iteration this time..."
                        )
                    AATApp.playback_stop(device)
                    continue
                else:
                    log("-> playback start: pass")
                time.sleep(2)
                '''
                log("-> playback pause:")
                th.reset()
                AATApp.playback_pause_resume(device)
                time.sleep(1)
                if th.wait_for_event(DetectionStateChangeListenerThread.Event.INACTIVE, timeout=5) < 0:
                    log("the tone was not detected, abort the iteration this time...")
                    AATApp.playback_stop(device)
                    continue
                else:
                    log("-> playback pause: pass")
                time.sleep(1)

                log("-> playback resume:")
                th.reset()
                AATApp.playback_pause_resume(device)
                if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0:
                    log("the tone was not detected, abort the iteration this time...")
                    AATApp.playback_stop(device)
                    continue
                else:
                    log("-> playback resume: pass")
                time.sleep(1)
                '''

                log("-> playback seek:")
                th.reset()
                AATApp.playback_seek(device)
                if th.wait_for_event(
                        DetectionStateChangeListenerThread.Event.ACTIVE,
                        timeout=5) < 0:
                    log("the tone was not detected, abort the iteration this time..."
                        )
                    AATApp.playback_stop(device)
                    continue
                else:
                    log("-> playback seek: pass")
                time.sleep(2)

                log("-> playback forward:")
                th.reset()
                AATApp.playback_forward(device)
                if th.wait_for_event(
                        DetectionStateChangeListenerThread.Event.ACTIVE,
                        timeout=5) < 0:
                    log("the tone was not detected, abort the iteration this time..."
                        )
                    AATApp.playback_stop(device)
                    continue
                else:
                    log("-> playback forward: pass")
                time.sleep(2)

                log("dev_playback_stop")
                th.reset()
                AATApp.playback_stop(device)
                log("stoping->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
                th.wait_for_event(
                    DetectionStateChangeListenerThread.Event.INACTIVE,
                    timeout=3)

                log("stoping")
                #time.sleep(1)

    log("-------- playback_task2 done --------")
    log("ToneDetector.stop_listen()")
    ToneDetector.stop_listen()
    th.join()

    log("playback_task2_run--")
    return
Ejemplo n.º 7
0
def playback_task_run(device, num_iter=1):
    package = "com.htc.audiofunctionsdemo"
    activity = ".activities.MainActivity"
    component = package + "/" + activity

    # force stop app string
    cmd = " ".join(["am", "force-stop", package])

    log("playback_task_run++")
    device.startActivity(component=component)
    time.sleep(1)

    th = DetectionStateChangeListenerThread()
    th.start()

    funcs = {
        "nonoffload": AATApp.playback_nonoffload,
        #"offload"   : AATApp.playback_offload
    }

    for i in range(num_iter):
        log("-------- playback_task #{} --------".format(i + 1))
        for name, func in funcs.items():
            func(device, "pop.wav")
            time.sleep(1)
            log("ToneDetector.start_listen(target_freq={})".format(OUT_FREQ))
            ToneDetector.start_listen(
                target_freq=OUT_FREQ,
                cb=lambda event: th.tone_detected_event_cb(event))
            log("dev_playback_{}_start".format(name))
            th.reset()
            log("reset DetectionStateChangeListener")

            log("-> playback start:")
            '''
            if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=1) < 0:
                log("the tone was not detected, abort the iteration this time...")
                AATApp.playback_stop(device)
                continue
            else:
                log("-> playback start: pass")
            '''
            pop = AudioFunction.get_pop()
            if pop:
                log("pop detect")
            else:
                log("no pop")

            time.sleep(4)

            pop = AudioFunction.get_pop()
            if pop:
                log("pop detect")
            else:
                log("no pop")

            log("dev_playback_stop")
            th.reset()
            AATApp.playback_stop(device)
            time.sleep(2)

            #th.wait_for_event(DetectionStateChangeListenerThread.Event.INACTIVE, timeout=1)

            log("stoping")

    log("-------- playback_task done --------")
    log("ToneDetector.stop_listen()")
    ToneDetector.stop_listen()
    th.join()
    AATApp.playback_stop(device)
    device.shell(cmd)

    log("playback_task_run--")
    return
Ejemplo n.º 8
0
def playback_GoogleMusic_run(device, serialno, num_iter=1):
    # Google Music
    # play
    # pause
    # resume
    # seek
    # forward
    log("GoogleMusic playback++")
    
    packageGM = "com.google.android.music"
    activityGM = "com.android.music.activitymanagement.TopLevelActivity"
    componentGM = packageGM + "/" + activityGM
    
    cmd = " ".join(["am", "force-stop", packageGM])
    
    freq = 440
    
    trials = []
    
    th = DetectionStateChangeListenerThread()
    th.start()
    
    for i in range(num_iter):
        trial = Trial(taskname="GoogleMusic playback")
        trial.put_extra(name="iter_id", value=i+1)

        # start google music
        device.wake() 
        time.sleep(1)
        device.startActivity(componentGM)
        log("-> GoogleMusic start")

        # into Music list
        log("-> GoogleMusic into Music list")
        vc, key = get_MusicList_id(device, serialno)
        if vc is None:
            log("can't find Music list")
            trial.invalidate(errormsg="can't find Music list")
            trials.append(trial)
            device.shell(cmd)
            continue

        log("find the Music list")
        control_Btn(vc, key)    

        # find 440Hz in list
        log("-> GoogleMusic find 440Hz in list")
        vc = ViewClient(device, serialno)
        view = get_fragment_list_view(device, serialno)
        uis = UiScrollable(view)

        for i in range(3):
            vc, key = get_File_id(device, serialno)
            if key is None:
                log("scroll")
                uis.flingForward()
                continue
            else:
                control_Btn(vc, key)
                break;

        # into art pager interface
        log("-> GoogleMusic into art pager")
        vc, key = get_ArtPager_id(device, serialno)
        if vc is None:
            log("can't find Art Pager")
            trial.invalidate(errormsg="GoogleMusic can't find Art Pager")
            trials.append(trial)
            device.shell(cmd)
            continue

        log("find the Art Pager")
        control_Btn(vc, key)  

        log("ToneDetector.start_listen(target_freq={})".format(freq))
        ToneDetector.start_listen(target_freq=freq, cb=lambda event: th.tone_detected_event_cb(event))

        th.reset()

        # the music already start, so detect it...
        log("-> GoogleMusic start function:")
        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="GoogleMusic start play fail")
            trials.append(trial)
            device.shell(cmd)
            continue
        else:
            log("-> GoogleMusic start function: pass")
            trial.put_extra(name="GoogleMusic start", value="pass")    

        pop = AudioFunction.get_pop()
        if pop:
            log("pop detect")
            trial.put_extra(name="playback start", value="pop")
                    
        # pause
        log("-> GoogleMusic pause function:")
        vc, key = get_play_pause_id(device, serialno)
        if vc is None:
            log("can't find pause btn")
            trial.invalidate(errormsg="can't find pause btn")
            trials.append(trial)
            device.shell(cmd)
            continue

        log("find the pause btn")
        control_Btn(vc, key)

        if th.wait_for_event(DetectionStateChangeListenerThread.Event.FALLING_EDGE, timeout=5) < 0:
            log("the tone was not pause...")

            trial.invalidate(errormsg="GoogleMusic pause fail")
            trials.append(trial)
            device.shell(cmd)
            continue
        else:
            log("-> GoogleMusic pause function: pass")
            trial.put_extra(name="GoogleMusic pause", value="pass")

        pop = AudioFunction.get_pop()
        if pop:
            log("pop detect")
            trial.put_extra(name="playback start", value="pop")
            
        # resume
        log("-> GoogleMusic resume function:")
        vc, key = get_play_pause_id(device, serialno)
        if vc is None:
            log("can't find resume btn")
            trial.invalidate(errormsg="can't find resume btn")
            trials.append(trial)
            device.shell(cmd)
            continue

        pop = AudioFunction.get_pop()
        if pop:
            log("pop detect")
            trial.put_extra(name="playback start", value="pop")
            
        log("find the resume btn")
        control_Btn(vc, key)

        if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0:
            log("the tone was not resume...")

            trial.invalidate(errormsg="GoogleMusic resume fail")
            trials.append(trial)
            device.shell(cmd)
            continue
        else:
            log("-> GoogleMusic resume function: pass")
            trial.put_extra(name="GoogleMusic resume", value="pass")

        pop = AudioFunction.get_pop()
        if pop:
            log("pop detect")
            trial.put_extra(name="playback start", value="pop")
        
        time.sleep(1)
        
        # seek
        log("-> GoogleMusic seek function:")
        vc, key = get_progress_id(device, serialno)
        if vc is None:
            log("can't find seek btn")
            trial.invalidate(errormsg="can't find seek btn")
            trials.append(trial)
            device.shell(cmd)
            continue

        log("find the seek btn")
        control_Btn(vc, key)

        if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0:
            log("seek fail...")

            trial.invalidate(errormsg="GoogleMusic seek fail")
            trials.append(trial)
            device.shell(cmd)
            continue
        else:
            log("-> GoogleMusic seek function: pass")
            trial.put_extra(name="GoogleMusic seek", value="pass")

        pop = AudioFunction.get_pop()
        if pop:
            log("pop detect")
            trial.put_extra(name="playback start", value="pop")
        
        time.sleep(1)
        
        # next
        log("-> GoogleMusic next function:")
        vc, key = get_next_id(device, serialno)
        if vc is None:
            log("can't find next btn")
            trial.invalidate(errormsg="can't find next btn")
            trials.append(trial)
            device.shell(cmd)
            continue

        log("find the next btn")
        control_Btn(vc, key)

        if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0:
            log("next fail...")

            trial.invalidate(errormsg="GoogleMusic next fail")
            trials.append(trial)
            device.shell(cmd)
            continue
        else:
            log("-> GoogleMusic next function: pass")
            trial.put_extra(name="GoogleMusic next", value="pass")

        pop = AudioFunction.get_pop()
        if pop:
            log("pop detect")
            trial.put_extra(name="playback start", value="pop")
        
        time.sleep(1)
        
        # pause
        log("-> GoogleMusic pause function:")
        vc, key = get_play_pause_id(device, serialno)
        if vc is None:
            log("can't find pause btn")
            trial.invalidate(errormsg="can't find pause btn")
            trials.append(trial)
            device.shell(cmd)
            continue

        log("find the pause btn")
        control_Btn(vc, key)

        if th.wait_for_event(DetectionStateChangeListenerThread.Event.FALLING_EDGE, timeout=5) < 0:
            log("pause fail...")

            trial.invalidate(errormsg="GoogleMusic pause fail")
            trials.append(trial)
            device.shell(cmd)
            continue
        else:
            log("-> GoogleMusic pause function: pass")
            trial.put_extra(name="GoogleMusic pause", value="pass")    

        pop = AudioFunction.get_pop()
        if pop:
            log("pop detect")
            trial.put_extra(name="playback start", value="pop")
        
        time.sleep(1)
        
        device.shell(cmd)
        
    time.sleep(2)
    log("ToneDetector.stop_listen()")
    ToneDetector.stop_listen()
    
    device.shell(cmd)
    th.join()
    
    log("GoogleMusic playback--")
    return trials
Ejemplo n.º 9
0
def playback_format_task_run(device, num_iter=1):
    log("playback_format_task_run++")

    package = "com.htc.audiofunctionsdemo"
    activity = ".activities.MainActivity"
    component = package + "/" + activity     
    
    trials = []
    
    device.startActivity(component=component)
    
    th = DetectionStateChangeListenerThread()
    th.start()

    funcs = {
        "nonoffload": AATApp.playback_nonoffload
    }
    
    formats = {
        "1k_Stereo_48k_16bits_aac.aac": 1000,
        "1k_Stereo_48k_16bits_wav.wav": 1000,
        "1k_Stereo_96k_24bits_flac.flac": 1000
    }

    # force stop app string
    cmd = " ".join(["am", "force-stop", package])
    
    for i in range(num_iter):
        log("-------- playback_format_task #{} --------".format(i+1))
        for name, func in funcs.items():
            log("dev_playback_{}_start".format(name))
            
            for file, freq in formats.items():
                
                trial = Trial(taskname="playback_{}_{}".format(name, file))
                trial.put_extra(name="iter_id", value=i+1)
            
                log("playback_file_{}".format(file))
                
                log("ToneDetector.start_listen(target_freq={})".format(freq))
                ToneDetector.start_listen(target_freq=freq, cb=lambda event: th.tone_detected_event_cb(event))  
                
                time.sleep(1)
                th.reset()
                log("reset DetectionStateChangeListener")
                
                func(device, file)

                log("-> playback start function:")
                if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0:
                    log("the tone was not detected, abort the iteration this time...")
                    AATApp.playback_stop(device)
                    trial.invalidate(errormsg="start play fail")
                    trials.append(trial)
                    continue
                else:
                    log("-> playback start function: pass")
                    trial.put_extra(name="playback start", value="pass")
                
                pop = AudioFunction.get_pop()
                if pop:
                    log("pop detect")
                    trial.put_extra(name="playback start", value="pop")
                    
                time.sleep(0.5)

                log("-> playback pause function:")
                th.reset()
                
                AATApp.playback_pause_resume(device)
                #time.sleep(1)
                if th.wait_for_event(DetectionStateChangeListenerThread.Event.INACTIVE, timeout=5) < 0:
                    log("the tone was not detected, abort the iteration this time...")
                    AATApp.playback_stop(device)
                    trial.invalidate(errormsg="pause fail")
                    trials.append(trial)
                    continue
                else:
                    log("-> playback pause function: pass")
                    trial.put_extra(name="playback pause", value="pass")
                
                pop = AudioFunction.get_pop()
                if pop:
                    log("pop detect")
                    trial.put_extra(name="playback start", value="pop")
                    
                time.sleep(1)

                log("-> playback resume function:")
                th.reset()
                AATApp.playback_pause_resume(device)
                if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0:
                    log("the tone was not detected, abort the iteration this time...")
                    AATApp.playback_stop(device)
                    trial.invalidate(errormsg="resume fail")
                    trials.append(trial)
                    continue
                else:
                    log("-> playback resume: pass")
                    trial.put_extra(name="playback resume", value="pass")

                pop = AudioFunction.get_pop()
                if pop:
                    log("pop detect")
                    trial.put_extra(name="playback start", value="pop")
                    
                time.sleep(1)

                log("-> playback seek function:")
                th.reset()
                AATApp.playback_seek(device)
                if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0:
                    log("the tone was not detected, abort the iteration this time...")
                    AATApp.playback_stop(device)
                    trial.invalidate(errormsg="seek fail")
                    trials.append(trial)
                    continue
                else:
                    log("-> playback seek: pass")
                    trial.put_extra(name="playback seek", value="pass")
                
                pop = AudioFunction.get_pop()
                if pop:
                    log("pop detect")
                    trial.put_extra(name="playback start", value="pop")
                    
                time.sleep(2)

                log("-> playback forward function:")
                th.reset()
                AATApp.playback_forward(device)
                if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0:
                    log("the tone was not detected, abort the iteration this time...")
                    AATApp.playback_stop(device)
                    trial.invalidate(errormsg="forward fail")
                    trials.append(trial)
                    continue
                else:
                    log("-> playback forward function: pass")
                    trial.put_extra(name="playback forward", value="pass")
                
                pop = AudioFunction.get_pop()
                if pop:
                    log("pop detect")
                    trial.put_extra(name="playback start", value="pop")
                time.sleep(2)

                th.reset()
                AATApp.playback_stop(device)
                log("dev_playback_stop")

                elapsed = th.wait_for_event(DetectionStateChangeListenerThread.Event.INACTIVE, timeout=5)
                
                trial.put_extra(name="elapsed", value=elapsed)
                
                pop = AudioFunction.get_pop()
                if pop:
                    log("pop detect")
                    trial.put_extra(name="playback start", value="pop")
                    
                trials.append(trial)

    log("ToneDetector.stop_listen()")
    ToneDetector.stop_listen()
    th.join()
    device.shell(cmd)
    
    log("playback_task_run--")
    return trials
Ejemplo n.º 10
0
def record_task_run(device, serialno, num_iter=1):
    log("record_task_run++")

    package = "com.htc.audiofunctionsdemo"
    activity = ".activities.MainActivity"
    component = package + "/" + activity

    trials = []
    cmd = " ".join(["am", "force-stop", package])

    device.startActivity(component=component)
    time.sleep(1)

    log("dev_record_start")
    AATApp.record_start(device)
    time.sleep(2)

    th = DetectionStateChangeListenerThread()
    th.start()

    log("ToneDetector.start_listen(serialno={}, target_freq={})".format(
        serialno, OUT_FREQ))
    ToneDetector.start_listen(
        serialno=serialno,
        target_freq=OUT_FREQ,
        cb=lambda event: th.tone_detected_event_cb(event))
    log("AudioFunction.play_sound(out_freq={})".format(OUT_FREQ))
    AudioFunction.play_sound(out_freq=OUT_FREQ)

    time.sleep(3)
    for i in range(num_iter):
        log("-------- record_task #{} --------".format(i + 1))

        trial = Trial(taskname="record")
        trial.put_extra(name="iter_id", value=i + 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: tx no sound")
            trials.append(trial)
            continue
        else:
            log("-> record function: pass")
            trial.put_extra(name="record", value="pass")

    log("AudioFunction.stop_audio()")
    AudioFunction.stop_audio()

    log("dev_record_stop")
    AATApp.record_stop(device)
    time.sleep(5)
    log("ToneDetector.stop_listen()")
    ToneDetector.stop_listen()
    th.join()

    device.shell(cmd)
    log("record_task_run--")
    return trials
Ejemplo n.º 11
0
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