Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/cras_input.h" | 5 #include "media/audio/cras/cras_input.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 | 95 |
| 96 // Signal to the manager that we're closed and can be removed. | 96 // Signal to the manager that we're closed and can be removed. |
| 97 // Should be last call in the method as it deletes "this". | 97 // Should be last call in the method as it deletes "this". |
| 98 audio_manager_->ReleaseInputStream(this); | 98 audio_manager_->ReleaseInputStream(this); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void CrasInputStream::Start(AudioInputCallback* callback) { | 101 void CrasInputStream::Start(AudioInputCallback* callback) { |
| 102 DCHECK(client_); | 102 DCHECK(client_); |
| 103 DCHECK(callback); | 103 DCHECK(callback); |
| 104 | 104 |
| 105 // Channel map to CRAS_CHANNEL, values in the same order of | |
| 106 // corresponding source in Chromium defined Channels. | |
| 107 static const int kChannelMap[] = { | |
| 108 CRAS_CH_FL, | |
| 109 CRAS_CH_FR, | |
| 110 CRAS_CH_FC, | |
| 111 CRAS_CH_LFE, | |
| 112 CRAS_CH_RL, | |
| 113 CRAS_CH_RR, | |
| 114 CRAS_CH_FLC, | |
| 115 CRAS_CH_FRC, | |
| 116 CRAS_CH_RC, | |
| 117 CRAS_CH_SL, | |
| 118 CRAS_CH_SR | |
| 119 }; | |
| 120 | |
| 105 // If already playing, stop before re-starting. | 121 // If already playing, stop before re-starting. |
| 106 if (started_) | 122 if (started_) |
| 107 return; | 123 return; |
| 108 | 124 |
| 109 StartAgc(); | 125 StartAgc(); |
| 110 | 126 |
| 111 callback_ = callback; | 127 callback_ = callback; |
| 112 | 128 |
| 113 // Prepare |audio_format| and |stream_params| for the stream we | 129 // Prepare |audio_format| and |stream_params| for the stream we |
| 114 // will create. | 130 // will create. |
| 115 cras_audio_format* audio_format = cras_audio_format_create( | 131 cras_audio_format* audio_format = cras_audio_format_create( |
| 116 AudioManagerCras::BitsToFormat(params_.bits_per_sample()), | 132 AudioManagerCras::BitsToFormat(params_.bits_per_sample()), |
| 117 params_.sample_rate(), | 133 params_.sample_rate(), |
| 118 params_.channels()); | 134 params_.channels()); |
| 119 if (!audio_format) { | 135 if (!audio_format) { |
| 120 DLOG(WARNING) << "Error setting up audio parameters."; | 136 DLOG(WARNING) << "Error setting up audio parameters."; |
| 121 callback_->OnError(this); | 137 callback_->OnError(this); |
| 122 callback_ = NULL; | 138 callback_ = NULL; |
| 123 return; | 139 return; |
| 124 } | 140 } |
| 125 | 141 |
| 142 // Inivialize channel layout to all -1 to indicate that non of | |
|
dgreid
2014/09/02 16:07:27
none
| |
| 143 // the channels is set in the layout. | |
| 144 int8 layout[CRAS_CH_MAX]; | |
| 145 for (size_t i = 0; i < CRAS_CH_MAX; i++) | |
| 146 layout[i] = -1; | |
| 147 | |
| 148 // Converts to CRAS defined channels. ChannelOrder will return -1 | |
| 149 // for channels that does not present in params_.channel_layout(). | |
|
dgreid
2014/09/02 16:07:27
s/does/are/
| |
| 150 for (size_t i = 0; i < arraysize(kChannelMap); ++i) | |
| 151 layout[kChannelMap[i]] = ChannelOrder(params_.channel_layout(), | |
| 152 static_cast<Channels>(i)); | |
| 153 if (cras_audio_format_set_channel_layout(audio_format, layout)) { | |
| 154 LOG(WARNING) << "Error setting channel layout."; | |
| 155 callback->OnError(this); | |
| 156 return; | |
| 157 } | |
| 158 | |
| 126 unsigned int frames_per_packet = params_.frames_per_buffer(); | 159 unsigned int frames_per_packet = params_.frames_per_buffer(); |
| 127 cras_stream_params* stream_params = cras_client_stream_params_create( | 160 cras_stream_params* stream_params = cras_client_stream_params_create( |
| 128 stream_direction_, | 161 stream_direction_, |
| 129 frames_per_packet, // Total latency. | 162 frames_per_packet, // Total latency. |
| 130 frames_per_packet, // Call back when this many ready. | 163 frames_per_packet, // Call back when this many ready. |
| 131 frames_per_packet, // Minimum Callback level ignored for capture streams. | 164 frames_per_packet, // Minimum Callback level ignored for capture streams. |
| 132 CRAS_STREAM_TYPE_DEFAULT, | 165 CRAS_STREAM_TYPE_DEFAULT, |
| 133 0, // Unused flags. | 166 0, // Unused flags. |
| 134 this, | 167 this, |
| 135 CrasInputStream::SamplesReady, | 168 CrasInputStream::SamplesReady, |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 | 300 |
| 268 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { | 301 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { |
| 269 return pow(10, dB / 20.0); | 302 return pow(10, dB / 20.0); |
| 270 } | 303 } |
| 271 | 304 |
| 272 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { | 305 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { |
| 273 return 20 * log10(volume_ratio); | 306 return 20 * log10(volume_ratio); |
| 274 } | 307 } |
| 275 | 308 |
| 276 } // namespace media | 309 } // namespace media |
| OLD | NEW |