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
--- 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;
}