Documentation is available at VLCServer.class.php
- <?php
- class VLCServer {
- /**
- * @access private
- * @var array
- */
- private $lDimensions;
- /**
- * @access private
- * @var string
- */
- private $lChannel;
- /**
- * @access private
- * @var string
- */
- private $lAudioCodec;
- /**
- * @access private
- * @var string
- */
- private $lVideoCodec;
- /**
- * @access private
- * @var int
- */
- private $lFPS;
- /**
- * @access private
- * @var string
- */
- private $lStreamType;
- /**
- * @access private
- * @var int
- */
- private $lBitrate;
- /**
- * @access private
- * @var int
- */
- private $lVolume;
- /**
- * @access private
- * @var int
- */
- private $lScale;
- /**
- * @access private
- * @var string
- */
- private $lVLCExecutable;
- /**
- * @access private
- * @var int
- */
- private $lChannels;
- /**
- * @access private
- * @var string
- */
- private $lEnigmaVersion;
- /**
- * Constructor. This creates a VLC Server object. Some defaults are already set. These are: volume, scale and audio channels. It alse detects when it is running on Windows or Linux.
- * @return VLCServer
- */
- function __construct($pEnigmaVersion = "enigma2") {
- $this->lDimensions = array();
- $this->lVLCExecutable = Settings::getVLCLocation();
- $this->lVolume = 60;
- $this->lScale = "0.50";
- $this->lChannels = 2;
- $this->setEnigmaVersion($pEnigmaVersion);
- }
- /**
- * Set the Enigma type. Valid values are 'enigma1' and 'enigma2'.
- * @param string $pType
- * @return boolean
- */
- public function setEnigmaVersion($pType) {
- if ( ($pType == trim($pType)) == "") return false;
- switch ($pType) {
- case "enigma1":
- $this->lEnigmaVersion = "enigma1";
- break;
- case "enigma2";
- $this->lEnigmaVersion = "enigma2";
- break;
- default:
- return false;
- break;
- }
- return true;
- }
- /**
- * Set the VLC Server encoding dimentions. This is the size of the re-encoded stream.
- * @param string $pSizes
- */
- public function setDimentions($pSizes) {
- $pSizes = explode("x",$pSizes);
- if (is_array($pSizes) && sizeof($pSizes) == 2 && is_numeric($pSizes[0]) && is_numeric($pSizes[1])) {
- $this->lDimensions = $pSizes;
- }
- }
- /**
- * Set the VLC Server source channel. This is the ID of a Channel Object.
- * @param string $pChannel
- */
- public function setChannel($pChannel) {
- // pChannel trimmed and than not empty, set pChannel;
- if ( ($pChannel = trim($pChannel)) != "") $this->lChannel = $pChannel;
- }
- /**
- * Set the VLC Server encoding audio codec. This sets the output audio codec.
- * @param string $pCodec
- */
- public function setAudioCodec($pCodec) {
- if ( ($pCodec = trim($pCodec)) != "") $this->lAudioCodec = $pCodec;
- }
- /**
- * Set the VLC Server encoding video codec. This sets the output video codec.
- * @param string $pCodec
- */
- public function setVideoCodec($pCodec) {
- if ( ($pCodec = trim($pCodec)) != "") $this->lVideoCodec = $pCodec;
- }
- /**
- * Set the VLC Server frames per second.
- * @param string $pFPS
- */
- public function setFPS($pFPS) {
- if ( is_numeric($pFPS = trim($pFPS)) ) $this->lFPS = $pFPS;
- }
- /**
- * Set the VLC Server stream type. This sets also the streamplayer type when you need the embedded player.
- * @param string $pStreamType
- */
- public function setStreamType($pStreamType) {
- if ( ($pStreamType = trim($pStreamType)) != "") $this->lStreamType = $pStreamType;
- }
- /**
- * Set the VLC Server streaming video bitrate. The higher the bitrate, the better the image qualitiy will be.
- * @param string $pRate
- */
- public function setBitrate($pRate) {
- if ( is_numeric($pRate = trim($pRate)) ) $this->lBitrate = $pRate;
- }
- /**
- * Start the VLC Server by executing the vlc command line. You have to set all options before starting this server. If the server is started, you should be able to connect to it and watch some tv.
- * @param boolean $pDebug
- * @return string
- */
- public function startServer($pDebug = 0) {
- $this->stopServer();
- switch ($this->lEnigmaVersion) {
- case "enigma1":
- //Zap first
- $lZapUrl = Settings::getStreamProtocol() . "://" . Settings::getDreamboxIP() . "/cgi-bin/zapTo?path=". $this->lChannel ."&curBouquet=0&curChannel=0";
- @fopen($lZapUrl,"r");
- sleep(1);
- $lStreamUrl = "/video.m3u";
- break;
- case "enigma2":
- $lStreamUrl = ":8001/" . $this->lChannel;
- break;
- }
- $lCMD = $this->lVLCExecutable . " -I dummy " . Settings::getStreamProtocol() . "://" . Settings::getDreamboxIP() . $lStreamUrl;
- if ($this->lStreamType == "rtp") $lCMD .= " --rtsp-tcp";
- $lCMD .= " --sout=";
- $lTransCode = "#transcode{acodec=". $this->lAudioCodec .",vcodec=". $this->lVideoCodec .",ab=64,vb=". $this->lBitrate . ",scale=". $this->lScale .",deinterlace,fps=". $this->lFPS .",channels=". $this->lChannels .",width=". $this->lDimensions[0] .",height=". $this->lDimensions[1];
- if($this->lStreamType == "rtp") {
- $lTransCode .= "}:rtp{port=". Settings::getVLCStreamPort() .",sdp=rtsp://". Settings::getVLCLanIP() .":". Settings::getVLCControlPort() ."/restream.sdp}";
- } else {
- switch ($this->lVideoCodec) {
- case "ASFH":
- $mux = "asfh";
- break;
- case "FLV1":
- $mux = "ffmpeg{mux=flv}";
- $lTransCode .= ",samplerate=44100";
- break;
- default:
- $mux = "ts";
- break;
- }
- if ($this->lStreamType == "mmsh") {
- $mux = "asfh";
- }
- $lTransCode .= "}:std{access=". $this->lStreamType .",mux=". $mux .",url=". Settings::getVLCLanIP() .":". Settings::getVLCStreamPort() . "} ";
- }
- if (VLCServer::isLinux()) $lTransCode = "\"" . $lTransCode . "\"";
- $lCMD .= $lTransCode;
- if (VLCServer::isLinux()) {
- $lCMD .= " >>/dev/null 2>>/dev/null &";
- shell_exec($lCMD);
- } else {
- $WshShell = new COM("WScript.Shell");
- $oExec = $WshShell->Run($lCMD, 7, false);
- }
- if ($pDebug == 1) return $lCMD;
- }
- /**
- * Stop the VLC Server. This is handy to spare some system resources.
- */
- public function stopServer() {
- if (VLCServer::isLinux()) {
- $lCMD = "killall -Iq vlc";
- shell_exec($lCMD);
- } else {
- // But you need to download this one: http://www.beyondlogic.org/solutions/processutil/processutil.htm
- exec("c:\process.exe -k vlc.exe");
- }
- }
- /**
- * Check if the server is still running.
- * @return boolean
- */
- public function isServerRunning() {
- if (VLCServer::isLinux()) {
- $lData = shell_exec("ps fax | grep vlc | grep -v grep | grep " . Settings::getDreamboxIP());
- return (strlen($lData) > 0);
- } else {
- // TODO Windows process check
- }
- }
- /**
- * Get the streaming url. This is based on the protocols and ip addresses.
- * @return string
- */
- public function getStreamingUrl() {
- $lStreamPort = Settings::getVLCWanStreamPort();
- $lStreamProtocol = Settings::getStreamProtocol();
- if ($this->lStreamType == "rtp") {
- $lStreamPort = Settings::getVLCControlPort() . "/restream.sdp";
- $lStreamProtocol = "rtsp";
- } elseif ($this->lStreamType == "mmsh") {
- $lStreamProtocol = "mms";
- } elseif ($this->lVideoCodec == "FLV") {
- $lStreamPort .= "/stream.flv";
- } elseif ($this->lStreamType == "udp") {
- $lStreamProtocol = "udp";
- }
- return $lStreamProtocol . "://" . Settings::getVLCWanIP() . ":". $lStreamPort;
- }
- /**
- * Get the HTML code for the embeded player. This code is based on the chosen protocols, and encoding settings.
- * @return string
- */
- public function getEmbeddedPlayer() {
- $lReturnValue = "";
- $lStreamPort = Settings::getVLCWanStreamPort();
- $lStreamProtocol = Settings::getStreamProtocol();
- if ($this->lStreamType == "rtp") {
- $lStreamPort = Settings::getVLCControlPort() . "/restream.sdp";
- $lStreamProtocol = "rtsp";
- } elseif ($this->lStreamType == "mmsh") {
- $lStreamProtocol = "mms";
- }
- if ($this->lStreamType == "mmsh") {
- $lReturnValue = "<object id = \"MediaPlayer\" width = ". $this->lDimensions[0] ." height = ". ($this->lDimensions[1] + 68 )." classid = \"CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" codebase = \"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902\" standby = \"Starting restreaming... please wait\" type = \"application/x-oleobject\">\n";
- $lReturnValue .= "<param name = \"FileName\" value = \"" . $this->getStreamingUrl() ." \">\n";
- $lReturnValue .= "<param name = \"animationatStart\" value = \"true\">\n";
- $lReturnValue .= "<param name = \"transparentatStart\" value = \"true\">\n";
- $lReturnValue .= "<param name = \"autoStart\" value = \"true\">\n";
- $lReturnValue .= "<param name = \"showControls\" value = \"1\">\n";
- $lReturnValue .= "<param name = \"ShowDisplay\" value = \"0\">\n";
- $lReturnValue .= "<param name = \"ShowStatusBar\" value = \"1\">\n";
- $lReturnValue .= "<embed type=\"application/x-mplayer2\" pluginspage = \"http://www.microsoft.com/Windows/MediaPlayer/\" src=" . $this->getStreamingUrl() . " name=\"MediaPlayer\" width = ". $this->lDimensions[0] ." height = ". ($this->lDimensions[1] + 68 ) ." autostart = \"true\" showcontrols = \"1\" showdisplay = \"0\" showstatusbar = \"1\" style=\"z-index: 1;\"></embed>\n";
- $lReturnValue .= "</object>\n";
- } elseif ($this->lVideoCodec == "FLV1") {
- $lReturnValue = "var so = new SWFObject('flash/flvplayer.swf','player','300','210','8','#ffffff');
- so.addParam('allowfullscreen','true');
- so.addVariable('file','" . $this->getStreamingUrl() . "');
- so.write('PlayerDiv');";
- } elseif (Utils::isFF()) {
- $lReturnValue = "<embed type=\"application/x-vlc-plugin\" name=\"vlc\" autoplay=\"yes\" loop=\"no\" height=\"". $this->lDimensions[1] ."\" width=\"". $this->lDimensions[0] ."\" target=\"". $this->getStreamingUrl() ."\" id=\"vlcplayer\" />";
- } else {
- $lReturnValue = "ERROR";
- }
- return trim($lReturnValue);
- }
- /**
- * Get the external stream data. This will return a m3u playlist file of a asx file for Media Player. This is based on the input streaming url.
- * @param string $pStreamingUrl
- * @return string
- */
- public function openExternal($pStreamingUrl) {
- // Start the current running stream in an external player
- if ((stripos($pStreamingUrl,"http://") !== false) || (stripos($pStreamingUrl,"rtsp://") !== false) || (stripos($pStreamingUrl,"udp://") !== false)) {
- header("Content-type: application/octet-stream");
- header("Content-Disposition: attachment; filename=externalstream.m3u");
- header("Content-Transfer-Encoding: binary");
- echo $pStreamingUrl;
- }elseif(stripos($pStreamingUrl,"mms://") !== false) {
- header("Content-type: video/x-ms-asf");
- header("Content-Disposition: attachment; filename=externalstream.asx");
- echo "<Asx Version = \"3.0\" >
- <Title >" . Settings::getProgramName() . "</Title>
- <Entry>
- <Param Name = \"MediaType\" Value = \"video\" />
- <Param Name = \"SourceURL\" Value = \"" . $pStreamingUrl . "\" />
- <Param Name = \"type\" Value = \"broadcast\" />
- <Title >" . Settings::getProgramName() . "</Title>
- <Ref href = \"" . $pStreamingUrl . "\"/>
- </Entry>
- </Asx>";
- }
- exit;
- }
- /**
- * Check if we are running on Linux.
- * @return boolean
- */
- static private function isLinux() {
- return stripos(php_uname(),"Linux") !== false;
- }
- }
- ?>
Documentation generated on Sat, 19 Jan 2008 12:56:21 +0100 by phpDocumentor 1.3.0RC3