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

Commit 3e0023ae authored by Eino-Ville Talvala's avatar Eino-Ville Talvala
Browse files

Camera2: Add buffer drop error callback

Previously single buffer drop errors were not propagated to
the client application, even though the HAL generated them.

Add new error callback to handle this case.

Bug: 24168122
Change-Id: Ice0d9a3592efed222351353abd7acc35854a20bd
parent 5781e61c
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -13775,6 +13775,7 @@ package android.hardware.camera2 {
  public static abstract class CameraCaptureSession.CaptureCallback {
  public static abstract class CameraCaptureSession.CaptureCallback {
    ctor public 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 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 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 onCaptureProgressed(android.hardware.camera2.CameraCaptureSession, android.hardware.camera2.CaptureRequest, android.hardware.camera2.CaptureResult);
+1 −0
Original line number Original line Diff line number Diff line
@@ -14176,6 +14176,7 @@ package android.hardware.camera2 {
  public static abstract class CameraCaptureSession.CaptureCallback {
  public static abstract class CameraCaptureSession.CaptureCallback {
    ctor public 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 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 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 onCaptureProgressed(android.hardware.camera2.CameraCaptureSession, android.hardware.camera2.CaptureRequest, android.hardware.camera2.CaptureResult);
+1 −0
Original line number Original line Diff line number Diff line
@@ -13785,6 +13785,7 @@ package android.hardware.camera2 {
  public static abstract class CameraCaptureSession.CaptureCallback {
  public static abstract class CameraCaptureSession.CaptureCallback {
    ctor public 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 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 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 onCaptureProgressed(android.hardware.camera2.CameraCaptureSession, android.hardware.camera2.CaptureRequest, android.hardware.camera2.CaptureResult);
+24 −0
Original line number Original line Diff line number Diff line
@@ -990,6 +990,30 @@ public abstract class CameraCaptureSession implements AutoCloseable {
                int sequenceId) {
                int sequenceId) {
            // default empty implementation
            // 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 Original line Diff line number Diff line
@@ -1116,6 +1116,11 @@ public class CameraDeviceImpl extends CameraDevice
                int sequenceId) {
                int sequenceId) {
            // default empty implementation
            // 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);
            final CaptureRequest request = holder.getRequest(subsequenceId);


            // No way to report buffer errors right now
            Runnable failureDispatch = null;
            if (errorCode == ERROR_CAMERA_BUFFER) {
            if (errorCode == ERROR_CAMERA_BUFFER) {
                Log.e(TAG, String.format("Lost output buffer reported for frame %d", frameNumber));
                final Surface outputSurface =
                return;
                        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);
                boolean mayHaveBuffers = (errorCode == ERROR_CAMERA_RESULT);


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


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


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


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

    } // public class CameraDeviceCallbacks
    } // public class CameraDeviceCallbacks


    /**
    /**
Loading