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

Commit 95171050 authored by Eino-Ville Talvala's avatar Eino-Ville Talvala Committed by Android (Google) Code Review
Browse files

Merge "Camera2: Add buffer drop error callback" into nyc-dev

parents d51b363c 3e0023ae
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -13776,6 +13776,7 @@ package android.hardware.camera2 {
  public static abstract class CameraCaptureSession.CaptureCallback {
    ctor public CameraCaptureSession.CaptureCallback();
    method public void onCaptureBufferLost(android.hardware.camera2.CameraCaptureSession, android.hardware.camera2.CaptureRequest, android.view.Surface, 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);
+1 −0
Original line number Diff line number Diff line
@@ -14177,6 +14177,7 @@ package android.hardware.camera2 {
  public static abstract class CameraCaptureSession.CaptureCallback {
    ctor public CameraCaptureSession.CaptureCallback();
    method public void onCaptureBufferLost(android.hardware.camera2.CameraCaptureSession, android.hardware.camera2.CaptureRequest, android.view.Surface, 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);
+1 −0
Original line number Diff line number Diff line
@@ -13786,6 +13786,7 @@ package android.hardware.camera2 {
  public static abstract class CameraCaptureSession.CaptureCallback {
    ctor public CameraCaptureSession.CaptureCallback();
    method public void onCaptureBufferLost(android.hardware.camera2.CameraCaptureSession, android.hardware.camera2.CaptureRequest, android.view.Surface, 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);
+24 −0
Original line number Diff line number Diff line
@@ -990,6 +990,30 @@ public abstract class CameraCaptureSession implements AutoCloseable {
                int sequenceId) {
            // default empty implementation
        }

        /**
         * <p>This method is called if a single buffer for a capture could not be sent to its
         * destination surface.</p>
         *
         * <p>If the whole capture failed, then {@link #onCaptureFailed} will be called instead. If
         * some but not all buffers were captured but the result metadata will not be available,
         * then onCaptureFailed will be invoked with {@link CaptureFailure#wasImageCaptured}
         * returning true, along with one or more calls to {@link #onCaptureBufferLost} for the
         * failed outputs.</p>
         *
         * @param session
         *            The session returned by {@link CameraDevice#createCaptureSession}
         * @param request
         *            The request that was given to the CameraDevice
         * @param target
         *            The target Surface that the buffer will not be produced for
         * @param frameNumber
         *            The frame number for the request
         */
        public void onCaptureBufferLost(@NonNull CameraCaptureSession session,
                @NonNull CaptureRequest request, @NonNull Surface target, long frameNumber) {
            // default empty implementation
        }
    }

    /**
+61 −38
Original line number Diff line number Diff line
@@ -1116,6 +1116,11 @@ public class CameraDeviceImpl extends CameraDevice
                int sequenceId) {
            // default empty implementation
        }

        public void onCaptureBufferLost(CameraDevice camera,
                CaptureRequest request, Surface target, long frameNumber) {
            // default empty implementation
        }
    }

    /**
@@ -1887,18 +1892,33 @@ public class CameraDeviceImpl extends CameraDevice

            final CaptureRequest request = holder.getRequest(subsequenceId);

            // No way to report buffer errors right now
            Runnable failureDispatch = null;
            if (errorCode == ERROR_CAMERA_BUFFER) {
                Log.e(TAG, String.format("Lost output buffer reported for frame %d", frameNumber));
                return;
                final Surface outputSurface =
                        mConfiguredOutputs.get(resultExtras.getErrorStreamId()).getSurface();
                if (DEBUG) {
                    Log.v(TAG, String.format("Lost output buffer reported for frame %d, target %s",
                            frameNumber, outputSurface));
                }

                failureDispatch = new Runnable() {
                    @Override
                    public void run() {
                        if (!CameraDeviceImpl.this.isClosed()){
                            holder.getCallback().onCaptureBufferLost(
                                CameraDeviceImpl.this,
                                request,
                                outputSurface,
                                frameNumber);
                        }
                    }
                };
            } else {
                boolean mayHaveBuffers = (errorCode == ERROR_CAMERA_RESULT);

                // This is only approximate - exact handling needs the camera service and HAL to
            // disambiguate between request failures to due abort and due to real errors.
            // For now, assume that if the session believes we're mid-abort, then the error
            // is due to abort.
                // disambiguate between request failures to due abort and due to real errors.  For
                // now, assume that if the session believes we're mid-abort, then the error is due
                // to abort.
                int reason = (mCurrentSession != null && mCurrentSession.isAborting()) ?
                        CaptureFailure.REASON_FLUSHED :
                        CaptureFailure.REASON_ERROR;
@@ -1910,7 +1930,7 @@ public class CameraDeviceImpl extends CameraDevice
                    requestId,
                    frameNumber);

            Runnable failureDispatch = new Runnable() {
                failureDispatch = new Runnable() {
                    @Override
                    public void run() {
                        if (!CameraDeviceImpl.this.isClosed()){
@@ -1921,7 +1941,6 @@ public class CameraDeviceImpl extends CameraDevice
                        }
                    }
                };
            holder.getHandler().post(failureDispatch);

                // Fire onCaptureSequenceCompleted if appropriate
                if (DEBUG) {
@@ -1931,6 +1950,10 @@ public class CameraDeviceImpl extends CameraDevice
                checkAndFireSequenceComplete();
            }

            // Dispatch the failure callback
            holder.getHandler().post(failureDispatch);
        }

    } // public class CameraDeviceCallbacks

    /**
Loading