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 b2d89135e..6111d1038 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 @@ -44,6 +44,7 @@ import android.util.Log; import android.util.Range; import android.util.Size; +import android.util.SizeF; import android.view.MotionEvent; import android.view.Surface; import android.view.SurfaceView; @@ -289,6 +290,28 @@ public List> getSupportedFps(Size size, Facing facing) { } } + public String[] getCameraIdsForWideAngle() { + List ids = new ArrayList<>(); + for (String cameraId : getCamerasAvailable()) { + CameraCharacteristics characteristics = getCameraCharacteristics(cameraId); + if (characteristics == null) continue; + float[] focalLength = characteristics.get(CameraCharacteristics.LENS_INFO_AVAILABLE_FOCAL_LENGTHS); + SizeF sensor = characteristics.get(CameraCharacteristics.SENSOR_INFO_PHYSICAL_SIZE); + if (focalLength == null || focalLength.length == 0 || sensor == null) continue; + float sensorWidth = sensor.getWidth(); + float sensorHeight = sensor.getHeight(); + float sensorSize = (float) Math.sqrt(sensorWidth * sensorWidth + sensorHeight * sensorHeight); + for (float focal : focalLength) { + float effectiveFocalLength = focal * (43.27f / sensorSize); + if (effectiveFocalLength >= 12f && effectiveFocalLength <= 16f) { + ids.add(cameraId); + break; + } + } + } + return ids.toArray(new String[0]); + } + public int getLevelSupported() { try { CameraCharacteristics characteristics = getCameraCharacteristics(); @@ -387,7 +410,7 @@ public Size[] getCameraResolutions(String cameraId) { } @Nullable - public CameraCharacteristics getCameraCharacteristics() { + public CameraCharacteristics getCameraCharacteristics(String cameraId) { try { return cameraId != null ? cameraManager.getCameraCharacteristics(cameraId) : null; } catch (CameraAccessException e) { @@ -396,6 +419,11 @@ public CameraCharacteristics getCameraCharacteristics() { } } + @Nullable + public CameraCharacteristics getCameraCharacteristics() { + return getCameraCharacteristics(cameraId); + } + public boolean enableVideoStabilization() { CameraCharacteristics characteristics = getCameraCharacteristics(); if (characteristics == null) return false; 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 8fa3f4709..8f0ff6344 100644 --- a/library/src/main/java/com/pedro/library/base/Camera2Base.java +++ b/library/src/main/java/com/pedro/library/base/Camera2Base.java @@ -216,6 +216,10 @@ public boolean isFaceDetectionEnabled() { return cameraManager.isFaceDetectionEnabled(); } + public String[] getCameraIdsForWideAngle() { + return cameraManager.getCameraIdsForWideAngle(); + } + /** * Enable EIS video stabilization * Warning: Turning both OIS and EIS modes on may produce undesirable interaction, so it is recommended not to enable both at the same time. diff --git a/library/src/main/java/com/pedro/library/util/sources/video/Camera2Source.kt b/library/src/main/java/com/pedro/library/util/sources/video/Camera2Source.kt index cce180438..693bd68b1 100644 --- a/library/src/main/java/com/pedro/library/util/sources/video/Camera2Source.kt +++ b/library/src/main/java/com/pedro/library/util/sources/video/Camera2Source.kt @@ -171,6 +171,8 @@ class Camera2Source(context: Context): VideoSource() { fun camerasAvailable(): Array? = camera.camerasAvailable + fun getCameraIdsForWideAngle(): Array = camera.getCameraIdsForWideAngle() + fun openCameraId(id: String) { if (isRunning()) stop() camera.openCameraId(id)