Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support get wide angle cameraids #1459

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -289,6 +290,28 @@ public List<Range<Integer>> getSupportedFps(Size size, Facing facing) {
}
}

public String[] getCameraIdsForWideAngle() {
List<String> 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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions library/src/main/java/com/pedro/library/base/Camera2Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ class Camera2Source(context: Context): VideoSource() {

fun camerasAvailable(): Array<String>? = camera.camerasAvailable

fun getCameraIdsForWideAngle(): Array<String> = camera.getCameraIdsForWideAngle()

fun openCameraId(id: String) {
if (isRunning()) stop()
camera.openCameraId(id)
Expand Down
Loading