Bug 1339230 - part1 : only need to do audio competing for active agent. r=baku

In Fennec, the audio competiting is to stop the playing tab if there is new
incoming tab. We only implement the way to pause the tab, not including to resume
the tab, so we just need to run the audio competing related stuffs when the agent
is active.

MozReview-Commit-ID: 3F0M2jLw9VY

--HG--
extra : rebase_source : 59eeb82cdda4a976a078663557776f4bc3b5d27b
This commit is contained in:
Alastor Wu 2017-02-24 17:15:20 +08:00
Родитель cae0cc252f
Коммит f940903c73
2 изменённых файлов: 20 добавлений и 25 удалений

Просмотреть файл

@ -1087,8 +1087,7 @@ AudioChannelService::ChildStatusReceived(uint64_t aChildID,
}
void
AudioChannelService::RefreshAgentsAudioFocusChanged(AudioChannelAgent* aAgent,
bool aActive)
AudioChannelService::RefreshAgentsAudioFocusChanged(AudioChannelAgent* aAgent)
{
MOZ_ASSERT(aAgent);
@ -1097,7 +1096,7 @@ AudioChannelService::RefreshAgentsAudioFocusChanged(AudioChannelAgent* aAgent,
while (iter.HasMore()) {
AudioChannelWindow* winData = iter.GetNext();
if (winData->mOwningAudioFocus) {
winData->AudioFocusChanged(aAgent, aActive);
winData->AudioFocusChanged(aAgent);
}
}
}
@ -1156,8 +1155,7 @@ AudioChannelService::AudioChannelWindow::RequestAudioFocus(AudioChannelAgent* aA
}
void
AudioChannelService::AudioChannelWindow::NotifyAudioCompetingChanged(AudioChannelAgent* aAgent,
bool aActive)
AudioChannelService::AudioChannelWindow::NotifyAudioCompetingChanged(AudioChannelAgent* aAgent)
{
// This function may be called after RemoveAgentAndReduceAgentsNum(), so the
// agent may be not contained in mAgent. In addition, the agent would still
@ -1177,10 +1175,10 @@ AudioChannelService::AudioChannelWindow::NotifyAudioCompetingChanged(AudioChanne
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
("AudioChannelWindow, NotifyAudioCompetingChanged, this = %p, "
"agent = %p, active = %d\n",
this, aAgent, aActive));
"agent = %p\n",
this, aAgent));
service->RefreshAgentsAudioFocusChanged(aAgent, aActive);
service->RefreshAgentsAudioFocusChanged(aAgent);
}
bool
@ -1210,8 +1208,7 @@ AudioChannelService::AudioChannelWindow::IsAudioCompetingInSameTab() const
}
void
AudioChannelService::AudioChannelWindow::AudioFocusChanged(AudioChannelAgent* aNewPlayingAgent,
bool aActive)
AudioChannelService::AudioChannelWindow::AudioFocusChanged(AudioChannelAgent* aNewPlayingAgent)
{
// This agent isn't always known for the current window, because it can comes
// from other window.
@ -1236,8 +1233,7 @@ AudioChannelService::AudioChannelWindow::AudioFocusChanged(AudioChannelAgent* aN
}
uint32_t type = GetCompetingBehavior(agent,
aNewPlayingAgent->AudioChannelType(),
aActive);
aNewPlayingAgent->AudioChannelType());
// If window will be suspended, it needs to abandon the audio focus
// because only one window can own audio focus at a time. However, we
@ -1267,8 +1263,7 @@ AudioChannelService::AudioChannelWindow::IsContainingPlayingAgent(AudioChannelAg
uint32_t
AudioChannelService::AudioChannelWindow::GetCompetingBehavior(AudioChannelAgent* aAgent,
int32_t aIncomingChannelType,
bool aIncomingChannelActive) const
int32_t aIncomingChannelType) const
{
MOZ_ASSERT(aAgent);
MOZ_ASSERT(IsEnableAudioCompetingForAllAgents() ?
@ -1279,8 +1274,7 @@ AudioChannelService::AudioChannelWindow::GetCompetingBehavior(AudioChannelAgent*
// TODO : add other competing cases for MediaSession API
if (presentChannelType == int32_t(AudioChannel::Normal) &&
aIncomingChannelType == int32_t(AudioChannel::Normal) &&
aIncomingChannelActive) {
aIncomingChannelType == int32_t(AudioChannel::Normal)) {
competingBehavior = nsISuspendedTypes::SUSPENDED_STOP_DISPOSABLE;
}
@ -1314,7 +1308,7 @@ AudioChannelService::AudioChannelWindow::AppendAgent(AudioChannelAgent* aAgent,
AudibleChangedReasons::eDataAudibleChanged);
} else if (IsEnableAudioCompetingForAllAgents() &&
aAudible != AudibleState::eAudible) {
NotifyAudioCompetingChanged(aAgent, true);
NotifyAudioCompetingChanged(aAgent);
}
}
@ -1412,8 +1406,9 @@ AudioChannelService::AudioChannelWindow::AudioAudibleChanged(AudioChannelAgent*
RemoveAudibleAgentIfContained(aAgent, aReason);
}
NotifyAudioCompetingChanged(aAgent, aAudible == AudibleState::eAudible);
if (aAudible != AudibleState::eNotAudible) {
if (aAudible == AudibleState::eAudible) {
NotifyAudioCompetingChanged(aAgent);
} else if (aAudible != AudibleState::eNotAudible) {
MaybeNotifyMediaBlockStart(aAgent);
}
}

Просмотреть файл

@ -233,8 +233,7 @@ private:
void SetDefaultVolumeControlChannelInternal(int32_t aChannel,
bool aVisible, uint64_t aChildID);
void RefreshAgentsAudioFocusChanged(AudioChannelAgent* aAgent,
bool aActive);
void RefreshAgentsAudioFocusChanged(AudioChannelAgent* aAgent);
class AudioChannelConfig final : public AudioPlaybackConfig
{
@ -261,7 +260,7 @@ private:
mChannels[(int16_t)AudioChannel::System].mMuted = false;
}
void AudioFocusChanged(AudioChannelAgent* aNewPlayingAgent, bool aActive);
void AudioFocusChanged(AudioChannelAgent* aNewPlayingAgent);
void AudioAudibleChanged(AudioChannelAgent* aAgent,
AudibleState aAudible,
AudibleChangedReasons aReason);
@ -310,11 +309,12 @@ private:
void MaybeNotifyMediaBlockStart(AudioChannelAgent* aAgent);
void RequestAudioFocus(AudioChannelAgent* aAgent);
void NotifyAudioCompetingChanged(AudioChannelAgent* aAgent, bool aActive);
// We need to do audio competing only when the new incoming agent started.
void NotifyAudioCompetingChanged(AudioChannelAgent* aAgent);
uint32_t GetCompetingBehavior(AudioChannelAgent* aAgent,
int32_t aIncomingChannelType,
bool aIncomingChannelActive) const;
int32_t aIncomingChannelType) const;
bool IsAgentInvolvingInAudioCompeting(AudioChannelAgent* aAgent) const;
bool IsAudioCompetingInSameTab() const;
bool IsContainingPlayingAgent(AudioChannelAgent* aAgent) const;