| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 1 | <!DOCTYPE html> |
| Matt Wolenetz | 74803c6 | 2016-08-19 01:46:40 | [diff] [blame] | 2 | <!-- Copyright © 2016 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). --> |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 3 | <html> |
| 4 | <head> |
| Aaron Colwell | aa3c90b | 2014-08-04 17:58:37 | [diff] [blame] | 5 | <title>Test MediaSource behavior when a seek is requested while another seek is pending.</title> |
| Aaron Colwell | 06f8ec2 | 2014-03-07 18:09:47 | [diff] [blame] | 6 | <script src="/resources/testharness.js"></script> |
| 7 | <script src="/resources/testharnessreport.js"></script> |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 8 | <script src="mediasource-util.js"></script> |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 9 | </head> |
| 10 | <body> |
| 11 | <div id="log"></div> |
| 12 | <script> |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 13 | 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 Colwell | 795cb53 | 2014-08-07 16:35:39 | [diff] [blame] | 19 | var segmentIndex = 2; |
| 20 | var secondSegmentInfo = segmentInfo.media[segmentIndex]; |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 21 | |
| 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 Avenard | a5a3baf | 2016-08-25 12:57:03 | [diff] [blame] | 34 | mediaElement.currentTime = Math.max(secondSegmentInfo.timev, secondSegmentInfo.timea); |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 35 | 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 Colwell | 795cb53 | 2014-08-07 16:35:39 | [diff] [blame] | 48 | // Append media data for the current position until the element starts playing. |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 49 | test.expectEvent(mediaElement, 'seeked', 'mediaElement finished seek'); |
| 50 | test.expectEvent(mediaElement, 'playing', 'mediaElement playing'); |
| Aaron Colwell | 795cb53 | 2014-08-07 16:35:39 | [diff] [blame] | 51 | |
| 52 | MediaSourceUtil.appendUntilEventFires(test, mediaElement, 'playing', sourceBuffer, mediaData, segmentInfo, segmentIndex); |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 53 | }); |
| 54 | |
| 55 | test.waitForExpectedEvents(function() |
| 56 | { |
| Jean-Yves Avenard | 1a00450 | 2016-08-25 12:57:04 | [diff] [blame] | 57 | 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 Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 73 | }); |
| 74 | |
| 75 | test.waitForExpectedEvents(function() |
| 76 | { |
| Jean-Yves Avenard | 20c994f | 2016-08-25 12:57:05 | [diff] [blame] | 77 | // 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 Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 87 | test.done(); |
| 88 | }); |
| 89 | |
| James Graham | 1da6470 | 2015-05-01 12:22:22 | [diff] [blame] | 90 | }, 'Test seeking to a new location before transitioning beyond HAVE_METADATA.'); |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 91 | |
| 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 Colwell | 795cb53 | 2014-08-07 16:35:39 | [diff] [blame] | 100 | var segmentIndex = 4; |
| 101 | var thirdSegmentInfo = segmentInfo.media[segmentIndex]; |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 102 | |
| 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 Avenard | a5a3baf | 2016-08-25 12:57:03 | [diff] [blame] | 121 | mediaElement.currentTime = Math.max(secondSegmentInfo.timev, secondSegmentInfo.timea); |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 122 | 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 Avenard | a5a3baf | 2016-08-25 12:57:03 | [diff] [blame] | 132 | mediaElement.currentTime = Math.max(thirdSegmentInfo.timev, thirdSegmentInfo.timea); |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 133 | 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 Avenard | a5a3baf | 2016-08-25 12:57:03 | [diff] [blame] | 142 | // 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 Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 144 | |
| 145 | // Append media data for the second seek position. |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 146 | test.expectEvent(mediaElement, 'seeked', 'mediaElement finished seek'); |
| Aaron Colwell | 795cb53 | 2014-08-07 16:35:39 | [diff] [blame] | 147 | MediaSourceUtil.appendUntilEventFires(test, mediaElement, 'seeked', sourceBuffer, mediaData, segmentInfo, segmentIndex); |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 148 | }); |
| 149 | |
| 150 | test.waitForExpectedEvents(function() |
| 151 | { |
| 152 | assert_false(mediaElement.seeking, 'mediaElement is no longer seeking'); |
| 153 | |
| Jean-Yves Avenard | 1a00450 | 2016-08-25 12:57:04 | [diff] [blame] | 154 | 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 Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 170 | }); |
| 171 | |
| 172 | test.waitForExpectedEvents(function() |
| 173 | { |
| Jean-Yves Avenard | 20c994f | 2016-08-25 12:57:05 | [diff] [blame] | 174 | // 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 Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 184 | test.done(); |
| 185 | }); |
| James Graham | 1da6470 | 2015-05-01 12:22:22 | [diff] [blame] | 186 | }, 'Test seeking to a new location during a pending seek.'); |
| Aaron Colwell | c6841a0 | 2014-03-07 01:37:56 | [diff] [blame] | 187 | </script> |
| 188 | </body> |
| 189 | </html> |