| Index: webrtc/api/java/android/org/webrtc/CameraEnumerationAndroid.java
|
| diff --git a/webrtc/api/java/android/org/webrtc/CameraEnumerationAndroid.java b/webrtc/api/java/android/org/webrtc/CameraEnumerationAndroid.java
|
| index 2fa685d1fbceda2fbb9f7ceac4d2e2bb5bfdb251..c5c8be3a5d8e62443fb28ce70c9a8dc82fd0d1c5 100644
|
| --- a/webrtc/api/java/android/org/webrtc/CameraEnumerationAndroid.java
|
| +++ b/webrtc/api/java/android/org/webrtc/CameraEnumerationAndroid.java
|
| @@ -43,56 +43,21 @@
|
| }
|
|
|
| public static class CaptureFormat {
|
| - // Class to represent a framerate range. The framerate varies because of lightning conditions.
|
| - // The values are multiplied by 1000, so 1000 represents one frame per second.
|
| - public static class FramerateRange {
|
| - public int min;
|
| - public int max;
|
| -
|
| - public FramerateRange(int min, int max) {
|
| - this.min = min;
|
| - this.max = max;
|
| - }
|
| -
|
| - @Override
|
| - public String toString() {
|
| - return "[" + (min / 1000.0f) + ":" + (max / 1000.0f) + "]";
|
| - }
|
| -
|
| - @Override
|
| - public boolean equals(Object other) {
|
| - if (!(other instanceof FramerateRange)) {
|
| - return false;
|
| - }
|
| - final FramerateRange otherFramerate = (FramerateRange) other;
|
| - return min == otherFramerate.min && max == otherFramerate.max;
|
| - }
|
| -
|
| - @Override
|
| - public int hashCode() {
|
| - // Use prime close to 2^16 to avoid collisions for normal values less than 2^16.
|
| - return 1 + 65537 * min + max;
|
| - }
|
| - }
|
| -
|
| public final int width;
|
| public final int height;
|
| - public final FramerateRange framerate;
|
| + public final int maxFramerate;
|
| + public final int minFramerate;
|
| // TODO(hbos): If VideoCapturer.startCapture is updated to support other image formats then this
|
| // needs to be updated and VideoCapturer.getSupportedFormats need to return CaptureFormats of
|
| // all imageFormats.
|
| public final int imageFormat = ImageFormat.NV21;
|
|
|
| - public CaptureFormat(int width, int height, int minFramerate, int maxFramerate) {
|
| + public CaptureFormat(int width, int height, int minFramerate,
|
| + int maxFramerate) {
|
| this.width = width;
|
| this.height = height;
|
| - this.framerate = new FramerateRange(minFramerate, maxFramerate);
|
| - }
|
| -
|
| - public CaptureFormat(int width, int height, FramerateRange framerate) {
|
| - this.width = width;
|
| - this.height = height;
|
| - this.framerate = framerate;
|
| + this.minFramerate = minFramerate;
|
| + this.maxFramerate = maxFramerate;
|
| }
|
|
|
| // Calculates the frame size of this capture format.
|
| @@ -114,14 +79,15 @@
|
|
|
| @Override
|
| public String toString() {
|
| - return width + "x" + height + "@" + framerate;
|
| + return width + "x" + height + "@[" + minFramerate + ":" + maxFramerate + "]";
|
| }
|
|
|
| public boolean isSameFormat(final CaptureFormat that) {
|
| if (that == null) {
|
| return false;
|
| }
|
| - return width == that.width && height == that.height && framerate.equals(that.framerate);
|
| + return width == that.width && height == that.height && maxFramerate == that.maxFramerate
|
| + && minFramerate == that.minFramerate;
|
| }
|
| }
|
|
|
| @@ -168,9 +134,7 @@
|
| return getNameOfDevice(android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK);
|
| }
|
|
|
| - // Helper class for finding the closest supported format for the two functions below. It creates a
|
| - // comparator based on the difference to some requested parameters, where the element with the
|
| - // minimum difference is the element that is closest to the requested parameters.
|
| + // Helper class for finding the closest supported format for the two functions below.
|
| private static abstract class ClosestComparator<T> implements Comparator<T> {
|
| // Difference between supported and requested parameter.
|
| abstract int diff(T supportedParameter);
|
| @@ -181,15 +145,20 @@
|
| }
|
| }
|
|
|
| - public static CaptureFormat.FramerateRange getClosestSupportedFramerateRange(
|
| - List<CaptureFormat.FramerateRange> supportedFramerates, final int requestedFps) {
|
| - return Collections.min(supportedFramerates,
|
| - new ClosestComparator<CaptureFormat.FramerateRange>() {
|
| - private static final int MAX_FPS_WEIGHT = 10;
|
| -
|
| - @Override
|
| - int diff(CaptureFormat.FramerateRange range) {
|
| - return range.min + MAX_FPS_WEIGHT * abs(requestedFps * 1000 - range.max);
|
| + public static int[] getFramerateRange(android.hardware.Camera.Parameters parameters,
|
| + final int framerate) {
|
| + List<int[]> listFpsRange = parameters.getSupportedPreviewFpsRange();
|
| + if (listFpsRange.isEmpty()) {
|
| + Logging.w(TAG, "No supported preview fps range");
|
| + return new int[]{0, 0};
|
| + }
|
| + return Collections.min(listFpsRange,
|
| + new ClosestComparator<int[]>() {
|
| + @Override int diff(int[] range) {
|
| + final int maxFpsWeight = 10;
|
| + return range[android.hardware.Camera.Parameters.PREVIEW_FPS_MIN_INDEX]
|
| + + maxFpsWeight * abs(framerate
|
| + - range[android.hardware.Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
|
| }
|
| });
|
| }
|
|
|