1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
// Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang).
// Extract & return the resolution string from a filename, if any.
function resolutionFromFilename(filename)
{
resolution = filename.replace(/^.*[^0-9]([0-9]+x[0-9]+)[^0-9].*$/, "$1");
if (resolution != filename) {
return resolution;
}
return "";
}
function appendBuffer(test, sourceBuffer, data)
{
test.expectEvent(sourceBuffer, "update");
test.expectEvent(sourceBuffer, "updateend");
sourceBuffer.appendBuffer(data);
}
function mediaSourceConfigChangeTest(directory, idA, idB, description)
{
var manifestFilenameA = directory + "/test-" + idA + "-manifest.json";
var manifestFilenameB = directory + "/test-" + idB + "-manifest.json";
mediasource_test(function(test, mediaElement, mediaSource)
{
mediaElement.pause();
mediaElement.addEventListener('error', test.unreached_func("Unexpected event 'error'"));
var expectResizeEvents = resolutionFromFilename(manifestFilenameA) != resolutionFromFilename(manifestFilenameB);
var expectedResizeEventCount = 0;
MediaSourceUtil.fetchManifestAndData(test, manifestFilenameA, function(typeA, dataA)
{
MediaSourceUtil.fetchManifestAndData(test, manifestFilenameB, function(typeB, dataB)
{
assert_equals(typeA, typeB, "Media format types match");
var sourceBuffer = mediaSource.addSourceBuffer(typeA);
appendBuffer(test, sourceBuffer, dataA);
++expectedResizeEventCount;
test.waitForExpectedEvents(function()
{
// Add the second buffer starting at 0.5 second.
sourceBuffer.timestampOffset = 0.5;
appendBuffer(test, sourceBuffer, dataB);
++expectedResizeEventCount;
});
test.waitForExpectedEvents(function()
{
// Add the first buffer starting at 1 second.
sourceBuffer.timestampOffset = 1;
appendBuffer(test, sourceBuffer, dataA);
++expectedResizeEventCount;
});
test.waitForExpectedEvents(function()
{
// Add the second buffer starting at 1.5 second.
sourceBuffer.timestampOffset = 1.5;
appendBuffer(test, sourceBuffer, dataB);
++expectedResizeEventCount;
});
test.waitForExpectedEvents(function()
{
assert_false(sourceBuffer.updating, "updating");
// Truncate the presentation to a duration of 2 seconds.
sourceBuffer.remove(2, Infinity);
assert_true(sourceBuffer.updating, "updating");
test.expectEvent(sourceBuffer, 'updatestart', 'sourceBuffer');
test.expectEvent(sourceBuffer, 'update', 'sourceBuffer');
test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
});
test.waitForExpectedEvents(function()
{
assert_false(sourceBuffer.updating, "updating");
assert_greater_than(mediaSource.duration, 2, "duration");
// Truncate the presentation to a duration of 2 seconds.
mediaSource.duration = 2;
test.expectEvent(mediaElement, "durationchange");
});
test.waitForExpectedEvents(function()
{
assert_false(sourceBuffer.updating, "updating");
mediaSource.endOfStream();
assert_false(sourceBuffer.updating, "updating");
if (expectResizeEvents) {
for (var i = 0; i < expectedResizeEventCount; ++i) {
test.expectEvent(mediaElement, "resize");
}
}
test.expectEvent(mediaElement, "ended");
mediaElement.play();
});
test.waitForExpectedEvents(function() {
test.done();
});
});
});
}, description);
};
|