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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 callback_->OnError(this); | 176 callback_->OnError(this); |
177 callback_ = NULL; | 177 callback_ = NULL; |
178 cras_audio_format_destroy(audio_format); | 178 cras_audio_format_destroy(audio_format); |
179 return; | 179 return; |
180 } | 180 } |
181 | 181 |
182 // Before starting the stream, save the number of bytes in a frame for use in | 182 // Before starting the stream, save the number of bytes in a frame for use in |
183 // the callback. | 183 // the callback. |
184 bytes_per_frame_ = cras_client_format_bytes_per_frame(audio_format); | 184 bytes_per_frame_ = cras_client_format_bytes_per_frame(audio_format); |
185 | 185 |
186 // For a hotword hardware stream, only wait for a single callback. | |
187 // Replace the existing callback with the HotwordSampleReady one that should | |
188 // only run once. | |
189 if (params_.effects() & | |
190 AudioParameters::PlatformEffectsMask::HARDWARE_INPUT) { | |
191 if (cras_client_add_hotword_callback(client_, audio_format, | |
192 CrasInputStream::HotwordSampleReady)) { | |
193 DLOG(WARNING) << "Failed to add the hotword callback."; | |
194 callback_->OnError(this); | |
195 callback_ = NULL; | |
196 } | |
197 } | |
198 | |
dgreid
2014/09/17 21:16:23
This can go above the creation of stream_params, a
rpetterson
2014/09/17 21:32:00
I've moved it and wrapped it in an else sinc ei as
dgreid
2014/09/17 21:36:33
Yes put that in the else as well, there is no need
rpetterson
2014/09/17 21:40:20
Done.
| |
186 // Adding the stream will start the audio callbacks. | 199 // Adding the stream will start the audio callbacks. |
187 if (cras_client_add_stream(client_, &stream_id_, stream_params)) { | 200 if (cras_client_add_stream(client_, &stream_id_, stream_params)) { |
188 DLOG(WARNING) << "Failed to add the stream."; | 201 DLOG(WARNING) << "Failed to add the stream."; |
189 callback_->OnError(this); | 202 callback_->OnError(this); |
190 callback_ = NULL; | 203 callback_ = NULL; |
191 } | 204 } |
192 | 205 |
193 // Done with config params. | 206 // Done with config params. |
194 cras_audio_format_destroy(audio_format); | 207 cras_audio_format_destroy(audio_format); |
195 cras_client_stream_params_destroy(stream_params); | 208 cras_client_stream_params_destroy(stream_params); |
(...skipping 21 matching lines...) Expand all Loading... | |
217 cras_stream_id_t stream_id, | 230 cras_stream_id_t stream_id, |
218 uint8* samples, | 231 uint8* samples, |
219 size_t frames, | 232 size_t frames, |
220 const timespec* sample_ts, | 233 const timespec* sample_ts, |
221 void* arg) { | 234 void* arg) { |
222 CrasInputStream* me = static_cast<CrasInputStream*>(arg); | 235 CrasInputStream* me = static_cast<CrasInputStream*>(arg); |
223 me->ReadAudio(frames, samples, sample_ts); | 236 me->ReadAudio(frames, samples, sample_ts); |
224 return frames; | 237 return frames; |
225 } | 238 } |
226 | 239 |
240 // Static callback asking for a single sample. Run on high priority thread. | |
241 int CrasInputStream::HotwordSampleReady(cras_client* client, | |
242 cras_audio_format* fmt, | |
243 uint8* hotword_phrase, | |
244 size_t frames, | |
245 const timespec* sample_ts, | |
246 void* arg) { | |
247 CrasInputStream* me = static_cast<CrasInputStream*>(arg); | |
248 me->ReadAudio(frames, single_sample, sample_ts); | |
dgreid
2014/09/17 21:16:23
this can be as much as two seconds of audio. Does
rpetterson
2014/09/17 21:32:00
Question for Dale.
DaleCurtis
2014/09/17 22:29:22
Yes, this needs to be converted to match the param
rpetterson
2014/09/22 22:24:40
During construction of the stream? Which parameter
DaleCurtis
2014/09/22 23:49:44
As mentioned, the parameters passed in during cons
dgreid
2014/12/10 00:23:34
It might be better to do it here, call ReadAudio r
rpetterson
2014/12/10 00:37:43
I'm unclear here. What do I need to change?
dgreid
2014/12/10 00:54:49
ignore that comment. it must have been a draft fr
| |
249 return frames; | |
250 } | |
251 | |
227 // Static callback for stream errors. | 252 // Static callback for stream errors. |
228 int CrasInputStream::StreamError(cras_client* client, | 253 int CrasInputStream::StreamError(cras_client* client, |
229 cras_stream_id_t stream_id, | 254 cras_stream_id_t stream_id, |
230 int err, | 255 int err, |
231 void* arg) { | 256 void* arg) { |
232 CrasInputStream* me = static_cast<CrasInputStream*>(arg); | 257 CrasInputStream* me = static_cast<CrasInputStream*>(arg); |
233 me->NotifyStreamError(err); | 258 me->NotifyStreamError(err); |
234 return 0; | 259 return 0; |
235 } | 260 } |
236 | 261 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 | 328 |
304 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { | 329 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { |
305 return pow(10, dB / 20.0); | 330 return pow(10, dB / 20.0); |
306 } | 331 } |
307 | 332 |
308 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { | 333 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { |
309 return 20 * log10(volume_ratio); | 334 return 20 * log10(volume_ratio); |
310 } | 335 } |
311 | 336 |
312 } // namespace media | 337 } // namespace media |
OLD | NEW |