From d79c58b5867610996694ebcce92a7ea761d8fc86 Mon Sep 17 00:00:00 2001 From: Bryce Seager van Dyk Date: Thu, 20 Aug 2020 16:22:49 +0000 Subject: [PATCH] Bug 1654383 - Replace GMPEncryptionType with cdm::EncryptionScheme. r=alwu,dminor This removes the need to do some conversions and simplifies the code a little. Drive by remove an assert which is already covered by a switch statement containing a MOZ_ASSERT_UNREACHABLE in ChromiumCDMParent. Differential Revision: https://phabricator.services.mozilla.com/D84432 --- dom/media/gmp/ChromiumCDMChild.cpp | 29 +++++-------------------- dom/media/gmp/ChromiumCDMParent.cpp | 22 +++++-------------- dom/media/gmp/GMPMessageUtils.h | 8 +++---- dom/media/gmp/GMPTypes.ipdlh | 6 ++--- dom/media/gmp/gmp-api/gmp-video-codec.h | 9 -------- 5 files changed, 18 insertions(+), 56 deletions(-) diff --git a/dom/media/gmp/ChromiumCDMChild.cpp b/dom/media/gmp/ChromiumCDMChild.cpp index 445f78eb812a..fcec6ef07536 100644 --- a/dom/media/gmp/ChromiumCDMChild.cpp +++ b/dom/media/gmp/ChromiumCDMChild.cpp @@ -521,32 +521,15 @@ mozilla::ipc::IPCResult ChromiumCDMChild::RecvGetStatusForPolicy( return IPC_OK(); } -static cdm::EncryptionScheme ConvertToCdmEncryptionScheme( - const GMPEncryptionScheme& aEncryptionScheme) { - switch (aEncryptionScheme) { - case GMPEncryptionScheme::kGMPEncryptionNone: - return cdm::EncryptionScheme::kUnencrypted; - case GMPEncryptionScheme::kGMPEncryptionCenc: - return cdm::EncryptionScheme::kCenc; - case GMPEncryptionScheme::kGMPEncryptionCbcs: - return cdm::EncryptionScheme::kCbcs; - default: - MOZ_ASSERT_UNREACHABLE("Cannot convert invalid encryption scheme!"); - return cdm::EncryptionScheme::kUnencrypted; - } -} - static void InitInputBuffer(const CDMInputBuffer& aBuffer, nsTArray& aSubSamples, cdm::InputBuffer_2& aInputBuffer) { aInputBuffer.data = aBuffer.mData().get(); aInputBuffer.data_size = aBuffer.mData().Size(); - if (aBuffer.mEncryptionScheme() > GMPEncryptionScheme::kGMPEncryptionNone) { - MOZ_ASSERT(aBuffer.mEncryptionScheme() == - GMPEncryptionScheme::kGMPEncryptionCenc || - aBuffer.mEncryptionScheme() == - GMPEncryptionScheme::kGMPEncryptionCbcs); + if (aBuffer.mEncryptionScheme() != cdm::EncryptionScheme::kUnencrypted) { + MOZ_ASSERT(aBuffer.mEncryptionScheme() == cdm::EncryptionScheme::kCenc || + aBuffer.mEncryptionScheme() == cdm::EncryptionScheme::kCbcs); aInputBuffer.key_id = aBuffer.mKeyId().Elements(); aInputBuffer.key_id_size = aBuffer.mKeyId().Length(); @@ -560,8 +543,7 @@ static void InitInputBuffer(const CDMInputBuffer& aBuffer, } aInputBuffer.subsamples = aSubSamples.Elements(); aInputBuffer.num_subsamples = aSubSamples.Length(); - aInputBuffer.encryption_scheme = - ConvertToCdmEncryptionScheme(aBuffer.mEncryptionScheme()); + aInputBuffer.encryption_scheme = aBuffer.mEncryptionScheme(); } aInputBuffer.pattern.crypt_byte_block = aBuffer.mCryptByteBlock(); aInputBuffer.pattern.skip_byte_block = aBuffer.mSkipByteBlock(); @@ -666,8 +648,7 @@ mozilla::ipc::IPCResult ChromiumCDMChild::RecvInitializeVideoDecoder( nsTArray extraData(aConfig.mExtraData().Clone()); config.extra_data = extraData.Elements(); config.extra_data_size = extraData.Length(); - config.encryption_scheme = - ConvertToCdmEncryptionScheme(aConfig.mEncryptionScheme()); + config.encryption_scheme = aConfig.mEncryptionScheme(); cdm::Status status = mCDM->InitializeVideoDecoder(config); GMP_LOG_DEBUG("ChromiumCDMChild::RecvInitializeVideoDecoder() status=%u", status); diff --git a/dom/media/gmp/ChromiumCDMParent.cpp b/dom/media/gmp/ChromiumCDMParent.cpp index 2a5f3a6b1387..bafd5a23405c 100644 --- a/dom/media/gmp/ChromiumCDMParent.cpp +++ b/dom/media/gmp/ChromiumCDMParent.cpp @@ -284,16 +284,15 @@ bool ChromiumCDMParent::InitCDMInputBuffer(gmp::CDMInputBuffer& aBuffer, return false; } memcpy(shmem.get(), aSample->Data(), aSample->Size()); - GMPEncryptionScheme encryptionScheme = - GMPEncryptionScheme::kGMPEncryptionNone; + cdm::EncryptionScheme encryptionScheme = cdm::EncryptionScheme::kUnencrypted; switch (crypto.mCryptoScheme) { case CryptoScheme::None: break; // Default to none case CryptoScheme::Cenc: - encryptionScheme = GMPEncryptionScheme::kGMPEncryptionCenc; + encryptionScheme = cdm::EncryptionScheme::kCenc; break; case CryptoScheme::Cbcs: - encryptionScheme = GMPEncryptionScheme::kGMPEncryptionCbcs; + encryptionScheme = cdm::EncryptionScheme::kCbcs; break; default: GMP_LOG_DEBUG( @@ -304,23 +303,14 @@ bool ChromiumCDMParent::InitCDMInputBuffer(gmp::CDMInputBuffer& aBuffer, break; } - const nsTArray& iv = - encryptionScheme != GMPEncryptionScheme::kGMPEncryptionCbcs - ? crypto.mIV - : crypto.mConstantIV; + const nsTArray& iv = encryptionScheme != cdm::EncryptionScheme::kCbcs + ? crypto.mIV + : crypto.mConstantIV; aBuffer = gmp::CDMInputBuffer( std::move(shmem), crypto.mKeyId, iv, aSample->mTime.ToMicroseconds(), aSample->mDuration.ToMicroseconds(), crypto.mPlainSizes, crypto.mEncryptedSizes, crypto.mCryptByteBlock, crypto.mSkipByteBlock, encryptionScheme); - MOZ_ASSERT( - aBuffer.mEncryptionScheme() == GMPEncryptionScheme::kGMPEncryptionNone || - aBuffer.mEncryptionScheme() == - GMPEncryptionScheme::kGMPEncryptionCenc || - aBuffer.mEncryptionScheme() == - GMPEncryptionScheme::kGMPEncryptionCbcs, - "aBuffer should use no encryption, cenc, or cbcs, other kinds are not " - "yet supported"); return true; } diff --git a/dom/media/gmp/GMPMessageUtils.h b/dom/media/gmp/GMPMessageUtils.h index e91f814084ae..ba1f9d54f296 100644 --- a/dom/media/gmp/GMPMessageUtils.h +++ b/dom/media/gmp/GMPMessageUtils.h @@ -49,10 +49,10 @@ struct ParamTraits GMP_BufferInvalid> {}; template <> -struct ParamTraits - : public ContiguousEnumSerializer< - GMPEncryptionScheme, GMPEncryptionScheme::kGMPEncryptionNone, - GMPEncryptionScheme::kGMPEncryptionInvalid> {}; +struct ParamTraits + : public ContiguousEnumSerializerInclusive< + cdm::EncryptionScheme, cdm::EncryptionScheme::kUnencrypted, + cdm::EncryptionScheme::kCbcs> {}; template <> struct ParamTraits diff --git a/dom/media/gmp/GMPTypes.ipdlh b/dom/media/gmp/GMPTypes.ipdlh index c89209efe4ff..9c1414e6b96c 100644 --- a/dom/media/gmp/GMPTypes.ipdlh +++ b/dom/media/gmp/GMPTypes.ipdlh @@ -5,8 +5,8 @@ include "GMPMessageUtils.h"; +using cdm::EncryptionScheme from "gmp-sanitized-cdm-exports.h"; using GMPBufferType from "gmp-video-codec.h"; -using GMPEncryptionScheme from "gmp-video-codec.h"; namespace mozilla { namespace gmp { @@ -58,7 +58,7 @@ struct CDMInputBuffer { uint32_t[] mCipherBytes; uint8_t mCryptByteBlock; uint8_t mSkipByteBlock; - GMPEncryptionScheme mEncryptionScheme; + EncryptionScheme mEncryptionScheme; }; struct CDMVideoDecoderConfig { @@ -68,7 +68,7 @@ struct CDMVideoDecoderConfig { int32_t mImageWidth; int32_t mImageHeight; uint8_t[] mExtraData; - GMPEncryptionScheme mEncryptionScheme; + EncryptionScheme mEncryptionScheme; }; struct CDMKeyInformation { diff --git a/dom/media/gmp/gmp-api/gmp-video-codec.h b/dom/media/gmp/gmp-api/gmp-video-codec.h index 53517d6e8ec1..81c32e63721a 100644 --- a/dom/media/gmp/gmp-api/gmp-video-codec.h +++ b/dom/media/gmp/gmp-api/gmp-video-codec.h @@ -217,13 +217,4 @@ struct GMPCodecSpecificInfo { GMPCodecSpecificInfoUnion mCodecSpecific; }; -// The encryption scheme used. Historically Widevine only supported none or -// cenc, but starting at interface version 10 the CDM should also support cbcs. -enum class GMPEncryptionScheme : uint8_t { - kGMPEncryptionNone = 0, - kGMPEncryptionCenc = 1, - kGMPEncryptionCbcs = 2, - kGMPEncryptionInvalid = 3, -}; - #endif // GMP_VIDEO_CODEC_h_