| 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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 AudioDeviceName(AudioManagerBase::kDefaultDeviceName, | 30 AudioDeviceName(AudioManagerBase::kDefaultDeviceName, |
| 31 AudioManagerBase::kDefaultDeviceId)); | 31 AudioManagerBase::kDefaultDeviceId)); |
| 32 } | 32 } |
| 33 | 33 |
| 34 // Maximum number of output streams that can be open simultaneously. | 34 // Maximum number of output streams that can be open simultaneously. |
| 35 static const int kMaxOutputStreams = 50; | 35 static const int kMaxOutputStreams = 50; |
| 36 | 36 |
| 37 // Default sample rate for input and output streams. | 37 // Default sample rate for input and output streams. |
| 38 static const int kDefaultSampleRate = 48000; | 38 static const int kDefaultSampleRate = 48000; |
| 39 | 39 |
| 40 // Define bounds for the output buffer size. | 40 // Minimum bound for the output buffer size. |
| 41 static const int kMinimumOutputBufferSize = 512; | 41 static const int kMinimumOutputBufferSize = 512; |
| 42 static const int kMaximumOutputBufferSize = 8192; | 42 |
| 43 // Maximum bound for the input and output buffer size. |
| 44 static const int kMaximumBufferSize = 8192; |
| 43 | 45 |
| 44 // Default input buffer size. | 46 // Default input buffer size. |
| 45 static const int kDefaultInputBufferSize = 1024; | 47 static const int kDefaultInputBufferSize = 1024; |
| 46 | 48 |
| 47 bool AudioManagerCras::HasAudioOutputDevices() { | 49 bool AudioManagerCras::HasAudioOutputDevices() { |
| 48 return true; | 50 return true; |
| 49 } | 51 } |
| 50 | 52 |
| 51 bool AudioManagerCras::HasAudioInputDevices() { | 53 bool AudioManagerCras::HasAudioInputDevices() { |
| 52 return true; | 54 return true; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 68 void AudioManagerCras::GetAudioInputDeviceNames( | 70 void AudioManagerCras::GetAudioInputDeviceNames( |
| 69 AudioDeviceNames* device_names) { | 71 AudioDeviceNames* device_names) { |
| 70 AddDefaultDevice(device_names); | 72 AddDefaultDevice(device_names); |
| 71 } | 73 } |
| 72 | 74 |
| 73 void AudioManagerCras::GetAudioOutputDeviceNames( | 75 void AudioManagerCras::GetAudioOutputDeviceNames( |
| 74 AudioDeviceNames* device_names) { | 76 AudioDeviceNames* device_names) { |
| 75 AddDefaultDevice(device_names); | 77 AddDefaultDevice(device_names); |
| 76 } | 78 } |
| 77 | 79 |
| 78 AudioParameters AudioManagerCras::GetInputStreamParameters( | 80 AudioParameters AudioManagerCras::GetPreferredInputStreamParameters( |
| 79 const std::string& device_id) { | 81 const std::string& input_device_id, |
| 82 const AudioParameters& input_params) { |
| 83 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
| 84 int sample_rate = kDefaultSampleRate; |
| 85 int buffer_size = kDefaultInputBufferSize; |
| 86 int bits_per_sample = 16; |
| 87 int input_channels = 0; |
| 88 if (input_params.IsValid()) { |
| 89 sample_rate = input_params.sample_rate(); |
| 90 bits_per_sample = input_params.bits_per_sample(); |
| 91 channel_layout = input_params.channel_layout(); |
| 92 input_channels = input_params.input_channels(); |
| 93 buffer_size = |
| 94 std::min(kMaximumBufferSize, input_params.frames_per_buffer()); |
| 95 } |
| 96 |
| 80 int user_buffer_size = GetUserBufferSize(); | 97 int user_buffer_size = GetUserBufferSize(); |
| 81 int buffer_size = user_buffer_size ? | 98 if (user_buffer_size) |
| 82 user_buffer_size : kDefaultInputBufferSize; | 99 buffer_size = user_buffer_size; |
| 100 |
| 83 | 101 |
| 84 // TODO(hshi): Fine-tune audio parameters based on |device_id|. The optimal | 102 // TODO(hshi): Fine-tune audio parameters based on |device_id|. The optimal |
| 85 // parameters for the loopback stream may differ from the default. | 103 // parameters for the loopback stream may differ from the default. |
| 86 return AudioParameters( | 104 return AudioParameters( |
| 87 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, | 105 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
| 88 kDefaultSampleRate, 16, buffer_size); | 106 sample_rate, bits_per_sample, buffer_size); |
| 89 } | 107 } |
| 90 | 108 |
| 91 AudioOutputStream* AudioManagerCras::MakeLinearOutputStream( | 109 AudioOutputStream* AudioManagerCras::MakeLinearOutputStream( |
| 92 const AudioParameters& params) { | 110 const AudioParameters& params) { |
| 93 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | 111 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
| 94 return MakeOutputStream(params); | 112 return MakeOutputStream(params); |
| 95 } | 113 } |
| 96 | 114 |
| 97 AudioOutputStream* AudioManagerCras::MakeLowLatencyOutputStream( | 115 AudioOutputStream* AudioManagerCras::MakeLowLatencyOutputStream( |
| 98 const AudioParameters& params, | 116 const AudioParameters& params, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 case 24: | 181 case 24: |
| 164 return SND_PCM_FORMAT_S24; | 182 return SND_PCM_FORMAT_S24; |
| 165 case 32: | 183 case 32: |
| 166 return SND_PCM_FORMAT_S32; | 184 return SND_PCM_FORMAT_S32; |
| 167 default: | 185 default: |
| 168 return SND_PCM_FORMAT_UNKNOWN; | 186 return SND_PCM_FORMAT_UNKNOWN; |
| 169 } | 187 } |
| 170 } | 188 } |
| 171 | 189 |
| 172 } // namespace media | 190 } // namespace media |
| OLD | NEW |