Bug 1284192 - get rid of GMPErr from CDMProxy base class. r=cpearce
authorJames Cheng <jacheng@mozilla.com>
Mon, 18 Jul 2016 22:12:00 +0200
changeset 345750 340f2259b820df20fe88a489763c9f82eb4918b0
parent 345749 813a61c61c6ce325f60801b2c6cc377e1801fd59
child 345751 81cb60fb8fbd8ef529f2a2c21852888b5fdab88b
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1284192
milestone50.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 1284192 - get rid of GMPErr from CDMProxy base class. r=cpearce MozReview-Commit-ID: 43WduOtIfZH
dom/media/eme/CDMProxy.h
dom/media/gmp/GMPCDMCallbackProxy.cpp
dom/media/gmp/GMPCDMProxy.cpp
dom/media/gmp/GMPCDMProxy.h
dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp
--- a/dom/media/eme/CDMProxy.h
+++ b/dom/media/eme/CDMProxy.h
@@ -13,22 +13,29 @@
 #include "mozilla/dom/MediaKeyMessageEvent.h"
 #include "mozilla/dom/MediaKeys.h"
 
 #include "nsIThread.h"
 
 namespace mozilla {
 class MediaRawData;
 
+enum DecryptStatus {
+  Ok = 0,
+  GenericErr = 1,
+  NoKeyErr = 2,
+  AbortedErr = 3,
+};
+
 struct DecryptResult {
-  DecryptResult(GMPErr aStatus, MediaRawData* aSample)
+  DecryptResult(DecryptStatus aStatus, MediaRawData* aSample)
     : mStatus(aStatus)
     , mSample(aSample)
   {}
-  GMPErr mStatus;
+  DecryptStatus mStatus;
   RefPtr<MediaRawData> mSample;
 };
 
 // Proxies calls CDM, and proxies calls back.
 // Note: Promises are passed in via a PromiseId, so that the ID can be
 // passed via IPC to the CDM, which can then signal when to reject or
 // resolve the promise using its PromiseId.
 class CDMProxy {
@@ -144,17 +151,17 @@ public:
   virtual void OnRejectPromise(uint32_t aPromiseId,
                                nsresult aDOMException,
                                const nsCString& aMsg) = 0;
 
   virtual RefPtr<DecryptPromise> Decrypt(MediaRawData* aSample) = 0;
 
   // Owner thread only.
   virtual void OnDecrypted(uint32_t aId,
-                           GMPErr aResult,
+                           DecryptStatus aResult,
                            const nsTArray<uint8_t>& aDecryptedData) = 0;
 
   // Reject promise with DOMException corresponding to aExceptionCode.
   // Can be called from any thread.
   virtual void RejectPromise(PromiseId aId,
                              nsresult aExceptionCode,
                              const nsCString& aReason) = 0;
 
--- a/dom/media/gmp/GMPCDMCallbackProxy.cpp
+++ b/dom/media/gmp/GMPCDMCallbackProxy.cpp
@@ -309,24 +309,35 @@ GMPCDMCallbackProxy::KeyStatusChanged(co
     nsCOMPtr<nsIRunnable> task;
     task = NewRunnableMethod<nsString>(mProxy,
                                        &CDMProxy::OnKeyStatusesChange,
                                        NS_ConvertUTF8toUTF16(aSessionId));
     NS_DispatchToMainThread(task);
   }
 }
 
+DecryptStatus
+ToDecryptStatus(GMPErr aError)
+{
+  switch (aError) {
+    case GMPNoErr: return Ok;
+    case GMPNoKeyErr: return NoKeyErr;
+    case GMPAbortedErr: return AbortedErr;
+    default: return GenericErr;
+  }
+}
+
 void
 GMPCDMCallbackProxy::Decrypted(uint32_t aId,
                                GMPErr aResult,
                                const nsTArray<uint8_t>& aDecryptedData)
 {
   MOZ_ASSERT(mProxy->IsOnOwnerThread());
 
-  mProxy->OnDecrypted(aId, aResult, aDecryptedData);
+  mProxy->OnDecrypted(aId, ToDecryptStatus(aResult), aDecryptedData);
 }
 
 void
 GMPCDMCallbackProxy::Terminated()
 {
   MOZ_ASSERT(mProxy->IsOnOwnerThread());
   nsCOMPtr<nsIRunnable> task = NewRunnableMethod(mProxy, &CDMProxy::Terminated);
   NS_DispatchToMainThread(task);
--- a/dom/media/gmp/GMPCDMProxy.cpp
+++ b/dom/media/gmp/GMPCDMProxy.cpp
@@ -466,17 +466,17 @@ GMPCDMProxy::gmp_Shutdown()
 {
   MOZ_ASSERT(IsOnOwnerThread());
 
   mShutdownCalled = true;
 
   // Abort any pending decrypt jobs, to awaken any clients waiting on a job.
   for (size_t i = 0; i < mDecryptionJobs.Length(); i++) {
     DecryptJob* job = mDecryptionJobs[i];
-    job->PostResult(GMPAbortedErr);
+    job->PostResult(AbortedErr);
   }
   mDecryptionJobs.Clear();
 
   if (mCDM) {
     mCDM->Close();
     mCDM = nullptr;
   }
 }
@@ -597,17 +597,17 @@ GMPCDMProxy::OnSessionClosed(const nsASt
   RefPtr<dom::MediaKeySession> session(mKeys->GetSession(aSessionId));
   if (session) {
     session->OnClosed();
   }
 }
 
 void
 GMPCDMProxy::OnDecrypted(uint32_t aId,
-                         GMPErr aResult,
+                         DecryptStatus aResult,
                          const nsTArray<uint8_t>& aDecryptedData)
 {
   MOZ_ASSERT(IsOnOwnerThread());
   gmp_Decrypted(aId, aResult, aDecryptedData);
 }
 
 static void
 LogToConsole(const nsAString& aMsg)
@@ -672,30 +672,30 @@ GMPCDMProxy::Decrypt(MediaRawData* aSamp
 }
 
 void
 GMPCDMProxy::gmp_Decrypt(RefPtr<DecryptJob> aJob)
 {
   MOZ_ASSERT(IsOnOwnerThread());
 
   if (!mCDM) {
-    aJob->PostResult(GMPAbortedErr);
+    aJob->PostResult(AbortedErr);
     return;
   }
 
   aJob->mId = ++mDecryptionJobCount;
   nsTArray<uint8_t> data;
   data.AppendElements(aJob->mSample->Data(), aJob->mSample->Size());
   mCDM->Decrypt(aJob->mId, aJob->mSample->mCrypto, data);
   mDecryptionJobs.AppendElement(aJob.forget());
 }
 
 void
 GMPCDMProxy::gmp_Decrypted(uint32_t aId,
-                           GMPErr aResult,
+                           DecryptStatus aResult,
                            const nsTArray<uint8_t>& aDecryptedData)
 {
   MOZ_ASSERT(IsOnOwnerThread());
 #ifdef DEBUG
   bool jobIdFound = false;
 #endif
   for (size_t i = 0; i < mDecryptionJobs.Length(); i++) {
     DecryptJob* job = mDecryptionJobs[i];
@@ -710,40 +710,40 @@ GMPCDMProxy::gmp_Decrypted(uint32_t aId,
 #ifdef DEBUG
   if (!jobIdFound) {
     NS_WARNING("GMPDecryptorChild returned incorrect job ID");
   }
 #endif
 }
 
 void
-GMPCDMProxy::DecryptJob::PostResult(GMPErr aResult)
+GMPCDMProxy::DecryptJob::PostResult(DecryptStatus aResult)
 {
   nsTArray<uint8_t> empty;
   PostResult(aResult, empty);
 }
 
 void
-GMPCDMProxy::DecryptJob::PostResult(GMPErr aResult,
+GMPCDMProxy::DecryptJob::PostResult(DecryptStatus aResult,
                                     const nsTArray<uint8_t>& aDecryptedData)
 {
   if (aDecryptedData.Length() != mSample->Size()) {
     NS_WARNING("CDM returned incorrect number of decrypted bytes");
   }
-  if (GMP_SUCCEEDED(aResult)) {
+  if (aResult == Ok) {
     nsAutoPtr<MediaRawDataWriter> writer(mSample->CreateWriter());
     PodCopy(writer->Data(),
             aDecryptedData.Elements(),
             std::min<size_t>(aDecryptedData.Length(), mSample->Size()));
-  } else if (aResult == GMPNoKeyErr) {
-    NS_WARNING("CDM returned GMPNoKeyErr");
+  } else if (aResult == NoKeyErr) {
+    NS_WARNING("CDM returned NoKeyErr");
     // We still have the encrypted sample, so we can re-enqueue it to be
     // decrypted again once the key is usable again.
   } else {
-    nsAutoCString str("CDM returned decode failure GMPErr=");
+    nsAutoCString str("CDM returned decode failure DecryptStatus=");
     str.AppendInt(aResult);
     NS_WARNING(str.get());
   }
   mPromise.Resolve(DecryptResult(aResult, mSample), __func__);
 }
 
 void
 GMPCDMProxy::GetSessionIdsForKeyId(const nsTArray<uint8_t>& aKeyId,
--- a/dom/media/gmp/GMPCDMProxy.h
+++ b/dom/media/gmp/GMPCDMProxy.h
@@ -81,17 +81,17 @@ public:
 
   void OnRejectPromise(uint32_t aPromiseId,
                        nsresult aDOMException,
                        const nsCString& aMsg) override;
 
   RefPtr<DecryptPromise> Decrypt(MediaRawData* aSample) override;
 
   void OnDecrypted(uint32_t aId,
-                   GMPErr aResult,
+                   DecryptStatus aResult,
                    const nsTArray<uint8_t>& aDecryptedData) override;
 
   void RejectPromise(PromiseId aId, nsresult aExceptionCode,
                      const nsCString& aReason) override;
 
   void ResolvePromise(PromiseId aId) override;
 
   const nsString& KeySystem() const override;
@@ -176,35 +176,36 @@ private:
     NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DecryptJob)
 
     explicit DecryptJob(MediaRawData* aSample)
       : mId(0)
       , mSample(aSample)
     {
     }
 
-    void PostResult(GMPErr aResult, const nsTArray<uint8_t>& aDecryptedData);
-    void PostResult(GMPErr aResult);
+    void PostResult(DecryptStatus aResult,
+                    const nsTArray<uint8_t>& aDecryptedData);
+    void PostResult(DecryptStatus aResult);
 
     RefPtr<DecryptPromise> Ensure() {
       return mPromise.Ensure(__func__);
     }
 
     uint32_t mId;
     RefPtr<MediaRawData> mSample;
   private:
     ~DecryptJob() {}
     MozPromiseHolder<DecryptPromise> mPromise;
   };
   // GMP thread only.
   void gmp_Decrypt(RefPtr<DecryptJob> aJob);
 
   // GMP thread only.
   void gmp_Decrypted(uint32_t aId,
-                     GMPErr aResult,
+                     DecryptStatus aResult,
                      const nsTArray<uint8_t>& aDecryptedData);
 
   class RejectPromiseTask : public Runnable {
   public:
     RejectPromiseTask(GMPCDMProxy* aProxy,
                       PromiseId aId,
                       nsresult aCode,
                       const nsCString& aReason)
--- a/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp
+++ b/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp
@@ -79,22 +79,22 @@ public:
       return;
     }
 
     if (mIsShutdown) {
       NS_WARNING("EME decrypted sample arrived after shutdown");
       return;
     }
 
-    if (aDecrypted.mStatus == GMPNoKeyErr) {
+    if (aDecrypted.mStatus == NoKeyErr) {
       // Key became unusable after we sent the sample to CDM to decrypt.
       // Call Input() again, so that the sample is enqueued for decryption
       // if the key becomes usable again.
       Input(aDecrypted.mSample);
-    } else if (GMP_FAILED(aDecrypted.mStatus)) {
+    } else if (aDecrypted.mStatus != Ok) {
       if (mCallback) {
         mCallback->Error(MediaDataDecoderError::FATAL_ERROR);
       }
     } else {
       MOZ_ASSERT(!mIsShutdown);
       // The Adobe GMP AAC decoder gets confused if we pass it non-encrypted
       // samples with valid crypto data. So clear the crypto data, since the
       // sample should be decrypted now anyway. If we don't do this and we're