Bug 1415766. P2 - move Seek() to private and tighten up some assertions. r=bechen,gerald
authorJW Wang <jwwang@mozilla.com>
Thu, 02 Nov 2017 14:46:24 +0800
changeset 444179 b12b1f6beb496de17cfcaa8af70d7216853b2866
parent 444178 753f3591930d7a1ef1cd2a8e4cbe9e0f6b57d901
child 444180 2f059a9dbd9d0b76230f53a78bf29dfad1e56d06
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbechen, gerald
bugs1415766
milestone58.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 1415766. P2 - move Seek() to private and tighten up some assertions. r=bechen,gerald 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