protected static function getAssetUrl(asset $asset)
 {
     $urlManager = DeliveryProfilePeer::getDeliveryProfile($asset->getEntryId());
     if ($asset instanceof flavorAsset) {
         $urlManager->initDeliveryDynamicAttributes(null, $asset);
     }
     $url = $urlManager->getFullAssetUrl($asset);
     $url = preg_replace('/^https?:\\/\\//', '', $url);
     $url = 'http://' . $url . '/ext/' . $asset->getId() . '.' . $asset->getFileExt();
     return $url;
 }
Exemplo n.º 2
0
 private function getCacheLocationByDeliveryType($deliveryType = null)
 {
     if (!$deliveryType) {
         return self::EDGE_SERVER_DEFAULT_LIVE_CACHE_APPLICATION_NAME;
     }
     $liveDeliveryTypes = DeliveryProfilePeer::getAllLiveDeliveryProfileTypes();
     if (!in_array($deliveryType, $liveDeliveryTypes)) {
         return self::EDGE_SERVER_DEFAULT_VOD_CACHE_APPLICATION_NAME;
     }
     return self::EDGE_SERVER_DEFAULT_LIVE_CACHE_APPLICATION_NAME;
 }
Exemplo n.º 3
0
 public function getExternalUrl($entryId, $format = PlaybackProtocol::HTTP)
 {
     $storage = StorageProfilePeer::retrieveByPK($this->getDc());
     if (!$storage || $storage->getProtocol() == StorageProfile::STORAGE_KALTURA_DC) {
         return kDataCenterMgr::getInternalRemoteUrl($this);
     }
     $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($this->getDc(), $entryId, PlaybackProtocol::HTTP, infraRequestUtils::getProtocol()));
     if (is_null($urlManager) && infraRequestUtils::getProtocol() != 'http') {
         $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($this->getDc(), $entryId));
     }
     if (is_null($urlManager)) {
         return null;
     }
     $url = $urlManager->getFileSyncUrl($this);
     $baseUrl = $urlManager->getUrl();
     $url = ltrim($url, "/");
     if (strpos($url, "://") === false) {
         $url = rtrim($baseUrl, "/") . "/" . $url;
     }
     return $url;
 }
