Bug 1415766. P1 - we never pass anything other than NS_SEEK_SET to Seek().
MozReview-Commit-ID: AgvapCwwSpr
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -20,17 +20,16 @@
#include "mozilla/ReentrantMonitor.h"
#include "mozilla/Services.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/SystemGroup.h"
#include "mozilla/Telemetry.h"
#include "nsContentUtils.h"
#include "nsIObserverService.h"
#include "nsIPrincipal.h"
-#include "nsISeekableStream.h"
#include "nsPrintfCString.h"
#include "nsProxyRelease.h"
#include "nsThreadUtils.h"
#include "prio.h"
#include <algorithm>
namespace mozilla {
@@ -2409,51 +2408,32 @@ MediaCacheStream::SetPlaybackRate(uint32
ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
if (aBytesPerSecond == mPlaybackBytesPerSecond)
return;
mPlaybackBytesPerSecond = aBytesPerSecond;
mMediaCache->QueueUpdate();
}
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;
}
void
MediaCacheStream::ThrottleReadahead(bool bThrottle)
{
MOZ_ASSERT(NS_IsMainThread());
@@ -2664,17 +2644,17 @@ MediaCacheStream::Read(char* aBuffer, ui
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 = Seek(nsISeekableStream::NS_SEEK_SET, aOffset);
+ nsresult rv = Seek(aOffset);
if (NS_FAILED(rv)) return rv;
return Read(aBuffer, aCount, aBytes);
}
nsresult
MediaCacheStream::ReadFromCache(char* aBuffer, int64_t aOffset, uint32_t aCount)
{
ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
--- a/dom/media/MediaCache.h
+++ b/dom/media/MediaCache.h
@@ -334,19 +334,17 @@ 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.
- // 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,
// 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.