2012-07-20 13:10:44 +04:00
|
|
|
/* Copyright 2012 Mozilla Foundation and Mozilla contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2011-12-12 22:22:26 +04:00
|
|
|
|
|
|
|
#ifndef mozilla_dom_system_b2g_audiomanager_h__
|
|
|
|
#define mozilla_dom_system_b2g_audiomanager_h__
|
|
|
|
|
2015-08-21 16:28:55 +03:00
|
|
|
#include "mozilla/HalTypes.h"
|
2012-04-22 22:14:36 +04:00
|
|
|
#include "mozilla/Observer.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2011-12-12 22:22:26 +04:00
|
|
|
#include "nsIAudioManager.h"
|
2012-09-29 13:39:05 +04:00
|
|
|
#include "nsIObserver.h"
|
2013-05-16 08:00:02 +04:00
|
|
|
#include "android_audio/AudioSystem.h"
|
2011-12-12 22:22:26 +04:00
|
|
|
|
|
|
|
// {b2b51423-502d-4d77-89b3-7786b562b084}
|
|
|
|
#define NS_AUDIOMANAGER_CID {0x94f6fd70, 0x7615, 0x4af9, \
|
|
|
|
{0x89, 0x10, 0xf9, 0x3c, 0x55, 0xe6, 0x62, 0xec}}
|
|
|
|
#define NS_AUDIOMANAGER_CONTRACTID "@mozilla.org/telephony/audiomanager;1"
|
|
|
|
|
|
|
|
namespace mozilla {
|
2012-04-22 22:14:36 +04:00
|
|
|
namespace hal {
|
|
|
|
class SwitchEvent;
|
|
|
|
typedef Observer<SwitchEvent> SwitchObserver;
|
|
|
|
} // namespace hal
|
|
|
|
|
2011-12-12 22:22:26 +04:00
|
|
|
namespace dom {
|
2012-03-15 02:43:26 +04:00
|
|
|
namespace gonk {
|
2015-07-17 05:07:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* FxOS can remeber the separate volume settings on difference output profiles.
|
|
|
|
* (1) Primary : speaker, receiver
|
|
|
|
* (2) Headset : wired headphone/headset
|
|
|
|
* (3) Bluetooth : BT SCO/A2DP devices
|
|
|
|
**/
|
|
|
|
enum AudioOutputProfiles {
|
2015-08-17 14:38:39 +03:00
|
|
|
DEVICE_ERROR = -1,
|
2015-07-17 05:07:37 +03:00
|
|
|
DEVICE_PRIMARY = 0,
|
|
|
|
DEVICE_HEADSET = 1,
|
|
|
|
DEVICE_BLUETOOTH = 2,
|
|
|
|
DEVICE_TOTAL_NUMBER = 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We have five sound volume settings from UX spec,
|
|
|
|
* You can see more informations in Bug1068219.
|
|
|
|
* (1) Media : music, video, FM ...
|
|
|
|
* (2) Notification : ringer, notification ...
|
|
|
|
* (3) Alarm : alarm
|
|
|
|
* (4) Telephony : GSM call, WebRTC call
|
|
|
|
* (5) Bluetooth SCO : SCO call
|
|
|
|
**/
|
|
|
|
enum AudioVolumeCategories {
|
|
|
|
VOLUME_MEDIA = 0,
|
|
|
|
VOLUME_NOTIFICATION = 1,
|
|
|
|
VOLUME_ALARM = 2,
|
|
|
|
VOLUME_TELEPHONY = 3,
|
|
|
|
VOLUME_BLUETOOTH_SCO = 4,
|
|
|
|
VOLUME_TOTAL_NUMBER = 5,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VolumeData {
|
|
|
|
const char* mChannelName;
|
|
|
|
uint32_t mCategory;
|
|
|
|
};
|
|
|
|
|
2013-07-18 09:22:36 +04:00
|
|
|
class RecoverTask;
|
2015-08-17 14:38:39 +03:00
|
|
|
class VolumeInitCallback;
|
2015-07-17 05:07:37 +03:00
|
|
|
class AudioProfileData;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class AudioManager final : public nsIAudioManager
|
2015-03-27 21:52:19 +03:00
|
|
|
, public nsIObserver
|
2011-12-12 22:22:26 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-05-28 10:19:22 +04:00
|
|
|
static already_AddRefed<AudioManager> GetInstance();
|
|
|
|
|
2011-12-12 22:22:26 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIAUDIOMANAGER
|
2012-09-29 13:39:05 +04:00
|
|
|
NS_DECL_NSIOBSERVER
|
2011-12-12 22:22:26 +04:00
|
|
|
|
2013-07-18 09:22:36 +04:00
|
|
|
// When audio backend is dead, recovery task needs to read all volume
|
|
|
|
// settings then set back into audio backend.
|
|
|
|
friend class RecoverTask;
|
2015-08-17 14:38:39 +03:00
|
|
|
friend class VolumeInitCallback;
|
2013-07-18 09:22:36 +04:00
|
|
|
|
2015-07-17 05:07:37 +03:00
|
|
|
// Open or close the specific profile
|
|
|
|
void SwitchProfileData(AudioOutputProfiles aProfile, bool aActive);
|
|
|
|
|
|
|
|
// Validate whether the volume index is within the range
|
|
|
|
nsresult ValidateVolumeIndex(uint32_t aCategory, uint32_t aIndex) const;
|
|
|
|
|
2015-08-21 16:28:55 +03:00
|
|
|
// Called when android AudioFlinger in mediaserver is died
|
|
|
|
void HandleAudioFlingerDied();
|
|
|
|
|
|
|
|
void HandleHeadphoneSwitchEvent(const hal::SwitchEvent& aEvent);
|
|
|
|
|
2011-12-12 22:22:26 +04:00
|
|
|
protected:
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mPhoneState;
|
2015-08-21 16:28:55 +03:00
|
|
|
|
|
|
|
// A bitwise variable for recording what kind of headset/headphone is attached.
|
|
|
|
int32_t mHeadsetState;
|
|
|
|
|
|
|
|
bool mSwitchDone;
|
|
|
|
|
|
|
|
#if defined(MOZ_B2G_BT) || ANDROID_VERSION >= 17
|
|
|
|
bool mBluetoothA2dpEnabled;
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_B2G_BT
|
|
|
|
bool mA2dpSwitchDone;
|
|
|
|
#endif
|
2015-07-17 05:07:37 +03:00
|
|
|
uint32_t mCurrentStreamVolumeTbl[AUDIO_STREAM_CNT];
|
2011-12-12 22:22:26 +04:00
|
|
|
|
2015-07-17 05:07:37 +03:00
|
|
|
nsresult SetStreamVolumeIndex(int32_t aStream, uint32_t aIndex);
|
|
|
|
nsresult GetStreamVolumeIndex(int32_t aStream, uint32_t *aIndex);
|
2013-07-18 09:22:36 +04:00
|
|
|
|
2012-04-22 22:14:36 +04:00
|
|
|
private:
|
|
|
|
nsAutoPtr<mozilla::hal::SwitchObserver> mObserver;
|
2013-12-04 10:57:40 +04:00
|
|
|
#ifdef MOZ_B2G_RIL
|
2013-11-27 11:46:27 +04:00
|
|
|
bool mMuteCallToRIL;
|
|
|
|
// mIsMicMuted is only used for toggling mute call to RIL.
|
|
|
|
bool mIsMicMuted;
|
2013-12-04 10:57:40 +04:00
|
|
|
#endif
|
2015-07-17 05:07:37 +03:00
|
|
|
nsTArray<nsAutoPtr<AudioProfileData>> mAudioProfiles;
|
|
|
|
AudioOutputProfiles mPresentProfile;
|
2013-07-30 10:58:58 +04:00
|
|
|
|
|
|
|
void HandleBluetoothStatusChanged(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const nsCString aAddress);
|
2014-05-29 11:20:42 +04:00
|
|
|
void HandleAudioChannelProcessChanged();
|
2014-05-28 10:19:22 +04:00
|
|
|
|
2015-07-17 05:07:37 +03:00
|
|
|
void CreateAudioProfilesData();
|
|
|
|
|
|
|
|
// Init the volume setting from the init setting callback
|
2015-08-17 14:38:39 +03:00
|
|
|
void InitProfileVolume(AudioOutputProfiles aProfile,
|
|
|
|
uint32_t aCatogory, uint32_t aIndex);
|
2015-07-17 05:07:37 +03:00
|
|
|
|
|
|
|
// Update volume data of profiles
|
|
|
|
void UpdateVolumeToProfile(AudioProfileData* aProfileData);
|
|
|
|
|
|
|
|
// Apply the volume data to device
|
|
|
|
void UpdateVolumeFromProfile(AudioProfileData* aProfileData);
|
|
|
|
|
|
|
|
// Send the volume changing event to Gaia
|
|
|
|
void SendVolumeChangeNotification(AudioProfileData* aProfileData);
|
|
|
|
|
|
|
|
// Update the mPresentProfile and profiles active status
|
|
|
|
void UpdateProfileState(AudioOutputProfiles aProfile, bool aActive);
|
|
|
|
|
|
|
|
// Volume control functions
|
|
|
|
nsresult SetVolumeByCategory(uint32_t aCategory, uint32_t aIndex);
|
|
|
|
uint32_t GetVolumeByCategory(uint32_t aCategory) const;
|
|
|
|
uint32_t GetMaxVolumeByCategory(uint32_t aCategory) const;
|
|
|
|
|
|
|
|
AudioProfileData* FindAudioProfileData(AudioOutputProfiles aProfile);
|
|
|
|
|
2015-08-17 14:38:39 +03:00
|
|
|
// Append the profile to the volume setting string.
|
|
|
|
nsAutoCString AppendProfileToVolumeSetting(const char* aName,
|
|
|
|
AudioOutputProfiles aProfile);
|
|
|
|
|
|
|
|
// Init volume from the settings database.
|
|
|
|
void InitVolumeFromDatabase();
|
|
|
|
|
|
|
|
// Promise functions.
|
|
|
|
void InitProfileVolumeSucceeded();
|
|
|
|
void InitProfileVolumeFailed(const char* aError);
|
|
|
|
|
2015-08-21 16:28:55 +03:00
|
|
|
void UpdateHeadsetConnectionState(hal::SwitchState aState);
|
|
|
|
|
2014-05-28 10:19:22 +04:00
|
|
|
AudioManager();
|
|
|
|
~AudioManager();
|
2012-04-22 22:14:36 +04:00
|
|
|
};
|
2011-12-12 22:22:26 +04:00
|
|
|
|
2012-04-22 22:14:36 +04:00
|
|
|
} /* namespace gonk */
|
2011-12-12 22:22:26 +04:00
|
|
|
} /* namespace dom */
|
|
|
|
} /* namespace mozilla */
|
|
|
|
|
|
|
|
#endif // mozilla_dom_system_b2g_audiomanager_h__
|