/**
  * Returns the default criteria filter
  *
  * @return     criteriaFilter The default criteria filter.
  */
 public static function &getCriteriaFilter()
 {
     if (self::$s_criteria_filter == null) {
         self::setDefaultCriteriaFilter();
     }
     if (self::$instance) {
         self::$instance->setInstanceCriteriaFilter();
     }
     return self::$s_criteria_filter;
 }
 /**
  * return the flavor params the best fits the fileFormat for a given partner_id
  * 
  * @param int $partnerId
  * @param string $fileFormat
  * @return FlavorParams
  */
 public static function getFlavorParamsFromFileFormat($partnerId, $fileFormat, $ignoreSourceTag = true)
 {
     $defaultCriteria = assetParamsPeer::getCriteriaFilter()->getFilter();
     $defaultCriteria->remove(assetParamsPeer::PARTNER_ID);
     //		assetParamsPeer::allowAccessToPartner0AndPartnerX($partnerId); // the flavor params can be from partner 0 too
     $c = new Criteria();
     $c->addAnd(assetParamsPeer::PARTNER_ID, array($partnerId, 0), Criteria::IN);
     //		$c->add (  assetParamsPeer::FORMAT , $fileFormat );
     $possible_flavor_params = assetParamsPeer::doSelect($c);
     myPartnerUtils::resetPartnerFilter('assetParams');
     $best_fp = null;
     foreach ($possible_flavor_params as $fp) {
         if ($fileFormat != $fp->getFormat()) {
             continue;
         }
         if ($ignoreSourceTag && $fp->hasTag(flavorParams::TAG_SOURCE)) {
             continue;
         }
         if (!$best_fp) {
             $best_fp = $fp;
         }
         if ($fp->getPartnerId() != $partnerId) {
             continue;
         }
         // same format for the partner
         $best_fp = $fp;
         break;
     }
     // if not fount any - choose the first flavor params from the list
     if (!$best_fp) {
         $best_fp = $possible_flavor_params[0];
     }
     return $best_fp;
 }
 public function toInsertableObject($object_to_fill = null, $props_to_skip = array())
 {
     if (!is_null($this->thumbParamsId)) {
         $dbAssetParams = assetParamsPeer::retrieveByPK($this->thumbParamsId);
         if ($dbAssetParams) {
             $object_to_fill->setFromAssetParams($dbAssetParams);
         }
     }
     return parent::toInsertableObject($object_to_fill, $props_to_skip);
 }
