Bug 1326330. Part 2 - add assertions and checks. draft
authorJW Wang <jwwang@mozilla.com>
Fri, 23 Dec 2016 19:19:04 +0800
changeset 454737 2530e9f5a40d2a40da750cdbe41cc9d8fc313959
parent 454736 46526adfb4ace56368a1f9c1b8033f1c1b7ca771
child 454746 a1c4e0e98f2ee79d47ae2c65193a38f4832d102e
push id40013
push userjwwang@mozilla.com
push dateFri, 30 Dec 2016 02:25:00 +0000
bugs1326330
milestone53.0a1
Bug 1326330. Part 2 - add assertions and checks. 1. ensure the 'finish' event is notified only once. 2. assert pushing items to a finished queue. MozReview-Commit-ID: 9lYWPANVz0m
dom/media/MediaQueue.h
--- a/dom/media/MediaQueue.h
+++ b/dom/media/MediaQueue.h
@@ -38,16 +38,17 @@ public:
 
   inline size_t GetSize() const {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
     return nsDeque::GetSize();
   }
 
   inline void Push(T* aItem) {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
+    MOZ_ASSERT(!mEndOfStream);
     MOZ_ASSERT(aItem);
     NS_ADDREF(aItem);
     MOZ_ASSERT(aItem->GetEndTime() >= aItem->mTime);
     nsDeque::Push(aItem);
     mPushEvent.Notify(RefPtr<T>(aItem));
   }
 
   inline already_AddRefed<T> PopFront() {
@@ -83,18 +84,20 @@ public:
   bool IsFinished() const {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
     return mEndOfStream;
   }
 
   // Informs the media queue that it won't be receiving any more items.
   void Finish() {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-    mEndOfStream = true;
-    mFinishEvent.Notify();
+    if (!mEndOfStream) {
+      mEndOfStream = true;
+      mFinishEvent.Notify();
+    }
   }
 
   // Returns the approximate number of microseconds of items in the queue.
   int64_t Duration() {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
     if (GetSize() == 0) {
       return 0;
     }