diff options
author | Ricardo Cerqueira <cyanogenmod@cerqueira.org> | 2013-12-06 02:16:40 +0000 |
---|---|---|
committer | Ricardo Cerqueira <cyanogenmod@cerqueira.org> | 2013-12-06 02:16:40 +0000 |
commit | aecf604ef14f07e078c309b015c2333e22640789 (patch) | |
tree | 3015ce491d513fb452665aa7f093138599800a20 /camera2/public/src/com/android/ex/camera2 | |
parent | 0ab100671fdff8675ea1f74f15627f09c7f7506f (diff) | |
parent | 3e8176df16950c067bcb1b37e62b2fc07d74065a (diff) | |
download | android_frameworks_ex-aecf604ef14f07e078c309b015c2333e22640789.tar.gz android_frameworks_ex-aecf604ef14f07e078c309b015c2333e22640789.tar.bz2 android_frameworks_ex-aecf604ef14f07e078c309b015c2333e22640789.zip |
Merge tag 'android-4.4.1_r1' into HEADcm-11.0-XNPH25R-bacon-d22b777afacm-11.0-XNPH22R-bacon-03d77315ea
Android 4.4.1 Release 1
Diffstat (limited to 'camera2/public/src/com/android/ex/camera2')
-rw-r--r-- | camera2/public/src/com/android/ex/camera2/pos/AutoFocusStateMachine.java | 76 | ||||
-rw-r--r-- | camera2/public/src/com/android/ex/camera2/utils/SysTrace.java | 121 |
2 files changed, 197 insertions, 0 deletions
diff --git a/camera2/public/src/com/android/ex/camera2/pos/AutoFocusStateMachine.java b/camera2/public/src/com/android/ex/camera2/pos/AutoFocusStateMachine.java index 5b11c2b..500fb12 100644 --- a/camera2/public/src/com/android/ex/camera2/pos/AutoFocusStateMachine.java +++ b/camera2/public/src/com/android/ex/camera2/pos/AutoFocusStateMachine.java @@ -21,6 +21,8 @@ import android.hardware.camera2.CaptureRequest; import android.hardware.camera2.CaptureResult; import android.util.Log; +import com.android.ex.camera2.utils.SysTrace; + /** * Manage the auto focus state machine for CameraDevice. * @@ -29,6 +31,10 @@ import android.util.Log; */ public class AutoFocusStateMachine { + /** + * Observe state AF state transitions triggered by + * {@link AutoFocusStateMachine#onCaptureCompleted onCaptureCompleted}. + */ public interface AutoFocusStateListener { /** * The camera is currently focused (either active or passive). @@ -72,6 +78,10 @@ public class AutoFocusStateMachine { private int mCurrentAfMode = AF_UNINITIALIZED; private int mCurrentAfTrigger = AF_UNINITIALIZED; + private int mCurrentAfCookie = AF_UNINITIALIZED; + private String mCurrentAfTrace = ""; + private int mLastAfCookie = 0; + public AutoFocusStateMachine(AutoFocusStateListener listener) { if (listener == null) { throw new IllegalArgumentException("listener should not be null"); @@ -146,9 +156,11 @@ public class AutoFocusStateMachine { switch (afState) { case CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED: mListener.onAutoFocusSuccess(result, /*locked*/true); + endTraceAsync(); break; case CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED: mListener.onAutoFocusFail(result, /*locked*/true); + endTraceAsync(); break; case CaptureResult.CONTROL_AF_STATE_PASSIVE_FOCUSED: mListener.onAutoFocusSuccess(result, /*locked*/false); @@ -169,6 +181,22 @@ public class AutoFocusStateMachine { } /** + * Reset the current AF state. + * + * <p> + * When dropping capture results (by not invoking {@link #onCaptureCompleted} when a new + * {@link CaptureResult} is available), call this function to reset the state. Otherwise + * the next time a new state is observed this class may incorrectly consider it as the same + * state as before, and not issue any callbacks by {@link AutoFocusStateListener}. + * </p> + */ + public synchronized void resetState() { + if (VERBOSE_LOGGING) Log.v(TAG, "resetState - last state was " + mLastAfState); + + mLastAfState = AF_UNINITIALIZED; + } + + /** * Lock the lens from moving. Typically used before taking a picture. * * <p>After calling this function, submit the new requestBuilder as a separate capture. @@ -195,6 +223,8 @@ public class AutoFocusStateMachine { throw new IllegalStateException("AF mode was not enabled"); } + beginTraceAsync("AFSM_lockAutoFocus"); + mCurrentAfTrigger = CaptureRequest.CONTROL_AF_TRIGGER_START; repeatingBuilder.set(CaptureRequest.CONTROL_AF_MODE, mCurrentAfMode); @@ -275,6 +305,8 @@ public class AutoFocusStateMachine { CaptureRequest.Builder requestBuilder) { if (VERBOSE_LOGGING) Log.v(TAG, "setActiveAutoFocus"); + beginTraceAsync("AFSM_setActiveAutoFocus"); + mCurrentAfMode = CaptureRequest.CONTROL_AF_MODE_AUTO; repeatingBuilder.set(CaptureRequest.CONTROL_AF_MODE, mCurrentAfMode); @@ -311,4 +343,48 @@ public class AutoFocusStateMachine { repeatingBuilder.set(CaptureRequest.CONTROL_AF_MODE, mCurrentAfMode); } + + private synchronized void beginTraceAsync(String sectionName) { + if (mCurrentAfCookie != AF_UNINITIALIZED) { + // Terminate any currently active async sections before beginning another section + SysTrace.endSectionAsync(mCurrentAfTrace, mCurrentAfCookie); + } + + mLastAfCookie++; + mCurrentAfCookie = mLastAfCookie; + mCurrentAfTrace = sectionName; + + SysTrace.beginSectionAsync(sectionName, mCurrentAfCookie); + } + + private synchronized void endTraceAsync() { + if (mCurrentAfCookie == AF_UNINITIALIZED) { + Log.w(TAG, "endTraceAsync - no current trace active"); + return; + } + + SysTrace.endSectionAsync(mCurrentAfTrace, mCurrentAfCookie); + mCurrentAfCookie = AF_UNINITIALIZED; + } + + /** + * Update the repeating request with current focus mode. + * + * <p>This is typically used when a new repeating request is created to update preview with + * new metadata (i.e. crop region). The current auto focus mode needs to be carried over for + * correct auto focus behavior.<p> + * + * @param repeatingBuilder Builder for a repeating request. + */ + public synchronized void updateCaptureRequest(CaptureRequest.Builder repeatingBuilder) { + if (repeatingBuilder == null) { + throw new IllegalArgumentException("repeatingBuilder shouldn't be null"); + } + + if (mCurrentAfMode == AF_UNINITIALIZED) { + throw new IllegalStateException("AF mode was not enabled"); + } + + repeatingBuilder.set(CaptureRequest.CONTROL_AF_MODE, mCurrentAfMode); + } } diff --git a/camera2/public/src/com/android/ex/camera2/utils/SysTrace.java b/camera2/public/src/com/android/ex/camera2/utils/SysTrace.java new file mode 100644 index 0000000..fd92216 --- /dev/null +++ b/camera2/public/src/com/android/ex/camera2/utils/SysTrace.java @@ -0,0 +1,121 @@ +/* + * Copyright 2013 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.ex.camera2.utils; + +import android.util.Log; + +/** + * Writes trace events to the system trace buffer. These trace events can be + * collected and visualized using the Systrace tool. + * + * <p> + * This tracing mechanism is independent of the method tracing mechanism + * offered by {@link Debug#startMethodTracing}. In particular, it enables + * tracing of events that occur across multiple processes. + * </p> + * + * <p> + * All traces are written using the <pre>APP</pre> tag. + * </p> + */ +public final class SysTrace { + + private static final String TAG = "SysTrace"; + private static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE); + + private static int sNestingLevel = 0; + + /** + * Writes trace message to indicate the value of a given counter. + * + * @param counterName The counter name to appear in the trace. + * @param counterValue The counter value. + * + */ + public static void traceCounter(String counterName, int counterValue) { + if (VERBOSE) { + Log.v(TAG, "traceCounter " + counterName + " " + counterValue); + } + } + + /** + * Writes a trace message to indicate that a given section of code has begun. This call must + * be followed by a corresponding call to {@link #endSection()} on the same thread. + * + * <p class="note"> At this time the vertical bar character '|', newline character '\n', and + * null character '\0' are used internally by the tracing mechanism. If sectionName contains + * these characters they will be replaced with a space character in the trace. + * + * @param sectionName The name of the code section to appear in the trace. This may be at + * most 127 Unicode code units long. + */ + public static void beginSection(String sectionName) { + if (VERBOSE) { + Log.v(TAG, String.format("beginSection[%d] %s", sNestingLevel, sectionName)); + sNestingLevel++; + } + } + + /** + * Writes a trace message to indicate that a given section of code has + * ended. + * <p> + * This call must be preceded by a corresponding call to + * {@link #beginSection(String)}. Calling this method will mark the end of + * the most recently begun section of code, so care must be taken to ensure + * that beginSection / endSection pairs are properly nested and called from + * the same thread. + * </p> + */ + public static void endSection() { + if (VERBOSE) { + sNestingLevel--; + Log.v(TAG, String.format("endSection[%d]", sNestingLevel)); + } + } + + /** + * Writes a trace message to indicate that a given section of code has + * begun. + * + * <p>Must be followed by a call to {@link #endSectionAsync} using the same + * tag. Unlike {@link #beginSection} and {@link #endSection}, + * asynchronous events do not need to be nested. The name and cookie used to + * begin an event must be used to end it.</p> + * + * @param methodName The method name to appear in the trace. + * @param cookie Unique identifier for distinguishing simultaneous events + */ + public static void beginSectionAsync(String methodName, int cookie) { + if (VERBOSE) { + Log.v(TAG, "beginSectionAsync " + methodName + " " + cookie); + } + } + + /** + * Writes a trace message to indicate that the current method has ended. + * Must be called exactly once for each call to {@link #beginSectionAsync} + * using the same tag, name and cookie. + * + * @param methodName The method name to appear in the trace. + * @param cookie Unique identifier for distinguishing simultaneous events + */ + public static void endSectionAsync(String methodName, int cookie) { + if (VERBOSE) { + Log.v(TAG, "endSectionAsync " + methodName + " " + cookie); + } + } +} |