зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1090523 - Add more logging to help debug infrequent EME/MSE failure. r=edwin
This commit is contained in:
Родитель
82ca72febb
Коммит
4cc292fee5
|
@ -50,14 +50,34 @@ function HexToBase64(hex)
|
|||
return window.btoa(bin).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
||||
}
|
||||
|
||||
function TimeStamp(token) {
|
||||
function pad(x) {
|
||||
return (x < 10) ? "0" + x : x;
|
||||
}
|
||||
var now = new Date();
|
||||
var ms = now.getMilliseconds();
|
||||
var time = "[" +
|
||||
pad(now.getHours()) + ":" +
|
||||
pad(now.getMinutes()) + ":" +
|
||||
pad(now.getSeconds()) + "." +
|
||||
ms +
|
||||
"]" +
|
||||
(ms < 10 ? " " : (ms < 100 ? " " : ""));
|
||||
return token ? (time + " " + token) : time;
|
||||
}
|
||||
|
||||
function Log(token, msg) {
|
||||
info(TimeStamp(token) + " " + msg);
|
||||
}
|
||||
|
||||
function UpdateSessionFunc(test, token) {
|
||||
return function(ev) {
|
||||
var msgStr = ArrayBufferToString(ev.message);
|
||||
var msg = JSON.parse(msgStr);
|
||||
|
||||
info(token + " got message from CDM: " + msgStr);
|
||||
is(msg.type, test.sessionType, token + " key session type should match");
|
||||
ok(msg.kids, token + " message event should contain key ID array");
|
||||
Log(token, "got message from CDM: " + msgStr);
|
||||
is(msg.type, test.sessionType, TimeStamp(token) + " key session type should match");
|
||||
ok(msg.kids, TimeStamp(token) + " message event should contain key ID array");
|
||||
|
||||
var outKeys = [];
|
||||
|
||||
|
@ -67,7 +87,7 @@ function UpdateSessionFunc(test, token) {
|
|||
var key = test.keys[idHex];
|
||||
|
||||
if (key) {
|
||||
info(token + " found key " + key + " for key id " + idHex);
|
||||
Log(token, "found key " + key + " for key id " + idHex);
|
||||
outKeys.push({
|
||||
"kty":"oct",
|
||||
"alg":"A128KW",
|
||||
|
@ -75,7 +95,7 @@ function UpdateSessionFunc(test, token) {
|
|||
"k":HexToBase64(key)
|
||||
});
|
||||
} else {
|
||||
bail(token + " Couldn't find key for key id " + idHex);
|
||||
bail(token + " couldn't find key for key id " + idHex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,15 +103,15 @@ function UpdateSessionFunc(test, token) {
|
|||
"keys" : outKeys,
|
||||
"type" : msg.type
|
||||
});
|
||||
info(token + " sending update message to CDM: " + update);
|
||||
Log(token, "sending update message to CDM: " + update);
|
||||
|
||||
ev.target.update(StringToArrayBuffer(update)).then(function() {
|
||||
info(token + " MediaKeySession update ok!");
|
||||
Log(token, "MediaKeySession update ok!");
|
||||
}, bail(token + " MediaKeySession update failed"));
|
||||
}
|
||||
}
|
||||
|
||||
function PlayFragmented(test, elem)
|
||||
function PlayFragmented(test, elem, token)
|
||||
{
|
||||
return new Promise(function(resolve, reject) {
|
||||
var ms = new MediaSource();
|
||||
|
@ -102,6 +122,7 @@ function PlayFragmented(test, elem)
|
|||
|
||||
function addNextFragment() {
|
||||
if (curFragment >= test.fragments.length) {
|
||||
Log(token, "addNextFragment() end of stream");
|
||||
ms.endOfStream();
|
||||
resolve();
|
||||
return;
|
||||
|
@ -114,18 +135,19 @@ function PlayFragmented(test, elem)
|
|||
req.responseType = "arraybuffer";
|
||||
|
||||
req.addEventListener("load", function() {
|
||||
info("fetch of " + fragmentFile + " complete");
|
||||
Log(token, "fetch of " + fragmentFile + " complete, appending");
|
||||
sb.appendBuffer(new Uint8Array(req.response));
|
||||
});
|
||||
|
||||
req.addEventListener("error", bail("Error fetching " + fragmentFile));
|
||||
req.addEventListener("abort", bail("Aborted fetching " + fragmentFile));
|
||||
req.addEventListener("error", bail(token + " error fetching " + fragmentFile));
|
||||
req.addEventListener("abort", bail(token + " aborted fetching " + fragmentFile));
|
||||
|
||||
info("fetching resource " + fragmentFile);
|
||||
Log(token, "addNextFragment() fetching next fragment " + fragmentFile);
|
||||
req.send(null);
|
||||
}
|
||||
|
||||
ms.addEventListener("sourceopen", function () {
|
||||
Log(token, "sourceopen");
|
||||
sb = ms.addSourceBuffer(test.type);
|
||||
sb.addEventListener("updateend", addNextFragment);
|
||||
|
||||
|
@ -137,10 +159,10 @@ function PlayFragmented(test, elem)
|
|||
// Returns a promise that is resovled when the media element is ready to have
|
||||
// its play() function called; when it's loaded MSE fragments, or once the load
|
||||
// has started for non-MSE video.
|
||||
function LoadTest(test, elem)
|
||||
function LoadTest(test, elem, token)
|
||||
{
|
||||
if (test.fragments) {
|
||||
return PlayFragmented(test, elem);
|
||||
return PlayFragmented(test, elem, token);
|
||||
}
|
||||
|
||||
// This file isn't fragmented; set the media source normally.
|
||||
|
@ -155,10 +177,12 @@ function SetupEME(test, token, params)
|
|||
var v = document.createElement("video");
|
||||
|
||||
// Log events dispatched to make debugging easier...
|
||||
["loadstart", "loadedmetadata", "loadeddata", "ended",
|
||||
"play", "canplay", "playing", "canplaythrough"].forEach(function (e) {
|
||||
[ "canplay", "canplaythrough", "ended", "error", "loadeddata",
|
||||
"loadedmetadata", "loadstart", "pause", "play", "playing", "progress",
|
||||
"stalled", "suspend", "waiting",
|
||||
].forEach(function (e) {
|
||||
v.addEventListener(e, function(event) {
|
||||
info(token + " " + e);
|
||||
Log(token, "" + e);
|
||||
}, false);
|
||||
});
|
||||
|
||||
|
@ -167,13 +191,13 @@ function SetupEME(test, token, params)
|
|||
: bail(token + " Failed to set MediaKeys on <video> element");
|
||||
|
||||
v.addEventListener("encrypted", function(ev) {
|
||||
info(token + " got encrypted event");
|
||||
Log(token, "got encrypted event");
|
||||
MediaKeys.create(KEYSYSTEM_TYPE).then(function(mediaKeys) {
|
||||
info(token + " created MediaKeys object ok");
|
||||
Log(token, "created MediaKeys object ok");
|
||||
mediaKeys.sessions = [];
|
||||
return v.setMediaKeys(mediaKeys);
|
||||
}, bail("failed to create MediaKeys object")).then(function() {
|
||||
info(token + " set MediaKeys on <video> element ok");
|
||||
Log(token, "set MediaKeys on <video> element ok");
|
||||
|
||||
var session = v.mediaKeys.createSession(test.sessionType);
|
||||
if (params && params.onsessioncreated) {
|
||||
|
|
|
@ -34,13 +34,13 @@ function startTest(test, token)
|
|||
} catch (ex) {
|
||||
threwError = true;
|
||||
}
|
||||
ok(threwError, token + " - Should throw an error when trying to draw EME video to canvas.");
|
||||
ok(threwError, TimeStamp(token) + " - Should throw an error when trying to draw EME video to canvas.");
|
||||
manager.finished(token);
|
||||
});
|
||||
|
||||
v.addEventListener("error", bail(token + " got error event"));
|
||||
|
||||
LoadTest(test, v);
|
||||
LoadTest(test, v, token);
|
||||
}
|
||||
|
||||
function beginTest() {
|
||||
|
|
|
@ -16,7 +16,7 @@ var manager = new MediaTestManager;
|
|||
function KeysChangeFunc(session, keys, token) {
|
||||
session.keyIdsReceived = [];
|
||||
for (var keyid in keys) {
|
||||
info("Set " + keyid + " to false in session.keyIdsReceived");
|
||||
Log(token, "Set " + keyid + " to false in session.keyIdsReceived");
|
||||
session.keyIdsReceived[keyid] = false;
|
||||
}
|
||||
return function(ev) {
|
||||
|
@ -25,7 +25,7 @@ function KeysChangeFunc(session, keys, token) {
|
|||
session.getUsableKeyIds().then(function(keyIds) {
|
||||
for (var k = 0; k < keyIds.length; k++) {
|
||||
var kid = Base64ToHex(window.btoa(ArrayBufferToString(keyIds[k])));
|
||||
ok(kid in session.keyIdsReceived, token + " session.keyIdsReceived contained " + kid + " as expected.");
|
||||
ok(kid in session.keyIdsReceived, TimeStamp(token) + " session.keyIdsReceived contained " + kid + " as expected.");
|
||||
session.keyIdsReceived[kid] = true;
|
||||
}
|
||||
}, bail("Failed to get keyIds"));
|
||||
|
@ -52,31 +52,31 @@ function startTest(test, token)
|
|||
|
||||
v.addEventListener("encrypted", function(ev) {
|
||||
ok(MediaKeys.isTypeSupported(KEYSYSTEM_TYPE, ev.initDataType, test.type),
|
||||
token + " MediaKeys should support this keysystem");
|
||||
TimeStamp(token) + " MediaKeys should support this keysystem");
|
||||
gotEncrypted = true;
|
||||
});
|
||||
|
||||
v.addEventListener("playing", function () { gotPlaying = true; });
|
||||
|
||||
v.addEventListener("ended", function(ev) {
|
||||
ok(true, token + " got ended event");
|
||||
ok(true, TimeStamp(token) + " got ended event");
|
||||
|
||||
ok(gotEncrypted, token + " encrypted event should have fired");
|
||||
ok(gotPlaying, token + " playing event should have fired");
|
||||
ok(gotEncrypted, TimeStamp(token) + " encrypted event should have fired");
|
||||
ok(gotPlaying, TimeStamp(token) + " playing event should have fired");
|
||||
|
||||
ok(Math.abs(test.duration - v.duration) < 0.1,
|
||||
token + " Duration of video should be corrrect");
|
||||
TimeStamp(token) + " Duration of video should be corrrect");
|
||||
ok(Math.abs(test.duration - v.currentTime) < 0.1,
|
||||
token + " Current time should be same as duration");
|
||||
TimeStamp(token) + " Current time should be same as duration");
|
||||
|
||||
// Verify all sessions had all keys went sent the to the CDM usable, and thus
|
||||
// that we received keyschange event(s).
|
||||
is(sessions.length, 1, token + " should have 1 session");
|
||||
is(sessions.length, 1, TimeStamp(token) + " should have 1 session");
|
||||
for (var i = 0; i < sessions.length; i++) {
|
||||
var session = sessions[i];
|
||||
ok(session.gotKeysChanged, token + " should have received at least one keychange event");
|
||||
ok(session.gotKeysChanged, TimeStamp(token) + " should have received at least one keychange event");
|
||||
for (var kid in session.keyIdsReceived) {
|
||||
ok(session.keyIdsReceived[kid], token + " key with id " + kid + " was usable as expected");
|
||||
ok(session.keyIdsReceived[kid], TimeStamp(token) + " key with id " + kid + " was usable as expected");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ function startTest(test, token)
|
|||
|
||||
v.addEventListener("error", bail(token + " got error event"));
|
||||
|
||||
LoadTest(test, v).then(function(){v.play();}, bail(token + " failed to load"));
|
||||
LoadTest(test, v, token).then(function(){v.play();}, bail(token + " failed to load"));
|
||||
}
|
||||
|
||||
function testIsTypeSupported()
|
||||
|
|
|
@ -22,7 +22,7 @@ function startTest(test, token)
|
|||
// Case 1. setting MediaKeys on an element captured by MediaElementSource should fail.
|
||||
var case1token = token + "_case1";
|
||||
var setKeysFailed = function() {
|
||||
ok(true, case1token + " setMediaKeys failed as expected.");
|
||||
ok(true, TimeStamp(case1token) + " setMediaKeys failed as expected.");
|
||||
manager.finished(case1token);
|
||||
};
|
||||
var v1 = SetupEME(test, case1token, { onSetKeysFail: setKeysFailed });
|
||||
|
@ -31,10 +31,10 @@ function startTest(test, token)
|
|||
v1.preload = "auto"; // Required due to "canplay" not firing for MSE unless we do this.
|
||||
v1.addEventListener("error", bail(case1token + " got error event"));
|
||||
v1.addEventListener("canplay", function(ev) {
|
||||
ok(false, case1token + " should never reach canplay, as setMediaKeys should fail");
|
||||
ok(false, TimeStamp(case1token) + " should never reach canplay, as setMediaKeys should fail");
|
||||
});
|
||||
manager.started(case1token);
|
||||
LoadTest(test, v1);
|
||||
LoadTest(test, v1, case1token);
|
||||
|
||||
|
||||
// Case 2. creating a MediaElementSource on a media element with a MediaKeys should fail.
|
||||
|
@ -55,7 +55,7 @@ function startTest(test, token)
|
|||
manager.finished(case2token);
|
||||
});
|
||||
manager.started(case2token);
|
||||
LoadTest(test, v2);
|
||||
LoadTest(test, v2, case2token);
|
||||
|
||||
|
||||
// Case 3. capturing a media element with mozCaptureStream that has a MediaKeys should fail.
|
||||
|
@ -64,18 +64,18 @@ function startTest(test, token)
|
|||
v3.preload = "auto"; // Required due to "canplay" not firing for MSE unless we do this.
|
||||
v3.addEventListener("error", bail(case3token + " got error event"));
|
||||
v3.addEventListener("canplay", function(ev) {
|
||||
ok(true, case3token + " should reach canplay");
|
||||
ok(true, TimeStamp(case3token) + " should reach canplay");
|
||||
var threw = false;
|
||||
try {
|
||||
var stream = v3.mozCaptureStreamUntilEnded();
|
||||
} catch (e) {
|
||||
threw = true;
|
||||
}
|
||||
ok(threw, "Should throw an error calling mozCaptureStreamUntilEnded an EME video.");
|
||||
ok(threw, TimeStamp(case3token) + " Should throw an error calling mozCaptureStreamUntilEnded an EME video.");
|
||||
manager.finished(case3token);
|
||||
});
|
||||
manager.started(case3token);
|
||||
LoadTest(test, v3);
|
||||
LoadTest(test, v3, case3token);
|
||||
}
|
||||
|
||||
function beginTest() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче