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
This commit is contained in:
Bryce Seager van Dyk 2020-08-20 16:22:49 +00:00
Родитель b17bb7ed34
Коммит d79c58b586
5 изменённых файлов: 18 добавлений и 56 удалений

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

@ -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<cdm::SubsampleEntry>& aSubSamples,
cdm::InputBuffer_2& aInputBuffer) {
aInputBuffer.data = aBuffer.mData().get<uint8_t>();
aInputBuffer.data_size = aBuffer.mData().Size<uint8_t>();
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<uint8_t> 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);

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

@ -284,16 +284,15 @@ bool ChromiumCDMParent::InitCDMInputBuffer(gmp::CDMInputBuffer& aBuffer,
return false;
}
memcpy(shmem.get<uint8_t>(), 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<uint8_t>& iv =
encryptionScheme != GMPEncryptionScheme::kGMPEncryptionCbcs
? crypto.mIV
: crypto.mConstantIV;
const nsTArray<uint8_t>& 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;
}

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

@ -49,10 +49,10 @@ struct ParamTraits<GMPBufferType>
GMP_BufferInvalid> {};
template <>
struct ParamTraits<GMPEncryptionScheme>
: public ContiguousEnumSerializer<
GMPEncryptionScheme, GMPEncryptionScheme::kGMPEncryptionNone,
GMPEncryptionScheme::kGMPEncryptionInvalid> {};
struct ParamTraits<cdm::EncryptionScheme>
: public ContiguousEnumSerializerInclusive<
cdm::EncryptionScheme, cdm::EncryptionScheme::kUnencrypted,
cdm::EncryptionScheme::kCbcs> {};
template <>
struct ParamTraits<cdm::HdcpVersion>

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

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

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

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