OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/cras/audio_manager_cras.h" | 5 #include "media/audio/cras/audio_manager_cras.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/environment.h" | 12 #include "base/environment.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/nix/xdg_util.h" | 16 #include "base/nix/xdg_util.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "base/strings/string_number_conversions.h" | |
18 #include "chromeos/audio/audio_device.h" | 19 #include "chromeos/audio/audio_device.h" |
19 #include "chromeos/audio/cras_audio_handler.h" | 20 #include "chromeos/audio/cras_audio_handler.h" |
20 #include "media/audio/audio_device_description.h" | 21 #include "media/audio/audio_device_description.h" |
21 #include "media/audio/cras/cras_input.h" | 22 #include "media/audio/cras/cras_input.h" |
22 #include "media/audio/cras/cras_unified.h" | 23 #include "media/audio/cras/cras_unified.h" |
23 #include "media/base/channel_layout.h" | 24 #include "media/base/channel_layout.h" |
24 #include "media/base/media_resources.h" | 25 #include "media/base/media_resources.h" |
25 | 26 |
26 // cras_util.h headers pull in min/max macros... | 27 // cras_util.h headers pull in min/max macros... |
27 // TODO(dgreid): Fix headers such that these aren't imported. | 28 // TODO(dgreid): Fix headers such that these aren't imported. |
(...skipping 30 matching lines...) Expand all Loading... | |
58 void RecordBeamformingDeviceState(CrosBeamformingDeviceState state) { | 59 void RecordBeamformingDeviceState(CrosBeamformingDeviceState state) { |
59 UMA_HISTOGRAM_ENUMERATION("Media.CrosBeamformingDeviceState", state, | 60 UMA_HISTOGRAM_ENUMERATION("Media.CrosBeamformingDeviceState", state, |
60 BEAMFORMING_STATE_MAX + 1); | 61 BEAMFORMING_STATE_MAX + 1); |
61 } | 62 } |
62 | 63 |
63 bool IsBeamformingDefaultEnabled() { | 64 bool IsBeamformingDefaultEnabled() { |
64 return base::FieldTrialList::FindFullName("ChromebookBeamforming") == | 65 return base::FieldTrialList::FindFullName("ChromebookBeamforming") == |
65 "Enabled"; | 66 "Enabled"; |
66 } | 67 } |
67 | 68 |
68 void AddDefaultDevice(AudioDeviceNames* device_names) { | |
69 DCHECK(device_names->empty()); | |
70 | |
71 // Cras will route audio from a proper physical device automatically. | |
72 device_names->push_back(AudioDeviceName::CreateDefault()); | |
73 } | |
74 | |
75 // Returns a mic positions string if the machine has a beamforming capable | 69 // Returns a mic positions string if the machine has a beamforming capable |
76 // internal mic and otherwise an empty string. | 70 // internal mic and otherwise an empty string. |
77 std::string MicPositions() { | 71 std::string MicPositions() { |
78 // Get the list of devices from CRAS. An internal mic with a non-empty | 72 // Get the list of devices from CRAS. An internal mic with a non-empty |
79 // positions field indicates the machine has a beamforming capable mic array. | 73 // positions field indicates the machine has a beamforming capable mic array. |
80 chromeos::AudioDeviceList devices; | 74 chromeos::AudioDeviceList devices; |
81 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); | 75 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); |
82 for (const auto& device : devices) { | 76 for (const auto& device : devices) { |
83 if (device.type == chromeos::AUDIO_TYPE_INTERNAL_MIC) { | 77 if (device.type == chromeos::AUDIO_TYPE_INTERNAL_MIC) { |
84 // There should be only one internal mic device. | 78 // There should be only one internal mic device. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 } | 142 } |
149 | 143 |
150 AudioManagerCras::~AudioManagerCras() { | 144 AudioManagerCras::~AudioManagerCras() { |
151 Shutdown(); | 145 Shutdown(); |
152 } | 146 } |
153 | 147 |
154 void AudioManagerCras::ShowAudioInputSettings() { | 148 void AudioManagerCras::ShowAudioInputSettings() { |
155 NOTIMPLEMENTED(); | 149 NOTIMPLEMENTED(); |
156 } | 150 } |
157 | 151 |
152 void AudioManagerCras::GetAudioDeviceNamesImpl(bool is_input, | |
153 AudioDeviceNames* device_names) { | |
154 DCHECK(device_names->empty()); | |
155 // At least two mic positions indicates we have a beamforming capable mic | |
156 // array. Add the virtual beamforming device to the list. When this device is | |
157 // queried through GetInputStreamParameters, provide the cached mic positions. | |
158 bool should_add_beamforming_devices = is_input && mic_positions_.size() > 1; | |
159 if (should_add_beamforming_devices) | |
160 AddBeamformingDevices(device_names); | |
161 chromeos::AudioDeviceList devices; | |
162 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); | |
163 for (const auto& device : devices) { | |
164 if (device.is_input == is_input && device.is_for_simple_usage()) { | |
165 media::AudioDeviceName device_name; | |
166 device_name.device_name = device.device_name; | |
167 device_name.unique_id = base::Uint64ToString(device.id); | |
168 device_names->push_back(device_name); | |
DaleCurtis
2016/07/06 18:58:52
Does emplace_back(device.device_name, base::Uint64
Qiang(Joe) Xu
2016/07/07 00:32:45
done. tks.
| |
169 } | |
170 } | |
171 if (!device_names->empty() && !should_add_beamforming_devices) { | |
172 device_names->push_front(media::AudioDeviceName::CreateDefault()); | |
DaleCurtis
2016/07/06 18:58:53
Just do this first to avoid push_front?
Qiang(Joe) Xu
2016/07/07 00:32:45
done. tks.
| |
173 } | |
174 } | |
175 | |
158 void AudioManagerCras::GetAudioInputDeviceNames( | 176 void AudioManagerCras::GetAudioInputDeviceNames( |
159 AudioDeviceNames* device_names) { | 177 AudioDeviceNames* device_names) { |
160 DCHECK(device_names->empty()); | |
161 | |
162 mic_positions_ = ParsePointsFromString(MicPositions()); | 178 mic_positions_ = ParsePointsFromString(MicPositions()); |
163 // At least two mic positions indicates we have a beamforming capable mic | 179 GetAudioDeviceNamesImpl(true, device_names); |
164 // array. Add the virtual beamforming device to the list. When this device is | |
165 // queried through GetInputStreamParameters, provide the cached mic positions. | |
166 if (mic_positions_.size() > 1) | |
167 AddBeamformingDevices(device_names); | |
168 else | |
169 AddDefaultDevice(device_names); | |
170 } | 180 } |
171 | 181 |
172 void AudioManagerCras::GetAudioOutputDeviceNames( | 182 void AudioManagerCras::GetAudioOutputDeviceNames( |
173 AudioDeviceNames* device_names) { | 183 AudioDeviceNames* device_names) { |
174 AddDefaultDevice(device_names); | 184 GetAudioDeviceNamesImpl(false, device_names); |
175 } | 185 } |
176 | 186 |
177 AudioParameters AudioManagerCras::GetInputStreamParameters( | 187 AudioParameters AudioManagerCras::GetInputStreamParameters( |
178 const std::string& device_id) { | 188 const std::string& device_id) { |
179 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 189 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
180 | 190 |
181 int user_buffer_size = GetUserBufferSize(); | 191 int user_buffer_size = GetUserBufferSize(); |
182 int buffer_size = user_buffer_size ? | 192 int buffer_size = user_buffer_size ? |
183 user_buffer_size : kDefaultInputBufferSize; | 193 user_buffer_size : kDefaultInputBufferSize; |
184 | 194 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 case 24: | 306 case 24: |
297 return SND_PCM_FORMAT_S24; | 307 return SND_PCM_FORMAT_S24; |
298 case 32: | 308 case 32: |
299 return SND_PCM_FORMAT_S32; | 309 return SND_PCM_FORMAT_S32; |
300 default: | 310 default: |
301 return SND_PCM_FORMAT_UNKNOWN; | 311 return SND_PCM_FORMAT_UNKNOWN; |
302 } | 312 } |
303 } | 313 } |
304 | 314 |
305 } // namespace media | 315 } // namespace media |
OLD | NEW |