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

Side by Side Diff: talk/app/webrtc/java/android/org/webrtc/CameraEnumerator.java

Issue 1338033003: Log to webrtc logging stream from java code. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 3 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 * libjingle 2 * libjingle
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 11 matching lines...) Expand all
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 package org.webrtc; 28 package org.webrtc;
29 29
30 import android.hardware.Camera; 30 import android.hardware.Camera;
31 import android.os.SystemClock; 31 import android.os.SystemClock;
32 import android.util.Log;
33 32
34 import org.webrtc.CameraEnumerationAndroid.CaptureFormat; 33 import org.webrtc.CameraEnumerationAndroid.CaptureFormat;
34 import org.webrtc.Logging;
35 35
36 import java.util.ArrayList; 36 import java.util.ArrayList;
37 import java.util.List; 37 import java.util.List;
38 38
39 @SuppressWarnings("deprecation") 39 @SuppressWarnings("deprecation")
40 public class CameraEnumerator implements CameraEnumerationAndroid.Enumerator { 40 public class CameraEnumerator implements CameraEnumerationAndroid.Enumerator {
41 private final static String TAG = "CameraEnumerator"; 41 private final static String TAG = "CameraEnumerator";
42 // Each entry contains the supported formats for corresponding camera index. T he formats for all 42 // Each entry contains the supported formats for corresponding camera index. T he formats for all
43 // cameras are enumerated on the first call to getSupportedFormats(), and cach ed for future 43 // cameras are enumerated on the first call to getSupportedFormats(), and cach ed for future
44 // reference. 44 // reference.
45 private List<List<CaptureFormat>> cachedSupportedFormats; 45 private List<List<CaptureFormat>> cachedSupportedFormats;
46 46
47 @Override 47 @Override
48 public List<CaptureFormat> getSupportedFormats(int cameraId) { 48 public List<CaptureFormat> getSupportedFormats(int cameraId) {
49 synchronized (this) { 49 synchronized (this) {
50 if (cachedSupportedFormats == null) { 50 if (cachedSupportedFormats == null) {
51 cachedSupportedFormats = new ArrayList<List<CaptureFormat>>(); 51 cachedSupportedFormats = new ArrayList<List<CaptureFormat>>();
52 for (int i = 0; i < CameraEnumerationAndroid.getDeviceCount(); ++i) { 52 for (int i = 0; i < CameraEnumerationAndroid.getDeviceCount(); ++i) {
53 cachedSupportedFormats.add(enumerateFormats(i)); 53 cachedSupportedFormats.add(enumerateFormats(i));
54 } 54 }
55 } 55 }
56 } 56 }
57 return cachedSupportedFormats.get(cameraId); 57 return cachedSupportedFormats.get(cameraId);
58 } 58 }
59 59
60 private List<CaptureFormat> enumerateFormats(int cameraId) { 60 private List<CaptureFormat> enumerateFormats(int cameraId) {
61 Log.d(TAG, "Get supported formats for camera index " + cameraId + "."); 61 Logging.d(TAG, "Get supported formats for camera index " + cameraId + ".");
62 final long startTimeMs = SystemClock.elapsedRealtime(); 62 final long startTimeMs = SystemClock.elapsedRealtime();
63 final Camera.Parameters parameters; 63 final Camera.Parameters parameters;
64 Camera camera = null; 64 Camera camera = null;
65 try { 65 try {
66 Log.d(TAG, "Opening camera with index " + cameraId); 66 Logging.d(TAG, "Opening camera with index " + cameraId);
67 camera = Camera.open(cameraId); 67 camera = Camera.open(cameraId);
68 parameters = camera.getParameters(); 68 parameters = camera.getParameters();
69 } catch (RuntimeException e) { 69 } catch (RuntimeException e) {
70 Log.e(TAG, "Open camera failed on camera index " + cameraId, e); 70 Logging.e(TAG, "Open camera failed on camera index " + cameraId, e);
71 return new ArrayList<CaptureFormat>(); 71 return new ArrayList<CaptureFormat>();
72 } finally { 72 } finally {
73 if (camera != null) { 73 if (camera != null) {
74 camera.release(); 74 camera.release();
75 } 75 }
76 } 76 }
77 77
78 final List<CaptureFormat> formatList = new ArrayList<CaptureFormat>(); 78 final List<CaptureFormat> formatList = new ArrayList<CaptureFormat>();
79 try { 79 try {
80 int minFps = 0; 80 int minFps = 0;
81 int maxFps = 0; 81 int maxFps = 0;
82 final List<int[]> listFpsRange = parameters.getSupportedPreviewFpsRange(); 82 final List<int[]> listFpsRange = parameters.getSupportedPreviewFpsRange();
83 if (listFpsRange != null) { 83 if (listFpsRange != null) {
84 // getSupportedPreviewFpsRange() returns a sorted list. Take the fps ran ge 84 // getSupportedPreviewFpsRange() returns a sorted list. Take the fps ran ge
85 // corresponding to the highest fps. 85 // corresponding to the highest fps.
86 final int[] range = listFpsRange.get(listFpsRange.size() - 1); 86 final int[] range = listFpsRange.get(listFpsRange.size() - 1);
87 minFps = range[Camera.Parameters.PREVIEW_FPS_MIN_INDEX]; 87 minFps = range[Camera.Parameters.PREVIEW_FPS_MIN_INDEX];
88 maxFps = range[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]; 88 maxFps = range[Camera.Parameters.PREVIEW_FPS_MAX_INDEX];
89 } 89 }
90 for (Camera.Size size : parameters.getSupportedPreviewSizes()) { 90 for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
91 formatList.add(new CaptureFormat(size.width, size.height, minFps, maxFps )); 91 formatList.add(new CaptureFormat(size.width, size.height, minFps, maxFps ));
92 } 92 }
93 } catch (Exception e) { 93 } catch (Exception e) {
94 Log.e(TAG, "getSupportedFormats() failed on camera index " + cameraId, e); 94 Logging.e(TAG, "getSupportedFormats() failed on camera index " + cameraId, e);
95 } 95 }
96 96
97 final long endTimeMs = SystemClock.elapsedRealtime(); 97 final long endTimeMs = SystemClock.elapsedRealtime();
98 Log.d(TAG, "Get supported formats for camera index " + cameraId + " done." 98 Logging.d(TAG, "Get supported formats for camera index " + cameraId + " done ."
99 + " Time spent: " + (endTimeMs - startTimeMs) + " ms."); 99 + " Time spent: " + (endTimeMs - startTimeMs) + " ms.");
100 return formatList; 100 return formatList;
101 } 101 }
102 } 102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698