Bug 1342822 - Backed out changeset a379d64f8496 (Bug 1338924 patch 3). r=gerald
authorChris Pearce <cpearce@mozilla.com>
Mon, 27 Feb 2017 13:57:39 +1300
changeset 374146 a6cfc821a0731ce1b865826db62d73c090998db5
parent 374145 1aecc3e0302853e1bdcffc924d50ecdff8e26101
child 374147 af9dd74bba62799c680d3a2f3d2bd2b7379bab62
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1342822, 1338924
milestone54.0a1
Bug 1342822 - Backed out changeset a379d64f8496 (Bug 1338924 patch 3). r=gerald MozReview-Commit-ID: 4aFx52mwpQ6
dom/media/gmp/widevine-adapter/WidevineDecryptor.cpp
dom/media/gmp/widevine-adapter/WidevineDecryptor.h
--- a/dom/media/gmp/widevine-adapter/WidevineDecryptor.cpp
+++ b/dom/media/gmp/widevine-adapter/WidevineDecryptor.cpp
@@ -3,19 +3,17 @@
  * 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 "WidevineDecryptor.h"
 
 #include "WidevineAdapter.h"
 #include "WidevineUtils.h"
 #include "WidevineFileIO.h"
-#include "GMPPlatform.h"
 #include <stdarg.h>
