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/bind.h" | 10 #include "base/bind.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 100 } |
101 | 101 |
102 void CrasInputStream::Start(AudioInputCallback* callback) { | 102 void CrasInputStream::Start(AudioInputCallback* callback) { |
103 DCHECK(client_); | 103 DCHECK(client_); |
104 DCHECK(callback); | 104 DCHECK(callback); |
105 | 105 |
106 // If already playing, stop before re-starting. | 106 // If already playing, stop before re-starting. |
107 if (started_) | 107 if (started_) |
108 return; | 108 return; |
109 | 109 |
| 110 StartAgc(); |
| 111 |
110 callback_ = callback; | 112 callback_ = callback; |
111 LOG(ERROR) << "Input Start"; | 113 LOG(ERROR) << "Input Start"; |
112 | 114 |
113 // Prepare |audio_format| and |stream_params| for the stream we | 115 // Prepare |audio_format| and |stream_params| for the stream we |
114 // will create. | 116 // will create. |
115 cras_audio_format* audio_format = cras_audio_format_create( | 117 cras_audio_format* audio_format = cras_audio_format_create( |
116 alsa_util::BitsToFormat(params_.bits_per_sample()), | 118 alsa_util::BitsToFormat(params_.bits_per_sample()), |
117 params_.sample_rate(), | 119 params_.sample_rate(), |
118 params_.channels()); | 120 params_.channels()); |
119 if (!audio_format) { | 121 if (!audio_format) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 164 |
163 started_ = true; | 165 started_ = true; |
164 } | 166 } |
165 | 167 |
166 void CrasInputStream::Stop() { | 168 void CrasInputStream::Stop() { |
167 DCHECK(client_); | 169 DCHECK(client_); |
168 | 170 |
169 if (!callback_ || !started_) | 171 if (!callback_ || !started_) |
170 return; | 172 return; |
171 | 173 |
| 174 StopAgc(); |
| 175 |
172 // Removing the stream from the client stops audio. | 176 // Removing the stream from the client stops audio. |
173 cras_client_rm_stream(client_, stream_id_); | 177 cras_client_rm_stream(client_, stream_id_); |
174 | 178 |
175 audio_manager_->DecreaseActiveInputStreamCount(); | 179 audio_manager_->DecreaseActiveInputStreamCount(); |
176 | 180 |
177 started_ = false; | 181 started_ = false; |
178 } | 182 } |
179 | 183 |
180 // Static callback asking for samples. Run on high priority thread. | 184 // Static callback asking for samples. Run on high priority thread. |
181 int CrasInputStream::SamplesReady(cras_client* client, | 185 int CrasInputStream::SamplesReady(cras_client* client, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 latency_ts.tv_nsec / base::Time::kNanosecondsPerMicrosecond; | 219 latency_ts.tv_nsec / base::Time::kNanosecondsPerMicrosecond; |
216 double frames_latency = | 220 double frames_latency = |
217 latency_usec * params_.sample_rate() / base::Time::kMicrosecondsPerSecond; | 221 latency_usec * params_.sample_rate() / base::Time::kMicrosecondsPerSecond; |
218 unsigned int bytes_latency = | 222 unsigned int bytes_latency = |
219 static_cast<unsigned int>(frames_latency * bytes_per_frame_); | 223 static_cast<unsigned int>(frames_latency * bytes_per_frame_); |
220 | 224 |
221 // Update the AGC volume level once every second. Note that, |volume| is | 225 // Update the AGC volume level once every second. Note that, |volume| is |
222 // also updated each time SetVolume() is called through IPC by the | 226 // also updated each time SetVolume() is called through IPC by the |
223 // render-side AGC. | 227 // render-side AGC. |
224 double normalized_volume = 0.0; | 228 double normalized_volume = 0.0; |
225 QueryAgcVolume(&normalized_volume); | 229 GetAgcVolume(&normalized_volume); |
226 | 230 |
227 callback_->OnData(this, | 231 callback_->OnData(this, |
228 buffer, | 232 buffer, |
229 frames * bytes_per_frame_, | 233 frames * bytes_per_frame_, |
230 bytes_latency, | 234 bytes_latency, |
231 normalized_volume); | 235 normalized_volume); |
232 } | 236 } |
233 | 237 |
234 void CrasInputStream::NotifyStreamError(int err) { | 238 void CrasInputStream::NotifyStreamError(int err) { |
235 if (callback_) | 239 if (callback_) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 274 |
271 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { | 275 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { |
272 return pow(10, dB / 20.0); | 276 return pow(10, dB / 20.0); |
273 } | 277 } |
274 | 278 |
275 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { | 279 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { |
276 return 20 * log10(volume_ratio); | 280 return 20 * log10(volume_ratio); |
277 } | 281 } |
278 | 282 |
279 } // namespace media | 283 } // namespace media |
OLD | NEW |