From cd5164d38dae8e3990295754bfc736135086c2af Mon Sep 17 00:00:00 2001 From: JW Wang Date: Thu, 2 Nov 2017 14:26:24 +0800 Subject: [PATCH] Bug 1415766. P1 - we never pass anything other than NS_SEEK_SET to Seek(). r=bechen,gerald MozReview-Commit-ID: AgvapCwwSpr --HG-- extra : rebase_source : 2ba05b44f228c3d9a9440202c024abbd5487282f extra : intermediate-source : f2ec0fec7c544171e7567beed322349dfb8e59a8 extra : source : 8e34a87b250f800897a761d2ccd408959007d02b --- dom/media/MediaCache.cpp | 30 +++++------------------------- dom/media/MediaCache.h | 4 +--- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/dom/media/MediaCache.cpp b/dom/media/MediaCache.cpp index d1a7e9f4679e..7e027a3628a8 100644 --- a/dom/media/MediaCache.cpp +++ b/dom/media/MediaCache.cpp @@ -25,7 +25,6 @@ #include "nsContentUtils.h" #include "nsIObserverService.h" #include "nsIPrincipal.h" -#include "nsISeekableStream.h" #include "nsPrintfCString.h" #include "nsProxyRelease.h" #include "nsThreadUtils.h" @@ -2414,41 +2413,22 @@ MediaCacheStream::SetPlaybackRate(uint32_t aBytesPerSecond) } nsresult -MediaCacheStream::Seek(int32_t aWhence, int64_t aOffset) +MediaCacheStream::Seek(int64_t aOffset) { NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread"); ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor()); - 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 (mClosed) { return NS_ERROR_FAILURE; } - + int64_t oldOffset = mStreamOffset; + int64_t newOffset = aOffset; if (!IsOffsetAllowed(newOffset)) { return NS_ERROR_FAILURE; } mStreamOffset = newOffset; - LOG("Stream %p Seek to %" PRId64, this, mStreamOffset); mMediaCache->NoteSeek(this, oldOffset); - mMediaCache->QueueUpdate(); return NS_OK; } @@ -2669,7 +2649,7 @@ MediaCacheStream::ReadAt(int64_t aOffset, char* aBuffer, NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread"); ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor()); - nsresult rv = Seek(nsISeekableStream::NS_SEEK_SET, aOffset); + nsresult rv = Seek(aOffset); if (NS_FAILED(rv)) return rv; return Read(aBuffer, aCount, aBytes); } diff --git a/dom/media/MediaCache.h b/dom/media/MediaCache.h index 7d830ce42c31..68d8d1ecf462 100644 --- a/dom/media/MediaCache.h +++ b/dom/media/MediaCache.h @@ -339,9 +339,7 @@ public: // 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. - // This can fail when aWhence is NS_SEEK_END and no stream length - // is known. - nsresult Seek(int32_t aWhence, int64_t aOffset); + 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,