Bug 1368837 - Replace debugging ReadAt with CachedReadAt code - r=cpearce
MozReview-Commit-ID: 88j9oAPdI0w
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -1652,89 +1652,16 @@ ResultName(nsresult aResult)
}
nsresult
MediaResourceIndex::ReadAt(int64_t aOffset,
char* aBuffer,
uint32_t aCount,
uint32_t* aBytes)
{
- const int oOffset = int(aOffset);
- const unsigned oCount = unsigned(aCount);
- nsresult rvu = UncachedReadAt(aOffset, aBuffer, aCount, aBytes);
- printf("**** [%p]CompareReadAt(%u@%d) UncachedReadAt -> %s, %u\n",
- this,
- oCount,
- oOffset,
- ResultName(rvu).get(),
- *aBytes);
-
- printf("**** [%p]CompareReadAt(%u@%d) CachedReadAt: ----------------\n",
- this,
- oCount,
- oOffset);
- char* buf = new char[aCount];
- uint32_t bytes = 0;
- nsresult rvc = CachedReadAt(aOffset, buf, aCount, &bytes);
-
- printf("**** [%p]CompareReadAt(%u@%d) ---------------- Comparing...\n",
- this,
- oCount,
- oOffset);
-
- if (rvu != rvc) {
- printf("*** read(aOffset=%d, aCount=%u) - rvu=%s != rvc=%s\n",
- int(aOffset),
- unsigned(aCount),
- ResultName(rvu).get(),
- ResultName(rvc).get());
- MOZ_ASSERT(rvu == rvc || rvc == NS_OK);
- if (rvc == NS_OK) {
- // Cached read wins!
- *aBytes = bytes;
- memcpy(aBuffer, buf, bytes);
- }
- } else if (NS_SUCCEEDED(rvu)) {
- if (*aBytes != bytes) {
- printf("*** read(aOffset=%d, aCount=%u) - bu=%u != bc=%u\n",
- int(aOffset),
- unsigned(aCount),
- unsigned(*aBytes),
- unsigned(bytes));
- MOZ_ASSERT(*aBytes == bytes);
- } else {
- for (uint32_t i = 0; i < bytes; ++i) {
- uint8_t bu = uint8_t(aBuffer[i]);
- uint8_t bc = uint8_t(buf[i]);
- if (bu != bc) {
- printf("*** read(aOffset=%d, aCount=%u) - u[%u]=%u != c[%u]=%u\n",
- int(aOffset),
- unsigned(aCount),
- unsigned(i),
- unsigned(bu),
- unsigned(i),
- unsigned(bc));
- MOZ_ASSERT(bu == bc);
- break;
- }
- }
- }
- }
-
- delete[] buf;
-
- return rvc;
-}
-
-nsresult
-MediaResourceIndex::CachedReadAt(int64_t aOffset,
- char* aBuffer,
- uint32_t aCount,
- uint32_t* aBytes)
-{
if (mCacheBlockSize == 0) {
return UncachedReadAt(aOffset, aBuffer, aCount, aBytes);
}
const int oOffset = int(aOffset);
const unsigned oCount = unsigned(aCount);
*aBytes = 0;
--- a/dom/media/MediaResource.h
+++ b/dom/media/MediaResource.h
@@ -809,28 +809,26 @@ public:
MediaResource* GetResource() const { return mResource; }
// Read up to aCount bytes from the stream. The read starts at
// aOffset in the stream, seeking to that location initially if
// it is not the current stream offset.
// Unlike MediaResource::ReadAt, ReadAt only returns fewer bytes than
// requested if end of stream or an error is encountered. There is no need to
// call it again to get more data.
+ // If the resource has cached data past the end of the request, it will be
+ // used to fill a local cache, which should speed up consecutive ReadAt's
+ // (mostly by avoiding using the resource's IOs and locks.)
// *aBytes will contain the number of bytes copied, even if an error occurred.
// ReadAt doesn't have an impact on the offset returned by Tell().
nsresult ReadAt(int64_t aOffset,
char* aBuffer,
uint32_t aCount,
uint32_t* aBytes);
- nsresult CachedReadAt(int64_t aOffset,
- char* aBuffer,
- uint32_t aCount,
- uint32_t* aBytes);
-
// Same as ReadAt, but doesn't try to cache around the read.
// Useful if you know that you will not read again from the same area.
nsresult UncachedReadAt(int64_t aOffset,
char* aBuffer,
uint32_t aCount,
uint32_t* aBytes) const;
// Convenience methods, directly calling the MediaResource method of the same