Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Side by Side Diff: media/audio/cras/audio_manager_cras.cc

Issue 1339183002: Add localized default audio device names. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix descriptions. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/grit/chromium_strings.h"
15 #include "chrome/grit/generated_resources.h"
14 #include "chromeos/audio/audio_device.h" 16 #include "chromeos/audio/audio_device.h"
15 #include "chromeos/audio/cras_audio_handler.h" 17 #include "chromeos/audio/cras_audio_handler.h"
16 #include "media/audio/cras/cras_input.h" 18 #include "media/audio/cras/cras_input.h"
17 #include "media/audio/cras/cras_unified.h" 19 #include "media/audio/cras/cras_unified.h"
18 #include "media/base/channel_layout.h" 20 #include "media/base/channel_layout.h"
21 #include "ui/base/l10n/l10n_util.h"
19 22
20 // cras_util.h headers pull in min/max macros... 23 // cras_util.h headers pull in min/max macros...
21 // TODO(dgreid): Fix headers such that these aren't imported. 24 // TODO(dgreid): Fix headers such that these aren't imported.
22 #undef min 25 #undef min
23 #undef max 26 #undef max
24 27
25 namespace media { 28 namespace media {
26 namespace { 29 namespace {
27 30
28 // Maximum number of output streams that can be open simultaneously. 31 // Maximum number of output streams that can be open simultaneously.
29 const int kMaxOutputStreams = 50; 32 const int kMaxOutputStreams = 50;
30 33
31 // Default sample rate for input and output streams. 34 // Default sample rate for input and output streams.
32 const int kDefaultSampleRate = 48000; 35 const int kDefaultSampleRate = 48000;
33 36
34 // Define bounds for the output buffer size. 37 // Define bounds for the output buffer size.
35 const int kMinimumOutputBufferSize = 512; 38 const int kMinimumOutputBufferSize = 512;
36 const int kMaximumOutputBufferSize = 8192; 39 const int kMaximumOutputBufferSize = 8192;
37 40
38 // Default input buffer size. 41 // Default input buffer size.
39 const int kDefaultInputBufferSize = 1024; 42 const int kDefaultInputBufferSize = 1024;
40 43
41 void AddDefaultDevice(AudioDeviceNames* device_names) {
42 // Cras will route audio from a proper physical device automatically.
43 device_names->push_back(
44 AudioDeviceName(AudioManagerBase::kDefaultDeviceName,
45 AudioManagerBase::kDefaultDeviceId));
46 }
47
48 // Returns the AudioDeviceName of the virtual device with beamforming on. 44 // Returns the AudioDeviceName of the virtual device with beamforming on.
49 AudioDeviceName BeamformingOnDeviceName() { 45 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"; 46 static const char kBeamformingOnIdSuffix[] = "-beamforming";
54
55 return AudioDeviceName( 47 return AudioDeviceName(
56 std::string(AudioManagerBase::kDefaultDeviceName) + 48 l10n_util::GetStringUTF8(
57 kBeamformingOnNameSuffix, 49 IDS_BEAMFORMING_ON_DEFAULT_AUDIO_INPUT_DEVICE_NAME),
58 std::string(AudioManagerBase::kDefaultDeviceId) + kBeamformingOnIdSuffix); 50 std::string(AudioManagerBase::kDefaultDeviceId) + kBeamformingOnIdSuffix);
59 } 51 }
60 52
61 // Returns the AudioDeviceName of the virtual device with beamforming off. 53 // Returns the AudioDeviceName of the virtual device with beamforming off.
62 AudioDeviceName BeamformingOffDeviceName() { 54 AudioDeviceName BeamformingOffDeviceName() {
63 static const char kBeamformingOffNameSuffix[] = " (pick up everything)"; 55 return AudioDeviceName(
64 return AudioDeviceName(std::string(AudioManagerBase::kDefaultDeviceName) + 56 l10n_util::GetStringUTF8(
65 kBeamformingOffNameSuffix, 57 IDS_BEAMFORMING_OFF_DEFAULT_AUDIO_INPUT_DEVICE_NAME),
66 AudioManagerBase::kDefaultDeviceId); 58 AudioManagerBase::kDefaultDeviceId);
67 } 59 }
68 60
69 // Returns a mic positions string if the machine has a beamforming capable 61 // Returns a mic positions string if the machine has a beamforming capable
70 // internal mic and otherwise an empty string. 62 // internal mic and otherwise an empty string.
71 std::string MicPositions() { 63 std::string MicPositions() {
72 // Get the list of devices from CRAS. An internal mic with a non-empty 64 // 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. 65 // positions field indicates the machine has a beamforming capable mic array.
74 chromeos::AudioDeviceList devices; 66 chromeos::AudioDeviceList devices;
75 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); 67 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices);
76 for (const auto& device : devices) { 68 for (const auto& device : devices) {
77 if (device.type == chromeos::AUDIO_TYPE_INTERNAL_MIC) { 69 if (device.type == chromeos::AUDIO_TYPE_INTERNAL_MIC) {
78 // There should be only one internal mic device. 70 // There should be only one internal mic device.
79 return device.mic_positions; 71 return device.mic_positions;
80 } 72 }
81 } 73 }
82 return ""; 74 return "";
83 } 75 }
84 76
85 } // namespace 77 } // namespace
86 78
79 void AudioManagerCras::AddDefaultDevice(AudioDeviceNames* device_names) const {
80 // Cras will route audio from a proper physical device automatically.
81 device_names->push_back(AudioDeviceName(GetDefaultDeviceName(),
82 AudioManagerBase::kDefaultDeviceId));
83 }
84
87 bool AudioManagerCras::HasAudioOutputDevices() { 85 bool AudioManagerCras::HasAudioOutputDevices() {
88 return true; 86 return true;
89 } 87 }
90 88
91 bool AudioManagerCras::HasAudioInputDevices() { 89 bool AudioManagerCras::HasAudioInputDevices() {
92 chromeos::AudioDeviceList devices; 90 chromeos::AudioDeviceList devices;
93 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); 91 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices);
94 for (size_t i = 0; i < devices.size(); ++i) { 92 for (size_t i = 0; i < devices.size(); ++i) {
95 if (devices[i].is_input && devices[i].is_for_simple_usage()) 93 if (devices[i].is_input && devices[i].is_for_simple_usage())
96 return true; 94 return true;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 case 24: 232 case 24:
235 return SND_PCM_FORMAT_S24; 233 return SND_PCM_FORMAT_S24;
236 case 32: 234 case 32:
237 return SND_PCM_FORMAT_S32; 235 return SND_PCM_FORMAT_S32;
238 default: 236 default:
239 return SND_PCM_FORMAT_UNKNOWN; 237 return SND_PCM_FORMAT_UNKNOWN;
240 } 238 }
241 } 239 }
242 240
243 } // namespace media 241 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698