Exemple #4
0
 /**
  * Creates new download job for multiple entry ids (comma separated), an email will be sent when the job is done
  * This sevice support the following entries: 
  * - MediaEntry
  * 	   - Video will be converted using the flavor params id
  *     - Audio will be downloaded as MP3
  *     - Image will be downloaded as Jpeg
  * - MixEntry will be flattened using the flavor params id
  * - Other entry types are not supported
  * 
  * Returns the admin email that the email message will be sent to 
  * 
  * @action xAddBulkDownload
  * @param string $entryIds Comma separated list of entry ids
  * @param string $flavorParamsId
  * @return string
  */
 public function xAddBulkDownloadAction($entryIds, $flavorParamsId = "")
 {
     $flavorParamsDb = null;
     if ($flavorParamsId !== null && $flavorParamsId != "") {
         $flavorParamsDb = assetParamsPeer::retrieveByPK($flavorParamsId);
         if (!$flavorParamsDb) {
             throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_ID_NOT_FOUND, $flavorParamsId);
         }
     }
     kJobsManager::addBulkDownloadJob($this->getPartnerId(), $this->getKuser()->getPuserId(), $entryIds, $flavorParamsId);
     return $this->getKuser()->getEmail();
 }
 public function toInsertableObject($object_to_fill = null, $props_to_skip = array())
 {
     if (!is_null($this->captionParamsId)) {
         $dbAssetParams = assetParamsPeer::retrieveByPK($this->captionParamsId);
         if ($dbAssetParams) {
             $object_to_fill->setFromAssetParams($dbAssetParams);
         }
     }
     if ($this->format === null && $object_to_fill->getContainerFormat() === null) {
         $this->format = KalturaCaptionType::SRT;
     }
     return parent::toInsertableObject($object_to_fill, $props_to_skip);
 }
 /**
  * Get the associated assetParams object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     assetParams The associated assetParams object.
  * @throws     PropelException
  */
 public function getFlavorParams(PropelPDO $con = null)
 {
     if ($this->aassetParams === null && $this->flavor_params_id !== null) {
         $this->aassetParams = assetParamsPeer::retrieveByPk($this->flavor_params_id);
         /* The following can be used additionally to
         		   guarantee the related object contains a reference
         		   to this object.  This level of coupling may, however, be
         		   undesirable since it could result in an only partially populated collection
         		   in the referenced object.
         		   $this->aassetParams->addassets($this);
         		 */
     }
     return $this->aassetParams;
 }
 protected function doGetListResponse(KalturaFilterPager $pager, array $types = null)
 {
     $flavorParamsFilter = $this->toObject();
     $c = new Criteria();
     $flavorParamsFilter->attachToCriteria($c);
     $pager->attachToCriteria($c);
     if ($types) {
         $c->add(assetParamsPeer::TYPE, $types, Criteria::IN);
     }
     $list = assetParamsPeer::doSelect($c);
     $c->setLimit(null);
     $totalCount = assetParamsPeer::doCount($c);
     return array($list, $totalCount);
 }
 public function toObject($object_to_fill = null, $props_to_skip = array())
 {
     if (!$object_to_fill) {
         $object_to_fill = new assetParamsConversionProfileFilter();
     }
     $conversionProfileCriteria = new Criteria();
     if ($this->conversionProfileIdEqual) {
         $conversionProfileCriteria->add(conversionProfile2Peer::ID, $this->conversionProfileIdEqual);
     }
     if ($this->conversionProfileIdIn) {
         $conversionProfileCriteria->add(conversionProfile2Peer::ID, explode(',', $this->conversionProfileIdIn), Criteria::IN);
     }
     if ($this->conversionProfileIdFilter) {
         $conversionProfileIdFilter = new conversionProfile2Filter();
         $this->conversionProfileIdFilter->toObject($conversionProfileIdFilter);
         $conversionProfileIdFilter->attachToCriteria($conversionProfileCriteria);
     }
     $this->conversionProfileIdEqual = null;
     $this->conversionProfileIdFilter = null;
     $conversionProfileIdIn = conversionProfile2Peer::getIds($conversionProfileCriteria);
     if (count($conversionProfileIdIn)) {
         $this->conversionProfileIdIn = implode(',', $conversionProfileIdIn);
     } else {
         $this->conversionProfileIdIn = -1;
     }
     // none existing conversion profile
     $assetParamsCriteria = new Criteria();
     if ($this->assetParamsIdEqual) {
         $assetParamsCriteria->add(assetParamsPeer::ID, $this->assetParamsIdEqual);
     }
     if ($this->assetParamsIdIn) {
         $assetParamsCriteria->add(assetParamsPeer::ID, explode(',', $this->assetParamsIdIn), Criteria::IN);
     }
     if ($this->assetParamsIdFilter) {
         $assetParamsIdFilter = new assetParamsFilter();
         $this->assetParamsIdFilter->toObject($assetParamsIdFilter);
         $assetParamsIdFilter->attachToCriteria($assetParamsCriteria);
     }
     $this->assetParamsIdEqual = null;
     $this->assetParamsIdFilter = null;
     $assetParamsIdIn = assetParamsPeer::getIds($assetParamsCriteria);
     if (count($assetParamsIdIn)) {
         $this->assetParamsIdIn = implode(',', $assetParamsIdIn);
     } else {
         $this->assetParamsIdIn = -1;
     }
     // none existing flavor
     return parent::toObject($object_to_fill, $props_to_skip);
 }
 /**
  * Add new Syndication Feed
  * 
  * @action add
  * @param KalturaBaseSyndicationFeed $syndicationFeed
  * @return KalturaBaseSyndicationFeed 
  */
 public function addAction(KalturaBaseSyndicationFeed $syndicationFeed)
 {
     $syndicationFeed->validatePlaylistId();
     $syndicationFeed->validateStorageId($this->getPartnerId());
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed) {
         $syndicationFeed->validatePropertyNotNull('xslt');
         $syndicationFeedDB = new genericSyndicationFeed();
         $syndicationFeedDB->incrementVersion();
     } else {
         $syndicationFeedDB = new syndicationFeed();
     }
     $syndicationFeed->toInsertableObject($syndicationFeedDB);
     $syndicationFeedDB->setPartnerId($this->getPartnerId());
     $syndicationFeedDB->setStatus(KalturaSyndicationFeedStatus::ACTIVE);
     $syndicationFeedDB->save();
     if ($syndicationFeed->addToDefaultConversionProfile) {
         $partner = PartnerPeer::retrieveByPK($this->getPartnerId());
         $c = new Criteria();
         $c->addAnd(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $partner->getDefaultConversionProfileId());
         $c->addAnd(flavorParamsConversionProfilePeer::FLAVOR_PARAMS_ID, $syndicationFeed->flavorParamId);
         $is_exist = flavorParamsConversionProfilePeer::doCount($c);
         if (!$is_exist || $is_exist === 0) {
             $assetParams = assetParamsPeer::retrieveByPK($syndicationFeed->flavorParamId);
             $fpc = new flavorParamsConversionProfile();
             $fpc->setConversionProfileId($partner->getDefaultConversionProfileId());
             $fpc->setFlavorParamsId($syndicationFeed->flavorParamId);
             if ($assetParams) {
                 $fpc->setReadyBehavior($assetParams->getReadyBehavior());
                 $fpc->setSystemName($assetParams->getSystemName());
                 if ($assetParams->hasTag(assetParams::TAG_SOURCE) || $assetParams->hasTag(assetParams::TAG_INGEST)) {
                     $fpc->setOrigin(assetParamsOrigin::INGEST);
                 } else {
                     $fpc->setOrigin(assetParamsOrigin::CONVERT);
                 }
             }
             $fpc->save();
         }
     }
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed) {
         $key = $syndicationFeedDB->getSyncKey(genericSyndicationFeed::FILE_SYNC_SYNDICATION_FEED_XSLT);
         kFileSyncUtils::file_put_contents($key, $syndicationFeed->xslt);
     }
     $syndicationFeed->fromObject($syndicationFeedDB, $this->getResponseProfile());
     return $syndicationFeed;
 }
 /**
  * @param string $baseUrl
  * @return array
  */
 protected function buildRtmpLiveStreamFlavorsArray()
 {
     $entry = entryPeer::retrieveByPK($this->params->getEntryId());
     if (in_array($entry->getSource(), LiveEntry::$kalturaLiveSourceTypes)) {
         /* @var $entry LiveEntry */
         $flavors = array(0 => $this->getFlavorAssetInfo($entry->getStreamName()));
         $conversionProfileId = $entry->getConversionProfileId();
         if ($conversionProfileId) {
             $liveParams = assetParamsPeer::retrieveByProfile($conversionProfileId);
             if (count($liveParams)) {
                 $flavors = array();
                 foreach ($liveParams as $index => $liveParamsItem) {
                     /* @var $liveParamsItem liveParams */
                     if ($entry->getLiveStreamConfigurationByProtocol(PlaybackProtocol::RTMP, 'rtmp')) {
                         $configuration = $entry->getLiveStreamConfigurationByProtocol(PlaybackProtocol::RTMP, 'rtmp');
                         $flavors[$index] = $this->getFlavorAssetInfo(str_replace("%i", $liveParamsItem->getId(), $configuration->getStreamName()), '', $liveParamsItem);
                         continue;
                     }
                     $flavors[$index] = $this->getFlavorAssetInfo($entry->getStreamName() . '_' . $liveParamsItem->getId(), '', $liveParamsItem);
                 }
             }
         }
         return $flavors;
     }
     $tmpFlavors = $entry->getStreamBitrates();
     if (count($tmpFlavors)) {
         $flavors = array();
         foreach ($tmpFlavors as $index => $flavor) {
             $brIndex = $index + 1;
             $flavors[$index] = $this->getFlavorAssetInfo(str_replace('%i', $brIndex, $entry->getStreamName()));
             $flavors[$index] = array_merge($flavors[$index], $flavor);
         }
     } else {
         $flavors[0] = $this->getFlavorAssetInfo(str_replace('%i', '1', $entry->getStreamName()));
     }
     return $flavors;
 }
 /**
  * Convert entry
  * 
  * @param string $entryId Media entry id
  * @param int $conversionProfileId
  * @param KalturaConversionAttributeArray $dynamicConversionAttributes
  * @return bigint job id
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  * @throws KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND
  * @throws KalturaErrors::FLAVOR_PARAMS_NOT_FOUND
  */
 protected function convert($entryId, $conversionProfileId = null, KalturaConversionAttributeArray $dynamicConversionAttributes = null)
 {
     $entry = entryPeer::retrieveByPK($entryId);
     if (!$entry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $srcFlavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if (!$srcFlavorAsset) {
         throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING);
     }
     if (is_null($conversionProfileId) || $conversionProfileId <= 0) {
         $conversionProfile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
         if (!$conversionProfile) {
             throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $conversionProfileId);
         }
         $conversionProfileId = $conversionProfile->getId();
     } else {
         //The search is with the entry's partnerId. so if conversion profile wasn't found it means that the
         //conversionId is not exist or the conversion profileId does'nt belong to this partner.
         $conversionProfile = conversionProfile2Peer::retrieveByPK($conversionProfileId);
         if (is_null($conversionProfile)) {
             throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $conversionProfileId);
         }
     }
     $srcSyncKey = $srcFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     // if the file sync isn't local (wasn't synced yet) proxy request to other datacenter
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false);
     if (!$fileSync) {
         throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
     } else {
         if (!$local) {
             kFileUtils::dumpApiRequest(kDataCenterMgr::getRemoteDcExternalUrl($fileSync));
         }
     }
     // even if it null
     $entry->setConversionQuality($conversionProfileId);
     $entry->save();
     if ($dynamicConversionAttributes) {
         $flavors = assetParamsPeer::retrieveByProfile($conversionProfileId);
         if (!count($flavors)) {
             throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_NOT_FOUND);
         }
         $srcFlavorParamsId = null;
         $flavorParams = $entry->getDynamicFlavorAttributes();
         foreach ($flavors as $flavor) {
             if ($flavor->hasTag(flavorParams::TAG_SOURCE)) {
                 $srcFlavorParamsId = $flavor->getId();
             }
             $flavorParams[$flavor->getId()] = $flavor;
         }
         $dynamicAttributes = array();
         foreach ($dynamicConversionAttributes as $dynamicConversionAttribute) {
             if (is_null($dynamicConversionAttribute->flavorParamsId)) {
                 $dynamicConversionAttribute->flavorParamsId = $srcFlavorParamsId;
             }
             if (is_null($dynamicConversionAttribute->flavorParamsId)) {
                 continue;
             }
             $dynamicAttributes[$dynamicConversionAttribute->flavorParamsId][trim($dynamicConversionAttribute->name)] = trim($dynamicConversionAttribute->value);
         }
         if (count($dynamicAttributes)) {
             $entry->setDynamicFlavorAttributes($dynamicAttributes);
             $entry->save();
         }
     }
     $srcFilePath = kFileSyncUtils::getLocalFilePathForKey($srcSyncKey);
     $job = kJobsManager::addConvertProfileJob(null, $entry, $srcFlavorAsset->getId(), $srcFilePath);
     if (!$job) {
         return null;
     }
     return $job->getId();
 }
 public static function copyConversionProfiles(Partner $fromPartner, Partner $toPartner, $permissionRequiredOnly = false)
 {
     $copiedList = array();
     KalturaLog::log("Copying conversion profiles from partner [" . $fromPartner->getId() . "] to partner [" . $toPartner->getId() . "]");
     $c = new Criteria();
     $c->add(conversionProfile2Peer::PARTNER_ID, $fromPartner->getId());
     $conversionProfiles = conversionProfile2Peer::doSelect($c);
     foreach ($conversionProfiles as $conversionProfile) {
         /* @var $conversionProfile conversionProfile2 */
         if ($permissionRequiredOnly && !count($conversionProfile->getRequiredCopyTemplatePermissions())) {
             continue;
         }
         if (!self::isPartnerPermittedForCopy($toPartner, $conversionProfile->getRequiredCopyTemplatePermissions())) {
             continue;
         }
         $newConversionProfile = $conversionProfile->copy();
         $newConversionProfile->setPartnerId($toPartner->getId());
         try {
             $newConversionProfile->save();
         } catch (Exception $e) {
             KalturaLog::info("Exception occured, conversion profile was not copied. Message: [" . $e->getMessage() . "]");
             continue;
         }
         KalturaLog::log("Copied [" . $conversionProfile->getId() . "], new id is [" . $newConversionProfile->getId() . "]");
         $copiedList[$conversionProfile->getId()] = $newConversionProfile->getId();
         $c = new Criteria();
         $c->add(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $conversionProfile->getId());
         $fpcpList = flavorParamsConversionProfilePeer::doSelect($c);
         foreach ($fpcpList as $fpcp) {
             $flavorParamsId = $fpcp->getFlavorParamsId();
             $flavorParams = assetParamsPeer::retrieveByPK($flavorParamsId);
             if ($flavorParams && $flavorParams->getPartnerId() === 0) {
                 $newFpcp = $fpcp->copy();
                 $newFpcp->setConversionProfileId($newConversionProfile->getId());
                 $newFpcp->save();
             }
         }
     }
     // make sure conversion profile is set on the new partner in case it was missed/skiped in the conversionProfile2::copy method
     if (!$toPartner->getDefaultConversionProfileId()) {
         $fromPartnerDefaultProfile = $fromPartner->getDefaultConversionProfileId();
         if ($fromPartnerDefaultProfile && key_exists($fromPartnerDefaultProfile, $copiedList)) {
             $toPartner->setDefaultConversionProfileId($copiedList[$fromPartnerDefaultProfile]);
         }
     }
     if (!$toPartner->getDefaultLiveConversionProfileId()) {
         $fromPartnerDefaultLiveProfile = $fromPartner->getDefaultLiveConversionProfileId();
         if ($fromPartnerDefaultLiveProfile && key_exists($fromPartnerDefaultLiveProfile, $copiedList)) {
             $toPartner->setDefaultLiveConversionProfileId($copiedList[$fromPartnerDefaultLiveProfile]);
         }
     }
     $toPartner->save();
 }
 public static function continueProfileConvert(BatchJob $parentJob)
 {
     $convertProfileJob = $parentJob->getRootJob();
     if ($convertProfileJob->getJobType() != BatchJobType::CONVERT_PROFILE) {
         throw new Exception("Root job [" . $convertProfileJob->getId() . "] is not profile conversion");
     }
     KalturaLog::log("Conversion decision layer continued for entry [" . $parentJob->getEntryId() . "]");
     $convertProfileData = $convertProfileJob->getData();
     $entryId = $convertProfileJob->getEntryId();
     $entry = $convertProfileJob->getEntry();
     if (!$entry) {
         throw new APIException(APIErrors::INVALID_ENTRY, $convertProfileJob, $entryId);
     }
     $profile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     if (!$profile) {
         $errDescription = "Conversion profile for entryId [{$entryId}] not found";
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob->getEntryId(), entryStatus::ERROR_CONVERTING);
         KalturaLog::err("No flavors created: {$errDescription}");
         throw new Exception($errDescription);
     }
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset)) {
         $errDescription = 'Original flavor asset not found';
         KalturaLog::err($errDescription);
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob->getEntryId(), entryStatus::ERROR_CONVERTING);
         throw new Exception($errDescription);
     }
     // gets the list of flavor params of the conversion profile
     $list = flavorParamsConversionProfilePeer::retrieveByConversionProfile($profile->getId());
     if (!count($list)) {
         $errDescription = "No flavors match the profile id [{$profile->getId()}]";
         KalturaLog::err($errDescription);
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob->getEntryId(), entryStatus::ERROR_CONVERTING);
         $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
         $originalFlavorAsset->setDeletedAt(time());
         $originalFlavorAsset->save();
         throw new Exception($errDescription);
     }
     // gets the ids of the flavor params
     $flavorsIds = array();
     $conversionProfileFlavorParams = array();
     foreach ($list as $flavorParamsConversionProfile) {
         $flavorsId = $flavorParamsConversionProfile->getFlavorParamsId();
         $flavorsIds[] = $flavorsId;
         $conversionProfileFlavorParams[$flavorsId] = $flavorParamsConversionProfile;
     }
     $dynamicFlavorAttributes = $entry->getDynamicFlavorAttributes();
     // gets the flavor params by the id
     $flavors = assetParamsPeer::retrieveFlavorsByPKs($flavorsIds);
     $entryIngestedFlavors = explode(',', $entry->getFlavorParamsIds());
     foreach ($flavors as $index => $flavor) {
         if (!isset($conversionProfileFlavorParams[$flavor->getId()])) {
             continue;
         }
         $conversionProfileFlavorParamsItem = $conversionProfileFlavorParams[$flavor->getId()];
         if ($flavor->hasTag(flavorParams::TAG_SOURCE)) {
             unset($flavors[$index]);
             continue;
         }
         if ($conversionProfileFlavorParamsItem->getOrigin() == assetParamsOrigin::INGEST) {
             unset($flavors[$index]);
             continue;
         }
         if (in_array($flavor->getId(), $entryIngestedFlavors) && $conversionProfileFlavorParamsItem->getOrigin() == assetParamsOrigin::CONVERT_WHEN_MISSING) {
             unset($flavors[$index]);
             continue;
         }
         // if flavor is not source (checked above), apply dynamic attributes defined for id -2 (all flavors)
         if (isset($dynamicFlavorAttributes[flavorParams::DYNAMIC_ATTRIBUTES_ALL_FLAVORS_INDEX])) {
             foreach ($dynamicFlavorAttributes[flavorParams::DYNAMIC_ATTRIBUTES_ALL_FLAVORS_INDEX] as $attributeName => $attributeValue) {
                 $flavor->setDynamicAttribute($attributeName, $attributeValue);
             }
         }
         // overwrite dynamic attributes if defined for this specific flavor
         if (isset($dynamicFlavorAttributes[$flavor->getId()])) {
             foreach ($dynamicFlavorAttributes[$flavor->getId()] as $attributeName => $attributeValue) {
                 $flavor->setDynamicAttribute($attributeName, $attributeValue);
             }
         }
     }
     KalturaLog::log(count($flavors) . " destination flavors found for this profile[" . $profile->getId() . "]");
     if (!count($flavors)) {
         return false;
     }
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId());
     return self::decideProfileFlavorsConvert($parentJob, $convertProfileJob, $flavors, $conversionProfileFlavorParams, $mediaInfo);
 }
