8478511a by David LaPalomento

Clean up example

Get rid of a whole bunch of intermediate copies when shuffling flv tags into the netstream.
1 parent a1799650
...@@ -71,31 +71,18 @@ ...@@ -71,31 +71,18 @@
71 mediaSource = new videojs.MediaSource(); 71 mediaSource = new videojs.MediaSource();
72 72
73 mediaSource.addEventListener('sourceopen', function(event){ 73 mediaSource.addEventListener('sourceopen', function(event){
74 var tag, bytes, parser, i, everything, old; 74 var parser;
75 75
76 // feed parsed bytes into the player 76 // feed parsed bytes into the player
77 var sourceBuffer = mediaSource.addSourceBuffer('video/flv; codecs="vp6,aac"'); 77 var sourceBuffer = mediaSource.addSourceBuffer('video/flv; codecs="vp6,aac"');
78 parser = new videojs.hls.SegmentParser(); 78 parser = new videojs.hls.SegmentParser();
79 // var header = parser.getFlvHeader(); 79 sourceBuffer.appendBuffer(parser.getFlvHeader(), video);
80 everything = parser.getFlvHeader();
81 // sourceBuffer.appendBuffer(header, video);
82 80
83 parser.parseSegmentBinaryData(window.bcSegment); 81 parser.parseSegmentBinaryData(window.bcSegment);
84 82
85 while (parser.tagsAvailable()) { 83 while (parser.tagsAvailable()) {
86 tag = parser.getNextTag(); 84 sourceBuffer.appendBuffer(parser.getNextTag().bytes, video);
87 old = everything;
88 everything = new Uint8Array(old.byteLength + tag.bytes.byteLength);
89 everything.set(old);
90 everything.set(tag.bytes, old.byteLength);
91 } 85 }
92 console.log('sending ' + everything.byteLength + 'B');
93 // var iframe = document.createElement('iframe');
94 // iframe.src = 'data:video/x-flv;base64,' + window.btoa((Array.prototype.map.call(everything, function(byte) {
95 // return String.fromCharCode(byte);
96 // })).join(''));
97 //document.body.appendChild(iframe);
98 sourceBuffer.appendBuffer(everything, video);
99 }, false); 86 }, false);
100 87
101 url = videojs.URL.createObjectURL(mediaSource); 88 url = videojs.URL.createObjectURL(mediaSource);
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
26 // Technically, this function returns the header and a metadata FLV tag 26 // Technically, this function returns the header and a metadata FLV tag
27 // if duration is greater than zero 27 // if duration is greater than zero
28 // duration in seconds 28 // duration in seconds
29 // @return {object} the bytes of the FLV header as a Uint8Array
29 self.getFlvHeader = function(duration, audio, video) { // :ByteArray { 30 self.getFlvHeader = function(duration, audio, video) { // :ByteArray {
30 var 31 var
31 headBytes = new Uint8Array(3 + 1 + 1 + 4), 32 headBytes = new Uint8Array(3 + 1 + 1 + 4),
......