hls-player-js/mp4-tree.js

50 lines
932 B
JavaScript
Raw Normal View History

DataView.prototype.getString = function(offset, length) {
text = '';
let end = offset + length;
for (let i = offset; i < end; i++) {
text += String.fromCharCode(this.getUint8(i));
}
return text;
}
class MP4Tree {
constructor(data) {
this.data = new DataView(data);
this.codecs = [];
this.idx = 0;
this.parse_codecs();
}
parse_codecs() {
this.parse_until('moov');
console.log(this.idx);
}
get_mime() {
return 'video/mp4; codecs="' + this.get_codec_string() + '"';
}
get_codec_string() {
return this.codecs.join(', ');
}
parse_until(name) {
let curr_head = null;
while (this.idx < this.data.byteLength) {
curr_head = this.read_next_head();
console.log(curr_head);
if (curr_head.name == name) {
break;
} else {
this.idx += curr_head.len;
}
}
}
read_next_head() {
return {"len": this.data.getUint32(this.idx), "name": this.data.getString(this.idx + 4, 4)};
}
}