From 0cb95c8c46179081d53b5db77dfd3771aad1a6ff Mon Sep 17 00:00:00 2001 From: James Cheng Date: Mon, 18 Jul 2016 22:12:00 +0200 Subject: [PATCH] Bug 1284192 - get rid of GMPErr from CDMProxy base class. r=cpearce MozReview-Commit-ID: 43WduOtIfZH --- dom/media/eme/CDMProxy.h | 13 +++++++++--- dom/media/gmp/GMPCDMCallbackProxy.cpp | 13 +++++++++++- dom/media/gmp/GMPCDMProxy.cpp | 20 +++++++++---------- dom/media/gmp/GMPCDMProxy.h | 9 +++++---- .../agnostic/eme/EMEDecoderModule.cpp | 4 ++-- 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/dom/media/eme/CDMProxy.h b/dom/media/eme/CDMProxy.h index 20a4a83ecf8f..863312bd92c1 100644 --- a/dom/media/eme/CDMProxy.h +++ b/dom/media/eme/CDMProxy.h @@ -18,12 +18,19 @@ 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 mSample; }; @@ -149,7 +156,7 @@ public: // Owner thread only. virtual void OnDecrypted(uint32_t aId, - GMPErr aResult, + DecryptStatus aResult, const nsTArray& aDecryptedData) = 0; // Reject promise with DOMException corresponding to aExceptionCode. diff --git a/dom/media/gmp/GMPCDMCallbackProxy.cpp b/dom/media/gmp/GMPCDMCallbackProxy.cpp index b729e8afe467..0013c59116c3 100644 --- a/dom/media/gmp/GMPCDMCallbackProxy.cpp +++ b/dom/media/gmp/GMPCDMCallbackProxy.cpp @@ -314,6 +314,17 @@ GMPCDMCallbackProxy::KeyStatusChanged(const nsCString& aSessionId, } } +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, @@ -321,7 +332,7 @@ GMPCDMCallbackProxy::Decrypted(uint32_t aId, { MOZ_ASSERT(mProxy->IsOnOwnerThread()); - mProxy->OnDecrypted(aId, aResult, aDecryptedData); + mProxy->OnDecrypted(aId, ToDecryptStatus(aResult), aDecryptedData); } void diff --git a/dom/media/gmp/GMPCDMProxy.cpp b/dom/media/gmp/GMPCDMProxy.cpp index 903078739c64..03612167e364 100644 --- a/dom/media/gmp/GMPCDMProxy.cpp +++ b/dom/media/gmp/GMPCDMProxy.cpp @@ -471,7 +471,7 @@ GMPCDMProxy::gmp_Shutdown() // 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(); @@ -602,7 +602,7 @@ GMPCDMProxy::OnSessionClosed(const nsAString& aSessionId) void GMPCDMProxy::OnDecrypted(uint32_t aId, - GMPErr aResult, + DecryptStatus aResult, const nsTArray& aDecryptedData) { MOZ_ASSERT(IsOnOwnerThread()); @@ -677,7 +677,7 @@ GMPCDMProxy::gmp_Decrypt(RefPtr aJob) MOZ_ASSERT(IsOnOwnerThread()); if (!mCDM) { - aJob->PostResult(GMPAbortedErr); + aJob->PostResult(AbortedErr); return; } @@ -690,7 +690,7 @@ GMPCDMProxy::gmp_Decrypt(RefPtr aJob) void GMPCDMProxy::gmp_Decrypted(uint32_t aId, - GMPErr aResult, + DecryptStatus aResult, const nsTArray& aDecryptedData) { MOZ_ASSERT(IsOnOwnerThread()); @@ -715,30 +715,30 @@ GMPCDMProxy::gmp_Decrypted(uint32_t aId, } void -GMPCDMProxy::DecryptJob::PostResult(GMPErr aResult) +GMPCDMProxy::DecryptJob::PostResult(DecryptStatus aResult) { nsTArray empty; PostResult(aResult, empty); } void -GMPCDMProxy::DecryptJob::PostResult(GMPErr aResult, +GMPCDMProxy::DecryptJob::PostResult(DecryptStatus aResult, const nsTArray& aDecryptedData) { if (aDecryptedData.Length() != mSample->Size()) { NS_WARNING("CDM returned incorrect number of decrypted bytes"); } - if (GMP_SUCCEEDED(aResult)) { + if (aResult == Ok) { nsAutoPtr writer(mSample->CreateWriter()); PodCopy(writer->Data(), aDecryptedData.Elements(), std::min(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()); } diff --git a/dom/media/gmp/GMPCDMProxy.h b/dom/media/gmp/GMPCDMProxy.h index 029f4dc89af3..2c2e3fc482db 100644 --- a/dom/media/gmp/GMPCDMProxy.h +++ b/dom/media/gmp/GMPCDMProxy.h @@ -86,7 +86,7 @@ public: RefPtr Decrypt(MediaRawData* aSample) override; void OnDecrypted(uint32_t aId, - GMPErr aResult, + DecryptStatus aResult, const nsTArray& aDecryptedData) override; void RejectPromise(PromiseId aId, nsresult aExceptionCode, @@ -181,8 +181,9 @@ private: { } - void PostResult(GMPErr aResult, const nsTArray& aDecryptedData); - void PostResult(GMPErr aResult); + void PostResult(DecryptStatus aResult, + const nsTArray& aDecryptedData); + void PostResult(DecryptStatus aResult); RefPtr Ensure() { return mPromise.Ensure(__func__); @@ -199,7 +200,7 @@ private: // GMP thread only. void gmp_Decrypted(uint32_t aId, - GMPErr aResult, + DecryptStatus aResult, const nsTArray& aDecryptedData); class RejectPromiseTask : public Runnable { diff --git a/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp b/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp index 62dcbea7b66f..bf970c99a1c2 100644 --- a/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp +++ b/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp @@ -84,12 +84,12 @@ public: 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); }