コード例 #1
0
 /**
  * Update media server status
  * 
  * @action reportStatus
  * @param string $hostname
  * @param KalturaMediaServerStatus $mediaServerStatus
  * @return KalturaMediaServer
  */
 function reportStatusAction($hostname, KalturaMediaServerStatus $mediaServerStatus)
 {
     $dbMediaServer = MediaServerPeer::retrieveByHostname($hostname);
     if (!$dbMediaServer) {
         $dbMediaServer = new MediaServer();
         $dbMediaServer->setHostname($hostname);
         $dbMediaServer->setDc(kDataCenterMgr::getCurrentDcId());
     }
     $mediaServerStatus->toUpdatableObject($dbMediaServer);
     $dbMediaServer->save();
     $mediaServer = new KalturaMediaServer();
     $mediaServer->fromObject($dbMediaServer, $this->getResponseProfile());
     return $mediaServer;
 }
コード例 #2
0
 /**
  * Validate the client's API key, store reported device information
  * in the database and return a success message.
  *
  * \param $request REST request from client
  *
  * \return Array with response data
  */
 private function reportDeviceInformation($request)
 {
     $result = array();
     $bodyData = $request->getBodyData();
     $arguments = $request->getURLArguments();
     // Validate client credentials
     if (isset($bodyData['AppName']) && isset($bodyData['ApiKey']) && Authentication::validate($bodyData['AppName'], $bodyData['ApiKey'])) {
         // Report device information
         if (isset($bodyData['OSVersion']) && isset($bodyData['APILevel']) && isset($bodyData['DeviceType']) && isset($bodyData['ReportedBy'])) {
             $result = MediaServer::handleReportDeviceInfoRequest($bodyData['OSVersion'], $bodyData['APILevel'], $bodyData['DeviceType'], $bodyData['ReportedBy']);
         } else {
             $result = array('Statuscode' => 'Error', 'Message' => 'Invalid or incomplete request. Check URL arguments and body data.');
         }
     } else {
         $result = array('Statuscode' => 'Error', 'Message' => 'Invalid or no auth data provided. Check your API key.');
     }
     return $result;
 }
