Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/android/audio_manager_android.h" | 5 #include "media/audio/android/audio_manager_android.h" |
| 6 | 6 |
| 7 #include "base/android/build_info.h" | 7 #include "base/android/build_info.h" |
| 8 #include "base/android/context_utils.h" | 8 #include "base/android/context_utils.h" |
| 9 #include "base/android/jni_array.h" | 9 #include "base/android/jni_array.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 } | 38 } |
| 39 | 39 |
| 40 // Maximum number of output streams that can be open simultaneously. | 40 // Maximum number of output streams that can be open simultaneously. |
| 41 const int kMaxOutputStreams = 10; | 41 const int kMaxOutputStreams = 10; |
| 42 | 42 |
| 43 const int kDefaultInputBufferSize = 1024; | 43 const int kDefaultInputBufferSize = 1024; |
| 44 const int kDefaultOutputBufferSize = 2048; | 44 const int kDefaultOutputBufferSize = 2048; |
| 45 | 45 |
| 46 } // namespace | 46 } // namespace |
| 47 | 47 |
| 48 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { | 48 ScopedAudioManagerPtr CreateAudioManager( |
| 49 return new AudioManagerAndroid(audio_log_factory); | 49 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 50 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | |
| 51 AudioLogFactory* audio_log_factory) { | |
| 52 return ScopedAudioManagerPtr(new AudioManagerAndroid( | |
| 53 std::move(task_runner), std::move(worker_task_runner), | |
| 54 audio_log_factory)); | |
| 50 } | 55 } |
| 51 | 56 |
| 52 AudioManagerAndroid::AudioManagerAndroid(AudioLogFactory* audio_log_factory) | 57 AudioManagerAndroid::AudioManagerAndroid( |
| 53 : AudioManagerBase(audio_log_factory), | 58 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 59 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | |
| 60 AudioLogFactory* audio_log_factory) | |
| 61 : AudioManagerBase(std::move(task_runner), | |
| 62 std::move(worker_task_runner), | |
| 63 audio_log_factory), | |
| 54 communication_mode_is_on_(false), | 64 communication_mode_is_on_(false), |
| 55 output_volume_override_set_(false), | 65 output_volume_override_set_(false), |
| 56 output_volume_override_(0) { | 66 output_volume_override_(0) { |
| 57 SetMaxOutputStreamsAllowed(kMaxOutputStreams); | 67 SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
| 58 | 68 |
| 59 // WARNING: This is executed on the UI loop, do not add any code here which | 69 // WARNING: This is executed on the UI loop, do not add any code here which |
| 60 // loads libraries or attempts to call out into the OS. Instead add such code | 70 // loads libraries or attempts to call out into the OS. Instead add such code |
| 61 // to the InitializeOnAudioThread() method below. | 71 // to the InitializeOnAudioThread() method below. |
| 62 | 72 |
| 63 // Task must be posted last to avoid races from handing out "this" to the | 73 // Task must be posted last to avoid races from handing out "this" to the |
| 64 // audio thread. | 74 // audio thread. |
| 65 GetTaskRunner()->PostTask(FROM_HERE, base::Bind( | 75 GetTaskRunner()->PostTask(FROM_HERE, base::Bind( |
| 66 &AudioManagerAndroid::InitializeOnAudioThread, | 76 &AudioManagerAndroid::InitializeOnAudioThread, |
| 67 base::Unretained(this))); | 77 base::Unretained(this))); |
| 68 } | 78 } |
| 69 | 79 |
| 70 AudioManagerAndroid::~AudioManagerAndroid() { | 80 AudioManagerAndroid::~AudioManagerAndroid() { |
| 71 // It's safe to post a task here since Shutdown() will wait for all tasks to | 81 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 72 // complete before returning. | 82 |
| 73 GetTaskRunner()->PostTask(FROM_HERE, base::Bind( | |
| 74 &AudioManagerAndroid::ShutdownOnAudioThread, base::Unretained(this))); | |
| 75 Shutdown(); | 83 Shutdown(); |
| 84 ShutdownOnAudioThread(); | |
|
DaleCurtis
2016/04/05 21:55:36
Why the reordering?
alokp
2016/04/05 23:57:39
You are right about this one. I read the code wron
| |
| 76 } | 85 } |
| 77 | 86 |
| 78 bool AudioManagerAndroid::HasAudioOutputDevices() { | 87 bool AudioManagerAndroid::HasAudioOutputDevices() { |
| 79 return true; | 88 return true; |
| 80 } | 89 } |
| 81 | 90 |
| 82 bool AudioManagerAndroid::HasAudioInputDevices() { | 91 bool AudioManagerAndroid::HasAudioInputDevices() { |
| 83 return true; | 92 return true; |
| 84 } | 93 } |
| 85 | 94 |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 output_volume_override_ = volume; | 418 output_volume_override_ = volume; |
| 410 | 419 |
| 411 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 420 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 412 for (OutputStreams::iterator it = streams_.begin(); | 421 for (OutputStreams::iterator it = streams_.begin(); |
| 413 it != streams_.end(); ++it) { | 422 it != streams_.end(); ++it) { |
| 414 (*it)->SetVolume(volume); | 423 (*it)->SetVolume(volume); |
| 415 } | 424 } |
| 416 } | 425 } |
| 417 | 426 |
| 418 } // namespace media | 427 } // namespace media |
| OLD | NEW |