Index: media/audio/cras/cras_input.cc |
diff --git a/media/audio/cras/cras_input.cc b/media/audio/cras/cras_input.cc |
index 0b8644603f8996e670b988c282a1b234e4062ee0..bdb0261df49c0066239943678c8c030060a210e0 100644 |
--- a/media/audio/cras/cras_input.cc |
+++ b/media/audio/cras/cras_input.cc |
@@ -159,8 +159,19 @@ void CrasInputStream::Start(AudioInputCallback* callback) { |
return; |
} |
- unsigned int frames_per_packet = params_.frames_per_buffer(); |
- cras_stream_params* stream_params = cras_client_stream_params_create( |
+ // For a hotword hardware stream, only wait for a single callback. |
+ // Replace the existing callback with the HotwordSampleReady one that should |
+ // only run once. |
+ if (params_.effects() & AudioParameters::PlatformEffectsMask::HOTWORD) { |
+ if (cras_client_add_hotword_callback(client_, audio_format, |
+ CrasInputStream::HotwordSampleReady)) { |
+ DLOG(WARNING) << "Failed to add the hotword callback."; |
+ callback_->OnError(this); |
+ callback_ = NULL; |
+ } |
+ }else { |
+ unsigned int frames_per_packet = params_.frames_per_buffer(); |
+ cras_stream_params* stream_params = cras_client_stream_params_create( |
stream_direction_, |
frames_per_packet, // Total latency. |
frames_per_packet, // Call back when this many ready. |
@@ -171,23 +182,24 @@ void CrasInputStream::Start(AudioInputCallback* callback) { |
CrasInputStream::SamplesReady, |
CrasInputStream::StreamError, |
audio_format); |
- if (!stream_params) { |
- DLOG(WARNING) << "Error setting up stream parameters."; |
- callback_->OnError(this); |
- callback_ = NULL; |
- cras_audio_format_destroy(audio_format); |
- return; |
- } |
- |
- // Before starting the stream, save the number of bytes in a frame for use in |
- // the callback. |
- bytes_per_frame_ = cras_client_format_bytes_per_frame(audio_format); |
- |
- // Adding the stream will start the audio callbacks. |
- if (cras_client_add_stream(client_, &stream_id_, stream_params)) { |
- DLOG(WARNING) << "Failed to add the stream."; |
- callback_->OnError(this); |
- callback_ = NULL; |
+ if (!stream_params) { |
+ DLOG(WARNING) << "Error setting up stream parameters."; |
+ callback_->OnError(this); |
+ callback_ = NULL; |
+ cras_audio_format_destroy(audio_format); |
+ return; |
+ } |
+ |
+ // Before starting the stream, save the number of bytes in a frame for use |
+ // in the callback. |
+ bytes_per_frame_ = cras_client_format_bytes_per_frame(audio_format); |
+ |
+ // Adding the stream will start the audio callbacks. |
+ if (cras_client_add_stream(client_, &stream_id_, stream_params)) { |
+ DLOG(WARNING) << "Failed to add the stream."; |
+ callback_->OnError(this); |
+ callback_ = NULL; |
+ } |
} |
// Done with config params. |
@@ -224,6 +236,18 @@ int CrasInputStream::SamplesReady(cras_client* client, |
return frames; |
} |
+// Static callback asking for a single sample. Run on high priority thread. |
+int CrasInputStream::HotwordSampleReady(cras_client* client, |
+ cras_audio_format* fmt, |
+ uint8* hotword_phrase, |
+ size_t frames, |
+ const timespec* sample_ts, |
+ void* arg) { |
+ CrasInputStream* me = static_cast<CrasInputStream*>(arg); |
+ me->ReadAudio(frames, single_sample, sample_ts); |
+ return frames; |
+} |
+ |
// Static callback for stream errors. |
int CrasInputStream::StreamError(cras_client* client, |
cras_stream_id_t stream_id, |