ImageCapture - PhotoCapabilities.java: add an inner Builder class
Cleanup: PhotoCapabilities is starting to have too many
parameters, so this CL adds a builder for it.
BUG=518807
Review-Url: https://codereview.chromium.org/2272653004
Cr-Commit-Position: refs/heads/master@{#414438}
diff --git a/media/capture/video/android/java/src/org/chromium/media/PhotoCapabilities.java b/media/capture/video/android/java/src/org/chromium/media/PhotoCapabilities.java
index 347caf9..f8dd905 100644
--- a/media/capture/video/android/java/src/org/chromium/media/PhotoCapabilities.java
+++ b/media/capture/video/android/java/src/org/chromium/media/PhotoCapabilities.java
@@ -27,7 +27,6 @@
public final int focusMode;
public final int exposureMode;
- // TODO(mcasas): Add a PhotoCapabilitiesBuilder to this class.
PhotoCapabilities(int maxIso, int minIso, int currentIso, int maxHeight, int minHeight,
int currentHeight, int maxWidth, int minWidth, int currentWidth, int maxZoom,
int minZoom, int currentZoom, int focusMode, int exposureMode) {
@@ -116,4 +115,99 @@
public int getExposureMode() {
return exposureMode;
}
+
+ public static class Builder {
+ public int maxIso;
+ public int minIso;
+ public int currentIso;
+ public int maxHeight;
+ public int minHeight;
+ public int currentHeight;
+ public int maxWidth;
+ public int minWidth;
+ public int currentWidth;
+ public int maxZoom;
+ public int minZoom;
+ public int currentZoom;
+ public int focusMode;
+ public int exposureMode;
+
+ public Builder() {}
+
+ public Builder setMaxIso(int maxIso) {
+ this.maxIso = maxIso;
+ return this;
+ }
+
+ public Builder setMinIso(int minIso) {
+ this.minIso = minIso;
+ return this;
+ }
+
+ public Builder setCurrentIso(int currentIso) {
+ this.currentIso = currentIso;
+ return this;
+ }
+
+ public Builder setMaxHeight(int maxHeight) {
+ this.maxHeight = maxHeight;
+ return this;
+ }
+
+ public Builder setMinHeight(int minHeight) {
+ this.minHeight = minHeight;
+ return this;
+ }
+
+ public Builder setCurrentHeight(int currentHeight) {
+ this.currentHeight = currentHeight;
+ return this;
+ }
+
+ public Builder setMaxWidth(int maxWidth) {
+ this.maxWidth = maxWidth;
+ return this;
+ }
+
+ public Builder setMinWidth(int minWidth) {
+ this.minWidth = minWidth;
+ return this;
+ }
+
+ public Builder setCurrentWidth(int currentWidth) {
+ this.currentWidth = currentWidth;
+ return this;
+ }
+
+ public Builder setMaxZoom(int maxZoom) {
+ this.maxZoom = maxZoom;
+ return this;
+ }
+
+ public Builder setMinZoom(int minZoom) {
+ this.minZoom = minZoom;
+ return this;
+ }
+
+ public Builder setCurrentZoom(int currentZoom) {
+ this.currentZoom = currentZoom;
+ return this;
+ }
+
+ public Builder setFocusMode(int focusMode) {
+ this.focusMode = focusMode;
+ return this;
+ }
+
+ public Builder setExposureMode(int exposureMode) {
+ this.exposureMode = exposureMode;
+ return this;
+ }
+
+ public PhotoCapabilities build() {
+ return new PhotoCapabilities(maxIso, minIso, currentIso, maxHeight, minHeight,
+ currentHeight, maxWidth, minWidth, currentWidth, maxZoom, minZoom, currentZoom,
+ focusMode, exposureMode);
+ }
+ }
}
diff --git a/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera.java b/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera.java
index 6bfbcfe3..39d6b94 100644
--- a/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera.java
+++ b/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera.java
@@ -301,14 +301,13 @@
@Override
public PhotoCapabilities getPhotoCapabilities() {
final android.hardware.Camera.Parameters parameters = getCameraParameters(mCamera);
+ PhotoCapabilities.Builder builder = new PhotoCapabilities.Builder();
Log.i(TAG, " CAM params: %s", parameters.flatten());
// Before the Camera2 API there was no official way to retrieve the supported, if any, ISO
// values from |parameters|; some platforms had "iso-values", others "iso-mode-values" etc.
// Ignore them.
- final int maxIso = 0;
- final int currentIso = 0;
- final int minIso = 0;
+ builder.setMinIso(0).setMaxIso(0).setCurrentIso(0);
List<android.hardware.Camera.Size> supportedSizes = parameters.getSupportedPictureSizes();
int minWidth = Integer.MAX_VALUE;
@@ -321,7 +320,11 @@
if (size.width > maxWidth) maxWidth = size.width;
if (size.height > maxHeight) maxHeight = size.height;
}
+ builder.setMinHeight(minHeight).setMaxHeight(maxHeight);
+ builder.setMinWidth(minWidth).setMaxWidth(maxWidth);
final android.hardware.Camera.Size currentSize = parameters.getPreviewSize();
+ builder.setCurrentHeight(currentSize.height);
+ builder.setCurrentWidth(currentSize.width);
int maxZoom = 0;
int currentZoom = 0;
@@ -332,6 +335,7 @@
currentZoom = 100 + 100 * parameters.getZoom();
minZoom = parameters.getZoomRatios().get(0);
}
+ builder.setMinZoom(minZoom).setMaxZoom(maxZoom).setCurrentZoom(currentZoom);
Log.d(TAG, "parameters.getFocusMode(): %s", parameters.getFocusMode());
final String focusMode = parameters.getFocusMode();
@@ -351,6 +355,7 @@
|| focusMode.equals(android.hardware.Camera.Parameters.FOCUS_MODE_FIXED)) {
jniFocusMode = AndroidMeteringMode.FIXED;
}
+ builder.setFocusMode(jniFocusMode);
// Exposure is usually continuously updated except it not available at all, or if the
// exposure compensation is locked, in which case we consider it as FIXED.
@@ -360,12 +365,12 @@
if (parameters.isAutoExposureLockSupported() && parameters.getAutoExposureLock()) {
jniExposureMode = AndroidMeteringMode.FIXED;
}
+ builder.setExposureMode(jniExposureMode);
+
// TODO(mcasas): https://crbug.com/518807 read the exposure compensation min and max
// values using getMinExposureCompensation() and getMaxExposureCompensation().
- return new PhotoCapabilities(minIso, maxIso, currentIso, maxHeight, minHeight,
- currentSize.height, maxWidth, minWidth, currentSize.width, maxZoom, minZoom,
- currentZoom, jniFocusMode, jniExposureMode);
+ return builder.build();
}
@Override
diff --git a/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java b/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java
index f633d7a5..c059d4f 100644
--- a/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java
+++ b/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java
@@ -572,6 +572,7 @@
public PhotoCapabilities getPhotoCapabilities() {
final CameraCharacteristics cameraCharacteristics = getCameraCharacteristics(mContext, mId);
+ PhotoCapabilities.Builder builder = new PhotoCapabilities.Builder();
int minIso = 0;
int maxIso = 0;
@@ -581,7 +582,8 @@
minIso = iso_range.getLower();
maxIso = iso_range.getUpper();
}
- final int currentIso = mPreviewRequest.get(CaptureRequest.SENSOR_SENSITIVITY);
+ builder.setMinIso(minIso).setMaxIso(maxIso);
+ builder.setCurrentIso(mPreviewRequest.get(CaptureRequest.SENSOR_SENSITIVITY));
final StreamConfigurationMap streamMap =
cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
@@ -596,8 +598,10 @@
if (size.getWidth() > maxWidth) maxWidth = size.getWidth();
if (size.getHeight() > maxHeight) maxHeight = size.getHeight();
}
- final int currentHeight = (mPhotoHeight > 0) ? mPhotoHeight : mCaptureFormat.getHeight();
- final int currentWidth = (mPhotoWidth > 0) ? mPhotoWidth : mCaptureFormat.getWidth();
+ builder.setMinHeight(minHeight).setMaxHeight(maxHeight);
+ builder.setMinWidth(minWidth).setMaxWidth(maxWidth);
+ builder.setCurrentHeight((mPhotoHeight > 0) ? mPhotoHeight : mCaptureFormat.getHeight());
+ builder.setCurrentWidth((mPhotoWidth > 0) ? mPhotoWidth : mCaptureFormat.getWidth());
// The Min and Max zoom are returned as x100 by the API to avoid using floating point. There
// is no min-zoom per se, so clamp it to always 100 (TODO(mcasas): make const member).
@@ -608,6 +612,7 @@
* cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE)
.width()
/ mPreviewRequest.get(CaptureRequest.SCALER_CROP_REGION).width();
+ builder.setMinZoom(minZoom).setMaxZoom(maxZoom).setCurrentZoom(currentZoom);
final int focusMode = mPreviewRequest.get(CaptureRequest.CONTROL_AF_MODE);
// Classify the Focus capabilities. In CONTINUOUS and SINGLE_SHOT, we can call
@@ -624,6 +629,7 @@
} else {
assert jniFocusMode == CameraMetadata.CONTROL_AF_MODE_EDOF;
}
+ builder.setFocusMode(jniFocusMode);
int jniExposureMode = AndroidMeteringMode.CONTINUOUS;
if (mPreviewRequest.get(CaptureRequest.CONTROL_AE_MODE)
@@ -633,12 +639,12 @@
if (mPreviewRequest.get(CaptureRequest.CONTROL_AE_LOCK)) {
jniExposureMode = AndroidMeteringMode.FIXED;
}
+ builder.setFocusMode(jniExposureMode);
+
// TODO(mcasas): https://crbug.com/518807 read the exposure compensation min and max
// values using CONTROL_AE_COMPENSATION_RANGE.
- return new PhotoCapabilities(minIso, maxIso, currentIso, maxHeight, minHeight,
- currentHeight, maxWidth, minWidth, currentWidth, maxZoom, minZoom, currentZoom,
- jniFocusMode, jniExposureMode);
+ return builder.build();
}
@Override