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

Side by Side Diff: webrtc/modules/audio_device/android/audio_manager.cc

Issue 2019223004: Moves ownership of OpenSL engine object to Android audio manager (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Feedback from magjed@ Created 4 years, 6 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 * 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 ALOGD("~dtor%s", GetThreadInfo().c_str()); 94 ALOGD("~dtor%s", GetThreadInfo().c_str());
95 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 95 RTC_DCHECK(thread_checker_.CalledOnValidThread());
96 Close(); 96 Close();
97 } 97 }
98 98
99 void AudioManager::SetActiveAudioLayer( 99 void AudioManager::SetActiveAudioLayer(
100 AudioDeviceModule::AudioLayer audio_layer) { 100 AudioDeviceModule::AudioLayer audio_layer) {
101 ALOGD("SetActiveAudioLayer(%d)%s", audio_layer, GetThreadInfo().c_str()); 101 ALOGD("SetActiveAudioLayer(%d)%s", audio_layer, GetThreadInfo().c_str());
102 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 102 RTC_DCHECK(thread_checker_.CalledOnValidThread());
103 RTC_DCHECK(!initialized_); 103 RTC_DCHECK(!initialized_);
104 // Store the currenttly utilized audio layer. 104 // Store the currently utilized audio layer.
105 audio_layer_ = audio_layer; 105 audio_layer_ = audio_layer;
106 // The delay estimate can take one of two fixed values depending on if the 106 // The delay estimate can take one of two fixed values depending on if the
107 // device supports low-latency output or not. However, it is also possible 107 // device supports low-latency output or not. However, it is also possible
108 // that the user explicitly selects the high-latency audio path, hence we use 108 // that the user explicitly selects the high-latency audio path, hence we use
109 // the selected |audio_layer| here to set the delay estimate. 109 // the selected |audio_layer| here to set the delay estimate.
110 delay_estimate_in_milliseconds_ = 110 delay_estimate_in_milliseconds_ =
111 (audio_layer == AudioDeviceModule::kAndroidJavaAudio) ? 111 (audio_layer == AudioDeviceModule::kAndroidJavaAudio) ?
112 kHighLatencyModeDelayEstimateInMilliseconds : 112 kHighLatencyModeDelayEstimateInMilliseconds :
113 kLowLatencyModeDelayEstimateInMilliseconds; 113 kLowLatencyModeDelayEstimateInMilliseconds;
114 ALOGD("delay_estimate_in_milliseconds: %d", delay_estimate_in_milliseconds_); 114 ALOGD("delay_estimate_in_milliseconds: %d", delay_estimate_in_milliseconds_);
115 } 115 }
116 116
117 SLObjectItf AudioManager::GetOpenSLEngine() {
118 ALOGD("GetOpenSLEngine%s", GetThreadInfo().c_str());
119 RTC_DCHECK(thread_checker_.CalledOnValidThread());
120 // Only allow usage of OpenSL ES if such an audio layer has been specified.
121 if (audio_layer_ != AudioDeviceModule::kAndroidOpenSLESAudio &&
122 audio_layer_ !=
123 AudioDeviceModule::kAndroidJavaInputAndOpenSLESOutputAudio) {
124 ALOGI("Unable to create OpenSL engine for the current audio layer: %d",
125 audio_layer_);
126 return nullptr;
127 }
128 // OpenSL ES for Android only supports a single engine per application.
129 // If one already has been created, return existing object instead of
130 // creating a new.
131 if (engine_object_.Get() != nullptr) {
132 ALOGI("The OpenSL ES engine object has already been created");
133 return engine_object_.Get();
134 }
135 // Create the engine object in thread safe mode.
136 const SLEngineOption option[] = {
137 {SL_ENGINEOPTION_THREADSAFE, static_cast<SLuint32>(SL_BOOLEAN_TRUE)}};
138 SLresult result =
139 slCreateEngine(engine_object_.Receive(), 1, option, 0, NULL, NULL);
140 if (result != SL_RESULT_SUCCESS) {
141 ALOGE("slCreateEngine() failed: %s", GetSLErrorString(result));
142 engine_object_.Reset();
143 return nullptr;
144 }
145 // Realize the SL Engine in synchronous mode.
146 result = engine_object_->Realize(engine_object_.Get(), SL_BOOLEAN_FALSE);
147 if (result != SL_RESULT_SUCCESS) {
148 ALOGE("Realize() failed: %s", GetSLErrorString(result));
149 engine_object_.Reset();
150 return nullptr;
151 }
152 // Finally return the SLObjectItf interface of the engine object.
153 return engine_object_.Get();
154 }
155
117 bool AudioManager::Init() { 156 bool AudioManager::Init() {
118 ALOGD("Init%s", GetThreadInfo().c_str()); 157 ALOGD("Init%s", GetThreadInfo().c_str());
119 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 158 RTC_DCHECK(thread_checker_.CalledOnValidThread());
120 RTC_DCHECK(!initialized_); 159 RTC_DCHECK(!initialized_);
121 RTC_DCHECK_NE(audio_layer_, AudioDeviceModule::kPlatformDefaultAudio); 160 RTC_DCHECK_NE(audio_layer_, AudioDeviceModule::kPlatformDefaultAudio);
122 if (!j_audio_manager_->Init()) { 161 if (!j_audio_manager_->Init()) {
123 ALOGE("init failed!"); 162 ALOGE("init failed!");
124 return false; 163 return false;
125 } 164 }
126 initialized_ = true; 165 initialized_ = true;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 return playout_parameters_; 277 return playout_parameters_;
239 } 278 }
240 279
241 const AudioParameters& AudioManager::GetRecordAudioParameters() { 280 const AudioParameters& AudioManager::GetRecordAudioParameters() {
242 RTC_CHECK(record_parameters_.is_valid()); 281 RTC_CHECK(record_parameters_.is_valid());
243 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 282 RTC_DCHECK(thread_checker_.CalledOnValidThread());
244 return record_parameters_; 283 return record_parameters_;
245 } 284 }
246 285
247 } // namespace webrtc 286 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_device/android/audio_manager.h ('k') | webrtc/modules/audio_device/android/audio_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698