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

Commit 1e42a0a4 authored by Emilian Peev's avatar Emilian Peev
Browse files

Camera: Use dedicated class for realtime latency queries

Return a dedicated still capture latency result instead of
using a Pair.

Bug: 262453235
Test: Camera CTS
Change-Id: I47f095baa6dfad26b01a84e9c73c7bfe1dfd88b5
parent d741b93f
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -17946,7 +17946,7 @@ package android.hardware.camera2 {
    method public int capture(@NonNull android.hardware.camera2.CaptureRequest, @NonNull java.util.concurrent.Executor, @NonNull android.hardware.camera2.CameraExtensionSession.ExtensionCaptureCallback) throws android.hardware.camera2.CameraAccessException;
    method public void close() throws android.hardware.camera2.CameraAccessException;
    method @NonNull public android.hardware.camera2.CameraDevice getDevice();
    method @Nullable public android.util.Pair<java.lang.Long,java.lang.Long> getRealtimeStillCaptureLatency() throws android.hardware.camera2.CameraAccessException;
    method @Nullable public android.hardware.camera2.CameraExtensionSession.StillCaptureLatency getRealtimeStillCaptureLatency() throws android.hardware.camera2.CameraAccessException;
    method public int setRepeatingRequest(@NonNull android.hardware.camera2.CaptureRequest, @NonNull java.util.concurrent.Executor, @NonNull android.hardware.camera2.CameraExtensionSession.ExtensionCaptureCallback) throws android.hardware.camera2.CameraAccessException;
    method public void stopRepeating() throws android.hardware.camera2.CameraAccessException;
  }
@@ -17969,6 +17969,12 @@ package android.hardware.camera2 {
    method public abstract void onConfigured(@NonNull android.hardware.camera2.CameraExtensionSession);
  }
  public static final class CameraExtensionSession.StillCaptureLatency {
    ctor public CameraExtensionSession.StillCaptureLatency(long, long);
    method public long getCaptureLatency();
    method public long getProcessingLatency();
  }
  public final class CameraManager {
    method @NonNull public android.hardware.camera2.CameraCharacteristics getCameraCharacteristics(@NonNull String) throws android.hardware.camera2.CameraAccessException;
    method @NonNull public android.hardware.camera2.CameraExtensionCharacteristics getCameraExtensionCharacteristics(@NonNull String) throws android.hardware.camera2.CameraAccessException;
+61 −12
Original line number Diff line number Diff line
@@ -19,10 +19,7 @@ package android.hardware.camera2;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.hardware.camera2.impl.PublicKey;
import android.hardware.camera2.utils.TypeReference;
import android.util.Pair;
import android.util.Range;
import android.hardware.camera2.utils.HashCodeHelpers;

import java.util.concurrent.Executor;

@@ -429,14 +426,66 @@ public abstract class CameraExtensionSession implements AutoCloseable {
    }

    /**
     * Return the realtime still {@link #capture} latency.
     * Realtime calculated still {@link #capture} latency.
     *
     * <p>The pair will be in milliseconds with the first value indicating the capture latency from
     * the {@link ExtensionCaptureCallback#onCaptureStarted} until
     * {@link ExtensionCaptureCallback#onCaptureProcessStarted}
     * and the second value containing the estimated post-processing latency from
     * {@link ExtensionCaptureCallback#onCaptureProcessStarted} until the processed frame returns
     * to the client.</p>
     * @see #getRealtimeStillCaptureLatency()
     */
    public final static class StillCaptureLatency {
        private final long mCaptureLatency, mProcessingLatency;

        public StillCaptureLatency(long captureLatency, long processingLatency) {
            mCaptureLatency = captureLatency;
            mProcessingLatency = processingLatency;
        }
        /**
         * Return the capture latency from
         * {@link ExtensionCaptureCallback#onCaptureStarted} until
         * {@link ExtensionCaptureCallback#onCaptureProcessStarted}.
         *
         * @return The realtime capture latency in milliseconds.
         */
        public long getCaptureLatency() {
            return mCaptureLatency;
        }

        /**
         * Return the estimated post-processing latency from
         * {@link ExtensionCaptureCallback#onCaptureProcessStarted} until the processed frame
         * returns to the client.
         *
         * @return returns post-processing latency in milliseconds
         */
        public long getProcessingLatency() {
            return mProcessingLatency;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            StillCaptureLatency latency = (StillCaptureLatency) o;

            if (mCaptureLatency != latency.mCaptureLatency) return false;
            if (mProcessingLatency != latency.mProcessingLatency) return false;

            return true;
        }

        @Override
        public int hashCode() {
            return HashCodeHelpers.hashCode(mCaptureLatency, mProcessingLatency);
        }

        @Override
        public String toString() {
            return "StillCaptureLatency(processingLatency:" + mProcessingLatency +
                    ", captureLatency: " + mCaptureLatency + ")";
        }
    }

    /**
     * Return the realtime still {@link #capture} latency.
     *
     * <p>The estimations will take into account the current environment conditions, the camera
     * state and will include the time spent processing the multi-frame capture request along with
@@ -446,7 +495,7 @@ public abstract class CameraExtensionSession implements AutoCloseable {
     * or {@code null} if the estimation is not supported.
     */
    @Nullable
    public Pair<Long, Long> getRealtimeStillCaptureLatency() throws CameraAccessException {
    public StillCaptureLatency getRealtimeStillCaptureLatency() throws CameraAccessException {
        throw new UnsupportedOperationException("Subclasses must override this method");
    }

+2 −2
Original line number Diff line number Diff line
@@ -332,7 +332,7 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
    }

    @Override
    public Pair<Long, Long> getRealtimeStillCaptureLatency() throws CameraAccessException {
    public StillCaptureLatency getRealtimeStillCaptureLatency() throws CameraAccessException {
        synchronized (mInterfaceLock) {
            if (!mInitialized) {
                throw new IllegalStateException("Uninitialized component");
@@ -341,7 +341,7 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
            try {
                LatencyPair latency = mSessionProcessor.getRealtimeCaptureLatency();
                if (latency != null) {
                    return new Pair<>(latency.first, latency.second);
                    return new StillCaptureLatency(latency.first, latency.second);
                }

                return null;
+2 −2
Original line number Diff line number Diff line
@@ -468,7 +468,7 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession {
    }

    @Override
    public Pair<Long, Long> getRealtimeStillCaptureLatency() throws CameraAccessException {
    public StillCaptureLatency getRealtimeStillCaptureLatency() throws CameraAccessException {
        synchronized (mInterfaceLock) {
            if (!mInitialized) {
                throw new IllegalStateException("Uninitialized component");
@@ -477,7 +477,7 @@ public final class CameraExtensionSessionImpl extends CameraExtensionSession {
            try {
                LatencyPair latency = mImageExtender.getRealtimeCaptureLatency();
                if (latency != null) {
                    return new Pair<>(latency.first, latency.second);
                    return new StillCaptureLatency(latency.first, latency.second);
                }

                return null;