コード例 #3
0
 protected function appendLiveParams(LiveStreamEntry $entry, MediaServer $mediaServer = null, SimpleXMLElement $encodes, liveParams $liveParams)
 {
     $streamName = $entry->getId() . '_' . $liveParams->getId();
     $videoCodec = 'PassThru';
     $audioCodec = 'AAC';
     $profile = 'main';
     $systemName = $liveParams->getSystemName() ? $liveParams->getSystemName() : $liveParams->getId();
     $encode = $encodes->addChild('Encode');
     $encode->addChild('Enable', 'true');
     $encode->addChild('Name', $systemName);
     $encode->addChild('StreamName', $streamName);
     $video = $encode->addChild('Video');
     $audio = $encode->addChild('Audio');
     if ($liveParams->hasTag(assetParams::TAG_AUDIO_ONLY)) {
         $videoCodec = 'Disable';
     }
     if ($liveParams->hasTag(liveParams::TAG_INGEST)) {
         $video->addChild('Codec', $videoCodec);
         $audio->addChild('Codec', $audioCodec);
         $audio->addChild('Bitrate', 96000);
         return;
     }
     if ($liveParams->getWidth() || $liveParams->getHeight() || $liveParams->getFrameRate()) {
         switch ($liveParams->getVideoCodec()) {
             case flavorParams::VIDEO_CODEC_COPY:
                 $videoCodec = 'PassThru';
                 break;
             case flavorParams::VIDEO_CODEC_FLV:
             case flavorParams::VIDEO_CODEC_VP6:
             case flavorParams::VIDEO_CODEC_H263:
                 $profile = 'baseline';
                 $videoCodec = 'H.263';
                 break;
             case flavorParams::VIDEO_CODEC_H264:
             case flavorParams::VIDEO_CODEC_H264B:
                 $profile = 'baseline';
                 // don't break
             // don't break
             case flavorParams::VIDEO_CODEC_H264H:
             case flavorParams::VIDEO_CODEC_H264M:
                 $streamName = "mp4:{$streamName}";
                 $videoCodec = 'H.264';
                 break;
             default:
                 KalturaLog::err("Live params video codec id [" . $liveParams->getVideoCodec() . "] is not expected");
                 break;
         }
         if ($liveParams->getAudioSampleRate() || $liveParams->getAudioChannels()) {
             switch ($liveParams->getAudioCodec()) {
                 case flavorParams::AUDIO_CODEC_AAC:
                 case flavorParams::AUDIO_CODEC_AACHE:
                     $audioCodec = 'AAC';
                     break;
                 default:
                     KalturaLog::err("Live params audio codec id [" . $liveParams->getAudioCodec() . "] is not expected");
                     break;
             }
         }
     }
     $video->addChild('Transcoder', $mediaServer ? $mediaServer->getTranscoder() : MediaServer::DEFAULT_TRANSCODER);
     $video->addChild('GPUID', $mediaServer ? $mediaServer->getGPUID() : MediaServer::DEFAULT_GPUID);
     $frameSize = $video->addChild('FrameSize');
     if (!$liveParams->getWidth() && !$liveParams->getHeight()) {
         $frameSize->addChild('FitMode', 'match-source');
     } elseif ($liveParams->getWidth() && $liveParams->getHeight()) {
         $frameSize->addChild('FitMode', 'fit-height');
         $frameSize->addChild('Width', $liveParams->getWidth());
         $frameSize->addChild('Height', $liveParams->getHeight());
     } elseif ($liveParams->getWidth()) {
         $frameSize->addChild('FitMode', 'fit-width');
         $frameSize->addChild('Width', $liveParams->getWidth());
     } elseif ($liveParams->getHeight()) {
         $frameSize->addChild('FitMode', 'fit-height');
         $frameSize->addChild('Height', $liveParams->getHeight());
     }
     $video->addChild('Codec', $videoCodec);
     $video->addChild('Profile', $profile);
     $video->addChild('Bitrate', $liveParams->getVideoBitrate() ? $liveParams->getVideoBitrate() * 1024 : 240000);
     $keyFrameInterval = $video->addChild('KeyFrameInterval');
     $keyFrameInterval->addChild('FollowSource', 'true');
     $keyFrameInterval->addChild('Interval', 60);
     $audio->addChild('Codec', $audioCodec);
     $audio->addChild('Bitrate', $liveParams->getAudioBitrate() ? $liveParams->getAudioBitrate() * 1024 : 96000);
 }
コード例 #4
0
ファイル: MediaServer.php プロジェクト: nepa/Server-One
 /**
  * Handle incoming requests that query for average noise level by zip
  * code. Sound levels are taken from the database and average is
  * calculated across all values with desired postal code.
  */
 public static function handleAverageNoiseLevelByZipCodeRequest($zipCode)
 {
     // Validate zip code
     if (!MediaServer::validZipCode($zipCode, false)) {
         return array('Statuscode' => 'Error', 'Message' => 'Invalid or no zip code provided.');
     }
     // Return average noise level by zip code
     $database = new Database();
     $resultSet = $database->getAverageNoiseLevelByZipCode($zipCode);
     // Cast average noise level to integer
     $averageNoiseLevel = intval($resultSet[0]['averageNoiseLevel']);
     if ($averageNoiseLevel == '') {
         return array('Statuscode' => 'Info', 'Message' => 'No sound levels found in postcode area.');
     }
     // Log average noise levels request
     Logger::log('Average noise levels requested for zip code area \'' . $zipCode . '\'.', Logger::NOISE_AVG_BY_ZIP_REQUEST);
     // Send response
     return array('Statuscode' => 'OK', 'Message' => 'Average sound level successfully queried by zip code.', 'AverageNoiseLevel' => $averageNoiseLevel);
 }
