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

Side by Side Diff: media/audio/audio_manager_base.cc

Issue 12974004: Add speaker on/off control on Android for WebRTC (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: remove log Created 7 years, 9 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/audio/audio_manager_base.h" 5 #include "media/audio/audio_manager_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 #endif 56 #endif
57 #if defined(OS_MACOSX) 57 #if defined(OS_MACOSX)
58 // On Mac, use a UI loop to get native message pump so that CoreAudio property 58 // On Mac, use a UI loop to get native message pump so that CoreAudio property
59 // listener callbacks fire. 59 // listener callbacks fire.
60 CHECK(audio_thread_->StartWithOptions( 60 CHECK(audio_thread_->StartWithOptions(
61 base::Thread::Options(MessageLoop::TYPE_UI, 0))); 61 base::Thread::Options(MessageLoop::TYPE_UI, 0)));
62 #else 62 #else
63 CHECK(audio_thread_->Start()); 63 CHECK(audio_thread_->Start());
64 #endif 64 #endif
65 message_loop_ = audio_thread_->message_loop_proxy(); 65 message_loop_ = audio_thread_->message_loop_proxy();
66
67 #if defined(OS_ANDROID)
68 JNIEnv* env = base::android::AttachCurrentThread();
69 jobject context = base::android::GetApplicationContext();
70 j_audio_manager_.Reset(
71 Java_AudioManagerAndroid_createAudioManagerAndroid(env, context));
72 #endif
66 } 73 }
67 74
68 AudioManagerBase::~AudioManagerBase() { 75 AudioManagerBase::~AudioManagerBase() {
69 // The platform specific AudioManager implementation must have already 76 // The platform specific AudioManager implementation must have already
70 // stopped the audio thread. Otherwise, we may destroy audio streams before 77 // stopped the audio thread. Otherwise, we may destroy audio streams before
71 // stopping the thread, resulting an unexpected behavior. 78 // stopping the thread, resulting an unexpected behavior.
72 // This way we make sure activities of the audio streams are all stopped 79 // This way we make sure activities of the audio streams are all stopped
73 // before we destroy them. 80 // before we destroy them.
74 CHECK(!audio_thread_.get()); 81 CHECK(!audio_thread_.get());
75 // All the output streams should have been deleted. 82 // All the output streams should have been deleted.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 stream = MakeLowLatencyOutputStream(params); 125 stream = MakeLowLatencyOutputStream(params);
119 break; 126 break;
120 case AudioParameters::AUDIO_FAKE: 127 case AudioParameters::AUDIO_FAKE:
121 stream = FakeAudioOutputStream::MakeFakeStream(this, params); 128 stream = FakeAudioOutputStream::MakeFakeStream(this, params);
122 break; 129 break;
123 default: 130 default:
124 stream = NULL; 131 stream = NULL;
125 break; 132 break;
126 } 133 }
127 134
128 if (stream) 135 if (stream) {
129 ++num_output_streams_; 136 ++num_output_streams_;
137 #if defined(OS_ANDROID)
138 if (num_output_streams_ == 1)
139 RegisterHeadsetReceiver();
140 #endif
141 }
130 142
131 return stream; 143 return stream;
132 } 144 }
133 145
134 AudioInputStream* AudioManagerBase::MakeAudioInputStream( 146 AudioInputStream* AudioManagerBase::MakeAudioInputStream(
135 const AudioParameters& params, const std::string& device_id) { 147 const AudioParameters& params, const std::string& device_id) {
136 // TODO(miu): Fix ~20 call points across several unit test modules to call 148 // TODO(miu): Fix ~20 call points across several unit test modules to call
137 // this method on the audio thread, then uncomment the following: 149 // this method on the audio thread, then uncomment the following:
138 // DCHECK(message_loop_->BelongsToCurrentThread()); 150 // DCHECK(message_loop_->BelongsToCurrentThread());
139 151
(...skipping 19 matching lines...) Expand all
159 stream = MakeLowLatencyInputStream(params, device_id); 171 stream = MakeLowLatencyInputStream(params, device_id);
160 break; 172 break;
161 case AudioParameters::AUDIO_FAKE: 173 case AudioParameters::AUDIO_FAKE:
162 stream = FakeAudioInputStream::MakeFakeStream(this, params); 174 stream = FakeAudioInputStream::MakeFakeStream(this, params);
163 break; 175 break;
164 default: 176 default:
165 stream = NULL; 177 stream = NULL;
166 break; 178 break;
167 } 179 }
168 180
169 if (stream) 181 if (stream) {
170 ++num_input_streams_; 182 ++num_input_streams_;
171
172 #if defined(OS_ANDROID) 183 #if defined(OS_ANDROID)
173 if (num_input_streams_ == 1) 184 if (num_input_streams_ == 1)
174 SetAudioMode(kAudioModeInCommunication); 185 SetAudioMode(kAudioModeInCommunication);
175 #endif 186 #endif
187 }
176 188
177 return stream; 189 return stream;
178 } 190 }
179 191
180 AudioOutputStream* AudioManagerBase::MakeAudioOutputStreamProxy( 192 AudioOutputStream* AudioManagerBase::MakeAudioOutputStreamProxy(
181 const AudioParameters& params) { 193 const AudioParameters& params) {
182 #if defined(OS_IOS) 194 #if defined(OS_IOS)
183 // IOS implements audio input only. 195 // IOS implements audio input only.
184 NOTIMPLEMENTED(); 196 NOTIMPLEMENTED();
185 return NULL; 197 return NULL;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 media::AudioDeviceNames* device_names) { 261 media::AudioDeviceNames* device_names) {
250 } 262 }
251 263
252 void AudioManagerBase::ReleaseOutputStream(AudioOutputStream* stream) { 264 void AudioManagerBase::ReleaseOutputStream(AudioOutputStream* stream) {
253 DCHECK(stream); 265 DCHECK(stream);
254 // TODO(xians) : Have a clearer destruction path for the AudioOutputStream. 266 // TODO(xians) : Have a clearer destruction path for the AudioOutputStream.
255 // For example, pass the ownership to AudioManager so it can delete the 267 // For example, pass the ownership to AudioManager so it can delete the
256 // streams. 268 // streams.
257 --num_output_streams_; 269 --num_output_streams_;
258 delete stream; 270 delete stream;
271 #if defined(OS_ANDROID)
272 if (!num_output_streams_)
273 UnregisterHeadsetReceiver();
274 #endif
259 } 275 }
260 276
261 void AudioManagerBase::ReleaseInputStream(AudioInputStream* stream) { 277 void AudioManagerBase::ReleaseInputStream(AudioInputStream* stream) {
262 DCHECK(stream); 278 DCHECK(stream);
263 // TODO(xians) : Have a clearer destruction path for the AudioInputStream. 279 // TODO(xians) : Have a clearer destruction path for the AudioInputStream.
264 --num_input_streams_; 280 --num_input_streams_;
265 delete stream; 281 delete stream;
266 #if defined(OS_ANDROID) 282 #if defined(OS_ANDROID)
267 if (!num_input_streams_) 283 if (!num_input_streams_)
268 SetAudioMode(kAudioModeNormal); 284 SetAudioMode(kAudioModeNormal);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 } 380 }
365 381
366 AudioParameters AudioManagerBase::GetInputStreamParameters( 382 AudioParameters AudioManagerBase::GetInputStreamParameters(
367 const std::string& device_id) { 383 const std::string& device_id) {
368 NOTREACHED(); 384 NOTREACHED();
369 return AudioParameters(); 385 return AudioParameters();
370 } 386 }
371 387
372 #if defined(OS_ANDROID) 388 #if defined(OS_ANDROID)
373 void AudioManagerBase::SetAudioMode(int mode) { 389 void AudioManagerBase::SetAudioMode(int mode) {
374 JNIEnv* env = base::android::AttachCurrentThread(); 390 Java_AudioManagerAndroid_setMode(
375 jobject context = base::android::GetApplicationContext(); 391 base::android::AttachCurrentThread(),
376 DCHECK(context); 392 j_audio_manager_.obj(), mode);
393 }
377 394
378 Java_AudioManagerAndroid_setMode(env, context, mode); 395 void AudioManagerBase::RegisterHeadsetReceiver() {
396 Java_AudioManagerAndroid_registerHeadsetReceiver(
397 base::android::AttachCurrentThread(),
398 j_audio_manager_.obj());
379 } 399 }
380 #endif 400
401 void AudioManagerBase::UnregisterHeadsetReceiver() {
402 Java_AudioManagerAndroid_unregisterHeadsetReceiver(
403 base::android::AttachCurrentThread(),
404 j_audio_manager_.obj());
405 }
406 #endif // defined(OS_ANDROID)
381 407
382 } // namespace media 408 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_manager_base.h ('k') | media/base/android/java/src/org/chromium/media/AudioManagerAndroid.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698