[mq]:
Bug 1284192 - get rid of GMPErr from CDMProxy base class. r?cpearce
MozReview-Commit-ID: 43WduOtIfZH
--- a/dom/media/eme/CDMProxy.h
+++ b/dom/media/eme/CDMProxy.h
@@ -13,22 +13,31 @@
#include "mozilla/dom/MediaKeyMessageEvent.h"
#include "mozilla/dom/MediaKeys.h"
#include "nsIThread.h"
namespace mozilla {
class MediaRawData;
+enum CDMErr
+{
+ CDMNoErr = 0,
+ CDMGenericErr = 1,
+ CDMNoKeyErr = 2,
+ CDMAbortedErr = 3,
+ CDMLastErr // Placeholder, must be last. This enum's values must remain consecutive!
+};
+
struct DecryptResult {
- DecryptResult(GMPErr aStatus, MediaRawData* aSample)
+ DecryptResult(CDMErr aStatus, MediaRawData* aSample)
: mStatus(aStatus)
, mSample(aSample)
{}
- GMPErr mStatus;
+ CDMErr 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 +153,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,
+ CDMErr 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,34 @@ GMPCDMCallbackProxy::KeyStatusChanged(co
nsCOMPtr<nsIRunnable> task;
task = NewRunnableMethod<nsString>(mProxy,
&CDMProxy::OnKeyStatusesChange,
NS_ConvertUTF8toUTF16(aSessionId));
NS_DispatchToMainThread(task);
}
}
+CDMErr
+ToCDMErr(GMPErr aError)
+{
+ switch (aError) {
+ case GMPNoErr: return CDMNoErr;
+ case GMPNoKeyErr: return CDMNoKeyErr;
+ default: return CDMGenericErr;
+ }
+}
+
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, ToCDMErr(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(CDMAbortedErr);
}
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,
+ CDMErr 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(CDMAbortedErr);
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,
+ CDMErr 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(CDMErr aResult)
{
nsTArray<uint8_t> empty;
PostResult(aResult, empty);
}
void
-GMPCDMProxy::DecryptJob::PostResult(GMPErr aResult,
+GMPCDMProxy::DecryptJob::PostResult(CDMErr 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 == CDMNoErr) {
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 == CDMNoKeyErr) {
+ NS_WARNING("CDM returned CDMNoKeyErr");
// 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 CDMErr=");
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,
+ CDMErr 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,35 @@ 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(CDMErr aResult, const nsTArray<uint8_t>& aDecryptedData);
+ void PostResult(CDMErr 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,
+ CDMErr 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 == CDMNoKeyErr) {
// 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 != CDMNoErr) {
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