From a20cf2c8a200c7ad1eec5b5e6ad754d18f099281 Mon Sep 17 00:00:00 2001 From: Emilian Peev Date: Tue, 6 Apr 2021 16:16:58 -0700 Subject: [PATCH] Camera: Enable camera extension latency range queries Allow Camera2 extension clients to query best/worst multi-frame capture latency ranges if available. Bug: 179819443 Test: make docs, atest -c cts/tests/camera/src/android/hardware/camera2/cts/CameraExtensionCharacteristicsTest.java Change-Id: I3f8c51d7cefbb58c79e3e75962a7b4d6283d24df --- core/api/current.txt | 1 + .../CameraExtensionCharacteristics.java | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/core/api/current.txt b/core/api/current.txt index 4f28266475a5c..40745e34e6a48 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -18032,6 +18032,7 @@ package android.hardware.camera2 { } public final class CameraExtensionCharacteristics { + method @Nullable public android.util.Range getEstimatedCaptureLatencyRange(int, @NonNull android.util.Size, int); method @NonNull public java.util.List getExtensionSupportedSizes(int, @NonNull Class); method @NonNull public java.util.List getExtensionSupportedSizes(int, int); method @NonNull public java.util.List getSupportedExtensions(); diff --git a/core/java/android/hardware/camera2/CameraExtensionCharacteristics.java b/core/java/android/hardware/camera2/CameraExtensionCharacteristics.java index 6121cd260dc3f..fd10c57e85dcb 100644 --- a/core/java/android/hardware/camera2/CameraExtensionCharacteristics.java +++ b/core/java/android/hardware/camera2/CameraExtensionCharacteristics.java @@ -15,6 +15,7 @@ */ package android.hardware.camera2; +import android.annotation.Nullable; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -33,6 +34,7 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.util.Log; import android.util.Pair; +import android.util.Range; import android.util.Size; import java.util.HashSet; @@ -566,4 +568,47 @@ public final class CameraExtensionCharacteristics { return new ArrayList<>(); } } + + /** + * Returns the estimated capture latency range in milliseconds for the + * target capture resolution during the calls to {@link CameraExtensionSession#capture}. This + * includes the time spent processing the multi-frame capture request along with any additional + * time for encoding of the processed buffer if necessary. + * + * @param extension the extension type + * @param captureOutputSize size of the capture output surface. If it is not in the supported + * output sizes, maximum capture output size is used for the estimation + * @param format device-specific extension output format + * @return the range of estimated minimal and maximal capture latency in milliseconds + * or null if no capture latency info can be provided + * + * @throws IllegalArgumentException in case of format different from {@link ImageFormat#JPEG} / + * {@link ImageFormat#YUV_420_888}; or unsupported extension. + */ + public @Nullable Range getEstimatedCaptureLatencyRange(@Extension int extension, + @NonNull Size captureOutputSize, @ImageFormat.Format int format) { + switch (format) { + case ImageFormat.YUV_420_888: + case ImageFormat.JPEG: + //No op + break; + default: + throw new IllegalArgumentException("Unsupported format: " + format); + } + + long clientId = registerClient(mContext); + if (clientId < 0) { + throw new IllegalArgumentException("Unsupported extensions"); + } + + try { + if (!isExtensionSupported(mCameraId, extension, mChars)) { + throw new IllegalArgumentException("Unsupported extension"); + } + } finally { + unregisterClient(clientId); + } + + return null; + } }