Пример #1
0
     logXml("Killed Segmenter process for monitor " . $monitor);
     exit;
 } else {
     if (!strcmp($action, "chk264")) {
         /* ACTION: Simply stalls while checking for 264 file.
          * Parms: <monitor><timeout> 
          * NOTE: This will be called directly by path, so include files
          * may not be available */
         session_start();
         require_once dirname(__FILE__) . "/../includes/functions.php";
         if (!isset($_GET['monitor']) || !isset($_GET['timeout'])) {
             logXmlErr("Monitor not specified for chk264");
             exit;
         }
         $monitor = validInteger($_GET['monitor']);
         $path = getTempDir() . "/" . m3u8fname($monitor);
         /* Wait for the second sample to become available */
         $tsfile = getTempDir() . "/sample_" . $monitor . "-2.ts";
         /* Setup timeout */
         $startTime = time();
         $timeout = validInteger($_GET['timeout']);
         while (!file_exists($path) || !file_exists($tsfile)) {
             if (time() > $startTime + $timeout) {
                 logXmlErr("Timed out waiting for stream to start, exiting...");
                 kill264proc($monitor);
                 exit;
             }
             usleep(10000);
         }
         logXml("File exists, stream created after " . (time() - $startTime) . " sec");
         exit;
Пример #2
0
/** Generate the web-page presented to the viewer when using H264 */
function h264vidHtml($width, $height, $monitor, $br, $thumbsrc)
{
    function printTermLink()
    {
        $str = "H264 Streaming Launching...<br>Tap to re-load if stream fails";
        $str2 = "document.getElementById(\"loaddiv\").innerHTML = \"" . $str . "\";";
        echo $str2;
    }
    $ajaxUrl = "?view=actions&action=spawn264&&monitor=" . $monitor . "&br=" . $br;
    /* Call these two directly to bypass server blocking issues */
    $ajax2Url = "./skins/xml/views/actions.php?action=chk264&monitor=" . $monitor;
    $ajax2Url .= "&timeout=" . ZM_EYEZM_H264_TIMEOUT;
    $ajax3Url = "./skins/xml/views/actions.php?action=kill264&monitor=" . $monitor;
    ?>
<html>
<head>
	<script type="text/javascript">
	/* Called when paused or done is pressed */
	function vidAbort() {
		document.getElementById('viddiv').style.display = 'none';
		var pElement = document.getElementsByTagName('video')[0];
		var ajaxKill = new AjaxConnection("<?php 
    echo $ajax3Url;
    ?>
");
		ajaxKill.connect("cbKilled");
		pElement.stop();
		pElement.src="";
		
	}
	function reloadStreamImage() {
		var obj = document.getElementById('liveStream');
		var src = obj.src;
		var date = new Date();
		obj.src = src + '&vrand=' + date.getTime();
		return false;
	}
	/* Callback when spawn264 process is ended */
	function cbVidLoad()
	{
		reloadStreamImage();
<?php 
    printTermLink();
    ?>
	}
	function vidLoaded() {
		window.setTimeout("startVid()", 500);
	}
	function bindListeners()
	{
		var pElement = document.getElementsByTagName('video')[0];
		/* Bind abort */
		pElement.addEventListener('abort', vidAbort, false);
		pElement.addEventListener('done', vidAbort, false);
		pElement.addEventListener('ended', vidAbort, false);
		pElement.addEventListener('pause', vidAbort, false);
		pElement.addEventListener('loadstart', vidLoaded, false);
	}
	/* Callback when kill264 process is ended */
	function cbKilled()
	{
		<?php 
    printTermLink();
    ?>
	}
	/* Called after an interval from cbFileExists() */
	function loadVid()
	{
		var pElement = document.getElementById("vidcontainer");
<?php 
    echo "pElement.src=\"./temp/" . m3u8fname($monitor) . "\"\n";
    ?>
		pElement.load();
	}
	function startVid()
	{
		document.getElementById('viddiv').style.display = 'block';
		var pElement = document.getElementById("vidcontainer");
		pElement.play();
	}
	/* Callback when stream is active and ready to be played */
	function cbFileExists()
	{
		window.setTimeout("loadVid()", 500);
	}
	/* On-load triggers two requests immediately: spawn264 and chk264 */
	window.onload = function() {
		bindListeners();
		var ajax1 = new AjaxConnection("<?php 
    echo "{$ajaxUrl}";
    ?>
");
		var ajax2 = new AjaxConnection("<?php 
    echo "{$ajax2Url}";
    ?>
");
		ajax1.connect("cbVidLoad");
		/* Don't initiate file-exists since eyeZm will */
		/*ajax2.connect("cbFileExists");*/
	}
	function AjaxConnection(url) {
		this.connect = connect;
		this.url = url;
	}
	function connect(return_func) {
		this.x = new XMLHttpRequest();
		this.x.open("GET", this.url, true);
		var self = this;
		this.x.onreadystatechange = function() {
			if (self.x.readyState != 4)
				return;
			eval(return_func + '()');
			delete self.x;
		}
		this.x.send(null);
	}
	</script>
<style type="text/css">
body {
	border: 0px solid;
	margin: 0px;
	padding: 0px;
	background-color: black;
	width: <?php 
    echo $width;
    ?>
px;
	height: <?php 
    echo $height;
    ?>
px;
}
.textcl {
	text-align: center;
	font-family: Arial;
	font-size: larger;
	width: 100%;
<?php 
    echo "padding-top: " . ($height / 2 - 100) . "px;";
    echo "padding-bottom: " . ($height / 2 - 100) . "px;";
    ?>
	z-index: 2;
	position: absolute;
	top: 0px;
	left: 0px;
	height: 100%;
}
.textcl2 {
	width: auto;
	height: auto;
	background-color: black;
	padding: 5px 5px;
	margin-left: 10px;
	margin-right: 10px;
	opacity: 0.7;
}
.textcl3 {
	width: auto;
	height: auto;
	padding: 2px 2px;
	margin: auto;
	color: white;
}
.imgdiv {
	position: absolute;
	padding: 0px;
	background-color: black;
	top: 0px;
	left: 0px;
	margin: 0px;
	width: <?php 
    echo $width;
    ?>
px;
	height: <?php 
    echo $height;
    ?>
px;
	z-index: 1;
	opacity: 0.7;
}

</style>
</head>
<body>
<div id="viddiv" style="display: none;">
<?php 
    echo "<video id=\"vidcontainer\" width='" . $width . "' height='" . $height . "' />\n";
    ?>
</div>
<div id="loaddiv2" class="textcl"><div id="loaddiv3" class="textcl2">
<div id="loaddiv" class="textcl3">
Initializing H264 Stream (<?php 
    echo $br;
    ?>
)...<br>
<span style="font-size: small;"><i>This may take a few seconds</i></span>
</div>
</div></div>

<div class="imgdiv" id="imagediv">
<?php 
    outputImageStream("liveStream", $thumbsrc, $width, $height, "stream");
    ?>
</div>
</body>
</html>
<?php 
}