Bug 1184429: P2. MediaResource::SilentReadAt to read from cache first. r=jwwang

In practice, it will always read from the cache. This allows SilentReadAt to really be silent and prevent unecessary NotifyDataArrived callbacks.
This commit is contained in:
Jean-Yves Avenard 2015-07-17 15:46:44 +10:00
Родитель ac32d3c055
Коммит ba9653671f
2 изменённых файлов: 12 добавлений и 1 удалений

Просмотреть файл

@ -409,6 +409,8 @@ private:
// MediaByteBuffer is a ref counted infallible TArray.
class MediaByteBuffer : public nsTArray<uint8_t> {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaByteBuffer);
MediaByteBuffer() = default;
explicit MediaByteBuffer(size_t aCapacity) : nsTArray<uint8_t>(aCapacity) {}
private:
~MediaByteBuffer() {}

Просмотреть файл

@ -324,8 +324,17 @@ public:
// aCount bytes. Otherwise, it returns an owned buffer.
virtual already_AddRefed<MediaByteBuffer> SilentReadAt(int64_t aOffset, uint32_t aCount)
{
nsRefPtr<MediaByteBuffer> bytes = new MediaByteBuffer(aCount);
bytes->SetLength(aCount);
nsresult rv =
ReadFromCache(reinterpret_cast<char*>(bytes->Elements()), aOffset, aCount);
if (NS_SUCCEEDED(rv)) {
return bytes.forget();
}
int64_t pos = Tell();
nsRefPtr<MediaByteBuffer> bytes = MediaReadAt(aOffset, aCount);
// Free our buffer first to minimize memory usage.
bytes = nullptr;
bytes = MediaReadAt(aOffset, aCount);
Seek(nsISeekableStream::NS_SEEK_SET, pos);
NS_ENSURE_TRUE(bytes && bytes->Length() == aCount, nullptr);
return bytes.forget();