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

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

Issue 1343163003: Partial revert of r9936. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@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 static java.lang.Math.abs; 30 import static java.lang.Math.abs;
31 import static java.lang.Math.ceil; 31 import static java.lang.Math.ceil;
32
33 import android.hardware.Camera; 32 import android.hardware.Camera;
33 import android.util.Log;
34 import android.graphics.ImageFormat; 34 import android.graphics.ImageFormat;
35 35
36 import org.json.JSONArray; 36 import org.json.JSONArray;
37 import org.json.JSONException; 37 import org.json.JSONException;
38 import org.json.JSONObject; 38 import org.json.JSONObject;
39 39
40 import org.webrtc.Logging;
41
42 import java.util.ArrayList;
43 import java.util.Collections; 40 import java.util.Collections;
44 import java.util.Comparator; 41 import java.util.Comparator;
45 import java.util.List; 42 import java.util.List;
46 43
47 @SuppressWarnings("deprecation") 44 @SuppressWarnings("deprecation")
48 public class CameraEnumerationAndroid { 45 public class CameraEnumerationAndroid {
49 private final static String TAG = "CameraEnumerationAndroid"; 46 private final static String TAG = "CameraEnumerationAndroid";
50 // Synchronized on |CameraEnumerationAndroid.this|. 47 // Synchronized on |CameraEnumerationAndroid.this|.
51 private static Enumerator enumerator = new CameraEnumerator(); 48 private static Enumerator enumerator = new CameraEnumerator();
52 49
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 return Camera.getNumberOfCameras(); 138 return Camera.getNumberOfCameras();
142 } 139 }
143 140
144 // Returns the name of the camera with camera index. Returns null if the 141 // Returns the name of the camera with camera index. Returns null if the
145 // camera can not be used. 142 // camera can not be used.
146 public static String getDeviceName(int index) { 143 public static String getDeviceName(int index) {
147 Camera.CameraInfo info = new Camera.CameraInfo(); 144 Camera.CameraInfo info = new Camera.CameraInfo();
148 try { 145 try {
149 Camera.getCameraInfo(index, info); 146 Camera.getCameraInfo(index, info);
150 } catch (Exception e) { 147 } catch (Exception e) {
151 Logging.e(TAG, "getCameraInfo failed on index " + index,e); 148 Log.e(TAG, "getCameraInfo failed on index " + index,e);
152 return null; 149 return null;
153 } 150 }
154 151
155 String facing = 152 String facing =
156 (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) ? "front" : "back "; 153 (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) ? "front" : "back ";
157 return "Camera " + index + ", Facing " + facing 154 return "Camera " + index + ", Facing " + facing
158 + ", Orientation " + info.orientation; 155 + ", Orientation " + info.orientation;
159 } 156 }
160 157
161 // Returns the name of the front facing camera. Returns null if the 158 // Returns the name of the front facing camera. Returns null if the
(...skipping 11 matching lines...) Expand all
173 public static String getSupportedFormatsAsJson(int id) throws JSONException { 170 public static String getSupportedFormatsAsJson(int id) throws JSONException {
174 List<CaptureFormat> formats = getSupportedFormats(id); 171 List<CaptureFormat> formats = getSupportedFormats(id);
175 JSONArray json_formats = new JSONArray(); 172 JSONArray json_formats = new JSONArray();
176 for (CaptureFormat format : formats) { 173 for (CaptureFormat format : formats) {
177 JSONObject json_format = new JSONObject(); 174 JSONObject json_format = new JSONObject();
178 json_format.put("width", format.width); 175 json_format.put("width", format.width);
179 json_format.put("height", format.height); 176 json_format.put("height", format.height);
180 json_format.put("framerate", (format.maxFramerate + 999) / 1000); 177 json_format.put("framerate", (format.maxFramerate + 999) / 1000);
181 json_formats.put(json_format); 178 json_formats.put(json_format);
182 } 179 }
183 Logging.d(TAG, "Supported formats for camera " + id + ": " 180 Log.d(TAG, "Supported formats for camera " + id + ": "
184 + json_formats.toString(2)); 181 + json_formats.toString(2));
185 return json_formats.toString(); 182 return json_formats.toString();
186 } 183 }
187 184
188 // Helper class for finding the closest supported format for the two functions below. 185 // Helper class for finding the closest supported format for the two functions below.
189 private static abstract class ClosestComparator<T> implements Comparator<T> { 186 private static abstract class ClosestComparator<T> implements Comparator<T> {
190 // Difference between supported and requested parameter. 187 // Difference between supported and requested parameter.
191 abstract int diff(T supportedParameter); 188 abstract int diff(T supportedParameter);
192 189
193 @Override 190 @Override
194 public int compare(T t1, T t2) { 191 public int compare(T t1, T t2) {
195 return diff(t1) - diff(t2); 192 return diff(t1) - diff(t2);
196 } 193 }
197 } 194 }
198 195
199 public static int[] getFramerateRange(Camera.Parameters parameters, final int framerate) { 196 public static int[] getFramerateRange(Camera.Parameters parameters, final int framerate) {
200 List<int[]> listFpsRange = parameters.getSupportedPreviewFpsRange(); 197 List<int[]> listFpsRange = parameters.getSupportedPreviewFpsRange();
201 if (listFpsRange.isEmpty()) { 198 if (listFpsRange.isEmpty()) {
202 Logging.w(TAG, "No supported preview fps range"); 199 Log.w(TAG, "No supported preview fps range");
203 return new int[]{0, 0}; 200 return new int[]{0, 0};
204 } 201 }
205 return Collections.min(listFpsRange, 202 return Collections.min(listFpsRange,
206 new ClosestComparator<int[]>() { 203 new ClosestComparator<int[]>() {
207 @Override int diff(int[] range) { 204 @Override int diff(int[] range) {
208 return abs(framerate - range[Camera.Parameters.PREVIEW_FPS_MIN_INDEX ]) 205 return abs(framerate - range[Camera.Parameters.PREVIEW_FPS_MIN_INDEX ])
209 + abs(framerate - range[Camera.Parameters.PREVIEW_FPS_MAX_INDEX] ); 206 + abs(framerate - range[Camera.Parameters.PREVIEW_FPS_MAX_INDEX] );
210 } 207 }
211 }); 208 });
212 } 209 }
(...skipping 10 matching lines...) Expand all
223 220
224 private static String getNameOfDevice(int facing) { 221 private static String getNameOfDevice(int facing) {
225 final Camera.CameraInfo info = new Camera.CameraInfo(); 222 final Camera.CameraInfo info = new Camera.CameraInfo();
226 for (int i = 0; i < Camera.getNumberOfCameras(); ++i) { 223 for (int i = 0; i < Camera.getNumberOfCameras(); ++i) {
227 try { 224 try {
228 Camera.getCameraInfo(i, info); 225 Camera.getCameraInfo(i, info);
229 if (info.facing == facing) { 226 if (info.facing == facing) {
230 return getDeviceName(i); 227 return getDeviceName(i);
231 } 228 }
232 } catch (Exception e) { 229 } catch (Exception e) {
233 Logging.e(TAG, "getCameraInfo() failed on index " + i, e); 230 Log.e(TAG, "getCameraInfo() failed on index " + i, e);
234 } 231 }
235 } 232 }
236 return null; 233 return null;
237 } 234 }
238 } 235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698