예제 #1
0
 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();
     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();
                 $primaryApplicationName = $kMediaServer->getApplicationName();
                 if ($primaryMediaServer) {
                     $isExternalMediaServerStream = $primaryMediaServer->getIsExternalMediaServer();
                 } else {
                     KalturaLog::debug("Cannot retrrive extra information for un-registered media server with host name [" . $kMediaServer->getHostname() . "]");
                 }
             }
         }
         if (!$currentDcOnly && count($kMediaServers)) {
             $kMediaServer = reset($kMediaServers);
             if ($kMediaServer && $kMediaServer instanceof kLiveMediaServer) {
                 $backupMediaServer = $kMediaServer->getMediaServer();
                 $backupApplicationName = $kMediaServer->getApplicationName();
             }
         }
     }
     $manifestUrl = null;
     $backupManifestUrl = null;
     $hlsManifestUrl = null;
     $hlsBackupManifestUrl = null;
     if (count($this->getPartner()->getLiveStreamPlaybackUrlConfigurations())) {
         $partnerConfigurations = $this->getPartner()->getLiveStreamPlaybackUrlConfigurations();
         if (isset($partnerConfigurations[$protocol])) {
             $manifestUrl = $partnerConfigurations[$protocol];
         }
     } elseif ($primaryMediaServer) {
         $partnerMediaServerConfiguration = $this->getPartner()->getMediaServersConfiguration();
         $primaryMediaServer->setPartnerMediaServerConfig($partnerMediaServerConfiguration);
         $manifestUrl = $primaryMediaServer->getManifestUrl($protocol);
         $hlsManifestUrl = $primaryMediaServer->getManifestUrl($protocol, PlaybackProtocol::HLS);
         if ($backupMediaServer) {
             $backupMediaServer->setPartnerMediaServerConfig($partnerMediaServerConfiguration);
             $backupManifestUrl = $backupMediaServer->getManifestUrl($protocol);
             $hlsBackupManifestUrl = $backupMediaServer->getManifestUrl($protocol, PlaybackProtocol::HLS);
         }
     }
     $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 .= $hlsManifestUrl . "{$primaryApplicationName}/" . $streamName . "/playlist.m3u8" . $queryString;
         $hdsStreamUrl = "{$manifestUrl}/manifest.f4m" . $queryString;
         $slStreamUrl = "{$manifestUrl}/Manifest" . $queryString;
         $mpdStreamUrl = "{$manifestUrl}/manifest.mpd" . $queryString;
         if ($backupManifestUrl) {
             $backupManifestUrl .= "{$backupApplicationName}/";
             $backupManifestUrl .= $streamName;
             $hlsBackupStreamUrl .= $hlsBackupManifestUrl . "{$backupApplicationName}/" . $streamName . "/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;
 }