mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-25 22:29:07 +00:00
Bug 791642 - nsIAudioManager: support voice volume. r=philikon
1. Provide api for adjusting volume based on each stream. 2. Modify settings.js for listening the changing for stream volume.
This commit is contained in:
parent
5c11a321fd
commit
24d7c0cc45
@ -64,6 +64,33 @@ SettingsListener.observe('audio.volume.master', 0.5, function(value) {
|
||||
audioManager.masterVolume = Math.max(0.0, Math.min(value, 1.0));
|
||||
});
|
||||
|
||||
const nsIAudioManager = Ci.nsIAudioManager;
|
||||
let audioSettings = [
|
||||
// settings name, default value, stream type
|
||||
['audio.volume.voice_call', 10, nsIAudioManager.STREAM_TYPE_VOICE_CALL],
|
||||
['audio.volume.system', 10, nsIAudioManager.STREAM_TYPE_SYSTEM],
|
||||
['audio.volume.ring', 7, nsIAudioManager.STREAM_TYPE_RING],
|
||||
['audio.volume.music', 15, nsIAudioManager.STREAM_TYPE_MUSIC],
|
||||
['audio.volume.alarm', 7, nsIAudioManager.STREAM_TYPE_ALARM],
|
||||
['audio.volume.notification', 7, nsIAudioManager.STREAM_TYPE_NOTIFICATION],
|
||||
['audio.volume.bt_sco', 15, nsIAudioManager.STREAM_TYPE_BLUETOOTH_SCO],
|
||||
['audio.volume.enforced_audible', 7, nsIAudioManager.STREAM_TYPE_ENFORCED_AUDIBLE],
|
||||
['audio.volume.dtmf', 15, nsIAudioManager.STREAM_TYPE_DTMF],
|
||||
['audio.volume.tts', 15, nsIAudioManager.STREAM_TYPE_TTS],
|
||||
['audio.volume.fm', 10, nsIAudioManager.STREAM_TYPE_FM],
|
||||
];
|
||||
|
||||
for each (let [setting, defaultValue, streamType] in audioSettings) {
|
||||
(function AudioStreamSettings(s, d, t) {
|
||||
SettingsListener.observe(s, d, function(value) {
|
||||
let audioManager = Services.audioManager;
|
||||
if (!audioManager)
|
||||
return;
|
||||
|
||||
audioManager.setStreamVolumeIndex(t, Math.min(value, d));
|
||||
});
|
||||
})(setting, defaultValue, streamType);
|
||||
}
|
||||
|
||||
// =================== Languages ====================
|
||||
SettingsListener.observe('language.current', 'en-US', function(value) {
|
||||
|
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <android/log.h>
|
||||
#include <android/log.h>
|
||||
|
||||
#include "mozilla/Hal.h"
|
||||
#include "AudioManager.h"
|
||||
@ -26,7 +26,7 @@ using namespace android;
|
||||
using namespace mozilla::hal;
|
||||
using namespace mozilla;
|
||||
|
||||
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "AudioManager" , ## args)
|
||||
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "AudioManager" , ## args)
|
||||
|
||||
#define HEADPHONES_STATUS_CHANGED "headphones-status-changed"
|
||||
#define HEADPHONES_STATUS_ON NS_LITERAL_STRING("on").get()
|
||||
@ -34,6 +34,21 @@ using namespace mozilla;
|
||||
#define HEADPHONES_STATUS_UNKNOWN NS_LITERAL_STRING("unknown").get()
|
||||
#define BLUETOOTH_SCO_STATUS_CHANGED "bluetooth-sco-status-changed"
|
||||
|
||||
// Refer AudioService.java from Android
|
||||
static int sMaxStreamVolumeTbl[AUDIO_STREAM_CNT] = {
|
||||
10, // voice call
|
||||
10, // system
|
||||
7, // ring
|
||||
15, // music
|
||||
7, // alarm
|
||||
7, // notification
|
||||
15, // BT SCO
|
||||
7, // enforced audible
|
||||
15, // DTMF
|
||||
15, // TTS
|
||||
10, // FM
|
||||
};
|
||||
|
||||
// A bitwise variable for recording what kind of headset is attached.
|
||||
static int sHeadsetState;
|
||||
static int kBtSampleRate = 8000;
|
||||
@ -44,7 +59,7 @@ IsFmRadioAudioOn()
|
||||
if (static_cast<
|
||||
audio_policy_dev_state_t (*) (audio_devices_t, const char *)
|
||||
>(AudioSystem::getDeviceConnectionState)) {
|
||||
return AudioSystem::getDeviceConnectionState(AUDIO_DEVICE_OUT_FM, "") ==
|
||||
return AudioSystem::getDeviceConnectionState(AUDIO_DEVICE_OUT_FM, "") ==
|
||||
AUDIO_POLICY_DEVICE_STATE_AVAILABLE ? true : false;
|
||||
} else {
|
||||
return false;
|
||||
@ -187,6 +202,11 @@ AudioManager::AudioManager() : mPhoneState(PHONE_STATE_CURRENT),
|
||||
if (NS_FAILED(obs->AddObserver(this, BLUETOOTH_SCO_STATUS_CHANGED, false))) {
|
||||
NS_WARNING("Failed to add bluetooth-sco-status-changed oberver!");
|
||||
}
|
||||
|
||||
for (int loop = 0; loop < AUDIO_STREAM_CNT; loop++) {
|
||||
AudioSystem::initStreamVolume(static_cast<audio_stream_type_t>(loop), 0,
|
||||
sMaxStreamVolumeTbl[loop]);
|
||||
}
|
||||
}
|
||||
|
||||
AudioManager::~AudioManager() {
|
||||
@ -338,7 +358,7 @@ AudioManager::SetFmRadioAudioEnabled(bool aFmRadioAudioEnabled)
|
||||
status_t (*) (AudioSystem::audio_devices, AudioSystem::device_connection_state, const char *)
|
||||
>(AudioSystem::setDeviceConnectionState)) {
|
||||
AudioSystem::setDeviceConnectionState(AUDIO_DEVICE_OUT_FM,
|
||||
aFmRadioAudioEnabled ? AUDIO_POLICY_DEVICE_STATE_AVAILABLE :
|
||||
aFmRadioAudioEnabled ? AUDIO_POLICY_DEVICE_STATE_AVAILABLE :
|
||||
AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, "");
|
||||
InternalSetAudioRoutes(GetCurrentSwitchState(SWITCH_HEADPHONES));
|
||||
return NS_OK;
|
||||
@ -346,3 +366,24 @@ AudioManager::SetFmRadioAudioEnabled(bool aFmRadioAudioEnabled)
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AudioManager::SetStreamVolumeIndex(int32_t aStream, int32_t aIndex) {
|
||||
status_t status =
|
||||
AudioSystem::setStreamVolumeIndex(static_cast<audio_stream_type_t>(aStream), aIndex);
|
||||
return status ? NS_ERROR_FAILURE : NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AudioManager::GetStreamVolumeIndex(int32_t aStream, int32_t* aIndex) {
|
||||
status_t status =
|
||||
AudioSystem::getStreamVolumeIndex(static_cast<audio_stream_type_t>(aStream), aIndex);
|
||||
return status ? NS_ERROR_FAILURE : NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AudioManager::GetMaxStreamVolumeIndex(int32_t aStream, int32_t* aMaxIndex) {
|
||||
*aMaxIndex = sMaxStreamVolumeTbl[aStream];
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, builtinclass, uuid(d2124467-7209-4b2e-a91a-cf3f90681e3c)]
|
||||
[scriptable, builtinclass, uuid(b76a3de4-79f4-4cbb-a0e2-871095eacb2c)]
|
||||
interface nsIAudioManager : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -59,4 +59,23 @@ interface nsIAudioManager : nsISupports
|
||||
|
||||
void setForceForUse(in long usage, in long force);
|
||||
long getForceForUse(in long usage);
|
||||
|
||||
/**
|
||||
* Control the volume of various audio streams
|
||||
*/
|
||||
const long STREAM_TYPE_VOICE_CALL = 0;
|
||||
const long STREAM_TYPE_SYSTEM = 1;
|
||||
const long STREAM_TYPE_RING = 2;
|
||||
const long STREAM_TYPE_MUSIC = 3;
|
||||
const long STREAM_TYPE_ALARM = 4;
|
||||
const long STREAM_TYPE_NOTIFICATION = 5;
|
||||
const long STREAM_TYPE_BLUETOOTH_SCO = 6;
|
||||
const long STREAM_TYPE_ENFORCED_AUDIBLE = 7;
|
||||
const long STREAM_TYPE_DTMF = 8;
|
||||
const long STREAM_TYPE_TTS = 9;
|
||||
const long STREAM_TYPE_FM = 10;
|
||||
|
||||
void setStreamVolumeIndex(in long stream, in long index);
|
||||
long getStreamVolumeIndex(in long stream);
|
||||
long getMaxStreamVolumeIndex(in long stream);
|
||||
};
|
||||
|
@ -75,6 +75,7 @@ typedef enum {
|
||||
AUDIO_STREAM_ENFORCED_AUDIBLE = 7, /* Sounds that cannot be muted by user and must be routed to speaker */
|
||||
AUDIO_STREAM_DTMF = 8,
|
||||
AUDIO_STREAM_TTS = 9,
|
||||
AUDIO_STREAM_FM = 10,
|
||||
|
||||
AUDIO_STREAM_CNT,
|
||||
AUDIO_STREAM_MAX = AUDIO_STREAM_CNT - 1,
|
||||
@ -335,6 +336,7 @@ public:
|
||||
ENFORCED_AUDIBLE = 7, // Sounds that cannot be muted by user and must be routed to speaker
|
||||
DTMF = 8,
|
||||
TTS = 9,
|
||||
FM = 10,
|
||||
NUM_STREAM_TYPES
|
||||
};
|
||||
|
||||
@ -699,8 +701,13 @@ public:
|
||||
static status_t initStreamVolume(stream_type stream,
|
||||
int indexMin,
|
||||
int indexMax);
|
||||
static status_t initStreamVolume(audio_stream_type_t stream,
|
||||
int indexMin,
|
||||
int indexMax);
|
||||
static status_t setStreamVolumeIndex(stream_type stream, int index);
|
||||
static status_t setStreamVolumeIndex(audio_stream_type_t stream, int index);
|
||||
static status_t getStreamVolumeIndex(stream_type stream, int *index);
|
||||
static status_t getStreamVolumeIndex(audio_stream_type_t stream, int *index);
|
||||
|
||||
static uint32_t getStrategyForStream(stream_type stream);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user