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
示例#2
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