From 737a6402836788d359fcd99bef93ae059c085577 Mon Sep 17 00:00:00 2001 From: TheTroll Date: Wed, 17 Mar 2010 14:06:08 +0100 Subject: Session start/stop implemented --- bin/session.php | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) (limited to 'bin/session.php') 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; +} + + ?> -- cgit v1.2.3