public function buildServeFlavors() { $flavors = array(); $baseUrl = $this->liveStreamConfig->getUrl(); $flavors[] = $this->getFlavorAssetInfo('', $baseUrl); // passing the url as urlPrefix so that only the path will be tokenized return $flavors; }
public function doServe(kLiveStreamConfiguration $liveStreamConfig) { $flavors = array(); $baseUrl = $liveStreamConfig->getUrl(); $this->finalizeUrls($baseUrl, $flavors); $flavors[] = $this->getFlavorAssetInfo('', $baseUrl); // passing the url as urlPrefix so that only the path will be tokenized $renderer = $this->getRenderer($flavors); return $renderer; }
public function doServe(kLiveStreamConfiguration $liveStreamConfig) { $flavors = $this->buildRtmpLiveStreamFlavorsArray(); $baseUrl = $liveStreamConfig->getUrl(); $this->finalizeUrls($baseUrl, $flavors); $renderer = $this->getRenderer($flavors); $renderer->baseUrl = $baseUrl; $renderer->streamType = kF4MManifestRenderer::PLAY_STREAM_TYPE_LIVE; return $renderer; }
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; }
/** * Add new pushPublish configuration to entry * * @action addLiveStreamPushPublishConfiguration * @param string $entryId * @param KalturaPlaybackProtocol $protocol * @param string $url * @param KalturaLiveStreamConfiguration $liveStreamConfiguration * @return KalturaLiveStreamEntry * @throws KalturaErrors::INVALID_ENTRY_ID */ public function addLiveStreamPushPublishConfigurationAction($entryId, $protocol, $url = null, KalturaLiveStreamConfiguration $liveStreamConfiguration = null) { $this->dumpApiRequest($entryId); $entry = entryPeer::retrieveByPK($entryId); if (!$entry || $entry->getType() != entryType::LIVE_STREAM) { throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_ID); } //Should not allow usage of both $url and $liveStreamConfiguration if ($url && !is_null($liveStreamConfiguration)) { throw new KalturaAPIException(KalturaErrors::SERVICE_FORBIDDEN); } /* @var $entry LiveEntry */ $pushPublishConfigurations = $entry->getPushPublishPlaybackConfigurations(); $configuration = null; if ($url) { $configuration = new kLiveStreamConfiguration(); $configuration->setProtocol($protocol); $configuration->setUrl($url); } elseif (!is_null($liveStreamConfiguration)) { $configuration = $liveStreamConfiguration->toInsertableObject(); $configuration->setProtocol($protocol); } if ($configuration) { $pushPublishConfigurations[] = $configuration; $entry->setPushPublishPlaybackConfigurations($pushPublishConfigurations); $entry->save(); } $apiEntry = KalturaEntryFactory::getInstanceByType($entry->getType()); $apiEntry->fromObject($entry, $this->getResponseProfile()); return $apiEntry; }
/** * @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(); } $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; }
/** * @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; }
public function doServe(kLiveStreamConfiguration $liveStreamConfig) { $baseUrl = $liveStreamConfig->getUrl(); $backupUrl = $liveStreamConfig->getBackupUrl(); $entry = entryPeer::retrieveByPK($this->params->getEntryId()); /* @var $entry LiveEntry */ if ($entry && $entry->getSyncDCs()) { $baseUrl = str_replace('_all.smil', '_publish.smil', $baseUrl); if ($backupUrl) { $backupUrl = str_replace('_all.smil', '_publish.smil', $backupUrl); } } if ($this->params->getUsePlayServer()) { $liveStreamConfig->setUrl($this->getPlayServerUrl($baseUrl)); $liveStreamConfig->setBackupUrl(null); } if (!$liveStreamConfig->getBackupUrl() && !$this->getForceProxy() || $this->params->getUsePlayServer() || $liveStreamConfig->getIsExternalStream()) { return parent::doServe($liveStreamConfig); } $flavors = array(); $this->buildM3u8Flavors($baseUrl, $flavors); if ($backupUrl) { $this->buildM3u8Flavors($backupUrl, $flavors); } foreach ($flavors as $index => $flavor) { $flavors[$index]['index'] = $index; } usort($flavors, array($this, 'compareFlavors')); foreach ($flavors as $index => $flavor) { unset($flavors[$index]['index']); } $this->DEFAULT_RENDERER_CLASS = 'kM3U8ManifestRenderer'; $renderer = $this->getRenderer($flavors); return $renderer; }
public function populateEntryFromData(LiveStreamEntry $entry) { $configurations = array(); foreach ($this->provisioningParams as $key => $provisioningParam) { switch ($key) { case self::HDS_URLS: $urls = unserialize($provisioningParam); $configuration = new kLiveStreamConfiguration(); $configuration->setProtocol(PlaybackProtocol::HDS); $configuration->setUrl($urls[self::PLAYBACK]); $configuration->setPublishUrl($urls[self::PUBLISH]); $configurations[] = $configuration; break; case self::APPLE_HTTP_URLS: $urls = unserialize($provisioningParam); $configuration = new kLiveStreamConfiguration(); $configuration->setProtocol(PlaybackProtocol::APPLE_HTTP); $configuration->setUrl($urls[self::PLAYBACK]); $configuration->setPublishUrl($urls[self::PUBLISH]); $configurations[] = $configuration; break; case self::SL_URLS: $urls = unserialize($provisioningParam); $configuration = new kLiveStreamConfiguration(); $configuration->setProtocol(PlaybackProtocol::SILVER_LIGHT); $configuration->setUrl($urls[self::PLAYBACK]); $configuration->setPublishUrl($urls[self::PUBLISH]); $configurations[] = $configuration; break; } } $entry->setLiveStreamConfigurations($configurations); }
public function populateEntryFromData(LiveStreamEntry $entry) { $entry->setStreamUsername($this->getEncoderUsername()); $entry->setStreamRemoteId($this->getStreamID()); $entry->setPrimaryBroadcastingUrl($this->getPrimaryBroadcastingUrl()); $entry->setSecondaryBroadcastingUrl($this->getSecondaryBroadcastingUrl()); $entry->setStreamName($this->getStreamName() . "_1_%i@" . $entry->getStreamRemoteId()); if (isset($this->basePlaybackUrls[PlaybackProtocol::APPLE_HTTP])) { $baseHlsUrl = $this->basePlaybackUrls[PlaybackProtocol::APPLE_HTTP]; } else { $baseHlsUrl = "http://" . ($this->getDomainName() ? $this->getDomainName() : self::DEFAULT_DOMAIN_NAME) . "/i/"; } $entry->setHlsStreamUrl($baseHlsUrl . $this->getStreamName() . "_1@" . $this->getStreamID() . "/master.m3u8"); $configs = $entry->getLiveStreamConfigurations(); $config = new kLiveStreamConfiguration(); $config->setProtocol(PlaybackProtocol::AKAMAI_HDS); if (isset($this->basePlaybackUrls[PlaybackProtocol::AKAMAI_HDS])) { $baseHdsUrl = $this->basePlaybackUrls[PlaybackProtocol::AKAMAI_HDS]; } else { $baseHdsUrl = "http://" . ($this->getDomainName() ? $this->getDomainName() : self::DEFAULT_DOMAIN_NAME) . "/z/"; } $config->setUrl($baseHdsUrl . $this->getStreamName() . "_1@" . $this->getStreamID() . "/manifest.f4m"); $configs[] = $config; $entry->setLiveStreamConfigurations($configs); }