summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/backend.php48
-rwxr-xr-xbin/jsonapi.php24
-rwxr-xr-xbin/session.php93
3 files changed, 138 insertions, 27 deletions
diff --git a/bin/backend.php b/bin/backend.php
index eed0cfd..49c2c66 100755
--- a/bin/backend.php
+++ b/bin/backend.php
@@ -52,10 +52,9 @@ switch ($action)
break;
case ("getStreamInfo"):
- $session = $_REQUEST['session'];
- $tree = file_get_contents("textfiles/getStreamInfo-" . $session . ".txt");
- print $tree;
- break;
+ $tree = getStreamInfo($_REQUEST['session']);
+ print $tree;
+ break;
case ("startBroadcast"):
$tree = startBroadcast($_REQUEST['type'], $_REQUEST['url'], $_REQUEST['mode']);
@@ -63,32 +62,29 @@ switch ($action)
break;
case ("stopBroadcast"):
- $tree = file_get_contents("textfiles/stopBroadcast.txt");
- print $tree;
- break;
+ $tree = stopBroadcast($_REQUEST['session']);
+ print $tree;
+ break;
case ("getStreamStatus"):
- $time = time();
- $session = $_REQUEST['session'];
- $prevmsg = $_REQUEST['msg'];
- while((time() - $time) < 29)
- {
- $tree = file_get_contents("textfiles/getStreamStatus.txt");
- $data = json_decode($tree);
- $message = $data->message;
- $status = $data->status;
- if ($prevmsg != $message) {
- print $tree;
- break;
- }
- else if ($status == "ready")
+ $time = time();
+ $session = $_REQUEST['session'];
+ $prevmsg = $_REQUEST['msg'];
+ while((time() - $time) < 29)
{
- print $tree;
- break;
+ // Get current status
+ $status = getStreamStatus($session);
+
+ $statusdec = json_decode($status);
+ if (($statusdec->message != prevmsg) || ($statusdec->status == "ready"))
+ {
+ print $status;
+ break;
+ }
+
+ usleep(1000);
}
- usleep(1000);
- }
- break;
+ break;
case ("getTimers"):
$tree = file_get_contents("textfiles/getTimers.txt");
diff --git a/bin/jsonapi.php b/bin/jsonapi.php
index 35ec623..a8aa82e 100755
--- a/bin/jsonapi.php
+++ b/bin/jsonapi.php
@@ -73,5 +73,29 @@ function startBroadcast($type, $url, $mode)
return json_encode($ret);
}
+function stopBroadcast($session)
+{
+ $ret = array();
+
+ $ret = sessiondelete($session);
+
+ return json_encode($ret);
+}
+
+function getStreamInfo($session)
+{
+ $ret = array();
+
+ $ret['stream'] = sessiongetinfo($session);
+
+ return json_encode($ret);
+}
+
+function getStreamStatus($session)
+{
+ $ret = sessiongetstatus($session);
+
+ return json_encode($ret);
+}
?>
diff --git a/bin/session.php b/bin/session.php
index 8b998d2..e575a5b 100755
--- a/bin/session.php
+++ b/bin/session.php
@@ -78,6 +78,8 @@ function sessioncreate($type, $url, $mode)
function sessiondelete($session)
{
+ $ret = array();
+
if ($session == 'all')
{
$dir_handle = @opendir('../ram/');
@@ -100,9 +102,44 @@ function sessiondelete($session)
}
}
else
- return sessiondeletesingle($session);
+ sessiondeletesingle($session);
+
+ $ret['status'] = "ok";
+ $ret['message'] = "Successfully stopped broadcast";
+
+ return $ret;
+
+}
+
+function sessiongetinfo($session)
+{
+ $info = array();
+
+ // Get some info
+ list($type, $mode, $url, $channame) = readinfostream($session);
+
+ // Fill common info
+ $info['session'] = $session;
+ $info['type'] = $type;
+ $info['mode'] = $mode;
+
+ // Type info
+ switch ($type)
+ {
+ case 'tv':
+ $info['channel'] = $channame;
+ break;
+ case 'rec':
+ $info['channel'] = $channame;
+ break;
+ case 'vid':
+ break;
+ }
+
+ return $info;
}
+
function sessiondeletesingle($session)
{
$ram = "../ram/" .$session ."/";
@@ -115,4 +152,58 @@ function sessiondeletesingle($session)
exec ($cmd);
}
+function sessiongetstatus($session)
+{
+ global $maxencodingprocesses, $httppath;
+
+ $status = array();
+
+ $path = '../ram/' .$session;
+
+ // Check that session exists
+ if (($session == "") || !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";
+ else
+ $status['message'] = "Error: cannot create session";
+ }
+ else
+ {
+ // Get stream info
+ list($type, $mode, $url, $channame) = readinfostream($session);
+
+ if (count(glob($path . '/*.ts')) < 2)
+ {
+ $status['status'] = "wait";
+ switch ($type)
+ {
+ 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;
+ }
+ }
+ else
+ {
+ $status['status'] = "ready";
+ $status['message'] = $mode ." Broadcast ready";
+
+ $status['url'] = $httppath ."ram/" .$session ."/stream.m3u8";
+
+ }
+ }
+
+ return $status;
+}
+
+
?>