mirror of https://bitbucket.org/ausocean/av.git
mjpeg-player: comments for classes and functions
This commit is contained in:
parent
9c978be91b
commit
6f583a2815
|
@ -24,6 +24,7 @@ import Hls from "./hlsjs/hls.js";
|
||||||
let started = false;
|
let started = false;
|
||||||
let player, viewer;
|
let player, viewer;
|
||||||
|
|
||||||
|
// init gets DOM elements once the document has been loaded and adds listeners where necessary.
|
||||||
function init() {
|
function init() {
|
||||||
document.addEventListener('DOMContentLoaded', load);
|
document.addEventListener('DOMContentLoaded', load);
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
@ -36,7 +37,8 @@ function init() {
|
||||||
|
|
||||||
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() {
|
function load() {
|
||||||
let url = document.getElementById('url').value;
|
let url = document.getElementById('url').value;
|
||||||
if (url == "") {
|
if (url == "") {
|
||||||
|
@ -54,7 +56,7 @@ function load() {
|
||||||
hls.loadSource(url, append);
|
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() {
|
function getQuery() {
|
||||||
let regex = new RegExp("\\?(.*)");
|
let regex = new RegExp("\\?(.*)");
|
||||||
let match = regex.exec(window.location.href);
|
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) {
|
function append(data) {
|
||||||
if (!started) {
|
if (!started) {
|
||||||
player = new Worker("player.js");
|
player = new Worker("player.js");
|
||||||
|
|
|
@ -19,7 +19,7 @@ LICENSE
|
||||||
If not, see http://www.gnu.org/licenses.
|
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('./lex-mjpeg.js');
|
||||||
self.importScripts('./hlsjs/mts-demuxer.js');
|
self.importScripts('./hlsjs/mts-demuxer.js');
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ const codecs = {
|
||||||
MTS_MJPEG: 2,
|
MTS_MJPEG: 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// onmessage is called whenever the main thread sends this worker a message.
|
||||||
onmessage = e => {
|
onmessage = e => {
|
||||||
switch (e.data.msg) {
|
switch (e.data.msg) {
|
||||||
case "setFrameRate":
|
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 {
|
class PlayerWorker {
|
||||||
init(codec) {
|
init(codec) {
|
||||||
this.frameRate = frameRate;
|
this.frameRate = frameRate;
|
||||||
|
|
Loading…
Reference in New Issue