From c441bf976879c42f29ad5da263c4e94cb0a432f7 Mon Sep 17 00:00:00 2001 From: "xhwang@chromium.org" Date: Tue, 13 Nov 2012 10:05:29 +0000 Subject: Implement heart beat in ClearKeyCdm. Clear Key CDM sends out heart beat message periodically. To facilitate testing, the period of heart beat messages is short (200ms) at start-up. Then the period gets longer and longer until it reaches the maximum (1min) to avoid message spam. The heart beat key message starts with HEARTBEAT and the application should parse key messages to handle them properly. BUG=none TEST=none Review URL: https://chromiumcodereview.appspot.com/11368023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167350 0039d316-1c4b-4281-b951-d872f2087c98 --- content/test/data/media/encrypted_media_utils.js | 25 ++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'content/test') diff --git a/content/test/data/media/encrypted_media_utils.js b/content/test/data/media/encrypted_media_utils.js index 40fbde6..16ab4b7 100644 --- a/content/test/data/media/encrypted_media_utils.js +++ b/content/test/data/media/encrypted_media_utils.js @@ -28,6 +28,20 @@ var KEY = new Uint8Array([0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b, 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c]); // Stores a failure message that is read by the browser test when it fails. var failMessage = ''; +// Heart beat message header. +var HEART_BEAT_HEADER = 'HEARTBEAT'; + +function isHeartBeatMessage(msg) { + if (msg.length < HEART_BEAT_HEADER.length) + return false; + + for (var i = 0; i < HEART_BEAT_HEADER.length; ++i) { + if (HEART_BEAT_HEADER[i] != String.fromCharCode(msg[i])) + return false; + } + + return true; +} function failTest(msg) { if (msg instanceof Event) @@ -95,17 +109,24 @@ function loadEncryptedMedia(video, mediaFile, keySystem, key) { } function onKeyMessage(e) { - console.log('onKeyMessage', e); + if (isHeartBeatMessage(e.message)) { + console.log('onKeyMessage - heart beat', e); + return; + } + + console.log('onKeyMessage - key request', e); video.webkitAddKey(keySystem, key, e.message); } var mediaSource = new WebKitMediaSource(); - video.src = window.URL.createObjectURL(mediaSource); + mediaSource.addEventListener('webkitsourceopen', onSourceOpen); video.addEventListener('webkitneedkey', onNeedKey); video.addEventListener('webkitkeymessage', onKeyMessage); video.addEventListener('webkitkeyerror', failTest); video.addEventListener('webkitkeyadded', onKeyAdded); installTitleEventHandler(video, 'error'); + + video.src = window.URL.createObjectURL(mediaSource); return mediaSource; } -- cgit v1.1