Commit c15c2b91 authored by amistry's avatar amistry Committed by Commit bot

Make availability of hotword hardware known to hotword component extension.

BUG=465971

Review URL: https://codereview.chromium.org/1011813006

Cr-Commit-Position: refs/heads/master@{#321525}
parent 4f4f19d7
...@@ -160,6 +160,7 @@ bool HotwordPrivateGetStatusFunction::RunSync() { ...@@ -160,6 +160,7 @@ bool HotwordPrivateGetStatusFunction::RunSync() {
result.audio_logging_enabled = false; result.audio_logging_enabled = false;
result.always_on_enabled = false; result.always_on_enabled = false;
result.user_is_active = false; result.user_is_active = false;
result.hotword_hardware_available = false;
} else { } else {
result.available = false; result.available = false;
result.always_on_available = false; result.always_on_available = false;
...@@ -173,6 +174,8 @@ bool HotwordPrivateGetStatusFunction::RunSync() { ...@@ -173,6 +174,8 @@ bool HotwordPrivateGetStatusFunction::RunSync() {
result.training_enabled = hotword_service->IsTraining(); result.training_enabled = hotword_service->IsTraining();
result.always_on_enabled = hotword_service->IsAlwaysOnEnabled(); result.always_on_enabled = hotword_service->IsAlwaysOnEnabled();
result.user_is_active = hotword_service->UserIsActive(); result.user_is_active = hotword_service->UserIsActive();
result.hotword_hardware_available =
HotwordService::IsHotwordHardwareAvailable();
} }
PrefService* prefs = GetProfile()->GetPrefs(); PrefService* prefs = GetProfile()->GetPrefs();
......
...@@ -11,6 +11,12 @@ cr.define('hotword.constants', function() { ...@@ -11,6 +11,12 @@ cr.define('hotword.constants', function() {
*/ */
var AUDIO_LOG_SECONDS = 2; var AUDIO_LOG_SECONDS = 2;
/**
* Timeout in seconds, for detecting false positives with a hotword stream.
* @const {number}
*/
var HOTWORD_STREAM_TIMEOUT_SECONDS = 2;
/** /**
* Hotword data shared module extension's ID. * Hotword data shared module extension's ID.
* @const {string} * @const {string}
...@@ -117,6 +123,7 @@ var NaClPlugin = { ...@@ -117,6 +123,7 @@ var NaClPlugin = {
MODEL_PREFIX: 'm', MODEL_PREFIX: 'm',
STOP: 's', STOP: 's',
LOG: 'l', LOG: 'l',
DSP: 'd',
BEGIN_SPEAKER_MODEL: 'b', BEGIN_SPEAKER_MODEL: 'b',
ADAPT_SPEAKER_MODEL: 'a', ADAPT_SPEAKER_MODEL: 'a',
FINISH_SPEAKER_MODEL: 'f', FINISH_SPEAKER_MODEL: 'f',
...@@ -276,6 +283,7 @@ return { ...@@ -276,6 +283,7 @@ return {
CLIENT_PORT_NAME: CLIENT_PORT_NAME, CLIENT_PORT_NAME: CLIENT_PORT_NAME,
COMMAND_FIELD_NAME: COMMAND_FIELD_NAME, COMMAND_FIELD_NAME: COMMAND_FIELD_NAME,
FILE_SYSTEM_SIZE_BYTES: FILE_SYSTEM_SIZE_BYTES, FILE_SYSTEM_SIZE_BYTES: FILE_SYSTEM_SIZE_BYTES,
HOTWORD_STREAM_TIMEOUT_SECONDS: HOTWORD_STREAM_TIMEOUT_SECONDS,
NUM_TRAINING_UTTERANCES: NUM_TRAINING_UTTERANCES, NUM_TRAINING_UTTERANCES: NUM_TRAINING_UTTERANCES,
SHARED_MODULE_ID: SHARED_MODULE_ID, SHARED_MODULE_ID: SHARED_MODULE_ID,
SHARED_MODULE_ROOT: SHARED_MODULE_ROOT, SHARED_MODULE_ROOT: SHARED_MODULE_ROOT,
......
...@@ -11,10 +11,12 @@ cr.define('hotword', function() { ...@@ -11,10 +11,12 @@ cr.define('hotword', function() {
* shutdown. * shutdown.
* *
* @param {boolean} loggingEnabled Whether audio logging is enabled. * @param {boolean} loggingEnabled Whether audio logging is enabled.
* @param {boolean} hotwordStream Whether the audio input stream is from a
* hotword stream.
* @constructor * @constructor
* @extends {cr.EventTarget} * @extends {cr.EventTarget}
*/ */
function NaClManager(loggingEnabled) { function NaClManager(loggingEnabled, hotwordStream) {
/** /**
* Current state of this manager. * Current state of this manager.
* @private {hotword.NaClManager.ManagerState_} * @private {hotword.NaClManager.ManagerState_}
...@@ -69,6 +71,12 @@ function NaClManager(loggingEnabled) { ...@@ -69,6 +71,12 @@ function NaClManager(loggingEnabled) {
*/ */
this.loggingEnabled_ = loggingEnabled; this.loggingEnabled_ = loggingEnabled;
/**
* Whether the audio input stream is from a hotword stream.
* @private {boolean}
*/
this.hotwordStream_ = hotwordStream;
/** /**
* Audio log of X seconds before hotword triggered. * Audio log of X seconds before hotword triggered.
* @private {?Object} * @private {?Object}
...@@ -432,6 +440,13 @@ NaClManager.prototype.handleRequestModel_ = function() { ...@@ -432,6 +440,13 @@ NaClManager.prototype.handleRequestModel_ = function() {
hotword.constants.NaClPlugin.LOG + ':' + hotword.constants.NaClPlugin.LOG + ':' +
hotword.constants.AUDIO_LOG_SECONDS); hotword.constants.AUDIO_LOG_SECONDS);
} }
// If the audio stream is from a hotword stream, tell the plugin.
if (this.hotwordStream_) {
this.sendDataToPlugin_(
hotword.constants.NaClPlugin.DSP + ':' +
hotword.constants.HOTWORD_STREAM_TIMEOUT_SECONDS);
}
}; };
/** /**
......
...@@ -301,7 +301,10 @@ cr.define('hotword', function() { ...@@ -301,7 +301,10 @@ cr.define('hotword', function() {
if (!this.pluginManager_) { if (!this.pluginManager_) {
this.state_ = State_.STARTING; this.state_ = State_.STARTING;
this.pluginManager_ = new hotword.NaClManager(this.loggingEnabled_); var isHotwordStream = this.isAlwaysOnEnabled() &&
this.hotwordStatus_.hotwordHardwareAvailable;
this.pluginManager_ = new hotword.NaClManager(this.loggingEnabled_,
isHotwordStream);
this.pluginManager_.addEventListener(hotword.constants.Event.READY, this.pluginManager_.addEventListener(hotword.constants.Event.READY,
this.onReady_.bind(this)); this.onReady_.bind(this));
this.pluginManager_.addEventListener(hotword.constants.Event.ERROR, this.pluginManager_.addEventListener(hotword.constants.Event.ERROR,
......
...@@ -50,6 +50,10 @@ ...@@ -50,6 +50,10 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#if defined(OS_CHROMEOS)
#include "chromeos/audio/cras_audio_handler.h"
#endif
using extensions::BrowserContextKeyedAPIFactory; using extensions::BrowserContextKeyedAPIFactory;
using extensions::HotwordPrivateEventService; using extensions::HotwordPrivateEventService;
...@@ -298,6 +302,23 @@ bool HotwordService::IsExperimentalHotwordingEnabled() { ...@@ -298,6 +302,23 @@ bool HotwordService::IsExperimentalHotwordingEnabled() {
return true; return true;
} }
// static
bool HotwordService::IsHotwordHardwareAvailable() {
#if defined(OS_CHROMEOS)
if (chromeos::CrasAudioHandler::IsInitialized()) {
chromeos::AudioDeviceList devices;
chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices);
for (size_t i = 0; i < devices.size(); ++i) {
if (devices[i].type == chromeos::AUDIO_TYPE_AOKR) {
DCHECK(devices[i].is_input);
return true;
}
}
}
#endif
return false;
}
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
class HotwordService::HotwordUserSessionStateObserver class HotwordService::HotwordUserSessionStateObserver
: public user_manager::UserManager::UserSessionStateObserver { : public user_manager::UserManager::UserSessionStateObserver {
......
...@@ -64,6 +64,9 @@ class HotwordService : public extensions::ExtensionRegistryObserver, ...@@ -64,6 +64,9 @@ class HotwordService : public extensions::ExtensionRegistryObserver,
// TODO(amistry): Remove this. // TODO(amistry): Remove this.
static bool IsExperimentalHotwordingEnabled(); static bool IsExperimentalHotwordingEnabled();
// Returns true if hotwording hardware is available.
static bool IsHotwordHardwareAvailable();
explicit HotwordService(Profile* profile); explicit HotwordService(Profile* profile);
~HotwordService() override; ~HotwordService() override;
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/common/chrome_version_info.h" #include "chrome/common/chrome_version_info.h"
#include "chromeos/audio/cras_audio_handler.h"
#endif #endif
using content::BrowserContext; using content::BrowserContext;
...@@ -53,15 +52,8 @@ bool HotwordServiceFactory::IsAlwaysOnAvailable() { ...@@ -53,15 +52,8 @@ bool HotwordServiceFactory::IsAlwaysOnAvailable() {
if ((channel == chrome::VersionInfo::CHANNEL_UNKNOWN || if ((channel == chrome::VersionInfo::CHANNEL_UNKNOWN ||
channel == chrome::VersionInfo::CHANNEL_CANARY || channel == chrome::VersionInfo::CHANNEL_CANARY ||
channel == chrome::VersionInfo::CHANNEL_DEV) && channel == chrome::VersionInfo::CHANNEL_DEV) &&
chromeos::CrasAudioHandler::IsInitialized()) { HotwordService::IsHotwordHardwareAvailable()) {
chromeos::AudioDeviceList devices; return true;
chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices);
for (size_t i = 0; i < devices.size(); ++i) {
if (devices[i].type == chromeos::AUDIO_TYPE_AOKR) {
DCHECK(devices[i].is_input);
return true;
}
}
} }
#endif #endif
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
......
...@@ -42,6 +42,9 @@ namespace hotwordPrivate { ...@@ -42,6 +42,9 @@ namespace hotwordPrivate {
// Whether the user corresponding to this profile is the active user. // Whether the user corresponding to this profile is the active user.
boolean userIsActive; boolean userIsActive;
// Whether hotword hardware is available if requested.
boolean hotwordHardwareAvailable;
}; };
dictionary LaunchState { dictionary LaunchState {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment