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

Commit 0324a950 authored by Eino-Ville Talvala's avatar Eino-Ville Talvala Committed by Android Git Automerger
Browse files

am 7e01420b: Merge "Camera2: New capture session interface" into lmp-preview-dev

* commit '7e01420b8e532694369fc885f83838fc527708dd':
  Camera2: New capture session interface
parents c877f6ab 88aca033
Loading
Loading
Loading
Loading
+42 −12
Original line number Diff line number Diff line
@@ -12188,6 +12188,35 @@ package android.hardware.camera2 {
    field public static final int CAMERA_ERROR = 3; // 0x3
  }
  public abstract class CameraCaptureSession implements java.lang.AutoCloseable {
    ctor public CameraCaptureSession();
    method public abstract void abortCaptures() throws android.hardware.camera2.CameraAccessException;
    method public abstract int capture(android.hardware.camera2.CaptureRequest, android.hardware.camera2.CameraCaptureSession.CaptureListener, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
    method public abstract int captureBurst(java.util.List<android.hardware.camera2.CaptureRequest>, android.hardware.camera2.CameraCaptureSession.CaptureListener, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
    method public abstract void close();
    method public abstract android.hardware.camera2.CameraDevice getDevice();
    method public abstract int setRepeatingBurst(java.util.List<android.hardware.camera2.CaptureRequest>, android.hardware.camera2.CameraCaptureSession.CaptureListener, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
    method public abstract int setRepeatingRequest(android.hardware.camera2.CaptureRequest, android.hardware.camera2.CameraCaptureSession.CaptureListener, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
    method public abstract void stopRepeating() throws android.hardware.camera2.CameraAccessException;
  }
  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.CaptureResult);
    method public void onCaptureFailed(android.hardware.camera2.CameraDevice, android.hardware.camera2.CaptureRequest, android.hardware.camera2.CaptureFailure);
    method public void onCaptureSequenceCompleted(android.hardware.camera2.CameraDevice, int, int);
    method public void onCaptureStarted(android.hardware.camera2.CameraDevice, android.hardware.camera2.CaptureRequest, long);
  }
  public static abstract class CameraCaptureSession.StateListener {
    ctor public CameraCaptureSession.StateListener();
    method public void onActive(android.hardware.camera2.CameraCaptureSession);
    method public void onClosed(android.hardware.camera2.CameraCaptureSession);
    method public abstract void onConfigureFailed(android.hardware.camera2.CameraCaptureSession);
    method public abstract void onConfigured(android.hardware.camera2.CameraCaptureSession);
    method public void onReady(android.hardware.camera2.CameraCaptureSession);
  }
  public final class CameraCharacteristics extends android.hardware.camera2.CameraMetadata {
    method public T get(android.hardware.camera2.CameraMetadata.Key<T>);
    method public java.util.List<android.hardware.camera2.CameraMetadata.Key<?>> getAvailableCaptureRequestKeys();
@@ -12255,16 +12284,17 @@ package android.hardware.camera2 {
  }
  public abstract interface CameraDevice implements java.lang.AutoCloseable {
    method public abstract int capture(android.hardware.camera2.CaptureRequest, android.hardware.camera2.CameraDevice.CaptureListener, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
    method public abstract 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 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();
    method public abstract void configureOutputs(java.util.List<android.view.Surface>) throws android.hardware.camera2.CameraAccessException;
    method public abstract deprecated void configureOutputs(java.util.List<android.view.Surface>) throws android.hardware.camera2.CameraAccessException;
    method public abstract android.hardware.camera2.CaptureRequest.Builder createCaptureRequest(int) throws android.hardware.camera2.CameraAccessException;
    method public abstract void flush() throws android.hardware.camera2.CameraAccessException;
    method public abstract void createCaptureSession(java.util.List<android.view.Surface>, android.hardware.camera2.CameraCaptureSession.StateListener, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
    method public abstract deprecated void flush() throws android.hardware.camera2.CameraAccessException;
    method public abstract java.lang.String getId();
    method public abstract int setRepeatingBurst(java.util.List<android.hardware.camera2.CaptureRequest>, android.hardware.camera2.CameraDevice.CaptureListener, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
    method public abstract int setRepeatingRequest(android.hardware.camera2.CaptureRequest, android.hardware.camera2.CameraDevice.CaptureListener, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
    method public abstract void stopRepeating() throws android.hardware.camera2.CameraAccessException;
    method public abstract deprecated int setRepeatingBurst(java.util.List<android.hardware.camera2.CaptureRequest>, android.hardware.camera2.CameraDevice.CaptureListener, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
    method public abstract deprecated int setRepeatingRequest(android.hardware.camera2.CaptureRequest, android.hardware.camera2.CameraDevice.CaptureListener, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
    method public abstract deprecated void stopRepeating() throws android.hardware.camera2.CameraAccessException;
    field public static final int TEMPLATE_MANUAL = 6; // 0x6
    field public static final int TEMPLATE_PREVIEW = 1; // 0x1
    field public static final int TEMPLATE_RECORD = 3; // 0x3
@@ -12273,7 +12303,7 @@ package android.hardware.camera2 {
    field public static final int TEMPLATE_ZERO_SHUTTER_LAG = 5; // 0x5
  }
  public static abstract class CameraDevice.CaptureListener {
  public static abstract deprecated class CameraDevice.CaptureListener {
    ctor public CameraDevice.CaptureListener();
    method public void onCaptureCompleted(android.hardware.camera2.CameraDevice, android.hardware.camera2.CaptureRequest, android.hardware.camera2.CaptureResult);
    method public void onCaptureFailed(android.hardware.camera2.CameraDevice, android.hardware.camera2.CaptureRequest, android.hardware.camera2.CaptureFailure);
@@ -12283,14 +12313,14 @@ package android.hardware.camera2 {
  public static abstract class CameraDevice.StateListener {
    ctor public CameraDevice.StateListener();
    method public void onActive(android.hardware.camera2.CameraDevice);
    method public void onBusy(android.hardware.camera2.CameraDevice);
    method public deprecated void onActive(android.hardware.camera2.CameraDevice);
    method public deprecated void onBusy(android.hardware.camera2.CameraDevice);
    method public void onClosed(android.hardware.camera2.CameraDevice);
    method public abstract void onDisconnected(android.hardware.camera2.CameraDevice);
    method public abstract void onError(android.hardware.camera2.CameraDevice, int);
    method public void onIdle(android.hardware.camera2.CameraDevice);
    method public deprecated void onIdle(android.hardware.camera2.CameraDevice);
    method public abstract void onOpened(android.hardware.camera2.CameraDevice);
    method public void onUnconfigured(android.hardware.camera2.CameraDevice);
    method public deprecated void onUnconfigured(android.hardware.camera2.CameraDevice);
    field public static final int ERROR_CAMERA_DEVICE = 4; // 0x4
    field public static final int ERROR_CAMERA_DISABLED = 3; // 0x3
    field public static final int ERROR_CAMERA_IN_USE = 1; // 0x1
+588 −0

File added.

Preview size limit exceeded, changes collapsed.

+137 −12
Original line number Diff line number Diff line
@@ -242,9 +242,125 @@ public interface CameraDevice extends AutoCloseable {
     * @see StreamConfigurationMap#getOutputFormats()
     * @see StreamConfigurationMap#getOutputSizes(int)
     * @see StreamConfigurationMap#getOutputSizes(Class)
     * @deprecated Use {@link #createCaptureSession} instead
     */
    public void configureOutputs(List<Surface> outputs) throws CameraAccessException;

    /**
     * <p>Create a new camera capture session by providing the target output set of Surfaces to the
     * camera device.</p>
     *
     * <p>The active capture session determines the set of potential output Surfaces for
     * the camera device for each capture request. A given request may use all
     * or a only some of the outputs. Once the CameraCaptureSession is created, requests can be
     * can be submitted with {@link CameraCaptureSession#capture capture},
     * {@link CameraCaptureSession#captureBurst captureBurst},
     * {@link CameraCaptureSession#setRepeatingRequest setRepeatingRequest}, or
     * {@link CameraCaptureSession#setRepeatingBurst setRepeatingBurst}.</p>
     *
     * <p>Surfaces suitable for inclusion as a camera output can be created for
     * various use cases and targets:</p>
     *
     * <ul>
     *
     * <li>For drawing to a {@link android.view.SurfaceView SurfaceView}: Set the size of the
     *   Surface with {@link android.view.SurfaceHolder#setFixedSize} to be one of the sizes
     *   returned by
     *   {@link StreamConfigurationMap#getOutputSizes(Class) getOutputSizes(SurfaceView.class)}
     *   and then obtain the Surface by calling {@link android.view.SurfaceHolder#getSurface}.</li>
     *
     * <li>For accessing through an OpenGL texture via a
     *   {@link android.graphics.SurfaceTexture SurfaceTexture}: Set the size of
     *   the SurfaceTexture with
     *   {@link android.graphics.SurfaceTexture#setDefaultBufferSize} to be one
     *   of the sizes returned by
     *   {@link StreamConfigurationMap#getOutputSizes(Class) getOutputSizes(SurfaceTexture.class)}
     *   before creating a Surface from the SurfaceTexture with
     *   {@link Surface#Surface}.</li>
     *
     * <li>For recording with {@link android.media.MediaCodec}: Call
     *   {@link android.media.MediaCodec#createInputSurface} after configuring
     *   the media codec to use one of the sizes returned by
     *   {@link StreamConfigurationMap#getOutputSizes(Class) getOutputSizes(MediaCodec.class)}
     *   </li>
     *
     * <li>For recording with {@link android.media.MediaRecorder}: Call
     *   {@link android.media.MediaRecorder#getSurface} after configuring the media recorder to use
     *   one of the sizes returned by
     *   {@link StreamConfigurationMap#getOutputSizes(Class) getOutputSizes(MediaRecorder.class)},
     *   or configuring it to use one of the supported
     *   {@link android.media.CamcorderProfile CamcorderProfiles}.</li>
     *
     * <li>For efficient YUV processing with {@link android.renderscript}:
     *   Create a RenderScript
     *   {@link android.renderscript.Allocation Allocation} with a supported YUV
     *   type, the IO_INPUT flag, and one of the sizes returned by
     *   {@link StreamConfigurationMap#getOutputSizes(Class) getOutputSizes(Allocation.class)},
     *   Then obtain the Surface with
     *   {@link android.renderscript.Allocation#getSurface}.</li>
     *
     * <li>For access to raw, uncompressed or JPEG data in the application: Create a
     *   {@link android.media.ImageReader} object with the one of the supported
     *   {@link StreamConfigurationMap#getOutputFormats() output image formats}, and a
     *   size from the supported
     *   {@link StreamConfigurationMap#getOutputSizes(int) sizes for that format}. Then obtain
     *   a Surface from it with {@link android.media.ImageReader#getSurface}.</li>
     *
     * </ul>
     *
     * </p>
     *
     * <p>The camera device will query each Surface's size and formats upon this
     * call, so they must be set to a valid setting at this time (in particular:
     * if the format is user-visible, it must be one of
     * {@link StreamConfigurationMap#getOutputFormats}; and the size must be one of
     * {@link StreamConfigurationMap#getOutputSizes(int)}).</p>
     *
     * <p>It can take several hundred milliseconds for the session's configuration to complete,
     * since camera hardware may need to be powered on or reconfigured. Once the configuration is
     * complete and the session is ready to actually capture data, the provided
     * {@link CameraCaptureSession.StateListener}'s
     * {@link CameraCaptureSession.StateListener#onConfigured} callback will be called.</p>
     *
     * <p>If a prior CameraCaptureSession already exists when a new one is created, the previous
     * session is closed. Any in-progress capture requests made on the prior session will be
     * completed before the new session is configured and is able to start capturing its own
     * requests. To minimize the transition time, the {@link CameraCaptureSession#abortCaptures}
     * call can be used to discard the remaining requests for the prior capture session before a new
     * one is created. Note that once the new session is created, the old one can no longer have its
     * captures aborted.</p>
     *
     * <p>Using larger resolution outputs, or more outputs, can result in slower
     * output rate from the device.</p>
     *
     * <p>Configuring a session with an empty or null list will close the current session, if
     * any. This can be used to release the current session's target surfaces for another use.</p>
     *
     * @param outputs The new set of Surfaces that should be made available as
     *                targets for captured image data.
     * @param listener The listener to notify about the status of the new capture session.
     * @param handler The handler on which the listener should be invoked, or {@code null} to use
     *                the current thread's {@link android.os.Looper looper}.
     * <!--
     * @return A new camera capture session to use, or null if an empty/null set of Surfaces is
     *         provided.
     * -->
     * @throws IllegalArgumentException if the set of output Surfaces do not meet the requirements,
     *                                  the listener is null, or the handler is null but the current
     *                                  thread has no looper.
     * @throws CameraAccessException if the camera device is no longer connected or has
     *                               encountered a fatal error
     * @throws IllegalStateException if the camera device has been closed
     *
     * @see CameraCaptureSession
     * @see StreamConfigurationMap#getOutputFormats()
     * @see StreamConfigurationMap#getOutputSizes(int)
     * @see StreamConfigurationMap#getOutputSizes(Class)
     */
    public void createCaptureSession(List<Surface> outputs,
            CameraCaptureSession.StateListener listener, Handler handler)
            throws CameraAccessException;

    /**
     * <p>Create a {@link CaptureRequest.Builder} for new capture requests,
     * initialized with template for a target use case. The settings are chosen
@@ -314,6 +430,7 @@ public interface CameraDevice extends AutoCloseable {
     * @see #captureBurst
     * @see #setRepeatingRequest
     * @see #setRepeatingBurst
     * @deprecated Use {@link CameraCaptureSession} instead
     */
    public int capture(CaptureRequest request, CaptureListener listener, Handler handler)
            throws CameraAccessException;
@@ -358,6 +475,7 @@ public interface CameraDevice extends AutoCloseable {
     * @see #capture
     * @see #setRepeatingRequest
     * @see #setRepeatingBurst
     * @deprecated Use {@link CameraCaptureSession} instead
     */
    public int captureBurst(List<CaptureRequest> requests, CaptureListener listener,
            Handler handler) throws CameraAccessException;
@@ -416,6 +534,7 @@ public interface CameraDevice extends AutoCloseable {
     * @see #setRepeatingBurst
     * @see #stopRepeating
     * @see #flush
     * @deprecated Use {@link CameraCaptureSession} instead
     */
    public int setRepeatingRequest(CaptureRequest request, CaptureListener listener,
            Handler handler) throws CameraAccessException;
@@ -474,6 +593,7 @@ public interface CameraDevice extends AutoCloseable {
     * @see #setRepeatingRequest
     * @see #stopRepeating
     * @see #flush
     * @deprecated Use {@link CameraCaptureSession} instead
     */
    public int setRepeatingBurst(List<CaptureRequest> requests, CaptureListener listener,
            Handler handler) throws CameraAccessException;
@@ -498,6 +618,7 @@ public interface CameraDevice extends AutoCloseable {
     * @see #setRepeatingRequest
     * @see #setRepeatingBurst
     * @see StateListener#onIdle
     * @deprecated Use {@link CameraCaptureSession} instead
     */
    public void stopRepeating() throws CameraAccessException;

@@ -534,25 +655,24 @@ public interface CameraDevice extends AutoCloseable {
     * @see #setRepeatingRequest
     * @see #setRepeatingBurst
     * @see #configureOutputs
     * @deprecated Use {@link CameraCaptureSession} instead
     */
    public void flush() throws CameraAccessException;

    /**
     * Close the connection to this camera device.
     * Close the connection to this camera device as quickly as possible.
     *
     * <p>After this call, all calls to
     * the camera device interface will throw a {@link IllegalStateException},
     * except for calls to close(). Once the device has fully shut down, the
     * {@link StateListener#onClosed} callback will be called, and the camera is
     * free to be re-opened.</p>
     * <p>Immediately after this call, all calls to the camera device or active session interface
     * will throw a {@link IllegalStateException}, except for calls to close(). Once the device has
     * fully shut down, the {@link StateListener#onClosed} callback will be called, and the camera
     * is free to be re-opened.</p>
     *
     * <p>After this call, besides the final {@link StateListener#onClosed} call, no calls to the
     * device's {@link StateListener} will occur, and any remaining submitted capture requests will
     * not fire their {@link CaptureListener} callbacks.</p>
     * <p>Immediately after this call, besides the final {@link StateListener#onClosed} calls, no
     * further callbacks from the device or the active session will occur, and any remaining
     * submitted capture requests will be discarded, as if
     * {@link CameraCaptureSession#abortCaptures} had been called, except that no success or failure
     * callbacks will be invoked.</p>
     *
     * <p>To shut down as fast as possible, call the {@link #flush} method and then {@link #close}
     * once the flush completes. This will discard some capture requests, but results in faster
     * shutdown.</p>
     */
    @Override
    public void close();
@@ -569,6 +689,7 @@ public interface CameraDevice extends AutoCloseable {
     * @see #captureBurst
     * @see #setRepeatingRequest
     * @see #setRepeatingBurst
     * @deprecated Use {@link CameraCaptureSession} instead
     */
    public static abstract class CaptureListener {

@@ -834,6 +955,7 @@ public interface CameraDevice extends AutoCloseable {
         * <p>The default implementation of this method does nothing.</p>
         *
         * @param camera the camera device has that become unconfigured
         * @deprecated Use {@link CameraCaptureSession.StateListener} instead.
         */
        public void onUnconfigured(CameraDevice camera) {
            // Default empty implementation
@@ -863,6 +985,7 @@ public interface CameraDevice extends AutoCloseable {
         * @see CameraDevice#captureBurst
         * @see CameraDevice#setRepeatingBurst
         * @see CameraDevice#setRepeatingRequest
         * @deprecated Use {@link CameraCaptureSession.StateListener} instead.
         */
        public void onActive(CameraDevice camera) {
            // Default empty implementation
@@ -896,6 +1019,7 @@ public interface CameraDevice extends AutoCloseable {
         *
         * @see CameraDevice#configureOutputs
         * @see CameraDevice#flush
         * @deprecated Use {@link CameraCaptureSession.StateListener} instead.
         */
        public void onBusy(CameraDevice camera) {
            // Default empty implementation
@@ -943,6 +1067,7 @@ public interface CameraDevice extends AutoCloseable {
         * @see CameraDevice#configureOutputs
         * @see CameraDevice#stopRepeating
         * @see CameraDevice#flush
         * @deprecated Use {@link CameraCaptureSession.StateListener} instead.
         */
        public void onIdle(CameraDevice camera) {
            // Default empty implementation
+22 −16
Original line number Diff line number Diff line
@@ -199,11 +199,7 @@ public final class CameraManager {
    }

    /**
     * Open a connection to a camera with the given ID. Use
     * {@link #getCameraIdList} to get the list of available camera
     * devices. Note that even if an id is listed, open may fail if the device
     * is disconnected between the calls to {@link #getCameraIdList} and
     * {@link #openCamera}.
     * Helper for openning a connection to a camera with the given ID.
     *
     * @param cameraId The unique identifier of the camera device to open
     * @param listener The listener for the camera. Must not be null.
@@ -216,20 +212,22 @@ public final class CameraManager {
     * @throws SecurityException if the application does not have permission to
     * access the camera
     * @throws IllegalArgumentException if listener or handler is null.
     * @return A handle to the newly-created camera device.
     *
     * @see #getCameraIdList
     * @see android.app.admin.DevicePolicyManager#setCameraDisabled
     */
    private void openCameraDeviceUserAsync(String cameraId,
    private CameraDevice openCameraDeviceUserAsync(String cameraId,
            CameraDevice.StateListener listener, Handler handler)
            throws CameraAccessException {
        CameraDevice device = null;
        try {

            synchronized (mLock) {

                ICameraDeviceUser cameraUser;

                android.hardware.camera2.impl.CameraDevice device =
                android.hardware.camera2.impl.CameraDevice deviceImpl =
                        new android.hardware.camera2.impl.CameraDevice(
                                cameraId,
                                listener,
@@ -237,7 +235,7 @@ public final class CameraManager {

                BinderHolder holder = new BinderHolder();

                ICameraDeviceCallbacks callbacks = device.getCallbacks();
                ICameraDeviceCallbacks callbacks = deviceImpl.getCallbacks();
                int id = Integer.parseInt(cameraId);
                try {
                    mCameraService.connectDevice(callbacks, id, mContext.getPackageName(),
@@ -257,7 +255,8 @@ public final class CameraManager {
                // TODO: factor out listener to be non-nested, then move setter to constructor
                // For now, calling setRemoteDevice will fire initial
                // onOpened/onUnconfigured callbacks.
                device.setRemoteDevice(cameraUser);
                deviceImpl.setRemoteDevice(cameraUser);
                device = deviceImpl;
            }

        } catch (NumberFormatException e) {
@@ -268,6 +267,7 @@ public final class CameraManager {
        } catch (RemoteException e) {
            // impossible
        }
        return device;
    }

    /**
@@ -278,20 +278,26 @@ public final class CameraManager {
     * is disconnected between the calls to {@link #getCameraIdList} and
     * {@link #openCamera}.</p>
     *
     * <p>If the camera successfully opens after this function call returns,
     * {@link CameraDevice.StateListener#onOpened} will be invoked with the
     * newly opened {@link CameraDevice} in the unconfigured state.</p>
     *
     * <p>Once the camera is successfully opened, {@link CameraDevice.StateListener#onOpened} will
     * be invoked with the newly opened {@link CameraDevice}. The camera device can then be set up
     * for operation by calling {@link CameraDevice#createCaptureSession} and
     * {@link CameraDevice#createCaptureRequest}</p>
     *
     * <!--
     * <p>Since the camera device will be opened asynchronously, any asynchronous operations done
     * on the returned CameraDevice instance will be queued up until the device startup has
     * completed and the listener's {@link CameraDevice.StateListener#onOpened onOpened} method is
     * called. The pending operations are then processed in order.</p>
     * -->
     * <p>If the camera becomes disconnected during initialization
     * after this function call returns,
     * {@link CameraDevice.StateListener#onDisconnected} with a
     * {@link CameraDevice} in the disconnected state (and
     * {@link CameraDevice.StateListener#onOpened} will be skipped).</p>
     *
     * <p>If the camera fails to initialize after this function call returns,
     * {@link CameraDevice.StateListener#onError} will be invoked with a
     * {@link CameraDevice} in the error state (and
     * {@link CameraDevice.StateListener#onOpened} will be skipped).</p>
     * <p>If opening the camera device fails, then the device listener's
     * {@link CameraDevice.StateListener#onError onError} method will be called, and subsequent
     * calls on the camera device will throw an {@link IllegalStateException}.</p>
     *
     * @param cameraId
     *             The unique identifier of the camera device to open
+8 −0

File changed.

Preview size limit exceeded, changes collapsed.