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

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

Issue 12571006: Add MODIFY_AUDIO_SETTINGS permission in Android manifest and implementation in audio manager. (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: move SetAudioMode to audio_manager_base 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"
11 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
12 #if defined(OS_ANDROID)
13 #include "jni/AudioManagerAndroid_jni.h"
14 #endif
12 #include "media/audio/audio_output_dispatcher_impl.h" 15 #include "media/audio/audio_output_dispatcher_impl.h"
13 #include "media/audio/audio_output_proxy.h" 16 #include "media/audio/audio_output_proxy.h"
14 #include "media/audio/audio_output_resampler.h" 17 #include "media/audio/audio_output_resampler.h"
15 #include "media/audio/audio_util.h" 18 #include "media/audio/audio_util.h"
16 #include "media/audio/fake_audio_input_stream.h" 19 #include "media/audio/fake_audio_input_stream.h"
17 #include "media/audio/fake_audio_output_stream.h" 20 #include "media/audio/fake_audio_output_stream.h"
18 #include "media/base/media_switches.h" 21 #include "media/base/media_switches.h"
19 22
20 namespace media { 23 namespace media {
21 24
22 static const int kStreamCloseDelaySeconds = 5; 25 static const int kStreamCloseDelaySeconds = 5;
23 26
24 // Default maximum number of output streams that can be open simultaneously 27 // Default maximum number of output streams that can be open simultaneously
25 // for all platforms. 28 // for all platforms.
26 static const int kDefaultMaxOutputStreams = 16; 29 static const int kDefaultMaxOutputStreams = 16;
27 30
28 // Default maximum number of input streams that can be open simultaneously 31 // Default maximum number of input streams that can be open simultaneously
29 // for all platforms. 32 // for all platforms.
30 static const int kDefaultMaxInputStreams = 16; 33 static const int kDefaultMaxInputStreams = 16;
31 34
32 static const int kMaxInputChannels = 2; 35 static const int kMaxInputChannels = 2;
33 36
37 #if defined(OS_ANDROID)
38 static const int kAudioModeNormal = 0x00000000;
39 static const int kAudioModeInCommunication = 0x00000003;
40 #endif
41
34 const char AudioManagerBase::kDefaultDeviceName[] = "Default"; 42 const char AudioManagerBase::kDefaultDeviceName[] = "Default";
35 const char AudioManagerBase::kDefaultDeviceId[] = "default"; 43 const char AudioManagerBase::kDefaultDeviceId[] = "default";
36 44
37 AudioManagerBase::AudioManagerBase() 45 AudioManagerBase::AudioManagerBase()
38 : num_active_input_streams_(0), 46 : num_active_input_streams_(0),
39 max_num_output_streams_(kDefaultMaxOutputStreams), 47 max_num_output_streams_(kDefaultMaxOutputStreams),
40 max_num_input_streams_(kDefaultMaxInputStreams), 48 max_num_input_streams_(kDefaultMaxInputStreams),
41 num_output_streams_(0), 49 num_output_streams_(0),
42 num_input_streams_(0), 50 num_input_streams_(0),
43 output_listeners_( 51 output_listeners_(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 stream = FakeAudioOutputStream::MakeFakeStream(this, params); 121 stream = FakeAudioOutputStream::MakeFakeStream(this, params);
114 break; 122 break;
115 default: 123 default:
116 stream = NULL; 124 stream = NULL;
117 break; 125 break;
118 } 126 }
119 127
120 if (stream) 128 if (stream)
121 ++num_output_streams_; 129 ++num_output_streams_;
122 130
131 #if defined(OS_ANDROID)
132 if (num_input_streams_)
Ami GONE FROM CHROMIUM 2013/03/20 00:30:27 I don't get it - here you're triggering off num_in
133 SetAudioMode(kAudioModeInCommunication);
134 #endif
135
123 return stream; 136 return stream;
124 } 137 }
125 138
126 AudioInputStream* AudioManagerBase::MakeAudioInputStream( 139 AudioInputStream* AudioManagerBase::MakeAudioInputStream(
127 const AudioParameters& params, const std::string& device_id) { 140 const AudioParameters& params, const std::string& device_id) {
128 // TODO(miu): Fix ~20 call points across several unit test modules to call 141 // TODO(miu): Fix ~20 call points across several unit test modules to call
129 // this method on the audio thread, then uncomment the following: 142 // this method on the audio thread, then uncomment the following:
130 // DCHECK(message_loop_->BelongsToCurrentThread()); 143 // DCHECK(message_loop_->BelongsToCurrentThread());
131 144
132 if (!params.IsValid() || (params.channels() > kMaxInputChannels) || 145 if (!params.IsValid() || (params.channels() > kMaxInputChannels) ||
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 media::AudioDeviceNames* device_names) { 249 media::AudioDeviceNames* device_names) {
237 } 250 }
238 251
239 void AudioManagerBase::ReleaseOutputStream(AudioOutputStream* stream) { 252 void AudioManagerBase::ReleaseOutputStream(AudioOutputStream* stream) {
240 DCHECK(stream); 253 DCHECK(stream);
241 // TODO(xians) : Have a clearer destruction path for the AudioOutputStream. 254 // TODO(xians) : Have a clearer destruction path for the AudioOutputStream.
242 // For example, pass the ownership to AudioManager so it can delete the 255 // For example, pass the ownership to AudioManager so it can delete the
243 // streams. 256 // streams.
244 --num_output_streams_; 257 --num_output_streams_;
245 delete stream; 258 delete stream;
259 #if defined(OS_ANDROID)
260 if (!num_output_streams_)
261 SetAudioMode(kAudioModeNormal);
262 #endif
246 } 263 }
247 264
248 void AudioManagerBase::ReleaseInputStream(AudioInputStream* stream) { 265 void AudioManagerBase::ReleaseInputStream(AudioInputStream* stream) {
249 DCHECK(stream); 266 DCHECK(stream);
250 // TODO(xians) : Have a clearer destruction path for the AudioInputStream. 267 // TODO(xians) : Have a clearer destruction path for the AudioInputStream.
251 --num_input_streams_; 268 --num_input_streams_;
252 delete stream; 269 delete stream;
253 } 270 }
254 271
255 void AudioManagerBase::IncreaseActiveInputStreamCount() { 272 void AudioManagerBase::IncreaseActiveInputStreamCount() {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 // So, better crash now than later. 327 // So, better crash now than later.
311 DCHECK(dispatcher->HasOneRef()) << "AudioOutputProxies are still alive"; 328 DCHECK(dispatcher->HasOneRef()) << "AudioOutputProxies are still alive";
312 dispatcher = NULL; 329 dispatcher = NULL;
313 } 330 }
314 } 331 }
315 332
316 output_dispatchers_.clear(); 333 output_dispatchers_.clear();
317 #endif // defined(OS_IOS) 334 #endif // defined(OS_IOS)
318 } 335 }
319 336
337 #if defined(OS_ANDROID)
338 // static
339 bool AudioManagerBase::RegisterAudioManager(JNIEnv* env) {
340 return RegisterNativesImpl(env);
341 }
342 #endif
343
320 void AudioManagerBase::AddOutputDeviceChangeListener( 344 void AudioManagerBase::AddOutputDeviceChangeListener(
321 AudioDeviceListener* listener) { 345 AudioDeviceListener* listener) {
322 DCHECK(message_loop_->BelongsToCurrentThread()); 346 DCHECK(message_loop_->BelongsToCurrentThread());
323 output_listeners_.AddObserver(listener); 347 output_listeners_.AddObserver(listener);
324 } 348 }
325 349
326 void AudioManagerBase::RemoveOutputDeviceChangeListener( 350 void AudioManagerBase::RemoveOutputDeviceChangeListener(
327 AudioDeviceListener* listener) { 351 AudioDeviceListener* listener) {
328 DCHECK(message_loop_->BelongsToCurrentThread()); 352 DCHECK(message_loop_->BelongsToCurrentThread());
329 output_listeners_.RemoveObserver(listener); 353 output_listeners_.RemoveObserver(listener);
330 } 354 }
331 355
332 void AudioManagerBase::NotifyAllOutputDeviceChangeListeners() { 356 void AudioManagerBase::NotifyAllOutputDeviceChangeListeners() {
333 DCHECK(message_loop_->BelongsToCurrentThread()); 357 DCHECK(message_loop_->BelongsToCurrentThread());
334 DVLOG(1) << "Firing OnDeviceChange() notifications."; 358 DVLOG(1) << "Firing OnDeviceChange() notifications.";
335 FOR_EACH_OBSERVER(AudioDeviceListener, output_listeners_, OnDeviceChange()); 359 FOR_EACH_OBSERVER(AudioDeviceListener, output_listeners_, OnDeviceChange());
336 } 360 }
337 361
338 AudioParameters AudioManagerBase::GetDefaultOutputStreamParameters() { 362 AudioParameters AudioManagerBase::GetDefaultOutputStreamParameters() {
339 return GetPreferredOutputStreamParameters(AudioParameters()); 363 return GetPreferredOutputStreamParameters(AudioParameters());
340 } 364 }
341 365
342 AudioParameters AudioManagerBase::GetInputStreamParameters( 366 AudioParameters AudioManagerBase::GetInputStreamParameters(
343 const std::string& device_id) { 367 const std::string& device_id) {
344 NOTREACHED(); 368 NOTREACHED();
345 return AudioParameters(); 369 return AudioParameters();
346 } 370 }
347 371
372 #if defined(OS_ANDROID)
373 void AudioManagerBase::SetAudioMode(int mode) {
374 JNIEnv* env = base::android::AttachCurrentThread();
375 jobject context = base::android::GetApplicationContext();
376 DCHECK(context);
377
378 Java_AudioManagerAndroid_setMode(env, context, mode);
379 }
380 #endif
381
348 } // namespace media 382 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698