Bug 882718 - Implement GetCueListByTimeInterval() at TextTrackCueList object. r=rillian
authorbechen <bechen@mozilla.com>
Wed, 01 Jun 2016 13:35:54 +0800
changeset 339132 61ffbcb578acacf05a572b4fc62ac210473f663f
parent 339131 e00bbe392726374f2fb99e6aa4e56f77ae80b0f6
child 339133 a12cd85eb79d0f93e62375f4731c6cbee82ce79e
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs882718
milestone49.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 882718 - Implement GetCueListByTimeInterval() at TextTrackCueList object. r=rillian MozReview-Commit-ID: 1T3EEfG83ec
dom/media/TextTrackCueList.cpp
dom/media/TextTrackCueList.h
--- a/dom/media/TextTrackCueList.cpp
+++ b/dom/media/TextTrackCueList.cpp
@@ -120,10 +120,24 @@ TextTrackCueList::GetArray(nsTArray<RefP
 void
 TextTrackCueList::SetCuesInactive()
 {
   for(uint32_t i = 0; i < mList.Length(); ++i) {
     mList[i]->SetActive(false);
   }
 }
 
+already_AddRefed<TextTrackCueList>
+TextTrackCueList::GetCueListByTimeInterval(media::Interval<double>& aInterval)
+{
+  RefPtr<TextTrackCueList> output = new TextTrackCueList(mParent);
+  for (uint32_t i = 0; i < mList.Length(); ++i) {
+    TextTrackCue* cue = mList[i];
+    if (cue->StartTime() <= aInterval.mEnd &&
+        aInterval.mStart <= cue->EndTime()) {
+      output->AddCue(*cue);
+    }
+  }
+  return output.forget();
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/media/TextTrackCueList.h
+++ b/dom/media/TextTrackCueList.h
@@ -7,16 +7,17 @@
 #ifndef mozilla_dom_TextTrackCueList_h
 #define mozilla_dom_TextTrackCueList_h
 
 #include "nsTArray.h"
 #include "nsCOMPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsWrapperCache.h"
 #include "mozilla/ErrorResult.h"
+#include "Intervals.h"
 
 namespace mozilla {
 namespace dom {
 
 class TextTrackCue;
 
 class TextTrackCueList final : public nsISupports
                              , public nsWrapperCache
@@ -51,16 +52,19 @@ public:
   void AddCue(TextTrackCue& aCue);
   void RemoveCue(TextTrackCue& aCue, ErrorResult& aRv);
   void RemoveCueAt(uint32_t aIndex);
   void RemoveAll();
   void GetArray(nsTArray<RefPtr<TextTrackCue> >& aCues);
 
   void SetCuesInactive();
 
+  already_AddRefed<TextTrackCueList>
+  GetCueListByTimeInterval(media::Interval<double>& aInterval);
+
 private:
   ~TextTrackCueList();
 
   nsCOMPtr<nsISupports> mParent;
 
   // A sorted list of TextTrackCues sorted by earliest start time. If the start
   // times are equal then it will be sorted by end time, earliest first.
   nsTArray< RefPtr<TextTrackCue> > mList;