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

Unified Diff: chrome/browser/resources/chromeos/emulator/audio_settings.js

Issue 1274403003: Full Implementation of Audio for the Chrome Os Device Emulator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Initial Patch Created 5 years, 4 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/chromeos/emulator/audio_settings.js
diff --git a/chrome/browser/resources/chromeos/emulator/audio_settings.js b/chrome/browser/resources/chromeos/emulator/audio_settings.js
new file mode 100644
index 0000000000000000000000000000000000000000..6ae13e853b4d71a88be853d3557a7c507f4a5b96
--- /dev/null
+++ b/chrome/browser/resources/chromeos/emulator/audio_settings.js
@@ -0,0 +1,165 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/** @enum {string} */ AudioNodeType = {
xiyuan 2015/08/07 20:17:12 nit: var AudioNodeType = {... "var" was missing.
mozartalouis 2015/08/07 22:44:07 Done.
+ HEADPHONE: 'HEADPHONE',
+ MIC: 'MIC',
+ USB: 'USB',
+ BLUETOOTH: 'BLUETOOTH',
+ HDMI: 'HDMI',
+ INTERNAL_SPEAKER: 'INTERNAL_SPEAKER',
+ INTERNAL_MIC: 'INTERNAL_MIC',
+ KEYBOARD_MIC: 'KEYBOARD_MIC',
+ AOKR: 'AOKR',
+ POST_MIX_LOOPBACK: 'POST_MIX_LOOPBACK',
+ POST_DSP_LOOPBACK: 'POST_DSP_LOOPBACK',
+ OTHER: 'OTHER',
+ NONE: '',
+};
+
+/**
+ * An audio node. Based on the struct AudioNode found in audio_node.h.
+ * @constructor
+ */
+var AudioNode = function() {
+ // Whether node will input or output audio.
+ this.isInput = false;
+
+ // Node ID.
+ this.id = '30001';
+
+ // Display name of the node. When this is empty, cras will automatically
+ // use |this.deviceName| as the display name.
+ this.name = '';
+
+ // The text label of the selected node name.
+ this.deviceName = 'New Device';
+
+ // Based on the AudioNodeType enum.
+ this.type = AudioNodeType.HEADPHONE;
+
+ // Whether the node is active or not.
+ this.active = false;
+
+ // The time the node was plugged in (in seconds).
+ this.pluggedTime = 0;
+};
+
+Polymer({
+ is: 'audio-settings',
+
+ properties: {
+ /**
+ * The title to be displayed in a heading element for the element.
+ */
+ title: {type: String},
+
+ /**
+ * A set of audio nodes.
+ * @type !Array<!AudioNode>
+ */
+ nodes: {type: Array, value: function() { return []; }},
+
+ /**
+ * A set of options for the possible audio node types.
+ * int |value| is based on the AudioType emumation.
+ * @type !Array<! {name: string, type: string} >
+ */
+ nodeTypeOptions: {
+ type: Array,
+ value: function() {
+ return [
+ {name: 'Headphones', type: AudioNodeType.HEADPHONE},
+ {name: 'Mic', type: AudioNodeType.MIC},
+ {name: 'Usb', type: AudioNodeType.USB},
+ {name: 'Bluetooth', type: AudioNodeType.BLUETOOTH},
+ {name: 'HDMI', type: AudioNodeType.HDMI},
+ {name: 'Internal Speaker', type: AudioNodeType.INTERNAL_SPEAKER},
+ {name: 'Internal Mic', type: AudioNodeType.INTERNAL_MIC},
+ {name: 'Keyboard Mic', type: AudioNodeType.KEYBOARD_MIC},
+ {name: 'Aokr', type: AudioNodeType.AOKR},
+ {name: 'Post Mix Loopback', type: AudioNodeType.POST_MIX_LOOPBACK},
+ {name: 'Post Dsp Loopback', type: AudioNodeType.POST_DSP_LOOPBACK},
+ {name: 'Other', type: AudioNodeType.OTHER}
+ ];
+ }
+ },
+ },
+
+ ready: function() { this.title = 'Audio Settings'; },
+
+ /**
+ * Adds a new node with default settings to the list of nodes.
+ */
+ appendNewNode: function() { this.push('nodes', new AudioNode()); },
michaelpg 2015/08/07 22:47:42 nit: don't put non-trivial functions all on one li
mozartalouis 2015/08/07 23:16:50 i think this was the work of clang-format. :/ won'
+
+ /**
+ * This adds or modifes an audio node to the AudioNodeList.
michaelpg 2015/08/07 22:47:42 nit: modifies
mozartalouis 2015/08/07 23:16:50 Done.
+ * @param {event} node.
michaelpg 2015/08/07 22:47:42 event -> Event
mozartalouis 2015/08/07 23:16:50 Done.
+ */
+ insertAudioNode: function(node) {
+ // Create a new audio node and add all the properties from |nodes[i]|
michaelpg 2015/08/07 22:47:42 nit: end w/ period
mozartalouis 2015/08/07 23:16:50 Done.
+ var info = this.nodes[node.path[2].dataIndex];
michaelpg 2015/08/07 22:47:42 node is an event, right? Rename the parameter to e
mozartalouis 2015/08/07 23:16:50 Done.
+ info.type = this.getAudioTypeForName(info.type);
+ chrome.send('insertAudioNode', [info]);
+ },
+
+ /**
+ * Removes the audio node with id |id|.
+ * @param {event} node.
+ */
+ removeAudioNode: function(node) {
+ var info = this.nodes[node.path[2].dataIndex];
+ chrome.send('removeAudioNode', [info.id]);
+ },
+
+ /**
+ * Returns the text for the label that corresponds to |type|.
+ * @param {string} type A string representing an AudioType
+ * of a node.
+ * @return {string} The label which represents |type|.
+ */
+ getNameForAudioType: function(type) {
+ for (var i = 0; i < this.nodeTypeOptions.length; ++i) {
+ if (this.nodeTypeOptions[i].type == type)
+ return this.nodeTypeOptions[i].name;
+ }
+ },
+
+ /**
+ * Returns the text for the label that corresponds to |name|.
+ * @param {string} name A string representing an AudioType
+ * of a nodes name.
+ * @return {string} The label which represents |name|.
+ */
+ getAudioTypeForName: function(name) {
+ for (var i = 0; i < this.nodeTypeOptions.length; ++i) {
+ if (this.nodeTypeOptions[i].name == name)
+ return this.nodeTypeOptions[i].type;
+ }
+ },
+
+ /**
+ * Called by the WebUI which provides a list of nodes.
+ * @param {!Array<!AudioNode>} nodeList A list of audio nodes.
+ */
+ updateAudioNodes: function(nodeList) {
+ /** @type {!Array<!AudioNode>} */ var newNodeList = [];
+ for (var i = 0; i < nodeList.length; ++i) {
+
+ // create a new audio node and add all the properties from |nodeList[i]|
+ var node = new AudioNode();
+
+ node.isInput = nodeList[i]['is_input'];
+ node.id = nodeList[i]['id'];
+ node.deviceName = nodeList[i]['device_name'];
+ node.type = this.getNameForAudioType(nodeList[i]['type']);
+ node.name = nodeList[i]['name'];
+ node.active = nodeList[i]['active'];
+
+ newNodeList.push(node);
+ }
+ this.nodes = newNodeList;
+ },
xiyuan 2015/08/07 20:17:12 nit: remove "," for the last property
mozartalouis 2015/08/07 22:44:07 Done.
michaelpg 2015/08/07 22:47:42 Some people like this as it makes it easier to add
+});

Powered by Google App Engine
This is Rietveld 408576698