コード例 #5
0
 /**
  * Validate the client's API key, save uploaded sound sample on
  * disk and return a success message.
  *
  * \param $request REST request from client
  *
  * \return Array with response data
  */
 private function uploadSoundSample($request)
 {
     $result = array();
     $bodyData = $request->getBodyData();
     $arguments = $request->getURLArguments();
     // Validate client credentials
     if (isset($bodyData['AppName']) && isset($bodyData['ApiKey']) && Authentication::validate($bodyData['AppName'], $bodyData['ApiKey'])) {
         // Upload sound sample
         if (isset($arguments['latitude']) && isset($arguments['longitude']) && isset($bodyData['Time']) && isset($bodyData['Tag']) && isset($bodyData['PayloadType']) && isset($bodyData['Payload']) && isset($bodyData['ReportedBy'])) {
             // Prevent PHP notice because of undefined index
             if (!isset($bodyData['Title'])) {
                 $bodyData['Title'] = null;
             }
             if (!isset($bodyData['Description'])) {
                 $bodyData['Description'] = null;
             }
             $result = MediaServer::handleUploadRequest($arguments['latitude'], $arguments['longitude'], $bodyData['Title'], $bodyData['Time'], $bodyData['Description'], $bodyData['Tag'], $bodyData['PayloadType'], $bodyData['Payload'], $bodyData['ReportedBy']);
         } else {
             $result = array('Statuscode' => 'Error', 'Message' => 'Invalid or incomplete request. Check URL arguments and body data.');
         }
     } else {
         $result = array('Statuscode' => 'Error', 'Message' => 'Invalid or no auth data provided. Check your API key.');
     }
     return $result;
 }
コード例 #6
0
ファイル: LiveEntry.php プロジェクト: visomar/server
 public function getLiveStreamConfigurations($protocol = 'http', $tag = null, $currentDcOnly = false, array $flavorParamsIds = array())
 {
     $configurations = array();
     if (!in_array($this->getSource(), self::$kalturaLiveSourceTypes)) {
         $configurations = $this->getFromCustomData('live_stream_configurations', null, array());
         if ($configurations && $this->getPushPublishEnabled()) {
             $pushPublishConfigurations = $this->getPushPublishConfigurations();
             $configurations = array_merge($configurations, $pushPublishConfigurations);
         }
         return $configurations;
     }
     $primaryMediaServer = null;
     $backupMediaServer = null;
     $primaryApplicationName = null;
     $backupApplicationName = null;
     $isExternalMediaServerStream = false;
     $kMediaServers = $this->getMediaServers();
     $partnerMediaServerConfiguration = $this->getPartner()->getMediaServersConfiguration();
     if (count($kMediaServers)) {
         foreach ($kMediaServers as $key => $kMediaServer) {
             if ($kMediaServer && $kMediaServer instanceof kLiveMediaServer) {
                 KalturaLog::debug("mediaServer->getDc [" . $kMediaServer->getDc() . "] == kDataCenterMgr::getCurrentDcId [" . kDataCenterMgr::getCurrentDcId() . "]");
                 if ($kMediaServer->getDc() == kDataCenterMgr::getCurrentDcId()) {
                     $primaryMediaServer = $kMediaServer->getMediaServer();
                     $primaryApplicationName = $kMediaServer->getApplicationName();
                     unset($kMediaServers[$key]);
                 }
             }
         }
         if (!$primaryMediaServer) {
             if ($currentDcOnly) {
                 return array();
             }
             $kMediaServer = array_shift($kMediaServers);
             if ($kMediaServer && $kMediaServer instanceof kLiveMediaServer) {
                 $primaryMediaServer = $kMediaServer->getMediaServer();
                 if (!$primaryMediaServer && $partnerMediaServerConfiguration && isset($partnerMediaServerConfiguration[$kMediaServer->getHostname()])) {
                     $primaryMediaServer = new MediaServer();
                     $primaryMediaServer->setHostname($kMediaServer->getHostname());
                     $primaryMediaServer->setIsExternalMediaServer(true);
                     $isExternalMediaServerStream = true;
                 }
                 $primaryApplicationName = $kMediaServer->getApplicationName();
             }
         }
         if (!$currentDcOnly && count($kMediaServers)) {
             $kMediaServer = reset($kMediaServers);
             if ($kMediaServer && $kMediaServer instanceof kLiveMediaServer) {
                 $backupMediaServer = $kMediaServer->getMediaServer();
                 if (!$backupMediaServer && $partnerMediaServerConfiguration && isset($partnerMediaServerConfiguration[$kMediaServer->getHostname()])) {
                     $backupMediaServer = new MediaServer();
                     $backupMediaServer->setHostname($kMediaServer->getHostname());
                     $backupMediaServer->setIsExternalMediaServer(true);
                     $isExternalMediaServerStream = true;
                 }
                 $backupApplicationName = $kMediaServer->getApplicationName();
             }
         }
     }
     $manifestUrl = null;
     $backupManifestUrl = null;
     if (count($this->getPartner()->getLiveStreamPlaybackUrlConfigurations())) {
         $partnerConfigurations = $this->getPartner()->getLiveStreamPlaybackUrlConfigurations();
         if (isset($partnerConfigurations[$protocol])) {
             $manifestUrl = $partnerConfigurations[$protocol];
         }
     } elseif ($primaryMediaServer) {
         $manifestUrl = $primaryMediaServer->getManifestUrl($protocol, $partnerMediaServerConfiguration);
         if ($backupMediaServer) {
             $backupManifestUrl = $backupMediaServer->getManifestUrl($protocol, $partnerMediaServerConfiguration);
         }
     }
     $rtmpStreamUrl = null;
     $hlsStreamUrl = null;
     $hdsStreamUrl = null;
     $slStreamUrl = null;
     $mpdStreamUrl = null;
     $hlsBackupStreamUrl = null;
     $hdsBackupStreamUrl = null;
     if ($manifestUrl) {
         $manifestUrl .= "{$primaryApplicationName}/";
         $streamName = $this->getId();
         if (is_null($tag) && ($this->getConversionProfileId() || $this->getType() == entryType::LIVE_CHANNEL)) {
             $tag = 'all';
         }
         $queryString = array();
         if ($this->getDvrStatus() == DVRStatus::ENABLED) {
             $queryString[] = 'DVR';
         }
         if (count($flavorParamsIds) === 1) {
             $streamName .= '_' . reset($flavorParamsIds);
         } elseif (count($flavorParamsIds) > 1) {
             sort($flavorParamsIds);
             $tag = implode('_', $flavorParamsIds);
             $queryString[] = 'flavorIds=' . implode(',', $flavorParamsIds);
             $streamName = "smil:{$streamName}_{$tag}.smil";
         } elseif ($tag) {
             $streamName = "smil:{$streamName}_{$tag}.smil";
         }
         if (count($queryString)) {
             $queryString = '?' . implode('&', $queryString);
         } else {
             $queryString = '';
         }
         $rtmpStreamUrl = $manifestUrl;
         $manifestUrl .= $streamName;
         $hlsStreamUrl = "{$manifestUrl}/playlist.m3u8" . $queryString;
         $hdsStreamUrl = "{$manifestUrl}/manifest.f4m" . $queryString;
         $slStreamUrl = "{$manifestUrl}/Manifest" . $queryString;
         $mpdStreamUrl = "{$manifestUrl}/manifest.mpd" . $queryString;
         if ($backupManifestUrl) {
             $backupManifestUrl .= "{$backupApplicationName}/";
             $backupManifestUrl .= $streamName;
             $hlsBackupStreamUrl = "{$backupManifestUrl}/playlist.m3u8" . $queryString;
             $hdsBackupStreamUrl = "{$backupManifestUrl}/manifest.f4m" . $queryString;
         }
     }
     //		TODO - enable it and test it in non-SaaS environment
     //		$configuration = new kLiveStreamConfiguration();
     //		$configuration->setProtocol(PlaybackProtocol::RTMP);
     //		$configuration->setUrl($rtmpStreamUrl);
     //		$configurations[] = $configuration;
     $configuration = new kLiveStreamConfiguration();
     $configuration->setProtocol(PlaybackProtocol::HDS);
     $configuration->setUrl($hdsStreamUrl);
     $configuration->setBackupUrl($hdsBackupStreamUrl);
     $configuration->setIsExternalStream($isExternalMediaServerStream);
     $configurations[] = $configuration;
     $configuration = new kLiveStreamConfiguration();
     $configuration->setProtocol(PlaybackProtocol::HLS);
     $configuration->setUrl($hlsStreamUrl);
     $configuration->setBackupUrl($hlsBackupStreamUrl);
     $configuration->setIsExternalStream($isExternalMediaServerStream);
     $configurations[] = $configuration;
     $configuration = new kLiveStreamConfiguration();
     $configuration->setProtocol(PlaybackProtocol::APPLE_HTTP);
     $configuration->setUrl($hlsStreamUrl);
     $configuration->setBackupUrl($hlsBackupStreamUrl);
     $configuration->setIsExternalStream($isExternalMediaServerStream);
     $configurations[] = $configuration;
     $configuration = new kLiveStreamConfiguration();
     $configuration->setProtocol(PlaybackProtocol::APPLE_HTTP_TO_MC);
     $configuration->setUrl($hlsStreamUrl);
     $configuration->setBackupUrl($hlsBackupStreamUrl);
     $configuration->setIsExternalStream($isExternalMediaServerStream);
     $configurations[] = $configuration;
     $configuration = new kLiveStreamConfiguration();
     $configuration->setProtocol(PlaybackProtocol::SILVER_LIGHT);
     $configuration->setUrl($slStreamUrl);
     $configuration->setIsExternalStream($isExternalMediaServerStream);
     $configurations[] = $configuration;
     $configuration = new kLiveStreamConfiguration();
     $configuration->setProtocol(PlaybackProtocol::MPEG_DASH);
     $configuration->setUrl($mpdStreamUrl);
     $configuration->setIsExternalStream($isExternalMediaServerStream);
     $configurations[] = $configuration;
     if ($this->getPushPublishEnabled()) {
         $pushPublishConfigurations = $this->getPushPublishPlaybackConfigurations();
         $configurations = array_merge($configurations, $pushPublishConfigurations);
     }
     return $configurations;
 }