Exemplo n.º 4
0
 protected function internalFulfilled(kScope $scope)
 {
     $profileIds = array();
     foreach ($this->deliveryProfileIds as $profileId) {
         $profileIds[] = $profileId->getValue();
     }
     KalturaLog::debug("Delivery profile ids [" . print_r($profileIds, true) . "]");
     $requestOrigin = @$_SERVER['HTTP_X_FORWARDED_HOST'];
     if (!$requestOrigin) {
         $requestOrigin = @$_SERVER['HTTP_HOST'];
     }
     $deliveryProfiles = DeliveryProfilePeer::retrieveByPKs($profileIds);
     foreach ($deliveryProfiles as $deliveryProfile) {
         /**
          * @var DeliveryProfile $deliveryProfile
          */
         $recognizer = $deliveryProfile->getRecognizer();
         if ($recognizer && $recognizer->isRecognized($requestOrigin)) {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 5
0
 private function serveLiveEntry()
 {
     if (in_array($this->entry->getSource(), LiveEntry::$kalturaLiveSourceTypes)) {
         if (!$this->entry->hasMediaServer()) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_LIVE, "Entry [{$this->entryId}] is not broadcasting");
         }
         kApiCache::setExpiry(120);
     }
     $liveStreamConfig = $this->getLiveEntryStreamConfig();
     if (!$liveStreamConfig) {
         KExternalErrors::dieError(KExternalErrors::LIVE_STREAM_CONFIG_NOT_FOUND, "Live stream playbck configuration not found for entry [{$this->entryId}]");
     }
     $cdnHost = parse_url($liveStreamConfig->getUrl(), PHP_URL_HOST);
     if ($this->deliveryAttributes->getFormat() == PlaybackProtocol::MULTICAST_SL) {
         $this->deliveryAttributes->setFormat(PlaybackProtocol::HDS);
     }
     $this->deliveryProfile = DeliveryProfilePeer::getLiveDeliveryProfileByHostName($cdnHost, $this->deliveryAttributes);
     if (!$this->deliveryProfile) {
         return null;
     }
     $this->deliveryProfile->setDynamicAttributes($this->deliveryAttributes);
     return $this->deliveryProfile->serve($liveStreamConfig);
 }
Exemplo n.º 6
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(DeliveryProfilePeer::DATABASE_NAME);
         $criteria->add(DeliveryProfilePeer::ID, $pks, Criteria::IN);
         $objs = DeliveryProfilePeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Exemplo n.º 7
0
 /**
  * Builds a Criteria object containing the primary key for this object.
  *
  * Unlike buildCriteria() this method includes the primary key values regardless
  * of whether or not they have been modified.
  *
  * @return     Criteria The Criteria object containing value(s) for primary key(s).
  */
 public function buildPkeyCriteria()
 {
     $criteria = new Criteria(DeliveryProfilePeer::DATABASE_NAME);
     $criteria->add(DeliveryProfilePeer::ID, $this->id);
     if ($this->alreadyInSave) {
         if ($this->isColumnModified(DeliveryProfilePeer::CUSTOM_DATA)) {
             if (!is_null($this->custom_data_md5)) {
                 $criteria->add(DeliveryProfilePeer::CUSTOM_DATA, "MD5(cast(" . DeliveryProfilePeer::CUSTOM_DATA . " as char character set latin1)) = '{$this->custom_data_md5}'", Criteria::CUSTOM);
             } else {
                 $criteria->add(DeliveryProfilePeer::CUSTOM_DATA, NULL, Criteria::ISNULL);
             }
         }
         if (count($this->modifiedColumns) == 2 && $this->isColumnModified(DeliveryProfilePeer::UPDATED_AT)) {
             $theModifiedColumn = null;
             foreach ($this->modifiedColumns as $modifiedColumn) {
                 if ($modifiedColumn != DeliveryProfilePeer::UPDATED_AT) {
                     $theModifiedColumn = $modifiedColumn;
                 }
             }
             $atomicColumns = DeliveryProfilePeer::getAtomicColumns();
             if (in_array($theModifiedColumn, $atomicColumns)) {
                 $criteria->add($theModifiedColumn, $this->getByName($theModifiedColumn, BasePeer::TYPE_COLNAME), Criteria::NOT_EQUAL);
             }
         }
     }
     return $criteria;
 }
Exemplo n.º 8
0
 /**
  * Ensure the request for media arrived in a way approved by the partner.
  * this may include restricting to a specific cdn, enforcing token usage etc..
  * Die in case of a breach.
  * 
  * @param entry $entry
  * @param asset $asset
  */
 public static function enforceDelivery($entry, $asset = null)
 {
     // block inactive partner
     $partnerId = $entry->getPartnerId();
     self::blockInactivePartner($partnerId);
     // validate serve access control
     $flavorParamsId = $asset ? $asset->getFlavorParamsId() : null;
     $secureEntryHelper = new KSecureEntryHelper($entry, null, null, ContextType::SERVE);
     $secureEntryHelper->validateForServe($flavorParamsId);
     // enforce delivery
     $partner = PartnerPeer::retrieveByPK($partnerId);
     // Note: Partner was already loaded by blockInactivePartner, no need to check for null
     $restricted = DeliveryProfilePeer::isRequestRestricted($partner);
     if ($restricted) {
         KalturaLog::log("DELIVERY_METHOD_NOT_ALLOWED partner [{$partnerId}]");
         KExternalErrors::dieError(KExternalErrors::DELIVERY_METHOD_NOT_ALLOWED);
     }
 }
Exemplo n.º 9
0
 public static function getCoreDeliveryProfileInstanceByType($type)
 {
     $coreType = kPluginableEnumsManager::apiToCore('DeliveryProfileType', $type);
     $class = DeliveryProfilePeer::getClassByDeliveryProfileType($coreType);
     return new $class();
 }
Exemplo n.º 10
0
 public function getExternalUrl($storageId, $fileName = null)
 {
     $key = $this->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storageId);
     if (!$fileSync || $fileSync->getStatus() != FileSync::FILE_SYNC_STATUS_READY) {
         return null;
     }
     $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc());
     if (!$storage) {
         return null;
     }
     $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $this->getEntryId()), $fileSync, $this);
     if (is_null($urlManager)) {
         return null;
     }
     $url = ltrim($urlManager->getFileSyncUrl($fileSync), "/");
     if (strpos($url, "://") === false) {
         $url = rtrim($urlManager->getUrl(), "/") . "/" . $url;
     }
     $url = $this->finalizeDownloadUrl($fileSync, $url, $fileName, true);
     return $url;
 }
