Bug 1417774 - remove unused MediaResource::Tell().
MozReview-Commit-ID: 3qlP4sSh9kM
--- a/dom/media/BufferMediaResource.h
+++ b/dom/media/BufferMediaResource.h
@@ -17,17 +17,16 @@ namespace mozilla {
// on top of it. The Read implementation involves copying memory, which is
// unfortunate, but the MediaResource interface mandates that.
class BufferMediaResource : public MediaResource
{
public:
BufferMediaResource(const uint8_t* aBuffer, uint32_t aLength)
: mBuffer(aBuffer)
, mLength(aLength)
- , mOffset(0)
{
}
protected:
virtual ~BufferMediaResource()
{
}
@@ -36,24 +35,21 @@ private:
nsresult ReadAt(int64_t aOffset, char* aBuffer,
uint32_t aCount, uint32_t* aBytes) override
{
if (aOffset < 0 || aOffset > mLength) {
return NS_ERROR_FAILURE;
}
*aBytes = std::min(mLength - static_cast<uint32_t>(aOffset), aCount);
memcpy(aBuffer, mBuffer + aOffset, *aBytes);
- mOffset = aOffset + *aBytes;
return NS_OK;
}
// Memory-based and no locks, caching discouraged.
bool ShouldCacheReads() override { return false; }
- int64_t Tell() override { return mOffset; }
-
void Pin() override {}
void Unpin() override {}
int64_t GetLength() override { return mLength; }
int64_t GetNextCachedData(int64_t aOffset) override { return aOffset; }
int64_t GetCachedDataEnd(int64_t aOffset) override
{
return std::max(aOffset, int64_t(mLength));
}
@@ -75,14 +71,13 @@ private:
{
aRanges += MediaByteRange(0, int64_t(mLength));
return NS_OK;
}
private:
const uint8_t * mBuffer;
uint32_t mLength;
- uint32_t mOffset;
};
} // namespace mozilla
#endif
--- a/dom/media/ChannelMediaResource.cpp
+++ b/dom/media/ChannelMediaResource.cpp
@@ -670,21 +670,16 @@ nsresult ChannelMediaResource::ReadAt(in
}
void
ChannelMediaResource::ThrottleReadahead(bool bThrottle)
{
mCacheStream.ThrottleReadahead(bThrottle);
}
-int64_t ChannelMediaResource::Tell()
-{
- return mCacheStream.Tell();
-}
-
nsresult ChannelMediaResource::GetCachedRanges(MediaByteRangeSet& aRanges)
{
return mCacheStream.GetCachedRanges(aRanges);
}
void
ChannelMediaResource::Suspend(bool aCloseImmediately)
{
--- a/dom/media/ChannelMediaResource.h
+++ b/dom/media/ChannelMediaResource.h
@@ -119,17 +119,16 @@ public:
// Other thread
void SetReadMode(MediaCacheStream::ReadMode aMode) override;
void SetPlaybackRate(uint32_t aBytesPerSecond) override;
nsresult ReadAt(int64_t offset, char* aBuffer,
uint32_t aCount, uint32_t* aBytes) override;
// Data stored in IO&lock-encumbered MediaCacheStream, caching recommended.
bool ShouldCacheReads() override { return true; }
- int64_t Tell() override;
// Any thread
void Pin() override;
void Unpin() override;
double GetDownloadRate(bool* aIsReliable) override;
int64_t GetLength() override;
int64_t GetNextCachedData(int64_t aOffset) override;
int64_t GetCachedDataEnd(int64_t aOffset) override;
--- a/dom/media/CloneableWithRangeMediaResource.cpp
+++ b/dom/media/CloneableWithRangeMediaResource.cpp
@@ -196,17 +196,16 @@ CloneableWithRangeMediaResource::ReadFro
}
uint32_t bytes = 0;
nsresult rv = reader->Read(aBuffer, aCount, &bytes);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
- mCurrentPosition = bytes + aOffset;
return bytes == aCount ? NS_OK : NS_ERROR_FAILURE;
}
nsresult
CloneableWithRangeMediaResource::ReadAt(int64_t aOffset, char* aBuffer,
uint32_t aCount, uint32_t* aBytes)
{
MOZ_ASSERT(!NS_IsMainThread());
@@ -217,19 +216,12 @@ CloneableWithRangeMediaResource::ReadAt(
return NS_ERROR_FAILURE;
}
nsresult rv = reader->Read(aBuffer, aCount, aBytes);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
- mCurrentPosition = *aBytes + aOffset;
return NS_OK;
}
-int64_t CloneableWithRangeMediaResource::Tell()
-{
- MaybeInitialize();
- return mCurrentPosition;
-}
-
} // mozilla namespace
--- a/dom/media/CloneableWithRangeMediaResource.h
+++ b/dom/media/CloneableWithRangeMediaResource.h
@@ -17,17 +17,16 @@ public:
CloneableWithRangeMediaResource(MediaResourceCallback* aCallback,
nsIChannel* aChannel,
nsIURI* aURI,
nsIInputStream* aStream,
uint64_t aSize)
: BaseMediaResource(aCallback, aChannel, aURI)
, mStream(do_QueryInterface(aStream))
, mSize(aSize)
- , mCurrentPosition(0)
, mInitialized(false)
{
MOZ_ASSERT(mStream);
}
~CloneableWithRangeMediaResource()
{
}
@@ -44,17 +43,16 @@ public:
// Other thread
void SetReadMode(MediaCacheStream::ReadMode aMode) override {}
void SetPlaybackRate(uint32_t aBytesPerSecond) override {}
nsresult ReadAt(int64_t aOffset, char* aBuffer,
uint32_t aCount, uint32_t* aBytes) override;
// (Probably) file-based, caching recommended.
bool ShouldCacheReads() override { return true; }
- int64_t Tell() override;
// Any thread
void Pin() override {}
void Unpin() override {}
double GetDownloadRate(bool* aIsReliable) override
{
// The data's all already here
@@ -100,17 +98,14 @@ private:
// Input stream for the media data. This can be used from any
// thread.
nsCOMPtr<nsICloneableInputStreamWithRange> mStream;
// The stream size.
uint64_t mSize;
- // The current position.
- uint64_t mCurrentPosition;
-
bool mInitialized;
};
} // namespace mozilla
#endif // mozilla_dom_media_CloneableWithRangeMediaResource_h
--- a/dom/media/FileMediaResource.cpp
+++ b/dom/media/FileMediaResource.cpp
@@ -207,22 +207,9 @@ FileMediaResource::UnsafeSeek(int32_t aW
NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
if (!mSeekable)
return NS_ERROR_FAILURE;
EnsureSizeInitialized();
return mSeekable->Seek(aWhence, aOffset);
}
-int64_t
-FileMediaResource::Tell()
-{
- MutexAutoLock lock(mLock);
- EnsureSizeInitialized();
-
- int64_t offset = 0;
- // Return mSize as offset (end of stream) in case of error
- if (!mSeekable || NS_FAILED(mSeekable->Tell(&offset)))
- return mSize;
- return offset;
-}
-
} // mozilla namespace
--- a/dom/media/FileMediaResource.h
+++ b/dom/media/FileMediaResource.h
@@ -40,17 +40,16 @@ public:
// Other thread
void SetReadMode(MediaCacheStream::ReadMode aMode) override {}
void SetPlaybackRate(uint32_t aBytesPerSecond) override {}
nsresult ReadAt(int64_t aOffset, char* aBuffer,
uint32_t aCount, uint32_t* aBytes) override;
// (Probably) file-based, caching recommended.
bool ShouldCacheReads() override { return true; }
- int64_t Tell() override;
// Any thread
void Pin() override {}
void Unpin() override {}
double GetDownloadRate(bool* aIsReliable) override
{
// The data's all already here
*aIsReliable = true;
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -2505,23 +2505,16 @@ MediaCacheStream::ReadBlockFromCache(int
if (aNoteBlockUsage) {
mMediaCache->NoteBlockUsage(
this, cacheBlock, aOffset, mCurrentMode, TimeStamp::Now());
}
return bytesRead;
}
-int64_t
-MediaCacheStream::Tell()
-{
- ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
- return mStreamOffset;
-}
-
nsresult
MediaCacheStream::Read(char* aBuffer, uint32_t aCount, uint32_t* aBytes)
{
NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
// Cache the offset in case it is changed again when we are waiting for the
--- a/dom/media/MediaCache.h
+++ b/dom/media/MediaCache.h
@@ -328,17 +328,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.
- 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.
nsresult ReadAt(int64_t aOffset, char* aBuffer,
--- a/dom/media/MediaResource.h
+++ b/dom/media/MediaResource.h
@@ -64,22 +64,16 @@ public:
virtual nsresult ReadAt(int64_t aOffset, char* aBuffer,
uint32_t aCount, uint32_t* aBytes) = 0;
// Indicate whether caching data in advance of reads is worth it.
// E.g. Caching lockless and memory-based MediaResource subclasses would be a
// waste, but caching lock/IO-bound resources means reducing the impact of
// each read.
virtual bool ShouldCacheReads() = 0;
- // Report the current offset in bytes from the start of the stream.
- // This is used to approximate where we currently are in the playback of a
- // media.
- // A call to ReadAt will update this position.
- virtual int64_t Tell() = 0;
-
// These can be called on any thread.
// Cached blocks associated with this stream will not be evicted
// while the stream is pinned.
virtual void Pin() = 0;
virtual void Unpin() = 0;
// Get the length of the stream in bytes. Returns -1 if not known.
// This can change over time; after a seek operation, a misbehaving
// server may give us a resource of a different length to what it had
--- a/dom/media/gtest/MockMediaResource.h
+++ b/dom/media/gtest/MockMediaResource.h
@@ -15,17 +15,16 @@ namespace mozilla
class MockMediaResource : public MediaResource
{
public:
explicit MockMediaResource(const char* aFileName);
nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount,
uint32_t* aBytes) override;
// Data stored in file, caching recommended.
bool ShouldCacheReads() override { return true; }
- int64_t Tell() override { return 0; }
void Pin() override {}
void Unpin() override {}
int64_t GetLength() override;
int64_t GetNextCachedData(int64_t aOffset) override;
int64_t GetCachedDataEnd(int64_t aOffset) override;
bool IsDataCachedToEndOfResource(int64_t aOffset) override
{
return false;
--- a/dom/media/mediasource/SourceBufferResource.cpp
+++ b/dom/media/mediasource/SourceBufferResource.cpp
@@ -62,20 +62,16 @@ SourceBufferResource::ReadAtInternal(int
uint64_t(aOffset) < mInputBuffer.GetOffset() ||
aOffset > GetLength()) {
return NS_ERROR_FAILURE;
}
uint32_t available = GetLength() - aOffset;
uint32_t count = std::min(aCount, available);
- // Keep the position of the last read to have Tell() approximately give us
- // the position we're up to in the stream.
- mOffset = aOffset + count;
-
SBR_DEBUGV("offset=%" PRId64 " GetLength()=%" PRId64
" available=%u count=%u mEnded=%d",
aOffset,
GetLength(),
available,
count,
mEnded);
if (available == 0) {
@@ -155,22 +151,17 @@ SourceBufferResource::Ended()
SourceBufferResource::~SourceBufferResource()
{
SBR_DEBUG("");
}
SourceBufferResource::SourceBufferResource()
#if defined(DEBUG)
: mTaskQueue(AbstractThread::GetCurrent()->AsTaskQueue())
- , mOffset(0)
-#else
- : mOffset(0)
#endif
- , mClosed(false)
- , mEnded(false)
{
SBR_DEBUG("");
}
#if defined(DEBUG)
AbstractThread*
SourceBufferResource::GetTaskQueue() const
{
--- a/dom/media/mediasource/SourceBufferResource.h
+++ b/dom/media/mediasource/SourceBufferResource.h
@@ -32,17 +32,16 @@ public:
SourceBufferResource();
nsresult Close();
nsresult ReadAt(int64_t aOffset,
char* aBuffer,
uint32_t aCount,
uint32_t* aBytes) override;
// Memory-based and no locks, caching discouraged.
bool ShouldCacheReads() override { return false; }
- int64_t Tell() override { return mOffset; }
void Pin() override { UNIMPLEMENTED(); }
void Unpin() override { UNIMPLEMENTED(); }
int64_t GetLength() override { return mInputBuffer.GetLength(); }
int64_t GetNextCachedData(int64_t aOffset) override
{
MOZ_ASSERT(OnTaskQueue());
MOZ_ASSERT(aOffset >= 0);
if (uint64_t(aOffset) < mInputBuffer.GetOffset()) {
@@ -134,18 +133,17 @@ private:
// TaskQueue methods and objects.
AbstractThread* GetTaskQueue() const;
bool OnTaskQueue() const;
#endif
// The buffer holding resource data.
ResourceQueue mInputBuffer;
- uint64_t mOffset;
- bool mClosed;
- bool mEnded;
+ bool mClosed = false;
+ bool mEnded = false;
};
} // namespace mozilla
#undef UNIMPLEMENTED
#endif /* MOZILLA_SOURCEBUFFERRESOURCE_H_ */