summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheTroll <trolldev@gmail.com>2010-03-27 19:46:30 +0100
committerTheTroll <trolldev@gmail.com>2010-03-27 19:46:30 +0100
commit275c3cd3d4532aa927945a940bb9c5b8304ba365 (patch)
tree1028da611e16c72bca64a46935cff7e42fe627bf
parent4241ab5e4b0d7a1a0165175c1067ac22edd76de8 (diff)
downloadistreamdev-275c3cd3d4532aa927945a940bb9c5b8304ba365.tar.gz
istreamdev-275c3cd3d4532aa927945a940bb9c5b8304ba365.tar.bz2
Added debug mode
-rwxr-xr-xbin/backend.php4
-rwxr-xr-xbin/debug.php19
-rwxr-xr-xbin/files.php16
-rwxr-xr-xbin/session.php36
-rwxr-xr-xbin/streaminfo.php3
-rwxr-xr-xbin/vdr.php45
-rwxr-xr-xconfig_default.php4
7 files changed, 121 insertions, 6 deletions
diff --git a/bin/backend.php b/bin/backend.php
index ad72df7..ca9917a 100755
--- a/bin/backend.php
+++ b/bin/backend.php
@@ -6,6 +6,7 @@ if (file_exists('../config.php'))
include ('../config.php');
else
include ('../config_default.php');
+include ('./debug.php');
include ('./auth.php');
include ('../getid3/getid3.php');
include ('./utils.php');
@@ -16,6 +17,9 @@ include ('./session.php');
include ('./jsonapi.php');
$action=$_REQUEST['action'];
+
+addlog("Executing action [" .$action ."]");
+
switch ($action)
{
case ("getGlobals"):
diff --git a/bin/debug.php b/bin/debug.php
new file mode 100755
index 0000000..dd24d5f
--- /dev/null
+++ b/bin/debug.php
@@ -0,0 +1,19 @@
+<?php
+function addlog($log)
+{
+ global $debug, $debugfile;
+
+ if (!$debug)
+ return ;
+
+ $newlog = date("[Y/m/d H:i:s] ") .$log ."\n";
+
+ $debughandle = fopen($debugfile, 'a');
+ if (!$debughandle)
+ return;
+ fwrite($debughandle, $newlog);
+
+ fclose($debughandle);
+}
+
+?>
diff --git a/bin/files.php b/bin/files.php
index 483eefc..64ebc7b 100755
--- a/bin/files.php
+++ b/bin/files.php
@@ -4,6 +4,8 @@ function mediagetinfostream($stream)
{
$info = array();
+ addlog("Requesting media info from " .$stream);
+
// Get info
$getid3 = new getID3;
$fileinfo = $getid3->analyze($stream);
@@ -32,6 +34,8 @@ function mediagentb($stream, $dest)
{
global $ffmpegpath;
+ addlog("Generating thumbnail for stream " .$stream ." to " .$dest);
+
// Get info
$getid3 = new getID3;
$fileinfo = $getid3->analyze($stream);
@@ -72,9 +76,11 @@ function mediagentb($stream, $dest)
}
if ($file)
- exec("cp \"" .$file ."\" ../ram/stream-tb-tmp.jpg; " .$ffmpegpath ." -y -i ../ram/stream-tb-tmp.jpg -s " .$resx ."x" .$resy ." " .$dest ." ; rm ../ram/stream-tb-tmp.jpg");
+ $cmd = "cp \"" .$file ."\" ../ram/stream-tb-tmp.jpg; " .$ffmpegpath ." -y -i ../ram/stream-tb-tmp.jpg -s " .$resx ."x" .$resy ." " .$dest ." ; rm ../ram/stream-tb-tmp.jpg";
else
- exec($ffmpegpath ." -y -i \"" .$stream ."\" -an -ss 00:00:05.00 -r 1 -vframes 1 -s " .$resx ."x" .$resy ." -f mjpeg " .$dest);
+ $cmd = $ffmpegpath ." -y -i \"" .$stream ."\" -an -ss 00:00:05.00 -r 1 -vframes 1 -s " .$resx ."x" .$resy ." -f mjpeg " .$dest;
+
+ addlog("Thumbnail generation command: " .$cmd);
if (!file_exists($dest))
exec('cp ../logos/nologoMEDIA.png ' .$dest);
@@ -107,6 +113,8 @@ function filegettype($file)
function mediagetmusicinfo($file)
{
+ addlog("Getting info for music file: " .$file);
+
// Get info
$getid3 = new getID3;
$fileinfo = $getid3->analyze($file);
@@ -133,6 +141,8 @@ function mediagetmusicinfo($file)
function generatelogo($type, $name, $dest)
{
+ addlog("Generating stream logo for file " .$name ." of type " .$type);
+
switch ($type)
{
case 'tv':
@@ -158,6 +168,8 @@ function generatelogo($type, $name, $dest)
function filesgetlisting($dir)
{
+ addlog("Listing dir: " .$dir);
+
$filelisting = array();
$folderlisting = array();
diff --git a/bin/session.php b/bin/session.php
index 886522a..172a02a 100755
--- a/bin/session.php
+++ b/bin/session.php
@@ -4,6 +4,8 @@ function sessioncreate($type, $url, $mode)
{
global $httppath, $ffmpegpath, $segmenterpath, $quality, $maxencodingprocesses;
+ addlog("Creating a new session for \"" .$url ."\" (" .$type .", " .$mode .")");
+
// Check url
if (!isurlvalid($url, $type))
return "";
@@ -11,7 +13,10 @@ function sessioncreate($type, $url, $mode)
// 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)
+ {
+ addlog("Error: Cannot create sesssion, too much sessions already encoding");
return "";
+ }
// Get a free session
$i=0;
@@ -22,6 +27,12 @@ function sessioncreate($type, $url, $mode)
break;
}
+ if ($i == 1000)
+ {
+ addlog("Error: Cannot find a new session name");
+ return "";
+ }
+
// Default
$qparams = $quality[0];
@@ -36,6 +47,7 @@ function sessioncreate($type, $url, $mode)
}
// Create session
+ addlog("Creating new session dir ram/" .$session);
exec('mkdir ../ram/' .$session);
// Extract $channame if needed
switch ($type)
@@ -74,6 +86,8 @@ function sessioncreate($type, $url, $mode)
$cmd = "";
}
+ addlog("Sending encoding command: " .$cmd);
+
$cmd = str_replace('%', '%%', $cmd);
exec ($cmd);
@@ -86,7 +100,7 @@ function sessioncreate($type, $url, $mode)
function sessiondelete($session)
{
$ret = array();
-
+
if ($session == 'all')
{
$dir_handle = @opendir('../ram/');
@@ -122,6 +136,8 @@ function sessiongetinfo($session)
{
$info = array();
+ addlog("Getting info for session " .$session);
+
// Get some info
list($type, $mode, $url, $channame) = readinfostream($session);
@@ -167,12 +183,16 @@ function sessiongetinfo($session)
function sessiondeletesingle($session)
{
+ addlog("Deleting session " .$session);
+
$ram = "../ram/" .$session ."/";
// Get segmenter PID if any
if (file_exists($ram ."segmenter.pid"))
$cmd = "/usr/local/bin/fw;kill `cat " .$ram ."segmenter.pid`; rm " .$ram ."segmenter.pid; ";
+ addlog("Sending session kill command: " .$cmd);
+
$cmd .= "rm -rf " .$ram;
exec ($cmd);
}
@@ -272,17 +292,25 @@ function sessiongetstatus($session, $prevmsg)
// Alway return ready
if ($status['status'] == "ready")
+ {
+ addlog("Returning status: " .$status['message']);
return $status;
+ }
// Status change
if ($status['message'] != $prevmsg)
+ {
+ addlog("Returning status: " .$status['message']);
return $status;
+ }
// Check session creation timeout
if ($checkstart && ((time() - $time) >= 10))
{
$status['status'] = "error";
$status['message'] = "Error: session could not start";
+
+ addlog("Returning status: " .$status['message']);
return $status;
}
@@ -292,6 +320,8 @@ function sessiongetstatus($session, $prevmsg)
/* Time out */
$status['status'] = "wait";
$status['message'] = $prevmsg;
+
+ addlog("Returning status: " .$status['message']);
return $status;
}
@@ -299,6 +329,8 @@ function sessiongetlist()
{
$sessions = array();
+ addlog("Listing sessions");
+
$dir_handle = @opendir('../ram/');
if ($dir_handle)
{
@@ -340,6 +372,8 @@ function streammusic($path, $file)
{
global $httppath;
+ addlog("Streaming music from path \"" .$path ."\"");
+
if (!isurlvalid($path, "media"))
return array();
diff --git a/bin/streaminfo.php b/bin/streaminfo.php
index fcf3310..8b935ef 100755
--- a/bin/streaminfo.php
+++ b/bin/streaminfo.php
@@ -1,3 +1,4 @@
+
<?php
/*
@@ -10,6 +11,8 @@
function writeinfostream($session, $type, $mode, $url, $channame)
{
+ addlog("Writting stream info from session " .$session ." (type=" .$type .", mode=" .$mode .", url=" .$url .", channame=" .$channame .")");
+
$ram = "../ram/" .$session ."/";
$infofile = fopen($ram ."streaminfo", 'w');
diff --git a/bin/vdr.php b/bin/vdr.php
index 72e63eb..2df3044 100755
--- a/bin/vdr.php
+++ b/bin/vdr.php
@@ -5,11 +5,15 @@ function vdrsendcommand($cmd)
{
global $svdrpip, $svdrpport;
+ addlog("Sending SVDRP command: " .$cmd);
+
$svdrp = new SVDRP($svdrpip, $svdrpport);
$svdrp->Connect();
$ret = $svdrp->Command($cmd);
$svdrp->Disconnect();
+ addlog("SVDRP command result received");
+
return $ret;
}
@@ -17,10 +21,13 @@ function vdrgetcategories()
{
global $vdrchannels;
+ addlog("VDR: vdrgetcategories()");
+
$catlist = array();
if (!file_exists($vdrchannels))
{
+ addlog("Error: can't find vdr channels file " .$vdrchannels);
print "Error: channels file not found";
return $catlist;
}
@@ -28,6 +35,7 @@ function vdrgetcategories()
$fp = fopen ($vdrchannels,"r");
if (!fp)
{
+ addlog("Error: can't open vdr channels file " .$vdrchannels);
print "Unable to open channels file";
return $catlist;
}
@@ -84,10 +92,13 @@ function vdrgetchannels($category, $now)
{
global $vdrchannels;
+ addlog("VDR: vdrgetchannels(category=" .$category .", now=" .$now .")");
+
$chanlist=array();
if (!file_exists($vdrchannels))
{
+ addlog("Error: can't find vdr channels file " .$vdrchannels);
print "Error: channels file not found";
return $chanlist;
}
@@ -95,6 +106,7 @@ function vdrgetchannels($category, $now)
$fp = fopen ($vdrchannels,"r");
if (!fp)
{
+ addlog("Error: can't open vdr channels file " .$vdrchannels);
print "Unable to open channels file";
return $chanlist;
}
@@ -200,6 +212,8 @@ function vdrgetchannels($category, $now)
function vdrgetchannum($chan)
{
+ addlog("VDR: vdrgetchannum(chan=" .$chan .")");
+
if ($_SESSION['channels'] == "")
$_SESSION['channels'] = vdrsendcommand("LSTC");
@@ -214,6 +228,8 @@ function vdrgetchannum($chan)
function vdrgetchanname($channum)
{
+ addlog("VDR: vdrgetchanname(channum=" .$channum .")");
+
$channel = vdrsendcommand("LSTC " .$channum);
// Get channel name
@@ -228,16 +244,24 @@ function vdrgetchanname($channum)
return $channame;
}
-function vdrgetchancat($chaname)
+function vdrgetchancat($channame)
{
global $vdrchannels;
+ addlog("VDR: vdrgetchancat(channame=" .$channame .")");
+
if (!file_exists($vdrchannels))
+ {
+ addlog("Error: can't find vdr channels file " .$vdrchannels);
return "";
+ }
$fp = fopen ($vdrchannels,"r");
if (!fp)
+ {
+ addlog("Error: can't open vdr channels file " .$vdrchannels);
return "";
+ }
$cat = "";
@@ -259,7 +283,7 @@ function vdrgetchancat($chaname)
$name = explode(":", $line);
$name = explode(";", $name[0]);
- if ($name[0] == $chaname)
+ if ($name[0] == $channame)
break;
}
@@ -268,6 +292,8 @@ function vdrgetchancat($chaname)
function vdrgetchaninfo($channum)
{
+ addlog("VDR: vdrgetchaninfo(channum=" .$channum .")");
+
$info = array();
$info['name'] = vdrgetchanname($channum);
@@ -280,6 +306,8 @@ function vdrgetchaninfo($channum)
function vdrgetepgat($channum, $at)
{
+ addlog("VDR: vdrgetepgat(channum=" .$channum .", at=" .$at .")");
+
$cmd = "LSTE " .$channum ." " .$at;
$epg = vdrsendcommand($cmd);
@@ -326,6 +354,8 @@ function vdrgetepgat($channum, $at)
function vdrgetfullepgat($channel, $at, $programs, $requestedday)
{
+ addlog("VDR: vdrgetfullepgat(channel=" .$channel .", at=" .$at .", program=" .$programs .", requestedday=" .$requestedday .")");
+
$chanentry = array();
$chanepg = array();
$epgout = array();
@@ -515,6 +545,8 @@ function vdrgetfullepgat($channel, $at, $programs, $requestedday)
function vdrgetepg($channel, $time, $day, $programs, $extended)
{
+ addlog("VDR: vdrgetepg(channel=" .$channel .", time=" .$time .", programs=" .$programs .", extended=" .$extented .")");
+
// Get local time (Not UTC)
$currentdate = date("U");
@@ -564,8 +596,9 @@ function vdrgetepg($channel, $time, $day, $programs, $extended)
function vdrgetrecinfo($rec)
{
+ addlog("VDR: vdrgetrecinfo(rec=" .$rec .")");
+
$infofile = $rec ."/info";
- $infofile = addcslashes($infofile, "'");
if (file_exists($infofile))
$info= file_get_contents($infofile);
else
@@ -618,6 +651,8 @@ function vdrgetrecinfo($rec)
function vdrlisttimers()
{
+ addlog("VDR: vdrlisttimers()");
+
$timerslist = array();
$timers = vdrsendcommand("LSTT");
@@ -661,6 +696,8 @@ function vdrlisttimers()
function vdrdeltimer($timer)
{
+ addlog("VDR: vdrdeltimer(timer=" .$timer .")");
+
$ret = array();
$message = vdrsendcommand("DELT " .$timer);
@@ -681,6 +718,8 @@ function vdrdeltimer($timer)
function vdrsettimer($prevtimer, $channum, $date, $stime, $etime, $desc, $active)
{
+ addlog("VDR: vdrsettimer(prevtimer=" .$prevtimer .", channum=" .$channum .", date=" .$date .", stime=" .$stime .", etime=" .$etime .", desc=" .$desc .", active=" .$active .")");
+
$ret = array();
if ($prevtimer == "")
diff --git a/config_default.php b/config_default.php
index fa9a4da..621791e 100755
--- a/config_default.php
+++ b/config_default.php
@@ -4,6 +4,10 @@
$enablemediavideo=1; // Video files streaming
$enablemediaaudio=1; // Audio files streaming
+ // Debug mode
+ $debug=0; // Debug all action
+ $debugfile="/tmp/istreamdev.log"; // Debug file
+
// Http configuration
$user = 'istreamdev'; // Login
$pass = 'iguest'; // Password