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() {
result.audio_logging_enabled = false;
result.always_on_enabled = false;
result.user_is_active = false;
result.hotword_hardware_available = false;
} else {
result.available = false;
result.always_on_available = false;
......@@ -173,6 +174,8 @@ bool HotwordPrivateGetStatusFunction::RunSync() {
result.training_enabled = hotword_service->IsTraining();
result.always_on_enabled = hotword_service->IsAlwaysOnEnabled();
result.user_is_active = hotword_service->UserIsActive();
result.hotword_hardware_available =
HotwordService::IsHotwordHardwareAvailable();
}
PrefService* prefs = GetProfile()->GetPrefs();
......
......@@ -11,6 +11,12 @@ cr.define('hotword.constants', function() {
*/
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.
* @const {string}
......@@ -117,6 +123,7 @@ var NaClPlugin = {
MODEL_PREFIX: 'm',
STOP: 's',
LOG: 'l',
DSP: 'd',
BEGIN_SPEAKER_MODEL: 'b',
ADAPT_SPEAKER_MODEL: 'a',
FINISH_SPEAKER_MODEL: 'f',
......@@ -276,6 +283,7 @@ return {
CLIENT_PORT_NAME: CLIENT_PORT_NAME,
COMMAND_FIELD_NAME: COMMAND_FIELD_NAME,
FILE_SYSTEM_SIZE_BYTES: FILE_SYSTEM_SIZE_BYTES,
HOTWORD_STREAM_TIMEOUT_SECONDS: HOTWORD_STREAM_TIMEOUT_SECONDS,
NUM_TRAINING_UTTERANCES: NUM_TRAINING_UTTERANCES,
SHARED_MODULE_ID: SHARED_MODULE_ID,
SHARED_MODULE_ROOT: SHARED_MODULE_ROOT,
......
......@@ -11,10 +11,12 @@ cr.define('hotword', function() {
* shutdown.
*
* @param {boolean} loggingEnabled Whether audio logging is enabled.
* @param {boolean} hotwordStream Whether the audio input stream is from a
* hotword stream.
* @constructor
* @extends {cr.EventTarget}
*/
function NaClManager(loggingEnabled) {
function NaClManager(loggingEnabled, hotwordStream) {
/**
* Current state of this manager.
* @private {hotword.NaClManager.ManagerState_}
......@@ -69,6 +71,12 @@ function NaClManager(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.
* @private {?Object}
......@@ -432,6 +440,13 @@ NaClManager.prototype.handleRequestModel_ = function() {
hotword.constants.NaClPlugin.LOG + ':' +
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() {
if (!this.pluginManager_) {
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.onReady_.bind(this));
this.pluginManager_.addEventListener(hotword.constants.Event.ERROR,
......
......@@ -50,6 +50,10 @@
#include "ui/base/l10n/l10n_util.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::HotwordPrivateEventService;
......@@ -298,6 +302,23 @@ bool HotwordService::IsExperimentalHotwordingEnabled() {
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)
class HotwordService::HotwordUserSessionStateObserver
: public user_manager::UserManager::UserSessionStateObserver {
......
......@@ -64,6 +64,9 @@ class HotwordService : public extensions::ExtensionRegistryObserver,
// TODO(amistry): Remove this.
static bool IsExperimentalHotwordingEnabled();
// Returns true if hotwording hardware is available.
static bool IsHotwordHardwareAvailable();
explicit HotwordService(Profile* profile);
~HotwordService() override;
......
......@@ -17,7 +17,6 @@
#if defined(OS_CHROMEOS)
#include "chrome/common/chrome_version_info.h"
#include "chromeos/audio/cras_audio_handler.h"
#endif
using content::BrowserContext;
......@@ -53,15 +52,8 @@ bool HotwordServiceFactory::IsAlwaysOnAvailable() {
if ((channel == chrome::VersionInfo::CHANNEL_UNKNOWN ||
channel == chrome::VersionInfo::CHANNEL_CANARY ||
channel == chrome::VersionInfo::CHANNEL_DEV) &&
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;
}
}
HotwordService::IsHotwordHardwareAvailable()) {
return true;
}
#endif
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
......
......@@ -42,6 +42,9 @@ namespace hotwordPrivate {
// Whether the user corresponding to this profile is the active user.
boolean userIsActive;
// Whether hotword hardware is available if requested.
boolean hotwordHardwareAvailable;
};
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