Bug 1374173 - SeekInternal is only used to SEEK_SET - r?jwwang draft
authorGerald Squelart <gsquelart@mozilla.com>
Tue, 13 Jun 2017 16:13:33 +1200
changeset 596337 b67a0f0d7b89c261c9771a6537a8031998fa5252
parent 596336 aceddfeddadbb5db6b91a73aa03d9a9a10799be2
child 633913 d52f4a8db4e75c8bbfcb2dc95bebac28b9d70525
push id64581
push usergsquelart@mozilla.com
push dateMon, 19 Jun 2017 04:51:32 +0000
reviewersjwwang
bugs1374173
milestone56.0a1
Bug 1374173 - SeekInternal is only used to SEEK_SET - r?jwwang So its code can be simplified by removing the code doing other operations. MozReview-Commit-ID: 32g7lp2XLNE
dom/media/MediaCache.cpp
dom/media/MediaCache.h
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -2238,45 +2238,30 @@ MediaCacheStream::SetPlaybackRate(uint32
   ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
   if (aBytesPerSecond == mPlaybackBytesPerSecond)
     return;
   mPlaybackBytesPerSecond = aBytesPerSecond;
   mMediaCache->QueueUpdate();
 }
 
 nsresult
-MediaCacheStream::SeekInternal(int32_t aWhence, int64_t aOffset)
+MediaCacheStream::SeekInternal(int64_t aOffset)
 {
-  mMediaCache->GetReentrantMonitor().AssertCurrentThreadIn();
-
-  if (mClosed)
-    return NS_ERROR_FAILURE;
-
-  int64_t oldOffset = mStreamOffset;
-  int64_t newOffset = mStreamOffset;
-  switch (aWhence) {
-  case PR_SEEK_END:
-    if (mStreamLength < 0)
-      return NS_ERROR_FAILURE;
-    newOffset = mStreamLength + aOffset;
-    break;
-  case PR_SEEK_CUR:
-    newOffset += aOffset;
-    break;
-  case PR_SEEK_SET:
-    newOffset = aOffset;
-    break;
-  default:
-    NS_ERROR("Unknown whence");
+  if (aOffset < 0) {
     return NS_ERROR_FAILURE;
   }
 
-  if (newOffset < 0)
+  mMediaCache->GetReentrantMonitor().AssertCurrentThreadIn();
+
+  if (mClosed) {
     return NS_ERROR_FAILURE;
-  mStreamOffset = newOffset;
+  }
+
+  int64_t oldOffset = mStreamOffset;
+  mStreamOffset = aOffset;
 
   LOG("Stream %p Seek to %" PRId64, this, mStreamOffset);
   mMediaCache->NoteSeek(this, oldOffset);
 
   mMediaCache->QueueUpdate();
   return NS_OK;
 }
 
@@ -2412,17 +2397,17 @@ MediaCacheStream::ReadInternal(char* aBu
 
 nsresult
 MediaCacheStream::ReadAt(int64_t aOffset, char* aBuffer,
                          uint32_t aCount, uint32_t* aBytes)
 {
   NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
 
   ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
-  nsresult rv = SeekInternal(nsISeekableStream::NS_SEEK_SET, aOffset);
+  nsresult rv = SeekInternal(aOffset);
   if (NS_FAILED(rv)) return rv;
   return ReadInternal(aBuffer, aCount, aBytes);
 }
 
 nsresult
 MediaCacheStream::ReadFromCache(char* aBuffer, int64_t aOffset, int64_t aCount)
 {
   ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
--- a/dom/media/MediaCache.h
+++ b/dom/media/MediaCache.h
@@ -429,19 +429,17 @@ private:
   // that the cache monitor is held. Main thread only.
   // aReentrantMonitor is the nsAutoReentrantMonitor wrapper holding the cache monitor.
   // This is used to NotifyAll to wake up threads that might be
   // blocked on reading from this stream.
   void CloseInternal(ReentrantMonitorAutoEnter& aReentrantMonitor);
   // Update mPrincipal given that data has been received from aPrincipal
   bool UpdatePrincipal(nsIPrincipal* aPrincipal);
 
-  // This can fail when aWhence is NS_SEEK_END and no stream length
-  // is known.
-  nsresult SeekInternal(int32_t aWhence, int64_t aOffset);
+  nsresult SeekInternal(int64_t aOffset);
   // *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 ReadInternal(char* aBuffer, uint32_t aCount, uint32_t* aBytes);
 
   // Instance of MediaCache to use with this MediaCacheStream.
   RefPtr<MediaCache> mMediaCache;