- updated videojs and dashjs
- combo selection algorithm now tries to find maximum simultracks
- when requesting stream info, add ?metaeverywhere=1 to the url to not count meta/subtitle tracks to simul_tracks and source priority sorting
- updated videojs, dashjs and hlsjs players
- improved html5 codec support testing
- urlappend: improved behaviour when url already contains search params
This commit is contained in:
Cat 2022-09-07 11:07:44 +02:00 committed by Thulinma
parent 6d86f98148
commit eee3595d46
26 changed files with 452 additions and 185 deletions

View file

@ -19,22 +19,49 @@ mistplayers.dashjs = {
return false;
}
var codecs = {};
if (!("MediaSource" in window)) { return false; }
if (!MediaSource.isTypeSupported) { return true; } //we can't ask, but let's assume something will work
//check if both audio and video have at least one playable track
//gather track types and codec strings
var playabletracks = {};
var hassubtitles = false;
for (var i in MistVideo.info.meta.tracks) {
if (MistVideo.info.meta.tracks[i].type != "meta") {
codecs[MistVideo.info.meta.tracks[i].codec] = 1;
if (MistVideo.info.meta.tracks[i].type == "meta") {
if (MistVideo.info.meta.tracks[i].codec == "subtitle") { hassubtitles = true; }
continue;
}
}
codecs = MistUtil.object.keys(codecs);
//if there's a h265 track, remove it from the list of codecs
for (var i = codecs.length-1; i >= 0; i--) {
if (codecs[i].substr(0,4) == "HEVC") {
codecs.splice(i,1);
if (!(MistVideo.info.meta.tracks[i].type in playabletracks)) {
playabletracks[MistVideo.info.meta.tracks[i].type] = {};
}
playabletracks[MistVideo.info.meta.tracks[i].type][MistUtil.tracks.translateCodec(MistVideo.info.meta.tracks[i])] = 1;
}
if (codecs.length < source.simul_tracks) { return false; } //if there's no longer enough playable tracks, skip this player
return ("MediaSource" in window);
var tracktypes = [];
for (var type in playabletracks) {
var playable = false;
for (var codec in playabletracks[type]) {
if (MediaSource.isTypeSupported("video/mp4;codecs=\""+codec+"\"")) {
playable = true;
break;
}
}
if (playable) {
tracktypes.push(type);
}
}
if (hassubtitles) {
//there is a subtitle track, check if there is a webvtt source
for (var i in MistVideo.info.source) {
if (MistVideo.info.source[i].type == "html5/text/vtt") {
tracktypes.push("subtitle");
break;
}
}
}
return tracktypes.length ? tracktypes : false;
},
player: function(){this.onreadylist = [];},
scriptsrc: function(host) { return host+"/dashjs.js"; }

View file

@ -19,55 +19,53 @@ mistplayers.flv = {
}
if (!window.MediaSource) { return false; }
if (!MediaSource.isTypeSupported) { return true; } //we can't ask, but let's assume something will work
try {
function test(mime) {
return window.MediaSource.isTypeSupported("video/mp4;codecs=\""+mime+"\"");
}
function translateCodec(track) {
function bin2hex(index) {
return ("0"+track.init.charCodeAt(index).toString(16)).slice(-2);
}
switch (track.codec) {
case "AAC":
return "mp4a.40.2";
case "MP3":
return "mp3";
//return "mp4a.40.34";
case "AC3":
return "ec-3";
case "H264":
return "avc1."+bin2hex(1)+bin2hex(2)+bin2hex(3);
case "HEVC":
return "hev1."+bin2hex(1)+bin2hex(6)+bin2hex(7)+bin2hex(8)+bin2hex(9)+bin2hex(10)+bin2hex(11)+bin2hex(12);
default:
return track.codec.toLowerCase();
}
}
var codecs = {};
//check if both audio and video have at least one playable track
//gather track types and codec strings
var playabletracks = {};
//var hassubtitles = false;
for (var i in MistVideo.info.meta.tracks) {
if (MistVideo.info.meta.tracks[i].type != "meta") {
codecs[translateCodec(MistVideo.info.meta.tracks[i])] = MistVideo.info.meta.tracks[i].type;
if (MistVideo.info.meta.tracks[i].type == "meta") {
//if (MistVideo.info.meta.tracks[i].codec == "subtitle") { hassubtitles = true; }
continue;
}
if (!(MistVideo.info.meta.tracks[i].type in playabletracks)) {
playabletracks[MistVideo.info.meta.tracks[i].type] = {};
}
playabletracks[MistVideo.info.meta.tracks[i].type][MistUtil.tracks.translateCodec(MistVideo.info.meta.tracks[i])] = 1;
}
var tracktypes = [];
for (var type in playabletracks) {
var playable = false;
for (var codec in playabletracks[type]) {
if (MediaSource.isTypeSupported("video/mp4;codecs=\""+codec+"\"")) {
playable = true;
break;
}
}
if (playable) {
tracktypes.push(type);
}
}
source.supportedCodecs = [];
for (var i in codecs) {
//i is the long name (like mp4a.40.2), codecs[i] is the type (audio/video)
var s = test(i);
if (s) {
source.supportedCodecs.push(codecs[i]);
source.supportedCodecs = tracktypes;
/*if (hassubtitles) {
//there is a subtitle track, check if there is a webvtt source
for (var i in MistVideo.info.source) {
if (MistVideo.info.source[i].type == "html5/text/vtt") {
tracktypes.push("subtitle");
break;
}
}
}
if ((!MistVideo.options.forceType) && (!MistVideo.options.forcePlayer)) { //unless we force mews, skip this player if not both video and audio are supported
if (source.supportedCodecs.length < source.simul_tracks) {
MistVideo.log("Not enough playable tracks for this source");
return false;
}
}
return source.supportedCodecs.length > 0;
}*/
return tracktypes.length ? tracktypes : false;
} catch(e){}
return false;

View file

@ -12,22 +12,49 @@ mistplayers.hlsjs = {
return false;
}
var codecs = {};
for (var i in MistVideo.info.meta.tracks) {
if (MistVideo.info.meta.tracks[i].type != "meta") {
codecs[MistVideo.info.meta.tracks[i].codec] = 1;
}
}
codecs = MistUtil.object.keys(codecs);
//if there's a h265 track, remove it from the list of codecs
for (var i = codecs.length-1; i >= 0; i--) {
if (codecs[i].substr(0,4) == "HEVC") {
codecs.splice(i,1);
}
}
if (codecs.length < source.simul_tracks) { return false; } //if there's no longer enough playable tracks, skip this player
if (!("MediaSource" in window)) { return false; }
if (!MediaSource.isTypeSupported) { return true; } //we can't ask, but let's assume something will work
return true;
//check if both audio and video have at least one playable track
//gather track types and codec strings
var playabletracks = {};
var hassubtitles = false;
for (var i in MistVideo.info.meta.tracks) {
if (MistVideo.info.meta.tracks[i].type == "meta") {
if (MistVideo.info.meta.tracks[i].codec == "subtitle") { hassubtitles = true; }
continue;
}
if (!(MistVideo.info.meta.tracks[i].type in playabletracks)) {
playabletracks[MistVideo.info.meta.tracks[i].type] = {};
}
playabletracks[MistVideo.info.meta.tracks[i].type][MistUtil.tracks.translateCodec(MistVideo.info.meta.tracks[i])] = 1;
}
var tracktypes = [];
for (var type in playabletracks) {
var playable = false;
for (var codec in playabletracks[type]) {
if (MediaSource.isTypeSupported("video/mp4;codecs=\""+codec+"\"")) {
playable = true;
break;
}
}
if (playable) {
tracktypes.push(type);
}
}
if (hassubtitles) {
//there is a subtitle track, check if there is a webvtt source
for (var i in MistVideo.info.source) {
if (MistVideo.info.source[i].type == "html5/text/vtt") {
tracktypes.push("subtitle");
break;
}
}
}
return tracktypes.length ? tracktypes : false;
},
player: function(){},
scriptsrc: function(host) { return host+"/hlsjs.js"; }
@ -81,13 +108,13 @@ p.prototype.build = function (MistVideo,callback) {
});
MistVideo.player.hls.attachMedia(video);
MistVideo.player.hls.on(Hls.Events.MEDIA_ATTACHED, function () {
console.log("video and hls.js are now bound together !");
//console.log("video and hls.js are now bound together !");
//hls.loadSource("https://cattop/mist/cmaf/live/v9.m3u8");
//hls.loadSource("https://mira:4433/cmaf/live/v9.m3u8");
MistVideo.player.hls.loadSource(url);
MistVideo.player.hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) {
/*MistVideo.player.hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) {
console.log("manifest loaded, found " + data.levels.length + " quality level");
});
});*/
});
}

View file

@ -33,27 +33,16 @@ mistplayers.html5 = {
try {
shortmime = shortmime.join("/");
function test(mime) {
var v = document.createElement("video");
if ((v) && (v.canPlayType(mime) != "")) {
support = v.canPlayType(mime);
}
return support;
}
//works for mp4 but not for webm
function translateCodec(track) {
function bin2hex(index) {
return ("0"+track.init.charCodeAt(index).toString(16)).slice(-2);
}
switch (track.codec) {
case "AAC":
return "mp4a.40.2";
case "MP3":
return "mp3";
//return "mp4a.40.34";
return "mp4a.40.34";
case "AC3":
return "ec-3";
case "H264":
@ -63,43 +52,64 @@ mistplayers.html5 = {
default:
return track.codec.toLowerCase();
}
}
var codecs = {};
var playabletracks = {};
var hassubtitles = false;
for (var i in MistVideo.info.meta.tracks) {
if (MistVideo.info.meta.tracks[i].type != "meta") {
codecs[translateCodec(MistVideo.info.meta.tracks[i])] = 1;
codecs[translateCodec(MistVideo.info.meta.tracks[i])] = MistVideo.info.meta.tracks[i];
}
else if (MistVideo.info.meta.tracks[i].codec == "subtitle") { hassubtitles = true; }
}
codecs = MistUtil.object.keys(codecs);
var container = mimetype.split("/")[2];
if (shortmime == "video/mp4") {
if (codecs.length) {
if (codecs.length > source.simul_tracks) {
//not all of the tracks have to work
var working = 0;
for (var i in codecs) {
var s = test(shortmime+";codecs=\""+codecs[i]+"\"");
if (s) {
working++;
}
}
return (working >= source.simul_tracks);
}
return test(shortmime+";codecs=\""+codecs.join(",")+"\"");
source.supportedCodecs = [];
for (var i in codecs) {
//i is the long name (like mp4a.40.2), codecs[i] is the track meta, codecs[i].codec is the short name (like AAC)
var s = test(i);
if (s) {
source.supportedCodecs.push(codecs[i].codec);
playabletracks[codecs[i].type] = 1;
}
}
else {
//if there's a h265 track, remove it from the list of codecs
for (var i = codecs.length-1; i >= 0; i--) {
if (codecs[i].substr(0,4) == "hev1") {
codecs.splice(i,1);
function test(codecs) {
var v = document.createElement("video");
if ((v) && (typeof v.canPlayType == "function")) {
var result;
switch (shortmime) {
case "video/webm": {
//if codecs are included here, at least chrome reports it as not working, even though it does. So we'll just assume it will play if webm returns maybe.
result = v.canPlayType(shortmime);
break;
}
case "video/mp4":
case "html5/application/vnd.apple.mpegurl":
default: {
result = v.canPlayType(shortmime+";codecs=\""+codecs+"\"");
break;
}
}
if (result != "") {
return result;
}
}
return false;
}
if (hassubtitles) {
//there is a subtitle track, check if there is a webvtt source
for (var i in MistVideo.info.source) {
if (MistVideo.info.source[i].type == "html5/text/vtt") {
playabletracks.subtitle = 1;
break;
}
}
if (codecs.length < source.simul_tracks) { return false; } //if there's no longer enough playable tracks, skip this player
}
support = test(shortmime);
support = MistUtil.object.keys(playabletracks);
} catch(e){}
return support;
},

View file

@ -42,14 +42,17 @@ mistplayers.mews = {
}
var codecs = {};
var playabletracks = {};
var hassubtitles = false;
for (var i in MistVideo.info.meta.tracks) {
if (MistVideo.info.meta.tracks[i].type != "meta") {
if (MistVideo.info.meta.tracks[i].codec == "HEVC") {
/*if (MistVideo.info.meta.tracks[i].codec == "HEVC") {
//the iPad claims to be able to play MP4/WS H265 tracks.. haha no.
continue;
}
codecs[translateCodec(MistVideo.info.meta.tracks[i])] = MistVideo.info.meta.tracks[i].codec;
}*/
codecs[translateCodec(MistVideo.info.meta.tracks[i])] = MistVideo.info.meta.tracks[i];
}
else if (MistVideo.info.meta.tracks[i].codec == "subtitle") { hassubtitles = true; }
}
var container = mimetype.split("/")[2];
function test(codecs) {
@ -58,19 +61,25 @@ mistplayers.mews = {
}
source.supportedCodecs = [];
for (var i in codecs) {
//i is the long name (like mp4a.40.2), codecs[i] is the short name (like AAC)
//i is the long name (like mp4a.40.2), codecs[i] is the track meta, codecs[i].codec is the short name (like AAC)
var s = test(i);
if (s) {
source.supportedCodecs.push(codecs[i]);
source.supportedCodecs.push(codecs[i].codec);
playabletracks[codecs[i].type] = 1;
}
}
if ((!MistVideo.options.forceType) && (!MistVideo.options.forcePlayer)) { //unless we force mews, skip this players if not both video and audio are supported
if (source.supportedCodecs.length < source.simul_tracks) {
MistVideo.log("Not enough playable tracks for this source");
return false;
if (hassubtitles) {
//there is a subtitle track, check if there is a webvtt source
for (var i in MistVideo.info.source) {
if (MistVideo.info.source[i].type == "html5/text/vtt") {
playabletracks.subtitle = 1;
break;
}
}
}
return source.supportedCodecs.length > 0;
return MistUtil.object.keys(playabletracks);
},
player: function(){}
};

View file

@ -19,7 +19,7 @@ mistplayers.rawws = {
}
for (var i in MistVideo.info.meta.tracks) {
if (MistVideo.info.meta.tracks[i].codec == "HEVC") { return true; }
if (MistVideo.info.meta.tracks[i].codec == "HEVC") { return ["video"]; }
}
return false;

View file

@ -19,22 +19,63 @@ mistplayers.videojs = {
return false;
}
var codecs = {};
for (var i in MistVideo.info.meta.tracks) {
if (MistVideo.info.meta.tracks[i].type != "meta") {
codecs[MistVideo.info.meta.tracks[i].codec] = 1;
function checkPlaybackOfTrackTypes(mime) {
if (!MediaSource.isTypeSupported) { return true; } //we can't ask, but let's assume something will work
//check if both audio and video have at least one playable track
//gather track types and codec strings
var playabletracks = {};
var hassubtitles = false;
for (var i in MistVideo.info.meta.tracks) {
if (MistVideo.info.meta.tracks[i].type == "meta") {
if (MistVideo.info.meta.tracks[i].codec == "subtitle") { hassubtitles = true; }
continue;
}
if (!(MistVideo.info.meta.tracks[i].type in playabletracks)) {
playabletracks[MistVideo.info.meta.tracks[i].type] = {};
}
playabletracks[MistVideo.info.meta.tracks[i].type][MistUtil.tracks.translateCodec(MistVideo.info.meta.tracks[i])] = 1;
}
}
codecs = MistUtil.object.keys(codecs);
//if there's a h265 track, remove it from the list of codecs
for (var i = codecs.length-1; i >= 0; i--) {
if (codecs[i].substr(0,4) == "HEVC") {
codecs.splice(i,1);
var tracktypes = [];
for (var type in playabletracks) {
var playable = false;
for (var codec in playabletracks[type]) {
if (MediaSource.isTypeSupported(mime+";codecs=\""+codec+"\"")) {
playable = true;
break;
}
}
if (playable) {
tracktypes.push(type);
}
}
if (hassubtitles) {
//there is a subtitle track, check if there is a webvtt source
for (var i in MistVideo.info.source) {
if (MistVideo.info.source[i].type == "html5/text/vtt") {
tracktypes.push("subtitle");
break;
}
}
}
return tracktypes.length ? tracktypes : false;
}
if (codecs.length < source.simul_tracks) { return false; } //if there's no longer enough playable tracks, skip this player
return ("MediaSource" in window);
//can this browser play this natively?
if (document.createElement("video").canPlayType(mimetype.replace("html5/",""))) {
//we can't ask, but let's assume something will work
if (!("MediaSource" in window)) { return true; }
if (!MediaSource.isTypeSupported) { return true; }
return checkPlaybackOfTrackTypes(mimetype.replace("html5/",""));
}
if (!("MediaSource" in window)) { return false; }
return checkPlaybackOfTrackTypes("video/mp4");
},
player: function(){},
scriptsrc: function(host) { return host+"/videojs.js"; }

View file

@ -7,15 +7,60 @@ mistplayers.webrtc = {
},
isBrowserSupported: function (mimetype,source,MistVideo) {
if ((!("WebSocket" in window)) || (!("RTCPeerConnection" in window))) { return false; }
if ((!("WebSocket" in window)) || (!("RTCPeerConnection" in window) || (!("RTCRtpReceiver" in window)))) { return false; }
//check for http/https mismatch
if (location.protocol.replace(/^http/,"ws") != MistUtil.http.url.split(source.url.replace(/^http/,"ws")).protocol) {
MistVideo.log("HTTP/HTTPS mismatch for this source");
return false;
}
//check if both audio and video have at least one playable track
//gather track types and codec strings
var playabletracks = {};
var hassubtitles = false;
for (var i in MistVideo.info.meta.tracks) {
if (MistVideo.info.meta.tracks[i].type == "meta") {
if (MistVideo.info.meta.tracks[i].codec == "subtitle") { hassubtitles = true; }
continue;
}
if (!(MistVideo.info.meta.tracks[i].type in playabletracks)) {
playabletracks[MistVideo.info.meta.tracks[i].type] = {};
}
playabletracks[MistVideo.info.meta.tracks[i].type][MistVideo.info.meta.tracks[i].codec] = 1;
}
var tracktypes = [];
for (var type in playabletracks) {
var playable = false;
for (var codec in playabletracks[type]) {
var supported = RTCRtpReceiver.getCapabilities(type).codecs;
for (var i in supported) {
if (supported[i].mimeType.toLowerCase() == (type+"/"+codec).toLowerCase()) {
playable = true;
break;
}
}
}
if (playable) {
tracktypes.push(type);
}
}
if (hassubtitles) {
//there is a subtitle track, check if there is a webvtt source
for (var i in MistVideo.info.source) {
if (MistVideo.info.source[i].type == "html5/text/vtt") {
tracktypes.push("subtitle");
break;
}
}
}
return tracktypes.length ? tracktypes : false;
return true;
//return true;
},
player: function(){}
};