function createDelivery($key, $type, &$urlManager)
{
    $deliveryType = $type[0];
    $streamerType = $type[1];
    $deliveryProfileClz = DeliveryProfilePeer::getClassByDeliveryProfileType($deliveryType);
    $deliveryProfile = new $deliveryProfileClz();
    $typename = preg_split('/(?=[A-Z])/', $deliveryProfileClz);
    $name = $key . " " . implode(" ", $typename);
    $deliveryProfile->setName($name);
    $deliveryProfile->setSystemName($name);
    $deliveryProfile->setDescription($name);
    $deliveryProfile->setType($deliveryType);
    $deliveryProfile->setStreamerType($streamerType);
    $deliveryProfile->setUrl($key);
    $deliveryProfile->setIsDefault(false);
    $deliveryProfile->setPartnerId(0);
    switch ($deliveryType) {
        case DeliveryProfileType::AKAMAI_HTTP:
            $host = find("params.http_header_host", $urlManager);
            if ($host) {
                $recognizer = new kUrlRecognizer();
                $recognizer->setHosts(explode(",", $host));
                $deliveryProfile->setRecognizer($recognizer);
            }
            $useIntelliseek = find("params.enable_intelliseek", $urlManager);
            if ($useIntelliseek) {
                $deliveryProfile->setUseIntelliseek(true);
            }
            break;
        case DeliveryProfileType::AKAMAI_RTSP:
            $host = find("params.rtsp_host", $urlManager);
            if ($host) {
                $deliveryProfile->setUrl($host);
            }
            break;
        case DeliveryProfileType::AKAMAI_RTMP:
            $enforce = find("params.enforce_rtmpe", $urlManager);
            if ($enforce) {
                $deliveryProfile->setEnforceRtmpe($enforce);
            }
            break;
        case DeliveryProfileType::AKAMAI_HD:
            $host = find("params.hd_flash", $urlManager);
            if ($host) {
                $deliveryProfile->setUrl($host);
            }
            break;
        case DeliveryProfileType::AKAMAI_HDS:
            $host = find("params.hd_secure_hds", $urlManager);
            if ($host) {
                $deliveryProfile->setUrl($host);
            }
            break;
        case DeliveryProfileType::AKAMAI_HLS_MANIFEST:
            $host = find("params.hd_ios", $urlManager);
            if ($host) {
                $deliveryProfile->setUrl($host);
            }
            $host = find("params.hd_secure_ios", $urlManager);
            if ($host) {
                $deliveryProfile->setUrl($host);
            }
            break;
    }
    return $deliveryProfile;
}
Exemplo n.º 12
0
 private static function addIsmLink(entry $entry, SimpleXMLElement $mrss)
 {
     if (self::$addedIsmUrl) {
         return;
     }
     self::$addedIsmUrl = true;
     $syncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
     $kalturaFileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey);
     $urlManager = DeliveryProfilePeer::getDeliveryProfile($entry->getId(), PlaybackProtocol::SILVER_LIGHT);
     if (!$urlManager) {
         return;
     }
     $urlManager->initDeliveryDynamicAttributes($kalturaFileSync);
     $partner = $entry->getPartner();
     if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) {
         if ($kalturaFileSync) {
             $urlPrefix = $urlManager->getUrl();
             $url = $urlManager->getFileSyncUrl($kalturaFileSync, false);
             $mrss->addChild('ismUrl', $urlPrefix . $url);
             return;
         }
     }
     if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) {
         return null;
     }
     $externalFileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey);
     if ($externalFileSync) {
         $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($externalFileSync->getDc(), $entry->getId(), PlaybackProtocol::SILVER_LIGHT));
         if (is_null($urlManager)) {
             return;
         }
         $url = $urlManager->getFileSyncUrl($externalFileSync, false);
         $urlPrefix = $urlManager->getUrl();
         $mrss->addChild('ismUrl', $urlPrefix . $url);
         return;
     }
     if ($partner->getStorageServePriority() != StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY) {
         if ($kalturaFileSync) {
             $url = $urlManager->getFileSyncUrl($kalturaFileSync, false);
             $mrss->addChild('ismUrl', $urlPrefix . $url);
             return;
         }
     }
 }
Exemplo n.º 13
0
 public static function enforceDelivery($partnerId)
 {
     $partner = PartnerPeer::retrieveByPK($partnerId);
     if (!$partner) {
         return;
     }
     $restricted = DeliveryProfilePeer::isRequestRestricted($partner);
     if ($restricted) {
         KalturaLog::log("DELIVERY_METHOD_NOT_ALLOWED partner [{$partnerId}]");
         KExternalErrors::dieError(KExternalErrors::DELIVERY_METHOD_NOT_ALLOWED);
     }
 }
 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;
 }
Exemplo n.º 15
0
 /**
  * Retrieve a list of available delivery depends on the filter given
  *
  * @action list
  * @param KalturaDeliveryProfileFilter $filter
  * @param KalturaFilterPager $pager
  * @return KalturaDeliveryProfileListResponse
  */
 function listAction(KalturaDeliveryProfileFilter $filter = null, KalturaFilterPager $pager = null)
 {
     if (!$filter) {
         $filter = new KalturaDeliveryProfileFilter();
     }
     if (!$pager) {
         $pager = new KalturaFilterPager();
     }
     $delivery = new DeliveryProfileFilter();
     $filter->toObject($delivery);
     DeliveryProfilePeer::setUseCriteriaFilter(false);
     $c = new Criteria();
     $c->add(DeliveryProfilePeer::PARTNER_ID, array(0, kCurrentContext::getCurrentPartnerId()), Criteria::IN);
     $delivery->attachToCriteria($c);
     $totalCount = DeliveryProfilePeer::doCount($c);
     $pager->attachToCriteria($c);
     $dbList = DeliveryProfilePeer::doSelect($c);
     DeliveryProfilePeer::setUseCriteriaFilter(true);
     $objects = KalturaDeliveryProfileArray::fromDbArray($dbList, $this->getResponseProfile());
     $response = new KalturaDeliveryProfileListResponse();
     $response->objects = $objects;
     $response->totalCount = $totalCount;
     return $response;
 }
Exemplo n.º 16
0
 private function serveLiveEntry()
 {
     if (in_array($this->entry->getSource(), LiveEntry::$kalturaLiveSourceTypes)) {
         if (!$this->entry->hasMediaServer()) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_LIVE, "Entry [{$this->entryId}] is not broadcasting");
         }
         kApiCache::setExpiry(120);
     }
     list($baseUrl, $backupUrl) = $this->getLiveEntryBaseUrls();
     $cdnHost = parse_url($baseUrl, PHP_URL_HOST);
     if ($this->deliveryAttributes->getFormat() == PlaybackProtocol::MULTICAST_SL) {
         $this->deliveryAttributes->setFormat(PlaybackProtocol::HDS);
     }
     $this->deliveryProfile = DeliveryProfilePeer::getLiveDeliveryProfileByHostName($cdnHost, $this->deliveryAttributes);
     if (!$this->deliveryProfile) {
         return null;
     }
     $this->deliveryProfile->setDynamicAttributes($this->deliveryAttributes);
     return $this->deliveryProfile->serve($baseUrl, $backupUrl);
 }
