Exemple #1
0
 /**
  * Delivering the status of a live stream (on-air/offline) if it is possible
  * 
  * @action isLive
  * @param string $id ID of the live stream
  * @param KalturaPlaybackProtocol $protocol protocol of the stream to test.
  * @return bool
  * 
  * @throws KalturaErrors::LIVE_STREAM_STATUS_CANNOT_BE_DETERMINED
  * @throws KalturaErrors::INVALID_ENTRY_ID
  */
 public function isLiveAction($id, $protocol)
 {
     if (!kCurrentContext::$ks) {
         kEntitlementUtils::initEntitlementEnforcement(null, false);
         $liveStreamEntry = kCurrentContext::initPartnerByEntryId($id);
         if (!$liveStreamEntry || $liveStreamEntry->getStatus() == entryStatus::DELETED) {
             throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_ID, $id);
         }
         // enforce entitlement
         $this->setPartnerFilters(kCurrentContext::getCurrentPartnerId());
     } else {
         $liveStreamEntry = entryPeer::retrieveByPK($id);
     }
     if (!$liveStreamEntry || $liveStreamEntry->getType() != entryType::LIVE_STREAM) {
         throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_ID, $id);
     }
     if (!in_array($liveStreamEntry->getSource(), LiveEntry::$kalturaLiveSourceTypes)) {
         KalturaResponseCacher::setConditionalCacheExpiry(self::ISLIVE_ACTION_NON_KALTURA_LIVE_CONDITIONAL_CACHE_EXPIRY);
     }
     /* @var $liveStreamEntry LiveStreamEntry */
     if (in_array($liveStreamEntry->getSource(), array(KalturaSourceType::LIVE_STREAM, KalturaSourceType::LIVE_STREAM_ONTEXTDATA_CAPTIONS))) {
         return $this->responseHandlingIsLive($liveStreamEntry->hasMediaServer());
     }
     $dpda = new DeliveryProfileDynamicAttributes();
     $dpda->setEntryId($id);
     $dpda->setFormat($protocol);
     switch ($protocol) {
         case KalturaPlaybackProtocol::HLS:
         case KalturaPlaybackProtocol::APPLE_HTTP:
             $url = $liveStreamEntry->getHlsStreamUrl();
             foreach (array(KalturaPlaybackProtocol::HLS, KalturaPlaybackProtocol::APPLE_HTTP) as $hlsProtocol) {
                 $config = $liveStreamEntry->getLiveStreamConfigurationByProtocol($hlsProtocol, requestUtils::getProtocol());
                 if ($config) {
                     $url = $config->getUrl();
                     $protocol = $hlsProtocol;
                     break;
                 }
             }
             KalturaLog::info('Determining status of live stream URL [' . $url . ']');
             $urlManager = DeliveryProfilePeer::getLiveDeliveryProfileByHostName(parse_url($url, PHP_URL_HOST), $dpda);
             if ($urlManager) {
                 return $this->responseHandlingIsLive($urlManager->isLive($url));
             }
             break;
         case KalturaPlaybackProtocol::HDS:
         case KalturaPlaybackProtocol::AKAMAI_HDS:
             $config = $liveStreamEntry->getLiveStreamConfigurationByProtocol($protocol, requestUtils::getProtocol());
             if ($config) {
                 $url = $config->getUrl();
                 KalturaLog::info('Determining status of live stream URL [' . $url . ']');
                 $urlManager = DeliveryProfilePeer::getLiveDeliveryProfileByHostName(parse_url($url, PHP_URL_HOST), $dpda);
                 if ($urlManager) {
                     return $this->responseHandlingIsLive($urlManager->isLive($url));
                 }
             }
             break;
     }
     throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_STATUS_CANNOT_BE_DETERMINED, $protocol);
 }
 /**
  * @return array primary URL and backup URL
  */
 private function getLiveEntryBaseUrls()
 {
     $this->initFlavorParamsIds();
     $tag = null;
     $tags = $this->deliveryAttributes->getTags();
     if (count($tags) == 1) {
         $tag = reset($tags);
     }
     $protocol = $this->deliveryAttributes->getMediaProtocol();
     if (in_array($this->deliveryAttributes->getFormat(), self::$httpFormats) && !in_array($protocol, self::$httpProtocols)) {
         $protocol = requestUtils::getProtocol();
     }
     $liveStreamConfig = $this->entry->getLiveStreamConfigurationByProtocol($this->deliveryAttributes->getFormat(), $protocol, $tag, false, $this->flavorParamsIds);
     /* @var $liveStreamConfig kLiveStreamConfiguration */
     if ($liveStreamConfig) {
         return array($liveStreamConfig->getUrl(), $liveStreamConfig->getBackupUrl());
     }
     switch ($this->deliveryAttributes->getFormat()) {
         case PlaybackProtocol::RTMP:
             $baseUrl = $this->entry->getStreamUrl();
             $baseUrl = rtrim($baseUrl, '/');
             if (strpos($this->deliveryAttributes->getMediaProtocol(), "rtmp") === 0) {
                 $baseUrl = $this->deliveryAttributes->getMediaProtocol() . '://' . preg_replace('/^rtmp.*?:\\/\\//', '', $baseUrl);
             }
             return array($baseUrl, null);
         case PlaybackProtocol::APPLE_HTTP:
             return array($this->entry->getHlsStreamUrl(), null);
             // TODO pass single tag
     }
     return array(null, null);
 }
 private function setContextDataStreamerTypeAndMediaProtocol(accessControlScope $scope, $flavorTags)
 {
     if ($this->streamerType && $this->streamerType != PlaybackProtocol::AUTO) {
         $this->mediaProtocol = $this->mediaProtocol ? $this->mediaProtocol : $this->streamerType;
     } elseif ($this->entry instanceof LiveEntry) {
         $protocols = array();
         if (!in_array($this->entry->getSource(), LiveEntry::$kalturaLiveSourceTypes)) {
             $protocols[] = PlaybackProtocol::AKAMAI_HDS;
         }
         $protocols[] = PlaybackProtocol::HDS;
         if ($this->entry->getStreamName()) {
             $this->streamerType = PlaybackProtocol::RTMP;
         }
         foreach ($protocols as $protocol) {
             $config = $this->entry->getLiveStreamConfigurationByProtocol($protocol, requestUtils::getProtocol());
             if ($config) {
                 $this->streamerType = $protocol;
                 break;
             }
         }
         if (in_array($this->entry->getSource(), array(EntrySourceType::LIVE_STREAM, EntrySourceType::LIVE_STREAM_ONTEXTDATA_CAPTIONS))) {
             $this->streamerType = PlaybackProtocol::HDS;
         }
         if ($this->entry->getSource() == EntrySourceType::AKAMAI_LIVE) {
             $this->streamerType = PlaybackProtocol::RTMP;
         }
         if ($this->entry->getSource() == EntrySourceType::AKAMAI_UNIVERSAL_LIVE) {
             $this->streamerType = PlaybackProtocol::AKAMAI_HDS;
         }
     } else {
         $this->isSecured = $this->isSecured || PermissionPeer::isValidForPartner(PermissionName::FEATURE_ENTITLEMENT_USED, $this->entry->getPartnerId());
         $forcedDeliveryTypeKey = kDeliveryUtils::getForcedDeliveryTypeKey($this->selectedTag);
         if ($forcedDeliveryTypeKey) {
             $defaultDeliveryTypeKey = $forcedDeliveryTypeKey;
         } else {
             $defaultDeliveryTypeKey = $this->partner->getDefaultDeliveryType();
         }
         if (!$defaultDeliveryTypeKey || $defaultDeliveryTypeKey == PlaybackProtocol::AUTO) {
             $deliveryType = $this->selectDeliveryTypeForAuto();
         } else {
             $deliveryType = kDeliveryUtils::getDeliveryTypeFromConfig($defaultDeliveryTypeKey);
         }
         if (!$deliveryType) {
             $deliveryType = array();
         }
         $this->streamerType = kDeliveryUtils::getStreamerType($deliveryType);
         $this->mediaProtocol = kDeliveryUtils::getMediaProtocol($deliveryType);
     }
     $httpStreamerTypes = array(PlaybackProtocol::HTTP, PlaybackProtocol::HDS, PlaybackProtocol::HLS, PlaybackProtocol::SILVER_LIGHT, PlaybackProtocol::MPEG_DASH);
     if (in_array($this->streamerType, $httpStreamerTypes)) {
         $this->mediaProtocol = infraRequestUtils::getProtocol();
     }
     if ($this->streamerType == PlaybackProtocol::AKAMAI_HD || $this->streamerType == PlaybackProtocol::AKAMAI_HDS) {
         $this->mediaProtocol = PlaybackProtocol::HTTP;
     }
     //If a plugin can determine the streamerType and mediaProtocol, prefer plugin result
     $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaContextDataHelper');
     foreach ($pluginInstances as $pluginInstance) {
         /* @var $pluginInstance IKalturaContextDataHelper */
         $this->streamerType = $pluginInstance->getContextDataStreamerType($scope, $flavorTags, $this->streamerType);
         $this->mediaProtocol = $pluginInstance->getContextDataMediaProtocol($scope, $flavorTags, $this->streamerType, $this->mediaProtocol);
     }
 }
 /**
  * @return array primary URL and backup URL
  */
 private function getLiveEntryStreamConfig()
 {
     $this->initFlavorParamsIds();
     $tag = null;
     $tags = $this->deliveryAttributes->getTags();
     if (count($tags) == 1) {
         $tag = reset($tags);
     }
     $protocol = $this->deliveryAttributes->getMediaProtocol();
     if (in_array($this->deliveryAttributes->getFormat(), self::$httpFormats) && !in_array($protocol, self::$httpProtocols)) {
         $protocol = requestUtils::getProtocol();
     }
     // use only cloud transcode flavors if timeAlignedRenditions was set
     $partnerId = $this->entry->getPartnerId();
     $partner = PartnerPeer::retrieveByPK($partnerId);
     $partnerTimeAligned = $partner->getTimeAlignedRenditions();
     if ($partnerTimeAligned && $this->getRequestParameter("playerType") === 'flash') {
         // check entry's flavors
         $entryFlavorParams = assetParamsPeer::retrieveByPKs(explode(',', $this->entry->getFlavorParamsIds()));
         $hasTranscode = false;
         foreach ($entryFlavorParams as $flavor) {
             // check if we have any transcode flavor
             if (!$flavor->hasTag("ingest")) {
                 $hasTranscode = true;
             }
         }
         // if so, use only the transcode
         if ($hasTranscode) {
             $tag = 'mbr';
         }
     }
     $liveStreamConfig = $this->entry->getLiveStreamConfigurationByProtocol($this->deliveryAttributes->getFormat(), $protocol, $tag, false, $this->flavorParamsIds);
     /* @var $liveStreamConfig kLiveStreamConfiguration */
     if ($liveStreamConfig) {
         return $liveStreamConfig;
     }
     switch ($this->deliveryAttributes->getFormat()) {
         case PlaybackProtocol::RTMP:
             $baseUrl = $this->entry->getStreamUrl();
             $baseUrl = rtrim($baseUrl, '/');
             if (strpos($this->deliveryAttributes->getMediaProtocol(), "rtmp") === 0) {
                 $baseUrl = $this->deliveryAttributes->getMediaProtocol() . '://' . preg_replace('/^rtmp.*?:\\/\\//', '', $baseUrl);
             }
             $liveStreamConfig = new kLiveStreamConfiguration();
             $liveStreamConfig->setUrl($baseUrl);
             $liveStreamConfig->setProtocol(PlaybackProtocol::RTMP);
             return $liveStreamConfig;
         case PlaybackProtocol::APPLE_HTTP:
             // TODO pass single tag
             $liveStreamConfig = new kLiveStreamConfiguration();
             $liveStreamConfig->setUrl($this->entry->getHlsStreamUrl());
             $liveStreamConfig->setProtocol(PlaybackProtocol::APPLE_HTTP);
             return $liveStreamConfig;
     }
     return null;
 }
 private function getFlavorAssetUrl($kalturaEntry)
 {
     $partner = PartnerPeer::retrieveByPK($this->syndicationFeed->partnerId);
     if (!$partner) {
         return null;
     }
     $flavorAsset = assetPeer::retrieveByEntryIdAndParams($kalturaEntry->id, $this->syndicationFeed->flavorParamId);
     if (!$flavorAsset) {
         return null;
     }
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $externalStorageUrl = $this->getExternalStorageUrl($partner, $flavorAsset, $syncKey);
     if ($externalStorageUrl) {
         return $externalStorageUrl;
     }
     if ($partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY) {
         return null;
     }
     if ($this->syndicationFeedDb->getServePlayManifest()) {
         $shouldAddKtToken = false;
         if ($this->syndicationFeed->type == KalturaSyndicationFeedType::ITUNES) {
             $entry = $flavorAsset->getentry();
             $accessControl = $entry->getaccessControl();
             if ($accessControl && $accessControl->hasRules()) {
                 $shouldAddKtToken = true;
             }
         }
         $cdnHost = requestUtils::getApiCdnHost();
         $clientTag = 'feed:' . $this->syndicationFeedDb->getId();
         $url = $cdnHost . $flavorAsset->getPlayManifestUrl($clientTag, null, PlaybackProtocol::HTTP, $shouldAddKtToken);
     } else {
         $urlManager = DeliveryProfilePeer::getDeliveryProfile($flavorAsset->getEntryId());
         $urlManager->initDeliveryDynamicAttributes(null, $flavorAsset);
         $protocol = requestUtils::getProtocol();
         if (!$urlManager->isProtocolSupported($protocol)) {
             $protocol = $protocol == 'http' ? 'https' : 'http';
             if (!$urlManager->isProtocolSupported($protocol)) {
                 $protocol = 'http';
             }
         }
         $url = $protocol . '://' . $urlManager->getFullAssetUrl($flavorAsset);
     }
     return $url;
 }
 protected function getPlayerUrl($entryId)
 {
     $uiconfId = $this->syndicationFeed->playerUiconfId ? '/ui_conf_id/' . $this->syndicationFeed->playerUiconfId : '';
     $url = requestUtils::getProtocol() . '://' . kConf::get('www_host') . '/kwidget/wid/_' . $this->syndicationFeed->partnerId . '/entry_id/' . $entryId . $uiconfId;
     return $url;
 }