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