/** * returns whether the delivery profile supports the passed deliveryAttributes such as mediaProtocol, flv support, etc.. * @param DeliveryProfileDynamicAttributes $deliveryAttributes */ public function supportsDeliveryDynamicAttributes(DeliveryProfileDynamicAttributes $deliveryAttributes) { if (!$deliveryAttributes->getMediaProtocol()) { return self::DYNAMIC_ATTRIBUTES_FULL_SUPPORT; } if (!is_null($this->getMediaProtocols())) { $supportedProtocols = explode(",", $this->getMediaProtocols()); if (!in_array($deliveryAttributes->getMediaProtocol(), $supportedProtocols)) { return self::DYNAMIC_ATTRIBUTES_NO_SUPPORT; } } return self::DYNAMIC_ATTRIBUTES_FULL_SUPPORT; }
public function getDeliveryServerNodeUrl($removeAfterUse = false) { $deliveryUrl = null; $deliveryNodeIds = $this->params->getEdgeServerIds(); $deliveryNodes = ServerNodePeer::retrieveRegisteredServerNodesArrayByPKs($deliveryNodeIds); if (!count($deliveryNodes)) { KalturaLog::debug("No active delivery nodes found among the requested edge list: " . print_r($deliveryNodeIds, true)); return null; } $deliveryNode = null; foreach ($deliveryNodes as $node) { /* @var $node EdgeServerNode */ if ($node->validateEdgeTreeRegistered()) { $deliveryNode = $node; break; } } if (!$deliveryNode) { KalturaLog::debug("Active edges were found but non of them is active, Failed to build valid serving route"); return null; } $deliveryUrl = $deliveryNode->getPlaybackHost($this->params->getMediaProtocol(), $this->params->getFormat(), $this->getType()); if (count($deliveryNodes) && $removeAfterUse) { $this->params->setEdgeServerIds(array_diff($deliveryNodeIds, array($deliveryNode->getId()))); } return $deliveryUrl; }
public function getDeliveryServerNodeUrl($removeAfterUse = false) { $deliveryUrl = null; $deliveryNodeIds = $this->params->getEdgeServerIds(); $deliveryNodes = ServerNodePeer::retrieveRegisteredServerNodesArrayByPKs($deliveryNodeIds); if (!count($deliveryNodes)) { KalturaLog::debug("No active delivery nodes found among the requested edge list: " . print_r($deliveryNodeIds, true)); return null; } /* @var $deliveryNode EdgeServerNode */ $deliveryNode = array_shift($deliveryNodes); $deliveryUrl = $deliveryNode->getPlaybackHost($this->params->getMediaProtocol(), $this->params->getFormat(), $this->getType()); if (count($deliveryNodes) && $removeAfterUse) { $this->params->setEdgeServerIds(array_diff($deliveryNodeIds, array($deliveryNode->getId()))); } return $deliveryUrl; }
public static function getVodPackagerUrl($flavors, $urlPrefix, $urlSuffix, DeliveryProfileDynamicAttributes $params) { $url = self::generateMultiUrl($flavors); $url .= $urlSuffix; // move any folders on the url prefix to the url part, so that the protocol folder will always be first $urlPrefixWithProtocol = $urlPrefix; if (strpos($urlPrefix, '://') === false) { $urlPrefixWithProtocol = 'http://' . $urlPrefix; } $urlPrefixPath = parse_url($urlPrefixWithProtocol, PHP_URL_PATH); if ($urlPrefixPath && substr($urlPrefix, -strlen($urlPrefixPath)) == $urlPrefixPath) { $urlPrefix = substr($urlPrefix, 0, -strlen($urlPrefixPath)); $url = rtrim($urlPrefixPath, '/') . '/' . ltrim($url, '/'); } $urlPrefix = trim(preg_replace('#https?://#', '', $urlPrefix), '/'); $urlPrefix = $params->getMediaProtocol() . '://' . $urlPrefix; return array('url' => $url, 'urlPrefix' => $urlPrefix); }
public function execute() { KExternalErrors::setResponseErrorCode(KExternalErrors::HTTP_STATUS_NOT_FOUND); $this->deliveryAttributes = new DeliveryProfileDynamicAttributes(); // Parse input parameters $this->deliveryAttributes->setSeekFromTime($this->getRequestParameter("seekFrom", -1)); if ($this->deliveryAttributes->getSeekFromTime() <= 0) { $this->deliveryAttributes->setSeekFromTime(-1); } $this->deliveryAttributes->setClipTo($this->getRequestParameter("clipTo", 0)); $this->deliveryAttributes->setPlaybackRate($this->getRequestParameter("playbackRate", 0)); $deliveryCode = $this->getRequestParameter("deliveryCode", null); $playbackContext = $this->getRequestParameter("playbackContext", null); $this->deliveryAttributes->setMediaProtocol($this->getRequestParameter("protocol", null)); if (!$this->deliveryAttributes->getMediaProtocol() || $this->deliveryAttributes->getMediaProtocol() === "null") { $this->deliveryAttributes->setMediaProtocol(PlaybackProtocol::HTTP); } $this->deliveryAttributes->setFormat($this->getRequestParameter("format")); if (!$this->deliveryAttributes->getFormat()) { $this->deliveryAttributes->setFormat(PlaybackProtocol::HTTP); } if ($this->deliveryAttributes->getFormat() == self::HDNETWORKSMIL) { $this->deliveryAttributes->setMediaProtocol(PlaybackProtocol::HTTP); } // Akamai HD doesn't support any other protocol if ($this->deliveryAttributes->getFormat() == PlaybackProtocol::AKAMAI_HDS) { if (strpos($this->deliveryAttributes->getMediaProtocol(), "http") !== 0) { $this->deliveryAttributes->setMediaProtocol(PlaybackProtocol::HTTP); } } $tags = $this->getRequestParameter("tags", null); if (!$tags) { $this->deliveryAttributes->setTags(self::getDefaultTagsByFormat($this->deliveryAttributes->getFormat())); } else { $tagsArray = explode(',', $tags); $tags = array(); foreach ($tagsArray as $tag) { $tags[] = array(trim($tag)); } $this->deliveryAttributes->setTags($tags); } $this->deliveryAttributes->setpreferredBitrate($this->getRequestParameter("preferredBitrate", null)); $this->maxBitrate = $this->getRequestParameter("maxBitrate", null); if ($this->maxBitrate && (!is_numeric($this->maxBitrate) || $this->maxBitrate <= 0)) { KExternalErrors::dieError(KExternalErrors::INVALID_MAX_BITRATE); } $this->deliveryAttributes->setStorageId($this->getRequestParameter("storageId", null)); $this->cdnHost = $this->getRequestParameter("cdnHost", null); $this->deliveryAttributes->setResponseFormat($this->getRequestParameter("responseFormat", null)); // Initialize $this->initEntry(); $this->deliveryAttributes->setEntryId($this->entryId); $this->deliveryAttributes->setUsePlayServer((bool) $this->getRequestParameter("usePlayServer") && PermissionPeer::isValidForPartner(PermissionName::FEATURE_PLAY_SERVER, $this->entry->getPartnerId())); if ($this->deliveryAttributes->getUsePlayServer()) { $this->deliveryAttributes->setPlayerConfig($this->getRequestParameter("playerConfig")); //In case request needs to be redirected to play-server we need to add the ui conf id to the manifest url as well $this->deliveryAttributes->setUiConfId($this->getRequestParameter("uiConfId")); } $this->secureEntryHelper->updateDeliveryAttributes($this->deliveryAttributes); $this->enforceEncryption(); $renderer = null; switch ($this->entry->getType()) { case entryType::MEDIA_CLIP: // VOD $renderer = $this->serveVodEntry(); break; case entryType::LIVE_STREAM: case entryType::LIVE_CHANNEL: // Live stream $renderer = $this->serveLiveEntry(); break; default: KExternalErrors::dieError(KExternalErrors::INVALID_ENTRY_TYPE); } if (!$renderer) { KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'This format is unsupported'); } $renderer->contributors = array(); $config = new kManifestContributorConfig(); $config->format = $this->deliveryAttributes->getFormat(); $config->deliveryCode = $deliveryCode; $config->storageId = $this->deliveryAttributes->getStorageId(); $config->entryId = $this->entryId; $contributors = KalturaPluginManager::getPluginInstances('IKalturaPlayManifestContributor'); foreach ($contributors as $contributor) { /* @var $contributor IKalturaPlayManifestContributor */ $renderer->contributors = array_merge($renderer->contributors, $contributor->getManifestEditors($config)); } $renderer->entryId = $this->entryId; $renderer->duration = $this->duration; if ($this->deliveryProfile) { $renderer->tokenizer = $this->deliveryProfile->getTokenizer(); } $renderer->defaultDeliveryCode = $this->entry->getPartner()->getDefaultDeliveryCode(); $renderer->lastModified = time(); // Handle caching $canCacheAccessControl = false; if (kConf::hasParam("force_caching_headers") && in_array($this->entry->getPartnerId(), kConf::get("force_caching_headers"))) { $renderer->cachingHeadersAge = 60; $renderer->forceCachingHeaders = true; } if (!$this->secureEntryHelper) { $canCacheAccessControl = true; // TODO: reconsider this if/when expired ktokens will be used } else { if (!$this->secureEntryHelper->shouldDisableCache() && !$this->secureEntryHelper->isKsAdmin() && ($this->secureEntryHelper->isKsWidget() || !$this->secureEntryHelper->hasRules())) { $canCacheAccessControl = true; } } if (!$renderer->tokenizer && $canCacheAccessControl) { // Note: kApiCache::hasExtraFields is checked in kManifestRenderers $renderer->cachingHeadersAge = 60; } if (!$this->secureEntryHelper || !$this->secureEntryHelper->shouldDisableCache()) { $cache = kPlayManifestCacher::getInstance(); $cache->storeRendererToCache($renderer); } // Output the response KExternalErrors::terminateDispatch(); $renderer->output($deliveryCode, $playbackContext); }
public function cloneAttributes(DeliveryProfileDynamicAttributes $newObj) { $this->deliveryProfileIds = $newObj->getDeliveryProfileIds(); $this->isDeliveryProfilesBlockedList = $newObj->getIsDeliveryProfilesBlockedList(); $this->format = $newObj->getFormat(); $this->extension = $newObj->getFileExtension(); $this->containerFormat = $newObj->getContainerFormat(); $this->seekFromTime = $newObj->getSeekFromTime(); $this->clipTo = $newObj->getClipTo(); $this->playbackRate = $newObj->getPlaybackRate(); $this->storageId = $newObj->getStorageId(); $this->entryId = $newObj->getEntryId(); $this->tags = $newObj->getTags(); $this->flavorAssets = $newObj->getFlavorAssets(); $this->remoteFileSyncs = $newObj->getRemoteFileSyncs(); $this->manifestFileSync = $newObj->getManifestFileSync(); $this->preferredBitrate = $newObj->getPreferredBitrate(); $this->responseFormat = $newObj->getResponseFormat(); $this->mediaProtocol = $newObj->getMediaProtocol(); $this->usePlayServer = $newObj->getUsePlayServer(); $this->playerConfig = $newObj->getPlayerConfig(); $this->uiConfId = $newObj->getUiConfId(); $this->edgeServerIds = $newObj->getEdgeServerIds(); }