[Mac][EME] Support ClearKey encryption with AES128-encrypted HLS
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Feb 2015 23:27:11 +0000 (23:27 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Feb 2015 23:27:11 +0000 (23:27 +0000)
commit86d31f6efe61bdb68c5d6bf88d49984df35c5335
tree451682237ba9eb5517bb1df478b688d212ae3b69
parent620a4ca281d2eea4ecc2069630d78ebdc9d97c8e
[Mac][EME] Support ClearKey encryption with AES128-encrypted HLS
https://bugs.webkit.org/show_bug.cgi?id=140825

Reviewed by Eric Carlson.

Source/WebCore:

Test: http/tests/media/clearkey/clear-key-hls-aes128.html

Add support for ClearKey encryption when used with an AES-128 encrypted HLS stream.

* Modules/encryptedmedia/CDM.cpp:
(WebCore::installedCDMFactories): Add the CDMPrivateClearKey factory.
* Modules/encryptedmedia/CDMPrivateClearKey.cpp:
(WebCore::CDMPrivateClearKey::supportsKeySystem): Support the "org.w3c.clearkey" key system.
(WebCore::CDMPrivateClearKey::supportsKeySystemAndMimeType): Ditto.
(WebCore::CDMPrivateClearKey::supportsMIMEType): Ditto.
(WebCore::CDMPrivateClearKey::createSession): Create a CDMSessionClearKey.
* Modules/encryptedmedia/CDMPrivateClearKey.h:
(WebCore::CDMPrivateClearKey::create): Simple factory.
(WebCore::CDMPrivateClearKey::~CDMPrivateClearKey): Virtual destructor.
(WebCore::CDMPrivateClearKey::CDMPrivateClearKey): Simple destructor.
* Modules/encryptedmedia/CDMSessionClearKey.cpp: Added.
(WebCore::clearKeyVM): Static method returning the VM to be used by JSON parsing.
(WebCore::CDMSessionClearKey::CDMSessionClearKey): Simple constructor.
(WebCore::CDMSessionClearKey::~CDMSessionClearKey): Simple destructor.
(WebCore::CDMSessionClearKey::generateKeyRequest): Store the initData, ensure that it consists of a UTF8-encoded key
    URI, and return same.
(WebCore::CDMSessionClearKey::releaseKeys): Purged all cached keys.
(WebCore::CDMSessionClearKey::update): Parse raw JSON-encoded JWK keys, rejecting non-AES, non-oct keys.
(WebCore::CDMSessionClearKey::cachedKeyForKeyID): Return cached keys.
* Modules/encryptedmedia/CDMSessionClearKey.h:

Add support for the "org.w3c.clearkey" CDM to MediaPlayerPrivateAVFoundationObjC, and do so in a platform-agnostic
way by simply asking for raw key data from MediaPlayerClient when notified that a key has been added.

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::keySystemIsSupported):
(WebCore::MediaPlayerPrivateAVFoundationObjC::supportsType):
(WebCore::MediaPlayerPrivateAVFoundationObjC::supportsKeySystem):
(WebCore::fulfillRequestWithKeyData): Added utility method.
(WebCore::MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource):
(WebCore::MediaPlayerPrivateAVFoundationObjC::keyAdded):

Pipe a keyAdded() notification down to MediaPlayer and a cachedKeyForKeyId() request up to CDMSessionClearKey:

* Modules/encryptedmedia/MediaKeySession.cpp:
(WebCore::MediaKeySession::cachedKeyForKeyId):
(WebCore::MediaKeySession::addKeyTimerFired):
* Modules/encryptedmedia/MediaKeySession.h:
* Modules/encryptedmedia/MediaKeys.cpp:
(WebCore::MediaKeys::keyAdded):
(WebCore::MediaKeys::cachedKeyForKeyId):
* Modules/encryptedmedia/MediaKeys.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::keyAdded):
* html/HTMLMediaElement.h:
* platform/graphics/CDMSession.h:
(WebCore::CDMSession::cachedKeyForKeyID):
* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::keyAdded):
(WebCore::MediaPlayer::cachedKeyForKeyId):
* platform/graphics/MediaPlayer.h:
(WebCore::MediaPlayerClient::mediaPlayerCachedKeyForKeyId):
* platform/graphics/MediaPlayerPrivate.h:
(WebCore::MediaPlayerPrivateInterface::keyAdded):

Add new files to project:

* WebCore.xcodeproj/project.pbxproj:
* CMakeLists.txt:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:

LayoutTests:

* http/tests/media/clearkey/clear-key-hls-aes128-expected.txt: Added.
* http/tests/media/clearkey/clear-key-hls-aes128.html: Added.
* http/tests/media/clearkey/support.js: Added.
(stringToUInt8Array):
(uInt8ArrayToString):
(base64EncodeUint8Array):
* http/tests/media/resources/hls/clearkey/crypt0.key: Added.
* http/tests/media/resources/hls/clearkey/iframe_index.m3u8: Added.
* http/tests/media/resources/hls/clearkey/main0.ts: Added.
* http/tests/media/resources/hls/clearkey/prog_index.m3u8: Added.
* media/video-test.js:
(waitForEventOnceOn):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@179641 268f45cc-cd09-0410-ab3c-d52691b4dbfc
31 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/media/clearkey/clear-key-hls-aes128-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/media/clearkey/clear-key-hls-aes128.html [new file with mode: 0644]
LayoutTests/http/tests/media/clearkey/support.js [new file with mode: 0644]
LayoutTests/http/tests/media/resources/hls/clearkey/crypt0.key [new file with mode: 0644]
LayoutTests/http/tests/media/resources/hls/clearkey/iframe_index.m3u8 [new file with mode: 0644]
LayoutTests/http/tests/media/resources/hls/clearkey/main0.ts [new file with mode: 0644]
LayoutTests/http/tests/media/resources/hls/clearkey/prog_index.m3u8 [new file with mode: 0644]
LayoutTests/media/video-test.js
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/encryptedmedia/CDM.cpp
Source/WebCore/Modules/encryptedmedia/CDMPrivateClearKey.cpp [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/CDMPrivateClearKey.h [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/CDMSessionClearKey.cpp [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/CDMSessionClearKey.h [new file with mode: 0644]
Source/WebCore/Modules/encryptedmedia/MediaKeySession.cpp
Source/WebCore/Modules/encryptedmedia/MediaKeySession.h
Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp
Source/WebCore/Modules/encryptedmedia/MediaKeys.h
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/platform/graphics/CDMSession.h
Source/WebCore/platform/graphics/MediaPlayer.cpp
Source/WebCore/platform/graphics/MediaPlayer.h
Source/WebCore/platform/graphics/MediaPlayerPrivate.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm