/** * Invoke remote execution of the streamer thread with the streamer engine job * @param X_Streamer_Engine $engine * @return boolean true if thread move to running state, false otherwise * This could happen if streamer job failed really fast (wrong params?) * or if the job is appended between the last waiting tick and the shutdown * of the thread */ public function start(X_Streamer_Engine $engine) { // check if streamer is alive (if it is, shutdown it) if ($this->isStreaming()) { $this->stop(); } // get standard params overloaded by engine's ones, if any $params = array_merge(array('streamerId' => $engine->getId(), 'streamerClass' => get_class($engine)), $engine->getRunnableParams()); // then wake up the thread X_Threads_Manager::instance()->appendJob($engine->getRunnableClass(), $params, self::THREAD_ID); // sleep 1 second, then check for 10 times and watch if something is working sleep(1); $i = 10; $threadInfo = X_Threads_Manager::instance()->getThreadInfo(self::THREAD_ID); while ($threadInfo->getState() != X_Threads_Thread_Info::RUNNING && $i > 0) { // this is a very special case: i appended the job just between // the last waiting tick and the stop of the thread, // so the thread manager tought he can simple append the message, // but for real the thread go in stop state (so it haven't read the // read the message) // to avoid this, i just append a renew message, so the thread // move from stop -> run stream job -> stop (if any) sleep(1); $threadInfo = X_Threads_Manager::instance()->getThreadInfo(self::THREAD_ID); $i--; } // check 1 more time if ($i <= 0 || $threadInfo->getState() != X_Threads_Thread_Info::RUNNING) { X_Debug::e("Streamer thread doesn't want to wake up or it finished really fast"); return false; } return true; }
/** * add a new Streamer_Engine inside the supported streamers * @param X_Streamer_Engine $streamer concrete implementation of X_Streamer_Engine * @param string $id an overloaded streamer id * @param string $pattern an overloaded location pattern * @return void */ public function register(X_Streamer_Engine $streamer, $id = null) { if ($id === null) { $id = $streamer->getId(); } X_Debug::i("Registering streamer {{$id}}"); $this->streamers[$id] = $streamer; return $this; }
/** * Add the button BackToStream in controls page * * @param X_Streamer_Engine $engine * @param Zend_Controller_Action $controller the controller who handle the request * @return array */ public function preGetControlItems(X_Streamer_Engine $engine, Zend_Controller_Action $controller) { $urlHelper = $controller->getHelper('url'); $return = new X_Page_ItemList_PItem(); if ($this->config('show.title', true)) { $onAirName = X_Env::_("p_streaminfo_unknown_source"); if ($engine instanceof X_Streamer_Engine_Vlc) { $vlc = $engine->getVlcWrapper(); $onAirName = $vlc->getCurrentName(); } else { // try to find the name from the location (if any) $providerId = $controller->getRequest()->getParam('p', false); $location = $controller->getRequest()->getParam('l', false); if ($providerId && $location) { $providerObj = X_VlcShares_Plugins::broker()->getPlugins($providerId); $location = X_Env::decode($location); if ($providerObj instanceof X_VlcShares_Plugins_ResolverInterface) { $onAirName = $providerObj->resolveLocation($location); } } } // show the title of the file $item = new X_Page_Item_PItem('streaminfo-onair', X_Env::_('p_streaminfo_onair') . ": {$onAirName}"); $item->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setLink(X_Env::completeUrl($urlHelper->url())); $return->append($item); } if ($engine instanceof X_Streamer_Engine_Vlc) { $vlc = $engine->getVlcWrapper(); if ($this->config('show.time', false)) { $currentTime = X_Env::formatTime($vlc->getCurrentTime()); $totalTime = X_Env::formatTime($vlc->getTotalTime()); $item = new X_Page_Item_PItem('streaminfo-time', "{$currentTime}/{$totalTime}"); $item->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setLink(X_Env::completeUrl($urlHelper->url())); $return->append($item); } } return $return; }