OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <script src="/w3c/resources/testharness.js"></script> |
| 5 <script src="/w3c/resources/testharnessreport.js"></script> |
| 6 <script src="mediasource-util.js"></script> |
| 7 </head> |
| 8 <body> |
| 9 <script> |
| 10 function verifyTrackProperties(trackType, track, expectedTrackInfo)
{ |
| 11 assert_equals(track.kind, expectedTrackInfo.kind, trackType + ".
kind"); |
| 12 assert_equals(track.label, expectedTrackInfo.label, trackType +
".label"); |
| 13 assert_equals(track.language, expectedTrackInfo.language, trackT
ype + ".language"); |
| 14 } |
| 15 |
| 16 function loadMediaAndVerifyAddedTracks(test, mediaElement, segmentIn
fo, sourceBuffer, mediaData, expectedAudioTrackInfo, expectedVideoTrackInfo, suc
cessCallback) |
| 17 { |
| 18 var initSegment = MediaSourceUtil.extractSegmentData(mediaData,
segmentInfo.init); |
| 19 test.expectEvent(sourceBuffer.audioTracks, "addtrack", "sourceBu
ffer.audioTracks addtrack event"); |
| 20 test.expectEvent(sourceBuffer.videoTracks, "addtrack", "sourceBu
ffer.videoTracks addtrack event"); |
| 21 test.expectEvent(mediaElement.audioTracks, "addtrack", "mediaEle
ment.audioTracks addtrack event"); |
| 22 test.expectEvent(mediaElement.videoTracks, "addtrack", "mediaEle
ment.videoTracks addtrack event"); |
| 23 test.expectEvent(mediaElement, "loadedmetadata", "loadedmetadata
done."); |
| 24 test.expectEvent(sourceBuffer, "updateend", "initSegment append
ended."); |
| 25 sourceBuffer.appendBuffer(initSegment); |
| 26 test.waitForExpectedEvents(function() |
| 27 { |
| 28 assert_equals(sourceBuffer.audioTracks.length, 1, "audioTrac
ks.length"); |
| 29 verifyTrackProperties("audio", sourceBuffer.audioTracks[0],
expectedAudioTrackInfo); |
| 30 assert_equals(sourceBuffer.audioTracks[0].sourceBuffer, sour
ceBuffer, "audioTrack.sourceBuffer"); |
| 31 // The first audio track is enabled by default. |
| 32 assert_true(sourceBuffer.audioTracks[0].enabled, "sourceBuff
er.audioTracks[0].enabled"); |
| 33 |
| 34 assert_equals(sourceBuffer.videoTracks.length, 1, "videoTrac
ks.length"); |
| 35 verifyTrackProperties("video", sourceBuffer.videoTracks[0],
expectedVideoTrackInfo); |
| 36 assert_equals(sourceBuffer.videoTracks[0].sourceBuffer, sour
ceBuffer, "videoTrack.sourceBuffer"); |
| 37 // The first video track is selected by default. |
| 38 assert_true(sourceBuffer.videoTracks[0].selected, "sourceBuf
fer.videoTracks[0].selected"); |
| 39 |
| 40 assert_not_equals(sourceBuffer.audioTracks[0].id, sourceBuff
er.videoTracks[0].id, "track ids must be unique"); |
| 41 |
| 42 assert_equals(mediaElement.videoTracks.length, 1, "videoTrac
ks.length"); |
| 43 assert_equals(mediaElement.videoTracks[0], sourceBuffer.vide
oTracks[0], "mediaElement.videoTrack == sourceBuffer.videoTrack"); |
| 44 |
| 45 assert_equals(mediaElement.audioTracks.length, 1, "audioTrac
ks.length"); |
| 46 assert_equals(mediaElement.audioTracks[0], sourceBuffer.audi
oTracks[0], "mediaElement.audioTrack == sourceBuffer.audioTrack"); |
| 47 |
| 48 successCallback(); |
| 49 }); |
| 50 } |
| 51 |
| 52 mediasource_testafterdataloaded(function(test, mediaElement, mediaSo
urce, segmentInfo, sourceBuffer, mediaData) |
| 53 { |
| 54 var expectedAudioTrackInfo = { kind: "main", label: "", language
: "" }; |
| 55 var expectedVideoTrackInfo = { kind: "main", label: "", language
: "" }; |
| 56 |
| 57 loadMediaAndVerifyAddedTracks(test, mediaElement, segmentInfo, s
ourceBuffer, mediaData, expectedAudioTrackInfo, expectedVideoTrackInfo, test.ste
p_func(function () |
| 58 { |
| 59 // Now append the same exact init segment again. This should
succeed, but no new tracks should |
| 60 // be added to the SourceBuffer or MediaElement. |
| 61 test.failOnEvent(sourceBuffer.audioTracks, "addtrack", "Unex
pected addtrack event on sourceBuffer.audioTracks for second init segment"); |
| 62 test.failOnEvent(sourceBuffer.videoTracks, "addtrack", "Unex
pected addtrack event on sourceBuffer.videoTracks for second init segment"); |
| 63 test.failOnEvent(mediaElement.audioTracks, "addtrack", "Unex
pected addtrack event on mediaElement.audioTracks for second init segment"); |
| 64 test.failOnEvent(mediaElement.videoTracks, "addtrack", "Unex
pected addtrack event on mediaElement.videoTracks for second init segment"); |
| 65 |
| 66 test.expectEvent(sourceBuffer, "updateend", "InitSegment app
end ended."); |
| 67 var initSegment = MediaSourceUtil.extractSegmentData(mediaDa
ta, segmentInfo.init); |
| 68 sourceBuffer.appendBuffer(initSegment); |
| 69 test.waitForExpectedEvents(function() |
| 70 { |
| 71 assert_equals(mediaElement.audioTracks.length, 1, "media
Element.audioTracks.length"); |
| 72 assert_equals(mediaElement.videoTracks.length, 1, "media
Element.videoTracks.length"); |
| 73 assert_equals(sourceBuffer.audioTracks.length, 1, "sourc
eBuffer.audioTracks.length"); |
| 74 assert_equals(sourceBuffer.videoTracks.length, 1, "sourc
eBuffer.videoTracks.length"); |
| 75 test.done(); |
| 76 }); |
| 77 })); |
| 78 }, "Same init segment appended twice"); |
| 79 |
| 80 mediasource_testafterdataloaded(function(test, mediaElement, mediaSo
urce, segmentInfo, sourceBuffer, mediaData) |
| 81 { |
| 82 var originalTrackDefaults = [ |
| 83 new TrackDefault("audio", "audio-language", "audio-label", [
"main"], "2"), |
| 84 new TrackDefault("video", "video-language", "video-label", [
"main"], "1") |
| 85 ]; |
| 86 var trackDefaultList = new TrackDefaultList(originalTrackDefault
s.slice()); |
| 87 sourceBuffer.trackDefaults = trackDefaultList; |
| 88 |
| 89 var expectedAudioTrackInfo = { kind: "main", label: "audio-label
", language: "audio-language" }; |
| 90 var expectedVideoTrackInfo = { kind: "main", label: "video-label
", language: "video-language" }; |
| 91 |
| 92 loadMediaAndVerifyAddedTracks(test, mediaElement, segmentInfo, s
ourceBuffer, mediaData, expectedAudioTrackInfo, expectedVideoTrackInfo, test.ste
p_func_done()); |
| 93 }, "Track defaults processing in the init segment algorithm (explici
t bytestream ids)"); |
| 94 |
| 95 mediasource_testafterdataloaded(function(test, mediaElement, mediaSo
urce, segmentInfo, sourceBuffer, mediaData) |
| 96 { |
| 97 var originalTrackDefaults = [ |
| 98 new TrackDefault("audio", "audio-language", "audio-label", [
"main"], ""), |
| 99 new TrackDefault("video", "video-language", "video-label", [
"main"], "") |
| 100 ]; |
| 101 var trackDefaultList = new TrackDefaultList(originalTrackDefault
s.slice()); |
| 102 sourceBuffer.trackDefaults = trackDefaultList; |
| 103 |
| 104 var expectedAudioTrackInfo = { kind: "main", label: "audio-label
", language: "audio-language" }; |
| 105 var expectedVideoTrackInfo = { kind: "main", label: "video-label
", language: "video-language" }; |
| 106 |
| 107 loadMediaAndVerifyAddedTracks(test, mediaElement, segmentInfo, s
ourceBuffer, mediaData, expectedAudioTrackInfo, expectedVideoTrackInfo, test.ste
p_func_done()); |
| 108 }, "Track defaults processing in the init segment algorithm (no byte
stream ids)"); |
| 109 |
| 110 </script> |
| 111 </body> |
| 112 </html> |
OLD | NEW |