summaryrefslogtreecommitdiff
path: root/bin/session.php
diff options
context:
space:
mode:
authorTheTroll <trolldev@gmail.com>2010-03-19 19:15:40 +0100
committerTheTroll <trolldev@gmail.com>2010-03-19 19:15:40 +0100
commit2e3115e6cc36bd71b951b3d3482df5a33dfa7301 (patch)
tree4e22d669958f05e54f97ff675ef9f9457718135f /bin/session.php
parent0e792d5728d393aed562896897d5dee1586cf990 (diff)
downloadistreamdev-2e3115e6cc36bd71b951b3d3482df5a33dfa7301.tar.gz
istreamdev-2e3115e6cc36bd71b951b3d3482df5a33dfa7301.tar.bz2
Improved status
Diffstat (limited to 'bin/session.php')
-rwxr-xr-xbin/session.php104
1 files changed, 87 insertions, 17 deletions
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'] = "<b>Error: too much sessions</b>";
else
- $status['message'] = "Error: cannot create session";
+ $status['message'] = "<b>Error: could not create session folder</b>";
}
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'] = "<b>Error: segmenter did not start correclty</b>";
+ }
+ 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'] = "<b>Live: requesting " .$channame ."</b>";
+ break;
+ case 'rec':
+ $status['message'] = "<b>Rec: requesting " .$channame ."</b>";
+ break;
+ case 'vid':
+ $status['message'] = "<b>Vid: requesting " .$url ."</b>";
+ break;
+ }
+
+ $status['message'] .= "<br>";
+
+ $status['message'] .= "<br> * Segmenter: ";
+ if (file_exists($path .'/segmenter.pid'))
+ $status['message'] .= "<i>running</i>";
+ else
+ $status['message'] .= "<i>stopped</i>";
+ $status['message'] .= "<br> * Segments: <i>";
+ $status['message'] .= count(glob($path . '/*.ts')) ."/2</i>";
+
}
}
else
{
$status['status'] = "ready";
- $status['message'] = "Broadcast ready (" .$mode .")";
+
+ $status['message'] = "<b>Broadcast ready</b><br>";
+
+ $status['message'] .= "<br> * Quality: <i>" .$mode ."</i>";
+ $status['message'] .= "<br> * Status: ";
+ if (file_exists($path .'/segmenter.pid'))
+ $status['message'] .= "<i>encoding...</i>";
+ else
+ $status['message'] .= "<i>fully encoded</i>";
$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();