Exemple #14
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(assetParamsPeer::DATABASE_NAME);
     $criteria->add(assetParamsPeer::ID, $this->id);
     if ($this->alreadyInSave) {
         if ($this->isColumnModified(assetParamsPeer::CUSTOM_DATA)) {
             if (!is_null($this->custom_data_md5)) {
                 $criteria->add(assetParamsPeer::CUSTOM_DATA, "MD5(cast(" . assetParamsPeer::CUSTOM_DATA . " as char character set latin1)) = '{$this->custom_data_md5}'", Criteria::CUSTOM);
             } else {
                 $criteria->add(assetParamsPeer::CUSTOM_DATA, NULL, Criteria::ISNULL);
             }
         }
         if (count($this->modifiedColumns) == 2 && $this->isColumnModified(assetParamsPeer::UPDATED_AT)) {
             $theModifiedColumn = null;
             foreach ($this->modifiedColumns as $modifiedColumn) {
                 if ($modifiedColumn != assetParamsPeer::UPDATED_AT) {
                     $theModifiedColumn = $modifiedColumn;
                 }
             }
             $atomicColumns = assetParamsPeer::getAtomicColumns();
             if (in_array($theModifiedColumn, $atomicColumns)) {
                 $criteria->add($theModifiedColumn, $this->getByName($theModifiedColumn, BasePeer::TYPE_COLNAME), Criteria::NOT_EQUAL);
             }
         }
     }
     return $criteria;
 }
 /**
  * Adds the relation of flavorParams <> conversionProfile2
  * 
  * @param conversionProfile2 $conversionProfileDb
  * @param $flavorParamsIds
  */
 protected function addFlavorParamsRelation(conversionProfile2 $conversionProfileDb, $flavorParamsIds)
 {
     $existingIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($conversionProfileDb->getId());
     $assetParamsObjects = assetParamsPeer::retrieveByPKs($flavorParamsIds);
     foreach ($assetParamsObjects as $assetParams) {
         /* @var $assetParams assetParams */
         if (in_array($assetParams->getId(), $existingIds)) {
             continue;
         }
         $fpc = new flavorParamsConversionProfile();
         $fpc->setConversionProfileId($conversionProfileDb->getId());
         $fpc->setFlavorParamsId($assetParams->getId());
         $fpc->setReadyBehavior($assetParams->getReadyBehavior());
         $fpc->setSystemName($assetParams->getSystemName());
         $fpc->setForceNoneComplied(false);
         if ($assetParams->hasTag(assetParams::TAG_SOURCE)) {
             $fpc->setOrigin(assetParamsOrigin::INGEST);
         } else {
             $fpc->setOrigin(assetParamsOrigin::CONVERT);
         }
         $fpc->save();
     }
 }
Exemple #16
0
 public function getStreamBitrates()
 {
     $streamBitrates = $this->getFromCustomData("streamBitrates");
     if (is_array($streamBitrates) && count($streamBitrates)) {
         return $streamBitrates;
     }
     if (in_array($this->getSource(), array(EntrySourceType::LIVE_STREAM, EntrySourceType::LIVE_STREAM_ONTEXTDATA_CAPTIONS))) {
         $liveParams = assetParamsPeer::retrieveByProfile($this->getConversionProfileId());
         $streamBitrates = array();
         foreach ($liveParams as $liveParamsItem) {
             /* @var $liveParamsItem liveParams */
             $streamBitrate = array('bitrate' => $liveParamsItem->getVideoBitrate(), 'width' => $liveParamsItem->getWidth(), 'height' => $liveParamsItem->getHeight(), 'tags' => $liveParamsItem->getTags());
             $streamBitrates[] = $streamBitrate;
         }
         return $streamBitrates;
     }
     return array(array('bitrate' => 300, 'width' => 320, 'height' => 240));
 }
Exemple #17
0
$readyBehavior = 2;
$isDefault = false;
$width = 0;
$height = 0;
$resolution = null;
$paperWidth = null;
$paperHeight = null;
$isReadonly = true;
/**************************************************
 * DON'T TOUCH THE FOLLOWING CODE
 ***************************************************/
