blob: 60c5eec1c76650b73fc15c23ab959b9e78efd140 [file] [log] [blame]
Aaron Colwellc6841a02014-03-07 01:37:561<!DOCTYPE html>
Matt Wolenetz74803c62016-08-19 01:46:402<!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
Aaron Colwellc6841a02014-03-07 01:37:563<html>
4 <head>
Aaron Colwellaa3c90b2014-08-04 17:58:375 <title>Test MediaSource behavior when a seek is requested while another seek is pending.</title>
Aaron Colwell06f8ec22014-03-07 18:09:476 <script src="/resources/testharness.js"></script>
7 <script src="/resources/testharnessreport.js"></script>
Aaron Colwellc6841a02014-03-07 01:37:568 <script src="mediasource-util.js"></script>
Aaron Colwellc6841a02014-03-07 01:37:569 </head>
10 <body>
11 <div id="log"></div>
12 <script>
Aaron Colwellc6841a02014-03-07 01:37:5613 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
14 {
15 mediaElement.play();
16
17 var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
18 var firstSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);
Aaron Colwell795cb532014-08-07 16:35:3919 var segmentIndex = 2;
20 var secondSegmentInfo = segmentInfo.media[segmentIndex];
Aaron Colwellc6841a02014-03-07 01:37:5621
22 // Append the initialization segment to trigger a transition to HAVE_METADATA.
23 test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
24 test.expectEvent(mediaElement, 'loadedmetadata', 'Reached HAVE_METADATA');
25 sourceBuffer.appendBuffer(initSegment);
26
27 test.waitForExpectedEvents(function()
28 {
29 assert_false(mediaElement.seeking, 'mediaElement is not seeking');
30 assert_equals(mediaElement.readyState, mediaElement.HAVE_METADATA, 'Still in HAVE_METADATA');
31
32 // Seek to a new position before letting the initial seek to 0 completes.
33 test.expectEvent(mediaElement, 'seeking', 'mediaElement');
Jean-Yves Avenarda5a3baf2016-08-25 12:57:0334 mediaElement.currentTime = Math.max(secondSegmentInfo.timev, secondSegmentInfo.timea);
Aaron Colwellc6841a02014-03-07 01:37:5635 assert_true(mediaElement.seeking, 'mediaElement is seeking');
36
37 // Append media data for time 0.
38 test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
39 sourceBuffer.appendBuffer(firstSegment);
40 });
41
42 test.waitForExpectedEvents(function()
43 {
44 // Verify that the media data didn't trigger a 'seeking' event or a transition beyond HAVE_METADATA.
45 assert_true(mediaElement.seeking, 'mediaElement is still seeking');
46 assert_equals(mediaElement.readyState, mediaElement.HAVE_METADATA, 'Still in HAVE_METADATA');
47
Aaron Colwell795cb532014-08-07 16:35:3948 // Append media data for the current position until the element starts playing.
Aaron Colwellc6841a02014-03-07 01:37:5649 test.expectEvent(mediaElement, 'seeked', 'mediaElement finished seek');
50 test.expectEvent(mediaElement, 'playing', 'mediaElement playing');
Aaron Colwell795cb532014-08-07 16:35:3951
52 MediaSourceUtil.appendUntilEventFires(test, mediaElement, 'playing', sourceBuffer, mediaData, segmentInfo, segmentIndex);
Aaron Colwellc6841a02014-03-07 01:37:5653 });
54
55 test.waitForExpectedEvents(function()
56 {
Jean-Yves Avenard1a004502016-08-25 12:57:0457 if (sourceBuffer.updating)
58 {
59 // The event playing was fired prior to the appendBuffer completing.
60 test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
61 test.waitForExpectedEvents(function()
62 {
63 assert_false(sourceBuffer.updating, 'append have compleded');
64 test.expectEvent(mediaSource, 'sourceended', 'mediaSource ended');
65 mediaSource.endOfStream();
66 });
67 }
68 else
69 {
70 test.expectEvent(mediaSource, 'sourceended', 'mediaSource ended');
71 mediaSource.endOfStream();
72 }
Aaron Colwellc6841a02014-03-07 01:37:5673 });
74
75 test.waitForExpectedEvents(function()
76 {
Jean-Yves Avenard20c994f2016-08-25 12:57:0577 // Note: we just completed the seek. However, we only have less than a second worth of data to play. It is possible that
78 // playback has reached the end since the seek completed.
79 if (!mediaElement.paused)
80 {
81 assert_greater_than_equal(mediaElement.readyState, mediaElement.HAVE_CURRENT_DATA, 'Greater or equal than HAVE_CURRENT_DATA');
82 }
83 else
84 {
85 assert_true(mediaElement.ended);
86 }
Aaron Colwellc6841a02014-03-07 01:37:5687 test.done();
88 });
89
James Graham1da64702015-05-01 12:22:2290 }, 'Test seeking to a new location before transitioning beyond HAVE_METADATA.');
Aaron Colwellc6841a02014-03-07 01:37:5691
92 mediasource_testafterdataloaded(function(test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData)
93 {
94 mediaElement.play();
95
96 var initSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
97 var firstSegment = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);
98 var secondSegmentInfo = segmentInfo.media[2];
99 var secondSegment = MediaSourceUtil.extractSegmentData(mediaData, secondSegmentInfo);
Aaron Colwell795cb532014-08-07 16:35:39100 var segmentIndex = 4;
101 var thirdSegmentInfo = segmentInfo.media[segmentIndex];
Aaron Colwellc6841a02014-03-07 01:37:56102
103 // Append the initialization segment to trigger a transition to HAVE_METADATA.
104 test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
105 test.expectEvent(mediaElement, 'loadedmetadata', 'Reached HAVE_METADATA');
106 sourceBuffer.appendBuffer(initSegment);
107
108 test.waitForExpectedEvents(function()
109 {
110 test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
111 test.expectEvent(mediaElement, 'playing', 'mediaElement playing');
112 sourceBuffer.appendBuffer(firstSegment);
113 });
114
115 test.waitForExpectedEvents(function()
116 {
117 assert_greater_than(mediaElement.readyState, mediaElement.HAVE_CURRENT_DATA, 'Greater than HAVE_CURRENT_DATA');
118
119 // Seek to a new position.
120 test.expectEvent(mediaElement, 'seeking', 'mediaElement');
Jean-Yves Avenarda5a3baf2016-08-25 12:57:03121 mediaElement.currentTime = Math.max(secondSegmentInfo.timev, secondSegmentInfo.timea);
Aaron Colwellc6841a02014-03-07 01:37:56122 assert_true(mediaElement.seeking, 'mediaElement is seeking');
123
124 });
125
126 test.waitForExpectedEvents(function()
127 {
128 assert_true(mediaElement.seeking, 'mediaElement is still seeking');
129
130 // Seek to a second position while the first seek is still pending.
131 test.expectEvent(mediaElement, 'seeking', 'mediaElement');
Jean-Yves Avenarda5a3baf2016-08-25 12:57:03132 mediaElement.currentTime = Math.max(thirdSegmentInfo.timev, thirdSegmentInfo.timea);
Aaron Colwellc6841a02014-03-07 01:37:56133 assert_true(mediaElement.seeking, 'mediaElement is seeking');
134
135 // Append media data for the first seek position.
136 test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
137 sourceBuffer.appendBuffer(secondSegment);
138 });
139
140 test.waitForExpectedEvents(function()
141 {
Jean-Yves Avenarda5a3baf2016-08-25 12:57:03142 // Note that we can't assume that the element is still seeking
143 // when the seeking event is fired as the operation is asynchronous.
Aaron Colwellc6841a02014-03-07 01:37:56144
145 // Append media data for the second seek position.
Aaron Colwellc6841a02014-03-07 01:37:56146 test.expectEvent(mediaElement, 'seeked', 'mediaElement finished seek');
Aaron Colwell795cb532014-08-07 16:35:39147 MediaSourceUtil.appendUntilEventFires(test, mediaElement, 'seeked', sourceBuffer, mediaData, segmentInfo, segmentIndex);
Aaron Colwellc6841a02014-03-07 01:37:56148 });
149
150 test.waitForExpectedEvents(function()
151 {
152 assert_false(mediaElement.seeking, 'mediaElement is no longer seeking');
153
Jean-Yves Avenard1a004502016-08-25 12:57:04154 if (sourceBuffer.updating)
155 {
156 // The event seeked was fired prior to the appendBuffer completing.
157 test.expectEvent(sourceBuffer, 'updateend', 'sourceBuffer');
158 test.waitForExpectedEvents(function()
159 {
160 assert_false(sourceBuffer.updating, 'append have compleded');
161 test.expectEvent(mediaSource, 'sourceended', 'mediaSource ended');
162 mediaSource.endOfStream();
163 });
164 }
165 else
166 {
167 test.expectEvent(mediaSource, 'sourceended', 'mediaSource ended');
168 mediaSource.endOfStream();
169 }
Aaron Colwellc6841a02014-03-07 01:37:56170 });
171
172 test.waitForExpectedEvents(function()
173 {
Jean-Yves Avenard20c994f2016-08-25 12:57:05174 // Note: we just completed the seek. However, we only have less than a second worth of data to play. It is possible that
175 // playback has reached the end since the seek completed.
176 if (!mediaElement.paused)
177 {
178 assert_greater_than_equal(mediaElement.readyState, mediaElement.HAVE_CURRENT_DATA, 'Greater or equal than HAVE_CURRENT_DATA');
179 }
180 else
181 {
182 assert_true(mediaElement.ended);
183 }
Aaron Colwellc6841a02014-03-07 01:37:56184 test.done();
185 });
James Graham1da64702015-05-01 12:22:22186 }, 'Test seeking to a new location during a pending seek.');
Aaron Colwellc6841a02014-03-07 01:37:56187 </script>
188 </body>
189</html>