Small changes

pull/661/head
Mattia Iavarone 6 years ago
parent fa88783d37
commit bafcb2146c
  1. 50
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraOptions.java
  2. 38
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java

@ -60,8 +60,8 @@ public class CameraOptions {
private float exposureCorrectionMinValue;
private float exposureCorrectionMaxValue;
private boolean autoFocusSupported;
private float fpsRangeMinValue;
private float fpsRangeMaxValue;
private float previewFrameRateMinValue;
private float previewFrameRateMaxValue;
public CameraOptions(@NonNull Camera.Parameters params, int cameraId, boolean flipSizes) {
@ -160,8 +160,8 @@ public class CameraOptions {
}
//fps range
fpsRangeMinValue = 0F;
fpsRangeMaxValue = 0F;
previewFrameRateMinValue = 0F;
previewFrameRateMaxValue = 0F;
}
// Camera2Engine constructor.
@ -280,21 +280,21 @@ public class CameraOptions {
}
//fps Range
fpsRangeMinValue = Float.MAX_VALUE;
fpsRangeMaxValue = Float.MIN_VALUE;
previewFrameRateMinValue = Float.MAX_VALUE;
previewFrameRateMaxValue = Float.MIN_VALUE;
Range<Integer>[] range = cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
if (range != null) {
for (Range<Integer> fpsRange : range) {
if (fpsRange.getLower() <= fpsRangeMinValue) {
fpsRangeMinValue = fpsRange.getLower();
if (fpsRange.getLower() <= previewFrameRateMinValue) {
previewFrameRateMinValue = fpsRange.getLower();
}
if (fpsRange.getUpper() >= fpsRangeMaxValue) {
fpsRangeMaxValue = fpsRange.getUpper();
if (fpsRange.getUpper() >= previewFrameRateMaxValue) {
previewFrameRateMaxValue = fpsRange.getUpper();
}
}
} else {
fpsRangeMinValue = 0F;
fpsRangeMaxValue = 0F;
previewFrameRateMinValue = 0F;
previewFrameRateMaxValue = 0F;
}
}
@ -308,7 +308,6 @@ public class CameraOptions {
return getSupportedControls(control.getClass()).contains(control);
}
/**
* Shorthand for other methods in this class,
* e.g. supports(GestureAction.ZOOM) == isZoomSupported().
@ -333,7 +332,6 @@ public class CameraOptions {
return false;
}
@SuppressWarnings("unchecked")
@NonNull
public <T extends Control> Collection<T> getSupportedControls(@NonNull Class<T> controlClass) {
@ -362,7 +360,6 @@ public class CameraOptions {
return Collections.emptyList();
}
/**
* Set of supported picture sizes for the currently opened camera.
*
@ -373,7 +370,6 @@ public class CameraOptions {
return Collections.unmodifiableSet(supportedPictureSizes);
}
/**
* Set of supported picture aspect ratios for the currently opened camera.
*
@ -385,7 +381,6 @@ public class CameraOptions {
return Collections.unmodifiableSet(supportedPictureAspectRatio);
}
/**
* Set of supported video sizes for the currently opened camera.
*
@ -396,7 +391,6 @@ public class CameraOptions {
return Collections.unmodifiableSet(supportedVideoSizes);
}
/**
* Set of supported picture aspect ratios for the currently opened camera.
*
@ -408,7 +402,6 @@ public class CameraOptions {
return Collections.unmodifiableSet(supportedVideoAspectRatio);
}
/**
* Set of supported facing values.
*
@ -421,7 +414,6 @@ public class CameraOptions {
return Collections.unmodifiableSet(supportedFacing);
}
/**
* Set of supported flash values.
*
@ -436,7 +428,6 @@ public class CameraOptions {
return Collections.unmodifiableSet(supportedFlash);
}
/**
* Set of supported white balance values.
*
@ -452,7 +443,6 @@ public class CameraOptions {
return Collections.unmodifiableSet(supportedWhiteBalance);
}
/**
* Set of supported hdr values.
*
@ -488,7 +478,6 @@ public class CameraOptions {
return autoFocusSupported;
}
/**
* Whether exposure correction is supported. If this is false, calling
* {@link CameraView#setExposureCorrection(float)} has no effect.
@ -501,7 +490,6 @@ public class CameraOptions {
return exposureCorrectionSupported;
}
/**
* The minimum value of negative exposure correction, in EV stops.
* This is presumably negative or 0 if not supported.
@ -524,18 +512,20 @@ public class CameraOptions {
}
/**
* The minimum value for FPS
* The minimum value for the preview frame rate, in frames per second (FPS).
*
* @return the min value
*/
public float getFpsRangeMinValue() {
return fpsRangeMinValue;
public float getPreviewFrameRateMinValue() {
return previewFrameRateMinValue;
}
/**
* The maximum value for FPS
* The maximum value for the preview frame rate, in frames per second (FPS).
*
* @return the max value
*/
public float getFpsRangeMaxValue() {
return fpsRangeMaxValue;
public float getPreviewFrameRateMaxValue() {
return previewFrameRateMaxValue;
}
}

@ -83,7 +83,6 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
private static final int FRAME_PROCESSING_FORMAT = ImageFormat.NV21;
private static final int FRAME_PROCESSING_INPUT_FORMAT = ImageFormat.YUV_420_888;
private static final int DEFAULT_FRAME_RATE = 30;
@VisibleForTesting static final long METER_TIMEOUT = 2500;
private final CameraManager mManager;
@ -1273,22 +1272,29 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
}
@SuppressWarnings("WeakerAccess")
protected boolean applyPreviewFrameRate(@NonNull CaptureRequest.Builder builder, float oldPreviewFrameRate) {
Range<Integer>[] fpsRanges = mCameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
if (fpsRanges != null) {
if (mPreviewFrameRate != 0f) {
for (Range<Integer> fpsRange : fpsRanges) {
if (fpsRange.contains((int) mPreviewFrameRate)) {
builder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
return true;
}
protected boolean applyPreviewFrameRate(@NonNull CaptureRequest.Builder builder,
float oldPreviewFrameRate) {
//noinspection unchecked
Range<Integer>[] fallback = new Range[]{};
Range<Integer>[] fpsRanges = readCharacteristic(
CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES,
fallback);
if (mPreviewFrameRate == 0F) {
// 0F is a special value. Fallback to a reasonable default.
for (Range<Integer> fpsRange : fpsRanges) {
if (fpsRange.contains(30) || fpsRange.contains(24)) {
builder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
return true;
}
} else {
for (Range<Integer> fpsRange : fpsRanges) {
if (fpsRange.contains(DEFAULT_FRAME_RATE)) {
builder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
return true;
}
}
} else {
// If out of boundaries, adjust it.
mPreviewFrameRate = Math.min(mPreviewFrameRate, mCameraOptions.getPreviewFrameRateMaxValue());
mPreviewFrameRate = Math.max(mPreviewFrameRate, mCameraOptions.getPreviewFrameRateMinValue());
for (Range<Integer> fpsRange : fpsRanges) {
if (fpsRange.contains(Math.round(mPreviewFrameRate))) {
builder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
return true;
}
}
}

Loading…
Cancel
Save