chdir(dirname(__FILE__));
require_once __DIR__ . '/../../bootstrap.php';
$flavorParams = null;
if ($flavorParamsId) {
    $flavorParams = assetParamsPeer::retrieveByPK($flavorParamsId);
    if (!$flavorParams instanceof PdfFlavorParams) {
        echo "Flavor params id [{$flavorParamsId}] is not PDF flavor params\n";
        exit;
    }
    $flavorParams->setVersion($flavorParams->getVersion() + 1);
} else {
    $flavorParams = new PdfFlavorParams();
    $flavorParams->setVersion(1);
    $flavorParams->setFormat(flavorParams::CONTAINER_FORMAT_PDF);
    $flavorParams->setVideoBitrate(1);
}
$pdfOperator = new kOperator();
$pdfOperator->id = conversionEngineType::PDF_CREATOR;
$operators = new kOperatorSets();
$operators->addSet(array($pdfOperator));
 /**
  * @param BatchJob $dbBatchJob
  * @param flavorAsset $currentFlavorAsset
  * @return BatchJob
  */
 public static function handleConvertFinished(BatchJob $dbBatchJob = null, flavorAsset $currentFlavorAsset)
 {
     KalturaLog::debug("entry id [" . $currentFlavorAsset->getEntryId() . "] flavor asset id [" . $currentFlavorAsset->getId() . "]");
     $profile = null;
     try {
         $profile = myPartnerUtils::getConversionProfile2ForEntry($currentFlavorAsset->getEntryId());
         KalturaLog::debug("profile [" . $profile->getId() . "]");
     } catch (Exception $e) {
         KalturaLog::err($e->getMessage());
     }
     $currentReadyBehavior = self::getReadyBehavior($currentFlavorAsset, $profile);
     KalturaLog::debug("Current ready behavior [{$currentReadyBehavior}]");
     if ($currentReadyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE) {
         return $dbBatchJob;
     }
     $rootBatchJob = null;
     if ($dbBatchJob) {
         $rootBatchJob = $dbBatchJob->getRootJob();
     }
     if ($rootBatchJob) {
         KalturaLog::debug("root batch job id [" . $rootBatchJob->getId() . "] type [" . $rootBatchJob->getJobType() . "]");
     }
     // update the root job end exit
     if ($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::BULKDOWNLOAD) {
         $siblingJobs = $rootBatchJob->getChildJobs();
         foreach ($siblingJobs as $siblingJob) {
             // checking only conversion child jobs
             if ($siblingJob->getJobType() != BatchJobType::CONVERT && $siblingJob->getJobType() != BatchJobType::CONVERT_COLLECTION && $siblingJob->getJobType() != BatchJobType::POSTCONVERT) {
                 continue;
             }
             // if not complete leave function
             if (!in_array($siblingJob->getStatus(), BatchJobPeer::getClosedStatusList())) {
                 KalturaLog::debug("job id [" . $siblingJob->getId() . "] status [" . $siblingJob->getStatus() . "]");
                 return $dbBatchJob;
             }
         }
         KalturaLog::debug("finish bulk download root job");
         // all child jobs completed
         kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
         return $dbBatchJob;
     }
     $inheritedFlavorParamsIds = array();
     $requiredFlavorParamsIds = array();
     $flavorParamsConversionProfileItems = array();
     if ($profile) {
         $flavorParamsConversionProfileItems = flavorParamsConversionProfilePeer::retrieveByConversionProfile($profile->getId());
     }
     foreach ($flavorParamsConversionProfileItems as $flavorParamsConversionProfile) {
         if ($flavorParamsConversionProfile->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             $requiredFlavorParamsIds[$flavorParamsConversionProfile->getFlavorParamsId()] = true;
         }
         if ($flavorParamsConversionProfile->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_NO_IMPACT) {
             $inheritedFlavorParamsIds[] = $flavorParamsConversionProfile->getFlavorParamsId();
         }
     }
     $flavorParamsItems = assetParamsPeer::retrieveByPKs($inheritedFlavorParamsIds);
     foreach ($flavorParamsItems as $flavorParams) {
         if ($flavorParams->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             $requiredFlavorParamsIds[$flavorParamsConversionProfile->getFlavorParamsId()] = true;
         }
     }
     KalturaLog::debug("required flavor params ids [" . print_r($requiredFlavorParamsIds, true) . "]");
     // go over all the flavor assets of the entry
     $inCompleteFlavorIds = array();
     $origianlAssetFlavorId = null;
     $siblingFlavorAssets = assetPeer::retrieveFlavorsByEntryId($currentFlavorAsset->getEntryId());
     foreach ($siblingFlavorAssets as $siblingFlavorAsset) {
         KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] flavor params id [" . $siblingFlavorAsset->getFlavorParamsId() . "]");
         // don't mark any incomplete flag
         if ($siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is ready");
             if (isset($requiredFlavorParamsIds[$siblingFlavorAsset->getFlavorParamsId()])) {
                 unset($requiredFlavorParamsIds[$siblingFlavorAsset->getFlavorParamsId()]);
             }
             continue;
         }
         $readyBehavior = self::getReadyBehavior($siblingFlavorAsset, $profile);
         if ($siblingFlavorAsset->getStatus() == flavorAsset::ASSET_STATUS_EXPORTING) {
             if ($siblingFlavorAsset->getIsOriginal()) {
                 $origianlAssetFlavorId = $siblingFlavorAsset->getFlavorParamsId();
             } else {
                 if ($readyBehavior != flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE) {
                     KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is incomplete");
                     $inCompleteFlavorIds[] = $siblingFlavorAsset->getFlavorParamsId();
                 }
             }
         }
         if ($readyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is ignored");
             continue;
         }
         if ($siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_QUEUED || $siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_CONVERTING || $siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_IMPORTING || $siblingFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_VALIDATING) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is incomplete");
             $inCompleteFlavorIds[] = $siblingFlavorAsset->getFlavorParamsId();
         }
         if ($readyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             KalturaLog::debug("sibling flavor asset id [" . $siblingFlavorAsset->getId() . "] is required");
             $requiredFlavorParamsIds[$siblingFlavorAsset->getFlavorParamsId()] = true;
         }
     }
     KalturaLog::debug("left required flavor params ids [" . print_r($requiredFlavorParamsIds, true) . "]");
     KalturaLog::debug("left incomplete flavor ids [" . print_r($inCompleteFlavorIds, true) . "]");
     if (count($requiredFlavorParamsIds)) {
         $inCompleteRequiredFlavorParamsIds = array_keys($requiredFlavorParamsIds);
         foreach ($inCompleteRequiredFlavorParamsIds as $inCompleteFlavorId) {
             $inCompleteFlavorIds[] = $inCompleteFlavorId;
         }
         KalturaLog::debug('Convert Finished - has In-Complete Required flavors [[' . print_r($inCompleteRequiredFlavorParamsIds, true) . ']');
     } elseif ($currentFlavorAsset->getStatus() == asset::ASSET_STATUS_READY && ($currentReadyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_OPTIONAL || $currentReadyBehavior == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED)) {
         // mark the entry as ready if all required conversions completed or any of the optionals
         if ($currentFlavorAsset->getentry()->getReplacedEntryId()) {
             KalturaLog::debug('Entry is temporary replacement and requires all flavors to complete');
         } else {
             KalturaLog::debug('Mark the entry as ready');
             kBatchManager::updateEntry($currentFlavorAsset->getEntryId(), entryStatus::READY);
         }
     }
     if ($origianlAssetFlavorId) {
         $inCompleteFlavorIds = array_diff($inCompleteFlavorIds, array($origianlAssetFlavorId));
     }
     if (!count($inCompleteFlavorIds)) {
         KalturaLog::debug('Convert Finished');
         if ($origianlAssetFlavorId && $rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
             kStorageExporter::exportSourceAssetFromJob($rootBatchJob);
         } else {
             // mark the context root job as finished only if all conversion jobs are completed
             kBatchManager::updateEntry($currentFlavorAsset->getEntryId(), entryStatus::READY);
             if ($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
                 kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
             }
         }
         return $dbBatchJob;
     }
     KalturaLog::debug('Convert Finished - has In-Complete flavors [' . print_r($inCompleteFlavorIds, true) . ']');
     if (!$rootBatchJob || $rootBatchJob->getJobType() != BatchJobType::CONVERT_PROFILE) {
         return $dbBatchJob;
     }
     $childJobs = $rootBatchJob->getChildJobs();
     KalturaLog::debug('Child jobs found [' . count($childJobs) . ']');
     if (count($childJobs) > 1) {
         $allDone = true;
         foreach ($childJobs as $childJob) {
             if ($childJob->getId() != $rootBatchJob->getId() && $childJob->getStatus() != BatchJob::BATCHJOB_STATUS_FINISHED) {
                 KalturaLog::debug('Child job id [' . $childJob->getId() . '] status [' . $childJob->getStatus() . ']');
                 $allDone = false;
             }
         }
         if ($allDone) {
             KalturaLog::debug('All child jobs done, closing profile');
             kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
         }
     }
     return $dbBatchJob;
 }
 private static function decideSourceFlavorConvert($entryId, assetParams $sourceFlavor = null, flavorAsset $originalFlavorAsset, $conversionProfileId, $flavors, mediaInfo $mediaInfo = null, BatchJob $parentJob, BatchJob $convertProfileJob)
 {
     if ($sourceFlavor && ($sourceFlavor->getOperators() || $sourceFlavor->getConversionEngines()) && $originalFlavorAsset->getInterFlowCount() == null) {
         KalturaLog::log("Source flavor asset requires conversion");
         self::adjustAssetParams($entryId, array($sourceFlavor));
         $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $errDescription = null;
         $sourceFlavorOutput = self::validateFlavorAndMediaInfo($sourceFlavor, $mediaInfo, $errDescription);
         if (!$sourceFlavorOutput) {
             if (!$errDescription) {
                 $errDescription = "Failed to create flavor params output from source flavor";
             }
             $originalFlavorAsset->setDescription($originalFlavorAsset->getDescription() . "\n{$errDescription}");
             $originalFlavorAsset->setStatus(flavorAsset::ASSET_STATUS_ERROR);
             $originalFlavorAsset->save();
             kBatchManager::updateEntry($entryId, entryStatus::ERROR_CONVERTING);
             kJobsManager::updateBatchJob($convertProfileJob, BatchJob::BATCHJOB_STATUS_FAILED);
             return false;
         }
     } elseif ($mediaInfo) {
         /*
          * Check whether there is a need for an intermediate source pre-processing
          */
         $sourceFlavorOutput = KDLWrap::GenerateIntermediateSource($mediaInfo, $flavors);
         if (!$sourceFlavorOutput) {
             return true;
         }
         $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         $errDescription = null;
         /*
          * Save the original source asset in another asset, in order 
          * to prevent its liquidated by the inter-source asset.
          * But, do it only if the conversion profile contains source flavor
          */
         if ($sourceFlavor) {
             $sourceAsset = assetPeer::retrieveById($mediaInfo->getFlavorAssetId());
             $copyFlavorParams = assetParamsPeer::retrieveBySystemName(self::SAVE_ORIGINAL_SOURCE_FLAVOR_PARAM_SYS_NAME);
             if (!$copyFlavorParams) {
                 throw new APIException(APIErrors::OBJECT_NOT_FOUND);
             }
             $asset = $sourceAsset->copy();
             $asset->setFlavorParamsId($copyFlavorParams->getId());
             $asset->setFromAssetParams($copyFlavorParams);
             $asset->setStatus(flavorAsset::ASSET_STATUS_READY);
             $asset->setIsOriginal(0);
             $asset->setTags($copyFlavorParams->getTags());
             $asset->incrementVersion();
             $asset->save();
             kFileSyncUtils::createSyncFileLinkForKey($asset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET), $sourceAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET));
             $origFileSync = kFileSyncUtils::getLocalFileSyncForKey($sourceAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET));
             $asset->setSize(intval($origFileSync->getFileSize() / 1000));
             $asset->save();
         }
     }
     /*
      * '_passthrough' controls whether the source is to be 'passthrough' although there 
      * is a source flavor that contains transcoder settings.
      * Looks for a '_passthrough' flag on the source's flavor params output.
      */
     if (!$sourceFlavorOutput || $sourceFlavorOutput->_passthrough == true) {
         return true;
     }
     // save flavor params
     $sourceFlavorOutput->setPartnerId($sourceFlavorOutput->getPartnerId());
     $sourceFlavorOutput->setEntryId($entryId);
     $sourceFlavorOutput->setFlavorAssetId($originalFlavorAsset->getId());
     $sourceFlavorOutput->setFlavorAssetVersion($originalFlavorAsset->getVersion());
     $sourceFlavorOutput->save();
     if ($errDescription) {
         $originalFlavorAsset->setDescription($originalFlavorAsset->getDescription() . "\n{$errDescription}");
     }
     $errDescription = kBusinessConvertDL::parseFlavorDescription($sourceFlavorOutput);
     if ($errDescription) {
         $originalFlavorAsset->setDescription($originalFlavorAsset->getDescription() . "\n{$errDescription}");
     }
     // decided by the business logic layer
     if ($sourceFlavorOutput->_create_anyway) {
         KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] selected to be created anyway");
     } else {
         if (!$sourceFlavorOutput->IsValid()) {
             KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is invalid");
             $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
             $originalFlavorAsset->save();
             $errDescription = "Source flavor could not be converted";
             self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $convertProfileJob->getEntryId());
             return false;
         }
         if ($sourceFlavorOutput->_force) {
             KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is forced");
         } elseif ($sourceFlavorOutput->_isNonComply) {
             KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is none-comply");
         } else {
             KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is valid");
         }
     }
     $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_CONVERTING);
     if (isset($sourceFlavor)) {
         $originalFlavorAsset->addTags($sourceFlavor->getTagsArray());
         $originalFlavorAsset->setFileExt($sourceFlavorOutput->getFileExt());
         $originalFlavorAsset->save();
     }
     // save flavor params
     $sourceFlavorOutput->setFlavorAssetVersion($originalFlavorAsset->getVersion());
     $sourceFlavorOutput->save();
     $mediaInfoId = null;
     if ($mediaInfo) {
         $mediaInfoId = $mediaInfo->getId();
     }
     kJobsManager::addFlavorConvertJob(array($srcSyncKey), $sourceFlavorOutput, $originalFlavorAsset->getId(), $conversionProfileId, $mediaInfoId, $parentJob);
     return false;
 }