Exemplo n.º 17
0
 private function setContextDataStorageProfilesXml()
 {
     if (PermissionPeer::isValidForPartner(PermissionName::FEATURE_REMOTE_STORAGE_DELIVERY_PRIORITY, $this->entry->getPartnerId()) && $this->partner->getStorageServePriority() != StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) {
         $asset = reset($this->allowedFlavorAssets);
         if (!$asset) {
             return;
         }
         $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);
             $deliveryProfileRtmp = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($storageProfileId, $this->entry, PlaybackProtocol::RTMP));
             if (is_null($deliveryProfileRtmp) && (!$this->streamerType || $this->streamerType == PlaybackProtocol::AUTO)) {
                 $this->streamerType = PlaybackProtocol::HTTP;
                 $this->mediaProtocol = PlaybackProtocol::HTTP;
             }
             $storageProfileXML = $storageProfilesXML->addChild("StorageProfile");
             $storageProfileXML->addAttribute("storageProfileId", $storageProfileId);
             $storageProfileXML->addChild("Name", $storageProfile->getName());
             $storageProfileXML->addChild("SystemName", $storageProfile->getSystemName());
         }
         $this->storageProfilesXML = $storageProfilesXML->saveXML();
     }
 }
Exemplo n.º 18
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);
 }
Exemplo n.º 19
0
 /**
  * Creates default criteria filter
  */
 public static function setDefaultCriteriaFilter()
 {
     if (self::$s_criteria_filter == null) {
         self::$s_criteria_filter = new criteriaFilter();
     }
     $c = new myCriteria();
     // We'd like to retrieve only active delivery profiles, and the ones we consider to remove but haven't removed yet.
     $c->addAnd(DeliveryProfilePeer::STATUS, array(DeliveryStatus::ACTIVE, DeliveryStatus::STAGING_OUT), Criteria::IN);
     self::$s_criteria_filter->setFilter($c);
 }
Exemplo n.º 20
0
 private static function getExternalStorageUrl(Partner $partner, asset $asset, FileSyncKey $key, $servePlayManifest = false, $playManifestClientTag = null, $storageId = null)
 {
     if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) {
         return null;
     }
     if (is_null($storageId) && $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) {
         if (kFileSyncUtils::getReadyInternalFileSyncForKey($key)) {
             // check if having file sync on kaltura dcs
             return null;
         }
     }
     $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storageId);
     if (!$fileSync) {
         return null;
     }
     $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc());
     if (!$storage) {
         return null;
     }
     if ($servePlayManifest) {
         // in case of an https request, if a delivery profile which supports https doesn't exist use an http cdn api host
         if (infraRequestUtils::getProtocol() == infraRequestUtils::PROTOCOL_HTTPS && DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $asset->getEntryId(), PlaybackProtocol::HTTP, "https"))) {
             $url = requestUtils::getApiCdnHost();
         } else {
             $url = infraRequestUtils::PROTOCOL_HTTP . "://" . kConf::get("cdn_api_host");
         }
         $url .= $asset->getPlayManifestUrl($playManifestClientTag, $storageId);
     } else {
         $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $asset->getEntryId()));
         if ($urlManager) {
             $dynamicAttrs = new DeliveryProfileDynamicAttributes();
             $dynamicAttrs->setFileExtension($asset->getFileExt());
             $dynamicAttrs->setStorageId($fileSync->getDc());
             $urlManager->setDynamicAttributes($dynamicAttrs);
             $url = ltrim($urlManager->getFileSyncUrl($fileSync), '/');
             if (strpos($url, "://") === false) {
                 $url = rtrim($urlManager->getUrl(), "/") . "/" . $url;
             }
         } else {
             KalturaLog::debug("Couldn't determine delivery profile for storage id");
             $url = null;
         }
     }
     return $url;
 }
Exemplo n.º 21
0
 public static function retrieveByTypeAndPks($pks, $type)
 {
     if (!count($pks)) {
         return array();
     }
     $criteria = new Criteria();
     $criteria->add(DeliveryProfilePeer::ID, $pks, Criteria::IN);
     $criteria->add(DeliveryProfilePeer::TYPE, $type);
     return DeliveryProfilePeer::doSelect($criteria);
 }
Exemplo n.º 22
0
<?php

/**
 * This script is used to tokenize a url by a given delivery profile.
 */
require_once dirname(__FILE__) . '/../bootstrap.php';
if (count($argv) != 3) {
    die("Usage: php tokenizeUrl.php <delivery profile id> <url>");
}
$deliveryId = $argv[1];
$url = $argv[2];
$delivery = DeliveryProfilePeer::retrieveByPK($deliveryId);
if (!$delivery) {
    die("ERROR: Delivery profile id " . $deliveryId . " wasn't found");
}
$tokenizer = $delivery->getTokenizer();
if (!$tokenizer) {
    echo "Delivery profile has no tokenizer! \nUrl remains : {$url}";
} else {
    echo $tokenizer->tokenizeSingleUrl($url);
}
 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()) {
         $cdnHost = requestUtils::getApiCdnHost();
         $clientTag = 'feed:' . $this->syndicationFeedDb->getId();
         $url = $cdnHost . $flavorAsset->getPlayManifestUrl($clientTag);
     } else {
         $urlManager = DeliveryProfilePeer::getDeliveryProfile($flavorAsset->getEntryId());
         $urlManager->initDeliveryDynamicAttributes(null, $flavorAsset);
         $url = "http://" . $urlManager->getFullAssetUrl($flavorAsset);
     }
     return $url;
 }
