Bug 1284192 - get rid of GMPErr from CDMProxy base class. r=cpearce

MozReview-Commit-ID: 43WduOtIfZH
This commit is contained in:
James Cheng 2016-07-18 22:12:00 +02:00
Родитель 02c5726f49
Коммит 0cb95c8c46
5 изменённых файлов: 39 добавлений и 20 удалений

Просмотреть файл

@ -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<MediaRawData> mSample;
};
@ -149,7 +156,7 @@ public:
// 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.

Просмотреть файл

@ -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

Просмотреть файл

@ -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<uint8_t>& aDecryptedData)
{
MOZ_ASSERT(IsOnOwnerThread());
@ -677,7 +677,7 @@ GMPCDMProxy::gmp_Decrypt(RefPtr<DecryptJob> aJob)
MOZ_ASSERT(IsOnOwnerThread());
if (!mCDM) {
aJob->PostResult(GMPAbortedErr);
aJob->PostResult(AbortedErr);
return;
}
@ -690,7 +690,7 @@ GMPCDMProxy::gmp_Decrypt(RefPtr<DecryptJob> aJob)
void
GMPCDMProxy::gmp_Decrypted(uint32_t aId,
GMPErr aResult,
DecryptStatus aResult,
const nsTArray<uint8_t>& 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<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());
}

Просмотреть файл

@ -86,7 +86,7 @@ public:
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,
@ -181,8 +181,9 @@ private:
{
}
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__);
@ -199,7 +200,7 @@ private:
// GMP thread only.
void gmp_Decrypted(uint32_t aId,
GMPErr aResult,
DecryptStatus aResult,
const nsTArray<uint8_t>& aDecryptedData);
class RejectPromiseTask : public Runnable {

Просмотреть файл

@ -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);
}