Exemple #20
0
 /**
  * @param BatchJob $batchJob
  * @param entry $entry
  * @param string $flavorAssetId
  * @param string $inputFileSyncLocalPath
  * @return BatchJob
  */
 public static function addConvertProfileJob(BatchJob $parentJob = null, entry $entry, $flavorAssetId, $inputFileSyncLocalPath)
 {
     KalturaLog::debug("Parent job [" . ($parentJob ? $parentJob->getId() : 'none') . "] entry [" . $entry->getId() . "] flavor asset [{$flavorAssetId}] input file [{$inputFileSyncLocalPath}]");
     if ($entry->getConversionQuality() == conversionProfile2::CONVERSION_PROFILE_NONE) {
         $entry->setStatus(entryStatus::PENDING);
         $entry->save();
         KalturaLog::notice('Entry should not be converted');
         return null;
     }
     $importingSources = false;
     // if file size is 0, do not create conversion profile and set entry status as error converting
     if (!file_exists($inputFileSyncLocalPath) || kFile::fileSize($inputFileSyncLocalPath) == 0) {
         KalturaLog::debug("Input file [{$inputFileSyncLocalPath}] does not exist");
         $partner = $entry->getPartner();
         $conversionProfile = myPartnerUtils::getConversionProfile2ForEntry($entry->getId());
         // load the asset params to the instance pool
         $flavorIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($conversionProfile->getId());
         assetParamsPeer::retrieveByPKs($flavorIds);
         $conversionRequired = false;
         $sourceFileRequiredStorages = array();
         $sourceIncludedInProfile = false;
         $flavorAsset = assetPeer::retrieveById($flavorAssetId);
         $flavors = flavorParamsConversionProfilePeer::retrieveByConversionProfile($conversionProfile->getId());
         KalturaLog::debug("Found flavors [" . count($flavors) . "] in conversion profile [" . $conversionProfile->getId() . "]");
         foreach ($flavors as $flavor) {
             /* @var $flavor flavorParamsConversionProfile */
             if ($flavor->getFlavorParamsId() == $flavorAsset->getFlavorParamsId()) {
                 KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] is ingested source");
                 $sourceIncludedInProfile = true;
                 continue;
             }
             $flavorParams = assetParamsPeer::retrieveByPK($flavor->getFlavorParamsId());
             if ($flavorParams instanceof liveParams || $flavor->getOrigin() == assetParamsOrigin::INGEST) {
                 KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] should be ingested");
                 continue;
             }
             if ($flavor->getOrigin() == assetParamsOrigin::CONVERT_WHEN_MISSING) {
                 $siblingFlavorAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $flavor->getFlavorParamsId());
                 if ($siblingFlavorAsset) {
                     KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] already ingested");
                     continue;
                 }
             }
             $sourceFileRequiredStorages[] = $flavorParams->getSourceRemoteStorageProfileId();
             $conversionRequired = true;
             break;
         }
         if ($conversionRequired) {
             foreach ($sourceFileRequiredStorages as $storageId) {
                 if ($storageId == StorageProfile::STORAGE_KALTURA_DC) {
                     $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                     list($syncFile, $local) = kFileSyncUtils::getReadyFileSyncForKey($key, true, false);
                     if ($syncFile && $syncFile->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL && $partner && $partner->getImportRemoteSourceForConvert()) {
                         KalturaLog::debug("Creates import job for remote file sync");
                         $url = $syncFile->getExternalUrl($entry->getId());
                         kJobsManager::addImportJob($parentJob, $entry->getId(), $partner->getId(), $url, $flavorAsset, null, null, true);
                         $importingSources = true;
                         continue;
                     }
                 } elseif ($flavorAsset->getExternalUrl($storageId)) {
                     continue;
                 }
                 kBatchManager::updateEntry($entry->getId(), entryStatus::ERROR_CONVERTING);
                 $flavorAsset = assetPeer::retrieveById($flavorAssetId);
                 $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
                 $flavorAsset->setDescription('Entry of size 0 should not be converted');
                 $flavorAsset->save();
                 KalturaLog::err('Entry of size 0 should not be converted');
                 return null;
             }
         } else {
             if ($flavorAsset->getStatus() == asset::FLAVOR_ASSET_STATUS_QUEUED) {
                 if ($sourceIncludedInProfile) {
                     $flavorAsset->setStatusLocalReady();
                 } else {
                     $flavorAsset->setStatus(asset::FLAVOR_ASSET_STATUS_DELETED);
                     $flavorAsset->setDeletedAt(time());
                 }
                 $flavorAsset->save();
                 if ($sourceIncludedInProfile) {
                     kBusinessPostConvertDL::handleConvertFinished(null, $flavorAsset);
                 }
             }
             return null;
         }
     }
     if ($entry->getStatus() != entryStatus::READY) {
         $entry->setStatus(entryStatus::PRECONVERT);
     }
     $jobData = new kConvertProfileJobData();
     $jobData->setFlavorAssetId($flavorAssetId);
     $jobData->setInputFileSyncLocalPath($inputFileSyncLocalPath);
     $jobData->setExtractMedia(true);
     if ($entry->getType() != entryType::MEDIA_CLIP) {
         $jobData->setExtractMedia(false);
         $entry->setCreateThumb(false);
     }
     $entry->save();
     $batchJob = null;
     if ($parentJob) {
         $batchJob = $parentJob->createChild(BatchJobType::CONVERT_PROFILE);
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($entry->getId());
         $batchJob->setPartnerId($entry->getPartnerId());
         $batchJob->setUseNewRoot(true);
     }
     $batchJob->setObjectId($entry->getId());
     $batchJob->setObjectType(BatchJobObjectType::ENTRY);
     if ($importingSources) {
         $batchJob->setStatus(BatchJob::BATCHJOB_STATUS_DONT_PROCESS);
     }
     return self::addJob($batchJob, $jobData, BatchJobType::CONVERT_PROFILE);
 }
 /**
  * List Thumb Params by filter with paging support (By default - all system default params will be listed too)
  * 
  * @action list
  * @param KalturaThumbParamsFilter $filter
  * @param KalturaFilterPager $pager
  * @return KalturaThumbParamsListResponse
  */
 public function listAction(KalturaThumbParamsFilter $filter = null, KalturaFilterPager $pager = null)
 {
     if (!$filter) {
         $filter = new KalturaThumbParamsFilter();
     }
     if (!$pager) {
         $pager = new KalturaFilterPager();
     }
     $thumbParamsFilter = new assetParamsFilter();
     $filter->toObject($thumbParamsFilter);
     $c = new Criteria();
     $thumbParamsFilter->attachToCriteria($c);
     $pager->attachToCriteria($c);
     $thumbTypes = KalturaPluginManager::getExtendedTypes(assetParamsPeer::OM_CLASS, assetType::THUMBNAIL);
     $c->add(assetParamsPeer::TYPE, $thumbTypes, Criteria::IN);
     $dbList = assetParamsPeer::doSelect($c);
     $c->setLimit(null);
     $totalCount = assetParamsPeer::doCount($c);
     $list = KalturaThumbParamsArray::fromDbArray($dbList);
     $response = new KalturaThumbParamsListResponse();
     $response->objects = $list;
     $response->totalCount = $totalCount;
     return $response;
 }
