Bug 1242874 - part4 : wrap the volume/mute/suspend for notifyStartedPlaying. r=baku

MozReview-Commit-ID: 2FMfEVuODmu
This commit is contained in:
Alastor Wu
2016-05-03 09:52:44 +08:00
parent 5704a47317
commit 7b158c5b32
8 changed files with 71 additions and 49 deletions

View File

@@ -201,17 +201,11 @@ AudioChannelAgent::InitInternal(nsPIDOMWindowInner* aWindow,
return NS_OK;
}
NS_IMETHODIMP AudioChannelAgent::NotifyStartedPlaying(float *aVolume,
bool* aMuted)
NS_IMETHODIMP
AudioChannelAgent::NotifyStartedPlaying(AudioPlaybackConfig* aConfig)
{
MOZ_ASSERT(aVolume);
MOZ_ASSERT(aMuted);
// Window-less AudioChannelAgents are muted by default.
if (!mWindow) {
*aVolume = 0;
*aMuted = true;
return NS_OK;
if (NS_WARN_IF(!aConfig)) {
return NS_ERROR_FAILURE;
}
RefPtr<AudioChannelService> service = AudioChannelService::GetOrCreate();
@@ -231,14 +225,13 @@ NS_IMETHODIMP AudioChannelAgent::NotifyStartedPlaying(float *aVolume,
"mute = %d, volume = %f, suspend = %d\n", this,
config.mMuted, config.mVolume, config.mSuspend));
*aVolume = config.mVolume;
*aMuted = config.mMuted;
aConfig->SetConfig(config.mVolume, config.mMuted, config.mSuspend);
mIsRegToService = true;
return NS_OK;
}
NS_IMETHODIMP AudioChannelAgent::NotifyStoppedPlaying()
NS_IMETHODIMP
AudioChannelAgent::NotifyStoppedPlaying()
{
if (mAudioChannelType == AUDIO_AGENT_CHANNEL_ERROR ||
!mIsRegToService) {

View File

@@ -55,6 +55,16 @@ interface nsISuspendedTypes : nsISupports
const uint32_t SUSPENDED_STOP_DISPOSABLE = 4;
};
%{C++
namespace mozilla {
namespace dom {
// It's defined in dom/audiochannel/AudioChannelService.h.
class AudioPlaybackConfig;
}
}
%}
[ptr] native AudioPlaybackConfig(mozilla::dom::AudioPlaybackConfig);
[uuid(15c05894-408e-4798-b527-a8c32d9c5f8c)]
interface nsIAudioChannelAgentCallback : nsISupports
{
@@ -152,15 +162,10 @@ interface nsIAudioChannelAgent : nsISupports
* Note: Gecko component SHOULD call this function first then start to
* play audio stream only when return value is true.
*
* @return
* normal state: the agent has registered with audio channel service and
* the component should start playback.
* muted state: the agent has registered with audio channel service but
* the component should not start playback.
* faded state: the agent has registered with audio channel service the
* component should start playback as well as reducing the volume.
* @param config
* It contains the playback related states (volume/mute/suspend)
*/
void notifyStartedPlaying(out float volume, out bool muted);
void notifyStartedPlaying(in AudioPlaybackConfig config);
/**
* Notify the agent we no longer want to play.

View File

@@ -452,10 +452,14 @@ FMRadio::EnableAudioChannelAgent()
{
NS_ENSURE_TRUE_VOID(mAudioChannelAgent);
float volume = 0.0;
bool muted = true;
mAudioChannelAgent->NotifyStartedPlaying(&volume, &muted);
WindowVolumeChanged(volume, muted);
AudioPlaybackConfig config;
nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
WindowVolumeChanged(config.mVolume, config.mMuted);
WindowSuspendChanged(config.mSuspend);
mAudioChannelAgentEnabled = true;
}

View File

@@ -5061,10 +5061,14 @@ HTMLMediaElement::NotifyAudioChannelAgent(bool aPlaying)
AutoNoJSAPI nojsapi;
if (aPlaying) {
float volume = 0.0;
bool muted = true;
mAudioChannelAgent->NotifyStartedPlaying(&volume, &muted);
WindowVolumeChanged(volume, muted);
AudioPlaybackConfig config;
nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
WindowVolumeChanged(config.mVolume, config.mMuted);
WindowSuspendChanged(config.mSuspend);
} else {
mAudioChannelAgent->NotifyStoppedPlaying();
mAudioChannelAgent = nullptr;

View File

@@ -664,14 +664,14 @@ AudioDestinationNode::InputMuted(bool aMuted)
return;
}
float volume = 0.0;
bool muted = true;
nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&volume, &muted);
AudioPlaybackConfig config;
nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
WindowVolumeChanged(volume, muted);
WindowVolumeChanged(config.mVolume, config.mMuted);
WindowSuspendChanged(config.mSuspend);
}
} // namespace dom

View File

@@ -712,9 +712,15 @@ nsSpeechTask::CreateAudioChannelAgent()
mAudioChannelAgent->InitWithWeakCallback(mUtterance->GetOwner(),
static_cast<int32_t>(AudioChannelService::GetDefaultAudioChannel()),
this);
float volume = 0.0f;
bool muted = true;
mAudioChannelAgent->NotifyStartedPlaying(&volume, &muted);
AudioPlaybackConfig config;
nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
WindowVolumeChanged(config.mVolume, config.mMuted);
WindowSuspendChanged(config.mSuspend);
}
void
@@ -736,9 +742,11 @@ nsSpeechTask::WindowVolumeChanged(float aVolume, bool aMuted)
NS_IMETHODIMP
nsSpeechTask::WindowSuspendChanged(nsSuspendedTypes aSuspend)
{
if (aSuspend == nsISuspendedTypes::NONE_SUSPENDED) {
if (aSuspend == nsISuspendedTypes::NONE_SUSPENDED &&
mUtterance->mPaused) {
Resume();
} else {
} else if (aSuspend != nsISuspendedTypes::NONE_SUSPENDED &&
!mUtterance->mPaused) {
Pause();
}
return NS_OK;

View File

@@ -107,6 +107,7 @@ using mozilla::plugins::PluginModuleContentParent;
#endif
#include "nsIAudioChannelAgent.h"
#include "AudioChannelService.h"
using namespace mozilla;
using namespace mozilla::plugins::parent;
@@ -2289,14 +2290,19 @@ _setvalue(NPP npp, NPPVariable variable, void *result)
return NPERR_NO_ERROR;
}
} else {
float volume = 0.0;
bool muted = true;
rv = agent->NotifyStartedPlaying(&volume, &muted);
dom::AudioPlaybackConfig config;
rv = agent->NotifyStartedPlaying(&config);
if (NS_WARN_IF(NS_FAILED(rv))) {
return NPERR_NO_ERROR;
}
rv = inst->WindowVolumeChanged(volume, muted);
rv = inst->WindowVolumeChanged(config.mVolume, config.mMuted);
if (NS_WARN_IF(NS_FAILED(rv))) {
return NPERR_NO_ERROR;
}
rv = inst->WindowSuspendChanged(config.mSuspend);
if (NS_WARN_IF(NS_FAILED(rv))) {
return NPERR_NO_ERROR;
}

View File

@@ -561,9 +561,8 @@ Telephony::HandleAudioAgentState()
}
} else if (!activeCall.IsNull() && !mIsAudioStartPlaying) {
mIsAudioStartPlaying = true;
float volume;
bool muted;
rv = mAudioAgent->NotifyStartedPlaying(&volume, &muted);
AudioPlaybackConfig config;
rv = mAudioAgent->NotifyStartedPlaying(&config);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@@ -577,9 +576,12 @@ Telephony::HandleAudioAgentState()
// because the modem have not changed the call state yet. It causes that
// the telephony can't be resumed. Therefore, we don't mute the telephony
// at the beginning.
volume = 1.0;
muted = false;
rv = WindowVolumeChanged(volume, muted);
rv = WindowVolumeChanged(1.0, false);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = WindowSuspendChanged(config.mSuspend);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}