Skip to content

Commit

Permalink
add getCameraResolutions by cameraId to camera2
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Nov 9, 2023
1 parent 2cdd1c1 commit 03f4405
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions library/src/main/java/com/pedro/library/base/Camera1Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Camera.Size> 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<Camera.Size> getResolutionsFront() {
return cameraManager.getPreviewSizeFront();
Expand Down
17 changes: 13 additions & 4 deletions library/src/main/java/com/pedro/library/base/Camera2Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Size> 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<Size> getResolutionsFront() {
return Arrays.asList(cameraManager.getCameraResolutionsFront());
}

/**
* Get supported resolutions of cameraId in px.
*
* @return list of resolutions supported by cameraId
*/
public List<Size> getResolutions(String cameraId) {
return Arrays.asList(cameraManager.getCameraResolutions(cameraId));
}

public List<Range<Integer>> getSupportedFps() {
return cameraManager.getSupportedFps(null, CameraHelper.Facing.BACK);
}
Expand Down

0 comments on commit 03f4405

Please sign in to comment.