Exemple #22
0
 /**
  * Authenticate live-stream entry against stream token and partner limitations
  * 
  * @action authenticate
  * @param string $entryId Live stream entry id
  * @param string $token Live stream broadcasting token
  * @return KalturaLiveStreamEntry The authenticated live stream entry
  * 
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  * @throws KalturaErrors::LIVE_STREAM_INVALID_TOKEN
  */
 function authenticateAction($entryId, $token)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry || $dbEntry->getType() != entryType::LIVE_STREAM) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     /* @var $dbEntry LiveStreamEntry */
     if ($dbEntry->getStreamPassword() != $token) {
         throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_INVALID_TOKEN, $entryId);
     }
     $mediaServer = $dbEntry->getMediaServer(true);
     if ($mediaServer) {
         $url = null;
         $protocol = null;
         foreach (array(KalturaPlaybackProtocol::HLS, KalturaPlaybackProtocol::APPLE_HTTP) as $hlsProtocol) {
             $config = $dbEntry->getLiveStreamConfigurationByProtocol($hlsProtocol, requestUtils::PROTOCOL_HTTP, null, true);
             if ($config) {
                 $url = $config->getUrl();
                 $protocol = $hlsProtocol;
                 break;
             }
         }
         if ($url) {
             KalturaLog::info('Determining status of live stream URL [' . $url . ']');
             $dpda = new DeliveryProfileDynamicAttributes();
             $dpda->setEntryId($entryId);
             $dpda->setFormat($protocol);
             $deliveryProfile = DeliveryProfilePeer::getLiveDeliveryProfileByHostName(parse_url($url, PHP_URL_HOST), $dpda);
             if ($deliveryProfile && $deliveryProfile->isLive($url)) {
                 throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_ALREADY_BROADCASTING, $entryId, $mediaServer->getHostname());
             }
         }
     }
     // fetch current stream live params
     $liveParamsIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($dbEntry->getConversionProfileId());
     $usedLiveParamsIds = array();
     foreach ($liveParamsIds as $liveParamsId) {
         $usedLiveParamsIds[$liveParamsId] = array($entryId);
     }
     // fetch all live entries that currently are live
     $baseCriteria = KalturaCriteria::create(entryPeer::OM_CLASS);
     $filter = new entryFilter();
     $filter->setIsLive(true);
     $filter->setIdNotIn(array($entryId));
     $filter->setPartnerSearchScope(baseObjectFilter::MATCH_KALTURA_NETWORK_AND_PRIVATE);
     $filter->attachToCriteria($baseCriteria);
     $entries = entryPeer::doSelect($baseCriteria);
     $maxInputStreams = $this->getPartner()->getMaxLiveStreamInputs();
     if (!$maxInputStreams) {
         $maxInputStreams = kConf::get('partner_max_live_stream_inputs', 'local', 10);
     }
     KalturaLog::debug("Max live stream inputs [{$maxInputStreams}]");
     $maxTranscodedStreams = 0;
     if (PermissionPeer::isValidForPartner(PermissionName::FEATURE_KALTURA_LIVE_STREAM_TRANSCODE, $this->getPartnerId())) {
         $maxTranscodedStreams = $this->getPartner()->getMaxLiveStreamOutputs();
         if (!$maxTranscodedStreams) {
             $maxTranscodedStreams = kConf::get('partner_max_live_stream_outputs', 'local', 10);
         }
     }
     KalturaLog::debug("Max live stream outputs [{$maxTranscodedStreams}]");
     $totalInputStreams = count($entries) + 1;
     if ($totalInputStreams > $maxInputStreams + $maxTranscodedStreams) {
         KalturaLog::debug("Live input stream [{$totalInputStreams}]");
         throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_EXCEEDED_MAX_PASSTHRU, $entryId);
     }
     $entryIds = array($entryId);
     foreach ($entries as $liveEntry) {
         /* @var $liveEntry LiveEntry */
         $entryIds[] = $liveEntry->getId();
         $liveParamsIds = array_map('intval', explode(',', $liveEntry->getFlavorParamsIds()));
         foreach ($liveParamsIds as $liveParamsId) {
             if (isset($usedLiveParamsIds[$liveParamsId])) {
                 $usedLiveParamsIds[$liveParamsId][] = $liveEntry->getId();
             } else {
                 $usedLiveParamsIds[$liveParamsId] = array($liveEntry->getId());
             }
         }
     }
     $liveParams = assetParamsPeer::retrieveByPKs(array_keys($usedLiveParamsIds));
     $passthruEntries = null;
     $transcodedEntries = null;
     foreach ($liveParams as $liveParamsItem) {
         /* @var $liveParamsItem LiveParams */
         if ($liveParamsItem->hasTag(liveParams::TAG_INGEST)) {
             $passthruEntries = array_intersect(is_array($passthruEntries) ? $passthruEntries : $entryIds, $usedLiveParamsIds[$liveParamsItem->getId()]);
         } else {
             $transcodedEntries = array_intersect(is_array($transcodedEntries) ? $transcodedEntries : $entryIds, $usedLiveParamsIds[$liveParamsItem->getId()]);
         }
     }
     $passthruEntries = array_diff($passthruEntries, $transcodedEntries);
     $passthruEntriesCount = count($passthruEntries);
     $transcodedEntriesCount = count($transcodedEntries);
     KalturaLog::debug("Live transcoded entries [{$transcodedEntriesCount}], max live transcoded streams [{$maxTranscodedStreams}]");
     if ($transcodedEntriesCount > $maxTranscodedStreams) {
         throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_EXCEEDED_MAX_TRANSCODED, $entryId);
     }
     $maxInputStreams += $maxTranscodedStreams - $transcodedEntriesCount;
     KalturaLog::debug("Live params inputs [{$passthruEntriesCount}], max live stream inputs [{$maxInputStreams}]");
     if ($passthruEntriesCount > $maxInputStreams) {
         throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_EXCEEDED_MAX_PASSTHRU, $entryId);
     }
     $entry = KalturaEntryFactory::getInstanceByType($dbEntry->getType());
     $entry->fromObject($dbEntry, $this->getResponseProfile());
     return $entry;
 }
 /**
  * @param EntryDistribution $entryDistribution
  * @param DistributionProfile $distributionProfile
  * @param bool $submitWhenReady
  * @return BatchJob
  */
 public static function submitAddEntryDistribution(EntryDistribution $entryDistribution, DistributionProfile $distributionProfile, $submitWhenReady = true)
 {
     if ($distributionProfile->getStatus() != DistributionProfileStatus::ENABLED || $distributionProfile->getSubmitEnabled() == DistributionProfileActionStatus::DISABLED) {
         KalturaLog::debug("Submission is not enabled");
         return null;
     }
     $validStatus = array(EntryDistributionStatus::ERROR_DELETING, EntryDistributionStatus::ERROR_SUBMITTING, EntryDistributionStatus::ERROR_UPDATING, EntryDistributionStatus::IMPORT_SUBMITTING, EntryDistributionStatus::PENDING, EntryDistributionStatus::QUEUED, EntryDistributionStatus::READY, EntryDistributionStatus::REMOVED);
     if (!in_array($entryDistribution->getStatus(), $validStatus)) {
         KalturaLog::notice("Wrong entry distribution status [" . $entryDistribution->getStatus() . "]");
         return null;
     }
     $returnValue = false;
     $validationErrors = $entryDistribution->getValidationErrors();
     if (!count($validationErrors)) {
         KalturaLog::debug("No validation errors found");
         $returnValue = true;
         $sunrise = $entryDistribution->getSunrise(null);
         if ($sunrise) {
             KalturaLog::debug("Applying sunrise [{$sunrise}]");
             $distributionProvider = $distributionProfile->getProvider();
             if (!$distributionProvider->isScheduleUpdateEnabled() && !$distributionProvider->isAvailabilityUpdateEnabled()) {
                 $sunrise -= $distributionProvider->getJobIntervalBeforeSunrise();
                 if ($sunrise > time()) {
                     KalturaLog::log("Will be sent on exact time [{$sunrise}] for sunrise time [" . $entryDistribution->getSunrise() . "]");
                     $entryDistribution->setDirtyStatus(EntryDistributionDirtyStatus::SUBMIT_REQUIRED);
                     $entryDistribution->save();
                     $returnValue = null;
                 }
             }
         }
         if ($returnValue) {
             $returnValue = self::addSubmitAddJob($entryDistribution, $distributionProfile);
         }
     }
     if (!$returnValue && $submitWhenReady && $entryDistribution->getStatus() != EntryDistributionStatus::QUEUED) {
         $entryDistribution->setStatus(EntryDistributionStatus::QUEUED);
         $entryDistribution->save();
         KalturaLog::debug("Will be submitted when ready");
     }
     if (!count($validationErrors)) {
         return $returnValue;
     }
     KalturaLog::log("Validation errors found");
     $entry = entryPeer::retrieveByPK($entryDistribution->getEntryId());
     if (!$entry) {
         KalturaLog::err("Entry [" . $entryDistribution->getEntryId() . "] not found");
         return null;
     }
     $autoCreateFlavors = $distributionProfile->getAutoCreateFlavorsArray();
     $autoCreateThumbs = $distributionProfile->getAutoCreateThumbArray();
     foreach ($validationErrors as $validationError) {
         if ($validationError->getErrorType() == DistributionErrorType::MISSING_FLAVOR && in_array($validationError->getData(), $autoCreateFlavors)) {
             $errDescription = null;
             KalturaLog::log("Adding flavor [" . $validationError->getData() . "] to entry [" . $entryDistribution->getEntryId() . "]");
             kBusinessPreConvertDL::decideAddEntryFlavor(null, $entryDistribution->getEntryId(), $validationError->getData(), $errDescription);
             if ($errDescription) {
                 KalturaLog::log($errDescription);
             }
         }
         if ($validationError->getErrorType() == DistributionErrorType::MISSING_THUMBNAIL && count($autoCreateThumbs)) {
             list($requiredWidth, $requiredHeight) = explode('x', $validationError->getData());
             $foundThumbParams = false;
             $thumbParamsObjects = assetParamsPeer::retrieveByPKs($autoCreateThumbs);
             foreach ($thumbParamsObjects as $thumbParams) {
                 /* @var $thumbParams thumbParams */
                 if ($thumbParams->getWidth() == intval($requiredWidth) && $thumbParams->getHeight() == intval($requiredHeight)) {
                     $foundThumbParams = true;
                     KalturaLog::log("Adding thumbnail [" . $thumbParams->getId() . "] to entry [" . $entryDistribution->getEntryId() . "]");
                     kBusinessPreConvertDL::decideThumbGenerate($entry, $thumbParams);
                     break;
                 }
             }
             if (!$foundThumbParams) {
                 KalturaLog::err("Required thumbnail params not found [" . $validationError->getData() . "]");
             }
         }
     }
     return null;
 }
 /**
  * Selects a collection of flavorParamsConversionProfile objects pre-filled with all related objects except conversionProfile2.
  *
  * @param      Criteria  $criteria
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of flavorParamsConversionProfile objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptconversionProfile2(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $criteria = clone $criteria;
     // Set the correct dbName if it has not been overridden
     // $criteria->getDbName() will return the same object if not set to another value
     // so == check is okay and faster
     if ($criteria->getDbName() == Propel::getDefaultDB()) {
         $criteria->setDbName(self::DATABASE_NAME);
     }
     flavorParamsConversionProfilePeer::addSelectColumns($criteria);
     $startcol2 = flavorParamsConversionProfilePeer::NUM_COLUMNS - flavorParamsConversionProfilePeer::NUM_LAZY_LOAD_COLUMNS;
     assetParamsPeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + (assetParamsPeer::NUM_COLUMNS - assetParamsPeer::NUM_LAZY_LOAD_COLUMNS);
     $criteria->addJoin(flavorParamsConversionProfilePeer::FLAVOR_PARAMS_ID, assetParamsPeer::ID, $join_behavior);
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = flavorParamsConversionProfilePeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = flavorParamsConversionProfilePeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://propel.phpdb.org/trac/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $cls = flavorParamsConversionProfilePeer::getOMClass(false);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             flavorParamsConversionProfilePeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined assetParams rows
         $key2 = assetParamsPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = assetParamsPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = assetParamsPeer::getOMClass($row, $startcol2);
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 assetParamsPeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (flavorParamsConversionProfile) to the collection in $obj2 (assetParams)
             $obj2->addflavorParamsConversionProfile($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Exemple #25
0
 function calculateUrgency(BatchJob $batchJob)
 {
     $flavorParamsId = $this->getFlavorParamsOutput()->getFlavorParamsId();
     $isBulkupload = $batchJob->getBulkJobId() !== null;
     $readiness = null;
     if ($this->priority == 0) {
         self::calculatePriority($batchJob);
     }
     if ($this->priority == self::MIGRATION_FLAVOR_PRIORITY) {
         return BatchJobUrgencyType::MIGRATION_URGENCY;
     }
     // If you have no conversion profile, there is no poinr in this calculation
     if (is_null($this->conversionProfileId)) {
         return BatchJobUrgencyType::DEFAULT_URGENCY;
     }
     if ($batchJob->getObjectId() && $batchJob->getObjectType()) {
         $batchJobs = BatchJobPeer::retrieveByJobTypeAndObject($batchJob->getObjectId(), $batchJob->getObjectType(), $batchJob->getJobType(), $batchJob->getJobSubType());
         if (count($batchJobs)) {
             return $batchJobs[0]->getLockInfo()->getUrgency() + 1;
         }
     }
     // a conversion job will be considered as required in one of the following cases:
     // 1. The flavor is required
     // 2. There are no required flavors and this is the flavor is optional with the minimal bitrate
     // 3. all flavors are set as READY_BEHAVIOR_NO_IMPACT.
     $allFlavorParamsIds = array();
     $hasRequired = false;
     $allNoImpact = true;
     // Go over all flavors and decide on cases 1-3
     $fpcps = flavorParamsConversionProfilePeer::retrieveByConversionProfile($this->conversionProfileId);
     foreach ($fpcps as $fpcp) {
         $allFlavorParamsIds[] = $fpcp->getFlavorParamsId();
         if ($fpcp->getFlavorParamsId() == $flavorParamsId) {
             // Case 1
             $readiness = $fpcp->getReadyBehavior();
         }
         if ($fpcp->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             // Case 2
             $hasRequired = true;
         }
         if ($fpcp->getReadyBehavior() != flavorParamsConversionProfile::READY_BEHAVIOR_NO_IMPACT) {
             // Case 3
             $allNoImpact = false;
         }
     }
     // Case 2
     if (!$hasRequired && $readiness == flavorParamsConversionProfile::READY_BEHAVIOR_OPTIONAL) {
         $flvParamsMinBitrate = assetParamsPeer::retrieveMinimalBitrate($allFlavorParamsIds);
         if (!is_null($flvParamsMinBitrate) && $flvParamsMinBitrate->getId() == $flavorParamsId) {
             $readiness = flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED;
         }
     }
     // Case 3
     if ($allNoImpact) {
         $readiness = flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED;
     }
     // Decide on the urgency by the readiness and the upload method
     if ($readiness == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
         return $isBulkupload ? BatchJobUrgencyType::REQUIRED_BULK_UPLOAD : BatchJobUrgencyType::REQUIRED_REGULAR_UPLOAD;
     } else {
         if ($readiness == flavorParamsConversionProfile::READY_BEHAVIOR_OPTIONAL) {
             return $isBulkupload ? BatchJobUrgencyType::OPTIONAL_BULK_UPLOAD : BatchJobUrgencyType::OPTIONAL_REGULAR_UPLOAD;
         } else {
             return BatchJobUrgencyType::DEFAULT_URGENCY;
         }
     }
 }
 /**
  * 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(assetParamsPeer::DATABASE_NAME);
         $criteria->add(assetParamsPeer::ID, $pks, Criteria::IN);
         $objs = assetParamsPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 public function execute()
 {
     $this->forceSystemAuthentication();
     $this->pid = $this->getRequestParameter("pid", 0);
     if (!is_null($this->getRequestParameter("advanced"))) {
         $this->getResponse()->setCookie('flavor-params-advanced', $this->getRequestParameter("advanced"));
         $this->advanced = (int) $this->getRequestParameter("advanced");
     } else {
         $this->advanced = (int) $this->getRequest()->getCookie('flavor-params-advanced');
     }
     myDbHelper::$use_alternative_con = null;
     $this->editFlavorParam = null;
     $this->editFlavorParam = assetParamsPeer::retrieveByPK($this->getRequestParameter("id"));
     if ($this->getRequestParameter("clone")) {
         $newFalvorParams = $this->editFlavorParam->copy();
         $newFalvorParams->setSourceAssetParamsIds($this->editFlavorParam->getSourceAssetParamsIds());
         $newFalvorParams->setAspectRatioProcessingMode($this->editFlavorParam->getAspectRatioProcessingMode());
         $newFalvorParams->setForceFrameToMultiplication16($this->editFlavorParam->getForceFrameToMultiplication16());
         $newFalvorParams->setIsGopInSec($this->editFlavorParam->getIsGopInSec());
         $newFalvorParams->setIsAvoidVideoShrinkFramesizeToSource($this->editFlavorParam->getIsAvoidVideoShrinkFramesizeToSource());
         $newFalvorParams->setIsAvoidVideoShrinkBitrateToSource($this->editFlavorParam->getIsAvoidVideoShrinkBitrateToSource());
         $newFalvorParams->setIsVideoFrameRateForLowBrAppleHls($this->editFlavorParam->getIsVideoFrameRateForLowBrAppleHls());
         $newFalvorParams->setIsAvoidForcedKeyFrames($this->editFlavorParam->getIsAvoidForcedKeyFrames());
         $newFalvorParams->setMultiStream($this->editFlavorParam->getMultiStream());
         $newFalvorParams->setAnamorphicPixels($this->editFlavorParam->getAnamorphicPixels());
         $newFalvorParams->setMaxFrameRate($this->editFlavorParam->getMaxFrameRate());
         $newFalvorParams->setWatermarkData($this->editFlavorParam->getWatermarkData());
         $newFalvorParams->setIsDefault(false);
         $newFalvorParams->setPartnerId(-1);
         $newFalvorParams->save();
         $this->redirect("system/flavorParams?pid=" . $this->pid . "&id=" . $newFalvorParams->getId());
     }
     if ($this->getRequestParameter("delete")) {
         if ($this->advanced || $this->editFlavorParam->getPartnerId() != 0) {
             $this->editFlavorParam->setDeletedAt(time());
             $this->editFlavorParam->save();
         }
         $this->redirect("system/flavorParams?pid=" . $this->pid);
     }
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         if ($this->advanced || $this->editFlavorParam->getPartnerId() != 0) {
             $partnerId = $this->getRequestParameter("partner-id");
             if ($this->advanced) {
                 $this->editFlavorParam->setPartnerId($partnerId);
             } else {
                 if ($partnerId != 0) {
                     $this->editFlavorParam->setPartnerId($partnerId);
                 }
             }
             if ($this->advanced >= 1) {
                 $this->editFlavorParam->setName($this->getRequestParameter("name"));
                 $this->editFlavorParam->setSystemName($this->getRequestParameter("systemName"));
                 $this->editFlavorParam->setDescription($this->getRequestParameter("description"));
                 $this->editFlavorParam->setIsDefault($this->getRequestParameter("is-default", false));
                 $this->editFlavorParam->setReadyBehavior($this->getRequestParameter("ready-behavior"));
                 $this->editFlavorParam->setTags($this->getRequestParameter("tags"));
                 $this->editFlavorParam->setSourceAssetParamsIds($this->getRequestParameter("sourceAssetParamsIds"));
                 $this->editFlavorParam->setFormat($this->getRequestParameter("format"));
                 $this->editFlavorParam->setTwoPass($this->getRequestParameter("two-pass", false));
                 $this->editFlavorParam->setRotate($this->getRequestParameter("rotate", false));
                 $this->editFlavorParam->setAspectRatioProcessingMode($this->getRequestParameter("aspectRatioProcessingMode", 0));
                 $this->editFlavorParam->setIsGopInSec($this->getRequestParameter("isGopInSec", 0));
                 $this->editFlavorParam->setForceFrameToMultiplication16($this->getRequestParameter("forceFrameToMultiplication16") ? "1" : "0");
                 $this->editFlavorParam->setIsAvoidVideoShrinkFramesizeToSource($this->getRequestParameter("isAvoidVideoShrinkFramesizeToSource", 0));
                 $this->editFlavorParam->setIsAvoidVideoShrinkBitrateToSource($this->getRequestParameter("isAvoidVideoShrinkBitrateToSource", 0));
                 $this->editFlavorParam->setIsVideoFrameRateForLowBrAppleHls($this->getRequestParameter("isVideoFrameRateForLowBrAppleHls", 0));
                 $this->editFlavorParam->setIsAvoidForcedKeyFrames($this->getRequestParameter("isAvoidForcedKeyFrames", 0));
                 $this->editFlavorParam->setMultiStream($this->getRequestParameter("multiStream", 0));
                 $this->editFlavorParam->setAnamorphicPixels($this->getRequestParameter("anamorphicPixels", 0));
                 $this->editFlavorParam->setWidth($this->getRequestParameter("width"));
                 $this->editFlavorParam->setHeight($this->getRequestParameter("height"));
                 $this->editFlavorParam->setVideoCodec($this->getRequestParameter("video-codec"));
                 $this->editFlavorParam->setVideoBitrate($this->getRequestParameter("video-bitrate"));
                 $this->editFlavorParam->setWatermarkData($this->getRequestParameter("watermarkData", 0));
                 $this->editFlavorParam->setFrameRate($this->getRequestParameter("frame-rate"));
                 $this->editFlavorParam->setMaxFrameRate($this->getRequestParameter("max-frame-rate"));
                 $this->editFlavorParam->setGopSize($this->getRequestParameter("gop-size"));
                 $this->editFlavorParam->setAudioCodec($this->getRequestParameter("audio-codec"));
                 $this->editFlavorParam->setAudioBitrate($this->getRequestParameter("audio-bitrate"));
                 $this->editFlavorParam->setAudioChannels($this->getRequestParameter("audio-channels"));
                 $this->editFlavorParam->setAudioSampleRate($this->getRequestParameter("audio-sample-rate"));
                 $this->editFlavorParam->setAudioResolution($this->getRequestParameter("audio-resolution"));
                 $this->editFlavorParam->setConversionEngines($this->getRequestParameter("conversion-engines"));
                 $this->editFlavorParam->setConversionEnginesExtraParams($this->getRequestParameter("conversion-engines-extra-params"));
                 $this->editFlavorParam->setOperators($this->getRequestParameter("operators"));
                 $this->editFlavorParam->setEngineVersion($this->getRequestParameter("engine-version"));
                 $this->editFlavorParam->setType($this->getRequestParameter("type"));
             }
             $this->editFlavorParam->save();
         }
         $this->redirect("system/flavorParams?pid=" . $this->editFlavorParam->getPartnerId());
     }
     $c = new Criteria();
     $c->add(assetParamsPeer::PARTNER_ID, array(0, $this->pid), Criteria::IN);
     $this->flavorParams = assetParamsPeer::doSelect($c);
     $this->formats = self::getEnumValues("flavorParams", "CONTAINER_FORMAT");
     $this->videoCodecs = self::getEnumValues("flavorParams", "VIDEO_CODEC");
     $this->audioCodecs = self::getEnumValues("flavorParams", "AUDIO_CODEC");
     $this->readyBehaviors = self::getEnumValues("flavorParamsConversionProfile", "READY_BEHAVIOR");
     $this->creationModes = self::getEnumValues("flavorParams", "CREATION_MODE");
 }
 /**
  * Serve XML rendition of the Kaltura Live Transcoding Profile usable by the Wowza transcoding add-on
  * 
  * @action serve
  * @param string $streamName the id of the live entry with it's stream suffix
  * @param string $hostname the media server host name
  * @return file
  * 
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  * @throws WowzaErrors::INVALID_STREAM_NAME
  */
 public function serveAction($streamName, $hostname = null)
 {
     $matches = null;
     if (!preg_match('/^(\\d_.{8})_(\\d+)$/', $streamName, $matches)) {
         throw new KalturaAPIException(WowzaErrors::INVALID_STREAM_NAME, $streamName);
     }
     $entryId = $matches[1];
     $suffix = $matches[2];
     $entry = null;
     if (!kCurrentContext::$ks) {
         kEntitlementUtils::initEntitlementEnforcement(null, false);
         $entry = kCurrentContext::initPartnerByEntryId($entryId);
         if (!$entry || $entry->getStatus() == entryStatus::DELETED) {
             throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
         }
         // enforce entitlement
         $this->setPartnerFilters(kCurrentContext::getCurrentPartnerId());
     } else {
         $entry = entryPeer::retrieveByPK($entryId);
     }
     if (!$entry || $entry->getType() != KalturaEntryType::LIVE_STREAM || !in_array($entry->getSource(), array(KalturaSourceType::LIVE_STREAM, KalturaSourceType::LIVE_STREAM_ONTEXTDATA_CAPTIONS))) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $mediaServer = null;
     if ($hostname) {
         $mediaServer = MediaServerPeer::retrieveByHostname($hostname);
     }
     $conversionProfileId = $entry->getConversionProfileId();
     $liveParams = assetParamsPeer::retrieveByProfile($conversionProfileId);
     $liveParamsInput = null;
     $disableIngested = true;
     foreach ($liveParams as $liveParamsItem) {
         /* @var $liveParamsItem liveParams */
         if ($liveParamsItem->getStreamSuffix() == $suffix) {
             $liveParamsInput = $liveParamsItem;
             if (!$liveParamsInput->hasTag(assetParams::TAG_SOURCE)) {
                 $liveParams = array($liveParamsInput);
                 $disableIngested = false;
             }
             break;
         }
     }
     $ignoreLiveParamsIds = array();
     if ($disableIngested) {
         $conversionProfileAssetParams = flavorParamsConversionProfilePeer::retrieveByConversionProfile($conversionProfileId);
         foreach ($conversionProfileAssetParams as $conversionProfileAssetParamsItem) {
             /* @var $conversionProfileAssetParamsItem flavorParamsConversionProfile */
             if ($conversionProfileAssetParamsItem->getOrigin() == assetParamsOrigin::INGEST) {
                 $ignoreLiveParamsIds[] = $conversionProfileAssetParamsItem->getFlavorParamsId();
             }
         }
     }
     // translate the $liveParams to XML according to doc: http://www.wowza.com/forums/content.php?304#configTemplate
     $root = new SimpleXMLElement('<Root/>');
     $transcode = $root->addChild('Transcode');
     $encodes = $transcode->addChild('Encodes');
     $groups = array();
     foreach ($liveParams as $liveParamsItem) {
         /* @var $liveParamsItem liveParams */
         if (!$liveParamsItem->hasTag(assetParams::TAG_SOURCE) && in_array($liveParamsItem->getId(), $ignoreLiveParamsIds)) {
             continue;
         }
         $this->appendLiveParams($entry, $mediaServer, $encodes, $liveParamsItem);
         $tags = $liveParamsItem->getTagsArray();
         $tags[] = 'all';
         foreach ($tags as $tag) {
             if (!isset($groups[$tag])) {
                 $groups[$tag] = array();
             }
             $systemName = $liveParamsItem->getSystemName() ? $liveParamsItem->getSystemName() : $liveParamsItem->getId();
             $groups[$tag][] = $systemName;
         }
     }
     $decode = $transcode->addChild('Decode');
     $video = $decode->addChild('Video');
     $video->addChild('Deinterlace', 'false');
     $streamNameGroups = $transcode->addChild('StreamNameGroups');
     foreach ($groups as $groupName => $groupMembers) {
         $streamNameGroup = $streamNameGroups->addChild('StreamNameGroup');
         $streamNameGroup->addChild('Name', $groupName);
         $streamNameGroup->addChild('StreamName', '${SourceStreamName}_' . $groupName);
         $members = $streamNameGroup->addChild('Members');
         foreach ($groupMembers as $groupMember) {
             $member = $members->addChild('Member');
             $member->addChild('EncodeName', $groupMember);
         }
     }
     $properties = $transcode->addChild('Properties');
     $dom = new DOMDocument("1.0");
     $dom->preserveWhiteSpace = false;
     $dom->formatOutput = true;
     $dom->loadXML($root->asXML());
     return new kRendererString($dom->saveXML(), 'text/xml');
 }
