Bug 882665 - Part b: Add list of pending text tracks to TextTrackManager. r=rillian, khuey
authorAndrew Quartey <andrew.quartey@gmail.com>
Fri, 25 Oct 2013 00:14:36 -0400
changeset 165944 53dd3aa9be7e239e1a0cac0ad6262b182685b6bb
parent 165943 2f3d1761b05915b2dd6713a5bcdee6548628a973
child 165945 c79088ab4e0c3c44a3352610effae537dc5b698b
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian, khuey
bugs882665
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 882665 - Part b: Add list of pending text tracks to TextTrackManager. r=rillian, khuey
content/html/content/public/HTMLMediaElement.h
content/html/content/src/HTMLMediaElement.cpp
content/html/content/src/TextTrackManager.cpp
content/html/content/src/TextTrackManager.h
content/media/TextTrack.cpp
--- a/content/html/content/public/HTMLMediaElement.h
+++ b/content/html/content/public/HTMLMediaElement.h
@@ -527,19 +527,19 @@ public:
                                            const nsAString& aLanguage);
 
   void AddTextTrack(TextTrack* aTextTrack) {
     if (mTextTrackManager) {
       mTextTrackManager->AddTextTrack(aTextTrack);
     }
   }
 
-  void RemoveTextTrack(TextTrack* aTextTrack) {
+  void RemoveTextTrack(TextTrack* aTextTrack, bool aPendingListOnly = false) {
     if (mTextTrackManager) {
-      mTextTrackManager->RemoveTextTrack(aTextTrack);
+      mTextTrackManager->RemoveTextTrack(aTextTrack, aPendingListOnly);
     }
   }
 
   /**
    * A public wrapper for FinishDecoderSetup()
    */
   nsresult FinishDecoderSetup(MediaDecoder* aDecoder, MediaResource* aStream) {
     return FinishDecoderSetup(aDecoder, aStream, nullptr, nullptr);
@@ -857,16 +857,21 @@ protected:
   bool CheckAudioChannelPermissions(const nsAString& aType);
 
   // This method does the check for muting/fading/unmuting the audio channel.
   nsresult UpdateChannelMuteState(mozilla::dom::AudioChannelState aCanPlay);
 
   // Update the audio channel playing state
   virtual void UpdateAudioChannelPlayingState();
 
+  // Adds to the element's list of pending text tracks each text track
+  // in the element's list of text tracks whose text track mode is not disabled
+  // and whose text track readiness state is loading.
+  void PopulatePendingTextTrackList();
+
   // The current decoder. Load() has been called on this decoder.
   // At most one of mDecoder and mSrcStream can be non-null.
   nsRefPtr<MediaDecoder> mDecoder;
 
   // A reference to the VideoFrameContainer which contains the current frame
   // of video to display.
   nsRefPtr<VideoFrameContainer> mVideoFrameContainer;
 
--- a/content/html/content/src/HTMLMediaElement.cpp
+++ b/content/html/content/src/HTMLMediaElement.cpp
@@ -3915,10 +3915,18 @@ HTMLMediaElement::AddTextTrack(TextTrack
                                const nsAString& aLabel,
                                const nsAString& aLanguage)
 {
   return mTextTrackManager ? mTextTrackManager->AddTextTrack(aKind, aLabel,
                                                              aLanguage)
                            : nullptr;
 }
 
+void
+HTMLMediaElement::PopulatePendingTextTrackList()
+{
+  if (mTextTrackManager) {
+    mTextTrackManager->PopulatePendingList();
+  }
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/content/html/content/src/TextTrackManager.cpp
+++ b/content/html/content/src/TextTrackManager.cpp
@@ -7,25 +7,27 @@
 
 #include "mozilla/dom/TextTrackManager.h"
 #include "mozilla/dom/HTMLMediaElement.h"
 #include "mozilla/dom/HTMLTrackElement.h"
 
 namespace mozilla {
 namespace dom {
 
-NS_IMPL_CYCLE_COLLECTION_1(TextTrackManager, mTextTracks)
+NS_IMPL_CYCLE_COLLECTION_2(TextTrackManager, mTextTracks, mPendingTextTracks)
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(TextTrackManager, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(TextTrackManager, Release)
 
 TextTrackManager::TextTrackManager(HTMLMediaElement *aMediaElement)
   : mMediaElement(aMediaElement)
 {
   MOZ_COUNT_CTOR(TextTrackManager);
   mTextTracks = new TextTrackList(mMediaElement->OwnerDoc()->GetParentObject());
+  mPendingTextTracks =
+    new TextTrackList(mMediaElement->OwnerDoc()->GetParentObject());
 }
 
 TextTrackManager::~TextTrackManager()
 {
   MOZ_COUNT_DTOR(TextTrackManager);
 }
 
 TextTrackList*
@@ -46,27 +48,46 @@ TextTrackManager::AddTextTrack(TextTrack
 
 void
 TextTrackManager::AddTextTrack(TextTrack* aTextTrack)
 {
   mTextTracks->AddTextTrack(aTextTrack);
 }
 
 void
-TextTrackManager::RemoveTextTrack(TextTrack* aTextTrack)
+TextTrackManager::RemoveTextTrack(TextTrack* aTextTrack, bool aPendingListOnly)
 {
+  mPendingTextTracks->RemoveTextTrack(aTextTrack);
+  if (aPendingListOnly) {
+    return;
+  }
+
   mTextTracks->RemoveTextTrack(aTextTrack);
 }
 
 void
 TextTrackManager::DidSeek()
 {
   mTextTracks->DidSeek();
 }
 
 void
 TextTrackManager::Update(double aTime)
 {
   mTextTracks->Update(aTime);
 }
 
+void
+TextTrackManager::PopulatePendingList()
+{
+  uint32_t len = mTextTracks->Length();
+  bool dummy;
+  for (uint32_t index = 0; index < len; ++index) {
+    TextTrack* ttrack = mTextTracks->IndexedGetter(index, dummy);
+    if (ttrack && ttrack->Mode() != TextTrackMode::Disabled &&
+        ttrack->ReadyState() == HTMLTrackElement::LOADING) {
+      mPendingTextTracks->AddTextTrack(ttrack);
+    }
+  }
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/content/html/content/src/TextTrackManager.h
+++ b/content/html/content/src/TextTrackManager.h
@@ -25,29 +25,33 @@ public:
   TextTrackManager(HTMLMediaElement *aMediaElement);
   ~TextTrackManager();
 
   TextTrackList* TextTracks() const;
   already_AddRefed<TextTrack> AddTextTrack(TextTrackKind aKind,
                                            const nsAString& aLabel,
                                            const nsAString& aLanguage);
   void AddTextTrack(TextTrack* aTextTrack);
-  void RemoveTextTrack(TextTrack* aTextTrack);
+  void RemoveTextTrack(TextTrack* aTextTrack, bool aPendingListOnly);
   void DidSeek();
 
   // Update the display of cues on the video as per the current play back time
   // of aTime.
   void Update(double aTime);
 
+  void PopulatePendingList();
+
 private:
   // The HTMLMediaElement that this TextTrackManager manages the TextTracks of.
   // This is a weak reference as the life time of TextTrackManager is dependent
   // on the HTMLMediaElement, so it should not be trying to hold the
   // HTMLMediaElement alive.
   HTMLMediaElement* mMediaElement;
   // List of the TextTrackManager's owning HTMLMediaElement's TextTracks.
   nsRefPtr<TextTrackList> mTextTracks;
+  // List of text track objects awaiting loading.
+  nsRefPtr<TextTrackList> mPendingTextTracks;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_TextTrackManager_h
--- a/content/media/TextTrack.cpp
+++ b/content/media/TextTrack.cpp
@@ -177,12 +177,16 @@ TextTrack::ReadyState() const
 {
   return mReadyState;
 }
 
 void
 TextTrack::SetReadyState(uint16_t aState)
 {
   mReadyState = aState;
+  if (mReadyState == HTMLTrackElement::LOADED ||
+      mReadyState == HTMLTrackElement::ERROR) {
+    mMediaElement->RemoveTextTrack(this, true);
+  }
 }
 
 } // namespace dom
 } // namespace mozilla