Title: [235610] trunk/Source/WebCore
Revision
235610
Author
commit-qu...@webkit.org
Date
2018-09-04 03:27:27 -0700 (Tue, 04 Sep 2018)

Log Message

[EME] Add the WebM initData support in ClearKey CDM
https://bugs.webkit.org/show_bug.cgi?id=189240

Patch by Yacine Bandou <yacine.bandou_...@softathome.com> on 2018-09-04
Reviewed by Xabier Rodriguez-Calvar.

Add the "webm" initDataType support in ClearKey CDM.
Read the WebM initData by following the W3C spec https://www.w3.org/TR/eme-initdata-webm/#common-system,
and put it in JSON object format like is specified in https://www.w3.org/TR/encrypted-media/#clear-key-request-format.

Tests: media/encrypted-media/clearKey/clearKey-encrypted-webm-event-mse.html
       media/encrypted-media/clearKey/clearKey-webm-video-playback-mse.html

* platform/encryptedmedia/clearkey/CDMClearKey.cpp:
(WebCore::extractKeyIdFromWebMInitData):
(WebCore::CDMPrivateClearKey::supportsInitDataType const):
(WebCore::CDMPrivateClearKey::supportsInitData const):
(WebCore::CDMInstanceClearKey::requestLicense):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (235609 => 235610)


--- trunk/Source/WebCore/ChangeLog	2018-09-04 10:27:20 UTC (rev 235609)
+++ trunk/Source/WebCore/ChangeLog	2018-09-04 10:27:27 UTC (rev 235610)
@@ -1,3 +1,23 @@
+2018-09-04  Yacine Bandou  <yacine.bandou_...@softathome.com>
+
+        [EME] Add the WebM initData support in ClearKey CDM
+        https://bugs.webkit.org/show_bug.cgi?id=189240
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        Add the "webm" initDataType support in ClearKey CDM.
+        Read the WebM initData by following the W3C spec https://www.w3.org/TR/eme-initdata-webm/#common-system,
+        and put it in JSON object format like is specified in https://www.w3.org/TR/encrypted-media/#clear-key-request-format.
+
+        Tests: media/encrypted-media/clearKey/clearKey-encrypted-webm-event-mse.html
+               media/encrypted-media/clearKey/clearKey-webm-video-playback-mse.html
+
+        * platform/encryptedmedia/clearkey/CDMClearKey.cpp:
+        (WebCore::extractKeyIdFromWebMInitData):
+        (WebCore::CDMPrivateClearKey::supportsInitDataType const):
+        (WebCore::CDMPrivateClearKey::supportsInitData const):
+        (WebCore::CDMInstanceClearKey::requestLicense):
+
 2018-09-03  Andy Estes  <aes...@apple.com>
 
         [Payment Request] Remove PaymentAddress.languageCode

Modified: trunk/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp (235609 => 235610)


--- trunk/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp	2018-09-04 10:27:20 UTC (rev 235609)
+++ trunk/Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp	2018-09-04 10:27:27 UTC (rev 235610)
@@ -263,6 +263,32 @@
     return keyIds;
 }
 
+static Ref<SharedBuffer> extractKeyIdFromWebMInitData(const SharedBuffer& initData)
+{
+    Ref<SharedBuffer> keyIds = SharedBuffer::create();
+
+    // Check if initData is a valid WebM initData.
+    if (initData.isEmpty() || initData.size() > std::numeric_limits<unsigned>::max())
+        return keyIds;
+
+    auto object = JSON::Object::create();
+    auto keyIdsArray = JSON::Array::create();
+
+    // Read the KeyId
+    // 9.1.3 License Request Format
+    // This section describes the format of the license request provided to the application via the message attribute of the message event.
+    // The format is a JSON object containing the following members:
+    // "kids"
+    // An array of key IDs. Each element of the array is the base64url encoding of the octet sequence containing the key ID value.
+    String keyId = WTF::base64URLEncode(initData.data(), initData.size());
+    keyIdsArray->pushString(keyId);
+
+    object->setArray("kids", WTFMove(keyIdsArray));
+    CString jsonData = object->toJSONString().utf8();
+    keyIds->append(jsonData.data(), jsonData.length());
+    return keyIds;
+}
+
 CDMFactoryClearKey& CDMFactoryClearKey::singleton()
 {
     static NeverDestroyed<CDMFactoryClearKey> s_factory;
@@ -294,7 +320,7 @@
 bool CDMPrivateClearKey::supportsInitDataType(const AtomicString& initDataType) const
 {
     // `keyids` and 'cenc' are the only supported init data type.
-    return (equalLettersIgnoringASCIICase(initDataType, "keyids") || equalLettersIgnoringASCIICase(initDataType, "cenc"));
+    return (equalLettersIgnoringASCIICase(initDataType, "keyids") || equalLettersIgnoringASCIICase(initDataType, "cenc") || equalLettersIgnoringASCIICase(initDataType, "webm"));
 }
 
 static bool containsPersistentLicenseType(const Vector<CDMSessionType>& types)
@@ -405,6 +431,10 @@
     if (equalLettersIgnoringASCIICase(initDataType, "cenc") && isCencInitData(initData))
         return true;
 
+    // Validate the initData buffer as WebM initData.
+    if (equalLettersIgnoringASCIICase(initDataType, "webm") && !initData.isEmpty())
+        return true;
+
     return false;
 }
 
@@ -471,6 +501,9 @@
     if (equalLettersIgnoringASCIICase(initDataType, "cenc"))
         initData = extractKeyidsFromCencInitData(initData.get());
 
+    if (equalLettersIgnoringASCIICase(initDataType, "webm"))
+        initData = extractKeyIdFromWebMInitData(initData.get());
+
     callOnMainThread(
         [weakThis = makeWeakPtr(*this), callback = WTFMove(callback), initData = WTFMove(initData), sessionIdValue = s_sessionIdValue]() mutable {
             if (!weakThis)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to