Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Unified Diff: media/audio/cras/cras_input.cc

Issue 551823005: [Hotword] Adding audio parameters to handle audio coming from the DSP. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: put call to add stream in else statement Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/audio/cras/cras_input.h ('k') | media/audio/cras/cras_input_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
« no previous file with comments | « media/audio/cras/cras_input.h ('k') | media/audio/cras/cras_input_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698