Exemplo n.º 24
0
 /**
  * @param FileSyncKey $key
  * @param string $url
  * @param StorageProfile $externalStorage
  * @return SyncFile
  */
 public static function createReadyExternalSyncFileForKey(FileSyncKey $key, $url, StorageProfile $externalStorage)
 {
     $externalStorageId = $externalStorage->getId();
     KalturaLog::debug("key [{$key}], externalStorage [{$externalStorageId}]");
     $fileRoot = '';
     $deliveryProfile = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($externalStorageId, ''));
     if ($deliveryProfile) {
         $fileRoot = $deliveryProfile->getUrl();
     }
     $filePath = str_replace($fileRoot, '', $url);
     $c = FileSyncPeer::getCriteriaForFileSyncKey($key);
     $c->add(FileSyncPeer::DC, $externalStorageId);
     $fileSync = FileSyncPeer::doSelectOne($c);
     if (!$fileSync) {
         $fileSync = FileSync::createForFileSyncKey($key);
     }
     $fileSync->setDc($externalStorageId);
     $fileSync->setFileRoot($fileRoot);
     $fileSync->setFilePath($filePath);
     $fileSync->setFileSize(-1);
     $fileSync->setStatus(FileSync::FILE_SYNC_STATUS_READY);
     $fileSync->setOriginal(false);
     $fileSync->setFileType(FileSync::FILE_SYNC_FILE_TYPE_URL);
     $fileSync->save();
     kEventsManager::raiseEvent(new kObjectAddedEvent($fileSync));
     return $fileSync;
 }
