/** * 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); }
/** * This action delivers entry-related data, based on the user's context: access control, restriction, playback format and storage information. * @action getContextData * @param string $entryId * @param KalturaEntryContextDataParams $contextDataParams * @return KalturaEntryContextDataResult */ public function getContextData($entryId, KalturaEntryContextDataParams $contextDataParams) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $ks = $this->getKs(); $isAdmin = false; if ($ks) { $isAdmin = $ks->isAdmin(); } $accessControl = $dbEntry->getAccessControl(); /* @var $accessControl accessControl */ $result = new KalturaEntryContextDataResult(); $result->isAdmin = $isAdmin; $result->isScheduledNow = $dbEntry->isScheduledNow($contextDataParams->time); if ($dbEntry->getStartDate() && abs($dbEntry->getStartDate(null) - time()) <= 86400 || $dbEntry->getEndDate() && abs($dbEntry->getEndDate(null) - time()) <= 86400) { KalturaResponseCacher::setConditionalCacheExpiry(600); } if ($accessControl && $accessControl->hasRules()) { $disableCache = true; if (kConf::hasMap("optimized_playback")) { $partnerId = $accessControl->getPartnerId(); $optimizedPlayback = kConf::getMap("optimized_playback"); if (array_key_exists($partnerId, $optimizedPlayback)) { $params = $optimizedPlayback[$partnerId]; if (array_key_exists('cache_kdp_acccess_control', $params) && $params['cache_kdp_acccess_control']) { $disableCache = false; } } } $accessControlScope = $accessControl->getScope(); $contextDataParams->toObject($accessControlScope); $accessControlScope->setEntryId($entryId); $result->isAdmin = $accessControlScope->getKs() && $accessControlScope->getKs()->isAdmin(); $dbResult = new kEntryContextDataResult(); if ($accessControl->applyContext($dbResult) && $disableCache) { KalturaResponseCacher::disableCache(); } $result->fromObject($dbResult); } $partner = PartnerPeer::retrieveByPK($dbEntry->getPartnerId()); if (PermissionPeer::isValidForPartner(PermissionName::FEATURE_REMOTE_STORAGE_DELIVERY_PRIORITY, $dbEntry->getPartnerId()) && $partner->getStorageServePriority() != StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) { if (is_null($contextDataParams->flavorAssetId)) { if ($contextDataParams->flavorTags) { $assets = assetPeer::retrieveReadyByEntryIdAndTag($entryId, $contextDataParams->flavorTags); $asset = reset($assets); } else { $asset = assetPeer::retrieveBestPlayByEntryId($entryId); } if (!$asset) { throw new KalturaAPIException(KalturaErrors::NO_FLAVORS_FOUND, $entryId); } } else { $asset = assetPeer::retrieveByPK($contextDataParams->flavorAssetId); if (!$asset) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $contextDataParams->flavorAssetId); } } if (!$asset) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $entryId); } $assetSyncKey = $asset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET); $fileSyncs = kFileSyncUtils::getAllReadyExternalFileSyncsForKey($assetSyncKey); $storageProfilesXML = new SimpleXMLElement("<StorageProfiles/>"); foreach ($fileSyncs as $fileSync) { $storageProfileId = $fileSync->getDc(); $storageProfile = StorageProfilePeer::retrieveByPK($storageProfileId); if (!$storageProfile->getDeliveryRmpBaseUrl() && (!$contextDataParams->streamerType || $contextDataParams->streamerType == StorageProfile::PLAY_FORMAT_AUTO)) { $contextDataParams->streamerType = StorageProfile::PLAY_FORMAT_HTTP; $contextDataParams->mediaProtocol = StorageProfile::PLAY_FORMAT_HTTP; } $storageProfileXML = $storageProfilesXML->addChild("StorageProfile"); $storageProfileXML->addAttribute("storageProfileId", $storageProfileId); $storageProfileXML->addChild("Name", $storageProfile->getName()); $storageProfileXML->addChild("SystemName", $storageProfile->getSystemName()); } $result->storageProfilesXML = $storageProfilesXML->saveXML(); } if ($contextDataParams->streamerType && $contextDataParams->streamerType != StorageProfile::PLAY_FORMAT_AUTO) { $result->streamerType = $contextDataParams->streamerType; $result->mediaProtocol = $contextDataParams->mediaProtocol ? $contextDataParams->mediaProtocol : $contextDataParams->streamerType; } else { $result->streamerType = $this->getPartner()->getStreamerType(); if (!$result->streamerType) { $result->streamerType = StorageProfile::PLAY_FORMAT_HTTP; } $result->mediaProtocol = $this->getPartner()->getMediaProtocol(); if (!$result->mediaProtocol) { $result->mediaProtocol = StorageProfile::PLAY_FORMAT_HTTP; } } return $result; }