Exemple #29
0
 public function getDynamicFlavorAttributesForAssetParams($assetParamsId)
 {
     // set dynamic flavor attributes
     $dynamicFlavorAttributes = array();
     $dynamicEntryAttributes = $this->getDynamicFlavorAttributes();
     // dynamic attributes for all entry flavors
     // if dynamic attributes are set for this specific flavor - use them
     if (isset($dynamicEntryAttributes[$assetParamsId])) {
         $dynamicFlavorAttributes = $dynamicEntryAttributes[$assetParamsId];
     } else {
         if (isset($dynamicEntryAttributes[flavorParams::DYNAMIC_ATTRIBUTES_ALL_FLAVORS_INDEX])) {
             $assetParamsDb = assetParamsPeer::retrieveByPK($assetParamsId);
             if (!$assetParamsDb->hasTag(flavorParams::TAG_SOURCE)) {
                 $dynamicFlavorAttributes = $dynamicEntryAttributes[flavorParams::DYNAMIC_ATTRIBUTES_ALL_FLAVORS_INDEX];
             }
         }
     }
     return $dynamicFlavorAttributes;
 }
Exemple #30
0
 public static function filterTagFlavors(array $flavors)
 {
     KalturaLog::log("Filter Tag Flavors, " . count($flavors) . " flavors supplied");
     // check if there is a complete flavor
     $hasComplied = false;
     $hasForced = false;
     $hasCreateAnyway = false;
     $originalFlavorParamsIds = array();
     foreach ($flavors as $flavorParamsId => $flavor) {
         $originalFlavorParamsIds[] = $flavor->getFlavorParamsId();
         if (!$flavor->_isNonComply) {
             $hasComplied = true;
         }
         if ($flavor->_force) {
             $hasForced = true;
         }
         if ($flavor->_create_anyway) {
             $hasCreateAnyway = true;
         }
     }
     $originalFlavorParams = array();
     $dbOriginalFlavorParams = assetParamsPeer::retrieveByPKs($originalFlavorParamsIds);
     foreach ($dbOriginalFlavorParams as $dbFlavorParams) {
         $originalFlavorParams[$dbFlavorParams->getId()] = $dbFlavorParams;
     }
     // return only complete flavors
     if ($hasComplied) {
         KalturaLog::log("Has complied flavors");
     }
     if ($hasForced) {
         KalturaLog::log("Has forced flavors");
     }
     if ($hasCreateAnyway) {
         KalturaLog::log("Has createAnyway flavors");
     }
     if ($hasComplied || $hasForced || $hasCreateAnyway) {
         return $flavors;
     }
     // find the lowest flavor
     $lowestFlavorParamsId = null;
     foreach ($flavors as $flavorParamsId => $flavor) {
         if (!$flavor->IsValid()) {
             continue;
         }
         // is lower than the selected
         if (!isset($originalFlavorParams[$flavor->getFlavorParamsId()])) {
             continue;
         }
         $currentOriginalFlavor = $originalFlavorParams[$flavor->getFlavorParamsId()];
         // is first flavor to check
         if (is_null($lowestFlavorParamsId)) {
             $lowestFlavorParamsId = $flavorParamsId;
             continue;
         }
         $lowestOriginalFlavor = $originalFlavorParams[$flavors[$lowestFlavorParamsId]->getFlavorParamsId()];
         if (self::isFlavorLower($currentOriginalFlavor, $lowestOriginalFlavor)) {
             $lowestFlavorParamsId = $flavorParamsId;
         }
     }
     if ($lowestFlavorParamsId) {
         KalturaLog::log("Lowest flavor selected [{$lowestFlavorParamsId}]");
         $flavors[$lowestFlavorParamsId]->_create_anyway = true;
     }
     return $flavors;
 }