From 03f4405dbf9d2b64be9ae2af61da213f718fc790 Mon Sep 17 00:00:00 2001 From: pedro Date: Thu, 9 Nov 2023 11:01:33 +0100 Subject: [PATCH] add getCameraResolutions by cameraId to camera2 --- .../input/video/Camera2ApiManager.java | 24 +++++++++++++++++++ .../com/pedro/library/base/Camera1Base.java | 8 +++---- .../com/pedro/library/base/Camera2Base.java | 17 +++++++++---- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/encoder/src/main/java/com/pedro/encoder/input/video/Camera2ApiManager.java b/encoder/src/main/java/com/pedro/encoder/input/video/Camera2ApiManager.java index 5df691615..8b2f5fe50 100644 --- a/encoder/src/main/java/com/pedro/encoder/input/video/Camera2ApiManager.java +++ b/encoder/src/main/java/com/pedro/encoder/input/video/Camera2ApiManager.java @@ -368,6 +368,24 @@ public Size[] getCameraResolutions(Facing facing) { } } + public Size[] getCameraResolutions(String cameraId) { + try { + CameraCharacteristics characteristics = getCharacteristicsForId(cameraManager, cameraId); + if (characteristics == null) { + return new Size[0]; + } + + StreamConfigurationMap streamConfigurationMap = + characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); + if (streamConfigurationMap == null) return new Size[0]; + Size[] outputSizes = streamConfigurationMap.getOutputSizes(SurfaceTexture.class); + return outputSizes != null ? outputSizes : new Size[0]; + } catch (CameraAccessException | NullPointerException e) { + Log.e(TAG, "Error", e); + return new Size[0]; + } + } + @Nullable public CameraCharacteristics getCameraCharacteristics() { try { @@ -1119,6 +1137,12 @@ public String getCameraIdForFacing(CameraHelper.Facing facing) { private CameraCharacteristics getCharacteristicsForFacing(CameraManager cameraManager, CameraHelper.Facing facing) throws CameraAccessException { String cameraId = getCameraIdForFacing(cameraManager, facing); + return getCharacteristicsForId(cameraManager, cameraId); + } + + @Nullable + private CameraCharacteristics getCharacteristicsForId(CameraManager cameraManager, + String cameraId) throws CameraAccessException { return cameraId != null ? cameraManager.getCameraCharacteristics(cameraId) : null; } diff --git a/library/src/main/java/com/pedro/library/base/Camera1Base.java b/library/src/main/java/com/pedro/library/base/Camera1Base.java index e87937d10..af572698b 100644 --- a/library/src/main/java/com/pedro/library/base/Camera1Base.java +++ b/library/src/main/java/com/pedro/library/base/Camera1Base.java @@ -770,18 +770,18 @@ public void stopStream() { } /** - * Get supported preview resolutions of back camera in px. + * Get supported resolutions of back camera in px. * - * @return list of preview resolutions supported by back camera + * @return list of resolutions supported by back camera */ public List getResolutionsBack() { return cameraManager.getPreviewSizeBack(); } /** - * Get supported preview resolutions of front camera in px. + * Get supported resolutions of front camera in px. * - * @return list of preview resolutions supported by front camera + * @return list of resolutions supported by front camera */ public List getResolutionsFront() { return cameraManager.getPreviewSizeFront(); diff --git a/library/src/main/java/com/pedro/library/base/Camera2Base.java b/library/src/main/java/com/pedro/library/base/Camera2Base.java index c7325a06c..db9638c24 100644 --- a/library/src/main/java/com/pedro/library/base/Camera2Base.java +++ b/library/src/main/java/com/pedro/library/base/Camera2Base.java @@ -715,23 +715,32 @@ public void stopStream() { } /** - * Get supported preview resolutions of back camera in px. + * Get supported resolutions of back camera in px. * - * @return list of preview resolutions supported by back camera + * @return list of resolutions supported by back camera */ public List getResolutionsBack() { return Arrays.asList(cameraManager.getCameraResolutionsBack()); } /** - * Get supported preview resolutions of front camera in px. + * Get supported resolutions of front camera in px. * - * @return list of preview resolutions supported by front camera + * @return list of resolutions supported by front camera */ public List getResolutionsFront() { return Arrays.asList(cameraManager.getCameraResolutionsFront()); } + /** + * Get supported resolutions of cameraId in px. + * + * @return list of resolutions supported by cameraId + */ + public List getResolutions(String cameraId) { + return Arrays.asList(cameraManager.getCameraResolutions(cameraId)); + } + public List> getSupportedFps() { return cameraManager.getSupportedFps(null, CameraHelper.Facing.BACK); }