コード例 #7
0
 /**
  * Validate the client's API key, store reported noise level
  * value in the database and return a success message.
  *
  * \param $request REST request from client
  *
  * \return Array with response data
  */
 private function reportNoiseLevel($request)
 {
     $result = array();
     $bodyData = $request->getBodyData();
     $arguments = $request->getURLArguments();
     // Validate client credentials
     if (isset($bodyData['AppName']) && isset($bodyData['ApiKey']) && Authentication::validate($bodyData['AppName'], $bodyData['ApiKey'])) {
         // Report noise level
         if (isset($arguments['latitude']) && isset($arguments['longitude']) && isset($bodyData['Time']) && isset($bodyData['NoiseLevel']) && isset($bodyData['NoiseLevelOrg']) && isset($bodyData['ReportedBy']) && isset($bodyData['InPocket'])) {
             // Prevent PHP notice because of undefined index
             if (!isset($arguments['zipCode'])) {
                 $arguments['zipCode'] = null;
             }
             $result = MediaServer::handleReportRequest($arguments['latitude'], $arguments['longitude'], $bodyData['Time'], $arguments['zipCode'], $bodyData['NoiseLevel'], $bodyData['NoiseLevelOrg'], $bodyData['ReportedBy'], $bodyData['InPocket']);
         } else {
             $result = array('Statuscode' => 'Error', 'Message' => 'Invalid or incomplete request. Check URL arguments and body data.');
         }
     } else {
         $result = array('Statuscode' => 'Error', 'Message' => 'Invalid or no auth data provided. Check your API key.');
     }
     return $result;
 }
コード例 #8
0
ファイル: MediaService.php プロジェクト: nepa/Server-One
 /**
  * Method to query for the average noise level by zip code.
  */
 public function getAverageNoiseLevelByZipCode($zipCode)
 {
     return MediaServer::handleAverageNoiseLevelByZipCodeRequest($zipCode);
 }
コード例 #9
0
 /**
  * Evaluate REST request and return a summary of the service's
  * use statistics for desired content type (e.g. noise level
  * reports or sound sample uploads).
  *
  * \param $request REST request from client
  *
  * \return Array with response data
  */
 private function getStatisticsSummary($request)
 {
     $result = array();
     $arguments = $request->getURLArguments();
     // Summarize use statistics
     if (isset($arguments['what'])) {
         $result = MediaServer::handleStatisticsSummaryRequest($arguments['what']);
         // Capitalize first letter of all array keys
         Utility::ucfirstKeys($result);
     } else {
         $result = array('Statuscode' => 'Error', 'Message' => 'Invalid or no arguments in REST request.');
     }
     return $result;
 }
コード例 #10
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      MediaServer $value A MediaServer object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(MediaServer $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         if (isset(self::$instances[$key]) || count(self::$instances) < kConf::get('max_num_instances_in_pool')) {
             self::$instances[$key] = $obj;
             kMemoryManager::registerPeer('MediaServerPeer');
         }
     }
 }