简体   繁体   中英

setTorchMode is very slow, how can I speed up the call?

I need to flash the camera flashlight at specific times, ideally at a precision of about 2ms every 0.5sec. With audio I've managed that well but the call to setTorchMode seems to be taking nearly 1/2s. I've tried to put the call in a Runnable but that (as expected) creates a backlog. Here are my timing measurements:

  public void doFlash() {
        if (cameraManager == null) return;
        try {
            Log.d(TAG,"1="+System.nanoTime()/1000000);
            cameraManager.setTorchMode(cameraId, true);
            Log.d(TAG,"2="+System.nanoTime()/1000000);
            yield();
            Log.d(TAG,"3="+System.nanoTime()/1000000);
            cameraManager.setTorchMode(cameraId, false);
            Log.d(TAG,"4="+System.nanoTime()/1000000);
            Log.d(TAG,"-------------");
        } catch (Exception e) {
            Log.d(TAG, "Could not switch on flash");
        }
    }
}

02-02 23:06:57.950 17528-17792/tech.glasgowneuro.attyseeg D/EPFragment: 1=1662873286 02-02 23:06:58.668 17528-17792/tech.glasgowneuro.attyseeg D/EPFragment: 2=1662874004 02-02 23:06:58.668 17528-17792/tech.glasgowneuro.attyseeg D/EPFragment: 3=1662874004 02-02 23:06:59.149 17528-17792/tech.glasgowneuro.attyseeg D/EPFragment: 4=1662874484 02-02 23:06:59.149 17528-17792/tech.glasgowneuro.attyseeg D/EPFragment: ------------- 02-02 23:06:59.149 17528-17792/tech.glasgowneuro.attyseeg D/EPFragment: 1=1662874484 02-02 23:06:59.649 17528-17792/tech.glasgowneuro.attyseeg D/EPFragment: 2=1662874985 02-02 23:06:59.649 17528-17792/tech.glasgowneuro.attyseeg D/EPFragment: 3=1662874985 02-02 23:07:00.074 17528-17792/tech.glasgowneuro.attyseeg D/EPFragment: 4=1662875409

I'm puzzled why this function takes so long? Are there other calls which are faster or how can this be done within 2ms or less?

I second that - it takes between 1/3 and 1 seconds (Samsung Galaxy S7). In contrast to the old "Camera" this is unusable if you want to blink...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM