diff options
author | Paul Rohde <codelogic@google.com> | 2015-03-30 17:37:21 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-03-30 17:37:21 +0000 |
commit | 778a15a2bd60115c19d461e90523e8726ec62ea4 (patch) | |
tree | cf5d572a05ca89d4136703331468bb91ee59fcc4 /src | |
parent | f6f2863e4f906d8f9b3cfbc04292177a51fe0f55 (diff) | |
parent | 3bc38870104d065beb667f2c1274efea26fbc3af (diff) | |
download | android_packages_apps_Camera2-778a15a2bd60115c19d461e90523e8726ec62ea4.tar.gz android_packages_apps_Camera2-778a15a2bd60115c19d461e90523e8726ec62ea4.tar.bz2 android_packages_apps_Camera2-778a15a2bd60115c19d461e90523e8726ec62ea4.zip |
Merge "Detect jank in the preview by measuring sensor timestamps." into ub-camera-haleakala
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/camera/one/v2/ZslOneCameraFactory.java | 6 | ||||
-rw-r--r-- | src/com/android/camera/one/v2/errorhandling/FramerateJankDetector.java | 70 |
2 files changed, 76 insertions, 0 deletions
diff --git a/src/com/android/camera/one/v2/ZslOneCameraFactory.java b/src/com/android/camera/one/v2/ZslOneCameraFactory.java index 3f6257ef6..b45a5f2f7 100644 --- a/src/com/android/camera/one/v2/ZslOneCameraFactory.java +++ b/src/com/android/camera/one/v2/ZslOneCameraFactory.java @@ -51,6 +51,7 @@ import com.android.camera.one.v2.core.FrameServerFactory; import com.android.camera.one.v2.core.RequestTemplate; import com.android.camera.one.v2.core.ResponseListener; import com.android.camera.one.v2.core.ResponseListeners; +import com.android.camera.one.v2.errorhandling.FramerateJankDetector; import com.android.camera.one.v2.errorhandling.RepeatFailureHandlerComponent; import com.android.camera.one.v2.imagesaver.ImageSaver; import com.android.camera.one.v2.initialization.CameraStarter; @@ -230,6 +231,11 @@ public class ZslOneCameraFactory implements OneCameraFactory { rootBuilder.addResponseListener(failureDetector); } + if (ApiHelper.IS_NEXUS_6) { + rootBuilder.addResponseListener( + new FramerateJankDetector(Loggers.tagFactory())); + } + final Observable<Integer> availableImageCount = sharedImageReaderFactory .provideAvailableImageCount(); final Observable<Boolean> frameServerAvailability = frameServerComponent diff --git a/src/com/android/camera/one/v2/errorhandling/FramerateJankDetector.java b/src/com/android/camera/one/v2/errorhandling/FramerateJankDetector.java new file mode 100644 index 000000000..849a4e3e9 --- /dev/null +++ b/src/com/android/camera/one/v2/errorhandling/FramerateJankDetector.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.camera.one.v2.errorhandling; + +import android.annotation.TargetApi; +import android.hardware.camera2.CaptureResult; +import android.hardware.camera2.TotalCaptureResult; +import android.os.Build.VERSION_CODES; + +import com.android.camera.debug.Log.Tag; +import com.android.camera.debug.Logger; +import com.android.camera.one.v2.core.ResponseListener; + +import javax.annotation.ParametersAreNonnullByDefault; + +/** + * Detect jank in the preview by detecting large percentage increases in the time + * delta between the sensor timestamps retrieved from the camera. + */ +@ParametersAreNonnullByDefault +@TargetApi(VERSION_CODES.L) +public final class FramerateJankDetector extends ResponseListener { + private static final double PERCENT_CHANGE_LOG_THRESHOLD = 1.20; + + private final Logger mLog; + + private long mLastFrameTimestamp = -1; + private double mLastDeltaMillis = 0.0; + + /** + * @param logFactory Used for logging. + */ + public FramerateJankDetector(Logger.Factory logFactory) { + mLog = logFactory.create(new Tag("FrameJank")); + } + + @Override + public void onCompleted(TotalCaptureResult result) { + long timestamp = result.get(CaptureResult.SENSOR_TIMESTAMP); + if (mLastFrameTimestamp >= 0) { + double deltaMillis = (timestamp - mLastFrameTimestamp) / 1000000.0; + + if (mLastDeltaMillis > 0) { + double percentChange = (deltaMillis - mLastDeltaMillis) / mLastDeltaMillis; + if (percentChange >= PERCENT_CHANGE_LOG_THRESHOLD) { + mLog.v("JANK. Time between frames (" + deltaMillis + "ms) increased by " + + (percentChange * 100) + "% over the last frame delta (" + + mLastDeltaMillis + "ms)"); + } + } + mLastDeltaMillis = deltaMillis; + } + + mLastFrameTimestamp = timestamp; + } +} |