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 ed93bd12a0fe6af831a4a27db268f86b0deb3791..f69a894c6f982da3f3890ef4b0d001cc6551b534 100644 |
--- a/webrtc/api/java/android/org/webrtc/CameraEnumerationAndroid.java |
+++ b/webrtc/api/java/android/org/webrtc/CameraEnumerationAndroid.java |
@@ -25,6 +25,37 @@ public class CameraEnumerationAndroid { |
private final static String TAG = "CameraEnumerationAndroid"; |
public static class CaptureFormat { |
+ // Class for describing width and height dimensions in pixels. |
+ public static class Size { |
+ public int width; |
+ public int height; |
+ |
+ public Size(int width, int height) { |
+ this.width = width; |
+ this.height = height; |
+ } |
+ |
+ @Override |
+ public String toString() { |
+ return width + "x" + height; |
+ } |
+ |
+ @Override |
+ public boolean equals(Object other) { |
+ if (!(other instanceof Size)) { |
+ return false; |
+ } |
+ final Size otherSize = (Size) other; |
+ return width == otherSize.width && height == otherSize.height; |
+ } |
+ |
+ @Override |
+ public int hashCode() { |
+ // Use prime close to 2^16 to avoid collisions for normal values less than 2^16. |
+ return 1 + 65537 * width + height; |
+ } |
+ } |
+ |
// 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 { |
@@ -57,29 +88,27 @@ public class CameraEnumerationAndroid { |
} |
} |
- public final int width; |
- public final int height; |
+ public final Size size; |
public final FramerateRange framerate; |
+ |
// 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) { |
- this.width = width; |
- this.height = height; |
+ this.size = new Size(width, height); |
this.framerate = new FramerateRange(minFramerate, maxFramerate); |
} |
- public CaptureFormat(int width, int height, FramerateRange framerate) { |
- this.width = width; |
- this.height = height; |
+ public CaptureFormat(Size size, FramerateRange framerate) { |
+ this.size = size; |
this.framerate = framerate; |
} |
// Calculates the frame size of this capture format. |
public int frameSize() { |
- return frameSize(width, height, imageFormat); |
+ return frameSize(size.width, size.height, imageFormat); |
} |
// Calculates the frame size of the specified image format. Currently only |
@@ -96,14 +125,21 @@ public class CameraEnumerationAndroid { |
@Override |
public String toString() { |
- return width + "x" + height + "@" + framerate; |
+ return size.toString() + "@" + framerate.toString(); |
} |
- public boolean isSameFormat(final CaptureFormat that) { |
- if (that == null) { |
+ @Override |
+ public boolean equals(Object other) { |
+ if (!(other instanceof CaptureFormat)) { |
return false; |
} |
- return width == that.width && height == that.height && framerate.equals(that.framerate); |
+ final CaptureFormat otherFormat = (CaptureFormat) other; |
+ return size.equals(otherFormat.size) && framerate.equals(otherFormat.framerate); |
+ } |
+ |
+ @Override |
+ public int hashCode() { |
+ return 1 + 31 * size.hashCode() + framerate.hashCode(); |
} |
} |
@@ -210,12 +246,13 @@ public class CameraEnumerationAndroid { |
}); |
} |
- public static android.hardware.Camera.Size getClosestSupportedSize( |
- List<android.hardware.Camera.Size> supportedSizes, final int requestedWidth, |
+ public static CaptureFormat.Size getClosestSupportedSize( |
+ List<CaptureFormat.Size> supportedSizes, final int requestedWidth, |
final int requestedHeight) { |
return Collections.min(supportedSizes, |
- new ClosestComparator<android.hardware.Camera.Size>() { |
- @Override int diff(android.hardware.Camera.Size size) { |
+ new ClosestComparator<CaptureFormat.Size>() { |
+ @Override |
+ int diff(CaptureFormat.Size size) { |
return abs(requestedWidth - size.width) + abs(requestedHeight - size.height); |
} |
}); |