| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 cr.define('hotword', function() { | 5 cr.define('hotword', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Class used to manage the state of the NaCl recognizer plugin. Handles all | 9 * Class used to manage the state of the NaCl recognizer plugin. Handles all |
| 10 * control of the NaCl plugin, including creation, start, stop, trigger, and | 10 * control of the NaCl plugin, including creation, start, stop, trigger, and |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 return this.recognizerState_ == ManagerState_.RUNNING; | 98 return this.recognizerState_ == ManagerState_.RUNNING; |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 /** | 101 /** |
| 102 * Set a timeout. Only allow one timeout to exist at any given time. | 102 * Set a timeout. Only allow one timeout to exist at any given time. |
| 103 * @param {!function()} func | 103 * @param {!function()} func |
| 104 * @param {number} timeout | 104 * @param {number} timeout |
| 105 * @private | 105 * @private |
| 106 */ | 106 */ |
| 107 NaClManager.prototype.setTimeout_ = function(func, timeout) { | 107 NaClManager.prototype.setTimeout_ = function(func, timeout) { |
| 108 assert(!this.naclTimeoutId_); | 108 assert(!this.naclTimeoutId_, 'Timeout already exists'); |
| 109 this.naclTimeoutId_ = window.setTimeout( | 109 this.naclTimeoutId_ = window.setTimeout( |
| 110 function() { | 110 function() { |
| 111 this.naclTimeoutId_ = null; | 111 this.naclTimeoutId_ = null; |
| 112 func(); | 112 func(); |
| 113 }.bind(this), timeout); | 113 }.bind(this), timeout); |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 /** | 116 /** |
| 117 * Clears the current timeout. | 117 * Clears the current timeout. |
| 118 * @private | 118 * @private |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 return plugin; | 209 return plugin; |
| 210 }; | 210 }; |
| 211 | 211 |
| 212 /** | 212 /** |
| 213 * Initializes the NaCl manager. | 213 * Initializes the NaCl manager. |
| 214 * @param {!string} naclArch Either 'arm', 'x86-32' or 'x86-64'. | 214 * @param {!string} naclArch Either 'arm', 'x86-32' or 'x86-64'. |
| 215 * @param {!MediaStream} stream A stream containing an audio source track. | 215 * @param {!MediaStream} stream A stream containing an audio source track. |
| 216 * @return {boolean} True if the successful. | 216 * @return {boolean} True if the successful. |
| 217 */ | 217 */ |
| 218 NaClManager.prototype.initialize = function(naclArch, stream) { | 218 NaClManager.prototype.initialize = function(naclArch, stream) { |
| 219 assert(this.recognizerState_ == ManagerState_.UNINITIALIZED); | 219 assert(this.recognizerState_ == ManagerState_.UNINITIALIZED, |
| 220 'Recognizer not in uninitialized state. State: ' + |
| 221 this.recognizerState_); |
| 220 var langs = this.getPossibleLanguages_(); | 222 var langs = this.getPossibleLanguages_(); |
| 221 var i, j; | 223 var i, j; |
| 222 // For country-lang variations. For example, when combined with path it will | 224 // For country-lang variations. For example, when combined with path it will |
| 223 // attempt to find: '/x86-32_en-gb/', else '/x86-32_en/', else '/x86-32_/'. | 225 // attempt to find: '/x86-32_en-gb/', else '/x86-32_en/', else '/x86-32_/'. |
| 224 for (i = 0; i < langs.length; i++) { | 226 for (i = 0; i < langs.length; i++) { |
| 225 var folder = hotword.constants.SHARED_MODULE_ROOT + '/_platform_specific/' + | 227 var folder = hotword.constants.SHARED_MODULE_ROOT + '/_platform_specific/' + |
| 226 naclArch + '_' + langs[i] + '/'; | 228 naclArch + '_' + langs[i] + '/'; |
| 227 var dataSrc = folder + hotword.constants.File.RECOGNIZER_CONFIG; | 229 var dataSrc = folder + hotword.constants.File.RECOGNIZER_CONFIG; |
| 228 var pluginSrc = hotword.constants.SHARED_MODULE_ROOT + '/hotword_' + | 230 var pluginSrc = hotword.constants.SHARED_MODULE_ROOT + '/hotword_' + |
| 229 langs[i] + '.nmf'; | 231 langs[i] + '.nmf'; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 this.recognizerState_ = ManagerState_.SHUTDOWN; | 270 this.recognizerState_ = ManagerState_.SHUTDOWN; |
| 269 this.stream_ = null; | 271 this.stream_ = null; |
| 270 }; | 272 }; |
| 271 | 273 |
| 272 /** | 274 /** |
| 273 * Sends data to the NaCl plugin. | 275 * Sends data to the NaCl plugin. |
| 274 * @param {!string} data Command to be sent to NaCl plugin. | 276 * @param {!string} data Command to be sent to NaCl plugin. |
| 275 * @private | 277 * @private |
| 276 */ | 278 */ |
| 277 NaClManager.prototype.sendDataToPlugin_ = function(data) { | 279 NaClManager.prototype.sendDataToPlugin_ = function(data) { |
| 278 assert(this.recognizerState_ != ManagerState_.UNINITIALIZED); | 280 assert(this.recognizerState_ != ManagerState_.UNINITIALIZED, |
| 281 'Recognizer in uninitialized state'); |
| 279 this.plugin_.postMessage(data); | 282 this.plugin_.postMessage(data); |
| 280 }; | 283 }; |
| 281 | 284 |
| 282 /** | 285 /** |
| 283 * Waits, with a timeout, for a message to be received from the plugin. If the | 286 * Waits, with a timeout, for a message to be received from the plugin. If the |
| 284 * message is not seen within the timeout, dispatch an 'error' event and go into | 287 * message is not seen within the timeout, dispatch an 'error' event and go into |
| 285 * the ERROR state. | 288 * the ERROR state. |
| 286 * @param {number} timeout Timeout, in milliseconds, to wait for the message. | 289 * @param {number} timeout Timeout, in milliseconds, to wait for the message. |
| 287 * @param {!string} message Message to wait for. | 290 * @param {!string} message Message to wait for. |
| 288 * @private | 291 * @private |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 break; | 429 break; |
| 427 } | 430 } |
| 428 } | 431 } |
| 429 }; | 432 }; |
| 430 | 433 |
| 431 return { | 434 return { |
| 432 NaClManager: NaClManager | 435 NaClManager: NaClManager |
| 433 }; | 436 }; |
| 434 | 437 |
| 435 }); | 438 }); |
| OLD | NEW |