Add Support for WebM Back

Adds support for WebM to the CDM. Decryption remains untouched,
however the initialization data is passed differently for WebM.

The previous version of this change broke playback for certain
apps that were being allowed to pass invalid MIME types before
this change was made. This version maintains backwards-compatiblity
for these apps for now by rewriting their MIME types as "video/mp4".

Merge of https://widevine-internal-review.googlesource.com/9225/
and https://widevine-internal-review.googlesource.com/9611/ from
the Widevine cdm repo.

Bug: 10638562
Change-Id: Ib37e838d08363f07b34b3a2e79a3f80a1f43e9ad
This commit is contained in:
John "Juce" Bruce
2014-03-31 14:12:11 -07:00
parent 66cadaa9fa
commit 702aadf853
16 changed files with 329 additions and 105 deletions

View File

@@ -149,22 +149,51 @@ status_t WVDrmPlugin::getKeyRequest(
return android::ERROR_DRM_CANNOT_HANDLE;
}
// Build PSSH box for PSSH data in initData.
static const char psshPrefix[] = {
0, 0, 0, 0, // Total size
'p', 's', 's', 'h', // "PSSH"
0, 0, 0, 0, // Flags - must be zero
0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, // Widevine UUID
0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED,
0, 0, 0, 0 // Size of initData
};
CdmInitData psshBox(psshPrefix, sizeof(psshPrefix) / sizeof(uint8_t));
psshBox.append(reinterpret_cast<const char*>(initData.array()),
initData.size());
uint32_t* psshBoxSize = reinterpret_cast<uint32_t*>(&psshBox[0]);
uint32_t* initDataSize = reinterpret_cast<uint32_t*>(&psshBox[28]);
*initDataSize = htonl(initData.size());
*psshBoxSize = htonl(psshBox.size());
string cdmMimeType = mimeType.string();
// Provide backwards-compatibility for versions of apps that pass the wrong
// MIME type.
// TODO(b/13731637) - Remove this.
if (cdmMimeType == "") {
ALOGW("ALERT: Empty MIME type is supported for backwards-compatibility "
"only and may go away in the future. Switch to \"video/mp4\" to "
"become compliant.");
cdmMimeType = "video/mp4";
} else if (cdmMimeType == "video/avc") {
ALOGW("ALERT: MIME type \"video/avc\" is supported for backwards-"
"compatibility only and may go away in the future. Switch to "
"\"video/mp4\" to become compliant.");
cdmMimeType = "video/mp4";
}
CdmInitData processedInitData;
if (cdmMimeType == wvcdm::ISO_BMFF_MIME_TYPE) {
// For ISO-BMFF, we need to wrap the init data in a new PSSH header.
static const char psshPrefix[] = {
0, 0, 0, 0, // Total size
'p', 's', 's', 'h', // "PSSH"
0, 0, 0, 0, // Flags - must be zero
0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, // Widevine UUID
0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED,
0, 0, 0, 0 // Size of initData
};
processedInitData.assign(psshPrefix, sizeof(psshPrefix) / sizeof(char));
processedInitData.append(reinterpret_cast<const char*>(initData.array()),
initData.size());
const size_t kPsshBoxSizeLocation = 0;
const size_t kInitDataSizeLocation =
sizeof(psshPrefix) - sizeof(uint32_t);
uint32_t psshBoxSize = htonl(processedInitData.size());
uint32_t initDataSize = htonl(initData.size());
memcpy(&processedInitData[kPsshBoxSizeLocation], &psshBoxSize,
sizeof(uint32_t));
memcpy(&processedInitData[kInitDataSizeLocation], &initDataSize,
sizeof(uint32_t));
} else {
// For other formats, we can pass the init data through unmodified.
processedInitData.assign(reinterpret_cast<const char*>(initData.array()),
initData.size());
}
CdmAppParameterMap cdmParameters;
for (size_t i = 0; i < optionalParameters.size(); ++i) {
@@ -179,11 +208,10 @@ status_t WVDrmPlugin::getKeyRequest(
CdmKeyMessage keyRequest;
string cdmDefaultUrl;
CdmResponseType res = mCDM->GenerateKeyRequest(cdmSessionId, cdmKeySetId,
psshBox, cdmLicenseType,
cdmParameters, &keyRequest,
&cdmDefaultUrl);
cdmMimeType, processedInitData,
cdmLicenseType, cdmParameters,
&keyRequest, &cdmDefaultUrl);
if (isCdmResponseTypeSuccess(res)) {
defaultUrl.clear();