Bug 1235612 - Part 3: Implement the logic of audible state notification for agent owners. r=baku

MozReview-Commit-ID: 6CueLPpuXWm

--HG--
extra : rebase_source : d40603e2ecc006a7b21f8b9adeb3a244e9821a2f
This commit is contained in:
Alastor Wu 2016-05-03 17:59:32 +08:00
parent 12d3b72c2e
commit b5d99318b3
7 changed files with 37 additions and 8 deletions

View File

@ -14,6 +14,7 @@
#include "mozilla/dom/PFMRadioChild.h"
#include "mozilla/dom/FMRadioService.h"
#include "mozilla/dom/TypedArray.h"
#include "AudioChannelService.h"
#include "DOMRequest.h"
#include "nsDOMClassInfo.h"
#include "nsIDocShell.h"
@ -453,7 +454,8 @@ FMRadio::EnableAudioChannelAgent()
NS_ENSURE_TRUE_VOID(mAudioChannelAgent);
AudioPlaybackConfig config;
nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config);
nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config,
AudioChannelService::AudibleState::eAudible);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}

View File

@ -3367,6 +3367,10 @@ void HTMLMediaElement::UpdateSrcMediaStreamPlaying(uint32_t aFlags)
mMediaStreamListener->Forget();
mMediaStreamListener = nullptr;
}
// If the input is a media stream, we don't check its data and always regard
// it as audible when it's playing.
NotifyAudibleStateChanged(shouldPlay);
}
void HTMLMediaElement::SetupSrcMediaStreamPlayback(DOMMediaStream* aStream)
@ -5061,8 +5065,15 @@ HTMLMediaElement::NotifyAudioChannelAgent(bool aPlaying)
AutoNoJSAPI nojsapi;
if (aPlaying) {
// The reason we don't call NotifyStartedPlaying after the media element
// really becomes audible is because there is another case needs to block
// element as early as we can, we would hear sound leaking if we block it
// too late. In that case (block autoplay in non-visited-tab), we need to
// create a connection before decoding, because we don't want user hearing
// any sound.
AudioPlaybackConfig config;
nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config);
nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config,
mIsAudioTrackAudible);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
@ -5618,7 +5629,15 @@ HTMLMediaElement::NotifyAudibleStateChanged(bool aAudible)
{
if (mIsAudioTrackAudible != aAudible) {
mIsAudioTrackAudible = aAudible;
// To do ...
NotifyAudioPlaybackChanged();
}
}
void
HTMLMediaElement::NotifyAudioPlaybackChanged()
{
if (mAudioChannelAgent) {
mAudioChannelAgent->NotifyStartedAudible(mIsAudioTrackAudible);
}
}

View File

@ -448,9 +448,13 @@ public:
// when the connection between Rtsp server and client gets lost.
virtual void ResetConnectionState() final override;
// Called by media decoder when the audible state changed.
// Called by media decoder when the audible state changed or when input is
// a media stream.
virtual void NotifyAudibleStateChanged(bool aAudible) final override;
// Notify agent when the MediaElement changes its audible state.
void NotifyAudioPlaybackChanged();
// XPCOM GetPreload() is OK
void SetPreload(const nsAString& aValue, ErrorResult& aRv)
{

View File

@ -664,7 +664,8 @@ AudioDestinationNode::InputMuted(bool aMuted)
}
AudioPlaybackConfig config;
nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config);
nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config,
AudioChannelService::AudibleState::eAudible);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}

View File

@ -714,7 +714,8 @@ nsSpeechTask::CreateAudioChannelAgent()
this);
AudioPlaybackConfig config;
nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config);
nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config,
AudioChannelService::AudibleState::eAudible);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}

View File

@ -2292,7 +2292,8 @@ _setvalue(NPP npp, NPPVariable variable, void *result)
} else {
dom::AudioPlaybackConfig config;
rv = agent->NotifyStartedPlaying(&config);
rv = agent->NotifyStartedPlaying(&config,
dom::AudioChannelService::AudibleState::eAudible);
if (NS_WARN_IF(NS_FAILED(rv))) {
return NPERR_NO_ERROR;
}

View File

@ -562,7 +562,8 @@ Telephony::HandleAudioAgentState()
} else if (!activeCall.IsNull() && !mIsAudioStartPlaying) {
mIsAudioStartPlaying = true;
AudioPlaybackConfig config;
rv = mAudioAgent->NotifyStartedPlaying(&config);
rv = mAudioAgent->NotifyStartedPlaying(&config,
AudioChannelService::AudibleState::eAudible);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}