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

Unified Diff: chrome/browser/resources/whispernet_proxy/js/wrapper.js

Issue 637223011: Redesign the copresence audio handlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Created 6 years, 2 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
Index: chrome/browser/resources/whispernet_proxy/js/wrapper.js
diff --git a/chrome/browser/resources/whispernet_proxy/js/wrapper.js b/chrome/browser/resources/whispernet_proxy/js/wrapper.js
index 7c3262b1c5823fdcc6e280e47794b8337dfa2e28..064088d5139097fdeaaa0f3ace1a06f10a54b753 100644
--- a/chrome/browser/resources/whispernet_proxy/js/wrapper.js
+++ b/chrome/browser/resources/whispernet_proxy/js/wrapper.js
@@ -49,7 +49,7 @@ function WhisperEncoder(params, whisperNacl) {
sample_rate: params.sampleRate || 48000.0,
upsampling_factor: params.bitsPerSample || 16,
};
- this.whisperNacl_.send(JSON.stringify(msg));
+ this.whisperNacl_.send(msg);
}
/**
@@ -71,7 +71,7 @@ WhisperEncoder.prototype.encode = function(token, audible, raw) {
use_dtmf: audible,
return_raw_samples: raw
};
- this.whisperNacl_.send(JSON.stringify(msg));
+ this.whisperNacl_.send(msg);
};
/**
@@ -119,7 +119,7 @@ function WhisperDecoder(params, whisperNacl) {
max_candidates: 1,
max_buffer_duration_in_seconds: 3
};
- this.whisperNacl_.send(JSON.stringify(msg));
+ this.whisperNacl_.send(msg);
}
/**
@@ -129,7 +129,7 @@ WhisperDecoder.prototype.wipeDecoder = function() {
var msg = {
type: 'wipe_decode_buffer'
};
- this.whisperNacl_.send(JSON.stringify(msg));
+ this.whisperNacl_.send(msg);
};
/**
@@ -139,17 +139,34 @@ WhisperDecoder.prototype.detectBroadcast = function() {
var msg = {
type: 'detect_broadcast'
};
- this.whisperNacl_.send(JSON.stringify(msg));
+ this.whisperNacl_.send(msg);
};
/**
* Method to request the decoder to process samples.
+ * @param {string} type Type of decoding to perform.
Daniel Erat 2014/10/17 22:25:59 same here
rkc 2014/10/18 00:21:54 Ditto.
* @param {ArrayBuffer} samples Array of samples to process.
*/
-WhisperDecoder.prototype.processSamples = function(samples) {
- // For sample processing, the Nacl module doesn't expect any frills in the
- // message, just send the samples directly.
- this.whisperNacl_.send(samples);
+WhisperDecoder.prototype.processSamples = function(type, samples) {
+ // We set the type value to 01b for audible, 10b for inaudible and 11b for
+ // both. This is due to not having any other way of actually sharing enum
+ // values across JS/Nacl boundaries - hence, viva la 1980's coding vida!
+ var typeVal = 0;
+ if (type == 'audible') {
+ typeVal = 1;
+ } else if (type == 'inaudible') {
+ typeVal = 2;
+ } else if (type == 'both') {
+ typeVal = 3;
+ }
+
+ var msg = {
+ type: 'decode_tokens',
+ request_type: typeVal,
+ data: samples,
+ };
+
+ this.whisperNacl_.send(msg);
};
/**
@@ -179,7 +196,7 @@ WhisperDecoder.prototype.onDetectBroadcast = function(callback) {
WhisperDecoder.prototype.onNaclMessage_ = function(e) {
var msg = e.data;
if (msg.type == 'decode_tokens_response') {
- this.handleCandidates_(JSON.parse(msg.tokens), msg.audible);
+ this.handleCandidates_(msg.tokens, msg.audible);
} else if (msg.type == 'detect_broadcast_response') {
this.detectBroadcastCallback_(msg.detected);
}

Powered by Google App Engine
This is Rietveld 408576698