Commit cd715fd3 authored by David Tseng's avatar David Tseng Committed by Commit Bot

Do not pan when audio is through internal speakers

Bug: 874102
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: I64ae721146a6ac631800bd0bbd1ca6cca9f522f8
Reviewed-on: https://chromium-review.googlesource.com/1172741
Commit-Queue: David Tseng <dtseng@chromium.org>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarKatie Dektar <katie@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583060}
parent 4de31cf0
......@@ -36,7 +36,7 @@ EarconEngine = function() {
this.baseDelay = 0.045;
/** @type {number} The master stereo panning, from -1 to 1. */
this.masterPan = 0;
this.masterPan = EarconEngine.CENTER_PAN_;
/** @type {number} The master reverb level as an amplification factor. */
this.masterReverb = 0.4;
......@@ -157,6 +157,12 @@ EarconEngine.BASE_URL = chrome.extension.getURL('cvox2/background/earcons/');
*/
EarconEngine.MAX_PAN_ABS_X_POSITION = 4;
/**
* Default (centered) pan position.
* @const {number}
*/
EarconEngine.CENTER_PAN_ = 0;
/**
* Fetches a sound asynchronously and loads its data into an AudioBuffer.
*
......@@ -718,3 +724,10 @@ EarconEngine.prototype.setPositionForRect = function(rect, container) {
this.masterPan = x;
};
/**
* Resets panning to default (centered).
*/
EarconEngine.prototype.resetPan = function() {
this.masterPan = EarconEngine.CENTER_PAN_;
};
......@@ -30,6 +30,15 @@ NextEarcons = function() {
* @private
*/
this.engine_ = new EarconEngine();
/** @private {boolean} */
this.shouldPan_ = true;
chrome.audio.getDevices(
{isActive: true, streamTypes: [chrome.audio.StreamType.OUTPUT]},
this.updateShouldPanForDevices_.bind(this));
chrome.audio.onDeviceListChanged.addListener(
this.updateShouldPanForDevices_.bind(this));
};
NextEarcons.prototype = {
......@@ -53,7 +62,10 @@ NextEarcons.prototype = {
var node = ChromeVoxState.instance.currentRange.start.node;
var rect = opt_location || node.location;
var container = node.root.location;
this.engine_.setPositionForRect(rect, container);
if (this.shouldPan_)
this.engine_.setPositionForRect(rect, container);
else
this.engine_.resetPan();
}
switch (earcon) {
case cvox.Earcon.ALERT_MODAL:
......@@ -133,4 +145,17 @@ NextEarcons.prototype = {
break;
}
},
/**
* Updates |this.shouldPan_| based on whether internal speakers are active or
* not.
* @param {Array<chrome.audio.AudioDeviceInfo>} devices
* @private
*/
updateShouldPanForDevices_: function(devices) {
this.shouldPan_ = !devices.some((device) => {
return device.isActive &&
device.deviceType == chrome.audio.DeviceType.INTERNAL_SPEAKER;
});
},
};
......@@ -14,6 +14,7 @@
},
"permissions": [
"accessibilityPrivate",
"audio",
"bookmarks",
"brailleDisplayPrivate",
"clipboardRead",
......
......@@ -46,6 +46,10 @@ _ACCESSIBILITY_PRIVATE_EXTERNS = (
ChromeRootPath(
'third_party/closure_compiler/externs/accessibility_private.js'))
# Audio API externs file.
_AUDIO_EXTERNS = (
ChromeRootPath('third_party/closure_compiler/externs/audio.js'))
# Automation API externs file.
_AUTOMATION_EXTERNS = (
ChromeRootPath('third_party/closure_compiler/externs/automation.js'))
......@@ -74,6 +78,7 @@ _COMMON_EXTERNS = [
CVoxPath('chromevox/background/externs.js'),
CVoxPath('host/chrome/externs.js'),
_ACCESSIBILITY_PRIVATE_EXTERNS,
_AUDIO_EXTERNS,
_AUTOMATION_EXTERNS,
_CHROME_EXTERNS,
_CHROME_EXTENSIONS_EXTERNS,
......
......@@ -31,6 +31,7 @@ class AudioAPI : public BrowserContextKeyedAPI, public AudioService::Observer {
// BrowserContextKeyedAPI implementation.
static BrowserContextKeyedAPIFactory<AudioAPI>* GetFactoryInstance();
static const bool kServiceRedirectedInIncognito = true;
// AudioService::Observer implementation.
void OnDeviceChanged() override;
......
......@@ -83,6 +83,14 @@
"platforms": ["chromeos"],
"session_types": ["kiosk"]
},
{
"channel": "stable",
"extension_types": ["extension"],
"platforms": ["chromeos"],
"whitelist": [
"75C7F4B720314B6CB1B5817CD86089DB95CD2461" // http://crbug.com/874102
]
},
{
"channel": "dev",
"extension_types": ["platform_app"]
......
// Copyright 2018 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.
// This file was generated by:
// tools/json_schema_compiler/compiler.py.
// NOTE: The format of types has changed. 'FooType' is now
// 'chrome.audio.FooType'.
// Please run the closure compiler before committing changes.
// See https://chromium.googlesource.com/chromium/src/+/master/docs/closure_compilation.md
/** @fileoverview Externs generated from namespace: audio */
/**
* @const
*/
chrome.audio = {};
/**
* @enum {string}
* @see https://developer.chrome.com/extensions/audio#type-StreamType
*/
chrome.audio.StreamType = {
INPUT: 'INPUT',
OUTPUT: 'OUTPUT',
};
/**
* @enum {string}
* @see https://developer.chrome.com/extensions/audio#type-DeviceType
*/
chrome.audio.DeviceType = {
HEADPHONE: 'HEADPHONE',
MIC: 'MIC',
USB: 'USB',
BLUETOOTH: 'BLUETOOTH',
HDMI: 'HDMI',
INTERNAL_SPEAKER: 'INTERNAL_SPEAKER',
INTERNAL_MIC: 'INTERNAL_MIC',
FRONT_MIC: 'FRONT_MIC',
REAR_MIC: 'REAR_MIC',
KEYBOARD_MIC: 'KEYBOARD_MIC',
HOTWORD: 'HOTWORD',
LINEOUT: 'LINEOUT',
POST_MIX_LOOPBACK: 'POST_MIX_LOOPBACK',
POST_DSP_LOOPBACK: 'POST_DSP_LOOPBACK',
OTHER: 'OTHER',
};
/**
* @typedef {{
* id: string,
* name: string,
* isActive: boolean,
* isMuted: boolean,
* volume: number
* }}
* @see https://developer.chrome.com/extensions/audio#type-OutputDeviceInfo
*/
chrome.audio.OutputDeviceInfo;
/**
* @typedef {{
* id: string,
* name: string,
* isActive: boolean,
* isMuted: boolean,
* gain: number
* }}
* @see https://developer.chrome.com/extensions/audio#type-InputDeviceInfo
*/
chrome.audio.InputDeviceInfo;
/**
* @typedef {{
* id: string,
* streamType: !chrome.audio.StreamType,
* deviceType: !chrome.audio.DeviceType,
* displayName: string,
* deviceName: string,
* isActive: boolean,
* level: number,
* stableDeviceId: (string|undefined)
* }}
* @see https://developer.chrome.com/extensions/audio#type-AudioDeviceInfo
*/
chrome.audio.AudioDeviceInfo;
/**
* @typedef {{
* streamTypes: (!Array<!chrome.audio.StreamType>|undefined),
* isActive: (boolean|undefined)
* }}
* @see https://developer.chrome.com/extensions/audio#type-DeviceFilter
*/
chrome.audio.DeviceFilter;
/**
* @typedef {{
* isMuted: (boolean|undefined),
* volume: (number|undefined),
* gain: (number|undefined),
* level: (number|undefined)
* }}
* @see https://developer.chrome.com/extensions/audio#type-DeviceProperties
*/
chrome.audio.DeviceProperties;
/**
* @typedef {{
* input: (!Array<string>|undefined),
* output: (!Array<string>|undefined)
* }}
* @see https://developer.chrome.com/extensions/audio#type-DeviceIdLists
*/
chrome.audio.DeviceIdLists;
/**
* @typedef {{
* streamType: !chrome.audio.StreamType,
* isMuted: boolean
* }}
* @see https://developer.chrome.com/extensions/audio#type-MuteChangedEvent
*/
chrome.audio.MuteChangedEvent;
/**
* @typedef {{
* deviceId: string,
* level: number
* }}
* @see https://developer.chrome.com/extensions/audio#type-LevelChangedEvent
*/
chrome.audio.LevelChangedEvent;
/**
* Gets a list of audio devices filtered based on |filter|.
* @param {!chrome.audio.DeviceFilter} filter Device properties by which to
* filter the list of returned audio devices. If the filter is not set
* or set to <code>{}</code>, returned device list will contain all
* available audio devices.
* @param {function(!Array<!chrome.audio.AudioDeviceInfo>):void} callback
* Reports the requested list of audio devices.
* @see https://developer.chrome.com/extensions/audio#method-getDevices
*/
chrome.audio.getDevices = function(filter, callback) {};
/**
* Sets lists of active input and/or output devices.
* @param {(!chrome.audio.DeviceIdLists|!Array<string>)} ids <p>Specifies IDs of
* devices that should be active. If either the input or output list is
* not set, devices in that category are unaffected. </p> <p>It
* is an error to pass in a non-existent device ID.</p> <p><b>NOTE:</b>
* While the method signature allows device IDs to be passed as a list
* of strings, this method of setting active devices is deprecated and
* should not be relied upon to work. Please use $(ref:DeviceIdLists)
* instead. </p>
* @param {function():void} callback
* @see https://developer.chrome.com/extensions/audio#method-setActiveDevices
*/
chrome.audio.setActiveDevices = function(ids, callback) {};
/**
* Sets the properties for the input or output device.
* @param {string} id
* @param {!chrome.audio.DeviceProperties} properties
* @param {function():void} callback
* @see https://developer.chrome.com/extensions/audio#method-setProperties
*/
chrome.audio.setProperties = function(id, properties, callback) {};
/**
* Gets the system-wide mute state for the specified stream type.
* @param {!chrome.audio.StreamType} streamType Stream type for which mute state
* should be fetched.
* @param {function(boolean):void} callback Callback reporting whether mute is
* set or not for specified stream type.
* @see https://developer.chrome.com/extensions/audio#method-getMute
*/
chrome.audio.getMute = function(streamType, callback) {};
/**
* Sets mute state for a stream type. The mute state will apply to all audio
* devices with the specified audio stream type.
* @param {!chrome.audio.StreamType} streamType Stream type for which mute state
* should be set.
* @param {boolean} isMuted New mute value.
* @param {function():void=} callback
* @see https://developer.chrome.com/extensions/audio#method-setMute
*/
chrome.audio.setMute = function(streamType, isMuted, callback) {};
/**
* Gets the information of all audio output and input devices.
* @param {function(!Array<!chrome.audio.OutputDeviceInfo>, !Array<!chrome.audio.InputDeviceInfo>):void}
* callback
* @deprecated Use $(ref:getDevices) instead.
* @see https://developer.chrome.com/extensions/audio#method-getInfo
*/
chrome.audio.getInfo = function(callback) {};
/**
* Fired when sound level changes for an active audio device.
* @type {!ChromeEvent}
* @see https://developer.chrome.com/extensions/audio#event-onLevelChanged
*/
chrome.audio.onLevelChanged;
/**
* Fired when the mute state of the audio input or output changes. Note that
* mute state is system-wide and the new value applies to every audio device
* with specified stream type.
* @type {!ChromeEvent}
* @see https://developer.chrome.com/extensions/audio#event-onMuteChanged
*/
chrome.audio.onMuteChanged;
/**
* Fired when audio devices change, either new devices being added, or existing
* devices being removed.
* @type {!ChromeEvent}
* @see https://developer.chrome.com/extensions/audio#event-onDeviceListChanged
*/
chrome.audio.onDeviceListChanged;
/**
* Fired when anything changes to the audio device configuration.
* @type {!ChromeEvent}
* @see https://developer.chrome.com/extensions/audio#event-onDeviceChanged
*/
chrome.audio.onDeviceChanged;
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