Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Unified Diff: webrtc/api/java/android/org/webrtc/Camera2Enumerator.java

Issue 2013433003: WIP: Android Camera2 capture implementation (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix CaptureFormat jni parsing Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/api/java/android/org/webrtc/Camera2Enumerator.java
diff --git a/webrtc/api/java/android/org/webrtc/Camera2Enumerator.java b/webrtc/api/java/android/org/webrtc/Camera2Enumerator.java
index 933599dc957044c1094dc003e145cbbd507dcd37..f91522a93edd65f2464e760af5ed5c3de19a8078 100644
--- a/webrtc/api/java/android/org/webrtc/Camera2Enumerator.java
+++ b/webrtc/api/java/android/org/webrtc/Camera2Enumerator.java
@@ -14,6 +14,8 @@ import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.ImageFormat;
+import android.graphics.SurfaceTexture;
+import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.params.StreamConfigurationMap;
@@ -61,39 +63,34 @@ public class Camera2Enumerator implements CameraEnumerationAndroid.Enumerator {
final CameraCharacteristics cameraCharacteristics;
try {
cameraCharacteristics = cameraManager.getCameraCharacteristics(Integer.toString(cameraId));
- } catch (Exception ex) {
- Logging.e(TAG, "getCameraCharacteristics(): " + ex);
+ } catch (CameraAccessException e) {
+ Logging.e(TAG, "getCameraCharacteristics(): " + e);
return new ArrayList<CaptureFormat>();
}
- // Calculate default max fps from auto-exposure ranges in case getOutputMinFrameDuration() is
- // not supported.
final Range<Integer>[] fpsRanges =
cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
- int defaultMaxFps = 0;
+ int maxFps = 0;
for (Range<Integer> fpsRange : fpsRanges) {
- defaultMaxFps = Math.max(defaultMaxFps, fpsRange.getUpper());
+ maxFps = Math.max(maxFps, fpsRange.getUpper());
+ }
+ if (maxFps < 1000) {
+ // Some LEGACY camera implementations use fps rates that are multiplied with 1000. Make sure
+ // all values are multiplied with 1000 for consistency.
+ maxFps *= 1000;
}
-
final StreamConfigurationMap streamMap =
cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
- final Size[] sizes = streamMap.getOutputSizes(ImageFormat.YUV_420_888);
+ final Size[] sizes = streamMap.getOutputSizes(SurfaceTexture.class);
if (sizes == null) {
- throw new RuntimeException("ImageFormat.YUV_420_888 not supported.");
+ Logging.e(TAG, "No supported camera output sizes.");
+ return new ArrayList<CaptureFormat>();
}
final List<CaptureFormat> formatList = new ArrayList<CaptureFormat>();
for (Size size : sizes) {
long minFrameDurationNs = 0;
- try {
- minFrameDurationNs = streamMap.getOutputMinFrameDuration(ImageFormat.YUV_420_888, size);
- } catch (Exception e) {
- // getOutputMinFrameDuration() is not supported on all devices. Ignore silently.
- }
- final int maxFps = (minFrameDurationNs == 0)
- ? defaultMaxFps
- : (int) Math.round(NANO_SECONDS_PER_SECOND / minFrameDurationNs);
- formatList.add(new CaptureFormat(size.getWidth(), size.getHeight(), 0, maxFps * 1000));
+ formatList.add(new CaptureFormat(size.getWidth(), size.getHeight(), 0, maxFps));
}
cachedSupportedFormats.put(cameraId, formatList);
final long endTimeMs = SystemClock.elapsedRealtime();
@@ -102,4 +99,25 @@ public class Camera2Enumerator implements CameraEnumerationAndroid.Enumerator {
return formatList;
}
}
+
+ // Convert from android.util.Size to CaptureFormat.Size.
+ public static List<CaptureFormat.Size> convertSizes(Size[] cameraSizes) {
+ final List<CaptureFormat.Size> sizes = new ArrayList<CaptureFormat.Size>();
+ for (Size size : cameraSizes) {
+ sizes.add(new CaptureFormat.Size(size.getWidth(), size.getHeight()));
+ }
+ return sizes;
+ }
+
+ // Convert from android.util.Range<Integer> to CaptureFormat.FramerateRange.
+ public static List<CaptureFormat.FramerateRange> convertFramerates(
+ Range<Integer>[] arrayRanges, int unitFactor) {
+ final List<CaptureFormat.FramerateRange> ranges = new ArrayList<CaptureFormat.FramerateRange>();
+ for (Range<Integer> range : arrayRanges) {
+ ranges.add(new CaptureFormat.FramerateRange(
+ range.getLower() * unitFactor,
+ range.getUpper() * unitFactor));
+ }
+ return ranges;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698