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 @@
mediaSource = new videojs.MediaSource();
mediaSource.addEventListener('sourceopen', function(event){
var tag, bytes, parser, i, everything, old;
var parser;
// feed parsed bytes into the player
var sourceBuffer = mediaSource.addSourceBuffer('video/flv; codecs="vp6,aac"');
parser = new videojs.hls.SegmentParser();
// var header = parser.getFlvHeader();
everything = parser.getFlvHeader();
// sourceBuffer.appendBuffer(header, video);
sourceBuffer.appendBuffer(parser.getFlvHeader(), video);
parser.parseSegmentBinaryData(window.bcSegment);
while (parser.tagsAvailable()) {
tag = parser.getNextTag();
old = everything;
everything = new Uint8Array(old.byteLength + tag.bytes.byteLength);
everything.set(old);
everything.set(tag.bytes, old.byteLength);
sourceBuffer.appendBuffer(parser.getNextTag().bytes, video);
}
console.log('sending ' + everything.byteLength + 'B');
// var iframe = document.createElement('iframe');
// iframe.src = 'data:video/x-flv;base64,' + window.btoa((Array.prototype.map.call(everything, function(byte) {
// return String.fromCharCode(byte);
// })).join(''));
//document.body.appendChild(iframe);
sourceBuffer.appendBuffer(everything, video);
}, false);
url = videojs.URL.createObjectURL(mediaSource);
......
......@@ -26,6 +26,7 @@
// Technically, this function returns the header and a metadata FLV tag
// if duration is greater than zero
// duration in seconds
// @return {object} the bytes of the FLV header as a Uint8Array
self.getFlvHeader = function(duration, audio, video) { // :ByteArray {
var
headBytes = new Uint8Array(3 + 1 + 1 + 4),
......