summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheTroll <trolldev@gmail.com>2010-04-02 15:59:49 +0200
committerTheTroll <trolldev@gmail.com>2010-04-02 15:59:49 +0200
commita0198dc43526022bd5ab3e768ee4ad518982c5df (patch)
tree3b46d8213532e603651c506beb6fabb2787c866a
parent45938e824d755cb4beddca176c81e692029d981e (diff)
downloadistreamdev-a0198dc43526022bd5ab3e768ee4ad518982c5df.tar.gz
istreamdev-a0198dc43526022bd5ab3e768ee4ad518982c5df.tar.bz2
Improved status reporting
-rwxr-xr-xbin/istream.sh26
-rw-r--r--bin/session.php61
-rw-r--r--bin/utils.php19
3 files changed, 74 insertions, 32 deletions
diff --git a/bin/istream.sh b/bin/istream.sh
index b8535c7..bd08092 100755
--- a/bin/istream.sh
+++ b/bin/istream.sh
@@ -55,23 +55,29 @@ fi
$FFMPEGPREFIX | $FFPATH -i "$STREAM" -deinterlace -f mpegts -acodec libmp3lame -ab $ARATE -ac 2 -s $XY -vcodec libx264 -b $VRATE -flags +loop \
-cmp \+chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -keyint_min 25 \
-sc_threshold 40 -i_qfactor 0.71 -bt $VRATE -maxrate $VRATE -bufsize $VRATE -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 \
- -qmin 10 -qmax 51 -qdiff 4 -level 30 -g 30 -async 2 -threads 4 - 2>$FFMPEGLOG >./fifo) &
+ -qmin 10 -qmax 51 -qdiff 4 -level 30 -g 30 -async 2 -threads 4 - 2>$FFMPEGLOG 1>./fifo) &
# Store ffmpeg pid
-PID=$!
-if [ ! -z "$PID" ]
+FFPID=$!
+if [ ! -z "$FFPID" ]
then
- 2>/dev/null echo `\ps ax --format pid,ppid | grep "$PID$" | awk {'print $1'}` > ./ffmpeg.pid
+ SPID=`\ps ax --format pid,ppid | grep "$FFPID$" | awk {'print $1'}`;
+ if [ ! -z "$SPID" ]
+ then
+ 2>/dev/null echo $SPID > ./ffmpeg.pid
+ fi
fi
# Now start segmenter
-(trap "rm -f ./segmenter.pid" EXIT HUP INT TERM ABRT; 2>/dev/null $SEGMENTERPATH ./fifo $SEGDUR stream stream.m3u8 $HTTP_PATH$SESSION/ $SEGWIN) &
+(trap "rm -f ./segmenter.pid; cat ./fifo" EXIT HUP INT TERM ABRT; 2>/dev/null $SEGMENTERPATH ./fifo $SEGDUR stream stream.m3u8 $HTTP_PATH$SESSION/ $SEGWIN) &
# Store segmenter pid
-PID=$!
-if [ ! -z "$PID" ]
+SEGPID=$!
+if [ ! -z "$SEGPID" ]
then
- 2>/dev/null echo `\ps ax --format pid,ppid | grep "$PID$" | awk {'print $1'}` > ./segmenter.pid
+ SPID=`\ps ax --format pid,ppid,cmd | grep "$SEGPID$" | grep segmenter | awk {'print $1'}`;
+ if [ ! -z "$SPID" ]
+ then
+ 2>/dev/null echo $SPID > ./segmenter.pid
+ fi
fi
-
-
diff --git a/bin/session.php b/bin/session.php
index e52b6e4..e854058 100644
--- a/bin/session.php
+++ b/bin/session.php
@@ -197,11 +197,11 @@ function sessiondeletesingle($session)
$cmd = "";
// First kill ffmpeg
- if (file_exists($ram ."ffmpeg.pid"))
+ if (is_pid_running($ram ."ffmpeg.pid"))
$cmd .= " kill `cat " .$ram ."ffmpeg.pid`; rm " .$ram ."ffmpeg.pid; ";
// Then kill segmenter
- if (file_exists($ram ."segmenter.pid"))
+ if (is_pid_running($ram ."segmenter.pid"))
$cmd .= " kill `cat " .$ram ."segmenter.pid`; rm " .$ram ."segmenter.pid; ";
addlog("Sending session kill command: " .$cmd);
@@ -236,10 +236,10 @@ function getstreamingstatus($session)
if (count(glob($path . '/*.ts')) < 2)
{
- if (!file_exists($path .'/segmenter.pid'))
+ if (!is_pid_running($path .'/ffmpeg.pid') || !is_pid_running($path .'/segmenter.pid'))
{
$status['status'] = "error";
- $status['message'] = "<b>Error: segmenter did not start correclty</b>";
+ $status['message'] = "<b>Error: streaming could not start correclty</b>";
}
else
{
@@ -256,25 +256,23 @@ function getstreamingstatus($session)
$status['message'] = "<b>Vid: requesting " .$url ."</b>";
break;
}
+ }
- $status['message'] .= "<br>";
+ $status['message'] .= "<br>";
-
- $status['message'] .= "<br> * FFmpeg: ";
- if (file_exists($path .'/ffmpeg.pid'))
- $status['message'] .= "<i>running</i>";
- else
- $status['message'] .= "<i>stopped</i>";
- $status['message'] .= "<br> * Segmenter: ";
- if (file_exists($path .'/segmenter.pid'))
- {
- $status['message'] .= "<i>running</i> (";
- $status['message'] .= count(glob($path . '/*.ts')) ."/2)</i>";
- }
- else
- $status['message'] .= "<i>stopped</i>";
-
+ $status['message'] .= "<br> * FFmpeg: ";
+ if (is_pid_running($path .'/ffmpeg.pid'))
+ $status['message'] .= "<i>running</i>";
+ else
+ $status['message'] .= "<i>stopped</i>";
+ $status['message'] .= "<br> * Segmenter: ";
+ if (is_pid_running($path .'/segmenter.pid'))
+ {
+ $status['message'] .= "<i>running</i> (";
+ $status['message'] .= count(glob($path . '/*.ts')) ."/2)</i>";
}
+ else
+ $status['message'] .= "<i>stopped</i>";
}
else
{
@@ -284,7 +282,7 @@ function getstreamingstatus($session)
$status['message'] .= "<br> * Quality: <i>" .$mode ."</i>";
$status['message'] .= "<br> * Status: ";
- if (file_exists($path .'/segmenter.pid'))
+ if (is_pid_running($path .'/segmenter.pid'))
$status['message'] .= "<i>encoding...</i>";
else
$status['message'] .= "<i>fully encoded</i>";
@@ -330,6 +328,25 @@ function sessiongetstatus($session, $prevmsg)
$status['status'] = "error";
$status['message'] = "Error: session could not start";
+
+ $status['message'] .= "<br>";
+
+ $status['message'] .= "<br> * FFmpeg: ";
+
+ if (is_pid_running('../ram/' .$session .'/ffmpeg.pid'))
+ $status['message'] .= "<i>running</i>";
+ else
+ $status['message'] .= "<i>stopped</i>";
+ $status['message'] .= "<br> * Segmenter: ";
+
+ if (is_pid_running('../ram/' .$session .'/segmenter.pid'))
+ {
+ $status['message'] .= "<i>running</i> (";
+ $status['message'] .= count(glob('../ram/' .$session .'/*.ts')) ."/2)</i>";
+ }
+ else
+ $status['message'] .= "<i>stopped</i>";
+
addlog("Returning status: " .$status['message']);
return $status;
}
@@ -382,7 +399,7 @@ function sessiongetlist()
$newsession['name'] = "Error: " .$newsession['name'];
// Check if encoding
- if (file_exists('../ram/' .$session .'/segmenter.pid') && ($status['status'] != "error"))
+ if (is_pid_running('../ram/' .$session .'/segmenter.pid') && ($status['status'] != "error"))
$newsession['encoding'] = 1;
else
$newsession['encoding'] = 0;
diff --git a/bin/utils.php b/bin/utils.php
index 2324032..a1489c8 100644
--- a/bin/utils.php
+++ b/bin/utils.php
@@ -182,4 +182,23 @@ if (!function_exists('json_encode'))
}
}
+function is_pid_running($pidfile)
+{
+ // Check file
+ if (!file_exists($pidfile))
+ return 0;
+
+ // Check if pid has a pid inside
+ exec('cat ' .$pidfile, $output);
+ if (!is_numeric($output[0]))
+ return 0;
+
+ // Check if pid is running
+ exec('ps `cat ' .$pidfile .'`', $output);
+ if(count($output) < 2)
+ return 0;
+
+ return 1;
+}
+
?>