Bug 1351953 - Send Data to CDM for decrypt and or decode in shmems. r=gerald

MozReview-Commit-ID: 2UdGimoOLKr

--HG--
extra : rebase_source : 04879d8c1639bf6f14cebc6031d8cc23e05e567a
This commit is contained in:
Chris Pearce 2017-03-27 13:19:38 +13:00
Родитель 65d7ce66ea
Коммит fb5a8a3e0d
5 изменённых файлов: 27 добавлений и 10 удалений

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

@ -14,6 +14,7 @@
#include "nsPrintfCString.h"
#include "base/time.h"
#include "GMPUtils.h"
#include "mozilla/ScopeExit.h"
namespace mozilla {
namespace gmp {
@ -388,8 +389,8 @@ InitInputBuffer(const CDMInputBuffer& aBuffer,
nsTArray<cdm::SubsampleEntry>& aSubSamples,
cdm::InputBuffer& aInputBuffer)
{
aInputBuffer.data = aBuffer.mData().Elements();
aInputBuffer.data_size = aBuffer.mData().Length();
aInputBuffer.data = aBuffer.mData().get<uint8_t>();
aInputBuffer.data_size = aBuffer.mData().Size<uint8_t>();
if (aBuffer.mIsEncrypted()) {
aInputBuffer.key_id = aBuffer.mKeyId().Elements();
@ -415,6 +416,11 @@ ChromiumCDMChild::RecvDecrypt(const uint32_t& aId,
{
MOZ_ASSERT(IsOnMessageLoopThread());
GMP_LOG("ChromiumCDMChild::RecvDecrypt()");
auto autoDeallocateShmem = MakeScopeExit([&,this] {
this->DeallocShmem(aBuffer.mData());
});
if (!mCDM) {
GMP_LOG("ChromiumCDMChild::RecvDecrypt() no CDM");
DecryptFailed(aId, cdm::kDecryptError);
@ -440,7 +446,7 @@ ChromiumCDMChild::RecvDecrypt(const uint32_t& aId,
}
if (!output.DecryptedBuffer() ||
output.DecryptedBuffer()->Size() != aBuffer.mData().Length()) {
output.DecryptedBuffer()->Size() != aBuffer.mData().Size<uint8_t>()) {
// The sizes of the input and output should exactly match.
DecryptFailed(aId, cdm::kDecryptError);
return IPC_OK();
@ -510,6 +516,10 @@ ChromiumCDMChild::RecvDecryptAndDecodeFrame(const CDMInputBuffer& aBuffer)
aBuffer.mTimestamp());
MOZ_ASSERT(mDecoderInitialized);
auto autoDeallocateShmem = MakeScopeExit([&, this] {
this->DeallocShmem(aBuffer.mData());
});
// The output frame may not have the same timestamp as the frame we put in.
// We may need to input a number of frames before we receive output. The
// CDM's decoder reorders to ensure frames output are in presentation order.

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

@ -169,8 +169,8 @@ ChromiumCDMParent::RemoveSession(const nsCString& aSessionId,
}
}
static bool
InitCDMInputBuffer(gmp::CDMInputBuffer& aBuffer, MediaRawData* aSample)
bool
ChromiumCDMParent::InitCDMInputBuffer(gmp::CDMInputBuffer& aBuffer, MediaRawData* aSample)
{
const CryptoSample& crypto = aSample->mCrypto;
if (crypto.mEncryptedSizes.Length() != crypto.mPlainSizes.Length()) {
@ -178,10 +178,13 @@ InitCDMInputBuffer(gmp::CDMInputBuffer& aBuffer, MediaRawData* aSample)
return false;
}
nsTArray<uint8_t> data;
data.AppendElements(aSample->Data(), aSample->Size());
Shmem shmem;
if (!AllocShmem(aSample->Size(), Shmem::SharedMemory::TYPE_BASIC, &shmem)) {
return false;
}
memcpy(shmem.get<uint8_t>(), aSample->Data(), aSample->Size());
aBuffer = gmp::CDMInputBuffer(data,
aBuffer = gmp::CDMInputBuffer(shmem,
crypto.mKeyId,
crypto.mIV,
aSample->mTime,
@ -209,6 +212,7 @@ ChromiumCDMParent::Decrypt(MediaRawData* aSample)
GMP_LOG(
"ChromiumCDMParent::Decrypt(this=%p) failed to send decrypt message",
this);
DeallocShmem(buffer.mData());
return DecryptPromise::CreateAndReject(DecryptResult(GenericErr, aSample),
__func__);
}
@ -721,6 +725,7 @@ ChromiumCDMParent::DecryptAndDecodeFrame(MediaRawData* aSample)
GMP_LOG(
"ChromiumCDMParent::Decrypt(this=%p) failed to send decrypt message.",
this);
DeallocShmem(buffer.mData());
return MediaDataDecoder::DecodePromise::CreateAndReject(
MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
"Failed to send decrypt to CDM process."),

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

@ -127,6 +127,8 @@ protected:
void ResolvePromise(uint32_t aPromiseId);
bool InitCDMInputBuffer(gmp::CDMInputBuffer& aBuffer, MediaRawData* aSample);
const uint32_t mPluginId;
GMPContentParent* mContentParent;
// Note: this pointer is a weak reference because otherwise it would cause

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

@ -61,7 +61,7 @@ struct GMPKeyInformation {
};
struct CDMInputBuffer {
uint8_t[] mData;
Shmem mData;
uint8_t[] mKeyId;
uint8_t[] mIV;
int64_t mTimestamp;

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

@ -87,7 +87,7 @@ parent:
async ResolveLoadSessionPromise(uint32_t aPromiseId, bool aSuccessful);
// Return values of cdm::ContentDecryptionModule8::Decrypt
async Decrypted(uint32_t aId, uint32_t aStatus, uint8_t[] aData);
async Decrypted(uint32_t aId, uint32_t aStatus, Shmem aData);
async OnDecoderInitDone(uint32_t aStatus);