mjpeg-player: comments for classes and functions

This commit is contained in:
Trek H 2020-01-21 11:47:37 +10:30
parent 9c978be91b
commit 6f583a2815
2 changed files with 9 additions and 4 deletions

View File

@ -24,6 +24,7 @@ import Hls from "./hlsjs/hls.js";
let started = false;
let player, viewer;
// init gets DOM elements once the document has been loaded and adds listeners where necessary.
function init() {
document.addEventListener('DOMContentLoaded', load);
document.addEventListener('DOMContentLoaded', function () {
@ -36,7 +37,8 @@ function init() {
init();
// load gets the URL and creates an Hls instance to load the content.
// load gets the URL from the URL input element or the browser's URL bar
// and creates an Hls instance to load the content from the URL.
function load() {
let url = document.getElementById('url').value;
if (url == "") {
@ -54,7 +56,7 @@ function load() {
hls.loadSource(url, append);
}
// getQuery gets everything after the question mark in the URL.
// getQuery gets everything after the question mark from the URL in the browser's URL bar.
function getQuery() {
let regex = new RegExp("\\?(.*)");
let match = regex.exec(window.location.href);
@ -65,7 +67,8 @@ function getQuery() {
}
}
// append is used as a callback for whenever
// append, on the first call, starts a player worker and passes it a frame rate and the video data,
// on subsequent calls it passes the video data to the player worker.
function append(data) {
if (!started) {
player = new Worker("player.js");

View File

@ -19,7 +19,7 @@ LICENSE
If not, see http://www.gnu.org/licenses.
*/
let frameRate = 25;
let frameRate = 25; //Keeps track of the frame rate, default is 25fps.
self.importScripts('./lex-mjpeg.js');
self.importScripts('./hlsjs/mts-demuxer.js');
@ -28,6 +28,7 @@ const codecs = {
MTS_MJPEG: 2,
}
// onmessage is called whenever the main thread sends this worker a message.
onmessage = e => {
switch (e.data.msg) {
case "setFrameRate":
@ -55,6 +56,7 @@ onmessage = e => {
}
};
// PlayerWorker has a FrameBuffer to hold frames and once started, passes them one at a time to the main thread.
class PlayerWorker {
init(codec) {
this.frameRate = frameRate;