| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 "content/browser/renderer_host/media/audio_output_device_enumerator.h" | 5 #include "content/browser/renderer_host/media/audio_output_device_enumerator.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "media/audio/audio_manager_base.h" | 12 #include "media/audio/audio_manager_base.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 AudioOutputDeviceEnumeration EnumerateDevicesOnDeviceThread( | 18 AudioOutputDeviceEnumeration EnumerateDevicesOnDeviceThread( |
| 19 media::AudioManager* audio_manager) { | 19 media::AudioManager* audio_manager) { |
| 20 DCHECK(audio_manager->GetWorkerTaskRunner()->BelongsToCurrentThread()); | 20 DCHECK(audio_manager->GetWorkerTaskRunner()->BelongsToCurrentThread()); |
| 21 | 21 |
| 22 AudioOutputDeviceEnumeration snapshot; | 22 AudioOutputDeviceEnumeration snapshot; |
| 23 media::AudioDeviceNames device_names; | 23 media::AudioDeviceNames device_names; |
| 24 audio_manager->GetAudioOutputDeviceNames(&device_names); | 24 audio_manager->GetAudioOutputDeviceNames(&device_names); |
| 25 | 25 |
| 26 snapshot.has_actual_devices = !device_names.empty(); |
| 27 |
| 26 // If no devices in enumeration, return a list with a default device | 28 // If no devices in enumeration, return a list with a default device |
| 27 if (device_names.empty()) { | 29 if (!snapshot.has_actual_devices) { |
| 28 snapshot.push_back({media::AudioManagerBase::kDefaultDeviceId, | 30 snapshot.devices.push_back( |
| 29 media::AudioManager::GetDefaultDeviceName(), | 31 {media::AudioManagerBase::kDefaultDeviceId, |
| 30 audio_manager->GetDefaultOutputStreamParameters()}); | 32 media::AudioManager::GetDefaultDeviceName(), |
| 33 audio_manager->GetDefaultOutputStreamParameters()}); |
| 31 return snapshot; | 34 return snapshot; |
| 32 } | 35 } |
| 33 | 36 |
| 34 for (const media::AudioDeviceName& name : device_names) { | 37 for (const media::AudioDeviceName& name : device_names) { |
| 35 snapshot.push_back( | 38 snapshot.devices.push_back( |
| 36 {name.unique_id, name.device_name, | 39 {name.unique_id, name.device_name, |
| 37 name.unique_id == media::AudioManagerBase::kDefaultDeviceId | 40 name.unique_id == media::AudioManagerBase::kDefaultDeviceId |
| 38 ? audio_manager->GetDefaultOutputStreamParameters() | 41 ? audio_manager->GetDefaultOutputStreamParameters() |
| 39 : audio_manager->GetOutputStreamParameters(name.unique_id)}); | 42 : audio_manager->GetOutputStreamParameters(name.unique_id)}); |
| 40 } | 43 } |
| 41 return snapshot; | 44 return snapshot; |
| 42 } | 45 } |
| 43 | 46 |
| 44 } // namespace | 47 } // namespace |
| 45 | 48 |
| 49 AudioOutputDeviceEnumeration::AudioOutputDeviceEnumeration( |
| 50 const std::vector<AudioOutputDeviceInfo>& devices, |
| 51 bool has_actual_devices) |
| 52 : devices(devices), has_actual_devices(has_actual_devices) {} |
| 53 |
| 54 AudioOutputDeviceEnumeration::AudioOutputDeviceEnumeration() |
| 55 : has_actual_devices(false) {} |
| 56 |
| 57 AudioOutputDeviceEnumeration::~AudioOutputDeviceEnumeration() {} |
| 58 |
| 46 AudioOutputDeviceEnumerator::AudioOutputDeviceEnumerator( | 59 AudioOutputDeviceEnumerator::AudioOutputDeviceEnumerator( |
| 47 media::AudioManager* audio_manager, | 60 media::AudioManager* audio_manager, |
| 48 CachePolicy cache_policy) | 61 CachePolicy cache_policy) |
| 49 : audio_manager_(audio_manager), | 62 : audio_manager_(audio_manager), |
| 50 cache_policy_(cache_policy), | 63 cache_policy_(cache_policy), |
| 51 current_event_sequence_(0), | 64 current_event_sequence_(0), |
| 52 seq_last_enumeration_(0), | 65 seq_last_enumeration_(0), |
| 53 seq_last_invalidation_(0), | 66 seq_last_invalidation_(0), |
| 54 is_enumeration_ongoing_(false), | 67 is_enumeration_ongoing_(false), |
| 55 weak_factory_(this) {} | 68 weak_factory_(this) {} |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 return ++current_event_sequence_; | 143 return ++current_event_sequence_; |
| 131 } | 144 } |
| 132 | 145 |
| 133 bool AudioOutputDeviceEnumerator::IsLastEnumerationValid() const { | 146 bool AudioOutputDeviceEnumerator::IsLastEnumerationValid() const { |
| 134 DCHECK(thread_checker_.CalledOnValidThread()); | 147 DCHECK(thread_checker_.CalledOnValidThread()); |
| 135 return seq_last_enumeration_ > seq_last_invalidation_ && | 148 return seq_last_enumeration_ > seq_last_invalidation_ && |
| 136 !is_enumeration_ongoing_; | 149 !is_enumeration_ongoing_; |
| 137 } | 150 } |
| 138 | 151 |
| 139 } // namespace content | 152 } // namespace content |
| OLD | NEW |