| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 AudioManagerAndroid::AudioManagerAndroid( | 57 AudioManagerAndroid::AudioManagerAndroid( |
| 58 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 58 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 59 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 59 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
| 60 AudioLogFactory* audio_log_factory) | 60 AudioLogFactory* audio_log_factory) |
| 61 : AudioManagerBase(std::move(task_runner), | 61 : AudioManagerBase(std::move(task_runner), |
| 62 std::move(worker_task_runner), | 62 std::move(worker_task_runner), |
| 63 audio_log_factory), | 63 audio_log_factory), |
| 64 communication_mode_is_on_(false), | 64 communication_mode_is_on_(false), |
| 65 output_volume_override_set_(false), | 65 output_volume_override_set_(false), |
| 66 output_volume_override_(0) { | 66 output_volume_override_(0), |
| 67 initialized_(false) { |
| 67 SetMaxOutputStreamsAllowed(kMaxOutputStreams); | 68 SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
| 69 } |
| 70 |
| 71 AudioManagerAndroid::~AudioManagerAndroid() { |
| 72 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 73 Shutdown(); |
| 74 |
| 75 if (j_audio_manager_.is_null()) |
| 76 return; |
| 77 DVLOG(2) << "Destroying Java part of the audio manager"; |
| 78 Java_AudioManagerAndroid_close(base::android::AttachCurrentThread(), |
| 79 j_audio_manager_.obj()); |
| 80 j_audio_manager_.Reset(); |
| 81 } |
| 82 |
| 83 void AudioManagerAndroid::InitializeIfNeeded() { |
| 84 if (initialized_) |
| 85 return; |
| 68 | 86 |
| 69 // WARNING: This is executed on the UI loop, do not add any code here which | 87 // WARNING: This is executed on the UI loop, do not add any code here which |
| 70 // loads libraries or attempts to call out into the OS. Instead add such code | 88 // loads libraries or attempts to call out into the OS. Instead add such code |
| 71 // to the InitializeOnAudioThread() method below. | 89 // to the InitializeOnAudioThread() method below. |
| 72 | 90 |
| 73 // Task must be posted last to avoid races from handing out "this" to the | 91 // Task must be posted last to avoid races from handing out "this" to the |
| 74 // audio thread. | 92 // audio thread. |
| 75 GetTaskRunner()->PostTask(FROM_HERE, base::Bind( | 93 GetTaskRunner()->PostTask(FROM_HERE, base::Bind( |
| 76 &AudioManagerAndroid::InitializeOnAudioThread, | 94 &AudioManagerAndroid::InitializeOnAudioThread, |
| 77 base::Unretained(this))); | 95 base::Unretained(this))); |
| 78 } | 96 initialized_ = true; |
| 79 | |
| 80 AudioManagerAndroid::~AudioManagerAndroid() { | |
| 81 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | |
| 82 Shutdown(); | |
| 83 | |
| 84 DVLOG(2) << "Destroying Java part of the audio manager"; | |
| 85 Java_AudioManagerAndroid_close(base::android::AttachCurrentThread(), | |
| 86 j_audio_manager_.obj()); | |
| 87 j_audio_manager_.Reset(); | |
| 88 } | 97 } |
| 89 | 98 |
| 90 bool AudioManagerAndroid::HasAudioOutputDevices() { | 99 bool AudioManagerAndroid::HasAudioOutputDevices() { |
| 91 return true; | 100 return true; |
| 92 } | 101 } |
| 93 | 102 |
| 94 bool AudioManagerAndroid::HasAudioInputDevices() { | 103 bool AudioManagerAndroid::HasAudioInputDevices() { |
| 95 return true; | 104 return true; |
| 96 } | 105 } |
| 97 | 106 |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 output_volume_override_ = volume; | 438 output_volume_override_ = volume; |
| 430 | 439 |
| 431 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 440 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 432 for (OutputStreams::iterator it = streams_.begin(); | 441 for (OutputStreams::iterator it = streams_.begin(); |
| 433 it != streams_.end(); ++it) { | 442 it != streams_.end(); ++it) { |
| 434 (*it)->SetVolume(volume); | 443 (*it)->SetVolume(volume); |
| 435 } | 444 } |
| 436 } | 445 } |
| 437 | 446 |
| 438 } // namespace media | 447 } // namespace media |
| OLD | NEW |