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

Side by Side Diff: webrtc/api/java/android/org/webrtc/Camera1Enumerator.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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 package org.webrtc; 11 package org.webrtc;
12 12
13 import android.os.SystemClock; 13 import android.os.SystemClock;
14 14
15 import org.webrtc.CameraEnumerationAndroid.CaptureFormat; 15 import org.webrtc.CameraEnumerationAndroid.CaptureFormat;
16 import org.webrtc.Logging; 16 import org.webrtc.Logging;
17 17
18 import java.util.ArrayList; 18 import java.util.ArrayList;
19 import java.util.List; 19 import java.util.List;
20 20
21 @SuppressWarnings("deprecation") 21 @SuppressWarnings("deprecation")
22 public class CameraEnumerator implements CameraEnumerationAndroid.Enumerator { 22 public class Camera1Enumerator implements CameraEnumerationAndroid.Enumerator {
23 private final static String TAG = "CameraEnumerator"; 23 private final static String TAG = "Camera1Enumerator";
24 // Each entry contains the supported formats for corresponding camera index. T he formats for all 24 // Each entry contains the supported formats for corresponding camera index. T he formats for all
25 // cameras are enumerated on the first call to getSupportedFormats(), and cach ed for future 25 // cameras are enumerated on the first call to getSupportedFormats(), and cach ed for future
26 // reference. 26 // reference.
27 private List<List<CaptureFormat>> cachedSupportedFormats; 27 private List<List<CaptureFormat>> cachedSupportedFormats;
28 28
29 @Override 29 @Override
30 public List<CaptureFormat> getSupportedFormats(int cameraId) { 30 public List<CaptureFormat> getSupportedFormats(int cameraId) {
31 synchronized (this) { 31 synchronized (this) {
32 if (cachedSupportedFormats == null) { 32 if (cachedSupportedFormats == null) {
33 cachedSupportedFormats = new ArrayList<List<CaptureFormat>>(); 33 cachedSupportedFormats = new ArrayList<List<CaptureFormat>>();
34 for (int i = 0; i < CameraEnumerationAndroid.getDeviceCount(); ++i) { 34 for (int i = 0; i < CameraEnumerationAndroid.getDeviceCount(); ++i) {
35 cachedSupportedFormats.add(enumerateFormats(i)); 35 cachedSupportedFormats.add(enumerateFormats(i));
36 } 36 }
37 } 37 }
38 } 38 }
39 return cachedSupportedFormats.get(cameraId); 39 return cachedSupportedFormats.get(cameraId);
40 } 40 }
41 41
42 private List<CaptureFormat> enumerateFormats(int cameraId) { 42 private static List<CaptureFormat> enumerateFormats(int cameraId) {
43 Logging.d(TAG, "Get supported formats for camera index " + cameraId + "."); 43 Logging.d(TAG, "Get supported formats for camera index " + cameraId + ".");
44 final long startTimeMs = SystemClock.elapsedRealtime(); 44 final long startTimeMs = SystemClock.elapsedRealtime();
45 final android.hardware.Camera.Parameters parameters; 45 final android.hardware.Camera.Parameters parameters;
46 android.hardware.Camera camera = null; 46 android.hardware.Camera camera = null;
47 try { 47 try {
48 Logging.d(TAG, "Opening camera with index " + cameraId); 48 Logging.d(TAG, "Opening camera with index " + cameraId);
49 camera = android.hardware.Camera.open(cameraId); 49 camera = android.hardware.Camera.open(cameraId);
50 parameters = camera.getParameters(); 50 parameters = camera.getParameters();
51 } catch (RuntimeException e) { 51 } catch (RuntimeException e) {
52 Logging.e(TAG, "Open camera failed on camera index " + cameraId, e); 52 Logging.e(TAG, "Open camera failed on camera index " + cameraId, e);
(...skipping 21 matching lines...) Expand all
74 } 74 }
75 } catch (Exception e) { 75 } catch (Exception e) {
76 Logging.e(TAG, "getSupportedFormats() failed on camera index " + cameraId, e); 76 Logging.e(TAG, "getSupportedFormats() failed on camera index " + cameraId, e);
77 } 77 }
78 78
79 final long endTimeMs = SystemClock.elapsedRealtime(); 79 final long endTimeMs = SystemClock.elapsedRealtime();
80 Logging.d(TAG, "Get supported formats for camera index " + cameraId + " done ." 80 Logging.d(TAG, "Get supported formats for camera index " + cameraId + " done ."
81 + " Time spent: " + (endTimeMs - startTimeMs) + " ms."); 81 + " Time spent: " + (endTimeMs - startTimeMs) + " ms.");
82 return formatList; 82 return formatList;
83 } 83 }
84
85 // Convert from android.hardware.Camera.Size to CaptureFormat.Size.
86 public static List<CaptureFormat.Size> convertSizes(
87 List<android.hardware.Camera.Size> cameraSizes) {
88 final List<CaptureFormat.Size> sizes = new ArrayList<CaptureFormat.Size>();
89 for (android.hardware.Camera.Size size : cameraSizes) {
90 sizes.add(new CaptureFormat.Size(size.width, size.height));
91 }
92 return sizes;
93 }
94
95 // Convert from int[2] to CaptureFormat.FramerateRange.
96 public static List<CaptureFormat.FramerateRange> convertFramerates(
97 List<int[]> arrayRanges) {
98 final List<CaptureFormat.FramerateRange> ranges = new ArrayList<CaptureForma t.FramerateRange>();
99 for (int[] range : arrayRanges) {
100 ranges.add(new CaptureFormat.FramerateRange(
101 range[android.hardware.Camera.Parameters.PREVIEW_FPS_MIN_INDEX],
102 range[android.hardware.Camera.Parameters.PREVIEW_FPS_MAX_INDEX]));
103 }
104 return ranges;
105 }
84 } 106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698