Exemplo n.º 25
0
 public function execute()
 {
     requestUtils::handleConditionalGet();
     $entry_id = $this->getRequestParameter("entry_id");
     $ks_str = $this->getRequestParameter("ks");
     $base64_referrer = $this->getRequestParameter("referrer");
     $referrer = base64_decode($base64_referrer);
     if (!is_string($referrer)) {
         // base64_decode can return binary data
         $referrer = "";
     }
     $clip_from = $this->getRequestParameter("clip_from", 0);
     // milliseconds
     $clip_to = $this->getRequestParameter("clip_to", 2147483647);
     // milliseconds
     if ($clip_to == 0) {
         $clip_to = 2147483647;
     }
     $request = $_SERVER["REQUEST_URI"];
     // remove dynamic fields from the url so we'll request a single url from the cdn
     $request = str_replace("/referrer/{$base64_referrer}", "", $request);
     $request = str_replace("/ks/{$ks_str}", "", $request);
     $entry = null;
     if ($ks_str) {
         try {
             kCurrentContext::initKsPartnerUser($ks_str);
         } catch (Exception $ex) {
             KExternalErrors::dieError(KExternalErrors::INVALID_KS);
         }
     } else {
         $entry = kCurrentContext::initPartnerByEntryId($entry_id);
         if (!$entry) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
         }
     }
     kEntitlementUtils::initEntitlementEnforcement();
     // workaround the filter which hides all the deleted entries -
     // now that deleted entries are part of xmls (they simply point to the 'deleted' templates), we should allow them here
     if (!$entry) {
         $entry = entryPeer::retrieveByPKNoFilter($entry_id);
     } else {
         if (!kEntitlementUtils::isEntryEntitled($entry)) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
         }
     }
     if (!$entry) {
         KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
     }
     KalturaMonitorClient::initApiMonitor(false, 'keditorservices.flvclipper', $entry->getPartnerId());
     myPartnerUtils::blockInactivePartner($entry->getPartnerId());
     if (PermissionPeer::isValidForPartner(PermissionName::FEATURE_BLOCK_FLVCLIPPER_ACTION, $entry->getPartnerId())) {
         KExternalErrors::dieError(KExternalErrors::ACTION_BLOCKED);
     }
     // set the memory size to be able to serve big files in a single chunk
     ini_set("memory_limit", "64M");
     // set the execution time to be able to serve big files in a single chunk
     ini_set("max_execution_time", 240);
     if ($entry->getType() == entryType::MIX && $entry->getStatus() == entryStatus::DELETED) {
         // because the fiter was turned off - a manual check for deleted entries must be done.
         KExternalErrors::dieGracefully();
     } else {
         if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) {
             $version = $this->getRequestParameter("version", null);
             $width = $this->getRequestParameter("width", -1);
             $height = $this->getRequestParameter("height", -1);
             $crop_provider = $this->getRequestParameter("crop_provider", null);
             $bgcolor = $this->getRequestParameter("bgcolor", "ffffff");
             $type = $this->getRequestParameter("type", 1);
             $quality = $this->getRequestParameter("quality", 0);
             $src_x = $this->getRequestParameter("src_x", 0);
             $src_y = $this->getRequestParameter("src_y", 0);
             $src_w = $this->getRequestParameter("src_w", 0);
             $src_h = $this->getRequestParameter("src_h", 0);
             $vid_sec = $this->getRequestParameter("vid_sec", -1);
             $vid_slice = $this->getRequestParameter("vid_slice", -1);
             $vid_slices = $this->getRequestParameter("vid_slices", -1);
             if ($width == -1 && $height == -1) {
                 $width = 640;
                 $height = 480;
             } else {
                 if ($width == -1) {
                     // if only either width or height is missing reset them to zero, and convertImage will handle them
                     $width = 0;
                 } else {
                     if ($height == -1) {
                         $height = 0;
                     }
                 }
             }
             $tempThumbPath = myEntryUtils::resizeEntryImage($entry, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices);
             kFileUtils::dumpFile($tempThumbPath, null, strpos($tempThumbPath, "_NOCACHE_") === false ? null : 0);
         }
     }
     $audio_only = $this->getRequestParameter("audio_only");
     // milliseconds
     $flavor = $this->getRequestParameter("flavor", 1);
     //
     $flavor_param_id = $this->getRequestParameter("flavor_param_id", null);
     //
     $streamer = $this->getRequestParameter("streamer");
     //
     if (substr($streamer, 0, 4) == "rtmp") {
         // the fms may add .mp4 to the end of the url
         $streamer = "rtmp";
     }
     // grab seek_from_bytes parameter and normalize url
     $seek_from_bytes = $this->getRequestParameter("seek_from_bytes", -1);
     $request = str_replace("/seek_from_bytes/{$seek_from_bytes}", "", $request);
     if ($seek_from_bytes <= 0) {
         $seek_from_bytes = -1;
     }
     // grab seek_from parameter and normalize url
     $seek_from = $this->getRequestParameter("seek_from", -1);
     $request = str_replace("/seek_from/{$seek_from}", "", $request);
     if ($seek_from <= 0) {
         $seek_from = -1;
     }
     $this->dump_from_byte = 0;
     // reset accurate seek from timestamp
     $seek_from_timestamp = -1;
     // backward compatibility
     if ($flavor === "0") {
         // for edit version
         $flavor = "edit";
     }
     if ($flavor === "1" || $flavor === 1) {
         // for play version
         $flavor = null;
     }
     // when flavor is null, we will get a default flavor
     if ($flavor == "edit") {
         $flavorAsset = assetPeer::retrieveBestEditByEntryId($entry->getId());
     } elseif (!is_null($flavor)) {
         $flavorAsset = assetPeer::retrieveById($flavor);
         // when specific asset was request, we don't validate its tags
         if ($flavorAsset && ($flavorAsset->getEntryId() != $entry->getId() || $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY)) {
             $flavorAsset = null;
         }
         // we will throw an error later
     } elseif (is_null($flavor) && !is_null($flavor_param_id)) {
         $flavorAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $flavor_param_id);
         if ($flavorAsset && $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) {
             $flavorAsset = null;
         }
         // we will throw an error later
     } else {
         if ($entry->getSource() == entry::ENTRY_MEDIA_SOURCE_WEBCAM) {
             $flavorAsset = assetPeer::retrieveOriginalByEntryId($entry->getId());
         } else {
             $flavorAsset = assetPeer::retrieveBestPlayByEntryId($entry->getId());
         }
         if (!$flavorAsset) {
             $flavorAssets = assetPeer::retrieveReadyFlavorsByEntryIdAndTag($entry->getId(), flavorParams::TAG_WEB);
             if (count($flavorAssets) > 0) {
                 $flavorAsset = $flavorAssets[0];
             }
         }
     }
     if (is_null($flavorAsset)) {
         KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
     }
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     if (kFileSyncUtils::file_exists($syncKey, false)) {
         $path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey);
     } else {
         list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
         if (is_null($fileSync)) {
             KalturaLog::log("Error - no FileSync for flavor [" . $flavorAsset->getId() . "]");
             KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND);
         }
         if ($fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL) {
             $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $flavorAsset->getEntryId()), null, $flavorAsset);
             if (!$urlManager) {
                 KalturaLog::log("Error - failed to find an HTTP delivery for storage profile [" . $fileSync->getDc() . "]");
                 KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND);
             }
             $url = rtrim($urlManager->getUrl(), '/') . '/' . ltrim($urlManager->getFileSyncUrl($fileSync), '/');
             header('location: ' . $url);
             die;
         }
         $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
         $this->redirect($remoteUrl);
     }
     $flv_wrapper = new myFlvHandler($path);
     $isFlv = $flv_wrapper->isFlv();
     // scrubbing is not allowed within mp4 files
     if (!$isFlv) {
         $seek_from = $seek_from_bytes = -1;
     }
     if ($seek_from !== -1 && $seek_from !== 0) {
         if ($audio_only === '0') {
             // audio_only was explicitly set to 0 - don't attempt to make further automatic investigations
         } elseif ($flv_wrapper->getFirstVideoTimestamp() < 0) {
             $audio_only = true;
         }
         list($bytes, $duration, $first_tag_byte, $to_byte) = $flv_wrapper->clip(0, -1, $audio_only);
         list($bytes, $duration, $from_byte, $to_byte, $seek_from_timestamp) = $flv_wrapper->clip($seek_from, -1, $audio_only);
         $seek_from_bytes = myFlvHandler::FLV_HEADER_SIZE + $flv_wrapper->getMetadataSize($audio_only) + $from_byte - $first_tag_byte;
     }
     // the direct path without a cdn is "http://s3kaltura.s3.amazonaws.com".$entry->getDataPath();
     $extStorageUrl = $entry->getExtStorageUrl();
     if ($extStorageUrl && substr_count($extStorageUrl, 's3kaltura')) {
         // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from
         if ($seek_from_timestamp == -1) {
             $seek_from_timestamp = $seek_from;
         }
         $request_host = parse_url($extStorageUrl, PHP_URL_HOST);
         $akamai_url = str_replace($request_host, "cdns3akmi.kaltura.com", $extStorageUrl);
         $akamai_url .= $seek_from_bytes == -1 ? "" : "?aktimeoffset=" . floor($seek_from_timestamp / 1000);
         header("Location: {$akamai_url}");
         KExternalErrors::dieGracefully();
     } elseif ($extStorageUrl) {
         // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from
         if ($seek_from_timestamp == -1) {
             $seek_from_timestamp = $seek_from;
         }
         $extStorageUrl .= $seek_from_bytes == -1 ? "" : "?aktimeoffset=" . floor($seek_from_timestamp / 1000);
         header("Location: {$extStorageUrl}");
         KExternalErrors::dieGracefully();
     }
     // use headers to detect cdn
     $cdn_name = "";
     $via_header = @$_SERVER["HTTP_VIA"];
     if (strpos($via_header, "llnw.net") !== false) {
         $cdn_name = "limelight";
     } else {
         if (strpos($via_header, "akamai") !== false) {
             $cdn_name = "akamai";
         } else {
             if (strpos($via_header, "Level3") !== false) {
                 $cdn_name = "level3";
             }
         }
     }
     // setting file extension - first trying frrom flavor asset
     $ext = $flavorAsset->getFileExt();
     // if failed, set extension according to file type (isFlv)
     if (!$ext) {
         $ext = $isFlv ? "flv" : "mp4";
     }
     $flv_extension = $streamer == "rtmp" ? "?" : "/a.{$ext}?novar=0";
     // dont check for rtmp / and for an already redirect url
     if ($streamer != "rtmp" && strpos($request, $flv_extension) === false) {
         // check security using ks
         $securyEntryHelper = new KSecureEntryHelper($entry, $ks_str, $referrer, ContextType::PLAY);
         if ($securyEntryHelper->shouldPreview()) {
             $this->checkForPreview($securyEntryHelper, $clip_to);
         } else {
             $securyEntryHelper->validateForPlay($entry, $ks_str);
         }
     } else {
         // if needs security check using cdn authentication mechanism
         // for now assume this is a cdn request and don't check for security
     }
     // use limelight mediavault if either security policy requires it or if we're trying to seek within the video
     if ($entry->getSecurityPolicy() || $seek_from_bytes !== -1) {
         // we have three options:
         // arrived through limelight mediavault url - the url is secured
         // arrived directly through limelight (not secured through mediavault) - enforce ks and redirect to mediavault url
         // didnt use limelight - enforce ks
         // the cdns are configured to authenticate request for /s/....
         // check if we're already in a redirected secure link using the "/s/" prefix
         $secure_request = substr($request, 0, 3) == "/s/";
         if ($secure_request && ($cdn_name == "limelight" || $cdn_name == "level3")) {
             // request was validated by cdn let it through
         } else {
             // extract ks
             $ks_str = $this->getRequestParameter("ks", "");
             if ($entry->getSecurityPolicy()) {
                 if (!$ks_str) {
                     $this->logMessage("flvclipper - no KS");
                     KExternalErrors::dieGracefully();
                 }
                 $ks = kSessionUtils::crackKs($ks_str);
                 if (!$ks) {
                     $this->logMessage("flvclipper - invalid ks [{$ks_str}]");
                     KExternalErrors::dieGracefully();
                 }
                 $matched_privs = $ks->verifyPrivileges("sview", $entry_id);
                 $this->logMessage("flvclipper - verifyPrivileges name [sview], priv [{$entry_id}] [{$matched_privs}]");
                 if (!$matched_privs) {
                     $this->logMessage("flvclipper - doesnt not match required privlieges [{$ks_str}]");
                     KExternalErrors::dieGracefully();
                 }
             }
             if ($cdn_name == "limelight") {
                 $ll_url = requestUtils::getCdnHost() . "/s{$request}" . $flv_extension;
                 $secret = kConf::get("limelight_madiavault_password");
                 $expire = "&e=" . (time() + 120);
                 $ll_url .= $expire;
                 $fs = $seek_from_bytes == -1 ? "" : "&fs={$seek_from_bytes}";
                 $ll_url .= "&h=" . md5("{$secret}{$ll_url}") . $fs;
                 //header("Location: $ll_url");
                 $this->redirect($ll_url);
             } else {
                 if ($cdn_name == "level3") {
                     $level3_url = $request . $flv_extension;
                     if ($entry->getSecurityPolicy()) {
                         $level3_url = "/s{$level3_url}";
                         // set expire time in GMT hence the date("Z") offset
                         $expire = "&nva=" . strftime("%Y%m%d%H%M%S", time() - date("Z") + 30);
                         $level3_url .= $expire;
                         $secret = kConf::get("level3_authentication_key");
                         $hash = "0" . substr(self::hmac('sha1', $secret, $level3_url), 0, 20);
                         $level3_url .= "&h={$hash}";
                     }
                     $level3_url .= $seek_from_bytes == -1 ? "" : "&start={$seek_from_bytes}";
                     header("Location: {$level3_url}");
                     KExternalErrors::dieGracefully();
                 } else {
                     if ($cdn_name == "akamai") {
                         $akamai_url = $request . $flv_extension;
                         // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from
                         if ($seek_from_timestamp == -1) {
                             $seek_from_timestamp = $seek_from;
                         }
                         $akamai_url .= $seek_from_bytes == -1 ? "" : "&aktimeoffset=" . floor($seek_from_timestamp / 1000);
                         header("Location: {$akamai_url}");
                         KExternalErrors::dieGracefully();
                     }
                 }
             }
             // a seek request without a supporting cdn - we need to send the answer from our server
             if ($seek_from_bytes !== -1 && $via_header === null) {
                 $this->dump_from_byte = $seek_from_bytes;
             }
         }
     }
     // always add the file suffix to the request (needed for scrubbing by some cdns,
     // and also breaks without extension on some corporate antivirus).
     // we add the the novar paramter since a leaving a trailing "?" will be trimmed
     // and then the /seek_from request will result in another url which level3
     // will try to refetch from the origin
     // note that for streamer we dont add the file extension
     if ($streamer != "rtmp" && strpos($request, $flv_extension) === false) {
         // a seek request without a supporting cdn - we need to send the answer from our server
         if ($seek_from_bytes !== -1 && $via_header === null) {
             $request .= "/seek_from_bytes/{$seek_from_bytes}";
         }
         requestUtils::sendCdnHeaders("flv", 0);
         header("Location: {$request}" . $flv_extension);
         KExternalErrors::dieGracefully();
     }
     // mp4
     if (!$isFlv) {
         $limit_file_size = 0;
         if ($clip_to != 2147483647) {
             $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId());
             if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) {
                 $duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration());
                 $limit_file_size = floor(@kFile::fileSize($path) * ($clip_to / $duration) * 1.2);
             }
         }
         KalturaLog::info("serving file [{$path}] entry id [{$entry_id}] limit file size [{$limit_file_size}] clip_to [{$clip_to}]");
         kFileUtils::dumpFile($path, null, null, $limit_file_size);
     }
     $this->logMessage("flvclipperAction: serving file [{$path}] entry_id [{$entry_id}] clip_from [{$clip_from}] clip_to [{$clip_to}]", "warning");
     if ($audio_only === '0') {
         // audio_only was explicitly set to 0 - don't attempt to make further automatic investigations
     } elseif ($flv_wrapper->getFirstVideoTimestamp() < 0) {
         $audio_only = true;
     }
     //$start = microtime(true);
     list($bytes, $duration, $from_byte, $to_byte, $from_ts, $cuepoint_pos) = myFlvStaticHandler::clip($path, $clip_from, $clip_to, $audio_only);
     $metadata_size = $flv_wrapper->getMetadataSize($audio_only);
     $this->from_byte = $from_byte;
     $this->to_byte = $to_byte;
     //$end1 = microtime(true);
     //$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" );
     //$this->logMessage( "flvclipperAction: serving file [$path] t1 [" . ( $end1-$start) . "]");
     $data_offset = $metadata_size + myFlvHandler::getHeaderSize();
     // if we're returning a partial file adjust the total size:
     // substract the metadata and bytes which are not delivered
     if ($this->dump_from_byte >= $data_offset && !$audio_only) {
         $bytes -= $metadata_size + max(0, $this->dump_from_byte - $data_offset);
     }
     $this->total_length = $data_offset + $bytes;
     //echo " $bytes , $duration ,$from_byte , $to_byte, $cuepoint_pos\n"; die;
     $this->cuepoint_time = 0;
     $this->cuepoint_pos = 0;
     if ($streamer == "chunked" && $clip_to != 2147483647) {
         $this->cuepoint_time = $clip_to - 1;
         $this->cuepoint_pos = $cuepoint_pos;
         $this->total_length += myFlvHandler::CUEPOINT_TAG_SIZE;
     }
     //$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes with header & md [" . $this->total_length . "] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" );
     $this->flv_wrapper = $flv_wrapper;
     $this->audio_only = $audio_only;
     try {
         Propel::close();
     } catch (Exception $e) {
         $this->logMessage("flvclipperAction: error closing db {$e}");
     }
     KExternalErrors::terminateDispatch();
     return sfView::SUCCESS;
 }
Exemplo n.º 26
0
 private function getCacheLocation($deliveryType = null, $assetType = null)
 {
     if ($assetType && $assetType == assetType::THUMBNAIL) {
         return self::EDGE_SERVER_DEFAULT_THUMBNAIL_CACHE_APPLICATION_NAME;
     }
     if ($assetType && $assetType == assetType::LIVE || !$deliveryType) {
         return self::EDGE_SERVER_DEFAULT_LIVE_CACHE_APPLICATION_NAME;
     }
     $liveDeliveryTypes = DeliveryProfilePeer::getAllLiveDeliveryProfileTypes();
     if (!in_array($deliveryType, $liveDeliveryTypes)) {
         return self::EDGE_SERVER_DEFAULT_VOD_CACHE_APPLICATION_NAME;
     }
     return self::EDGE_SERVER_DEFAULT_LIVE_CACHE_APPLICATION_NAME;
 }
Exemplo n.º 27
0
 public function getFieldNameFromPeer($field_name)
 {
     $res = DeliveryProfilePeer::translateFieldName($field_name, $this->field_name_translation_type, BasePeer::TYPE_COLNAME);
     return $res;
 }