Bug 1415766. P2 - move Seek() to private and tighten up some assertions. draft
authorJW Wang <jwwang@mozilla.com>
Thu, 02 Nov 2017 14:46:24 +0800
changeset 695421 ea534d1dc86b986927d7f2425c7300a35496e8c1
parent 695342 7c6146ae0eaba6cea78e7d147b7ecb1951c951f0
child 739586 ce5fd191b85cb80f476bfa3b9979d5a343875ef2
push id88410
push userjwwang@mozilla.com
push dateThu, 09 Nov 2017 05:42:56 +0000
bugs1415766
milestone58.0a1
Bug 1415766. P2 - move Seek() to private and tighten up some assertions. MozReview-Commit-ID: BBsXqKUrOi1
dom/media/MediaCache.cpp
dom/media/MediaCache.h
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -2410,28 +2410,28 @@ MediaCacheStream::SetPlaybackRate(uint32
     return;
   mPlaybackBytesPerSecond = aBytesPerSecond;
   mMediaCache->QueueUpdate();
 }
 
 nsresult
 MediaCacheStream::Seek(int64_t aOffset)
 {
-  NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
+  MOZ_ASSERT(!NS_IsMainThread());
+  mMediaCache->GetReentrantMonitor().AssertCurrentThreadIn();
 
-  ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
-  if (mClosed) {
-    return NS_ERROR_FAILURE;
+  if (!IsOffsetAllowed(aOffset)) {
+    return NS_ERROR_ILLEGAL_VALUE;
   }
+  if (mClosed) {
+    return NS_ERROR_ABORT;
+  }
+
   int64_t oldOffset = mStreamOffset;
-  int64_t newOffset = aOffset;
-  if (!IsOffsetAllowed(newOffset)) {
-    return NS_ERROR_FAILURE;
-  }
-  mStreamOffset = newOffset;
+  mStreamOffset = aOffset;
   LOG("Stream %p Seek to %" PRId64, this, mStreamOffset);
   mMediaCache->NoteSeek(this, oldOffset);
   mMediaCache->QueueUpdate();
   return NS_OK;
 }
 
 void
 MediaCacheStream::ThrottleReadahead(bool bThrottle)
--- a/dom/media/MediaCache.h
+++ b/dom/media/MediaCache.h
@@ -334,17 +334,16 @@ public:
 
   // Returns true when all streams for this resource are suspended or their
   // channel has ended.
   bool AreAllStreamsForResourceSuspended();
 
   // These methods must be called on a different thread from the main
   // thread. They should always be called on the same thread for a given
   // stream.
-  nsresult Seek(int64_t aOffset);
   int64_t Tell();
   // *aBytes gets the number of bytes that were actually read. This can
   // be less than aCount. If the first byte of data is not in the cache,
   // this will block until the data is available or the stream is
   // closed, otherwise it won't block.
   nsresult Read(char* aBuffer, uint32_t aCount, uint32_t* aBytes);
   // Seeks to aOffset in the stream then performs a Read operation. See
   // 'Read' for argument and return details.
@@ -428,16 +427,19 @@ private:
   // is nothing to read.
   uint32_t ReadPartialBlock(int64_t aOffset, Span<char> aBuffer);
 
   // Read data from the cache block specified by aOffset. Return the number of
   // bytes read successfully or an error code if any failure.
   Result<uint32_t, nsresult> ReadBlockFromCache(int64_t aOffset,
                                                 Span<char> aBuffer);
 
+  // Non-main thread only.
+  nsresult Seek(int64_t aOffset);
+
   // Returns the end of the bytes starting at the given offset
   // which are in cache.
   // This method assumes that the cache monitor is held and can be called on
   // any thread.
   int64_t GetCachedDataEndInternal(int64_t aOffset);
   // Returns the offset of the first byte of cached data at or after aOffset,
   // or -1 if there is no such cached data.
   // This method assumes that the cache monitor is held and can be called on