Bug 1385155. P1 - remove dead code. r=gerald
authorJW Wang <jwwang@mozilla.com>
Thu, 27 Jul 2017 17:36:18 +0800
changeset 420247 343e5952d6fe4480dfecdd6ab1758d6e5a025283
parent 420246 a9cb889906077ef445d3ef14dd0978f33228cc0b
child 420248 78d726cefb1275075bae8a9a7c5e67d8d360e6fc
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1385155
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
dom/media/fmp4/MP4Stream.cpp
dom/media/fmp4/MP4Stream.h
--- a/dom/media/fmp4/MP4Stream.cpp
+++ b/dom/media/fmp4/MP4Stream.cpp
@@ -1,90 +1,41 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * 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);
 }
 
 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);
   if (NS_FAILED(rv)) {
     *aBytesRead = 0;
     return false;
   }
   *aBytesRead = aCount;
--- a/dom/media/fmp4/MP4Stream.h
+++ b/dom/media/fmp4/MP4Stream.h
@@ -6,102 +6,27 @@
 
 #ifndef MP4_STREAM_H_
 #define MP4_STREAM_H_
 
 #include "mp4_demuxer/Stream.h"
 
 #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
 
 #endif