Bug 844323 - Prelude part 1: Use a pref to in nsHTMLMediaElement to control whether we talk to the audio service. r=amarchesini

Previously, we used #ifdef B2G.  Using a pref allows us to write mochitests which run in desktop Firefox that test the audio service and its interaction with other components.
This commit is contained in:
Justin Lebar 2013-04-25 20:53:25 -04:00
parent d1432b1ada
commit 3541bd638a
3 changed files with 34 additions and 20 deletions

View File

@ -665,6 +665,9 @@ pref("memory_info_dumper.watch_fifo.directory", "/data/local");
pref("general.useragent.enable_overrides", true); pref("general.useragent.enable_overrides", true);
// Make <audio> and <video> talk to the AudioChannelService.
pref("media.useAudioChannelService", true);
pref("b2g.version", @MOZ_B2G_VERSION@); pref("b2g.version", @MOZ_B2G_VERSION@);
// Disable console buffering to save memory. // Disable console buffering to save memory.
@ -673,4 +676,4 @@ pref("consoleservice.buffered", false);
#ifdef MOZ_WIDGET_GONK #ifdef MOZ_WIDGET_GONK
// Performance testing suggests 2k is a better page size for SQLite. // Performance testing suggests 2k is a better page size for SQLite.
pref("toolkit.storage.pageSize", 2048); pref("toolkit.storage.pageSize", 2048);
#endif #endif

View File

@ -970,6 +970,11 @@ static bool IsAutoplayEnabled()
return Preferences::GetBool("media.autoplay.enabled"); return Preferences::GetBool("media.autoplay.enabled");
} }
static bool UseAudioChannelService()
{
return Preferences::GetBool("media.useAudioChannelService");
}
void HTMLMediaElement::UpdatePreloadAction() void HTMLMediaElement::UpdatePreloadAction()
{ {
PreloadAction nextAction = PRELOAD_UNDEFINED; PreloadAction nextAction = PRELOAD_UNDEFINED;
@ -2163,7 +2168,10 @@ bool HTMLMediaElement::ParseAttribute(int32_t aNamespaceID,
bool HTMLMediaElement::CheckAudioChannelPermissions(const nsAString& aString) bool HTMLMediaElement::CheckAudioChannelPermissions(const nsAString& aString)
{ {
#ifdef ANDROID if (!UseAudioChannelService()) {
return true;
}
// Only normal channel doesn't need permission. // Only normal channel doesn't need permission.
if (!aString.EqualsASCII("normal")) { if (!aString.EqualsASCII("normal")) {
nsCOMPtr<nsIPermissionManager> permissionManager = nsCOMPtr<nsIPermissionManager> permissionManager =
@ -2179,7 +2187,7 @@ bool HTMLMediaElement::CheckAudioChannelPermissions(const nsAString& aString)
return false; return false;
} }
} }
#endif
return true; return true;
} }
@ -3218,17 +3226,17 @@ void HTMLMediaElement::SuspendOrResumeElement(bool aPauseElement, bool aSuspendE
void HTMLMediaElement::NotifyOwnerDocumentActivityChanged() void HTMLMediaElement::NotifyOwnerDocumentActivityChanged()
{ {
nsIDocument* ownerDoc = OwnerDoc(); nsIDocument* ownerDoc = OwnerDoc();
#ifdef ANDROID if (UseAudioChannelService()) {
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(OwnerDoc()); nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(OwnerDoc());
if (domDoc) { if (domDoc) {
bool hidden = false; bool hidden = false;
domDoc->GetHidden(&hidden); domDoc->GetHidden(&hidden);
// SetVisibilityState will update mChannelSuspended via the CanPlayChanged callback. // SetVisibilityState will update mChannelSuspended via the CanPlayChanged callback.
if (mPlayingThroughTheAudioChannel && mAudioChannelAgent) { if (mPlayingThroughTheAudioChannel && mAudioChannelAgent) {
mAudioChannelAgent->SetVisibilityState(!hidden); mAudioChannelAgent->SetVisibilityState(!hidden);
}
} }
} }
#endif
bool suspendEvents = !ownerDoc->IsActive() || !ownerDoc->IsVisible(); bool suspendEvents = !ownerDoc->IsActive() || !ownerDoc->IsVisible();
bool pauseElement = suspendEvents || mChannelSuspended; bool pauseElement = suspendEvents || mChannelSuspended;
@ -3656,9 +3664,10 @@ ImageContainer* HTMLMediaElement::GetImageContainer()
nsresult HTMLMediaElement::UpdateChannelMuteState(bool aCanPlay) nsresult HTMLMediaElement::UpdateChannelMuteState(bool aCanPlay)
{ {
// Only on B2G we mute the HTMLMediaElement following the rules of if (!UseAudioChannelService()) {
// AudioChannelService. return NS_OK;
#ifdef ANDROID }
// We have to mute this channel: // We have to mute this channel:
if (!aCanPlay && !mChannelSuspended) { if (!aCanPlay && !mChannelSuspended) {
mChannelSuspended = true; mChannelSuspended = true;
@ -3669,15 +3678,15 @@ nsresult HTMLMediaElement::UpdateChannelMuteState(bool aCanPlay)
} }
SuspendOrResumeElement(mChannelSuspended, false); SuspendOrResumeElement(mChannelSuspended, false);
#endif
return NS_OK; return NS_OK;
} }
void HTMLMediaElement::UpdateAudioChannelPlayingState() void HTMLMediaElement::UpdateAudioChannelPlayingState()
{ {
// The HTMLMediaElement is registered to the AudioChannelService only on B2G. if (!UseAudioChannelService()) {
#ifdef ANDROID return;
}
bool playingThroughTheAudioChannel = bool playingThroughTheAudioChannel =
(!mPaused && (!mPaused &&
(HasAttr(kNameSpaceID_None, nsGkAtoms::loop) || (HasAttr(kNameSpaceID_None, nsGkAtoms::loop) ||
@ -3711,7 +3720,6 @@ void HTMLMediaElement::UpdateAudioChannelPlayingState()
mAudioChannelAgent = nullptr; mAudioChannelAgent = nullptr;
} }
} }
#endif
} }
/* void canPlayChanged (in boolean canPlay); */ /* void canPlayChanged (in boolean canPlay); */

View File

@ -712,3 +712,6 @@ pref("media.webaudio.enabled", true);
// This needs more tests and stability fixes first, as well as UI. // This needs more tests and stability fixes first, as well as UI.
pref("media.navigator.enabled", false); pref("media.navigator.enabled", false);
pref("media.peerconnection.enabled", false); pref("media.peerconnection.enabled", false);
// Make <audio> and <video> talk to the AudioChannelService.
pref("media.useAudioChannelService", true);