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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 package org.webrtc; | 28 package org.webrtc; |
29 | 29 |
30 import android.content.Context; | 30 import android.content.Context; |
31 import android.graphics.ImageFormat; | 31 import android.graphics.ImageFormat; |
32 import android.hardware.camera2.CameraCharacteristics; | 32 import android.hardware.camera2.CameraCharacteristics; |
33 import android.hardware.camera2.CameraManager; | 33 import android.hardware.camera2.CameraManager; |
34 import android.hardware.camera2.params.StreamConfigurationMap; | 34 import android.hardware.camera2.params.StreamConfigurationMap; |
35 import android.os.Build; | 35 import android.os.Build; |
36 import android.os.SystemClock; | 36 import android.os.SystemClock; |
37 import android.util.Log; | |
38 import android.util.Range; | 37 import android.util.Range; |
39 import android.util.Size; | 38 import android.util.Size; |
40 | 39 |
41 import org.webrtc.CameraEnumerationAndroid.CaptureFormat; | 40 import org.webrtc.CameraEnumerationAndroid.CaptureFormat; |
| 41 import org.webrtc.Logging; |
42 | 42 |
43 import java.util.ArrayList; | 43 import java.util.ArrayList; |
44 import java.util.HashMap; | 44 import java.util.HashMap; |
45 import java.util.List; | 45 import java.util.List; |
46 import java.util.Map; | 46 import java.util.Map; |
47 | 47 |
48 public class Camera2Enumerator implements CameraEnumerationAndroid.Enumerator { | 48 public class Camera2Enumerator implements CameraEnumerationAndroid.Enumerator { |
49 private final static String TAG = "Camera2Enumerator"; | 49 private final static String TAG = "Camera2Enumerator"; |
50 private final static double NANO_SECONDS_PER_SECOND = 1.0e9; | 50 private final static double NANO_SECONDS_PER_SECOND = 1.0e9; |
51 | 51 |
(...skipping 10 matching lines...) Expand all Loading... |
62 public Camera2Enumerator(Context context) { | 62 public Camera2Enumerator(Context context) { |
63 cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERV
ICE); | 63 cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERV
ICE); |
64 } | 64 } |
65 | 65 |
66 @Override | 66 @Override |
67 public List<CaptureFormat> getSupportedFormats(int cameraId) { | 67 public List<CaptureFormat> getSupportedFormats(int cameraId) { |
68 synchronized (cachedSupportedFormats) { | 68 synchronized (cachedSupportedFormats) { |
69 if (cachedSupportedFormats.containsKey(cameraId)) { | 69 if (cachedSupportedFormats.containsKey(cameraId)) { |
70 return cachedSupportedFormats.get(cameraId); | 70 return cachedSupportedFormats.get(cameraId); |
71 } | 71 } |
72 Log.d(TAG, "Get supported formats for camera index " + cameraId + "."); | 72 Logging.d(TAG, "Get supported formats for camera index " + cameraId + ".")
; |
73 final long startTimeMs = SystemClock.elapsedRealtime(); | 73 final long startTimeMs = SystemClock.elapsedRealtime(); |
74 | 74 |
75 final CameraCharacteristics cameraCharacteristics; | 75 final CameraCharacteristics cameraCharacteristics; |
76 try { | 76 try { |
77 cameraCharacteristics = cameraManager.getCameraCharacteristics(Integer.t
oString(cameraId)); | 77 cameraCharacteristics = cameraManager.getCameraCharacteristics(Integer.t
oString(cameraId)); |
78 } catch (Exception ex) { | 78 } catch (Exception ex) { |
79 Log.e(TAG, "getCameraCharacteristics(): " + ex); | 79 Logging.e(TAG, "getCameraCharacteristics(): " + ex); |
80 return new ArrayList<CaptureFormat>(); | 80 return new ArrayList<CaptureFormat>(); |
81 } | 81 } |
82 | 82 |
83 // Calculate default max fps from auto-exposure ranges in case getOutputMi
nFrameDuration() is | 83 // Calculate default max fps from auto-exposure ranges in case getOutputMi
nFrameDuration() is |
84 // not supported. | 84 // not supported. |
85 final Range<Integer>[] fpsRanges = | 85 final Range<Integer>[] fpsRanges = |
86 cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_T
ARGET_FPS_RANGES); | 86 cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_T
ARGET_FPS_RANGES); |
87 int defaultMaxFps = 0; | 87 int defaultMaxFps = 0; |
88 for (Range<Integer> fpsRange : fpsRanges) { | 88 for (Range<Integer> fpsRange : fpsRanges) { |
89 defaultMaxFps = Math.max(defaultMaxFps, fpsRange.getUpper()); | 89 defaultMaxFps = Math.max(defaultMaxFps, fpsRange.getUpper()); |
(...skipping 14 matching lines...) Expand all Loading... |
104 } catch (Exception e) { | 104 } catch (Exception e) { |
105 // getOutputMinFrameDuration() is not supported on all devices. Ignore
silently. | 105 // getOutputMinFrameDuration() is not supported on all devices. Ignore
silently. |
106 } | 106 } |
107 final int maxFps = (minFrameDurationNs == 0) | 107 final int maxFps = (minFrameDurationNs == 0) |
108 ? defaultMaxFps | 108 ? defaultMaxFps |
109 : (int) Math.round(NANO_SECONDS_PER_SECOND / minF
rameDurationNs); | 109 : (int) Math.round(NANO_SECONDS_PER_SECOND / minF
rameDurationNs); |
110 formatList.add(new CaptureFormat(size.getWidth(), size.getHeight(), 0, m
axFps * 1000)); | 110 formatList.add(new CaptureFormat(size.getWidth(), size.getHeight(), 0, m
axFps * 1000)); |
111 } | 111 } |
112 cachedSupportedFormats.put(cameraId, formatList); | 112 cachedSupportedFormats.put(cameraId, formatList); |
113 final long endTimeMs = SystemClock.elapsedRealtime(); | 113 final long endTimeMs = SystemClock.elapsedRealtime(); |
114 Log.d(TAG, "Get supported formats for camera index " + cameraId + " done." | 114 Logging.d(TAG, "Get supported formats for camera index " + cameraId + " do
ne." |
115 + " Time spent: " + (endTimeMs - startTimeMs) + " ms."); | 115 + " Time spent: " + (endTimeMs - startTimeMs) + " ms."); |
116 return formatList; | 116 return formatList; |
117 } | 117 } |
118 } | 118 } |
119 } | 119 } |
OLD | NEW |