Bug 819858 - Add AudioChannelAgent to AudioManager for telephony joining AudioChannelService. r=baku, a=blocking-basecamp

This commit is contained in:
Marco Chen 2012-12-13 09:45:10 +08:00
parent 82e61d47bc
commit 1834026fda
4 changed files with 23 additions and 26 deletions

View File

@ -299,17 +299,3 @@ AudioChannelService::ChannelName(AudioChannelType aType)
return nullptr;
}
#ifdef MOZ_WIDGET_GONK
void
AudioChannelService::SetPhoneInCall(bool aActive)
{
//while ring tone and in-call mode, mute media element
if (aActive) {
mChannelCounters[AUDIO_CHANNEL_TELEPHONY] = 1;
} else {
mChannelCounters[AUDIO_CHANNEL_TELEPHONY] = 0;
}
Notify();
}
#endif

View File

@ -52,13 +52,6 @@ public:
*/
virtual bool GetMuted(AudioChannelType aType, bool aElementHidden);
/**
* Sync the phone status with telephony
*/
#ifdef MOZ_WIDGET_GONK
void SetPhoneInCall(bool aActive);
#endif
protected:
void Notify();

View File

@ -294,17 +294,32 @@ AudioManager::GetPhoneState(int32_t* aState)
NS_IMETHODIMP
AudioManager::SetPhoneState(int32_t aState)
{
if (mPhoneState == aState) {
return NS_OK;
}
if (AudioSystem::setPhoneState(aState)) {
return NS_ERROR_FAILURE;
}
mPhoneState = aState;
nsRefPtr<AudioChannelService> audioChannelService = AudioChannelService::GetAudioChannelService();
if (!audioChannelService) {
return NS_ERROR_FAILURE;
if (aState == PHONE_STATE_IN_CALL) {
if (!mPhoneAudioAgent) {
mPhoneAudioAgent = do_CreateInstance("@mozilla.org/audiochannelagent;1");
MOZ_ASSERT(mPhoneAudioAgent);
// Telephony doesn't be paused by any other channels.
mPhoneAudioAgent->Init(AUDIO_CHANNEL_TELEPHONY, nullptr);
// Telephony can always play.
bool canPlay;
mPhoneAudioAgent->StartPlaying(&canPlay);
}
} else if (mPhoneAudioAgent) {
mPhoneAudioAgent->StopPlaying();
mPhoneAudioAgent = nullptr;
}
audioChannelService->SetPhoneInCall(aState == nsIAudioManager::PHONE_STATE_IN_CALL);
return NS_OK;
}

View File

@ -20,12 +20,14 @@
#include "nsAutoPtr.h"
#include "nsIAudioManager.h"
#include "nsIObserver.h"
#include "AudioChannelAgent.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"
using namespace mozilla::dom;
namespace mozilla {
namespace hal {
@ -52,7 +54,8 @@ protected:
private:
nsAutoPtr<mozilla::hal::SwitchObserver> mObserver;
bool mFMChannelIsMuted;
nsCOMPtr<AudioChannelAgent> mPhoneAudioAgent;
bool mFMChannelIsMuted;
};
} /* namespace gonk */