From 2e3115e6cc36bd71b951b3d3482df5a33dfa7301 Mon Sep 17 00:00:00 2001 From: TheTroll Date: Fri, 19 Mar 2010 19:15:40 +0100 Subject: Improved status --- bin/backend.php | 19 ++--------- bin/jsonapi.php | 4 +-- bin/session.php | 104 +++++++++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 91 insertions(+), 36 deletions(-) (limited to 'bin') diff --git a/bin/backend.php b/bin/backend.php index 5cca474..f312ed0 100755 --- a/bin/backend.php +++ b/bin/backend.php @@ -71,23 +71,8 @@ switch ($action) break; case ("getStreamStatus"): - $time = time(); - $session = $_REQUEST['session']; - $prevmsg = $_REQUEST['msg']; - while((time() - $time) < 29) - { - // Get current status - $status = getStreamStatus($session); - - $statusdec = json_decode($status); - if (($statusdec->message != $prevmsg) || ($statusdec->status == "ready")) - { - print $status; - break; - } - - usleep(1000); - } + $tree= getStreamStatus($_REQUEST['session'], $_REQUEST['msg']); + print $tree; break; case ("getTimers"): diff --git a/bin/jsonapi.php b/bin/jsonapi.php index b0e53cb..bb83f52 100755 --- a/bin/jsonapi.php +++ b/bin/jsonapi.php @@ -119,9 +119,9 @@ function getStreamInfo($session) return json_encode($ret); } -function getStreamStatus($session) +function getStreamStatus($session, $prevmsg) { - $ret = sessiongetstatus("session" .$session); + $ret = sessiongetstatus("session" .$session, $prevmsg); return json_encode($ret); } diff --git a/bin/session.php b/bin/session.php index bbb39e8..6940780 100755 --- a/bin/session.php +++ b/bin/session.php @@ -2,7 +2,12 @@ function sessioncreate($type, $url, $mode) { - global $httppath, $ffmpegpath, $segmenterpath, $quality; + global $httppath, $ffmpegpath, $segmenterpath, $quality, $maxencodingprocesses; + + // Check that the max number of session is not reached yet + $nbencprocess = exec("find ../ram/ -name segmenter.pid | wc | awk '{ print $1 }'"); + if ($nbencprocess >= $maxencodingprocesses) + return ""; // Get a free session $i=0; @@ -169,7 +174,7 @@ function sessiondeletesingle($session) exec ($cmd); } -function sessiongetstatus($session) +function getstreamingstatus($session) { global $maxencodingprocesses, $httppath; @@ -178,15 +183,15 @@ function sessiongetstatus($session) $path = '../ram/' .$session; // Check that session exists - if (($session == "") || !count(glob($path))) + if (!count(glob($path))) { $status['status'] = "error"; $nbencprocess = exec("find ../ram/ -name segmenter.pid | wc | awk '{ print $1 }'"); if ($nbencprocess >= $maxencodingprocesses) - $status['message'] = "Error: maximun number of sessions reached"; + $status['message'] = "Error: too much sessions"; else - $status['message'] = "Error: cannot create session"; + $status['message'] = "Error: could not create session folder"; } else { @@ -195,24 +200,51 @@ function sessiongetstatus($session) if (count(glob($path . '/*.ts')) < 2) { - $status['status'] = "wait"; - switch ($type) + if (!file_exists($path .'/segmenter.pid')) + { + $status['status'] = "error"; + $status['message'] = "Error: segmenter did not start correclty"; + } + else { - case 'tv': - $status['message'] = "Requesting live channel " .$channame; - break; - case 'rec': - $status['message'] = "Requesting recording channel " .$channame; - break; - case 'vid': - $status['message'] = "Requesting video file " .$url; - break; + $status['status'] = "wait"; + switch ($type) + { + case 'tv': + $status['message'] = "Live: requesting " .$channame .""; + break; + case 'rec': + $status['message'] = "Rec: requesting " .$channame .""; + break; + case 'vid': + $status['message'] = "Vid: requesting " .$url .""; + break; + } + + $status['message'] .= "
"; + + $status['message'] .= "
* Segmenter: "; + if (file_exists($path .'/segmenter.pid')) + $status['message'] .= "running"; + else + $status['message'] .= "stopped"; + $status['message'] .= "
* Segments: "; + $status['message'] .= count(glob($path . '/*.ts')) ."/2"; + } } else { $status['status'] = "ready"; - $status['message'] = "Broadcast ready (" .$mode .")"; + + $status['message'] = "Broadcast ready
"; + + $status['message'] .= "
* Quality: " .$mode .""; + $status['message'] .= "
* Status: "; + if (file_exists($path .'/segmenter.pid')) + $status['message'] .= "encoding..."; + else + $status['message'] .= "fully encoded"; $status['url'] = $httppath ."ram/" .$session ."/stream.m3u8"; @@ -222,6 +254,44 @@ function sessiongetstatus($session) return $status; } +function sessiongetstatus($session, $prevmsg) +{ + $time = time(); + + // Check if we need to timeout on the sesssion creation */ + $checkstart = preg_match("/requesting/", $prevmsg); + + while((time() - $time) < 29) + { + + // Get current status + $status = getstreamingstatus($session); + + // Alway return ready + if ($status['status'] == "ready") + return $status; + + // Status change + if ($status['message'] != $prevmsg) + return $status; + + // Check session creation timeout + if ($checkstart && ((time() - $time) >= 10)) + { + $status['status'] = "error"; + $status['message'] = "Session could not start"; + return $status; + } + + usleep(10000); + } + + /* Time out */ + $status['status'] = "wait"; + $status['message'] = $prevmsg; + return $status; +} + function sessiongetlist() { $sessions = array(); -- cgit v1.2.3