OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 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 |
(...skipping 15 matching lines...) Expand all Loading... |
26 // At construction, storeAudioParameters() is called and it retrieves | 26 // At construction, storeAudioParameters() is called and it retrieves |
27 // fundamental audio parameters like native sample rate and number of channels. | 27 // fundamental audio parameters like native sample rate and number of channels. |
28 // The result is then provided to the caller by nativeCacheAudioParameters(). | 28 // The result is then provided to the caller by nativeCacheAudioParameters(). |
29 // It is also possible to call init() to set up the audio environment for best | 29 // It is also possible to call init() to set up the audio environment for best |
30 // possible "VoIP performance". All settings done in init() are reverted by | 30 // possible "VoIP performance". All settings done in init() are reverted by |
31 // dispose(). This class can also be used without calling init() if the user | 31 // dispose(). This class can also be used without calling init() if the user |
32 // prefers to set up the audio environment separately. However, it is | 32 // prefers to set up the audio environment separately. However, it is |
33 // recommended to always use AudioManager.MODE_IN_COMMUNICATION. | 33 // recommended to always use AudioManager.MODE_IN_COMMUNICATION. |
34 // This class also adds support for output volume control of the | 34 // This class also adds support for output volume control of the |
35 // STREAM_VOICE_CALL-type stream. | 35 // STREAM_VOICE_CALL-type stream. |
36 class WebRtcAudioManager { | 36 public class WebRtcAudioManager { |
37 private static final boolean DEBUG = false; | 37 private static final boolean DEBUG = false; |
38 | 38 |
39 private static final String TAG = "WebRtcAudioManager"; | 39 private static final String TAG = "WebRtcAudioManager"; |
40 | 40 |
| 41 private static boolean blacklistDeviceForOpenSLESUsage = false; |
| 42 private static boolean blacklistDeviceForOpenSLESUsageIsOverridden = false; |
| 43 |
| 44 // Call this method to override the deault list of blacklisted devices |
| 45 // specified in WebRtcAudioUtils.BLACKLISTED_OPEN_SL_ES_MODELS. |
| 46 // Allows an app to take control over which devices to exlude from using |
| 47 // the OpenSL ES audio output path |
| 48 public static synchronized void setBlacklistDeviceForOpenSLESUsage( |
| 49 boolean enable) { |
| 50 blacklistDeviceForOpenSLESUsageIsOverridden = true; |
| 51 blacklistDeviceForOpenSLESUsage = enable; |
| 52 } |
| 53 |
41 // Default audio data format is PCM 16 bit per sample. | 54 // Default audio data format is PCM 16 bit per sample. |
42 // Guaranteed to be supported by all devices. | 55 // Guaranteed to be supported by all devices. |
43 private static final int BITS_PER_SAMPLE = 16; | 56 private static final int BITS_PER_SAMPLE = 16; |
44 | 57 |
45 private static final int DEFAULT_FRAME_PER_BUFFER = 256; | 58 private static final int DEFAULT_FRAME_PER_BUFFER = 256; |
46 | 59 |
47 // TODO(henrika): add stereo support for playout. | 60 // TODO(henrika): add stereo support for playout. |
48 private static final int CHANNELS = 1; | 61 private static final int CHANNELS = 1; |
49 | 62 |
50 // List of possible audio modes. | 63 // List of possible audio modes. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 if (!initialized) { | 116 if (!initialized) { |
104 return; | 117 return; |
105 } | 118 } |
106 } | 119 } |
107 | 120 |
108 private boolean isCommunicationModeEnabled() { | 121 private boolean isCommunicationModeEnabled() { |
109 return (audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION); | 122 return (audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION); |
110 } | 123 } |
111 | 124 |
112 private boolean isDeviceBlacklistedForOpenSLESUsage() { | 125 private boolean isDeviceBlacklistedForOpenSLESUsage() { |
113 boolean blacklisted = | 126 boolean blacklisted = blacklistDeviceForOpenSLESUsageIsOverridden ? |
| 127 blacklistDeviceForOpenSLESUsage : |
114 WebRtcAudioUtils.deviceIsBlacklistedForOpenSLESUsage(); | 128 WebRtcAudioUtils.deviceIsBlacklistedForOpenSLESUsage(); |
115 if (blacklisted) { | 129 if (blacklisted) { |
116 Logging.e(TAG, Build.MODEL + " is blacklisted for OpenSL ES usage!"); | 130 Logging.e(TAG, Build.MODEL + " is blacklisted for OpenSL ES usage!"); |
117 } | 131 } |
118 return blacklisted; | 132 return blacklisted; |
119 } | 133 } |
120 | 134 |
121 private void storeAudioParameters() { | 135 private void storeAudioParameters() { |
122 // Only mono is supported currently (in both directions). | 136 // Only mono is supported currently (in both directions). |
123 // TODO(henrika): add support for stereo playout. | 137 // TODO(henrika): add support for stereo playout. |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 if (!condition) { | 276 if (!condition) { |
263 throw new AssertionError("Expected condition to be true"); | 277 throw new AssertionError("Expected condition to be true"); |
264 } | 278 } |
265 } | 279 } |
266 | 280 |
267 private native void nativeCacheAudioParameters( | 281 private native void nativeCacheAudioParameters( |
268 int sampleRate, int channels, boolean hardwareAEC, boolean hardwareAGC, | 282 int sampleRate, int channels, boolean hardwareAEC, boolean hardwareAGC, |
269 boolean hardwareNS, boolean lowLatencyOutput, int outputBufferSize, | 283 boolean hardwareNS, boolean lowLatencyOutput, int outputBufferSize, |
270 int inputBufferSize, long nativeAudioManager); | 284 int inputBufferSize, long nativeAudioManager); |
271 } | 285 } |
OLD | NEW |