Bug 1412737. P1 - improve error handling.
MozReview-Commit-ID: 776P80x63y8
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -2512,30 +2512,34 @@ MediaCacheStream::Tell()
}
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());
- if (mClosed)
- return NS_ERROR_FAILURE;
// Cache the offset in case it is changed again when we are waiting for the
// monitor to be notified to avoid reading at the wrong position.
auto streamOffset = mStreamOffset;
uint32_t count = 0;
// Read one block (or part of a block) at a time
while (count < aCount) {
+ if (mClosed) {
+ return NS_ERROR_ABORT;
+ }
+
int32_t streamBlock = OffsetToBlockIndex(streamOffset);
if (streamBlock < 0) {
- break;
+ LOGE("Stream %p invalid offset=%" PRId64, this, streamOffset);
+ return NS_ERROR_ILLEGAL_VALUE;
}
+
uint32_t offsetInStreamBlock = uint32_t(streamOffset - streamBlock*BLOCK_SIZE);
int64_t size = std::min<int64_t>(aCount - count, BLOCK_SIZE - offsetInStreamBlock);
if (mStreamLength >= 0) {
// Don't try to read beyond the end of the stream
int64_t bytesRemaining = mStreamLength - streamOffset;
if (bytesRemaining <= 0) {
// Get out of here and return NS_OK
@@ -2593,37 +2597,32 @@ MediaCacheStream::Read(char* aBuffer, ui
// Updat mStreamOffset before we drop the lock. We need to run
// Update() again since stream reading strategy might have changed.
mStreamOffset = streamOffset;
mMediaCache->QueueUpdate();
}
// No data has been read yet, so block
mon.Wait();
- if (mClosed) {
- // We may have successfully read some data, but let's just throw
- // that out.
- return NS_ERROR_FAILURE;
- }
continue;
}
mMediaCache->NoteBlockUsage(
this, cacheBlock, streamOffset, mCurrentMode, TimeStamp::Now());
int64_t offset = cacheBlock*BLOCK_SIZE + offsetInStreamBlock;
int32_t bytes;
MOZ_ASSERT(size >= 0 && size <= INT32_MAX, "Size out of range.");
nsresult rv = mMediaCache->ReadCacheFile(
offset, aBuffer + count, int32_t(size), &bytes);
if (NS_FAILED(rv)) {
- if (count == 0)
- return rv;
- // If we did successfully read some data, may as well return it
- break;
+ nsCString name;
+ GetErrorName(rv, name);
+ LOGE("Stream %p ReadCacheFile failed, rv=%s", this, name.Data());
+ return rv;
}
streamOffset += bytes;
count += bytes;
}
if (count > 0) {
// Some data was read, so queue an update since block priorities may
// have changed