-#include "TimeUnits.h"
 
 using namespace cdm;
 using namespace std;
 
 namespace mozilla {
 
 static map<uint32_t, RefPtr<CDMWrapper>> sDecryptors;
 
@@ -155,135 +153,47 @@ void
 WidevineDecryptor::SetServerCertificate(uint32_t aPromiseId,
                                         const uint8_t* aServerCert,
                                         uint32_t aServerCertSize)
 {
   CDM_LOG("Decryptor::SetServerCertificate()");
   CDM()->SetServerCertificate(aPromiseId, aServerCert, aServerCertSize);
 }
 
-cdm::Time
-WidevineDecryptor::ThrottleDecrypt(cdm::Time aWallTime, cdm::Time aSampleDuration)
-{
-  const cdm::Time WindowSize = 1.0;
-  const cdm::Time MaxThroughput = 2.0;
-
-  // Forget decrypts that happened before the start of our window.
-  while (!mDecrypts.empty() && mDecrypts.front().mWallTime < aWallTime - WindowSize) {
-    mDecrypts.pop_front();
-  }
-
-  // How much time duration of the media would we have decrypted inside the
-  // time window if we did decrypt this block?
-  cdm::Time durationDecrypted = aSampleDuration;
-  for (const DecryptJob& job : mDecrypts) {
-    durationDecrypted += job.mSampleDuration;
-  }
-
-  if (durationDecrypted > MaxThroughput) {
-    // If we decrypted a sample of this duration, we would have decrypted more than
-    // our threshold for max throughput, over the preceding wall time window.
-    return durationDecrypted - MaxThroughput;
-  }
-
-  return 0.0;
-}
-
 void
 WidevineDecryptor::Decrypt(GMPBuffer* aBuffer,
                            GMPEncryptedBufferMetadata* aMetadata,
                            uint64_t aDurationUsecs)
 {
   if (!mCallback) {
     CDM_LOG("WidevineDecryptor::Decrypt() this=%p FAIL; !mCallback", this);
     return;
   }
-
-  cdm::Time duration = double(aDurationUsecs) / USECS_PER_S;
-  mPendingDecrypts.push({aBuffer, aMetadata, duration});
-  ProcessDecrypts();
-}
-
-void
-WidevineDecryptor::ProcessDecryptsFromTimer()
-{
-  MOZ_ASSERT(mPendingDecryptTimerSet);
-  mPendingDecryptTimerSet = false;
-  ProcessDecrypts();
-}
-
-void
-WidevineDecryptor::ProcessDecrypts()
-{
-  while (!mPendingDecrypts.empty()) {
-    PendingDecrypt job = mPendingDecrypts.front();
-
-    // We throttle our decrypt so that we don't decrypt more than a certain
-    // duration of samples per second. This is to work around bugs in the
-    // Widevine CDM. See bug 1338924.
-    cdm::Time now = GetCurrentWallTime();
-    cdm::Time delay = ThrottleDecrypt(now, job.mSampleDuration);
-
-    if (delay > 0.0) {
-      // If we decrypted this sample now, we'd decrypt more than our threshold
-      // per second of samples. Enqueue the sample, and wait until we'd be able
-      // to decrypt it without breaking our throughput threshold.
-      if (!mPendingDecryptTimerSet) {
-        mPendingDecryptTimerSet = true;
-        RefPtr<WidevineDecryptor> self = this;
-        GMPTask* task = gmp::NewGMPTask(
-          [self]() {
-            self->ProcessDecryptsFromTimer();
-          });
-        gmp::SetTimerOnMainThread(task, delay * 1000);
-      }
-      return;
-    }
-    DecryptBuffer(job);
-    mDecrypts.push_back(DecryptJob(now, job.mSampleDuration));
-    mPendingDecrypts.pop();
-  }
-}
-
-void
-WidevineDecryptor::DecryptBuffer(const PendingDecrypt& aJob)
-{
-  GMPBuffer* buffer = aJob.mBuffer;
-  const GMPEncryptedBufferMetadata* crypto = aJob.mMetadata;
+  const GMPEncryptedBufferMetadata* crypto = aMetadata;
   InputBuffer sample;
   nsTArray<SubsampleEntry> subsamples;
-  InitInputBuffer(crypto, buffer->Id(), buffer->Data(), buffer->Size(), sample, subsamples);
+  InitInputBuffer(crypto, aBuffer->Id(), aBuffer->Data(), aBuffer->Size(), sample, subsamples);
   WidevineDecryptedBlock decrypted;
   Status rv = CDM()->Decrypt(sample, &decrypted);
   CDM_LOG("Decryptor::Decrypt(timestamp=%" PRId64 ") rv=%d sz=%d",
           sample.timestamp, rv, decrypted.DecryptedBuffer()->Size());
   if (rv == kSuccess) {
-    buffer->Resize(decrypted.DecryptedBuffer()->Size());
-    memcpy(buffer->Data(),
+    aBuffer->Resize(decrypted.DecryptedBuffer()->Size());
+    memcpy(aBuffer->Data(),
            decrypted.DecryptedBuffer()->Data(),
            decrypted.DecryptedBuffer()->Size());
   }
-  mCallback->Decrypted(buffer, ToGMPErr(rv));
+  mCallback->Decrypted(aBuffer, ToGMPErr(rv));
 }
 
 void
 WidevineDecryptor::DecryptingComplete()
 {
   CDM_LOG("WidevineDecryptor::DecryptingComplete() this=%p, instanceId=%u",
           this, mInstanceId);
-
-  // Ensure buffers are freed.
-  while (!mPendingDecrypts.empty()) {
-    PendingDecrypt& job = mPendingDecrypts.front();
-    if (mCallback) {
-      mCallback->Decrypted(job.mBuffer, GMPAbortedErr);
-    }
-    mPendingDecrypts.pop();
-  }
-
   // Drop our references to the CDMWrapper. When any other references
   // held elsewhere are dropped (for example references held by a
   // WidevineVideoDecoder, or a runnable), the CDMWrapper destroys
   // the CDM.
   mCDM = nullptr;
   sDecryptors.erase(mInstanceId);
   mCallback = nullptr;
   Release();
--- a/dom/media/gmp/widevine-adapter/WidevineDecryptor.h
+++ b/dom/media/gmp/widevine-adapter/WidevineDecryptor.h
@@ -7,18 +7,16 @@
 #define WidevineDecryptor_h_
 
 #include "stddef.h"
 #include "content_decryption_module.h"
 #include "gmp-api/gmp-decryption.h"
 #include "mozilla/RefPtr.h"
 #include "WidevineUtils.h"
 #include <map>
-#include <deque>
-#include <queue>
 
 namespace mozilla {
 
 class WidevineDecryptor : public GMPDecryptor
                         , public cdm::Host_8
 {
 public:
 
@@ -116,62 +114,22 @@ public:
   void QueryOutputProtectionStatus() override;
   void OnDeferredInitializationDone(cdm::StreamType aStreamType,
                                     cdm::Status aDecoderStatus) override;
   cdm::FileIO* CreateFileIO(cdm::FileIOClient* aClient) override;
 
   GMPDecryptorCallback* Callback() const { return mCallback; }
   RefPtr<CDMWrapper> GetCDMWrapper() const { return mCDM; }
 private:
-
-  struct PendingDecrypt
-  {
-    PendingDecrypt(GMPBuffer* aBuffer,
-      GMPEncryptedBufferMetadata* aMetadata,
-      cdm::Time aSampleDuration)
-      : mBuffer(aBuffer)
-      , mMetadata(aMetadata)
-      , mSampleDuration(aSampleDuration)
-    {
-    }
-    GMPBuffer* mBuffer;
-    GMPEncryptedBufferMetadata* mMetadata;
-    cdm::Time mSampleDuration;
-  };
-
-  // Queue of buffers waiting to be decrypted.
-  std::queue<PendingDecrypt> mPendingDecrypts;
-
-  void DecryptBuffer(const PendingDecrypt& aJob);
-  cdm::Time ThrottleDecrypt(cdm::Time aWallClock, cdm::Time aSampleDuration);
-  void ProcessDecrypts();
-  void ProcessDecryptsFromTimer();
-
-  struct DecryptJob
-  {
-    DecryptJob(cdm::Time aWallTime, cdm::Time aSampleDuration)
-      : mWallTime(aWallTime)
-      , mSampleDuration(aSampleDuration)
-    {}
-    cdm::Time mWallTime;
-    cdm::Time mSampleDuration;
-  };
-
-  // Queue of durations of buffers that have been decrypted, along with the
-  // wall-clock timestamp when they were decrypted. This enables us to
-  // throttle the throughput against the wall-clock.
-  std::deque<DecryptJob> mDecrypts;
-
   ~WidevineDecryptor();
   RefPtr<CDMWrapper> mCDM;
   cdm::ContentDecryptionModule_8* CDM() { return mCDM->GetCDM(); }
 
   GMPDecryptorCallback* mCallback;
   std::map<uint32_t, uint32_t> mPromiseIdToNewSessionTokens;
   bool mDistinctiveIdentifierRequired = false;
   bool mPersistentStateRequired = false;
   uint32_t mInstanceId = 0;
-  bool mPendingDecryptTimerSet = false;
 };
 
 } // namespace mozilla
 
 #endif // WidevineDecryptor_h_