Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6e9c5cc6 authored by Igor Murashkin's avatar Igor Murashkin Committed by Android (Google) Code Review
Browse files

Merge "camera2: Change CaptureListener callbacks to include the session (api)" into lmp-preview-dev

parents cbc9a679 21547d66
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -12097,12 +12097,12 @@ package android.hardware.camera2 {
  public static abstract class CameraCaptureSession.CaptureListener {
    ctor public CameraCaptureSession.CaptureListener();
    method public void onCaptureCompleted(android.hardware.camera2.CameraDevice, android.hardware.camera2.CaptureRequest, android.hardware.camera2.TotalCaptureResult);
    method public void onCaptureFailed(android.hardware.camera2.CameraDevice, android.hardware.camera2.CaptureRequest, android.hardware.camera2.CaptureFailure);
    method public void onCaptureProgressed(android.hardware.camera2.CameraDevice, android.hardware.camera2.CaptureRequest, android.hardware.camera2.CaptureResult);
    method public void onCaptureSequenceAborted(android.hardware.camera2.CameraDevice, int);
    method public void onCaptureSequenceCompleted(android.hardware.camera2.CameraDevice, int, long);
    method public void onCaptureStarted(android.hardware.camera2.CameraDevice, android.hardware.camera2.CaptureRequest, long);
    method public void onCaptureCompleted(android.hardware.camera2.CameraCaptureSession, android.hardware.camera2.CaptureRequest, android.hardware.camera2.TotalCaptureResult);
    method public void onCaptureFailed(android.hardware.camera2.CameraCaptureSession, android.hardware.camera2.CaptureRequest, android.hardware.camera2.CaptureFailure);
    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);
  }
  public static abstract class CameraCaptureSession.StateListener {
@@ -12189,7 +12189,7 @@ package android.hardware.camera2 {
    method public final int hashCode();
  }
  public abstract interface CameraDevice implements java.lang.AutoCloseable {
  public abstract class CameraDevice implements java.lang.AutoCloseable {
    method public abstract deprecated int capture(android.hardware.camera2.CaptureRequest, android.hardware.camera2.CameraDevice.CaptureListener, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
    method public abstract deprecated int captureBurst(java.util.List<android.hardware.camera2.CaptureRequest>, android.hardware.camera2.CameraDevice.CaptureListener, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
    method public abstract void close();
+26 −17
Original line number Diff line number Diff line
@@ -370,6 +370,7 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         * <p>If the camera device configuration fails, then {@link #onConfigureFailed} will
         * be invoked instead of this callback.</p>
         *
         * @param session the session returned by {@link CameraDevice#createCaptureSession}
         */
        public abstract void onConfigured(CameraCaptureSession session);

@@ -383,6 +384,8 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         * callback is invoked will throw an IllegalStateException. Any capture requests submitted
         * to the session prior to this callback will be discarded and will not produce any
         * callbacks on their listeners.</p>
         *
         * @param session the session returned by {@link CameraDevice#createCaptureSession}
         */
        public abstract void onConfigureFailed(CameraCaptureSession session);

@@ -396,6 +399,8 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         * <p>Otherwise, this callback will be invoked any time the session finishes processing
         * all of its active capture requests, and no repeating request or burst is set up.</p>
         *
         * @param session the session returned by {@link CameraDevice#createCaptureSession}
         *
         */
        public void onReady(CameraCaptureSession session) {
            // default empty implementation
@@ -410,6 +415,8 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         *
         * <p>If the session runs out of capture requests to process and calls {@link #onReady},
         * then this callback will be invoked again once new requests are submitted for capture.</p>
         *
         * @param session the session returned by {@link CameraDevice#createCaptureSession}
         */
        public void onActive(CameraCaptureSession session) {
            // default empty implementation
@@ -426,6 +433,8 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         * any repeating requests or bursts are stopped (as if {@link #stopRepeating()} was called).
         * However, any in-progress capture requests submitted to the session will be completed
         * as normal.</p>
         *
         * @param session the session returned by {@link CameraDevice#createCaptureSession}
         */
        public void onClosed(CameraCaptureSession session) {
            // default empty implementation
@@ -478,13 +487,13 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         *
         * <p>The default implementation of this method does nothing.</p>
         *
         * @param camera the CameraDevice sending the callback
         * @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.
         *
         * @see android.media.MediaActionSound
         */
        public void onCaptureStarted(CameraDevice camera,
        public void onCaptureStarted(CameraCaptureSession session,
                CaptureRequest request, long timestamp) {
            // default empty implementation
        }
@@ -502,7 +511,7 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         *
         * <p>The default implementation of this method does nothing.</p>
         *
         * @param camera The CameraDevice sending the callback.
         * @param session the session returned by {@link CameraDevice#createCaptureSession}
         * @param request The request that was given to the CameraDevice
         * @param result The partial output metadata from the capture, which
         * includes a subset of the CaptureResult fields.
@@ -514,7 +523,7 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         *
         * @hide
         */
        public void onCapturePartial(CameraDevice camera,
        public void onCapturePartial(CameraCaptureSession session,
                CaptureRequest request, CaptureResult result) {
            // default empty implementation
        }
@@ -545,7 +554,7 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         *
         * <p>The default implementation of this method does nothing.</p>
         *
         * @param camera The CameraDevice sending the callback.
         * @param session the session returned by {@link CameraDevice#createCaptureSession}
         * @param request The request that was given to the CameraDevice
         * @param partialResult The partial output metadata from the capture, which
         * includes a subset of the {@link TotalCaptureResult} fields.
@@ -555,7 +564,7 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         * @see #setRepeatingRequest
         * @see #setRepeatingBurst
         */
        public void onCaptureProgressed(CameraDevice camera,
        public void onCaptureProgressed(CameraCaptureSession session,
                CaptureRequest request, CaptureResult partialResult) {
            // default empty implementation
        }
@@ -573,7 +582,7 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         *
         * <p>The default implementation of this method does nothing.</p>
         *
         * @param camera The CameraDevice sending the callback.
         * @param session the session returned by {@link CameraDevice#createCaptureSession}
         * @param request The request that was given to the CameraDevice
         * @param result The total output metadata from the capture, including the
         * final capture parameters and the state of the camera system during
@@ -584,7 +593,7 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         * @see #setRepeatingRequest
         * @see #setRepeatingBurst
         */
        public void onCaptureCompleted(CameraDevice camera,
        public void onCaptureCompleted(CameraCaptureSession session,
                CaptureRequest request, TotalCaptureResult result) {
            // default empty implementation
        }
@@ -600,8 +609,8 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         *
         * <p>The default implementation of this method does nothing.</p>
         *
         * @param camera
         *            The CameraDevice sending the callback.
         * @param session
         *            The session returned by {@link CameraDevice#createCaptureSession}
         * @param request
         *            The request that was given to the CameraDevice
         * @param failure
@@ -613,7 +622,7 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         * @see #setRepeatingRequest
         * @see #setRepeatingBurst
         */
        public void onCaptureFailed(CameraDevice camera,
        public void onCaptureFailed(CameraCaptureSession session,
                CaptureRequest request, CaptureFailure failure) {
            // default empty implementation
        }
@@ -629,8 +638,8 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         *
         * <p>The default implementation does nothing.</p>
         *
         * @param camera
         *            The CameraDevice sending the callback.
         * @param session
         *            The session returned by {@link CameraDevice#createCaptureSession}
         * @param sequenceId
         *            A sequence ID returned by the {@link #capture} family of functions.
         * @param frameNumber
@@ -643,7 +652,7 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         * @see CaptureFailure#getSequenceId()
         * @see #onCaptureSequenceAborted
         */
        public void onCaptureSequenceCompleted(CameraDevice camera,
        public void onCaptureSequenceCompleted(CameraCaptureSession session,
                int sequenceId, long frameNumber) {
            // default empty implementation
        }
@@ -661,8 +670,8 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         *
         * <p>The default implementation does nothing.</p>
         *
         * @param camera
         *            The CameraDevice sending the callback.
         * @param session
         *            The session returned by {@link CameraDevice#createCaptureSession}
         * @param sequenceId
         *            A sequence ID returned by the {@link #capture} family of functions.
         *
@@ -672,7 +681,7 @@ public abstract class CameraCaptureSession implements AutoCloseable {
         * @see CaptureFailure#getSequenceId()
         * @see #onCaptureSequenceCompleted
         */
        public void onCaptureSequenceAborted(CameraDevice camera,
        public void onCaptureSequenceAborted(CameraCaptureSession session,
                int sequenceId) {
            // default empty implementation
        }
+19 −13
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ import android.view.Surface;
import java.util.List;

/**
 * <p>The CameraDevice class is an interface to a single camera connected to an
 * <p>The CameraDevice class is a representation of a single camera connected to an
 * Android device, allowing for fine-grain control of image capture and
 * post-processing at high frame rates.</p>
 *
@@ -46,7 +46,7 @@ import java.util.List;
 * @see CameraManager#openCamera
 * @see android.Manifest.permission#CAMERA
 */
public interface CameraDevice extends AutoCloseable {
public abstract class CameraDevice implements AutoCloseable {

    /**
     * Create a request suitable for a camera preview window. Specifically, this
@@ -127,7 +127,7 @@ public interface CameraDevice extends AutoCloseable {
     * @see CameraManager#getCameraCharacteristics
     * @see CameraManager#getCameraIdList
     */
    public String getId();
    public abstract String getId();

    /**
     * <p>Set up a new output set of Surfaces for the camera device.</p>
@@ -245,7 +245,7 @@ public interface CameraDevice extends AutoCloseable {
     * @deprecated Use {@link #createCaptureSession} instead
     */
    @Deprecated
    public void configureOutputs(List<Surface> outputs) throws CameraAccessException;
    public abstract void configureOutputs(List<Surface> outputs) throws CameraAccessException;

    /**
     * <p>Create a new camera capture session by providing the target output set of Surfaces to the
@@ -358,7 +358,7 @@ public interface CameraDevice extends AutoCloseable {
     * @see StreamConfigurationMap#getOutputSizes(int)
     * @see StreamConfigurationMap#getOutputSizes(Class)
     */
    public void createCaptureSession(List<Surface> outputs,
    public abstract void createCaptureSession(List<Surface> outputs,
            CameraCaptureSession.StateListener listener, Handler handler)
            throws CameraAccessException;

@@ -387,7 +387,7 @@ public interface CameraDevice extends AutoCloseable {
     * @see #TEMPLATE_VIDEO_SNAPSHOT
     * @see #TEMPLATE_MANUAL
     */
    public CaptureRequest.Builder createCaptureRequest(int templateType)
    public abstract CaptureRequest.Builder createCaptureRequest(int templateType)
            throws CameraAccessException;

    /**
@@ -434,7 +434,7 @@ public interface CameraDevice extends AutoCloseable {
     * @deprecated Use {@link CameraCaptureSession} instead
     */
    @Deprecated
    public int capture(CaptureRequest request, CaptureListener listener, Handler handler)
    public abstract int capture(CaptureRequest request, CaptureListener listener, Handler handler)
            throws CameraAccessException;

    /**
@@ -481,7 +481,7 @@ public interface CameraDevice extends AutoCloseable {
     * @deprecated Use {@link CameraCaptureSession} instead
     */
    @Deprecated
    public int captureBurst(List<CaptureRequest> requests, CaptureListener listener,
    public abstract int captureBurst(List<CaptureRequest> requests, CaptureListener listener,
            Handler handler) throws CameraAccessException;

    /**
@@ -541,7 +541,7 @@ public interface CameraDevice extends AutoCloseable {
     * @deprecated Use {@link CameraCaptureSession} instead
     */
    @Deprecated
    public int setRepeatingRequest(CaptureRequest request, CaptureListener listener,
    public abstract int setRepeatingRequest(CaptureRequest request, CaptureListener listener,
            Handler handler) throws CameraAccessException;

    /**
@@ -602,7 +602,7 @@ public interface CameraDevice extends AutoCloseable {
     * @deprecated Use {@link CameraCaptureSession} instead
     */
    @Deprecated
    public int setRepeatingBurst(List<CaptureRequest> requests, CaptureListener listener,
    public abstract int setRepeatingBurst(List<CaptureRequest> requests, CaptureListener listener,
            Handler handler) throws CameraAccessException;

    /**
@@ -628,7 +628,7 @@ public interface CameraDevice extends AutoCloseable {
     * @deprecated Use {@link CameraCaptureSession} instead
     */
    @Deprecated
    public void stopRepeating() throws CameraAccessException;
    public abstract void stopRepeating() throws CameraAccessException;

    /**
     * Flush all captures currently pending and in-progress as fast as
@@ -666,7 +666,7 @@ public interface CameraDevice extends AutoCloseable {
     * @deprecated Use {@link CameraCaptureSession} instead
     */
    @Deprecated
    public void flush() throws CameraAccessException;
    public abstract void flush() throws CameraAccessException;

    /**
     * Close the connection to this camera device as quickly as possible.
@@ -684,7 +684,7 @@ public interface CameraDevice extends AutoCloseable {
     *
     */
    @Override
    public void close();
    public abstract void close();

    /**
     * <p>A listener for tracking the progress of a {@link CaptureRequest}
@@ -1230,4 +1230,10 @@ public interface CameraDevice extends AutoCloseable {
         */
        public abstract void onError(CameraDevice camera, int error); // Must implement
    }

    /**
     * To be inherited by android.hardware.camera2.* code only.
     * @hide
     */
    public CameraDevice() {}
}
+2 −2
Original line number Diff line number Diff line
@@ -228,8 +228,8 @@ public final class CameraManager {

                ICameraDeviceUser cameraUser;

                android.hardware.camera2.impl.CameraDevice deviceImpl =
                        new android.hardware.camera2.impl.CameraDevice(
                android.hardware.camera2.impl.CameraDeviceImpl deviceImpl =
                        new android.hardware.camera2.impl.CameraDeviceImpl(
                                cameraId,
                                listener,
                                handler,
+85 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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 android.hardware.camera2.dispatch;

import java.lang.reflect.Method;

import static com.android.internal.util.Preconditions.*;

/**
 * A dispatcher that replaces one argument with another; replaces any argument at an index
 * with another argument.
 *
 * <p>For example, we can override an {@code void onSomething(int x)} calls to have {@code x} always
 * equal to 1. Or, if using this with a duck typing dispatcher, we could even overwrite {@code x} to
 * be something
 * that's not an {@code int}.</p>
 *
 * @param <T>
 *          source dispatch type, whose methods with {@link #dispatch} will be called
 * @param <TArg>
 *          argument replacement type, args in {@link #dispatch} matching {@code argumentIndex}
 *          will be overriden to objects of this type
 */
public class ArgumentReplacingDispatcher<T, TArg> implements Dispatchable<T> {

    private final Dispatchable<T> mTarget;
    private final int mArgumentIndex;
    private final TArg mReplaceWith;

    /**
     * Create a new argument replacing dispatcher; dispatches are forwarded to {@code target}
     * after the argument is replaced.
     *
     * <p>For example, if a method {@code onAction(T1 a, Integer b, T2 c)} is invoked, and we wanted
     * to replace all occurrences of {@code b} with {@code 0xDEADBEEF}, we would set
     * {@code argumentIndex = 1} and {@code replaceWith = 0xDEADBEEF}.</p>
     *
     * <p>If a method dispatched has less arguments than {@code argumentIndex}, it is
     * passed through with the arguments unchanged.</p>
     *
     * @param target destination dispatch type, methods will be redirected to this dispatcher
     * @param argumentIndex the numeric index of the argument {@code >= 0}
     * @param replaceWith arguments matching {@code argumentIndex} will be replaced with this object
     */
    public ArgumentReplacingDispatcher(Dispatchable<T> target, int argumentIndex,
            TArg replaceWith) {
        mTarget = checkNotNull(target, "target must not be null");
        mArgumentIndex = checkArgumentNonnegative(argumentIndex,
                "argumentIndex must not be negative");
        mReplaceWith = checkNotNull(replaceWith, "replaceWith must not be null");
    }

    @Override
    public Object dispatch(Method method, Object[] args) throws Throwable {

        if (args.length > mArgumentIndex) {
            args = arrayCopy(args); // don't change in-place since it can affect upstream dispatches
            args[mArgumentIndex] = mReplaceWith;
        }

        return mTarget.dispatch(method, args);
    }

    private static Object[] arrayCopy(Object[] array) {
        int length = array.length;
        Object[] newArray = new Object[length];
        for (int i = 0; i < length; ++i) {
            newArray[i] = array[i];
        }
        return newArray;
    }
}
Loading