Пример #1
0
 /**
  * @param flavorAsset $flavorAsset
  * @return string representing the version string
  */
 protected function getFlavorVersionString(flavorAsset $flavorAsset)
 {
     $entry = $flavorAsset->getentry();
     $partner = $entry->getPartner();
     $flavorAssetVersion = $flavorAsset->getVersion();
     $partnerFlavorVersion = $partner->getCacheFlavorVersion();
     $entryFlavorVersion = $entry->getCacheFlavorVersion();
     return (!$flavorAssetVersion ? '' : "/v/{$flavorAssetVersion}") . ($partnerFlavorVersion ? "/pv/{$partnerFlavorVersion}" : '') . ($entryFlavorVersion ? "/ev/{$entryFlavorVersion}" : '');
 }
Пример #2
0
 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;
 }
Пример #3
0
 /**
  * 
  * @param $flavorAsset
  * @param $con
  * 
  * @return flavorParamsOutput
  */
 public static function retrieveByFlavorAsset(flavorAsset $flavorAsset, $con = null)
 {
     return self::retrieveByFlavorAssetId($flavorAsset->getId(), $flavorAsset->getVersion(), $con);
 }
Пример #4
0
 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;
         }
         /*
          * If the conversion profile contains source flavor and the source is tagged with 'save_source' ==> 
          * save the original source asset in another asset, in order 
          * to prevent its liquidated by the inter-source asset.
          */
         if (isset($sourceFlavor) && strstr($sourceFlavor->getTagsArray(), assetParams::TAG_SAVE_SOURCE) !== false) {
             self::saveOriginalSource($mediaInfo);
         }
     } 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 (isset($sourceFlavor)) {
             self::saveOriginalSource($mediaInfo);
         }
     }
     /*
      * '_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 (!isset($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)) {
         $tagsArr = $sourceFlavor->getTagsArray();
         // No need for 'save_source' tag on the inter-src asset, remove it.
         if (($key = array_search(assetParams::TAG_SAVE_SOURCE, $tagsArr)) !== false) {
             unset($tagsArr[$key]);
         }
         $originalFlavorAsset->addTags($tagsArr);
         $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;
 }
Пример #5
0
 /**
  * 
  * Allows to create additional files in the conversion process in addition to flavor asset 
  */
 private static function handleAdditionalFilesConvertFinished(flavorAsset $flavorAsset, BatchJob $dbBatchJob, kConvertJobData $data)
 {
     if (!$flavorAsset->getVersion() || !kFileSyncUtils::fileSync_exists($flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET))) {
         $flavorAsset->incrementVersion();
         $flavorAsset->save();
     }
     foreach ($data->getExtraDestFileSyncs() as $destFileSyncDesc) {
         $syncKey = $flavorAsset->getSyncKey($destFileSyncDesc->getFileSyncObjectSubType());
         $flavorParamsOutput = $data->getFlavorParamsOutput();
         $storageProfileId = $flavorParamsOutput->getSourceRemoteStorageProfileId();
         if ($storageProfileId == StorageProfile::STORAGE_KALTURA_DC) {
             kFileSyncUtils::moveFromFile($destFileSyncDesc->getFileSyncLocalPath(), $syncKey, false);
         } elseif ($flavorParamsOutput->getRemoteStorageProfileIds()) {
             $remoteStorageProfileIds = explode(',', $flavorParamsOutput->getRemoteStorageProfileIds());
             foreach ($remoteStorageProfileIds as $remoteStorageProfileId) {
                 $storageProfile = StorageProfilePeer::retrieveByPK($remoteStorageProfileId);
                 kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $destFileSyncDesc->getFileSyncLocalPath(), $storageProfile);
             }
         }
     }
 }
Пример #6
0
 /**
  * batch createFlavorAsset orgenize a convert job data 
  * 
  * @param flavorParamsOutputWrap $flavor
  * @param int $partnerId
  * @param int $entryId
  * @param string $description
  * @return flavorAsset
  */
 public static function createErrorFlavorAsset(flavorParamsOutputWrap $flavor, $partnerId, $entryId, $description)
 {
     $flavorAsset = flavorAssetPeer::retrieveByEntryIdAndFlavorParams($entryId, $flavor->getFlavorParamsId());
     if ($flavorAsset) {
         $description = $flavorAsset->getDescription() . "\n" . $description;
         $flavorAsset->setDescription($description);
         $flavorAsset->incrementVersion();
     } else {
         // creates the flavor asset
         $flavorAsset = new flavorAsset();
         $flavorAsset->setPartnerId($partnerId);
         $flavorAsset->setEntryId($entryId);
         $flavorAsset->setDescription($description);
     }
     $flavorAsset->setTags($flavor->getTags());
     $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
     $flavorAsset->setFlavorParamsId($flavor->getFlavorParamsId());
     $flavorAsset->setFileExt($flavor->getFileExt());
     $flavorAsset->save();
     // save flavor params
     $flavor->setPartnerId($partnerId);
     $flavor->setEntryId($entryId);
     $flavor->setFlavorAssetId($flavorAsset->getId());
     $flavor->setFlavorAssetVersion($flavorAsset->getVersion());
     $flavor->save();
     return $flavorAsset;
 }