public static function formatGenericUrl($url, $pattern = null, DeliveryProfileDynamicAttributes $params) { if ($pattern) { $seekFromSec = $params->getSeekFromTime() > 0 ? $params->getSeekFromTime() / 1000 : 0; $pattern = str_replace('{url}', $url, $pattern); $pattern = str_replace('{seekFromSec}', $seekFromSec, $pattern); return $pattern; } else { return '/' . $url; // the trailing slash will force adding the host name to the url } }
public static function getExtraParams(DeliveryProfileDynamicAttributes $params) { $result = ''; $seekStart = $params->getSeekFromTime(); if ($seekStart > 0) { $result .= '/clipFrom/' . $seekStart; } $seekEnd = $params->getClipTo(); if ($seekEnd) { $result .= '/clipTo/' . $seekEnd; } $playbackRate = $params->getPlaybackRate(); if ($playbackRate) { $result .= '/speed/' . $playbackRate; } return $result; }
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(); }