From a0198dc43526022bd5ab3e768ee4ad518982c5df Mon Sep 17 00:00:00 2001 From: TheTroll Date: Fri, 2 Apr 2010 15:59:49 +0200 Subject: Improved status reporting --- bin/istream.sh | 26 ++++++++++++++---------- bin/session.php | 61 ++++++++++++++++++++++++++++++++++++--------------------- bin/utils.php | 19 ++++++++++++++++++ 3 files changed, 74 insertions(+), 32 deletions(-) (limited to 'bin') 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'] = "Error: segmenter did not start correclty"; + $status['message'] = "Error: streaming could not start correclty"; } else { @@ -256,25 +256,23 @@ function getstreamingstatus($session) $status['message'] = "Vid: requesting " .$url .""; break; } + } - $status['message'] .= "
"; + $status['message'] .= "
"; - - $status['message'] .= "
* FFmpeg: "; - if (file_exists($path .'/ffmpeg.pid')) - $status['message'] .= "running"; - else - $status['message'] .= "stopped"; - $status['message'] .= "
* Segmenter: "; - if (file_exists($path .'/segmenter.pid')) - { - $status['message'] .= "running ("; - $status['message'] .= count(glob($path . '/*.ts')) ."/2)"; - } - else - $status['message'] .= "stopped"; - + $status['message'] .= "
* FFmpeg: "; + if (is_pid_running($path .'/ffmpeg.pid')) + $status['message'] .= "running"; + else + $status['message'] .= "stopped"; + $status['message'] .= "
* Segmenter: "; + if (is_pid_running($path .'/segmenter.pid')) + { + $status['message'] .= "running ("; + $status['message'] .= count(glob($path . '/*.ts')) ."/2)"; } + else + $status['message'] .= "stopped"; } else { @@ -284,7 +282,7 @@ function getstreamingstatus($session) $status['message'] .= "
* Quality: " .$mode .""; $status['message'] .= "
* Status: "; - if (file_exists($path .'/segmenter.pid')) + if (is_pid_running($path .'/segmenter.pid')) $status['message'] .= "encoding..."; else $status['message'] .= "fully encoded"; @@ -330,6 +328,25 @@ function sessiongetstatus($session, $prevmsg) $status['status'] = "error"; $status['message'] = "Error: session could not start"; + + $status['message'] .= "
"; + + $status['message'] .= "
* FFmpeg: "; + + if (is_pid_running('../ram/' .$session .'/ffmpeg.pid')) + $status['message'] .= "running"; + else + $status['message'] .= "stopped"; + $status['message'] .= "
* Segmenter: "; + + if (is_pid_running('../ram/' .$session .'/segmenter.pid')) + { + $status['message'] .= "running ("; + $status['message'] .= count(glob('../ram/' .$session .'/*.ts')) ."/2)"; + } + else + $status['message'] .= "stopped"; + 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; +} + ?> -- cgit v1.2.3