Bug 1302350 - part1 : create audio channel agent in the beginning. draft
authorAlastor Wu <alwu@mozilla.com>
Tue, 01 Nov 2016 17:46:07 +0800
changeset 432487 20ec9c8e274884bbef225c6dfa97ee09324766ed
parent 431996 2c773b97167252cedcba0be0c7af9d4cab192ef5
child 432488 dd3087266d34b01a678cd1006722f99af89c5d33
push id34328
push useralwu@mozilla.com
push dateWed, 02 Nov 2016 06:23:00 +0000
bugs1302350
milestone52.0a1
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
dom/html/HTMLMediaElement.cpp
dom/html/HTMLMediaElement.h
--- 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;