| OLD | NEW |
| (Empty) |
| 1 <html> | |
| 2 <head> | |
| 3 <title>Test media source config changes.</title> | |
| 4 </head> | |
| 5 <body onload="runTest();"> | |
| 6 <video controls></video> | |
| 7 <script src='eme_player_js/app_loader.js' type='text/javascript'></script> | |
| 8 <script type="text/javascript"> | |
| 9 var testConfig = new TestConfig(); | |
| 10 testConfig.loadQueryParams(); | |
| 11 testConfig.useMSE = '1'; | |
| 12 var runEncrypted = testConfig.runEncrypted == 1; | |
| 13 | |
| 14 var video = document.querySelector('video'); | |
| 15 var mediaType = 'video/webm; codecs="vorbis, vp8"'; | |
| 16 | |
| 17 var MEDIA_1 = 'bear-320x240.webm'; | |
| 18 var MEDIA_2 = 'bear-640x360.webm'; | |
| 19 if (runEncrypted) { | |
| 20 MEDIA_1 = 'bear-320x240-av-enc_av.webm'; | |
| 21 MEDIA_2 = 'bear-640x360-av-enc_av.webm'; | |
| 22 } | |
| 23 | |
| 24 var MEDIA_1_WIDTH = 320; | |
| 25 var MEDIA_1_HEIGHT = 240; | |
| 26 | |
| 27 var MEDIA_2_WIDTH = 640; | |
| 28 var MEDIA_2_HEIGHT = 360; | |
| 29 var MEDIA_2_LENGTH = 2.75; | |
| 30 | |
| 31 // The time in secs to append the second media source. | |
| 32 var APPEND_TIME = 1; | |
| 33 // DELTA is the time after APPEND_TIME where the second video dimensions | |
| 34 // are guaranteed to take effect. | |
| 35 var DELTA = 0.1; | |
| 36 // Append MEDIA_2 source at APPEND_TIME, so expected total duration is: | |
| 37 var TOTAL_DURATION = APPEND_TIME + MEDIA_2_LENGTH; | |
| 38 | |
| 39 function appendNextSource(mediaSource) { | |
| 40 console.log('Appending next media source at ' + APPEND_TIME + 'sec.'); | |
| 41 var xhr = new XMLHttpRequest(); | |
| 42 xhr.open("GET", MEDIA_2); | |
| 43 xhr.responseType = 'arraybuffer'; | |
| 44 xhr.addEventListener('load', function(e) { | |
| 45 var onUpdateEnd = function(e) { | |
| 46 console.log('Second buffer append ended.'); | |
| 47 srcBuffer.removeEventListener('updateend', onUpdateEnd); | |
| 48 mediaSource.endOfStream(); | |
| 49 if (!mediaSource.duration || | |
| 50 Math.abs(mediaSource.duration - TOTAL_DURATION) > DELTA) { | |
| 51 Utils.failTest('Unexpected mediaSource.duration = ' + | |
| 52 mediaSource.duration + ', expected duration = ' + | |
| 53 TOTAL_DURATION); | |
| 54 return; | |
| 55 } | |
| 56 video.play(); | |
| 57 }; | |
| 58 console.log('Appending next media source at ' + APPEND_TIME + 'sec.'); | |
| 59 var srcBuffer = mediaSource.sourceBuffers[0]; | |
| 60 srcBuffer.addEventListener('updateend', onUpdateEnd); | |
| 61 srcBuffer.timestampOffset = APPEND_TIME; | |
| 62 srcBuffer.appendBuffer(new Uint8Array(e.target.response)); | |
| 63 }); | |
| 64 xhr.send(); | |
| 65 } | |
| 66 | |
| 67 function onTimeUpdate() { | |
| 68 // crbug.com/246308 | |
| 69 //checkVideoProperties(); | |
| 70 | |
| 71 // Seek to APPEND_TIME because after a seek a timeUpdate event is fired | |
| 72 // before video width and height properties get updated. | |
| 73 if (video.currentTime < APPEND_TIME - DELTA) { | |
| 74 // Seek to save test execution time (about 1 secs) and to test seek | |
| 75 // on the first buffer. | |
| 76 video.currentTime = APPEND_TIME - DELTA; | |
| 77 } else if (video.currentTime > APPEND_TIME + DELTA) { | |
| 78 // Check video duration here to guarantee that second segment has been | |
| 79 // appended and video total duration is updated. | |
| 80 // Video duration is a float value so we check it within a range. | |
| 81 if (!video.duration || | |
| 82 Math.abs(video.duration - TOTAL_DURATION) > DELTA) { | |
| 83 Utils.failTest('Unexpected video.duration = ' + video.duration + | |
| 84 ', expected duration = ' + TOTAL_DURATION); | |
| 85 return; | |
| 86 } | |
| 87 | |
| 88 video.removeEventListener('timeupdate', onTimeUpdate); | |
| 89 video.removeEventListener('ended', Utils.failTest); | |
| 90 Utils.installTitleEventHandler(video, 'ended'); | |
| 91 // Seek to save test execution time and to test seek on second buffer. | |
| 92 video.currentTime = APPEND_TIME + MEDIA_2_LENGTH * 0.9; | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 function checkVideoProperties() { | |
| 97 if (video.currentTime <= APPEND_TIME) { | |
| 98 if (video.videoWidth != MEDIA_1_WIDTH || | |
| 99 video.videoHeight != MEDIA_1_HEIGHT) { | |
| 100 logVideoDimensions(); | |
| 101 Utils.failTest('Unexpected dimensions for first video segment.'); | |
| 102 return; | |
| 103 } | |
| 104 } else if (video.currentTime >= APPEND_TIME + DELTA) { | |
| 105 if (video.videoWidth != MEDIA_2_WIDTH || | |
| 106 video.videoHeight != MEDIA_2_HEIGHT) { | |
| 107 logVideoDimensions(); | |
| 108 Utils.failTest('Unexpected dimensions for second video segment.'); | |
| 109 return; | |
| 110 } | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 function logVideoDimensions() { | |
| 115 console.log('video.currentTime = ' + video.currentTime + | |
| 116 ', video dimensions = ' + video.videoWidth + 'x' + | |
| 117 video.videoHeight + '.'); | |
| 118 } | |
| 119 | |
| 120 function runTest() { | |
| 121 testConfig.mediaFile = MEDIA_1; | |
| 122 testConfig.mediaType = mediaType; | |
| 123 video.addEventListener('timeupdate', onTimeUpdate); | |
| 124 video.addEventListener('ended', Utils.failTest); | |
| 125 if (runEncrypted) { | |
| 126 var emePlayer = PlayerUtils.createPlayer(video, testConfig); | |
| 127 emePlayer.registerEventListeners(); | |
| 128 } | |
| 129 var mediaSource = MediaSourceUtils.loadMediaSource( | |
| 130 MEDIA_1, mediaType, appendNextSource); | |
| 131 video.src = window.URL.createObjectURL(mediaSource); | |
| 132 } | |
| 133 </script> | |
| 134 </body> | |
| 135 </html> | |
| OLD | NEW |