Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/linux/audio_manager_linux.h" | 5 #include "media/audio/linux/audio_manager_linux.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/environment.h" | 8 #include "base/environment.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/nix/xdg_util.h" | 10 #include "base/nix/xdg_util.h" |
| 11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
| 12 #include "base/stringprintf.h" | |
| 12 #include "media/audio/audio_output_dispatcher.h" | 13 #include "media/audio/audio_output_dispatcher.h" |
| 13 #include "media/audio/fake_audio_input_stream.h" | 14 #include "media/audio/fake_audio_input_stream.h" |
| 14 #include "media/audio/fake_audio_output_stream.h" | 15 #include "media/audio/fake_audio_output_stream.h" |
| 15 #include "media/audio/linux/alsa_input.h" | 16 #include "media/audio/linux/alsa_input.h" |
| 16 #include "media/audio/linux/alsa_output.h" | 17 #include "media/audio/linux/alsa_output.h" |
| 17 #include "media/audio/linux/alsa_wrapper.h" | 18 #include "media/audio/linux/alsa_wrapper.h" |
| 18 #include "media/base/limits.h" | 19 #include "media/base/limits.h" |
| 19 #include "media/base/media_switches.h" | 20 #include "media/base/media_switches.h" |
| 20 | 21 |
| 21 // Maximum number of output streams that can be open simultaneously. | 22 // Maximum number of output streams that can be open simultaneously. |
| 22 static const size_t kMaxOutputStreams = 50; | 23 static const size_t kMaxOutputStreams = 50; |
| 23 | 24 |
| 24 static const int kMaxInputChannels = 2; | 25 static const int kMaxInputChannels = 2; |
| 25 | 26 |
| 26 // Implementation of AudioManager. | 27 // Implementation of AudioManager. |
| 27 bool AudioManagerLinux::HasAudioOutputDevices() { | 28 bool AudioManagerLinux::HasAudioOutputDevices() { |
| 28 // TODO(ajwong): Make this actually query audio devices. | 29 // TODO(ajwong): Make this actually query audio devices. |
| 29 return true; | 30 return true; |
| 30 } | 31 } |
| 31 | 32 |
| 32 bool AudioManagerLinux::HasAudioInputDevices() { | 33 bool AudioManagerLinux::HasAudioInputDevices() { |
|
awong
2011/05/23 17:36:15
It's slightly confusing to me that you don't popul
xians
2011/05/24 13:50:27
Sorry that I forgot to reply this.
We cant do this
| |
| 33 // TODO(satish): Make this actually query audio devices. | 34 if (!initialized()) { |
| 34 return true; | 35 return false; |
| 36 } | |
| 37 | |
| 38 // Constants specified by the ALSA API for device hints. | |
| 39 static const int kGetAllDevices = -1; | |
| 40 static const char kPcmInterfaceName[] = "pcm"; | |
| 41 static const char kIoHintName[] = "IOID"; | |
| 42 static const char kNameHintName[] = "NAME"; | |
| 43 // Since "default", "pulse" and "dmix" devices are virtual devices mapped to | |
|
awong
2011/05/23 17:36:15
Newline before comment.
xians
2011/05/23 20:15:59
Done.
| |
| 44 // real devices, we remove them from the list to avoiding duplicate counting. | |
| 45 // In addition, note that we support no more than 2 channels for recording, | |
| 46 // hence surround devices are not stored in the list. Finally, output and | |
| 47 // null devices are not considered as valid devices for recording. | |
| 48 static const char kOutputDevice[] = "Output"; | |
| 49 static const char KNotWantedDefaultDevice[] = "default"; | |
| 50 static const char kNotWantedNullDevice[] = "null"; | |
| 51 static const char kNotWantedPulseDevice[] = "pulse"; | |
| 52 static const char kNotWantedDmixDevice[] = "dmix"; | |
| 53 static const char kNotWantedSurroundDevice[] = "surround"; | |
| 54 bool has_device(false); | |
| 55 void **hints = NULL; | |
| 56 | |
| 57 // Use the same approach to find the devices as in | |
| 58 // AlsaPcmOutputStream::FindDeviceForChannels | |
| 59 // Get Alsa device hints. | |
| 60 int error = wrapper_->DeviceNameHint(kGetAllDevices, | |
| 61 kPcmInterfaceName, | |
| 62 &hints); | |
| 63 if (error == 0) { | |
| 64 // NOTE: Do not early return from inside this if statement. The | |
|
awong
2011/05/23 17:36:15
This function is long anyways. Throw the whole bod
xians
2011/05/23 20:15:59
I made a helper function to do this. But I am actu
| |
| 65 // hints above need to be freed. | |
| 66 for (void** hint_iter = hints; *hint_iter != NULL; hint_iter++) { | |
| 67 // Only examine devices that are input capable.. Valid values are | |
| 68 // "Input", "Output", and NULL which means both input and output. | |
| 69 scoped_ptr_malloc<char> io(wrapper_->DeviceNameGetHint(*hint_iter, | |
| 70 kIoHintName)); | |
| 71 // Wrong device type, skip it. | |
| 72 if (io != NULL && | |
| 73 strncmp(kOutputDevice, io.get(), strlen(kOutputDevice)) == 0) | |
| 74 continue; | |
| 75 | |
| 76 scoped_ptr_malloc<char> hint_device_name( | |
| 77 wrapper_->DeviceNameGetHint(*hint_iter, kNameHintName)); | |
| 78 // Now check if if it is a valid device. | |
| 79 if (hint_device_name != NULL && | |
| 80 strncmp(KNotWantedDefaultDevice, | |
| 81 hint_device_name.get(), | |
| 82 strlen(KNotWantedDefaultDevice)) != 0 && | |
| 83 strncmp(kNotWantedNullDevice, | |
| 84 hint_device_name.get(), | |
| 85 strlen(kNotWantedNullDevice)) != 0 && | |
| 86 strncmp(kNotWantedPulseDevice, | |
| 87 hint_device_name.get(), | |
| 88 strlen(kNotWantedPulseDevice)) != 0 && | |
| 89 strncmp(kNotWantedDmixDevice, | |
| 90 hint_device_name.get(), | |
| 91 strlen(kNotWantedDmixDevice)) != 0 && | |
| 92 strncmp(kNotWantedSurroundDevice, | |
| 93 hint_device_name.get(), | |
| 94 strlen(kNotWantedSurroundDevice)) != 0) { | |
| 95 // Found a real and valid device. | |
| 96 has_device = true; | |
| 97 break; | |
| 98 } | |
| 99 } | |
| 100 } else { | |
| 101 LOG(ERROR) << "Unable to get device hints: " << wrapper_->StrError(error); | |
| 102 } | |
| 103 // Destory the hint now that we're done with it. | |
|
awong
2011/05/23 17:36:15
Newline before comment.
xians
2011/05/23 20:15:59
Done.
| |
| 104 wrapper_->DeviceNameFreeHint(hints); | |
| 105 hints = NULL; | |
| 106 return has_device; | |
| 35 } | 107 } |
| 36 | 108 |
| 37 AudioOutputStream* AudioManagerLinux::MakeAudioOutputStream( | 109 AudioOutputStream* AudioManagerLinux::MakeAudioOutputStream( |
| 38 AudioParameters params) { | 110 AudioParameters params) { |
| 39 // Early return for testing hook. Do this before checking for | 111 // Early return for testing hook. Do this before checking for |
| 40 // |initialized_|. | 112 // |initialized_|. |
| 41 if (params.format == AudioParameters::AUDIO_MOCK) { | 113 if (params.format == AudioParameters::AUDIO_MOCK) { |
| 42 return FakeAudioOutputStream::MakeFakeStream(params); | 114 return FakeAudioOutputStream::MakeFakeStream(params); |
| 43 } | 115 } |
| 44 | 116 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 | 212 |
| 141 void AudioManagerLinux::ShowAudioInputSettings() { | 213 void AudioManagerLinux::ShowAudioInputSettings() { |
| 142 scoped_ptr<base::Environment> env(base::Environment::Create()); | 214 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 143 base::nix::DesktopEnvironment desktop = base::nix::GetDesktopEnvironment( | 215 base::nix::DesktopEnvironment desktop = base::nix::GetDesktopEnvironment( |
| 144 env.get()); | 216 env.get()); |
| 145 std::string command((desktop == base::nix::DESKTOP_ENVIRONMENT_GNOME) ? | 217 std::string command((desktop == base::nix::DESKTOP_ENVIRONMENT_GNOME) ? |
| 146 "gnome-volume-control" : "kmix"); | 218 "gnome-volume-control" : "kmix"); |
| 147 base::LaunchApp(CommandLine(FilePath(command)), false, false, NULL); | 219 base::LaunchApp(CommandLine(FilePath(command)), false, false, NULL); |
| 148 } | 220 } |
| 149 | 221 |
| 222 void AudioManagerLinux::GetAudioInputDeviceNames( | |
| 223 AudioInputDeviceNames* device_names) { | |
| 224 // TODO(xians): query a full list of valid devices. | |
| 225 if (HasAudioInputDevices()) { | |
| 226 // Add the default device to the list. | |
| 227 // We use (device_name)_(index) to make up the unique_ids to identify the | |
| 228 // devices. For default device, the index is 0, so its unique_id is | |
| 229 // Default_0. | |
| 230 AudioInputDeviceName name; | |
| 231 name.device_name = AudioManagerBase::kDefaultDeviceName; | |
| 232 name.unique_id = StringPrintf("%s_0", AudioManagerBase::kDefaultDeviceName); | |
| 233 device_names->push_back(name); | |
| 234 } | |
| 235 } | |
| 236 | |
| 150 // static | 237 // static |
| 151 AudioManager* AudioManager::CreateAudioManager() { | 238 AudioManager* AudioManager::CreateAudioManager() { |
| 152 return new AudioManagerLinux(); | 239 return new AudioManagerLinux(); |
| 153 } | 240 } |
| OLD | NEW |