Compare commits

..

No commits in common. "hydrar" and "master" have entirely different histories.

78 changed files with 3727 additions and 6160 deletions

File diff suppressed because one or more lines are too long

View file

@ -1 +1 @@
mistplayers.dashjs={name:"Dash.js player",mimes:["dash/video/mp4"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(e){return MistUtil.array.indexOf(this.mimes,e)==-1?false:true},isBrowserSupported:function(e,t,i){if(location.protocol!=MistUtil.http.url.split(t.url).protocol){i.log("HTTP/HTTPS mismatch for this source");return false}if(location.protocol=="file:"){i.log("This source ("+e+") won't load if the page is run via file://");return false}if(!("MediaSource"in window)){return false}if(!MediaSource.isTypeSupported){return true}var r={};var a=false;for(var s in i.info.meta.tracks){if(i.info.meta.tracks[s].type=="meta"){if(i.info.meta.tracks[s].codec=="subtitle"){a=true}continue}if(!(i.info.meta.tracks[s].type in r)){r[i.info.meta.tracks[s].type]={}}r[i.info.meta.tracks[s].type][MistUtil.tracks.translateCodec(i.info.meta.tracks[s])]=1}var o=[];for(var n in r){var l=false;for(var f in r[n]){if(MediaSource.isTypeSupported('video/mp4;codecs="'+f+'"')){l=true;break}}if(l){o.push(n)}}if(a){for(var s in i.info.source){if(i.info.source[s].type=="html5/text/vtt"){o.push("subtitle");break}}}return o.length?o:false},player:function(){this.onreadylist=[]},scriptsrc:function(e){return e+"/dashjs.js"}};var p=mistplayers.dashjs.player;p.prototype=new MistPlayer;p.prototype.build=function(e,t){var i=this;this.onDashLoad=function(){if(e.destroyed){return}e.log("Building DashJS player..");var r=document.createElement("video");if("Proxy"in window){var a={get:{},set:{}};e.player.api=new Proxy(r,{get:function(e,t,i){if(t in a.get){return a.get[t].apply(e,arguments)}var r=e[t];if(typeof r==="function"){return function(){return r.apply(e,arguments)}}return r},set:function(e,t,i){if(t in a.set){return a.set[t].call(e,i)}return e[t]=i}});if(e.info.type=="live"){a.get.duration=function(){var t=0;if(this.buffered.length){t=this.buffered.end(this.buffered.length-1)}var i=((new Date).getTime()-e.player.api.lastProgress.getTime())*.001;return t+i+-1*e.player.api.liveOffset+45};a.set.currentTime=function(t){var i=t-e.player.api.duration;e.log("Seeking to "+MistUtil.format.time(t)+" ("+Math.round(i*-10)/10+"s from live)");e.video.currentTime=t};MistUtil.event.addListener(r,"progress",(function(){e.player.api.lastProgress=new Date}));e.player.api.lastProgress=new Date;e.player.api.liveOffset=0}}else{i.api=r}if(e.options.autoplay){r.setAttribute("autoplay","")}if(e.options.loop&&e.info.type!="live"){r.setAttribute("loop","")}if(e.options.poster){r.setAttribute("poster",e.options.poster)}if(e.options.muted){r.muted=true}if(e.options.controls=="stock"){r.setAttribute("controls","")}var s=dashjs.MediaPlayer().create();s.initialize(r,e.source.url,e.options.autoplay);i.dash=s;var o=["METRIC_ADDED","METRIC_UPDATED","METRIC_CHANGED","METRICS_CHANGED","FRAGMENT_LOADING_STARTED","FRAGMENT_LOADING_COMPLETED","LOG","PLAYBACK_TIME_UPDATED","PLAYBACK_PROGRESS"];for(var n in dashjs.MediaPlayer.events){if(o.indexOf(n)<0){i.dash.on(dashjs.MediaPlayer.events[n],(function(t){e.log("Player event fired: "+t.type)}))}}e.player.setSize=function(e){this.api.style.width=e.width+"px";this.api.style.height=e.height+"px"};e.player.api.setSource=function(t){e.player.dash.attachSource(t)};if(e.options.controls!="stock"){i.dash.updateSettings({streaming:{text:{defaultEnabled:false}}})}var l=false;i.dash.on("allTextTracksAdded",(function(){l=true}));e.player.api.setSubtitle=function(t){if(!l){var r=function(){e.player.api.setSubtitle(t);i.dash.off("allTextTracksAdded",r)};i.dash.on("allTextTracksAdded",r);return}if(!t){i.dash.enableText(false);return}var a=i.dash.getTracksFor("text");for(var s in a){var o="idx"in t?t.idx:t.trackid;if(a[s].id==o){i.dash.setTextTrack(s);if(!i.dash.isTextEnabled()){i.dash.enableText()}return true}}return false};MistUtil.event.addListener(r,"progress",(function(t){if(e.container.getAttribute("data-loading")=="stalled"){e.container.removeAttribute("data-loading")}}));i.api.unload=function(){i.dash.reset()};e.log("Built html");t(r)};if("dashjs"in window){this.onDashLoad()}else{var r=MistUtil.scripts.insert(e.urlappend(mistplayers.dashjs.scriptsrc(e.options.host)),{onerror:function(t){var i="Failed to load dashjs.js";if(t.message){i+=": "+t.message}e.showError(i)},onload:i.onDashLoad},e)}};
mistplayers.dashjs={name:"Dash.js player",mimes:["dash/video/mp4"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(e){return MistUtil.array.indexOf(this.mimes,e)==-1?false:true},isBrowserSupported:function(e,t,i){if(location.protocol!=MistUtil.http.url.split(t.url).protocol){i.log("HTTP/HTTPS mismatch for this source");return false}if(location.protocol=="file:"){i.log("This source ("+e+") won't load if the page is run via file://");return false}if(!("MediaSource"in window)){return false}if(!MediaSource.isTypeSupported){return true}var r={};var a=false;for(var s in i.info.meta.tracks){if(i.info.meta.tracks[s].type=="meta"){if(i.info.meta.tracks[s].codec=="subtitle"){a=true}continue}if(!(i.info.meta.tracks[s].type in r)){r[i.info.meta.tracks[s].type]={}}r[i.info.meta.tracks[s].type][MistUtil.tracks.translateCodec(i.info.meta.tracks[s])]=1}var o=[];for(var n in r){var l=false;for(var f in r[n]){if(MediaSource.isTypeSupported('video/mp4;codecs="'+f+'"')){l=true;break}}if(l){o.push(n)}}if(a){for(var s in i.info.source){if(i.info.source[s].type=="html5/text/vtt"){o.push("subtitle");break}}}return o.length?o:false},player:function(){this.onreadylist=[]},scriptsrc:function(e){return e+"/dashjs.js"}};var p=mistplayers.dashjs.player;p.prototype=new MistPlayer;p.prototype.build=function(e,t){var i=this;this.onDashLoad=function(){if(e.destroyed){return}e.log("Building DashJS player..");var r=document.createElement("video");if("Proxy"in window){var a={get:{},set:{}};e.player.api=new Proxy(r,{get:function(e,t,i){if(t in a.get){return a.get[t].apply(e,arguments)}var r=e[t];if(typeof r==="function"){return function(){return r.apply(e,arguments)}}return r},set:function(e,t,i){if(t in a.set){return a.set[t].call(e,i)}return e[t]=i}});if(e.info.type=="live"){a.get.duration=function(){var t=0;if(this.buffered.length){t=this.buffered.end(this.buffered.length-1)}var i=((new Date).getTime()-e.player.api.lastProgress.getTime())*.001;return t+i+-1*e.player.api.liveOffset+45};a.set.currentTime=function(t){var i=t-e.player.api.duration;e.log("Seeking to "+MistUtil.format.time(t)+" ("+Math.round(i*-10)/10+"s from live)");e.video.currentTime=t};MistUtil.event.addListener(r,"progress",function(){e.player.api.lastProgress=new Date});e.player.api.lastProgress=new Date;e.player.api.liveOffset=0}}else{i.api=r}if(e.options.autoplay){r.setAttribute("autoplay","")}if(e.options.loop&&e.info.type!="live"){r.setAttribute("loop","")}if(e.options.poster){r.setAttribute("poster",e.options.poster)}if(e.options.muted){r.muted=true}if(e.options.controls=="stock"){r.setAttribute("controls","")}var s=dashjs.MediaPlayer().create();s.initialize(r,e.source.url,e.options.autoplay);i.dash=s;var o=["METRIC_ADDED","METRIC_UPDATED","METRIC_CHANGED","METRICS_CHANGED","FRAGMENT_LOADING_STARTED","FRAGMENT_LOADING_COMPLETED","LOG","PLAYBACK_TIME_UPDATED","PLAYBACK_PROGRESS"];for(var n in dashjs.MediaPlayer.events){if(o.indexOf(n)<0){i.dash.on(dashjs.MediaPlayer.events[n],function(t){e.log("Player event fired: "+t.type)})}}e.player.setSize=function(e){this.api.style.width=e.width+"px";this.api.style.height=e.height+"px"};e.player.api.setSource=function(t){e.player.dash.attachSource(t)};if(e.options.controls!="stock"){i.dash.updateSettings({streaming:{text:{defaultEnabled:false}}})}var l=false;i.dash.on("allTextTracksAdded",function(){l=true});e.player.api.setSubtitle=function(t){if(!l){var r=function(){e.player.api.setSubtitle(t);i.dash.off("allTextTracksAdded",r)};i.dash.on("allTextTracksAdded",r);return}if(!t){i.dash.enableText(false);return}var a=i.dash.getTracksFor("text");for(var s in a){var o="idx"in t?t.idx:t.trackid;if(a[s].id==o){i.dash.setTextTrack(s);if(!i.dash.isTextEnabled()){i.dash.enableText()}return true}}return false};MistUtil.event.addListener(r,"progress",function(t){if(e.container.getAttribute("data-loading")=="stalled"){e.container.removeAttribute("data-loading")}});i.api.unload=function(){i.dash.reset()};e.log("Built html");t(r)};if("dashjs"in window){this.onDashLoad()}else{var r=MistUtil.scripts.insert(e.urlappend(mistplayers.dashjs.scriptsrc(e.options.host)),{onerror:function(t){var i="Failed to load dashjs.js";if(t.message){i+=": "+t.message}e.showError(i)},onload:i.onDashLoad},e)}};

View file

@ -1 +1 @@
mistplayers.flash_strobe={name:"Strobe Flash media playback",mimes:["flash/10","flash/11","flash/7"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(t){return this.mimes.indexOf(t)==-1?false:true},isBrowserSupported:function(t,e,i){if(MistUtil.http.url.split(e.url).protocol.slice(0,4)=="http"&&location.protocol!=MistUtil.http.url.split(e.url).protocol){i.log("HTTP/HTTPS mismatch for this source");return false}var r=0;try{var a=navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;if(a.version){r=a.version.split(".")[0]}else{r=a.description.replace(/([^0-9\.])/g,"").split(".")[0]}}catch(t){}try{r=new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version").replace(/([^0-9\,])/g,"").split(",")[0]}catch(t){}if(!r){return false}var l=t.split("/");return Number(r)>=Number(l[l.length-1])},player:function(){this.onreadylist=[]}};var p=mistplayers.flash_strobe.player;p.prototype=new MistPlayer;p.prototype.build=function(t,e){var i=document.createElement("object");var r=document.createElement("embed");i.appendChild(r);function a(e){var a=t.options;function l(t,e){var i=document.createElement("param");i.setAttribute("name",t);i.setAttribute("value",e);return i}MistUtil.empty(i);i.appendChild(l("movie",t.urlappend(a.host+t.source.player_url)));var o="src="+encodeURIComponent(e)+"&controlBarMode="+(a.controls?"floating":"none")+"&initialBufferTime=0.5&expandedBufferTime=5&minContinuousPlaybackTime=3"+(a.live?"&streamType=live":"")+(a.autoplay?"&autoPlay=true":"")+(a.loop?"&loop=true":"")+(a.poster?"&poster="+a.poster:"")+(a.muted?"&muted=true":"");i.appendChild(l("flashvars",o));i.appendChild(l("allowFullScreen","true"));i.appendChild(l("wmode","direct"));if(a.autoplay){i.appendChild(l("autoPlay","true"))}if(a.loop){i.appendChild(l("loop","true"))}if(a.poster){i.appendChild(l("poster",a.poster))}if(a.muted){i.appendChild(l("muted","true"))}r.setAttribute("src",t.urlappend(t.source.player_url));r.setAttribute("type","application/x-shockwave-flash");r.setAttribute("allowfullscreen","true");r.setAttribute("flashvars",o)}a(t.source.url);this.api={};this.setSize=function(t){i.setAttribute("width",t.width);i.setAttribute("height",t.height);r.setAttribute("width",t.width);r.setAttribute("height",t.height)};this.setSize(t.calcSize());this.onready((function(){if(t.container){t.container.removeAttribute("data-loading")}}));this.api.setSource=function(t){a(t)};t.log("Built html");e(i)};
mistplayers.flash_strobe={name:"Strobe Flash media playback",mimes:["flash/10","flash/11","flash/7"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(t){return this.mimes.indexOf(t)==-1?false:true},isBrowserSupported:function(t,e,i){if(MistUtil.http.url.split(e.url).protocol.slice(0,4)=="http"&&location.protocol!=MistUtil.http.url.split(e.url).protocol){i.log("HTTP/HTTPS mismatch for this source");return false}var r=0;try{var a=navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;if(a.version){r=a.version.split(".")[0]}else{r=a.description.replace(/([^0-9\.])/g,"").split(".")[0]}}catch(t){}try{r=new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version").replace(/([^0-9\,])/g,"").split(",")[0]}catch(t){}if(!r){return false}var l=t.split("/");return Number(r)>=Number(l[l.length-1])},player:function(){this.onreadylist=[]}};var p=mistplayers.flash_strobe.player;p.prototype=new MistPlayer;p.prototype.build=function(t,e){var i=document.createElement("object");var r=document.createElement("embed");i.appendChild(r);function a(e){var a=t.options;function l(t,e){var i=document.createElement("param");i.setAttribute("name",t);i.setAttribute("value",e);return i}MistUtil.empty(i);i.appendChild(l("movie",t.urlappend(a.host+t.source.player_url)));var o="src="+encodeURIComponent(e)+"&controlBarMode="+(a.controls?"floating":"none")+"&initialBufferTime=0.5&expandedBufferTime=5&minContinuousPlaybackTime=3"+(a.live?"&streamType=live":"")+(a.autoplay?"&autoPlay=true":"")+(a.loop?"&loop=true":"")+(a.poster?"&poster="+a.poster:"")+(a.muted?"&muted=true":"");i.appendChild(l("flashvars",o));i.appendChild(l("allowFullScreen","true"));i.appendChild(l("wmode","direct"));if(a.autoplay){i.appendChild(l("autoPlay","true"))}if(a.loop){i.appendChild(l("loop","true"))}if(a.poster){i.appendChild(l("poster",a.poster))}if(a.muted){i.appendChild(l("muted","true"))}r.setAttribute("src",t.urlappend(t.source.player_url));r.setAttribute("type","application/x-shockwave-flash");r.setAttribute("allowfullscreen","true");r.setAttribute("flashvars",o)}a(t.source.url);this.api={};this.setSize=function(t){i.setAttribute("width",t.width);i.setAttribute("height",t.height);r.setAttribute("width",t.width);r.setAttribute("height",t.height)};this.setSize(t.calcSize());this.onready(function(){if(t.container){t.container.removeAttribute("data-loading")}});this.api.setSource=function(t){a(t)};t.log("Built html");e(i)};

View file

@ -1 +1 @@
mistplayers.flv={name:"HTML5 FLV Player",mimes:["flash/7"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(e){return MistUtil.array.indexOf(this.mimes,e)==-1?false:true},isBrowserSupported:function(e,t,r){if(location.protocol!=MistUtil.http.url.split(t.url).protocol){if(location.protocol=="file:"&&MistUtil.http.url.split(t.url).protocol=="http:"){r.log("This page was loaded over file://, the player might not behave as intended.")}else{r.log("HTTP/HTTPS mismatch for this source");return false}}if(!window.MediaSource){return false}if(!MediaSource.isTypeSupported){return true}try{var o={};for(var a in r.info.meta.tracks){if(r.info.meta.tracks[a].type=="meta"){continue}if(!(r.info.meta.tracks[a].type in o)){o[r.info.meta.tracks[a].type]={}}o[r.info.meta.tracks[a].type][MistUtil.tracks.translateCodec(r.info.meta.tracks[a])]=1}var i=[];for(var l in o){var n=false;for(var s in o[l]){if(MediaSource.isTypeSupported('video/mp4;codecs="'+s+'"')){n=true;break}}if(n){i.push(l)}}t.supportedCodecs=i;return i.length?i:false}catch(e){}return false},player:function(){this.onreadylist=[]},scriptsrc:function(e){return e+"/flv.js"}};var p=mistplayers.flv.player;p.prototype=new MistPlayer;p.prototype.build=function(e,t){this.onFLVLoad=function(){if(e.destroyed){return}e.log("Building flv.js player..");var r=document.createElement("video");r.setAttribute("playsinline","");var o=["autoplay","loop","poster"];for(var a in o){var i=o[a];if(e.options[i]){r.setAttribute(i,e.options[i]===true?"":e.options[i])}}if(e.options.muted){r.muted=true}if(e.options.controls=="stock"){r.setAttribute("controls","")}if(e.info.type=="live"){r.loop=false}flvjs.LoggingControl.applyConfig({enableVerbose:false});flvjs.LoggingControl.addLogListener((function(t,r){e.log("[flvjs] "+r)}));var l={type:"flv",url:e.source.url,hasAudio:false,hasVideo:false};for(var a in e.source.supportedCodecs){l["has"+e.source.supportedCodecs[a].charAt(0).toUpperCase()+e.source.supportedCodecs[a].slice(1)]=true}e.player.create=function(t){t=MistUtil.object.extend({},t);e.player.flvPlayer=flvjs.createPlayer(t,{lazyLoad:false});e.player.flvPlayer.attachMediaElement(r);e.player.flvPlayer.load();e.player.flvPlayer.play();if(!e.options.autoplay){r.pause()}};e.player.create(l);e.player.api={};function n(t){Object.defineProperty(e.player.api,t,{get:function(){return r[t]},set:function(e){return r[t]=e}})}var s=["volume","buffered","muted","loop","paused",,"error","textTracks","webkitDroppedFrameCount","webkitDecodedFrameCount"];if(e.info.type!="live"){s.push("duration")}else{Object.defineProperty(e.player.api,"duration",{get:function(){if(!r.buffered.length){return 0}return r.buffered.end(r.buffered.length-1)}})}for(var a in s){n(s[a])}function f(t){if(t in r){e.player.api[t]=function(){return r[t].call(r,arguments)}}}var s=["load","getVideoPlaybackQuality","play","pause"];for(var a in s){f(s[a])}e.player.api.setSource=function(t){if(t!=l.url&&t!=""){e.player.flvPlayer.unload();e.player.flvPlayer.detachMediaElement();e.player.flvPlayer.destroy();l.url=t;e.player.create(l)}};e.player.api.unload=function(){e.player.flvPlayer.unload();e.player.flvPlayer.detachMediaElement();e.player.flvPlayer.destroy()};e.player.setSize=function(e){r.style.width=e.width+"px";r.style.height=e.height+"px"};Object.defineProperty(e.player.api,"currentTime",{get:function(){return r.currentTime},set:function(t){var o=.5;for(var a=0;a<r.buffered.length;a++){if(t>=r.buffered.start(a)&&t<=r.buffered.end(a)-o){return r.currentTime=t}}e.log("Seek attempted outside of buffer, but MistServer does not support seeking in progressive flash. Setting to closest available instead");return r.currentTime=r.buffered.length?r.buffered.end(r.buffered.length-1)-o:0}});t(r)};if("flvjs"in window){this.onFLVLoad()}else{var r=MistUtil.scripts.insert(e.urlappend(mistplayers.flv.scriptsrc(e.options.host)),{onerror:function(t){var r="Failed to load flv.js";if(t.message){r+=": "+t.message}e.showError(r)},onload:e.player.onFLVLoad},e)}};
mistplayers.flv={name:"HTML5 FLV Player",mimes:["flash/7"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(e){return MistUtil.array.indexOf(this.mimes,e)==-1?false:true},isBrowserSupported:function(e,t,r){if(location.protocol!=MistUtil.http.url.split(t.url).protocol){if(location.protocol=="file:"&&MistUtil.http.url.split(t.url).protocol=="http:"){r.log("This page was loaded over file://, the player might not behave as intended.")}else{r.log("HTTP/HTTPS mismatch for this source");return false}}if(!window.MediaSource){return false}if(!MediaSource.isTypeSupported){return true}try{var o={};for(var a in r.info.meta.tracks){if(r.info.meta.tracks[a].type=="meta"){continue}if(!(r.info.meta.tracks[a].type in o)){o[r.info.meta.tracks[a].type]={}}o[r.info.meta.tracks[a].type][MistUtil.tracks.translateCodec(r.info.meta.tracks[a])]=1}var i=[];for(var l in o){var n=false;for(var s in o[l]){if(MediaSource.isTypeSupported('video/mp4;codecs="'+s+'"')){n=true;break}}if(n){i.push(l)}}t.supportedCodecs=i;return i.length?i:false}catch(e){}return false},player:function(){this.onreadylist=[]},scriptsrc:function(e){return e+"/flv.js"}};var p=mistplayers.flv.player;p.prototype=new MistPlayer;p.prototype.build=function(e,t){this.onFLVLoad=function(){if(e.destroyed){return}e.log("Building flv.js player..");var r=document.createElement("video");r.setAttribute("playsinline","");var o=["autoplay","loop","poster"];for(var a in o){var i=o[a];if(e.options[i]){r.setAttribute(i,e.options[i]===true?"":e.options[i])}}if(e.options.muted){r.muted=true}if(e.options.controls=="stock"){r.setAttribute("controls","")}if(e.info.type=="live"){r.loop=false}flvjs.LoggingControl.applyConfig({enableVerbose:false});flvjs.LoggingControl.addLogListener(function(t,r){e.log("[flvjs] "+r)});var l={type:"flv",url:e.source.url,hasAudio:false,hasVideo:false};for(var a in e.source.supportedCodecs){l["has"+e.source.supportedCodecs[a].charAt(0).toUpperCase()+e.source.supportedCodecs[a].slice(1)]=true}e.player.create=function(t){t=MistUtil.object.extend({},t);e.player.flvPlayer=flvjs.createPlayer(t,{lazyLoad:false});e.player.flvPlayer.attachMediaElement(r);e.player.flvPlayer.load();e.player.flvPlayer.play();if(!e.options.autoplay){r.pause()}};e.player.create(l);e.player.api={};function n(t){Object.defineProperty(e.player.api,t,{get:function(){return r[t]},set:function(e){return r[t]=e}})}var s=["volume","buffered","muted","loop","paused",,"error","textTracks","webkitDroppedFrameCount","webkitDecodedFrameCount"];if(e.info.type!="live"){s.push("duration")}else{Object.defineProperty(e.player.api,"duration",{get:function(){if(!r.buffered.length){return 0}return r.buffered.end(r.buffered.length-1)}})}for(var a in s){n(s[a])}function f(t){if(t in r){e.player.api[t]=function(){return r[t].call(r,arguments)}}}var s=["load","getVideoPlaybackQuality","play","pause"];for(var a in s){f(s[a])}e.player.api.setSource=function(t){if(t!=l.url&&t!=""){e.player.flvPlayer.unload();e.player.flvPlayer.detachMediaElement();e.player.flvPlayer.destroy();l.url=t;e.player.create(l)}};e.player.api.unload=function(){e.player.flvPlayer.unload();e.player.flvPlayer.detachMediaElement();e.player.flvPlayer.destroy()};e.player.setSize=function(e){r.style.width=e.width+"px";r.style.height=e.height+"px"};Object.defineProperty(e.player.api,"currentTime",{get:function(){return r.currentTime},set:function(t){var o=.5;for(var a=0;a<r.buffered.length;a++){if(t>=r.buffered.start(a)&&t<=r.buffered.end(a)-o){return r.currentTime=t}}e.log("Seek attempted outside of buffer, but MistServer does not support seeking in progressive flash. Setting to closest available instead");return r.currentTime=r.buffered.length?r.buffered.end(r.buffered.length-1)-o:0}});t(r)};if("flvjs"in window){this.onFLVLoad()}else{var r=MistUtil.scripts.insert(e.urlappend(mistplayers.flv.scriptsrc(e.options.host)),{onerror:function(t){var r="Failed to load flv.js";if(t.message){r+=": "+t.message}e.showError(r)},onload:e.player.onFLVLoad},e)}};

View file

@ -1 +1 @@
mistplayers.hlsjs={name:"HLS.js player",mimes:["html5/application/vnd.apple.mpegurl","html5/application/vnd.apple.mpegurl;version=7"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(t){return this.mimes.indexOf(t)==-1?false:true},isBrowserSupported:function(t,e,r){if(location.protocol!=MistUtil.http.url.split(e.url).protocol){r.log("HTTP/HTTPS mismatch for this source");return false}if(!("MediaSource"in window)){return false}if(!MediaSource.isTypeSupported){return true}var i={};var s=false;for(var o in r.info.meta.tracks){if(r.info.meta.tracks[o].type=="meta"){if(r.info.meta.tracks[o].codec=="subtitle"){s=true}continue}if(!(r.info.meta.tracks[o].type in i)){i[r.info.meta.tracks[o].type]={}}i[r.info.meta.tracks[o].type][MistUtil.tracks.translateCodec(r.info.meta.tracks[o])]=1}var a=[];for(var l in i){var n=false;for(var p in i[l]){if(MediaSource.isTypeSupported('video/mp4;codecs="'+p+'"')){n=true;break}}if(n){a.push(l)}}if(s){for(var o in r.info.source){if(r.info.source[o].type=="html5/text/vtt"){a.push("subtitle");break}}}return a.length?a:false},player:function(){},scriptsrc:function(t){return t+"/hlsjs.js"}};var p=mistplayers.hlsjs.player;p.prototype=new MistPlayer;p.prototype.build=function(t,e){var r=this;var i=document.createElement("video");i.setAttribute("playsinline","");var s=["autoplay","loop","poster"];for(var o in s){var a=s[o];if(t.options[a]){i.setAttribute(a,t.options[a]===true?"":t.options[a])}}if(t.options.muted){i.muted=true}if(t.info.type=="live"){i.loop=false}if(t.options.controls=="stock"){i.setAttribute("controls","")}i.setAttribute("crossorigin","anonymous");this.setSize=function(t){i.style.width=t.width+"px";i.style.height=t.height+"px"};this.api=i;t.player.api.unload=function(){if(t.player.hls){t.player.hls.destroy();t.player.hls=false;t.log("hls.js instance disposed")}};function l(e){t.player.hls=new Hls({maxBufferLength:15,maxMaxBufferLength:60});t.player.hls.attachMedia(i);t.player.hls.on(Hls.Events.MEDIA_ATTACHED,(function(){t.player.hls.loadSource(e)}))}t.player.api.setSource=function(e){if(!t.player.hls){return}if(t.player.hls.url!=e){t.player.hls.destroy();l(e)}};t.player.api.setSubtitle=function(t){var e=i.getElementsByTagName("track");for(var r=e.length-1;r>=0;r--){i.removeChild(e[r])}if(t){var s=document.createElement("track");i.appendChild(s);s.kind="subtitles";s.label=t.label;s.srclang=t.lang;s.src=t.src;s.setAttribute("default","")}};function n(){l(t.source.url)}if("Hls"in window){n()}else{var p=t.urlappend(mistplayers.hlsjs.scriptsrc(t.options.host));MistUtil.scripts.insert(p,{onerror:function(e){var r="Failed to load hlsjs.js";if(e.message){r+=": "+e.message}t.showError(r)},onload:n},t)}e(i)};
mistplayers.hlsjs={name:"HLS.js player",mimes:["html5/application/vnd.apple.mpegurl","html5/application/vnd.apple.mpegurl;version=7"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(t){return this.mimes.indexOf(t)==-1?false:true},isBrowserSupported:function(t,e,r){if(location.protocol!=MistUtil.http.url.split(e.url).protocol){r.log("HTTP/HTTPS mismatch for this source");return false}if(!("MediaSource"in window)){return false}if(!MediaSource.isTypeSupported){return true}var i={};var s=false;for(var o in r.info.meta.tracks){if(r.info.meta.tracks[o].type=="meta"){if(r.info.meta.tracks[o].codec=="subtitle"){s=true}continue}if(!(r.info.meta.tracks[o].type in i)){i[r.info.meta.tracks[o].type]={}}i[r.info.meta.tracks[o].type][MistUtil.tracks.translateCodec(r.info.meta.tracks[o])]=1}var a=[];for(var l in i){var n=false;for(var p in i[l]){if(MediaSource.isTypeSupported('video/mp4;codecs="'+p+'"')){n=true;break}}if(n){a.push(l)}}if(s){for(var o in r.info.source){if(r.info.source[o].type=="html5/text/vtt"){a.push("subtitle");break}}}return a.length?a:false},player:function(){},scriptsrc:function(t){return t+"/hlsjs.js"}};var p=mistplayers.hlsjs.player;p.prototype=new MistPlayer;p.prototype.build=function(t,e){var r=this;var i=document.createElement("video");i.setAttribute("playsinline","");var s=["autoplay","loop","poster"];for(var o in s){var a=s[o];if(t.options[a]){i.setAttribute(a,t.options[a]===true?"":t.options[a])}}if(t.options.muted){i.muted=true}if(t.info.type=="live"){i.loop=false}if(t.options.controls=="stock"){i.setAttribute("controls","")}i.setAttribute("crossorigin","anonymous");this.setSize=function(t){i.style.width=t.width+"px";i.style.height=t.height+"px"};this.api=i;t.player.api.unload=function(){if(t.player.hls){t.player.hls.destroy();t.player.hls=false;t.log("hls.js instance disposed")}};function l(e){t.player.hls=new Hls({maxBufferLength:15,maxMaxBufferLength:60});t.player.hls.attachMedia(i);t.player.hls.on(Hls.Events.MEDIA_ATTACHED,function(){t.player.hls.loadSource(e)})}t.player.api.setSource=function(e){if(!t.player.hls){return}if(t.player.hls.url!=e){t.player.hls.destroy();l(e)}};t.player.api.setSubtitle=function(t){var e=i.getElementsByTagName("track");for(var r=e.length-1;r>=0;r--){i.removeChild(e[r])}if(t){var s=document.createElement("track");i.appendChild(s);s.kind="subtitles";s.label=t.label;s.srclang=t.lang;s.src=t.src;s.setAttribute("default","")}};function n(){l(t.source.url)}if("Hls"in window){n()}else{var p=t.urlappend(mistplayers.hlsjs.scriptsrc(t.options.host));MistUtil.scripts.insert(p,{onerror:function(e){var r="Failed to load hlsjs.js";if(e.message){r+=": "+e.message}t.showError(r)},onload:n},t)}e(i)};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -2555,6 +2555,7 @@ MistSkins["default"] = {
if (!window.chrome || !window.chrome.cast || !window.chrome.cast.isAvailable || (tries > 5)) {
if (ele.parentNode) { ele.parentNode.removeChild(ele); }
MistVideo.log("Chromecast is not supported");
console.warn(chrome,chrome.cast,chrome.cast ? chrome.cast.isAvailable : undefined,cast);
return;
}

View file

@ -213,7 +213,7 @@ namespace Secure{
}
/// Calculates a SHA256 digest as per NSAs SHA-2, returning it as binary.
/// Assumes output is big enough to contain 32 bytes of data.
/// Assumes output is big enough to contain 16 bytes of data.
void sha256bin(const char *input, const unsigned int in_len, char *output){
// Initialize the hash, according to MD5 spec.
uint32_t hash[] ={0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,

View file

@ -36,7 +36,7 @@
bool Util::Config::is_active = false;
bool Util::Config::is_restarting = false;
static int serv_sock_fd = -1;
static Socket::Server *serv_sock_pointer = 0;
uint32_t Util::printDebugLevel = DEBUG;
__thread char Util::streamName[256] = {0};
__thread char Util::exitReason[256] = {0};
@ -521,7 +521,7 @@ int Util::Config::serveThreadedSocket(int (*callback)(Socket::Connection &)){
return 1;
}
Socket::getSocketName(server_socket.getSocket(), Util::listenInterface, Util::listenPort);
serv_sock_fd = server_socket.getSocket();
serv_sock_pointer = &server_socket;
activate();
if (server_socket.getSocket()){
int oldSock = server_socket.getSocket();
@ -531,7 +531,7 @@ int Util::Config::serveThreadedSocket(int (*callback)(Socket::Connection &)){
}
}
int r = threadServer(server_socket, callback);
serv_sock_fd = -1;
serv_sock_pointer = 0;
return r;
}
@ -549,7 +549,7 @@ int Util::Config::serveForkedSocket(int (*callback)(Socket::Connection &S)){
return 1;
}
Socket::getSocketName(server_socket.getSocket(), Util::listenInterface, Util::listenPort);
serv_sock_fd = server_socket.getSocket();
serv_sock_pointer = &server_socket;
activate();
if (server_socket.getSocket()){
int oldSock = server_socket.getSocket();
@ -559,7 +559,7 @@ int Util::Config::serveForkedSocket(int (*callback)(Socket::Connection &S)){
}
}
int r = forkServer(server_socket, callback);
serv_sock_fd = -1;
serv_sock_pointer = 0;
return r;
}
@ -601,10 +601,6 @@ void Util::Config::setMutexAborter(void * mutex){
mutabort = (tthread::mutex*)mutex;
}
void Util::Config::setServerFD(int fd){
serv_sock_fd = fd;
}
/// Basic signal handler. Sets is_active to false if it receives
/// a SIGINT, SIGHUP or SIGTERM signal, reaps children for the SIGCHLD
/// signal, and ignores all other signals.
@ -614,7 +610,7 @@ void Util::Config::signal_handler(int signum, siginfo_t *sigInfo, void *ignore){
case SIGHUP:
case SIGTERM:
if (!mutabort || mutabort->try_lock()){
if (serv_sock_fd != -1){close(serv_sock_fd);}
if (serv_sock_pointer){serv_sock_pointer->close();}
if (mutabort){mutabort->unlock();}
}
#if DEBUG >= DLVL_DEVEL
@ -763,7 +759,6 @@ void Util::Config::addStandardPushCapabilities(JSON::Value &cap){
pp["track_selectors"]["type"] = "group";
pp["track_selectors"]["name"] = "Track selectors";
pp["track_selectors"]["help"] = "Control which tracks are part of the output";
pp["track_selectors"]["sort"] = "v";
{
JSON::Value & o = pp["track_selectors"]["options"];
o["audio"]["name"] = "Audio track(s)";
@ -788,7 +783,6 @@ void Util::Config::addStandardPushCapabilities(JSON::Value &cap){
pp["trackwait_opts"]["type"] = "group";
pp["trackwait_opts"]["name"] = "Wait for tracks";
pp["trackwait_opts"]["help"] = "Before starting, ensure the available tracks satisfy certain conditions";
pp["trackwait_opts"]["sort"] = "w";
{
JSON::Value & o = pp["trackwait_opts"]["options"];
o["waittrackcount"]["name"] = "Wait for tracks count";
@ -825,10 +819,37 @@ void Util::Config::addStandardPushCapabilities(JSON::Value &cap){
o["maxwaittrackms"]["sort"] = "bdad";
}
pp["pls_opts"]["type"] = "group";
pp["pls_opts"]["name"] = "Playlist writing options";
pp["pls_opts"]["help"] = "Control the writing of a playlist file when recording to a segmented format";
{
JSON::Value & o = pp["pls_opts"]["options"];
o["noendlist"]["name"] = "Don't end playlist";
o["noendlist"]["help"] = "If set, does not write #X-EXT-ENDLIST when finalizing the playlist on exit";
o["noendlist"]["type"] = "bool";
o["noendlist"]["format"] = "set_or_unset";
o["noendlist"]["sort"] = "bfa";
o["m3u8"]["name"] = "Playlist path (relative to segments)";
o["m3u8"]["help"] = "If set, will write a m3u8 playlist file for the segments to the given path (relative from the first segment path). When this parameter is used, at least one of the variables $segmentCounter or $currentMediaTime must be part of the segment path (to keep segments from overwriting each other). The \"Split interval\" parameter will default to 60 seconds when using this option.";
o["m3u8"]["type"] = "string";
o["m3u8"]["sort"] = "apa";
o["targetAge"]["name"] = "Playlist target age";
o["targetAge"]["help"] = "When writing a playlist, delete segment entries that are more than this many seconds old from the playlist (and, if possible, also delete said segments themselves). When set to 0 or left empty, does not delete.";
o["targetAge"]["type"] = "int";
o["targetAge"]["unit"] = "s";
o["targetAge"]["sort"] = "apb";
o["maxEntries"]["name"] = "Playlist max entries";
o["maxEntries"]["help"] = "When writing a playlist, delete oldest segment entries once this entry count has been reached (and, if possible, also delete said segments themselves). When set to 0 or left empty, does not delete.";
o["maxEntries"]["type"] = "int";
o["maxEntries"]["sort"] = "apc";
}
pp["time_opts"]["type"] = "group";
pp["time_opts"]["name"] = "Timing options";
pp["time_opts"]["help"] = "Control speed and the start/stop timing";
pp["time_opts"]["sort"] = "x";
{
JSON::Value & o = pp["time_opts"]["options"];
o["rate"]["name"] = "Playback rate";
@ -892,55 +913,17 @@ void Util::Config::addStandardPushCapabilities(JSON::Value &cap){
o["split"]["sort"] = "bh";
}
pp["pls_opts"]["type"] = "group";
pp["pls_opts"]["name"] = "Playlist writing options";
pp["pls_opts"]["help"] = "Control the writing of a playlist file when recording to a segmented format";
pp["pls_opts"]["sort"] = "y";
{
JSON::Value & o = pp["pls_opts"]["options"];
o["noendlist"]["name"] = "Don't end playlist";
o["noendlist"]["help"] = "If set, does not write #X-EXT-ENDLIST when finalizing the playlist on exit";
o["noendlist"]["type"] = "bool";
o["noendlist"]["format"] = "set_or_unset";
o["noendlist"]["sort"] = "bfa";
pp["unmask"]["name"] = "Unmask tracks";
pp["unmask"]["help"] = "If set to any value, removes any applied track masking before selecting tracks, acting as if no mask was applied at all";
pp["unmask"]["type"] = "bool";
pp["unmask"]["format"] = "set_or_unset";
pp["unmask"]["sort"] = "bc";
o["m3u8"]["name"] = "Playlist path (relative to segments)";
o["m3u8"]["help"] = "If set, will write a m3u8 playlist file for the segments to the given path (relative from the first segment path). When this parameter is used, at least one of the variables $segmentCounter or $currentMediaTime must be part of the segment path (to keep segments from overwriting each other). The \"Split interval\" parameter will default to 60 seconds when using this option.";
o["m3u8"]["type"] = "string";
o["m3u8"]["sort"] = "apa";
o["targetAge"]["name"] = "Playlist target age";
o["targetAge"]["help"] = "When writing a playlist, delete segment entries that are more than this many seconds old from the playlist (and, if possible, also delete said segments themselves). When set to 0 or left empty, does not delete.";
o["targetAge"]["type"] = "int";
o["targetAge"]["unit"] = "s";
o["targetAge"]["sort"] = "apb";
o["maxEntries"]["name"] = "Playlist max entries";
o["maxEntries"]["help"] = "When writing a playlist, delete oldest segment entries once this entry count has been reached (and, if possible, also delete said segments themselves). When set to 0 or left empty, does not delete.";
o["maxEntries"]["type"] = "int";
o["maxEntries"]["sort"] = "apc";
}
pp["misc_genopts"]["type"] = "group";
pp["misc_genopts"]["name"] = "Miscellaneous options";
pp["misc_genopts"]["sort"] = "z";
{
JSON::Value & o = pp["misc_genopts"]["options"];
o["unmask"]["name"] = "Unmask tracks";
o["unmask"]["help"] = "If set to any value, removes any applied track masking before selecting tracks, acting as if no mask was applied at all";
o["unmask"]["type"] = "bool";
o["unmask"]["format"] = "set_or_unset";
o["unmask"]["sort"] = "bc";
o["append"]["name"] = "Append to file";
o["append"]["help"] = "If set to any value, will (if possible) append to an existing file, rather than overwriting it";
o["append"]["type"] = "bool";
o["append"]["format"] = "set_or_unset";
o["append"]["sort"] = "bf";
}
pp["append"]["name"] = "Append to file";
pp["append"]["help"] = "If set to any value, will (if possible) append to an existing file, rather than overwriting it";
pp["append"]["type"] = "bool";
pp["append"]["format"] = "set_or_unset";
pp["append"]["sort"] = "bf";
}

View file

@ -38,7 +38,6 @@ namespace Util{
public:
static void setMutexAborter(void * mutex);
static void wipeShm();
static void setServerFD(int fd);
// variables
static bool is_active; ///< Set to true by activate(), set to false by the signal handler.
static bool is_restarting; ///< Set to true when restarting, set to false on boot.

View file

@ -27,7 +27,6 @@ headers = [
'mp4_generic.h',
'mp4.h',
'mp4_ms.h',
'mp4_stream.h',
'mpeg.h',
'nal.h',
'ogg.h',
@ -35,7 +34,6 @@ headers = [
'rtmpchunks.h',
'rtp_fec.h',
'rtp.h',
'segmentreader.h',
'sdp.h',
'sdp_media.h',
'shared_memory.h',
@ -98,7 +96,6 @@ libmist = library('mist',
'mp4_encryption.cpp',
'mp4_generic.cpp',
'mp4_ms.cpp',
'mp4_stream.cpp',
'mpeg.cpp',
'nal.cpp',
'ogg.cpp',
@ -106,7 +103,6 @@ libmist = library('mist',
'rtmpchunks.cpp',
'rtp_fec.cpp',
'rtp.cpp',
'segmentreader.cpp',
'sdp.cpp',
'sdp_media.cpp',
'shared_memory.cpp',

View file

@ -619,7 +619,7 @@ namespace MP4{
void containerBox::setContent(Box &newContent, uint32_t no){
int tempLoc = 0;
uint32_t contentCount = getContentCount();
unsigned int contentCount = getContentCount();
for (unsigned int i = 0; i < no; i++){
if (i < contentCount){
tempLoc += getBoxLen(tempLoc);
@ -646,24 +646,20 @@ namespace MP4{
}
Box containerBox::getChild(const char *boxName){
size_t maxLoc = boxedSize() - 8;
size_t tempLoc = payloadOffset;
while (tempLoc < maxLoc){
Box thisChild(data+tempLoc, false);
if (thisChild.isType(boxName)){return thisChild;}
tempLoc += calcBoxSize(data+tempLoc);
uint32_t count = getContentCount();
for (uint32_t i = 0; i < count; i++){
Box &thisChild = getContent(i);
if (thisChild.isType(boxName)){return Box(thisChild.asBox(), false);}
}
return Box((char *)"\000\000\000\010erro", false);
}
std::deque<Box> containerBox::getChildren(const char *boxName){
std::deque<Box> res;
size_t maxLoc = boxedSize() - 8;
size_t tempLoc = payloadOffset;
while (tempLoc < maxLoc){
Box thisChild(data+tempLoc, false);
if (thisChild.isType(boxName)){res.push_back(thisChild);}
tempLoc += calcBoxSize(data+tempLoc);
uint32_t count = getContentCount();
for (uint32_t i = 0; i < count; i++){
Box &thisChild = getContent(i);
if (thisChild.isType(boxName)){res.push_back(Box(thisChild.asBox(), false));}
}
return res;
}
@ -711,8 +707,8 @@ namespace MP4{
Box &containerFullBox::getContent(uint32_t no){
static Box ret = Box((char *)"\000\000\000\010erro", false);
if (no > getContentCount()){return ret;}
uint32_t i = 0;
size_t tempLoc = 4;
unsigned int i = 0;
int tempLoc = 4;
while (i < no){
tempLoc += getBoxLen(tempLoc);
i++;

View file

@ -61,13 +61,13 @@ namespace MP4{
void TRUN::setFlags(uint32_t newFlags){setInt24(newFlags, 1);}
uint32_t TRUN::getFlags() const {return getInt24(1);}
uint32_t TRUN::getFlags(){return getInt24(1);}
void TRUN::setDataOffset(uint32_t newOffset){
if (getFlags() & trundataOffset){setInt32(newOffset, 8);}
}
uint32_t TRUN::getDataOffset() const {
uint32_t TRUN::getDataOffset(){
if (getFlags() & trundataOffset){
return getInt32(8);
}else{
@ -84,7 +84,7 @@ namespace MP4{
}
}
uint32_t TRUN::getFirstSampleFlags() const {
uint32_t TRUN::getFirstSampleFlags(){
if (!(getFlags() & trunfirstSampleFlags)){return 0;}
if (getFlags() & trundataOffset){
return getInt32(12);
@ -93,7 +93,7 @@ namespace MP4{
}
}
uint32_t TRUN::getSampleInformationCount() const {return getInt32(4);}
uint32_t TRUN::getSampleInformationCount(){return getInt32(4);}
void TRUN::setSampleInformation(trunSampleInformation newSample, uint32_t no){
uint32_t flags = getFlags();
@ -125,7 +125,7 @@ namespace MP4{
if (getSampleInformationCount() < no + 1){setInt32(no + 1, 4);}
}
trunSampleInformation TRUN::getSampleInformation(uint32_t no, TFHD * tfhd, TREX * trex) const{
trunSampleInformation TRUN::getSampleInformation(uint32_t no){
trunSampleInformation ret;
ret.sampleDuration = 0;
ret.sampleSize = 0;
@ -140,42 +140,19 @@ namespace MP4{
if (flags & trunsampleOffsets){sampInfoSize += 4;}
uint32_t offset = 8;
if (flags & trundataOffset){offset += 4;}
if (flags & trunfirstSampleFlags){
if (!no){ret.sampleFlags = getFirstSampleFlags();}
offset += 4;
}
if (flags & trunfirstSampleFlags){offset += 4;}
uint32_t innerOffset = 0;
if (flags & trunsampleDuration){
ret.sampleDuration = getInt32(offset + no * sampInfoSize + innerOffset);
innerOffset += 4;
}else if (tfhd && (tfhd->getFlags() & tfhdSampleDura)){
ret.sampleDuration = tfhd->getDefaultSampleDuration();
}else if (trex){
ret.sampleDuration = trex->getDefaultSampleDuration();
}else{
WARN_MSG("Could not get sample duration from TRUN, TFHD or TREX box(es)!");
}
if (flags & trunsampleSize){
ret.sampleSize = getInt32(offset + no * sampInfoSize + innerOffset);
innerOffset += 4;
}else if (tfhd && (tfhd->getFlags() & tfhdSampleSize)){
ret.sampleSize = tfhd->getDefaultSampleSize();
}else if (trex){
ret.sampleSize = trex->getDefaultSampleSize();
}else{
WARN_MSG("Could not get sample size from TRUN, TFHD or TREX box(es)!");
}
if (flags & trunsampleFlags){
ret.sampleFlags = getInt32(offset + no * sampInfoSize + innerOffset);
innerOffset += 4;
}else if ((flags & trunfirstSampleFlags) && !no){
ret.sampleFlags = getFirstSampleFlags();
}else if (tfhd && (tfhd->getFlags() & tfhdSampleFlag)){
ret.sampleFlags = tfhd->getDefaultSampleFlags();
}else if (trex){
ret.sampleFlags = trex->getDefaultSampleFlags();
}else{
WARN_MSG("Could not get sample flags from TRUN, TFHD or TREX box(es)!");
}
if (flags & trunsampleOffsets){
ret.sampleOffset = getInt32(offset + no * sampInfoSize + innerOffset);
@ -184,7 +161,7 @@ namespace MP4{
return ret;
}
std::string TRUN::toPrettyString(uint32_t indent) const {
std::string TRUN::toPrettyString(uint32_t indent){
std::stringstream r;
r << std::string(indent, ' ') << "[trun] Track Fragment Run (" << boxedSize() << ")" << std::endl;
r << std::string(indent + 1, ' ') << "Version " << (int)getInt8(0) << std::endl;
@ -224,17 +201,17 @@ namespace MP4{
std::string prettySampleFlags(uint32_t flag){
std::stringstream r;
if (flag & noKeySample){
r << "noKeySample";
}else{
r << "isKeySample";
}
if (flag & noIPicture){r << " noIPicture";}
if (flag & isIPicture){r << " isIPicture";}
if (flag & noDisposable){r << " noDisposable";}
if (flag & isDisposable){r << " isDisposable";}
if (flag & isRedundant){r << " isRedundant";}
if (flag & noRedundant){r << " noRedundant";}
if (flag & noKeySample){
r << " noKeySample";
}else{
r << " isKeySample";
}
return r.str();
}
@ -2633,11 +2610,11 @@ namespace MP4{
void STSZ::setSampleSize(uint32_t newSampleSize){setInt32(newSampleSize, 4);}
uint32_t STSZ::getSampleSize() const {return getInt32(4);}
uint32_t STSZ::getSampleSize(){return getInt32(4);}
void STSZ::setSampleCount(uint32_t newSampleCount){setInt32(newSampleCount, 8);}
uint32_t STSZ::getSampleCount() const {return getInt32(8);}
uint32_t STSZ::getSampleCount(){return getInt32(8);}
void STSZ::setEntrySize(uint32_t newEntrySize, uint32_t no){
if (no + 1 > getSampleCount()){
@ -2649,7 +2626,7 @@ namespace MP4{
setInt32(newEntrySize, 12 + no * 4);
}
uint32_t STSZ::getEntrySize(uint32_t no) const {
uint32_t STSZ::getEntrySize(uint32_t no){
if (no >= getSampleCount()){return 0;}
long unsigned int retVal = getInt32(12 + no * 4);
if (retVal == 0){

View file

@ -39,53 +39,6 @@ namespace MP4{
std::string toPrettyString(uint32_t indent = 0);
};
enum tfhdflags{
tfhdBaseOffset = 0x000001,
tfhdSampleDesc = 0x000002,
tfhdSampleDura = 0x000008,
tfhdSampleSize = 0x000010,
tfhdSampleFlag = 0x000020,
tfhdNoDuration = 0x010000,
tfhdBaseIsMoof = 0x020000,
};
class TFHD : public Box{
public:
TFHD();
void setFlags(uint32_t newFlags);
uint32_t getFlags();
void setTrackID(uint32_t newID);
uint32_t getTrackID();
void setBaseDataOffset(uint64_t newOffset);
uint64_t getBaseDataOffset();
void setSampleDescriptionIndex(uint32_t newIndex);
uint32_t getSampleDescriptionIndex();
void setDefaultSampleDuration(uint32_t newDuration);
uint32_t getDefaultSampleDuration();
void setDefaultSampleSize(uint32_t newSize);
uint32_t getDefaultSampleSize();
void setDefaultSampleFlags(uint32_t newFlags);
uint32_t getDefaultSampleFlags();
bool getDefaultBaseIsMoof();
std::string toPrettyString(uint32_t indent = 0);
};
class TREX : public fullBox{
public:
TREX(unsigned int trackId = 0);
void setTrackID(uint32_t newTrackID);
uint32_t getTrackID();
void setDefaultSampleDescriptionIndex(uint32_t newDefaultSampleDescriptionIndex);
uint32_t getDefaultSampleDescriptionIndex();
void setDefaultSampleDuration(uint32_t newDefaultSampleDuration);
uint32_t getDefaultSampleDuration();
void setDefaultSampleSize(uint32_t newDefaultSampleSize);
uint32_t getDefaultSampleSize();
void setDefaultSampleFlags(uint32_t newDefaultSampleFlags);
uint32_t getDefaultSampleFlags();
std::string toPrettyString(uint32_t indent = 0);
};
struct trunSampleInformation {
uint32_t sampleDuration;
uint32_t sampleSize;
@ -116,15 +69,45 @@ namespace MP4{
public:
TRUN();
void setFlags(uint32_t newFlags);
uint32_t getFlags() const;
uint32_t getFlags();
void setDataOffset(uint32_t newOffset);
uint32_t getDataOffset() const;
uint32_t getDataOffset();
void setFirstSampleFlags(uint32_t newSampleFlags);
uint32_t getFirstSampleFlags() const;
uint32_t getSampleInformationCount() const;
uint32_t getFirstSampleFlags();
uint32_t getSampleInformationCount();
void setSampleInformation(trunSampleInformation newSample, uint32_t no);
trunSampleInformation getSampleInformation(uint32_t no, TFHD * tfhd = 0, TREX * trex = 0) const;
std::string toPrettyString(uint32_t indent = 0) const;
trunSampleInformation getSampleInformation(uint32_t no);
std::string toPrettyString(uint32_t indent = 0);
};
enum tfhdflags{
tfhdBaseOffset = 0x000001,
tfhdSampleDesc = 0x000002,
tfhdSampleDura = 0x000008,
tfhdSampleSize = 0x000010,
tfhdSampleFlag = 0x000020,
tfhdNoDuration = 0x010000,
tfhdBaseIsMoof = 0x020000,
};
class TFHD : public Box{
public:
TFHD();
void setFlags(uint32_t newFlags);
uint32_t getFlags();
void setTrackID(uint32_t newID);
uint32_t getTrackID();
void setBaseDataOffset(uint64_t newOffset);
uint64_t getBaseDataOffset();
void setSampleDescriptionIndex(uint32_t newIndex);
uint32_t getSampleDescriptionIndex();
void setDefaultSampleDuration(uint32_t newDuration);
uint32_t getDefaultSampleDuration();
void setDefaultSampleSize(uint32_t newSize);
uint32_t getDefaultSampleSize();
void setDefaultSampleFlags(uint32_t newFlags);
uint32_t getDefaultSampleFlags();
bool getDefaultBaseIsMoof();
std::string toPrettyString(uint32_t indent = 0);
};
class AVCC : public Box{
@ -329,6 +312,22 @@ namespace MP4{
MVEX();
};
class TREX : public fullBox{
public:
TREX(unsigned int trackId = 0);
void setTrackID(uint32_t newTrackID);
uint32_t getTrackID();
void setDefaultSampleDescriptionIndex(uint32_t newDefaultSampleDescriptionIndex);
uint32_t getDefaultSampleDescriptionIndex();
void setDefaultSampleDuration(uint32_t newDefaultSampleDuration);
uint32_t getDefaultSampleDuration();
void setDefaultSampleSize(uint32_t newDefaultSampleSize);
uint32_t getDefaultSampleSize();
void setDefaultSampleFlags(uint32_t newDefaultSampleFlags);
uint32_t getDefaultSampleFlags();
std::string toPrettyString(uint32_t indent = 0);
};
class MFRA : public containerBox{
public:
MFRA();
@ -642,11 +641,11 @@ namespace MP4{
public:
STSZ(char v = 1, uint32_t f = 0);
void setSampleSize(uint32_t newSampleSize);
uint32_t getSampleSize() const;
uint32_t getSampleSize();
void setSampleCount(uint32_t newSampleCount);
uint32_t getSampleCount() const;
uint32_t getSampleCount();
void setEntrySize(uint32_t newEntrySize, uint32_t no);
uint32_t getEntrySize(uint32_t no) const;
uint32_t getEntrySize(uint32_t no);
std::string toPrettyString(uint32_t indent = 0);
};

View file

@ -1,508 +0,0 @@
#include "mp4_stream.h"
#include "h264.h"
#include "mp4_dash.h"
namespace MP4{
Stream::Stream(){
}
Stream::~Stream(){
}
void Stream::open(Util::ResizeablePointer & ptr){
}
bool Stream::hasPacket(size_t tid) const{
return false;
}
bool Stream::hasPacket() const{
return !curPositions.empty();
}
void Stream::getPacket(size_t tid, DTSC::Packet &pack, uint64_t &thisTime, size_t &thisIdx){
}
uint32_t Stream::getEarliestPID(){
return INVALID_TRACK_ID;
}
void Stream::getEarliestPacket(DTSC::Packet &pack, uint64_t &thisTime, size_t &thisIdx){
if (curPositions.empty()){
pack.null();
return;
}
// pop uit set
MP4::PartTime curPart = *curPositions.begin();
curPositions.erase(curPositions.begin());
thisTime = curPart.time;
thisIdx = curPart.trackID;
pack.genericFill(curPart.time, curPart.offset, curPart.trackID, 0/*readBuffer + (curPart.bpos-readPos)*/, curPart.size, 0, curPart.keyframe);
// get the next part for this track
curPart.index++;
if (curPart.index < trkHdrs[curPart.trackID].size()){
trkHdrs[curPart.trackID].getPart(curPart.index, &curPart.bpos, &curPart.size, &curPart.time, &curPart.offset, &curPart.keyframe);
curPositions.insert(curPart);
}
}
void Stream::initializeMetadata(DTSC::Meta &meta, size_t tid, size_t mappingId){
}
TrackHeader::TrackHeader(){
timeIndex = timeSample = timeFirstSample = timeTotal = timeExtra = 0;
bposIndex = bposSample = 0;
offsetIndex = offsetSample = 0;
keyIndex = keySample = 0;
hasOffsets = false;
hasKeys = false;
isVideo = false;
sttsBox.clear();
cttsBox.clear();
stszBox.clear();
stcoBox.clear();
co64Box.clear();
stscBox.clear();
stssBox.clear();
trexBox.clear();
trexPtr = 0;
stco64 = false;
trafMode = false;
trackId = 0;
}
void TrackHeader::nextMoof(){
timeIndex = timeSample = timeFirstSample = timeTotal = timeExtra = 0;
bposIndex = bposSample = 0;
offsetIndex = offsetSample = 0;
trafMode = true;
trafs.clear();
}
/// Switch back to non-moof reading mode, disabling TRAF mode and wiping all TRAF boxes
void TrackHeader::revertToMoov(){
timeIndex = timeSample = timeFirstSample = timeTotal = timeExtra = 0;
bposIndex = bposSample = 0;
offsetIndex = offsetSample = 0;
keyIndex = keySample = 0;
trafMode = false;
trafs.clear();
}
void TrackHeader::read(TREX &_trexBox){
trexBox.copyFrom(_trexBox);
if (trexBox.isType("trex")){trexPtr = &trexBox;}
}
void TrackHeader::read(TRAK &trakBox){
vidWidth = vidHeight = audChannels = audRate = audSize = 0;
codec.clear();
MDIA mdiaBox = trakBox.getChild<MDIA>();
timeScale = mdiaBox.getChild<MDHD>().getTimeScale();
lang = mdiaBox.getChild<MP4::MDHD>().getLanguage();
TKHD tkhd = trakBox.getChild<TKHD>();
trackId = tkhd.getTrackID();
if (tkhd.getWidth()){
vidWidth = tkhd.getWidth();
vidHeight = tkhd.getHeight();
}
STBL stblBox = mdiaBox.getChild<MINF>().getChild<STBL>();
sttsBox.copyFrom(stblBox.getChild<STTS>());
cttsBox.copyFrom(stblBox.getChild<CTTS>());
hasOffsets = cttsBox.isType("ctts");
stszBox.copyFrom(stblBox.getChild<STSZ>());
stcoBox.copyFrom(stblBox.getChild<STCO>());
co64Box.copyFrom(stblBox.getChild<CO64>());
stco64 = co64Box.isType("co64");
stscBox.copyFrom(stblBox.getChild<STSC>());
stssBox.copyFrom(stblBox.getChild<STSS>());
hasKeys = stssBox.isType("stss");
Box sEntryBox = stblBox.getChild<MP4::STSD>().getEntry(0);
sType = sEntryBox.getType();
std::string handler = mdiaBox.getChild<MP4::HDLR>().getHandlerType();
isVideo = false;
if (handler == "vide"){
isVideo = true;
trackType = "video";
}else if (handler == "soun"){
trackType = "audio";
}else if (handler == "sbtl"){
trackType = "meta";
}else{
INFO_MSG("Unsupported handler: %s", handler.c_str());
}
isCompatible = false;
if (sType == "avc1" || sType == "h264" || sType == "mp4v"){
codec = "H264";
isCompatible = true;
VisualSampleEntry &vEntryBox = (VisualSampleEntry &)sEntryBox;
if (!vidWidth){
vidWidth = vEntryBox.getWidth();
vidHeight = vEntryBox.getHeight();
}
MP4::Box initBox = vEntryBox.getCLAP();
if (initBox.isType("avcC")){initData.assign(initBox.payload(), initBox.payloadSize());}
initBox = vEntryBox.getPASP();
if (initBox.isType("avcC")){initData.assign(initBox.payload(), initBox.payloadSize());}
// Read metadata from init data if not set
if (!vidWidth){
h264::sequenceParameterSet sps;
sps.fromDTSCInit(initData);
h264::SPSMeta spsChar = sps.getCharacteristics();
vidWidth = spsChar.width;
vidHeight = spsChar.height;
}
}
if (sType == "hev1" || sType == "hvc1"){
codec = "HEVC";
isCompatible = true;
MP4::VisualSampleEntry &vEntryBox = (MP4::VisualSampleEntry &)sEntryBox;
if (!vidWidth){
vidWidth = vEntryBox.getWidth();
vidHeight = vEntryBox.getHeight();
}
MP4::Box initBox = vEntryBox.getCLAP();
if (initBox.isType("hvcC")){initData.assign(initBox.payload(), initBox.payloadSize());}
initBox = vEntryBox.getPASP();
if (initBox.isType("hvcC")){initData.assign(initBox.payload(), initBox.payloadSize());}
}
if (sType == "av01"){
codec = "AV1";
isCompatible = true;
MP4::VisualSampleEntry &vEntryBox = (MP4::VisualSampleEntry &)sEntryBox;
if (!vidWidth){
vidWidth = vEntryBox.getWidth();
vidHeight = vEntryBox.getHeight();
}
MP4::Box initBox = vEntryBox.getCLAP();
if (initBox.isType("av1C")){initData.assign(initBox.payload(), initBox.payloadSize());}
initBox = vEntryBox.getPASP();
if (initBox.isType("av1C")){initData.assign(initBox.payload(), initBox.payloadSize());}
}
if (sType == "mp4a" || sType == "aac " || sType == "ac-3"){
MP4::AudioSampleEntry &aEntryBox = (MP4::AudioSampleEntry &)sEntryBox;
audRate = aEntryBox.getSampleRate();
audChannels = aEntryBox.getChannelCount();
audSize = 16; /// \TODO Actually get this from somewhere, probably..?
if (sType == "ac-3"){
codec = "AC3";
isCompatible = true;
}else{
MP4::Box codingBox = aEntryBox.getCodecBox();
if (codingBox.getType() == "esds"){
MP4::ESDS & esdsBox = (MP4::ESDS &)codingBox;
codec = esdsBox.getCodec();
isCompatible = true;
initData = esdsBox.getInitData();
}
if (codingBox.getType() == "wave"){
MP4::WAVE & waveBox = (MP4::WAVE &)codingBox;
for (size_t c = 0; c < waveBox.getContentCount(); ++c){
MP4::Box content = waveBox.getContent(c);
if (content.getType() == "esds"){
MP4::ESDS & esdsBox = (MP4::ESDS &)content;
codec = esdsBox.getCodec();
isCompatible = true;
initData = esdsBox.getInitData();
}
}
}
}
}
if (sType == "tx3g"){// plain text subtitles
codec = "subtitle";
isCompatible = true;
}
}
void TrackHeader::read(TRAF &trafBox){
if (!trafMode){
// Warn anyone that forgot to call nextMoof(), hopefully preventing future issues
WARN_MSG("Reading TRAF box header without signalling start of next MOOF box first!");
}
TRAF tBox;
trafs.push_back(tBox);
trafs.rbegin()->copyFrom(trafBox);
}
void TrackHeader::increaseTime(uint32_t delta){
// Calculate millisecond-time for current timestamp
uint64_t timePrev = (timeTotal * 1000) / timeScale;
timeTotal += delta;
//Undo time shifts as much as possible
if (timeExtra){
timeTotal -= timeExtra;
timeExtra = 0;
}
//Make sure our timestamps go up by at least 1ms for every packet
if (timePrev >= (uint64_t)((timeTotal * 1000) / timeScale)){
uint32_t wantSamples = ((timePrev+1) * timeScale) / 1000;
timeExtra += wantSamples - timeTotal;
timeTotal = wantSamples;
}
++timeSample;
}
uint64_t TrackHeader::size() const {
if (!trafMode){
return (stszBox ? stszBox.getSampleCount() : 0);
}
if (!trafs.size()){return 0;}
uint64_t parts = 0;
for (std::deque<TRAF>::const_iterator t = trafs.begin(); t != trafs.end(); ++t){
std::deque<TRUN> runs = ((TRAF)(*t)).getChildren<TRUN>();
for (std::deque<TRUN>::const_iterator r = runs.begin(); r != runs.end(); ++r){
parts += r->getSampleInformationCount();
}
}
return parts;
}
/// Retrieves the information associated with a specific part (=frame).
/// The index is the zero-based part number, all other arguments are optional and if non-zero will be filled.
void TrackHeader::getPart(uint64_t index, uint64_t * byteOffset, uint32_t * byteLen, uint64_t * time, int32_t * timeOffset, bool * keyFrame, uint64_t moofPos){
// Switch between reading TRAF boxes or global headers
if (!trafMode){
// Reading global headers
// Calculate time, if requested
if (time){
// If we went backwards, reset our current position
if (index < timeSample){
timeIndex = timeFirstSample = timeSample = timeExtra = timeTotal = 0;
}
// Find the packet count per chunk entry for this sample
uint64_t eCnt = sttsBox.getEntryCount();
STTSEntry entry;
while (timeIndex < eCnt){
entry = sttsBox.getSTTSEntry(timeIndex);
// check where the next index starts
uint64_t nextSampleIndex = timeFirstSample + entry.sampleCount;
// If the next chunk starts with a higher sample than we want, we can stop here
if (nextSampleIndex > index){break;}
timeFirstSample = nextSampleIndex;
// Increase timestamp by delta for each sample with the same delta
while (timeSample < nextSampleIndex){increaseTime(entry.sampleDelta);}
++timeIndex;
}
// Inside the samples with the same delta, we may still need to increase the timestamp.
while (timeSample < index){increaseTime(entry.sampleDelta);}
*time = (timeTotal * 1000) / timeScale;
}
// Look up time offset, if requested and available
if (timeOffset){
if (hasOffsets){
// If we went backwards, reset our current position
if (index < offsetSample){
offsetIndex = offsetSample = 0;
}
// Find the packet count per chunk entry for this sample
uint64_t eCnt = cttsBox.getEntryCount();
CTTSEntry entry;
while (offsetIndex < eCnt){
entry = cttsBox.getCTTSEntry(offsetIndex);
// check where the next index starts
uint64_t nextSampleIndex = offsetSample + entry.sampleCount;
// If the next chunk starts with a higher sample than we want, we can stop here
if (nextSampleIndex > index){break;}
offsetSample = nextSampleIndex;
++offsetIndex;
}
*timeOffset = (entry.sampleOffset * 1000) / timeScale;
}else{
// Default to zero if there are no offsets for this track
*timeOffset = 0;
}
}
// Look up keyframe-ness, if requested and available
if (keyFrame){
if (!isVideo){
// Non-video tracks are never keyframes
*keyFrame = false;
}else{
// Video tracks with keys follow them
if (hasKeys){
// If we went backwards, reset our current position
if (index < keySample){
keyIndex = keySample = 0;
}
// Find the packet count per chunk entry for this sample
uint64_t eCnt = stssBox.getEntryCount();
while (keyIndex < eCnt){
// check where the next index starts
uint64_t nextSampleIndex;
if (keyIndex + 1 < eCnt){
nextSampleIndex = stssBox.getSampleNumber(keyIndex + 1) - 1;
}else{
nextSampleIndex = stszBox.getSampleCount();
}
// If the next key has a higher sample than we want, we can stop here
if (nextSampleIndex > index){break;}
keySample = nextSampleIndex;
++keyIndex;
}
*keyFrame = (keySample == index);
}else{
// Everything is a keyframe if there are no keys listed for a video track
*keyFrame = true;
}
}
}
// Calculate byte position of packet, if requested
if (byteOffset){
// If we went backwards, reset our current position
if (index < bposSample){
bposIndex = bposSample = 0;
}
// Find the packet count per chunk entry for this sample
uint64_t eCnt = stscBox.getEntryCount();
STSCEntry entry;
while (bposIndex < eCnt){
entry = stscBox.getSTSCEntry(bposIndex);
// check where the next index starts
uint64_t nextSampleIndex;
if (bposIndex + 1 < eCnt){
nextSampleIndex = bposSample + (stscBox.getSTSCEntry(bposIndex + 1).firstChunk - entry.firstChunk) *
entry.samplesPerChunk;
}else{
nextSampleIndex = stszBox.getSampleCount();
}
// If the next chunk starts with a higher sample than we want, we can stop here
if (nextSampleIndex > index){break;}
bposSample = nextSampleIndex;
++bposIndex;
}
// Find the chunk index the sample is in
uint64_t chunkIndex = (entry.firstChunk - 1) + ((index - bposSample) / entry.samplesPerChunk);
// Set offset to position of start of this chunk
*byteOffset = (stco64 ? co64Box.getChunkOffset(chunkIndex) : stcoBox.getChunkOffset(chunkIndex));
// Increase the offset by all samples in the chunk we already passed to arrive at our current sample
uint64_t sampleStart = bposSample + (chunkIndex - (entry.firstChunk - 1)) * entry.samplesPerChunk;
for (int j = sampleStart; j < index; j++){*byteOffset += stszBox.getEntrySize(j);}
}
// Look up byte length of packet, if requested
if (byteLen){
*byteLen = stszBox.getEntrySize(index);
}
// Specifically for text tracks, remove the 2-byte header if possible
if (byteOffset && byteLen && *byteLen >= 2 && sType == "tx3g"){
*byteLen -= 2;
*byteOffset += 2;
}
}else{
// Reading from TRAF boxes
size_t skipped = 0;
for (std::deque<TRAF>::const_iterator t = trafs.begin(); t != trafs.end(); ++t){
size_t firstTRAFIndex = skipped;
std::deque<TRUN> runs = ((TRAF)(*t)).getChildren<TRUN>();
for (std::deque<TRUN>::const_iterator r = runs.begin(); r != runs.end(); ++r){
uint32_t count = r->getSampleInformationCount();
if (index >= skipped + count){
skipped += count;
continue;
}
// Okay, our index is inside this TRUN!
// Let's pull the TFHD box into this as well...
TFHD tfhd = ((TRAF)(*t)).getChild<TFHD>();
trunSampleInformation si = r->getSampleInformation(index - skipped, &tfhd, trexPtr);
if (byteOffset){
size_t offset = 0;
if (tfhd.getDefaultBaseIsMoof()){
offset += moofPos;
}
if (r->getFlags() & MP4::trundataOffset){
offset += r->getDataOffset();
size_t target = index - skipped;
for (size_t i = 0; i < target; ++i){
offset += r->getSampleInformation(i, &tfhd, trexPtr).sampleSize;
}
}else{
FAIL_MSG("Unimplemented: trun box does not contain a data offset!");
}
*byteOffset = offset;
}
if (time){
// If we went backwards, reset our current position
if (!index || index < timeSample){
timeIndex = timeFirstSample = timeSample = timeExtra = 0;
TFDT tfdt = ((TRAF)(*t)).getChild<TFDT>();
timeTotal = tfdt.getBaseMediaDecodeTime();
}
std::deque<TRUN>::const_iterator runIt = runs.begin();
uint32_t locCount = runIt->getSampleInformationCount();
size_t locSkipped = firstTRAFIndex;
while (timeSample < index){
// Most common case: timeSample is in the current TRUN box
if (timeSample >= skipped && timeSample < skipped + count){
trunSampleInformation i = r->getSampleInformation(timeSample - skipped, &tfhd, trexPtr);
increaseTime(i.sampleDuration);
continue;
}
// Less common case: everything else
// Ensure "runIt" points towards the TRUN box that index "timeSample" is in
while (timeSample >= locSkipped + locCount && runIt != runs.end()){
locSkipped += locCount;
runIt++;
locCount = runIt->getSampleInformationCount();
}
// Abort increase if we can't find the box. This _should_ never happen...
if (runIt == runs.end()){
WARN_MSG("Attempted to read time information from a TRAF box that did not contain the sample we're reading!");
break;
}
// Cool, now we know it's valid, increase the time accordingly.
trunSampleInformation i = runIt->getSampleInformation(timeSample - locSkipped, &tfhd, trexPtr);
increaseTime(i.sampleDuration);
}
*time = (timeTotal * 1000) / timeScale;
}
if (byteLen){
*byteLen = si.sampleSize;
}
if (timeOffset){
*timeOffset = (si.sampleOffset * 1000) / timeScale;
}
if (keyFrame){
*keyFrame = !(si.sampleFlags & MP4::noKeySample);
}
return;
}
}
}
}
} // namespace MP4

View file

@ -1,123 +0,0 @@
#include "dtsc.h"
#include "util.h"
#include "mp4_generic.h"
namespace MP4{
class PartTime{
public:
PartTime() : time(0), duration(0), offset(0), trackID(0), bpos(0), size(0), index(0){}
bool operator<(const PartTime &rhs) const{
if (time < rhs.time){return true;}
if (time > rhs.time){return false;}
if (trackID < rhs.trackID){return true;}
return (trackID == rhs.trackID && bpos < rhs.bpos);
}
uint64_t time;
uint64_t duration;
int32_t offset;
size_t trackID;
uint64_t bpos;
uint32_t size;
uint64_t index;
bool keyframe;
};
class TrackHeader{
public:
TrackHeader();
/// Reads (new) track header information for processing
void read(TRAK &trakBox);
/// Reads (new) track header information for processing
void read(TREX &trexBox);
/// Reads (new) track header information for processing
void read(TRAF &trafBox);
/// Signal that we're going to be reading the next moof box now.
/// Wipes internal TRAF boxes, ensures TRAF mode is enabled so no reads happen from MOOV headers anymore.
void nextMoof();
/// Switch back to non-moof reading mode, disabling TRAF mode and wiping all TRAF boxes
void revertToMoov();
/// Returns true if we know how to parse this track, false otherwise
bool compatible() const {return isCompatible;}
/// Retrieves the information associated with a specific part (=frame).
void getPart(uint64_t index, uint64_t * byteOffset = 0, uint32_t * byteLen = 0, uint64_t * time = 0, int32_t * timeOffset = 0, bool * keyFrame = 0, uint64_t moofPos = 0);
/// Returns the number of parts this track header contains
uint64_t size() const;
// Information about the track. Public for convenience, but setting them has no effect.
// The exception is sType, which affects processing of the data in some cases and should not be written to.
// All of these are filled by the read() function when reading an MP4::TRAK box.
size_t trackId; ///< MP4-internal ID for this track
uint64_t timeScale; ///< Timescale in units per second
std::string sType; ///< MP4-internal codec name for this track - do not write to externally!
std::string codec; ///< Mist codec name for this track
std::string trackType; ///< Which Mist-compatible track type this is
std::string initData; ///< Initialization data for the track, in Mist-compatible format
std::string lang; ///< Language of the track
uint32_t vidWidth, vidHeight;
uint32_t audChannels, audRate, audSize;
private:
/// Internal function that increases the time of the current part to the next part
void increaseTime(uint32_t delta);
// next variables are needed for the stsc/stco loop
uint64_t bposIndex; ///< Current read index in stsc box
uint64_t bposSample; ///< First sample number in current chunk entry
// next variables are needed for the stts loop
uint64_t timeIndex; ///< Index in STTS box
uint64_t timeSample; ///< Sample counter for STTS box
uint64_t timeFirstSample; ///< First sample in STTS box entry
uint64_t timeTotal; ///< Total timestamp for STTS box
uint64_t timeExtra; ///< Extra timestamp for STTS box
uint64_t offsetIndex; ///< Index in CTTS box
uint64_t offsetSample; ///< First sample number in CTTS entry
uint64_t keyIndex; ///< Index in stss box
uint64_t keySample; ///< First sample number in stss entry
STSS stssBox; ///< keyframe list
STCO stcoBox; ///< positions of chunks (32-bit)
CO64 co64Box; ///< positions of chunks (64-bit)
STSZ stszBox; ///< packet sizes
STTS sttsBox; ///< packet durations
CTTS cttsBox; ///< packet time offsets (optional)
STSC stscBox; ///< packet count per chunk
TREX trexBox; ///< packet count per chunk
TREX * trexPtr; ///< Either 0 or pointer to trexBox member
std::deque<TRAF> trafs; ///< Current traf boxes, if any
bool stco64; // 64 bit chunk offsets?
bool hasOffsets; ///< Are time offsets present?
bool hasKeys; ///< Are keyframes listed?
bool isVideo; ///< Is this a video track?
bool isCompatible; ///< True if Mist supports this track type
bool trafMode; ///< True if we are ignoring the moov headers and only looking at traf headers
};
class Stream{
public:
Stream();
~Stream();
void open(Util::ResizeablePointer & ptr);
bool hasPacket(size_t tid) const;
bool hasPacket() const;
void getPacket(size_t tid, DTSC::Packet &pack, uint64_t &thisTime, size_t &thisIdx);
uint32_t getEarliestPID();
void getEarliestPacket(DTSC::Packet &pack, uint64_t &thisTime, size_t &thisIdx);
void initializeMetadata(DTSC::Meta &meta, size_t tid = INVALID_TRACK_ID, size_t mappingId = INVALID_TRACK_ID);
private:
std::map<size_t, TrackHeader> trkHdrs;
std::map<size_t, std::string> codecs;
std::set<MP4::PartTime> curPositions;
MOOV moovBox;
Box mdatBox;
};
} // namespace MP4

View file

@ -1,437 +0,0 @@
#include "segmentreader.h"
#include "timing.h"
#ifdef SSL
#include "mbedtls/aes.h"
#endif
/// Helper function for printing encryption keys in hex format
static std::string printhex(const char *data, size_t len){
static const char *const lut = "0123456789ABCDEF";
std::string output;
output.reserve(2 * len);
for (size_t i = 0; i < len; ++i){
const unsigned char c = data[i];
output.push_back(lut[c >> 4]);
output.push_back(lut[c & 15]);
}
return output;
}
namespace Mist{
SegmentReader::SegmentReader(){
progressCallback = 0;
isOpen = false;
#ifdef SSL
encrypted = false;
#endif
currBuf = 0;
packetPtr = 0;
mp4PacksLeft = 0;
lastMoof = 0;
}
void SegmentReader::onProgress(bool (*callback)(uint8_t)){
progressCallback = callback;
segDL.onProgress(callback);
}
void SegmentReader::reset(){
tsStream.clear();
}
/// Reads the segment at least up to position _offset.
/// Returns true if the position is available, false otherwise.
bool SegmentReader::readTo(size_t _offset){
// Have it? Return true right away
if (currBuf->size() >= _offset){return true;}
// Buffered? Just return false - we can't download more.
if (buffered){return false;}
// Past end of file? Always return false.
if (_offset > currBuf->rsize()){return false;}
#ifdef SSL
// Encrypted? Round up to nearest multiple of 16
if (encrypted && _offset % 16){
_offset = ((size_t)(_offset / 16) + 1) * 16;
// Clip to size of file
if (_offset > currBuf->rsize()){_offset = currBuf->rsize();}
}
#endif
// Attempt to download what we need
size_t retries = 0;
while (currBuf->size() < _offset){
size_t preSize = getDataCallbackPos();
if (!segDL){
if (!segDL.isSeekable()){return false;}
// Only retry/resume if seekable and allocated size greater than current size
if (currBuf->rsize() > currBuf->size()){
// Seek to current position to resume
if (retries++ > 5){
segDL.close();
return false;
}
segDL.seek(getDataCallbackPos());
}
}
segDL.readSome(_offset - currBuf->size(), *this);
// Sleep if we made no progress
if (getDataCallbackPos() == preSize){
Util::sleep(5);
if (progressCallback && !progressCallback(0)){return false;}
}
}
return true;
}
void SegmentReader::initializeMetadata(DTSC::Meta &meta, size_t tid, size_t mappingId){
if (parser == STRM_TS){
tsStream.initializeMetadata(meta, tid, mappingId);
return;
}
if (parser == STRM_MP4){
for (std::deque<MP4::TrackHeader>::iterator it = mp4Headers.begin(); it != mp4Headers.end(); ++it){
if (it->trackId != tid){continue;}
size_t tNumber = meta.addTrack();
INFO_MSG("Found track %zu of type %s -> %s", tNumber, it->sType.c_str(), it->codec.c_str());
meta.setID(tNumber, mappingId);
meta.setCodec(tNumber, it->codec);
meta.setInit(tNumber, it->initData);
meta.setLang(tNumber, it->lang);
if (it->trackType == "video"){
meta.setType(tNumber, "video");
meta.setWidth(tNumber, it->vidWidth);
meta.setHeight(tNumber, it->vidHeight);
}
if (it->trackType == "audio"){
meta.setType(tNumber, "audio");
meta.setChannels(tNumber, it->audChannels);
meta.setRate(tNumber, it->audRate);
meta.setSize(tNumber, it->audSize);
}
}
return;
}
}
/// Attempts to read a single TS packet from the current segment, setting packetPtr on success
bool SegmentReader::readNext(DTSC::Packet & thisPacket, uint64_t bytePos){
while (*this){
if (parser == STRM_UNKN){
if (!readTo(189)){
WARN_MSG("File format detection failed: could not read at least 189 bytes!");
return false;
}
if ((*currBuf)[0] == 0x47 && (*currBuf)[188] == 0x47){
parser = STRM_TS;
continue;
}
if (!memcmp(*currBuf + 4, "ftyp", 4) || !memcmp(*currBuf + 4, "styp", 4) || !memcmp(*currBuf + 4, "moof", 4) || !memcmp(*currBuf + 4, "moov", 4)){
parser = STRM_MP4;
continue;
}
WARN_MSG("File format detection failed: unable to recognize file format!");
return false;
}
if (parser == STRM_TS){
if (currBuf->size() == currBuf->rsize() && offset + 188 > currBuf->size()){tsStream.finish();}
if (tsStream.hasPacketOnEachTrack() || (currBuf->size() == currBuf->rsize() && offset + 188 > currBuf->size())){
if (!tsStream.hasPacket()){return false;}
tsStream.getEarliestPacket(thisPacket);
return true;
}
if (!readTo(offset + 188)){return false;}
tsStream.parse(*currBuf + offset, bytePos);
offset += 188;
}
if (parser == STRM_MP4){
if (mp4PacksLeft){
std::deque<size_t>::iterator pIt = mp4PackNo.begin();
for (std::deque<MP4::TrackHeader>::iterator it = mp4Headers.begin(); it != mp4Headers.end(); ++it){
if (*pIt < it->size()){
uint64_t prtBpos = 0, prtTime = 0;
uint32_t prtBlen = 0;
int32_t prtTimeOff = 0;
bool prtKey = false;
it->getPart(*pIt, &prtBpos, &prtBlen, &prtTime, &prtTimeOff, &prtKey, lastMoof);
// Increase/decrease counters
--mp4PacksLeft;
++(*pIt);
// Abort reading if we cannot read this part, try the next part
if (!readTo(prtBpos + prtBlen)){continue;}
// Fill the packet and return true
thisPacket.genericFill(prtTime, prtTimeOff, it->trackId, *currBuf + prtBpos, prtBlen, bytePos, prtKey);
return true;
}
++pIt;
}
}
if (!mp4PacksLeft){
// Read more boxes!
if (offset >= currBuf->rsize()){return false;}
if (!readTo(offset + 12)){
INFO_MSG("Could not read next MP4 box!");
return false;
}
std::string boxType = std::string(*currBuf+offset+4, 4);
uint64_t boxSize = MP4::calcBoxSize(*currBuf+offset);
if (!readTo(offset + boxSize)){
INFO_MSG("Could not read next MP4 box!");
return false;
}
if (boxType == "moov"){
mp4PacksLeft = 0;
mp4Headers.clear();
mp4PackNo.clear();
MP4::Box moovBox(*currBuf+offset, false);
std::deque<MP4::TRAK> trak = ((MP4::MOOV*)&moovBox)->getChildren<MP4::TRAK>();
for (std::deque<MP4::TRAK>::iterator trakIt = trak.begin(); trakIt != trak.end(); trakIt++){
mp4Headers.push_back(MP4::TrackHeader());
mp4PackNo.push_back(0);
mp4Headers.rbegin()->read(*trakIt);
mp4PacksLeft += mp4Headers.rbegin()->size();
}
std::deque<MP4::TREX> trex = ((MP4::MOOV*)&moovBox)->getChild<MP4::MVEX>().getChildren<MP4::TREX>();
for (std::deque<MP4::TREX>::iterator trexIt = trex.begin(); trexIt != trex.end(); trexIt++){
for (std::deque<MP4::TrackHeader>::iterator it = mp4Headers.begin(); it != mp4Headers.end(); ++it){
if (it->trackId == trexIt->getTrackID()){it->read(*trexIt);}
}
}
MEDIUM_MSG("Read moov box");
}
if (boxType == "moof"){
if (!mp4Headers.size()){
FAIL_MSG("Attempting to read moof box without reading moov box first!");
return false;
}
lastMoof = offset;
MP4::Box moofBox(*currBuf+offset, false);
// Indicate that we're reading the next moof box to all track headers
for (std::deque<MP4::TrackHeader>::iterator it = mp4Headers.begin(); it != mp4Headers.end(); ++it){
it->nextMoof();
}
// Loop over traf boxes inside the moof box, but them in our header parser
std::deque<MP4::TRAF> trafs = ((MP4::MOOF*)&moofBox)->getChildren<MP4::TRAF>();
for (std::deque<MP4::TRAF>::iterator t = trafs.begin(); t != trafs.end(); ++t){
if (!(t->getChild<MP4::TFHD>())){
WARN_MSG("Could not find thfd box inside traf box!");
continue;
}
uint32_t trackId = t->getChild<MP4::TFHD>().getTrackID();
for (std::deque<MP4::TrackHeader>::iterator it = mp4Headers.begin(); it != mp4Headers.end(); ++it){
if (it->trackId == trackId){
it->read(*t);
break;
}
}
}
mp4PacksLeft = 0;
std::deque<size_t>::iterator pIt = mp4PackNo.begin();
for (std::deque<MP4::TrackHeader>::iterator it = mp4Headers.begin(); it != mp4Headers.end(); ++it){
mp4PacksLeft += it->size();
(*pIt) = 0;
++pIt;
}
}
offset += boxSize;
}
}
}
return false;
}
void SegmentReader::setInit(const std::string & data){
char * ptr = (char *)data.data();
size_t len = data.size();
size_t offset = 0;
while (offset + 8 <= len){
std::string boxType = std::string(ptr+offset+4, 4);
uint64_t boxSize = MP4::calcBoxSize(ptr+offset);
if (boxType == "moov"){
mp4PacksLeft = 0;
mp4Headers.clear();
mp4PackNo.clear();
MP4::Box moovBox(ptr+offset, false);
std::deque<MP4::TRAK> trak = ((MP4::MOOV*)&moovBox)->getChildren<MP4::TRAK>();
for (std::deque<MP4::TRAK>::iterator trakIt = trak.begin(); trakIt != trak.end(); trakIt++){
mp4Headers.push_back(MP4::TrackHeader());
mp4PackNo.push_back(0);
mp4Headers.rbegin()->read(*trakIt);
mp4PacksLeft += mp4Headers.rbegin()->size();
}
std::deque<MP4::TREX> trex = ((MP4::MOOV*)&moovBox)->getChild<MP4::MVEX>().getChildren<MP4::TREX>();
for (std::deque<MP4::TREX>::iterator trexIt = trex.begin(); trexIt != trex.end(); trexIt++){
for (std::deque<MP4::TrackHeader>::iterator it = mp4Headers.begin(); it != mp4Headers.end(); ++it){
if (it->trackId == trexIt->getTrackID()){it->read(*trexIt);}
}
}
MEDIUM_MSG("Read moov box");
}
offset += boxSize;
}
}
/// Stores data in currBuf, decodes if/as necessary, in whole 16-byte blocks
void SegmentReader::dataCallback(const char *ptr, size_t size){
#ifdef SSL
if (encrypted){
// Try to complete a 16-byte remainder
if (decBuffer.size()){
size_t toAppend = 16 - decBuffer.size();
decBuffer.append(ptr, toAppend);
if (decBuffer.size() != 16){
//Not enough data yet
return;
}
// Decode 16 bytes
currBuf->allocate(currBuf->size() + 16);
mbedtls_aes_crypt_cbc(&aes, MBEDTLS_AES_DECRYPT, 16, tmpIvec, (const unsigned char *)(char*)decBuffer,
((unsigned char *)(char *)*currBuf) + currBuf->size());
currBuf->append(0, 16);
// Clear remainder
decBuffer.truncate(0);
// Shift buffers
ptr += toAppend;
size -= toAppend;
}
// Decode any multiple of 16 bytes
size_t toDecode = ((size_t)(size / 16)) * 16;
if (toDecode){
currBuf->allocate(currBuf->size() + toDecode);
mbedtls_aes_crypt_cbc(&aes, MBEDTLS_AES_DECRYPT, toDecode, tmpIvec, (const unsigned char *)ptr,
((unsigned char *)(char *)*currBuf) + currBuf->size());
currBuf->append(0, toDecode);
// Shift buffers
ptr += toDecode;
size -= toDecode;
}
// Store remainder, if needed
if (size){decBuffer.append(ptr, size);}
return;
}
#endif
currBuf->append(ptr, size);
}
size_t SegmentReader::getDataCallbackPos() const{
#ifdef SSL
return startAtByte+currBuf->size()+decBuffer.size();
#else
return startAtByte+currBuf->size();
#endif
}
/// Attempts to read a single TS packet from the current segment, setting packetPtr on success
void SegmentReader::close(){
packetPtr = 0;
isOpen = false;
segDL.close();
}
/// Loads the given segment URL into the segment buffer.
bool SegmentReader::load(const std::string &path, uint64_t startAt, uint64_t stopAt, const char * ivec, const char * keyAES, Util::ResizeablePointer * bufPtr){
tsStream.partialClear();
lastMoof = 0;
for (std::deque<MP4::TrackHeader>::iterator it = mp4Headers.begin(); it != mp4Headers.end(); ++it){
it->nextMoof();
}
isOpen = false;
parser = STRM_UNKN;
if (ivec && keyAES && memcmp(keyAES, "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 16)){
#ifdef SSL
encrypted = true;
std::string hexKey = printhex(keyAES, 16);
std::string hexIvec = printhex(ivec, 16);
MEDIUM_MSG("Loading segment: %s, key: %s, ivec: %s", path.c_str(), hexKey.c_str(), hexIvec.c_str());
#else
FAIL_MSG("Cannot read encrypted segment: %s", path.c_str());
return false;
#endif
}else{
encrypted = false;
MEDIUM_MSG("Loading segment: %s", path.c_str());
}
startAtByte = startAt;
stopAtByte = stopAt;
offset = 0;
currBuf = bufPtr;
// Is there at least one byte? Check if we need to resume or have a whole buffer
// If reserved and total size match, assume we have the whole thing
if (currBuf->size() && (currBuf->rsize() == currBuf->size())){
buffered = true;
}else{
buffered = false;
if (currBuf->size()){
MEDIUM_MSG("Cache was incomplete (%zu/%" PRIu32 "), resuming", currBuf->size(), currBuf->rsize());
}
// We only re-open and seek if the opened URL doesn't match what we want already
HTTP::URL A = segDL.getURI();
HTTP::URL B = HTTP::localURIResolver().link(path);
if (A != B){
if (!segDL.open(path) || !segDL){
FAIL_MSG("Could not open %s", path.c_str());
return false;
}
if (!segDL){return false;}
}
// Non-seekable case is handled further down
if (segDL.isSeekable() && startAtByte + currBuf->size()){
//Seek to startAtByte position, since it's not the beginning of the file
MEDIUM_MSG("Seeking to %zu", startAtByte + currBuf->size());
segDL.seek(startAtByte + currBuf->size());
}
}
if (!buffered){
if (!currBuf->size() || !currBuf->rsize()){
// Allocate full size if known
if (stopAtByte || segDL.getSize() != std::string::npos){currBuf->allocate(stopAtByte?(stopAtByte - startAtByte):segDL.getSize());}
}
// Download full segment if not seekable, pretend it was cached all along
if (!segDL.isSeekable()){
currBuf->truncate(0);
segDL.readAll(*this);
if (startAtByte || stopAtByte){
WARN_MSG("Wasting data: downloaded whole segment due to unavailability of range requests, but caching only part of it");
if (startAtByte){currBuf->shift(startAtByte);}
if (stopAtByte){currBuf->truncate(stopAtByte - startAtByte);}
}
buffered = true;
segDL.close();
}
}
#ifdef SSL
decBuffer.truncate(0);
// If we have a non-null key, decrypt
if (encrypted){
// Load key
mbedtls_aes_setkey_dec(&aes, (const unsigned char *)keyAES, 128);
// Load initialization vector
memcpy(tmpIvec, ivec, 16);
}
#endif
packetPtr = 0;
isOpen = true;
VERYHIGH_MSG("Segment opened: %s", path.c_str());
return true;
}
}// namespace Mist

View file

@ -1,58 +0,0 @@
#include <http_parser.h>
#include <urireader.h>
#include <dtsc.h>
#include <ts_stream.h>
#include <mp4_stream.h>
namespace Mist{
enum streamType {STRM_UNKN, STRM_TS, STRM_MP4};
class SegmentReader: public Util::DataCallback{
public:
SegmentReader();
void onProgress(bool (*callback)(uint8_t));
operator bool() const {return isOpen;}
char *packetPtr;
bool load(const std::string &path, uint64_t startAt, uint64_t stopAt, const char * ivec, const char * keyAES, Util::ResizeablePointer * bufPtr);
bool readNext(DTSC::Packet & thisPacket, uint64_t bytePos);
void setInit(const std::string & initData);
void reset();
void close();
void initializeMetadata(DTSC::Meta &meta, size_t tid, size_t mappingId);
virtual void dataCallback(const char *ptr, size_t size);
virtual size_t getDataCallbackPos() const;
private:
HTTP::URIReader segDL; ///< If non-buffered, reader for the data
Util::ResizeablePointer * currBuf; ///< Storage for all (non)buffered segment content
uint64_t startAtByte; ///< Start position in bytes
uint64_t stopAtByte; ///< Stop position in bytes
bool encrypted; ///< True if segment must be decrypted before parsing
bool buffered; ///< True if segment is fully buffered in memory
bool isOpen; ///< True if a segment has been successfully opened
bool (*progressCallback)(uint8_t);
bool readTo(size_t offset);
size_t offset;
// Parser related
streamType parser;
TS::Stream tsStream;
std::deque<MP4::TrackHeader> mp4Headers;
std::deque<size_t> mp4PackNo;
size_t mp4PacksLeft;
uint64_t lastMoof;
#ifdef SSL
//Encryption-related
Util::ResizeablePointer decBuffer; ///< Buffer for pre-decryption data - max 16 bytes
unsigned char tmpIvec[16];
mbedtls_aes_context aes; ///< Decryption context
#endif
};
} // namespace Mist

View file

@ -44,14 +44,6 @@ static const char *gai_strmagic(int errcode){
}
}
std::string Socket::sockaddrToString(const sockaddr* A){
char addressBuffer[INET6_ADDRSTRLEN];
if (inet_ntop(AF_INET, A, addressBuffer, INET6_ADDRSTRLEN)){
return addressBuffer;
}
return "";
}
static std::string getIPv6BinAddr(const struct sockaddr_in6 &remoteaddr){
char tmpBuffer[17] = "\000\000\000\000\000\000\000\000\000\000\377\377\000\000\000\000";
switch (remoteaddr.sin6_family){
@ -138,44 +130,6 @@ bool Socket::matchIPv6Addr(const std::string &A, const std::string &B, uint8_t p
return true;
}
bool Socket::compareAddress(const sockaddr* A, const sockaddr* B){
if (!A || !B){return false;}
bool aSix = false, bSix = false;
char *aPtr = 0, *bPtr = 0;
uint16_t aPort = 0, bPort = 0;
if (A->sa_family == AF_INET){
aPtr = (char*)&((sockaddr_in*)A)->sin_addr;
aPort = ((sockaddr_in*)A)->sin_port;
}else if(A->sa_family == AF_INET6){
aPtr = (char*)&((sockaddr_in6*)A)->sin6_addr;
aPort = ((sockaddr_in6*)A)->sin6_port;
if (!memcmp("\000\000\000\000\000\000\000\000\000\000\377\377", aPtr, 12)){
aPtr += 12;
}else{
aSix = true;
}
}else{
return false;
}
if (B->sa_family == AF_INET){
bPtr = (char*)&((sockaddr_in*)B)->sin_addr;
bPort = ((sockaddr_in*)B)->sin_port;
}else if(B->sa_family == AF_INET6){
bPtr = (char*)&((sockaddr_in6*)B)->sin6_addr;
bPort = ((sockaddr_in6*)B)->sin6_port;
if (!memcmp("\000\000\000\000\000\000\000\000\000\000\377\377", bPtr, 12)){
bPtr += 12;
}else{
bSix = true;
}
}else{
return false;
}
if (aPort != bPort){return false;}
if (aSix != bSix){return false;}
return !memcmp(aPtr, bPtr, aSix?16:4);
}
/// Attempts to match the given address with optional subnet to the given binary-form IPv6 address.
/// Returns true if match could be made, false otherwise.
bool Socket::isBinAddress(const std::string &binAddr, std::string addr){
@ -226,7 +180,7 @@ std::string Socket::getBinForms(std::string addr){
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED | AI_ALL;
hints.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED;
hints.ai_protocol = 0;
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
@ -246,45 +200,6 @@ std::string Socket::getBinForms(std::string addr){
return ret;
}
std::deque<std::string> Socket::getAddrs(std::string addr, uint16_t port, int family){
std::deque<std::string> ret;
struct addrinfo *result, *rp, hints;
if (addr.substr(0, 7) == "::ffff:"){addr = addr.substr(7);}
std::stringstream ss;
ss << port;
memset(&hints, 0, sizeof(struct addrinfo));
// For unspecified, we do IPv6, then do IPv4 separately after
hints.ai_family = family==AF_UNSPEC?AF_INET6:family;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE | AI_V4MAPPED | AI_ALL;
hints.ai_protocol = IPPROTO_UDP;
int s = getaddrinfo(addr.c_str(), ss.str().c_str(), &hints, &result);
if (!s){
// Store each address in a string and put it in the deque.
for (rp = result; rp != NULL; rp = rp->ai_next){
ret.push_back(std::string((char*)rp->ai_addr, rp->ai_addrlen));
}
freeaddrinfo(result);
}
// If failed or unspecified, (also) try IPv4
if (s || family==AF_UNSPEC){
hints.ai_family = AF_INET;
s = getaddrinfo(addr.c_str(), ss.str().c_str(), &hints, &result);
if (!s){
// Store each address in a string and put it in the deque.
for (rp = result; rp != NULL; rp = rp->ai_next){
ret.push_back(std::string((char*)rp->ai_addr, rp->ai_addrlen));
}
freeaddrinfo(result);
}
}
// Return all we found
return ret;
}
/// Checks bytes (length len) containing a binary-encoded IPv4 or IPv6 IP address, and writes it in
/// human-readable notation to target. Writes "unknown" if it cannot decode to a sensible value.
void Socket::hostBytesToStr(const char *bytes, size_t len, std::string &target){
@ -1764,7 +1679,6 @@ void Socket::UDPConnection::init(bool _nonblock, int _family){
isConnected = false;
wasEncrypted = false;
pretendReceive = false;
ignoreSendErrors = false;
sock = socket(family, SOCK_DGRAM, 0);
if (sock == -1 && family == AF_INET6){
sock = socket(AF_INET, SOCK_DGRAM, 0);
@ -1786,6 +1700,10 @@ void Socket::UDPConnection::init(bool _nonblock, int _family){
up = 0;
down = 0;
destAddr = 0;
destAddr_size = 0;
recvAddr = 0;
recvAddr_size = 0;
hasReceiveData = false;
#ifdef __CYGWIN__
data.allocate(SOCKETSIZE);
@ -1794,23 +1712,6 @@ void Socket::UDPConnection::init(bool _nonblock, int _family){
#endif
}
void Socket::UDPConnection::assimilate(int _sock){
if (sock != -1){close();}
sock = _sock;
{ // Extract socket family
struct sockaddr_storage fin_addr;
socklen_t alen = sizeof(fin_addr);
if (getsockname(sock, (struct sockaddr *)&fin_addr, &alen) == 0){
family = fin_addr.ss_family;
if (family == AF_INET6){
boundPort = ntohs(((struct sockaddr_in6 *)&fin_addr)->sin6_port);
}else{
boundPort = ntohs(((struct sockaddr_in *)&fin_addr)->sin_port);
}
}
}
}
#if HAVE_UPSTREAM_MBEDTLS_SRTP
#if MBEDTLS_VERSION_MAJOR > 2
static void dtlsExtractKeyData( void *user, mbedtls_ssl_key_export_type type, const unsigned char *ms, size_t, const unsigned char client_random[32], const unsigned char server_random[32], mbedtls_tls_prf_types tls_prf_type){
@ -2026,10 +1927,18 @@ void Socket::UDPConnection::checkRecvBuf(){
Socket::UDPConnection::UDPConnection(const UDPConnection &o){
init(!o.isBlocking, o.family);
INFO_MSG("Copied socket of type %s", addrFam(o.family));
if (o.destAddr.size()){destAddr = o.destAddr;}
if (o.recvAddr.size()){recvAddr = o.recvAddr;}
if (o.destAddr && o.destAddr_size){
destAddr = malloc(o.destAddr_size);
destAddr_size = o.destAddr_size;
if (destAddr){memcpy(destAddr, o.destAddr, o.destAddr_size);}
}
if (o.recvAddr && o.recvAddr_size){
recvAddr = malloc(o.recvAddr_size);
recvAddr_size = o.recvAddr_size;
if (recvAddr){memcpy(recvAddr, o.recvAddr, o.recvAddr_size);}
}
if (o.data.size()){
data = o.data;
data.assign(o.data, o.data.size());
pretendReceive = true;
}
hasReceiveData = o.hasReceiveData;
@ -2047,6 +1956,14 @@ void Socket::UDPConnection::close(){
/// Closes the UDP socket, cleans up any memory allocated by the socket.
Socket::UDPConnection::~UDPConnection(){
close();
if (destAddr){
free(destAddr);
destAddr = 0;
}
if (recvAddr){
free(recvAddr);
recvAddr = 0;
}
#ifdef SSL
deinitDTLS();
#endif
@ -2058,10 +1975,10 @@ bool Socket::UDPConnection::operator==(const Socket::UDPConnection& b) const{
if (sock == b.sock){return true;}
// If either is closed (and the other is not), not equal.
if (sock == -1 || b.sock == -1){return false;}
size_t recvSize = recvAddr.size();
if (b.recvAddr.size() < recvSize){recvSize = b.recvAddr.size();}
size_t destSize = destAddr.size();
if (b.destAddr.size() < destSize){destSize = b.destAddr.size();}
size_t recvSize = recvAddr_size;
if (b.recvAddr_size < recvSize){recvSize = b.recvAddr_size;}
size_t destSize = destAddr_size;
if (b.destAddr_size < destSize){destSize = b.destAddr_size;}
// They are equal if they hold the same local and remote address.
if (recvSize && destSize && destAddr && b.destAddr && recvAddr && b.recvAddr){
if (!memcmp(recvAddr, b.recvAddr, recvSize) && !memcmp(destAddr, b.destAddr, destSize)){
@ -2082,108 +1999,128 @@ void Socket::UDPConnection::setSocketFamily(int AF_TYPE){\
/// Allocates enough space for the largest type of address we support, so that receive calls can write to it.
void Socket::UDPConnection::allocateDestination(){
if (!destAddr.size()){
destAddr.truncate(0);
destAddr.allocate(sizeof(sockaddr_in6));
memset(destAddr, 0, sizeof(sockaddr_in6));
((struct sockaddr *)(char*)destAddr)->sa_family = AF_UNSPEC;
destAddr.append(0, sizeof(sockaddr_in6));
if (destAddr && destAddr_size < sizeof(sockaddr_in6)){
free(destAddr);
destAddr = 0;
}
if (!recvAddr.size()){
recvAddr.truncate(0);
recvAddr.allocate(sizeof(sockaddr_in6));
memset(recvAddr, 0, sizeof(sockaddr_in6));
((struct sockaddr *)(char*)recvAddr)->sa_family = AF_UNSPEC;
recvAddr.append(0, sizeof(sockaddr_in6));
}
#ifdef HASPKTINFO
const int opt = 1;
if (setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &opt, sizeof(opt))){
WARN_MSG("Could not set IPv4 packet info receiving enabled!");
}
if (family == AF_INET6){
if (setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &opt, sizeof(opt))){
WARN_MSG("Could not set IPv6 packet info receiving enabled!");
if (!destAddr){
destAddr = malloc(sizeof(sockaddr_in6));
if (destAddr){
destAddr_size = sizeof(sockaddr_in6);
memset(destAddr, 0, sizeof(sockaddr_in6));
((struct sockaddr_in *)destAddr)->sin_family = AF_UNSPEC;
}
}
if (recvAddr && recvAddr_size < sizeof(sockaddr_in6)){
free(recvAddr);
recvAddr = 0;
}
if (!recvAddr){
recvAddr = malloc(sizeof(sockaddr_in6));
if (recvAddr){
recvAddr_size = sizeof(sockaddr_in6);
memset(recvAddr, 0, sizeof(sockaddr_in6));
((struct sockaddr_in *)recvAddr)->sin_family = AF_UNSPEC;
}
const int opt = 1;
if (setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &opt, sizeof(opt))){
WARN_MSG("Could not set PKTINFO to 1!");
}
}
#endif
}
/// Stores the properties of the receiving end of this UDP socket.
/// This will be the receiving end for all SendNow calls.
void Socket::UDPConnection::SetDestination(std::string destIp, uint32_t port){
DONTEVEN_MSG("Setting destination to %s:%u", destIp.c_str(), port);
// UDP sockets can switch between IPv4 and IPv6 on demand.
// We change IPv4-mapped IPv6 addresses into IPv4 addresses for Windows-sillyness reasons.
if (destIp.substr(0, 7) == "::ffff:"){destIp = destIp.substr(7);}
struct addrinfo *result, *rp, hints;
std::stringstream ss;
ss << port;
std::deque<std::string> addrs = getAddrs(destIp, port, family);
for (std::deque<std::string>::iterator it = addrs.begin(); it != addrs.end(); ++it){
if (setDestination((sockaddr*)it->data(), it->size())){return;}
}
destAddr.truncate(0);
allocateDestination();
FAIL_MSG("Could not set destination for UDP socket: %s:%d", destIp.c_str(), port);
}// Socket::UDPConnection SetDestination
bool Socket::UDPConnection::setDestination(sockaddr * addr, size_t size){
// UDP sockets can on-the-fly switch between IPv4/IPv6 if necessary
if (family != addr->sa_family){
if (ignoreSendErrors){return false;}
WARN_MSG("Switching UDP socket from %s to %s", addrFam(family), addrFam(((sockaddr*)(char*)destAddr)->sa_family));
close();
family = addr->sa_family;
sock = socket(family, SOCK_DGRAM, 0);
{
// Allow address re-use
int on = 1;
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = family;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = AI_ADDRCONFIG | AI_ALL;
hints.ai_protocol = IPPROTO_UDP;
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL;
int s = getaddrinfo(destIp.c_str(), ss.str().c_str(), &hints, &result);
if (s != 0){
hints.ai_family = AF_UNSPEC;
s = getaddrinfo(destIp.c_str(), ss.str().c_str(), &hints, &result);
if (s != 0){
FAIL_MSG("Could not connect UDP socket to %s:%i! Error: %s", destIp.c_str(), port, gai_strmagic(s));
return;
}
if (family == AF_INET6){
const int optval = 0;
if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval)) < 0){
WARN_MSG("Could not set IPv6 UDP socket to be dual-stack! %s", strerror(errno));
}
for (rp = result; rp != NULL; rp = rp->ai_next){
// assume success
if (destAddr){
free(destAddr);
destAddr = 0;
}
destAddr_size = rp->ai_addrlen;
destAddr = malloc(destAddr_size);
if (!destAddr){return;}
memcpy(destAddr, rp->ai_addr, rp->ai_addrlen);
if (family != rp->ai_family){
INFO_MSG("Switching UDP socket from %s to %s", addrFam(family), addrFam(rp->ai_family));
close();
family = rp->ai_family;
sock = socket(family, SOCK_DGRAM, 0);
{
// Allow address re-use
int on = 1;
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
}
checkRecvBuf();
if (boundPort){
INFO_MSG("Rebinding to %s:%d %s", boundAddr.c_str(), boundPort, boundMulti.c_str());
bind(boundPort, boundAddr, boundMulti);
}
}
checkRecvBuf();
if (boundPort){
INFO_MSG("Rebinding to %s:%d %s", boundAddr.c_str(), boundPort, boundMulti.c_str());
bind(boundPort, boundAddr, boundMulti);
{
std::string trueDest;
uint32_t truePort;
GetDestination(trueDest, truePort);
HIGH_MSG("Set UDP destination: %s:%d => %s:%d (%s)", destIp.c_str(), port, trueDest.c_str(), truePort, addrFam(family));
}
freeaddrinfo(result);
return;
//\todo Possibly detect and handle failure
}
hasReceiveData = false;
destAddr.assign(addr, size);
{
std::string trueDest;
uint32_t truePort;
GetDestination(trueDest, truePort);
HIGH_MSG("Set UDP destination to %s:%d (%s)", trueDest.c_str(), truePort, addrFam(family));
}
return true;
}
const Util::ResizeablePointer & Socket::UDPConnection::getRemoteAddr() const{
return destAddr;
}
freeaddrinfo(result);
free(destAddr);
destAddr = 0;
FAIL_MSG("Could not set destination for UDP socket: %s:%d", destIp.c_str(), port);
}// Socket::UDPConnection SetDestination
/// Gets the properties of the receiving end of this UDP socket.
/// This will be the receiving end for all SendNow calls.
void Socket::UDPConnection::GetDestination(std::string &destIp, uint32_t &port){
if (!destAddr.size()){
if (!destAddr || !destAddr_size){
destIp = "";
port = 0;
return;
}
char addr_str[INET6_ADDRSTRLEN + 1];
addr_str[INET6_ADDRSTRLEN] = 0; // set last byte to zero, to prevent walking out of the array
if (((struct sockaddr *)(char*)destAddr)->sa_family == AF_INET6){
if (inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)(char*)destAddr)->sin6_addr), addr_str, INET6_ADDRSTRLEN) != 0){
if (((struct sockaddr_in *)destAddr)->sin_family == AF_INET6){
if (inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)destAddr)->sin6_addr), addr_str, INET6_ADDRSTRLEN) != 0){
destIp = addr_str;
port = ntohs(((struct sockaddr_in6 *)(char*)destAddr)->sin6_port);
port = ntohs(((struct sockaddr_in6 *)destAddr)->sin6_port);
return;
}
}
if (((struct sockaddr_in *)(char*)destAddr)->sin_family == AF_INET){
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)(char*)destAddr)->sin_addr), addr_str, INET6_ADDRSTRLEN) != 0){
if (((struct sockaddr_in *)destAddr)->sin_family == AF_INET){
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)destAddr)->sin_addr), addr_str, INET6_ADDRSTRLEN) != 0){
destIp = addr_str;
port = ntohs(((struct sockaddr_in *)(char*)destAddr)->sin_port);
port = ntohs(((struct sockaddr_in *)destAddr)->sin_port);
return;
}
}
@ -2195,24 +2132,24 @@ void Socket::UDPConnection::GetDestination(std::string &destIp, uint32_t &port){
/// Gets the properties of the receiving end of the local UDP socket.
/// This will be the sending end for all SendNow calls.
void Socket::UDPConnection::GetLocalDestination(std::string &destIp, uint32_t &port){
if (!recvAddr.size()){
if (!recvAddr || !recvAddr_size){
destIp = "";
port = 0;
return;
}
char addr_str[INET6_ADDRSTRLEN + 1];
addr_str[INET6_ADDRSTRLEN] = 0; // set last byte to zero, to prevent walking out of the array
if (((struct sockaddr *)(char*)recvAddr)->sa_family == AF_INET6){
if (inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)(char*)recvAddr)->sin6_addr), addr_str, INET6_ADDRSTRLEN) != 0){
if (((struct sockaddr_in *)recvAddr)->sin_family == AF_INET6){
if (inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)recvAddr)->sin6_addr), addr_str, INET6_ADDRSTRLEN) != 0){
destIp = addr_str;
port = ntohs(((struct sockaddr_in6 *)(char*)recvAddr)->sin6_port);
port = ntohs(((struct sockaddr_in6 *)recvAddr)->sin6_port);
return;
}
}
if (((struct sockaddr *)(char*)recvAddr)->sa_family == AF_INET){
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)(char*)recvAddr)->sin_addr), addr_str, INET6_ADDRSTRLEN) != 0){
if (((struct sockaddr_in *)recvAddr)->sin_family == AF_INET){
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)recvAddr)->sin_addr), addr_str, INET6_ADDRSTRLEN) != 0){
destIp = addr_str;
port = ntohs(((struct sockaddr_in *)(char*)recvAddr)->sin_port);
port = ntohs(((struct sockaddr_in *)recvAddr)->sin_port);
return;
}
}
@ -2225,7 +2162,7 @@ void Socket::UDPConnection::GetLocalDestination(std::string &destIp, uint32_t &p
/// This will be the receiving end for all SendNow calls.
std::string Socket::UDPConnection::getBinDestination(){
std::string binList;
if (destAddr.size()){binList = getIPv6BinAddr(*(sockaddr_in6*)(char*)destAddr);}
if (destAddr && destAddr_size){binList = getIPv6BinAddr(*(sockaddr_in6*)destAddr);}
if (binList.size() < 16){return std::string("\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 16);}
return binList.substr(0, 16);
}// Socket::UDPConnection GetDestination
@ -2233,12 +2170,12 @@ std::string Socket::UDPConnection::getBinDestination(){
/// Returns the port number of the receiving end of this socket.
/// Returns 0 on error.
uint32_t Socket::UDPConnection::getDestPort() const{
if (!destAddr.size()){return 0;}
if (((const struct sockaddr *)(const char*)destAddr)->sa_family == AF_INET6){
return ntohs(((const struct sockaddr_in6 *)(const char*)destAddr)->sin6_port);
if (!destAddr || !destAddr_size){return 0;}
if (((struct sockaddr_in *)destAddr)->sin_family == AF_INET6){
return ntohs(((struct sockaddr_in6 *)destAddr)->sin6_port);
}
if (((const struct sockaddr *)(const char*)destAddr)->sa_family == AF_INET){
return ntohs(((const struct sockaddr_in *)(const char*)destAddr)->sin_port);
if (((struct sockaddr_in *)destAddr)->sin_family == AF_INET){
return ntohs(((struct sockaddr_in *)destAddr)->sin_port);
}
return 0;
}
@ -2252,10 +2189,6 @@ void Socket::UDPConnection::setBlocking(bool blocking){
}
}
void Socket::UDPConnection::setIgnoreSendErrors(bool ign){
ignoreSendErrors = ign;
}
/// Sends a UDP datagram using the buffer sdata.
/// This function simply calls SendNow(const char*, size_t)
void Socket::UDPConnection::SendNow(const std::string &sdata){
@ -2274,7 +2207,7 @@ void Socket::UDPConnection::SendNow(const char *sdata){
/// Does not do anything if len < 1.
/// Prints an DLVL_FAIL level debug message if sending failed.
void Socket::UDPConnection::SendNow(const char *sdata, size_t len){
SendNow(sdata, len, (sockaddr*)(char*)destAddr, destAddr.size());
SendNow(sdata, len, (sockaddr*)destAddr, destAddr_size);
}
/// Sends a UDP datagram using the buffer sdata of length len.
@ -2287,7 +2220,6 @@ void Socket::UDPConnection::SendNow(const char *sdata, size_t len, sockaddr * dA
if (r > 0){
up += r;
}else{
if (ignoreSendErrors){return;}
if (errno == EDESTADDRREQ){
close();
return;
@ -2296,8 +2228,8 @@ void Socket::UDPConnection::SendNow(const char *sdata, size_t len, sockaddr * dA
}
return;
}
#ifdef HASPKTINFO
if (hasReceiveData && recvAddr.size()){
#if !defined(__CYGWIN__) && !defined(_WIN32)
if (hasReceiveData && recvAddr){
msghdr mHdr;
char msg_control[0x100];
iovec iovec;
@ -2312,34 +2244,22 @@ void Socket::UDPConnection::SendNow(const char *sdata, size_t len, sockaddr * dA
mHdr.msg_flags = 0;
int cmsg_space = 0;
cmsghdr * cmsg = CMSG_FIRSTHDR(&mHdr);
if (family == AF_INET){
cmsg->cmsg_level = IPPROTO_IP;
cmsg->cmsg_type = IP_PKTINFO;
cmsg->cmsg_level = IPPROTO_IP;
cmsg->cmsg_type = IP_PKTINFO;
struct in_pktinfo in_pktinfo;
memcpy(&(in_pktinfo.ipi_spec_dst), &(((sockaddr_in*)(char*)recvAddr)->sin_family), sizeof(in_pktinfo.ipi_spec_dst));
in_pktinfo.ipi_ifindex = recvInterface;
cmsg->cmsg_len = CMSG_LEN(sizeof(in_pktinfo));
*(struct in_pktinfo*)CMSG_DATA(cmsg) = in_pktinfo;
cmsg_space += CMSG_SPACE(sizeof(in_pktinfo));
}else if (family == AF_INET6){
cmsg->cmsg_level = IPPROTO_IPV6;
cmsg->cmsg_type = IPV6_PKTINFO;
struct in6_pktinfo in6_pktinfo;
memcpy(&(in6_pktinfo.ipi6_addr), &(((sockaddr_in6*)(char*)recvAddr)->sin6_addr), sizeof(in6_pktinfo.ipi6_addr));
in6_pktinfo.ipi6_ifindex = recvInterface;
cmsg->cmsg_len = CMSG_LEN(sizeof(in6_pktinfo));
*(struct in6_pktinfo*)CMSG_DATA(cmsg) = in6_pktinfo;
cmsg_space += CMSG_SPACE(sizeof(in6_pktinfo));
}
struct in_pktinfo in_pktinfo;
memcpy(&(in_pktinfo.ipi_spec_dst), &(((sockaddr_in*)recvAddr)->sin_family), sizeof(in_pktinfo.ipi_spec_dst));
in_pktinfo.ipi_ifindex = recvInterface;
cmsg->cmsg_len = CMSG_LEN(sizeof(in_pktinfo));
*(struct in_pktinfo*)CMSG_DATA(cmsg) = in_pktinfo;
cmsg_space += CMSG_SPACE(sizeof(in_pktinfo));
mHdr.msg_controllen = cmsg_space;
int r = sendmsg(sock, &mHdr, 0);
if (r > 0){
up += r;
}else{
if (errno != ENETUNREACH && !ignoreSendErrors){
if (errno != ENETUNREACH){
FAIL_MSG("Could not send UDP data through %d: %s", sock, strerror(errno));
}
}
@ -2350,11 +2270,11 @@ void Socket::UDPConnection::SendNow(const char *sdata, size_t len, sockaddr * dA
if (r > 0){
up += r;
}else{
if (errno != ENETUNREACH && !ignoreSendErrors){
if (errno != ENETUNREACH){
FAIL_MSG("Could not send UDP data through %d: %s", sock, strerror(errno));
}
}
#ifdef HASPKTINFO
#if !defined(__CYGWIN__) && !defined(_WIN32)
}
#endif
}
@ -2452,10 +2372,6 @@ std::string Socket::UDPConnection::getBoundAddress(){
return boundaddr;
}
uint16_t Socket::UDPConnection::getBoundPort() const{
return boundPort;
}
/// Bind to a port number, returning the bound port.
/// If that fails, returns zero.
/// \arg port Port to bind to, required.
@ -2467,15 +2383,13 @@ uint16_t Socket::UDPConnection::bind(int port, std::string iface, const std::str
close(); // we open a new socket for each attempt
int addr_ret;
bool multicast = false;
bool repeatWithIPv4 = false;
struct addrinfo hints, *addr_result, *rp;
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE | AI_V4MAPPED;
if (destAddr.size()){
hints.ai_family = ((struct sockaddr *)(char*)destAddr)->sa_family;
if (destAddr && destAddr_size){
hints.ai_family = ((struct sockaddr_in *)destAddr)->sin_family;
}else{
hints.ai_family = AF_INET6;
repeatWithIPv4 = true;
hints.ai_family = AF_UNSPEC;
}
hints.ai_socktype = SOCK_DGRAM;
@ -2484,24 +2398,14 @@ uint16_t Socket::UDPConnection::bind(int port, std::string iface, const std::str
std::stringstream ss;
ss << port;
repeatAddressFinding:
if (iface == "0.0.0.0" || iface.length() == 0){
if ((addr_ret = getaddrinfo(0, ss.str().c_str(), &hints, &addr_result)) != 0){
FAIL_MSG("Could not resolve %s for UDP: %s", iface.c_str(), gai_strmagic(addr_ret));
if (repeatWithIPv4 && hints.ai_family != AF_INET){
hints.ai_family = AF_INET;
goto repeatAddressFinding;
}
return 0;
}
}else{
if ((addr_ret = getaddrinfo(iface.c_str(), ss.str().c_str(), &hints, &addr_result)) != 0){
FAIL_MSG("Could not resolve %s for UDP: %s", iface.c_str(), gai_strmagic(addr_ret));
if (repeatWithIPv4 && hints.ai_family != AF_INET){
hints.ai_family = AF_INET;
goto repeatAddressFinding;
}
return 0;
}
}
@ -2518,7 +2422,7 @@ repeatAddressFinding:
}
if (rp->ai_family == AF_INET6){
const int optval = 0;
if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval)) < 0){
if (setsockopt(sock, SOL_SOCKET, IPV6_V6ONLY, &optval, sizeof(optval)) < 0){
WARN_MSG("Could not set IPv6 UDP socket to be dual-stack! %s", strerror(errno));
}
}
@ -2579,10 +2483,6 @@ repeatAddressFinding:
freeaddrinfo(addr_result);
if (sock == -1){
FAIL_MSG("Could not open %s for UDP: %s", iface.c_str(), err_str.c_str());
if (repeatWithIPv4 && hints.ai_family != AF_INET){
hints.ai_family = AF_INET;
goto repeatAddressFinding;
}
return 0;
}
@ -2670,7 +2570,7 @@ repeatAddressFinding:
}
bool Socket::UDPConnection::connect(){
if (!recvAddr.size() || !destAddr.size()){
if (!recvAddr || !recvAddr_size || !destAddr || !destAddr_size){
WARN_MSG("Attempting to connect a UDP socket without local and/or remote address!");
return false;
}
@ -2679,23 +2579,27 @@ bool Socket::UDPConnection::connect(){
std::string destIp;
uint32_t port = 0;
char addr_str[INET6_ADDRSTRLEN + 1];
if (((struct sockaddr *)(char*)recvAddr)->sa_family == AF_INET6){
if (inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)(char*)recvAddr)->sin6_addr), addr_str, INET6_ADDRSTRLEN) != 0){
if (((struct sockaddr_in *)recvAddr)->sin_family == AF_INET6){
if (inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)recvAddr)->sin6_addr), addr_str, INET6_ADDRSTRLEN) != 0){
destIp = addr_str;
port = ntohs(((struct sockaddr_in6 *)(char*)recvAddr)->sin6_port);
port = ntohs(((struct sockaddr_in6 *)recvAddr)->sin6_port);
}
}
if (((struct sockaddr *)(char*)recvAddr)->sa_family == AF_INET){
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)(char*)recvAddr)->sin_addr), addr_str, INET6_ADDRSTRLEN) != 0){
if (((struct sockaddr_in *)recvAddr)->sin_family == AF_INET){
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)recvAddr)->sin_addr), addr_str, INET6_ADDRSTRLEN) != 0){
destIp = addr_str;
port = ntohs(((struct sockaddr_in *)(char*)recvAddr)->sin_port);
port = ntohs(((struct sockaddr_in *)recvAddr)->sin_port);
}
}
int ret = ::bind(sock, (const struct sockaddr*)(char*)recvAddr, recvAddr.size());
int ret = ::bind(sock, (const struct sockaddr*)recvAddr, recvAddr_size);
if (!ret){
INFO_MSG("Bound socket %d to %s:%" PRIu32, sock, destIp.c_str(), port);
}else{
FAIL_MSG("Failed to bind socket %d (%s) %s:%" PRIu32 ": %s", sock, addrFam(((struct sockaddr *)(char*)recvAddr)->sa_family), destIp.c_str(), port, strerror(errno));
FAIL_MSG("Failed to bind socket %d (%s) %s:%" PRIu32 ": %s", sock, addrFam(((struct sockaddr_in *)recvAddr)->sin_family), destIp.c_str(), port, strerror(errno));
std::ofstream bleh("/tmp/socket_recv");
bleh.write((const char*)recvAddr, recvAddr_size);
bleh.write((const char*)destAddr, destAddr_size);
bleh.close();
return false;
}
}
@ -2704,19 +2608,19 @@ bool Socket::UDPConnection::connect(){
std::string destIp;
uint32_t port;
char addr_str[INET6_ADDRSTRLEN + 1];
if (((struct sockaddr *)(char*)destAddr)->sa_family == AF_INET6){
if (inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)(char*)destAddr)->sin6_addr), addr_str, INET6_ADDRSTRLEN) != 0){
if (((struct sockaddr_in *)destAddr)->sin_family == AF_INET6){
if (inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)destAddr)->sin6_addr), addr_str, INET6_ADDRSTRLEN) != 0){
destIp = addr_str;
port = ntohs(((struct sockaddr_in6 *)(char*)destAddr)->sin6_port);
port = ntohs(((struct sockaddr_in6 *)destAddr)->sin6_port);
}
}
if (((struct sockaddr *)(char*)destAddr)->sa_family == AF_INET){
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)(char*)destAddr)->sin_addr), addr_str, INET6_ADDRSTRLEN) != 0){
if (((struct sockaddr_in *)destAddr)->sin_family == AF_INET){
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)destAddr)->sin_addr), addr_str, INET6_ADDRSTRLEN) != 0){
destIp = addr_str;
port = ntohs(((struct sockaddr_in *)(char*)destAddr)->sin_port);
port = ntohs(((struct sockaddr_in *)destAddr)->sin_port);
}
}
int ret = ::connect(sock, (const struct sockaddr*)(char*)destAddr, destAddr.size());
int ret = ::connect(sock, (const struct sockaddr*)destAddr, destAddr_size);
if (!ret){
INFO_MSG("Connected socket to %s:%" PRIu32, destIp.c_str(), port);
}else{
@ -2781,37 +2685,18 @@ bool Socket::UDPConnection::Receive(){
if (errno != EAGAIN){INFO_MSG("UDP receive: %d (%s)", errno, strerror(errno));}
return false;
}
if (destAddr.size() && destsize){destAddr.assign(&addr, destsize);}
#ifdef HASPKTINFO
if (recvAddr.size()){
if (destAddr && destsize && destAddr_size >= destsize){memcpy(destAddr, &addr, destsize);}
#if !defined(__CYGWIN__) && !defined(_WIN32)
if (recvAddr){
for ( struct cmsghdr *cmsg = CMSG_FIRSTHDR(&mHdr); cmsg != NULL; cmsg = CMSG_NXTHDR(&mHdr, cmsg)){
if (cmsg->cmsg_level == IPPROTO_IP && cmsg->cmsg_type == IP_PKTINFO){
struct in_pktinfo* pi = (in_pktinfo*)CMSG_DATA(cmsg);
if (family == AF_INET6){
struct sockaddr_in6 * recvCast = (sockaddr_in6*)(char*)recvAddr;
recvCast->sin6_port = htons(boundPort);
recvCast->sin6_family = AF_INET6;
memcpy(((char*)&(recvCast->sin6_addr)) + 12, &(pi->ipi_spec_dst), sizeof(pi->ipi_spec_dst));
memset((void*)&(recvCast->sin6_addr), 0, 10);
memset((char*)&(recvCast->sin6_addr) + 10, 255, 2);
}else{
struct sockaddr_in * recvCast = (sockaddr_in*)(char*)recvAddr;
recvCast->sin_port = htons(boundPort);
recvCast->sin_family = AF_INET;
memcpy(&(recvCast->sin_addr), &(pi->ipi_spec_dst), sizeof(pi->ipi_spec_dst));
}
recvInterface = pi->ipi_ifindex;
hasReceiveData = true;
}
if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == IPV6_PKTINFO){
struct in6_pktinfo* pi = (in6_pktinfo*)CMSG_DATA(cmsg);
struct sockaddr_in6 * recvCast = (sockaddr_in6*)(char*)recvAddr;
recvCast->sin6_family = AF_INET6;
recvCast->sin6_port = htons(boundPort);
memcpy(&(recvCast->sin6_addr), &(pi->ipi6_addr), sizeof(pi->ipi6_addr));
recvInterface = pi->ipi6_ifindex;
hasReceiveData = true;
}
if (cmsg->cmsg_level != IPPROTO_IP || cmsg->cmsg_type != IP_PKTINFO){continue;}
struct in_pktinfo* pi = (in_pktinfo*)CMSG_DATA(cmsg);
struct sockaddr_in * recvCast = (sockaddr_in*)recvAddr;
recvCast->sin_family = family;
recvCast->sin_port = htons(boundPort);
memcpy(&(recvCast->sin_addr), &(pi->ipi_spec_dst), sizeof(pi->ipi_spec_dst));
recvInterface = pi->ipi_ifindex;
hasReceiveData = true;
}
}
#endif

View file

@ -51,13 +51,10 @@ namespace Buffer{
/// Holds Socket tools.
namespace Socket{
std::string sockaddrToString(const sockaddr* A);
void hostBytesToStr(const char *bytes, size_t len, std::string &target);
bool isBinAddress(const std::string &binAddr, std::string matchTo);
bool matchIPv6Addr(const std::string &A, const std::string &B, uint8_t prefix);
bool compareAddress(const sockaddr* A, const sockaddr* B);
std::string getBinForms(std::string addr);
std::deque<std::string> getAddrs(std::string addr, uint16_t port, int family = AF_UNSPEC);
/// Returns true if given human-readable address (address, not hostname) is a local address.
bool isLocal(const std::string &host);
/// Returns true if given human-readable hostname is a local address.
@ -218,12 +215,14 @@ namespace Socket{
class UDPConnection{
private:
void init(bool nonblock, int family = AF_INET6);
int sock; ///< Internally saved socket number
int sock; ///< Internally saved socket number.
std::string remotehost; ///< Stores remote host address
Util::ResizeablePointer destAddr; ///< Destination address
Util::ResizeablePointer recvAddr; ///< Local address
unsigned int up; ///< Amount of bytes transferred up
unsigned int down; ///< Amount of bytes transferred down
void *destAddr; ///< Destination address pointer.
unsigned int destAddr_size; ///< Size of the destination address pointer.
void *recvAddr; ///< Destination address pointer.
unsigned int recvAddr_size; ///< Size of the destination address pointer.
unsigned int up; ///< Amount of bytes transferred up.
unsigned int down; ///< Amount of bytes transferred down.
int family; ///< Current socket address family
std::string boundAddr, boundMulti;
int boundPort;
@ -234,7 +233,6 @@ namespace Socket{
bool hasReceiveData;
bool isBlocking;
bool isConnected;
bool ignoreSendErrors;
bool pretendReceive; ///< If true, will pretend to have just received the current data buffer on new Receive() call
bool onData();
@ -256,7 +254,6 @@ namespace Socket{
UDPConnection(const UDPConnection &o);
UDPConnection(bool nonblock = false);
~UDPConnection();
void assimilate(int sock);
bool operator==(const UDPConnection& b) const;
operator bool() const;
#ifdef SSL
@ -272,18 +269,14 @@ namespace Socket{
uint16_t bind(int port, std::string iface = "", const std::string &multicastAddress = "");
bool connect();
void setBlocking(bool blocking);
void setIgnoreSendErrors(bool ign);
void allocateDestination();
void SetDestination(std::string hostname, uint32_t port);
bool setDestination(sockaddr * addr, size_t size);
const Util::ResizeablePointer & getRemoteAddr() const;
void GetDestination(std::string &hostname, uint32_t &port);
void GetLocalDestination(std::string &hostname, uint32_t &port);
std::string getBinDestination();
const void * getDestAddr(){return destAddr;}
size_t getDestAddrLen(){return destAddr.size();}
size_t getDestAddrLen(){return destAddr_size;}
std::string getBoundAddress();
uint16_t getBoundPort() const;
uint32_t getDestPort() const;
bool Receive();
void SendNow(const std::string &data);

View file

@ -1,5 +1,5 @@
#include "defines.h"
#include "http_parser.h"
#include "lib/http_parser.h"
#include "socket_srt.h"
#include "json.h"
#include "timing.h"
@ -9,15 +9,6 @@
#define INVALID_SRT_SOCKET -1
/// Calls gai_strerror with the given argument, calling regular strerror on the global errno as needed
static const char *gai_strmagic(int errcode){
if (errcode == EAI_SYSTEM){
return strerror(errno);
}else{
return gai_strerror(errcode);
}
}
namespace Socket{
namespace SRT{
bool isInited = false;
@ -35,7 +26,6 @@ namespace Socket{
bool libraryCleanup(){
if (isInited){
alarm(2);
srt_cleanup();
isInited = false;
}
@ -51,36 +41,17 @@ namespace Socket{
sockaddr_in createInetAddr(const std::string &_host, int _port){
sockaddr_in res;
memset(&res, 0, sizeof res);
struct addrinfo *result, *rp, hints;
std::stringstream ss;
ss << _port;
memset(&res, 9, sizeof res);
res.sin_family = AF_INET;
res.sin_port = htons(_port);
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET6;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = AI_ADDRCONFIG | AI_ALL;
hints.ai_protocol = IPPROTO_UDP;
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL;
int s = getaddrinfo(_host.c_str(), ss.str().c_str(), &hints, &result);
if (s != 0){
hints.ai_family = AF_UNSPEC;
s = getaddrinfo(_host.c_str(), ss.str().c_str(), &hints, &result);
if (s != 0){
FAIL_MSG("Could not connect SRT socket to %s:%i! Error: %s", _host.c_str(), _port, gai_strmagic(s));
return res;
}
if (_host != ""){
if (inet_pton(AF_INET, _host.c_str(), &res.sin_addr) == 1){return res;}
hostent *he = gethostbyname(_host.c_str());
if (!he || he->h_addrtype != AF_INET){ERROR_MSG("Host not found %s", _host.c_str());}
res.sin_addr = *(in_addr *)he->h_addr_list[0];
}
for (rp = result; rp != NULL; rp = rp->ai_next){
size_t maxSize = rp->ai_addrlen;
if (maxSize > sizeof(res)){maxSize = sizeof(res);}
memcpy(&res, rp->ai_addr, maxSize);
break;
}
freeaddrinfo(result);
return res;
}
@ -120,9 +91,9 @@ namespace Socket{
direction = rhs.direction;
remotehost = rhs.remotehost;
sock = rhs.sock;
HIGH_MSG("COPIED SRT socket %d", sock);
performanceMonitor = rhs.performanceMonitor;
host = rhs.host;
outgoing_port = rhs.outgoing_port;
prev_pktseq = rhs.prev_pktseq;
lastGood = rhs.lastGood;
chunkTransmitSize = rhs.chunkTransmitSize;
@ -139,94 +110,17 @@ namespace Socket{
SRTConnection::SRTConnection(const std::string &_host, int _port, const std::string &_direction,
const std::map<std::string, std::string> &_params){
initializeEmpty();
connect(_host, _port, _direction, _params);
}
SRTConnection::SRTConnection(Socket::UDPConnection & _udpsocket, const std::string &_direction, const paramList &_params){
initializeEmpty();
direction = "output";
handleConnectionParameters("", _params);
HIGH_MSG("Opening SRT connection in %s mode (%s) on socket %d", modeName.c_str(), direction.c_str(), _udpsocket.getSock());
// Copy address from UDP socket
memcpy(&remoteaddr, _udpsocket.getDestAddr(), _udpsocket.getDestAddrLen());
static char addrconv[INET6_ADDRSTRLEN];
if (remoteaddr.sin6_family == AF_INET6){
remotehost = inet_ntop(AF_INET6, &(remoteaddr.sin6_addr), addrconv, INET6_ADDRSTRLEN);
HIGH_MSG("IPv6 addr [%s]", remotehost.c_str());
}
if (remoteaddr.sin6_family == AF_INET){
remotehost = inet_ntop(AF_INET, &(((sockaddr_in *)&remoteaddr)->sin_addr), addrconv, INET6_ADDRSTRLEN);
HIGH_MSG("IPv4 addr [%s]", remotehost.c_str());
}
sock = srt_create_socket();
HIGH_MSG("Opened SRT socket %d", sock);
if (_direction == "rendezvous"){
bool v = true;
srt_setsockopt(sock, 0, SRTO_RENDEZVOUS, &v, sizeof v);
}
if (preConfigureSocket() == SRT_ERROR){
ERROR_MSG("Error configuring SRT socket");
return;
}
srt_bind_acquire(sock, _udpsocket.getSock());
if (sock == SRT_INVALID_SOCK){
ERROR_MSG("Error creating an SRT socket from bound UDP socket");
return;
}
lastGood = Util::bootMS();
if (_direction == "rendezvous"){return;}
srt_listen(sock, 1);
SRTSOCKET tmpSock = srt_accept_bond(&sock, 1, 10000);
HIGH_MSG("Opened SRT socket %d", tmpSock);
close();
sock = tmpSock;
if (sock == SRT_INVALID_SOCK){
FAIL_MSG("SRT error: %s", srt_getlasterror_str());
return;
}
if (postConfigureSocket() == SRT_ERROR){
ERROR_MSG("Error during postconfigure socket");
return;
}
HIGH_MSG("UDP to SRT socket conversion %" PRId32 ": %s", sock, getStateStr());
}
const char * SRTConnection::getStateStr(){
if (sock == INVALID_SRT_SOCKET){return "invalid / closed";}
int state = srt_getsockstate(sock);
switch (state){
case SRTS_INIT: return "init";
case SRTS_OPENED: return "opened";
case SRTS_LISTENING: return "listening";
case SRTS_CONNECTING: return "connecting";
case SRTS_CONNECTED: return "connected";
case SRTS_BROKEN: return "broken";
case SRTS_CLOSING: return "closing";
case SRTS_CLOSED: return "closed";
case SRTS_NONEXIST: return "does not exist";
}
return "unknown";
}
SRTConnection::SRTConnection(SRTSOCKET alreadyConnected){
initializeEmpty();
sock = alreadyConnected;
HIGH_MSG("COPIED SRT socket %d", sock);
}
std::string SRTConnection::getStreamName(){
int sNameLen = 512;
char sName[512];
char sName[sNameLen];
int optRes = srt_getsockflag(sock, SRTO_STREAMID, (void *)sName, &sNameLen);
if (optRes != -1 && sNameLen){return sName;}
return "";
@ -264,8 +158,8 @@ namespace Socket{
}
if (err == SRT_ENOCONN){
if (Util::bootMS() > lastGood + 5000){
ERROR_MSG("SRT connection timed out");
timedOut = true;
ERROR_MSG("SRT connection timed out - closing");
close();
}
return 0;
}
@ -275,7 +169,6 @@ namespace Socket{
}
if (receivedBytes == 0){
close();
return 0;
}else{
lastGood = Util::bootMS();
}
@ -295,14 +188,13 @@ namespace Socket{
int err = srt_getlasterror(0);
if (err == SRT_EASYNCRCV){return 0;}
if (err == SRT_ECONNLOST){
INFO_MSG("SRT connection %d lost", sock);
close();
return 0;
}
if (err == SRT_ENOCONN){
if (Util::bootMS() > lastGood + 5000){
ERROR_MSG("SRT connection timed out - closing");
timedOut = true;
close();
}
return 0;
}
@ -311,9 +203,7 @@ namespace Socket{
return 0;
}
if (receivedBytes == 0){
INFO_MSG("SRT connection %d closed", sock);
close();
return 0;
}else{
lastGood = Util::bootMS();
}
@ -323,43 +213,51 @@ namespace Socket{
void SRTConnection::connect(const std::string &_host, int _port, const std::string &_direction,
const std::map<std::string, std::string> &_params){
initializeEmpty();
direction = _direction;
timedOut = false;
handleConnectionParameters(_host, _params);
HIGH_MSG("Opening SRT connection %s in %s mode on %s:%d", modeName.c_str(), direction.c_str(),
_host.c_str(), _port);
if (sock == SRT_INVALID_SOCK){
sock = srt_create_socket();
HIGH_MSG("Opened SRT socket %d", sock);
if (sock == SRT_INVALID_SOCK){
ERROR_MSG("Error creating an SRT socket");
return;
}
if (preConfigureSocket() == SRT_ERROR){
ERROR_MSG("Error configuring SRT socket");
return;
}
sock = srt_create_socket();
if (sock == SRT_ERROR){
ERROR_MSG("Error creating an SRT socket");
return;
}
if (modeName == "rendezvous"){
bool v = true;
srt_setsockopt(sock, 0, SRTO_RENDEZVOUS, &v, sizeof v);
}
if (preConfigureSocket() == SRT_ERROR){
ERROR_MSG("Error configuring SRT socket");
return;
}
if (modeName == "caller"){
std::deque<std::string> addrs = Socket::getAddrs(_host, _port);
for (std::deque<std::string>::iterator it = addrs.begin(); it != addrs.end(); ++it){
size_t maxSize = it->size();
if (maxSize > sizeof(remoteaddr)){maxSize = sizeof(remoteaddr);}
memcpy(&remoteaddr, it->data(), maxSize);
if (outgoing_port){setupAdapter("", outgoing_port);}
sockaddr *psa = (sockaddr *)&remoteaddr;
HIGH_MSG("Going to connect sock %d", sock);
if (srt_connect(sock, psa, sizeof remoteaddr) != SRT_ERROR){
if (postConfigureSocket() == SRT_ERROR){ERROR_MSG("Error during postconfigure socket");}
INFO_MSG("Caller SRT socket %" PRId32 " success targetting %s:%u", sock, _host.c_str(), _port);
lastGood = Util::bootMS();
return;
}
sockaddr_in sa = createInetAddr(_host, _port);
memcpy(&remoteaddr, &sa, sizeof(sockaddr_in));
sockaddr *psa = (sockaddr *)&sa;
HIGH_MSG("Going to connect sock %d", sock);
if (srt_connect(sock, psa, sizeof sa) == SRT_ERROR){
srt_close(sock);
sock = -1;
ERROR_MSG("Can't connect SRT Socket");
return;
}
close();
ERROR_MSG("Can't connect SRT socket to any address for %s", _host.c_str());
HIGH_MSG("Connected sock %d", sock);
if (postConfigureSocket() == SRT_ERROR){
ERROR_MSG("Error during postconfigure socket");
return;
}
INFO_MSG("Caller SRT socket %" PRId32 " success targetting %s:%u", sock, _host.c_str(), _port);
lastGood = Util::bootMS();
return;
}
if (modeName == "listener"){
@ -369,19 +267,61 @@ namespace Socket{
sockaddr *psa = (sockaddr *)&sa;
if (srt_bind(sock, psa, sizeof sa) == SRT_ERROR){
close();
srt_close(sock);
sock = -1;
ERROR_MSG("Can't connect SRT Socket: %s", srt_getlasterror_str());
return;
}
if (srt_listen(sock, 100) == SRT_ERROR){
close();
srt_close(sock);
sock = -1;
ERROR_MSG("Can not listen on Socket");
}
INFO_MSG("Listener SRT socket success @ %s:%u", _host.c_str(), _port);
lastGood = Util::bootMS();
return;
}
ERROR_MSG("Invalid mode parameter. Use 'caller' or 'listener'");
if (modeName == "rendezvous"){
int outport = (outgoing_port ? outgoing_port : _port);
HIGH_MSG("Going to bind a server on %s:%u", _host.c_str(), _port);
sockaddr_in sa = createInetAddr(_host, outport);
sockaddr *psa = (sockaddr *)&sa;
if (srt_bind(sock, psa, sizeof sa) == SRT_ERROR){
srt_close(sock);
sock = -1;
ERROR_MSG("Can't connect SRT Socket");
return;
}
sockaddr_in sb = createInetAddr(_host, outport);
sockaddr *psb = (sockaddr *)&sb;
if (srt_connect(sock, psb, sizeof sb) == SRT_ERROR){
srt_close(sock);
sock = -1;
ERROR_MSG("Can't connect SRT Socket");
return;
}
if (postConfigureSocket() == SRT_ERROR){
ERROR_MSG("Error during postconfigure socket");
return;
}
INFO_MSG("Rendezvous SRT socket success @ %s:%u", _host.c_str(), _port);
lastGood = Util::bootMS();
return;
}
ERROR_MSG("Invalid mode parameter. Use 'client' or 'server'");
}
void SRTConnection::setupAdapter(const std::string &_host, int _port){
sockaddr_in localsa = createInetAddr(_host, _port);
sockaddr *psa = (sockaddr *)&localsa;
if (srt_bind(sock, psa, sizeof localsa) == SRT_ERROR){
ERROR_MSG("Unable to bind socket to %s:%u", _host.c_str(), _port);
}
}
void SRTConnection::SendNow(const std::string &data){SendNow(data.data(), data.size());}
@ -398,17 +338,14 @@ namespace Socket{
return;
}
if (err == SRT_ENOCONN){
if (Util::bootMS() > lastGood + 10000){
if (Util::bootMS() > lastGood + 5000){
ERROR_MSG("SRT connection timed out - closing");
timedOut = true;
close();
}
return;
}
// ERROR_MSG("Unable to send data over socket %" PRId32 ": %s", sock, srt_getlasterror_str());
if (srt_getsockstate(sock) != SRTS_CONNECTED){
close();
return;
}
if (srt_getsockstate(sock) != SRTS_CONNECTED){close();}
}else{
lastGood = Util::bootMS();
}
@ -441,9 +378,9 @@ namespace Socket{
memset(&performanceMonitor, 0, sizeof(performanceMonitor));
prev_pktseq = 0;
sock = SRT_INVALID_SOCK;
outgoing_port = 0;
chunkTransmitSize = 1316;
blocking = false;
timedOut = false;
timeout = 0;
}
@ -460,9 +397,9 @@ namespace Socket{
void SRTConnection::handleConnectionParameters(const std::string &_host,
const std::map<std::string, std::string> &_params){
params = _params;
VERYHIGH_MSG("SRT Received parameters: ");
DONTEVEN_MSG("SRT Received parameters: ");
for (std::map<std::string, std::string>::const_iterator it = params.begin(); it != params.end(); it++){
VERYHIGH_MSG(" %s: %s", it->first.c_str(), it->second.c_str());
DONTEVEN_MSG(" %s: %s", it->first.c_str(), it->second.c_str());
}
adapter = (params.count("adapter") ? params.at("adapter") : "");
@ -480,6 +417,8 @@ namespace Socket{
tsbpdMode = (params.count("tsbpd") && JSON::Value(params.at("tsbpd")).asBool());
outgoing_port = (params.count("port") ? strtol(params.at("port").c_str(), 0, 0) : 0);
if ((!params.count("transtype") || params.at("transtype") != "file") && chunkTransmitSize > SRT_LIVE_DEF_PLSIZE){
if (chunkTransmitSize > SRT_LIVE_MAX_PLSIZE){
ERROR_MSG("Chunk size in live mode exceeds 1456 bytes!");
@ -500,10 +439,12 @@ namespace Socket{
}
if (srt_setsockopt(sock, 0, SRTO_RCVSYN, &no, sizeof no) == -1){return -1;}
linger lin;
lin.l_linger = params.count("linger") ? atoi(params.at("linger").c_str()) : 0;
lin.l_onoff = lin.l_linger ? 1 : 0;
srt_setsockopt(sock, 0, SRTO_LINGER, &lin, sizeof(linger));
if (params.count("linger")){
linger lin;
lin.l_linger = atoi(params.at("linger").c_str());
lin.l_onoff = lin.l_linger > 0 ? 1 : 0;
srt_setsockopt(sock, 0, SRTO_LINGER, &lin, sizeof(linger));
}
std::string errMsg = configureSocketLoop(SRT::SockOpt::PRE);
if (errMsg.size()){
@ -549,11 +490,9 @@ namespace Socket{
}
void SRTConnection::close(){
if (sock != INVALID_SRT_SOCKET){
HIGH_MSG("Closing SRT socket %d", sock);
setBlocking(true);
if (sock != -1){
srt_close(sock);
sock = INVALID_SRT_SOCKET;
sock = -1;
}
}

View file

@ -37,14 +37,12 @@ namespace Socket{
SRTConnection(SRTSOCKET alreadyConnected);
SRTConnection(const std::string &_host, int _port, const std::string &_direction = "input",
const paramList &_params = paramList());
SRTConnection(Socket::UDPConnection & _udpsocket, const std::string &_direction, const paramList &_params);
void connect(const std::string &_host, int _port, const std::string &_direction = "input",
const paramList &_params = paramList());
void close();
bool connected() const{return (sock != -1) && !timedOut;}
bool connected() const{return sock != -1;}
operator bool() const{return connected();}
const char * getStateStr();
void setBlocking(bool blocking); ///< Set this socket to be blocking (true) or nonblocking (false).
bool isBlocking(); ///< Check if this socket is blocking (true) or nonblocking (false).
@ -79,9 +77,9 @@ namespace Socket{
CBytePerfMon performanceMonitor;
std::string host;
int outgoing_port;
int32_t prev_pktseq;
uint64_t lastGood;
bool timedOut;
uint32_t chunkTransmitSize;
@ -96,6 +94,7 @@ namespace Socket{
void handleConnectionParameters(const std::string &_host, const paramList &_params);
int preConfigureSocket();
std::string configureSocketLoop(SRT::SockOpt::Binding _binding);
void setupAdapter(const std::string &_host, int _port);
bool blocking;
};

View file

@ -213,6 +213,7 @@ namespace HTTP{
downer.getSocket().close();
downer.getSocket().Received().clear();
allData.truncate(0);
if (!downer.isOk()){return false;}
supportRangeRequest = false;
totalSize = std::string::npos;
}else{
@ -287,23 +288,19 @@ namespace HTTP{
}
void URIReader::readAll(size_t (*dataCallback)(const char *data, size_t len)){
while (!isEOF()){
if (!readSome(dataCallback, 419430)){Util::sleep(50);}
}
while (!isEOF()){readSome(dataCallback, 419430);}
}
/// Read all function, with use of callbacks
void URIReader::readAll(Util::DataCallback &cb){
while (!isEOF()){
if (!readSome(1048576, cb)){Util::sleep(50);}
}
while (!isEOF()){readSome(1048576, cb);}
}
/// Read all blocking function, which internally uses the Nonblocking function.
void URIReader::readAll(char *&dataPtr, size_t &dataLen){
if (getSize() != std::string::npos){allData.allocate(getSize());}
while (!isEOF()){
if (!readSome(10046, *this)){Util::sleep(50);}
readSome(10046, *this);
bufPos = allData.size();
}
dataPtr = allData;
@ -312,38 +309,27 @@ namespace HTTP{
void httpBodyCallback(const char *ptr, size_t size){INFO_MSG("callback");}
size_t URIReader::readSome(size_t (*dataCallback)(const char *data, size_t len), size_t wantedLen){
void URIReader::readSome(size_t (*dataCallback)(const char *data, size_t len), size_t wantedLen){
/// TODO: Implement
return 0;
}
// readsome with callback
size_t URIReader::readSome(size_t wantedLen, Util::DataCallback &cb){
if (isEOF()){return 0;}
void URIReader::readSome(size_t wantedLen, Util::DataCallback &cb){
if (isEOF()){return;}
// Files read from the memory-mapped file
if (stateType == HTTP::File){
// Simple bounds check, don't read beyond the end of the file
uint64_t dataLen = ((wantedLen + curPos) > totalSize) ? totalSize - curPos : wantedLen;
cb.dataCallback(mapped + curPos, dataLen);
curPos += dataLen;
return dataLen;
return;
}
// HTTP-based read from the Downloader
if (stateType == HTTP::HTTP){
// Note: this function returns true if the full read was completed only.
// It's the reason this function returns void rather than bool.
size_t prev = cb.getDataCallbackPos();
if (downer.continueNonBlocking(cb)){
if (downer.getStatusCode() >= 400){
WARN_MSG("Received error response code %" PRIu32 " (%s)", downer.getStatusCode(), downer.getStatusText().c_str());
// cb.dataCallbackFlush();
downer.getSocket().close();
downer.getSocket().Received().clear();
allData.truncate(0);
return 0;
}
}
return cb.getDataCallbackPos() - prev;
downer.continueNonBlocking(cb);
return;
}
// Everything else uses the socket directly
int s = downer.getSocket().Received().bytes(wantedLen);
@ -353,7 +339,7 @@ namespace HTTP{
s = downer.getSocket().Received().bytes(wantedLen);
}else{
Util::sleep(50);
return s;
return;
}
}
// Future optimization: augment the Socket::Buffer to handle a Util::DataCallback as argument.
@ -361,11 +347,10 @@ namespace HTTP{
Util::ResizeablePointer buf;
downer.getSocket().Received().remove(buf, s);
cb.dataCallback(buf, s);
return s;
}
/// Readsome blocking function.
size_t URIReader::readSome(char *&dataPtr, size_t &dataLen, size_t wantedLen){
void URIReader::readSome(char *&dataPtr, size_t &dataLen, size_t wantedLen){
// Clear the buffer if we're finished with it
if (allData.size() && bufPos == allData.size()){
allData.truncate(0);
@ -380,13 +365,12 @@ namespace HTTP{
dataPtr = allData + bufPos;
dataLen = wantedLen;
bufPos += wantedLen;
return wantedLen;
return;
}
// Ok, we have a short count. Return the amount we actually got.
dataPtr = allData + bufPos;
dataLen = allData.size() - bufPos;
bufPos = allData.size();
return dataLen;
}
void URIReader::close(){

View file

@ -1,6 +1,7 @@
#pragma once
#include "downloader.h"
#include "util.h"
#include <fstream>
namespace HTTP{
enum URIType{Closed = 0, File, Stream, HTTP};
@ -36,11 +37,11 @@ namespace HTTP{
void readAll(Util::DataCallback &cb);
/// Reads wantedLen bytes of data from current position, calling the dataCallback whenever minLen/maxLen require it.
size_t readSome(size_t (*dataCallback)(const char *data, size_t len), size_t wantedLen);
void readSome(size_t (*dataCallback)(const char *data, size_t len), size_t wantedLen);
/// Reads wantedLen bytes of data from current position, returning it in a single buffer.
size_t readSome(char *&dataPtr, size_t &dataLen, size_t wantedLen);
void readSome(char *&dataPtr, size_t &dataLen, size_t wantedLen);
size_t readSome(size_t wantedLen, Util::DataCallback &cb);
void readSome(size_t wantedLen, Util::DataCallback &cb);
/// Closes the currently open URI. Does not change the internal URI value.
void close();

View file

@ -20,7 +20,6 @@
#endif
#include <stdlib.h>
#include <sys/resource.h>
#include <fstream>
#define RAXHDR_FIELDOFFSET p[1]
#define RAX_REQDFIELDS_LEN 36
@ -361,20 +360,6 @@ namespace Util{
maxSize = 0;
}
ResizeablePointer::ResizeablePointer(const ResizeablePointer & rhs){
currSize = 0;
ptr = 0;
maxSize = 0;
append(rhs, rhs.size());
}
ResizeablePointer& ResizeablePointer::operator= (const ResizeablePointer& rhs){
if (this == &rhs){return *this;}
truncate(0);
append(rhs, rhs.size());
return *this;
}
void ResizeablePointer::shift(size_t byteCount){
//Shifting the entire buffer is easy, we do nothing and set size to zero
if (byteCount >= currSize){
@ -386,20 +371,6 @@ namespace Util{
currSize -= byteCount;
}
/// Takes another ResizeablePointer as argument and swaps their pointers around,
/// thus exchanging them without needing to copy anything.
void ResizeablePointer::swap(ResizeablePointer & rhs){
void * tmpPtr = ptr;
size_t tmpCurrSize = currSize;
size_t tmpMaxSize = maxSize;
ptr = rhs.ptr;
currSize = rhs.currSize;
maxSize = rhs.maxSize;
rhs.ptr = tmpPtr;
rhs.currSize = tmpCurrSize;
rhs.maxSize = tmpMaxSize;
}
bool ResizeablePointer::assign(const void *p, uint32_t l){
if (!allocate(l)){return false;}
memcpy(ptr, p, l);
@ -434,7 +405,12 @@ namespace Util{
bool ResizeablePointer::allocate(uint32_t l){
if (l > maxSize){
void *tmp = realloc(ptr, l);
void *tmp = 0;
if (!ptr){
tmp = malloc(l);
}else{
tmp = realloc(ptr, l);
}
if (!tmp){
FAIL_MSG("Could not allocate %" PRIu32 " bytes of memory", l);
return false;

View file

@ -48,8 +48,6 @@ namespace Util{
class ResizeablePointer{
public:
ResizeablePointer();
ResizeablePointer(const ResizeablePointer & rhs);
ResizeablePointer& operator= (const ResizeablePointer& rhs);
~ResizeablePointer();
inline size_t &size(){return currSize;}
inline const size_t size() const{return currSize;}
@ -59,7 +57,6 @@ namespace Util{
bool append(const std::string &str);
bool allocate(uint32_t l);
void shift(size_t byteCount);
void swap(ResizeablePointer & rhs);
uint32_t rsize();
void truncate(const size_t newLen);
inline operator char *(){return (char *)ptr;}

View file

@ -1,14 +1,12 @@
</head>
<body>
<nav>
<div class="textures"></div>
<a href='#' class=logo>MistServer</a>
<div class=menu>
</div>
</nav>
<div class=filler>
<header>
<div class="texture"></div>
<h1>Management Interface</h1>
<aside id=status>
<span id='connection' class='red'>Disconnected</span>

View file

@ -1,4 +0,0 @@
<svg viewBox="0 0 202.52 150" version="1.1" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid meet">
<path d="m53.406 10.557-5.0488 3.3223 42.061 63.951c-1.0569 1.2973-1.8786 2.7896-2.418 4.4121h-70.115v6.0449h69.498c0.81169 6.9508 6.713 12.344 13.879 12.344 7.1658 0 13.064-5.393 13.875-12.344h69.5v-6.0449h-70.117c-0.53924-1.6225-1.3594-3.1148-2.416-4.4121l42.061-63.951-5.0508-3.3223-41.777 63.518c-1.8391-0.89026-3.894-1.4043-6.0742-1.4043-2.1814 0-4.238 0.51505-6.0781 1.4062z" fill="#b5d3e2"/>
<path d="m49.875 0c-7.0953 0-12.848 5.7519-12.848 12.846 0 3.7198 1.5899 7.0604 4.1152 9.4062l-20.535 46.447c-1.0469-0.19686-2.1225-0.31055-3.2266-0.31055-9.5991 0-17.381 7.783-17.381 17.381 0 9.5997 7.7817 17.381 17.381 17.381 5.3445 0 10.122-2.4174 13.311-6.2129l54.49 29.096c-0.83369 2.0328-1.3008 4.2547-1.3008 6.5879 0 9.5997 7.7811 17.379 17.379 17.379 9.5997 0 17.381-7.7792 17.381-17.379 0-2.3333-0.46899-4.5551-1.3027-6.5879l54.492-29.098c3.1877 3.796 7.963 6.2148 13.309 6.2148 9.5997 0 17.381-7.7812 17.381-17.381 0-9.5978-7.7812-17.381-17.381-17.381-1.1042 0-2.1796 0.11369-3.2266 0.31055l-20.535-46.447c2.5256-2.3459 4.1152-5.6861 4.1152-9.4062 0-7.0938-5.7519-12.846-12.846-12.846-5.9165 0-10.885 4.0056-12.377 9.4473h-78.018c-1.4922-5.4418-6.4613-9.4473-12.377-9.4473zm13.406 15.492h75.957l-24.789 11.568c-3.1173-3.8293-7.8647-6.2793-13.188-6.2793-5.3228 0-10.072 2.45-13.189 6.2793zm-3.498 5.5312 24.967 12.77c-0.30913 1.2822-0.49218 2.6131-0.49218 3.9902 0 1.6082 0.23907 3.1582 0.65625 4.6328l-54.004 32.453c-1.2919-1.6017-2.8674-2.9575-4.6426-4.0176l20.174-45.635c1.0944 0.30322 2.2426 0.47851 3.4336 0.47851 3.9887 0 7.552-1.819 9.9082-4.6719zm82.953 0c2.3561 2.8528 5.9208 4.6719 9.9102 4.6719 1.1903 0 2.3377-0.17551 3.4316-0.47851l20.176 45.635c-1.7754 1.0602-3.3507 2.4157-4.6426 4.0176l-54.004-32.453c0.41706-1.4746 0.6543-3.0247 0.6543-4.6328 0-1.377-0.18122-2.7081-0.49024-3.9902zm-54.041 28.186c2.2766 2.5025 5.2868 4.3206 8.6894 5.1211v61.355c-3.5044 0.80386-6.605 2.6644-8.9492 5.2324l-54.734-29.225c0.67236-1.8515 1.0605-3.8399 1.0605-5.9238 0-1.8275-0.28752-3.5875-0.81055-5.2422zm25.131 2e-3 54.742 31.316c-0.52293 1.6547-0.80859 3.4147-0.80859 5.2422 0 2.0838 0.38643 4.0724 1.0586 5.9238l-54.734 29.225c-2.3448-2.5682-5.4441-4.4287-8.9492-5.2324v-61.354c3.4038-0.79961 6.4143-2.6181 8.6914-5.1211z" fill="#8cb3cf"/>
</svg>

Before

Width:  |  Height:  |  Size: 2.3 KiB

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
<g style="fill:white;stroke-linecap:round;stroke-linejoin:round;stroke-width:2;stroke:black">
<path d="m37.911 25.289v29.464m5.912-30.901v29.464m-11.823-27.378v29.464m-5.911-30.113v29.464m-5.912-30.901v29.464m-6.09-34.372 2.0832 35.971c8.8845 3.9794 18.734 5.7595 31.761.29565l2.1104-36.298" />
<path d="m13.099 12.895c7.7397-4.6876 30.017-4.6844 37.926-.09329l-.06132 5.8224c-9.8599 4.1879-26.296 4.0174-37.855-.24019z"/>
<path d="m38.84 11.832v-3.4648c0-1.5465-1.2445-2.791-2.791-2.791h-7.793c-1.5465 0-2.791 1.2445-2.791 2.791v3.4648" style="fill:none;"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 745 B

View file

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0,1.599)" style="fill:#fff;stroke-linejoin:round;stroke-width:2;stroke:#000"><path id="embed_a" d="m41.235 15.244v7.4431l12.655 7.6678-12.655 7.7982v7.4043l19.765-12.669v-5.1286z"/><path d="m25.809 45.827h5.2092l7.1731-30.852h-5.1407z" style="fill:#bbb"/><use transform="matrix(-1,0,0,1,64,0)" href="#embed_a"/></g></svg>

Before

Width:  |  Height:  |  Size: 503 B

View file

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="m3 24.95v38.05h58v-45.308l-20.045.13815-7.412 7.2845z" style="fill:none;stroke-linejoin:round;stroke-width:2;stroke:black"/></svg>

Before

Width:  |  Height:  |  Size: 297 B

View file

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg width="55.3" height="100" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<path id="a" d="m41.5 82-27.7-16v-32l27.7-16" style="fill:#ccc"/>
<use transform="translate(-27.7 -48)" xlink:href="#a"/>
<use transform="translate(-27.7 48)" xlink:href="#a"/>
<use transform="translate(27.7,-48)" xlink:href="#a"/>
<use transform="translate(27.7,48)" xlink:href="#a"/>
</svg>

Before

Width:  |  Height:  |  Size: 524 B

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
<g style="fill:white;stroke-width:2;stroke:black;stroke-linejoin:round">
<path d="m26.76 5.6635c-7.5343 0-13.601 6.0188-13.601 13.497v11.019h-1.3072c-1.5978 0-2.884 1.2767-2.884 2.8627v23.508c0 1.586 1.2862 2.8627 2.884 2.8627h31.152c1.5978 0 2.884-1.2767 2.884-2.8627v-23.508c0-1.586-1.2862-2.8627-2.884-2.8627h-1.3072v-11.019c0-7.4787-6.067-13.497-13.601-13.497h-1.3342zm.66709 5.5315c4.9411 0 8.9181 3.9476 8.9181 8.8523v10.133h-17.836v-10.133c0-4.9046 3.977-8.8523 8.9181-8.8523zm0 24.955a5.3965 5.3567 0 015.3973 5.3575 5.3965 5.3567 0 01-1.1084 3.1737l.78501 9.18h-10.148l.78501-9.18a5.3965 5.3567 0 01-1.1084-3.1737 5.3965 5.3567 0 015.3973-5.3575z"/>
<path d="m46.396 3.3457a12.774 12.774 0 00-12.773 12.773 12.774 12.774 0 007.9375 11.795l.13086 27.883 3.9941 4.2812 4.0762-4.2812v-2.582l.93359-1.0742-.93359-1.0059v-2.0195l1.1309-1.2285-2.3105-2.8203 1.9492-2.0469-.76953-.77734v-1.6406l1.1387-1.6445-1.1387-1.6309v-2.8945h.58203v-2.5293h.88867v-3.9883a12.774 12.774 0 007.9375-11.795 12.774 12.774 0 00-12.773-12.773zm0 4.6367a2.7302 2.7302 0 012.7305 2.7305 2.7302 2.7302 0 01-2.7305 2.7305 2.7302 2.7302 0 01-2.7305-2.7305 2.7302 2.7302 0 012.7305-2.7305z" style="fill:#bbb"/></g>
</svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g style="fill:white;stroke-linejoin:round;stroke-width:2;stroke:#000">
<circle cx="32" cy="32" r="25.82"/>
<g style="fill:#bbb">
<circle cx="32" cy="32" r="3.1649" />
<path id="nuke_a" d="m35.089 26.907c1.7185 1.0445 2.8663 2.9346 2.866 5.0926h15.059c3.2e-5-7.7385-4.183-14.5-10.411-18.147z" />
<use transform="rotate(120 32 32)" href="#nuke_a"/>
<use transform="rotate(240 32 32)" href="#nuke_a"/>
</g></g>
</svg>

Before

Width:  |  Height:  |  Size: 619 B

View file

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" xmlns="http://www.w3.org/2000/svg">
<path d="m17.449 8.781a4.3899 4.3892 0 00-2.0138 3.6931l.02568 42.198a4.3899 4.3892 0 006.5995 3.782l36.55-21.099a4.3899 4.3892 0 00-.01639-7.5822l-36.576-21.099a4.3899 4.3892 0 00-4.5693.107z" style="fill:#fff;stroke-width:2;stroke:#000"/>
</svg>

Before

Width:  |  Height:  |  Size: 367 B

View file

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
<g style="fill:white;stroke-linejoin:round;stroke-width:2;stroke:black">
<rect x="3" y="11.068" width="58" height="41.864" rx="4.3702" ry="4.3702" style="fill:#999"/>
<rect x="3" y="46.094" width="58" height="6.8374" rx="0" ry="0" style="fill:#888"/>
<path d="m28.168 21.579c-.32531.20939-.52183.56983-.52162.95671l.0067 10.931c.00099.40652.21892.78159.57162.98374.3527.20215.78648.20062 1.1377-.004l9.4671-5.4658c.34883-.20454.56278-.57894.5619-.98331-.000891-.40437-.21644-.77785-.56615-.98087l-9.4738-5.4654c-.36858-.21304-.8253-.20233-1.1835.02774v0"/>
<rect x="3" y="46.094" width="18.513" height="6.8374" rx="0" ry="0"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 797 B

View file

@ -1,7 +0,0 @@
https://ai-generator.livepeer.cloud/
Create a simple icon. The subject is <subbject>. The background is bright white. Make the subject as simple as possible, instead fill large areas with black.
resolution: 512x512
steps: 50
guidance scale: 3.5

View file

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="m23.281 40.259 1.6271-4.0733-21.419 6.9038 20.588 8.0913-1.2718-3.8278c39.218 0 62.256-18.891.9224-18.891 39.996 0 40.549 11.797-.44748 11.797z" style="fill:white;stroke-linejoin:round;stroke-width:2;stroke:#000"/></svg>

Before

Width:  |  Height:  |  Size: 387 B

View file

@ -1,7 +0,0 @@
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg">
<g style="fill:white;stroke-linejoin:round;stroke-linecap:round;stroke-width:2;stroke:#000">
<path d="m4.4688 12.736s-2.0621 7.6884 2.2158 12.786c4.2779 5.0979 11.307 4.6211 11.307 4.6211s27.012 25.587 29.406 27.869 8.5275 2.1674 11.066-.90518c2.5384-3.0726 2.2306-7.4614-.46845-10.211s-27.997-27.545-27.997-27.545.6011-8.1225-4.8868-12.408c-5.4879-4.2856-13.415-1.7504-13.415-1.7504s8.7811 7.3913 8.762 9.4592c-.01913 2.0679-3.916 6.2966-6.3076 6.4202s-9.681-8.3364-9.681-8.3364z"/>
<path d="m22.633 38.006s-6.736 7.5891-8.0449 8.4199c-1.3089.83085-3.5855-.2392-4.4648.80469-.87936 1.0439-6.5742 9.1207-6.5742 10.383l2.4688 2.377c1.2622 0 9.3389-5.6949 10.383-6.5742s-.02812-3.1559.80273-4.4648c.64227-1.0118 2.3172-1.885 8.4219-8.0449z"/>
<path d="m40.861 26.306 14.533-14.533m-17.375 11.694 14.533-14.533m-2.3952-3.6008-15.215 15.059 8.6584 8.6493 15.449-14.514c2.7285-2.5225 2.4789-6.8937.16099-8.9833-2.318-2.0896-6.1056-2.7806-9.0534-.21097z" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g style="fill:#ccc;stroke-linecap:round;stroke-linejoin:round;stroke-width:2;stroke:#000">
<path d="m26.816 7.4258v.87305h-1.0586v1.4805h-.99805v42.021h1.498v1.2207h11.484v-1.2207h1.498v-42.021h-.99805v-1.4805h-1.0586v-.87305h-10.367z"/>
<path d="m28.678 60.63v-7.6083h6.6448v7.6083"/>
<path id="status_a" d="m39.24 37.375h8.6066c0 3.302-.4732 4.3899-3.0278 5.5674s-3.5266 3.5141-4.0095 5.1494.05917 2.6733-1.5693 2.6733z"/>
<use id="status_b" transform="translate(0 -26.03)" href="#status_a"/>
<use id="status_c" transform="translate(0,-13.015)" href="#status_a"/>
<use transform="matrix(-1 0 0 1 63.892 0)" href="#status_a"/>
<use transform="matrix(-1,0,0,1,63.892,0)" href="#status_c"/>
<use transform="matrix(-1 0 0 1 63.892 0)" href="#status_b"/>
<g style="fill:#fff;stroke-width:1.5">
<path d="m29.228 12.969c-.21726.14276-.3485.3885-.34836.65228l.0045 7.4528c.000662.27716.1462.53288.38175.67071.23554.13782.52525.13678.75984-.0027l6.3225-3.7265c.23296-.13945.37584-.39472.37526-.67042-.000662-.2757-.14455-.53033-.3781-.66875l-6.327-3.7262c-.24616-.14525-.55117-.13795-.79038.01891"/>
<path d="m28.631 33.591a.91153.69906 0 00.8543.69339h.51971a.91153.69906 0 00.90415-.65518v-5.6399a.91153.69906 0 00-.8543-.6934h-.51971a.91153.69906 0 00-.90412.65518z"/>
<path d="m33.188 33.591a.91153.69906 0 00.8543.69339h.51969a.91153.69906 0 00.90415-.65518v-5.6399a.91153.69906 0 00-.8543-.6934h-.51969a.91153.69906 0 00-.90415.65518z"/>
<rect x="28.5" y="40.855" width="7" height="7"/>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.7 KiB

View file

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
<g style="fill:white;stroke-linecap:round;stroke-linejoin:round;stroke-width:2;stroke:#000">
<path d="m16.564 58.246s.27018-3.0341-.47957-4.5114-3.7331-1.0108-5.1198-6.5631c-1.5007-6.0087-1.1589-11.304.08641-16.021.03329-.1261.42694-13.37.64983-15.41.20442-1.8708 3.537-2.2802 4.3239-.96699.78927 1.3172 1.1392 14.198 1.1392 14.198s-.58395-17.69.65463-21.119c.93458-2.5873 4.348-1.9673 4.8895-.50415 1.1377 3.0744 1.2248 21.386 1.486 21.358 2e-6 0-.28989-15.948.47589-23.456.27165-2.6633 5.7062-3.3332 5.8418.38078.6057 16.6.71775 22.883.71775 22.883s-.18809-13.139.77038-19.004c.48999-2.9982 4.0818-4.0291 5.2626.12132.94806 3.3323.83166 25.886.83166 25.886 3.9578-.31514 6.126-4.0335 9.4217-4.9206 3.2958-.88712 7.4839-.88189 7.7241 2.5082.24024 3.3901-6.2486 2.079-8.9921 8.9748s-7.7062 10.483-9.724 11.538c-2.0178 1.0559-1.3502 4.9943-1.3502 4.9943-3.1568.52358-15.602.68533-18.61-.36635z"/>
<path d="m16.196 29.234c.68211-.37578 1.3442-.30741 1.998-.05263m4.9785-.13114c.73722-.55467 1.4554-.37523 1.9592-.0516m5.1708-.1362c.58432-.51144 1.32-.39807 2.1111-.05561m-17.211 24.02c1.2363.71309 2.742 1.3089 4.3832 1.7712m12.704.7217c2.096-.42638 3.3585-1.2068 4.7751-2.0055m-11.456-2.3503c-.29197-8.4288 3.6119-12.731 9.5389-15.044" style="fill:none;stroke-width:1.5"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.4 KiB

File diff suppressed because one or more lines are too long

View file

@ -1,16 +1,14 @@
var MD5=function(a){function b(a,b){var d,c,e,g,f;e=a&2147483648;g=b&2147483648;d=a&1073741824;c=b&1073741824;f=(a&1073741823)+(b&1073741823);return d&c?f^2147483648^e^g:d|c?f&1073741824?f^3221225472^e^g:f^1073741824^e^g:f^e^g}function e(a,d,c,e,g,f,h){a=b(a,b(b(d&c|~d&e,g),h));return b(a<<f|a>>>32-f,d)}function c(a,d,c,e,g,f,h){a=b(a,b(b(d&e|c&~e,g),h));return b(a<<f|a>>>32-f,d)}function d(a,d,c,e,g,f,h){a=b(a,b(b(d^c^e,g),h));return b(a<<f|a>>>32-f,d)}function j(a,d,c,e,g,f,h){a=b(a,b(b(c^(d|~e),
g),h));return b(a<<f|a>>>32-f,d)}function i(a){var b="",d="",c;for(c=0;3>=c;c++)d=a>>>8*c&255,d="0"+d.toString(16),b+=d.substr(d.length-2,2);return b}var f=[],m,n,k,q,h,g,l,o,f=a.replace(/\r\n/g,"\n"),a="";for(m=0;m<f.length;m++)n=f.charCodeAt(m),128>n?a+=String.fromCharCode(n):(127<n&&2048>n?a+=String.fromCharCode(n>>6|192):(a+=String.fromCharCode(n>>12|224),a+=String.fromCharCode(n>>6&63|128)),a+=String.fromCharCode(n&63|128));f=a;a=f.length;m=a+8;n=16*((m-m%64)/64+1);k=Array(n-1);for(h=q=0;h<a;)m=
(h-h%4)/4,q=8*(h%4),k[m]|=f.charCodeAt(h)<<q,h++;m=(h-h%4)/4;k[m]|=128<<8*(h%4);k[n-2]=a<<3;k[n-1]=a>>>29;f=k;h=1732584193;g=4023233417;l=2562383102;o=271733878;for(a=0;a<f.length;a+=16)m=h,n=g,k=l,q=o,h=e(h,g,l,o,f[a+0],7,3614090360),o=e(o,h,g,l,f[a+1],12,3905402710),l=e(l,o,h,g,f[a+2],17,606105819),g=e(g,l,o,h,f[a+3],22,3250441966),h=e(h,g,l,o,f[a+4],7,4118548399),o=e(o,h,g,l,f[a+5],12,1200080426),l=e(l,o,h,g,f[a+6],17,2821735955),g=e(g,l,o,h,f[a+7],22,4249261313),h=e(h,g,l,o,f[a+8],7,1770035416),
o=e(o,h,g,l,f[a+9],12,2336552879),l=e(l,o,h,g,f[a+10],17,4294925233),g=e(g,l,o,h,f[a+11],22,2304563134),h=e(h,g,l,o,f[a+12],7,1804603682),o=e(o,h,g,l,f[a+13],12,4254626195),l=e(l,o,h,g,f[a+14],17,2792965006),g=e(g,l,o,h,f[a+15],22,1236535329),h=c(h,g,l,o,f[a+1],5,4129170786),o=c(o,h,g,l,f[a+6],9,3225465664),l=c(l,o,h,g,f[a+11],14,643717713),g=c(g,l,o,h,f[a+0],20,3921069994),h=c(h,g,l,o,f[a+5],5,3593408605),o=c(o,h,g,l,f[a+10],9,38016083),l=c(l,o,h,g,f[a+15],14,3634488961),g=c(g,l,o,h,f[a+4],20,3889429448),
h=c(h,g,l,o,f[a+9],5,568446438),o=c(o,h,g,l,f[a+14],9,3275163606),l=c(l,o,h,g,f[a+3],14,4107603335),g=c(g,l,o,h,f[a+8],20,1163531501),h=c(h,g,l,o,f[a+13],5,2850285829),o=c(o,h,g,l,f[a+2],9,4243563512),l=c(l,o,h,g,f[a+7],14,1735328473),g=c(g,l,o,h,f[a+12],20,2368359562),h=d(h,g,l,o,f[a+5],4,4294588738),o=d(o,h,g,l,f[a+8],11,2272392833),l=d(l,o,h,g,f[a+11],16,1839030562),g=d(g,l,o,h,f[a+14],23,4259657740),h=d(h,g,l,o,f[a+1],4,2763975236),o=d(o,h,g,l,f[a+4],11,1272893353),l=d(l,o,h,g,f[a+7],16,4139469664),
g=d(g,l,o,h,f[a+10],23,3200236656),h=d(h,g,l,o,f[a+13],4,681279174),o=d(o,h,g,l,f[a+0],11,3936430074),l=d(l,o,h,g,f[a+3],16,3572445317),g=d(g,l,o,h,f[a+6],23,76029189),h=d(h,g,l,o,f[a+9],4,3654602809),o=d(o,h,g,l,f[a+12],11,3873151461),l=d(l,o,h,g,f[a+15],16,530742520),g=d(g,l,o,h,f[a+2],23,3299628645),h=j(h,g,l,o,f[a+0],6,4096336452),o=j(o,h,g,l,f[a+7],10,1126891415),l=j(l,o,h,g,f[a+14],15,2878612391),g=j(g,l,o,h,f[a+5],21,4237533241),h=j(h,g,l,o,f[a+12],6,1700485571),o=j(o,h,g,l,f[a+3],10,2399980690),
l=j(l,o,h,g,f[a+10],15,4293915773),g=j(g,l,o,h,f[a+1],21,2240044497),h=j(h,g,l,o,f[a+8],6,1873313359),o=j(o,h,g,l,f[a+15],10,4264355552),l=j(l,o,h,g,f[a+6],15,2734768916),g=j(g,l,o,h,f[a+13],21,1309151649),h=j(h,g,l,o,f[a+4],6,4149444226),o=j(o,h,g,l,f[a+11],10,3174756917),l=j(l,o,h,g,f[a+2],15,718787259),g=j(g,l,o,h,f[a+9],21,3951481745),h=b(h,m),g=b(g,n),l=b(l,k),o=b(o,q);return(i(h)+i(g)+i(l)+i(o)).toLowerCase()};(function(a){a.fn.stupidtable=function(){a(this).on("click","thead th",function(){a(this).stupidsort()})};a.fn.stupidsort=function(){function b(b){var d=0,c;a(b).children("td,th").each(function(){if(d==m)return c=a(this),!1;var b=a(this).attr("colspan");d+=b?Number(b):1});b="undefined"!=typeof c.data("sort-value")?c.data("sort-value"):"undefined"!=typeof c.attr("data-sort-value")?c.attr("data-sort-value"):c.text();switch(i){case "string":case "string-ins":b=String(b).toLowerCase();break;case "int":b=
parseInt(Number(b));break;case "float":b=Number(b)}return b}var e=a(this),c=e.closest("table"),d=c.children("tbody"),j=d.children("tr"),i=e.attr("data-sort-type");if(i){var f=!0;e.hasClass("sorting-asc")&&(f=!1);var m=0;e.prevAll().each(function(){var b=a(this).attr("colspan");m+=b?Number(b):1});j.sort(function(a,d){var c=f?1:-1,a=b(a),d=b(d);return a>d?1*c:a<d?-1*c:0});d.append(j);c.find("thead th").removeClass("sorting-asc").removeClass("sorting-desc");e.addClass(f?"sorting-asc":"sorting-desc")}}})(jQuery);$(function(){UI.elements={menu:$("nav > .menu"),main:$("main"),header:$("header"),connection:{status:$("#connection"),user_and_host:$("#user_and_host"),msg:$("#message")}};UI.buildMenu();UI.stored.getOpts();$("body").on("keydown",function(a){switch(a.key){case "Escape":UI.elements.context_menu&&UI.elements.context_menu.hide()}});UI.elements.main.click(function(a){UI.elements.context_menu&&!a.isDefaultPrevented()&&UI.elements.context_menu.hide()});var a=!1;UI.elements.main.on("mousedown",function(b){var c=
b.target;a=setTimeout(function(){function e(a){a.preventDefault()}function f(){window.removeEventListener("click",e,!0);document.removeEventListener("mouseup",f)}a=!1;var m=new Event("contextmenu",{bubbles:!0});m.pageX=b.pageX;m.pageY=b.pageY;c.dispatchEvent(m);window.addEventListener("click",e,!0);document.addEventListener("mouseup",function(){requestAnimationFrame(f)})},1500)});UI.elements.main.on("mouseleave",function(){a&&(clearTimeout(a),a=!1)});UI.elements.main.on("mouseup",function(){a&&(clearTimeout(a),
a=!1)});try{if("mistLogin"in sessionStorage){var b=JSON.parse(sessionStorage.mistLogin);mist.user.name=b.name;mist.user.password=b.password;mist.user.host=b.host}}catch(e){}location.hash&&(b=decodeURIComponent(location.hash).substring(1).split("@")[0].split("&"),mist.user.name=b[0],b[1]&&(mist.user.host=b[1]));mist.send(function(){$(window).trigger("hashchange")},{},{timeout:5,hide:!0});var c=0;$("body > div.filler").on("scroll",function(){var a=$(this).scrollLeft();a!=c&&UI.elements.header.css("margin-right",
-1*a+"px");c=a})});var lastpage=[];$(window).on("hashchange",function(){var a=decodeURIComponent(location.hash).substring(1).split("@");a[1]||(a[1]="");a=a[1].split("&");""==a[0]&&(a[0]="Overview");UI.showTab(a[0],a[1],lastpage);if(lastpage[0]!=a[0]||lastpage[1]!=a[1])lastpage=[a[0],a[1]]});
var MD5=function(a){function b(a,b){var c,h,d,e,g;d=a&2147483648;e=b&2147483648;c=a&1073741824;h=b&1073741824;g=(a&1073741823)+(b&1073741823);return c&h?g^2147483648^d^e:c|h?g&1073741824?g^3221225472^d^e:g^1073741824^d^e:g^d^e}function d(a,c,h,d,e,g,f){a=b(a,b(b(c&h|~c&d,e),f));return b(a<<g|a>>>32-g,c)}function c(a,c,h,d,e,g,f){a=b(a,b(b(c&d|h&~d,e),f));return b(a<<g|a>>>32-g,c)}function e(a,c,h,d,e,g,f){a=b(a,b(b(c^h^d,e),f));return b(a<<g|a>>>32-g,c)}function l(a,c,h,d,g,e,f){a=b(a,b(b(h^(c|~d),
g),f));return b(a<<e|a>>>32-e,c)}function i(a){var b="",c="",h;for(h=0;3>=h;h++)c=a>>>8*h&255,c="0"+c.toString(16),b+=c.substr(c.length-2,2);return b}var f=[],m,n,j,q,g,h,k,o,f=a.replace(/\r\n/g,"\n"),a="";for(m=0;m<f.length;m++)n=f.charCodeAt(m),128>n?a+=String.fromCharCode(n):(127<n&&2048>n?a+=String.fromCharCode(n>>6|192):(a+=String.fromCharCode(n>>12|224),a+=String.fromCharCode(n>>6&63|128)),a+=String.fromCharCode(n&63|128));f=a;a=f.length;m=a+8;n=16*((m-m%64)/64+1);j=Array(n-1);for(g=q=0;g<a;)m=
(g-g%4)/4,q=8*(g%4),j[m]|=f.charCodeAt(g)<<q,g++;m=(g-g%4)/4;j[m]|=128<<8*(g%4);j[n-2]=a<<3;j[n-1]=a>>>29;f=j;g=1732584193;h=4023233417;k=2562383102;o=271733878;for(a=0;a<f.length;a+=16)m=g,n=h,j=k,q=o,g=d(g,h,k,o,f[a+0],7,3614090360),o=d(o,g,h,k,f[a+1],12,3905402710),k=d(k,o,g,h,f[a+2],17,606105819),h=d(h,k,o,g,f[a+3],22,3250441966),g=d(g,h,k,o,f[a+4],7,4118548399),o=d(o,g,h,k,f[a+5],12,1200080426),k=d(k,o,g,h,f[a+6],17,2821735955),h=d(h,k,o,g,f[a+7],22,4249261313),g=d(g,h,k,o,f[a+8],7,1770035416),
o=d(o,g,h,k,f[a+9],12,2336552879),k=d(k,o,g,h,f[a+10],17,4294925233),h=d(h,k,o,g,f[a+11],22,2304563134),g=d(g,h,k,o,f[a+12],7,1804603682),o=d(o,g,h,k,f[a+13],12,4254626195),k=d(k,o,g,h,f[a+14],17,2792965006),h=d(h,k,o,g,f[a+15],22,1236535329),g=c(g,h,k,o,f[a+1],5,4129170786),o=c(o,g,h,k,f[a+6],9,3225465664),k=c(k,o,g,h,f[a+11],14,643717713),h=c(h,k,o,g,f[a+0],20,3921069994),g=c(g,h,k,o,f[a+5],5,3593408605),o=c(o,g,h,k,f[a+10],9,38016083),k=c(k,o,g,h,f[a+15],14,3634488961),h=c(h,k,o,g,f[a+4],20,3889429448),
g=c(g,h,k,o,f[a+9],5,568446438),o=c(o,g,h,k,f[a+14],9,3275163606),k=c(k,o,g,h,f[a+3],14,4107603335),h=c(h,k,o,g,f[a+8],20,1163531501),g=c(g,h,k,o,f[a+13],5,2850285829),o=c(o,g,h,k,f[a+2],9,4243563512),k=c(k,o,g,h,f[a+7],14,1735328473),h=c(h,k,o,g,f[a+12],20,2368359562),g=e(g,h,k,o,f[a+5],4,4294588738),o=e(o,g,h,k,f[a+8],11,2272392833),k=e(k,o,g,h,f[a+11],16,1839030562),h=e(h,k,o,g,f[a+14],23,4259657740),g=e(g,h,k,o,f[a+1],4,2763975236),o=e(o,g,h,k,f[a+4],11,1272893353),k=e(k,o,g,h,f[a+7],16,4139469664),
h=e(h,k,o,g,f[a+10],23,3200236656),g=e(g,h,k,o,f[a+13],4,681279174),o=e(o,g,h,k,f[a+0],11,3936430074),k=e(k,o,g,h,f[a+3],16,3572445317),h=e(h,k,o,g,f[a+6],23,76029189),g=e(g,h,k,o,f[a+9],4,3654602809),o=e(o,g,h,k,f[a+12],11,3873151461),k=e(k,o,g,h,f[a+15],16,530742520),h=e(h,k,o,g,f[a+2],23,3299628645),g=l(g,h,k,o,f[a+0],6,4096336452),o=l(o,g,h,k,f[a+7],10,1126891415),k=l(k,o,g,h,f[a+14],15,2878612391),h=l(h,k,o,g,f[a+5],21,4237533241),g=l(g,h,k,o,f[a+12],6,1700485571),o=l(o,g,h,k,f[a+3],10,2399980690),
k=l(k,o,g,h,f[a+10],15,4293915773),h=l(h,k,o,g,f[a+1],21,2240044497),g=l(g,h,k,o,f[a+8],6,1873313359),o=l(o,g,h,k,f[a+15],10,4264355552),k=l(k,o,g,h,f[a+6],15,2734768916),h=l(h,k,o,g,f[a+13],21,1309151649),g=l(g,h,k,o,f[a+4],6,4149444226),o=l(o,g,h,k,f[a+11],10,3174756917),k=l(k,o,g,h,f[a+2],15,718787259),h=l(h,k,o,g,f[a+9],21,3951481745),g=b(g,m),h=b(h,n),k=b(k,j),o=b(o,q);return(i(g)+i(h)+i(k)+i(o)).toLowerCase()};(function(a){a.fn.stupidtable=function(){a(this).on("click","thead th",function(){a(this).stupidsort()})};a.fn.stupidsort=function(){function b(b){var c=0,d;a(b).children("td,th").each(function(){if(c==m)return d=a(this),!1;var b=a(this).attr("colspan");c+=b?Number(b):1});b="undefined"!=typeof d.data("sort-value")?d.data("sort-value"):"undefined"!=typeof d.attr("data-sort-value")?d.attr("data-sort-value"):d.text();switch(i){case "string":case "string-ins":b=String(b).toLowerCase();break;case "int":b=
parseInt(Number(b));break;case "float":b=Number(b)}return b}var d=a(this),c=d.closest("table"),e=c.children("tbody"),l=e.children("tr"),i=d.attr("data-sort-type");if(i){var f=!0;d.hasClass("sorting-asc")&&(f=!1);var m=0;d.prevAll().each(function(){var b=a(this).attr("colspan");m+=b?Number(b):1});l.sort(function(a,c){var d=f?1:-1,a=b(a),c=b(c);return a>c?1*d:a<c?-1*d:0});e.append(l);c.find("thead th").removeClass("sorting-asc").removeClass("sorting-desc");d.addClass(f?"sorting-asc":"sorting-desc")}}})(jQuery);$(function(){UI.elements={menu:$("nav > .menu"),main:$("main"),header:$("header"),connection:{status:$("#connection"),user_and_host:$("#user_and_host"),msg:$("#message")}};UI.buildMenu();UI.stored.getOpts();try{if("mistLogin"in sessionStorage){var a=JSON.parse(sessionStorage.mistLogin);mist.user.name=a.name;mist.user.password=a.password;mist.user.host=a.host}}catch(b){}location.hash&&(a=decodeURIComponent(location.hash).substring(1).split("@")[0].split("&"),mist.user.name=a[0],a[1]&&(mist.user.host=
a[1]));mist.send(function(){$(window).trigger("hashchange")},{},{timeout:5,hide:!0});var d=0;$("body > div.filler").on("scroll",function(){var a=$(this).scrollLeft();a!=d&&UI.elements.header.css("margin-right",-1*a+"px");d=a})});var lastpage=[];$(window).on("hashchange",function(){var a=decodeURIComponent(location.hash).substring(1).split("@");a[1]||(a[1]="");a=a[1].split("&");""==a[0]&&(a[0]="Overview");UI.showTab(a[0],a[1],lastpage);if(lastpage[0]!=a[0]||lastpage[1]!=a[1])lastpage=[a[0],a[1]]});
var MistVideoObject={},otherhost={host:!1,https:!1},UI={debug:!1,elements:{},stored:{getOpts:function(){var a=localStorage.stored;a&&(a=JSON.parse(a));$.extend(!0,this.vars,a);return this.vars},saveOpt:function(a,b){this.vars[a]=b;localStorage.stored=JSON.stringify(this.vars);return this.vars},vars:{helpme:!0}},interval:{list:{},clear:function(){for(var a in this.list)clearInterval(this.list[a].id);this.list={}},set:function(a,b){this.opts&&log("[interval]","Set called on interval, but an interval is already active.");
var e={delay:b,callback:a,id:setInterval(a,b)};this.list[e.id]=e;return e.id}},websockets:{list:[],clear:function(){for(var a in this.list)this.list[a].close()},create:function(a){var b=new WebSocket(a),e=this;this.list.push(b);b.addEventListener("close",function(){for(var a=e.list.length-1;0<=a;a--)e.list[a]==b&&e.list.splice(a,1)});return b}},countrylist:{AF:"Afghanistan",AX:"&Aring;land Islands",AL:"Albania",DZ:"Algeria",AS:"American Samoa",AD:"Andorra",AO:"Angola",AI:"Anguilla",AQ:"Antarctica",
var d={delay:b,callback:a,id:setInterval(a,b)};this.list[d.id]=d;return d.id}},websockets:{list:[],clear:function(){for(var a in this.list)this.list[a].close()},create:function(a){var b=new WebSocket(a),d=this;this.list.push(b);b.addEventListener("close",function(){for(var a=d.list.length-1;0<=a;a--)d.list[a]==b&&d.list.splice(a,1)});return b}},countrylist:{AF:"Afghanistan",AX:"&Aring;land Islands",AL:"Albania",DZ:"Algeria",AS:"American Samoa",AD:"Andorra",AO:"Angola",AI:"Anguilla",AQ:"Antarctica",
AG:"Antigua and Barbuda",AR:"Argentina",AM:"Armenia",AW:"Aruba",AU:"Australia",AT:"Austria",AZ:"Azerbaijan",BS:"Bahamas",BH:"Bahrain",BD:"Bangladesh",BB:"Barbados",BY:"Belarus",BE:"Belgium",BZ:"Belize",BJ:"Benin",BM:"Bermuda",BT:"Bhutan",BO:"Bolivia, Plurinational State of",BQ:"Bonaire, Sint Eustatius and Saba",BA:"Bosnia and Herzegovina",BW:"Botswana",BV:"Bouvet Island",BR:"Brazil",IO:"British Indian Ocean Territory",BN:"Brunei Darussalam",BG:"Bulgaria",BF:"Burkina Faso",BI:"Burundi",KH:"Cambodia",
CM:"Cameroon",CA:"Canada",CV:"Cape Verde",KY:"Cayman Islands",CF:"Central African Republic",TD:"Chad",CL:"Chile",CN:"China",CX:"Christmas Island",CC:"Cocos (Keeling) Islands",CO:"Colombia",KM:"Comoros",CG:"Congo",CD:"Congo, the Democratic Republic of the",CK:"Cook Islands",CR:"Costa Rica",CI:"C&ocirc;te d'Ivoire",HR:"Croatia",CU:"Cuba",CW:"Cura&ccedil;ao",CY:"Cyprus",CZ:"Czech Republic",DK:"Denmark",DJ:"Djibouti",DM:"Dominica",DO:"Dominican Republic",EC:"Ecuador",EG:"Egypt",SV:"El Salvador",GQ:"Equatorial Guinea",
ER:"Eritrea",EE:"Estonia",ET:"Ethiopia",FK:"Falkland Islands (Malvinas)",FO:"Faroe Islands",FJ:"Fiji",FI:"Finland",FR:"France",GF:"French Guiana",PF:"French Polynesia",TF:"French Southern Territories",GA:"Gabon",GM:"Gambia",GE:"Georgia",DE:"Germany",GH:"Ghana",GI:"Gibraltar",GR:"Greece",GL:"Greenland",GD:"Grenada",GP:"Guadeloupe",GU:"Guam",GT:"Guatemala",GG:"Guernsey",GN:"Guinea",GW:"Guinea-Bissau",GY:"Guyana",HT:"Haiti",HM:"Heard Island and McDonald Islands",VA:"Holy See (Vatican City State)",HN:"Honduras",
@ -19,369 +17,346 @@ MK:"Macedonia, the former Yugoslav Republic of",MG:"Madagascar",MW:"Malawi",MY:"
NU:"Niue",NF:"Norfolk Island",MP:"Northern Mariana Islands",NO:"Norway",OM:"Oman",PK:"Pakistan",PW:"Palau",PS:"Palestine, State of",PA:"Panama",PG:"Papua New Guinea",PY:"Paraguay",PE:"Peru",PH:"Philippines",PN:"Pitcairn",PL:"Poland",PT:"Portugal",PR:"Puerto Rico",QA:"Qatar",RE:"R&eacute;union",RO:"Romania",RU:"Russian Federation",RW:"Rwanda",BL:"Saint Barth&eacute;lemy",SH:"Saint Helena, Ascension and Tristan da Cunha",KN:"Saint Kitts and Nevis",LC:"Saint Lucia",MF:"Saint Martin (French part)",PM:"Saint Pierre and Miquelon",
VC:"Saint Vincent and the Grenadines",WS:"Samoa",SM:"San Marino",ST:"Sao Tome and Principe",SA:"Saudi Arabia",SN:"Senegal",RS:"Serbia",SC:"Seychelles",SL:"Sierra Leone",SG:"Singapore",SX:"Sint Maarten (Dutch part)",SK:"Slovakia",SI:"Slovenia",SB:"Solomon Islands",SO:"Somalia",ZA:"South Africa",GS:"South Georgia and the South Sandwich Islands",SS:"South Sudan",ES:"Spain",LK:"Sri Lanka",SD:"Sudan",SR:"Suriname",SJ:"Svalbard and Jan Mayen",SZ:"Swaziland",SE:"Sweden",CH:"Switzerland",SY:"Syrian Arab Republic",
TW:"Taiwan, Province of China",TJ:"Tajikistan",TZ:"Tanzania, United Republic of",TH:"Thailand",TL:"Timor-Leste",TG:"Togo",TK:"Tokelau",TO:"Tonga",TT:"Trinidad and Tobago",TN:"Tunisia",TR:"Turkey",TM:"Turkmenistan",TC:"Turks and Caicos Islands",TV:"Tuvalu",UG:"Uganda",UA:"Ukraine",AE:"United Arab Emirates",GB:"United Kingdom",US:"United States",UM:"United States Minor Outlying Islands",UY:"Uruguay",UZ:"Uzbekistan",VU:"Vanuatu",VE:"Venezuela, Bolivarian Republic of",VN:"Viet Nam",VG:"Virgin Islands, British",
VI:"Virgin Islands, U.S.",WF:"Wallis and Futuna",EH:"Western Sahara",YE:"Yemen",ZM:"Zambia",ZW:"Zimbabwe"},tooltip:{show:function(a,b){$tooltip=this.element;$.contains(document.body,$tooltip[0])||$("body").append($tooltip);$tooltip.html(b);clearTimeout(this.hiding);delete this.hiding;var e=$(document).height()-$tooltip.outerHeight(),c=$(document).width()-$tooltip.outerWidth();$tooltip.css("left",Math.min(a.pageX+10,c-10));$tooltip.css("top",Math.min(a.pageY+25,e-10));$tooltip.show().addClass("show")},
hide:function(){$tooltip=this.element;$tooltip.removeClass("show");this.hiding=setTimeout(function(){$tooltip.hide()},500)},element:$("<div>").attr("id","tooltip")},context_menu:function(){var a=$("<section>").attr("id","context_menu");a[0].style.display="none";this.ele=a;UI.elements.context_menu=this;this.pos=function(b){var e=a.parent(),c=e.height()-a.outerHeight(),d=e.width()-a.outerWidth();a.css("left",Math.min(b.pageX-e.position().left,d));a.css("top",Math.min(b.pageY-e.position().top,c))};this.show=
function(b,e){if("string"==typeof b||b instanceof jQuery)a.html(b);else if("object"==typeof b){a.html("");Array.isArray(b)||(b=[b]);for(var c in b){var d=b[c];if(d instanceof jQuery)a.children().last().remove(),a.append(d);else for(var j in d){var i=d[j],f=$("<div>");if("string"==typeof i)f.text(i);else if(i instanceof jQuery){a.append(i);continue}else 2<=i.length&&"function"==typeof i[1]&&(f.click(i[1]),f.on("keydown",function(a){switch(a.key){case "Enter":$(this).click()}}),f.attr("tabindex","0")),
3<=i.length&&(1<i[2].length?f.append($("<div>").addClass("icon").attr("data-icon",i[2])):f.attr("data-icon",i[2]),4<=i.length&&f.attr("title",i[3])),f.append(i[0]);a.append(f)}a.append($("<hr>"))}a.children().last().remove();a.find("[tabindex]").first().focus()}a.parent()||$("body").append(a);e&&this.pos(e);a[0].style.display=""};this.hide=function(){a[0].style.display="none"};this.remove=function(){delete UI.element.context_menu;a.remove()};a.on("keydown",function(b){function e(b){var d=a.find(":focus");
d.length?"down"==b?(b=d.nextAll("[tabindex]"),b.length?b.first().focus():a.find("[tabindex]").first().focus()):(b=d.prevAll("[tabindex]"),b.length?b.first().focus():a.find("[tabindex]").last().focus()):a.find("[tabindex]").first().focus()}switch(b.key){case "ArrowDown":e("down");break;case "ArrowUp":e("up")}});this.hide()},pagecontrol:function(a,b){function e(a){var b=document.createElement("button");b.appendChild(document.createTextNode(a));b.addEventListener("click",function(){c(a)});d.elements.page_buttons[a]=
b;d.elements.page_button_cont.append(b);return b}function c(b){perpage=d.vars.page_size;b||(b=d.vars.currentpage);"next"==b&&(b=d.vars.currentpage+1);"previous"==b&&(b=d.vars.currentpage-1);var c=a.querySelectorAll(":scope > :not(.hidden)");d.vars.entries=c.length;!j&&0<d.vars.entries&&(j=getComputedStyle(c[0]).getPropertyValue("display"));c=c.length;b instanceof HTMLElement&&(b=Array.from(a.children).indexOf(b),b=Math.floor(b/perpage)+1);b=Math.max(1,b);maxpage=Math.floor((c-1)/perpage)+1;b=Math.min(b,
maxpage);for(c=1;c<=maxpage;c++)switch(c in d.elements.page_buttons||e(c),c){case 1:case b-1:case b:case b+1:case maxpage:d.elements.page_buttons[c].classList.remove("hidden");break;default:d.elements.page_buttons[c].classList.add("hidden")}for(var m=Object.keys(d.elements.page_buttons),c=maxpage;c<m.length;c++)d.elements.page_buttons[m[c]].classList.add("hidden");d.vars.currentpage in d.elements.page_buttons&&d.elements.page_buttons[d.vars.currentpage].classList.remove("active");1==b?d.elements.prev.attr("disabled",
""):d.elements.prev.removeAttr("disabled");b==maxpage?d.elements.next.attr("disabled",""):d.elements.next.removeAttr("disabled");d.vars.currentpage=b;d.vars.currentpage in d.elements.page_buttons&&d.elements.page_buttons[b].classList.add("active");c="."+d.vars.uid+" > * { display: none !important; }\n";c+="."+d.vars.uid+" > *:not(.hidden) ";c+="~ *:not(.hidden) ".repeat(Math.max(0,perpage*(b-1)));c+="{ display: "+(j?j:"revert")+" !important; }\n";c+="."+d.vars.uid+"> *:not(.hidden) ";c+="~ *:not(.hidden) ".repeat(perpage*
b);d.elements.style.textContent=c+"{ display: none !important; }\n";d.elements.summary.update();d.elements.jumpto.val(b)}var d=$("<div>").addClass("page_control");d.elements={prev:$("<button>").text("Previous").click(function(){c("previous")}),next:$("<button>").text("Next").click(function(){c("next")}),page_buttons:{},page_button_cont:$("<div>").addClass("page_numbers"),pagelength:$("<select>").append($("<option>").text(5)).append($("<option>").text(10)).append($("<option>").text(25)).append($("<option>").text(50)).append($("<option>").text(100)).change(function(){d.vars.page_size=
$(this).val();c()}),jumpto:$("<select>").addClass("jump_to").change(function(){c($(this).val())}),summary:document.createElement("span"),style:document.createElement("style")};d.vars={currentpage:1,page_size:b||25,entries:0,uid:"paginated_"+(Math.random()+"").slice(2)};d.elements.pagelength.val(d.vars.page_size);d.elements.summary.className="summary";d.elements.summary.elements={start:document.createTextNode(""),end:document.createTextNode(""),total:document.createTextNode("")};d.elements.summary.appendChild(document.createTextNode("Showing "));
d.elements.summary.appendChild(d.elements.summary.elements.start);d.elements.summary.appendChild(document.createTextNode("-"));d.elements.summary.appendChild(d.elements.summary.elements.end);d.elements.summary.appendChild(document.createTextNode(" of "));d.elements.summary.appendChild(d.elements.summary.elements.total);d.elements.summary.appendChild(document.createTextNode(" items."));d.elements.summary.update=function(){this.elements.start.nodeValue=Math.max(0,(d.vars.currentpage-1)*d.vars.page_size+
1);this.elements.end.nodeValue=Math.min(d.vars.currentpage*d.vars.page_size,d.vars.entries);this.elements.total.nodeValue=d.vars.entries;for(var a=Math.floor((d.vars.entries-1)/d.vars.page_size)+1;d.elements.jumpto.children().length<a;)d.elements.jumpto.append($("<option>").text(d.elements.jumpto.children().length+1));for(;d.elements.jumpto.children().length>a;)d.elements.jumpto.children().last().remove()};a.classList.add(d.vars.uid);var j=!1;a.show_page=c;c();d.append($("<div>").addClass("pages").append(d.elements.prev).append(d.elements.page_button_cont).append(d.elements.next)).append(d.elements.summary).append($("<label>").addClass("input_container").append($("<span>").text("Jump to page:")).append(d.elements.jumpto)).append($("<label>").addClass("input_container").append($("<span>").text("Items per page:")).append(d.elements.pagelength)).append(d.elements.style);
return d},sortableItems:function(a,b,e){var c,d=1;e&&(c=e.getAttribute("data-sortby"),d=e.getAttribute("data-sortdir")?e.getAttribute("data-sortdir"):1);a.sort=function(a,i){if(!i){i=d;a==c&&(i=i*-1)}c=a=a?a:c;d=i;if(e){e.setAttribute("data-sortby",a);e.setAttribute("data-sortdir",i);var f=e.querySelector("[data-sorting]");f&&f.removeAttribute("data-sorting");e.querySelector('[data-index="'+a+'"]').setAttribute("data-sorting","")}for(var f=(new Intl.Collator("en",{numeric:true,sensitivity:"accent"})).compare,
m=0;m<this.children.length-1;m++){var n=this.children[m],k=this.children[m+1];if(i*f(b.call(n,a),b.call(k,a))>0){this.insertBefore(k,n);m>0&&(m=m-2)}}}},humanMime:function(a){var b=!1;switch(a){case "html5/application/vnd.apple.mpegurl":b="HLS (TS)";break;case "html5/application/vnd.apple.mpegurl;version=7":b="HLS (CMAF)";break;case "html5/application/sdp":b="SDP";break;case "html5/video/webm":b="WebM";break;case "html5/video/raw":b="Raw";break;case "html5/video/mp4":b="MP4";break;case "ws/video/mp4":b=
VI:"Virgin Islands, U.S.",WF:"Wallis and Futuna",EH:"Western Sahara",YE:"Yemen",ZM:"Zambia",ZW:"Zimbabwe"},tooltip:{show:function(a,b){$tooltip=this.element;$.contains(document.body,$tooltip[0])||$("body").append($tooltip);$tooltip.html(b);clearTimeout(this.hiding);delete this.hiding;var d=$(document).height()-$tooltip.outerHeight(),c=$(document).width()-$tooltip.outerWidth();$tooltip.css("left",Math.min(a.pageX+10,c-10));$tooltip.css("top",Math.min(a.pageY+25,d-10));$tooltip.show().addClass("show")},
hide:function(){$tooltip=this.element;$tooltip.removeClass("show");this.hiding=setTimeout(function(){$tooltip.hide()},500)},element:$("<div>").attr("id","tooltip")},humanMime:function(a){var b=!1;switch(a){case "html5/application/vnd.apple.mpegurl":b="HLS (TS)";break;case "html5/application/vnd.apple.mpegurl;version=7":b="HLS (CMAF)";break;case "html5/application/sdp":b="SDP";break;case "html5/video/webm":b="WebM";break;case "html5/video/raw":b="Raw";break;case "html5/video/mp4":b="MP4";break;case "ws/video/mp4":b=
"MP4 (websocket)";break;case "ws/video/raw":b="Raw (websocket)";break;case "dtsc":b="DTSC";break;case "html5/audio/aac":b="AAC";break;case "html5/audio/flac":b="FLAC";break;case "html5/image/jpeg":b="JPG";break;case "dash/video/mp4":b="DASH";break;case "flash/11":b="HDS";break;case "flash/10":b="RTMP";break;case "flash/7":b="Progressive";break;case "html5/audio/mp3":b="MP3";break;case "html5/audio/wav":b="WAV";break;case "html5/video/mp2t":case "html5/video/mpeg":b="TS";break;case "html5/application/vnd.ms-sstr+xml":case "html5/application/vnd.ms-ss":b=
"Smooth Streaming";break;case "html5/text/vtt":b="VTT Subtitles";break;case "html5/text/plain":b="SRT Subtitles";break;case "html5/text/javascript":b="JSON Subtitles";break;case "rtsp":b="RTSP";break;case "srt":b="SRT";break;case "webrtc":b="WebRTC (websocket)";break;case "whep":b="WebRTC (WHEP)"}return b},popup:{element:null,show:function(a){this.element=$("<div>").attr("id","popup").append($("<button>").text("Close").addClass("close").click(function(){UI.popup.element.fadeOut("fast",function(){UI.popup.element.remove();
UI.popup.element=null})})).append(a);$("body").append(this.element)}},menu:[{Overview:{},General:{hiddenmenu:{"Edit variable":{},"Edit external writer":{}}},Protocols:{},Streams:{keepParam:!0,hiddenmenu:{Edit:{},Status:{},Preview:{},Embed:{}}},Push:{},Triggers:{},Logs:{},Statistics:{},"Server Stats":{}},{Disconnect:{classes:["red"]}},{Documentation:{link:"https://docs.mistserver.org/"},Changelog:{link:"https://releases.mistserver.org/changelog"},"Email for Help":{}}],buildMenu:function(){function a(a,
b){var c=$("<a>").addClass("button");c.html($("<span>").addClass("plain").text(a)).append($("<span>").addClass("highlighted").text(a));for(var d in b.classes)c.addClass(b.classes[d]);"link"in b?c.attr("href",b.link).attr("target","_blank"):"submenu"in b||c.click(function(b){if(!$(this).closest(".menu").hasClass("hide")){var c,d=$(this).closest(".hiddenmenu[data-param]");d.length&&(c=d.attr("data-param"));UI.navto(a,c);b.stopPropagation()}});return c}var b=UI.elements.menu,e;for(e in UI.menu){0<e&&
b.append($("<br>"));for(var c in UI.menu[e]){var d=UI.menu[e][c],j=a(c,d);b.append(j);if("submenu"in d){var i=$("<span>").addClass("submenu");j.addClass("arrowdown").append(i);for(var f in d.submenu)i.append(a(f,d.submenu[f]))}else if("hiddenmenu"in d)for(f in i=$("<span>").addClass("hiddenmenu"),d.keepParam&&i.attr("data-param",""),j.append(i),d.hiddenmenu)i.append(a(f,d.hiddenmenu[f]))}}e=$("<div>").attr("id","ih_button").text("?").click(function(){$("body").toggleClass("helpme");UI.stored.saveOpt("helpme",
$("body").hasClass("helpme"))}).attr("title","Click to toggle the display of integrated help");UI.stored.getOpts().helpme&&$("body").addClass("helpme");b.after(e).after($("<div>").addClass("separator"))},findInput:function(a){return this.findInOutput("inputs",a)},findOutput:function(a){return this.findInOutput("connectors",a)},findInOutput:function(a,b){if("capabilities"in mist.data){var e=!1,c=mist.data.capabilities[a];b in c&&(e=c[b]);b+".exe"in c&&(e=c[b+".exe"]);return e}throw"Request capabilities first";
},findFolderSubstreams:function(a,b){mist.send(function(e){var c=a.name,d=0,j={},i;for(i in e.browse.files){var f;a:{f=e.browse.files[i];var m=void 0;for(m in mist.data.capabilities.inputs)if(!(0<=m.indexOf("Buffer")||0<=m.indexOf("Buffer.exe")||0<=m.indexOf("Folder")||0<=m.indexOf("Folder.exe"))&&mist.inputMatch(mist.data.capabilities.inputs[m].source_match,"/"+f)){f=!0;break a}f=!1}if(f){f=c+"+"+e.browse.files[i];var m=j,n=f,k=f,q=$.extend({},a);delete q.meta;delete q.error;q.online=2;q.name=k;
q.ischild=!0;m[n]=q;j[f].source=a.source+e.browse.files[i];d++}}a.filesfound="files"in e.browse&&e.browse.files.length?!0:!1;b(j)},{browse:a.source})},updateLiveStreamHint:function(a,b,e){if(a){var c=parseURL(mist.user.host),d=b.match(/@.*/);d&&(d=d[0].substring(1));var j=b.replace(/(?:.+?):\/\//,""),j=j.split("/"),j=j[0],j=j.split(":"),j=j[0],i=b.match(/:\d+/);i&&(i=i[0]);var f={},m="RTMP RTSP RTMP.exe RTSP.exe TSSRT TSSRT.exe".split(" "),n;for(n in m)m[n]in mist.data.capabilities.connectors&&(f[m[n]]=
mist.data.capabilities.connectors[m[n]].optional.port["default"]);var m={RTMP:1935,"RTMP.exe":1935,RTSP:554,"RTSP.exe":554,TSSRT:-1,"TSSRT.exe":-1,TS:-1,"TS.exe":-1},k;for(k in f){for(n in mist.data.config.protocols){var q=mist.data.config.protocols[n];if(q.connector==k){"port"in q&&(f[k]=q.port);break}}f[k]=f[k]==m[k]?"":":"+f[k]}f.TS="";f["TS.exe"]="";e.find(".field").closest("label").hide();for(n in f){var h;k=i?i:f[n];switch(n){case "RTMP":case "RTMP.exe":h="rtmp://"+c.host+k+"/"+(d?d:"live")+
"/";k=e.find(".field.RTMPurl").setval(h).closest("label");k.length&&(k[0].style.display="");k=e.find(".field.RTMPkey").setval(""==a?"STREAMNAME":a).closest("label");k.length&&(k[0].style.display="");h+=""==a?"STREAMNAME":a;break;case "TSSRT":case "TSSRT.exe":"srt://"==b.slice(0,6)?i?(h=parseURL(b.replace()),""==h.host&&(h=parseURL(b.replace(/^srt:\/\//,"http://localhost")),h.host=h.host.replace(/^localhost/,"")),h=""!=h.host&&(!h.search||!h.searchParams||"listener"!=h.searchParams.get("mode"))?"Caller mode: you should push to the other side.":
h.search&&h.searchParams&&"caller"==h.searchParams.get("mode")?"Caller mode: you should probably add an address.":"srt://"+c.host+i):h="You must specify a port.":h="srt://"+c.host+k+"?streamid="+(""==a?"STREAMNAME":a);break;case "RTSP":case "RTSP.exe":h="rtsp://"+c.host+k+"/"+(""==a?"STREAMNAME":a)+(d?"?pass="+d:"");break;case "TS":case "TS.exe":h="udp://"+(""==j?c.host:j)+k+"/"}k=e.find(".field."+n.replace(".exe",""));k.length&&(k.setval(h).closest("label")[0].style.display="")}}},buildUI:function(a){var b=
$("<div>").addClass("input_container"),e;for(e in a){var c=a[e];if(c instanceof jQuery)b.append(c);else if("help"==c.type){var d=$("<span>").addClass("text_container").append($("<span>").addClass("description").append(c.help));b.append(d);if("classes"in c)for(var j in c.classes)d.addClass(c.classes[j])}else if("text"==c.type)b.append($("<span>").addClass("text_container").append($("<span>").addClass("text").append(c.text)));else if("custom"==c.type)b.append(c.custom);else if("buttons"==c.type)for(j in d=
$("<span>").addClass("button_container").on("keydown",function(a){a.stopPropagation()}),"css"in c&&d.css(c.css),b.append(d),c.buttons){var i=c.buttons[j],f=$("<button>").text(i.label).data("opts",i);"css"in i&&f.css(i.css);if("classes"in i)for(var m in i.classes)f.addClass(i.classes[m]);d.append(f);switch(i.type){case "cancel":f.addClass("cancel").click(i["function"]);break;case "save":f.addClass("save").click(function(){var a=$(this).data("opts").preSave;a&&a.call(this);var b=$(this).closest(".input_container"),
c=!1;b.find('.hasValidate:visible, input[type="hidden"].hasValidate').each(function(){if(c=$(this).data("validate")(this,!0))return!1});(a=$(this).data("opts").failedValidate)&&a.call(this);c||(b.find('.isSetting:visible, input[type="hidden"].isSetting').each(function(){var a=$(this).getval(),b=$(this).data("pointer");if(""===a)if("default"in $(this).data("opts"))a=$(this).data("opts")["default"];else return b.main[b.index]=null,!0;b.main[b.index]=a;(a=$(this).data("opts").postSave)&&a.call(this)}),
(a=$(this).data("opts")["function"])&&a(this))});break;default:f.click(i["function"])}}else{i=$("<label>").addClass("UIelement");b.append(i);"css"in c&&i.css(c.css);i.append($("<span>").addClass("label").html("label"in c?c.label+":":""));if("classes"in c)for(m in c.classes)i.addClass(c.classes[m]);f=$("<span>").addClass("field_container");i.append(f);switch(c.type){case "password":d=$("<input>").attr("type","password");break;case "int":d=$("<input>").attr("type","number");"min"in c&&d.attr("min",
c.min);"max"in c&&d.attr("max",c.max);"step"in c&&d.attr("step",c.step);"validate"in c?c.validate.push("int"):c.validate=["int"];break;case "span":d=$("<span>");break;case "debug":c.select=[["","Default"],[0,"0 - All debugging messages disabled"],[1,"1 - Messages about failed operations"],[2,"2 - Previous level, and error messages"],[3,"3 - Previous level, and warning messages"],[4,"4 - Previous level, and status messages for development"],[5,"5 - Previous level, and more status messages for development"],
[6,"6 - Previous level, and verbose debugging messages"],[7,"7 - Previous level, and very verbose debugging messages"],[8,"8 - Report everything in extreme detail"],[9,"9 - Report everything in insane detail"],[10,"10 - All messages enabled"]];case "select":d=$("<select>");for(j in c.select){var n=$("<option>");"string"==typeof c.select[j]?n.text(c.select[j]):n.val(c.select[j][0]).text(c.select[j][1]);d.append(n)}break;case "textarea":d=$("<textarea>").on("keydown",function(a){a.stopPropagation()});
break;case "checkbox":d=$("<input>").attr("type","checkbox");break;case "hidden":d=$("<input>").attr("type","hidden");i.hide();break;case "email":d=$("<input>").attr("type","email").attr("autocomplete","on").attr("required","");break;case "browse":d=$("<input>").attr("type","text");"filetypes"in c&&d.data("filetypes",c.filetypes);break;case "geolimited":case "hostlimited":d=$("<input>").attr("type","hidden");break;case "radioselect":d=$("<div>").addClass("radioselect");for(e in c.radioselect){var k=
$("<input>").attr("type","radio").val(c.radioselect[e][0]).attr("name",c.label);c.readonly&&k.prop("disabled",!0);n=$("<label>").append(k).append($("<span>").html(c.radioselect[e][1]));d.append(n);if(2<c.radioselect[e].length)for(j in k=$("<select>").change(function(){$(this).parent().find("input[type=radio]:enabled").prop("checked","true")}),n.append(k),c.readonly&&k.prop("disabled",!0),c.radioselect[e][2])n=$("<option>"),k.append(n),c.radioselect[e][2][j]instanceof Array?n.val(c.radioselect[e][2][j][0]).html(c.radioselect[e][2][j][1]):
n.html(c.radioselect[e][2][j])}break;case "checklist":d=$("<div>").addClass("checkcontainer");$controls=$("<div>").addClass("controls");$checklist=$("<div>").addClass("checklist");d.append($checklist);for(e in c.checklist)"string"==typeof c.checklist[e]&&(c.checklist[e]=[c.checklist[e],c.checklist[e]]),$checklist.append($("<label>").text(c.checklist[e][1]).prepend($("<input>").attr("type","checkbox").attr("name",c.checklist[e][0])));break;case "DOMfield":d=c.DOMfield;break;case "unix":d=$("<input>").attr("type",
"datetime-local").attr("step",1);c.unit=$("<button>").text("Now").click(function(){$(this).closest(".field_container").find(".field").setval((new Date).getTime()/1E3)});break;case "selectinput":d=$("<div>").addClass("selectinput");k=$("<select>");d.append(k);k.data("input",!1);for(e in c.selectinput)n=$("<option>"),k.append(n),"string"==typeof c.selectinput[e]?n.text(c.selectinput[e]):(n.text(c.selectinput[e][1]),"string"==typeof c.selectinput[e][0]?n.val(c.selectinput[e][0]):(n.val("CUSTOM"),k.data("input")||
k.data("input",UI.buildUI([c.selectinput[e][0]]).children())));k.data("input")&&d.append(k.data("input"));k.change(function(){"CUSTOM"==$(this).val()?$(this).data("input").css("display","flex"):$(this).data("input").hide()});k.trigger("change");break;case "inputlist":d=$("<div>").addClass("inputlist");d.data("newitem",function(){var a;if("input"in c)a=UI.buildUI([c.input]).find(".field_container");else{var b=Object.assign({},c);delete b.validate;delete b.pointer;b.type="str";a=UI.buildUI([b]).find(".field_container")}a.removeClass("isSetting");
a.addClass("listitem");var d=function(b){$(this).is(":last-child")?""!=$(this).find(".field").getval()?(b=a.clone().keyup(d),b.find(".field").setval(""),$(this).after(b)):8==b.which&&$(this).prev().find(".field").focus():""==$(this).find(".field").getval()&&(b=$(this).prev(),b.length||(b=$(this).next()),b.find(".field").focus(),$(this).remove())};a.keyup(d);return a});d.append(d.data("newitem"));break;case "sublist":d=$("<div>").addClass("sublist");k=$("<div>").addClass("curvals");k.append($("<span>").text("None."));
var q=$("<div>").addClass("itemsettings"),h=$("<button>").text("New "+c.itemLabel),g=c.sublist,l=c,o=d,u=i;d.data("build",function(a,b){for(var c in l.saveas)c in a||delete l.saveas[c];l.saveas=Object.assign(l.saveas,a);c="New";"undefined"!=typeof b&&(c="Edit");c=UI.buildUI([$("<h4>").text(c+" "+l.itemLabel)].concat(g).concat([{label:"Save first",type:"str",classes:["onlyshowhelp"],validate:[function(){return{msg:"Did you want to save this "+l.itemLabel+"?",classes:["red"]}}]},{type:"buttons",buttons:[{label:"Cancel",
type:"cancel","function":function(){q.html("");h.show();u.show()}},{label:"Save "+l.itemLabel,type:"save",preSave:function(){$(this).closest(".input_container").find(".onlyshowhelp").closest("label").hide()},failedValidate:function(){$(this).closest(".input_container").find(".onlyshowhelp").closest("label").show()},"function":function(){var a=o.getval(),c=Object.assign({},l.saveas),d;for(d in c)null===c[d]&&delete c[d];"undefined"==typeof b?a.push(c):a[b]=c;o.setval(a);q.html("");h.show();u.show()}}]}]));
q.html(c);h.hide();u.hide()});var p=d;h.click(function(){p.data("build")({})});g.unshift({type:"str",label:"Human readable name",placeholder:"none",help:"A convenient name to describe this "+c.itemLabel+". It won't be used by MistServer.",pointer:{main:c.saveas,index:"x-LSP-name"}});d.data("savelist",[]);d.append(k).append(h);b.append(q);break;case "json":d=$("<textarea>").on("keydown",function(a){a.stopPropagation()}).on("keyup change",function(){this.style.height="";this.style.height=(this.scrollHeight?
this.scrollHeight+20:14*this.value.split("\n").length+20)+"px"}).css("min-height","3em");k=function(a,b){if(""!=$(b).val()&&null===a)return{msg:"Invalid json",classes:["red"]}};"validate"in c?c.validate.push(k):c.validate=[k];break;case "bitmask":d=$("<div>").addClass("bitmask");for(e in c.bitmask)d.append($("<label>").append($("<input>").attr("type","checkbox").attr("name","bitmask_"+("pointer"in c?c.pointer.index:"")).attr("value",c.bitmask[e][0]).addClass("field")).append($("<span>").text(c.bitmask[e][1])));
i.attr("for","none");break;default:d=$("<input>").attr("type","text"),"maxlength"in c&&d.attr("maxlength",c.maxlength),"minlength"in c&&d.attr("minlength",c.minlength)}d.addClass("field").data("opts",c);"pointer"in c&&d.attr("name",c.pointer.index);f.append(d);if("classes"in c)for(j in c.classes)d.addClass(c.classes[j]);"placeholder"in c&&d.attr("placeholder",c.placeholder);"default"in c&&d.attr("placeholder",c["default"]);"unit"in c&&f.append($("<span>").addClass("unit").html(c.unit));"prefix"in
c&&f.prepend($("<span>").addClass("unit").html(c.prefix));"readonly"in c&&(d.attr("readonly","readonly"),d.click(function(){this.selectionStart==this.selectionEnd&&$(this).select()}));"qrcode"in c&&f.append($("<span>").addClass("unit").html($("<button>").text("QR").on("keydown",function(a){a.stopPropagation()}).click(function(){var a=String($(this).closest(".field_container").find(".field").getval()),b=$("<div>").addClass("qrcode");UI.popup.show($("<span>").addClass("qr_container").append($("<p>").text(a)).append(b));
b.qrcode({text:a,size:Math.min(b.width(),b.height())})})));"clipboard"in c&&document.queryCommandSupported("copy")&&f.append($("<span>").addClass("unit").html($("<button>").text("Copy").on("keydown",function(a){a.stopPropagation()}).click(function(){var a=String($(this).closest(".field_container").find(".field").getval()),b=document.createElement("textarea");b.value=a;document.body.appendChild(b);b.select();var c=false;try{c=document.execCommand("copy")}catch(d){}if(c){$(this).text("Copied to clipboard!");
document.body.removeChild(b);var e=$(this);setTimeout(function(){e.text("Copy")},5E3)}else{document.body.removeChild(b);alert("Failed to copy:\n"+a)}})));"rows"in c&&d.attr("rows",c.rows);if("dependent"in c)for(e in c.dependent)i.attr("data-dependent-"+e,c.dependent[e]);switch(c.type){case "browse":k=$("<div>").addClass("grouper").append(i);b.append(k);k=$("<button>").text("Browse").on("keydown",function(a){a.stopPropagation()});f.append(k);k.click(function(){function a(b){h.text("Loading..");mist.send(function(a){f.text(a.browse.path[0]);
mist.data.LTS&&d.setval(a.browse.path[0]+"/");h.html(m.clone(true).text("..").attr("title","Folder up"));if(a.browse.subdirectories){a.browse.subdirectories.sort();for(var b in a.browse.subdirectories){var g=a.browse.subdirectories[b];h.append(m.clone(true).attr("title",f.text()+k+g).text(g))}}if(a.browse.files){a.browse.files.sort();for(b in a.browse.files){var g=a.browse.files[b],q=f.text()+k+g,g=$("<a>").text(g).addClass("file").attr("title",q);h.append(g);if(i){var l=true,j;for(j in i)if(typeof i[j]!=
"undefined"&&mist.inputMatch(i[j],q)){l=false;break}l&&g.hide()}g.click(function(){var a=$(this).attr("title");d.setval(a).removeAttr("readonly").css("opacity",1);e.show();c.remove()})}}},{browse:b})}var b=$(this).closest(".grouper"),c=$("<div>").addClass("browse_container"),d=b.find(".field").attr("readonly","readonly").css("opacity",0.5),e=$(this),g=$("<button>").text("Stop browsing").click(function(){e.show();c.remove();d.removeAttr("readonly").css("opacity",1)}),f=$("<span>").addClass("field"),
h=$("<div>").addClass("browse_contents"),m=$("<a>").addClass("folder"),i=d.data("filetypes");b.append(c);c.append($("<label>").addClass("UIelement").append($("<span>").addClass("label").text("Current folder:")).append($("<span>").addClass("field_container").append(f).append(g))).append(h);var k="/";mist.data.config.version.indexOf("indows")>-1&&(k="\\");m.click(function(){var b=f.text()+k+$(this).text();a(b)});b=d.getval();g=b.split("://");g.length>1&&(b=g[0]=="file"?g[1]:"");b=b.split(k);b.pop();
b=b.join(k);e.hide();a(b)});break;case "geolimited":case "hostlimited":k={field:d};k.blackwhite=$("<select>").append($("<option>").val("-").text("Blacklist")).append($("<option>").val("+").text("Whitelist"));k.values=$("<span>").addClass("limit_value_list");switch(c.type){case "geolimited":k.prototype=$("<select>").append($("<option>").val("").text("[Select a country]"));for(e in UI.countrylist)k.prototype.append($("<option>").val(e).html(UI.countrylist[e]));break;case "hostlimited":k.prototype=$("<input>").attr("type",
"text").attr("placeholder","type a host")}k.prototype.on("change keyup",function(){$(this).closest(".field_container").data("subUI").blackwhite.trigger("change")});k.blackwhite.change(function(){var a=$(this).closest(".field_container").data("subUI"),b=[],c=false;a.values.children().each(function(){c=$(this).val();c!=""?b.push(c):$(this).remove()});a.values.append(a.prototype.clone(true));b.length>0?a.field.val($(this).val()+b.join(" ")):a.field.val("");a.field.trigger("change")});k.values.append(k.prototype.clone(!0));
f.data("subUI",k).addClass("limit_list").append(k.blackwhite).append(k.values)}"pointer"in c&&(d.data("pointer",c.pointer).addClass("isSetting"),c.pointer.main&&(k=c.pointer.main[c.pointer.index],"undefined"!=k&&d.setval(k)));(""==d.getval()||null==d.getval()||!("pointer"in c))&&"value"in c&&d.setval(c.value);if("datalist"in c)for(e in k="datalist_"+e+MD5(d[0].outerHTML),d.attr("list",k),k=$("<datalist>").attr("id",k),f.append(k),c.datalist)k.append($("<option>").val(c.datalist[e]));f=$("<span>").addClass("help_container");
i.append(f);"help"in c&&(f.append($("<span>").addClass("ih_balloon").html(c.help)),d.on("focusin mouseover",function(){$(this).closest("label").addClass("active")}).on("focusout mouseout",function(){$(this).closest("label").removeClass("active")}));if("validate"in c){i=[];for(j in c.validate){k=c.validate[j];if("function"!=typeof k)switch(k){case "required":k=function(a){return a==""||a==null?{msg:"This is a required field.",classes:["red"]}:false};break;case "int":k=function(a,b){var c=$(b).data("opts");
if(!$(b)[0].validity.valid){var d=[];"min"in c&&d.push(" greater than or equal to "+c.min);"max"in c&&d.push(" smaller than or equal to "+c.max);return{msg:"Please enter an integer"+d.join(" and")+".",classes:["red"]}}};break;case "streamname":k=function(a,b){if(a!=""){if(a.toLowerCase()!=a)return{msg:"Uppercase letters are not allowed.",classes:["red"]};if(a.replace(/[^\da-z_\-\.]/g,"")!=a)return{msg:"Special characters (except for underscores (_), periods (.) and dashes (-)) are not allowed.",classes:["red"]};
if("streams"in mist.data&&a in mist.data.streams&&$(b).data("pointer").main.name!=a)return{msg:"This streamname already exists.<br>If you want to edit an existing stream, please click edit on the the streams tab.",classes:["red"]}}};break;case "streamname_with_wildcard":k=function(a){if(a!=""){streampart=a.split("+");var b=streampart.slice(1).join("+");streampart=streampart[0];if(streampart.toLowerCase()!=streampart)return{msg:"Uppercase letters are not allowed in a stream name.",classes:["red"]};
if(streampart.replace(/[^\da-z_]/g,"")!=streampart)return{msg:"Special characters (except for underscores) are not allowed in a stream name.",classes:["red"]};if(streampart!=a&&b.replace(/[\00|\0|\/]/g,"")!=b)return{msg:"Slashes or null bytes are not allowed in wildcards.",classes:["red"]}}};break;case "streamname_with_wildcard_and_variables":k=function(a){if(a!=""){streampart=a.split("+");var b=streampart.slice(1).join("+");streampart=streampart[0];if(streampart.toLowerCase()!=streampart)return{msg:"Uppercase letters are not allowed in a stream name.",
classes:["red"]};if(streampart.replace(/[^\da-z_$]/g,"")!=streampart)return{msg:"Special characters (except for underscores) are not allowed in a stream name.",classes:["red"]};if(streampart!=a&&b.replace(/[\00|\0|\/]/g,"")!=b)return{msg:"Slashes or null bytes are not allowed in wildcards.",classes:["red"]}}};break;case "track_selector_parameter":k=function(){};break;case "track_selector":k=function(){};break;default:k=function(){}}i.push(k)}d.data("validate_functions",i).data("help_container",f).data("validate",
function(a,b){if($(a).is(":visible")||$(a).is('input[type="hidden"]')){var c=$(a).getval(),d=$(a).data("validate_functions"),e=$(a).data("help_container");e.find(".err_balloon").remove();for(var g in d){var f=d[g](c,a);if(f){$err=$("<span>").addClass("err_balloon").html(f.msg);for(var h in f.classes)$err.addClass(f.classes[h]);e.prepend($err);b&&$(a).focus();return typeof f=="object"&&"break"in f?f["break"]:true}}return false}}).addClass("hasValidate").on("change keyup",function(){$(this).data("validate")($(this))});
""!=d.getval()&&d.trigger("change")}"function"in c&&(d.on("change keyup",c["function"]),d.trigger("change"))}}b.on("keydown",function(a){var b=!1;switch(a.which){case 13:b=$(this).find("button.save").first();break;case 27:b=$(this).find("button.cancel").first()}b&&b.length&&(b.trigger("click"),a.stopPropagation())});return b},buildVheaderTable:function(a){var b=$("<table>"),e=$("<tr>").addClass("header").append($("<td>").addClass("vheader").attr("rowspan",a.labels.length+1).append($("<span>").text(a.vheader))),
c=[];e.append($("<td>"));for(var d in a.labels)c.push($("<tr>").append($("<td>").html(""==a.labels[d]?"&nbsp;":a.labels[d]+":")));for(var j in a.content)for(d in e.append($("<td>").html(a.content[j].header)),a.content[j].body)c[d].append($("<td>").html(a.content[j].body[d]));b.append($("<tbody>").append(e).append(c));return b},plot:{addGraph:function(a,b){var e={id:a.id,xaxis:a.xaxis,datasets:[],elements:{cont:$("<div>").addClass("graph"),plot:$("<div>").addClass("plot"),legend:$("<div>").addClass("legend").attr("draggable",
"true")}};UI.draggable(e.elements.legend);e.elements.cont.append(e.elements.plot).append(e.elements.legend);b.append(e.elements.cont);return e},go:function(a){if(!(1>Object.keys(a).length)){var b={totals:[],clients:[]},e;for(e in a)for(var c in a[e].datasets){var d=a[e].datasets[c];switch(d.datatype){case "clients":case "upbps":case "downbps":case "perc_lost":case "perc_retrans":switch(d.origin[0]){case "total":b.totals.push({fields:[d.datatype],end:-15});break;case "stream":b.totals.push({fields:[d.datatype],
streams:[d.origin[1]],end:-15});break;case "protocol":b.totals.push({fields:[d.datatype],protocols:[d.origin[1]],end:-15})}break;case "cpuload":case "memload":b.capabilities={}}}0==b.totals.length&&delete b.totals;0==b.clients.length&&delete b.clients;mist.send(function(){for(var b in a){var c=a[b];if(1>c.datasets.length){c.elements.plot.html("");c.elements.legend.html("");break}switch(c.xaxis){case "time":var d=[];c.yaxes={};var e=[],n;for(n in c.datasets){var k=c.datasets[n];k.display&&(k.getdata(),
k.yaxistype in c.yaxes||(d.push(UI.plot.yaxes[k.yaxistype]),c.yaxes[k.yaxistype]=d.length),k.yaxis=c.yaxes[k.yaxistype],e.push(k))}d[0]&&(d[0].color=0);c.plot=$.plot(c.elements.plot,e,{legend:{show:!1},xaxis:UI.plot.xaxes[c.xaxis],yaxes:d,grid:{hoverable:!0,borderWidth:{top:0,right:0,bottom:1,left:1},color:"black",backgroundColor:{colors:["rgba(0,0,0,0)","rgba(0,0,0,0.025)"]}},crosshair:{mode:"x"}});d=$("<table>").addClass("legend-list").addClass("nolay").html($("<tr>").html($("<td>").html($("<h3>").text(c.id))).append($("<td>").css("padding-right",
"2em").css("text-align","right").html($("<span>").addClass("value")).append($("<button>").data("opts",c).text("X").addClass("close").click(function(){var b=$(this).data("opts");if(confirm("Are you sure you want to remove "+b.id+"?")){b.elements.cont.remove();var c=$(".graph_ids option:contains("+b.id+")"),d=c.parent();c.remove();UI.plot.del(b.id);delete a[b.id];d.trigger("change");UI.plot.go(a)}}))));c.elements.legend.html(d);var q=function(a){var b=c.elements.legend.find(".value"),d=1;if(typeof a==
"undefined")b.eq(0).html("Latest:");else{var e=c.plot.getXAxes()[0],a=Math.min(e.max,a),a=Math.max(e.min,a);b.eq(0).html(UI.format.time(a/1E3))}for(var h in c.datasets){var f="&nbsp;";if(c.datasets[h].display){var e=UI.plot.yaxes[c.datasets[h].yaxistype].tickFormatter,m=c.datasets[h].data;if(a)for(var k in m){if(m[k][0]==a){f=e(m[k][1]);break}if(m[k][0]>a){if(k!=0){f=m[k];m=m[k-1];f=e(f[1]+(a-f[0])*(m[1]-f[1])/(m[0]-f[0]))}break}}else f=e(c.datasets[h].data[c.datasets[h].data.length-1][1])}b.eq(d).html(f);
d++}};c.plot.getOptions();for(n in c.datasets)e=$("<input>").attr("type","checkbox").data("index",n).data("graph",c).click(function(){var a=$(this).data("graph");$(this).is(":checked")?a.datasets[$(this).data("index")].display=true:a.datasets[$(this).data("index")].display=false;var b={};b[a.id]=a;UI.plot.go(b)}),c.datasets[n].display&&e.attr("checked","checked"),d.append($("<tr>").html($("<td>").html($("<label>").html(e).append($("<div>").addClass("series-color").css("background-color",c.datasets[n].color)).append(c.datasets[n].label))).append($("<td>").css("padding-right",
"2em").css("text-align","right").html($("<span>").addClass("value")).append($("<button>").text("X").addClass("close").data("index",n).data("graph",c).click(function(){var b=$(this).data("index"),c=$(this).data("graph");if(confirm("Are you sure you want to remove "+c.datasets[b].label+" from "+c.id+"?")){c.datasets.splice(b,1);if(c.datasets.length==0){c.elements.cont.remove();var b=$(".graph_ids option:contains("+c.id+")"),d=b.parent();b.remove();d.trigger("change");UI.plot.del(c.id);delete a[c.id];
UI.plot.go(a)}else{UI.plot.save(c);b={};b[c.id]=c;UI.plot.go(b)}}}))));q();var h=!1;c.elements.plot.on("plothover",function(a,b,c){if(b.x!=h){q(b.x);h=b.x}if(c){a=$("<span>").append($("<h3>").text(c.series.label).prepend($("<div>").addClass("series-color").css("background-color",c.series.color))).append($("<table>").addClass("nolay").html($("<tr>").html($("<td>").text("Time:")).append($("<td>").html(UI.format.dateTime(c.datapoint[0]/1E3,"long")))).append($("<tr>").html($("<td>").text("Value:")).append($("<td>").html(c.series.yaxis.tickFormatter(c.datapoint[1],
c.series.yaxis)))));UI.tooltip.show(b,a.children())}else UI.tooltip.hide()}).on("mouseout",function(){q()})}}},b)}},save:function(a){var b={id:a.id,xaxis:a.xaxis,datasets:[]},e;for(e in a.datasets)b.datasets.push({origin:a.datasets[e].origin,datatype:a.datasets[e].datatype});a=mist.stored.get().graphs||{};a[b.id]=b;mist.stored.set("graphs",a)},del:function(a){var b=mist.stored.get().graphs||{};delete b[a];mist.stored.set("graphs",b)},datatype:{getOptions:function(a){var b=$.extend(!0,{},UI.plot.datatype.templates.general),
e=$.extend(!0,{},UI.plot.datatype.templates[a.datatype]),a=$.extend(!0,e,a),a=$.extend(!0,b,a);switch(a.origin[0]){case "total":switch(a.datatype){case "cpuload":case "memload":break;default:a.label+=" (total)"}break;case "stream":case "protocol":a.label+=" ("+a.origin[1]+")"}var b=[],c;for(c in a.basecolor)e=a.basecolor[c],e+=50*(0.5-Math.random()),e=Math.round(e),e=Math.min(255,Math.max(0,e)),b.push(e);a.color="rgb("+b.join(",")+")";return a},templates:{general:{display:!0,datatype:"general",label:"",
yaxistype:"amount",data:[],lines:{show:!0},points:{show:!1},getdata:function(){var a=mist.data.totals["stream"==this.origin[0]?this.origin[1]:"all_streams"]["protocol"==this.origin[0]?this.origin[1]:"all_protocols"][this.datatype];return this.data=a}},cpuload:{label:"CPU use",yaxistype:"percentage",basecolor:[237,194,64],cores:1,getdata:function(){var a=!1,b;for(b in this.data)this.data[b][0]<1E3*(mist.data.config.time-600)&&(a=b);!1!==a&&this.data.splice(0,Number(a)+1);this.data.push([1E3*mist.data.config.time,
mist.data.capabilities.cpu_use/10]);return this.data}},memload:{label:"Memory load",yaxistype:"percentage",basecolor:[175,216,248],getdata:function(){var a=!1,b;for(b in this.data)this.data[b][0]<1E3*(mist.data.config.time-600)&&(a=b);!1!==a&&this.data.splice(0,Number(a)+1);this.data.push([1E3*mist.data.config.time,mist.data.capabilities.load.memory]);return this.data}},clients:{label:"Connections",basecolor:[203,75,75]},upbps:{label:"Bandwidth up",yaxistype:"bytespersec",basecolor:[77,167,77]},downbps:{label:"Bandwidth down",
yaxistype:"bytespersec",basecolor:[148,64,237]},perc_lost:{label:"Lost packages",yaxistype:"percentage",basecolor:[255,33,234]},perc_retrans:{label:"Re-transmitted packages",yaxistype:"percentage",basecolor:[0,0,255]}}},yaxes:{percentage:{name:"percentage",color:"black",tickColor:0,tickDecimals:0,tickFormatter:function(a){return UI.format.addUnit(UI.format.number(a),"%")},tickLength:0,min:0,max:100},amount:{name:"amount",color:"black",tickColor:0,tickDecimals:0,tickFormatter:function(a){return UI.format.number(a)},
tickLength:0,min:0},bytespersec:{name:"bytespersec",color:"black",tickColor:0,tickDecimals:1,tickFormatter:function(a){return UI.format.bytes(a,!0)},tickLength:0,ticks:function(a){var b=0.3*Math.sqrt($(".graph").first().height()),b=(a.max-a.min)/b,e=Math.floor(Math.log(Math.abs(b))/Math.log(1024)),c=b/Math.pow(1024,e),d=-Math.floor(Math.log(c)/Math.LN10),j=a.tickDecimals;null!=j&&d>j&&(d=j);var i=Math.pow(10,-d),c=c/i,f;if(1.5>c)f=1;else if(3>c){if(f=2,2.25<c&&(null==j||d+1<=j))f=2.5,++d}else f=7.5>
c?5:10;f=f*i*Math.pow(1024,e);null!=a.minTickSize&&f<a.minTickSize&&(f=a.minTickSize);a.delta=b;a.tickDecimals=Math.max(0,null!=j?j:d);a.tickSize=f;b=[];e=a.tickSize*Math.floor(a.min/a.tickSize);d=0;j=Number.NaN;do i=j,j=e+d*a.tickSize,b.push(j),++d;while(j<a.max&&j!=i);return b},min:0}},xaxes:{time:{name:"time",mode:"time",timezone:"browser",ticks:5}}},draggable:function(a){a.attr("draggable",!0);a.on("dragstart",function(a){$(this).css("opacity",0.4).data("dragstart",{click:{x:a.originalEvent.pageX,
y:a.originalEvent.pageY},ele:{x:this.offsetLeft,y:this.offsetTop}})}).on("dragend",function(a){var e=$(this).data("dragstart"),c=e.ele.x-e.click.x+a.originalEvent.pageX,a=e.ele.y-e.click.y+a.originalEvent.pageY;$(this).css({opacity:1,top:a,left:c,right:"auto",bottom:"auto"})});a.parent().on("dragleave",function(){})},format:{time:function(a,b){var e=new Date(1E3*a),c=[];c.push(("0"+e.getHours()).slice(-2));c.push(("0"+e.getMinutes()).slice(-2));"short"!=b&&c.push(("0"+e.getSeconds()).slice(-2));return c.join(":")},
date:function(a,b){var e=new Date(1E3*a),c="Sun Mon Tue Wed Thu Fri Sat".split(" "),d=[];"long"==b&&d.push(c[e.getDay()]);d.push(("0"+e.getDate()).slice(-2));d.push("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ")[e.getMonth()]);"short"!=b&&d.push(e.getFullYear());return d.join(" ")},dateTime:function(a,b){return UI.format.date(a,b)+", "+UI.format.time(a,b)},duration:function(a,b){var e=[0.001,1E3,60,60,24,1E99],c=["ms","sec","min","hr","day"],d={},j=!!(0>a),i=Math.abs(a),f;for(f in c){var i=
Math.round(i/e[f]),m=i%e[Number(f)+1];d[c[f]]=m;i-=m}var n;for(f=c.length-1;0<=f;f--)if(0<d[c[f]]){n=c[f];break}e=$("<span>");switch(n){case "day":if(b){e.append(UI.format.addUnit(d.day,"days, ")).append(UI.format.addUnit(d.hr,"hrs"));break}else e.append(UI.format.addUnit(d.day,"days, "));default:if(b)switch(n){case "hr":e.append(UI.format.addUnit(d.hr,"hrs, ")).append(UI.format.addUnit(d.min,"mins"));break;case "min":e.append(UI.format.addUnit(d.min,"mins, ")).append(UI.format.addUnit(d.sec,"s"));
break;case "sec":d=Math.round(1E3*d.sec+d.ms)/1E3;e.append(UI.format.addUnit(d,"s"));break;case "ms":e.append(UI.format.addUnit(d.ms,"ms"))}else e.append([("0"+d.hr).slice(-2),("0"+d.min).slice(-2),("0"+d.sec).slice(-2)+(d.ms?"."+("00"+d.ms).slice(-3):"")].join(":"))}return(j?"- ":"")+e[0].innerHTML},number:function(a){if(isNaN(Number(a))||0==a)return a;var b=Math.pow(10,3-Math.floor(Math.log(a)/Math.LN10)-1),a=Math.round(a*b)/b;if(1E4<=a){number=a.toString().split(".");for(a=/(\d+)(\d{3})/;a.test(number[0]);)number[0]=
number[0].replace(a,"$1 $2");a=number.join(".")}return a},status:function(a){var b=$("<span>");if("undefined"==typeof a.online)return b.text("Unknown, checking.."),"undefined"!=typeof a.error&&b.text(a.error),b;switch(a.online){case -1:b.text("Enabling");break;case 0:b.text("Unavailable").addClass("red");break;case 1:b.text("Active").addClass("green");break;case 2:b.text("Standby").addClass("orange");break;default:b.text(a.online)}"error"in a&&b.text(a.error);return b},capital:function(a){return a.charAt(0).toUpperCase()+
a.substring(1)},addUnit:function(a,b){var e=$("<span>").html(a);e.append($("<span>").addClass("unit").html(b));return e[0].innerHTML},bytes:function(a,b){var e="bytes KiB MiB GiB TiB PiB".split(" ");if(0==a)unit=e[0];else{var c=Math.floor(Math.log(Math.abs(a))/Math.log(1024));0>c?unit=e[0]:(a/=Math.pow(1024,c),unit=e[c])}return UI.format.addUnit(UI.format.number(a),unit+(b?"/s":""))},bits:function(a,b){var e="b Kib Mib Gib Tib Pib".split(" ");if(0==a)unit=e[0];else{var c=Math.floor(Math.log(Math.abs(a))/
Math.log(1024));0>c?unit=e[0]:(a/=Math.pow(1024,c),unit=e[c])}return UI.format.addUnit(UI.format.number(a),unit+(b?"ps":""))}},navto:function(a,b){var e=location.hash,c=e.split("@");c[0]=[mist.user.name,mist.user.host].join("&");c[1]=[a,b].join("&");"undefined"!=typeof screenlog&&screenlog.navto(c[1]);location.hash=c.join("@");location.hash==e&&$(window).trigger("hashchange")},showTab:function(a,b,e){var c=UI.elements.main;"undefined"==typeof e&&(e=[]);if(mist.user.loggedin){if(!("ui_settings"in mist.data)){c.html("Loading..");
mist.send(function(){UI.showTab(a,b)},{ui_settings:!0});return}mist.data.config.serverid&&(document.title=mist.data.config.serverid+" - MistServer MI")}var d=UI.elements.menu.removeClass("hide").find('.plain:contains("'+a+'")').filter(function(){return $(this).text()===a}).closest(".button");0<d.length&&(UI.elements.menu.find(".button.active").removeClass("active"),d.addClass("active"),$submenu=d.closest("[data-param]"),$submenu.length&&$submenu.attr("data-param",b));window.mv&&mv.reference&&mv.reference.unload();
UI.interval.clear();UI.websockets.clear();c.attr("data-tab",a).html($("<h2>").text(a));switch(a){case "Login":if(mist.user.loggedin){UI.navto("Overview");return}document.title="MistServer MI";UI.elements.menu.addClass("hide");UI.elements.connection.status.text("Disconnected").removeClass("green").addClass("red");c.append(UI.buildUI([{type:"help",help:"Please provide your account details.<br>You were asked to set these when MistController was started for the first time. If you did not yet set any account details, log in with your desired credentials to create a new account."},
{label:"Host",help:"Url location of the MistServer API. Generally located at http://MistServerIP:4242/api","default":"http://localhost:4242/api",pointer:{main:mist.user,index:"host"}},{label:"Username",help:"Please enter your username here.",validate:["required"],pointer:{main:mist.user,index:"name"}},{label:"Password",type:"password",help:"Please enter your password here.",validate:["required"],pointer:{main:mist.user,index:"rawpassword"}},{type:"buttons",buttons:[{label:"Login",type:"save","function":function(){mist.user.password=
MD5(mist.user.rawpassword);delete mist.user.rawpassword;mist.send(function(){UI.navto("Overview")})}}]}]));break;case "Create a new account":UI.elements.menu.addClass("hide");c.append($("<p>").text("No account has been created yet in the MistServer at ").append($("<i>").text(mist.user.host)).append("."));c.append(UI.buildUI([{type:"buttons",buttons:[{label:"Select other host",type:"cancel",css:{"float":"left"},"function":function(){UI.navto("Login")}}]},{type:"custom",custom:$("<br>")},{label:"Desired username",
type:"str",validate:["required"],help:"Enter your desired username. In the future, you will need this to access the Management Interface.",pointer:{main:mist.user,index:"name"}},{label:"Desired password",type:"password",validate:["required",function(a,b){$(".match_password.field").not($(b)).trigger("change");return false}],help:"Enter your desired password. In the future, you will need this to access the Management Interface.",pointer:{main:mist.user,index:"rawpassword"},classes:["match_password"]},
{label:"Repeat password",type:"password",validate:["required",function(a,b){return a!=$(".match_password.field").not($(b)).val()?{msg:'The fields "Desired password" and "Repeat password" do not match.',classes:["red"]}:false}],help:"Repeat your desired password.",classes:["match_password"]},{type:"buttons",buttons:[{type:"save",label:"Create new account","function":function(){mist.send(function(){UI.navto("Account created")},{authorize:{new_username:mist.user.name,new_password:mist.user.rawpassword}});
mist.user.password=MD5(mist.user.rawpassword);delete mist.user.rawpassword}}]}]));break;case "Account created":UI.elements.menu.addClass("hide");c.append($("<p>").text("Your account has been created succesfully.")).append(UI.buildUI([{type:"text",text:"Would you like to enable all (currently) available protocols with their default settings?"},{type:"buttons",buttons:[{label:"Enable protocols",type:"save","function":function(){if(mist.data.config.protocols)c.append("Unable to enable all protocols as protocol settings already exist.<br>");
else{c.append("Retrieving available protocols..<br>");mist.send(function(a){var b=[],d;for(d in a.capabilities.connectors)if(a.capabilities.connectors[d].required)c.append('Could not enable protocol "'+d+'" because it has required settings.<br>');else{b.push({connector:d});c.append('Enabled protocol "'+d+'".<br>')}c.append("Saving protocol settings..<br>");mist.send(function(){c.append("Protocols enabled. Redirecting..");setTimeout(function(){UI.navto("Overview")},5E3)},{config:{protocols:b}})},{capabilities:true})}}},
{label:"Skip",type:"cancel","function":function(){UI.navto("Overview")}}]}]));break;case "Overview":if("undefined"==typeof mist.data.bandwidth){mist.send(function(){UI.navto(a)},{bandwidth:!0});c.append("Loading..");return}var j=$("<span>").text("Loading.."),i=$("<span>"),f=$("<span>").addClass("logs"),m=$("<span>"),n=$("<span>"),k=$("<span>").text("Unknown"),q=$("<span>"),h=$("<span>"),g=parseURL(mist.user.host),g=g.protocol+g.host+g.port,l={};c.append(UI.buildUI([{type:"help",help:"You can find most basic information about your MistServer here.<br>You can also set the debug level and force a save to the config.json file that MistServer uses to save your settings. "},
{type:"span",label:"Version",pointer:{main:mist.data.config,index:"version"}},{type:"span",label:"Version check",value:j},{type:"span",label:"Server time",value:n},{type:"span",label:"Licensed to",value:"license"in mist.data.config?mist.data.config.license.user:""},{type:"span",label:"Active licenses",value:k},{type:"span",label:"Configured streams",value:mist.data.streams?Object.keys(mist.data.streams).length:0},{type:"span",label:"Active streams",value:i},{type:"span",label:"Current connections",
value:m},{type:"span",label:"Enabled protocols",value:q},{type:"span",label:"Disabled protocols",value:h},{type:"span",label:"Recent problems",value:f},$("<br>"),$("<h3>").text("Write config now"),{type:"help",help:"Tick the box in order to force an immediate save to the config.json MistServer uses to save your settings. Saving will otherwise happen upon closing MistServer. Don't forget to press save after ticking the box."},{type:"checkbox",label:"Force configurations save",pointer:{main:l,index:"save"}},
{type:"buttons",buttons:[{type:"save",label:"Save","function":function(){var a={};if(l.save)a.save=l.save;delete l.save;mist.send(function(){UI.navto("Overview")},a)}}]}]));if(mist.data.LTS){var o=function(a){function b(a){if(a.update){var d="";"progress"in a.update&&(d=" ("+a.update.progress+"%)");j.text("Updating.."+d);c(a.log);setTimeout(function(){mist.send(function(a){b(a)},{update:true})},1E3)}else UI.showTab("Overview")}function c(a){a=a.filter(function(a){return a[1]=="UPDR"});if(a.length){var b=
$("<div>");j.append(b);for(var d in a)b.append($("<div>").text(a[d][2]))}}if(!a.update||!("uptodate"in a.update)){j.text("Unknown, checking..");setTimeout(function(){mist.send(function(a){"update"in a&&o(a)},{checkupdate:true})},5E3)}else if(a.update.error)j.addClass("red").text(a.update.error);else if(a.update.uptodate)j.text("Your version is up to date.").addClass("green");else{if(a.update.progress){j.addClass("orange").removeClass("red").text("Updating..");b(a)}else{j.text("");j.append($("<span>").addClass("red").text("On "+
(new Date(a.update.date)).toLocaleDateString()+" version "+a.update.version+" became available."));(!a.update.url||a.update.url.slice(-4)!=".zip")&&j.append($("<button>").text("Rolling update").css({"font-size":"1em","margin-left":"1em"}).click(function(){if(confirm("Are you sure you want to execute a rolling update?")){j.addClass("orange").removeClass("red").text("Rolling update command sent..");mist.send(function(a){b(a)},{autoupdate:true})}}));var d=$("<a>").attr("href",a.update.url).attr("target",
"_blank").text("Manual download");d[0].protocol="https:";j.append($("<div>").append(d))}c(a.log)}};o(mist.data);if("license"in mist.data.config){if("active_products"in mist.data.config.license&&Object.keys(mist.data.config.license.active_products).length){var u=$("<table>").css("text-indent","0");k.html(u);u.append($("<tr>").append($("<th>").append("Product")).append($("<th>").append("Updates until")).append($("<th>").append("Use until")).append($("<th>").append("Max. simul. instances")));for(var p in mist.data.config.license.active_products){var s=
mist.data.config.license.active_products[p];u.append($("<tr>").append($("<td>").append(s.name)).append($("<td>").append(s.updates_final?s.updates_final:"&infin;")).append($("<td>").append(s.use_final?s.use_final:"&infin;")).append($("<td>").append(s.amount?s.amount:"&infin;")))}}else k.text("None. ");k.append($("<a>").text("More details").attr("href","https://shop.mistserver.org/myinvoices").attr("target","_blank"))}}else j.text("");p=function(){var a={totals:{fields:["clients"],start:-10},active_streams:true};
if(!("capabilities"in mist.data))a.capabilities=true;mist.send(function(){ga()},a)};var ga=function(){i.text("active_streams"in mist.data?mist.data.active_streams?mist.data.active_streams.length:0:"?");if("totals"in mist.data&&"all_streams"in mist.data.totals)var a=mist.data.totals.all_streams.all_protocols.clients,a=a.length?UI.format.number(a[a.length-1][1]):0;else a="Loading..";m.text(a);n.text(UI.format.dateTime(mist.data.config.time,"long"));f.html("");a=0;"license"in mist.data.config&&"user_msg"in
mist.data.config.license&&mist.data.log.unshift([mist.data.config.license.time,"ERROR",mist.data.config.license.user_msg]);for(var b in mist.data.log){var c=mist.data.log[b];if(["FAIL","ERROR"].indexOf(c[1])>-1){a++;var d=$("<span>").addClass("content").addClass("red"),e=c[2].split("|");for(b in e)d.append($("<span>").text(e[b]));f.append($("<div>").append($("<span>").append(UI.format.time(c[0])).css("margin-right","0.5em")).append(d));if(a==5)break}}a==0&&f.html("None.");a=[];c=[];for(b in mist.data.config.protocols){d=
mist.data.config.protocols[b];a.indexOf(d.connector)>-1||a.push(d.connector)}q.text(a.length?a.join(", "):"None.");if("capabilities"in mist.data){for(b in mist.data.capabilities.connectors)a.indexOf(b)==-1&&c.push(b);h.text(c.length?c.join(", "):"None.")}else h.text("Loading..")};p();ga();UI.interval.set(p,3E4);break;case "General":var L={serverid:mist.data.config.serverid,debug:mist.data.config.debug,accesslog:mist.data.config.accesslog,prometheus:mist.data.config.prometheus,defaultStream:mist.data.config.defaultStream,
trustedproxy:mist.data.config.trustedproxy},M={sessionViewerMode:mist.data.config.sessionViewerMode,sessionInputMode:mist.data.config.sessionInputMode,sessionOutputMode:mist.data.config.sessionOutputMode,sessionUnspecifiedMode:mist.data.config.sessionUnspecifiedMode,tknMode:mist.data.config.tknMode,sessionStreamInfoMode:mist.data.config.sessionStreamInfoMode},U={location:"location"in mist.data.config?mist.data.config.location:{}},F={limit:""};"bandwidth"in mist.data&&(F=mist.data.bandwidth,null==
F&&(F={}),F.limit||(F.limit=""));var ha=$("<select>").html($("<option>").val(1).text("bytes/s")).append($("<option>").val(1024).text("KiB/s")).append($("<option>").val(1048576).text("MiB/s")).append($("<option>").val(1073741824).text("GiB/s"));c.html(UI.buildUI([$("<h2>").text("General settings"),{type:"help",help:"These are settings that apply to your MistServer instance in general."},{type:"str",label:"Human readable name",pointer:{main:L,index:"serverid"},help:"You can name your MistServer here for personal use. You'll still need to set host name within your network yourself."},
{type:"debug",label:"Debug level",pointer:{main:L,index:"debug"},help:"You can set the amount of debug information MistServer saves in the log. A full reboot of MistServer is required before some components of MistServer can post debug information."},{type:"selectinput",label:"Access log",selectinput:[["","Do not track"],["LOG","Log to MistServer log"],[{type:"str",label:"Path",LTSonly:!0},"Log to file"]],pointer:{main:L,index:"accesslog"},help:"Enable access logs.",LTSonly:!0},{type:"selectinput",
label:"Prometheus stats output",selectinput:[["","Disabled"],[{type:"str",label:"Passphrase",LTSonly:!0},"Enabled"]],pointer:{main:L,index:"prometheus"},help:"Make stats available in Prometheus format. These can be accessed via "+g+"/PASSPHRASE or "+g+"/PASSPHRASE.json.",LTSonly:!0},{type:"inputlist",label:"Trusted proxies",help:"List of proxy server addresses that are allowed to override the viewer IP address to arbitrary values.<br>You may use a hostname or IP address.",pointer:{main:L,index:"trustedproxy"}},
{type:"str",validate:["streamname_with_wildcard_and_variables"],label:"Fallback stream",pointer:{main:L,index:"defaultStream"},help:"When this is set, if someone attempts to view a stream that does not exist, or is offline, they will be redirected to this stream instead. $stream may be used to refer to the original stream name.",LTSonly:!0},{type:"buttons",buttons:[{type:"save",label:"Save","function":function(a){$(a).text("Saving..");mist.send(function(){UI.navto("General")},{config:L})}}]}]));c.append(UI.buildUI([$("<h3>").text("Sessions"),
{type:"bitmask",label:"Bundle viewer sessions by",bitmask:[[8,"Stream name"],[4,"IP address"],[2,"Token"],[1,"Protocol"]],pointer:{main:M,index:"sessionViewerMode"},help:"Change the way viewer connections are bundled into sessions.<br>Default: stream name, viewer IP and token"},{type:"bitmask",label:"Bundle input sessions by",bitmask:[[8,"Stream name"],[4,"IP address"],[2,"Token"],[1,"Protocol"]],pointer:{main:M,index:"sessionInputMode"},help:"Change the way input connections are bundled into sessions.<br>Default: stream name, input IP, token and protocol"},
{type:"bitmask",label:"Bundle output sessions by",bitmask:[[8,"Stream name"],[4,"IP address"],[2,"Token"],[1,"Protocol"]],pointer:{main:M,index:"sessionOutputMode"},help:"Change the way output connections are bundled into sessions.<br>Default: stream name, output IP, token and protocol"},{type:"bitmask",label:"Bundle unspecified sessions by",bitmask:[[8,"Stream name"],[4,"IP address"],[2,"Token"],[1,"Protocol"]],pointer:{main:M,index:"sessionUnspecifiedMode"},help:"Change the way unspecified connections are bundled into sessions.<br>Default: none"},
{type:"select",label:"Treat HTTP-only sessions as",select:[[1,"A viewer session"],[2,"An output session: skip executing the USER_NEW and USER_END triggers"],[4,"A separate 'unspecified' session: skip executing the USER_NEW and USER_END triggers"],[3,"Do not start a session: skip executing the USER_NEW and USER_END triggers and do not count for statistics"]],pointer:{main:M,index:"sessionStreamInfoMode"},help:"Change the way the stream info connection gets treated.<br>Default: as a viewer session"},
{type:"bitmask",label:"Communicate session token",bitmask:[[8,"Write to cookie"],[4,"Write to URL parameter"],[2,"Read from cookie"],[1,"Read from URL parameter"]],pointer:{main:M,index:"tknMode"},help:"Change the way the session token gets passed to and from MistServer, which can be set as a cookie or URL parameter named `tkn`. Reading the session token as a URL parameter takes precedence over reading from the cookie.<br>Default: all"},{type:"buttons",buttons:[{type:"save",label:"Save","function":function(a){$(a).text("Saving..");
mist.send(function(){UI.navto("General")},{config:M})}}]}]));var D=$("<div>").html("Loading..");mist.send(function(a){if(a.variable_list){var b=$("<tbody>");D.html($("<table>").html($("<thead>").html($("<tr>").append($("<th>").text("Variable")).append($("<th>").text("Latest value")).append($("<th>").text("Command")).append($("<th>").text("Check interval")).append($("<th>").text("Last checked")).append($("<th>")))).append(b));for(var c in a.variable_list){var d=a.variable_list[c];b.append($("<tr>").addClass("variable").attr("data-name",
c).html($("<td>").text("$"+c)).append($("<td>").html($("<code>").text(typeof d=="string"?JSON.stringify(d):d[2]>0?JSON.stringify(d[3]):""))).append($("<td>").text(typeof d=="string"?"":d[0])).append($("<td>").html(typeof d=="string"?"Never":d[1]==0?"Once":UI.format.duration(d[1]))).append($("<td>").attr("title",d[2]>0?typeof d=="string"?"":"At "+UI.format.dateTime(new Date(d[2]),"long"):"Not yet").html(typeof d=="string"?"":d[2]>0?UI.format.duration((new Date).getTime()*0.001-d[2])+" ago":"Not yet")).append($("<td>").html($("<button>").text("Edit").click(function(){var a=
$(this).closest("tr").attr("data-name");UI.navto("Edit variable",a)})).append($("<button>").text("Remove").click(function(){var a=$(this).closest("tr").attr("data-name");confirm("Are you sure you want to remove the custom variable $"+a+"?")&&mist.send(function(){UI.showTab("General")},{variable_remove:a})}))))}}else D.html("None configured.")},{variable_list:!0});c.append(UI.buildUI([$("<h3>").text("Custom variables"),{type:"help",help:"In certain places, like target URL's and pushes, variable substitution is applied in order to replace a $variable with their corresponding value. Here you can define your own constants and variables which will be used when variable substitution is applied. Variables can be used within variables but will not be reflected in their latest value on this page."},
$("<div>").addClass("button_container").css("text-align","right").html($("<button>").text("New variable").click(function(){UI.navto("Edit variable","")})),D]));c.append(UI.buildUI([$("<h3>").text("Load balancer"),{type:"help",help:"If you're using MistServer's load balancer, the information below is passed to it so that it can make informed decisions."},{type:"selectinput",label:"Server's bandwidth limit",selectinput:[["","Default (1 gbps)"],[{label:"Custom",type:"int",min:0,unit:ha},"Custom"]],pointer:{main:F,
index:"limit"},help:"This is the amount of traffic this server is willing to handle."},{type:"inputlist",label:"Bandwidth exceptions",pointer:{main:F,index:"exceptions"},help:"Data sent to the hosts and subnets listed here will not count towards reported bandwidth usage.<br>Examples:<ul><li>192.168.0.0/16</li><li>localhost</li><li>10.0.0.0/8</li><li>fe80::/16</li></ul>"},{type:"int",step:1E-8,label:"Server latitude",pointer:{main:U.location,index:"lat"},help:"This setting is only useful when MistServer is combined with a load balancer. When this is set, the balancer can send users to a server close to them."},
{type:"int",step:1E-8,label:"Server longitude",pointer:{main:U.location,index:"lon"},help:"This setting is only useful when MistServer is combined with a load balancer. When this is set, the balancer can send users to a server close to them."},{type:"str",label:"Server location name",pointer:{main:U.location,index:"name"},help:"This setting is only useful when MistServer is combined with a load balancer. This will be displayed as the server's location."},{type:"buttons",buttons:[{type:"save",label:"Save",
"function":function(a){$(a).text("Saving..");var a={config:U},b={};b.limit=F.limit?ha.val()*F.limit:0;b.exceptions=F.exceptions;if(b.exceptions===null)b.exceptions=[];a.bandwidth=b;mist.send(function(){UI.navto("Overview")},a)}}]}]));var G=$("<div>").html("Loading..");c.append(UI.buildUI([$("<h3>").text("External writers"),{type:"help",help:"When pushing a stream to a target unsupported by MistServer like S3 storage, an external writer can be provided which handles writing the media data to the target location. The writer will receive data over stdin and MistServer will print any info written to stdout and stderr as log messages."},
$("<div>").addClass("button_container").css("text-align","right").html($("<button>").text("New external writer").click(function(){UI.navto("Edit external writer","")})),G]));mist.send(function(a){if(a.external_writer_list){var b=$("<tbody>");G.html($("<table>").html($("<thead>").html($("<tr>").append($("<th>").text("Name")).append($("<th>").text("Command line")).append($("<th>").text("URI protocols handled")).append($("<th>")))).append(b));for(var c in a.external_writer_list){var d=a.external_writer_list[c];
b){var c=$("<a>").addClass("button");c.html($("<span>").addClass("plain").text(a)).append($("<span>").addClass("highlighted").text(a));for(var d in b.classes)c.addClass(b.classes[d]);"link"in b?c.attr("href",b.link).attr("target","_blank"):"submenu"in b||c.click(function(b){if(!$(this).closest(".menu").hasClass("hide")){var c,d=$(this).closest(".hiddenmenu[data-param]");d.length&&(c=d.attr("data-param"));UI.navto(a,c);b.stopPropagation()}});return c}var b=UI.elements.menu,d;for(d in UI.menu){0<d&&
b.append($("<br>"));for(var c in UI.menu[d]){var e=UI.menu[d][c],l=a(c,e);b.append(l);if("submenu"in e){var i=$("<span>").addClass("submenu");l.addClass("arrowdown").append(i);for(var f in e.submenu)i.append(a(f,e.submenu[f]))}else if("hiddenmenu"in e)for(f in i=$("<span>").addClass("hiddenmenu"),e.keepParam&&i.attr("data-param",""),l.append(i),e.hiddenmenu)i.append(a(f,e.hiddenmenu[f]))}}d=$("<div>").attr("id","ih_button").text("?").click(function(){$("body").toggleClass("helpme");UI.stored.saveOpt("helpme",
$("body").hasClass("helpme"))}).attr("title","Click to toggle the display of integrated help");UI.stored.getOpts().helpme&&$("body").addClass("helpme");b.after(d).after($("<div>").addClass("separator"))},findInput:function(a){return this.findInOutput("inputs",a)},findOutput:function(a){return this.findInOutput("connectors",a)},findInOutput:function(a,b){if("capabilities"in mist.data){var d=!1,c=mist.data.capabilities[a];b in c&&(d=c[b]);b+".exe"in c&&(d=c[b+".exe"]);return d}throw"Request capabilities first";
},updateLiveStreamHint:function(a,b,d){if(a){var c=parseURL(mist.user.host),e=b.match(/@.*/);e&&(e=e[0].substring(1));var l=b.replace(/(?:.+?):\/\//,""),l=l.split("/"),l=l[0],l=l.split(":"),l=l[0],i=b.match(/:\d+/);i&&(i=i[0]);var f={},m="RTMP RTSP RTMP.exe RTSP.exe TSSRT TSSRT.exe".split(" "),n;for(n in m)m[n]in mist.data.capabilities.connectors&&(f[m[n]]=mist.data.capabilities.connectors[m[n]].optional.port["default"]);var m={RTMP:1935,"RTMP.exe":1935,RTSP:554,"RTSP.exe":554,TSSRT:-1,"TSSRT.exe":-1,
TS:-1,"TS.exe":-1},j;for(j in f){for(n in mist.data.config.protocols){var q=mist.data.config.protocols[n];if(q.connector==j){"port"in q&&(f[j]=q.port);break}}f[j]=f[j]==m[j]?"":":"+f[j]}f.TS="";f["TS.exe"]="";d.find(".field").closest("label").hide();for(n in f){var g;j=i?i:f[n];switch(n){case "RTMP":case "RTMP.exe":g="rtmp://"+c.host+j+"/"+(e?e:"live")+"/";j=d.find(".field.RTMPurl").setval(g).closest("label");j.length&&(j[0].style.display="");j=d.find(".field.RTMPkey").setval(""==a?"STREAMNAME":a).closest("label");
j.length&&(j[0].style.display="");g+=""==a?"STREAMNAME":a;break;case "TSSRT":case "TSSRT.exe":"srt://"==b.slice(0,6)?i?(g=parseURL(b.replace()),""==g.host&&(g=parseURL(b.replace(/^srt:\/\//,"http://localhost")),g.host=g.host.replace(/^localhost/,"")),g=""!=g.host&&(!g.search||!g.searchParams||"listener"!=g.searchParams.get("mode"))?"Caller mode: you should push to the other side.":g.search&&g.searchParams&&"caller"==g.searchParams.get("mode")?"Caller mode: you should probably add an address.":"srt://"+
c.host+i):g="You must specify a port.":g="srt://"+c.host+j+"?streamid="+(""==a?"STREAMNAME":a);break;case "RTSP":case "RTSP.exe":g="rtsp://"+c.host+j+"/"+(""==a?"STREAMNAME":a)+(e?"?pass="+e:"");break;case "TS":case "TS.exe":g="udp://"+(""==l?c.host:l)+j+"/"}j=d.find(".field."+n.replace(".exe",""));j.length&&(j.setval(g).closest("label")[0].style.display="")}}},buildUI:function(a){var b=$("<div>").addClass("input_container"),d;for(d in a){var c=a[d];if(c instanceof jQuery)b.append(c);else if("help"==
c.type){var e=$("<span>").addClass("text_container").append($("<span>").addClass("description").append(c.help));b.append(e);if("classes"in c)for(var l in c.classes)e.addClass(c.classes[l])}else if("text"==c.type)b.append($("<span>").addClass("text_container").append($("<span>").addClass("text").append(c.text)));else if("custom"==c.type)b.append(c.custom);else if("buttons"==c.type)for(l in e=$("<span>").addClass("button_container").on("keydown",function(a){a.stopPropagation()}),"css"in c&&e.css(c.css),
b.append(e),c.buttons){var i=c.buttons[l],f=$("<button>").text(i.label).data("opts",i);"css"in i&&f.css(i.css);if("classes"in i)for(var m in i.classes)f.addClass(i.classes[m]);e.append(f);switch(i.type){case "cancel":f.addClass("cancel").click(i["function"]);break;case "save":f.addClass("save").click(function(){var a=$(this).data("opts").preSave;a&&a.call(this);var b=$(this).closest(".input_container"),c=!1;b.find('.hasValidate:visible, input[type="hidden"].hasValidate').each(function(){if(c=$(this).data("validate")(this,
!0))return!1});(a=$(this).data("opts").failedValidate)&&a.call(this);c||(b.find('.isSetting:visible, input[type="hidden"].isSetting').each(function(){var a=$(this).getval(),b=$(this).data("pointer");if(""===a)if("default"in $(this).data("opts"))a=$(this).data("opts")["default"];else return b.main[b.index]=null,!0;b.main[b.index]=a;(a=$(this).data("opts").postSave)&&a.call(this)}),(a=$(this).data("opts")["function"])&&a(this))});break;default:f.click(i["function"])}}else{i=$("<label>").addClass("UIelement");
b.append(i);"css"in c&&i.css(c.css);i.append($("<span>").addClass("label").html("label"in c?c.label+":":""));if("classes"in c)for(m in c.classes)i.addClass(c.classes[m]);f=$("<span>").addClass("field_container");i.append(f);switch(c.type){case "password":e=$("<input>").attr("type","password");break;case "int":e=$("<input>").attr("type","number");"min"in c&&e.attr("min",c.min);"max"in c&&e.attr("max",c.max);"step"in c&&e.attr("step",c.step);"validate"in c?c.validate.push("int"):c.validate=["int"];
break;case "span":e=$("<span>");break;case "debug":c.select=[["","Default"],[0,"0 - All debugging messages disabled"],[1,"1 - Messages about failed operations"],[2,"2 - Previous level, and error messages"],[3,"3 - Previous level, and warning messages"],[4,"4 - Previous level, and status messages for development"],[5,"5 - Previous level, and more status messages for development"],[6,"6 - Previous level, and verbose debugging messages"],[7,"7 - Previous level, and very verbose debugging messages"],
[8,"8 - Report everything in extreme detail"],[9,"9 - Report everything in insane detail"],[10,"10 - All messages enabled"]];case "select":e=$("<select>");for(l in c.select){var n=$("<option>");"string"==typeof c.select[l]?n.text(c.select[l]):n.val(c.select[l][0]).text(c.select[l][1]);e.append(n)}break;case "textarea":e=$("<textarea>").on("keydown",function(a){a.stopPropagation()});break;case "checkbox":e=$("<input>").attr("type","checkbox");break;case "hidden":e=$("<input>").attr("type","hidden");
i.hide();break;case "email":e=$("<input>").attr("type","email").attr("autocomplete","on").attr("required","");break;case "browse":e=$("<input>").attr("type","text");"filetypes"in c&&e.data("filetypes",c.filetypes);break;case "geolimited":case "hostlimited":e=$("<input>").attr("type","hidden");break;case "radioselect":e=$("<div>").addClass("radioselect");for(d in c.radioselect){var j=$("<input>").attr("type","radio").val(c.radioselect[d][0]).attr("name",c.label);c.readonly&&j.prop("disabled",!0);n=
$("<label>").append(j).append($("<span>").html(c.radioselect[d][1]));e.append(n);if(2<c.radioselect[d].length)for(l in j=$("<select>").change(function(){$(this).parent().find("input[type=radio]:enabled").prop("checked","true")}),n.append(j),c.readonly&&j.prop("disabled",!0),c.radioselect[d][2])n=$("<option>"),j.append(n),c.radioselect[d][2][l]instanceof Array?n.val(c.radioselect[d][2][l][0]).html(c.radioselect[d][2][l][1]):n.html(c.radioselect[d][2][l])}break;case "checklist":e=$("<div>").addClass("checkcontainer");
$controls=$("<div>").addClass("controls");$checklist=$("<div>").addClass("checklist");e.append($checklist);for(d in c.checklist)"string"==typeof c.checklist[d]&&(c.checklist[d]=[c.checklist[d],c.checklist[d]]),$checklist.append($("<label>").text(c.checklist[d][1]).prepend($("<input>").attr("type","checkbox").attr("name",c.checklist[d][0])));break;case "DOMfield":e=c.DOMfield;break;case "unix":e=$("<input>").attr("type","datetime-local").attr("step",1);c.unit=$("<button>").text("Now").click(function(){$(this).closest(".field_container").find(".field").setval((new Date).getTime()/
1E3)});break;case "selectinput":e=$("<div>").addClass("selectinput");j=$("<select>");e.append(j);j.data("input",!1);for(d in c.selectinput)n=$("<option>"),j.append(n),"string"==typeof c.selectinput[d]?n.text(c.selectinput[d]):(n.text(c.selectinput[d][1]),"string"==typeof c.selectinput[d][0]?n.val(c.selectinput[d][0]):(n.val("CUSTOM"),j.data("input")||j.data("input",UI.buildUI([c.selectinput[d][0]]).children())));j.data("input")&&e.append(j.data("input"));j.change(function(){"CUSTOM"==$(this).val()?
$(this).data("input").css("display","flex"):$(this).data("input").hide()});j.trigger("change");break;case "inputlist":e=$("<div>").addClass("inputlist");e.data("newitem",function(){var a;if("input"in c)a=UI.buildUI([c.input]).find(".field_container");else{var b=Object.assign({},c);delete b.validate;delete b.pointer;b.type="str";a=UI.buildUI([b]).find(".field_container")}a.removeClass("isSetting");a.addClass("listitem");var h=function(b){$(this).is(":last-child")?""!=$(this).find(".field").getval()?
(b=a.clone().keyup(h),b.find(".field").setval(""),$(this).after(b)):8==b.which&&$(this).prev().find(".field").focus():""==$(this).find(".field").getval()&&(b=$(this).prev(),b.length||(b=$(this).next()),b.find(".field").focus(),$(this).remove())};a.keyup(h);return a});e.append(e.data("newitem"));break;case "sublist":e=$("<div>").addClass("sublist");j=$("<div>").addClass("curvals");j.append($("<span>").text("None."));var q=$("<div>").addClass("itemsettings"),g=$("<button>").text("New "+c.itemLabel),
h=c.sublist,k=c,o=e,s=i;e.data("build",function(a,b){for(var c in k.saveas)c in a||delete k.saveas[c];k.saveas=Object.assign(k.saveas,a);c="New";"undefined"!=typeof b&&(c="Edit");c=UI.buildUI([$("<h4>").text(c+" "+k.itemLabel)].concat(h).concat([{label:"Save first",type:"str",classes:["onlyshowhelp"],validate:[function(){return{msg:"Did you want to save this "+k.itemLabel+"?",classes:["red"]}}]},{type:"buttons",buttons:[{label:"Cancel",type:"cancel","function":function(){q.html("");g.show();s.show()}},
{label:"Save "+k.itemLabel,type:"save",preSave:function(){$(this).closest(".input_container").find(".onlyshowhelp").closest("label").hide()},failedValidate:function(){$(this).closest(".input_container").find(".onlyshowhelp").closest("label").show()},"function":function(){var a=o.getval(),c=Object.assign({},k.saveas),h;for(h in c)null===c[h]&&delete c[h];"undefined"==typeof b?a.push(c):a[b]=c;o.setval(a);q.html("");g.show();s.show()}}]}]));q.html(c);g.hide();s.hide()});var p=e;g.click(function(){p.data("build")({})});
h.unshift({type:"str",label:"Human readable name",placeholder:"none",help:"A convenient name to describe this "+c.itemLabel+". It won't be used by MistServer.",pointer:{main:c.saveas,index:"x-LSP-name"}});e.data("savelist",[]);e.append(j).append(g);b.append(q);break;case "json":e=$("<textarea>").on("keydown",function(a){a.stopPropagation()}).on("keyup change",function(){this.style.height="";this.style.height=(this.scrollHeight?this.scrollHeight+20:14*this.value.split("\n").length+20)+"px"}).css("min-height",
"3em");j=function(a,b){if(""!=$(b).val()&&null===a)return{msg:"Invalid json",classes:["red"]}};"validate"in c?c.validate.push(j):c.validate=[j];break;case "bitmask":e=$("<div>").addClass("bitmask");for(d in c.bitmask)e.append($("<label>").append($("<input>").attr("type","checkbox").attr("name","bitmask_"+("pointer"in c?c.pointer.index:"")).attr("value",c.bitmask[d][0]).addClass("field")).append($("<span>").text(c.bitmask[d][1])));i.attr("for","none");break;default:e=$("<input>").attr("type","text"),
"maxlength"in c&&e.attr("maxlength",c.maxlength),"minlength"in c&&e.attr("minlength",c.minlength)}e.addClass("field").data("opts",c);"pointer"in c&&e.attr("name",c.pointer.index);f.append(e);if("classes"in c)for(l in c.classes)e.addClass(c.classes[l]);"placeholder"in c&&e.attr("placeholder",c.placeholder);"default"in c&&e.attr("placeholder",c["default"]);"unit"in c&&f.append($("<span>").addClass("unit").html(c.unit));"prefix"in c&&f.prepend($("<span>").addClass("unit").html(c.prefix));"readonly"in
c&&(e.attr("readonly","readonly"),e.click(function(){this.selectionStart==this.selectionEnd&&$(this).select()}));"qrcode"in c&&f.append($("<span>").addClass("unit").html($("<button>").text("QR").on("keydown",function(a){a.stopPropagation()}).click(function(){var a=String($(this).closest(".field_container").find(".field").getval()),b=$("<div>").addClass("qrcode");UI.popup.show($("<span>").addClass("qr_container").append($("<p>").text(a)).append(b));b.qrcode({text:a,size:Math.min(b.width(),b.height())})})));
"clipboard"in c&&document.queryCommandSupported("copy")&&f.append($("<span>").addClass("unit").html($("<button>").text("Copy").on("keydown",function(a){a.stopPropagation()}).click(function(){var a=String($(this).closest(".field_container").find(".field").getval()),b=document.createElement("textarea");b.value=a;document.body.appendChild(b);b.select();var c=false;try{c=document.execCommand("copy")}catch(h){}if(c){$(this).text("Copied to clipboard!");document.body.removeChild(b);var d=$(this);setTimeout(function(){d.text("Copy")},
5E3)}else{document.body.removeChild(b);alert("Failed to copy:\n"+a)}})));"rows"in c&&e.attr("rows",c.rows);if("dependent"in c)for(d in c.dependent)i.attr("data-dependent-"+d,c.dependent[d]);switch(c.type){case "browse":j=$("<div>").addClass("grouper").append(i);b.append(j);j=$("<button>").text("Browse").on("keydown",function(a){a.stopPropagation()});f.append(j);j.click(function(){function a(b){f.text("Loading..");mist.send(function(a){g.text(a.browse.path[0]);mist.data.LTS&&h.setval(a.browse.path[0]+
"/");f.html(m.clone(true).text("..").attr("title","Folder up"));if(a.browse.subdirectories){a.browse.subdirectories.sort();for(var b in a.browse.subdirectories){var e=a.browse.subdirectories[b];f.append(m.clone(true).attr("title",g.text()+q+e).text(e))}}if(a.browse.files){a.browse.files.sort();for(b in a.browse.files){var e=a.browse.files[b],j=g.text()+q+e,e=$("<a>").text(e).addClass("file").attr("title",j);f.append(e);if(k){var i=true,l;for(l in k)if(typeof k[l]!="undefined"&&mist.inputMatch(k[l],
j)){i=false;break}i&&e.hide()}e.click(function(){var a=$(this).attr("title");h.setval(a).removeAttr("readonly").css("opacity",1);d.show();c.remove()})}}},{browse:b})}var b=$(this).closest(".grouper"),c=$("<div>").addClass("browse_container"),h=b.find(".field").attr("readonly","readonly").css("opacity",0.5),d=$(this),e=$("<button>").text("Stop browsing").click(function(){d.show();c.remove();h.removeAttr("readonly").css("opacity",1)}),g=$("<span>").addClass("field"),f=$("<div>").addClass("browse_contents"),
m=$("<a>").addClass("folder"),k=h.data("filetypes");b.append(c);c.append($("<label>").addClass("UIelement").append($("<span>").addClass("label").text("Current folder:")).append($("<span>").addClass("field_container").append(g).append(e))).append(f);var q="/";mist.data.config.version.indexOf("indows")>-1&&(q="\\");m.click(function(){var b=g.text()+q+$(this).text();a(b)});b=h.getval();e=b.split("://");e.length>1&&(b=e[0]=="file"?e[1]:"");b=b.split(q);b.pop();b=b.join(q);d.hide();a(b)});break;case "geolimited":case "hostlimited":j=
{field:e};j.blackwhite=$("<select>").append($("<option>").val("-").text("Blacklist")).append($("<option>").val("+").text("Whitelist"));j.values=$("<span>").addClass("limit_value_list");switch(c.type){case "geolimited":j.prototype=$("<select>").append($("<option>").val("").text("[Select a country]"));for(d in UI.countrylist)j.prototype.append($("<option>").val(d).html(UI.countrylist[d]));break;case "hostlimited":j.prototype=$("<input>").attr("type","text").attr("placeholder","type a host")}j.prototype.on("change keyup",
function(){$(this).closest(".field_container").data("subUI").blackwhite.trigger("change")});j.blackwhite.change(function(){var a=$(this).closest(".field_container").data("subUI"),b=[],c=false;a.values.children().each(function(){c=$(this).val();c!=""?b.push(c):$(this).remove()});a.values.append(a.prototype.clone(true));b.length>0?a.field.val($(this).val()+b.join(" ")):a.field.val("");a.field.trigger("change")});j.values.append(j.prototype.clone(!0));f.data("subUI",j).addClass("limit_list").append(j.blackwhite).append(j.values)}"pointer"in
c&&(e.data("pointer",c.pointer).addClass("isSetting"),c.pointer.main&&(j=c.pointer.main[c.pointer.index],"undefined"!=j&&e.setval(j)));(""==e.getval()||null==e.getval()||!("pointer"in c))&&"value"in c&&e.setval(c.value);if("datalist"in c)for(d in j="datalist_"+d+MD5(e[0].outerHTML),e.attr("list",j),j=$("<datalist>").attr("id",j),f.append(j),c.datalist)j.append($("<option>").val(c.datalist[d]));f=$("<span>").addClass("help_container");i.append(f);"help"in c&&(f.append($("<span>").addClass("ih_balloon").html(c.help)),
e.on("focus mouseover",function(){$(this).closest("label").addClass("active")}).on("blur mouseout",function(){$(this).closest("label").removeClass("active")}));if("validate"in c){i=[];for(l in c.validate){j=c.validate[l];if("function"!=typeof j)switch(j){case "required":j=function(a){return a==""||a==null?{msg:"This is a required field.",classes:["red"]}:false};break;case "int":j=function(a,b){var c=$(b).data("opts");if(!$(b)[0].validity.valid){var h=[];"min"in c&&h.push(" greater than or equal to "+
c.min);"max"in c&&h.push(" smaller than or equal to "+c.max);return{msg:"Please enter an integer"+h.join(" and")+".",classes:["red"]}}};break;case "streamname":j=function(a,b){if(a!=""){if(!isNaN(a.charAt(0)))return{msg:"The first character may not be a number.",classes:["red"]};if(a.toLowerCase()!=a)return{msg:"Uppercase letters are not allowed.",classes:["red"]};if(a.replace(/[^\da-z_\-\.]/g,"")!=a)return{msg:"Special characters (except for underscores (_), periods (.) and dashes (-)) are not allowed.",
classes:["red"]};if("streams"in mist.data&&a in mist.data.streams&&$(b).data("pointer").main.name!=a)return{msg:"This streamname already exists.<br>If you want to edit an existing stream, please click edit on the the streams tab.",classes:["red"]}}};break;case "streamname_with_wildcard":j=function(a){if(a!=""){streampart=a.split("+");var b=streampart.slice(1).join("+");streampart=streampart[0];if(!isNaN(streampart.charAt(0)))return{msg:"The first character may not be a number.",classes:["red"]};if(streampart.toLowerCase()!=
streampart)return{msg:"Uppercase letters are not allowed in a stream name.",classes:["red"]};if(streampart.replace(/[^\da-z_]/g,"")!=streampart)return{msg:"Special characters (except for underscores) are not allowed in a stream name.",classes:["red"]};if(streampart!=a&&b.replace(/[\00|\0|\/]/g,"")!=b)return{msg:"Slashes or null bytes are not allowed in wildcards.",classes:["red"]}}};break;case "streamname_with_wildcard_and_variables":j=function(a){if(a!=""){streampart=a.split("+");var b=streampart.slice(1).join("+");
streampart=streampart[0];if(!isNaN(streampart.charAt(0)))return{msg:"The first character may not be a number.",classes:["red"]};if(streampart.toLowerCase()!=streampart)return{msg:"Uppercase letters are not allowed in a stream name.",classes:["red"]};if(streampart.replace(/[^\da-z_$]/g,"")!=streampart)return{msg:"Special characters (except for underscores) are not allowed in a stream name.",classes:["red"]};if(streampart!=a&&b.replace(/[\00|\0|\/]/g,"")!=b)return{msg:"Slashes or null bytes are not allowed in wildcards.",
classes:["red"]}}};break;case "track_selector_parameter":j=function(){};break;case "track_selector":j=function(){};break;default:j=function(){}}i.push(j)}e.data("validate_functions",i).data("help_container",f).data("validate",function(a,b){if($(a).is(":visible")||$(a).is('input[type="hidden"]')){var c=$(a).getval(),h=$(a).data("validate_functions"),d=$(a).data("help_container");d.find(".err_balloon").remove();for(var e in h){var g=h[e](c,a);if(g){$err=$("<span>").addClass("err_balloon").html(g.msg);
for(var f in g.classes)$err.addClass(g.classes[f]);d.prepend($err);b&&$(a).focus();return typeof g=="object"&&"break"in g?g["break"]:true}}return false}}).addClass("hasValidate").on("change keyup",function(){$(this).data("validate")($(this))});""!=e.getval()&&e.trigger("change")}"function"in c&&(e.on("change keyup",c["function"]),e.trigger("change"))}}b.on("keydown",function(a){var b=!1;switch(a.which){case 13:b=$(this).find("button.save").first();break;case 27:b=$(this).find("button.cancel").first()}b&&
b.length&&(b.trigger("click"),a.stopPropagation())});return b},buildVheaderTable:function(a){var b=$("<table>"),d=$("<tr>").addClass("header").append($("<td>").addClass("vheader").attr("rowspan",a.labels.length+1).append($("<span>").text(a.vheader))),c=[];d.append($("<td>"));for(var e in a.labels)c.push($("<tr>").append($("<td>").html(""==a.labels[e]?"&nbsp;":a.labels[e]+":")));for(var l in a.content)for(e in d.append($("<td>").html(a.content[l].header)),a.content[l].body)c[e].append($("<td>").html(a.content[l].body[e]));
b.append($("<tbody>").append(d).append(c));return b},plot:{addGraph:function(a,b){var d={id:a.id,xaxis:a.xaxis,datasets:[],elements:{cont:$("<div>").addClass("graph"),plot:$("<div>").addClass("plot"),legend:$("<div>").addClass("legend").attr("draggable","true")}};UI.draggable(d.elements.legend);d.elements.cont.append(d.elements.plot).append(d.elements.legend);b.append(d.elements.cont);return d},go:function(a){if(!(1>Object.keys(a).length)){var b={totals:[],clients:[]},d;for(d in a)for(var c in a[d].datasets){var e=
a[d].datasets[c];switch(e.datatype){case "clients":case "upbps":case "downbps":case "perc_lost":case "perc_retrans":switch(e.origin[0]){case "total":b.totals.push({fields:[e.datatype],end:-15});break;case "stream":b.totals.push({fields:[e.datatype],streams:[e.origin[1]],end:-15});break;case "protocol":b.totals.push({fields:[e.datatype],protocols:[e.origin[1]],end:-15})}break;case "cpuload":case "memload":b.capabilities={}}}0==b.totals.length&&delete b.totals;0==b.clients.length&&delete b.clients;
mist.send(function(){for(var b in a){var c=a[b];if(1>c.datasets.length){c.elements.plot.html("");c.elements.legend.html("");break}switch(c.xaxis){case "time":var d=[];c.yaxes={};var e=[],n;for(n in c.datasets){var j=c.datasets[n];j.display&&(j.getdata(),j.yaxistype in c.yaxes||(d.push(UI.plot.yaxes[j.yaxistype]),c.yaxes[j.yaxistype]=d.length),j.yaxis=c.yaxes[j.yaxistype],e.push(j))}d[0]&&(d[0].color=0);c.plot=$.plot(c.elements.plot,e,{legend:{show:!1},xaxis:UI.plot.xaxes[c.xaxis],yaxes:d,grid:{hoverable:!0,
borderWidth:{top:0,right:0,bottom:1,left:1},color:"black",backgroundColor:{colors:["rgba(0,0,0,0)","rgba(0,0,0,0.025)"]}},crosshair:{mode:"x"}});d=$("<table>").addClass("legend-list").addClass("nolay").html($("<tr>").html($("<td>").html($("<h3>").text(c.id))).append($("<td>").css("padding-right","2em").css("text-align","right").html($("<span>").addClass("value")).append($("<button>").data("opts",c).text("X").addClass("close").click(function(){var b=$(this).data("opts");if(confirm("Are you sure you want to remove "+
b.id+"?")){b.elements.cont.remove();var c=$(".graph_ids option:contains("+b.id+")"),d=c.parent();c.remove();UI.plot.del(b.id);delete a[b.id];d.trigger("change");UI.plot.go(a)}}))));c.elements.legend.html(d);var q=function(a){var b=c.elements.legend.find(".value"),d=1;if(typeof a=="undefined")b.eq(0).html("Latest:");else{var e=c.plot.getXAxes()[0],a=Math.min(e.max,a),a=Math.max(e.min,a);b.eq(0).html(UI.format.time(a/1E3))}for(var g in c.datasets){var f="&nbsp;";if(c.datasets[g].display){var e=UI.plot.yaxes[c.datasets[g].yaxistype].tickFormatter,
m=c.datasets[g].data;if(a)for(var q in m){if(m[q][0]==a){f=e(m[q][1]);break}if(m[q][0]>a){if(q!=0){f=m[q];m=m[q-1];f=e(f[1]+(a-f[0])*(m[1]-f[1])/(m[0]-f[0]))}break}}else f=e(c.datasets[g].data[c.datasets[g].data.length-1][1])}b.eq(d).html(f);d++}};c.plot.getOptions();for(n in c.datasets)e=$("<input>").attr("type","checkbox").data("index",n).data("graph",c).click(function(){var a=$(this).data("graph");$(this).is(":checked")?a.datasets[$(this).data("index")].display=true:a.datasets[$(this).data("index")].display=
false;var b={};b[a.id]=a;UI.plot.go(b)}),c.datasets[n].display&&e.attr("checked","checked"),d.append($("<tr>").html($("<td>").html($("<label>").html(e).append($("<div>").addClass("series-color").css("background-color",c.datasets[n].color)).append(c.datasets[n].label))).append($("<td>").css("padding-right","2em").css("text-align","right").html($("<span>").addClass("value")).append($("<button>").text("X").addClass("close").data("index",n).data("graph",c).click(function(){var b=$(this).data("index"),
c=$(this).data("graph");if(confirm("Are you sure you want to remove "+c.datasets[b].label+" from "+c.id+"?")){c.datasets.splice(b,1);if(c.datasets.length==0){c.elements.cont.remove();var b=$(".graph_ids option:contains("+c.id+")"),d=b.parent();b.remove();d.trigger("change");UI.plot.del(c.id);delete a[c.id];UI.plot.go(a)}else{UI.plot.save(c);b={};b[c.id]=c;UI.plot.go(b)}}}))));q();var g=!1;c.elements.plot.on("plothover",function(a,b,c){if(b.x!=g){q(b.x);g=b.x}if(c){a=$("<span>").append($("<h3>").text(c.series.label).prepend($("<div>").addClass("series-color").css("background-color",
c.series.color))).append($("<table>").addClass("nolay").html($("<tr>").html($("<td>").text("Time:")).append($("<td>").html(UI.format.dateTime(c.datapoint[0]/1E3,"long")))).append($("<tr>").html($("<td>").text("Value:")).append($("<td>").html(c.series.yaxis.tickFormatter(c.datapoint[1],c.series.yaxis)))));UI.tooltip.show(b,a.children())}else UI.tooltip.hide()}).on("mouseout",function(){q()})}}},b)}},save:function(a){var b={id:a.id,xaxis:a.xaxis,datasets:[]},d;for(d in a.datasets)b.datasets.push({origin:a.datasets[d].origin,
datatype:a.datasets[d].datatype});a=mist.stored.get().graphs||{};a[b.id]=b;mist.stored.set("graphs",a)},del:function(a){var b=mist.stored.get().graphs||{};delete b[a];mist.stored.set("graphs",b)},datatype:{getOptions:function(a){var b=$.extend(!0,{},UI.plot.datatype.templates.general),d=$.extend(!0,{},UI.plot.datatype.templates[a.datatype]),a=$.extend(!0,d,a),a=$.extend(!0,b,a);switch(a.origin[0]){case "total":switch(a.datatype){case "cpuload":case "memload":break;default:a.label+=" (total)"}break;
case "stream":case "protocol":a.label+=" ("+a.origin[1]+")"}var b=[],c;for(c in a.basecolor)d=a.basecolor[c],d+=50*(0.5-Math.random()),d=Math.round(d),d=Math.min(255,Math.max(0,d)),b.push(d);a.color="rgb("+b.join(",")+")";return a},templates:{general:{display:!0,datatype:"general",label:"",yaxistype:"amount",data:[],lines:{show:!0},points:{show:!1},getdata:function(){var a=mist.data.totals["stream"==this.origin[0]?this.origin[1]:"all_streams"]["protocol"==this.origin[0]?this.origin[1]:"all_protocols"][this.datatype];
return this.data=a}},cpuload:{label:"CPU use",yaxistype:"percentage",basecolor:[237,194,64],cores:1,getdata:function(){var a=!1,b;for(b in this.data)this.data[b][0]<1E3*(mist.data.config.time-600)&&(a=b);!1!==a&&this.data.splice(0,Number(a)+1);this.data.push([1E3*mist.data.config.time,mist.data.capabilities.cpu_use/10]);return this.data}},memload:{label:"Memory load",yaxistype:"percentage",basecolor:[175,216,248],getdata:function(){var a=!1,b;for(b in this.data)this.data[b][0]<1E3*(mist.data.config.time-
600)&&(a=b);!1!==a&&this.data.splice(0,Number(a)+1);this.data.push([1E3*mist.data.config.time,mist.data.capabilities.load.memory]);return this.data}},clients:{label:"Connections",basecolor:[203,75,75]},upbps:{label:"Bandwidth up",yaxistype:"bytespersec",basecolor:[77,167,77]},downbps:{label:"Bandwidth down",yaxistype:"bytespersec",basecolor:[148,64,237]},perc_lost:{label:"Lost packages",yaxistype:"percentage",basecolor:[255,33,234]},perc_retrans:{label:"Re-transmitted packages",yaxistype:"percentage",
basecolor:[0,0,255]}}},yaxes:{percentage:{name:"percentage",color:"black",tickColor:0,tickDecimals:0,tickFormatter:function(a){return UI.format.addUnit(UI.format.number(a),"%")},tickLength:0,min:0,max:100},amount:{name:"amount",color:"black",tickColor:0,tickDecimals:0,tickFormatter:function(a){return UI.format.number(a)},tickLength:0,min:0},bytespersec:{name:"bytespersec",color:"black",tickColor:0,tickDecimals:1,tickFormatter:function(a){return UI.format.bytes(a,!0)},tickLength:0,ticks:function(a){var b=
0.3*Math.sqrt($(".graph").first().height()),b=(a.max-a.min)/b,d=Math.floor(Math.log(Math.abs(b))/Math.log(1024)),c=b/Math.pow(1024,d),e=-Math.floor(Math.log(c)/Math.LN10),l=a.tickDecimals;null!=l&&e>l&&(e=l);var i=Math.pow(10,-e),c=c/i,f;if(1.5>c)f=1;else if(3>c){if(f=2,2.25<c&&(null==l||e+1<=l))f=2.5,++e}else f=7.5>c?5:10;f=f*i*Math.pow(1024,d);null!=a.minTickSize&&f<a.minTickSize&&(f=a.minTickSize);a.delta=b;a.tickDecimals=Math.max(0,null!=l?l:e);a.tickSize=f;b=[];d=a.tickSize*Math.floor(a.min/
a.tickSize);e=0;l=Number.NaN;do i=l,l=d+e*a.tickSize,b.push(l),++e;while(l<a.max&&l!=i);return b},min:0}},xaxes:{time:{name:"time",mode:"time",timezone:"browser",ticks:5}}},draggable:function(a){a.attr("draggable",!0);a.on("dragstart",function(a){$(this).css("opacity",0.4).data("dragstart",{click:{x:a.originalEvent.pageX,y:a.originalEvent.pageY},ele:{x:this.offsetLeft,y:this.offsetTop}})}).on("dragend",function(a){var d=$(this).data("dragstart"),c=d.ele.x-d.click.x+a.originalEvent.pageX,a=d.ele.y-
d.click.y+a.originalEvent.pageY;$(this).css({opacity:1,top:a,left:c,right:"auto",bottom:"auto"})});a.parent().on("dragleave",function(){})},format:{time:function(a,b){var d=new Date(1E3*a),c=[];c.push(("0"+d.getHours()).slice(-2));c.push(("0"+d.getMinutes()).slice(-2));"short"!=b&&c.push(("0"+d.getSeconds()).slice(-2));return c.join(":")},date:function(a,b){var d=new Date(1E3*a),c="Sun Mon Tue Wed Thu Fri Sat".split(" "),e=[];"long"==b&&e.push(c[d.getDay()]);e.push(("0"+d.getDate()).slice(-2));e.push("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ")[d.getMonth()]);
"short"!=b&&e.push(d.getFullYear());return e.join(" ")},dateTime:function(a,b){return UI.format.date(a,b)+", "+UI.format.time(a,b)},duration:function(a,b){var d=[0.001,1E3,60,60,24,1E99],c=["ms","sec","min","hr","day"],e={},l=!!(0>a),i=Math.abs(a),f;for(f in c){var i=Math.round(i/d[f]),m=i%d[Number(f)+1];e[c[f]]=m;i-=m}var n;for(f=c.length-1;0<=f;f--)if(0<e[c[f]]){n=c[f];break}d=$("<span>");switch(n){case "day":if(b){d.append(UI.format.addUnit(e.day,"days, ")).append(UI.format.addUnit(e.hr,"hrs"));
break}else d.append(UI.format.addUnit(e.day,"days, "));default:if(b)switch(n){case "hr":d.append(UI.format.addUnit(e.hr,"hrs, ")).append(UI.format.addUnit(e.min,"mins"));break;case "min":d.append(UI.format.addUnit(e.min,"mins, ")).append(UI.format.addUnit(e.sec,"s"));break;case "sec":e=Math.round(1E3*e.sec+e.ms)/1E3;d.append(UI.format.addUnit(e,"s"));break;case "ms":d.append(UI.format.addUnit(e.ms,"ms"))}else d.append([("0"+e.hr).slice(-2),("0"+e.min).slice(-2),("0"+e.sec).slice(-2)+(e.ms?"."+("00"+
e.ms).slice(-3):"")].join(":"))}return(l?"- ":"")+d[0].innerHTML},number:function(a){if(isNaN(Number(a))||0==a)return a;var b=Math.pow(10,3-Math.floor(Math.log(a)/Math.LN10)-1),a=Math.round(a*b)/b;if(1E4<=a){number=a.toString().split(".");for(a=/(\d+)(\d{3})/;a.test(number[0]);)number[0]=number[0].replace(a,"$1 $2");a=number.join(".")}return a},status:function(a){var b=$("<span>");if("undefined"==typeof a.online)return b.text("Unknown, checking.."),"undefined"!=typeof a.error&&b.text(a.error),b;switch(a.online){case -1:b.text("Enabling");
break;case 0:b.text("Unavailable").addClass("red");break;case 1:b.text("Active").addClass("green");break;case 2:b.text("Standby").addClass("orange");break;default:b.text(a.online)}"error"in a&&b.text(a.error);return b},capital:function(a){return a.charAt(0).toUpperCase()+a.substring(1)},addUnit:function(a,b){var d=$("<span>").html(a);d.append($("<span>").addClass("unit").html(b));return d[0].innerHTML},bytes:function(a,b){var d="bytes KiB MiB GiB TiB PiB".split(" ");if(0==a)unit=d[0];else{var c=Math.floor(Math.log(Math.abs(a))/
Math.log(1024));0>c?unit=d[0]:(a/=Math.pow(1024,c),unit=d[c])}return UI.format.addUnit(UI.format.number(a),unit+(b?"/s":""))},bits:function(a,b){var d="b Kib Mib Gib Tib Pib".split(" ");if(0==a)unit=d[0];else{var c=Math.floor(Math.log(Math.abs(a))/Math.log(1024));0>c?unit=d[0]:(a/=Math.pow(1024,c),unit=d[c])}return UI.format.addUnit(UI.format.number(a),unit+(b?"ps":""))}},navto:function(a,b){var d=location.hash,c=d.split("@");c[0]=[mist.user.name,mist.user.host].join("&");c[1]=[a,b].join("&");"undefined"!=
typeof screenlog&&screenlog.navto(c[1]);location.hash=c.join("@");location.hash==d&&$(window).trigger("hashchange")},showTab:function(a,b,d){var c=UI.elements.main;"undefined"==typeof d&&(d=[]);if(mist.user.loggedin){if(!("ui_settings"in mist.data)){c.html("Loading..");mist.send(function(){UI.showTab(a,b)},{ui_settings:!0});return}mist.data.config.serverid&&(document.title=mist.data.config.serverid+" - MistServer MI")}var e=UI.elements.menu.removeClass("hide").find('.plain:contains("'+a+'")').filter(function(){return $(this).text()===
a}).closest(".button");0<e.length&&(UI.elements.menu.find(".button.active").removeClass("active"),e.addClass("active"),$submenu=e.closest("[data-param]"),$submenu.length&&$submenu.attr("data-param",b));window.mv&&mv.reference&&mv.reference.unload();UI.interval.clear();UI.websockets.clear();c.attr("data-tab",a).html($("<h2>").text(a));switch(a){case "Login":if(mist.user.loggedin){UI.navto("Overview");return}document.title="MistServer MI";UI.elements.menu.addClass("hide");UI.elements.connection.status.text("Disconnected").removeClass("green").addClass("red");
c.append(UI.buildUI([{type:"help",help:"Please provide your account details.<br>You were asked to set these when MistController was started for the first time. If you did not yet set any account details, log in with your desired credentials to create a new account."},{label:"Host",help:"Url location of the MistServer API. Generally located at http://MistServerIP:4242/api","default":"http://localhost:4242/api",pointer:{main:mist.user,index:"host"}},{label:"Username",help:"Please enter your username here.",
validate:["required"],pointer:{main:mist.user,index:"name"}},{label:"Password",type:"password",help:"Please enter your password here.",validate:["required"],pointer:{main:mist.user,index:"rawpassword"}},{type:"buttons",buttons:[{label:"Login",type:"save","function":function(){mist.user.password=MD5(mist.user.rawpassword);delete mist.user.rawpassword;mist.send(function(){UI.navto("Overview")})}}]}]));break;case "Create a new account":UI.elements.menu.addClass("hide");c.append($("<p>").text("No account has been created yet in the MistServer at ").append($("<i>").text(mist.user.host)).append("."));
c.append(UI.buildUI([{type:"buttons",buttons:[{label:"Select other host",type:"cancel",css:{"float":"left"},"function":function(){UI.navto("Login")}}]},{type:"custom",custom:$("<br>")},{label:"Desired username",type:"str",validate:["required"],help:"Enter your desired username. In the future, you will need this to access the Management Interface.",pointer:{main:mist.user,index:"name"}},{label:"Desired password",type:"password",validate:["required",function(a,b){$(".match_password.field").not($(b)).trigger("change");
return false}],help:"Enter your desired password. In the future, you will need this to access the Management Interface.",pointer:{main:mist.user,index:"rawpassword"},classes:["match_password"]},{label:"Repeat password",type:"password",validate:["required",function(a,b){return a!=$(".match_password.field").not($(b)).val()?{msg:'The fields "Desired password" and "Repeat password" do not match.',classes:["red"]}:false}],help:"Repeat your desired password.",classes:["match_password"]},{type:"buttons",
buttons:[{type:"save",label:"Create new account","function":function(){mist.send(function(){UI.navto("Account created")},{authorize:{new_username:mist.user.name,new_password:mist.user.rawpassword}});mist.user.password=MD5(mist.user.rawpassword);delete mist.user.rawpassword}}]}]));break;case "Account created":UI.elements.menu.addClass("hide");c.append($("<p>").text("Your account has been created succesfully.")).append(UI.buildUI([{type:"text",text:"Would you like to enable all (currently) available protocols with their default settings?"},
{type:"buttons",buttons:[{label:"Enable protocols",type:"save","function":function(){if(mist.data.config.protocols)c.append("Unable to enable all protocols as protocol settings already exist.<br>");else{c.append("Retrieving available protocols..<br>");mist.send(function(a){var b=[],d;for(d in a.capabilities.connectors)if(a.capabilities.connectors[d].required)c.append('Could not enable protocol "'+d+'" because it has required settings.<br>');else{b.push({connector:d});c.append('Enabled protocol "'+
d+'".<br>')}c.append("Saving protocol settings..<br>");mist.send(function(){c.append("Protocols enabled. Redirecting..");setTimeout(function(){UI.navto("Overview")},5E3)},{config:{protocols:b}})},{capabilities:true})}}},{label:"Skip",type:"cancel","function":function(){UI.navto("Overview")}}]}]));break;case "Overview":if("undefined"==typeof mist.data.bandwidth){mist.send(function(){UI.navto(a)},{bandwidth:!0});c.append("Loading..");return}var l=$("<span>").text("Loading.."),i=$("<span>"),f=$("<span>").addClass("logs"),
m=$("<span>"),n=$("<span>"),j=$("<span>").text("Unknown"),q=$("<span>"),g=$("<span>"),h=parseURL(mist.user.host),h=h.protocol+h.host+h.port,k={};c.append(UI.buildUI([{type:"help",help:"You can find most basic information about your MistServer here.<br>You can also set the debug level and force a save to the config.json file that MistServer uses to save your settings. "},{type:"span",label:"Version",pointer:{main:mist.data.config,index:"version"}},{type:"span",label:"Version check",value:l},{type:"span",
label:"Server time",value:n},{type:"span",label:"Licensed to",value:"license"in mist.data.config?mist.data.config.license.user:""},{type:"span",label:"Active licenses",value:j},{type:"span",label:"Configured streams",value:mist.data.streams?Object.keys(mist.data.streams).length:0},{type:"span",label:"Active streams",value:i},{type:"span",label:"Current connections",value:m},{type:"span",label:"Enabled protocols",value:q},{type:"span",label:"Disabled protocols",value:g},{type:"span",label:"Recent problems",
value:f},$("<br>"),$("<h3>").text("Write config now"),{type:"help",help:"Tick the box in order to force an immediate save to the config.json MistServer uses to save your settings. Saving will otherwise happen upon closing MistServer. Don't forget to press save after ticking the box."},{type:"checkbox",label:"Force configurations save",pointer:{main:k,index:"save"}},{type:"buttons",buttons:[{type:"save",label:"Save","function":function(){var a={};if(k.save)a.save=k.save;delete k.save;mist.send(function(){UI.navto("Overview")},
a)}}]}]));if(mist.data.LTS){var o=function(a){function b(a){if(a.update){var d="";"progress"in a.update&&(d=" ("+a.update.progress+"%)");l.text("Updating.."+d);c(a.log);setTimeout(function(){mist.send(function(a){b(a)},{update:true})},1E3)}else UI.showTab("Overview")}function c(a){a=a.filter(function(a){return a[1]=="UPDR"});if(a.length){var b=$("<div>");l.append(b);for(var d in a)b.append($("<div>").text(a[d][2]))}}if(!a.update||!("uptodate"in a.update)){l.text("Unknown, checking..");setTimeout(function(){mist.send(function(a){"update"in
a&&o(a)},{checkupdate:true})},5E3)}else if(a.update.error)l.addClass("red").text(a.update.error);else if(a.update.uptodate)l.text("Your version is up to date.").addClass("green");else{if(a.update.progress){l.addClass("orange").removeClass("red").text("Updating..");b(a)}else{l.text("");l.append($("<span>").addClass("red").text("On "+(new Date(a.update.date)).toLocaleDateString()+" version "+a.update.version+" became available."));(!a.update.url||a.update.url.slice(-4)!=".zip")&&l.append($("<button>").text("Rolling update").css({"font-size":"1em",
"margin-left":"1em"}).click(function(){if(confirm("Are you sure you want to execute a rolling update?")){l.addClass("orange").removeClass("red").text("Rolling update command sent..");mist.send(function(a){b(a)},{autoupdate:true})}}));var d=$("<a>").attr("href",a.update.url).attr("target","_blank").text("Manual download");d[0].protocol="https:";l.append($("<div>").append(d))}c(a.log)}};o(mist.data);if("license"in mist.data.config){if("active_products"in mist.data.config.license&&Object.keys(mist.data.config.license.active_products).length){var s=
$("<table>").css("text-indent","0");j.html(s);s.append($("<tr>").append($("<th>").append("Product")).append($("<th>").append("Updates until")).append($("<th>").append("Use until")).append($("<th>").append("Max. simul. instances")));for(var p in mist.data.config.license.active_products)h=mist.data.config.license.active_products[p],s.append($("<tr>").append($("<td>").append(h.name)).append($("<td>").append(h.updates_final?h.updates_final:"&infin;")).append($("<td>").append(h.use_final?h.use_final:"&infin;")).append($("<td>").append(h.amount?
h.amount:"&infin;")))}else j.text("None. ");j.append($("<a>").text("More details").attr("href","https://shop.mistserver.org/myinvoices").attr("target","_blank"))}}else l.text("");p=function(){var a={totals:{fields:["clients"],start:-10},active_streams:true};if(!("capabilities"in mist.data))a.capabilities=true;mist.send(function(){ca()},a)};var ca=function(){i.text("active_streams"in mist.data?mist.data.active_streams?mist.data.active_streams.length:0:"?");if("totals"in mist.data&&"all_streams"in mist.data.totals)var a=
mist.data.totals.all_streams.all_protocols.clients,a=a.length?UI.format.number(a[a.length-1][1]):0;else a="Loading..";m.text(a);n.text(UI.format.dateTime(mist.data.config.time,"long"));f.html("");a=0;"license"in mist.data.config&&"user_msg"in mist.data.config.license&&mist.data.log.unshift([mist.data.config.license.time,"ERROR",mist.data.config.license.user_msg]);for(var b in mist.data.log){var c=mist.data.log[b];if(["FAIL","ERROR"].indexOf(c[1])>-1){a++;var d=$("<span>").addClass("content").addClass("red"),
h=c[2].split("|");for(b in h)d.append($("<span>").text(h[b]));f.append($("<div>").append($("<span>").append(UI.format.time(c[0]))).append(d));if(a==5)break}}a==0&&f.html("None.");a=[];c=[];for(b in mist.data.config.protocols){d=mist.data.config.protocols[b];a.indexOf(d.connector)>-1||a.push(d.connector)}q.text(a.length?a.join(", "):"None.");if("capabilities"in mist.data){for(b in mist.data.capabilities.connectors)a.indexOf(b)==-1&&c.push(b);g.text(c.length?c.join(", "):"None.")}else g.text("Loading..")};
p();ca();UI.interval.set(p,3E4);break;case "General":var G={serverid:mist.data.config.serverid,debug:mist.data.config.debug,accesslog:mist.data.config.accesslog,prometheus:mist.data.config.prometheus,defaultStream:mist.data.config.defaultStream,trustedproxy:mist.data.config.trustedproxy},H={sessionViewerMode:mist.data.config.sessionViewerMode,sessionInputMode:mist.data.config.sessionInputMode,sessionOutputMode:mist.data.config.sessionOutputMode,sessionUnspecifiedMode:mist.data.config.sessionUnspecifiedMode,
tknMode:mist.data.config.tknMode,sessionStreamInfoMode:mist.data.config.sessionStreamInfoMode},P={location:"location"in mist.data.config?mist.data.config.location:{}},x={limit:""};"bandwidth"in mist.data&&(x=mist.data.bandwidth,null==x&&(x={}),x.limit||(x.limit=""));var da=$("<select>").html($("<option>").val(1).text("bytes/s")).append($("<option>").val(1024).text("KiB/s")).append($("<option>").val(1048576).text("MiB/s")).append($("<option>").val(1073741824).text("GiB/s"));c.html(UI.buildUI([$("<h2>").text("General settings"),
{type:"help",help:"These are settings that apply to your MistServer instance in general."},{type:"str",label:"Human readable name",pointer:{main:G,index:"serverid"},help:"You can name your MistServer here for personal use. You'll still need to set host name within your network yourself."},{type:"debug",label:"Debug level",pointer:{main:G,index:"debug"},help:"You can set the amount of debug information MistServer saves in the log. A full reboot of MistServer is required before some components of MistServer can post debug information."},
{type:"selectinput",label:"Access log",selectinput:[["","Do not track"],["LOG","Log to MistServer log"],[{type:"str",label:"Path",LTSonly:!0},"Log to file"]],pointer:{main:G,index:"accesslog"},help:"Enable access logs.",LTSonly:!0},{type:"selectinput",label:"Prometheus stats output",selectinput:[["","Disabled"],[{type:"str",label:"Passphrase",LTSonly:!0},"Enabled"]],pointer:{main:G,index:"prometheus"},help:"Make stats available in Prometheus format. These can be accessed via "+h+"/PASSPHRASE or "+
h+"/PASSPHRASE.json.",LTSonly:!0},{type:"inputlist",label:"Trusted proxies",help:"List of proxy server addresses that are allowed to override the viewer IP address to arbitrary values.<br>You may use a hostname or IP address.",pointer:{main:G,index:"trustedproxy"}},{type:"str",validate:["streamname_with_wildcard_and_variables"],label:"Fallback stream",pointer:{main:G,index:"defaultStream"},help:"When this is set, if someone attempts to view a stream that does not exist, or is offline, they will be redirected to this stream instead. $stream may be used to refer to the original stream name.",
LTSonly:!0},{type:"buttons",buttons:[{type:"save",label:"Save","function":function(a){$(a).text("Saving..");mist.send(function(){UI.navto("General")},{config:G})}}]}]));c.append(UI.buildUI([$("<h3>").text("Sessions"),{type:"bitmask",label:"Bundle viewer sessions by",bitmask:[[8,"Stream name"],[4,"IP address"],[2,"Token"],[1,"Protocol"]],pointer:{main:H,index:"sessionViewerMode"},help:"Change the way viewer connections are bundled into sessions.<br>Default: stream name, viewer IP and token"},{type:"bitmask",
label:"Bundle input sessions by",bitmask:[[8,"Stream name"],[4,"IP address"],[2,"Token"],[1,"Protocol"]],pointer:{main:H,index:"sessionInputMode"},help:"Change the way input connections are bundled into sessions.<br>Default: stream name, input IP, token and protocol"},{type:"bitmask",label:"Bundle output sessions by",bitmask:[[8,"Stream name"],[4,"IP address"],[2,"Token"],[1,"Protocol"]],pointer:{main:H,index:"sessionOutputMode"},help:"Change the way output connections are bundled into sessions.<br>Default: stream name, output IP, token and protocol"},
{type:"bitmask",label:"Bundle unspecified sessions by",bitmask:[[8,"Stream name"],[4,"IP address"],[2,"Token"],[1,"Protocol"]],pointer:{main:H,index:"sessionUnspecifiedMode"},help:"Change the way unspecified connections are bundled into sessions.<br>Default: none"},{type:"select",label:"Treat HTTP-only sessions as",select:[[1,"A viewer session"],[2,"An output session: skip executing the USER_NEW and USER_END triggers"],[4,"A separate 'unspecified' session: skip executing the USER_NEW and USER_END triggers"],
[3,"Do not start a session: skip executing the USER_NEW and USER_END triggers and do not count for statistics"]],pointer:{main:H,index:"sessionStreamInfoMode"},help:"Change the way the stream info connection gets treated.<br>Default: as a viewer session"},{type:"bitmask",label:"Communicate session token",bitmask:[[8,"Write to cookie"],[4,"Write to URL parameter"],[2,"Read from cookie"],[1,"Read from URL parameter"]],pointer:{main:H,index:"tknMode"},help:"Change the way the session token gets passed to and from MistServer, which can be set as a cookie or URL parameter named `tkn`. Reading the session token as a URL parameter takes precedence over reading from the cookie.<br>Default: all"},
{type:"buttons",buttons:[{type:"save",label:"Save","function":function(a){$(a).text("Saving..");mist.send(function(){UI.navto("General")},{config:H})}}]}]));var S=$("<div>").html("Loading..");mist.send(function(a){if(a.variable_list){var b=$("<tbody>");S.html($("<table>").html($("<thead>").html($("<tr>").append($("<th>").text("Variable")).append($("<th>").text("Latest value")).append($("<th>").text("Command")).append($("<th>").text("Check interval")).append($("<th>").text("Last checked")).append($("<th>")))).append(b));
for(var c in a.variable_list){var d=a.variable_list[c];b.append($("<tr>").addClass("variable").attr("data-name",c).html($("<td>").text("$"+c)).append($("<td>").html($("<code>").text(typeof d=="string"?JSON.stringify(d):d[2]>0?JSON.stringify(d[3]):""))).append($("<td>").text(typeof d=="string"?"":d[0])).append($("<td>").html(typeof d=="string"?"Never":d[1]==0?"Once":UI.format.duration(d[1]))).append($("<td>").attr("title",d[2]>0?typeof d=="string"?"":"At "+UI.format.dateTime(new Date(d[2]),"long"):
"Not yet").html(typeof d=="string"?"":d[2]>0?UI.format.duration((new Date).getTime()*0.001-d[2])+" ago":"Not yet")).append($("<td>").html($("<button>").text("Edit").click(function(){var a=$(this).closest("tr").attr("data-name");UI.navto("Edit variable",a)})).append($("<button>").text("Remove").click(function(){var a=$(this).closest("tr").attr("data-name");confirm("Are you sure you want to remove the custom variable $"+a+"?")&&mist.send(function(){UI.showTab("General")},{variable_remove:a})}))))}}else S.html("None configured.")},
{variable_list:!0});c.append(UI.buildUI([$("<h3>").text("Custom variables"),{type:"help",help:"In certain places, like target URL's and pushes, variable substitution is applied in order to replace a $variable with their corresponding value. Here you can define your own constants and variables which will be used when variable substitution is applied. Variables can be used within variables but will not be reflected in their latest value on this page."},$("<div>").addClass("button_container").css("text-align",
"right").html($("<button>").text("New variable").click(function(){UI.navto("Edit variable","")})),S]));c.append(UI.buildUI([$("<h3>").text("Load balancer"),{type:"help",help:"If you're using MistServer's load balancer, the information below is passed to it so that it can make informed decisions."},{type:"selectinput",label:"Server's bandwidth limit",selectinput:[["","Default (1 gbps)"],[{label:"Custom",type:"int",min:0,unit:da},"Custom"]],pointer:{main:x,index:"limit"},help:"This is the amount of traffic this server is willing to handle."},
{type:"inputlist",label:"Bandwidth exceptions",pointer:{main:x,index:"exceptions"},help:"Data sent to the hosts and subnets listed here will not count towards reported bandwidth usage.<br>Examples:<ul><li>192.168.0.0/16</li><li>localhost</li><li>10.0.0.0/8</li><li>fe80::/16</li></ul>"},{type:"int",step:1E-8,label:"Server latitude",pointer:{main:P.location,index:"lat"},help:"This setting is only useful when MistServer is combined with a load balancer. When this is set, the balancer can send users to a server close to them."},
{type:"int",step:1E-8,label:"Server longitude",pointer:{main:P.location,index:"lon"},help:"This setting is only useful when MistServer is combined with a load balancer. When this is set, the balancer can send users to a server close to them."},{type:"str",label:"Server location name",pointer:{main:P.location,index:"name"},help:"This setting is only useful when MistServer is combined with a load balancer. This will be displayed as the server's location."},{type:"buttons",buttons:[{type:"save",label:"Save",
"function":function(a){$(a).text("Saving..");var a={config:P},b={};b.limit=x.limit?da.val()*x.limit:0;b.exceptions=x.exceptions;if(b.exceptions===null)b.exceptions=[];a.bandwidth=b;mist.send(function(){UI.navto("Overview")},a)}}]}]));var C=$("<div>").html("Loading..");c.append(UI.buildUI([$("<h3>").text("External writers"),{type:"help",help:"When pushing a stream to a target unsupported by MistServer like S3 storage, an external writer can be provided which handles writing the media data to the target location. The writer will receive data over stdin and MistServer will print any info written to stdout and stderr as log messages."},
$("<div>").addClass("button_container").css("text-align","right").html($("<button>").text("New external writer").click(function(){UI.navto("Edit external writer","")})),C]));mist.send(function(a){if(a.external_writer_list){var b=$("<tbody>");C.html($("<table>").html($("<thead>").html($("<tr>").append($("<th>").text("Name")).append($("<th>").text("Command line")).append($("<th>").text("URI protocols handled")).append($("<th>")))).append(b));for(var c in a.external_writer_list){var d=a.external_writer_list[c];
b.append($("<tr>").addClass("uploader").attr("data-name",c).html($("<td>").text(d[0])).append($("<td>").html($("<code>").html(d[1]))).append($("<td>").text(d[2]?d[2].join(", "):"none").addClass("desc")).append($("<td>").html($("<button>").text("Edit").click(function(){var a=$(this).closest("tr").attr("data-name");UI.navto("Edit external writer",a)})).append($("<button>").text("Remove").click(function(){var b=$(this).closest("tr").attr("data-name"),b=a.external_writer_list[b][0];confirm("Are you sure you want to remove the Uploader '"+
b+"'?")&&mist.send(function(){UI.showTab("General")},{external_writer_remove:b})}))))}}else G.html("None configured.")},{external_writer_list:!0});break;case "Edit external writer":var v=!1;""!=b&&(v=!0);var w=function(){v?c.html($("<h2>").text("Edit external writer '"+b+"'")):c.html($("<h2>").text("New external writer"));var a={};if(mist.data.external_writer_list&&b in mist.data.external_writer_list){var d=mist.data.external_writer_list[b];a.name=d[0];a.cmdline=d[1];a.protocols=d[2]}c.append(UI.buildUI([{type:"str",
b+"'?")&&mist.send(function(){UI.showTab("General")},{external_writer_remove:b})}))))}}else C.html("None configured.")},{external_writer_list:!0});break;case "Edit external writer":var u=!1;""!=b&&(u=!0);var D=function(){u?c.html($("<h2>").text("Edit external writer '"+b+"'")):c.html($("<h2>").text("New external writer"));var a={};if(mist.data.external_writer_list&&b in mist.data.external_writer_list){var d=mist.data.external_writer_list[b];a.name=d[0];a.cmdline=d[1];a.protocols=d[2]}c.append(UI.buildUI([{type:"str",
label:"Human readable name",help:"A human readable name for the external writer.",validate:["required"],pointer:{main:a,index:"name"}},{type:"str",label:"Command line",help:"Command line for a local command (with optional arguments) which will write media data to the target.",validate:["required"],pointer:{main:a,index:"cmdline"}},{type:"inputlist",label:"URI protocols handled",help:"URI protocols which the external writer will be handling.",validate:["required",function(a){for(var b in a){var c=
a[b];if(c.match(/^([a-z\d\+\-\.])+?$/)===null)return{classes:["red"],msg:"There was a problem with the protocol URI '"+$("<div>").text(c).html()+"':<br>A protocol URI may only contain lower case letters, digits, and the following special characters . + and -"}}}],input:{type:"str",unit:"://"},pointer:{main:a,index:"protocols"}},{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("General")}},{type:"save",label:"Save","function":function(){var c={external_writer_add:a},
d=null;b!=""&&b in mist.data.external_writer_list&&(d=mist.data.external_writer_list[b][0]);if(d!==null&&a.name!=d)c.external_writer_remove=d;mist.send(function(){UI.navto("General")},c)}}]}]))};"external_writer_list"in mist.data?w():mist.send(function(){w()},{external_writer_list:!0});break;case "Edit variable":v=!1;""!=b&&(v=!0);var P=function(a,d){v?c.html($("<h2>").text('Edit Variable "$'+b+'"')):c.html($("<h2>").text("New Variable"));var e=$("<div>");c.append(UI.buildUI([{type:"str",maxlength:31,
d=null;b!=""&&b in mist.data.external_writer_list&&(d=mist.data.external_writer_list[b][0]);if(d!==null&&a.name!=d)c.external_writer_remove=d;mist.send(function(){UI.navto("General")},c)}}]}]))};"external_writer_list"in mist.data?D():mist.send(function(){D()},{external_writer_list:!0});break;case "Edit variable":u=!1;""!=b&&(u=!0);var v=function(a,d){u?c.html($("<h2>").text('Edit Variable "$'+b+'"')):c.html($("<h2>").text("New Variable"));var h=$("<div>");c.append(UI.buildUI([{type:"str",maxlength:31,
label:"Variable name",prefix:"$",help:"What should the variable be called? A dollar sign will automatically be prepended.",pointer:{main:a,index:"name"},validate:["required",function(a){if(a.length&&a[0]=="$")return{msg:"The dollar sign will automatically be prepended. You don't need to type it here.",classes:["red"]};if(a.indexOf("{")!==-1||a.indexOf("}")!==-1||a.indexOf("$")!==-1)return{msg:'The following symbols are not permitted: "$ { }".',classes:["red"]}}]},{type:"select",label:"Type",help:"What kind of variable is this? It can either be a static value that you can enter below, or a dynamic one that is returned by a command.",
select:[["value","Static value"],["command","Dynamic through command"]],value:"value",pointer:{main:d,index:"type"},"function":function(){var a=[$("Invalid variable type")];switch($(this).val()){case "value":a=[{type:"str",label:"Value",pointer:{main:d,index:"value"},help:"The static value that this variable should be replaced with. There is a character limit of 63 characters.",validate:["required"]}];break;case "command":a=[{type:"str",label:"Command",help:"The command that should be executed to retrieve the value for this variable.<br>For example:<br><code>/usr/bin/date +%A</code><br>There is a character limit of 511 characters.",
validate:["required"],pointer:{main:d,index:"target"}},{type:"int",min:0,max:4294967295,"default":0,label:"Checking interval",unit:"s",help:"At what interval, in seconds, MistServer should execute the command and update the value.<br>To execute the command once when MistServer starts up (and then never update), set the interval to 0.",pointer:{main:d,index:"interval"}},{type:"int",min:0,max:4294967295,"default":1,label:"Wait time",unit:"s",help:"Specifies the maximum time, in seconds, MistServer should wait for data when executing the variable target. If set to 0 this variable takes on the same value as the interval.<br>MistServer only updates one variable at a time, so setting this value too high can block other variables from updating.",
pointer:{main:d,index:"waitTime"}}]}e.html(UI.buildUI(a))}},e,{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("General")}},{type:"save",label:"Save","function":function(){var c={variable_add:a};switch(d.type){case "value":a.value=d.value;break;case "command":a.target=d.target;a.interval=d.interval;a.waitTime=d.waitTime}if(a.name!=b)c.variable_remove=b;mist.send(function(){UI.navto("General")},c)}}]}]))};c.html("Loading..");v?mist.send(function(a){if(b in a.variable_list){a=
a.variable_list[b];P({name:b},typeof a=="string"?{value:a,type:"value"}:{target:a[0],interval:a[1],waitTime:a[4],type:"command"})}else c.append('Variable "$'+b+'" does not exist.')},{variable_list:!0}):P({},{});break;case "Protocols":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a)},{capabilities:!0});c.append("Loading..");return}var C=$("<tbody>");c.append(UI.buildUI([{type:"help",help:"You can find an overview of all the protocols and their relevant information here. You can add, edit or delete protocols."}])).append($("<button>").text("Delete all protocols").click(function(){if(confirm("Are you sure you want to delete all currently configured protocols?")){mist.data.config.protocols=
pointer:{main:d,index:"waitTime"}}]}h.html(UI.buildUI(a))}},h,{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("General")}},{type:"save",label:"Save","function":function(){var c={variable_add:a};switch(d.type){case "value":a.value=d.value;break;case "command":a.target=d.target;a.interval=d.interval;a.waitTime=d.waitTime}if(a.name!=b)c.variable_remove=b;mist.send(function(){UI.navto("General")},c)}}]}]))};c.html("Loading..");u?mist.send(function(a){if(b in a.variable_list){a=
a.variable_list[b];v({name:b},typeof a=="string"?{value:a,type:"value"}:{target:a[0],interval:a[1],waitTime:a[4],type:"command"})}else c.append('Variable "$'+b+'" does not exist.')},{variable_list:!0}):v({},{});break;case "Protocols":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a)},{capabilities:!0});c.append("Loading..");return}var A=$("<tbody>");c.append(UI.buildUI([{type:"help",help:"You can find an overview of all the protocols and their relevant information here. You can add, edit or delete protocols."}])).append($("<button>").text("Delete all protocols").click(function(){if(confirm("Are you sure you want to delete all currently configured protocols?")){mist.data.config.protocols=
[];mist.send(function(){UI.navto("Protocols")},{config:mist.data.config})}})).append($("<button>").text("Enable default protocols").click(function(){var a=Object.keys(mist.data.capabilities.connectors),b;for(b in mist.data.config.protocols){var c=a.indexOf(mist.data.config.protocols[b].connector);c>-1&&a.splice(c,1)}var d=[];for(b in a)(!("required"in mist.data.capabilities.connectors[a[b]])||Object.keys(mist.data.capabilities.connectors[a[b]].required).length==0)&&d.push(a[b]);c="Click OK to enable disabled protocols with their default settings:\n ";
c=d.length?c+d.join(", "):c+"None.";if(d.length!=a.length){a=a.filter(function(a){return d.indexOf(a)<0});c=c+("\n\nThe following protocols can only be set manually:\n "+a.join(", "))}if(confirm(c)&&d.length){if(mist.data.config.protocols===null)mist.data.config.protocols=[];for(b in d)mist.data.config.protocols.push({connector:d[b]});mist.send(function(){UI.navto("Protocols")},{config:mist.data.config})}})).append("<br>").append($("<button>").text("New protocol").click(function(){UI.navto("Edit Protocol")}).css("clear",
"both")).append($("<table>").html($("<thead>").addClass("sticky").html($("<tr>").html($("<th>").text("Protocol")).append($("<th>").text("Status")).append($("<th>").text("Settings")).append($("<th>")))).append(C));var ia=function(){function a(b){var c=mist.data.capabilities.connectors[b.connector];if(!c)return"";var d=[],e=["required","optional"],g;for(g in e)for(var f in c[e[g]])b[f]&&b[f]!=""?d.push(f+": "+b[f]):c[e[g]][f]["default"]&&d.push(f+": "+c[e[g]][f]["default"]);return $("<span>").addClass("description").text(d.join(", "))}
C.html("");for(var b in mist.data.config.protocols){var c=mist.data.config.protocols[b],d=mist.data.capabilities.connectors[c.connector];C.append($("<tr>").data("index",b).append($("<td>").text(d&&d.friendly?d.friendly:c.connector)).append($("<td>").html(UI.format.status(c))).append($("<td>").html(a(c))).append($("<td>").css("text-align","right").html($("<button>").text("Edit").click(function(){UI.navto("Edit Protocol",$(this).closest("tr").data("index"))})).append($("<button>").text("Delete").click(function(){var a=
$(this).closest("tr").data("index");if(confirm('Are you sure you want to delete the protocol "'+mist.data.config.protocols[a].connector+'"?')){mist.send(function(){UI.navto("Protocols")},{deleteprotocol:mist.data.config.protocols[a]});mist.data.config.protocols.splice(a,1)}}))))}};ia();UI.interval.set(function(){mist.send(function(){ia()})},1E4);break;case "Edit Protocol":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a,b)},{capabilities:!0});c.append("Loading..");return}v=
!1;""!=b&&0<=b&&(v=!0);var Q={};for(p in mist.data.config.protocols)Q[mist.data.config.protocols[p].connector]=1;var ja=function(a){var b=mist.data.capabilities.connectors[a],c=mist.convertBuildOptions(b,r);if(v)var d=$.extend({},r);c.push({type:"hidden",pointer:{main:r,index:"connector"},value:a});c.push({type:"buttons",buttons:[{type:"save",label:"Save","function":function(){var a={};v?a.updateprotocol=[d,r]:a.addprotocol=r;mist.send(function(){UI.navto("Protocols")},a)}},{type:"cancel",label:"Cancel",
"function":function(){UI.navto("Protocols")}}]});if("deps"in b&&b.deps!=""){u=$("<span>").text("Dependencies:");$ul=$("<ul>");u.append($ul);if(typeof b.deps=="string")b.deps=b.deps.split(", ");for(var e in b.deps){a=$("<li>").text(b.deps[e]+" ");$ul.append(a);typeof Q[b.deps[e]]!="undefined"||typeof Q[b.deps[e]+".exe"]!="undefined"?a.append($("<span>").addClass("green").text("(Configured)")):a.append($("<span>").addClass("red").text("(Not yet configured)"))}c.unshift({type:"text",text:u[0].innerHTML})}return UI.buildUI(c)},
Q={};for(p in mist.data.config.protocols)Q[mist.data.config.protocols[p].connector]=1;if(v)r=p=mist.data.config.protocols[b],c.find("h2").append(' "'+p.connector+'"'),c.append(ja(p.connector));else{c.html($("<h2>").text("New Protocol"));var r={},d=[["",""]];for(p in mist.data.capabilities.connectors)d.push([p,mist.data.capabilities.connectors[p].friendly?mist.data.capabilities.connectors[p].friendly:p]);var ka=$("<span>");c.append(UI.buildUI([{label:"Protocol",type:"select",select:d,"function":function(){$(this).getval()!=
""&&ka.html(ja($(this).getval()))}}])).append(ka)}break;case "Streams":if(!("capabilities"in mist.data)){c.html("Loading..");mist.send(function(){UI.navto(a,b)},{capabilities:!0});return}var s=mist.stored.get(),z={by:name,dir:1};""==b&&"viewmode"in s&&(b=s.viewmode);"sortstreams"in s&&(z=s.sortstreams);"streams_pagesize"in s&&(k=s.streams_pagesize);var x,s=UI.buildUI([{type:"help",help:"This is an overview of the streams you've currently configured.<br>You can left click a stream to "+("thumbnails"==
b?"edit":"preview")+" it"+("thumbnails"==b?", or its thumbnail to preview it":"")+". You can right click a stream for an action menu."},$("<div>").css({width:"45.25em",display:"flex","justify-content":"flex-end"}).append($("<button>").text("Switch to "+("thumbnails"==b?"list":"thumbnail")+" view").click(function(){mist.stored.set("viewmode",b=="thumbnails"?"list":"thumbnails");UI.navto("Streams",b=="thumbnails"?"list":"thumbnails")})).append($("<button>").text("Create a new stream").click(function(){UI.navto("Edit")})),
{label:"Filter streams",help:"Stream names that do not contain the text you enter here will be hidden.","function":function(){var a=$(this).getval();x&&x.filter(a)},css:{"margin-top":"3em"}}]);c.append(s);var t=$.extend({},mist.data.streams);if("thumbnails"==b){x=UI.dynamic({create:function(){var a=document.createElement("div");a.className="streams thumbnails";UI.sortableItems(a,function(a){return this.sortValues[a]},false);return a},values:t,add:{create:function(a){var b=document.createElement("div");
b.className="stream";b.setAttribute("data-id",a);var c=["thumbnail","actions"];b.elements={};b.elements.header=document.createElement("a");b.elements.header.className="header";b.appendChild(b.elements.header);for(var d in c){var e=c[d];b.elements[e]=document.createElement("div");b.elements[e].className=e;b.elements[e].raw=false;b.appendChild(b.elements[e])}if(a.indexOf("+")>=0){b.setAttribute("data-iswildcardstream","yes");c=document.createElement("span");c.className="wildparent";d=a.split("+");c.appendChild(document.createTextNode(d.shift()+
"+"));b.elements.header.appendChild(c);b.elements.header.appendChild(document.createTextNode(d.join("+")))}else{b.setAttribute("data-iswildcardstream","no");b.elements.header.innerText=a}b.elements.header.addEventListener("click",function(){UI.navto("Edit",a)});b.elements.thumbnail.addEventListener("click",function(){t[a].isfolderstream?t[a].filesfound?UI.navto("Edit",a):UI.findFolderSubstreams(t[a],function(c){$.extend(t,c);x.update(t);t[a].filesfound=true;b.setAttribute("data-showingsubstreams",
"yes");b.setAttribute("title","This is a folder stream: it points to a folder with media files inside.")}):UI.navto("Preview",a)});b.elements.actions.appendChild($("<button>").text("Actions").click(function(b){var c=$(this).offset();I.fill(a,{pageX:c.left,pageY:c.top});b.stopPropagation()})[0]);b.insertBefore(UI.modules.stream.status(a,{thumbnail:false,tags:"readonly"})[0],b.children[1]);b.remove=function(){this.parentNode&&this.parentNode.removeChild(this)};b.addEventListener("contextmenu",function(b){b.preventDefault();
I.fill(a,b)});return b},update:function(a){if(a.online==1&&a.online!=this.elements.thumbnail.raw){var b=UI.modules.stream.thumbnail(a.name,{clone:true});this.elements.thumbnail.appendChild(b[0]);this.elements.thumbnail.raw=a.online}if(a.source!=this.raw_source){this.raw_source=a.source;b=UI.findInput("Folder");this.setAttribute("title",a.source);if(b)if(mist.inputMatch(b.source_match,a.source)){this.setAttribute("data-isfolderstream","yes");a.isfolderstream=true;this.setAttribute("title","This is a folder stream: it points to a folder with media files inside. Click to request its sub streams.")}else{this.setAttribute("data-isfolderstream",
"no");this.setAttribute("title",a.source);a.isfolderstream=false}}b=[0,1,2,3,5,4,0];this.sortValues={name:a.name,state:a.stats&&a.stats.length>=2?b.length>a.stats[1]?b[a.stats[1]]:0:0,viewers:a.stats&&a.stats.length>=3?a.stats[2]:0,inputs:a.stats&&a.stats.length>=4?a.stats[3]:0,outputs:a.stats&&a.stats.length>=5?a.stats[4]:0}}},update:function(){this.sort();this.show_page&&this.show_page()}});c.append(x);var J=z.by,V={name:1,viewers:-1,state:-1,inputs:-1,outputs:-1},R=V[J]*z.dir;s.append(UI.buildUI([{label:"Sort streams by",
help:"Choose by which attribute the streams listed below should be sorted",type:"select",select:[["name","Stream name"],["state","State (Online, offline, waiting etc.)"],["viewers","Viewers"],["inputs","Inputs"],["outputs","Outputs"]],value:z.by,"function":function(){J=$(this).getval();z.by=J;mist.stored.set("sortstreams",z);x&&x.sort(J,V[J]*R)},unit:$("<label>").append($("<input>").attr("type","checkbox").prop("checked",-1==R).change(function(){R=$(this).is(":checked")?-1:1;z.dir=R*V[J];mist.stored.set("sortstreams",
z);x&&x.sort(J,V[J]*R)})).append($("<span>").text("Reverse"))}]).children())}else{var E=$("<table>").addClass("streams");c.append(E);E.layout={name:function(a,b){if(b!=this.raw){this.raw=b;var c=this,d=$("<a>").text(a.name).click(function(){$(c).attr("data-iswildcard")=="no"&&$(c).attr("data-isfolderstream")=="yes"?UI.navto("Edit",b):UI.navto("Preview",b)});if(b.indexOf("+")>=0){var e=b.split("+"),g=e.shift(),e=e.join("+");$(this).attr("data-iswildcard",g+"+");d.attr("title","This is a wildcard stream: its config is inherited from its parent: '"+
g+"'.").html($("<span>").addClass("wildparent").text(g+"+")).append(e)}else $(this).attr("data-iswildcard","no");$(this).html(d)}if(a.source!=this.raw_src){this.raw_src=a.source;if(mist.data.capabilities)if(d=UI.findInput("Folder"))if(mist.inputMatch(d.source_match,a.source)){$(this).attr("data-isfolderstream","yes").attr("title","This is a folder stream: it points to a folder with media files inside. Click the '\u2795' to request its sub streams.");a.isfolderstream=true}else{$(this).attr("data-isfolderstream",
"no").attr("title",a.source);a.isfolderstream=false}}},actions:function(a,b){if(!this.raw){$(this).html($("<button>").text("Actions").click(function(a){var c=$(this).offset();I.fill(b,{pageX:c.left,pageY:c.top});a.stopPropagation()}));this.raw=true}},state:function(a){var b=$("<div>").attr("data-streamstatus",0).text("Inactive");if("stats"in a){if(this.raw==a.stats[1])return;b=$("<div>").attr("data-streamstatus",a.stats[1]).text(["Offline","Initializing","Booting","Waiting for data","Available","Shutting down",
"Invalid state"][a.stats[1]]);this.raw=a.stats[1]}$(this).html(b).addClass("activestream")},viewers:function(a){var b="";if("stats"in a){if(this.raw==a.stats[2])return;b=a.stats[2];this.raw=a.stats[2]}$(this).html(b)},inputs:function(a){var b="";if("stats"in a){if(this.raw==a.stats[3])return;b=a.stats[3];this.raw=a.stats[3]}$(this).html(b)},outputs:function(a){var b="";if("stats"in a){if(this.raw==a.stats[4])return;b=a.stats[4];this.raw=a.stats[4]}$(this).html(b)}};var Y=$("<tr>").attr("data-sortby",
"name");E.append($("<thead>").addClass("sticky").append(Y));s={name:"Stream name",actions:""};for(p in E.layout)g=p in s?s[p]:UI.format.capital(p),d=$("<th>").text(g),""!=g&&d.attr("data-index",p).click(function(){var a=$(this).attr("data-index");if(z.by==a)z.dir=z.dir*-1;else{z.by=a;z.dir=1}mist.stored.set("sortstreams",z);x.sort($(this).attr("data-index"))}),Y.append(d);x=UI.dynamic({create:function(){var a=document.createElement("tbody");UI.sortableItems(a,function(a){return this._cells[a].raw},
Y[0]);a.remove=function(){this.parentNode&&this.parentNode.removeChild(this)};return a},values:t,add:{create:function(a){var b=document.createElement("tr");b.setAttribute("data-id",a);b._cells={};for(var c in E.layout){var d=document.createElement("td");b._cells[c]=d;b.append(d)}b.addEventListener("contextmenu",function(b){b.preventDefault();I.fill(a,b)});b.addEventListener("click",function(){if(t[a].isfolderstream&&!("filesfound"in t[a])){UI.findFolderSubstreams(t[a],function(a){$.extend(t,a);x.update(t);
b.setAttribute("data-showingsubstreams","")});x.show_page(this)}});b.remove=function(){this.parentNode&&this.parentNode.removeChild(this)};return b},update:function(a){for(var b in E.layout)E.layout[b].call(this._cells[b],a,this._id)}},update:function(){this.sort();this.show_page&&this.show_page()}});E.append(x)}x.filter=function(a){for(var a=a.toLowerCase(),b=0;b<this.children.length;b++){var c=this.children[b];c.getAttribute("data-id").toLowerCase().indexOf(a)>=0?c.classList.remove("hidden"):c.classList.add("hidden")}x.show_page()};
var I=new UI.context_menu;c.append(I.ele);I.fill=function(a,b){var c=[$("<div>").addClass("header").text(a)],d=[["<span>Edit "+(a.indexOf("+")<0?"stream":"<b>"+a.split("+")[0]+"</b>")+"</span>",function(){UI.navto("Edit",a)},"Edit","Change the settings of this stream."],["Stream status",function(){UI.navto("Status",a)},"Status","See more details about the status of this stream."],["Preview stream",function(){UI.navto("Preview",a)},"Preview","Watch the stream."],["Embed stream",function(){UI.navto("Embed",
a)},"Embed","Get urls to this stream or get code to embed it on your website."]],e=[["Delete stream",function(){if(confirm('Are you sure you want to delete the stream "'+a+'"?')){delete mist.data.streams[a];mist.send(function(){delete t[a];x.update(t)},{deletestream:[a]})}},"trash","Remove this stream's settings."],["Stop sessions",function(){confirm("Are you sure you want to disconnect all sessions (viewers, pushes and possibly the input) for the stream '"+a+"'?")&&mist.send(function(){},{stop_sessions:a})},
"stop","Disconnect sessions for this stream. Disconnecting a session will kill any currently open connections (viewers, pushes and possibly the input). If the USER_NEW trigger is in use, it will be triggered again by any reconnecting connections."],["Invalidate sessions",function(){confirm("Are you sure you want to invalidate all sessions for the stream '"+a+"'?\nThis will re-trigger the USER_NEW trigger.")&&mist.send(function(){},{invalidate_sessions:a})},"invalidate","Invalidate all the currently active sessions for this stream. This has the effect of re-triggering the USER_NEW trigger, allowing you to selectively close some of the existing connections after they have been previously allowed. If you don't have a USER_NEW trigger configured, this will not have any effect."],
["Nuke stream",function(){confirm("Are you sure you want to completely shut down the stream '"+a+"'?\nAll viewers will be disconnected.")&&mist.send(function(){},{nuke_stream:a})},"nuke","Shut down a running stream completely and/or clean up any potentially left over stream data in memory. It attempts a clean shutdown of the running stream first, followed by a forced shut down, and then follows up by checking for left over data in memory and cleaning that up if any is found."]];if(t[a].isfolderstream){d.pop();
d.pop();e=[e[0]]}c=[c];t[a].isfolderstream&&!t[a].filesfound&&c.push([["Scan folder for sub streams",function(){UI.findFolderSubstreams(t[a],function(a){$.extend(t,a);x.update(t)})},"folder"]]);c.push(d);c.push(e);t[a].online==1&&c.push($("<aside>").append(UI.modules.stream.thumbnail(a)));I.show(c,b);I.ele.find("[tabindex]").first().focus()};UI.sockets.ws.active_streams.subscribe(function(a,b){if(a=="stream"){var c=b[0],d=c.split("+")[0];if(d in mist.data.streams){if(d!=c&&!(c in t)){t[c]=$.extend({},
mist.data.streams[d]);t[c].name=c;if(t[d].isfolderstream)t[c].source=t[c].source+c.replace(d+"+")}t[c].stats=b;x.update(t)}else c in t?t[c].stats=b:console.log("Received information about unknown stream",c,b)}});p=UI.pagecontrol(x,k);c.append(p);p.elements.pagelength.change(function(){mist.stored.set("streams_pagesize",$(this).val())});break;case "Edit":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a,b)},{capabilities:!0});c.append("Loading..");return}v=!1;""!=b&&(v=
!0);v?(k=b.split("+")[0],r=mist.data.streams[k],c.html(UI.modules.stream.header(b,a,k)),k!=b&&c.append($("<div>").addClass("err_balloon").addClass("orange").css({position:"static",width:"54.65em",margin:"2em 0 3em"}).html("Note:<br>You are editing the settings of <b>"+k+"</b>, which is the parent of wildcard stream <b>"+b+"</b>. This will also affect other children of <b>"+k+"</b>."))):(c.html($("<h2>").text("New Stream")),r={});var k=[],g=$("<datalist>").attr("id","source_datalist"),N=$("<div>").addClass("source_info"),
Z=!1,S=!1;for(p in mist.data.capabilities.inputs)for(s in mist.data.capabilities.inputs[p].source_match)k.push(mist.data.capabilities.inputs[p].source_match[s]),g.append($("<option>").val(mist.data.capabilities.inputs[p].source_match[s]));var W=$("<div>"),la=function(a){var c={};if(!mist.data.streams)mist.data.streams={};mist.data.streams[r.name]=r;b!=r.name&&delete mist.data.streams[b];c.addstream={};c.addstream[r.name]=r;if(b!=r.name)c.deletestream=[b];if(r.stop_sessions&&b!=""){c.stop_sessions=
b;delete r.stop_sessions}var d=null,e;for(e in mist.data.capabilities.inputs)if(typeof mist.data.capabilities.inputs[e].source_match!="undefined"&&mist.inputMatch(mist.data.capabilities.inputs[e].source_match,r.source)){d=e;break}if(d){d=mist.data.capabilities.inputs[d];for(e in r)e=="name"||e=="source"||e=="stop_sessions"||e=="processes"||"optional"in d&&e in d.optional||"required"in d&&e in d.required||e=="always_on"&&"always_match"in d&&mist.inputMatch(d.always_match,r.source)||delete r[e]}mist.send(function(){delete mist.data.streams[r.name].online;
delete mist.data.streams[r.name].error;UI.navto(a,a=="Preview"?b.indexOf("+")<0?r.name:b:"")},c)},ma=$("<style>").text("button.saveandpreview { display: none; }"),O=$("<span>"),s=$("<div>"),aa={},d=[],na=$("<div>");for(p in mist.data.capabilities.processes)d.push([p,mist.data.capabilities.processes[p].hrn?mist.data.capabilities.processes[p].hrn:mist.data.capabilities.processes[p].name]);d.length&&(p=[{label:"New process",type:"select",select:d,value:d[0][0],pointer:{main:aa,index:"process"},"function":function(){var a=
$(this).getval();if(a!=null){var a=mist.data.capabilities.processes[a],b=[$("<h4>").text(a.name+" Process options")];na.html(UI.buildUI(b.concat(mist.convertBuildOptions(a,aa))))}}},na],s.append(UI.buildUI([$("<br>"),$("<h3>").text("Stream processes"),{label:"Stream processes",itemLabel:"stream process",type:"sublist",sublist:p,saveas:aa,pointer:{main:r,index:"processes"}}])));s=UI.buildUI([{label:"Stream name",type:"str",validate:["required","streamname"],pointer:{main:r,index:"name"},help:"Set the name this stream will be recognised by for players and/or stream pushing."},
{label:"Source",type:"browse",filetypes:k,pointer:{main:r,index:"source"},help:"<p> Below is the explanation of the input methods for MistServer. Anything between brackets () will go to default settings if not specified. </p> <table class=valigntop> <tr> <th colspan=3><b>File inputs</b></th> </tr> <tr> <th>File</th> <td> Linux/MacOS:&nbsp;/PATH/FILE<br> Windows:&nbsp;/cygdrive/DRIVE/PATH/FILE </td> <td> For file input please specify the proper path and file.<br> Supported inputs are: DTSC, FLV, MP3. MistServer Pro has TS, MP4, ISMV added as input. </td> </tr> <th> Folder </th> <td> Linux/MacOS:&nbsp;/PATH/<br> Windows:&nbsp;/cygdrive/DRIVE/PATH/ </td> <td> A folder stream makes all the recognised files in the selected folder available as a stream. </td> </tr> <tr><td colspan=3>&nbsp;</td></tr> <tr> <th colspan=3><b>Push inputs</b></th> </tr> <tr> <th>RTMP</th> <td>push://(IP)(@PASSWORD)</td> <td> IP is white listed IP for pushing towards MistServer, if left empty all are white listed.<br> PASSWORD is the application under which to push to MistServer, if it doesn't match the stream will be rejected. PASSWORD is MistServer Pro only. </td> </tr> <tr> <th>SRT</th> <td>push://(IP)</td> <td> IP is white listed IP for pushing towards MistServer, if left empty all are white listed.<br> </td> </tr> <tr> <th>RTSP</th> <td>push://(IP)(@PASSWORD)</td> <td>IP is white listed IP for pushing towards MistServer, if left empty all are white listed.</td> </tr> <tr> <th>TS</th> <td>tsudp://(IP):PORT(/INTERFACE)</td> <td> IP is the IP address used to listen for this stream, multi-cast IP range is: 224.0.0.0 - 239.255.255.255. If IP is not set all addresses will listened to.<br> PORT is the port you reserve for this stream on the chosen IP.<br> INTERFACE is the interface used, if left all interfaces will be used. </td> </tr> <tr><td colspan=3>&nbsp;</td></tr> <tr> <th colspan=3><b>Pull inputs</b></th> </tr> <tr> <th>DTSC</th> <td>dtsc://MISTSERVER_IP:PORT/(STREAMNAME)</td> <td>MISTSERVER_IP is the IP of another MistServer to pull from.<br> PORT is the DTSC port of the other MistServer. (default is 4200)<br> STREAMNAME is the name of the target stream on the other MistServer. If left empty, the name of this stream will be used. </td> </tr> <tr> <th>HLS</th> <td>http://URL/TO/STREAM.m3u8</td> <td>The URL where the HLS stream is available to MistServer.</td> </tr> <tr> <th>RTSP</th> <td>rtsp://(USER:PASSWORD@)IP(:PORT)(/path)</td> <td> USER:PASSWORD is the account used if authorization is required.<br> IP is the IP address used to pull this stream from.<br> PORT is the port used to connect through.<br> PATH is the path to be used to identify the correct stream. </td> </tr> </table>",
"function":function(){function a(c){var d=$.extend({},h);if(h.dynamic_capa){d.desc="Loading dynamic capabilities..";if(!("dynamic_capa_results"in h)||!(c in h.dynamic_capa_results)){S=c;if(Z)return;Z=setTimeout(function(){if(!("dynamic_capa_results"in h))h.dynamic_capa_results={};h.dynamic_capa_results[S]=null;mist.send(function(b){Z=false;h.dynamic_capa_results[S]=b.capabilities;a(S)},{capabilities:S})},1E3)}else{delete d.desc;h.dynamic_capa_results[c]&&(d=h.dynamic_capa_results[c])}}W.html($("<h3>").text(h.name+
" Input options"));d=mist.convertBuildOptions(d,r);"always_match"in mist.data.capabilities.inputs[f]&&mist.inputMatch(mist.data.capabilities.inputs[f].always_match,c)&&d.push({label:"Always on",type:"checkbox",help:"Keep this input available at all times, even when there are no active viewers.",pointer:{main:r,index:"always_on"},value:b==""&&(f=="TSSRT"||f=="TSRIST")?true:false});W.append(UI.buildUI(d));N.html("");if(h.enum_static_prefix&&c.slice(0,h.enum_static_prefix.length)==h.enum_static_prefix){var g=
function(){N.html($("<p>").text("Possible sources for "+h.name+": (click to set)"));var a=h.enumerated_sources[h.enum_static_prefix],b;for(b in a){var d=a[b].split(" ")[0];N.append($("<div>").attr("data-source",d).text(a[b]).click(function(){var a=$(this).attr("data-source");e.val(a).trigger("change")}).addClass(d==c?"active":""))}};if(!("enumerated_sources"in h)||!(h.enum_static_prefix in h.enumerated_sources)){if(!("enumerated_sources"in h))h.enumerated_sources={};h.enumerated_sources[h.enum_static_prefix]=
[];setTimeout(function(){delete h.enumerated_sources[h.enum_static_prefix]},1E4);mist.send(function(a){if(!("enumerated_sources"in h))h.enumerated_sources={};h.enumerated_sources[h.enum_static_prefix]=a.enumerate_sources;g()},{enumerate_sources:c})}else g()}}var d=$(this).val(),e=$(this);ma.remove();O.html("");if(d!=""){var g=null,f;for(f in mist.data.capabilities.inputs)if(typeof mist.data.capabilities.inputs[f].source_match!="undefined"&&mist.inputMatch(mist.data.capabilities.inputs[f].source_match,
d)){g=f;break}if(g===null){W.html($("<h3>").text("Unrecognized input").addClass("red")).append($("<span>").text("Please edit the stream source.").addClass("red"));N.html("")}else{var h=mist.data.capabilities.inputs[g],g=N.find("div");if(g.length){g.removeClass("active");g.filter('[data-source="'+d+'"]').addClass("active")}if(h.name=="Folder")b.indexOf("+")<0&&c.append(ma);else if(["Buffer","Buffer.exe","TS","TS.exe","TSSRT","TSSRT.exe"].indexOf(h.name)>-1){g=[$("<br>"),$("<span>").text("Configure your source to push to:")];
switch(h.name){case "Buffer":case "Buffer.exe":g.push({label:"RTMP full url",type:"span",clipboard:true,readonly:true,classes:["RTMP"],help:"Use this RTMP url if your client doesn't ask for a stream key"});g.push({label:"RTMP url",type:"span",clipboard:true,readonly:true,classes:["RTMPurl"],help:"Use this RTMP url if your client also asks for a stream key"});g.push({label:"RTMP stream key",type:"span",clipboard:true,readonly:true,classes:["RTMPkey"],help:"Use this key if your client asks for a stream key"});
g.push({label:"SRT",type:"span",clipboard:true,readonly:true,classes:["TSSRT"]});g.push({label:"RTSP",type:"span",clipboard:true,readonly:true,classes:["RTSP"]});break;case "TS":case "TS.exe":d.charAt(0)=="/"||d.slice(0,7)=="ts-exec"?g=[]:g.push({label:"TS",type:"span",clipboard:true,readonly:true,classes:["TS"]});break;case "TSSRT":case "TSSRT.exe":g.push({label:"SRT",type:"span",clipboard:true,readonly:true,classes:["TSSRT"]})}O.html(UI.buildUI(g));UI.updateLiveStreamHint(c.find("[name=name]").val(),
c.find("[name=source]").val(),O)}a(d)}}}},g,N,{label:"Stop sessions",type:"checkbox",help:"When saving these stream settings, kill this stream's current connections.",pointer:{main:r,index:"stop_sessions"}},O,$("<br>"),{type:"custom",custom:W},s,{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("Streams")}},{type:"save",label:"Save","function":function(){la("Streams")}},{type:"save",label:"Save and Preview","function":function(){la("Preview")},classes:["saveandpreview"]}]}]);
c.append(s);s.change(function(){var a=c.find(".header");a.length&&a.attr("data-changed","yes")});c.find("[name=name]").keyup(function(){UI.updateLiveStreamHint($(this).val(),c.find("[name=source]").val(),O)});UI.updateLiveStreamHint(c.find("[name=name]").val(),c.find("[name=source]").val(),O);c.find('[name="source"]').attr("list","source_datalist");break;case "Status":if(""==b){UI.navto("Streams");return}var A=$("<div>").addClass("dashboard");c.html(UI.modules.stream.header(b,a)).append(A);p=UI.modules.stream.findMist(function(){A.append(UI.modules.stream.status(b,
{status:false,stats:false}));A.append(UI.modules.stream.metadata(b));A.append($("<section>").addClass("logcont").append(UI.modules.stream.logs(b)).append(UI.modules.stream.accesslogs(b)));A.append(UI.modules.stream.processes(b));A.append(UI.modules.stream.triggers(b,"Status"));A.append(UI.modules.stream.pushes(b))});A.append(p);A.append(UI.modules.stream.actions("Status",b));break;case "Preview":if(""==b){UI.navto("Streams");return}var A=$("<div>").addClass("dashboard"),oa=$("<div>").text("Loading..");
c.html(UI.modules.stream.header(b,a)).append(oa).append(A);p=UI.modules.stream.findMist(function(){if(typeof mistplayers=="undefined")throw"Player.js was not applied properly.";oa.replaceWith(UI.modules.stream.status(b,{tags:false,thumbnail:false,status:false,stats:false}));window.mv={};$preview=UI.modules.stream.preview(b,window.mv);A.append($preview);A.append(UI.modules.stream.playercontrols(window.mv,$preview)).append(UI.modules.stream.logs(b)).append(UI.modules.stream.metadata(b))});A.append(p);
break;case "Embed":if(""==b){UI.navto("Streams");return}c.html(UI.modules.stream.header(b,a));$("<span>");c.append(UI.modules.stream.findMist(function(a){c.append(UI.modules.stream.embedurls(b,a,this.getUrls()))},!1,!0));break;case "Push":var K=$("<div>").text("Loading..");c.append(K);mist.send(function(a){function b(a){setTimeout(function(){mist.send(function(c){var d=false;if("push_list"in c&&c.push_list&&c.push_list.length){var d=true,g;for(g in c.push_list)if(a.indexOf(c.push_list[g][0])>-1){d=
false;break}}else d=true;if(d)for(g in a)e.find("tr[data-pushid="+a[g]+"]").remove();else b()},{push_list:1})},1E3)}function c(g,h){var f=$("<span>"),m=$("<span>");if(h=="Automatic"&&g.length>=4){var k=function(a,b,c){a=""+("$"+a+" ");switch(Number(b)){case 0:a=a+"is true";break;case 1:a=a+"is false";break;case 2:a=a+("== "+c);break;case 3:a=a+("!= "+c);break;case 10:a=a+("> (numerical) "+c);break;case 11:a=a+(">= (numerical) "+c);break;case 12:a=a+("< (numerical) "+c);break;case 13:a=a+("<= (numerical) "+
c);break;case 20:a=a+("> (lexical) "+c);break;case 21:a=a+(">= (lexical) "+c);break;case 22:a=a+("< (lexical) "+c);break;case 23:a=a+("<= (lexical) "+c);break;default:a=a+"comparison operator unknown"}return a};f.append($("<span>").text(g[2]));g[3]&&f.append($("<span>").text(", schedule on "+(new Date(g[3]*1E3)).toLocaleString()));g.length>=5&&g[4]&&f.append($("<span>").text(", complete on "+(new Date(g[4]*1E3)).toLocaleString()));g.length>=8&&g[5]&&f.append($("<span>").text(", starts if "+k(g[5],
g[6],g[7])));g.length>=11&&g[8]&&f.append($("<span>").text(", stops if "+k(g[8],g[9],g[10])))}else g.length>=4&&g[2]!=g[3]?f.append($("<span>").text(g[2])).append($("<span>").html("&#187").addClass("unit").css("margin","0 0.5em")).append($("<span>").text(g[3])):f.append($("<span>").text(g[2]));k=$("<td>").append($("<button>").text(h=="Automatic"?"Remove":"Stop").click(function(){if(confirm("Are you sure you want to "+$(this).text().toLowerCase()+" this push?\n"+g[1]+" to "+g[2])){var a=$(this).closest("tr");
a.html($("<td colspan=99>").html($("<span>").addClass("red").text(h=="Automatic"?"Removing..":"Stopping..")));if(h=="Automatic"){var c=g.slice(1);mist.send(function(){a.remove()},{push_auto_remove:[c]})}else mist.send(function(){b([g[0]])},{push_stop:[g[0]]})}}));if(h=="Automatic"){k.prepend($("<button>").text("Edit").click(function(){UI.navto("Start Push","auto_"+($(this).closest("tr").index()-1))}));k.append($("<button>").text("Stop pushes").click(function(){if(confirm('Are you sure you want to stop all pushes matching \n"'+
g[1]+" to "+g[2]+'"?'+(d.wait!=0?"\n\nRetrying is enabled. That means the push will just restart. You'll probably want to set that to 0.":""))){var c=$(this);c.text("Stopping pushes..");var h=[],f;for(f in a.push_list)if(g[1]==a.push_list[f][1]&&g[2]==a.push_list[f][2]){h.push(a.push_list[f][0]);e.find("tr[data-pushid="+a.push_list[f][0]+"]").html($("<td colspan=99>").html($("<span>").addClass("red").text("Stopping..")))}mist.send(function(){c.text("Stop pushes");b(h)},{push_stop:h})}}))}else{if(g.length>=
6){var q=g[5];m.append($("<div>").append("Active for: "+UI.format.duration(q.active_seconds))).append($("<div>").append("Data transferred: "+UI.format.bytes(q.bytes))).append($("<div>").append("Media time transferred: "+UI.format.duration(q.mediatime*0.001)));"pkt_retrans_count"in q&&m.append($("<div>").append("Packets retransmitted: "+UI.format.number(q.pkt_retrans_count||0)));"pkt_loss_count"in q&&m.append($("<div>").append("Packets lost: "+UI.format.number(q.pkt_loss_count||0)+" ("+UI.format.addUnit(UI.format.number(q.pkt_loss_perc||
0),"%")+" over the last "+UI.format.addUnit(5,"s")+")"))}if(g.length>=5)for(var i in g[4]){q=g[4][i];m.append($("<div>").append(UI.format.time(q[0])+" ["+q[1]+"] "+q[2]))}}return $("<tr>").css("vertical-align","top").attr("data-pushid",g[0]).append($("<td>").text(g[1])).append($("<td>").append(f.children())).append($("<td>").addClass("logs").append(m.children())).append(k)}K.html(UI.buildUI([{type:"help",help:"You can push streams to files or other servers, allowing them to broadcast your stream as well."}]));
var d=a.push_settings;d||(d={});var e=$("<table>").append($("<tr>").append($("<th>").text("Stream")).append($("<th>").text("Target")).append($("<th>")).append($("<th>"))),g=e.clone();if("push_list"in a)for(var h in a.push_list)e.append(c(a.push_list[h],"Manual"));if("push_auto_list"in a)for(h in a.push_auto_list){var f=a.push_auto_list[h].slice();f.unshift(-1);g.append(c(f,"Automatic"))}K.append($("<h3>").text("Automatic push settings")).append(UI.buildUI([{label:"Delay before retry",unit:"s",type:"int",
"both")).append($("<table>").html($("<thead>").html($("<tr>").html($("<th>").text("Protocol")).append($("<th>").text("Status")).append($("<th>").text("Settings")).append($("<th>")))).append(A));var L=function(){function a(b){var c=mist.data.capabilities.connectors[b.connector];if(!c)return"";var d=[],h=["required","optional"],e;for(e in h)for(var g in c[h[e]])b[g]&&b[g]!=""?d.push(g+": "+b[g]):c[h[e]][g]["default"]&&d.push(g+": "+c[h[e]][g]["default"]);return $("<span>").addClass("description").text(d.join(", "))}
A.html("");for(var b in mist.data.config.protocols){var c=mist.data.config.protocols[b],d=mist.data.capabilities.connectors[c.connector];A.append($("<tr>").data("index",b).append($("<td>").text(d&&d.friendly?d.friendly:c.connector)).append($("<td>").html(UI.format.status(c))).append($("<td>").html(a(c))).append($("<td>").css("text-align","right").html($("<button>").text("Edit").click(function(){UI.navto("Edit Protocol",$(this).closest("tr").data("index"))})).append($("<button>").text("Delete").click(function(){var a=
$(this).closest("tr").data("index");if(confirm('Are you sure you want to delete the protocol "'+mist.data.config.protocols[a].connector+'"?')){mist.send(function(){UI.navto("Protocols")},{deleteprotocol:mist.data.config.protocols[a]});mist.data.config.protocols.splice(a,1)}}))))}};L();UI.interval.set(function(){mist.send(function(){L()})},1E4);break;case "Edit Protocol":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a,b)},{capabilities:!0});c.append("Loading..");return}u=
!1;""!=b&&0<=b&&(u=!0);var M={};for(p in mist.data.config.protocols)M[mist.data.config.protocols[p].connector]=1;var ea=function(a){var b=mist.data.capabilities.connectors[a],c=mist.convertBuildOptions(b,r);if(u)var d=$.extend({},r);c.push({type:"hidden",pointer:{main:r,index:"connector"},value:a});c.push({type:"buttons",buttons:[{type:"save",label:"Save","function":function(){var a={};u?a.updateprotocol=[d,r]:a.addprotocol=r;mist.send(function(){UI.navto("Protocols")},a)}},{type:"cancel",label:"Cancel",
"function":function(){UI.navto("Protocols")}}]});if("deps"in b&&b.deps!=""){s=$("<span>").text("Dependencies:");$ul=$("<ul>");s.append($ul);if(typeof b.deps=="string")b.deps=b.deps.split(", ");for(var h in b.deps){a=$("<li>").text(b.deps[h]+" ");$ul.append(a);typeof M[b.deps[h]]!="undefined"||typeof M[b.deps[h]+".exe"]!="undefined"?a.append($("<span>").addClass("green").text("(Configured)")):a.append($("<span>").addClass("red").text("(Not yet configured)"))}c.unshift({type:"text",text:s[0].innerHTML})}return UI.buildUI(c)},
M={};for(p in mist.data.config.protocols)M[mist.data.config.protocols[p].connector]=1;if(u)r=p=mist.data.config.protocols[b],c.find("h2").append(' "'+p.connector+'"'),c.append(ea(p.connector));else{c.html($("<h2>").text("New Protocol"));var r={},t=[["",""]];for(p in mist.data.capabilities.connectors)t.push([p,mist.data.capabilities.connectors[p].friendly?mist.data.capabilities.connectors[p].friendly:p]);var fa=$("<span>");c.append(UI.buildUI([{label:"Protocol",type:"select",select:t,"function":function(){$(this).getval()!=
""&&fa.html(ea($(this).getval()))}}])).append(fa)}break;case "Streams":if(!("capabilities"in mist.data)){c.html("Loading..");mist.send(function(){UI.navto(a)},{capabilities:!0});return}p=$("<button>");var I=$("<span>").text("Loading..");c.append(UI.buildUI([{type:"help",help:"Here you can create, edit or delete new and existing streams. Go to stream preview or embed a video player on your website."},$("<div>").css({width:"45.25em",display:"flex","justify-content":"flex-end"}).append(p).append($("<button>").text("Create a new stream").click(function(){UI.navto("Edit")}))])).append(I);
""==b&&(k=mist.stored.get(),"viewmode"in k&&(b=k.viewmode));p.text("Switch to "+("thumbnails"==b?"list":"thumbnail")+" view").click(function(){mist.stored.set("viewmode",b=="thumbnails"?"list":"thumbnails");UI.navto("Streams",b=="thumbnails"?"list":"thumbnails")});var B=$.extend(!0,{},mist.data.streams),T=function(a,b){var c=$.extend({},b);delete c.meta;delete c.error;c.online=2;c.name=a;c.ischild=true;return c},ga=function(b,d,h){I.remove();switch(b){case "thumbnails":var e=$("<div>").addClass("preview_icons"),
g;g=h||[];d.sort();d.unshift("");I.remove();c.append($("<h2>").text(a)).append(UI.buildUI([{label:"Filter the streams",type:"datalist",datalist:d,pointer:{main:{},index:"stream"},help:"If you type something here, the box below will only show streams with names that contain your text.","function":function(){var a=$(this).val();e.children().each(function(){$(this).hide();$(this).attr("data-stream").indexOf(a)>-1&&$(this).show()})}}]));d.shift();c.append($("<span>").addClass("description").text("Choose a stream below.")).append(e);
b=false;if(UI.findOutput("JPG")){var f=false,m;for(m in mist.data.config.protocols){h=mist.data.config.protocols[m];if(h.connector=="HTTP"||h.connector=="HTTP.exe")f=h.port?":"+h.port:":8080";if(h.connector=="JPG"||h.connector=="JPG.exe")b=true}if(b&&f){f=parseURL(mist.user.host).host+f;b=function(a){return"http://"+f+"/"+encodeURIComponent(a)+".jpg"}}}for(m in d){var h=d[m],q="",j=$("<button>").text("Delete").click(function(){var a=$(this).closest("div").attr("data-stream");if(confirm('Are you sure you want to delete the stream "'+
a+'"?')){delete mist.data.streams[a];var b={};b.deletestream=[a];mist.send(function(){UI.navto("Streams")},b)}}),k=$("<button>").text("Settings").click(function(){UI.navto("Edit",$(this).closest("div").attr("data-stream"))}),l=$("<button>").text("Preview").click(function(){UI.navto("Preview",$(this).closest("div").attr("data-stream"))}),i=$("<button>").text("Embed").click(function(){UI.navto("Embed",$(this).closest("div").attr("data-stream"))}),n=$("<span>").addClass("image");b&&g.indexOf(h)==-1&&
n.append($("<img>").attr("src",b(h)).error(function(){$(this).hide()}));if(h.indexOf("+")>-1){q=h.split("+");q=mist.data.streams[q[0]].source+q[1];k=j="";n.addClass("wildcard")}else{q=mist.data.streams[h].source;if(g.indexOf(h)>-1){i=l="";n.addClass("folder")}}e.append($("<div>").append($("<span>").addClass("streamname").text(h)).append(n).append($("<span>").addClass("description").text(q)).append($("<span>").addClass("button_container").append(k).append(j).append(l).append(i)).attr("title",h).attr("data-stream",
h))}break;default:var o=$("<tbody>").append($("<tr>").append("<td>").attr("colspan",6).text("Loading.."));m=$("<table>").html($("<thead>").html($("<tr>").html($("<th>").text("Stream name").attr("data-sort-type","string").addClass("sorting-asc")).append($("<th>")).append($("<th>").text("Source").attr("data-sort-type","string")).append($("<th>").text("Status").attr("data-sort-type","int")).append($("<th>").css("text-align","right").text("Connections").attr("data-sort-type","int")))).append(o);c.append(m);
m.stupidtable();var p=function(){var a=[],b;for(b in mist.data.active_streams)a.push({streams:[mist.data.active_streams[b]],fields:["clients"],start:-2});mist.send(function(){$.extend(true,B,mist.data.streams);var a=0;o.html("");d.sort();for(var b in d){var c=d[b],h;h=c in mist.data.streams?mist.data.streams[c]:B[c];var e=$("<td>").css("text-align","right").html($("<span>").addClass("description").text("Loading..")),g=0;if(typeof mist.data.totals!="undefined"&&typeof mist.data.totals[c]!="undefined"){var f=
mist.data.totals[c].all_protocols.clients,g=0;if(f.length){for(a in f)g=g+f[a][1];g=Math.round(g/f.length)}}e.html(UI.format.number(g));if(g==0&&h.online==1)h.online=2;g=$("<td>").css("white-space","nowrap");(!("ischild"in h)||!h.ischild)&&g.html($("<button>").text("Settings").click(function(){UI.navto("Edit",$(this).closest("tr").data("index"))})).append($("<button>").text("Delete").click(function(){var a=$(this).closest("tr").data("index");if(confirm('Are you sure you want to delete the stream "'+
a+'"?')){delete mist.data.streams[a];var b={};mist.data.LTS?b.deletestream=[a]:b.streams=mist.data.streams;mist.send(function(){UI.navto("Streams")},b)}}));f=$("<span>").text(h.name);h.ischild&&f.css("padding-left","1em");var m=UI.format.status(h),q=$("<button>").text("Status").click(function(){UI.navto("Status",$(this).closest("tr").data("index"))}),j=$("<button>").text("Preview").click(function(){UI.navto("Preview",$(this).closest("tr").data("index"))}),k=$("<button>").text("Embed").css("margin-right",
"1em").click(function(){UI.navto("Embed",$(this).closest("tr").data("index"))});if("filesfound"in B[c]||h.online<0){m.html("");e.html("");j.css({opacity:0,pointerEvents:"none"});k.css({opacity:0,pointerEvents:"none"})}g.prepend(k).prepend(q).prepend(j);o.append($("<tr>").data("index",c).html($("<td>").html(f).attr("title",h.name=="..."?"The results were truncated":h.name).addClass("overflow_ellipsis")).append(g).append($("<td>").text(h.source).attr("title",h.source).addClass("description").addClass("overflow_ellipsis").css("max-width",
"20em")).append($("<td>").data("sort-value",h.online).html(m)).append(e));a++}},{totals:a,active_streams:true})},U=0,r=0;for(g in mist.data.streams){m=mist.data.capabilities.inputs.Folder||mist.data.capabilities.inputs["Folder.exe"];if(!m)break;if(mist.inputMatch(m.source_match,mist.data.streams[g].source)){B[g].source=B[g].source+"*";B[g].filesfound=null;mist.send(function(a,b){var c=b.stream,d=0,h;a:for(h in a.browse.files){var g;for(g in mist.data.capabilities.inputs)if(!(g.indexOf("Buffer")>=
0||g.indexOf("Buffer.exe")>=0||g.indexOf("Folder")>=0||g.indexOf("Folder.exe")>=0)&&mist.inputMatch(mist.data.capabilities.inputs[g].source_match,"/"+a.browse.files[h])){var e=c+"+"+a.browse.files[h];B[e]=T(e,mist.data.streams[c]);B[e].source=mist.data.streams[c].source+a.browse.files[h];d++;if(d>=500){B[c+"+zzzzzzzzz"]={ischild:true,name:"...",online:-1};break a}}}"files"in a.browse&&a.browse.files.length?B[c].filesfound=true:mist.data.streams[c].filesfound=false;r++;if(U==r){mist.send(function(){p()},
{active_streams:true});UI.interval.set(function(){p()},5E3)}},{browse:mist.data.streams[g].source},{stream:g});U++}}if(U==0){mist.send(function(){p()},{active_streams:true});UI.interval.set(function(){p()},5E3)}}},V=0,ha=0,t={},ia=[];for(k in mist.data.streams)if(mist.inputMatch((mist.data.capabilities.inputs.Folder||mist.data.capabilities.inputs["Folder.exe"]).source_match,mist.data.streams[k].source))ia.push(k),mist.send(function(a,c){var d=c.stream,h=0,g;a:for(g in a.browse.files){var e;for(e in mist.data.capabilities.inputs)if(!(e.indexOf("Buffer")>=
0||e.indexOf("Folder")>=0)&&mist.inputMatch(mist.data.capabilities.inputs[e].source_match,"/"+a.browse.files[g])){t[d+"+"+a.browse.files[g]]=true;h++;if(h>=500){t[d+"+zzzzzzzzz"]=true;break a}}}ha++;V==ha&&mist.send(function(){for(var a in mist.data.active_streams){var c=mist.data.active_streams[a].split("+");if(c.length>1&&c[0]in mist.data.streams){t[mist.data.active_streams[a]]=true;B[mist.data.active_streams[a]]=T(mist.data.active_streams[a],mist.data.streams[c[0]])}}t=Object.keys(t);t=t.concat(Object.keys(mist.data.streams));
t.sort();ga(b,t,ia)},{active_streams:true})},{browse:mist.data.streams[k].source},{stream:k}),V++;0==V&&mist.send(function(){for(var a in mist.data.active_streams){var c=mist.data.active_streams[a].split("+");if(c.length>1&&c[0]in mist.data.streams){t[mist.data.active_streams[a]]=true;B[mist.data.active_streams[a]]=T(mist.data.active_streams[a],mist.data.streams[c[0]])}}t=Object.keys(t);mist.data.streams&&(t=t.concat(Object.keys(mist.data.streams)));t.sort();ga(b,t)},{active_streams:!0});break;case "Edit":if("undefined"==
typeof mist.data.capabilities){mist.send(function(){UI.navto(a,b)},{capabilities:!0});c.append("Loading..");return}u=!1;""!=b&&(u=!0);u?(h=b.split("+")[0],r=mist.data.streams[h],c.find("h2").append(' "'+h+'"')):(c.html($("<h2>").text("New Stream")),r={});var h=[],e=$("<datalist>").attr("id","source_datalist"),J=$("<div>").addClass("source_info"),W=!1,N=!1;for(p in mist.data.capabilities.inputs)for(j in mist.data.capabilities.inputs[p].source_match)h.push(mist.data.capabilities.inputs[p].source_match[j]),
e.append($("<option>").val(mist.data.capabilities.inputs[p].source_match[j]));var Q=$("<div>"),ja=function(a){var c={};if(!mist.data.streams)mist.data.streams={};mist.data.streams[r.name]=r;b!=r.name&&delete mist.data.streams[b];c.addstream={};c.addstream[r.name]=r;if(b!=r.name)c.deletestream=[b];if(r.stop_sessions&&b!=""){c.stop_sessions=b;delete r.stop_sessions}var d=null,h;for(h in mist.data.capabilities.inputs)if(typeof mist.data.capabilities.inputs[h].source_match!="undefined"&&mist.inputMatch(mist.data.capabilities.inputs[h].source_match,
r.source)){d=h;break}if(d){d=mist.data.capabilities.inputs[d];for(h in r)h=="name"||h=="source"||h=="stop_sessions"||h=="processes"||"optional"in d&&h in d.optional||"required"in d&&h in d.required||h=="always_on"&&"always_match"in d&&mist.inputMatch(d.always_match,r.source)||delete r[h]}mist.send(function(){delete mist.data.streams[r.name].online;delete mist.data.streams[r.name].error;UI.navto(a,a=="Preview"?r.name:"")},c)},ka=$("<style>").text("button.saveandpreview { display: none; }"),K=$("<span>"),
j=$("<div>"),X={},t=[],la=$("<div>");for(p in mist.data.capabilities.processes)t.push([p,mist.data.capabilities.processes[p].hrn?mist.data.capabilities.processes[p].hrn:mist.data.capabilities.processes[p].name]);t.length&&(p=[{label:"New process",type:"select",select:t,value:t[0][0],pointer:{main:X,index:"process"},"function":function(){var a=$(this).getval();if(a!=null){var a=mist.data.capabilities.processes[a],b=[$("<h4>").text(a.name+" Process options")];la.html(UI.buildUI(b.concat(mist.convertBuildOptions(a,
X))))}}},la],j.append(UI.buildUI([$("<br>"),$("<h3>").text("Stream processes"),{label:"Stream processes",itemLabel:"stream process",type:"sublist",sublist:p,saveas:X,pointer:{main:r,index:"processes"}}])));c.append(UI.buildUI([{label:"Stream name",type:"str",validate:["required","streamname"],pointer:{main:r,index:"name"},help:"Set the name this stream will be recognised by for players and/or stream pushing."},{label:"Source",type:"browse",filetypes:h,pointer:{main:r,index:"source"},help:"<p> Below is the explanation of the input methods for MistServer. Anything between brackets () will go to default settings if not specified. </p> <table class=valigntop> <tr> <th colspan=3><b>File inputs</b></th> </tr> <tr> <th>File</th> <td> Linux/MacOS:&nbsp;/PATH/FILE<br> Windows:&nbsp;/cygdrive/DRIVE/PATH/FILE </td> <td> For file input please specify the proper path and file.<br> Supported inputs are: DTSC, FLV, MP3. MistServer Pro has TS, MP4, ISMV added as input. </td> </tr> <th> Folder </th> <td> Linux/MacOS:&nbsp;/PATH/<br> Windows:&nbsp;/cygdrive/DRIVE/PATH/ </td> <td> A folder stream makes all the recognised files in the selected folder available as a stream. </td> </tr> <tr><td colspan=3>&nbsp;</td></tr> <tr> <th colspan=3><b>Push inputs</b></th> </tr> <tr> <th>RTMP</th> <td>push://(IP)(@PASSWORD)</td> <td> IP is white listed IP for pushing towards MistServer, if left empty all are white listed.<br> PASSWORD is the application under which to push to MistServer, if it doesn't match the stream will be rejected. PASSWORD is MistServer Pro only. </td> </tr> <tr> <th>SRT</th> <td>push://(IP)</td> <td> IP is white listed IP for pushing towards MistServer, if left empty all are white listed.<br> </td> </tr> <tr> <th>RTSP</th> <td>push://(IP)(@PASSWORD)</td> <td>IP is white listed IP for pushing towards MistServer, if left empty all are white listed.</td> </tr> <tr> <th>TS</th> <td>tsudp://(IP):PORT(/INTERFACE)</td> <td> IP is the IP address used to listen for this stream, multi-cast IP range is: 224.0.0.0 - 239.255.255.255. If IP is not set all addresses will listened to.<br> PORT is the port you reserve for this stream on the chosen IP.<br> INTERFACE is the interface used, if left all interfaces will be used. </td> </tr> <tr><td colspan=3>&nbsp;</td></tr> <tr> <th colspan=3><b>Pull inputs</b></th> </tr> <tr> <th>DTSC</th> <td>dtsc://MISTSERVER_IP:PORT/(STREAMNAME)</td> <td>MISTSERVER_IP is the IP of another MistServer to pull from.<br> PORT is the DTSC port of the other MistServer. (default is 4200)<br> STREAMNAME is the name of the target stream on the other MistServer. If left empty, the name of this stream will be used. </td> </tr> <tr> <th>HLS</th> <td>http://URL/TO/STREAM.m3u8</td> <td>The URL where the HLS stream is available to MistServer.</td> </tr> <tr> <th>RTSP</th> <td>rtsp://(USER:PASSWORD@)IP(:PORT)(/path)</td> <td> USER:PASSWORD is the account used if authorization is required.<br> IP is the IP address used to pull this stream from.<br> PORT is the port used to connect through.<br> PATH is the path to be used to identify the correct stream. </td> </tr> </table>",
"function":function(){function a(c){var d=$.extend({},f);if(f.dynamic_capa){d.desc="Loading dynamic capabilities..";if(!("dynamic_capa_results"in f)||!(c in f.dynamic_capa_results)){N=c;if(W)return;W=setTimeout(function(){if(!("dynamic_capa_results"in f))f.dynamic_capa_results={};f.dynamic_capa_results[N]=null;mist.send(function(b){W=false;f.dynamic_capa_results[N]=b.capabilities;a(N)},{capabilities:N})},1E3)}else{delete d.desc;f.dynamic_capa_results[c]&&(d=f.dynamic_capa_results[c])}}Q.html($("<h3>").text(f.name+
" Input options"));d=mist.convertBuildOptions(d,r);"always_match"in mist.data.capabilities.inputs[e]&&mist.inputMatch(mist.data.capabilities.inputs[e].always_match,c)&&d.push({label:"Always on",type:"checkbox",help:"Keep this input available at all times, even when there are no active viewers.",pointer:{main:r,index:"always_on"},value:b==""&&(e=="TSSRT"||e=="TSRIST")?true:false});Q.append(UI.buildUI(d));J.html("");if(f.enum_static_prefix&&c.slice(0,f.enum_static_prefix.length)==f.enum_static_prefix){var g=
function(){J.html($("<p>").text("Possible sources for "+f.name+": (click to set)"));var a=f.enumerated_sources[f.enum_static_prefix],b;for(b in a){var d=a[b].split(" ")[0];J.append($("<div>").attr("data-source",d).text(a[b]).click(function(){var a=$(this).attr("data-source");h.val(a).trigger("change")}).addClass(d==c?"active":""))}};if(!("enumerated_sources"in f)||!(f.enum_static_prefix in f.enumerated_sources)){if(!("enumerated_sources"in f))f.enumerated_sources={};f.enumerated_sources[f.enum_static_prefix]=
[];setTimeout(function(){delete f.enumerated_sources[f.enum_static_prefix]},1E4);mist.send(function(a){if(!("enumerated_sources"in f))f.enumerated_sources={};f.enumerated_sources[f.enum_static_prefix]=a.enumerate_sources;g()},{enumerate_sources:c})}else g()}}var d=$(this).val(),h=$(this);ka.remove();K.html("");if(d!=""){var g=null,e;for(e in mist.data.capabilities.inputs)if(typeof mist.data.capabilities.inputs[e].source_match!="undefined"&&mist.inputMatch(mist.data.capabilities.inputs[e].source_match,
d)){g=e;break}if(g===null){Q.html($("<h3>").text("Unrecognized input").addClass("red")).append($("<span>").text("Please edit the stream source.").addClass("red"));J.html("")}else{var f=mist.data.capabilities.inputs[g],g=J.find("div");if(g.length){g.removeClass("active");g.filter('[data-source="'+d+'"]').addClass("active")}if(f.name=="Folder")c.append(ka);else if(["Buffer","Buffer.exe","TS","TS.exe","TSSRT","TSSRT.exe"].indexOf(f.name)>-1){g=[$("<br>"),$("<span>").text("Configure your source to push to:")];
switch(f.name){case "Buffer":case "Buffer.exe":g.push({label:"RTMP full url",type:"span",clipboard:true,readonly:true,classes:["RTMP"],help:"Use this RTMP url if your client doesn't ask for a stream key"});g.push({label:"RTMP url",type:"span",clipboard:true,readonly:true,classes:["RTMPurl"],help:"Use this RTMP url if your client also asks for a stream key"});g.push({label:"RTMP stream key",type:"span",clipboard:true,readonly:true,classes:["RTMPkey"],help:"Use this key if your client asks for a stream key"});
g.push({label:"SRT",type:"span",clipboard:true,readonly:true,classes:["TSSRT"]});g.push({label:"RTSP",type:"span",clipboard:true,readonly:true,classes:["RTSP"]});break;case "TS":case "TS.exe":d.charAt(0)=="/"||d.slice(0,7)=="ts-exec"?g=[]:g.push({label:"TS",type:"span",clipboard:true,readonly:true,classes:["TS"]});break;case "TSSRT":case "TSSRT.exe":g.push({label:"SRT",type:"span",clipboard:true,readonly:true,classes:["TSSRT"]})}K.html(UI.buildUI(g));UI.updateLiveStreamHint(c.find("[name=name]").val(),
c.find("[name=source]").val(),K)}a(d)}}}},e,J,{label:"Stop sessions",type:"checkbox",help:"When saving these stream settings, kill this stream's current connections.",pointer:{main:r,index:"stop_sessions"}},K,$("<br>"),{type:"custom",custom:Q},j,{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("Streams")}},{type:"save",label:"Save","function":function(){ja("Streams")}},{type:"save",label:"Save and Preview","function":function(){ja("Preview")},classes:["saveandpreview"]}]}]));
c.find("[name=name]").keyup(function(){UI.updateLiveStreamHint($(this).val(),c.find("[name=source]").val(),K)});UI.updateLiveStreamHint(c.find("[name=name]").val(),c.find("[name=source]").val(),K);c.find('[name="source"]').attr("list","source_datalist");break;case "Status":if(""==b){UI.navto("Streams");return}-1==b.indexOf("+")&&$("<button>").text("Settings").addClass("settings").click(function(){UI.navto("Edit",b)});var y=$("<div>").addClass("dashboard");c.html(UI.modules.stream.bigbuttons(b,a)).append($("<h2>").text('Status of "'+
b+'"')).append(y);p=UI.modules.stream.findMist(function(){y.append(UI.modules.stream.status(b));y.append(UI.modules.stream.metadata(b));y.append($("<section>").addClass("logcont").append(UI.modules.stream.logs(b)).append(UI.modules.stream.accesslogs(b)));y.append(UI.modules.stream.processes(b));y.append(UI.modules.stream.triggers(b,"Status"));y.append(UI.modules.stream.pushes(b))});y.append(p);y.append(UI.modules.stream.actions("Status",b));break;case "Preview":if(""==b){UI.navto("Streams");return}var y=
$("<div>").addClass("dashboard"),ma=$("<div>");c.html(UI.modules.stream.bigbuttons(b,a)).append($("<h2>").text('Preview of "'+b+'"')).append(ma).append(y);p=UI.modules.stream.findMist(function(){if(typeof mistplayers=="undefined")throw"Player.js was not applied properly.";ma.replaceWith(UI.modules.stream.status(b,{tags:false,thumbnail:false}));window.mv={};$preview=UI.modules.stream.preview(b,window.mv);y.append($preview);y.append(UI.modules.stream.playercontrols(window.mv,$preview)).append(UI.modules.stream.logs(b)).append(UI.modules.stream.metadata(b))});
y.append(p);break;case "Embed":if(""==b){UI.navto("Streams");return}c.html(UI.modules.stream.bigbuttons(b,a)).append($("<h2>").text('Embed "'+b+'"'));$("<span>");c.append(UI.modules.stream.findMist(function(a){c.append(UI.modules.stream.embedurls(b,a,this.getUrls()))},!1,!0));break;case "Push":var F=$("<div>").text("Loading..");c.append(F);mist.send(function(a){function b(a){setTimeout(function(){mist.send(function(c){var d=false;if("push_list"in c&&c.push_list&&c.push_list.length){var d=true,g;for(g in c.push_list)if(a.indexOf(c.push_list[g][0])>
-1){d=false;break}}else d=true;if(d)for(g in a)h.find("tr[data-pushid="+a[g]+"]").remove();else b()},{push_list:1})},1E3)}function c(g,e){var f=$("<span>"),m=$("<span>");if(e=="Automatic"&&g.length>=4){var q=function(a,b,c){a=""+("$"+a+" ");switch(Number(b)){case 0:a=a+"is true";break;case 1:a=a+"is false";break;case 2:a=a+("== "+c);break;case 3:a=a+("!= "+c);break;case 10:a=a+("> (numerical) "+c);break;case 11:a=a+(">= (numerical) "+c);break;case 12:a=a+("< (numerical) "+c);break;case 13:a=a+("<= (numerical) "+
c);break;case 20:a=a+("> (lexical) "+c);break;case 21:a=a+(">= (lexical) "+c);break;case 22:a=a+("< (lexical) "+c);break;case 23:a=a+("<= (lexical) "+c);break;default:a=a+"comparison operator unknown"}return a};f.append($("<span>").text(g[2]));g[3]&&f.append($("<span>").text(", schedule on "+(new Date(g[3]*1E3)).toLocaleString()));g.length>=5&&g[4]&&f.append($("<span>").text(", complete on "+(new Date(g[4]*1E3)).toLocaleString()));g.length>=8&&g[5]&&f.append($("<span>").text(", starts if "+q(g[5],
g[6],g[7])));g.length>=11&&g[8]&&f.append($("<span>").text(", stops if "+q(g[8],g[9],g[10])))}else g.length>=4&&g[2]!=g[3]?f.append($("<span>").text(g[2])).append($("<span>").html("&#187").addClass("unit").css("margin","0 0.5em")).append($("<span>").text(g[3])):f.append($("<span>").text(g[2]));q=$("<td>").append($("<button>").text(e=="Automatic"?"Remove":"Stop").click(function(){if(confirm("Are you sure you want to "+$(this).text().toLowerCase()+" this push?\n"+g[1]+" to "+g[2])){var a=$(this).closest("tr");
a.html($("<td colspan=99>").html($("<span>").addClass("red").text(e=="Automatic"?"Removing..":"Stopping..")));if(e=="Automatic"){var c=g.slice(1);mist.send(function(){a.remove()},{push_auto_remove:[c]})}else mist.send(function(){b([g[0]])},{push_stop:[g[0]]})}}));if(e=="Automatic"){q.prepend($("<button>").text("Edit").click(function(){UI.navto("Start Push","auto_"+($(this).closest("tr").index()-1))}));q.append($("<button>").text("Stop pushes").click(function(){if(confirm('Are you sure you want to stop all pushes matching \n"'+
g[1]+" to "+g[2]+'"?'+(d.wait!=0?"\n\nRetrying is enabled. That means the push will just restart. You'll probably want to set that to 0.":""))){var c=$(this);c.text("Stopping pushes..");var e=[],f;for(f in a.push_list)if(g[1]==a.push_list[f][1]&&g[2]==a.push_list[f][2]){e.push(a.push_list[f][0]);h.find("tr[data-pushid="+a.push_list[f][0]+"]").html($("<td colspan=99>").html($("<span>").addClass("red").text("Stopping..")))}mist.send(function(){c.text("Stop pushes");b(e)},{push_stop:e})}}))}else{if(g.length>=
6){var j=g[5];m.append($("<div>").append("Active for: "+UI.format.duration(j.active_seconds))).append($("<div>").append("Data transferred: "+UI.format.bytes(j.bytes))).append($("<div>").append("Media time transferred: "+UI.format.duration(j.mediatime*0.001)));"pkt_retrans_count"in j&&m.append($("<div>").append("Packets retransmitted: "+UI.format.number(j.pkt_retrans_count||0)));"pkt_loss_count"in j&&m.append($("<div>").append("Packets lost: "+UI.format.number(j.pkt_loss_count||0)+" ("+UI.format.addUnit(UI.format.number(j.pkt_loss_perc||
0),"%")+" over the last "+UI.format.addUnit(5,"s")+")"))}if(g.length>=5)for(var k in g[4]){j=g[4][k];m.append($("<div>").append(UI.format.time(j[0])+" ["+j[1]+"] "+j[2]))}}return $("<tr>").css("vertical-align","top").attr("data-pushid",g[0]).append($("<td>").text(g[1])).append($("<td>").append(f.children())).append($("<td>").addClass("logs").append(m.children())).append(q)}F.html(UI.buildUI([{type:"help",help:"You can push streams to files or other servers, allowing them to broadcast your stream as well."}]));
var d=a.push_settings;d||(d={});var h=$("<table>").append($("<tr>").append($("<th>").text("Stream")).append($("<th>").text("Target")).append($("<th>")).append($("<th>"))),g=h.clone();if("push_list"in a)for(var e in a.push_list)h.append(c(a.push_list[e],"Manual"));if("push_auto_list"in a)for(e in a.push_auto_list){var f=a.push_auto_list[e].slice();f.unshift(-1);g.append(c(f,"Automatic"))}F.append($("<h3>").text("Automatic push settings")).append(UI.buildUI([{label:"Delay before retry",unit:"s",type:"int",
min:0,help:"How long the delay should be before MistServer retries an automatic push.<br>If set to 0, it does not retry.","default":3,pointer:{main:d,index:"wait"}},{label:"Maximum retries",unit:"/s",type:"int",min:0,help:"The maximum amount of retries per second (for all automatic pushes).<br>If set to 0, there is no limit.","default":0,pointer:{main:d,index:"maxspeed"}},{type:"buttons",buttons:[{type:"save",label:"Save","function":function(){mist.send(function(){UI.navto("Push")},{push_settings:d})}}]}])).append($("<h3>").text("Automatic push settings")).append($("<button>").text("Add an automatic push").click(function(){UI.navto("Start Push",
"auto")}));g.find("tr").length==1?K.append($("<div>").text("No automatic pushes have been configured.").addClass("text").css("margin-top","0.5em")):K.append(g);K.append($("<h3>").text("Pushes")).append($("<button>").text("Start a push").click(function(){UI.navto("Start Push")}));if(e.find("tr").length==1)K.append($("<div>").text("No pushes are active.").addClass("text").css("margin-top","0.5em"));else{var g=[],f=[],m=$("<select>").css("margin-left","0.5em").append($("<option>").text("Any stream").val("")),
k=$("<select>").css("margin-left","0.5em").append($("<option>").text("Any target").val(""));for(h in a.push_list){g.indexOf(a.push_list[h][1])==-1&&g.push(a.push_list[h][1]);f.indexOf(a.push_list[h][2])==-1&&f.push(a.push_list[h][2])}g.sort();f.sort();for(h in g)m.append($("<option>").text(g[h]));for(h in f)k.append($("<option>").text(f[h]));K.append($("<button>").text("Stop all pushes").click(function(){var c=[],d;for(d in a.push_list)c.push(a.push_list[d][0]);if(c.length!=0&&confirm("Are you sure you want to stop all pushes?")){mist.send(function(){b(c)},
{push_stop:c});e.find("tr:not(:first-child)").html($("<td colspan=99>").append($("<span>").addClass("red").text("Stopping..")));$(this).remove()}})).append($("<label>").css("margin-left","1em").append($("<span>").text("Stop all pushes that match: ").css("font-size","0.9em")).append(m).append($("<span>").css("margin-left","0.5em").text("and").css("font-size","0.9em")).append(k).append($("<button>").css("margin-left","0.5em").text("Apply").click(function(){var c=m.val(),d=k.val();if(c==""&&d=="")return alert("Looks like you want to stop all pushes. Maybe you should use that button?");
var g={},h;for(h in a.push_list)if((c==""||a.push_list[h][1]==c)&&(d==""||a.push_list[h][2]==d))g[a.push_list[h][0]]=a.push_list[h];if(Object.keys(g).length==0)return alert("No matching pushes.");c="Are you sure you want to stop these pushes?\n\n";for(h in g)c=c+(g[h][1]+" to "+g[h][2]+"\n");if(confirm(c)){g=Object.keys(g);mist.send(function(){b(g)},{push_stop:g});for(h in g)e.find("tr[data-pushid="+g[h]+"]").html($("<td colspan=99>").html($("<span>").addClass("red").text("Stopping..")))}}))).append(e)}UI.interval.set(function(){mist.send(function(a){var b=
e.find("tr").first();e.empty();e.append(b);for(var d in a.push_list)e.append(c(a.push_list[d]))},{push_list:1})},5E3)},{push_settings:1,push_list:1,push_auto_list:1});break;case "Start Push":if(!("capabilities"in mist.data)||!("variable_list"in mist.data)||!("external_writer_list"in mist.data)){c.append("Loading MistServer capabilities..");mist.send(function(){UI.showTab("Start Push",b,e)},{capabilities:!0,variable_list:!0,external_writer_list:!0});return}var y,X=function(d){var g=false,h=b.split("_");
b=h[0];h.length==2&&(g=h[1]);if(g!==false&&typeof d=="undefined")mist.send(function(a){X(a.push_auto_list[g])},{push_auto_list:1});else{var f=[],m=[],k={},q=[],i;for(i in mist.data.capabilities.connectors){h=mist.data.capabilities.connectors[i];if("push_urls"in h){k[i]=h.push_urls;for(var j in h.push_urls)h.push_urls[j][0]=="/"?f.push(h.push_urls[j]):m.push(h.push_urls[j])}}if(mist.data.external_writer_list)for(i in mist.data.external_writer_list){h=mist.data.external_writer_list[i];if(h.length>=
3)for(j in h[2])q.push(h[2][j]+"://")}f.sort();m.sort();b=="auto"&&c.find("h2").text("Add automatic push");var l={params:{}},n=[];if(b=="auto"&&typeof d!="undefined"){l={stream:d[0],target:d[1],params:{}};j=l.target.split("?");if(j.length>1){n=j.pop();l.target=j.join("?");n=n.split("&");for(i in n){j=n[i].split("=");l.params[j.shift()]=j.join("=")}}if(d.length>=3)l.scheduletime=d[2]!=0?d[2]:null;if(d.length>=4)l.completetime=d[3]!=0?d[3]:null;if(d.length>=5)l.startVariableName=d[4]!=""?d[4]:null;
if(d.length>=6)l.startVariableOperator=d[5]!=""?d[5]:null;if(d.length>=7)l.startVariableValue=d[6]!=""?d[6]:null;if(d.length>=8)l.endVariableName=d[7]!=""?d[7]:null;if(d.length>=9)l.endVariableOperator=d[8]!=""?d[8]:null;if(d.length>=10)l.endVariableValue=d[9]!=""?d[9]:null}var o=$("<div>").css("margin","1em 0"),p=$("<div>"),s,r;if(b=="auto"){p.css("margin","1em 0").html(UI.buildUI([{label:"This push should be active",help:"When 'based on server time' is selected, a start and/or end timestamp can be configured. When it's 'based on a variable', the push will be activated while the specified variable matches the specified value.",
type:"select",select:[["time","Based on server time"],["variable","Based on a variable"]],value:l.startVariableName||l.endVariableName?"variable":"time",classes:["activewhen"],"function":function(){var a=p.find(".varbased").closest(".UIelement"),b=p.find(".timebased").closest(".UIelement");if($(this).getval()=="time"){a.hide();b.css("display","")}else{b.hide();a.css("display","");p.find('[name="startVariableOperator"]').trigger("change");p.find('[name="endVariableOperator"]').trigger("change")}}},
$("<br>"),$("<span>").addClass("UIelement").append($("<h3>").text("Start the push").addClass("varbased")),{classes:["varbased"],label:"Use this variable",type:"str",help:"This variable should be used to determine if this push should be started.",prefix:"$",datalist:Object.keys(mist.data.variable_list||[]),pointer:{main:l,index:"startVariableName"}},{classes:["varbased"],label:"Comparison operator",type:"select",select:[[0,"is true"],[1,"is false"],[2,"=="],[3,"!="],[10,"> (numerical)"],[11,">= (numerical)"],
[12,"< (numerical)"],[13,"<= (numerical)"],[20,"> (lexical)"],[21,">= (lexical)"],[22,"< (lexical)"],[23,"<= (lexical)"]],value:2,css:{display:"none"},help:"How would you like to compare this variable?",pointer:{main:l,index:"startVariableOperator"},"function":function(){var a=p.find('[name="startVariableValue"]').closest(".UIelement");Number($(this).getval())<2?a.hide():a.css("display","")}},{classes:["varbased"],label:"Variable value",type:"str",help:"The variable will be compared with this value to determine if this push should be started.<br>You can also enter another variable here!",
datalist:Object.values(mist.data.variable_list||[]).map(function(a){return typeof a=="string"?a:a[3]}).concat(Object.keys(mist.data.variable_list||[]).map(function(a){return"$"+a})),pointer:{main:l,index:"startVariableValue"}},$("<span>").addClass("UIelement").append($("<h3>").text("Stop the push").addClass("varbased")),{classes:["varbased"],label:"Use this variable",type:"str",help:"This variable should be used to determine if this push should be stopped.<br>You can leave this field blank if you do not want to have a stop condition. (You can always stop the push manually)",
prefix:"$",datalist:Object.keys(mist.data.variable_list||[]),pointer:{main:l,index:"endVariableName"}},{classes:["varbased"],label:"Comparison operator",type:"select",select:[[0,"is true"],[1,"is false"],[2,"=="],[3,"!="],[10,"> (numerical)"],[11,">= (numerical)"],[12,"< (numerical)"],[13,"<= (numerical)"],[20,"> (lexical)"],[21,">= (lexical)"],[22,"< (lexical)"],[23,"<= (lexical)"]],value:2,help:"How would you like to compare this variable?",pointer:{main:l,index:"endVariableOperator"},"function":function(){var a=
p.find('[name="endVariableValue"]').closest(".UIelement");Number($(this).getval())<2?a.hide():a.css("display","")}},{classes:["varbased"],label:"Variable value",type:"str",help:"The variable will be compared with this value to determine if this push should be stopped.<br>You can also enter another variable here!",datalist:Object.values(mist.data.variable_list||[]).map(function(a){return typeof a=="string"?a:a[3]}).concat(Object.keys(mist.data.variable_list||[]).map(function(a){return"$"+a})),pointer:{main:l,
index:"endVariableValue"}},{classes:["timebased"],type:"unix",label:"Start time",min:0,help:"The time where the push will become active. The default is to start immediately.",pointer:{main:l,index:"scheduletime"}},{classes:["timebased"],type:"unix",label:"End time",min:0,help:"The time where the push will stop. Defaults to never stop automatically.<br>Only makes sense for live streams.",pointer:{main:l,index:"completetime"}}],l));p.find(".activewhen").trigger("change")}i=[{label:"Stream name",type:"str",
help:"This may either be a full stream name, a partial wildcard stream name, or a full wildcard stream name.<br>For example, given the stream <i>a</i> you can use: <ul> <li><i>a</i>: the stream configured as <i>a</i></li> <li><i>a+</i>: all streams configured as <i>a</i> with a wildcard behind it, but not <i>a</i> itself</li> <li><i>a+b</i>: only the version of stream <i>a</i> that has wildcard <i>b</i></li> </ul>",pointer:{main:l,index:"stream"},
validate:["required",function(a){a=a.split("+");a=a[0];return a in mist.data.streams?false:{msg:"'"+a+"' is not a stream name.",classes:["orange"],"break":false}}],datalist:y,value:e[1]!=""?e[1]:""},{label:"Target",type:"str",help:"Where the stream will be pushed to.<br> Valid push formats: <ul> <li>"+m.join("</li><li>")+"</li> </ul> Valid file formats: <ul> <li>"+f.join("</li><li>")+"</li> </ul> "+
(q.length?"Additionally, the following protocols (from generic writers) may be used in combination with any of the above file formats:<ul><li>"+q.join("</li><li>")+"</li></ul>":"")+" Valid text replacements: <ul> <li>$stream - inserts the stream name used to push to MistServer</li> <li>$day - inserts the current day number</li><li>$month - inserts the current month number</li> <li>$year - inserts the current year number</li><li>$hour - inserts the hour timestamp when stream was received</li> <li>$minute - inserts the minute timestamp the stream was received</li> <li>$seconds - inserts the seconds timestamp when the stream was received</li> <li>$datetime - inserts $year.$month.$day.$hour.$minute.$seconds timestamp when the stream was received</li> </ul>",
pointer:{main:l,index:"target"},validate:["required",function(a){for(var b in m)if(mist.inputMatch(m[b],a))return false;for(b in f){if(mist.inputMatch(f[b],a))return false;for(var c in q)if(mist.inputMatch(q[c]+f[b].slice(1),a))return false}return{msg:"Does not match a valid target.<br>Valid push formats: <ul> <li>"+m.join("</li><li>")+"</li> </ul> Valid file formats: <ul> <li>"+f.join("</li><li>")+
"</li> </ul> "+(q.length?"Additionally, the following protocols may be used in combination with any of the above file formats:<ul><li>"+q.join("</li><li>")+"</li></ul>":""),classes:["red"]}}],"function":function(){function a(b,d){if(b.prot_only&&String().match&&c.match(/.+\:\/\/.+/)===null)delete s[d];else if(b.file_only&&c[0]!="/")delete s[d];else if(b.type=="group")for(var e in b.options)a(b.options[e],e);else r[d]=b}var b=false,c=$(this).getval();for(connector in k)for(var d in k[connector]){if(mist.inputMatch(k[connector][d],
c)){b=connector;break}if(k[connector][d][0]=="/")for(var e in q)if(mist.inputMatch(q[e]+k[connector][d].slice(1),c)){b=connector;break}}if(b){if(!("friendly"in mist.data.capabilities.connectors[b]))mist.data.capabilities.connectors[b].friendly=mist.data.capabilities.connectors[b].name;o.html($("<h3>").text(mist.data.capabilities.connectors[b].friendly.replace("over HTTP","")));s=$.extend({},mist.data.capabilities.connectors[b].push_parameters);r={};for(d in mist.data.capabilities.connectors[b].push_parameters)a(mist.data.capabilities.connectors[b].push_parameters[d],
d);b={desc:mist.data.capabilities.connectors[b].desc.replace("over HTTP",""),optional:s,sort:"sort"};b=mist.convertBuildOptions(b,l.params);e=[];for(d in n){var g=n[d].split("="),h=g[0];h in s||e.push(h+(g.length>1?"="+g.slice(1).join("="):""))}b.push($("<br>"));b.push({type:"inputlist",label:"Custom url parameters",value:e,classes:["custom_url_parameters"],input:{type:"str",placeholder:"name=value",prefix:""},help:"Any custom url parameters not covered by the parameters configurable above.",pointer:{main:l,
index:"custom_url_params"}});o.append(UI.buildUI(b))}else o.html($("<h4>").addClass("red").text("Unrecognized target.")).append($("<span>").text("Please edit the push target."))}},p,o];i.push({type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){e[0]&&e[0]!=a?UI.navto(e[0],e[1]):UI.navto("Push")}},{type:"save",label:"Save",preSave:function(){delete l.startVariableName;delete l.startVariableOperator;delete l.startVariableValue;delete l.endVariableName;delete l.endVariableOperator;
delete l.endVariableValue;delete l.completetime;delete l.scheduletime},"function":function(){var c=l.params,g;for(g in c)c[g]===null?delete c[g]:g in r||delete c[g];if(l.startVariableName||l.endVariableName){l.scheduletime=0;l.completetime=0}if(l.startVariableName===null){delete l.startVariableName;delete l.startVariableOperator;delete l.startVariableValue}if(l.endVariableName===null){delete l.endVariableName;delete l.endVariableOperator;delete l.endVariableValue}if(l.scheduletime)c.recstartunix=
l.scheduletime;if(Object.keys(c).length||l.custom_url_params&&l.custom_url_params.length){var h="?",f=l.target.split("?");if(f.length>1){h="&";f=f[f.length-1];f=f.split("&");for(g in f){var m=f[g].split("=")[0];m in c&&delete c[m]}}if(Object.keys(c).length||l.custom_url_params&&l.custom_url_params.length){f=[];for(g in c)f.push(g+"="+c[g]);for(g in l.custom_url_params)f.push(l.custom_url_params[g]);h=h+f.join("&");l.target=l.target+h}}delete l.params;delete l.custom_url_params;c={};c[b=="auto"?"push_auto_add":
"push_start"]=l;if(typeof d!="undefined"&&(d[0]!=l.stream||d[1]!=l.target))c.push_auto_remove=[d];mist.send(function(){e[0]&&e[0]!=a?UI.navto(e[0],e[1]):UI.navto("Push")},c)}}]});c.append(UI.buildUI(i))}};mist.data.LTS?mist.send(function(a){(y=a.active_streams)||(y=[]);var a=[],b;for(b in y)y[b].indexOf("+")!=-1&&a.push(y[b].replace(/\+.*/,"")+"+");y=y.concat(a);var c=0,d=0;for(b in mist.data.streams){y.push(b);if(mist.inputMatch(UI.findInput("Folder").source_match,mist.data.streams[b].source)){y.push(b+
"+");mist.send(function(a,b){var e=b.stream,g;for(g in a.browse.files)for(var h in mist.data.capabilities.inputs)h.indexOf("Buffer")>=0||(h.indexOf("Folder")>=0||h.indexOf("Buffer.exe")>=0||h.indexOf("Folder.exe")>=0)||mist.inputMatch(mist.data.capabilities.inputs[h].source_match,"/"+a.browse.files[g])&&y.push(e+"+"+a.browse.files[g]);d++;if(c==d){y=y.filter(function(a,b,c){return c.lastIndexOf(a)===b}).sort();X()}},{browse:mist.data.streams[b].source},{stream:b});c++}}if(c==d){y=y.filter(function(a,
b,c){return c.lastIndexOf(a)===b}).sort();X()}},{active_streams:1}):(y=Object.keys(mist.data.streams),X());break;case "Triggers":if(!("triggers"in mist.data.config)||!mist.data.config.triggers)mist.data.config.triggers={};C=$("<tbody>");E=$("<table>").html($("<thead>").addClass("sticky").html($("<tr>").html($("<th>").text("Trigger on").attr("data-sort-type","string").addClass("sorting-asc")).append($("<th>").text("Applies to").attr("data-sort-type","string")).append($("<th>").text("Handler").attr("data-sort-type",
"string")).append($("<th>")))).append(C);c.append(UI.buildUI([{type:"help",help:"Triggers are a way to react to events that occur inside MistServer. These allow you to block specific users, redirect streams, keep tabs on what is being pushed where, etcetera. For full documentation, please refer to the developer documentation section on the MistServer website."}])).append($("<button>").text("New trigger").click(function(){UI.navto("Edit Trigger")})).append(E);E.stupidtable();k=mist.data.config.triggers;
for(p in k)for(s in k[p])g=triggerRewrite(k[p][s]),C.append($("<tr>").attr("data-index",p+","+s).append($("<td>").text(p)).append($("<td>").text("streams"in g?g.streams.join(", "):"")).append($("<td>").text(g.handler)).append($("<td>").html($("<button>").text("Edit").click(function(){UI.navto("Edit Trigger",$(this).closest("tr").attr("data-index"))})).append($("<button>").text("Delete").click(function(){var a=$(this).closest("tr").attr("data-index").split(",");if(confirm("Are you sure you want to delete this "+
a[0]+" trigger?")){mist.data.config.triggers[a[0]].splice(a[1],1);mist.data.config.triggers[a[0]].length==0&&delete mist.data.config.triggers[a[0]];mist.send(function(){UI.navto("Triggers")},{config:mist.data.config})}}))));break;case "Edit Trigger":if(!("triggers"in mist.data.config)||!mist.data.config.triggers)mist.data.config.triggers={};if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.showTab(a,b,e)},{capabilities:!0});c.append("Loading..");return}b?(b=b.split(","),k=triggerRewrite(mist.data.config.triggers[b[0]][b[1]]),
r={triggeron:b[0],appliesto:k.streams,url:k.handler,async:k.sync,"default":k["default"],params:k.params}):(c.html($("<h2>").text("New Trigger")),r={});k=[];for(p in mist.data.capabilities.triggers)k.push([p,p+": "+mist.data.capabilities.triggers[p].when]);var ba=$("<div>").addClass("desc"),pa=$("<div>");c.append(UI.buildUI([{label:"Trigger on",pointer:{main:r,index:"triggeron"},help:"For what event this trigger should activate.",type:"select",select:k,validate:["required"],"function":function(){var a=
$(this).getval(),b=mist.data.capabilities.triggers[a];ba.html("");if(b){a=[$("<h4>").text("Trigger properties"),{type:"help",help:'The trigger "<i>'+a+'</i>" has the following properties:'},{type:"span",label:"Triggers",value:b.when,help:"When this trigger is activated"}];b.payload!=""&&a.push({label:"Payload",type:"textarea",value:b.payload,rows:b.payload.split("\n").length,readonly:true,clipboard:true,help:"The information this trigger sends to the handler."});a.push({type:"span",label:"Requires response",
value:function(a){switch(a){case "ignored":return"No. The trigger will ignore the response of the handler.";case "always":return"Yes. The trigger needs a response to proceed.";case "when-blocking":return"The trigger needs a response to proceed if it is configured to be blocking.";default:return a}}(b.response),help:"Whether this trigger requires a response from the trigger handler"});a.push({type:"span",label:"Response action",value:b.response_action,help:"What this trigger will do with its handler's response"});
ba.append(UI.buildUI(a));b.stream_specific?$("[name=appliesto]").closest(".UIelement").show():$("[name=appliesto]").setval([]).closest(".UIelement").hide();if(b.argument){$("[name=params]").closest(".UIelement").show();pa.text(b.argument)}else $("[name=params]").setval("").closest(".UIelement").hide()}}},ba,$("<h4>").text("Trigger settings"),{label:"Applies to",pointer:{main:r,index:"appliesto"},help:"For triggers that can apply to specific streams, this value decides what streams they are triggered for. (none checked = always triggered)",
type:"checklist",checklist:Object.keys(mist.data.streams),value:""!=e[1]?[e[1]]:[]},$("<br>"),{label:"Handler (URL or executable)",help:"This can be either an HTTP URL or a full path to an executable.",pointer:{main:r,index:"url"},validate:["required"],type:"str"},{label:"Blocking",type:"checkbox",help:"If checked, pauses processing and uses the response of the handler. If the response does not start with 1, true, yes or cont, further processing is aborted. If unchecked, processing is never paused and the response is not checked.",
pointer:{main:r,index:"async"}},{label:"Parameters",type:"str",help:$("<div>").text("The extra data you want this trigger to use.").append(pa),pointer:{main:r,index:"params"}},{label:"Default response",type:"str",help:"The default response in case the handler fails or is set to non-blocking.",placeholder:"true",pointer:{main:r,index:"default"}},{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){e[0]&&e[0]!=a?UI.navto(e[0],e[1]):UI.navto("Triggers")}},{type:"save",label:"Save",
"function":function(){b&&mist.data.config.triggers[b[0]].splice(b[1],1);var c={handler:r.url,sync:r.async?true:false,streams:typeof r.appliesto=="undefined"?[]:r.appliesto,params:r.params,"default":r["default"]};if(!("triggers"in mist.data.config))mist.data.config.triggers={};r.triggeron in mist.data.config.triggers||(mist.data.config.triggers[r.triggeron]=[]);mist.data.config.triggers[r.triggeron].push(c);mist.send(function(){e[0]&&e[0]!=a?UI.navto(e[0],e[1]):UI.navto("Triggers")},{config:mist.data.config})}}]}]));
$("[name=triggeron]").trigger("change");break;case "Logs":var qa=$("<button>").text("Refresh now").click(function(){$(this).text("Loading..");mist.send(function(){ca();qa.text("Refresh now")})}).css("padding","0.2em 0.5em").css("flex-grow",0);c.append(UI.buildUI([{type:"help",help:"Here you have an overview of all edited settings within MistServer and possible warnings or errors MistServer has encountered. MistServer stores up to 100 logs at a time."},{label:"Refresh every",type:"select",select:[[10,
"10 seconds"],[30,"30 seconds"],[60,"minute"],[300,"5 minutes"]],value:30,"function":function(){UI.interval.clear();UI.interval.set(function(){mist.send(function(){ca()})},$(this).val()*1E3)},help:"How often the table below should be updated."},{label:"..or",type:"DOMfield",DOMfield:qa,help:"Instantly refresh the table below."}]));c.append($("<button>").text("Purge logs").click(function(){mist.send(function(){mist.data.log=[];UI.navto("Logs")},{clearstatlogs:true})}));C=$("<tbody>").css("font-size",
"0.9em");c.append($("<table>").addClass("logs").append(C));var sa=function(a){var b=$("<span>").text(a);switch(a){case "WARN":b.addClass("orange");break;case "ERROR":case "FAIL":b.addClass("red")}return b},ca=function(){var a=mist.data.log;if(a){a.length>=2&&a[0][0]<a[a.length-1][0]&&a.reverse();C.html("");for(var b in a){var c=$("<span>").addClass("content");a[b].length>=4&&a[b][3]!=""&&c.append($("<span>").text("["+a[b][3]+"] "));var d=a[b][2].split("|"),e;for(e in d)c.append($("<span>").text(d[e]));
C.append($("<tr>").html($("<td>").text(UI.format.dateTime(a[b][0],"long")).css("white-space","nowrap")).append($("<td>").html(sa(a[b][1])).css("text-:align","center")).append($("<td>").html(c).css("text-align","left")))}}};ca();break;case "Statistics":var H=$("<span>").text("Loading..");c.append(H);var r={graph:"new"},B=mist.stored.get().graphs?$.extend(!0,{},mist.stored.get().graphs):{},T={};for(p in mist.data.streams)T[p]=!0;for(p in mist.data.active_streams)T[mist.data.active_streams[p]]=!0;var T=
Object.keys(T).sort(),da=[];for(p in mist.data.config.protocols)da.push(mist.data.config.protocols[p].connector);da.sort();mist.send(function(){UI.plot.datatype.templates.cpuload.cores=0;for(var a in mist.data.capabilities.cpu)UI.plot.datatype.templates.cpuload.cores=UI.plot.datatype.templates.cpuload.cores+mist.data.capabilities.cpu[a].cores;H.html(UI.buildUI([{type:"help",help:"Here you will find the MistServer stream statistics, you can select various categories yourself. All statistics are live: up to five minutes are saved."},
$("<h3>").text("Select the data to display"),{label:"Add to",type:"select",select:[["new","New graph"]],pointer:{main:r,index:"graph"},classes:["graph_ids"],"function":function(){if($(this).val()){var a=H.find(".graph_xaxis"),b=H.find(".graph_id");if($(this).val()=="new"){a.children("option").prop("disabled",false);b.setval("Graph "+(Object.keys(B).length+1)).closest("label").show()}else{var c=B[$(this).val()].xaxis;a.children("option").prop("disabled",true).filter('[value="'+c+'"]').prop("disabled",
false);b.closest("label").hide()}a.children('option[value="'+a.val()+'"]:disabled').length&&a.val(a.children("option:enabled").first().val());a.trigger("change")}}},{label:"Graph id",type:"str",pointer:{main:r,index:"id"},classes:["graph_id"],validate:[function(a){return a in B?{msg:"This graph id has already been used. Please enter something else.",classes:["red"]}:false}]},{label:"Axis type",type:"select",select:[["time","Time line"]],pointer:{main:r,index:"xaxis"},value:"time",classes:["graph_xaxis"],
"function":function(){$s=H.find(".graph_datatype");switch($(this).getval()){case "coords":$s.children("option").prop("disabled",true).filter('[value="coords"]').prop("disabled",false);break;case "time":$s.children("option").prop("disabled",false).filter('[value="coords"]').prop("disabled",true)}if(!$s.val()||$s.children('option[value="'+$s.val()+'"]:disabled').length){$s.val($s.children("option:enabled").first().val());$s.trigger("change")}}},{label:"Data type",type:"select",select:[["clients","Connections"],
["upbps","Bandwidth (up)"],["downbps","Bandwidth (down)"],["cpuload","CPU use"],["memload","Memory load"],["coords","Client location"],["perc_lost","Lost packages"],["perc_retrans","Re-transmitted packages"]],pointer:{main:r,index:"datatype"},classes:["graph_datatype"],"function":function(){$s=H.find(".graph_origin");switch($(this).getval()){case "cpuload":case "memload":$s.find("input[type=radio]").not('[value="total"]').prop("disabled",true);$s.find('input[type=radio][value="total"]').prop("checked",
true);break;default:$s.find("input[type=radio]").prop("disabled",false)}}},{label:"Data origin",type:"radioselect",radioselect:[["total","All"],["stream","The stream:",T],["protocol","The protocol:",da]],pointer:{main:r,index:"origin"},value:["total"],classes:["graph_origin"]},{type:"buttons",buttons:[{label:"Add data set",type:"save","function":function(){var a;if(r.graph=="new"){a=UI.plot.addGraph(r,b);B[a.id]=a;H.find("input.graph_id").val("");H.find("select.graph_ids").append($("<option>").text(a.id)).val(a.id).trigger("change")}else a=
B[r.graph];var c=UI.plot.datatype.getOptions({datatype:r.datatype,origin:r.origin});a.datasets.push(c);UI.plot.save(a);UI.plot.go(B)}}]}]));var b=$("<div>").addClass("graph_container");c.append(b);var d=H.find("select.graph_ids");for(a in B){var e=UI.plot.addGraph(B[a],b);d.append($("<option>").text(e.id)).val(e.id);var g=[],h;for(h in B[a].datasets){var f=UI.plot.datatype.getOptions({datatype:B[a].datasets[h].datatype,origin:B[a].datasets[h].origin});g.push(f)}e.datasets=g;B[e.id]=e}d.trigger("change");
UI.plot.go(B);UI.interval.set(function(){UI.plot.go(B)},1E4)},{active_streams:!0,capabilities:!0});break;case "Server Stats":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.showTab(a)},{capabilities:!0});c.append("Loading..");return}var ea=$("<table>"),fa=$("<table>"),k={vheader:"CPUs",labels:["Model","Processor speed","Amount of cores","Amount of threads"],content:[]};for(p in mist.data.capabilities.cpu)s=mist.data.capabilities.cpu[p],k.content.push({header:"CPU #"+(Number(p)+
1),body:[s.model,UI.format.addUnit(UI.format.number(s.mhz),"MHz"),s.cores,s.threads]});p=UI.buildVheaderTable(k);var ra=function(){var a=mist.data.capabilities.mem,b=mist.data.capabilities.load,a={vheader:"Memory",labels:["Used","Cached","Available","Total"],content:[{header:"Physical memory",body:[UI.format.bytes(a.used*1048576)+" ("+UI.format.addUnit(b.memory,"%")+")",UI.format.bytes(a.cached*1048576),UI.format.bytes(a.free*1048576),UI.format.bytes(a.total*1048576)]},{header:"Swap memory",body:[UI.format.bytes((a.swaptotal-
a.swapfree)*1048576),UI.format.addUnit("","N/A"),UI.format.bytes(a.swapfree*1048576),UI.format.bytes(a.swaptotal*1048576)]}]},a=UI.buildVheaderTable(a);ea.replaceWith(a);ea=a;b={vheader:"Load average",labels:["CPU use","1 minute","5 minutes","15 minutes"],content:[{header:"&nbsp;",body:[UI.format.addUnit(UI.format.number(mist.data.capabilities.cpu_use/10),"%"),UI.format.number(b.one/100),UI.format.number(b.five/100),UI.format.number(b.fifteen/100)]}]};b=UI.buildVheaderTable(b);fa.replaceWith(b);fa=
b};ra();c.append(UI.buildUI([{type:"help",help:"You can find general server statistics here. Note that memory and CPU usage is for your entire machine, not just MistServer."}])).append($("<table>").css("width","auto").addClass("nolay").append($("<tr>").append($("<td>").append(ea)).append($("<td>").append(fa))).append($("<tr>").append($("<td>").append(p).attr("colspan",2))));UI.interval.set(function(){mist.send(function(){ra()},{capabilities:true})},3E4);break;case "Email for Help":p=$.extend({},mist.data);
delete p.statistics;delete p.totals;delete p.clients;delete p.capabilities;p=JSON.stringify(p);p="Version: "+mist.data.config.version+"\n\nConfig:\n"+p;r={};c.append(UI.buildUI([{type:"help",help:"You can use this form to email MistServer support if you're having difficulties.<br>A copy of your server config file will automatically be included."},{type:"str",label:"Your name",validate:["required"],pointer:{main:r,index:"name"},value:mist.user.name},{type:"email",label:"Your email address",validate:["required"],
pointer:{main:r,index:"email"}},{type:"hidden",value:"Integrated Help",pointer:{main:r,index:"subject"}},{type:"hidden",value:"-",pointer:{main:r,index:"company"}},{type:"textarea",rows:20,label:"Your message",validate:["required"],pointer:{main:r,index:"message"}},{type:"textarea",rows:20,label:"Your config file",readonly:!0,value:p,pointer:{main:r,index:"configfile"}},{type:"buttons",buttons:[{type:"save",label:"Send","function":function(a){$(a).text("Sending..");$.ajax({type:"POST",url:"https://mistserver.org/contact?skin=plain",
data:r,success:function(a){a=$("<span>").html(a);a.find("script").remove();c.html(a[0].innerHTML)}})}}]}]));break;case "Disconnect":mist.user.password="";delete mist.user.authstring;delete mist.user.loggedin;mist.data={};UI.sockets.http_host=null;sessionStorage.removeItem("mistLogin");UI.navto("Login");break;default:c.append($("<p>").text("This tab does not exist."))}c.find(".field").filter(function(){var a=$(this).getval();return a==""||a==null?true:false}).each(function(){var a=[];$(this).is("input, select, textarea")?
a.push($(this)):a=$(this).find("input, select, textarea");if(a.length){$(a[0]).focus();return false}})},dynamic:function(a,b){var a=Object.assign({},a),e=a.create(b);if(e){e.raw="";a.getEntry||(a.getEntry=function(a,b){return b in a?a[b]:!1});a.getEntries||(a.getEntries=function(a){return a});e.update&&(a.update=e.update);a.update||(a.update=function(){});if("object"==typeof a.add){var c=a.add;a.add=function(a){return UI.dynamic(c,a)}}a.add&&(e._children={},e.add=function(b){var c=a.add.call(e,b);
if(c){c.remove=function(){var a=this;a instanceof jQuery&&(a=a[0]);a.parentNode&&a.parentNode.removeChild(a);delete e._children[b]};c._id=b;e._children[b]=c;c.customAdd?c.customAdd(e):e.append(c)}});e.update=function(b,c){var i=a.getEntries(b,e._id),f=JSON.stringify(i);if(this.raw!=f){this.values=i;this.values_orig=b;if(a.add){for(var m in i){m in this._children||this.add(m);m in this._children&&this._children[m].update.call(this._children[m],i[m],i)}for(var n in this._children)n in i||this._children[n].remove()}a.update.call(e,
i,c);this.raw=f}};a.values&&e.update.call(e,a.values);return e}},modules:{stream:{header:function(a,b,e){function c(c){if(!c)return $("<span>").addClass("spacer");var e=c;"string"!=typeof c&&(e=c[0],c=c[1]);return $("<li>").addClass("tab").addClass(c==b?"active":!1).attr("tabindex",0).attr("data-icon",c).text(e).click(function(){if(!(b=="Edit"&&d.attr("data-changed"))||confirm("Your settings have not been saved. Are you sure you want to navigate away?"))UI.navto(c,c=="Streams"?"":a)})}var d=$("<div>").addClass("header"),
j=$("<ul>").addClass("tabnav");d.append($("<div>").css("display","flex").css("align-items","baseline").append($("<h2>").text('Stream "'+a+'"')).append(UI.modules.stream.status(a,{tags:!1,thumbnail:!1,livestreamhint:!1}))).append(j).append($("<h2>").text("Edit"==b?'Edit "'+e+'"':b));var e=[["Settings","Edit"],"Status","Preview","Embed"],i=!1;if(0>a.indexOf("+")){var f=mist.data.streams[a];if(f.source&&(f.source.match(/^\/.+\/$/)||f.source.match(/^folder:.+$/)))i=!0}i&&(e.pop(),e.pop());e.push(!1);
e.push(["Overview","Streams"]);j.append($("<span>").addClass("curtab-icon").attr("data-icon",b));for(var m in e)j.append(c(e[m]));return d},bigbuttons:function(a,b){var e=$("<div>").addClass("bigbuttons");e.append($("<button>").text("Settings").addClass("settings").click(function(){UI.navto("Edit",a)}));var c=!1;if(0>a.indexOf("+")){var d=mist.data.streams[a];if(d.source&&(d.source.match(/^\/.+\/$/)||d.source.match(/^folder:.+$/)))c=!0}"Status"!=b&&e.append($("<button>").text("Status").addClass("status").click(function(){UI.navto("Status",
a)}));"Preview"!=b&&!c&&e.append($("<button>").text("Preview").addClass("preview").click(function(){UI.navto("Preview",a)}));"Embed"!=b&&!c&&e.append($("<button>").text("Embed").addClass("embed").click(function(){UI.navto("Embed",a)}));e.append($("<button>").addClass("cancel").addClass("return").text("Return").click(function(){UI.navto("Streams")}));return e},findMist:function(a,b,e){function c(a){function b(a){for(var c=[],d=0;d<a.length;d++)a.indexOf(a[d])==d&&c.push(a[d]);return c}var d={HTTP:[],
HTTPS:[]},q=d.HTTP,h=d.HTTPS;if(UI.sockets.http_host)if(e)q.push(UI.sockets.http_host),h.push(UI.sockets.http_host);else return a([UI.sockets.http_host]);if(mist.data.capabilities){var g=mist.stored.get();"HTTPurl"in g&&("https"==g.HTTPurl.slice(0,5)?h.push(g.HTTPurl):q.push(g.HTTPurl));for(var l in mist.data.config.protocols){var g=mist.data.config.protocols[l],i=g.connector,i=(""+i).replace(".exe","");switch(g.connector){case "HTTP":case "HTTPS":if(g.pubaddr)for(var j in g.pubaddr){var p=g.pubaddr[j].split(":")[0].toUpperCase();
d[p].push(g.pubaddr[j])}(p=g.port)||g.connector in mist.data.capabilities.connectors&&(p=mist.data.capabilities.connectors[g.connector].optional.port["default"]);p&&d[g.connector].push(parseURL(mist.user.host,{port:p,pathname:"",protocol:i.toLowerCase()+":"}).full)}}q.length||q.push(parseURL(mist.user.host,{port:8080,pathname:""}).full);h.length||(h=q);q=b(q);h=b(h);f.urls=d;return a("https:"==location.protocol?h:q)}mist.send(function(){c(a)},{capabilities:!0})}function d(a,c){if(c>=a.length)return j();
try{if(b||(b=function(a){return a+"player.js"}),url=b(a[c]),"http"==url.slice(0,4))$.ajax({type:"GET",url:url,success:function(b){f.hide();i(a[c],b)},error:function(){d(a,c+1)}});else if("ws"==url.slice(0,2)){var e=UI.websockets.create(url);e.onopen=function(){e.onerror=function(){};f.hide();i(a[c],e)};e.onerror=function(){d(a,c+1)}}else throw"I'm not sure how to contact MistServer with this protocol. (at "+url+")";}catch(q){j(a)}}function j(a){1==a.length&&a[0]==UI.sockets.http_host&&(UI.sockets.http_host=
null,c(function(b){a=b;d(b,0)}));var b={};f.show().html($("<p>").text("Could not locate the MistHTTP output url. Where can it be reached?")).append($("<div>").addClass("description").append($("<p>").text("Attempts:")).append($("<ul>").html("<li>"+a.join("</li><li>")+"</li>"))).append(UI.buildUI([{label:"MistServer HTTP endpoint",type:"datalist",datalist:a,help:"Please specify the url at which MistServer's HTTP endpoint can be reached.",pointer:{main:b,index:"url"}},{type:"buttons",buttons:[{type:"save",
label:"Connect","function":function(){a.unshift(b.url);d(a,0)}}]}]))}function i(b,c){b!=UI.sockets.http_host&&(UI.sockets.http_host=b,mist.stored.set("HTTPUrl",b));a.call(f,b,c)}var f=$("<div>").addClass("findMist").hide();c(function(a){d(a,0)});f.getUrls=function(){return f.urls};return f},livestreamhint:function(a){var b=$("<div>").addClass("livestreamhint"),e=mist.data.streams[a.split("+")[0]];if(e.source&&"/"!=e.source.slice(0,1)&&!e.source.match(/-exec:/)){var c=null,d;for(d in mist.data.capabilities.inputs)if("undefined"!=
typeof mist.data.capabilities.inputs[d].source_match&&mist.inputMatch(mist.data.capabilities.inputs[d].source_match,e.source)){c=d;break}if(c){c=mist.data.capabilities.inputs[c];d=[$("<span>").text("Configure your source to push to:")];switch(c.name){case "Buffer":case "Buffer.exe":d.push({label:"RTMP full url",type:"span",clipboard:!0,readonly:!0,classes:["RTMP"],help:"Use this RTMP url if your client doesn't ask for a stream key"});d.push({label:"RTMP url",type:"span",clipboard:!0,readonly:!0,classes:["RTMPurl"],
help:"Use this RTMP url if your client also asks for a stream key"});d.push({label:"RTMP stream key",type:"span",clipboard:!0,readonly:!0,classes:["RTMPkey"],help:"Use this key if your client asks for a stream key"});d.push({label:"SRT",type:"span",clipboard:!0,readonly:!0,classes:["TSSRT"]});d.push({label:"RTSP",type:"span",clipboard:!0,readonly:!0,classes:["RTSP"]});break;case "TS":case "TS.exe":"/"==e.source.charAt(0)?d=[]:d.push({label:"TS",type:"span",clipboard:!0,readonly:!0,classes:["TS"]});
break;case "TSSRT":case "TSSRT.exe":d.push({label:"SRT",type:"span",clipboard:!0,readonly:!0,classes:["TSSRT"]});break;default:d=[]}d.length&&(b.html(UI.buildUI(d)),UI.updateLiveStreamHint(a,e.source,b))}}else return!1;return b},status:function(a,b){b||(b={});var b=Object.assign({livestreamhint:!0,status:!0,stats:!0,tags:!0,thumbnail:!0},b),e=$("<div>").addClass("activestream"),c=b.status?$("<div>").attr("data-streamstatus",0).text("Offline").hide():!1,d=b.stats?$("<span>").attr("beforeifnotempty",
"Viewers: "):!1,j=b.stats?$("<span>").attr("beforeifnotempty","Inputs: "):!1,i=b.stats?$("<span>").attr("beforeifnotempty","Outputs: "):!1,f=b.tags?{cont:$("<div>").attr("beforeifnotempty","Tags: "),children:{},ele:function(c){var d=$("<span>").addClass("tag").text(c);"readonly"!=b.tags&&d.append($("<button>").text("\ud83d\uddd9").attr("title","Remove tag").click(function(){var b=$(this),d={};d[a]=c;b.parent().text("Removing..");mist.send(function(){b.parent().remove()},{untag_stream:d})}));return this.children[c]=
d},update:function(a){var a=""==a?[]:a.split(" "),b={},c;for(c in a){var d=a[c];b[d]=1;d in this.children||this.cont.append(this.ele(d))}for(c in this.children)c in b||(this.children[c].remove(),delete this.children[c])}}:!1,m=b.tags&&"readonly"!=b.tags?$("<div>").addClass("input_container").css("display","block").html($("<input>").attr("placeholder","Tag name").on("keydown",function(a){switch(a.key){case " ":a.preventDefault();break;case "Enter":$(this).parent().find("button").click()}})).append($("<button>").text("Add tag").click(function(){var b=
{},c=$(this),d=c.parent().find("input");b[a]=d.val();c.text("Adding..");mist.send(function(){c.text("Add tag");d.val("")},{tag_stream:b})})):!1,n=b.livestreamhint?UI.modules.stream.livestreamhint(a):!1;e.html(c).append(d).append(j).append(i).append(f?f.cont:!1).append(m).append(b.thumbnail?UI.modules.stream.thumbnail(a):!1).append(n);UI.sockets.ws.active_streams.subscribe(function(e,m){b.status&&c.css("display","");if("stream"==e&&m[0]==a){var h="Offline;Initializing;Booting;Waiting for data;Available;Shutting down;Invalid state".split(";");
b.status&&c.attr("data-streamstatus",m[1]).text(h[m[1]]);b.stats&&(d.text(m[2]),j.text(0<m[3]?m[3]:""),i.text(0<m[4]?m[4]:""));b.tags&&f.update(m[5]);n&&(0==m[1]?n.show():n.hide())}});return $("<section>").addClass("activestream").append(e)},actions:function(a,b){return $("<section>").addClass("actions").addClass("bigbuttons").html($("<button>").text("Stop all sessions").attr("data-icon","stop").attr("title","Disconnect sessions for this stream. Disconnecting a session will kill any currently open connections (viewers, pushes and possibly the input). If the USER_NEW trigger is in use, it will be triggered again by any reconnecting connections.").click(function(){confirm("Are you sure you want to disconnect all sessions (viewers, pushes and possibly the input) from this stream?")&&
mist.send(function(){},{stop_sessions:b})})).append($("<button>").text("Invalidate sessions").attr("data-icon","invalidate").attr("title","Invalidate all the currently active sessions for this stream. This has the effect of re-triggering the USER_NEW trigger, allowing you to selectively close some of the existing connections after they have been previously allowed. If you don't have a USER_NEW trigger configured, this will not have any effect.").click(function(){confirm("Are you sure you want to invalidate all sessions for the stream '"+
b+"'?\nThis will re-trigger the USER_NEW trigger.")&&mist.send(function(){},{invalidate_sessions:b})})).append($("<button>").text("Nuke stream").attr("data-icon","nuke").attr("title","Shut down a running stream completely and/or clean up any potentially left over stream data in memory. It attempts a clean shutdown of the running stream first, followed by a forced shut down, and then follows up by checking for left over data in memory and cleaning that up if any is found.").click(function(){confirm("Are you sure you want to completely shut down the stream '"+
b+"'?\nAll viewers will be disconnected.")&&mist.send(function(){UI.showTab(a,b)},{nuke_stream:b})}))},thumbnail:function(a,b){if(UI.findOutput("JPG")){var e,c,d=$("<img>").hover(function(){e&&c&&$(this).attr("src",c)},function(){e&&c&&$(this).attr("src",e)});UI.sockets.ws.info_json.subscribe(function(a){if(a.source){for(var b in a.source)if("html5/image/jpeg"==a.source[b].type){var m=a.source[b].url;-1<m.indexOf(".mjpg")?c=m:e=m;if(e&&c)break}if(c||e)c?e||(e=c):c=e,d.attr("src",e),j&&j.attr("src",
e)}},a);var j;b&&b.clone&&(j=$("<img>").addClass("clone"));return $("<section>").addClass("thumbnail").html(d).append(j)}},metadata:function(a,b){function e(b){if(!d.freeze)if(b.error&&(!c.rawdata||"live"==c.rawdata.type))c.html("").attr("onempty",b.error+".");else{if(c.rawdata&&"live"==c.rawdata.type||!b.error)c.rawdata=b;d.parent().length||c.html($("<div>").append($("<button>").text("Open raw json").click(function(){var b=window.open(null,"Stream info json for "+a);b.document.write("<html><head><title>Raw stream metadata for '"+
a+'\'</title><meta http-equiv="content-type" content="application/json; charset=utf-8"></head><body><code><pre>'+JSON.stringify(c.rawdata,null,2)+"</pre></code></body></html>");b.document.close()})).append($("<button>").text("Freeze").attr("title","Pauze updating the stream metadata information below").click(function(){"Freeze"==$(this).text()?($(this).text("Frozen").css("background","#bbb"),d.freeze=!0):($(this).text("Freeze")[0].style.background="",d.freeze=!1)}))).append(d);d.freeze||d.update(b)}}
b||(b={});var b=Object.assign({tracktable:!0,tracktiming:!0},b),c=$("<div>").addClass("meta").text("Loading.."),d=UI.dynamic({create:function(){var a=$("<span>");a.main=UI.dynamic({create:function(){var c=$("<div>").addClass("main").addClass("input_container");c.type=$("<span>");c.html($("<label>").append($("<span>").text("Type:")).append(c.type));c.buffer=$("<span>");c.append($("<label>").attr("data-liveonly","").append($("<span>").text("Buffer window:")).append(c.buffer));c.jitter=$("<span>");c.append($("<label>").attr("data-liveonly",
"").append($("<span>").text("Jitter:")).append(c.jitter));b.tracktiming&&(c.timing=UI.dynamic({create:function(){var a=$("<div>").addClass("tracktiming");a.box=$("<div>").addClass("boxcont");a.box.label=$("<span>").addClass("center");a.box.left=$("<span>").addClass("left");a.box.right=$("<span>").addClass("right");a.box.append($("<div>").addClass("box")).append(a.box.label).append(a.box.left).append(a.box.right);a.append(a.box);a.bounds=null;a.mstopos=function(a){return!this.bounds?25:100*((a-this.bounds.firstms.min)/
(this.bounds.lastms.max-this.bounds.firstms.min))};a.mstosize=function(a){return!this.bounds?10:100*(a/(this.bounds.lastms.max-this.bounds.firstms.min))};return a},add:{create:function(a){a=$("<div>").addClass("track").attr("data-track",a);a.label=$("<label>");a.box=$("<div>").addClass("box");a.jitter=$("<div>").addClass("jitter");a.box.append(a.jitter);a.left=$("<span>").addClass("left").attr("beforeifnotempty","-");a.right=$("<span>").addClass("right").attr("beforeifnotempty","+");a.box.append(a.left);
a.box.append(a.right);a.append(a.box).append(a.label);return a},update:function(a){a.type!=this.raw_type&&this.attr("data-type",a.type);a.type!=this.raw_tracktype&&(this.attr("title",UI.format.capital(a.type)),this.raw_tracktype=a.type);this.label.raw!=a.idx+a.type+a.codec&&(this.label.text("Track "+a.idx+" ("+a.codec+")"),this.label.raw=a.idx+a.type+a.codec,this.css("order",a.idx));this.jitter.raw!=a.jitter&&(this.jitter.attr("title","Jitter: "+a.jitter+"ms"),this.jitter.raw=a.jitter);var b="nowms"in
a?"nowms":"lastms",d=c.timing.bounds.firstms.max,e=c.timing.bounds.lastms.min;this.box.css("left",c.timing.mstopos(a.firstms)+"%");this.box.css("right",100-c.timing.mstopos(a[b])+"%");d>=e?(a.firstms>e?this.left.html(UI.format.duration(0.001*(d-a.firstms),!0)):this.left.html(UI.format.duration(0.001*(e-a.firstms),!0)),a.lastms>d?this.right.html(UI.format.duration(0.001*(a[b]-d),!0)):this.right.html(UI.format.duration(0.001*(a[b]-e),!0))):(this.left.html(UI.format.duration(0.001*(d-a.firstms),!0)),
this.right.html(UI.format.duration(0.001*(a[b]-e),!0)));this.jitter.width(100*(a.jitter/(a[b]-a.firstms))+"%")}},getEntries:function(a){var b={},d=!c.includemeta.is(":checked"),e;for(e in a)d&&"meta"==a[e].type||(b[e]=a[e]);a={firstms:{min:1E9,max:-1E9},lastms:{min:1E9,max:-1E9}};for(e in b)d="nowms"in b[e]?"nowms":"lastms",a.firstms.min=Math.min(a.firstms.min,b[e].firstms),a.firstms.max=Math.max(a.firstms.max,b[e].firstms),a.lastms.min=Math.min(a.lastms.min,b[e][d]),a.lastms.max=Math.max(a.lastms.max,
b[e][d]);c.timing.bounds=a;for(e in b)b[e].bounds=a;return b},update:function(a){var b=c.timing.bounds.firstms.max,d=c.timing.bounds.lastms.min;this.box.label.html(UI.format.duration(0.001*Math.abs(b-d),!0));this.box[0].style.setProperty("--ntracks",Object.keys(a).length);b<d?(this.box.css("margin-left",c.timing.mstopos(b)+"%"),this.box.css("margin-right",100-c.timing.mstopos(d)+"%"),this.box.left.html(UI.format.duration(0.001*b)),this.box.right.html(UI.format.duration(0.001*d)),this.box.removeClass("gap")):
(this.box.css("margin-left",c.timing.mstopos(d)+"%"),this.box.css("margin-right",100-c.timing.mstopos(b)+"%"),this.box.left.html(UI.format.duration(0.001*d)),this.box.right.html(UI.format.duration(0.001*b)),this.box.addClass("gap"));40>this.box.width()?this.box.addClass("toosmall"):this.box.removeClass("toosmall")}}),c.includemeta=$("<input>").attr("type","checkbox").click(function(){a.main.timing.update(a.main.timing.values_orig)}),c.append($("<label>").append($("<span>").text("Include metadata in graph:")).append(c.includemeta)).append($("<label>").append($("<span>").text("Track timing:"))).append(c.timing));
b.tracktable&&(c.tracks=UI.dynamic({create:function(){return $("<div>").addClass("tracks")},getEntries:function(a){var b={audio:{},video:{},subtitle:{},meta:{}};if(a){var c=Object.keys(a).sort(function(b,c){return a[b].idx-a[c].idx}),d;for(d in c){var e=a[c[d]],g=e.codec=="subtitle"?"subtitle":e.type;b[g][c[d]]=e;e.nth=Object.values(b[g]).length}}return b},add:function(a){var b=UI.dynamic({create:function(a){var b=$("<table>").css("width","auto");b.rows=[];var c={audio:{vheader:"Audio",labels:["Codec",
"Duration","Jitter","Avg bitrate","Peak bitrate","Channels","Samplerate","Language","Track index"]},video:{vheader:"Video",labels:["Codec","Duration","Jitter","Avg bitrate","Peak bitrate","Size","Framerate","Language","Track index","Has B-Frames"]},subtitle:{vheader:"Subtitles",labels:["Codec","Duration","Jitter","Avg bitrate","Peak bitrate","Language"]},meta:{vheader:"Metadata",labels:["Codec","Duration","Jitter","Avg bitrate","Peak bitrate"]}};b.headers=c[a].labels;b.header=$("<tr>").addClass("header").append($("<td>").addClass("vheader").attr("rowspan",
c[a].labels.length+1).html($("<span>").text(c[a].vheader))).append($("<td>"));var d=$("<tbody>").append(b.header),e;for(e in c[a].labels){var f=$("<tr>").attr("data-label",c[a].labels[e]).append($("<td>").text(c[a].labels[e]+":"));b.rows.push(f);d.append(f)}b.append(d);return b},add:{create:function(){var a=$("<td>"),c=[],d;for(d in b.headers)c.push($("<td>"));return{header:a,cells:c,customAdd:function(a){a.header.append(this.header);for(var b in this.cells)a.rows[b].append(this.cells[b])}}},update:function(a){a=
function(a){function b(a,c){return"maxbps"in a?UI.format.bits(a[c]*8,1):c=="maxbps"?UI.format.bits(a.bps*8,1):"unknown"}function c(a){if(a.firstms==0&&a.lastms==0)return"\u00ab No data \u00bb";var b="lastms";"nowms"in a&&(b="nowms");var d;d=UI.format.duration((a.lastms-a.firstms)/1E3);return d=d+("<br><span class=description>"+UI.format.duration(a.firstms/1E3)+" to "+UI.format.duration(a[b]/1E3)+"</span>")}switch(a.codec=="subtitle"?"subtitle":a.type){case "audio":return{header:"Track "+a.idx,body:[a.codec,
c(a),UI.format.addUnit(UI.format.number(a.jitter),"ms"),b(a,"bps"),b(a,"maxbps"),a.channels,UI.format.addUnit(UI.format.number(a.rate),"Hz"),"language"in a?a.language:"unknown",a.nth]};case "video":return{header:"Track "+a.idx,body:[a.codec,c(a),UI.format.addUnit(UI.format.number(a.jitter),"ms"),b(a,"bps"),b(a,"maxbps"),UI.format.addUnit(a.width,"x ")+UI.format.addUnit(a.height,"px"),a.fpks==0?"variable":UI.format.addUnit(UI.format.number(a.fpks/1E3),"fps"),"language"in a?a.language:"unknown",a.nth,
"bframes"in a?"yes":"no"]};case "subtitle":return{header:"Track "+a.idx,body:[a.codec,c(a),UI.format.addUnit(UI.format.number(a.jitter),"ms"),b(a,"bps"),b(a,"maxbps"),"language"in a?a.language:"unknown",a.nth]};case "meta":return{header:"Track "+a.idx,body:[a.codec,c(a),UI.format.addUnit(UI.format.number(a.jitter),"ms"),b(a,"bps"),b(a,"maxbps")]}}}(a);if(this.header.raw!=a.header){this.header.text(a.header);this.header.raw=a.header}for(var b in this.cells)if(this.cells[b].raw!=a.body[b]){this.cells[b].html(a.body[b]);
this.cells[b].raw=a.body[b]}}},update:function(){Object.values(this._children).length?this.show():this.hide()}},a);return b},update:function(){}}),c.append($("<label>").append($("<span>").text("Track metadata:"))).append(c.tracks));return c},update:function(a){this.type.raw!=a.type&&(this.type.text("live"==a.type?"Live":"Video on demand"),this.type.raw=a.type);a.meta&&(this.buffer.raw!=a.meta.buffer_window&&(this.buffer.html(a.meta.buffer_window?UI.format.addUnit(UI.format.number(0.001*a.meta.buffer_window),
"s"):"N/A"),this.buffer.raw=a.meta.buffer_window),this.jitter.raw!=a.meta.jitter&&(this.jitter.html(a.meta.jitter?UI.format.addUnit(UI.format.number(a.meta.jitter),"ms"):"N/A"),this.jitter.raw=a.meta.jitter),this.tracks.update(a.meta.tracks),this.timing.update(a.meta.tracks))}});a.audio=$("<table>").hide();a.video=$("<table>").hide();a.subtitle=$("<table>").hide();a.metadata=$("<table>").hide();return a.append(a.main).append(a.audio).append(a.video).append(a.subtitle).append(a.metadata)},update:function(a){this.main.update(a);
this.raw_type!=a.type&&(this.attr("data-type",a.type),this.raw_type=a.type)}}),j=!0;UI.sockets.ws.info_json.subscribe(function(b){e(b);j&&!b.error&&(j=!1,"live"==b.type&&UI.interval.set(function(){$.ajax({type:"GET",url:UI.sockets.http_host+"json_"+a+".js",success:e})},5E3))},a);return $("<section>").addClass("meta").append($("<h3>").text("Stream metadata")).append(c)},processes:function(a){var b=$("<div>").attr("onempty","None.").addClass("processes"),e={"Process type:":function(a){return $("<b>").text(a.process)},
"Source:":function(a){var b=$("<span>").text(a.source);a.source_tracks&&a.source_tracks.length&&b.append($("<span>").addClass("description").text(" track "+a.source_tracks.slice(0,-2).concat(a.source_tracks.slice(-2).join(" and ")).join(", ")));return b},"Sink:":function(a){var b=$("<span>").text(a.sink);a.sink_tracks&&a.sink_tracks.length&&b.append($("<span>").addClass("description").text(" track "+a.sink_tracks.slice(0,-2).concat(a.sink_tracks.slice(-2).join(" and ")).join(", ")));return b},"Active for:":function(a){var b=
(new Date).setSeconds((new Date).getSeconds()-a.active_seconds);return $("<span>").append($("<span>").text(UI.format.duration(a.active_seconds))).append($("<span>").addClass("description").text(" since "+UI.format.time(b/1E3)))},"Pid:":function(a,b){return b},"Logs:":function(a){var b=$("<div>").text("None.");if(a.logs&&a.logs.length){b.html("").addClass("description").addClass("logs").css({maxHeight:"6em",display:"flex",flexFlow:"column-reverse nowrap"});for(var c in a.logs){var e=a.logs[c];b.prepend($("<div>").append(UI.format.time(e[0])+
" ["+e[1]+"] "+e[2]))}}return b},"Additional info:":function(a){var b;if("ainfo"in a&&a.ainfo&&Object.keys(a.ainfo).length){b=$("<table>");var c=!1;a.process in mist.data.capabilities.processes&&(c=mist.data.capabilities.processes[a.process]);a.process+".exe"in mist.data.capabilities.processes&&(c=mist.data.capabilities.processes[a.process+".exe"]);for(var e in a.ainfo){var m=!1;c&&(c.ainfo&&c.ainfo[e])&&(m=c.ainfo[e]);m||(m={name:e});b.append($("<tr>").append($("<th>").text(m.name+":")).append($("<td>").html(a.ainfo[e]).append(m.unit?
$("<span>").addClass("unit").text(m.unit):"")))}}else b=$("<span>").addClass("description").text("N/A");return b}},c=UI.dynamic({create:function(){var a=$("<table>");a.rows={};for(var b in e){var c=$("<tr>").append($("<th>").text(b).css("vertical-align","top"));a.append(c);a.rows[b]=c}return a},add:{create:function(){var a=$("<div>").hide();a.remove=function(){for(var a in this.children)this.children[a].remove()};return a},add:{create:function(){return $("<td>").css("vertical-align","top")},update:function(a){this.html(a)}},
getEntries:function(a,b){var c={},f;for(f in e){var m=e[f](a,b);"object"==typeof m&&(m=m.prop("outerHTML"));c[f]=m}return c},update:function(){for(var a in this._children)this._children[a].moved||(c.rows[a].append(this._children[a]),this._children[a].moved=!0)}},update:function(a){Object.keys(a).length?c.parent().length||(c.find("tr").first().addClass("header"),b.append(c)):c.remove()}});UI.sockets.http.api.subscribe(function(a){a.proc_list&&c.update(a.proc_list)},{proc_list:a});return $("<section>").addClass("processes").append($("<h3>").text("Processes")).append(b)},
triggers:function(a,b){var e=$("<div>").attr("onempty","None.").addClass("triggers");if(mist.data.config.triggers&&Object.keys(mist.data.config.triggers).length){var c=$("<table>").append($("<tbody>").append($("<tr>").addClass("header type").append($("<th>").text("Trigger name:"))).append($("<tr>").addClass("streams").append($("<th>").text("Applies to:"))).append($("<tr>").addClass("handler").append($("<th>").text("Handler:"))).append($("<tr>").addClass("blocking").append($("<th>").text("Blocking:"))).append($("<tr>").addClass("response").append($("<th>").text("Default response:"))).append($("<tr>").addClass("actions").append($("<th>").text("Actions:"))));
e.append(c);var d=0,j;for(j in mist.data.config.triggers){var i=mist.data.config.triggers[j],f;for(f in i){var m=i[f];if(!m.streams.length||!(0>m.streams.indexOf(a)&&0>m.streams.indexOf(a.split("+")[0]))){d++;for(var n=c.find("tr"),k=0;k<n.length;k++){var q=$("<td>");switch(k){case 0:q.append($("<b>").text(j));break;case 1:q.text(m.streams.length?m.streams.join(", "):"All streams");break;case 2:q.text(m.handler);break;case 3:q.text(m.sync?"Blocking":"Non-blocking");break;case 4:q.text(m["default"]?
m["default"]:"true");break;case 5:q.addClass("buttons").attr("data-index",f).attr("data-type",j).append($("<button>").text("Edit").click(function(){var a=$(this).closest(".buttons");UI.navto("Edit Trigger",a.attr("data-type")+","+a.attr("data-index"))})).append(1<m.streams.length?$("<button>").text("Remove from stream").click(function(){var c=$(this).closest(".buttons"),d=c.attr("data-type"),c=mist.data.config.triggers[d][c.attr("data-index")].streams,d=c.indexOf(a);0<=d?c.splice(d,1):(d=c.indexOf(a.split("+")[0]),
0<=d&&c.splice(d,1));mist.send(function(){UI.navto(b,a)},{config:mist.data.config})}):$("<button>").text("Remove").click(function(){var c=$(this).closest(".buttons"),d=c.attr("data-type");confirm("Are you sure you want to delete this "+d+" trigger?")&&(mist.data.config.triggers[d].splice(c.attr("data-index"),1),0==mist.data.config.triggers[d].length&&delete mist.data.config.triggers[d],mist.send(function(){UI.navto(b,a)},{config:mist.data.config}))}))}n.eq(k).append(q)}}}}0==d&&c.remove()}return $("<section>").addClass("triggers").append($("<h3>").text("Triggers")).append($("<button>").text("Add a trigger").click(function(){UI.navto("Edit Trigger")})).append(e)},
pushes:function(a){var b=$("<div>").addClass("pushes");b.html("Loading..");mist.send(function(e){function c(b,c){function d(a,b,c){a=""+("$"+a+" ");switch(Number(b)){case 0:a+="is true";break;case 1:a+="is false";break;case 2:a+="== "+c;break;case 3:a+="!= "+c;break;case 10:a+="> (numerical) "+c;break;case 11:a+=">= (numerical) "+c;break;case 12:a+="< (numerical) "+c;break;case 13:a+="<= (numerical) "+c;break;case 20:a+="> (lexical) "+c;break;case 21:a+=">= (lexical) "+c;break;case 22:a+="< (lexical) "+
"auto")}));g.find("tr").length==1?F.append($("<div>").text("No automatic pushes have been configured.").addClass("text").css("margin-top","0.5em")):F.append(g);F.append($("<h3>").text("Pushes")).append($("<button>").text("Start a push").click(function(){UI.navto("Start Push")}));if(h.find("tr").length==1)F.append($("<div>").text("No pushes are active.").addClass("text").css("margin-top","0.5em"));else{var g=[],f=[],m=$("<select>").css("margin-left","0.5em").append($("<option>").text("Any stream").val("")),
q=$("<select>").css("margin-left","0.5em").append($("<option>").text("Any target").val(""));for(e in a.push_list){g.indexOf(a.push_list[e][1])==-1&&g.push(a.push_list[e][1]);f.indexOf(a.push_list[e][2])==-1&&f.push(a.push_list[e][2])}g.sort();f.sort();for(e in g)m.append($("<option>").text(g[e]));for(e in f)q.append($("<option>").text(f[e]));F.append($("<button>").text("Stop all pushes").click(function(){var c=[],d;for(d in a.push_list)c.push(a.push_list[d][0]);if(c.length!=0&&confirm("Are you sure you want to stop all pushes?")){mist.send(function(){b(c)},
{push_stop:c});h.find("tr:not(:first-child)").html($("<td colspan=99>").append($("<span>").addClass("red").text("Stopping..")));$(this).remove()}})).append($("<label>").css("margin-left","1em").append($("<span>").text("Stop all pushes that match: ").css("font-size","0.9em")).append(m).append($("<span>").css("margin-left","0.5em").text("and").css("font-size","0.9em")).append(q).append($("<button>").css("margin-left","0.5em").text("Apply").click(function(){var c=m.val(),d=q.val();if(c==""&&d=="")return alert("Looks like you want to stop all pushes. Maybe you should use that button?");
var g={},e;for(e in a.push_list)if((c==""||a.push_list[e][1]==c)&&(d==""||a.push_list[e][2]==d))g[a.push_list[e][0]]=a.push_list[e];if(Object.keys(g).length==0)return alert("No matching pushes.");c="Are you sure you want to stop these pushes?\n\n";for(e in g)c=c+(g[e][1]+" to "+g[e][2]+"\n");if(confirm(c)){g=Object.keys(g);mist.send(function(){b(g)},{push_stop:g});for(e in g)h.find("tr[data-pushid="+g[e]+"]").html($("<td colspan=99>").html($("<span>").addClass("red").text("Stopping..")))}}))).append(h)}UI.interval.set(function(){mist.send(function(a){var b=
h.find("tr").first();h.empty();h.append(b);for(var d in a.push_list)h.append(c(a.push_list[d]))},{push_list:1})},5E3)},{push_settings:1,push_list:1,push_auto_list:1});break;case "Start Push":if(!("capabilities"in mist.data)||!("variable_list"in mist.data)||!("external_writer_list"in mist.data)){c.append("Loading MistServer capabilities..");mist.send(function(){UI.showTab("Start Push",b,d)},{capabilities:!0,variable_list:!0,external_writer_list:!0});return}var w,R=function(g){var h=false,e=b.split("_");
b=e[0];e.length==2&&(h=e[1]);if(h!==false&&typeof g=="undefined")mist.send(function(a){R(a.push_auto_list[h])},{push_auto_list:1});else{var f=[],m=[],q={},j=[],k;for(k in mist.data.capabilities.connectors){e=mist.data.capabilities.connectors[k];if("push_urls"in e){q[k]=e.push_urls;for(var l in e.push_urls)e.push_urls[l][0]=="/"?f.push(e.push_urls[l]):m.push(e.push_urls[l])}}if(mist.data.external_writer_list)for(k in mist.data.external_writer_list){e=mist.data.external_writer_list[k];if(e.length>=
3)for(l in e[2])j.push(e[2][l]+"://")}f.sort();m.sort();b=="auto"&&c.find("h2").text("Add automatic push");var i={params:{}},n=[];if(b=="auto"&&typeof g!="undefined"){i={stream:g[0],target:g[1],params:{}};l=i.target.split("?");if(l.length>1){n=l.pop();i.target=l.join("?");n=n.split("&");for(k in n){l=n[k].split("=");i.params[l.shift()]=l.join("=")}}if(g.length>=3)i.scheduletime=g[2]!=0?g[2]:null;if(g.length>=4)i.completetime=g[3]!=0?g[3]:null;if(g.length>=5)i.startVariableName=g[4]!=""?g[4]:null;
if(g.length>=6)i.startVariableOperator=g[5]!=""?g[5]:null;if(g.length>=7)i.startVariableValue=g[6]!=""?g[6]:null;if(g.length>=8)i.endVariableName=g[7]!=""?g[7]:null;if(g.length>=9)i.endVariableOperator=g[8]!=""?g[8]:null;if(g.length>=10)i.endVariableValue=g[9]!=""?g[9]:null}var o=$("<div>").css("margin","1em 0"),p=$("<div>"),r,x;if(b=="auto"){p.css("margin","1em 0").html(UI.buildUI([{label:"This push should be active",help:"When 'based on server time' is selected, a start and/or end timestamp can be configured. When it's 'based on a variable', the push will be activated while the specified variable matches the specified value.",
type:"select",select:[["time","Based on server time"],["variable","Based on a variable"]],value:i.startVariableName||i.endVariableName?"variable":"time",classes:["activewhen"],"function":function(){var a=p.find(".varbased").closest(".UIelement"),b=p.find(".timebased").closest(".UIelement");if($(this).getval()=="time"){a.hide();b.css("display","")}else{b.hide();a.css("display","");p.find('[name="startVariableOperator"]').trigger("change");p.find('[name="endVariableOperator"]').trigger("change")}}},
$("<br>"),$("<span>").addClass("UIelement").append($("<h3>").text("Start the push").addClass("varbased")),{classes:["varbased"],label:"Use this variable",type:"str",help:"This variable should be used to determine if this push should be started.",prefix:"$",datalist:Object.keys(mist.data.variable_list||[]),pointer:{main:i,index:"startVariableName"}},{classes:["varbased"],label:"Comparison operator",type:"select",select:[[0,"is true"],[1,"is false"],[2,"=="],[3,"!="],[10,"> (numerical)"],[11,">= (numerical)"],
[12,"< (numerical)"],[13,"<= (numerical)"],[20,"> (lexical)"],[21,">= (lexical)"],[22,"< (lexical)"],[23,"<= (lexical)"]],value:2,css:{display:"none"},help:"How would you like to compare this variable?",pointer:{main:i,index:"startVariableOperator"},"function":function(){var a=p.find('[name="startVariableValue"]').closest(".UIelement");Number($(this).getval())<2?a.hide():a.css("display","")}},{classes:["varbased"],label:"Variable value",type:"str",help:"The variable will be compared with this value to determine if this push should be started.<br>You can also enter another variable here!",
datalist:Object.values(mist.data.variable_list||[]).map(function(a){return typeof a=="string"?a:a[3]}).concat(Object.keys(mist.data.variable_list||[]).map(function(a){return"$"+a})),pointer:{main:i,index:"startVariableValue"}},$("<span>").addClass("UIelement").append($("<h3>").text("Stop the push").addClass("varbased")),{classes:["varbased"],label:"Use this variable",type:"str",help:"This variable should be used to determine if this push should be stopped.<br>You can leave this field blank if you do not want to have a stop condition. (You can always stop the push manually)",
prefix:"$",datalist:Object.keys(mist.data.variable_list||[]),pointer:{main:i,index:"endVariableName"}},{classes:["varbased"],label:"Comparison operator",type:"select",select:[[0,"is true"],[1,"is false"],[2,"=="],[3,"!="],[10,"> (numerical)"],[11,">= (numerical)"],[12,"< (numerical)"],[13,"<= (numerical)"],[20,"> (lexical)"],[21,">= (lexical)"],[22,"< (lexical)"],[23,"<= (lexical)"]],value:2,help:"How would you like to compare this variable?",pointer:{main:i,index:"endVariableOperator"},"function":function(){var a=
p.find('[name="endVariableValue"]').closest(".UIelement");Number($(this).getval())<2?a.hide():a.css("display","")}},{classes:["varbased"],label:"Variable value",type:"str",help:"The variable will be compared with this value to determine if this push should be stopped.<br>You can also enter another variable here!",datalist:Object.values(mist.data.variable_list||[]).map(function(a){return typeof a=="string"?a:a[3]}).concat(Object.keys(mist.data.variable_list||[]).map(function(a){return"$"+a})),pointer:{main:i,
index:"endVariableValue"}},{classes:["timebased"],type:"unix",label:"Start time",min:0,help:"The time where the push will become active. The default is to start immediately.",pointer:{main:i,index:"scheduletime"}},{classes:["timebased"],type:"unix",label:"End time",min:0,help:"The time where the push will stop. Defaults to never stop automatically.<br>Only makes sense for live streams.",pointer:{main:i,index:"completetime"}}],i));p.find(".activewhen").trigger("change")}k=[{label:"Stream name",type:"str",
help:"This may either be a full stream name, a partial wildcard stream name, or a full wildcard stream name.<br>For example, given the stream <i>a</i> you can use: <ul> <li><i>a</i>: the stream configured as <i>a</i></li> <li><i>a+</i>: all streams configured as <i>a</i> with a wildcard behind it, but not <i>a</i> itself</li> <li><i>a+b</i>: only the version of stream <i>a</i> that has wildcard <i>b</i></li> </ul>",pointer:{main:i,index:"stream"},
validate:["required",function(a){a=a.split("+");a=a[0];return a in mist.data.streams?false:{msg:"'"+a+"' is not a stream name.",classes:["orange"],"break":false}}],datalist:w,value:d[1]!=""?d[1]:""},{label:"Target",type:"str",help:"Where the stream will be pushed to.<br> Valid push formats: <ul> <li>"+m.join("</li><li>")+"</li> </ul> Valid file formats: <ul> <li>"+f.join("</li><li>")+"</li> </ul> "+
(j.length?"Additionally, the following protocols (from generic writers) may be used in combination with any of the above file formats:<ul><li>"+j.join("</li><li>")+"</li></ul>":"")+" Valid text replacements: <ul> <li>$stream - inserts the stream name used to push to MistServer</li> <li>$day - inserts the current day number</li><li>$month - inserts the current month number</li> <li>$year - inserts the current year number</li><li>$hour - inserts the hour timestamp when stream was received</li> <li>$minute - inserts the minute timestamp the stream was received</li> <li>$seconds - inserts the seconds timestamp when the stream was received</li> <li>$datetime - inserts $year.$month.$day.$hour.$minute.$seconds timestamp when the stream was received</li> </ul>",
pointer:{main:i,index:"target"},validate:["required",function(a){for(var b in m)if(mist.inputMatch(m[b],a))return false;for(b in f){if(mist.inputMatch(f[b],a))return false;for(var c in j)if(mist.inputMatch(j[c]+f[b].slice(1),a))return false}return{msg:"Does not match a valid target.<br>Valid push formats: <ul> <li>"+m.join("</li><li>")+"</li> </ul> Valid file formats: <ul> <li>"+f.join("</li><li>")+
"</li> </ul> "+(j.length?"Additionally, the following protocols may be used in combination with any of the above file formats:<ul><li>"+j.join("</li><li>")+"</li></ul>":""),classes:["red"]}}],"function":function(){function a(b,d){if(b.prot_only&&String().match&&c.match(/.+\:\/\/.+/)===null)delete r[d];else if(b.file_only&&c[0]!="/")delete r[d];else if(b.type=="group")for(var g in b.options)a(b.options[g],g);else x[d]=b}var b=false,c=$(this).getval();for(connector in q)for(var d in q[connector]){if(mist.inputMatch(q[connector][d],
c)){b=connector;break}if(q[connector][d][0]=="/")for(var g in j)if(mist.inputMatch(j[g]+q[connector][d].slice(1),c)){b=connector;break}}if(b){if(!("friendly"in mist.data.capabilities.connectors[b]))mist.data.capabilities.connectors[b].friendly=mist.data.capabilities.connectors[b].name;o.html($("<h3>").text(mist.data.capabilities.connectors[b].friendly.replace("over HTTP","")));r=$.extend({},mist.data.capabilities.connectors[b].push_parameters);x={};for(d in mist.data.capabilities.connectors[b].push_parameters)a(mist.data.capabilities.connectors[b].push_parameters[d],
d);b={desc:mist.data.capabilities.connectors[b].desc.replace("over HTTP",""),optional:r,sort:"sort"};b=mist.convertBuildOptions(b,i.params);g=[];for(d in n){var h=n[d].split("="),e=h[0];e in r||g.push(e+(h.length>1?"="+h.slice(1).join("="):""))}b.push($("<br>"));b.push({type:"inputlist",label:"Custom url parameters",value:g,classes:["custom_url_parameters"],input:{type:"str",placeholder:"name=value",prefix:""},help:"Any custom url parameters not covered by the parameters configurable above.",pointer:{main:i,
index:"custom_url_params"}});o.append(UI.buildUI(b))}else o.html($("<h4>").addClass("red").text("Unrecognized target.")).append($("<span>").text("Please edit the push target."))}},p,o];k.push({type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){d[0]&&d[0]!=a?UI.navto(d[0],d[1]):UI.navto("Push")}},{type:"save",label:"Save",preSave:function(){delete i.startVariableName;delete i.startVariableOperator;delete i.startVariableValue;delete i.endVariableName;delete i.endVariableOperator;
delete i.endVariableValue;delete i.completetime;delete i.scheduletime},"function":function(){var c=i.params,h;for(h in c)c[h]===null?delete c[h]:h in x||delete c[h];if(i.startVariableName||i.endVariableName){i.scheduletime=0;i.completetime=0}if(i.startVariableName===null){delete i.startVariableName;delete i.startVariableOperator;delete i.startVariableValue}if(i.endVariableName===null){delete i.endVariableName;delete i.endVariableOperator;delete i.endVariableValue}if(i.scheduletime)c.recstartunix=
i.scheduletime;if(Object.keys(c).length||i.custom_url_params&&i.custom_url_params.length){var e="?",f=i.target.split("?");if(f.length>1){e="&";f=f[f.length-1];f=f.split("&");for(h in f){var m=f[h].split("=")[0];m in c&&delete c[m]}}if(Object.keys(c).length||i.custom_url_params&&i.custom_url_params.length){f=[];for(h in c)f.push(h+"="+c[h]);for(h in i.custom_url_params)f.push(i.custom_url_params[h]);e=e+f.join("&");i.target=i.target+e}}delete i.params;delete i.custom_url_params;c={};c[b=="auto"?"push_auto_add":
"push_start"]=i;if(typeof g!="undefined"&&(g[0]!=i.stream||g[1]!=i.target))c.push_auto_remove=[g];mist.send(function(){d[0]&&d[0]!=a?UI.navto(d[0],d[1]):UI.navto("Push")},c)}}]});c.append(UI.buildUI(k))}};mist.data.LTS?mist.send(function(a){(w=a.active_streams)||(w=[]);var a=[],b;for(b in w)w[b].indexOf("+")!=-1&&a.push(w[b].replace(/\+.*/,"")+"+");w=w.concat(a);var c=0,d=0;for(b in mist.data.streams){w.push(b);if(mist.inputMatch(UI.findInput("Folder").source_match,mist.data.streams[b].source)){w.push(b+
"+");mist.send(function(a,b){var g=b.stream,h;for(h in a.browse.files)for(var e in mist.data.capabilities.inputs)e.indexOf("Buffer")>=0||(e.indexOf("Folder")>=0||e.indexOf("Buffer.exe")>=0||e.indexOf("Folder.exe")>=0)||mist.inputMatch(mist.data.capabilities.inputs[e].source_match,"/"+a.browse.files[h])&&w.push(g+"+"+a.browse.files[h]);d++;if(c==d){w=w.filter(function(a,b,c){return c.lastIndexOf(a)===b}).sort();R()}},{browse:mist.data.streams[b].source},{stream:b});c++}}if(c==d){w=w.filter(function(a,
b,c){return c.lastIndexOf(a)===b}).sort();R()}},{active_streams:1}):(w=Object.keys(mist.data.streams),R());break;case "Triggers":if(!("triggers"in mist.data.config)||!mist.data.config.triggers)mist.data.config.triggers={};A=$("<tbody>");h=$("<table>").html($("<thead>").html($("<tr>").html($("<th>").text("Trigger on").attr("data-sort-type","string").addClass("sorting-asc")).append($("<th>").text("Applies to").attr("data-sort-type","string")).append($("<th>").text("Handler").attr("data-sort-type","string")).append($("<th>")))).append(A);
c.append(UI.buildUI([{type:"help",help:"Triggers are a way to react to events that occur inside MistServer. These allow you to block specific users, redirect streams, keep tabs on what is being pushed where, etcetera. For full documentation, please refer to the developer documentation section on the MistServer website."}])).append($("<button>").text("New trigger").click(function(){UI.navto("Edit Trigger")})).append(h);h.stupidtable();h=mist.data.config.triggers;for(p in h)for(j in h[p])e=triggerRewrite(h[p][j]),
A.append($("<tr>").attr("data-index",p+","+j).append($("<td>").text(p)).append($("<td>").text("streams"in e?e.streams.join(", "):"")).append($("<td>").text(e.handler)).append($("<td>").html($("<button>").text("Edit").click(function(){UI.navto("Edit Trigger",$(this).closest("tr").attr("data-index"))})).append($("<button>").text("Delete").click(function(){var a=$(this).closest("tr").attr("data-index").split(",");if(confirm("Are you sure you want to delete this "+a[0]+" trigger?")){mist.data.config.triggers[a[0]].splice(a[1],
1);mist.data.config.triggers[a[0]].length==0&&delete mist.data.config.triggers[a[0]];mist.send(function(){UI.navto("Triggers")},{config:mist.data.config})}}))));break;case "Edit Trigger":if(!("triggers"in mist.data.config)||!mist.data.config.triggers)mist.data.config.triggers={};if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.showTab(a,b,d)},{capabilities:!0});c.append("Loading..");return}b?(b=b.split(","),j=triggerRewrite(mist.data.config.triggers[b[0]][b[1]]),r={triggeron:b[0],
appliesto:j.streams,url:j.handler,async:j.sync,"default":j["default"],params:j.params}):(c.html($("<h2>").text("New Trigger")),r={});j=[];for(p in mist.data.capabilities.triggers)j.push([p,p+": "+mist.data.capabilities.triggers[p].when]);var Y=$("<div>").addClass("desc"),na=$("<div>");c.append(UI.buildUI([{label:"Trigger on",pointer:{main:r,index:"triggeron"},help:"For what event this trigger should activate.",type:"select",select:j,validate:["required"],"function":function(){var a=$(this).getval(),
b=mist.data.capabilities.triggers[a];Y.html("");if(b){a=[$("<h4>").text("Trigger properties"),{type:"help",help:'The trigger "<i>'+a+'</i>" has the following properties:'},{type:"span",label:"Triggers",value:b.when,help:"When this trigger is activated"}];b.payload!=""&&a.push({label:"Payload",type:"textarea",value:b.payload,rows:b.payload.split("\n").length,readonly:true,clipboard:true,help:"The information this trigger sends to the handler."});a.push({type:"span",label:"Requires response",value:function(a){switch(a){case "ignored":return"No. The trigger will ignore the response of the handler.";
case "always":return"Yes. The trigger needs a response to proceed.";case "when-blocking":return"The trigger needs a response to proceed if it is configured to be blocking.";default:return a}}(b.response),help:"Whether this trigger requires a response from the trigger handler"});a.push({type:"span",label:"Response action",value:b.response_action,help:"What this trigger will do with its handler's response"});Y.append(UI.buildUI(a));b.stream_specific?$("[name=appliesto]").closest(".UIelement").show():
$("[name=appliesto]").setval([]).closest(".UIelement").hide();if(b.argument){$("[name=params]").closest(".UIelement").show();na.text(b.argument)}else $("[name=params]").setval("").closest(".UIelement").hide()}}},Y,$("<h4>").text("Trigger settings"),{label:"Applies to",pointer:{main:r,index:"appliesto"},help:"For triggers that can apply to specific streams, this value decides what streams they are triggered for. (none checked = always triggered)",type:"checklist",checklist:Object.keys(mist.data.streams),
value:""!=d[1]?[d[1]]:[]},$("<br>"),{label:"Handler (URL or executable)",help:"This can be either an HTTP URL or a full path to an executable.",pointer:{main:r,index:"url"},validate:["required"],type:"str"},{label:"Blocking",type:"checkbox",help:"If checked, pauses processing and uses the response of the handler. If the response does not start with 1, true, yes or cont, further processing is aborted. If unchecked, processing is never paused and the response is not checked.",pointer:{main:r,index:"async"}},
{label:"Parameters",type:"str",help:$("<div>").text("The extra data you want this trigger to use.").append(na),pointer:{main:r,index:"params"}},{label:"Default response",type:"str",help:"The default response in case the handler fails or is set to non-blocking.",placeholder:"true",pointer:{main:r,index:"default"}},{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){d[0]&&d[0]!=a?UI.navto(d[0],d[1]):UI.navto("Triggers")}},{type:"save",label:"Save","function":function(){b&&mist.data.config.triggers[b[0]].splice(b[1],
1);var c={handler:r.url,sync:r.async?true:false,streams:typeof r.appliesto=="undefined"?[]:r.appliesto,params:r.params,"default":r["default"]};if(!("triggers"in mist.data.config))mist.data.config.triggers={};r.triggeron in mist.data.config.triggers||(mist.data.config.triggers[r.triggeron]=[]);mist.data.config.triggers[r.triggeron].push(c);mist.send(function(){d[0]&&d[0]!=a?UI.navto(d[0],d[1]):UI.navto("Triggers")},{config:mist.data.config})}}]}]));$("[name=triggeron]").trigger("change");break;case "Logs":var oa=
$("<button>").text("Refresh now").click(function(){$(this).text("Loading..");mist.send(function(){Z();oa.text("Refresh now")})}).css("padding","0.2em 0.5em").css("flex-grow",0);c.append(UI.buildUI([{type:"help",help:"Here you have an overview of all edited settings within MistServer and possible warnings or errors MistServer has encountered. MistServer stores up to 100 logs at a time."},{label:"Refresh every",type:"select",select:[[10,"10 seconds"],[30,"30 seconds"],[60,"minute"],[300,"5 minutes"]],
value:30,"function":function(){UI.interval.clear();UI.interval.set(function(){mist.send(function(){Z()})},$(this).val()*1E3)},help:"How often the table below should be updated."},{label:"..or",type:"DOMfield",DOMfield:oa,help:"Instantly refresh the table below."}]));c.append($("<button>").text("Purge logs").click(function(){mist.send(function(){mist.data.log=[];UI.navto("Logs")},{clearstatlogs:true})}));A=$("<tbody>").css("font-size","0.9em");c.append($("<table>").addClass("logs").append(A));var qa=
function(a){var b=$("<span>").text(a);switch(a){case "WARN":b.addClass("orange");break;case "ERROR":case "FAIL":b.addClass("red")}return b},Z=function(){var a=mist.data.log;if(a){a.length>=2&&a[0][0]<a[a.length-1][0]&&a.reverse();A.html("");for(var b in a){var c=$("<span>").addClass("content"),d=a[b][2].split("|"),g;for(g in d)c.append($("<span>").text(d[g]));A.append($("<tr>").html($("<td>").text(UI.format.dateTime(a[b][0],"long")).css("white-space","nowrap")).append($("<td>").html(qa(a[b][1])).css("text-align",
"center")).append($("<td>").html(c).css("text-align","left")))}}};Z();break;case "Statistics":var E=$("<span>").text("Loading..");c.append(E);var r={graph:"new"},z=mist.stored.get().graphs?$.extend(!0,{},mist.stored.get().graphs):{},O={};for(p in mist.data.streams)O[p]=!0;for(p in mist.data.active_streams)O[mist.data.active_streams[p]]=!0;var O=Object.keys(O).sort(),aa=[];for(p in mist.data.config.protocols)aa.push(mist.data.config.protocols[p].connector);aa.sort();mist.send(function(){UI.plot.datatype.templates.cpuload.cores=
0;for(var a in mist.data.capabilities.cpu)UI.plot.datatype.templates.cpuload.cores=UI.plot.datatype.templates.cpuload.cores+mist.data.capabilities.cpu[a].cores;E.html(UI.buildUI([{type:"help",help:"Here you will find the MistServer stream statistics, you can select various categories yourself. All statistics are live: up to five minutes are saved."},$("<h3>").text("Select the data to display"),{label:"Add to",type:"select",select:[["new","New graph"]],pointer:{main:r,index:"graph"},classes:["graph_ids"],
"function":function(){if($(this).val()){var a=E.find(".graph_xaxis"),b=E.find(".graph_id");if($(this).val()=="new"){a.children("option").prop("disabled",false);b.setval("Graph "+(Object.keys(z).length+1)).closest("label").show()}else{var c=z[$(this).val()].xaxis;a.children("option").prop("disabled",true).filter('[value="'+c+'"]').prop("disabled",false);b.closest("label").hide()}a.children('option[value="'+a.val()+'"]:disabled').length&&a.val(a.children("option:enabled").first().val());a.trigger("change")}}},
{label:"Graph id",type:"str",pointer:{main:r,index:"id"},classes:["graph_id"],validate:[function(a){return a in z?{msg:"This graph id has already been used. Please enter something else.",classes:["red"]}:false}]},{label:"Axis type",type:"select",select:[["time","Time line"]],pointer:{main:r,index:"xaxis"},value:"time",classes:["graph_xaxis"],"function":function(){$s=E.find(".graph_datatype");switch($(this).getval()){case "coords":$s.children("option").prop("disabled",true).filter('[value="coords"]').prop("disabled",
false);break;case "time":$s.children("option").prop("disabled",false).filter('[value="coords"]').prop("disabled",true)}if(!$s.val()||$s.children('option[value="'+$s.val()+'"]:disabled').length){$s.val($s.children("option:enabled").first().val());$s.trigger("change")}}},{label:"Data type",type:"select",select:[["clients","Connections"],["upbps","Bandwidth (up)"],["downbps","Bandwidth (down)"],["cpuload","CPU use"],["memload","Memory load"],["coords","Client location"],["perc_lost","Lost packages"],
["perc_retrans","Re-transmitted packages"]],pointer:{main:r,index:"datatype"},classes:["graph_datatype"],"function":function(){$s=E.find(".graph_origin");switch($(this).getval()){case "cpuload":case "memload":$s.find("input[type=radio]").not('[value="total"]').prop("disabled",true);$s.find('input[type=radio][value="total"]').prop("checked",true);break;default:$s.find("input[type=radio]").prop("disabled",false)}}},{label:"Data origin",type:"radioselect",radioselect:[["total","All"],["stream","The stream:",
O],["protocol","The protocol:",aa]],pointer:{main:r,index:"origin"},value:["total"],classes:["graph_origin"]},{type:"buttons",buttons:[{label:"Add data set",type:"save","function":function(){var a;if(r.graph=="new"){a=UI.plot.addGraph(r,b);z[a.id]=a;E.find("input.graph_id").val("");E.find("select.graph_ids").append($("<option>").text(a.id)).val(a.id).trigger("change")}else a=z[r.graph];var c=UI.plot.datatype.getOptions({datatype:r.datatype,origin:r.origin});a.datasets.push(c);UI.plot.save(a);UI.plot.go(z)}}]}]));
var b=$("<div>").addClass("graph_container");c.append(b);var d=E.find("select.graph_ids");for(a in z){var g=UI.plot.addGraph(z[a],b);d.append($("<option>").text(g.id)).val(g.id);var h=[],e;for(e in z[a].datasets){var f=UI.plot.datatype.getOptions({datatype:z[a].datasets[e].datatype,origin:z[a].datasets[e].origin});h.push(f)}g.datasets=h;z[g.id]=g}d.trigger("change");UI.plot.go(z);UI.interval.set(function(){UI.plot.go(z)},1E4)},{active_streams:!0,capabilities:!0});break;case "Server Stats":if("undefined"==
typeof mist.data.capabilities){mist.send(function(){UI.showTab(a)},{capabilities:!0});c.append("Loading..");return}var ba=$("<table>"),I=$("<table>"),j={vheader:"CPUs",labels:["Model","Processor speed","Amount of cores","Amount of threads"],content:[]};for(p in mist.data.capabilities.cpu)h=mist.data.capabilities.cpu[p],j.content.push({header:"CPU #"+(Number(p)+1),body:[h.model,UI.format.addUnit(UI.format.number(h.mhz),"MHz"),h.cores,h.threads]});p=UI.buildVheaderTable(j);var pa=function(){var a=mist.data.capabilities.mem,
b=mist.data.capabilities.load,a={vheader:"Memory",labels:["Used","Cached","Available","Total"],content:[{header:"Physical memory",body:[UI.format.bytes(a.used*1048576)+" ("+UI.format.addUnit(b.memory,"%")+")",UI.format.bytes(a.cached*1048576),UI.format.bytes(a.free*1048576),UI.format.bytes(a.total*1048576)]},{header:"Swap memory",body:[UI.format.bytes((a.swaptotal-a.swapfree)*1048576),UI.format.addUnit("","N/A"),UI.format.bytes(a.swapfree*1048576),UI.format.bytes(a.swaptotal*1048576)]}]},a=UI.buildVheaderTable(a);
ba.replaceWith(a);ba=a;b={vheader:"Load average",labels:["CPU use","1 minute","5 minutes","15 minutes"],content:[{header:"&nbsp;",body:[UI.format.addUnit(UI.format.number(mist.data.capabilities.cpu_use/10),"%"),UI.format.number(b.one/100),UI.format.number(b.five/100),UI.format.number(b.fifteen/100)]}]};b=UI.buildVheaderTable(b);I.replaceWith(b);I=b};pa();c.append(UI.buildUI([{type:"help",help:"You can find general server statistics here. Note that memory and CPU usage is for your entire machine, not just MistServer."}])).append($("<table>").css("width",
"auto").addClass("nolay").append($("<tr>").append($("<td>").append(ba)).append($("<td>").append(I))).append($("<tr>").append($("<td>").append(p).attr("colspan",2))));UI.interval.set(function(){mist.send(function(){pa()},{capabilities:true})},3E4);break;case "Email for Help":p=$.extend({},mist.data);delete p.statistics;delete p.totals;delete p.clients;delete p.capabilities;p=JSON.stringify(p);p="Version: "+mist.data.config.version+"\n\nConfig:\n"+p;r={};c.append(UI.buildUI([{type:"help",help:"You can use this form to email MistServer support if you're having difficulties.<br>A copy of your server config file will automatically be included."},
{type:"str",label:"Your name",validate:["required"],pointer:{main:r,index:"name"},value:mist.user.name},{type:"email",label:"Your email address",validate:["required"],pointer:{main:r,index:"email"}},{type:"hidden",value:"Integrated Help",pointer:{main:r,index:"subject"}},{type:"hidden",value:"-",pointer:{main:r,index:"company"}},{type:"textarea",rows:20,label:"Your message",validate:["required"],pointer:{main:r,index:"message"}},{type:"textarea",rows:20,label:"Your config file",readonly:!0,value:p,
pointer:{main:r,index:"configfile"}},{type:"buttons",buttons:[{type:"save",label:"Send","function":function(a){$(a).text("Sending..");$.ajax({type:"POST",url:"https://mistserver.org/contact?skin=plain",data:r,success:function(a){a=$("<span>").html(a);a.find("script").remove();c.html(a[0].innerHTML)}})}}]}]));break;case "Disconnect":mist.user.password="";delete mist.user.authstring;delete mist.user.loggedin;sessionStorage.removeItem("mistLogin");UI.navto("Login");break;default:c.append($("<p>").text("This tab does not exist."))}c.find(".field").filter(function(){var a=
$(this).getval();return a==""||a==null?true:false}).each(function(){var a=[];$(this).is("input, select, textarea")?a.push($(this)):a=$(this).find("input, select, textarea");if(a.length){$(a[0]).focus();return false}})},dynamic:function(a,b){var a=Object.assign({},a),d=a.create(b);if(d){d.raw="";a.getEntry||(a.getEntry=function(a,b){return b in a?a[b]:!1});a.getEntries||(a.getEntries=function(a){return a});d.update&&(a.update=d.update);a.update||(a.update=function(){});if("object"==typeof a.add){var c=
a.add;a.add=function(a){return UI.dynamic(c,a)}}a.add&&(d._children={},d.add=function(b){var c=a.add.call(d,b);if(c){c.remove=function(){var a=this;a instanceof jQuery&&(a=a[0]);a.parentNode&&a.parentNode.removeChild(a);delete d._children[b]};c.id=b;d._children[b]=c;c.customAdd?c.customAdd(d):d.append(c)}});d.update=function(b,c){var i=a.getEntries(b,d.id),f=JSON.stringify(i);if(this.raw!=f){this.values=i;this.values_orig=b;if(a.add){for(var m in i){m in this._children||this.add(m);m in this._children&&
this._children[m].update.call(this._children[m],i[m],i)}for(var n in this._children)n in i||this._children[n].remove()}a.update.call(d,i,c);this.raw=f}};a.values&&d.update.call(d,a.values);return d}},modules:{stream:{bigbuttons:function(a,b){var d=$("<div>").addClass("bigbuttons");d.append($("<button>").text("Settings").addClass("settings").click(function(){UI.navto("Edit",a)}));var c=!1;if(0>a.indexOf("+")){var e=mist.data.streams[a];if(e.source&&(e.source.match(/^\/.+\/$/)||e.source.match(/^folder:.+$/)))c=
!0}"Status"!=b&&d.append($("<button>").text("Status").attr("data-icon","\ud83d\udea5").click(function(){UI.navto("Status",a)}));"Preview"!=b&&!c&&d.append($("<button>").text("Preview").addClass("preview").click(function(){UI.navto("Preview",a)}));"Embed"!=b&&!c&&d.append($("<button>").text("Embed").addClass("embed").click(function(){UI.navto("Embed",a)}));d.append($("<button>").addClass("cancel").addClass("return").text("Return").click(function(){UI.navto("Streams")}));return d},findMist:function(a,
b,d){function c(a){function b(a){for(var c=[],d=0;d<a.length;d++)a.indexOf(a[d])==d&&c.push(a[d]);return c}var e={HTTP:[],HTTPS:[]},q=e.HTTP,g=e.HTTPS;if(UI.sockets.http_host)if(d)q.push(UI.sockets.http_host),g.push(UI.sockets.http_host);else return a([UI.sockets.http_host]);if(mist.data.capabilities){var h=mist.stored.get();"HTTPurl"in h&&("https"==h.HTTPurl.slice(0,5)?g.push(h.HTTPurl):q.push(h.HTTPurl));for(var i in mist.data.config.protocols){var h=mist.data.config.protocols[i],l=h.connector,
l=(""+l).replace(".exe","");switch(h.connector){case "HTTP":case "HTTPS":if(h.pubaddr)for(var s in h.pubaddr){var p=h.pubaddr[s].split(":")[0].toUpperCase();e[p].push(h.pubaddr[s])}(p=h.port)||h.connector in mist.data.capabilities.connectors&&(p=mist.data.capabilities.connectors[h.connector].optional.port["default"]);p&&e[h.connector].push(parseURL(mist.user.host,{port:p,pathname:"",protocol:l.toLowerCase()+":"}).full)}}q.length||q.push(parseURL(mist.user.host,{port:8080,pathname:""}).full);g.length||
(g=q);q=b(q);g=b(g);f.urls=e;return a("https:"==location.protocol?g:q)}mist.send(function(){c(a)},{capabilities:!0})}function e(a,c){if(c>=a.length)return l();try{if(b||(b=function(a){return a+"player.js"}),url=b(a[c]),"http"==url.slice(0,4))$.ajax({type:"GET",url:url,success:function(b){f.hide();i(a[c],b)},error:function(){e(a,c+1)}});else if("ws"==url.slice(0,2)){var d=UI.websockets.create(url);d.onopen=function(){d.onerror=function(){};f.hide();i(a[c],d)};d.onerror=function(){e(a,c+1)}}else throw"I'm not sure how to contact MistServer with this protocol. (at "+
url+")";}catch(q){l(a)}}function l(a){1==a.length&&a[0]==UI.sockets.http_host&&(UI.sockets.http_host=null,c(function(b){a=b;e(b,0)}));var b={};f.show().html($("<p>").text("Could not locate the MistHTTP output url. Where can it be reached?")).append($("<div>").addClass("description").append($("<p>").text("Attempts:")).append($("<ul>").html("<li>"+a.join("</li><li>")+"</li>"))).append(UI.buildUI([{label:"MistServer HTTP endpoint",type:"datalist",datalist:a,help:"Please specify the url at which MistServer's HTTP endpoint can be reached.",
pointer:{main:b,index:"url"}},{type:"buttons",buttons:[{type:"save",label:"Connect","function":function(){a.unshift(b.url);e(a,0)}}]}]))}function i(b,c){b!=UI.sockets.http_host&&(UI.sockets.http_host=b,mist.stored.set("HTTPUrl",b));a.call(f,b,c)}var f=$("<div>").addClass("findMist").hide();c(function(a){e(a,0)});f.getUrls=function(){return f.urls};return f},livestreamhint:function(a){var b=$("<div>").addClass("livestreamhint"),d=mist.data.streams[a.split("+")[0]];if(d.source&&"/"!=d.source.slice(0,
1)&&!d.source.match(/-exec:/)){var c=null,e;for(e in mist.data.capabilities.inputs)if("undefined"!=typeof mist.data.capabilities.inputs[e].source_match&&mist.inputMatch(mist.data.capabilities.inputs[e].source_match,d.source)){c=e;break}if(c){c=mist.data.capabilities.inputs[c];e=[$("<span>").text("Configure your source to push to:")];switch(c.name){case "Buffer":case "Buffer.exe":e.push({label:"RTMP full url",type:"span",clipboard:!0,readonly:!0,classes:["RTMP"],help:"Use this RTMP url if your client doesn't ask for a stream key"});
e.push({label:"RTMP url",type:"span",clipboard:!0,readonly:!0,classes:["RTMPurl"],help:"Use this RTMP url if your client also asks for a stream key"});e.push({label:"RTMP stream key",type:"span",clipboard:!0,readonly:!0,classes:["RTMPkey"],help:"Use this key if your client asks for a stream key"});e.push({label:"SRT",type:"span",clipboard:!0,readonly:!0,classes:["TSSRT"]});e.push({label:"RTSP",type:"span",clipboard:!0,readonly:!0,classes:["RTSP"]});break;case "TS":case "TS.exe":"/"==d.source.charAt(0)?
e=[]:e.push({label:"TS",type:"span",clipboard:!0,readonly:!0,classes:["TS"]});break;case "TSSRT":case "TSSRT.exe":e.push({label:"SRT",type:"span",clipboard:!0,readonly:!0,classes:["TSSRT"]});break;default:e=[]}e.length&&(b.html(UI.buildUI(e)),UI.updateLiveStreamHint(a,d.source,b))}}else return!1;return b},status:function(a,b){b||(b={});var b=Object.assign({livestreamhint:!0,status:!0,stats:!0,tags:!0,thumbnail:!0},b),d=$("<div>").addClass("activestream"),c=b.status?$("<div>").attr("data-streamstatus",
0).text("Offline"):!1,e=b.stats?$("<span>").attr("beforeifnotempty","Viewers: "):!1,l=b.stats?$("<span>").attr("beforeifnotempty","Inputs: "):!1,i=b.stats?$("<span>").attr("beforeifnotempty","Outputs: "):!1,f=b.tags?{cont:$("<div>").attr("beforeifnotempty","Tags: "),children:{},ele:function(b){var c=$("<span>").addClass("tag").text(b).append($("<button>").text("\ud83d\uddd9").attr("title","Remove tag").click(function(){var c=$(this),d={};d[a]=b;c.parent().text("Removing..");mist.send(function(){c.parent().remove()},
{untag_stream:d})}));return this.children[b]=c},update:function(a){var a=""==a?[]:a.split(" "),b={},c;for(c in a){var d=a[c];b[d]=1;d in this.children||this.cont.append(this.ele(d))}for(c in this.children)c in b||(this.children[c].remove(),delete this.children[c])}}:!1,m=b.tags?$("<div>").html($("<input>").attr("placeholder","Tag name").on("keydown",function(a){switch(a.key){case " ":a.preventDefault();break;case "Enter":$(this).parent().find("button").click()}})).append($("<button>").text("Add tag").click(function(){var b=
{},c=$(this),d=c.parent().find("input");b[a]=d.val();c.text("Adding..");mist.send(function(){c.text("Add tag");d.val("")},{tag_stream:b})})):!1,n=b.livestreamhint?UI.modules.stream.livestreamhint(a):!1;d.html(c).append(e).append(l).append(i).append(f?f.cont:!1).append(m).append(b.thumbnail?UI.modules.stream.thumbnail(a):!1).append(n);UI.sockets.ws.active_streams.subscribe(function(d,m){if("stream"==d&&m[0]==a){var g="Offline;Initializing;Booting;Waiting for data;Ready;Shutting down;Invalid state".split(";");
b.status&&c.attr("data-streamstatus",m[1]).text(g[m[1]]);b.stats&&(e.text(m[2]),l.text(0<m[3]?m[3]:""),i.text(0<m[4]?m[4]:""));b.tags&&f.update(m[5]);n&&(0==m[1]?n.show():n.hide())}});return $("<section>").addClass("activestream").append(d)},actions:function(a,b){return $("<section>").addClass("actions").addClass("bigbuttons").html($("<button>").text("Stop all sessions").attr("data-icon","\u270b").attr("title","Disconnect sessions for this stream. Disconnecting a session will kill any currently open connections (viewers, pushes and possibly the input). If the USER_NEW trigger is in use, it will be triggered again by any reconnecting connections.").click(function(){confirm("Are you sure you want to disconnect all sessions (viewers, pushes and possibly the input) from this stream?")&&
mist.send(function(){},{stop_sessions:b})})).append($("<button>").text("Invalidate sessions").attr("data-icon","\ud83d\udd10").attr("title","Invalidate all the currently active sessions for this stream. This has the effect of re-triggering the USER_NEW trigger, allowing you to selectively close some of the existing connections after they have been previously allowed. If you don't have a USER_NEW trigger configured, this will not have any effect.").click(function(){confirm("Are you sure you want to invalidate all sessions for the stream '"+
b+"'?\nThis will re-trigger the USER_NEW trigger.")&&mist.send(function(){},{invalidate_sessions:b})})).append($("<button>").text("Nuke stream").attr("data-icon","\u2622\ufe0f").attr("title","Shut down a running stream completely and/or clean up any potentially left over stream data in memory. It attempts a clean shutdown of the running stream first, followed by a forced shut down, and then follows up by checking for left over data in memory and cleaning that up if any is found.").click(function(){confirm("Are you sure you want to completely shut down the stream '"+
b+"'?\nAll viewers will be disconnected.")&&mist.send(function(){UI.showTab(a,b)},{nuke_stream:b})}))},thumbnail:function(a){if(UI.findOutput("JPG")){var b=$("<img>");UI.sockets.ws.info_json.subscribe(function(a){if(a.source)for(var c in a.source)if("html5/image/jpeg"==a.source[c].type){b.attr("src",a.source[c].url);break}},a);return $("<section>").addClass("thumbnail").html(b)}},metadata:function(a,b){function d(b){if(!e.freeze)if(b.error&&(!c.rawdata||"live"==c.rawdata.type))c.html("").attr("onempty",
b.error+".");else{if(c.rawdata&&"live"==c.rawdata.type||!b.error)c.rawdata=b;e.parent().length||c.html($("<div>").append($("<button>").text("Open raw json").click(function(){var b=window.open(null,"Stream info json for "+a);b.document.write("<html><head><title>Raw stream metadata for '"+a+'\'</title><meta http-equiv="content-type" content="application/json; charset=utf-8"></head><body><code><pre>'+JSON.stringify(c.rawdata,null,2)+"</pre></code></body></html>");b.document.close()})).append($("<button>").text("Freeze").attr("title",
"Pauze updating the stream metadata information below").click(function(){"Freeze"==$(this).text()?($(this).text("Frozen").css("background","#bbb"),e.freeze=!0):($(this).text("Freeze")[0].style.background="",e.freeze=!1)}))).append(e);e.freeze||e.update(b)}}b||(b={});var b=Object.assign({tracktable:!0,tracktiming:!0},b),c=$("<div>").addClass("meta").text("Loading.."),e=UI.dynamic({create:function(){var a=$("<span>");a.main=UI.dynamic({create:function(){var c=$("<div>").addClass("main");c.type=$("<span>");
c.html($("<label>").append($("<span>").text("Type:")).append(c.type));c.buffer=$("<span>");c.append($("<label>").attr("data-liveonly","").append($("<span>").text("Buffer window:")).append(c.buffer));c.jitter=$("<span>");c.append($("<label>").attr("data-liveonly","").append($("<span>").text("Jitter:")).append(c.jitter));b.tracktiming&&(c.timing=UI.dynamic({create:function(){var a=$("<div>").addClass("tracktiming");a.box=$("<div>").addClass("boxcont");a.box.label=$("<span>").addClass("center");a.box.left=
$("<span>").addClass("left");a.box.right=$("<span>").addClass("right");a.box.append($("<div>").addClass("box")).append(a.box.label).append(a.box.left).append(a.box.right);a.append(a.box);a.bounds=null;a.mstopos=function(a){return!this.bounds?25:100*((a-this.bounds.firstms.min)/(this.bounds.lastms.max-this.bounds.firstms.min))};a.mstosize=function(a){return!this.bounds?10:100*(a/(this.bounds.lastms.max-this.bounds.firstms.min))};return a},add:{create:function(a){a=$("<div>").addClass("track").attr("data-track",
a);a.label=$("<label>");a.box=$("<div>").addClass("box");a.jitter=$("<div>").addClass("jitter");a.box.append(a.jitter);a.left=$("<span>").addClass("left").attr("beforeifnotempty","-");a.right=$("<span>").addClass("right").attr("beforeifnotempty","+");a.box.append(a.left);a.box.append(a.right);a.append(a.box).append(a.label);return a},update:function(a){a.type!=this.raw_type&&this.attr("data-type",a.type);a.type!=this.raw_tracktype&&(this.attr("title",UI.format.capital(a.type)),this.raw_tracktype=
a.type);this.label.raw!=a.idx+a.type+a.codec&&(this.label.text("Track "+a.idx+" ("+a.codec+")"),this.label.raw=a.idx+a.type+a.codec,this.css("order",a.idx));this.jitter.raw!=a.jitter&&(this.jitter.attr("title","Jitter: "+a.jitter+"ms"),this.jitter.raw=a.jitter);var b="nowms"in a?"nowms":"lastms",d=c.timing.bounds.firstms.max,e=c.timing.bounds.lastms.min;this.box.css("left",c.timing.mstopos(a.firstms)+"%");this.box.css("right",100-c.timing.mstopos(a[b])+"%");d>=e?(a.firstms>e?this.left.html(UI.format.duration(0.001*
(d-a.firstms),!0)):this.left.html(UI.format.duration(0.001*(e-a.firstms),!0)),a.lastms>d?this.right.html(UI.format.duration(0.001*(a[b]-d),!0)):this.right.html(UI.format.duration(0.001*(a[b]-e),!0))):(this.left.html(UI.format.duration(0.001*(d-a.firstms),!0)),this.right.html(UI.format.duration(0.001*(a[b]-e),!0)));this.jitter.width(100*(a.jitter/(a[b]-a.firstms))+"%")}},getEntries:function(a){var b={},d=!c.includemeta.is(":checked"),e;for(e in a)d&&"meta"==a[e].type||(b[e]=a[e]);a={firstms:{min:1E9,
max:-1E9},lastms:{min:1E9,max:-1E9}};for(e in b)d="nowms"in b[e]?"nowms":"lastms",a.firstms.min=Math.min(a.firstms.min,b[e].firstms),a.firstms.max=Math.max(a.firstms.max,b[e].firstms),a.lastms.min=Math.min(a.lastms.min,b[e][d]),a.lastms.max=Math.max(a.lastms.max,b[e][d]);c.timing.bounds=a;for(e in b)b[e].bounds=a;return b},update:function(a){var b=c.timing.bounds.firstms.max,d=c.timing.bounds.lastms.min;this.box.label.html(UI.format.duration(0.001*Math.abs(b-d),!0));this.box[0].style.setProperty("--ntracks",
Object.keys(a).length);b<d?(this.box.css("margin-left",c.timing.mstopos(b)+"%"),this.box.css("margin-right",100-c.timing.mstopos(d)+"%"),this.box.left.html(UI.format.duration(0.001*b)),this.box.right.html(UI.format.duration(0.001*d)),this.box.removeClass("gap")):(this.box.css("margin-left",c.timing.mstopos(d)+"%"),this.box.css("margin-right",100-c.timing.mstopos(b)+"%"),this.box.left.html(UI.format.duration(0.001*d)),this.box.right.html(UI.format.duration(0.001*b)),this.box.addClass("gap"));40>this.box.width()?
this.box.addClass("toosmall"):this.box.removeClass("toosmall")}}),c.includemeta=$("<input>").attr("type","checkbox").click(function(){a.main.timing.update(a.main.timing.values_orig)}),c.append($("<label>").append($("<span>").text("Include metadata in graph:")).append(c.includemeta)).append($("<label>").append($("<span>").text("Track timing:"))).append(c.timing));b.tracktable&&(c.tracks=UI.dynamic({create:function(){return $("<div>").addClass("tracks")},getEntries:function(a){var b={audio:{},video:{},
subtitle:{},meta:{}};if(a){var c=Object.keys(a).sort(function(b,c){return a[b].idx-a[c].idx}),d;for(d in c){var g=a[c[d]],h=g.codec=="subtitle"?"subtitle":g.type;b[h][c[d]]=g;g.nth=Object.values(b[h]).length}}return b},add:function(a){var b=UI.dynamic({create:function(a){var b=$("<table>").css("width","auto");b.rows=[];var c={audio:{vheader:"Audio",labels:["Codec","Duration","Jitter","Avg bitrate","Peak bitrate","Channels","Samplerate","Language","Track index"]},video:{vheader:"Video",labels:["Codec",
"Duration","Jitter","Avg bitrate","Peak bitrate","Size","Framerate","Language","Track index","Has B-Frames"]},subtitle:{vheader:"Subtitles",labels:["Codec","Duration","Jitter","Avg bitrate","Peak bitrate","Language"]},meta:{vheader:"Metadata",labels:["Codec","Duration","Jitter","Avg bitrate","Peak bitrate"]}};b.headers=c[a].labels;b.header=$("<tr>").addClass("header").append($("<td>").addClass("vheader").attr("rowspan",c[a].labels.length+1).html($("<span>").text(c[a].vheader))).append($("<td>"));
var d=$("<tbody>").append(b.header),e;for(e in c[a].labels){var f=$("<tr>").attr("data-label",c[a].labels[e]).append($("<td>").text(c[a].labels[e]+":"));b.rows.push(f);d.append(f)}b.append(d);return b},add:{create:function(){var a=$("<td>"),c=[],d;for(d in b.headers)c.push($("<td>"));return{header:a,cells:c,customAdd:function(a){a.header.append(this.header);for(var b in this.cells)a.rows[b].append(this.cells[b])}}},update:function(a){a=function(a){function b(a,c){return"maxbps"in a?UI.format.bits(a[c]*
8,1):c=="maxbps"?UI.format.bits(a.bps*8,1):"unknown"}function c(a){if(a.firstms==0&&a.lastms==0)return"\u00ab No data \u00bb";var b="lastms";"nowms"in a&&(b="nowms");var d;d=UI.format.duration((a.lastms-a.firstms)/1E3);return d=d+("<br><span class=description>"+UI.format.duration(a.firstms/1E3)+" to "+UI.format.duration(a[b]/1E3)+"</span>")}switch(a.codec=="subtitle"?"subtitle":a.type){case "audio":return{header:"Track "+a.idx,body:[a.codec,c(a),UI.format.addUnit(UI.format.number(a.jitter),"ms"),
b(a,"bps"),b(a,"maxbps"),a.channels,UI.format.addUnit(UI.format.number(a.rate),"Hz"),"language"in a?a.language:"unknown",a.nth]};case "video":return{header:"Track "+a.idx,body:[a.codec,c(a),UI.format.addUnit(UI.format.number(a.jitter),"ms"),b(a,"bps"),b(a,"maxbps"),UI.format.addUnit(a.width,"x ")+UI.format.addUnit(a.height,"px"),a.fpks==0?"variable":UI.format.addUnit(UI.format.number(a.fpks/1E3),"fps"),"language"in a?a.language:"unknown",a.nth,"bframes"in a?"yes":"no"]};case "subtitle":return{header:"Track "+
a.idx,body:[a.codec,c(a),UI.format.addUnit(UI.format.number(a.jitter),"ms"),b(a,"bps"),b(a,"maxbps"),"language"in a?a.language:"unknown",a.nth]};case "meta":return{header:"Track "+a.idx,body:[a.codec,c(a),UI.format.addUnit(UI.format.number(a.jitter),"ms"),b(a,"bps"),b(a,"maxbps")]}}}(a);if(this.header.raw!=a.header){this.header.text(a.header);this.header.raw=a.header}for(var b in this.cells)if(this.cells[b].raw!=a.body[b]){this.cells[b].html(a.body[b]);this.cells[b].raw=a.body[b]}}},update:function(){Object.values(this._children).length?
this.show():this.hide()}},a);return b},update:function(){}}),c.append($("<label>").append($("<span>").text("Track metadata:"))).append(c.tracks));return c},update:function(a){this.type.raw!=a.type&&(this.type.text("live"==a.type?"Live":"Video on demand"),this.type.raw=a.type);a.meta&&(this.buffer.raw!=a.meta.buffer_window&&(this.buffer.html(a.meta.buffer_window?UI.format.addUnit(UI.format.number(0.001*a.meta.buffer_window),"s"):"N/A"),this.buffer.raw=a.meta.buffer_window),this.jitter.raw!=a.meta.jitter&&
(this.jitter.html(a.meta.jitter?UI.format.addUnit(UI.format.number(a.meta.jitter),"ms"):"N/A"),this.jitter.raw=a.meta.jitter),this.tracks.update(a.meta.tracks),this.timing.update(a.meta.tracks))}});a.audio=$("<table>").hide();a.video=$("<table>").hide();a.subtitle=$("<table>").hide();a.metadata=$("<table>").hide();return a.append(a.main).append(a.audio).append(a.video).append(a.subtitle).append(a.metadata)},update:function(a){this.main.update(a);this.raw_type!=a.type&&(this.attr("data-type",a.type),
this.raw_type=a.type)}}),l=!0;UI.sockets.ws.info_json.subscribe(function(b){d(b);l&&!b.error&&(l=!1,"live"==b.type&&UI.interval.set(function(){$.ajax({type:"GET",url:UI.sockets.http_host+"json_"+a+".js",success:d})},5E3))},a);return $("<section>").addClass("meta").append($("<h3>").text("Stream metadata")).append(c)},processes:function(a){var b=$("<div>").attr("onempty","None.").addClass("processes"),d={"Process type:":function(a){return $("<b>").text(a.process)},"Source:":function(a){var b=$("<span>").text(a.source);
a.source_tracks&&a.source_tracks.length&&b.append($("<span>").addClass("description").text(" track "+a.source_tracks.slice(0,-2).concat(a.source_tracks.slice(-2).join(" and ")).join(", ")));return b},"Sink:":function(a){var b=$("<span>").text(a.sink);a.sink_tracks&&a.sink_tracks.length&&b.append($("<span>").addClass("description").text(" track "+a.sink_tracks.slice(0,-2).concat(a.sink_tracks.slice(-2).join(" and ")).join(", ")));return b},"Active for:":function(a){var b=(new Date).setSeconds((new Date).getSeconds()-
a.active_seconds);return $("<span>").append($("<span>").text(UI.format.duration(a.active_seconds))).append($("<span>").addClass("description").text(" since "+UI.format.time(b/1E3)))},"Pid:":function(a,b){return b},"Logs:":function(a){var b=$("<div>").text("None.");if(a.logs&&a.logs.length){b.html("").addClass("description").addClass("logs").css({maxHeight:"6em",display:"flex",flexFlow:"column-reverse nowrap"});for(var c in a.logs){var d=a.logs[c];b.prepend($("<div>").append(UI.format.time(d[0])+" ["+
d[1]+"] "+d[2]))}}return b},"Additional info:":function(a){var b;if("ainfo"in a&&a.ainfo&&Object.keys(a.ainfo).length){b=$("<table>");var c=!1;a.process in mist.data.capabilities.processes&&(c=mist.data.capabilities.processes[a.process]);a.process+".exe"in mist.data.capabilities.processes&&(c=mist.data.capabilities.processes[a.process+".exe"]);for(var d in a.ainfo){var m=!1;c&&(c.ainfo&&c.ainfo[d])&&(m=c.ainfo[d]);m||(m={name:d});b.append($("<tr>").append($("<th>").text(m.name+":")).append($("<td>").html(a.ainfo[d]).append(m.unit?
$("<span>").addClass("unit").text(m.unit):"")))}}else b=$("<span>").addClass("description").text("N/A");return b}},c=UI.dynamic({create:function(){var a=$("<table>");a.rows={};for(var b in d){var c=$("<tr>").append($("<th>").text(b).css("vertical-align","top"));a.append(c);a.rows[b]=c}return a},add:{create:function(){var a=$("<div>").hide();a.remove=function(){for(var a in this.children)this.children[a].remove()};return a},add:{create:function(){return $("<td>").css("vertical-align","top")},update:function(a){this.html(a)}},
getEntries:function(a,b){var c={},f;for(f in d){var m=d[f](a,b);"object"==typeof m&&(m=m.prop("outerHTML"));c[f]=m}return c},update:function(){for(var a in this._children)this._children[a].moved||(c.rows[a].append(this._children[a]),this._children[a].moved=!0)}},update:function(a){Object.keys(a).length?c.parent().length||(c.find("tr").first().addClass("header"),b.append(c)):c.remove()}});UI.sockets.http.api.subscribe(function(a){a.proc_list&&c.update(a.proc_list)},{proc_list:a});return $("<section>").addClass("processes").append($("<h3>").text("Processes")).append(b)},
triggers:function(a,b){var d=$("<div>").attr("onempty","None.").addClass("triggers");if(mist.data.config.triggers&&Object.keys(mist.data.config.triggers).length){var c=$("<table>").append($("<tbody>").append($("<tr>").addClass("header type").append($("<th>").text("Trigger name:"))).append($("<tr>").addClass("streams").append($("<th>").text("Applies to:"))).append($("<tr>").addClass("handler").append($("<th>").text("Handler:"))).append($("<tr>").addClass("blocking").append($("<th>").text("Blocking:"))).append($("<tr>").addClass("response").append($("<th>").text("Default response:"))).append($("<tr>").addClass("actions").append($("<th>").text("Actions:"))));
d.append(c);var e=0,l;for(l in mist.data.config.triggers){var i=mist.data.config.triggers[l],f;for(f in i){var m=i[f];if(!m.streams.length||!(0>m.streams.indexOf(a)&&0>m.streams.indexOf(a.split("+")[0]))){e++;for(var n=c.find("tr"),j=0;j<n.length;j++){var q=$("<td>");switch(j){case 0:q.append($("<b>").text(l));break;case 1:q.text(m.streams.length?m.streams.join(", "):"All streams");break;case 2:q.text(m.handler);break;case 3:q.text(m.sync?"Blocking":"Non-blocking");break;case 4:q.text(m["default"]?
m["default"]:"true");break;case 5:q.addClass("buttons").attr("data-index",f).attr("data-type",l).append($("<button>").text("Edit").click(function(){var a=$(this).closest(".buttons");UI.navto("Edit Trigger",a.attr("data-type")+","+a.attr("data-index"))})).append(1<m.streams.length?$("<button>").text("Remove from stream").click(function(){var c=$(this).closest(".buttons"),d=c.attr("data-type"),c=mist.data.config.triggers[d][c.attr("data-index")].streams,d=c.indexOf(a);0<=d?c.splice(d,1):(d=c.indexOf(a.split("+")[0]),
0<=d&&c.splice(d,1));mist.send(function(){UI.navto(b,a)},{config:mist.data.config})}):$("<button>").text("Remove").click(function(){var c=$(this).closest(".buttons"),d=c.attr("data-type");confirm("Are you sure you want to delete this "+d+" trigger?")&&(mist.data.config.triggers[d].splice(c.attr("data-index"),1),0==mist.data.config.triggers[d].length&&delete mist.data.config.triggers[d],mist.send(function(){UI.navto(b,a)},{config:mist.data.config}))}))}n.eq(j).append(q)}}}}0==e&&c.remove()}return $("<section>").addClass("triggers").append($("<h3>").text("Triggers")).append($("<button>").text("Add a trigger").click(function(){UI.navto("Edit Trigger")})).append(d)},
pushes:function(a){var b=$("<div>").addClass("pushes");b.html("Loading..");mist.send(function(d){function c(b,c){function d(a,b,c){a=""+("$"+a+" ");switch(Number(b)){case 0:a+="is true";break;case 1:a+="is false";break;case 2:a+="== "+c;break;case 3:a+="!= "+c;break;case 10:a+="> (numerical) "+c;break;case 11:a+=">= (numerical) "+c;break;case 12:a+="< (numerical) "+c;break;case 13:a+="<= (numerical) "+c;break;case 20:a+="> (lexical) "+c;break;case 21:a+=">= (lexical) "+c;break;case 22:a+="< (lexical) "+
c;break;case 23:a+="<= (lexical) "+c;break;default:a+="comparison operator unknown"}return a}var e={Target:function(a){return"Automatic"==b?a[2]:4<=a.length&&a[2]!=a[3]?a[2]+$("<span>").html("&#187").addClass("unit").css("margin","0 0.5em").prop("outerHTML")+a[3]:a[2]},Conditions:!1,Statistics:!1,Actions:$("<div>").addClass("buttons")};"Automatic"==b?e.Conditions=function(a){var b=$("<div>");a[3]&&b.append($("<span>").text("schedule on "+(new Date(1E3*a[3])).toLocaleString()));5<=a.length&&a[4]&&
b.append($("<span>").text("complete on "+(new Date(1E3*a[4])).toLocaleString()));8<=a.length&&a[5]&&b.append($("<span>").text("starts if "+d(a[5],a[6],a[7])));11<=a.length&&a[8]&&b.append($("<span>").text("stops if "+d(a[8],a[9],a[10])));return b.children().length?b.children():""}:e.Statistics={create:function(){return $("<div>").addClass("statistics")},add:{create:function(a){var b={active_seconds:"Active for: ",bytes:"Data transfered: ",mediatime:"Media time transfered: ",pkt_retrans_count:"Packets retransmitted: ",
pkt_loss_count:"Packets lost: ",tracks:"Tracks: "};if(a in b)return $("<div>").attr("beforeifnotempty",b[a])},update:function(a,b){var c={active_seconds:UI.format.duration,bytes:UI.format.bytes,mediatime:function(a){return UI.format.duration(0.001*a)},tracks:function(a){return a.join(", ")},pkt_retrans_count:function(a){return UI.format.number(a||0)},pkt_loss_count:function(a){return UI.format.number(a||0)+" ("+UI.format.addUnit(UI.format.number(b.pkt_loss_perc||0),"%")+" over the last "+UI.format.addUnit(5,
"s")+")"}};this._id in c&&this.html(c[this._id](a))}}};e.Actions.append($("<button>").text("Automatic"==b?"Remove":"Stop").click(function(){var a=$(this).closest("table").data("values")[$(this).closest("td").attr("data-pushid")];if(confirm("Are you sure you want to "+$(this).text().toLowerCase()+" this push?\n"+a[1]+" to "+a[2]))if($(this).html($("<span>").addClass("red").text("Automatic"==b?"Removing..":"Stopping..")),"Automatic"==b){var a=a.slice(1),c=this;mist.send(function(a){$(c).text("Done.");
k.update(a.push_auto_list)},{push_auto_remove:[a]})}else mist.send(function(){},{push_stop:[a[0]]})}));"Automatic"==b&&e.Actions.prepend($("<button>").text("Edit").click(function(){UI.navto("Start Push","auto_"+$(this).closest("td").attr("data-pushid"))}));var n=$("<div>").attr("onempty","None."),k;k="Automatic"==b?UI.dynamic({create:function(){var a=$("<table>"),b=$("<tr>");a.append($("<thead>").append(b));for(var c in e)if(e[c]){var d=$("<td>").addClass("header").text(c).attr("data-column",c);b.append(d)}return a},
"s")+")"}};this.id in c&&this.html(c[this.id](a))}}};e.Actions.append($("<button>").text("Automatic"==b?"Remove":"Stop").click(function(){var a=$(this).closest("table").data("values")[$(this).closest("td").attr("data-pushid")];if(confirm("Are you sure you want to "+$(this).text().toLowerCase()+" this push?\n"+a[1]+" to "+a[2]))if($(this).html($("<span>").addClass("red").text("Automatic"==b?"Removing..":"Stopping..")),"Automatic"==b){var a=a.slice(1),c=this;mist.send(function(a){$(c).text("Done.");
j.update(a.push_auto_list)},{push_auto_remove:[a]})}else mist.send(function(){},{push_stop:[a[0]]})}));"Automatic"==b&&e.Actions.prepend($("<button>").text("Edit").click(function(){UI.navto("Start Push","auto_"+$(this).closest("td").attr("data-pushid"))}));var n=$("<div>").attr("onempty","None."),j;j="Automatic"==b?UI.dynamic({create:function(){var a=$("<table>"),b=$("<tr>");a.append($("<thead>").append(b));for(var c in e)if(e[c]){var d=$("<td>").addClass("header").text(c).attr("data-column",c);b.append(d)}return a},
add:{create:function(a){var b=$("<tr>");b._children={};for(var c in e)if(e[c]){var d=$("<td>").attr("data-pushid",a).attr("data-column",c);b._children[c]=d;b.append(d);e[c]instanceof jQuery?d.html(e[c].clone(!0)):"object"==typeof e[c]&&(d.dynamic=UI.dynamic(e[c]),d.html(d.dynamic))}return b},update:function(a){for(var b in e)if("function"==typeof e[b]){var c=e[b](a);c!=this._children[b].raw&&(this._children[b].html(c),this._children[b].raw=c)}}},update:function(a){this.data("values",a);if(Object.keys(a).length){this.parent().length||
n.append(this);var a=!1,b;for(b in this.children)if(""!=this.children[b]._children.Conditions.raw){a=!0;break}a?this.removeClass("hideConditioins"):this.addClass("hideConditions")}else this[0].parentNode&&this[0].parentNode.removeChild(this[0])},values:c,getEntries:function(b){var c={},d=!1;1==a.split("+").length&&(d=!0);for(var e in b){var f=b[e];f.unshift(Number(e));if(f[1]==a||!d&&f[1].split("+")[0]==a)c[f[0]]=f}return c}}):UI.dynamic({create:function(){var a=$("<table>");a.rows={};for(var b in e)if(e[b]){var c=
$("<tr>").addClass(b).append($("<th>").text(b+":"));a.append(c);a.rows[b]=c}a.rows.Target.addClass("header");return a},add:{create:function(a){var b=$("<tr>").text(a);b.children={};for(var c in e)if(e[c]){var d=$("<td>").attr("data-pushid",a);b.children[c]=d;b.append(d);e[c]instanceof jQuery?d.html(e[c].clone(!0)):"object"==typeof e[c]&&(d.dynamic=UI.dynamic(e[c]),d.html(d.dynamic))}var f=b.remove;b.remove=function(){for(var a in b.children)b.children[a].remove();return f.apply(this,arguments)};return b},
update:function(a){for(var b in e)if("function"==typeof e[b]){var c=e[b](a);c!=this.children[b].raw&&(this.children[b].html(c),this.children[b].raw=c)}else"Statistics"==b&&e[b]&&5<=a.length&&(c={},6<=a.length&&(c=a[5]),c.logs=a[4],this.children[b].dynamic.update(c))}},update:function(a){this.data("values",a);if(Object.keys(a).length){this.parent().length||n.append(this);for(var b in this.children)if(!this.children[b].moved){for(var c in this.children[b].children)this.rows[c].append(this.children[b].children[c]);
this.children[b].moved=!0;this.children[b][0].parentNode.removeChild(this.children[b][0])}}else this[0].parentNode&&this[0].parentNode.removeChild(this[0])},values:c,getEntries:function(b){var c={},d=!1;1==a.split("+").length&&(d=!0);for(var e in b){var f=b[e];if(f[1]==a||!d&&f[1].split("+")[0]==a)c[f[0]]=f}return c}});n.update=function(){return k.update.apply(k,arguments)};return n}b.html("");b.append($("<h4>").text("Automatic pushes"));b.append($("<button>").text("Add an automatic push").click(function(){UI.navto("Start Push",
"auto")}));b.append(c("Automatic",e.push_auto_list));b.append($("<h4>").text("Active pushes"));b.append($("<button>").text("Start a push").click(function(){UI.navto("Start Push")}));var d=c("Manual",e.push_list);b.append(d);UI.sockets.http.api.subscribe(function(a){d.update(a.push_list)},{push_list:1})},{push_auto_list:1,push_list:1});return $("<section>").addClass("pushes").append($("<h3>").text("Pushes and recordings")).append(b)},logs:function(a){var b=$("<div>").attr("onempty","None.").addClass("logs"),
e=!1;UI.sockets.ws.active_streams.subscribe(function(c,d){if("log"==c){var j=b[0].scrollTop>=b[0].scrollHeight-b[0].clientHeight;if(!(""!=d[3]&&d[3]!=a.split("+")[0])&&"ACCS"!=d[1]){var i=$("<div>").attr("data-debuglevel",d[1]).html($("<span>").addClass("description").text(UI.format.dateTime(d[0]))).append($("<span>").text(d[3])).append($("<span>").text(d[1]+":")).append($("<span>").text(d[2]));b.append(i);j&&(b[0].scrollTop=b[0].scrollHeight);if(e)try{j=e.document.scrollingElement.scrollTop>=e.document.scrollingElement.scrollHeight-
e.document.scrollingElement.clientHeight,e.document.write(i[0].outerHTML),j&&(e.document.scrollingElement.scrollTop=e.document.scrollingElement.scrollHeight)}catch(f){}}}});return $("<section>").addClass("logs").append($("<h3>").text("MistServer logs")).append($("<button>").text("Open raw").click(function(){e=window.open("","MistServer logs for "+a);e.document.write("<html><head><title>MistServer logs for '"+a+'\'</title><meta http-equiv="content-type" content="application/json; charset=utf-8"><style>body{padding-left:2em;text-indent:-2em;}body>*>*:not(:last-child):not(:empty){padding-right:.5em;}.description{font-size:.9em;color:#777}</style></head><body>');
e.document.write(b[0].innerHTML);e.document.scrollingElement.scrollTop=e.document.scrollingElement.scrollHeight})).append(b)},accesslogs:function(a){var b=$("<div>").attr("onempty","None.").addClass("accesslogs"),e=!1;UI.sockets.ws.active_streams.subscribe(function(c,d){if("access"==c){var j=b[0].scrollTop>=b[0].scrollHeight-b[0].clientHeight;if(!(""!=d[2]&&d[2]!=a.split("+")[0])){var i=$("<div>").html($("<span>").addClass("description").text(UI.format.dateTime(d[0]))).append($("<span>").attr("beforeifnotempty",
"Token: ").attr("title",d[1]).css("max-width","10em").text(d[1])).append($("<span>").attr("beforeifnotempty","Connector: ").text(d[3])).append($("<span>").attr("beforeifnotempty","Hostname: ").text(d[4])).append($("<span>").attr("beforeifnotempty","Connected for: ").html(UI.format.duration(d[5]))).append($("<span>").html("\u2191"+UI.format.bytes(d[6]))).append($("<span>").html("\u2193"+UI.format.bytes(d[7]))).append($("<span>").attr("beforeifnotempty","Tags: ").text(d[8]));b.append(i);j&&(b[0].scrollTop=
b[0].scrollHeight);if(e)try{j=e.document.scrollingElement.scrollTop>=e.document.scrollingElement.scrollHeight-e.document.scrollingElement.clientHeight,e.document.write(i[0].outerHTML),j&&(e.document.scrollingElement.scrollTop=e.document.scrollingElement.scrollHeight)}catch(f){}}}});return $("<section>").addClass("accesslogs").append($("<h3>").text("Access logs")).append($("<button>").text("Open raw").click(function(){e=window.open("","MistServer access logs for "+a);e.document.write("<html><head><title>MistServer access logs for '"+
a+'\'</title><meta http-equiv="content-type" content="application/json; charset=utf-8"><style>body{padding-left:2em;text-indent:-2em;}body>*>*:not(:last-child):not(:empty){padding-right:.5em;}.description{font-size:.9em;color:#777}[beforeifnotempty]:not(:empty):before{content:attr(beforeifnotempty);color:#777}</style></head><body>');e.document.write(b[0].innerHTML);e.document.scrollingElement.scrollTop=e.document.scrollingElement.scrollHeight})).append(b)},preview:function(a,b){var e=$("<section>").addClass("preview");
b||(window.mv={},b=mv);UI.sockets.http.player(function(){mistPlay(a,{target:e[0],host:UI.sockets.http_host,skin:{inherit:"dev",colors:{accent:"var(--accentColor)"}},loop:true,MistVideoObject:b})},function(a){$preciew_cont.html(a)});return e},playercontrols:function(a,b){function e(){function b(a){return e.UI.buildStructure.call(e.UI,a)}var e=a.reference,i=b({"if":function(){return this.playerName&&this.source},then:{type:"container",classes:["mistvideo-description"],style:{display:"block"},children:[{type:"playername",
style:{display:"inline"}},{type:"text",text:"is playing",style:{margin:"0 0.2em"}},{type:"mimetype"}]}}),f=b({type:"container",classes:["mistvideo-column","mistvideo-devcontrols"],children:[{type:"text",text:"Player control"},{type:"container",classes:["mistvideo-devbuttons"],style:{"flex-wrap":"wrap"},children:[{"if":function(){return!(!this.player||!this.player.api)},then:{type:"button",title:"Reload the video source",label:"Reload video",onclick:function(){this.player.api.load()}}},{type:"button",
title:"Build MistVideo again",label:"Reload player",onclick:function(){this.reload()}},{type:"button",title:"Switch to the next available player and source combination",label:"Try next combination",onclick:function(){this.nextCombo()}}]},{type:"forcePlayer"},{type:"forceType"},{type:"forceSource"}]}),m=b({type:"decodingIssues",style:{"max-width":"30em","flex-flow":"column nowrap"}}),n=b({type:"log"}),k=$("<button>").text("Open raw").css({display:"block",marginTop:"0.333em"}).click(function(){var a=
e.stream;tab=window.open("","Player logs for "+a);tab.document.write("<html><head><title>Player logs for '"+a+'\'</title><meta http-equiv="content-type" content="application/json; charset=utf-8"><style>.timestamp{color:#777;font-size:0.9em;}</style></head><body>');tab.document.write(n.lastChild.outerHTML);tab.document.scrollingElement.scrollTop=tab.document.scrollingElement.scrollHeight});n.insertBefore(k[0],n.children[0]);c.html($("<div>").append($("<div>").append($("<h3>").addClass("title").text("MistPlayer")).append(i)).append(f).append(m)).append(n)}
var c=$("<section>").addClass("controls").addClass("mistvideo").addClass("input_container").html($("<h3>").text("MistPlayer")).append($("<p>").text("Waiting for player.."));b||(b=$(".dashboard"));$("link#devcss").length||document.head.appendChild($("<link>").attr("rel","stylesheet").attr("type","text/css").attr("href",UI.sockets.http_host+"skins/dev.css").attr("id","devcss")[0]);a&&(a.reference&&a.reference.skin)&&e();b[0].addEventListener("initialized",function(){e()});b[0].addEventListener("initializedFailed",
function(){e()});return c},embedurls:function(a,b,e){function c(){function b(a){switch(typeof a){case "string":return $.isNumeric(a)?a:'"'+a+'"';case "object":return JSON.stringify(a);default:return a}}q&&UI.stored.saveOpt("embedoptions",g);for(var c=a+"_",d=12,f="";d--;){var l;l=Math.floor(62*Math.random());l=10>l?l:36>l?String.fromCharCode(l+55):String.fromCharCode(l+61);f+=l}var c=c+f,d=['target: document.getElementById("'+c+'")'],i;for(i in g)"prioritize_type"==i?g[i]&&""!=g[i]&&d.push("forcePriority: "+
JSON.stringify({source:[["type",[g[i]]]]})):"monitor_action"==i?g[i]&&""!=g[i]&&"nextCombo"==g[i]&&d.push('monitor: {\n action: function(){\n this.MistVideo.log("Switching to nextCombo because of poor playback in "+this.MistVideo.source.type+" ("+Math.round(this.vars.score*1000)/10+"%)");\n this.MistVideo.nextCombo();\n }\n }'):g[i]!=h[i]&&(null!=g[i]&&("object"!=typeof g[i]||JSON.stringify(g[i])!=JSON.stringify(h[i])))&&d.push(i+": "+b(g[i]));i=[];i.push('<div class="mistvideo" id="'+
c+'">');i.push(" <noscript>");i.push(' <a href="'+n+k+'.html" target="_blank">');i.push(" Click here to play this video");i.push(" </a>");i.push(" </noscript>");i.push(" <script>");i.push(" var a = function(){");i.push(' mistPlay("'+a+'",{');i.push(" "+d.join(",\n "));i.push(" });");i.push(" };");i.push(" if (!window.mistplayers) {");i.push(' var p = document.createElement("script");');e.HTTPS.length?(i.push(' if (location.protocol == "https:") { p.src = "'+
("https://"==parseURL(n).protocol?n:e.HTTPS[0])+'player.js" } '),i.push(' else { p.src = "'+("http://"==parseURL(n).protocol?n:e.HTTP[0])+'player.js" } ')):i.push(' p.src = "'+n+'player.js"');i.push(" document.head.appendChild(p);");i.push(" p.onload = a;");i.push(" }");i.push(" else { a(); }");i.push(" <\/script>");i.push("</div>");return i.join("\n")}function d(e){UI.sockets.ws.info_json.subscribe(function(a){if("error"==a.type)if(e==n)d(b);else throw a;else{if("source"in
a&&(!q||a.source.length)){var f=e==n?!1:n,h=[],i=j.find(".field.forceType"),k=j.find(".field.prioritize_type");f&&(f=f.replace(parseURL(f).protocol,""),h.push($("<div>").addClass("orange").html('Warning: the provided base URL <a href="'+n+'">'+n+"</a> could not be reached. These links are my best guess but will probably not work properly.").css({margin:"0.5em 0",width:"45em","word-break":"normal"})));for(var m in a.source){var u=a.source[m],D=UI.humanMime(u.type),G=u.url;f&&(G=parseURL(u.url).protocol+
f+u.relurl);var v=G.match(/[\?\&]tkn=\d+\&?/);v&&(v=v[0],G=G.replace(v,"?"==v[0]&&"&"==v.slice(-1)?"?":"&"==v.slice(-1)?"&":""));h.push({label:D?D+" <span class=description>("+u.type+")</span>":UI.format.capital(u.type),type:"str",value:G,readonly:!0,qrcode:!0,clipboard:!0});D=UI.humanMime(u.type);0==i.children('option[value="'+u.type+'"]').length&&(i.append($("<option>").text(D?D+" ("+u.type+")":UI.format.capital(u.type)).val(u.type)),k.append($("<option>").text(D?D+" ("+u.type+")":UI.format.capital(u.type)).val(u.type)))}i.val(g.forceType);
k.val(g.prioritize_type);o.html(UI.buildUI(h));q=!0}if("meta"in a&&"tracks"in a.meta){var f={},w;for(w in a.meta.tracks)if(h=a.meta.tracks[w],"subtitle"==h.codec&&(h.type="subtitle"),!("audio"!=h.type&&"video"!=h.type&&"subtitle"!=h.type))h.type in f||(f[h.type]="subtitle"==h.type?[]:[["","Autoselect "+h.type]]),f[h.type].push([h.trackid,UI.format.capital(h.type)+" track "+(f[h.type].length+("subtitle"==h.type?1:0))]);l.html("");if(Object.keys(f).length){l.closest("label").show();var a=["audio","video",
"subtitle"],P;for(P in a)if(w=a[P],f[w]&&f[w].length){h=$("<select>").attr("data-type",w).css("flex-grow","1").change(function(){""==$(this).val()?delete g.setTracks[$(this).attr("data-type")]:g.setTracks[$(this).attr("data-type")]=$(this).val();$(".embed_code").setval(c(g))});l.append(h);"subtitle"==w?f[w].unshift(["","No "+w]):f[w].push([-1,"No "+w]);for(var C in f[w])h.append($("<option>").val(f[w][C][0]).text(f[w][C][1]));w in g.setTracks&&(h.val(g.setTracks[w]),null==h.val()&&(h.val(""),delete g.setTracks[w],
$(".embed_code").setval(c(g))))}}else l.closest("label").hide()}}},a,e.replace(/^http/,"ws")+"json_"+encodeURIComponent(a)+".js",!1,"?inclzero=1")}var j=$("<section>").addClass("embedurls"),i=$("<datalist>").attr("id","urlhints"),f=e.HTTPS.concat(e.HTTP),m;for(m in f)i.append($("<option>").val(f[m]));var n=otherhost.host?otherhost.host:f.length?f[0]:b;j.append($("<span>").addClass("input_container").append($("<label>").addClass("UIelement").append($("<span>").addClass("label").text("Use base URL:")).append($("<span>").addClass("field_container").append($("<input>").attr("type",
"text").addClass("field").val(n).attr("list","urlhints")).append(i).append($("<span>").addClass("unit").append($("<button>").text("Apply").click(function(){otherhost.host=$(this).closest("label").find("input").val();"/"!=otherhost.host.slice(-1)&&(otherhost.host+="/");UI.navto("Embed",a)}))))));var k=encodeURIComponent(a),q=!1,h={forcePlayer:"",forceType:"",controls:!0,autoplay:!0,loop:!1,muted:!1,fillSpace:!1,poster:"",urlappend:"",setTracks:{}},g=$.extend({},h),i=UI.stored.getOpts();"embedoptions"in
i&&(g=$.extend(g,i.embedoptions,!0),"object"!=typeof g.setTracks&&(g.setTracks={}));i={};switch(g.controls){case "stock":i.controls="stock";break;case !0:i.controls=1;break;case !1:i.controls=0}var f=c(g),l=$("<div>").text("Loading..").css("display","flex").css("flex-flow","column nowrap"),o=$("<span>").text("Loading..").css("word-break","break-all");if(mistplayers){var u=[["","Automatic"]];for(m in mistplayers)u.push([m,mistplayers[m].name])}j.append(UI.buildUI([$("<h3>").text("Urls"),{label:"Stream info json",
type:"str",value:n+"json_"+k+".js",readonly:!0,clipboard:!0,help:"Information about this stream as a json page."},{label:"Stream info script",type:"str",value:n+"info_"+k+".js",readonly:!0,clipboard:!0,help:"This script loads information about this stream into a mistvideo javascript object."},{label:"HTML page",type:"str",value:n+k+".html",readonly:!0,qrcode:!0,clipboard:!0,help:"A basic html containing the embedded stream."},$("<h3>").text("Embed code"),{label:"Embed code",type:"textarea",value:f,
rows:f.split("\n").length+3,readonly:!0,classes:["embed_code"],clipboard:!0,help:"Include this code on your webpage to embed the stream. The options below can be used to configure how your content is displayed."},$("<h4>").text("Embed code options (optional)").css("margin-top",0),{type:"help",help:"Use these controls to customise what this embedded video will look like.<br>Not all players have all of these options."},{label:"Prioritize type",type:"select",select:[["","Automatic"]],pointer:{main:g,
index:"prioritize_type"},classes:["prioritize_type"],"function":function(){if(q){g.prioritize_type=$(this).getval();$(".embed_code").setval(c(g))}},help:"Try to use this source type first, but full back to something else if it is not available."},{label:"Force type",type:"select",select:[["","Automatic"]],pointer:{main:g,index:"forceType"},classes:["forceType"],"function":function(){if(q){g.forceType=$(this).getval();$(".embed_code").setval(c(g))}},help:"Only use this particular source."},{label:"Force player",
type:"select",select:u,pointer:{main:g,index:"forcePlayer"},classes:["forcePlayer"],"function":function(){if(q){g.forcePlayer=$(this).getval();$(".embed_code").setval(c(g))}},help:"Only use this particular player."},{label:"Controls",type:"select",select:[["1","MistServer Controls"],["stock","Player controls"],["0","None"]],pointer:{main:i,index:"controls"},"function":function(){g.controls=$(this).getval()==1;switch($(this).getval()){case 0:g.controls=false;break;case 1:g.controls=true;break;case "stock":g.controls=
"stock"}$(".embed_code").setval(c(g))},help:"The type of controls that should be shown."},{label:"Autoplay",type:"checkbox",pointer:{main:g,index:"autoplay"},"function":function(){g.autoplay=$(this).getval();$(".embed_code").setval(c(g))},help:"Whether or not the video should play as the page is loaded."},{label:"Loop",type:"checkbox",pointer:{main:g,index:"loop"},"function":function(){g.loop=$(this).getval();$(".embed_code").setval(c(g))},help:"If the video should restart when the end is reached."},
{label:"Start muted",type:"checkbox",pointer:{main:g,index:"muted"},"function":function(){g.muted=$(this).getval();$(".embed_code").setval(c(g))},help:"If the video should restart when the end is reached."},{label:"Fill available space",type:"checkbox",pointer:{main:g,index:"fillSpace"},"function":function(){g.fillSpace=$(this).getval();$(".embed_code").setval(c(g))},help:"The video will fit the available space in its container, even if the video stream has a smaller resolution."},{label:"Poster",
type:"str",pointer:{main:g,index:"poster"},"function":function(){g.poster=$(this).getval();$(".embed_code").setval(c(g))},help:"URL to an image that is displayed when the video is not playing."},{label:"Video URL addition",type:"str",pointer:{main:g,index:"urlappend"},help:"The embed script will append this string to the video url, useful for sending through params.",classes:["embed_code_forceprotocol"],"function":function(){g.urlappend=$(this).getval();$(".embed_code").setval(c(g))}},{label:"Preselect tracks",
type:"DOMfield",DOMfield:l,help:"Pre-select these tracks."},{label:"Monitoring action",type:"select",select:[["","Ask the viewer what to do"],["nextCombo","Try the next source / player combination"]],pointer:{main:g,index:"monitor_action"},"function":function(){g.monitor_action=$(this).getval();$(".embed_code").setval(c(g))},help:"What the player should do when playback is poor."},$("<h3>").text("Protocol stream urls"),o]));d(n);return j}}},sockets:{http_host:null,http:{api:{command:{},listeners:[],
interval:!1,get:function(){var a=this;mist.send(function(b){for(var e in a.listeners)a.listeners[e](b)},a.command)},init:function(){var a=this;a.get();a.interval=UI.interval.set(function(){a.get()},5E3)},subscribe:function(a,b){this.command=Object.assign(this.command,b);this.listeners.push(a);(!this.interval||!(this.interval in UI.interval.list))&&this.init()}},player:function(a,b){if(mistPlay)a();else{UI.sockets.http_host||b("Could not find player.js: MistServer host unknown");var e=UI.sockets.http_host+
"player.js";$.ajax({type:"GET",url:e,success:function(){a()},error:function(){b("Error while retrieving player.js from "+e)}})}}},ws:{info_json:{children:{},init:function(a){var b=UI.websockets.create(a);this.children[a]={ws:!1,messages:[],listeners:[]};this.children[a].ws=b;var e=this;b.onmessage=function(b){b=JSON.parse(b.data);if(a in e.children){e.children[a].messages.push(b);for(var c in e.children[a].listeners)e.children[a].listeners[c](b)}};b.onerror=function(b){if(a in e.children)for(var c in e.children[a].listeners)e.children[a].listeners[c](b)};
b.cleanup=function(){delete e.children[a];b.onclose=function(){};b.onmessage=function(){}};var c=b.close;b.close=function(){b.cleanup();return c.apply(this,arguments)};b.onclose=function(){b.cleanup()}},subscribe:function(a,b,e,c){if(!a)throw"Callback function not specified.";if(!b&&!e)throw"Stream name not specified.";c||(c="");if(!e){if(!UI.sockets.http_host){var d=this,j=arguments;UI.modules.stream.findMist(function(){d.subscribe.apply(d,j)});return}e=UI.sockets.http_host.replace(/^http/,"ws")+
"json_"+encodeURIComponent(b)+".js"+c}(!(e in this.children)||1<this.children[e].ws.readyState)&&this.init(e);for(var i in this.children[e].messages)a(this.children[e].messages[i]);this.children[e].listeners.push(a)}},active_streams:{ws:!1,listeners:[],messages:[],init:function(){var a=parseURL(mist.user.host),a=parseURL(mist.user.host,{pathname:a.pathname.replace(/\/api$/,"")+"/ws",search:"?logs=100&accs=100&streams=1"}),b=UI.websockets.create(a.full.replace(/^http/,"ws"));this.ws=b;var e=this;b.authState=
0;b.onmessage=function(a){var b=JSON.parse(a.data),a=b[0],b=b[1];if("auth"==a)!0===b?this.authState=2:!1===b?(this.send(JSON.stringify(["auth",{password:MD5(mist.user.password+mist.user.authstring),username:mist.user.name}])),this.authState=1):"object"==typeof b&&("challenge"in b?(this.send(JSON.stringify(["auth",{password:MD5(mist.user.password+b.challenge),username:mist.user.name}])),this.authState=1):"status"in b&&"OK"==b.status&&(this.authState=2));else{e.messages.push([a,b]);for(var j in e.listeners)e.listeners[j](a,
b)}};b.onclose=function(){e.listeners=[];e.messages=[];e.ws=!1};b.keepAlive=function(){setTimeout(function(){1==b.readyState&&(b.send(""),b.keepAlive())},200)};b.onopen=function(){b.keepAlive()}},subscribe:function(a){(!this.ws||1<this.ws.readyState)&&this.init();for(var b in this.messages)a(this.messages[b][0],this.messages[b][1]);this.listeners.push(a)}}}}};"origin"in location||(location.origin=location.protocol+"//");var host;
this.children[b].moved=!0;this.children[b][0].parentNode.removeChild(this.children[b][0])}}else this[0].parentNode&&this[0].parentNode.removeChild(this[0])},values:c,getEntries:function(b){var c={},d=!1;1==a.split("+").length&&(d=!0);for(var e in b){var f=b[e];if(f[1]==a||!d&&f[1].split("+")[0]==a)c[f[0]]=f}return c}});n.update=function(){return j.update.apply(j,arguments)};return n}b.html("");b.append($("<h4>").text("Automatic pushes"));b.append($("<button>").text("Add an automatic push").click(function(){UI.navto("Start Push",
"auto")}));b.append(c("Automatic",d.push_auto_list));b.append($("<h4>").text("Active pushes"));b.append($("<button>").text("Start a push").click(function(){UI.navto("Start Push")}));var e=c("Manual",d.push_list);b.append(e);UI.sockets.http.api.subscribe(function(a){e.update(a.push_list)},{push_list:1})},{push_auto_list:1,push_list:1});return $("<section>").addClass("pushes").append($("<h3>").text("Pushes and recordings")).append(b)},logs:function(a){var b=$("<div>").attr("onempty","None.").addClass("logs"),
d=!1;UI.sockets.ws.active_streams.subscribe(function(c,e){if("log"==c){var l=b[0].scrollTop>=b[0].scrollHeight-b[0].clientHeight;if(!(""!=e[3]&&e[3]!=a.split("+")[0])&&"ACCS"!=e[1]){var i=$("<div>").attr("data-debuglevel",e[1]).html($("<span>").addClass("description").text(UI.format.dateTime(e[0]))).append($("<span>").text(e[3])).append($("<span>").text(e[1]+":")).append($("<span>").text(e[2]));b.append(i);l&&(b[0].scrollTop=b[0].scrollHeight);if(d)try{l=d.document.scrollingElement.scrollTop>=d.document.scrollingElement.scrollHeight-
d.document.scrollingElement.clientHeight,d.document.write(i[0].outerHTML),l&&(d.document.scrollingElement.scrollTop=d.document.scrollingElement.scrollHeight)}catch(f){}}}});return $("<section>").addClass("logs").append($("<h3>").text("MistServer logs")).append($("<button>").text("Open raw").click(function(){d=window.open("","MistServer logs for "+a);d.document.write("<html><head><title>MistServer logs for '"+a+'\'</title><meta http-equiv="content-type" content="application/json; charset=utf-8"><style>body{padding-left:2em;text-indent:-2em;}body>*>*:not(:last-child):not(:empty){padding-right:.5em;}.description{font-size:.9em;color:#777}</style></head><body>');
d.document.write(b[0].innerHTML);d.document.scrollingElement.scrollTop=d.document.scrollingElement.scrollHeight})).append(b)},accesslogs:function(a){var b=$("<div>").attr("onempty","None.").addClass("accesslogs"),d=!1;UI.sockets.ws.active_streams.subscribe(function(c,e){if("access"==c){var l=b[0].scrollTop>=b[0].scrollHeight-b[0].clientHeight;if(!(""!=e[2]&&e[2]!=a.split("+")[0])){var i=$("<div>").html($("<span>").addClass("description").text(UI.format.dateTime(e[0]))).append($("<span>").attr("beforeifnotempty",
"Token: ").attr("title",e[1]).css("max-width","10em").text(e[1])).append($("<span>").attr("beforeifnotempty","Connector: ").text(e[3])).append($("<span>").attr("beforeifnotempty","Hostname: ").text(e[4])).append($("<span>").attr("beforeifnotempty","Connected for: ").html(UI.format.duration(e[5]))).append($("<span>").html("\u2191"+UI.format.bytes(e[6]))).append($("<span>").html("\u2193"+UI.format.bytes(e[7]))).append($("<span>").attr("beforeifnotempty","Tags: ").text(e[8]));b.append(i);l&&(b[0].scrollTop=
b[0].scrollHeight);if(d)try{l=d.document.scrollingElement.scrollTop>=d.document.scrollingElement.scrollHeight-d.document.scrollingElement.clientHeight,d.document.write(i[0].outerHTML),l&&(d.document.scrollingElement.scrollTop=d.document.scrollingElement.scrollHeight)}catch(f){}}}});return $("<section>").addClass("accesslogs").append($("<h3>").text("Access logs")).append($("<button>").text("Open raw").click(function(){d=window.open("","MistServer access logs for "+a);d.document.write("<html><head><title>MistServer access logs for '"+
a+'\'</title><meta http-equiv="content-type" content="application/json; charset=utf-8"><style>body{padding-left:2em;text-indent:-2em;}body>*>*:not(:last-child):not(:empty){padding-right:.5em;}.description{font-size:.9em;color:#777}[beforeifnotempty]:not(:empty):before{content:attr(beforeifnotempty);color:#777}</style></head><body>');d.document.write(b[0].innerHTML);d.document.scrollingElement.scrollTop=d.document.scrollingElement.scrollHeight})).append(b)},preview:function(a,b){var d=$("<section>").addClass("preview");
b||(window.mv={},b=mv);UI.sockets.http.player(function(){mistPlay(a,{target:d[0],host:UI.sockets.http_host,skin:"dev",loop:true,MistVideoObject:b})},function(a){$preciew_cont.html(a)});return d},playercontrols:function(a,b){function d(){function b(a){return d.UI.buildStructure.call(d.UI,a)}var d=a.reference,i=b({"if":function(){return this.playerName&&this.source},then:{type:"container",classes:["mistvideo-description"],style:{display:"block"},children:[{type:"playername",style:{display:"inline"}},
{type:"text",text:"is playing",style:{margin:"0 0.2em"}},{type:"mimetype"}]}}),f=b({type:"container",classes:["mistvideo-column","mistvideo-devcontrols"],children:[{type:"text",text:"Player control"},{type:"container",classes:["mistvideo-devbuttons"],style:{"flex-wrap":"wrap"},children:[{"if":function(){return!(!this.player||!this.player.api)},then:{type:"button",title:"Reload the video source",label:"Reload video",onclick:function(){this.player.api.load()}}},{type:"button",title:"Build MistVideo again",
label:"Reload player",onclick:function(){this.reload()}},{type:"button",title:"Switch to the next available player and source combination",label:"Try next combination",onclick:function(){this.nextCombo()}}]},{type:"forcePlayer"},{type:"forceType"},{type:"forceSource"}]}),m=b({type:"decodingIssues",style:{"max-width":"30em","flex-flow":"column nowrap"}}),n=b({type:"log"}),j=$("<button>").text("Open raw").css({display:"block",marginTop:"0.333em"}).click(function(){var a=d.stream;tab=window.open("",
"Player logs for "+a);tab.document.write("<html><head><title>Player logs for '"+a+'\'</title><meta http-equiv="content-type" content="application/json; charset=utf-8"><style>.timestamp{color:#777;font-size:0.9em;}</style></head><body>');tab.document.write(n.lastChild.outerHTML);tab.document.scrollingElement.scrollTop=tab.document.scrollingElement.scrollHeight});n.insertBefore(j[0],n.children[0]);c.html($("<div>").append($("<div>").append($("<h3>").addClass("title").text("MistPlayer")).append(i)).append(f).append(m)).append(n)}
var c=$("<section>").addClass("controls").addClass("mistvideo").html($("<h3>").text("MistPlayer")).append($("<p>").text("Waiting for player.."));b||(b=$(".dashboard"));$("link#devcss").length||document.head.appendChild($("<link>").attr("rel","stylesheet").attr("type","text/css").attr("href",UI.sockets.http_host+"skins/dev.css").attr("id","devcss")[0]);a&&(a.reference&&a.reference.skin)&&d();b[0].addEventListener("initialized",function(){d()});b[0].addEventListener("initializedFailed",function(){d()});
return c},embedurls:function(a,b,d){function c(){function b(a){switch(typeof a){case "string":return $.isNumeric(a)?a:'"'+a+'"';case "object":return JSON.stringify(a);default:return a}}q&&UI.stored.saveOpt("embedoptions",h);for(var c=a+"_",e=12,f="";e--;){var i;i=Math.floor(62*Math.random());i=10>i?i:36>i?String.fromCharCode(i+55):String.fromCharCode(i+61);f+=i}var c=c+f,e=['target: document.getElementById("'+c+'")'],k;for(k in h)"prioritize_type"==k?h[k]&&""!=h[k]&&e.push("forcePriority: "+JSON.stringify({source:[["type",
[h[k]]]]})):"monitor_action"==k?h[k]&&""!=h[k]&&"nextCombo"==h[k]&&e.push('monitor: {\n action: function(){\n this.MistVideo.log("Switching to nextCombo because of poor playback in "+this.MistVideo.source.type+" ("+Math.round(this.vars.score*1000)/10+"%)");\n this.MistVideo.nextCombo();\n }\n }'):h[k]!=g[k]&&(null!=h[k]&&("object"!=typeof h[k]||JSON.stringify(h[k])!=JSON.stringify(g[k])))&&e.push(k+": "+b(h[k]));k=[];k.push('<div class="mistvideo" id="'+
c+'">');k.push(" <noscript>");k.push(' <a href="'+n+j+'.html" target="_blank">');k.push(" Click here to play this video");k.push(" </a>");k.push(" </noscript>");k.push(" <script>");k.push(" var a = function(){");k.push(' mistPlay("'+a+'",{');k.push(" "+e.join(",\n "));k.push(" });");k.push(" };");k.push(" if (!window.mistplayers) {");k.push(' var p = document.createElement("script");');d.HTTPS.length?(k.push(' if (location.protocol == "https:") { p.src = "'+
("https://"==parseURL(n).protocol?n:d.HTTPS[0])+'player.js" } '),k.push(' else { p.src = "'+("http://"==parseURL(n).protocol?n:d.HTTP[0])+'player.js" } ')):k.push(' p.src = "'+n+'player.js"');k.push(" document.head.appendChild(p);");k.push(" p.onload = a;");k.push(" }");k.push(" else { a(); }");k.push(" <\/script>");k.push("</div>");return k.join("\n")}function e(d){UI.sockets.ws.info_json.subscribe(function(a){if("error"==a.type)if(d==n)e(b);else throw a;else{if("source"in
a&&(!q||a.source.length)){var g=d==n?!1:n,f=[],i=l.find(".field.forceType"),j=l.find(".field.prioritize_type");g&&(g=g.replace(parseURL(g).protocol,""),f.push($("<div>").addClass("orange").html('Warning: the provided base URL <a href="'+n+'">'+n+"</a> could not be reached. These links are my best guess but will probably not work properly.").css({margin:"0.5em 0",width:"45em","word-break":"normal"})));for(var m in a.source){var s=a.source[m],C=UI.humanMime(s.type),u=s.url;g&&(u=parseURL(s.url).protocol+
g+s.relurl);var D=u.match(/[\?\&]tkn=\d+\&?/);D&&(D=D[0],u=u.replace(D,"?"==D[0]&&"&"==D.slice(-1)?"?":"&"==D.slice(-1)?"&":""));f.push({label:C?C+" <span class=description>("+s.type+")</span>":UI.format.capital(s.type),type:"str",value:u,readonly:!0,qrcode:!0,clipboard:!0});C=UI.humanMime(s.type);0==i.children('option[value="'+s.type+'"]').length&&(i.append($("<option>").text(C?C+" ("+s.type+")":UI.format.capital(s.type)).val(s.type)),j.append($("<option>").text(C?C+" ("+s.type+")":UI.format.capital(s.type)).val(s.type)))}i.val(h.forceType);
j.val(h.prioritize_type);o.html(UI.buildUI(f));q=!0}if("meta"in a&&"tracks"in a.meta){var g={},v;for(v in a.meta.tracks)if(f=a.meta.tracks[v],"subtitle"==f.codec&&(f.type="subtitle"),!("audio"!=f.type&&"video"!=f.type&&"subtitle"!=f.type))f.type in g||(g[f.type]="subtitle"==f.type?[]:[["","Autoselect "+f.type]]),g[f.type].push([f.trackid,UI.format.capital(f.type)+" track "+(g[f.type].length+("subtitle"==f.type?1:0))]);k.html("");if(Object.keys(g).length){k.closest("label").show();var a=["audio","video",
"subtitle"],A;for(A in a)if(v=a[A],g[v]&&g[v].length){f=$("<select>").attr("data-type",v).css("flex-grow","1").change(function(){""==$(this).val()?delete h.setTracks[$(this).attr("data-type")]:h.setTracks[$(this).attr("data-type")]=$(this).val();$(".embed_code").setval(c(h))});k.append(f);"subtitle"==v?g[v].unshift(["","No "+v]):g[v].push([-1,"No "+v]);for(var L in g[v])f.append($("<option>").val(g[v][L][0]).text(g[v][L][1]));v in h.setTracks&&(f.val(h.setTracks[v]),null==f.val()&&(f.val(""),delete h.setTracks[v],
$(".embed_code").setval(c(h))))}}else k.closest("label").hide()}}},a,d.replace(/^http/,"ws")+"json_"+encodeURIComponent(a)+".js",!1,"?inclzero=1")}var l=$("<section>").addClass("embedurls"),i=$("<datalist>").attr("id","urlhints"),f=d.HTTPS.concat(d.HTTP),m;for(m in f)i.append($("<option>").val(f[m]));var n=otherhost.host?otherhost.host:f.length?f[0]:b;l.append($("<span>").addClass("input_container").append($("<label>").addClass("UIelement").append($("<span>").addClass("label").text("Use base URL:")).append($("<span>").addClass("field_container").append($("<input>").attr("type",
"text").addClass("field").val(n).attr("list","urlhints")).append(i).append($("<span>").addClass("unit").append($("<button>").text("Apply").click(function(){otherhost.host=$(this).closest("label").find("input").val();"/"!=otherhost.host.slice(-1)&&(otherhost.host+="/");UI.navto("Embed",a)}))))));var j=encodeURIComponent(a),q=!1,g={forcePlayer:"",forceType:"",controls:!0,autoplay:!0,loop:!1,muted:!1,fillSpace:!1,poster:"",urlappend:"",setTracks:{}},h=$.extend({},g),i=UI.stored.getOpts();"embedoptions"in
i&&(h=$.extend(h,i.embedoptions,!0),"object"!=typeof h.setTracks&&(h.setTracks={}));i={};switch(h.controls){case "stock":i.controls="stock";break;case !0:i.controls=1;break;case !1:i.controls=0}var f=c(h),k=$("<div>").text("Loading..").css("display","flex").css("flex-flow","column nowrap"),o=$("<span>").text("Loading..").css("word-break","break-all");if(mistplayers){var s=[["","Automatic"]];for(m in mistplayers)s.push([m,mistplayers[m].name])}l.append(UI.buildUI([$("<h3>").text("Urls"),{label:"Stream info json",
type:"str",value:n+"json_"+j+".js",readonly:!0,clipboard:!0,help:"Information about this stream as a json page."},{label:"Stream info script",type:"str",value:n+"info_"+j+".js",readonly:!0,clipboard:!0,help:"This script loads information about this stream into a mistvideo javascript object."},{label:"HTML page",type:"str",value:n+j+".html",readonly:!0,qrcode:!0,clipboard:!0,help:"A basic html containing the embedded stream."},$("<h3>").text("Embed code"),{label:"Embed code",type:"textarea",value:f,
rows:f.split("\n").length+3,readonly:!0,classes:["embed_code"],clipboard:!0,help:"Include this code on your webpage to embed the stream. The options below can be used to configure how your content is displayed."},$("<h4>").text("Embed code options (optional)").css("margin-top",0),{type:"help",help:"Use these controls to customise what this embedded video will look like.<br>Not all players have all of these options."},{label:"Prioritize type",type:"select",select:[["","Automatic"]],pointer:{main:h,
index:"prioritize_type"},classes:["prioritize_type"],"function":function(){if(q){h.prioritize_type=$(this).getval();$(".embed_code").setval(c(h))}},help:"Try to use this source type first, but full back to something else if it is not available."},{label:"Force type",type:"select",select:[["","Automatic"]],pointer:{main:h,index:"forceType"},classes:["forceType"],"function":function(){if(q){h.forceType=$(this).getval();$(".embed_code").setval(c(h))}},help:"Only use this particular source."},{label:"Force player",
type:"select",select:s,pointer:{main:h,index:"forcePlayer"},classes:["forcePlayer"],"function":function(){if(q){h.forcePlayer=$(this).getval();$(".embed_code").setval(c(h))}},help:"Only use this particular player."},{label:"Controls",type:"select",select:[["1","MistServer Controls"],["stock","Player controls"],["0","None"]],pointer:{main:i,index:"controls"},"function":function(){h.controls=$(this).getval()==1;switch($(this).getval()){case 0:h.controls=false;break;case 1:h.controls=true;break;case "stock":h.controls=
"stock"}$(".embed_code").setval(c(h))},help:"The type of controls that should be shown."},{label:"Autoplay",type:"checkbox",pointer:{main:h,index:"autoplay"},"function":function(){h.autoplay=$(this).getval();$(".embed_code").setval(c(h))},help:"Whether or not the video should play as the page is loaded."},{label:"Loop",type:"checkbox",pointer:{main:h,index:"loop"},"function":function(){h.loop=$(this).getval();$(".embed_code").setval(c(h))},help:"If the video should restart when the end is reached."},
{label:"Start muted",type:"checkbox",pointer:{main:h,index:"muted"},"function":function(){h.muted=$(this).getval();$(".embed_code").setval(c(h))},help:"If the video should restart when the end is reached."},{label:"Fill available space",type:"checkbox",pointer:{main:h,index:"fillSpace"},"function":function(){h.fillSpace=$(this).getval();$(".embed_code").setval(c(h))},help:"The video will fit the available space in its container, even if the video stream has a smaller resolution."},{label:"Poster",
type:"str",pointer:{main:h,index:"poster"},"function":function(){h.poster=$(this).getval();$(".embed_code").setval(c(h))},help:"URL to an image that is displayed when the video is not playing."},{label:"Video URL addition",type:"str",pointer:{main:h,index:"urlappend"},help:"The embed script will append this string to the video url, useful for sending through params.",classes:["embed_code_forceprotocol"],"function":function(){h.urlappend=$(this).getval();$(".embed_code").setval(c(h))}},{label:"Preselect tracks",
type:"DOMfield",DOMfield:k,help:"Pre-select these tracks."},{label:"Monitoring action",type:"select",select:[["","Ask the viewer what to do"],["nextCombo","Try the next source / player combination"]],pointer:{main:h,index:"monitor_action"},"function":function(){h.monitor_action=$(this).getval();$(".embed_code").setval(c(h))},help:"What the player should do when playback is poor."},$("<h3>").text("Protocol stream urls"),o]));e(n);return l}}},sockets:{http_host:null,http:{api:{command:{},listeners:[],
interval:!1,get:function(){var a=this;mist.send(function(b){for(var d in a.listeners)a.listeners[d](b)},a.command)},init:function(){var a=this;a.get();a.interval=UI.interval.set(function(){a.get()},5E3)},subscribe:function(a,b){this.command=Object.assign(this.command,b);this.listeners.push(a);(!this.interval||!(this.interval in UI.interval.list))&&this.init()}},player:function(a,b){if(mistPlay)a();else{UI.sockets.http_host||b("Could not find player.js: MistServer host unknown");var d=UI.sockets.http_host+
"player.js";$.ajax({type:"GET",url:d,success:function(){a()},error:function(){b("Error while retrieving player.js from "+d)}})}}},ws:{info_json:{children:{},init:function(a){var b=UI.websockets.create(a);this.children[a]={ws:!1,listeners:[]};this.children[a].ws=b;var d=this;b.onmessage=function(b){b=JSON.parse(b.data);if(a in d.children)for(var c in d.children[a].listeners)d.children[a].listeners[c](b)};b.onerror=function(b){if(a in d.children)for(var c in d.children[a].listeners)d.children[a].listeners[c](b)};
b.cleanup=function(){delete d.children[a];b.onclose=function(){};b.onmessage=function(){}};var c=b.close;b.close=function(){b.cleanup();return c.apply(this,arguments)};b.onclose=function(){b.cleanup()}},subscribe:function(a,b,d,c){if(!a)throw"Callback function not specified.";if(!b&&!d)throw"Stream name not specified.";c||(c="");d||(d=UI.sockets.http_host.replace(/^http/,"ws")+"json_"+encodeURIComponent(b)+".js"+c);(!(d in this.children)||1<this.children[d].ws.readyState)&&this.init(d);this.children[d].listeners.push(a)}},
active_streams:{ws:!1,listeners:[],init:function(){var a=parseURL(mist.user.host),a=parseURL(mist.user.host,{pathname:a.pathname.replace(/\/api$/,"")+"/ws",search:"?logs=100&accs=100&streams=1"});this.ws=a=UI.websockets.create(a.full.replace(/^http/,"ws"));var b=this;a.authState=0;a.onmessage=function(a){var c=JSON.parse(a.data),a=c[0],c=c[1];if("auth"==a)!0===c?this.authState=2:!1===c?(this.send(JSON.stringify(["auth",{password:MD5(mist.user.password+mist.user.authstring),username:mist.user.name}])),
this.authState=1):"object"==typeof c&&("challenge"in c?(this.send(JSON.stringify(["auth",{password:MD5(mist.user.password+c.challenge),username:mist.user.name}])),this.authState=1):"status"in c&&"OK"==c.status&&(this.authState=2));else for(var e in b.listeners)b.listeners[e](a,c)};a.onclose=function(){b.listeners=[];b.ws=!1}},subscribe:function(a){(!this.ws||1<this.ws.readyState)&&this.init();this.listeners.push(a)}}}}};"origin"in location||(location.origin=location.protocol+"//");var host;
host="file://"==location.origin?"http://localhost:4242/api":location.origin+location.pathname.replace(/\/+$/,"")+"/api";
var mist={data:{},user:{name:"",password:"",host:host},send:function(a,b,e){var b=b||{},e=e||{},e=$.extend(true,{timeOut:3E4,sendData:b},e),c={authorize:{password:mist.user.authstring?MD5(mist.user.password+mist.user.authstring):"",username:mist.user.name}};$.extend(true,c,b);log("Send",$.extend(true,{},b));var d={url:mist.user.host,type:"POST",data:{command:JSON.stringify(c)},dataType:"jsonp",crossDomain:true,timeout:e.timeout*1E3,async:true,error:function(c,d,m){console.warn("connection failed :(",
m);delete mist.user.loggedin;if(!e.hide){switch(d){case "timeout":d=$("<i>").text("The connection timed out. ");break;case "abort":d=$("<i>").text("The connection was aborted. ");break;default:d=$("<i>").text(d+". ").css("text-transform","capitalize")}$("#message").addClass("red").text("An error occurred while attempting to communicate with MistServer:").append($("<br>")).append($("<span>").text(d)).append($("<a>").text("Send server request again").click(function(){mist.send(a,b,e)}))}UI.navto("Login")},
success:function(d,f,m){log("Receive",$.extend(true,{},d),"as reply to",e.sendData);mist.lastrequest=m;delete mist.user.loggedin;switch(d.authorize.status){case "OK":if("streams"in d)if(d.streams)if("incomplete list"in d.streams){delete d.streams["incomplete list"];$.extend(mist.data.streams,d.streams)}else mist.data.streams=d.streams;else mist.data.streams={};var f=$.extend({},d),m=["config","capabilities","ui_settings","LTS","active_streams","browse","log","totals","bandwidth","variable_list","external_writer_list"],
j;for(j in f)m.indexOf(j)==-1&&delete f[j];if("bandwidth"in c&&!("bandwidth"in d))f.bandwidth=null;e.sendData.capabilities&&e.sendData.capabilities!==true&&delete f.capabilities;$.extend(mist.data,f);mist.user.loggedin=true;UI.elements.connection.status.text("Connected").removeClass("red").addClass("green");UI.elements.connection.user_and_host.text(mist.user.name+" @ "+mist.user.host);UI.elements.connection.msg.removeClass("red").text("Last communication with the server at "+UI.format.time((new Date).getTime()/
1E3));if(d.log){f=d.log[d.log.length-1];UI.elements.connection.msg.append($("<br>")).append($("<span>").text("Last log entry: "+UI.format.time(f[0])+" ["+f[1]+"] "+f[2]))}if("totals"in d){f=function(a,b,c){var d;d=function(){for(var a in c.fields)e[c.fields[a]].push([j,0])};var e={},f;for(f in c.fields)e[c.fields[f]]=[];var i=0,j;if(c.data){if(c.start>mist.data.config.time-600){j=(mist.data.config.time-600)*1E3;d();j=c.start*1E3;d()}else j=c.start*1E3;for(f in c.data){if(f==0){j=c.start*1E3;var m=
0}else{j=j+c.interval[m][1]*1E3;c.interval[m][0]--;if(c.interval[m][0]<=0){m++;m<c.interval.length-1&&(i=i+2)}}if(i%2==1){d();i--}for(var n in c.data[f])e[c.fields[n]].push([j,c.data[f][n]]);if(i){d();i--}}if(mist.data.config.time-c.end>20){d();j=(mist.data.config.time-15)*1E3;d()}}else{j=(mist.data.config.time-600)*1E3;d();j=(mist.data.config.time-15)*1E3;d()}d=e;stream=a?a.join(" "):"all_streams";protocol=b?b.join("_"):"all_protocols";stream in mist.data.totals||(mist.data.totals[stream]={});protocol in
mist.data.totals[stream]||(mist.data.totals[stream][protocol]={});$.extend(mist.data.totals[stream][protocol],d)};mist.data.totals={};if("fields"in d.totals)f(b.totals.streams,b.totals.protocols,d.totals);else for(j in d.totals)f(b.totals[j].streams,b.totals[j].protocols,d.totals[j])}a&&a(d,e);break;case "CHALL":if(d.authorize.challenge==mist.user.authstring){mist.user.password!=""&&UI.elements.connection.msg.text("The credentials you provided are incorrect.").addClass("red");UI.navto("Login")}else if(mist.user.password==
"")UI.navto("Login");else{mist.user.authstring=d.authorize.challenge;mist.send(a,b,e);sessionStorage.setItem("mistLogin",JSON.stringify({host:mist.user.host,name:mist.user.name,password:mist.user.password}))}break;case "NOACC":UI.navto("Create a new account");break;case "ACC_MADE":delete b.authorize;mist.send(a,b,e);break;default:UI.navto("Login")}}};e.hide||UI.elements.connection.msg.removeClass("red").text("Data sent, waiting for a reply..").append($("<br>")).append($("<a>").text("Cancel request").click(function(){j.abort()}));
var j=$.ajax(d)},inputMatch:function(a,b){if(typeof a=="undefined")return false;typeof a=="string"&&(a=[a]);for(var e in a){var c=a[e].replace(/[^\w\s]/g,"\\$&"),c=c.replace(/\\\*/g,".*");if(RegExp("^(?:[a-zA-Z]:)?"+c+"(?:\\?[^\\?]*)?$","i").test(b))return true}return false},convertBuildOptions:function(a,b){function e(a,c,e){var f={label:UI.format.capital(e.name?e.name:c),pointer:{main:b,index:c},validate:[]};d[a]=="required"&&(!("default"in e)||e["default"]=="")&&f.validate.push("required");if("default"in
e){f.placeholder=e["default"];if(e.type=="select")for(var i in e.select)if(e.select[i][0]==e["default"]){f.placeholder=e.select[i][1];break}}if("help"in e)f.help=e.help;if("unit"in e)f.unit=e.unit;if("placeholder"in e)f.placeholder=e.placeholder;if("datalist"in e)f.datalist=e.datalist;if("type"in e)switch(e.type){case "int":f.type="int";if("max"in e)f.max=e.max;if("min"in e)f.min=e.min;break;case "uint":f.type="int";f.min=0;if("max"in e)f.max=e.max;if("min"in e)f.min=Math.max(f.min,e.min);break;case "radioselect":f.type=
"radioselect";f.radioselect=e.radioselect;break;case "select":f.type="select";f.select=e.select.slice(0);f.validate.indexOf("required")>=0&&f.select.unshift(["","placeholder"in f?"Default ("+f.placeholder+")":""]);break;case "sublist":f.type="sublist";f.saveas={};f.itemLabel=e.itemLabel;f.sublist=mist.convertBuildOptions(e,f.saveas);break;case "group":a=mist.convertBuildOptions({optional:e.options},b);a=a.slice(1);"help"in e&&a.unshift($("<span>").addClass("description").text(e.help));"name"in e&&
a.unshift($("<b>").text(e.name));return $("<div>").addClass("itemsettings").append(UI.buildUI(a));case "bool":f.type="checkbox";break;case "unixtime":f.type="unix";break;case "json":case "debug":case "inputlist":f.type=e.type;break;default:f.type="str"}else f.type="checkbox";if("format"in e)switch(e.format){case "set_or_unset":f.postSave=function(){var a=$(this).data("pointer");a.main[a.index]||delete a.main[a.index]}}"influences"in e?f["function"]=function(){var a=$(this).closest(".UIelement"),b=
a.find("style");if(b.length)b=b[0];else{b=$("<style>").addClass("dependencies")[0];a.append(b)}b.innerHTML=".UIelement[data-dependent-"+c+"]:not([data-dependent-"+c+'~="'+$(this).getval()+'"]) { display: none; }\n';$(b).data("content",b.innerHTML);$("style.dependencies.hidden").each(function(){$(this).html($(this).data("content")).removeClass("hidden")});$(".UIelement:not(:visible) style.dependencies:not(.hidden)").each(function(){$(this).addClass("hidden");$(this).html("")})}:"disable"in e&&(f["function"]=
function(){for(var a=$(this).closest(".input_container"),b=$(this).getval(),c=0;c<e.disable.length;c++){var d=a.find('.field[name="'+e.disable[c]+'"]').closest(".UIelement");if(d.length)b==""?d[0].style.display="":d.hide()}});if("dependent"in e)f.dependent=e.dependent;if("value"in e)f.value=e.value;if("validate"in e){f.validate=f.validate.concat(e.validate);if(e.validate.indexOf("track_selector_parameter")>-1)f.help="<div>"+e.help+"</div><p>Track selector parameters consist of a string value which may be any of the following:</p> <ul><li><code>selector,selector</code>: Selects the union of the given selectors. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>selector,!selector</code>: Selects the difference of the given selectors. Specifically, all tracks part of the first selector that are not part of the second selector. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>selector,|selector</code>: Selects the intersection of the given selectors. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>none</code> or <code>-1</code>: Selects no tracks of this type.</li> <li><code>all</code> or <code>*</code>: Selects all tracks of this type.</li> <li>Any positive integer: Select this specific track ID. Does not apply if the given track ID does not exist or is of the wrong type. <strong>Does</strong> apply if the given track ID is incompatible with the currently active protocol or container format.</li> <li>ISO 639-1/639-3 language code: Select all tracks marked as the given language. Case insensitive.</li> <li>Codec string (e.g. <code>h264</code>): Select all tracks of the given codec. Case insensitive.</li> <li><code>highbps</code>, <code>maxbps</code> or <code>bestbps</code>: Select the track of this type with the highest bit rate.</li> <li><code>lowbps</code>, <code>minbps</code> or <code>worstbps</code>: Select the track of this type with the lowest bit rate.</li> <li><code>Xbps</code> or <code>Xkbps</code> or <code>Xmbps</code>: Select the single of this type which has a bit rate closest to the given number X. This number is in bits, not bytes.</li> <li><code>&gt;Xbps</code> or <code>&gt;Xkbps</code> or <code>&gt;Xmbps</code>: Select all tracks of this type which have a bit rate greater than the given number X. This number is in bits, not bytes.</li> <li><code>&lt;Xbps</code> or <code>&lt;Xkbps</code> or <code>&lt;Xmbps</code>: Select all tracks of this type which have a bit rate less than the given number X. This number is in bits, not bytes.</li> <li><code>max&lt;Xbps</code> or <code>max&lt;Xkbps</code> or <code>max&lt;Xmbps</code>: Select the one track of this type which has the highest bit rate less than the given number X. This number is in bits, not bytes.</li> <li><code>highres</code>, <code>maxres</code> or <code>bestres</code>: Select the track of this type with the highest pixel surface area. Only applied when the track type is video.</li> <li><code>lowres</code>, <code>minres</code> or <code>worstres</code>: Select the track of this type with the lowest pixel surface area. Only applied when the track type is video.</li> <li><code>XxY</code>: Select all tracks of this type with the given pixel surface area in X by Y pixels. Only applied when the track type is video.</li> <li><code>~XxY</code>: Select the single track of this type closest to the given pixel surface area in X by Y pixels. Only applied when the track type is video.</li> <li><code>&gt;XxY</code>: Select all tracks of this type with a pixel surface area greater than X by Y pixels. Only applied when the track type is video.</li> <li><code>&lt;XxY</code>: Select all tracks of this type with a pixel surface area less than X by Y pixels. Only applied when the track type is video.</li> <li><code>720p</code>, <code>1080p</code>, <code>1440p</code>, <code>2k</code>, <code>4k</code>, <code>5k</code>, or <code>8k</code>: Select all tracks of this type with the given pixel surface area. Only applied when the track type is video.</li> <li><code>surround</code>, <code>mono</code>, <code>stereo</code>, <code>Xch</code>: Select all tracks of this type with the given channel count. The 'Xch' variant can use any positive integer for 'X'. Only applied when the track type is audio.</li></ul>";
if(e.validate.indexOf("track_selector")>-1)f.help="<div>"+e.help+"</div><p>A track selector is at least one track type (audio, video or subtitle) combined with a track selector parameter. For example: <code>audio=none&video=maxres</code>.<p>Track selector parameters consist of a string value which may be any of the following:</p> <ul><li><code>selector,selector</code>: Selects the union of the given selectors. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>selector,!selector</code>: Selects the difference of the given selectors. Specifically, all tracks part of the first selector that are not part of the second selector. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>selector,|selector</code>: Selects the intersection of the given selectors. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>none</code> or <code>-1</code>: Selects no tracks of this type.</li> <li><code>all</code> or <code>*</code>: Selects all tracks of this type.</li> <li>Any positive integer: Select this specific track ID. Does not apply if the given track ID does not exist or is of the wrong type. <strong>Does</strong> apply if the given track ID is incompatible with the currently active protocol or container format.</li> <li>ISO 639-1/639-3 language code: Select all tracks marked as the given language. Case insensitive.</li> <li>Codec string (e.g. <code>h264</code>): Select all tracks of the given codec. Case insensitive.</li> <li><code>highbps</code>, <code>maxbps</code> or <code>bestbps</code>: Select the track of this type with the highest bit rate.</li> <li><code>lowbps</code>, <code>minbps</code> or <code>worstbps</code>: Select the track of this type with the lowest bit rate.</li> <li><code>Xbps</code> or <code>Xkbps</code> or <code>Xmbps</code>: Select the single of this type which has a bit rate closest to the given number X. This number is in bits, not bytes.</li> <li><code>&gt;Xbps</code> or <code>&gt;Xkbps</code> or <code>&gt;Xmbps</code>: Select all tracks of this type which have a bit rate greater than the given number X. This number is in bits, not bytes.</li> <li><code>&lt;Xbps</code> or <code>&lt;Xkbps</code> or <code>&lt;Xmbps</code>: Select all tracks of this type which have a bit rate less than the given number X. This number is in bits, not bytes.</li> <li><code>max&lt;Xbps</code> or <code>max&lt;Xkbps</code> or <code>max&lt;Xmbps</code>: Select the one track of this type which has the highest bit rate less than the given number X. This number is in bits, not bytes.</li> <li><code>highres</code>, <code>maxres</code> or <code>bestres</code>: Select the track of this type with the highest pixel surface area. Only applied when the track type is video.</li> <li><code>lowres</code>, <code>minres</code> or <code>worstres</code>: Select the track of this type with the lowest pixel surface area. Only applied when the track type is video.</li> <li><code>XxY</code>: Select all tracks of this type with the given pixel surface area in X by Y pixels. Only applied when the track type is video.</li> <li><code>~XxY</code>: Select the single track of this type closest to the given pixel surface area in X by Y pixels. Only applied when the track type is video.</li> <li><code>&gt;XxY</code>: Select all tracks of this type with a pixel surface area greater than X by Y pixels. Only applied when the track type is video.</li> <li><code>&lt;XxY</code>: Select all tracks of this type with a pixel surface area less than X by Y pixels. Only applied when the track type is video.</li> <li><code>720p</code>, <code>1080p</code>, <code>1440p</code>, <code>2k</code>, <code>4k</code>, <code>5k</code>, or <code>8k</code>: Select all tracks of this type with the given pixel surface area. Only applied when the track type is video.</li> <li><code>surround</code>, <code>mono</code>, <code>stereo</code>, <code>Xch</code>: Select all tracks of this type with the given channel count. The 'Xch' variant can use any positive integer for 'X'. Only applied when the track type is audio.</li></ul>"}return f}
var c=[],d=["required","optional"];"desc"in a&&c.push({type:"help",help:a.desc});for(var j in d)if(a[d[j]]){c.push($("<h4>").text(UI.format.capital(d[j])+" parameters"));var i=Object.keys(a[d[j]]);"sort"in a&&i.sort(function(b,c){return(""+a[d[j]][b][a.sort]).localeCompare(a[d[j]][c][a.sort])});for(var f in i){var m=i[f],n=a[d[j]][m];if(Array.isArray(n))for(var k in n)c.push(e(j,m,n[k]));else c.push(e(j,m,n))}}return c},stored:{get:function(){return mist.data.ui_settings||{}},set:function(a,b){var e=
this.get();e[a]=b;mist.send(function(){},{ui_settings:e})},del:function(a){delete mist.data.ui_settings[a];mist.send(function(){},{ui_settings:mist.data.ui_settings})}}};function log(){try{UI.debug&&[].push.call(arguments,Error().stack);[].unshift.call(arguments,"["+UI.format.time((new Date).getTime()/1E3)+"]");console.log.apply(console,arguments)}catch(a){}}
var mist={data:{},user:{name:"",password:"",host:host},send:function(a,b,d){var b=b||{},d=d||{},d=$.extend(true,{timeOut:3E4,sendData:b},d),c={authorize:{password:mist.user.authstring?MD5(mist.user.password+mist.user.authstring):"",username:mist.user.name}};$.extend(true,c,b);log("Send",$.extend(true,{},b));var e={url:mist.user.host,type:"POST",data:{command:JSON.stringify(c)},dataType:"jsonp",crossDomain:true,timeout:d.timeout*1E3,async:true,error:function(c,e,m){console.warn("connection failed :(",
m);delete mist.user.loggedin;if(!d.hide){switch(e){case "timeout":e=$("<i>").text("The connection timed out. ");break;case "abort":e=$("<i>").text("The connection was aborted. ");break;default:e=$("<i>").text(e+". ").css("text-transform","capitalize")}$("#message").addClass("red").text("An error occurred while attempting to communicate with MistServer:").append($("<br>")).append($("<span>").text(e)).append($("<a>").text("Send server request again").click(function(){mist.send(a,b,d)}))}UI.navto("Login")},
success:function(e,f,m){log("Receive",$.extend(true,{},e),"as reply to",d.sendData);mist.lastrequest=m;delete mist.user.loggedin;switch(e.authorize.status){case "OK":if("streams"in e)if(e.streams)if("incomplete list"in e.streams){delete e.streams["incomplete list"];$.extend(mist.data.streams,e.streams)}else mist.data.streams=e.streams;else mist.data.streams={};var f=$.extend({},e),m=["config","capabilities","ui_settings","LTS","active_streams","browse","log","totals","bandwidth","variable_list","external_writer_list"],
l;for(l in f)m.indexOf(l)==-1&&delete f[l];if("bandwidth"in c&&!("bandwidth"in e))f.bandwidth=null;d.sendData.capabilities&&d.sendData.capabilities!==true&&delete f.capabilities;$.extend(mist.data,f);mist.user.loggedin=true;UI.elements.connection.status.text("Connected").removeClass("red").addClass("green");UI.elements.connection.user_and_host.text(mist.user.name+" @ "+mist.user.host);UI.elements.connection.msg.removeClass("red").text("Last communication with the server at "+UI.format.time((new Date).getTime()/
1E3));if(e.log){f=e.log[e.log.length-1];UI.elements.connection.msg.append($("<br>")).append($("<span>").text("Last log entry: "+UI.format.time(f[0])+" ["+f[1]+"] "+f[2]))}if("totals"in e){f=function(a,b,c){var d;d=function(){for(var a in c.fields)e[c.fields[a]].push([l,0])};var e={},f;for(f in c.fields)e[c.fields[f]]=[];var i=0,l;if(c.data){if(c.start>mist.data.config.time-600){l=(mist.data.config.time-600)*1E3;d();l=c.start*1E3;d()}else l=c.start*1E3;for(f in c.data){if(f==0){l=c.start*1E3;var m=
0}else{l=l+c.interval[m][1]*1E3;c.interval[m][0]--;if(c.interval[m][0]<=0){m++;m<c.interval.length-1&&(i=i+2)}}if(i%2==1){d();i--}for(var n in c.data[f])e[c.fields[n]].push([l,c.data[f][n]]);if(i){d();i--}}if(mist.data.config.time-c.end>20){d();l=(mist.data.config.time-15)*1E3;d()}}else{l=(mist.data.config.time-600)*1E3;d();l=(mist.data.config.time-15)*1E3;d()}d=e;stream=a?a.join(" "):"all_streams";protocol=b?b.join("_"):"all_protocols";stream in mist.data.totals||(mist.data.totals[stream]={});protocol in
mist.data.totals[stream]||(mist.data.totals[stream][protocol]={});$.extend(mist.data.totals[stream][protocol],d)};mist.data.totals={};if("fields"in e.totals)f(b.totals.streams,b.totals.protocols,e.totals);else for(l in e.totals)f(b.totals[l].streams,b.totals[l].protocols,e.totals[l])}a&&a(e,d);break;case "CHALL":if(e.authorize.challenge==mist.user.authstring){mist.user.password!=""&&UI.elements.connection.msg.text("The credentials you provided are incorrect.").addClass("red");UI.navto("Login")}else if(mist.user.password==
"")UI.navto("Login");else{mist.user.authstring=e.authorize.challenge;mist.send(a,b,d);sessionStorage.setItem("mistLogin",JSON.stringify({host:mist.user.host,name:mist.user.name,password:mist.user.password}))}break;case "NOACC":UI.navto("Create a new account");break;case "ACC_MADE":delete b.authorize;mist.send(a,b,d);break;default:UI.navto("Login")}}};d.hide||UI.elements.connection.msg.removeClass("red").text("Data sent, waiting for a reply..").append($("<br>")).append($("<a>").text("Cancel request").click(function(){l.abort()}));
var l=$.ajax(e)},inputMatch:function(a,b){if(typeof a=="undefined")return false;typeof a=="string"&&(a=[a]);for(var d in a){var c=a[d].replace(/[^\w\s]/g,"\\$&"),c=c.replace(/\\\*/g,".*");if(RegExp("^(?:[a-zA-Z]:)?"+c+"(?:\\?[^\\?]*)?$","i").test(b))return true}return false},convertBuildOptions:function(a,b){function d(a,c,d){var f={label:UI.format.capital(d.name?d.name:c),pointer:{main:b,index:c},validate:[]};e[a]=="required"&&(!("default"in d)||d["default"]=="")&&f.validate.push("required");if("default"in
d){f.placeholder=d["default"];if(d.type=="select")for(var i in d.select)if(d.select[i][0]==d["default"]){f.placeholder=d.select[i][1];break}}if("help"in d)f.help=d.help;if("unit"in d)f.unit=d.unit;if("placeholder"in d)f.placeholder=d.placeholder;if("datalist"in d)f.datalist=d.datalist;if("type"in d)switch(d.type){case "int":f.type="int";if("max"in d)f.max=d.max;if("min"in d)f.min=d.min;break;case "uint":f.type="int";f.min=0;if("max"in d)f.max=d.max;if("min"in d)f.min=Math.max(f.min,d.min);break;case "radioselect":f.type=
"radioselect";f.radioselect=d.radioselect;break;case "select":f.type="select";f.select=d.select.slice(0);f.validate.indexOf("required")>=0&&f.select.unshift(["","placeholder"in f?"Default ("+f.placeholder+")":""]);break;case "sublist":f.type="sublist";f.saveas={};f.itemLabel=d.itemLabel;f.sublist=mist.convertBuildOptions(d,f.saveas);break;case "group":a=mist.convertBuildOptions({optional:d.options},b);a=a.slice(1);"help"in d&&a.unshift($("<span>").addClass("description").text(d.help));"name"in d&&
a.unshift($("<b>").text(d.name));return $("<div>").addClass("itemsettings").append(UI.buildUI(a));case "bool":f.type="checkbox";break;case "unixtime":f.type="unix";break;case "json":case "debug":case "inputlist":f.type=d.type;break;default:f.type="str"}else f.type="checkbox";if("format"in d)switch(d.format){case "set_or_unset":f.postSave=function(){var a=$(this).data("pointer");a.main[a.index]||delete a.main[a.index]}}"influences"in d?f["function"]=function(){var a=$(this).closest(".UIelement"),b=
a.find("style");if(b.length)b=b[0];else{b=$("<style>").addClass("dependencies")[0];a.append(b)}b.innerHTML=".UIelement[data-dependent-"+c+"]:not([data-dependent-"+c+'~="'+$(this).getval()+'"]) { display: none; }\n';$(b).data("content",b.innerHTML);$("style.dependencies.hidden").each(function(){$(this).html($(this).data("content")).removeClass("hidden")});$(".UIelement:not(:visible) style.dependencies:not(.hidden)").each(function(){$(this).addClass("hidden");$(this).html("")})}:"disable"in d&&(f["function"]=
function(){for(var a=$(this).closest(".input_container"),b=$(this).getval(),c=0;c<d.disable.length;c++){var e=a.find('.field[name="'+d.disable[c]+'"]').closest(".UIelement");if(e.length)b==""?e[0].style.display="":e.hide()}});if("dependent"in d)f.dependent=d.dependent;if("value"in d)f.value=d.value;if("validate"in d){f.validate=f.validate.concat(d.validate);if(d.validate.indexOf("track_selector_parameter")>-1)f.help="<div>"+d.help+"</div><p>Track selector parameters consist of a string value which may be any of the following:</p> <ul><li><code>selector,selector</code>: Selects the union of the given selectors. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>selector,!selector</code>: Selects the difference of the given selectors. Specifically, all tracks part of the first selector that are not part of the second selector. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>selector,|selector</code>: Selects the intersection of the given selectors. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>none</code> or <code>-1</code>: Selects no tracks of this type.</li> <li><code>all</code> or <code>*</code>: Selects all tracks of this type.</li> <li>Any positive integer: Select this specific track ID. Does not apply if the given track ID does not exist or is of the wrong type. <strong>Does</strong> apply if the given track ID is incompatible with the currently active protocol or container format.</li> <li>ISO 639-1/639-3 language code: Select all tracks marked as the given language. Case insensitive.</li> <li>Codec string (e.g. <code>h264</code>): Select all tracks of the given codec. Case insensitive.</li> <li><code>highbps</code>, <code>maxbps</code> or <code>bestbps</code>: Select the track of this type with the highest bit rate.</li> <li><code>lowbps</code>, <code>minbps</code> or <code>worstbps</code>: Select the track of this type with the lowest bit rate.</li> <li><code>Xbps</code> or <code>Xkbps</code> or <code>Xmbps</code>: Select the single of this type which has a bit rate closest to the given number X. This number is in bits, not bytes.</li> <li><code>&gt;Xbps</code> or <code>&gt;Xkbps</code> or <code>&gt;Xmbps</code>: Select all tracks of this type which have a bit rate greater than the given number X. This number is in bits, not bytes.</li> <li><code>&lt;Xbps</code> or <code>&lt;Xkbps</code> or <code>&lt;Xmbps</code>: Select all tracks of this type which have a bit rate less than the given number X. This number is in bits, not bytes.</li> <li><code>max&lt;Xbps</code> or <code>max&lt;Xkbps</code> or <code>max&lt;Xmbps</code>: Select the one track of this type which has the highest bit rate less than the given number X. This number is in bits, not bytes.</li> <li><code>highres</code>, <code>maxres</code> or <code>bestres</code>: Select the track of this type with the highest pixel surface area. Only applied when the track type is video.</li> <li><code>lowres</code>, <code>minres</code> or <code>worstres</code>: Select the track of this type with the lowest pixel surface area. Only applied when the track type is video.</li> <li><code>XxY</code>: Select all tracks of this type with the given pixel surface area in X by Y pixels. Only applied when the track type is video.</li> <li><code>~XxY</code>: Select the single track of this type closest to the given pixel surface area in X by Y pixels. Only applied when the track type is video.</li> <li><code>&gt;XxY</code>: Select all tracks of this type with a pixel surface area greater than X by Y pixels. Only applied when the track type is video.</li> <li><code>&lt;XxY</code>: Select all tracks of this type with a pixel surface area less than X by Y pixels. Only applied when the track type is video.</li> <li><code>720p</code>, <code>1080p</code>, <code>1440p</code>, <code>2k</code>, <code>4k</code>, <code>5k</code>, or <code>8k</code>: Select all tracks of this type with the given pixel surface area. Only applied when the track type is video.</li> <li><code>surround</code>, <code>mono</code>, <code>stereo</code>, <code>Xch</code>: Select all tracks of this type with the given channel count. The 'Xch' variant can use any positive integer for 'X'. Only applied when the track type is audio.</li></ul>";
if(d.validate.indexOf("track_selector")>-1)f.help="<div>"+d.help+"</div><p>A track selector is at least one track type (audio, video or subtitle) combined with a track selector parameter. For example: <code>audio=none&video=maxres</code>.<p>Track selector parameters consist of a string value which may be any of the following:</p> <ul><li><code>selector,selector</code>: Selects the union of the given selectors. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>selector,!selector</code>: Selects the difference of the given selectors. Specifically, all tracks part of the first selector that are not part of the second selector. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>selector,|selector</code>: Selects the intersection of the given selectors. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>none</code> or <code>-1</code>: Selects no tracks of this type.</li> <li><code>all</code> or <code>*</code>: Selects all tracks of this type.</li> <li>Any positive integer: Select this specific track ID. Does not apply if the given track ID does not exist or is of the wrong type. <strong>Does</strong> apply if the given track ID is incompatible with the currently active protocol or container format.</li> <li>ISO 639-1/639-3 language code: Select all tracks marked as the given language. Case insensitive.</li> <li>Codec string (e.g. <code>h264</code>): Select all tracks of the given codec. Case insensitive.</li> <li><code>highbps</code>, <code>maxbps</code> or <code>bestbps</code>: Select the track of this type with the highest bit rate.</li> <li><code>lowbps</code>, <code>minbps</code> or <code>worstbps</code>: Select the track of this type with the lowest bit rate.</li> <li><code>Xbps</code> or <code>Xkbps</code> or <code>Xmbps</code>: Select the single of this type which has a bit rate closest to the given number X. This number is in bits, not bytes.</li> <li><code>&gt;Xbps</code> or <code>&gt;Xkbps</code> or <code>&gt;Xmbps</code>: Select all tracks of this type which have a bit rate greater than the given number X. This number is in bits, not bytes.</li> <li><code>&lt;Xbps</code> or <code>&lt;Xkbps</code> or <code>&lt;Xmbps</code>: Select all tracks of this type which have a bit rate less than the given number X. This number is in bits, not bytes.</li> <li><code>max&lt;Xbps</code> or <code>max&lt;Xkbps</code> or <code>max&lt;Xmbps</code>: Select the one track of this type which has the highest bit rate less than the given number X. This number is in bits, not bytes.</li> <li><code>highres</code>, <code>maxres</code> or <code>bestres</code>: Select the track of this type with the highest pixel surface area. Only applied when the track type is video.</li> <li><code>lowres</code>, <code>minres</code> or <code>worstres</code>: Select the track of this type with the lowest pixel surface area. Only applied when the track type is video.</li> <li><code>XxY</code>: Select all tracks of this type with the given pixel surface area in X by Y pixels. Only applied when the track type is video.</li> <li><code>~XxY</code>: Select the single track of this type closest to the given pixel surface area in X by Y pixels. Only applied when the track type is video.</li> <li><code>&gt;XxY</code>: Select all tracks of this type with a pixel surface area greater than X by Y pixels. Only applied when the track type is video.</li> <li><code>&lt;XxY</code>: Select all tracks of this type with a pixel surface area less than X by Y pixels. Only applied when the track type is video.</li> <li><code>720p</code>, <code>1080p</code>, <code>1440p</code>, <code>2k</code>, <code>4k</code>, <code>5k</code>, or <code>8k</code>: Select all tracks of this type with the given pixel surface area. Only applied when the track type is video.</li> <li><code>surround</code>, <code>mono</code>, <code>stereo</code>, <code>Xch</code>: Select all tracks of this type with the given channel count. The 'Xch' variant can use any positive integer for 'X'. Only applied when the track type is audio.</li></ul>"}return f}
var c=[],e=["required","optional"];"desc"in a&&c.push({type:"help",help:a.desc});for(var l in e)if(a[e[l]]){c.push($("<h4>").text(UI.format.capital(e[l])+" parameters"));var i=Object.keys(a[e[l]]);"sort"in a&&i.sort(function(b,c){return(""+a[e[l]][b][a.sort]).localeCompare(a[e[l]][c][a.sort])});for(var f in i){var m=i[f],n=a[e[l]][m];if(Array.isArray(n))for(var j in n)c.push(d(l,m,n[j]));else c.push(d(l,m,n))}}return c},stored:{get:function(){return mist.data.ui_settings||{}},set:function(a,b){var d=
this.get();d[a]=b;mist.send(function(){},{ui_settings:d})},del:function(a){delete mist.data.ui_settings[a];mist.send(function(){},{ui_settings:mist.data.ui_settings})}}};function log(){try{UI.debug&&[].push.call(arguments,Error().stack);[].unshift.call(arguments,"["+UI.format.time((new Date).getTime()/1E3)+"]");console.log.apply(console,arguments)}catch(a){}}
$.fn.getval=function(){var a=$(this).data("opts"),b=$(this).val();if(a&&"type"in a)switch(a.type){case "int":b!=""&&(b=Number(b));break;case "span":b=$(this).html();break;case "debug":b=$(this).val()==""?null:Number($(this).val());break;case "checkbox":b=$(this).prop("checked");break;case "radioselect":a=$(this).find("label > input[type=radio]:checked").parent();if(a.length){b=[];b.push(a.children("input[type=radio]").val());a=a.children("select");a.length&&b.push(a.val())}else b="";break;case "checklist":b=
[];$(this).find(".checklist input[type=checkbox]:checked").each(function(){b.push($(this).attr("name"))});break;case "unix":b!=""&&(b=Math.round(new Date($(this).val())/1E3));break;case "selectinput":b=$(this).children("select").first().val();b=="CUSTOM"&&(b=$(this).children("label").first().find(".field_container").children().first().getval());break;case "inputlist":b=[];$(this).find(".field").each(function(){$(this).getval()!=""&&b.push($(this).getval())});break;case "sublist":b=$(this).data("savelist");
break;case "json":try{b=JSON.parse($(this).val())}catch(e){b=null}break;case "bitmask":b=0;$(this).find("input").each(function(){$(this).prop("checked")&&(b=b+Number($(this).val()))})}return b};
$.fn.setval=function(a){var b=$(this).data("opts");$(this).val(a);if(b&&"type"in b)switch(b.type){case "span":$(this).html(a).attr("title",a);break;case "checkbox":$(this).prop("checked",a);break;case "geolimited":case "hostlimited":b=$(this).closest(".field_container").data("subUI");if(typeof a=="undefined"||a.length==0)a="-";b.blackwhite.val(a.charAt(0));var a=a.substr(1).split(" "),e;for(e in a)b.values.append(b.prototype.clone(true).val(a[e]));b.blackwhite.trigger("change");break;case "radioselect":if(typeof a==
"undefined")return $(this);e=$(this).find('label > input[type=radio][value="'+a[0]+'"]').prop("checked",true).parent();a.length>1&&e.children("select").val(a[1]);break;case "checklist":b=$(this).find(".checklist input[type=checkbox]").prop("checked",false);for(e in a)b.filter('[name="'+a[e]+'"]').prop("checked",true);break;case "unix":if(typeof a!="undefined"&&a!=""&&a!==null){a=new Date(Math.round(a)*1E3);a.setMinutes(a.getMinutes()-a.getTimezoneOffset());a=a.toISOString();$(this).val(a.split("Z")[0])}break;
case "selectinput":a===null&&(a="");var c=false;for(e in b.selectinput){var d;typeof b.selectinput[e]=="string"?d=b.selectinput[e]:typeof b.selectinput[e][0]=="string"&&(d=b.selectinput[e][0]);if(d==a){$(this).children("select").first().val(a);c=true;break}}if(!c){$(this).children("label").first().find(".field_container").children().first().setval(a);$(this).children("select").first().val("CUSTOM").trigger("change")}break;case "inputlist":typeof a=="string"&&(a=[a]);for(e in a){b=$(this).data("newitem")();
b.find(".field").setval(a[e]);$(this).append(b)}$(this).append($(this).children().first());break;case "sublist":var j=$(this),b=$(this).children(".curvals");b.html("");if(a&&a.length)for(e in a){var c=$.extend(true,{},a[e]),i=function(a){for(var b in a)b.slice(0,6)=="x-LSP-"?delete a[b]:typeof a[b]=="object"&&i(a[b])};i(c);b.append($("<div>").addClass("subitem").append($("<span>").addClass("itemdetails").text(a[e]["x-LSP-name"]?a[e]["x-LSP-name"]:JSON.stringify(c)).attr("title",JSON.stringify(c,null,
2))).append($("<button>").addClass("move").text("^").attr("title","Move item up").click(function(){var a=$(this).parent().index();if(a!=0){var b=j.getval();b.splice(a-1,0,b.splice(a,1)[0]);j.setval(b)}})).append($("<button>").text("Edit").click(function(){var a=$(this).parent().index(),b=$(this).closest(".field");b.data("build")(Object.assign({},b.getval()[a]),a)})).append($("<button>").text("x").attr("title","Remove item").click(function(a){var b=$(this).parent().index(),c=j.data("savelist");c.splice(b,
1);j.setval(c);a.preventDefault()})))}else b.append("None.");j.data("savelist",a);break;case "json":$(this).val(a===null?"":JSON.stringify(a,null,2));break;case "bitmask":c=$(this).data("opts").bitmask;b=$(this).find("input");for(e in c){$el=b.eq(e);(a&c[e][0])==c[e][0]?$el.attr("checked","checked"):$el.removeAttr("checked")}}$(this).trigger("change");return $(this)};
function parseURL(a,b){var e;if("URL"in window&&typeof window.URL=="function")try{e=new URL(a)}catch(c){e=document.createElement("a");e.href=a}else{e=document.createElement("a");e.href=a}if(b)for(var d in b)e[d]=b[d];return{full:e.href,protocol:e.protocol+"//",host:e.hostname,port:e.port?":"+e.port:"",pathname:e.pathname?e.pathname:null,search:e.search?e.search.replace(/^\?/,""):null,searchParams:e.search?e.searchParams:null}}
break;case "json":try{b=JSON.parse($(this).val())}catch(d){b=null}break;case "bitmask":b=0;$(this).find("input").each(function(){$(this).prop("checked")&&(b=b+Number($(this).val()))})}return b};
$.fn.setval=function(a){var b=$(this).data("opts");$(this).val(a);if(b&&"type"in b)switch(b.type){case "span":$(this).html(a);break;case "checkbox":$(this).prop("checked",a);break;case "geolimited":case "hostlimited":b=$(this).closest(".field_container").data("subUI");if(typeof a=="undefined"||a.length==0)a="-";b.blackwhite.val(a.charAt(0));var a=a.substr(1).split(" "),d;for(d in a)b.values.append(b.prototype.clone(true).val(a[d]));b.blackwhite.trigger("change");break;case "radioselect":if(typeof a==
"undefined")return $(this);d=$(this).find('label > input[type=radio][value="'+a[0]+'"]').prop("checked",true).parent();a.length>1&&d.children("select").val(a[1]);break;case "checklist":b=$(this).find(".checklist input[type=checkbox]").prop("checked",false);for(d in a)b.filter('[name="'+a[d]+'"]').prop("checked",true);break;case "unix":if(typeof a!="undefined"&&a!=""&&a!==null){a=new Date(Math.round(a)*1E3);a.setMinutes(a.getMinutes()-a.getTimezoneOffset());a=a.toISOString();$(this).val(a.split("Z")[0])}break;
case "selectinput":a===null&&(a="");var c=false;for(d in b.selectinput){var e;typeof b.selectinput[d]=="string"?e=b.selectinput[d]:typeof b.selectinput[d][0]=="string"&&(e=b.selectinput[d][0]);if(e==a){$(this).children("select").first().val(a);c=true;break}}if(!c){$(this).children("label").first().find(".field_container").children().first().setval(a);$(this).children("select").first().val("CUSTOM").trigger("change")}break;case "inputlist":typeof a=="string"&&(a=[a]);for(d in a){b=$(this).data("newitem")();
b.find(".field").setval(a[d]);$(this).append(b)}$(this).append($(this).children().first());break;case "sublist":var l=$(this),b=$(this).children(".curvals");b.html("");if(a&&a.length)for(d in a){var c=$.extend(true,{},a[d]),i=function(a){for(var b in a)b.slice(0,6)=="x-LSP-"?delete a[b]:typeof a[b]=="object"&&i(a[b])};i(c);b.append($("<div>").addClass("subitem").append($("<span>").addClass("itemdetails").text(a[d]["x-LSP-name"]?a[d]["x-LSP-name"]:JSON.stringify(c)).attr("title",JSON.stringify(c,null,
2))).append($("<button>").addClass("move").text("^").attr("title","Move item up").click(function(){var a=$(this).parent().index();if(a!=0){var b=l.getval();b.splice(a-1,0,b.splice(a,1)[0]);l.setval(b)}})).append($("<button>").text("Edit").click(function(){var a=$(this).parent().index(),b=$(this).closest(".field");b.data("build")(Object.assign({},b.getval()[a]),a)})).append($("<button>").text("x").attr("title","Remove item").click(function(a){var b=$(this).parent().index(),c=l.data("savelist");c.splice(b,
1);l.setval(c);a.preventDefault()})))}else b.append("None.");l.data("savelist",a);break;case "json":$(this).val(a===null?"":JSON.stringify(a,null,2));break;case "bitmask":c=$(this).data("opts").bitmask;b=$(this).find("input");for(d in c){$el=b.eq(d);(a&c[d][0])==c[d][0]?$el.attr("checked","checked"):$el.removeAttr("checked")}}$(this).trigger("change");return $(this)};
function parseURL(a,b){var d;if("URL"in window&&typeof window.URL=="function")try{d=new URL(a)}catch(c){d=document.createElement("a");d.href=a}else{d=document.createElement("a");d.href=a}if(b)for(var e in b)d[e]=b[e];return{full:d.href,protocol:d.protocol+"//",host:d.hostname,port:d.port?":"+d.port:"",pathname:d.pathname?d.pathname:null,search:d.search?d.search.replace(/^\?/,""):null,searchParams:d.search?d.searchParams:null}}
function triggerRewrite(a){return typeof a=="object"&&typeof a.length=="undefined"?a:obj={handler:a[0],sync:a[1],streams:a[2],"default":a[3]}};

File diff suppressed because it is too large Load diff

View file

@ -16,14 +16,12 @@
</head>
<body>
<nav>
<div class="textures"></div>
<a href='#' class=logo>MistServer</a>
<div class=menu>
</div>
</nav>
<div class=filler>
<header>
<div class="textures"></div>
<h1>Management Interface</h1>
<aside id=status>
<span id='connection' class='red'>Disconnected</span>

View file

@ -100,9 +100,6 @@ message('Building release @0@ for version @1@ @ debug level @2@'.format(release,
mist_deps = []
ccpp = meson.get_compiler('cpp')
if ccpp.has_header_symbol('netinet/in.h', 'IPV6_RECVPKTINFO') and ccpp.has_header_symbol('netinet/in.h', 'IP_PKTINFO')
option_defines += '-DHASPKTINFO'
endif
if usessl
mbedtls = ccpp.find_library('mbedtls', required: false)

View file

@ -3,6 +3,113 @@
#include <mist/mp4_generic.h>
#include <mist/h264.h>
class mp4TrackHeader{
public:
mp4TrackHeader(){
initialised = false;
stscStart = 0;
sampleIndex = 0;
deltaIndex = 0;
deltaPos = 0;
deltaTotal = 0;
offsetIndex = 0;
offsetPos = 0;
sttsBox.clear();
hasCTTS = false;
cttsBox.clear();
stszBox.clear();
stcoBox.clear();
co64Box.clear();
stco64 = false;
trackId = 0;
}
void read(MP4::TRAK &trakBox){
initialised = false;
std::string tmp; // temporary string for copying box data
MP4::Box trakLoopPeek;
timeScale = 1;
MP4::MDIA mdiaBox = trakBox.getChild<MP4::MDIA>();
timeScale = mdiaBox.getChild<MP4::MDHD>().getTimeScale();
trackId = trakBox.getChild<MP4::TKHD>().getTrackID();
MP4::STBL stblBox = mdiaBox.getChild<MP4::MINF>().getChild<MP4::STBL>();
sttsBox.copyFrom(stblBox.getChild<MP4::STTS>());
cttsBox.copyFrom(stblBox.getChild<MP4::CTTS>());
stszBox.copyFrom(stblBox.getChild<MP4::STSZ>());
stcoBox.copyFrom(stblBox.getChild<MP4::STCO>());
co64Box.copyFrom(stblBox.getChild<MP4::CO64>());
stscBox.copyFrom(stblBox.getChild<MP4::STSC>());
stco64 = co64Box.isType("co64");
hasCTTS = cttsBox.isType("ctts");
}
size_t trackId;
MP4::STCO stcoBox;
MP4::CO64 co64Box;
MP4::STSZ stszBox;
MP4::STTS sttsBox;
bool hasCTTS;
MP4::CTTS cttsBox;
MP4::STSC stscBox;
uint64_t timeScale;
void getPart(uint64_t index, uint64_t &offset, uint64_t &size){
if (index < sampleIndex){
sampleIndex = 0;
stscStart = 0;
}
uint64_t stscCount = stscBox.getEntryCount();
MP4::STSCEntry stscEntry;
while (stscStart < stscCount){
stscEntry = stscBox.getSTSCEntry(stscStart);
// check where the next index starts
uint64_t nextSampleIndex;
if (stscStart + 1 < stscCount){
nextSampleIndex = sampleIndex + (stscBox.getSTSCEntry(stscStart + 1).firstChunk - stscEntry.firstChunk) *
stscEntry.samplesPerChunk;
}else{
nextSampleIndex = stszBox.getSampleCount();
}
if (nextSampleIndex > index){break;}
sampleIndex = nextSampleIndex;
++stscStart;
}
if (sampleIndex > index){
FAIL_MSG("Could not complete seek - not in file (%" PRIu64 " > %" PRIu64 ")", sampleIndex, index);
}
uint64_t stcoPlace = (stscEntry.firstChunk - 1) + ((index - sampleIndex) / stscEntry.samplesPerChunk);
uint64_t stszStart = sampleIndex + (stcoPlace - (stscEntry.firstChunk - 1)) * stscEntry.samplesPerChunk;
offset = (stco64 ? co64Box.getChunkOffset(stcoPlace) : stcoBox.getChunkOffset(stcoPlace));
for (int j = stszStart; j < index; j++){offset += stszBox.getEntrySize(j);}
size = stszBox.getEntrySize(index);
initialised = true;
}
uint64_t size(){return (stszBox.asBox() ? stszBox.getSampleCount() : 0);}
private:
bool initialised;
// next variables are needed for the stsc/stco loop
uint64_t stscStart;
uint64_t sampleIndex;
// next variables are needed for the stts loop
uint64_t deltaIndex; ///< Index in STTS box
uint64_t deltaPos; ///< Sample counter for STTS box
uint64_t deltaTotal; ///< Total timestamp for STTS box
// for CTTS box loop
uint64_t offsetIndex; ///< Index in CTTS box
uint64_t offsetPos; ///< Sample counter for CTTS box
bool stco64;
};
void AnalyserMP4::init(Util::Config &conf){
Analyser::init(conf);
}
@ -40,76 +147,22 @@ bool AnalyserMP4::parsePacket(){
if (mp4Data.read(mp4Buffer)){
INFO_MSG("Read a %" PRIu64 "b %s box at position %" PRIu64, mp4Data.boxedSize(), mp4Data.getType().c_str(), prePos);
// If we get an mdat, analyse it if we have known tracks, otherwise store it for later
if (mp4Data.getType() == "mdat"){
// Remember where we saw the mdat box
mdatPos = prePos;
if (hdrs.size()){
// We have tracks, analyse it directly
analyseData(mp4Data);
}else{
// No tracks yet, mdat is probably before the moov, we'll store a copy for later.
mdat.assign(mp4Data.asBox(), mp4Data.boxedSize());
}
analyseData(mp4Data);
return true;
}
// moof is parsed into the tracks we already have
if (mp4Data.getType() == "moof"){
moof.assign(mp4Data.asBox(), mp4Data.boxedSize());
moofPos = prePos;
// Indicate that we're reading the next moof box to all track headers
for (std::map<uint64_t, MP4::TrackHeader>::iterator t = hdrs.begin(); t != hdrs.end(); ++t){
t->second.nextMoof();
}
// Loop over traf boxes inside the moof box
std::deque<MP4::TRAF> trafs = ((MP4::MOOF*)&mp4Data)->getChildren<MP4::TRAF>();
for (std::deque<MP4::TRAF>::iterator t = trafs.begin(); t != trafs.end(); ++t){
if (!(t->getChild<MP4::TFHD>())){
WARN_MSG("Could not find thfd box inside traf box!");
continue;
}
uint32_t trackId = t->getChild<MP4::TFHD>().getTrackID();
if (!hdrs.count(trackId)){
WARN_MSG("Could not find matching trak box for traf box %" PRIu32 "!", trackId);
continue;
}
hdrs[trackId].read(*t);
}
}
// moov contains tracks; we parse it (wiping existing tracks, if any) and if we saw an mdat earlier, now analyse it.
if (mp4Data.getType() == "moov"){
// Remember where we saw this box
moov.assign(mp4Data.asBox(), mp4Data.boxedSize());
moovPos = prePos;
// Wipe existing headers, we got new ones.
hdrs.clear();
// Loop over trak boxes inside the moov box
std::deque<MP4::TRAK> traks = ((MP4::MOOV*)&mp4Data)->getChildren<MP4::TRAK>();
for (std::deque<MP4::TRAK>::iterator trakIt = traks.begin(); trakIt != traks.end(); trakIt++){
// Create a temporary header, since we don't know the trackId yet...
MP4::TrackHeader tHdr;
tHdr.read(*trakIt);
if (!tHdr.compatible()){
INFO_MSG("Unsupported: %s", tHdr.sType.c_str());
}else{
INFO_MSG("Detected %s", tHdr.codec.c_str());
}
// Regardless of support, we now put it in our track header array (after all, even unsupported tracks can be analysed!)
hdrs[tHdr.trackId].read(*trakIt);
}
std::deque<MP4::TREX> trex = ((MP4::MOOV*)&mp4Data)->getChild<MP4::MVEX>().getChildren<MP4::TREX>();
for (std::deque<MP4::TREX>::iterator trexIt = trex.begin(); trexIt != trex.end(); trexIt++){
hdrs[trexIt->getTrackID()].read(*trexIt);
}
// If we stored an mdat earlier, we can now analyse and then wipe it
if (mdat.size()){
MP4::Box mdatBox(mdat, false);
analyseData(mdatBox);
mdat.truncate(0);
}
}
// No matter what box we saw, (try to) pretty-print it
if (detail >= 2){std::cout << mp4Data.toPrettyString(0) << std::endl;}
if (detail >= 2){
std::cout << mp4Data.toPrettyString(0) << std::endl;
}
return true;
}
FAIL_MSG("Could not read box at position %" PRIu64, prePos);
@ -149,58 +202,66 @@ h264::nalUnit * getNalUnit(const char * data, size_t pktLen){
}
void AnalyserMP4::analyseData(MP4::Box & mdatBox){
// Abort if we have no headers
if (!hdrs.size()){return;}
// Loop over known headers
for (std::map<uint64_t, MP4::TrackHeader>::iterator t = hdrs.begin(); t != hdrs.end(); ++t){
size_t noPkts = t->second.size();
for (size_t i = 0; i < noPkts; ++i){
uint64_t offset = 0, time = 0;
int32_t timeOffset = 0;
uint32_t size = 0;
bool keyFrame = false;
t->second.getPart(i, &offset, &size, &time, &timeOffset, &keyFrame, moofPos);
// Update mediaTime with last parsed packet, if time increased
if (time > mediaTime){mediaTime = time;}
std::cout << "Packet " << i << " for track " << t->first << " (" << t->second.codec << ")";
if (keyFrame){std::cout << " (KEY)";}
std::cout << ": " << size << "b @" << offset << ", T " << time;
if (timeOffset){
if (timeOffset > 0){
std::cout << "+" << timeOffset;
}else{
std::cout << timeOffset;
}
}
std::cout << std::endl;
if (offset < mdatPos){
std::cout << "Data is before mdat!" << std::endl;
continue;
}
if (offset - mdatPos + size > mdatBox.boxedSize()){
std::cout << "Data is after mdat!" << std::endl;
continue;
}
if (detail < 4){continue;}
const char * ptr = mdatBox.asBox() - mdatPos + offset;
if (t->second.codec == "H264"){
size_t j = 0;
while (j+4 <= size){
uint32_t len = Bit::btohl(ptr+j);
std::cout << len << " bytes: ";
printByteRange(ptr, j, 4);
if (j+4+len > size){len = size-j-4;}
if (moov.size()){
MP4::Box globHdr(moov, false);
std::deque<MP4::TRAK> traks = ((MP4::MOOV*)&globHdr)->getChildren<MP4::TRAK>();
h264::nalUnit * nalu = getNalUnit(ptr+j+4, len);
nalu->toPrettyString(std::cout);
delete nalu;
if (detail > 5){printByteRange(ptr, j+4, j+4+len);}
j += 4 + len;
size_t trkCounter = 0;
for (std::deque<MP4::TRAK>::iterator trakIt = traks.begin(); trakIt != traks.end(); trakIt++){
trkCounter++;
MP4::MDIA mdiaBox = trakIt->getChild<MP4::MDIA>();
std::string hdlrType = mdiaBox.getChild<MP4::HDLR>().getHandlerType();
if (hdlrType != "vide" && hdlrType != "soun" && hdlrType != "sbtl"){
INFO_MSG("Unsupported handler: %s", hdlrType.c_str());
continue;
}
std::string sType = mdiaBox.getChild<MP4::MINF>().getChild<MP4::STBL>().getChild<MP4::STSD>().getEntry(0).getType();
if (sType == "avc1" || sType == "h264" || sType == "mp4v"){sType = "H264";}
if (sType == "hev1" || sType == "hvc1"){sType = "HEVC";}
if (sType == "ac-3"){sType = "AC3";}
if (sType == "tx3g"){sType = "subtitle";}
INFO_MSG("Detected %s", sType.c_str());
mp4TrackHeader tHdr;
tHdr.read(*trakIt);
size_t noPkts = tHdr.size();
for (size_t i = 0; i < noPkts; ++i){
uint64_t offset = 0, size = 0;
tHdr.getPart(i, offset, size);
std::cout << "Packet " << i << " for track " << trkCounter << " (" << sType << "): " << size << " bytes" << std::endl;
if (offset < mdatPos){
std::cout << "Data is before mdat!" << std::endl;
continue;
}
}else{
if (detail > 5){printByteRange(ptr, 0, size);}
if (offset - mdatPos + size > mdatBox.boxedSize()){
std::cout << "Data is after mdat!" << std::endl;
continue;
}
const char * ptr = mdatBox.asBox() - mdatPos + offset;
if (sType == "H264"){
size_t j = 0;
while (j+4 <= size){
uint32_t len = Bit::btohl(ptr+j);
std::cout << len << " bytes: ";
printByteRange(ptr, j, 4);
if (j+4+len > size){len = size-j-4;}
h264::nalUnit * nalu = getNalUnit(ptr+j+4, len);
nalu->toPrettyString(std::cout);
delete nalu;
printByteRange(ptr, j+4, j+4+len);
j += 4 + len;
}
}else{
printByteRange(ptr, 0, size);
}
}
}
}
if (moof.size()){
}
///\TODO update mediaTime with the current timestamp
}

View file

@ -1,6 +1,5 @@
#include "analyser.h"
#include <mist/mp4.h>
#include <mist/mp4_stream.h>
class AnalyserMP4 : public Analyser{
public:
@ -11,7 +10,6 @@ public:
private:
Util::ResizeablePointer moof;
Util::ResizeablePointer moov;
Util::ResizeablePointer mdat;
uint64_t moovPos;
uint64_t moofPos;
uint64_t mdatPos;
@ -21,5 +19,4 @@ private:
MP4::Box mp4Data;
uint64_t curPos;
uint64_t prePos;
std::map<uint64_t, MP4::TrackHeader> hdrs;
};

View file

@ -350,7 +350,6 @@ void Controller::handleWebSocket(HTTP::Parser &H, Socket::Connection &C, bool au
lastStrmStat.erase(strm);
}
}
W.readFrame();
if (!sent){Util::sleep(500);}
}
}
@ -1140,7 +1139,7 @@ void Controller::handleAPICommands(JSON::Value &Request, JSON::Value &Response){
if (Request.isMember("api_endpoint")){
HTTP::URL url("http://localhost:4242");
url.host = Util::listenInterface;
if (url.host == "::"){url.host = "[::1]";}
if (url.host == "::"){url.host = "::1";}
if (url.host == "0.0.0.0"){url.host = "127.0.0.1";}
url.port = JSON::Value(Util::listenPort).asString();
Response["api_endpoint"] = url.getUrl();

View file

@ -174,23 +174,13 @@ void Controller::updateBandwidthConfig(){
/// This function is ran whenever a stream becomes active.
void Controller::streamStarted(std::string stream){
INFO_MSG("Stream %s became active", stream.c_str());
{
streamTotals & sT = streamStats[stream];
JSON::Value strCnf = Util::getStreamConfig(stream);
if (strCnf.isMember("tags")){
jsonForEachConst(strCnf["tags"], it){
sT.tags.insert(it->asString());
}
INFO_MSG("Applied %" PRIu32 " tags to stream %s from config",strCnf["tags"].size() , stream.c_str());
}
if (tagQueue.count(stream)){
tagQueueItem & q = tagQueue[stream];
for (std::set<std::string>::iterator it = q.tags.begin(); it != q.tags.end(); ++it){
sT.tags.insert(*it);
}
INFO_MSG("Applied %zu tags to stream %s retroactively",q.tags.size() , stream.c_str());
tagQueue.erase(stream);
if (tagQueue.count(stream)){
tagQueueItem & q = tagQueue[stream];
for (std::set<std::string>::iterator it = q.tags.begin(); it != q.tags.end(); ++it){
streamStats[stream].tags.insert(*it);
}
INFO_MSG("Applied %zu tags to stream %s retroactively",q.tags.size() , stream.c_str());
tagQueue.erase(stream);
}
Controller::doAutoPush(stream);
}
@ -435,7 +425,7 @@ void Controller::SharedMemStats(void *config){
for (uint64_t cPos = startPos; cPos < endPos; ++cPos){
std::string strm = strmStats->getPointer("stream", cPos);
std::string tags = strmStats->getPointer("tags", cPos);
if (strm.size() && tags.size() && streamStats.count(strm)){
if (tags.size() && streamStats.count(strm)){
INFO_MSG("Restoring stream tags: %s -> %s", strm.c_str(), tags.c_str());
streamTotals & st = streamStats[strm];
while (tags.size()){
@ -478,8 +468,7 @@ void Controller::SharedMemStats(void *config){
cutOffPoint = 0;
}
for (std::map<std::string, statSession>::iterator it = sessions.begin(); it != sessions.end(); it++){
std::string strm = it->second.getStreamName();
if (strm.size()){streamStats[strm].currSessions++;}
streamStats[it->second.getStreamName()].currSessions++;
// This part handles ending sessions, keeping them in cache for now
if (it->second.getEnd() < cutOffPoint){
viewSecondsTotal += it->second.getConnTime();
@ -487,32 +476,30 @@ void Controller::SharedMemStats(void *config){
// Don't count this session as a viewer
continue;
}
if (strm.size()){
// Recount input, output and viewer type sessions
switch (it->second.getSessType()){
case SESS_UNSET: break;
case SESS_VIEWER:
if (it->second.hasDataFor(tOut)){
streamStats[it->second.getStreamName()].currViews++;
}
servSeconds += it->second.getConnTime();
break;
case SESS_INPUT:
if (it->second.hasDataFor(tIn)){
streamStats[it->second.getStreamName()].currIns++;
}
break;
case SESS_OUTPUT:
if (it->second.hasDataFor(tOut)){
streamStats[it->second.getStreamName()].currOuts++;
}
break;
case SESS_UNSPECIFIED:
if (it->second.hasDataFor(tOut)){
streamStats[it->second.getStreamName()].currUnspecified++;
}
break;
// Recount input, output and viewer type sessions
switch (it->second.getSessType()){
case SESS_UNSET: break;
case SESS_VIEWER:
if (it->second.hasDataFor(tOut)){
streamStats[it->second.getStreamName()].currViews++;
}
servSeconds += it->second.getConnTime();
break;
case SESS_INPUT:
if (it->second.hasDataFor(tIn)){
streamStats[it->second.getStreamName()].currIns++;
}
break;
case SESS_OUTPUT:
if (it->second.hasDataFor(tOut)){
streamStats[it->second.getStreamName()].currOuts++;
}
break;
case SESS_UNSPECIFIED:
if (it->second.hasDataFor(tOut)){
streamStats[it->second.getStreamName()].currUnspecified++;
}
break;
}
}
while (mustWipe.size()){
@ -766,15 +753,14 @@ void Controller::statSession::update(uint64_t index, Comms::Sessions &statComm){
}
}
// Only count connections that are countable
if (noBWCount != 2 && streamName.size()){
if (noBWCount != 2){
createEmptyStatsIfNeeded(streamName);
streamTotals & sT = streamStats[streamName];
sT.upBytes += currUp - prevUp;
sT.downBytes += currDown - prevDown;
sT.packSent += currPktSent - prevPktSent;
sT.packLoss += currPktLost - prevPktLost;
sT.packRetrans += currPktRetrans - prevPktRetrans;
if (sessionType == SESS_VIEWER){sT.viewSeconds += secIncr;}
streamStats[streamName].upBytes += currUp - prevUp;
streamStats[streamName].downBytes += currDown - prevDown;
streamStats[streamName].packSent += currPktSent - prevPktSent;
streamStats[streamName].packLoss += currPktLost - prevPktLost;
streamStats[streamName].packRetrans += currPktRetrans - prevPktRetrans;
if (sessionType == SESS_VIEWER){streamStats[streamName].viewSeconds += secIncr;}
}
}

View file

@ -894,6 +894,13 @@ namespace Mist{
break;
}
if (M.getLive() && !internalOnly){
uint64_t currLastUpdate = M.getLastUpdated();
if (currLastUpdate > activityCounter){activityCounter = currLastUpdate;}
}else{
if ((connectedUsers || isAlwaysOn()) && M.getValidTracks().size()){activityCounter = Util::bootSecs();}
}
inputServeStats();
// if not shutting down, wait 1 second before looping
preMs = Util::bootMS() - preMs;
@ -937,14 +944,7 @@ namespace Mist{
/// For live streams, this is twice the biggest fragment duration.
/// For non-live streams this is INPUT_TIMEOUT seconds.
/// The default Pro implementation also allows cancelling the shutdown through the STREAM_UNLOAD trigger.
bool Input::keepRunning(bool updateActCtr){
// Default behaviour to stop an input when there's not activity after X seconds
// This is overriden by certain inputs (buffer, HLS, more) where there is different logic
// for updating 'activityCounter'
if (updateActCtr){
if ((connectedUsers || isAlwaysOn()) && M.getValidTracks().size()){activityCounter = Util::bootSecs();}
}
bool Input::keepRunning(){
// We keep running in serve mode if the config is still active AND either
// - INPUT_TIMEOUT seconds haven't passed yet,
// - this is a live stream and at least two of the biggest fragment haven't passed yet,

View file

@ -74,7 +74,7 @@ namespace Mist{
virtual void getNext(size_t idx = INVALID_TRACK_ID){}
virtual void seek(uint64_t seekTime, size_t idx = INVALID_TRACK_ID){}
virtual void finish();
virtual bool keepRunning(bool updateActCtr = true);
virtual bool keepRunning();
virtual bool openStreamSource(){return readHeader();}
virtual void closeStreamSource(){}
virtual void parseStreamHeader(){}

View file

@ -111,7 +111,7 @@ namespace Mist{
// Overrides the default keepRunning function to shut down
// if the file disappears or changes, by polling the file's mtime.
// If neither applies, calls the original function.
bool InputAAC::keepRunning(bool updateActCtr){
bool InputAAC::keepRunning(){
struct stat statData;
if (stat(config->getString("input").c_str(), &statData) == -1){
INFO_MSG("Shutting down because input file disappeared");
@ -121,7 +121,7 @@ namespace Mist{
INFO_MSG("Shutting down because input file changed");
return false;
}
return Input::keepRunning(updateActCtr);
return Input::keepRunning();
}

View file

@ -16,7 +16,7 @@ namespace Mist{
bool readHeader();
void seek(uint64_t seekTime, size_t idx);
void getNext(size_t idx = INVALID_TRACK_ID);
bool keepRunning(bool updateActCtr = true);
bool keepRunning();
uint64_t lastModTime;
HTTP::URIReader inFile;
size_t audioTrack;

View file

@ -258,14 +258,6 @@ namespace Mist{
meta.setLive(true);
}
bool InputBuffer::keepRunning(bool updateActCtr){
if (M.getLive()){
uint64_t currLastUpdate = M.getLastUpdated();
if (currLastUpdate > activityCounter){activityCounter = currLastUpdate;}
}
return Input::keepRunning(false);
}
/// Checks if removing a key from this track is allowed/safe, and if so, removes it.
/// Returns true if a key was actually removed, false otherwise
/// Aborts if any of the following conditions are true (while active):

View file

@ -34,7 +34,6 @@ namespace Mist{
bool needHeader(){return false;}
void getNext(size_t idx = INVALID_TRACK_ID){};
void seek(uint64_t seekTime, size_t idx = INVALID_TRACK_ID){};
bool keepRunning(bool updateActCtr = true);
void removeTrack(size_t tid);

View file

@ -67,7 +67,7 @@ namespace Mist{
/// Overrides the default keepRunning function to shut down
/// if the file disappears or changes, by polling the file's mtime.
/// If neither applies, calls the original function.
bool InputFLV::keepRunning(bool updateActCtr){
bool InputFLV::keepRunning(){
struct stat statData;
if (stat(config->getString("input").c_str(), &statData) == -1){
INFO_MSG("Shutting down because input file disappeared");
@ -77,7 +77,7 @@ namespace Mist{
INFO_MSG("Shutting down because input file changed");
return false;
}
return Input::keepRunning(updateActCtr);
return Input::keepRunning();
}
bool InputFLV::readHeader(){

View file

@ -15,7 +15,7 @@ namespace Mist{
bool readHeader();
void getNext(size_t idx = INVALID_TRACK_ID);
void seek(uint64_t seekTime, size_t idx = INVALID_TRACK_ID);
bool keepRunning(bool updateActCtr = true);
bool keepRunning();
FLV::Tag tmpTag;
uint64_t lastModTime;
FILE *inFile;

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,12 @@
#include "input.h"
#include <mist/dtsc.h>
#include <mist/nal.h>
#include <mist/segmentreader.h>
#include <mist/ts_packet.h>
#include <mist/ts_stream.h>
#include <string>
//#include <stdint.h>
#include <mist/http_parser.h>
#include <mist/urireader.h>
#define BUFFERTIME 10
@ -16,9 +21,6 @@ namespace Mist{
struct playListEntries{
std::string filename;
std::string relative_filename;
std::string mapName;
uint64_t startAtByte; ///< Byte position inside filename where to start reading
uint64_t stopAtByte; ///< Byte position inside filename where to stop sending
uint64_t bytePos;
uint64_t mUTC; ///< UTC unix millis timestamp of first packet, if known
float duration; ///< Duration of entry in seconds
@ -34,43 +36,51 @@ namespace Mist{
timestamp = 0;
timeOffset = 0;
wait = 0;
startAtByte = 0;
stopAtByte = 0;
for (size_t i = 0; i < 16; ++i){
ivec[i] = 0;
keyAES[i] = 0;
}
}
std::string shortName() const{
if (!startAtByte && !stopAtByte){return filename;}
std::string ret = filename;
ret += " (";
ret += JSON::Value(startAtByte).asString();
ret += "-";
ret += JSON::Value(stopAtByte).asString();
ret += ")";
return ret;
}
};
inline bool operator< (const playListEntries a, const playListEntries b){
return a.filename < b.filename || (a.filename == b.filename && a.startAtByte < b.startAtByte);
}
inline bool operator== (const playListEntries a, const playListEntries b){
return a.filename == b.filename && a.startAtByte == b.startAtByte;
}
/// Keeps the segment entry list by playlist ID
extern std::map<uint32_t, std::deque<playListEntries> > listEntries;
class SegmentDownloader: public Util::DataCallback{
public:
SegmentDownloader();
HTTP::URIReader segDL;
char *packetPtr;
bool loadSegment(const playListEntries &entry);
bool readNext();
virtual void dataCallback(const char *ptr, size_t size);
virtual size_t getDataCallbackPos() const;
void close();
bool atEnd() const;
private:
bool encrypted;
bool buffered;
size_t offset;
bool firstPacket;
Util::ResizeablePointer outData;
Util::ResizeablePointer * currBuf;
size_t encOffset;
unsigned char tmpIvec[16];
#ifdef SSL
mbedtls_aes_context aes;
#endif
bool isOpen;
};
class Playlist{
public:
Playlist(const std::string &uriSrc = "");
bool isUrl() const;
bool reload();
void addEntry(const std::string & absolute_filename, const std::string &filename, float duration, uint64_t &bpos,
const std::string &key, const std::string &keyIV, const std::string mapName, uint64_t startByte, uint64_t lenByte);
const std::string &key, const std::string &keyIV);
bool isSupportedFile(const std::string filename);
std::string uri; // link to the current playlistfile
HTTP::URL root;
@ -89,7 +99,6 @@ namespace Mist{
uint64_t nextUTC; ///< If non-zero, the UTC timestamp of the next segment on this playlist
char keyAES[16];
std::map<std::string, std::string> keys;
std::map<std::string, std::string> maps;
uint64_t firstIndex; //< the index of the first segment in the playlist
uint64_t lastSegment;
std::map<size_t, bool> tracks;
@ -100,16 +109,17 @@ namespace Mist{
class InputHLS : public Input{
public:
InputHLS(Util::Config *cfg);
~InputHLS(){}
~InputHLS();
bool needsLock(){return !config->getBool("realtime");}
bool openStreamSource();
bool callback();
protected:
uint64_t zUTC; ///< Zero point in local millis, as UTC unix time millis
uint64_t nUTC; ///< Next packet timestamp in UTC unix time millis
int64_t streamOffset; ///< bootMsOffset we need to set once we have parsed the header
unsigned int startTime;
SegmentReader segDowner;
SegmentDownloader segDowner;
int version;
int targetDuration;
bool endPlaylist;
@ -119,12 +129,18 @@ namespace Mist{
std::map<uint64_t, uint64_t> pidMapping;
std::map<uint64_t, uint64_t> pidMappingR;
std::map<int, int64_t> plsTimeOffset;
std::map<int, int64_t> DVRTimeOffsets;
std::map<int, uint64_t> plsLastTime;
std::map<int, uint64_t> plsInterval;
size_t currentIndex;
std::string currentFile;
TS::Stream tsStream; ///< Used for parsing the incoming ts stream
Socket::Connection conn;
TS::Packet tsBuf;
// Used to map packetId of packets in pidMapping
int pidCounter;
@ -144,10 +160,10 @@ namespace Mist{
bool preSetup();
bool readHeader();
bool readExistingHeader();
void postHeader();
void getNext(size_t idx = INVALID_TRACK_ID);
void seek(uint64_t seekTime, size_t idx = INVALID_TRACK_ID);
bool keepRunning(bool updateActCtr = true);
FILE *inFile;
FILE *tsFile;
bool readIndex();
bool initPlaylist(const std::string &uri, bool fullInit = true);
@ -156,6 +172,7 @@ namespace Mist{
void parseStreamHeader();
void parseLivePoint();
void streamMainLoop();
uint32_t getMappedTrackId(uint64_t id);
uint32_t getMappedTrackPlaylist(uint64_t id);

View file

@ -1,7 +1,10 @@
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <inttypes.h>
#include <iostream>
#include <mist/bitfields.h>
#include <mist/defines.h>
#include <mist/flv_tag.h>
@ -13,9 +16,84 @@
namespace Mist{
MP4::TrackHeader &InputMP4::headerData(size_t trackID){
static MP4::TrackHeader none;
for (std::deque<MP4::TrackHeader>::iterator it = trackHeaders.begin(); it != trackHeaders.end(); it++){
mp4TrackHeader::mp4TrackHeader(){
initialised = false;
stscStart = 0;
sampleIndex = 0;
deltaIndex = 0;
deltaPos = 0;
deltaTotal = 0;
offsetIndex = 0;
offsetPos = 0;
stscBox.clear();
stszBox.clear();
stcoBox.clear();
co64Box.clear();
stco64 = false;
trackId = 0;
}
uint64_t mp4TrackHeader::size(){return (stszBox.asBox() ? stszBox.getSampleCount() : 0);}
void mp4TrackHeader::read(MP4::TRAK &trakBox){
initialised = false;
std::string tmp; // temporary string for copying box data
MP4::Box trakLoopPeek;
timeScale = 1;
MP4::MDIA mdiaBox = trakBox.getChild<MP4::MDIA>();
timeScale = mdiaBox.getChild<MP4::MDHD>().getTimeScale();
trackId = trakBox.getChild<MP4::TKHD>().getTrackID();
MP4::STBL stblBox = mdiaBox.getChild<MP4::MINF>().getChild<MP4::STBL>();
stszBox.copyFrom(stblBox.getChild<MP4::STSZ>());
stcoBox.copyFrom(stblBox.getChild<MP4::STCO>());
co64Box.copyFrom(stblBox.getChild<MP4::CO64>());
stscBox.copyFrom(stblBox.getChild<MP4::STSC>());
stco64 = co64Box.isType("co64");
}
void mp4TrackHeader::getPart(uint64_t index, uint64_t &offset){
if (index < sampleIndex){
sampleIndex = 0;
stscStart = 0;
}
uint64_t stscCount = stscBox.getEntryCount();
MP4::STSCEntry stscEntry;
while (stscStart < stscCount){
stscEntry = stscBox.getSTSCEntry(stscStart);
// check where the next index starts
uint64_t nextSampleIndex;
if (stscStart + 1 < stscCount){
nextSampleIndex = sampleIndex + (stscBox.getSTSCEntry(stscStart + 1).firstChunk - stscEntry.firstChunk) *
stscEntry.samplesPerChunk;
}else{
nextSampleIndex = stszBox.getSampleCount();
}
if (nextSampleIndex > index){break;}
sampleIndex = nextSampleIndex;
++stscStart;
}
if (sampleIndex > index){
FAIL_MSG("Could not complete seek - not in file (%" PRIu64 " > %" PRIu64 ")", sampleIndex, index);
}
uint64_t stcoPlace = (stscEntry.firstChunk - 1) + ((index - sampleIndex) / stscEntry.samplesPerChunk);
uint64_t stszStart = sampleIndex + (stcoPlace - (stscEntry.firstChunk - 1)) * stscEntry.samplesPerChunk;
offset = (stco64 ? co64Box.getChunkOffset(stcoPlace) : stcoBox.getChunkOffset(stcoPlace));
for (int j = stszStart; j < index; j++){offset += stszBox.getEntrySize(j);}
initialised = true;
}
mp4TrackHeader &InputMP4::headerData(size_t trackID){
static mp4TrackHeader none;
for (std::deque<mp4TrackHeader>::iterator it = trackHeaders.begin(); it != trackHeaders.end(); it++){
if (it->trackId == trackID){return *it;}
}
return none;
@ -45,7 +123,6 @@ namespace Mist{
capa["codecs"]["audio"].append("AC3");
capa["codecs"]["audio"].append("MP3");
readPos = 0;
nextBox = 0;
}
bool InputMP4::checkArguments(){
@ -116,7 +193,6 @@ namespace Mist{
std::string boxType = std::string(readBuffer+4, 4);
uint64_t boxSize = MP4::calcBoxSize(readBuffer);
if (boxType == "moov"){
moovPos = readPos;
while (readBuffer.size() < boxSize && inFile && keepRunning()){inFile.readSome(boxSize-readBuffer.size(), *this);}
if (readBuffer.size() < boxSize){
Util::logExitReason(ER_FORMAT_SPECIFIC, "Could not read entire MOOV box into memory");
@ -127,16 +203,11 @@ namespace Mist{
// for all box in moov
std::deque<MP4::TRAK> trak = ((MP4::MOOV*)&moovBox)->getChildren<MP4::TRAK>();
for (std::deque<MP4::TRAK>::iterator trakIt = trak.begin(); trakIt != trak.end(); trakIt++){
trackHeaders.push_back(MP4::TrackHeader());
trackHeaders.push_back(mp4TrackHeader());
trackHeaders.rbegin()->read(*trakIt);
}
std::deque<MP4::TREX> trex = ((MP4::MOOV*)&moovBox)->getChild<MP4::MVEX>().getChildren<MP4::TREX>();
for (std::deque<MP4::TREX>::iterator trexIt = trex.begin(); trexIt != trex.end(); trexIt++){
for (std::deque<MP4::TrackHeader>::iterator it = trackHeaders.begin(); it != trackHeaders.end(); it++){
if (it->trackId == trexIt->getTrackID()){it->read(*trexIt);}
}
}
hasMoov = true;
break;
}
activityCounter = Util::bootSecs();
//Skip to next box
@ -150,8 +221,6 @@ namespace Mist{
}
readPos = inFile.getPos();
}
// Stop if we've found a MOOV box - we'll do the rest afterwards
if (hasMoov){break;}
}
if (!hasMoov){
@ -174,199 +243,369 @@ namespace Mist{
meta.reInit(isSingular() ? streamName : "");
tNumber = 0;
bps = 0;
// Create header file from MP4 data
MP4::Box moovBox(readBuffer, false);
bool sawParts = false;
bool parsedInitial = false;
for (std::deque<MP4::TrackHeader>::iterator it = trackHeaders.begin(); it != trackHeaders.end(); it++){
if (!it->compatible()){
INFO_MSG("Unsupported track: %s", it->trackType.c_str());
std::deque<MP4::TRAK> trak = ((MP4::MOOV*)&moovBox)->getChildren<MP4::TRAK>();
HIGH_MSG("Obtained %zu trak Boxes", trak.size());
uint64_t globalTimeOffset = 0;
for (std::deque<MP4::TRAK>::iterator trakIt = trak.begin(); trakIt != trak.end(); trakIt++){
MP4::MDIA mdiaBox = trakIt->getChild<MP4::MDIA>();
std::string hdlrType = mdiaBox.getChild<MP4::HDLR>().getHandlerType();
if (hdlrType != "vide" && hdlrType != "soun" && hdlrType != "sbtl"){
INFO_MSG("Unsupported handler: %s", hdlrType.c_str());
continue;
}
MP4::STBL stblBox = mdiaBox.getChild<MP4::MINF>().getChild<MP4::STBL>();
MP4::STSD stsdBox = stblBox.getChild<MP4::STSD>();
MP4::Box sEntryBox = stsdBox.getEntry(0);
std::string sType = sEntryBox.getType();
if (!(sType == "avc1" || sType == "h264" || sType == "mp4v" || sType == "hev1" || sType == "hvc1" || sType == "mp4a" || sType == "aac " || sType == "ac-3" || sType == "tx3g")){
INFO_MSG("Unsupported track type: %s", sType.c_str());
continue;
}
MP4::CTTS cttsBox = stblBox.getChild<MP4::CTTS>(); // optional ctts box
MP4::MDHD mdhdBox = mdiaBox.getChild<MP4::MDHD>();
uint64_t timescale = mdhdBox.getTimeScale();
int64_t DTS_CTS_offset = 0; ///< Difference between composition time and decode time. Always positive.
if (cttsBox.isType("ctts")){
uint32_t cttsCount = cttsBox.getEntryCount();
for (uint32_t i = 0; i < cttsCount; ++i){
MP4::CTTSEntry e = cttsBox.getCTTSEntry(i);
int64_t o = (-e.sampleOffset * 1000) / (int64_t)timescale;
if (o > DTS_CTS_offset){DTS_CTS_offset = o;}
}
if (DTS_CTS_offset > globalTimeOffset){globalTimeOffset = DTS_CTS_offset;}
}
}
for (std::deque<MP4::TRAK>::iterator trakIt = trak.begin(); trakIt != trak.end(); trakIt++){
MP4::MDIA mdiaBox = trakIt->getChild<MP4::MDIA>();
std::string hdlrType = mdiaBox.getChild<MP4::HDLR>().getHandlerType();
if (hdlrType != "vide" && hdlrType != "soun" && hdlrType != "sbtl"){
INFO_MSG("Unsupported handler: %s", hdlrType.c_str());
continue;
}
MP4::STBL stblBox = mdiaBox.getChild<MP4::MINF>().getChild<MP4::STBL>();
MP4::STSD stsdBox = stblBox.getChild<MP4::STSD>();
MP4::Box sEntryBox = stsdBox.getEntry(0);
std::string sType = sEntryBox.getType();
if (!(sType == "avc1" || sType == "h264" || sType == "mp4v" || sType == "hev1" || sType == "hvc1" || sType == "mp4a" || sType == "aac " || sType == "ac-3" || sType == "tx3g" || sType == "av01")){
INFO_MSG("Unsupported track type: %s", sType.c_str());
continue;
}
tNumber = meta.addTrack();
HIGH_MSG("Found track %zu of type %s -> %s", tNumber, it->sType.c_str(), it->codec.c_str());
meta.setID(tNumber, it->trackId);
meta.setCodec(tNumber, it->codec);
meta.setInit(tNumber, it->initData);
meta.setLang(tNumber, it->lang);
if (it->trackType == "video"){
MP4::TKHD tkhdBox = trakIt->getChild<MP4::TKHD>();
if (tkhdBox.getWidth() > 0){
meta.setWidth(tNumber, tkhdBox.getWidth());
meta.setHeight(tNumber, tkhdBox.getHeight());
}
meta.setID(tNumber, tkhdBox.getTrackID());
MP4::MDHD mdhdBox = mdiaBox.getChild<MP4::MDHD>();
uint64_t timescale = mdhdBox.getTimeScale();
meta.setLang(tNumber, mdhdBox.getLanguage());
HIGH_MSG("Found track %zu of type %s", tNumber, sType.c_str());
if (sType == "avc1" || sType == "h264" || sType == "mp4v"){
MP4::VisualSampleEntry &vEntryBox = (MP4::VisualSampleEntry &)sEntryBox;
meta.setType(tNumber, "video");
meta.setWidth(tNumber, it->vidWidth);
meta.setHeight(tNumber, it->vidHeight);
meta.setCodec(tNumber, "H264");
if (!meta.getWidth(tNumber)){
meta.setWidth(tNumber, vEntryBox.getWidth());
meta.setHeight(tNumber, vEntryBox.getHeight());
}
MP4::Box initBox = vEntryBox.getCLAP();
if (initBox.isType("avcC")){
meta.setInit(tNumber, initBox.payload(), initBox.payloadSize());
}
initBox = vEntryBox.getPASP();
if (initBox.isType("avcC")){
meta.setInit(tNumber, initBox.payload(), initBox.payloadSize());
}
/// this is a hacky way around invalid FLV data (since it gets ignored nearly
/// everywhere, but we do need correct data...
if (!meta.getWidth(tNumber)){
h264::sequenceParameterSet sps;
sps.fromDTSCInit(meta.getInit(tNumber));
h264::SPSMeta spsChar = sps.getCharacteristics();
meta.setWidth(tNumber, spsChar.width);
meta.setHeight(tNumber, spsChar.height);
}
}
if (it->trackType == "audio"){
if (sType == "hev1" || sType == "hvc1"){
MP4::VisualSampleEntry &vEntryBox = (MP4::VisualSampleEntry &)sEntryBox;
meta.setType(tNumber, "video");
meta.setCodec(tNumber, "HEVC");
if (!meta.getWidth(tNumber)){
meta.setWidth(tNumber, vEntryBox.getWidth());
meta.setHeight(tNumber, vEntryBox.getHeight());
}
MP4::Box initBox = vEntryBox.getCLAP();
if (initBox.isType("hvcC")){
meta.setInit(tNumber, initBox.payload(), initBox.payloadSize());
}
initBox = vEntryBox.getPASP();
if (initBox.isType("hvcC")){
meta.setInit(tNumber, initBox.payload(), initBox.payloadSize());
}
}
if (sType == "av01"){
MP4::VisualSampleEntry &vEntryBox = (MP4::VisualSampleEntry &)sEntryBox;
meta.setType(tNumber, "video");
meta.setCodec(tNumber, "AV1");
if (!meta.getWidth(tNumber)){
meta.setWidth(tNumber, vEntryBox.getWidth());
meta.setHeight(tNumber, vEntryBox.getHeight());
}
MP4::Box initBox = vEntryBox.getCLAP();
if (initBox.isType("av1C")){
meta.setInit(tNumber, initBox.payload(), initBox.payloadSize());
}
initBox = vEntryBox.getPASP();
if (initBox.isType("av1C")){
meta.setInit(tNumber, initBox.payload(), initBox.payloadSize());
}
}
if (sType == "mp4a" || sType == "aac " || sType == "ac-3"){
MP4::AudioSampleEntry &aEntryBox = (MP4::AudioSampleEntry &)sEntryBox;
meta.setType(tNumber, "audio");
meta.setChannels(tNumber, it->audChannels);
meta.setRate(tNumber, it->audRate);
meta.setSize(tNumber, it->audSize);
}
if (it->size()){sawParts = true;}
}
meta.setChannels(tNumber, aEntryBox.getChannelCount());
meta.setRate(tNumber, aEntryBox.getSampleRate());
// Might be an fMP4 file! Let's try finding some moof boxes...
bool sawMoof = false;
size_t moofPos = 0;
while ((readBuffer.size() >= 16 || inFile) && keepRunning()){
//Read box header if needed
while (readBuffer.size() < 16 && inFile && keepRunning()){inFile.readSome(16, *this);}
//Failed? Abort - this is not fatal, unlike in the loop above (could just be EOF).
if (readBuffer.size() < 16){break;}
//Box type is always on bytes 5-8 from the start of a box
std::string boxType = std::string(readBuffer+4, 4);
uint64_t boxSize = MP4::calcBoxSize(readBuffer);
if (boxType == "moof"){
while (readBuffer.size() < boxSize && inFile && keepRunning()){inFile.readSome(boxSize-readBuffer.size(), *this);}
if (readBuffer.size() < boxSize){
WARN_MSG("Could not read entire MOOF box into memory at %" PRIu64 " bytes, aborting further parsing!", readPos);
break;
}
if (sawParts && !parsedInitial){
for (std::deque<MP4::TrackHeader>::iterator it = trackHeaders.begin(); it != trackHeaders.end(); ++it){
tNumber = M.trackIDToIndex(it->trackId);
for (uint64_t partNo = 0; partNo < it->size(); ++partNo){
uint64_t prtBpos = 0, prtTime = 0;
uint32_t prtBlen = 0;
int32_t prtTimeOff = 0;
bool prtKey = false;
it->getPart(partNo, &prtBpos, &prtBlen, &prtTime, &prtTimeOff, &prtKey);
meta.update(prtTime, prtTimeOff, tNumber, prtBlen, moovPos, prtKey && it->trackType != "audio");
sawParts = true;
if (sType == "ac-3"){
meta.setCodec(tNumber, "AC3");
}else{
MP4::Box codingBox = aEntryBox.getCodecBox();
if (codingBox.getType() == "esds"){
MP4::ESDS & esdsBox = (MP4::ESDS &)codingBox;
meta.setCodec(tNumber, esdsBox.getCodec());
meta.setInit(tNumber, esdsBox.getInitData());
}
if (codingBox.getType() == "wave"){
MP4::WAVE & waveBox = (MP4::WAVE &)codingBox;
for (size_t c = 0; c < waveBox.getContentCount(); ++c){
MP4::Box content = waveBox.getContent(c);
if (content.getType() == "esds"){
MP4::ESDS & esdsBox = (MP4::ESDS &)content;
meta.setCodec(tNumber, esdsBox.getCodec());
meta.setInit(tNumber, esdsBox.getInitData());
}
}
bps += M.getBps(tNumber);
}
parsedInitial = true;
}
MP4::Box moofBox(readBuffer, false);
moofPos = readPos;
// Indicate that we're reading the next moof box to all track headers
for (std::deque<MP4::TrackHeader>::iterator t = trackHeaders.begin(); t != trackHeaders.end(); ++t){
t->nextMoof();
meta.setSize(tNumber, 16); ///\todo this might be nice to calculate from mp4 file;
}
if (sType == "tx3g"){// plain text subtitles
meta.setType(tNumber, "meta");
meta.setCodec(tNumber, "subtitle");
}
MP4::STSS stssBox = stblBox.getChild<MP4::STSS>();
MP4::STTS sttsBox = stblBox.getChild<MP4::STTS>();
MP4::STSZ stszBox = stblBox.getChild<MP4::STSZ>();
MP4::STCO stcoBox = stblBox.getChild<MP4::STCO>();
MP4::CO64 co64Box = stblBox.getChild<MP4::CO64>();
MP4::STSC stscBox = stblBox.getChild<MP4::STSC>();
MP4::CTTS cttsBox = stblBox.getChild<MP4::CTTS>(); // optional ctts box
bool stco64 = co64Box.isType("co64");
bool hasCTTS = cttsBox.isType("ctts");
int64_t DTS_CTS_offset = 0; ///< Difference between composition time and decode time. Always positive.
if (hasCTTS){
uint32_t cttsCount = cttsBox.getEntryCount();
for (uint32_t i = 0; i < cttsCount; ++i){
MP4::CTTSEntry e = cttsBox.getCTTSEntry(i);
int64_t o = (-e.sampleOffset * 1000) / (int64_t)timescale;
if (o > DTS_CTS_offset){DTS_CTS_offset = o;}
}
// Loop over traf boxes inside the moof box, but them in our header parser
std::deque<MP4::TRAF> trafs = ((MP4::MOOF*)&moofBox)->getChildren<MP4::TRAF>();
for (std::deque<MP4::TRAF>::iterator t = trafs.begin(); t != trafs.end(); ++t){
if (!(t->getChild<MP4::TFHD>())){
WARN_MSG("Could not find thfd box inside traf box!");
continue;
}
uint32_t trackId = t->getChild<MP4::TFHD>().getTrackID();
headerData(trackId).read(*t);
}
INFO_MSG("Calculated DTS/CTS offset for track %zu: %" PRId64, tNumber, DTS_CTS_offset);
uint64_t totaldur = 0; ///\todo note: set this to begin time
uint64_t totalExtraDur = 0;
mp4PartBpos BsetPart;
uint64_t entryNo = 0;
uint64_t sampleNo = 0;
uint64_t stssIndex = 0;
uint64_t stcoIndex = 0;
uint64_t stscIndex = 0;
uint64_t cttsIndex = 0; // current ctts Index we are reading
uint64_t cttsEntryRead = 0; // current part of ctts we are reading
uint64_t stssCount = stssBox.getEntryCount();
uint64_t stscCount = stscBox.getEntryCount();
uint64_t stszCount = stszBox.getSampleCount();
uint64_t stcoCount = (stco64 ? co64Box.getEntryCount() : stcoBox.getEntryCount());
MP4::STTSEntry sttsEntry = sttsBox.getSTTSEntry(0);
uint32_t fromSTCOinSTSC = 0;
uint64_t tmpOffset = (stco64 ? co64Box.getChunkOffset(0) : stcoBox.getChunkOffset(0));
uint64_t nextFirstChunk = (stscCount > 1 ? stscBox.getSTSCEntry(1).firstChunk - 1 : stcoCount);
for (uint64_t stszIndex = 0; stszIndex < stszCount; ++stszIndex){
if (stcoIndex >= nextFirstChunk){
++stscIndex;
nextFirstChunk =
(stscIndex + 1 < stscCount ? stscBox.getSTSCEntry(stscIndex + 1).firstChunk - 1 : stcoCount);
}
BsetPart.keyframe = (meta.getType(tNumber) == "video" && stssIndex < stssCount &&
stszIndex + 1 == stssBox.getSampleNumber(stssIndex));
if (BsetPart.keyframe){++stssIndex;}
// in bpos set
BsetPart.stcoNr = stcoIndex;
// bpos = chunkoffset[samplenr] in stco
BsetPart.bpos = tmpOffset;
++fromSTCOinSTSC;
if (fromSTCOinSTSC < stscBox.getSTSCEntry(stscIndex).samplesPerChunk){// as long as we are still in this chunk
tmpOffset += stszBox.getEntrySize(stszIndex);
}else{
++stcoIndex;
fromSTCOinSTSC = 0;
tmpOffset = (stco64 ? co64Box.getChunkOffset(stcoIndex) : stcoBox.getChunkOffset(stcoIndex));
}
BsetPart.time = (totaldur * 1000) / timescale;
totaldur += sttsEntry.sampleDelta;
//Undo time shifts as much as possible
if (totalExtraDur){
totaldur -= totalExtraDur;
totalExtraDur = 0;
}
// Parse data from moof header into our header
for (std::deque<MP4::TrackHeader>::iterator it = trackHeaders.begin(); it != trackHeaders.end(); it++){
if (!it->compatible()){continue;}
tNumber = M.trackIDToIndex(it->trackId);
for (uint64_t partNo = 0; partNo < it->size(); ++partNo){
uint64_t prtBpos = 0, prtTime = 0;
uint32_t prtBlen = 0;
int32_t prtTimeOff = 0;
bool prtKey = false;
it->getPart(partNo, &prtBpos, &prtBlen, &prtTime, &prtTimeOff, &prtKey, moofPos);
// Skip any parts that are outside the file limits
if (inFile.getSize() != std::string::npos && prtBpos + prtBlen > inFile.getSize()){continue;}
// Note: we set the byte position to the position of the moof, so we can re-read it later with ease
meta.update(prtTime, prtTimeOff, tNumber, prtBlen, moofPos, prtKey && it->trackType != "audio");
sawParts = true;
//Make sure our timestamps go up by at least 1 for every packet
if (BsetPart.time >= (uint64_t)((totaldur * 1000) / timescale)){
uint32_t wantSamples = ((BsetPart.time+1) * timescale) / 1000;
totalExtraDur += wantSamples - totaldur;
totaldur = wantSamples;
}
sampleNo++;
if (sampleNo >= sttsEntry.sampleCount){
++entryNo;
sampleNo = 0;
if (entryNo < sttsBox.getEntryCount()){sttsEntry = sttsBox.getSTTSEntry(entryNo);}
}
if (hasCTTS){
MP4::CTTSEntry cttsEntry = cttsBox.getCTTSEntry(cttsIndex);
cttsEntryRead++;
if (cttsEntryRead >= cttsEntry.sampleCount){
++cttsIndex;
cttsEntryRead = 0;
}
BsetPart.timeOffset = (cttsEntry.sampleOffset * 1000) / (int64_t)timescale;
}else{
BsetPart.timeOffset = 0;
}
}
activityCounter = Util::bootSecs();
//Skip to next box
if (readBuffer.size() > boxSize){
readBuffer.shift(boxSize);
readPos += boxSize;
}else{
readBuffer.truncate(0);
if (!inFile.seek(readPos + boxSize)){
FAIL_MSG("Seek to %" PRIu64 " failed! Aborting load", readPos+boxSize);
if (sType == "tx3g"){
if (stszBox.getEntrySize(stszIndex) <= 2 && false){
FAIL_MSG("size <=2");
}else{
long long packSendSize = 0;
packSendSize = 24 + (BsetPart.timeOffset ? 17 : 0) + (BsetPart.bpos ? 15 : 0) + 19 +
stszBox.getEntrySize(stszIndex) + 11 - 2 + 19;
meta.update(BsetPart.time - DTS_CTS_offset + globalTimeOffset, BsetPart.timeOffset + DTS_CTS_offset, tNumber,
stszBox.getEntrySize(stszIndex) - 2, BsetPart.bpos+2, true, packSendSize);
}
}else{
meta.update(BsetPart.time - DTS_CTS_offset + globalTimeOffset, BsetPart.timeOffset + DTS_CTS_offset, tNumber,
stszBox.getEntrySize(stszIndex), BsetPart.bpos, BsetPart.keyframe);
}
readPos = inFile.getPos();
}
}
if (!sawParts){
WARN_MSG("Could not find any MOOF boxes with data, either! Considering load failed and aborting.");
return false;
}
// Mark file as fmp4 so we know to treat it as one
if (sawMoof){meta.inputLocalVars["fmp4"] = true;}
if (!parsedInitial){
for (std::deque<MP4::TrackHeader>::iterator it = trackHeaders.begin(); it != trackHeaders.end(); ++it){
tNumber = M.trackIDToIndex(it->trackId);
for (uint64_t partNo = 0; partNo < it->size(); ++partNo){
uint64_t prtBpos = 0, prtTime = 0;
uint32_t prtBlen = 0;
int32_t prtTimeOff = 0;
bool prtKey = false;
it->getPart(partNo, &prtBpos, &prtBlen, &prtTime, &prtTimeOff, &prtKey);
meta.update(prtTime, prtTimeOff, tNumber, prtBlen, prtBpos, prtKey && it->trackType != "audio");
sawParts = true;
}
bps += M.getBps(tNumber);
}
}
bps = 0;
std::set<size_t> tracks = M.getValidTracks();
for (std::set<size_t>::iterator it = tracks.begin(); it != tracks.end(); it++){bps += M.getBps(*it);}
return true;
}
void InputMP4::getNext(size_t idx){// get next part from track in stream
thisPacket.null();
if (curPositions.empty()){
// fMP4 file? Seek to the right header and read it in
if (nextBox){
uint32_t trackId = M.getID(idx);
MP4::TrackHeader & thisHeader = headerData(trackId);
thisPacket.null();
return;
}
// pop uit set
mp4PartTime curPart = *curPositions.begin();
curPositions.erase(curPositions.begin());
std::string boxType;
while (boxType != "moof"){
if (!shiftTo(nextBox, 12)){return;}
boxType = std::string(readBuffer+(nextBox - readPos)+4, 4);
if (boxType == "moof"){break;}
if (boxType != "mdat"){INFO_MSG("Skipping box: %s", boxType.c_str());}
uint64_t boxSize = MP4::calcBoxSize(readBuffer + (nextBox - readPos));
nextBox += boxSize;
}
uint64_t boxSize = MP4::calcBoxSize(readBuffer + (nextBox - readPos));
if (!shiftTo(nextBox, boxSize)){return;}
uint64_t moofPos = nextBox;
{
MP4::Box moofBox(readBuffer + (nextBox-readPos), false);
thisHeader.nextMoof();
// Loop over traf boxes inside the moof box, but them in our header parser
std::deque<MP4::TRAF> trafs = ((MP4::MOOF*)&moofBox)->getChildren<MP4::TRAF>();
for (std::deque<MP4::TRAF>::iterator t = trafs.begin(); t != trafs.end(); ++t){
if (!(t->getChild<MP4::TFHD>())){
WARN_MSG("Could not find thfd box inside traf box!");
continue;
}
if (t->getChild<MP4::TFHD>().getTrackID() == trackId){thisHeader.read(*t);}
}
}
size_t headerDataSize = thisHeader.size();
MP4::PartTime addPart;
addPart.trackID = idx;
for (size_t i = 0; i < headerDataSize; i++){
thisHeader.getPart(i, &addPart.bpos, &addPart.size, &addPart.time, &addPart.offset, &addPart.keyframe, moofPos);
addPart.index = i;
curPositions.insert(addPart);
}
nextBox += boxSize;
bool isKeyframe = false;
DTSC::Keys keys(M.keys(curPart.trackID));
DTSC::Parts parts(M.parts(curPart.trackID));
uint32_t nextKeyNum = nextKeyframe[curPart.trackID];
if (nextKeyNum < keys.getEndValid()){
// checking if this is a keyframe
if (meta.getType(curPart.trackID) == "video" && curPart.time == keys.getTime(nextKeyNum)){
isKeyframe = true;
}
// if a keyframe has passed, we find the next keyframe
if (keys.getTime(nextKeyNum) <= curPart.time){
++nextKeyframe[curPart.trackID];
++nextKeyNum;
}
}
if (curPart.bpos < readPos || curPart.bpos > readPos + readBuffer.size() + 512*1024 + bps){
INFO_MSG("Buffer contains %" PRIu64 "-%" PRIu64 ", but we need %" PRIu64 "; seeking!", readPos, readPos + readBuffer.size(), curPart.bpos);
readBuffer.truncate(0);
if (!inFile.seek(curPart.bpos)){
Util::logExitReason(ER_FORMAT_SPECIFIC, "seek unsuccessful @bpos %" PRIu64 ": %s", curPart.bpos, strerror(errno));
thisPacket.null();
return;
}
readPos = inFile.getPos();
}else{
//If we have more than 5MiB buffered and are more than 5MiB into the buffer, shift the first 4MiB off the buffer.
//This prevents infinite growth of the read buffer for large files
if (readBuffer.size() >= 5*1024*1024 && curPart.bpos > readPos + 5*1024*1024 + bps){
readBuffer.shift(4*1024*1024);
readPos += 4*1024*1024;
}
}
// pop uit set
MP4::PartTime curPart = *curPositions.begin();
curPositions.erase(curPositions.begin());
if (!shiftTo(curPart.bpos, curPart.size)){return;}
while (readPos+readBuffer.size() < curPart.bpos+curPart.size && inFile && keepRunning()){
inFile.readSome((curPart.bpos+curPart.size) - (readPos+readBuffer.size()), *this);
}
if (readPos+readBuffer.size() < curPart.bpos+curPart.size){
FAIL_MSG("Read unsuccessful at %" PRIu64 ", seeking to retry...", readPos+readBuffer.size());
readBuffer.truncate(0);
if (!inFile.seek(curPart.bpos)){
Util::logExitReason(ER_FORMAT_SPECIFIC, "seek unsuccessful @bpos %" PRIu64 ": %s", curPart.bpos, strerror(errno));
thisPacket.null();
return;
}
readPos = inFile.getPos();
while (readPos+readBuffer.size() < curPart.bpos+curPart.size && inFile && keepRunning()){
inFile.readSome((curPart.bpos+curPart.size) - (readPos+readBuffer.size()), *this);
}
if (readPos+readBuffer.size() < curPart.bpos+curPart.size){
Util::logExitReason(ER_FORMAT_SPECIFIC, "Read retry unsuccessful at %" PRIu64 ", aborting", readPos+readBuffer.size());
thisPacket.null();
return;
}
}
if (M.getCodec(curPart.trackID) == "subtitle"){
static JSON::Value thisPack;
thisPack.null();
thisPack["trackid"] = (uint64_t)curPart.trackID;
thisPack["bpos"] = curPart.bpos; //(long long)fileSource.tellg();
thisPack["data"] = std::string(readBuffer + (curPart.bpos-readPos), curPart.size);
@ -376,129 +615,61 @@ namespace Mist{
std::string tmpStr = thisPack.toNetPacked();
thisPacket.reInit(tmpStr.data(), tmpStr.size());
}else{
bool isKeyframe = (curPart.keyframe && meta.getType(curPart.trackID) == "video");
thisPacket.genericFill(curPart.time, curPart.offset, curPart.trackID, readBuffer + (curPart.bpos-readPos), curPart.size, 0, isKeyframe);
}
thisTime = curPart.time;
thisIdx = curPart.trackID;
if (!nextBox){
// get the next part for this track
curPart.index++;
if (curPart.index < headerData(M.getID(curPart.trackID)).size()){
headerData(M.getID(curPart.trackID)).getPart(curPart.index, &curPart.bpos, &curPart.size, &curPart.time, &curPart.offset, &curPart.keyframe);
curPositions.insert(curPart);
}
// get the next part for this track
curPart.index++;
if (curPart.index < headerData(M.getID(curPart.trackID)).size()){
headerData(M.getID(curPart.trackID)).getPart(curPart.index, curPart.bpos);
if (M.getCodec(curPart.trackID) == "subtitle"){curPart.bpos += 2;}
curPart.size = parts.getSize(curPart.index);
curPart.offset = parts.getOffset(curPart.index);
curPart.time = M.getPartTime(curPart.index, thisIdx);
curPart.duration = parts.getDuration(curPart.index);
curPositions.insert(curPart);
}
}
void InputMP4::seek(uint64_t seekTime, size_t idx){// seek to a point
nextKeyframe.clear();
curPositions.clear();
if (idx == INVALID_TRACK_ID){
FAIL_MSG("Seeking more than 1 track at a time in MP4 input is unsupported");
return;
}
MP4::PartTime addPart;
addPart.trackID = idx;
size_t trackId = M.getID(idx);
MP4::TrackHeader &thisHeader = headerData(M.getID(idx));
uint64_t moofPos = 0;
// fMP4 file? Seek to the right header and read it in
if (M.inputLocalVars.isMember("fmp4")){
uint32_t keyIdx = M.getKeyIndexForTime(idx, seekTime);
size_t bPos = M.getKeys(idx).getBpos(keyIdx);
if (bPos == moovPos){
thisHeader.revertToMoov();
if (!shiftTo(bPos, 12)){return;}
uint64_t boxSize = MP4::calcBoxSize(readBuffer + (bPos - readPos));
nextBox = bPos + boxSize;
}else{
if (!shiftTo(bPos, 12)){return;}
std::string boxType = std::string(readBuffer+(bPos - readPos)+4, 4);
if (boxType != "moof"){
FAIL_MSG("Read %s box instead of moof box at %zub!", boxType.c_str(), bPos);
Util::logExitReason(ER_FORMAT_SPECIFIC, "Did not find moof box at expected position");
return;
}
uint64_t boxSize = MP4::calcBoxSize(readBuffer + (bPos - readPos));
if (!shiftTo(bPos, boxSize)){return;}
MP4::Box moofBox(readBuffer + (bPos-readPos), false);
moofPos = bPos;
thisHeader.nextMoof();
// Loop over traf boxes inside the moof box, put them in our header parser
std::deque<MP4::TRAF> trafs = ((MP4::MOOF*)&moofBox)->getChildren<MP4::TRAF>();
for (std::deque<MP4::TRAF>::iterator t = trafs.begin(); t != trafs.end(); ++t){
if (!(t->getChild<MP4::TFHD>())){
WARN_MSG("Could not find thfd box inside traf box!");
continue;
}
if (t->getChild<MP4::TFHD>().getTrackID() == trackId){thisHeader.read(*t);}
}
nextBox = bPos + boxSize;
if (idx != INVALID_TRACK_ID){
handleSeek(seekTime, idx);
}else{
std::set<size_t> tracks = M.getValidTracks();
for (std::set<size_t>::iterator it = tracks.begin(); it != tracks.end(); it++){
handleSeek(seekTime, *it);
}
}
}
void InputMP4::handleSeek(uint64_t seekTime, size_t idx){
nextKeyframe[idx] = 0;
mp4PartTime addPart;
addPart.trackID = idx;
// for all stsz samples in those tracks
mp4TrackHeader &thisHeader = headerData(M.getID(idx));
size_t headerDataSize = thisHeader.size();
DTSC::Keys keys(M.keys(idx));
DTSC::Parts parts(M.parts(idx));
for (size_t i = 0; i < headerDataSize; i++){
thisHeader.getPart(i, &addPart.bpos, &addPart.size, &addPart.time, &addPart.offset, &addPart.keyframe, moofPos);
// Skip any parts that are outside the file limits
if (inFile.getSize() != std::string::npos && addPart.bpos + addPart.size > inFile.getSize()){continue;}
thisHeader.getPart(i, addPart.bpos);
if (M.getCodec(idx) == "subtitle"){addPart.bpos += 2;}
addPart.size = parts.getSize(i);
addPart.offset = parts.getOffset(i);
addPart.time = M.getPartTime(i, idx);
addPart.duration = parts.getDuration(i);
if (keys.getTime(nextKeyframe[idx]) < addPart.time){nextKeyframe[idx]++;}
if (addPart.time >= seekTime){
addPart.index = i;
curPositions.insert(addPart);
if (!nextBox){break;}
break;
}
}
}
/// Shifts the read buffer (if needed) so that bytes pos through pos+len are currently buffered.
/// Returns true on success, false on failure.
bool InputMP4::shiftTo(size_t pos, size_t len){
if (pos < readPos || pos > readPos + readBuffer.size() + 512*1024 + bps){
INFO_MSG("Buffer contains %" PRIu64 "-%" PRIu64 ", but we need %" PRIu64 "; seeking!", readPos, readPos + readBuffer.size(), pos);
readBuffer.truncate(0);
if (!inFile.seek(pos)){
return false;
}
readPos = inFile.getPos();
}else{
//If we have more than 5MiB buffered and are more than 5MiB into the buffer, shift the first 4MiB off the buffer.
//This prevents infinite growth of the read buffer for large files
if (readBuffer.size() >= 5*1024*1024 && pos > readPos + 5*1024*1024 + bps){
readBuffer.shift(4*1024*1024);
readPos += 4*1024*1024;
}
}
while (readPos+readBuffer.size() < pos+len && inFile && keepRunning()){
inFile.readSome((pos+len) - (readPos+readBuffer.size()), *this);
}
if (readPos+readBuffer.size() < pos+len){
if (inFile.getSize() != std::string::npos || inFile.getSize() > readPos+readBuffer.size()){
FAIL_MSG("Read unsuccessful at %" PRIu64 ", seeking to retry...", readPos+readBuffer.size());
readBuffer.truncate(0);
if (!inFile.seek(pos)){
return false;
}
readPos = inFile.getPos();
while (readPos+readBuffer.size() < pos+len && inFile && keepRunning()){
inFile.readSome((pos+len) - (readPos+readBuffer.size()), *this);
}
if (readPos+readBuffer.size() < pos+len){
return false;
}
}else{
WARN_MSG("Attempt to read past end of file!");
return false;
}
}
return true;
}
}// namespace Mist

View file

@ -2,9 +2,71 @@
#include <mist/dtsc.h>
#include <mist/urireader.h>
#include <mist/mp4.h>
#include <mist/mp4_stream.h>
#include <mist/mp4_generic.h>
namespace Mist{
class mp4PartTime{
public:
mp4PartTime() : time(0), duration(0), offset(0), trackID(0), bpos(0), size(0), index(0){}
bool operator<(const mp4PartTime &rhs) const{
if (time < rhs.time){return true;}
if (time > rhs.time){return false;}
if (trackID < rhs.trackID){return true;}
return (trackID == rhs.trackID && bpos < rhs.bpos);
}
uint64_t time;
uint64_t duration;
int32_t offset;
size_t trackID;
uint64_t bpos;
uint32_t size;
uint64_t index;
};
struct mp4PartBpos{
bool operator<(const mp4PartBpos &rhs) const{
if (time < rhs.time){return true;}
if (time > rhs.time){return false;}
if (trackID < rhs.trackID){return true;}
return (trackID == rhs.trackID && bpos < rhs.bpos);
}
uint64_t time;
size_t trackID;
uint64_t bpos;
uint64_t size;
uint64_t stcoNr;
int32_t timeOffset;
bool keyframe;
};
class mp4TrackHeader{
public:
mp4TrackHeader();
size_t trackId;
void read(MP4::TRAK &trakBox);
MP4::STCO stcoBox;
MP4::CO64 co64Box;
MP4::STSZ stszBox;
MP4::STSC stscBox;
uint64_t timeScale;
void getPart(uint64_t index, uint64_t &offset);
uint64_t size();
private:
bool initialised;
// next variables are needed for the stsc/stco loop
uint64_t stscStart;
uint64_t sampleIndex;
// next variables are needed for the stts loop
uint64_t deltaIndex; ///< Index in STTS box
uint64_t deltaPos; ///< Sample counter for STTS box
uint64_t deltaTotal; ///< Total timestamp for STTS box
// for CTTS box loop
uint64_t offsetIndex; ///< Index in CTTS box
uint64_t offsetPos; ///< Sample counter for CTTS box
bool stco64;
};
class InputMP4 : public Input, public Util::DataCallback {
public:
InputMP4(Util::Config *cfg);
@ -19,19 +81,20 @@ namespace Mist{
bool needHeader();
void getNext(size_t idx = INVALID_TRACK_ID);
void seek(uint64_t seekTime, size_t idx = INVALID_TRACK_ID);
bool shiftTo(size_t pos, size_t len);
void handleSeek(uint64_t seekTime, size_t idx);
HTTP::URIReader inFile;
Util::ResizeablePointer readBuffer;
uint64_t readPos;
uint64_t moovPos;
uint64_t bps;
uint64_t nextBox;
MP4::TrackHeader &headerData(size_t trackID);
mp4TrackHeader &headerData(size_t trackID);
std::deque<MP4::TrackHeader> trackHeaders;
std::set<MP4::PartTime> curPositions;
std::deque<mp4TrackHeader> trackHeaders;
std::set<mp4PartTime> curPositions;
// remember last seeked keyframe;
std::map<size_t, uint32_t> nextKeyframe;
};
}// namespace Mist

View file

@ -1,10 +1,8 @@
#include "input_tssrt.h"
#include <string>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sys/stat.h>
#include <mist/defines.h>
#include <mist/downloader.h>
#include <mist/flv_tag.h>
@ -15,9 +13,11 @@
#include <mist/timing.h>
#include <mist/ts_packet.h>
#include <mist/util.h>
#include <mist/auth.h>
#include <string>
#include <mist/procs.h>
#include <mist/tinythread.h>
#include <sys/stat.h>
Util::Config *cfgPointer = NULL;
std::string baseStreamName;
@ -33,6 +33,7 @@ void signal_handler(int signum, siginfo_t *sigInfo, void *ignore){
}
}
// We use threads here for multiple input pushes, because of the internals of the SRT Library
static void callThreadCallbackSRT(void *socknum){
// use the accepted socket as the second parameter
@ -46,8 +47,6 @@ namespace Mist{
/// \arg cfg Util::Config that contains all current configurations.
InputTSSRT::InputTSSRT(Util::Config *cfg, Socket::SRTConnection s) : Input(cfg){
rawIdx = INVALID_TRACK_ID;
udpInit = 0;
srtConn = 0;
lastRawPacket = 0;
bootMSOffsetCalculated = false;
assembler.setLive();
@ -137,17 +136,16 @@ namespace Mist{
// Setup if we are called form with a thread for push-based input.
if (s.connected()){
srtConn = new Socket::SRTConnection(s);
srtConn = s;
streamName = baseStreamName;
std::string streamid = srtConn->getStreamName();
std::string streamid = srtConn.getStreamName();
int64_t acc = config->getInteger("acceptable");
if (acc == 0){
if (streamid.size()){streamName += "+" + streamid;}
}else if(acc == 2){
if (streamName != streamid){
FAIL_MSG("Stream ID '%s' does not match stream name, push blocked", streamid.c_str());
srtConn->close();
srtConn = 0;
srtConn.close();
}
}
Util::setStreamName(streamName);
@ -171,49 +169,46 @@ namespace Mist{
Socket::SRT::libraryInit();
rawMode = config->getBool("raw");
if (rawMode){INFO_MSG("Entering raw mode");}
if (srtConn && *srtConn){return true;}
std::string source = config->getString("input");
standAlone = false;
HTTP::URL u(source);
INFO_MSG("Parsed url: %s", u.getUrl().c_str());
if (Socket::interpretSRTMode(u) == "listener"){
std::map<std::string, std::string> arguments;
HTTP::parseVars(u.args, arguments);
sSock = Socket::SRTServer(u.getPort(), u.host, arguments, false);
struct sigaction new_action;
struct sigaction cur_action;
new_action.sa_sigaction = signal_handler;
sigemptyset(&new_action.sa_mask);
new_action.sa_flags = SA_SIGINFO;
sigaction(SIGINT, &new_action, &cur_action);
if (cur_action.sa_sigaction && cur_action.sa_sigaction != oldSignal){
if (oldSignal){WARN_MSG("Multiple signal handlers! I can't deal with this.");}
oldSignal = cur_action.sa_sigaction;
if (srtConn.getSocket() == -1){
std::string source = config->getString("input");
standAlone = false;
HTTP::URL u(source);
INFO_MSG("Parsed url: %s", u.getUrl().c_str());
if (Socket::interpretSRTMode(u) == "listener"){
std::map<std::string, std::string> arguments;
HTTP::parseVars(u.args, arguments);
sSock = Socket::SRTServer(u.getPort(), u.host, arguments, false);
struct sigaction new_action;
struct sigaction cur_action;
new_action.sa_sigaction = signal_handler;
sigemptyset(&new_action.sa_mask);
new_action.sa_flags = SA_SIGINFO;
sigaction(SIGINT, &new_action, &cur_action);
if (cur_action.sa_sigaction && cur_action.sa_sigaction != oldSignal){
if (oldSignal){WARN_MSG("Multiple signal handlers! I can't deal with this.");}
oldSignal = cur_action.sa_sigaction;
}
sigaction(SIGHUP, &new_action, &cur_action);
if (cur_action.sa_sigaction && cur_action.sa_sigaction != oldSignal){
if (oldSignal){WARN_MSG("Multiple signal handlers! I can't deal with this.");}
oldSignal = cur_action.sa_sigaction;
}
sigaction(SIGTERM, &new_action, &cur_action);
if (cur_action.sa_sigaction && cur_action.sa_sigaction != oldSignal){
if (oldSignal){WARN_MSG("Multiple signal handlers! I can't deal with this.");}
oldSignal = cur_action.sa_sigaction;
}
}else{
std::map<std::string, std::string> arguments;
HTTP::parseVars(u.args, arguments);
size_t connectCnt = 0;
do{
srtConn.connect(u.host, u.getPort(), "input", arguments);
if (!srtConn){Util::sleep(1000);}
++connectCnt;
}while (!srtConn && connectCnt < 10);
if (!srtConn){WARN_MSG("Connecting to %s timed out", u.getUrl().c_str());}
}
sigaction(SIGHUP, &new_action, &cur_action);
if (cur_action.sa_sigaction && cur_action.sa_sigaction != oldSignal){
if (oldSignal){WARN_MSG("Multiple signal handlers! I can't deal with this.");}
oldSignal = cur_action.sa_sigaction;
}
sigaction(SIGTERM, &new_action, &cur_action);
if (cur_action.sa_sigaction && cur_action.sa_sigaction != oldSignal){
if (oldSignal){WARN_MSG("Multiple signal handlers! I can't deal with this.");}
oldSignal = cur_action.sa_sigaction;
}
}else{
std::map<std::string, std::string> arguments;
HTTP::parseVars(u.args, arguments);
std::string addData;
if (arguments.count("streamid")){addData = arguments["streamid"];}
size_t connectCnt = 0;
do{
if (!srtConn){srtConn = new Socket::SRTConnection();}
srtConn->connect(u.host, u.getPort(), "input", arguments);
if (!*srtConn){Util::sleep(1000);}
++connectCnt;
}while (!*srtConn && connectCnt < 10);
if (!*srtConn){WARN_MSG("Connecting to %s timed out", u.getUrl().c_str());}
}
return true;
}
@ -222,13 +217,13 @@ namespace Mist{
void InputTSSRT::getNext(size_t idx){
thisPacket.null();
bool hasPacket = tsStream.hasPacket();
while (!hasPacket && srtConn && *srtConn && config->is_active){
while (!hasPacket && srtConn && config->is_active){
size_t recvSize = srtConn->RecvNow();
size_t recvSize = srtConn.RecvNow();
if (recvSize){
if (rawMode){
keepAlive();
rawBuffer.append(srtConn->recvbuf, recvSize);
rawBuffer.append(srtConn.recvbuf, recvSize);
if (rawBuffer.size() >= 1316 && (lastRawPacket == 0 || lastRawPacket != Util::bootMS())){
if (rawIdx == INVALID_TRACK_ID){
rawIdx = meta.addTrack();
@ -245,8 +240,8 @@ namespace Mist{
}
continue;
}
if (assembler.assemble(tsStream, srtConn->recvbuf, recvSize, true)){hasPacket = tsStream.hasPacket();}
}else if (srtConn && *srtConn){
if (assembler.assemble(tsStream, srtConn.recvbuf, recvSize, true)){hasPacket = tsStream.hasPacket();}
}else if (srtConn){
// This should not happen as the SRT socket is read blocking and won't return until there is
// data. But if it does, wait before retry
Util::sleep(10);
@ -255,7 +250,7 @@ namespace Mist{
if (hasPacket){tsStream.getEarliestPacket(thisPacket);}
if (!thisPacket){
if (srtConn && *srtConn){
if (srtConn){
INFO_MSG("Could not getNext TS packet!");
Util::logExitReason(ER_FORMAT_SPECIFIC, "internal TS parser error");
}else{
@ -291,7 +286,7 @@ namespace Mist{
void InputTSSRT::streamMainLoop(){
// If we do not have a srtConn here, we are the main thread and should start accepting pushes.
if (!srtConn || !*srtConn){
if (srtConn.getSocket() == -1){
cfgPointer = config;
baseStreamName = streamName;
while (config->is_active && sSock.connected()){
@ -309,7 +304,7 @@ namespace Mist{
}
// If we are here: we have a proper connection (either accepted or pull input) and should start parsing it as such
Input::streamMainLoop();
srtConn->close();
srtConn.close();
Socket::SRT::libraryCleanup();
}
@ -318,11 +313,11 @@ namespace Mist{
void InputTSSRT::setSingular(bool newSingular){singularFlag = newSingular;}
void InputTSSRT::connStats(Comms::Connections &statComm){
statComm.setUp(srtConn->dataUp());
statComm.setDown(srtConn->dataDown());
statComm.setPacketCount(srtConn->packetCount());
statComm.setPacketLostCount(srtConn->packetLostCount());
statComm.setPacketRetransmitCount(srtConn->packetRetransmitCount());
statComm.setUp(srtConn.dataUp());
statComm.setDown(srtConn.dataDown());
statComm.setPacketCount(srtConn.packetCount());
statComm.setPacketLostCount(srtConn.packetLostCount());
statComm.setPacketRetransmitCount(srtConn.packetRetransmitCount());
}
}// namespace Mist

View file

@ -4,6 +4,7 @@
#include <mist/socket_srt.h>
#include <mist/ts_packet.h>
#include <mist/ts_stream.h>
#include <set>
#include <string>
namespace Mist{
@ -15,7 +16,7 @@ namespace Mist{
void setSingular(bool newSingular);
virtual bool needsLock();
virtual std::string getConnectedBinHost(){
if (srtConn && *srtConn){return srtConn->getBinHost();}
if (srtConn){return srtConn.getBinHost();}
return Input::getConnectedBinHost();
}
@ -37,8 +38,7 @@ namespace Mist{
int64_t timeStampOffset;
uint64_t lastTimeStamp;
Socket::SRTConnection * srtConn;
Socket::UDPConnection * udpInit;
Socket::SRTConnection srtConn;
bool singularFlag;
virtual void connStats(Comms::Connections &statComm);

View file

@ -37,7 +37,7 @@ if have_librist
endif
if have_srt
outputs += {'name' : 'TSSRT', 'format' : 'tssrt', 'extra': ['ts', 'with_srt']}
outputs += {'name' : 'TSSRT', 'format' : 'tssrt', 'extra': ['ts', 'debased', 'with_srt']}
endif
if get_option('WITH_SANITY')

View file

@ -93,7 +93,6 @@ namespace Mist{
Output::Output(Socket::Connection &conn) : myConn(conn){
dataWaitTimeout = 2500;
thisBootMs = Util::bootMS();
pushing = false;
recursingSync = false;
firstTime = Util::bootMS();

View file

@ -74,7 +74,7 @@ namespace Mist{
udpSize = 7;
if (targetParams.count("tracks")){tracks = targetParams["tracks"];}
if (targetParams.count("pkts")){udpSize = atoi(targetParams["pkts"].c_str());}
packetBuffer.allocate(188 * udpSize);
packetBuffer.reserve(188 * udpSize);
if (target.path.size()){
if (!pushSock.bind(0, target.path)){
disconnect();
@ -230,7 +230,7 @@ namespace Mist{
if (wrapRTP){
// Send RTP packet itself
if (rand() % 100 >= dropPercentage){
tsOut.sendTS(&pushSock, packetBuffer, packetBuffer.size());
tsOut.sendTS(&pushSock, packetBuffer.c_str(), packetBuffer.size());
myConn.addUp(tsOut.getHsize() + tsOut.getPayloadSize());
} else {
INFO_MSG("Dropping RTP packet in order to simulate packet loss");
@ -239,14 +239,15 @@ namespace Mist{
if (sendFEC){
// Send FEC packet if available
uint64_t bytesSent = 0;
tsOut.parseFEC(&fecColumnSock, &fecRowSock, bytesSent, packetBuffer, packetBuffer.size());
tsOut.parseFEC(&fecColumnSock, &fecRowSock, bytesSent, packetBuffer.c_str(), packetBuffer.size());
myConn.addUp(bytesSent);
}
}else{
pushSock.SendNow(packetBuffer, packetBuffer.size());
pushSock.SendNow(packetBuffer);
myConn.addUp(packetBuffer.size());
}
packetBuffer.truncate(0);
packetBuffer.clear();
packetBuffer.reserve(udpSize * len);
curFilled = 0;
}
packetBuffer.append(tsData, len);

View file

@ -21,7 +21,7 @@ namespace Mist{
bool wrapRTP;
bool sendFEC;
void onRTP(void *socket, const char *data, size_t nbytes);
Util::ResizeablePointer packetBuffer;
std::string packetBuffer;
Socket::UDPConnection pushSock;
Socket::UDPConnection fecColumnSock;
Socket::UDPConnection fecRowSock;

View file

@ -8,7 +8,6 @@ namespace Mist{
setBlocking(true);
sendRepeatingHeaders = 0;
lastHeaderTime = 0;
maxSkipAhead = 0;
}
void TSOutput::fillPacket(char const *data, size_t dataLen, bool &firstPack, bool video,
@ -71,8 +70,6 @@ namespace Mist{
return;
}
}
if (liveSeek(true)){return;}
if (!M.trackLoaded(thisIdx)){return;}
// Get ready some data to speed up accesses
std::string type = M.getType(thisIdx);
std::string codec = M.getCodec(thisIdx);

View file

@ -6,13 +6,11 @@
#include <mist/encode.h>
#include <mist/stream.h>
#include <mist/triggers.h>
#include <mist/auth.h>
bool allowStreamNameOverride = true;
namespace Mist{
OutTSSRT::OutTSSRT(Socket::Connection &conn, Socket::SRTConnection * _srtSock) : TSOutput(conn){
srtConn = _srtSock;
OutTSSRT::OutTSSRT(Socket::Connection &conn, Socket::SRTConnection & _srtSock) : TSOutput(conn), srtConn(_srtSock){
// NOTE: conn is useless for SRT, as it uses a different socket type.
sendRepeatingHeaders = 500; // PAT/PMT every 500ms (DVB spec)
streamName = config->getString("streamname");
@ -20,14 +18,9 @@ namespace Mist{
pushOut = false;
bootMSOffsetCalculated = false;
assembler.setLive();
udpInit = 0;
// Push output configuration
if (config->getString("target").size()){
Socket::SRT::libraryInit();
target = HTTP::URL(config->getString("target"));
HTTP::parseVars(target.args, targetParams);
std::string addData;
if (targetParams.count("streamid")){addData = targetParams["streamid"];}
if (target.protocol != "srt"){
FAIL_MSG("Target %s must begin with srt://, aborting", target.getUrl().c_str());
onFail("Invalid srt target: doesn't start with srt://", true);
@ -39,27 +32,28 @@ namespace Mist{
return;
}
pushOut = true;
HTTP::parseVars(target.args, targetParams);
size_t connectCnt = 0;
do{
if (!srtConn){srtConn = new Socket::SRTConnection();}
if (srtConn){srtConn->connect(target.host, target.getPort(), "output", targetParams);}
if (!*srtConn){
srtConn.connect(target.host, target.getPort(), "output", targetParams);
if (!srtConn){
Util::sleep(1000);
}else{
INFO_MSG("SRT socket %s on attempt %zu", srtConn->getStateStr(), connectCnt+1);
INFO_MSG("Connect success on attempt %zu", connectCnt+1);
break;
}
++connectCnt;
}while ((!srtConn || !*srtConn) && connectCnt < 5);
}while (!srtConn && connectCnt < 5);
if (!srtConn){
FAIL_MSG("Failed to connect to '%s'!", config->getString("target").c_str());
}
wantRequest = false;
parseData = true;
initialize();
}else{
// Pull output configuration, In this case we have an srt connection in the second constructor parameter.
// Handle override / append of streamname options
std::string sName = srtConn->getStreamName();
std::string sName = srtConn.getStreamName();
if (allowStreamNameOverride){
if (sName != ""){
streamName = sName;
@ -67,19 +61,18 @@ namespace Mist{
Util::setStreamName(streamName);
}
}
myConn.setHost(srtConn->remotehost);
int64_t accTypes = config->getInteger("acceptable");
if (accTypes == 0){//Allow both directions
srtConn->setBlocking(false);
srtConn.setBlocking(false);
//Try to read the socket 10 times. If any reads succeed, assume they are pushing in
size_t retries = 60;
while (!accTypes && *srtConn && retries){
size_t recvSize = srtConn->Recv();
while (!accTypes && srtConn && retries){
size_t recvSize = srtConn.Recv();
if (recvSize){
accTypes = 2;
INFO_MSG("Connection put into ingest mode");
assembler.assemble(tsIn, srtConn->recvbuf, recvSize, true);
assembler.assemble(tsIn, srtConn.recvbuf, recvSize, true);
}else{
Util::sleep(50);
}
@ -92,14 +85,14 @@ namespace Mist{
}
}
if (accTypes == 1){// Only allow outgoing
srtConn->setBlocking(true);
srtConn->direction = "output";
srtConn.setBlocking(true);
srtConn.direction = "output";
parseData = true;
wantRequest = false;
initialize();
}else if (accTypes == 2){//Only allow incoming
srtConn->setBlocking(false);
srtConn->direction = "input";
srtConn.setBlocking(false);
srtConn.direction = "input";
if (Triggers::shouldTrigger("PUSH_REWRITE")){
HTTP::URL reqUrl;
reqUrl.protocol = "srt";
@ -122,11 +115,7 @@ namespace Mist{
Util::sanitizeName(streamName);
}
}
if (!streamName.size()){
Util::logExitReason(ER_FORMAT_SPECIFIC, "Push from %s rejected - there is no stream name set", getConnectedHost().c_str());
onFinish();
return;
}
myConn.setHost(srtConn.remotehost);
if (!allowPush("")){
onFinish();
return;
@ -139,57 +128,23 @@ namespace Mist{
}
}
lastWorked = Util::bootSecs();
lastTimeStamp = 0;
timeStampOffset = 0;
}
bool OutTSSRT::onFinish(){
config->is_active = false;
myConn.close();
srtConn.close();
return false;
}
OutTSSRT::~OutTSSRT(){
if(srtConn){
srtConn->close();
delete srtConn;
srtConn = 0;
}
Socket::SRT::libraryCleanup();
}
OutTSSRT::~OutTSSRT(){}
// Override initialSeek to go to last possible position for live streams
void OutTSSRT::initialSeek(bool dryRun){
if (!meta){return;}
meta.removeLimiter();
uint64_t seekPos = 0;
std::set<size_t> validTracks = M.getValidTracks();
if (M.getLive() && validTracks.size()){
if (userSelect.size()){
for (std::map<size_t, Comms::Users>::iterator it = userSelect.begin(); it != userSelect.end(); it++){
if (M.trackValid(it->first) && (M.getNowms(it->first) < seekPos || !seekPos)){
seekPos = meta.getNowms(it->first);
}
}
}else{
for (std::set<size_t>::iterator it = validTracks.begin(); it != validTracks.end(); it++){
if (meta.getNowms(*it) < seekPos || !seekPos){seekPos = meta.getNowms(*it);}
}
}
}
seek(seekPos);
}
static void addIntOpt(JSON::Value & pp, const std::string & param, const std::string & name, const std::string & help, size_t def = 0,const std::string unit = ""){
static void addIntOpt(JSON::Value & pp, const std::string & param, const std::string & name, const std::string & help, size_t def = 0){
pp[param]["name"] = name;
pp[param]["help"] = help;
pp[param]["type"] = "int";
pp[param]["default"] = (uint64_t)def;
if (unit != "") {
pp[param]["unit"] = unit;
}
}
static void addStrOpt(JSON::Value & pp, const std::string & param, const std::string & name, const std::string & help, const std::string & def = ""){
@ -203,16 +158,16 @@ namespace Mist{
pp[param]["name"] = name;
pp[param]["help"] = help;
pp[param]["type"] = "select";
pp[param]["select"][0u][0u] = "";
pp[param]["select"][0u][1u] = def?"Default (true)":"Default (false)";
pp[param]["select"][1u][0u] = 0;
pp[param]["select"][1u][1u] = "False";
pp[param]["select"][2u][0u] = 1;
pp[param]["select"][2u][1u] = "True";
pp[param]["select"][0u][0u] = 0;
pp[param]["select"][0u][1u] = "False";
pp[param]["select"][1u][0u] = 1;
pp[param]["select"][1u][1u] = "True";
pp[param]["type"] = "select";
pp[param]["default"] = def?1:0;
}
void OutTSSRT::init(Util::Config *cfg){
Output::init(cfg);
capa["name"] = "TSSRT";
@ -235,6 +190,14 @@ namespace Mist{
capa["optional"]["streamname"]["short"] = "s";
capa["optional"]["streamname"]["default"] = "";
capa["optional"]["filelimit"]["name"] = "Open file descriptor limit";
capa["optional"]["filelimit"]["help"] = "Increase open file descriptor to this value if current system value is lower. A higher value may be needed for handling many concurrent SRT connections.";
capa["optional"]["filelimit"]["type"] = "int";
capa["optional"]["filelimit"]["option"] = "--filelimit";
capa["optional"]["filelimit"]["short"] = "l";
capa["optional"]["filelimit"]["default"] = "1024";
capa["optional"]["acceptable"]["name"] = "Acceptable connection types";
capa["optional"]["acceptable"]["help"] =
"Whether to allow only incoming pushes (2), only outgoing pulls (1), or both (0, default)";
@ -269,107 +232,61 @@ namespace Mist{
config->addStandardPushCapabilities(capa);
JSON::Value & pp = capa["push_parameters"];
pp["srtopts_main"]["name"] = "Commonly used SRT options";
pp["srtopts_main"]["help"] = "Control the SRT connection";
pp["srtopts_main"]["type"] = "group";
pp["srtopts_main"]["sort"] = "aaa";
pp["srtopts_main"]["expand"] = true;
addIntOpt(pp["srtopts_main"]["options"], "latency", "Latency", "Socket latency, in milliseconds.", 120,"ms");
addStrOpt(pp["srtopts_main"]["options"], "streamid", "Stream ID", "Stream ID to transmit to the other side. MistServer uses this field for the stream name, but the field is entirely free-form and may contain anything.");
addStrOpt(pp["srtopts_main"]["options"], "passphrase", "Encryption passphrase", "Enables encryption with the given passphrase.");
pp["srtopts_main"]["options"]["passphrase"]["minlength"] = 10;
pp["srtopts_main"]["options"]["passphrase"]["maxlength"] = 79;
pp["srtopts"]["name"] = "More SRT options";
pp["srtopts"]["help"] = "Control the SRT connection";
pp["srtopts"]["type"] = "group";
pp["srtopts"]["sort"] = "ab";
pp["srtopts"]["options"]["mode"]["name"] = "Mode";
pp["srtopts"]["options"]["mode"]["help"] = "The connection mode. Can be listener, caller, or rendezvous. By default is listener if the host is missing from the URL, and is caller otherwise.";
pp["srtopts"]["options"]["mode"]["type"] = "select";
pp["srtopts"]["options"]["mode"]["select"][0u][0u] = "";
pp["srtopts"]["options"]["mode"]["select"][0u][1u] = "Default (listener)";
pp["srtopts"]["options"]["mode"]["select"][1u][0u] = "listener";
pp["srtopts"]["options"]["mode"]["select"][1u][1u] = "Listener";
pp["srtopts"]["options"]["mode"]["select"][2u][0u] = "caller";
pp["srtopts"]["options"]["mode"]["select"][2u][1u] = "Caller";
pp["srtopts"]["options"]["mode"]["select"][3u][0u] = "rendezvous";
pp["srtopts"]["options"]["mode"]["select"][3u][1u] = "Rendezvous";
pp["srtopts"]["options"]["transtype"]["name"] = "Transmission type";
pp["srtopts"]["options"]["transtype"]["help"] = "This should be set to live (the default) unless you know what you're doing.";
pp["srtopts"]["options"]["transtype"]["select"][0u][0u] = "";
pp["srtopts"]["options"]["transtype"]["select"][0u][1u] = "Default (live)";
pp["srtopts"]["options"]["transtype"]["select"][1u][0u] = "live";
pp["srtopts"]["options"]["transtype"]["select"][1u][1u] = "Live";
pp["srtopts"]["options"]["transtype"]["select"][2u][0u] = "file";
pp["srtopts"]["options"]["transtype"]["select"][2u][1u] = "File";
pp["srtopts"]["options"]["transtype"]["type"] = "select";
pp["mode"]["name"] = "Mode";
pp["mode"]["help"] = "The connection mode. Can be listener, caller, or rendezvous. By default is listener if the host is missing from the URL, and is caller otherwise.";
pp["mode"]["type"] = "select";
pp["mode"]["select"][0u][0u] = "default";
pp["mode"]["select"][0u][1u] = "Default";
pp["mode"]["select"][1u][0u] = "listener";
pp["mode"]["select"][1u][1u] = "Listener";
pp["mode"]["select"][2u][0u] = "caller";
pp["mode"]["select"][2u][1u] = "Caller";
pp["mode"]["select"][3u][0u] = "rendezvous";
pp["mode"]["select"][3u][1u] = "Rendezvous";
pp["mode"]["type"] = "select";
pp["transtype"]["name"] = "Transmission type";
pp["transtype"]["help"] = "This should be set to live (the default) unless you know what you're doing.";
pp["transtype"]["type"] = "select";
pp["transtype"]["select"][0u][0u] = "";
pp["transtype"]["select"][0u][1u] = "Live";
pp["transtype"]["select"][1u][0u] = "file";
pp["transtype"]["select"][1u][1u] = "File";
pp["transtype"]["type"] = "select";
//addStrOpt(pp, "adapter", "", "");
//addIntOpt(pp, "timeout", "", "");
//addIntOpt(pp, "port", "", "");
addBoolOpt(pp["srtopts"]["options"], "tsbpd", "Timestamp-based Packet Delivery mode", "In this mode the packet's time is assigned at the sending time (or allowed to be predefined), transmitted in the packet's header, and then restored on the receiver side so that the time intervals between consecutive packets are preserved when delivering to the application.", true);
addBoolOpt(pp["srtopts"]["options"], "linger", "Linger closed sockets", "Whether to keep closed sockets around for 180 seconds of linger time or not.", true);
addIntOpt(pp["srtopts"]["options"], "maxbw", "Maximum send bandwidth", "Maximum send bandwidth in bytes per second, -1 for infinite, 0 for relative to input bandwidth.", -1,"bytes/s");
pp["srtopts"]["options"]["pbkeylen"]["name"] = "Encryption key length";
pp["srtopts"]["options"]["pbkeylen"]["help"] = "The encryption key length. Default: auto.";
pp["srtopts"]["options"]["pbkeylen"]["select"][0u][0u] = "";
pp["srtopts"]["options"]["pbkeylen"]["select"][0u][1u] = "Default (auto)";
pp["srtopts"]["options"]["pbkeylen"]["select"][1u][0u] = "0";
pp["srtopts"]["options"]["pbkeylen"]["select"][1u][1u] = "Auto";
pp["srtopts"]["options"]["pbkeylen"]["select"][2u][0u] = "16";
pp["srtopts"]["options"]["pbkeylen"]["select"][2u][1u] = "AES-128";
pp["srtopts"]["options"]["pbkeylen"]["select"][3u][0u] = "24";
pp["srtopts"]["options"]["pbkeylen"]["select"][3u][1u] = "AES-192";
pp["srtopts"]["options"]["pbkeylen"]["select"][4u][0u] = "32";
pp["srtopts"]["options"]["pbkeylen"]["select"][4u][1u] = "AES-256";
pp["srtopts"]["options"]["pbkeylen"]["default"] = "0";
pp["srtopts"]["options"]["pbkeylen"]["type"] = "select";
addIntOpt(pp["srtopts"]["options"], "mss", "Maximum Segment Size", "Maximum size for packets including all headers, in bytes. The default of 1500 is generally the maximum value you can use in most networks.", 1500,"bytes");
addIntOpt(pp["srtopts"]["options"], "fc", "Flight Flag Size", "Maximum packets that may be 'in flight' without being acknowledged.", 25600,"packets");
addIntOpt(pp["srtopts"]["options"], "sndbuf", "Send Buffer Size", "Size of the send buffer, in bytes",0,"bytes");
addIntOpt(pp["srtopts"]["options"], "rcvbuf", "Receive Buffer Size", "Size of the receive buffer, in bytes",0,"bytes");
addIntOpt(pp["srtopts"]["options"], "ipttl", "TTL", "Time To Live for IPv4 connections or unicast hops for IPv6 connections. Defaults to system default.",0,"hops");
addIntOpt(pp["srtopts"]["options"], "iptos", "Type of Service", "TOS for IPv4 connections or Traffic Class for IPv6 connections. Defaults to system default.");
addIntOpt(pp["srtopts"]["options"], "inputbw", "Input bandwidth", "Estimated bandwidth of data to be sent. Default of 0 means automatic.",0,"bytes/s");
addIntOpt(pp["srtopts"]["options"], "oheadbw", "Recovery Bandwidth Overhead", "Percentage of bandwidth to use for recovery.",25,"%");
addBoolOpt(pp, "tsbpd", "Timestamp-based Packet Delivery mode", "In this mode the packet's time is assigned at the sending time (or allowed to be predefined), transmitted in the packet's header, and then restored on the receiver side so that the time intervals between consecutive packets are preserved when delivering to the application.", true);
addBoolOpt(pp, "linger", "Linger closed sockets", "Whether to keep closed sockets around for 180 seconds of linger time or not.", true);
addIntOpt(pp, "maxbw", "Maximum send bandwidth", "Maximum send bandwidth in bytes per second, -1 for infinite, 0 for relative to input bandwidth.", -1);
addIntOpt(pp, "pbkeylen", "Encryption key length", "May be 0 (auto), 16 (AES-128), 24 (AES-192) or 32 (AES-256).", 0);
addStrOpt(pp, "passphrase", "Encryption passphrase", "Enables encryption with the given passphrase.");
addIntOpt(pp, "mss", "Maximum Segment Size", "Maximum size for packets including all headers, in bytes. The default of 1500 is generally the maximum value you can use in most networks.", 1500);
addIntOpt(pp, "fc", "Flight Flag Size", "Maximum packets that may be 'in flight' without being acknowledged.", 25600);
addIntOpt(pp, "sndbuf", "Send Buffer Size", "Size of the send buffer, in bytes");
addIntOpt(pp, "rcvbuf", "Receive Buffer Size", "Size of the receive buffer, in bytes");
addIntOpt(pp, "ipttl", "TTL", "Time To Live for IPv4 connections or unicast hops for IPv6 connections. Defaults to system default.");
addIntOpt(pp, "iptos", "Type of Service", "TOS for IPv4 connections or Traffic Class for IPv6 connections. Defaults to system default.");
addIntOpt(pp, "inputbw", "Input bandwidth", "Estimated bandwidth of data to be sent. Default of 0 means automatic.");
addIntOpt(pp, "oheadbw", "Recovery Bandwidth Overhead", "Percentage of bandwidth to use for recovery.", 25);
addIntOpt(pp, "latency", "Latency", "Socket latency, in milliseconds.", 120);
//addIntOpt(pp, "rcvlatency", "Receive Latency", "Latency in receive mode, in milliseconds", 120);
//addIntOpt(pp, "peerlatency", "", "");
addBoolOpt(pp["srtopts"]["options"], "tlpktdrop", "Too-late Packet Drop", "Skips packets that cannot (sending) or have not (receiving) been delivered in time", true);
addIntOpt(pp["srtopts"]["options"], "snddropdelay", "Send Drop Delay", "Extra delay before Too-late packet drop on sender side is triggered, in milliseconds.",0,"ms");
addBoolOpt(pp["srtopts"]["options"], "nakreport", "Repeat loss reports", "When enabled, repeats loss reports every time the retransmission timeout has expired.", true);
addIntOpt(pp["srtopts"]["options"], "conntimeo", "Connect timeout", "Milliseconds to wait before timing out a connection attempt for caller and rendezvous modes.", 3000,"ms");
addIntOpt(pp["srtopts"]["options"], "lossmaxttl", "Reorder Tolerance", "Maximum amount of packets that may be out of order, or 0 to disable this mechanism.",0,"packets");
addIntOpt(pp["srtopts"]["options"], "minversion", "Minimum SRT version", "Minimum SRT version to require the other side of the connection to support.");
addStrOpt(pp["srtopts"]["options"], "congestion", "Congestion controller", "May be set to 'live' or 'file'", "live");
pp["srtopts"]["options"]["congestion"]["select"][0u][0u] = "";
pp["srtopts"]["options"]["congestion"]["select"][0u][1u] = "Default (live)";
pp["srtopts"]["options"]["congestion"]["select"][1u][0u] = "live";
pp["srtopts"]["options"]["congestion"]["select"][1u][1u] = "Live";
pp["srtopts"]["options"]["congestion"]["select"][2u][0u] = "file";
pp["srtopts"]["options"]["congestion"]["select"][2u][1u] = "File";
pp["srtopts"]["options"]["congestion"]["type"] = "select";
addBoolOpt(pp["srtopts"]["options"], "messageapi", "Message API", "When true, uses the default Message API. When false, uses the Stream API", true);
addBoolOpt(pp, "tlpktdrop", "Too-late Packet Drop", "Skips packets that cannot (sending) or have not (receiving) been delivered in time", true);
addIntOpt(pp, "snddropdelay", "Send Drop Delay", "Extra delay before Too-late packet drop on sender side is triggered, in milliseconds.");
addBoolOpt(pp, "nakreport", "Repeat loss reports", "When enabled, repeats loss reports every time the retransmission timeout has expired.", true);
addIntOpt(pp, "conntimeo", "Connect timeout", "Milliseconds to wait before timing out a connection attempt for caller and rendezvous modes.", 3000);
addIntOpt(pp, "lossmaxttl", "Reorder Tolerance", "Maximum amount of packets that may be out of order, or 0 to disable this mechanism.");
addIntOpt(pp, "minversion", "Minimum SRT version", "Minimum SRT version to require the other side of the connection to support.");
addStrOpt(pp, "streamid", "Stream ID", "Stream ID to transmit to the other side. MistServer uses this field for the stream name, but the field is entirely free-form and may contain anything.");
addStrOpt(pp, "congestion", "Congestion controller", "May be set to 'live' or 'file'", "live");
addBoolOpt(pp, "messageapi", "Message API", "When true, uses the default Message API. When false, uses the Stream API", true);
//addIntOpt(pp, "kmrefreshrate", "", "");
//addIntOpt(pp, "kmreannounce", "", "");
addBoolOpt(pp["srtopts"]["options"], "enforcedencryption", "Enforced Encryption", "If enabled, enforces that both sides either set no passphrase, or set the same passphrase. When disabled, falls back to no passphrase if the passphrases do not match.", true);
addIntOpt(pp["srtopts"]["options"], "peeridletimeo", "Peer Idle Timeout", "Time to wait, in milliseconds, before the connection is considered broken if the peer does not respond.", 5000,"ms");
addStrOpt(pp["srtopts"]["options"], "packetfilter", "Packet Filter", "Sets the SRT packet filter string, see SRT library documentation for details.");
addBoolOpt(pp, "enforcedencryption", "Enforced Encryption", "If enabled, enforces that both sides either set no passphrase, or set the same passphrase. When disabled, falls back to no passphrase if the passphrases do not match.", true);
addIntOpt(pp, "peeridletimeo", "Peer Idle Timeout", "Time to wait, in milliseconds, before the connection is considered broken if the peer does not respond.", 5000);
addStrOpt(pp, "packetfilter", "Packet Filter", "Sets the SRT packet filter string, see SRT library documentation for details.");
JSON::Value opt;
opt["arg"] = "string";
@ -396,83 +313,32 @@ namespace Mist{
opt["default"] = "";
opt["help"] = "Which parser to use for data tracks";
config->addOption("datatrack", opt);
capa["optional"]["passphrase"]["name"] = "Passphrase";
capa["optional"]["passphrase"]["help"] = "If set, requires a SRT passphrase to connect";
capa["optional"]["passphrase"]["type"] = "string";
capa["optional"]["passphrase"]["option"] = "--passphrase";
capa["optional"]["passphrase"]["short"] = "P";
capa["optional"]["passphrase"]["default"] = "";
capa["optional"]["passphrase"]["minlength"] = 10;
capa["optional"]["passphrase"]["maxlength"] = 79;
opt.null();
opt["long"] = "passphrase";
opt["short"] = "P";
opt["arg"] = "string";
opt["default"] = "";
opt["help"] = "If set, requires a SRT passphrase to connect";
config->addOption("passphrase", opt);
capa["optional"]["sockopts"]["name"] = "SRT socket options";
capa["optional"]["sockopts"]["help"] = "Any additional SRT socket options to apply";
capa["optional"]["sockopts"]["type"] = "string";
capa["optional"]["sockopts"]["option"] = "--sockopts";
capa["optional"]["sockopts"]["short"] = "O";
capa["optional"]["sockopts"]["default"] = "";
opt.null();
opt["long"] = "sockopts";
opt["short"] = "O";
opt["arg"] = "string";
opt["default"] = "";
opt["help"] = "Any additional SRT socket options to apply";
config->addOption("sockopts", opt);
}
// Buffers TS packets and sends after 7 are buffered.
void OutTSSRT::sendTS(const char *tsData, size_t len){
packetBuffer.append(tsData, len);
if (packetBuffer.size() >= 1316){//7 whole TS packets
if (!*srtConn){
if (!srtConn){
if (config->getString("target").size()){
if (lastWorked + 5 < Util::bootSecs()){
Util::logExitReason(ER_CLEAN_REMOTE_CLOSE, "SRT connection closed, no reconnect success after 5s");
config->is_active = false;
parseData = false;
return;
}
INFO_MSG("Reconnecting...");
if (srtConn){
srtConn->close();
delete srtConn;
}
if (udpInit){
srtConn = new Socket::SRTConnection(*udpInit, "rendezvous", targetParams);
}else{
srtConn = new Socket::SRTConnection();
}
srtConn->connect(target.host, target.getPort(), "output", targetParams);
if (!*srtConn){Util::sleep(500);}
srtConn.connect(target.host, target.getPort(), "output", targetParams);
if (!srtConn){Util::sleep(500);}
}else{
Util::logExitReason(ER_CLEAN_REMOTE_CLOSE, "SRT connection closed (mid-send)");
config->is_active = false;
Util::logExitReason(ER_CLEAN_REMOTE_CLOSE, "SRT connection closed");
myConn.close();
parseData = false;
return;
}
}
if (*srtConn){
srtConn->SendNow(packetBuffer, packetBuffer.size());
if (!*srtConn){
if (srtConn){
srtConn.SendNow(packetBuffer, packetBuffer.size());
if (!srtConn){
if (!config->getString("target").size()){
Util::logExitReason(ER_CLEAN_REMOTE_CLOSE, "SRT connection closed (post-send)");
config->is_active = false;
Util::logExitReason(ER_CLEAN_REMOTE_CLOSE, "SRT connection closed");
myConn.close();
parseData = false;
}
}else{
lastWorked = Util::bootSecs();
}
}
packetBuffer.assign(0,0);
@ -480,12 +346,11 @@ namespace Mist{
}
void OutTSSRT::requestHandler(){
size_t recvSize = srtConn->Recv();
size_t recvSize = srtConn.Recv();
if (!recvSize){
if (!*srtConn){
Util::logExitReason(ER_CLEAN_REMOTE_CLOSE, "SRT connection %s (in request handler)", srtConn->getStateStr());
config->is_active = false;
srtConn->close();
if (!srtConn){
myConn.close();
srtConn.close();
wantRequest = false;
}else{
Util::sleep(50);
@ -493,13 +358,13 @@ namespace Mist{
return;
}
lastRecv = Util::bootSecs();
if (!assembler.assemble(tsIn, srtConn->recvbuf, recvSize, true)){return;}
if (!assembler.assemble(tsIn, srtConn.recvbuf, recvSize, true)){return;}
while (tsIn.hasPacket()){
tsIn.getEarliestPacket(thisPacket);
if (!thisPacket){
Util::logExitReason(ER_FORMAT_SPECIFIC, "Could not get TS packet");
config->is_active = false;
srtConn->close();
INFO_MSG("Could not get TS packet");
myConn.close();
srtConn.close();
wantRequest = false;
return;
}
@ -515,7 +380,7 @@ namespace Mist{
size_t thisIdx = M.trackIDToIndex(thisPacket.getTrackId(), getpid());
if (thisIdx == INVALID_TRACK_ID){return;}
if (!userSelect.count(thisIdx)){
userSelect[thisIdx].reload(streamName, thisIdx, COMM_STATUS_ACTIVE | COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
userSelect[thisIdx].reload(streamName, thisIdx, COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
}
uint64_t pktTimeWithOffset = thisPacket.getTime() + timeStampOffset;
@ -541,126 +406,164 @@ namespace Mist{
bool OutTSSRT::dropPushTrack(uint32_t trackId, const std::string & dropReason){
Util::logExitReason(ER_SHM_LOST, "track dropped by buffer");
config->is_active = false;
if (srtConn){srtConn->close();}
myConn.close();
srtConn.close();
return Output::dropPushTrack(trackId, dropReason);
}
void OutTSSRT::connStats(uint64_t now, Comms::Connections &statComm){
if (!srtConn || !*srtConn){return;}
statComm.setUp(srtConn->dataUp());
statComm.setDown(srtConn->dataDown());
statComm.setTime(now - srtConn->connTime());
statComm.setPacketCount(srtConn->packetCount());
statComm.setPacketLostCount(srtConn->packetLostCount());
statComm.setPacketRetransmitCount(srtConn->packetRetransmitCount());
if (!srtConn){return;}
statComm.setUp(srtConn.dataUp());
statComm.setDown(srtConn.dataDown());
statComm.setTime(now - srtConn.connTime());
statComm.setPacketCount(srtConn.packetCount());
statComm.setPacketLostCount(srtConn.packetLostCount());
statComm.setPacketRetransmitCount(srtConn.packetRetransmitCount());
}
}// namespace Mist
bool OutTSSRT::listenMode(){
std::string tgt = config->getString("target");
return (!tgt.size() || (tgt.size() >= 6 && tgt.substr(0, 6) == "srt://" && Socket::interpretSRTMode(HTTP::URL(tgt)) == "listener"));
Socket::SRTServer server_socket;
static uint64_t sockCount = 0;
void (*oldSignal)(int, siginfo_t *,void *) = 0;
void signal_handler(int signum, siginfo_t *sigInfo, void *ignore){
server_socket.close();
if (oldSignal){
oldSignal(signum, sigInfo, ignore);
}
}
void initSRTConnection(Socket::UDPConnection & s, std::map<std::string, std::string> & arguments, bool listener = true){
Socket::SRT::libraryInit();
Socket::SRTConnection * tmpSock = new Socket::SRTConnection(s, listener?"output":"rendezvous", arguments);
if (!*tmpSock){
delete tmpSock;
return;
void handleUSR1(int signum, siginfo_t *sigInfo, void *ignore){
if (!sockCount){
INFO_MSG("USR1 received - triggering rolling restart (no connections active)");
Util::Config::is_restarting = true;
Util::logExitReason(ER_CLEAN_SIGNAL, "signal USR1, no connections");
server_socket.close();
Util::Config::is_active = false;
}else{
INFO_MSG("USR1 received - triggering rolling restart when connection count reaches zero");
Util::Config::is_restarting = true;
Util::logExitReason(ER_CLEAN_SIGNAL, "signal USR1, after disconnect wait");
}
}
// Callback for SRT-serving threads
static void callThreadCallbackSRT(void *srtPtr){
sockCount++;
Socket::SRTConnection & srtSock = *(Socket::SRTConnection*)srtPtr;
int fds[2];
pipe(fds);
Socket::Connection Sconn(fds[0], fds[1]);
HIGH_MSG("Started thread for socket %i", srtSock.getSocket());
mistOut tmp(Sconn,srtSock);
tmp.run();
HIGH_MSG("Closing thread for socket %i", srtSock.getSocket());
Sconn.close();
srtSock.close();
delete &srtSock;
sockCount--;
if (!sockCount && Util::Config::is_restarting){
server_socket.close();
Util::Config::is_active = false;
INFO_MSG("Last active connection closed; triggering rolling restart now!");
}
}
int main(int argc, char *argv[]){
Socket::SRT::libraryInit();
DTSC::trackValidMask = TRACK_VALID_EXT_HUMAN;
Util::redirectLogsIfNeeded();
Util::Config conf(argv[0]);
Util::Config::binaryType = Util::OUTPUT;
mistOut::init(&conf);
if (conf.parseArgs(argc, argv)){
if (conf.getBool("json")){
mistOut::capa["version"] = PACKAGE_VERSION;
std::cout << mistOut::capa.toString() << std::endl;
return -1;
}
if (!listener){
std::string host;
uint32_t port;
s.GetDestination(host, port);
tmpSock->connect(host, port, "output", arguments);
INFO_MSG("UDP to SRT socket conversion: %s", tmpSock->getStateStr());
}
Socket::Connection S(1, 0);
mistOut tmp(S, tmpSock);
tmp.run();
}
conf.activate();
int filelimit = conf.getInteger("filelimit");
Util::sysSetNrOpenFiles(filelimit);
void OutTSSRT::listener(Util::Config &conf, int (*callback)(Socket::Connection &S)){
// Check SRT options/arguments first
std::string target = conf.getString("target");
std::map<std::string, std::string> arguments;
if (!mistOut::listenMode() && (!target.size() || Socket::interpretSRTMode(HTTP::URL(target)) != "listener")){
Socket::Connection S(fileno(stdout), fileno(stdin));
Socket::SRTConnection tmpSock;
mistOut tmp(S, tmpSock);
return tmp.run();
}
{
struct sigaction new_action;
new_action.sa_sigaction = handleUSR1;
sigemptyset(&new_action.sa_mask);
new_action.sa_flags = 0;
sigaction(SIGUSR1, &new_action, NULL);
}
if (target.size()){
//Force acceptable option to 1 (outgoing only), since this is a push output and we can't accept incoming connections
conf.getOption("acceptable", true).append((uint64_t)1);
//Disable overriding streamname with streamid parameter on other side
allowStreamNameOverride = false;
HTTP::URL tgt(target);
std::map<std::string, std::string> arguments;
HTTP::parseVars(tgt.args, arguments);
conf.getOption("interface", true).append(tgt.host);
conf.getOption("port", true).append((uint64_t)tgt.getPort());
server_socket = Socket::SRTServer(tgt.getPort(), tgt.host, arguments, false, "output");
conf.getOption("target", true).append("");
}else{
HTTP::parseVars(conf.getString("sockopts"), arguments);
std::string opt = conf.getString("passphrase");
if (opt.size()){arguments["passphrase"] = opt;}
std::map<std::string, std::string> arguments;
server_socket = Socket::SRTServer(conf.getInteger("port"), conf.getString("interface"), arguments, false, "output");
}
uint16_t localPort;
// Either re-use socket 0 or bind a new socket
Socket::UDPConnection udpSrv;
if (Socket::checkTrueSocket(0)){
udpSrv.assimilate(0);
localPort = udpSrv.getBoundPort();
}else{
localPort = udpSrv.bind(conf.getInteger("port"), conf.getString("interface"));
if (!server_socket.connected()){
DEVEL_MSG("Failure to open socket");
return 1;
}
// Ensure socket zero is now us
if (udpSrv.getSock()){
int oldSock = udpSrv.getSock();
if (!dup2(oldSock, 0)){
udpSrv.assimilate(0);
struct sigaction new_action;
struct sigaction cur_action;
new_action.sa_sigaction = signal_handler;
sigemptyset(&new_action.sa_mask);
new_action.sa_flags = SA_SIGINFO;
sigaction(SIGINT, &new_action, &cur_action);
if (cur_action.sa_sigaction && cur_action.sa_sigaction != oldSignal){
if (oldSignal){WARN_MSG("Multiple signal handlers! I can't deal with this.");}
oldSignal = cur_action.sa_sigaction;
}
sigaction(SIGHUP, &new_action, &cur_action);
if (cur_action.sa_sigaction && cur_action.sa_sigaction != oldSignal){
if (oldSignal){WARN_MSG("Multiple signal handlers! I can't deal with this.");}
oldSignal = cur_action.sa_sigaction;
}
sigaction(SIGTERM, &new_action, &cur_action);
if (cur_action.sa_sigaction && cur_action.sa_sigaction != oldSignal){
if (oldSignal){WARN_MSG("Multiple signal handlers! I can't deal with this.");}
oldSignal = cur_action.sa_sigaction;
}
Comms::defaultCommFlags = COMM_STATUS_NOKILL;
Util::Procs::socketList.insert(server_socket.getSocket());
while (conf.is_active && server_socket.connected()){
Socket::SRTConnection S = server_socket.accept(false, "output");
if (S.connected()){// check if the new connection is valid
// spawn a new thread for this connection
tthread::thread T(callThreadCallbackSRT, (void *)new Socket::SRTConnection(S));
// detach it, no need to keep track of it anymore
T.detach();
}else{
Util::sleep(10); // sleep 10ms
}
}
if (!udpSrv){
Util::logExitReason(ER_READ_START_FAILURE, "Failure to open listening socket");
conf.is_active = false;
return;
}
Util::Config::setServerFD(0);
udpSrv.allocateDestination();
Util::Procs::socketList.insert(udpSrv.getSock());
int maxFD = udpSrv.getSock();
while (conf.is_active && udpSrv){
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(maxFD, &rfds);
struct timeval T;
T.tv_sec = 2;
T.tv_usec = 0;
int r = select(maxFD + 1, &rfds, NULL, NULL, &T);
if (r){
while(udpSrv.Receive()){
// Ignore if it's not an SRT handshake packet
if (udpSrv.data.size() >= 4 && udpSrv.data[0] == 0x80 && !udpSrv.data[1] && !udpSrv.data[2] && !udpSrv.data[3]){
bool rendezvous = false;
if (udpSrv.data.size() >= 40){
rendezvous = (!udpSrv.data[36] && !udpSrv.data[37] && !udpSrv.data[38] && !udpSrv.data[39]);
}
std::string remoteIP, localIP;
uint32_t remotePort, localPort;
udpSrv.GetDestination(remoteIP, remotePort);
udpSrv.GetLocalDestination(localIP, localPort);
INFO_MSG("SRT handshake from %s:%" PRIu32 "! Spawning child process to handle it...", remoteIP.c_str(), remotePort);
if (!fork()){
Socket::UDPConnection s(udpSrv);
udpSrv.close();
if (!s.connect()){return;}
return initSRTConnection(s, arguments, !rendezvous);
}
}
}
}
Util::Procs::socketList.erase(server_socket.getSocket());
server_socket.close();
if (conf.is_restarting){
INFO_MSG("Reloading input...");
execvp(argv[0], argv);
FAIL_MSG("Error reloading: %s", strerror(errno));
}
}
}// namespace Mist
INFO_MSG("Exit reason: %s", Util::exitReason);
Socket::SRT::libraryCleanup();
return 0;
}

View file

@ -5,29 +5,25 @@
namespace Mist{
class OutTSSRT : public TSOutput{
public:
OutTSSRT(Socket::Connection &conn, Socket::SRTConnection * _srtSock = 0);
OutTSSRT(Socket::Connection &conn, Socket::SRTConnection & _srtSock);
~OutTSSRT();
static bool listenMode();
static void listener(Util::Config &conf, int (*callback)(Socket::Connection &S));
static bool listenMode(){return !(config->getString("target").size());}
static void init(Util::Config *cfg);
void sendTS(const char *tsData, size_t len = 188);
bool isReadyForPlay(){return true;}
virtual void requestHandler();
virtual bool onFinish();
virtual void initialSeek(bool dryRun = false);
inline virtual bool keepGoing(){return config->is_active;}
protected:
virtual void connStats(uint64_t now, Comms::Connections &statComm);
virtual std::string getConnectedHost(){return srtConn?srtConn->remotehost:"";}
virtual std::string getConnectedBinHost(){return srtConn?srtConn->getBinHost():"";}
virtual std::string getConnectedHost(){return srtConn.remotehost;}
virtual std::string getConnectedBinHost(){return srtConn.getBinHost();}
virtual bool dropPushTrack(uint32_t trackId, const std::string & dropReason);
private:
HTTP::URL target;
int64_t timeStampOffset;
uint64_t lastTimeStamp;
uint64_t lastWorked;
bool pushOut;
Util::ResizeablePointer packetBuffer;
Socket::UDPConnection pushSock;
@ -35,8 +31,7 @@ namespace Mist{
TS::Assembler assembler;
bool bootMSOffsetCalculated;
Socket::SRTConnection * srtConn;
Socket::UDPConnection * udpInit;
Socket::SRTConnection & srtConn;
};
}// namespace Mist

View file

@ -1,7 +1,7 @@
[wrap-git]
directory = srt
url = https://github.com/Haivision/srt.git
revision = v1.5.3
revision = v1.5.1
patch_directory = libsrt
[provide]

View file

@ -1,9 +1,9 @@
project('SRT', 'cpp', 'c', version: '1.5.3')
project('SRT', 'cpp', 'c', version: '1.5.1')
if host_machine.system() == 'cygwin'
add_project_arguments(['-DENABLE_LOGGING=1', '-O3', '-DNDEBUG', '-DENABLE_MONOTONIC_CLOCK=1', '-DENABLE_NEW_RCVBUFFER=1', '-DENABLE_SOCK_CLOEXEC=1', '-DHAI_ENABLE_SRT=1', '-DHAI_PATCH=1', '-DHAVE_INET_PTON=1', '-DHAVE_PTHREAD_GETNAME_NP=1', '-DHAVE_PTHREAD_SETNAME_NP=1', '-DCYGWIN=1', '-DCYGWIN_USE_POSIX', '-DNDEBUG', '-DSRT_DYNAMIC', '-DSRT_ENABLE_APP_READER', '-DSRT_ENABLE_CLOSE_SYNCH', '-DSRT_ENABLE_ENCRYPTION', '-DSRT_EXPORTS', '-DSRT_VERSION="1.5.3"', '-DUSE_MBEDTLS=1', '-D_GNU_SOURCE'], language: ['cpp','c'])
add_project_arguments(['-DENABLE_LOGGING=1', '-O3', '-DNDEBUG', '-DENABLE_MONOTONIC_CLOCK=1', '-DENABLE_NEW_RCVBUFFER=1', '-DENABLE_SOCK_CLOEXEC=1', '-DHAI_ENABLE_SRT=1', '-DHAI_PATCH=1', '-DHAVE_INET_PTON=1', '-DHAVE_PTHREAD_GETNAME_NP=1', '-DHAVE_PTHREAD_SETNAME_NP=1', '-DCYGWIN=1', '-DCYGWIN_USE_POSIX', '-DNDEBUG', '-DSRT_DYNAMIC', '-DSRT_ENABLE_APP_READER', '-DSRT_ENABLE_CLOSE_SYNCH', '-DSRT_ENABLE_ENCRYPTION', '-DSRT_EXPORTS', '-DSRT_VERSION="1.5.1"', '-DUSE_MBEDTLS=1', '-D_GNU_SOURCE'], language: ['cpp','c'])
else
add_project_arguments(['-DENABLE_LOGGING=1', '-O3', '-DNDEBUG', '-DENABLE_MONOTONIC_CLOCK=1', '-DENABLE_NEW_RCVBUFFER=1', '-DENABLE_SOCK_CLOEXEC=1', '-DHAI_ENABLE_SRT=1', '-DHAI_PATCH=1', '-DHAVE_INET_PTON=1', '-DHAVE_PTHREAD_GETNAME_NP=1', '-DHAVE_PTHREAD_SETNAME_NP=1', '-DLINUX=1', '-DNDEBUG', '-DSRT_DYNAMIC', '-DSRT_ENABLE_APP_READER', '-DSRT_ENABLE_BINDTODEVICE', '-DSRT_ENABLE_CLOSE_SYNCH', '-DSRT_ENABLE_ENCRYPTION', '-DSRT_EXPORTS', '-DSRT_VERSION="1.5.3"', '-DUSE_MBEDTLS=1', '-D_GNU_SOURCE'], language: ['cpp','c'])
add_project_arguments(['-DENABLE_LOGGING=1', '-O3', '-DNDEBUG', '-DENABLE_MONOTONIC_CLOCK=1', '-DENABLE_NEW_RCVBUFFER=1', '-DENABLE_SOCK_CLOEXEC=1', '-DHAI_ENABLE_SRT=1', '-DHAI_PATCH=1', '-DHAVE_INET_PTON=1', '-DHAVE_PTHREAD_GETNAME_NP=1', '-DHAVE_PTHREAD_SETNAME_NP=1', '-DLINUX=1', '-DNDEBUG', '-DSRT_DYNAMIC', '-DSRT_ENABLE_APP_READER', '-DSRT_ENABLE_BINDTODEVICE', '-DSRT_ENABLE_CLOSE_SYNCH', '-DSRT_ENABLE_ENCRYPTION', '-DSRT_EXPORTS', '-DSRT_VERSION="1.5.1"', '-DUSE_MBEDTLS=1', '-D_GNU_SOURCE'], language: ['cpp','c'])
endif
@ -24,8 +24,7 @@ subdir('srt')
srt_src = files(
'srtcore/api.cpp',
'srtcore/buffer_snd.cpp',
'srtcore/buffer_tools.cpp',
'srtcore/buffer.cpp',
'srtcore/buffer_rcv.cpp',
'srtcore/cache.cpp',
'srtcore/channel.cpp',
@ -72,8 +71,7 @@ libsrt = library(
'srt',
sources: [srt_src, versionfile],
dependencies: [mbedtls_lib, mbedx509_lib, mbedcrypto_lib, thread_dep],
include_directories: ['srt', 'haicrypt', 'srtcore'],
install: true
include_directories: ['srt', 'haicrypt', 'srtcore']
)
srt_dep = declare_dependency(
@ -83,11 +81,3 @@ srt_dep = declare_dependency(
include_directories: include_directories('.'),
)
pkg = import('pkgconfig')
pkg.generate(libraries : libsrt,
subdirs : ['.', 'srt'],
version : '1.5.3',
name : 'srt',
filebase : 'srt',
description : 'Haivision SRT library')

View file

@ -1,14 +1,15 @@
versionfile = configure_file(format: 'cmake@', output: 'version.h', input: files('../srtcore/version.h.in'), configuration: {
'SRT_VERSION_MAJOR': 1,
'SRT_VERSION_MINOR' : 5,
'SRT_VERSION_PATCH': 3,
'CI_BUILD_NUMBER_STRING': '"1.5.3"',
'SRT_VERSION': '1.5.3',
}, install_dir: 'include/srt')
'SRT_VERSION_PATCH': 1,
'CI_BUILD_NUMBER_STRING': '"1.5.1"',
'SRT_VERSION': '1.5.1',
})
header_tgts += configure_file(copy:true, install_dir: 'include/srt', input: files('../srtcore/srt.h'), output: 'srt.h')
header_tgts += configure_file(copy:true, install_dir: 'include/srt', input: files('../srtcore/logging_api.h'), output: 'logging_api.h')
header_tgts += configure_file(copy:true, install_dir: 'include/srt', input: files('../srtcore/access_control.h'), output: 'access_control.h')
header_tgts += configure_file(copy:true, install_dir: 'include/srt', input: files('../srtcore/platform_sys.h'), output: 'platform_sys.h')
header_tgts += configure_file(copy:true, install_dir: 'include/srt', input: files('../srtcore/udt.h'), output: 'udt.h')
header_tgts += configure_file(copy:true, input: files('../srtcore/srt.h'), output: 'srt.h')
header_tgts += configure_file(copy:true, input: files('../srtcore/logging_api.h'), output: 'logging_api.h')
header_tgts += configure_file(copy:true, input: files('../srtcore/access_control.h'), output: 'access_control.h')
header_tgts += configure_file(copy:true, input: files('../srtcore/platform_sys.h'), output: 'platform_sys.h')
header_tgts += configure_file(copy:true, input: files('../srtcore/udt.h'), output: 'udt.h')