Esempio n. 1
0
 /**
  * addFlavorConvertJob adds a single flavor conversion 
  * 
  * @param FileSyncKey $srcSyncKey
  * @param flavorParamsOutput $flavor
  * @param int $flavorAssetId
  * @param int $conversionProfileId
  * @param int $mediaInfoId
  * @param BatchJob $parentJob
  * @param int $lastEngineType  
  * @param bool $sameRoot
  * @return BatchJob 
  */
 public static function addFlavorConvertJob(array $srcSyncKeys, flavorParamsOutput $flavor, $flavorAssetId, $conversionProfileId = null, $mediaInfoId = null, BatchJob $parentJob = null, $lastEngineType = null, $sameRoot = true, $priority = 0)
 {
     KalturaLog::debug('Add convert job for [' . $flavorAssetId . ']');
     $flavorAsset = assetPeer::retrieveById($flavorAssetId);
     if (!$flavorAsset) {
         KalturaLog::err("No flavor asset found for id [{$flavorAssetId}]");
         return null;
     }
     $partner = PartnerPeer::retrieveByPK($flavorAsset->getPartnerId());
     $srcFileSyncs = array();
     $waitForImportComplete = false;
     foreach ($srcSyncKeys as $srcSyncKey) {
         $srcFileSyncDescriptor = new kSourceFileSyncDescriptor();
         $addImportJob = false;
         $fileSync = self::getFileSyncForKey($srcSyncKey, $flavor, $flavorAsset, $partner, $addImportJob);
         if (!$fileSync) {
             return null;
         }
         $srcFlavorAsset = assetPeer::retrieveById($srcSyncKey->getObjectId());
         if ($addImportJob) {
             KalturaLog::debug("Creates import job for remote file sync");
             $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_WAIT_FOR_CONVERT);
             $flavorAsset->setDescription("Source file sync is importing: {$srcSyncKey}");
             $flavorAsset->save();
             $url = $fileSync->getExternalUrl($flavorAsset->getEntryId());
             kJobsManager::addImportJob($parentJob, $flavorAsset->getEntryId(), $partner->getId(), $url, $srcFlavorAsset, null, null, true);
             $waitForImportComplete = true;
         } else {
             if ($flavor->getSourceRemoteStorageProfileId() == StorageProfile::STORAGE_KALTURA_DC) {
                 if ($fileSync->getFileType() != FileSync::FILE_SYNC_FILE_TYPE_URL) {
                     $srcFileSyncDescriptor->setFileSyncLocalPath($fileSync->getFullPath());
                 }
             } else {
                 $srcFileSyncDescriptor->setFileSyncLocalPath($fileSync->getFilePath());
             }
             $srcFileSyncDescriptor->setFileSyncRemoteUrl($fileSync->getExternalUrl($flavorAsset->getEntryId()));
             $srcFileSyncDescriptor->setAssetId($srcSyncKey->getObjectId());
             $srcFileSyncDescriptor->setAssetParamsId($srcFlavorAsset->getFlavorParamsId());
             $srcFileSyncDescriptor->setFileSyncObjectSubType($srcSyncKey->getObjectSubType());
             $srcFileSyncs[] = $srcFileSyncDescriptor;
         }
     }
     if ($waitForImportComplete) {
         return;
     }
     // creates convert data
     $convertData = new kConvertJobData();
     $convertData->setSrcFileSyncs($srcFileSyncs);
     $convertData->setMediaInfoId($mediaInfoId);
     $convertData->setFlavorParamsOutputId($flavor->getId());
     $convertData->setFlavorAssetId($flavorAssetId);
     $convertData->setConversionProfileId($conversionProfileId);
     $convertData->setPriority($priority);
     $dbCurrentConversionEngine = self::getNextConversionEngine($flavor, $parentJob, $lastEngineType, $convertData);
     if (!$dbCurrentConversionEngine) {
         return null;
     }
     // creats a child convert job
     if ($parentJob) {
         $dbConvertFlavorJob = $parentJob->createChild(BatchJobType::CONVERT, $dbCurrentConversionEngine, $sameRoot);
         KalturaLog::log("Created from parent job");
     } else {
         $dbConvertFlavorJob = new BatchJob();
         $dbConvertFlavorJob->setPartnerId($flavor->getPartnerId());
         $dbConvertFlavorJob->setJobType(BatchJobType::CONVERT);
         $dbConvertFlavorJob->setJobSubType($dbCurrentConversionEngine);
         KalturaLog::log("Created from flavor convert job");
     }
     $dbConvertFlavorJob->setEntryId($flavor->getEntryId());
     KalturaLog::log("Job created with entry id [" . $dbConvertFlavorJob->getEntryId() . "]");
     $mediaInfo = mediaInfoPeer::retrieveByPK($mediaInfoId);
     if ($mediaInfo === NULL) {
         // in case we don't know the estimatted info, we will set it to a big number.
         $estimatedEffort = kJobData::MAX_ESTIMATED_EFFORT;
     } else {
         $estimatedEffort = max($mediaInfo->getVideoDuration(), $mediaInfo->getAudioDuration(), $mediaInfo->getContainerDuration());
     }
     $dbConvertFlavorJob->setObjectId($flavorAssetId);
     $dbConvertFlavorJob->setObjectType(BatchJobObjectType::ASSET);
     return kJobsManager::addJob($dbConvertFlavorJob, $convertData, BatchJobType::CONVERT, $dbCurrentConversionEngine);
 }
Esempio n. 2
0
 private static function getFileSyncDescriptor(kSourceFileSyncDescriptor $flavorAssetDesc, $objectSubType)
 {
     $ismDescriptor = null;
     $flavorAsset = assetPeer::retrieveById($flavorAssetDesc->getAssetId());
     $key = $flavorAsset->getSyncKey($objectSubType);
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($key);
     if ($fileSync) {
         $ismDescriptor = new kSourceFileSyncDescriptor();
         $ismDescriptor->setFileSyncLocalPath($fileSync->getFullPath());
         $ismDescriptor->setFileSyncRemoteUrl($fileSync->getExternalUrl($flavorAsset->getEntryId()));
         $ismDescriptor->setAssetId($key->getObjectId());
         $ismDescriptor->setAssetParamsId($flavorAssetDesc->getAssetParamsId());
         $ismDescriptor->setFileSyncObjectSubType($key->getObjectSubType());
     }
     return $ismDescriptor;
 }