diff --git a/lib/class/channel.class.php b/lib/class/channel.class.php index bdc03a49..f79ea4d3 100644 --- a/lib/class/channel.class.php +++ b/lib/class/channel.class.php @@ -472,7 +472,7 @@ class Channel extends database_object implements media, library_item fclose($this->transcoder['stderr']); } fclose($this->transcoder['handle']); - proc_terminate($this->transcoder['process']); + Stream::kill_process($this->$transcoder); $this->media = null; $this->transcoder = null; diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php index 0aa95945..3b725779 100644 --- a/lib/class/stream.class.php +++ b/lib/class/stream.class.php @@ -256,8 +256,7 @@ class Stream // Windows doesn't like to provide stderr as a pipe $descriptors[2] = array('pipe', 'w'); $cmdPrefix = "exec "; - } - else + } else $cmdPrefix = "start /B "; @@ -277,6 +276,21 @@ class Stream return array_merge($parray, $settings); } + public static function kill_process($transcoder) + { + $status = proc_get_status($transcoder['process']); + if ($status['running'] == true) { + $pid = $status['pid']; + debug_event('stream', 'Stream process about to be killed. pid:' . $pid, 1); + + (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') ? exec("taskkill /F /T /PID $pid") : exec("kill -9 $pid"); + + proc_close($transcoder['process']); + } else { + debug_event('stream', 'Process is not running, kill skipped.', 5); + } + } + /** * validate_bitrate * this function takes a bitrate and returns a valid one diff --git a/lib/class/waveform.class.php b/lib/class/waveform.class.php index 4731c055..bf0ac7f2 100644 --- a/lib/class/waveform.class.php +++ b/lib/class/waveform.class.php @@ -111,7 +111,8 @@ class Waveform fclose($fp); fclose($tfp); - proc_terminate($transcoder['process']); + + Stream::kill_process($transcoder); $waveform = self::create_waveform($tmpfile); //$waveform = self::create_waveform("C:\\tmp\\test.wav"); diff --git a/play/index.php b/play/index.php index acd01b5f..148e8b13 100644 --- a/play/index.php +++ b/play/index.php @@ -678,20 +678,7 @@ if ($bytes_streamed < $stream_size && (connection_status() == 0)) { if ($transcode && isset($transcoder)) { fclose($fp); - function kill($pid){ - return stripos(php_uname('s'), 'win')>-1 ? exec("taskkill /F /T /PID $pid") : exec("kill -9 $pid"); - } - - $status = proc_get_status($transcoder['process']); - if($status['running'] == true) - { - $pid = $status['pid']; - debug_event('play', 'Stream process about to be killed. pid:'.$pid, 1); - - kill($pid); - - proc_close($transcoder['process']); - } + Stream::kill_process($transcoder); } else { fclose($fp); }