| 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 "chromeos/audio/audio_device.h" | 18 #include "chromeos/audio/audio_device.h" |
| 19 #include "chromeos/audio/cras_audio_handler.h" | 19 #include "chromeos/audio/cras_audio_handler.h" |
| 20 #include "media/audio/audio_device_description.h" |
| 20 #include "media/audio/cras/cras_input.h" | 21 #include "media/audio/cras/cras_input.h" |
| 21 #include "media/audio/cras/cras_unified.h" | 22 #include "media/audio/cras/cras_unified.h" |
| 22 #include "media/base/channel_layout.h" | 23 #include "media/base/channel_layout.h" |
| 23 #include "media/base/media_resources.h" | 24 #include "media/base/media_resources.h" |
| 24 | 25 |
| 25 // cras_util.h headers pull in min/max macros... | 26 // cras_util.h headers pull in min/max macros... |
| 26 // TODO(dgreid): Fix headers such that these aren't imported. | 27 // TODO(dgreid): Fix headers such that these aren't imported. |
| 27 #undef min | 28 #undef min |
| 28 #undef max | 29 #undef max |
| 29 | 30 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 62 |
| 62 bool IsBeamformingDefaultEnabled() { | 63 bool IsBeamformingDefaultEnabled() { |
| 63 return base::FieldTrialList::FindFullName("ChromebookBeamforming") == | 64 return base::FieldTrialList::FindFullName("ChromebookBeamforming") == |
| 64 "Enabled"; | 65 "Enabled"; |
| 65 } | 66 } |
| 66 | 67 |
| 67 void AddDefaultDevice(AudioDeviceNames* device_names) { | 68 void AddDefaultDevice(AudioDeviceNames* device_names) { |
| 68 DCHECK(device_names->empty()); | 69 DCHECK(device_names->empty()); |
| 69 | 70 |
| 70 // Cras will route audio from a proper physical device automatically. | 71 // Cras will route audio from a proper physical device automatically. |
| 71 device_names->push_back(AudioDeviceName(AudioManager::GetDefaultDeviceName(), | 72 device_names->push_back(AudioDeviceName::CreateDefault()); |
| 72 AudioManagerBase::kDefaultDeviceId)); | |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Returns a mic positions string if the machine has a beamforming capable | 75 // Returns a mic positions string if the machine has a beamforming capable |
| 76 // internal mic and otherwise an empty string. | 76 // internal mic and otherwise an empty string. |
| 77 std::string MicPositions() { | 77 std::string MicPositions() { |
| 78 // Get the list of devices from CRAS. An internal mic with a non-empty | 78 // 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. | 79 // positions field indicates the machine has a beamforming capable mic array. |
| 80 chromeos::AudioDeviceList devices; | 80 chromeos::AudioDeviceList devices; |
| 81 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); | 81 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); |
| 82 for (const auto& device : devices) { | 82 for (const auto& device : devices) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 94 void AudioManagerCras::AddBeamformingDevices(AudioDeviceNames* device_names) { | 94 void AudioManagerCras::AddBeamformingDevices(AudioDeviceNames* device_names) { |
| 95 DCHECK(device_names->empty()); | 95 DCHECK(device_names->empty()); |
| 96 const std::string beamforming_on_name = | 96 const std::string beamforming_on_name = |
| 97 GetLocalizedStringUTF8(BEAMFORMING_ON_DEFAULT_AUDIO_INPUT_DEVICE_NAME); | 97 GetLocalizedStringUTF8(BEAMFORMING_ON_DEFAULT_AUDIO_INPUT_DEVICE_NAME); |
| 98 const std::string beamforming_off_name = | 98 const std::string beamforming_off_name = |
| 99 GetLocalizedStringUTF8(BEAMFORMING_OFF_DEFAULT_AUDIO_INPUT_DEVICE_NAME); | 99 GetLocalizedStringUTF8(BEAMFORMING_OFF_DEFAULT_AUDIO_INPUT_DEVICE_NAME); |
| 100 | 100 |
| 101 if (IsBeamformingDefaultEnabled()) { | 101 if (IsBeamformingDefaultEnabled()) { |
| 102 // The first device in the list is expected to have a "default" device ID. | 102 // The first device in the list is expected to have a "default" device ID. |
| 103 // Web apps may depend on this behavior. | 103 // Web apps may depend on this behavior. |
| 104 beamforming_on_device_id_ = AudioManagerBase::kDefaultDeviceId; | 104 beamforming_on_device_id_ = AudioDeviceDescription::kDefaultDeviceId; |
| 105 beamforming_off_device_id_ = kBeamformingOffDeviceId; | 105 beamforming_off_device_id_ = kBeamformingOffDeviceId; |
| 106 | 106 |
| 107 // Users in the experiment will have the "beamforming on" device appear | 107 // Users in the experiment will have the "beamforming on" device appear |
| 108 // first in the list. This causes it to be selected by default. | 108 // first in the list. This causes it to be selected by default. |
| 109 device_names->push_back( | 109 device_names->push_back( |
| 110 AudioDeviceName(beamforming_on_name, beamforming_on_device_id_)); | 110 AudioDeviceName(beamforming_on_name, beamforming_on_device_id_)); |
| 111 device_names->push_back( | 111 device_names->push_back( |
| 112 AudioDeviceName(beamforming_off_name, beamforming_off_device_id_)); | 112 AudioDeviceName(beamforming_off_name, beamforming_off_device_id_)); |
| 113 } else { | 113 } else { |
| 114 beamforming_off_device_id_ = AudioManagerBase::kDefaultDeviceId; | 114 beamforming_off_device_id_ = AudioDeviceDescription::kDefaultDeviceId; |
| 115 beamforming_on_device_id_ = kBeamformingOnDeviceId; | 115 beamforming_on_device_id_ = kBeamformingOnDeviceId; |
| 116 | 116 |
| 117 device_names->push_back( | 117 device_names->push_back( |
| 118 AudioDeviceName(beamforming_off_name, beamforming_off_device_id_)); | 118 AudioDeviceName(beamforming_off_name, beamforming_off_device_id_)); |
| 119 device_names->push_back( | 119 device_names->push_back( |
| 120 AudioDeviceName(beamforming_on_name, beamforming_on_device_id_)); | 120 AudioDeviceName(beamforming_on_name, beamforming_on_device_id_)); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 bool AudioManagerCras::HasAudioOutputDevices() { | 124 bool AudioManagerCras::HasAudioOutputDevices() { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 case 24: | 290 case 24: |
| 291 return SND_PCM_FORMAT_S24; | 291 return SND_PCM_FORMAT_S24; |
| 292 case 32: | 292 case 32: |
| 293 return SND_PCM_FORMAT_S32; | 293 return SND_PCM_FORMAT_S32; |
| 294 default: | 294 default: |
| 295 return SND_PCM_FORMAT_UNKNOWN; | 295 return SND_PCM_FORMAT_UNKNOWN; |
| 296 } | 296 } |
| 297 } | 297 } |
| 298 | 298 |
| 299 } // namespace media | 299 } // namespace media |
| OLD | NEW |