| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 // AudioManager implementation | 65 // AudioManager implementation |
| 66 AudioManager::AudioManager() | 66 AudioManager::AudioManager() |
| 67 : j_environment_(JVM::GetInstance()->environment()), | 67 : j_environment_(JVM::GetInstance()->environment()), |
| 68 audio_layer_(AudioDeviceModule::kPlatformDefaultAudio), | 68 audio_layer_(AudioDeviceModule::kPlatformDefaultAudio), |
| 69 initialized_(false), | 69 initialized_(false), |
| 70 hardware_aec_(false), | 70 hardware_aec_(false), |
| 71 low_latency_playout_(false), | 71 low_latency_playout_(false), |
| 72 delay_estimate_in_milliseconds_(0) { | 72 delay_estimate_in_milliseconds_(0) { |
| 73 ALOGD("ctor%s", GetThreadInfo().c_str()); | 73 ALOGD("ctor%s", GetThreadInfo().c_str()); |
| 74 CHECK(j_environment_); | 74 RTC_CHECK(j_environment_); |
| 75 JNINativeMethod native_methods[] = { | 75 JNINativeMethod native_methods[] = { |
| 76 {"nativeCacheAudioParameters", | 76 {"nativeCacheAudioParameters", |
| 77 "(IIZZIIJ)V", | 77 "(IIZZIIJ)V", |
| 78 reinterpret_cast<void*>(&webrtc::AudioManager::CacheAudioParameters)}}; | 78 reinterpret_cast<void*>(&webrtc::AudioManager::CacheAudioParameters)}}; |
| 79 j_native_registration_ = j_environment_->RegisterNatives( | 79 j_native_registration_ = j_environment_->RegisterNatives( |
| 80 "org/webrtc/voiceengine/WebRtcAudioManager", | 80 "org/webrtc/voiceengine/WebRtcAudioManager", |
| 81 native_methods, arraysize(native_methods)); | 81 native_methods, arraysize(native_methods)); |
| 82 j_audio_manager_.reset(new JavaAudioManager( | 82 j_audio_manager_.reset(new JavaAudioManager( |
| 83 j_native_registration_.get(), | 83 j_native_registration_.get(), |
| 84 j_native_registration_->NewObject( | 84 j_native_registration_->NewObject( |
| 85 "<init>", "(Landroid/content/Context;J)V", | 85 "<init>", "(Landroid/content/Context;J)V", |
| 86 JVM::GetInstance()->context(), PointerTojlong(this)))); | 86 JVM::GetInstance()->context(), PointerTojlong(this)))); |
| 87 } | 87 } |
| 88 | 88 |
| 89 AudioManager::~AudioManager() { | 89 AudioManager::~AudioManager() { |
| 90 ALOGD("~dtor%s", GetThreadInfo().c_str()); | 90 ALOGD("~dtor%s", GetThreadInfo().c_str()); |
| 91 DCHECK(thread_checker_.CalledOnValidThread()); | 91 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 92 Close(); | 92 Close(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void AudioManager::SetActiveAudioLayer( | 95 void AudioManager::SetActiveAudioLayer( |
| 96 AudioDeviceModule::AudioLayer audio_layer) { | 96 AudioDeviceModule::AudioLayer audio_layer) { |
| 97 ALOGD("SetActiveAudioLayer(%d)%s", audio_layer, GetThreadInfo().c_str()); | 97 ALOGD("SetActiveAudioLayer(%d)%s", audio_layer, GetThreadInfo().c_str()); |
| 98 DCHECK(thread_checker_.CalledOnValidThread()); | 98 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 99 DCHECK(!initialized_); | 99 RTC_DCHECK(!initialized_); |
| 100 // Store the currenttly utilized audio layer. | 100 // Store the currenttly utilized audio layer. |
| 101 audio_layer_ = audio_layer; | 101 audio_layer_ = audio_layer; |
| 102 // The delay estimate can take one of two fixed values depending on if the | 102 // The delay estimate can take one of two fixed values depending on if the |
| 103 // device supports low-latency output or not. However, it is also possible | 103 // device supports low-latency output or not. However, it is also possible |
| 104 // that the user explicitly selects the high-latency audio path, hence we use | 104 // that the user explicitly selects the high-latency audio path, hence we use |
| 105 // the selected |audio_layer| here to set the delay estimate. | 105 // the selected |audio_layer| here to set the delay estimate. |
| 106 delay_estimate_in_milliseconds_ = | 106 delay_estimate_in_milliseconds_ = |
| 107 (audio_layer == AudioDeviceModule::kAndroidJavaAudio) ? | 107 (audio_layer == AudioDeviceModule::kAndroidJavaAudio) ? |
| 108 kHighLatencyModeDelayEstimateInMilliseconds : | 108 kHighLatencyModeDelayEstimateInMilliseconds : |
| 109 kLowLatencyModeDelayEstimateInMilliseconds; | 109 kLowLatencyModeDelayEstimateInMilliseconds; |
| 110 ALOGD("delay_estimate_in_milliseconds: %d", delay_estimate_in_milliseconds_); | 110 ALOGD("delay_estimate_in_milliseconds: %d", delay_estimate_in_milliseconds_); |
| 111 } | 111 } |
| 112 | 112 |
| 113 bool AudioManager::Init() { | 113 bool AudioManager::Init() { |
| 114 ALOGD("Init%s", GetThreadInfo().c_str()); | 114 ALOGD("Init%s", GetThreadInfo().c_str()); |
| 115 DCHECK(thread_checker_.CalledOnValidThread()); | 115 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 116 DCHECK(!initialized_); | 116 RTC_DCHECK(!initialized_); |
| 117 DCHECK_NE(audio_layer_, AudioDeviceModule::kPlatformDefaultAudio); | 117 RTC_DCHECK_NE(audio_layer_, AudioDeviceModule::kPlatformDefaultAudio); |
| 118 if (!j_audio_manager_->Init()) { | 118 if (!j_audio_manager_->Init()) { |
| 119 ALOGE("init failed!"); | 119 ALOGE("init failed!"); |
| 120 return false; | 120 return false; |
| 121 } | 121 } |
| 122 initialized_ = true; | 122 initialized_ = true; |
| 123 return true; | 123 return true; |
| 124 } | 124 } |
| 125 | 125 |
| 126 bool AudioManager::Close() { | 126 bool AudioManager::Close() { |
| 127 ALOGD("Close%s", GetThreadInfo().c_str()); | 127 ALOGD("Close%s", GetThreadInfo().c_str()); |
| 128 DCHECK(thread_checker_.CalledOnValidThread()); | 128 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 129 if (!initialized_) | 129 if (!initialized_) |
| 130 return true; | 130 return true; |
| 131 j_audio_manager_->Close(); | 131 j_audio_manager_->Close(); |
| 132 initialized_ = false; | 132 initialized_ = false; |
| 133 return true; | 133 return true; |
| 134 } | 134 } |
| 135 | 135 |
| 136 bool AudioManager::IsCommunicationModeEnabled() const { | 136 bool AudioManager::IsCommunicationModeEnabled() const { |
| 137 ALOGD("IsCommunicationModeEnabled()"); | 137 ALOGD("IsCommunicationModeEnabled()"); |
| 138 DCHECK(thread_checker_.CalledOnValidThread()); | 138 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 139 return j_audio_manager_->IsCommunicationModeEnabled(); | 139 return j_audio_manager_->IsCommunicationModeEnabled(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 bool AudioManager::IsAcousticEchoCancelerSupported() const { | 142 bool AudioManager::IsAcousticEchoCancelerSupported() const { |
| 143 DCHECK(thread_checker_.CalledOnValidThread()); | 143 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 144 return hardware_aec_; | 144 return hardware_aec_; |
| 145 } | 145 } |
| 146 | 146 |
| 147 bool AudioManager::IsLowLatencyPlayoutSupported() const { | 147 bool AudioManager::IsLowLatencyPlayoutSupported() const { |
| 148 DCHECK(thread_checker_.CalledOnValidThread()); | 148 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 149 ALOGD("IsLowLatencyPlayoutSupported()"); | 149 ALOGD("IsLowLatencyPlayoutSupported()"); |
| 150 // Some devices are blacklisted for usage of OpenSL ES even if they report | 150 // Some devices are blacklisted for usage of OpenSL ES even if they report |
| 151 // that low-latency playout is supported. See b/21485703 for details. | 151 // that low-latency playout is supported. See b/21485703 for details. |
| 152 return j_audio_manager_->IsDeviceBlacklistedForOpenSLESUsage() ? | 152 return j_audio_manager_->IsDeviceBlacklistedForOpenSLESUsage() ? |
| 153 false : low_latency_playout_; | 153 false : low_latency_playout_; |
| 154 } | 154 } |
| 155 | 155 |
| 156 int AudioManager::GetDelayEstimateInMilliseconds() const { | 156 int AudioManager::GetDelayEstimateInMilliseconds() const { |
| 157 return delay_estimate_in_milliseconds_; | 157 return delay_estimate_in_milliseconds_; |
| 158 } | 158 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 180 jboolean low_latency_output, | 180 jboolean low_latency_output, |
| 181 jint output_buffer_size, | 181 jint output_buffer_size, |
| 182 jint input_buffer_size) { | 182 jint input_buffer_size) { |
| 183 ALOGD("OnCacheAudioParameters%s", GetThreadInfo().c_str()); | 183 ALOGD("OnCacheAudioParameters%s", GetThreadInfo().c_str()); |
| 184 ALOGD("hardware_aec: %d", hardware_aec); | 184 ALOGD("hardware_aec: %d", hardware_aec); |
| 185 ALOGD("low_latency_output: %d", low_latency_output); | 185 ALOGD("low_latency_output: %d", low_latency_output); |
| 186 ALOGD("sample_rate: %d", sample_rate); | 186 ALOGD("sample_rate: %d", sample_rate); |
| 187 ALOGD("channels: %d", channels); | 187 ALOGD("channels: %d", channels); |
| 188 ALOGD("output_buffer_size: %d", output_buffer_size); | 188 ALOGD("output_buffer_size: %d", output_buffer_size); |
| 189 ALOGD("input_buffer_size: %d", input_buffer_size); | 189 ALOGD("input_buffer_size: %d", input_buffer_size); |
| 190 DCHECK(thread_checker_.CalledOnValidThread()); | 190 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 191 hardware_aec_ = hardware_aec; | 191 hardware_aec_ = hardware_aec; |
| 192 low_latency_playout_ = low_latency_output; | 192 low_latency_playout_ = low_latency_output; |
| 193 // TODO(henrika): add support for stereo output. | 193 // TODO(henrika): add support for stereo output. |
| 194 playout_parameters_.reset(sample_rate, channels, | 194 playout_parameters_.reset(sample_rate, channels, |
| 195 static_cast<size_t>(output_buffer_size)); | 195 static_cast<size_t>(output_buffer_size)); |
| 196 record_parameters_.reset(sample_rate, channels, | 196 record_parameters_.reset(sample_rate, channels, |
| 197 static_cast<size_t>(input_buffer_size)); | 197 static_cast<size_t>(input_buffer_size)); |
| 198 } | 198 } |
| 199 | 199 |
| 200 const AudioParameters& AudioManager::GetPlayoutAudioParameters() { | 200 const AudioParameters& AudioManager::GetPlayoutAudioParameters() { |
| 201 CHECK(playout_parameters_.is_valid()); | 201 RTC_CHECK(playout_parameters_.is_valid()); |
| 202 DCHECK(thread_checker_.CalledOnValidThread()); | 202 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 203 return playout_parameters_; | 203 return playout_parameters_; |
| 204 } | 204 } |
| 205 | 205 |
| 206 const AudioParameters& AudioManager::GetRecordAudioParameters() { | 206 const AudioParameters& AudioManager::GetRecordAudioParameters() { |
| 207 CHECK(record_parameters_.is_valid()); | 207 RTC_CHECK(record_parameters_.is_valid()); |
| 208 DCHECK(thread_checker_.CalledOnValidThread()); | 208 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 209 return record_parameters_; | 209 return record_parameters_; |
| 210 } | 210 } |
| 211 | 211 |
| 212 } // namespace webrtc | 212 } // namespace webrtc |
| OLD | NEW |