Bug 1302350 - part1 : create audio channel agent in the beginning.
We create audio channel agent in the beginning in oreder to use some agent's methods.
But the agent is still started after media element starting playing.
MozReview-Commit-ID: KPGb7snB2t7
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -2915,16 +2915,17 @@ HTMLMediaElement::HTMLMediaElement(alrea
MOZ_ASSERT(NS_IsMainThread());
mWatchManager.Watch(mDownloadSuspendedByCache, &HTMLMediaElement::UpdateReadyStateInternal);
// Paradoxically, there is a self-edge whereby UpdateReadyStateInternal refuses
// to run until mReadyState reaches at least HAVE_METADATA by some other means.
mWatchManager.Watch(mReadyState, &HTMLMediaElement::UpdateReadyStateInternal);
mShutdownObserver->Subscribe(this);
+ CreateAudioChannelAgent();
}
HTMLMediaElement::~HTMLMediaElement()
{
NS_ASSERTION(!mHasSelfReference,
"How can we be destroyed if we're still holding a self reference?");
mShutdownObserver->Unsubscribe();
@@ -5774,23 +5775,16 @@ HTMLMediaElement::IsPlayingThroughTheAud
void
HTMLMediaElement::UpdateAudioChannelPlayingState()
{
bool playingThroughTheAudioChannel = IsPlayingThroughTheAudioChannel();
if (playingThroughTheAudioChannel != mPlayingThroughTheAudioChannel) {
mPlayingThroughTheAudioChannel = playingThroughTheAudioChannel;
-
- // If we are not playing, we don't need to create a new audioChannelAgent.
- if (!mAudioChannelAgent && !mPlayingThroughTheAudioChannel) {
- return;
- }
-
- CreateAudioChannelAgent();
NotifyAudioChannelAgent(mPlayingThroughTheAudioChannel);
}
}
void
HTMLMediaElement::NotifyAudioChannelAgent(bool aPlaying)
{
// This is needed to pass nsContentUtils::IsCallerChrome().
@@ -5811,17 +5805,16 @@ HTMLMediaElement::NotifyAudioChannelAgen
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
WindowVolumeChanged(config.mVolume, config.mMuted);
WindowSuspendChanged(config.mSuspend);
} else {
mAudioChannelAgent->NotifyStoppedPlaying();
- mAudioChannelAgent = nullptr;
}
}
NS_IMETHODIMP
HTMLMediaElement::WindowVolumeChanged(float aVolume, bool aMuted)
{
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
("HTMLMediaElement, WindowVolumeChanged, this = %p, "
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1217,17 +1217,18 @@ protected:
TextTrackManager* GetOrCreateTextTrackManager();
// Recomputes ready state and fires events as necessary based on current state.
void UpdateReadyStateInternal();
// Notifies the audio channel agent when the element starts or stops playing.
void NotifyAudioChannelAgent(bool aPlaying);
- // Creates the audio channel agent.
+ // Creates the audio channel agent in the beginning and this agent would be
+ // used to communicate with the AudioChannelService.
void CreateAudioChannelAgent();
// Determine if the element should be paused because of suspend conditions.
bool ShouldElementBePaused();
// Create or destroy the captured stream depend on mAudioCapturedByWindow.
void AudioCaptureStreamChangeIfNeeded();
@@ -1622,17 +1623,18 @@ protected:
// Is this media element playing?
bool mPlayingThroughTheAudioChannel;
// Disable the video playback by track selection. This flag might not be
// enough if we ever expand the ability of supporting multi-tracks video
// playback.
bool mDisableVideo;
- // An agent used to join audio channel service.
+ // An agent used to join audio channel service and its life cycle would equal
+ // to media element.
RefPtr<AudioChannelAgent> mAudioChannelAgent;
RefPtr<TextTrackManager> mTextTrackManager;
RefPtr<AudioTrackList> mAudioTrackList;
RefPtr<VideoTrackList> mVideoTrackList;