Bug 1296531 - Add MediaSegment::IsNull. r?jesup draft
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 16 May 2017 13:06:02 +0200
changeset 670314 b99f08db97240d20a0d4cc9c47c929d75ea92e8e
parent 670313 41ccce50c2a305e25d662986839931489d2338fb
child 670315 df8ef53c3587c4a4dbcc47692b823dd218187f64
push id81598
push userbmo:apehrson@mozilla.com
push dateTue, 26 Sep 2017 09:13:19 +0000
reviewersjesup
bugs1296531
milestone58.0a1
Bug 1296531 - Add MediaSegment::IsNull. r?jesup This allows us to see if all chunks in a MediaSegment are null. When this is true for the MediaSegment passed to NotifyQueuedChanges, we can assume that the track's input is blocked for the given time. MozReview-Commit-ID: zf7V7aiohg
dom/media/AudioSegment.h
dom/media/MediaSegment.h
--- a/dom/media/AudioSegment.h
+++ b/dom/media/AudioSegment.h
@@ -403,26 +403,16 @@ public:
     for (ChunkIterator ci(*this); !ci.IsEnded(); ci.Next()) {
       if (ci->ChannelCount()) {
         return ci->ChannelCount();
       }
     }
     return 0;
   }
 
-  bool IsNull() const {
-    for (ChunkIterator ci(*const_cast<AudioSegment*>(this)); !ci.IsEnded();
-         ci.Next()) {
-      if (!ci->IsNull()) {
-        return false;
-      }
-    }
-    return true;
-  }
-
   static Type StaticType() { return AUDIO; }
 
   size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override
   {
     return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
   }
 };
 
--- a/dom/media/MediaSegment.h
+++ b/dom/media/MediaSegment.h
@@ -144,16 +144,21 @@ public:
    * principal id than the current one.
    */
   void SetLastPrincipalHandle(const PrincipalHandle& aLastPrincipalHandle)
   {
     mLastPrincipalHandle = aLastPrincipalHandle;
   }
 
   /**
+   * Returns true if all chunks in this segment are null.
+   */
+  virtual bool IsNull() const = 0;
+
+  /**
    * Create a MediaSegment of the same type.
    */
   virtual MediaSegment* CreateEmptyClone() const = 0;
   /**
    * Moves contents of aSource to the end of this segment.
    */
   virtual void AppendFrom(MediaSegment* aSource) = 0;
   /**
@@ -224,16 +229,25 @@ protected:
 };
 
 /**
  * C is the implementation class subclassed from MediaSegmentBase.
  * C must contain a Chunk class.
  */
 template <class C, class Chunk> class MediaSegmentBase : public MediaSegment {
 public:
+  bool IsNull() const override
+  {
+    for (typename C::ConstChunkIterator iter(*this); !iter.IsEnded(); iter.Next()) {
+      if (!iter->IsNull()) {
+        return false;
+      }
+    }
+    return true;
+  }
   MediaSegment* CreateEmptyClone() const override
   {
     return new C();
   }
   void AppendFrom(MediaSegment* aSource) override
   {
     NS_ASSERTION(aSource->GetType() == C::StaticType(), "Wrong type");
     AppendFromInternal(static_cast<C*>(aSource));