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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/environment.h" | 10 #include "base/environment.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/nix/xdg_util.h" | 12 #include "base/nix/xdg_util.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "chromeos/audio/audio_device.h" | 14 #include "chromeos/audio/audio_device.h" |
15 #include "chromeos/audio/cras_audio_handler.h" | 15 #include "chromeos/audio/cras_audio_handler.h" |
16 #include "media/audio/cras/cras_input.h" | 16 #include "media/audio/cras/cras_input.h" |
17 #include "media/audio/cras/cras_unified.h" | 17 #include "media/audio/cras/cras_unified.h" |
18 #include "media/base/channel_layout.h" | 18 #include "media/base/channel_layout.h" |
19 #include "media/base/media_resources.h" | |
19 | 20 |
20 // cras_util.h headers pull in min/max macros... | 21 // cras_util.h headers pull in min/max macros... |
21 // TODO(dgreid): Fix headers such that these aren't imported. | 22 // TODO(dgreid): Fix headers such that these aren't imported. |
22 #undef min | 23 #undef min |
23 #undef max | 24 #undef max |
24 | 25 |
25 namespace media { | 26 namespace media { |
26 namespace { | 27 namespace { |
27 | 28 |
28 // Maximum number of output streams that can be open simultaneously. | 29 // Maximum number of output streams that can be open simultaneously. |
29 const int kMaxOutputStreams = 50; | 30 const int kMaxOutputStreams = 50; |
30 | 31 |
31 // Default sample rate for input and output streams. | 32 // Default sample rate for input and output streams. |
32 const int kDefaultSampleRate = 48000; | 33 const int kDefaultSampleRate = 48000; |
33 | 34 |
34 // Define bounds for the output buffer size. | 35 // Define bounds for the output buffer size. |
35 const int kMinimumOutputBufferSize = 512; | 36 const int kMinimumOutputBufferSize = 512; |
36 const int kMaximumOutputBufferSize = 8192; | 37 const int kMaximumOutputBufferSize = 8192; |
37 | 38 |
38 // Default input buffer size. | 39 // Default input buffer size. |
39 const int kDefaultInputBufferSize = 1024; | 40 const int kDefaultInputBufferSize = 1024; |
40 | 41 |
41 void AddDefaultDevice(AudioDeviceNames* device_names) { | 42 void AddDefaultDevice(AudioDeviceNames* device_names) { |
42 // Cras will route audio from a proper physical device automatically. | 43 // Cras will route audio from a proper physical device automatically. |
43 device_names->push_back( | 44 device_names->push_back(AudioDeviceName(AudioManager::GetDefaultDeviceName(), |
44 AudioDeviceName(AudioManagerBase::kDefaultDeviceName, | 45 AudioManagerBase::kDefaultDeviceId)); |
45 AudioManagerBase::kDefaultDeviceId)); | |
46 } | 46 } |
47 | 47 |
48 // Returns the AudioDeviceName of the virtual device with beamforming on. | 48 // Returns the AudioDeviceName of the virtual device with beamforming on. |
49 AudioDeviceName BeamformingOnDeviceName() { | 49 AudioDeviceName BeamformingOnDeviceName() { |
50 // TODO(ajm): Replace these strings with properly localized ones. | |
51 // (crbug.com/497001) | |
52 static const char kBeamformingOnNameSuffix[] = " (pick up just one person)"; | |
53 static const char kBeamformingOnIdSuffix[] = "-beamforming"; | 50 static const char kBeamformingOnIdSuffix[] = "-beamforming"; |
54 | |
55 return AudioDeviceName( | 51 return AudioDeviceName( |
56 std::string(AudioManagerBase::kDefaultDeviceName) + | 52 GetLocalizedStringUTF8(BEAMFORMING_ON_DEFAULT_AUDIO_INPUT_DEVICE_NAME), |
57 kBeamformingOnNameSuffix, | |
58 std::string(AudioManagerBase::kDefaultDeviceId) + kBeamformingOnIdSuffix); | 53 std::string(AudioManagerBase::kDefaultDeviceId) + kBeamformingOnIdSuffix); |
59 } | 54 } |
60 | 55 |
61 // Returns the AudioDeviceName of the virtual device with beamforming off. | 56 // Returns the AudioDeviceName of the virtual device with beamforming off. |
62 AudioDeviceName BeamformingOffDeviceName() { | 57 AudioDeviceName BeamformingOffDeviceName() { |
63 static const char kBeamformingOffNameSuffix[] = " (pick up everything)"; | 58 return AudioDeviceName( |
64 return AudioDeviceName(std::string(AudioManagerBase::kDefaultDeviceName) + | 59 GetLocalizedStringUTF8(BEAMFORMING_OFF_DEFAULT_AUDIO_INPUT_DEVICE_NAME), |
65 kBeamformingOffNameSuffix, | 60 AudioManagerBase::kDefaultDeviceId); |
66 AudioManagerBase::kDefaultDeviceId); | |
67 } | 61 } |
68 | 62 |
69 // Returns a mic positions string if the machine has a beamforming capable | 63 // Returns a mic positions string if the machine has a beamforming capable |
70 // internal mic and otherwise an empty string. | 64 // internal mic and otherwise an empty string. |
71 std::string MicPositions() { | 65 std::string MicPositions() { |
72 // Get the list of devices from CRAS. An internal mic with a non-empty | 66 // Get the list of devices from CRAS. An internal mic with a non-empty |
73 // positions field indicates the machine has a beamforming capable mic array. | 67 // positions field indicates the machine has a beamforming capable mic array. |
74 chromeos::AudioDeviceList devices; | 68 chromeos::AudioDeviceList devices; |
75 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); | 69 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); |
76 for (const auto& device : devices) { | 70 for (const auto& device : devices) { |
(...skipping 17 matching lines...) Expand all Loading... | |
94 for (size_t i = 0; i < devices.size(); ++i) { | 88 for (size_t i = 0; i < devices.size(); ++i) { |
95 if (devices[i].is_input && devices[i].is_for_simple_usage()) | 89 if (devices[i].is_input && devices[i].is_for_simple_usage()) |
96 return true; | 90 return true; |
97 } | 91 } |
98 return false; | 92 return false; |
99 } | 93 } |
100 | 94 |
101 AudioManagerCras::AudioManagerCras(AudioLogFactory* audio_log_factory) | 95 AudioManagerCras::AudioManagerCras(AudioLogFactory* audio_log_factory) |
102 : AudioManagerBase(audio_log_factory), | 96 : AudioManagerBase(audio_log_factory), |
103 has_keyboard_mic_(false), | 97 has_keyboard_mic_(false), |
104 beamforming_on_device_name_(BeamformingOnDeviceName()), | 98 beamforming_on_device_name_(BeamformingOnDeviceName()), |
ajm
2015/09/18 00:43:21
Initializing these at construction was too early a
| |
105 beamforming_off_device_name_(BeamformingOffDeviceName()) { | 99 beamforming_off_device_name_(BeamformingOffDeviceName()) { |
106 SetMaxOutputStreamsAllowed(kMaxOutputStreams); | 100 SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
107 } | 101 } |
108 | 102 |
109 AudioManagerCras::~AudioManagerCras() { | 103 AudioManagerCras::~AudioManagerCras() { |
110 Shutdown(); | 104 Shutdown(); |
111 } | 105 } |
112 | 106 |
113 void AudioManagerCras::ShowAudioInputSettings() { | 107 void AudioManagerCras::ShowAudioInputSettings() { |
114 NOTIMPLEMENTED(); | 108 NOTIMPLEMENTED(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 case 24: | 228 case 24: |
235 return SND_PCM_FORMAT_S24; | 229 return SND_PCM_FORMAT_S24; |
236 case 32: | 230 case 32: |
237 return SND_PCM_FORMAT_S32; | 231 return SND_PCM_FORMAT_S32; |
238 default: | 232 default: |
239 return SND_PCM_FORMAT_UNKNOWN; | 233 return SND_PCM_FORMAT_UNKNOWN; |
240 } | 234 } |
241 } | 235 } |
242 | 236 |
243 } // namespace media | 237 } // namespace media |
OLD | NEW |