From e8df3093f53fa992f89e019b2fc87ff4fac0f335 Mon Sep 17 00:00:00 2001 From: Eino-Ville Talvala Date: Mon, 8 Sep 2014 14:30:50 -0700 Subject: Camera2: Add frameNumber to CaptureCallback#onCaptureStarted Otherwise, cannot reliably match up capture progressed and failure callbacks with the start callback. Bug: 17421092 Change-Id: I91d92be70a15536b215bac330370ce37e426ec26 --- api/current.txt | 2 +- .../android/hardware/camera2/CameraCaptureSession.java | 15 ++++++++++++++- .../hardware/camera2/dispatch/MethodNameInvoker.java | 8 +++++--- .../android/hardware/camera2/impl/CallbackProxies.java | 4 ++-- .../android/hardware/camera2/impl/CameraDeviceImpl.java | 8 +++++--- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/api/current.txt b/api/current.txt index 0eb67be1ff65..e9000a9ba572 100644 --- a/api/current.txt +++ b/api/current.txt @@ -12691,7 +12691,7 @@ package android.hardware.camera2 { method public void onCaptureProgressed(android.hardware.camera2.CameraCaptureSession, android.hardware.camera2.CaptureRequest, android.hardware.camera2.CaptureResult); method public void onCaptureSequenceAborted(android.hardware.camera2.CameraCaptureSession, int); method public void onCaptureSequenceCompleted(android.hardware.camera2.CameraCaptureSession, int, long); - method public void onCaptureStarted(android.hardware.camera2.CameraCaptureSession, android.hardware.camera2.CaptureRequest, long); + method public void onCaptureStarted(android.hardware.camera2.CameraCaptureSession, android.hardware.camera2.CaptureRequest, long, long); } public static abstract class CameraCaptureSession.StateCallback { diff --git a/core/java/android/hardware/camera2/CameraCaptureSession.java b/core/java/android/hardware/camera2/CameraCaptureSession.java index 29e42ea246b1..ce830288eed2 100644 --- a/core/java/android/hardware/camera2/CameraCaptureSession.java +++ b/core/java/android/hardware/camera2/CameraCaptureSession.java @@ -483,7 +483,9 @@ public abstract class CameraCaptureSession implements AutoCloseable { * and in the buffers sent to each output Surface. These buffer * timestamps are accessible through, for example, * {@link android.media.Image#getTimestamp() Image.getTimestamp()} or - * {@link android.graphics.SurfaceTexture#getTimestamp()}.

+ * {@link android.graphics.SurfaceTexture#getTimestamp()}. + * The frame number included is equal to the frame number that will be included in + * {@link CaptureResult#getFrameNumber}.

* *

For the simplest way to play a shutter sound camera shutter or a * video recording start/stop sound, see the @@ -494,9 +496,20 @@ public abstract class CameraCaptureSession implements AutoCloseable { * @param session the session returned by {@link CameraDevice#createCaptureSession} * @param request the request for the capture that just begun * @param timestamp the timestamp at start of capture, in nanoseconds. + * @param frameNumber the frame number for this capture * * @see android.media.MediaActionSound */ + public void onCaptureStarted(CameraCaptureSession session, + CaptureRequest request, long timestamp, long frameNumber) { + // Temporary trampoline for API change transition + onCaptureStarted(session, request, timestamp); + } + + /** + * Temporary for API change transition + * @hide + */ public void onCaptureStarted(CameraCaptureSession session, CaptureRequest request, long timestamp) { // default empty implementation diff --git a/core/java/android/hardware/camera2/dispatch/MethodNameInvoker.java b/core/java/android/hardware/camera2/dispatch/MethodNameInvoker.java index 02c3d87acf2e..c66a3a40718f 100644 --- a/core/java/android/hardware/camera2/dispatch/MethodNameInvoker.java +++ b/core/java/android/hardware/camera2/dispatch/MethodNameInvoker.java @@ -48,7 +48,8 @@ public class MethodNameInvoker { /** * Invoke a method by its name. * - *

If more than one method exists in {@code targetClass}, the first method will be used.

+ *

If more than one method exists in {@code targetClass}, the first method with the right + * number of arguments will be used, and later calls will all use that method.

* * @param methodName * The name of the method, which will be matched 1:1 to the destination method @@ -68,8 +69,9 @@ public class MethodNameInvoker { Method targetMethod = mMethods.get(methodName); if (targetMethod == null) { for (Method method : mTargetClass.getMethods()) { - // TODO future: match by # of params and types of params if possible - if (method.getName().equals(methodName)) { + // TODO future: match types of params if possible + if (method.getName().equals(methodName) && + (params.length == method.getParameterTypes().length) ) { targetMethod = method; mMethods.put(methodName, targetMethod); break; diff --git a/core/java/android/hardware/camera2/impl/CallbackProxies.java b/core/java/android/hardware/camera2/impl/CallbackProxies.java index e5ddb7a1a607..f0217acc0116 100644 --- a/core/java/android/hardware/camera2/impl/CallbackProxies.java +++ b/core/java/android/hardware/camera2/impl/CallbackProxies.java @@ -98,8 +98,8 @@ public class CallbackProxies { @Override public void onCaptureStarted(CameraDevice camera, - CaptureRequest request, long timestamp) { - mProxy.invoke("onCaptureStarted", camera, request, timestamp); + CaptureRequest request, long timestamp, long frameNumber) { + mProxy.invoke("onCaptureStarted", camera, request, timestamp, frameNumber); } @Override diff --git a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java index d454092a8633..f011d60c0cb0 100644 --- a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java +++ b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java @@ -803,7 +803,7 @@ public class CameraDeviceImpl extends CameraDevice { * @see android.media.MediaActionSound */ public void onCaptureStarted(CameraDevice camera, - CaptureRequest request, long timestamp) { + CaptureRequest request, long timestamp, long frameNumber) { // default empty implementation } @@ -1237,8 +1237,10 @@ public class CameraDeviceImpl extends CameraDevice { @Override public void onCaptureStarted(final CaptureResultExtras resultExtras, final long timestamp) { int requestId = resultExtras.getRequestId(); + final long frameNumber = resultExtras.getFrameNumber(); + if (DEBUG) { - Log.d(TAG, "Capture started for id " + requestId); + Log.d(TAG, "Capture started for id " + requestId + " frame number " + frameNumber); } final CaptureCallbackHolder holder; @@ -1263,7 +1265,7 @@ public class CameraDeviceImpl extends CameraDevice { holder.getCallback().onCaptureStarted( CameraDeviceImpl.this, holder.getRequest(resultExtras.getSubsequenceId()), - timestamp); + timestamp, frameNumber); } } }); -- cgit v1.2.3-59-g8ed1b