mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-12 10:40:12 +00:00
Bug 736939 - AudioManager implementation. r=cjones, a=b2g-only
This commit is contained in:
parent
fce206dad7
commit
d7038612fa
@ -35,14 +35,66 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
#include "mozilla/Hal.h"
|
||||
#include "AudioManager.h"
|
||||
#include "gonk/AudioSystem.h"
|
||||
|
||||
using namespace mozilla::dom::gonk;
|
||||
using namespace android;
|
||||
using namespace mozilla::hal;
|
||||
using namespace mozilla;
|
||||
|
||||
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "AudioManager" , ## args)
|
||||
|
||||
NS_IMPL_ISUPPORTS1(AudioManager, nsIAudioManager)
|
||||
|
||||
static AudioSystem::audio_devices
|
||||
GetRoutingMode(int aType) {
|
||||
if (aType == nsIAudioManager::FORCE_SPEAKER) {
|
||||
return AudioSystem::DEVICE_OUT_SPEAKER;
|
||||
} else if (aType == nsIAudioManager::FORCE_HEADPHONES) {
|
||||
return AudioSystem::DEVICE_OUT_WIRED_HEADSET;
|
||||
} else if (aType == nsIAudioManager::FORCE_BT_SCO) {
|
||||
return AudioSystem::DEVICE_OUT_BLUETOOTH_SCO;
|
||||
} else if (aType == nsIAudioManager::FORCE_BT_A2DP) {
|
||||
return AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP;
|
||||
} else {
|
||||
return AudioSystem::DEVICE_IN_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
InternalSetAudioRoutes(SwitchState aState)
|
||||
{
|
||||
if (aState == SWITCH_STATE_ON) {
|
||||
AudioManager::SetAudioRoute(nsIAudioManager::FORCE_HEADPHONES);
|
||||
} else if (aState == SWITCH_STATE_OFF) {
|
||||
AudioManager::SetAudioRoute(nsIAudioManager::FORCE_SPEAKER);
|
||||
}
|
||||
}
|
||||
|
||||
class HeadphoneSwitchObserver : public SwitchObserver
|
||||
{
|
||||
public:
|
||||
void Notify(const SwitchEvent& aEvent) {
|
||||
InternalSetAudioRoutes(aEvent.status());
|
||||
}
|
||||
};
|
||||
|
||||
AudioManager::AudioManager() : mPhoneState(PHONE_STATE_CURRENT),
|
||||
mObserver(new HeadphoneSwitchObserver())
|
||||
{
|
||||
RegisterSwitchObserver(SWITCH_HEADPHONES, mObserver);
|
||||
|
||||
InternalSetAudioRoutes(GetCurrentSwitchState(SWITCH_HEADPHONES));
|
||||
}
|
||||
|
||||
AudioManager::~AudioManager() {
|
||||
UnregisterSwitchObserver(SWITCH_HEADPHONES, mObserver);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
AudioManager::GetMicrophoneMuted(bool* aMicrophoneMuted)
|
||||
{
|
||||
@ -161,3 +213,12 @@ AudioManager::GetForceForUse(PRInt32 aUsage, PRInt32* aForce) {
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
AudioManager::SetAudioRoute(int aRoutes) {
|
||||
audio_io_handle_t handle = AudioSystem::getOutput(AudioSystem::SYSTEM);
|
||||
|
||||
String8 cmd;
|
||||
cmd.appendFormat("%s=%d", AudioParameter::keyRouting, GetRoutingMode(aRoutes));
|
||||
AudioSystem::setParameters(handle, cmd);
|
||||
}
|
||||
|
@ -38,15 +38,22 @@
|
||||
#ifndef mozilla_dom_system_b2g_audiomanager_h__
|
||||
#define mozilla_dom_system_b2g_audiomanager_h__
|
||||
|
||||
#include "mozilla/Observer.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIAudioManager.h"
|
||||
|
||||
|
||||
// {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 {
|
||||
namespace hal {
|
||||
class SwitchEvent;
|
||||
typedef Observer<SwitchEvent> SwitchObserver;
|
||||
} // namespace hal
|
||||
|
||||
namespace dom {
|
||||
namespace gonk {
|
||||
|
||||
@ -56,16 +63,18 @@ public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIAUDIOMANAGER
|
||||
|
||||
AudioManager() : mPhoneState(PHONE_STATE_CURRENT)
|
||||
{
|
||||
}
|
||||
AudioManager();
|
||||
~AudioManager();
|
||||
|
||||
static void SetAudioRoute(int aRoutes);
|
||||
protected:
|
||||
PRInt32 mPhoneState;
|
||||
|
||||
private:
|
||||
nsAutoPtr<mozilla::hal::SwitchObserver> mObserver;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace telephony */
|
||||
} /* namespace gonk */
|
||||
} /* namespace dom */
|
||||
} /* namespace mozilla */
|
||||
|
||||
|
@ -67,3 +67,4 @@ XPCSHELL_TESTS = tests
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
include $(topsrcdir)/ipc/chromium/chromium-config.mk
|
||||
|
Loading…
x
Reference in New Issue
Block a user