зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1385155. P1 - remove dead code. r=gerald
We are able to remove some dead code for BlockingReadIntoCache, LastReadFailed, ClearFailedRead, Pin and Unpin have no callers at all. MozReview-Commit-ID: KkywoKznejB --HG-- extra : rebase_source : c6124bce6eca0b974767073fe1daf51aa50635f2
This commit is contained in:
Родитель
b9cda6f285
Коммит
80b7228709
|
@ -5,13 +5,11 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "MP4Stream.h"
|
||||
#include "MediaResource.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
MP4Stream::MP4Stream(MediaResource* aResource)
|
||||
: mResource(aResource)
|
||||
, mPinCount(0)
|
||||
{
|
||||
MOZ_COUNT_CTOR(MP4Stream);
|
||||
MOZ_ASSERT(aResource);
|
||||
|
@ -20,66 +18,19 @@ MP4Stream::MP4Stream(MediaResource* aResource)
|
|||
MP4Stream::~MP4Stream()
|
||||
{
|
||||
MOZ_COUNT_DTOR(MP4Stream);
|
||||
MOZ_ASSERT(mPinCount == 0);
|
||||
}
|
||||
|
||||
bool
|
||||
MP4Stream::BlockingReadIntoCache(int64_t aOffset, size_t aCount, Monitor* aToUnlock)
|
||||
{
|
||||
MOZ_ASSERT(mPinCount > 0);
|
||||
CacheBlock block(aOffset, aCount);
|
||||
if (!block.Init()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t bytesRead = 0;
|
||||
{
|
||||
MonitorAutoUnlock unlock(*aToUnlock);
|
||||
nsresult rv = mResource.ReadAt(aOffset, block.Buffer(), aCount, &bytesRead);
|
||||
if (NS_FAILED(rv)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
MOZ_ASSERT(block.mCount >= bytesRead);
|
||||
block.mCount = bytesRead;
|
||||
|
||||
mCache.AppendElement(Move(block));
|
||||
return true;
|
||||
}
|
||||
|
||||
// We surreptitiously reimplement the supposedly-blocking ReadAt as a non-
|
||||
// blocking CachedReadAt, and record when it fails. This allows MP4Reader
|
||||
// to retry the read as an actual blocking read without holding the lock.
|
||||
bool
|
||||
MP4Stream::ReadAt(int64_t aOffset, void* aBuffer, size_t aCount,
|
||||
size_t* aBytesRead)
|
||||
{
|
||||
if (mFailedRead.isSome()) {
|
||||
mFailedRead.reset();
|
||||
}
|
||||
|
||||
if (!CachedReadAt(aOffset, aBuffer, aCount, aBytesRead)) {
|
||||
mFailedRead.emplace(aOffset, aCount);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return CachedReadAt(aOffset, aBuffer, aCount, aBytesRead);
|
||||
}
|
||||
|
||||
bool
|
||||
MP4Stream::CachedReadAt(int64_t aOffset, void* aBuffer, size_t aCount,
|
||||
size_t* aBytesRead)
|
||||
{
|
||||
// First, check our local cache.
|
||||
for (size_t i = 0; i < mCache.Length(); ++i) {
|
||||
if (mCache[i].mOffset == aOffset && mCache[i].mCount >= aCount) {
|
||||
memcpy(aBuffer, mCache[i].Buffer(), aCount);
|
||||
*aBytesRead = aCount;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult rv =
|
||||
mResource.GetResource()->ReadFromCache(reinterpret_cast<char*>(aBuffer),
|
||||
aOffset, aCount);
|
||||
|
|
|
@ -11,95 +11,20 @@
|
|||
|
||||
#include "MediaResource.h"
|
||||
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Monitor.h"
|
||||
#include "mozilla/UniquePtrExtensions.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class Monitor;
|
||||
|
||||
class MP4Stream : public mp4_demuxer::Stream {
|
||||
public:
|
||||
explicit MP4Stream(MediaResource* aResource);
|
||||
virtual ~MP4Stream();
|
||||
bool BlockingReadIntoCache(int64_t aOffset, size_t aCount, Monitor* aToUnlock);
|
||||
bool ReadAt(int64_t aOffset, void* aBuffer, size_t aCount,
|
||||
size_t* aBytesRead) override;
|
||||
bool CachedReadAt(int64_t aOffset, void* aBuffer, size_t aCount,
|
||||
size_t* aBytesRead) override;
|
||||
bool Length(int64_t* aSize) override;
|
||||
|
||||
struct ReadRecord {
|
||||
ReadRecord(int64_t aOffset, size_t aCount) : mOffset(aOffset), mCount(aCount) {}
|
||||
bool operator==(const ReadRecord& aOther) { return mOffset == aOther.mOffset && mCount == aOther.mCount; }
|
||||
int64_t mOffset;
|
||||
size_t mCount;
|
||||
};
|
||||
bool LastReadFailed(ReadRecord* aOut)
|
||||
{
|
||||
if (mFailedRead.isSome()) {
|
||||
*aOut = mFailedRead.ref();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ClearFailedRead() { mFailedRead.reset(); }
|
||||
|
||||
void Pin()
|
||||
{
|
||||
mResource.GetResource()->Pin();
|
||||
++mPinCount;
|
||||
}
|
||||
|
||||
void Unpin()
|
||||
{
|
||||
mResource.GetResource()->Unpin();
|
||||
MOZ_ASSERT(mPinCount);
|
||||
--mPinCount;
|
||||
if (mPinCount == 0) {
|
||||
mCache.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
MediaResourceIndex mResource;
|
||||
Maybe<ReadRecord> mFailedRead;
|
||||
uint32_t mPinCount;
|
||||
|
||||
struct CacheBlock {
|
||||
CacheBlock(int64_t aOffset, size_t aCount)
|
||||
: mOffset(aOffset), mCount(aCount), mBuffer(nullptr) {}
|
||||
int64_t mOffset;
|
||||
size_t mCount;
|
||||
|
||||
CacheBlock(CacheBlock&& aOther)
|
||||
: mOffset(aOther.mOffset)
|
||||
, mCount(aOther.mCount)
|
||||
, mBuffer(Move(aOther.mBuffer))
|
||||
{}
|
||||
|
||||
bool Init()
|
||||
{
|
||||
mBuffer = MakeUniqueFallible<char[]>(mCount);
|
||||
return !!mBuffer;
|
||||
}
|
||||
|
||||
char* Buffer()
|
||||
{
|
||||
MOZ_ASSERT(mBuffer.get());
|
||||
return mBuffer.get();
|
||||
}
|
||||
|
||||
private:
|
||||
CacheBlock(const CacheBlock&) = delete;
|
||||
CacheBlock& operator=(const CacheBlock&) = delete;
|
||||
|
||||
UniquePtr<char[]> mBuffer;
|
||||
};
|
||||
nsTArray<CacheBlock> mCache;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
Загрузка…
Ссылка в новой задаче